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.
Files changed (47) hide show
  1. package/dist/cjs/client/client.js +19 -15
  2. package/dist/cjs/client/client.js.map +1 -1
  3. package/dist/cjs/extensions/erc1155/drops/write/updateMetadata.js +2 -2
  4. package/dist/cjs/extensions/erc1155/drops/write/updateMetadata.js.map +1 -1
  5. package/dist/cjs/extensions/erc721/drops/write/updateMetadata.js +2 -2
  6. package/dist/cjs/extensions/erc721/drops/write/updateMetadata.js.map +1 -1
  7. package/dist/cjs/utils/fetch.js +4 -11
  8. package/dist/cjs/utils/fetch.js.map +1 -1
  9. package/dist/cjs/utils/jwt/is-jwt.js +7 -0
  10. package/dist/cjs/utils/jwt/is-jwt.js.map +1 -0
  11. package/dist/cjs/version.js +1 -1
  12. package/dist/esm/client/client.js +19 -15
  13. package/dist/esm/client/client.js.map +1 -1
  14. package/dist/esm/extensions/erc1155/drops/write/updateMetadata.js +2 -2
  15. package/dist/esm/extensions/erc1155/drops/write/updateMetadata.js.map +1 -1
  16. package/dist/esm/extensions/erc721/drops/write/updateMetadata.js +2 -2
  17. package/dist/esm/extensions/erc721/drops/write/updateMetadata.js.map +1 -1
  18. package/dist/esm/utils/fetch.js +4 -11
  19. package/dist/esm/utils/fetch.js.map +1 -1
  20. package/dist/esm/utils/jwt/is-jwt.js +4 -0
  21. package/dist/esm/utils/jwt/is-jwt.js.map +1 -0
  22. package/dist/esm/version.js +1 -1
  23. package/dist/types/client/client.d.ts +2 -2
  24. package/dist/types/client/client.d.ts.map +1 -1
  25. package/dist/types/extensions/erc1155/drops/write/updateMetadata.d.ts +1 -3
  26. package/dist/types/extensions/erc1155/drops/write/updateMetadata.d.ts.map +1 -1
  27. package/dist/types/extensions/erc721/drops/write/updateMetadata.d.ts +0 -2
  28. package/dist/types/extensions/erc721/drops/write/updateMetadata.d.ts.map +1 -1
  29. package/dist/types/utils/fetch.d.ts.map +1 -1
  30. package/dist/types/utils/jwt/is-jwt.d.ts +3 -0
  31. package/dist/types/utils/jwt/is-jwt.d.ts.map +1 -0
  32. package/dist/types/utils/jwt/types.d.ts +1 -0
  33. package/dist/types/utils/jwt/types.d.ts.map +1 -1
  34. package/dist/types/version.d.ts +1 -1
  35. package/package.json +11 -11
  36. package/src/client/client.test.ts +17 -2
  37. package/src/client/client.ts +23 -17
  38. package/src/extensions/erc1155/drops/write/updateMetadata.test.ts +0 -1
  39. package/src/extensions/erc1155/drops/write/updateMetadata.ts +4 -7
  40. package/src/extensions/erc721/drops/write/updateMetadata.test.ts +0 -2
  41. package/src/extensions/erc721/drops/write/updateMetadata.ts +2 -4
  42. package/src/extensions/marketplace/direct-listings/direct-listings.test.ts +317 -394
  43. package/src/utils/fetch.test.ts +20 -0
  44. package/src/utils/fetch.ts +6 -14
  45. package/src/utils/jwt/is-jwt.ts +5 -0
  46. package/src/utils/jwt/types.ts +2 -0
  47. package/src/version.ts +1 -1
@@ -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");
@@ -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 = getTWAuthToken();
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
- }
@@ -0,0 +1,5 @@
1
+ import type { JWTString } from "./types.js";
2
+
3
+ export function isJWT(str: string): str is JWTString {
4
+ return str.split(".").length === 3;
5
+ }
@@ -8,3 +8,5 @@ export type JWTPayload<Tctx = unknown> = {
8
8
  jti: string;
9
9
  ctx?: Tctx;
10
10
  };
11
+
12
+ export type JWTString = `${string}.${string}.${string}`;
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.57.0";
1
+ export const version = "5.57.1";