@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/dist/index.mjs CHANGED
@@ -22,7 +22,7 @@ var __privateMethod = (obj, member, method) => {
22
22
  };
23
23
 
24
24
  // src/utils.ts
25
- import { normalizeSuiAddress } from "@mysten/sui.js/utils";
25
+ import { normalizeStructTag, normalizeSuiAddress, parseStructTag } from "@mysten/sui.js/utils";
26
26
 
27
27
  // src/bcs.ts
28
28
  import { bcs } from "@mysten/sui.js/bcs";
@@ -105,37 +105,38 @@ async function getKioskObject(client, id) {
105
105
  function extractKioskData(data, listings, lockedItemIds, kioskId) {
106
106
  return data.reduce(
107
107
  (acc, val) => {
108
- const type = getTypeWithoutPackageAddress(val.name.type);
109
- switch (type) {
110
- case "kiosk::Item":
111
- acc.itemIds.push(val.objectId);
112
- acc.items.push({
113
- objectId: val.objectId,
114
- type: val.objectType,
115
- isLocked: false,
116
- kioskId
117
- });
118
- break;
119
- case "kiosk::Listing":
120
- acc.listingIds.push(val.objectId);
121
- listings.push({
122
- objectId: val.name.value.id,
123
- listingId: val.objectId,
124
- isExclusive: val.name.value.is_exclusive
125
- });
126
- break;
127
- case "kiosk::Lock":
128
- lockedItemIds?.push(val.name.value.id);
129
- break;
108
+ const type = val.name.type;
109
+ if (type.startsWith("0x2::kiosk::Item")) {
110
+ acc.itemIds.push(val.objectId);
111
+ acc.items.push({
112
+ objectId: val.objectId,
113
+ type: val.objectType,
114
+ isLocked: false,
115
+ kioskId
116
+ });
117
+ }
118
+ if (type.startsWith("0x2::kiosk::Listing")) {
119
+ acc.listingIds.push(val.objectId);
120
+ listings.push({
121
+ objectId: val.name.value.id,
122
+ listingId: val.objectId,
123
+ isExclusive: val.name.value.is_exclusive
124
+ });
125
+ }
126
+ if (type.startsWith("0x2::kiosk::Lock")) {
127
+ lockedItemIds?.push(val.name.value.id);
128
+ }
129
+ if (type.startsWith("0x2::kiosk_extension::ExtensionKey")) {
130
+ acc.extensions.push({
131
+ objectId: val.objectId,
132
+ type: normalizeStructTag(parseStructTag(val.name.type).typeParams[0])
133
+ });
130
134
  }
131
135
  return acc;
132
136
  },
133
137
  { items: [], itemIds: [], listingIds: [], extensions: [] }
134
138
  );
135
139
  }
136
- function getTypeWithoutPackageAddress(type) {
137
- return type.split("::").slice(-2).join("::");
138
- }
139
140
  function attachListingsAndPrices(kioskData, listings, listingObjects) {
140
141
  const itemListings = listings.reduce(
141
142
  (acc, item, idx) => {
@@ -558,6 +559,28 @@ async function getOwnedKiosks(client, address, options) {
558
559
  kioskIds: kioskIdList
559
560
  };
560
561
  }
562
+ async function fetchKioskExtension(client, kioskId, extensionType) {
563
+ const extension = await client.getDynamicFieldObject({
564
+ parentId: kioskId,
565
+ name: {
566
+ type: `0x2::kiosk_extension::ExtensionKey<${extensionType}>`,
567
+ value: {
568
+ dummy_field: false
569
+ }
570
+ }
571
+ });
572
+ if (!extension.data)
573
+ return null;
574
+ const fields = extension?.data?.content?.fields?.value?.fields;
575
+ return {
576
+ objectId: extension.data.objectId,
577
+ type: extensionType,
578
+ isEnabled: fields?.is_enabled,
579
+ permissions: fields?.permissions,
580
+ storageId: fields?.storage?.fields?.id?.id,
581
+ storageSize: fields?.storage?.fields?.size
582
+ };
583
+ }
561
584
 
562
585
  // src/query/transfer-policy.ts
563
586
  import { isValidSuiAddress as isValidSuiAddress2 } from "@mysten/sui.js/utils";
@@ -664,6 +687,14 @@ var KioskClient = class {
664
687
  options || {}
665
688
  )).data;
666
689
  }
690
+ /**
691
+ * Fetch the extension data (if any) for a kiosk, by type
692
+ * @param kioskId The ID of the kiosk to lookup
693
+ * @param extensionType The Type of the extension (can be used from by using the type returned by `getKiosk()`)
694
+ */
695
+ async getKioskExtension({ kioskId, type }) {
696
+ return fetchKioskExtension(this.client, kioskId, type);
697
+ }
667
698
  /**
668
699
  * Query the Transfer Policy(ies) for type `T`.
669
700
  * @param type The Type we're querying for (E.g `0xMyAddress::hero::Hero`)
@@ -1562,7 +1593,6 @@ export {
1562
1593
  getBaseRules,
1563
1594
  getKioskObject,
1564
1595
  getNormalizedRuleType,
1565
- getTypeWithoutPackageAddress,
1566
1596
  mainnetRules,
1567
1597
  objArg,
1568
1598
  parseTransferPolicyCapObject,