@rtsdk/topia 0.17.9 → 0.18.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.
package/dist/index.cjs CHANGED
@@ -40731,6 +40731,52 @@ class DroppedAsset extends Asset {
40731
40731
  }
40732
40732
  _DroppedAsset_updateDroppedAsset = new WeakMap();
40733
40733
 
40734
+ // TODO: Define InventoryItemInterface and InventoryItemOptionalInterface
40735
+ /**
40736
+ * InventoryItem represents an item in a user's inventory.
40737
+ *
40738
+ * @remarks
40739
+ * This class should be instantiated via InventoryFactory only.
40740
+ *
40741
+ * @keywords inventory, item, asset, object
40742
+ */
40743
+ class InventoryItem extends SDKController {
40744
+ // Add more properties as needed (e.g., name, quantity, metadata)
40745
+ constructor(topia, id, options = { attributes: {}, credentials: {} }) {
40746
+ super(topia, Object.assign({}, options.credentials));
40747
+ this.id = id;
40748
+ Object.assign(this, options.attributes);
40749
+ const { name = "", description = "", type = "", created_at = new Date(), updated_at = new Date(), metadata = null, image_path = "", interactive_key_id = "", status = "", } = options.attributes;
40750
+ this.name = name;
40751
+ this.description = description;
40752
+ this.type = type;
40753
+ this.created_at = created_at;
40754
+ this.updated_at = updated_at;
40755
+ this.metadata = metadata;
40756
+ this.image_path = image_path;
40757
+ this.interactive_key_id = interactive_key_id;
40758
+ this.status = status;
40759
+ }
40760
+ /**
40761
+ * Fetches the inventory item details from the platform and assigns them to this instance.
40762
+ *
40763
+ * @example
40764
+ * ```ts
40765
+ * await item.fetchInventoryItemById();
40766
+ * ```
40767
+ *
40768
+ * @returns {Promise<InventoryItem>} Returns when the item has been fetched and assigned.
40769
+ */
40770
+ fetchInventoryItemById() {
40771
+ return __awaiter(this, void 0, void 0, function* () {
40772
+ const response = yield this.topiaPublicApi().get(`/inventory/${this.id}`, this.requestOptions);
40773
+ Object.assign(this, response.data);
40774
+ return this;
40775
+ });
40776
+ }
40777
+ }
40778
+
40779
+ var _Ecosystem_inventoryItems;
40734
40780
  /* ============================================================================
40735
40781
  AI RULES for code assistants
40736
40782
 
@@ -40774,7 +40820,9 @@ AI RULES for code assistants
40774
40820
  class Ecosystem extends SDKController {
40775
40821
  constructor(topia, options = { credentials: {} }) {
40776
40822
  super(topia, options.credentials);
40823
+ _Ecosystem_inventoryItems.set(this, void 0);
40777
40824
  this.dataObject = {};
40825
+ __classPrivateFieldSet(this, _Ecosystem_inventoryItems, [], "f");
40778
40826
  }
40779
40827
  /**
40780
40828
  * Retrieves the data object for a Topia ecosystem. Requires canUpdateEcosystemDataObjects permission to be set to true for the public key.
@@ -40911,6 +40959,88 @@ class Ecosystem extends SDKController {
40911
40959
  }
40912
40960
  });
40913
40961
  }
40962
+ /**
40963
+ * Retrieves all inventory items for a given keyholder (app public key).
40964
+ *
40965
+ * @keywords get, fetch, retrieve, list, inventory, items, keyholder
40966
+ *
40967
+ * @example
40968
+ * ```ts
40969
+ * const items = await ecosystem.fetchInventoryItems("appPublicKey", "appJWT");
40970
+ * ```
40971
+ *
40972
+ * @returns {Promise<object[]>} Returns an array of InventoryItem objects.
40973
+ */
40974
+ fetchInventoryItems() {
40975
+ return __awaiter(this, void 0, void 0, function* () {
40976
+ try {
40977
+ // const query = appJWT ? `?appPublicKey=${appPublicKey}&appJWT=${appJWT}` : `?appPublicKey=${appPublicKey}`;
40978
+ const response = yield this.topiaPublicApi().get(`/inventory/`, this.requestOptions);
40979
+ // TODO: Replace 'object' with InventoryItem and instantiate InventoryItem objects if needed
40980
+ // create temp map and then update private property only once
40981
+ const tempItems = [];
40982
+ for (const index in response.data) {
40983
+ tempItems.push(new InventoryItem(this.topia, response.data[index].id, {
40984
+ attributes: response.data[index],
40985
+ credentials: this.credentials,
40986
+ }));
40987
+ }
40988
+ __classPrivateFieldSet(this, _Ecosystem_inventoryItems, tempItems, "f");
40989
+ }
40990
+ catch (error) {
40991
+ throw this.errorHandler({ error, sdkMethod: "Ecosystem.fetchInventoryItems" });
40992
+ }
40993
+ });
40994
+ }
40995
+ get inventoryItems() {
40996
+ return __classPrivateFieldGet(this, _Ecosystem_inventoryItems, "f");
40997
+ }
40998
+ }
40999
+ _Ecosystem_inventoryItems = new WeakMap();
41000
+
41001
+ /**
41002
+ * Controller for a user's owned inventory item.
41003
+ *
41004
+ * @remarks
41005
+ * This class should be instantiated via UserInventoryItemFactory only.
41006
+ *
41007
+ * @property inventoryItemId - The root inventory item's id
41008
+ */
41009
+ class UserInventoryItem extends InventoryItem {
41010
+ constructor(topia, id, options = { attributes: {}, credentials: {} }) {
41011
+ const { attributes = {} } = options;
41012
+ const { item_id = "" } = attributes;
41013
+ super(topia, item_id, { attributes: options.attributes, credentials: options.credentials });
41014
+ Object.assign(this, options.attributes);
41015
+ this.userItemId = id;
41016
+ const { user_id = "", quantity = 0, grant_source = "unknown", type = "unknown", metadata = {}, created_at = new Date(), updated_at = new Date(), } = options.attributes;
41017
+ this.item_id = item_id;
41018
+ this.quantity = quantity;
41019
+ this.grant_source = grant_source;
41020
+ this.user_id = user_id;
41021
+ this.type = type;
41022
+ this.metadata = metadata;
41023
+ this.created_at = created_at;
41024
+ this.updated_at = updated_at;
41025
+ }
41026
+ /**
41027
+ * Fetches the user inventory item details from the platform and assigns them to this instance.
41028
+ *
41029
+ * @example
41030
+ * ```ts
41031
+ * await userInventoryItem.fetchUserInventoryItemById();
41032
+ * ```
41033
+ *
41034
+ * @returns {Promise<void>} Returns when the item has been fetched and assigned.
41035
+ */
41036
+ fetchUserInventoryItemById() {
41037
+ return __awaiter(this, void 0, void 0, function* () {
41038
+ // TODO: Implement API call to fetch user inventory item details
41039
+ // Example:
41040
+ // const response = await this.topia.api.get(`/inventory/user-items/${this.userId}/${this.inventoryItemId}`, this.options?.credentials);
41041
+ // Object.assign(this, response.data);
41042
+ });
41043
+ }
40914
41044
  }
40915
41045
 
40916
41046
  /* ============================================================================
@@ -41821,7 +41951,7 @@ class World extends SDKController {
41821
41951
  }
41822
41952
  _World_droppedAssetsMap = new WeakMap();
41823
41953
 
41824
- var _User_adminWorldsMap, _User_assetsMap, _User_scenesMap, _User_worldsMap;
41954
+ var _User_userInventoryItems, _User_adminWorldsMap, _User_assetsMap, _User_scenesMap, _User_worldsMap;
41825
41955
  /* ============================================================================
41826
41956
  AI RULES for code assistants
41827
41957
 
@@ -41866,6 +41996,7 @@ AI RULES for code assistants
41866
41996
  class User extends SDKController {
41867
41997
  constructor(topia, options = { profileId: null, credentials: {} }) {
41868
41998
  super(topia, Object.assign({ profileId: options === null || options === void 0 ? void 0 : options.profileId }, options.credentials));
41999
+ _User_userInventoryItems.set(this, void 0);
41869
42000
  _User_adminWorldsMap.set(this, void 0);
41870
42001
  _User_assetsMap.set(this, void 0);
41871
42002
  _User_scenesMap.set(this, void 0);
@@ -41877,6 +42008,7 @@ class User extends SDKController {
41877
42008
  __classPrivateFieldSet(this, _User_assetsMap, {}, "f");
41878
42009
  __classPrivateFieldSet(this, _User_scenesMap, {}, "f");
41879
42010
  __classPrivateFieldSet(this, _User_worldsMap, {}, "f");
42011
+ __classPrivateFieldSet(this, _User_userInventoryItems, [], "f");
41880
42012
  }
41881
42013
  get adminWorlds() {
41882
42014
  return __classPrivateFieldGet(this, _User_adminWorldsMap, "f");
@@ -42491,9 +42623,46 @@ class User extends SDKController {
42491
42623
  }
42492
42624
  });
42493
42625
  }
42626
+ /**
42627
+ * Retrieves all inventory items owned by this visitor and app's key.
42628
+ *
42629
+ * @keywords get, fetch, retrieve, list, inventory, items, visitor
42630
+ *
42631
+ * @example
42632
+ * ```ts
42633
+ * const items = await visitor.fetchInventoryItems();
42634
+ * ```
42635
+ *
42636
+ * @returns {Promise<void>} Returns an array of InventoryItem objects.
42637
+ */
42638
+ fetchInventoryItems() {
42639
+ return __awaiter(this, void 0, void 0, function* () {
42640
+ try {
42641
+ if (!this.profileId)
42642
+ throw "This method requires the use of a profileId";
42643
+ const response = yield this.topiaPublicApi().get(`/user/${this.profileId}/get-user-inventory-items`, this.requestOptions);
42644
+ // TODO: Replace 'object' with InventoryItem and instantiate InventoryItem objects if needed
42645
+ const tempItems = [];
42646
+ for (const index in response.data) {
42647
+ tempItems.push(new UserInventoryItem(this.topia, response.data[index].id, {
42648
+ attributes: response.data[index],
42649
+ credentials: this.credentials,
42650
+ }));
42651
+ }
42652
+ __classPrivateFieldSet(this, _User_userInventoryItems, tempItems, "f");
42653
+ }
42654
+ catch (error) {
42655
+ throw this.errorHandler({ error, sdkMethod: "Visitor.fetchInventoryItems" });
42656
+ }
42657
+ });
42658
+ }
42659
+ get inventoryItems() {
42660
+ return __classPrivateFieldGet(this, _User_userInventoryItems, "f");
42661
+ }
42494
42662
  }
42495
- _User_adminWorldsMap = new WeakMap(), _User_assetsMap = new WeakMap(), _User_scenesMap = new WeakMap(), _User_worldsMap = new WeakMap();
42663
+ _User_userInventoryItems = new WeakMap(), _User_adminWorldsMap = new WeakMap(), _User_assetsMap = new WeakMap(), _User_scenesMap = new WeakMap(), _User_worldsMap = new WeakMap();
42496
42664
 
42665
+ var _Visitor_visitorInventoryItems;
42497
42666
  /* ============================================================================
42498
42667
  AI RULES for code assistants
42499
42668
 
@@ -42535,9 +42704,11 @@ AI RULES for code assistants
42535
42704
  class Visitor extends User {
42536
42705
  constructor(topia, id, urlSlug, options = { attributes: {}, credentials: {} }) {
42537
42706
  super(topia, { credentials: Object.assign({ urlSlug }, options.credentials) });
42707
+ _Visitor_visitorInventoryItems.set(this, void 0);
42538
42708
  Object.assign(this, options.attributes);
42539
42709
  this.id = id;
42540
42710
  this.urlSlug = urlSlug;
42711
+ __classPrivateFieldSet(this, _Visitor_visitorInventoryItems, [], "f");
42541
42712
  }
42542
42713
  /**
42543
42714
  * Get a single visitor from a world
@@ -43044,7 +43215,138 @@ class Visitor extends User {
43044
43215
  }
43045
43216
  });
43046
43217
  }
43047
- }
43218
+ /**
43219
+ * Retrieves all inventory items owned by this visitor and app's key.
43220
+ *
43221
+ * @keywords get, fetch, retrieve, list, inventory, items, visitor
43222
+ *
43223
+ * @example
43224
+ * ```ts
43225
+ * const items = await visitor.fetchInventoryItems();
43226
+ * ```
43227
+ *
43228
+ * @returns {Promise<void>} Returns an array of InventoryItem objects.
43229
+ */
43230
+ fetchInventoryItem(item) {
43231
+ return __awaiter(this, void 0, void 0, function* () {
43232
+ try {
43233
+ const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/visitors/${this.id}/get-visitor-inventory-items/${item.id}`, this.requestOptions);
43234
+ return new UserInventoryItem(this.topia, response.data.id, {
43235
+ attributes: response.data,
43236
+ credentials: this.credentials,
43237
+ });
43238
+ }
43239
+ catch (error) {
43240
+ throw this.errorHandler({ error, sdkMethod: "Visitor.fetchInventoryItems" });
43241
+ }
43242
+ });
43243
+ }
43244
+ /**
43245
+ * Retrieves all inventory items owned by this visitor and app's key.
43246
+ *
43247
+ * @keywords get, fetch, retrieve, list, inventory, items, visitor
43248
+ *
43249
+ * @example
43250
+ * ```ts
43251
+ * const items = await visitor.fetchInventoryItems();
43252
+ * ```
43253
+ *
43254
+ * @returns {Promise<void>} Returns an array of InventoryItem objects.
43255
+ */
43256
+ fetchInventoryItems() {
43257
+ return __awaiter(this, void 0, void 0, function* () {
43258
+ try {
43259
+ const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/visitors/${this.id}/get-visitor-inventory-items`, this.requestOptions);
43260
+ // TODO: Replace 'object' with InventoryItem and instantiate InventoryItem objects if needed
43261
+ const tempItems = [];
43262
+ for (const index in response.data) {
43263
+ tempItems.push(new UserInventoryItem(this.topia, response.data[index].id, {
43264
+ attributes: response.data[index],
43265
+ credentials: this.credentials,
43266
+ }));
43267
+ }
43268
+ __classPrivateFieldSet(this, _Visitor_visitorInventoryItems, tempItems, "f");
43269
+ }
43270
+ catch (error) {
43271
+ throw this.errorHandler({ error, sdkMethod: "Visitor.fetchInventoryItems" });
43272
+ }
43273
+ });
43274
+ }
43275
+ get inventoryItems() {
43276
+ return __classPrivateFieldGet(this, _Visitor_visitorInventoryItems, "f");
43277
+ }
43278
+ /**
43279
+ * Grants an inventory item to this visitor.
43280
+ *
43281
+ * @param item The ID of the inventory item to grant.
43282
+ * @param quantity The quantity to grant (default 1).
43283
+ *
43284
+ * @example
43285
+ * ```ts
43286
+ * await visitor.grantInventoryItem("item-id-123", 2);
43287
+ * ```
43288
+ *
43289
+ * @returns {Promise<UserInventoryItem>} Returns the updated inventory or a response object.
43290
+ */
43291
+ grantInventoryItem(item, quantity = 1) {
43292
+ var _a;
43293
+ return __awaiter(this, void 0, void 0, function* () {
43294
+ // Error if item already exists in #visitorInventoryItems
43295
+ const exists = (_a = __classPrivateFieldGet(this, _Visitor_visitorInventoryItems, "f")) === null || _a === void 0 ? void 0 : _a.some((visitorItem) => visitorItem.id === item.id);
43296
+ if (exists) {
43297
+ throw new Error(`Inventory item with id '${item.id}' already exists in visitorInventoryItems.`);
43298
+ }
43299
+ try {
43300
+ const response = yield this.topiaPublicApi().put(`/world/${this.urlSlug}/visitors/${this.id}/grant-visitor-inventory-item`, { itemId: item.id, quantity }, this.requestOptions);
43301
+ const userInventoryItemFactory = new UserInventoryItemFactory(this.topia);
43302
+ const { inventoryItem, user_id, quantity: newQuantity } = response.data;
43303
+ return userInventoryItemFactory.create(inventoryItem, user_id, newQuantity, {
43304
+ attributes: response.data,
43305
+ credentials: this.credentials,
43306
+ });
43307
+ }
43308
+ catch (error) {
43309
+ throw this.errorHandler({ error, sdkMethod: "Visitor.grantInventoryItem" });
43310
+ }
43311
+ });
43312
+ }
43313
+ /**
43314
+ * Modifies the quantity of an inventory item in this visitor's inventory.
43315
+ *
43316
+ * @param item The ID of the inventory item to modify.
43317
+ * @param quantity The new quantity to set.
43318
+ *
43319
+ * @example
43320
+ * ```ts
43321
+ * await visitor.modifyInventoryItemQuantity("item-id-123", 5);
43322
+ * ```
43323
+ *
43324
+ * @returns {Promise<UserInventoryItem>} Returns the updated inventory or a response object.
43325
+ */
43326
+ modifyInventoryItemQuantity(item, quantity) {
43327
+ var _a;
43328
+ return __awaiter(this, void 0, void 0, function* () {
43329
+ // Check for existence in #visitorInventoryItems
43330
+ const found = (_a = __classPrivateFieldGet(this, _Visitor_visitorInventoryItems, "f")) === null || _a === void 0 ? void 0 : _a.some((visitorItem) => visitorItem.id === item.userItemId);
43331
+ if (!found) {
43332
+ throw new Error(`Inventory item with id '${item.userItemId}' does not exist in visitorInventoryItems.`);
43333
+ }
43334
+ try {
43335
+ const response = yield this.topiaPublicApi().put(`/world/${this.urlSlug}/visitors/${this.id}/update-visitor-inventory-item-quantity`, { userItemId: item.id, itemId: item.item_id, quantity }, this.requestOptions);
43336
+ const userInventoryItemFactory = new UserInventoryItemFactory(this.topia);
43337
+ const { inventoryItem, user_id, quantity: newQuantity } = response.data;
43338
+ return userInventoryItemFactory.create(inventoryItem, user_id, newQuantity, {
43339
+ attributes: response.data,
43340
+ credentials: this.credentials,
43341
+ });
43342
+ }
43343
+ catch (error) {
43344
+ throw this.errorHandler({ error, sdkMethod: "Visitor.modifyInventoryItemQuantity" });
43345
+ }
43346
+ });
43347
+ }
43348
+ }
43349
+ _Visitor_visitorInventoryItems = new WeakMap();
43048
43350
 
43049
43351
  /**
43050
43352
  * Create an instance of WebRTCConnector class with optional session credentials.
@@ -43356,7 +43658,7 @@ class AssetFactory extends SDKController {
43356
43658
  super(topia);
43357
43659
  }
43358
43660
  /**
43359
- * Instantiate a new instance of Asset class with the specified asset ID.
43661
+ * Instantiate a new instance of Asset class with the specified asset id.
43360
43662
  *
43361
43663
  * @remarks
43362
43664
  * This method creates a new Asset controller instance that can be used to interact with an existing asset.
@@ -43574,7 +43876,7 @@ class DroppedAssetFactory extends SDKController {
43574
43876
  *
43575
43877
  * @remarks
43576
43878
  * This method leverages the handleGetDroppedAssetByUniqueName endpoint in the Public API and assumes there is exactly one dropped asset with the matching uniqueName for the given urlSlug.
43577
- * Use this when you need to find a dropped asset by its uniqueName rather than its ID.
43879
+ * Use this when you need to find a dropped asset by its uniqueName rather than its id.
43578
43880
  *
43579
43881
  * @keywords find, search, unique name, retrieve, locate, lookup, dropped asset
43580
43882
  *
@@ -43876,7 +44178,7 @@ class SceneFactory {
43876
44178
  *
43877
44179
  * @remarks
43878
44180
  * This method creates a controller instance for working with a scene but does not fetch its properties.
43879
- * Use this when you need to interact with a specific scene by its ID.
44181
+ * Use this when you need to interact with a specific scene by its id.
43880
44182
  *
43881
44183
  * @keywords create, instantiate, scene, initialize, instance, template
43882
44184
  *
@@ -43983,7 +44285,7 @@ class UserFactory {
43983
44285
  *
43984
44286
  * @remarks
43985
44287
  * This method creates a controller instance for interacting with user-specific operations.
43986
- * The User controller doesn't require an ID since it represents the currently authenticated user.
44288
+ * The User controller doesn't require an id since it represents the currently authenticated user.
43987
44289
  *
43988
44290
  * @keywords create, instantiate, user, initialize, account, profile, member
43989
44291
  *
@@ -44082,7 +44384,7 @@ class VisitorFactory {
44082
44384
  *
44083
44385
  * // Create a Visitor instance with credentials
44084
44386
  * const visitorInstance = Visitor.create(
44085
- * 12345, // visitor ID
44387
+ * 12345, // visitor id
44086
44388
  * "my-world-slug",
44087
44389
  * {
44088
44390
  * credentials: {
@@ -44120,7 +44422,7 @@ class VisitorFactory {
44120
44422
  *
44121
44423
  * // Get a fully populated Visitor instance
44122
44424
  * const visitorInstance = await Visitor.get(
44123
- * 12345, // visitor ID
44425
+ * 12345, // visitor id
44124
44426
  * "my-world-slug",
44125
44427
  * {
44126
44428
  * credentials: {
@@ -44457,6 +44759,57 @@ class WorldFactory extends SDKController {
44457
44759
  }
44458
44760
  }
44459
44761
 
44762
+ // import { UserInventoryItem } from "controllers";
44763
+ /**
44764
+ * Factory for creating UserInventoryItem instances. Use this factory to work with user-owned inventory items.
44765
+ *
44766
+ * @remarks
44767
+ * This factory should be instantiated once per application and reused across your codebase.
44768
+ *
44769
+ * @example
44770
+ * ```ts
44771
+ * // In your initialization file (e.g., utils/topiaInit.ts)
44772
+ * import { Topia, UserInventoryItemFactory } from "@rtsdk/topia";
44773
+ * const topia = new Topia({ config });
44774
+ * export const UserInventoryItem = new UserInventoryItemFactory(topia);
44775
+ * ```
44776
+ */
44777
+ class UserInventoryItemFactory {
44778
+ constructor(topia) {
44779
+ this.topia = topia;
44780
+ }
44781
+ /**
44782
+ * Instantiate a new instance of UserInventoryItem class for a user's owned item.
44783
+ *
44784
+ * @example
44785
+ * ```ts
44786
+ * const userItem = UserInventoryItem.create("item-id-123", 42, 5, { credentials });
44787
+ * ```
44788
+ *
44789
+ * @returns {UserInventoryItem} Returns a new UserInventoryItem object for interacting with the specified item.
44790
+ */
44791
+ create(inventoryItemId, userId, quantity, options) {
44792
+ return new UserInventoryItem(this.topia, inventoryItemId, options);
44793
+ }
44794
+ /**
44795
+ * Retrieve a user inventory item and all its properties.
44796
+ *
44797
+ * @example
44798
+ * ```ts
44799
+ * const userItem = await UserInventoryItem.get("item-id-123", 42, { credentials });
44800
+ * ```
44801
+ *
44802
+ * @returns {Promise<UserInventoryItem>} Returns a new UserInventoryItem object with all properties.
44803
+ */
44804
+ get(inventoryItemId, options) {
44805
+ return __awaiter(this, void 0, void 0, function* () {
44806
+ const userItem = new UserInventoryItem(this.topia, inventoryItemId, options);
44807
+ yield userItem.fetchUserInventoryItemById();
44808
+ return userItem;
44809
+ });
44810
+ }
44811
+ }
44812
+
44460
44813
  Error.stackTraceLimit = 20;
44461
44814
  process.on("unhandledRejection", (reason) => {
44462
44815
  if (reason && reason.data) {
package/dist/index.d.ts CHANGED
@@ -1172,6 +1172,38 @@ declare class World extends SDKController implements WorldInterface {
1172
1172
  }): Promise<void | ResponseType$1>;
1173
1173
  }
1174
1174
 
1175
+ /**
1176
+ * Controller for a user's owned inventory item.
1177
+ *
1178
+ * @remarks
1179
+ * This class should be instantiated via UserInventoryItemFactory only.
1180
+ *
1181
+ * @property inventoryItemId - The root inventory item's id
1182
+ */
1183
+ declare class UserInventoryItem extends InventoryItem implements UserInventoryItemInterface {
1184
+ userItemId: string;
1185
+ user_id: string;
1186
+ item_id: string;
1187
+ quantity: number;
1188
+ created_at?: Date;
1189
+ updated_at?: Date;
1190
+ metadata?: object | null;
1191
+ grant_source: string;
1192
+ type: string;
1193
+ constructor(topia: Topia, id: string, options?: UserInventoryItemOptionalInterface);
1194
+ /**
1195
+ * Fetches the user inventory item details from the platform and assigns them to this instance.
1196
+ *
1197
+ * @example
1198
+ * ```ts
1199
+ * await userInventoryItem.fetchUserInventoryItemById();
1200
+ * ```
1201
+ *
1202
+ * @returns {Promise<void>} Returns when the item has been fetched and assigned.
1203
+ */
1204
+ fetchUserInventoryItemById(): Promise<void>;
1205
+ }
1206
+
1175
1207
  /**
1176
1208
  * Create an instance of User class with optional session credentials.
1177
1209
  *
@@ -1615,6 +1647,53 @@ declare class User extends SDKController implements UserInterface {
1615
1647
  releaseLock?: boolean;
1616
1648
  };
1617
1649
  }): Promise<void | ResponseType$1>;
1650
+ /**
1651
+ * Retrieves all inventory items owned by this visitor and app's key.
1652
+ *
1653
+ * @keywords get, fetch, retrieve, list, inventory, items, visitor
1654
+ *
1655
+ * @example
1656
+ * ```ts
1657
+ * const items = await visitor.fetchInventoryItems();
1658
+ * ```
1659
+ *
1660
+ * @returns {Promise<void>} Returns an array of InventoryItem objects.
1661
+ */
1662
+ fetchInventoryItems(): Promise<void>;
1663
+ get inventoryItems(): UserInventoryItem[];
1664
+ }
1665
+
1666
+ /**
1667
+ * InventoryItem represents an item in a user's inventory.
1668
+ *
1669
+ * @remarks
1670
+ * This class should be instantiated via InventoryFactory only.
1671
+ *
1672
+ * @keywords inventory, item, asset, object
1673
+ */
1674
+ declare class InventoryItem extends SDKController implements InventoryItemInterface {
1675
+ id: string;
1676
+ name?: string;
1677
+ description?: string;
1678
+ type?: string;
1679
+ created_at?: Date;
1680
+ updated_at?: Date;
1681
+ metadata?: object | null;
1682
+ image_path?: string;
1683
+ interactive_key_id?: string;
1684
+ status?: string;
1685
+ constructor(topia: Topia, id: string, options?: InventoryItemOptionalInterface);
1686
+ /**
1687
+ * Fetches the inventory item details from the platform and assigns them to this instance.
1688
+ *
1689
+ * @example
1690
+ * ```ts
1691
+ * await item.fetchInventoryItemById();
1692
+ * ```
1693
+ *
1694
+ * @returns {Promise<InventoryItem>} Returns when the item has been fetched and assigned.
1695
+ */
1696
+ fetchInventoryItemById(): Promise<InventoryItem>;
1618
1697
  }
1619
1698
 
1620
1699
  /**
@@ -1628,6 +1707,7 @@ declare class User extends SDKController implements UserInterface {
1628
1707
  * ```
1629
1708
  */
1630
1709
  declare class Visitor extends User implements VisitorInterface {
1710
+ #private;
1631
1711
  readonly id: number;
1632
1712
  urlSlug: string;
1633
1713
  user?: User;
@@ -1945,6 +2025,61 @@ declare class Visitor extends User implements VisitorInterface {
1945
2025
  sendSignalToVisitor(signal: any): Promise<void | (ResponseType$1 & {
1946
2026
  answerSignal: any;
1947
2027
  })>;
2028
+ /**
2029
+ * Retrieves all inventory items owned by this visitor and app's key.
2030
+ *
2031
+ * @keywords get, fetch, retrieve, list, inventory, items, visitor
2032
+ *
2033
+ * @example
2034
+ * ```ts
2035
+ * const items = await visitor.fetchInventoryItems();
2036
+ * ```
2037
+ *
2038
+ * @returns {Promise<void>} Returns an array of InventoryItem objects.
2039
+ */
2040
+ fetchInventoryItem(item: InventoryItem): Promise<UserInventoryItem>;
2041
+ /**
2042
+ * Retrieves all inventory items owned by this visitor and app's key.
2043
+ *
2044
+ * @keywords get, fetch, retrieve, list, inventory, items, visitor
2045
+ *
2046
+ * @example
2047
+ * ```ts
2048
+ * const items = await visitor.fetchInventoryItems();
2049
+ * ```
2050
+ *
2051
+ * @returns {Promise<void>} Returns an array of InventoryItem objects.
2052
+ */
2053
+ fetchInventoryItems(): Promise<void>;
2054
+ get inventoryItems(): UserInventoryItem[];
2055
+ /**
2056
+ * Grants an inventory item to this visitor.
2057
+ *
2058
+ * @param item The ID of the inventory item to grant.
2059
+ * @param quantity The quantity to grant (default 1).
2060
+ *
2061
+ * @example
2062
+ * ```ts
2063
+ * await visitor.grantInventoryItem("item-id-123", 2);
2064
+ * ```
2065
+ *
2066
+ * @returns {Promise<UserInventoryItem>} Returns the updated inventory or a response object.
2067
+ */
2068
+ grantInventoryItem(item: InventoryItem, quantity?: number): Promise<UserInventoryItem>;
2069
+ /**
2070
+ * Modifies the quantity of an inventory item in this visitor's inventory.
2071
+ *
2072
+ * @param item The ID of the inventory item to modify.
2073
+ * @param quantity The new quantity to set.
2074
+ *
2075
+ * @example
2076
+ * ```ts
2077
+ * await visitor.modifyInventoryItemQuantity("item-id-123", 5);
2078
+ * ```
2079
+ *
2080
+ * @returns {Promise<UserInventoryItem>} Returns the updated inventory or a response object.
2081
+ */
2082
+ modifyInventoryItemQuantity(item: UserInventoryItem, quantity: number): Promise<UserInventoryItem>;
1948
2083
  }
1949
2084
 
1950
2085
  type VisitorType = {
@@ -2332,19 +2467,24 @@ interface VisitorInterface extends SDKInterface {
2332
2467
  name?: string;
2333
2468
  }): Promise<ResponseType$1>;
2334
2469
  getAllParticles(): Promise<ResponseType$1>;
2470
+ fetchInventoryItems(): Promise<void>;
2471
+ inventoryItems: UserInventoryItem[];
2472
+ grantInventoryItem(item: InventoryItem, quantity: number): Promise<UserInventoryItem>;
2473
+ modifyInventoryItemQuantity(item: UserInventoryItem, quantity: number): Promise<UserInventoryItem>;
2474
+ fetchInventoryItem(item: InventoryItem): Promise<UserInventoryItem>;
2335
2475
  triggerParticle({ id, name, duration, }: {
2336
2476
  id?: string;
2337
2477
  name?: string;
2338
2478
  duration?: number;
2339
- fetchDataObject(appPublicKey?: string, appJWT?: string, sharedAppPublicKey?: string, sharedAppJWT?: string): Promise<void | ResponseType$1>;
2340
- setDataObject(dataObject: object | null | undefined, options: object): Promise<void | ResponseType$1>;
2341
- updateDataObject(dataObject: object, options: object): Promise<void | ResponseType$1>;
2342
- incrementDataObjectValue(path: string, amount: number, options: object): Promise<void | ResponseType$1>;
2343
- updatePublicKeyAnalytics(analytics?: AnalyticType[]): Promise<void | ResponseType$1>;
2344
- sendSignalToVisitor(signal: any): Promise<void | (ResponseType$1 & {
2345
- answerSignal: any;
2346
- })>;
2347
2479
  }): Promise<ResponseType$1 | string>;
2480
+ fetchDataObject(appPublicKey?: string, appJWT?: string, sharedAppPublicKey?: string, sharedAppJWT?: string): Promise<void | ResponseType$1>;
2481
+ setDataObject(dataObject: object | null | undefined, options: object): Promise<void | ResponseType$1>;
2482
+ updateDataObject(dataObject: object, options: object): Promise<void | ResponseType$1>;
2483
+ incrementDataObjectValue(path: string, amount: number, options: object): Promise<void | ResponseType$1>;
2484
+ updatePublicKeyAnalytics(analytics?: AnalyticType[]): Promise<void | ResponseType$1>;
2485
+ sendSignalToVisitor(signal: any): Promise<void | (ResponseType$1 & {
2486
+ answerSignal: any;
2487
+ })>;
2348
2488
  color?: string;
2349
2489
  dataObject?: object | null | undefined;
2350
2490
  displayName?: string;
@@ -2509,6 +2649,56 @@ interface WorldWebhooksInterface {
2509
2649
  webhooks: Array<WebhookInterface>;
2510
2650
  }
2511
2651
 
2652
+ type InteractiveCredentials$1 = {
2653
+ apiKey?: string;
2654
+ assetId?: string;
2655
+ interactiveNonce?: string;
2656
+ interactivePublicKey?: string;
2657
+ profileId?: string | null;
2658
+ urlSlug?: string;
2659
+ visitorId?: number;
2660
+ iframeId?: string;
2661
+ gameEngineId?: string;
2662
+ };
2663
+
2664
+ /**
2665
+ * Interface for an inventory item.
2666
+ */
2667
+ interface InventoryItemInterface extends SDKInterface {
2668
+ id: string;
2669
+ name?: string;
2670
+ description?: string;
2671
+ type?: string;
2672
+ created_at?: Date;
2673
+ updated_at?: Date;
2674
+ metadata?: object | null;
2675
+ image_path?: string;
2676
+ interactive_key_id?: string;
2677
+ status?: string;
2678
+ }
2679
+ type InventoryItemOptionalInterface = {
2680
+ attributes?: InventoryItemInterface | object;
2681
+ credentials?: InteractiveCredentials$1;
2682
+ };
2683
+
2684
+ /**
2685
+ * Interface for a user-owned inventory item.
2686
+ */
2687
+ interface UserInventoryItemInterface extends InventoryItemInterface {
2688
+ userItemId: string;
2689
+ user_id: string;
2690
+ item_id: string;
2691
+ quantity: number;
2692
+ created_at?: Date;
2693
+ updated_at?: Date;
2694
+ metadata?: object | null;
2695
+ grant_source: string;
2696
+ }
2697
+ type UserInventoryItemOptionalInterface = {
2698
+ attributes?: UserInventoryItemInterface | object;
2699
+ credentials?: InteractiveCredentials$1;
2700
+ };
2701
+
2512
2702
  /**
2513
2703
  * Create a single instance of Topia axios used for all calls to the public API in all classes
2514
2704
  *
@@ -2660,6 +2850,7 @@ declare class Asset extends SDKController implements AssetInterface {
2660
2850
  * ```
2661
2851
  */
2662
2852
  declare class Ecosystem extends SDKController {
2853
+ #private;
2663
2854
  dataObject?: object | null | undefined;
2664
2855
  constructor(topia: Topia, options?: EcosystemOptionalInterface);
2665
2856
  /**
@@ -2778,6 +2969,20 @@ declare class Ecosystem extends SDKController {
2778
2969
  releaseLock?: boolean;
2779
2970
  };
2780
2971
  }): Promise<void | ResponseType$1>;
2972
+ /**
2973
+ * Retrieves all inventory items for a given keyholder (app public key).
2974
+ *
2975
+ * @keywords get, fetch, retrieve, list, inventory, items, keyholder
2976
+ *
2977
+ * @example
2978
+ * ```ts
2979
+ * const items = await ecosystem.fetchInventoryItems("appPublicKey", "appJWT");
2980
+ * ```
2981
+ *
2982
+ * @returns {Promise<object[]>} Returns an array of InventoryItem objects.
2983
+ */
2984
+ fetchInventoryItems(): Promise<void>;
2985
+ get inventoryItems(): InventoryItem[];
2781
2986
  }
2782
2987
 
2783
2988
  /**
@@ -2942,7 +3147,7 @@ declare class WorldActivity extends SDKController {
2942
3147
  declare class AssetFactory extends SDKController {
2943
3148
  constructor(topia: Topia);
2944
3149
  /**
2945
- * Instantiate a new instance of Asset class with the specified asset ID.
3150
+ * Instantiate a new instance of Asset class with the specified asset id.
2946
3151
  *
2947
3152
  * @remarks
2948
3153
  * This method creates a new Asset controller instance that can be used to interact with an existing asset.
@@ -3104,7 +3309,7 @@ declare class DroppedAssetFactory extends SDKController {
3104
3309
  *
3105
3310
  * @remarks
3106
3311
  * This method leverages the handleGetDroppedAssetByUniqueName endpoint in the Public API and assumes there is exactly one dropped asset with the matching uniqueName for the given urlSlug.
3107
- * Use this when you need to find a dropped asset by its uniqueName rather than its ID.
3312
+ * Use this when you need to find a dropped asset by its uniqueName rather than its id.
3108
3313
  *
3109
3314
  * @keywords find, search, unique name, retrieve, locate, lookup, dropped asset
3110
3315
  *
@@ -3301,7 +3506,7 @@ declare class SceneFactory {
3301
3506
  *
3302
3507
  * @remarks
3303
3508
  * This method creates a controller instance for working with a scene but does not fetch its properties.
3304
- * Use this when you need to interact with a specific scene by its ID.
3509
+ * Use this when you need to interact with a specific scene by its id.
3305
3510
  *
3306
3511
  * @keywords create, instantiate, scene, initialize, instance, template
3307
3512
  *
@@ -3369,7 +3574,7 @@ declare class UserFactory {
3369
3574
  *
3370
3575
  * @remarks
3371
3576
  * This method creates a controller instance for interacting with user-specific operations.
3372
- * The User controller doesn't require an ID since it represents the currently authenticated user.
3577
+ * The User controller doesn't require an id since it represents the currently authenticated user.
3373
3578
  *
3374
3579
  * @keywords create, instantiate, user, initialize, account, profile, member
3375
3580
  *
@@ -3435,7 +3640,7 @@ declare class VisitorFactory {
3435
3640
  *
3436
3641
  * // Create a Visitor instance with credentials
3437
3642
  * const visitorInstance = Visitor.create(
3438
- * 12345, // visitor ID
3643
+ * 12345, // visitor id
3439
3644
  * "my-world-slug",
3440
3645
  * {
3441
3646
  * credentials: {
@@ -3471,7 +3676,7 @@ declare class VisitorFactory {
3471
3676
  *
3472
3677
  * // Get a fully populated Visitor instance
3473
3678
  * const visitorInstance = await Visitor.get(
3474
- * 12345, // visitor ID
3679
+ * 12345, // visitor id
3475
3680
  * "my-world-slug",
3476
3681
  * {
3477
3682
  * credentials: {
@@ -3713,4 +3918,4 @@ declare class WorldFactory extends SDKController {
3713
3918
  }>;
3714
3919
  }
3715
3920
 
3716
- export { AnalyticType, AnimationMetaType, Asset, AssetFactory, AssetInterface, AssetOptionalInterface, AssetOptions, AssetType, DroppedAsset, DroppedAssetClickType, DroppedAssetFactory, DroppedAssetInterface, DroppedAssetLinkType, DroppedAssetMediaType, DroppedAssetMediaVolumeRadius, DroppedAssetOptionalInterface, DroppedAssetOptions, Ecosystem, EcosystemFactory, EcosystemInterface, EcosystemOptionalInterface, FireToastInterface, FrameType, InteractiveCredentials, MoveAllVisitorsInterface, MoveVisitorInterface, OpenIframeInterface, RemoveClickableLinkInterface, ResponseType$1 as ResponseType, SDKController, SDKInterface, Scene, SceneFactory, SceneInterface, SceneOptionalInterface, SetClickableLinkMultiInterface, Topia, TopiaInterface, UpdateBroadcastInterface, UpdateClickTypeInterface, UpdateClickableLinkMultiInterface, UpdateDroppedAssetInterface, UpdateMediaTypeInterface, UpdatePrivateZoneInterface, User, UserFactory, UserInterface, UserOptionalInterface, UserOptions, Visitor, VisitorFactory, VisitorInterface, VisitorOptionalInterface, VisitorOptions, VisitorType, VisitorsToMoveArrayType, VisitorsToMoveType, WebRTCConnector, WebRTCConnectorFactory, WebRTCConnectorInterface, WebRTCConnectorOptionalInterface, WebhookInterface, World, WorldActivity, WorldActivityFactory, WorldActivityOptionalInterface, WorldActivityType, WorldDetailsInterface, WorldFactory, WorldInterface, WorldOptionalInterface, WorldOptions, WorldWebhooksInterface };
3921
+ export { AnalyticType, AnimationMetaType, Asset, AssetFactory, AssetInterface, AssetOptionalInterface, AssetOptions, AssetType, DroppedAsset, DroppedAssetClickType, DroppedAssetFactory, DroppedAssetInterface, DroppedAssetLinkType, DroppedAssetMediaType, DroppedAssetMediaVolumeRadius, DroppedAssetOptionalInterface, DroppedAssetOptions, Ecosystem, EcosystemFactory, EcosystemInterface, EcosystemOptionalInterface, FireToastInterface, FrameType, InteractiveCredentials, InventoryItemInterface, InventoryItemOptionalInterface, MoveAllVisitorsInterface, MoveVisitorInterface, OpenIframeInterface, RemoveClickableLinkInterface, ResponseType$1 as ResponseType, SDKController, SDKInterface, Scene, SceneFactory, SceneInterface, SceneOptionalInterface, SetClickableLinkMultiInterface, Topia, TopiaInterface, UpdateBroadcastInterface, UpdateClickTypeInterface, UpdateClickableLinkMultiInterface, UpdateDroppedAssetInterface, UpdateMediaTypeInterface, UpdatePrivateZoneInterface, User, UserFactory, UserInterface, UserInventoryItemInterface, UserInventoryItemOptionalInterface, UserOptionalInterface, UserOptions, Visitor, VisitorFactory, VisitorInterface, VisitorOptionalInterface, VisitorOptions, VisitorType, VisitorsToMoveArrayType, VisitorsToMoveType, WebRTCConnector, WebRTCConnectorFactory, WebRTCConnectorInterface, WebRTCConnectorOptionalInterface, WebhookInterface, World, WorldActivity, WorldActivityFactory, WorldActivityOptionalInterface, WorldActivityType, WorldDetailsInterface, WorldFactory, WorldInterface, WorldOptionalInterface, WorldOptions, WorldWebhooksInterface };
package/dist/index.js CHANGED
@@ -40729,6 +40729,52 @@ class DroppedAsset extends Asset {
40729
40729
  }
40730
40730
  _DroppedAsset_updateDroppedAsset = new WeakMap();
40731
40731
 
40732
+ // TODO: Define InventoryItemInterface and InventoryItemOptionalInterface
40733
+ /**
40734
+ * InventoryItem represents an item in a user's inventory.
40735
+ *
40736
+ * @remarks
40737
+ * This class should be instantiated via InventoryFactory only.
40738
+ *
40739
+ * @keywords inventory, item, asset, object
40740
+ */
40741
+ class InventoryItem extends SDKController {
40742
+ // Add more properties as needed (e.g., name, quantity, metadata)
40743
+ constructor(topia, id, options = { attributes: {}, credentials: {} }) {
40744
+ super(topia, Object.assign({}, options.credentials));
40745
+ this.id = id;
40746
+ Object.assign(this, options.attributes);
40747
+ const { name = "", description = "", type = "", created_at = new Date(), updated_at = new Date(), metadata = null, image_path = "", interactive_key_id = "", status = "", } = options.attributes;
40748
+ this.name = name;
40749
+ this.description = description;
40750
+ this.type = type;
40751
+ this.created_at = created_at;
40752
+ this.updated_at = updated_at;
40753
+ this.metadata = metadata;
40754
+ this.image_path = image_path;
40755
+ this.interactive_key_id = interactive_key_id;
40756
+ this.status = status;
40757
+ }
40758
+ /**
40759
+ * Fetches the inventory item details from the platform and assigns them to this instance.
40760
+ *
40761
+ * @example
40762
+ * ```ts
40763
+ * await item.fetchInventoryItemById();
40764
+ * ```
40765
+ *
40766
+ * @returns {Promise<InventoryItem>} Returns when the item has been fetched and assigned.
40767
+ */
40768
+ fetchInventoryItemById() {
40769
+ return __awaiter(this, void 0, void 0, function* () {
40770
+ const response = yield this.topiaPublicApi().get(`/inventory/${this.id}`, this.requestOptions);
40771
+ Object.assign(this, response.data);
40772
+ return this;
40773
+ });
40774
+ }
40775
+ }
40776
+
40777
+ var _Ecosystem_inventoryItems;
40732
40778
  /* ============================================================================
40733
40779
  AI RULES for code assistants
40734
40780
 
@@ -40772,7 +40818,9 @@ AI RULES for code assistants
40772
40818
  class Ecosystem extends SDKController {
40773
40819
  constructor(topia, options = { credentials: {} }) {
40774
40820
  super(topia, options.credentials);
40821
+ _Ecosystem_inventoryItems.set(this, void 0);
40775
40822
  this.dataObject = {};
40823
+ __classPrivateFieldSet(this, _Ecosystem_inventoryItems, [], "f");
40776
40824
  }
40777
40825
  /**
40778
40826
  * Retrieves the data object for a Topia ecosystem. Requires canUpdateEcosystemDataObjects permission to be set to true for the public key.
@@ -40909,6 +40957,88 @@ class Ecosystem extends SDKController {
40909
40957
  }
40910
40958
  });
40911
40959
  }
40960
+ /**
40961
+ * Retrieves all inventory items for a given keyholder (app public key).
40962
+ *
40963
+ * @keywords get, fetch, retrieve, list, inventory, items, keyholder
40964
+ *
40965
+ * @example
40966
+ * ```ts
40967
+ * const items = await ecosystem.fetchInventoryItems("appPublicKey", "appJWT");
40968
+ * ```
40969
+ *
40970
+ * @returns {Promise<object[]>} Returns an array of InventoryItem objects.
40971
+ */
40972
+ fetchInventoryItems() {
40973
+ return __awaiter(this, void 0, void 0, function* () {
40974
+ try {
40975
+ // const query = appJWT ? `?appPublicKey=${appPublicKey}&appJWT=${appJWT}` : `?appPublicKey=${appPublicKey}`;
40976
+ const response = yield this.topiaPublicApi().get(`/inventory/`, this.requestOptions);
40977
+ // TODO: Replace 'object' with InventoryItem and instantiate InventoryItem objects if needed
40978
+ // create temp map and then update private property only once
40979
+ const tempItems = [];
40980
+ for (const index in response.data) {
40981
+ tempItems.push(new InventoryItem(this.topia, response.data[index].id, {
40982
+ attributes: response.data[index],
40983
+ credentials: this.credentials,
40984
+ }));
40985
+ }
40986
+ __classPrivateFieldSet(this, _Ecosystem_inventoryItems, tempItems, "f");
40987
+ }
40988
+ catch (error) {
40989
+ throw this.errorHandler({ error, sdkMethod: "Ecosystem.fetchInventoryItems" });
40990
+ }
40991
+ });
40992
+ }
40993
+ get inventoryItems() {
40994
+ return __classPrivateFieldGet(this, _Ecosystem_inventoryItems, "f");
40995
+ }
40996
+ }
40997
+ _Ecosystem_inventoryItems = new WeakMap();
40998
+
40999
+ /**
41000
+ * Controller for a user's owned inventory item.
41001
+ *
41002
+ * @remarks
41003
+ * This class should be instantiated via UserInventoryItemFactory only.
41004
+ *
41005
+ * @property inventoryItemId - The root inventory item's id
41006
+ */
41007
+ class UserInventoryItem extends InventoryItem {
41008
+ constructor(topia, id, options = { attributes: {}, credentials: {} }) {
41009
+ const { attributes = {} } = options;
41010
+ const { item_id = "" } = attributes;
41011
+ super(topia, item_id, { attributes: options.attributes, credentials: options.credentials });
41012
+ Object.assign(this, options.attributes);
41013
+ this.userItemId = id;
41014
+ const { user_id = "", quantity = 0, grant_source = "unknown", type = "unknown", metadata = {}, created_at = new Date(), updated_at = new Date(), } = options.attributes;
41015
+ this.item_id = item_id;
41016
+ this.quantity = quantity;
41017
+ this.grant_source = grant_source;
41018
+ this.user_id = user_id;
41019
+ this.type = type;
41020
+ this.metadata = metadata;
41021
+ this.created_at = created_at;
41022
+ this.updated_at = updated_at;
41023
+ }
41024
+ /**
41025
+ * Fetches the user inventory item details from the platform and assigns them to this instance.
41026
+ *
41027
+ * @example
41028
+ * ```ts
41029
+ * await userInventoryItem.fetchUserInventoryItemById();
41030
+ * ```
41031
+ *
41032
+ * @returns {Promise<void>} Returns when the item has been fetched and assigned.
41033
+ */
41034
+ fetchUserInventoryItemById() {
41035
+ return __awaiter(this, void 0, void 0, function* () {
41036
+ // TODO: Implement API call to fetch user inventory item details
41037
+ // Example:
41038
+ // const response = await this.topia.api.get(`/inventory/user-items/${this.userId}/${this.inventoryItemId}`, this.options?.credentials);
41039
+ // Object.assign(this, response.data);
41040
+ });
41041
+ }
40912
41042
  }
40913
41043
 
40914
41044
  /* ============================================================================
@@ -41819,7 +41949,7 @@ class World extends SDKController {
41819
41949
  }
41820
41950
  _World_droppedAssetsMap = new WeakMap();
41821
41951
 
41822
- var _User_adminWorldsMap, _User_assetsMap, _User_scenesMap, _User_worldsMap;
41952
+ var _User_userInventoryItems, _User_adminWorldsMap, _User_assetsMap, _User_scenesMap, _User_worldsMap;
41823
41953
  /* ============================================================================
41824
41954
  AI RULES for code assistants
41825
41955
 
@@ -41864,6 +41994,7 @@ AI RULES for code assistants
41864
41994
  class User extends SDKController {
41865
41995
  constructor(topia, options = { profileId: null, credentials: {} }) {
41866
41996
  super(topia, Object.assign({ profileId: options === null || options === void 0 ? void 0 : options.profileId }, options.credentials));
41997
+ _User_userInventoryItems.set(this, void 0);
41867
41998
  _User_adminWorldsMap.set(this, void 0);
41868
41999
  _User_assetsMap.set(this, void 0);
41869
42000
  _User_scenesMap.set(this, void 0);
@@ -41875,6 +42006,7 @@ class User extends SDKController {
41875
42006
  __classPrivateFieldSet(this, _User_assetsMap, {}, "f");
41876
42007
  __classPrivateFieldSet(this, _User_scenesMap, {}, "f");
41877
42008
  __classPrivateFieldSet(this, _User_worldsMap, {}, "f");
42009
+ __classPrivateFieldSet(this, _User_userInventoryItems, [], "f");
41878
42010
  }
41879
42011
  get adminWorlds() {
41880
42012
  return __classPrivateFieldGet(this, _User_adminWorldsMap, "f");
@@ -42489,9 +42621,46 @@ class User extends SDKController {
42489
42621
  }
42490
42622
  });
42491
42623
  }
42624
+ /**
42625
+ * Retrieves all inventory items owned by this visitor and app's key.
42626
+ *
42627
+ * @keywords get, fetch, retrieve, list, inventory, items, visitor
42628
+ *
42629
+ * @example
42630
+ * ```ts
42631
+ * const items = await visitor.fetchInventoryItems();
42632
+ * ```
42633
+ *
42634
+ * @returns {Promise<void>} Returns an array of InventoryItem objects.
42635
+ */
42636
+ fetchInventoryItems() {
42637
+ return __awaiter(this, void 0, void 0, function* () {
42638
+ try {
42639
+ if (!this.profileId)
42640
+ throw "This method requires the use of a profileId";
42641
+ const response = yield this.topiaPublicApi().get(`/user/${this.profileId}/get-user-inventory-items`, this.requestOptions);
42642
+ // TODO: Replace 'object' with InventoryItem and instantiate InventoryItem objects if needed
42643
+ const tempItems = [];
42644
+ for (const index in response.data) {
42645
+ tempItems.push(new UserInventoryItem(this.topia, response.data[index].id, {
42646
+ attributes: response.data[index],
42647
+ credentials: this.credentials,
42648
+ }));
42649
+ }
42650
+ __classPrivateFieldSet(this, _User_userInventoryItems, tempItems, "f");
42651
+ }
42652
+ catch (error) {
42653
+ throw this.errorHandler({ error, sdkMethod: "Visitor.fetchInventoryItems" });
42654
+ }
42655
+ });
42656
+ }
42657
+ get inventoryItems() {
42658
+ return __classPrivateFieldGet(this, _User_userInventoryItems, "f");
42659
+ }
42492
42660
  }
42493
- _User_adminWorldsMap = new WeakMap(), _User_assetsMap = new WeakMap(), _User_scenesMap = new WeakMap(), _User_worldsMap = new WeakMap();
42661
+ _User_userInventoryItems = new WeakMap(), _User_adminWorldsMap = new WeakMap(), _User_assetsMap = new WeakMap(), _User_scenesMap = new WeakMap(), _User_worldsMap = new WeakMap();
42494
42662
 
42663
+ var _Visitor_visitorInventoryItems;
42495
42664
  /* ============================================================================
42496
42665
  AI RULES for code assistants
42497
42666
 
@@ -42533,9 +42702,11 @@ AI RULES for code assistants
42533
42702
  class Visitor extends User {
42534
42703
  constructor(topia, id, urlSlug, options = { attributes: {}, credentials: {} }) {
42535
42704
  super(topia, { credentials: Object.assign({ urlSlug }, options.credentials) });
42705
+ _Visitor_visitorInventoryItems.set(this, void 0);
42536
42706
  Object.assign(this, options.attributes);
42537
42707
  this.id = id;
42538
42708
  this.urlSlug = urlSlug;
42709
+ __classPrivateFieldSet(this, _Visitor_visitorInventoryItems, [], "f");
42539
42710
  }
42540
42711
  /**
42541
42712
  * Get a single visitor from a world
@@ -43042,7 +43213,138 @@ class Visitor extends User {
43042
43213
  }
43043
43214
  });
43044
43215
  }
43045
- }
43216
+ /**
43217
+ * Retrieves all inventory items owned by this visitor and app's key.
43218
+ *
43219
+ * @keywords get, fetch, retrieve, list, inventory, items, visitor
43220
+ *
43221
+ * @example
43222
+ * ```ts
43223
+ * const items = await visitor.fetchInventoryItems();
43224
+ * ```
43225
+ *
43226
+ * @returns {Promise<void>} Returns an array of InventoryItem objects.
43227
+ */
43228
+ fetchInventoryItem(item) {
43229
+ return __awaiter(this, void 0, void 0, function* () {
43230
+ try {
43231
+ const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/visitors/${this.id}/get-visitor-inventory-items/${item.id}`, this.requestOptions);
43232
+ return new UserInventoryItem(this.topia, response.data.id, {
43233
+ attributes: response.data,
43234
+ credentials: this.credentials,
43235
+ });
43236
+ }
43237
+ catch (error) {
43238
+ throw this.errorHandler({ error, sdkMethod: "Visitor.fetchInventoryItems" });
43239
+ }
43240
+ });
43241
+ }
43242
+ /**
43243
+ * Retrieves all inventory items owned by this visitor and app's key.
43244
+ *
43245
+ * @keywords get, fetch, retrieve, list, inventory, items, visitor
43246
+ *
43247
+ * @example
43248
+ * ```ts
43249
+ * const items = await visitor.fetchInventoryItems();
43250
+ * ```
43251
+ *
43252
+ * @returns {Promise<void>} Returns an array of InventoryItem objects.
43253
+ */
43254
+ fetchInventoryItems() {
43255
+ return __awaiter(this, void 0, void 0, function* () {
43256
+ try {
43257
+ const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/visitors/${this.id}/get-visitor-inventory-items`, this.requestOptions);
43258
+ // TODO: Replace 'object' with InventoryItem and instantiate InventoryItem objects if needed
43259
+ const tempItems = [];
43260
+ for (const index in response.data) {
43261
+ tempItems.push(new UserInventoryItem(this.topia, response.data[index].id, {
43262
+ attributes: response.data[index],
43263
+ credentials: this.credentials,
43264
+ }));
43265
+ }
43266
+ __classPrivateFieldSet(this, _Visitor_visitorInventoryItems, tempItems, "f");
43267
+ }
43268
+ catch (error) {
43269
+ throw this.errorHandler({ error, sdkMethod: "Visitor.fetchInventoryItems" });
43270
+ }
43271
+ });
43272
+ }
43273
+ get inventoryItems() {
43274
+ return __classPrivateFieldGet(this, _Visitor_visitorInventoryItems, "f");
43275
+ }
43276
+ /**
43277
+ * Grants an inventory item to this visitor.
43278
+ *
43279
+ * @param item The ID of the inventory item to grant.
43280
+ * @param quantity The quantity to grant (default 1).
43281
+ *
43282
+ * @example
43283
+ * ```ts
43284
+ * await visitor.grantInventoryItem("item-id-123", 2);
43285
+ * ```
43286
+ *
43287
+ * @returns {Promise<UserInventoryItem>} Returns the updated inventory or a response object.
43288
+ */
43289
+ grantInventoryItem(item, quantity = 1) {
43290
+ var _a;
43291
+ return __awaiter(this, void 0, void 0, function* () {
43292
+ // Error if item already exists in #visitorInventoryItems
43293
+ const exists = (_a = __classPrivateFieldGet(this, _Visitor_visitorInventoryItems, "f")) === null || _a === void 0 ? void 0 : _a.some((visitorItem) => visitorItem.id === item.id);
43294
+ if (exists) {
43295
+ throw new Error(`Inventory item with id '${item.id}' already exists in visitorInventoryItems.`);
43296
+ }
43297
+ try {
43298
+ const response = yield this.topiaPublicApi().put(`/world/${this.urlSlug}/visitors/${this.id}/grant-visitor-inventory-item`, { itemId: item.id, quantity }, this.requestOptions);
43299
+ const userInventoryItemFactory = new UserInventoryItemFactory(this.topia);
43300
+ const { inventoryItem, user_id, quantity: newQuantity } = response.data;
43301
+ return userInventoryItemFactory.create(inventoryItem, user_id, newQuantity, {
43302
+ attributes: response.data,
43303
+ credentials: this.credentials,
43304
+ });
43305
+ }
43306
+ catch (error) {
43307
+ throw this.errorHandler({ error, sdkMethod: "Visitor.grantInventoryItem" });
43308
+ }
43309
+ });
43310
+ }
43311
+ /**
43312
+ * Modifies the quantity of an inventory item in this visitor's inventory.
43313
+ *
43314
+ * @param item The ID of the inventory item to modify.
43315
+ * @param quantity The new quantity to set.
43316
+ *
43317
+ * @example
43318
+ * ```ts
43319
+ * await visitor.modifyInventoryItemQuantity("item-id-123", 5);
43320
+ * ```
43321
+ *
43322
+ * @returns {Promise<UserInventoryItem>} Returns the updated inventory or a response object.
43323
+ */
43324
+ modifyInventoryItemQuantity(item, quantity) {
43325
+ var _a;
43326
+ return __awaiter(this, void 0, void 0, function* () {
43327
+ // Check for existence in #visitorInventoryItems
43328
+ const found = (_a = __classPrivateFieldGet(this, _Visitor_visitorInventoryItems, "f")) === null || _a === void 0 ? void 0 : _a.some((visitorItem) => visitorItem.id === item.userItemId);
43329
+ if (!found) {
43330
+ throw new Error(`Inventory item with id '${item.userItemId}' does not exist in visitorInventoryItems.`);
43331
+ }
43332
+ try {
43333
+ const response = yield this.topiaPublicApi().put(`/world/${this.urlSlug}/visitors/${this.id}/update-visitor-inventory-item-quantity`, { userItemId: item.id, itemId: item.item_id, quantity }, this.requestOptions);
43334
+ const userInventoryItemFactory = new UserInventoryItemFactory(this.topia);
43335
+ const { inventoryItem, user_id, quantity: newQuantity } = response.data;
43336
+ return userInventoryItemFactory.create(inventoryItem, user_id, newQuantity, {
43337
+ attributes: response.data,
43338
+ credentials: this.credentials,
43339
+ });
43340
+ }
43341
+ catch (error) {
43342
+ throw this.errorHandler({ error, sdkMethod: "Visitor.modifyInventoryItemQuantity" });
43343
+ }
43344
+ });
43345
+ }
43346
+ }
43347
+ _Visitor_visitorInventoryItems = new WeakMap();
43046
43348
 
43047
43349
  /**
43048
43350
  * Create an instance of WebRTCConnector class with optional session credentials.
@@ -43354,7 +43656,7 @@ class AssetFactory extends SDKController {
43354
43656
  super(topia);
43355
43657
  }
43356
43658
  /**
43357
- * Instantiate a new instance of Asset class with the specified asset ID.
43659
+ * Instantiate a new instance of Asset class with the specified asset id.
43358
43660
  *
43359
43661
  * @remarks
43360
43662
  * This method creates a new Asset controller instance that can be used to interact with an existing asset.
@@ -43572,7 +43874,7 @@ class DroppedAssetFactory extends SDKController {
43572
43874
  *
43573
43875
  * @remarks
43574
43876
  * This method leverages the handleGetDroppedAssetByUniqueName endpoint in the Public API and assumes there is exactly one dropped asset with the matching uniqueName for the given urlSlug.
43575
- * Use this when you need to find a dropped asset by its uniqueName rather than its ID.
43877
+ * Use this when you need to find a dropped asset by its uniqueName rather than its id.
43576
43878
  *
43577
43879
  * @keywords find, search, unique name, retrieve, locate, lookup, dropped asset
43578
43880
  *
@@ -43874,7 +44176,7 @@ class SceneFactory {
43874
44176
  *
43875
44177
  * @remarks
43876
44178
  * This method creates a controller instance for working with a scene but does not fetch its properties.
43877
- * Use this when you need to interact with a specific scene by its ID.
44179
+ * Use this when you need to interact with a specific scene by its id.
43878
44180
  *
43879
44181
  * @keywords create, instantiate, scene, initialize, instance, template
43880
44182
  *
@@ -43981,7 +44283,7 @@ class UserFactory {
43981
44283
  *
43982
44284
  * @remarks
43983
44285
  * This method creates a controller instance for interacting with user-specific operations.
43984
- * The User controller doesn't require an ID since it represents the currently authenticated user.
44286
+ * The User controller doesn't require an id since it represents the currently authenticated user.
43985
44287
  *
43986
44288
  * @keywords create, instantiate, user, initialize, account, profile, member
43987
44289
  *
@@ -44080,7 +44382,7 @@ class VisitorFactory {
44080
44382
  *
44081
44383
  * // Create a Visitor instance with credentials
44082
44384
  * const visitorInstance = Visitor.create(
44083
- * 12345, // visitor ID
44385
+ * 12345, // visitor id
44084
44386
  * "my-world-slug",
44085
44387
  * {
44086
44388
  * credentials: {
@@ -44118,7 +44420,7 @@ class VisitorFactory {
44118
44420
  *
44119
44421
  * // Get a fully populated Visitor instance
44120
44422
  * const visitorInstance = await Visitor.get(
44121
- * 12345, // visitor ID
44423
+ * 12345, // visitor id
44122
44424
  * "my-world-slug",
44123
44425
  * {
44124
44426
  * credentials: {
@@ -44455,6 +44757,57 @@ class WorldFactory extends SDKController {
44455
44757
  }
44456
44758
  }
44457
44759
 
44760
+ // import { UserInventoryItem } from "controllers";
44761
+ /**
44762
+ * Factory for creating UserInventoryItem instances. Use this factory to work with user-owned inventory items.
44763
+ *
44764
+ * @remarks
44765
+ * This factory should be instantiated once per application and reused across your codebase.
44766
+ *
44767
+ * @example
44768
+ * ```ts
44769
+ * // In your initialization file (e.g., utils/topiaInit.ts)
44770
+ * import { Topia, UserInventoryItemFactory } from "@rtsdk/topia";
44771
+ * const topia = new Topia({ config });
44772
+ * export const UserInventoryItem = new UserInventoryItemFactory(topia);
44773
+ * ```
44774
+ */
44775
+ class UserInventoryItemFactory {
44776
+ constructor(topia) {
44777
+ this.topia = topia;
44778
+ }
44779
+ /**
44780
+ * Instantiate a new instance of UserInventoryItem class for a user's owned item.
44781
+ *
44782
+ * @example
44783
+ * ```ts
44784
+ * const userItem = UserInventoryItem.create("item-id-123", 42, 5, { credentials });
44785
+ * ```
44786
+ *
44787
+ * @returns {UserInventoryItem} Returns a new UserInventoryItem object for interacting with the specified item.
44788
+ */
44789
+ create(inventoryItemId, userId, quantity, options) {
44790
+ return new UserInventoryItem(this.topia, inventoryItemId, options);
44791
+ }
44792
+ /**
44793
+ * Retrieve a user inventory item and all its properties.
44794
+ *
44795
+ * @example
44796
+ * ```ts
44797
+ * const userItem = await UserInventoryItem.get("item-id-123", 42, { credentials });
44798
+ * ```
44799
+ *
44800
+ * @returns {Promise<UserInventoryItem>} Returns a new UserInventoryItem object with all properties.
44801
+ */
44802
+ get(inventoryItemId, options) {
44803
+ return __awaiter(this, void 0, void 0, function* () {
44804
+ const userItem = new UserInventoryItem(this.topia, inventoryItemId, options);
44805
+ yield userItem.fetchUserInventoryItemById();
44806
+ return userItem;
44807
+ });
44808
+ }
44809
+ }
44810
+
44458
44811
  Error.stackTraceLimit = 20;
44459
44812
  process.on("unhandledRejection", (reason) => {
44460
44813
  if (reason && reason.data) {
package/package.json CHANGED
@@ -27,6 +27,7 @@
27
27
  "rollup-plugin-typescript2": "^0.34.1",
28
28
  "ts-jest": "^29.0.3",
29
29
  "typedoc": "^0.28.8",
30
+ "typedoc-plugin-frontmatter": "^1.3.0",
30
31
  "typescript": "^5.0.4",
31
32
  "yalc": "^1.0.0-pre.53"
32
33
  },
@@ -60,5 +61,5 @@
60
61
  "yalc-push": "yarn build && yalc publish --push --dev --no-scripts"
61
62
  },
62
63
  "type": "module",
63
- "version": "0.17.09"
64
+ "version": "0.18.01"
64
65
  }