diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9d33a3f..5fe008c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,6 +4,7 @@ on: workflow_dispatch permissions: contents: write + id-token: write jobs: publish_package: @@ -25,6 +26,18 @@ jobs: - name: Install modules run: bun install + - name: Prepare to JSR publish + run: bun jsr + + - name: Type-check + run: tsc --noEmit + + - name: Setup Deno + uses: denoland/setup-deno@v1 + + - name: Publish package to JSR + run: deno publish --allow-dirty --unstable-sloppy-imports + - name: Install Node uses: actions/setup-node@v4 with: @@ -32,7 +45,7 @@ jobs: registry-url: "https://registry.npmjs.org" scope: "@gramio" - - name: Publish package + - name: Publish package to NPM run: npm publish --access public env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/README.md b/README.md index 0283eb7..aa76c8a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ # @gramio/auto-retry -A plugin that catches errors with the retry_after field (rate limit errors), waits for the specified time and repeats the API request. +[![npm](https://img.shields.io/npm/v/@gramio/auto-retry?logo=npm&style=flat&labelColor=000&color=3b82f6)](https://www.npmjs.org/package/@gramio/auto-retry) +[![JSR](https://jsr.io/badges/@gramio/auto-retry)](https://jsr.io/@gramio/auto-retry) +[![JSR Score](https://jsr.io/badges/@gramio/auto-retry/score)](https://jsr.io/@gramio/auto-retry) + +A plugin that catches errors with the `retry_after` field (**rate limit** errors), **waits** for the specified time and **repeats** the API request. ```ts import { Bot } from "gramio"; diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..6aa40ad --- /dev/null +++ b/deno.json @@ -0,0 +1,11 @@ +{ + "name": "@gramio/auto-retry", + "version": "0.0.3", + "exports": "./src/index.ts", + "publish": { + "include": ["deno.json", "src", "README.md", "tsconfig.json"] + }, + "imports": { + "gramio": "jsr:@gramio/core@^0.0.32" + } +} diff --git a/package.json b/package.json index e9b4ebc..78bd2ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gramio/auto-retry", - "version": "0.0.1", + "version": "0.0.2", "main": "dist/index.js", "devDependencies": { "@types/bun": "^1.0.12", diff --git a/scripts/release-jsr.ts b/scripts/release-jsr.ts new file mode 100644 index 0000000..5add437 --- /dev/null +++ b/scripts/release-jsr.ts @@ -0,0 +1,16 @@ +import { execSync } from "node:child_process"; +import fs from "node:fs"; + +const version = execSync("npm pkg get version") + .toString() + .replace(/"|\n/gi, ""); + +const jsrConfig = JSON.parse(String(fs.readFileSync("deno.json"))); + +jsrConfig.version = version; + +fs.writeFileSync("deno.json", JSON.stringify(jsrConfig, null, 4)); + +// execSync("bun x @teidesu/slow-types-compiler fix --entry deno.json"); + +console.log("Prepared to release on JSR!"); diff --git a/src/index.ts b/src/index.ts index c07e057..9aea952 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,25 @@ import { Plugin } from "gramio"; -export function autoRetry() { +/** + * A plugin that catches errors with the `retry_after` field (**rate limit** errors), **waits** for the specified time and **repeats** the API request. + * @example + * ```ts + * import { Bot } from "gramio"; + * import { autoRetry } from "@gramio/auto-retry"; + * + * const bot = new Bot(process.env.TOKEN!) + * .extend(autoRetry()) + * .command("start", async (context) => { + * for (let index = 0; index < 100; index++) { + * await context.reply(`some ${index}`); + * } + * }) + * .onStart(console.log); + * + * bot.start(); + * ``` + */ +export function autoRetry(): Plugin { return new Plugin("@gramio/auto-retry").onResponseError( async (error, api) => { if (error.payload?.retry_after) {