@atlaskit/media-client 33.3.2 → 33.4.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 +18 -0
- package/dist/cjs/client/file-fetcher/index.js +213 -180
- package/dist/cjs/client/media-client.js +1 -2
- package/dist/cjs/client/media-store/MediaStore.js +233 -130
- package/dist/cjs/models/document.js +1 -0
- package/dist/cjs/utils/createCopyIntentRegisterationBatcher.js +2 -2
- package/dist/cjs/utils/createFileDataLoader.js +2 -2
- package/dist/cjs/utils/hashing/hasherCreator.js +1 -2
- package/dist/cjs/utils/hashing/simpleHasher.js +1 -2
- package/dist/cjs/utils/request/helpers.js +1 -1
- package/dist/es2019/client/file-fetcher/index.js +20 -0
- package/dist/es2019/client/media-store/MediaStore.js +57 -0
- package/dist/es2019/models/document.js +0 -0
- package/dist/es2019/utils/createCopyIntentRegisterationBatcher.js +3 -3
- package/dist/es2019/utils/createFileDataLoader.js +3 -3
- package/dist/es2019/utils/request/helpers.js +2 -2
- package/dist/esm/client/file-fetcher/index.js +213 -180
- package/dist/esm/client/media-store/MediaStore.js +233 -130
- package/dist/esm/models/document.js +0 -0
- package/dist/esm/utils/createCopyIntentRegisterationBatcher.js +3 -3
- package/dist/esm/utils/createFileDataLoader.js +3 -3
- package/dist/esm/utils/request/helpers.js +2 -2
- package/dist/types/client/file-fetcher/index.d.ts +3 -1
- package/dist/types/client/media-store/MediaStore.d.ts +4 -0
- package/dist/types/client/media-store/types.d.ts +9 -0
- package/dist/types/models/document.d.ts +54 -0
- package/dist/types-ts4.5/client/file-fetcher/index.d.ts +3 -1
- package/dist/types-ts4.5/client/media-store/MediaStore.d.ts +4 -0
- package/dist/types-ts4.5/client/media-store/types.d.ts +9 -0
- package/dist/types-ts4.5/models/document.d.ts +54 -0
- package/package.json +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -51,8 +51,8 @@ function createBatchCopyIntentRegisterationFunc(mediaStore) {
|
|
|
51
51
|
while (1) switch (_context.prev = _context.next) {
|
|
52
52
|
case 0:
|
|
53
53
|
metadataTraceContext = {
|
|
54
|
-
traceId: (0, _mediaCommon.
|
|
55
|
-
spanId: (0, _mediaCommon.
|
|
54
|
+
traceId: (0, _mediaCommon.getRandomTelemetryId)(),
|
|
55
|
+
spanId: (0, _mediaCommon.getRandomTelemetryId)()
|
|
56
56
|
};
|
|
57
57
|
files = keysByToken[batchKey].map(function (key) {
|
|
58
58
|
return {
|
|
@@ -101,8 +101,8 @@ function createBatchLoadingFunc(mediaStore) {
|
|
|
101
101
|
while (1) switch (_context.prev = _context.next) {
|
|
102
102
|
case 0:
|
|
103
103
|
metadataTraceContext = {
|
|
104
|
-
traceId: (0, _mediaCommon.
|
|
105
|
-
spanId: (0, _mediaCommon.
|
|
104
|
+
traceId: (0, _mediaCommon.getRandomTelemetryId)(),
|
|
105
|
+
spanId: (0, _mediaCommon.getRandomTelemetryId)()
|
|
106
106
|
};
|
|
107
107
|
fileIds = fileIdsByCollection[collectionNameKey];
|
|
108
108
|
includeHashForDuplicateFiles = includeHashByCollection[collectionNameKey];
|
|
@@ -9,8 +9,7 @@ exports.destroyHashers = exports.createHasher = void 0;
|
|
|
9
9
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
10
10
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
11
|
var _mediaCore = require("@atlaskit/media-core");
|
|
12
|
-
function
|
|
13
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
14
13
|
var hasher = null;
|
|
15
14
|
var sha256Hasher = null;
|
|
16
15
|
var destroyHashers = exports.destroyHashers = function destroyHashers() {
|
|
@@ -9,8 +9,7 @@ exports.SimpleHasher = void 0;
|
|
|
9
9
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
10
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
11
|
var Rusha = _interopRequireWildcard(require("rusha"));
|
|
12
|
-
function
|
|
13
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
14
13
|
var SimpleHasher = exports.SimpleHasher = /*#__PURE__*/function () {
|
|
15
14
|
function SimpleHasher() {
|
|
16
15
|
(0, _classCallCheck2.default)(this, SimpleHasher);
|
|
@@ -56,7 +56,7 @@ function isRateLimitedError(error) {
|
|
|
56
56
|
}
|
|
57
57
|
var extendTraceContext = exports.extendTraceContext = function extendTraceContext(traceContext) {
|
|
58
58
|
return traceContext ? _objectSpread(_objectSpread({}, traceContext), {}, {
|
|
59
|
-
spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || (0, _mediaCommon.
|
|
59
|
+
spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || (0, _mediaCommon.getRandomTelemetryId)()
|
|
60
60
|
}) : undefined;
|
|
61
61
|
};
|
|
62
62
|
var ZipkinHeaderKeys = exports.ZipkinHeaderKeys = {
|
|
@@ -155,6 +155,26 @@ export class FileFetcherImpl {
|
|
|
155
155
|
this.setFileState(id, mapMediaItemToFileState(id, itemDetails));
|
|
156
156
|
return data;
|
|
157
157
|
});
|
|
158
|
+
_defineProperty(this, "deleteArtifact", async (id, params, collectionName, traceContext) => {
|
|
159
|
+
// TODO: Uncomment JEST check after endpoint is fixed
|
|
160
|
+
if (process.env.NODE_ENV === 'test') {
|
|
161
|
+
await this.mediaApi.deleteArtifact(id, params, collectionName, traceContext);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Manually remove the artifact from file state instead of re-requesting the entire payload.
|
|
165
|
+
const file = this.store.getState().files[id];
|
|
166
|
+
if (file && file.status === 'processed' && file.artifacts) {
|
|
167
|
+
const updatedArtifacts = {
|
|
168
|
+
...file.artifacts
|
|
169
|
+
};
|
|
170
|
+
delete updatedArtifacts[params.artifactName];
|
|
171
|
+
const updatedFileState = {
|
|
172
|
+
...file,
|
|
173
|
+
artifacts: updatedArtifacts
|
|
174
|
+
};
|
|
175
|
+
this.setFileState(id, updatedFileState);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
158
178
|
_defineProperty(this, "getOrFetchFileState", async (id, collectionName) => {
|
|
159
179
|
let fileState = this.store.getState().files[id];
|
|
160
180
|
return fileState !== null && fileState !== void 0 ? fileState : await this.getCurrentState(id, {
|
|
@@ -86,6 +86,26 @@ export class MediaStore {
|
|
|
86
86
|
};
|
|
87
87
|
return this.request(`/file/${id}/artifact/binary`, options).then(createMapResponseToJson(metadata));
|
|
88
88
|
});
|
|
89
|
+
_defineProperty(this, "deleteArtifact", async (id, params, collectionName, traceContext) => {
|
|
90
|
+
const metadata = {
|
|
91
|
+
method: 'DELETE',
|
|
92
|
+
endpoint: '/file/{fileId}/artifact/{artifactName}'
|
|
93
|
+
};
|
|
94
|
+
const authContext = {
|
|
95
|
+
collectionName,
|
|
96
|
+
access: [{
|
|
97
|
+
type: 'file',
|
|
98
|
+
id,
|
|
99
|
+
actions: ['update']
|
|
100
|
+
}]
|
|
101
|
+
};
|
|
102
|
+
const options = {
|
|
103
|
+
...metadata,
|
|
104
|
+
authContext,
|
|
105
|
+
traceContext
|
|
106
|
+
};
|
|
107
|
+
await this.request(`/file/${id}/artifact/${params.artifactName}`, options);
|
|
108
|
+
});
|
|
89
109
|
_defineProperty(this, "resolveAuth", authContext => resolveAuth(this.config.authProvider, authContext, this.config.authProviderTimeout));
|
|
90
110
|
_defineProperty(this, "resolveInitialAuth", () => resolveInitialAuth(this.config.initialAuth));
|
|
91
111
|
this.config = config;
|
|
@@ -374,6 +394,43 @@ export class MediaStore {
|
|
|
374
394
|
};
|
|
375
395
|
return this.request(`/file/${id}/image/metadata`, options).then(createMapResponseToJson(metadata));
|
|
376
396
|
}
|
|
397
|
+
async getDocumentContent(id, options) {
|
|
398
|
+
const metadata = {
|
|
399
|
+
method: 'GET',
|
|
400
|
+
endpoint: '/file/{fileId}/document/contents'
|
|
401
|
+
};
|
|
402
|
+
const requestOptions = {
|
|
403
|
+
...metadata,
|
|
404
|
+
authContext: {
|
|
405
|
+
collectionName: options.collectionName
|
|
406
|
+
},
|
|
407
|
+
params: {
|
|
408
|
+
pageStart: options.pageStart,
|
|
409
|
+
pageEnd: options.pageEnd,
|
|
410
|
+
'max-age': FILE_CACHE_MAX_AGE
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
return this.request(`/file/${id}/document/contents`, requestOptions).then(createMapResponseToJson(metadata));
|
|
414
|
+
}
|
|
415
|
+
async getDocumentPageImage(id, options) {
|
|
416
|
+
const endpoint = cdnFeatureFlag('page');
|
|
417
|
+
const metadata = {
|
|
418
|
+
method: 'GET',
|
|
419
|
+
endpoint: `/file/{fileId}/document/${endpoint}`
|
|
420
|
+
};
|
|
421
|
+
const requestOptions = {
|
|
422
|
+
...metadata,
|
|
423
|
+
authContext: {
|
|
424
|
+
collectionName: options.collectionName
|
|
425
|
+
},
|
|
426
|
+
params: {
|
|
427
|
+
page: options.page,
|
|
428
|
+
zoom: options.zoom,
|
|
429
|
+
'max-age': FILE_CACHE_MAX_AGE
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
return this.request(`/file/${id}/document/${endpoint}`, requestOptions).then(createMapResponseToBlob(metadata));
|
|
433
|
+
}
|
|
377
434
|
async appendChunksToUpload(uploadId, body, collectionName, traceContext) {
|
|
378
435
|
const metadata = {
|
|
379
436
|
method: 'PUT',
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Dataloader from 'dataloader';
|
|
2
|
-
import {
|
|
2
|
+
import { getRandomTelemetryId } from '@atlaskit/media-common';
|
|
3
3
|
export const MAX_BATCH_SIZE = 100;
|
|
4
4
|
/**
|
|
5
5
|
* Returns a function that, given Array<DataloaderKey>, resolves to an array of same length containing either DataloaderResult or Error.
|
|
@@ -29,8 +29,8 @@ function createBatchCopyIntentRegisterationFunc(mediaStore) {
|
|
|
29
29
|
const items = [];
|
|
30
30
|
await Promise.all(Object.keys(keysByToken).map(async batchKey => {
|
|
31
31
|
const metadataTraceContext = {
|
|
32
|
-
traceId:
|
|
33
|
-
spanId:
|
|
32
|
+
traceId: getRandomTelemetryId(),
|
|
33
|
+
spanId: getRandomTelemetryId()
|
|
34
34
|
};
|
|
35
35
|
const files = keysByToken[batchKey].map(key => ({
|
|
36
36
|
id: key.id,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Dataloader from 'dataloader';
|
|
2
|
-
import {
|
|
2
|
+
import { getRandomTelemetryId } from '@atlaskit/media-common';
|
|
3
3
|
export const MAX_BATCH_SIZE = 100;
|
|
4
4
|
const isBatchLoadingErrorResult = result => {
|
|
5
5
|
return result.error instanceof Error;
|
|
@@ -77,8 +77,8 @@ export function createBatchLoadingFunc(mediaStore) {
|
|
|
77
77
|
const items = [];
|
|
78
78
|
await Promise.all(Object.keys(fileIdsByCollection).map(async collectionNameKey => {
|
|
79
79
|
const metadataTraceContext = {
|
|
80
|
-
traceId:
|
|
81
|
-
spanId:
|
|
80
|
+
traceId: getRandomTelemetryId(),
|
|
81
|
+
spanId: getRandomTelemetryId()
|
|
82
82
|
};
|
|
83
83
|
const fileIds = fileIdsByCollection[collectionNameKey];
|
|
84
84
|
const includeHashForDuplicateFiles = includeHashByCollection[collectionNameKey];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isClientBasedAuth } from '@atlaskit/media-core';
|
|
2
|
-
import {
|
|
2
|
+
import { getRandomTelemetryId } from '@atlaskit/media-common';
|
|
3
3
|
import { mapAuthToQueryParameters } from '../../models/auth-query-parameters';
|
|
4
4
|
import { RequestError, isRequestError } from './errors';
|
|
5
5
|
const getStatusCode = error => {
|
|
@@ -23,7 +23,7 @@ export function isRateLimitedError(error) {
|
|
|
23
23
|
}
|
|
24
24
|
export const extendTraceContext = traceContext => traceContext ? {
|
|
25
25
|
...traceContext,
|
|
26
|
-
spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) ||
|
|
26
|
+
spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || getRandomTelemetryId()
|
|
27
27
|
} : undefined;
|
|
28
28
|
export const ZipkinHeaderKeys = {
|
|
29
29
|
traceId: 'x-b3-traceid',
|