@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,443 +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 __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
11
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
12
- 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");
13
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
14
- };
15
- var _DroppedAsset_updateDroppedAsset;
16
- // controllers
17
- import { Asset } from "controllers/Asset";
18
- /**
19
- * @summary
20
- * Create an instance of Dropped Asset class with a given dropped asset id, url slug, and optional attributes and session credentials.
21
- *
22
- * @usage
23
- * ```ts
24
- * await new DroppedAsset(topia, "1giFZb0sQ3X27L7uGyQX", "example", { attributes: { text: "" }, credentials: { assetId: "1giFZb0sQ3X27L7uGyQX" } } });
25
- * ```
26
- */
27
- export class DroppedAsset extends Asset {
28
- constructor(topia, id, urlSlug, options = { attributes: { text: "" }, credentials: {} }) {
29
- var _a;
30
- super(topia, id, options);
31
- // update dropped assets
32
- _DroppedAsset_updateDroppedAsset.set(this, (payload, updateType) => __awaiter(this, void 0, void 0, function* () {
33
- try {
34
- yield this.topiaPublicApi().put(`/world/${this.urlSlug}/assets/${this.id}/${updateType}`, Object.assign({}, payload), this.requestOptions);
35
- }
36
- catch (error) {
37
- throw this.errorHandler({ error });
38
- }
39
- }));
40
- Object.assign(this, options.attributes);
41
- this.id = id;
42
- this.text = (_a = options.attributes) === null || _a === void 0 ? void 0 : _a.text;
43
- this.urlSlug = urlSlug;
44
- }
45
- /**
46
- * @summary
47
- * Retrieves dropped asset details.
48
- *
49
- * @usage
50
- * ```ts
51
- * await droppedAsset.fetchDroppedAssetById();
52
- * const { assetName } = droppedAsset;
53
- * ```
54
- */
55
- fetchDroppedAssetById() {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- try {
58
- const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/assets/${this.id}`, this.requestOptions);
59
- const droppedAssetDetails = response.data;
60
- droppedAssetDetails.urlSlug = this.urlSlug;
61
- Object.assign(this, droppedAssetDetails);
62
- }
63
- catch (error) {
64
- throw this.errorHandler({ error });
65
- }
66
- });
67
- }
68
- /**
69
- * @summary
70
- * Delete dropped asset.
71
- *
72
- * @usage
73
- * ```ts
74
- * await droppedAsset.deleteDroppedAsset();
75
- * ```
76
- */
77
- deleteDroppedAsset() {
78
- return __awaiter(this, void 0, void 0, function* () {
79
- try {
80
- yield this.topiaPublicApi().delete(`/world/${this.urlSlug}/assets/${this.id}`, this.requestOptions);
81
- }
82
- catch (error) {
83
- throw this.errorHandler({ error });
84
- }
85
- });
86
- }
87
- /**
88
- * @summary
89
- * Retrieves the data object for a dropped asset.
90
- *
91
- * @usage
92
- * ```ts
93
- * await droppedAsset.fetchDroppedAssetDataObject();
94
- * const { dataObject } = droppedAsset;
95
- * ```
96
- */
97
- fetchDroppedAssetDataObject() {
98
- return __awaiter(this, void 0, void 0, function* () {
99
- try {
100
- const response = yield this.topiaPublicApi().get(`/world/${this.urlSlug}/assets/${this.id}/data-object`, this.requestOptions);
101
- this.dataObject = response.data;
102
- }
103
- catch (error) {
104
- throw this.errorHandler({ error });
105
- }
106
- });
107
- }
108
- /**
109
- * @summary
110
- * Sets the data object for a dropped asset.
111
- *
112
- * 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
113
- *
114
- * @usage
115
- * ```ts
116
- * await droppedAsset.setDroppedAssetDataObject({
117
- * "exampleKey": "exampleValue",
118
- * });
119
- * const { dataObject } = droppedAsset;
120
- * ```
121
- */
122
- setDroppedAssetDataObject(dataObject, options = {}) {
123
- return __awaiter(this, void 0, void 0, function* () {
124
- try {
125
- const { lock = {} } = options;
126
- yield this.topiaPublicApi().put(`/world/${this.urlSlug}/assets/${this.id}/set-data-object`, { dataObject, lock }, this.requestOptions);
127
- this.dataObject = dataObject;
128
- }
129
- catch (error) {
130
- throw this.errorHandler({ error });
131
- }
132
- });
133
- }
134
- /**
135
- * @summary
136
- * Updates the data object for a dropped asset.
137
- *
138
- * 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
139
- *
140
- * @usage
141
- * ```ts
142
- * await droppedAsset.updateDroppedAssetDataObject({
143
- * "exampleKey": "exampleValue",
144
- * });
145
- * const { dataObject } = droppedAsset;
146
- * ```
147
- */
148
- // get dropped asset
149
- updateDroppedAssetDataObject(dataObject, options = {}) {
150
- return __awaiter(this, void 0, void 0, function* () {
151
- try {
152
- const { lock = {} } = options;
153
- yield this.topiaPublicApi().put(`/world/${this.urlSlug}/assets/${this.id}/update-data-object`, { dataObject, lock }, this.requestOptions);
154
- this.dataObject = dataObject;
155
- }
156
- catch (error) {
157
- throw this.errorHandler({ error });
158
- }
159
- });
160
- }
161
- /**
162
- * @summary
163
- * Updates broadcast options for a dropped asset.
164
- *
165
- * @usage
166
- * ```ts
167
- * await droppedAsset.updateBroadcast({
168
- * assetBroadcast: true,
169
- * assetBroadcastAll: true,
170
- * broadcasterEmail: "example@email.com"
171
- * });
172
- * ```
173
- */
174
- updateBroadcast({ assetBroadcast, assetBroadcastAll, broadcasterEmail, }) {
175
- try {
176
- return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { assetBroadcast, assetBroadcastAll, broadcasterEmail }, "set-asset-broadcast");
177
- }
178
- catch (error) {
179
- throw this.errorHandler({ error });
180
- }
181
- }
182
- /**
183
- * @summary
184
- * Updates click options for a dropped asset.
185
- *
186
- * @usage
187
- * ```ts
188
- * await droppedAsset.updateClickType({
189
- * "clickType": "portal",
190
- * "clickableLink": "https://topia.io",
191
- * "clickableLinkTitle": "My awesome link!",
192
- * "clickableDisplayTextDescription": "Description",
193
- * "clickableDisplayTextHeadline": "Title",
194
- * "position": {
195
- * "x": 0,
196
- * "y": 0
197
- * },
198
- * "portalName": "community"
199
- * });
200
- * ```
201
- */
202
- updateClickType({ clickType, clickableLink, clickableLinkTitle, clickableDisplayTextDescription, clickableDisplayTextHeadline, portalName, position, }) {
203
- try {
204
- return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, {
205
- clickType,
206
- clickableLink,
207
- clickableLinkTitle,
208
- clickableDisplayTextDescription,
209
- clickableDisplayTextHeadline,
210
- portalName,
211
- position,
212
- }, "change-click-type");
213
- }
214
- catch (error) {
215
- throw this.errorHandler({ error });
216
- }
217
- }
218
- /**
219
- * @summary
220
- * Updates text and style of a dropped asset.
221
- *
222
- * @usage
223
- * ```ts
224
- * const style = {
225
- * "textColor": "#abc123",
226
- * "textFontFamily": "Arial",
227
- * "textSize": 40,
228
- * "textWeight": "normal",
229
- * "textWidth": 200
230
- * };
231
- * await droppedAsset.updateCustomTextAsset(style, "hello world");
232
- * ```
233
- */
234
- updateCustomTextAsset(style, text) {
235
- try {
236
- return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { style, text }, "set-custom-text");
237
- }
238
- catch (error) {
239
- throw this.errorHandler({ error });
240
- }
241
- }
242
- /**
243
- * @summary
244
- * Updates media options for a dropped asset.
245
- *
246
- * @usage
247
- * ```ts
248
- * await droppedAsset.updateMediaType({
249
- * "mediaType": "link",
250
- * "mediaLink": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
251
- * "isVideo": true,
252
- * "syncUserMedia": true,
253
- * "audioSliderVolume: 30"
254
- * "portalName": "community",
255
- * "audioRadius": 0,
256
- * "mediaName": "string"
257
- * });
258
- * ```
259
- */
260
- updateMediaType({ audioRadius, audioSliderVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia, }) {
261
- try {
262
- return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { audioRadius, audioSliderVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia }, "change-media-type");
263
- }
264
- catch (error) {
265
- throw this.errorHandler({ error });
266
- }
267
- }
268
- /**
269
- * @summary
270
- * Updates mute zone options for a dropped asset.
271
- *
272
- * @usage
273
- * ```ts
274
- * await droppedAsset.updateMuteZone(true);
275
- * ```
276
- */
277
- updateMuteZone(isMutezone) {
278
- try {
279
- return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { isMutezone }, "set-mute-zone");
280
- }
281
- catch (error) {
282
- throw this.errorHandler({ error });
283
- }
284
- }
285
- /**
286
- * @summary
287
- * Moves a dropped asset to specified coordinates.
288
- *
289
- * @usage
290
- * ```ts
291
- * await droppedAsset.updatePosition(100,200);
292
- * ```
293
- */
294
- updatePosition(x, y) {
295
- try {
296
- return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { x, y }, "set-position");
297
- }
298
- catch (error) {
299
- throw this.errorHandler({ error });
300
- }
301
- }
302
- /**
303
- * @summary
304
- * Updates private zone options for a dropped asset.
305
- *
306
- * @usage
307
- * ```ts
308
- * await droppedAsset.updateMuteZone({
309
- * "isPrivateZone": false,
310
- * "isPrivateZoneChatDisabled": true,
311
- * "privateZoneUserCap": 10
312
- * });
313
- * ```
314
- */
315
- updatePrivateZone({ isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap, }) {
316
- try {
317
- return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap }, "set-private-zone");
318
- }
319
- catch (error) {
320
- throw this.errorHandler({ error });
321
- }
322
- }
323
- /**
324
- * @summary
325
- * Updates the size of a dropped asset.
326
- *
327
- * @usage
328
- * ```ts
329
- * await droppedAsset.assetScale(.5);
330
- * ```
331
- */
332
- updateScale(assetScale) {
333
- try {
334
- return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { assetScale }, "change-scale");
335
- }
336
- catch (error) {
337
- throw this.errorHandler({ error });
338
- }
339
- }
340
- /**
341
- * @summary
342
- * Change or remove media embedded in a dropped asset.
343
- *
344
- * @usage
345
- * ```ts
346
- * await droppedAsset.updateUploadedMediaSelected("LVWyxwNxI96eLjnXWwYO");
347
- * ```
348
- */
349
- updateUploadedMediaSelected(mediaId) {
350
- try {
351
- return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { mediaId }, "change-uploaded-media-selected");
352
- }
353
- catch (error) {
354
- throw this.errorHandler({ error });
355
- }
356
- }
357
- /**
358
- * @summary
359
- * Change or remove top and bottom layers of a dropped asset.
360
- *
361
- * @usage
362
- * ```ts
363
- * await droppedAsset.updateWebImageLayers("","https://www.shutterstock.com/image-vector/colorful-illustration-test-word-260nw-1438324490.jpg");
364
- * ```
365
- */
366
- updateWebImageLayers(bottom, top) {
367
- try {
368
- return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { bottom, top }, "set-webimage-layers");
369
- }
370
- catch (error) {
371
- throw this.errorHandler({ error });
372
- }
373
- }
374
- /**
375
- * @summary
376
- * Add a webhook to a dropped asset
377
- *
378
- * @usage
379
- * ```ts
380
- * await droppedAsset.addWebhook({
381
- * active: true,
382
- * dataObject: {},
383
- * description: "Webhook desc",
384
- * enteredBy: "you",
385
- * isUniqueOnly: false,
386
- * title: "title",
387
- * type: "type",
388
- * url: "https://url.com",
389
- * urlSlug: "world",
390
- * });
391
- * ```
392
- */
393
- addWebhook({ dataObject, description, isUniqueOnly, title, type, url, }) {
394
- return __awaiter(this, void 0, void 0, function* () {
395
- try {
396
- yield this.topiaPublicApi().post(`/world/${this.urlSlug}/webhooks`, {
397
- active: true,
398
- assetId: this.id,
399
- dataObject,
400
- description,
401
- enteredBy: "",
402
- isUniqueOnly,
403
- title,
404
- type,
405
- url,
406
- urlSlug: this.urlSlug,
407
- }, this.requestOptions);
408
- }
409
- catch (error) {
410
- throw this.errorHandler({ error });
411
- }
412
- });
413
- }
414
- /**
415
- * @summary
416
- * Set the interactive settings on a dropped asset
417
- *
418
- * @usage
419
- * ```ts
420
- * await droppedAsset.setInteractiveSettings({
421
- * isInteractive: true,
422
- * interactivePublicKey: "xyz"
423
- * });
424
- * ```
425
- */
426
- setInteractiveSettings({ isInteractive = false, interactivePublicKey = "", }) {
427
- return __awaiter(this, void 0, void 0, function* () {
428
- try {
429
- yield this.topiaPublicApi().put(`/world/${this.urlSlug}/assets/${this.id}/set-asset-interactive-settings`, {
430
- interactivePublicKey,
431
- isInteractive,
432
- }, this.requestOptions);
433
- this.isInteractive = isInteractive;
434
- this.interactivePublicKey = interactivePublicKey;
435
- }
436
- catch (error) {
437
- throw this.errorHandler({ error });
438
- }
439
- });
440
- }
441
- }
442
- _DroppedAsset_updateDroppedAsset = new WeakMap();
443
- export default DroppedAsset;
@@ -1,76 +0,0 @@
1
- // utils
2
- import jwt from "jsonwebtoken";
3
- import { AxiosError } from "axios";
4
- /**
5
- * @summary
6
- * Create an instance of SDKController class with credentials.
7
- *
8
- * @usage
9
- * ```ts
10
- * const credentials = {
11
- * assetId: "exampleAsset",
12
- * interactiveNonce: "exampleNonce"
13
- * interactivePublicKey: "examplePublicKey",
14
- * visitorId: 1,
15
- * url: "https://topia.io",
16
- * }
17
- * const topia = await new Topia({
18
- * apiDomain: "api.topia.io",
19
- * apiKey: "exampleKey",
20
- * interactiveKey: "key",
21
- * interactiveSecret: "secret",
22
- * }
23
- * await new SDKController({ credentials, topia });
24
- * ```
25
- */
26
- export class SDKController {
27
- constructor(topia, credentials = {}) {
28
- const { assetId, interactiveNonce, visitorId, apiKey } = credentials;
29
- this.topia = topia;
30
- this.credentials = credentials;
31
- this.requestOptions = {};
32
- let payload = {};
33
- const headers = {};
34
- if (visitorId && assetId && interactiveNonce) {
35
- payload = {
36
- interactiveNonce,
37
- visitorId,
38
- assetId,
39
- };
40
- this.jwt = jwt.sign(payload, topia.interactiveSecret);
41
- headers.InteractiveJWT = this.jwt;
42
- }
43
- if (apiKey) {
44
- headers.Authorization = apiKey;
45
- }
46
- this.requestOptions = { headers };
47
- }
48
- topiaPublicApi() {
49
- this.stackTrace = new Error("Thrown here:");
50
- return this.topia.axios;
51
- }
52
- errorHandler({ error, message = "Something went wrong. Please try again or contact support.", }) {
53
- var _a, _b, _c, _d;
54
- let data = {}, errorMessage = message, status = 500, url = "unknown", method = "unknown", stack = "empty";
55
- if (error instanceof AxiosError) {
56
- errorMessage = (error === null || error === void 0 ? void 0 : error.message) || message;
57
- if (error.response) {
58
- status = error.response.status;
59
- data = error.response.data;
60
- }
61
- if ((_a = error === null || error === void 0 ? void 0 : error.config) === null || _a === void 0 ? void 0 : _a.url)
62
- url = error.config.url;
63
- if ((_b = error === null || error === void 0 ? void 0 : error.config) === null || _b === void 0 ? void 0 : _b.method)
64
- method = error.config.method;
65
- if ((_c = this.stackTrace) === null || _c === void 0 ? void 0 : _c.stack)
66
- stack = `${error.stack}\n${this.stackTrace.stack}`;
67
- }
68
- else if (error instanceof Error) {
69
- errorMessage = (error === null || error === void 0 ? void 0 : error.message) || message;
70
- if ((_d = this.stackTrace) === null || _d === void 0 ? void 0 : _d.stack)
71
- stack = `${error.stack}\n${this.stackTrace.stack}`;
72
- }
73
- return { success: false, status, url, method, message: errorMessage, data, stack };
74
- }
75
- }
76
- export default SDKController;
@@ -1,39 +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
- // controllers
11
- import { SDKController } from "controllers/SDKController";
12
- /**
13
- * @summary
14
- * Create an instance of Scene class with a given scene id and optional attributes and session credentials.
15
- *
16
- * @usage
17
- * ```ts
18
- * await new Scene(topia, "sceneId", { attributes: { name: "My Scene" } });
19
- * ```
20
- */
21
- export class Scene extends SDKController {
22
- constructor(topia, id, options = { attributes: {}, credentials: {} }) {
23
- super(topia, options.credentials);
24
- this.id = id;
25
- Object.assign(this, options.attributes);
26
- }
27
- fetchSceneById() {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- try {
30
- const response = yield this.topiaPublicApi().get(`/scenes/${this.id}`, this.requestOptions);
31
- Object.assign(this, response.data);
32
- }
33
- catch (error) {
34
- throw this.errorHandler({ error });
35
- }
36
- });
37
- }
38
- }
39
- export default Scene;
@@ -1,39 +0,0 @@
1
- import axios from "axios";
2
- // utils
3
- import { getBrowserWarning } from "utils";
4
- /**
5
- * @summary
6
- * Create a single instance of Topia axios used for all calls to the public API in all classes
7
- *
8
- * @usage
9
- * ```ts
10
- * const topia = await new Topia({
11
- * apiDomain: "api.topia.io",
12
- * apiKey: "exampleKey",
13
- * interactiveKey: "key",
14
- * interactiveSecret: "secret",
15
- * });
16
- * ```
17
- */
18
- export class Topia {
19
- constructor({ apiDomain, apiKey, apiProtocol, interactiveKey, interactiveSecret, }) {
20
- getBrowserWarning();
21
- this.apiDomain = apiDomain || "api.topia.io";
22
- this.apiKey = apiKey;
23
- this.apiProtocol = apiProtocol || "https";
24
- this.interactiveSecret = interactiveSecret;
25
- const headers = {
26
- "ApplicationId": "sdk-js-topia",
27
- "Content-Type": "application/json",
28
- };
29
- if (apiKey)
30
- headers.Authorization = apiKey;
31
- if (interactiveKey)
32
- headers.PublicKey = interactiveKey;
33
- this.axios = axios.create({
34
- baseURL: `${this.apiProtocol}://${this.apiDomain}/api/v1`,
35
- headers,
36
- });
37
- }
38
- }
39
- export default Topia;