Skip to content

Commit

Permalink
Refactor build and deploy scripts, add ExtendedRequestInit interface
Browse files Browse the repository at this point in the history
  • Loading branch information
mikelxc committed Feb 20, 2024
1 parent 21cffdd commit 653cfff
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ jobs:
with:
bun-version: latest
- run: bun install
- run: bun run build
- run: npm publish
- run: bun run publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
},
"scripts": {
"test": "bun test",
"build": "rm -rf ./dist && rm ./tsconfig.tsbuildinfo && bun build ./src/index.ts --outdir=./dist/src --target=node --format=esm --minify --sourcemap=external && bun build ./src/utils/index.ts --outdir=./dist/src/utils --target=node --format=esm --minify --sourcemap=external && bun tsc --emitDeclarationOnly"
"build": "rm -rf ./dist && rm ./tsconfig.tsbuildinfo && bun build ./src/index.ts --outdir=./dist/src --target=node --format=esm --minify --sourcemap=external && bun build ./src/utils/index.ts --outdir=./dist/src/utils --target=node --format=esm --minify --sourcemap=external && bun tsc --emitDeclarationOnly",
"deploy": "bun build ./src/index.ts --outdir=./dist/src --target=node --format=esm --minify --sourcemap=external && bun build ./src/utils/index.ts --outdir=./dist/src/utils --target=node --format=esm --minify --sourcemap=external && bun tsc --emitDeclarationOnly && npm publish --access public"
},
"repository": {
"type": "git",
Expand Down
21 changes: 15 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import type {
HexString,
} from "./types";
export type * from "./types";
interface ExtendedRequestInit extends RequestInit {
cache?: "no-store" | "force-cache";
}
export default class Client {
private baseUrl = "https://paymagicapi.com/v1";
private credentials: OAuthCredentials;
Expand All @@ -29,8 +32,8 @@ export default class Client {
client_secret: this.credentials.clientSecret,
}),
cache: "no-store",
})
.then((res) => res.json())
} as ExtendedRequestInit)
.then((res) => res.json() as Promise<{ access_token: string }>)
.then((data) => data.access_token);
this.token = response;
this.tokenExpiry = new Date(new Date().getTime() + 30000);
Expand All @@ -57,7 +60,7 @@ export default class Client {
return this.tx(data);
}
if (response.status === 200) {
const resData = await response.json();
const resData = (await response.json()) as { txHash: HexString };
return { txHash: resData.txHash };
}
return {
Expand Down Expand Up @@ -91,7 +94,11 @@ export default class Client {
return this.sign(data);
}
if (response.status === 200) {
const data = await response.json();
const data = (await response.json()) as {
hash: `0x${string}`;
signature: `0x${string}`;
type: "string" | "hash" | "typedData";
};
return data;
}
return {
Expand All @@ -110,11 +117,13 @@ export default class Client {
method: "POST",
body: JSON.stringify({ userIds: [userIds].toString() }),
})
.then((res) => res.json())
.then(
(res) => res.json() as Promise<{ users: { accountAddress: Address }[] }>
)
.then((data) => data.users)
.catch((err) => {
console.error(err);
return "";
return [];
});
const addresses = resolvedUser.map(
(u: { accountAddress: Address }) => u.accountAddress
Expand Down

0 comments on commit 653cfff

Please sign in to comment.