@atlaskit/media-client 25.0.2 → 25.1.0
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 +12 -0
- package/dist/cjs/client/media-store/MediaStore.js +631 -0
- package/dist/cjs/client/media-store/index.js +19 -627
- package/dist/cjs/client/media-store/types.js +5 -0
- package/dist/cjs/test-helpers/MockedMediaApi/MockedMediaApi.js +449 -0
- package/dist/cjs/test-helpers/MockedMediaApi/helpers.js +184 -0
- package/dist/cjs/test-helpers/MockedMediaApi/index.js +55 -0
- package/dist/cjs/test-helpers/index.js +49 -0
- package/dist/es2019/client/media-store/MediaStore.js +385 -0
- package/dist/es2019/client/media-store/index.js +1 -385
- package/dist/es2019/client/media-store/types.js +1 -0
- package/dist/es2019/test-helpers/MockedMediaApi/MockedMediaApi.js +164 -0
- package/dist/es2019/test-helpers/MockedMediaApi/helpers.js +166 -0
- package/dist/es2019/test-helpers/MockedMediaApi/index.js +2 -0
- package/dist/es2019/test-helpers/index.js +2 -1
- package/dist/esm/client/media-store/MediaStore.js +624 -0
- package/dist/esm/client/media-store/index.js +1 -624
- package/dist/esm/client/media-store/types.js +1 -0
- package/dist/esm/test-helpers/MockedMediaApi/MockedMediaApi.js +442 -0
- package/dist/esm/test-helpers/MockedMediaApi/helpers.js +176 -0
- package/dist/esm/test-helpers/MockedMediaApi/index.js +2 -0
- package/dist/esm/test-helpers/index.js +2 -1
- package/dist/types/client/media-store/MediaStore.d.ts +34 -0
- package/dist/types/client/media-store/index.d.ts +2 -166
- package/dist/types/client/media-store/types.d.ts +161 -0
- package/dist/types/test-helpers/MockedMediaApi/MockedMediaApi.d.ts +16 -0
- package/dist/types/test-helpers/MockedMediaApi/helpers.d.ts +23 -0
- package/dist/types/test-helpers/MockedMediaApi/index.d.ts +3 -0
- package/dist/types/test-helpers/index.d.ts +2 -0
- package/dist/types-ts4.5/client/media-store/MediaStore.d.ts +34 -0
- package/dist/types-ts4.5/client/media-store/index.d.ts +2 -166
- package/dist/types-ts4.5/client/media-store/types.d.ts +161 -0
- package/dist/types-ts4.5/test-helpers/MockedMediaApi/MockedMediaApi.d.ts +16 -0
- package/dist/types-ts4.5/test-helpers/MockedMediaApi/helpers.d.ts +23 -0
- package/dist/types-ts4.5/test-helpers/MockedMediaApi/index.d.ts +3 -0
- package/dist/types-ts4.5/test-helpers/index.d.ts +2 -0
- package/package.json +2 -2
- package/report.api.md +120 -1
- package/tmp/api-report-tmp.d.ts +47 -1
|
@@ -64,6 +64,42 @@ Object.defineProperty(exports, "collectionNames", {
|
|
|
64
64
|
return _collectionNames.collectionNames;
|
|
65
65
|
}
|
|
66
66
|
});
|
|
67
|
+
Object.defineProperty(exports, "copy", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
get: function get() {
|
|
70
|
+
return _MockedMediaApi.copy;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(exports, "createEmptyFileItem", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
get: function get() {
|
|
76
|
+
return _MockedMediaApi.createEmptyFileItem;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
Object.defineProperty(exports, "createErrorFileState", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
get: function get() {
|
|
82
|
+
return _MockedMediaApi.createErrorFileState;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
Object.defineProperty(exports, "createFileState", {
|
|
86
|
+
enumerable: true,
|
|
87
|
+
get: function get() {
|
|
88
|
+
return _MockedMediaApi.createFileState;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
Object.defineProperty(exports, "createMockedMediaApi", {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
get: function get() {
|
|
94
|
+
return _MockedMediaApi.createMockedMediaApi;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
Object.defineProperty(exports, "createProcessingFileItem", {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
get: function get() {
|
|
100
|
+
return _MockedMediaApi.createProcessingFileItem;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
67
103
|
Object.defineProperty(exports, "createStorybookMediaClient", {
|
|
68
104
|
enumerable: true,
|
|
69
105
|
get: function get() {
|
|
@@ -88,6 +124,12 @@ Object.defineProperty(exports, "createUploadMediaClientConfig", {
|
|
|
88
124
|
return _mediaClientProvider.createUploadMediaClientConfig;
|
|
89
125
|
}
|
|
90
126
|
});
|
|
127
|
+
Object.defineProperty(exports, "createUploadingFileState", {
|
|
128
|
+
enumerable: true,
|
|
129
|
+
get: function get() {
|
|
130
|
+
return _MockedMediaApi.createUploadingFileState;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
91
133
|
Object.defineProperty(exports, "defaultBaseUrl", {
|
|
92
134
|
enumerable: true,
|
|
93
135
|
get: function get() {
|
|
@@ -202,6 +244,12 @@ Object.defineProperty(exports, "genericFileId", {
|
|
|
202
244
|
return _exampleMediaItems.genericFileId;
|
|
203
245
|
}
|
|
204
246
|
});
|
|
247
|
+
Object.defineProperty(exports, "getIdentifier", {
|
|
248
|
+
enumerable: true,
|
|
249
|
+
get: function get() {
|
|
250
|
+
return _MockedMediaApi.getIdentifier;
|
|
251
|
+
}
|
|
252
|
+
});
|
|
205
253
|
Object.defineProperty(exports, "gifFileId", {
|
|
206
254
|
enumerable: true,
|
|
207
255
|
get: function get() {
|
|
@@ -370,4 +418,5 @@ var _collectionNames = require("./collectionNames");
|
|
|
370
418
|
var _exampleMediaItems = require("./exampleMediaItems");
|
|
371
419
|
var _mediaPickerAuthProvider = require("./mediaPickerAuthProvider");
|
|
372
420
|
var _fakeMediaClient = require("./fakeMediaClient");
|
|
421
|
+
var _MockedMediaApi = require("./MockedMediaApi");
|
|
373
422
|
var authProviderBaseURL = exports.authProviderBaseURL = 'https://media.dev.atl-paas.net';
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import { getRandomHex } from '@atlaskit/media-common';
|
|
3
|
+
import { FILE_CACHE_MAX_AGE, MAX_RESOLUTION } from '../../constants';
|
|
4
|
+
import { getArtifactUrl } from '../../models/artifacts';
|
|
5
|
+
import { request } from '../../utils/request';
|
|
6
|
+
import { createUrl, createMapResponseToJson, createMapResponseToBlob } from '../../utils/request/helpers';
|
|
7
|
+
import { resolveAuth, resolveInitialAuth } from './resolveAuth';
|
|
8
|
+
const MEDIA_API_REGION = 'media-api-region';
|
|
9
|
+
const MEDIA_API_ENVIRONMENT = 'media-api-environment';
|
|
10
|
+
const defaultImageOptions = {
|
|
11
|
+
'max-age': FILE_CACHE_MAX_AGE,
|
|
12
|
+
allowAnimated: true,
|
|
13
|
+
mode: 'crop'
|
|
14
|
+
};
|
|
15
|
+
const extendImageParams = (params, fetchMaxRes = false) => {
|
|
16
|
+
return {
|
|
17
|
+
...defaultImageOptions,
|
|
18
|
+
...params,
|
|
19
|
+
...(fetchMaxRes ? {
|
|
20
|
+
width: MAX_RESOLUTION,
|
|
21
|
+
height: MAX_RESOLUTION
|
|
22
|
+
} : {})
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const jsonHeaders = {
|
|
26
|
+
Accept: 'application/json',
|
|
27
|
+
'Content-Type': 'application/json'
|
|
28
|
+
};
|
|
29
|
+
export class MediaStore {
|
|
30
|
+
constructor(config) {
|
|
31
|
+
_defineProperty(this, "resolveAuth", authContext => resolveAuth(this.config.authProvider, authContext));
|
|
32
|
+
_defineProperty(this, "resolveInitialAuth", () => resolveInitialAuth(this.config.initialAuth));
|
|
33
|
+
this.config = config;
|
|
34
|
+
}
|
|
35
|
+
async removeCollectionFile(id, collectionName, occurrenceKey, traceContext) {
|
|
36
|
+
const metadata = {
|
|
37
|
+
method: 'PUT',
|
|
38
|
+
endpoint: '/collection/{collectionName}'
|
|
39
|
+
};
|
|
40
|
+
const body = {
|
|
41
|
+
actions: [{
|
|
42
|
+
action: 'remove',
|
|
43
|
+
item: {
|
|
44
|
+
type: 'file',
|
|
45
|
+
id,
|
|
46
|
+
occurrenceKey
|
|
47
|
+
}
|
|
48
|
+
}]
|
|
49
|
+
};
|
|
50
|
+
const options = {
|
|
51
|
+
...metadata,
|
|
52
|
+
authContext: {
|
|
53
|
+
collectionName
|
|
54
|
+
},
|
|
55
|
+
headers: {
|
|
56
|
+
Accept: 'application/json',
|
|
57
|
+
'Content-Type': 'application/json'
|
|
58
|
+
},
|
|
59
|
+
body: JSON.stringify(body),
|
|
60
|
+
traceContext
|
|
61
|
+
};
|
|
62
|
+
await this.request(`/collection/${collectionName}`, options);
|
|
63
|
+
}
|
|
64
|
+
createUpload(createUpTo = 1, collectionName, traceContext) {
|
|
65
|
+
const metadata = {
|
|
66
|
+
method: 'POST',
|
|
67
|
+
endpoint: '/upload'
|
|
68
|
+
};
|
|
69
|
+
const options = {
|
|
70
|
+
...metadata,
|
|
71
|
+
authContext: {
|
|
72
|
+
collectionName
|
|
73
|
+
},
|
|
74
|
+
params: {
|
|
75
|
+
createUpTo
|
|
76
|
+
},
|
|
77
|
+
headers: {
|
|
78
|
+
Accept: 'application/json'
|
|
79
|
+
},
|
|
80
|
+
traceContext
|
|
81
|
+
};
|
|
82
|
+
return this.request(`/upload`, options).then(createMapResponseToJson(metadata));
|
|
83
|
+
}
|
|
84
|
+
async uploadChunk(etag, blob, uploadId, partNumber, collectionName, traceContext) {
|
|
85
|
+
const metadata = {
|
|
86
|
+
method: 'PUT',
|
|
87
|
+
endpoint: '/chunk/{etag}'
|
|
88
|
+
};
|
|
89
|
+
const options = {
|
|
90
|
+
...metadata,
|
|
91
|
+
params: {
|
|
92
|
+
uploadId,
|
|
93
|
+
partNumber
|
|
94
|
+
},
|
|
95
|
+
authContext: {
|
|
96
|
+
collectionName
|
|
97
|
+
},
|
|
98
|
+
body: blob,
|
|
99
|
+
traceContext
|
|
100
|
+
};
|
|
101
|
+
await this.request(`/chunk/${etag}`, options);
|
|
102
|
+
}
|
|
103
|
+
probeChunks(chunks, uploadId, collectionName, traceContext) {
|
|
104
|
+
const metadata = {
|
|
105
|
+
method: 'POST',
|
|
106
|
+
endpoint: '/chunk/probe'
|
|
107
|
+
};
|
|
108
|
+
const options = {
|
|
109
|
+
...metadata,
|
|
110
|
+
params: {
|
|
111
|
+
uploadId
|
|
112
|
+
},
|
|
113
|
+
authContext: {
|
|
114
|
+
collectionName
|
|
115
|
+
},
|
|
116
|
+
headers: jsonHeaders,
|
|
117
|
+
body: JSON.stringify({
|
|
118
|
+
chunks
|
|
119
|
+
}),
|
|
120
|
+
traceContext
|
|
121
|
+
};
|
|
122
|
+
return this.request(`/chunk/probe`, options).then(createMapResponseToJson(metadata));
|
|
123
|
+
}
|
|
124
|
+
createFileFromUpload(body, params = {}, traceContext) {
|
|
125
|
+
const metadata = {
|
|
126
|
+
method: 'POST',
|
|
127
|
+
endpoint: '/file/upload'
|
|
128
|
+
};
|
|
129
|
+
const options = {
|
|
130
|
+
...metadata,
|
|
131
|
+
authContext: {
|
|
132
|
+
collectionName: params.collection
|
|
133
|
+
},
|
|
134
|
+
params,
|
|
135
|
+
headers: jsonHeaders,
|
|
136
|
+
body: JSON.stringify(body),
|
|
137
|
+
traceContext
|
|
138
|
+
};
|
|
139
|
+
return this.request('/file/upload', options).then(createMapResponseToJson(metadata));
|
|
140
|
+
}
|
|
141
|
+
getRejectedResponseFromDescriptor(descriptor, limit) {
|
|
142
|
+
return {
|
|
143
|
+
fileId: descriptor.fileId,
|
|
144
|
+
error: {
|
|
145
|
+
code: 'ExceedMaxFileSizeLimit',
|
|
146
|
+
title: 'The expected file size exceeded the maximum size limit.',
|
|
147
|
+
href: 'https://dt-api-filestore--app.ap-southeast-2.dev.atl-paas.net/api.html#BadRequest',
|
|
148
|
+
limit,
|
|
149
|
+
size: descriptor.size
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
async touchFiles(body, params = {}, traceContext) {
|
|
154
|
+
const metadata = {
|
|
155
|
+
method: 'POST',
|
|
156
|
+
endpoint: '/upload/createWithFiles'
|
|
157
|
+
};
|
|
158
|
+
const options = {
|
|
159
|
+
...metadata,
|
|
160
|
+
authContext: {
|
|
161
|
+
collectionName: params.collection
|
|
162
|
+
},
|
|
163
|
+
headers: jsonHeaders,
|
|
164
|
+
body: JSON.stringify(body),
|
|
165
|
+
traceContext
|
|
166
|
+
};
|
|
167
|
+
return this.request('/upload/createWithFiles', options).then(createMapResponseToJson(metadata));
|
|
168
|
+
}
|
|
169
|
+
getFile(fileId, params = {}, traceContext) {
|
|
170
|
+
const metadata = {
|
|
171
|
+
method: 'GET',
|
|
172
|
+
endpoint: '/file/{fileId}'
|
|
173
|
+
};
|
|
174
|
+
const options = {
|
|
175
|
+
...metadata,
|
|
176
|
+
authContext: {
|
|
177
|
+
collectionName: params.collection
|
|
178
|
+
},
|
|
179
|
+
params,
|
|
180
|
+
traceContext
|
|
181
|
+
};
|
|
182
|
+
return this.request(`/file/${fileId}`, options).then(createMapResponseToJson(metadata));
|
|
183
|
+
}
|
|
184
|
+
async getFileImageURL(id, params) {
|
|
185
|
+
const {
|
|
186
|
+
collection: collectionName
|
|
187
|
+
} = params || {};
|
|
188
|
+
const auth = await this.resolveAuth({
|
|
189
|
+
collectionName
|
|
190
|
+
});
|
|
191
|
+
return this.createFileImageURL(id, auth, params);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// TODO Create ticket in case Trace Id can be supported through query params
|
|
195
|
+
getFileImageURLSync(id, params) {
|
|
196
|
+
const auth = this.resolveInitialAuth();
|
|
197
|
+
return this.createFileImageURL(id, auth, params);
|
|
198
|
+
}
|
|
199
|
+
createFileImageURL(id, auth, params) {
|
|
200
|
+
const options = {
|
|
201
|
+
params: extendImageParams(params),
|
|
202
|
+
auth
|
|
203
|
+
};
|
|
204
|
+
return createUrl(`${auth.baseUrl}/file/${id}/image`, options);
|
|
205
|
+
}
|
|
206
|
+
async getFileBinaryURL(id, collectionName) {
|
|
207
|
+
const auth = await this.resolveAuth({
|
|
208
|
+
collectionName
|
|
209
|
+
});
|
|
210
|
+
const options = {
|
|
211
|
+
params: {
|
|
212
|
+
dl: true,
|
|
213
|
+
collection: collectionName,
|
|
214
|
+
'max-age': FILE_CACHE_MAX_AGE
|
|
215
|
+
},
|
|
216
|
+
auth
|
|
217
|
+
};
|
|
218
|
+
return createUrl(`${auth.baseUrl}/file/${id}/binary`, options);
|
|
219
|
+
}
|
|
220
|
+
async getArtifactURL(artifacts, artifactName, collectionName) {
|
|
221
|
+
const artifactUrl = getArtifactUrl(artifacts, artifactName);
|
|
222
|
+
if (!artifactUrl) {
|
|
223
|
+
throw new Error(`artifact ${artifactName} not found`);
|
|
224
|
+
}
|
|
225
|
+
const auth = await this.resolveAuth({
|
|
226
|
+
collectionName
|
|
227
|
+
});
|
|
228
|
+
const options = {
|
|
229
|
+
params: {
|
|
230
|
+
collection: collectionName,
|
|
231
|
+
'max-age': FILE_CACHE_MAX_AGE
|
|
232
|
+
},
|
|
233
|
+
auth
|
|
234
|
+
};
|
|
235
|
+
return createUrl(`${auth.baseUrl}${artifactUrl}`, options);
|
|
236
|
+
}
|
|
237
|
+
async getImage(id, params, controller, fetchMaxRes, traceContext) {
|
|
238
|
+
// TODO add checkWebpSupport() back https://product-fabric.atlassian.net/browse/MPT-584
|
|
239
|
+
const isWebpSupported = false;
|
|
240
|
+
const headers = {};
|
|
241
|
+
if (isWebpSupported) {
|
|
242
|
+
headers.accept = 'image/webp,image/*,*/*;q=0.8';
|
|
243
|
+
}
|
|
244
|
+
const metadata = {
|
|
245
|
+
method: 'GET',
|
|
246
|
+
endpoint: '/file/{fileId}/image'
|
|
247
|
+
};
|
|
248
|
+
const options = {
|
|
249
|
+
...metadata,
|
|
250
|
+
authContext: {
|
|
251
|
+
collectionName: params && params.collection
|
|
252
|
+
},
|
|
253
|
+
params: extendImageParams(params, fetchMaxRes),
|
|
254
|
+
headers,
|
|
255
|
+
traceContext
|
|
256
|
+
};
|
|
257
|
+
return this.request(`/file/${id}/image`, options, controller).then(createMapResponseToBlob(metadata));
|
|
258
|
+
}
|
|
259
|
+
async getItems(ids, collectionName, traceContext) {
|
|
260
|
+
const descriptors = ids.map(id => ({
|
|
261
|
+
type: 'file',
|
|
262
|
+
id,
|
|
263
|
+
collection: collectionName
|
|
264
|
+
}));
|
|
265
|
+
const metadata = {
|
|
266
|
+
method: 'POST',
|
|
267
|
+
endpoint: '/items'
|
|
268
|
+
};
|
|
269
|
+
const options = {
|
|
270
|
+
...metadata,
|
|
271
|
+
authContext: {
|
|
272
|
+
collectionName
|
|
273
|
+
},
|
|
274
|
+
headers: jsonHeaders,
|
|
275
|
+
body: JSON.stringify({
|
|
276
|
+
descriptors
|
|
277
|
+
}),
|
|
278
|
+
traceContext
|
|
279
|
+
};
|
|
280
|
+
return this.request('/items', options).then(createMapResponseToJson(metadata));
|
|
281
|
+
}
|
|
282
|
+
async getImageMetadata(id, params, traceContext) {
|
|
283
|
+
const metadata = {
|
|
284
|
+
method: 'GET',
|
|
285
|
+
endpoint: '/file/{fileId}/image/metadata'
|
|
286
|
+
};
|
|
287
|
+
const options = {
|
|
288
|
+
...metadata,
|
|
289
|
+
authContext: {
|
|
290
|
+
collectionName: params && params.collection
|
|
291
|
+
},
|
|
292
|
+
params,
|
|
293
|
+
traceContext
|
|
294
|
+
};
|
|
295
|
+
return this.request(`/file/${id}/image/metadata`, options).then(createMapResponseToJson(metadata));
|
|
296
|
+
}
|
|
297
|
+
async appendChunksToUpload(uploadId, body, collectionName, traceContext) {
|
|
298
|
+
const metadata = {
|
|
299
|
+
method: 'PUT',
|
|
300
|
+
endpoint: '/upload/{uploadId}/chunks'
|
|
301
|
+
};
|
|
302
|
+
const options = {
|
|
303
|
+
...metadata,
|
|
304
|
+
authContext: {
|
|
305
|
+
collectionName
|
|
306
|
+
},
|
|
307
|
+
headers: jsonHeaders,
|
|
308
|
+
body: JSON.stringify(body),
|
|
309
|
+
traceContext
|
|
310
|
+
};
|
|
311
|
+
await this.request(`/upload/${uploadId}/chunks`, options);
|
|
312
|
+
}
|
|
313
|
+
copyFileWithToken(body, params, traceContext) {
|
|
314
|
+
const metadata = {
|
|
315
|
+
method: 'POST',
|
|
316
|
+
endpoint: '/file/copy/withToken'
|
|
317
|
+
};
|
|
318
|
+
const options = {
|
|
319
|
+
...metadata,
|
|
320
|
+
authContext: {
|
|
321
|
+
collectionName: params.collection
|
|
322
|
+
},
|
|
323
|
+
// Contains collection name to write to
|
|
324
|
+
params,
|
|
325
|
+
// Contains collection name to write to
|
|
326
|
+
headers: jsonHeaders,
|
|
327
|
+
body: JSON.stringify(body),
|
|
328
|
+
// Contains collection name to read from
|
|
329
|
+
traceContext
|
|
330
|
+
};
|
|
331
|
+
return this.request('/file/copy/withToken', options).then(createMapResponseToJson(metadata));
|
|
332
|
+
}
|
|
333
|
+
async request(path, options = {
|
|
334
|
+
method: 'GET',
|
|
335
|
+
endpoint: undefined,
|
|
336
|
+
authContext: {}
|
|
337
|
+
}, controller) {
|
|
338
|
+
const {
|
|
339
|
+
method,
|
|
340
|
+
endpoint,
|
|
341
|
+
authContext,
|
|
342
|
+
params,
|
|
343
|
+
headers,
|
|
344
|
+
body,
|
|
345
|
+
clientOptions,
|
|
346
|
+
traceContext
|
|
347
|
+
} = options;
|
|
348
|
+
const auth = await this.resolveAuth(authContext);
|
|
349
|
+
const extendedTraceContext = traceContext ? {
|
|
350
|
+
...traceContext,
|
|
351
|
+
spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || getRandomHex(8)
|
|
352
|
+
} : undefined;
|
|
353
|
+
const response = await request(`${auth.baseUrl}${path}`, {
|
|
354
|
+
method,
|
|
355
|
+
endpoint,
|
|
356
|
+
auth,
|
|
357
|
+
params,
|
|
358
|
+
headers,
|
|
359
|
+
body,
|
|
360
|
+
clientOptions,
|
|
361
|
+
traceContext: extendedTraceContext
|
|
362
|
+
}, controller);
|
|
363
|
+
setKeyValueInSessionStorage(MEDIA_API_REGION, response.headers.get('x-media-region'));
|
|
364
|
+
setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
|
|
365
|
+
return response;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
const getValueFromSessionStorage = key => {
|
|
369
|
+
return window && window.sessionStorage && window.sessionStorage.getItem(key) || undefined;
|
|
370
|
+
};
|
|
371
|
+
const setKeyValueInSessionStorage = (key, value) => {
|
|
372
|
+
if (!value || !(window && window.sessionStorage)) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
const currentValue = window.sessionStorage.getItem(key);
|
|
376
|
+
if (currentValue !== value) {
|
|
377
|
+
window.sessionStorage.setItem(key, value);
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
export const getMediaEnvironment = () => {
|
|
381
|
+
return getValueFromSessionStorage(MEDIA_API_ENVIRONMENT);
|
|
382
|
+
};
|
|
383
|
+
export const getMediaRegion = () => {
|
|
384
|
+
return getValueFromSessionStorage(MEDIA_API_REGION);
|
|
385
|
+
};
|