Skip to content

Commit

Permalink
chore: add publisher to JSR
Browse files Browse the repository at this point in the history
  • Loading branch information
kravetsone committed May 12, 2024
1 parent 3711f19 commit 17003f7
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 4 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on: workflow_dispatch

permissions:
contents: write
id-token: write

jobs:
publish_package:
Expand All @@ -25,14 +26,26 @@ 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:
node-version: "20.x"
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 }}
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
11 changes: 11 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
16 changes: 16 additions & 0 deletions scripts/release-jsr.ts
Original file line number Diff line number Diff line change
@@ -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!");
21 changes: 20 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit 17003f7

Please sign in to comment.