Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix edit button and update plugins #244

Merged
merged 6 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 81 additions & 70 deletions .github/scripts/check-plugins.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,61 @@
import { readFile, writeFile } from "fs/promises"
import { readFile, writeFile } from "node:fs/promises";

const PLUGIN_LIST_PATH = "./src/lib/plugin-directory.txt"
const PLUGIN_INFO_PATH = "./src/lib/plugins/plugins.json"
const GITHUB_TOKEN = process.env.GITHUB_TOKEN
const PLUGIN_LIST_PATH = "./src/lib/plugin-directory.txt";
const PLUGIN_INFO_PATH = "./src/lib/plugins/plugins.json";
const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
const GITHUB_HEADERS = {
headers: {
Authorization: `Bearer ${GITHUB_TOKEN}`,
"User-Agent": "GitHub Actions",
},
}
};

async function importTxtFile() {
try {
const text = await readFile(PLUGIN_LIST_PATH, "utf-8")
const lines = text.split("\n").filter((line) => line.trim() !== "")
const text = await readFile(PLUGIN_LIST_PATH, "utf-8");
const lines = text.split("\n").filter((line) => line.trim() !== "");

console.log(`Imported ${lines.length} lines from ${PLUGIN_LIST_PATH}`)
return lines
console.log(`Imported ${lines.length} lines from ${PLUGIN_LIST_PATH}`);
return lines;
} catch (error) {
throw new Error(`Error importing plugin directory text file: ${error.message}`)
throw new Error(
`Error importing plugin directory text file: ${error.message}`,
);
}
}

/**
* @returns {Promise<Object<string, any>>}
* */
*/
async function importPluginJson() {
try {
const text = await readFile(PLUGIN_INFO_PATH, "utf-8")
const json = JSON.parse(text)
console.log(`Imported ${Object.keys(json).length} plugins from ${PLUGIN_INFO_PATH}`)
return json
const text = await readFile(PLUGIN_INFO_PATH, "utf-8");
const json = JSON.parse(text);
console.log(
`Imported ${Object.keys(json).length} plugins from ${PLUGIN_INFO_PATH}`,
);
return json;
} catch (error) {
throw new Error(`Error importing plugin information json file: ${error.message}`)
throw new Error(
`Error importing plugin information json file: ${error.message}`,
);
}
}

/**
* @param {string} repo
* @returns {{name: string, pluginId: string, description: string, tags: string[], author: string, authorIcon: string, sourceLink: string, license: string}}
* */
*/
async function fetchRepo(repo) {
const url = `https://api.github.com/repos/${repo}`
const response = await fetch(url, GITHUB_HEADERS)
const url = `https://api.github.com/repos/${repo}`;
const response = await fetch(url, GITHUB_HEADERS);
if (!response.ok) {
const message = `Error ${response.status}: Cannot fetch repo ${repo}`
throw new Error(message)
const message = `Error ${response.status}: Cannot fetch repo ${repo}`;
throw new Error(message);
}
const repoData = await response.json()
const author = repoData.owner.login
const license = author === "wharfkit" ? "BSD-3" : repoData.license.name
const repoData = await response.json();
const author = repoData.owner.login;
const license = author === "wharfkit" ? "BSD-3" : repoData.license.name;

return {
name: repoData.name,
Expand All @@ -60,105 +66,110 @@ async function fetchRepo(repo) {
authorIcon: repoData.owner.avatar_url,
sourceLink: repoData.html_url,
license: license,
}
};
}

/**
* @param {string} repo
* @returns {{version: string, lastPublishedDate: string } | {}}
* */
*/
async function fetchRelease(repo) {
const url = `https://api.github.com/repos/${repo}/releases/latest`
const response = await fetch(url, GITHUB_HEADERS)
const url = `https://api.github.com/repos/${repo}/releases/latest`;
const response = await fetch(url, GITHUB_HEADERS);
if (!response.ok) {
const message = `Error ${response.status}: Cannot fetch latest release for ${repo}`
const message =
`Error ${response.status}: Cannot fetch latest release for ${repo}`;
// Not throwing so process can continue
console.error(message)
return {}
console.error(message);
return {};
}
const release = await response.json()
const release = await response.json();
return {
version: release.tag_name,
lastPublishedDate: release.published_at,
}
};
}

/**
* @param {string} repo
* @returns {{readme: string } | {}}
* */
*/
async function fetchReadme(repo) {
const url = `https://api.github.com/repos/${repo}/readme`
const response = await fetch(url, GITHUB_HEADERS)
const url = `https://api.github.com/repos/${repo}/readme`;
const response = await fetch(url, GITHUB_HEADERS);
if (!response.ok) {
const message = `Error ${response.status}: Cannot fetch readme for ${repo}`
const message = `Error ${response.status}: Cannot fetch readme for ${repo}`;
// Not throwing so process can continue
console.error(message)
return {}
console.error(message);
return {};
}
const { download_url } = await response.json()
const readmeRes = await fetch(download_url, GITHUB_HEADERS)
const readme = await readmeRes.text()
const { download_url } = await response.json();
const readmeRes = await fetch(download_url, GITHUB_HEADERS);
const readme = await readmeRes.text();
return {
readme,
}
};
}

/**
* @param {string} repo
* */
*/
async function fetchSha(repo) {
const url = `https://api.github.com/repos/${repo}/commits`
const response = await fetch(url, GITHUB_HEADERS)
const url = `https://api.github.com/repos/${repo}/commits`;
const response = await fetch(url, GITHUB_HEADERS);
if (!response.ok) {
const message = `Error ${response.status}: Cannot fetch commit for ${repo}`
throw new Error(message)
const message = `Error ${response.status}: Cannot fetch commit for ${repo}`;
throw new Error(message);
}
const [result] = await response.json()
return result.sha
const [result] = await response.json();
return result.sha;
}

/**
* @param {string} plugin
* */
*/
async function fetchPluginInfo(plugin) {
console.log(`Fetching info for ${plugin}...`)
console.log(`Fetching info for ${plugin}...`);
const [pluginRepo, pluginRelease, pluginReadme] = await Promise.all([
fetchRepo(plugin),
fetchRelease(plugin),
fetchReadme(plugin),
])
return { ...pluginRepo, ...pluginRelease, ...pluginReadme }
]);
return { ...pluginRepo, ...pluginRelease, ...pluginReadme };
}

async function main() {
try {
const pluginList = await importTxtFile()
const currentPluginData = await importPluginJson()
const pluginList = await importTxtFile();
const currentPluginData = await importPluginJson();
const updatedPlugins = await Promise.all(
pluginList.map(async (plugin) => {
// Check if no updates are needed
if (currentPluginData[plugin]) {
const remoteSha = await fetchSha(plugin)
const { sha: currentSha } = currentPluginData[plugin]
const remoteSha = await fetchSha(plugin);
const { sha: currentSha } = currentPluginData[plugin];
if (remoteSha === currentSha) {
console.log(`No updates found for ${plugin}`)
console.log(`No updates found for ${plugin}`);
// Re-use existing data
return [plugin, currentPluginData[plugin]]
return [plugin, currentPluginData[plugin]];
}
}

const pluginInfo = await fetchPluginInfo(plugin)
return [plugin, pluginInfo]
})
)
const updatedPluginsMap = new Map(updatedPlugins)
const updatedPluginsJson = Object.fromEntries(updatedPluginsMap)
const updatedPluginsJsonString = JSON.stringify(updatedPluginsJson, null, 2)
await writeFile(PLUGIN_INFO_PATH, updatedPluginsJsonString)
const pluginInfo = await fetchPluginInfo(plugin);
return [plugin, pluginInfo];
}),
);
const updatedPluginsMap = new Map(updatedPlugins);
const updatedPluginsJson = Object.fromEntries(updatedPluginsMap);
const updatedPluginsJsonString = JSON.stringify(
updatedPluginsJson,
null,
2,
);
await writeFile(PLUGIN_INFO_PATH, updatedPluginsJsonString);
} catch (error) {
console.error(error)
console.error(error);
}
}

main()
main();
2 changes: 1 addition & 1 deletion .github/workflows/plugin-updater.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5.0.2
uses: peter-evans/create-pull-request@v6
with:
add-paths: src/lib/plugins/plugins.json
title: "Automated updates to plugin directory"
2 changes: 1 addition & 1 deletion .yarnrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--frozen-lockfile true
--frozen-lockfile true
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@sveltejs/adapter-cloudflare": "2.0.1",
"@sveltejs/kit": "^1.20.4",
"@types/js-yaml": "^4.0.8",
"@types/node": "^20.11.22",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"@vitejs/plugin-basic-ssl": "^1.0.1",
Expand Down
7 changes: 2 additions & 5 deletions src/lib/components/TOC.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import { activeTocSection } from "$lib/stores"
import { scrollToTop } from "../utils"
export let headings: HeadingNode[]
const GITHUB_EDIT_URL =
`https://github.com/wharfkit/website/blob/dev` + $page && $page.data.section.indexPage
? $page.data.section.indexPage.source
: ""
export let editUrl: string
</script>

<nav aria-label="Table of Contents" class="toc">
Expand All @@ -28,7 +25,7 @@
</li>
{/each}
</menu>
<a href={GITHUB_EDIT_URL} class="edit button" data-type="secondary">Edit this page</a>
<a href={editUrl} class="edit button" data-type="secondary">Edit this page</a>
</nav>

<style>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/docs/AccountKit/Account.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Each `Account` class instance represents a specific blockchain account. It offer
In most cases, the [AccountKit Factory](/docs/account-kit/account-kit-factory) will be used to create `Account` instances. However, they can also be created manually if the relevant data is provided. Here is a basic example of how to do so:

```ts
import { Account } from "@wharfkit/contract"
import { Account } from "@wharfkit/account"
import { APIClient } from "@wharfkit/antelope"

const accountArgs = {
Expand Down
10 changes: 7 additions & 3 deletions src/lib/plugins/plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"authorIcon": "https://avatars.githubusercontent.com/u/115573427?v=4",
"sourceLink": "https://github.com/wharfkit/transact-plugin-resource-provider",
"license": "BSD-3",
"version": "1.0.1",
"lastPublishedDate": "2023-09-09T00:22:30Z",
"version": "1.1.0",
"lastPublishedDate": "2024-02-05T17:39:25Z",
"readme": "# @wharfkit/transact-plugin-resource-provider\n\nA `transactPlugin` for use with the `@wharfkit/session` library that provides resources to perform transactions.\n\n## Caveats\n\n- Resource Provider API endpoint must conform to the [Resource Provider API specification](https://wharfkit.com/docs/utilities/resource-provider-spec).\n- To allow fees from the Resource Provider, the `allowFees` parameter must be specified and set to `true`.\n- Any fees must be paid in the networks system token, deployed on the `eosio.token` account using the standard token contract.\n\n## Installation\n\nThe `@wharfkit/transact-plugin-resource-provider` package is distributed as a module on [npm](https://www.npmjs.com/package/@wharfkit/transact-plugin-resource-provider).\n\n```\nyarn add @wharfkit/transact-plugin-resource-provider\n# or\nnpm install --save @wharfkit/transact-plugin-resource-provider\n```\n\n## Usage\n\nInclude when configuring the Session Kit:\n\n```ts\nimport {TransactPluginResourceProvider} from '@wharfkit/transact-plugin-resource-provider'\n\nconst kit = new SessionKit(\n {\n // ... your session kit args\n },\n {\n // ... your other options\n transactPlugins: [new TransactPluginResourceProvider()],\n }\n)\n```\n\nOr when you are manually configuring a Session:\n\n```ts\nimport {TransactPluginResourceProvider} from '@wharfkit/transact-plugin-resource-provider'\n\nconst session = new Session(\n {\n // ... your session kit args\n },\n {\n // ... your other options\n transactPlugins: [new TransactPluginResourceProvider()],\n }\n)\n```\n\nThe plugin is also capable of utilizing any API that conforms to the [Resource Provider API specification](https://forums.eoscommunity.org/t/initial-specification-for-the-resource-provider-api-endpoint/1546). To change the default endpoints, specify them in the constructor as a key/value pair using the chainId and URL.\n\n```ts\nimport {TransactPluginResourceProvider} from '@wharfkit/transact-plugin-resource-provider'\n\nconst session = new Session(\n {\n // ... your session kit args\n },\n {\n // ... your other session kit options\n transactPlugins: [\n new TransactPluginResourceProvider({\n endpoints: {\n '73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d':\n 'https://jungle4.greymass.com',\n },\n }),\n ],\n }\n)\n```\n\nThe full list of options that can be passed in during instantiation are defined in the `ResourceProviderOptions`:\n\n```ts\ninterface ResourceProviderOptions {\n // Defaults to true, determines whether or not the user will be prompted with fees.\n allowFees?: boolean\n // The API endpoints to request resources from.\n endpoints?: Record<string, string>\n // The maximum allowed fee, if a fee exists. Provides a sanity check against the API.\n maxFee?: AssetType\n}\n```\n\n## Developing\n\nYou need [Make](https://www.gnu.org/software/make/), [node.js](https://nodejs.org/en/) and [yarn](https://classic.yarnpkg.com/en/docs/install) installed.\n\nClone the repository and run `make` to checkout all dependencies and build the project. See the [Makefile](./Makefile) for other useful targets. Before submitting a pull request make sure to run `make lint`.\n\n---\n\nMade with ☕️ & ❤️ by [Greymass](https://greymass.com), if you find this useful please consider [supporting us](https://greymass.com/support-us).\n"
},
"wharfkit/wallet-plugin-anchor": {
Expand All @@ -41,6 +41,8 @@
"authorIcon": "https://avatars.githubusercontent.com/u/115573427?v=4",
"sourceLink": "https://github.com/wharfkit/wallet-plugin-anchor",
"license": "BSD-3",
"version": "1.3.0",
"lastPublishedDate": "2024-02-05T17:43:03Z",
"readme": "# @wharfkit/wallet-plugin-anchor\n\nA Session Kit wallet plugin for the [Anchor](https://www.greymass.com/anchor) wallet.\n\n## Usage\n\nInclude this wallet plugin while initializing the SessionKit.\n\n**NOTE**: This wallet plugin will only work with the SessionKit and requires a browser-based environment.\n\n```ts\nimport {WalletPluginAnchor} from '@wharfkit/wallet-plugin-anchor'\n\nconst kit = new SessionKit({\n // ... your other options\n walletPlugins: [new WalletPluginAnchor()],\n})\n```\n\nCustom buoy url and websocket class are supported.\n\n```ts\nimport WebSocket from 'isomorphic-ws'\nimport {WalletPluginAnchor} from '@wharfkit/wallet-plugin-anchor'\n\nconst kit = new SessionKit({\n // ... your other options\n walletPlugins: [\n new WalletPluginAnchor({\n buoyUrl: 'https://cb.anchor.link',\n buoyWs: Websocket,\n }),\n ],\n})\n```\n\n## Developing\n\nYou need [Make](https://www.gnu.org/software/make/), [node.js](https://nodejs.org/en/) and [yarn](https://classic.yarnpkg.com/en/docs/install) installed.\n\nClone the repository and run `make` to checkout all dependencies and build the project. See the [Makefile](./Makefile) for other useful targets. Before submitting a pull request make sure to run `make lint`.\n\n---\n\nMade with ☕️ & ❤️ by [Greymass](https://greymass.com), if you find this useful please consider [supporting us](https://greymass.com/support-us).\n"
},
"wharfkit/wallet-plugin-cloudwallet": {
Expand All @@ -55,6 +57,8 @@
"authorIcon": "https://avatars.githubusercontent.com/u/115573427?v=4",
"sourceLink": "https://github.com/wharfkit/wallet-plugin-cloudwallet",
"license": "BSD-3",
"version": "1.3.2",
"lastPublishedDate": "2024-02-05T17:43:28Z",
"readme": "# @wharfkit/wallet-plugin-cloudwallet\n\nA Session Kit wallet plugin for the [CloudWallet](https://mycloudwallet.com).\n\n## Usage\n\nInclude this wallet plugin while initializing the SessionKit.\n\n**NOTE**: This wallet plugin will only work with the SessionKit and requires a browser-based environment.\n\n```ts\nimport {WalletPluginCloudWallet} from '@wharfkit/wallet-plugin-cloudwallet'\n\nconst kit = new SessionKit({\n // ... your other options\n walletPlugins: [new WalletPluginCloudWallet()],\n})\n```\n\nIf you need to modify which chains are supported, modify the URLs being used, or alter the timeout, you can specify one or more of these paramaters during plugin initialization.\n\n```ts\nimport {WalletPluginCloudWallet} from '@wharfkit/wallet-plugin-cloudwallet'\n\nconst kit = new SessionKit({\n // ... your other options\n walletPlugins: [\n new WalletPluginCloudWallet({\n supportedChains: [\n '1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4', // WAX (Mainnet)\n ],\n url: 'https://www.mycloudwallet.com',\n autoUrl: 'https://idm-api.mycloudwallet.com/v1/accounts/auto-accept',\n loginTimeout: 300000, // 5 minutes\n }),\n ],\n})\n```\n\n## Developing\n\nYou need [Make](https://www.gnu.org/software/make/), [node.js](https://nodejs.org/en/) and [yarn](https://classic.yarnpkg.com/en/docs/install) installed.\n\nClone the repository and run `make` to checkout all dependencies and build the project. See the [Makefile](./Makefile) for other useful targets. Before submitting a pull request make sure to run `make lint`.\n\n---\n\nMade with ☕️ & ❤️ by [Greymass](https://greymass.com), if you find this useful please consider [supporting us](https://greymass.com/support-us).\n"
},
"wharfkit/wallet-plugin-scatter": {
Expand Down Expand Up @@ -217,7 +221,7 @@
"authorIcon": "https://avatars.githubusercontent.com/u/115573427?v=4",
"sourceLink": "https://github.com/wharfkit/transact-plugin-finality-checker",
"license": "BSD-3",
"readme": "# @wharfkit/transact-plugin-template\n\nA template to create a `transactPlugin` for use during a `transact` call within the `@wharfkit/session` library.\n\n## Usage\n\n- [Use this as a template.](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template)\n- Write your plugin's logic.\n- Publish it on Github or npmjs.com\n- Include it in your project and use it.\n\n## Developing\n\nYou need [Make](https://www.gnu.org/software/make/), [node.js](https://nodejs.org/en/) and [yarn](https://classic.yarnpkg.com/en/docs/install) installed.\n\nClone the repository and run `make` to checkout all dependencies and build the project. See the [Makefile](./Makefile) for other useful targets. Before submitting a pull request make sure to run `make lint`.\n\n---\n\nMade with ☕️ & ❤️ by [Greymass](https://greymass.com), if you find this useful please consider [supporting us](https://greymass.com/support-us).\n"
"readme": "# @wharfkit/transact-plugin-finality-checker\n\nA [Transact plugin](https://wharfkit.com/docs/session-kit/plugin-transact) that displays the finality status of a transaction after it has been broadcasted to the blockchain.\n\n## Usage\n\nInstall the plugin:\n\n```bash\nyarn add @wharfkit/transact-plugin-finality-checker\n```\n\nThen use it when instantiating the `SessionKit`:\n\n```js\nnew SessionKit(sessionArgs, {\n ...\n transactPlugins: [\n new TransactPluginFinalityChecker(),\n ],\n})\n\n## Developing\n\nYou need [Make](https://www.gnu.org/software/make/), [node.js](https://nodejs.org/en/) and [yarn](https://classic.yarnpkg.com/en/docs/install) installed.\n\nClone the repository and run `make` to checkout all dependencies and build the project. See the [Makefile](./Makefile) for other useful targets. Before submitting a pull request make sure to run `make lint`.\n\n---\n\nMade with ☕️ & ❤️ by [Greymass](https://greymass.com), if you find this useful please consider [supporting us](https://greymass.com/support-us).\n"
},
"wharfkit/transact-plugin-mock": {
"name": "transact-plugin-mock",
Expand Down
Loading
Loading