@unidy.io/sdk 1.1.4 → 1.2.0-alpha2

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 (398) hide show
  1. package/dist/cjs/app-globals-DSKjcXX_.js.map +1 -1
  2. package/dist/cjs/{auth-store-BaxuIp4z.js → auth-store-DC9EVec8.js} +2 -3
  3. package/dist/cjs/auth-store-DC9EVec8.js.map +1 -0
  4. package/dist/cjs/{i18n-BoDZ8kd2.js → i18n-BAZB-eHh.js} +2 -8
  5. package/dist/cjs/{i18n-BoDZ8kd2.js.map → i18n-BAZB-eHh.js.map} +1 -1
  6. package/dist/cjs/{index-R2MKLaem.js → index-CvFbf5-D.js} +1477 -1105
  7. package/dist/cjs/index-CvFbf5-D.js.map +1 -0
  8. package/dist/cjs/index.cjs.js +6 -5
  9. package/dist/cjs/index.cjs.js.map +1 -1
  10. package/dist/cjs/{newsletter-helpers-DR0vsegt.js → newsletter-helpers-Dj0yYHZf.js} +61 -74
  11. package/dist/cjs/newsletter-helpers-Dj0yYHZf.js.map +1 -0
  12. package/dist/cjs/{profile-helpers-B2h2III_.js → profile-helpers-D66Ycaft.js} +3 -3
  13. package/dist/cjs/{profile-helpers-B2h2III_.js.map → profile-helpers-D66Ycaft.js.map} +1 -1
  14. package/dist/cjs/u-conditional-render.cjs.entry.js +5 -6
  15. package/dist/cjs/u-conditional-render.entry.cjs.js.map +1 -1
  16. package/dist/cjs/u-config.cjs.entry.js +5 -6
  17. package/dist/cjs/u-config.entry.cjs.js.map +1 -1
  18. package/dist/cjs/u-email-field.cjs.entry.js +2 -2
  19. package/dist/cjs/u-error-message.cjs.entry.js +3 -3
  20. package/dist/cjs/u-error-message.entry.cjs.js.map +1 -1
  21. package/dist/cjs/u-field.u-raw-field.entry.cjs.js.map +1 -1
  22. package/dist/cjs/u-field_2.cjs.entry.js +2 -2
  23. package/dist/cjs/u-full-profile.cjs.entry.js +1 -1
  24. package/dist/cjs/u-logout-button.cjs.entry.js +6 -7
  25. package/dist/cjs/u-logout-button.entry.cjs.js.map +1 -1
  26. package/dist/cjs/u-magic-code-field.cjs.entry.js +5 -6
  27. package/dist/cjs/u-magic-code-field.entry.cjs.js.map +1 -1
  28. package/dist/cjs/u-missing-field.cjs.entry.js +1 -1
  29. package/dist/cjs/u-missing-fields-submit-button.cjs.entry.js +9 -5
  30. package/dist/cjs/u-missing-fields-submit-button.entry.cjs.js.map +1 -1
  31. package/dist/cjs/u-newsletter-checkbox.cjs.entry.js +5 -6
  32. package/dist/cjs/u-newsletter-checkbox.entry.cjs.js.map +1 -1
  33. package/dist/cjs/u-newsletter-logout-button.cjs.entry.js +6 -7
  34. package/dist/cjs/u-newsletter-logout-button.entry.cjs.js.map +1 -1
  35. package/dist/cjs/u-newsletter-preference-checkbox.cjs.entry.js +5 -6
  36. package/dist/cjs/u-newsletter-preference-checkbox.entry.cjs.js.map +1 -1
  37. package/dist/cjs/u-newsletter-resend-doi-button.cjs.entry.js +4 -5
  38. package/dist/cjs/u-newsletter-resend-doi-button.entry.cjs.js.map +1 -1
  39. package/dist/cjs/u-newsletter-root.cjs.entry.js +5 -6
  40. package/dist/cjs/u-newsletter-root.entry.cjs.js.map +1 -1
  41. package/dist/cjs/u-newsletter-toggle-subscription-button.cjs.entry.js +4 -5
  42. package/dist/cjs/u-newsletter-toggle-subscription-button.entry.cjs.js.map +1 -1
  43. package/dist/cjs/u-passkey.cjs.entry.js +5 -6
  44. package/dist/cjs/u-passkey.entry.cjs.js.map +1 -1
  45. package/dist/cjs/u-password-field.cjs.entry.js +2 -2
  46. package/dist/cjs/u-profile.u-submit-button.entry.cjs.js.map +1 -1
  47. package/dist/cjs/u-profile_2.cjs.entry.js +35 -55
  48. package/dist/cjs/u-registration-button.cjs.entry.js +2 -2
  49. package/dist/cjs/u-reset-password-button.cjs.entry.js +4 -5
  50. package/dist/cjs/u-reset-password-button.entry.cjs.js.map +1 -1
  51. package/dist/cjs/u-send-magic-code-button.cjs.entry.js +5 -6
  52. package/dist/cjs/u-send-magic-code-button.entry.cjs.js.map +1 -1
  53. package/dist/cjs/u-signed-in.cjs.entry.js +1 -1
  54. package/dist/cjs/u-signin-root.cjs.entry.js +1 -1
  55. package/dist/cjs/u-signin-step.cjs.entry.js +5 -6
  56. package/dist/cjs/u-signin-step.entry.cjs.js.map +1 -1
  57. package/dist/cjs/u-signin-strategy.cjs.entry.js +1 -1
  58. package/dist/cjs/u-social-login-button.cjs.entry.js +2 -2
  59. package/dist/cjs/u-spinner.cjs.entry.js +1 -1
  60. package/dist/cjs/u-spinner.entry.cjs.js.map +1 -1
  61. package/dist/cjs/u-ticketable-list.cjs.entry.js +39 -29
  62. package/dist/cjs/u-ticketable-list.entry.cjs.js.map +1 -1
  63. package/dist/collection/api/base-client.js +129 -0
  64. package/dist/collection/api/base-client.js.map +1 -0
  65. package/dist/collection/api/base-service.js +72 -0
  66. package/dist/collection/api/base-service.js.map +1 -0
  67. package/dist/collection/api/client.js +18 -139
  68. package/dist/collection/api/client.js.map +1 -1
  69. package/dist/collection/api/index.js +25 -5
  70. package/dist/collection/api/index.js.map +1 -1
  71. package/dist/collection/api/shared.js +11 -2
  72. package/dist/collection/api/shared.js.map +1 -1
  73. package/dist/collection/api/standalone.js +88 -0
  74. package/dist/collection/api/standalone.js.map +1 -0
  75. package/dist/collection/auth/api/auth.js +66 -124
  76. package/dist/collection/auth/api/auth.js.map +1 -1
  77. package/dist/collection/auth/api/schemas.js +78 -0
  78. package/dist/collection/auth/api/schemas.js.map +1 -0
  79. package/dist/collection/auth/auth-helpers.js +47 -36
  80. package/dist/collection/auth/auth-helpers.js.map +1 -1
  81. package/dist/collection/auth/components/missing-fields-submit-button/missing-fields-submit-button.js +4 -1
  82. package/dist/collection/auth/components/missing-fields-submit-button/missing-fields-submit-button.js.map +1 -1
  83. package/dist/collection/auth/components/password-field/password-field.js +1 -1
  84. package/dist/collection/auth/passkey-auth.js +8 -6
  85. package/dist/collection/auth/passkey-auth.js.map +1 -1
  86. package/dist/collection/auth/store/auth-store.js +0 -1
  87. package/dist/collection/auth/store/auth-store.js.map +1 -1
  88. package/dist/collection/locales/de.json +0 -1
  89. package/dist/collection/locales/en.json +0 -1
  90. package/dist/collection/locales/fr.json +0 -1
  91. package/dist/collection/locales/it.json +0 -1
  92. package/dist/collection/locales/nl_be.json +0 -1
  93. package/dist/collection/locales/ro.json +0 -1
  94. package/dist/collection/newsletter/api/newsletters.js +192 -167
  95. package/dist/collection/newsletter/api/newsletters.js.map +1 -1
  96. package/dist/collection/newsletter/api/schemas.js +112 -0
  97. package/dist/collection/newsletter/api/schemas.js.map +1 -0
  98. package/dist/collection/newsletter/newsletter-helpers.js +57 -70
  99. package/dist/collection/newsletter/newsletter-helpers.js.map +1 -1
  100. package/dist/collection/profile/api/profile.js +56 -155
  101. package/dist/collection/profile/api/profile.js.map +1 -1
  102. package/dist/collection/profile/api/schemas.js +120 -0
  103. package/dist/collection/profile/api/schemas.js.map +1 -0
  104. package/dist/collection/profile/components/field/field.css +1 -1
  105. package/dist/collection/profile/components/profile/profile.js +35 -101
  106. package/dist/collection/profile/components/profile/profile.js.map +1 -1
  107. package/dist/collection/shared/components/config/config.js +2 -2
  108. package/dist/collection/shared/components/error-message/error-message.js +3 -3
  109. package/dist/collection/shared/components/error-message/error-message.js.map +1 -1
  110. package/dist/collection/shared/components/spinner/spinner.css +1 -1
  111. package/dist/collection/shared/components/submit-button/submit-button.css +1 -1
  112. package/dist/collection/ticketable/api/schemas.js +58 -9
  113. package/dist/collection/ticketable/api/schemas.js.map +1 -1
  114. package/dist/collection/ticketable/api/subscriptions.js +13 -44
  115. package/dist/collection/ticketable/api/subscriptions.js.map +1 -1
  116. package/dist/collection/ticketable/api/ticketable-service.js +74 -0
  117. package/dist/collection/ticketable/api/ticketable-service.js.map +1 -0
  118. package/dist/collection/ticketable/api/tickets.js +13 -45
  119. package/dist/collection/ticketable/api/tickets.js.map +1 -1
  120. package/dist/collection/ticketable/components/ticketable-list/ticketable-list.js +37 -77
  121. package/dist/collection/ticketable/components/ticketable-list/ticketable-list.js.map +1 -1
  122. package/dist/components/auth-store.js +0 -1
  123. package/dist/components/auth-store.js.map +1 -1
  124. package/dist/components/field.js +1 -1
  125. package/dist/components/field.js.map +1 -1
  126. package/dist/components/i18n.js +0 -6
  127. package/dist/components/i18n.js.map +1 -1
  128. package/dist/components/index.js +1 -2
  129. package/dist/components/index.js.map +1 -1
  130. package/dist/components/index2.js +1475 -1106
  131. package/dist/components/index2.js.map +1 -1
  132. package/dist/components/newsletter-helpers.js +57 -70
  133. package/dist/components/newsletter-helpers.js.map +1 -1
  134. package/dist/components/profile.js +34 -54
  135. package/dist/components/profile.js.map +1 -1
  136. package/dist/components/spinner.js +1 -1
  137. package/dist/components/spinner.js.map +1 -1
  138. package/dist/components/submit-button.js +1 -1
  139. package/dist/components/submit-button.js.map +1 -1
  140. package/dist/components/u-config.js +1 -2
  141. package/dist/components/u-config.js.map +1 -1
  142. package/dist/components/u-error-message.js +2 -2
  143. package/dist/components/u-error-message.js.map +1 -1
  144. package/dist/components/u-logout-button.js +1 -1
  145. package/dist/components/u-magic-code-field.js +1 -1
  146. package/dist/components/u-missing-fields-submit-button.js +4 -1
  147. package/dist/components/u-missing-fields-submit-button.js.map +1 -1
  148. package/dist/components/u-newsletter-root.js +1 -1
  149. package/dist/components/u-passkey.js +1 -1
  150. package/dist/components/u-reset-password-button.js +1 -1
  151. package/dist/components/u-send-magic-code-button.js +1 -1
  152. package/dist/components/u-signin-step.js +1 -1
  153. package/dist/components/u-ticketable-list.js +36 -29
  154. package/dist/components/u-ticketable-list.js.map +1 -1
  155. package/dist/esm/app-globals-CPU9ZcqZ.js.map +1 -1
  156. package/dist/esm/{auth-store-CVvBlKGv.js → auth-store-BMqUdTpC.js} +2 -3
  157. package/dist/esm/auth-store-BMqUdTpC.js.map +1 -0
  158. package/dist/esm/{i18n-CLdWzy5J.js → i18n-BANodpxG.js} +2 -8
  159. package/dist/esm/{i18n-CLdWzy5J.js.map → i18n-BANodpxG.js.map} +1 -1
  160. package/dist/esm/{index-DSDkaHWI.js → index-2p1QEJrx.js} +1477 -1108
  161. package/dist/esm/index-2p1QEJrx.js.map +1 -0
  162. package/dist/esm/index.js +3 -4
  163. package/dist/esm/index.js.map +1 -1
  164. package/dist/esm/{newsletter-helpers-Dc_24im3.js → newsletter-helpers-D64LTcSM.js} +61 -74
  165. package/dist/esm/newsletter-helpers-D64LTcSM.js.map +1 -0
  166. package/dist/esm/{profile-helpers-CglNd6Nw.js → profile-helpers-DAvXZ9Uj.js} +3 -3
  167. package/dist/esm/{profile-helpers-CglNd6Nw.js.map → profile-helpers-DAvXZ9Uj.js.map} +1 -1
  168. package/dist/esm/u-conditional-render.entry.js +5 -6
  169. package/dist/esm/u-conditional-render.entry.js.map +1 -1
  170. package/dist/esm/u-config.entry.js +4 -5
  171. package/dist/esm/u-config.entry.js.map +1 -1
  172. package/dist/esm/u-email-field.entry.js +2 -2
  173. package/dist/esm/u-error-message.entry.js +3 -3
  174. package/dist/esm/u-error-message.entry.js.map +1 -1
  175. package/dist/esm/u-field.u-raw-field.entry.js.map +1 -1
  176. package/dist/esm/u-field_2.entry.js +2 -2
  177. package/dist/esm/u-full-profile.entry.js +1 -1
  178. package/dist/esm/u-logout-button.entry.js +5 -6
  179. package/dist/esm/u-logout-button.entry.js.map +1 -1
  180. package/dist/esm/u-magic-code-field.entry.js +4 -5
  181. package/dist/esm/u-magic-code-field.entry.js.map +1 -1
  182. package/dist/esm/u-missing-field.entry.js +1 -1
  183. package/dist/esm/u-missing-fields-submit-button.entry.js +9 -5
  184. package/dist/esm/u-missing-fields-submit-button.entry.js.map +1 -1
  185. package/dist/esm/u-newsletter-checkbox.entry.js +5 -6
  186. package/dist/esm/u-newsletter-checkbox.entry.js.map +1 -1
  187. package/dist/esm/u-newsletter-logout-button.entry.js +6 -7
  188. package/dist/esm/u-newsletter-logout-button.entry.js.map +1 -1
  189. package/dist/esm/u-newsletter-preference-checkbox.entry.js +5 -6
  190. package/dist/esm/u-newsletter-preference-checkbox.entry.js.map +1 -1
  191. package/dist/esm/u-newsletter-resend-doi-button.entry.js +4 -5
  192. package/dist/esm/u-newsletter-resend-doi-button.entry.js.map +1 -1
  193. package/dist/esm/u-newsletter-root.entry.js +4 -5
  194. package/dist/esm/u-newsletter-root.entry.js.map +1 -1
  195. package/dist/esm/u-newsletter-toggle-subscription-button.entry.js +4 -5
  196. package/dist/esm/u-newsletter-toggle-subscription-button.entry.js.map +1 -1
  197. package/dist/esm/u-passkey.entry.js +4 -5
  198. package/dist/esm/u-passkey.entry.js.map +1 -1
  199. package/dist/esm/u-password-field.entry.js +2 -2
  200. package/dist/esm/u-profile.u-submit-button.entry.js.map +1 -1
  201. package/dist/esm/u-profile_2.entry.js +36 -56
  202. package/dist/esm/u-registration-button.entry.js +2 -2
  203. package/dist/esm/u-reset-password-button.entry.js +3 -4
  204. package/dist/esm/u-reset-password-button.entry.js.map +1 -1
  205. package/dist/esm/u-send-magic-code-button.entry.js +4 -5
  206. package/dist/esm/u-send-magic-code-button.entry.js.map +1 -1
  207. package/dist/esm/u-signed-in.entry.js +1 -1
  208. package/dist/esm/u-signin-root.entry.js +1 -1
  209. package/dist/esm/u-signin-step.entry.js +4 -5
  210. package/dist/esm/u-signin-step.entry.js.map +1 -1
  211. package/dist/esm/u-signin-strategy.entry.js +1 -1
  212. package/dist/esm/u-social-login-button.entry.js +2 -2
  213. package/dist/esm/u-spinner.entry.js +1 -1
  214. package/dist/esm/u-spinner.entry.js.map +1 -1
  215. package/dist/esm/u-ticketable-list.entry.js +40 -30
  216. package/dist/esm/u-ticketable-list.entry.js.map +1 -1
  217. package/dist/sdk/index.esm.js +1 -1
  218. package/dist/sdk/index.esm.js.map +1 -1
  219. package/dist/sdk/locales/de.json +0 -1
  220. package/dist/sdk/locales/en.json +0 -1
  221. package/dist/sdk/locales/fr.json +0 -1
  222. package/dist/sdk/locales/it.json +0 -1
  223. package/dist/sdk/locales/nl_be.json +0 -1
  224. package/dist/sdk/locales/ro.json +0 -1
  225. package/dist/sdk/{p-5babee6b.entry.js → p-098eef67.entry.js} +2 -2
  226. package/dist/sdk/p-0e74de96.entry.js +2 -0
  227. package/dist/sdk/p-0e74de96.entry.js.map +1 -0
  228. package/dist/sdk/p-0ed36cbb.entry.js +2 -0
  229. package/dist/sdk/p-0ed36cbb.entry.js.map +1 -0
  230. package/dist/sdk/p-1149e044.entry.js +2 -0
  231. package/dist/sdk/p-1149e044.entry.js.map +1 -0
  232. package/dist/sdk/p-16d763fd.entry.js +2 -0
  233. package/dist/sdk/p-16d763fd.entry.js.map +1 -0
  234. package/dist/sdk/p-1d404c36.entry.js +2 -0
  235. package/dist/sdk/p-1d404c36.entry.js.map +1 -0
  236. package/dist/sdk/p-32da9922.entry.js +2 -0
  237. package/dist/sdk/p-32da9922.entry.js.map +1 -0
  238. package/dist/sdk/p-3d3a9c90.entry.js +2 -0
  239. package/dist/sdk/p-3d3a9c90.entry.js.map +1 -0
  240. package/dist/sdk/p-43024bd6.entry.js +2 -0
  241. package/dist/sdk/p-43024bd6.entry.js.map +1 -0
  242. package/dist/sdk/{p-e2e7061b.entry.js → p-5da49d00.entry.js} +2 -2
  243. package/dist/sdk/{p-f961fbea.entry.js → p-67af762e.entry.js} +2 -2
  244. package/dist/sdk/{p-f961fbea.entry.js.map → p-67af762e.entry.js.map} +1 -1
  245. package/dist/sdk/p-7099bd56.entry.js +2 -0
  246. package/dist/sdk/p-7099bd56.entry.js.map +1 -0
  247. package/dist/sdk/p-745742f1.entry.js +2 -0
  248. package/dist/sdk/{p-9e71a36c.entry.js → p-74e6523f.entry.js} +2 -2
  249. package/dist/sdk/p-86d16818.entry.js +2 -0
  250. package/dist/sdk/{p-effaf86b.entry.js.map → p-86d16818.entry.js.map} +1 -1
  251. package/dist/sdk/{p-DA84OuuU.js → p-BasehRhW.js} +2 -2
  252. package/dist/sdk/{p-DA84OuuU.js.map → p-BasehRhW.js.map} +1 -1
  253. package/dist/sdk/p-C4aHo4nN.js +2 -0
  254. package/dist/sdk/p-C4aHo4nN.js.map +1 -0
  255. package/dist/sdk/p-CFiZLMAA.js.map +1 -1
  256. package/dist/sdk/p-DGDhaqCd.js +2 -0
  257. package/dist/sdk/p-DGDhaqCd.js.map +1 -0
  258. package/dist/sdk/{p-CbRhHGU5.js → p-DSq94RWc.js} +2 -2
  259. package/dist/sdk/{p-CbRhHGU5.js.map → p-DSq94RWc.js.map} +1 -1
  260. package/dist/sdk/p-DSwwVdp1.js +2 -0
  261. package/dist/sdk/p-DSwwVdp1.js.map +1 -0
  262. package/dist/sdk/p-a037bbe3.entry.js +2 -0
  263. package/dist/sdk/p-a037bbe3.entry.js.map +1 -0
  264. package/dist/sdk/p-adcb7911.entry.js +2 -0
  265. package/dist/sdk/p-adcb7911.entry.js.map +1 -0
  266. package/dist/sdk/{p-39b61f33.entry.js → p-bbbec3d4.entry.js} +2 -2
  267. package/dist/sdk/{p-f232929b.entry.js → p-c2fba7c8.entry.js} +2 -2
  268. package/dist/sdk/p-c4618822.entry.js +2 -0
  269. package/dist/sdk/p-c4618822.entry.js.map +1 -0
  270. package/dist/sdk/p-ca4e57f2.entry.js +2 -0
  271. package/dist/sdk/p-ca4e57f2.entry.js.map +1 -0
  272. package/dist/sdk/p-ce4ab77c.entry.js +2 -0
  273. package/dist/sdk/p-ce4ab77c.entry.js.map +1 -0
  274. package/dist/sdk/p-d143e097.entry.js +2 -0
  275. package/dist/sdk/p-d143e097.entry.js.map +1 -0
  276. package/dist/sdk/{p-a69b83ec.entry.js → p-e0d2397c.entry.js} +2 -2
  277. package/dist/sdk/{p-80034205.entry.js → p-e6beb9d7.entry.js} +2 -2
  278. package/dist/sdk/p-ecc7fcff.entry.js +2 -0
  279. package/dist/sdk/p-ecc7fcff.entry.js.map +1 -0
  280. package/dist/sdk/{p-2cb6a2d0.entry.js → p-f1788e52.entry.js} +2 -2
  281. package/dist/sdk/p-fb665a5c.entry.js +2 -0
  282. package/dist/sdk/p-fb665a5c.entry.js.map +1 -0
  283. package/dist/sdk/p-fc67cf07.entry.js +2 -0
  284. package/dist/sdk/p-fc67cf07.entry.js.map +1 -0
  285. package/dist/sdk/sdk.esm.js +1 -1
  286. package/dist/sdk/u-conditional-render.entry.esm.js.map +1 -1
  287. package/dist/sdk/u-config.entry.esm.js.map +1 -1
  288. package/dist/sdk/u-error-message.entry.esm.js.map +1 -1
  289. package/dist/sdk/u-field.u-raw-field.entry.esm.js.map +1 -1
  290. package/dist/sdk/u-logout-button.entry.esm.js.map +1 -1
  291. package/dist/sdk/u-magic-code-field.entry.esm.js.map +1 -1
  292. package/dist/sdk/u-missing-fields-submit-button.entry.esm.js.map +1 -1
  293. package/dist/sdk/u-newsletter-checkbox.entry.esm.js.map +1 -1
  294. package/dist/sdk/u-newsletter-logout-button.entry.esm.js.map +1 -1
  295. package/dist/sdk/u-newsletter-preference-checkbox.entry.esm.js.map +1 -1
  296. package/dist/sdk/u-newsletter-resend-doi-button.entry.esm.js.map +1 -1
  297. package/dist/sdk/u-newsletter-root.entry.esm.js.map +1 -1
  298. package/dist/sdk/u-newsletter-toggle-subscription-button.entry.esm.js.map +1 -1
  299. package/dist/sdk/u-passkey.entry.esm.js.map +1 -1
  300. package/dist/sdk/u-profile.u-submit-button.entry.esm.js.map +1 -1
  301. package/dist/sdk/u-reset-password-button.entry.esm.js.map +1 -1
  302. package/dist/sdk/u-send-magic-code-button.entry.esm.js.map +1 -1
  303. package/dist/sdk/u-signin-step.entry.esm.js.map +1 -1
  304. package/dist/sdk/u-spinner.entry.esm.js.map +1 -1
  305. package/dist/sdk/u-ticketable-list.entry.esm.js.map +1 -1
  306. package/dist/types/api/base-client.d.ts +54 -0
  307. package/dist/types/api/base-service.d.ts +62 -0
  308. package/dist/types/api/client.d.ts +9 -31
  309. package/dist/types/api/index.d.ts +1 -0
  310. package/dist/types/api/shared.d.ts +11 -0
  311. package/dist/types/api/standalone.d.ts +105 -0
  312. package/dist/types/auth/api/auth.d.ts +71 -287
  313. package/dist/types/auth/api/schemas.d.ts +572 -0
  314. package/dist/types/auth/auth-helpers.d.ts +65 -66
  315. package/dist/types/auth/store/auth-store.d.ts +3 -3
  316. package/dist/types/components.d.ts +0 -72
  317. package/dist/types/newsletter/api/newsletters.d.ts +73 -196
  318. package/dist/types/newsletter/api/schemas.d.ts +192 -0
  319. package/dist/types/profile/api/profile.d.ts +12 -237
  320. package/dist/types/profile/api/schemas.d.ts +336 -0
  321. package/dist/types/profile/components/profile/profile.d.ts +1 -17
  322. package/dist/types/shared/components/error-message/error-message.d.ts +1 -1
  323. package/dist/types/ticketable/api/schemas.d.ts +108 -15
  324. package/dist/types/ticketable/api/subscriptions.d.ts +16 -83
  325. package/dist/types/ticketable/api/ticketable-service.d.ts +39 -0
  326. package/dist/types/ticketable/api/tickets.d.ts +16 -85
  327. package/dist/types/ticketable/components/ticketable-list/ticketable-list.d.ts +2 -12
  328. package/package.json +5 -1
  329. package/dist/cjs/auth-NU3DBc-6.js +0 -581
  330. package/dist/cjs/auth-NU3DBc-6.js.map +0 -1
  331. package/dist/cjs/auth-store-BaxuIp4z.js.map +0 -1
  332. package/dist/cjs/index-R2MKLaem.js.map +0 -1
  333. package/dist/cjs/newsletter-helpers-DR0vsegt.js.map +0 -1
  334. package/dist/collection/ticketable/api/get-with-schema.js +0 -35
  335. package/dist/collection/ticketable/api/get-with-schema.js.map +0 -1
  336. package/dist/components/auth.js +0 -580
  337. package/dist/components/auth.js.map +0 -1
  338. package/dist/esm/auth-nsjRdpvS.js +0 -579
  339. package/dist/esm/auth-nsjRdpvS.js.map +0 -1
  340. package/dist/esm/auth-store-CVvBlKGv.js.map +0 -1
  341. package/dist/esm/index-DSDkaHWI.js.map +0 -1
  342. package/dist/esm/newsletter-helpers-Dc_24im3.js.map +0 -1
  343. package/dist/sdk/p-0ab98e7a.entry.js +0 -2
  344. package/dist/sdk/p-0ab98e7a.entry.js.map +0 -1
  345. package/dist/sdk/p-0d324822.entry.js +0 -2
  346. package/dist/sdk/p-0d324822.entry.js.map +0 -1
  347. package/dist/sdk/p-0fb37ee9.entry.js +0 -2
  348. package/dist/sdk/p-0fb37ee9.entry.js.map +0 -1
  349. package/dist/sdk/p-3049e73f.entry.js +0 -2
  350. package/dist/sdk/p-3049e73f.entry.js.map +0 -1
  351. package/dist/sdk/p-312b919e.entry.js +0 -2
  352. package/dist/sdk/p-312b919e.entry.js.map +0 -1
  353. package/dist/sdk/p-319c5d3b.entry.js +0 -2
  354. package/dist/sdk/p-319c5d3b.entry.js.map +0 -1
  355. package/dist/sdk/p-34b98f55.entry.js +0 -2
  356. package/dist/sdk/p-34b98f55.entry.js.map +0 -1
  357. package/dist/sdk/p-4ec3302d.entry.js +0 -2
  358. package/dist/sdk/p-4ec3302d.entry.js.map +0 -1
  359. package/dist/sdk/p-568eabbc.entry.js +0 -2
  360. package/dist/sdk/p-568eabbc.entry.js.map +0 -1
  361. package/dist/sdk/p-5b40a68b.entry.js +0 -2
  362. package/dist/sdk/p-5b40a68b.entry.js.map +0 -1
  363. package/dist/sdk/p-66587fdd.entry.js +0 -2
  364. package/dist/sdk/p-66587fdd.entry.js.map +0 -1
  365. package/dist/sdk/p-88d93d64.entry.js +0 -2
  366. package/dist/sdk/p-90e2253e.entry.js +0 -2
  367. package/dist/sdk/p-90e2253e.entry.js.map +0 -1
  368. package/dist/sdk/p-BiILQPdb.js +0 -2
  369. package/dist/sdk/p-BiILQPdb.js.map +0 -1
  370. package/dist/sdk/p-DdUvQelg.js +0 -2
  371. package/dist/sdk/p-DdUvQelg.js.map +0 -1
  372. package/dist/sdk/p-PKvQIsOt.js +0 -2
  373. package/dist/sdk/p-PKvQIsOt.js.map +0 -1
  374. package/dist/sdk/p-a4f5940f.entry.js +0 -2
  375. package/dist/sdk/p-a4f5940f.entry.js.map +0 -1
  376. package/dist/sdk/p-aMrLKr2m.js +0 -2
  377. package/dist/sdk/p-aMrLKr2m.js.map +0 -1
  378. package/dist/sdk/p-bfb04b17.entry.js +0 -2
  379. package/dist/sdk/p-bfb04b17.entry.js.map +0 -1
  380. package/dist/sdk/p-c6816542.entry.js +0 -2
  381. package/dist/sdk/p-c6816542.entry.js.map +0 -1
  382. package/dist/sdk/p-da363474.entry.js +0 -2
  383. package/dist/sdk/p-da363474.entry.js.map +0 -1
  384. package/dist/sdk/p-e54d5d38.entry.js +0 -2
  385. package/dist/sdk/p-e54d5d38.entry.js.map +0 -1
  386. package/dist/sdk/p-e81bbd62.entry.js +0 -2
  387. package/dist/sdk/p-e81bbd62.entry.js.map +0 -1
  388. package/dist/sdk/p-effaf86b.entry.js +0 -2
  389. package/dist/types/ticketable/api/get-with-schema.d.ts +0 -3
  390. /package/dist/sdk/{p-5babee6b.entry.js.map → p-098eef67.entry.js.map} +0 -0
  391. /package/dist/sdk/{p-e2e7061b.entry.js.map → p-5da49d00.entry.js.map} +0 -0
  392. /package/dist/sdk/{p-88d93d64.entry.js.map → p-745742f1.entry.js.map} +0 -0
  393. /package/dist/sdk/{p-9e71a36c.entry.js.map → p-74e6523f.entry.js.map} +0 -0
  394. /package/dist/sdk/{p-39b61f33.entry.js.map → p-bbbec3d4.entry.js.map} +0 -0
  395. /package/dist/sdk/{p-f232929b.entry.js.map → p-c2fba7c8.entry.js.map} +0 -0
  396. /package/dist/sdk/{p-a69b83ec.entry.js.map → p-e0d2397c.entry.js.map} +0 -0
  397. /package/dist/sdk/{p-80034205.entry.js.map → p-e6beb9d7.entry.js.map} +0 -0
  398. /package/dist/sdk/{p-2cb6a2d0.entry.js.map → p-f1788e52.entry.js.map} +0 -0
@@ -1,38 +1,56 @@
1
1
  'use strict';
2
2
 
3
- var i18n = require('./i18n-BoDZ8kd2.js');
4
3
  var index = require('./index-B_N5xKgH.js');
5
- require('./profile-store-P_BcYkef.js');
6
4
  var unidyStore = require('./unidy-store-7AbWnZ6g.js');
5
+ var authStore = require('./auth-store-DC9EVec8.js');
6
+ var i18n = require('./i18n-BAZB-eHh.js');
7
+ var profileStore = require('./profile-store-P_BcYkef.js');
8
+ var flashStore = require('./flash-store-BuIBuQDx.js');
9
+ var componentUtils = require('./component-utils-BpMyeVQo.js');
7
10
 
8
- class ApiClient {
9
- baseUrl;
10
- api_key;
11
+ /**
12
+ * Base API client with shared functionality for both browser and standalone environments.
13
+ */
14
+ /**
15
+ * Abstract base class for API clients.
16
+ * Provides shared functionality for making HTTP requests.
17
+ */
18
+ class BaseApiClient {
19
+ /**
20
+ * Error messages that indicate a connection failure rather than a server error.
21
+ * Grouped by source/environment.
22
+ */
11
23
  static CONNECTION_ERROR_MESSAGES = [
12
- "Failed to fetch",
13
- "NetworkError",
14
- "ERR_CONNECTION_REFUSED",
15
- "ERR_NETWORK",
16
- "ERR_INTERNET_DISCONNECTED",
24
+ // Browser fetch API errors
25
+ "Failed to fetch", // Generic browser fetch failure (Chrome)
26
+ "NetworkError", // Firefox network error
27
+ "Load failed", // Safari network error
28
+ "The network connection was lost", // Safari connection lost
29
+ // Chromium/V8 error codes (used by Node.js and Chrome)
30
+ "ERR_CONNECTION_REFUSED", // Server not accepting connections
31
+ "ERR_NETWORK", // General network error
32
+ "ERR_INTERNET_DISCONNECTED", // No internet connection
33
+ // Node.js system error codes
34
+ "ECONNREFUSED", // Connection refused by server
35
+ "ENOTFOUND", // DNS lookup failed
36
+ "EAI_AGAIN", // Temporary DNS failure
17
37
  ];
18
38
  onConnectionChange;
19
- logger = index.createLogger("ApiClient");
20
- constructor(baseUrl, api_key, onConnectionChange) {
21
- this.baseUrl = baseUrl;
22
- this.api_key = api_key;
23
- this.api_key = api_key;
24
- this.onConnectionChange = onConnectionChange;
39
+ baseUrl;
40
+ api_key;
41
+ constructor(config) {
42
+ this.baseUrl = config.baseUrl;
43
+ this.api_key = config.apiKey;
44
+ this.onConnectionChange = config.onConnectionChange;
25
45
  }
26
46
  isConnectionError(error) {
27
47
  if (error instanceof Error) {
28
- return ApiClient.CONNECTION_ERROR_MESSAGES.some((msg) => error.message.includes(msg));
48
+ return BaseApiClient.CONNECTION_ERROR_MESSAGES.some((msg) => error.message.includes(msg));
29
49
  }
30
50
  return false;
31
51
  }
32
52
  setConnectionStatus(isConnected) {
33
- if (this.onConnectionChange) {
34
- this.onConnectionChange(isConnected);
35
- }
53
+ this.onConnectionChange?.(isConnected);
36
54
  }
37
55
  baseHeaders() {
38
56
  const h = new Headers();
@@ -50,15 +68,27 @@ class ApiClient {
50
68
  }
51
69
  return out;
52
70
  }
71
+ /**
72
+ * Builds a query string from params, filtering out undefined/null values.
73
+ */
74
+ buildQueryString(params) {
75
+ if (!params)
76
+ return "";
77
+ const filtered = Object.entries(params)
78
+ .filter(([_, v]) => v !== undefined && v !== null)
79
+ .map(([k, v]) => [k, String(v)]);
80
+ if (filtered.length === 0)
81
+ return "";
82
+ return `?${new URLSearchParams(Object.fromEntries(filtered)).toString()}`;
83
+ }
53
84
  async request(method, endpoint, body, headers) {
54
85
  let res = null;
55
86
  try {
56
87
  res = await fetch(`${this.baseUrl}${endpoint}`, {
57
88
  method,
58
- mode: "cors",
59
- credentials: "include",
89
+ ...this.getRequestOptions(),
60
90
  headers: this.mergeHeaders(this.baseHeaders(), headers),
61
- body: JSON.stringify(body) || undefined,
91
+ body: body ? JSON.stringify(body) : undefined,
62
92
  });
63
93
  let data;
64
94
  try {
@@ -68,37 +98,33 @@ class ApiClient {
68
98
  data = undefined;
69
99
  }
70
100
  this.setConnectionStatus(true);
71
- const response = {
101
+ return {
72
102
  data,
73
103
  status: res.status,
74
104
  headers: res.headers,
75
105
  success: res.ok,
76
106
  connectionError: false,
77
107
  };
78
- return response;
79
108
  }
80
109
  catch (error) {
81
110
  const connectionFailed = this.isConnectionError(error);
82
111
  if (connectionFailed) {
83
112
  this.setConnectionStatus(false);
84
- index.captureException(error, {
85
- tags: { error_type: "connection_error" },
86
- extra: { endpoint, method },
87
- });
113
+ this.handleConnectionError(error, endpoint, method);
88
114
  }
89
- const response = {
90
- status: res ? res.status : connectionFailed ? 0 : 500,
115
+ return {
116
+ status: res?.status ?? (connectionFailed ? 0 : 500),
91
117
  error: error instanceof Error ? error.message : String(error),
92
- headers: res ? res.headers : new Headers(),
118
+ headers: res?.headers ?? new Headers(),
93
119
  success: false,
94
120
  data: undefined,
95
121
  connectionError: connectionFailed,
96
122
  };
97
- return response;
98
123
  }
99
124
  }
100
- async get(endpoint, headers) {
101
- return this.request("GET", endpoint, undefined, headers);
125
+ async get(endpoint, headers, params) {
126
+ const queryString = this.buildQueryString(params);
127
+ return this.request("GET", `${endpoint}${queryString}`, undefined, headers);
102
128
  }
103
129
  async post(endpoint, body, headers) {
104
130
  return this.request("POST", endpoint, body, headers);
@@ -109,40 +135,26 @@ class ApiClient {
109
135
  async delete(endpoint, headers) {
110
136
  return this.request("DELETE", endpoint, undefined, headers);
111
137
  }
112
- getWithSchema(returnSchema, urlBuilder, paramSchema) {
113
- const fn = async (args, params) => {
114
- // Build URL
115
- const baseUrl = urlBuilder(args);
116
- // Validate and parse params with Zod if provided
117
- let queryString = "";
118
- if (paramSchema && params) {
119
- const validatedParams = paramSchema.parse(params);
120
- queryString = `?${new URLSearchParams(validatedParams).toString()}`;
121
- }
122
- const fullUrl = `${baseUrl}${queryString}`;
123
- const response = await this.get(fullUrl);
124
- if (!response.success || !response.data) {
125
- return response;
126
- }
127
- const parsed = returnSchema.safeParse(response.data);
128
- if (!parsed.success) {
129
- this.logger.error("Invalid response format", parsed.error);
130
- return {
131
- ...response,
132
- success: false,
133
- error: i18n.t("errors.invalid_response_format", {
134
- defaultValue: "Invalid response format",
135
- }),
136
- data: undefined,
137
- };
138
- }
139
- return {
140
- ...response,
141
- data: parsed.data,
142
- };
138
+ }
139
+
140
+ /**
141
+ * Browser-specific API client with CORS mode and Sentry error reporting.
142
+ */
143
+ class ApiClient extends BaseApiClient {
144
+ constructor(baseUrl, apiKey, onConnectionChange) {
145
+ super({ baseUrl, apiKey, onConnectionChange });
146
+ }
147
+ getRequestOptions() {
148
+ return {
149
+ mode: "cors",
150
+ credentials: "include",
143
151
  };
144
- // biome-ignore lint/suspicious/noExplicitAny: fn can literally be any function
145
- return fn;
152
+ }
153
+ handleConnectionError(error, endpoint, method) {
154
+ index.captureException(error, {
155
+ tags: { error_type: "connection_error" },
156
+ extra: { endpoint, method },
157
+ });
146
158
  }
147
159
  }
148
160
 
@@ -686,7 +698,6 @@ const _parse = (_Err) => (schema, value, _ctx, _params) => {
686
698
  }
687
699
  return result.value;
688
700
  };
689
- const parse$1 = /* @__PURE__*/ _parse($ZodRealError);
690
701
  const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
691
702
  const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
692
703
  let result = schema._zod.run({ value, issues: [] }, ctx);
@@ -699,7 +710,6 @@ const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
699
710
  }
700
711
  return result.value;
701
712
  };
702
- const parseAsync$1 = /* @__PURE__*/ _parseAsync($ZodRealError);
703
713
  const _safeParse = (_Err) => (schema, value, _ctx) => {
704
714
  const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
705
715
  const result = schema._zod.run({ value, issues: [] }, ctx);
@@ -822,14 +832,13 @@ function datetime$1(args) {
822
832
  const timeRegex = `${time}(?:${opts.join("|")})`;
823
833
  return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
824
834
  }
825
- const string$2 = (params) => {
835
+ const string$1 = (params) => {
826
836
  const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
827
837
  return new RegExp(`^${regex}$`);
828
838
  };
829
839
  const integer = /^-?\d+$/;
830
- const number$2 = /^-?\d+(?:\.\d+)?/;
831
- const boolean$2 = /^(?:true|false)$/i;
832
- const _null$3 = /^null$/i;
840
+ const number$1 = /^-?\d+(?:\.\d+)?/;
841
+ const boolean$1 = /^(?:true|false)$/i;
833
842
  // regex for string with no uppercase letters
834
843
  const lowercase = /^[^A-Z]*$/;
835
844
  // regex for string with no lowercase letters
@@ -1418,7 +1427,7 @@ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
1418
1427
  });
1419
1428
  const $ZodString = /*@__PURE__*/ $constructor("$ZodString", (inst, def) => {
1420
1429
  $ZodType.init(inst, def);
1421
- inst._zod.pattern = [...(inst?._zod.bag?.patterns ?? [])].pop() ?? string$2(inst._zod.bag);
1430
+ inst._zod.pattern = [...(inst?._zod.bag?.patterns ?? [])].pop() ?? string$1(inst._zod.bag);
1422
1431
  inst._zod.parse = (payload, _) => {
1423
1432
  if (def.coerce)
1424
1433
  try {
@@ -1740,7 +1749,7 @@ const $ZodJWT = /*@__PURE__*/ $constructor("$ZodJWT", (inst, def) => {
1740
1749
  });
1741
1750
  const $ZodNumber = /*@__PURE__*/ $constructor("$ZodNumber", (inst, def) => {
1742
1751
  $ZodType.init(inst, def);
1743
- inst._zod.pattern = inst._zod.bag.pattern ?? number$2;
1752
+ inst._zod.pattern = inst._zod.bag.pattern ?? number$1;
1744
1753
  inst._zod.parse = (payload, _ctx) => {
1745
1754
  if (def.coerce)
1746
1755
  try {
@@ -1774,7 +1783,7 @@ const $ZodNumberFormat = /*@__PURE__*/ $constructor("$ZodNumber", (inst, def) =>
1774
1783
  });
1775
1784
  const $ZodBoolean = /*@__PURE__*/ $constructor("$ZodBoolean", (inst, def) => {
1776
1785
  $ZodType.init(inst, def);
1777
- inst._zod.pattern = boolean$2;
1786
+ inst._zod.pattern = boolean$1;
1778
1787
  inst._zod.parse = (payload, _ctx) => {
1779
1788
  if (def.coerce)
1780
1789
  try {
@@ -1793,23 +1802,6 @@ const $ZodBoolean = /*@__PURE__*/ $constructor("$ZodBoolean", (inst, def) => {
1793
1802
  return payload;
1794
1803
  };
1795
1804
  });
1796
- const $ZodNull = /*@__PURE__*/ $constructor("$ZodNull", (inst, def) => {
1797
- $ZodType.init(inst, def);
1798
- inst._zod.pattern = _null$3;
1799
- inst._zod.values = new Set([null]);
1800
- inst._zod.parse = (payload, _ctx) => {
1801
- const input = payload.value;
1802
- if (input === null)
1803
- return payload;
1804
- payload.issues.push({
1805
- expected: "null",
1806
- code: "invalid_type",
1807
- input,
1808
- inst,
1809
- });
1810
- return payload;
1811
- };
1812
- });
1813
1805
  const $ZodAny = /*@__PURE__*/ $constructor("$ZodAny", (inst, def) => {
1814
1806
  $ZodType.init(inst, def);
1815
1807
  inst._zod.parse = (payload) => payload;
@@ -3041,12 +3033,6 @@ function _boolean(Class, params) {
3041
3033
  ...normalizeParams(params),
3042
3034
  });
3043
3035
  }
3044
- function _null$2(Class, params) {
3045
- return new Class({
3046
- type: "null",
3047
- ...normalizeParams(params),
3048
- });
3049
- }
3050
3036
  function _any(Class) {
3051
3037
  return new Class({
3052
3038
  type: "any",
@@ -3378,12 +3364,12 @@ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
3378
3364
  inst.superRefine = (refinement) => inst.check(superRefine(refinement));
3379
3365
  inst.overwrite = (fn) => inst.check(_overwrite(fn));
3380
3366
  // wrappers
3381
- inst.optional = () => optional$1(inst);
3367
+ inst.optional = () => optional(inst);
3382
3368
  inst.nullable = () => nullable(inst);
3383
- inst.nullish = () => optional$1(nullable(inst));
3369
+ inst.nullish = () => optional(nullable(inst));
3384
3370
  inst.nonoptional = (params) => nonoptional(inst, params);
3385
- inst.array = () => array$1(inst);
3386
- inst.or = (arg) => union$1([inst, arg]);
3371
+ inst.array = () => array(inst);
3372
+ inst.or = (arg) => union([inst, arg]);
3387
3373
  inst.and = (arg) => intersection(inst, arg);
3388
3374
  inst.transform = (tx) => pipe(inst, transform(tx));
3389
3375
  inst.default = (def) => _default(inst, def);
@@ -3474,7 +3460,7 @@ const ZodString = /*@__PURE__*/ $constructor("ZodString", (inst, def) => {
3474
3460
  inst.time = (params) => inst.check(time(params));
3475
3461
  inst.duration = (params) => inst.check(duration(params));
3476
3462
  });
3477
- function string$1(params) {
3463
+ function string(params) {
3478
3464
  return _string(ZodString, params);
3479
3465
  }
3480
3466
  const ZodStringFormat = /*@__PURE__*/ $constructor("ZodStringFormat", (inst, def) => {
@@ -3605,7 +3591,7 @@ const ZodNumber = /*@__PURE__*/ $constructor("ZodNumber", (inst, def) => {
3605
3591
  inst.isFinite = true;
3606
3592
  inst.format = bag.format ?? null;
3607
3593
  });
3608
- function number$1(params) {
3594
+ function number(params) {
3609
3595
  return _number(ZodNumber, params);
3610
3596
  }
3611
3597
  const ZodNumberFormat = /*@__PURE__*/ $constructor("ZodNumberFormat", (inst, def) => {
@@ -3619,16 +3605,9 @@ const ZodBoolean = /*@__PURE__*/ $constructor("ZodBoolean", (inst, def) => {
3619
3605
  $ZodBoolean.init(inst, def);
3620
3606
  ZodType.init(inst, def);
3621
3607
  });
3622
- function boolean$1(params) {
3608
+ function boolean(params) {
3623
3609
  return _boolean(ZodBoolean, params);
3624
3610
  }
3625
- const ZodNull = /*@__PURE__*/ $constructor("ZodNull", (inst, def) => {
3626
- $ZodNull.init(inst, def);
3627
- ZodType.init(inst, def);
3628
- });
3629
- function _null$1(params) {
3630
- return _null$2(ZodNull, params);
3631
- }
3632
3611
  const ZodAny = /*@__PURE__*/ $constructor("ZodAny", (inst, def) => {
3633
3612
  $ZodAny.init(inst, def);
3634
3613
  ZodType.init(inst, def);
@@ -3640,7 +3619,7 @@ const ZodUnknown = /*@__PURE__*/ $constructor("ZodUnknown", (inst, def) => {
3640
3619
  $ZodUnknown.init(inst, def);
3641
3620
  ZodType.init(inst, def);
3642
3621
  });
3643
- function unknown$1() {
3622
+ function unknown() {
3644
3623
  return _unknown(ZodUnknown);
3645
3624
  }
3646
3625
  const ZodNever = /*@__PURE__*/ $constructor("ZodNever", (inst, def) => {
@@ -3669,7 +3648,7 @@ const ZodArray = /*@__PURE__*/ $constructor("ZodArray", (inst, def) => {
3669
3648
  inst.length = (len, params) => inst.check(_length(len, params));
3670
3649
  inst.unwrap = () => inst.element;
3671
3650
  });
3672
- function array$1(element, params) {
3651
+ function array(element, params) {
3673
3652
  return _array(ZodArray, element, params);
3674
3653
  }
3675
3654
  const ZodObject = /*@__PURE__*/ $constructor("ZodObject", (inst, def) => {
@@ -3680,8 +3659,8 @@ const ZodObject = /*@__PURE__*/ $constructor("ZodObject", (inst, def) => {
3680
3659
  });
3681
3660
  inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
3682
3661
  inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall: catchall });
3683
- inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown$1() });
3684
- inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown$1() });
3662
+ inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
3663
+ inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
3685
3664
  inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() });
3686
3665
  inst.strip = () => inst.clone({ ...inst._zod.def, catchall: undefined });
3687
3666
  inst.extend = (incoming) => {
@@ -3696,7 +3675,7 @@ const ZodObject = /*@__PURE__*/ $constructor("ZodObject", (inst, def) => {
3696
3675
  inst.partial = (...args) => partial(ZodOptional, inst, args[0]);
3697
3676
  inst.required = (...args) => required(ZodNonOptional, inst, args[0]);
3698
3677
  });
3699
- function object$1(shape, params) {
3678
+ function object(shape, params) {
3700
3679
  const def = {
3701
3680
  type: "object",
3702
3681
  shape: shape ?? {},
@@ -3709,7 +3688,7 @@ const ZodUnion = /*@__PURE__*/ $constructor("ZodUnion", (inst, def) => {
3709
3688
  ZodType.init(inst, def);
3710
3689
  inst.options = def.options;
3711
3690
  });
3712
- function union$1(options, params) {
3691
+ function union(options, params) {
3713
3692
  return new ZodUnion({
3714
3693
  type: "union",
3715
3694
  options: options,
@@ -3752,7 +3731,7 @@ const ZodRecord = /*@__PURE__*/ $constructor("ZodRecord", (inst, def) => {
3752
3731
  inst.keyType = def.keyType;
3753
3732
  inst.valueType = def.valueType;
3754
3733
  });
3755
- function record$1(keyType, valueType, params) {
3734
+ function record(keyType, valueType, params) {
3756
3735
  return new ZodRecord({
3757
3736
  type: "record",
3758
3737
  keyType,
@@ -3820,7 +3799,7 @@ const ZodLiteral = /*@__PURE__*/ $constructor("ZodLiteral", (inst, def) => {
3820
3799
  },
3821
3800
  });
3822
3801
  });
3823
- function literal$1(value, params) {
3802
+ function literal(value, params) {
3824
3803
  return new ZodLiteral({
3825
3804
  type: "literal",
3826
3805
  values: Array.isArray(value) ? value : [value],
@@ -3872,7 +3851,7 @@ const ZodOptional = /*@__PURE__*/ $constructor("ZodOptional", (inst, def) => {
3872
3851
  ZodType.init(inst, def);
3873
3852
  inst.unwrap = () => inst._zod.def.innerType;
3874
3853
  });
3875
- function optional$1(innerType) {
3854
+ function optional(innerType) {
3876
3855
  return new ZodOptional({
3877
3856
  type: "optional",
3878
3857
  innerType: innerType,
@@ -3984,57 +3963,110 @@ function date(params) {
3984
3963
  return _coercedDate(ZodDate, params);
3985
3964
  }
3986
3965
 
3987
- const FieldType = _enum(["text", "textarea", "number", "boolean", "select", "radio", "date", "datetime-local", "checkbox", "tel"]);
3988
- const BaseFieldDataSchema = object$1({
3989
- required: boolean$1(),
3990
- label: string$1(),
3991
- attr_name: string$1(),
3992
- locked: boolean$1().optional(),
3993
- locked_text: string$1().optional(),
3966
+ /**
3967
+ * Base error schema that all API errors extend from.
3968
+ * Contains the common error_identifier field.
3969
+ */
3970
+ const BaseErrorSchema = object({
3971
+ error_identifier: string(),
3972
+ });
3973
+ /**
3974
+ * Schema validation error extends base error with an array of error messages.
3975
+ */
3976
+ const SchemaValidationErrorSchema = BaseErrorSchema.extend({
3977
+ errors: array(string()),
3978
+ });
3979
+ const PaginationMetaSchema = object({
3980
+ count: number(),
3981
+ page: number(),
3982
+ limit: number(),
3983
+ last: number(),
3984
+ prev: number().nullable(),
3985
+ next: number().nullable(),
3986
+ });
3987
+ const PaginationParamsSchema = object({
3988
+ page: number().int().min(1),
3989
+ limit: number().int().min(0).max(250),
3990
+ });
3991
+
3992
+ // Field type enum
3993
+ const FieldTypeEnum = _enum([
3994
+ "text",
3995
+ "textarea",
3996
+ "number",
3997
+ "boolean",
3998
+ "select",
3999
+ "radio",
4000
+ "date",
4001
+ "datetime-local",
4002
+ "checkbox",
4003
+ "tel",
4004
+ ]);
4005
+ // Base field data schema
4006
+ const BaseFieldDataSchema = object({
4007
+ required: boolean(),
4008
+ label: string(),
4009
+ attr_name: string(),
4010
+ locked: boolean().optional(),
4011
+ locked_text: string().optional(),
3994
4012
  })
3995
4013
  .strict();
3996
- const SelectOptionSchema = object$1({
3997
- value: string$1(),
3998
- label: string$1(),
4014
+ // Select option schema
4015
+ const SelectOptionSchema = object({
4016
+ value: string(),
4017
+ label: string(),
3999
4018
  })
4000
4019
  .strict();
4001
- const RadioValue = union$1([string$1(), literal$1("_NOT_SET_"), boolean$1()]).nullable();
4002
- const RadioOptionSchema = object$1({
4020
+ // Radio value type
4021
+ const RadioValue = union([string(), literal("_NOT_SET_"), boolean()]).nullable();
4022
+ // Radio option schema
4023
+ const RadioOptionSchema = object({
4003
4024
  value: RadioValue,
4004
- label: string$1(),
4005
- checked: boolean$1(),
4025
+ label: string(),
4026
+ checked: boolean(),
4006
4027
  })
4007
4028
  .strict();
4029
+ // Text field type enum
4030
+ const TextFieldTypeEnum = _enum(["text", "textarea"]);
4031
+ // Text field schema
4008
4032
  const TextFieldSchema = BaseFieldDataSchema.extend({
4009
- value: union$1([string$1(), _null$1()]),
4010
- type: _enum(["text", "textarea"]),
4033
+ value: string().nullable(),
4034
+ type: TextFieldTypeEnum,
4011
4035
  }).strict();
4036
+ // Phone field schema
4012
4037
  const PhoneFieldSchema = BaseFieldDataSchema.extend({
4013
- value: union$1([string$1().nullable()]),
4014
- type: _enum(["tel"]),
4038
+ value: string().nullable(),
4039
+ type: literal("tel"),
4015
4040
  }).strict();
4041
+ // Radio field schema
4016
4042
  const RadioFieldSchema = BaseFieldDataSchema.extend({
4017
4043
  value: RadioValue,
4018
- type: _enum(["radio"]),
4019
- radio_options: array$1(RadioOptionSchema),
4044
+ type: literal("radio"),
4045
+ radio_options: array(RadioOptionSchema),
4020
4046
  }).strict();
4047
+ // Select field schema
4021
4048
  const SelectFieldSchema = BaseFieldDataSchema.extend({
4022
- value: string$1().nullable(),
4023
- type: _enum(["select"]),
4024
- options: array$1(SelectOptionSchema),
4049
+ value: string().nullable(),
4050
+ type: literal("select"),
4051
+ options: array(SelectOptionSchema),
4025
4052
  }).strict();
4053
+ // Date field type enum
4054
+ const DateFieldTypeEnum = _enum(["date", "datetime-local"]);
4055
+ // Date field schema
4026
4056
  const DateFieldSchema = BaseFieldDataSchema.extend({
4027
- value: union$1([string$1(), _null$1()]),
4028
- type: _enum(["date", "datetime-local"]),
4057
+ value: string().nullable(),
4058
+ type: DateFieldTypeEnum,
4029
4059
  }).strict();
4060
+ // Custom field schema
4030
4061
  const CustomFieldSchema = BaseFieldDataSchema.extend({
4031
- value: union$1([string$1(), _null$1(), boolean$1(), number$1(), array$1(string$1())]),
4032
- type: FieldType,
4033
- readonly: boolean$1(),
4034
- radio_options: array$1(RadioOptionSchema).optional(),
4035
- options: array$1(SelectOptionSchema).optional(),
4062
+ value: union([string(), boolean(), number(), array(string())]).nullable(),
4063
+ type: FieldTypeEnum,
4064
+ readonly: boolean(),
4065
+ radio_options: array(RadioOptionSchema).optional(),
4066
+ options: array(SelectOptionSchema).optional(),
4036
4067
  }).strict();
4037
- const UserProfileSchema = object$1({
4068
+ // User profile schema
4069
+ const UserProfileSchema = object({
4038
4070
  salutation: RadioFieldSchema,
4039
4071
  first_name: TextFieldSchema,
4040
4072
  last_name: TextFieldSchema,
@@ -4048,15 +4080,16 @@ const UserProfileSchema = object$1({
4048
4080
  country_code: SelectFieldSchema,
4049
4081
  date_of_birth: DateFieldSchema,
4050
4082
  preferred_language: TextFieldSchema.optional(),
4051
- custom_attributes: record$1(string$1(), CustomFieldSchema),
4052
- });
4053
- const UserProfileErrorSchema = object$1({
4054
- error_identifier: string$1(),
4055
- })
4056
- .strict();
4057
- const FormErrorsValue = union$1([array$1(string$1()), array$1(tuple([number$1(), array$1(string$1())]))]);
4058
- const FormErrorsRawSchema = record$1(string$1(), FormErrorsValue);
4059
- const UserProfileFormErrorSchema = object$1({
4083
+ custom_attributes: record(string(), CustomFieldSchema),
4084
+ });
4085
+ // Profile error response schema extends base error
4086
+ const ProfileErrorResponseSchema = BaseErrorSchema;
4087
+ // Form errors value type
4088
+ const FormErrorsValue = union([array(string()), array(tuple([number(), array(string())]))]);
4089
+ // Form errors raw schema
4090
+ const FormErrorsRawSchema = record(string(), FormErrorsValue);
4091
+ // User profile form error schema with transformation
4092
+ const UserProfileFormErrorSchema = object({
4060
4093
  errors: FormErrorsRawSchema,
4061
4094
  })
4062
4095
  .strict()
@@ -4069,144 +4102,157 @@ const UserProfileFormErrorSchema = object$1({
4069
4102
  }));
4070
4103
  return { errors, flatErrors };
4071
4104
  });
4072
- const UserProfileRailsFormErrorSchema = object$1({
4073
- error_details: FormErrorsRawSchema,
4074
- })
4075
- .loose()
4076
- .transform(({ error_details }) => ({ errors: error_details }))
4077
- .pipe(UserProfileFormErrorSchema);
4078
- const ProfileResultSchema = union$1([
4079
- UserProfileSchema,
4080
- UserProfileErrorSchema,
4081
- UserProfileFormErrorSchema,
4082
- UserProfileRailsFormErrorSchema,
4083
- ]);
4084
- class ProfileService {
4085
- client;
4086
- constructor(client) {
4087
- this.client = client;
4105
+
4106
+ class ProfileService extends BaseService {
4107
+ constructor(client, deps) {
4108
+ super(client, "ProfileService", deps);
4088
4109
  }
4089
- async fetchProfile({ idToken, lang }) {
4110
+ async get() {
4111
+ const idToken = await this.getIdToken();
4090
4112
  if (!idToken) {
4091
- return { status: 401, success: false, headers: new Headers(), error: "missing id_token" };
4113
+ return ["missing_id_token", null];
4092
4114
  }
4093
- try {
4094
- const resp = await this.client.get(`/api/sdk/v1/profile${lang ? `?lang=${lang}` : ""}`, { "X-ID-Token": idToken });
4095
- const parsed = ProfileResultSchema.safeParse(resp.data);
4096
- if (!parsed.success) {
4097
- return { status: 400, success: false, headers: new Headers(), error: "invalid profile data" };
4115
+ const lang = this.getLocale();
4116
+ const response = await this.client.get(`/api/sdk/v1/profile${lang ? `?lang=${lang}` : ""}`, this.buildAuthHeaders({ "X-ID-Token": idToken }));
4117
+ return this.handleResponse(response, () => {
4118
+ if (!response.success) {
4119
+ const error = ProfileErrorResponseSchema.safeParse(response.data);
4120
+ if (error.success) {
4121
+ if (response.status === 401) {
4122
+ return ["unauthorized", error.data];
4123
+ }
4124
+ return ["server_error", error.data];
4125
+ }
4126
+ return ["server_error", null];
4098
4127
  }
4099
- const data = parsed.data;
4100
- if ("error_identifier" in data) {
4101
- return { ...resp, data, error: data.error_identifier };
4128
+ const parsed = UserProfileSchema.safeParse(response.data);
4129
+ if (!parsed.success) {
4130
+ this.logger.error("Invalid profile data", parsed.error);
4131
+ return ["invalid_profile_data", null];
4102
4132
  }
4103
- return { ...resp, data };
4104
- }
4105
- catch (error) {
4106
- index.captureException(error);
4107
- return {
4108
- status: error instanceof TypeError ? 0 : 500,
4109
- success: false,
4110
- headers: new Headers(),
4111
- error: error instanceof Error ? error.message : String(error),
4112
- };
4113
- }
4133
+ return [null, parsed.data];
4134
+ });
4114
4135
  }
4115
- async updateProfile({ idToken, data, lang }) {
4136
+ async update(args) {
4137
+ const idToken = await this.getIdToken();
4116
4138
  if (!idToken) {
4117
- return { status: 401, success: false, headers: new Headers(), error: "missing id_token" };
4139
+ return ["missing_id_token", null];
4118
4140
  }
4119
- const payload = data;
4120
- try {
4121
- const resp = await this.client.patch(`/api/sdk/v1/profile${lang ? `?lang=${lang}` : ""}`, { ...payload }, { "X-ID-Token": idToken });
4122
- const parsed = ProfileResultSchema.safeParse(resp.data);
4123
- if (!parsed.success) {
4124
- return { status: 400, success: false, headers: new Headers(), error: "invalid profile data" };
4125
- }
4126
- const result = parsed.data;
4127
- if ("errors" in result) {
4128
- return { ...resp, data: result };
4141
+ const { payload } = args;
4142
+ const lang = this.getLocale();
4143
+ const response = await this.client.patch(`/api/sdk/v1/profile${lang ? `?lang=${lang}` : ""}`, { ...payload }, this.buildAuthHeaders({ "X-ID-Token": idToken }));
4144
+ return this.handleResponse(response, () => {
4145
+ if (!response.success) {
4146
+ // Check for form validation errors first
4147
+ const formErrors = UserProfileFormErrorSchema.safeParse(response.data);
4148
+ if (formErrors.success) {
4149
+ return ["validation_error", formErrors.data];
4150
+ }
4151
+ // Check for API error response
4152
+ const error = ProfileErrorResponseSchema.safeParse(response.data);
4153
+ if (error.success) {
4154
+ if (response.status === 401) {
4155
+ return ["unauthorized", error.data];
4156
+ }
4157
+ return ["server_error", error.data];
4158
+ }
4159
+ return ["server_error", null];
4129
4160
  }
4130
- if ("error_identifier" in result) {
4131
- return { ...resp, data: result, error: result.error_identifier };
4161
+ const parsed = UserProfileSchema.safeParse(response.data);
4162
+ if (!parsed.success) {
4163
+ this.logger.error("Invalid profile data", parsed.error);
4164
+ return ["invalid_profile_data", null];
4132
4165
  }
4133
- return { ...resp, data: result };
4134
- }
4135
- catch (error) {
4136
- index.captureException(error);
4137
- return {
4138
- status: error instanceof TypeError ? 0 : 500,
4139
- success: false,
4140
- headers: new Headers(),
4141
- error: error instanceof Error ? error.message : String(error),
4142
- };
4143
- }
4166
+ return [null, parsed.data];
4167
+ });
4144
4168
  }
4145
4169
  }
4146
4170
 
4147
- const LoginOptionsSchema = object$1({
4148
- magic_link: boolean$1(),
4149
- password: boolean$1(),
4150
- social_logins: array$1(string$1()),
4151
- passkey: boolean$1(),
4152
- });
4153
- const CreateSignInResponseSchema = object$1({
4154
- sid: string$1(),
4155
- status: _enum(["pending_verification", "authenticated", "completed"]),
4156
- email: string$1(),
4157
- expired: boolean$1(),
4171
+ // Sign-in status enum
4172
+ const SignInStatusEnum = _enum(["pending_verification", "authenticated", "completed"]);
4173
+ // Login options for sign-in response
4174
+ const LoginOptionsSchema = object({
4175
+ magic_link: boolean(),
4176
+ password: boolean(),
4177
+ social_logins: array(string()),
4178
+ passkey: boolean(),
4179
+ });
4180
+ // Sign-in creation response
4181
+ const CreateSignInResponseSchema = object({
4182
+ sid: string(),
4183
+ status: SignInStatusEnum,
4184
+ email: string(),
4185
+ expired: boolean(),
4158
4186
  login_options: LoginOptionsSchema,
4159
4187
  });
4160
- const ErrorSchema = object$1({
4161
- error_identifier: string$1(),
4162
- });
4163
- const SendMagicCodeResponseSchema = object$1({
4164
- enable_resend_after: number$1(),
4165
- sid: string$1().optional(),
4166
- });
4167
- const SendMagicCodeErrorSchema = object$1({
4168
- error_identifier: string$1(),
4169
- enable_resend_after: number$1(),
4170
- });
4171
- const TokenResponseSchema = object$1({
4172
- jwt: string$1(),
4173
- sid: string$1().optional(),
4174
- });
4175
- const RequiredFieldsResponseSchema = object$1({
4176
- error_identifier: literal$1("missing_required_fields"),
4177
- fields: UserProfileSchema.omit({ custom_attributes: true }).partial().extend({
4178
- custom_attributes: UserProfileSchema.shape.custom_attributes?.optional(),
4188
+ // Generic error response (re-export of base error for backwards compatibility)
4189
+ const ErrorSchema = BaseErrorSchema;
4190
+ // Magic code response
4191
+ const SendMagicCodeResponseSchema = object({
4192
+ enable_resend_after: number(),
4193
+ sid: string().optional(),
4194
+ });
4195
+ // Magic code error extends base error with resend timing
4196
+ const SendMagicCodeErrorSchema = BaseErrorSchema.extend({
4197
+ enable_resend_after: number(),
4198
+ });
4199
+ // JWT token response
4200
+ const TokenResponseSchema = object({
4201
+ jwt: string(),
4202
+ sid: string().optional(),
4203
+ });
4204
+ // Missing required fields response extends base error with specific error_identifier
4205
+ const RequiredFieldsResponseSchema = object({
4206
+ error_identifier: literal("missing_required_fields"),
4207
+ meta: object({
4208
+ fields: UserProfileSchema.omit({ custom_attributes: true }).partial().extend({
4209
+ custom_attributes: UserProfileSchema.shape.custom_attributes?.optional(),
4210
+ }),
4211
+ sid: string().optional(),
4179
4212
  }),
4180
- sid: string$1().optional(),
4181
- });
4182
- object$1({
4183
- error_details: object$1({
4184
- password: array$1(string$1()),
4213
+ })
4214
+ .transform(({ error_identifier, meta }) => ({
4215
+ error_identifier,
4216
+ fields: meta.fields,
4217
+ sid: meta.sid,
4218
+ }));
4219
+ // Invalid password response with field-level errors
4220
+ const InvalidPasswordResponseSchema = object({
4221
+ error_details: object({
4222
+ password: array(string()),
4185
4223
  }),
4186
4224
  });
4187
- const PasskeyOptionsResponseSchema = object$1({
4188
- challenge: string$1(),
4189
- timeout: number$1(),
4190
- rpId: string$1(),
4191
- userVerification: string$1(),
4192
- allowCredentials: array$1(any()),
4193
- });
4194
- object$1({
4195
- id: string$1(),
4196
- rawId: string$1(),
4197
- response: object$1({
4198
- authenticatorData: string$1(),
4199
- clientDataJSON: string$1(),
4200
- signature: string$1(),
4225
+ // Passkey authentication options
4226
+ const PasskeyOptionsResponseSchema = object({
4227
+ challenge: string(),
4228
+ timeout: number(),
4229
+ rpId: string(),
4230
+ userVerification: string(),
4231
+ allowCredentials: array(any()),
4232
+ });
4233
+ // Passkey credential for authentication
4234
+ object({
4235
+ id: string(),
4236
+ rawId: string(),
4237
+ response: object({
4238
+ authenticatorData: string(),
4239
+ clientDataJSON: string(),
4240
+ signature: string(),
4201
4241
  }),
4202
- type: string$1(),
4242
+ type: string(),
4203
4243
  });
4204
- class AuthService {
4205
- client;
4206
- constructor(client) {
4207
- this.client = client;
4244
+
4245
+ class AuthService extends BaseService {
4246
+ constructor(client, deps) {
4247
+ super(client, "AuthService", deps);
4208
4248
  }
4209
- async createSignIn(email, password, sendMagicCode) {
4249
+ /** Safely parse error response, returning a fallback if parsing fails */
4250
+ parseErrorResponse(data) {
4251
+ const parsed = ErrorSchema.safeParse(data);
4252
+ return parsed.success ? parsed.data : { error_identifier: "unknown_error" };
4253
+ }
4254
+ async createSignIn(args) {
4255
+ const { email, password, sendMagicCode } = args.payload;
4210
4256
  const response = await this.client.post("/api/sdk/v1/sign_ins", { email, password, sendMagicCode });
4211
4257
  return this.handleResponse(response, () => {
4212
4258
  if (!response.success) {
@@ -4214,7 +4260,7 @@ class AuthService {
4214
4260
  if (missing_fields_check.success) {
4215
4261
  return ["missing_required_fields", missing_fields_check.data];
4216
4262
  }
4217
- const error_response = ErrorSchema.parse(response.data);
4263
+ const error_response = this.parseErrorResponse(response.data);
4218
4264
  return [
4219
4265
  error_response.error_identifier,
4220
4266
  error_response,
@@ -4229,25 +4275,25 @@ class AuthService {
4229
4275
  return [null, CreateSignInResponseSchema.parse(response.data)];
4230
4276
  });
4231
4277
  }
4232
- async sendMagicCode(signInId) {
4278
+ async sendMagicCode(args) {
4279
+ const { signInId } = args;
4233
4280
  const response = await this.client.post(`/api/sdk/v1/sign_ins/${signInId}/send_magic_code`, {});
4234
4281
  return this.handleResponse(response, () => {
4235
4282
  if (!response.success) {
4236
- try {
4237
- const error_response = SendMagicCodeErrorSchema.parse(response.data);
4238
- return ["magic_code_recently_created", error_response];
4239
- }
4240
- catch {
4241
- const error_response = ErrorSchema.parse(response.data);
4242
- return [error_response.error_identifier, error_response];
4283
+ const magicCodeError = SendMagicCodeErrorSchema.safeParse(response.data);
4284
+ if (magicCodeError.success) {
4285
+ return ["magic_code_recently_created", magicCodeError.data];
4243
4286
  }
4287
+ const error_response = this.parseErrorResponse(response.data);
4288
+ return [error_response.error_identifier, error_response];
4244
4289
  }
4245
4290
  return [null, SendMagicCodeResponseSchema.parse(response.data)];
4246
4291
  });
4247
4292
  }
4248
- async authenticateWithPassword(signInId, password) {
4293
+ async authenticateWithPassword(args) {
4294
+ const { signInId, payload } = args;
4249
4295
  const response = await this.client.post(`/api/sdk/v1/sign_ins/${signInId}/authenticate`, {
4250
- password,
4296
+ password: payload.password,
4251
4297
  });
4252
4298
  return this.handleResponse(response, () => {
4253
4299
  if (!response.success) {
@@ -4255,7 +4301,7 @@ class AuthService {
4255
4301
  if (missing_fields_check.success) {
4256
4302
  return ["missing_required_fields", missing_fields_check.data];
4257
4303
  }
4258
- const error_response = ErrorSchema.parse(response.data);
4304
+ const error_response = this.parseErrorResponse(response.data);
4259
4305
  return [
4260
4306
  error_response.error_identifier,
4261
4307
  error_response,
@@ -4264,10 +4310,10 @@ class AuthService {
4264
4310
  return [null, TokenResponseSchema.parse(response.data)];
4265
4311
  });
4266
4312
  }
4267
- // biome-ignore lint/suspicious/noExplicitAny: user fields are dynamic
4268
- async updateMissingFields(signInId, user) {
4313
+ async updateMissingFields(args) {
4314
+ const { signInId, payload } = args;
4269
4315
  const response = await this.client.patch(`/api/sdk/v1/sign_ins/${signInId}/update_required_fields`, {
4270
- user,
4316
+ user: payload.user,
4271
4317
  });
4272
4318
  return this.handleResponse(response, () => {
4273
4319
  if (!response.success) {
@@ -4275,15 +4321,16 @@ class AuthService {
4275
4321
  if (missing_fields_check.success) {
4276
4322
  return ["missing_required_fields", missing_fields_check.data];
4277
4323
  }
4278
- const error_response = ErrorSchema.parse(response.data);
4324
+ const error_response = this.parseErrorResponse(response.data);
4279
4325
  return [error_response.error_identifier, error_response];
4280
4326
  }
4281
4327
  return [null, TokenResponseSchema.parse(response.data)];
4282
4328
  });
4283
4329
  }
4284
- async authenticateWithMagicCode(signInId, code) {
4330
+ async authenticateWithMagicCode(args) {
4331
+ const { signInId, payload } = args;
4285
4332
  const response = await this.client.post(`/api/sdk/v1/sign_ins/${signInId}/authenticate`, {
4286
- code,
4333
+ code: payload.code,
4287
4334
  });
4288
4335
  return this.handleResponse(response, () => {
4289
4336
  if (!response.success) {
@@ -4291,7 +4338,7 @@ class AuthService {
4291
4338
  if (missing_fields_check.success) {
4292
4339
  return ["missing_required_fields", missing_fields_check.data];
4293
4340
  }
4294
- const error_response = ErrorSchema.parse(response.data);
4341
+ const error_response = this.parseErrorResponse(response.data);
4295
4342
  return [
4296
4343
  error_response.error_identifier,
4297
4344
  error_response,
@@ -4300,21 +4347,25 @@ class AuthService {
4300
4347
  return [null, TokenResponseSchema.parse(response.data)];
4301
4348
  });
4302
4349
  }
4303
- async refreshToken(signInId) {
4350
+ async refreshToken(args) {
4351
+ const { signInId } = args;
4304
4352
  const response = await this.client.post(`/api/sdk/v1/sign_ins/${signInId}/refresh_token`, {});
4305
4353
  return this.handleResponse(response, () => {
4306
4354
  if (!response.success) {
4307
- const error_response = ErrorSchema.parse(response.data);
4355
+ const error_response = this.parseErrorResponse(response.data);
4308
4356
  return [error_response.error_identifier, error_response];
4309
4357
  }
4310
4358
  return [null, TokenResponseSchema.parse(response.data)];
4311
4359
  });
4312
4360
  }
4313
- async sendResetPasswordEmail(signInId, returnTo) {
4314
- const response = await this.client.post(`/api/sdk/v1/sign_ins/${signInId}/password_reset/send`, { return_to: returnTo });
4361
+ async sendResetPasswordEmail(args) {
4362
+ const { signInId, payload } = args;
4363
+ const response = await this.client.post(`/api/sdk/v1/sign_ins/${signInId}/password_reset/send`, {
4364
+ return_to: payload.returnTo,
4365
+ });
4315
4366
  return this.handleResponse(response, () => {
4316
4367
  if (!response.success) {
4317
- const error_response = ErrorSchema.parse(response.data);
4368
+ const error_response = this.parseErrorResponse(response.data);
4318
4369
  return [
4319
4370
  error_response.error_identifier,
4320
4371
  error_response,
@@ -4323,61 +4374,68 @@ class AuthService {
4323
4374
  return [null, null];
4324
4375
  });
4325
4376
  }
4326
- async resetPassword(signInId, token, password, passwordConfirmation) {
4377
+ async resetPassword(args) {
4378
+ const { signInId, token, payload } = args;
4327
4379
  const response = await this.client.patch(`/api/sdk/v1/sign_ins/${signInId}/password_reset`, {
4328
4380
  token,
4329
- password,
4330
- password_confirmation: passwordConfirmation,
4381
+ password: payload.password,
4382
+ password_confirmation: payload.passwordConfirmation,
4331
4383
  });
4332
4384
  return this.handleResponse(response, () => {
4333
4385
  if (!response.success) {
4334
- const error_response = ErrorSchema.parse(response.data);
4335
- return [
4336
- error_response.error_identifier,
4337
- response.data,
4338
- ];
4386
+ // invalid_password has a different response shape (error_details.password)
4387
+ const invalidPasswordParsed = InvalidPasswordResponseSchema.safeParse(response.data);
4388
+ if (invalidPasswordParsed.success) {
4389
+ return ["invalid_password", invalidPasswordParsed.data];
4390
+ }
4391
+ const error_response = this.parseErrorResponse(response.data);
4392
+ return [error_response.error_identifier, error_response];
4339
4393
  }
4340
4394
  return [null, null];
4341
4395
  });
4342
4396
  }
4343
- async validateResetPasswordToken(signInId, token) {
4397
+ async validateResetPasswordToken(args) {
4398
+ const { signInId, token } = args;
4344
4399
  const response = await this.client.get(`/api/sdk/v1/sign_ins/${signInId}/password_reset?token=${encodeURIComponent(token)}`);
4345
4400
  return this.handleResponse(response, () => {
4346
4401
  if (!response.success) {
4347
- const error_response = ErrorSchema.parse(response.data);
4402
+ const error_response = this.parseErrorResponse(response.data);
4348
4403
  return [error_response.error_identifier, error_response];
4349
4404
  }
4350
4405
  return [null, null];
4351
4406
  });
4352
4407
  }
4353
- async signOut(signInId) {
4408
+ async signOut(args) {
4409
+ const { signInId } = args;
4354
4410
  const response = await this.client.post(`/api/sdk/v1/sign_ins/${signInId}/sign_out`, {});
4355
4411
  return this.handleResponse(response, () => {
4356
4412
  if (!response.success) {
4357
- const error_response = ErrorSchema.parse(response.data);
4413
+ const error_response = this.parseErrorResponse(response.data);
4358
4414
  return [error_response.error_identifier, error_response];
4359
4415
  }
4360
4416
  return [null, null];
4361
4417
  });
4362
4418
  }
4363
- async getPasskeyOptions(sid) {
4364
- const endpoint = sid ? `/api/sdk/v1/passkeys/new?sid=${encodeURIComponent(sid)}` : "/api/sdk/v1/passkeys/new";
4419
+ async getPasskeyOptions(args) {
4420
+ const signInId = args?.signInId;
4421
+ const endpoint = signInId ? `/api/sdk/v1/passkeys/new?sid=${encodeURIComponent(signInId)}` : "/api/sdk/v1/passkeys/new";
4365
4422
  const response = await this.client.get(endpoint);
4366
4423
  return this.handleResponse(response, () => {
4367
4424
  if (!response.success) {
4368
- const error_response = ErrorSchema.parse(response.data);
4425
+ const error_response = this.parseErrorResponse(response.data);
4369
4426
  return ["bad_request", error_response];
4370
4427
  }
4371
4428
  return [null, PasskeyOptionsResponseSchema.parse(response.data)];
4372
4429
  });
4373
4430
  }
4374
- async authenticateWithPasskey(credential) {
4431
+ async authenticateWithPasskey(args) {
4432
+ const { payload } = args;
4375
4433
  const response = await this.client.post("/api/sdk/v1/passkeys", {
4376
- publicKeyCredential: credential,
4434
+ publicKeyCredential: payload.credential,
4377
4435
  });
4378
4436
  return this.handleResponse(response, () => {
4379
4437
  if (!response.success) {
4380
- const error_response = ErrorSchema.parse(response.data);
4438
+ const error_response = this.parseErrorResponse(response.data);
4381
4439
  return [
4382
4440
  error_response.error_identifier,
4383
4441
  error_response,
@@ -4386,841 +4444,1151 @@ class AuthService {
4386
4444
  return [null, TokenResponseSchema.parse(response.data)];
4387
4445
  });
4388
4446
  }
4389
- handleResponse(
4390
- // biome-ignore lint/suspicious/noExplicitAny: generic handler for all responses
4391
- response, handler) {
4392
- if (response.connectionError) {
4393
- unidyStore.unidyState.backendConnected = false;
4394
- return ["connection_failed", null];
4395
- }
4396
- try {
4397
- return handler();
4398
- }
4399
- catch (error) {
4400
- index.captureException(error);
4401
- return ["schema_validation_error", SchemaValidationErrorSchema.parse(response.data)];
4402
- }
4403
- }
4404
4447
  }
4405
4448
 
4406
- const ZodMiniType = /*@__PURE__*/ $constructor("ZodMiniType", (inst, def) => {
4407
- if (!inst._zod)
4408
- throw new Error("Uninitialized schema in ZodMiniType.");
4409
- $ZodType.init(inst, def);
4410
- inst.def = def;
4411
- inst.type = def.type;
4412
- inst.parse = (data, params) => parse$1(inst, data, params, { callee: inst.parse });
4413
- inst.safeParse = (data, params) => safeParse$1(inst, data, params);
4414
- inst.parseAsync = async (data, params) => parseAsync$1(inst, data, params, { callee: inst.parseAsync });
4415
- inst.safeParseAsync = async (data, params) => safeParseAsync$1(inst, data, params);
4416
- inst.check = (...checks) => {
4417
- return inst.clone({
4418
- ...def,
4419
- checks: [
4420
- ...(def.checks ?? []),
4421
- ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch),
4422
- ],
4423
- }
4424
- // { parent: true }
4425
- );
4426
- };
4427
- inst.clone = (_def, params) => clone(inst, _def, params);
4428
- inst.brand = () => inst;
4429
- inst.register = ((reg, meta) => {
4430
- reg.add(inst, meta);
4431
- return inst;
4432
- });
4433
- });
4434
- const ZodMiniString = /*@__PURE__*/ $constructor("ZodMiniString", (inst, def) => {
4435
- $ZodString.init(inst, def);
4436
- ZodMiniType.init(inst, def);
4449
+ // Salutation enum
4450
+ const SalutationEnum = _enum(["mr", "mrs", "mx"]);
4451
+ // Newsletter subscription from API
4452
+ const NewsletterSubscriptionSchema = object({
4453
+ id: number(),
4454
+ email: string(),
4455
+ newsletter_internal_name: string(),
4456
+ preference_identifiers: array(string()),
4457
+ preference_token: string(),
4458
+ confirmed_at: string().nullable(),
4437
4459
  });
4438
- function string(params) {
4439
- return _string(ZodMiniString, params);
4440
- }
4441
- const ZodMiniNumber = /*@__PURE__*/ $constructor("ZodMiniNumber", (inst, def) => {
4442
- $ZodNumber.init(inst, def);
4443
- ZodMiniType.init(inst, def);
4460
+ // Newsletter subscription error extends base error with typed meta
4461
+ const NewsletterSubscriptionErrorSchema = BaseErrorSchema.extend({
4462
+ error_details: record(string(), array(string())).optional(),
4463
+ meta: object({
4464
+ newsletter_internal_name: string(),
4465
+ }),
4444
4466
  });
4445
- function number(params) {
4446
- return _number(ZodMiniNumber, params);
4447
- }
4448
- const ZodMiniBoolean = /*@__PURE__*/ $constructor("ZodMiniBoolean", (inst, def) => {
4449
- $ZodBoolean.init(inst, def);
4450
- ZodMiniType.init(inst, def);
4467
+ // Create subscriptions response
4468
+ const CreateSubscriptionsResponseSchema = object({
4469
+ results: array(NewsletterSubscriptionSchema),
4470
+ errors: array(NewsletterSubscriptionErrorSchema),
4451
4471
  });
4452
- function boolean(params) {
4453
- return _boolean(ZodMiniBoolean, params);
4454
- }
4455
- const ZodMiniNull = /*@__PURE__*/ $constructor("ZodMiniNull", (inst, def) => {
4456
- $ZodNull.init(inst, def);
4457
- ZodMiniType.init(inst, def);
4472
+ // Additional fields for subscription creation - using .partial() for all optional fields
4473
+ const AdditionalFieldsSchema = object({
4474
+ first_name: string().nullable(),
4475
+ last_name: string().nullable(),
4476
+ salutation: SalutationEnum.nullable(),
4477
+ phone_number: string().nullable(),
4478
+ date_of_birth: string().nullable(),
4479
+ company_name: string().nullable(),
4480
+ address_line_1: string().nullable(),
4481
+ address_line_2: string().nullable(),
4482
+ city: string().nullable(),
4483
+ postal_code: string().nullable(),
4484
+ country_code: string().nullable(),
4485
+ preferred_language: string().nullable(),
4486
+ custom_attributes: record(string(), unknown()).nullable(),
4487
+ })
4488
+ .partial();
4489
+ // Create subscriptions payload
4490
+ const CreateSubscriptionsPayloadSchema = object({
4491
+ email: string(),
4492
+ additional_fields: optional(AdditionalFieldsSchema),
4493
+ newsletter_subscriptions: array(object({
4494
+ newsletter_internal_name: string(),
4495
+ preference_identifiers: optional(array(string())),
4496
+ })),
4497
+ redirect_to_after_confirmation: optional(string()),
4458
4498
  });
4459
- function _null(params) {
4460
- return _null$2(ZodMiniNull, params);
4461
- }
4462
- const ZodMiniUnknown = /*@__PURE__*/ $constructor("ZodMiniUnknown", (inst, def) => {
4463
- $ZodUnknown.init(inst, def);
4464
- ZodMiniType.init(inst, def);
4499
+ // Update subscription payload
4500
+ const UpdateSubscriptionPayloadSchema = object({
4501
+ preference_identifiers: array(string()),
4465
4502
  });
4466
- function unknown() {
4467
- return _unknown(ZodMiniUnknown);
4468
- }
4469
- const ZodMiniArray = /*@__PURE__*/ $constructor("ZodMiniArray", (inst, def) => {
4470
- $ZodArray.init(inst, def);
4471
- ZodMiniType.init(inst, def);
4503
+ // Login email payload
4504
+ const LoginEmailPayloadSchema = object({
4505
+ email: string(),
4506
+ redirect_uri: string(),
4472
4507
  });
4473
- function array(element, params) {
4474
- return new ZodMiniArray({
4475
- type: "array",
4476
- element: element,
4477
- ...normalizeParams(params),
4478
- });
4479
- }
4480
- const ZodMiniObject = /*@__PURE__*/ $constructor("ZodMiniObject", (inst, def) => {
4481
- $ZodObject.init(inst, def);
4482
- ZodMiniType.init(inst, def);
4483
- defineLazy(inst, "shape", () => def.shape);
4508
+ // Resend DOI payload
4509
+ const ResendDoiPayloadSchema = object({
4510
+ redirect_to_after_confirmation: string(),
4511
+ })
4512
+ .partial();
4513
+ // Preference schema
4514
+ const PreferenceSchema = object({
4515
+ id: number(),
4516
+ name: string(),
4517
+ description: string().nullable(),
4518
+ plugin_identifier: string().nullable(),
4519
+ position: number(),
4520
+ default: boolean(),
4521
+ hidden: boolean(),
4484
4522
  });
4485
- function object(shape, params) {
4486
- const def = {
4487
- type: "object",
4488
- shape: shape ?? {},
4489
- ...normalizeParams(params),
4490
- };
4491
- return new ZodMiniObject(def);
4492
- }
4493
- const ZodMiniUnion = /*@__PURE__*/ $constructor("ZodMiniUnion", (inst, def) => {
4494
- $ZodUnion.init(inst, def);
4495
- ZodMiniType.init(inst, def);
4523
+ // Preference group schema
4524
+ const PreferenceGroupSchema = object({
4525
+ id: number(),
4526
+ name: string(),
4527
+ position: number(),
4528
+ flat: boolean(),
4529
+ preferences: array(PreferenceSchema),
4496
4530
  });
4497
- function union(options, params) {
4498
- return new ZodMiniUnion({
4499
- type: "union",
4500
- options: options,
4501
- ...normalizeParams(params),
4502
- });
4503
- }
4504
- const ZodMiniRecord = /*@__PURE__*/ $constructor("ZodMiniRecord", (inst, def) => {
4505
- $ZodRecord.init(inst, def);
4506
- ZodMiniType.init(inst, def);
4531
+ // Newsletter schema
4532
+ const NewsletterSchema = object({
4533
+ id: number(),
4534
+ internal_name: string(),
4535
+ default: boolean(),
4536
+ position: number(),
4537
+ opt_in_type: string(),
4538
+ title: string(),
4539
+ description: string().nullable(),
4540
+ created_at: string(),
4541
+ updated_at: string(),
4542
+ preference_groups: array(PreferenceGroupSchema),
4507
4543
  });
4508
- function record(keyType, valueType, params) {
4509
- return new ZodMiniRecord({
4510
- type: "record",
4511
- keyType,
4512
- valueType: valueType,
4513
- ...normalizeParams(params),
4514
- });
4515
- }
4516
- const ZodMiniLiteral = /*@__PURE__*/ $constructor("ZodMiniLiteral", (inst, def) => {
4517
- $ZodLiteral.init(inst, def);
4518
- ZodMiniType.init(inst, def);
4544
+ // Newsletters list response
4545
+ const NewslettersResponseSchema = object({
4546
+ newsletters: array(NewsletterSchema),
4519
4547
  });
4520
- function literal(value, params) {
4521
- return new ZodMiniLiteral({
4522
- type: "literal",
4523
- values: Array.isArray(value) ? value : [value],
4524
- ...normalizeParams(params),
4525
- });
4526
- }
4527
- const ZodMiniOptional = /*@__PURE__*/ $constructor("ZodMiniOptional", (inst, def) => {
4528
- $ZodOptional.init(inst, def);
4529
- ZodMiniType.init(inst, def);
4530
- });
4531
- function optional(innerType) {
4532
- return new ZodMiniOptional({
4533
- type: "optional",
4534
- innerType: innerType,
4535
- });
4536
- }
4537
-
4538
- function getDefaultExportFromCjs (x) {
4539
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
4540
- }
4541
-
4542
- var eventemitter3 = {exports: {}};
4543
-
4544
- var hasRequiredEventemitter3;
4545
-
4546
- function requireEventemitter3 () {
4547
- if (hasRequiredEventemitter3) return eventemitter3.exports;
4548
- hasRequiredEventemitter3 = 1;
4549
- (function (module) {
4550
-
4551
- var has = Object.prototype.hasOwnProperty
4552
- , prefix = '~';
4553
-
4554
- /**
4555
- * Constructor to create a storage for our `EE` objects.
4556
- * An `Events` instance is a plain object whose properties are event names.
4557
- *
4558
- * @constructor
4559
- * @private
4560
- */
4561
- function Events() {}
4562
-
4563
- //
4564
- // We try to not inherit from `Object.prototype`. In some engines creating an
4565
- // instance in this way is faster than calling `Object.create(null)` directly.
4566
- // If `Object.create(null)` is not supported we prefix the event names with a
4567
- // character to make sure that the built-in object properties are not
4568
- // overridden or used as an attack vector.
4569
- //
4570
- if (Object.create) {
4571
- Events.prototype = Object.create(null);
4572
-
4573
- //
4574
- // This hack is needed because the `__proto__` property is still inherited in
4575
- // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
4576
- //
4577
- if (!new Events().__proto__) prefix = false;
4578
- }
4579
-
4580
- /**
4581
- * Representation of a single event listener.
4582
- *
4583
- * @param {Function} fn The listener function.
4584
- * @param {*} context The context to invoke the listener with.
4585
- * @param {Boolean} [once=false] Specify if the listener is a one-time listener.
4586
- * @constructor
4587
- * @private
4588
- */
4589
- function EE(fn, context, once) {
4590
- this.fn = fn;
4591
- this.context = context;
4592
- this.once = once || false;
4593
- }
4594
-
4595
- /**
4596
- * Add a listener for a given event.
4597
- *
4598
- * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
4599
- * @param {(String|Symbol)} event The event name.
4600
- * @param {Function} fn The listener function.
4601
- * @param {*} context The context to invoke the listener with.
4602
- * @param {Boolean} once Specify if the listener is a one-time listener.
4603
- * @returns {EventEmitter}
4604
- * @private
4605
- */
4606
- function addListener(emitter, event, fn, context, once) {
4607
- if (typeof fn !== 'function') {
4608
- throw new TypeError('The listener must be a function');
4609
- }
4610
-
4611
- var listener = new EE(fn, context || emitter, once)
4612
- , evt = prefix ? prefix + event : event;
4613
-
4614
- if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
4615
- else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
4616
- else emitter._events[evt] = [emitter._events[evt], listener];
4617
-
4618
- return emitter;
4619
- }
4620
-
4621
- /**
4622
- * Clear event by name.
4623
- *
4624
- * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
4625
- * @param {(String|Symbol)} evt The Event name.
4626
- * @private
4627
- */
4628
- function clearEvent(emitter, evt) {
4629
- if (--emitter._eventsCount === 0) emitter._events = new Events();
4630
- else delete emitter._events[evt];
4631
- }
4632
-
4633
- /**
4634
- * Minimal `EventEmitter` interface that is molded against the Node.js
4635
- * `EventEmitter` interface.
4636
- *
4637
- * @constructor
4638
- * @public
4639
- */
4640
- function EventEmitter() {
4641
- this._events = new Events();
4642
- this._eventsCount = 0;
4643
- }
4644
-
4645
- /**
4646
- * Return an array listing the events for which the emitter has registered
4647
- * listeners.
4648
- *
4649
- * @returns {Array}
4650
- * @public
4651
- */
4652
- EventEmitter.prototype.eventNames = function eventNames() {
4653
- var names = []
4654
- , events
4655
- , name;
4656
-
4657
- if (this._eventsCount === 0) return names;
4658
-
4659
- for (name in (events = this._events)) {
4660
- if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
4661
- }
4662
-
4663
- if (Object.getOwnPropertySymbols) {
4664
- return names.concat(Object.getOwnPropertySymbols(events));
4665
- }
4666
-
4667
- return names;
4668
- };
4669
-
4670
- /**
4671
- * Return the listeners registered for a given event.
4672
- *
4673
- * @param {(String|Symbol)} event The event name.
4674
- * @returns {Array} The registered listeners.
4675
- * @public
4676
- */
4677
- EventEmitter.prototype.listeners = function listeners(event) {
4678
- var evt = prefix ? prefix + event : event
4679
- , handlers = this._events[evt];
4680
-
4681
- if (!handlers) return [];
4682
- if (handlers.fn) return [handlers.fn];
4683
-
4684
- for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
4685
- ee[i] = handlers[i].fn;
4686
- }
4687
-
4688
- return ee;
4689
- };
4690
-
4691
- /**
4692
- * Return the number of listeners listening to a given event.
4693
- *
4694
- * @param {(String|Symbol)} event The event name.
4695
- * @returns {Number} The number of listeners.
4696
- * @public
4697
- */
4698
- EventEmitter.prototype.listenerCount = function listenerCount(event) {
4699
- var evt = prefix ? prefix + event : event
4700
- , listeners = this._events[evt];
4701
-
4702
- if (!listeners) return 0;
4703
- if (listeners.fn) return 1;
4704
- return listeners.length;
4705
- };
4706
-
4707
- /**
4708
- * Calls each of the listeners registered for a given event.
4709
- *
4710
- * @param {(String|Symbol)} event The event name.
4711
- * @returns {Boolean} `true` if the event had listeners, else `false`.
4712
- * @public
4713
- */
4714
- EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
4715
- var evt = prefix ? prefix + event : event;
4716
-
4717
- if (!this._events[evt]) return false;
4718
-
4719
- var listeners = this._events[evt]
4720
- , len = arguments.length
4721
- , args
4722
- , i;
4723
-
4724
- if (listeners.fn) {
4725
- if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
4726
-
4727
- switch (len) {
4728
- case 1: return listeners.fn.call(listeners.context), true;
4729
- case 2: return listeners.fn.call(listeners.context, a1), true;
4730
- case 3: return listeners.fn.call(listeners.context, a1, a2), true;
4731
- case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
4732
- case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
4733
- case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
4734
- }
4735
-
4736
- for (i = 1, args = new Array(len -1); i < len; i++) {
4737
- args[i - 1] = arguments[i];
4738
- }
4739
-
4740
- listeners.fn.apply(listeners.context, args);
4741
- } else {
4742
- var length = listeners.length
4743
- , j;
4744
-
4745
- for (i = 0; i < length; i++) {
4746
- if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
4747
-
4748
- switch (len) {
4749
- case 1: listeners[i].fn.call(listeners[i].context); break;
4750
- case 2: listeners[i].fn.call(listeners[i].context, a1); break;
4751
- case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
4752
- case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
4753
- default:
4754
- if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
4755
- args[j - 1] = arguments[j];
4756
- }
4757
-
4758
- listeners[i].fn.apply(listeners[i].context, args);
4759
- }
4760
- }
4761
- }
4762
-
4763
- return true;
4764
- };
4765
-
4766
- /**
4767
- * Add a listener for a given event.
4768
- *
4769
- * @param {(String|Symbol)} event The event name.
4770
- * @param {Function} fn The listener function.
4771
- * @param {*} [context=this] The context to invoke the listener with.
4772
- * @returns {EventEmitter} `this`.
4773
- * @public
4774
- */
4775
- EventEmitter.prototype.on = function on(event, fn, context) {
4776
- return addListener(this, event, fn, context, false);
4777
- };
4778
-
4779
- /**
4780
- * Add a one-time listener for a given event.
4781
- *
4782
- * @param {(String|Symbol)} event The event name.
4783
- * @param {Function} fn The listener function.
4784
- * @param {*} [context=this] The context to invoke the listener with.
4785
- * @returns {EventEmitter} `this`.
4786
- * @public
4787
- */
4788
- EventEmitter.prototype.once = function once(event, fn, context) {
4789
- return addListener(this, event, fn, context, true);
4790
- };
4791
-
4792
- /**
4793
- * Remove the listeners of a given event.
4794
- *
4795
- * @param {(String|Symbol)} event The event name.
4796
- * @param {Function} fn Only remove the listeners that match this function.
4797
- * @param {*} context Only remove the listeners that have this context.
4798
- * @param {Boolean} once Only remove one-time listeners.
4799
- * @returns {EventEmitter} `this`.
4800
- * @public
4801
- */
4802
- EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
4803
- var evt = prefix ? prefix + event : event;
4804
-
4805
- if (!this._events[evt]) return this;
4806
- if (!fn) {
4807
- clearEvent(this, evt);
4808
- return this;
4809
- }
4810
-
4811
- var listeners = this._events[evt];
4812
-
4813
- if (listeners.fn) {
4814
- if (
4815
- listeners.fn === fn &&
4816
- (!once || listeners.once) &&
4817
- (!context || listeners.context === context)
4818
- ) {
4819
- clearEvent(this, evt);
4820
- }
4821
- } else {
4822
- for (var i = 0, events = [], length = listeners.length; i < length; i++) {
4823
- if (
4824
- listeners[i].fn !== fn ||
4825
- (once && !listeners[i].once) ||
4826
- (context && listeners[i].context !== context)
4827
- ) {
4828
- events.push(listeners[i]);
4829
- }
4830
- }
4831
-
4832
- //
4833
- // Reset the array, or remove it completely if we have no more listeners.
4834
- //
4835
- if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
4836
- else clearEvent(this, evt);
4837
- }
4838
-
4839
- return this;
4840
- };
4841
-
4842
- /**
4843
- * Remove all listeners, or those of the specified event.
4844
- *
4845
- * @param {(String|Symbol)} [event] The event name.
4846
- * @returns {EventEmitter} `this`.
4847
- * @public
4848
- */
4849
- EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
4850
- var evt;
4851
-
4852
- if (event) {
4853
- evt = prefix ? prefix + event : event;
4854
- if (this._events[evt]) clearEvent(this, evt);
4855
- } else {
4856
- this._events = new Events();
4857
- this._eventsCount = 0;
4858
- }
4859
-
4860
- return this;
4861
- };
4862
-
4863
- //
4864
- // Alias methods names because people roll like that.
4865
- //
4866
- EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
4867
- EventEmitter.prototype.addListener = EventEmitter.prototype.on;
4868
-
4869
- //
4870
- // Expose the prefix.
4871
- //
4872
- EventEmitter.prefixed = prefix;
4873
-
4874
- //
4875
- // Allow `EventEmitter` to be imported as module namespace.
4876
- //
4877
- EventEmitter.EventEmitter = EventEmitter;
4878
-
4879
- //
4880
- // Expose the module.
4881
- //
4882
- {
4883
- module.exports = EventEmitter;
4884
- }
4885
- } (eventemitter3));
4886
- return eventemitter3.exports;
4887
- }
4888
-
4889
- var eventemitter3Exports = requireEventemitter3();
4890
- var EventEmitter = /*@__PURE__*/getDefaultExportFromCjs(eventemitter3Exports);
4548
+ // Delete subscription response
4549
+ const DeleteSubscriptionResponseSchema = object({
4550
+ new_preference_token: string(),
4551
+ })
4552
+ .nullable();
4553
+ // Generic newsletter error response (extends base error)
4554
+ const NewsletterErrorResponseSchema = BaseErrorSchema;
4891
4555
 
4892
- const NewsletterSubscriptionSchema = object({
4893
- id: number(),
4894
- email: string(),
4895
- newsletter_internal_name: string(),
4896
- preference_identifiers: array(string()),
4897
- preference_token: string(),
4898
- confirmed_at: union([string(), _null()]),
4899
- });
4900
- const NewsletterSubscriptionErrorSchema = object({
4901
- error_identifier: string(),
4902
- error_details: optional(record(string(), array(string()))),
4903
- meta: object({
4904
- newsletter_internal_name: string(),
4905
- }),
4906
- });
4907
- const CreateSubscriptionsResponseSchema = object({
4908
- results: array(NewsletterSubscriptionSchema),
4909
- errors: array(NewsletterSubscriptionErrorSchema),
4910
- });
4911
- const AdditionalFieldsSchema = object({
4912
- first_name: optional(union([string(), _null()])),
4913
- last_name: optional(union([string(), _null()])),
4914
- salutation: optional(union([literal("mr"), literal("mrs"), literal("mx"), _null()])),
4915
- phone_number: optional(union([string(), _null()])),
4916
- date_of_birth: optional(union([string(), _null()])),
4917
- company_name: optional(union([string(), _null()])),
4918
- address_line_1: optional(union([string(), _null()])),
4919
- address_line_2: optional(union([string(), _null()])),
4920
- city: optional(union([string(), _null()])),
4921
- postal_code: optional(union([string(), _null()])),
4922
- country_code: optional(union([string(), _null()])),
4923
- preferred_language: optional(union([string(), _null()])),
4924
- custom_attributes: optional(union([record(string(), unknown()), _null()])),
4925
- });
4926
- const CreateSubscriptionsPayloadSchema = object({
4927
- email: string(),
4928
- additional_fields: optional(AdditionalFieldsSchema),
4929
- newsletter_subscriptions: array(object({
4930
- newsletter_internal_name: string(),
4931
- preference_identifiers: optional(array(string())),
4932
- })),
4933
- redirect_to_after_confirmation: optional(string()),
4934
- });
4935
- const UpdateSubscriptionPayloadSchema = object({
4936
- preference_identifiers: array(string()),
4937
- });
4938
- const LoginEmailPayloadSchema = object({
4939
- email: string(),
4940
- redirect_uri: string(),
4941
- });
4942
- const ResendDoiPayloadSchema = object({
4943
- redirect_to_after_confirmation: optional(string()),
4944
- });
4945
- const PreferenceSchema = object({
4946
- id: number(),
4947
- name: string(),
4948
- description: union([string(), _null()]),
4949
- plugin_identifier: union([string(), _null()]),
4950
- position: number(),
4951
- default: boolean(),
4952
- hidden: boolean(),
4953
- });
4954
- const PreferenceGroupSchema = object({
4955
- id: number(),
4956
- name: string(),
4957
- position: number(),
4958
- flat: boolean(),
4959
- preferences: array(PreferenceSchema),
4960
- });
4961
- const NewsletterSchema = object({
4962
- id: number(),
4963
- internal_name: string(),
4964
- default: boolean(),
4965
- position: number(),
4966
- opt_in_type: string(),
4967
- title: string(),
4968
- description: union([string(), _null()]),
4969
- created_at: string(),
4970
- updated_at: string(),
4971
- preference_groups: array(PreferenceGroupSchema),
4972
- });
4973
- object({
4974
- newsletters: array(NewsletterSchema),
4975
- });
4976
- class NewsletterService extends EventEmitter {
4977
- client;
4978
- logger = index.createLogger("NewsletterService");
4979
- constructor(client) {
4980
- super();
4981
- this.client = client;
4556
+ class NewsletterService extends BaseService {
4557
+ constructor(client, deps) {
4558
+ super(client, "NewsletterService", deps);
4982
4559
  }
4983
- buildAuthHeaders(auth) {
4984
- if (!auth)
4985
- return undefined;
4986
- const headers = {};
4987
- if (auth.idToken) {
4988
- headers["X-ID-Token"] = auth.idToken;
4989
- }
4990
- if (auth.preferenceToken) {
4991
- headers["X-Preference-Token"] = auth.preferenceToken;
4992
- }
4993
- return Object.keys(headers).length > 0 ? headers : undefined;
4560
+ async buildNewsletterAuthHeaders(options) {
4561
+ const idToken = await this.getIdToken();
4562
+ return this.buildAuthHeaders({
4563
+ "X-ID-Token": idToken ?? undefined,
4564
+ "X-Preference-Token": options?.preferenceToken,
4565
+ });
4994
4566
  }
4995
- async createSubscriptions(payload, auth) {
4567
+ /**
4568
+ * Create newsletter subscriptions for a user
4569
+ */
4570
+ async create(args) {
4571
+ const { payload, options } = args;
4996
4572
  CreateSubscriptionsPayloadSchema.parse(payload);
4997
- const response = await this.client.post("/api/sdk/v1/newsletters/newsletter_subscription", payload, this.buildAuthHeaders(auth));
4998
- switch (response.status) {
4999
- case 401:
5000
- this.emit("unauthorized", response);
5001
- return ["unauthorized", response];
5002
- case 429:
5003
- this.logger.warn("Rate limit exceeded");
5004
- this.emit("rate_limit_exceeded", response);
5005
- return ["rate_limit_exceeded", response];
5006
- case 500:
5007
- index.captureException(response);
5008
- return ["server_error", response];
5009
- case 0:
5010
- return ["network_error", response];
5011
- default:
5012
- if (response.data) {
5013
- try {
5014
- const validatedData = CreateSubscriptionsResponseSchema.parse(response.data);
5015
- if (validatedData.errors.length > 0) {
5016
- this.emit("newsletter_error", response);
5017
- return ["newsletter_error", response];
5018
- }
5019
- return [null, response];
5020
- }
5021
- catch (_validationError) {
5022
- return ["schema_validation_error", response];
5023
- }
4573
+ const headers = await this.buildNewsletterAuthHeaders(options);
4574
+ const response = await this.client.post("/api/sdk/v1/newsletters/newsletter_subscription", payload, headers);
4575
+ return this.handleResponse(response, () => {
4576
+ if (!response.success) {
4577
+ const parsed = NewsletterErrorResponseSchema.safeParse(response.data);
4578
+ const error = parsed.success ? parsed.data : { error_identifier: "unknown_error" };
4579
+ switch (response.status) {
4580
+ case 401:
4581
+ return ["unauthorized", error];
4582
+ case 429:
4583
+ this.logger.warn("Rate limit exceeded");
4584
+ return ["rate_limit_exceeded", error];
4585
+ case 500:
4586
+ this.errorReporter.captureException(response);
4587
+ return ["server_error", error];
4588
+ default:
4589
+ return ["server_error", error];
5024
4590
  }
5025
- return ["error", response];
5026
- }
4591
+ }
4592
+ const data = CreateSubscriptionsResponseSchema.parse(response.data);
4593
+ if (data.errors.length > 0) {
4594
+ return ["newsletter_error", data];
4595
+ }
4596
+ return [null, data];
4597
+ });
5027
4598
  }
5028
- async listSubscriptions(auth) {
5029
- return this.client.get("/api/sdk/v1/newsletters/newsletter_subscription", this.buildAuthHeaders(auth));
4599
+ /**
4600
+ * List all subscriptions for the authenticated user
4601
+ */
4602
+ async list(args) {
4603
+ const headers = await this.buildNewsletterAuthHeaders(args?.options);
4604
+ const response = await this.client.get("/api/sdk/v1/newsletters/newsletter_subscription", headers);
4605
+ return this.handleResponse(response, () => {
4606
+ if (!response.success) {
4607
+ const parsed = NewsletterErrorResponseSchema.safeParse(response.data);
4608
+ const error = parsed.success ? parsed.data : { error_identifier: "unknown_error" };
4609
+ if (response.status === 401) {
4610
+ return ["unauthorized", error];
4611
+ }
4612
+ return ["server_error", error];
4613
+ }
4614
+ const data = array(NewsletterSubscriptionSchema).parse(response.data);
4615
+ return [null, data];
4616
+ });
5030
4617
  }
5031
- async getSubscription(internalName, auth) {
5032
- return this.client.get(`/api/sdk/v1/newsletters/${internalName}/newsletter_subscription`, this.buildAuthHeaders(auth));
4618
+ /**
4619
+ * Get a specific subscription by newsletter internal name
4620
+ */
4621
+ async get(args) {
4622
+ const { internalName, options } = args;
4623
+ const headers = await this.buildNewsletterAuthHeaders(options);
4624
+ const response = await this.client.get(`/api/sdk/v1/newsletters/${internalName}/newsletter_subscription`, headers);
4625
+ return this.handleResponse(response, () => {
4626
+ if (!response.success) {
4627
+ const parsed = NewsletterErrorResponseSchema.safeParse(response.data);
4628
+ const error = parsed.success ? parsed.data : { error_identifier: "unknown_error" };
4629
+ if (response.status === 401) {
4630
+ return ["unauthorized", error];
4631
+ }
4632
+ if (response.status === 404) {
4633
+ return ["not_found", error];
4634
+ }
4635
+ return ["server_error", error];
4636
+ }
4637
+ const data = NewsletterSubscriptionSchema.parse(response.data);
4638
+ return [null, data];
4639
+ });
5033
4640
  }
5034
- async updateSubscription(internalName, payload, auth) {
4641
+ /**
4642
+ * Update a subscription's preferences
4643
+ */
4644
+ async update(args) {
4645
+ const { internalName, payload, options } = args;
5035
4646
  UpdateSubscriptionPayloadSchema.parse(payload);
5036
- return this.client.patch(`/api/sdk/v1/newsletters/${internalName}/newsletter_subscription`, payload, this.buildAuthHeaders(auth));
4647
+ const headers = await this.buildNewsletterAuthHeaders(options);
4648
+ const response = await this.client.patch(`/api/sdk/v1/newsletters/${internalName}/newsletter_subscription`, payload, headers);
4649
+ return this.handleResponse(response, () => {
4650
+ if (!response.success) {
4651
+ const parsed = NewsletterErrorResponseSchema.safeParse(response.data);
4652
+ const error = parsed.success ? parsed.data : { error_identifier: "unknown_error" };
4653
+ if (response.status === 401) {
4654
+ return ["unauthorized", error];
4655
+ }
4656
+ if (response.status === 404) {
4657
+ return ["not_found", error];
4658
+ }
4659
+ return ["server_error", error];
4660
+ }
4661
+ const data = NewsletterSubscriptionSchema.parse(response.data);
4662
+ return [null, data];
4663
+ });
5037
4664
  }
5038
- async deleteSubscription(internalName, auth) {
5039
- return this.client.delete(`/api/sdk/v1/newsletters/${internalName}/newsletter_subscription`, this.buildAuthHeaders(auth));
4665
+ /**
4666
+ * Delete a subscription
4667
+ */
4668
+ async delete(args) {
4669
+ const { internalName, options } = args;
4670
+ const headers = await this.buildNewsletterAuthHeaders(options);
4671
+ const response = await this.client.delete(`/api/sdk/v1/newsletters/${internalName}/newsletter_subscription`, headers);
4672
+ return this.handleResponse(response, () => {
4673
+ if (!response.success) {
4674
+ const parsed = NewsletterErrorResponseSchema.safeParse(response.data);
4675
+ const error = parsed.success ? parsed.data : { error_identifier: "unknown_error" };
4676
+ if (response.status === 401) {
4677
+ return ["unauthorized", error];
4678
+ }
4679
+ if (response.status === 404) {
4680
+ return ["not_found", error];
4681
+ }
4682
+ return ["server_error", error];
4683
+ }
4684
+ const data = DeleteSubscriptionResponseSchema.parse(response.data);
4685
+ return [null, data];
4686
+ });
5040
4687
  }
5041
- async resendDoi(internalName, payload, auth) {
4688
+ /**
4689
+ * Resend double opt-in confirmation email
4690
+ */
4691
+ async resendDoi(args) {
4692
+ const { internalName, payload, options } = args;
5042
4693
  ResendDoiPayloadSchema.parse(payload);
5043
- return this.client.post(`/api/sdk/v1/newsletters/${internalName}/newsletter_subscription/resend_doi`, payload, this.buildAuthHeaders(auth));
4694
+ const headers = await this.buildNewsletterAuthHeaders(options);
4695
+ const response = await this.client.post(`/api/sdk/v1/newsletters/${internalName}/newsletter_subscription/resend_doi`, payload, headers);
4696
+ return this.handleResponse(response, () => {
4697
+ if (!response.success) {
4698
+ const parsed = NewsletterErrorResponseSchema.safeParse(response.data);
4699
+ const error = parsed.success ? parsed.data : { error_identifier: "unknown_error" };
4700
+ if (response.status === 401) {
4701
+ return ["unauthorized", error];
4702
+ }
4703
+ if (response.status === 404) {
4704
+ return ["not_found", error];
4705
+ }
4706
+ if (error.error_identifier === "already_confirmed") {
4707
+ return ["already_confirmed", error];
4708
+ }
4709
+ return ["server_error", error];
4710
+ }
4711
+ return [null, null];
4712
+ });
5044
4713
  }
5045
- async sendLoginEmail(payload) {
4714
+ /**
4715
+ * Send a login email for newsletter management
4716
+ */
4717
+ async sendLoginEmail(args) {
4718
+ const { payload } = args;
5046
4719
  LoginEmailPayloadSchema.parse(payload);
5047
- return this.client.post("/api/sdk/v1/newsletters/newsletter_subscription/login_email", payload);
5048
- }
5049
- async listNewsletters() {
5050
- return this.client.get("/api/sdk/v1/newsletters");
5051
- }
5052
- async getNewsletter(internalName) {
5053
- return this.client.get(`/api/sdk/v1/newsletters/${internalName}`);
5054
- }
5055
- onError(callback, errorIdentifier) {
5056
- this.on("newsletter_error", (response) => {
5057
- if (!response.data?.errors) {
5058
- return;
4720
+ const response = await this.client.post("/api/sdk/v1/newsletters/newsletter_subscription/login_email", payload);
4721
+ return this.handleResponse(response, () => {
4722
+ if (!response.success) {
4723
+ const parsed = NewsletterErrorResponseSchema.safeParse(response.data);
4724
+ const error = parsed.success ? parsed.data : { error_identifier: "unknown_error" };
4725
+ if (response.status === 429) {
4726
+ return ["rate_limit_exceeded", error];
4727
+ }
4728
+ return ["server_error", error];
5059
4729
  }
5060
- const errors = errorIdentifier
5061
- ? response.data.errors.filter((error) => error.error_identifier === errorIdentifier)
5062
- : response.data.errors;
5063
- if (errors.length > 0) {
5064
- callback(errors);
4730
+ return [null, null];
4731
+ });
4732
+ }
4733
+ /**
4734
+ * List all available newsletters
4735
+ */
4736
+ async listAll() {
4737
+ const response = await this.client.get("/api/sdk/v1/newsletters");
4738
+ return this.handleResponse(response, () => {
4739
+ if (!response.success) {
4740
+ return ["server_error", null];
5065
4741
  }
4742
+ const data = NewslettersResponseSchema.parse(response.data);
4743
+ return [null, data];
5066
4744
  });
5067
4745
  }
5068
- onRateLimitError(callback) {
5069
- this.on("rate_limit_exceeded", (response) => {
5070
- if (response.status === 429) {
5071
- callback();
4746
+ /**
4747
+ * Get a newsletter by its internal name
4748
+ */
4749
+ async getByName(args) {
4750
+ const { internalName } = args;
4751
+ const response = await this.client.get(`/api/sdk/v1/newsletters/${internalName}`);
4752
+ return this.handleResponse(response, () => {
4753
+ if (!response.success) {
4754
+ const parsed = NewsletterErrorResponseSchema.safeParse(response.data);
4755
+ const error = parsed.success ? parsed.data : { error_identifier: "unknown_error" };
4756
+ if (response.status === 404) {
4757
+ return ["not_found", error];
4758
+ }
4759
+ return ["server_error", error];
5072
4760
  }
4761
+ const data = NewsletterSchema.parse(response.data);
4762
+ return [null, data];
5073
4763
  });
5074
4764
  }
5075
4765
  }
5076
4766
 
5077
- const SchemaValidationErrorSchema = object$1({
5078
- error_identifier: string$1(), // unprocessable entity etc. TODO we can define enum later
5079
- errors: array$1(string$1()),
5080
- });
5081
- const PaginationMetaSchema = object$1({
5082
- count: number$1(),
5083
- page: number$1(),
5084
- limit: number$1(),
5085
- last: number$1(),
5086
- prev: number$1().nullable(),
5087
- next: number$1().nullable(),
5088
- });
5089
- const PaginationParamsSchema = object$1({
5090
- page: number$1().int().min(1),
5091
- limit: number$1().int().min(0).max(250),
5092
- });
5093
-
5094
- const TicketableListParamsBaseSchema = object$1({
5095
- service_id: number$1().nullable(),
5096
- state: string$1(),
5097
- payment_state: string$1(),
5098
- order_by: _enum(["starts_at", "ends_at", "reference", "created_at"]),
5099
- order_direction: _enum(["asc", "desc"]),
5100
- })
5101
- .merge(PaginationParamsSchema);
5102
-
5103
- function getWithSchema(client, returnSchema, urlBuilder, paramSchema) {
5104
- const fn = async (args, params) => {
5105
- // Build URL
5106
- const baseUrl = urlBuilder(args);
5107
- // Validate and parse params with Zod if provided
5108
- let queryString = "";
5109
- if (paramSchema && params) {
5110
- const validatedParams = paramSchema.parse(params);
5111
- queryString = `?${new URLSearchParams(validatedParams).toString()}`;
5112
- }
5113
- const fullUrl = `${baseUrl}${queryString}`;
5114
- const response = await client.get(fullUrl);
5115
- if (!response.success || !response.data) {
5116
- return response;
5117
- }
5118
- const parsed = returnSchema.safeParse(response.data);
5119
- if (!parsed.success) {
5120
- index.captureException(parsed.error);
5121
- return {
5122
- ...response,
5123
- success: false,
5124
- error: "Invalid response format",
5125
- data: undefined,
5126
- };
5127
- }
5128
- return {
5129
- ...response,
5130
- data: parsed.data,
5131
- };
5132
- };
5133
- // biome-ignore lint/suspicious/noExplicitAny: fn can literally be any function
5134
- return fn;
5135
- }
5136
-
5137
4767
  // Date transformer for ISO8601 strings
5138
- const dateTransformer$1 = date();
5139
- const nullableDateTransformer$1 = date().nullable();
5140
- // Ticket types based on TicketSerializer
5141
- const TicketSchema = object$1({
4768
+ const dateTransformer = date();
4769
+ const nullableDateTransformer = date().nullable();
4770
+ // Ticket schema based on TicketSerializer
4771
+ const TicketSchema = object({
5142
4772
  id: uuid(), // unidy_id
5143
- title: string$1(),
5144
- text: string$1().nullable(),
5145
- reference: string$1(),
5146
- metadata: record$1(string$1(), unknown$1()).nullable(),
5147
- wallet_export: record$1(string$1(), unknown$1()).nullable(),
5148
- state: string$1(),
5149
- payment_state: string$1().nullable(),
5150
- button_cta_url: string$1().nullable(),
5151
- info_banner: string$1().nullable(),
5152
- seating: string$1().nullable(),
5153
- venue: string$1().nullable(),
5154
- currency: string$1().nullable(),
5155
- starts_at: dateTransformer$1, // ISO8601(3) -> Date
5156
- ends_at: nullableDateTransformer$1, // ISO8601(3) -> Date | null
5157
- created_at: dateTransformer$1, // ISO8601(3) -> Date
5158
- updated_at: dateTransformer$1, // ISO8601(3) -> Date
5159
- price: number$1(), // decimal(8, 2) -> float
4773
+ title: string(),
4774
+ text: string().nullable(),
4775
+ reference: string(),
4776
+ metadata: record(string(), unknown()).nullable(),
4777
+ wallet_export: record(string(), unknown()).nullable(),
4778
+ state: string(),
4779
+ payment_state: string().nullable(),
4780
+ button_cta_url: string().nullable(),
4781
+ info_banner: string().nullable(),
4782
+ seating: string().nullable(),
4783
+ venue: string().nullable(),
4784
+ currency: string().nullable(),
4785
+ starts_at: dateTransformer, // ISO8601(3) -> Date
4786
+ ends_at: nullableDateTransformer, // ISO8601(3) -> Date | null
4787
+ created_at: dateTransformer, // ISO8601(3) -> Date
4788
+ updated_at: dateTransformer, // ISO8601(3) -> Date
4789
+ price: number(), // decimal(8, 2) -> float
5160
4790
  user_id: uuid(),
5161
4791
  ticket_category_id: uuid(),
5162
4792
  });
5163
- // List response
5164
- const TicketsListResponseSchema = object$1({
4793
+ // Tickets list response schema
4794
+ const TicketsListResponseSchema = object({
5165
4795
  meta: PaginationMetaSchema,
5166
- results: array$1(TicketSchema),
4796
+ results: array(TicketSchema),
5167
4797
  });
5168
- // Query params schema with validations
5169
- const TicketsListParamsSchema = TicketableListParamsBaseSchema.extend({ ticket_category_id: string$1().uuid() }).partial();
5170
- class TicketsService {
5171
- client;
5172
- list;
5173
- get;
5174
- constructor(client) {
5175
- this.client = client;
5176
- this.list = getWithSchema(this.client, TicketsListResponseSchema, (_args) => "/api/sdk/v1/tickets", TicketsListParamsSchema);
5177
- this.get = getWithSchema(this.client, TicketSchema, (args) => `/api/sdk/v1/tickets/${args.id}`);
5178
- }
5179
- }
5180
-
5181
- // Date transformer for ISO8601 strings
5182
- const dateTransformer = date();
5183
- const nullableDateTransformer = date().nullable();
5184
- // Subscription types based on SubscriptionSerializer
5185
- const SubscriptionSchema = object$1({
4798
+ // Subscription schema based on SubscriptionSerializer
4799
+ const SubscriptionSchema = object({
5186
4800
  id: uuid(), // unidy_id
5187
- title: string$1(),
5188
- text: string$1(),
5189
- payment_frequency: string$1().nullable(),
5190
- metadata: record$1(string$1(), unknown$1()).nullable(),
5191
- wallet_export: record$1(string$1(), unknown$1()).nullable(),
5192
- state: string$1(),
5193
- reference: string$1(),
5194
- payment_state: string$1().nullable(),
5195
- currency: string$1().nullable(),
5196
- button_cta_url: string$1().nullable(),
4801
+ title: string(),
4802
+ text: string(),
4803
+ payment_frequency: string().nullable(),
4804
+ metadata: record(string(), unknown()).nullable(),
4805
+ wallet_export: record(string(), unknown()).nullable(),
4806
+ state: string(),
4807
+ reference: string(),
4808
+ payment_state: string().nullable(),
4809
+ currency: string().nullable(),
4810
+ button_cta_url: string().nullable(),
5197
4811
  created_at: dateTransformer, // ISO8601(3) -> Date
5198
4812
  updated_at: dateTransformer, // ISO8601(3) -> Date
5199
4813
  starts_at: nullableDateTransformer, // ISO8601(3) -> Date | null
5200
4814
  ends_at: nullableDateTransformer, // ISO8601(3) -> Date | null
5201
4815
  next_payment_at: nullableDateTransformer, // ISO8601(3) -> Date | null
5202
- price: number$1(), // decimal(8, 2) -> float
4816
+ price: number(), // decimal(8, 2) -> float
5203
4817
  user_id: uuid(),
5204
4818
  subscription_category_id: uuid(),
5205
4819
  });
5206
- // List response
5207
- const SubscriptionsListResponseSchema = object$1({
4820
+ // Subscriptions list response schema
4821
+ const SubscriptionsListResponseSchema = object({
5208
4822
  meta: PaginationMetaSchema,
5209
- results: array$1(SubscriptionSchema),
4823
+ results: array(SubscriptionSchema),
5210
4824
  });
5211
- // Query params schema with validations
5212
- const SubscriptionsListParamsSchema = TicketableListParamsBaseSchema.extend({ subscription_category_id: string$1().uuid() }).partial();
5213
- class SubscriptionsService {
4825
+
4826
+ /**
4827
+ * Base service for ticketable resources (tickets and subscriptions).
4828
+ * Handles common query parameter building and response parsing.
4829
+ */
4830
+ class TicketableService extends BaseService {
4831
+ /**
4832
+ * Builds query params from args, mapping camelCase to snake_case.
4833
+ * Returns undefined values filtered out.
4834
+ */
4835
+ buildListParams(args = {}, categoryIdKey, categoryIdValue) {
4836
+ return {
4837
+ page: args.page,
4838
+ limit: args.perPage,
4839
+ state: args.state,
4840
+ payment_state: args.paymentState,
4841
+ order_by: args.orderBy,
4842
+ order_direction: args.orderDirection,
4843
+ service_id: args.serviceId,
4844
+ [categoryIdKey]: categoryIdValue,
4845
+ };
4846
+ }
4847
+ /**
4848
+ * Converts params to query string, filtering undefined/null and converting to strings.
4849
+ */
4850
+ toQueryString(params) {
4851
+ const filtered = Object.entries(params)
4852
+ .filter(([_, v]) => v !== undefined && v !== null)
4853
+ .map(([k, v]) => [k, String(v)]);
4854
+ if (filtered.length === 0)
4855
+ return "";
4856
+ return `?${new URLSearchParams(Object.fromEntries(filtered)).toString()}`;
4857
+ }
4858
+ /**
4859
+ * Generic list handler with schema validation.
4860
+ */
4861
+ async handleList(endpoint, queryString, schema, resourceName) {
4862
+ const response = await this.client.get(`${endpoint}${queryString}`);
4863
+ return this.handleResponse(response, () => {
4864
+ if (!response.success) {
4865
+ this.logger.error(`Failed to fetch ${resourceName}`, response);
4866
+ return ["server_error", null];
4867
+ }
4868
+ const parsed = schema.safeParse(response.data);
4869
+ if (!parsed.success) {
4870
+ this.logger.error("Invalid response format", parsed.error);
4871
+ return ["invalid_response", null];
4872
+ }
4873
+ return [null, parsed.data];
4874
+ });
4875
+ }
4876
+ /**
4877
+ * Generic get handler with schema validation.
4878
+ */
4879
+ async handleGet(endpoint, schema, resourceName) {
4880
+ const response = await this.client.get(endpoint);
4881
+ return this.handleResponse(response, () => {
4882
+ if (!response.success) {
4883
+ if (response.status === 404) {
4884
+ return ["not_found", null];
4885
+ }
4886
+ this.logger.error(`Failed to fetch ${resourceName}`, response);
4887
+ return ["server_error", null];
4888
+ }
4889
+ const parsed = schema.safeParse(response.data);
4890
+ if (!parsed.success) {
4891
+ this.logger.error("Invalid response format", parsed.error);
4892
+ return ["invalid_response", null];
4893
+ }
4894
+ return [null, parsed.data];
4895
+ });
4896
+ }
4897
+ }
4898
+
4899
+ class TicketsService extends TicketableService {
4900
+ constructor(client, deps) {
4901
+ super(client, "TicketsService", deps);
4902
+ }
4903
+ async list(args = {}) {
4904
+ const params = this.buildListParams(args, "ticket_category_id", args.ticketCategoryId);
4905
+ const queryString = this.toQueryString(params);
4906
+ return this.handleList("/api/sdk/v1/tickets", queryString, TicketsListResponseSchema, "tickets");
4907
+ }
4908
+ async get(args) {
4909
+ return this.handleGet(`/api/sdk/v1/tickets/${args.id}`, TicketSchema, "ticket");
4910
+ }
4911
+ }
4912
+
4913
+ class SubscriptionsService extends TicketableService {
4914
+ constructor(client, deps) {
4915
+ super(client, "SubscriptionsService", deps);
4916
+ }
4917
+ async list(args = {}) {
4918
+ const params = this.buildListParams(args, "subscription_category_id", args.subscriptionCategoryId);
4919
+ const queryString = this.toQueryString(params);
4920
+ return this.handleList("/api/sdk/v1/subscriptions", queryString, SubscriptionsListResponseSchema, "subscriptions");
4921
+ }
4922
+ async get(args) {
4923
+ return this.handleGet(`/api/sdk/v1/subscriptions/${args.id}`, SubscriptionSchema, "subscription");
4924
+ }
4925
+ }
4926
+
4927
+ class InvalidTokenError extends Error {
4928
+ }
4929
+ InvalidTokenError.prototype.name = "InvalidTokenError";
4930
+ function b64DecodeUnicode(str) {
4931
+ return decodeURIComponent(atob(str).replace(/(.)/g, (m, p) => {
4932
+ let code = p.charCodeAt(0).toString(16).toUpperCase();
4933
+ if (code.length < 2) {
4934
+ code = "0" + code;
4935
+ }
4936
+ return "%" + code;
4937
+ }));
4938
+ }
4939
+ function base64UrlDecode(str) {
4940
+ let output = str.replace(/-/g, "+").replace(/_/g, "/");
4941
+ switch (output.length % 4) {
4942
+ case 0:
4943
+ break;
4944
+ case 2:
4945
+ output += "==";
4946
+ break;
4947
+ case 3:
4948
+ output += "=";
4949
+ break;
4950
+ default:
4951
+ throw new Error("base64 string is not of the correct length");
4952
+ }
4953
+ try {
4954
+ return b64DecodeUnicode(output);
4955
+ }
4956
+ catch (err) {
4957
+ return atob(output);
4958
+ }
4959
+ }
4960
+ function jwtDecode(token, options) {
4961
+ if (typeof token !== "string") {
4962
+ throw new InvalidTokenError("Invalid token specified: must be a string");
4963
+ }
4964
+ options || (options = {});
4965
+ const pos = options.header === true ? 0 : 1;
4966
+ const part = token.split(".")[pos];
4967
+ if (typeof part !== "string") {
4968
+ throw new InvalidTokenError(`Invalid token specified: missing part #${pos + 1}`);
4969
+ }
4970
+ let decoded;
4971
+ try {
4972
+ decoded = base64UrlDecode(part);
4973
+ }
4974
+ catch (e) {
4975
+ throw new InvalidTokenError(`Invalid token specified: invalid base64 for part #${pos + 1} (${e.message})`);
4976
+ }
4977
+ try {
4978
+ return JSON.parse(decoded);
4979
+ }
4980
+ catch (e) {
4981
+ throw new InvalidTokenError(`Invalid token specified: invalid json for part #${pos + 1} (${e.message})`);
4982
+ }
4983
+ }
4984
+
4985
+ const logger = index.createLogger("PasskeyAuth");
4986
+ const PASSKEY_ERRORS = {
4987
+ NotSupportedError: "passkey_not_supported",
4988
+ NotAllowedError: "passkey_cancelled",
4989
+ SecurityError: "passkey_security_error",
4990
+ InvalidStateError: "passkey_invalid_state",
4991
+ };
4992
+ function decodeBase64Url(base64url) {
4993
+ const base64 = base64url.replace(/-/g, "+").replace(/_/g, "/");
4994
+ const padded = base64 + "=".repeat((4 - (base64.length % 4)) % 4);
4995
+ return Uint8Array.from(atob(padded), (c) => c.charCodeAt(0));
4996
+ }
4997
+ function buildPublicKeyOptions(options) {
4998
+ return {
4999
+ challenge: Uint8Array.from(atob(options.challenge), (c) => c.charCodeAt(0)),
5000
+ timeout: options.timeout || 60000,
5001
+ rpId: options.rpId,
5002
+ userVerification: options.userVerification || "required",
5003
+ allowCredentials: options.allowCredentials?.map((cred) => ({
5004
+ ...cred,
5005
+ id: decodeBase64Url(cred.id),
5006
+ })),
5007
+ };
5008
+ }
5009
+ function formatCredentialForServer(credential) {
5010
+ const response = credential.response;
5011
+ return {
5012
+ id: credential.id,
5013
+ rawId: btoa(String.fromCharCode(...new Uint8Array(credential.rawId))),
5014
+ response: {
5015
+ authenticatorData: btoa(String.fromCharCode(...new Uint8Array(response.authenticatorData))),
5016
+ clientDataJSON: btoa(String.fromCharCode(...new Uint8Array(response.clientDataJSON))),
5017
+ signature: btoa(String.fromCharCode(...new Uint8Array(response.signature))),
5018
+ },
5019
+ type: credential.type,
5020
+ };
5021
+ }
5022
+ function extractAndSetSignInId(tokenResponse) {
5023
+ if (tokenResponse.sid) {
5024
+ authStore.authStore.setSignInId(tokenResponse.sid);
5025
+ return;
5026
+ }
5027
+ // Fallback: extract sid from JWT token payload
5028
+ try {
5029
+ const decoded = jwtDecode(tokenResponse.jwt);
5030
+ if (decoded.sid) {
5031
+ authStore.authStore.setSignInId(decoded.sid);
5032
+ }
5033
+ }
5034
+ catch {
5035
+ // Failed to decode JWT token to extract sid, continue without it
5036
+ }
5037
+ }
5038
+ function handlePasskeyError(error) {
5039
+ logger.error("Passkey error:", error);
5040
+ let errorMessage = "passkey_error";
5041
+ if (error instanceof DOMException) {
5042
+ errorMessage = PASSKEY_ERRORS[error.name] || "passkey_error";
5043
+ }
5044
+ authStore.authStore.setGlobalError("auth", errorMessage);
5045
+ authStore.authStore.setLoading(false);
5046
+ }
5047
+ async function authenticateWithPasskey(client, onSuccess) {
5048
+ authStore.authStore.setLoading(true);
5049
+ authStore.authStore.clearErrors();
5050
+ if (!window.PublicKeyCredential) {
5051
+ authStore.authStore.setGlobalError("auth", "passkey_not_supported");
5052
+ authStore.authStore.setLoading(false);
5053
+ return;
5054
+ }
5055
+ try {
5056
+ const [optionsError, options] = await client.auth.getPasskeyOptions(authStore.state.sid ? { signInId: authStore.state.sid } : undefined);
5057
+ if (optionsError || !options) {
5058
+ authStore.authStore.setGlobalError("auth", optionsError || "bad_request");
5059
+ authStore.authStore.setLoading(false);
5060
+ return;
5061
+ }
5062
+ const publicKeyOptions = buildPublicKeyOptions(options);
5063
+ const credential = (await navigator.credentials.get({
5064
+ publicKey: publicKeyOptions,
5065
+ }));
5066
+ if (!credential) {
5067
+ authStore.authStore.setGlobalError("auth", "passkey_cancelled");
5068
+ authStore.authStore.setLoading(false);
5069
+ return;
5070
+ }
5071
+ const formattedCredential = formatCredentialForServer(credential);
5072
+ const [verifyError, tkResponse] = await client.auth.authenticateWithPasskey({
5073
+ payload: { credential: formattedCredential },
5074
+ });
5075
+ const tokenResponse = tkResponse;
5076
+ if (verifyError || !tokenResponse) {
5077
+ authStore.authStore.setGlobalError("auth", verifyError || "authentication_failed");
5078
+ authStore.authStore.setLoading(false);
5079
+ return;
5080
+ }
5081
+ authStore.authStore.setToken(tokenResponse.jwt);
5082
+ extractAndSetSignInId(tokenResponse);
5083
+ onSuccess(tokenResponse);
5084
+ }
5085
+ catch (error) {
5086
+ handlePasskeyError(error);
5087
+ }
5088
+ }
5089
+
5090
+ class AuthHelpers {
5214
5091
  client;
5215
- list;
5216
- get;
5092
+ logger = index.createLogger("AuthHelpers");
5217
5093
  constructor(client) {
5218
5094
  this.client = client;
5219
- this.list = getWithSchema(this.client, SubscriptionsListResponseSchema, (_args) => "/api/sdk/v1/subscriptions", SubscriptionsListParamsSchema);
5220
- this.get = getWithSchema(this.client, SubscriptionSchema, (args) => `/api/sdk/v1/subscriptions/${args.id}`);
5095
+ }
5096
+ async createSignIn(email, password, sendMagicCode) {
5097
+ if (!email) {
5098
+ throw new Error(i18n.t("errors.required_field", { field: "Email" }));
5099
+ }
5100
+ authStore.authStore.setLoading(true);
5101
+ authStore.authStore.clearErrors();
5102
+ const [error, response] = await this.client.auth.createSignIn({ payload: { email, password, sendMagicCode } });
5103
+ if (error) {
5104
+ this.handleAuthError(error, response);
5105
+ return;
5106
+ }
5107
+ if (password) {
5108
+ const token = jwtDecode(response.jwt);
5109
+ authStore.authStore.setSignInId(token.sid);
5110
+ authStore.authStore.setToken(response.jwt);
5111
+ authStore.authStore.setLoading(false);
5112
+ authStore.authStore.getRootComponentRef()?.onAuth(response);
5113
+ return;
5114
+ }
5115
+ if (sendMagicCode) {
5116
+ authStore.authStore.setSignInId(response.sid);
5117
+ authStore.authStore.setMagicCodeStep("sent");
5118
+ authStore.authStore.setStep("magic-code");
5119
+ authStore.authStore.setLoading(false);
5120
+ return [error, response];
5121
+ }
5122
+ const signInResponse = response;
5123
+ authStore.authStore.setStep("verification");
5124
+ authStore.authStore.setEmail(email);
5125
+ authStore.authStore.setSignInId(signInResponse.sid);
5126
+ authStore.authStore.setLoginOptions(signInResponse.login_options);
5127
+ authStore.authStore.setLoading(false);
5128
+ }
5129
+ async authenticateWithPassword(password) {
5130
+ if (!authStore.state.sid) {
5131
+ throw new Error(i18n.t("errors.no_sign_in_id"));
5132
+ }
5133
+ if (!password) {
5134
+ throw new Error(i18n.t("errors.required_field", { field: "Password" }));
5135
+ }
5136
+ authStore.authStore.setLoading(true);
5137
+ authStore.authStore.clearErrors();
5138
+ const [error, response] = await this.client.auth.authenticateWithPassword({
5139
+ signInId: authStore.state.sid,
5140
+ payload: { password },
5141
+ });
5142
+ if (error) {
5143
+ this.handleAuthError(error, response);
5144
+ }
5145
+ else {
5146
+ authStore.authStore.setLoading(false);
5147
+ this.handleAuthSuccess(response);
5148
+ return;
5149
+ }
5150
+ }
5151
+ handleAuthError(error, response) {
5152
+ if (error === "account_not_found") {
5153
+ authStore.authStore.setFieldError("email", error);
5154
+ authStore.authStore.setLoading(false);
5155
+ return;
5156
+ }
5157
+ if (error === "missing_required_fields") {
5158
+ authStore.authStore.setMissingFields(response.fields);
5159
+ profileStore.state.data = response.fields;
5160
+ if (response.sid) {
5161
+ authStore.authStore.setSignInId(response.sid);
5162
+ }
5163
+ authStore.authStore.setStep("missing-fields");
5164
+ authStore.authStore.setLoading(false);
5165
+ return;
5166
+ }
5167
+ if (error === "account_locked") {
5168
+ authStore.authStore.setGlobalError("auth", error);
5169
+ }
5170
+ else {
5171
+ authStore.authStore.setFieldError("password", error);
5172
+ }
5173
+ authStore.authStore.setLoading(false);
5174
+ }
5175
+ async logout() {
5176
+ const [error, _] = await this.client.auth.signOut({ signInId: authStore.state.sid });
5177
+ if (error) {
5178
+ authStore.authStore.setGlobalError("auth", error);
5179
+ }
5180
+ return [error, _];
5181
+ }
5182
+ async refreshToken() {
5183
+ if (authStore.state.step === "missing-fields") {
5184
+ return;
5185
+ }
5186
+ this.extractSignInIdFromQuery();
5187
+ if (!authStore.state.sid) {
5188
+ this.logger.warn("No sign-in ID in the session");
5189
+ return;
5190
+ }
5191
+ const [error, response] = await this.client.auth.refreshToken({ signInId: authStore.state.sid });
5192
+ if (error) {
5193
+ authStore.authStore.reset();
5194
+ authStore.authStore.setGlobalError("auth", error);
5195
+ }
5196
+ else {
5197
+ authStore.authStore.setToken(response.jwt);
5198
+ }
5199
+ }
5200
+ handleSocialAuthRedirect() {
5201
+ // missing required fields flow
5202
+ const url = new URL(window.location.href);
5203
+ const params = url.searchParams;
5204
+ const error = params.get("error");
5205
+ if (error !== "missing_required_fields") {
5206
+ return;
5207
+ }
5208
+ const fieldsFromUrl = params.get("fields");
5209
+ if (!fieldsFromUrl) {
5210
+ return;
5211
+ }
5212
+ const signInId = params.get("sid");
5213
+ if (signInId) {
5214
+ authStore.authStore.setSignInId(signInId);
5215
+ }
5216
+ else {
5217
+ return;
5218
+ }
5219
+ try {
5220
+ const fields = JSON.parse(fieldsFromUrl);
5221
+ authStore.authStore.setMissingFields(fields);
5222
+ profileStore.state.data = fields;
5223
+ authStore.authStore.setStep("missing-fields");
5224
+ params.delete("error");
5225
+ params.delete("fields");
5226
+ const cleanUrl = `${url.origin}${url.pathname}${url.hash}`;
5227
+ window.history.replaceState(null, "", cleanUrl);
5228
+ }
5229
+ catch (e) {
5230
+ this.logger.error("Failed to parse missing fields payload:", e);
5231
+ authStore.authStore.setGlobalError("auth", "invalid_required_fields_payload");
5232
+ }
5233
+ }
5234
+ async sendMagicCode() {
5235
+ if (!authStore.state.sid && authStore.state.step !== "single-login") {
5236
+ throw new Error(i18n.t("errors.no_sign_in_id"));
5237
+ }
5238
+ authStore.authStore.setMagicCodeStep("requested");
5239
+ authStore.authStore.setLoading(true);
5240
+ authStore.authStore.clearErrors();
5241
+ if (authStore.state.step === "single-login") {
5242
+ const [error, response] = await this.createSignIn(authStore.state.email, undefined, true);
5243
+ authStore.authStore.setLoading(false);
5244
+ return [error, response];
5245
+ }
5246
+ const [error, response] = await this.client.auth.sendMagicCode({ signInId: authStore.state.sid });
5247
+ authStore.authStore.setLoading(false);
5248
+ authStore.authStore.setStep("magic-code");
5249
+ if (!error) {
5250
+ authStore.authStore.setMagicCodeStep("sent");
5251
+ return [null, response];
5252
+ }
5253
+ authStore.authStore.setFieldError("magicCode", error);
5254
+ if (error === "magic_code_recently_created") {
5255
+ authStore.authStore.setMagicCodeStep("sent");
5256
+ }
5257
+ return [error, response];
5258
+ }
5259
+ async authenticateWithMagicCode(code) {
5260
+ if (!authStore.state.sid) {
5261
+ throw new Error(i18n.t("errors.no_sign_in_id"));
5262
+ }
5263
+ if (!code) {
5264
+ throw new Error(i18n.t("errors.magic_code_is_missing"));
5265
+ }
5266
+ authStore.authStore.setLoading(true);
5267
+ authStore.authStore.clearErrors();
5268
+ const [error, response] = await this.client.auth.authenticateWithMagicCode({
5269
+ signInId: authStore.state.sid,
5270
+ payload: { code },
5271
+ });
5272
+ if (!error) {
5273
+ this.handleAuthSuccess(response);
5274
+ return;
5275
+ }
5276
+ if (error === "missing_required_fields") {
5277
+ this.handleMissingFields(response);
5278
+ return;
5279
+ }
5280
+ authStore.authStore.setLoading(false);
5281
+ authStore.authStore.setFieldError("magicCode", error);
5282
+ }
5283
+ async sendResetPasswordEmail() {
5284
+ if (!authStore.state.sid) {
5285
+ throw new Error(i18n.t("errors.no_sign_in_id"));
5286
+ }
5287
+ authStore.authStore.setLoading(true);
5288
+ authStore.authStore.setResetPasswordStep("requested");
5289
+ const [error, _] = await this.client.auth.sendResetPasswordEmail({
5290
+ signInId: authStore.state.sid,
5291
+ payload: { returnTo: window.location.href },
5292
+ });
5293
+ if (error) {
5294
+ authStore.authStore.setFieldError("resetPassword", error);
5295
+ }
5296
+ else {
5297
+ authStore.authStore.setResetPasswordStep("sent");
5298
+ authStore.authStore.clearErrors();
5299
+ }
5300
+ authStore.authStore.setLoading(false);
5301
+ }
5302
+ async handleResetPasswordRedirect() {
5303
+ const url = new URL(window.location.href);
5304
+ const params = url.searchParams;
5305
+ const resetToken = params.get("reset_password_token");
5306
+ if (!resetToken) {
5307
+ return false;
5308
+ }
5309
+ if (authStore.state.sid) {
5310
+ authStore.authStore.setLoading(true);
5311
+ const [error] = await this.client.auth.validateResetPasswordToken({
5312
+ signInId: authStore.state.sid,
5313
+ token: resetToken,
5314
+ });
5315
+ if (error) {
5316
+ authStore.authStore.setFieldError("resetPassword", error);
5317
+ authStore.authStore.setStep("reset-password");
5318
+ authStore.authStore.setLoading(false);
5319
+ return false;
5320
+ }
5321
+ }
5322
+ authStore.authStore.setResetToken(resetToken);
5323
+ authStore.authStore.setStep("reset-password");
5324
+ authStore.authStore.setLoading(false);
5325
+ return true;
5326
+ }
5327
+ async resetPassword() {
5328
+ if (!authStore.state.resetPassword.token) {
5329
+ throw new Error("No reset token available");
5330
+ }
5331
+ if (!authStore.state.resetPassword.newPassword) {
5332
+ authStore.authStore.setFieldError("resetPassword", "password_required");
5333
+ return;
5334
+ }
5335
+ if (authStore.state.resetPassword.passwordConfirmation &&
5336
+ authStore.state.resetPassword.newPassword !== authStore.state.resetPassword.passwordConfirmation) {
5337
+ authStore.authStore.setFieldError("resetPassword", "passwords_do_not_match");
5338
+ return;
5339
+ }
5340
+ authStore.authStore.setLoading(true);
5341
+ authStore.authStore.clearErrors();
5342
+ const [error, response] = await this.client.auth.resetPassword({
5343
+ signInId: authStore.state.sid,
5344
+ token: authStore.state.resetPassword.token,
5345
+ payload: {
5346
+ password: authStore.state.resetPassword.newPassword,
5347
+ passwordConfirmation: authStore.state.resetPassword.passwordConfirmation,
5348
+ },
5349
+ });
5350
+ if (error) {
5351
+ authStore.authStore.setFieldError("resetPassword", error);
5352
+ // TODO: add proper password requirements handling --> for now this is fine
5353
+ if (error === "invalid_password") {
5354
+ authStore.authStore.setFieldError("password", response.error_details?.password.map((p) => i18n.t(`errors.password_requirements.${p}`)).join("\n"));
5355
+ }
5356
+ }
5357
+ else {
5358
+ authStore.authStore.setStep("email");
5359
+ authStore.authStore.updateResetPassword({
5360
+ step: "completed",
5361
+ token: null,
5362
+ newPassword: "",
5363
+ passwordConfirmation: "",
5364
+ });
5365
+ componentUtils.clearUrlParam("reset_password_token");
5366
+ flashStore.Flash.success.addMessage("Password reset successfully");
5367
+ }
5368
+ authStore.authStore.setLoading(false);
5369
+ }
5370
+ authenticateWithPasskey() {
5371
+ return authenticateWithPasskey(this.client, (response) => this.handleAuthSuccess(response));
5372
+ }
5373
+ extractSignInIdFromQuery() {
5374
+ const sid = componentUtils.clearUrlParam("sid");
5375
+ if (sid) {
5376
+ authStore.authStore.setSignInId(sid);
5377
+ }
5378
+ }
5379
+ handleMissingFields(response) {
5380
+ authStore.authStore.setMissingFields(response.fields);
5381
+ profileStore.state.data = response.fields;
5382
+ authStore.authStore.setStep("missing-fields");
5383
+ authStore.authStore.setLoading(false);
5384
+ }
5385
+ handleAuthSuccess(response) {
5386
+ authStore.authStore.setToken(response.jwt);
5387
+ authStore.authStore.setLoading(false);
5388
+ authStore.authStore.getRootComponentRef()?.onAuth(response);
5221
5389
  }
5222
5390
  }
5223
5391
 
5392
+ class Auth {
5393
+ static instance;
5394
+ helpers;
5395
+ constructor(client) {
5396
+ this.helpers = new AuthHelpers(client);
5397
+ this.helpers.handleSocialAuthRedirect();
5398
+ this.helpers.handleResetPasswordRedirect();
5399
+ }
5400
+ static Errors = {
5401
+ email: {
5402
+ NOT_FOUND: "account_not_found",
5403
+ },
5404
+ magicCode: {
5405
+ RECENTLY_CREATED: "magic_code_recently_created",
5406
+ NOT_VALID: "magic_code_not_valid",
5407
+ EXPIRED: "magic_code_expired",
5408
+ USED: "magic_code_used",
5409
+ },
5410
+ password: {
5411
+ INVALID: "invalid_password",
5412
+ NOT_SET: "password_not_set",
5413
+ RESET_PASSWORD_ALREADY_SENT: "reset_password_already_sent",
5414
+ },
5415
+ general: {
5416
+ ACCOUNT_LOCKED: "account_locked",
5417
+ SIGN_IN_EXPIRED: "sign_in_expired",
5418
+ },
5419
+ };
5420
+ static async getInstance() {
5421
+ if (!Auth.isInitialized()) {
5422
+ await unidyStore.waitForConfig();
5423
+ return Auth.initialize(getUnidyClient());
5424
+ }
5425
+ return Auth.instance;
5426
+ }
5427
+ static initialize(client) {
5428
+ Auth.instance = new Auth(client);
5429
+ if (Auth.instance.isTokenValid(authStore.state.token)) {
5430
+ authStore.authStore.setAuthenticated(true);
5431
+ }
5432
+ return Auth.instance;
5433
+ }
5434
+ static isInitialized() {
5435
+ return !!Auth.instance;
5436
+ }
5437
+ isTokenValid(token) {
5438
+ try {
5439
+ let decoded;
5440
+ if (typeof token === "string") {
5441
+ decoded = jwtDecode(token);
5442
+ }
5443
+ else {
5444
+ decoded = token;
5445
+ }
5446
+ if (!decoded)
5447
+ return false;
5448
+ const currentTime = Date.now() / 1000;
5449
+ return decoded.exp > currentTime;
5450
+ }
5451
+ catch (error) {
5452
+ index.captureException(error);
5453
+ return false;
5454
+ }
5455
+ }
5456
+ async isAuthenticated() {
5457
+ const token = await this.getToken();
5458
+ return typeof token === "string";
5459
+ }
5460
+ async getToken() {
5461
+ const currentToken = authStore.state.token;
5462
+ if (currentToken && this.isTokenValid(currentToken)) {
5463
+ return currentToken;
5464
+ }
5465
+ await this.helpers.refreshToken();
5466
+ if (authStore.state.globalErrors.auth || !authStore.state.token) {
5467
+ return this.createAuthError(i18n.t("errors.refresh_failed"), "REFRESH_FAILED", true);
5468
+ }
5469
+ return authStore.state.token;
5470
+ }
5471
+ async userData() {
5472
+ const token = await this.getToken();
5473
+ if (typeof token !== "string") {
5474
+ return null;
5475
+ }
5476
+ if (!token) {
5477
+ return null;
5478
+ }
5479
+ try {
5480
+ return jwtDecode(token);
5481
+ }
5482
+ catch (error) {
5483
+ index.captureException(error);
5484
+ return null;
5485
+ }
5486
+ }
5487
+ async logout() {
5488
+ const [error, _] = await this.helpers.logout();
5489
+ if (error) {
5490
+ return this.createAuthError(i18n.t("errors.sign_out_failed", { reason: error }), "SIGN_OUT_FAILED", false);
5491
+ }
5492
+ authStore.authStore.reset();
5493
+ return true;
5494
+ }
5495
+ getEmail() {
5496
+ return authStore.state.email;
5497
+ }
5498
+ createAuthError(message, code, requiresReauth = false) {
5499
+ const error = new Error(message);
5500
+ error.code = code;
5501
+ error.requiresReauth = requiresReauth;
5502
+ return error;
5503
+ }
5504
+ }
5505
+
5506
+ /** Default no-op error reporter */
5507
+ const noopErrorReporter = {
5508
+ captureException: () => { },
5509
+ };
5510
+ /**
5511
+ * Default console logger for services.
5512
+ *
5513
+ * Note: This intentionally doesn't use the logger.ts module because:
5514
+ * 1. Services need to work in non-browser environments (standalone/Node.js)
5515
+ * 2. logger.ts is designed for Stencil components with browser-specific features
5516
+ * (localStorage-based log levels, UnidyComponent mixin)
5517
+ * 3. Services allow dependency injection of custom loggers for flexibility
5518
+ */
5519
+ const consoleLogger = {
5520
+ error: console.error.bind(console),
5521
+ warn: console.warn.bind(console),
5522
+ info: console.info.bind(console),
5523
+ debug: console.debug.bind(console),
5524
+ };
5525
+ class BaseService {
5526
+ client;
5527
+ logger;
5528
+ errorReporter;
5529
+ getIdToken;
5530
+ getLocale;
5531
+ constructor(client, serviceName, deps) {
5532
+ this.client = client;
5533
+ // Use injected dependencies or defaults
5534
+ this.logger = deps?.logger ?? consoleLogger;
5535
+ this.errorReporter = deps?.errorReporter ?? noopErrorReporter;
5536
+ this.getIdToken = deps?.getIdToken ?? (async () => null);
5537
+ this.getLocale = deps?.getLocale ?? (() => "en");
5538
+ // Prefix logger if using console
5539
+ if (!deps?.logger) {
5540
+ this.logger = {
5541
+ error: (...args) => console.error(`[${serviceName}]`, ...args),
5542
+ warn: (...args) => console.warn(`[${serviceName}]`, ...args),
5543
+ info: (...args) => console.info(`[${serviceName}]`, ...args),
5544
+ debug: (...args) => console.debug(`[${serviceName}]`, ...args),
5545
+ };
5546
+ }
5547
+ }
5548
+ handleResponse(response, handler) {
5549
+ if (response.connectionError) {
5550
+ return ["connection_failed", null];
5551
+ }
5552
+ try {
5553
+ return handler();
5554
+ }
5555
+ catch (error) {
5556
+ this.logger.error("Schema validation error", error);
5557
+ this.errorReporter.captureException(error);
5558
+ // Use safeParse to avoid throwing if response.data doesn't match the schema
5559
+ const parsed = SchemaValidationErrorSchema.safeParse(response.data);
5560
+ const schemaError = parsed.success
5561
+ ? parsed.data
5562
+ : { error_identifier: "schema_validation_error", errors: [String(error)] };
5563
+ return ["schema_validation_error", schemaError];
5564
+ }
5565
+ }
5566
+ buildAuthHeaders(headers) {
5567
+ const filtered = Object.entries(headers).reduce((acc, [key, value]) => {
5568
+ if (value !== undefined) {
5569
+ acc[key] = value;
5570
+ }
5571
+ return acc;
5572
+ }, {});
5573
+ return Object.keys(filtered).length > 0 ? filtered : undefined;
5574
+ }
5575
+ }
5576
+
5577
+ /** Default browser dependencies using Sentry and the SDK logger */
5578
+ function createBrowserDeps(serviceName) {
5579
+ return {
5580
+ logger: index.createLogger(serviceName),
5581
+ errorReporter: {
5582
+ captureException: (error, context) => index.captureException(error, { extra: context }),
5583
+ },
5584
+ getIdToken: async () => {
5585
+ const auth = await Auth.getInstance();
5586
+ const token = await auth.getToken();
5587
+ return typeof token === "string" ? token : null;
5588
+ },
5589
+ getLocale: () => unidyStore.unidyState.locale,
5590
+ };
5591
+ }
5224
5592
  class UnidyClient {
5225
5593
  apiClient;
5226
5594
  newsletters;
@@ -5232,11 +5600,12 @@ class UnidyClient {
5232
5600
  this.apiClient = new ApiClient(baseUrl, apiKey, (isConnected) => {
5233
5601
  unidyStore.unidyState.backendConnected = isConnected;
5234
5602
  });
5235
- this.newsletters = new NewsletterService(this.apiClient);
5236
- this.profile = new ProfileService(this.apiClient);
5237
- this.auth = new AuthService(this.apiClient);
5238
- this.tickets = new TicketsService(this.apiClient);
5239
- this.subscriptions = new SubscriptionsService(this.apiClient);
5603
+ // Initialize services with browser-specific dependencies
5604
+ this.newsletters = new NewsletterService(this.apiClient, createBrowserDeps("NewsletterService"));
5605
+ this.profile = new ProfileService(this.apiClient, createBrowserDeps("ProfileService"));
5606
+ this.auth = new AuthService(this.apiClient, createBrowserDeps("AuthService"));
5607
+ this.tickets = new TicketsService(this.apiClient, createBrowserDeps("TicketsService"));
5608
+ this.subscriptions = new SubscriptionsService(this.apiClient, createBrowserDeps("SubscriptionsService"));
5240
5609
  }
5241
5610
  }
5242
5611
  let instance = null;
@@ -5251,7 +5620,10 @@ function getUnidyClient() {
5251
5620
  }
5252
5621
 
5253
5622
  exports.ApiClient = ApiClient;
5623
+ exports.Auth = Auth;
5254
5624
  exports.AuthService = AuthService;
5625
+ exports.BaseErrorSchema = BaseErrorSchema;
5626
+ exports.BaseService = BaseService;
5255
5627
  exports.NewsletterService = NewsletterService;
5256
5628
  exports.PaginationMetaSchema = PaginationMetaSchema;
5257
5629
  exports.PaginationParamsSchema = PaginationParamsSchema;
@@ -5262,6 +5634,6 @@ exports.TicketsService = TicketsService;
5262
5634
  exports.UnidyClient = UnidyClient;
5263
5635
  exports.UserProfileSchema = UserProfileSchema;
5264
5636
  exports.getUnidyClient = getUnidyClient;
5265
- //# sourceMappingURL=index-R2MKLaem.js.map
5637
+ //# sourceMappingURL=index-CvFbf5-D.js.map
5266
5638
 
5267
- //# sourceMappingURL=index-R2MKLaem.js.map
5639
+ //# sourceMappingURL=index-CvFbf5-D.js.map