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