@adobe/acc-js-sdk 1.1.57 → 1.1.59
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/docs/changeLog.html +18 -0
- package/package-lock.json +282 -10
- package/package.json +1 -1
- package/src/client.js +20 -6
- package/src/util.js +27 -0
- package/test/client.test.js +105 -2
- package/test/util.test.js +111 -0
package/docs/changeLog.html
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
layout: page
|
|
3
3
|
title: Change Log
|
|
4
4
|
---
|
|
5
|
+
|
|
6
|
+
<section class="changelog"><h1>Version 1.1.59</h1>
|
|
7
|
+
<h2>2025/08/22</h2>
|
|
8
|
+
<li>
|
|
9
|
+
In previous commit, computing the UUID was not working in a browser context
|
|
10
|
+
</li>
|
|
11
|
+
</section>
|
|
12
|
+
|
|
13
|
+
<section class="changelog"><h1>Version 1.1.58</h1>
|
|
14
|
+
<h2>2025/08/20</h2>
|
|
15
|
+
<li>
|
|
16
|
+
Bumped dependencies version to fix vulnerabilities
|
|
17
|
+
</li>
|
|
18
|
+
<li>
|
|
19
|
+
Improved resource upload so that a custom resource id can be passed
|
|
20
|
+
</li>
|
|
21
|
+
</section>
|
|
22
|
+
|
|
5
23
|
<section class="changelog"><h1>Version 1.1.57</h1>
|
|
6
24
|
<h2>2025/06/24</h2>
|
|
7
25
|
<li>
|
package/package-lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/acc-js-sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.59",
|
|
4
4
|
"lockfileVersion": 2,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@adobe/acc-js-sdk",
|
|
9
|
-
"version": "1.1.
|
|
9
|
+
"version": "1.1.59",
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"axios": "^1.7.8",
|
|
@@ -1336,6 +1336,18 @@
|
|
|
1336
1336
|
"dev": true,
|
|
1337
1337
|
"license": "MIT"
|
|
1338
1338
|
},
|
|
1339
|
+
"node_modules/call-bind-apply-helpers": {
|
|
1340
|
+
"version": "1.0.2",
|
|
1341
|
+
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
|
|
1342
|
+
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
|
|
1343
|
+
"dependencies": {
|
|
1344
|
+
"es-errors": "^1.3.0",
|
|
1345
|
+
"function-bind": "^1.1.2"
|
|
1346
|
+
},
|
|
1347
|
+
"engines": {
|
|
1348
|
+
"node": ">= 0.4"
|
|
1349
|
+
}
|
|
1350
|
+
},
|
|
1339
1351
|
"node_modules/callsites": {
|
|
1340
1352
|
"version": "3.1.0",
|
|
1341
1353
|
"dev": true,
|
|
@@ -1677,6 +1689,19 @@
|
|
|
1677
1689
|
"domelementtype": "1"
|
|
1678
1690
|
}
|
|
1679
1691
|
},
|
|
1692
|
+
"node_modules/dunder-proto": {
|
|
1693
|
+
"version": "1.0.1",
|
|
1694
|
+
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
|
1695
|
+
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
|
|
1696
|
+
"dependencies": {
|
|
1697
|
+
"call-bind-apply-helpers": "^1.0.1",
|
|
1698
|
+
"es-errors": "^1.3.0",
|
|
1699
|
+
"gopd": "^1.2.0"
|
|
1700
|
+
},
|
|
1701
|
+
"engines": {
|
|
1702
|
+
"node": ">= 0.4"
|
|
1703
|
+
}
|
|
1704
|
+
},
|
|
1680
1705
|
"node_modules/electron-to-chromium": {
|
|
1681
1706
|
"version": "1.4.284",
|
|
1682
1707
|
"dev": true,
|
|
@@ -1711,6 +1736,47 @@
|
|
|
1711
1736
|
"is-arrayish": "^0.2.1"
|
|
1712
1737
|
}
|
|
1713
1738
|
},
|
|
1739
|
+
"node_modules/es-define-property": {
|
|
1740
|
+
"version": "1.0.1",
|
|
1741
|
+
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
|
|
1742
|
+
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
|
|
1743
|
+
"engines": {
|
|
1744
|
+
"node": ">= 0.4"
|
|
1745
|
+
}
|
|
1746
|
+
},
|
|
1747
|
+
"node_modules/es-errors": {
|
|
1748
|
+
"version": "1.3.0",
|
|
1749
|
+
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
|
|
1750
|
+
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
|
|
1751
|
+
"engines": {
|
|
1752
|
+
"node": ">= 0.4"
|
|
1753
|
+
}
|
|
1754
|
+
},
|
|
1755
|
+
"node_modules/es-object-atoms": {
|
|
1756
|
+
"version": "1.1.1",
|
|
1757
|
+
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
|
|
1758
|
+
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
|
|
1759
|
+
"dependencies": {
|
|
1760
|
+
"es-errors": "^1.3.0"
|
|
1761
|
+
},
|
|
1762
|
+
"engines": {
|
|
1763
|
+
"node": ">= 0.4"
|
|
1764
|
+
}
|
|
1765
|
+
},
|
|
1766
|
+
"node_modules/es-set-tostringtag": {
|
|
1767
|
+
"version": "2.1.0",
|
|
1768
|
+
"resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz",
|
|
1769
|
+
"integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==",
|
|
1770
|
+
"dependencies": {
|
|
1771
|
+
"es-errors": "^1.3.0",
|
|
1772
|
+
"get-intrinsic": "^1.2.6",
|
|
1773
|
+
"has-tostringtag": "^1.0.2",
|
|
1774
|
+
"hasown": "^2.0.2"
|
|
1775
|
+
},
|
|
1776
|
+
"engines": {
|
|
1777
|
+
"node": ">= 0.4"
|
|
1778
|
+
}
|
|
1779
|
+
},
|
|
1714
1780
|
"node_modules/escalade": {
|
|
1715
1781
|
"version": "3.1.1",
|
|
1716
1782
|
"dev": true,
|
|
@@ -2089,11 +2155,14 @@
|
|
|
2089
2155
|
}
|
|
2090
2156
|
},
|
|
2091
2157
|
"node_modules/form-data": {
|
|
2092
|
-
"version": "4.0.
|
|
2093
|
-
"
|
|
2158
|
+
"version": "4.0.4",
|
|
2159
|
+
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.4.tgz",
|
|
2160
|
+
"integrity": "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==",
|
|
2094
2161
|
"dependencies": {
|
|
2095
2162
|
"asynckit": "^0.4.0",
|
|
2096
2163
|
"combined-stream": "^1.0.8",
|
|
2164
|
+
"es-set-tostringtag": "^2.1.0",
|
|
2165
|
+
"hasown": "^2.0.2",
|
|
2097
2166
|
"mime-types": "^2.1.12"
|
|
2098
2167
|
},
|
|
2099
2168
|
"engines": {
|
|
@@ -2118,9 +2187,12 @@
|
|
|
2118
2187
|
}
|
|
2119
2188
|
},
|
|
2120
2189
|
"node_modules/function-bind": {
|
|
2121
|
-
"version": "1.1.
|
|
2122
|
-
"
|
|
2123
|
-
"
|
|
2190
|
+
"version": "1.1.2",
|
|
2191
|
+
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
|
2192
|
+
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
|
|
2193
|
+
"funding": {
|
|
2194
|
+
"url": "https://github.com/sponsors/ljharb"
|
|
2195
|
+
}
|
|
2124
2196
|
},
|
|
2125
2197
|
"node_modules/functional-red-black-tree": {
|
|
2126
2198
|
"version": "1.0.1",
|
|
@@ -2143,6 +2215,29 @@
|
|
|
2143
2215
|
"node": "6.* || 8.* || >= 10.*"
|
|
2144
2216
|
}
|
|
2145
2217
|
},
|
|
2218
|
+
"node_modules/get-intrinsic": {
|
|
2219
|
+
"version": "1.3.0",
|
|
2220
|
+
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
|
|
2221
|
+
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
|
|
2222
|
+
"dependencies": {
|
|
2223
|
+
"call-bind-apply-helpers": "^1.0.2",
|
|
2224
|
+
"es-define-property": "^1.0.1",
|
|
2225
|
+
"es-errors": "^1.3.0",
|
|
2226
|
+
"es-object-atoms": "^1.1.1",
|
|
2227
|
+
"function-bind": "^1.1.2",
|
|
2228
|
+
"get-proto": "^1.0.1",
|
|
2229
|
+
"gopd": "^1.2.0",
|
|
2230
|
+
"has-symbols": "^1.1.0",
|
|
2231
|
+
"hasown": "^2.0.2",
|
|
2232
|
+
"math-intrinsics": "^1.1.0"
|
|
2233
|
+
},
|
|
2234
|
+
"engines": {
|
|
2235
|
+
"node": ">= 0.4"
|
|
2236
|
+
},
|
|
2237
|
+
"funding": {
|
|
2238
|
+
"url": "https://github.com/sponsors/ljharb"
|
|
2239
|
+
}
|
|
2240
|
+
},
|
|
2146
2241
|
"node_modules/get-package-type": {
|
|
2147
2242
|
"version": "0.1.0",
|
|
2148
2243
|
"dev": true,
|
|
@@ -2151,6 +2246,18 @@
|
|
|
2151
2246
|
"node": ">=8.0.0"
|
|
2152
2247
|
}
|
|
2153
2248
|
},
|
|
2249
|
+
"node_modules/get-proto": {
|
|
2250
|
+
"version": "1.0.1",
|
|
2251
|
+
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
|
|
2252
|
+
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
|
|
2253
|
+
"dependencies": {
|
|
2254
|
+
"dunder-proto": "^1.0.1",
|
|
2255
|
+
"es-object-atoms": "^1.0.0"
|
|
2256
|
+
},
|
|
2257
|
+
"engines": {
|
|
2258
|
+
"node": ">= 0.4"
|
|
2259
|
+
}
|
|
2260
|
+
},
|
|
2154
2261
|
"node_modules/get-stream": {
|
|
2155
2262
|
"version": "6.0.1",
|
|
2156
2263
|
"dev": true,
|
|
@@ -2206,6 +2313,17 @@
|
|
|
2206
2313
|
"url": "https://github.com/sponsors/sindresorhus"
|
|
2207
2314
|
}
|
|
2208
2315
|
},
|
|
2316
|
+
"node_modules/gopd": {
|
|
2317
|
+
"version": "1.2.0",
|
|
2318
|
+
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
|
|
2319
|
+
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
|
|
2320
|
+
"engines": {
|
|
2321
|
+
"node": ">= 0.4"
|
|
2322
|
+
},
|
|
2323
|
+
"funding": {
|
|
2324
|
+
"url": "https://github.com/sponsors/ljharb"
|
|
2325
|
+
}
|
|
2326
|
+
},
|
|
2209
2327
|
"node_modules/graceful-fs": {
|
|
2210
2328
|
"version": "4.2.10",
|
|
2211
2329
|
"dev": true,
|
|
@@ -2230,6 +2348,42 @@
|
|
|
2230
2348
|
"node": ">=8"
|
|
2231
2349
|
}
|
|
2232
2350
|
},
|
|
2351
|
+
"node_modules/has-symbols": {
|
|
2352
|
+
"version": "1.1.0",
|
|
2353
|
+
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
|
|
2354
|
+
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
|
|
2355
|
+
"engines": {
|
|
2356
|
+
"node": ">= 0.4"
|
|
2357
|
+
},
|
|
2358
|
+
"funding": {
|
|
2359
|
+
"url": "https://github.com/sponsors/ljharb"
|
|
2360
|
+
}
|
|
2361
|
+
},
|
|
2362
|
+
"node_modules/has-tostringtag": {
|
|
2363
|
+
"version": "1.0.2",
|
|
2364
|
+
"resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz",
|
|
2365
|
+
"integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==",
|
|
2366
|
+
"dependencies": {
|
|
2367
|
+
"has-symbols": "^1.0.3"
|
|
2368
|
+
},
|
|
2369
|
+
"engines": {
|
|
2370
|
+
"node": ">= 0.4"
|
|
2371
|
+
},
|
|
2372
|
+
"funding": {
|
|
2373
|
+
"url": "https://github.com/sponsors/ljharb"
|
|
2374
|
+
}
|
|
2375
|
+
},
|
|
2376
|
+
"node_modules/hasown": {
|
|
2377
|
+
"version": "2.0.2",
|
|
2378
|
+
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
|
|
2379
|
+
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
|
|
2380
|
+
"dependencies": {
|
|
2381
|
+
"function-bind": "^1.1.2"
|
|
2382
|
+
},
|
|
2383
|
+
"engines": {
|
|
2384
|
+
"node": ">= 0.4"
|
|
2385
|
+
}
|
|
2386
|
+
},
|
|
2233
2387
|
"node_modules/html-encoding-sniffer": {
|
|
2234
2388
|
"version": "3.0.0",
|
|
2235
2389
|
"license": "MIT",
|
|
@@ -3506,6 +3660,14 @@
|
|
|
3506
3660
|
"node": ">= 12"
|
|
3507
3661
|
}
|
|
3508
3662
|
},
|
|
3663
|
+
"node_modules/math-intrinsics": {
|
|
3664
|
+
"version": "1.1.0",
|
|
3665
|
+
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
|
3666
|
+
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
|
|
3667
|
+
"engines": {
|
|
3668
|
+
"node": ">= 0.4"
|
|
3669
|
+
}
|
|
3670
|
+
},
|
|
3509
3671
|
"node_modules/mdurl": {
|
|
3510
3672
|
"version": "1.0.1",
|
|
3511
3673
|
"dev": true,
|
|
@@ -5443,6 +5605,15 @@
|
|
|
5443
5605
|
"version": "1.1.2",
|
|
5444
5606
|
"dev": true
|
|
5445
5607
|
},
|
|
5608
|
+
"call-bind-apply-helpers": {
|
|
5609
|
+
"version": "1.0.2",
|
|
5610
|
+
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
|
|
5611
|
+
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
|
|
5612
|
+
"requires": {
|
|
5613
|
+
"es-errors": "^1.3.0",
|
|
5614
|
+
"function-bind": "^1.1.2"
|
|
5615
|
+
}
|
|
5616
|
+
},
|
|
5446
5617
|
"callsites": {
|
|
5447
5618
|
"version": "3.1.0",
|
|
5448
5619
|
"dev": true
|
|
@@ -5666,6 +5837,16 @@
|
|
|
5666
5837
|
"domelementtype": "1"
|
|
5667
5838
|
}
|
|
5668
5839
|
},
|
|
5840
|
+
"dunder-proto": {
|
|
5841
|
+
"version": "1.0.1",
|
|
5842
|
+
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
|
5843
|
+
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
|
|
5844
|
+
"requires": {
|
|
5845
|
+
"call-bind-apply-helpers": "^1.0.1",
|
|
5846
|
+
"es-errors": "^1.3.0",
|
|
5847
|
+
"gopd": "^1.2.0"
|
|
5848
|
+
}
|
|
5849
|
+
},
|
|
5669
5850
|
"electron-to-chromium": {
|
|
5670
5851
|
"version": "1.4.284",
|
|
5671
5852
|
"dev": true
|
|
@@ -5689,6 +5870,35 @@
|
|
|
5689
5870
|
"is-arrayish": "^0.2.1"
|
|
5690
5871
|
}
|
|
5691
5872
|
},
|
|
5873
|
+
"es-define-property": {
|
|
5874
|
+
"version": "1.0.1",
|
|
5875
|
+
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
|
|
5876
|
+
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g=="
|
|
5877
|
+
},
|
|
5878
|
+
"es-errors": {
|
|
5879
|
+
"version": "1.3.0",
|
|
5880
|
+
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
|
|
5881
|
+
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw=="
|
|
5882
|
+
},
|
|
5883
|
+
"es-object-atoms": {
|
|
5884
|
+
"version": "1.1.1",
|
|
5885
|
+
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
|
|
5886
|
+
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
|
|
5887
|
+
"requires": {
|
|
5888
|
+
"es-errors": "^1.3.0"
|
|
5889
|
+
}
|
|
5890
|
+
},
|
|
5891
|
+
"es-set-tostringtag": {
|
|
5892
|
+
"version": "2.1.0",
|
|
5893
|
+
"resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz",
|
|
5894
|
+
"integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==",
|
|
5895
|
+
"requires": {
|
|
5896
|
+
"es-errors": "^1.3.0",
|
|
5897
|
+
"get-intrinsic": "^1.2.6",
|
|
5898
|
+
"has-tostringtag": "^1.0.2",
|
|
5899
|
+
"hasown": "^2.0.2"
|
|
5900
|
+
}
|
|
5901
|
+
},
|
|
5692
5902
|
"escalade": {
|
|
5693
5903
|
"version": "3.1.1",
|
|
5694
5904
|
"dev": true
|
|
@@ -5924,10 +6134,14 @@
|
|
|
5924
6134
|
"integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA=="
|
|
5925
6135
|
},
|
|
5926
6136
|
"form-data": {
|
|
5927
|
-
"version": "4.0.
|
|
6137
|
+
"version": "4.0.4",
|
|
6138
|
+
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.4.tgz",
|
|
6139
|
+
"integrity": "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==",
|
|
5928
6140
|
"requires": {
|
|
5929
6141
|
"asynckit": "^0.4.0",
|
|
5930
6142
|
"combined-stream": "^1.0.8",
|
|
6143
|
+
"es-set-tostringtag": "^2.1.0",
|
|
6144
|
+
"hasown": "^2.0.2",
|
|
5931
6145
|
"mime-types": "^2.1.12"
|
|
5932
6146
|
}
|
|
5933
6147
|
},
|
|
@@ -5941,8 +6155,9 @@
|
|
|
5941
6155
|
"optional": true
|
|
5942
6156
|
},
|
|
5943
6157
|
"function-bind": {
|
|
5944
|
-
"version": "1.1.
|
|
5945
|
-
"
|
|
6158
|
+
"version": "1.1.2",
|
|
6159
|
+
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
|
6160
|
+
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA=="
|
|
5946
6161
|
},
|
|
5947
6162
|
"functional-red-black-tree": {
|
|
5948
6163
|
"version": "1.0.1",
|
|
@@ -5956,10 +6171,36 @@
|
|
|
5956
6171
|
"version": "2.0.5",
|
|
5957
6172
|
"dev": true
|
|
5958
6173
|
},
|
|
6174
|
+
"get-intrinsic": {
|
|
6175
|
+
"version": "1.3.0",
|
|
6176
|
+
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
|
|
6177
|
+
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
|
|
6178
|
+
"requires": {
|
|
6179
|
+
"call-bind-apply-helpers": "^1.0.2",
|
|
6180
|
+
"es-define-property": "^1.0.1",
|
|
6181
|
+
"es-errors": "^1.3.0",
|
|
6182
|
+
"es-object-atoms": "^1.1.1",
|
|
6183
|
+
"function-bind": "^1.1.2",
|
|
6184
|
+
"get-proto": "^1.0.1",
|
|
6185
|
+
"gopd": "^1.2.0",
|
|
6186
|
+
"has-symbols": "^1.1.0",
|
|
6187
|
+
"hasown": "^2.0.2",
|
|
6188
|
+
"math-intrinsics": "^1.1.0"
|
|
6189
|
+
}
|
|
6190
|
+
},
|
|
5959
6191
|
"get-package-type": {
|
|
5960
6192
|
"version": "0.1.0",
|
|
5961
6193
|
"dev": true
|
|
5962
6194
|
},
|
|
6195
|
+
"get-proto": {
|
|
6196
|
+
"version": "1.0.1",
|
|
6197
|
+
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
|
|
6198
|
+
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
|
|
6199
|
+
"requires": {
|
|
6200
|
+
"dunder-proto": "^1.0.1",
|
|
6201
|
+
"es-object-atoms": "^1.0.0"
|
|
6202
|
+
}
|
|
6203
|
+
},
|
|
5963
6204
|
"get-stream": {
|
|
5964
6205
|
"version": "6.0.1",
|
|
5965
6206
|
"dev": true
|
|
@@ -5990,6 +6231,11 @@
|
|
|
5990
6231
|
"type-fest": "^0.20.2"
|
|
5991
6232
|
}
|
|
5992
6233
|
},
|
|
6234
|
+
"gopd": {
|
|
6235
|
+
"version": "1.2.0",
|
|
6236
|
+
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
|
|
6237
|
+
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg=="
|
|
6238
|
+
},
|
|
5993
6239
|
"graceful-fs": {
|
|
5994
6240
|
"version": "4.2.10",
|
|
5995
6241
|
"dev": true
|
|
@@ -6005,6 +6251,27 @@
|
|
|
6005
6251
|
"version": "4.0.0",
|
|
6006
6252
|
"dev": true
|
|
6007
6253
|
},
|
|
6254
|
+
"has-symbols": {
|
|
6255
|
+
"version": "1.1.0",
|
|
6256
|
+
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
|
|
6257
|
+
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ=="
|
|
6258
|
+
},
|
|
6259
|
+
"has-tostringtag": {
|
|
6260
|
+
"version": "1.0.2",
|
|
6261
|
+
"resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz",
|
|
6262
|
+
"integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==",
|
|
6263
|
+
"requires": {
|
|
6264
|
+
"has-symbols": "^1.0.3"
|
|
6265
|
+
}
|
|
6266
|
+
},
|
|
6267
|
+
"hasown": {
|
|
6268
|
+
"version": "2.0.2",
|
|
6269
|
+
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
|
|
6270
|
+
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
|
|
6271
|
+
"requires": {
|
|
6272
|
+
"function-bind": "^1.1.2"
|
|
6273
|
+
}
|
|
6274
|
+
},
|
|
6008
6275
|
"html-encoding-sniffer": {
|
|
6009
6276
|
"version": "3.0.0",
|
|
6010
6277
|
"requires": {
|
|
@@ -6867,6 +7134,11 @@
|
|
|
6867
7134
|
"version": "4.2.3",
|
|
6868
7135
|
"dev": true
|
|
6869
7136
|
},
|
|
7137
|
+
"math-intrinsics": {
|
|
7138
|
+
"version": "1.1.0",
|
|
7139
|
+
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
|
7140
|
+
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g=="
|
|
7141
|
+
},
|
|
6870
7142
|
"mdurl": {
|
|
6871
7143
|
"version": "1.0.1",
|
|
6872
7144
|
"dev": true
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -583,7 +583,7 @@ const fileUploader = (client) => {
|
|
|
583
583
|
* @param {FileUploadOptions|undefined} options
|
|
584
584
|
* @returns {Promise<{name: string, md5: string, type: string, size: string, url: string}>}
|
|
585
585
|
*/
|
|
586
|
-
upload: (file, options) => {
|
|
586
|
+
upload: (file, options, fileResPrefix) => {
|
|
587
587
|
console.log(`fileuploader.upload is an experimental feature and is not currently fully functional. It is work in progress and will change in the future.`);
|
|
588
588
|
return new Promise((resolve, reject) => {
|
|
589
589
|
const action = (options && options.action) ? options.action : "publishIfNeeded";
|
|
@@ -631,12 +631,26 @@ const fileUploader = (client) => {
|
|
|
631
631
|
};
|
|
632
632
|
if (action === "publishIfNeeded") {
|
|
633
633
|
try {
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
634
|
+
// Following https://jira.corp.adobe.com/browse/NEO-88828 the fileRes internal name is defined as is:
|
|
635
|
+
// If a prefix is not provided, we keep the old behavior which is to use the prefix 'RES' and the xtkResource counter (i.e.'RES1'...)
|
|
636
|
+
// If a prefix is provided, we use it with a UUID (i.e. 'customPrefix-123e4567-e89b-12d3-a456-426614174000')
|
|
637
|
+
const oldBehaviorPrefix = 'RES';
|
|
638
|
+
const prefix = Util.validateFileResPrefix(fileResPrefix, oldBehaviorPrefix);
|
|
639
|
+
const getUUIDOrFallback = async() => {
|
|
640
|
+
try {
|
|
641
|
+
return Util.getUUID();
|
|
642
|
+
} catch (error) {
|
|
643
|
+
// In case getUUID throws, fall back to increasing the counter
|
|
644
|
+
return await client.NLWS.xtkCounter.increaseValue({ name: 'xtkResource' });
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
const suffix = (prefix === oldBehaviorPrefix) ?
|
|
648
|
+
await client.NLWS.xtkCounter.increaseValue({ name: 'xtkResource' }) : await getUUIDOrFallback();
|
|
649
|
+
|
|
650
|
+
const internalName = (prefix === oldBehaviorPrefix) ? `${prefix}${suffix}` : `${prefix}_${suffix}`;
|
|
651
|
+
|
|
638
652
|
const fileRes = {
|
|
639
|
-
internalName
|
|
653
|
+
internalName,
|
|
640
654
|
md5: data[0].md5,
|
|
641
655
|
label: data[0].fileName,
|
|
642
656
|
fileName: data[0].fileName,
|
package/src/util.js
CHANGED
|
@@ -143,6 +143,33 @@ class Util {
|
|
|
143
143
|
return schemaId;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
+
static validateFileResPrefix(prefix, defaultPrefix = 'RES') {
|
|
147
|
+
const regex = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
148
|
+
|
|
149
|
+
if (typeof prefix !== "string" || !regex.test(prefix)) {
|
|
150
|
+
return defaultPrefix;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return prefix;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
static getUUID() {
|
|
157
|
+
if (globalThis.crypto &&
|
|
158
|
+
globalThis.crypto.randomUUID &&
|
|
159
|
+
typeof globalThis.crypto.randomUUID === 'function') {
|
|
160
|
+
return globalThis.crypto.randomUUID(); // browser
|
|
161
|
+
}
|
|
162
|
+
const nodeCrypto = (() => {
|
|
163
|
+
return require("crypto");
|
|
164
|
+
})();
|
|
165
|
+
if (nodeCrypto && nodeCrypto.randomUUID) {
|
|
166
|
+
return nodeCrypto.randomUUID(); // Node
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
//Nothing worked
|
|
170
|
+
throw new Error('Unable to generate UUID');
|
|
171
|
+
}
|
|
172
|
+
|
|
146
173
|
/**
|
|
147
174
|
* Test if an object is a promise
|
|
148
175
|
* @param {*} object the object to test
|
package/test/client.test.js
CHANGED
|
@@ -27,6 +27,7 @@ const { EntityAccessor } = require('../src/entityAccessor.js');
|
|
|
27
27
|
const { JSDOM } = require('jsdom');
|
|
28
28
|
const dom = new JSDOM();
|
|
29
29
|
const { CampaignException } = require('../src/campaign.js');
|
|
30
|
+
const { Util } = require('../src/util');
|
|
30
31
|
|
|
31
32
|
describe('ACC Client', function () {
|
|
32
33
|
|
|
@@ -3603,7 +3604,7 @@ describe('ACC Client', function () {
|
|
|
3603
3604
|
statusCode: 500,
|
|
3604
3605
|
});
|
|
3605
3606
|
});
|
|
3606
|
-
});
|
|
3607
|
+
}); // "File uploader - on server"
|
|
3607
3608
|
|
|
3608
3609
|
describe("File uploader - on browser", () => {
|
|
3609
3610
|
beforeEach(() => {
|
|
@@ -4217,8 +4218,110 @@ describe('ACC Client', function () {
|
|
|
4217
4218
|
statusCode: 400,
|
|
4218
4219
|
});
|
|
4219
4220
|
});
|
|
4221
|
+
it("Test uploads by specifying a file prefix", async () => {
|
|
4222
|
+
// Create a mock client and logon
|
|
4223
|
+
const client = await Mock.makeClient();
|
|
4224
|
+
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
4225
|
+
await client.NLWS.xtkSession.logon();
|
|
4226
|
+
|
|
4227
|
+
// Mock the upload protocol
|
|
4228
|
+
// - the upload.jsp (which returns the content of an iframe and JS to eval)
|
|
4229
|
+
// - call to xtk:session#Write
|
|
4230
|
+
// - call to xtk:fileRes#PublishIfNeeded
|
|
4231
|
+
// - call to xtk:fileRes#GetURL
|
|
4232
|
+
|
|
4233
|
+
client._transport.mockReturnValueOnce(
|
|
4234
|
+
Promise.resolve(`Ok
|
|
4235
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
4236
|
+
<head>
|
|
4237
|
+
<script type="text/javascript">if(window.parent&&window.parent.document.controller&&"function"==typeof window.parent.document.controller.uploadFileCallBack){var aFilesInfo=new Array;aFilesInfo.push({paramName:"file",fileName:"test.txt",newFileName:"d8e8fca2dc0f896fd7cb4cb0031ba249.txt",md5:"d8e8fca2dc0f896fd7cb4cb0031ba249"}),window.parent.document.controller.uploadFileCallBack(aFilesInfo)}</script>
|
|
4238
|
+
</head>
|
|
4239
|
+
<body></body>
|
|
4240
|
+
</html>`)
|
|
4241
|
+
); // upload.jsp
|
|
4242
|
+
|
|
4243
|
+
client._transport.mockReturnValueOnce(
|
|
4244
|
+
Mock.GET_XTK_SESSION_SCHEMA_RESPONSE
|
|
4245
|
+
); // GetEntityIfMoreRecentResponse - session
|
|
4246
|
+
|
|
4247
|
+
client._transport.mockReturnValueOnce(Mock.FILE_RES_WRITE_RESPONSE); // xtk:session#Write
|
|
4248
|
+
jest.spyOn(Util, 'validateFileResPrefix').mockImplementation((param) => param);
|
|
4249
|
+
|
|
4250
|
+
client._transport.mockReturnValueOnce(
|
|
4251
|
+
Promise.resolve(Mock.GET_FILERES_QUERY_SCHEMA_RESPONSE)
|
|
4252
|
+
); // GetEntityIfMoreRecentResponse - fileRes
|
|
4253
|
+
client._transport.mockReturnValueOnce(
|
|
4254
|
+
Promise.resolve(Mock.PUBLISH_IF_NEEDED_RESPONSE)
|
|
4255
|
+
); // xtk:fileRes#PublishIfNeeded
|
|
4256
|
+
|
|
4257
|
+
client._transport.mockReturnValueOnce(
|
|
4258
|
+
Promise.resolve(Mock.GET_URL_RESPONSE)
|
|
4259
|
+
); // xtk:fileRes#GetURL
|
|
4260
|
+
|
|
4261
|
+
// Call upload
|
|
4262
|
+
await client.fileUploader.upload({
|
|
4263
|
+
type: "text/html",
|
|
4264
|
+
size: 12345,
|
|
4265
|
+
}, undefined, 'PREFIX');
|
|
4266
|
+
expect(Util.validateFileResPrefix).toHaveBeenLastCalledWith('PREFIX', 'RES');
|
|
4220
4267
|
});
|
|
4221
|
-
|
|
4268
|
+
|
|
4269
|
+
it("Test uploads by with a file prefix but getUUID throws", async () => {
|
|
4270
|
+
// Create a mock client and logon
|
|
4271
|
+
const client = await Mock.makeClient();
|
|
4272
|
+
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
4273
|
+
await client.NLWS.xtkSession.logon();
|
|
4274
|
+
|
|
4275
|
+
// Mock the upload protocol
|
|
4276
|
+
// - the upload.jsp (which returns the content of an iframe and JS to eval)
|
|
4277
|
+
// - call to xtk:session#Write
|
|
4278
|
+
// - call to xtk:fileRes#PublishIfNeeded
|
|
4279
|
+
// - call to xtk:fileRes#GetURL
|
|
4280
|
+
|
|
4281
|
+
client._transport.mockReturnValueOnce(
|
|
4282
|
+
Promise.resolve(`Ok
|
|
4283
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
4284
|
+
<head>
|
|
4285
|
+
<script type="text/javascript">if(window.parent&&window.parent.document.controller&&"function"==typeof window.parent.document.controller.uploadFileCallBack){var aFilesInfo=new Array;aFilesInfo.push({paramName:"file",fileName:"test.txt",newFileName:"d8e8fca2dc0f896fd7cb4cb0031ba249.txt",md5:"d8e8fca2dc0f896fd7cb4cb0031ba249"}),window.parent.document.controller.uploadFileCallBack(aFilesInfo)}</script>
|
|
4286
|
+
</head>
|
|
4287
|
+
<body></body>
|
|
4288
|
+
</html>`)
|
|
4289
|
+
); // upload.jsp
|
|
4290
|
+
|
|
4291
|
+
client._transport.mockReturnValueOnce(
|
|
4292
|
+
Promise.resolve(Mock.GET_XTK_COUNTER_RESPONSE)
|
|
4293
|
+
); // GetEntityIfMoreRecentResponse - counter
|
|
4294
|
+
client._transport.mockReturnValueOnce(
|
|
4295
|
+
Mock.INCREASE_VALUE_RESPONSE
|
|
4296
|
+
); // xtk:counter#IncreaseValue
|
|
4297
|
+
|
|
4298
|
+
client._transport.mockReturnValueOnce(
|
|
4299
|
+
Mock.GET_XTK_SESSION_SCHEMA_RESPONSE
|
|
4300
|
+
); // GetEntityIfMoreRecentResponse - session
|
|
4301
|
+
|
|
4302
|
+
client._transport.mockReturnValueOnce(Mock.FILE_RES_WRITE_RESPONSE); // xtk:session#Write
|
|
4303
|
+
jest.spyOn(Util, 'getUUID').mockImplementation(() => { throw new Error('UUID error'); });
|
|
4304
|
+
|
|
4305
|
+
client._transport.mockReturnValueOnce(
|
|
4306
|
+
Promise.resolve(Mock.GET_FILERES_QUERY_SCHEMA_RESPONSE)
|
|
4307
|
+
); // GetEntityIfMoreRecentResponse - fileRes
|
|
4308
|
+
client._transport.mockReturnValueOnce(
|
|
4309
|
+
Promise.resolve(Mock.PUBLISH_IF_NEEDED_RESPONSE)
|
|
4310
|
+
); // xtk:fileRes#PublishIfNeeded
|
|
4311
|
+
|
|
4312
|
+
client._transport.mockReturnValueOnce(
|
|
4313
|
+
Promise.resolve(Mock.GET_URL_RESPONSE)
|
|
4314
|
+
); // xtk:fileRes#GetURL
|
|
4315
|
+
|
|
4316
|
+
// Call upload
|
|
4317
|
+
await client.fileUploader.upload({
|
|
4318
|
+
type: "text/html",
|
|
4319
|
+
size: 12345,
|
|
4320
|
+
}, undefined, 'PREFIX');
|
|
4321
|
+
expect(Util.getUUID).toHaveBeenCalledTimes(1);
|
|
4322
|
+
});
|
|
4323
|
+
}); // "File uploader - on browser"
|
|
4324
|
+
}); // 'upload'
|
|
4222
4325
|
|
|
4223
4326
|
describe('uploadAemAsset', () => {
|
|
4224
4327
|
// write unit test for client.fileUploader.uploadAemAsset method
|
package/test/util.test.js
CHANGED
|
@@ -446,5 +446,116 @@ describe('Util', function() {
|
|
|
446
446
|
await expect(Util.asPromise(Promise.resolve(3))).resolves.toBe(3);
|
|
447
447
|
});
|
|
448
448
|
});
|
|
449
|
+
|
|
450
|
+
describe("Validate file res prefix", () => {
|
|
451
|
+
it("Should return the correct prefix", () => {
|
|
452
|
+
expect(Util.validateFileResPrefix("customPrefix")).toBe("customPrefix");
|
|
453
|
+
expect(Util.validateFileResPrefix("1invalidPrefix")).toBe("RES");
|
|
454
|
+
expect(Util.validateFileResPrefix("anotherInvalidPrefix!")).toBe("RES");
|
|
455
|
+
expect(Util.validateFileResPrefix("valid_prefix_2")).toBe("valid_prefix_2");
|
|
456
|
+
|
|
457
|
+
expect(Util.validateFileResPrefix("valid_prefix_3", "customDefault")).toBe("valid_prefix_3");
|
|
458
|
+
expect(Util.validateFileResPrefix("132Invalid", "customDefault")).toBe("customDefault");
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
describe("GetUUID", () => {
|
|
463
|
+
describe("UUID - on server node", () => {
|
|
464
|
+
describe("node <= 16", () => {
|
|
465
|
+
describe('code coverage: getUUID', () => {
|
|
466
|
+
let originalCrypto;
|
|
467
|
+
// on old Node versions, crypto may not be available
|
|
468
|
+
// deleting globalThis.crypto to simulate the environment on newer Node
|
|
469
|
+
beforeEach(() => {
|
|
470
|
+
// Save the original crypto
|
|
471
|
+
originalCrypto = globalThis.crypto;
|
|
472
|
+
delete globalThis.crypto;
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
afterEach(() => {
|
|
476
|
+
// Restore it after the test
|
|
477
|
+
globalThis.crypto = originalCrypto;
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
it('should handle require("crypto") throwing', () => {
|
|
481
|
+
// Force require("crypto") to throw
|
|
482
|
+
jest.mock('crypto', () => {
|
|
483
|
+
throw new Error('mock require failure');
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
// Re-require the module AFTER mocking
|
|
487
|
+
const UUIDHelper = require('../src/util.js').Util;
|
|
488
|
+
|
|
489
|
+
let exceptionCaught = false;
|
|
490
|
+
try{
|
|
491
|
+
UUIDHelper.getUUID();
|
|
492
|
+
} catch (e) {
|
|
493
|
+
exceptionCaught = true;
|
|
494
|
+
}
|
|
495
|
+
expect(exceptionCaught).toBe(true);
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
it('should handle require("crypto") throwing', () => {
|
|
499
|
+
// Force require("crypto") to not have randomUUID
|
|
500
|
+
jest.mock('crypto', () => ({}));
|
|
501
|
+
|
|
502
|
+
// Re-require the module AFTER mocking
|
|
503
|
+
const UUIDHelper = require('../src/util.js').Util;
|
|
504
|
+
|
|
505
|
+
let exceptionCaught = false;
|
|
506
|
+
try{
|
|
507
|
+
UUIDHelper.getUUID();
|
|
508
|
+
} catch (e) {
|
|
509
|
+
exceptionCaught = e.message === 'Unable to generate UUID';
|
|
510
|
+
}
|
|
511
|
+
expect(exceptionCaught).toBe(true);
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
it('should fallback to node crypto when globalThis.crypto is not available', () => {
|
|
515
|
+
jest.unmock('crypto');
|
|
516
|
+
// Spy on require
|
|
517
|
+
const spy = jest.spyOn(require('crypto'), 'randomUUID').mockReturnValue('mock-uuid');
|
|
518
|
+
|
|
519
|
+
// Re-import the module if your getUUID function is from a module
|
|
520
|
+
const uuid = Util.getUUID(); // or just call getUUID() if it's in scope
|
|
521
|
+
|
|
522
|
+
expect(uuid).toBe('mock-uuid');
|
|
523
|
+
expect(spy).toHaveBeenCalled();
|
|
524
|
+
spy.mockRestore();
|
|
525
|
+
});
|
|
526
|
+
});
|
|
527
|
+
});
|
|
528
|
+
});
|
|
529
|
+
describe("node > 16", () => {
|
|
530
|
+
it('should return a correct UUID v4', () => {
|
|
531
|
+
// x is [0-9a-f], Y is 8, 9, a or b
|
|
532
|
+
// uuid format: xxxxxxxx-xxxx-4xxx-Yxxx-xxxxxxxxxxxx
|
|
533
|
+
const uuidV4Regex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
534
|
+
expect(uuidV4Regex.test(Util.getUUID())).toBe(true);
|
|
535
|
+
});
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
describe("UUID - on browser", () => {
|
|
539
|
+
// code coverage test as we mock the browser return values
|
|
540
|
+
it('should return a correct UUID v4', () => {
|
|
541
|
+
if (!globalThis.crypto || !globalThis.crypto.randomUUID){
|
|
542
|
+
globalThis.crypto = {
|
|
543
|
+
...globalThis.crypto,
|
|
544
|
+
randomUUID: jest.fn(),
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
// x is [0-9a-f], Y is 8, 9, a or b
|
|
549
|
+
// uuid v4 format: xxxxxxxx-xxxx-4xxx-Yxxx-xxxxxxxxxxxx
|
|
550
|
+
// Mocking crypto.randomUUID to return a specific valid v4 UUID
|
|
551
|
+
jest.spyOn(globalThis.crypto, 'randomUUID').mockReturnValue('123e4567-e89b-42d3-a456-426614174000');
|
|
552
|
+
const uuidV4Regex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
553
|
+
expect(uuidV4Regex.test(Util.getUUID())).toBe(true);
|
|
554
|
+
// Mocking crypto.randomUUID to return a specific an invalid v4 UUID
|
|
555
|
+
jest.spyOn(globalThis.crypto, 'randomUUID').mockReturnValue('12345678-1234-0234-0567-426614174000');
|
|
556
|
+
expect(uuidV4Regex.test(Util.getUUID())).toBe(false);
|
|
557
|
+
});
|
|
558
|
+
});
|
|
559
|
+
});
|
|
449
560
|
});
|
|
450
561
|
|