thirdweb 5.57.0 → 5.57.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/client.js +19 -15
- package/dist/cjs/client/client.js.map +1 -1
- package/dist/cjs/extensions/erc1155/drops/write/updateMetadata.js +2 -2
- package/dist/cjs/extensions/erc1155/drops/write/updateMetadata.js.map +1 -1
- package/dist/cjs/extensions/erc721/drops/write/updateMetadata.js +2 -2
- package/dist/cjs/extensions/erc721/drops/write/updateMetadata.js.map +1 -1
- package/dist/cjs/utils/fetch.js +4 -11
- package/dist/cjs/utils/fetch.js.map +1 -1
- package/dist/cjs/utils/jwt/is-jwt.js +7 -0
- package/dist/cjs/utils/jwt/is-jwt.js.map +1 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/client/client.js +19 -15
- package/dist/esm/client/client.js.map +1 -1
- package/dist/esm/extensions/erc1155/drops/write/updateMetadata.js +2 -2
- package/dist/esm/extensions/erc1155/drops/write/updateMetadata.js.map +1 -1
- package/dist/esm/extensions/erc721/drops/write/updateMetadata.js +2 -2
- package/dist/esm/extensions/erc721/drops/write/updateMetadata.js.map +1 -1
- package/dist/esm/utils/fetch.js +4 -11
- package/dist/esm/utils/fetch.js.map +1 -1
- package/dist/esm/utils/jwt/is-jwt.js +4 -0
- package/dist/esm/utils/jwt/is-jwt.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/client/client.d.ts +2 -2
- package/dist/types/client/client.d.ts.map +1 -1
- package/dist/types/extensions/erc1155/drops/write/updateMetadata.d.ts +1 -3
- package/dist/types/extensions/erc1155/drops/write/updateMetadata.d.ts.map +1 -1
- package/dist/types/extensions/erc721/drops/write/updateMetadata.d.ts +0 -2
- package/dist/types/extensions/erc721/drops/write/updateMetadata.d.ts.map +1 -1
- package/dist/types/utils/fetch.d.ts.map +1 -1
- package/dist/types/utils/jwt/is-jwt.d.ts +3 -0
- package/dist/types/utils/jwt/is-jwt.d.ts.map +1 -0
- package/dist/types/utils/jwt/types.d.ts +1 -0
- package/dist/types/utils/jwt/types.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +11 -11
- package/src/client/client.test.ts +17 -2
- package/src/client/client.ts +23 -17
- package/src/extensions/erc1155/drops/write/updateMetadata.test.ts +0 -1
- package/src/extensions/erc1155/drops/write/updateMetadata.ts +4 -7
- package/src/extensions/erc721/drops/write/updateMetadata.test.ts +0 -2
- package/src/extensions/erc721/drops/write/updateMetadata.ts +2 -4
- package/src/extensions/marketplace/direct-listings/direct-listings.test.ts +317 -394
- package/src/utils/fetch.test.ts +20 -0
- package/src/utils/fetch.ts +6 -14
- package/src/utils/jwt/is-jwt.ts +5 -0
- package/src/utils/jwt/types.ts +2 -0
- package/src/version.ts +1 -1
package/src/utils/fetch.test.ts
CHANGED
@@ -52,6 +52,26 @@ describe("getClientFetch", () => {
|
|
52
52
|
);
|
53
53
|
});
|
54
54
|
|
55
|
+
it("should send a bearer token if secret key is a JWT", () => {
|
56
|
+
vi.spyOn(global, "fetch").mockResolvedValue(new Response());
|
57
|
+
const clientFetch = getClientFetch({
|
58
|
+
clientId: "test-client-id",
|
59
|
+
secretKey: "foo.bar.baz",
|
60
|
+
});
|
61
|
+
clientFetch("https://api.thirdweb.com/test");
|
62
|
+
|
63
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
64
|
+
"https://api.thirdweb.com/test",
|
65
|
+
expect.objectContaining({
|
66
|
+
headers: expect.any(Headers),
|
67
|
+
}),
|
68
|
+
);
|
69
|
+
|
70
|
+
// biome-ignore lint/suspicious/noExplicitAny: `any` type ok for tests
|
71
|
+
const headers = (global.fetch as any).mock.calls[0][1].headers;
|
72
|
+
expect(headers.get("authorization")).toBe("Bearer foo.bar.baz");
|
73
|
+
});
|
74
|
+
|
55
75
|
it("should abort the request after timeout", async () => {
|
56
76
|
vi.useFakeTimers();
|
57
77
|
const abortSpy = vi.spyOn(AbortController.prototype, "abort");
|
package/src/utils/fetch.ts
CHANGED
@@ -7,6 +7,7 @@ import {
|
|
7
7
|
detectOS,
|
8
8
|
detectPlatform,
|
9
9
|
} from "./detect-platform.js";
|
10
|
+
import { isJWT } from "./jwt/is-jwt.js";
|
10
11
|
|
11
12
|
const DEFAULT_REQUEST_TIMEOUT = 60000;
|
12
13
|
|
@@ -31,7 +32,11 @@ export function getClientFetch(client: ThirdwebClient, ecosystem?: Ecosystem) {
|
|
31
32
|
if (!headers) {
|
32
33
|
headers = new Headers();
|
33
34
|
}
|
34
|
-
const authToken =
|
35
|
+
const authToken =
|
36
|
+
client.secretKey && isJWT(client.secretKey)
|
37
|
+
? client.secretKey
|
38
|
+
: undefined;
|
39
|
+
|
35
40
|
// if we have an auth token set, use that (thirdweb.com/dashboard sets this for the user)
|
36
41
|
// pay urls should never send the auth token, because we always want the "developer" to be the one making the request, not the "end user"
|
37
42
|
if (authToken && !isPayUrl(url)) {
|
@@ -185,16 +190,3 @@ function parseOs(os: OperatingSystem | NodeJS.Platform) {
|
|
185
190
|
return osLowerCased.replace(/\s/gi, "_");
|
186
191
|
}
|
187
192
|
}
|
188
|
-
|
189
|
-
function getTWAuthToken(): string | null {
|
190
|
-
if (
|
191
|
-
typeof globalThis !== "undefined" &&
|
192
|
-
"TW_AUTH_TOKEN" in globalThis &&
|
193
|
-
// biome-ignore lint/suspicious/noExplicitAny: get around globalThis typing
|
194
|
-
typeof (globalThis as any).TW_AUTH_TOKEN === "string"
|
195
|
-
) {
|
196
|
-
// biome-ignore lint/suspicious/noExplicitAny: get around globalThis typing
|
197
|
-
return (globalThis as any).TW_AUTH_TOKEN as string;
|
198
|
-
}
|
199
|
-
return null;
|
200
|
-
}
|
package/src/utils/jwt/types.ts
CHANGED
package/src/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = "5.57.
|
1
|
+
export const version = "5.57.1";
|