@rtsdk/topia 0.0.31 → 0.1.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 (101) hide show
  1. package/dist/index.cjs +43 -13
  2. package/dist/index.js +43 -13
  3. package/dist/types/example.d.ts +6 -0
  4. package/dist/types/src/__mocks__/assets.d.ts +99 -0
  5. package/dist/{src/__mocks__/index.js → types/src/__mocks__/index.d.ts} +4 -4
  6. package/dist/types/src/__mocks__/scenes.d.ts +79 -0
  7. package/dist/types/src/__mocks__/visitors.d.ts +83 -0
  8. package/dist/types/src/__mocks__/worlds.d.ts +73 -0
  9. package/dist/types/src/controllers/Asset.d.ts +20 -0
  10. package/dist/types/src/controllers/DroppedAsset.d.ts +285 -0
  11. package/dist/types/src/controllers/SDKController.d.ts +48 -0
  12. package/dist/types/src/controllers/Scene.d.ts +19 -0
  13. package/dist/types/src/controllers/Topia.d.ts +33 -0
  14. package/dist/types/src/controllers/User.d.ts +58 -0
  15. package/dist/types/src/controllers/Visitor.d.ts +50 -0
  16. package/dist/types/src/controllers/World.d.ts +143 -0
  17. package/dist/types/src/controllers/WorldActivity.d.ts +83 -0
  18. package/dist/{src/interfaces/AssetInterfaces.js → types/src/controllers/__tests__/asset.test.d.ts} +1 -1
  19. package/dist/{src/interfaces/DroppedAssetInterfaces.js → types/src/controllers/__tests__/droppedAsset.test.d.ts} +1 -1
  20. package/dist/{src/interfaces/SDKInterfaces.js → types/src/controllers/__tests__/scene.test.d.ts} +1 -1
  21. package/dist/{src/interfaces/SceneInterfaces.js → types/src/controllers/__tests__/user.test.d.ts} +1 -1
  22. package/dist/types/src/controllers/__tests__/visitor.test.d.ts +1 -0
  23. package/dist/types/src/controllers/__tests__/world.test.d.ts +1 -0
  24. package/dist/types/src/controllers/__tests__/worldActivity.test.d.ts +1 -0
  25. package/dist/{src/controllers/index.js → types/src/controllers/index.d.ts} +9 -9
  26. package/dist/types/src/factories/AssetFactory.d.ts +8 -0
  27. package/dist/types/src/factories/DroppedAssetFactory.d.ts +16 -0
  28. package/dist/types/src/factories/SceneFactory.d.ts +9 -0
  29. package/dist/types/src/factories/UserFactory.d.ts +8 -0
  30. package/dist/types/src/factories/VisitorFactory.d.ts +9 -0
  31. package/dist/types/src/factories/WorldActivityFactory.d.ts +8 -0
  32. package/dist/types/src/factories/WorldFactory.d.ts +8 -0
  33. package/dist/{src/factories/index.js → types/src/factories/index.d.ts} +7 -7
  34. package/dist/types/src/index.d.ts +4 -0
  35. package/dist/types/src/interfaces/AssetInterfaces.d.ts +26 -0
  36. package/dist/types/src/interfaces/DroppedAssetInterfaces.d.ts +102 -0
  37. package/dist/types/src/interfaces/SDKInterfaces.d.ts +8 -0
  38. package/dist/types/src/interfaces/SceneInterfaces.d.ts +27 -0
  39. package/dist/types/src/interfaces/TopiaInterfaces.d.ts +10 -0
  40. package/dist/types/src/interfaces/UserInterfaces.d.ts +6 -0
  41. package/dist/types/src/interfaces/VisitorInterfaces.d.ts +37 -0
  42. package/dist/types/src/interfaces/WorldActivityInterfaces.d.ts +11 -0
  43. package/dist/types/src/interfaces/WorldInterfaces.d.ts +32 -0
  44. package/dist/{src/interfaces/index.js → types/src/interfaces/index.d.ts} +9 -9
  45. package/dist/types/src/types/DroppedAssetTypes.d.ts +10 -0
  46. package/dist/types/src/types/InteractiveCredentialsTypes.d.ts +8 -0
  47. package/dist/types/src/types/OptionsTypes.d.ts +21 -0
  48. package/dist/types/src/types/ResponseTypes.d.ts +4 -0
  49. package/dist/types/src/types/VisitorTypes.d.ts +33 -0
  50. package/dist/{src/types/index.js → types/src/types/index.d.ts} +5 -4
  51. package/dist/types/src/utils/__tests__/removeUndefined.test.d.ts +1 -0
  52. package/dist/types/src/utils/__tests__/scatterVisitors.test.d.ts +1 -0
  53. package/dist/types/src/utils/getBrowserWarning.d.ts +1 -0
  54. package/dist/{src/utils/index.js → types/src/utils/index.d.ts} +3 -3
  55. package/dist/types/src/utils/removeUndefined.d.ts +8 -0
  56. package/dist/types/src/utils/scatterVisitors.d.ts +4 -0
  57. package/package.json +3 -2
  58. package/dist/example.js +0 -32
  59. package/dist/src/__mocks__/assets.js +0 -249
  60. package/dist/src/__mocks__/scenes.js +0 -104
  61. package/dist/src/__mocks__/visitors.js +0 -83
  62. package/dist/src/__mocks__/worlds.js +0 -52
  63. package/dist/src/controllers/Asset.js +0 -39
  64. package/dist/src/controllers/DroppedAsset.js +0 -443
  65. package/dist/src/controllers/SDKController.js +0 -76
  66. package/dist/src/controllers/Scene.js +0 -39
  67. package/dist/src/controllers/Topia.js +0 -39
  68. package/dist/src/controllers/User.js +0 -139
  69. package/dist/src/controllers/Visitor.js +0 -92
  70. package/dist/src/controllers/World.js +0 -257
  71. package/dist/src/controllers/WorldActivity.js +0 -162
  72. package/dist/src/controllers/__tests__/asset.test.js +0 -37
  73. package/dist/src/controllers/__tests__/droppedAsset.test.js +0 -98
  74. package/dist/src/controllers/__tests__/scene.test.js +0 -38
  75. package/dist/src/controllers/__tests__/user.test.js +0 -49
  76. package/dist/src/controllers/__tests__/visitor.test.js +0 -47
  77. package/dist/src/controllers/__tests__/world.test.js +0 -51
  78. package/dist/src/controllers/__tests__/worldActivity.test.js +0 -63
  79. package/dist/src/factories/AssetFactory.js +0 -11
  80. package/dist/src/factories/DroppedAssetFactory.js +0 -42
  81. package/dist/src/factories/SceneFactory.js +0 -27
  82. package/dist/src/factories/UserFactory.js +0 -10
  83. package/dist/src/factories/VisitorFactory.js +0 -26
  84. package/dist/src/factories/WorldActivityFactory.js +0 -10
  85. package/dist/src/factories/WorldFactory.js +0 -10
  86. package/dist/src/index.js +0 -23
  87. package/dist/src/interfaces/TopiaInterfaces.js +0 -1
  88. package/dist/src/interfaces/UserInterfaces.js +0 -1
  89. package/dist/src/interfaces/VisitorInterfaces.js +0 -1
  90. package/dist/src/interfaces/WorldActivityInterfaces.js +0 -1
  91. package/dist/src/interfaces/WorldInterfaces.js +0 -1
  92. package/dist/src/types/DroppedAssetTypes.js +0 -12
  93. package/dist/src/types/InteractiveCredentialsTypes.js +0 -1
  94. package/dist/src/types/OptionsTypes.js +0 -1
  95. package/dist/src/types/ResponseTypes.js +0 -1
  96. package/dist/src/types/VisitorTypes.js +0 -1
  97. package/dist/src/utils/__tests__/removeUndefined.test.js +0 -10
  98. package/dist/src/utils/__tests__/scatterVisitors.test.js +0 -11
  99. package/dist/src/utils/getBrowserWarning.js +0 -5
  100. package/dist/src/utils/removeUndefined.js +0 -11
  101. package/dist/src/utils/scatterVisitors.js +0 -8
@@ -1,139 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
11
- if (kind === "m") throw new TypeError("Private method is not writable");
12
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
13
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
14
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
15
- };
16
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
17
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
18
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
19
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
- };
21
- var _User_assetsMap, _User_scenesMap, _User_worldsMap;
22
- // controllers
23
- import { Asset } from "controllers/Asset";
24
- import { Scene } from "controllers/Scene";
25
- import { SDKController } from "controllers/SDKController";
26
- import { World } from "controllers/World";
27
- /**
28
- * @summary
29
- * Create an instance of User class with optional session credentials.
30
- *
31
- * @usage
32
- * ```ts
33
- * await new User(topia, { interactiveNonce: "exampleNonce", interactivePublicKey: "examplePublicKey", visitorId: 1 });
34
- * ```
35
- */
36
- export class User extends SDKController {
37
- constructor(topia, options = { credentials: {} }) {
38
- super(topia, options.credentials);
39
- _User_assetsMap.set(this, void 0);
40
- _User_scenesMap.set(this, void 0);
41
- _User_worldsMap.set(this, void 0);
42
- __classPrivateFieldSet(this, _User_assetsMap, {}, "f");
43
- __classPrivateFieldSet(this, _User_scenesMap, {}, "f");
44
- __classPrivateFieldSet(this, _User_worldsMap, {}, "f");
45
- }
46
- get assets() {
47
- return __classPrivateFieldGet(this, _User_assetsMap, "f");
48
- }
49
- get scenes() {
50
- return __classPrivateFieldGet(this, _User_scenesMap, "f");
51
- }
52
- get worlds() {
53
- return __classPrivateFieldGet(this, _User_worldsMap, "f");
54
- }
55
- /**
56
- * @summary
57
- * Returns all assets owned by User when an email address is provided.
58
- */
59
- fetchAssets() {
60
- return __awaiter(this, void 0, void 0, function* () {
61
- try {
62
- const response = yield this.topiaPublicApi().get(`/assets/my-assets`, this.requestOptions);
63
- const tempAssetsMap = {};
64
- for (const i in response.data) {
65
- const assetDetails = response.data[i];
66
- tempAssetsMap[assetDetails.id] = new Asset(this.topia, assetDetails.id, {
67
- attributes: assetDetails,
68
- credentials: this.credentials,
69
- });
70
- }
71
- __classPrivateFieldSet(this, _User_assetsMap, tempAssetsMap, "f");
72
- }
73
- catch (error) {
74
- throw this.errorHandler({ error });
75
- }
76
- });
77
- }
78
- /**
79
- * @summary
80
- * Returns all scenes owned by User
81
- */
82
- fetchScenes() {
83
- return __awaiter(this, void 0, void 0, function* () {
84
- try {
85
- const response = yield this.topiaPublicApi().get("/scenes/my-scenes", this.requestOptions);
86
- const tempScenesMap = {};
87
- for (const i in response.data) {
88
- const sceneDetails = response.data[i];
89
- tempScenesMap[sceneDetails.id] = new Scene(this.topia, sceneDetails.urlSlug, {
90
- attributes: sceneDetails,
91
- credentials: this.credentials,
92
- });
93
- }
94
- __classPrivateFieldSet(this, _User_scenesMap, tempScenesMap, "f");
95
- }
96
- catch (error) {
97
- throw this.errorHandler({ error });
98
- }
99
- });
100
- }
101
- /**
102
- * @summary
103
- * Retrieves all worlds owned by user with matching API Key,
104
- * creates a new World object for each,
105
- * and creates new map of Worlds accessible via user.worlds.
106
- *
107
- * @usage
108
- * ```ts
109
- * await user.fetchWorldsByKey();
110
- * const userWorlds = user.worlds;
111
- * ```
112
- *
113
- * @result
114
- * ```ts
115
- * { urlSlug: new World({ apiKey, worldArgs, urlSlug }) }
116
- * ```
117
- */
118
- fetchWorldsByKey() {
119
- return __awaiter(this, void 0, void 0, function* () {
120
- try {
121
- const response = yield this.topiaPublicApi().get("/user/worlds", this.requestOptions);
122
- const tempWorldsMap = {};
123
- for (const i in response.data) {
124
- const worldDetails = response.data[i];
125
- tempWorldsMap[worldDetails.urlSlug] = new World(this.topia, worldDetails.urlSlug, {
126
- attributes: worldDetails,
127
- credentials: this.credentials,
128
- });
129
- }
130
- __classPrivateFieldSet(this, _User_worldsMap, tempWorldsMap, "f");
131
- }
132
- catch (error) {
133
- throw this.errorHandler({ error });
134
- }
135
- });
136
- }
137
- }
138
- _User_assetsMap = new WeakMap(), _User_scenesMap = new WeakMap(), _User_worldsMap = new WeakMap();
139
- export default User;
@@ -1,92 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { User } from "controllers/User";
11
- /**
12
- * @summary
13
- * Create an instance of Visitor class with a given id and optional attributes and session credentials.
14
- *
15
- * @usage
16
- * ```ts
17
- * await new Visitor(topia, id, urlSlug, { attributes: { moveTo: { x: 0, y: 0 } } });
18
- * ```
19
- */
20
- export class Visitor extends User {
21
- constructor(topia, id, urlSlug, options = { attributes: {}, credentials: {} }) {
22
- super(topia, { credentials: options.credentials });
23
- Object.assign(this, options.attributes);
24
- this.id = id;
25
- this.urlSlug = urlSlug;
26
- }
27
- /**
28
- * @summary
29
- * Get a single visitor from a world
30
- *
31
- * @usage
32
- * ```ts
33
- * await visitor.fetchVisitor();
34
- * ```
35
- *
36
- * @result
37
- * Returns details for a visitor in a world by id and urlSlug
38
- */
39
- fetchVisitor() {
40
- var _a;
41
- return __awaiter(this, void 0, void 0, function* () {
42
- try {
43
- const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/visitors/${this.id}`, this.requestOptions);
44
- if (((_a = response.data) === null || _a === void 0 ? void 0 : _a.visitorId) === this.id) {
45
- Object.assign(this, response.data);
46
- }
47
- else if (response.data[this.id]) {
48
- Object.assign(this, response.data[this.id]);
49
- }
50
- else {
51
- throw "This visitor is not active";
52
- }
53
- }
54
- catch (error) {
55
- throw this.errorHandler({ error });
56
- }
57
- });
58
- }
59
- /**
60
- * @summary
61
- * Teleport or walk a visitor currently in a world to a single set of coordinates.
62
- *
63
- * @usage
64
- * ```ts
65
- * await visitor.moveVisitor({
66
- * shouldTeleportVisitor: true,
67
- * x: 100,
68
- * y: 100,
69
- * });
70
- * ```
71
- *
72
- * @result
73
- * Updates each Visitor instance and world.visitors map.
74
- */
75
- moveVisitor({ shouldTeleportVisitor, x, y }) {
76
- return __awaiter(this, void 0, void 0, function* () {
77
- try {
78
- yield this.topiaPublicApi().put(`/world/${this.urlSlug}/visitors/${this.id}/move`, {
79
- moveTo: {
80
- x,
81
- y,
82
- },
83
- teleport: shouldTeleportVisitor,
84
- }, this.requestOptions);
85
- }
86
- catch (error) {
87
- throw this.errorHandler({ error });
88
- }
89
- });
90
- }
91
- }
92
- export default Visitor;
@@ -1,257 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
11
- if (kind === "m") throw new TypeError("Private method is not writable");
12
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
13
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
14
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
15
- };
16
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
17
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
18
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
19
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
- };
21
- var _World_droppedAssetsMap;
22
- // controllers
23
- import { DroppedAsset } from "controllers/DroppedAsset";
24
- import { SDKController } from "controllers/SDKController";
25
- // utils
26
- import { removeUndefined } from "utils";
27
- /**
28
- * @summary
29
- * Create an instance of World class with a given url slug and optional attributes and session credentials.
30
- *
31
- * @usage
32
- * ```ts
33
- * await new World(topia, "exampleWorld", { attributes: { name: "Example World" } });
34
- * ```
35
- */
36
- export class World extends SDKController {
37
- constructor(topia, urlSlug, options = { attributes: {}, credentials: {} }) {
38
- super(topia, options.credentials);
39
- _World_droppedAssetsMap.set(this, void 0);
40
- Object.assign(this, options.attributes);
41
- __classPrivateFieldSet(this, _World_droppedAssetsMap, {}, "f");
42
- this.urlSlug = urlSlug;
43
- }
44
- get droppedAssets() {
45
- return __classPrivateFieldGet(this, _World_droppedAssetsMap, "f");
46
- }
47
- //////// world details
48
- /**
49
- * @summary
50
- * Retrieves details of a world.
51
- *
52
- * @usage
53
- * ```ts
54
- * await world.fetchDetails();
55
- * const { name } = world;
56
- * ```
57
- */
58
- fetchDetails() {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- try {
61
- const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/world-details`, this.requestOptions);
62
- Object.assign(this, response.data);
63
- }
64
- catch (error) {
65
- throw this.errorHandler({ error });
66
- }
67
- });
68
- }
69
- /**
70
- * @summary
71
- * Update details of a world.
72
- *
73
- * @usage
74
- * ```ts
75
- * await world.updateDetails({
76
- * controls: {
77
- * allowMuteAll: true,
78
- * disableHideVideo: true,
79
- * isMobileDisabled: false,
80
- * isShowingCurrentGuests: false,
81
- * },
82
- * description: 'Welcome to my world.',
83
- * forceAuthOnLogin: false,
84
- * height: 2000,
85
- * name: 'Example',
86
- * spawnPosition: { x: 100, y: 100 },
87
- * width: 2000
88
- * });
89
- * ```
90
- */
91
- updateDetails({ controls, description, forceAuthOnLogin, height, name, spawnPosition, width, }) {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- const payload = {
94
- controls,
95
- description,
96
- forceAuthOnLogin,
97
- height,
98
- name,
99
- spawnPosition,
100
- width,
101
- };
102
- try {
103
- yield this.topiaPublicApi().put(`/world/${this.urlSlug}/world-details`, payload, this.requestOptions);
104
- const cleanPayload = removeUndefined(payload);
105
- Object.assign(this, cleanPayload);
106
- }
107
- catch (error) {
108
- throw this.errorHandler({ error });
109
- }
110
- });
111
- }
112
- ////////// dropped assets
113
- /**
114
- * @summary
115
- * Retrieve all assets dropped in a world.
116
- *
117
- * @usage
118
- * ```ts
119
- * await world.fetchDroppedAssets();
120
- * const assets = world.droppedAssets;
121
- * ```
122
- */
123
- fetchDroppedAssets() {
124
- return __awaiter(this, void 0, void 0, function* () {
125
- try {
126
- const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/assets`, this.requestOptions);
127
- // create temp map and then update private property only once
128
- const tempDroppedAssetsMap = {};
129
- for (const index in response.data) {
130
- // tempDroppedAssetsMap[id] = createDroppedAsset(this.apiKey, response.data[id], this.urlSlug);
131
- tempDroppedAssetsMap[index] = new DroppedAsset(this.topia, response.data[index].id, this.urlSlug, {
132
- attributes: response.data[index],
133
- credentials: this.credentials,
134
- });
135
- }
136
- __classPrivateFieldSet(this, _World_droppedAssetsMap, tempDroppedAssetsMap, "f");
137
- }
138
- catch (error) {
139
- throw this.errorHandler({ error });
140
- }
141
- });
142
- }
143
- /**
144
- * @summary
145
- * Retrieve all assets dropped in a world matching uniqueName.
146
- *
147
- * @usage
148
- * ```ts
149
- * await world.fetchDroppedAssets();
150
- * const assets = world.droppedAssets;
151
- * ```
152
- */
153
- fetchDroppedAssetsWithUniqueName({ uniqueName, isPartial = false, isReversed = false, }) {
154
- return __awaiter(this, void 0, void 0, function* () {
155
- try {
156
- const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/assets-with-unique-name/${uniqueName}?${isPartial ? `partial=${isPartial}&` : ""}${isReversed ? `reversed=${isReversed}` : ""}`, this.requestOptions);
157
- // create temp map and then update private property only once
158
- const droppedAssets = [];
159
- for (const asset of response.data.assets) {
160
- droppedAssets.push(new DroppedAsset(this.topia, asset.id, this.urlSlug, {
161
- attributes: asset,
162
- credentials: this.credentials,
163
- }));
164
- }
165
- return droppedAssets;
166
- }
167
- catch (error) {
168
- throw this.errorHandler({ error });
169
- }
170
- });
171
- }
172
- /**
173
- * @summary
174
- * Update multiple custom text dropped assets with a single style while preserving text for specified dropped assets only.
175
- *
176
- * @usage
177
- * ```ts
178
- * const droppedAssetsToUpdate = [world.droppedAssets["6"], world.droppedAssets["12"]];
179
- * const style = {
180
- * "textColor": "#abc123",
181
- * "textFontFamily": "Arial",
182
- * "textSize": 40,
183
- * "textWeight": "normal",
184
- * "textWidth": 200
185
- * };
186
- * await world.updateCustomText(droppedAssetsToUpdate, style);
187
- * ```
188
- *
189
- * @result
190
- * Updates each DroppedAsset instance and world.droppedAssets map.
191
- */
192
- updateCustomTextDroppedAssets(droppedAssetsToUpdate, style) {
193
- return __awaiter(this, void 0, void 0, function* () {
194
- const allPromises = [];
195
- droppedAssetsToUpdate.forEach((a) => {
196
- allPromises.push(a.updateCustomTextAsset(style, a.text));
197
- });
198
- const outcomes = yield Promise.all(allPromises);
199
- return outcomes;
200
- });
201
- }
202
- /**
203
- * @summary
204
- * Drop a scene in a world.
205
- *
206
- * @usage
207
- * ```ts
208
- * await world.dropScene({
209
- * "sceneId": "string",
210
- * "position": {
211
- * "x": 0,
212
- * "y": 0
213
- * },
214
- * "assetSuffix": "string"
215
- * });
216
- * ```
217
- */
218
- dropScene({ assetSuffix, position, sceneId, }) {
219
- return __awaiter(this, void 0, void 0, function* () {
220
- try {
221
- yield this.topiaPublicApi().post(`/world/${this.urlSlug}/drop-scene`, { assetSuffix, position, sceneId }, this.requestOptions);
222
- }
223
- catch (error) {
224
- throw this.errorHandler({ error });
225
- }
226
- });
227
- }
228
- /**
229
- * @summary
230
- * Replace the current scene of a world.
231
- *
232
- * @usage
233
- * ```ts
234
- * const droppedAssetsToUpdate = [world.droppedAssets["6"], world.droppedAssets["12"]]
235
- * const style = {
236
- * "textColor": "#abc123",
237
- * "textFontFamily": "Arial",
238
- * "textSize": 40,
239
- * "textWeight": "normal",
240
- * "textWidth": 200
241
- * }
242
- * await world.replaceScene(SCENE_ID);
243
- * ```
244
- */
245
- replaceScene(sceneId) {
246
- return __awaiter(this, void 0, void 0, function* () {
247
- try {
248
- yield this.topiaPublicApi().put(`/world/${this.urlSlug}/change-scene`, { sceneId }, this.requestOptions);
249
- }
250
- catch (error) {
251
- throw this.errorHandler({ error });
252
- }
253
- });
254
- }
255
- }
256
- _World_droppedAssetsMap = new WeakMap();
257
- export default World;
@@ -1,162 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
11
- if (kind === "m") throw new TypeError("Private method is not writable");
12
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
13
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
14
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
15
- };
16
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
17
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
18
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
19
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
- };
21
- var _WorldActivity_visitorsMap;
22
- // controllers
23
- import { SDKController } from "controllers/SDKController";
24
- import { Visitor } from "controllers/Visitor";
25
- // utils
26
- import { scatterVisitors } from "utils";
27
- /**
28
- * @summary
29
- * Create an instance of WorldActivity class with a given url slug and optional attributes and session credentials.
30
- *
31
- * This class is responsible for all activity of a specified world including editing dropped assets, moving current visitors, etc.
32
- *
33
- * @usage
34
- * ```ts
35
- * await new WorldActivity(topia, "exampleWorld", { attributes: { name: "Example World" } });
36
- * ```
37
- */
38
- export class WorldActivity extends SDKController {
39
- constructor(topia, urlSlug, options = { credentials: {} }) {
40
- super(topia, options.credentials);
41
- _WorldActivity_visitorsMap.set(this, void 0);
42
- __classPrivateFieldSet(this, _WorldActivity_visitorsMap, {}, "f");
43
- this.urlSlug = urlSlug;
44
- }
45
- get visitors() {
46
- return __classPrivateFieldGet(this, _WorldActivity_visitorsMap, "f");
47
- }
48
- //////// visitors
49
- fetchVisitors() {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- try {
52
- const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/visitors`, this.requestOptions);
53
- // create temp map and then update private property only once
54
- const tempVisitorsMap = {};
55
- for (const id in response.data) {
56
- tempVisitorsMap[id] = new Visitor(this.topia, response.data[id].visitorId, this.urlSlug, {
57
- attributes: response.data[id],
58
- credentials: this.credentials,
59
- });
60
- }
61
- __classPrivateFieldSet(this, _WorldActivity_visitorsMap, tempVisitorsMap, "f");
62
- }
63
- catch (error) {
64
- throw this.errorHandler({ error });
65
- }
66
- });
67
- }
68
- /**
69
- * @summary
70
- * Retrieve all visitors currently in a world.
71
- *
72
- * @usage
73
- * ```ts
74
- * const visitors = await world.currentVisitors();
75
- * ```
76
- */
77
- currentVisitors() {
78
- return __awaiter(this, void 0, void 0, function* () {
79
- try {
80
- yield this.fetchVisitors();
81
- return this.visitors;
82
- }
83
- catch (error) {
84
- return error;
85
- }
86
- });
87
- }
88
- /**
89
- * @summary
90
- * Move all visitors currently in a world to a single set of coordinates.
91
- * Optionally refetch visitors, teleport or walk visitors to new location,
92
- * and scatter visitors by any number so that they don't all move to the exact same location.
93
- *
94
- * @usage
95
- * ```ts
96
- * await world.moveAllVisitors({
97
- * shouldFetchVisitors: true,
98
- * shouldTeleportVisitors: true,
99
- * scatterVisitorsBy: 40,
100
- * x: 100,
101
- * y: 100,
102
- * });
103
- * ```
104
- *
105
- * @result
106
- * Updates each Visitor instance and world.visitors map.
107
- */
108
- moveAllVisitors({ shouldFetchVisitors = true, shouldTeleportVisitors = true, scatterVisitorsBy = 0, x, y, }) {
109
- return __awaiter(this, void 0, void 0, function* () {
110
- if (shouldFetchVisitors)
111
- yield this.fetchVisitors();
112
- const allPromises = [];
113
- if (!this.visitors)
114
- return;
115
- const objectKeys = Object.keys(this.visitors);
116
- objectKeys.forEach((key) => allPromises.push(__classPrivateFieldGet(this, _WorldActivity_visitorsMap, "f")[key].moveVisitor({
117
- shouldTeleportVisitor: shouldTeleportVisitors,
118
- x: scatterVisitors(x, scatterVisitorsBy),
119
- y: scatterVisitors(y, scatterVisitorsBy),
120
- })));
121
- const outcomes = yield Promise.all(allPromises);
122
- return outcomes;
123
- });
124
- }
125
- /**
126
- * @summary
127
- * Teleport or walk a list of visitors currently in a world to various coordinates.
128
- *
129
- * @usage
130
- * ```ts
131
- * const visitorsToMove = [
132
- * {
133
- * visitorObj: world.visitors["1"],
134
- * shouldTeleportVisitor: true,
135
- * x: 100,
136
- * y: 100
137
- * }, {
138
- * visitorObj: world.visitors["2"],
139
- * shouldTeleportVisitor: false,
140
- * x: 100,
141
- * y: 100
142
- * }
143
- * ];
144
- * await world.moveVisitors(visitorsToMove);
145
- * ```
146
- *
147
- * @result
148
- * Updates each Visitor instance and world.visitors map.
149
- */
150
- moveVisitors(visitorsToMove) {
151
- return __awaiter(this, void 0, void 0, function* () {
152
- const allPromises = [];
153
- visitorsToMove.forEach((v) => {
154
- allPromises.push(v.visitorObj.moveVisitor({ shouldTeleportVisitor: v.shouldTeleportVisitor, x: v.x, y: v.y }));
155
- });
156
- const outcomes = yield Promise.all(allPromises);
157
- return outcomes;
158
- });
159
- }
160
- }
161
- _WorldActivity_visitorsMap = new WeakMap();
162
- export default WorldActivity;
@@ -1,37 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import MockAdapter from "axios-mock-adapter";
11
- import { AssetFactory } from "factories";
12
- import { Topia } from "controllers/Topia";
13
- const apiDomain = "api.topia.io";
14
- describe("Asset Class", () => {
15
- let Asset, mock, testAsset, topia;
16
- beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
17
- topia = new Topia({
18
- apiDomain,
19
- apiKey: "exampleKey",
20
- apiProtocol: "https",
21
- interactiveKey: "key",
22
- interactiveSecret: "secret",
23
- });
24
- mock = new MockAdapter(topia.axios);
25
- Asset = new AssetFactory(topia);
26
- testAsset = Asset.create("test");
27
- }));
28
- afterEach(() => {
29
- mock.restore();
30
- jest.resetAllMocks();
31
- });
32
- it("should return an array of assets owned by specific email address", () => __awaiter(void 0, void 0, void 0, function* () {
33
- mock.onGet(`https://${apiDomain}/api/v1/assets/topia-assets`).reply(200);
34
- yield testAsset.fetchPlatformAssets();
35
- expect(mock.history.get.length).toBe(1);
36
- }));
37
- });