@nemme/js-sdk 0.6.1 → 0.6.2
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.
- package/README.md +13 -46
- package/dist/browser.d.ts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/deliveries/delivery-manager.d.ts +2 -3
- package/dist/forms/form-manager.d.ts +10 -1
- package/dist/index.cjs +11 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +6750 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/nemme-sdk.umd.js +4 -4
- package/dist/nemme-sdk.umd.js.map +1 -1
- package/package.json +7 -32
- package/dist/chunks/client-BPx3v4ob.js +0 -389
- package/dist/chunks/client-BPx3v4ob.js.map +0 -1
- package/dist/chunks/client-DVvy_lUY.js +0 -2
- package/dist/chunks/client-DVvy_lUY.js.map +0 -1
- package/dist/chunks/form-manager-CH-LT8Ck.js +0 -6143
- package/dist/chunks/form-manager-CH-LT8Ck.js.map +0 -1
- package/dist/chunks/form-manager-DSnwY9Sd.js +0 -12
- package/dist/chunks/form-manager-DSnwY9Sd.js.map +0 -1
- package/dist/chunks/httpClient-D2IO92uv.js +0 -149
- package/dist/chunks/httpClient-D2IO92uv.js.map +0 -1
- package/dist/chunks/httpClient-hrn9Ffa2.js +0 -2
- package/dist/chunks/httpClient-hrn9Ffa2.js.map +0 -1
- package/dist/forms-entry.d.ts +0 -3
- package/dist/forms.cjs +0 -2
- package/dist/forms.cjs.map +0 -1
- package/dist/forms.esm.js +0 -6
- package/dist/forms.esm.js.map +0 -1
- package/dist/react-entry.d.ts +0 -3
- package/dist/react.cjs +0 -2
- package/dist/react.cjs.map +0 -1
- package/dist/react.esm.js +0 -67
- package/dist/react.esm.js.map +0 -1
- package/dist/style-entry.d.ts +0 -0
- package/dist/style.cjs +0 -2
- package/dist/style.cjs.map +0 -1
- package/dist/style.esm.js +0 -2
- package/dist/style.esm.js.map +0 -1
- package/dist/types/forms.d.ts +0 -10
- /package/dist/{js-sdk.css → assets/js-sdk.css} +0 -0
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
const T = {
|
|
2
|
-
apiBaseUrl: "https://api.nemme.io",
|
|
3
|
-
debug: !1
|
|
4
|
-
}, p = {
|
|
5
|
-
debug: 0,
|
|
6
|
-
info: 1,
|
|
7
|
-
warn: 2,
|
|
8
|
-
error: 3
|
|
9
|
-
};
|
|
10
|
-
class h {
|
|
11
|
-
prefix;
|
|
12
|
-
enabled;
|
|
13
|
-
level;
|
|
14
|
-
constructor(e = {}) {
|
|
15
|
-
this.prefix = e.prefix || "Nemme SDK", this.enabled = e.enabled !== void 0 ? e.enabled : !0, this.level = e.level || "info";
|
|
16
|
-
}
|
|
17
|
-
shouldLog(e) {
|
|
18
|
-
return this.enabled && p[e] >= p[this.level];
|
|
19
|
-
}
|
|
20
|
-
formatMessage(e) {
|
|
21
|
-
return `[${this.prefix}] ${e}`;
|
|
22
|
-
}
|
|
23
|
-
debug(e, ...t) {
|
|
24
|
-
this.shouldLog("debug") && console.debug(this.formatMessage(e), ...t);
|
|
25
|
-
}
|
|
26
|
-
info(e, ...t) {
|
|
27
|
-
this.shouldLog("info") && console.info(this.formatMessage(e), ...t);
|
|
28
|
-
}
|
|
29
|
-
warn(e, ...t) {
|
|
30
|
-
this.shouldLog("warn") && console.warn(this.formatMessage(e), ...t);
|
|
31
|
-
}
|
|
32
|
-
error(e, ...t) {
|
|
33
|
-
this.shouldLog("error") && console.error(this.formatMessage(e), ...t);
|
|
34
|
-
}
|
|
35
|
-
// Create a child logger with a new prefix
|
|
36
|
-
child(e) {
|
|
37
|
-
return new h({
|
|
38
|
-
prefix: `${this.prefix}:${e}`,
|
|
39
|
-
enabled: this.enabled,
|
|
40
|
-
level: this.level
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
// Configure logger settings
|
|
44
|
-
configure(e) {
|
|
45
|
-
e.prefix !== void 0 && (this.prefix = e.prefix), e.enabled !== void 0 && (this.enabled = e.enabled), e.level !== void 0 && (this.level = e.level);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
const w = new h(), m = w.child("network"), v = 3e4, E = (r, e) => {
|
|
49
|
-
const t = new URL(r, T.apiBaseUrl);
|
|
50
|
-
return e && Object.entries(e).forEach(([d, i]) => {
|
|
51
|
-
i != null && t.searchParams.append(d, String(i));
|
|
52
|
-
}), t.toString();
|
|
53
|
-
}, L = {
|
|
54
|
-
/**
|
|
55
|
-
* Make an HTTP request
|
|
56
|
-
*/
|
|
57
|
-
async request(r, e = {}) {
|
|
58
|
-
const { method: t = "GET", headers: d = {}, body: i, params: b, timeout: u = v } = e, c = E(r, b), y = {
|
|
59
|
-
"Content-Type": "application/json",
|
|
60
|
-
Accept: "application/json",
|
|
61
|
-
...d
|
|
62
|
-
}, f = {
|
|
63
|
-
method: t,
|
|
64
|
-
headers: y,
|
|
65
|
-
body: i ? JSON.stringify(i) : void 0
|
|
66
|
-
}, g = new AbortController(), x = setTimeout(() => g.abort(), u);
|
|
67
|
-
f.signal = g.signal;
|
|
68
|
-
try {
|
|
69
|
-
const s = await fetch(c, f);
|
|
70
|
-
let o;
|
|
71
|
-
const a = s.headers.get("content-type");
|
|
72
|
-
if (a && a.includes("application/json"))
|
|
73
|
-
o = await s.json();
|
|
74
|
-
else {
|
|
75
|
-
const l = await s.text();
|
|
76
|
-
try {
|
|
77
|
-
o = JSON.parse(l);
|
|
78
|
-
} catch {
|
|
79
|
-
o = l;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
const n = {
|
|
83
|
-
data: o,
|
|
84
|
-
status: s.status,
|
|
85
|
-
statusText: s.statusText,
|
|
86
|
-
headers: s.headers,
|
|
87
|
-
ok: s.ok
|
|
88
|
-
};
|
|
89
|
-
if (s.ok)
|
|
90
|
-
n.ok = !0;
|
|
91
|
-
else {
|
|
92
|
-
const l = `Request failed with status ${s.status}: ${s.statusText}`;
|
|
93
|
-
m.error(l, {
|
|
94
|
-
url: c,
|
|
95
|
-
method: t,
|
|
96
|
-
status: s.status,
|
|
97
|
-
data: n.data
|
|
98
|
-
}), n.ok = !1, n.error = {
|
|
99
|
-
message: l,
|
|
100
|
-
details: n.data
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
return n;
|
|
104
|
-
} catch (s) {
|
|
105
|
-
let o = "Network request failed", a = {};
|
|
106
|
-
return s instanceof DOMException && s.name === "AbortError" ? (o = `Request timeout after ${u}ms`, a = { timeout: u, url: c }) : a = {
|
|
107
|
-
message: s instanceof Error ? s.message : String(s),
|
|
108
|
-
url: c,
|
|
109
|
-
method: t
|
|
110
|
-
}, m.error(o, a), {
|
|
111
|
-
data: {},
|
|
112
|
-
status: 0,
|
|
113
|
-
statusText: o,
|
|
114
|
-
headers: new Headers(),
|
|
115
|
-
ok: !1,
|
|
116
|
-
error: {
|
|
117
|
-
message: o,
|
|
118
|
-
details: a
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
} finally {
|
|
122
|
-
clearTimeout(x);
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
/**
|
|
126
|
-
* Convenience methods for common HTTP methods
|
|
127
|
-
*/
|
|
128
|
-
async get(r, e = {}) {
|
|
129
|
-
return this.request(r, { ...e, method: "GET" });
|
|
130
|
-
},
|
|
131
|
-
async post(r, e, t = {}) {
|
|
132
|
-
return this.request(r, { ...t, method: "POST", body: e });
|
|
133
|
-
},
|
|
134
|
-
async put(r, e, t = {}) {
|
|
135
|
-
return this.request(r, { ...t, method: "PUT", body: e });
|
|
136
|
-
},
|
|
137
|
-
async patch(r, e, t = {}) {
|
|
138
|
-
return this.request(r, { ...t, method: "PATCH", body: e });
|
|
139
|
-
},
|
|
140
|
-
async delete(r, e = {}) {
|
|
141
|
-
return this.request(r, { ...e, method: "DELETE" });
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
export {
|
|
145
|
-
T as c,
|
|
146
|
-
L as h,
|
|
147
|
-
w as l
|
|
148
|
-
};
|
|
149
|
-
//# sourceMappingURL=httpClient-D2IO92uv.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"httpClient-D2IO92uv.js","sources":["../../src/config.ts","../../src/utils/logger.ts","../../src/networking/httpClient.ts"],"sourcesContent":["export const config = {\n apiBaseUrl: import.meta.env['VITE_API_BASE_URL'],\n debug: import.meta.env.DEV\n};\n","/**\n * Logger utility for the SDK\n * Provides consistent logging across the SDK with different log levels\n */\n\nexport type LogLevel = 'debug' | 'info' | 'warn' | 'error';\n\ninterface LoggerOptions {\n prefix?: string;\n enabled?: boolean;\n level?: LogLevel;\n}\n\nconst LOG_LEVELS: Record<LogLevel, number> = {\n debug: 0,\n info: 1,\n warn: 2,\n error: 3\n};\n\nexport class Logger {\n private prefix: string;\n private enabled: boolean;\n private level: LogLevel;\n\n constructor(options: LoggerOptions = {}) {\n this.prefix = options.prefix || 'Nemme SDK';\n this.enabled = options.enabled !== undefined ? options.enabled : true;\n this.level = options.level || 'info';\n }\n\n private shouldLog(level: LogLevel): boolean {\n return this.enabled && LOG_LEVELS[level] >= LOG_LEVELS[this.level];\n }\n\n private formatMessage(message: string): string {\n return `[${this.prefix}] ${message}`;\n }\n\n debug(message: string, ...args: unknown[]): void {\n if (this.shouldLog('debug')) {\n console.debug(this.formatMessage(message), ...args);\n }\n }\n\n info(message: string, ...args: unknown[]): void {\n if (this.shouldLog('info')) {\n console.info(this.formatMessage(message), ...args);\n }\n }\n\n warn(message: string, ...args: unknown[]): void {\n if (this.shouldLog('warn')) {\n console.warn(this.formatMessage(message), ...args);\n }\n }\n\n error(message: string, ...args: unknown[]): void {\n if (this.shouldLog('error')) {\n console.error(this.formatMessage(message), ...args);\n }\n }\n\n // Create a child logger with a new prefix\n child(prefix: string): Logger {\n return new Logger({\n prefix: `${this.prefix}:${prefix}`,\n enabled: this.enabled,\n level: this.level\n });\n }\n\n // Configure logger settings\n configure(options: LoggerOptions): void {\n if (options.prefix !== undefined) {\n this.prefix = options.prefix;\n }\n if (options.enabled !== undefined) {\n this.enabled = options.enabled;\n }\n if (options.level !== undefined) {\n this.level = options.level;\n }\n }\n}\n\n// Create and export a default logger instance\nexport const logger = new Logger();\n","import { config } from '../config';\nimport { logger } from '../utils';\n\n// Create a network-specific logger\nconst networkLogger = logger.child('network');\n\nexport type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n\nexport interface RequestOptions {\n method?: HttpMethod;\n headers?: Record<string, string>;\n body?: unknown;\n params?: Record<string, string | number | boolean>;\n timeout?: number;\n}\n\nexport interface HttpResponse<T = unknown> {\n data: T;\n status: number;\n statusText: string;\n headers: Headers;\n ok: boolean;\n error?: {\n message: string;\n details?: unknown;\n };\n}\n\nconst DEFAULT_TIMEOUT = 30000; // 30 seconds\n\n/**\n * Creates a URL with query parameters\n */\nconst createUrl = (endpoint: string, params?: Record<string, string | number | boolean>): string => {\n const url = new URL(endpoint, config.apiBaseUrl);\n\n if (params) {\n Object.entries(params).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n url.searchParams.append(key, String(value));\n }\n });\n }\n\n return url.toString();\n};\n\n/**\n * Global HTTP client for making API requests\n */\nexport const httpClient = {\n /**\n * Make an HTTP request\n */\n async request<T = unknown>(endpoint: string, options: RequestOptions = {}): Promise<HttpResponse<T>> {\n const { method = 'GET', headers = {}, body, params, timeout = DEFAULT_TIMEOUT } = options;\n\n const url = createUrl(endpoint, params);\n\n // Prepare headers with defaults\n const requestHeaders: Record<string, string> = {\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n ...headers\n };\n\n // Prepare request options\n const requestOptions: RequestInit = {\n method,\n headers: requestHeaders,\n body: body ? JSON.stringify(body) : undefined\n };\n\n // Create abort controller for timeout\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), timeout);\n requestOptions.signal = controller.signal;\n\n try {\n const response = await fetch(url, requestOptions);\n\n // Parse response data\n let data: T;\n const contentType = response.headers.get('content-type');\n\n if (contentType && contentType.includes('application/json')) {\n data = await response.json();\n } else {\n const text = await response.text();\n try {\n data = JSON.parse(text) as T;\n } catch {\n data = text as unknown as T;\n }\n }\n\n const result: HttpResponse<T> = {\n data,\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n ok: response.ok\n };\n\n // Handle error responses but don't throw\n if (!response.ok) {\n const errorMessage = `Request failed with status ${response.status}: ${response.statusText}`;\n networkLogger.error(errorMessage, {\n url,\n method,\n status: response.status,\n data: result.data\n });\n\n result.ok = false;\n result.error = {\n message: errorMessage,\n details: result.data\n };\n } else {\n result.ok = true;\n }\n\n return result;\n } catch (error) {\n // Log the error but don't throw\n let errorMessage = 'Network request failed';\n let errorDetails = {};\n\n if (error instanceof DOMException && error.name === 'AbortError') {\n errorMessage = `Request timeout after ${timeout}ms`;\n errorDetails = { timeout, url };\n } else {\n errorDetails = {\n message: error instanceof Error ? error.message : String(error),\n url,\n method\n };\n }\n\n networkLogger.error(errorMessage, errorDetails);\n\n // Return an error response instead of throwing\n const errorResponse: HttpResponse<T> = {\n data: {} as T,\n status: 0,\n statusText: errorMessage,\n headers: new Headers(),\n ok: false,\n error: {\n message: errorMessage,\n details: errorDetails\n }\n };\n\n return errorResponse;\n } finally {\n clearTimeout(timeoutId);\n }\n },\n\n /**\n * Convenience methods for common HTTP methods\n */\n async get<T = unknown>(endpoint: string, options: Omit<RequestOptions, 'method'> = {}): Promise<HttpResponse<T>> {\n return this.request<T>(endpoint, { ...options, method: 'GET' });\n },\n\n async post<T = unknown>(\n endpoint: string,\n data?: unknown,\n options: Omit<RequestOptions, 'method' | 'body'> = {}\n ): Promise<HttpResponse<T>> {\n return this.request<T>(endpoint, { ...options, method: 'POST', body: data });\n },\n\n async put<T = unknown>(\n endpoint: string,\n data?: unknown,\n options: Omit<RequestOptions, 'method' | 'body'> = {}\n ): Promise<HttpResponse<T>> {\n return this.request<T>(endpoint, { ...options, method: 'PUT', body: data });\n },\n\n async patch<T = unknown>(\n endpoint: string,\n data?: unknown,\n options: Omit<RequestOptions, 'method' | 'body'> = {}\n ): Promise<HttpResponse<T>> {\n return this.request<T>(endpoint, { ...options, method: 'PATCH', body: data });\n },\n\n async delete<T = unknown>(endpoint: string, options: Omit<RequestOptions, 'method'> = {}): Promise<HttpResponse<T>> {\n return this.request<T>(endpoint, { ...options, method: 'DELETE' });\n }\n};\n"],"names":["config","LOG_LEVELS","Logger","options","level","message","args","prefix","logger","networkLogger","DEFAULT_TIMEOUT","createUrl","endpoint","params","url","key","value","httpClient","method","headers","body","timeout","requestHeaders","requestOptions","controller","timeoutId","response","data","contentType","text","result","errorMessage","error","errorDetails"],"mappings":"AAAO,MAAMA,IAAS;AAAA,EACpB,YAAY;AAAA,EACZ,OAAO;AACT,GCUMC,IAAuC;AAAA,EAC3C,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AACT;AAEO,MAAMC,EAAO;AAAA,EACV;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAYC,IAAyB,IAAI;AACvC,SAAK,SAASA,EAAQ,UAAU,aAChC,KAAK,UAAUA,EAAQ,YAAY,SAAYA,EAAQ,UAAU,IACjE,KAAK,QAAQA,EAAQ,SAAS;AAAA,EAChC;AAAA,EAEQ,UAAUC,GAA0B;AAC1C,WAAO,KAAK,WAAWH,EAAWG,CAAK,KAAKH,EAAW,KAAK,KAAK;AAAA,EACnE;AAAA,EAEQ,cAAcI,GAAyB;AAC7C,WAAO,IAAI,KAAK,MAAM,KAAKA,CAAO;AAAA,EACpC;AAAA,EAEA,MAAMA,MAAoBC,GAAuB;AAC/C,IAAI,KAAK,UAAU,OAAO,KACxB,QAAQ,MAAM,KAAK,cAAcD,CAAO,GAAG,GAAGC,CAAI;AAAA,EAEtD;AAAA,EAEA,KAAKD,MAAoBC,GAAuB;AAC9C,IAAI,KAAK,UAAU,MAAM,KACvB,QAAQ,KAAK,KAAK,cAAcD,CAAO,GAAG,GAAGC,CAAI;AAAA,EAErD;AAAA,EAEA,KAAKD,M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GAAU,EAAE,GAAGT,GAAS,QAAQ,UAAU;AAAA,EACnE;AACF;"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const b={apiBaseUrl:"https://api.nemme.io",debug:!1},p={debug:0,info:1,warn:2,error:3};class h{prefix;enabled;level;constructor(e={}){this.prefix=e.prefix||"Nemme SDK",this.enabled=e.enabled!==void 0?e.enabled:!0,this.level=e.level||"info"}shouldLog(e){return this.enabled&&p[e]>=p[this.level]}formatMessage(e){return`[${this.prefix}] ${e}`}debug(e,...t){this.shouldLog("debug")&&console.debug(this.formatMessage(e),...t)}info(e,...t){this.shouldLog("info")&&console.info(this.formatMessage(e),...t)}warn(e,...t){this.shouldLog("warn")&&console.warn(this.formatMessage(e),...t)}error(e,...t){this.shouldLog("error")&&console.error(this.formatMessage(e),...t)}child(e){return new h({prefix:`${this.prefix}:${e}`,enabled:this.enabled,level:this.level})}configure(e){e.prefix!==void 0&&(this.prefix=e.prefix),e.enabled!==void 0&&(this.enabled=e.enabled),e.level!==void 0&&(this.level=e.level)}}const y=new h,m=y.child("network"),v=3e4,E=(r,e)=>{const t=new URL(r,b.apiBaseUrl);return e&&Object.entries(e).forEach(([d,i])=>{i!=null&&t.searchParams.append(d,String(i))}),t.toString()},L={async request(r,e={}){const{method:t="GET",headers:d={},body:i,params:T,timeout:u=v}=e,c=E(r,T),w={"Content-Type":"application/json",Accept:"application/json",...d},f={method:t,headers:w,body:i?JSON.stringify(i):void 0},g=new AbortController,x=setTimeout(()=>g.abort(),u);f.signal=g.signal;try{const s=await fetch(c,f);let o;const a=s.headers.get("content-type");if(a&&a.includes("application/json"))o=await s.json();else{const l=await s.text();try{o=JSON.parse(l)}catch{o=l}}const n={data:o,status:s.status,statusText:s.statusText,headers:s.headers,ok:s.ok};if(s.ok)n.ok=!0;else{const l=`Request failed with status ${s.status}: ${s.statusText}`;m.error(l,{url:c,method:t,status:s.status,data:n.data}),n.ok=!1,n.error={message:l,details:n.data}}return n}catch(s){let o="Network request failed",a={};return s instanceof DOMException&&s.name==="AbortError"?(o=`Request timeout after ${u}ms`,a={timeout:u,url:c}):a={message:s instanceof Error?s.message:String(s),url:c,method:t},m.error(o,a),{data:{},status:0,statusText:o,headers:new Headers,ok:!1,error:{message:o,details:a}}}finally{clearTimeout(x)}},async get(r,e={}){return this.request(r,{...e,method:"GET"})},async post(r,e,t={}){return this.request(r,{...t,method:"POST",body:e})},async put(r,e,t={}){return this.request(r,{...t,method:"PUT",body:e})},async patch(r,e,t={}){return this.request(r,{...t,method:"PATCH",body:e})},async delete(r,e={}){return this.request(r,{...e,method:"DELETE"})}};exports.config=b;exports.httpClient=L;exports.logger=y;
|
|
2
|
-
//# sourceMappingURL=httpClient-hrn9Ffa2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"httpClient-hrn9Ffa2.js","sources":["../../src/config.ts","../../src/utils/logger.ts","../../src/networking/httpClient.ts"],"sourcesContent":["export const config = {\n apiBaseUrl: import.meta.env['VITE_API_BASE_URL'],\n debug: import.meta.env.DEV\n};\n","/**\n * Logger utility for the SDK\n * Provides consistent logging across the SDK with different log levels\n */\n\nexport type LogLevel = 'debug' | 'info' | 'warn' | 'error';\n\ninterface LoggerOptions {\n prefix?: string;\n enabled?: boolean;\n level?: LogLevel;\n}\n\nconst LOG_LEVELS: Record<LogLevel, number> = {\n debug: 0,\n info: 1,\n warn: 2,\n error: 3\n};\n\nexport class Logger {\n private prefix: string;\n private enabled: boolean;\n private level: LogLevel;\n\n constructor(options: LoggerOptions = {}) {\n this.prefix = options.prefix || 'Nemme SDK';\n this.enabled = options.enabled !== undefined ? options.enabled : true;\n this.level = options.level || 'info';\n }\n\n private shouldLog(level: LogLevel): boolean {\n return this.enabled && LOG_LEVELS[level] >= LOG_LEVELS[this.level];\n }\n\n private formatMessage(message: string): string {\n return `[${this.prefix}] ${message}`;\n }\n\n debug(message: string, ...args: unknown[]): void {\n if (this.shouldLog('debug')) {\n console.debug(this.formatMessage(message), ...args);\n }\n }\n\n info(message: string, ...args: unknown[]): void {\n if (this.shouldLog('info')) {\n console.info(this.formatMessage(message), ...args);\n }\n }\n\n warn(message: string, ...args: unknown[]): void {\n if (this.shouldLog('warn')) {\n console.warn(this.formatMessage(message), ...args);\n }\n }\n\n error(message: string, ...args: unknown[]): void {\n if (this.shouldLog('error')) {\n console.error(this.formatMessage(message), ...args);\n }\n }\n\n // Create a child logger with a new prefix\n child(prefix: string): Logger {\n return new Logger({\n prefix: `${this.prefix}:${prefix}`,\n enabled: this.enabled,\n level: this.level\n });\n }\n\n // Configure logger settings\n configure(options: LoggerOptions): void {\n if (options.prefix !== undefined) {\n this.prefix = options.prefix;\n }\n if (options.enabled !== undefined) {\n this.enabled = options.enabled;\n }\n if (options.level !== undefined) {\n this.level = options.level;\n }\n }\n}\n\n// Create and export a default logger instance\nexport const logger = new Logger();\n","import { config } from '../config';\nimport { logger } from '../utils';\n\n// Create a network-specific logger\nconst networkLogger = logger.child('network');\n\nexport type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n\nexport interface RequestOptions {\n method?: HttpMethod;\n headers?: Record<string, string>;\n body?: unknown;\n params?: Record<string, string | number | boolean>;\n timeout?: number;\n}\n\nexport interface HttpResponse<T = unknown> {\n data: T;\n status: number;\n statusText: string;\n headers: Headers;\n ok: boolean;\n error?: {\n message: string;\n details?: unknown;\n };\n}\n\nconst DEFAULT_TIMEOUT = 30000; // 30 seconds\n\n/**\n * Creates a URL with query parameters\n */\nconst createUrl = (endpoint: string, params?: Record<string, string | number | boolean>): string => {\n const url = new URL(endpoint, config.apiBaseUrl);\n\n if (params) {\n Object.entries(params).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n url.searchParams.append(key, String(value));\n }\n });\n }\n\n return url.toString();\n};\n\n/**\n * Global HTTP client for making API requests\n */\nexport const httpClient = {\n /**\n * Make an HTTP request\n */\n async request<T = unknown>(endpoint: string, options: RequestOptions = {}): Promise<HttpResponse<T>> {\n const { method = 'GET', headers = {}, body, params, timeout = DEFAULT_TIMEOUT } = options;\n\n const url = createUrl(endpoint, params);\n\n // Prepare headers with defaults\n const requestHeaders: Record<string, string> = {\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n ...headers\n };\n\n // Prepare request options\n const requestOptions: RequestInit = {\n method,\n headers: requestHeaders,\n body: body ? JSON.stringify(body) : undefined\n };\n\n // Create abort controller for timeout\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), timeout);\n requestOptions.signal = controller.signal;\n\n try {\n const response = await fetch(url, requestOptions);\n\n // Parse response data\n let data: T;\n const contentType = response.headers.get('content-type');\n\n if (contentType && contentType.includes('application/json')) {\n data = await response.json();\n } else {\n const text = await response.text();\n try {\n data = JSON.parse(text) as T;\n } catch {\n data = text as unknown as T;\n }\n }\n\n const result: HttpResponse<T> = {\n data,\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n ok: response.ok\n };\n\n // Handle error responses but don't throw\n if (!response.ok) {\n const errorMessage = `Request failed with status ${response.status}: ${response.statusText}`;\n networkLogger.error(errorMessage, {\n url,\n method,\n status: response.status,\n data: result.data\n });\n\n result.ok = false;\n result.error = {\n message: errorMessage,\n details: result.data\n };\n } else {\n result.ok = true;\n }\n\n return result;\n } catch (error) {\n // Log the error but don't throw\n let errorMessage = 'Network request failed';\n let errorDetails = {};\n\n if (error instanceof DOMException && error.name === 'AbortError') {\n errorMessage = `Request timeout after ${timeout}ms`;\n errorDetails = { timeout, url };\n } else {\n errorDetails = {\n message: error instanceof Error ? error.message : String(error),\n url,\n method\n };\n }\n\n networkLogger.error(errorMessage, errorDetails);\n\n // Return an error response instead of throwing\n const errorResponse: HttpResponse<T> = {\n data: {} as T,\n status: 0,\n statusText: errorMessage,\n headers: new Headers(),\n ok: false,\n error: {\n message: errorMessage,\n details: errorDetails\n }\n };\n\n return errorResponse;\n } finally {\n clearTimeout(timeoutId);\n }\n },\n\n /**\n * Convenience methods for common HTTP methods\n */\n async get<T = unknown>(endpoint: string, options: Omit<RequestOptions, 'method'> = {}): Promise<HttpResponse<T>> {\n return this.request<T>(endpoint, { ...options, method: 'GET' });\n },\n\n async post<T = unknown>(\n endpoint: string,\n data?: unknown,\n options: Omit<RequestOptions, 'method' | 'body'> = {}\n ): Promise<HttpResponse<T>> {\n return this.request<T>(endpoint, { ...options, method: 'POST', body: data });\n },\n\n async put<T = unknown>(\n endpoint: string,\n data?: unknown,\n options: Omit<RequestOptions, 'method' | 'body'> = {}\n ): Promise<HttpResponse<T>> {\n return this.request<T>(endpoint, { ...options, method: 'PUT', body: data });\n },\n\n async patch<T = unknown>(\n endpoint: string,\n data?: unknown,\n options: Omit<RequestOptions, 'method' | 'body'> = {}\n ): Promise<HttpResponse<T>> {\n return this.request<T>(endpoint, { ...options, method: 'PATCH', body: data });\n },\n\n async delete<T = unknown>(endpoint: string, options: Omit<RequestOptions, 'method'> = {}): Promise<HttpResponse<T>> {\n return this.request<T>(endpoint, { ...options, method: 'DELETE' });\n }\n};\n"],"names":["config","LOG_LEVELS","Logger","options","level","message","args","prefix","logger","networkLogger","DEFAULT_TIMEOUT","createUrl","endpoint","params","url","key","value","httpClient","method","headers","body","timeout","requestHeaders","requestOptions","controller","timeoutId","response","data","contentType","text","result","errorMessage","error","errorDetails"],"mappings":"aAAO,MAAMA,EAAS,CACpB,WAAY,uBACZ,MAAO,EACT,ECUMC,EAAuC,CAC3C,MAAO,EACP,KAAM,EACN,KAAM,EACN,MAAO,CACT,EAEO,MAAMC,CAAO,CACV,OACA,QACA,MAER,YAAYC,EAAyB,GAAI,CACvC,KAAK,OAASA,EAAQ,QAAU,YAChC,KAAK,QAAUA,EAAQ,UAAY,OAAYA,EAAQ,QAAU,GACjE,KAAK,MAAQA,EAAQ,OAAS,MAChC,CAEQ,UAAUC,EAA0B,CAC1C,OAAO,KAAK,SAAWH,EAAWG,CAAK,GAAKH,EAAW,KAAK,KAAK,CACnE,CAEQ,cAAcI,EAAyB,CAC7C,MAAO,IAAI,KAAK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ClDD,EAAe,yBAAyBV,CAAO,KAC/CY,EAAe,CAAE,QAAAZ,EAAS,IAAAP,CAAA,GAE1BmB,EAAe,CACb,QAASD,aAAiB,MAAQA,EAAM,QAAU,OAAOA,CAAK,EAC9D,IAAAlB,EACA,OAAAI,CAAA,EAIJT,EAAc,MAAMsB,EAAcE,CAAY,EAGP,CACrC,KAAM,CAAA,EACN,OAAQ,EACR,WAAYF,EACZ,QAAS,IAAI,QACb,GAAI,GACJ,MAAO,CACL,QAASA,EACT,QAASE,CAAA,CACX,CAIJ,QAAA,CACE,aAAaR,CAAS,CACxB,CACF,EAKA,MAAM,IAAiBb,EAAkBT,EAA0C,GAA8B,CAC/G,OAAO,KAAK,QAAWS,EAAU,CAAE,GAAGT,EAAS,OAAQ,MAAO,CAChE,EAEA,MAAM,KACJS,EACAe,EACAxB,EAAmD,CAAA,EACzB,CAC1B,OAAO,KAAK,QAAWS,EAAU,CAAE,GAAGT,EAAS,OAAQ,OAAQ,KAAMwB,EAAM,CAC7E,EAEA,MAAM,IACJf,EACAe,EACAxB,EAAmD,CAAA,EACzB,CAC1B,OAAO,KAAK,QAAWS,EAAU,CAAE,GAAGT,EAAS,OAAQ,MAAO,KAAMwB,EAAM,CAC5E,EAEA,MAAM,MACJf,EACAe,EACAxB,EAAmD,CAAA,EACzB,CAC1B,OAAO,KAAK,QAAWS,EAAU,CAAE,GAAGT,EAAS,OAAQ,QAAS,KAAMwB,EAAM,CAC9E,EAEA,MAAM,OAAoBf,EAAkBT,EAA0C,GAA8B,CAClH,OAAO,KAAK,QAAWS,EAAU,CAAE,GAAGT,EAAS,OAAQ,SAAU,CACnE,CACF"}
|
package/dist/forms-entry.d.ts
DELETED
package/dist/forms.cjs
DELETED
package/dist/forms.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"forms.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/forms.esm.js
DELETED
package/dist/forms.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"forms.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/dist/react-entry.d.ts
DELETED
package/dist/react.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("react/jsx-runtime"),r=require("react"),w=require("./chunks/client-DVvy_lUY.js"),d=r.createContext(void 0),y=({clientKey:e,config:n,children:s})=>{const[l,i]=r.useState(null),[o,a]=r.useState(!1),[C,c]=r.useState(null);r.useEffect(()=>{let u=null,m=!1;const x=async()=>{try{const t=new w.NemmeClient(e);if(await t.init(n),m){t.destroy();return}u=t,i(t),a(t.initialized),c(t.lastInitError?t.lastInitError.message:null)}catch(t){m||(c(t instanceof Error?t.message:"Failed to initialize Nemme client"),a(!1))}},v=setTimeout(()=>{i(null),a(!1),c(null)},0);return x(),()=>{clearTimeout(v),m=!0,u&&u.destroy()}},[e,n]);const N={client:l,isInitialized:o,error:C};return z.jsx(d.Provider,{value:N,children:s})},f=()=>{const e=r.useContext(d);if(e===void 0)throw new Error("useNemmeContext must be used within a NemmeProvider");return e},I=()=>{const{client:e,isInitialized:n,error:s}=f(),l=r.useCallback(async o=>{if(!e||!n){console.warn("Nemme client not initialized");return}return e.track(o)},[e,n]),i=r.useCallback(async()=>{if(!e||!n){console.warn("Nemme client not initialized");return}return e.flush()},[e,n]);return{track:l,flush:i,isInitialized:n,error:s,client:e}};exports.NemmeProvider=y;exports.useNemme=I;exports.useNemmeContext=f;
|
|
2
|
-
//# sourceMappingURL=react.cjs.map
|
package/dist/react.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"react.cjs","sources":["../src/react/context.ts","../src/react/NemmeProvider.tsx","../src/react/useNemmeContext.ts","../src/react/useNemme.ts"],"sourcesContent":["import { createContext } from 'react';\nimport { NemmeClient } from '../client';\n\nexport interface NemmeContextType {\n client: NemmeClient | null;\n isInitialized: boolean;\n error: string | null;\n}\n\nexport const NemmeContext = createContext<NemmeContextType | undefined>(undefined);\n","import * as React from 'react';\nimport { useEffect, useState } from 'react';\nimport { ClientConfigType, NemmeClient } from '../client';\nimport { NemmeContext, NemmeContextType } from './context';\n\ninterface NemmeProviderProps {\n clientKey: string;\n config: ClientConfigType;\n children: React.ReactNode;\n}\n\nexport const NemmeProvider: React.FC<NemmeProviderProps> = ({ clientKey, config, children }) => {\n const [client, setClient] = useState<NemmeClient | null>(null);\n const [isInitialized, setIsInitialized] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n useEffect(() => {\n let currentClient: NemmeClient | null = null;\n let isCancelled = false;\n\n const initializeClient = async () => {\n try {\n const nemmeClient = new NemmeClient(clientKey);\n await nemmeClient.init(config);\n\n // Check if effect was cancelled during async operation\n if (isCancelled) {\n nemmeClient.destroy();\n return;\n }\n\n currentClient = nemmeClient;\n setClient(nemmeClient);\n setIsInitialized(nemmeClient.initialized);\n setError(nemmeClient.lastInitError ? nemmeClient.lastInitError.message : null);\n } catch (err) {\n if (!isCancelled) {\n setError(err instanceof Error ? err.message : 'Failed to initialize Nemme client');\n setIsInitialized(false);\n }\n }\n };\n\n // Reset state when starting new initialization (deferred to avoid sync setState in effect)\n const resetId = setTimeout(() => {\n setClient(null);\n setIsInitialized(false);\n setError(null);\n }, 0);\n\n initializeClient();\n\n return () => {\n clearTimeout(resetId);\n isCancelled = true;\n if (currentClient) {\n currentClient.destroy();\n }\n };\n }, [clientKey, config]);\n\n const value: NemmeContextType = {\n client,\n isInitialized,\n error\n };\n\n return <NemmeContext.Provider value={value}>{children}</NemmeContext.Provider>;\n};\n","import { useContext } from 'react';\nimport { NemmeContext } from './context';\n\nexport const useNemmeContext = () => {\n const context = useContext(NemmeContext);\n if (context === undefined) {\n throw new Error('useNemmeContext must be used within a NemmeProvider');\n }\n return context;\n};\n","import { useCallback } from 'react';\nimport { useNemmeContext } from './useNemmeContext';\nimport { TrackEventOptions } from '../client';\n\nexport const useNemme = () => {\n const { client, isInitialized, error } = useNemmeContext();\n\n const track = useCallback(\n async <T extends TrackEventOptions>(options: T) => {\n if (!client || !isInitialized) {\n console.warn('Nemme client not initialized');\n return;\n }\n return client.track(options);\n },\n [client, isInitialized]\n );\n\n const flush = useCallback(async () => {\n if (!client || !isInitialized) {\n console.warn('Nemme client not initialized');\n return;\n }\n return client.flush();\n }, [client, isInitialized]);\n\n return {\n track,\n flush,\n isInitialized,\n error,\n client\n };\n};\n"],"names":["NemmeContext","createContext","NemmeProvider","clientKey","config","children","client","setClient","useState","isInitialized","setIsInitialized","error","setError","useEffect","currentClient","isCancelled","initializeClient","nemmeClient","NemmeClient","err","resetId","value","jsx","useNemmeContext","context","useContext","useNemme","track","useCallback","options","flush"],"mappings":"iLASaA,EAAeC,EAAAA,cAA4C,MAAS,ECEpEC,EAA8C,CAAC,CAAE,UAAAC,EAAW,OAAAC,EAAQ,SAAAC,KAAe,CAC9F,KAAM,CAACC,EAAQC,CAAS,EAAIC,EAAAA,SAA6B,IAAI,EACvD,CAACC,EAAeC,CAAgB,EAAIF,EAAAA,SAAS,EAAK,EAClD,CAACG,EAAOC,CAAQ,EAAIJ,EAAAA,SAAwB,IAAI,EAEtDK,EAAAA,UAAU,IAAM,CACd,IAAIC,EAAoC,KACpCC,EAAc,GAElB,MAAMC,EAAmB,SAAY,CACnC,GAAI,CACF,MAAMC,EAAc,IAAIC,EAAAA,YAAYf,CAAS,EAI7C,GAHA,MAAMc,EAAY,KAAKb,CAAM,EAGzBW,EAAa,CACfE,EAAY,QAAA,EACZ,MACF,CAEAH,EAAgBG,EAChBV,EAAUU,CAAW,EACrBP,EAAiBO,EAAY,WAAW,EACxCL,EAASK,EAAY,cAAgBA,EAAY,cAAc,QAAU,IAAI,CAC/E,OAASE,EAAK,CACPJ,IACHH,EAASO,aAAe,MAAQA,EAAI,QAAU,mCAAmC,EACjFT,EAAiB,EAAK,EAE1B,CACF,EAGMU,EAAU,WAAW,IAAM,CAC/Bb,EAAU,IAAI,EACdG,EAAiB,EAAK,EACtBE,EAAS,IAAI,CACf,EAAG,CAAC,EAEJ,OAAAI,EAAA,EAEO,IAAM,CACX,aAAaI,CAAO,EACpBL,EAAc,GACVD,GACFA,EAAc,QAAA,CAElB,CACF,EAAG,CAACX,EAAWC,CAAM,CAAC,EAEtB,MAAMiB,EAA0B,CAAA,OAC9Bf,EACA,cAAAG,EACA,MAAAE,CAAA,EAGF,OAAOW,EAAAA,IAACtB,EAAa,SAAb,CAAsB,MAAAqB,EAAe,SAAAhB,CAAA,CAAS,CACxD,ECjEakB,EAAkB,IAAM,CACnC,MAAMC,EAAUC,EAAAA,WAAWzB,CAAY,EACvC,GAAIwB,IAAY,OACd,MAAM,IAAI,MAAM,qDAAqD,EAEvE,OAAOA,CACT,ECLaE,EAAW,IAAM,CAC5B,KAAM,CAAE,OAAApB,EAAQ,cAAAG,EAAe,MAAAE,CAAA,EAAUY,EAAA,EAEnCI,EAAQC,EAAAA,YACZ,MAAoCC,GAAe,CACjD,GAAI,CAACvB,GAAU,CAACG,EAAe,CAC7B,QAAQ,KAAK,8BAA8B,EAC3C,MACF,CACA,OAAOH,EAAO,MAAMuB,CAAO,CAC7B,EACA,CAACvB,EAAQG,CAAa,CAAA,EAGlBqB,EAAQF,EAAAA,YAAY,SAAY,CACpC,GAAI,CAACtB,GAAU,CAACG,EAAe,CAC7B,QAAQ,KAAK,8BAA8B,EAC3C,MACF,CACA,OAAOH,EAAO,MAAA,CAChB,EAAG,CAACA,EAAQG,CAAa,CAAC,EAE1B,MAAO,CACL,MAAAkB,EACA,MAAAG,EACA,cAAArB,EACA,MAAAE,EACA,OAAAL,CAAA,CAEJ"}
|
package/dist/react.esm.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { jsx as w } from "react/jsx-runtime";
|
|
2
|
-
import { createContext as I, useState as u, useEffect as v, useContext as E, useCallback as d } from "react";
|
|
3
|
-
import { N as h } from "./chunks/client-BPx3v4ob.js";
|
|
4
|
-
const f = I(void 0), b = ({ clientKey: e, config: n, children: i }) => {
|
|
5
|
-
const [s, r] = u(null), [o, l] = u(!1), [C, a] = u(null);
|
|
6
|
-
v(() => {
|
|
7
|
-
let c = null, m = !1;
|
|
8
|
-
const x = async () => {
|
|
9
|
-
try {
|
|
10
|
-
const t = new h(e);
|
|
11
|
-
if (await t.init(n), m) {
|
|
12
|
-
t.destroy();
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
c = t, r(t), l(t.initialized), a(t.lastInitError ? t.lastInitError.message : null);
|
|
16
|
-
} catch (t) {
|
|
17
|
-
m || (a(t instanceof Error ? t.message : "Failed to initialize Nemme client"), l(!1));
|
|
18
|
-
}
|
|
19
|
-
}, z = setTimeout(() => {
|
|
20
|
-
r(null), l(!1), a(null);
|
|
21
|
-
}, 0);
|
|
22
|
-
return x(), () => {
|
|
23
|
-
clearTimeout(z), m = !0, c && c.destroy();
|
|
24
|
-
};
|
|
25
|
-
}, [e, n]);
|
|
26
|
-
const N = {
|
|
27
|
-
client: s,
|
|
28
|
-
isInitialized: o,
|
|
29
|
-
error: C
|
|
30
|
-
};
|
|
31
|
-
return /* @__PURE__ */ w(f.Provider, { value: N, children: i });
|
|
32
|
-
}, y = () => {
|
|
33
|
-
const e = E(f);
|
|
34
|
-
if (e === void 0)
|
|
35
|
-
throw new Error("useNemmeContext must be used within a NemmeProvider");
|
|
36
|
-
return e;
|
|
37
|
-
}, T = () => {
|
|
38
|
-
const { client: e, isInitialized: n, error: i } = y(), s = d(
|
|
39
|
-
async (o) => {
|
|
40
|
-
if (!e || !n) {
|
|
41
|
-
console.warn("Nemme client not initialized");
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
return e.track(o);
|
|
45
|
-
},
|
|
46
|
-
[e, n]
|
|
47
|
-
), r = d(async () => {
|
|
48
|
-
if (!e || !n) {
|
|
49
|
-
console.warn("Nemme client not initialized");
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
return e.flush();
|
|
53
|
-
}, [e, n]);
|
|
54
|
-
return {
|
|
55
|
-
track: s,
|
|
56
|
-
flush: r,
|
|
57
|
-
isInitialized: n,
|
|
58
|
-
error: i,
|
|
59
|
-
client: e
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
export {
|
|
63
|
-
b as NemmeProvider,
|
|
64
|
-
T as useNemme,
|
|
65
|
-
y as useNemmeContext
|
|
66
|
-
};
|
|
67
|
-
//# sourceMappingURL=react.esm.js.map
|
package/dist/react.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"react.esm.js","sources":["../src/react/context.ts","../src/react/NemmeProvider.tsx","../src/react/useNemmeContext.ts","../src/react/useNemme.ts"],"sourcesContent":["import { createContext } from 'react';\nimport { NemmeClient } from '../client';\n\nexport interface NemmeContextType {\n client: NemmeClient | null;\n isInitialized: boolean;\n error: string | null;\n}\n\nexport const NemmeContext = createContext<NemmeContextType | undefined>(undefined);\n","import * as React from 'react';\nimport { useEffect, useState } from 'react';\nimport { ClientConfigType, NemmeClient } from '../client';\nimport { NemmeContext, NemmeContextType } from './context';\n\ninterface NemmeProviderProps {\n clientKey: string;\n config: ClientConfigType;\n children: React.ReactNode;\n}\n\nexport const NemmeProvider: React.FC<NemmeProviderProps> = ({ clientKey, config, children }) => {\n const [client, setClient] = useState<NemmeClient | null>(null);\n const [isInitialized, setIsInitialized] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n useEffect(() => {\n let currentClient: NemmeClient | null = null;\n let isCancelled = false;\n\n const initializeClient = async () => {\n try {\n const nemmeClient = new NemmeClient(clientKey);\n await nemmeClient.init(config);\n\n // Check if effect was cancelled during async operation\n if (isCancelled) {\n nemmeClient.destroy();\n return;\n }\n\n currentClient = nemmeClient;\n setClient(nemmeClient);\n setIsInitialized(nemmeClient.initialized);\n setError(nemmeClient.lastInitError ? nemmeClient.lastInitError.message : null);\n } catch (err) {\n if (!isCancelled) {\n setError(err instanceof Error ? err.message : 'Failed to initialize Nemme client');\n setIsInitialized(false);\n }\n }\n };\n\n // Reset state when starting new initialization (deferred to avoid sync setState in effect)\n const resetId = setTimeout(() => {\n setClient(null);\n setIsInitialized(false);\n setError(null);\n }, 0);\n\n initializeClient();\n\n return () => {\n clearTimeout(resetId);\n isCancelled = true;\n if (currentClient) {\n currentClient.destroy();\n }\n };\n }, [clientKey, config]);\n\n const value: NemmeContextType = {\n client,\n isInitialized,\n error\n };\n\n return <NemmeContext.Provider value={value}>{children}</NemmeContext.Provider>;\n};\n","import { useContext } from 'react';\nimport { NemmeContext } from './context';\n\nexport const useNemmeContext = () => {\n const context = useContext(NemmeContext);\n if (context === undefined) {\n throw new Error('useNemmeContext must be used within a NemmeProvider');\n }\n return context;\n};\n","import { useCallback } from 'react';\nimport { useNemmeContext } from './useNemmeContext';\nimport { TrackEventOptions } from '../client';\n\nexport const useNemme = () => {\n const { client, isInitialized, error } = useNemmeContext();\n\n const track = useCallback(\n async <T extends TrackEventOptions>(options: T) => {\n if (!client || !isInitialized) {\n console.warn('Nemme client not initialized');\n return;\n }\n return client.track(options);\n },\n [client, isInitialized]\n );\n\n const flush = useCallback(async () => {\n if (!client || !isInitialized) {\n console.warn('Nemme client not initialized');\n return;\n }\n return client.flush();\n }, [client, isInitialized]);\n\n return {\n track,\n flush,\n isInitialized,\n error,\n client\n };\n};\n"],"names":["NemmeContext","createContext","NemmeProvider","clientKey","config","children","client","setClient","useState","isInitialized","setIsInitialized","error","setError","useEffect","currentClient","isCancelled","initializeClient","nemmeClient","NemmeClient","err","resetId","value","jsx","useNemmeContext","context","useContext","useNemme","track","useCallback","options","flush"],"mappings":";;;AASO,MAAMA,IAAeC,EAA4C,MAAS,GCEpEC,IAA8C,CAAC,EAAE,WAAAC,GAAW,QAAAC,GAAQ,UAAAC,QAAe;AAC9F,QAAM,CAACC,GAAQC,CAAS,IAAIC,EAA6B,IAAI,GACvD,CAACC,GAAeC,CAAgB,IAAIF,EAAS,EAAK,GAClD,CA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,CAACvB,KAAU,CAACG,GAAe;AAC7B,gBAAQ,KAAK,8BAA8B;AAC3C;AAAA,MACF;AACA,aAAOH,EAAO,MAAMuB,CAAO;AAAA,IAC7B;AAAA,IACA,CAACvB,GAAQG,CAAa;AAAA,EAAA,GAGlBqB,IAAQF,EAAY,YAAY;AACpC,QAAI,CAACtB,KAAU,CAACG,GAAe;AAC7B,cAAQ,KAAK,8BAA8B;AAC3C;AAAA,IACF;AACA,WAAOH,EAAO,MAAA;AAAA,EAChB,GAAG,CAACA,GAAQG,CAAa,CAAC;AAE1B,SAAO;AAAA,IACL,OAAAkB;AAAA,IACA,OAAAG;AAAA,IACA,eAAArB;AAAA,IACA,OAAAE;AAAA,IACA,QAAAL;AAAA,EAAA;AAEJ;"}
|
package/dist/style-entry.d.ts
DELETED
|
File without changes
|
package/dist/style.cjs
DELETED
package/dist/style.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"style.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/style.esm.js
DELETED
package/dist/style.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"style.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/types/forms.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export type FormErrorType = 'FETCH_ERROR' | 'SUBMISSION_ERROR';
|
|
2
|
-
export declare class FormError extends Error {
|
|
3
|
-
errorType: string;
|
|
4
|
-
constructor(errorType: FormErrorType, message?: string);
|
|
5
|
-
}
|
|
6
|
-
export type FormConfig = {
|
|
7
|
-
zIndex?: number;
|
|
8
|
-
theme?: 'light' | 'dark';
|
|
9
|
-
onFormError?: (error: FormError) => void;
|
|
10
|
-
};
|
|
File without changes
|