@enterprisestandard/react 0.0.3-beta.20251013.2 → 0.0.3-beta.20251014.1
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/dist/index.d.ts +0 -1
- package/dist/index.js +35 -31
- package/dist/sso.d.ts +4 -4
- package/dist/vault.d.ts +3 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ export type EnterpriseStandard = {
|
|
|
12
12
|
type ESConfig = {
|
|
13
13
|
ioniteUrl?: string;
|
|
14
14
|
defaultInstance?: boolean;
|
|
15
|
-
ssoUserUrl?: string;
|
|
16
15
|
};
|
|
17
16
|
export declare function enterpriseStandard(appId: string, appKey?: string, initConfig?: ESConfig): Promise<EnterpriseStandard>;
|
|
18
17
|
export type * from './enterprise-user';
|
package/dist/index.js
CHANGED
|
@@ -34,10 +34,10 @@ var jwksCache = new Map;
|
|
|
34
34
|
function sso(config) {
|
|
35
35
|
const configWithDefaults = {
|
|
36
36
|
...config,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
cookies_secure: config.cookies_secure !== undefined ? config.cookies_secure : true,
|
|
38
|
+
cookies_same_site: config.cookies_same_site !== undefined ? config.cookies_same_site : "Strict",
|
|
39
|
+
cookies_prefix: config.cookies_prefix ?? `es.sso.${config.client_id}`,
|
|
40
|
+
cookies_path: config.cookies_path ?? "/"
|
|
41
41
|
};
|
|
42
42
|
async function getUser(request) {
|
|
43
43
|
if (!configWithDefaults) {
|
|
@@ -357,7 +357,7 @@ function sso(config) {
|
|
|
357
357
|
return tokens.access_token;
|
|
358
358
|
}
|
|
359
359
|
function createCookie(name, value, expires) {
|
|
360
|
-
name = `${configWithDefaults.
|
|
360
|
+
name = `${configWithDefaults.cookies_prefix}.${name}`;
|
|
361
361
|
if (typeof value !== "string") {
|
|
362
362
|
value = btoa(JSON.stringify(value));
|
|
363
363
|
}
|
|
@@ -372,16 +372,16 @@ function sso(config) {
|
|
|
372
372
|
if (value.length > 4000) {
|
|
373
373
|
throw new Error(`Error setting cookie: ${name}. Cookie length is: ${value.length}`);
|
|
374
374
|
}
|
|
375
|
-
return `${name}=${value}; ${exp}; Path=${configWithDefaults.
|
|
375
|
+
return `${name}=${value}; ${exp}; Path=${configWithDefaults.cookies_path}; HttpOnly;${configWithDefaults.cookies_secure ? " Secure;" : ""} SameSite=${configWithDefaults.cookies_same_site};`;
|
|
376
376
|
}
|
|
377
377
|
function clearCookie(name) {
|
|
378
|
-
return `${configWithDefaults.
|
|
378
|
+
return `${configWithDefaults.cookies_prefix}.${name}=; Max-Age=0; Path=${configWithDefaults.cookies_path}; HttpOnly;${configWithDefaults.cookies_secure ? " Secure;" : ""} SameSite=${configWithDefaults.cookies_same_site};`;
|
|
379
379
|
}
|
|
380
380
|
function getCookie(name, req, parse = false) {
|
|
381
381
|
const header = req.headers.get("cookie");
|
|
382
382
|
if (!header)
|
|
383
383
|
return null;
|
|
384
|
-
const cookie = header.split(";").find((row) => row.trim().startsWith(`${configWithDefaults.
|
|
384
|
+
const cookie = header.split(";").find((row) => row.trim().startsWith(`${configWithDefaults.cookies_prefix}.${name}=`));
|
|
385
385
|
if (!cookie)
|
|
386
386
|
return null;
|
|
387
387
|
const val = cookie.split("=")[1].trim();
|
|
@@ -452,8 +452,8 @@ function sso(config) {
|
|
|
452
452
|
}
|
|
453
453
|
|
|
454
454
|
// src/vault.ts
|
|
455
|
-
function vault(url
|
|
456
|
-
async function getFullSecret(path) {
|
|
455
|
+
function vault(url) {
|
|
456
|
+
async function getFullSecret(path, token) {
|
|
457
457
|
const resp = await fetch(`${url}/${path}`, { headers: { "X-Vault-Token": token } });
|
|
458
458
|
if (resp.status !== 200) {
|
|
459
459
|
throw new Error(`Vault returned invalid status, ${resp.status}: '${resp.statusText}' from URL: ${url}`);
|
|
@@ -468,8 +468,8 @@ function vault(url, token) {
|
|
|
468
468
|
return {
|
|
469
469
|
url,
|
|
470
470
|
getFullSecret,
|
|
471
|
-
getSecret: async (path) => {
|
|
472
|
-
return (await getFullSecret(path)).data;
|
|
471
|
+
getSecret: async (path, token) => {
|
|
472
|
+
return (await getFullSecret(path, token)).data;
|
|
473
473
|
}
|
|
474
474
|
};
|
|
475
475
|
}
|
|
@@ -620,38 +620,38 @@ async function handler(request, config) {
|
|
|
620
620
|
return sso2.handler(request, config);
|
|
621
621
|
}
|
|
622
622
|
// src/ui/sign-in-loading.tsx
|
|
623
|
-
import {
|
|
623
|
+
import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
|
|
624
624
|
function SignInLoading({ complete = false, children }) {
|
|
625
625
|
const { isLoading } = useUser();
|
|
626
626
|
if (isLoading && !complete)
|
|
627
|
-
return /* @__PURE__ */
|
|
627
|
+
return /* @__PURE__ */ jsxDEV(Fragment, {
|
|
628
628
|
children
|
|
629
|
-
});
|
|
629
|
+
}, undefined, false, undefined, this);
|
|
630
630
|
return null;
|
|
631
631
|
}
|
|
632
632
|
// src/ui/signed-in.tsx
|
|
633
|
-
import {
|
|
633
|
+
import { jsxDEV as jsxDEV2, Fragment as Fragment2 } from "react/jsx-dev-runtime";
|
|
634
634
|
function SignedIn({ children }) {
|
|
635
635
|
const { user } = useUser();
|
|
636
636
|
if (user)
|
|
637
|
-
return /* @__PURE__ */
|
|
637
|
+
return /* @__PURE__ */ jsxDEV2(Fragment2, {
|
|
638
638
|
children
|
|
639
|
-
});
|
|
639
|
+
}, undefined, false, undefined, this);
|
|
640
640
|
return null;
|
|
641
641
|
}
|
|
642
642
|
// src/ui/signed-out.tsx
|
|
643
|
-
import {
|
|
643
|
+
import { jsxDEV as jsxDEV3, Fragment as Fragment3 } from "react/jsx-dev-runtime";
|
|
644
644
|
function SignedOut({ children }) {
|
|
645
645
|
const { user, isLoading } = useUser();
|
|
646
646
|
if (user || isLoading)
|
|
647
647
|
return null;
|
|
648
|
-
return /* @__PURE__ */
|
|
648
|
+
return /* @__PURE__ */ jsxDEV3(Fragment3, {
|
|
649
649
|
children
|
|
650
|
-
});
|
|
650
|
+
}, undefined, false, undefined, this);
|
|
651
651
|
}
|
|
652
652
|
// src/ui/sso-provider.tsx
|
|
653
653
|
import { createContext, useCallback, useContext, useEffect, useState } from "react";
|
|
654
|
-
import {
|
|
654
|
+
import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
|
|
655
655
|
var CTX = createContext(undefined);
|
|
656
656
|
var generateStorageKey = (tenantId) => {
|
|
657
657
|
return `es-sso-user-${tenantId.replace(/[^a-zA-Z0-9]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "")}`;
|
|
@@ -786,10 +786,10 @@ function SSOProvider({
|
|
|
786
786
|
tokenUrl,
|
|
787
787
|
refreshUrl
|
|
788
788
|
};
|
|
789
|
-
return /* @__PURE__ */
|
|
789
|
+
return /* @__PURE__ */ jsxDEV4(CTX.Provider, {
|
|
790
790
|
value: contextValue,
|
|
791
791
|
children
|
|
792
|
-
});
|
|
792
|
+
}, undefined, false, undefined, this);
|
|
793
793
|
}
|
|
794
794
|
function useUser() {
|
|
795
795
|
const context = useContext(CTX);
|
|
@@ -880,29 +880,33 @@ function useToken() {
|
|
|
880
880
|
async function enterpriseStandard(appId, appKey, initConfig) {
|
|
881
881
|
let vaultUrl;
|
|
882
882
|
let vaultToken;
|
|
883
|
-
let
|
|
883
|
+
let secrets;
|
|
884
884
|
const ioniteUrl = initConfig?.ioniteUrl ?? "https://ionite.com";
|
|
885
885
|
if (appId === "IONITE_PUBLIC_DEMO") {
|
|
886
886
|
vaultUrl = "https://vault-ionite.ionite.dev/v1/secret/data";
|
|
887
|
-
|
|
888
|
-
|
|
887
|
+
secrets = {
|
|
888
|
+
sso: {
|
|
889
|
+
path: "public/IONITE_PUBLIC_DEMO_SSO",
|
|
890
|
+
token: "hvs.CAESIDGntTzqry6HOySoqAGUMQyfkF4RDj3xas23zhsJC6-uGh4KHGh2cy5mSzZXNHFQRWlZMG9VVnpWSlA1Zk1YeUE"
|
|
891
|
+
}
|
|
892
|
+
};
|
|
889
893
|
} else if (appKey) {
|
|
890
894
|
if (!vaultUrl || !vaultToken) {
|
|
891
895
|
throw new Error("TODO something is wrong with the ionite config, handle this error");
|
|
892
896
|
}
|
|
893
|
-
|
|
897
|
+
secrets = {};
|
|
894
898
|
} else {
|
|
895
899
|
throw new Error("TODO tell them how to connect to ionite");
|
|
896
900
|
}
|
|
897
901
|
const defaultInstance2 = getDefaultInstance();
|
|
898
|
-
const vaultClient = await vault(vaultUrl
|
|
902
|
+
const vaultClient = await vault(vaultUrl);
|
|
899
903
|
const result = {
|
|
900
904
|
appId,
|
|
901
905
|
ioniteUrl,
|
|
902
906
|
defaultInstance: initConfig?.defaultInstance || initConfig?.defaultInstance !== false && !defaultInstance2,
|
|
903
907
|
vault: vaultClient,
|
|
904
|
-
sso:
|
|
905
|
-
iam:
|
|
908
|
+
sso: secrets.sso ? sso(await vaultClient.getSecret(secrets.sso.path, secrets.sso.token)) : undefined,
|
|
909
|
+
iam: secrets.iam ? await iam(await vaultClient.getSecret(secrets.iam.path, secrets.iam.token)) : undefined
|
|
906
910
|
};
|
|
907
911
|
if (result.defaultInstance) {
|
|
908
912
|
if (defaultInstance2) {
|
package/dist/sso.d.ts
CHANGED
|
@@ -10,10 +10,10 @@ export type SSOConfig = {
|
|
|
10
10
|
post_logout_redirect_uri?: string;
|
|
11
11
|
silent_redirect_uri?: string;
|
|
12
12
|
jwks_uri?: string;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
cookies_prefix?: string;
|
|
14
|
+
cookies_path?: string;
|
|
15
|
+
cookies_secure?: boolean;
|
|
16
|
+
cookies_same_site?: 'Strict' | 'Lax';
|
|
17
17
|
};
|
|
18
18
|
export type ESConfig = {
|
|
19
19
|
es?: EnterpriseStandard;
|
package/dist/vault.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ type MetaData = {
|
|
|
10
10
|
};
|
|
11
11
|
export type Vault = {
|
|
12
12
|
url: string;
|
|
13
|
-
getFullSecret: <T>(path: string) => Promise<Secret<T>>;
|
|
14
|
-
getSecret: <T>(path: string) => Promise<T>;
|
|
13
|
+
getFullSecret: <T>(path: string, token: string) => Promise<Secret<T>>;
|
|
14
|
+
getSecret: <T>(path: string, token: string) => Promise<T>;
|
|
15
15
|
};
|
|
16
|
-
export declare function vault(url: string
|
|
16
|
+
export declare function vault(url: string): Vault;
|
|
17
17
|
export {};
|