@mysten/kiosk 0.7.5 → 0.7.7

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/package.json CHANGED
@@ -2,11 +2,12 @@
2
2
  "name": "@mysten/kiosk",
3
3
  "author": "Mysten Labs <build@mystenlabs.com>",
4
4
  "description": "Sui Kiosk library",
5
- "version": "0.7.5",
5
+ "version": "0.7.7",
6
6
  "license": "Apache-2.0",
7
7
  "main": "./dist/index.js",
8
8
  "module": "./dist/index.mjs",
9
9
  "types": "./dist/index.d.ts",
10
+ "sideEffects": false,
10
11
  "files": [
11
12
  "dist",
12
13
  "src",
@@ -24,7 +25,7 @@
24
25
  }
25
26
  },
26
27
  "dependencies": {
27
- "@mysten/sui.js": "0.43.3"
28
+ "@mysten/sui.js": "0.45.0"
28
29
  },
29
30
  "devDependencies": {
30
31
  "cross-env": "^7.0.3",
@@ -40,7 +41,7 @@
40
41
  "build": "pnpm build:types && pnpm build:tsup",
41
42
  "build:tsup": "tsup ./src/index.ts --format esm,cjs --sourcemap",
42
43
  "build:types": "tsc --build",
43
- "test": "echo \"Error: no test specified\"",
44
+ "test": "echo 'No unit tests for kiosk SDK'",
44
45
  "pre-commit": "pnpm prettier:fix && pnpm lint && pnpm build",
45
46
  "prettier:check": "prettier -c --ignore-unknown .",
46
47
  "prettier:fix": "prettier -w --ignore-unknown .",
@@ -13,7 +13,7 @@ import {
13
13
  type BaseRulePackageIds,
14
14
  type TransferPolicyRule,
15
15
  } from '../constants';
16
- import { fetchKiosk, getOwnedKiosks } from '../query/kiosk';
16
+ import { fetchKiosk, fetchKioskExtension, getOwnedKiosks } from '../query/kiosk';
17
17
  import {
18
18
  queryOwnedTransferPolicies,
19
19
  queryTransferPolicy,
@@ -87,6 +87,15 @@ export class KioskClient {
87
87
  ).data;
88
88
  }
89
89
 
90
+ /**
91
+ * Fetch the extension data (if any) for a kiosk, by type
92
+ * @param kioskId The ID of the kiosk to lookup
93
+ * @param extensionType The Type of the extension (can be used from by using the type returned by `getKiosk()`)
94
+ */
95
+ async getKioskExtension({ kioskId, type }: { kioskId: string; type: string }) {
96
+ return fetchKioskExtension(this.client, kioskId, type);
97
+ }
98
+
90
99
  /**
91
100
  * Query the Transfer Policy(ies) for type `T`.
92
101
  * @param type The Type we're querying for (E.g `0xMyAddress::hero::Hero`)
@@ -13,6 +13,7 @@ import { isValidSuiAddress } from '@mysten/sui.js/utils';
13
13
  import {
14
14
  FetchKioskOptions,
15
15
  KIOSK_OWNER_CAP,
16
+ KioskExtension,
16
17
  KioskListing,
17
18
  OwnedKiosks,
18
19
  PagedKioskData,
@@ -151,3 +152,34 @@ export async function getOwnedKiosks(
151
152
  kioskIds: kioskIdList,
152
153
  };
153
154
  }
155
+
156
+ // Get a kiosk extension data for a given kioskId and extensionType.
157
+ export async function fetchKioskExtension(
158
+ client: SuiClient,
159
+ kioskId: string,
160
+ extensionType: string,
161
+ ): Promise<KioskExtension | null> {
162
+ const extension = await client.getDynamicFieldObject({
163
+ parentId: kioskId,
164
+ name: {
165
+ type: `0x2::kiosk_extension::ExtensionKey<${extensionType}>`,
166
+ value: {
167
+ dummy_field: false,
168
+ },
169
+ },
170
+ });
171
+
172
+ if (!extension.data) return null;
173
+
174
+ const fields = (extension?.data?.content as { fields: { [k: string]: any } })?.fields?.value
175
+ ?.fields;
176
+
177
+ return {
178
+ objectId: extension.data.objectId,
179
+ type: extensionType,
180
+ isEnabled: fields?.is_enabled,
181
+ permissions: fields?.permissions,
182
+ storageId: fields?.storage?.fields?.id?.id,
183
+ storageSize: fields?.storage?.fields?.size,
184
+ };
185
+ }
@@ -108,6 +108,25 @@ export type KioskItem = {
108
108
  /** Optional Kiosk Data */
109
109
  data?: SuiObjectData;
110
110
  };
111
+
112
+ /** The overview type returned from `getKiosk` */
113
+ export type KioskExtensionOverview = {
114
+ /** The ID of the extension's DF */
115
+ objectId: string;
116
+ /** The inner type of the Extension */
117
+ type: string;
118
+ };
119
+ /**
120
+ * Hold the KioskExtension data
121
+ */
122
+ export type KioskExtension = KioskExtensionOverview & {
123
+ /** These fields are only there if we have `withExtensions` flag */
124
+ isEnabled: boolean;
125
+ permissions: string;
126
+ storageId: string;
127
+ storageSize: number;
128
+ };
129
+
111
130
  /**
112
131
  * Aggregated data from the Kiosk.
113
132
  */
@@ -116,7 +135,7 @@ export type KioskData = {
116
135
  itemIds: string[];
117
136
  listingIds: string[];
118
137
  kiosk?: Kiosk;
119
- extensions: any[]; // type will be defined on later versions of the SDK.
138
+ extensions: KioskExtensionOverview[]; // type will be defined on later versions of the SDK.
120
139
  };
121
140
 
122
141
  export type PagedKioskData = {
package/src/utils.ts CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  type DynamicFieldInfo,
14
14
  } from '@mysten/sui.js/client';
15
15
  import { TransactionBlock, TransactionObjectArgument } from '@mysten/sui.js/transactions';
16
- import { normalizeSuiAddress } from '@mysten/sui.js/utils';
16
+ import { normalizeStructTag, normalizeSuiAddress, parseStructTag } from '@mysten/sui.js/utils';
17
17
 
18
18
  import { bcs } from './bcs';
19
19
  import {
@@ -80,41 +80,42 @@ export function extractKioskData(
80
80
  ): KioskData {
81
81
  return data.reduce<KioskData>(
82
82
  (acc: KioskData, val: DynamicFieldInfo) => {
83
- const type = getTypeWithoutPackageAddress(val.name.type);
84
-
85
- switch (type) {
86
- case 'kiosk::Item':
87
- acc.itemIds.push(val.objectId);
88
- acc.items.push({
89
- objectId: val.objectId,
90
- type: val.objectType,
91
- isLocked: false,
92
- kioskId,
93
- });
94
- break;
95
- case 'kiosk::Listing':
96
- acc.listingIds.push(val.objectId);
97
- listings.push({
98
- objectId: (val.name.value as { id: string }).id,
99
- listingId: val.objectId,
100
- isExclusive: (val.name.value as { is_exclusive: boolean }).is_exclusive,
101
- });
102
- break;
103
- case 'kiosk::Lock':
104
- lockedItemIds?.push((val.name.value as { id: string }).id);
105
- break;
83
+ const type = val.name.type;
84
+
85
+ if (type.startsWith('0x2::kiosk::Item')) {
86
+ acc.itemIds.push(val.objectId);
87
+ acc.items.push({
88
+ objectId: val.objectId,
89
+ type: val.objectType,
90
+ isLocked: false,
91
+ kioskId,
92
+ });
106
93
  }
94
+ if (type.startsWith('0x2::kiosk::Listing')) {
95
+ acc.listingIds.push(val.objectId);
96
+ listings.push({
97
+ objectId: (val.name.value as { id: string }).id,
98
+ listingId: val.objectId,
99
+ isExclusive: (val.name.value as { is_exclusive: boolean }).is_exclusive,
100
+ });
101
+ }
102
+ if (type.startsWith('0x2::kiosk::Lock')) {
103
+ lockedItemIds?.push((val.name.value as { id: string }).id);
104
+ }
105
+
106
+ if (type.startsWith('0x2::kiosk_extension::ExtensionKey')) {
107
+ acc.extensions.push({
108
+ objectId: val.objectId,
109
+ type: normalizeStructTag(parseStructTag(val.name.type).typeParams[0]),
110
+ });
111
+ }
112
+
107
113
  return acc;
108
114
  },
109
115
  { items: [], itemIds: [], listingIds: [], extensions: [] },
110
116
  );
111
117
  }
112
118
 
113
- // e.g. 0x2::kiosk::Item -> kiosk::Item
114
- export function getTypeWithoutPackageAddress(type: string) {
115
- return type.split('::').slice(-2).join('::');
116
- }
117
-
118
119
  /**
119
120
  * A helper that attaches the listing prices to kiosk listings.
120
121
  */