epicenter-libs 3.33.0 → 3.34.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/browser/epicenter.js +105 -2
- package/dist/browser/epicenter.js.map +1 -1
- package/dist/cjs/epicenter.js +105 -2
- package/dist/cjs/epicenter.js.map +1 -1
- package/dist/epicenter.js +105 -2
- package/dist/epicenter.js.map +1 -1
- package/dist/epicenter.min.js +1 -1
- package/dist/epicenter.min.js.map +1 -1
- package/dist/module/epicenter.js +105 -2
- package/dist/module/epicenter.js.map +1 -1
- package/dist/types/adapters/chat.d.ts +63 -0
- package/package.json +1 -1
- package/src/adapters/chat.ts +95 -0
- package/src/utils/identification.ts +4 -0
- package/dist/test/_virtual/runtime.js +0 -3
- package/dist/test/_virtual/runtime2.js +0 -3
- package/dist/test/adapters/account.js +0 -169
- package/dist/test/adapters/admin.js +0 -53
- package/dist/test/adapters/asset.js +0 -425
- package/dist/test/adapters/authentication.js +0 -349
- package/dist/test/adapters/channel.js +0 -201
- package/dist/test/adapters/chat.js +0 -199
- package/dist/test/adapters/cometd.js +0 -514
- package/dist/test/adapters/consensus.js +0 -484
- package/dist/test/adapters/daily.js +0 -244
- package/dist/test/adapters/email.js +0 -179
- package/dist/test/adapters/episode.js +0 -175
- package/dist/test/adapters/group.js +0 -655
- package/dist/test/adapters/leaderboard.js +0 -162
- package/dist/test/adapters/matchmaker.js +0 -159
- package/dist/test/adapters/presence.js +0 -85
- package/dist/test/adapters/project.js +0 -94
- package/dist/test/adapters/recaptcha.js +0 -24
- package/dist/test/adapters/run.js +0 -1008
- package/dist/test/adapters/somebody.js +0 -154
- package/dist/test/adapters/task.js +0 -192
- package/dist/test/adapters/time.js +0 -28
- package/dist/test/adapters/user.js +0 -105
- package/dist/test/adapters/vault.js +0 -403
- package/dist/test/adapters/video.js +0 -249
- package/dist/test/adapters/vonage.js +0 -130
- package/dist/test/adapters/wallet.js +0 -130
- package/dist/test/adapters/world.js +0 -507
- package/dist/test/apis/video.js +0 -294
- package/dist/test/apis/vonage.js +0 -121
- package/dist/test/epicenter.js +0 -121
- package/dist/test/node_modules/@babel/runtime/helpers/esm/defineProperty.js +0 -12
- package/dist/test/node_modules/@babel/runtime/helpers/esm/toPrimitive.js +0 -14
- package/dist/test/node_modules/@babel/runtime/helpers/esm/toPropertyKey.js +0 -9
- package/dist/test/node_modules/@babel/runtime/helpers/esm/typeof.js +0 -11
- package/dist/test/node_modules/cometd/AckExtension.js +0 -91
- package/dist/test/node_modules/cometd/CallbackPollingTransport.js +0 -148
- package/dist/test/node_modules/cometd/Client.js +0 -2160
- package/dist/test/node_modules/cometd/Extension.js +0 -47
- package/dist/test/node_modules/cometd/LongPollingTransport.js +0 -135
- package/dist/test/node_modules/cometd/ReloadExtension.js +0 -214
- package/dist/test/node_modules/cometd/RequestTransport.js +0 -252
- package/dist/test/node_modules/cometd/Transport.js +0 -167
- package/dist/test/node_modules/cometd/TransportRegistry.js +0 -107
- package/dist/test/node_modules/cometd/WebSocketTransport.js +0 -384
- package/dist/test/node_modules/cometd/cometd.js +0 -9
- package/dist/test/node_modules/regenerator-runtime/runtime.js +0 -773
- package/dist/test/utilities.js +0 -17
- package/dist/test/utils/config.js +0 -189
- package/dist/test/utils/constants.js +0 -293
- package/dist/test/utils/cookies.js +0 -75
- package/dist/test/utils/error-manager.js +0 -57
- package/dist/test/utils/error.js +0 -12
- package/dist/test/utils/fault.js +0 -34
- package/dist/test/utils/filter-parser.js +0 -68
- package/dist/test/utils/helpers.js +0 -9
- package/dist/test/utils/identification.js +0 -161
- package/dist/test/utils/result.js +0 -20
- package/dist/test/utils/router.js +0 -551
- package/dist/test/utils/store.js +0 -79
|
@@ -1,425 +0,0 @@
|
|
|
1
|
-
import fetch from 'cross-fetch';
|
|
2
|
-
import { ROLE } from '../utils/constants.js';
|
|
3
|
-
import '../utils/helpers.js';
|
|
4
|
-
import Fault from '../utils/fault.js';
|
|
5
|
-
import '../utils/config.js';
|
|
6
|
-
import '../utils/identification.js';
|
|
7
|
-
import '../utils/error-manager.js';
|
|
8
|
-
import Router from '../utils/router.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Creates a presigned URL for uploading a file to S3
|
|
12
|
-
* Base URL: POST `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/asset`
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* import { assetAdapter, SCOPE_BOUNDARY } from 'epicenter-libs';
|
|
16
|
-
* const ticket = await assetAdapter.create('myfile.pdf', {
|
|
17
|
-
* scopeBoundary: SCOPE_BOUNDARY.GROUP,
|
|
18
|
-
* scopeKey: '0000017dd3bf540e5ada5b1e058f08f20461',
|
|
19
|
-
* });
|
|
20
|
-
*
|
|
21
|
-
* @param file File path/name for the asset
|
|
22
|
-
* @param scope Scope associated with the asset
|
|
23
|
-
* @param scope.scopeBoundary Scope boundary, defines the type of scope; See [scope boundary](#SCOPE_BOUNDARY) for all types
|
|
24
|
-
* @param scope.scopeKey Scope key, a unique identifier tied to the scope. E.g., if your `scopeBoundary` is `GROUP`, your `scopeKey` will be your `groupKey`; for `EPISODE`, `episodeKey`, etc.
|
|
25
|
-
* @param [scope.userKey] User key to further scope the asset to a specific user
|
|
26
|
-
* @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
|
|
27
|
-
* @param [optionals.readLock] Role allowed to read; defaults to USER
|
|
28
|
-
* @param [optionals.writeLock] Role allowed to write; defaults to USER
|
|
29
|
-
* @param [optionals.ttlSeconds] Time to live in seconds for the asset
|
|
30
|
-
* @param [optionals.tokenAccessSeconds] How long the presigned URL is valid for in seconds
|
|
31
|
-
* @returns promise that resolves to an asset ticket containing the presigned upload URL
|
|
32
|
-
*/
|
|
33
|
-
async function create(file, scope, optionals = {}) {
|
|
34
|
-
const {
|
|
35
|
-
scopeBoundary,
|
|
36
|
-
scopeKey,
|
|
37
|
-
userKey
|
|
38
|
-
} = scope;
|
|
39
|
-
const {
|
|
40
|
-
readLock,
|
|
41
|
-
writeLock,
|
|
42
|
-
ttlSeconds,
|
|
43
|
-
tokenAccessSeconds,
|
|
44
|
-
...routingOptions
|
|
45
|
-
} = optionals;
|
|
46
|
-
return await new Router().withSearchParams({
|
|
47
|
-
tokenAccessSeconds
|
|
48
|
-
}).post('/asset', {
|
|
49
|
-
body: {
|
|
50
|
-
file,
|
|
51
|
-
scope: {
|
|
52
|
-
scopeBoundary,
|
|
53
|
-
scopeKey,
|
|
54
|
-
userKey
|
|
55
|
-
},
|
|
56
|
-
permit: {
|
|
57
|
-
readLock: readLock !== null && readLock !== void 0 ? readLock : ROLE.USER,
|
|
58
|
-
writeLock: writeLock !== null && writeLock !== void 0 ? writeLock : ROLE.USER
|
|
59
|
-
},
|
|
60
|
-
ttlSeconds
|
|
61
|
-
},
|
|
62
|
-
...routingOptions
|
|
63
|
-
}).then(({
|
|
64
|
-
body
|
|
65
|
-
}) => body);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Updates an existing asset and returns a presigned URL for uploading the new file to S3
|
|
70
|
-
* Base URL: PATCH `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/asset`
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* import { assetAdapter, SCOPE_BOUNDARY } from 'epicenter-libs';
|
|
74
|
-
* const ticket = await assetAdapter.update('myfile.pdf', {
|
|
75
|
-
* scopeBoundary: SCOPE_BOUNDARY.GROUP,
|
|
76
|
-
* scopeKey: '0000017dd3bf540e5ada5b1e058f08f20461',
|
|
77
|
-
* });
|
|
78
|
-
*
|
|
79
|
-
* @param file File path/name for the asset
|
|
80
|
-
* @param scope Scope associated with the asset
|
|
81
|
-
* @param scope.scopeBoundary Scope boundary, defines the type of scope; See [scope boundary](#SCOPE_BOUNDARY) for all types
|
|
82
|
-
* @param scope.scopeKey Scope key, a unique identifier tied to the scope. E.g., if your `scopeBoundary` is `GROUP`, your `scopeKey` will be your `groupKey`; for `EPISODE`, `episodeKey`, etc.
|
|
83
|
-
* @param [scope.userKey] User key to further scope the asset to a specific user
|
|
84
|
-
* @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
|
|
85
|
-
* @param [optionals.readLock] Role allowed to read; defaults to USER
|
|
86
|
-
* @param [optionals.writeLock] Role allowed to write; defaults to USER
|
|
87
|
-
* @param [optionals.ttlSeconds] Time to live in seconds for the asset
|
|
88
|
-
* @param [optionals.tokenAccessSeconds] How long the presigned URL is valid for in seconds
|
|
89
|
-
* @returns promise that resolves to an asset ticket containing the presigned upload URL
|
|
90
|
-
*/
|
|
91
|
-
async function update(file, scope, optionals = {}) {
|
|
92
|
-
const {
|
|
93
|
-
scopeBoundary,
|
|
94
|
-
scopeKey,
|
|
95
|
-
userKey
|
|
96
|
-
} = scope;
|
|
97
|
-
const {
|
|
98
|
-
readLock,
|
|
99
|
-
writeLock,
|
|
100
|
-
ttlSeconds,
|
|
101
|
-
tokenAccessSeconds,
|
|
102
|
-
...routingOptions
|
|
103
|
-
} = optionals;
|
|
104
|
-
return await new Router().withSearchParams({
|
|
105
|
-
tokenAccessSeconds
|
|
106
|
-
}).patch('/asset', {
|
|
107
|
-
body: {
|
|
108
|
-
file,
|
|
109
|
-
scope: {
|
|
110
|
-
scopeBoundary,
|
|
111
|
-
scopeKey,
|
|
112
|
-
userKey
|
|
113
|
-
},
|
|
114
|
-
permit: {
|
|
115
|
-
readLock: readLock !== null && readLock !== void 0 ? readLock : ROLE.USER,
|
|
116
|
-
writeLock: writeLock !== null && writeLock !== void 0 ? writeLock : ROLE.USER
|
|
117
|
-
},
|
|
118
|
-
ttlSeconds
|
|
119
|
-
},
|
|
120
|
-
...routingOptions
|
|
121
|
-
}).then(({
|
|
122
|
-
body
|
|
123
|
-
}) => body);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Deletes an asset by asset key
|
|
128
|
-
* Base URL: DELETE `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/asset/{ASSET_KEY}`
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* import { assetAdapter } from 'epicenter-libs';
|
|
132
|
-
* await assetAdapter.remove('0000017dd3bf540e5ada5b1e058f08f20461');
|
|
133
|
-
*
|
|
134
|
-
* @param assetKey The unique key for the asset
|
|
135
|
-
* @param [optionals] Optional arguments; pass network call options overrides here.
|
|
136
|
-
* @returns promise that resolves when the asset is deleted
|
|
137
|
-
*/
|
|
138
|
-
async function remove(assetKey, optionals = {}) {
|
|
139
|
-
return await new Router().delete(`/asset/${assetKey}`, optionals).then(({
|
|
140
|
-
body
|
|
141
|
-
}) => body);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Deletes all assets within a given scope
|
|
146
|
-
* Base URL: DELETE `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/asset/in/{SCOPE_BOUNDARY}/{SCOPE_KEY}` or DELETE `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/asset/in/{SCOPE_BOUNDARY}/{SCOPE_KEY}/{USER_KEY}`
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* import { assetAdapter, SCOPE_BOUNDARY } from 'epicenter-libs';
|
|
150
|
-
* await assetAdapter.removeFromScope({
|
|
151
|
-
* scopeBoundary: SCOPE_BOUNDARY.GROUP,
|
|
152
|
-
* scopeKey: '0000017dd3bf540e5ada5b1e058f08f20461',
|
|
153
|
-
* });
|
|
154
|
-
*
|
|
155
|
-
* @param scope Scope associated with the assets to delete
|
|
156
|
-
* @param scope.scopeBoundary Scope boundary, defines the type of scope; See [scope boundary](#SCOPE_BOUNDARY) for all types
|
|
157
|
-
* @param scope.scopeKey Scope key, a unique identifier tied to the scope. E.g., if your `scopeBoundary` is `GROUP`, your `scopeKey` will be your `groupKey`; for `EPISODE`, `episodeKey`, etc.
|
|
158
|
-
* @param [scope.userKey] User key to further scope the deletion to a specific user
|
|
159
|
-
* @param [optionals] Optional arguments; pass network call options overrides here.
|
|
160
|
-
* @returns promise that resolves when all assets in the scope are deleted
|
|
161
|
-
*/
|
|
162
|
-
async function removeFromScope(scope, optionals = {}) {
|
|
163
|
-
const {
|
|
164
|
-
scopeBoundary,
|
|
165
|
-
scopeKey,
|
|
166
|
-
userKey
|
|
167
|
-
} = scope;
|
|
168
|
-
const uriComponent = userKey ? `/${userKey}` : '';
|
|
169
|
-
return await new Router().delete(`/asset/in/${scopeBoundary}/${scopeKey}${uriComponent}`, optionals).then(({
|
|
170
|
-
body
|
|
171
|
-
}) => body);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Retrieves asset metadata by asset key
|
|
176
|
-
* Base URL: GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/asset/{ASSET_KEY}`
|
|
177
|
-
*
|
|
178
|
-
* @example
|
|
179
|
-
* import { assetAdapter } from 'epicenter-libs';
|
|
180
|
-
* const asset = await assetAdapter.get('0000017dd3bf540e5ada5b1e058f08f20461');
|
|
181
|
-
*
|
|
182
|
-
* @param assetKey The unique key for the asset
|
|
183
|
-
* @param [optionals] Optional arguments; pass network call options overrides here.
|
|
184
|
-
* @returns promise that resolves to the asset metadata
|
|
185
|
-
*/
|
|
186
|
-
async function get(assetKey, optionals = {}) {
|
|
187
|
-
const {
|
|
188
|
-
server,
|
|
189
|
-
accountShortName,
|
|
190
|
-
projectShortName
|
|
191
|
-
} = optionals;
|
|
192
|
-
return await new Router().withServer(server).withAccountShortName(accountShortName).withProjectShortName(projectShortName).get(`/asset/${assetKey}`).then(({
|
|
193
|
-
body
|
|
194
|
-
}) => body);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Lists all assets within a given scope, optionally filtered by file pattern
|
|
199
|
-
* Base URL: GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/asset/in/{SCOPE_BOUNDARY}/{SCOPE_KEY}/{FILTER}` or GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/asset/in/{SCOPE_BOUNDARY}/{SCOPE_KEY}/{USER_KEY}/{FILTER}`
|
|
200
|
-
*
|
|
201
|
-
* @example
|
|
202
|
-
* import { assetAdapter, SCOPE_BOUNDARY } from 'epicenter-libs';
|
|
203
|
-
* // List all assets in the scope
|
|
204
|
-
* const assets = await assetAdapter.list({
|
|
205
|
-
* scopeBoundary: SCOPE_BOUNDARY.GROUP,
|
|
206
|
-
* scopeKey: '0000017dd3bf540e5ada5b1e058f08f20461',
|
|
207
|
-
* });
|
|
208
|
-
* // List only PDF files
|
|
209
|
-
* const pdfs = await assetAdapter.list({
|
|
210
|
-
* scopeBoundary: SCOPE_BOUNDARY.GROUP,
|
|
211
|
-
* scopeKey: '0000017dd3bf540e5ada5b1e058f08f20461',
|
|
212
|
-
* }, { filter: '*.pdf' });
|
|
213
|
-
*
|
|
214
|
-
* @param scope Scope associated with the assets
|
|
215
|
-
* @param scope.scopeBoundary Scope boundary, defines the type of scope; See [scope boundary](#SCOPE_BOUNDARY) for all types
|
|
216
|
-
* @param scope.scopeKey Scope key, a unique identifier tied to the scope. E.g., if your `scopeBoundary` is `GROUP`, your `scopeKey` will be your `groupKey`; for `EPISODE`, `episodeKey`, etc.
|
|
217
|
-
* @param [scope.userKey] User key to further scope the list to a specific user
|
|
218
|
-
* @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
|
|
219
|
-
* @param [optionals.filter] File pattern to filter assets (e.g., '*.pdf' for PDF files); defaults to '*' (all files)
|
|
220
|
-
* @returns promise that resolves to a list of assets
|
|
221
|
-
*/
|
|
222
|
-
async function list(scope, optionals = {}) {
|
|
223
|
-
const {
|
|
224
|
-
scopeBoundary,
|
|
225
|
-
scopeKey,
|
|
226
|
-
userKey
|
|
227
|
-
} = scope;
|
|
228
|
-
const {
|
|
229
|
-
filter,
|
|
230
|
-
...routingOptions
|
|
231
|
-
} = optionals;
|
|
232
|
-
const uriComponent = userKey ? `/${userKey}` : '';
|
|
233
|
-
return await new Router().get(`/asset/in/${scopeBoundary}/${scopeKey}${uriComponent}/${filter !== null && filter !== void 0 ? filter : '*'}`, routingOptions).then(({
|
|
234
|
-
body
|
|
235
|
-
}) => body);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Generates a presigned URL for accessing an asset
|
|
240
|
-
* Base URL: GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/asset/url/{ASSET_KEY}`
|
|
241
|
-
*
|
|
242
|
-
* @example
|
|
243
|
-
* import { assetAdapter } from 'epicenter-libs';
|
|
244
|
-
* const url = await assetAdapter.getURL('0000017dd3bf540e5ada5b1e058f08f20461');
|
|
245
|
-
* // Use the url to access the asset
|
|
246
|
-
*
|
|
247
|
-
* @param assetKey The unique key for the asset
|
|
248
|
-
* @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
|
|
249
|
-
* @param [optionals.tokenAccessSeconds] How long the presigned URL is valid for in seconds
|
|
250
|
-
* @returns promise that resolves to the presigned URL
|
|
251
|
-
*/
|
|
252
|
-
async function getURL(assetKey, optionals = {}) {
|
|
253
|
-
const {
|
|
254
|
-
tokenAccessSeconds,
|
|
255
|
-
...routingOptions
|
|
256
|
-
} = optionals;
|
|
257
|
-
return await new Router().withSearchParams({
|
|
258
|
-
tokenAccessSeconds
|
|
259
|
-
}).get(`/asset/url/${assetKey}`, routingOptions).then(({
|
|
260
|
-
body
|
|
261
|
-
}) => body);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Generates a presigned URL for accessing an asset by scope and file name
|
|
266
|
-
* Base URL: GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/asset/url/with/{SCOPE_BOUNDARY}/{SCOPE_KEY}/{FILE}` or GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/asset/url/with/{SCOPE_BOUNDARY}/{SCOPE_KEY}/{USER_KEY}/{FILE}`
|
|
267
|
-
*
|
|
268
|
-
* @example
|
|
269
|
-
* import { assetAdapter, SCOPE_BOUNDARY } from 'epicenter-libs';
|
|
270
|
-
* const url = await assetAdapter.getURLWithScope('myfile.pdf', {
|
|
271
|
-
* scopeBoundary: SCOPE_BOUNDARY.GROUP,
|
|
272
|
-
* scopeKey: '0000017dd3bf540e5ada5b1e058f08f20461',
|
|
273
|
-
* });
|
|
274
|
-
*
|
|
275
|
-
* @param file File path/name for the asset
|
|
276
|
-
* @param scope Scope associated with the asset
|
|
277
|
-
* @param scope.scopeBoundary Scope boundary, defines the type of scope; See [scope boundary](#SCOPE_BOUNDARY) for all types
|
|
278
|
-
* @param scope.scopeKey Scope key, a unique identifier tied to the scope. E.g., if your `scopeBoundary` is `GROUP`, your `scopeKey` will be your `groupKey`; for `EPISODE`, `episodeKey`, etc.
|
|
279
|
-
* @param [scope.userKey] User key to further scope the asset to a specific user
|
|
280
|
-
* @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
|
|
281
|
-
* @param [optionals.tokenAccessSeconds] How long the presigned URL is valid for in seconds
|
|
282
|
-
* @returns promise that resolves to the presigned URL
|
|
283
|
-
*/
|
|
284
|
-
async function getURLWithScope(file, scope, optionals = {}) {
|
|
285
|
-
const {
|
|
286
|
-
scopeBoundary,
|
|
287
|
-
scopeKey,
|
|
288
|
-
userKey
|
|
289
|
-
} = scope;
|
|
290
|
-
const {
|
|
291
|
-
tokenAccessSeconds,
|
|
292
|
-
...routingOptions
|
|
293
|
-
} = optionals;
|
|
294
|
-
const uriComponent = userKey ? `/${userKey}` : '';
|
|
295
|
-
return await new Router().withSearchParams({
|
|
296
|
-
tokenAccessSeconds
|
|
297
|
-
}).get(`/asset/url/with/${scopeBoundary}/${scopeKey}${uriComponent}/${file}`, routingOptions).then(({
|
|
298
|
-
body
|
|
299
|
-
}) => body);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Downloads an asset by asset key
|
|
304
|
-
* Base URL: GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/asset/download/{ASSET_KEY}`
|
|
305
|
-
*
|
|
306
|
-
* @example
|
|
307
|
-
* import { assetAdapter } from 'epicenter-libs';
|
|
308
|
-
* await assetAdapter.download('0000017dd3bf540e5ada5b1e058f08f20461');
|
|
309
|
-
*
|
|
310
|
-
* @param assetKey The unique key for the asset
|
|
311
|
-
* @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
|
|
312
|
-
* @param [optionals.tokenAccessSeconds] How long the presigned URL is valid for in seconds
|
|
313
|
-
* @returns promise that resolves when the download is complete
|
|
314
|
-
*/
|
|
315
|
-
async function download(assetKey, optionals = {}) {
|
|
316
|
-
const {
|
|
317
|
-
tokenAccessSeconds,
|
|
318
|
-
...routingOptions
|
|
319
|
-
} = optionals;
|
|
320
|
-
return await new Router().withSearchParams({
|
|
321
|
-
tokenAccessSeconds
|
|
322
|
-
}).get(`/asset/download/${assetKey}`, routingOptions).then(({
|
|
323
|
-
body
|
|
324
|
-
}) => body);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Downloads an asset by scope and file name
|
|
329
|
-
* Base URL: GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/asset/download/with/{SCOPE_BOUNDARY}/{SCOPE_KEY}/{FILE}` or GET `https://forio.com/api/v3/{ACCOUNT}/{PROJECT}/asset/download/with/{SCOPE_BOUNDARY}/{SCOPE_KEY}/{USER_KEY}/{FILE}`
|
|
330
|
-
*
|
|
331
|
-
* @example
|
|
332
|
-
* import { assetAdapter, SCOPE_BOUNDARY } from 'epicenter-libs';
|
|
333
|
-
* await assetAdapter.downloadWithScope('myfile.pdf', {
|
|
334
|
-
* scopeBoundary: SCOPE_BOUNDARY.GROUP,
|
|
335
|
-
* scopeKey: '0000017dd3bf540e5ada5b1e058f08f20461',
|
|
336
|
-
* });
|
|
337
|
-
*
|
|
338
|
-
* @param file File path/name for the asset
|
|
339
|
-
* @param scope Scope associated with the asset
|
|
340
|
-
* @param scope.scopeBoundary Scope boundary, defines the type of scope; See [scope boundary](#SCOPE_BOUNDARY) for all types
|
|
341
|
-
* @param scope.scopeKey Scope key, a unique identifier tied to the scope. E.g., if your `scopeBoundary` is `GROUP`, your `scopeKey` will be your `groupKey`; for `EPISODE`, `episodeKey`, etc.
|
|
342
|
-
* @param [scope.userKey] User key to further scope the asset to a specific user
|
|
343
|
-
* @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
|
|
344
|
-
* @param [optionals.tokenAccessSeconds] How long the presigned URL is valid for in seconds
|
|
345
|
-
* @returns promise that resolves when the download is complete
|
|
346
|
-
*/
|
|
347
|
-
async function downloadWithScope(file, scope, optionals = {}) {
|
|
348
|
-
const {
|
|
349
|
-
scopeBoundary,
|
|
350
|
-
scopeKey,
|
|
351
|
-
userKey
|
|
352
|
-
} = scope;
|
|
353
|
-
const {
|
|
354
|
-
tokenAccessSeconds,
|
|
355
|
-
...routingOptions
|
|
356
|
-
} = optionals;
|
|
357
|
-
const uriComponent = userKey ? `/${userKey}` : '';
|
|
358
|
-
return await new Router().withSearchParams({
|
|
359
|
-
tokenAccessSeconds
|
|
360
|
-
}).get(`/asset/download/with/${scopeBoundary}/${scopeKey}${uriComponent}/${file}`, routingOptions).then(({
|
|
361
|
-
body
|
|
362
|
-
}) => body);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* Convenience function to store a file directly to S3. This function obtains a presigned URL from the Epicenter server and uploads the file to S3. If the asset already exists and `overwrite` is true, it will update the existing asset.
|
|
367
|
-
*
|
|
368
|
-
* @example
|
|
369
|
-
* import { assetAdapter, SCOPE_BOUNDARY, ROLE } from 'epicenter-libs';
|
|
370
|
-
* const file = new File(['content'], 'myfile.pdf');
|
|
371
|
-
* await assetAdapter.store(file, {
|
|
372
|
-
* scopeBoundary: SCOPE_BOUNDARY.GROUP,
|
|
373
|
-
* scopeKey: '0000017dd3bf540e5ada5b1e058f08f20461',
|
|
374
|
-
* }, {
|
|
375
|
-
* overwrite: true,
|
|
376
|
-
* readLock: ROLE.USER,
|
|
377
|
-
* });
|
|
378
|
-
*
|
|
379
|
-
* @param file File object to store
|
|
380
|
-
* @param scope Scope associated with the asset
|
|
381
|
-
* @param scope.scopeBoundary Scope boundary, defines the type of scope; See [scope boundary](#SCOPE_BOUNDARY) for all types
|
|
382
|
-
* @param scope.scopeKey Scope key, a unique identifier tied to the scope. E.g., if your `scopeBoundary` is `GROUP`, your `scopeKey` will be your `groupKey`; for `EPISODE`, `episodeKey`, etc.
|
|
383
|
-
* @param [scope.userKey] User key to further scope the asset to a specific user
|
|
384
|
-
* @param [optionals] Optional arguments; pass network call options overrides here. Special arguments specific to this method are listed below if they exist.
|
|
385
|
-
* @param [optionals.readLock] Role allowed to read; defaults to USER
|
|
386
|
-
* @param [optionals.writeLock] Role allowed to write; defaults to USER
|
|
387
|
-
* @param [optionals.ttlSeconds] Time to live in seconds for the asset
|
|
388
|
-
* @param [optionals.overwrite] If true, will update the asset if it already exists; if false, will throw an error if the asset exists
|
|
389
|
-
* @param [optionals.fileName] Optional file name to use instead of the file's name property
|
|
390
|
-
* @param [optionals.tokenAccessSeconds] How long the presigned URL is valid for in seconds
|
|
391
|
-
* @returns promise that resolves when the file is stored
|
|
392
|
-
*/
|
|
393
|
-
const CONFLICT = 409;
|
|
394
|
-
async function store(file, scope, optionals = {}) {
|
|
395
|
-
const {
|
|
396
|
-
overwrite,
|
|
397
|
-
fileName,
|
|
398
|
-
...remaining
|
|
399
|
-
} = optionals;
|
|
400
|
-
const name = fileName !== null && fileName !== void 0 ? fileName : file.name;
|
|
401
|
-
let presignedUrl = '';
|
|
402
|
-
try {
|
|
403
|
-
const response = await create(name, scope, {
|
|
404
|
-
inert: true,
|
|
405
|
-
...remaining
|
|
406
|
-
});
|
|
407
|
-
presignedUrl = response.url;
|
|
408
|
-
} catch (error) {
|
|
409
|
-
if (error instanceof Fault) {
|
|
410
|
-
const shouldUpdate = error.status === CONFLICT && overwrite;
|
|
411
|
-
if (!shouldUpdate) throw error;
|
|
412
|
-
const response = await update(name, scope, remaining);
|
|
413
|
-
presignedUrl = response.url;
|
|
414
|
-
} else {
|
|
415
|
-
throw error;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
await fetch(presignedUrl, {
|
|
419
|
-
method: 'PUT',
|
|
420
|
-
body: file
|
|
421
|
-
});
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
export { create, download, downloadWithScope, get, getURL, getURLWithScope, list, remove, removeFromScope, store, update };
|