oidc-spa 10.2.11 → 10.2.13

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 (33) hide show
  1. package/README.md +0 -24
  2. package/core/createOidc.js +4 -3
  3. package/core/createOidc.js.map +1 -1
  4. package/core/loginOrGoToAuthServer.js +18 -0
  5. package/core/loginOrGoToAuthServer.js.map +1 -1
  6. package/esm/core/createOidc.mjs +4 -3
  7. package/esm/core/createOidc.mjs.map +1 -1
  8. package/esm/core/loginOrGoToAuthServer.mjs +18 -0
  9. package/esm/core/loginOrGoToAuthServer.mjs.map +1 -1
  10. package/esm/tanstack-start/react/createOidcSpaUtils.mjs +26 -55
  11. package/esm/tanstack-start/react/createOidcSpaUtils.mjs.map +1 -1
  12. package/esm/tools/isNetworkError.d.ts +15 -0
  13. package/esm/tools/isNetworkError.mjs +18 -0
  14. package/esm/tools/isNetworkError.mjs.map +1 -0
  15. package/esm/vendor/build-runtime/babel.d.ts +5 -4
  16. package/esm/vendor/build-runtime/babel.mjs +4 -4
  17. package/esm/vite-plugin/handleTanstackStartBootstrapEnv.d.ts +11 -0
  18. package/esm/vite-plugin/handleTanstackStartBootstrapEnv.mjs +372 -0
  19. package/esm/vite-plugin/handleTanstackStartBootstrapEnv.mjs.map +1 -0
  20. package/esm/vite-plugin/vite-plugin.mjs +18 -2
  21. package/esm/vite-plugin/vite-plugin.mjs.map +1 -1
  22. package/package.json +1 -1
  23. package/src/core/createOidc.ts +3 -2
  24. package/src/core/loginOrGoToAuthServer.ts +19 -0
  25. package/src/tanstack-start/react/createOidcSpaUtils.ts +29 -87
  26. package/src/tanstack-start/react/publicEnv.d.ts +3 -0
  27. package/src/tools/isNetworkError.ts +17 -0
  28. package/src/vendor/build-runtime/babel.ts +13 -4
  29. package/src/vite-plugin/handleTanstackStartBootstrapEnv.ts +440 -0
  30. package/src/vite-plugin/vite-plugin.ts +20 -2
  31. package/tools/isNetworkError.d.ts +15 -0
  32. package/tools/isNetworkError.js +21 -0
  33. package/tools/isNetworkError.js.map +1 -0
@@ -7,6 +7,7 @@ import { manageOptimizedDeps } from "./manageOptimizedDeps";
7
7
  import { transformCreateFileRoute } from "./transformTanstackRouterCreateFileRoute";
8
8
  import { getProjectType, type ProjectType } from "./projectType";
9
9
  import { createHandleTanstackStartClientOutput } from "./handleTanstackStartClientOutput";
10
+ import { createHandleTanstackStartBootstrapEnv } from "./handleTanstackStartBootstrapEnv";
10
11
 
11
12
  export type OidcSpaVitePluginParams = {
12
13
  /** See: https://docs.oidc-spa.dev/v/v10/security-features/browser-runtime-freeze */
@@ -87,6 +88,7 @@ export function oidcSpa(params: OidcSpaVitePluginParams = {}) {
87
88
 
88
89
  let projectType: ProjectType | undefined = undefined;
89
90
  let isBuild = false;
91
+ let bootstrapEnvHandler: ReturnType<typeof createHandleTanstackStartBootstrapEnv> | undefined;
90
92
 
91
93
  const plugin: Plugin = {
92
94
  name: "oidc-spa",
@@ -110,6 +112,10 @@ export function oidcSpa(params: OidcSpaVitePluginParams = {}) {
110
112
  pluginNames: resolvedConfig.plugins.map(({ name }) => name)
111
113
  });
112
114
 
115
+ if (projectType === "tanstack-start") {
116
+ bootstrapEnvHandler = createHandleTanstackStartBootstrapEnv({ resolvedConfig });
117
+ }
118
+
113
119
  const clientEntrypointHandler = createHandleClientEntrypoint({
114
120
  oidcSpaVitePluginParams: params,
115
121
  resolvedConfig,
@@ -157,12 +163,24 @@ export function oidcSpa(params: OidcSpaVitePluginParams = {}) {
157
163
  return transformed;
158
164
  },
159
165
  resolveId(id) {
160
- return resolveId_handleTanstackStartClientOutput?.(id) ?? null;
166
+ return (
167
+ bootstrapEnvHandler?.resolveId(id) ??
168
+ resolveId_handleTanstackStartClientOutput?.(id) ??
169
+ null
170
+ );
161
171
  },
162
- buildStart() {
172
+ async buildStart() {
173
+ await bootstrapEnvHandler?.buildStart(this);
163
174
  buildStart_handleTanstackStartClientOutput?.call(this);
164
175
  },
176
+ configureServer(server) {
177
+ bootstrapEnvHandler?.configureServer(server);
178
+ },
165
179
  async load(id) {
180
+ {
181
+ const r = await bootstrapEnvHandler?.load(id, this);
182
+ if (r !== null && r !== undefined) return r;
183
+ }
166
184
  {
167
185
  const r = load_handleTanstackStartClientOutput?.(id) ?? null;
168
186
 
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Tells whether an error thrown by `fetch()` (or by something that calls it,
3
+ * like oidc-client-ts, which re-throws it unwrapped) is a network failure.
4
+ *
5
+ * The Fetch spec requires a network failure to reject with a `TypeError`, but
6
+ * it does not specify the message, and every engine words it differently:
7
+ *
8
+ * - Chromium: "Failed to fetch"
9
+ * - Firefox: "NetworkError when attempting to fetch resource."
10
+ * - Safari: "Load failed"
11
+ *
12
+ * Matching on the text therefore only ever recognises one engine, and silently
13
+ * skips the recovery path everywhere else. Match on the type instead.
14
+ */
15
+ export declare function isNetworkError(error: unknown): boolean;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNetworkError = isNetworkError;
4
+ /**
5
+ * Tells whether an error thrown by `fetch()` (or by something that calls it,
6
+ * like oidc-client-ts, which re-throws it unwrapped) is a network failure.
7
+ *
8
+ * The Fetch spec requires a network failure to reject with a `TypeError`, but
9
+ * it does not specify the message, and every engine words it differently:
10
+ *
11
+ * - Chromium: "Failed to fetch"
12
+ * - Firefox: "NetworkError when attempting to fetch resource."
13
+ * - Safari: "Load failed"
14
+ *
15
+ * Matching on the text therefore only ever recognises one engine, and silently
16
+ * skips the recovery path everywhere else. Match on the type instead.
17
+ */
18
+ function isNetworkError(error) {
19
+ return error instanceof TypeError;
20
+ }
21
+ //# sourceMappingURL=isNetworkError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isNetworkError.js","sourceRoot":"","sources":["../src/tools/isNetworkError.ts"],"names":[],"mappings":";;AAcA,wCAEC;AAhBD;;;;;;;;;;;;;GAaG;AACH,SAAgB,cAAc,CAAC,KAAc;IACzC,OAAO,KAAK,YAAY,SAAS,CAAC;AACtC,CAAC"}