@salesforce/pwa-kit-dev 3.0.0-preview.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.
Files changed (54) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +35 -0
  3. package/bin/pwa-kit-dev.js +461 -0
  4. package/configs/babel/babel-config.js +34 -0
  5. package/configs/eslint/README.md +21 -0
  6. package/configs/eslint/eslint-config.js +11 -0
  7. package/configs/eslint/index.js +11 -0
  8. package/configs/eslint/no-react.js +18 -0
  9. package/configs/eslint/partials/base.js +38 -0
  10. package/configs/eslint/partials/jest.js +24 -0
  11. package/configs/eslint/partials/react.js +29 -0
  12. package/configs/eslint/partials/typescript-permit-any.js +31 -0
  13. package/configs/eslint/partials/typescript.js +17 -0
  14. package/configs/eslint/recommended.js +20 -0
  15. package/configs/eslint/safe-types.js +20 -0
  16. package/configs/jest/jest-babel-transform.js +19 -0
  17. package/configs/jest/jest.config.js +33 -0
  18. package/configs/jest/mocks/fileMock.js +9 -0
  19. package/configs/jest/mocks/styleMock.js +9 -0
  20. package/configs/jest/mocks/svgMock.js +11 -0
  21. package/configs/webpack/config-names.js +24 -0
  22. package/configs/webpack/config.js +425 -0
  23. package/configs/webpack/overrides-plugin.js +120 -0
  24. package/configs/webpack/plugins.js +92 -0
  25. package/package.json +150 -0
  26. package/scripts/version.js +22 -0
  27. package/ssr/server/build-dev-server.js +443 -0
  28. package/ssr/server/build-dev-server.test.js +635 -0
  29. package/ssr/server/loading-screen/css/main.css +272 -0
  30. package/ssr/server/loading-screen/css/normalize.css +349 -0
  31. package/ssr/server/loading-screen/img/cloud-1.svg +1 -0
  32. package/ssr/server/loading-screen/img/cloud-2.svg +1 -0
  33. package/ssr/server/loading-screen/img/cloud-3.svg +1 -0
  34. package/ssr/server/loading-screen/img/cloud.svg +1 -0
  35. package/ssr/server/loading-screen/img/codey-arm.svg +1 -0
  36. package/ssr/server/loading-screen/img/codey-bear.svg +1 -0
  37. package/ssr/server/loading-screen/img/codey-bg.svg +1 -0
  38. package/ssr/server/loading-screen/img/codey-cloud.svg +1 -0
  39. package/ssr/server/loading-screen/img/codey-search.svg +1 -0
  40. package/ssr/server/loading-screen/img/codey.svg +1 -0
  41. package/ssr/server/loading-screen/img/codeyCarry.svg +1 -0
  42. package/ssr/server/loading-screen/img/devDocumentation.svg +1 -0
  43. package/ssr/server/loading-screen/img/devGithub.svg +1 -0
  44. package/ssr/server/loading-screen/img/devTrailhead.svg +1 -0
  45. package/ssr/server/loading-screen/img/logo.svg +1 -0
  46. package/ssr/server/loading-screen/img/slds_spinner_brand_9EA9F1.gif +0 -0
  47. package/ssr/server/loading-screen/index.html +130 -0
  48. package/ssr/server/test_fixtures/app/main.js +6 -0
  49. package/ssr/server/test_fixtures/app/static/favicon.ico +0 -0
  50. package/ssr/server/test_fixtures/localhost.pem +45 -0
  51. package/utils/script-utils.js +312 -0
  52. package/utils/script-utils.test.js +282 -0
  53. package/utils/test-fixtures/minimal-built-app/ssr.js +9 -0
  54. package/utils/test-fixtures/minimal-built-app/static/favicon.ico +0 -0
@@ -0,0 +1 @@
1
+ <svg fill="none" height="34" viewBox="0 0 48 34" width="48" xmlns="http://www.w3.org/2000/svg"><path d="m19.9691 3.6516c1.5524-1.60529 3.7045-2.61081 6.086-2.61081 3.1753 0 5.9273 1.76406 7.4091 4.39251 1.2877-.5645 2.699-.88203 4.1808-.88203 5.7155 0 10.355 4.67475 10.355 10.44323 0 5.7685-4.6395 10.4432-10.355 10.4432-.7056 0-1.376-.0706-2.0463-.2117-1.2878 2.3109-3.7751 3.8809-6.5976 3.8809-1.1819 0-2.3109-.2822-3.3164-.7585-1.3231 3.0871-4.3749 5.2569-7.9383 5.2569-3.7221 0-6.8798-2.3462-8.09701-5.645-.52922.1059-1.07607.1764-1.64057.1764-4.42778 0-8.00882-3.6339-8.00882-8.097 0-2.9989 1.60529-5.6097 4.00441-7.021-.49394-1.129-.75855-2.3814-.75855-3.70448 0-5.15105 4.18082-9.31422 9.33184-9.31422 2.9989 0 5.6803 1.42889 7.3914 3.6516z" fill="#0d9dda"/><g fill="#fff"><path d="m6.93254 17.4289c-.03528.0705.01764.0882.01764.1058.0882.0706.17641.1059.28225.1588.49394.2646.95259.3352 1.42889.3352.98787 0 1.60528-.5292 1.60528-1.3584v-.0176c0-.7762-.68797-1.0584-1.34067-1.2701l-.08821-.0353c-.49393-.1588-.91731-.2999-.91731-.6174v-.0177c0-.2822.24697-.4763.63506-.4763.42338 0 .93495.1412 1.25248.3176 0 0 .0882.0529.12349-.0353.01764-.0529.17636-.4939.19406-.5469.0176-.0529-.0177-.0882-.0529-.1058-.37049-.2293-.88207-.3705-1.41128-.3705h-.10585c-.89967 0-1.53473.5469-1.53473 1.3231v.0176c0 .8291.68798 1.0937 1.34069 1.2701l.10584.0353c.4763.1412.88203.2646.88203.5998v.0176c0 .2999-.26461.5293-.68798.5293-.15877 0-.68799 0-1.27013-.3705-.07056-.0353-.10584-.0706-.15876-.1058-.03528-.0177-.10585-.053-.12349.0529z"/><path d="m21.3627 17.4289c-.0353.0705.0177.0882.0177.1058.0882.0706.1764.1059.2822.1588.4939.2646.9526.3352 1.4289.3352.9879 0 1.6053-.5292 1.6053-1.3584v-.0176c0-.7762-.688-1.0584-1.3407-1.2701l-.0882-.0353c-.4939-.1588-.9173-.2999-.9173-.6174v-.0177c0-.2822.247-.4763.635-.4763.4234 0 .935.1412 1.2525.3176 0 0 .0882.0529.1235-.0353.0177-.0529.1764-.4939.1941-.5469.0176-.0529-.0177-.0882-.053-.1058-.3704-.2293-.882-.3705-1.4112-.3705h-.1059c-.8996 0-1.5347.5469-1.5347 1.3231v.0176c0 .8291.688 1.0937 1.3407 1.2701l.1058.0353c.4763.1412.8821.2646.8821.5998v.0176c0 .2999-.2646.5293-.688.5293-.1588 0-.688 0-1.2701-.3705-.0706-.0353-.1059-.0706-.1588-.1058-.0176-.0177-.1058-.0353-.1235.0529z"/><path d="m32.0177 14.8887c-.0882-.2646-.2117-.5116-.3704-.7057-.1765-.194-.3881-.3704-.6351-.4762-.247-.1235-.5469-.1765-.882-.1765-.3352 0-.6351.053-.8821.1765-.2469.1234-.4586.2822-.635.4762-.1588.1941-.2999.4411-.3705.7057-.0882.2646-.1235.5645-.1235.882s.0353.6174.1235.882.2117.5116.3705.7057c.1764.194.3881.3704.635.4762.247.1059.5469.1765.8821.1765.3351 0 .635-.053.882-.1765.247-.1058.4586-.2822.6351-.4762.1587-.1941.2998-.4411.3704-.7057.0882-.2646.1235-.5645.1235-.882s-.0353-.6174-.1235-.882zm-.8115.882c0 .4763-.0882.8468-.2646 1.1114s-.441.388-.7938.388c-.3704 0-.6174-.1234-.7938-.388s-.2646-.6351-.2646-1.1114.0882-.8467.2646-1.1114c.1764-.2646.4234-.388.7938-.388.3705 0 .6351.1234.7938.388.1764.2647.2646.6351.2646 1.1114z"/><g clip-rule="evenodd" fill-rule="evenodd"><path d="m38.7741 17.1466c-.0353-.0882-.1059-.0529-.1059-.0529-.1235.0529-.247.0882-.3881.1059-.1411.0176-.2822.0352-.4586.0352-.4058 0-.7057-.1234-.935-.3528-.2293-.2293-.3528-.6174-.3528-1.129 0-.4586.1058-.8114.3175-1.076.1941-.2646.5116-.4058.9173-.4058.3352 0 .5998.0353.8644.1235 0 0 .0706.0353.0882-.0529.0706-.1941.1235-.3352.1941-.5645.0176-.0706-.0353-.0882-.0529-.0882-.1059-.0353-.3529-.1059-.5469-.1411-.1764-.0353-.3881-.0353-.6174-.0353-.3528 0-.6527.0529-.9173.1764s-.494.2822-.6704.4763c-.1764.194-.3175.441-.4057.7056s-.1411.5645-.1411.882c0 .688.1764 1.2349.5468 1.6406.3705.4057.9173.6174 1.623.6174.4233 0 .8467-.0882 1.1642-.2117 0 0 .053-.0352.0353-.1058z"/><path d="m42.9722 14.7299c-.0706-.2646-.247-.5292-.3528-.6527-.1765-.1941-.3529-.3352-.5293-.4058-.2293-.1058-.4939-.1587-.7938-.1587-.3528 0-.6703.0529-.9173.1764-.2646.1235-.4763.2822-.6351.4939-.1764.2117-.2999.441-.3704.7233-.0882.2822-.1235.5645-.1235.882s.0353.6174.1235.882c.0882.2647.2117.5116.4057.7057.1764.194.4234.3528.7056.4586.2823.1059.6175.1588 1.0055.1588.8115 0 1.2349-.1764 1.3937-.2823.0352-.0176.0529-.0529.0176-.1411l-.1764-.5116c-.0353-.0705-.1058-.0529-.1058-.0529-.1941.0706-.4763.2117-1.1467.2117-.4234 0-.7585-.1235-.9526-.3352-.2117-.2117-.2999-.5115-.3175-.9173h2.7872s.0706 0 .0882-.0705c-.0176 0 .0706-.5293-.1058-1.1643zm-2.7696.5821c.0353-.2646.1058-.4763.2293-.6527.1764-.2646.4234-.4057.7938-.4057.3705 0 .5998.1411.7762.4057.1235.1764.1588.4057.1764.6527z"/><path d="m20.6924 14.7299c-.0706-.2646-.247-.5292-.3528-.6527-.1764-.1941-.3528-.3352-.5293-.4058-.2293-.1058-.4939-.1587-.7938-.1587-.3528 0-.6703.0529-.9173.1764-.2646.1235-.4763.2822-.635.4939-.1765.2117-.2999.441-.3705.7233-.0882.2822-.1235.5645-.1235.882s.0353.6174.1235.882c.0882.2647.2117.5116.4057.7057.1764.194.4234.3528.7057.4586.2822.1059.6174.1588 1.0055.1588.8114 0 1.2348-.1764 1.3936-.2823.0353-.0176.0529-.0529.0176-.1411l-.1764-.5116c-.0353-.0705-.1058-.0529-.1058-.0529-.1941.0706-.4763.2117-1.1467.2117-.4233 0-.7585-.1235-.9526-.3352-.2116-.2117-.2998-.5115-.3175-.9173h2.7872s.0706 0 .0882-.0705c-.0176 0 .0706-.5293-.1058-1.1643zm-2.7696.5821c.0353-.2646.1059-.4763.2293-.6527.1764-.2646.4234-.4057.7939-.4057.3704 0 .5997.1411.7761.4057.1059.1764.1588.4057.1765.6527z"/></g><path d="m13.0187 15.1709c-.1058 0-.2646-.0177-.441-.0177-.2469 0-.4763.0353-.688.0883-.2116.0529-.4057.1411-.5821.2646-.1764.1234-.2999.2822-.4057.4586-.1059.1764-.1412.4058-.1412.6351 0 .2469.0353.4586.1235.635s.2117.3176.3705.4411c.1587.1058.3528.194.5645.2469s.4586.0706.7409.0706c.2822 0 .5645-.0177.8467-.0706.2646-.0529.5998-.1058.7057-.1411.0882-.0176.194-.0529.194-.0529.0706-.0177.0706-.0882.0706-.0882v-2.5403c0-.5645-.1412-.9702-.4411-1.2348-.2998-.247-.7232-.3881-1.2701-.3881-.2117 0-.5468.0353-.7409.0706 0 0-.5998.1234-.8644.3175 0 0-.0529.0353-.0176.1058l.194.5293c.0177.0705.0882.0529.0882.0529s.0177 0 .053-.0177c.5292-.2822 1.2172-.2822 1.2172-.2822.2999 0 .5292.0529.6879.1764.1588.1235.2294.2999.2294.6703v.1235c-.2823-.0176-.494-.0529-.494-.0529zm-1.1113 1.9581c-.1059-.0882-.1235-.1058-.1588-.1588-.0529-.0882-.0882-.2117-.0882-.3704 0-.247.0882-.4234.247-.5469 0 0 .2469-.2117.8114-.194.4058 0 .7586.0705.7586.0705v1.2702s-.3528.0705-.7586.1058c-.5645.0176-.8114-.1764-.8114-.1764z"/><path clip-rule="evenodd" d="m35.4574 13.742c.0176-.0705-.0177-.0882-.0353-.1058-.0529-.0177-.2823-.0706-.4587-.0706-.3528-.0176-.5468.0353-.7232.1235-.1764.0706-.3705.2117-.4763.3528v-.3352c0-.0529-.0353-.0882-.0882-.0882h-.7057c-.0529 0-.0882.0353-.0882.0882v4.1456c0 .0529.0353.0882.0882.0882h.7233c.0529 0 .0882-.0353.0882-.0882v-2.0816c0-.2823.0353-.5645.0882-.7233.0529-.1764.1411-.3175.247-.4057.1058-.1059.2117-.1764.3351-.2117.1235-.0353.2647-.0529.3705-.0529.1411 0 .2999.0353.2999.0353.0529 0 .0882-.0353.1058-.0706.0706-.1411.2117-.5292.2294-.5998z" fill-rule="evenodd"/><path clip-rule="evenodd" d="m28.5953 11.8192c-.0882-.0353-.1764-.0529-.2823-.0705-.1058-.0177-.2293-.0353-.3704-.0353-.5116 0-.8997.1411-1.182.4234-.2822.2822-.4586.7056-.5645 1.2701l-.0352.194h-.6351s-.0706 0-.0882.0882l-.1058.5822c0 .0529.0176.0882.0882.0882h.6174l-.6174 3.4752c-.053.2822-.1059.5115-.1588.6879s-.1235.2999-.1941.3881c-.0705.0882-.1411.1588-.2469.1941-.0882.0353-.2117.0529-.3352.0529-.0706 0-.1588-.0176-.2293-.0176-.0706-.0177-.1059-.0353-.1588-.053 0 0-.0705-.0352-.1058.053-.0177.0529-.1941.5115-.2117.5645-.0177.0529 0 .1058.0353.1058.0882.0353.1411.0529.2469.0706.1588.0352.2823.0352.4058.0352.2646 0 .4939-.0352.6879-.1058.1941-.0706.3705-.194.5116-.3528.1588-.1764.2646-.3705.3528-.6174.0882-.247.1764-.5645.247-.935l.6351-3.5457h.9173s.0705 0 .0882-.0882l.1058-.5822c0-.0529-.0176-.0882-.0882-.0882h-.882c0-.0176.0529-.3351.1411-.635.0353-.1235.1235-.2294.1941-.2999.0705-.0706.1411-.1235.2293-.1412.0882-.0352.194-.0352.2999-.0352.0882 0 .1587.0176.2293.0176.0882.0176.1235.0353.1411.0353.0882.0353.1059 0 .1235-.0353l.2117-.5821c.0529-.0706 0-.0882-.0176-.1059z" fill-rule="evenodd"/><path clip-rule="evenodd" d="m16.1585 17.8346c0 .0529-.0353.0882-.0882.0882h-.7409c-.0529 0-.0882-.0353-.0882-.0882v-5.9272c0-.0529.0353-.0882.0882-.0882h.7409c.0529 0 .0882.0353.0882.0882z" fill-rule="evenodd"/></g></svg>
@@ -0,0 +1,130 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8"/>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
6
+ <title>Building your app...</title>
7
+ <link rel="stylesheet" href="./css/normalize.css">
8
+ <link rel="stylesheet" href="./css/main.css">
9
+ </head>
10
+ <body>
11
+ <main>
12
+ <div class="wrapper">
13
+ <div class="main-img">
14
+ <img class="layer layer-2" src="./img/codey-bg.svg" />
15
+ <img class="layer layer-1" src="./img/codey-bear.svg" />
16
+ <img class="layer cloud-1" src="./img/cloud-1.svg" />
17
+ <img class="layer cloud-2" src="./img/cloud-2.svg" />
18
+ <img class="layer cloud-3" src="./img/cloud-3.svg" />
19
+ </div>
20
+ <div class="message">
21
+ <h1 class="loading-text">Building your app</h1>
22
+ <div class="fun-facts">
23
+ <p class="fun-fact">Tip: <code>AppConfig</code> is one of four special components in PWA Kit for adding functionality across multiple pages. <a target="_blank" href="https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/special-components.html">Learn more</a>.</p>
24
+ <p class="fun-fact">Tip: You can use the <code>getProps</code> method to inject data from API requests into your pages. <a target="_blank" href="https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/routing.html">Learn more</a>.</p>
25
+ <p class="fun-fact">Tip: Maximizing your cache hit ratio can drastically improve storefront performance. <a target="_blank" href="https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/maximizing-your-cache-hit-ratio.html">Learn more</a>.</p>
26
+ <p class="fun-fact">Pop quiz: What does SLAS stand for? See the <a target="_blank" href="https://developer.salesforce.com/docs/commerce/commerce-api/references?meta=shopper-login:Summary">SLAS docs</a> for the answer!</p>
27
+ <p class="fun-fact">Fun fact: In PWA Kit 1.4, we now support React 17. <a target="_blank" href="https://github.com/SalesforceCommerceCloud/pwa-kit/releases">Learn more</a>.</p>
28
+ <p class="fun-fact">Want to write in TypeScript? You can start now!</p>
29
+ <p class="fun-fact">Have you seen the new <a target="_blank" href="https://developer.salesforce.com/developer-centers/commerce-cloud">Commerce Cloud</a> page on the Salesforce Developers portal?</p>
30
+ <p class="fun-fact">Want to learn more about composable commerce? Hang out with us at <a target="_blank" href="https://www.salesforce.com/trailblazerdx/">TrailblazerDX 2022</a>!</p>
31
+ <p class="fun-fact">The Retail React App template implements core ecommerce flows from home page to checkout. <a target="_blank" href="https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/retail-react-app.html">Learn more</a>.</p>
32
+ </div>
33
+ </div>
34
+ </div>
35
+ </main>
36
+
37
+ <footer>
38
+ <div class="logo">
39
+ <img src="./img/logo.svg" />
40
+ </div>
41
+
42
+ <ul class="external-links">
43
+ <li>
44
+ <a href="https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/overview" target="_blank">
45
+ <img src="./img/devDocumentation.svg" alt="Documentation"/>
46
+ <span>Documentation</span>
47
+ </a>
48
+ </li>
49
+ <li>
50
+ <a href="https://github.com/SalesforceCommerceCloud/pwa-kit" target="_blank">
51
+ <img src="./img/devGithub.svg" alt="GitHub"/>
52
+ <span>Github</span>
53
+ </a>
54
+ </li>
55
+ <li>
56
+ <a href="https://trailhead.salesforce.com/en/content/learn/modules/commerce-pwa-kit-and-managed-runtime" target="_blank">
57
+ <img src="./img/devTrailhead.svg" alt="Trailhead"/>
58
+ <span>Trailhead</span>
59
+ </a>
60
+ </li>
61
+ </ul>
62
+ </footer>
63
+
64
+ <script>
65
+ (function() {
66
+ const url = new URL(window.location)
67
+ const loading = url.searchParams.get('loading')
68
+
69
+ if (loading === '1') {
70
+ const interval = 1000
71
+ const waitForReady = () => {
72
+ return new Promise((resolve) => {
73
+ const checkReady = () => {
74
+ fetch('/__mrt/status')
75
+ .then((res) => res.json())
76
+ .then((data) => {
77
+ if (data.ready) {
78
+ resolve()
79
+ } else {
80
+ setTimeout(checkReady, interval)
81
+ }
82
+ })
83
+ }
84
+ checkReady()
85
+ })
86
+ }
87
+
88
+ waitForReady().then(() => {
89
+ // Redirect to homepage
90
+ window.location = url.origin
91
+ })
92
+ }
93
+
94
+ const animateFacts = () => {
95
+ const holdMs = 7000; // Show time for each fun fact
96
+ const transitionMs = 433; // Cross-fade time for each fun fact (once at the beginning, another at the end)
97
+ const facts = document.querySelectorAll('.fun-fact');
98
+ facts.forEach((fact) => {
99
+ fact.style.transitionDuration = transitionMs + 'ms';
100
+ fact.classList.add('fun-fact--hidden');
101
+ });
102
+ let counter = 0;
103
+
104
+ const modulo = (x, y) => ((x % y) + y) % y
105
+
106
+ const update = () => {
107
+ const previous = modulo(counter - 1, facts.length)
108
+ const current = modulo(counter, facts.length)
109
+ facts[previous].classList.remove('fun-fact--show')
110
+ setTimeout(() => facts[previous].classList.add('fun-fact--hidden'), transitionMs)
111
+ facts[current].classList.remove('fun-fact--hidden')
112
+ setTimeout(() => facts[current].classList.add('fun-fact--show'), 50)
113
+ }
114
+ update();
115
+ setInterval(() => {
116
+ counter += 1;
117
+ update()
118
+ }, holdMs)
119
+ }
120
+ animateFacts()
121
+ })()
122
+ </script>
123
+
124
+ <script>
125
+ (function() {
126
+ fetch('/__mrt/clear-browser-data')
127
+ })()
128
+ </script>
129
+ </body>
130
+ </html>
@@ -0,0 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2021, salesforce.com, inc.
3
+ * All rights reserved.
4
+ * SPDX-License-Identifier: BSD-3-Clause
5
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
+ */
@@ -0,0 +1,45 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIIEowIBAAKCAQEA2jfc6QnD73JTV4HpxyC6IMhJfOGnPPx//ZZrcUEPEYe1M+cC
3
+ K471lvqWtl8TMJDcKwIlLPzC84JeoobUYHPjhfrbO4pt/8T4eMRGVn+L4UmEyIzG
4
+ /c9tXc9U9mtGEAiIeRplgcfwA0RiTG/gQ817qC8Oc2PLHzBupuGuuOBs90YrHGfI
5
+ Q9gvJ0RrEDym7u3NW++NKT4AzFk6NRL+CFlo4HG0Xb2y+oNmwDRU7L26TVyXRgn1
6
+ QiCIHJw5D6CB4jjXzZDD8Uj4N7hkfM8IjNv4Qs7gaRjS0yNLnqB2f0XEsQG8vn51
7
+ h2EtCPT36msgNz0RAYzDBl7c1aD5fAWyXDfPHQIDAQABAoIBABtWODRxZrxOZCZo
8
+ PfMWJHsK3Dnqwtqe/yGzgE41yj918rtHyzvNsvJw/gRmsK661voEUMfr+jgrMtPF
9
+ dEGJAw27uU8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w7Eq6BnJS4vfbxhf0a2bV3+Cv+HOjJPLHNS+O
42
+ SzggRD8O7uB6FOf0ni38j7ndvU8Z9ylYgtNOqsB2pGfQMyGjPObbY8NzUSbrHeWG
43
+ NJEdY8aW3q62elexs5y3y1t7epzfrmlrL3p4b/lQewLM5/Fn90qSF3St9baugF0m
44
+ hjHf9mKEV706lXDQvLkWt+sE/GwP2lsDa8czfZY=
45
+ -----END CERTIFICATE-----
@@ -0,0 +1,312 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.readCredentials = exports.parseLog = exports.glob = exports.getProjectPkg = exports.getPkgJSON = exports.getCredentialsFile = exports.defaultMessage = exports.createBundle = exports.DEFAULT_DOCS_URL = exports.DEFAULT_CLOUD_ORIGIN = exports.CloudAPIClient = void 0;
7
+ var _os = _interopRequireDefault(require("os"));
8
+ var _path = _interopRequireDefault(require("path"));
9
+ var _archiver = _interopRequireDefault(require("archiver"));
10
+ var _nodeFetch = _interopRequireDefault(require("node-fetch"));
11
+ var _url = require("url");
12
+ var _promises = require("fs/promises");
13
+ var _fs = require("fs");
14
+ var _fsExtra = require("fs-extra");
15
+ var _minimatch = require("minimatch");
16
+ var _gitRevSync = _interopRequireDefault(require("git-rev-sync"));
17
+ var _validator = _interopRequireDefault(require("validator"));
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
20
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
21
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
22
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
23
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
24
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
25
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } /*
26
+ * Copyright (c) 2022, Salesforce, Inc.
27
+ * All rights reserved.
28
+ * SPDX-License-Identifier: BSD-3-Clause
29
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
30
+ */
31
+ const DEFAULT_CLOUD_ORIGIN = 'https://cloud.mobify.com';
32
+ exports.DEFAULT_CLOUD_ORIGIN = DEFAULT_CLOUD_ORIGIN;
33
+ const DEFAULT_DOCS_URL = 'https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/pushing-and-deploying-bundles.html';
34
+ exports.DEFAULT_DOCS_URL = DEFAULT_DOCS_URL;
35
+ /**
36
+ * Get the package info for pwa-kit-dev.
37
+ */
38
+ const getPkgJSON = /*#__PURE__*/function () {
39
+ var _ref = _asyncToGenerator(function* () {
40
+ const candidates = [_path.default.join(__dirname, '..', 'package.json'), _path.default.join(__dirname, '..', '..', 'package.json')];
41
+ for (const candidate of candidates) {
42
+ try {
43
+ const data = yield (0, _fsExtra.readJson)(candidate);
44
+ return data;
45
+ } catch {
46
+ // Keep looking
47
+ }
48
+ }
49
+ return {
50
+ name: '@salesforce/pwa-kit-dev',
51
+ version: 'unknown'
52
+ };
53
+ });
54
+ return function getPkgJSON() {
55
+ return _ref.apply(this, arguments);
56
+ };
57
+ }();
58
+
59
+ /**
60
+ * Get the package info for the current project.
61
+ */
62
+ exports.getPkgJSON = getPkgJSON;
63
+ const getProjectPkg = /*#__PURE__*/function () {
64
+ var _ref2 = _asyncToGenerator(function* () {
65
+ const p = _path.default.join(process.cwd(), 'package.json');
66
+ try {
67
+ const data = yield (0, _fsExtra.readJson)(p);
68
+ return data;
69
+ } catch {
70
+ throw new Error(`Could not read project package at "${p}"`);
71
+ }
72
+ });
73
+ return function getProjectPkg() {
74
+ return _ref2.apply(this, arguments);
75
+ };
76
+ }();
77
+ exports.getProjectPkg = getProjectPkg;
78
+ class CloudAPIClient {
79
+ constructor(params) {
80
+ this.opts = {
81
+ origin: params.origin || DEFAULT_CLOUD_ORIGIN,
82
+ fetch: params.fetch || _nodeFetch.default,
83
+ credentials: params.credentials
84
+ };
85
+ }
86
+ getAuthHeader() {
87
+ const {
88
+ username,
89
+ api_key
90
+ } = this.opts.credentials;
91
+ const encoded = Buffer.from(`${username}:${api_key}`, 'binary').toString('base64');
92
+ return {
93
+ Authorization: `Basic ${encoded}`
94
+ };
95
+ }
96
+ getHeaders() {
97
+ var _this = this;
98
+ return _asyncToGenerator(function* () {
99
+ const pkg = yield getPkgJSON();
100
+ return _objectSpread({
101
+ 'User-Agent': `${pkg.name}@${pkg.version}`
102
+ }, _this.getAuthHeader());
103
+ })();
104
+ }
105
+ throwForStatus(res) {
106
+ return _asyncToGenerator(function* () {
107
+ if (res.status < 400) {
108
+ return;
109
+ }
110
+ const body = yield res.text();
111
+ let error;
112
+ try {
113
+ error = JSON.parse(body);
114
+ } catch {
115
+ error = {}; // Cloud doesn't always return JSON
116
+ }
117
+
118
+ if (res.status === 403) {
119
+ error.docs_url = 'https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/mrt-overview.html#users,-abilities,-and-roles';
120
+ }
121
+ throw new Error([`HTTP ${res.status}`, error.message || body, `For more information visit ${error.docs_url || DEFAULT_DOCS_URL}`].join('\n'));
122
+ })();
123
+ }
124
+ push(bundle, projectSlug, target) {
125
+ var _this2 = this;
126
+ return _asyncToGenerator(function* () {
127
+ const base = `api/projects/${projectSlug}/builds/`;
128
+ const pathname = target ? base + `${target}/` : base;
129
+ const url = new _url.URL(_this2.opts.origin);
130
+ url.pathname = pathname;
131
+ const body = Buffer.from(JSON.stringify(bundle));
132
+ const headers = _objectSpread(_objectSpread({}, yield _this2.getHeaders()), {}, {
133
+ 'Content-Length': body.length.toString()
134
+ });
135
+ const res = yield _this2.opts.fetch(url.toString(), {
136
+ body,
137
+ method: 'POST',
138
+ headers
139
+ });
140
+ yield _this2.throwForStatus(res);
141
+ return yield res.json();
142
+ })();
143
+ }
144
+ createLoggingToken(project, environment) {
145
+ var _this3 = this;
146
+ return _asyncToGenerator(function* () {
147
+ const url = new _url.URL(_this3.opts.origin);
148
+ url.pathname = `/api/projects/${project}/target/${environment}/jwt/`;
149
+ const headers = _objectSpread(_objectSpread({}, yield _this3.getHeaders()), {}, {
150
+ // Annoyingly, the new logging endpoint only accepts an
151
+ // Authorization header that is inconsistent with our older APIs!
152
+ Authorization: `Bearer ${_this3.opts.credentials.api_key}`
153
+ });
154
+ const res = yield _this3.opts.fetch(url.toString(), {
155
+ method: 'POST',
156
+ headers
157
+ });
158
+ yield _this3.throwForStatus(res);
159
+ const data = yield res.json();
160
+ return data['token'];
161
+ })();
162
+ }
163
+ }
164
+ exports.CloudAPIClient = CloudAPIClient;
165
+ const defaultMessage = (gitInstance = _gitRevSync.default) => {
166
+ try {
167
+ return `${gitInstance.branch()}: ${gitInstance.short()}`;
168
+ } catch (err) {
169
+ if ((err === null || err === void 0 ? void 0 : err.code) === 'ENOENT') {
170
+ console.log('Using default bundle message as no message was provided and not in a Git repo.');
171
+ }
172
+ return 'PWA Kit Bundle';
173
+ }
174
+ };
175
+ exports.defaultMessage = defaultMessage;
176
+ const createBundle = /*#__PURE__*/function () {
177
+ var _ref3 = _asyncToGenerator(function* ({
178
+ message,
179
+ ssr_parameters,
180
+ ssr_only,
181
+ ssr_shared,
182
+ buildDirectory,
183
+ projectSlug
184
+ }) {
185
+ message = message || defaultMessage();
186
+ const tmpDir = yield (0, _promises.mkdtemp)(_path.default.join(_os.default.tmpdir(), 'pwa-kit-dev-'));
187
+ const destination = _path.default.join(tmpDir, 'build.tar');
188
+ const filesInArchive = [];
189
+ if (ssr_only.length === 0 || ssr_shared.length === 0) {
190
+ throw new Error('no ssrOnly or ssrShared files are defined');
191
+ }
192
+ return Promise.resolve().then(() => (0, _promises.stat)(buildDirectory)).catch(() => {
193
+ const fullPath = _path.default.join(process.cwd(), buildDirectory);
194
+ throw new Error(`Build directory at path "${fullPath}" not found.\n` + 'Run `pwa-kit-dev build` first!');
195
+ }).then(() => new Promise((resolve, reject) => {
196
+ const output = (0, _fs.createWriteStream)(destination);
197
+ const archive = (0, _archiver.default)('tar');
198
+ archive.pipe(output);
199
+
200
+ // See https://web.archive.org/web/20160712064705/http://archiverjs.com/docs/global.html#TarEntryData
201
+ const newRoot = _path.default.join(projectSlug, 'bld', '');
202
+ // WARNING: There are a lot of type assertions here because we use a very old
203
+ // version of archiver, and the types provided don't match the docs. :\
204
+ archive.directory(buildDirectory, '', entry => {
205
+ const stats = entry.stats;
206
+ if (stats !== null && stats !== void 0 && stats.isFile() && entry.name) {
207
+ filesInArchive.push(entry.name);
208
+ }
209
+ entry.prefix = newRoot;
210
+ return entry;
211
+ });
212
+ archive.on('error', reject);
213
+ output.on('finish', resolve);
214
+ archive.finalize();
215
+ })).then(() => (0, _promises.readFile)(destination)).then(data => {
216
+ const encoding = 'base64';
217
+ return {
218
+ message,
219
+ encoding,
220
+ data: data.toString(encoding),
221
+ ssr_parameters,
222
+ ssr_only: filesInArchive.filter(glob(ssr_only)),
223
+ ssr_shared: filesInArchive.filter(glob(ssr_shared))
224
+ };
225
+ })
226
+ // This is a false positive. The promise returned by `.finally()` won't resolve until
227
+ // the `rm()` completes!
228
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
229
+ .finally(() => (0, _promises.rm)(tmpDir, {
230
+ recursive: true
231
+ }));
232
+ });
233
+ return function createBundle(_x) {
234
+ return _ref3.apply(this, arguments);
235
+ };
236
+ }();
237
+ exports.createBundle = createBundle;
238
+ const glob = patterns => {
239
+ // The patterns can include negations, so matching is done against all
240
+ // the patterns. A match is true if a given path matches any pattern and
241
+ // does not match any negating patterns.
242
+
243
+ const allPatterns = (patterns || []).map(pattern => new _minimatch.Minimatch(pattern, {
244
+ nocomment: true
245
+ })).filter(pattern => !pattern.empty);
246
+ const positivePatterns = allPatterns.filter(pattern => !pattern.negate);
247
+ const negativePatterns = allPatterns.filter(pattern => pattern.negate);
248
+ return path => {
249
+ if (path) {
250
+ const positive = positivePatterns.some(pattern => pattern.match(path));
251
+ const negative = negativePatterns.some(pattern => !pattern.match(path));
252
+ return positive && !negative;
253
+ }
254
+ return false;
255
+ };
256
+ };
257
+ exports.glob = glob;
258
+ const getCredentialsFile = (cloudOrigin, credentialsFile) => {
259
+ if (credentialsFile) {
260
+ return credentialsFile;
261
+ } else {
262
+ const url = new _url.URL(cloudOrigin);
263
+ const host = url.host;
264
+ const suffix = host === 'cloud.mobify.com' ? '' : `--${host}`;
265
+ return _path.default.join(_os.default.homedir(), `.mobify${suffix}`);
266
+ }
267
+ };
268
+ exports.getCredentialsFile = getCredentialsFile;
269
+ const readCredentials = /*#__PURE__*/function () {
270
+ var _ref4 = _asyncToGenerator(function* (filepath) {
271
+ try {
272
+ const data = yield (0, _fsExtra.readJson)(filepath);
273
+ return {
274
+ username: data.username,
275
+ api_key: data.api_key
276
+ };
277
+ } catch (e) {
278
+ throw new Error(`Credentials file "${filepath}" not found.\n` + 'Visit https://runtime.commercecloud.com/account/settings for ' + 'steps on authorizing your computer to push bundles.');
279
+ }
280
+ });
281
+ return function readCredentials(_x2) {
282
+ return _ref4.apply(this, arguments);
283
+ };
284
+ }();
285
+ exports.readCredentials = readCredentials;
286
+ const parseLog = log => {
287
+ const parts = log.trim().split('\t');
288
+ let requestId, shortRequestId, level;
289
+ if (parts.length >= 3 && _validator.default.isISO8601(parts[0]) && _validator.default.isUUID(parts[1]) && _validator.default.isAlpha(parts[2])) {
290
+ // An application log
291
+ parts.shift();
292
+ requestId = parts.shift();
293
+ level = parts.shift();
294
+ } else {
295
+ // A platform log
296
+ const words = parts[0].split(' ');
297
+ level = words.shift();
298
+ parts[0] = words.join(' ');
299
+ }
300
+ const message = parts.join('\t');
301
+ const match = /(?<id>[a-f\d]{8})/.exec(requestId || message);
302
+ if (match) {
303
+ var _match$groups;
304
+ shortRequestId = (_match$groups = match.groups) === null || _match$groups === void 0 ? void 0 : _match$groups.id;
305
+ }
306
+ return {
307
+ level,
308
+ message,
309
+ shortRequestId
310
+ };
311
+ };
312
+ exports.parseLog = parseLog;