@react-pakistan/util-functions 1.25.89 → 2.0.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.
Files changed (412) hide show
  1. package/README.md +74 -315
  2. package/constants/api-methods.d.ts +3 -1
  3. package/constants/api-methods.js +1 -15
  4. package/constants/cache-time.d.ts +7 -5
  5. package/constants/cache-time.js +1 -8
  6. package/constants/countries-timezones.d.ts +4 -2
  7. package/constants/countries-timezones.js +1 -1411
  8. package/constants/currencies.d.ts +4 -2
  9. package/constants/currencies.js +1 -1076
  10. package/constants/dial-codes.d.ts +5 -3
  11. package/constants/dial-codes.js +1 -1216
  12. package/constants/layout-direction.d.ts +3 -1
  13. package/constants/layout-direction.js +1 -8
  14. package/constants/react-pakistan-meta.d.ts +4 -2
  15. package/constants/react-pakistan-meta.js +1 -35
  16. package/constants/react-pakistan.d.ts +5 -3
  17. package/constants/react-pakistan.js +12 -104
  18. package/constants/select-value-delimiter.d.ts +3 -1
  19. package/constants/select-value-delimiter.js +1 -13
  20. package/constants/social-media-colors.d.ts +3 -1
  21. package/constants/social-media-colors.js +1 -42
  22. package/constants/social-media-sizes.d.ts +6 -4
  23. package/constants/social-media-sizes.js +1 -327
  24. package/constants/user-roles.d.ts +3 -1
  25. package/constants/user-roles.js +1 -9
  26. package/edu-pilot-pro/types/academics.d.ts +2 -0
  27. package/edu-pilot-pro/types/academics.js +1 -0
  28. package/edu-pilot-pro/types/admission.d.ts +878 -0
  29. package/edu-pilot-pro/types/admission.js +1 -0
  30. package/edu-pilot-pro/types/communication.d.ts +2 -0
  31. package/edu-pilot-pro/types/communication.js +1 -0
  32. package/edu-pilot-pro/types/enums.d.ts +413 -0
  33. package/edu-pilot-pro/types/enums.js +1 -0
  34. package/edu-pilot-pro/types/finance.d.ts +2 -0
  35. package/edu-pilot-pro/types/finance.js +1 -0
  36. package/edu-pilot-pro/types/index.d.ts +2 -0
  37. package/edu-pilot-pro/types/index.js +1 -0
  38. package/edu-pilot-pro/types/user-management.d.ts +2 -0
  39. package/edu-pilot-pro/types/user-management.js +1 -0
  40. package/factory/generic-component-factory.d.ts +12 -9
  41. package/factory/generic-component-factory.js +1 -131
  42. package/factory/generic-module-factory.d.ts +14 -10
  43. package/factory/generic-module-factory.js +1 -190
  44. package/general/basic-get.d.ts +8 -1
  45. package/general/basic-get.js +1 -83
  46. package/general/basic-post.d.ts +8 -1
  47. package/general/basic-post.js +1 -70
  48. package/general/calculate-pages.d.ts +9 -1
  49. package/general/calculate-pages.js +1 -7
  50. package/general/camel-to-sentence-case.d.ts +3 -1
  51. package/general/camel-to-sentence-case.js +1 -20
  52. package/general/check-even-odd-length.d.ts +3 -1
  53. package/general/check-even-odd-length.js +1 -17
  54. package/general/clear-cache.d.ts +7 -2
  55. package/general/clear-cache.js +1 -12
  56. package/general/cnic-formatter.d.ts +16 -3
  57. package/general/cnic-formatter.js +1 -53
  58. package/general/convert-url-to-base64.d.ts +8 -6
  59. package/general/convert-url-to-base64.js +1 -231
  60. package/general/countries.d.ts +5 -3
  61. package/general/countries.js +1 -514
  62. package/general/create-date.d.ts +3 -1
  63. package/general/create-date.js +1 -22
  64. package/general/crypto.d.ts +4 -2
  65. package/general/crypto.js +1 -45
  66. package/general/currencies.d.ts +2 -0
  67. package/general/currencies.js +0 -1077
  68. package/general/delete-image-from-private-supabase.d.ts +10 -2
  69. package/general/delete-image-from-private-supabase.js +1 -66
  70. package/general/delete-image-from-public-supabase.d.ts +10 -2
  71. package/general/delete-image-from-public-supabase.js +1 -66
  72. package/general/download-from-url.d.ts +8 -1
  73. package/general/download-from-url.js +1 -82
  74. package/general/dynamic-page-limit.d.ts +9 -3
  75. package/general/dynamic-page-limit.js +1 -7
  76. package/general/enum-to-text.d.ts +8 -1
  77. package/general/enum-to-text.js +1 -11
  78. package/general/fetch-data.d.ts +16 -4
  79. package/general/fetch-data.js +1 -95
  80. package/general/fetch-supabase-image.d.ts +11 -2
  81. package/general/fetch-supabase-image.js +1 -67
  82. package/general/fetch-supabase-private-assets.d.ts +11 -2
  83. package/general/fetch-supabase-private-assets.js +1 -69
  84. package/general/format-date.d.ts +10 -2
  85. package/general/format-date.js +1 -49
  86. package/general/format-number.d.ts +12 -2
  87. package/general/format-number.js +1 -35
  88. package/general/format-phone-display.d.ts +9 -1
  89. package/general/format-phone-display.js +1 -32
  90. package/general/format-phone.d.ts +10 -2
  91. package/general/format-phone.js +1 -20
  92. package/general/format-pricing.d.ts +8 -1
  93. package/general/format-pricing.js +1 -23
  94. package/general/format-secs.d.ts +8 -1
  95. package/general/format-secs.js +1 -21
  96. package/general/format-time.d.ts +8 -2
  97. package/general/format-time.js +1 -38
  98. package/general/format-value.d.ts +8 -1
  99. package/general/format-value.js +1 -7
  100. package/general/full-month-range.d.ts +3 -2
  101. package/general/full-month-range.js +1 -24
  102. package/general/full-year-range.d.ts +3 -2
  103. package/general/full-year-range.js +1 -20
  104. package/general/generate-article-schema.d.ts +3 -2
  105. package/general/generate-article-schema.js +1 -100
  106. package/general/generate-blog-schema.d.ts +3 -2
  107. package/general/generate-blog-schema.js +1 -32
  108. package/general/generate-book-schema.d.ts +3 -2
  109. package/general/generate-book-schema.js +1 -109
  110. package/general/generate-breadcrumb-schema.d.ts +3 -2
  111. package/general/generate-breadcrumb-schema.js +1 -34
  112. package/general/generate-carousel-schema.d.ts +3 -2
  113. package/general/generate-carousel-schema.js +1 -172
  114. package/general/generate-course-schema.d.ts +3 -2
  115. package/general/generate-course-schema.js +1 -124
  116. package/general/generate-dataset-schema.d.ts +3 -2
  117. package/general/generate-dataset-schema.js +1 -156
  118. package/general/generate-discussion-forum-schema.d.ts +3 -2
  119. package/general/generate-discussion-forum-schema.js +1 -67
  120. package/general/generate-education-schema.d.ts +3 -2
  121. package/general/generate-education-schema.js +1 -137
  122. package/general/generate-employer-aggregate-rating-schema.d.ts +3 -2
  123. package/general/generate-employer-aggregate-rating-schema.js +1 -64
  124. package/general/generate-event-schema.d.ts +3 -2
  125. package/general/generate-event-schema.js +1 -214
  126. package/general/generate-faq-schema.d.ts +3 -2
  127. package/general/generate-faq-schema.js +1 -43
  128. package/general/generate-grid.d.ts +3 -2
  129. package/general/generate-grid.js +1 -55
  130. package/general/generate-image-metadata-schema.d.ts +3 -2
  131. package/general/generate-image-metadata-schema.js +1 -73
  132. package/general/generate-job-posting-schema.d.ts +3 -2
  133. package/general/generate-job-posting-schema.js +1 -120
  134. package/general/generate-local-business-schema.d.ts +3 -2
  135. package/general/generate-local-business-schema.js +1 -75
  136. package/general/generate-math-solver-schema.d.ts +3 -2
  137. package/general/generate-math-solver-schema.js +1 -83
  138. package/general/generate-movie-carousel-schema.d.ts +3 -2
  139. package/general/generate-movie-carousel-schema.js +1 -160
  140. package/general/generate-organization-schema.d.ts +3 -2
  141. package/general/generate-organization-schema.js +1 -39
  142. package/general/generate-profile-page-schema.d.ts +3 -2
  143. package/general/generate-profile-page-schema.js +1 -82
  144. package/general/generate-qa-page-schema.d.ts +3 -2
  145. package/general/generate-qa-page-schema.js +1 -67
  146. package/general/generate-recipe-schema.d.ts +3 -2
  147. package/general/generate-recipe-schema.js +1 -104
  148. package/general/generate-ref.d.ts +8 -2
  149. package/general/generate-ref.js +1 -12
  150. package/general/generate-review-snippet-schema.d.ts +3 -2
  151. package/general/generate-review-snippet-schema.js +1 -137
  152. package/general/generate-shopping-loyalty-program-schema.d.ts +3 -2
  153. package/general/generate-shopping-loyalty-program-schema.js +1 -59
  154. package/general/generate-shopping-merchant-listing-schema.d.ts +3 -2
  155. package/general/generate-shopping-merchant-listing-schema.js +1 -153
  156. package/general/generate-shopping-merchant-return-policy-schema.d.ts +3 -2
  157. package/general/generate-shopping-merchant-return-policy-schema.js +1 -68
  158. package/general/generate-shopping-merchant-shipping-policy-schema.d.ts +3 -2
  159. package/general/generate-shopping-merchant-shipping-policy-schema.js +1 -74
  160. package/general/generate-shopping-overview-schema.d.ts +3 -2
  161. package/general/generate-shopping-overview-schema.js +1 -157
  162. package/general/generate-shopping-product-snippet-schema.d.ts +3 -2
  163. package/general/generate-shopping-product-snippet-schema.js +1 -167
  164. package/general/generate-shopping-variants-schema.d.ts +3 -2
  165. package/general/generate-shopping-variants-schema.js +1 -143
  166. package/general/generate-software-app-schema.d.ts +3 -2
  167. package/general/generate-software-app-schema.js +1 -143
  168. package/general/generate-speakable-schema.d.ts +3 -2
  169. package/general/generate-speakable-schema.js +1 -139
  170. package/general/generate-subscription-schema.d.ts +3 -2
  171. package/general/generate-subscription-schema.js +1 -133
  172. package/general/generate-vacation-rental-schema.d.ts +3 -2
  173. package/general/generate-vacation-rental-schema.js +1 -135
  174. package/general/generate-video-schema.d.ts +3 -2
  175. package/general/generate-video-schema.js +1 -163
  176. package/general/generic-cache.d.ts +17 -15
  177. package/general/generic-cache.js +1 -659
  178. package/general/get-available-page-limit.d.ts +8 -2
  179. package/general/get-available-page-limit.js +1 -31
  180. package/general/get-calendar-current-month.d.ts +11 -3
  181. package/general/get-calendar-current-month.js +1 -31
  182. package/general/get-calendar-dates.d.ts +11 -3
  183. package/general/get-calendar-dates.js +1 -42
  184. package/general/get-calendar-next-month.d.ts +12 -3
  185. package/general/get-calendar-next-month.js +1 -32
  186. package/general/get-calendar-previous-month.d.ts +12 -3
  187. package/general/get-calendar-previous-month.js +1 -36
  188. package/general/get-current-year.d.ts +7 -1
  189. package/general/get-current-year.js +1 -5
  190. package/general/get-day-name.d.ts +5 -3
  191. package/general/get-day-name.js +1 -14
  192. package/general/get-dial-code.d.ts +8 -1
  193. package/general/get-dial-code.js +1 -8
  194. package/general/get-full-name.d.ts +9 -2
  195. package/general/get-full-name.js +1 -8
  196. package/general/get-href.d.ts +3 -1
  197. package/general/get-href.js +1 -13
  198. package/general/get-month-name.d.ts +5 -3
  199. package/general/get-month-name.js +1 -19
  200. package/general/get-month-number.d.ts +5 -3
  201. package/general/get-month-number.js +1 -29
  202. package/general/get-number-of-days-in-month.d.ts +9 -2
  203. package/general/get-number-of-days-in-month.js +1 -12
  204. package/general/get-pathname.d.ts +3 -1
  205. package/general/get-pathname.js +1 -16
  206. package/general/get-week-day.d.ts +8 -1
  207. package/general/get-week-day.js +1 -9
  208. package/general/image-url-to-base64.d.ts +3 -1
  209. package/general/image-url-to-base64.js +1 -80
  210. package/general/is-created-or-updated.d.ts +3 -1
  211. package/general/is-created-or-updated.js +1 -26
  212. package/general/is-next-button-disabled.d.ts +9 -1
  213. package/general/is-next-button-disabled.js +1 -5
  214. package/general/is-odd.d.ts +3 -1
  215. package/general/is-odd.js +1 -13
  216. package/general/is-previous-button-disabled.d.ts +8 -1
  217. package/general/is-previous-button-disabled.js +1 -7
  218. package/general/linear-gradients.d.ts +4 -2
  219. package/general/linear-gradients.js +1 -52
  220. package/general/multi-part-search.d.ts +10 -2
  221. package/general/multi-part-search.js +1 -16
  222. package/general/normalize-phone.d.ts +15 -2
  223. package/general/normalize-phone.js +1 -40
  224. package/general/parse-frontmatter.d.ts +11 -4
  225. package/general/parse-frontmatter.js +2 -35
  226. package/general/remove-data-image-prefix.d.ts +8 -1
  227. package/general/remove-data-image-prefix.js +1 -7
  228. package/general/repeat-times.d.ts +3 -1
  229. package/general/repeat-times.js +1 -21
  230. package/general/resolve-anchor-link.d.ts +3 -1
  231. package/general/resolve-anchor-link.js +1 -26
  232. package/general/resolve-current-date.d.ts +3 -1
  233. package/general/resolve-current-date.js +1 -22
  234. package/general/resolve-grid.d.ts +3 -1
  235. package/general/resolve-grid.js +1 -18
  236. package/general/resolve-initials.d.ts +3 -1
  237. package/general/resolve-initials.js +1 -17
  238. package/general/set-timezone.d.ts +11 -1
  239. package/general/set-timezone.js +1 -12
  240. package/general/slugify.d.ts +3 -1
  241. package/general/slugify.js +1 -24
  242. package/general/text-to-enum.d.ts +8 -1
  243. package/general/text-to-enum.js +1 -10
  244. package/general/text-to-sentence-case.d.ts +3 -1
  245. package/general/text-to-sentence-case.js +1 -16
  246. package/general/time-out.d.ts +3 -1
  247. package/general/time-out.js +1 -16
  248. package/general/time-zones.d.ts +3 -1
  249. package/general/time-zones.js +1 -437
  250. package/general/truncate-text.d.ts +3 -1
  251. package/general/truncate-text.js +1 -18
  252. package/general/type.d.ts +3 -1
  253. package/general/type.js +1 -2
  254. package/general/upload-blob-to-private-supabase.d.ts +14 -2
  255. package/general/upload-blob-to-private-supabase.js +1 -62
  256. package/general/upload-blob-to-public-supabase.d.ts +14 -2
  257. package/general/upload-blob-to-public-supabase.js +1 -62
  258. package/general/upload-image-to-private-supabase.d.ts +15 -3
  259. package/general/upload-image-to-private-supabase.js +1 -66
  260. package/general/upload-image-to-public-supabase.d.ts +15 -3
  261. package/general/upload-image-to-public-supabase.js +1 -66
  262. package/general/url-to-sentence-case.d.ts +3 -1
  263. package/general/url-to-sentence-case.js +1 -19
  264. package/general/validate-comment.d.ts +3 -1
  265. package/general/validate-comment.js +1 -21
  266. package/general/validate-email.d.ts +3 -1
  267. package/general/validate-email.js +1 -24
  268. package/general/validate-form.d.ts +12 -3
  269. package/general/validate-form.js +1 -29
  270. package/general/validate-name.d.ts +3 -1
  271. package/general/validate-name.js +1 -21
  272. package/hooks/use-change.d.ts +11 -2
  273. package/hooks/use-change.js +1 -23
  274. package/hooks/use-debounce.d.ts +10 -1
  275. package/hooks/use-debounce.js +1 -14
  276. package/hooks/use-fetch.d.ts +7 -5
  277. package/hooks/use-fetch.js +1 -239
  278. package/hooks/use-force-render.d.ts +6 -2
  279. package/hooks/use-force-render.js +1 -17
  280. package/hooks/use-ip-geo-location.d.ts +8 -1
  281. package/hooks/use-ip-geo-location.js +1 -79
  282. package/hooks/use-is-mobile.d.ts +8 -1
  283. package/hooks/use-is-mobile.js +1 -22
  284. package/hooks/use-module-entity-v2.d.ts +7 -4
  285. package/hooks/use-module-entity-v2.js +1 -188
  286. package/hooks/use-module-entity.d.ts +7 -4
  287. package/hooks/use-module-entity.js +1 -177
  288. package/hooks/use-phone-formatter.d.ts +10 -2
  289. package/hooks/use-phone-formatter.js +1 -23
  290. package/hooks/use-position.d.ts +6 -3
  291. package/hooks/use-position.js +1 -43
  292. package/hooks/use-rtl.d.ts +4 -2
  293. package/hooks/use-rtl.js +1 -84
  294. package/hooks/use-sticky.d.ts +3 -1
  295. package/hooks/use-sticky.js +1 -39
  296. package/hooks/use-toggle-state.d.ts +3 -2
  297. package/hooks/use-toggle-state.js +1 -26
  298. package/hooks/use-window-event-listener.d.ts +9 -1
  299. package/hooks/use-window-event-listener.js +1 -11
  300. package/hooks/with-seo.d.ts +11 -2
  301. package/hooks/with-seo.js +1 -37
  302. package/local-storage/get-storage-value.d.ts +5 -2
  303. package/local-storage/get-storage-value.js +1 -20
  304. package/local-storage/remove-storage-value.d.ts +3 -1
  305. package/local-storage/remove-storage-value.js +1 -14
  306. package/local-storage/set-storage-value.d.ts +3 -1
  307. package/local-storage/set-storage-value.js +1 -14
  308. package/local-storage/type.d.ts +3 -1
  309. package/local-storage/type.js +1 -2
  310. package/npm.d.d.ts +2 -0
  311. package/npm.d.js +0 -0
  312. package/package.json +20 -18
  313. package/storybook/generate-sitemap.d.ts +3 -1
  314. package/storybook/generate-sitemap.js +17 -26
  315. package/storybook/preview.d.ts +4 -2
  316. package/storybook/preview.js +1 -62
  317. package/storybook/react-design-story-script.d.ts +3 -1
  318. package/storybook/react-design-story-script.js +5 -27
  319. package/storybook/react-emoji-collection.d.ts +3 -1
  320. package/storybook/react-emoji-collection.js +10 -55
  321. package/storybook/react-emoji-story-script.d.ts +3 -1
  322. package/storybook/react-emoji-story-script.js +5 -31
  323. package/storybook/react-emoji-story-template.d.ts +3 -1
  324. package/storybook/react-emoji-story-template.js +45 -15
  325. package/storybook/react-icon-collection.d.ts +3 -1
  326. package/storybook/react-icon-collection.js +10 -42
  327. package/storybook/react-icon-story-script.d.ts +3 -1
  328. package/storybook/react-icon-story-script.js +5 -27
  329. package/storybook/react-icon-story-template.d.ts +3 -1
  330. package/storybook/react-icon-story-template.js +45 -14
  331. package/storybook/react-logo-collection.d.ts +3 -1
  332. package/storybook/react-logo-collection.js +10 -42
  333. package/storybook/react-logo-story-script.d.ts +3 -1
  334. package/storybook/react-logo-story-script.js +5 -27
  335. package/storybook/react-logo-story-template.d.ts +3 -1
  336. package/storybook/react-logo-story-template.js +45 -14
  337. package/storybook/react-pakistan-theme.d.ts +3 -1
  338. package/storybook/react-pakistan-theme.js +1 -31
  339. package/storybook/responsive-args.d.ts +11 -10
  340. package/storybook/responsive-args.js +1 -19
  341. package/storybook/responsive-component.d.ts +4 -2
  342. package/storybook/responsive-component.js +37 -23
  343. package/storybook/responsive-screens.d.ts +3 -1
  344. package/storybook/responsive-screens.js +1 -109
  345. package/storybook/theme.d.ts +17 -15
  346. package/storybook/theme.js +1 -1022
  347. package/api/stellar-solutions/app-user/index.d.ts +0 -51
  348. package/api/stellar-solutions/app-user/index.js +0 -210
  349. package/api/stellar-solutions/bank/index.d.ts +0 -59
  350. package/api/stellar-solutions/bank/index.js +0 -210
  351. package/api/stellar-solutions/branch/index.d.ts +0 -58
  352. package/api/stellar-solutions/branch/index.js +0 -220
  353. package/api/stellar-solutions/company/index.d.ts +0 -57
  354. package/api/stellar-solutions/company/index.js +0 -218
  355. package/api/stellar-solutions/company-report/index.d.ts +0 -15
  356. package/api/stellar-solutions/company-report/index.js +0 -74
  357. package/api/stellar-solutions/constants.d.ts +0 -19
  358. package/api/stellar-solutions/constants.js +0 -22
  359. package/api/stellar-solutions/contact/index.d.ts +0 -56
  360. package/api/stellar-solutions/contact/index.js +0 -217
  361. package/api/stellar-solutions/currency/index.d.ts +0 -55
  362. package/api/stellar-solutions/currency/index.js +0 -212
  363. package/api/stellar-solutions/customer/index.d.ts +0 -68
  364. package/api/stellar-solutions/customer/index.js +0 -249
  365. package/api/stellar-solutions/expense/index.d.ts +0 -58
  366. package/api/stellar-solutions/expense/index.js +0 -229
  367. package/api/stellar-solutions/expense-category/index.d.ts +0 -53
  368. package/api/stellar-solutions/expense-category/index.js +0 -214
  369. package/api/stellar-solutions/lead/index.d.ts +0 -51
  370. package/api/stellar-solutions/lead/index.js +0 -206
  371. package/api/stellar-solutions/menu-order/index.d.ts +0 -53
  372. package/api/stellar-solutions/menu-order/index.js +0 -202
  373. package/api/stellar-solutions/payment/index.d.ts +0 -65
  374. package/api/stellar-solutions/payment/index.js +0 -230
  375. package/api/stellar-solutions/payment-mode/index.d.ts +0 -53
  376. package/api/stellar-solutions/payment-mode/index.js +0 -191
  377. package/api/stellar-solutions/preference/index.d.ts +0 -25
  378. package/api/stellar-solutions/preference/index.js +0 -114
  379. package/api/stellar-solutions/product/index.d.ts +0 -64
  380. package/api/stellar-solutions/product/index.js +0 -235
  381. package/api/stellar-solutions/product-category/index.d.ts +0 -51
  382. package/api/stellar-solutions/product-category/index.js +0 -212
  383. package/api/stellar-solutions/profile/index.d.ts +0 -78
  384. package/api/stellar-solutions/profile/index.js +0 -234
  385. package/api/stellar-solutions/quote-invoice/index.d.ts +0 -97
  386. package/api/stellar-solutions/quote-invoice/index.js +0 -369
  387. package/api/stellar-solutions/quote-invoice-report/index.d.ts +0 -15
  388. package/api/stellar-solutions/quote-invoice-report/index.js +0 -74
  389. package/api/stellar-solutions/tax/index.d.ts +0 -55
  390. package/api/stellar-solutions/tax/index.js +0 -224
  391. package/api/stellar-solutions/types/common.d.ts +0 -24
  392. package/api/stellar-solutions/types/common.js +0 -22
  393. package/api/stellar-solutions/types/erp.d.ts +0 -302
  394. package/api/stellar-solutions/types/erp.js +0 -73
  395. package/api/stellar-solutions/types/index.d.ts +0 -3
  396. package/api/stellar-solutions/types/index.js +0 -19
  397. package/api/stellar-solutions/types/pos.d.ts +0 -176
  398. package/api/stellar-solutions/types/pos.js +0 -61
  399. package/constants/index.d.ts +0 -12
  400. package/constants/index.js +0 -28
  401. package/factory/index.d.ts +0 -2
  402. package/factory/index.js +0 -18
  403. package/general/index.d.ts +0 -95
  404. package/general/index.js +0 -111
  405. package/index.d.ts +0 -28
  406. package/index.js +0 -44
  407. package/local-storage/index.d.ts +0 -4
  408. package/local-storage/index.js +0 -20
  409. package/setupTests.d.ts +0 -1
  410. package/setupTests.js +0 -52
  411. package/storybook/index.d.ts +0 -17
  412. package/storybook/index.js +0 -33
@@ -1,659 +1 @@
1
- "use strict";
2
- /**
3
- * Generic Cache Utilities
4
- *
5
- * A lightweight localStorage-backed cache used by module-level cache wrappers.
6
- * Key behaviors:
7
- * - Default expiration: 1 day (configurable per cache)
8
- * - Search and filter requests bypass the cache and always fetch fresh data
9
- * - Lists are stored as a normalized map (id -> item) for fast lookups
10
- * - Provides both synchronous reads (`getCachedDataSync`) and async reads
11
- * with API fallback (`getCachedData`)
12
- * - Single-item helpers available (`getCachedSingleItem`, `getCachedSingleItemSync`)
13
- *
14
- * The main async helper `getCachedData` now accepts a single options object
15
- * (`GetCachedDataOptions`) which includes `config`, optional `searchQuery`,
16
- * `filters`, `pageLimit` and extra `params` for the list API. Module cache
17
- * wrappers should call `getCachedData({ config, searchQuery, filters, pageLimit, params, headers })`.
18
- * Both `getCachedData` and `getCachedSingleItem` accept an optional `headers`
19
- * object which will be forwarded to the underlying `fetchData` calls.
20
- *
21
- * Organization:
22
- * - Types
23
- * - List Cache Functions
24
- * - Single Item Cache Functions
25
- * - Cache Utilities
26
- */
27
- var __assign = (this && this.__assign) || function () {
28
- __assign = Object.assign || function(t) {
29
- for (var s, i = 1, n = arguments.length; i < n; i++) {
30
- s = arguments[i];
31
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
32
- t[p] = s[p];
33
- }
34
- return t;
35
- };
36
- return __assign.apply(this, arguments);
37
- };
38
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
39
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
40
- return new (P || (P = Promise))(function (resolve, reject) {
41
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
42
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
43
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
44
- step((generator = generator.apply(thisArg, _arguments || [])).next());
45
- });
46
- };
47
- var __generator = (this && this.__generator) || function (thisArg, body) {
48
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
49
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
50
- function verb(n) { return function (v) { return step([n, v]); }; }
51
- function step(op) {
52
- if (f) throw new TypeError("Generator is already executing.");
53
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
54
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
55
- if (y = 0, t) op = [op[0] & 2, t.value];
56
- switch (op[0]) {
57
- case 0: case 1: t = op; break;
58
- case 4: _.label++; return { value: op[1], done: false };
59
- case 5: _.label++; y = op[1]; op = [0]; continue;
60
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
61
- default:
62
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
63
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
64
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
65
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
66
- if (t[2]) _.ops.pop();
67
- _.trys.pop(); continue;
68
- }
69
- op = body.call(thisArg, _);
70
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
71
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
72
- }
73
- };
74
- Object.defineProperty(exports, "__esModule", { value: true });
75
- exports.isCacheStale = exports.preloadCache = exports.invalidateCache = exports.getCachedItemByIdAsync = exports.getCachedDataWithFallback = exports.getCachedSingleItem = exports.getCachedSingleItemSync = exports.getCachedItemById = exports.getCachedData = exports.getCachedDataSync = void 0;
76
- var constants_1 = require("../constants");
77
- var fetch_data_1 = require("./fetch-data");
78
- var local_storage_1 = require("../local-storage");
79
- // Type guards for cached shapes
80
- function isCachedArrayShape(v) {
81
- if (!v || typeof v !== 'object')
82
- return false;
83
- var o = v;
84
- return (Array.isArray(o.items) &&
85
- typeof o.cachedAt === 'string' &&
86
- typeof o.count === 'number');
87
- }
88
- function isCachedMapShape(v) {
89
- if (!v || typeof v !== 'object')
90
- return false;
91
- var o = v;
92
- return (o.items !== undefined &&
93
- typeof o.items === 'object' &&
94
- !Array.isArray(o.items) &&
95
- typeof o.cachedAt === 'string');
96
- }
97
- // ============================================================================
98
- // LIST CACHE FUNCTIONS
99
- // ============================================================================
100
- /**
101
- * Get synchronous cached data for a module
102
- * Returns empty result if cache is missing or stale
103
- *
104
- * @param cacheKey - localStorage key for the cache
105
- * @param expirationMs - Cache expiration time in milliseconds (default: 1 day)
106
- * @returns {count: number, items: T[]} - Cached data or empty array
107
- *
108
- * @example
109
- * const users = getCachedDataSync<UserBE>(LS_KEYS.USERS);
110
- * if (users.items.length > 0) {
111
- * console.log(users.items[0].name);
112
- * }
113
- */
114
- var getCachedDataSync = function (cacheKey, expirationMs) {
115
- var _a, _b, _c;
116
- if (expirationMs === void 0) { expirationMs = constants_1.ONE_DAY_IN_MS; }
117
- try {
118
- var raw = (0, local_storage_1.getStorageValue)(cacheKey);
119
- if (raw == null)
120
- return { count: 0, items: [] };
121
- var currentTime = new Date().getTime();
122
- if (isCachedArrayShape(raw)) {
123
- var cachedTime = new Date(raw.cachedAt).getTime();
124
- var ageInMs = currentTime - cachedTime;
125
- if (ageInMs < expirationMs) {
126
- return {
127
- count: (_a = raw.count) !== null && _a !== void 0 ? _a : raw.items.length,
128
- items: raw.items,
129
- currentPage: (_b = raw.currentPage) !== null && _b !== void 0 ? _b : undefined,
130
- };
131
- }
132
- return { count: 0, items: [] };
133
- }
134
- if (isCachedMapShape(raw)) {
135
- var cachedTime = new Date(raw.cachedAt).getTime();
136
- var ageInMs = currentTime - cachedTime;
137
- if (ageInMs < expirationMs) {
138
- var itemsArray = Object.values(raw.items || {});
139
- var storedCount = raw.count;
140
- return {
141
- count: storedCount !== null && storedCount !== void 0 ? storedCount : itemsArray.length,
142
- items: itemsArray,
143
- currentPage: (_c = raw.currentPage) !== null && _c !== void 0 ? _c : undefined,
144
- };
145
- }
146
- return { count: 0, items: [] };
147
- }
148
- return { count: 0, items: [] };
149
- }
150
- catch (error) {
151
- console.error("Error getting cached data for ".concat(cacheKey, ":"), error);
152
- return { count: 0, items: [] };
153
- }
154
- };
155
- exports.getCachedDataSync = getCachedDataSync;
156
- /**
157
- * Get cached data with API fallback for a module
158
- *
159
- * Accepts a single `GetCachedDataOptions` object. The function will return
160
- * cached results when fresh, or fetch from the API when the cache is stale
161
- * or when `searchQuery`/`filters` are present (those always bypass cache).
162
- *
163
- * @param opts - `GetCachedDataOptions` containing `config`, optional
164
- * `searchQuery`, `filters`, `pageLimit`, and extra `params`
165
- * @returns Promise<{count: number, items: T[]}> - Cached or fresh data
166
- *
167
- * @example
168
- * const config = { cacheKey: LS_KEYS.USERS, apiUrl: USER_API_ROUTES.LIST, responseKey: 'users' };
169
- * // Basic usage (reads cache if fresh)
170
- * const users = await getCachedData<UserBE>({ config });
171
- *
172
- * // With search (bypasses cache)
173
- * const filtered = await getCachedData<UserBE>({ config, searchQuery: 'John' });
174
- *
175
- * // With filters and custom page limit
176
- * const active = await getCachedData<UserBE>({ config, filters: { enabled: true }, pageLimit: 200 });
177
- */
178
- var getCachedData = function (opts) { return __awaiter(void 0, void 0, void 0, function () {
179
- var config, params, headers, cacheKey, apiUrl, responseKey, expirationMs, fallBackPageLimit, fallBackCurrentPage, filters, searchQuery, paramsWithoutFilters_1, otherParams_1, queryObj_1, searchParams_1, response_1, itemsRaw_1, items_1, respCurrentPageRaw_1, respCurrentPage_1, requestCurrentPage_1, raw, currentTime, cachedTime, ageInMs, cachedTime, ageInMs, itemsArray, storedCount, cachedCurrentPage, requestedCurrentPage, paramsWithoutFilters_2, otherParams_2, queryObj_2, searchParams_2, response_2, itemsRaw_2, fetchedItems, respCount, respCurrentPageRaw_2, respCurrentPage_2, newItemsMap, mergedItemsMap, mergedItemsArray, newCount, newCurrentPage, shouldCache_1, updatedCache, paramsWithoutFilters_3, otherParams, queryObj, searchParams, response, itemsRaw, items, count, respCurrentPageRaw, respCurrentPage, requestCurrentPage, shouldCache, itemsMap, updatedCache, error_1;
180
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
181
- return __generator(this, function (_v) {
182
- switch (_v.label) {
183
- case 0:
184
- config = opts.config, params = opts.params, headers = opts.headers;
185
- cacheKey = config.cacheKey, apiUrl = config.apiUrl, responseKey = config.responseKey;
186
- expirationMs = (_a = config.expirationMs) !== null && _a !== void 0 ? _a : constants_1.ONE_DAY_IN_MS;
187
- fallBackPageLimit = (_c = (_b = params === null || params === void 0 ? void 0 : params.pageLimit) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : '100';
188
- fallBackCurrentPage = (_e = (_d = params === null || params === void 0 ? void 0 : params.currentPage) === null || _d === void 0 ? void 0 : _d.toString()) !== null && _e !== void 0 ? _e : '1';
189
- filters = params === null || params === void 0 ? void 0 : params.filters;
190
- searchQuery = params === null || params === void 0 ? void 0 : params.searchQuery;
191
- _v.label = 1;
192
- case 1:
193
- _v.trys.push([1, 8, , 9]);
194
- if (!((searchQuery && searchQuery.trim()) || (params === null || params === void 0 ? void 0 : params.filters))) return [3 /*break*/, 3];
195
- paramsWithoutFilters_1 = __assign({}, (params || {}));
196
- if (paramsWithoutFilters_1.filters !== undefined) {
197
- delete paramsWithoutFilters_1.filters;
198
- }
199
- otherParams_1 = Object.keys(paramsWithoutFilters_1).reduce(function (acc, key) {
200
- acc[key] = String(paramsWithoutFilters_1[key]);
201
- return acc;
202
- }, {});
203
- queryObj_1 = __assign(__assign(__assign({ pageLimit: fallBackPageLimit, currentPage: fallBackCurrentPage }, (searchQuery && { searchQuery: searchQuery })), (filters
204
- ? Object.keys(filters).reduce(function (acc, key) {
205
- acc[key] = String(filters[key]);
206
- return acc;
207
- }, {})
208
- : {})), otherParams_1);
209
- searchParams_1 = new URLSearchParams(queryObj_1);
210
- return [4 /*yield*/, (0, fetch_data_1.fetchData)({
211
- url: "".concat(apiUrl, "?").concat(searchParams_1.toString()),
212
- method: constants_1.API_METHODS.GET,
213
- headers: headers,
214
- })];
215
- case 2:
216
- response_1 = _v.sent();
217
- itemsRaw_1 = responseKey
218
- ? (_f = response_1 === null || response_1 === void 0 ? void 0 : response_1.data) === null || _f === void 0 ? void 0 : _f[responseKey]
219
- : ((_g = response_1 === null || response_1 === void 0 ? void 0 : response_1.data) === null || _g === void 0 ? void 0 : _g.items) || (response_1 === null || response_1 === void 0 ? void 0 : response_1.data);
220
- items_1 = Array.isArray(itemsRaw_1) ? itemsRaw_1 : [];
221
- respCurrentPageRaw_1 = (_h = response_1 === null || response_1 === void 0 ? void 0 : response_1.data) === null || _h === void 0 ? void 0 : _h.currentPage;
222
- respCurrentPage_1 = respCurrentPageRaw_1 == null ? undefined : Number(respCurrentPageRaw_1);
223
- requestCurrentPage_1 = (params === null || params === void 0 ? void 0 : params.currentPage)
224
- ? Number(params.currentPage)
225
- : undefined;
226
- return [2 /*return*/, {
227
- count: ((_j = response_1 === null || response_1 === void 0 ? void 0 : response_1.data) === null || _j === void 0 ? void 0 : _j.count) || items_1.length,
228
- items: items_1,
229
- currentPage: respCurrentPage_1 !== null && respCurrentPage_1 !== void 0 ? respCurrentPage_1 : requestCurrentPage_1,
230
- }];
231
- case 3:
232
- raw = (0, local_storage_1.getStorageValue)(cacheKey);
233
- currentTime = new Date().getTime();
234
- if (isCachedArrayShape(raw)) {
235
- cachedTime = new Date(raw.cachedAt).getTime();
236
- ageInMs = currentTime - cachedTime;
237
- if (ageInMs < expirationMs) {
238
- return [2 /*return*/, {
239
- count: raw.count,
240
- items: raw.items,
241
- currentPage: (_k = raw.currentPage) !== null && _k !== void 0 ? _k : undefined,
242
- }];
243
- }
244
- }
245
- if (!isCachedMapShape(raw)) return [3 /*break*/, 6];
246
- cachedTime = new Date(raw.cachedAt).getTime();
247
- ageInMs = currentTime - cachedTime;
248
- if (!(ageInMs < expirationMs)) return [3 /*break*/, 6];
249
- itemsArray = Object.values(raw.items || {});
250
- storedCount = raw.count;
251
- cachedCurrentPage = raw.currentPage;
252
- requestedCurrentPage = (params === null || params === void 0 ? void 0 : params.currentPage)
253
- ? Number(params.currentPage)
254
- : undefined;
255
- if (!(requestedCurrentPage !== undefined &&
256
- requestedCurrentPage !== cachedCurrentPage)) return [3 /*break*/, 5];
257
- paramsWithoutFilters_2 = __assign({}, (params || {}));
258
- if (paramsWithoutFilters_2.filters !== undefined) {
259
- delete paramsWithoutFilters_2.filters;
260
- }
261
- otherParams_2 = Object.keys(paramsWithoutFilters_2).reduce(function (acc, key) {
262
- acc[key] = String(paramsWithoutFilters_2[key]);
263
- return acc;
264
- }, {});
265
- queryObj_2 = __assign({ pageLimit: fallBackPageLimit, currentPage: String(requestedCurrentPage) }, otherParams_2);
266
- searchParams_2 = new URLSearchParams(queryObj_2);
267
- return [4 /*yield*/, (0, fetch_data_1.fetchData)({
268
- url: "".concat(apiUrl, "?").concat(searchParams_2.toString()),
269
- method: constants_1.API_METHODS.GET,
270
- headers: headers,
271
- })];
272
- case 4:
273
- response_2 = _v.sent();
274
- itemsRaw_2 = (responseKey
275
- ? (_l = response_2 === null || response_2 === void 0 ? void 0 : response_2.data) === null || _l === void 0 ? void 0 : _l[responseKey]
276
- : (_m = response_2 === null || response_2 === void 0 ? void 0 : response_2.data) === null || _m === void 0 ? void 0 : _m.items) || (response_2 === null || response_2 === void 0 ? void 0 : response_2.data);
277
- fetchedItems = Array.isArray(itemsRaw_2)
278
- ? itemsRaw_2
279
- : [];
280
- respCount = (_o = response_2 === null || response_2 === void 0 ? void 0 : response_2.data) === null || _o === void 0 ? void 0 : _o.count;
281
- respCurrentPageRaw_2 = (_p = response_2 === null || response_2 === void 0 ? void 0 : response_2.data) === null || _p === void 0 ? void 0 : _p.currentPage;
282
- respCurrentPage_2 = respCurrentPageRaw_2 == null ? undefined : Number(respCurrentPageRaw_2);
283
- newItemsMap = fetchedItems.reduce(function (acc, item, idx) {
284
- var _a, _b;
285
- var obj = item;
286
- var keyCandidate = (_b = (_a = obj === null || obj === void 0 ? void 0 : obj.id) !== null && _a !== void 0 ? _a : obj === null || obj === void 0 ? void 0 : obj.uid) !== null && _b !== void 0 ? _b : idx;
287
- var key = String(keyCandidate);
288
- acc[key] = item;
289
- return acc;
290
- }, {});
291
- mergedItemsMap = Object.assign({}, raw.items || {}, newItemsMap);
292
- mergedItemsArray = Object.values(mergedItemsMap);
293
- newCount = respCount !== null && respCount !== void 0 ? respCount : mergedItemsArray.length;
294
- newCurrentPage = respCurrentPage_2 !== null && respCurrentPage_2 !== void 0 ? respCurrentPage_2 : requestedCurrentPage;
295
- shouldCache_1 = Array.isArray(itemsRaw_2) && typeof respCount === 'number';
296
- if (shouldCache_1) {
297
- updatedCache = {
298
- items: mergedItemsMap,
299
- cachedAt: new Date().toISOString(),
300
- count: newCount,
301
- currentPage: newCurrentPage,
302
- };
303
- (0, local_storage_1.setStorageValue)(cacheKey, updatedCache);
304
- }
305
- return [2 /*return*/, {
306
- count: newCount,
307
- items: mergedItemsArray,
308
- currentPage: newCurrentPage,
309
- }];
310
- case 5: return [2 /*return*/, {
311
- count: storedCount !== null && storedCount !== void 0 ? storedCount : itemsArray.length,
312
- items: itemsArray,
313
- currentPage: (_q = raw.currentPage) !== null && _q !== void 0 ? _q : undefined,
314
- }];
315
- case 6:
316
- paramsWithoutFilters_3 = __assign({}, (params || {}));
317
- if (paramsWithoutFilters_3.filters !== undefined) {
318
- delete paramsWithoutFilters_3.filters;
319
- }
320
- otherParams = Object.keys(paramsWithoutFilters_3).reduce(function (acc, key) {
321
- acc[key] = String(paramsWithoutFilters_3[key]);
322
- return acc;
323
- }, {});
324
- queryObj = __assign({ pageLimit: fallBackPageLimit, currentPage: fallBackCurrentPage }, otherParams);
325
- searchParams = new URLSearchParams(queryObj);
326
- return [4 /*yield*/, (0, fetch_data_1.fetchData)({
327
- url: "".concat(apiUrl, "?").concat(searchParams.toString()),
328
- method: constants_1.API_METHODS.GET,
329
- headers: headers,
330
- })];
331
- case 7:
332
- response = _v.sent();
333
- itemsRaw = (responseKey ? (_r = response === null || response === void 0 ? void 0 : response.data) === null || _r === void 0 ? void 0 : _r[responseKey] : (_s = response === null || response === void 0 ? void 0 : response.data) === null || _s === void 0 ? void 0 : _s.items) ||
334
- (response === null || response === void 0 ? void 0 : response.data);
335
- items = Array.isArray(itemsRaw) ? itemsRaw : [];
336
- count = (_t = response === null || response === void 0 ? void 0 : response.data) === null || _t === void 0 ? void 0 : _t.count;
337
- respCurrentPageRaw = (_u = response === null || response === void 0 ? void 0 : response.data) === null || _u === void 0 ? void 0 : _u.currentPage;
338
- respCurrentPage = respCurrentPageRaw == null ? undefined : Number(respCurrentPageRaw);
339
- requestCurrentPage = (params === null || params === void 0 ? void 0 : params.currentPage)
340
- ? Number(params.currentPage)
341
- : undefined;
342
- shouldCache = Array.isArray(itemsRaw) && typeof count === 'number';
343
- if (shouldCache) {
344
- itemsMap = items.reduce(function (acc, item, idx) {
345
- var _a, _b;
346
- var obj = item;
347
- var keyCandidate = (_b = (_a = obj === null || obj === void 0 ? void 0 : obj.id) !== null && _a !== void 0 ? _a : obj === null || obj === void 0 ? void 0 : obj.uid) !== null && _b !== void 0 ? _b : idx;
348
- var key = String(keyCandidate);
349
- acc[key] = item;
350
- return acc;
351
- }, {});
352
- updatedCache = {
353
- items: itemsMap,
354
- cachedAt: new Date().toISOString(),
355
- count: count,
356
- currentPage: respCurrentPage !== null && respCurrentPage !== void 0 ? respCurrentPage : requestCurrentPage,
357
- };
358
- (0, local_storage_1.setStorageValue)(cacheKey, updatedCache);
359
- }
360
- // Return count as number when present, otherwise fallback to items.length
361
- return [2 /*return*/, {
362
- count: count,
363
- items: items,
364
- currentPage: respCurrentPage !== null && respCurrentPage !== void 0 ? respCurrentPage : requestCurrentPage,
365
- }];
366
- case 8:
367
- error_1 = _v.sent();
368
- console.error("Error fetching data for ".concat(cacheKey, ":"), error_1);
369
- return [2 /*return*/, { count: 0, items: [] }];
370
- case 9: return [2 /*return*/];
371
- }
372
- });
373
- }); };
374
- exports.getCachedData = getCachedData;
375
- /**
376
- * Get single cached item by ID from a list cache
377
- *
378
- * @param cacheKey - localStorage key for the cache
379
- * @param itemId - ID of the item to retrieve
380
- * @returns T | null - Cached item or null
381
- *
382
- * @example
383
- * const user = getCachedItemById<UserBE>(LS_KEYS.USERS, 'user-123');
384
- * if (user) {
385
- * console.log(user.name);
386
- * }
387
- */
388
- var getCachedItemById = function (cacheKey, itemId) {
389
- if (!itemId) {
390
- return null;
391
- }
392
- try {
393
- // Try to read normalized cache first for O(1) lookup
394
- var raw = (0, local_storage_1.getStorageValue)(cacheKey);
395
- if (isCachedArrayShape(raw)) {
396
- return raw.items.find(function (i) { return i.id === itemId; }) || null;
397
- }
398
- if (isCachedMapShape(raw)) {
399
- return (raw.items && raw.items[itemId]) || null;
400
- }
401
- // Fallback to sync reader
402
- var items = (0, exports.getCachedDataSync)(cacheKey).items;
403
- return items.find(function (item) { return item.id === itemId; }) || null;
404
- }
405
- catch (error) {
406
- console.error("Error getting cached item by ID for ".concat(cacheKey, ":"), error);
407
- return null;
408
- }
409
- };
410
- exports.getCachedItemById = getCachedItemById;
411
- // ============================================================================
412
- // SINGLE ITEM CACHE FUNCTIONS
413
- // ============================================================================
414
- /**
415
- * Get synchronous cached single item
416
- * Returns null if cache is missing or stale
417
- *
418
- * @param cacheKey - localStorage key for the cache
419
- * @param expirationMs - Cache expiration time in milliseconds (default: 1 day)
420
- * @returns T | null - Cached item or null
421
- *
422
- * @example
423
- * const workspace = getCachedSingleItemSync<WorkspaceBE>(LS_KEYS.WORKSPACE);
424
- * if (workspace) {
425
- * console.log(workspace.name);
426
- * }
427
- */
428
- var getCachedSingleItemSync = function (cacheKey, expirationMs) {
429
- if (expirationMs === void 0) { expirationMs = constants_1.ONE_DAY_IN_MS; }
430
- try {
431
- var cachedData = (0, local_storage_1.getStorageValue)(cacheKey);
432
- if (!cachedData) {
433
- return null;
434
- }
435
- var currentTime = new Date().getTime();
436
- var cachedTime = new Date(cachedData.cachedAt).getTime();
437
- var ageInMs = currentTime - cachedTime;
438
- if (ageInMs < expirationMs) {
439
- return cachedData.item;
440
- }
441
- return null;
442
- }
443
- catch (error) {
444
- console.error("Error getting cached single item for ".concat(cacheKey, ":"), error);
445
- return null;
446
- }
447
- };
448
- exports.getCachedSingleItemSync = getCachedSingleItemSync;
449
- /**
450
- * Get cached single item with API fallback
451
- * Useful for workspace, profile, settings, etc.
452
- *
453
- * @param config - Cache configuration (cacheKey, apiUrl, expirationMs, responseKey)
454
- * @param params - Optional query parameters for API request
455
- * @returns Promise<T | null> - Cached or fresh item
456
- *
457
- * @example
458
- * const config = { cacheKey: LS_KEYS.WORKSPACE, apiUrl: '/api/workspace', responseKey: 'workspace' };
459
- * const workspace = await getCachedSingleItem<WorkspaceBE>(config, { subdomain: 'school1' });
460
- */
461
- var getCachedSingleItem = function (config, params, headers) { return __awaiter(void 0, void 0, void 0, function () {
462
- var cacheKey, apiUrl, expirationMs, cachedData, currentTime, cachedTime, ageInMs, queryParams, response, item, updatedCache, error_2;
463
- var _a;
464
- return __generator(this, function (_b) {
465
- switch (_b.label) {
466
- case 0:
467
- cacheKey = config.cacheKey, apiUrl = config.apiUrl;
468
- expirationMs = (_a = config.expirationMs) !== null && _a !== void 0 ? _a : constants_1.ONE_DAY_IN_MS;
469
- _b.label = 1;
470
- case 1:
471
- _b.trys.push([1, 3, , 4]);
472
- cachedData = (0, local_storage_1.getStorageValue)(cacheKey);
473
- currentTime = new Date().getTime();
474
- if (cachedData) {
475
- cachedTime = new Date(cachedData.cachedAt).getTime();
476
- ageInMs = currentTime - cachedTime;
477
- if (ageInMs < expirationMs) {
478
- return [2 /*return*/, cachedData.item];
479
- }
480
- }
481
- queryParams = params
482
- ? "?".concat(new URLSearchParams(params).toString())
483
- : '';
484
- return [4 /*yield*/, (0, fetch_data_1.fetchData)({
485
- url: "".concat(apiUrl).concat(queryParams),
486
- method: constants_1.API_METHODS.GET,
487
- headers: headers,
488
- })];
489
- case 2:
490
- response = _b.sent();
491
- item = (response === null || response === void 0 ? void 0 : response.data) || null;
492
- if (item) {
493
- updatedCache = {
494
- item: item,
495
- cachedAt: new Date().toISOString(),
496
- };
497
- (0, local_storage_1.setStorageValue)(cacheKey, updatedCache);
498
- }
499
- return [2 /*return*/, item];
500
- case 3:
501
- error_2 = _b.sent();
502
- console.error("Error fetching single item for ".concat(cacheKey, ":"), error_2);
503
- return [2 /*return*/, null];
504
- case 4: return [2 /*return*/];
505
- }
506
- });
507
- }); };
508
- exports.getCachedSingleItem = getCachedSingleItem;
509
- /**
510
- * Get cached data but fall back to the API when sync cache is empty.
511
- *
512
- * This helper first performs a quick synchronous cache check via
513
- * `getCachedDataSync`. If that returns an empty result it will call
514
- * the async `getCachedData` to fetch fresh data from the API and return
515
- * the result. Use this when callers want a fast-path cache read but also
516
- * need the ability to recall the API transparently when cache is missing.
517
- */
518
- var getCachedDataWithFallback = function (config, params, headers) { return __awaiter(void 0, void 0, void 0, function () {
519
- var expirationMs, sync, error_3;
520
- var _a;
521
- return __generator(this, function (_b) {
522
- switch (_b.label) {
523
- case 0:
524
- expirationMs = (_a = config.expirationMs) !== null && _a !== void 0 ? _a : constants_1.ONE_DAY_IN_MS;
525
- _b.label = 1;
526
- case 1:
527
- _b.trys.push([1, 3, , 4]);
528
- sync = (0, exports.getCachedDataSync)(config.cacheKey, expirationMs);
529
- if (sync &&
530
- sync.count > 0 &&
531
- Array.isArray(sync.items) &&
532
- sync.items.length > 0) {
533
- return [2 /*return*/, sync];
534
- }
535
- return [4 /*yield*/, (0, exports.getCachedData)({ config: config, params: params, headers: headers })];
536
- case 2:
537
- // Sync cache empty — fetch from API and return result
538
- return [2 /*return*/, _b.sent()];
539
- case 3:
540
- error_3 = _b.sent();
541
- console.error("Error in getCachedDataWithFallback for ".concat(config.cacheKey, ":"), error_3);
542
- return [2 /*return*/, { count: 0, items: [] }];
543
- case 4: return [2 /*return*/];
544
- }
545
- });
546
- }); };
547
- exports.getCachedDataWithFallback = getCachedDataWithFallback;
548
- /**
549
- * Async variant to get a single item by ID with API fallback.
550
- *
551
- * Unlike `getCachedItemById` (sync), this function will call the API
552
- * (via `getCachedDataWithFallback`) when the item is not available in
553
- * the local cache. Requires a full `CacheConfig` so the API URL is
554
- * available for fetching.
555
- */
556
- var getCachedItemByIdAsync = function (config, itemId, params, headers) { return __awaiter(void 0, void 0, void 0, function () {
557
- var raw, found, list, error_4;
558
- return __generator(this, function (_a) {
559
- switch (_a.label) {
560
- case 0:
561
- if (!itemId)
562
- return [2 /*return*/, null];
563
- _a.label = 1;
564
- case 1:
565
- _a.trys.push([1, 3, , 4]);
566
- raw = (0, local_storage_1.getStorageValue)(config.cacheKey);
567
- if (isCachedArrayShape(raw)) {
568
- found = raw.items.find(function (i) { return i.id === itemId; });
569
- if (found)
570
- return [2 /*return*/, found];
571
- }
572
- if (isCachedMapShape(raw)) {
573
- if (raw.items && raw.items[itemId])
574
- return [2 /*return*/, raw.items[itemId]];
575
- }
576
- return [4 /*yield*/, (0, exports.getCachedDataWithFallback)(config, params, headers)];
577
- case 2:
578
- list = _a.sent();
579
- return [2 /*return*/, list.items.find(function (i) { return i.id === itemId; }) || null];
580
- case 3:
581
- error_4 = _a.sent();
582
- console.error("Error in getCachedItemByIdAsync for ".concat(config.cacheKey, ":"), error_4);
583
- return [2 /*return*/, null];
584
- case 4: return [2 /*return*/];
585
- }
586
- });
587
- }); };
588
- exports.getCachedItemByIdAsync = getCachedItemByIdAsync;
589
- // ============================================================================
590
- // CACHE UTILITIES
591
- // ============================================================================
592
- /**
593
- * Invalidate (remove) cache for a module
594
- * Useful after create/update/delete operations
595
- *
596
- * @param cacheKey - localStorage key for the cache
597
- *
598
- * @example
599
- * invalidateCache(LS_KEYS.USERS);
600
- * const freshUsers = await getCachedData(config);
601
- */
602
- var invalidateCache = function (cacheKey) {
603
- try {
604
- localStorage.removeItem(cacheKey);
605
- }
606
- catch (error) {
607
- console.error("Error invalidating cache for ".concat(cacheKey, ":"), error);
608
- }
609
- };
610
- exports.invalidateCache = invalidateCache;
611
- /**
612
- * Preload cache for a module
613
- * Useful to call on app initialization or login
614
- *
615
- * @param config - Cache configuration
616
- * @returns Promise<ListResponse<T>> - Preloaded data
617
- *
618
- * @example
619
- * const config = { cacheKey: LS_KEYS.USERS, apiUrl: USER_API_ROUTES.LIST, responseKey: 'users' };
620
- * await preloadCache(config);
621
- */
622
- var preloadCache = function (config) { return __awaiter(void 0, void 0, void 0, function () {
623
- return __generator(this, function (_a) {
624
- return [2 /*return*/, (0, exports.getCachedData)({ config: config })];
625
- });
626
- }); };
627
- exports.preloadCache = preloadCache;
628
- /**
629
- * Check if cache is stale (older than expiration time)
630
- *
631
- * @param cacheKey - localStorage key for the cache
632
- * @param expirationMs - Cache expiration time in milliseconds (default: 1 day)
633
- * @returns boolean - True if cache is stale or doesn't exist
634
- *
635
- * @example
636
- * if (isCacheStale(LS_KEYS.USERS)) {
637
- * await getCachedData(config); // This will fetch fresh data
638
- * }
639
- */
640
- var isCacheStale = function (cacheKey, expirationMs) {
641
- if (expirationMs === void 0) { expirationMs = constants_1.ONE_DAY_IN_MS; }
642
- try {
643
- var raw = (0, local_storage_1.getStorageValue)(cacheKey);
644
- if (raw == null)
645
- return true;
646
- if (isCachedArrayShape(raw) || isCachedMapShape(raw)) {
647
- var cachedTime = new Date(raw.cachedAt).getTime();
648
- var currentTime = new Date().getTime();
649
- var ageInMs = currentTime - cachedTime;
650
- return ageInMs >= expirationMs;
651
- }
652
- return true;
653
- }
654
- catch (error) {
655
- console.error("Error checking cache staleness for ".concat(cacheKey, ":"), error);
656
- return true;
657
- }
658
- };
659
- exports.isCacheStale = isCacheStale;
1
+ var U=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var ge=Object.getOwnPropertyNames;var de=Object.prototype.hasOwnProperty;var me=(t,n)=>{for(var e in n)U(t,e,{get:n[e],enumerable:!0})},he=(t,n,e,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of ge(n))!de.call(t,r)&&r!==e&&U(t,r,{get:()=>n[r],enumerable:!(s=ue(n,r))||s.enumerable});return t};var le=t=>he(U({},"__esModule",{value:!0}),t);var Re={};me(Re,{getCachedData:()=>v,getCachedDataSync:()=>G,getCachedDataWithFallback:()=>Z,getCachedItemById:()=>fe,getCachedItemByIdAsync:()=>ye,getCachedSingleItem:()=>pe,getCachedSingleItemSync:()=>Te,invalidateCache:()=>Ce,isCacheStale:()=>Pe,preloadCache:()=>we});module.exports=le(Re);var I=require("../constants/api-methods"),P=require("../constants/cache-time"),x=require("./fetch-data"),T=require("../local-storage/get-storage-value"),$=require("../local-storage/set-storage-value");function k(t){if(!t||typeof t!="object")return!1;const n=t;return Array.isArray(n.items)&&typeof n.cachedAt=="string"&&typeof n.count=="number"}function M(t){if(!t||typeof t!="object")return!1;const n=t;return n.items!==void 0&&typeof n.items=="object"&&!Array.isArray(n.items)&&typeof n.cachedAt=="string"}const G=(t,n=P.ONE_DAY_IN_MS)=>{try{const e=(0,T.getStorageValue)(t);if(e==null)return{count:0,items:[]};const s=new Date().getTime();if(k(e)){const r=new Date(e.cachedAt).getTime();return s-r<n?{count:e.count??e.items.length,items:e.items,currentPage:e.currentPage??void 0}:{count:0,items:[]}}if(M(e)){const r=new Date(e.cachedAt).getTime();if(s-r<n){const a=Object.values(e.items||{});return{count:e.count??a.length,items:a,currentPage:e.currentPage??void 0}}return{count:0,items:[]}}return{count:0,items:[]}}catch(e){return console.error(`Error getting cached data for ${t}:`,e),{count:0,items:[]}}},v=async t=>{const{config:n,params:e,headers:s}=t,{cacheKey:r,apiUrl:u,responseKey:a}=n,p=n.expirationMs??P.ONE_DAY_IN_MS,D=e?.pageLimit?.toString()??"100",j=e?.currentPage?.toString()??"1",y=e?.filters,l=e?.searchQuery;try{if(l&&l.trim()||e?.filters){const o={...e||{}};o.filters!==void 0&&delete o.filters;const f=Object.keys(o).reduce((i,h)=>(i[h]=String(o[h]),i),{}),C={pageLimit:D,currentPage:j,...l&&{searchQuery:l},...y?Object.keys(y).reduce((i,h)=>(i[h]=String(y[h]),i),{}):{},...f},R=new URLSearchParams(C),d=await(0,x.fetchData)({url:`${u}?${R.toString()}`,method:I.API_METHODS.GET,headers:s}),g=a?d?.data?.[a]:d?.data?.items||d?.data,m=Array.isArray(g)?g:[],A=d?.data?.currentPage,N=A==null?void 0:Number(A),q=e?.currentPage?Number(e.currentPage):void 0;return{count:d?.data?.count||m.length,items:m,currentPage:N??q}}const c=(0,T.getStorageValue)(r),B=new Date().getTime();if(k(c)){const o=new Date(c.cachedAt).getTime();if(B-o<p)return{count:c.count,items:c.items,currentPage:c.currentPage??void 0}}if(M(c)){const o=new Date(c.cachedAt).getTime();if(B-o<p){const C=Object.values(c.items||{}),R=c.count,d=c.currentPage,g=e?.currentPage?Number(e.currentPage):void 0;if(g!==void 0&&g!==d){const m={...e||{}};m.filters!==void 0&&delete m.filters;const A=Object.keys(m).reduce((w,S)=>(w[S]=String(m[S]),w),{}),N={pageLimit:D,currentPage:String(g),...A},q=new URLSearchParams(N),i=await(0,x.fetchData)({url:`${u}?${q.toString()}`,method:I.API_METHODS.GET,headers:s}),h=(a?i?.data?.[a]:i?.data?.items)||i?.data,re=Array.isArray(h)?h:[],Q=i?.data?.count,V=i?.data?.currentPage,se=V==null?void 0:Number(V),ae=re.reduce((w,S,ce)=>{const X=S,oe=X?.id??X?.uid??ce,ie=String(oe);return w[ie]=S,w},{}),H=Object.assign({},c.items||{},ae),Y=Object.values(H),z=Q??Y.length,J=se??g;if(Array.isArray(h)&&typeof Q=="number"){const w={items:H,cachedAt:new Date().toISOString(),count:z,currentPage:J};(0,$.setStorageValue)(r,w)}return{count:z,items:Y,currentPage:J}}return{count:R??C.length,items:C,currentPage:c.currentPage??void 0}}}const O={...e||{}};O.filters!==void 0&&delete O.filters;const ee=Object.keys(O).reduce((o,f)=>(o[f]=String(O[f]),o),{}),te={pageLimit:D,currentPage:j,...ee},ne=new URLSearchParams(te),b=await(0,x.fetchData)({url:`${u}?${ne.toString()}`,method:I.API_METHODS.GET,headers:s}),E=(a?b?.data?.[a]:b?.data?.items)||b?.data,F=Array.isArray(E)?E:[],L=b?.data?.count,W=b?.data?.currentPage,_=W==null?void 0:Number(W),K=e?.currentPage?Number(e.currentPage):void 0;if(Array.isArray(E)&&typeof L=="number"){const f={items:F.reduce((C,R,d)=>{const g=R,m=g?.id??g?.uid??d,A=String(m);return C[A]=R,C},{}),cachedAt:new Date().toISOString(),count:L,currentPage:_??K};(0,$.setStorageValue)(r,f)}return{count:L,items:F,currentPage:_??K}}catch(c){return console.error(`Error fetching data for ${r}:`,c),{count:0,items:[]}}},fe=(t,n)=>{if(!n)return null;try{const e=(0,T.getStorageValue)(t);if(k(e))return e.items.find(r=>r.id===n)||null;if(M(e))return e.items&&e.items[n]||null;const{items:s}=G(t);return s.find(r=>r.id===n)||null}catch(e){return console.error(`Error getting cached item by ID for ${t}:`,e),null}},Te=(t,n=P.ONE_DAY_IN_MS)=>{try{const e=(0,T.getStorageValue)(t);if(!e)return null;const s=new Date().getTime(),r=new Date(e.cachedAt).getTime();return s-r<n?e.item:null}catch(e){return console.error(`Error getting cached single item for ${t}:`,e),null}},pe=async(t,n,e)=>{const{cacheKey:s,apiUrl:r}=t,u=t.expirationMs??P.ONE_DAY_IN_MS;try{const a=(0,T.getStorageValue)(s),p=new Date().getTime();if(a){const l=new Date(a.cachedAt).getTime();if(p-l<u)return a.item}const D=n?`?${new URLSearchParams(n).toString()}`:"",y=(await(0,x.fetchData)({url:`${r}${D}`,method:I.API_METHODS.GET,headers:e}))?.data||null;if(y){const l={item:y,cachedAt:new Date().toISOString()};(0,$.setStorageValue)(s,l)}return y}catch(a){return console.error(`Error fetching single item for ${s}:`,a),null}},Z=async(t,n,e)=>{const s=t.expirationMs??P.ONE_DAY_IN_MS;try{const r=G(t.cacheKey,s);return r&&r.count>0&&Array.isArray(r.items)&&r.items.length>0?r:await v({config:t,params:n,headers:e})}catch(r){return console.error(`Error in getCachedDataWithFallback for ${t.cacheKey}:`,r),{count:0,items:[]}}},ye=async(t,n,e,s)=>{if(!n)return null;try{const r=(0,T.getStorageValue)(t.cacheKey);if(k(r)){const a=r.items.find(p=>p.id===n);if(a)return a}return M(r)&&r.items&&r.items[n]?r.items[n]:(await Z(t,e,s)).items.find(a=>a.id===n)||null}catch(r){return console.error(`Error in getCachedItemByIdAsync for ${t.cacheKey}:`,r),null}},Ce=t=>{try{localStorage.removeItem(t)}catch(n){console.error(`Error invalidating cache for ${t}:`,n)}},we=async t=>v({config:t}),Pe=(t,n=P.ONE_DAY_IN_MS)=>{try{const e=(0,T.getStorageValue)(t);if(e==null)return!0;if(k(e)||M(e)){const s=new Date(e.cachedAt).getTime();return new Date().getTime()-s>=n}return!0}catch(e){return console.error(`Error checking cache staleness for ${t}:`,e),!0}};0&&(module.exports={getCachedData,getCachedDataSync,getCachedDataWithFallback,getCachedItemById,getCachedItemByIdAsync,getCachedSingleItem,getCachedSingleItemSync,invalidateCache,isCacheStale,preloadCache});