@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
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Javascript RTSDK - Topia Client Library
|
|
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. 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
|
+
|
|
5
|
+
## Get Started
|
|
6
|
+
|
|
7
|
+
Run `yarn add @rtsdk/topia` or `npm install @rtsdk/topia`
|
|
8
|
+
|
|
9
|
+
## Authorization
|
|
10
|
+
|
|
11
|
+
A Topia provided API Key should be included with every object initialization as a parameter named `apiKey`. This API Key is used to in authorization headers in all calls to the Public API.
|
|
12
|
+
|
|
13
|
+
## Testing
|
|
14
|
+
|
|
15
|
+
We use Jest for testing and take advantage of dependency injection to pass mock data into our services.
|
|
16
|
+
|
|
17
|
+
To run the test suite, please run:
|
|
18
|
+
|
|
19
|
+
`yarn test`
|
|
@@ -1,13 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
18
|
+
fetchPlatformAssets() {
|
|
8
19
|
return new Promise((resolve, reject) => {
|
|
9
|
-
|
|
10
|
-
.get(
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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(
|
|
11
|
-
|
|
13
|
+
constructor(topia, id, urlSlug, options = { args: { text: "" }, creds: {} }) {
|
|
14
|
+
var _a;
|
|
15
|
+
super(topia, id, options);
|
|
12
16
|
// update dropped assets
|
|
13
|
-
|
|
17
|
+
this.updateDroppedAsset = (payload, updateType) => {
|
|
14
18
|
return new Promise((resolve, reject) => {
|
|
15
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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;
|
package/dist/controllers/User.js
CHANGED
|
@@ -10,24 +10,54 @@ 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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
// utils
|
|
17
|
+
import { getErrorMessage } from "utils";
|
|
18
|
+
/**
|
|
19
|
+
* Create an instance of User class with a given apiKey.
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* await new User({ email: "example@email.io" });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export class User extends SDKController {
|
|
26
|
+
constructor(topia, email, options = { creds: {} }) {
|
|
27
|
+
super(topia, options.creds);
|
|
17
28
|
_User_worldsMap.set(this, void 0);
|
|
18
29
|
__classPrivateFieldSet(this, _User_worldsMap, {}, "f");
|
|
19
|
-
this.apiKey = apiKey;
|
|
20
30
|
this.email = email;
|
|
21
31
|
}
|
|
22
32
|
get worlds() {
|
|
23
33
|
return __classPrivateFieldGet(this, _User_worldsMap, "f");
|
|
24
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* @summary
|
|
37
|
+
* Returns all assets owned by User when an email address is provided.
|
|
38
|
+
*/
|
|
39
|
+
fetchAssetsByEmail(ownerEmail) {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
this.topia.axios
|
|
42
|
+
.get(`/assets/my-assets?email=${ownerEmail}`, this.requestOptions)
|
|
43
|
+
.then((response) => {
|
|
44
|
+
resolve(response.data);
|
|
45
|
+
})
|
|
46
|
+
.catch((error) => {
|
|
47
|
+
reject(new Error(getErrorMessage(error)));
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @summary
|
|
53
|
+
* Returns all scenes owned by User when an email address is provided.
|
|
54
|
+
*/
|
|
25
55
|
fetchScenesByEmail() {
|
|
26
56
|
return new Promise((resolve, reject) => {
|
|
27
57
|
if (!this.email)
|
|
28
58
|
reject("There is no email associated with this user.");
|
|
29
|
-
|
|
30
|
-
.get(`/scenes/my-scenes?email=${this.email}
|
|
59
|
+
this.topia.axios
|
|
60
|
+
.get(`/scenes/my-scenes?email=${this.email}`, this.requestOptions)
|
|
31
61
|
.then((response) => {
|
|
32
62
|
resolve(response.data);
|
|
33
63
|
})
|
|
@@ -36,19 +66,32 @@ export class User {
|
|
|
36
66
|
});
|
|
37
67
|
});
|
|
38
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* @summary
|
|
71
|
+
* Retrieves all worlds owned by user with matching API Key,
|
|
72
|
+
* creates a new World object for each,
|
|
73
|
+
* and creates new map of Worlds accessible via user.worlds.
|
|
74
|
+
*
|
|
75
|
+
* @usage
|
|
76
|
+
* ```ts
|
|
77
|
+
* await user.fetchWorldsByKey();
|
|
78
|
+
* const userWorlds = user.worlds;
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @result
|
|
82
|
+
* ```ts
|
|
83
|
+
* { urlSlug: new World({ apiKey, worldArgs, urlSlug }) }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
39
86
|
fetchWorldsByKey() {
|
|
40
87
|
return new Promise((resolve, reject) => {
|
|
41
|
-
|
|
42
|
-
.get("/user/worlds")
|
|
88
|
+
this.topia.axios
|
|
89
|
+
.get("/user/worlds", this.requestOptions)
|
|
43
90
|
.then((response) => {
|
|
44
91
|
const tempWorldsMap = {};
|
|
45
92
|
for (const i in response.data) {
|
|
46
93
|
const worldDetails = response.data[i];
|
|
47
|
-
tempWorldsMap[worldDetails.urlSlug] = new World({
|
|
48
|
-
apiKey: this.apiKey,
|
|
49
|
-
args: worldDetails,
|
|
50
|
-
urlSlug: worldDetails.urlSlug,
|
|
51
|
-
});
|
|
94
|
+
tempWorldsMap[worldDetails.urlSlug] = new World(this.topia, worldDetails.urlSlug, { args: worldDetails });
|
|
52
95
|
}
|
|
53
96
|
__classPrivateFieldSet(this, _User_worldsMap, tempWorldsMap, "f");
|
|
54
97
|
resolve("Success!");
|
|
@@ -1,25 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
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
|
-
|
|
14
|
-
.put(`/world/${this.urlSlug}/visitors/${this.
|
|
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) => {
|