@ollaid/native-sso 2.5.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/components/AvatarCropModal.d.ts +1 -1
  2. package/dist/components/DebugPanel.d.ts +1 -1
  3. package/dist/components/LoginModal.d.ts +1 -1
  4. package/dist/components/NativeSSOPage.d.ts +4 -2
  5. package/dist/components/OnboardingModal.d.ts +1 -1
  6. package/dist/components/PasswordRecoveryModal.d.ts +1 -1
  7. package/dist/components/SignupModal.d.ts +1 -1
  8. package/dist/components/ui.d.ts +1 -1
  9. package/dist/hooks/useLogout.d.ts +1 -1
  10. package/dist/hooks/useMobilePassword.d.ts +1 -1
  11. package/dist/hooks/useMobileRegistration.d.ts +2 -2
  12. package/dist/hooks/useNativeAuth.d.ts +8 -5
  13. package/dist/hooks/useTokenHealthCheck.d.ts +1 -1
  14. package/dist/index-Bpixveaz.js +489 -0
  15. package/dist/index-Bpixveaz.js.map +1 -0
  16. package/dist/index-DDOXM37y.cjs +488 -0
  17. package/dist/index-DDOXM37y.cjs.map +1 -0
  18. package/dist/index.cjs +7118 -184
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.ts +4 -3
  21. package/dist/index.js +7118 -184
  22. package/dist/index.js.map +1 -1
  23. package/dist/provider.d.ts +4 -1
  24. package/dist/services/api.d.ts +52 -10
  25. package/dist/services/debugLogger.d.ts +1 -1
  26. package/dist/services/iamAccount.d.ts +1 -1
  27. package/dist/services/mobilePassword.d.ts +1 -1
  28. package/dist/services/mobileRegistration.d.ts +1 -1
  29. package/dist/services/nativeAuth.d.ts +1 -1
  30. package/dist/services/profile.d.ts +1 -1
  31. package/dist/services/profileChange.d.ts +1 -1
  32. package/dist/services/profileMedia.d.ts +1 -1
  33. package/dist/types/mobile.d.ts +1 -1
  34. package/dist/types/native.d.ts +1 -1
  35. package/dist/web-BQDVoI6q.cjs +146 -0
  36. package/dist/web-BQDVoI6q.cjs.map +1 -0
  37. package/dist/web-DPmAPlXS.js +146 -0
  38. package/dist/web-DPmAPlXS.js.map +1 -0
  39. package/package.json +10 -3
  40. package/README.md +0 -2503
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Version réécrite from scratch pour éviter les états qui bloquent le bouton Valider.
5
5
  *
6
- * @version 2.5.0
6
+ * @version 2.7.0
7
7
  */
8
8
  export interface AvatarCropModalProps {
9
9
  open: boolean;
@@ -2,7 +2,7 @@
2
2
  * DebugPanel — Panneau de debug flottant pour @ollaid/native-sso
3
3
  * Affiche l'historique des appels API en temps réel (style terminal)
4
4
  * N'apparaît que quand debug=true
5
- * @version 2.5.0
5
+ * @version 2.7.0
6
6
  */
7
7
  export type DebugOnboardingPreset = 'current' | 'photo' | 'phone' | 'email' | 'all';
8
8
  interface DebugPanelProps {
@@ -2,7 +2,7 @@
2
2
  * Login Modal for @ollaid/native-sso
3
3
  * Complete login flow aligned with Native SSO design
4
4
  *
5
- * @version 2.5.0
5
+ * @version 2.7.0
6
6
  */
7
7
  import type { UserInfos } from '../types/native';
8
8
  export interface LoginModalProps {
@@ -2,9 +2,10 @@
2
2
  * NativeSSOPage — Page autonome complète pour @ollaid/native-sso
3
3
  * Design aligné sur le parcours Native SSO (fond primary, card blanche, ShieldCheck branding)
4
4
  *
5
- * @version 2.5.0
5
+ * @version 2.7.0
6
6
  */
7
7
  import type { UserInfos } from '../types/native';
8
+ import type { NativeStorageAdapter } from '../services/api';
8
9
  export interface NativeSSOPageProps {
9
10
  saasApiUrl: string;
10
11
  iamApiUrl: string;
@@ -29,6 +30,7 @@ export interface NativeSSOPageProps {
29
30
  hideFooter?: boolean;
30
31
  redirectAfterLogin?: string;
31
32
  redirectAfterLogout?: string;
33
+ storage?: NativeStorageAdapter;
32
34
  }
33
- export declare function NativeSSOPage({ saasApiUrl, iamApiUrl, onLoginSuccess, onLogout, onOnboardingComplete, accountType, configPrefix, title, description, logoUrl, hideFooter, redirectAfterLogin, redirectAfterLogout, }: NativeSSOPageProps): import("react/jsx-runtime").JSX.Element;
35
+ export declare function NativeSSOPage({ saasApiUrl, iamApiUrl, onLoginSuccess, onLogout, onOnboardingComplete, accountType, configPrefix, title, description, logoUrl, hideFooter, redirectAfterLogin, redirectAfterLogout, storage, }: NativeSSOPageProps): import("react/jsx-runtime").JSX.Element;
34
36
  export default NativeSSOPage;
@@ -3,7 +3,7 @@
3
3
  * Mode `missing` : champs absents uniquement
4
4
  * Mode `edit` : édition complète du profil depuis le SaaS
5
5
  *
6
- * @version 2.5.0
6
+ * @version 2.7.0
7
7
  */
8
8
  import type { NativeUser, UserInfos } from '../types/native';
9
9
  export interface OnboardingModalProps {
@@ -3,7 +3,7 @@
3
3
  * Flow: email → method-choice → OTP → new password → success
4
4
  * Design aligned with web SSO
5
5
  *
6
- * @version 2.5.0
6
+ * @version 2.7.0
7
7
  */
8
8
  export interface PasswordRecoveryModalProps {
9
9
  open: boolean;
@@ -2,7 +2,7 @@
2
2
  * Signup Modal for @ollaid/native-sso — Design aligned with web SSO
3
3
  * Full signup flow: intro → account-type → info → OTP → password → confirm → success
4
4
  *
5
- * @version 2.5.0
5
+ * @version 2.7.0
6
6
  */
7
7
  import type { UserInfos } from '../types/native';
8
8
  export interface SignupModalProps {
@@ -3,7 +3,7 @@
3
3
  * Lightweight replacements for shadcn/ui components + inline SVG icons
4
4
  * No external dependencies required
5
5
  *
6
- * @version 2.5.0
6
+ * @version 2.7.0
7
7
  */
8
8
  import React from 'react';
9
9
  export declare function IconShieldCheck(props: React.SVGProps<SVGSVGElement>): import("react/jsx-runtime").JSX.Element;
@@ -22,7 +22,7 @@
22
22
  * };
23
23
  * ```
24
24
  *
25
- * @version 2.5.0
25
+ * @version 2.7.0
26
26
  */
27
27
  export interface UseLogoutOptions {
28
28
  /** Callback appelé après une déconnexion réussie (redirection, toast, etc.) */
@@ -2,7 +2,7 @@
2
2
  * Hook de récupération de mot de passe v1.0
3
3
  * Architecture Frontend-First avec appels directs à l'IAM
4
4
  *
5
- * @version 2.5.0
5
+ * @version 2.7.0
6
6
  */
7
7
  export interface UseMobilePasswordOptions {
8
8
  saasApiUrl: string;
@@ -2,7 +2,7 @@
2
2
  * Hook d'inscription Mobile SSO v1.0
3
3
  * Gère le flow: init → verify-otp → complete
4
4
  *
5
- * @version 2.5.0
5
+ * @version 2.7.0
6
6
  */
7
7
  import type { MobileRegistrationFormData, AccountType } from '../types/mobile';
8
8
  interface RegistrationConflict {
@@ -41,7 +41,7 @@ export declare function useMobileRegistration(options?: UseMobileRegistrationOpt
41
41
  error_type?: undefined;
42
42
  } | {
43
43
  success: boolean;
44
- error_type: any;
44
+ error_type: string | undefined;
45
45
  otp_code_dev?: undefined;
46
46
  otp_method?: undefined;
47
47
  otp_sent_to?: undefined;
@@ -2,8 +2,9 @@
2
2
  * Hook d'authentification Native SSO v1.0
3
3
  * Architecture Frontend-First avec appels directs à l'IAM
4
4
  *
5
- * @version 2.5.0
5
+ * @version 2.7.0
6
6
  */
7
+ import { type NativeStorageAdapter } from '../services/api';
7
8
  import type { NativeAuthStatus, NativeExchangeResponse, AccountType } from '../types/native';
8
9
  export interface UseNativeAuthOptions {
9
10
  /** URL du Backend SaaS */
@@ -19,6 +20,8 @@ export interface UseNativeAuthOptions {
19
20
  * Permet le multi-tenant dynamique : 'iam', 'iam_vendor', 'iam_client', etc.
20
21
  */
21
22
  configPrefix?: string;
23
+ /** Stockage injecté pour les apps natives / Capacitor */
24
+ storage?: NativeStorageAdapter;
22
25
  }
23
26
  export declare function useNativeAuth(options: UseNativeAuthOptions): {
24
27
  credentialsLoaded: boolean;
@@ -126,7 +129,7 @@ export declare function useNativeAuth(options: UseNativeAuthOptions): {
126
129
  success: boolean;
127
130
  user: {
128
131
  iam_reference: string;
129
- alias_reference: any;
132
+ alias_reference: string;
130
133
  id?: number;
131
134
  reference: string;
132
135
  name: string;
@@ -181,7 +184,7 @@ export declare function useNativeAuth(options: UseNativeAuthOptions): {
181
184
  success: boolean;
182
185
  user: {
183
186
  iam_reference: string;
184
- alias_reference: any;
187
+ alias_reference: string;
185
188
  id?: number;
186
189
  reference: string;
187
190
  name: string;
@@ -223,7 +226,7 @@ export declare function useNativeAuth(options: UseNativeAuthOptions): {
223
226
  success: boolean;
224
227
  user: {
225
228
  iam_reference: string;
226
- alias_reference: any;
229
+ alias_reference: string;
227
230
  id?: number;
228
231
  reference: string;
229
232
  name: string;
@@ -255,7 +258,7 @@ export declare function useNativeAuth(options: UseNativeAuthOptions): {
255
258
  success: boolean;
256
259
  user: {
257
260
  iam_reference: string;
258
- alias_reference: any;
261
+ alias_reference: string;
259
262
  id?: number;
260
263
  reference: string;
261
264
  name: string;
@@ -10,7 +10,7 @@
10
10
  * - Si 401 → révoque l'IAM (POST /iam/disconnect) + nettoie le frontend
11
11
  * - Ne déconnecte PAS si offline ou serveur inaccessible
12
12
  *
13
- * @version 2.5.0
13
+ * @version 2.7.0
14
14
  */
15
15
  import type { UserInfos } from '../types/native';
16
16
  export interface UseTokenHealthCheckOptions {
@@ -0,0 +1,489 @@
1
+ /*! Capacitor: https://capacitorjs.com/ - MIT License */
2
+ var ExceptionCode;
3
+ (function(ExceptionCode2) {
4
+ ExceptionCode2["Unimplemented"] = "UNIMPLEMENTED";
5
+ ExceptionCode2["Unavailable"] = "UNAVAILABLE";
6
+ })(ExceptionCode || (ExceptionCode = {}));
7
+ class CapacitorException extends Error {
8
+ constructor(message, code, data) {
9
+ super(message);
10
+ this.message = message;
11
+ this.code = code;
12
+ this.data = data;
13
+ }
14
+ }
15
+ const getPlatformId = (win) => {
16
+ var _a, _b;
17
+ if (win === null || win === void 0 ? void 0 : win.androidBridge) {
18
+ return "android";
19
+ } else if ((_b = (_a = win === null || win === void 0 ? void 0 : win.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.bridge) {
20
+ return "ios";
21
+ } else {
22
+ return "web";
23
+ }
24
+ };
25
+ const createCapacitor = (win) => {
26
+ const capCustomPlatform = win.CapacitorCustomPlatform || null;
27
+ const cap = win.Capacitor || {};
28
+ const Plugins = cap.Plugins = cap.Plugins || {};
29
+ const getPlatform = () => {
30
+ return capCustomPlatform !== null ? capCustomPlatform.name : getPlatformId(win);
31
+ };
32
+ const isNativePlatform = () => getPlatform() !== "web";
33
+ const isPluginAvailable = (pluginName) => {
34
+ const plugin = registeredPlugins.get(pluginName);
35
+ if (plugin === null || plugin === void 0 ? void 0 : plugin.platforms.has(getPlatform())) {
36
+ return true;
37
+ }
38
+ if (getPluginHeader(pluginName)) {
39
+ return true;
40
+ }
41
+ return false;
42
+ };
43
+ const getPluginHeader = (pluginName) => {
44
+ var _a;
45
+ return (_a = cap.PluginHeaders) === null || _a === void 0 ? void 0 : _a.find((h) => h.name === pluginName);
46
+ };
47
+ const handleError = (err) => win.console.error(err);
48
+ const registeredPlugins = /* @__PURE__ */ new Map();
49
+ const registerPlugin2 = (pluginName, jsImplementations = {}) => {
50
+ const registeredPlugin = registeredPlugins.get(pluginName);
51
+ if (registeredPlugin) {
52
+ console.warn(`Capacitor plugin "${pluginName}" already registered. Cannot register plugins twice.`);
53
+ return registeredPlugin.proxy;
54
+ }
55
+ const platform = getPlatform();
56
+ const pluginHeader = getPluginHeader(pluginName);
57
+ let jsImplementation;
58
+ const loadPluginImplementation = async () => {
59
+ if (!jsImplementation && platform in jsImplementations) {
60
+ jsImplementation = typeof jsImplementations[platform] === "function" ? jsImplementation = await jsImplementations[platform]() : jsImplementation = jsImplementations[platform];
61
+ } else if (capCustomPlatform !== null && !jsImplementation && "web" in jsImplementations) {
62
+ jsImplementation = typeof jsImplementations["web"] === "function" ? jsImplementation = await jsImplementations["web"]() : jsImplementation = jsImplementations["web"];
63
+ }
64
+ return jsImplementation;
65
+ };
66
+ const createPluginMethod = (impl, prop) => {
67
+ var _a, _b;
68
+ if (pluginHeader) {
69
+ const methodHeader = pluginHeader === null || pluginHeader === void 0 ? void 0 : pluginHeader.methods.find((m) => prop === m.name);
70
+ if (methodHeader) {
71
+ if (methodHeader.rtype === "promise") {
72
+ return (options) => cap.nativePromise(pluginName, prop.toString(), options);
73
+ } else {
74
+ return (options, callback) => cap.nativeCallback(pluginName, prop.toString(), options, callback);
75
+ }
76
+ } else if (impl) {
77
+ return (_a = impl[prop]) === null || _a === void 0 ? void 0 : _a.bind(impl);
78
+ }
79
+ } else if (impl) {
80
+ return (_b = impl[prop]) === null || _b === void 0 ? void 0 : _b.bind(impl);
81
+ } else {
82
+ throw new CapacitorException(`"${pluginName}" plugin is not implemented on ${platform}`, ExceptionCode.Unimplemented);
83
+ }
84
+ };
85
+ const createPluginMethodWrapper = (prop) => {
86
+ let remove;
87
+ const wrapper = (...args) => {
88
+ const p = loadPluginImplementation().then((impl) => {
89
+ const fn = createPluginMethod(impl, prop);
90
+ if (fn) {
91
+ const p2 = fn(...args);
92
+ remove = p2 === null || p2 === void 0 ? void 0 : p2.remove;
93
+ return p2;
94
+ } else {
95
+ throw new CapacitorException(`"${pluginName}.${prop}()" is not implemented on ${platform}`, ExceptionCode.Unimplemented);
96
+ }
97
+ });
98
+ if (prop === "addListener") {
99
+ p.remove = async () => remove();
100
+ }
101
+ return p;
102
+ };
103
+ wrapper.toString = () => `${prop.toString()}() { [capacitor code] }`;
104
+ Object.defineProperty(wrapper, "name", {
105
+ value: prop,
106
+ writable: false,
107
+ configurable: false
108
+ });
109
+ return wrapper;
110
+ };
111
+ const addListener = createPluginMethodWrapper("addListener");
112
+ const removeListener = createPluginMethodWrapper("removeListener");
113
+ const addListenerNative = (eventName, callback) => {
114
+ const call = addListener({ eventName }, callback);
115
+ const remove = async () => {
116
+ const callbackId = await call;
117
+ removeListener({
118
+ eventName,
119
+ callbackId
120
+ }, callback);
121
+ };
122
+ const p = new Promise((resolve) => call.then(() => resolve({ remove })));
123
+ p.remove = async () => {
124
+ console.warn(`Using addListener() without 'await' is deprecated.`);
125
+ await remove();
126
+ };
127
+ return p;
128
+ };
129
+ const proxy = new Proxy({}, {
130
+ get(_, prop) {
131
+ switch (prop) {
132
+ case "$$typeof":
133
+ return void 0;
134
+ case "toJSON":
135
+ return () => ({});
136
+ case "addListener":
137
+ return pluginHeader ? addListenerNative : addListener;
138
+ case "removeListener":
139
+ return removeListener;
140
+ default:
141
+ return createPluginMethodWrapper(prop);
142
+ }
143
+ }
144
+ });
145
+ Plugins[pluginName] = proxy;
146
+ registeredPlugins.set(pluginName, {
147
+ name: pluginName,
148
+ proxy,
149
+ platforms: /* @__PURE__ */ new Set([...Object.keys(jsImplementations), ...pluginHeader ? [platform] : []])
150
+ });
151
+ return proxy;
152
+ };
153
+ if (!cap.convertFileSrc) {
154
+ cap.convertFileSrc = (filePath) => filePath;
155
+ }
156
+ cap.getPlatform = getPlatform;
157
+ cap.handleError = handleError;
158
+ cap.isNativePlatform = isNativePlatform;
159
+ cap.isPluginAvailable = isPluginAvailable;
160
+ cap.registerPlugin = registerPlugin2;
161
+ cap.Exception = CapacitorException;
162
+ cap.DEBUG = !!cap.DEBUG;
163
+ cap.isLoggingEnabled = !!cap.isLoggingEnabled;
164
+ return cap;
165
+ };
166
+ const initCapacitorGlobal = (win) => win.Capacitor = createCapacitor(win);
167
+ const Capacitor = /* @__PURE__ */ initCapacitorGlobal(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {});
168
+ const registerPlugin = Capacitor.registerPlugin;
169
+ class WebPlugin {
170
+ constructor() {
171
+ this.listeners = {};
172
+ this.retainedEventArguments = {};
173
+ this.windowListeners = {};
174
+ }
175
+ addListener(eventName, listenerFunc) {
176
+ let firstListener = false;
177
+ const listeners = this.listeners[eventName];
178
+ if (!listeners) {
179
+ this.listeners[eventName] = [];
180
+ firstListener = true;
181
+ }
182
+ this.listeners[eventName].push(listenerFunc);
183
+ const windowListener = this.windowListeners[eventName];
184
+ if (windowListener && !windowListener.registered) {
185
+ this.addWindowListener(windowListener);
186
+ }
187
+ if (firstListener) {
188
+ this.sendRetainedArgumentsForEvent(eventName);
189
+ }
190
+ const remove = async () => this.removeListener(eventName, listenerFunc);
191
+ const p = Promise.resolve({ remove });
192
+ return p;
193
+ }
194
+ async removeAllListeners() {
195
+ this.listeners = {};
196
+ for (const listener in this.windowListeners) {
197
+ this.removeWindowListener(this.windowListeners[listener]);
198
+ }
199
+ this.windowListeners = {};
200
+ }
201
+ notifyListeners(eventName, data, retainUntilConsumed) {
202
+ const listeners = this.listeners[eventName];
203
+ if (!listeners) {
204
+ if (retainUntilConsumed) {
205
+ let args = this.retainedEventArguments[eventName];
206
+ if (!args) {
207
+ args = [];
208
+ }
209
+ args.push(data);
210
+ this.retainedEventArguments[eventName] = args;
211
+ }
212
+ return;
213
+ }
214
+ listeners.forEach((listener) => listener(data));
215
+ }
216
+ hasListeners(eventName) {
217
+ var _a;
218
+ return !!((_a = this.listeners[eventName]) === null || _a === void 0 ? void 0 : _a.length);
219
+ }
220
+ registerWindowListener(windowEventName, pluginEventName) {
221
+ this.windowListeners[pluginEventName] = {
222
+ registered: false,
223
+ windowEventName,
224
+ pluginEventName,
225
+ handler: (event) => {
226
+ this.notifyListeners(pluginEventName, event);
227
+ }
228
+ };
229
+ }
230
+ unimplemented(msg = "not implemented") {
231
+ return new Capacitor.Exception(msg, ExceptionCode.Unimplemented);
232
+ }
233
+ unavailable(msg = "not available") {
234
+ return new Capacitor.Exception(msg, ExceptionCode.Unavailable);
235
+ }
236
+ async removeListener(eventName, listenerFunc) {
237
+ const listeners = this.listeners[eventName];
238
+ if (!listeners) {
239
+ return;
240
+ }
241
+ const index2 = listeners.indexOf(listenerFunc);
242
+ this.listeners[eventName].splice(index2, 1);
243
+ if (!this.listeners[eventName].length) {
244
+ this.removeWindowListener(this.windowListeners[eventName]);
245
+ }
246
+ }
247
+ addWindowListener(handle) {
248
+ window.addEventListener(handle.windowEventName, handle.handler);
249
+ handle.registered = true;
250
+ }
251
+ removeWindowListener(handle) {
252
+ if (!handle) {
253
+ return;
254
+ }
255
+ window.removeEventListener(handle.windowEventName, handle.handler);
256
+ handle.registered = false;
257
+ }
258
+ sendRetainedArgumentsForEvent(eventName) {
259
+ const args = this.retainedEventArguments[eventName];
260
+ if (!args) {
261
+ return;
262
+ }
263
+ delete this.retainedEventArguments[eventName];
264
+ args.forEach((arg) => {
265
+ this.notifyListeners(eventName, arg);
266
+ });
267
+ }
268
+ }
269
+ const encode = (str) => encodeURIComponent(str).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
270
+ const decode = (str) => str.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
271
+ class CapacitorCookiesPluginWeb extends WebPlugin {
272
+ async getCookies() {
273
+ const cookies = document.cookie;
274
+ const cookieMap = {};
275
+ cookies.split(";").forEach((cookie) => {
276
+ if (cookie.length <= 0)
277
+ return;
278
+ let [key, value] = cookie.replace(/=/, "CAP_COOKIE").split("CAP_COOKIE");
279
+ key = decode(key).trim();
280
+ value = decode(value).trim();
281
+ cookieMap[key] = value;
282
+ });
283
+ return cookieMap;
284
+ }
285
+ async setCookie(options) {
286
+ try {
287
+ const encodedKey = encode(options.key);
288
+ const encodedValue = encode(options.value);
289
+ const expires = `; expires=${(options.expires || "").replace("expires=", "")}`;
290
+ const path = (options.path || "/").replace("path=", "");
291
+ const domain = options.url != null && options.url.length > 0 ? `domain=${options.url}` : "";
292
+ document.cookie = `${encodedKey}=${encodedValue || ""}${expires}; path=${path}; ${domain};`;
293
+ } catch (error) {
294
+ return Promise.reject(error);
295
+ }
296
+ }
297
+ async deleteCookie(options) {
298
+ try {
299
+ document.cookie = `${options.key}=; Max-Age=0`;
300
+ } catch (error) {
301
+ return Promise.reject(error);
302
+ }
303
+ }
304
+ async clearCookies() {
305
+ try {
306
+ const cookies = document.cookie.split(";") || [];
307
+ for (const cookie of cookies) {
308
+ document.cookie = cookie.replace(/^ +/, "").replace(/=.*/, `=;expires=${(/* @__PURE__ */ new Date()).toUTCString()};path=/`);
309
+ }
310
+ } catch (error) {
311
+ return Promise.reject(error);
312
+ }
313
+ }
314
+ async clearAllCookies() {
315
+ try {
316
+ await this.clearCookies();
317
+ } catch (error) {
318
+ return Promise.reject(error);
319
+ }
320
+ }
321
+ }
322
+ registerPlugin("CapacitorCookies", {
323
+ web: () => new CapacitorCookiesPluginWeb()
324
+ });
325
+ const readBlobAsBase64 = async (blob) => new Promise((resolve, reject) => {
326
+ const reader = new FileReader();
327
+ reader.onload = () => {
328
+ const base64String = reader.result;
329
+ resolve(base64String.indexOf(",") >= 0 ? base64String.split(",")[1] : base64String);
330
+ };
331
+ reader.onerror = (error) => reject(error);
332
+ reader.readAsDataURL(blob);
333
+ });
334
+ const normalizeHttpHeaders = (headers = {}) => {
335
+ const originalKeys = Object.keys(headers);
336
+ const loweredKeys = Object.keys(headers).map((k) => k.toLocaleLowerCase());
337
+ const normalized = loweredKeys.reduce((acc, key, index2) => {
338
+ acc[key] = headers[originalKeys[index2]];
339
+ return acc;
340
+ }, {});
341
+ return normalized;
342
+ };
343
+ const buildUrlParams = (params, shouldEncode = true) => {
344
+ if (!params)
345
+ return null;
346
+ const output = Object.entries(params).reduce((accumulator, entry) => {
347
+ const [key, value] = entry;
348
+ let encodedValue;
349
+ let item;
350
+ if (Array.isArray(value)) {
351
+ item = "";
352
+ value.forEach((str) => {
353
+ encodedValue = shouldEncode ? encodeURIComponent(str) : str;
354
+ item += `${key}=${encodedValue}&`;
355
+ });
356
+ item.slice(0, -1);
357
+ } else {
358
+ encodedValue = shouldEncode ? encodeURIComponent(value) : value;
359
+ item = `${key}=${encodedValue}`;
360
+ }
361
+ return `${accumulator}&${item}`;
362
+ }, "");
363
+ return output.substr(1);
364
+ };
365
+ const buildRequestInit = (options, extra = {}) => {
366
+ const output = Object.assign({ method: options.method || "GET", headers: options.headers }, extra);
367
+ const headers = normalizeHttpHeaders(options.headers);
368
+ const type = headers["content-type"] || "";
369
+ if (typeof options.data === "string") {
370
+ output.body = options.data;
371
+ } else if (type.includes("application/x-www-form-urlencoded")) {
372
+ const params = new URLSearchParams();
373
+ for (const [key, value] of Object.entries(options.data || {})) {
374
+ params.set(key, value);
375
+ }
376
+ output.body = params.toString();
377
+ } else if (type.includes("multipart/form-data") || options.data instanceof FormData) {
378
+ const form = new FormData();
379
+ if (options.data instanceof FormData) {
380
+ options.data.forEach((value, key) => {
381
+ form.append(key, value);
382
+ });
383
+ } else {
384
+ for (const key of Object.keys(options.data)) {
385
+ form.append(key, options.data[key]);
386
+ }
387
+ }
388
+ output.body = form;
389
+ const headers2 = new Headers(output.headers);
390
+ headers2.delete("content-type");
391
+ output.headers = headers2;
392
+ } else if (type.includes("application/json") || typeof options.data === "object") {
393
+ output.body = JSON.stringify(options.data);
394
+ }
395
+ return output;
396
+ };
397
+ class CapacitorHttpPluginWeb extends WebPlugin {
398
+ /**
399
+ * Perform an Http request given a set of options
400
+ * @param options Options to build the HTTP request
401
+ */
402
+ async request(options) {
403
+ const requestInit = buildRequestInit(options, options.webFetchExtra);
404
+ const urlParams = buildUrlParams(options.params, options.shouldEncodeUrlParams);
405
+ const url = urlParams ? `${options.url}?${urlParams}` : options.url;
406
+ const response = await fetch(url, requestInit);
407
+ const contentType = response.headers.get("content-type") || "";
408
+ let { responseType = "text" } = response.ok ? options : {};
409
+ if (contentType.includes("application/json")) {
410
+ responseType = "json";
411
+ }
412
+ let data;
413
+ let blob;
414
+ switch (responseType) {
415
+ case "arraybuffer":
416
+ case "blob":
417
+ blob = await response.blob();
418
+ data = await readBlobAsBase64(blob);
419
+ break;
420
+ case "json":
421
+ data = await response.json();
422
+ break;
423
+ case "document":
424
+ case "text":
425
+ default:
426
+ data = await response.text();
427
+ }
428
+ const headers = {};
429
+ response.headers.forEach((value, key) => {
430
+ headers[key] = value;
431
+ });
432
+ return {
433
+ data,
434
+ headers,
435
+ status: response.status,
436
+ url: response.url
437
+ };
438
+ }
439
+ /**
440
+ * Perform an Http GET request given a set of options
441
+ * @param options Options to build the HTTP request
442
+ */
443
+ async get(options) {
444
+ return this.request(Object.assign(Object.assign({}, options), { method: "GET" }));
445
+ }
446
+ /**
447
+ * Perform an Http POST request given a set of options
448
+ * @param options Options to build the HTTP request
449
+ */
450
+ async post(options) {
451
+ return this.request(Object.assign(Object.assign({}, options), { method: "POST" }));
452
+ }
453
+ /**
454
+ * Perform an Http PUT request given a set of options
455
+ * @param options Options to build the HTTP request
456
+ */
457
+ async put(options) {
458
+ return this.request(Object.assign(Object.assign({}, options), { method: "PUT" }));
459
+ }
460
+ /**
461
+ * Perform an Http PATCH request given a set of options
462
+ * @param options Options to build the HTTP request
463
+ */
464
+ async patch(options) {
465
+ return this.request(Object.assign(Object.assign({}, options), { method: "PATCH" }));
466
+ }
467
+ /**
468
+ * Perform an Http DELETE request given a set of options
469
+ * @param options Options to build the HTTP request
470
+ */
471
+ async delete(options) {
472
+ return this.request(Object.assign(Object.assign({}, options), { method: "DELETE" }));
473
+ }
474
+ }
475
+ registerPlugin("CapacitorHttp", {
476
+ web: () => new CapacitorHttpPluginWeb()
477
+ });
478
+ const Device = registerPlugin("Device", {
479
+ web: () => import("./web-DPmAPlXS.js").then((m) => new m.DeviceWeb())
480
+ });
481
+ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
482
+ __proto__: null,
483
+ Device
484
+ }, Symbol.toStringTag, { value: "Module" }));
485
+ export {
486
+ WebPlugin as W,
487
+ index as i
488
+ };
489
+ //# sourceMappingURL=index-Bpixveaz.js.map