@dropins/storefront-auth 2.2.0-alpha002 → 2.2.0-alpha003
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/api.js +2 -2
- package/api.js.map +1 -1
- package/package.json +1 -1
package/api.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{c as A,a as O,g as v}from"./chunks/createCustomerAddress.js";import{g as M,a as
|
|
3
|
+
import{c as A,a as O,g as v}from"./chunks/createCustomerAddress.js";import{g as M,a as U}from"./chunks/getCustomerToken.js";import{g as w,v as I}from"./chunks/verifyToken.js";import{r as b}from"./chunks/requestPasswordResetEmail.js";import{r as q}from"./chunks/resetPassword.js";import{r as N}from"./chunks/revokeCustomerToken.js";import{c as D}from"./chunks/confirmEmail.js";import{r as B}from"./chunks/resendConfirmationEmail.js";import{f as m}from"./chunks/network-error.js";import{g as K,r as V,a as W,s as X,b as Y}from"./chunks/network-error.js";import{c as $,i as ee}from"./chunks/initialize.js";import"./fragments.js";import"./chunks/setReCaptchaToken.js";import"@dropins/tools/recaptcha.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/lib.js";import"./chunks/transform-attributes-form.js";import"./chunks/acdl.js";import"@dropins/tools/fetch-graphql.js";const c=`
|
|
4
4
|
query GET_CUSTOMER_ROLE_PERMISSIONS {
|
|
5
5
|
customer {
|
|
6
6
|
role {
|
|
@@ -33,5 +33,5 @@ import{c as A,a as O,g as v}from"./chunks/createCustomerAddress.js";import{g as
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
`;let
|
|
36
|
+
`;let i=null,o=null;const p=e=>{const t={},r=s=>{s.forEach(n=>{var a;t[n.text]=!0,(a=n.children)!=null&&a.length&&r(n.children)})};return r(e),t},l=e=>(e==null?void 0:e.id)==="MA=="&&Array.isArray(e.permissions)&&e.permissions.length===0,d=e=>{var r;if(l(e))return{admin:!0};const t={all:!0};if((r=e==null?void 0:e.permissions)!=null&&r.length){const s=p(e.permissions);return{...t,...s}}return t},f=async()=>{var e,t;try{const r=await m(c,{method:"GET"}),s=d((t=(e=r.data)==null?void 0:e.customer)==null?void 0:t.role);return i=s,o=null,s}catch(r){throw o=null,r}},S=()=>i?Promise.resolve(i):(o||(o=f()),o),_=()=>{i=null,o=null};export{_ as __clearCacheForTesting,$ as config,D as confirmEmail,A as createCustomer,O as createCustomerAddress,m as fetchGraphQl,v as getAttributesForm,K as getConfig,M as getCustomerData,S as getCustomerRolePermissions,U as getCustomerToken,w as getStoreConfig,ee as initialize,V as removeFetchGraphQlHeader,b as requestPasswordResetEmail,B as resendConfirmationEmail,q as resetPassword,N as revokeCustomerToken,W as setEndpoint,X as setFetchGraphQlHeader,Y as setFetchGraphQlHeaders,I as verifyToken};
|
|
37
37
|
//# sourceMappingURL=api.js.map
|
package/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sources":["/@dropins/storefront-auth/src/api/getCustomerRolePermissions/graphql/getCustomerRolePermissions.graphql.ts","/@dropins/storefront-auth/src/api/getCustomerRolePermissions/getCustomerRolePermissions.ts"],"sourcesContent":["export const GET_CUSTOMER_ROLE_PERMISSIONS = `\n query GET_CUSTOMER_ROLE_PERMISSIONS {\n customer {\n role {\n id\n name\n permissions {\n id\n text\n children {\n id\n text\n children {\n id\n text\n children {\n id\n text\n children {\n id\n text\n children {\n id\n text\n }\n }\n }\n }\n }\n }\n }\n }\n }\n`;\n","/********************************************************************\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: Adobe permits you to use, modify, and distribute this \n * file in accordance with the terms of the Adobe license agreement \n * accompanying it. \n *******************************************************************/\n\nimport { fetchGraphQl } from \"@/auth/api/fetch-graphql\";\nimport { GET_CUSTOMER_ROLE_PERMISSIONS } from \"./graphql/getCustomerRolePermissions.graphql\";\n\n// TypeScript interfaces\ninterface Permission {\n id: string;\n text: string;\n children?: Permission[];\n}\n\ninterface Role {\n id: string;\n name: string;\n permissions?: Permission[];\n}\n\ninterface GetCustomerRolePermissionsResponse {\n data?: {\n customer?: {\n role?: Role;\n };\n };\n errors?: {\n message: string;\n }[];\n}\n\ninterface FlattenedPermissions {\n all?: boolean;\n admin?: boolean;\n [key: string]: boolean | undefined;\n}\n\n// Module-level cache\nlet permissionsCache: FlattenedPermissions | null = null;\nlet fetchPromise: Promise<FlattenedPermissions> | null = null;\n\n/**\n * Recursively flattens permission tree into a flat object\n */\nconst flattenPermissionTree = (permissions: Permission[]): Record<string, boolean> => {\n const flattened: Record<string, boolean> = {};\n\n const processPermissions = (perms: Permission[]): void => {\n perms.forEach(permission => {\n flattened[permission.text] = true;\n if (permission.children?.length) {\n processPermissions(permission.children);\n }\n });\n };\n\n processPermissions(permissions);\n return flattened;\n};\n\n/**\n * Determines if user has admin privileges\n * Admin is only when user has role ID 'MA==' AND has an empty permissions array\n */\nconst isAdminUser = (role?: Role): boolean => {\n return role?.id === 'MA==' &&\n Array.isArray(role.permissions) &&\n role.permissions.length === 0;\n};\n\n/**\n * Processes role data into flattened permissions\n */\nconst processUserPermissions = (role?: Role): FlattenedPermissions => {\n if (isAdminUser(role)) {\n return { admin: true };\n }\n\n const basePermissions: FlattenedPermissions = { all: true };\n \n if (role?.permissions?.length) {\n const flattenedPerms = flattenPermissionTree(role.permissions);\n return { ...basePermissions, ...flattenedPerms };\n }\n\n return basePermissions;\n};\n\n/**\n * Fetches user role permissions from GraphQL API\n */\nconst fetchUserRolePermissions = async (): Promise<FlattenedPermissions> => {\n try {\n const response = await fetchGraphQl(GET_CUSTOMER_ROLE_PERMISSIONS, {\n method: 'GET'\n }) as GetCustomerRolePermissionsResponse;\n\n
|
|
1
|
+
{"version":3,"file":"api.js","sources":["/@dropins/storefront-auth/src/api/getCustomerRolePermissions/graphql/getCustomerRolePermissions.graphql.ts","/@dropins/storefront-auth/src/api/getCustomerRolePermissions/getCustomerRolePermissions.ts"],"sourcesContent":["export const GET_CUSTOMER_ROLE_PERMISSIONS = `\n query GET_CUSTOMER_ROLE_PERMISSIONS {\n customer {\n role {\n id\n name\n permissions {\n id\n text\n children {\n id\n text\n children {\n id\n text\n children {\n id\n text\n children {\n id\n text\n children {\n id\n text\n }\n }\n }\n }\n }\n }\n }\n }\n }\n`;\n","/********************************************************************\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: Adobe permits you to use, modify, and distribute this \n * file in accordance with the terms of the Adobe license agreement \n * accompanying it. \n *******************************************************************/\n\nimport { fetchGraphQl } from \"@/auth/api/fetch-graphql\";\nimport { GET_CUSTOMER_ROLE_PERMISSIONS } from \"./graphql/getCustomerRolePermissions.graphql\";\n\n// TypeScript interfaces\ninterface Permission {\n id: string;\n text: string;\n children?: Permission[];\n}\n\ninterface Role {\n id: string;\n name: string;\n permissions?: Permission[];\n}\n\ninterface GetCustomerRolePermissionsResponse {\n data?: {\n customer?: {\n role?: Role;\n };\n };\n errors?: {\n message: string;\n }[];\n}\n\ninterface FlattenedPermissions {\n all?: boolean;\n admin?: boolean;\n [key: string]: boolean | undefined;\n}\n\n// Module-level cache\nlet permissionsCache: FlattenedPermissions | null = null;\nlet fetchPromise: Promise<FlattenedPermissions> | null = null;\n\n/**\n * Recursively flattens permission tree into a flat object\n */\nconst flattenPermissionTree = (permissions: Permission[]): Record<string, boolean> => {\n const flattened: Record<string, boolean> = {};\n\n const processPermissions = (perms: Permission[]): void => {\n perms.forEach(permission => {\n flattened[permission.text] = true;\n if (permission.children?.length) {\n processPermissions(permission.children);\n }\n });\n };\n\n processPermissions(permissions);\n return flattened;\n};\n\n/**\n * Determines if user has admin privileges\n * Admin is only when user has role ID 'MA==' AND has an empty permissions array\n */\nconst isAdminUser = (role?: Role): boolean => {\n return role?.id === 'MA==' &&\n Array.isArray(role.permissions) &&\n role.permissions.length === 0;\n};\n\n/**\n * Processes role data into flattened permissions\n */\nconst processUserPermissions = (role?: Role): FlattenedPermissions => {\n if (isAdminUser(role)) {\n return { admin: true };\n }\n\n const basePermissions: FlattenedPermissions = { all: true };\n \n if (role?.permissions?.length) {\n const flattenedPerms = flattenPermissionTree(role.permissions);\n return { ...basePermissions, ...flattenedPerms };\n }\n\n return basePermissions;\n};\n\n/**\n * Fetches user role permissions from GraphQL API\n */\nconst fetchUserRolePermissions = async (): Promise<FlattenedPermissions> => {\n try {\n const response = await fetchGraphQl(GET_CUSTOMER_ROLE_PERMISSIONS, {\n method: 'GET'\n }) as GetCustomerRolePermissionsResponse;\n\n const permissions = processUserPermissions(response.data?.customer?.role);\n\n // Update cache\n permissionsCache = permissions;\n fetchPromise = null;\n\n return permissions;\n } catch (error) {\n fetchPromise = null;\n throw error;\n }\n};\n\n/**\n * Gets user role permissions with caching\n */\nexport const getCustomerRolePermissions = (): Promise<FlattenedPermissions> => {\n // Return cached data as resolved promise if available\n if (permissionsCache) {\n return Promise.resolve(permissionsCache);\n }\n\n // No cache available - create and return fetch promise if not already fetching\n if (!fetchPromise) {\n fetchPromise = fetchUserRolePermissions();\n }\n\n return fetchPromise;\n};\n\n/**\n * Clears the permissions cache - for testing purposes\n * @internal\n */\nexport const __clearCacheForTesting = (): void => {\n permissionsCache = null;\n fetchPromise = null;\n};\n"],"names":["GET_CUSTOMER_ROLE_PERMISSIONS","permissionsCache","fetchPromise","flattenPermissionTree","permissions","flattened","processPermissions","perms","permission","_a","isAdminUser","role","processUserPermissions","basePermissions","flattenedPerms","fetchUserRolePermissions","response","fetchGraphQl","_b","error","getCustomerRolePermissions","__clearCacheForTesting"],"mappings":"62BAAO,MAAMA,EAAgC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EC2C7C,IAAIC,EAAgD,KAChDC,EAAqD,KAKzD,MAAMC,EAAyBC,GAAuD,CACpF,MAAMC,EAAqC,CAAA,EAErCC,EAAsBC,GAA8B,CACxDA,EAAM,QAAQC,GAAc,OAC1BH,EAAUG,EAAW,IAAI,EAAI,IACzBC,EAAAD,EAAW,WAAX,MAAAC,EAAqB,QACvBH,EAAmBE,EAAW,QAAQ,CAE1C,CAAC,CACH,EAEA,OAAAF,EAAmBF,CAAW,EACvBC,CACT,EAMMK,EAAeC,IACZA,GAAA,YAAAA,EAAM,MAAO,QAClB,MAAM,QAAQA,EAAK,WAAW,GAC9BA,EAAK,YAAY,SAAW,EAM1BC,EAA0BD,GAAsC,OACpE,GAAID,EAAYC,CAAI,EAClB,MAAO,CAAE,MAAO,EAAA,EAGlB,MAAME,EAAwC,CAAE,IAAK,EAAA,EAErD,IAAIJ,EAAAE,GAAA,YAAAA,EAAM,cAAN,MAAAF,EAAmB,OAAQ,CAC7B,MAAMK,EAAiBX,EAAsBQ,EAAK,WAAW,EAC7D,MAAO,CAAE,GAAGE,EAAiB,GAAGC,CAAA,CAClC,CAEA,OAAOD,CACT,EAKME,EAA2B,SAA2C,SAC1E,GAAI,CACF,MAAMC,EAAW,MAAMC,EAAajB,EAA+B,CACjE,OAAQ,KAAA,CACT,EAEKI,EAAcQ,GAAuBM,GAAAT,EAAAO,EAAS,OAAT,YAAAP,EAAe,WAAf,YAAAS,EAAyB,IAAI,EAGxE,OAAAjB,EAAmBG,EACnBF,EAAe,KAERE,CACT,OAASe,EAAO,CACd,MAAAjB,EAAe,KACTiB,CACR,CACF,EAKaC,EAA6B,IAEpCnB,EACK,QAAQ,QAAQA,CAAgB,GAIpCC,IACHA,EAAea,EAAA,GAGVb,GAOImB,EAAyB,IAAY,CAChDpB,EAAmB,KACnBC,EAAe,IACjB"}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name": "@dropins/storefront-auth", "version": "2.2.0-
|
|
1
|
+
{"name": "@dropins/storefront-auth", "version": "2.2.0-alpha003", "@dropins/tools": "1.4.1-alpha009", "license": "SEE LICENSE IN LICENSE.md"}
|