oidc-spa 10.2.12 → 10.2.14
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/core/createOidc.js +1 -1
- package/esm/core/createOidc.mjs +1 -1
- package/esm/tanstack-start/react/createOidcSpaUtils.mjs +26 -57
- package/esm/tanstack-start/react/createOidcSpaUtils.mjs.map +1 -1
- package/esm/vendor/build-runtime/babel.d.ts +5 -4
- package/esm/vendor/build-runtime/babel.mjs +4 -4
- package/esm/vite-plugin/handleTanstackStartBootstrapEnv.d.ts +10 -0
- package/esm/vite-plugin/handleTanstackStartBootstrapEnv.mjs +419 -0
- package/esm/vite-plugin/handleTanstackStartBootstrapEnv.mjs.map +1 -0
- package/esm/vite-plugin/vite-plugin.mjs +16 -1
- package/esm/vite-plugin/vite-plugin.mjs.map +1 -1
- package/package.json +1 -1
- package/src/tanstack-start/react/createOidcSpaUtils.ts +37 -93
- package/src/tanstack-start/react/publicEnv.d.ts +3 -0
- package/src/vendor/build-runtime/babel.ts +13 -4
- package/src/vite-plugin/handleTanstackStartBootstrapEnv.ts +490 -0
- package/src/vite-plugin/vite-plugin.ts +18 -1
|
@@ -16,7 +16,6 @@ import { assert, type Equals, is } from "../../tools/tsafe/assert";
|
|
|
16
16
|
import { createObjectThatThrowsIfAccessed } from "../../tools/createObjectThatThrowsIfAccessed";
|
|
17
17
|
import { createStatefulEvt } from "../../tools/StatefulEvt";
|
|
18
18
|
import { id } from "../../tools/tsafe/id";
|
|
19
|
-
import { typeGuard } from "../../tools/tsafe/typeGuard";
|
|
20
19
|
import type { GetterOrDirectValue } from "../../tools/GetterOrDirectValue";
|
|
21
20
|
import { createServerFn, createMiddleware } from "@tanstack/react-start";
|
|
22
21
|
// @ts-expect-error: Since our module is not labeled as ESM we don't have the types here.
|
|
@@ -27,6 +26,7 @@ import { BEFORE_LOAD_FN_BRAND_PROPERTY_NAME } from "./disableSsrIfLoginEnforced"
|
|
|
27
26
|
import { setDesiredPostLoginRedirectUrl } from "../../core/desiredPostLoginRedirectUrl";
|
|
28
27
|
import type { MaybeAsync } from "../../tools/MaybeAsync";
|
|
29
28
|
import { enableStateDataCookie } from "../../core/StateDataCookie";
|
|
29
|
+
import { publicEnvNames } from "virtual:oidc-spa/tanstack-start-public-env";
|
|
30
30
|
|
|
31
31
|
export function createOidcSpaUtils<
|
|
32
32
|
AutoLogin extends boolean,
|
|
@@ -541,95 +541,57 @@ export function createOidcSpaUtils<
|
|
|
541
541
|
assert(prModuleCore !== undefined);
|
|
542
542
|
|
|
543
543
|
const paramsOfBootstrap = await (async () => {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
544
|
+
class OidcSpaServerEnvRetrievalError extends Error {
|
|
545
|
+
constructor(params: { envName: string }) {
|
|
546
|
+
super(`oidc-spa: Env value ${params.envName} couldn't be pulled from server`);
|
|
547
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
547
550
|
|
|
548
|
-
const
|
|
549
|
-
|
|
550
|
-
|
|
551
|
+
const env_server_proxy = new Proxy(
|
|
552
|
+
publicEnvNames.size === 0 ? {} : await fetchServerEnvVariableValues(),
|
|
553
|
+
{
|
|
554
|
+
get: (target, envName) => {
|
|
555
|
+
assert(typeof envName === "string");
|
|
551
556
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
557
|
+
if (!Object.prototype.hasOwnProperty.call(target, envName)) {
|
|
558
|
+
throw new OidcSpaServerEnvRetrievalError({ envName });
|
|
559
|
+
}
|
|
555
560
|
|
|
556
|
-
|
|
561
|
+
return target[envName];
|
|
562
|
+
},
|
|
563
|
+
has: (target, envName) => {
|
|
564
|
+
assert(typeof envName === "string");
|
|
557
565
|
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
assert(typeof envName === "string");
|
|
566
|
+
if (!Object.prototype.hasOwnProperty.call(target, envName)) {
|
|
567
|
+
throw new OidcSpaServerEnvRetrievalError({ envName });
|
|
568
|
+
}
|
|
562
569
|
|
|
563
|
-
if (envName in env) {
|
|
564
570
|
return true;
|
|
565
571
|
}
|
|
566
|
-
|
|
567
|
-
envNamesToPullFromServer.add(envName);
|
|
568
|
-
|
|
569
|
-
return true;
|
|
570
572
|
}
|
|
571
|
-
|
|
573
|
+
) as Record<string, string>;
|
|
572
574
|
|
|
573
|
-
let
|
|
574
|
-
| {
|
|
575
|
-
hasThrown: false;
|
|
576
|
-
paramsOfBootstrap: ParamsOfBootstrap<
|
|
577
|
-
AutoLogin,
|
|
578
|
-
DecodedIdToken,
|
|
579
|
-
AccessTokenClaims
|
|
580
|
-
>;
|
|
581
|
-
}
|
|
582
|
-
| {
|
|
583
|
-
hasThrown: true;
|
|
584
|
-
error: unknown;
|
|
585
|
-
}
|
|
586
|
-
| undefined = undefined;
|
|
587
|
-
|
|
588
|
-
while (true) {
|
|
589
|
-
envNamesToPullFromServer = new Set();
|
|
590
|
-
|
|
591
|
-
result = undefined;
|
|
592
|
-
|
|
593
|
-
try {
|
|
594
|
-
const paramsOfBootstrap = getParamsOfBootstrap({ process: { env: env_proxy } });
|
|
595
|
-
result = {
|
|
596
|
-
hasThrown: false,
|
|
597
|
-
paramsOfBootstrap
|
|
598
|
-
};
|
|
599
|
-
} catch (error) {
|
|
600
|
-
result = {
|
|
601
|
-
hasThrown: true,
|
|
602
|
-
error
|
|
603
|
-
};
|
|
604
|
-
}
|
|
575
|
+
let paramsOfBootstrap: ParamsOfBootstrap<AutoLogin, DecodedIdToken, AccessTokenClaims>;
|
|
605
576
|
|
|
606
|
-
|
|
607
|
-
|
|
577
|
+
try {
|
|
578
|
+
paramsOfBootstrap = getParamsOfBootstrap({ process: { env: env_server_proxy } });
|
|
579
|
+
} catch (error) {
|
|
580
|
+
if (error instanceof OidcSpaServerEnvRetrievalError) {
|
|
581
|
+
throw error;
|
|
608
582
|
}
|
|
609
583
|
|
|
610
|
-
Object.entries(
|
|
611
|
-
await fetchServerEnvVariableValues({
|
|
612
|
-
data: {
|
|
613
|
-
envVarNames: Array.from(envNamesToPullFromServer)
|
|
614
|
-
}
|
|
615
|
-
})
|
|
616
|
-
).forEach(([envName, value]) => {
|
|
617
|
-
env[envName] = value;
|
|
618
|
-
});
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
if (result.hasThrown) {
|
|
622
584
|
throw new Error(
|
|
623
585
|
[
|
|
624
586
|
"oidc-spa: The function argument passed to bootstrapOidc",
|
|
625
587
|
"has thrown when invoked."
|
|
626
588
|
].join(" "),
|
|
627
589
|
//@ts-expect-error
|
|
628
|
-
{ cause:
|
|
590
|
+
{ cause: error }
|
|
629
591
|
);
|
|
630
592
|
}
|
|
631
593
|
|
|
632
|
-
return
|
|
594
|
+
return paramsOfBootstrap;
|
|
633
595
|
})();
|
|
634
596
|
|
|
635
597
|
dParamsOfBootstrap.resolve(paramsOfBootstrap);
|
|
@@ -793,7 +755,7 @@ export function createOidcSpaUtils<
|
|
|
793
755
|
enforceLogin[BEFORE_LOAD_FN_BRAND_PROPERTY_NAME] = true;
|
|
794
756
|
|
|
795
757
|
const prValidateAndGetAccessTokenClaims =
|
|
796
|
-
createValidateAndGetAccessTokenClaims === undefined
|
|
758
|
+
createValidateAndGetAccessTokenClaims === undefined || isBrowser
|
|
797
759
|
? undefined
|
|
798
760
|
: dParamsOfBootstrap.pr.then(paramsOfBootstrap =>
|
|
799
761
|
createValidateAndGetAccessTokenClaims({
|
|
@@ -1021,26 +983,8 @@ export function createOidcSpaUtils<
|
|
|
1021
983
|
};
|
|
1022
984
|
}
|
|
1023
985
|
|
|
1024
|
-
const fetchServerEnvVariableValues = createServerFn({ method: "GET" })
|
|
1025
|
-
.
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
const { envVarNames } = data as Record<string, unknown>;
|
|
1031
|
-
|
|
1032
|
-
assert(
|
|
1033
|
-
typeGuard<string[]>(
|
|
1034
|
-
envVarNames,
|
|
1035
|
-
Array.isArray(envVarNames) && envVarNames.every(name => typeof name === "string")
|
|
1036
|
-
)
|
|
1037
|
-
);
|
|
1038
|
-
|
|
1039
|
-
return { envVarNames };
|
|
1040
|
-
})
|
|
1041
|
-
.handler(async ({ data }) => {
|
|
1042
|
-
const { envVarNames } = data;
|
|
1043
|
-
return Object.fromEntries(
|
|
1044
|
-
envVarNames.map(envVarName => [envVarName, process.env[envVarName] ?? ""])
|
|
1045
|
-
);
|
|
1046
|
-
});
|
|
986
|
+
const fetchServerEnvVariableValues = createServerFn({ method: "GET" }).handler(async () =>
|
|
987
|
+
Object.fromEntries(
|
|
988
|
+
Array.from(publicEnvNames).map(envVarName => [envVarName, process.env[envVarName] ?? ""])
|
|
989
|
+
)
|
|
990
|
+
);
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
export * as babelParser from "@babel/parser";
|
|
2
|
-
import
|
|
3
|
-
export
|
|
2
|
+
import babelGenerate_import from "@babel/generator";
|
|
3
|
+
// Babel's CommonJS entrypoints expose their callable export under `default`.
|
|
4
|
+
// Native ESM and bundlers do not unwrap these imports in the same way.
|
|
5
|
+
export const babelGenerate: typeof babelGenerate_import =
|
|
6
|
+
typeof babelGenerate_import === "function"
|
|
7
|
+
? babelGenerate_import
|
|
8
|
+
: (babelGenerate_import as { default: typeof babelGenerate_import }).default;
|
|
4
9
|
export * as babelTypes from "@babel/types";
|
|
5
|
-
import
|
|
6
|
-
export
|
|
10
|
+
import babelTraverse_import from "@babel/traverse";
|
|
11
|
+
export const babelTraverse: typeof babelTraverse_import =
|
|
12
|
+
typeof babelTraverse_import === "function"
|
|
13
|
+
? babelTraverse_import
|
|
14
|
+
: (babelTraverse_import as { default: typeof babelTraverse_import }).default;
|
|
15
|
+
export type { NodePath } from "@babel/traverse";
|