@rtsdk/topia 0.0.17 → 0.0.19

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 (50) hide show
  1. package/dist/index.js +4 -40824
  2. package/dist/src/controllers/Asset.js +0 -19
  3. package/dist/src/factories/DroppedAssetFactory.js +17 -0
  4. package/package.json +2 -2
  5. package/dist/__mocks__/assets.js +0 -241
  6. package/dist/__mocks__/index.js +0 -4
  7. package/dist/__mocks__/scenes.js +0 -104
  8. package/dist/__mocks__/visitors.js +0 -83
  9. package/dist/__mocks__/worlds.js +0 -52
  10. package/dist/controllers/Asset.js +0 -31
  11. package/dist/controllers/DroppedAsset.js +0 -335
  12. package/dist/controllers/SDKController.js +0 -36
  13. package/dist/controllers/Topia.js +0 -32
  14. package/dist/controllers/User.js +0 -106
  15. package/dist/controllers/Visitor.js +0 -55
  16. package/dist/controllers/World.js +0 -328
  17. package/dist/controllers/__tests__/asset.test.js +0 -37
  18. package/dist/controllers/__tests__/droppedAsset.test.js +0 -98
  19. package/dist/controllers/__tests__/user.test.js +0 -50
  20. package/dist/controllers/__tests__/visitor.test.js +0 -41
  21. package/dist/controllers/__tests__/world.test.js +0 -77
  22. package/dist/controllers/index.js +0 -7
  23. package/dist/factories/AssetFactory.js +0 -11
  24. package/dist/factories/DroppedAssetFactory.js +0 -26
  25. package/dist/factories/UserFactory.js +0 -10
  26. package/dist/factories/VisitorFactory.js +0 -10
  27. package/dist/factories/WorldFactory.js +0 -10
  28. package/dist/factories/index.js +0 -5
  29. package/dist/interfaces/AssetInterfaces.js +0 -1
  30. package/dist/interfaces/DroppedAssetInterfaces.js +0 -1
  31. package/dist/interfaces/SDKInterfaces.js +0 -1
  32. package/dist/interfaces/TopiaInterfaces.js +0 -1
  33. package/dist/interfaces/UserInterfaces.js +0 -1
  34. package/dist/interfaces/VisitorInterfaces.js +0 -1
  35. package/dist/interfaces/WorldInterfaces.js +0 -1
  36. package/dist/interfaces/index.js +0 -7
  37. package/dist/src/utils/getErrorMessage.js +0 -5
  38. package/dist/src/utils/getSuccessResponse.js +0 -3
  39. package/dist/types/DroppedAssetTypes.js +0 -12
  40. package/dist/types/InteractiveCredentialsTypes.js +0 -1
  41. package/dist/types/OptionsTypes.js +0 -1
  42. package/dist/types/VisitorTypes.js +0 -1
  43. package/dist/types/index.js +0 -3
  44. package/dist/utils/__tests__/removeUndefined.test.js +0 -10
  45. package/dist/utils/__tests__/scatterVisitors.test.js +0 -11
  46. package/dist/utils/getErrorMessage.js +0 -7
  47. package/dist/utils/index.js +0 -4
  48. package/dist/utils/publicAPI.js +0 -13
  49. package/dist/utils/removeUndefined.js +0 -11
  50. package/dist/utils/scatterVisitors.js +0 -8
@@ -1,335 +0,0 @@
1
- // controllers
2
- import { Asset } from "controllers/Asset";
3
- // utils
4
- import { getErrorMessage } from "utils";
5
- /**
6
- * Create an instance of Dropped Asset class with a given apiKey and optional arguments.
7
- *
8
- * ```ts
9
- * await new DroppedAsset({ id: "1giFZb0sQ3X27L7uGyQX", urlSlug: "magic" });
10
- * ```
11
- */
12
- export class DroppedAsset extends Asset {
13
- constructor(topia, id, urlSlug, options = { args: { text: "" }, creds: {} }) {
14
- var _a;
15
- super(topia, id, options);
16
- // update dropped assets
17
- this.updateDroppedAsset = (payload, updateType) => {
18
- return new Promise((resolve, reject) => {
19
- this.topia.axios
20
- .put(`/world/${this.urlSlug}/assets/${this.id}/${updateType}`, Object.assign({}, payload), this.requestOptions)
21
- .then(() => {
22
- resolve("Success!");
23
- })
24
- .catch((error) => {
25
- reject(new Error(getErrorMessage(error)));
26
- });
27
- });
28
- };
29
- this.id = id;
30
- this.text = (_a = options.args) === null || _a === void 0 ? void 0 : _a.text;
31
- this.urlSlug = urlSlug;
32
- Object.assign(this, options.args);
33
- }
34
- /**
35
- * @summary
36
- * Retrieves dropped asset details.
37
- *
38
- * @usage
39
- * ```ts
40
- * await droppedAsset.fetchDroppedAssetById();
41
- * const { assetName } = droppedAsset;
42
- * ```
43
- */
44
- // get dropped asset
45
- fetchDroppedAssetById() {
46
- return new Promise((resolve, reject) => {
47
- this.topia.axios
48
- .get(`/world/${this.urlSlug}/assets/${this.id}`, this.requestOptions)
49
- .then((response) => {
50
- Object.assign(this, response.data);
51
- resolve("Success!");
52
- })
53
- .catch((error) => {
54
- reject(new Error(getErrorMessage(error)));
55
- });
56
- });
57
- }
58
- // delete dropped asset
59
- deleteDroppedAsset() {
60
- return new Promise((resolve, reject) => {
61
- this.topia.axios
62
- .delete(`/world/${this.urlSlug}/assets/${this.id}`, this.requestOptions)
63
- .then(() => {
64
- resolve("Success!");
65
- })
66
- .catch((error) => {
67
- reject(new Error(getErrorMessage(error)));
68
- });
69
- });
70
- }
71
- /**
72
- * @summary
73
- * Retrieves the data object for a dropped asset.
74
- *
75
- * @usage
76
- * ```ts
77
- * await droppedAsset.fetchDroppedAssetDataObject();
78
- * const { dataObject } = droppedAsset;
79
- * ```
80
- */
81
- // get dropped asset
82
- fetchDroppedAssetDataObject() {
83
- return new Promise((resolve, reject) => {
84
- this.topia.axios
85
- .get(`/world/${this.urlSlug}/assets/${this.id}/data-object`, this.requestOptions)
86
- .then((response) => {
87
- this.dataObject = response.data;
88
- resolve("Success!");
89
- })
90
- .catch((error) => {
91
- reject(new Error(getErrorMessage(error)));
92
- });
93
- });
94
- }
95
- /**
96
- * @summary
97
- * Updates the data object for a dropped asset.
98
- *
99
- * @usage
100
- * ```ts
101
- * await droppedAsset.updateDroppedAssetDataObject({
102
- * "exampleKey": "exampleValue",
103
- * });
104
- * const { dataObject } = droppedAsset;
105
- * ```
106
- */
107
- // get dropped asset
108
- updateDroppedAssetDataObject(dataObject) {
109
- return new Promise((resolve, reject) => {
110
- this.topia.axios
111
- .put(`/world/${this.urlSlug}/assets/${this.id}/set-data-object`, dataObject, this.requestOptions)
112
- .then(() => {
113
- this.dataObject = dataObject;
114
- resolve("Success!");
115
- })
116
- .catch((error) => {
117
- reject(new Error(getErrorMessage(error)));
118
- });
119
- });
120
- }
121
- /**
122
- * @summary
123
- * Updates broadcast options for a dropped asset.
124
- *
125
- * @usage
126
- * ```ts
127
- * await droppedAsset.updateBroadcast({
128
- * assetBroadcast: true,
129
- * assetBroadcastAll: true,
130
- * broadcasterEmail: "example@email.com"
131
- * });
132
- * ```
133
- */
134
- updateBroadcast({ assetBroadcast, assetBroadcastAll, broadcasterEmail }) {
135
- return new Promise((resolve, reject) => {
136
- return this.updateDroppedAsset({ assetBroadcast, assetBroadcastAll, broadcasterEmail }, "set-asset-broadcast")
137
- .then(resolve)
138
- .catch((error) => {
139
- reject(new Error(getErrorMessage(error)));
140
- });
141
- });
142
- }
143
- /**
144
- * @summary
145
- * Updates click options for a dropped asset.
146
- *
147
- * @usage
148
- * ```ts
149
- * await droppedAsset.updateClickType({
150
- * "clickType": "portal",
151
- * "clickableLink": "https://topia.io",
152
- * "clickableLinkTitle": "My awesome link!",
153
- * "position": {
154
- * "x": 0,
155
- * "y": 0
156
- * },
157
- * "portalName": "community"
158
- * });
159
- * ```
160
- */
161
- updateClickType({ clickType, clickableLink, clickableLinkTitle, portalName, position, }) {
162
- return new Promise((resolve, reject) => {
163
- return this.updateDroppedAsset({ clickType, clickableLink, clickableLinkTitle, portalName, position }, "change-click-type")
164
- .then(resolve)
165
- .catch((error) => {
166
- reject(new Error(getErrorMessage(error)));
167
- });
168
- });
169
- }
170
- /**
171
- * @summary
172
- * Updates text and style of a dropped asset.
173
- *
174
- * @usage
175
- * ```ts
176
- * const style = {
177
- * "textColor": "#abc123",
178
- * "textFontFamily": "Arial",
179
- * "textSize": 40,
180
- * "textWeight": "normal",
181
- * "textWidth": 200
182
- * };
183
- * await droppedAsset.updateCustomText(style, "hello world");
184
- * ```
185
- */
186
- updateCustomText(style, text) {
187
- return new Promise((resolve, reject) => {
188
- return this.updateDroppedAsset({ style, text }, "set-custom-text")
189
- .then(resolve)
190
- .catch((error) => {
191
- reject(new Error(getErrorMessage(error)));
192
- });
193
- });
194
- }
195
- /**
196
- * @summary
197
- * Updates media options for a dropped asset.
198
- *
199
- * @usage
200
- * ```ts
201
- * await droppedAsset.updateMediaType({
202
- * "mediaType": "link",
203
- * "mediaLink": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
204
- * "isVideo": true,
205
- * "syncUserMedia": true,
206
- * "audioVolume": -1,
207
- * "portalName": "community",
208
- * "audioRadius": 0,
209
- * "mediaName": "string"
210
- * });
211
- * ```
212
- */
213
- updateMediaType({ audioRadius, audioVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia, }) {
214
- return new Promise((resolve, reject) => {
215
- return this.updateDroppedAsset({ audioRadius, audioVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia }, "change-media-type")
216
- .then(resolve)
217
- .catch((error) => {
218
- reject(new Error(getErrorMessage(error)));
219
- });
220
- });
221
- }
222
- /**
223
- * @summary
224
- * Updates mute zone options for a dropped asset.
225
- *
226
- * @usage
227
- * ```ts
228
- * await droppedAsset.updateMuteZone(true);
229
- * ```
230
- */
231
- updateMuteZone(isMutezone) {
232
- return new Promise((resolve, reject) => {
233
- return this.updateDroppedAsset({ isMutezone }, "set-mute-zone")
234
- .then(resolve)
235
- .catch((error) => {
236
- reject(new Error(getErrorMessage(error)));
237
- });
238
- });
239
- }
240
- /**
241
- * @summary
242
- * Moves a dropped asset to specified coordinates.
243
- *
244
- * @usage
245
- * ```ts
246
- * await droppedAsset.updatePosition(100,200);
247
- * ```
248
- */
249
- updatePosition(x, y) {
250
- return new Promise((resolve, reject) => {
251
- return this.updateDroppedAsset({ x, y }, "set-position")
252
- .then(resolve)
253
- .catch((error) => {
254
- reject(new Error(getErrorMessage(error)));
255
- });
256
- });
257
- }
258
- /**
259
- * @summary
260
- * Updates private zone options for a dropped asset.
261
- *
262
- * @usage
263
- * ```ts
264
- * await droppedAsset.updateMuteZone({
265
- * "isPrivateZone": false,
266
- * "isPrivateZoneChatDisabled": true,
267
- * "privateZoneUserCap": 10
268
- * });
269
- * ```
270
- */
271
- updatePrivateZone({ isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap, }) {
272
- return new Promise((resolve, reject) => {
273
- return this.updateDroppedAsset({ isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap }, "set-private-zone")
274
- .then(resolve)
275
- .catch((error) => {
276
- reject(new Error(getErrorMessage(error)));
277
- });
278
- });
279
- }
280
- /**
281
- * @summary
282
- * Updates the size of a dropped asset.
283
- *
284
- * @usage
285
- * ```ts
286
- * await droppedAsset.assetScale(.5);
287
- * ```
288
- */
289
- updateScale(assetScale) {
290
- return new Promise((resolve, reject) => {
291
- return this.updateDroppedAsset({ assetScale }, "change-scale")
292
- .then(resolve)
293
- .catch((error) => {
294
- reject(new Error(getErrorMessage(error)));
295
- });
296
- });
297
- }
298
- /**
299
- * @summary
300
- * Change or remove media embedded in a dropped asset.
301
- *
302
- * @usage
303
- * ```ts
304
- * await droppedAsset.updateUploadedMediaSelected("LVWyxwNxI96eLjnXWwYO");
305
- * ```
306
- */
307
- updateUploadedMediaSelected(mediaId) {
308
- return new Promise((resolve, reject) => {
309
- return this.updateDroppedAsset({ mediaId }, "change-uploaded-media-selected")
310
- .then(resolve)
311
- .catch((error) => {
312
- reject(new Error(getErrorMessage(error)));
313
- });
314
- });
315
- }
316
- /**
317
- * @summary
318
- * Change or remove top and bottom layers of a dropped asset.
319
- *
320
- * @usage
321
- * ```ts
322
- * await droppedAsset.updateWebImageLayers("","https://www.shutterstock.com/image-vector/colorful-illustration-test-word-260nw-1438324490.jpg");
323
- * ```
324
- */
325
- updateWebImageLayers(bottom, top) {
326
- return new Promise((resolve, reject) => {
327
- return this.updateDroppedAsset({ bottom, top }, "set-webimage-layers")
328
- .then(resolve)
329
- .catch((error) => {
330
- reject(new Error(getErrorMessage(error)));
331
- });
332
- });
333
- }
334
- }
335
- export default DroppedAsset;
@@ -1,36 +0,0 @@
1
- // utils
2
- import jwt from "jsonwebtoken";
3
- /**
4
- * Create an instance of SDKController class with credentials.
5
- *
6
- * ```ts
7
- * const creds = {
8
- * assetId: "exampleAsset",
9
- * interactiveNonce: "exampleNonce"
10
- * interactivePublicKey: "examplePublicKey",
11
- * playerId: 1,
12
- * url: "https://topia.io",
13
- * }
14
- * const topia = await new Topia({
15
- * apiDomain: "api.topia.io",
16
- * apiKey: "exampleKey",
17
- * interactiveKey: "key",
18
- * interactiveSecret: "secret",
19
- * }
20
- * await new SDKController({ creds, topia });
21
- * ```
22
- */
23
- export class SDKController {
24
- constructor(topia, creds) {
25
- this.creds = creds;
26
- this.topia = topia;
27
- if (creds && topia.interactiveSecret) {
28
- this.jwt = jwt.sign(creds, topia.interactiveSecret);
29
- this.requestOptions = { headers: { Interactivejwt: this.jwt } };
30
- }
31
- else {
32
- this.requestOptions = {};
33
- }
34
- }
35
- }
36
- export default SDKController;
@@ -1,32 +0,0 @@
1
- import axios from "axios";
2
- /**
3
- * Create a single instance of Topia axios used for all calls to the public API in all classes
4
- *
5
- * ```ts
6
- * const topia = await new Topia({
7
- * apiDomain: "api.topia.io",
8
- * apiKey: "exampleKey",
9
- * interactiveKey: "key",
10
- * interactiveSecret: "secret",
11
- * });
12
- * ```
13
- */
14
- export class Topia {
15
- constructor({ apiKey, apiDomain, interactiveKey, interactiveSecret, }) {
16
- this.apiKey = apiKey;
17
- this.apiDomain = apiDomain || "api.topia.io";
18
- this.interactiveSecret = interactiveSecret;
19
- const headers = {
20
- "Content-Type": "application/json",
21
- };
22
- if (apiKey)
23
- headers.Authorization = apiKey;
24
- if (interactiveKey)
25
- headers.Publickey = interactiveKey;
26
- this.axios = axios.create({
27
- baseURL: `https://${apiDomain}/api`,
28
- headers,
29
- });
30
- }
31
- }
32
- export default Topia;
@@ -1,106 +0,0 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- 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");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- 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");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _User_worldsMap;
13
- // controllers
14
- import { SDKController } from "controllers/SDKController";
15
- import { World } from "controllers/World";
16
- // utils
17
- import { getErrorMessage } from "utils";
18
- /**
19
- * Create an instance of User class with a given apiKey.
20
- *
21
- * ```ts
22
- * await new User({ email: "example@email.io" });
23
- * ```
24
- */
25
- export class User extends SDKController {
26
- constructor(topia, email, options = { creds: {} }) {
27
- super(topia, options.creds);
28
- _User_worldsMap.set(this, void 0);
29
- __classPrivateFieldSet(this, _User_worldsMap, {}, "f");
30
- this.email = email;
31
- }
32
- get worlds() {
33
- return __classPrivateFieldGet(this, _User_worldsMap, "f");
34
- }
35
- /**
36
- * @summary
37
- * Returns all assets owned by User when an email address is provided.
38
- */
39
- fetchAssetsByEmail(ownerEmail) {
40
- return new Promise((resolve, reject) => {
41
- this.topia.axios
42
- .get(`/assets/my-assets?email=${ownerEmail}`, this.requestOptions)
43
- .then((response) => {
44
- resolve(response.data);
45
- })
46
- .catch((error) => {
47
- reject(new Error(getErrorMessage(error)));
48
- });
49
- });
50
- }
51
- /**
52
- * @summary
53
- * Returns all scenes owned by User when an email address is provided.
54
- */
55
- fetchScenesByEmail() {
56
- return new Promise((resolve, reject) => {
57
- if (!this.email)
58
- reject("There is no email associated with this user.");
59
- this.topia.axios
60
- .get(`/scenes/my-scenes?email=${this.email}`, this.requestOptions)
61
- .then((response) => {
62
- resolve(response.data);
63
- })
64
- .catch((error) => {
65
- reject(new Error(getErrorMessage(error)));
66
- });
67
- });
68
- }
69
- /**
70
- * @summary
71
- * Retrieves all worlds owned by user with matching API Key,
72
- * creates a new World object for each,
73
- * and creates new map of Worlds accessible via user.worlds.
74
- *
75
- * @usage
76
- * ```ts
77
- * await user.fetchWorldsByKey();
78
- * const userWorlds = user.worlds;
79
- * ```
80
- *
81
- * @result
82
- * ```ts
83
- * { urlSlug: new World({ apiKey, worldArgs, urlSlug }) }
84
- * ```
85
- */
86
- fetchWorldsByKey() {
87
- return new Promise((resolve, reject) => {
88
- this.topia.axios
89
- .get("/user/worlds", this.requestOptions)
90
- .then((response) => {
91
- const tempWorldsMap = {};
92
- for (const i in response.data) {
93
- const worldDetails = response.data[i];
94
- tempWorldsMap[worldDetails.urlSlug] = new World(this.topia, worldDetails.urlSlug, { args: worldDetails });
95
- }
96
- __classPrivateFieldSet(this, _User_worldsMap, tempWorldsMap, "f");
97
- resolve("Success!");
98
- })
99
- .catch((error) => {
100
- reject(new Error(getErrorMessage(error)));
101
- });
102
- });
103
- }
104
- }
105
- _User_worldsMap = new WeakMap();
106
- export default User;
@@ -1,55 +0,0 @@
1
- // controllers
2
- import { SDKController } from "controllers/SDKController";
3
- // utils
4
- import { getErrorMessage } from "utils";
5
- /**
6
- * Create an instance of Visitor class with a given apiKey and optional arguments.
7
- *
8
- * ```ts
9
- * await new Visitor(this.topia, id, urlSlug, { options });
10
- * ```
11
- */
12
- export class Visitor extends SDKController {
13
- constructor(topia, id, urlSlug, options = { args: {}, creds: {} }) {
14
- super(topia, options.creds);
15
- Object.assign(this, options.args);
16
- this.id = id;
17
- this.urlSlug = urlSlug;
18
- this.moveVisitor;
19
- }
20
- /**
21
- * @summary
22
- * Teleport or walk a visitor currently in a world to a single set of coordinates.
23
- *
24
- * @usage
25
- * ```ts
26
- * await visitor.moveVisitor({
27
- * shouldTeleportVisitor: true,
28
- * x: 100,
29
- * y: 100,
30
- * });
31
- * ```
32
- *
33
- * @result
34
- * Updates each Visitor instance and world.visitors map.
35
- */
36
- moveVisitor({ shouldTeleportVisitor, x, y }) {
37
- return new Promise((resolve, reject) => {
38
- this.topia.axios
39
- .put(`/world/${this.urlSlug}/visitors/${this.id}/move`, {
40
- moveTo: {
41
- x,
42
- y,
43
- },
44
- teleport: shouldTeleportVisitor,
45
- }, this.requestOptions)
46
- .then(() => {
47
- resolve("Success!");
48
- })
49
- .catch((error) => {
50
- reject(new Error(getErrorMessage(error)));
51
- });
52
- });
53
- }
54
- }
55
- export default Visitor;