@authdog/node-commons 0.0.19 → 0.0.21
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.mts +19 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +5 -3
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
declare const validateAndParsePublicKey: (publicKey: string) => any;
|
|
9
|
+
|
|
10
|
+
declare const parseCookies: (cookieHeader: string | null) => {
|
|
11
|
+
name: string;
|
|
12
|
+
value: string;
|
|
13
|
+
}[];
|
|
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
|
-
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")}},
|
|
1
|
+
"use strict";var n=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var y=(r,e)=>{for(var t in e)n(r,t,{get:e[t],enumerable:!0})},P=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of p(e))!d.call(r,i)&&i!==t&&n(r,i,{get:()=>e[i],enumerable:!(o=c(e,i))||o.enumerable});return r};var g=r=>P(n({},"__esModule",{value:!0}),r);var h={};y(h,{buildSessionKey:()=>u,fetchUserData:()=>f,getPublicKeyPayload:()=>s,parseCookies:()=>l,validateAndParsePublicKey:()=>a});module.exports=g(h);var s=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")}},a=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 l=r=>r?r.split(";").map(e=>{let[t,o]=e.trim().split("=");return{name:t,value:o}}):[];var u=r=>`user_session_${r}`;var f=async(r,e,t)=>{let o=await fetch(`${r}/oidc/${e}/userinfo`,{headers:{authorization:`Bearer ${t}`}});if(!o.ok)throw new Error("Failed to fetch user info");return o.json()};0&&(module.exports={buildSessionKey,fetchUserData,getPublicKeyPayload,parseCookies,validateAndParsePublicKey});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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\
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/public-key.ts","../src/cookies.ts","../src/session.ts","../src/identity.ts"],"sourcesContent":["export {\n getPublicKeyPayload,\n validateAndParsePublicKey,\n PublicKeyPayload,\n} from \"./public-key\";\nexport { parseCookies } from \"./cookies\";\nexport { buildSessionKey } from \"./session\";\nexport { fetchUserData } from \"./identity\";\n","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\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};\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};\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};\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,kBAAAC,EAAA,wBAAAC,EAAA,iBAAAC,EAAA,8BAAAC,IAAA,eAAAC,EAAAP,GCMO,IAAMQ,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,EAEaC,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,EClCO,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,GACvB,gBAAgBA,CAAa,GCD/B,IAAMC,EAAgB,MAC3BC,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,CACvB","names":["index_exports","__export","buildSessionKey","fetchUserData","getPublicKeyPayload","parseCookies","validateAndParsePublicKey","__toCommonJS","getPublicKeyPayload","publicKey","validateAndParsePublicKey","parseCookies","cookieHeader","cookie","name","value","buildSessionKey","environmentId","fetchUserData","identityHost","environmentId","token","userData"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
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
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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\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};\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};\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};\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,EAEaC,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,EClCO,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,GACvB,gBAAgBA,CAAa,GCD/B,IAAMC,EAAgB,MAC3BC,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,CACvB","names":["getPublicKeyPayload","publicKey","validateAndParsePublicKey","parseCookies","cookieHeader","cookie","name","value","buildSessionKey","environmentId","fetchUserData","identityHost","environmentId","token","userData"]}
|
package/package.json
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authdog/node-commons",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"description": "Authdog Next.js SDK",
|
|
5
|
-
"type": "module",
|
|
6
5
|
"source": "src/index.ts",
|
|
7
6
|
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/index.
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.js"
|
|
13
14
|
}
|
|
14
15
|
},
|
|
15
16
|
"files": [
|
|
16
17
|
"dist/"
|
|
17
18
|
],
|
|
18
19
|
"devDependencies": {
|
|
20
|
+
"@types/node": "^22.14.1",
|
|
19
21
|
"dotenv": "^16.4.7",
|
|
20
22
|
"prettier": "^3.4.2",
|
|
21
23
|
"tsup": "^8.3.5",
|