@atlaskit/media-common 13.1.0 → 13.2.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,19 @@
1
1
  # @atlaskit/media-common
2
2
 
3
+ ## 13.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`5653e8be24c05`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/5653e8be24c05) -
8
+ Replace `uuid-validate` with an inlined, browser-only `isValidUuid` helper in
9
+ `@atlaskit/media-common`. Removes the `uuid-validate` dependency from `media-card`,
10
+ `media-client`, `media-common` and `media-picker` so consumers no longer pull in the Node `Buffer`
11
+ polyfill purely for a `Buffer.isBuffer` check that always returned `false` in the browser.
12
+
13
+ Adds a new `@atlaskit/media-common/isValidUuid` subpath export so consumers can import the helper
14
+ without going through the package's barrel file (in line with the Debarreling Platform Packages
15
+ initiative).
16
+
3
17
  ## 13.1.0
4
18
 
5
19
  ### Minor Changes
@@ -6,11 +6,11 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.sanitiseAnalyticsPayload = void 0;
8
8
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
- var _uuidValidate = _interopRequireDefault(require("uuid-validate"));
10
9
  var _immer = require("immer");
10
+ var _isValidUuid = require("../utils/isValidUuid");
11
11
  var sanitiseFileId = function sanitiseFileId(draft) {
12
12
  var fileId = draft.attributes.fileAttributes.fileId;
13
- draft.attributes.fileAttributes.fileId = fileId === 'external-image' || (0, _uuidValidate.default)(fileId) ? fileId : 'INVALID_FILE_ID';
13
+ draft.attributes.fileAttributes.fileId = fileId === 'external-image' || (0, _isValidUuid.isValidUuid)(fileId) ? fileId : 'INVALID_FILE_ID';
14
14
  };
15
15
  var hasFileAttributesWithFileId = function hasFileAttributesWithFileId(payload) {
16
16
  return 'attributes' in payload && !!payload.attributes && (0, _typeof2.default)(payload.attributes) === 'object' && 'fileAttributes' in payload.attributes && !!payload.attributes.fileAttributes && (0, _typeof2.default)(payload.attributes.fileAttributes) === 'object' && 'fileId' in payload.attributes.fileAttributes && typeof payload.attributes.fileAttributes.fileId === 'string';
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isValidUuid = void 0;
7
+ var BASIC_UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
8
+
9
+ // Modified copy of `uuid-validate` package
10
+ var isValidUuid = exports.isValidUuid = function isValidUuid(value) {
11
+ if (typeof value !== 'string') {
12
+ return false;
13
+ }
14
+ var normalizedValue = value.toLowerCase();
15
+ if (!BASIC_UUID_REGEX.test(normalizedValue)) {
16
+ return false;
17
+ }
18
+ var version = normalizedValue[14];
19
+ if (version === '1' || version === '2') {
20
+ return true;
21
+ }
22
+ if (version === '3' || version === '4' || version === '5') {
23
+ var variant = normalizedValue[19];
24
+ return variant === '8' || variant === '9' || variant === 'a' || variant === 'b';
25
+ }
26
+ return false;
27
+ };
@@ -1,10 +1,10 @@
1
- import isValidId from 'uuid-validate';
2
1
  import { produce } from 'immer';
2
+ import { isValidUuid } from '../utils/isValidUuid';
3
3
  const sanitiseFileId = draft => {
4
4
  const {
5
5
  fileId
6
6
  } = draft.attributes.fileAttributes;
7
- draft.attributes.fileAttributes.fileId = fileId === 'external-image' || isValidId(fileId) ? fileId : 'INVALID_FILE_ID';
7
+ draft.attributes.fileAttributes.fileId = fileId === 'external-image' || isValidUuid(fileId) ? fileId : 'INVALID_FILE_ID';
8
8
  };
9
9
  const hasFileAttributesWithFileId = payload => 'attributes' in payload && !!payload.attributes && typeof payload.attributes === 'object' && 'fileAttributes' in payload.attributes && !!payload.attributes.fileAttributes && typeof payload.attributes.fileAttributes === 'object' && 'fileId' in payload.attributes.fileAttributes && typeof payload.attributes.fileAttributes.fileId === 'string';
10
10
  export const sanitiseAnalyticsPayload = payload => hasFileAttributesWithFileId(payload) ? produce(payload, sanitiseFileId) : payload;
@@ -0,0 +1,21 @@
1
+ const BASIC_UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
2
+
3
+ // Modified copy of `uuid-validate` package
4
+ export const isValidUuid = value => {
5
+ if (typeof value !== 'string') {
6
+ return false;
7
+ }
8
+ const normalizedValue = value.toLowerCase();
9
+ if (!BASIC_UUID_REGEX.test(normalizedValue)) {
10
+ return false;
11
+ }
12
+ const version = normalizedValue[14];
13
+ if (version === '1' || version === '2') {
14
+ return true;
15
+ }
16
+ if (version === '3' || version === '4' || version === '5') {
17
+ const variant = normalizedValue[19];
18
+ return variant === '8' || variant === '9' || variant === 'a' || variant === 'b';
19
+ }
20
+ return false;
21
+ };
@@ -1,9 +1,9 @@
1
1
  import _typeof from "@babel/runtime/helpers/typeof";
2
- import isValidId from 'uuid-validate';
3
2
  import { produce } from 'immer';
3
+ import { isValidUuid } from '../utils/isValidUuid';
4
4
  var sanitiseFileId = function sanitiseFileId(draft) {
5
5
  var fileId = draft.attributes.fileAttributes.fileId;
6
- draft.attributes.fileAttributes.fileId = fileId === 'external-image' || isValidId(fileId) ? fileId : 'INVALID_FILE_ID';
6
+ draft.attributes.fileAttributes.fileId = fileId === 'external-image' || isValidUuid(fileId) ? fileId : 'INVALID_FILE_ID';
7
7
  };
8
8
  var hasFileAttributesWithFileId = function hasFileAttributesWithFileId(payload) {
9
9
  return 'attributes' in payload && !!payload.attributes && _typeof(payload.attributes) === 'object' && 'fileAttributes' in payload.attributes && !!payload.attributes.fileAttributes && _typeof(payload.attributes.fileAttributes) === 'object' && 'fileId' in payload.attributes.fileAttributes && typeof payload.attributes.fileAttributes.fileId === 'string';
@@ -0,0 +1,21 @@
1
+ var BASIC_UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
2
+
3
+ // Modified copy of `uuid-validate` package
4
+ export var isValidUuid = function isValidUuid(value) {
5
+ if (typeof value !== 'string') {
6
+ return false;
7
+ }
8
+ var normalizedValue = value.toLowerCase();
9
+ if (!BASIC_UUID_REGEX.test(normalizedValue)) {
10
+ return false;
11
+ }
12
+ var version = normalizedValue[14];
13
+ if (version === '1' || version === '2') {
14
+ return true;
15
+ }
16
+ if (version === '3' || version === '4' || version === '5') {
17
+ var variant = normalizedValue[19];
18
+ return variant === '8' || variant === '9' || variant === 'a' || variant === 'b';
19
+ }
20
+ return false;
21
+ };
@@ -0,0 +1 @@
1
+ export declare const isValidUuid: (value: unknown) => value is string;
@@ -0,0 +1 @@
1
+ export declare const isValidUuid: (value: unknown) => value is string;
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@atlaskit/media-common/isValidUuid",
3
+ "main": "../dist/cjs/utils/isValidUuid.js",
4
+ "module": "../dist/esm/utils/isValidUuid.js",
5
+ "module:es2019": "../dist/es2019/utils/isValidUuid.js",
6
+ "sideEffects": false,
7
+ "types": "../dist/types/utils/isValidUuid.d.ts",
8
+ "typesVersions": {
9
+ ">=4.5 <5.9": {
10
+ "*": [
11
+ "../dist/types-ts4.5/utils/isValidUuid.d.ts"
12
+ ]
13
+ }
14
+ }
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/media-common",
3
- "version": "13.1.0",
3
+ "version": "13.2.0",
4
4
  "description": "Includes common utilities used by other media packages",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -35,8 +35,7 @@
35
35
  "@atlaskit/link": "^3.4.0",
36
36
  "@atlaskit/section-message": "^8.12.0",
37
37
  "@babel/runtime": "^7.0.0",
38
- "immer": "11.1.4",
39
- "uuid-validate": "^0.0.3"
38
+ "immer": "11.1.4"
40
39
  },
41
40
  "peerDependencies": {
42
41
  "enzyme": ">=3.10.0",
@@ -49,7 +48,6 @@
49
48
  }
50
49
  },
51
50
  "devDependencies": {
52
- "@types/uuid-validate": "^0.0.2",
53
51
  "enzyme": "^3.10.0",
54
52
  "react": "^18.2.0",
55
53
  "react-dom": "^18.2.0"