@authdog/node-commons 0.0.17 → 0.0.19
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 +6 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +10 -4
- package/dist/index.d.mts +0 -14
- package/dist/index.mjs +0 -2
- package/dist/index.mjs.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,10 +5,15 @@ interface PublicKeyPayload {
|
|
|
5
5
|
region?: "EU" | "US";
|
|
6
6
|
}
|
|
7
7
|
declare const getPublicKeyPayload: (publicKey: string) => PublicKeyPayload;
|
|
8
|
+
declare const validateAndParsePublicKey: (publicKey: string) => any;
|
|
8
9
|
|
|
9
10
|
declare const parseCookies: (cookieHeader: string | null) => {
|
|
10
11
|
name: string;
|
|
11
12
|
value: string;
|
|
12
13
|
}[];
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
declare const buildSessionKey: (environmentId: string) => string;
|
|
16
|
+
|
|
17
|
+
declare const fetchUserData: (identityHost: string, environmentId: string, token: string) => Promise<any>;
|
|
18
|
+
|
|
19
|
+
export { type PublicKeyPayload, buildSessionKey, fetchUserData, getPublicKeyPayload, parseCookies, validateAndParsePublicKey };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
var i=r=>{if(!r)throw new Error("Public key is not defined");if(!r.startsWith("pk_"))throw new Error("Invalid public key");try{return JSON.parse(Buffer.from(r.replace("pk_",""),"base64").toString("utf-8"))}catch{throw new Error("Failed to parse public key")}},n=r=>{if(!r)throw new Error("Public key is not defined");if(!r.startsWith("pk_"))throw new Error("Invalid public key");return JSON.parse(Buffer.from(r.replace("pk_",""),"base64").toString("utf-8"))};var s=r=>r?r.split(";").map(e=>{let[o,t]=e.trim().split("=");return{name:o,value:t}}):[];var a=r=>`user_session_${r}`;var l=async(r,e,o)=>{let t=await fetch(`${r}/oidc/${e}/userinfo`,{headers:{authorization:`Bearer ${o}`}});if(!t.ok)throw new Error("Failed to fetch user info");return t.json()};export{a as buildSessionKey,l as fetchUserData,i as getPublicKeyPayload,s as parseCookies,n as validateAndParsePublicKey};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/public-key.ts","../src/cookies.ts","../src/session.ts","../src/identity.ts"],"sourcesContent":["export interface PublicKeyPayload {\n environmentId: string;\n identityHost: string;\n version?: string;\n region?: \"EU\" | \"US\";\n}\nexport const getPublicKeyPayload = (publicKey: string): PublicKeyPayload => {\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n if (!publicKey.startsWith(\"pk_\")) {\n throw new Error(\"Invalid public key\");\n }\n try {\n return JSON.parse(\n Buffer.from(publicKey.replace(\"pk_\", \"\"), \"base64\").toString(\"utf-8\"),\n );\n } catch (e) {\n throw new Error(\"Failed to parse public key\");\n }\n};\n\n\nexport const validateAndParsePublicKey = (publicKey: string) => {\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n\n if (!publicKey.startsWith(\"pk_\")) {\n throw new Error(\"Invalid public key\");\n }\n\n // Decode Base64-encoded publicKey\n return JSON.parse(\n Buffer.from(publicKey.replace(\"pk_\", \"\"), \"base64\").toString(\"utf-8\"),\n );\n};","// Function to parse cookies from request\nexport const parseCookies = (cookieHeader: string | null) => {\n if (!cookieHeader) {\n return [];\n }\n\n return cookieHeader.split(\";\").map((cookie) => {\n const [name, value] = cookie.trim().split(\"=\");\n return { name, value };\n });\n};\n","export const buildSessionKey = (environmentId: string) => {\n return `user_session_${environmentId}`;\n};","export const fetchUserData = async (\n identityHost: string,\n environmentId: string,\n token: string,\n ) => {\n const userData = await fetch(\n `${identityHost}/oidc/${environmentId}/userinfo`,\n {\n headers: {\n authorization: `Bearer ${token}`,\n },\n },\n );\n \n if (!userData.ok) {\n throw new Error(\"Failed to fetch user info\");\n }\n \n return userData.json();\n};"],"mappings":"AAMO,IAAMA,EAAuBC,GAAwC,CAC1E,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,2BAA2B,EAE7C,GAAI,CAACA,EAAU,WAAW,KAAK,EAC7B,MAAM,IAAI,MAAM,oBAAoB,EAEtC,GAAI,CACF,OAAO,KAAK,MACV,OAAO,KAAKA,EAAU,QAAQ,MAAO,EAAE,EAAG,QAAQ,EAAE,SAAS,OAAO,CACtE,CACF,MAAY,CACV,MAAM,IAAI,MAAM,4BAA4B,CAC9C,CACF,EAGaC,EAA6BD,GAAsB,CAC9D,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,2BAA2B,EAG7C,GAAI,CAACA,EAAU,WAAW,KAAK,EAC7B,MAAM,IAAI,MAAM,oBAAoB,EAItC,OAAO,KAAK,MACV,OAAO,KAAKA,EAAU,QAAQ,MAAO,EAAE,EAAG,QAAQ,EAAE,SAAS,OAAO,CACtE,CACF,ECnCO,IAAME,EAAgBC,GACtBA,EAIEA,EAAa,MAAM,GAAG,EAAE,IAAKC,GAAW,CAC7C,GAAM,CAACC,EAAMC,CAAK,EAAIF,EAAO,KAAK,EAAE,MAAM,GAAG,EAC7C,MAAO,CAAE,KAAAC,EAAM,MAAAC,CAAM,CACvB,CAAC,EANQ,CAAC,ECHL,IAAMC,EAAmBC,GACrB,gBAAgBA,CAAa,GCDjC,IAAMC,EAAgB,MACzBC,EACAC,EACAC,IACG,CACH,IAAMC,EAAW,MAAM,MACrB,GAAGH,CAAY,SAASC,CAAa,YACrC,CACE,QAAS,CACP,cAAe,UAAUC,CAAK,EAChC,CACF,CACF,EAEA,GAAI,CAACC,EAAS,GACZ,MAAM,IAAI,MAAM,2BAA2B,EAG7C,OAAOA,EAAS,KAAK,CACzB","names":["getPublicKeyPayload","publicKey","validateAndParsePublicKey","parseCookies","cookieHeader","cookie","name","value","buildSessionKey","environmentId","fetchUserData","identityHost","environmentId","token","userData"]}
|
package/package.json
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authdog/node-commons",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"description": "Authdog Next.js SDK",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"source": "src/index.ts",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
9
15
|
"files": [
|
|
10
16
|
"dist/"
|
|
11
17
|
],
|
package/dist/index.d.mts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
interface PublicKeyPayload {
|
|
2
|
-
environmentId: string;
|
|
3
|
-
identityHost: string;
|
|
4
|
-
version?: string;
|
|
5
|
-
region?: "EU" | "US";
|
|
6
|
-
}
|
|
7
|
-
declare const getPublicKeyPayload: (publicKey: string) => PublicKeyPayload;
|
|
8
|
-
|
|
9
|
-
declare const parseCookies: (cookieHeader: string | null) => {
|
|
10
|
-
name: string;
|
|
11
|
-
value: string;
|
|
12
|
-
}[];
|
|
13
|
-
|
|
14
|
-
export { getPublicKeyPayload, parseCookies };
|
package/dist/index.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var i=r=>{if(!r)throw new Error("Public key is not defined");if(!r.startsWith("pk_"))throw new Error("Invalid public key");try{return JSON.parse(Buffer.from(r.replace("pk_",""),"base64").toString("utf-8"))}catch{throw new Error("Failed to parse public key")}};var n=r=>r?r.split(";").map(t=>{let[e,o]=t.trim().split("=");return{name:e,value:o}}):[];export{i as getPublicKeyPayload,n as parseCookies};
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/public-key.ts","../src/cookies.ts"],"sourcesContent":["export interface PublicKeyPayload {\n environmentId: string;\n identityHost: string;\n version?: string;\n region?: \"EU\" | \"US\";\n}\nexport const getPublicKeyPayload = (publicKey: string): PublicKeyPayload => {\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n if (!publicKey.startsWith(\"pk_\")) {\n throw new Error(\"Invalid public key\");\n }\n try {\n return JSON.parse(\n Buffer.from(publicKey.replace(\"pk_\", \"\"), \"base64\").toString(\"utf-8\"),\n );\n } catch (e) {\n throw new Error(\"Failed to parse public key\");\n }\n};\n","// Function to parse cookies from request\nexport const parseCookies = (cookieHeader: string | null) => {\n if (!cookieHeader) {\n return [];\n }\n\n return cookieHeader.split(\";\").map((cookie) => {\n const [name, value] = cookie.trim().split(\"=\");\n return { name, value };\n });\n};\n"],"mappings":"AAMO,IAAMA,EAAuBC,GAAwC,CAC1E,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,2BAA2B,EAE7C,GAAI,CAACA,EAAU,WAAW,KAAK,EAC7B,MAAM,IAAI,MAAM,oBAAoB,EAEtC,GAAI,CACF,OAAO,KAAK,MACV,OAAO,KAAKA,EAAU,QAAQ,MAAO,EAAE,EAAG,QAAQ,EAAE,SAAS,OAAO,CACtE,CACF,MAAY,CACV,MAAM,IAAI,MAAM,4BAA4B,CAC9C,CACF,ECnBO,IAAMC,EAAgBC,GACtBA,EAIEA,EAAa,MAAM,GAAG,EAAE,IAAKC,GAAW,CAC7C,GAAM,CAACC,EAAMC,CAAK,EAAIF,EAAO,KAAK,EAAE,MAAM,GAAG,EAC7C,MAAO,CAAE,KAAAC,EAAM,MAAAC,CAAM,CACvB,CAAC,EANQ,CAAC","names":["getPublicKeyPayload","publicKey","parseCookies","cookieHeader","cookie","name","value"]}
|