@rtsdk/topia 0.17.9 → 0.18.0

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 itemId 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 itemId 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) {