@rtsdk/topia 0.19.0 → 0.19.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
@@ -40683,6 +40683,32 @@ class DroppedAsset extends Asset {
40683
40683
  }
40684
40684
  });
40685
40685
  }
40686
+ /**
40687
+ * Checks if this dropped asset exists with the current app's public key installed.
40688
+ *
40689
+ * @keywords check, exists, verify, validate, lookup
40690
+ *
40691
+ * @example
40692
+ * ```ts
40693
+ * const { exists } = await droppedAsset.checkExists();
40694
+ * ```
40695
+ *
40696
+ * @returns {Promise<{ exists: boolean }>} Returns whether the asset exists with the app's public key.
40697
+ */
40698
+ checkExists() {
40699
+ return __awaiter(this, void 0, void 0, function* () {
40700
+ try {
40701
+ const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/dropped-asset/${this.id}/exists`, this.requestOptions);
40702
+ return response.data;
40703
+ }
40704
+ catch (error) {
40705
+ throw this.errorHandler({
40706
+ error,
40707
+ sdkMethod: "DroppedAsset.checkExists",
40708
+ });
40709
+ }
40710
+ });
40711
+ }
40686
40712
  /**
40687
40713
  * Retrieve analytics for a dropped asset by day, week, month, quarter, or year
40688
40714
  *
@@ -41013,7 +41039,7 @@ class UserInventoryItem extends InventoryItem {
41013
41039
  super(topia, item_id, { attributes: options.attributes, credentials: options.credentials });
41014
41040
  Object.assign(this, options.attributes);
41015
41041
  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;
41042
+ const { user_id = "", quantity = 0, grant_source = "unknown", type = "unknown", metadata = {}, created_at = new Date(), updated_at = new Date(), profile_id = null, } = options.attributes;
41017
41043
  this.item_id = item_id;
41018
41044
  this.quantity = quantity;
41019
41045
  this.grant_source = grant_source;
@@ -41022,6 +41048,7 @@ class UserInventoryItem extends InventoryItem {
41022
41048
  this.metadata = metadata;
41023
41049
  this.created_at = created_at;
41024
41050
  this.updated_at = updated_at;
41051
+ this.profile_id = profile_id;
41025
41052
  }
41026
41053
  /**
41027
41054
  * Fetches the user inventory item details from the platform and assigns them to this instance.
@@ -43456,27 +43483,31 @@ class Visitor extends User {
43456
43483
  }
43457
43484
  /**
43458
43485
  * Modifies the quantity of an inventory item in this visitor's inventory.
43486
+ * Supports upsert behavior - if the visitor doesn't own the item yet, it will be granted first.
43459
43487
  *
43460
- * @param item The UserInventoryItem to modify.
43461
- * @param quantity The new quantity to set.
43488
+ * @param item Either a UserInventoryItem (for owned items) or an InventoryItem (for upsert).
43489
+ * @param quantity The quantity delta to apply (positive to add, negative to subtract).
43462
43490
  *
43463
43491
  * @example
43464
43492
  * ```ts
43465
- * await visitor.modifyInventoryItemQuantity("item-id-123", 5);
43493
+ * // Modify an existing user inventory item
43494
+ * await visitor.modifyInventoryItemQuantity(userItem, 5);
43495
+ *
43496
+ * // Upsert: grant if not owned, or modify if already owned
43497
+ * await visitor.modifyInventoryItemQuantity(inventoryItem, 1);
43466
43498
  * ```
43467
43499
  *
43468
43500
  * @returns {Promise<UserInventoryItem>} Returns the updated inventory item or a response object.
43469
43501
  */
43470
43502
  modifyInventoryItemQuantity(item, quantity) {
43471
- var _a;
43472
43503
  return __awaiter(this, void 0, void 0, function* () {
43473
- // Check for existence in #visitorInventoryItems
43474
- const found = (_a = __classPrivateFieldGet(this, _Visitor_visitorInventoryItems, "f")) === null || _a === void 0 ? void 0 : _a.some((visitorItem) => visitorItem.id === item.userItemId);
43475
- if (!found) {
43476
- throw new Error(`Inventory item with id '${item.userItemId}' does not exist in visitorInventoryItems.`);
43477
- }
43478
43504
  try {
43479
- 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);
43505
+ // Determine if item is a UserInventoryItem (has userItemId) or InventoryItem (only has id)
43506
+ const isUserItem = "userItemId" in item && item.userItemId;
43507
+ const body = isUserItem
43508
+ ? { userItemId: item.userItemId, itemId: item.item_id, quantity }
43509
+ : { itemId: item.id, quantity };
43510
+ const response = yield this.topiaPublicApi().put(`/world/${this.urlSlug}/visitors/${this.id}/update-visitor-inventory-item-quantity`, body, this.requestOptions);
43480
43511
  const userInventoryItemFactory = new UserInventoryItemFactory(this.topia);
43481
43512
  const { inventoryItem, user_id, quantity: newQuantity } = response.data;
43482
43513
  return userInventoryItemFactory.create(inventoryItem, user_id, newQuantity, {
package/dist/index.d.ts CHANGED
@@ -651,6 +651,21 @@ declare class DroppedAsset extends Asset implements DroppedAssetInterface {
651
651
  isInteractive?: boolean;
652
652
  interactivePublicKey: string;
653
653
  }): Promise<void | ResponseType$1>;
654
+ /**
655
+ * Checks if this dropped asset exists with the current app's public key installed.
656
+ *
657
+ * @keywords check, exists, verify, validate, lookup
658
+ *
659
+ * @example
660
+ * ```ts
661
+ * const { exists } = await droppedAsset.checkExists();
662
+ * ```
663
+ *
664
+ * @returns {Promise<{ exists: boolean }>} Returns whether the asset exists with the app's public key.
665
+ */
666
+ checkExists(): Promise<{
667
+ exists: boolean;
668
+ }>;
654
669
  /**
655
670
  * Retrieve analytics for a dropped asset by day, week, month, quarter, or year
656
671
  *
@@ -1190,6 +1205,7 @@ declare class UserInventoryItem extends InventoryItem implements UserInventoryIt
1190
1205
  metadata?: object | null;
1191
1206
  grant_source: string;
1192
1207
  type: string;
1208
+ profile_id?: string | null;
1193
1209
  constructor(topia: Topia, id: string, options?: UserInventoryItemOptionalInterface);
1194
1210
  /**
1195
1211
  * Fetches the user inventory item details from the platform and assigns them to this instance.
@@ -2143,18 +2159,23 @@ declare class Visitor extends User implements VisitorInterface {
2143
2159
  grantInventoryItem(item: InventoryItem, quantity?: number): Promise<UserInventoryItem>;
2144
2160
  /**
2145
2161
  * Modifies the quantity of an inventory item in this visitor's inventory.
2162
+ * Supports upsert behavior - if the visitor doesn't own the item yet, it will be granted first.
2146
2163
  *
2147
- * @param item The UserInventoryItem to modify.
2148
- * @param quantity The new quantity to set.
2164
+ * @param item Either a UserInventoryItem (for owned items) or an InventoryItem (for upsert).
2165
+ * @param quantity The quantity delta to apply (positive to add, negative to subtract).
2149
2166
  *
2150
2167
  * @example
2151
2168
  * ```ts
2152
- * await visitor.modifyInventoryItemQuantity("item-id-123", 5);
2169
+ * // Modify an existing user inventory item
2170
+ * await visitor.modifyInventoryItemQuantity(userItem, 5);
2171
+ *
2172
+ * // Upsert: grant if not owned, or modify if already owned
2173
+ * await visitor.modifyInventoryItemQuantity(inventoryItem, 1);
2153
2174
  * ```
2154
2175
  *
2155
2176
  * @returns {Promise<UserInventoryItem>} Returns the updated inventory item or a response object.
2156
2177
  */
2157
- modifyInventoryItemQuantity(item: UserInventoryItem, quantity: number): Promise<UserInventoryItem>;
2178
+ modifyInventoryItemQuantity(item: UserInventoryItem | InventoryItem, quantity: number): Promise<UserInventoryItem>;
2158
2179
  }
2159
2180
 
2160
2181
  type VisitorType = {
@@ -2778,6 +2799,7 @@ interface UserInventoryItemInterface extends InventoryItemInterface {
2778
2799
  updated_at?: Date;
2779
2800
  metadata?: object | null;
2780
2801
  grant_source: string;
2802
+ profile_id?: string | null;
2781
2803
  }
2782
2804
  type UserInventoryItemOptionalInterface = {
2783
2805
  attributes?: UserInventoryItemInterface | object;
package/dist/index.js CHANGED
@@ -40681,6 +40681,32 @@ class DroppedAsset extends Asset {
40681
40681
  }
40682
40682
  });
40683
40683
  }
40684
+ /**
40685
+ * Checks if this dropped asset exists with the current app's public key installed.
40686
+ *
40687
+ * @keywords check, exists, verify, validate, lookup
40688
+ *
40689
+ * @example
40690
+ * ```ts
40691
+ * const { exists } = await droppedAsset.checkExists();
40692
+ * ```
40693
+ *
40694
+ * @returns {Promise<{ exists: boolean }>} Returns whether the asset exists with the app's public key.
40695
+ */
40696
+ checkExists() {
40697
+ return __awaiter(this, void 0, void 0, function* () {
40698
+ try {
40699
+ const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/dropped-asset/${this.id}/exists`, this.requestOptions);
40700
+ return response.data;
40701
+ }
40702
+ catch (error) {
40703
+ throw this.errorHandler({
40704
+ error,
40705
+ sdkMethod: "DroppedAsset.checkExists",
40706
+ });
40707
+ }
40708
+ });
40709
+ }
40684
40710
  /**
40685
40711
  * Retrieve analytics for a dropped asset by day, week, month, quarter, or year
40686
40712
  *
@@ -41011,7 +41037,7 @@ class UserInventoryItem extends InventoryItem {
41011
41037
  super(topia, item_id, { attributes: options.attributes, credentials: options.credentials });
41012
41038
  Object.assign(this, options.attributes);
41013
41039
  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;
41040
+ const { user_id = "", quantity = 0, grant_source = "unknown", type = "unknown", metadata = {}, created_at = new Date(), updated_at = new Date(), profile_id = null, } = options.attributes;
41015
41041
  this.item_id = item_id;
41016
41042
  this.quantity = quantity;
41017
41043
  this.grant_source = grant_source;
@@ -41020,6 +41046,7 @@ class UserInventoryItem extends InventoryItem {
41020
41046
  this.metadata = metadata;
41021
41047
  this.created_at = created_at;
41022
41048
  this.updated_at = updated_at;
41049
+ this.profile_id = profile_id;
41023
41050
  }
41024
41051
  /**
41025
41052
  * Fetches the user inventory item details from the platform and assigns them to this instance.
@@ -43454,27 +43481,31 @@ class Visitor extends User {
43454
43481
  }
43455
43482
  /**
43456
43483
  * Modifies the quantity of an inventory item in this visitor's inventory.
43484
+ * Supports upsert behavior - if the visitor doesn't own the item yet, it will be granted first.
43457
43485
  *
43458
- * @param item The UserInventoryItem to modify.
43459
- * @param quantity The new quantity to set.
43486
+ * @param item Either a UserInventoryItem (for owned items) or an InventoryItem (for upsert).
43487
+ * @param quantity The quantity delta to apply (positive to add, negative to subtract).
43460
43488
  *
43461
43489
  * @example
43462
43490
  * ```ts
43463
- * await visitor.modifyInventoryItemQuantity("item-id-123", 5);
43491
+ * // Modify an existing user inventory item
43492
+ * await visitor.modifyInventoryItemQuantity(userItem, 5);
43493
+ *
43494
+ * // Upsert: grant if not owned, or modify if already owned
43495
+ * await visitor.modifyInventoryItemQuantity(inventoryItem, 1);
43464
43496
  * ```
43465
43497
  *
43466
43498
  * @returns {Promise<UserInventoryItem>} Returns the updated inventory item or a response object.
43467
43499
  */
43468
43500
  modifyInventoryItemQuantity(item, quantity) {
43469
- var _a;
43470
43501
  return __awaiter(this, void 0, void 0, function* () {
43471
- // Check for existence in #visitorInventoryItems
43472
- const found = (_a = __classPrivateFieldGet(this, _Visitor_visitorInventoryItems, "f")) === null || _a === void 0 ? void 0 : _a.some((visitorItem) => visitorItem.id === item.userItemId);
43473
- if (!found) {
43474
- throw new Error(`Inventory item with id '${item.userItemId}' does not exist in visitorInventoryItems.`);
43475
- }
43476
43502
  try {
43477
- 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);
43503
+ // Determine if item is a UserInventoryItem (has userItemId) or InventoryItem (only has id)
43504
+ const isUserItem = "userItemId" in item && item.userItemId;
43505
+ const body = isUserItem
43506
+ ? { userItemId: item.userItemId, itemId: item.item_id, quantity }
43507
+ : { itemId: item.id, quantity };
43508
+ const response = yield this.topiaPublicApi().put(`/world/${this.urlSlug}/visitors/${this.id}/update-visitor-inventory-item-quantity`, body, this.requestOptions);
43478
43509
  const userInventoryItemFactory = new UserInventoryItemFactory(this.topia);
43479
43510
  const { inventoryItem, user_id, quantity: newQuantity } = response.data;
43480
43511
  return userInventoryItemFactory.create(inventoryItem, user_id, newQuantity, {
package/package.json CHANGED
@@ -61,5 +61,5 @@
61
61
  "yalc-push": "yarn build && yalc publish --push --dev --no-scripts"
62
62
  },
63
63
  "type": "module",
64
- "version": "0.19.00"
64
+ "version": "0.19.01"
65
65
  }