@timardex/cluemart-shared 2.1.8 → 2.2.0
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/index.cjs +50 -0
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.mts +19 -2
- package/dist/auth/index.d.ts +19 -2
- package/dist/auth/index.mjs +44 -0
- package/dist/auth/index.mjs.map +1 -1
- package/dist/hooks/index.cjs +20 -4
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.mjs +20 -4
- package/dist/hooks/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/auth/index.mjs
CHANGED
|
@@ -67,6 +67,44 @@ function createAuthManager() {
|
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
// src/auth/interests.ts
|
|
71
|
+
var INTEREST_LABEL_OVERRIDES = {
|
|
72
|
+
["vendor" /* VENDOR */]: "Stallholder"
|
|
73
|
+
};
|
|
74
|
+
var interestOptions = [
|
|
75
|
+
"event" /* EVENT */,
|
|
76
|
+
"vendor" /* VENDOR */,
|
|
77
|
+
"partner" /* PARTNER */,
|
|
78
|
+
"visitor" /* VISITOR */
|
|
79
|
+
].map((value) => ({
|
|
80
|
+
label: INTEREST_LABEL_OVERRIDES[value] ?? value.charAt(0).toUpperCase() + value.slice(1),
|
|
81
|
+
value
|
|
82
|
+
}));
|
|
83
|
+
var PROFILE_DASHBOARDS_PATH = "Profile \u2192 Dashboards \u2192 ";
|
|
84
|
+
var INSTRUCTION_MIDDLE = ", then tap ";
|
|
85
|
+
var INSTRUCTION_AFTER = " and fill in your details.";
|
|
86
|
+
var INTEREST_INSTRUCTIONS = [
|
|
87
|
+
{
|
|
88
|
+
action: "Create Stallholder",
|
|
89
|
+
before: "To create your Stallholder profile, go to ",
|
|
90
|
+
dashboard: "Stallholder Dashboard",
|
|
91
|
+
interest: "vendor" /* VENDOR */
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
action: "Create Event",
|
|
95
|
+
before: "To create your Event profile, go to ",
|
|
96
|
+
dashboard: "Event Dashboard",
|
|
97
|
+
interest: "event" /* EVENT */
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
action: "Create Partner",
|
|
101
|
+
before: "To create your Partner profile, go to ",
|
|
102
|
+
dashboard: "Partner Dashboard",
|
|
103
|
+
interest: "partner" /* PARTNER */
|
|
104
|
+
}
|
|
105
|
+
];
|
|
106
|
+
var getInterestInstructions = (interests = []) => INTEREST_INSTRUCTIONS.filter(({ interest }) => interests.includes(interest));
|
|
107
|
+
|
|
70
108
|
// src/auth/licenceUtils.ts
|
|
71
109
|
function isLicencedResourceType(resourceType) {
|
|
72
110
|
return resourceType !== "affiliate" /* AFFILIATE */ && resourceType !== "school" /* SCHOOL */;
|
|
@@ -341,8 +379,12 @@ export {
|
|
|
341
379
|
ADMIN_APP_ROLES,
|
|
342
380
|
ADMIN_DASHBOARD_CONTEXTS,
|
|
343
381
|
DEFAULT_LIMITS,
|
|
382
|
+
INSTRUCTION_AFTER,
|
|
383
|
+
INSTRUCTION_MIDDLE,
|
|
384
|
+
INTEREST_INSTRUCTIONS,
|
|
344
385
|
NO_LICENCE_FLAGS,
|
|
345
386
|
PERMISSIONS,
|
|
387
|
+
PROFILE_DASHBOARDS_PATH,
|
|
346
388
|
ROLE_PERMISSIONS,
|
|
347
389
|
UserProvider,
|
|
348
390
|
WILDCARD_PERMISSION,
|
|
@@ -350,6 +392,7 @@ export {
|
|
|
350
392
|
canAccessAdminPath,
|
|
351
393
|
createAuthManager,
|
|
352
394
|
getDefaultAdminHome,
|
|
395
|
+
getInterestInstructions,
|
|
353
396
|
getLicenceFlagsByRole,
|
|
354
397
|
getPermissionsForRoles,
|
|
355
398
|
getUsableAdminContexts,
|
|
@@ -360,6 +403,7 @@ export {
|
|
|
360
403
|
hasPermission,
|
|
361
404
|
hasRole,
|
|
362
405
|
hasUserLicenceType,
|
|
406
|
+
interestOptions,
|
|
363
407
|
isLicencedResourceType,
|
|
364
408
|
isProfileBadgeLicence,
|
|
365
409
|
permissionListIncludes,
|
package/dist/auth/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/createAuthManager.ts","../../src/auth/licenceUtils.ts","../../src/auth/useAuthCore.ts"],"sourcesContent":["export type AuthManager = {\n logout: () => Promise<void>;\n setLogout: (fn: () => Promise<void>) => void;\n handleRefetchUser: () => Promise<void>;\n setUserRefetch: (fn: () => Promise<void>) => void;\n};\n\n/**\n * Creates an auth manager used by Apollo error links to trigger logout/refetch\n * without importing React. Matches the former mobile authManager shape.\n *\n * `logout()` dedupes concurrent calls via an in-flight promise so token-refresh\n * failures do not kick off multiple logout sequences.\n */\nexport function createAuthManager(): AuthManager {\n let logoutFn: (() => Promise<void>) | null = null;\n let userRefetchFn: (() => Promise<void>) | null = null;\n let logoutPromise: Promise<void> | null = null;\n\n return {\n handleRefetchUser: async () => {\n if (userRefetchFn) {\n await userRefetchFn();\n } else {\n console.warn(\"❌ User refetch function not set!\");\n }\n },\n logout(): Promise<void> {\n if (logoutPromise !== null) return logoutPromise;\n if (logoutFn === null) {\n console.warn(\"❌ Logout function not set!\");\n return Promise.resolve();\n }\n logoutPromise = logoutFn().finally(() => {\n logoutPromise = null;\n });\n return logoutPromise;\n },\n setLogout(fn: () => Promise<void>) {\n logoutFn = fn;\n },\n setUserRefetch(fn: () => Promise<void>) {\n userRefetchFn = fn;\n },\n };\n}\n","/* eslint-disable camelcase */\nimport { EnumResourceType, EnumUserLicence } from \"../enums\";\nimport type { SafeUserType } from \"../types\";\nimport { TIERS_BY_PRIORITY, type Tier } from \"../types/subscription\";\n\nimport type {\n HasLicenceResult,\n LicencedResourceType,\n LicencesByRole,\n LimitType,\n ProfileBadgeLicence,\n RoleLicences,\n} from \"./types\";\n\nexport function isLicencedResourceType(\n resourceType: EnumResourceType,\n): resourceType is LicencedResourceType {\n return (\n resourceType !== EnumResourceType.AFFILIATE &&\n resourceType !== EnumResourceType.SCHOOL\n );\n}\n\nexport function isProfileBadgeLicence(\n licenceType: EnumUserLicence,\n): licenceType is ProfileBadgeLicence {\n return (\n licenceType !== EnumUserLicence.STANDARD_AFFILIATE &&\n licenceType !== EnumUserLicence.STANDARD_SCHOOL\n );\n}\n\nexport const hasUserLicenceType = (\n authUser: SafeUserType | null,\n licenceType: EnumUserLicence,\n): boolean =>\n authUser?.licences?.some((licence) => licence.licenceType === licenceType) ??\n false;\n\nexport const hasLicence = (\n authUser: SafeUserType | null,\n licenceType: \"vendor\" | \"partner\" | \"event\",\n): HasLicenceResult => {\n const directLicence =\n authUser?.licences?.some((licence) =>\n licence.licenceType?.includes(licenceType),\n ) ?? false;\n\n return {\n directLicence,\n };\n};\n\n/** Default limits per subscription tier. */\nexport const DEFAULT_LIMITS: Record<LimitType, Record<Tier, number>> = {\n // 1 means calendar/productMenu is enabled, 0 means disabled\n availability: { pro: 1, pro_plus: 1, standard: 0 },\n calendar: { pro: 1, pro_plus: 1, standard: 0 },\n coupons: { pro: 1, pro_plus: 1, standard: 0 },\n images: { pro: 12, pro_plus: 12, standard: 6 },\n posters: { pro: 5, pro_plus: 5, standard: 5 },\n productsList: { pro: 1, pro_plus: 1, standard: 0 },\n relationShare: { pro: 1, pro_plus: 1, standard: 0 },\n statistics: { pro: 1, pro_plus: 1, standard: 0 },\n};\n\n/** All tiers off — used when the viewer does not own the resource. */\nexport const NO_LICENCE_FLAGS: LicencesByRole = {\n event: {\n pro_plus: false,\n // eslint-disable-next-line sort-keys\n pro: false,\n standard: false,\n },\n partner: {\n pro_plus: false,\n // eslint-disable-next-line sort-keys\n pro: false,\n standard: false,\n },\n vendor: {\n pro_plus: false,\n // eslint-disable-next-line sort-keys\n pro: false,\n standard: false,\n },\n};\n\n/**\n * Parses an array of licence strings into structured, role-based licences.\n * Users with no licences yet default to pro (create / trial access).\n */\nexport function getLicenceFlagsByRole(licences?: string[]): LicencesByRole {\n const normalized = licences?.map((l) => l.toLowerCase()) ?? [];\n const hasAnyLicence = normalized.length > 0;\n\n function resolve(role: EnumResourceType): RoleLicences {\n const result: RoleLicences = {\n pro_plus: false,\n // eslint-disable-next-line sort-keys\n pro: false,\n standard: false,\n };\n\n for (const tier of TIERS_BY_PRIORITY) {\n if (normalized.some((l) => l.startsWith(`${tier}_${role}`))) {\n result[tier] = true;\n break; // stop at first match → ensures mutual exclusivity\n }\n }\n\n // No licences at all → grant pro so new users can use pro features\n if (!hasAnyLicence) {\n result.pro = true;\n }\n\n return result;\n }\n\n return {\n event: resolve(EnumResourceType.EVENT),\n partner: resolve(EnumResourceType.PARTNER),\n vendor: resolve(EnumResourceType.VENDOR),\n };\n}\n","import { useCallback, useEffect, useMemo, useState } from \"react\";\n\nimport { EnumResourceType, EnumUserLicence, EnumUserRole } from \"../enums\";\nimport { useLogout } from \"../graphql/hooks/auth\";\nimport { useGetUser } from \"../graphql/hooks/user/hooksQuery\";\nimport { USER_STORAGE_KEY } from \"../storage\";\nimport type { SafeUserType } from \"../types\";\n\nimport {\n DEFAULT_LIMITS,\n getLicenceFlagsByRole,\n hasLicence,\n hasUserLicenceType,\n isLicencedResourceType,\n NO_LICENCE_FLAGS,\n} from \"./licenceUtils\";\nimport {\n getPermissionsForRoles,\n hasRole as roleHasRole,\n permissionListIncludes,\n} from \"./permissions\";\nimport type { Permission } from \"./permissions\";\nimport type {\n LimitType,\n LogoutReason,\n UseAuthCoreAdapters,\n UseAuthReturnType,\n} from \"./types\";\n\n/**\n * Platform-agnostic auth session core (source of truth for shared useAuth).\n *\n * Owns: persisted user load/set, refetch, role/licence flags, logout orchestration.\n * Does not own: AsyncStorage vs localStorage, Expo/Next navigation, toasts,\n * Apollo/WS reset, Firebase — those stay in each app's adapter wrapper.\n */\nexport function useAuthCore(adapters: UseAuthCoreAdapters): UseAuthReturnType {\n const {\n storage,\n authManager,\n afterLogout,\n shouldCallLogoutMutation = () => true,\n notifyLogoutSuccess,\n notifySessionExpired,\n onError,\n } = adapters;\n\n const [authUser, setAuthUser] = useState<SafeUserType | null>(null);\n const [isLoading, setIsLoading] = useState(true);\n\n const userId = useMemo(() => authUser?._id ?? \"\", [authUser?._id]);\n const { refetch } = useGetUser(userId);\n const { logout, loading } = useLogout();\n\n const handleSetAuthUser = useCallback(\n async (user: SafeUserType | null) => {\n setAuthUser(user);\n if (user) {\n await storage.setItem(USER_STORAGE_KEY, JSON.stringify(user));\n } else {\n await storage.removeItem(USER_STORAGE_KEY);\n }\n },\n [storage],\n );\n\n const handleRefetchUser = useCallback(async () => {\n if (!authUser) return;\n try {\n const result = await refetch();\n if (!result) return;\n const { data } = result;\n if (data?.user) await handleSetAuthUser(data.user);\n } catch (error: unknown) {\n onError?.(error, { action: \"refetchUser\" });\n console.warn(\n \"Failed to refetch user:\",\n error instanceof Error ? error.message : error,\n );\n }\n }, [authUser, handleSetAuthUser, onError, refetch]);\n\n const licences = useCallback(\n (resourceId: string) => {\n const myLicences =\n authUser?.licences?.map((licence) => licence.licenceType) ?? [];\n\n const myResourceIds = [\n authUser?.vendor ?? null,\n authUser?.partner ?? null,\n ...(authUser?.events ?? []),\n ].filter((id): id is string => id !== null);\n\n return myResourceIds.includes(resourceId)\n ? getLicenceFlagsByRole(myLicences)\n : NO_LICENCE_FLAGS;\n },\n [authUser],\n );\n\n const getLicenseAccessLevel = useCallback(\n (\n limitType: LimitType,\n resourceId: string,\n resourceType: EnumResourceType,\n ): number => {\n if (!isLicencedResourceType(resourceType)) {\n return 0;\n }\n\n // No resource yet (e.g. create flow): grant pro limits.\n if (resourceId === \"\") {\n return DEFAULT_LIMITS[limitType].pro;\n }\n\n const roleLicences = licences(resourceId)[resourceType];\n\n if (roleLicences.pro_plus) return DEFAULT_LIMITS[limitType].pro_plus;\n if (roleLicences.pro) return DEFAULT_LIMITS[limitType].pro;\n if (roleLicences.standard) return DEFAULT_LIMITS[limitType].standard;\n\n return 0;\n },\n [licences],\n );\n\n const hasVendorLicence = useMemo(\n () => hasLicence(authUser, \"vendor\"),\n [authUser],\n );\n\n const hasPartnerLicence = useMemo(\n () => hasLicence(authUser, \"partner\"),\n [authUser],\n );\n\n const hasEventLicence = useMemo(\n () => hasLicence(authUser, \"event\"),\n [authUser],\n );\n\n const hasUserLicence = useCallback(\n (licenceType: EnumUserLicence) => hasUserLicenceType(authUser, licenceType),\n [authUser],\n );\n\n const permissions = useMemo(() => {\n if (authUser?.permissions != null) {\n return authUser.permissions;\n }\n return getPermissionsForRoles(authUser?.roles);\n }, [authUser?.permissions, authUser?.roles]);\n\n const hasPermissionFn = useCallback(\n (permission: Permission) => permissionListIncludes(permissions, permission),\n [permissions],\n );\n\n const hasRoleFn = useCallback(\n (role: EnumUserRole) => roleHasRole(authUser?.roles, role),\n [authUser?.roles],\n );\n\n const isAdmin = useMemo(\n () =>\n roleHasRole(authUser?.roles, EnumUserRole.ADMIN) ||\n permissionListIncludes(permissions, \"dashboard.admin\") ||\n permissionListIncludes(permissions, \"*\"),\n [authUser?.roles, permissions],\n );\n\n const isSuperAdmin = useMemo(\n () => roleHasRole(authUser?.roles, EnumUserRole.SUPER_ADMIN),\n [authUser?.roles],\n );\n\n const isAffiliate = useMemo(\n () =>\n roleHasRole(authUser?.roles, EnumUserRole.AFFILIATE) &&\n authUser?.affiliate !== null &&\n authUser?.affiliate !== undefined,\n [authUser?.roles, authUser?.affiliate],\n );\n\n const isSchool = useMemo(\n () =>\n roleHasRole(authUser?.roles, EnumUserRole.SCHOOL) &&\n authUser?.school !== null &&\n authUser?.school !== undefined,\n [authUser?.roles, authUser?.school],\n );\n\n // Mount-only hydrate from storage. Do not re-run when adapter identities\n // change — that can overwrite a newer in-memory user (e.g. post-login setUser).\n useEffect(() => {\n const loadUser = async () => {\n try {\n const userJson = await storage.getItem(USER_STORAGE_KEY);\n await handleSetAuthUser(userJson ? JSON.parse(userJson) : null);\n } catch (error: unknown) {\n onError?.(error, { action: \"loadUserFromStorage\" });\n console.error(\"Failed to load user from storage:\", error);\n } finally {\n setIsLoading(false);\n }\n };\n\n void loadUser();\n }, []);\n\n const logoutWithReason = useCallback(\n async (reason: LogoutReason) => {\n try {\n if (shouldCallLogoutMutation(reason)) {\n try {\n const result = await logout();\n const message = result?.data?.logout?.message as string | undefined;\n if (message) {\n notifyLogoutSuccess?.(message);\n }\n } catch (err: unknown) {\n onError?.(err, { action: \"logout\" });\n console.warn(\"Logout request failed (ignored):\", err);\n }\n }\n } finally {\n await afterLogout(reason);\n setAuthUser(null);\n await storage.removeItem(USER_STORAGE_KEY);\n }\n },\n [\n afterLogout,\n logout,\n notifyLogoutSuccess,\n onError,\n shouldCallLogoutMutation,\n storage,\n ],\n );\n\n const handleLogoutExplicit = useCallback(\n () => logoutWithReason(\"manual\"),\n [logoutWithReason],\n );\n\n const handleLogoutExpired = useCallback(async () => {\n const hadSession = authUser != null;\n if (!hadSession) return;\n await logoutWithReason(\"expired\");\n notifySessionExpired?.();\n }, [authUser, logoutWithReason, notifySessionExpired]);\n\n useEffect(() => {\n authManager.setLogout(() => handleLogoutExpired());\n authManager.setUserRefetch(() => handleRefetchUser());\n }, [authManager, handleLogoutExpired, handleRefetchUser]);\n\n return {\n authUser,\n getLicenseAccessLevel,\n handleLogoutExplicit,\n hasEventLicence,\n hasPartnerLicence,\n hasPermission: hasPermissionFn,\n hasRole: hasRoleFn,\n hasUserLicence,\n hasVendorLicence,\n isAdmin,\n isAffiliate,\n isLoading: loading || isLoading,\n isSchool,\n isSuperAdmin,\n permissions,\n refetchUser: handleRefetchUser,\n setUser: handleSetAuthUser,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcO,SAAS,oBAAiC;AAC/C,MAAI,WAAyC;AAC7C,MAAI,gBAA8C;AAClD,MAAI,gBAAsC;AAE1C,SAAO;AAAA,IACL,mBAAmB,YAAY;AAC7B,UAAI,eAAe;AACjB,cAAM,cAAc;AAAA,MACtB,OAAO;AACL,gBAAQ,KAAK,uCAAkC;AAAA,MACjD;AAAA,IACF;AAAA,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;AAChB,cAAM,QAAQ,WAAW,gBAAgB;AAAA,MAC3C;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,uBAAuB;AAAA,IAC3B,MAAM,iBAAiB,QAAQ;AAAA,IAC/B,CAAC,gBAAgB;AAAA,EACnB;AAEA,QAAM,sBAAsB,YAAY,YAAY;AAClD,UAAM,aAAa,YAAY;AAC/B,QAAI,CAAC,WAAY;AACjB,UAAM,iBAAiB,SAAS;AAChC,2BAAuB;AAAA,EACzB,GAAG,CAAC,UAAU,kBAAkB,oBAAoB,CAAC;AAErD,YAAU,MAAM;AACd,gBAAY,UAAU,MAAM,oBAAoB,CAAC;AACjD,gBAAY,eAAe,MAAM,kBAAkB,CAAC;AAAA,EACtD,GAAG,CAAC,aAAa,qBAAqB,iBAAiB,CAAC;AAExD,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,WAAW;AAAA,IACtB;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb,SAAS;AAAA,EACX;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/auth/createAuthManager.ts","../../src/auth/interests.ts","../../src/auth/licenceUtils.ts","../../src/auth/useAuthCore.ts"],"sourcesContent":["export type AuthManager = {\n logout: () => Promise<void>;\n setLogout: (fn: () => Promise<void>) => void;\n handleRefetchUser: () => Promise<void>;\n setUserRefetch: (fn: () => Promise<void>) => void;\n};\n\n/**\n * Creates an auth manager used by Apollo error links to trigger logout/refetch\n * without importing React. Matches the former mobile authManager shape.\n *\n * `logout()` dedupes concurrent calls via an in-flight promise so token-refresh\n * failures do not kick off multiple logout sequences.\n */\nexport function createAuthManager(): AuthManager {\n let logoutFn: (() => Promise<void>) | null = null;\n let userRefetchFn: (() => Promise<void>) | null = null;\n let logoutPromise: Promise<void> | null = null;\n\n return {\n handleRefetchUser: async () => {\n if (userRefetchFn) {\n await userRefetchFn();\n } else {\n console.warn(\"❌ User refetch function not set!\");\n }\n },\n logout(): Promise<void> {\n if (logoutPromise !== null) return logoutPromise;\n if (logoutFn === null) {\n console.warn(\"❌ Logout function not set!\");\n return Promise.resolve();\n }\n logoutPromise = logoutFn().finally(() => {\n logoutPromise = null;\n });\n return logoutPromise;\n },\n setLogout(fn: () => Promise<void>) {\n logoutFn = fn;\n },\n setUserRefetch(fn: () => Promise<void>) {\n userRefetchFn = fn;\n },\n };\n}\n","import { EnumResourceType } from \"../enums\";\nimport { OptionItem } from \"../types\";\n\n/**\n * Labels shown to users for each selectable interest during registration.\n * Only overrides that differ from the enum value's capitalized form are listed.\n */\nconst INTEREST_LABEL_OVERRIDES: Partial<Record<EnumResourceType, string>> = {\n [EnumResourceType.VENDOR]: \"Stallholder\",\n};\n\nexport const interestOptions: OptionItem[] = [\n EnumResourceType.EVENT,\n EnumResourceType.VENDOR,\n EnumResourceType.PARTNER,\n EnumResourceType.VISITOR,\n].map((value) => ({\n label:\n INTEREST_LABEL_OVERRIDES[value] ??\n value.charAt(0).toUpperCase() + value.slice(1),\n value,\n}));\n\nexport const PROFILE_DASHBOARDS_PATH = \"Profile → Dashboards → \";\nexport const INSTRUCTION_MIDDLE = \", then tap \";\nexport const INSTRUCTION_AFTER = \" and fill in your details.\";\n\nexport type InterestInstruction = {\n action: string;\n before: string;\n dashboard: string;\n interest: EnumResourceType;\n};\n\nexport const INTEREST_INSTRUCTIONS: InterestInstruction[] = [\n {\n action: \"Create Stallholder\",\n before: \"To create your Stallholder profile, go to \",\n dashboard: \"Stallholder Dashboard\",\n interest: EnumResourceType.VENDOR,\n },\n {\n action: \"Create Event\",\n before: \"To create your Event profile, go to \",\n dashboard: \"Event Dashboard\",\n interest: EnumResourceType.EVENT,\n },\n {\n action: \"Create Partner\",\n before: \"To create your Partner profile, go to \",\n dashboard: \"Partner Dashboard\",\n interest: EnumResourceType.PARTNER,\n },\n];\n\n/**\n * Instructions for the interests currently selected during registration.\n * Multiple interests are supported.\n */\nexport const getInterestInstructions = (\n interests: EnumResourceType[] = [],\n): InterestInstruction[] =>\n INTEREST_INSTRUCTIONS.filter(({ interest }) => interests.includes(interest));\n","/* eslint-disable camelcase */\nimport { EnumResourceType, EnumUserLicence } from \"../enums\";\nimport type { SafeUserType } from \"../types\";\nimport { TIERS_BY_PRIORITY, type Tier } from \"../types/subscription\";\n\nimport type {\n HasLicenceResult,\n LicencedResourceType,\n LicencesByRole,\n LimitType,\n ProfileBadgeLicence,\n RoleLicences,\n} from \"./types\";\n\nexport function isLicencedResourceType(\n resourceType: EnumResourceType,\n): resourceType is LicencedResourceType {\n return (\n resourceType !== EnumResourceType.AFFILIATE &&\n resourceType !== EnumResourceType.SCHOOL\n );\n}\n\nexport function isProfileBadgeLicence(\n licenceType: EnumUserLicence,\n): licenceType is ProfileBadgeLicence {\n return (\n licenceType !== EnumUserLicence.STANDARD_AFFILIATE &&\n licenceType !== EnumUserLicence.STANDARD_SCHOOL\n );\n}\n\nexport const hasUserLicenceType = (\n authUser: SafeUserType | null,\n licenceType: EnumUserLicence,\n): boolean =>\n authUser?.licences?.some((licence) => licence.licenceType === licenceType) ??\n false;\n\nexport const hasLicence = (\n authUser: SafeUserType | null,\n licenceType: \"vendor\" | \"partner\" | \"event\",\n): HasLicenceResult => {\n const directLicence =\n authUser?.licences?.some((licence) =>\n licence.licenceType?.includes(licenceType),\n ) ?? false;\n\n return {\n directLicence,\n };\n};\n\n/** Default limits per subscription tier. */\nexport const DEFAULT_LIMITS: Record<LimitType, Record<Tier, number>> = {\n // 1 means calendar/productMenu is enabled, 0 means disabled\n availability: { pro: 1, pro_plus: 1, standard: 0 },\n calendar: { pro: 1, pro_plus: 1, standard: 0 },\n coupons: { pro: 1, pro_plus: 1, standard: 0 },\n images: { pro: 12, pro_plus: 12, standard: 6 },\n posters: { pro: 5, pro_plus: 5, standard: 5 },\n productsList: { pro: 1, pro_plus: 1, standard: 0 },\n relationShare: { pro: 1, pro_plus: 1, standard: 0 },\n statistics: { pro: 1, pro_plus: 1, standard: 0 },\n};\n\n/** All tiers off — used when the viewer does not own the resource. */\nexport const NO_LICENCE_FLAGS: LicencesByRole = {\n event: {\n pro_plus: false,\n // eslint-disable-next-line sort-keys\n pro: false,\n standard: false,\n },\n partner: {\n pro_plus: false,\n // eslint-disable-next-line sort-keys\n pro: false,\n standard: false,\n },\n vendor: {\n pro_plus: false,\n // eslint-disable-next-line sort-keys\n pro: false,\n standard: false,\n },\n};\n\n/**\n * Parses an array of licence strings into structured, role-based licences.\n * Users with no licences yet default to pro (create / trial access).\n */\nexport function getLicenceFlagsByRole(licences?: string[]): LicencesByRole {\n const normalized = licences?.map((l) => l.toLowerCase()) ?? [];\n const hasAnyLicence = normalized.length > 0;\n\n function resolve(role: EnumResourceType): RoleLicences {\n const result: RoleLicences = {\n pro_plus: false,\n // eslint-disable-next-line sort-keys\n pro: false,\n standard: false,\n };\n\n for (const tier of TIERS_BY_PRIORITY) {\n if (normalized.some((l) => l.startsWith(`${tier}_${role}`))) {\n result[tier] = true;\n break; // stop at first match → ensures mutual exclusivity\n }\n }\n\n // No licences at all → grant pro so new users can use pro features\n if (!hasAnyLicence) {\n result.pro = true;\n }\n\n return result;\n }\n\n return {\n event: resolve(EnumResourceType.EVENT),\n partner: resolve(EnumResourceType.PARTNER),\n vendor: resolve(EnumResourceType.VENDOR),\n };\n}\n","import { useCallback, useEffect, useMemo, useState } from \"react\";\n\nimport { EnumResourceType, EnumUserLicence, EnumUserRole } from \"../enums\";\nimport { useLogout } from \"../graphql/hooks/auth\";\nimport { useGetUser } from \"../graphql/hooks/user/hooksQuery\";\nimport { USER_STORAGE_KEY } from \"../storage\";\nimport type { SafeUserType } from \"../types\";\n\nimport {\n DEFAULT_LIMITS,\n getLicenceFlagsByRole,\n hasLicence,\n hasUserLicenceType,\n isLicencedResourceType,\n NO_LICENCE_FLAGS,\n} from \"./licenceUtils\";\nimport {\n getPermissionsForRoles,\n hasRole as roleHasRole,\n permissionListIncludes,\n} from \"./permissions\";\nimport type { Permission } from \"./permissions\";\nimport type {\n LimitType,\n LogoutReason,\n UseAuthCoreAdapters,\n UseAuthReturnType,\n} from \"./types\";\n\n/**\n * Platform-agnostic auth session core (source of truth for shared useAuth).\n *\n * Owns: persisted user load/set, refetch, role/licence flags, logout orchestration.\n * Does not own: AsyncStorage vs localStorage, Expo/Next navigation, toasts,\n * Apollo/WS reset, Firebase — those stay in each app's adapter wrapper.\n */\nexport function useAuthCore(adapters: UseAuthCoreAdapters): UseAuthReturnType {\n const {\n storage,\n authManager,\n afterLogout,\n shouldCallLogoutMutation = () => true,\n notifyLogoutSuccess,\n notifySessionExpired,\n onError,\n } = adapters;\n\n const [authUser, setAuthUser] = useState<SafeUserType | null>(null);\n const [isLoading, setIsLoading] = useState(true);\n\n const userId = useMemo(() => authUser?._id ?? \"\", [authUser?._id]);\n const { refetch } = useGetUser(userId);\n const { logout, loading } = useLogout();\n\n const handleSetAuthUser = useCallback(\n async (user: SafeUserType | null) => {\n setAuthUser(user);\n if (user) {\n await storage.setItem(USER_STORAGE_KEY, JSON.stringify(user));\n } else {\n await storage.removeItem(USER_STORAGE_KEY);\n }\n },\n [storage],\n );\n\n const handleRefetchUser = useCallback(async () => {\n if (!authUser) return;\n try {\n const result = await refetch();\n if (!result) return;\n const { data } = result;\n if (data?.user) await handleSetAuthUser(data.user);\n } catch (error: unknown) {\n onError?.(error, { action: \"refetchUser\" });\n console.warn(\n \"Failed to refetch user:\",\n error instanceof Error ? error.message : error,\n );\n }\n }, [authUser, handleSetAuthUser, onError, refetch]);\n\n const licences = useCallback(\n (resourceId: string) => {\n const myLicences =\n authUser?.licences?.map((licence) => licence.licenceType) ?? [];\n\n const myResourceIds = [\n authUser?.vendor ?? null,\n authUser?.partner ?? null,\n ...(authUser?.events ?? []),\n ].filter((id): id is string => id !== null);\n\n return myResourceIds.includes(resourceId)\n ? getLicenceFlagsByRole(myLicences)\n : NO_LICENCE_FLAGS;\n },\n [authUser],\n );\n\n const getLicenseAccessLevel = useCallback(\n (\n limitType: LimitType,\n resourceId: string,\n resourceType: EnumResourceType,\n ): number => {\n if (!isLicencedResourceType(resourceType)) {\n return 0;\n }\n\n // No resource yet (e.g. create flow): grant pro limits.\n if (resourceId === \"\") {\n return DEFAULT_LIMITS[limitType].pro;\n }\n\n const roleLicences = licences(resourceId)[resourceType];\n\n if (roleLicences.pro_plus) return DEFAULT_LIMITS[limitType].pro_plus;\n if (roleLicences.pro) return DEFAULT_LIMITS[limitType].pro;\n if (roleLicences.standard) return DEFAULT_LIMITS[limitType].standard;\n\n return 0;\n },\n [licences],\n );\n\n const hasVendorLicence = useMemo(\n () => hasLicence(authUser, \"vendor\"),\n [authUser],\n );\n\n const hasPartnerLicence = useMemo(\n () => hasLicence(authUser, \"partner\"),\n [authUser],\n );\n\n const hasEventLicence = useMemo(\n () => hasLicence(authUser, \"event\"),\n [authUser],\n );\n\n const hasUserLicence = useCallback(\n (licenceType: EnumUserLicence) => hasUserLicenceType(authUser, licenceType),\n [authUser],\n );\n\n const permissions = useMemo(() => {\n if (authUser?.permissions != null) {\n return authUser.permissions;\n }\n return getPermissionsForRoles(authUser?.roles);\n }, [authUser?.permissions, authUser?.roles]);\n\n const hasPermissionFn = useCallback(\n (permission: Permission) => permissionListIncludes(permissions, permission),\n [permissions],\n );\n\n const hasRoleFn = useCallback(\n (role: EnumUserRole) => roleHasRole(authUser?.roles, role),\n [authUser?.roles],\n );\n\n const isAdmin = useMemo(\n () =>\n roleHasRole(authUser?.roles, EnumUserRole.ADMIN) ||\n permissionListIncludes(permissions, \"dashboard.admin\") ||\n permissionListIncludes(permissions, \"*\"),\n [authUser?.roles, permissions],\n );\n\n const isSuperAdmin = useMemo(\n () => roleHasRole(authUser?.roles, EnumUserRole.SUPER_ADMIN),\n [authUser?.roles],\n );\n\n const isAffiliate = useMemo(\n () =>\n roleHasRole(authUser?.roles, EnumUserRole.AFFILIATE) &&\n authUser?.affiliate !== null &&\n authUser?.affiliate !== undefined,\n [authUser?.roles, authUser?.affiliate],\n );\n\n const isSchool = useMemo(\n () =>\n roleHasRole(authUser?.roles, EnumUserRole.SCHOOL) &&\n authUser?.school !== null &&\n authUser?.school !== undefined,\n [authUser?.roles, authUser?.school],\n );\n\n // Mount-only hydrate from storage. Do not re-run when adapter identities\n // change — that can overwrite a newer in-memory user (e.g. post-login setUser).\n useEffect(() => {\n const loadUser = async () => {\n try {\n const userJson = await storage.getItem(USER_STORAGE_KEY);\n await handleSetAuthUser(userJson ? JSON.parse(userJson) : null);\n } catch (error: unknown) {\n onError?.(error, { action: \"loadUserFromStorage\" });\n console.error(\"Failed to load user from storage:\", error);\n } finally {\n setIsLoading(false);\n }\n };\n\n void loadUser();\n }, []);\n\n const logoutWithReason = useCallback(\n async (reason: LogoutReason) => {\n try {\n if (shouldCallLogoutMutation(reason)) {\n try {\n const result = await logout();\n const message = result?.data?.logout?.message as string | undefined;\n if (message) {\n notifyLogoutSuccess?.(message);\n }\n } catch (err: unknown) {\n onError?.(err, { action: \"logout\" });\n console.warn(\"Logout request failed (ignored):\", err);\n }\n }\n } finally {\n await afterLogout(reason);\n setAuthUser(null);\n await storage.removeItem(USER_STORAGE_KEY);\n }\n },\n [\n afterLogout,\n logout,\n notifyLogoutSuccess,\n onError,\n shouldCallLogoutMutation,\n storage,\n ],\n );\n\n const handleLogoutExplicit = useCallback(\n () => logoutWithReason(\"manual\"),\n [logoutWithReason],\n );\n\n const handleLogoutExpired = useCallback(async () => {\n const hadSession = authUser != null;\n if (!hadSession) return;\n await logoutWithReason(\"expired\");\n notifySessionExpired?.();\n }, [authUser, logoutWithReason, notifySessionExpired]);\n\n useEffect(() => {\n authManager.setLogout(() => handleLogoutExpired());\n authManager.setUserRefetch(() => handleRefetchUser());\n }, [authManager, handleLogoutExpired, handleRefetchUser]);\n\n return {\n authUser,\n getLicenseAccessLevel,\n handleLogoutExplicit,\n hasEventLicence,\n hasPartnerLicence,\n hasPermission: hasPermissionFn,\n hasRole: hasRoleFn,\n hasUserLicence,\n hasVendorLicence,\n isAdmin,\n isAffiliate,\n isLoading: loading || isLoading,\n isSchool,\n isSuperAdmin,\n permissions,\n refetchUser: handleRefetchUser,\n setUser: handleSetAuthUser,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcO,SAAS,oBAAiC;AAC/C,MAAI,WAAyC;AAC7C,MAAI,gBAA8C;AAClD,MAAI,gBAAsC;AAE1C,SAAO;AAAA,IACL,mBAAmB,YAAY;AAC7B,UAAI,eAAe;AACjB,cAAM,cAAc;AAAA,MACtB,OAAO;AACL,gBAAQ,KAAK,uCAAkC;AAAA,MACjD;AAAA,IACF;AAAA,IACA,SAAwB;AACtB,UAAI,kBAAkB,KAAM,QAAO;AACnC,UAAI,aAAa,MAAM;AACrB,gBAAQ,KAAK,iCAA4B;AACzC,eAAO,QAAQ,QAAQ;AAAA,MACzB;AACA,sBAAgB,SAAS,EAAE,QAAQ,MAAM;AACvC,wBAAgB;AAAA,MAClB,CAAC;AACD,aAAO;AAAA,IACT;AAAA,IACA,UAAU,IAAyB;AACjC,iBAAW;AAAA,IACb;AAAA,IACA,eAAe,IAAyB;AACtC,sBAAgB;AAAA,IAClB;AAAA,EACF;AACF;;;ACtCA,IAAM,2BAAsE;AAAA,EAC1E,sBAAwB,GAAG;AAC7B;AAEO,IAAM,kBAAgC;AAAA;AAAA;AAAA;AAAA;AAK7C,EAAE,IAAI,CAAC,WAAW;AAAA,EAChB,OACE,yBAAyB,KAAK,KAC9B,MAAM,OAAO,CAAC,EAAE,YAAY,IAAI,MAAM,MAAM,CAAC;AAAA,EAC/C;AACF,EAAE;AAEK,IAAM,0BAA0B;AAChC,IAAM,qBAAqB;AAC3B,IAAM,oBAAoB;AAS1B,IAAM,wBAA+C;AAAA,E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MAAM;AACxB,oBAAY,IAAI;AAChB,cAAM,QAAQ,WAAW,gBAAgB;AAAA,MAC3C;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,uBAAuB;AAAA,IAC3B,MAAM,iBAAiB,QAAQ;AAAA,IAC/B,CAAC,gBAAgB;AAAA,EACnB;AAEA,QAAM,sBAAsB,YAAY,YAAY;AAClD,UAAM,aAAa,YAAY;AAC/B,QAAI,CAAC,WAAY;AACjB,UAAM,iBAAiB,SAAS;AAChC,2BAAuB;AAAA,EACzB,GAAG,CAAC,UAAU,kBAAkB,oBAAoB,CAAC;AAErD,YAAU,MAAM;AACd,gBAAY,UAAU,MAAM,oBAAoB,CAAC;AACjD,gBAAY,eAAe,MAAM,kBAAkB,CAAC;AAAA,EACtD,GAAG,CAAC,aAAa,qBAAqB,iBAAiB,CAAC;AAExD,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,WAAW;AAAA,IACtB;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb,SAAS;AAAA,EACX;AACF;","names":[]}
|
package/dist/hooks/index.cjs
CHANGED
|
@@ -1906,10 +1906,26 @@ var startTimeCannotBeInPastTest = yup.string().test(
|
|
|
1906
1906
|
);
|
|
1907
1907
|
var dateTimeSchema = yup.object().shape({
|
|
1908
1908
|
dateStatus: yup.mixed().oneOf(Object.values(EnumEventDateStatus)).required("Date status is required"),
|
|
1909
|
-
endDate: yup.string().label("End Date").
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1909
|
+
endDate: yup.string().label("End Date").defined().when("dateStatus", {
|
|
1910
|
+
is: (status) => status !== "Canceled" /* CANCELED */,
|
|
1911
|
+
then: () => yup.string().label("End Date").concat(endDateNotInPastTest).concat(endDateAfterStartDateTest).required("End date is required"),
|
|
1912
|
+
otherwise: () => yup.string().label("End Date").defined()
|
|
1913
|
+
}),
|
|
1914
|
+
endTime: yup.string().label("End Time").defined().when("dateStatus", {
|
|
1915
|
+
is: (status) => status !== "Canceled" /* CANCELED */,
|
|
1916
|
+
then: () => yup.string().label("End Time").concat(endTimeMustBeAfterStartTimeTest).required("End time is required"),
|
|
1917
|
+
otherwise: () => yup.string().label("End Time").defined()
|
|
1918
|
+
}),
|
|
1919
|
+
startDate: yup.string().label("Start Date").defined().when("dateStatus", {
|
|
1920
|
+
is: (status) => status !== "Canceled" /* CANCELED */,
|
|
1921
|
+
then: () => yup.string().label("Start Date").concat(startDateNotInPastTest).required("Start date is required"),
|
|
1922
|
+
otherwise: () => yup.string().label("Start Date").defined()
|
|
1923
|
+
}),
|
|
1924
|
+
startTime: yup.string().label("Start Time").defined().when("dateStatus", {
|
|
1925
|
+
is: (status) => status !== "Canceled" /* CANCELED */,
|
|
1926
|
+
then: () => yup.string().label("Start Time").concat(startTimeCannotBeInPastTest).required("Start time is required"),
|
|
1927
|
+
otherwise: () => yup.string().label("Start Time").defined()
|
|
1928
|
+
})
|
|
1913
1929
|
});
|
|
1914
1930
|
var stallTypesSchema = yup.object({
|
|
1915
1931
|
label: yup.string().trim().label("Stall Type").required("Stall type is required"),
|