@rtsdk/topia 0.2.4 → 0.3.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.
Files changed (4) hide show
  1. package/dist/index.cjs +41277 -1177
  2. package/dist/index.d.ts +215 -43
  3. package/dist/index.js +484 -474
  4. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -1,20 +1,3 @@
1
- /**
2
- * BSD 3-Clause License
3
- *
4
- * Copyright (c) 2023, metaversecloud.com | topia.io
5
- * All rights reserved.
6
- *
7
- * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
8
- *
9
- * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
10
- *
11
- * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
12
- *
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
- *
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.
16
- */
17
-
18
1
  import * as axios from 'axios';
19
2
  import { AxiosResponse, AxiosInstance, AxiosError } from 'axios';
20
3
  import jwt from 'jsonwebtoken';
@@ -31,13 +14,13 @@ declare enum DroppedAssetMediaType {
31
14
  }
32
15
 
33
16
  type InteractiveCredentials = {
17
+ apiKey?: string;
34
18
  assetId?: string;
35
19
  interactiveNonce?: string;
36
20
  interactivePublicKey?: string;
37
- visitorId?: number;
38
- urlSlug?: string;
39
- apiKey?: string;
40
21
  profileId?: string | null;
22
+ urlSlug?: string;
23
+ visitorId?: number;
41
24
  };
42
25
 
43
26
  type AssetOptions = {
@@ -56,7 +39,7 @@ type VisitorOptions = {
56
39
  credentials?: InteractiveCredentials | undefined;
57
40
  };
58
41
  type WorldOptions = {
59
- attributes?: WorldInterface | undefined;
42
+ attributes?: WorldDetailsInterface | undefined;
60
43
  credentials?: InteractiveCredentials | undefined;
61
44
  };
62
45
 
@@ -125,8 +108,7 @@ declare class DroppedAsset extends Asset implements DroppedAssetInterface {
125
108
  *
126
109
  * @usage
127
110
  * ```ts
128
- * await droppedAsset.fetchDataObject();
129
- * const { dataObject } = droppedAsset;
111
+ * const dataObject = await droppedAsset.fetchDataObject();
130
112
  * ```
131
113
  */
132
114
  fetchDataObject(): Promise<void | ResponseType>;
@@ -141,7 +123,6 @@ declare class DroppedAsset extends Asset implements DroppedAssetInterface {
141
123
  * await droppedAsset.setDataObject({
142
124
  * "exampleKey": "exampleValue",
143
125
  * });
144
- * const { dataObject } = droppedAsset;
145
126
  * ```
146
127
  */
147
128
  setDataObject(dataObject: object, options?: {
@@ -161,7 +142,6 @@ declare class DroppedAsset extends Asset implements DroppedAssetInterface {
161
142
  * await droppedAsset.updateDataObject({
162
143
  * "exampleKey": "exampleValue",
163
144
  * });
164
- * const { dataObject } = droppedAsset;
165
145
  * ```
166
146
  */
167
147
  updateDataObject(dataObject: object, options?: {
@@ -170,6 +150,26 @@ declare class DroppedAsset extends Asset implements DroppedAssetInterface {
170
150
  releaseLock?: boolean;
171
151
  };
172
152
  }): Promise<void | ResponseType>;
153
+ /**
154
+ * @summary
155
+ * Increments a specific value in the data object for a dropped asset by the amount specified. Must have valid interactive credentials from a visitor in the world.
156
+ *
157
+ * 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
158
+ *
159
+ * @usage
160
+ * ```ts
161
+ * await droppedAsset.incrementDataObjectValue(
162
+ * "path": "key",
163
+ * "amount": 1,
164
+ * );
165
+ * ```
166
+ */
167
+ incrementDataObjectValue(path: string, amount: number, options?: {
168
+ lock?: {
169
+ lockId: string;
170
+ releaseLock?: boolean;
171
+ };
172
+ }): Promise<void | ResponseType>;
173
173
  /**
174
174
  * @summary
175
175
  * Updates broadcast options for a dropped asset.
@@ -372,6 +372,7 @@ declare class DroppedAsset extends Asset implements DroppedAssetInterface {
372
372
  declare class World extends SDKController implements WorldInterface {
373
373
  #private;
374
374
  urlSlug: string;
375
+ dataObject?: object | null | undefined;
375
376
  constructor(topia: Topia, urlSlug: string, options?: WorldOptionalInterface);
376
377
  get droppedAssets(): {
377
378
  [key: string]: DroppedAsset;
@@ -409,7 +410,7 @@ declare class World extends SDKController implements WorldInterface {
409
410
  * });
410
411
  * ```
411
412
  */
412
- updateDetails({ controls, description, forceAuthOnLogin, height, name, spawnPosition, width, }: WorldInterface): Promise<void | ResponseType>;
413
+ updateDetails({ controls, description, forceAuthOnLogin, height, name, spawnPosition, width, }: WorldDetailsInterface): Promise<void | ResponseType>;
413
414
  /**
414
415
  * @summary
415
416
  * Retrieve all assets dropped in a world.
@@ -496,6 +497,77 @@ declare class World extends SDKController implements WorldInterface {
496
497
  * ```
497
498
  */
498
499
  replaceScene(sceneId: string): Promise<void | ResponseType>;
500
+ /**
501
+ * @summary
502
+ * Retrieves the data object for a world. Must have valid interactive credentials from a visitor in the world.
503
+ *
504
+ * @usage
505
+ * ```ts
506
+ * await world.fetchDataObject();
507
+ * const { dataObject } = world;
508
+ * ```
509
+ */
510
+ fetchDataObject: () => Promise<void | ResponseType>;
511
+ /**
512
+ * @summary
513
+ * Sets the data object for a user. Must have valid interactive credentials from a visitor in the world.
514
+ *
515
+ * 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
516
+ *
517
+ * @usage
518
+ * ```ts
519
+ * await world.setDataObject({
520
+ * "exampleKey": "exampleValue",
521
+ * });
522
+ * const { dataObject } = world;
523
+ * ```
524
+ */
525
+ setDataObject: (dataObject: object | null | undefined, options?: {
526
+ lock?: {
527
+ lockId: string;
528
+ releaseLock?: boolean;
529
+ };
530
+ }) => Promise<void | ResponseType>;
531
+ /**
532
+ * @summary
533
+ * Updates the data object for a world. Must have valid interactive credentials from a visitor in the world.
534
+ *
535
+ * 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
536
+ *
537
+ * @usage
538
+ * ```ts
539
+ * await world.updateDataObject({
540
+ * "exampleKey": "exampleValue",
541
+ * });
542
+ * const { dataObject } = world;
543
+ * ```
544
+ */
545
+ updateDataObject: (dataObject: object, options?: {
546
+ lock?: {
547
+ lockId: string;
548
+ releaseLock?: boolean;
549
+ };
550
+ }) => Promise<void | ResponseType>;
551
+ /**
552
+ * @summary
553
+ * Increments a specific value in the data object for a world by the amount specified. Must have valid interactive credentials from a visitor in the world.
554
+ *
555
+ * 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
556
+ *
557
+ * @usage
558
+ * ```ts
559
+ * await world.incrementDataObjectValue(
560
+ * "path": "key",
561
+ * "amount": 1,
562
+ * );
563
+ * ```
564
+ */
565
+ incrementDataObjectValue(path: string, amount: number, options?: {
566
+ lock?: {
567
+ lockId: string;
568
+ releaseLock?: boolean;
569
+ };
570
+ }): Promise<void | ResponseType>;
499
571
  }
500
572
 
501
573
  /**
@@ -507,7 +579,7 @@ declare class World extends SDKController implements WorldInterface {
507
579
  * await new User(topia, { interactiveNonce: "exampleNonce", interactivePublicKey: "examplePublicKey", visitorId: 1 });
508
580
  * ```
509
581
  */
510
- declare class User extends SDKController {
582
+ declare class User extends SDKController implements UserInterface {
511
583
  #private;
512
584
  profileId?: string | null;
513
585
  dataObject?: object | null | undefined;
@@ -556,8 +628,7 @@ declare class User extends SDKController {
556
628
  *
557
629
  * @usage
558
630
  * ```ts
559
- * await droppedAsset.fetchDataObject();
560
- * const { dataObject } = droppedAsset;
631
+ * const dataObject = await user.fetchDataObject();
561
632
  * ```
562
633
  */
563
634
  fetchDataObject(): Promise<void | ResponseType>;
@@ -569,10 +640,9 @@ declare class User extends SDKController {
569
640
  *
570
641
  * @usage
571
642
  * ```ts
572
- * await droppedAsset.setDataObject({
643
+ * await user.setDataObject({
573
644
  * "exampleKey": "exampleValue",
574
645
  * });
575
- * const { dataObject } = droppedAsset;
576
646
  * ```
577
647
  */
578
648
  setDataObject(dataObject: object | null | undefined, options?: {
@@ -589,10 +659,9 @@ declare class User extends SDKController {
589
659
  *
590
660
  * @usage
591
661
  * ```ts
592
- * await droppedAsset.updateUserDataObject({
662
+ * await user.updateUserDataObject({
593
663
  * "exampleKey": "exampleValue",
594
664
  * });
595
- * const { dataObject } = droppedAsset;
596
665
  * ```
597
666
  */
598
667
  updateDataObject(dataObject: object, options?: {
@@ -601,6 +670,26 @@ declare class User extends SDKController {
601
670
  releaseLock?: boolean;
602
671
  };
603
672
  }): Promise<void | ResponseType>;
673
+ /**
674
+ * @summary
675
+ * Increments a specific value in the data object for a user by the amount specified. Must have valid interactive credentials from a visitor in the world.
676
+ *
677
+ * 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
678
+ *
679
+ * @usage
680
+ * ```ts
681
+ * await user.incrementDataObjectValue(
682
+ * "path": "key",
683
+ * "amount": 1,
684
+ * );
685
+ * ```
686
+ */
687
+ incrementDataObjectValue(path: string, amount: number, options?: {
688
+ lock?: {
689
+ lockId: string;
690
+ releaseLock?: boolean;
691
+ };
692
+ }): Promise<void | ResponseType>;
604
693
  }
605
694
 
606
695
  /**
@@ -613,7 +702,6 @@ declare class User extends SDKController {
613
702
  * ```
614
703
  */
615
704
  declare class Visitor extends User implements VisitorInterface {
616
- #private;
617
705
  readonly id: number;
618
706
  urlSlug: string;
619
707
  user?: User;
@@ -682,8 +770,7 @@ declare class Visitor extends User implements VisitorInterface {
682
770
  *
683
771
  * @usage
684
772
  * ```ts
685
- * await droppedAsset.fetchVisitorDataObject();
686
- * const { dataObject } = droppedAsset;
773
+ * const dataObject = await visitor.fetchVisitorDataObject();
687
774
  * ```
688
775
  */
689
776
  fetchDataObject(): Promise<void | ResponseType>;
@@ -695,10 +782,9 @@ declare class Visitor extends User implements VisitorInterface {
695
782
  *
696
783
  * @usage
697
784
  * ```ts
698
- * await droppedAsset.setVisitorDataObject({
785
+ * await visitor.setVisitorDataObject({
699
786
  * "exampleKey": "exampleValue",
700
787
  * });
701
- * const { dataObject } = droppedAsset;
702
788
  * ```
703
789
  */
704
790
  setDataObject(dataObject: object | null | undefined, options?: {
@@ -715,10 +801,9 @@ declare class Visitor extends User implements VisitorInterface {
715
801
  *
716
802
  * @usage
717
803
  * ```ts
718
- * await droppedAsset.updateVisitorDataObject({
804
+ * await visitor.updateVisitorDataObject({
719
805
  * "exampleKey": "exampleValue",
720
806
  * });
721
- * const { dataObject } = droppedAsset;
722
807
  * ```
723
808
  */
724
809
  updateDataObject(dataObject: object, options?: {
@@ -727,6 +812,26 @@ declare class Visitor extends User implements VisitorInterface {
727
812
  releaseLock?: boolean;
728
813
  };
729
814
  }): Promise<void | ResponseType>;
815
+ /**
816
+ * @summary
817
+ * Increments a specific value in the data object for a visitor by the amount specified. Must have valid interactive credentials from a visitor in the world.
818
+ *
819
+ * 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
820
+ *
821
+ * @usage
822
+ * ```ts
823
+ * await visitor.incrementDataObjectValue(
824
+ * "path": "key",
825
+ * "amount": 1,
826
+ * );
827
+ * ```
828
+ */
829
+ incrementDataObjectValue(path: string, amount: number, options?: {
830
+ lock?: {
831
+ lockId: string;
832
+ releaseLock?: boolean;
833
+ };
834
+ }): Promise<void | ResponseType>;
730
835
  }
731
836
 
732
837
  type VisitorType = {
@@ -795,6 +900,35 @@ type AssetOptionalInterface = {
795
900
  };
796
901
 
797
902
  interface DroppedAssetInterface extends AssetInterface {
903
+ fetchDroppedAssetById(): Promise<void | ResponseType>;
904
+ deleteDroppedAsset(): Promise<void | ResponseType>;
905
+ fetchDataObject(): Promise<void | ResponseType>;
906
+ setDataObject(dataObject: object, options: object): Promise<void | ResponseType>;
907
+ updateDataObject(dataObject: object, options: object): Promise<void | ResponseType>;
908
+ incrementDataObjectValue(path: string, amount: number, options: object): Promise<void | ResponseType>;
909
+ updateBroadcast({ assetBroadcast, assetBroadcastAll, broadcasterEmail, }: UpdateBroadcastInterface): Promise<void | ResponseType>;
910
+ updateClickType({ clickType, clickableLink, clickableLinkTitle, clickableDisplayTextDescription, clickableDisplayTextHeadline, isForceLinkInIframe, isOpenLinkInDrawer, portalName, position, }: UpdateClickTypeInterface): Promise<void | ResponseType>;
911
+ updateCustomTextAsset(style: object | undefined | null, text: string | null | undefined): Promise<void | ResponseType>;
912
+ updateMediaType({ audioRadius, audioSliderVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia, }: UpdateMediaTypeInterface): Promise<void | ResponseType>;
913
+ updateMuteZone(isMutezone: boolean): Promise<void | ResponseType>;
914
+ updateWebhookZone(isWebhookZoneEnabled: boolean): Promise<void | ResponseType>;
915
+ updatePosition(x: number, y: number): Promise<void | ResponseType>;
916
+ updatePrivateZone({ isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap, }: UpdatePrivateZoneInterface): Promise<void | ResponseType>;
917
+ updateScale(assetScale: number): Promise<void | ResponseType>;
918
+ updateUploadedMediaSelected(mediaId: string): Promise<void | ResponseType>;
919
+ updateWebImageLayers(bottom: string, top: string): Promise<void | ResponseType>;
920
+ addWebhook({ dataObject, description, isUniqueOnly, title, type, url, }: {
921
+ dataObject: object;
922
+ description: string;
923
+ isUniqueOnly: boolean;
924
+ title: string;
925
+ type: string;
926
+ url: string;
927
+ }): Promise<void | AxiosResponse>;
928
+ setInteractiveSettings({ isInteractive, interactivePublicKey, }: {
929
+ isInteractive?: boolean;
930
+ interactivePublicKey: string;
931
+ }): Promise<void | ResponseType>;
798
932
  id?: string;
799
933
  assetId?: string;
800
934
  assetScale?: number | null;
@@ -898,6 +1032,7 @@ interface UpdatePrivateZoneInterface {
898
1032
  }
899
1033
 
900
1034
  interface SceneInterface {
1035
+ fetchSceneById(): Promise<void | ResponseType>;
901
1036
  id: string;
902
1037
  background?: null;
903
1038
  description?: string;
@@ -933,6 +1068,14 @@ interface TopiaInterface {
933
1068
  interactiveSecret?: jwt.Secret;
934
1069
  }
935
1070
 
1071
+ interface UserInterface {
1072
+ fetchAssets(): Promise<void | ResponseType>;
1073
+ fetchScenes(): Promise<void | ResponseType>;
1074
+ fetchWorldsByKey(): Promise<void | ResponseType>;
1075
+ fetchDataObject(): Promise<void | ResponseType>;
1076
+ setDataObject(dataObject: object | null | undefined, options: object): Promise<void | ResponseType>;
1077
+ incrementDataObjectValue(path: string, amount: number, options: object): Promise<void | ResponseType>;
1078
+ }
936
1079
  interface UserOptionalInterface {
937
1080
  credentials?: InteractiveCredentials | object;
938
1081
  profileId?: string | null;
@@ -941,6 +1084,14 @@ interface UserOptionalInterface {
941
1084
  }
942
1085
 
943
1086
  interface VisitorInterface extends SDKInterface {
1087
+ fetchVisitor(): Promise<void | ResponseType>;
1088
+ moveVisitor({ shouldTeleportVisitor, x, y }: MoveVisitorInterface): Promise<void | ResponseType>;
1089
+ fireToast({ groupId, title, text }: FireToastInterface): Promise<void | ResponseType>;
1090
+ openIframe({ link, shouldOpenInDrawer, title }: OpenIframeInterface): Promise<void | ResponseType>;
1091
+ fetchDataObject(): Promise<void | ResponseType>;
1092
+ setDataObject(dataObject: object | null | undefined, options: object): Promise<void | ResponseType>;
1093
+ updateDataObject(dataObject: object, options: object): Promise<void | ResponseType>;
1094
+ incrementDataObjectValue(path: string, amount: number, options: object): Promise<void | ResponseType>;
944
1095
  color?: string;
945
1096
  dataObject?: object | null | undefined;
946
1097
  displayName?: string;
@@ -998,7 +1149,7 @@ interface MoveAllVisitorsInterface {
998
1149
  y: number;
999
1150
  }
1000
1151
 
1001
- interface WorldInterface extends SDKInterface {
1152
+ interface WorldDetailsInterface {
1002
1153
  background?: string | null;
1003
1154
  controls?: {
1004
1155
  allowMuteAll?: boolean;
@@ -1024,8 +1175,29 @@ interface WorldInterface extends SDKInterface {
1024
1175
  useTopiaPassword?: boolean;
1025
1176
  width?: number;
1026
1177
  }
1178
+ interface WorldInterface extends SDKInterface, WorldDetailsInterface {
1179
+ fetchDetails(): Promise<void | ResponseType>;
1180
+ updateDetails({ controls, description, forceAuthOnLogin, height, name, spawnPosition, width, }: WorldDetailsInterface): Promise<void | ResponseType>;
1181
+ fetchDroppedAssets(): Promise<void | ResponseType>;
1182
+ fetchDroppedAssetsWithUniqueName({ uniqueName, isPartial, isReversed, }: {
1183
+ uniqueName: string;
1184
+ isPartial?: boolean;
1185
+ isReversed?: boolean;
1186
+ }): Promise<DroppedAsset[]>;
1187
+ updateCustomTextDroppedAssets(droppedAssetsToUpdate: Array<DroppedAsset>, style: object): Promise<object>;
1188
+ dropScene({ assetSuffix, position, sceneId, }: {
1189
+ assetSuffix: string;
1190
+ position: object;
1191
+ sceneId: string;
1192
+ }): Promise<void | ResponseType>;
1193
+ replaceScene(sceneId: string): Promise<void | ResponseType>;
1194
+ fetchDataObject(): Promise<void | ResponseType>;
1195
+ setDataObject(dataObject: object | null | undefined, options: object): Promise<void | ResponseType>;
1196
+ updateDataObject(dataObject: object, options: object): Promise<void | ResponseType>;
1197
+ incrementDataObjectValue(path: string, amount: number, options: object): Promise<void | ResponseType>;
1198
+ }
1027
1199
  interface WorldOptionalInterface {
1028
- attributes?: WorldInterface | object;
1200
+ attributes?: WorldDetailsInterface | object;
1029
1201
  credentials?: InteractiveCredentials | object;
1030
1202
  }
1031
1203
 
@@ -1248,4 +1420,4 @@ declare class WorldFactory {
1248
1420
  create(urlSlug: string, options?: WorldOptionalInterface): World;
1249
1421
  }
1250
1422
 
1251
- export { AssetFactory, AssetInterface, AssetOptionalInterface, AssetOptions, DroppedAssetClickType, DroppedAssetFactory, DroppedAssetInterface, DroppedAssetMediaType, DroppedAssetOptionalInterface, DroppedAssetOptions, FireToastInterface, InteractiveCredentials, MoveAllVisitorsInterface, MoveVisitorInterface, OpenIframeInterface, ResponseType, SDKInterface, SceneFactory, SceneInterface, SceneOptionalInterface, Topia, TopiaInterface, UpdateBroadcastInterface, UpdateClickTypeInterface, UpdateMediaTypeInterface, UpdatePrivateZoneInterface, UserFactory, UserOptionalInterface, UserOptions, VisitorFactory, VisitorInterface, VisitorOptionalInterface, VisitorOptions, VisitorType, VisitorsToMoveArrayType, VisitorsToMoveType, WorldActivityFactory, WorldActivityOptionalInterface, WorldFactory, WorldInterface, WorldOptionalInterface, WorldOptions };
1423
+ export { Asset, AssetFactory, AssetInterface, AssetOptionalInterface, AssetOptions, DroppedAsset, DroppedAssetClickType, DroppedAssetFactory, DroppedAssetInterface, DroppedAssetMediaType, DroppedAssetOptionalInterface, DroppedAssetOptions, FireToastInterface, InteractiveCredentials, MoveAllVisitorsInterface, MoveVisitorInterface, OpenIframeInterface, ResponseType, SDKController, SDKInterface, Scene, SceneFactory, SceneInterface, SceneOptionalInterface, Topia, TopiaInterface, UpdateBroadcastInterface, UpdateClickTypeInterface, UpdateMediaTypeInterface, UpdatePrivateZoneInterface, User, UserFactory, UserInterface, UserOptionalInterface, UserOptions, Visitor, VisitorFactory, VisitorInterface, VisitorOptionalInterface, VisitorOptions, VisitorType, VisitorsToMoveArrayType, VisitorsToMoveType, World, WorldActivity, WorldActivityFactory, WorldActivityOptionalInterface, WorldDetailsInterface, WorldFactory, WorldInterface, WorldOptionalInterface, WorldOptions };