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
@@ -14,7 +14,6 @@ describe("client", () => {
14
14
  expect(client.secretKey).toBe("bar");
15
15
  });
16
16
  it("should ignore clientId if secretKey is provided", () => {
17
- // @ts-expect-error - testing invalid input
18
17
  const client = createThirdwebClient({ clientId: "foo", secretKey: "bar" });
19
18
  expect(client.clientId).toBe(computeClientIdFromSecretKey("bar"));
20
19
  expect(client.secretKey).toBe("bar");
@@ -22,7 +21,23 @@ describe("client", () => {
22
21
  it("should throw an error if neither clientId nor secretKey is provided", () => {
23
22
  // @ts-expect-error - testing invalid input
24
23
  expect(() => createThirdwebClient({})).toThrowError(
25
- "clientId or secretKey must be provided",
24
+ /clientId or secretKey must be provided/,
26
25
  );
27
26
  });
27
+
28
+ describe("jwt", () => {
29
+ it("should accept a jwt being passed", () => {
30
+ const client = createThirdwebClient({
31
+ clientId: "foo",
32
+ secretKey: "bar.baz.qux",
33
+ });
34
+ expect(client.clientId).toBe("foo");
35
+ expect(client.secretKey).toBe("bar.baz.qux");
36
+ });
37
+ it("should throw if clientId is missing with JWT input", () => {
38
+ expect(() =>
39
+ createThirdwebClient({ secretKey: "bar.baz.qux" }),
40
+ ).toThrowError(/clientId must be provided when using a JWT secretKey/);
41
+ });
42
+ });
28
43
  });
@@ -1,4 +1,5 @@
1
1
  import { computeClientIdFromSecretKey } from "../utils/client-id.js";
2
+ import { isJWT } from "../utils/jwt/is-jwt.js";
2
3
  import type { Prettify } from "../utils/type-utils.js";
3
4
 
4
5
  type FetchConfig = {
@@ -54,10 +55,10 @@ export type CreateThirdwebClientOptions = Prettify<
54
55
  (
55
56
  | {
56
57
  clientId: string;
57
- secretKey?: never;
58
+ secretKey?: string;
58
59
  }
59
60
  | {
60
- clientId?: never;
61
+ clientId?: string;
61
62
  secretKey: string;
62
63
  }
63
64
  ) &
@@ -102,23 +103,28 @@ export function createThirdwebClient(
102
103
  options: CreateThirdwebClientOptions,
103
104
  ): ThirdwebClient {
104
105
  const { clientId, secretKey, ...rest } = options;
105
- // if secretKey is provided, compute the clientId from it (and ignore any clientId passed in)
106
+
107
+ let realClientId: string | undefined = clientId;
108
+
106
109
  if (secretKey) {
107
- return {
108
- ...rest,
109
- clientId: computeClientIdFromSecretKey(secretKey),
110
- secretKey,
111
- } as const;
110
+ if (isJWT(secretKey)) {
111
+ // when passing a JWT as secret key we HAVE to also have a clientId
112
+ if (!clientId) {
113
+ throw new Error("clientId must be provided when using a JWT secretKey");
114
+ }
115
+ } else {
116
+ realClientId = computeClientIdFromSecretKey(secretKey);
117
+ }
112
118
  }
113
- // otherwise if clientId is provided, use it
114
- if (clientId) {
115
- return {
116
- ...rest,
117
- clientId: options.clientId,
118
- secretKey: undefined,
119
- } as const;
119
+
120
+ // only path we get here is if we have no secretKey and no clientId
121
+ if (!realClientId) {
122
+ throw new Error("clientId or secretKey must be provided");
120
123
  }
121
124
 
122
- // otherwise throw an error
123
- throw new Error("clientId or secretKey must be provided");
125
+ return {
126
+ ...rest,
127
+ clientId: realClientId,
128
+ secretKey,
129
+ } as const;
124
130
  }
@@ -41,7 +41,6 @@ describe.runIf(process.env.TW_SECRET_KEY)("updateMetadata ERC1155", () => {
41
41
  contract,
42
42
  targetTokenId: 1n,
43
43
  newMetadata: { name: "token 1 - updated" },
44
- client,
45
44
  });
46
45
  await sendAndConfirmTransaction({ transaction: updateTx, account });
47
46
 
@@ -1,19 +1,16 @@
1
+ import type { BaseTransactionOptions } from "../../../../transaction/types.js";
2
+ import type { NFT, NFTInput } from "../../../../utils/nft/parseNft.js";
1
3
  import * as BaseURICount from "../../../erc721/__generated__/IBatchMintMetadata/read/getBaseURICount.js";
2
4
  import * as BatchAtIndex from "../../__generated__/BatchMintMetadata/read/getBatchIdAtIndex.js";
3
5
  import * as BatchBaseURI from "../../__generated__/DropERC1155/write/updateBatchBaseURI.js";
4
6
  import * as GetNFT from "../../read/getNFT.js";
5
7
 
6
- import type { ThirdwebClient } from "../../../../client/client.js";
7
- import type { BaseTransactionOptions } from "../../../../transaction/types.js";
8
- import type { NFT, NFTInput } from "../../../../utils/nft/parseNft.js";
9
-
10
8
  /**
11
9
  * @extension ERC1155
12
10
  */
13
11
  export type UpdateMetadataParams = {
14
12
  targetTokenId: bigint;
15
13
  newMetadata: NFTInput;
16
- client: ThirdwebClient;
17
14
  };
18
15
 
19
16
  /**
@@ -22,7 +19,7 @@ export type UpdateMetadataParams = {
22
19
  export async function getUpdateMetadataParams(
23
20
  options: BaseTransactionOptions<UpdateMetadataParams>,
24
21
  ): Promise<BatchBaseURI.UpdateBatchBaseURIParams> {
25
- const { contract, targetTokenId, newMetadata, client } = options;
22
+ const { contract, targetTokenId, newMetadata } = options;
26
23
  const batchCount = await BaseURICount.getBaseURICount(options);
27
24
  if (batchCount === 0n) {
28
25
  throw new Error(
@@ -75,7 +72,7 @@ export async function getUpdateMetadataParams(
75
72
  const { uploadOrExtractURIs } = await import("../../../../utils/ipfs.js");
76
73
  const batchOfUris = await uploadOrExtractURIs(
77
74
  newMetadatas,
78
- client,
75
+ contract.client,
79
76
  Number(startTokenId),
80
77
  );
81
78
 
@@ -42,7 +42,6 @@ describe.runIf(process.env.TW_SECRET_KEY)("updateMetadata ERC721", () => {
42
42
  contract,
43
43
  targetTokenId: 1n,
44
44
  newMetadata: { name: "token 1 - updated" },
45
- client,
46
45
  });
47
46
  await sendAndConfirmTransaction({ transaction: updateTx, account });
48
47
 
@@ -74,7 +73,6 @@ describe.runIf(process.env.TW_SECRET_KEY)("updateMetadata ERC721", () => {
74
73
  contract,
75
74
  targetTokenId: 0n,
76
75
  newMetadata: { name: "token 1 - updated" },
77
- client,
78
76
  });
79
77
  await expect(
80
78
  sendAndConfirmTransaction({ transaction: updateTx, account }),
@@ -1,4 +1,3 @@
1
- import type { ThirdwebClient } from "../../../../client/client.js";
2
1
  import type { BaseTransactionOptions } from "../../../../transaction/types.js";
3
2
  import type { NFT, NFTInput } from "../../../../utils/nft/parseNft.js";
4
3
  import * as BatchBaseURI from "../../__generated__/DropERC721/write/updateBatchBaseURI.js";
@@ -12,7 +11,6 @@ import * as GetNFT from "../../read/getNFT.js";
12
11
  export type UpdateMetadataParams = {
13
12
  targetTokenId: bigint;
14
13
  newMetadata: NFTInput;
15
- client: ThirdwebClient;
16
14
  };
17
15
 
18
16
  /**
@@ -21,7 +19,7 @@ export type UpdateMetadataParams = {
21
19
  export async function getUpdateMetadataParams(
22
20
  options: BaseTransactionOptions<UpdateMetadataParams>,
23
21
  ): Promise<BatchBaseURI.UpdateBatchBaseURIParams> {
24
- const { contract, targetTokenId, newMetadata, client } = options;
22
+ const { contract, targetTokenId, newMetadata } = options;
25
23
  const batchCount = await BaseURICount.getBaseURICount(options);
26
24
  if (batchCount === 0n) {
27
25
  throw new Error(
@@ -76,7 +74,7 @@ export async function getUpdateMetadataParams(
76
74
  const { uploadOrExtractURIs } = await import("../../../../utils/ipfs.js");
77
75
  const batchOfUris = await uploadOrExtractURIs(
78
76
  newMetadatas,
79
- client,
77
+ contract.client,
80
78
  Number(startTokenId),
81
79
  );
82
80