@takeshape/util 11.45.5 → 11.47.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.
Files changed (242) hide show
  1. package/dist/cjs/common/arrays.js +42 -0
  2. package/dist/cjs/common/assert.js +9 -0
  3. package/dist/cjs/common/async-noop.js +5 -0
  4. package/dist/cjs/common/billing.js +35 -0
  5. package/dist/cjs/common/clone.js +76 -0
  6. package/dist/cjs/common/delay.js +28 -0
  7. package/dist/cjs/common/draftjs-templates.js +131 -0
  8. package/dist/cjs/common/draftjs.js +807 -0
  9. package/dist/cjs/common/get-image-url.js +8 -0
  10. package/dist/cjs/common/highlight-code.js +33 -0
  11. package/dist/cjs/common/http.js +19 -0
  12. package/dist/cjs/common/index.js +50 -0
  13. package/dist/cjs/common/map.js +7 -0
  14. package/dist/cjs/common/memoize.js +13 -0
  15. package/dist/cjs/common/merge.js +64 -0
  16. package/dist/cjs/common/mime.js +68 -0
  17. package/dist/cjs/common/names.js +13 -0
  18. package/dist/cjs/common/naming.js +65 -0
  19. package/dist/cjs/common/path-to-string.js +10 -0
  20. package/dist/cjs/common/persisted-queries.js +4 -0
  21. package/dist/cjs/common/predicate.js +15 -0
  22. package/dist/cjs/common/set-in.js +13 -0
  23. package/dist/cjs/common/sets.js +19 -0
  24. package/dist/cjs/common/sleep.js +9 -0
  25. package/dist/cjs/common/sort-object.js +16 -0
  26. package/dist/cjs/common/strings.js +74 -0
  27. package/dist/cjs/common/templates.js +109 -0
  28. package/dist/cjs/common/timezone.js +606 -0
  29. package/dist/cjs/common/tracing.js +2 -0
  30. package/dist/cjs/common/types.js +63 -0
  31. package/dist/cjs/common/unix-to-iso.js +15 -0
  32. package/dist/cjs/common/urls.js +9 -0
  33. package/dist/cjs/common/validation.js +5 -0
  34. package/dist/cjs/common/value.js +8 -0
  35. package/dist/cjs/common/visit.js +60 -0
  36. package/dist/cjs/node/encryption.js +31 -0
  37. package/dist/cjs/node/gzip.js +10 -0
  38. package/dist/cjs/node/index.js +19 -0
  39. package/dist/cjs/node/search-params.js +23 -0
  40. package/dist/cjs/package.json +1 -0
  41. package/dist/esm/common/arrays.js +33 -0
  42. package/dist/esm/common/assert.js +5 -0
  43. package/dist/esm/common/async-noop.js +2 -0
  44. package/dist/esm/common/billing.js +29 -0
  45. package/dist/esm/common/clone.js +71 -0
  46. package/dist/esm/common/delay.js +22 -0
  47. package/dist/esm/common/draftjs-templates.js +122 -0
  48. package/dist/esm/common/draftjs.js +792 -0
  49. package/{es → dist/esm/common}/get-image-url.js +2 -7
  50. package/dist/esm/common/highlight-code.js +26 -0
  51. package/dist/esm/common/http.js +15 -0
  52. package/dist/esm/common/index.js +34 -0
  53. package/{es → dist/esm/common}/map.js +2 -2
  54. package/dist/esm/common/memoize.js +6 -0
  55. package/dist/esm/common/merge.js +54 -0
  56. package/dist/esm/common/mime.js +60 -0
  57. package/dist/esm/common/names.js +9 -0
  58. package/dist/esm/common/naming.js +54 -0
  59. package/dist/esm/common/path-to-string.js +6 -0
  60. package/{es → dist/esm/common}/persisted-queries.js +1 -1
  61. package/{es → dist/esm/common}/predicate.js +4 -4
  62. package/dist/esm/common/set-in.js +7 -0
  63. package/dist/esm/common/sets.js +14 -0
  64. package/dist/esm/common/sleep.js +5 -0
  65. package/dist/esm/common/sort-object.js +12 -0
  66. package/dist/esm/common/strings.js +60 -0
  67. package/dist/esm/common/templates.js +95 -0
  68. package/dist/esm/common/timezone.js +602 -0
  69. package/dist/esm/common/tracing.js +1 -0
  70. package/dist/esm/common/types.js +50 -0
  71. package/dist/esm/common/unix-to-iso.js +9 -0
  72. package/dist/esm/common/urls.js +5 -0
  73. package/dist/esm/common/validation.js +2 -0
  74. package/dist/esm/common/value.js +4 -0
  75. package/dist/esm/common/visit.js +52 -0
  76. package/dist/esm/node/encryption.js +25 -0
  77. package/dist/esm/node/gzip.js +4 -0
  78. package/dist/esm/node/index.js +3 -0
  79. package/dist/esm/node/search-params.js +17 -0
  80. package/dist/esm/package.json +1 -0
  81. package/dist/tsconfig.types.tsbuildinfo +1 -0
  82. package/dist/{arrays.d.ts → types/common/arrays.d.ts} +0 -1
  83. package/dist/{assert.d.ts → types/common/assert.d.ts} +0 -1
  84. package/dist/{async-noop.d.ts → types/common/async-noop.d.ts} +0 -1
  85. package/dist/types/common/billing.d.ts +365 -0
  86. package/dist/{clone.d.ts → types/common/clone.d.ts} +0 -1
  87. package/dist/{delay.d.ts → types/common/delay.d.ts} +0 -1
  88. package/dist/{draftjs-templates.d.ts → types/common/draftjs-templates.d.ts} +1 -2
  89. package/dist/{draftjs.d.ts → types/common/draftjs.d.ts} +1 -2
  90. package/dist/{get-image-url.d.ts → types/common/get-image-url.d.ts} +0 -1
  91. package/dist/types/common/highlight-code.d.ts +14 -0
  92. package/dist/{http.d.ts → types/common/http.d.ts} +0 -1
  93. package/dist/types/common/index.d.ts +34 -0
  94. package/dist/{map.d.ts → types/common/map.d.ts} +0 -1
  95. package/dist/{memoize.d.ts → types/common/memoize.d.ts} +0 -1
  96. package/dist/{merge.d.ts → types/common/merge.d.ts} +0 -1
  97. package/dist/{mime.d.ts → types/common/mime.d.ts} +0 -1
  98. package/dist/{names.d.ts → types/common/names.d.ts} +0 -1
  99. package/dist/{naming.d.ts → types/common/naming.d.ts} +0 -1
  100. package/dist/{path-to-string.d.ts → types/common/path-to-string.d.ts} +0 -1
  101. package/dist/{persisted-queries.d.ts → types/common/persisted-queries.d.ts} +0 -1
  102. package/dist/{predicate.d.ts → types/common/predicate.d.ts} +0 -1
  103. package/dist/{set-in.d.ts → types/common/set-in.d.ts} +0 -1
  104. package/dist/{sets.d.ts → types/common/sets.d.ts} +0 -1
  105. package/dist/{sleep.d.ts → types/common/sleep.d.ts} +0 -1
  106. package/dist/{sort-object.d.ts → types/common/sort-object.d.ts} +0 -1
  107. package/dist/{strings.d.ts → types/common/strings.d.ts} +1 -2
  108. package/dist/{templates.d.ts → types/common/templates.d.ts} +1 -2
  109. package/dist/{timezone.d.ts → types/common/timezone.d.ts} +0 -1
  110. package/dist/{tracing.d.ts → types/common/tracing.d.ts} +1 -2
  111. package/dist/{types.d.ts → types/common/types.d.ts} +0 -1
  112. package/dist/{unix-to-iso.d.ts → types/common/unix-to-iso.d.ts} +0 -1
  113. package/dist/{urls.d.ts → types/common/urls.d.ts} +0 -1
  114. package/dist/{validation.d.ts → types/common/validation.d.ts} +0 -1
  115. package/dist/{value.d.ts → types/common/value.d.ts} +0 -1
  116. package/dist/{visit.d.ts → types/common/visit.d.ts} +0 -1
  117. package/dist/{encryption.d.ts → types/node/encryption.d.ts} +0 -1
  118. package/dist/{gzip.d.ts → types/node/gzip.d.ts} +1 -2
  119. package/dist/types/node/index.d.ts +3 -0
  120. package/dist/{search-params.d.ts → types/node/search-params.d.ts} +1 -2
  121. package/package.json +33 -21
  122. package/dist/arrays.d.ts.map +0 -1
  123. package/dist/arrays.js +0 -44
  124. package/dist/assert.d.ts.map +0 -1
  125. package/dist/assert.js +0 -11
  126. package/dist/async-noop.d.ts.map +0 -1
  127. package/dist/async-noop.js +0 -8
  128. package/dist/billing.d.ts +0 -366
  129. package/dist/billing.d.ts.map +0 -1
  130. package/dist/billing.js +0 -48
  131. package/dist/browser.d.ts +0 -2
  132. package/dist/browser.d.ts.map +0 -1
  133. package/dist/browser.js +0 -16
  134. package/dist/clone.d.ts.map +0 -1
  135. package/dist/clone.js +0 -101
  136. package/dist/common.d.ts +0 -32
  137. package/dist/common.d.ts.map +0 -1
  138. package/dist/common.js +0 -346
  139. package/dist/delay.d.ts.map +0 -1
  140. package/dist/delay.js +0 -34
  141. package/dist/draftjs-templates.d.ts.map +0 -1
  142. package/dist/draftjs-templates.js +0 -157
  143. package/dist/draftjs.d.ts.map +0 -1
  144. package/dist/draftjs.js +0 -836
  145. package/dist/encryption.d.ts.map +0 -1
  146. package/dist/encryption.js +0 -33
  147. package/dist/get-image-url.d.ts.map +0 -1
  148. package/dist/get-image-url.js +0 -15
  149. package/dist/gzip.d.ts.map +0 -1
  150. package/dist/gzip.js +0 -11
  151. package/dist/highlight-code.d.ts +0 -15
  152. package/dist/highlight-code.d.ts.map +0 -1
  153. package/dist/highlight-code.js +0 -35
  154. package/dist/http.d.ts.map +0 -1
  155. package/dist/http.js +0 -18
  156. package/dist/index.d.ts +0 -6
  157. package/dist/index.d.ts.map +0 -1
  158. package/dist/index.js +0 -60
  159. package/dist/map.d.ts.map +0 -1
  160. package/dist/map.js +0 -9
  161. package/dist/memoize.d.ts.map +0 -1
  162. package/dist/memoize.js +0 -13
  163. package/dist/merge.d.ts.map +0 -1
  164. package/dist/merge.js +0 -67
  165. package/dist/mime.d.ts.map +0 -1
  166. package/dist/mime.js +0 -37
  167. package/dist/names.d.ts.map +0 -1
  168. package/dist/names.js +0 -15
  169. package/dist/naming.d.ts.map +0 -1
  170. package/dist/naming.js +0 -91
  171. package/dist/path-to-string.d.ts.map +0 -1
  172. package/dist/path-to-string.js +0 -13
  173. package/dist/persisted-queries.d.ts.map +0 -1
  174. package/dist/persisted-queries.js +0 -7
  175. package/dist/predicate.d.ts.map +0 -1
  176. package/dist/predicate.js +0 -17
  177. package/dist/search-params.d.ts.map +0 -1
  178. package/dist/search-params.js +0 -25
  179. package/dist/set-in.d.ts.map +0 -1
  180. package/dist/set-in.js +0 -11
  181. package/dist/sets.d.ts.map +0 -1
  182. package/dist/sets.js +0 -21
  183. package/dist/sleep.d.ts.map +0 -1
  184. package/dist/sleep.js +0 -11
  185. package/dist/sort-object.d.ts.map +0 -1
  186. package/dist/sort-object.js +0 -21
  187. package/dist/strings.d.ts.map +0 -1
  188. package/dist/strings.js +0 -87
  189. package/dist/templates.d.ts.map +0 -1
  190. package/dist/templates.js +0 -120
  191. package/dist/timezone.d.ts.map +0 -1
  192. package/dist/timezone.js +0 -17
  193. package/dist/tracing.d.ts.map +0 -1
  194. package/dist/tracing.js +0 -5
  195. package/dist/types.d.ts.map +0 -1
  196. package/dist/types.js +0 -92
  197. package/dist/unix-to-iso.d.ts.map +0 -1
  198. package/dist/unix-to-iso.js +0 -17
  199. package/dist/urls.d.ts.map +0 -1
  200. package/dist/urls.js +0 -11
  201. package/dist/validation.d.ts.map +0 -1
  202. package/dist/validation.js +0 -8
  203. package/dist/value.d.ts.map +0 -1
  204. package/dist/value.js +0 -11
  205. package/dist/visit.d.ts.map +0 -1
  206. package/dist/visit.js +0 -61
  207. package/es/arrays.js +0 -33
  208. package/es/assert.js +0 -5
  209. package/es/async-noop.js +0 -2
  210. package/es/billing.js +0 -40
  211. package/es/browser.js +0 -1
  212. package/es/clone.js +0 -94
  213. package/es/common.js +0 -31
  214. package/es/delay.js +0 -26
  215. package/es/draftjs-templates.js +0 -147
  216. package/es/draftjs.js +0 -819
  217. package/es/encryption.js +0 -26
  218. package/es/gzip.js +0 -4
  219. package/es/highlight-code.js +0 -26
  220. package/es/http.js +0 -11
  221. package/es/index.js +0 -6
  222. package/es/memoize.js +0 -6
  223. package/es/merge.js +0 -58
  224. package/es/mime.js +0 -29
  225. package/es/names.js +0 -9
  226. package/es/naming.js +0 -78
  227. package/es/path-to-string.js +0 -6
  228. package/es/search-params.js +0 -17
  229. package/es/set-in.js +0 -6
  230. package/es/sets.js +0 -14
  231. package/es/sleep.js +0 -5
  232. package/es/sort-object.js +0 -14
  233. package/es/strings.js +0 -72
  234. package/es/templates.js +0 -105
  235. package/es/timezone.js +0 -10
  236. package/es/tracing.js +0 -1
  237. package/es/types.js +0 -80
  238. package/es/unix-to-iso.js +0 -9
  239. package/es/urls.js +0 -5
  240. package/es/validation.js +0 -2
  241. package/es/value.js +0 -4
  242. package/es/visit.js +0 -53
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.value = void 0;
4
+ function value(x) {
5
+ return () => x;
6
+ }
7
+ exports.value = value;
8
+ exports.default = value;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.visitJsonPath = exports.visit = void 0;
7
+ const isObject_js_1 = __importDefault(require("lodash/isObject.js"));
8
+ /**
9
+ * Walk a tree, calling the callback for any property name matching a value in the keys array.
10
+ */
11
+ function visit(tree, keys, callback) {
12
+ const traverse = (obj, path) => {
13
+ for (const [key, value] of Object.entries(obj)) {
14
+ if (keys.includes(key)) {
15
+ callback(value, [...path, key]);
16
+ }
17
+ if ((0, isObject_js_1.default)(value)) {
18
+ traverse(value, [...path, key]);
19
+ }
20
+ }
21
+ };
22
+ traverse(tree, []);
23
+ }
24
+ exports.visit = visit;
25
+ /**
26
+ * Walk a tree with JSONPath, calling the callback for matching properties.
27
+ * Normalizes the resulting path
28
+ */
29
+ function visitJsonPath(tree, jsonPaths, callback) {
30
+ const paths = jsonPaths.map((p) => p.split('.').slice());
31
+ const testPaths = (propPath) => {
32
+ return paths.findIndex((testPath) => {
33
+ const isFromRoot = testPath[0] === '$';
34
+ const tPath = isFromRoot ? testPath.slice(1) : testPath.slice().reverse();
35
+ const pPath = isFromRoot ? propPath.slice() : propPath.slice().reverse();
36
+ let isMatchingPath = isFromRoot ? tPath.length === pPath.length : tPath.length <= pPath.length;
37
+ for (const [pI, pP] of pPath.entries()) {
38
+ if (tPath[pI] === undefined || !isMatchingPath) {
39
+ break;
40
+ }
41
+ isMatchingPath = pP === tPath[pI] || tPath[pI] === '*';
42
+ }
43
+ return isMatchingPath;
44
+ });
45
+ };
46
+ const traverse = (obj, path) => {
47
+ for (const [prop, value] of Object.entries(obj)) {
48
+ const propPath = [...path, prop];
49
+ const foundIndex = testPaths(propPath);
50
+ if (foundIndex > -1) {
51
+ callback(value, propPath, foundIndex);
52
+ }
53
+ if ((0, isObject_js_1.default)(value)) {
54
+ traverse(value, propPath);
55
+ }
56
+ }
57
+ };
58
+ traverse(tree, []);
59
+ }
60
+ exports.visitJsonPath = visitJsonPath;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.decrypt = exports.encrypt = void 0;
7
+ const node_crypto_1 = __importDefault(require("node:crypto"));
8
+ const curry_js_1 = __importDefault(require("lodash/curry.js"));
9
+ const CIPHER_ALGORITHM = 'aes-256-ctr';
10
+ const IV_LENGTH = 16;
11
+ const KEY_ENCODING = 'base64';
12
+ const CIPHER_TEXT_ENCODING = 'base64';
13
+ const CONTENT_ENCODING = 'utf8';
14
+ exports.encrypt = (0, curry_js_1.default)((key, plaintext) => {
15
+ // Initialization Vector
16
+ const iv = node_crypto_1.default.randomBytes(IV_LENGTH);
17
+ const cipher = node_crypto_1.default.createCipheriv(CIPHER_ALGORITHM, Buffer.from(key, KEY_ENCODING), iv);
18
+ const cipherText = cipher.update(Buffer.from(plaintext, CONTENT_ENCODING));
19
+ return Buffer.concat([iv, cipherText, cipher.final()]).toString(CIPHER_TEXT_ENCODING);
20
+ });
21
+ exports.decrypt = (0, curry_js_1.default)((key, encrypted) => {
22
+ const input = Buffer.from(encrypted, CIPHER_TEXT_ENCODING);
23
+ if (input.length < IV_LENGTH + 1) {
24
+ throw new TypeError('Provided "encrypted" must decrypt to a non-empty string');
25
+ }
26
+ // Initialization Vector
27
+ const iv = input.slice(0, IV_LENGTH);
28
+ const decipher = node_crypto_1.default.createDecipheriv(CIPHER_ALGORITHM, Buffer.from(key, KEY_ENCODING), iv);
29
+ const cipherText = input.slice(IV_LENGTH);
30
+ return Buffer.concat([decipher.update(cipherText), decipher.final()]).toString(CONTENT_ENCODING);
31
+ });
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.gunzip = exports.gzip = void 0;
7
+ const node_util_1 = require("node:util");
8
+ const node_zlib_1 = __importDefault(require("node:zlib"));
9
+ exports.gzip = (0, node_util_1.promisify)(node_zlib_1.default.gzip);
10
+ exports.gunzip = (0, node_util_1.promisify)(node_zlib_1.default.gunzip);
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./encryption.js"), exports);
18
+ __exportStar(require("./gzip.js"), exports);
19
+ __exportStar(require("./search-params.js"), exports);
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.concatURLSearchParams = exports.toSearchParamsRecord = exports.toSearchParamsEntries = void 0;
4
+ const node_url_1 = require("node:url");
5
+ function toSearchParamsEntries(obj) {
6
+ if (obj instanceof node_url_1.URLSearchParams) {
7
+ return [...obj.entries()];
8
+ }
9
+ if (typeof obj === 'object' && !Array.isArray(obj)) {
10
+ return Object.entries(obj).map(([k, v]) => [k, v?.toString() ?? '']);
11
+ }
12
+ return [...new node_url_1.URLSearchParams(obj).entries()];
13
+ }
14
+ exports.toSearchParamsEntries = toSearchParamsEntries;
15
+ function toSearchParamsRecord(obj) {
16
+ return Object.fromEntries(toSearchParamsEntries(obj));
17
+ }
18
+ exports.toSearchParamsRecord = toSearchParamsRecord;
19
+ function concatURLSearchParams(...searchParamsInput) {
20
+ const entries = searchParamsInput.flatMap((item) => (item ? toSearchParamsEntries(item) : []));
21
+ return new node_url_1.URLSearchParams(entries);
22
+ }
23
+ exports.concatURLSearchParams = concatURLSearchParams;
@@ -0,0 +1 @@
1
+ {"type": "commonjs"}
@@ -0,0 +1,33 @@
1
+ export function arrayContainsAll(a, b) {
2
+ return a.every((value) => b.includes(value));
3
+ }
4
+ export function setIsEqual(a, b) {
5
+ if (a.length !== b.length) {
6
+ return false;
7
+ }
8
+ if (a.length === 0) {
9
+ return true;
10
+ }
11
+ const refSet = new Set(a);
12
+ return b.every((value) => refSet.has(value));
13
+ }
14
+ export function arrayStartsWith(a, b) {
15
+ if (a.length < b.length) {
16
+ return false;
17
+ }
18
+ for (let i = 0; i < b.length; i++) {
19
+ if (a[i] !== b[i]) {
20
+ return false;
21
+ }
22
+ }
23
+ return true;
24
+ }
25
+ export function isDefined(x) {
26
+ return x !== null && x !== undefined;
27
+ }
28
+ export function toArray(obj) {
29
+ return obj ? [obj] : [];
30
+ }
31
+ export function ensureArray(obj) {
32
+ return Array.isArray(obj) ? obj : [obj];
33
+ }
@@ -0,0 +1,5 @@
1
+ export function assert(arg, message) {
2
+ if (!arg) {
3
+ throw new Error(message);
4
+ }
5
+ }
@@ -0,0 +1,2 @@
1
+ import { value } from './value.js';
2
+ export const asyncNoop = value(Promise.resolve());
@@ -0,0 +1,29 @@
1
+ import { assert } from './assert.js';
2
+ export const DEFAULT_MIN_SCHEDULE_TRIGGER_INTERVAL = 60;
3
+ export const DEFAULT_ENTITLEMENTS = {
4
+ users: 3,
5
+ apiRequests: 10000,
6
+ apiRateLimit: 5,
7
+ contentEntries: 500,
8
+ deployTargets: 1,
9
+ roles: 5,
10
+ workflows: 0,
11
+ locales: 2,
12
+ webhooks: true,
13
+ providers: [],
14
+ importFromCSV: false,
15
+ minScheduleTriggerInterval: DEFAULT_MIN_SCHEDULE_TRIGGER_INTERVAL,
16
+ bandwidth: 5,
17
+ apiCdn: false,
18
+ guards: 0
19
+ };
20
+ export function isStripeProductObject(product) {
21
+ return Boolean(product && typeof product !== 'string' && product.object === 'product' && !product.deleted);
22
+ }
23
+ export function getStripeProductObject(product) {
24
+ assert(isStripeProductObject(product), 'product is not a Stripe product object');
25
+ return product;
26
+ }
27
+ export function isStripeChargeObject(charge) {
28
+ return typeof charge !== 'string';
29
+ }
@@ -0,0 +1,71 @@
1
+ import { isIterableObject } from './types.js';
2
+ /**
3
+ * Clone any JSON serializable value similar to JSON.parse(JSON.stringify()) but better performance
4
+ */
5
+ export function deepClone(value) {
6
+ if (!value) {
7
+ return value;
8
+ }
9
+ if (Array.isArray(value)) {
10
+ const { length } = value;
11
+ const result = new Array(length);
12
+ for (let i = 0; i < length; i++) {
13
+ result[i] = deepClone(value[i]);
14
+ }
15
+ return result;
16
+ }
17
+ if (isIterableObject(value)) {
18
+ const obj = value;
19
+ const result = {};
20
+ for (const key of Object.keys(obj)) {
21
+ const value = obj[key];
22
+ if (value !== undefined) {
23
+ result[key] = deepClone(value);
24
+ }
25
+ }
26
+ return result;
27
+ }
28
+ return value;
29
+ }
30
+ export const REMOVE = Symbol('REMOVE');
31
+ function arrayFilter(value) {
32
+ return value !== REMOVE;
33
+ }
34
+ /**
35
+ * Clone any JSON serializable value and transform using a callback
36
+ * @param value the value to clone
37
+ * @param customizer a callback that is called for every key/index
38
+ */
39
+ export function deepCloneWith(value, customizer) {
40
+ const clone = (value, key, parent) => {
41
+ const newValue = customizer(value, key, parent, clone);
42
+ if (newValue !== undefined) {
43
+ return newValue;
44
+ }
45
+ if (Array.isArray(value)) {
46
+ const { length } = value;
47
+ const arr = new Array(length);
48
+ let edited = false;
49
+ for (let i = 0; i < length; i++) {
50
+ const newValue = clone(value[i], i, value);
51
+ if (newValue === REMOVE) {
52
+ edited = true;
53
+ }
54
+ arr[i] = newValue;
55
+ }
56
+ return edited ? arr.filter(arrayFilter) : arr;
57
+ }
58
+ if (isIterableObject(value)) {
59
+ const newObject = {};
60
+ for (const key of Object.keys(value)) {
61
+ const newValue = clone(value[key], key, value);
62
+ if (newValue !== undefined && newValue !== REMOVE) {
63
+ newObject[key] = newValue;
64
+ }
65
+ }
66
+ return newObject;
67
+ }
68
+ return value;
69
+ };
70
+ return clone(value, undefined, undefined);
71
+ }
@@ -0,0 +1,22 @@
1
+ export async function delay(timeout, value) {
2
+ return new Promise((resolve) => {
3
+ setTimeout(resolve, timeout, value);
4
+ });
5
+ }
6
+ function randomInt(minimum, maximum) {
7
+ const co = Math.random() * (maximum - minimum + 1);
8
+ return Math.floor(co + minimum);
9
+ }
10
+ // Decorrelated jitter backoff:
11
+ // https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
12
+ export async function backoff(baseDelay, maxDelay, attempt = { num: 1, lastDelay: 0 }) {
13
+ const msec = Math.min(maxDelay, randomInt(baseDelay, (attempt.lastDelay || baseDelay) * 3));
14
+ await delay(msec);
15
+ return {
16
+ num: attempt.num + 1,
17
+ lastDelay: msec
18
+ };
19
+ }
20
+ export async function randomDelay(minimum, maximum, value) {
21
+ return delay(randomInt(minimum, maximum), value);
22
+ }
@@ -0,0 +1,122 @@
1
+ import shortid from 'shortid';
2
+ export const getDraftjsImage = (params) => {
3
+ const { captionText, creditText, alignment, size, assetId, linkUrl, linkIsExternal, depth, key, path } = params;
4
+ const blockKey = shortid.generate();
5
+ return {
6
+ contentBlock: {
7
+ key: shortid.generate(),
8
+ text: ' ',
9
+ type: 'atomic',
10
+ depth,
11
+ inlineStyleRanges: [],
12
+ entityRanges: [
13
+ {
14
+ offset: 0,
15
+ length: 1,
16
+ key
17
+ }
18
+ ],
19
+ data: {}
20
+ },
21
+ entities: {
22
+ [key]: {
23
+ type: 'image',
24
+ mutability: 'IMMUTABLE',
25
+ data: {
26
+ id: assetId,
27
+ path,
28
+ caption: {
29
+ blocks: [
30
+ {
31
+ key: blockKey,
32
+ text: captionText,
33
+ type: 'unstyled',
34
+ depth,
35
+ inlineStyleRanges: [],
36
+ entityRanges: [],
37
+ data: {}
38
+ }
39
+ ],
40
+ entityMap: {}
41
+ },
42
+ credit: {
43
+ blocks: [
44
+ {
45
+ key: blockKey,
46
+ text: creditText,
47
+ type: 'unstyled',
48
+ depth,
49
+ inlineStyleRanges: [],
50
+ entityRanges: [],
51
+ data: {}
52
+ }
53
+ ],
54
+ entityMap: {}
55
+ },
56
+ link: {
57
+ url: linkUrl,
58
+ external: linkIsExternal
59
+ },
60
+ alignment,
61
+ size,
62
+ contentTypeId: 'ASSET'
63
+ }
64
+ }
65
+ }
66
+ };
67
+ };
68
+ export const getDraftjsPullquote = (params) => {
69
+ const { text, depth } = params;
70
+ return {
71
+ contentBlock: {
72
+ key: shortid.generate(),
73
+ text,
74
+ type: 'pullquote',
75
+ depth,
76
+ inlineStyleRanges: [],
77
+ entityRanges: [],
78
+ data: {}
79
+ },
80
+ entities: {}
81
+ };
82
+ };
83
+ export const getDraftjsOembed = (params) => {
84
+ const { key, depth, html, width = 550, height = undefined, url = undefined, author_name = undefined, author_url = undefined, type = undefined, cache_age = undefined, provider_name = undefined, provider_url = undefined, version = undefined } = params;
85
+ return {
86
+ contentBlock: {
87
+ key: shortid.generate(),
88
+ text: ' ',
89
+ type: 'atomic',
90
+ depth,
91
+ inlineStyleRanges: [],
92
+ entityRanges: [
93
+ {
94
+ offset: 0,
95
+ length: 1,
96
+ key
97
+ }
98
+ ],
99
+ data: {}
100
+ },
101
+ // Only html is required
102
+ entities: {
103
+ [key]: {
104
+ type: 'oembed',
105
+ mutability: 'IMMUTABLE',
106
+ data: {
107
+ url,
108
+ author_name,
109
+ author_url,
110
+ html,
111
+ width,
112
+ height,
113
+ type,
114
+ cache_age,
115
+ provider_name,
116
+ provider_url,
117
+ version
118
+ }
119
+ }
120
+ }
121
+ };
122
+ };