@atlaskit/media-client 37.7.6 → 38.0.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 CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/media-client
2
2
 
3
+ ## 38.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [`59efe37532b46`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/59efe37532b46) -
8
+ `UploadableFile.size` is now a required field instead of optional, and the size is consistently
9
+ forwarded to downstream services.
10
+
11
+ Because `size` is now always available, `createFileFromUpload` sends `conditions.size` in the
12
+ request body unconditionally, instead of only sending it when the size happened to be truthy. This
13
+ lets downstream services validate the number of bytes they received against the size the client
14
+ declared, rather than accepting an upload whose expected size is unknown.
15
+
16
+ Accordingly, `MediaStoreCreateFileFromUploadBody.conditions` and its `size` are now required
17
+ rather than optional.
18
+
3
19
  ## 37.7.6
4
20
 
5
21
  ### Patch Changes
@@ -99,28 +99,23 @@ var createProcessingFunction = function createProcessingFunction(store, deferred
99
99
  };
100
100
  var createFileFromUpload = /*#__PURE__*/function () {
101
101
  var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(file, store, uploadableFileUpfrontIds, uploadId, traceContext) {
102
- var collection, name, mimeType, content, id, occurrenceKey, body;
102
+ var collection, name, mimeType, content, id, occurrenceKey;
103
103
  return _regenerator.default.wrap(function (_context4) {
104
104
  while (1) switch (_context4.prev = _context4.next) {
105
105
  case 0:
106
106
  collection = file.collection, name = file.name, mimeType = file.mimeType, content = file.content;
107
107
  id = uploadableFileUpfrontIds.id, occurrenceKey = uploadableFileUpfrontIds.occurrenceKey; // If the file is a Blob and the size is not passed from consumer, set the file size from file content
108
108
  if (content instanceof Blob && !file.size) {
109
- file.size = content === null || content === void 0 ? void 0 : content.size;
109
+ file.size = content.size;
110
110
  }
111
- body = file.size ? {
111
+ return _context4.abrupt("return", store.createFileFromUpload({
112
112
  uploadId: uploadId,
113
113
  name: name,
114
114
  mimeType: mimeType,
115
115
  conditions: {
116
116
  size: file.size
117
117
  }
118
- } : {
119
- uploadId: uploadId,
120
- name: name,
121
- mimeType: mimeType
122
- };
123
- return _context4.abrupt("return", store.createFileFromUpload(body, {
118
+ }, {
124
119
  occurrenceKey: occurrenceKey,
125
120
  collection: collection,
126
121
  replaceFileId: id
@@ -41,21 +41,16 @@ const createFileFromUpload = async (file, store, uploadableFileUpfrontIds, uploa
41
41
 
42
42
  // If the file is a Blob and the size is not passed from consumer, set the file size from file content
43
43
  if (content instanceof Blob && !file.size) {
44
- file.size = content === null || content === void 0 ? void 0 : content.size;
44
+ file.size = content.size;
45
45
  }
46
- const body = file.size ? {
46
+ return store.createFileFromUpload({
47
47
  uploadId,
48
48
  name,
49
49
  mimeType,
50
50
  conditions: {
51
51
  size: file.size
52
52
  }
53
- } : {
54
- uploadId,
55
- name,
56
- mimeType
57
- };
58
- return store.createFileFromUpload(body, {
53
+ }, {
59
54
  occurrenceKey,
60
55
  collection,
61
56
  replaceFileId: id
@@ -93,28 +93,23 @@ var createProcessingFunction = function createProcessingFunction(store, deferred
93
93
  };
94
94
  var createFileFromUpload = /*#__PURE__*/function () {
95
95
  var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(file, store, uploadableFileUpfrontIds, uploadId, traceContext) {
96
- var collection, name, mimeType, content, id, occurrenceKey, body;
96
+ var collection, name, mimeType, content, id, occurrenceKey;
97
97
  return _regeneratorRuntime.wrap(function (_context4) {
98
98
  while (1) switch (_context4.prev = _context4.next) {
99
99
  case 0:
100
100
  collection = file.collection, name = file.name, mimeType = file.mimeType, content = file.content;
101
101
  id = uploadableFileUpfrontIds.id, occurrenceKey = uploadableFileUpfrontIds.occurrenceKey; // If the file is a Blob and the size is not passed from consumer, set the file size from file content
102
102
  if (content instanceof Blob && !file.size) {
103
- file.size = content === null || content === void 0 ? void 0 : content.size;
103
+ file.size = content.size;
104
104
  }
105
- body = file.size ? {
105
+ return _context4.abrupt("return", store.createFileFromUpload({
106
106
  uploadId: uploadId,
107
107
  name: name,
108
108
  mimeType: mimeType,
109
109
  conditions: {
110
110
  size: file.size
111
111
  }
112
- } : {
113
- uploadId: uploadId,
114
- name: name,
115
- mimeType: mimeType
116
- };
117
- return _context4.abrupt("return", store.createFileFromUpload(body, {
112
+ }, {
118
113
  occurrenceKey: occurrenceKey,
119
114
  collection: collection,
120
115
  replaceFileId: id
@@ -82,13 +82,13 @@ export type MediaStoreCreateFileFromBinaryParams = {
82
82
  };
83
83
  export type MediaStoreCreateFileFromUploadConditions = {
84
84
  readonly hash?: string;
85
- readonly size?: number;
85
+ readonly size: number;
86
86
  };
87
87
  export type MediaStoreCreateFileFromUploadBody = {
88
88
  readonly uploadId: string;
89
89
  readonly name?: string;
90
90
  readonly mimeType?: string;
91
- readonly conditions?: MediaStoreCreateFileFromUploadConditions;
91
+ readonly conditions: MediaStoreCreateFileFromUploadConditions;
92
92
  };
93
93
  export type MediaStoreGetFileParams = {
94
94
  readonly version?: number;
@@ -6,7 +6,7 @@ export type UploadableFile = {
6
6
  name?: string;
7
7
  mimeType?: string;
8
8
  collection?: string;
9
- size?: number;
9
+ size: number;
10
10
  };
11
11
  export type UploadableFileUpfrontIds = {
12
12
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/media-client",
3
- "version": "37.7.6",
3
+ "version": "38.0.0",
4
4
  "description": "Media API Web Client Library",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"