@bleedingdev/modern-js-runtime-extensions 3.9.0-ultramodern.4 → 3.9.0-ultramodern.5

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 (155) hide show
  1. package/dist/cjs/contextExtensions.js +74 -0
  2. package/dist/cjs/headRuntime.js +91 -0
  3. package/dist/cjs/helmetContext.js +54 -0
  4. package/dist/cjs/index.js +18 -4
  5. package/dist/cjs/prefetchPolicy.js +52 -0
  6. package/dist/cjs/request-policy/browser.js +139 -0
  7. package/dist/cjs/request-policy/client.js +234 -0
  8. package/dist/cjs/request-policy/node.js +149 -0
  9. package/dist/cjs/request-policy/policyCore.js +266 -0
  10. package/dist/cjs/request-policy/requestContext.js +137 -0
  11. package/dist/cjs/request-policy/traceparent.js +56 -0
  12. package/dist/cjs/request-policy/transport.js +234 -0
  13. package/dist/cjs/request-policy/types.js +57 -0
  14. package/dist/cjs/routeHydration.js +127 -0
  15. package/dist/cjs/routerPrefetchPolicy.js +153 -0
  16. package/dist/cjs/routerProvider.js +170 -0
  17. package/dist/cjs/routerState.js +167 -0
  18. package/dist/cjs/routerStatePlugin.js +86 -0
  19. package/dist/cjs/routerStateTypes.js +18 -0
  20. package/dist/cjs/runtimeContextProjection.js +112 -0
  21. package/dist/cjs/server-config/bffRuntime.js +18 -0
  22. package/dist/cjs/server-config/index.js +18 -0
  23. package/dist/cjs/server-config/serverTelemetry.js +18 -0
  24. package/dist/cjs/shellStream.js +34 -2
  25. package/dist/cjs/workspaceEvents.js +159 -0
  26. package/dist/esm/contextExtensions.mjs +33 -0
  27. package/dist/esm/headRuntime.mjs +43 -0
  28. package/dist/esm/helmetContext.mjs +13 -0
  29. package/dist/esm/index.mjs +2 -0
  30. package/dist/esm/prefetchPolicy.mjs +11 -0
  31. package/dist/esm/request-policy/browser.mjs +11 -0
  32. package/dist/esm/request-policy/client.mjs +195 -0
  33. package/dist/esm/request-policy/policyCore.mjs +171 -0
  34. package/dist/esm/request-policy/requestContext.mjs +75 -0
  35. package/dist/esm/request-policy/traceparent.mjs +18 -0
  36. package/dist/esm/request-policy/transport.mjs +196 -0
  37. package/dist/esm/request-policy/types.mjs +10 -0
  38. package/dist/esm/routeHydration.mjs +77 -0
  39. package/dist/esm/routerPrefetchPolicy.mjs +115 -0
  40. package/dist/esm/routerProvider.mjs +117 -0
  41. package/dist/esm/routerState.mjs +105 -0
  42. package/dist/esm/routerStatePlugin.mjs +48 -0
  43. package/dist/esm/routerStateTypes.mjs +0 -0
  44. package/dist/esm/runtimeContextProjection.mjs +74 -0
  45. package/dist/esm/server-config/bffRuntime.mjs +0 -0
  46. package/dist/esm/server-config/index.mjs +0 -0
  47. package/dist/esm/server-config/serverTelemetry.mjs +0 -0
  48. package/dist/esm/shellStream.mjs +34 -2
  49. package/dist/esm/workspaceEvents.mjs +66 -0
  50. package/dist/esm-node/contextExtensions.mjs +34 -0
  51. package/dist/esm-node/headRuntime.mjs +44 -0
  52. package/dist/esm-node/helmetContext.mjs +14 -0
  53. package/dist/esm-node/index.mjs +2 -0
  54. package/dist/esm-node/prefetchPolicy.mjs +12 -0
  55. package/dist/esm-node/request-policy/browser.mjs +12 -0
  56. package/dist/esm-node/request-policy/client.mjs +196 -0
  57. package/dist/esm-node/request-policy/node.mjs +22 -0
  58. package/dist/esm-node/request-policy/policyCore.mjs +172 -0
  59. package/dist/esm-node/request-policy/requestContext.mjs +76 -0
  60. package/dist/esm-node/request-policy/traceparent.mjs +19 -0
  61. package/dist/esm-node/request-policy/transport.mjs +197 -0
  62. package/dist/esm-node/request-policy/types.mjs +11 -0
  63. package/dist/esm-node/routeHydration.mjs +78 -0
  64. package/dist/esm-node/routerPrefetchPolicy.mjs +116 -0
  65. package/dist/esm-node/routerProvider.mjs +118 -0
  66. package/dist/esm-node/routerState.mjs +106 -0
  67. package/dist/esm-node/routerStatePlugin.mjs +49 -0
  68. package/dist/esm-node/routerStateTypes.mjs +1 -0
  69. package/dist/esm-node/runtimeContextProjection.mjs +75 -0
  70. package/dist/esm-node/server-config/bffRuntime.mjs +1 -0
  71. package/dist/esm-node/server-config/index.mjs +1 -0
  72. package/dist/esm-node/server-config/serverTelemetry.mjs +1 -0
  73. package/dist/esm-node/shellStream.mjs +34 -2
  74. package/dist/esm-node/workspaceEvents.mjs +67 -0
  75. package/dist/types/contextExtensions.d.ts +34 -0
  76. package/dist/types/headRuntime.d.ts +12 -0
  77. package/dist/types/helmetContext.d.ts +10 -0
  78. package/dist/types/index.d.ts +2 -0
  79. package/dist/types/prefetchPolicy.d.ts +4 -0
  80. package/dist/types/request-policy/browser.d.ts +10 -0
  81. package/dist/types/request-policy/client.d.ts +14 -0
  82. package/dist/types/request-policy/node.d.ts +10 -0
  83. package/dist/types/request-policy/policyCore.d.ts +107 -0
  84. package/dist/types/request-policy/requestContext.d.ts +22 -0
  85. package/dist/types/request-policy/traceparent.d.ts +10 -0
  86. package/dist/types/request-policy/transport.d.ts +12 -0
  87. package/dist/types/request-policy/types.d.ts +144 -0
  88. package/dist/types/routeHydration.d.ts +24 -0
  89. package/dist/types/routerPrefetchPolicy.d.ts +28 -0
  90. package/dist/types/routerProvider.d.ts +77 -0
  91. package/dist/types/routerState.d.ts +12 -0
  92. package/dist/types/routerStatePlugin.d.ts +19 -0
  93. package/dist/types/routerStateTypes.d.ts +40 -0
  94. package/dist/types/runtimeContextProjection.d.ts +30 -0
  95. package/dist/types/server-config/bffRuntime.d.ts +122 -0
  96. package/dist/types/server-config/index.d.ts +2 -0
  97. package/dist/types/server-config/serverTelemetry.d.ts +322 -0
  98. package/dist/types/workspaceEvents.d.ts +62 -0
  99. package/package.json +198 -13
  100. package/rslib.config.mts +17 -2
  101. package/rstest.config.mts +33 -2
  102. package/src/contextExtensions.ts +81 -0
  103. package/src/headRuntime.tsx +77 -0
  104. package/src/helmetContext.ts +31 -0
  105. package/src/index.ts +2 -0
  106. package/src/prefetchPolicy.ts +33 -0
  107. package/src/request-policy/browser.ts +22 -0
  108. package/src/request-policy/client.ts +404 -0
  109. package/src/request-policy/node.ts +41 -0
  110. package/src/request-policy/policyCore.ts +424 -0
  111. package/src/request-policy/requestContext.ts +149 -0
  112. package/src/request-policy/traceparent.ts +43 -0
  113. package/src/request-policy/transport.ts +349 -0
  114. package/src/request-policy/types.ts +229 -0
  115. package/src/routeHydration.ts +208 -0
  116. package/src/routerPrefetchPolicy.ts +195 -0
  117. package/src/routerProvider.ts +340 -0
  118. package/src/routerState.ts +208 -0
  119. package/src/routerStatePlugin.ts +86 -0
  120. package/src/routerStateTypes.ts +46 -0
  121. package/src/runtimeContextProjection.ts +105 -0
  122. package/src/server-config/bffRuntime.ts +136 -0
  123. package/src/server-config/index.ts +2 -0
  124. package/src/server-config/serverTelemetry.ts +337 -0
  125. package/src/shellStream.ts +55 -25
  126. package/src/workspaceEvents.ts +324 -0
  127. package/tests/buildIdentity.test.ts +2 -4
  128. package/tests/contextExtensions.test.ts +71 -0
  129. package/tests/headRuntime.test.tsx +369 -0
  130. package/tests/nativeSafeFailureCompatibility.test.ts +117 -0
  131. package/tests/prefetchPolicy.test.ts +51 -0
  132. package/tests/rendererHead.test.ts +1 -72
  133. package/tests/request-policy/browser-policy.test.ts +608 -0
  134. package/tests/request-policy/client-isolation.test.ts +149 -0
  135. package/tests/request-policy/identityBinding.test.ts +75 -0
  136. package/tests/request-policy/node-policy.test.ts +741 -0
  137. package/tests/request-policy/policyCore.test.ts +250 -0
  138. package/tests/request-policy/requestContext.test.ts +80 -0
  139. package/tests/request-policy/requestFactory.outbound-contract.test.ts +691 -0
  140. package/tests/request-policy/traceparent.test.ts +55 -0
  141. package/tests/request-policy/transport-retry.test.ts +370 -0
  142. package/tests/routeHydration.test.ts +180 -0
  143. package/tests/routerPrefetchPolicy.test.ts +102 -0
  144. package/tests/routerProvider.test.ts +38 -0
  145. package/tests/routerState.test.ts +157 -0
  146. package/tests/routerStatePlugin.test.ts +108 -0
  147. package/tests/runtimeContextProjection.test.ts +135 -0
  148. package/tests/shellStream.test.ts +37 -0
  149. package/tests/workspaceEvents.test.ts +391 -0
  150. package/dist/cjs/rscHtmlStream.js +0 -128
  151. package/dist/esm/rscHtmlStream.mjs +0 -86
  152. package/dist/esm-node/rscHtmlStream.mjs +0 -87
  153. package/dist/types/rscHtmlStream.d.ts +0 -4
  154. package/src/rscHtmlStream.ts +0 -142
  155. package/tests/rscHtmlStream.test.ts +0 -153
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ BFF_DEFAULT_PROTECTED_IDENTITY_HEADERS: ()=>external_types_js_namespaceObject.BFF_DEFAULT_PROTECTED_IDENTITY_HEADERS,
32
+ BFF_ENVELOPE_HEADER: ()=>external_types_js_namespaceObject.BFF_ENVELOPE_HEADER,
33
+ BFF_LOCALE_HEADER: ()=>BFF_LOCALE_HEADER,
34
+ BFF_OPERATION_CONTEXT_DETAIL_HEADER: ()=>external_types_js_namespaceObject.BFF_OPERATION_CONTEXT_DETAIL_HEADER,
35
+ BFF_OPERATION_CONTEXT_HEADER: ()=>external_types_js_namespaceObject.BFF_OPERATION_CONTEXT_HEADER,
36
+ BFF_TRACEPARENT_HEADER: ()=>BFF_TRACEPARENT_HEADER,
37
+ createRequestContextHeaders: ()=>createRequestContextHeaders,
38
+ createRequestContextSnapshot: ()=>createRequestContextSnapshot,
39
+ parseTraceparent: ()=>external_traceparent_js_namespaceObject.parseTraceparent
40
+ });
41
+ const external_traceparent_js_namespaceObject = require("./traceparent.js");
42
+ const external_types_js_namespaceObject = require("./types.js");
43
+ const BFF_LOCALE_HEADER = 'accept-language';
44
+ const BFF_TRACEPARENT_HEADER = 'traceparent';
45
+ const readHeader = (headers, header)=>{
46
+ if (!headers) return;
47
+ const normalized = header.toLowerCase();
48
+ const key = Object.keys(headers).find((current)=>current.toLowerCase() === normalized);
49
+ if (!key) return;
50
+ const value = headers[key];
51
+ return Array.isArray(value) ? value[0] : value;
52
+ };
53
+ const readString = (value)=>'string' == typeof value && value.length > 0 ? value : void 0;
54
+ function createOperationContextSnapshot(operationContext, safeContext) {
55
+ if (!operationContext) return;
56
+ const snapshot = {
57
+ ...operationContext,
58
+ ...safeContext.locale || operationContext?.locale ? {
59
+ locale: safeContext.locale || operationContext?.locale
60
+ } : {},
61
+ ...safeContext.traceparent || operationContext?.traceparent ? {
62
+ traceparent: safeContext.traceparent || operationContext?.traceparent
63
+ } : {},
64
+ ...safeContext.traceId || operationContext?.traceId ? {
65
+ traceId: safeContext.traceId || operationContext?.traceId
66
+ } : {},
67
+ ...safeContext.spanId || operationContext?.spanId ? {
68
+ spanId: safeContext.spanId || operationContext?.spanId
69
+ } : {}
70
+ };
71
+ return Object.keys(snapshot).some((key)=>void 0 !== snapshot[key]) ? snapshot : void 0;
72
+ }
73
+ function createRequestContextSnapshot(input = {}) {
74
+ const locale = readString(input.locale) || readString(readHeader(input.headers, BFF_LOCALE_HEADER));
75
+ const traceparent = readString(input.traceparent) || readString(input.operationContext?.traceparent) || readString(readHeader(input.headers, BFF_TRACEPARENT_HEADER));
76
+ const parsedTraceparent = input.operationContext?.traceId && input.operationContext?.spanId ? {
77
+ traceId: input.operationContext.traceId,
78
+ spanId: input.operationContext.spanId
79
+ } : (0, external_traceparent_js_namespaceObject.parseTraceparent)(traceparent);
80
+ const headers = {};
81
+ if (locale) headers[BFF_LOCALE_HEADER] = locale;
82
+ if (traceparent) headers[BFF_TRACEPARENT_HEADER] = traceparent;
83
+ const operationContext = createOperationContextSnapshot(input.operationContext, {
84
+ ...locale ? {
85
+ locale
86
+ } : {},
87
+ ...traceparent ? {
88
+ traceparent
89
+ } : {},
90
+ ...parsedTraceparent ? {
91
+ traceId: parsedTraceparent.traceId,
92
+ spanId: parsedTraceparent.spanId
93
+ } : {}
94
+ });
95
+ return {
96
+ headers,
97
+ ...locale ? {
98
+ locale
99
+ } : {},
100
+ ...traceparent ? {
101
+ traceparent
102
+ } : {},
103
+ ...parsedTraceparent ? {
104
+ traceId: parsedTraceparent.traceId,
105
+ spanId: parsedTraceparent.spanId
106
+ } : {},
107
+ ...operationContext ? {
108
+ operationContext
109
+ } : {}
110
+ };
111
+ }
112
+ function createRequestContextHeaders(input = {}) {
113
+ return createRequestContextSnapshot(input).headers;
114
+ }
115
+ exports.BFF_DEFAULT_PROTECTED_IDENTITY_HEADERS = __webpack_exports__.BFF_DEFAULT_PROTECTED_IDENTITY_HEADERS;
116
+ exports.BFF_ENVELOPE_HEADER = __webpack_exports__.BFF_ENVELOPE_HEADER;
117
+ exports.BFF_LOCALE_HEADER = __webpack_exports__.BFF_LOCALE_HEADER;
118
+ exports.BFF_OPERATION_CONTEXT_DETAIL_HEADER = __webpack_exports__.BFF_OPERATION_CONTEXT_DETAIL_HEADER;
119
+ exports.BFF_OPERATION_CONTEXT_HEADER = __webpack_exports__.BFF_OPERATION_CONTEXT_HEADER;
120
+ exports.BFF_TRACEPARENT_HEADER = __webpack_exports__.BFF_TRACEPARENT_HEADER;
121
+ exports.createRequestContextHeaders = __webpack_exports__.createRequestContextHeaders;
122
+ exports.createRequestContextSnapshot = __webpack_exports__.createRequestContextSnapshot;
123
+ exports.parseTraceparent = __webpack_exports__.parseTraceparent;
124
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
125
+ "BFF_DEFAULT_PROTECTED_IDENTITY_HEADERS",
126
+ "BFF_ENVELOPE_HEADER",
127
+ "BFF_LOCALE_HEADER",
128
+ "BFF_OPERATION_CONTEXT_DETAIL_HEADER",
129
+ "BFF_OPERATION_CONTEXT_HEADER",
130
+ "BFF_TRACEPARENT_HEADER",
131
+ "createRequestContextHeaders",
132
+ "createRequestContextSnapshot",
133
+ "parseTraceparent"
134
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
135
+ Object.defineProperty(exports, '__esModule', {
136
+ value: true
137
+ });
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ const TRACEPARENT_REGEX = /^00-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/i;
31
+ const isAllZeroHex = (value)=>/^0+$/.test(value);
32
+ function parseTraceparent(traceparent) {
33
+ if (!traceparent) return;
34
+ const match = traceparent.trim().match(TRACEPARENT_REGEX);
35
+ if (!match) return;
36
+ const [, rawTraceId, rawSpanId, rawFlags] = match;
37
+ if (!rawTraceId || !rawSpanId || !rawFlags) return;
38
+ const traceId = rawTraceId.toLowerCase();
39
+ const spanId = rawSpanId.toLowerCase();
40
+ if (isAllZeroHex(traceId) || isAllZeroHex(spanId)) return;
41
+ return {
42
+ traceId,
43
+ spanId,
44
+ sampled: (0x1 & Number.parseInt(rawFlags, 16)) === 1
45
+ };
46
+ }
47
+ __webpack_require__.d(__webpack_exports__, {
48
+ parseTraceparent: ()=>parseTraceparent
49
+ });
50
+ exports.parseTraceparent = __webpack_exports__.parseTraceparent;
51
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
52
+ "parseTraceparent"
53
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
54
+ Object.defineProperty(exports, '__esModule', {
55
+ value: true
56
+ });
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ const DEFAULT_RETRYABLE_STATUS_CODES = [
31
+ 408,
32
+ 425,
33
+ 429,
34
+ 500,
35
+ 502,
36
+ 503,
37
+ 504
38
+ ];
39
+ const DEFAULT_BASE_DELAY_MS = 100;
40
+ const DEFAULT_MAX_DELAY_MS = 1000;
41
+ const DEFAULT_JITTER_RATIO = 0.1;
42
+ const DEFAULT_RETRYABLE_METHODS = new Set([
43
+ 'DELETE',
44
+ 'GET',
45
+ 'HEAD',
46
+ 'OPTIONS',
47
+ 'PUT',
48
+ 'TRACE'
49
+ ]);
50
+ const createTimeoutError = (timeoutMs)=>{
51
+ const error = new Error(`Request timed out after ${timeoutMs}ms`);
52
+ error.name = 'TimeoutError';
53
+ return error;
54
+ };
55
+ const unrefTimer = (timer)=>{
56
+ if ('object' == typeof timer && null !== timer && 'unref' in timer && 'function' == typeof timer.unref) timer.unref();
57
+ };
58
+ const wait = (ms)=>new Promise((resolve)=>{
59
+ const timer = setTimeout(()=>resolve(), ms);
60
+ unrefTimer(timer);
61
+ });
62
+ const toStatusCode = (error)=>{
63
+ if (!error || 'object' != typeof error) return;
64
+ const status = error.status;
65
+ if ('number' == typeof status) return status;
66
+ const responseStatus = error.response?.status;
67
+ if ('number' == typeof responseStatus) return responseStatus;
68
+ };
69
+ const isRetryableNetworkError = (error)=>{
70
+ if (!error || 'object' != typeof error) return false;
71
+ const name = error.name;
72
+ if ('FetchError' === name || 'TimeoutError' === name || 'TypeError' === name) return true;
73
+ const code = error.code;
74
+ return 'ECONNRESET' === code || 'ETIMEDOUT' === code || 'ECONNREFUSED' === code || 'EPIPE' === code;
75
+ };
76
+ const normalizePositiveNumber = (value, fallback)=>'number' == typeof value && Number.isFinite(value) && value > 0 ? value : fallback;
77
+ const normalizeNonNegativeInt = (value, fallback)=>'number' == typeof value && Number.isFinite(value) && value >= 0 ? Math.floor(value) : fallback;
78
+ const normalizeJitterRatio = (value)=>{
79
+ if ('number' != typeof value || !Number.isFinite(value)) return DEFAULT_JITTER_RATIO;
80
+ return Math.max(0, Math.min(1, value));
81
+ };
82
+ const shouldRetryWithDefaults = (method, statusCode, error, retryableStatusCodes)=>{
83
+ if (!DEFAULT_RETRYABLE_METHODS.has(method.toUpperCase())) return false;
84
+ if ('number' == typeof statusCode) return retryableStatusCodes.includes(statusCode);
85
+ return isRetryableNetworkError(error);
86
+ };
87
+ const shouldRetry = (retryOptions, context, retryableStatusCodes)=>{
88
+ if ('function' == typeof retryOptions?.shouldRetry) try {
89
+ return retryOptions.shouldRetry(context);
90
+ } catch (error) {
91
+ return false;
92
+ }
93
+ return shouldRetryWithDefaults(context.method, context.statusCode, context.error, retryableStatusCodes);
94
+ };
95
+ const getBackoffMs = (retryOptions, attempt)=>{
96
+ const baseDelayMs = normalizePositiveNumber(retryOptions?.baseDelayMs, DEFAULT_BASE_DELAY_MS);
97
+ const maxDelayMs = normalizePositiveNumber(retryOptions?.maxDelayMs, DEFAULT_MAX_DELAY_MS);
98
+ const jitterRatio = normalizeJitterRatio(retryOptions?.jitterRatio);
99
+ const exponentialDelay = Math.min(maxDelayMs, baseDelayMs * 2 ** Math.max(0, attempt - 1));
100
+ const jitterFactor = 0 === jitterRatio ? 1 : 1 + (2 * Math.random() - 1) * jitterRatio;
101
+ return Math.max(0, Math.floor(exponentialDelay * jitterFactor));
102
+ };
103
+ const emitDegradedEvent = (transport, event)=>{
104
+ if ('function' != typeof transport?.onDegraded) return;
105
+ try {
106
+ transport.onDegraded(event);
107
+ } catch (error) {}
108
+ };
109
+ const withTimeout = async (promise, timeoutMs, signalBuilder)=>{
110
+ if (!timeoutMs || timeoutMs <= 0) {
111
+ const result = await promise;
112
+ return {
113
+ result
114
+ };
115
+ }
116
+ const controller = signalBuilder?.();
117
+ let timeoutTriggered = false;
118
+ let rejectTimeout;
119
+ const timeoutPromise = new Promise((_, reject)=>{
120
+ rejectTimeout = reject;
121
+ });
122
+ const timer = setTimeout(()=>{
123
+ timeoutTriggered = true;
124
+ if (controller) controller.abort();
125
+ rejectTimeout?.(createTimeoutError(timeoutMs));
126
+ }, timeoutMs);
127
+ unrefTimer(timer);
128
+ try {
129
+ const result = await Promise.race([
130
+ promise,
131
+ timeoutPromise
132
+ ]);
133
+ return {
134
+ result,
135
+ timeoutTriggered
136
+ };
137
+ } catch (error) {
138
+ if (timeoutTriggered && error?.name === 'AbortError') throw createTimeoutError(timeoutMs);
139
+ throw error;
140
+ } finally{
141
+ clearTimeout(timer);
142
+ }
143
+ };
144
+ const executeWithResilience = async ({ requestId, target, method, url, init, fetcher, transport })=>{
145
+ const retries = normalizeNonNegativeInt(transport?.retry?.retries, 0);
146
+ const timeoutMs = 'number' == typeof transport?.timeoutMs && transport.timeoutMs > 0 ? transport.timeoutMs : void 0;
147
+ const maxAttempts = retries + 1;
148
+ const retryableStatusCodes = transport?.retry?.retryableStatusCodes && transport.retry.retryableStatusCodes.length > 0 ? transport.retry.retryableStatusCodes : DEFAULT_RETRYABLE_STATUS_CODES;
149
+ let attempt = 0;
150
+ while(attempt < maxAttempts){
151
+ attempt += 1;
152
+ const canUseAbortController = "u" > typeof AbortController;
153
+ let controller;
154
+ if (timeoutMs && canUseAbortController) controller = new AbortController();
155
+ const callerSignal = init.signal;
156
+ const requestSignal = controller ? callerSignal && !callerSignal.aborted ? AbortSignal.any([
157
+ callerSignal,
158
+ controller.signal
159
+ ]) : callerSignal || controller.signal : callerSignal;
160
+ const nextInit = requestSignal ? {
161
+ ...init,
162
+ signal: requestSignal
163
+ } : init;
164
+ try {
165
+ const { result } = await withTimeout(fetcher(url, nextInit), timeoutMs, ()=>controller);
166
+ return result;
167
+ } catch (error) {
168
+ const statusCode = toStatusCode(error);
169
+ const decisionContext = {
170
+ requestId,
171
+ target,
172
+ method,
173
+ url,
174
+ attempt,
175
+ maxAttempts,
176
+ error,
177
+ statusCode
178
+ };
179
+ if (error?.name === 'TimeoutError') emitDegradedEvent(transport, {
180
+ requestId,
181
+ target,
182
+ method,
183
+ url,
184
+ reason: 'timeout',
185
+ attempt,
186
+ maxAttempts,
187
+ timeoutMs,
188
+ statusCode,
189
+ error
190
+ });
191
+ const canRetry = attempt < maxAttempts && shouldRetry(transport?.retry, decisionContext, retryableStatusCodes);
192
+ if (!canRetry) {
193
+ if (retries > 0 || error?.name === 'TimeoutError') emitDegradedEvent(transport, {
194
+ requestId,
195
+ target,
196
+ method,
197
+ url,
198
+ reason: 'retry_exhausted',
199
+ attempt,
200
+ maxAttempts,
201
+ timeoutMs,
202
+ statusCode,
203
+ error
204
+ });
205
+ throw error;
206
+ }
207
+ const backoffMs = getBackoffMs(transport?.retry, attempt);
208
+ emitDegradedEvent(transport, {
209
+ requestId,
210
+ target,
211
+ method,
212
+ url,
213
+ reason: 'retry',
214
+ attempt,
215
+ maxAttempts,
216
+ timeoutMs,
217
+ backoffMs,
218
+ statusCode,
219
+ error
220
+ });
221
+ if (backoffMs > 0) await wait(backoffMs);
222
+ }
223
+ }
224
+ };
225
+ __webpack_require__.d(__webpack_exports__, {}, {
226
+ executeWithResilience: executeWithResilience
227
+ });
228
+ exports.executeWithResilience = __webpack_exports__.executeWithResilience;
229
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
230
+ "executeWithResilience"
231
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
232
+ Object.defineProperty(exports, '__esModule', {
233
+ value: true
234
+ });
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ const BFF_ENVELOPE_HEADER = 'x-modernjs-bff-envelope';
31
+ const BFF_OPERATION_CONTEXT_HEADER = 'x-operation-id';
32
+ const BFF_OPERATION_CONTEXT_DETAIL_HEADER = 'x-modernjs-bff-operation-context';
33
+ const BFF_DEFAULT_PROTECTED_IDENTITY_HEADERS = [
34
+ 'x-tenant-id',
35
+ 'x-subject-id',
36
+ 'x-user-id',
37
+ BFF_OPERATION_CONTEXT_HEADER
38
+ ];
39
+ __webpack_require__.d(__webpack_exports__, {}, {
40
+ BFF_DEFAULT_PROTECTED_IDENTITY_HEADERS: BFF_DEFAULT_PROTECTED_IDENTITY_HEADERS,
41
+ BFF_ENVELOPE_HEADER: BFF_ENVELOPE_HEADER,
42
+ BFF_OPERATION_CONTEXT_DETAIL_HEADER: BFF_OPERATION_CONTEXT_DETAIL_HEADER,
43
+ BFF_OPERATION_CONTEXT_HEADER: BFF_OPERATION_CONTEXT_HEADER
44
+ });
45
+ exports.BFF_DEFAULT_PROTECTED_IDENTITY_HEADERS = __webpack_exports__.BFF_DEFAULT_PROTECTED_IDENTITY_HEADERS;
46
+ exports.BFF_ENVELOPE_HEADER = __webpack_exports__.BFF_ENVELOPE_HEADER;
47
+ exports.BFF_OPERATION_CONTEXT_DETAIL_HEADER = __webpack_exports__.BFF_OPERATION_CONTEXT_DETAIL_HEADER;
48
+ exports.BFF_OPERATION_CONTEXT_HEADER = __webpack_exports__.BFF_OPERATION_CONTEXT_HEADER;
49
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
50
+ "BFF_DEFAULT_PROTECTED_IDENTITY_HEADERS",
51
+ "BFF_ENVELOPE_HEADER",
52
+ "BFF_OPERATION_CONTEXT_DETAIL_HEADER",
53
+ "BFF_OPERATION_CONTEXT_HEADER"
54
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
55
+ Object.defineProperty(exports, '__esModule', {
56
+ value: true
57
+ });
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ createRouteHydrationScriptTags: ()=>createRouteHydrationScriptTags,
32
+ getMatchedRouteChunks: ()=>getMatchedRouteChunks,
33
+ injectBeforeHydrationEntryScript: ()=>injectBeforeHydrationEntryScript,
34
+ orderHydrationScriptChunks: ()=>orderHydrationScriptChunks,
35
+ replaceChunkJsPlaceholder: ()=>replaceChunkJsPlaceholder
36
+ });
37
+ const external_html_js_namespaceObject = require("./html.js");
38
+ function getScriptTags(template) {
39
+ const scriptRegExp = /<script\b[^>]*\bsrc=(["'])(.*?)\1[^>]*><\/script>/g;
40
+ return Array.from(template.matchAll(scriptRegExp)).map((match)=>({
41
+ index: match.index ?? 0,
42
+ tag: match[0],
43
+ src: match[2]
44
+ }));
45
+ }
46
+ function getAssetBasename(src) {
47
+ const withoutQuery = src.split(/[?#]/)[0];
48
+ return withoutQuery.split('/').pop() || withoutQuery;
49
+ }
50
+ function isEntryScript(src, entryName, asyncEntry) {
51
+ const basename = getAssetBasename(src);
52
+ const prefix = asyncEntry ? `async-${entryName}` : entryName;
53
+ return basename === `${prefix}.js` || basename.startsWith(`${prefix}.`) || basename.startsWith(`${prefix}-`);
54
+ }
55
+ const dedupeByUrl = (chunks)=>{
56
+ const seen = new Set();
57
+ return chunks.filter((chunk)=>{
58
+ if (void 0 === chunk.url || '' === chunk.url || seen.has(chunk.url)) return false;
59
+ seen.add(chunk.url);
60
+ return true;
61
+ });
62
+ };
63
+ const isAsyncEntryScriptChunk = (chunk, entryName)=>{
64
+ if (void 0 === chunk.url || !chunk.url.endsWith('.js')) return false;
65
+ const asyncEntryName = `async-${entryName}`;
66
+ const filename = chunk.filename ?? chunk.url;
67
+ const basename = filename.split('/').pop() ?? filename;
68
+ return basename === `${asyncEntryName}.js` || basename.startsWith(`${asyncEntryName}.`) || basename.startsWith(`${asyncEntryName}-`);
69
+ };
70
+ function getMatchedRouteChunks(routeManifest, matchedRouteIds, routeAssetToChunk) {
71
+ const routeAssets = routeManifest?.routeAssets;
72
+ if (void 0 === routeAssets) return [];
73
+ return matchedRouteIds.flatMap((routeId)=>routeAssets[routeId]?.assets ?? []).map(routeAssetToChunk);
74
+ }
75
+ const orderHydrationScriptChunks = ({ asyncEntryChunks, collectedChunks, matchedRouteChunks, entryName })=>{
76
+ const asyncEntryScriptChunks = [];
77
+ const asyncEntryDependencyChunks = [];
78
+ for (const chunk of asyncEntryChunks)if (isAsyncEntryScriptChunk(chunk, entryName)) asyncEntryScriptChunks.push(chunk);
79
+ else asyncEntryDependencyChunks.push(chunk);
80
+ return dedupeByUrl([
81
+ ...asyncEntryDependencyChunks,
82
+ ...collectedChunks,
83
+ ...matchedRouteChunks,
84
+ ...asyncEntryScriptChunks
85
+ ]);
86
+ };
87
+ function injectBeforeHydrationEntryScript(template, scripts, entryName = 'index') {
88
+ if ('' === scripts) return template;
89
+ const scriptTags = getScriptTags(template);
90
+ const target = scriptTags.find((match)=>isEntryScript(match.src, entryName, false)) ?? scriptTags.find((match)=>isEntryScript(match.src, entryName, true));
91
+ if (void 0 === target) return template;
92
+ return `${template.slice(0, target.index)}${scripts}${template.slice(target.index)}`;
93
+ }
94
+ function replaceChunkJsPlaceholder(template, scripts, entryName, placeholder) {
95
+ if (!template.includes(placeholder)) return template;
96
+ if ('' === scripts) return template.replace(placeholder, ()=>'');
97
+ const withoutPlaceholder = template.replace(placeholder, ()=>'');
98
+ const withEarlyScripts = injectBeforeHydrationEntryScript(withoutPlaceholder, scripts, entryName);
99
+ if (withEarlyScripts !== withoutPlaceholder) return withEarlyScripts;
100
+ return template.replace(placeholder, ()=>scripts);
101
+ }
102
+ function createRouteHydrationScriptTags(routeManifest, matchedRouteIds, entryName, options = {}) {
103
+ const { nonce, template } = options;
104
+ const routeAssets = routeManifest?.routeAssets;
105
+ if (void 0 === routeAssets) return '';
106
+ const existingScriptSrcs = void 0 === template ? new Set() : new Set(getScriptTags(template).map(({ src })=>src));
107
+ const jsAssets = Array.from(new Set([
108
+ ...getMatchedRouteChunks(routeManifest, matchedRouteIds, (asset)=>asset),
109
+ ...routeAssets[`async-${entryName}`]?.assets ?? []
110
+ ].filter((asset)=>asset.endsWith('.js'))));
111
+ return jsAssets.filter((asset)=>!existingScriptSrcs.has(asset)).map((asset)=>`<script src="${(0, external_html_js_namespaceObject.escapeHtmlAttribute)(asset)}"${nonce ? ` nonce="${(0, external_html_js_namespaceObject.escapeHtmlAttribute)(nonce)}"` : ''}></script>`).join(' ');
112
+ }
113
+ exports.createRouteHydrationScriptTags = __webpack_exports__.createRouteHydrationScriptTags;
114
+ exports.getMatchedRouteChunks = __webpack_exports__.getMatchedRouteChunks;
115
+ exports.injectBeforeHydrationEntryScript = __webpack_exports__.injectBeforeHydrationEntryScript;
116
+ exports.orderHydrationScriptChunks = __webpack_exports__.orderHydrationScriptChunks;
117
+ exports.replaceChunkJsPlaceholder = __webpack_exports__.replaceChunkJsPlaceholder;
118
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
119
+ "createRouteHydrationScriptTags",
120
+ "getMatchedRouteChunks",
121
+ "injectBeforeHydrationEntryScript",
122
+ "orderHydrationScriptChunks",
123
+ "replaceChunkJsPlaceholder"
124
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
125
+ Object.defineProperty(exports, '__esModule', {
126
+ value: true
127
+ });