@rtsdk/topia 0.0.11 → 0.0.12

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 (83) hide show
  1. package/README.md +1 -1
  2. package/dist/controllers/Asset.js +19 -8
  3. package/dist/controllers/DroppedAsset.js +217 -33
  4. package/dist/controllers/SDKController.js +36 -0
  5. package/dist/controllers/Topia.js +32 -0
  6. package/dist/controllers/User.js +32 -17
  7. package/dist/controllers/Visitor.js +36 -12
  8. package/dist/controllers/World.js +172 -30
  9. package/dist/controllers/__tests__/asset.test.js +24 -10
  10. package/dist/controllers/__tests__/droppedAsset.test.js +18 -13
  11. package/dist/controllers/__tests__/user.test.js +33 -6
  12. package/dist/controllers/__tests__/visitor.test.js +27 -10
  13. package/dist/controllers/__tests__/world.test.js +26 -24
  14. package/dist/controllers/index.js +2 -0
  15. package/dist/example.js +32 -0
  16. package/dist/factories/AssetFactory.js +11 -0
  17. package/dist/factories/DroppedAssetFactory.js +26 -0
  18. package/dist/factories/UserFactory.js +10 -0
  19. package/dist/factories/VisitorFactory.js +10 -0
  20. package/dist/factories/WorldFactory.js +10 -0
  21. package/dist/factories/index.js +5 -0
  22. package/dist/index.js +13 -2
  23. package/dist/interfaces/SDKInterfaces.js +1 -0
  24. package/dist/interfaces/TopiaInterfaces.js +1 -0
  25. package/dist/interfaces/UserInterfaces.js +1 -0
  26. package/dist/interfaces/index.js +3 -0
  27. package/dist/src/__mocks__/assets.js +241 -0
  28. package/dist/src/__mocks__/index.js +4 -0
  29. package/dist/src/__mocks__/scenes.js +104 -0
  30. package/dist/src/__mocks__/visitors.js +83 -0
  31. package/dist/src/__mocks__/worlds.js +52 -0
  32. package/dist/src/controllers/Asset.js +39 -0
  33. package/dist/src/controllers/DroppedAsset.js +358 -0
  34. package/dist/src/controllers/SDKController.js +43 -0
  35. package/dist/src/controllers/Topia.js +35 -0
  36. package/dist/src/controllers/User.js +113 -0
  37. package/dist/src/controllers/Visitor.js +62 -0
  38. package/dist/src/controllers/World.js +319 -0
  39. package/dist/src/controllers/__tests__/asset.test.js +36 -0
  40. package/dist/src/controllers/__tests__/droppedAsset.test.js +97 -0
  41. package/dist/src/controllers/__tests__/user.test.js +49 -0
  42. package/dist/src/controllers/__tests__/visitor.test.js +40 -0
  43. package/dist/src/controllers/__tests__/world.test.js +80 -0
  44. package/dist/src/controllers/index.js +7 -0
  45. package/dist/src/factories/AssetFactory.js +11 -0
  46. package/dist/src/factories/DroppedAssetFactory.js +26 -0
  47. package/dist/src/factories/UserFactory.js +10 -0
  48. package/dist/src/factories/VisitorFactory.js +10 -0
  49. package/dist/src/factories/WorldFactory.js +10 -0
  50. package/dist/src/factories/index.js +5 -0
  51. package/dist/src/index.js +2 -0
  52. package/dist/src/interfaces/AssetInterfaces.js +1 -0
  53. package/dist/src/interfaces/DroppedAssetInterfaces.js +1 -0
  54. package/dist/src/interfaces/SDKInterfaces.js +1 -0
  55. package/dist/src/interfaces/TopiaInterfaces.js +1 -0
  56. package/dist/src/interfaces/UserInterfaces.js +1 -0
  57. package/dist/src/interfaces/VisitorInterfaces.js +1 -0
  58. package/dist/src/interfaces/WorldInterfaces.js +1 -0
  59. package/dist/src/interfaces/index.js +7 -0
  60. package/dist/src/types/DroppedAssetTypes.js +12 -0
  61. package/dist/src/types/InteractiveCredentialsTypes.js +1 -0
  62. package/dist/src/types/OptionsTypes.js +1 -0
  63. package/dist/src/types/ResponseTypes.js +1 -0
  64. package/dist/src/types/VisitorTypes.js +1 -0
  65. package/dist/src/types/index.js +4 -0
  66. package/dist/src/utils/__tests__/removeUndefined.test.js +10 -0
  67. package/dist/src/utils/__tests__/scatterVisitors.test.js +11 -0
  68. package/dist/src/utils/getBrowserWarning.js +5 -0
  69. package/dist/src/utils/getErrorMessage.js +5 -0
  70. package/dist/src/utils/getErrorResponse.js +20 -0
  71. package/dist/src/utils/getSuccessResponse.js +3 -0
  72. package/dist/src/utils/index.js +4 -0
  73. package/dist/src/utils/removeUndefined.js +11 -0
  74. package/dist/src/utils/scatterVisitors.js +8 -0
  75. package/dist/types/InteractiveCredentialsTypes.js +1 -0
  76. package/dist/types/OptionsTypes.js +1 -0
  77. package/dist/types/index.js +1 -0
  78. package/dist/utils/getErrorMessage.js +3 -1
  79. package/dist/utils/publicAPI.js +3 -0
  80. package/dist/utils/removeUndefined.js +3 -0
  81. package/dist/utils/scatterVisitors.js +3 -0
  82. package/package.json +3 -1
  83. package/dist/utils/createDroppedAsset.js +0 -72
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Javascript RTSDK - Topia Client Library
2
2
 
3
- The Topia Client Library leverages the Topia Public API and allows users to interact with the topia systems and modify their world programmatically.
3
+ The Topia Client Library leverages the Topia Public API and allows users to interact with the topia systems and modify their world programmatically. With the SDK you can now build new features to be used in Topia! Check out a few awesome examples [here](https://sdk-examples.metaversecloud.com/).
4
4
 
5
5
  ## Get Started
6
6
 
@@ -1,13 +1,24 @@
1
- import { getErrorMessage, publicAPI } from "utils";
2
- export class Asset {
3
- constructor({ apiKey, args }) {
4
- this.apiKey = apiKey;
5
- Object.assign(this, args);
1
+ // controllers
2
+ import { SDKController } from "controllers/SDKController";
3
+ // utils
4
+ import { getErrorMessage } from "utils";
5
+ /**
6
+ * Create an instance of Asset class with a given apiKey and optional arguments.
7
+ *
8
+ * ```ts
9
+ * await new Asset({ args: { assetName: "My Asset", isPublic: false } });
10
+ * ```
11
+ */
12
+ export class Asset extends SDKController {
13
+ constructor(topia, id, options = { args: {}, creds: {} }) {
14
+ super(topia, options.creds);
15
+ this.id = id;
16
+ Object.assign(this, options.args);
6
17
  }
7
- fetchAssetsByEmail(ownerEmail) {
18
+ fetchPlatformAssets() {
8
19
  return new Promise((resolve, reject) => {
9
- publicAPI(this.apiKey)
10
- .get(`/assets/my-assets?email=${ownerEmail}`)
20
+ this.topia.axios
21
+ .get("/assets/topia-assets", this.requestOptions)
11
22
  .then((response) => {
12
23
  resolve(response.data);
13
24
  })
@@ -1,19 +1,23 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- 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");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var _DroppedAsset_updateDroppedAsset;
7
- import { getErrorMessage, publicAPI } from "utils";
8
- import Asset from "./Asset";
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
+ */
9
12
  export class DroppedAsset extends Asset {
10
- constructor({ apiKey, id, args, urlSlug, }) {
11
- super({ apiKey, args });
13
+ constructor(topia, id, urlSlug, options = { args: { text: "" }, creds: {} }) {
14
+ var _a;
15
+ super(topia, id, options);
12
16
  // update dropped assets
13
- _DroppedAsset_updateDroppedAsset.set(this, (payload, updateType) => {
17
+ this.updateDroppedAsset = (payload, updateType) => {
14
18
  return new Promise((resolve, reject) => {
15
- publicAPI(this.apiKey)
16
- .put(`/world/${this.urlSlug}/assets/${this.id}/${updateType}`, Object.assign({}, payload))
19
+ this.topia.axios
20
+ .put(`/world/${this.urlSlug}/assets/${this.id}/${updateType}`, Object.assign({}, payload), this.requestOptions)
17
21
  .then(() => {
18
22
  resolve("Success!");
19
23
  })
@@ -21,19 +25,27 @@ export class DroppedAsset extends Asset {
21
25
  reject(new Error(getErrorMessage(error)));
22
26
  });
23
27
  });
24
- });
25
- Object.assign(this, args);
26
- this.apiKey = apiKey;
28
+ };
27
29
  this.id = id;
28
- this.text = args.text;
30
+ this.text = (_a = options.args) === null || _a === void 0 ? void 0 : _a.text;
29
31
  this.urlSlug = urlSlug;
30
- this.updateCustomText;
32
+ Object.assign(this, options.args);
31
33
  }
34
+ /**
35
+ * @summary
36
+ * Retrieves dropped asset details.
37
+ *
38
+ * @usage
39
+ * ```ts
40
+ * await droppedAsset.fetchDroppedAssetById();
41
+ * const { assetName } = droppedAsset;
42
+ * ```
43
+ */
32
44
  // get dropped asset
33
45
  fetchDroppedAssetById() {
34
46
  return new Promise((resolve, reject) => {
35
- publicAPI(this.apiKey)
36
- .get(`/world/${this.urlSlug}/assets/${this.id}`)
47
+ this.topia.axios
48
+ .get(`/world/${this.urlSlug}/assets/${this.id}`, this.requestOptions)
37
49
  .then((response) => {
38
50
  Object.assign(this, response.data);
39
51
  resolve("Success!");
@@ -46,9 +58,59 @@ export class DroppedAsset extends Asset {
46
58
  // delete dropped asset
47
59
  deleteDroppedAsset() {
48
60
  return new Promise((resolve, reject) => {
49
- publicAPI(this.apiKey)
50
- .delete(`/world/${this.urlSlug}/assets/${this.id}`)
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)
51
112
  .then(() => {
113
+ this.dataObject = dataObject;
52
114
  resolve("Success!");
53
115
  })
54
116
  .catch((error) => {
@@ -56,90 +118,213 @@ export class DroppedAsset extends Asset {
56
118
  });
57
119
  });
58
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
+ */
59
134
  updateBroadcast({ assetBroadcast, assetBroadcastAll, broadcasterEmail }) {
60
135
  return new Promise((resolve, reject) => {
61
- return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { assetBroadcast, assetBroadcastAll, broadcasterEmail }, "set-asset-broadcast")
136
+ return this.updateDroppedAsset({ assetBroadcast, assetBroadcastAll, broadcasterEmail }, "set-asset-broadcast")
62
137
  .then(resolve)
63
138
  .catch((error) => {
64
139
  reject(new Error(getErrorMessage(error)));
65
140
  });
66
141
  });
67
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
+ */
68
161
  updateClickType({ clickType, clickableLink, clickableLinkTitle, portalName, position, }) {
69
162
  return new Promise((resolve, reject) => {
70
- return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { clickType, clickableLink, clickableLinkTitle, portalName, position }, "change-click-type")
163
+ return this.updateDroppedAsset({ clickType, clickableLink, clickableLinkTitle, portalName, position }, "change-click-type")
71
164
  .then(resolve)
72
165
  .catch((error) => {
73
166
  reject(new Error(getErrorMessage(error)));
74
167
  });
75
168
  });
76
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
+ */
77
186
  updateCustomText(style, text) {
78
187
  return new Promise((resolve, reject) => {
79
- return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { style, text }, "set-custom-text")
188
+ return this.updateDroppedAsset({ style, text }, "set-custom-text")
80
189
  .then(resolve)
81
190
  .catch((error) => {
82
191
  reject(new Error(getErrorMessage(error)));
83
192
  });
84
193
  });
85
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
+ */
86
213
  updateMediaType({ audioRadius, audioVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia, }) {
87
214
  return new Promise((resolve, reject) => {
88
- return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { audioRadius, audioVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia }, "change-media-type")
215
+ return this.updateDroppedAsset({ audioRadius, audioVolume, isVideo, mediaLink, mediaName, mediaType, portalName, syncUserMedia }, "change-media-type")
89
216
  .then(resolve)
90
217
  .catch((error) => {
91
218
  reject(new Error(getErrorMessage(error)));
92
219
  });
93
220
  });
94
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
+ */
95
231
  updateMuteZone(isMutezone) {
96
232
  return new Promise((resolve, reject) => {
97
- return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { isMutezone }, "set-mute-zone")
233
+ return this.updateDroppedAsset({ isMutezone }, "set-mute-zone")
98
234
  .then(resolve)
99
235
  .catch((error) => {
100
236
  reject(new Error(getErrorMessage(error)));
101
237
  });
102
238
  });
103
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
+ */
104
249
  updatePosition(x, y) {
105
250
  return new Promise((resolve, reject) => {
106
- return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { x, y }, "set-position")
251
+ return this.updateDroppedAsset({ x, y }, "set-position")
107
252
  .then(resolve)
108
253
  .catch((error) => {
109
254
  reject(new Error(getErrorMessage(error)));
110
255
  });
111
256
  });
112
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
+ */
113
271
  updatePrivateZone({ isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap, }) {
114
272
  return new Promise((resolve, reject) => {
115
- return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap }, "set-private-zone")
273
+ return this.updateDroppedAsset({ isPrivateZone, isPrivateZoneChatDisabled, privateZoneUserCap }, "set-private-zone")
116
274
  .then(resolve)
117
275
  .catch((error) => {
118
276
  reject(new Error(getErrorMessage(error)));
119
277
  });
120
278
  });
121
279
  }
280
+ /**
281
+ * @summary
282
+ * Updates the size of a dropped asset.
283
+ *
284
+ * @usage
285
+ * ```ts
286
+ * await droppedAsset.assetScale(.5);
287
+ * ```
288
+ */
122
289
  updateScale(assetScale) {
123
290
  return new Promise((resolve, reject) => {
124
- return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { assetScale }, "change-scale")
291
+ return this.updateDroppedAsset({ assetScale }, "change-scale")
125
292
  .then(resolve)
126
293
  .catch((error) => {
127
294
  reject(new Error(getErrorMessage(error)));
128
295
  });
129
296
  });
130
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
+ */
131
307
  updateUploadedMediaSelected(mediaId) {
132
308
  return new Promise((resolve, reject) => {
133
- return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { mediaId }, "change-uploaded-media-selected")
309
+ return this.updateDroppedAsset({ mediaId }, "change-uploaded-media-selected")
134
310
  .then(resolve)
135
311
  .catch((error) => {
136
312
  reject(new Error(getErrorMessage(error)));
137
313
  });
138
314
  });
139
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
+ */
140
325
  updateWebImageLayers(bottom, top) {
141
326
  return new Promise((resolve, reject) => {
142
- return __classPrivateFieldGet(this, _DroppedAsset_updateDroppedAsset, "f").call(this, { bottom, top }, "set-webimage-layers")
327
+ return this.updateDroppedAsset({ bottom, top }, "set-webimage-layers")
143
328
  .then(resolve)
144
329
  .catch((error) => {
145
330
  reject(new Error(getErrorMessage(error)));
@@ -147,5 +332,4 @@ export class DroppedAsset extends Asset {
147
332
  });
148
333
  }
149
334
  }
150
- _DroppedAsset_updateDroppedAsset = new WeakMap();
151
335
  export default DroppedAsset;
@@ -0,0 +1,36 @@
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;
@@ -0,0 +1,32 @@
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;
@@ -10,20 +10,23 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _User_worldsMap;
13
+ // controllers
14
+ import { SDKController } from "controllers/SDKController";
13
15
  import { World } from "controllers/World";
14
- import { getErrorMessage, publicAPI } from "utils";
16
+ // utils
17
+ import { getErrorMessage } from "utils";
15
18
  /**
16
- * Create an instance of User class with a given apiKey
19
+ * Create an instance of User class with a given apiKey.
17
20
  *
18
21
  * ```ts
19
- * await new User({ apiKey: API_KEY, email: "example@email.io" })
22
+ * await new User({ email: "example@email.io" });
20
23
  * ```
21
24
  */
22
- export class User {
23
- constructor({ apiKey, email }) {
25
+ export class User extends SDKController {
26
+ constructor(topia, email, options = { creds: {} }) {
27
+ super(topia, options.creds);
24
28
  _User_worldsMap.set(this, void 0);
25
29
  __classPrivateFieldSet(this, _User_worldsMap, {}, "f");
26
- this.apiKey = apiKey;
27
30
  this.email = email;
28
31
  }
29
32
  get worlds() {
@@ -31,14 +34,30 @@ export class User {
31
34
  }
32
35
  /**
33
36
  * @summary
34
- * Returns all scenes owned by User when an email address is provided
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.
35
54
  */
36
55
  fetchScenesByEmail() {
37
56
  return new Promise((resolve, reject) => {
38
57
  if (!this.email)
39
58
  reject("There is no email associated with this user.");
40
- publicAPI(this.apiKey)
41
- .get(`/scenes/my-scenes?email=${this.email}`)
59
+ this.topia.axios
60
+ .get(`/scenes/my-scenes?email=${this.email}`, this.requestOptions)
42
61
  .then((response) => {
43
62
  resolve(response.data);
44
63
  })
@@ -51,7 +70,7 @@ export class User {
51
70
  * @summary
52
71
  * Retrieves all worlds owned by user with matching API Key,
53
72
  * creates a new World object for each,
54
- * and creates new map of Worlds accessible via user.worlds
73
+ * and creates new map of Worlds accessible via user.worlds.
55
74
  *
56
75
  * @usage
57
76
  * ```ts
@@ -66,17 +85,13 @@ export class User {
66
85
  */
67
86
  fetchWorldsByKey() {
68
87
  return new Promise((resolve, reject) => {
69
- publicAPI(this.apiKey)
70
- .get("/user/worlds")
88
+ this.topia.axios
89
+ .get("/user/worlds", this.requestOptions)
71
90
  .then((response) => {
72
91
  const tempWorldsMap = {};
73
92
  for (const i in response.data) {
74
93
  const worldDetails = response.data[i];
75
- tempWorldsMap[worldDetails.urlSlug] = new World({
76
- apiKey: this.apiKey,
77
- args: worldDetails,
78
- urlSlug: worldDetails.urlSlug,
79
- });
94
+ tempWorldsMap[worldDetails.urlSlug] = new World(this.topia, worldDetails.urlSlug, { args: worldDetails });
80
95
  }
81
96
  __classPrivateFieldSet(this, _User_worldsMap, tempWorldsMap, "f");
82
97
  resolve("Success!");
@@ -1,25 +1,49 @@
1
- import { getErrorMessage, publicAPI } from "utils";
2
- export class Visitor {
3
- constructor({ apiKey, args, urlSlug }) {
4
- Object.assign(this, args);
5
- this.apiKey = apiKey;
6
- this.moveTo = args.moveTo;
7
- this.playerId = args.playerId;
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;
8
17
  this.urlSlug = urlSlug;
9
18
  this.moveVisitor;
10
19
  }
11
- moveVisitor(shouldTeleportVisitor, x, y) {
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 }) {
12
37
  return new Promise((resolve, reject) => {
13
- publicAPI(this.apiKey)
14
- .put(`/world/${this.urlSlug}/visitors/${this.playerId}/move`, {
38
+ this.topia.axios
39
+ .put(`/world/${this.urlSlug}/visitors/${this.id}/move`, {
15
40
  moveTo: {
16
41
  x,
17
42
  y,
18
43
  },
19
44
  teleport: shouldTeleportVisitor,
20
- })
45
+ }, this.requestOptions)
21
46
  .then(() => {
22
- this.moveTo = { x, y };
23
47
  resolve("Success!");
24
48
  })
25
49
  .catch((error) => {