@mysten/kiosk 1.3.13 → 1.4.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.
@@ -1 +1 @@
1
- {"version":3,"file":"transfer-policy.mjs","names":["TransferPolicyStruct","TransferPolicyCapStruct"],"sources":["../../src/query/transfer-policy.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { isValidSuiAddress } from '@mysten/sui/utils';\n\nimport {\n\tTransferPolicyCap as TransferPolicyCapStruct,\n\tTransferPolicy as TransferPolicyStruct,\n} from '../contracts/0x2/transfer_policy.js';\nimport type { KioskCompatibleClient, TransferPolicy, TransferPolicyCap } from '../types/index.js';\nimport {\n\tTRANSFER_POLICY_CAP_TYPE,\n\tTRANSFER_POLICY_CREATED_EVENT,\n\tTRANSFER_POLICY_TYPE,\n} from '../types/index.js';\nimport { queryEvents } from './client-utils.js';\n\n/**\n * Searches the `TransferPolicy`-s for the given type. The search is performed via\n * the `TransferPolicyCreated` event. The policy can either be owned or shared,\n * and the caller needs to filter the results accordingly (ie single owner can not\n * be accessed by anyone but the owner).\n *\n * This method requires event querying support (JSON-RPC or GraphQL clients).\n * gRPC clients do not support event querying and will throw an error.\n *\n * @param client - The Sui client (must support event querying)\n * @param type - The type of the asset (e.g., \"0x123::nft::NFT\")\n * @throws Error if the client doesn't support event querying\n */\nexport async function queryTransferPolicy(\n\tclient: KioskCompatibleClient,\n\ttype: string,\n): Promise<TransferPolicy[]> {\n\tconst data = await queryEvents(client, `${TRANSFER_POLICY_CREATED_EVENT}<${type}>`);\n\n\tconst search = data.map((event) => event.json as { id: string });\n\n\tconst { objects } = await client.core.getObjects({\n\t\tobjectIds: search.map((policy: { id: string }) => policy.id),\n\t\tinclude: { content: true },\n\t});\n\n\treturn objects\n\t\t.filter((obj) => !(obj instanceof Error) && obj.content)\n\t\t.map((obj) => {\n\t\t\tif (obj instanceof Error) {\n\t\t\t\tthrow obj;\n\t\t\t}\n\n\t\t\tif (!obj.content) {\n\t\t\t\tthrow new Error(`Invalid policy: ${obj.objectId}, expected object with content`);\n\t\t\t}\n\n\t\t\tconst parsed = TransferPolicyStruct.parse(obj.content);\n\n\t\t\treturn {\n\t\t\t\tid: obj.objectId,\n\t\t\t\ttype: `${TRANSFER_POLICY_TYPE}<${type}>`,\n\t\t\t\towner: obj.owner,\n\t\t\t\trules: parsed.rules.contents.map((rule) => rule.name),\n\t\t\t\tbalance: parsed.balance.value.toString(),\n\t\t\t} as TransferPolicy;\n\t\t});\n}\n\n/**\n * Fetches all TransferPolicyCap objects owned by an address for a specific type.\n *\n * @param client - The Sui client\n * @param address - The owner address\n * @param type - The type of the asset\n * @returns Array of TransferPolicyCap objects\n */\nexport async function queryTransferPolicyCapsByType(\n\tclient: KioskCompatibleClient,\n\taddress: string,\n\ttype: string,\n): Promise<TransferPolicyCap[]> {\n\tif (!isValidSuiAddress(address)) return [];\n\n\tconst policies = [];\n\tlet hasNextPage = true;\n\tlet cursor: string | null = null;\n\n\twhile (hasNextPage) {\n\t\tconst result: Awaited<ReturnType<typeof client.core.listOwnedObjects>> =\n\t\t\tawait client.core.listOwnedObjects({\n\t\t\t\towner: address,\n\t\t\t\ttype: `${TRANSFER_POLICY_CAP_TYPE}<${type}>`,\n\t\t\t\tcursor,\n\t\t\t\tlimit: 50,\n\t\t\t\tinclude: {\n\t\t\t\t\tcontent: true,\n\t\t\t\t},\n\t\t\t});\n\n\t\tfor (const obj of result.objects) {\n\t\t\tif (obj.content) {\n\t\t\t\tpolicies.push({\n\t\t\t\t\tpolicyId: TransferPolicyCapStruct.parse(obj.content).policy_id,\n\t\t\t\t\tpolicyCapId: obj.objectId,\n\t\t\t\t\ttype,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\thasNextPage = result.hasNextPage;\n\t\tcursor = result.cursor;\n\t}\n\n\treturn policies;\n}\n\n/**\n * Fetches all TransferPolicyCap objects owned by an address (all types).\n *\n * Uses struct-level filtering (without type parameters) to efficiently query\n * only TransferPolicyCap objects. This matches all generic instantiations\n * (e.g., TransferPolicyCap<T> for any T) and is supported natively by all clients.\n *\n * @param client - The Sui client\n * @param address - The owner address\n * @returns Array of TransferPolicyCap objects or undefined if address is invalid\n */\nexport async function queryOwnedTransferPolicies(\n\tclient: KioskCompatibleClient,\n\taddress: string,\n): Promise<TransferPolicyCap[] | undefined> {\n\tif (!isValidSuiAddress(address)) return;\n\n\tlet hasNextPage = true;\n\tlet cursor: string | null = null;\n\tconst policies: TransferPolicyCap[] = [];\n\n\twhile (hasNextPage) {\n\t\tconst result: Awaited<ReturnType<typeof client.core.listOwnedObjects>> =\n\t\t\tawait client.core.listOwnedObjects({\n\t\t\t\towner: address,\n\t\t\t\ttype: TRANSFER_POLICY_CAP_TYPE,\n\t\t\t\tcursor,\n\t\t\t\tlimit: 50,\n\t\t\t\tinclude: {\n\t\t\t\t\tcontent: true,\n\t\t\t\t},\n\t\t\t});\n\n\t\t// All results are TransferPolicyCap objects, extract the type parameter\n\t\tfor (const obj of result.objects) {\n\t\t\tif (obj.content) {\n\t\t\t\t// Extract the type parameter T from \"0x2::transfer_policy::TransferPolicyCap<T>\"\n\t\t\t\tconst objectType = obj.type!.replace(`${TRANSFER_POLICY_CAP_TYPE}<`, '').slice(0, -1);\n\n\t\t\t\tpolicies.push({\n\t\t\t\t\tpolicyId: TransferPolicyCapStruct.parse(obj.content).policy_id,\n\t\t\t\t\tpolicyCapId: obj.objectId,\n\t\t\t\t\ttype: objectType,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\thasNextPage = result.hasNextPage;\n\t\tcursor = result.cursor;\n\t}\n\n\treturn policies;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA8BA,eAAsB,oBACrB,QACA,MAC4B;CAG5B,MAAM,UAFO,MAAM,YAAY,QAAQ,GAAG,8BAA8B,GAAG,KAAK,GAAG,EAE/D,KAAK,UAAU,MAAM,KAAuB;CAEhE,MAAM,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QAAO,aAAa;EACnB,MAAM,SACL,MAAM,OAAO,KAAK,iBAAiB;GAClC,OAAO;GACP,MAAM;GACN;GACA,OAAO;GACP,SAAS,EACR,SAAS,MACT;GACD,CAAC;AAGH,OAAK,MAAM,OAAO,OAAO,QACxB,KAAI,IAAI,SAAS;GAEhB,MAAM,aAAa,IAAI,KAAM,QAAQ,GAAG,yBAAyB,IAAI,GAAG,CAAC,MAAM,GAAG,GAAG;AAErF,YAAS,KAAK;IACb,UAAUA,kBAAwB,MAAM,IAAI,QAAQ,CAAC;IACrD,aAAa,IAAI;IACjB,MAAM;IACN,CAAC;;AAIJ,gBAAc,OAAO;AACrB,WAAS,OAAO;;AAGjB,QAAO"}
1
+ {"version":3,"file":"transfer-policy.mjs","names":["TransferPolicyStruct","TransferPolicyCapStruct"],"sources":["../../src/query/transfer-policy.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { isValidSuiAddress } from '@mysten/sui/utils';\n\nimport {\n\tTransferPolicyCap as TransferPolicyCapStruct,\n\tTransferPolicy as TransferPolicyStruct,\n} from '../contracts/0x2/transfer_policy.js';\nimport type { KioskCompatibleClient, TransferPolicy, TransferPolicyCap } from '../types/index.js';\nimport {\n\tTRANSFER_POLICY_CAP_TYPE,\n\tTRANSFER_POLICY_CREATED_EVENT,\n\tTRANSFER_POLICY_TYPE,\n} from '../types/index.js';\nimport { queryEvents } from './client-utils.js';\n\n/**\n * Searches the `TransferPolicy`-s for the given type. The search is performed via\n * the `TransferPolicyCreated` event. The policy can either be owned or shared,\n * and the caller needs to filter the results accordingly (ie single owner can not\n * be accessed by anyone but the owner).\n *\n * @param client - A Sui client with the Core API\n * @param type - The type of the asset (e.g., \"0x123::nft::NFT\")\n */\nexport async function queryTransferPolicy(\n\tclient: KioskCompatibleClient,\n\ttype: string,\n): Promise<TransferPolicy[]> {\n\tconst data = await queryEvents(client, `${TRANSFER_POLICY_CREATED_EVENT}<${type}>`);\n\n\tconst search = data.map((event) => event.json as { id: string });\n\n\tconst { objects } = await client.core.getObjects({\n\t\tobjectIds: search.map((policy: { id: string }) => policy.id),\n\t\tinclude: { content: true },\n\t});\n\n\treturn objects\n\t\t.filter((obj) => !(obj instanceof Error) && obj.content)\n\t\t.map((obj) => {\n\t\t\tif (obj instanceof Error) {\n\t\t\t\tthrow obj;\n\t\t\t}\n\n\t\t\tif (!obj.content) {\n\t\t\t\tthrow new Error(`Invalid policy: ${obj.objectId}, expected object with content`);\n\t\t\t}\n\n\t\t\tconst parsed = TransferPolicyStruct.parse(obj.content);\n\n\t\t\treturn {\n\t\t\t\tid: obj.objectId,\n\t\t\t\ttype: `${TRANSFER_POLICY_TYPE}<${type}>`,\n\t\t\t\towner: obj.owner,\n\t\t\t\trules: parsed.rules.contents.map((rule) => rule.name),\n\t\t\t\tbalance: parsed.balance.value.toString(),\n\t\t\t} as TransferPolicy;\n\t\t});\n}\n\n/**\n * Fetches all TransferPolicyCap objects owned by an address for a specific type.\n *\n * @param client - The Sui client\n * @param address - The owner address\n * @param type - The type of the asset\n * @returns Array of TransferPolicyCap objects\n */\nexport async function queryTransferPolicyCapsByType(\n\tclient: KioskCompatibleClient,\n\taddress: string,\n\ttype: string,\n): Promise<TransferPolicyCap[]> {\n\tif (!isValidSuiAddress(address)) return [];\n\n\tconst policies = [];\n\tlet hasNextPage = true;\n\tlet cursor: string | null = null;\n\n\twhile (hasNextPage) {\n\t\tconst result: Awaited<ReturnType<typeof client.core.listOwnedObjects>> =\n\t\t\tawait client.core.listOwnedObjects({\n\t\t\t\towner: address,\n\t\t\t\ttype: `${TRANSFER_POLICY_CAP_TYPE}<${type}>`,\n\t\t\t\tcursor,\n\t\t\t\tlimit: 50,\n\t\t\t\tinclude: {\n\t\t\t\t\tcontent: true,\n\t\t\t\t},\n\t\t\t});\n\n\t\tfor (const obj of result.objects) {\n\t\t\tif (obj.content) {\n\t\t\t\tpolicies.push({\n\t\t\t\t\tpolicyId: TransferPolicyCapStruct.parse(obj.content).policy_id,\n\t\t\t\t\tpolicyCapId: obj.objectId,\n\t\t\t\t\ttype,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\thasNextPage = result.hasNextPage;\n\t\tcursor = result.cursor;\n\t}\n\n\treturn policies;\n}\n\n/**\n * Fetches all TransferPolicyCap objects owned by an address (all types).\n *\n * Uses struct-level filtering (without type parameters) to efficiently query\n * only TransferPolicyCap objects. This matches all generic instantiations\n * (e.g., TransferPolicyCap<T> for any T) and is supported natively by all clients.\n *\n * @param client - The Sui client\n * @param address - The owner address\n * @returns Array of TransferPolicyCap objects or undefined if address is invalid\n */\nexport async function queryOwnedTransferPolicies(\n\tclient: KioskCompatibleClient,\n\taddress: string,\n): Promise<TransferPolicyCap[] | undefined> {\n\tif (!isValidSuiAddress(address)) return;\n\n\tlet hasNextPage = true;\n\tlet cursor: string | null = null;\n\tconst policies: TransferPolicyCap[] = [];\n\n\twhile (hasNextPage) {\n\t\tconst result: Awaited<ReturnType<typeof client.core.listOwnedObjects>> =\n\t\t\tawait client.core.listOwnedObjects({\n\t\t\t\towner: address,\n\t\t\t\ttype: TRANSFER_POLICY_CAP_TYPE,\n\t\t\t\tcursor,\n\t\t\t\tlimit: 50,\n\t\t\t\tinclude: {\n\t\t\t\t\tcontent: true,\n\t\t\t\t},\n\t\t\t});\n\n\t\t// All results are TransferPolicyCap objects, extract the type parameter\n\t\tfor (const obj of result.objects) {\n\t\t\tif (obj.content) {\n\t\t\t\t// Extract the type parameter T from \"0x2::transfer_policy::TransferPolicyCap<T>\"\n\t\t\t\tconst objectType = obj.type!.replace(`${TRANSFER_POLICY_CAP_TYPE}<`, '').slice(0, -1);\n\n\t\t\t\tpolicies.push({\n\t\t\t\t\tpolicyId: TransferPolicyCapStruct.parse(obj.content).policy_id,\n\t\t\t\t\tpolicyCapId: obj.objectId,\n\t\t\t\t\ttype: objectType,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\thasNextPage = result.hasNextPage;\n\t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AAC;AAIJ,gBAAc,OAAO;AACrB,WAAS,OAAO;;AAGjB,QAAO;;;;;;;;;;;;;AAcR,eAAsB,2BACrB,QACA,SAC2C;AAC3C,KAAI,CAAC,kBAAkB,QAAQ,CAAE;CAEjC,IAAI,cAAc;CAClB,IAAI,SAAwB;CAC5B,MAAM,WAAgC,EAAE;AAExC,QAAO,aAAa;EACnB,MAAM,SACL,MAAM,OAAO,KAAK,iBAAiB;GAClC,OAAO;GACP,MAAM;GACN;GACA,OAAO;GACP,SAAS,EACR,SAAS,MACT;GACD,CAAC;AAGH,OAAK,MAAM,OAAO,OAAO,QACxB,KAAI,IAAI,SAAS;GAEhB,MAAM,aAAa,IAAI,KAAM,QAAQ,GAAG,yBAAyB,IAAI,GAAG,CAAC,MAAM,GAAG,GAAG;AAErF,YAAS,KAAK;IACb,UAAUA,kBAAwB,MAAM,IAAI,QAAQ,CAAC;IACrD,aAAa,IAAI;IACjB,MAAM;IACN,CAAC;;AAIJ,gBAAc,OAAO;AACrB,WAAS,OAAO;;AAGjB,QAAO"}
@@ -2,9 +2,7 @@ import { BaseRulePackageIds } from "../constants.mjs";
2
2
  import { FetchKioskOptions, ItemId, ItemReference, ItemValue, KIOSK_ITEM, KIOSK_LISTING, KIOSK_LOCK, KIOSK_MODULE, KIOSK_OWNER_CAP, KIOSK_PURCHASE_CAP, KIOSK_TYPE, Kiosk, KioskData, KioskDisplay, KioskExtension, KioskExtensionOverview, KioskItem, KioskListing, KioskOwnerCap, ObjectWithDisplay, OwnedKiosks, PagedKioskData, Price, PurchaseAndResolvePoliciesResponse, PurchaseCap, PurchaseOptionalParams, PurchaseOptions } from "./kiosk.mjs";
3
3
  import { KIOSK_LOCK_RULE, ROYALTY_RULE, RuleResolvingParams, TRANSFER_POLICY_CAP_TYPE, TRANSFER_POLICY_CREATED_EVENT, TRANSFER_POLICY_MODULE, TRANSFER_POLICY_TYPE, TransferPolicy, TransferPolicyCap, TransferPolicyCreated } from "./transfer-policy.mjs";
4
4
  import { TransactionObjectArgument } from "@mysten/sui/transactions";
5
- import { SuiGraphQLClient } from "@mysten/sui/graphql";
6
- import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
7
- import { SuiClientTypes } from "@mysten/sui/client";
5
+ import { ClientWithCoreApi, SuiClientTypes } from "@mysten/sui/client";
8
6
 
9
7
  //#region src/types/index.d.ts
10
8
  /**
@@ -19,7 +17,11 @@ type KioskClientOptions = {
19
17
  network: SuiClientTypes.Network;
20
18
  packageIds?: BaseRulePackageIds;
21
19
  };
22
- type KioskCompatibleClient = SuiJsonRpcClient | SuiGraphQLClient;
20
+ type KioskCompatibleClient = ClientWithCoreApi;
21
+ type KioskPaginationArguments = {
22
+ cursor?: string | null;
23
+ limit?: number | null;
24
+ };
23
25
  //#endregion
24
- export { KioskClientOptions, KioskCompatibleClient, ObjectArgument };
26
+ export { KioskClientOptions, KioskCompatibleClient, KioskPaginationArguments, ObjectArgument };
25
27
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/types/index.ts"],"mappings":";;;;;;;;;;;AAgBA;KAAY,cAAA,YAA0B,yBAAA;;;;KAK1B,kBAAA;EACX,MAAA,EAAQ,qBAAA;EACR,OAAA,EAAS,cAAA,CAAe,OAAA;EACxB,UAAA,GAAa,kBAAA;AAAA;AAAA,KAGF,qBAAA,GAAwB,gBAAA,GAAmB,gBAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/types/index.ts"],"mappings":";;;;;;;;;AAcA;KAAY,cAAA,YAA0B,yBAAA;;;;KAK1B,kBAAA;EACX,MAAA,EAAQ,qBAAA;EACR,OAAA,EAAS,cAAA,CAAe,OAAA;EACxB,UAAA,GAAa,kBAAA;AAAA;AAAA,KAGF,qBAAA,GAAwB,iBAAA;AAAA,KAExB,wBAAA;EACX,MAAA;EACA,KAAA;AAAA"}
package/dist/utils.d.mts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Kiosk, KioskData, KioskListing, ObjectWithDisplay } from "./types/kiosk.mjs";
2
- import "./types/index.mjs";
3
- import { PaginationArguments } from "@mysten/sui/jsonRpc";
2
+ import { KioskPaginationArguments } from "./types/index.mjs";
4
3
  import { ClientWithCoreApi, SuiClientTypes } from "@mysten/sui/client";
5
4
 
6
5
  //#region src/utils.d.ts
@@ -25,7 +24,7 @@ declare function attachLockedItems(kioskData: KioskData, lockedItemIds: string[]
25
24
  * We need that to fetch the kiosk DFs consistently, until we have
26
25
  * RPC calls that allow filtering of Type / batch fetching of spec
27
26
  */
28
- declare function getAllDynamicFields(client: ClientWithCoreApi, parentId: string, pagination: PaginationArguments<string>): Promise<DynamicFieldInfo[]>;
27
+ declare function getAllDynamicFields(client: ClientWithCoreApi, parentId: string, pagination: KioskPaginationArguments): Promise<DynamicFieldInfo[]>;
29
28
  /**
30
29
  * Converts a number to basis points.
31
30
  * Supports up to 2 decimal points.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.mts","names":[],"sources":["../src/utils.ts"],"mappings":";;;;;;KAWY,gBAAA,GAAmB,cAAA,CAAe,yBAAA;AAAA,iBAExB,cAAA,CAAe,MAAA,EAAQ,iBAAA,EAAmB,EAAA,WAAa,OAAA,CAAQ,KAAA;AAAA,iBAsBrE,gBAAA,CACf,IAAA,EAAM,gBAAA,IACN,QAAA,EAAU,YAAA,IACV,aAAA,YACA,OAAA,WACE,SAAA;AA7BH;;;AAAA,iBA4FgB,uBAAA,CACf,SAAA,EAAW,SAAA,EACX,QAAA,EAAU,YAAA,IACV,cAAA,EAAgB,iBAAA;;AA7FjB;;;iBA4HgB,aAAA,CAAc,SAAA,EAAW,SAAA,EAAW,OAAA,EAAS,iBAAA;;;;iBAiB7C,iBAAA,CAAkB,SAAA,EAAW,SAAA,EAAW,aAAA;;;;;;iBAqBlC,mBAAA,CACrB,MAAA,EAAQ,iBAAA,EACR,QAAA,UACA,UAAA,EAAY,mBAAA,WACV,OAAA,CAAQ,gBAAA;;AAhJX;;;;;iBA2KgB,uBAAA,CAAwB,UAAA;AAAA,iBAOxB,qBAAA,CAAsB,IAAA"}
1
+ {"version":3,"file":"utils.d.mts","names":[],"sources":["../src/utils.ts"],"mappings":";;;;;KAgBY,gBAAA,GAAmB,cAAA,CAAe,yBAAA;AAAA,iBAExB,cAAA,CAAe,MAAA,EAAQ,iBAAA,EAAmB,EAAA,WAAa,OAAA,CAAQ,KAAA;AAAA,iBAsBrE,gBAAA,CACf,IAAA,EAAM,gBAAA,IACN,QAAA,EAAU,YAAA,IACV,aAAA,YACA,OAAA,WACE,SAAA;AA7BH;;;AAAA,iBA4FgB,uBAAA,CACf,SAAA,EAAW,SAAA,EACX,QAAA,EAAU,YAAA,IACV,cAAA,EAAgB,iBAAA;;AA7FjB;;;iBA4HgB,aAAA,CAAc,SAAA,EAAW,SAAA,EAAW,OAAA,EAAS,iBAAA;;;;iBAiB7C,iBAAA,CAAkB,SAAA,EAAW,SAAA,EAAW,aAAA;;;;;;iBAqBlC,mBAAA,CACrB,MAAA,EAAQ,iBAAA,EACR,QAAA,UACA,UAAA,EAAY,wBAAA,GACV,OAAA,CAAQ,gBAAA;;AAhJX;;;;;iBA2KgB,uBAAA,CAAwB,UAAA;AAAA,iBAOxB,qBAAA,CAAsB,IAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","names":["KioskStruct"],"sources":["../src/utils.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '@mysten/sui/bcs';\nimport { PaginationArguments } from '@mysten/sui/jsonRpc';\nimport type { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';\nimport { normalizeStructTag, normalizeSuiAddress, parseStructTag } from '@mysten/sui/utils';\n\nimport { Item, Listing, Lock, Kiosk as KioskStruct } from './contracts/0x2/kiosk.js';\nimport type { Kiosk, KioskData, KioskListing, ObjectWithDisplay } from './types/index.js';\n\nexport type DynamicFieldInfo = SuiClientTypes.ListDynamicFieldsResponse['dynamicFields'][number];\n\nexport async function getKioskObject(client: ClientWithCoreApi, id: string): Promise<Kiosk> {\n\tconst { object } = await client.core.getObject({\n\t\tobjectId: id,\n\t\tinclude: { content: true },\n\t});\n\n\tif (!object.content) {\n\t\tthrow new Error(`Kiosk ${id} not found or has no content`);\n\t}\n\n\tconst parsed = KioskStruct.parse(object.content);\n\n\treturn {\n\t\tid: parsed.id,\n\t\tprofits: parsed.profits.value.toString(),\n\t\towner: parsed.owner,\n\t\titemCount: parsed.item_count,\n\t\tallowExtensions: parsed.allow_extensions,\n\t};\n}\n\n// helper to extract kiosk data from dynamic fields.\nexport function extractKioskData(\n\tdata: DynamicFieldInfo[],\n\tlistings: KioskListing[],\n\tlockedItemIds: string[],\n\tkioskId: string,\n): KioskData {\n\treturn data.reduce<KioskData>(\n\t\t(acc: KioskData, val: DynamicFieldInfo) => {\n\t\t\tconst type = val.name.type;\n\n\t\t\tconst parsedType = parseStructTag(type);\n\t\t\tconst baseType = `${normalizeSuiAddress(parsedType.address)}::${parsedType.module}::${parsedType.name}`;\n\n\t\t\tif (\n\t\t\t\tbaseType ===\n\t\t\t\t'0x0000000000000000000000000000000000000000000000000000000000000002::kiosk::Item'\n\t\t\t) {\n\t\t\t\tconst parsed = Item.parse(val.name.bcs);\n\t\t\t\tacc.itemIds.push(parsed.id);\n\t\t\t\tacc.items.push({\n\t\t\t\t\tobjectId: parsed.id,\n\t\t\t\t\ttype: val.valueType,\n\t\t\t\t\tisLocked: false,\n\t\t\t\t\tkioskId,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tbaseType ===\n\t\t\t\t'0x0000000000000000000000000000000000000000000000000000000000000002::kiosk::Listing'\n\t\t\t) {\n\t\t\t\tconst parsed = Listing.parse(val.name.bcs);\n\n\t\t\t\tacc.listingIds.push(val.fieldId);\n\t\t\t\tlistings.push({\n\t\t\t\t\tobjectId: parsed.id,\n\t\t\t\t\tlistingId: val.fieldId,\n\t\t\t\t\tisExclusive: parsed.is_exclusive,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tbaseType ===\n\t\t\t\t'0x0000000000000000000000000000000000000000000000000000000000000002::kiosk::Lock'\n\t\t\t) {\n\t\t\t\tlockedItemIds?.push(Lock.parse(val.name.bcs).id);\n\t\t\t}\n\n\t\t\t// Check for ExtensionKey type\n\t\t\tif (\n\t\t\t\tbaseType ===\n\t\t\t\t'0x0000000000000000000000000000000000000000000000000000000000000002::kiosk_extension::ExtensionKey'\n\t\t\t) {\n\t\t\t\tacc.extensions.push({\n\t\t\t\t\tobjectId: val.fieldId,\n\t\t\t\t\ttype: normalizeStructTag(parsedType.typeParams[0]),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn acc;\n\t\t},\n\t\t{ items: [], itemIds: [], listingIds: [], extensions: [] },\n\t);\n}\n\n/**\n * A helper that attaches the listing prices to kiosk listings.\n */\nexport function attachListingsAndPrices(\n\tkioskData: KioskData,\n\tlistings: KioskListing[],\n\tlistingObjects: ObjectWithDisplay[],\n) {\n\tconst itemListings = listings.reduce<Record<string, KioskListing>>(\n\t\t(acc: Record<string, KioskListing>, item, idx) => {\n\t\t\tacc[item.objectId] = { ...item };\n\n\t\t\t// return in case we don't have any listing objects.\n\t\t\t// that's the case when we don't have the `listingPrices` included.\n\t\t\tif (listingObjects.length === 0) return acc;\n\n\t\t\tconst obj = listingObjects[idx];\n\n\t\t\t// Parse BCS content to extract the price (u64 value)\n\t\t\tif (obj.content) {\n\t\t\t\tacc[item.objectId].price = bcs.u64().parse(obj.content).toString();\n\t\t\t}\n\n\t\t\treturn acc;\n\t\t},\n\t\t{},\n\t);\n\n\tkioskData.items.forEach((item) => {\n\t\titem.listing = itemListings[item.objectId] || undefined;\n\t});\n}\n\n/**\n * A helper that attaches object data to kiosk items.\n * Works with core API objects that contain BCS content.\n */\nexport function attachObjects(kioskData: KioskData, objects: ObjectWithDisplay[]) {\n\tconst mapping = objects.reduce<Record<string, ObjectWithDisplay>>(\n\t\t(acc: Record<string, ObjectWithDisplay>, obj) => {\n\t\t\tacc[obj.objectId] = obj;\n\t\t\treturn acc;\n\t\t},\n\t\t{},\n\t);\n\n\tkioskData.items.forEach((item) => {\n\t\titem.data = mapping[item.objectId] || undefined;\n\t});\n}\n\n/**\n * A Helper to attach locked state to items in Kiosk Data.\n */\nexport function attachLockedItems(kioskData: KioskData, lockedItemIds: string[]) {\n\t// map lock status in an array of type { item_id: true }\n\tconst lockedStatuses = lockedItemIds.reduce<Record<string, boolean>>(\n\t\t(acc: Record<string, boolean>, item: string) => {\n\t\t\tacc[item] = true;\n\t\t\treturn acc;\n\t\t},\n\t\t{},\n\t);\n\n\t// parse lockedItemIds and attach their locked status.\n\tkioskData.items.forEach((item) => {\n\t\titem.isLocked = lockedStatuses[item.objectId] || false;\n\t});\n}\n\n/**\n * A helper to fetch all dynamic field pages.\n * We need that to fetch the kiosk DFs consistently, until we have\n * RPC calls that allow filtering of Type / batch fetching of spec\n */\nexport async function getAllDynamicFields(\n\tclient: ClientWithCoreApi,\n\tparentId: string,\n\tpagination: PaginationArguments<string>,\n): Promise<DynamicFieldInfo[]> {\n\tlet hasNextPage = true;\n\tlet cursor: string | null = null;\n\tconst data: DynamicFieldInfo[] = [];\n\n\twhile (hasNextPage) {\n\t\tconst result = await client.core.listDynamicFields({\n\t\t\tparentId,\n\t\t\tlimit: pagination.limit || undefined,\n\t\t\tcursor,\n\t\t});\n\n\t\tdata.push(...result.dynamicFields);\n\n\t\thasNextPage = result.hasNextPage;\n\t\tcursor = result.cursor;\n\t}\n\n\treturn data;\n}\n\n/**\n * Converts a number to basis points.\n * Supports up to 2 decimal points.\n * E.g 9.95 -> 995\n * @param percentage A percentage amount in the range [0, 100] including decimals.\n */\nexport function percentageToBasisPoints(percentage: number) {\n\tif (percentage < 0 || percentage > 100)\n\t\tthrow new Error('Percentage needs to be in the [0,100] range.');\n\treturn Math.ceil(percentage * 100);\n}\n\n// Normalizes the packageId part of a rule's type.\nexport function getNormalizedRuleType(rule: string) {\n\tconst normalizedRuleAddress = rule.split('::');\n\tnormalizedRuleAddress[0] = normalizeSuiAddress(normalizedRuleAddress[0]);\n\treturn normalizedRuleAddress.join('::');\n}\n"],"mappings":";;;;;AAaA,eAAsB,eAAe,QAA2B,IAA4B;CAC3F,MAAM,EAAE,WAAW,MAAM,OAAO,KAAK,UAAU;EAC9C,UAAU;EACV,SAAS,EAAE,SAAS,MAAM;EAC1B,CAAC;AAEF,KAAI,CAAC,OAAO,QACX,OAAM,IAAI,MAAM,SAAS,GAAG,8BAA8B;CAG3D,MAAM,SAASA,MAAY,MAAM,OAAO,QAAQ;AAEhD,QAAO;EACN,IAAI,OAAO;EACX,SAAS,OAAO,QAAQ,MAAM,UAAU;EACxC,OAAO,OAAO;EACd,WAAW,OAAO;EAClB,iBAAiB,OAAO;EACxB;;AAIF,SAAgB,iBACf,MACA,UACA,eACA,SACY;AACZ,QAAO,KAAK,QACV,KAAgB,QAA0B;EAC1C,MAAM,OAAO,IAAI,KAAK;EAEtB,MAAM,aAAa,eAAe,KAAK;EACvC,MAAM,WAAW,GAAG,oBAAoB,WAAW,QAAQ,CAAC,IAAI,WAAW,OAAO,IAAI,WAAW;AAEjG,MACC,aACA,mFACC;GACD,MAAM,SAAS,KAAK,MAAM,IAAI,KAAK,IAAI;AACvC,OAAI,QAAQ,KAAK,OAAO,GAAG;AAC3B,OAAI,MAAM,KAAK;IACd,UAAU,OAAO;IACjB,MAAM,IAAI;IACV,UAAU;IACV;IACA,CAAC;;AAGH,MACC,aACA,sFACC;GACD,MAAM,SAAS,QAAQ,MAAM,IAAI,KAAK,IAAI;AAE1C,OAAI,WAAW,KAAK,IAAI,QAAQ;AAChC,YAAS,KAAK;IACb,UAAU,OAAO;IACjB,WAAW,IAAI;IACf,aAAa,OAAO;IACpB,CAAC;;AAGH,MACC,aACA,kFAEA,gBAAe,KAAK,KAAK,MAAM,IAAI,KAAK,IAAI,CAAC,GAAG;AAIjD,MACC,aACA,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,OAAK,KAAK,GAAG,OAAO,cAAc;AAElC,gBAAc,OAAO;AACrB,WAAS,OAAO;;AAGjB,QAAO;;;;;;;;AASR,SAAgB,wBAAwB,YAAoB;AAC3D,KAAI,aAAa,KAAK,aAAa,IAClC,OAAM,IAAI,MAAM,+CAA+C;AAChE,QAAO,KAAK,KAAK,aAAa,IAAI;;AAInC,SAAgB,sBAAsB,MAAc;CACnD,MAAM,wBAAwB,KAAK,MAAM,KAAK;AAC9C,uBAAsB,KAAK,oBAAoB,sBAAsB,GAAG;AACxE,QAAO,sBAAsB,KAAK,KAAK"}
1
+ {"version":3,"file":"utils.mjs","names":["KioskStruct"],"sources":["../src/utils.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '@mysten/sui/bcs';\nimport type { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';\nimport { normalizeStructTag, normalizeSuiAddress, parseStructTag } from '@mysten/sui/utils';\n\nimport { Item, Listing, Lock, Kiosk as KioskStruct } from './contracts/0x2/kiosk.js';\nimport type {\n\tKiosk,\n\tKioskData,\n\tKioskListing,\n\tKioskPaginationArguments,\n\tObjectWithDisplay,\n} from './types/index.js';\n\nexport type DynamicFieldInfo = SuiClientTypes.ListDynamicFieldsResponse['dynamicFields'][number];\n\nexport async function getKioskObject(client: ClientWithCoreApi, id: string): Promise<Kiosk> {\n\tconst { object } = await client.core.getObject({\n\t\tobjectId: id,\n\t\tinclude: { content: true },\n\t});\n\n\tif (!object.content) {\n\t\tthrow new Error(`Kiosk ${id} not found or has no content`);\n\t}\n\n\tconst parsed = KioskStruct.parse(object.content);\n\n\treturn {\n\t\tid: parsed.id,\n\t\tprofits: parsed.profits.value.toString(),\n\t\towner: parsed.owner,\n\t\titemCount: parsed.item_count,\n\t\tallowExtensions: parsed.allow_extensions,\n\t};\n}\n\n// helper to extract kiosk data from dynamic fields.\nexport function extractKioskData(\n\tdata: DynamicFieldInfo[],\n\tlistings: KioskListing[],\n\tlockedItemIds: string[],\n\tkioskId: string,\n): KioskData {\n\treturn data.reduce<KioskData>(\n\t\t(acc: KioskData, val: DynamicFieldInfo) => {\n\t\t\tconst type = val.name.type;\n\n\t\t\tconst parsedType = parseStructTag(type);\n\t\t\tconst baseType = `${normalizeSuiAddress(parsedType.address)}::${parsedType.module}::${parsedType.name}`;\n\n\t\t\tif (\n\t\t\t\tbaseType ===\n\t\t\t\t'0x0000000000000000000000000000000000000000000000000000000000000002::kiosk::Item'\n\t\t\t) {\n\t\t\t\tconst parsed = Item.parse(val.name.bcs);\n\t\t\t\tacc.itemIds.push(parsed.id);\n\t\t\t\tacc.items.push({\n\t\t\t\t\tobjectId: parsed.id,\n\t\t\t\t\ttype: val.valueType,\n\t\t\t\t\tisLocked: false,\n\t\t\t\t\tkioskId,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tbaseType ===\n\t\t\t\t'0x0000000000000000000000000000000000000000000000000000000000000002::kiosk::Listing'\n\t\t\t) {\n\t\t\t\tconst parsed = Listing.parse(val.name.bcs);\n\n\t\t\t\tacc.listingIds.push(val.fieldId);\n\t\t\t\tlistings.push({\n\t\t\t\t\tobjectId: parsed.id,\n\t\t\t\t\tlistingId: val.fieldId,\n\t\t\t\t\tisExclusive: parsed.is_exclusive,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tbaseType ===\n\t\t\t\t'0x0000000000000000000000000000000000000000000000000000000000000002::kiosk::Lock'\n\t\t\t) {\n\t\t\t\tlockedItemIds?.push(Lock.parse(val.name.bcs).id);\n\t\t\t}\n\n\t\t\t// Check for ExtensionKey type\n\t\t\tif (\n\t\t\t\tbaseType ===\n\t\t\t\t'0x0000000000000000000000000000000000000000000000000000000000000002::kiosk_extension::ExtensionKey'\n\t\t\t) {\n\t\t\t\tacc.extensions.push({\n\t\t\t\t\tobjectId: val.fieldId,\n\t\t\t\t\ttype: normalizeStructTag(parsedType.typeParams[0]),\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn acc;\n\t\t},\n\t\t{ items: [], itemIds: [], listingIds: [], extensions: [] },\n\t);\n}\n\n/**\n * A helper that attaches the listing prices to kiosk listings.\n */\nexport function attachListingsAndPrices(\n\tkioskData: KioskData,\n\tlistings: KioskListing[],\n\tlistingObjects: ObjectWithDisplay[],\n) {\n\tconst itemListings = listings.reduce<Record<string, KioskListing>>(\n\t\t(acc: Record<string, KioskListing>, item, idx) => {\n\t\t\tacc[item.objectId] = { ...item };\n\n\t\t\t// return in case we don't have any listing objects.\n\t\t\t// that's the case when we don't have the `listingPrices` included.\n\t\t\tif (listingObjects.length === 0) return acc;\n\n\t\t\tconst obj = listingObjects[idx];\n\n\t\t\t// Parse BCS content to extract the price (u64 value)\n\t\t\tif (obj.content) {\n\t\t\t\tacc[item.objectId].price = bcs.u64().parse(obj.content).toString();\n\t\t\t}\n\n\t\t\treturn acc;\n\t\t},\n\t\t{},\n\t);\n\n\tkioskData.items.forEach((item) => {\n\t\titem.listing = itemListings[item.objectId] || undefined;\n\t});\n}\n\n/**\n * A helper that attaches object data to kiosk items.\n * Works with core API objects that contain BCS content.\n */\nexport function attachObjects(kioskData: KioskData, objects: ObjectWithDisplay[]) {\n\tconst mapping = objects.reduce<Record<string, ObjectWithDisplay>>(\n\t\t(acc: Record<string, ObjectWithDisplay>, obj) => {\n\t\t\tacc[obj.objectId] = obj;\n\t\t\treturn acc;\n\t\t},\n\t\t{},\n\t);\n\n\tkioskData.items.forEach((item) => {\n\t\titem.data = mapping[item.objectId] || undefined;\n\t});\n}\n\n/**\n * A Helper to attach locked state to items in Kiosk Data.\n */\nexport function attachLockedItems(kioskData: KioskData, lockedItemIds: string[]) {\n\t// map lock status in an array of type { item_id: true }\n\tconst lockedStatuses = lockedItemIds.reduce<Record<string, boolean>>(\n\t\t(acc: Record<string, boolean>, item: string) => {\n\t\t\tacc[item] = true;\n\t\t\treturn acc;\n\t\t},\n\t\t{},\n\t);\n\n\t// parse lockedItemIds and attach their locked status.\n\tkioskData.items.forEach((item) => {\n\t\titem.isLocked = lockedStatuses[item.objectId] || false;\n\t});\n}\n\n/**\n * A helper to fetch all dynamic field pages.\n * We need that to fetch the kiosk DFs consistently, until we have\n * RPC calls that allow filtering of Type / batch fetching of spec\n */\nexport async function getAllDynamicFields(\n\tclient: ClientWithCoreApi,\n\tparentId: string,\n\tpagination: KioskPaginationArguments,\n): Promise<DynamicFieldInfo[]> {\n\tlet hasNextPage = true;\n\tlet cursor: string | null = null;\n\tconst data: DynamicFieldInfo[] = [];\n\n\twhile (hasNextPage) {\n\t\tconst result = await client.core.listDynamicFields({\n\t\t\tparentId,\n\t\t\tlimit: pagination.limit || undefined,\n\t\t\tcursor,\n\t\t});\n\n\t\tdata.push(...result.dynamicFields);\n\n\t\thasNextPage = result.hasNextPage;\n\t\tcursor = result.cursor;\n\t}\n\n\treturn data;\n}\n\n/**\n * Converts a number to basis points.\n * Supports up to 2 decimal points.\n * E.g 9.95 -> 995\n * @param percentage A percentage amount in the range [0, 100] including decimals.\n */\nexport function percentageToBasisPoints(percentage: number) {\n\tif (percentage < 0 || percentage > 100)\n\t\tthrow new Error('Percentage needs to be in the [0,100] range.');\n\treturn Math.ceil(percentage * 100);\n}\n\n// Normalizes the packageId part of a rule's type.\nexport function getNormalizedRuleType(rule: string) {\n\tconst normalizedRuleAddress = rule.split('::');\n\tnormalizedRuleAddress[0] = normalizeSuiAddress(normalizedRuleAddress[0]);\n\treturn normalizedRuleAddress.join('::');\n}\n"],"mappings":";;;;;AAkBA,eAAsB,eAAe,QAA2B,IAA4B;CAC3F,MAAM,EAAE,WAAW,MAAM,OAAO,KAAK,UAAU;EAC9C,UAAU;EACV,SAAS,EAAE,SAAS,MAAM;EAC1B,CAAC;AAEF,KAAI,CAAC,OAAO,QACX,OAAM,IAAI,MAAM,SAAS,GAAG,8BAA8B;CAG3D,MAAM,SAASA,MAAY,MAAM,OAAO,QAAQ;AAEhD,QAAO;EACN,IAAI,OAAO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patterns and code examples for complex scenarios.
3
+ > Advanced Kiosk SDK usage patterns and code examples for complex scenarios
4
4
 
5
5
  # Some extended examples
6
6
 
@@ -14,8 +14,8 @@ const bullsharkType = `${packageId}::suifrens::SuiFren<${packageId}::bullshark::
14
14
  const capyType = `${packageId}::suifrens::SuiFren<${packageId}::capy::Capy>`;
15
15
 
16
16
  // initialize the client with the kiosk extension.
17
- const client = new SuiJsonRpcClient({
18
- url: getJsonRpcFullnodeUrl('mainnet'),
17
+ const client = new SuiGrpcClient({
18
+ baseUrl: 'https://fullnode.mainnet.sui.io:443',
19
19
  network: 'mainnet',
20
20
  }).$extend(kiosk());
21
21
  ```
package/docs/from-v1.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Migrating from Kiosk SDK V1
2
2
 
3
- > Migrate from Kiosk SDK v1 to the current version with the builder-pattern API.
3
+ > Migrate from Kiosk SDK v1 to the current version with the builder-pattern API
4
4
 
5
5
  The original version of Kiosk SDK provided basic experimentation with the Kiosk API. The new version
6
6
  of the SDK (0.7+) provides a more robust experience for building kiosk/transfer policy transactions.
@@ -46,8 +46,8 @@ Using the new SDK, you can build the same transaction as follows:
46
46
  ```typescript
47
47
 
48
48
  // You need to do this only once and re-use it in the application.
49
- const client = new SuiJsonRpcClient({
50
- url: getJsonRpcFullnodeUrl('mainnet'),
49
+ const client = new SuiGrpcClient({
50
+ baseUrl: 'https://fullnode.mainnet.sui.io:443',
51
51
  network: 'mainnet',
52
52
  }).$extend(kiosk());
53
53
 
@@ -98,8 +98,8 @@ Using the new SDK, you can build the same transaction as follows:
98
98
  ```typescript
99
99
 
100
100
  // You need to do this only once and re-use it in the application.
101
- const client = new SuiJsonRpcClient({
102
- url: getJsonRpcFullnodeUrl('mainnet'),
101
+ const client = new SuiGrpcClient({
102
+ baseUrl: 'https://fullnode.mainnet.sui.io:443',
103
103
  network: 'mainnet',
104
104
  }).$extend(kiosk());
105
105
 
@@ -198,8 +198,8 @@ Using the new SDK, you can build the same transaction as follows:
198
198
  ```typescript
199
199
 
200
200
  // You need to do this only once and re-use it in the application.
201
- const client = new SuiJsonRpcClient({
202
- url: getJsonRpcFullnodeUrl('mainnet'),
201
+ const client = new SuiGrpcClient({
202
+ baseUrl: 'https://fullnode.mainnet.sui.io:443',
203
203
  network: 'mainnet',
204
204
  }).$extend(kiosk());
205
205
 
@@ -296,8 +296,8 @@ On the new SDK, the same transaction can be built as follows:
296
296
  ```typescript
297
297
 
298
298
  // You need to do this only once and re-use it in the application.
299
- const client = new SuiJsonRpcClient({
300
- url: getJsonRpcFullnodeUrl('mainnet'),
299
+ const client = new SuiGrpcClient({
300
+ baseUrl: 'https://fullnode.mainnet.sui.io:443',
301
301
  network: 'mainnet',
302
302
  }).$extend(kiosk());
303
303
 
package/docs/index.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Kiosk SDK
2
2
 
3
- > TypeScript SDK for interacting with Sui Kiosk onchain commerce.
3
+ > TypeScript SDK for interacting with Sui Kiosk onchain commerce
4
4
 
5
5
  Kiosk SDK is a tool to interact with Sui and Mysten Kiosk. You can use it to query kiosk related
6
6
  data, build transactions to interact, and extend Kiosk to support custom rules.
@@ -16,7 +16,10 @@ npm i @mysten/kiosk
16
16
  The Kiosk SDK exports a client extension that integrates with Sui clients. Add it to your client
17
17
  using `$extend(kiosk())` to access kiosk functionality through `client.kiosk`.
18
18
 
19
- > The Kiosk SDK requires `SuiJsonRpcClient` or `SuiGraphQLClient`. It does not work with
20
- > `SuiGrpcClient` because it uses event queries that are not available in gRPC.
19
+ The Kiosk extension accepts any Sui client that implements `ClientWithCoreApi`. Use `SuiGrpcClient`
20
+ for new Kiosk code; `SuiGraphQLClient` and the deprecated `SuiJsonRpcClient` are also compatible.
21
+
22
+ > **Note:** The gRPC object API returns Display v2 metadata. Use GraphQL or JSON-RPC when reading objects
23
+ > whose types still rely on legacy Display metadata.
21
24
 
22
25
  - [Read more about setting up the Kiosk client extension](/kiosk/kiosk-client/introduction)
@@ -1,14 +1,17 @@
1
1
  # Kiosk Client
2
2
 
3
- > Introduction to the KioskClient extension for querying and managing kiosks on Sui.
3
+ > Introduction to the KioskClient extension for querying and managing kiosks on Sui
4
4
 
5
5
  The Kiosk SDK exports a client extension that provides all Kiosk functionality.
6
6
 
7
7
  > We recommend you keep only one client instance throughout your app or script. For example, in
8
8
  > React, you'd use a context to provide the client.
9
9
 
10
- > The Kiosk SDK requires `SuiJsonRpcClient` or `SuiGraphQLClient`. It does not work with
11
- > `SuiGrpcClient` because it uses event queries that are not available in gRPC.
10
+ The Kiosk extension accepts any Sui client that implements `ClientWithCoreApi`. Use `SuiGrpcClient`
11
+ for new Kiosk code; `SuiGraphQLClient` and the deprecated `SuiJsonRpcClient` are also compatible.
12
+
13
+ > **Note:** The gRPC object API returns Display v2 metadata. Use GraphQL or JSON-RPC when reading objects
14
+ > whose types still rely on legacy Display metadata.
12
15
 
13
16
  ## Setting up the kiosk extension
14
17
 
@@ -20,8 +23,8 @@ require constantly changing the package IDs).
20
23
 
21
24
  ```typescript
22
25
 
23
- const client = new SuiJsonRpcClient({
24
- url: getJsonRpcFullnodeUrl('testnet'),
26
+ const client = new SuiGrpcClient({
27
+ baseUrl: 'https://fullnode.testnet.sui.io:443',
25
28
  network: 'testnet',
26
29
  }).$extend(kiosk());
27
30
 
@@ -36,8 +39,8 @@ for the rules and extensions you want to use.
36
39
 
37
40
  ```typescript
38
41
 
39
- const client = new SuiJsonRpcClient({
40
- url: getJsonRpcFullnodeUrl('devnet'),
42
+ const client = new SuiGrpcClient({
43
+ baseUrl: 'https://fullnode.devnet.sui.io:443',
41
44
  network: 'devnet',
42
45
  }).$extend(
43
46
  kiosk({
@@ -1,8 +1,8 @@
1
1
  # Kiosk
2
2
  > Interact with on-chain commerce applications
3
3
 
4
- - [Kiosk SDK](..md): TypeScript SDK for interacting with Sui Kiosk onchain commerce.
5
- - [Kiosk Client](./kiosk-client/introduction.md): Introduction to the KioskClient extension for querying and managing kiosks on Sui.
4
+ - [Kiosk SDK](..md): TypeScript SDK for interacting with Sui Kiosk onchain commerce
5
+ - [Kiosk Client](./kiosk-client/introduction.md): Introduction to the KioskClient extension for querying and managing kiosks on Sui
6
6
  - [Querying](./kiosk-client/querying.md): Query kiosk contents, owned kiosks, items, and transfer policies using the Kiosk SDK.
7
7
  - [KioskTransaction](./kiosk-client/kiosk-transaction/kiosk-transaction.md): Build kiosk transactions for listing, purchasing, and managing items on Sui.
8
8
  - [Managing Owned Kiosk](./kiosk-client/kiosk-transaction/managing.md): Manage kiosk items by placing, listing, delisting, and withdrawing using the Kiosk SDK.
@@ -10,5 +10,5 @@
10
10
  - [Examples](./kiosk-client/kiosk-transaction/examples.md): Practical code examples for kiosk transactions including minting, listing, and purchasing.
11
11
  - [TransferPolicyTransaction](./kiosk-client/transfer-policy-transaction/introduction.md): Create and manage transfer policies for kiosk items using the Kiosk SDK.
12
12
  - [Using the manager](./kiosk-client/transfer-policy-transaction/using-the-manager.md): Use the TransferPolicyTransaction manager to add rules and withdraw profits.
13
- - [Advanced Examples](./advanced-examples.md): Advanced Kiosk SDK usage patterns and code examples for complex scenarios.
14
- - [Migrating from Kiosk SDK V1](./from-v1.md): Migrate from Kiosk SDK v1 to the current version with the builder-pattern API.
13
+ - [Advanced Examples](./advanced-examples.md): Advanced Kiosk SDK usage patterns and code examples for complex scenarios
14
+ - [Migrating from Kiosk SDK V1](./from-v1.md): Migrate from Kiosk SDK v1 to the current version with the builder-pattern API
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@mysten/kiosk",
3
3
  "author": "Mysten Labs <build@mystenlabs.com>",
4
4
  "description": "Sui Kiosk library",
5
- "version": "1.3.13",
5
+ "version": "1.4.1",
6
6
  "license": "Apache-2.0",
7
7
  "type": "module",
8
8
  "main": "./dist/index.mjs",
@@ -32,8 +32,7 @@
32
32
  "url": "https://github.com/MystenLabs/ts-sdks/issues/new"
33
33
  },
34
34
  "dependencies": {
35
- "@mysten/bcs": "^2.1.0",
36
- "@mysten/utils": "^0.4.0"
35
+ "@mysten/bcs": "^2.1.0"
37
36
  },
38
37
  "devDependencies": {
39
38
  "cross-env": "^10.1.0",
@@ -45,13 +44,13 @@
45
44
  "wait-on": "^9.0.10"
46
45
  },
47
46
  "peerDependencies": {
48
- "@mysten/sui": "^2.23.2"
47
+ "@mysten/sui": "^2.25.0"
49
48
  },
50
49
  "scripts": {
51
50
  "build": "rm -rf dist && tsc --noEmit && tsdown",
52
51
  "build:docs": "node ../docs/scripts/build-docs.ts",
53
52
  "codegen": "sui-ts-codegen generate && pnpm lint:fix",
54
- "test": "echo 'No unit tests for kiosk SDK'",
53
+ "test": "vitest run --typecheck --config vitest.unit.config.mts",
55
54
  "pre-commit": "pnpm prettier:fix && pnpm lint && pnpm build",
56
55
  "prettier:check": "prettier -c --ignore-unknown .",
57
56
  "prettier:fix": "prettier -w --ignore-unknown .",
@@ -1,7 +1,6 @@
1
1
  // Copyright (c) Mysten Labs, Inc.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type { PaginationArguments } from '@mysten/sui/jsonRpc';
5
4
  import type { SuiClientTypes } from '@mysten/sui/client';
6
5
 
7
6
  import {
@@ -24,6 +23,7 @@ import type {
24
23
  KioskClientOptions,
25
24
  KioskCompatibleClient,
26
25
  KioskData,
26
+ KioskPaginationArguments,
27
27
  OwnedKiosks,
28
28
  } from '../types/index.js';
29
29
 
@@ -37,11 +37,11 @@ export type KioskExtensionOptions<Name extends string = 'kiosk'> = {
37
37
  *
38
38
  * @example
39
39
  * ```ts
40
- * import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
40
+ * import { SuiGrpcClient } from '@mysten/sui/grpc';
41
41
  * import { kiosk } from '@mysten/kiosk';
42
42
  *
43
- * const client = new SuiJsonRpcClient({
44
- * url: getJsonRpcFullnodeUrl('mainnet'),
43
+ * const client = new SuiGrpcClient({
44
+ * baseUrl: 'https://fullnode.mainnet.sui.io:443',
45
45
  * network: 'mainnet',
46
46
  * }).$extend(kiosk());
47
47
  *
@@ -100,7 +100,7 @@ export class KioskClient {
100
100
  pagination,
101
101
  }: {
102
102
  address: string;
103
- pagination?: PaginationArguments<string>;
103
+ pagination?: KioskPaginationArguments;
104
104
  }): Promise<OwnedKiosks> {
105
105
  const personalPackageId =
106
106
  this.packageIds?.personalKioskRulePackageId || PERSONAL_KIOSK_RULE_ADDRESS[this.network];
@@ -8,7 +8,11 @@ import {
8
8
  BcsTuple,
9
9
  } from '@mysten/sui/bcs';
10
10
  import { normalizeStructTag, normalizeSuiAddress } from '@mysten/sui/utils';
11
- import { type TransactionArgument, isArgument } from '@mysten/sui/transactions';
11
+ import {
12
+ type TransactionArgument,
13
+ type TransactionObjectArgument,
14
+ isArgument,
15
+ } from '@mysten/sui/transactions';
12
16
  import { type ClientWithCoreApi, type SuiClientTypes } from '@mysten/sui/client';
13
17
 
14
18
  const MOVE_STDLIB_ADDRESS = normalizeSuiAddress('0x1');
@@ -106,6 +110,12 @@ export function normalizeMoveArguments(
106
110
  continue;
107
111
  }
108
112
 
113
+ if (argType === '0x2::accumulator::AccumulatorRoot') {
114
+ // Chain-wide shared singleton at a fixed address (SUI_ACCUMULATOR_ROOT_OBJECT_ID).
115
+ normalizedArgs.push((tx) => tx.object('0xacc'));
116
+ continue;
117
+ }
118
+
109
119
  if (argType === '0x3::sui_system::SuiSystemState') {
110
120
  normalizedArgs.push((tx) => tx.object.system());
111
121
  continue;
@@ -124,7 +134,10 @@ export function normalizeMoveArguments(
124
134
  throw new Error(`Expected arguments to be passed as an array`);
125
135
  }
126
136
  const name = parameterNames[index];
127
- arg = args[name as keyof typeof args];
137
+ arg =
138
+ name !== undefined && Object.prototype.hasOwnProperty.call(args, name)
139
+ ? args[name as keyof typeof args]
140
+ : undefined;
128
141
 
129
142
  if (arg === undefined) {
130
143
  throw new Error(`Parameter ${name} is required`);
@@ -157,6 +170,40 @@ export function normalizeMoveArguments(
157
170
  return normalizedArgs;
158
171
  }
159
172
 
173
+ /* -------------------------- Config-mapped arguments -------------------------- */
174
+
175
+ /** Context passed to config resolver functions. */
176
+ export interface ConfigResolverContext {
177
+ /**
178
+ * The matched parameter's own instantiated type arguments (not the whole function's type
179
+ * argument tuple). Concrete instantiations are canonical type tags; generic positions pass
180
+ * the caller's `typeArguments` strings through as provided.
181
+ */
182
+ typeArguments: string[];
183
+ /** The package address the generated call will be sent to. */
184
+ packageAddress: string;
185
+ /** The Move module of the generated call. */
186
+ moduleName: string;
187
+ /** The Move function of the generated call. */
188
+ functionName: string;
189
+ /** The Move name of the matched parameter, when the summary includes parameter names. */
190
+ parameterName?: string;
191
+ /** The matched parameter's position in the generated function's arguments. */
192
+ parameterIndex: number;
193
+ }
194
+
195
+ /**
196
+ * A non-callback transaction argument in a generated config object, used for keys whose matched
197
+ * parameter can't be supplied as an object id string.
198
+ */
199
+ export type ConfigObjectValue = Exclude<TransactionObjectArgument, (...args: never[]) => unknown>;
200
+
201
+ /**
202
+ * A plain value in a generated config object: an object id or a non-callback transaction
203
+ * argument. Keys that can resolve multiple bindings are typed as resolver functions instead.
204
+ */
205
+ export type ConfigValue = string | ConfigObjectValue;
206
+
160
207
  /* -------------------------- Move type tags -------------------------- */
161
208
 
162
209
  /** A type argument: a type tag string, or a BCS type whose name is a Move type. */