@nocobase/plugin-notification-in-app-message 2.1.0-beta.2 → 2.1.0-beta.21

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.
Files changed (104) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +99 -1
  3. package/dist/client/index.js +1 -1
  4. package/dist/externalVersion.js +9 -11
  5. package/dist/node_modules/uuid/dist/bin/uuid +2 -0
  6. package/dist/node_modules/uuid/dist/commonjs-browser/index.js +104 -0
  7. package/dist/node_modules/uuid/dist/commonjs-browser/max.js +7 -0
  8. package/dist/node_modules/uuid/dist/commonjs-browser/md5.js +200 -0
  9. package/dist/node_modules/uuid/dist/commonjs-browser/native.js +10 -0
  10. package/dist/node_modules/uuid/dist/commonjs-browser/nil.js +7 -0
  11. package/dist/node_modules/uuid/dist/commonjs-browser/parse.js +44 -0
  12. package/dist/node_modules/uuid/dist/commonjs-browser/regex.js +7 -0
  13. package/dist/node_modules/uuid/dist/commonjs-browser/rng.js +23 -0
  14. package/dist/node_modules/uuid/dist/commonjs-browser/sha1.js +82 -0
  15. package/dist/node_modules/uuid/dist/commonjs-browser/stringify.js +38 -0
  16. package/dist/node_modules/uuid/dist/commonjs-browser/v1.js +131 -0
  17. package/dist/node_modules/uuid/dist/commonjs-browser/v1ToV6.js +26 -0
  18. package/dist/node_modules/uuid/dist/commonjs-browser/v3.js +11 -0
  19. package/dist/node_modules/uuid/dist/commonjs-browser/v35.js +63 -0
  20. package/dist/node_modules/uuid/dist/commonjs-browser/v4.js +32 -0
  21. package/dist/node_modules/uuid/dist/commonjs-browser/v5.js +11 -0
  22. package/dist/node_modules/uuid/dist/commonjs-browser/v6.js +42 -0
  23. package/dist/node_modules/uuid/dist/commonjs-browser/v6ToV1.js +26 -0
  24. package/dist/node_modules/uuid/dist/commonjs-browser/v7.js +152 -0
  25. package/dist/node_modules/uuid/dist/commonjs-browser/validate.js +12 -0
  26. package/dist/node_modules/uuid/dist/commonjs-browser/version.js +15 -0
  27. package/dist/node_modules/uuid/dist/esm-browser/index.js +14 -0
  28. package/dist/node_modules/uuid/dist/esm-browser/max.js +1 -0
  29. package/dist/node_modules/uuid/dist/esm-browser/md5.js +194 -0
  30. package/dist/node_modules/uuid/dist/esm-browser/native.js +4 -0
  31. package/dist/node_modules/uuid/dist/esm-browser/nil.js +1 -0
  32. package/dist/node_modules/uuid/dist/esm-browser/parse.js +37 -0
  33. package/dist/node_modules/uuid/dist/esm-browser/regex.js +1 -0
  34. package/dist/node_modules/uuid/dist/esm-browser/rng.js +17 -0
  35. package/dist/node_modules/uuid/dist/esm-browser/sha1.js +76 -0
  36. package/dist/node_modules/uuid/dist/esm-browser/stringify.js +31 -0
  37. package/dist/node_modules/uuid/dist/esm-browser/v1.js +125 -0
  38. package/dist/node_modules/uuid/dist/esm-browser/v1ToV6.js +20 -0
  39. package/dist/node_modules/uuid/dist/esm-browser/v3.js +4 -0
  40. package/dist/node_modules/uuid/dist/esm-browser/v35.js +55 -0
  41. package/dist/node_modules/uuid/dist/esm-browser/v4.js +25 -0
  42. package/dist/node_modules/uuid/dist/esm-browser/v5.js +4 -0
  43. package/dist/node_modules/uuid/dist/esm-browser/v6.js +36 -0
  44. package/dist/node_modules/uuid/dist/esm-browser/v6ToV1.js +20 -0
  45. package/dist/node_modules/uuid/dist/esm-browser/v7.js +146 -0
  46. package/dist/node_modules/uuid/dist/esm-browser/validate.js +5 -0
  47. package/dist/node_modules/uuid/dist/esm-browser/version.js +8 -0
  48. package/dist/node_modules/uuid/dist/esm-node/index.js +14 -0
  49. package/dist/node_modules/uuid/dist/esm-node/max.js +1 -0
  50. package/dist/node_modules/uuid/dist/esm-node/md5.js +10 -0
  51. package/dist/node_modules/uuid/dist/esm-node/native.js +4 -0
  52. package/dist/node_modules/uuid/dist/esm-node/nil.js +1 -0
  53. package/dist/node_modules/uuid/dist/esm-node/parse.js +37 -0
  54. package/dist/node_modules/uuid/dist/esm-node/regex.js +1 -0
  55. package/dist/node_modules/uuid/dist/esm-node/rng.js +10 -0
  56. package/dist/node_modules/uuid/dist/esm-node/sha1.js +10 -0
  57. package/dist/node_modules/uuid/dist/esm-node/stringify.js +31 -0
  58. package/dist/node_modules/uuid/dist/esm-node/v1.js +125 -0
  59. package/dist/node_modules/uuid/dist/esm-node/v1ToV6.js +20 -0
  60. package/dist/node_modules/uuid/dist/esm-node/v3.js +4 -0
  61. package/dist/node_modules/uuid/dist/esm-node/v35.js +55 -0
  62. package/dist/node_modules/uuid/dist/esm-node/v4.js +25 -0
  63. package/dist/node_modules/uuid/dist/esm-node/v5.js +4 -0
  64. package/dist/node_modules/uuid/dist/esm-node/v6.js +32 -0
  65. package/dist/node_modules/uuid/dist/esm-node/v6ToV1.js +20 -0
  66. package/dist/node_modules/uuid/dist/esm-node/v7.js +146 -0
  67. package/dist/node_modules/uuid/dist/esm-node/validate.js +5 -0
  68. package/dist/node_modules/uuid/dist/esm-node/version.js +8 -0
  69. package/dist/node_modules/uuid/dist/index.js +1 -0
  70. package/dist/node_modules/uuid/dist/max.js +7 -0
  71. package/dist/node_modules/uuid/dist/md5-browser.js +200 -0
  72. package/dist/node_modules/uuid/dist/md5.js +17 -0
  73. package/dist/node_modules/uuid/dist/native-browser.js +10 -0
  74. package/dist/node_modules/uuid/dist/native.js +11 -0
  75. package/dist/node_modules/uuid/dist/nil.js +7 -0
  76. package/dist/node_modules/uuid/dist/parse.js +44 -0
  77. package/dist/node_modules/uuid/dist/regex.js +7 -0
  78. package/dist/node_modules/uuid/dist/rng-browser.js +23 -0
  79. package/dist/node_modules/uuid/dist/rng.js +17 -0
  80. package/dist/node_modules/uuid/dist/sha1-browser.js +82 -0
  81. package/dist/node_modules/uuid/dist/sha1.js +17 -0
  82. package/dist/node_modules/uuid/dist/stringify.js +38 -0
  83. package/dist/node_modules/uuid/dist/uuid-bin.js +75 -0
  84. package/dist/node_modules/uuid/dist/v1.js +131 -0
  85. package/dist/node_modules/uuid/dist/v1ToV6.js +26 -0
  86. package/dist/node_modules/uuid/dist/v3.js +11 -0
  87. package/dist/node_modules/uuid/dist/v35.js +63 -0
  88. package/dist/node_modules/uuid/dist/v4.js +32 -0
  89. package/dist/node_modules/uuid/dist/v5.js +11 -0
  90. package/dist/node_modules/uuid/dist/v6.js +38 -0
  91. package/dist/node_modules/uuid/dist/v6ToV1.js +26 -0
  92. package/dist/node_modules/uuid/dist/v7.js +152 -0
  93. package/dist/node_modules/uuid/dist/validate.js +12 -0
  94. package/dist/node_modules/uuid/dist/version.js +15 -0
  95. package/dist/node_modules/uuid/package.json +1 -0
  96. package/dist/server/InAppNotificationChannel.d.ts +5 -0
  97. package/dist/server/InAppNotificationChannel.js +93 -35
  98. package/dist/server/defineMyInAppMessages.js +2 -1
  99. package/dist/server/parseUserSelectionConf.d.ts +2 -1
  100. package/dist/server/parseUserSelectionConf.js +3 -2
  101. package/package.json +5 -2
  102. package/LICENSE.txt +0 -172
  103. package/dist/client/components/UsersAddition.d.ts +0 -10
  104. package/dist/client/components/UsersSelect.d.ts +0 -18
@@ -0,0 +1,146 @@
1
+ import rng from './rng.js';
2
+ import { unsafeStringify } from './stringify.js';
3
+
4
+ /**
5
+ * UUID V7 - Unix Epoch time-based UUID
6
+ *
7
+ * The IETF has published RFC9562, introducing 3 new UUID versions (6,7,8). This
8
+ * implementation of V7 is based on the accepted, though not yet approved,
9
+ * revisions.
10
+ *
11
+ * RFC 9562:https://www.rfc-editor.org/rfc/rfc9562.html Universally Unique
12
+ * IDentifiers (UUIDs)
13
+
14
+ *
15
+ * Sample V7 value:
16
+ * https://www.rfc-editor.org/rfc/rfc9562.html#name-example-of-a-uuidv7-value
17
+ *
18
+ * Monotonic Bit Layout: RFC rfc9562.6.2 Method 1, Dedicated Counter Bits ref:
19
+ * https://www.rfc-editor.org/rfc/rfc9562.html#section-6.2-5.1
20
+ *
21
+ * 0 1 2 3 0 1 2 3 4 5 6
22
+ * 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
23
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
24
+ * | unix_ts_ms |
25
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
26
+ * | unix_ts_ms | ver | seq_hi |
27
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
28
+ * |var| seq_low | rand |
29
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30
+ * | rand |
31
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32
+ *
33
+ * seq is a 31 bit serialized counter; comprised of 12 bit seq_hi and 19 bit
34
+ * seq_low, and randomly initialized upon timestamp change. 31 bit counter size
35
+ * was selected as any bitwise operations in node are done as _signed_ 32 bit
36
+ * ints. we exclude the sign bit.
37
+ */
38
+
39
+ var _seqLow = null;
40
+ var _seqHigh = null;
41
+ var _msecs = 0;
42
+ function v7(options, buf, offset) {
43
+ options = options || {};
44
+
45
+ // initialize buffer and pointer
46
+ var i = buf && offset || 0;
47
+ var b = buf || new Uint8Array(16);
48
+
49
+ // rnds is Uint8Array(16) filled with random bytes
50
+ var rnds = options.random || (options.rng || rng)();
51
+
52
+ // milliseconds since unix epoch, 1970-01-01 00:00
53
+ var msecs = options.msecs !== undefined ? options.msecs : Date.now();
54
+
55
+ // seq is user provided 31 bit counter
56
+ var seq = options.seq !== undefined ? options.seq : null;
57
+
58
+ // initialize local seq high/low parts
59
+ var seqHigh = _seqHigh;
60
+ var seqLow = _seqLow;
61
+
62
+ // check if clock has advanced and user has not provided msecs
63
+ if (msecs > _msecs && options.msecs === undefined) {
64
+ _msecs = msecs;
65
+
66
+ // unless user provided seq, reset seq parts
67
+ if (seq !== null) {
68
+ seqHigh = null;
69
+ seqLow = null;
70
+ }
71
+ }
72
+
73
+ // if we have a user provided seq
74
+ if (seq !== null) {
75
+ // trim provided seq to 31 bits of value, avoiding overflow
76
+ if (seq > 0x7fffffff) {
77
+ seq = 0x7fffffff;
78
+ }
79
+
80
+ // split provided seq into high/low parts
81
+ seqHigh = seq >>> 19 & 0xfff;
82
+ seqLow = seq & 0x7ffff;
83
+ }
84
+
85
+ // randomly initialize seq
86
+ if (seqHigh === null || seqLow === null) {
87
+ seqHigh = rnds[6] & 0x7f;
88
+ seqHigh = seqHigh << 8 | rnds[7];
89
+ seqLow = rnds[8] & 0x3f; // pad for var
90
+ seqLow = seqLow << 8 | rnds[9];
91
+ seqLow = seqLow << 5 | rnds[10] >>> 3;
92
+ }
93
+
94
+ // increment seq if within msecs window
95
+ if (msecs + 10000 > _msecs && seq === null) {
96
+ if (++seqLow > 0x7ffff) {
97
+ seqLow = 0;
98
+ if (++seqHigh > 0xfff) {
99
+ seqHigh = 0;
100
+
101
+ // increment internal _msecs. this allows us to continue incrementing
102
+ // while staying monotonic. Note, once we hit 10k milliseconds beyond system
103
+ // clock, we will reset breaking monotonicity (after (2^31)*10000 generations)
104
+ _msecs++;
105
+ }
106
+ }
107
+ } else {
108
+ // resetting; we have advanced more than
109
+ // 10k milliseconds beyond system clock
110
+ _msecs = msecs;
111
+ }
112
+ _seqHigh = seqHigh;
113
+ _seqLow = seqLow;
114
+
115
+ // [bytes 0-5] 48 bits of local timestamp
116
+ b[i++] = _msecs / 0x10000000000 & 0xff;
117
+ b[i++] = _msecs / 0x100000000 & 0xff;
118
+ b[i++] = _msecs / 0x1000000 & 0xff;
119
+ b[i++] = _msecs / 0x10000 & 0xff;
120
+ b[i++] = _msecs / 0x100 & 0xff;
121
+ b[i++] = _msecs & 0xff;
122
+
123
+ // [byte 6] - set 4 bits of version (7) with first 4 bits seq_hi
124
+ b[i++] = seqHigh >>> 4 & 0x0f | 0x70;
125
+
126
+ // [byte 7] remaining 8 bits of seq_hi
127
+ b[i++] = seqHigh & 0xff;
128
+
129
+ // [byte 8] - variant (2 bits), first 6 bits seq_low
130
+ b[i++] = seqLow >>> 13 & 0x3f | 0x80;
131
+
132
+ // [byte 9] 8 bits seq_low
133
+ b[i++] = seqLow >>> 5 & 0xff;
134
+
135
+ // [byte 10] remaining 5 bits seq_low, 3 bits random
136
+ b[i++] = seqLow << 3 & 0xff | rnds[10] & 0x07;
137
+
138
+ // [bytes 11-15] always random
139
+ b[i++] = rnds[11];
140
+ b[i++] = rnds[12];
141
+ b[i++] = rnds[13];
142
+ b[i++] = rnds[14];
143
+ b[i++] = rnds[15];
144
+ return buf || unsafeStringify(b);
145
+ }
146
+ export default v7;
@@ -0,0 +1,5 @@
1
+ import REGEX from './regex.js';
2
+ function validate(uuid) {
3
+ return typeof uuid === 'string' && REGEX.test(uuid);
4
+ }
5
+ export default validate;
@@ -0,0 +1,8 @@
1
+ import validate from './validate.js';
2
+ function version(uuid) {
3
+ if (!validate(uuid)) {
4
+ throw TypeError('Invalid UUID');
5
+ }
6
+ return parseInt(uuid.slice(14, 15), 16);
7
+ }
8
+ export default version;
@@ -0,0 +1,14 @@
1
+ export { default as MAX } from './max.js';
2
+ export { default as NIL } from './nil.js';
3
+ export { default as parse } from './parse.js';
4
+ export { default as stringify } from './stringify.js';
5
+ export { default as v1 } from './v1.js';
6
+ export { default as v1ToV6 } from './v1ToV6.js';
7
+ export { default as v3 } from './v3.js';
8
+ export { default as v4 } from './v4.js';
9
+ export { default as v5 } from './v5.js';
10
+ export { default as v6 } from './v6.js';
11
+ export { default as v6ToV1 } from './v6ToV1.js';
12
+ export { default as v7 } from './v7.js';
13
+ export { default as validate } from './validate.js';
14
+ export { default as version } from './version.js';
@@ -0,0 +1 @@
1
+ export default 'ffffffff-ffff-ffff-ffff-ffffffffffff';
@@ -0,0 +1,10 @@
1
+ import crypto from 'node:crypto';
2
+ function md5(bytes) {
3
+ if (Array.isArray(bytes)) {
4
+ bytes = Buffer.from(bytes);
5
+ } else if (typeof bytes === 'string') {
6
+ bytes = Buffer.from(bytes, 'utf8');
7
+ }
8
+ return crypto.createHash('md5').update(bytes).digest();
9
+ }
10
+ export default md5;
@@ -0,0 +1,4 @@
1
+ import crypto from 'node:crypto';
2
+ export default {
3
+ randomUUID: crypto.randomUUID
4
+ };
@@ -0,0 +1 @@
1
+ export default '00000000-0000-0000-0000-000000000000';
@@ -0,0 +1,37 @@
1
+ import validate from './validate.js';
2
+ function parse(uuid) {
3
+ if (!validate(uuid)) {
4
+ throw TypeError('Invalid UUID');
5
+ }
6
+ let v;
7
+ const arr = new Uint8Array(16);
8
+
9
+ // Parse ########-....-....-....-............
10
+ arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
11
+ arr[1] = v >>> 16 & 0xff;
12
+ arr[2] = v >>> 8 & 0xff;
13
+ arr[3] = v & 0xff;
14
+
15
+ // Parse ........-####-....-....-............
16
+ arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;
17
+ arr[5] = v & 0xff;
18
+
19
+ // Parse ........-....-####-....-............
20
+ arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;
21
+ arr[7] = v & 0xff;
22
+
23
+ // Parse ........-....-....-####-............
24
+ arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;
25
+ arr[9] = v & 0xff;
26
+
27
+ // Parse ........-....-....-....-############
28
+ // (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
29
+ arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000 & 0xff;
30
+ arr[11] = v / 0x100000000 & 0xff;
31
+ arr[12] = v >>> 24 & 0xff;
32
+ arr[13] = v >>> 16 & 0xff;
33
+ arr[14] = v >>> 8 & 0xff;
34
+ arr[15] = v & 0xff;
35
+ return arr;
36
+ }
37
+ export default parse;
@@ -0,0 +1 @@
1
+ export default /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
@@ -0,0 +1,10 @@
1
+ import crypto from 'node:crypto';
2
+ const rnds8Pool = new Uint8Array(256); // # of random values to pre-allocate
3
+ let poolPtr = rnds8Pool.length;
4
+ export default function rng() {
5
+ if (poolPtr > rnds8Pool.length - 16) {
6
+ crypto.randomFillSync(rnds8Pool);
7
+ poolPtr = 0;
8
+ }
9
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
10
+ }
@@ -0,0 +1,10 @@
1
+ import crypto from 'node:crypto';
2
+ function sha1(bytes) {
3
+ if (Array.isArray(bytes)) {
4
+ bytes = Buffer.from(bytes);
5
+ } else if (typeof bytes === 'string') {
6
+ bytes = Buffer.from(bytes, 'utf8');
7
+ }
8
+ return crypto.createHash('sha1').update(bytes).digest();
9
+ }
10
+ export default sha1;
@@ -0,0 +1,31 @@
1
+ import validate from './validate.js';
2
+
3
+ /**
4
+ * Convert array of 16 byte values to UUID string format of the form:
5
+ * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
6
+ */
7
+ const byteToHex = [];
8
+ for (let i = 0; i < 256; ++i) {
9
+ byteToHex.push((i + 0x100).toString(16).slice(1));
10
+ }
11
+ export function unsafeStringify(arr, offset = 0) {
12
+ // Note: Be careful editing this code! It's been tuned for performance
13
+ // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
14
+ //
15
+ // Note to future-self: No, you can't remove the `toLowerCase()` call.
16
+ // REF: https://github.com/uuidjs/uuid/pull/677#issuecomment-1757351351
17
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
18
+ }
19
+ function stringify(arr, offset = 0) {
20
+ const uuid = unsafeStringify(arr, offset);
21
+ // Consistency check for valid UUID. If this throws, it's likely due to one
22
+ // of the following:
23
+ // - One or more input array values don't map to a hex octet (leading to
24
+ // "undefined" in the uuid)
25
+ // - Invalid input values for the RFC `version` or `variant` fields
26
+ if (!validate(uuid)) {
27
+ throw TypeError('Stringified UUID is invalid');
28
+ }
29
+ return uuid;
30
+ }
31
+ export default stringify;
@@ -0,0 +1,125 @@
1
+ import rng from './rng.js';
2
+ import { unsafeStringify } from './stringify.js';
3
+
4
+ // **`v1()` - Generate time-based UUID**
5
+ //
6
+ // Inspired by https://github.com/LiosK/UUID.js
7
+ // and http://docs.python.org/library/uuid.html
8
+
9
+ let _nodeId;
10
+ let _clockseq;
11
+
12
+ // Previous uuid creation time
13
+ let _lastMSecs = 0;
14
+ let _lastNSecs = 0;
15
+
16
+ // See https://github.com/uuidjs/uuid for API details
17
+ function v1(options, buf, offset) {
18
+ let i = buf && offset || 0;
19
+ const b = buf || new Array(16);
20
+ options = options || {};
21
+ let node = options.node;
22
+ let clockseq = options.clockseq;
23
+
24
+ // v1 only: Use cached `node` and `clockseq` values
25
+ if (!options._v6) {
26
+ if (!node) {
27
+ node = _nodeId;
28
+ }
29
+ if (clockseq == null) {
30
+ clockseq = _clockseq;
31
+ }
32
+ }
33
+
34
+ // Handle cases where we need entropy. We do this lazily to minimize issues
35
+ // related to insufficient system entropy. See #189
36
+ if (node == null || clockseq == null) {
37
+ const seedBytes = options.random || (options.rng || rng)();
38
+
39
+ // Randomize node
40
+ if (node == null) {
41
+ node = [seedBytes[0], seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]];
42
+
43
+ // v1 only: cache node value for reuse
44
+ if (!_nodeId && !options._v6) {
45
+ // per RFC4122 4.5: Set MAC multicast bit (v1 only)
46
+ node[0] |= 0x01; // Set multicast bit
47
+
48
+ _nodeId = node;
49
+ }
50
+ }
51
+
52
+ // Randomize clockseq
53
+ if (clockseq == null) {
54
+ // Per 4.2.2, randomize (14 bit) clockseq
55
+ clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff;
56
+ if (_clockseq === undefined && !options._v6) {
57
+ _clockseq = clockseq;
58
+ }
59
+ }
60
+ }
61
+
62
+ // v1 & v6 timestamps are 100 nano-second units since the Gregorian epoch,
63
+ // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so time is
64
+ // handled internally as 'msecs' (integer milliseconds) and 'nsecs'
65
+ // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
66
+ let msecs = options.msecs !== undefined ? options.msecs : Date.now();
67
+
68
+ // Per 4.2.1.2, use count of uuid's generated during the current clock
69
+ // cycle to simulate higher resolution clock
70
+ let nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1;
71
+
72
+ // Time since last uuid creation (in msecs)
73
+ const dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 10000;
74
+
75
+ // Per 4.2.1.2, Bump clockseq on clock regression
76
+ if (dt < 0 && options.clockseq === undefined) {
77
+ clockseq = clockseq + 1 & 0x3fff;
78
+ }
79
+
80
+ // Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
81
+ // time interval
82
+ if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) {
83
+ nsecs = 0;
84
+ }
85
+
86
+ // Per 4.2.1.2 Throw error if too many uuids are requested
87
+ if (nsecs >= 10000) {
88
+ throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");
89
+ }
90
+ _lastMSecs = msecs;
91
+ _lastNSecs = nsecs;
92
+ _clockseq = clockseq;
93
+
94
+ // Per 4.1.4 - Convert from unix epoch to Gregorian epoch
95
+ msecs += 12219292800000;
96
+
97
+ // `time_low`
98
+ const tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
99
+ b[i++] = tl >>> 24 & 0xff;
100
+ b[i++] = tl >>> 16 & 0xff;
101
+ b[i++] = tl >>> 8 & 0xff;
102
+ b[i++] = tl & 0xff;
103
+
104
+ // `time_mid`
105
+ const tmh = msecs / 0x100000000 * 10000 & 0xfffffff;
106
+ b[i++] = tmh >>> 8 & 0xff;
107
+ b[i++] = tmh & 0xff;
108
+
109
+ // `time_high_and_version`
110
+ b[i++] = tmh >>> 24 & 0xf | 0x10; // include version
111
+ b[i++] = tmh >>> 16 & 0xff;
112
+
113
+ // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
114
+ b[i++] = clockseq >>> 8 | 0x80;
115
+
116
+ // `clock_seq_low`
117
+ b[i++] = clockseq & 0xff;
118
+
119
+ // `node`
120
+ for (let n = 0; n < 6; ++n) {
121
+ b[i + n] = node[n];
122
+ }
123
+ return buf || unsafeStringify(b);
124
+ }
125
+ export default v1;
@@ -0,0 +1,20 @@
1
+ import parse from './parse.js';
2
+ import { unsafeStringify } from './stringify.js';
3
+
4
+ /**
5
+ * Convert a v1 UUID to a v6 UUID
6
+ *
7
+ * @param {string|Uint8Array} uuid - The v1 UUID to convert to v6
8
+ * @returns {string|Uint8Array} The v6 UUID as the same type as the `uuid` arg
9
+ * (string or Uint8Array)
10
+ */
11
+ export default function v1ToV6(uuid) {
12
+ const v1Bytes = typeof uuid === 'string' ? parse(uuid) : uuid;
13
+ const v6Bytes = _v1ToV6(v1Bytes);
14
+ return typeof uuid === 'string' ? unsafeStringify(v6Bytes) : v6Bytes;
15
+ }
16
+
17
+ // Do the field transformation needed for v1 -> v6
18
+ function _v1ToV6(v1Bytes, randomize = false) {
19
+ return Uint8Array.of((v1Bytes[6] & 0x0f) << 4 | v1Bytes[7] >> 4 & 0x0f, (v1Bytes[7] & 0x0f) << 4 | (v1Bytes[4] & 0xf0) >> 4, (v1Bytes[4] & 0x0f) << 4 | (v1Bytes[5] & 0xf0) >> 4, (v1Bytes[5] & 0x0f) << 4 | (v1Bytes[0] & 0xf0) >> 4, (v1Bytes[0] & 0x0f) << 4 | (v1Bytes[1] & 0xf0) >> 4, (v1Bytes[1] & 0x0f) << 4 | (v1Bytes[2] & 0xf0) >> 4, 0x60 | v1Bytes[2] & 0x0f, v1Bytes[3], v1Bytes[8], v1Bytes[9], v1Bytes[10], v1Bytes[11], v1Bytes[12], v1Bytes[13], v1Bytes[14], v1Bytes[15]);
20
+ }
@@ -0,0 +1,4 @@
1
+ import v35 from './v35.js';
2
+ import md5 from './md5.js';
3
+ const v3 = v35('v3', 0x30, md5);
4
+ export default v3;
@@ -0,0 +1,55 @@
1
+ import { unsafeStringify } from './stringify.js';
2
+ import parse from './parse.js';
3
+ function stringToBytes(str) {
4
+ str = unescape(encodeURIComponent(str)); // UTF8 escape
5
+
6
+ const bytes = [];
7
+ for (let i = 0; i < str.length; ++i) {
8
+ bytes.push(str.charCodeAt(i));
9
+ }
10
+ return bytes;
11
+ }
12
+ export const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
13
+ export const URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
14
+ export default function v35(name, version, hashfunc) {
15
+ function generateUUID(value, namespace, buf, offset) {
16
+ var _namespace;
17
+ if (typeof value === 'string') {
18
+ value = stringToBytes(value);
19
+ }
20
+ if (typeof namespace === 'string') {
21
+ namespace = parse(namespace);
22
+ }
23
+ if (((_namespace = namespace) === null || _namespace === void 0 ? void 0 : _namespace.length) !== 16) {
24
+ throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
25
+ }
26
+
27
+ // Compute hash of namespace and value, Per 4.3
28
+ // Future: Use spread syntax when supported on all platforms, e.g. `bytes =
29
+ // hashfunc([...namespace, ... value])`
30
+ let bytes = new Uint8Array(16 + value.length);
31
+ bytes.set(namespace);
32
+ bytes.set(value, namespace.length);
33
+ bytes = hashfunc(bytes);
34
+ bytes[6] = bytes[6] & 0x0f | version;
35
+ bytes[8] = bytes[8] & 0x3f | 0x80;
36
+ if (buf) {
37
+ offset = offset || 0;
38
+ for (let i = 0; i < 16; ++i) {
39
+ buf[offset + i] = bytes[i];
40
+ }
41
+ return buf;
42
+ }
43
+ return unsafeStringify(bytes);
44
+ }
45
+
46
+ // Function#name is not settable on some platforms (#270)
47
+ try {
48
+ generateUUID.name = name;
49
+ } catch (err) {}
50
+
51
+ // For CommonJS default export support
52
+ generateUUID.DNS = DNS;
53
+ generateUUID.URL = URL;
54
+ return generateUUID;
55
+ }
@@ -0,0 +1,25 @@
1
+ import native from './native.js';
2
+ import rng from './rng.js';
3
+ import { unsafeStringify } from './stringify.js';
4
+ function v4(options, buf, offset) {
5
+ if (native.randomUUID && !buf && !options) {
6
+ return native.randomUUID();
7
+ }
8
+ options = options || {};
9
+ const rnds = options.random || (options.rng || rng)();
10
+
11
+ // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
12
+ rnds[6] = rnds[6] & 0x0f | 0x40;
13
+ rnds[8] = rnds[8] & 0x3f | 0x80;
14
+
15
+ // Copy bytes to buffer, if provided
16
+ if (buf) {
17
+ offset = offset || 0;
18
+ for (let i = 0; i < 16; ++i) {
19
+ buf[offset + i] = rnds[i];
20
+ }
21
+ return buf;
22
+ }
23
+ return unsafeStringify(rnds);
24
+ }
25
+ export default v4;
@@ -0,0 +1,4 @@
1
+ import v35 from './v35.js';
2
+ import sha1 from './sha1.js';
3
+ const v5 = v35('v5', 0x50, sha1);
4
+ export default v5;
@@ -0,0 +1,32 @@
1
+ import { unsafeStringify } from './stringify.js';
2
+ import v1 from './v1.js';
3
+ import v1ToV6 from './v1ToV6.js';
4
+
5
+ /**
6
+ *
7
+ * @param {object} options
8
+ * @param {Uint8Array=} buf
9
+ * @param {number=} offset
10
+ * @returns
11
+ */
12
+ export default function v6(options = {}, buf, offset = 0) {
13
+ // v6 is v1 with different field layout, so we start with a v1 UUID, albeit
14
+ // with slightly different behavior around how the clock_seq and node fields
15
+ // are randomized, which is why we call v1 with _v6: true.
16
+ let bytes = v1({
17
+ ...options,
18
+ _v6: true
19
+ }, new Uint8Array(16));
20
+
21
+ // Reorder the fields to v6 layout.
22
+ bytes = v1ToV6(bytes);
23
+
24
+ // Return as a byte array if requested
25
+ if (buf) {
26
+ for (let i = 0; i < 16; i++) {
27
+ buf[offset + i] = bytes[i];
28
+ }
29
+ return buf;
30
+ }
31
+ return unsafeStringify(bytes);
32
+ }
@@ -0,0 +1,20 @@
1
+ import parse from './parse.js';
2
+ import { unsafeStringify } from './stringify.js';
3
+
4
+ /**
5
+ * Convert a v6 UUID to a v1 UUID
6
+ *
7
+ * @param {string|Uint8Array} uuid - The v6 UUID to convert to v6
8
+ * @returns {string|Uint8Array} The v1 UUID as the same type as the `uuid` arg
9
+ * (string or Uint8Array)
10
+ */
11
+ export default function v6ToV1(uuid) {
12
+ const v6Bytes = typeof uuid === 'string' ? parse(uuid) : uuid;
13
+ const v1Bytes = _v6ToV1(v6Bytes);
14
+ return typeof uuid === 'string' ? unsafeStringify(v1Bytes) : v1Bytes;
15
+ }
16
+
17
+ // Do the field transformation needed for v6 -> v1
18
+ function _v6ToV1(v6Bytes) {
19
+ return Uint8Array.of((v6Bytes[3] & 0x0f) << 4 | v6Bytes[4] >> 4 & 0x0f, (v6Bytes[4] & 0x0f) << 4 | (v6Bytes[5] & 0xf0) >> 4, (v6Bytes[5] & 0x0f) << 4 | v6Bytes[6] & 0x0f, v6Bytes[7], (v6Bytes[1] & 0x0f) << 4 | (v6Bytes[2] & 0xf0) >> 4, (v6Bytes[2] & 0x0f) << 4 | (v6Bytes[3] & 0xf0) >> 4, 0x10 | (v6Bytes[0] & 0xf0) >> 4, (v6Bytes[0] & 0x0f) << 4 | (v6Bytes[1] & 0xf0) >> 4, v6Bytes[8], v6Bytes[9], v6Bytes[10], v6Bytes[11], v6Bytes[12], v6Bytes[13], v6Bytes[14], v6Bytes[15]);
20
+ }