@unidy.io/sdk 1.1.4 → 1.2.0-alpha

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