@timardex/cluemart-shared 1.5.813 → 1.5.822

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.
Files changed (88) hide show
  1. package/dist/{ad-0muFV6oH.d.ts → ad-BFGA6SrQ.d.ts} +4 -123
  2. package/dist/{ad-Dlk9SFLw.d.mts → ad-BRC6KNgv.d.mts} +4 -123
  3. package/dist/apollo/index.cjs +1362 -0
  4. package/dist/apollo/index.cjs.map +1 -0
  5. package/dist/apollo/index.d.mts +337 -0
  6. package/dist/apollo/index.d.ts +337 -0
  7. package/dist/apollo/index.mjs +1273 -0
  8. package/dist/apollo/index.mjs.map +1 -0
  9. package/dist/auth/index.cjs +1425 -0
  10. package/dist/auth/index.cjs.map +1 -0
  11. package/dist/auth/index.d.mts +119 -0
  12. package/dist/auth/index.d.ts +119 -0
  13. package/dist/auth/index.mjs +317 -0
  14. package/dist/auth/index.mjs.map +1 -0
  15. package/dist/{chunk-LETM2YHF.mjs → chunk-D33VEY7Q.mjs} +3 -1
  16. package/dist/chunk-D33VEY7Q.mjs.map +1 -0
  17. package/dist/chunk-DQ7ZHIXW.mjs +26 -0
  18. package/dist/chunk-DQ7ZHIXW.mjs.map +1 -0
  19. package/dist/{chunk-LKMJ75YV.mjs → chunk-EUOLQ7SS.mjs} +2 -2
  20. package/dist/{chunk-GJO7X2Y4.mjs → chunk-IREUJYMR.mjs} +3 -3
  21. package/dist/{chunk-POXARN2X.mjs → chunk-KMLUQVNM.mjs} +1 -24
  22. package/dist/chunk-KMLUQVNM.mjs.map +1 -0
  23. package/dist/chunk-MIDSLTUJ.mjs +1214 -0
  24. package/dist/chunk-MIDSLTUJ.mjs.map +1 -0
  25. package/dist/{chunk-DLPDX4EH.mjs → chunk-N7KENXCS.mjs} +10 -49
  26. package/dist/chunk-N7KENXCS.mjs.map +1 -0
  27. package/dist/chunk-RAYUJODN.mjs +45 -0
  28. package/dist/chunk-RAYUJODN.mjs.map +1 -0
  29. package/dist/{chunk-4TP57ZL7.mjs → chunk-UHDYJBIX.mjs} +2 -2
  30. package/dist/{chunk-4ICKZHQA.mjs → chunk-WZPKYUSX.mjs} +361 -2328
  31. package/dist/chunk-WZPKYUSX.mjs.map +1 -0
  32. package/dist/{contactUs-CiXFYse5.d.ts → contactUs-Bwxzw-cB.d.ts} +1 -1
  33. package/dist/{contactUs-HPydW6BR.d.mts → contactUs-b5SfvqmJ.d.mts} +1 -1
  34. package/dist/enums/index.cjs +2 -0
  35. package/dist/enums/index.cjs.map +1 -1
  36. package/dist/enums/index.d.mts +3 -1
  37. package/dist/enums/index.d.ts +3 -1
  38. package/dist/enums/index.mjs +1 -1
  39. package/dist/formFields/index.cjs.map +1 -1
  40. package/dist/formFields/index.d.mts +1 -1
  41. package/dist/formFields/index.d.ts +1 -1
  42. package/dist/formFields/index.mjs +7 -5
  43. package/dist/{global-Dq6A7pNV.d.mts → global-959zf6qy.d.mts} +1 -1
  44. package/dist/{global-B2jacmZB.d.ts → global-wVC9VaCx.d.ts} +1 -1
  45. package/dist/graphql/index.cjs +2 -844
  46. package/dist/graphql/index.cjs.map +1 -1
  47. package/dist/graphql/index.d.mts +4 -3
  48. package/dist/graphql/index.d.ts +4 -3
  49. package/dist/graphql/index.mjs +23 -21
  50. package/dist/hooks/index.cjs +5 -0
  51. package/dist/hooks/index.cjs.map +1 -1
  52. package/dist/hooks/index.d.mts +4 -3
  53. package/dist/hooks/index.d.ts +4 -3
  54. package/dist/hooks/index.mjs +15 -12
  55. package/dist/hooks/index.mjs.map +1 -1
  56. package/dist/index.cjs +4 -844
  57. package/dist/index.cjs.map +1 -1
  58. package/dist/index.d.mts +3 -1
  59. package/dist/index.d.ts +3 -1
  60. package/dist/index.mjs +3 -843
  61. package/dist/index.mjs.map +1 -1
  62. package/dist/map/index.d.mts +1 -1
  63. package/dist/map/index.d.ts +1 -1
  64. package/dist/{resourceActivities-DUR5JaaB.d.ts → resourceActivities-ChZcl5wJ.d.ts} +1 -1
  65. package/dist/{resourceActivities-BCZ6HU7U.d.mts → resourceActivities-ZPT9JlfH.d.mts} +1 -1
  66. package/dist/sharing/index.cjs.map +1 -1
  67. package/dist/sharing/index.d.mts +1 -1
  68. package/dist/sharing/index.d.ts +1 -1
  69. package/dist/sharing/index.mjs +3 -3
  70. package/dist/subscription-BU8GvH2K.d.ts +12 -0
  71. package/dist/subscription-bmAdrnfi.d.mts +12 -0
  72. package/dist/types/index.d.mts +9 -16
  73. package/dist/types/index.d.ts +9 -16
  74. package/dist/types/index.mjs +7 -5
  75. package/dist/user-CCN2IPDV.d.ts +124 -0
  76. package/dist/user-CadKvubI.d.mts +124 -0
  77. package/dist/utils/index.cjs.map +1 -1
  78. package/dist/utils/index.d.mts +1 -1
  79. package/dist/utils/index.d.ts +1 -1
  80. package/dist/utils/index.mjs +8 -5
  81. package/package.json +25 -9
  82. package/dist/chunk-4ICKZHQA.mjs.map +0 -1
  83. package/dist/chunk-DLPDX4EH.mjs.map +0 -1
  84. package/dist/chunk-LETM2YHF.mjs.map +0 -1
  85. package/dist/chunk-POXARN2X.mjs.map +0 -1
  86. /package/dist/{chunk-LKMJ75YV.mjs.map → chunk-EUOLQ7SS.mjs.map} +0 -0
  87. /package/dist/{chunk-GJO7X2Y4.mjs.map → chunk-IREUJYMR.mjs.map} +0 -0
  88. /package/dist/{chunk-4TP57ZL7.mjs.map → chunk-UHDYJBIX.mjs.map} +0 -0
@@ -0,0 +1,1425 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/auth/index.ts
22
+ var auth_exports = {};
23
+ __export(auth_exports, {
24
+ DEFAULT_LIMITS: () => DEFAULT_LIMITS,
25
+ SUPER_ADMIN_EMAIL: () => SUPER_ADMIN_EMAIL,
26
+ UserProvider: () => UserProvider,
27
+ createAuthManager: () => createAuthManager,
28
+ getLicenceFlagsByRole: () => getLicenceFlagsByRole,
29
+ hasLicence: () => hasLicence,
30
+ hasUserLicenceType: () => hasUserLicenceType,
31
+ isLicencedResourceType: () => isLicencedResourceType,
32
+ isProfileBadgeLicence: () => isProfileBadgeLicence,
33
+ useAuthCore: () => useAuthCore,
34
+ useAuthUser: () => useAuthUser
35
+ });
36
+ module.exports = __toCommonJS(auth_exports);
37
+
38
+ // src/auth/constants.ts
39
+ var SUPER_ADMIN_EMAIL = "hello@cluemart.co.nz";
40
+
41
+ // src/auth/createAuthManager.ts
42
+ function createAuthManager() {
43
+ let logoutFn = null;
44
+ let userRefetchFn = null;
45
+ let logoutPromise = null;
46
+ return {
47
+ handleRefetchUser: async () => {
48
+ if (userRefetchFn) {
49
+ await userRefetchFn();
50
+ } else {
51
+ console.warn("\u274C User refetch function not set!");
52
+ }
53
+ },
54
+ logout() {
55
+ if (logoutPromise !== null) return logoutPromise;
56
+ if (logoutFn === null) {
57
+ console.warn("\u274C Logout function not set!");
58
+ return Promise.resolve();
59
+ }
60
+ logoutPromise = logoutFn().finally(() => {
61
+ logoutPromise = null;
62
+ });
63
+ return logoutPromise;
64
+ },
65
+ setLogout(fn) {
66
+ logoutFn = fn;
67
+ },
68
+ setUserRefetch(fn) {
69
+ userRefetchFn = fn;
70
+ }
71
+ };
72
+ }
73
+
74
+ // src/types/subscription.ts
75
+ var TIERS_BY_PRIORITY = ["pro_plus", "pro", "standard"];
76
+ var TIER_FROM_LICENCE = {
77
+ ["pro_event" /* PRO_EVENT */]: "pro",
78
+ ["pro_plus_event" /* PRO_PLUS_EVENT */]: "pro_plus",
79
+ ["pro_plus_vendor" /* PRO_PLUS_VENDOR */]: "pro_plus",
80
+ ["pro_vendor" /* PRO_VENDOR */]: "pro",
81
+ ["standard_event" /* STANDARD_EVENT */]: "standard",
82
+ ["standard_partner" /* STANDARD_PARTNER */]: "standard",
83
+ ["standard_vendor" /* STANDARD_VENDOR */]: "standard",
84
+ ["standard_affiliate" /* STANDARD_AFFILIATE */]: "standard",
85
+ ["standard_school" /* STANDARD_SCHOOL */]: "standard"
86
+ };
87
+
88
+ // src/auth/licenceUtils.ts
89
+ function isLicencedResourceType(resourceType) {
90
+ return resourceType !== "affiliate" /* AFFILIATE */ && resourceType !== "school" /* SCHOOL */;
91
+ }
92
+ function isProfileBadgeLicence(licenceType) {
93
+ return licenceType !== "standard_affiliate" /* STANDARD_AFFILIATE */ && licenceType !== "standard_school" /* STANDARD_SCHOOL */;
94
+ }
95
+ var hasUserLicenceType = (authUser, licenceType) => authUser?.licences?.some((licence) => licence.licenceType === licenceType) ?? false;
96
+ var hasLicence = (authUser, licenceType) => {
97
+ const directLicence = authUser?.licences?.some(
98
+ (licence) => licence.licenceType?.includes(licenceType)
99
+ ) ?? false;
100
+ const associateLicence = authUser?.associates?.some(
101
+ (associate) => associate.licence?.licenceType?.includes(licenceType)
102
+ ) ?? false;
103
+ return {
104
+ associateLicence,
105
+ directLicence
106
+ };
107
+ };
108
+ var DEFAULT_LIMITS = {
109
+ // 1 means calendar/productMenu is enabled, 0 means disabled
110
+ associates: { pro: 3, pro_plus: 3, standard: 0 },
111
+ availability: { pro: 1, pro_plus: 1, standard: 0 },
112
+ calendar: { pro: 1, pro_plus: 1, standard: 0 },
113
+ images: { pro: 12, pro_plus: 12, standard: 6 },
114
+ posters: { pro: 5, pro_plus: 5, standard: 5 },
115
+ productsList: { pro: 1, pro_plus: 1, standard: 0 },
116
+ relationShare: { pro: 1, pro_plus: 1, standard: 0 },
117
+ statistics: { pro: 1, pro_plus: 1, standard: 0 }
118
+ };
119
+ function getLicenceFlagsByRole(licences) {
120
+ const normalized = licences?.map((l) => l.toLowerCase()) ?? [];
121
+ function resolve(role) {
122
+ const result = {
123
+ pro_plus: false,
124
+ // eslint-disable-next-line sort-keys
125
+ pro: false,
126
+ standard: false
127
+ };
128
+ for (const tier of TIERS_BY_PRIORITY) {
129
+ if (normalized.some((l) => l.startsWith(`${tier}_${role}`))) {
130
+ result[tier] = true;
131
+ break;
132
+ }
133
+ }
134
+ return result;
135
+ }
136
+ return {
137
+ event: resolve("event" /* EVENT */),
138
+ partner: resolve("partner" /* PARTNER */),
139
+ vendor: resolve("vendor" /* VENDOR */)
140
+ };
141
+ }
142
+
143
+ // src/auth/useAuthCore.ts
144
+ var import_react = require("react");
145
+
146
+ // src/graphql/hooks/auth.ts
147
+ var import_client3 = require("@apollo/client");
148
+
149
+ // src/graphql/mutations/auth.ts
150
+ var import_client2 = require("@apollo/client");
151
+
152
+ // src/graphql/queries/global.ts
153
+ var import_client = require("@apollo/client");
154
+ var POSTER_USAGE_FIELDS_FRAGMENT = import_client.gql`
155
+ fragment PosterUsageFields on PosterUsageType {
156
+ month
157
+ count
158
+ }
159
+ `;
160
+ var SOCIAL_MEDIA_FIELDS_FRAGMENT = import_client.gql`
161
+ fragment SocialMediaFields on SocialMediaType {
162
+ name
163
+ link
164
+ }
165
+ `;
166
+ var RESOURCE_IMAGE_FIELDS_FRAGMENT = import_client.gql`
167
+ fragment ResourceImageFields on ResourceImageType {
168
+ active
169
+ source
170
+ title
171
+ }
172
+ `;
173
+ var OWNER_FIELDS_FRAGMENT = import_client.gql`
174
+ fragment OwnerFields on OwnerType {
175
+ email
176
+ userId
177
+ }
178
+ `;
179
+ var CATEGORY_FIELDS_FRAGMENT = import_client.gql`
180
+ fragment CategoryFields on CategoryType {
181
+ id
182
+ name
183
+ subcategories {
184
+ id
185
+ items {
186
+ id
187
+ name
188
+ }
189
+ name
190
+ }
191
+ }
192
+ `;
193
+ var LICENCE_FIELDS_FRAGMENT = import_client.gql`
194
+ fragment LicenceFields on UserLicenceType {
195
+ expiryDate
196
+ issuedDate
197
+ licenceType
198
+ prevLicenceType
199
+ }
200
+ `;
201
+ var ASSOCIATES_FIELDS_FRAGMENT = import_client.gql`
202
+ fragment AssociatesFields on AssociateType {
203
+ email
204
+ resourceId
205
+ resourceType
206
+ licence {
207
+ ...LicenceFields
208
+ }
209
+ }
210
+ ${LICENCE_FIELDS_FRAGMENT}
211
+ `;
212
+ var TERMS_AGREEMENT_FIELDS_FRAGMENT = import_client.gql`
213
+ fragment TermsAgreementFields on TermsAgreementType {
214
+ appBuildNumber
215
+ appId
216
+ appVersion
217
+ brand
218
+ deviceName
219
+ installationId
220
+ manufacturer
221
+ modelName
222
+ osName
223
+ osVersion
224
+ termVersion
225
+ timestamp
226
+ }
227
+ `;
228
+ var DATETIME_FIELDS_FRAGMENT = import_client.gql`
229
+ fragment DateTimeFields on DateTimeType {
230
+ dateStatus
231
+ endDate
232
+ endTime
233
+ startDate
234
+ startTime
235
+ }
236
+ `;
237
+ var LOCATION_GEO_FIELDS_FRAGMENT = import_client.gql`
238
+ fragment LocationGeoFields on LocationGeoType {
239
+ coordinates
240
+ type
241
+ }
242
+ `;
243
+ var LOCATION_FIELDS_FRAGMENT = import_client.gql`
244
+ fragment LocationFields on LocationType {
245
+ city
246
+ country
247
+ fullAddress
248
+ geo {
249
+ ...LocationGeoFields
250
+ }
251
+ latitude
252
+ longitude
253
+ region
254
+ }
255
+ ${LOCATION_GEO_FIELDS_FRAGMENT}
256
+ `;
257
+ var USER_ACTIVITY_FIELDS_FRAGMENT = import_client.gql`
258
+ fragment UserActivityFields on UserActivityType {
259
+ favourites {
260
+ events
261
+ partners
262
+ vendors
263
+ }
264
+ going {
265
+ events {
266
+ resourceId
267
+ dateTime {
268
+ ...DateTimeFields
269
+ }
270
+ }
271
+ }
272
+ interested {
273
+ events {
274
+ resourceId
275
+ dateTime {
276
+ ...DateTimeFields
277
+ }
278
+ }
279
+ }
280
+ present {
281
+ events {
282
+ resourceId
283
+ dateTime {
284
+ ...DateTimeFields
285
+ }
286
+ }
287
+ }
288
+ }
289
+ ${DATETIME_FIELDS_FRAGMENT}
290
+ `;
291
+ var REDEEMED_REWARD_FIELDS_FRAGMENT = import_client.gql`
292
+ fragment RedeemedRewardFields on RedeemedRewardType {
293
+ name
294
+ pointsUsed
295
+ redeemedAt
296
+ }
297
+ `;
298
+ var USER_FIELDS_FRAGMENT = import_client.gql`
299
+ fragment UserFields on UserType {
300
+ _id
301
+ active
302
+ associates {
303
+ ...AssociatesFields
304
+ }
305
+ affiliate
306
+ avatar {
307
+ ...ResourceImageFields
308
+ }
309
+ createdAt
310
+ deletedAt
311
+ email
312
+ events
313
+ firstName
314
+ game
315
+ isTester
316
+ lastName
317
+ licences {
318
+ ...LicenceFields
319
+ }
320
+ location {
321
+ ...LocationFields
322
+ }
323
+ partner
324
+ overallPoints
325
+ platform
326
+ preferredRegion
327
+ promoCodes
328
+ role
329
+ redeemedRewards {
330
+ ...RedeemedRewardFields
331
+ }
332
+ school
333
+ termsAgreement {
334
+ ...TermsAgreementFields
335
+ }
336
+ userActivity {
337
+ ...UserActivityFields
338
+ }
339
+ vendor
340
+ updatedAt
341
+ }
342
+ ${RESOURCE_IMAGE_FIELDS_FRAGMENT}
343
+ ${ASSOCIATES_FIELDS_FRAGMENT}
344
+ ${TERMS_AGREEMENT_FIELDS_FRAGMENT}
345
+ ${USER_ACTIVITY_FIELDS_FRAGMENT}
346
+ ${LICENCE_FIELDS_FRAGMENT}
347
+ ${LOCATION_FIELDS_FRAGMENT}
348
+ ${REDEEMED_REWARD_FIELDS_FRAGMENT}
349
+ `;
350
+ var STALL_TYPE_FIELDS_FRAGMENT = import_client.gql`
351
+ fragment StallTypeFields on StallTypeType {
352
+ label
353
+ price
354
+ stallCapacity
355
+ }
356
+ `;
357
+ var RELATION_DATES_FRAGMENT = import_client.gql`
358
+ fragment RelationDates on RelationDateType {
359
+ dateTime {
360
+ dateStatus
361
+ endDate
362
+ endTime
363
+ startDate
364
+ startTime
365
+ stallType {
366
+ ...StallTypeFields
367
+ }
368
+ }
369
+ lastUpdateBy {
370
+ resourceId
371
+ userEmail
372
+ }
373
+ paymentReference
374
+ status
375
+ }
376
+ ${STALL_TYPE_FIELDS_FRAGMENT}
377
+ `;
378
+ var CONTACT_DETAILS_FIELDS_FRAGMENT = import_client.gql`
379
+ fragment ContactDetailsFields on ContactDetailsType {
380
+ email
381
+ landlinePhone
382
+ mobilePhone
383
+ }
384
+ `;
385
+ var EVENT_LIST_ITEM = import_client.gql`
386
+ fragment EventListItemFields on EventListItemType {
387
+ _id
388
+ active
389
+ approvedAt
390
+ claimed
391
+ cover {
392
+ ...ResourceImageFields
393
+ }
394
+ createdAt
395
+ dateTime {
396
+ ...DateTimeFields
397
+ }
398
+ deletedAt
399
+ description
400
+ eventType
401
+ googlePlaceId
402
+ images {
403
+ ...ResourceImageFields
404
+ }
405
+ location {
406
+ ...LocationFields
407
+ }
408
+ logo {
409
+ ...ResourceImageFields
410
+ }
411
+ name
412
+ rainOrShine
413
+ rating
414
+ region
415
+ relations {
416
+ relationId
417
+ relationDates {
418
+ ...RelationDates
419
+ }
420
+ }
421
+ reviewCount
422
+ slug
423
+ updatedAt
424
+ }
425
+ ${DATETIME_FIELDS_FRAGMENT}
426
+ ${LOCATION_FIELDS_FRAGMENT}
427
+ ${RESOURCE_IMAGE_FIELDS_FRAGMENT}
428
+ ${RELATION_DATES_FRAGMENT}
429
+ `;
430
+ var RELATED_POST_FIELDS_FRAGMENT = import_client.gql`
431
+ fragment RelatedPostFields on RelatedPostType {
432
+ postActive
433
+ postId
434
+ postSlug
435
+ postType
436
+ }
437
+ `;
438
+ var SOCIAL_SHARE_RESOURCE_FIELDS_FRAGMENT = import_client.gql`
439
+ fragment SocialShareResourceFields on SocialShareResourceType {
440
+ qrCode {
441
+ ...ResourceImageFields
442
+ }
443
+ socialImage {
444
+ ...ResourceImageFields
445
+ }
446
+ }
447
+ ${RESOURCE_IMAGE_FIELDS_FRAGMENT}
448
+ `;
449
+
450
+ // src/graphql/mutations/auth.ts
451
+ var REGISTER_MUTATION = import_client2.gql`
452
+ mutation register($input: RegisterInputType!) {
453
+ register(input: $input) {
454
+ message
455
+ refreshToken
456
+ token
457
+ user {
458
+ ...UserFields
459
+ }
460
+ }
461
+ }
462
+ ${USER_FIELDS_FRAGMENT}
463
+ `;
464
+ var LOGIN_MUTATION = import_client2.gql`
465
+ mutation login($input: LoginInputType!) {
466
+ login(input: $input) {
467
+ message
468
+ refreshToken
469
+ token
470
+ user {
471
+ ...UserFields
472
+ }
473
+ }
474
+ }
475
+ ${USER_FIELDS_FRAGMENT}
476
+ `;
477
+ var LOGOUT_MUTATION = import_client2.gql`
478
+ mutation logout {
479
+ logout {
480
+ message
481
+ }
482
+ }
483
+ `;
484
+ var REFRESH_TOKEN_MUTATION = import_client2.gql`
485
+ mutation refreshToken($input: RefreshTokenInputType!) {
486
+ refreshToken(input: $input) {
487
+ refreshToken
488
+ token
489
+ }
490
+ }
491
+ `;
492
+ var RESET_PASSWORD_MUTATION = import_client2.gql`
493
+ mutation resetPassword($input: ResetPasswordInputType!) {
494
+ resetPassword(input: $input) {
495
+ message
496
+ }
497
+ }
498
+ `;
499
+ var REQUEST_PASSWORD_RESET_MUTATION = import_client2.gql`
500
+ mutation requestPasswordReset($input: RequestPasswordResetInputType!) {
501
+ requestPasswordReset(input: $input) {
502
+ message
503
+ }
504
+ }
505
+ `;
506
+ var VALIDATE_VERIFICATION_TOKEN_MUTATION = import_client2.gql`
507
+ mutation validateVerificationToken(
508
+ $input: ValidateVerificationTokenInputType!
509
+ ) {
510
+ validateVerificationToken(input: $input) {
511
+ message
512
+ }
513
+ }
514
+ `;
515
+
516
+ // src/graphql/hooks/auth.ts
517
+ var useLogout = () => {
518
+ const [logout, { loading, error }] = (0, import_client3.useMutation)(LOGOUT_MUTATION);
519
+ return { error, loading, logout };
520
+ };
521
+
522
+ // src/graphql/hooks/user/hooksQuery.ts
523
+ var import_client8 = require("@apollo/client");
524
+
525
+ // src/graphql/queries/user.ts
526
+ var import_client7 = require("@apollo/client");
527
+
528
+ // src/graphql/queries/event.ts
529
+ var import_client4 = require("@apollo/client");
530
+ var EVENT_INFO = import_client4.gql`
531
+ fragment EventInfoFields on EventInfoType {
532
+ _id
533
+ applicationDeadlineHours
534
+ dateTime {
535
+ dateStatus
536
+ endDate
537
+ endTime
538
+ stallTypes {
539
+ ...StallTypeFields
540
+ }
541
+ startDate
542
+ startTime
543
+ }
544
+ eventId
545
+ packInTime
546
+ paymentDueHours
547
+ paymentInfo {
548
+ accountHolderName
549
+ accountNumber
550
+ link
551
+ paymentMethod
552
+ }
553
+ refundPolicy {
554
+ category
555
+ label
556
+ value
557
+ }
558
+ requirements {
559
+ category
560
+ label
561
+ value
562
+ }
563
+ }
564
+ ${STALL_TYPE_FIELDS_FRAGMENT}
565
+ `;
566
+ var EVENT = import_client4.gql`
567
+ fragment EventFields on EventType {
568
+ _id
569
+ active
570
+ associates {
571
+ ...AssociatesFields
572
+ }
573
+ adIds
574
+ approvedAt
575
+ cover {
576
+ ...ResourceImageFields
577
+ }
578
+ claimed
579
+ createdAt
580
+ contactDetails {
581
+ ...ContactDetailsFields
582
+ }
583
+ dateTime {
584
+ ...DateTimeFields
585
+ }
586
+ description
587
+ deletedAt
588
+ googlePlaceId
589
+ images {
590
+ ...ResourceImageFields
591
+ }
592
+ eventType
593
+ location {
594
+ ...LocationFields
595
+ }
596
+ logo {
597
+ ...ResourceImageFields
598
+ }
599
+ eventInfoId
600
+ name
601
+ nzbn
602
+ owner {
603
+ ...OwnerFields
604
+ }
605
+ promoCodes
606
+ provider
607
+ posterUsage {
608
+ ...PosterUsageFields
609
+ }
610
+ region
611
+ relations {
612
+ relationId
613
+ relationDates {
614
+ ...RelationDates
615
+ }
616
+ }
617
+ rating
618
+ reviewCount
619
+ rainOrShine
620
+ relatedPost {
621
+ ...RelatedPostFields
622
+ }
623
+ socialMedia {
624
+ ...SocialMediaFields
625
+ }
626
+ sharePublic {
627
+ ...SocialShareResourceFields
628
+ }
629
+ shareRelation {
630
+ ...SocialShareResourceFields
631
+ }
632
+ slug
633
+ tags
634
+ termsAgreement {
635
+ ...TermsAgreementFields
636
+ }
637
+ updatedAt
638
+ }
639
+ ${DATETIME_FIELDS_FRAGMENT}
640
+ ${LOCATION_FIELDS_FRAGMENT}
641
+ ${OWNER_FIELDS_FRAGMENT}
642
+ ${RESOURCE_IMAGE_FIELDS_FRAGMENT}
643
+ ${SOCIAL_MEDIA_FIELDS_FRAGMENT}
644
+ ${POSTER_USAGE_FIELDS_FRAGMENT}
645
+ ${ASSOCIATES_FIELDS_FRAGMENT}
646
+ ${CONTACT_DETAILS_FIELDS_FRAGMENT}
647
+ ${TERMS_AGREEMENT_FIELDS_FRAGMENT}
648
+ ${RELATION_DATES_FRAGMENT}
649
+ ${RELATED_POST_FIELDS_FRAGMENT}
650
+ ${SOCIAL_SHARE_RESOURCE_FIELDS_FRAGMENT}
651
+ `;
652
+ var GET_EVENTS = import_client4.gql`
653
+ query getEvents($dateStatus: EventDateStatusEnumType) {
654
+ events(dateStatus: $dateStatus) {
655
+ ...EventListItemFields
656
+ }
657
+ }
658
+ ${EVENT_LIST_ITEM}
659
+ `;
660
+ var GET_EVENT = import_client4.gql`
661
+ query getEvent($_id: ID!) {
662
+ event(_id: $_id) {
663
+ ...EventFields
664
+ }
665
+ }
666
+ ${EVENT}
667
+ `;
668
+ var GET_EVENT_BY_PLACE_ID = import_client4.gql`
669
+ query getEventByPlaceId($googlePlaceId: String!) {
670
+ eventByPlaceId(googlePlaceId: $googlePlaceId) {
671
+ ...EventListItemFields
672
+ }
673
+ }
674
+ ${EVENT_LIST_ITEM}
675
+ `;
676
+ var GET_EVENTS_BY_REGION = import_client4.gql`
677
+ query getEventsByRegion(
678
+ $region: String!
679
+ $options: ResourcesByRegionOptions
680
+ $dateStatus: EventDateStatusEnumType
681
+ ) {
682
+ eventsByRegion(
683
+ region: $region
684
+ options: $options
685
+ dateStatus: $dateStatus
686
+ ) {
687
+ ...EventListItemFields
688
+ }
689
+ }
690
+ ${EVENT_LIST_ITEM}
691
+ `;
692
+ var SEARCH_EVENTS = import_client4.gql`
693
+ query searchEvents(
694
+ $region: String!
695
+ $search: String
696
+ $tags: [String]
697
+ $dateStatus: EventDateStatusEnumType
698
+ ) {
699
+ eventsSearch(
700
+ region: $region
701
+ search: $search
702
+ tags: $tags
703
+ dateStatus: $dateStatus
704
+ ) {
705
+ ...EventListItemFields
706
+ }
707
+ }
708
+ ${EVENT_LIST_ITEM}
709
+ `;
710
+ var GET_EVENTS_NEAR_ME = import_client4.gql`
711
+ query getEventsNearMe(
712
+ $latitude: Float!
713
+ $longitude: Float!
714
+ $radius: Int
715
+ $dateStatus: EventDateStatusEnumType
716
+ ) {
717
+ eventsNearMe(
718
+ latitude: $latitude
719
+ longitude: $longitude
720
+ radius: $radius
721
+ dateStatus: $dateStatus
722
+ ) {
723
+ ...EventListItemFields
724
+ }
725
+ }
726
+ ${EVENT_LIST_ITEM}
727
+ `;
728
+ var GET_EVENT_INFO = import_client4.gql`
729
+ query getEventInfo($eventId: ID!) {
730
+ eventInfo(eventId: $eventId) {
731
+ ...EventInfoFields
732
+ }
733
+ }
734
+ ${EVENT_INFO}
735
+ `;
736
+
737
+ // src/graphql/queries/partner.ts
738
+ var import_client5 = require("@apollo/client");
739
+ var PARTNER = import_client5.gql`
740
+ fragment PartnerFields on PartnerType {
741
+ _id
742
+ active
743
+ associates {
744
+ ...AssociatesFields
745
+ }
746
+ adIds
747
+ approvedAt
748
+ cover {
749
+ ...ResourceImageFields
750
+ }
751
+ createdAt
752
+ contactDetails {
753
+ ...ContactDetailsFields
754
+ }
755
+ description
756
+ deletedAt
757
+ images {
758
+ ...ResourceImageFields
759
+ }
760
+ location {
761
+ ...LocationFields
762
+ }
763
+ logo {
764
+ ...ResourceImageFields
765
+ }
766
+ name
767
+ nzbn
768
+ owner {
769
+ ...OwnerFields
770
+ }
771
+ partnerType
772
+ posterUsage {
773
+ ...PosterUsageFields
774
+ }
775
+ rating
776
+ region
777
+ reviewCount
778
+ relatedPost {
779
+ ...RelatedPostFields
780
+ }
781
+ socialMedia {
782
+ ...SocialMediaFields
783
+ }
784
+ slug
785
+ sharePublic {
786
+ ...SocialShareResourceFields
787
+ }
788
+ termsAgreement {
789
+ ...TermsAgreementFields
790
+ }
791
+ updatedAt
792
+ }
793
+ ${TERMS_AGREEMENT_FIELDS_FRAGMENT}
794
+ ${LOCATION_FIELDS_FRAGMENT}
795
+ ${OWNER_FIELDS_FRAGMENT}
796
+ ${ASSOCIATES_FIELDS_FRAGMENT}
797
+ ${RESOURCE_IMAGE_FIELDS_FRAGMENT}
798
+ ${POSTER_USAGE_FIELDS_FRAGMENT}
799
+ ${SOCIAL_MEDIA_FIELDS_FRAGMENT}
800
+ ${CONTACT_DETAILS_FIELDS_FRAGMENT}
801
+ ${RELATED_POST_FIELDS_FRAGMENT}
802
+ ${SOCIAL_SHARE_RESOURCE_FIELDS_FRAGMENT}
803
+ `;
804
+ var GET_PARTNERS = import_client5.gql`
805
+ query getPartners {
806
+ partners {
807
+ ...PartnerFields
808
+ }
809
+ }
810
+ ${PARTNER}
811
+ `;
812
+ var GET_PARTNER = import_client5.gql`
813
+ query getPartner($_id: ID!) {
814
+ partner(_id: $_id) {
815
+ ...PartnerFields
816
+ }
817
+ }
818
+ ${PARTNER}
819
+ `;
820
+ var GET_PARTNERS_BY_REGION = import_client5.gql`
821
+ query getPartnersByRegion(
822
+ $region: String!
823
+ $options: ResourcesByRegionOptions
824
+ ) {
825
+ partnersByRegion(region: $region, options: $options) {
826
+ ...PartnerFields
827
+ }
828
+ }
829
+ ${PARTNER}
830
+ `;
831
+ var SEARCH_PARTNERS = import_client5.gql`
832
+ query searchPartners($search: String!, $region: String!) {
833
+ partnersSearch(search: $search, region: $region) {
834
+ ...PartnerFields
835
+ }
836
+ }
837
+ ${PARTNER}
838
+ `;
839
+
840
+ // src/graphql/queries/vendor.ts
841
+ var import_client6 = require("@apollo/client");
842
+ var VENDOR_DATETIME_FIELDS_FRAGMENT = import_client6.gql`
843
+ fragment VendorDateTimeFields on VendorDateTimeType {
844
+ dateStatus
845
+ endDate
846
+ endTime
847
+ startDate
848
+ startTime
849
+ }
850
+ `;
851
+ var VENDOR_PRODUCT_LIST_FIELDS_FRAGMENT = import_client6.gql`
852
+ fragment VendorProductListFields on VendorProductListType {
853
+ description
854
+ name
855
+ price
856
+ priceUnit
857
+ productGroups
858
+ }
859
+ `;
860
+ var VENDOR = import_client6.gql`
861
+ fragment VendorFields on VendorType {
862
+ _id
863
+ active
864
+ associates {
865
+ ...AssociatesFields
866
+ }
867
+ adIds
868
+ approvedAt
869
+ availability {
870
+ corporate
871
+ private
872
+ school
873
+ }
874
+ vendorInfoId
875
+ categories {
876
+ ...CategoryFields
877
+ }
878
+ calendar {
879
+ active
880
+ calendarData {
881
+ dateTime {
882
+ ...VendorDateTimeFields
883
+ }
884
+ description
885
+ location {
886
+ ...LocationFields
887
+ }
888
+ }
889
+ }
890
+ contactDetails {
891
+ ...ContactDetailsFields
892
+ }
893
+ cover {
894
+ ...ResourceImageFields
895
+ }
896
+ createdAt
897
+ claimed
898
+ description
899
+ deletedAt
900
+ foodTruck
901
+ images {
902
+ ...ResourceImageFields
903
+ }
904
+ logo {
905
+ ...ResourceImageFields
906
+ }
907
+ name
908
+ owner {
909
+ ...OwnerFields
910
+ }
911
+ products {
912
+ active
913
+ productsList {
914
+ ...VendorProductListFields
915
+ }
916
+ }
917
+ promoCodes
918
+ posterUsage {
919
+ ...PosterUsageFields
920
+ }
921
+ rating
922
+ region
923
+ reviewCount
924
+ relatedPost {
925
+ ...RelatedPostFields
926
+ }
927
+ relations {
928
+ relationId
929
+ relationDates {
930
+ ...RelationDates
931
+ }
932
+ }
933
+ slug
934
+ socialMedia {
935
+ ...SocialMediaFields
936
+ }
937
+ sharePublic {
938
+ ...SocialShareResourceFields
939
+ }
940
+ shareRelation {
941
+ ...SocialShareResourceFields
942
+ }
943
+ termsAgreement {
944
+ ...TermsAgreementFields
945
+ }
946
+ updatedAt
947
+ vendorType
948
+ unregisteredVendorId
949
+ }
950
+ ${CATEGORY_FIELDS_FRAGMENT}
951
+ ${VENDOR_DATETIME_FIELDS_FRAGMENT}
952
+ ${LOCATION_FIELDS_FRAGMENT}
953
+ ${OWNER_FIELDS_FRAGMENT}
954
+ ${RESOURCE_IMAGE_FIELDS_FRAGMENT}
955
+ ${SOCIAL_MEDIA_FIELDS_FRAGMENT}
956
+ ${POSTER_USAGE_FIELDS_FRAGMENT}
957
+ ${ASSOCIATES_FIELDS_FRAGMENT}
958
+ ${VENDOR_PRODUCT_LIST_FIELDS_FRAGMENT}
959
+ ${CONTACT_DETAILS_FIELDS_FRAGMENT}
960
+ ${TERMS_AGREEMENT_FIELDS_FRAGMENT}
961
+ ${RELATION_DATES_FRAGMENT}
962
+ ${RELATED_POST_FIELDS_FRAGMENT}
963
+ ${SOCIAL_SHARE_RESOURCE_FIELDS_FRAGMENT}
964
+ `;
965
+ var VENDOR_ATTRIBUTES_FRAGMENT = import_client6.gql`
966
+ fragment VendorAttributesFields on VendorAttributesType {
967
+ details
968
+ isRequired
969
+ }
970
+ `;
971
+ var VENDOR_INFO = import_client6.gql`
972
+ fragment VendorInfoFields on VendorInfoType {
973
+ _id
974
+ compliance {
975
+ foodBeverageLicense
976
+ liabilityInsurance
977
+ }
978
+ documents {
979
+ ...ResourceImageFields
980
+ }
981
+ requirements {
982
+ electricity {
983
+ ...VendorAttributesFields
984
+ }
985
+ gazebo {
986
+ ...VendorAttributesFields
987
+ }
988
+ table {
989
+ ...VendorAttributesFields
990
+ }
991
+ }
992
+ product {
993
+ foodFlavors
994
+ packaging
995
+ priceRange {
996
+ max
997
+ min
998
+ }
999
+ producedIn
1000
+ }
1001
+ stallInfo {
1002
+ size {
1003
+ depth
1004
+ width
1005
+ }
1006
+ }
1007
+ vendorId
1008
+ }
1009
+ ${VENDOR_ATTRIBUTES_FRAGMENT}
1010
+ ${RESOURCE_IMAGE_FIELDS_FRAGMENT}
1011
+ `;
1012
+ var UNREGISTERED_VENDOR_INVITATION_FRAGMENT = import_client6.gql`
1013
+ fragment UnregisteredVendorInvitationFields on UnregisteredVendorInvitationType {
1014
+ dateTime {
1015
+ ...DateTimeFields
1016
+ }
1017
+ inviterId
1018
+ }
1019
+ ${DATETIME_FIELDS_FRAGMENT}
1020
+ `;
1021
+ var UNREGISTERED_VENDOR = import_client6.gql`
1022
+ fragment UnregisteredVendorFields on UnregisteredVendorType {
1023
+ _id
1024
+ active
1025
+ categoryIds
1026
+ claimed
1027
+ createdAt
1028
+ deletedAt
1029
+ email
1030
+ invitations {
1031
+ ...UnregisteredVendorInvitationFields
1032
+ }
1033
+ name
1034
+ region
1035
+ updatedAt
1036
+ }
1037
+ ${UNREGISTERED_VENDOR_INVITATION_FRAGMENT}
1038
+ `;
1039
+ var GET_VENDORS = import_client6.gql`
1040
+ query getVendors {
1041
+ vendors {
1042
+ ...VendorFields
1043
+ }
1044
+ }
1045
+ ${VENDOR}
1046
+ `;
1047
+ var GET_VENDOR = import_client6.gql`
1048
+ query getVendor($_id: ID!) {
1049
+ vendor(_id: $_id) {
1050
+ ...VendorFields
1051
+ }
1052
+ }
1053
+ ${VENDOR}
1054
+ `;
1055
+ var GET_VENDORS_BY_REGION = import_client6.gql`
1056
+ query getVendorsByRegion(
1057
+ $region: String!
1058
+ $options: ResourcesByRegionOptions
1059
+ ) {
1060
+ vendorsByRegion(region: $region, options: $options) {
1061
+ ...VendorFields
1062
+ }
1063
+ }
1064
+ ${VENDOR}
1065
+ `;
1066
+ var SEARCH_VENDORS = import_client6.gql`
1067
+ query searchVendors($search: String!, $region: String!) {
1068
+ vendorSearch(search: $search, region: $region) {
1069
+ ...VendorFields
1070
+ }
1071
+ }
1072
+ ${VENDOR}
1073
+ `;
1074
+ var GET_VENDOR_INFO = import_client6.gql`
1075
+ query getVendorInfo($vendorId: ID!) {
1076
+ vendorInfo(vendorId: $vendorId) {
1077
+ ...VendorInfoFields
1078
+ }
1079
+ }
1080
+ ${VENDOR_INFO}
1081
+ `;
1082
+ var GET_UNREGISTERED_VENDORS = import_client6.gql`
1083
+ query getUnregisteredVendors {
1084
+ unregisteredVendors {
1085
+ ...UnregisteredVendorFields
1086
+ }
1087
+ }
1088
+ ${UNREGISTERED_VENDOR}
1089
+ `;
1090
+ var GET_UNREGISTERED_VENDORS_BY_INVITER_ID = import_client6.gql`
1091
+ query getUnregisteredVendorsByInviterId($inviterId: ID!) {
1092
+ unregisteredVendorsByInviterId(inviterId: $inviterId) {
1093
+ ...UnregisteredVendorFields
1094
+ }
1095
+ }
1096
+ ${UNREGISTERED_VENDOR}
1097
+ `;
1098
+ var GET_UNREGISTERED_VENDOR = import_client6.gql`
1099
+ query getUnregisteredVendor($_id: ID!) {
1100
+ unregisteredVendor(_id: $_id) {
1101
+ ...UnregisteredVendorFields
1102
+ }
1103
+ }
1104
+ ${UNREGISTERED_VENDOR}
1105
+ `;
1106
+
1107
+ // src/graphql/queries/user.ts
1108
+ var GET_USERS = import_client7.gql`
1109
+ query getUsers {
1110
+ users {
1111
+ ...UserFields
1112
+ }
1113
+ }
1114
+ ${USER_FIELDS_FRAGMENT}
1115
+ `;
1116
+ var GET_USER = import_client7.gql`
1117
+ query getUser($_id: ID!) {
1118
+ user(_id: $_id) {
1119
+ ...UserFields
1120
+ }
1121
+ }
1122
+ ${USER_FIELDS_FRAGMENT}
1123
+ `;
1124
+ var GET_USER_EVENTS = import_client7.gql`
1125
+ query getUserEvents {
1126
+ userEvents {
1127
+ ...EventFields
1128
+ }
1129
+ }
1130
+ ${EVENT}
1131
+ `;
1132
+ var GET_USER_VENDORS = import_client7.gql`
1133
+ query getUserVendors {
1134
+ userVendors {
1135
+ ...VendorFields
1136
+ }
1137
+ }
1138
+ ${VENDOR}
1139
+ `;
1140
+ var GET_USER_PARTNERS = import_client7.gql`
1141
+ query getUserPartners {
1142
+ userPartners {
1143
+ ...PartnerFields
1144
+ }
1145
+ }
1146
+ ${PARTNER}
1147
+ `;
1148
+ var GET_USER_ACTIVITIES = import_client7.gql`
1149
+ query getUserActivities {
1150
+ userActivities {
1151
+ favourites {
1152
+ events {
1153
+ ...EventListItemFields
1154
+ }
1155
+ partners {
1156
+ ...PartnerFields
1157
+ }
1158
+ vendors {
1159
+ ...VendorFields
1160
+ }
1161
+ }
1162
+ going {
1163
+ events {
1164
+ ...EventListItemFields
1165
+ }
1166
+ }
1167
+ interested {
1168
+ events {
1169
+ ...EventListItemFields
1170
+ }
1171
+ }
1172
+ present {
1173
+ events {
1174
+ ...EventListItemFields
1175
+ }
1176
+ }
1177
+ }
1178
+ }
1179
+ ${EVENT_LIST_ITEM}
1180
+ ${VENDOR}
1181
+ ${PARTNER}
1182
+ `;
1183
+ var GET_USER_RESOURCES = import_client7.gql`
1184
+ query getUserResources($userId: ID!) {
1185
+ userResources(userId: $userId) {
1186
+ resources {
1187
+ _id
1188
+ logo
1189
+ name
1190
+ resourceType
1191
+ }
1192
+ }
1193
+ }
1194
+ `;
1195
+
1196
+ // src/graphql/hooks/user/hooksQuery.ts
1197
+ var useGetUser = (_id) => {
1198
+ const { loading, error, data, refetch } = (0, import_client8.useQuery)(
1199
+ GET_USER,
1200
+ {
1201
+ fetchPolicy: "network-only",
1202
+ skip: !_id || _id === "",
1203
+ variables: { _id }
1204
+ }
1205
+ );
1206
+ const user = data?.user;
1207
+ return { error, loading, refetch, user };
1208
+ };
1209
+
1210
+ // src/storage/index.ts
1211
+ var USER_STORAGE_KEY = "authUser";
1212
+
1213
+ // src/auth/useAuthCore.ts
1214
+ function useAuthCore(adapters) {
1215
+ const {
1216
+ storage,
1217
+ authManager,
1218
+ afterLogout,
1219
+ shouldCallLogoutMutation = () => true,
1220
+ notifyLogoutSuccess,
1221
+ notifySessionExpired,
1222
+ onError
1223
+ } = adapters;
1224
+ const [authUser, setAuthUser] = (0, import_react.useState)(null);
1225
+ const [isLoading, setIsLoading] = (0, import_react.useState)(true);
1226
+ const userId = (0, import_react.useMemo)(() => authUser?._id ?? "", [authUser?._id]);
1227
+ const { refetch } = useGetUser(userId);
1228
+ const { logout, loading } = useLogout();
1229
+ const handleSetAuthUser = (0, import_react.useCallback)(
1230
+ async (user) => {
1231
+ setAuthUser(user);
1232
+ if (user) {
1233
+ await storage.setItem(USER_STORAGE_KEY, JSON.stringify(user));
1234
+ } else {
1235
+ await storage.removeItem(USER_STORAGE_KEY);
1236
+ }
1237
+ },
1238
+ [storage]
1239
+ );
1240
+ const handleRefetchUser = (0, import_react.useCallback)(async () => {
1241
+ if (!authUser) return;
1242
+ try {
1243
+ const result = await refetch();
1244
+ if (!result) return;
1245
+ const { data } = result;
1246
+ if (data?.user) await handleSetAuthUser(data.user);
1247
+ } catch (error) {
1248
+ onError?.(error, { action: "refetchUser" });
1249
+ console.warn(
1250
+ "Failed to refetch user:",
1251
+ error instanceof Error ? error.message : error
1252
+ );
1253
+ }
1254
+ }, [authUser, handleSetAuthUser, onError, refetch]);
1255
+ const licences = (0, import_react.useCallback)(
1256
+ (resourceId) => {
1257
+ if (resourceId === "")
1258
+ return {
1259
+ event: { pro: true, pro_plus: false, standard: false },
1260
+ partner: { pro: false, pro_plus: false, standard: true },
1261
+ vendor: { pro: true, pro_plus: false, standard: false }
1262
+ };
1263
+ const myLicences = authUser?.licences?.map((licence) => licence.licenceType) ?? [];
1264
+ const associateLicences = authUser?.associates?.map(
1265
+ (associate) => associate.licence.licenceType
1266
+ ) ?? [];
1267
+ const myResourceIds = [
1268
+ authUser?.vendor ?? null,
1269
+ authUser?.partner ?? null,
1270
+ ...authUser?.events ?? []
1271
+ ].filter((id) => id !== null);
1272
+ return myResourceIds.includes(resourceId) ? getLicenceFlagsByRole(myLicences) : getLicenceFlagsByRole(associateLicences);
1273
+ },
1274
+ [authUser]
1275
+ );
1276
+ const getLicenseAccessLevel = (0, import_react.useCallback)(
1277
+ (limitType, resourceId, resourceType) => {
1278
+ if (!isLicencedResourceType(resourceType)) {
1279
+ return 0;
1280
+ }
1281
+ const roleLicences = licences(resourceId)[resourceType];
1282
+ if (roleLicences.pro_plus) return DEFAULT_LIMITS[limitType].pro_plus;
1283
+ if (roleLicences.pro) return DEFAULT_LIMITS[limitType].pro;
1284
+ if (roleLicences.standard) return DEFAULT_LIMITS[limitType].standard;
1285
+ return 0;
1286
+ },
1287
+ [licences]
1288
+ );
1289
+ const hasVendorLicence = (0, import_react.useMemo)(
1290
+ () => hasLicence(authUser, "vendor"),
1291
+ [authUser]
1292
+ );
1293
+ const hasPartnerLicence = (0, import_react.useMemo)(
1294
+ () => hasLicence(authUser, "partner"),
1295
+ [authUser]
1296
+ );
1297
+ const hasEventLicence = (0, import_react.useMemo)(
1298
+ () => hasLicence(authUser, "event"),
1299
+ [authUser]
1300
+ );
1301
+ const hasUserLicence = (0, import_react.useCallback)(
1302
+ (licenceType) => hasUserLicenceType(authUser, licenceType),
1303
+ [authUser]
1304
+ );
1305
+ const isAdmin = (0, import_react.useMemo)(
1306
+ () => authUser?.role === "admin" /* ADMIN */,
1307
+ [authUser?.role]
1308
+ );
1309
+ const isSuperAdmin = (0, import_react.useMemo)(
1310
+ () => authUser?.role === "super_admin" /* SUPER_ADMIN */ && authUser?.email === SUPER_ADMIN_EMAIL,
1311
+ [authUser?.role, authUser?.email]
1312
+ );
1313
+ const isAffiliate = (0, import_react.useMemo)(
1314
+ () => authUser?.role === "affiliate" /* AFFILIATE */ && authUser?.affiliate !== null,
1315
+ [authUser?.role, authUser?.affiliate]
1316
+ );
1317
+ const isSchool = (0, import_react.useMemo)(
1318
+ () => authUser?.role === "school" /* SCHOOL */ && authUser?.school !== null,
1319
+ [authUser?.school]
1320
+ );
1321
+ (0, import_react.useEffect)(() => {
1322
+ const loadUser = async () => {
1323
+ try {
1324
+ const userJson = await storage.getItem(USER_STORAGE_KEY);
1325
+ await handleSetAuthUser(userJson ? JSON.parse(userJson) : null);
1326
+ } catch (error) {
1327
+ onError?.(error, { action: "loadUserFromStorage" });
1328
+ console.error("Failed to load user from storage:", error);
1329
+ } finally {
1330
+ setIsLoading(false);
1331
+ }
1332
+ };
1333
+ void loadUser();
1334
+ }, []);
1335
+ const logoutWithReason = (0, import_react.useCallback)(
1336
+ async (reason) => {
1337
+ try {
1338
+ if (shouldCallLogoutMutation(reason)) {
1339
+ try {
1340
+ const result = await logout();
1341
+ const message = result?.data?.logout?.message;
1342
+ if (message) {
1343
+ notifyLogoutSuccess?.(message);
1344
+ }
1345
+ } catch (err) {
1346
+ onError?.(err, { action: "logout" });
1347
+ console.warn("Logout request failed (ignored):", err);
1348
+ }
1349
+ }
1350
+ } finally {
1351
+ await afterLogout(reason);
1352
+ setAuthUser(null);
1353
+ await storage.removeItem(USER_STORAGE_KEY);
1354
+ }
1355
+ },
1356
+ [
1357
+ afterLogout,
1358
+ logout,
1359
+ notifyLogoutSuccess,
1360
+ onError,
1361
+ shouldCallLogoutMutation,
1362
+ storage
1363
+ ]
1364
+ );
1365
+ const handleLogoutExplicit = (0, import_react.useCallback)(
1366
+ () => logoutWithReason("manual"),
1367
+ [logoutWithReason]
1368
+ );
1369
+ const handleLogoutExpired = (0, import_react.useCallback)(async () => {
1370
+ const hadSession = authUser != null;
1371
+ if (!hadSession) return;
1372
+ await logoutWithReason("expired");
1373
+ notifySessionExpired?.();
1374
+ }, [authUser, logoutWithReason, notifySessionExpired]);
1375
+ (0, import_react.useEffect)(() => {
1376
+ authManager.setLogout(() => handleLogoutExpired());
1377
+ authManager.setUserRefetch(() => handleRefetchUser());
1378
+ }, [authManager, handleLogoutExpired, handleRefetchUser]);
1379
+ return {
1380
+ authUser,
1381
+ getLicenseAccessLevel,
1382
+ handleLogoutExplicit,
1383
+ hasEventLicence,
1384
+ hasPartnerLicence,
1385
+ hasUserLicence,
1386
+ hasVendorLicence,
1387
+ isAdmin,
1388
+ isAffiliate,
1389
+ isLoading: loading || isLoading,
1390
+ isSchool,
1391
+ isSuperAdmin,
1392
+ refetchUser: handleRefetchUser,
1393
+ setUser: handleSetAuthUser
1394
+ };
1395
+ }
1396
+
1397
+ // src/auth/UserProvider.tsx
1398
+ var import_react2 = require("react");
1399
+ var import_jsx_runtime = require("react/jsx-runtime");
1400
+ var UserContext = (0, import_react2.createContext)(void 0);
1401
+ var UserProvider = ({ children, value }) => {
1402
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(UserContext.Provider, { value, children });
1403
+ };
1404
+ var useAuthUser = () => {
1405
+ const context = (0, import_react2.useContext)(UserContext);
1406
+ if (!context) {
1407
+ throw new Error("useAuthUser must be used within a UserProvider");
1408
+ }
1409
+ return context;
1410
+ };
1411
+ // Annotate the CommonJS export names for ESM import in node:
1412
+ 0 && (module.exports = {
1413
+ DEFAULT_LIMITS,
1414
+ SUPER_ADMIN_EMAIL,
1415
+ UserProvider,
1416
+ createAuthManager,
1417
+ getLicenceFlagsByRole,
1418
+ hasLicence,
1419
+ hasUserLicenceType,
1420
+ isLicencedResourceType,
1421
+ isProfileBadgeLicence,
1422
+ useAuthCore,
1423
+ useAuthUser
1424
+ });
1425
+ //# sourceMappingURL=index.cjs.map