@mysten/kiosk 0.7.5 → 0.7.6

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @mysten/kiosk
2
2
 
3
+ ## 0.7.6
4
+
5
+ ### Patch Changes
6
+
7
+ - b48289346: Mark packages as being side-effect free.
8
+ - 3699dd364: Adds support for extensions (on `getKiosk()`), and exports a `getKioskExtension()` function on kioskClient to get extension's content
9
+ - Updated dependencies [b48289346]
10
+ - Updated dependencies [11cf4e68b]
11
+ - @mysten/sui.js@0.44.0
12
+
3
13
  ## 0.7.5
4
14
 
5
15
  ### Patch Changes
@@ -31,6 +31,15 @@ export declare class KioskClient {
31
31
  id: string;
32
32
  options?: FetchKioskOptions;
33
33
  }): Promise<KioskData>;
34
+ /**
35
+ * Fetch the extension data (if any) for a kiosk, by type
36
+ * @param kioskId The ID of the kiosk to lookup
37
+ * @param extensionType The Type of the extension (can be used from by using the type returned by `getKiosk()`)
38
+ */
39
+ getKioskExtension({ kioskId, type }: {
40
+ kioskId: string;
41
+ type: string;
42
+ }): Promise<import("../types").KioskExtension | null>;
34
43
  /**
35
44
  * Query the Transfer Policy(ies) for type `T`.
36
45
  * @param type The Type we're querying for (E.g `0xMyAddress::hero::Hero`)
package/dist/index.js CHANGED
@@ -73,7 +73,6 @@ __export(src_exports, {
73
73
  getBaseRules: () => getBaseRules,
74
74
  getKioskObject: () => getKioskObject,
75
75
  getNormalizedRuleType: () => getNormalizedRuleType,
76
- getTypeWithoutPackageAddress: () => getTypeWithoutPackageAddress,
77
76
  mainnetRules: () => mainnetRules,
78
77
  objArg: () => objArg,
79
78
  parseTransferPolicyCapObject: () => parseTransferPolicyCapObject,
@@ -167,37 +166,38 @@ async function getKioskObject(client, id) {
167
166
  function extractKioskData(data, listings, lockedItemIds, kioskId) {
168
167
  return data.reduce(
169
168
  (acc, val) => {
170
- const type = getTypeWithoutPackageAddress(val.name.type);
171
- switch (type) {
172
- case "kiosk::Item":
173
- acc.itemIds.push(val.objectId);
174
- acc.items.push({
175
- objectId: val.objectId,
176
- type: val.objectType,
177
- isLocked: false,
178
- kioskId
179
- });
180
- break;
181
- case "kiosk::Listing":
182
- acc.listingIds.push(val.objectId);
183
- listings.push({
184
- objectId: val.name.value.id,
185
- listingId: val.objectId,
186
- isExclusive: val.name.value.is_exclusive
187
- });
188
- break;
189
- case "kiosk::Lock":
190
- lockedItemIds?.push(val.name.value.id);
191
- break;
169
+ const type = val.name.type;
170
+ if (type.startsWith("0x2::kiosk::Item")) {
171
+ acc.itemIds.push(val.objectId);
172
+ acc.items.push({
173
+ objectId: val.objectId,
174
+ type: val.objectType,
175
+ isLocked: false,
176
+ kioskId
177
+ });
178
+ }
179
+ if (type.startsWith("0x2::kiosk::Listing")) {
180
+ acc.listingIds.push(val.objectId);
181
+ listings.push({
182
+ objectId: val.name.value.id,
183
+ listingId: val.objectId,
184
+ isExclusive: val.name.value.is_exclusive
185
+ });
186
+ }
187
+ if (type.startsWith("0x2::kiosk::Lock")) {
188
+ lockedItemIds?.push(val.name.value.id);
189
+ }
190
+ if (type.startsWith("0x2::kiosk_extension::ExtensionKey")) {
191
+ acc.extensions.push({
192
+ objectId: val.objectId,
193
+ type: (0, import_utils.normalizeStructTag)((0, import_utils.parseStructTag)(val.name.type).typeParams[0])
194
+ });
192
195
  }
193
196
  return acc;
194
197
  },
195
198
  { items: [], itemIds: [], listingIds: [], extensions: [] }
196
199
  );
197
200
  }
198
- function getTypeWithoutPackageAddress(type) {
199
- return type.split("::").slice(-2).join("::");
200
- }
201
201
  function attachListingsAndPrices(kioskData, listings, listingObjects) {
202
202
  const itemListings = listings.reduce(
203
203
  (acc, item, idx) => {
@@ -620,6 +620,28 @@ async function getOwnedKiosks(client, address, options) {
620
620
  kioskIds: kioskIdList
621
621
  };
622
622
  }
623
+ async function fetchKioskExtension(client, kioskId, extensionType) {
624
+ const extension = await client.getDynamicFieldObject({
625
+ parentId: kioskId,
626
+ name: {
627
+ type: `0x2::kiosk_extension::ExtensionKey<${extensionType}>`,
628
+ value: {
629
+ dummy_field: false
630
+ }
631
+ }
632
+ });
633
+ if (!extension.data)
634
+ return null;
635
+ const fields = extension?.data?.content?.fields?.value?.fields;
636
+ return {
637
+ objectId: extension.data.objectId,
638
+ type: extensionType,
639
+ isEnabled: fields?.is_enabled,
640
+ permissions: fields?.permissions,
641
+ storageId: fields?.storage?.fields?.id?.id,
642
+ storageSize: fields?.storage?.fields?.size
643
+ };
644
+ }
623
645
 
624
646
  // src/query/transfer-policy.ts
625
647
  var import_utils6 = require("@mysten/sui.js/utils");
@@ -726,6 +748,14 @@ var KioskClient = class {
726
748
  options || {}
727
749
  )).data;
728
750
  }
751
+ /**
752
+ * Fetch the extension data (if any) for a kiosk, by type
753
+ * @param kioskId The ID of the kiosk to lookup
754
+ * @param extensionType The Type of the extension (can be used from by using the type returned by `getKiosk()`)
755
+ */
756
+ async getKioskExtension({ kioskId, type }) {
757
+ return fetchKioskExtension(this.client, kioskId, type);
758
+ }
729
759
  /**
730
760
  * Query the Transfer Policy(ies) for type `T`.
731
761
  * @param type The Type we're querying for (E.g `0xMyAddress::hero::Hero`)
@@ -1625,7 +1655,6 @@ validateFinalizedStatus_fn = function() {
1625
1655
  getBaseRules,
1626
1656
  getKioskObject,
1627
1657
  getNormalizedRuleType,
1628
- getTypeWithoutPackageAddress,
1629
1658
  mainnetRules,
1630
1659
  objArg,
1631
1660
  parseTransferPolicyCapObject,