@intlayer/design-system 5.7.2 → 5.7.4

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 (158) hide show
  1. package/dist/.vite/manifest.json +39 -0
  2. package/dist/Form-CriPBaZk.js.map +1 -1
  3. package/dist/Form-DJrUK3mm.cjs.map +1 -1
  4. package/dist/better-auth.8zoxzg-F-BEBqzpjz.cjs +40 -0
  5. package/dist/better-auth.8zoxzg-F-BEBqzpjz.cjs.map +1 -0
  6. package/dist/better-auth.8zoxzg-F-D8e0X4ys.js +41 -0
  7. package/dist/better-auth.8zoxzg-F-D8e0X4ys.js.map +1 -0
  8. package/dist/components/Breadcrumb/index.cjs +1 -0
  9. package/dist/components/Breadcrumb/index.cjs.map +1 -1
  10. package/dist/components/Breadcrumb/index.d.ts +1 -1
  11. package/dist/components/Breadcrumb/index.d.ts.map +1 -1
  12. package/dist/components/Breadcrumb/index.mjs +1 -0
  13. package/dist/components/Breadcrumb/index.mjs.map +1 -1
  14. package/dist/components/CopyToClipboard/index.cjs +32 -23
  15. package/dist/components/CopyToClipboard/index.cjs.map +1 -1
  16. package/dist/components/CopyToClipboard/index.d.ts.map +1 -1
  17. package/dist/components/CopyToClipboard/index.mjs +32 -23
  18. package/dist/components/CopyToClipboard/index.mjs.map +1 -1
  19. package/dist/components/DictionaryFieldEditor/ContentEditorView/TextEditor.cjs +7 -4
  20. package/dist/components/DictionaryFieldEditor/ContentEditorView/TextEditor.cjs.map +1 -1
  21. package/dist/components/DictionaryFieldEditor/ContentEditorView/TextEditor.d.ts +2 -2
  22. package/dist/components/DictionaryFieldEditor/ContentEditorView/TextEditor.d.ts.map +1 -1
  23. package/dist/components/DictionaryFieldEditor/ContentEditorView/TextEditor.mjs +7 -4
  24. package/dist/components/DictionaryFieldEditor/ContentEditorView/TextEditor.mjs.map +1 -1
  25. package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/DictionaryCreationForm.cjs +1 -0
  26. package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/DictionaryCreationForm.cjs.map +1 -1
  27. package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/DictionaryCreationForm.mjs +1 -0
  28. package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/DictionaryCreationForm.mjs.map +1 -1
  29. package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.cjs +2 -1
  30. package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.cjs.map +1 -1
  31. package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.mjs +2 -1
  32. package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.mjs.map +1 -1
  33. package/dist/components/DictionaryFieldEditor/DictionaryFieldEditor.cjs +2 -1
  34. package/dist/components/DictionaryFieldEditor/DictionaryFieldEditor.cjs.map +1 -1
  35. package/dist/components/DictionaryFieldEditor/DictionaryFieldEditor.mjs +2 -1
  36. package/dist/components/DictionaryFieldEditor/DictionaryFieldEditor.mjs.map +1 -1
  37. package/dist/components/DictionaryFieldEditor/NavigationView/NavigationViewNode.cjs +2 -2
  38. package/dist/components/DictionaryFieldEditor/NavigationView/NavigationViewNode.cjs.map +1 -1
  39. package/dist/components/DictionaryFieldEditor/NavigationView/NavigationViewNode.mjs +2 -2
  40. package/dist/components/DictionaryFieldEditor/NavigationView/NavigationViewNode.mjs.map +1 -1
  41. package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.cjs +5 -2
  42. package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.cjs.map +1 -1
  43. package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.d.ts.map +1 -1
  44. package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.mjs +5 -2
  45. package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.mjs.map +1 -1
  46. package/dist/components/DictionaryFieldEditor/StructureView/StructureView.cjs +2 -1
  47. package/dist/components/DictionaryFieldEditor/StructureView/StructureView.cjs.map +1 -1
  48. package/dist/components/DictionaryFieldEditor/StructureView/StructureView.mjs +2 -1
  49. package/dist/components/DictionaryFieldEditor/StructureView/StructureView.mjs.map +1 -1
  50. package/dist/components/DictionaryFieldEditor/VersionSwitcherDropDown/VersionSwitcherContext.cjs +2 -1
  51. package/dist/components/DictionaryFieldEditor/VersionSwitcherDropDown/VersionSwitcherContext.cjs.map +1 -1
  52. package/dist/components/DictionaryFieldEditor/VersionSwitcherDropDown/VersionSwitcherContext.mjs +2 -1
  53. package/dist/components/DictionaryFieldEditor/VersionSwitcherDropDown/VersionSwitcherContext.mjs.map +1 -1
  54. package/dist/components/EditableField/EditableFieldTextArea.cjs +2 -1
  55. package/dist/components/EditableField/EditableFieldTextArea.cjs.map +1 -1
  56. package/dist/components/EditableField/EditableFieldTextArea.mjs +2 -1
  57. package/dist/components/EditableField/EditableFieldTextArea.mjs.map +1 -1
  58. package/dist/components/Flags/Flag.cjs +23 -1
  59. package/dist/components/Flags/Flag.cjs.map +1 -1
  60. package/dist/components/Flags/Flag.d.ts.map +1 -1
  61. package/dist/components/Flags/Flag.mjs +23 -1
  62. package/dist/components/Flags/Flag.mjs.map +1 -1
  63. package/dist/components/Form/FormBase.cjs.map +1 -1
  64. package/dist/components/Form/FormBase.mjs.map +1 -1
  65. package/dist/components/Form/elements/CheckboxElement.d.ts +2 -2
  66. package/dist/components/Form/elements/CheckboxElement.d.ts.map +1 -1
  67. package/dist/components/IDE/CodeContext.cjs +2 -1
  68. package/dist/components/IDE/CodeContext.cjs.map +1 -1
  69. package/dist/components/IDE/CodeContext.mjs +2 -1
  70. package/dist/components/IDE/CodeContext.mjs.map +1 -1
  71. package/dist/components/Input/Checkbox.cjs +29 -22
  72. package/dist/components/Input/Checkbox.cjs.map +1 -1
  73. package/dist/components/Input/Checkbox.d.ts +3 -2
  74. package/dist/components/Input/Checkbox.d.ts.map +1 -1
  75. package/dist/components/Input/Checkbox.mjs +30 -23
  76. package/dist/components/Input/Checkbox.mjs.map +1 -1
  77. package/dist/components/Link/Link.cjs +2 -2
  78. package/dist/components/Link/Link.cjs.map +1 -1
  79. package/dist/components/Link/Link.mjs +2 -2
  80. package/dist/components/Link/Link.mjs.map +1 -1
  81. package/dist/components/LocaleSwitcherContentDropDown/LocaleSwitcherContent.cjs +2 -1
  82. package/dist/components/LocaleSwitcherContentDropDown/LocaleSwitcherContent.cjs.map +1 -1
  83. package/dist/components/LocaleSwitcherContentDropDown/LocaleSwitcherContent.mjs +2 -1
  84. package/dist/components/LocaleSwitcherContentDropDown/LocaleSwitcherContent.mjs.map +1 -1
  85. package/dist/components/LocaleSwitcherContentDropDown/LocaleSwitcherContentContext.cjs +2 -1
  86. package/dist/components/LocaleSwitcherContentDropDown/LocaleSwitcherContentContext.cjs.map +1 -1
  87. package/dist/components/LocaleSwitcherContentDropDown/LocaleSwitcherContentContext.mjs +2 -1
  88. package/dist/components/LocaleSwitcherContentDropDown/LocaleSwitcherContentContext.mjs.map +1 -1
  89. package/dist/components/Modal/Modal.cjs +2 -1
  90. package/dist/components/Modal/Modal.cjs.map +1 -1
  91. package/dist/components/Modal/Modal.mjs +2 -1
  92. package/dist/components/Modal/Modal.mjs.map +1 -1
  93. package/dist/components/Navbar/MobileNavbar.cjs +2 -1
  94. package/dist/components/Navbar/MobileNavbar.cjs.map +1 -1
  95. package/dist/components/Navbar/MobileNavbar.mjs +2 -1
  96. package/dist/components/Navbar/MobileNavbar.mjs.map +1 -1
  97. package/dist/components/Navbar/index.cjs +2 -1
  98. package/dist/components/Navbar/index.cjs.map +1 -1
  99. package/dist/components/Navbar/index.mjs +2 -1
  100. package/dist/components/Navbar/index.mjs.map +1 -1
  101. package/dist/components/SwitchSelector/index.cjs +2 -1
  102. package/dist/components/SwitchSelector/index.cjs.map +1 -1
  103. package/dist/components/SwitchSelector/index.mjs +2 -1
  104. package/dist/components/SwitchSelector/index.mjs.map +1 -1
  105. package/dist/components/TabSelector/TabSelector.cjs +2 -1
  106. package/dist/components/TabSelector/TabSelector.cjs.map +1 -1
  107. package/dist/components/TabSelector/TabSelector.mjs +2 -1
  108. package/dist/components/TabSelector/TabSelector.mjs.map +1 -1
  109. package/dist/components/TextArea/AutocompleteTextArea.cjs +5 -4
  110. package/dist/components/TextArea/AutocompleteTextArea.cjs.map +1 -1
  111. package/dist/components/TextArea/AutocompleteTextArea.mjs +5 -4
  112. package/dist/components/TextArea/AutocompleteTextArea.mjs.map +1 -1
  113. package/dist/hooks/auth.cjs +1783 -0
  114. package/dist/hooks/auth.cjs.map +1 -0
  115. package/dist/hooks/auth.d.ts +32 -0
  116. package/dist/hooks/auth.d.ts.map +1 -0
  117. package/dist/hooks/auth.mjs +1783 -0
  118. package/dist/hooks/auth.mjs.map +1 -0
  119. package/dist/hooks/index.cjs +4 -1
  120. package/dist/hooks/index.cjs.map +1 -1
  121. package/dist/hooks/index.d.ts +1 -0
  122. package/dist/hooks/index.d.ts.map +1 -1
  123. package/dist/hooks/index.mjs +5 -2
  124. package/dist/hooks/index.mjs.map +1 -1
  125. package/dist/hooks/intlayerAPIHooks.cjs +65 -66
  126. package/dist/hooks/intlayerAPIHooks.cjs.map +1 -1
  127. package/dist/hooks/intlayerAPIHooks.d.ts +884 -9
  128. package/dist/hooks/intlayerAPIHooks.d.ts.map +1 -1
  129. package/dist/hooks/intlayerAPIHooks.mjs +66 -67
  130. package/dist/hooks/intlayerAPIHooks.mjs.map +1 -1
  131. package/dist/hooks/useAuth/useAuth.cjs.map +1 -1
  132. package/dist/hooks/useAuth/useAuth.d.ts +6 -7
  133. package/dist/hooks/useAuth/useAuth.d.ts.map +1 -1
  134. package/dist/hooks/useAuth/useAuth.mjs.map +1 -1
  135. package/dist/hooks/useAuth/useOAuth2.cjs +3 -3
  136. package/dist/hooks/useAuth/useOAuth2.cjs.map +1 -1
  137. package/dist/hooks/useAuth/useOAuth2.mjs +3 -3
  138. package/dist/hooks/useAuth/useOAuth2.mjs.map +1 -1
  139. package/dist/hooks/useAuth/useSession.cjs +5 -5
  140. package/dist/hooks/useAuth/useSession.cjs.map +1 -1
  141. package/dist/hooks/useAuth/useSession.d.ts +354 -6
  142. package/dist/hooks/useAuth/useSession.d.ts.map +1 -1
  143. package/dist/hooks/useAuth/useSession.mjs +5 -5
  144. package/dist/hooks/useAuth/useSession.mjs.map +1 -1
  145. package/dist/hooks/useIntlayerAPI.cjs +7 -1
  146. package/dist/hooks/useIntlayerAPI.cjs.map +1 -1
  147. package/dist/hooks/useIntlayerAPI.d.ts +11 -0
  148. package/dist/hooks/useIntlayerAPI.d.ts.map +1 -0
  149. package/dist/hooks/useIntlayerAPI.mjs +8 -2
  150. package/dist/hooks/useIntlayerAPI.mjs.map +1 -1
  151. package/dist/hooks/useUser/index.cjs +2 -1
  152. package/dist/hooks/useUser/index.cjs.map +1 -1
  153. package/dist/hooks/useUser/index.d.ts +18 -2
  154. package/dist/hooks/useUser/index.d.ts.map +1 -1
  155. package/dist/hooks/useUser/index.mjs +2 -1
  156. package/dist/hooks/useUser/index.mjs.map +1 -1
  157. package/package.json +20 -19
  158. package/dist/tailwind.css +0 -2
@@ -0,0 +1,1783 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const configuration = require("@intlayer/config/built");
4
+ const betterAuth_8zoxzgF = require("../better-auth.8zoxzg-F-BEBqzpjz.cjs");
5
+ var __defProp = Object.defineProperty;
6
+ var __defProps = Object.defineProperties;
7
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var BetterFetchError = class extends Error {
25
+ constructor(status, statusText, error) {
26
+ super(statusText || status.toString(), {
27
+ cause: error
28
+ });
29
+ this.status = status;
30
+ this.statusText = statusText;
31
+ this.error = error;
32
+ }
33
+ };
34
+ var initializePlugins = async (url, options) => {
35
+ var _a, _b, _c, _d, _e, _f;
36
+ let opts = options || {};
37
+ const hooks = {
38
+ onRequest: [options == null ? void 0 : options.onRequest],
39
+ onResponse: [options == null ? void 0 : options.onResponse],
40
+ onSuccess: [options == null ? void 0 : options.onSuccess],
41
+ onError: [options == null ? void 0 : options.onError],
42
+ onRetry: [options == null ? void 0 : options.onRetry]
43
+ };
44
+ if (!options || !(options == null ? void 0 : options.plugins)) {
45
+ return {
46
+ url,
47
+ options: opts,
48
+ hooks
49
+ };
50
+ }
51
+ for (const plugin of (options == null ? void 0 : options.plugins) || []) {
52
+ if (plugin.init) {
53
+ const pluginRes = await ((_a = plugin.init) == null ? void 0 : _a.call(plugin, url.toString(), options));
54
+ opts = pluginRes.options || opts;
55
+ url = pluginRes.url;
56
+ }
57
+ hooks.onRequest.push((_b = plugin.hooks) == null ? void 0 : _b.onRequest);
58
+ hooks.onResponse.push((_c = plugin.hooks) == null ? void 0 : _c.onResponse);
59
+ hooks.onSuccess.push((_d = plugin.hooks) == null ? void 0 : _d.onSuccess);
60
+ hooks.onError.push((_e = plugin.hooks) == null ? void 0 : _e.onError);
61
+ hooks.onRetry.push((_f = plugin.hooks) == null ? void 0 : _f.onRetry);
62
+ }
63
+ return {
64
+ url,
65
+ options: opts,
66
+ hooks
67
+ };
68
+ };
69
+ var LinearRetryStrategy = class {
70
+ constructor(options) {
71
+ this.options = options;
72
+ }
73
+ shouldAttemptRetry(attempt, response) {
74
+ if (this.options.shouldRetry) {
75
+ return Promise.resolve(
76
+ attempt < this.options.attempts && this.options.shouldRetry(response)
77
+ );
78
+ }
79
+ return Promise.resolve(attempt < this.options.attempts);
80
+ }
81
+ getDelay() {
82
+ return this.options.delay;
83
+ }
84
+ };
85
+ var ExponentialRetryStrategy = class {
86
+ constructor(options) {
87
+ this.options = options;
88
+ }
89
+ shouldAttemptRetry(attempt, response) {
90
+ if (this.options.shouldRetry) {
91
+ return Promise.resolve(
92
+ attempt < this.options.attempts && this.options.shouldRetry(response)
93
+ );
94
+ }
95
+ return Promise.resolve(attempt < this.options.attempts);
96
+ }
97
+ getDelay(attempt) {
98
+ const delay = Math.min(
99
+ this.options.maxDelay,
100
+ this.options.baseDelay * 2 ** attempt
101
+ );
102
+ return delay;
103
+ }
104
+ };
105
+ function createRetryStrategy(options) {
106
+ if (typeof options === "number") {
107
+ return new LinearRetryStrategy({
108
+ type: "linear",
109
+ attempts: options,
110
+ delay: 1e3
111
+ });
112
+ }
113
+ switch (options.type) {
114
+ case "linear":
115
+ return new LinearRetryStrategy(options);
116
+ case "exponential":
117
+ return new ExponentialRetryStrategy(options);
118
+ default:
119
+ throw new Error("Invalid retry strategy");
120
+ }
121
+ }
122
+ var getAuthHeader = async (options) => {
123
+ const headers = {};
124
+ const getValue = async (value) => typeof value === "function" ? await value() : value;
125
+ if (options == null ? void 0 : options.auth) {
126
+ if (options.auth.type === "Bearer") {
127
+ const token = await getValue(options.auth.token);
128
+ if (!token) {
129
+ return headers;
130
+ }
131
+ headers["authorization"] = `Bearer ${token}`;
132
+ } else if (options.auth.type === "Basic") {
133
+ const username = getValue(options.auth.username);
134
+ const password = getValue(options.auth.password);
135
+ if (!username || !password) {
136
+ return headers;
137
+ }
138
+ headers["authorization"] = `Basic ${btoa(`${username}:${password}`)}`;
139
+ } else if (options.auth.type === "Custom") {
140
+ const value = getValue(options.auth.value);
141
+ if (!value) {
142
+ return headers;
143
+ }
144
+ headers["authorization"] = `${getValue(options.auth.prefix)} ${value}`;
145
+ }
146
+ }
147
+ return headers;
148
+ };
149
+ var JSON_RE = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;
150
+ function detectResponseType(request) {
151
+ const _contentType = request.headers.get("content-type");
152
+ const textTypes = /* @__PURE__ */ new Set([
153
+ "image/svg",
154
+ "application/xml",
155
+ "application/xhtml",
156
+ "application/html"
157
+ ]);
158
+ if (!_contentType) {
159
+ return "json";
160
+ }
161
+ const contentType = _contentType.split(";").shift() || "";
162
+ if (JSON_RE.test(contentType)) {
163
+ return "json";
164
+ }
165
+ if (textTypes.has(contentType) || contentType.startsWith("text/")) {
166
+ return "text";
167
+ }
168
+ return "blob";
169
+ }
170
+ function isJSONParsable(value) {
171
+ try {
172
+ JSON.parse(value);
173
+ return true;
174
+ } catch (error) {
175
+ return false;
176
+ }
177
+ }
178
+ function isJSONSerializable(value) {
179
+ if (value === void 0) {
180
+ return false;
181
+ }
182
+ const t = typeof value;
183
+ if (t === "string" || t === "number" || t === "boolean" || t === null) {
184
+ return true;
185
+ }
186
+ if (t !== "object") {
187
+ return false;
188
+ }
189
+ if (Array.isArray(value)) {
190
+ return true;
191
+ }
192
+ if (value.buffer) {
193
+ return false;
194
+ }
195
+ return value.constructor && value.constructor.name === "Object" || typeof value.toJSON === "function";
196
+ }
197
+ function jsonParse(text) {
198
+ try {
199
+ return JSON.parse(text);
200
+ } catch (error) {
201
+ return text;
202
+ }
203
+ }
204
+ function isFunction(value) {
205
+ return typeof value === "function";
206
+ }
207
+ function getFetch(options) {
208
+ if (options == null ? void 0 : options.customFetchImpl) {
209
+ return options.customFetchImpl;
210
+ }
211
+ if (typeof globalThis !== "undefined" && isFunction(globalThis.fetch)) {
212
+ return globalThis.fetch;
213
+ }
214
+ if (typeof window !== "undefined" && isFunction(window.fetch)) {
215
+ return window.fetch;
216
+ }
217
+ throw new Error("No fetch implementation found");
218
+ }
219
+ async function getHeaders(opts) {
220
+ const headers = new Headers(opts == null ? void 0 : opts.headers);
221
+ const authHeader = await getAuthHeader(opts);
222
+ for (const [key, value] of Object.entries(authHeader || {})) {
223
+ headers.set(key, value);
224
+ }
225
+ if (!headers.has("content-type")) {
226
+ const t = detectContentType(opts == null ? void 0 : opts.body);
227
+ if (t) {
228
+ headers.set("content-type", t);
229
+ }
230
+ }
231
+ return headers;
232
+ }
233
+ function detectContentType(body) {
234
+ if (isJSONSerializable(body)) {
235
+ return "application/json";
236
+ }
237
+ return null;
238
+ }
239
+ function getBody(options) {
240
+ if (!(options == null ? void 0 : options.body)) {
241
+ return null;
242
+ }
243
+ const headers = new Headers(options == null ? void 0 : options.headers);
244
+ if (isJSONSerializable(options.body) && !headers.has("content-type")) {
245
+ for (const [key, value] of Object.entries(options == null ? void 0 : options.body)) {
246
+ if (value instanceof Date) {
247
+ options.body[key] = value.toISOString();
248
+ }
249
+ }
250
+ return JSON.stringify(options.body);
251
+ }
252
+ return options.body;
253
+ }
254
+ function getMethod$1(url, options) {
255
+ var _a;
256
+ if (options == null ? void 0 : options.method) {
257
+ return options.method.toUpperCase();
258
+ }
259
+ if (url.startsWith("@")) {
260
+ const pMethod = (_a = url.split("@")[1]) == null ? void 0 : _a.split("/")[0];
261
+ if (!methods.includes(pMethod)) {
262
+ return (options == null ? void 0 : options.body) ? "POST" : "GET";
263
+ }
264
+ return pMethod.toUpperCase();
265
+ }
266
+ return (options == null ? void 0 : options.body) ? "POST" : "GET";
267
+ }
268
+ function getTimeout(options, controller) {
269
+ let abortTimeout;
270
+ if (!(options == null ? void 0 : options.signal) && (options == null ? void 0 : options.timeout)) {
271
+ abortTimeout = setTimeout(() => controller == null ? void 0 : controller.abort(), options == null ? void 0 : options.timeout);
272
+ }
273
+ return {
274
+ abortTimeout,
275
+ clearTimeout: () => {
276
+ if (abortTimeout) {
277
+ clearTimeout(abortTimeout);
278
+ }
279
+ }
280
+ };
281
+ }
282
+ var ValidationError = class _ValidationError extends Error {
283
+ constructor(issues, message) {
284
+ super(message || JSON.stringify(issues, null, 2));
285
+ this.issues = issues;
286
+ Object.setPrototypeOf(this, _ValidationError.prototype);
287
+ }
288
+ };
289
+ async function parseStandardSchema(schema, input) {
290
+ let result = await schema["~standard"].validate(input);
291
+ if (result.issues) {
292
+ throw new ValidationError(result.issues);
293
+ }
294
+ return result.value;
295
+ }
296
+ var methods = ["get", "post", "put", "patch", "delete"];
297
+ var applySchemaPlugin = (config) => ({
298
+ id: "apply-schema",
299
+ name: "Apply Schema",
300
+ version: "1.0.0",
301
+ async init(url, options) {
302
+ var _a, _b, _c, _d;
303
+ const schema = ((_b = (_a = config.plugins) == null ? void 0 : _a.find(
304
+ (plugin) => {
305
+ var _a2;
306
+ return ((_a2 = plugin.schema) == null ? void 0 : _a2.config) ? url.startsWith(plugin.schema.config.baseURL || "") || url.startsWith(plugin.schema.config.prefix || "") : false;
307
+ }
308
+ )) == null ? void 0 : _b.schema) || config.schema;
309
+ if (schema) {
310
+ let urlKey = url;
311
+ if ((_c = schema.config) == null ? void 0 : _c.prefix) {
312
+ if (urlKey.startsWith(schema.config.prefix)) {
313
+ urlKey = urlKey.replace(schema.config.prefix, "");
314
+ if (schema.config.baseURL) {
315
+ url = url.replace(schema.config.prefix, schema.config.baseURL);
316
+ }
317
+ }
318
+ }
319
+ if ((_d = schema.config) == null ? void 0 : _d.baseURL) {
320
+ if (urlKey.startsWith(schema.config.baseURL)) {
321
+ urlKey = urlKey.replace(schema.config.baseURL, "");
322
+ }
323
+ }
324
+ const keySchema = schema.schema[urlKey];
325
+ if (keySchema) {
326
+ let opts = __spreadProps(__spreadValues({}, options), {
327
+ method: keySchema.method,
328
+ output: keySchema.output
329
+ });
330
+ if (!(options == null ? void 0 : options.disableValidation)) {
331
+ opts = __spreadProps(__spreadValues({}, opts), {
332
+ body: keySchema.input ? await parseStandardSchema(keySchema.input, options == null ? void 0 : options.body) : options == null ? void 0 : options.body,
333
+ params: keySchema.params ? await parseStandardSchema(keySchema.params, options == null ? void 0 : options.params) : options == null ? void 0 : options.params,
334
+ query: keySchema.query ? await parseStandardSchema(keySchema.query, options == null ? void 0 : options.query) : options == null ? void 0 : options.query
335
+ });
336
+ }
337
+ return {
338
+ url,
339
+ options: opts
340
+ };
341
+ }
342
+ }
343
+ return {
344
+ url,
345
+ options
346
+ };
347
+ }
348
+ });
349
+ var createFetch = (config) => {
350
+ async function $fetch(url, options) {
351
+ const opts = __spreadProps(__spreadValues(__spreadValues({}, config), options), {
352
+ plugins: [...(config == null ? void 0 : config.plugins) || [], applySchemaPlugin(config || {})]
353
+ });
354
+ if (config == null ? void 0 : config.catchAllError) {
355
+ try {
356
+ return await betterFetch(url, opts);
357
+ } catch (error) {
358
+ return {
359
+ data: null,
360
+ error: {
361
+ status: 500,
362
+ statusText: "Fetch Error",
363
+ message: "Fetch related error. Captured by catchAllError option. See error property for more details.",
364
+ error
365
+ }
366
+ };
367
+ }
368
+ }
369
+ return await betterFetch(url, opts);
370
+ }
371
+ return $fetch;
372
+ };
373
+ function getURL2(url, option) {
374
+ let { baseURL, params, query } = option || {
375
+ query: {},
376
+ params: {},
377
+ baseURL: ""
378
+ };
379
+ let basePath = url.startsWith("http") ? url.split("/").slice(0, 3).join("/") : baseURL || "";
380
+ if (url.startsWith("@")) {
381
+ const m = url.toString().split("@")[1].split("/")[0];
382
+ if (methods.includes(m)) {
383
+ url = url.replace(`@${m}/`, "/");
384
+ }
385
+ }
386
+ if (!basePath.endsWith("/")) basePath += "/";
387
+ let [path, urlQuery] = url.replace(basePath, "").split("?");
388
+ const queryParams = new URLSearchParams(urlQuery);
389
+ for (const [key, value] of Object.entries(query || {})) {
390
+ if (value == null) continue;
391
+ queryParams.set(key, String(value));
392
+ }
393
+ if (params) {
394
+ if (Array.isArray(params)) {
395
+ const paramPaths = path.split("/").filter((p) => p.startsWith(":"));
396
+ for (const [index, key] of paramPaths.entries()) {
397
+ const value = params[index];
398
+ path = path.replace(key, value);
399
+ }
400
+ } else {
401
+ for (const [key, value] of Object.entries(params)) {
402
+ path = path.replace(`:${key}`, String(value));
403
+ }
404
+ }
405
+ }
406
+ path = path.split("/").map(encodeURIComponent).join("/");
407
+ if (path.startsWith("/")) path = path.slice(1);
408
+ let queryParamString = queryParams.toString();
409
+ queryParamString = queryParamString.length > 0 ? `?${queryParamString}`.replace(/\+/g, "%20") : "";
410
+ if (!basePath.startsWith("http")) {
411
+ return `${basePath}${path}${queryParamString}`;
412
+ }
413
+ const _url = new URL(`${path}${queryParamString}`, basePath);
414
+ return _url;
415
+ }
416
+ var betterFetch = async (url, options) => {
417
+ var _a, _b, _c, _d, _e, _f, _g, _h;
418
+ const {
419
+ hooks,
420
+ url: __url,
421
+ options: opts
422
+ } = await initializePlugins(url, options);
423
+ const fetch2 = getFetch(opts);
424
+ const controller = new AbortController();
425
+ const signal = (_a = opts.signal) != null ? _a : controller.signal;
426
+ const _url = getURL2(__url, opts);
427
+ const body = getBody(opts);
428
+ const headers = await getHeaders(opts);
429
+ const method = getMethod$1(__url, opts);
430
+ let context = __spreadProps(__spreadValues({}, opts), {
431
+ url: _url,
432
+ headers,
433
+ body,
434
+ method,
435
+ signal
436
+ });
437
+ for (const onRequest of hooks.onRequest) {
438
+ if (onRequest) {
439
+ const res = await onRequest(context);
440
+ if (res instanceof Object) {
441
+ context = res;
442
+ }
443
+ }
444
+ }
445
+ if ("pipeTo" in context && typeof context.pipeTo === "function" || typeof ((_b = options == null ? void 0 : options.body) == null ? void 0 : _b.pipe) === "function") {
446
+ if (!("duplex" in context)) {
447
+ context.duplex = "half";
448
+ }
449
+ }
450
+ const { clearTimeout: clearTimeout2 } = getTimeout(opts, controller);
451
+ let response = await fetch2(context.url, context);
452
+ clearTimeout2();
453
+ const responseContext = {
454
+ response,
455
+ request: context
456
+ };
457
+ for (const onResponse of hooks.onResponse) {
458
+ if (onResponse) {
459
+ const r = await onResponse(__spreadProps(__spreadValues({}, responseContext), {
460
+ response: ((_c = options == null ? void 0 : options.hookOptions) == null ? void 0 : _c.cloneResponse) ? response.clone() : response
461
+ }));
462
+ if (r instanceof Response) {
463
+ response = r;
464
+ } else if (r instanceof Object) {
465
+ response = r.response;
466
+ }
467
+ }
468
+ }
469
+ if (response.ok) {
470
+ const hasBody = context.method !== "HEAD";
471
+ if (!hasBody) {
472
+ return {
473
+ data: "",
474
+ error: null
475
+ };
476
+ }
477
+ const responseType = detectResponseType(response);
478
+ const successContext = {
479
+ data: "",
480
+ response,
481
+ request: context
482
+ };
483
+ if (responseType === "json" || responseType === "text") {
484
+ const text = await response.text();
485
+ const parser2 = (_d = context.jsonParser) != null ? _d : jsonParse;
486
+ const data = await parser2(text);
487
+ successContext.data = data;
488
+ } else {
489
+ successContext.data = await response[responseType]();
490
+ }
491
+ if (context == null ? void 0 : context.output) {
492
+ if (context.output && !context.disableValidation) {
493
+ successContext.data = await parseStandardSchema(
494
+ context.output,
495
+ successContext.data
496
+ );
497
+ }
498
+ }
499
+ for (const onSuccess of hooks.onSuccess) {
500
+ if (onSuccess) {
501
+ await onSuccess(__spreadProps(__spreadValues({}, successContext), {
502
+ response: ((_e = options == null ? void 0 : options.hookOptions) == null ? void 0 : _e.cloneResponse) ? response.clone() : response
503
+ }));
504
+ }
505
+ }
506
+ if (options == null ? void 0 : options.throw) {
507
+ return successContext.data;
508
+ }
509
+ return {
510
+ data: successContext.data,
511
+ error: null
512
+ };
513
+ }
514
+ const parser = (_f = options == null ? void 0 : options.jsonParser) != null ? _f : jsonParse;
515
+ const responseText = await response.text();
516
+ const isJSONResponse = isJSONParsable(responseText);
517
+ const errorObject = isJSONResponse ? await parser(responseText) : null;
518
+ const errorContext = {
519
+ response,
520
+ responseText,
521
+ request: context,
522
+ error: __spreadProps(__spreadValues({}, errorObject), {
523
+ status: response.status,
524
+ statusText: response.statusText
525
+ })
526
+ };
527
+ for (const onError of hooks.onError) {
528
+ if (onError) {
529
+ await onError(__spreadProps(__spreadValues({}, errorContext), {
530
+ response: ((_g = options == null ? void 0 : options.hookOptions) == null ? void 0 : _g.cloneResponse) ? response.clone() : response
531
+ }));
532
+ }
533
+ }
534
+ if (options == null ? void 0 : options.retry) {
535
+ const retryStrategy = createRetryStrategy(options.retry);
536
+ const _retryAttempt = (_h = options.retryAttempt) != null ? _h : 0;
537
+ if (await retryStrategy.shouldAttemptRetry(_retryAttempt, response)) {
538
+ for (const onRetry of hooks.onRetry) {
539
+ if (onRetry) {
540
+ await onRetry(responseContext);
541
+ }
542
+ }
543
+ const delay = retryStrategy.getDelay(_retryAttempt);
544
+ await new Promise((resolve) => setTimeout(resolve, delay));
545
+ return await betterFetch(url, __spreadProps(__spreadValues({}, options), {
546
+ retryAttempt: _retryAttempt + 1
547
+ }));
548
+ }
549
+ }
550
+ if (options == null ? void 0 : options.throw) {
551
+ throw new BetterFetchError(
552
+ response.status,
553
+ response.statusText,
554
+ isJSONResponse ? errorObject : responseText
555
+ );
556
+ }
557
+ return {
558
+ data: null,
559
+ error: __spreadProps(__spreadValues({}, errorObject), {
560
+ status: response.status,
561
+ statusText: response.statusText
562
+ })
563
+ };
564
+ };
565
+ class BetterAuthError extends Error {
566
+ constructor(message, cause) {
567
+ super(message);
568
+ this.name = "BetterAuthError";
569
+ this.message = message;
570
+ this.cause = cause;
571
+ this.stack = "";
572
+ }
573
+ }
574
+ function checkHasPath(url) {
575
+ try {
576
+ const parsedUrl = new URL(url);
577
+ return parsedUrl.pathname !== "/";
578
+ } catch (error) {
579
+ throw new BetterAuthError(
580
+ `Invalid base URL: ${url}. Please provide a valid base URL.`
581
+ );
582
+ }
583
+ }
584
+ function withPath(url, path = "/api/auth") {
585
+ const hasPath = checkHasPath(url);
586
+ if (hasPath) {
587
+ return url;
588
+ }
589
+ path = path.startsWith("/") ? path : `/${path}`;
590
+ return `${url.replace(/\/+$/, "")}${path}`;
591
+ }
592
+ function getBaseURL(url, path, request) {
593
+ if (url) {
594
+ return withPath(url, path);
595
+ }
596
+ const fromEnv = betterAuth_8zoxzgF.env.BETTER_AUTH_URL || betterAuth_8zoxzgF.env.NEXT_PUBLIC_BETTER_AUTH_URL || betterAuth_8zoxzgF.env.PUBLIC_BETTER_AUTH_URL || betterAuth_8zoxzgF.env.NUXT_PUBLIC_BETTER_AUTH_URL || betterAuth_8zoxzgF.env.NUXT_PUBLIC_AUTH_URL || (betterAuth_8zoxzgF.env.BASE_URL !== "/" ? betterAuth_8zoxzgF.env.BASE_URL : void 0);
597
+ if (fromEnv) {
598
+ return withPath(fromEnv, path);
599
+ }
600
+ if (typeof window !== "undefined" && window.location) {
601
+ return withPath(window.location.origin, path);
602
+ }
603
+ return void 0;
604
+ }
605
+ var dist = {};
606
+ var lifecycle = {};
607
+ var cleanStores = {};
608
+ var task = {};
609
+ var hasRequiredTask;
610
+ function requireTask() {
611
+ if (hasRequiredTask) return task;
612
+ hasRequiredTask = 1;
613
+ Object.defineProperty(task, "__esModule", { value: true });
614
+ task.cleanTasks = task.allTasks = task.task = task.startTask = void 0;
615
+ let tasks = 0;
616
+ let resolves = [];
617
+ function startTask() {
618
+ tasks += 1;
619
+ return () => {
620
+ tasks -= 1;
621
+ if (tasks === 0) {
622
+ let prevResolves = resolves;
623
+ resolves = [];
624
+ for (let i of prevResolves)
625
+ i();
626
+ }
627
+ };
628
+ }
629
+ task.startTask = startTask;
630
+ function task$1(cb) {
631
+ let endTask = startTask();
632
+ return cb().finally(endTask);
633
+ }
634
+ task.task = task$1;
635
+ function allTasks() {
636
+ if (tasks === 0) {
637
+ return Promise.resolve();
638
+ } else {
639
+ return new Promise((resolve) => {
640
+ resolves.push(resolve);
641
+ });
642
+ }
643
+ }
644
+ task.allTasks = allTasks;
645
+ function cleanTasks() {
646
+ tasks = 0;
647
+ }
648
+ task.cleanTasks = cleanTasks;
649
+ return task;
650
+ }
651
+ var hasRequiredCleanStores;
652
+ function requireCleanStores() {
653
+ if (hasRequiredCleanStores) return cleanStores;
654
+ hasRequiredCleanStores = 1;
655
+ (function(exports2) {
656
+ var define_process_env_default = {};
657
+ Object.defineProperty(exports2, "__esModule", { value: true });
658
+ exports2.cleanStores = exports2.clean = void 0;
659
+ const index_js_1 = /* @__PURE__ */ requireTask();
660
+ exports2.clean = Symbol("clean");
661
+ let cleanStores2 = (...stores) => {
662
+ if (define_process_env_default.NODE_ENV === "production") {
663
+ throw new Error("cleanStores() can be used only during development or tests");
664
+ }
665
+ (0, index_js_1.cleanTasks)();
666
+ for (let store of stores) {
667
+ if (store) {
668
+ if (store.mocked)
669
+ delete store.mocked;
670
+ if (store[exports2.clean])
671
+ store[exports2.clean]();
672
+ }
673
+ }
674
+ };
675
+ exports2.cleanStores = cleanStores2;
676
+ })(cleanStores);
677
+ return cleanStores;
678
+ }
679
+ var hasRequiredLifecycle;
680
+ function requireLifecycle() {
681
+ if (hasRequiredLifecycle) return lifecycle;
682
+ hasRequiredLifecycle = 1;
683
+ (function(exports2) {
684
+ var define_process_env_default = {};
685
+ Object.defineProperty(exports2, "__esModule", { value: true });
686
+ exports2.onMount = exports2.STORE_UNMOUNT_DELAY = exports2.onBuild = exports2.onNotify = exports2.onSet = exports2.onStop = exports2.onStart = void 0;
687
+ const index_js_1 = /* @__PURE__ */ requireCleanStores();
688
+ const START = 0;
689
+ const STOP = 1;
690
+ const SET = 2;
691
+ const NOTIFY = 3;
692
+ const BUILD = 4;
693
+ const MOUNT = 5;
694
+ const UNMOUNT = 6;
695
+ const REVERT_MUTATION = 10;
696
+ let on = (object, listener, eventKey, mutateStore) => {
697
+ object.events = object.events || {};
698
+ if (!object.events[eventKey + REVERT_MUTATION]) {
699
+ object.events[eventKey + REVERT_MUTATION] = mutateStore((eventProps) => {
700
+ object.events[eventKey].reduceRight((event, l) => (l(event), event), {
701
+ shared: {},
702
+ ...eventProps
703
+ });
704
+ });
705
+ }
706
+ object.events[eventKey] = object.events[eventKey] || [];
707
+ object.events[eventKey].push(listener);
708
+ return () => {
709
+ let currentListeners = object.events[eventKey];
710
+ let index = currentListeners.indexOf(listener);
711
+ currentListeners.splice(index, 1);
712
+ if (!currentListeners.length) {
713
+ delete object.events[eventKey];
714
+ object.events[eventKey + REVERT_MUTATION]();
715
+ delete object.events[eventKey + REVERT_MUTATION];
716
+ }
717
+ };
718
+ };
719
+ let onStart = (store, listener) => on(store, listener, START, (runListeners) => {
720
+ let originListen = store.listen;
721
+ store.listen = (arg) => {
722
+ if (!store.lc && !store.starting) {
723
+ store.starting = true;
724
+ runListeners();
725
+ delete store.starting;
726
+ }
727
+ return originListen(arg);
728
+ };
729
+ return () => {
730
+ store.listen = originListen;
731
+ };
732
+ });
733
+ exports2.onStart = onStart;
734
+ let onStop = (store, listener) => on(store, listener, STOP, (runListeners) => {
735
+ let originOff = store.off;
736
+ store.off = () => {
737
+ runListeners();
738
+ originOff();
739
+ };
740
+ return () => {
741
+ store.off = originOff;
742
+ };
743
+ });
744
+ exports2.onStop = onStop;
745
+ let onSet = (store, listener) => on(store, listener, SET, (runListeners) => {
746
+ let originSet = store.set;
747
+ let originSetKey = store.setKey;
748
+ if (store.setKey) {
749
+ store.setKey = (changed, changedValue) => {
750
+ let isAborted;
751
+ let abort = () => {
752
+ isAborted = true;
753
+ };
754
+ runListeners({
755
+ abort,
756
+ changed,
757
+ newValue: { ...store.value, [changed]: changedValue }
758
+ });
759
+ if (!isAborted)
760
+ return originSetKey(changed, changedValue);
761
+ };
762
+ }
763
+ store.set = (newValue) => {
764
+ let isAborted;
765
+ let abort = () => {
766
+ isAborted = true;
767
+ };
768
+ runListeners({ abort, newValue });
769
+ if (!isAborted)
770
+ return originSet(newValue);
771
+ };
772
+ return () => {
773
+ store.set = originSet;
774
+ store.setKey = originSetKey;
775
+ };
776
+ });
777
+ exports2.onSet = onSet;
778
+ let onNotify = (store, listener) => on(store, listener, NOTIFY, (runListeners) => {
779
+ let originNotify = store.notify;
780
+ store.notify = (changed) => {
781
+ let isAborted;
782
+ let abort = () => {
783
+ isAborted = true;
784
+ };
785
+ runListeners({ abort, changed });
786
+ if (!isAborted)
787
+ return originNotify(changed);
788
+ };
789
+ return () => {
790
+ store.notify = originNotify;
791
+ };
792
+ });
793
+ exports2.onNotify = onNotify;
794
+ let onBuild = (Template, listener) => on(Template, listener, BUILD, (runListeners) => {
795
+ let originBuild = Template.build;
796
+ Template.build = (...args) => {
797
+ let store = originBuild(...args);
798
+ runListeners({ store });
799
+ return store;
800
+ };
801
+ return () => {
802
+ Template.build = originBuild;
803
+ };
804
+ });
805
+ exports2.onBuild = onBuild;
806
+ exports2.STORE_UNMOUNT_DELAY = 1e3;
807
+ let onMount = (store, initialize) => {
808
+ let listener = (payload) => {
809
+ let destroy = initialize(payload);
810
+ if (destroy)
811
+ store.events[UNMOUNT].push(destroy);
812
+ };
813
+ return on(store, listener, MOUNT, (runListeners) => {
814
+ let originListen = store.listen;
815
+ store.listen = (arg) => {
816
+ if (!store.lc && !store.active) {
817
+ store.active = true;
818
+ runListeners();
819
+ }
820
+ return originListen(arg);
821
+ };
822
+ let originOff = store.off;
823
+ store.events[UNMOUNT] = [];
824
+ store.off = () => {
825
+ setTimeout(() => {
826
+ if (store.active && !store.lc) {
827
+ store.active = false;
828
+ for (let destroy of store.events[UNMOUNT])
829
+ destroy();
830
+ store.events[UNMOUNT] = [];
831
+ originOff();
832
+ }
833
+ }, exports2.STORE_UNMOUNT_DELAY);
834
+ };
835
+ if (define_process_env_default.NODE_ENV !== "production") {
836
+ let originClean = store[index_js_1.clean];
837
+ store[index_js_1.clean] = () => {
838
+ for (let destroy of store.events[UNMOUNT])
839
+ destroy();
840
+ store.events[UNMOUNT] = [];
841
+ store.active = false;
842
+ originClean();
843
+ };
844
+ }
845
+ return () => {
846
+ store.listen = originListen;
847
+ store.off = originOff;
848
+ };
849
+ });
850
+ };
851
+ exports2.onMount = onMount;
852
+ })(lifecycle);
853
+ return lifecycle;
854
+ }
855
+ var action = {};
856
+ var hasRequiredAction;
857
+ function requireAction() {
858
+ if (hasRequiredAction) return action;
859
+ hasRequiredAction = 1;
860
+ (function(exports2) {
861
+ Object.defineProperty(exports2, "__esModule", { value: true });
862
+ exports2.actionFor = exports2.action = exports2.lastAction = void 0;
863
+ const index_js_1 = /* @__PURE__ */ requireTask();
864
+ exports2.lastAction = Symbol();
865
+ let doAction = (store, actionName, cb, args) => {
866
+ let tracker = { ...store };
867
+ tracker.set = (...setArgs) => {
868
+ store[exports2.lastAction] = actionName;
869
+ store.set(...setArgs);
870
+ delete store[exports2.lastAction];
871
+ };
872
+ if (store.setKey) {
873
+ tracker.setKey = (...setArgs) => {
874
+ store[exports2.lastAction] = actionName;
875
+ store.setKey(...setArgs);
876
+ delete store[exports2.lastAction];
877
+ };
878
+ }
879
+ let result = cb(tracker, ...args);
880
+ if (result instanceof Promise) {
881
+ let endTask = (0, index_js_1.startTask)();
882
+ return result.finally(endTask);
883
+ }
884
+ return result;
885
+ };
886
+ let action2 = (store, actionName, cb) => (...args) => doAction(store, actionName, cb, args);
887
+ exports2.action = action2;
888
+ let actionFor = (Template, actionName, cb) => {
889
+ return (store, ...rest) => doAction(store, actionName, cb, rest);
890
+ };
891
+ exports2.actionFor = actionFor;
892
+ })(action);
893
+ return action;
894
+ }
895
+ var mapTemplate = {};
896
+ var map = {};
897
+ var atom = {};
898
+ var hasRequiredAtom;
899
+ function requireAtom() {
900
+ if (hasRequiredAtom) return atom;
901
+ hasRequiredAtom = 1;
902
+ (function(exports2) {
903
+ var define_process_env_default = {};
904
+ Object.defineProperty(exports2, "__esModule", { value: true });
905
+ exports2.atom = exports2.notifyId = void 0;
906
+ const index_js_1 = /* @__PURE__ */ requireCleanStores();
907
+ let listenerQueue = [];
908
+ exports2.notifyId = 0;
909
+ let atom2 = (initialValue) => {
910
+ let currentListeners;
911
+ let nextListeners = [];
912
+ let store = {
913
+ lc: 0,
914
+ value: initialValue,
915
+ set(data) {
916
+ store.value = data;
917
+ store.notify();
918
+ },
919
+ get() {
920
+ if (!store.lc) {
921
+ store.listen(() => {
922
+ })();
923
+ }
924
+ return store.value;
925
+ },
926
+ notify(changedKey) {
927
+ currentListeners = nextListeners;
928
+ let runListenerQueue = !listenerQueue.length;
929
+ for (let i = 0; i < currentListeners.length; i++) {
930
+ listenerQueue.push(currentListeners[i], store.value, changedKey);
931
+ }
932
+ if (runListenerQueue) {
933
+ exports2.notifyId++;
934
+ for (let i = 0; i < listenerQueue.length; i += 3) {
935
+ listenerQueue[i](listenerQueue[i + 1], listenerQueue[i + 2]);
936
+ }
937
+ listenerQueue.length = 0;
938
+ }
939
+ },
940
+ listen(listener) {
941
+ if (nextListeners === currentListeners) {
942
+ nextListeners = nextListeners.slice();
943
+ }
944
+ store.lc = nextListeners.push(listener);
945
+ return () => {
946
+ if (nextListeners === currentListeners) {
947
+ nextListeners = nextListeners.slice();
948
+ }
949
+ let index = nextListeners.indexOf(listener);
950
+ if (~index) {
951
+ nextListeners.splice(index, 1);
952
+ store.lc--;
953
+ if (!store.lc)
954
+ store.off();
955
+ }
956
+ };
957
+ },
958
+ subscribe(cb) {
959
+ let unbind = store.listen(cb);
960
+ cb(store.value);
961
+ return unbind;
962
+ },
963
+ off() {
964
+ }
965
+ /* It will be called on last listener unsubscribing.
966
+ We will redefine it in onMount and onStop. */
967
+ };
968
+ if (define_process_env_default.NODE_ENV !== "production") {
969
+ store[index_js_1.clean] = () => {
970
+ nextListeners = [];
971
+ store.lc = 0;
972
+ store.off();
973
+ };
974
+ }
975
+ return store;
976
+ };
977
+ exports2.atom = atom2;
978
+ })(atom);
979
+ return atom;
980
+ }
981
+ var hasRequiredMap;
982
+ function requireMap() {
983
+ if (hasRequiredMap) return map;
984
+ hasRequiredMap = 1;
985
+ Object.defineProperty(map, "__esModule", { value: true });
986
+ map.map = void 0;
987
+ const index_js_1 = /* @__PURE__ */ requireAtom();
988
+ let map$1 = (value = {}) => {
989
+ let store = (0, index_js_1.atom)(value);
990
+ store.setKey = function(key, newValue) {
991
+ if (typeof newValue === "undefined") {
992
+ if (key in store.value) {
993
+ store.value = { ...store.value };
994
+ delete store.value[key];
995
+ store.notify(key);
996
+ }
997
+ } else if (store.value[key] !== newValue) {
998
+ store.value = {
999
+ ...store.value,
1000
+ [key]: newValue
1001
+ };
1002
+ store.notify(key);
1003
+ }
1004
+ };
1005
+ return store;
1006
+ };
1007
+ map.map = map$1;
1008
+ return map;
1009
+ }
1010
+ var hasRequiredMapTemplate;
1011
+ function requireMapTemplate() {
1012
+ if (hasRequiredMapTemplate) return mapTemplate;
1013
+ hasRequiredMapTemplate = 1;
1014
+ var define_process_env_default = {};
1015
+ Object.defineProperty(mapTemplate, "__esModule", { value: true });
1016
+ mapTemplate.mapTemplate = void 0;
1017
+ const index_js_1 = /* @__PURE__ */ requireLifecycle();
1018
+ const index_js_2 = /* @__PURE__ */ requireCleanStores();
1019
+ const index_js_3 = /* @__PURE__ */ requireMap();
1020
+ function mapTemplate$1(init) {
1021
+ let Template = (id, ...args) => {
1022
+ if (!Template.cache[id]) {
1023
+ Template.cache[id] = Template.build(id, ...args);
1024
+ }
1025
+ return Template.cache[id];
1026
+ };
1027
+ Template.build = (id, ...args) => {
1028
+ let store = (0, index_js_3.map)({ id });
1029
+ (0, index_js_1.onMount)(store, () => {
1030
+ let destroy;
1031
+ if (init)
1032
+ destroy = init(store, id, ...args);
1033
+ return () => {
1034
+ delete Template.cache[id];
1035
+ if (destroy)
1036
+ destroy();
1037
+ };
1038
+ });
1039
+ return store;
1040
+ };
1041
+ Template.cache = {};
1042
+ if (define_process_env_default.NODE_ENV !== "production") {
1043
+ Template[index_js_2.clean] = () => {
1044
+ for (let id in Template.cache) {
1045
+ Template.cache[id][index_js_2.clean]();
1046
+ }
1047
+ Template.cache = {};
1048
+ };
1049
+ }
1050
+ return Template;
1051
+ }
1052
+ mapTemplate.mapTemplate = mapTemplate$1;
1053
+ return mapTemplate;
1054
+ }
1055
+ var listenKeys = {};
1056
+ var hasRequiredListenKeys;
1057
+ function requireListenKeys() {
1058
+ if (hasRequiredListenKeys) return listenKeys;
1059
+ hasRequiredListenKeys = 1;
1060
+ Object.defineProperty(listenKeys, "__esModule", { value: true });
1061
+ listenKeys.listenKeys = void 0;
1062
+ function listenKeys$1(store, keys, listener) {
1063
+ let keysSet = /* @__PURE__ */ new Set([...keys, void 0]);
1064
+ return store.listen((value, changed) => {
1065
+ if (keysSet.has(changed)) {
1066
+ listener(value, changed);
1067
+ }
1068
+ });
1069
+ }
1070
+ listenKeys.listenKeys = listenKeys$1;
1071
+ return listenKeys;
1072
+ }
1073
+ var keepMount = {};
1074
+ var hasRequiredKeepMount;
1075
+ function requireKeepMount() {
1076
+ if (hasRequiredKeepMount) return keepMount;
1077
+ hasRequiredKeepMount = 1;
1078
+ Object.defineProperty(keepMount, "__esModule", { value: true });
1079
+ keepMount.keepMount = void 0;
1080
+ let keepMount$1 = (store) => {
1081
+ store.listen(() => {
1082
+ });
1083
+ };
1084
+ keepMount.keepMount = keepMount$1;
1085
+ return keepMount;
1086
+ }
1087
+ var computed = {};
1088
+ var hasRequiredComputed;
1089
+ function requireComputed() {
1090
+ if (hasRequiredComputed) return computed;
1091
+ hasRequiredComputed = 1;
1092
+ Object.defineProperty(computed, "__esModule", { value: true });
1093
+ computed.computed = void 0;
1094
+ const index_js_1 = /* @__PURE__ */ requireLifecycle();
1095
+ const index_js_2 = /* @__PURE__ */ requireAtom();
1096
+ let computed$1 = (stores, cb) => {
1097
+ if (!Array.isArray(stores))
1098
+ stores = [stores];
1099
+ let diamondNotifyId;
1100
+ let diamondArgs = [];
1101
+ let run = () => {
1102
+ let args = stores.map((store) => store.get());
1103
+ if (diamondNotifyId !== index_js_2.notifyId || args.some((arg, i) => arg !== diamondArgs[i])) {
1104
+ diamondNotifyId = index_js_2.notifyId;
1105
+ diamondArgs = args;
1106
+ derived.set(cb(...args));
1107
+ }
1108
+ };
1109
+ let derived = (0, index_js_2.atom)();
1110
+ (0, index_js_1.onMount)(derived, () => {
1111
+ let unbinds = stores.map((store) => store.listen(run, cb));
1112
+ run();
1113
+ return () => {
1114
+ for (let unbind of unbinds)
1115
+ unbind();
1116
+ };
1117
+ });
1118
+ return derived;
1119
+ };
1120
+ computed.computed = computed$1;
1121
+ return computed;
1122
+ }
1123
+ var hasRequiredDist;
1124
+ function requireDist() {
1125
+ if (hasRequiredDist) return dist;
1126
+ hasRequiredDist = 1;
1127
+ (function(exports2) {
1128
+ Object.defineProperty(exports2, "__esModule", { value: true });
1129
+ exports2.map = exports2.atom = exports2.computed = exports2.keepMount = exports2.listenKeys = exports2.mapTemplate = exports2.cleanStores = exports2.clean = exports2.lastAction = exports2.actionFor = exports2.action = exports2.task = exports2.allTasks = exports2.startTask = exports2.cleanTasks = exports2.onSet = exports2.onStop = exports2.onBuild = exports2.onMount = exports2.onStart = exports2.onNotify = exports2.STORE_UNMOUNT_DELAY = void 0;
1130
+ var index_js_1 = /* @__PURE__ */ requireLifecycle();
1131
+ Object.defineProperty(exports2, "STORE_UNMOUNT_DELAY", { enumerable: true, get: function() {
1132
+ return index_js_1.STORE_UNMOUNT_DELAY;
1133
+ } });
1134
+ Object.defineProperty(exports2, "onNotify", { enumerable: true, get: function() {
1135
+ return index_js_1.onNotify;
1136
+ } });
1137
+ Object.defineProperty(exports2, "onStart", { enumerable: true, get: function() {
1138
+ return index_js_1.onStart;
1139
+ } });
1140
+ Object.defineProperty(exports2, "onMount", { enumerable: true, get: function() {
1141
+ return index_js_1.onMount;
1142
+ } });
1143
+ Object.defineProperty(exports2, "onBuild", { enumerable: true, get: function() {
1144
+ return index_js_1.onBuild;
1145
+ } });
1146
+ Object.defineProperty(exports2, "onStop", { enumerable: true, get: function() {
1147
+ return index_js_1.onStop;
1148
+ } });
1149
+ Object.defineProperty(exports2, "onSet", { enumerable: true, get: function() {
1150
+ return index_js_1.onSet;
1151
+ } });
1152
+ var index_js_2 = /* @__PURE__ */ requireTask();
1153
+ Object.defineProperty(exports2, "cleanTasks", { enumerable: true, get: function() {
1154
+ return index_js_2.cleanTasks;
1155
+ } });
1156
+ Object.defineProperty(exports2, "startTask", { enumerable: true, get: function() {
1157
+ return index_js_2.startTask;
1158
+ } });
1159
+ Object.defineProperty(exports2, "allTasks", { enumerable: true, get: function() {
1160
+ return index_js_2.allTasks;
1161
+ } });
1162
+ Object.defineProperty(exports2, "task", { enumerable: true, get: function() {
1163
+ return index_js_2.task;
1164
+ } });
1165
+ var index_js_3 = /* @__PURE__ */ requireAction();
1166
+ Object.defineProperty(exports2, "action", { enumerable: true, get: function() {
1167
+ return index_js_3.action;
1168
+ } });
1169
+ Object.defineProperty(exports2, "actionFor", { enumerable: true, get: function() {
1170
+ return index_js_3.actionFor;
1171
+ } });
1172
+ Object.defineProperty(exports2, "lastAction", { enumerable: true, get: function() {
1173
+ return index_js_3.lastAction;
1174
+ } });
1175
+ var index_js_4 = /* @__PURE__ */ requireCleanStores();
1176
+ Object.defineProperty(exports2, "clean", { enumerable: true, get: function() {
1177
+ return index_js_4.clean;
1178
+ } });
1179
+ Object.defineProperty(exports2, "cleanStores", { enumerable: true, get: function() {
1180
+ return index_js_4.cleanStores;
1181
+ } });
1182
+ var index_js_5 = /* @__PURE__ */ requireMapTemplate();
1183
+ Object.defineProperty(exports2, "mapTemplate", { enumerable: true, get: function() {
1184
+ return index_js_5.mapTemplate;
1185
+ } });
1186
+ var index_js_6 = /* @__PURE__ */ requireListenKeys();
1187
+ Object.defineProperty(exports2, "listenKeys", { enumerable: true, get: function() {
1188
+ return index_js_6.listenKeys;
1189
+ } });
1190
+ var index_js_7 = /* @__PURE__ */ requireKeepMount();
1191
+ Object.defineProperty(exports2, "keepMount", { enumerable: true, get: function() {
1192
+ return index_js_7.keepMount;
1193
+ } });
1194
+ var index_js_8 = /* @__PURE__ */ requireComputed();
1195
+ Object.defineProperty(exports2, "computed", { enumerable: true, get: function() {
1196
+ return index_js_8.computed;
1197
+ } });
1198
+ var index_js_9 = /* @__PURE__ */ requireAtom();
1199
+ Object.defineProperty(exports2, "atom", { enumerable: true, get: function() {
1200
+ return index_js_9.atom;
1201
+ } });
1202
+ var index_js_10 = /* @__PURE__ */ requireMap();
1203
+ Object.defineProperty(exports2, "map", { enumerable: true, get: function() {
1204
+ return index_js_10.map;
1205
+ } });
1206
+ })(dist);
1207
+ return dist;
1208
+ }
1209
+ var distExports = /* @__PURE__ */ requireDist();
1210
+ const isServer = typeof window === "undefined";
1211
+ const useAuthQuery = (initializedAtom, path, $fetch, options) => {
1212
+ const value = distExports.atom({
1213
+ data: null,
1214
+ error: null,
1215
+ isPending: true,
1216
+ isRefetching: false,
1217
+ refetch: () => {
1218
+ return fn();
1219
+ }
1220
+ });
1221
+ const fn = () => {
1222
+ const opts = typeof options === "function" ? options({
1223
+ data: value.get().data,
1224
+ error: value.get().error,
1225
+ isPending: value.get().isPending
1226
+ }) : options;
1227
+ return $fetch(path, {
1228
+ ...opts,
1229
+ async onSuccess(context) {
1230
+ value.set({
1231
+ data: context.data,
1232
+ error: null,
1233
+ isPending: false,
1234
+ isRefetching: false,
1235
+ refetch: value.value.refetch
1236
+ });
1237
+ await opts?.onSuccess?.(context);
1238
+ },
1239
+ async onError(context) {
1240
+ const { request } = context;
1241
+ const retryAttempts = typeof request.retry === "number" ? request.retry : request.retry?.attempts;
1242
+ const retryAttempt = request.retryAttempt || 0;
1243
+ if (retryAttempts && retryAttempt < retryAttempts) return;
1244
+ value.set({
1245
+ error: context.error,
1246
+ data: null,
1247
+ isPending: false,
1248
+ isRefetching: false,
1249
+ refetch: value.value.refetch
1250
+ });
1251
+ await opts?.onError?.(context);
1252
+ },
1253
+ async onRequest(context) {
1254
+ const currentValue = value.get();
1255
+ value.set({
1256
+ isPending: currentValue.data === null,
1257
+ data: currentValue.data,
1258
+ error: null,
1259
+ isRefetching: true,
1260
+ refetch: value.value.refetch
1261
+ });
1262
+ await opts?.onRequest?.(context);
1263
+ }
1264
+ });
1265
+ };
1266
+ initializedAtom = Array.isArray(initializedAtom) ? initializedAtom : [initializedAtom];
1267
+ let isMounted = false;
1268
+ for (const initAtom of initializedAtom) {
1269
+ initAtom.subscribe(() => {
1270
+ if (isServer) {
1271
+ return;
1272
+ }
1273
+ if (isMounted) {
1274
+ fn();
1275
+ } else {
1276
+ distExports.onMount(value, () => {
1277
+ setTimeout(() => {
1278
+ fn();
1279
+ }, 0);
1280
+ isMounted = true;
1281
+ return () => {
1282
+ value.off();
1283
+ initAtom.off();
1284
+ };
1285
+ });
1286
+ }
1287
+ });
1288
+ }
1289
+ return value;
1290
+ };
1291
+ const PROTO_POLLUTION_PATTERNS = {
1292
+ proto: /"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,
1293
+ constructor: /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,
1294
+ protoShort: /"__proto__"\s*:/,
1295
+ constructorShort: /"constructor"\s*:/
1296
+ };
1297
+ const JSON_SIGNATURE = /^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;
1298
+ const SPECIAL_VALUES = {
1299
+ true: true,
1300
+ false: false,
1301
+ null: null,
1302
+ undefined: void 0,
1303
+ nan: Number.NaN,
1304
+ infinity: Number.POSITIVE_INFINITY,
1305
+ "-infinity": Number.NEGATIVE_INFINITY
1306
+ };
1307
+ const ISO_DATE_REGEX = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,7}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;
1308
+ function isValidDate(date) {
1309
+ return date instanceof Date && !isNaN(date.getTime());
1310
+ }
1311
+ function parseISODate(value) {
1312
+ const match = ISO_DATE_REGEX.exec(value);
1313
+ if (!match) return null;
1314
+ const [
1315
+ ,
1316
+ year,
1317
+ month,
1318
+ day,
1319
+ hour,
1320
+ minute,
1321
+ second,
1322
+ ms,
1323
+ offsetSign,
1324
+ offsetHour,
1325
+ offsetMinute
1326
+ ] = match;
1327
+ let date = new Date(
1328
+ Date.UTC(
1329
+ parseInt(year, 10),
1330
+ parseInt(month, 10) - 1,
1331
+ parseInt(day, 10),
1332
+ parseInt(hour, 10),
1333
+ parseInt(minute, 10),
1334
+ parseInt(second, 10),
1335
+ ms ? parseInt(ms.padEnd(3, "0"), 10) : 0
1336
+ )
1337
+ );
1338
+ if (offsetSign) {
1339
+ const offset = (parseInt(offsetHour, 10) * 60 + parseInt(offsetMinute, 10)) * (offsetSign === "+" ? -1 : 1);
1340
+ date.setUTCMinutes(date.getUTCMinutes() + offset);
1341
+ }
1342
+ return isValidDate(date) ? date : null;
1343
+ }
1344
+ function betterJSONParse(value, options = {}) {
1345
+ const {
1346
+ strict = false,
1347
+ warnings = false,
1348
+ reviver,
1349
+ parseDates = true
1350
+ } = options;
1351
+ if (typeof value !== "string") {
1352
+ return value;
1353
+ }
1354
+ const trimmed = value.trim();
1355
+ if (trimmed[0] === '"' && trimmed.endsWith('"') && !trimmed.slice(1, -1).includes('"')) {
1356
+ return trimmed.slice(1, -1);
1357
+ }
1358
+ const lowerValue = trimmed.toLowerCase();
1359
+ if (lowerValue.length <= 9 && lowerValue in SPECIAL_VALUES) {
1360
+ return SPECIAL_VALUES[lowerValue];
1361
+ }
1362
+ if (!JSON_SIGNATURE.test(trimmed)) {
1363
+ if (strict) {
1364
+ throw new SyntaxError("[better-json] Invalid JSON");
1365
+ }
1366
+ return value;
1367
+ }
1368
+ const hasProtoPattern = Object.entries(PROTO_POLLUTION_PATTERNS).some(
1369
+ ([key, pattern]) => {
1370
+ const matches = pattern.test(trimmed);
1371
+ if (matches && warnings) {
1372
+ console.warn(
1373
+ `[better-json] Detected potential prototype pollution attempt using ${key} pattern`
1374
+ );
1375
+ }
1376
+ return matches;
1377
+ }
1378
+ );
1379
+ if (hasProtoPattern && strict) {
1380
+ throw new Error(
1381
+ "[better-json] Potential prototype pollution attempt detected"
1382
+ );
1383
+ }
1384
+ try {
1385
+ const secureReviver = (key, value2) => {
1386
+ if (key === "__proto__" || key === "constructor" && value2 && typeof value2 === "object" && "prototype" in value2) {
1387
+ if (warnings) {
1388
+ console.warn(
1389
+ `[better-json] Dropping "${key}" key to prevent prototype pollution`
1390
+ );
1391
+ }
1392
+ return void 0;
1393
+ }
1394
+ if (parseDates && typeof value2 === "string") {
1395
+ const date = parseISODate(value2);
1396
+ if (date) {
1397
+ return date;
1398
+ }
1399
+ }
1400
+ return reviver ? reviver(key, value2) : value2;
1401
+ };
1402
+ return JSON.parse(trimmed, secureReviver);
1403
+ } catch (error) {
1404
+ if (strict) {
1405
+ throw error;
1406
+ }
1407
+ return value;
1408
+ }
1409
+ }
1410
+ function parseJSON(value, options = { strict: true }) {
1411
+ return betterJSONParse(value, options);
1412
+ }
1413
+ const redirectPlugin = {
1414
+ id: "redirect",
1415
+ name: "Redirect",
1416
+ hooks: {
1417
+ onSuccess(context) {
1418
+ if (context.data?.url && context.data?.redirect) {
1419
+ if (typeof window !== "undefined" && window.location) {
1420
+ if (window.location) {
1421
+ try {
1422
+ window.location.href = context.data.url;
1423
+ } catch {
1424
+ }
1425
+ }
1426
+ }
1427
+ }
1428
+ }
1429
+ }
1430
+ };
1431
+ function getSessionAtom($fetch) {
1432
+ const $signal = distExports.atom(false);
1433
+ const session = useAuthQuery($signal, "/get-session", $fetch, {
1434
+ method: "GET"
1435
+ });
1436
+ return {
1437
+ session,
1438
+ $sessionSignal: $signal
1439
+ };
1440
+ }
1441
+ const getClientConfig = (options) => {
1442
+ const isCredentialsSupported = "credentials" in Request.prototype;
1443
+ const baseURL = getBaseURL(options?.baseURL, options?.basePath);
1444
+ const pluginsFetchPlugins = options?.plugins?.flatMap((plugin) => plugin.fetchPlugins).filter((pl) => pl !== void 0) || [];
1445
+ const lifeCyclePlugin = {
1446
+ id: "lifecycle-hooks",
1447
+ name: "lifecycle-hooks",
1448
+ hooks: {
1449
+ onSuccess: options?.fetchOptions?.onSuccess,
1450
+ onError: options?.fetchOptions?.onError,
1451
+ onRequest: options?.fetchOptions?.onRequest,
1452
+ onResponse: options?.fetchOptions?.onResponse
1453
+ }
1454
+ };
1455
+ const { onSuccess, onError, onRequest, onResponse, ...restOfFetchOptions } = options?.fetchOptions || {};
1456
+ const $fetch = createFetch({
1457
+ baseURL,
1458
+ ...isCredentialsSupported ? { credentials: "include" } : {},
1459
+ method: "GET",
1460
+ jsonParser(text) {
1461
+ if (!text) {
1462
+ return null;
1463
+ }
1464
+ return parseJSON(text, {
1465
+ strict: false
1466
+ });
1467
+ },
1468
+ customFetchImpl: async (input, init) => {
1469
+ try {
1470
+ return await fetch(input, init);
1471
+ } catch (error) {
1472
+ return Response.error();
1473
+ }
1474
+ },
1475
+ ...restOfFetchOptions,
1476
+ plugins: [
1477
+ lifeCyclePlugin,
1478
+ ...restOfFetchOptions.plugins || [],
1479
+ ...options?.disableDefaultFetchPlugins ? [] : [redirectPlugin],
1480
+ ...pluginsFetchPlugins
1481
+ ]
1482
+ });
1483
+ const { $sessionSignal, session } = getSessionAtom($fetch);
1484
+ const plugins = options?.plugins || [];
1485
+ let pluginsActions = {};
1486
+ let pluginsAtoms = {
1487
+ $sessionSignal,
1488
+ session
1489
+ };
1490
+ let pluginPathMethods = {
1491
+ "/sign-out": "POST",
1492
+ "/revoke-sessions": "POST",
1493
+ "/revoke-other-sessions": "POST",
1494
+ "/delete-user": "POST"
1495
+ };
1496
+ const atomListeners = [
1497
+ {
1498
+ signal: "$sessionSignal",
1499
+ matcher(path) {
1500
+ return path === "/sign-out" || path === "/update-user" || path.startsWith("/sign-in") || path.startsWith("/sign-up") || path === "/delete-user" || path === "/verify-email";
1501
+ }
1502
+ }
1503
+ ];
1504
+ for (const plugin of plugins) {
1505
+ if (plugin.getAtoms) {
1506
+ Object.assign(pluginsAtoms, plugin.getAtoms?.($fetch));
1507
+ }
1508
+ if (plugin.pathMethods) {
1509
+ Object.assign(pluginPathMethods, plugin.pathMethods);
1510
+ }
1511
+ if (plugin.atomListeners) {
1512
+ atomListeners.push(...plugin.atomListeners);
1513
+ }
1514
+ }
1515
+ const $store = {
1516
+ notify: (signal) => {
1517
+ pluginsAtoms[signal].set(
1518
+ !pluginsAtoms[signal].get()
1519
+ );
1520
+ },
1521
+ listen: (signal, listener) => {
1522
+ pluginsAtoms[signal].subscribe(listener);
1523
+ },
1524
+ atoms: pluginsAtoms
1525
+ };
1526
+ for (const plugin of plugins) {
1527
+ if (plugin.getActions) {
1528
+ Object.assign(
1529
+ pluginsActions,
1530
+ plugin.getActions?.($fetch, $store, options)
1531
+ );
1532
+ }
1533
+ }
1534
+ return {
1535
+ pluginsActions,
1536
+ pluginsAtoms,
1537
+ pluginPathMethods,
1538
+ atomListeners,
1539
+ $fetch,
1540
+ $store
1541
+ };
1542
+ };
1543
+ function getMethod(path, knownPathMethods, args) {
1544
+ const method = knownPathMethods[path];
1545
+ const { fetchOptions, query, ...body } = args || {};
1546
+ if (method) {
1547
+ return method;
1548
+ }
1549
+ if (fetchOptions?.method) {
1550
+ return fetchOptions.method;
1551
+ }
1552
+ if (body && Object.keys(body).length > 0) {
1553
+ return "POST";
1554
+ }
1555
+ return "GET";
1556
+ }
1557
+ function createDynamicPathProxy(routes, client, knownPathMethods, atoms, atomListeners) {
1558
+ function createProxy(path = []) {
1559
+ return new Proxy(function() {
1560
+ }, {
1561
+ get(target, prop) {
1562
+ const fullPath = [...path, prop];
1563
+ let current = routes;
1564
+ for (const segment of fullPath) {
1565
+ if (current && typeof current === "object" && segment in current) {
1566
+ current = current[segment];
1567
+ } else {
1568
+ current = void 0;
1569
+ break;
1570
+ }
1571
+ }
1572
+ if (typeof current === "function") {
1573
+ return current;
1574
+ }
1575
+ return createProxy(fullPath);
1576
+ },
1577
+ apply: async (_, __, args) => {
1578
+ const routePath = "/" + path.map(
1579
+ (segment) => segment.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)
1580
+ ).join("/");
1581
+ const arg = args[0] || {};
1582
+ const fetchOptions = args[1] || {};
1583
+ const { query, fetchOptions: argFetchOptions, ...body } = arg;
1584
+ const options = {
1585
+ ...fetchOptions,
1586
+ ...argFetchOptions
1587
+ };
1588
+ const method = getMethod(routePath, knownPathMethods, arg);
1589
+ return await client(routePath, {
1590
+ ...options,
1591
+ body: method === "GET" ? void 0 : {
1592
+ ...body,
1593
+ ...options?.body || {}
1594
+ },
1595
+ query: query || options?.query,
1596
+ method,
1597
+ async onSuccess(context) {
1598
+ await options?.onSuccess?.(context);
1599
+ const matches = atomListeners?.find((s) => s.matcher(routePath));
1600
+ if (!matches) return;
1601
+ const signal = atoms[matches.signal];
1602
+ if (!signal) return;
1603
+ const val = signal.get();
1604
+ setTimeout(() => {
1605
+ signal.set(!val);
1606
+ }, 10);
1607
+ }
1608
+ });
1609
+ }
1610
+ });
1611
+ }
1612
+ return createProxy();
1613
+ }
1614
+ function capitalizeFirstLetter(str) {
1615
+ return str.charAt(0).toUpperCase() + str.slice(1);
1616
+ }
1617
+ function createAuthClient(options) {
1618
+ const {
1619
+ pluginPathMethods,
1620
+ pluginsActions,
1621
+ pluginsAtoms,
1622
+ $fetch,
1623
+ atomListeners,
1624
+ $store
1625
+ } = getClientConfig(options);
1626
+ let resolvedHooks = {};
1627
+ for (const [key, value] of Object.entries(pluginsAtoms)) {
1628
+ resolvedHooks[`use${capitalizeFirstLetter(key)}`] = value;
1629
+ }
1630
+ const routes = {
1631
+ ...pluginsActions,
1632
+ ...resolvedHooks,
1633
+ $fetch,
1634
+ $store
1635
+ };
1636
+ const proxy = createDynamicPathProxy(
1637
+ routes,
1638
+ $fetch,
1639
+ pluginPathMethods,
1640
+ pluginsAtoms,
1641
+ atomListeners
1642
+ );
1643
+ return proxy;
1644
+ }
1645
+ const getAuthAPI = (intlayerConfig) => {
1646
+ const backendURL = intlayerConfig?.editor?.backendURL ?? configuration.editor?.backendURL;
1647
+ if (!backendURL) {
1648
+ throw new Error(
1649
+ "Backend URL is not defined in the Intlayer configuration."
1650
+ );
1651
+ }
1652
+ const getAuthClient = () => {
1653
+ return createAuthClient({
1654
+ baseURL: backendURL,
1655
+ withCredentials: true
1656
+ // makes fetch forward cookies
1657
+ });
1658
+ };
1659
+ const signInEmail = async (...args) => {
1660
+ const client = getAuthClient();
1661
+ return client.signIn.email(...args);
1662
+ };
1663
+ const signInSocial = async (...args) => {
1664
+ const client = getAuthClient();
1665
+ return client.signIn.social(...args);
1666
+ };
1667
+ const signUpEmail = async (...args) => {
1668
+ const client = getAuthClient();
1669
+ return client.signUp.email(...args);
1670
+ };
1671
+ const signOut = async (...args) => {
1672
+ const client = getAuthClient();
1673
+ return client.signOut(...args);
1674
+ };
1675
+ const changePasswordSession = async (...args) => {
1676
+ const client = getAuthClient();
1677
+ return client.changePassword(...args);
1678
+ };
1679
+ const requestPasswordResetSession = async (...args) => {
1680
+ const client = getAuthClient();
1681
+ return client.requestPasswordReset(...args);
1682
+ };
1683
+ const resetPassword = async (...args) => {
1684
+ const client = getAuthClient();
1685
+ return client.resetPassword(...args);
1686
+ };
1687
+ const verifyEmailSession = async (...args) => {
1688
+ const client = getAuthClient();
1689
+ return client.verifyEmail(...args);
1690
+ };
1691
+ const getSession = async (...args) => {
1692
+ const client = getAuthClient();
1693
+ return client.getSession(...args);
1694
+ };
1695
+ const forgetPassword = async (...args) => {
1696
+ const client = getAuthClient();
1697
+ return client.forgetPassword(...args);
1698
+ };
1699
+ const sendVerificationEmail = async (...args) => {
1700
+ const client = getAuthClient();
1701
+ return client.sendVerificationEmail(...args);
1702
+ };
1703
+ const changeEmail = async (...args) => {
1704
+ const client = getAuthClient();
1705
+ return client.changeEmail(...args);
1706
+ };
1707
+ const deleteUser = async (...args) => {
1708
+ const client = getAuthClient();
1709
+ return client.deleteUser(...args);
1710
+ };
1711
+ const revokeSession = async (...args) => {
1712
+ const client = getAuthClient();
1713
+ return client.revokeSession(...args);
1714
+ };
1715
+ const revokeSessions = async (...args) => {
1716
+ const client = getAuthClient();
1717
+ return client.revokeSessions(...args);
1718
+ };
1719
+ const revokeOtherSessions = async (...args) => {
1720
+ const client = getAuthClient();
1721
+ return client.revokeOtherSessions(...args);
1722
+ };
1723
+ const linkSocial = async (...args) => {
1724
+ const client = getAuthClient();
1725
+ return client.linkSocial(...args);
1726
+ };
1727
+ const listAccounts = async (...args) => {
1728
+ const client = getAuthClient();
1729
+ return client.listAccounts(...args);
1730
+ };
1731
+ const unlinkAccount = async (...args) => {
1732
+ const client = getAuthClient();
1733
+ return client.unlinkAccount(...args);
1734
+ };
1735
+ const refreshToken = async (...args) => {
1736
+ const client = getAuthClient();
1737
+ return client.refreshToken(...args);
1738
+ };
1739
+ const getAccessToken = async (...args) => {
1740
+ const client = getAuthClient();
1741
+ return client.getAccessToken(...args);
1742
+ };
1743
+ const accountInfo = async (...args) => {
1744
+ const client = getAuthClient();
1745
+ return client.accountInfo(...args);
1746
+ };
1747
+ const updateUser = async (...args) => {
1748
+ const client = getAuthClient();
1749
+ return client.updateUser(...args);
1750
+ };
1751
+ const listSessions = async (...args) => {
1752
+ const client = getAuthClient();
1753
+ return client.listSessions(...args);
1754
+ };
1755
+ return {
1756
+ signInEmail,
1757
+ signUpEmail,
1758
+ signOut,
1759
+ signInSocial,
1760
+ linkSocial,
1761
+ changePasswordSession,
1762
+ requestPasswordResetSession,
1763
+ resetPassword,
1764
+ verifyEmailSession,
1765
+ getSession,
1766
+ forgetPassword,
1767
+ sendVerificationEmail,
1768
+ changeEmail,
1769
+ deleteUser,
1770
+ revokeSession,
1771
+ revokeSessions,
1772
+ revokeOtherSessions,
1773
+ listAccounts,
1774
+ unlinkAccount,
1775
+ refreshToken,
1776
+ getAccessToken,
1777
+ accountInfo,
1778
+ updateUser,
1779
+ listSessions
1780
+ };
1781
+ };
1782
+ exports.getAuthAPI = getAuthAPI;
1783
+ //# sourceMappingURL=auth.cjs.map