foundation-sdk 0.2.6 → 0.2.7
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/auth-auth0.cjs +1 -1
- package/dist/auth-auth0.cjs.map +1 -1
- package/dist/auth-auth0.d.cts +5 -1
- package/dist/auth-auth0.d.ts +5 -1
- package/dist/auth-auth0.js +1 -1
- package/dist/auth-auth0.js.map +1 -1
- package/dist/auth-cognito.cjs +1 -1
- package/dist/auth-cognito.cjs.map +1 -1
- package/dist/auth-cognito.d.cts +5 -1
- package/dist/auth-cognito.d.ts +5 -1
- package/dist/auth-cognito.js +1 -1
- package/dist/auth-cognito.js.map +1 -1
- package/dist/foundation-sdk.browser.auth0.global.js +1 -1
- package/dist/foundation-sdk.browser.auth0.global.js.map +1 -1
- package/dist/foundation-sdk.browser.global.js +1 -1
- package/dist/foundation-sdk.browser.global.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -201
- package/dist/index.d.ts +10 -201
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types-HdCjnyCt.d.cts +204 -0
- package/dist/types-HdCjnyCt.d.ts +204 -0
- package/package.json +3 -1
package/dist/auth-auth0.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var d=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var y=(n,t)=>{for(var r in t)d(n,r,{get:t[r],enumerable:!0})},m=(n,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of l(t))!f.call(n,o)&&o!==r&&d(n,o,{get:()=>t[o],enumerable:!(s=w(t,o))||s.enumerable});return n};var A=n=>m(d({},"__esModule",{value:!0}),n);var v={};y(v,{auth0Auth:()=>g});module.exports=A(v);var p=require("@auth0/auth0-spa-js");var P=new Map;function u(n,t){P.set(n,t)}u("none",async()=>({login:async()=>{},logout:async()=>{},getUser:async()=>{},getTokenSilently:async()=>"none",isAuthenticated:async()=>!0}));var g=async n=>{let t=n.auth0;if(!t)throw new Error("Auth0 config required");let r=await(0,p.createAuth0Client)({domain:t.domain,clientId:t.clientId,authorizationParams:{audience:t.audience,scope:t.scope||"openid profile email",redirect_uri:window.location.origin},useRefreshTokens:!0,cacheLocation:"localstorage"}),s=t.domain,o=t.clientId;return{login:e=>r.loginWithRedirect(e),logout:e=>r.logout({logoutParams:{returnTo:window.location.origin},...e}),getUser:async()=>{let e=await r.getUser();if(e)return{id:e.sub||"",email:e.email||"",name:e.name,picture:e.picture}},getTokenSilently:e=>r.getTokenSilently(e),isAuthenticated:()=>r.isAuthenticated(),async signIn(e,a){let i=await fetch(`https://${s}/oauth/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({grant_type:"password",client_id:o,username:e,password:a,audience:t.audience,scope:t.scope||"openid profile email"})});if(!i.ok){let c=await i.json().catch(()=>({}));throw new Error(c.error_description||c.message||"Sign in failed")}},async signUp(e,a,i){let c=await fetch(`https://${s}/dbconnections/signup`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:o,email:e,password:a,connection:"Username-Password-Authentication",...i})});if(!c.ok){let h=await c.json().catch(()=>({}));throw new Error(h.description||h.message||"Sign up failed")}},async forgotPassword(e){let a=await fetch(`https://${s}/dbconnections/change_password`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:o,email:e,connection:"Username-Password-Authentication"})});if(!a.ok){let i=await a.json().catch(()=>({}));throw new Error(i.error_description||i.message||"Password reset request failed")}},async resetPassword(){throw new Error("Auth0 password reset is completed via the email link, not a code")}}};u("auth0",g);0&&(module.exports={auth0Auth});
|
|
2
2
|
//# sourceMappingURL=auth-auth0.cjs.map
|
package/dist/auth-auth0.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/auth-auth0.ts","../src/auth.ts"],"sourcesContent":["import { createAuth0Client } from '@auth0/auth0-spa-js'\nimport { registerAuthProvider } from './auth'\nimport type { AuthClient } from './types'\n\
|
|
1
|
+
{"version":3,"sources":["../src/auth-auth0.ts","../src/auth.ts"],"sourcesContent":["import { createAuth0Client } from '@auth0/auth0-spa-js'\nimport { registerAuthProvider } from './auth'\nimport type { AuthClient } from './types'\n\n/** Auth0 auth provider factory — pass to createFoundation({ auth: auth0Auth }) or import to auto-register */\nexport const auth0Auth = async (config: Record<string, unknown>): Promise<AuthClient> => {\n const auth0 = config.auth0 as { domain: string; clientId: string; audience?: string; scope?: string }\n if (!auth0) throw new Error('Auth0 config required')\n\n const client = await createAuth0Client({\n domain: auth0.domain,\n clientId: auth0.clientId,\n authorizationParams: {\n audience: auth0.audience,\n scope: auth0.scope || 'openid profile email',\n redirect_uri: window.location.origin\n },\n useRefreshTokens: true,\n cacheLocation: 'localstorage'\n })\n\n const domain = auth0.domain\n const clientId = auth0.clientId\n\n return {\n login: (options) => client.loginWithRedirect(options),\n logout: (options) => client.logout({ logoutParams: { returnTo: window.location.origin }, ...options }),\n getUser: async () => {\n const user = await client.getUser()\n if (!user) return undefined\n return { id: user.sub || '', email: user.email || '', name: user.name, picture: user.picture }\n },\n getTokenSilently: (options) => client.getTokenSilently(options),\n isAuthenticated: () => client.isAuthenticated(),\n\n async signIn(email: string, password: string) {\n const response = await fetch(`https://${domain}/oauth/token`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n grant_type: 'password',\n client_id: clientId,\n username: email,\n password,\n audience: auth0.audience,\n scope: auth0.scope || 'openid profile email'\n })\n })\n if (!response.ok) {\n const err = await response.json().catch(() => ({}))\n throw new Error(err.error_description || err.message || 'Sign in failed')\n }\n },\n\n async signUp(email: string, password: string, metadata?: Record<string, unknown>) {\n const response = await fetch(`https://${domain}/dbconnections/signup`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n client_id: clientId,\n email,\n password,\n connection: 'Username-Password-Authentication',\n ...metadata\n })\n })\n if (!response.ok) {\n const err = await response.json().catch(() => ({}))\n throw new Error(err.description || err.message || 'Sign up failed')\n }\n },\n\n async forgotPassword(email: string) {\n const response = await fetch(`https://${domain}/dbconnections/change_password`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n client_id: clientId,\n email,\n connection: 'Username-Password-Authentication'\n })\n })\n if (!response.ok) {\n const err = await response.json().catch(() => ({}))\n throw new Error(err.error_description || err.message || 'Password reset request failed')\n }\n },\n\n async resetPassword() {\n throw new Error('Auth0 password reset is completed via the email link, not a code')\n }\n }\n}\n\n// Auto-register when imported\nregisterAuthProvider('auth0', auth0Auth)\n","/**\n * Auth core — provider registry and AuthService wrapper.\n * Provider implementations live in auth-auth0.ts and auth-cognito.ts.\n */\nimport type { AuthClient, AuthService, User } from './types'\n\nconst MAX_LISTENERS = 100\n\n// --- Provider registry ---\n\nconst providers = new Map<string, (config: Record<string, unknown>) => Promise<AuthClient>>()\n\nexport function registerAuthProvider(name: string, factory: (config: Record<string, unknown>) => Promise<AuthClient>) {\n providers.set(name, factory)\n}\n\n// Built-in \"none\" provider\nregisterAuthProvider('none', async () => ({\n login: async () => {},\n logout: async () => {},\n getUser: async () => undefined,\n getTokenSilently: async () => 'none',\n isAuthenticated: async () => true\n}))\n\nexport interface AuthProviderConfig {\n provider: string\n [key: string]: unknown\n}\n\nexport async function createAuthClient(config: AuthProviderConfig): Promise<AuthClient> {\n const factory = providers.get(config.provider)\n if (!factory) {\n throw new Error(\n `Auth provider \"${config.provider}\" not registered. ` +\n `Import \"foundation-sdk/${config.provider}\" to register it.`\n )\n }\n return factory(config)\n}\n\n// --- AuthService wrapper ---\n\nexport function createAuthService(client: AuthClient): AuthService & { _initUser(): Promise<void> } {\n let user: User | null = null\n const listeners: Array<(user: User | null) => void> = []\n\n function notifyListeners() {\n listeners.forEach(fn => { try { fn(user) } catch { /* */ } })\n }\n\n async function refreshUser() {\n const authUser = await client.getUser()\n user = authUser ? { id: authUser.id, email: authUser.email, name: authUser.name, picture: authUser.picture } : null\n }\n\n return {\n get user() { return user },\n get isAuthenticated() { return !!user },\n\n async getToken() {\n return client.getTokenSilently()\n },\n\n async login(options) {\n await client.login(options)\n await refreshUser()\n notifyListeners()\n },\n\n async logout(options) {\n await client.logout(options)\n user = null\n notifyListeners()\n },\n\n async signIn(email, password) {\n if (!client.signIn) throw new Error('signIn not supported by this auth provider')\n await client.signIn(email, password)\n await refreshUser()\n notifyListeners()\n },\n\n async signUp(email, password, metadata) {\n if (!client.signUp) throw new Error('signUp not supported by this auth provider')\n await client.signUp(email, password, metadata)\n },\n\n async forgotPassword(email) {\n if (!client.forgotPassword) throw new Error('forgotPassword not supported by this auth provider')\n await client.forgotPassword(email)\n },\n\n async resetPassword(code, newPassword) {\n if (!client.resetPassword) throw new Error('resetPassword not supported by this auth provider')\n await client.resetPassword(code, newPassword)\n },\n\n onChange(callback) {\n if (listeners.length >= MAX_LISTENERS) {\n console.warn('[Foundation SDK] Auth listener limit reached.')\n return () => {}\n }\n listeners.push(callback)\n return () => {\n const idx = listeners.indexOf(callback)\n if (idx > -1) listeners.splice(idx, 1)\n }\n },\n\n async _initUser() {\n const authenticated = await client.isAuthenticated()\n if (authenticated) await refreshUser()\n }\n }\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,eAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkC,+BCUlC,IAAMC,EAAY,IAAI,IAEf,SAASC,EAAqBC,EAAcC,EAAmE,CACpHH,EAAU,IAAIE,EAAMC,CAAO,CAC7B,CAGAF,EAAqB,OAAQ,UAAa,CACxC,MAAO,SAAY,CAAC,EACpB,OAAQ,SAAY,CAAC,EACrB,QAAS,SAAS,GAClB,iBAAkB,SAAY,OAC9B,gBAAiB,SAAY,EAC/B,EAAE,EDlBK,IAAMG,EAAY,MAAOC,GAAyD,CACvF,IAAMC,EAAQD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MAAM,WAAWN,CAAM,wBAAyB,CACrE,OAAQ,OACR,QAAS,CAAE,eAAgB,kBAAmB,EAC9C,KAAM,KAAK,UAAU,CACnB,UAAWC,EACX,MAAAG,EACA,SAAAC,EACA,WAAY,mCACZ,GAAGG,CACL,CAAC,CACH,CAAC,EACD,GAAI,CAACF,EAAS,GAAI,CAChB,IAAMC,EAAM,MAAMD,EAAS,KAAK,EAAE,MAAM,KAAO,CAAC,EAAE,EAClD,MAAM,IAAI,MAAMC,EAAI,aAAeA,EAAI,SAAW,gBAAgB,CACpE,CACF,EAEA,MAAM,eAAeH,EAAe,CAClC,IAAME,EAAW,MAAM,MAAM,WAAWN,CAAM,iCAAkC,CAC9E,OAAQ,OACR,QAAS,CAAE,eAAgB,kBAAmB,EAC9C,KAAM,KAAK,UAAU,CACnB,UAAWC,EACX,MAAAG,EACA,WAAY,kCACd,CAAC,CACH,CAAC,EACD,GAAI,CAACE,EAAS,GAAI,CAChB,IAAMC,EAAM,MAAMD,EAAS,KAAK,EAAE,MAAM,KAAO,CAAC,EAAE,EAClD,MAAM,IAAI,MAAMC,EAAI,mBAAqBA,EAAI,SAAW,+BAA+B,CACzF,CACF,EAEA,MAAM,eAAgB,CACpB,MAAM,IAAI,MAAM,kEAAkE,CACpF,CACF,CACF,EAGAE,EAAqB,QAASb,CAAS","names":["auth_auth0_exports","__export","auth0Auth","__toCommonJS","import_auth0_spa_js","providers","registerAuthProvider","name","factory","auth0Auth","config","auth0","client","domain","clientId","options","user","email","password","response","err","metadata","registerAuthProvider"]}
|
package/dist/auth-auth0.d.cts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
import { A as AuthClient } from './types-HdCjnyCt.cjs';
|
|
1
2
|
|
|
2
|
-
|
|
3
|
+
/** Auth0 auth provider factory — pass to createFoundation({ auth: auth0Auth }) or import to auto-register */
|
|
4
|
+
declare const auth0Auth: (config: Record<string, unknown>) => Promise<AuthClient>;
|
|
5
|
+
|
|
6
|
+
export { auth0Auth };
|
package/dist/auth-auth0.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
import { A as AuthClient } from './types-HdCjnyCt.js';
|
|
1
2
|
|
|
2
|
-
|
|
3
|
+
/** Auth0 auth provider factory — pass to createFoundation({ auth: auth0Auth }) or import to auto-register */
|
|
4
|
+
declare const auth0Auth: (config: Record<string, unknown>) => Promise<AuthClient>;
|
|
5
|
+
|
|
6
|
+
export { auth0Auth };
|
package/dist/auth-auth0.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createAuth0Client as p}from"@auth0/auth0-spa-js";var h=new Map;function d(s,
|
|
1
|
+
import{createAuth0Client as p}from"@auth0/auth0-spa-js";var h=new Map;function d(s,e){h.set(s,e)}d("none",async()=>({login:async()=>{},logout:async()=>{},getUser:async()=>{},getTokenSilently:async()=>"none",isAuthenticated:async()=>!0}));var g=async s=>{let e=s.auth0;if(!e)throw new Error("Auth0 config required");let o=await p({domain:e.domain,clientId:e.clientId,authorizationParams:{audience:e.audience,scope:e.scope||"openid profile email",redirect_uri:window.location.origin},useRefreshTokens:!0,cacheLocation:"localstorage"}),a=e.domain,c=e.clientId;return{login:t=>o.loginWithRedirect(t),logout:t=>o.logout({logoutParams:{returnTo:window.location.origin},...t}),getUser:async()=>{let t=await o.getUser();if(t)return{id:t.sub||"",email:t.email||"",name:t.name,picture:t.picture}},getTokenSilently:t=>o.getTokenSilently(t),isAuthenticated:()=>o.isAuthenticated(),async signIn(t,r){let n=await fetch(`https://${a}/oauth/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({grant_type:"password",client_id:c,username:t,password:r,audience:e.audience,scope:e.scope||"openid profile email"})});if(!n.ok){let i=await n.json().catch(()=>({}));throw new Error(i.error_description||i.message||"Sign in failed")}},async signUp(t,r,n){let i=await fetch(`https://${a}/dbconnections/signup`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:c,email:t,password:r,connection:"Username-Password-Authentication",...n})});if(!i.ok){let u=await i.json().catch(()=>({}));throw new Error(u.description||u.message||"Sign up failed")}},async forgotPassword(t){let r=await fetch(`https://${a}/dbconnections/change_password`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:c,email:t,connection:"Username-Password-Authentication"})});if(!r.ok){let n=await r.json().catch(()=>({}));throw new Error(n.error_description||n.message||"Password reset request failed")}},async resetPassword(){throw new Error("Auth0 password reset is completed via the email link, not a code")}}};d("auth0",g);export{g as auth0Auth};
|
|
2
2
|
//# sourceMappingURL=auth-auth0.js.map
|
package/dist/auth-auth0.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/auth-auth0.ts","../src/auth.ts"],"sourcesContent":["import { createAuth0Client } from '@auth0/auth0-spa-js'\nimport { registerAuthProvider } from './auth'\nimport type { AuthClient } from './types'\n\
|
|
1
|
+
{"version":3,"sources":["../src/auth-auth0.ts","../src/auth.ts"],"sourcesContent":["import { createAuth0Client } from '@auth0/auth0-spa-js'\nimport { registerAuthProvider } from './auth'\nimport type { AuthClient } from './types'\n\n/** Auth0 auth provider factory — pass to createFoundation({ auth: auth0Auth }) or import to auto-register */\nexport const auth0Auth = async (config: Record<string, unknown>): Promise<AuthClient> => {\n const auth0 = config.auth0 as { domain: string; clientId: string; audience?: string; scope?: string }\n if (!auth0) throw new Error('Auth0 config required')\n\n const client = await createAuth0Client({\n domain: auth0.domain,\n clientId: auth0.clientId,\n authorizationParams: {\n audience: auth0.audience,\n scope: auth0.scope || 'openid profile email',\n redirect_uri: window.location.origin\n },\n useRefreshTokens: true,\n cacheLocation: 'localstorage'\n })\n\n const domain = auth0.domain\n const clientId = auth0.clientId\n\n return {\n login: (options) => client.loginWithRedirect(options),\n logout: (options) => client.logout({ logoutParams: { returnTo: window.location.origin }, ...options }),\n getUser: async () => {\n const user = await client.getUser()\n if (!user) return undefined\n return { id: user.sub || '', email: user.email || '', name: user.name, picture: user.picture }\n },\n getTokenSilently: (options) => client.getTokenSilently(options),\n isAuthenticated: () => client.isAuthenticated(),\n\n async signIn(email: string, password: string) {\n const response = await fetch(`https://${domain}/oauth/token`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n grant_type: 'password',\n client_id: clientId,\n username: email,\n password,\n audience: auth0.audience,\n scope: auth0.scope || 'openid profile email'\n })\n })\n if (!response.ok) {\n const err = await response.json().catch(() => ({}))\n throw new Error(err.error_description || err.message || 'Sign in failed')\n }\n },\n\n async signUp(email: string, password: string, metadata?: Record<string, unknown>) {\n const response = await fetch(`https://${domain}/dbconnections/signup`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n client_id: clientId,\n email,\n password,\n connection: 'Username-Password-Authentication',\n ...metadata\n })\n })\n if (!response.ok) {\n const err = await response.json().catch(() => ({}))\n throw new Error(err.description || err.message || 'Sign up failed')\n }\n },\n\n async forgotPassword(email: string) {\n const response = await fetch(`https://${domain}/dbconnections/change_password`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n client_id: clientId,\n email,\n connection: 'Username-Password-Authentication'\n })\n })\n if (!response.ok) {\n const err = await response.json().catch(() => ({}))\n throw new Error(err.error_description || err.message || 'Password reset request failed')\n }\n },\n\n async resetPassword() {\n throw new Error('Auth0 password reset is completed via the email link, not a code')\n }\n }\n}\n\n// Auto-register when imported\nregisterAuthProvider('auth0', auth0Auth)\n","/**\n * Auth core — provider registry and AuthService wrapper.\n * Provider implementations live in auth-auth0.ts and auth-cognito.ts.\n */\nimport type { AuthClient, AuthService, User } from './types'\n\nconst MAX_LISTENERS = 100\n\n// --- Provider registry ---\n\nconst providers = new Map<string, (config: Record<string, unknown>) => Promise<AuthClient>>()\n\nexport function registerAuthProvider(name: string, factory: (config: Record<string, unknown>) => Promise<AuthClient>) {\n providers.set(name, factory)\n}\n\n// Built-in \"none\" provider\nregisterAuthProvider('none', async () => ({\n login: async () => {},\n logout: async () => {},\n getUser: async () => undefined,\n getTokenSilently: async () => 'none',\n isAuthenticated: async () => true\n}))\n\nexport interface AuthProviderConfig {\n provider: string\n [key: string]: unknown\n}\n\nexport async function createAuthClient(config: AuthProviderConfig): Promise<AuthClient> {\n const factory = providers.get(config.provider)\n if (!factory) {\n throw new Error(\n `Auth provider \"${config.provider}\" not registered. ` +\n `Import \"foundation-sdk/${config.provider}\" to register it.`\n )\n }\n return factory(config)\n}\n\n// --- AuthService wrapper ---\n\nexport function createAuthService(client: AuthClient): AuthService & { _initUser(): Promise<void> } {\n let user: User | null = null\n const listeners: Array<(user: User | null) => void> = []\n\n function notifyListeners() {\n listeners.forEach(fn => { try { fn(user) } catch { /* */ } })\n }\n\n async function refreshUser() {\n const authUser = await client.getUser()\n user = authUser ? { id: authUser.id, email: authUser.email, name: authUser.name, picture: authUser.picture } : null\n }\n\n return {\n get user() { return user },\n get isAuthenticated() { return !!user },\n\n async getToken() {\n return client.getTokenSilently()\n },\n\n async login(options) {\n await client.login(options)\n await refreshUser()\n notifyListeners()\n },\n\n async logout(options) {\n await client.logout(options)\n user = null\n notifyListeners()\n },\n\n async signIn(email, password) {\n if (!client.signIn) throw new Error('signIn not supported by this auth provider')\n await client.signIn(email, password)\n await refreshUser()\n notifyListeners()\n },\n\n async signUp(email, password, metadata) {\n if (!client.signUp) throw new Error('signUp not supported by this auth provider')\n await client.signUp(email, password, metadata)\n },\n\n async forgotPassword(email) {\n if (!client.forgotPassword) throw new Error('forgotPassword not supported by this auth provider')\n await client.forgotPassword(email)\n },\n\n async resetPassword(code, newPassword) {\n if (!client.resetPassword) throw new Error('resetPassword not supported by this auth provider')\n await client.resetPassword(code, newPassword)\n },\n\n onChange(callback) {\n if (listeners.length >= MAX_LISTENERS) {\n console.warn('[Foundation SDK] Auth listener limit reached.')\n return () => {}\n }\n listeners.push(callback)\n return () => {\n const idx = listeners.indexOf(callback)\n if (idx > -1) listeners.splice(idx, 1)\n }\n },\n\n async _initUser() {\n const authenticated = await client.isAuthenticated()\n if (auth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0Auth","config","auth0","client","createAuth0Client","domain","clientId","options","user","email","password","response","err","metadata","registerAuthProvider"]}
|
package/dist/auth-cognito.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var s=require("aws-amplify"),
|
|
1
|
+
"use strict";var s=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var p=(e,r)=>{for(var t in r)s(e,t,{get:r[t],enumerable:!0})},h=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of d(r))!w.call(e,i)&&i!==t&&s(e,i,{get:()=>r[i],enumerable:!(o=c(r,i))||o.enumerable});return e};var l=e=>h(s({},"__esModule",{value:!0}),e);var f={};p(f,{cognitoAuth:()=>g});module.exports=l(f);var u=require("aws-amplify"),n=require("aws-amplify/auth");var y=new Map;function a(e,r){y.set(e,r)}a("none",async()=>({login:async()=>{},logout:async()=>{},getUser:async()=>{},getTokenSilently:async()=>"none",isAuthenticated:async()=>!0}));var g=async e=>{let r=e.cognito;if(!r)throw new Error("Cognito config required");return u.Amplify.configure({Auth:{Cognito:{userPoolId:r.userPoolId,userPoolClientId:r.clientId,loginWith:{oauth:{domain:r.domain.replace("https://",""),scopes:(r.scope||"openid profile email").split(" "),redirectSignIn:[window.location.origin],redirectSignOut:[window.location.origin],responseType:"code"}}}}}),{login:async()=>{await(0,n.signInWithRedirect)()},logout:async()=>{await(0,n.signOut)()},getUser:async()=>{try{let t=await(0,n.getCurrentUser)();return{id:t.userId,email:t.signInDetails?.loginId||"",name:t.username}}catch{return}},getTokenSilently:async()=>{let o=(await(0,n.fetchAuthSession)()).tokens?.accessToken?.toString();if(!o)throw new Error("No token available");return o},isAuthenticated:async()=>{try{return await(0,n.getCurrentUser)(),!0}catch{return!1}},async signIn(t,o){await(0,n.signIn)({username:t,password:o})},async signUp(t,o,i){await(0,n.signUp)({username:t,password:o,options:{userAttributes:{email:t,...i}}})},async forgotPassword(t){await(0,n.resetPassword)({username:t})},async resetPassword(t,o){await(0,n.confirmResetPassword)({username:"",confirmationCode:t,newPassword:o})}}};a("cognito",g);0&&(module.exports={cognitoAuth});
|
|
2
2
|
//# sourceMappingURL=auth-cognito.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/auth-cognito.ts","../src/auth.ts"],"sourcesContent":["import { Amplify } from 'aws-amplify'\nimport {\n fetchAuthSession,\n signInWithRedirect,\n signOut,\n getCurrentUser,\n signIn as cognitoSignIn,\n signUp as cognitoSignUp,\n resetPassword as cognitoResetPassword,\n confirmResetPassword\n} from 'aws-amplify/auth'\nimport { registerAuthProvider } from './auth'\nimport type { AuthClient } from './types'\n\
|
|
1
|
+
{"version":3,"sources":["../src/auth-cognito.ts","../src/auth.ts"],"sourcesContent":["import { Amplify } from 'aws-amplify'\nimport {\n fetchAuthSession,\n signInWithRedirect,\n signOut,\n getCurrentUser,\n signIn as cognitoSignIn,\n signUp as cognitoSignUp,\n resetPassword as cognitoResetPassword,\n confirmResetPassword\n} from 'aws-amplify/auth'\nimport { registerAuthProvider } from './auth'\nimport type { AuthClient } from './types'\n\n/** Cognito auth provider factory — pass to createFoundation({ auth: cognitoAuth }) or import to auto-register */\nexport const cognitoAuth = async (config: Record<string, unknown>): Promise<AuthClient> => {\n const cognito = config.cognito as { userPoolId: string; clientId: string; region: string; domain: string; scope?: string }\n if (!cognito) throw new Error('Cognito config required')\n\n Amplify.configure({\n Auth: {\n Cognito: {\n userPoolId: cognito.userPoolId,\n userPoolClientId: cognito.clientId,\n loginWith: {\n oauth: {\n domain: cognito.domain.replace('https://', ''),\n scopes: (cognito.scope || 'openid profile email').split(' '),\n redirectSignIn: [window.location.origin],\n redirectSignOut: [window.location.origin],\n responseType: 'code'\n }\n }\n }\n }\n })\n\n return {\n login: async () => { await signInWithRedirect() },\n logout: async () => { await signOut() },\n getUser: async () => {\n try {\n const user = await getCurrentUser()\n return { id: user.userId, email: user.signInDetails?.loginId || '', name: user.username }\n } catch { return undefined }\n },\n getTokenSilently: async () => {\n const session = await fetchAuthSession()\n const token = session.tokens?.accessToken?.toString()\n if (!token) throw new Error('No token available')\n return token\n },\n isAuthenticated: async () => {\n try {\n await getCurrentUser()\n return true\n } catch { return false }\n },\n\n async signIn(email: string, password: string) {\n await cognitoSignIn({ username: email, password })\n },\n\n async signUp(email: string, password: string, metadata?: Record<string, unknown>) {\n await cognitoSignUp({\n username: email,\n password,\n options: { userAttributes: { email, ...metadata } }\n })\n },\n\n async forgotPassword(email: string) {\n await cognitoResetPassword({ username: email })\n },\n\n async resetPassword(code: string, newPassword: string) {\n await confirmResetPassword({ username: '', confirmationCode: code, newPassword })\n }\n }\n}\n\n// Auto-register when imported\nregisterAuthProvider('cognito', cognitoAuth)\n","/**\n * Auth core — provider registry and AuthService wrapper.\n * Provider implementations live in auth-auth0.ts and auth-cognito.ts.\n */\nimport type { AuthClient, AuthService, User } from './types'\n\nconst MAX_LISTENERS = 100\n\n// --- Provider registry ---\n\nconst providers = new Map<string, (config: Record<string, unknown>) => Promise<AuthClient>>()\n\nexport function registerAuthProvider(name: string, factory: (config: Record<string, unknown>) => Promise<AuthClient>) {\n providers.set(name, factory)\n}\n\n// Built-in \"none\" provider\nregisterAuthProvider('none', async () => ({\n login: async () => {},\n logout: async () => {},\n getUser: async () => undefined,\n getTokenSilently: async () => 'none',\n isAuthenticated: async () => true\n}))\n\nexport interface AuthProviderConfig {\n provider: string\n [key: string]: unknown\n}\n\nexport async function createAuthClient(config: AuthProviderConfig): Promise<AuthClient> {\n const factory = providers.get(config.provider)\n if (!factory) {\n throw new Error(\n `Auth provider \"${config.provider}\" not registered. ` +\n `Import \"foundation-sdk/${config.provider}\" to register it.`\n )\n }\n return factory(config)\n}\n\n// --- AuthService wrapper ---\n\nexport function createAuthService(client: AuthClient): AuthService & { _initUser(): Promise<void> } {\n let user: User | null = null\n const listeners: Array<(user: User | null) => void> = []\n\n function notifyListeners() {\n listeners.forEach(fn => { try { fn(user) } catch { /* */ } })\n }\n\n async function refreshUser() {\n const authUser = await client.getUser()\n user = authUser ? { id: authUser.id, email: authUser.email, name: authUser.name, picture: authUser.picture } : null\n }\n\n return {\n get user() { return user },\n get isAuthenticated() { return !!user },\n\n async getToken() {\n return client.getTokenSilently()\n },\n\n async login(options) {\n await client.login(options)\n await refreshUser()\n notifyListeners()\n },\n\n async logout(options) {\n await client.logout(options)\n user = null\n notifyListeners()\n },\n\n async signIn(email, password) {\n if (!client.signIn) throw new Error('signIn not supported by this auth provider')\n await client.signIn(email, password)\n await refreshUser()\n notifyListeners()\n },\n\n async signUp(email, password, metadata) {\n if (!client.signUp) throw new Error('signUp not supported by this auth provider')\n await client.signUp(email, password, metadata)\n },\n\n async forgotPassword(email) {\n if (!client.forgotPassword) throw new Error('forgotPassword not supported by this auth provider')\n await client.forgotPassword(email)\n },\n\n async resetPassword(code, newPassword) {\n if (!client.resetPassword) throw new Error('resetPassword not supported by this auth provider')\n await client.resetPassword(code, newPassword)\n },\n\n onChange(callback) {\n if (listeners.length >= MAX_LISTENERS) {\n console.warn('[Foundation SDK] Auth listener limit reached.')\n return () => {}\n }\n listeners.push(callback)\n return () => {\n const idx = listeners.indexOf(callback)\n if (idx > -1) listeners.splice(idx, 1)\n }\n },\n\n async _initUser() {\n const authenticated = await client.isAuthenticated()\n if (authenticated) await refreshUser()\n }\n }\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAwB,uBACxBC,EASO,4BCAP,IAAMC,EAAY,IAAI,IAEf,SAASC,EAAqBC,EAAcC,EAAmE,CACpHH,EAAU,IAAIE,EAAMC,CAAO,CAC7B,CAGAF,EAAqB,OAAQ,UAAa,CACxC,MAAO,SAAY,CAAC,EACpB,OAAQ,SAAY,CAAC,EACrB,QAAS,SAAS,GAClB,iBAAkB,SAAY,OAC9B,gBAAiB,SAAY,EAC/B,EAAE,EDRK,IAAMG,E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H,EAAe,CAClC,QAAM,EAAAK,eAAqB,CAAE,SAAUL,CAAM,CAAC,CAChD,EAEA,MAAM,cAAcM,EAAcC,EAAqB,CACrD,QAAM,wBAAqB,CAAE,SAAU,GAAI,iBAAkBD,EAAM,YAAAC,CAAY,CAAC,CAClF,CACF,CACF,EAGAC,EAAqB,UAAWb,CAAW","names":["auth_cognito_exports","__export","cognitoAuth","__toCommonJS","import_aws_amplify","import_auth","providers","registerAuthProvider","name","factory","cognitoAuth","config","cognito","user","token","email","password","cognitoSignIn","metadata","cognitoSignUp","cognitoResetPassword","code","newPassword","registerAuthProvider"]}
|
package/dist/auth-cognito.d.cts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
import { A as AuthClient } from './types-HdCjnyCt.cjs';
|
|
1
2
|
|
|
2
|
-
|
|
3
|
+
/** Cognito auth provider factory — pass to createFoundation({ auth: cognitoAuth }) or import to auto-register */
|
|
4
|
+
declare const cognitoAuth: (config: Record<string, unknown>) => Promise<AuthClient>;
|
|
5
|
+
|
|
6
|
+
export { cognitoAuth };
|
package/dist/auth-cognito.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
import { A as AuthClient } from './types-HdCjnyCt.js';
|
|
1
2
|
|
|
2
|
-
|
|
3
|
+
/** Cognito auth provider factory — pass to createFoundation({ auth: cognitoAuth }) or import to auto-register */
|
|
4
|
+
declare const cognitoAuth: (config: Record<string, unknown>) => Promise<AuthClient>;
|
|
5
|
+
|
|
6
|
+
export { cognitoAuth };
|
package/dist/auth-cognito.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Amplify as u}from"aws-amplify";import{fetchAuthSession as g,signInWithRedirect as c,signOut as d,getCurrentUser as
|
|
1
|
+
import{Amplify as u}from"aws-amplify";import{fetchAuthSession as g,signInWithRedirect as c,signOut as d,getCurrentUser as i,signIn as w,signUp as p,resetPassword as h,confirmResetPassword as l}from"aws-amplify/auth";var a=new Map;function o(e,n){a.set(e,n)}o("none",async()=>({login:async()=>{},logout:async()=>{},getUser:async()=>{},getTokenSilently:async()=>"none",isAuthenticated:async()=>!0}));var y=async e=>{let n=e.cognito;if(!n)throw new Error("Cognito config required");return u.configure({Auth:{Cognito:{userPoolId:n.userPoolId,userPoolClientId:n.clientId,loginWith:{oauth:{domain:n.domain.replace("https://",""),scopes:(n.scope||"openid profile email").split(" "),redirectSignIn:[window.location.origin],redirectSignOut:[window.location.origin],responseType:"code"}}}}}),{login:async()=>{await c()},logout:async()=>{await d()},getUser:async()=>{try{let t=await i();return{id:t.userId,email:t.signInDetails?.loginId||"",name:t.username}}catch{return}},getTokenSilently:async()=>{let r=(await g()).tokens?.accessToken?.toString();if(!r)throw new Error("No token available");return r},isAuthenticated:async()=>{try{return await i(),!0}catch{return!1}},async signIn(t,r){await w({username:t,password:r})},async signUp(t,r,s){await p({username:t,password:r,options:{userAttributes:{email:t,...s}}})},async forgotPassword(t){await h({username:t})},async resetPassword(t,r){await l({username:"",confirmationCode:t,newPassword:r})}}};o("cognito",y);export{y as cognitoAuth};
|
|
2
2
|
//# sourceMappingURL=auth-cognito.js.map
|
package/dist/auth-cognito.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/auth-cognito.ts","../src/auth.ts"],"sourcesContent":["import { Amplify } from 'aws-amplify'\nimport {\n fetchAuthSession,\n signInWithRedirect,\n signOut,\n getCurrentUser,\n signIn as cognitoSignIn,\n signUp as cognitoSignUp,\n resetPassword as cognitoResetPassword,\n confirmResetPassword\n} from 'aws-amplify/auth'\nimport { registerAuthProvider } from './auth'\nimport type { AuthClient } from './types'\n\
|
|
1
|
+
{"version":3,"sources":["../src/auth-cognito.ts","../src/auth.ts"],"sourcesContent":["import { Amplify } from 'aws-amplify'\nimport {\n fetchAuthSession,\n signInWithRedirect,\n signOut,\n getCurrentUser,\n signIn as cognitoSignIn,\n signUp as cognitoSignUp,\n resetPassword as cognitoResetPassword,\n confirmResetPassword\n} from 'aws-amplify/auth'\nimport { registerAuthProvider } from './auth'\nimport type { AuthClient } from './types'\n\n/** Cognito auth provider factory — pass to createFoundation({ auth: cognitoAuth }) or import to auto-register */\nexport const cognitoAuth = async (config: Record<string, unknown>): Promise<AuthClient> => {\n const cognito = config.cognito as { userPoolId: string; clientId: string; region: string; domain: string; scope?: string }\n if (!cognito) throw new Error('Cognito config required')\n\n Amplify.configure({\n Auth: {\n Cognito: {\n userPoolId: cognito.userPoolId,\n userPoolClientId: cognito.clientId,\n loginWith: {\n oauth: {\n domain: cognito.domain.replace('https://', ''),\n scopes: (cognito.scope || 'openid profile email').split(' '),\n redirectSignIn: [window.location.origin],\n redirectSignOut: [window.location.origin],\n responseType: 'code'\n }\n }\n }\n }\n })\n\n return {\n login: async () => { await signInWithRedirect() },\n logout: async () => { await signOut() },\n getUser: async () => {\n try {\n const user = await getCurrentUser()\n return { id: user.userId, email: user.signInDetails?.loginId || '', name: user.username }\n } catch { return undefined }\n },\n getTokenSilently: async () => {\n const session = await fetchAuthSession()\n const token = session.tokens?.accessToken?.toString()\n if (!token) throw new Error('No token available')\n return token\n },\n isAuthenticated: async () => {\n try {\n await getCurrentUser()\n return true\n } catch { return false }\n },\n\n async signIn(email: string, password: string) {\n await cognitoSignIn({ username: email, password })\n },\n\n async signUp(email: string, password: string, metadata?: Record<string, unknown>) {\n await cognitoSignUp({\n username: email,\n password,\n options: { userAttributes: { email, ...metadata } }\n })\n },\n\n async forgotPassword(email: string) {\n await cognitoResetPassword({ username: email })\n },\n\n async resetPassword(code: string, newPassword: string) {\n await confirmResetPassword({ username: '', confirmationCode: code, newPassword })\n }\n }\n}\n\n// Auto-register when imported\nregisterAuthProvider('cognito', cognitoAuth)\n","/**\n * Auth core — provider registry and AuthService wrapper.\n * Provider implementations live in auth-auth0.ts and auth-cognito.ts.\n */\nimport type { AuthClient, AuthService, User } from './types'\n\nconst MAX_LISTENERS = 100\n\n// --- Provider registry ---\n\nconst providers = new Map<string, (config: Record<string, unknown>) => Promise<AuthClient>>()\n\nexport function registerAuthProvider(name: string, factory: (config: Record<string, unknown>) => Promise<AuthClient>) {\n providers.set(name, factory)\n}\n\n// Built-in \"none\" provider\nregisterAuthProvider('none', async () => ({\n login: async () => {},\n logout: async () => {},\n getUser: async () => undefined,\n getTokenSilently: async () => 'none',\n isAuthenticated: async () => true\n}))\n\nexport interface AuthProviderConfig {\n provider: string\n [key: string]: unknown\n}\n\nexport async function createAuthClient(config: AuthProviderConfig): Promise<AuthClient> {\n const factory = providers.get(config.provider)\n if (!factory) {\n throw new Error(\n `Auth provider \"${config.provider}\" not registered. ` +\n `Import \"foundation-sdk/${config.provider}\" to register it.`\n )\n }\n return factory(config)\n}\n\n// --- AuthService wrapper ---\n\nexport function createAuthService(client: AuthClient): AuthService & { _initUser(): Promise<void> } {\n let user: User | null = null\n const listeners: Array<(user: User | null) => void> = []\n\n function notifyListeners() {\n listeners.forEach(fn => { try { fn(user) } catch { /* */ } })\n }\n\n async function refreshUser() {\n const authUser = await client.getUser()\n user = authUser ? { id: authUser.id, email: authUser.email, name: authUser.name, picture: authUser.picture } : null\n }\n\n return {\n get user() { return user },\n get isAuthenticated() { return !!user },\n\n async getToken() {\n return client.getTokenSilently()\n },\n\n async login(options) {\n await client.login(options)\n await refreshUser()\n notifyListeners()\n },\n\n async logout(options) {\n await client.logout(options)\n user = null\n notifyListeners()\n },\n\n async signIn(email, password) {\n if (!client.signIn) throw new Error('signIn not supported by this auth provider')\n await client.signIn(email, password)\n await refreshUser()\n notifyListeners()\n },\n\n async signUp(email, password, metadata) {\n if (!client.signUp) throw new Error('signUp not supported by this auth provider')\n await client.signUp(email, password, metadata)\n },\n\n async forgotPassword(email) {\n if (!client.forgotPassword) throw new Error('forgotPassword not supported by this auth provider')\n await client.forgotPassword(email)\n },\n\n async resetPassword(code, newPassword) {\n if (!client.resetPassword) throw new Error('resetPassword not supported by this auth provider')\n await client.resetPassword(code, newPassword)\n },\n\n onChange(callback) {\n if (listeners.length >= MAX_LISTENERS) {\n console.warn('[Foundation SDK] Auth listener limit reached.')\n return () => {}\n }\n listeners.push(callback)\n return () => {\n const idx = listeners.indexOf(callback)\n if (idx > -1) listeners.splice(idx, 1)\n }\n },\n\n async _initUser() {\n const authenticated = await client.isAuthenticated()\n if (authenticated) await refreshUser()\n }\n }\n}\n"],"mappings":"AAAA,OAAS,WAAAA,MAAe,cACxB,OACE,oBAAAC,EACA,sBAAAC,EACA,WAAAC,EACA,kBAAAC,EACA,UAAUC,EACV,UAAUC,EACV,iBAAiBC,EACjB,wBAAAC,MACK,mBCAP,IAAMC,EAAY,IAAI,IAEf,SAASC,EAAqBC,EAAcC,EAAmE,CACpHH,EAAU,IAAIE,EAAMC,CAAO,CAC7B,CAGAF,EAAqB,OAAQ,UAAa,CACxC,MAAO,SAAY,CAAC,EACpB,OAAQ,SAAY,CAAC,EACrB,QAAS,SAAS,GAClB,iBAAkB,SAAY,OAC9B,gBAAiB,SAAY,EAC/B,EAAE,EDRK,IAAMG,EAAc,MAAOC,GAAyD,CACzF,IAAMC,EAAUD,EAAO,QACvB,GAAI,CAACC,EAAS,MAAM,IAAI,MAAM,yBAAyB,EAEvD,OAAAC,EAAQ,UAAU,CAChB,KAAM,CACJ,QAAS,CACP,WAAYD,EAAQ,WACpB,iBAAkBA,EAAQ,SAC1B,UAAW,CACT,MAAO,CACL,OAAQA,EAAQ,OAAO,QAAQ,WAAY,EAAE,EAC7C,QAASA,EAAQ,OAAS,wBAAwB,MAAM,GAAG,EAC3D,eAAgB,CAAC,OAAO,SAAS,MAAM,EACvC,gBAAiB,CAAC,OAAO,SAAS,MAAM,EACxC,aAAc,MAChB,CACF,CACF,CACF,CACF,CAAC,EAEM,CACL,MAAO,SAAY,CAAE,MAAME,EAAmB,CAAE,EAChD,OAAQ,SAAY,CAAE,MAAMC,EAAQ,CAAE,EACtC,QAAS,SAAY,CACnB,GAAI,CACF,IAAMC,EAAO,MAAMC,EAAe,EAClC,MAAO,CAAE,GAAID,EAAK,OAAQ,MAAOA,EAAK,eAAe,SAAW,GAAI,KAAMA,EAAK,QAAS,CAC1F,MAAQ,CAAE,MAAiB,CAC7B,EACA,iBAAkB,SAAY,CAE5B,IAAME,GADU,MAAMC,EAAiB,GACjB,QAAQ,aAAa,SAAS,EACpD,GAAI,CAACD,EAAO,MAAM,IAAI,MAAM,oBAAoB,EAChD,OAAOA,CACT,EACA,gBAAiB,SAAY,CAC3B,GAAI,CACF,aAAMD,EAAe,EACd,EACT,MAAQ,CAAE,MAAO,EAAM,CACzB,EAEA,MAAM,OAAOG,EAAeC,EAAkB,CAC5C,MAAMC,EAAc,CAAE,SAAUF,EAAO,SAAAC,CAAS,CAAC,CACnD,EAEA,MAAM,OAAOD,EAAeC,EAAkBE,EAAoC,CAChF,MAAMC,EAAc,CAClB,SAAUJ,EACV,SAAAC,EACA,QAAS,CAAE,eAAgB,CAAE,MAAAD,EAAO,GAAGG,CAAS,CAAE,CACpD,CAAC,CACH,EAEA,MAAM,eAAeH,EAAe,CAClC,MAAMK,EAAqB,CAAE,SAAUL,CAAM,CAAC,CAChD,EAEA,MAAM,cAAcM,EAAcC,EAAqB,CACrD,MAAMC,EAAqB,CAAE,SAAU,GAAI,iBAAkBF,EAAM,YAAAC,CAAY,CAAC,CAClF,CACF,CACF,EAGAE,EAAqB,UAAWnB,CAAW","names":["Amplify","fetchAuthSession","signInWithRedirect","signOut","getCurrentUser","cognitoSignIn","cognitoSignUp","cognitoResetPassword","confirmResetPassword","providers","registerAuthProvider","name","factory","cognitoAuth","config","cognito","Amplify","signInWithRedirect","signOut","user","getCurrentUser","token","fetchAuthSession","email","password","cognitoSignIn","metadata","cognitoSignUp","cognitoResetPassword","code","newPassword","confirmResetPassword","registerAuthProvider"]}
|