@rtsdk/topia 0.0.10 → 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 +19 -0
  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 +56 -13
  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 -18283
  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 +5 -1
  83. package/dist/utils/createDroppedAsset.js +0 -72
@@ -19,17 +19,27 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
19
19
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
20
  };
21
21
  var _World_droppedAssetsMap, _World_visitorsMap;
22
- import { getErrorMessage, publicAPI, removeUndefined, scatterVisitors } from "utils";
22
+ // controllers
23
23
  import { DroppedAsset } from "controllers/DroppedAsset";
24
+ import { SDKController } from "controllers/SDKController";
24
25
  import { Visitor } from "controllers/Visitor";
25
- export class World {
26
- constructor({ apiKey, args, urlSlug }) {
26
+ // utils
27
+ import { getErrorMessage, removeUndefined, scatterVisitors } from "utils";
28
+ /**
29
+ * Create an instance of World class with a given apiKey and optional arguments.
30
+ *
31
+ * ```ts
32
+ * await new World({ urlSlug: "magic" });
33
+ * ```
34
+ */
35
+ export class World extends SDKController {
36
+ constructor(topia, urlSlug, options = { args: {}, creds: {} }) {
37
+ super(topia, options.creds);
27
38
  _World_droppedAssetsMap.set(this, void 0);
28
39
  _World_visitorsMap.set(this, void 0);
29
- Object.assign(this, args);
40
+ Object.assign(this, options.args);
30
41
  __classPrivateFieldSet(this, _World_droppedAssetsMap, {}, "f");
31
42
  __classPrivateFieldSet(this, _World_visitorsMap, {}, "f");
32
- this.apiKey = apiKey;
33
43
  this.urlSlug = urlSlug;
34
44
  }
35
45
  get droppedAssets() {
@@ -38,11 +48,21 @@ export class World {
38
48
  get visitors() {
39
49
  return __classPrivateFieldGet(this, _World_visitorsMap, "f");
40
50
  }
51
+ /**
52
+ * @summary
53
+ * Retrieves details of a world.
54
+ *
55
+ * @usage
56
+ * ```ts
57
+ * await world.fetchDetails();
58
+ * const { name } = world;
59
+ * ```
60
+ */
41
61
  // world details
42
62
  fetchDetails() {
43
63
  return new Promise((resolve, reject) => {
44
- publicAPI(this.apiKey)
45
- .get(`/world/${this.urlSlug}/world-details`)
64
+ this.topia.axios
65
+ .get(`/world/${this.urlSlug}/world-details`, this.requestOptions)
46
66
  .then((response) => {
47
67
  Object.assign(this, response.data);
48
68
  resolve("Success!");
@@ -52,6 +72,28 @@ export class World {
52
72
  });
53
73
  });
54
74
  }
75
+ /**
76
+ * @summary
77
+ * Update details of a world.
78
+ *
79
+ * @usage
80
+ * ```ts
81
+ * await world.updateDetails({
82
+ * controls: {
83
+ * allowMuteAll: true,
84
+ * disableHideVideo: true,
85
+ * isMobileDisabled: false,
86
+ * isShowingCurrentGuests: false,
87
+ * },
88
+ * description: 'Welcome to my world.',
89
+ * forceAuthOnLogin: false,
90
+ * height: 2000,
91
+ * name: 'Example',
92
+ * spawnPosition: { x: 100, y: 100 },
93
+ * width: 2000
94
+ * });
95
+ * ```
96
+ */
55
97
  updateDetails({ controls, description, forceAuthOnLogin, height, name, spawnPosition, width, }) {
56
98
  const payload = {
57
99
  controls,
@@ -63,8 +105,8 @@ export class World {
63
105
  width,
64
106
  };
65
107
  return new Promise((resolve, reject) => {
66
- publicAPI(this.apiKey)
67
- .put(`/world/${this.urlSlug}/world-details`, payload)
108
+ this.topia.axios
109
+ .put(`/world/${this.urlSlug}/world-details`, payload, this.requestOptions)
68
110
  .then(() => {
69
111
  const cleanPayload = removeUndefined(payload);
70
112
  Object.assign(this, cleanPayload);
@@ -78,16 +120,14 @@ export class World {
78
120
  // visitors
79
121
  fetchVisitors() {
80
122
  return new Promise((resolve, reject) => {
81
- publicAPI(this.apiKey)
82
- .get(`/world/${this.urlSlug}/visitors`)
123
+ this.topia.axios
124
+ .get(`/world/${this.urlSlug}/visitors`, this.requestOptions)
83
125
  .then((response) => {
84
126
  // create temp map and then update private property only once
85
127
  const tempVisitorsMap = {};
86
- for (const playerId in response.data) {
87
- tempVisitorsMap[playerId] = new Visitor({
88
- apiKey: this.apiKey,
89
- args: response.data[playerId],
90
- urlSlug: this.urlSlug,
128
+ for (const id in response.data) {
129
+ tempVisitorsMap[id] = new Visitor(this.topia, response.data[id].playerId, this.urlSlug, {
130
+ args: response.data[id],
91
131
  });
92
132
  }
93
133
  __classPrivateFieldSet(this, _World_visitorsMap, tempVisitorsMap, "f");
@@ -98,6 +138,15 @@ export class World {
98
138
  });
99
139
  });
100
140
  }
141
+ /**
142
+ * @summary
143
+ * Retrieve all visitors currently in a world.
144
+ *
145
+ * @usage
146
+ * ```ts
147
+ * const visitors = await world.currentVisitors();
148
+ * ```
149
+ */
101
150
  currentVisitors() {
102
151
  return __awaiter(this, void 0, void 0, function* () {
103
152
  try {
@@ -109,6 +158,26 @@ export class World {
109
158
  }
110
159
  });
111
160
  }
161
+ /**
162
+ * @summary
163
+ * Move all visitors currently in a world to a single set of coordinates.
164
+ * Optionally refetch visitors, teleport or walk visitors to new location,
165
+ * and scatter visitors by any number so that they don't all move to the exact same location.
166
+ *
167
+ * @usage
168
+ * ```ts
169
+ * await world.moveAllVisitors({
170
+ * shouldFetchVisitors: true,
171
+ * shouldTeleportVisitors: true,
172
+ * scatterVisitorsBy: 40,
173
+ * x: 100,
174
+ * y: 100,
175
+ * });
176
+ * ```
177
+ *
178
+ * @result
179
+ * Updates each Visitor instance and world.visitors map.
180
+ */
112
181
  moveAllVisitors({ shouldFetchVisitors = true, shouldTeleportVisitors = true, scatterVisitorsBy = 0, x, y, }) {
113
182
  return __awaiter(this, void 0, void 0, function* () {
114
183
  if (shouldFetchVisitors)
@@ -117,49 +186,105 @@ export class World {
117
186
  if (!this.visitors)
118
187
  return;
119
188
  const objectKeys = Object.keys(this.visitors);
120
- objectKeys.forEach((key) => allPromises.push(__classPrivateFieldGet(this, _World_visitorsMap, "f")[key].moveVisitor(shouldTeleportVisitors, scatterVisitors(x, scatterVisitorsBy), scatterVisitors(y, scatterVisitorsBy))));
189
+ objectKeys.forEach((key) => allPromises.push(__classPrivateFieldGet(this, _World_visitorsMap, "f")[key].moveVisitor({
190
+ shouldTeleportVisitor: shouldTeleportVisitors,
191
+ x: scatterVisitors(x, scatterVisitorsBy),
192
+ y: scatterVisitors(y, scatterVisitorsBy),
193
+ })));
121
194
  const outcomes = yield Promise.allSettled(allPromises);
122
195
  return outcomes;
123
196
  });
124
197
  }
198
+ /**
199
+ * @summary
200
+ * Teleport or walk a list of visitors currently in a world to various coordinates.
201
+ *
202
+ * @usage
203
+ * ```ts
204
+ * const visitorsToMove = [
205
+ * {
206
+ * visitorObj: world.visitors["1"],
207
+ * shouldTeleportVisitor: true,
208
+ * x: 100,
209
+ * y: 100
210
+ * }, {
211
+ * visitorObj: world.visitors["2"],
212
+ * shouldTeleportVisitor: false,
213
+ * x: 100,
214
+ * y: 100
215
+ * }
216
+ * ];
217
+ * await world.moveVisitors(visitorsToMove);
218
+ * ```
219
+ *
220
+ * @result
221
+ * Updates each Visitor instance and world.visitors map.
222
+ */
125
223
  moveVisitors(visitorsToMove) {
126
224
  return __awaiter(this, void 0, void 0, function* () {
127
225
  const allPromises = [];
128
226
  visitorsToMove.forEach((v) => {
129
- allPromises.push(v.visitorObj.moveVisitor(v.shouldTeleportVisitor, v.x, v.y));
227
+ allPromises.push(v.visitorObj.moveVisitor({ shouldTeleportVisitor: v.shouldTeleportVisitor, x: v.x, y: v.y }));
130
228
  });
131
229
  const outcomes = yield Promise.allSettled(allPromises);
132
230
  return outcomes;
133
231
  });
134
232
  }
233
+ /**
234
+ * @summary
235
+ * Retrieve all assets dropped in a world.
236
+ *
237
+ * @usage
238
+ * ```ts
239
+ * await world.fetchDroppedAssets();
240
+ * const assets = world.droppedAssets;
241
+ * ```
242
+ */
135
243
  // dropped assets
136
244
  fetchDroppedAssets() {
137
245
  return new Promise((resolve, reject) => {
138
- publicAPI(this.apiKey)
139
- .get(`/world/${this.urlSlug}/assets`)
246
+ this.topia.axios
247
+ .get(`/world/${this.urlSlug}/assets`, this.requestOptions)
140
248
  .then((response) => {
141
249
  // create temp map and then update private property only once
142
250
  const tempDroppedAssetsMap = {};
143
- for (const id in response.data) {
251
+ for (const index in response.data) {
144
252
  // tempDroppedAssetsMap[id] = createDroppedAsset(this.apiKey, response.data[id], this.urlSlug);
145
- tempDroppedAssetsMap[id] = new DroppedAsset({
146
- apiKey: this.apiKey,
147
- id,
148
- args: response.data[id],
149
- urlSlug: this.urlSlug,
253
+ tempDroppedAssetsMap[index] = new DroppedAsset(this.topia, response.data[index].id, this.urlSlug, {
254
+ args: response.data[index],
150
255
  });
151
256
  }
152
257
  __classPrivateFieldSet(this, _World_droppedAssetsMap, tempDroppedAssetsMap, "f");
153
258
  resolve("Success!");
154
259
  })
155
260
  .catch((error) => {
156
- reject(new Error(getErrorMessage(error)));
261
+ reject(getErrorMessage(error));
262
+ // reject(new Error(getErrorMessage(error)));
157
263
  });
158
264
  });
159
265
  }
266
+ /**
267
+ * @summary
268
+ * Update multiple custom text dropped assets with a single style while preserving text for specified dropped assets only.
269
+ *
270
+ * @usage
271
+ * ```ts
272
+ * const droppedAssetsToUpdate = [world.droppedAssets["6"], world.droppedAssets["12"]];
273
+ * const style = {
274
+ * "textColor": "#abc123",
275
+ * "textFontFamily": "Arial",
276
+ * "textSize": 40,
277
+ * "textWeight": "normal",
278
+ * "textWidth": 200
279
+ * };
280
+ * await world.moveVisitors(droppedAssetsToUpdate, style);
281
+ * ```
282
+ *
283
+ * @result
284
+ * Updates each DroppedAsset instance and world.droppedAssets map.
285
+ */
160
286
  updateCustomTextDroppedAssets(droppedAssetsToUpdate, style) {
161
287
  return __awaiter(this, void 0, void 0, function* () {
162
- // adds ability to update any styles for specified dropped assets only while preserving text
163
288
  const allPromises = [];
164
289
  droppedAssetsToUpdate.forEach((a) => {
165
290
  allPromises.push(a.updateCustomText(style, a.text));
@@ -168,11 +293,28 @@ export class World {
168
293
  return outcomes;
169
294
  });
170
295
  }
296
+ /**
297
+ * @summary
298
+ * Replace the current scene of a world.
299
+ *
300
+ * @usage
301
+ * ```ts
302
+ * const droppedAssetsToUpdate = [world.droppedAssets["6"], world.droppedAssets["12"]]
303
+ * const style = {
304
+ * "textColor": "#abc123",
305
+ * "textFontFamily": "Arial",
306
+ * "textSize": 40,
307
+ * "textWeight": "normal",
308
+ * "textWidth": 200
309
+ * }
310
+ * await world.replaceScene(SCENE_ID);
311
+ * ```
312
+ */
171
313
  // scenes
172
314
  replaceScene(sceneId) {
173
315
  return new Promise((resolve, reject) => {
174
- publicAPI(this.apiKey)
175
- .put(`/world/${this.urlSlug}/change-scene`, { sceneId })
316
+ this.topia.axios
317
+ .put(`/world/${this.urlSlug}/change-scene`, { sceneId }, this.requestOptions)
176
318
  .then(() => {
177
319
  resolve("Success!");
178
320
  })
@@ -7,17 +7,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { assets } from "../../__mocks__";
11
- import { Asset } from "..";
12
- afterEach(() => {
13
- jest.resetAllMocks();
14
- });
10
+ import axios from "axios";
11
+ import MockAdapter from "axios-mock-adapter";
12
+ import { AssetFactory } from "factories";
13
+ import { Topia } from "controllers/Topia";
14
+ const apiDomain = "api.topia.io";
15
15
  describe("Asset Class", () => {
16
+ let Asset, mock, testAsset, topia;
17
+ beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
18
+ mock = new MockAdapter(axios);
19
+ topia = new Topia({
20
+ apiDomain: "api.topia.io",
21
+ apiKey: "exampleKey",
22
+ interactiveKey: "key",
23
+ interactiveSecret: "secret",
24
+ });
25
+ Asset = new AssetFactory(topia);
26
+ testAsset = Asset.create("test");
27
+ }));
28
+ afterEach(() => {
29
+ mock.restore();
30
+ jest.resetAllMocks();
31
+ });
16
32
  it("should return an array of assets owned by specific email address", () => __awaiter(void 0, void 0, void 0, function* () {
17
- const testAsset = new Asset({ apiKey: "key", args: { id: "abc123" } });
18
- testAsset.fetchAssetsByEmail = jest.fn().mockReturnValue(assets);
19
- const mockAssets = yield testAsset.fetchAssetsByEmail("lina@topia.io");
20
- expect(testAsset.fetchAssetsByEmail).toHaveBeenCalled();
21
- expect(mockAssets).toBeDefined();
33
+ mock.onGet(`https://${apiDomain}/api/assets/topia-assets`).reply(200, "Success!");
34
+ yield testAsset.fetchPlatformAssets();
35
+ expect(mock.history.get.length).toBe(1);
22
36
  }));
23
37
  });
@@ -8,30 +8,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { droppedAssets } from "__mocks__";
11
- import { DroppedAsset } from "..";
12
- import { DroppedAssetClickType, DroppedAssetMediaType } from "../../types/DroppedAssetTypes";
11
+ import { Topia } from "controllers";
12
+ import { DroppedAssetClickType, DroppedAssetMediaType } from "types/DroppedAssetTypes";
13
13
  import axios from "axios";
14
14
  import MockAdapter from "axios-mock-adapter";
15
- const BASE_URL = `https://api.topia.io/api/world/magic/assets/${droppedAssets[0].id}`;
16
- const apiKey = "key";
15
+ import { DroppedAssetFactory } from "factories";
16
+ const apiDomain = "api.topia.io";
17
17
  const args = droppedAssets[0];
18
+ const BASE_URL = `https://api.topia.io/api/world/magic/assets/${droppedAssets[0].id}`;
18
19
  const id = droppedAssets[0].id;
19
- const urlSlug = "magic";
20
20
  describe("DroppedAsset Class", () => {
21
- let mock, testDroppedAsset;
22
- beforeEach(() => {
21
+ let DroppedAsset, mock, testDroppedAsset, topia;
22
+ beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
23
23
  mock = new MockAdapter(axios);
24
- testDroppedAsset = new DroppedAsset({ apiKey, id, args, urlSlug });
25
- });
24
+ topia = new Topia({
25
+ apiDomain,
26
+ apiKey: "key",
27
+ });
28
+ DroppedAsset = new DroppedAssetFactory(topia);
29
+ testDroppedAsset = yield DroppedAsset.create(id, "magic");
30
+ }));
26
31
  afterEach(() => {
27
32
  mock.restore();
28
33
  jest.resetAllMocks();
29
34
  });
30
35
  it("should fetch dropped asset by id", () => __awaiter(void 0, void 0, void 0, function* () {
31
- testDroppedAsset.fetchDroppedAssetById = jest.fn().mockReturnValue(droppedAssets[0]);
32
- const mockDroppedAssets = yield testDroppedAsset.fetchDroppedAssetById();
33
- expect(testDroppedAsset.fetchDroppedAssetById).toHaveBeenCalled();
34
- expect(mockDroppedAssets).toBeDefined();
36
+ mock.onGet(BASE_URL).reply(200, droppedAssets[0]);
37
+ yield testDroppedAsset.fetchDroppedAssetById();
38
+ expect(mock.history.get.length).toBe(1);
39
+ expect(testDroppedAsset.urlSlug).toBeDefined();
35
40
  }));
36
41
  it("should update dropped asset broadcast zone", () => __awaiter(void 0, void 0, void 0, function* () {
37
42
  mock.onPut(`${BASE_URL}/set-asset-broadcast`).reply(200, "Success!");
@@ -7,17 +7,44 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { scenes } from "__mocks__";
11
- import { User } from "controllers";
12
- afterEach(() => {
13
- jest.resetAllMocks();
14
- });
10
+ import axios from "axios";
11
+ import MockAdapter from "axios-mock-adapter";
12
+ import { droppedAssets, scenes, worlds } from "__mocks__";
13
+ import { Topia } from "controllers";
14
+ import { UserFactory } from "factories";
15
+ const apiDomain = "api.topia.io";
16
+ const email = "test@email.com";
15
17
  describe("User Class", () => {
18
+ let mock, testUser, topia, User;
19
+ beforeEach(() => {
20
+ mock = new MockAdapter(axios);
21
+ topia = new Topia({
22
+ apiDomain,
23
+ apiKey: "key",
24
+ });
25
+ User = new UserFactory(topia);
26
+ testUser = User.create(email);
27
+ });
28
+ afterEach(() => {
29
+ mock.restore();
30
+ jest.resetAllMocks();
31
+ });
32
+ it("should update user.worlds", () => __awaiter(void 0, void 0, void 0, function* () {
33
+ mock.onGet(`https://${apiDomain}/api/user/worlds`).reply(200, worlds);
34
+ yield testUser.fetchWorldsByKey();
35
+ expect(mock.history.get.length).toBe(1);
36
+ expect(Object.keys(testUser.worlds).length).toBe(Object.keys(worlds).length);
37
+ }));
16
38
  it("should return an array of scenes owned by specific email address", () => __awaiter(void 0, void 0, void 0, function* () {
17
- const testUser = yield new User({ apiKey: "key", email: "test@email.com" });
18
39
  testUser.fetchScenesByEmail = jest.fn().mockReturnValue(scenes);
19
40
  const mockScenes = yield testUser.fetchScenesByEmail();
20
41
  expect(testUser.fetchScenesByEmail).toHaveBeenCalled();
21
42
  expect(mockScenes).toBeDefined();
22
43
  }));
44
+ it("should return an array of assets owned by specific email address", () => __awaiter(void 0, void 0, void 0, function* () {
45
+ testUser.fetchAssetsByEmail = jest.fn().mockReturnValue(droppedAssets);
46
+ const mockAssets = yield testUser.fetchAssetsByEmail("lina@topia.io");
47
+ expect(testUser.fetchAssetsByEmail).toHaveBeenCalled();
48
+ expect(mockAssets).toBeDefined();
49
+ }));
23
50
  });
@@ -7,18 +7,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { Visitor } from "controllers";
11
- import { visitor } from "../../__mocks__/visitors";
12
- afterEach(() => {
13
- jest.resetAllMocks();
14
- });
10
+ import axios from "axios";
11
+ import MockAdapter from "axios-mock-adapter";
12
+ import { visitors } from "../../__mocks__";
13
+ import { Topia } from "controllers";
14
+ import { VisitorFactory } from "factories";
15
+ const apiDomain = "api.topia.io";
16
+ const id = visitors["1"].playerId;
15
17
  describe("Visitor Class", () => {
16
- it("should create an instance of Visitor", () => __awaiter(void 0, void 0, void 0, function* () {
17
- const testVisitor = new Visitor({
18
+ let mock, testVisitor, topia, Visitor;
19
+ beforeEach(() => {
20
+ mock = new MockAdapter(axios);
21
+ topia = new Topia({
22
+ apiDomain,
18
23
  apiKey: "key",
19
- args: visitor,
20
- urlSlug: "magic",
21
24
  });
22
- expect(testVisitor.playerId).toEqual(1);
25
+ Visitor = new VisitorFactory(topia);
26
+ testVisitor = Visitor.create(id, "magic");
27
+ });
28
+ afterEach(() => {
29
+ mock.restore();
30
+ jest.resetAllMocks();
31
+ });
32
+ it("should move a list of visitors to uniquely specified coordinates", () => __awaiter(void 0, void 0, void 0, function* () {
33
+ mock.onPut(`https://${apiDomain}/api/world/magic/visitors/${id}/move`).reply(200, "Success!");
34
+ yield testVisitor.moveVisitor({
35
+ shouldTeleportVisitor: true,
36
+ x: 100,
37
+ y: 100,
38
+ });
39
+ expect(mock.history.put.length).toBe(1);
23
40
  }));
24
41
  });
@@ -10,16 +10,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import axios from "axios";
11
11
  import MockAdapter from "axios-mock-adapter";
12
12
  import { visitors, worlds } from "../../__mocks__";
13
- import { Visitor, World } from "controllers";
13
+ import { Visitor, Topia } from "controllers";
14
+ import { WorldFactory } from "factories";
15
+ // const args = worlds[1];
14
16
  const BASE_URL = "https://api.topia.io/api/world/magic";
15
- const apiKey = "key";
16
- const args = worlds[1];
17
17
  const urlSlug = worlds[1].urlSlug;
18
18
  describe("World Class", () => {
19
- let mock, testWorld;
19
+ let mock, testWorld, topia, World;
20
20
  beforeEach(() => {
21
21
  mock = new MockAdapter(axios);
22
- testWorld = new World({ apiKey, args, urlSlug });
22
+ topia = new Topia({
23
+ apiDomain: "api.topia.io",
24
+ apiKey: "key",
25
+ });
26
+ World = new WorldFactory(topia);
27
+ testWorld = World.create(urlSlug);
23
28
  });
24
29
  afterEach(() => {
25
30
  mock.restore();
@@ -32,15 +37,20 @@ describe("World Class", () => {
32
37
  expect(testWorld.fetchDetails).toHaveBeenCalled();
33
38
  expect(mockDetails).toBeDefined();
34
39
  }));
35
- it("should update details of a world", () => __awaiter(void 0, void 0, void 0, function* () {
36
- mock.onPut(`${BASE_URL}/world-details`).reply(200, "Success!");
37
- const worldArgs = Object.assign(Object.assign({}, args), { controls: {
38
- allowMuteAll: false,
39
- }, description: "testing update details", name: "magic" });
40
- yield testWorld.updateDetails(worldArgs);
41
- expect(mock.history.put.length).toBe(1);
42
- expect(testWorld.urlSlug).toEqual("magic");
43
- }));
40
+ // it("should update details of a world", async () => {
41
+ // mock.onPut(`${BASE_URL}/world-details`).reply(200, "Success!");
42
+ // const worldArgs = {
43
+ // ...args,
44
+ // controls: {
45
+ // allowMuteAll: false,
46
+ // },
47
+ // description: "testing update details",
48
+ // name: "magic",
49
+ // };
50
+ // await testWorld.updateDetails(worldArgs);
51
+ // expect(mock.history.put.length).toBe(1);
52
+ // expect(testWorld.urlSlug).toEqual("magic");
53
+ // });
44
54
  it("should move all visitors within a world to a single set of coordinates", () => __awaiter(void 0, void 0, void 0, function* () {
45
55
  mock.onGet(`${BASE_URL}/visitors`).reply(200, visitors);
46
56
  mock.onPut(`${BASE_URL}/visitors/1/move`).reply(200, "Success!");
@@ -55,16 +65,8 @@ describe("World Class", () => {
55
65
  }));
56
66
  it("should move a list of visitors to uniquely specified coordinates", () => __awaiter(void 0, void 0, void 0, function* () {
57
67
  mock.onPut(`${BASE_URL}/visitors/1/move`).reply(200, "Success!");
58
- const v1 = new Visitor({
59
- apiKey,
60
- args: visitors["1"],
61
- urlSlug,
62
- });
63
- const v2 = new Visitor({
64
- apiKey,
65
- args: visitors["2"],
66
- urlSlug,
67
- });
68
+ const v1 = new Visitor(topia, visitors["1"].playerId, urlSlug, { args: visitors["1"] });
69
+ const v2 = new Visitor(topia, visitors["2"].playerId, urlSlug, { args: visitors["2"] });
68
70
  const testVisitors = [
69
71
  { visitorObj: v1, shouldTeleportVisitor: true, x: 0, y: 0 },
70
72
  { visitorObj: v2, shouldTeleportVisitor: false, x: 100, y: 100 },
@@ -1,5 +1,7 @@
1
1
  export { Asset } from "./Asset";
2
2
  export { DroppedAsset } from "./DroppedAsset";
3
+ export { SDKController } from "./SDKController";
3
4
  export { User } from "./User";
4
5
  export { Visitor } from "./Visitor";
5
6
  export { World } from "./World";
7
+ export { Topia } from "./Topia";
@@ -0,0 +1,32 @@
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
+ // @ts-nocheck
11
+ // Initialization... on backend
12
+ import { Topia, DroppedAssetFactory, TopiaWorldFactory } from "@rtsdk/topia";
13
+ const myTopiaInstance = new Topia({
14
+ apiDomain: process.env.INSTANCE_DOMAIN || "api.topia.io/",
15
+ apiKey: process.env.API_KEY,
16
+ interactiveKey: process.env.INTERACTIVE_KEY,
17
+ interactiveSecret: process.env.INTERACTIVE_SECRET,
18
+ });
19
+ const DroppedAsset = new DroppedAssetFactory(myTopiaInstance);
20
+ const TopiaWorld = new TopiaWorldFactory(myTopiaInstance);
21
+ export default { myTopiaInstance, DroppedAsset, TopiaWorld };
22
+ const setTextOnAsset = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
23
+ const asset = yield DroppedAsset.get(req.body.assetId, req.body.urlSlug, { creds: req.body });
24
+ yield asset.setAssetText(req.body.text);
25
+ });
26
+ import { myTopiaInterface } from "./src";
27
+ const setTextOnAsset = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
28
+ const asset = yield new DroppedAssetFactory(myTopiaInterface).get(req.body.assetId, req.body.urlSlug, {
29
+ creds: req.body,
30
+ });
31
+ yield asset.setAssetText(req.body.text);
32
+ });
@@ -0,0 +1,11 @@
1
+ import { Asset } from "controllers";
2
+ export class AssetFactory {
3
+ constructor(topia) {
4
+ this.topia = topia;
5
+ this.create;
6
+ }
7
+ create(id, options) {
8
+ return new Asset(this.topia, id, options);
9
+ }
10
+ }
11
+ export default AssetFactory;
@@ -0,0 +1,26 @@
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 { DroppedAsset } from "controllers";
11
+ export class DroppedAssetFactory {
12
+ constructor(topia) {
13
+ this.topia = topia;
14
+ }
15
+ create(id, urlSlug, options) {
16
+ return new DroppedAsset(this.topia, id, urlSlug, options);
17
+ }
18
+ get(id, urlSlug, options) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const droppedAsset = new DroppedAsset(this.topia, id, urlSlug, options);
21
+ yield droppedAsset.fetchDroppedAssetById();
22
+ return droppedAsset;
23
+ });
24
+ }
25
+ }
26
+ export default DroppedAssetFactory;
@@ -0,0 +1,10 @@
1
+ import { User } from "controllers";
2
+ export class UserFactory {
3
+ constructor(topia) {
4
+ this.topia = topia;
5
+ }
6
+ create(email, options) {
7
+ return new User(this.topia, email, options);
8
+ }
9
+ }
10
+ export default UserFactory;