@salesforce/pwa-kit-react-sdk 3.8.0-preview.0-basepath → 3.8.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 (52) hide show
  1. package/CHANGELOG.md +3 -7
  2. package/package.json +6 -5
  3. package/ssr/browser/main.js +130 -0
  4. package/ssr/browser/main.test.js +54 -0
  5. package/ssr/server/react-rendering.js +434 -0
  6. package/ssr/server/react-rendering.test.js +745 -0
  7. package/ssr/universal/compatibility.js +31 -0
  8. package/ssr/universal/components/_app/index.js +35 -0
  9. package/ssr/universal/components/_app/index.test.js +20 -0
  10. package/ssr/universal/components/_app-config/index.js +87 -0
  11. package/ssr/universal/components/_app-config/index.test.js +21 -0
  12. package/ssr/universal/components/_document/index.js +92 -0
  13. package/ssr/universal/components/_document/index.test.js +58 -0
  14. package/ssr/universal/components/_error/index.js +55 -0
  15. package/ssr/universal/components/_error/index.test.js +28 -0
  16. package/ssr/universal/components/app-error-boundary/index.js +113 -0
  17. package/ssr/universal/components/app-error-boundary/index.test.js +109 -0
  18. package/ssr/universal/components/fetch-strategy/index.js +42 -0
  19. package/ssr/universal/components/refresh/index.js +123 -0
  20. package/ssr/universal/components/refresh/index.test.js +78 -0
  21. package/ssr/universal/components/route-component/index.js +415 -0
  22. package/ssr/universal/components/route-component/index.test.js +378 -0
  23. package/ssr/universal/components/switch/index.js +62 -0
  24. package/ssr/universal/components/throw-404/index.js +36 -0
  25. package/ssr/universal/components/throw-404/index.test.js +26 -0
  26. package/ssr/universal/components/with-correlation-id/index.js +36 -0
  27. package/ssr/universal/components/with-legacy-get-props/index.js +100 -0
  28. package/ssr/universal/components/with-legacy-get-props/index.test.js +35 -0
  29. package/ssr/universal/components/with-react-query/index.js +130 -0
  30. package/ssr/universal/components/with-react-query/index.test.js +101 -0
  31. package/ssr/universal/contexts/index.js +72 -0
  32. package/ssr/universal/contexts/index.test.js +101 -0
  33. package/ssr/universal/errors.js +34 -0
  34. package/ssr/universal/errors.test.js +20 -0
  35. package/ssr/universal/events.js +38 -0
  36. package/ssr/universal/events.test.js +39 -0
  37. package/ssr/universal/hooks/index.js +84 -0
  38. package/ssr/universal/routes.js +15 -0
  39. package/ssr/universal/utils.client.test.js +46 -0
  40. package/ssr/universal/utils.js +61 -0
  41. package/ssr/universal/utils.server.test.js +24 -0
  42. package/utils/assets.js +120 -0
  43. package/utils/assets.test.js +106 -0
  44. package/utils/logger-instance.js +19 -0
  45. package/utils/performance.js +126 -0
  46. package/utils/performance.test.js +50 -0
  47. package/utils/url.js +41 -0
  48. package/utils/url.test.js +47 -0
  49. package/utils/uuidv4.client.js +21 -0
  50. package/utils/uuidv4.client.test.js +27 -0
  51. package/utils/warnings.js +81 -0
  52. package/utils/warnings.test.js +48 -0
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ var _uuidv = require("./uuidv4.client");
4
+ /*
5
+ * Copyright (c) 2022, salesforce.com, inc.
6
+ * All rights reserved.
7
+ * SPDX-License-Identifier: BSD-3-Clause
8
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
+ */
10
+
11
+ let originalCrypto;
12
+ describe('uuidv4', () => {
13
+ beforeEach(() => {
14
+ originalCrypto = global.crypto;
15
+ });
16
+ afterEach(() => {
17
+ global.crypto = originalCrypto;
18
+ });
19
+ test('returns correct format', () => {
20
+ global.crypto = {
21
+ // we mock the module because crypto.getRandomValues
22
+ // is not available on node v14 (came out in node v15)
23
+ getRandomValues: () => [123]
24
+ };
25
+ expect((0, _uuidv.uuidv4)()).toBe('abbbbbbb-abbb-4bbb-bbbb-abbbbbbbbbbb');
26
+ });
27
+ });
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.experimental = exports.deprecated = void 0;
7
+ /*
8
+ * Copyright (c) 2021, salesforce.com, inc.
9
+ * All rights reserved.
10
+ * SPDX-License-Identifier: BSD-3-Clause
11
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
12
+ */
13
+ /**
14
+ * @module progressive-web-sdk/utils/warnings
15
+ * @private
16
+ */
17
+
18
+ let displayed = {};
19
+
20
+ /**
21
+ *
22
+ * Prints a warning to the console that a deprecated function is being used.
23
+ * This allows you to say when the function will be removed and what alternate
24
+ * function should be used. Example: "This function will be removed in version
25
+ * 1.2.3. Please use alternateFunction() instead."
26
+ *
27
+ * @function
28
+ * @param {String} message A message to follow the initial deprecation warning
29
+ */
30
+ const deprecated = message => {
31
+ warn('deprecated', message);
32
+ };
33
+
34
+ /**
35
+ * Prints a warning to the console that an experimental function is being used.
36
+ *
37
+ * @function
38
+ * @param {String} message A message to follow the initial experimental warning
39
+ */
40
+ exports.deprecated = deprecated;
41
+ const experimental = message => {
42
+ warn('experimental', message);
43
+ };
44
+
45
+ /**
46
+ * Displays a warning once per hard navigation.
47
+ * Does not display a warning when in production mode.
48
+ * @private
49
+ */
50
+ exports.experimental = experimental;
51
+ const shouldDisplay = name => {
52
+ if (process.env.NODE_ENV === 'production' || displayed[name]) {
53
+ return false;
54
+ } else {
55
+ displayed[name] = true;
56
+ return true;
57
+ }
58
+ };
59
+
60
+ /**
61
+ * Logs a warning to the console
62
+ * @param type Warning type
63
+ * @param message A message to follow the initial warning
64
+ */
65
+ const warn = (type, message) => {
66
+ let functionName = '';
67
+
68
+ // Get caller name by reading an Error stack trace instead of getting
69
+ // function property `caller` because it is not allowed in `strict` mode.
70
+ try {
71
+ throw new Error();
72
+ } catch (e) {
73
+ functionName = e.stack.split('\n')[3].split(' ')[5];
74
+ }
75
+ const messages = {
76
+ experimental: `You are currently using an experimental function: [${functionName}] This function may change at any time.`,
77
+ deprecated: `You are currently using an deprecated function: [${functionName}].`
78
+ };
79
+ if (!shouldDisplay(functionName)) return;
80
+ console.warn(`[PWA Kit API WARNING]: ${messages[type]} ${message ? message : ''}`);
81
+ };
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ var _warnings = require("./warnings");
4
+ /*
5
+ * Copyright (c) 2021, salesforce.com, inc.
6
+ * All rights reserved.
7
+ * SPDX-License-Identifier: BSD-3-Clause
8
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
+ */
10
+
11
+ describe('warnings', () => {
12
+ let original;
13
+ beforeEach(() => {
14
+ original = console.warn;
15
+ console.warn = jest.fn();
16
+ });
17
+ afterEach(() => {
18
+ console.warn = original;
19
+ });
20
+ test('deprecated', () => {
21
+ const testFunction1 = () => {
22
+ (0, _warnings.deprecated)('msg');
23
+ };
24
+ testFunction1();
25
+ expect(console.warn.mock.calls[0][0]).toBe(`[PWA Kit API WARNING]: You are currently using an deprecated function: [testFunction1]. msg`);
26
+ testFunction1();
27
+ expect(console.warn).toHaveBeenCalledTimes(1);
28
+ const testFunction2 = () => {
29
+ (0, _warnings.deprecated)();
30
+ };
31
+ testFunction2();
32
+ expect(console.warn.mock.calls[1][0]).toBe(`[PWA Kit API WARNING]: You are currently using an deprecated function: [testFunction2]. `);
33
+ });
34
+ test('experimental', () => {
35
+ const testFunction3 = () => {
36
+ (0, _warnings.experimental)('msg');
37
+ };
38
+ testFunction3();
39
+ expect(console.warn.mock.calls[0][0]).toBe(`[PWA Kit API WARNING]: You are currently using an experimental function: [testFunction3] This function may change at any time. msg`);
40
+ testFunction3();
41
+ expect(console.warn).toHaveBeenCalledTimes(1);
42
+ const testFunction4 = () => {
43
+ (0, _warnings.experimental)();
44
+ };
45
+ testFunction4();
46
+ expect(console.warn.mock.calls[1][0]).toBe(`[PWA Kit API WARNING]: You are currently using an experimental function: [testFunction4] This function may change at any time. `);
47
+ });
48
+ });