@rtsdk/topia 0.0.23 → 0.0.25

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.
Files changed (31) hide show
  1. package/LICENSE.md +1 -2
  2. package/README.md +56 -56
  3. package/dist/example.js +3 -3
  4. package/dist/index.js +358 -231
  5. package/dist/src/__mocks__/scenes.js +1 -1
  6. package/dist/src/controllers/DroppedAsset.js +13 -5
  7. package/dist/src/controllers/SDKController.js +1 -1
  8. package/dist/src/controllers/Scene.js +39 -0
  9. package/dist/src/controllers/Topia.js +2 -2
  10. package/dist/src/controllers/User.js +38 -15
  11. package/dist/src/controllers/Visitor.js +7 -7
  12. package/dist/src/controllers/World.js +52 -145
  13. package/dist/src/controllers/WorldActivity.js +160 -0
  14. package/dist/src/controllers/__tests__/asset.test.js +2 -2
  15. package/dist/src/controllers/__tests__/droppedAsset.test.js +1 -1
  16. package/dist/src/controllers/__tests__/scene.test.js +37 -0
  17. package/dist/src/controllers/__tests__/user.test.js +14 -15
  18. package/dist/src/controllers/__tests__/visitor.test.js +10 -4
  19. package/dist/src/controllers/__tests__/world.test.js +2 -34
  20. package/dist/src/controllers/__tests__/worldActivity.test.js +62 -0
  21. package/dist/src/controllers/index.js +2 -0
  22. package/dist/src/factories/SceneFactory.js +27 -0
  23. package/dist/src/factories/UserFactory.js +2 -2
  24. package/dist/src/factories/VisitorFactory.js +3 -3
  25. package/dist/src/factories/WorldActivityFactory.js +10 -0
  26. package/dist/src/factories/index.js +2 -0
  27. package/dist/src/index.js +1 -1
  28. package/dist/src/interfaces/SceneInterfaces.js +1 -0
  29. package/dist/src/interfaces/WorldActivityInterfaces.js +1 -0
  30. package/dist/src/interfaces/index.js +2 -0
  31. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -12,8 +12,7 @@
12
12
  *
13
13
  * - Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
14
14
  *
15
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
16
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17
16
  */
18
17
 
19
18
  import require$$0$1 from 'buffer';
@@ -39763,7 +39762,7 @@ class SDKController {
39763
39762
  assetId,
39764
39763
  };
39765
39764
  this.jwt = jwt.sign(payload, topia.interactiveSecret);
39766
- headers.Interactivejwt = this.jwt;
39765
+ headers.InteractiveJWT = this.jwt;
39767
39766
  }
39768
39767
  if (apiKey) {
39769
39768
  headers.Authorization = apiKey;
@@ -39869,14 +39868,24 @@ class DroppedAsset extends Asset {
39869
39868
  return __awaiter(this, void 0, void 0, function* () {
39870
39869
  try {
39871
39870
  const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/assets/${this.id}`, this.requestOptions);
39872
- Object.assign(this, response.data);
39871
+ const droppedAssetDetails = response.data;
39872
+ droppedAssetDetails.urlSlug = this.urlSlug;
39873
+ Object.assign(this, droppedAssetDetails);
39873
39874
  }
39874
39875
  catch (error) {
39875
39876
  throw this.errorHandler({ error });
39876
39877
  }
39877
39878
  });
39878
39879
  }
39879
- // delete dropped asset
39880
+ /**
39881
+ * @summary
39882
+ * Delete dropped asset.
39883
+ *
39884
+ * @usage
39885
+ * ```ts
39886
+ * await droppedAsset.deleteDroppedAsset();
39887
+ * ```
39888
+ */
39880
39889
  deleteDroppedAsset() {
39881
39890
  return __awaiter(this, void 0, void 0, function* () {
39882
39891
  try {
@@ -39897,7 +39906,6 @@ class DroppedAsset extends Asset {
39897
39906
  * const { dataObject } = droppedAsset;
39898
39907
  * ```
39899
39908
  */
39900
- // get dropped asset
39901
39909
  fetchDroppedAssetDataObject() {
39902
39910
  return __awaiter(this, void 0, void 0, function* () {
39903
39911
  try {
@@ -39911,7 +39919,7 @@ class DroppedAsset extends Asset {
39911
39919
  }
39912
39920
  /**
39913
39921
  * @summary
39914
- * Setss the data object for a dropped asset.
39922
+ * Sets the data object for a dropped asset.
39915
39923
  *
39916
39924
  * Optionally, a lock can be provided with this request to ensure only one update happens at a time between all updates that share the same lock id
39917
39925
  *
@@ -39923,7 +39931,6 @@ class DroppedAsset extends Asset {
39923
39931
  * const { dataObject } = droppedAsset;
39924
39932
  * ```
39925
39933
  */
39926
- // get dropped asset
39927
39934
  setDroppedAssetDataObject(dataObject, options = {}) {
39928
39935
  return __awaiter(this, void 0, void 0, function* () {
39929
39936
  try {
@@ -40248,74 +40255,24 @@ _DroppedAsset_updateDroppedAsset = new WeakMap();
40248
40255
 
40249
40256
  /**
40250
40257
  * @summary
40251
- * Create an instance of Visitor class with a given id and optional attributes and session credentials.
40258
+ * Create an instance of Scene class with a given scene id and optional attributes and session credentials.
40252
40259
  *
40253
40260
  * @usage
40254
40261
  * ```ts
40255
- * await new Visitor(topia, id, urlSlug, { attributes: { moveTo: { x: 0, y: 0 } } });
40262
+ * await new Scene(topia, "sceneId", { attributes: { name: "My Scene" } });
40256
40263
  * ```
40257
40264
  */
40258
- class Visitor extends SDKController {
40259
- constructor(topia, id, urlSlug, options = { attributes: {}, credentials: {} }) {
40265
+ class Scene extends SDKController {
40266
+ constructor(topia, id, options = { attributes: {}, credentials: {} }) {
40260
40267
  super(topia, options.credentials);
40261
- Object.assign(this, options.attributes);
40262
40268
  this.id = id;
40263
- this.urlSlug = urlSlug;
40264
- }
40265
- /**
40266
- * @summary
40267
- * Get a single visitor from a world
40268
- *
40269
- * @usage
40270
- * ```ts
40271
- * await visitor.fetchVisitor();
40272
- * ```
40273
- *
40274
- * @result
40275
- * Updates each Visitor instance and world.visitors map.
40276
- */
40277
- fetchVisitor() {
40278
- return __awaiter(this, void 0, void 0, function* () {
40279
- try {
40280
- const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/visitors/${this.id}`, this.requestOptions);
40281
- if (response.data.success) {
40282
- Object.assign(this, response.data).players[0];
40283
- }
40284
- else {
40285
- throw "This visitor is not active";
40286
- }
40287
- }
40288
- catch (error) {
40289
- throw this.errorHandler({ error });
40290
- }
40291
- });
40269
+ Object.assign(this, options.attributes);
40292
40270
  }
40293
- /**
40294
- * @summary
40295
- * Teleport or walk a visitor currently in a world to a single set of coordinates.
40296
- *
40297
- * @usage
40298
- * ```ts
40299
- * await visitor.moveVisitor({
40300
- * shouldTeleportVisitor: true,
40301
- * x: 100,
40302
- * y: 100,
40303
- * });
40304
- * ```
40305
- *
40306
- * @result
40307
- * Updates each Visitor instance and world.visitors map.
40308
- */
40309
- moveVisitor({ shouldTeleportVisitor, x, y }) {
40271
+ fetchSceneById() {
40310
40272
  return __awaiter(this, void 0, void 0, function* () {
40311
40273
  try {
40312
- yield this.topiaPublicApi().put(`/world/${this.urlSlug}/visitors/${this.id}/move`, {
40313
- moveTo: {
40314
- x,
40315
- y,
40316
- },
40317
- teleport: shouldTeleportVisitor,
40318
- }, this.requestOptions);
40274
+ const response = yield this.topiaPublicApi().get(`/scenes/${this.id}`, this.requestOptions);
40275
+ Object.assign(this, response.data);
40319
40276
  }
40320
40277
  catch (error) {
40321
40278
  throw this.errorHandler({ error });
@@ -40351,7 +40308,7 @@ const scatterVisitors = (original, scatterBy) => {
40351
40308
  return Math.floor(Math.random() * (max - min) + min);
40352
40309
  };
40353
40310
 
40354
- var _World_droppedAssetsMap, _World_visitorsMap;
40311
+ var _World_droppedAssetsMap;
40355
40312
  /**
40356
40313
  * @summary
40357
40314
  * Create an instance of World class with a given url slug and optional attributes and session credentials.
@@ -40365,18 +40322,14 @@ class World extends SDKController {
40365
40322
  constructor(topia, urlSlug, options = { attributes: {}, credentials: {} }) {
40366
40323
  super(topia, options.credentials);
40367
40324
  _World_droppedAssetsMap.set(this, void 0);
40368
- _World_visitorsMap.set(this, void 0);
40369
40325
  Object.assign(this, options.attributes);
40370
40326
  __classPrivateFieldSet(this, _World_droppedAssetsMap, {}, "f");
40371
- __classPrivateFieldSet(this, _World_visitorsMap, {}, "f");
40372
40327
  this.urlSlug = urlSlug;
40373
40328
  }
40374
40329
  get droppedAssets() {
40375
40330
  return __classPrivateFieldGet(this, _World_droppedAssetsMap, "f");
40376
40331
  }
40377
- get visitors() {
40378
- return __classPrivateFieldGet(this, _World_visitorsMap, "f");
40379
- }
40332
+ //////// world details
40380
40333
  /**
40381
40334
  * @summary
40382
40335
  * Retrieves details of a world.
@@ -40387,7 +40340,6 @@ class World extends SDKController {
40387
40340
  * const { name } = world;
40388
40341
  * ```
40389
40342
  */
40390
- // world details
40391
40343
  fetchDetails() {
40392
40344
  return __awaiter(this, void 0, void 0, function* () {
40393
40345
  try {
@@ -40442,120 +40394,39 @@ class World extends SDKController {
40442
40394
  }
40443
40395
  });
40444
40396
  }
40445
- // visitors
40446
- fetchVisitors() {
40447
- return __awaiter(this, void 0, void 0, function* () {
40448
- try {
40449
- const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/visitors`, this.requestOptions);
40450
- // create temp map and then update private property only once
40451
- const tempVisitorsMap = {};
40452
- for (const id in response.data) {
40453
- tempVisitorsMap[id] = new Visitor(this.topia, response.data[id].playerId, this.urlSlug, {
40454
- attributes: response.data[id],
40455
- });
40456
- }
40457
- __classPrivateFieldSet(this, _World_visitorsMap, tempVisitorsMap, "f");
40458
- }
40459
- catch (error) {
40460
- throw this.errorHandler({ error });
40461
- }
40462
- });
40463
- }
40397
+ ////////// dropped assets
40464
40398
  /**
40465
40399
  * @summary
40466
- * Retrieve all visitors currently in a world.
40400
+ * Retrieve all assets dropped in a world.
40467
40401
  *
40468
40402
  * @usage
40469
40403
  * ```ts
40470
- * const visitors = await world.currentVisitors();
40404
+ * await world.fetchDroppedAssets();
40405
+ * const assets = world.droppedAssets;
40471
40406
  * ```
40472
40407
  */
40473
- currentVisitors() {
40408
+ fetchDroppedAssets() {
40474
40409
  return __awaiter(this, void 0, void 0, function* () {
40475
40410
  try {
40476
- yield this.fetchVisitors();
40477
- return this.visitors;
40411
+ const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/assets`, this.requestOptions);
40412
+ // create temp map and then update private property only once
40413
+ const tempDroppedAssetsMap = {};
40414
+ for (const index in response.data) {
40415
+ // tempDroppedAssetsMap[id] = createDroppedAsset(this.apiKey, response.data[id], this.urlSlug);
40416
+ tempDroppedAssetsMap[index] = new DroppedAsset(this.topia, response.data[index].id, this.urlSlug, {
40417
+ attributes: response.data[index],
40418
+ });
40419
+ }
40420
+ __classPrivateFieldSet(this, _World_droppedAssetsMap, tempDroppedAssetsMap, "f");
40478
40421
  }
40479
40422
  catch (error) {
40480
- return error;
40423
+ throw this.errorHandler({ error });
40481
40424
  }
40482
40425
  });
40483
40426
  }
40484
40427
  /**
40485
40428
  * @summary
40486
- * Move all visitors currently in a world to a single set of coordinates.
40487
- * Optionally refetch visitors, teleport or walk visitors to new location,
40488
- * and scatter visitors by any number so that they don't all move to the exact same location.
40489
- *
40490
- * @usage
40491
- * ```ts
40492
- * await world.moveAllVisitors({
40493
- * shouldFetchVisitors: true,
40494
- * shouldTeleportVisitors: true,
40495
- * scatterVisitorsBy: 40,
40496
- * x: 100,
40497
- * y: 100,
40498
- * });
40499
- * ```
40500
- *
40501
- * @result
40502
- * Updates each Visitor instance and world.visitors map.
40503
- */
40504
- moveAllVisitors({ shouldFetchVisitors = true, shouldTeleportVisitors = true, scatterVisitorsBy = 0, x, y, }) {
40505
- return __awaiter(this, void 0, void 0, function* () {
40506
- if (shouldFetchVisitors)
40507
- yield this.fetchVisitors();
40508
- const allPromises = [];
40509
- if (!this.visitors)
40510
- return;
40511
- const objectKeys = Object.keys(this.visitors);
40512
- objectKeys.forEach((key) => allPromises.push(__classPrivateFieldGet(this, _World_visitorsMap, "f")[key].moveVisitor({
40513
- shouldTeleportVisitor: shouldTeleportVisitors,
40514
- x: scatterVisitors(x, scatterVisitorsBy),
40515
- y: scatterVisitors(y, scatterVisitorsBy),
40516
- })));
40517
- const outcomes = yield Promise.all(allPromises);
40518
- return outcomes;
40519
- });
40520
- }
40521
- /**
40522
- * @summary
40523
- * Teleport or walk a list of visitors currently in a world to various coordinates.
40524
- *
40525
- * @usage
40526
- * ```ts
40527
- * const visitorsToMove = [
40528
- * {
40529
- * visitorObj: world.visitors["1"],
40530
- * shouldTeleportVisitor: true,
40531
- * x: 100,
40532
- * y: 100
40533
- * }, {
40534
- * visitorObj: world.visitors["2"],
40535
- * shouldTeleportVisitor: false,
40536
- * x: 100,
40537
- * y: 100
40538
- * }
40539
- * ];
40540
- * await world.moveVisitors(visitorsToMove);
40541
- * ```
40542
- *
40543
- * @result
40544
- * Updates each Visitor instance and world.visitors map.
40545
- */
40546
- moveVisitors(visitorsToMove) {
40547
- return __awaiter(this, void 0, void 0, function* () {
40548
- const allPromises = [];
40549
- visitorsToMove.forEach((v) => {
40550
- allPromises.push(v.visitorObj.moveVisitor({ shouldTeleportVisitor: v.shouldTeleportVisitor, x: v.x, y: v.y }));
40551
- });
40552
- const outcomes = yield Promise.all(allPromises);
40553
- return outcomes;
40554
- });
40555
- }
40556
- /**
40557
- * @summary
40558
- * Retrieve all assets dropped in a world.
40429
+ * Retrieve all assets dropped in a world matching uniqueName.
40559
40430
  *
40560
40431
  * @usage
40561
40432
  * ```ts
@@ -40563,20 +40434,18 @@ class World extends SDKController {
40563
40434
  * const assets = world.droppedAssets;
40564
40435
  * ```
40565
40436
  */
40566
- // dropped assets
40567
- fetchDroppedAssets() {
40437
+ fetchDroppedAssetsWithUniqueName({ uniqueName, isPartial = false, isReversed = false, }) {
40568
40438
  return __awaiter(this, void 0, void 0, function* () {
40569
40439
  try {
40570
- const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/assets`, this.requestOptions);
40440
+ const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/assets-with-unique-name/${uniqueName}?${isPartial ? `partial=${isPartial}&` : ""}${isReversed ? `reversed=${isReversed}` : ""}`, this.requestOptions);
40571
40441
  // create temp map and then update private property only once
40572
- const tempDroppedAssetsMap = {};
40573
- for (const index in response.data) {
40574
- // tempDroppedAssetsMap[id] = createDroppedAsset(this.apiKey, response.data[id], this.urlSlug);
40575
- tempDroppedAssetsMap[index] = new DroppedAsset(this.topia, response.data[index].id, this.urlSlug, {
40576
- attributes: response.data[index],
40577
- });
40442
+ const droppedAssets = [];
40443
+ for (const asset of response.data.assets) {
40444
+ droppedAssets.push(new DroppedAsset(this.topia, asset.id, this.urlSlug, {
40445
+ attributes: asset,
40446
+ }));
40578
40447
  }
40579
- __classPrivateFieldSet(this, _World_droppedAssetsMap, tempDroppedAssetsMap, "f");
40448
+ return droppedAssets;
40580
40449
  }
40581
40450
  catch (error) {
40582
40451
  throw this.errorHandler({ error });
@@ -40615,26 +40484,24 @@ class World extends SDKController {
40615
40484
  }
40616
40485
  /**
40617
40486
  * @summary
40618
- * Replace the current scene of a world.
40487
+ * Drop a scene in a world.
40619
40488
  *
40620
40489
  * @usage
40621
40490
  * ```ts
40622
- * const droppedAssetsToUpdate = [world.droppedAssets["6"], world.droppedAssets["12"]]
40623
- * const style = {
40624
- * "textColor": "#abc123",
40625
- * "textFontFamily": "Arial",
40626
- * "textSize": 40,
40627
- * "textWeight": "normal",
40628
- * "textWidth": 200
40629
- * }
40630
- * await world.replaceScene(SCENE_ID);
40491
+ * await world.dropScene({
40492
+ * "sceneId": "string",
40493
+ * "position": {
40494
+ * "x": 0,
40495
+ * "y": 0
40496
+ * },
40497
+ * "assetSuffix": "string"
40498
+ * });
40631
40499
  * ```
40632
40500
  */
40633
- // scenes
40634
- replaceScene(sceneId) {
40501
+ dropScene({ assetSuffix, position, sceneId, }) {
40635
40502
  return __awaiter(this, void 0, void 0, function* () {
40636
40503
  try {
40637
- yield this.topiaPublicApi().put(`/world/${this.urlSlug}/change-scene`, { sceneId }, this.requestOptions);
40504
+ yield this.topiaPublicApi().post(`/world/${this.urlSlug}/drop-scene`, { assetSuffix, position, sceneId }, this.requestOptions);
40638
40505
  }
40639
40506
  catch (error) {
40640
40507
  throw this.errorHandler({ error });
@@ -40643,27 +40510,25 @@ class World extends SDKController {
40643
40510
  }
40644
40511
  /**
40645
40512
  * @summary
40646
- * Retrieve all assets dropped in a world matching uniqueName.
40513
+ * Replace the current scene of a world.
40647
40514
  *
40648
40515
  * @usage
40649
40516
  * ```ts
40650
- * await world.fetchDroppedAssets();
40651
- * const assets = world.droppedAssets;
40517
+ * const droppedAssetsToUpdate = [world.droppedAssets["6"], world.droppedAssets["12"]]
40518
+ * const style = {
40519
+ * "textColor": "#abc123",
40520
+ * "textFontFamily": "Arial",
40521
+ * "textSize": 40,
40522
+ * "textWeight": "normal",
40523
+ * "textWidth": 200
40524
+ * }
40525
+ * await world.replaceScene(SCENE_ID);
40652
40526
  * ```
40653
40527
  */
40654
- // dropped assets
40655
- fetchDroppedAssetsWithUniqueName({ uniqueName, isPartial = false, isReversed = false, }) {
40528
+ replaceScene(sceneId) {
40656
40529
  return __awaiter(this, void 0, void 0, function* () {
40657
40530
  try {
40658
- const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/assets-with-unique-name/${uniqueName}?${isPartial ? `partial=${isPartial}&` : ""}${isReversed ? `reversed=${isReversed}` : ""}`, this.requestOptions);
40659
- // create temp map and then update private property only once
40660
- const droppedAssets = [];
40661
- for (const asset of response.data.assets) {
40662
- droppedAssets.push(new DroppedAsset(this.topia, asset.id, this.urlSlug, {
40663
- attributes: asset,
40664
- }));
40665
- }
40666
- return droppedAssets;
40531
+ yield this.topiaPublicApi().put(`/world/${this.urlSlug}/change-scene`, { sceneId }, this.requestOptions);
40667
40532
  }
40668
40533
  catch (error) {
40669
40534
  throw this.errorHandler({ error });
@@ -40671,24 +40536,33 @@ class World extends SDKController {
40671
40536
  });
40672
40537
  }
40673
40538
  }
40674
- _World_droppedAssetsMap = new WeakMap(), _World_visitorsMap = new WeakMap();
40539
+ _World_droppedAssetsMap = new WeakMap();
40675
40540
 
40676
- var _User_worldsMap;
40541
+ var _User_assetsMap, _User_scenesMap, _User_worldsMap;
40677
40542
  /**
40678
40543
  * @summary
40679
- * Create an instance of User class with email and optional session credentials.
40544
+ * Create an instance of User class with optional session credentials.
40680
40545
  *
40681
40546
  * @usage
40682
40547
  * ```ts
40683
- * await new User(topia, "example@email.io", { interactiveNonce: "exampleNonce", interactivePublicKey: "examplePublicKey", playerId: 1 });
40548
+ * await new User(topia, { interactiveNonce: "exampleNonce", interactivePublicKey: "examplePublicKey", playerId: 1 });
40684
40549
  * ```
40685
40550
  */
40686
40551
  class User extends SDKController {
40687
- constructor(topia, email, options = { credentials: {} }) {
40552
+ constructor(topia, options = { credentials: {} }) {
40688
40553
  super(topia, options.credentials);
40554
+ _User_assetsMap.set(this, void 0);
40555
+ _User_scenesMap.set(this, void 0);
40689
40556
  _User_worldsMap.set(this, void 0);
40557
+ __classPrivateFieldSet(this, _User_assetsMap, {}, "f");
40558
+ __classPrivateFieldSet(this, _User_scenesMap, {}, "f");
40690
40559
  __classPrivateFieldSet(this, _User_worldsMap, {}, "f");
40691
- this.email = email;
40560
+ }
40561
+ get assets() {
40562
+ return __classPrivateFieldGet(this, _User_assetsMap, "f");
40563
+ }
40564
+ get scenes() {
40565
+ return __classPrivateFieldGet(this, _User_scenesMap, "f");
40692
40566
  }
40693
40567
  get worlds() {
40694
40568
  return __classPrivateFieldGet(this, _User_worldsMap, "f");
@@ -40697,11 +40571,18 @@ class User extends SDKController {
40697
40571
  * @summary
40698
40572
  * Returns all assets owned by User when an email address is provided.
40699
40573
  */
40700
- fetchAssetsByEmail(ownerEmail) {
40574
+ fetchAssets() {
40701
40575
  return __awaiter(this, void 0, void 0, function* () {
40702
40576
  try {
40703
- const response = yield this.topiaPublicApi().get(`/assets/my-assets?email=${ownerEmail}`, this.requestOptions);
40704
- return response.data;
40577
+ const response = yield this.topiaPublicApi().get(`/assets/my-assets`, this.requestOptions);
40578
+ const tempAssetsMap = {};
40579
+ for (const i in response.data) {
40580
+ const assetDetails = response.data[i];
40581
+ tempAssetsMap[assetDetails.id] = new Asset(this.topia, assetDetails.id, {
40582
+ attributes: assetDetails,
40583
+ });
40584
+ }
40585
+ __classPrivateFieldSet(this, _User_assetsMap, tempAssetsMap, "f");
40705
40586
  }
40706
40587
  catch (error) {
40707
40588
  throw this.errorHandler({ error });
@@ -40710,15 +40591,20 @@ class User extends SDKController {
40710
40591
  }
40711
40592
  /**
40712
40593
  * @summary
40713
- * Returns all scenes owned by User when an email address is provided.
40594
+ * Returns all scenes owned by User
40714
40595
  */
40715
- fetchScenesByEmail() {
40596
+ fetchScenes() {
40716
40597
  return __awaiter(this, void 0, void 0, function* () {
40717
40598
  try {
40718
- if (!this.email)
40719
- throw this.errorHandler({ error: new Error("There is no email associated with this user.") }); // throw a new Error so the stack trace goes to errorHandler
40720
- const response = yield this.topiaPublicApi().get(`/scenes/my-scenes?email=${this.email}`, this.requestOptions);
40721
- return response.data;
40599
+ const response = yield this.topiaPublicApi().get("/scenes/my-scenes", this.requestOptions);
40600
+ const tempScenesMap = {};
40601
+ for (const i in response.data) {
40602
+ const sceneDetails = response.data[i];
40603
+ tempScenesMap[sceneDetails.id] = new Scene(this.topia, sceneDetails.urlSlug, {
40604
+ attributes: sceneDetails,
40605
+ });
40606
+ }
40607
+ __classPrivateFieldSet(this, _User_scenesMap, tempScenesMap, "f");
40722
40608
  }
40723
40609
  catch (error) {
40724
40610
  throw this.errorHandler({ error });
@@ -40761,7 +40647,222 @@ class User extends SDKController {
40761
40647
  });
40762
40648
  }
40763
40649
  }
40764
- _User_worldsMap = new WeakMap();
40650
+ _User_assetsMap = new WeakMap(), _User_scenesMap = new WeakMap(), _User_worldsMap = new WeakMap();
40651
+
40652
+ /**
40653
+ * @summary
40654
+ * Create an instance of Visitor class with a given id and optional attributes and session credentials.
40655
+ *
40656
+ * @usage
40657
+ * ```ts
40658
+ * await new Visitor(topia, id, urlSlug, { attributes: { moveTo: { x: 0, y: 0 } } });
40659
+ * ```
40660
+ */
40661
+ class Visitor extends User {
40662
+ constructor(topia, id, urlSlug, options = { attributes: {}, credentials: {} }) {
40663
+ super(topia, { credentials: options.credentials });
40664
+ Object.assign(this, options.attributes);
40665
+ this.id = id;
40666
+ this.urlSlug = urlSlug;
40667
+ }
40668
+ /**
40669
+ * @summary
40670
+ * Get a single visitor from a world
40671
+ *
40672
+ * @usage
40673
+ * ```ts
40674
+ * await visitor.fetchVisitor();
40675
+ * ```
40676
+ *
40677
+ * @result
40678
+ * Returns details for a visitor in a world by id and urlSlug
40679
+ */
40680
+ fetchVisitor() {
40681
+ var _a;
40682
+ return __awaiter(this, void 0, void 0, function* () {
40683
+ try {
40684
+ const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/visitors/${this.id}`, this.requestOptions);
40685
+ if (((_a = response.data) === null || _a === void 0 ? void 0 : _a.playerId) === this.id) {
40686
+ Object.assign(this, response.data);
40687
+ }
40688
+ else {
40689
+ throw "This visitor is not active";
40690
+ }
40691
+ }
40692
+ catch (error) {
40693
+ throw this.errorHandler({ error });
40694
+ }
40695
+ });
40696
+ }
40697
+ /**
40698
+ * @summary
40699
+ * Teleport or walk a visitor currently in a world to a single set of coordinates.
40700
+ *
40701
+ * @usage
40702
+ * ```ts
40703
+ * await visitor.moveVisitor({
40704
+ * shouldTeleportVisitor: true,
40705
+ * x: 100,
40706
+ * y: 100,
40707
+ * });
40708
+ * ```
40709
+ *
40710
+ * @result
40711
+ * Updates each Visitor instance and world.visitors map.
40712
+ */
40713
+ moveVisitor({ shouldTeleportVisitor, x, y }) {
40714
+ return __awaiter(this, void 0, void 0, function* () {
40715
+ try {
40716
+ yield this.topiaPublicApi().put(`/world/${this.urlSlug}/visitors/${this.id}/move`, {
40717
+ moveTo: {
40718
+ x,
40719
+ y,
40720
+ },
40721
+ teleport: shouldTeleportVisitor,
40722
+ }, this.requestOptions);
40723
+ }
40724
+ catch (error) {
40725
+ throw this.errorHandler({ error });
40726
+ }
40727
+ });
40728
+ }
40729
+ }
40730
+
40731
+ var _WorldActivity_visitorsMap;
40732
+ /**
40733
+ * @summary
40734
+ * Create an instance of WorldActivity class with a given url slug and optional attributes and session credentials.
40735
+ *
40736
+ * This class is responsible for all activity of a specified world including editing dropped assets, moving current visitors, etc.
40737
+ *
40738
+ * @usage
40739
+ * ```ts
40740
+ * await new WorldActivity(topia, "exampleWorld", { attributes: { name: "Example World" } });
40741
+ * ```
40742
+ */
40743
+ class WorldActivity extends SDKController {
40744
+ constructor(topia, urlSlug, options = { credentials: {} }) {
40745
+ super(topia, options.credentials);
40746
+ _WorldActivity_visitorsMap.set(this, void 0);
40747
+ __classPrivateFieldSet(this, _WorldActivity_visitorsMap, {}, "f");
40748
+ this.urlSlug = urlSlug;
40749
+ }
40750
+ get visitors() {
40751
+ return __classPrivateFieldGet(this, _WorldActivity_visitorsMap, "f");
40752
+ }
40753
+ //////// visitors
40754
+ fetchVisitors() {
40755
+ return __awaiter(this, void 0, void 0, function* () {
40756
+ try {
40757
+ const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/visitors`, this.requestOptions);
40758
+ // create temp map and then update private property only once
40759
+ const tempVisitorsMap = {};
40760
+ for (const id in response.data) {
40761
+ tempVisitorsMap[id] = new Visitor(this.topia, response.data[id].playerId, this.urlSlug, {
40762
+ attributes: response.data[id],
40763
+ });
40764
+ }
40765
+ __classPrivateFieldSet(this, _WorldActivity_visitorsMap, tempVisitorsMap, "f");
40766
+ }
40767
+ catch (error) {
40768
+ throw this.errorHandler({ error });
40769
+ }
40770
+ });
40771
+ }
40772
+ /**
40773
+ * @summary
40774
+ * Retrieve all visitors currently in a world.
40775
+ *
40776
+ * @usage
40777
+ * ```ts
40778
+ * const visitors = await world.currentVisitors();
40779
+ * ```
40780
+ */
40781
+ currentVisitors() {
40782
+ return __awaiter(this, void 0, void 0, function* () {
40783
+ try {
40784
+ yield this.fetchVisitors();
40785
+ return this.visitors;
40786
+ }
40787
+ catch (error) {
40788
+ return error;
40789
+ }
40790
+ });
40791
+ }
40792
+ /**
40793
+ * @summary
40794
+ * Move all visitors currently in a world to a single set of coordinates.
40795
+ * Optionally refetch visitors, teleport or walk visitors to new location,
40796
+ * and scatter visitors by any number so that they don't all move to the exact same location.
40797
+ *
40798
+ * @usage
40799
+ * ```ts
40800
+ * await world.moveAllVisitors({
40801
+ * shouldFetchVisitors: true,
40802
+ * shouldTeleportVisitors: true,
40803
+ * scatterVisitorsBy: 40,
40804
+ * x: 100,
40805
+ * y: 100,
40806
+ * });
40807
+ * ```
40808
+ *
40809
+ * @result
40810
+ * Updates each Visitor instance and world.visitors map.
40811
+ */
40812
+ moveAllVisitors({ shouldFetchVisitors = true, shouldTeleportVisitors = true, scatterVisitorsBy = 0, x, y, }) {
40813
+ return __awaiter(this, void 0, void 0, function* () {
40814
+ if (shouldFetchVisitors)
40815
+ yield this.fetchVisitors();
40816
+ const allPromises = [];
40817
+ if (!this.visitors)
40818
+ return;
40819
+ const objectKeys = Object.keys(this.visitors);
40820
+ objectKeys.forEach((key) => allPromises.push(__classPrivateFieldGet(this, _WorldActivity_visitorsMap, "f")[key].moveVisitor({
40821
+ shouldTeleportVisitor: shouldTeleportVisitors,
40822
+ x: scatterVisitors(x, scatterVisitorsBy),
40823
+ y: scatterVisitors(y, scatterVisitorsBy),
40824
+ })));
40825
+ const outcomes = yield Promise.all(allPromises);
40826
+ return outcomes;
40827
+ });
40828
+ }
40829
+ /**
40830
+ * @summary
40831
+ * Teleport or walk a list of visitors currently in a world to various coordinates.
40832
+ *
40833
+ * @usage
40834
+ * ```ts
40835
+ * const visitorsToMove = [
40836
+ * {
40837
+ * visitorObj: world.visitors["1"],
40838
+ * shouldTeleportVisitor: true,
40839
+ * x: 100,
40840
+ * y: 100
40841
+ * }, {
40842
+ * visitorObj: world.visitors["2"],
40843
+ * shouldTeleportVisitor: false,
40844
+ * x: 100,
40845
+ * y: 100
40846
+ * }
40847
+ * ];
40848
+ * await world.moveVisitors(visitorsToMove);
40849
+ * ```
40850
+ *
40851
+ * @result
40852
+ * Updates each Visitor instance and world.visitors map.
40853
+ */
40854
+ moveVisitors(visitorsToMove) {
40855
+ return __awaiter(this, void 0, void 0, function* () {
40856
+ const allPromises = [];
40857
+ visitorsToMove.forEach((v) => {
40858
+ allPromises.push(v.visitorObj.moveVisitor({ shouldTeleportVisitor: v.shouldTeleportVisitor, x: v.x, y: v.y }));
40859
+ });
40860
+ const outcomes = yield Promise.all(allPromises);
40861
+ return outcomes;
40862
+ });
40863
+ }
40864
+ }
40865
+ _WorldActivity_visitorsMap = new WeakMap();
40765
40866
 
40766
40867
  /**
40767
40868
  * @summary
@@ -40790,9 +40891,9 @@ class Topia {
40790
40891
  if (apiKey)
40791
40892
  headers.Authorization = apiKey;
40792
40893
  if (interactiveKey)
40793
- headers.Publickey = interactiveKey;
40894
+ headers.PublicKey = interactiveKey;
40794
40895
  this.axios = axios.create({
40795
- baseURL: `https://${this.apiDomain}/api`,
40896
+ baseURL: `https://${this.apiDomain}/api/v1`,
40796
40897
  headers,
40797
40898
  });
40798
40899
  }
@@ -40840,12 +40941,29 @@ class DroppedAssetFactory extends SDKController {
40840
40941
  }
40841
40942
  }
40842
40943
 
40944
+ class SceneFactory {
40945
+ constructor(topia) {
40946
+ this.topia = topia;
40947
+ this.create;
40948
+ }
40949
+ create(id, options) {
40950
+ return new Scene(this.topia, id, options);
40951
+ }
40952
+ get(id, options) {
40953
+ return __awaiter(this, void 0, void 0, function* () {
40954
+ const scene = yield new Scene(this.topia, id, options);
40955
+ yield scene.fetchSceneById();
40956
+ return scene;
40957
+ });
40958
+ }
40959
+ }
40960
+
40843
40961
  class UserFactory {
40844
40962
  constructor(topia) {
40845
40963
  this.topia = topia;
40846
40964
  }
40847
- create(email, options) {
40848
- return new User(this.topia, email, options);
40965
+ create(options) {
40966
+ return new User(this.topia, options);
40849
40967
  }
40850
40968
  }
40851
40969
 
@@ -40853,6 +40971,9 @@ class VisitorFactory {
40853
40971
  constructor(topia) {
40854
40972
  this.topia = topia;
40855
40973
  }
40974
+ create(id, urlSlug, options) {
40975
+ return new Visitor(this.topia, id, urlSlug, options);
40976
+ }
40856
40977
  get(id, urlSlug, options) {
40857
40978
  return __awaiter(this, void 0, void 0, function* () {
40858
40979
  const visitor = new Visitor(this.topia, id, urlSlug, options);
@@ -40860,8 +40981,14 @@ class VisitorFactory {
40860
40981
  return visitor;
40861
40982
  });
40862
40983
  }
40863
- create(id, urlSlug, options) {
40864
- return new Visitor(this.topia, id, urlSlug, options);
40984
+ }
40985
+
40986
+ class WorldActivityFactory {
40987
+ constructor(topia) {
40988
+ this.topia = topia;
40989
+ }
40990
+ create(urlSlug, options) {
40991
+ return new WorldActivity(this.topia, urlSlug, options);
40865
40992
  }
40866
40993
  }
40867
40994
 
@@ -40896,4 +41023,4 @@ process.on("uncaughtException", function (err) {
40896
41023
  process.exit(1);
40897
41024
  });
40898
41025
 
40899
- export { AssetFactory, DroppedAssetFactory, Topia, UserFactory, VisitorFactory, WorldFactory };
41026
+ export { AssetFactory, DroppedAssetFactory, SceneFactory, Topia, UserFactory, VisitorFactory, WorldActivityFactory, WorldFactory };