@foxpixel/react 0.1.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.
- package/README.md +216 -0
- package/dist/index.d.mts +408 -0
- package/dist/index.d.ts +408 -0
- package/dist/index.js +495 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +448 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +39 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
// src/context/FoxPixelContext.tsx
|
|
2
|
+
import { createContext, useContext, useMemo } from "react";
|
|
3
|
+
|
|
4
|
+
// src/client/http.ts
|
|
5
|
+
import axios from "axios";
|
|
6
|
+
var FoxPixelHttpClient = class {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
const apiUrl = config.apiUrl || process.env.NEXT_PUBLIC_FOXPIXEL_API_URL || "https://api.foxpixel.com";
|
|
9
|
+
this.client = axios.create({
|
|
10
|
+
baseURL: apiUrl,
|
|
11
|
+
headers: {
|
|
12
|
+
"Content-Type": "application/json"
|
|
13
|
+
},
|
|
14
|
+
withCredentials: true
|
|
15
|
+
// Important for httpOnly cookies (End User auth)
|
|
16
|
+
});
|
|
17
|
+
this.apiKey = config.apiKey || process.env.FOXPIXEL_API_KEY;
|
|
18
|
+
this.tenantId = config.tenantId;
|
|
19
|
+
this.client.interceptors.request.use(
|
|
20
|
+
(config2) => {
|
|
21
|
+
if (this.endUserToken) {
|
|
22
|
+
} else if (this.apiKey) {
|
|
23
|
+
config2.headers["Authorization"] = `Bearer ${this.apiKey}`;
|
|
24
|
+
}
|
|
25
|
+
return config2;
|
|
26
|
+
},
|
|
27
|
+
(error) => Promise.reject(error)
|
|
28
|
+
);
|
|
29
|
+
this.client.interceptors.response.use(
|
|
30
|
+
(response) => response,
|
|
31
|
+
(error) => {
|
|
32
|
+
const apiError = {
|
|
33
|
+
message: "An error occurred",
|
|
34
|
+
status: error.response?.status
|
|
35
|
+
};
|
|
36
|
+
if (error.response?.data) {
|
|
37
|
+
const data = error.response.data;
|
|
38
|
+
apiError.message = data.message || data.error || apiError.message;
|
|
39
|
+
apiError.code = data.code;
|
|
40
|
+
}
|
|
41
|
+
const requestUrl = error.config?.url || "";
|
|
42
|
+
const isMeEndpoint = requestUrl.includes("/auth/end-user/me");
|
|
43
|
+
const isUnauthorized = error.response?.status === 401;
|
|
44
|
+
if (isMeEndpoint && isUnauthorized) {
|
|
45
|
+
apiError.expected = true;
|
|
46
|
+
}
|
|
47
|
+
return Promise.reject(apiError);
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Set API Key (server-side only)
|
|
53
|
+
*/
|
|
54
|
+
setApiKey(apiKey) {
|
|
55
|
+
this.apiKey = apiKey;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Set tenant ID
|
|
59
|
+
*/
|
|
60
|
+
setTenantId(tenantId) {
|
|
61
|
+
this.tenantId = tenantId;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Set end user token (for client-side auth)
|
|
65
|
+
* Note: In practice, end user auth uses httpOnly cookies
|
|
66
|
+
*/
|
|
67
|
+
setEndUserToken(token) {
|
|
68
|
+
this.endUserToken = token;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Clear end user token (logout)
|
|
72
|
+
*/
|
|
73
|
+
clearEndUserToken() {
|
|
74
|
+
this.endUserToken = void 0;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get underlying axios instance
|
|
78
|
+
*/
|
|
79
|
+
getInstance() {
|
|
80
|
+
return this.client;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Make GET request
|
|
84
|
+
*/
|
|
85
|
+
async get(url, config) {
|
|
86
|
+
const response = await this.client.get(url, config);
|
|
87
|
+
return response.data;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Make POST request
|
|
91
|
+
*/
|
|
92
|
+
async post(url, data, config) {
|
|
93
|
+
const response = await this.client.post(url, data, config);
|
|
94
|
+
return response.data;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Make PUT request
|
|
98
|
+
*/
|
|
99
|
+
async put(url, data, config) {
|
|
100
|
+
const response = await this.client.put(url, data, config);
|
|
101
|
+
return response.data;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Make DELETE request
|
|
105
|
+
*/
|
|
106
|
+
async delete(url, config) {
|
|
107
|
+
const response = await this.client.delete(url, config);
|
|
108
|
+
return response.data;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// src/context/FoxPixelContext.tsx
|
|
113
|
+
import { jsx } from "react/jsx-runtime";
|
|
114
|
+
var FoxPixelContext = createContext(null);
|
|
115
|
+
function FoxPixelProvider({ children, config = {} }) {
|
|
116
|
+
const client = useMemo(() => {
|
|
117
|
+
return new FoxPixelHttpClient(config);
|
|
118
|
+
}, [config.apiUrl, config.apiKey, config.tenantId]);
|
|
119
|
+
const value = useMemo(() => ({
|
|
120
|
+
client,
|
|
121
|
+
config
|
|
122
|
+
}), [client, config]);
|
|
123
|
+
return /* @__PURE__ */ jsx(FoxPixelContext.Provider, { value, children });
|
|
124
|
+
}
|
|
125
|
+
function useFoxPixelContext() {
|
|
126
|
+
const context = useContext(FoxPixelContext);
|
|
127
|
+
if (!context) {
|
|
128
|
+
throw new Error("useFoxPixelContext must be used within FoxPixelProvider");
|
|
129
|
+
}
|
|
130
|
+
return context;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/context/AuthContext.tsx
|
|
134
|
+
import { createContext as createContext2, useContext as useContext2, useEffect, useState, useCallback } from "react";
|
|
135
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
136
|
+
var AuthContext = createContext2(null);
|
|
137
|
+
function AuthProvider({
|
|
138
|
+
children,
|
|
139
|
+
loginPath = "/login",
|
|
140
|
+
accountPath = "/account"
|
|
141
|
+
}) {
|
|
142
|
+
const { client } = useFoxPixelContext();
|
|
143
|
+
const [user, setUser] = useState(null);
|
|
144
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
145
|
+
const [error, setError] = useState(null);
|
|
146
|
+
const fetchCurrentUser = useCallback(async () => {
|
|
147
|
+
try {
|
|
148
|
+
setIsLoading(true);
|
|
149
|
+
setError(null);
|
|
150
|
+
const response = await client.get("/api/v1/auth/end-user/me");
|
|
151
|
+
setUser(response);
|
|
152
|
+
} catch (err) {
|
|
153
|
+
const apiError = err;
|
|
154
|
+
if (apiError.status !== 401 && !apiError.expected) {
|
|
155
|
+
setError(apiError);
|
|
156
|
+
}
|
|
157
|
+
setUser(null);
|
|
158
|
+
} finally {
|
|
159
|
+
setIsLoading(false);
|
|
160
|
+
}
|
|
161
|
+
}, [client]);
|
|
162
|
+
const login = useCallback(async (credentials) => {
|
|
163
|
+
try {
|
|
164
|
+
setIsLoading(true);
|
|
165
|
+
setError(null);
|
|
166
|
+
const response = await client.post(
|
|
167
|
+
"/api/v1/auth/end-user/login",
|
|
168
|
+
credentials
|
|
169
|
+
);
|
|
170
|
+
setUser(response.user);
|
|
171
|
+
} catch (err) {
|
|
172
|
+
const apiError = err;
|
|
173
|
+
setError(apiError);
|
|
174
|
+
setUser(null);
|
|
175
|
+
throw apiError;
|
|
176
|
+
} finally {
|
|
177
|
+
setIsLoading(false);
|
|
178
|
+
}
|
|
179
|
+
}, [client]);
|
|
180
|
+
const register = useCallback(async (data) => {
|
|
181
|
+
try {
|
|
182
|
+
setIsLoading(true);
|
|
183
|
+
setError(null);
|
|
184
|
+
const response = await client.post(
|
|
185
|
+
"/api/v1/auth/end-user/register",
|
|
186
|
+
data
|
|
187
|
+
);
|
|
188
|
+
setUser(response.user);
|
|
189
|
+
} catch (err) {
|
|
190
|
+
const apiError = err;
|
|
191
|
+
setError(apiError);
|
|
192
|
+
setUser(null);
|
|
193
|
+
throw apiError;
|
|
194
|
+
} finally {
|
|
195
|
+
setIsLoading(false);
|
|
196
|
+
}
|
|
197
|
+
}, [client]);
|
|
198
|
+
const updateProfile = useCallback(async (data) => {
|
|
199
|
+
try {
|
|
200
|
+
setIsLoading(true);
|
|
201
|
+
setError(null);
|
|
202
|
+
const response = await client.put(
|
|
203
|
+
"/api/v1/auth/end-user/me",
|
|
204
|
+
data
|
|
205
|
+
);
|
|
206
|
+
setUser(response);
|
|
207
|
+
} catch (err) {
|
|
208
|
+
const apiError = err;
|
|
209
|
+
setError(apiError);
|
|
210
|
+
throw apiError;
|
|
211
|
+
} finally {
|
|
212
|
+
setIsLoading(false);
|
|
213
|
+
}
|
|
214
|
+
}, [client]);
|
|
215
|
+
const logout = useCallback(async () => {
|
|
216
|
+
try {
|
|
217
|
+
setIsLoading(true);
|
|
218
|
+
setError(null);
|
|
219
|
+
await client.post("/api/v1/auth/end-user/logout", {});
|
|
220
|
+
setUser(null);
|
|
221
|
+
} catch (err) {
|
|
222
|
+
const apiError = err;
|
|
223
|
+
setError(apiError);
|
|
224
|
+
setUser(null);
|
|
225
|
+
} finally {
|
|
226
|
+
setIsLoading(false);
|
|
227
|
+
}
|
|
228
|
+
}, [client]);
|
|
229
|
+
useEffect(() => {
|
|
230
|
+
fetchCurrentUser();
|
|
231
|
+
}, [fetchCurrentUser]);
|
|
232
|
+
const value = {
|
|
233
|
+
user,
|
|
234
|
+
isLoading,
|
|
235
|
+
isAuthenticated: user !== null,
|
|
236
|
+
error,
|
|
237
|
+
login,
|
|
238
|
+
logout,
|
|
239
|
+
register,
|
|
240
|
+
updateProfile,
|
|
241
|
+
refetch: fetchCurrentUser
|
|
242
|
+
};
|
|
243
|
+
return /* @__PURE__ */ jsx2(AuthContext.Provider, { value, children });
|
|
244
|
+
}
|
|
245
|
+
function useAuth() {
|
|
246
|
+
const context = useContext2(AuthContext);
|
|
247
|
+
if (!context) {
|
|
248
|
+
throw new Error("useAuth must be used within AuthProvider");
|
|
249
|
+
}
|
|
250
|
+
return context;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// src/components/ProtectedRoute.tsx
|
|
254
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
255
|
+
import { Fragment, jsx as jsx3 } from "react/jsx-runtime";
|
|
256
|
+
function ProtectedRoute({
|
|
257
|
+
children,
|
|
258
|
+
loginPath = "/login",
|
|
259
|
+
loadingComponent
|
|
260
|
+
}) {
|
|
261
|
+
const { isAuthenticated, isLoading } = useAuth();
|
|
262
|
+
const [isMounted, setIsMounted] = useState2(false);
|
|
263
|
+
useEffect2(() => {
|
|
264
|
+
setIsMounted(true);
|
|
265
|
+
}, []);
|
|
266
|
+
useEffect2(() => {
|
|
267
|
+
if (!isMounted || typeof window === "undefined") return;
|
|
268
|
+
if (!isLoading && !isAuthenticated) {
|
|
269
|
+
const returnUrl = window.location.pathname + window.location.search;
|
|
270
|
+
const url = `${loginPath}?returnUrl=${encodeURIComponent(returnUrl)}`;
|
|
271
|
+
window.location.href = url;
|
|
272
|
+
}
|
|
273
|
+
}, [isMounted, isLoading, isAuthenticated, loginPath]);
|
|
274
|
+
if (!isMounted || isLoading) {
|
|
275
|
+
return loadingComponent || /* @__PURE__ */ jsx3("div", { className: "flex items-center justify-center min-h-screen", children: /* @__PURE__ */ jsx3("div", { className: "text-gray-500", children: "Carregando..." }) });
|
|
276
|
+
}
|
|
277
|
+
if (!isAuthenticated) {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
return /* @__PURE__ */ jsx3(Fragment, { children });
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// src/components/GuestOnlyRoute.tsx
|
|
284
|
+
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
285
|
+
import { Fragment as Fragment2, jsx as jsx4 } from "react/jsx-runtime";
|
|
286
|
+
var ACCOUNT_PREFIX = "/account";
|
|
287
|
+
function isSafeRedirect(url) {
|
|
288
|
+
if (!url || url.startsWith("//") || url.includes(":")) return false;
|
|
289
|
+
return url.startsWith("/") && url.startsWith(ACCOUNT_PREFIX);
|
|
290
|
+
}
|
|
291
|
+
function GuestOnlyRoute({
|
|
292
|
+
children,
|
|
293
|
+
redirectTo = "/account",
|
|
294
|
+
loadingComponent
|
|
295
|
+
}) {
|
|
296
|
+
const { isAuthenticated, isLoading } = useAuth();
|
|
297
|
+
const [isMounted, setIsMounted] = useState3(false);
|
|
298
|
+
useEffect3(() => {
|
|
299
|
+
setIsMounted(true);
|
|
300
|
+
}, []);
|
|
301
|
+
useEffect3(() => {
|
|
302
|
+
if (!isMounted || typeof window === "undefined") return;
|
|
303
|
+
if (isLoading) return;
|
|
304
|
+
if (!isAuthenticated) return;
|
|
305
|
+
const params = new URLSearchParams(window.location.search);
|
|
306
|
+
const returnUrl = params.get("returnUrl");
|
|
307
|
+
const destination = returnUrl && isSafeRedirect(returnUrl) ? returnUrl : redirectTo;
|
|
308
|
+
window.location.href = destination;
|
|
309
|
+
}, [isMounted, isLoading, isAuthenticated, redirectTo]);
|
|
310
|
+
if (!isMounted || isLoading) {
|
|
311
|
+
return loadingComponent || /* @__PURE__ */ jsx4("div", { className: "flex items-center justify-center min-h-screen", children: /* @__PURE__ */ jsx4("div", { className: "text-gray-500", children: "Carregando..." }) });
|
|
312
|
+
}
|
|
313
|
+
if (isAuthenticated) {
|
|
314
|
+
return loadingComponent || /* @__PURE__ */ jsx4("div", { className: "flex items-center justify-center min-h-screen", children: /* @__PURE__ */ jsx4("div", { className: "text-gray-500", children: "A redirecionar..." }) });
|
|
315
|
+
}
|
|
316
|
+
return /* @__PURE__ */ jsx4(Fragment2, { children });
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// src/components/withAuth.tsx
|
|
320
|
+
import { useEffect as useEffect4, useState as useState4 } from "react";
|
|
321
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
322
|
+
function withAuth(Component, options = {}) {
|
|
323
|
+
const { loginPath = "/login", loadingComponent } = options;
|
|
324
|
+
return function AuthenticatedComponent(props) {
|
|
325
|
+
const { isAuthenticated, isLoading } = useAuth();
|
|
326
|
+
const [isMounted, setIsMounted] = useState4(false);
|
|
327
|
+
useEffect4(() => {
|
|
328
|
+
setIsMounted(true);
|
|
329
|
+
}, []);
|
|
330
|
+
useEffect4(() => {
|
|
331
|
+
if (!isMounted || typeof window === "undefined") return;
|
|
332
|
+
if (!isLoading && !isAuthenticated) {
|
|
333
|
+
const returnUrl = window.location.pathname + window.location.search;
|
|
334
|
+
window.location.href = `${loginPath}?returnUrl=${encodeURIComponent(returnUrl)}`;
|
|
335
|
+
}
|
|
336
|
+
}, [isMounted, isLoading, isAuthenticated, loginPath]);
|
|
337
|
+
if (!isMounted || isLoading) {
|
|
338
|
+
return loadingComponent || /* @__PURE__ */ jsx5("div", { className: "flex items-center justify-center min-h-screen", children: /* @__PURE__ */ jsx5("div", { className: "text-gray-500", children: "Carregando..." }) });
|
|
339
|
+
}
|
|
340
|
+
if (!isAuthenticated) {
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
return /* @__PURE__ */ jsx5(Component, { ...props });
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// src/hooks/useServices.ts
|
|
348
|
+
import { useState as useState5, useEffect as useEffect5 } from "react";
|
|
349
|
+
function useServices(options = {}) {
|
|
350
|
+
const { client } = useFoxPixelContext();
|
|
351
|
+
const [services, setServices] = useState5(null);
|
|
352
|
+
const [isLoading, setIsLoading] = useState5(true);
|
|
353
|
+
const [error, setError] = useState5(null);
|
|
354
|
+
const fetchServices = async () => {
|
|
355
|
+
try {
|
|
356
|
+
setIsLoading(true);
|
|
357
|
+
setError(null);
|
|
358
|
+
const params = new URLSearchParams();
|
|
359
|
+
if (options.category) params.append("category", options.category);
|
|
360
|
+
if (options.active !== void 0) params.append("active", String(options.active));
|
|
361
|
+
const url = `/api/v1/services${params.toString() ? `?${params.toString()}` : ""}`;
|
|
362
|
+
const data = await client.get(url);
|
|
363
|
+
setServices(data);
|
|
364
|
+
} catch (err) {
|
|
365
|
+
setError(err);
|
|
366
|
+
setServices(null);
|
|
367
|
+
} finally {
|
|
368
|
+
setIsLoading(false);
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
useEffect5(() => {
|
|
372
|
+
fetchServices();
|
|
373
|
+
}, [options.category, options.active]);
|
|
374
|
+
return {
|
|
375
|
+
services,
|
|
376
|
+
isLoading,
|
|
377
|
+
error,
|
|
378
|
+
refetch: fetchServices
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// src/hooks/useLeadCapture.ts
|
|
383
|
+
import { useState as useState6 } from "react";
|
|
384
|
+
function useLeadCapture() {
|
|
385
|
+
const { client } = useFoxPixelContext();
|
|
386
|
+
const [isLoading, setIsLoading] = useState6(false);
|
|
387
|
+
const [error, setError] = useState6(null);
|
|
388
|
+
const captureLead = async (data) => {
|
|
389
|
+
try {
|
|
390
|
+
setIsLoading(true);
|
|
391
|
+
setError(null);
|
|
392
|
+
const lead = await client.post("/api/v1/leads", data);
|
|
393
|
+
return lead;
|
|
394
|
+
} catch (err) {
|
|
395
|
+
const apiError = err;
|
|
396
|
+
setError(apiError);
|
|
397
|
+
throw apiError;
|
|
398
|
+
} finally {
|
|
399
|
+
setIsLoading(false);
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
return {
|
|
403
|
+
captureLead,
|
|
404
|
+
isLoading,
|
|
405
|
+
error
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// src/hooks/useContactCapture.ts
|
|
410
|
+
import { useState as useState7 } from "react";
|
|
411
|
+
function useContactCapture() {
|
|
412
|
+
const { client } = useFoxPixelContext();
|
|
413
|
+
const [isLoading, setIsLoading] = useState7(false);
|
|
414
|
+
const [error, setError] = useState7(null);
|
|
415
|
+
const captureContact = async (data) => {
|
|
416
|
+
try {
|
|
417
|
+
setIsLoading(true);
|
|
418
|
+
setError(null);
|
|
419
|
+
const contact = await client.post("/api/v1/contacts", data);
|
|
420
|
+
return contact;
|
|
421
|
+
} catch (err) {
|
|
422
|
+
const apiError = err;
|
|
423
|
+
setError(apiError);
|
|
424
|
+
throw apiError;
|
|
425
|
+
} finally {
|
|
426
|
+
setIsLoading(false);
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
return {
|
|
430
|
+
captureContact,
|
|
431
|
+
isLoading,
|
|
432
|
+
error
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
export {
|
|
436
|
+
AuthProvider,
|
|
437
|
+
FoxPixelHttpClient,
|
|
438
|
+
FoxPixelProvider,
|
|
439
|
+
GuestOnlyRoute,
|
|
440
|
+
ProtectedRoute,
|
|
441
|
+
useAuth,
|
|
442
|
+
useContactCapture,
|
|
443
|
+
useFoxPixelContext,
|
|
444
|
+
useLeadCapture,
|
|
445
|
+
useServices,
|
|
446
|
+
withAuth
|
|
447
|
+
};
|
|
448
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/context/FoxPixelContext.tsx","../src/client/http.ts","../src/context/AuthContext.tsx","../src/components/ProtectedRoute.tsx","../src/components/GuestOnlyRoute.tsx","../src/components/withAuth.tsx","../src/hooks/useServices.ts","../src/hooks/useLeadCapture.ts","../src/hooks/useContactCapture.ts"],"sourcesContent":["/**\n * React Context for FoxPixel SDK\n * Provides HTTP client and configuration to all hooks\n */\n\nimport React, { createContext, useContext, useMemo, ReactNode } from 'react';\nimport { FoxPixelHttpClient } from '../client/http';\nimport { FoxPixelConfig } from '../types';\n\ninterface FoxPixelContextValue {\n client: FoxPixelHttpClient;\n config: FoxPixelConfig;\n}\n\nconst FoxPixelContext = createContext<FoxPixelContextValue | null>(null);\n\nexport interface FoxPixelProviderProps {\n children: ReactNode;\n config?: FoxPixelConfig;\n}\n\n/**\n * FoxPixelProvider - Wraps your app and provides SDK functionality\n * \n * IMPORTANT: API Key should NEVER be passed from client-side.\n * Use server-side proxy (Next.js API routes) for API Key authentication.\n * \n * @example\n * ```tsx\n * // Client-side (no API Key)\n * <FoxPixelProvider>\n * <App />\n * </FoxPixelProvider>\n * \n * // Server-side proxy (Next.js API route)\n * // pages/api/foxpixel/[...path].ts\n * export default async function handler(req, res) {\n * const apiKey = process.env.FOXPIXEL_API_KEY;\n * // Proxy request with API Key\n * }\n * ```\n */\nexport function FoxPixelProvider({ children, config = {} }: FoxPixelProviderProps) {\n const client = useMemo(() => {\n return new FoxPixelHttpClient(config);\n }, [config.apiUrl, config.apiKey, config.tenantId]);\n\n const value = useMemo(() => ({\n client,\n config,\n }), [client, config]);\n\n return (\n <FoxPixelContext.Provider value={value}>\n {children}\n </FoxPixelContext.Provider>\n );\n}\n\n/**\n * Hook to access FoxPixel context\n * @throws Error if used outside FoxPixelProvider\n */\nexport function useFoxPixelContext(): FoxPixelContextValue {\n const context = useContext(FoxPixelContext);\n \n if (!context) {\n throw new Error('useFoxPixelContext must be used within FoxPixelProvider');\n }\n \n return context;\n}\n","/**\n * HTTP client for FoxPixel API\n * Handles authentication and request/response transformation\n */\n\nimport axios, { AxiosInstance, AxiosRequestConfig, AxiosError } from 'axios';\nimport { FoxPixelConfig, ApiError } from '../types';\n\nexport class FoxPixelHttpClient {\n private client: AxiosInstance;\n private apiKey?: string;\n private tenantId?: string;\n private endUserToken?: string;\n\n constructor(config: FoxPixelConfig) {\n const apiUrl = config.apiUrl || process.env.NEXT_PUBLIC_FOXPIXEL_API_URL || 'https://api.foxpixel.com';\n \n this.client = axios.create({\n baseURL: apiUrl,\n headers: {\n 'Content-Type': 'application/json',\n },\n withCredentials: true, // Important for httpOnly cookies (End User auth)\n });\n\n this.apiKey = config.apiKey || process.env.FOXPIXEL_API_KEY;\n this.tenantId = config.tenantId;\n\n // Setup request interceptor\n this.client.interceptors.request.use(\n (config) => {\n // If end user is logged in, use their token\n // Otherwise, use API Key (server-side only)\n if (this.endUserToken) {\n // End user token is sent via httpOnly cookie automatically\n // No need to set Authorization header\n } else if (this.apiKey) {\n // API Key should only be used server-side\n // In production, this should be proxied through Next.js API routes\n config.headers['Authorization'] = `Bearer ${this.apiKey}`;\n }\n return config;\n },\n (error) => Promise.reject(error)\n );\n\n // Setup response interceptor for error handling\n this.client.interceptors.response.use(\n (response) => response,\n (error: AxiosError) => {\n const apiError: ApiError = {\n message: 'An error occurred',\n status: error.response?.status,\n };\n\n if (error.response?.data) {\n const data = error.response.data as any;\n apiError.message = data.message || data.error || apiError.message;\n apiError.code = data.code;\n }\n\n // Mark 401 on /me endpoint as \"expected\" (not an error)\n // 401 is expected when checking if user is logged in (no cookie = not logged in)\n // The hook (useAuth) will handle this gracefully by ignoring 401\n const requestUrl = error.config?.url || '';\n const isMeEndpoint = requestUrl.includes('/auth/end-user/me');\n const isUnauthorized = error.response?.status === 401;\n\n if (isMeEndpoint && isUnauthorized) {\n // Mark as expected error (hook will handle silently)\n apiError.expected = true;\n }\n\n return Promise.reject(apiError);\n }\n );\n }\n\n /**\n * Set API Key (server-side only)\n */\n setApiKey(apiKey: string) {\n this.apiKey = apiKey;\n }\n\n /**\n * Set tenant ID\n */\n setTenantId(tenantId: string) {\n this.tenantId = tenantId;\n }\n\n /**\n * Set end user token (for client-side auth)\n * Note: In practice, end user auth uses httpOnly cookies\n */\n setEndUserToken(token: string) {\n this.endUserToken = token;\n }\n\n /**\n * Clear end user token (logout)\n */\n clearEndUserToken() {\n this.endUserToken = undefined;\n }\n\n /**\n * Get underlying axios instance\n */\n getInstance(): AxiosInstance {\n return this.client;\n }\n\n /**\n * Make GET request\n */\n async get<T>(url: string, config?: AxiosRequestConfig): Promise<T> {\n const response = await this.client.get<T>(url, config);\n return response.data;\n }\n\n /**\n * Make POST request\n */\n async post<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T> {\n const response = await this.client.post<T>(url, data, config);\n return response.data;\n }\n\n /**\n * Make PUT request\n */\n async put<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T> {\n const response = await this.client.put<T>(url, data, config);\n return response.data;\n }\n\n /**\n * Make DELETE request\n */\n async delete<T>(url: string, config?: AxiosRequestConfig): Promise<T> {\n const response = await this.client.delete<T>(url, config);\n return response.data;\n }\n}\n","/**\n * Global Authentication Context\n * Manages authentication state across the entire application\n * Automatically handles session restoration on page reload\n */\n\nimport React, { createContext, useContext, useEffect, useState, useCallback, ReactNode } from 'react';\nimport { useFoxPixelContext } from './FoxPixelContext';\nimport { EndUser, EndUserLoginRequest, ApiError } from '../types';\n\ninterface AuthContextValue {\n user: EndUser | null;\n isLoading: boolean;\n isAuthenticated: boolean;\n error: ApiError | null;\n login: (credentials: EndUserLoginRequest) => Promise<void>;\n logout: () => Promise<void>;\n register: (data: { email: string; password: string; fullName: string; phone?: string }) => Promise<void>;\n updateProfile: (data: { fullName?: string; phone?: string }) => Promise<void>;\n refetch: () => Promise<void>;\n}\n\nconst AuthContext = createContext<AuthContextValue | null>(null);\n\nexport interface AuthProviderProps {\n children: ReactNode;\n /**\n * Redirect path when user is not authenticated\n * Default: '/login'\n */\n loginPath?: string;\n /**\n * Redirect path after successful login\n * Default: '/account'\n */\n accountPath?: string;\n}\n\n/**\n * AuthProvider - Manages authentication state globally\n * \n * Automatically:\n * - Restores session on mount (checks httpOnly cookie)\n * - Manages user state across the app\n * - Handles login/logout transparently\n * \n * @example\n * ```tsx\n * // In _app.tsx\n * <FoxPixelProvider>\n * <AuthProvider>\n * <Component {...pageProps} />\n * </AuthProvider>\n * </FoxPixelProvider>\n * ```\n */\nexport function AuthProvider({ \n children, \n loginPath = '/login',\n accountPath = '/account'\n}: AuthProviderProps) {\n const { client } = useFoxPixelContext();\n const [user, setUser] = useState<EndUser | null>(null);\n const [isLoading, setIsLoading] = useState(true);\n const [error, setError] = useState<ApiError | null>(null);\n\n /**\n * Fetch current user from backend\n * Automatically called on mount to restore session\n */\n const fetchCurrentUser = useCallback(async () => {\n try {\n setIsLoading(true);\n setError(null);\n\n const response = await client.get<EndUser>('/api/v1/auth/end-user/me');\n setUser(response);\n } catch (err) {\n const apiError = err as ApiError;\n \n // 401 is expected when not logged in (no cookie)\n // Don't treat it as an error\n if (apiError.status !== 401 && !apiError.expected) {\n setError(apiError);\n }\n \n setUser(null);\n } finally {\n setIsLoading(false);\n }\n }, [client]);\n\n /**\n * Login with email and password\n * Token is automatically stored in httpOnly cookie by backend\n */\n const login = useCallback(async (credentials: EndUserLoginRequest) => {\n try {\n setIsLoading(true);\n setError(null);\n\n const response = await client.post<{ user: EndUser; message: string }>(\n '/api/v1/auth/end-user/login',\n credentials\n );\n\n setUser(response.user);\n } catch (err) {\n const apiError = err as ApiError;\n setError(apiError);\n setUser(null);\n throw apiError;\n } finally {\n setIsLoading(false);\n }\n }, [client]);\n\n /**\n * Register new user\n * Automatically logs in after registration (backend sets cookie)\n */\n const register = useCallback(async (data: { \n email: string; \n password: string; \n fullName: string; \n phone?: string \n }) => {\n try {\n setIsLoading(true);\n setError(null);\n\n const response = await client.post<{ user: EndUser; message: string }>(\n '/api/v1/auth/end-user/register',\n data\n );\n\n // Backend automatically logs in after registration (cookie is set)\n setUser(response.user);\n } catch (err) {\n const apiError = err as ApiError;\n setError(apiError);\n setUser(null);\n throw apiError;\n } finally {\n setIsLoading(false);\n }\n }, [client]);\n\n /**\n * Update user profile (fullName, phone)\n * Automatically refreshes user data after update\n */\n const updateProfile = useCallback(async (data: { fullName?: string; phone?: string }) => {\n try {\n setIsLoading(true);\n setError(null);\n\n const response = await client.put<EndUser>(\n '/api/v1/auth/end-user/me',\n data\n );\n\n // Update user state with new data\n setUser(response);\n } catch (err) {\n const apiError = err as ApiError;\n setError(apiError);\n throw apiError;\n } finally {\n setIsLoading(false);\n }\n }, [client]);\n\n /**\n * Logout (removes httpOnly cookie)\n */\n const logout = useCallback(async () => {\n try {\n setIsLoading(true);\n setError(null);\n\n await client.post('/api/v1/auth/end-user/logout', {});\n setUser(null);\n } catch (err) {\n const apiError = err as ApiError;\n setError(apiError);\n // Even if logout fails, clear user state\n setUser(null);\n } finally {\n setIsLoading(false);\n }\n }, [client]);\n\n // Restore session on mount (check if user is already logged in)\n useEffect(() => {\n fetchCurrentUser();\n }, [fetchCurrentUser]);\n\n const value: AuthContextValue = {\n user,\n isLoading,\n isAuthenticated: user !== null,\n error,\n login,\n logout,\n register,\n updateProfile,\n refetch: fetchCurrentUser,\n };\n\n return (\n <AuthContext.Provider value={value}>\n {children}\n </AuthContext.Provider>\n );\n}\n\n/**\n * Hook to access authentication context\n * @throws Error if used outside AuthProvider\n */\nexport function useAuth(): AuthContextValue {\n const context = useContext(AuthContext);\n \n if (!context) {\n throw new Error('useAuth must be used within AuthProvider');\n }\n \n return context;\n}\n","/**\n * ProtectedRoute - Automatically protects pages/routes\n * Redirects to login if user is not authenticated\n *\n * Does NOT use next/router (useRouter) to avoid \"NextRouter was not mounted\"\n * during SSR. Uses window.location for redirect instead.\n *\n * Usage:\n * ```tsx\n * export default function Dashboard() {\n * return (\n * <ProtectedRoute>\n * <YourContent />\n * </ProtectedRoute>\n * );\n * }\n * ```\n */\n\nimport { ReactNode, useEffect, useState } from 'react';\nimport { useAuth } from '../context/AuthContext';\n\ninterface ProtectedRouteProps {\n children: ReactNode;\n /**\n * Redirect path when not authenticated\n * Default: '/login'\n */\n loginPath?: string;\n /**\n * Show loading spinner while checking auth\n */\n loadingComponent?: ReactNode;\n}\n\nexport function ProtectedRoute({\n children,\n loginPath = '/login',\n loadingComponent,\n}: ProtectedRouteProps) {\n const { isAuthenticated, isLoading } = useAuth();\n const [isMounted, setIsMounted] = useState(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n useEffect(() => {\n if (!isMounted || typeof window === 'undefined') return;\n if (!isLoading && !isAuthenticated) {\n const returnUrl = window.location.pathname + window.location.search;\n const url = `${loginPath}?returnUrl=${encodeURIComponent(returnUrl)}`;\n window.location.href = url;\n }\n }, [isMounted, isLoading, isAuthenticated, loginPath]);\n\n // SSR or loading: show placeholder (no useRouter)\n if (!isMounted || isLoading) {\n return (\n loadingComponent || (\n <div className=\"flex items-center justify-center min-h-screen\">\n <div className=\"text-gray-500\">Carregando...</div>\n </div>\n )\n );\n }\n\n if (!isAuthenticated) {\n return null;\n }\n\n return <>{children}</>;\n}\n","/**\n * GuestOnlyRoute - For login/register pages\n * If user is already authenticated, redirects to account (or returnUrl).\n * Otherwise renders children (login/register form).\n *\n * Does NOT use next/router (avoids SSR issues). Uses window.location.\n *\n * Usage:\n * ```tsx\n * export default function Login() {\n * return (\n * <GuestOnlyRoute>\n * <LoginForm />\n * </GuestOnlyRoute>\n * );\n * }\n * ```\n */\n\nimport { ReactNode, useEffect, useState } from 'react';\nimport { useAuth } from '../context/AuthContext';\n\ninterface GuestOnlyRouteProps {\n children: ReactNode;\n /**\n * Where to redirect when already authenticated.\n * Default: '/account'\n */\n redirectTo?: string;\n /**\n * Show this while checking auth or redirecting.\n */\n loadingComponent?: ReactNode;\n}\n\n/** Base path for account area. returnUrl must start with this to be trusted. */\nconst ACCOUNT_PREFIX = '/account';\n\nfunction isSafeRedirect(url: string): boolean {\n if (!url || url.startsWith('//') || url.includes(':')) return false;\n return url.startsWith('/') && url.startsWith(ACCOUNT_PREFIX);\n}\n\nexport function GuestOnlyRoute({\n children,\n redirectTo = '/account',\n loadingComponent,\n}: GuestOnlyRouteProps) {\n const { isAuthenticated, isLoading } = useAuth();\n const [isMounted, setIsMounted] = useState(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n useEffect(() => {\n if (!isMounted || typeof window === 'undefined') return;\n if (isLoading) return;\n if (!isAuthenticated) return;\n\n const params = new URLSearchParams(window.location.search);\n const returnUrl = params.get('returnUrl');\n const destination =\n returnUrl && isSafeRedirect(returnUrl) ? returnUrl : redirectTo;\n window.location.href = destination;\n }, [isMounted, isLoading, isAuthenticated, redirectTo]);\n\n if (!isMounted || isLoading) {\n return (\n loadingComponent || (\n <div className=\"flex items-center justify-center min-h-screen\">\n <div className=\"text-gray-500\">Carregando...</div>\n </div>\n )\n );\n }\n\n if (isAuthenticated) {\n return (\n loadingComponent || (\n <div className=\"flex items-center justify-center min-h-screen\">\n <div className=\"text-gray-500\">A redirecionar...</div>\n </div>\n )\n );\n }\n\n return <>{children}</>;\n}\n","/**\n * Higher-Order Component (HOC) to protect components\n * Automatically redirects to login if user is not authenticated\n *\n * Does NOT use next/router to avoid SSR \"NextRouter was not mounted\".\n * Uses window.location for redirect.\n *\n * Usage:\n * ```tsx\n * function MyProtectedPage() {\n * return <div>Protected Content</div>;\n * }\n * export default withAuth(MyProtectedPage);\n * ```\n */\n\nimport { ComponentType, useEffect, useState, ReactNode } from 'react';\nimport { useAuth } from '../context/AuthContext';\n\ninterface WithAuthOptions {\n loginPath?: string;\n loadingComponent?: ReactNode;\n}\n\nexport function withAuth<P extends object>(\n Component: ComponentType<P>,\n options: WithAuthOptions = {}\n) {\n const { loginPath = '/login', loadingComponent } = options;\n\n return function AuthenticatedComponent(props: P) {\n const { isAuthenticated, isLoading } = useAuth();\n const [isMounted, setIsMounted] = useState(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n useEffect(() => {\n if (!isMounted || typeof window === 'undefined') return;\n if (!isLoading && !isAuthenticated) {\n const returnUrl = window.location.pathname + window.location.search;\n window.location.href = `${loginPath}?returnUrl=${encodeURIComponent(returnUrl)}`;\n }\n }, [isMounted, isLoading, isAuthenticated, loginPath]);\n\n if (!isMounted || isLoading) {\n return (\n loadingComponent || (\n <div className=\"flex items-center justify-center min-h-screen\">\n <div className=\"text-gray-500\">Carregando...</div>\n </div>\n )\n );\n }\n\n if (!isAuthenticated) {\n return null;\n }\n\n return <Component {...props} />;\n };\n}\n","/**\n * Hook to fetch and manage services (Projects module)\n */\n\nimport { useState, useEffect } from 'react';\nimport { useFoxPixelContext } from '../context/FoxPixelContext';\nimport { ServiceCatalogResponse, ApiError } from '../types';\n\ninterface UseServicesOptions {\n category?: string;\n active?: boolean;\n}\n\ninterface UseServicesReturn {\n services: ServiceCatalogResponse[] | null;\n isLoading: boolean;\n error: ApiError | null;\n refetch: () => Promise<void>;\n}\n\n/**\n * Fetch services from Projects module\n * \n * @example\n * ```tsx\n * function ServicesPage() {\n * const { services, isLoading, error } = useServices({ active: true });\n * \n * if (isLoading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * \n * return (\n * <div>\n * {services?.map(service => (\n * <ServiceCard key={service.id} service={service} />\n * ))}\n * </div>\n * );\n * }\n * ```\n */\nexport function useServices(options: UseServicesOptions = {}): UseServicesReturn {\n const { client } = useFoxPixelContext();\n const [services, setServices] = useState<ServiceCatalogResponse[] | null>(null);\n const [isLoading, setIsLoading] = useState(true);\n const [error, setError] = useState<ApiError | null>(null);\n\n const fetchServices = async () => {\n try {\n setIsLoading(true);\n setError(null);\n\n const params = new URLSearchParams();\n if (options.category) params.append('category', options.category);\n if (options.active !== undefined) params.append('active', String(options.active));\n\n const url = `/api/v1/services${params.toString() ? `?${params.toString()}` : ''}`;\n const data = await client.get<ServiceCatalogResponse[]>(url);\n \n setServices(data);\n } catch (err) {\n setError(err as ApiError);\n setServices(null);\n } finally {\n setIsLoading(false);\n }\n };\n\n useEffect(() => {\n fetchServices();\n }, [options.category, options.active]);\n\n return {\n services,\n isLoading,\n error,\n refetch: fetchServices,\n };\n}\n","/**\n * Hook to capture leads (CRM module)\n */\n\nimport { useState } from 'react';\nimport { useFoxPixelContext } from '../context/FoxPixelContext';\nimport { CreateLeadRequest, Lead, ApiError } from '../types';\n\ninterface UseLeadCaptureReturn {\n captureLead: (data: CreateLeadRequest) => Promise<Lead>;\n isLoading: boolean;\n error: ApiError | null;\n}\n\n/**\n * Capture a lead (create lead in CRM)\n * \n * @example\n * ```tsx\n * function ContactForm() {\n * const { captureLead, isLoading, error } = useLeadCapture();\n * \n * const handleSubmit = async (e) => {\n * e.preventDefault();\n * try {\n * const lead = await captureLead({\n * fullName: 'John Doe',\n * email: 'john@example.com',\n * phone: '+1234567890',\n * source: 'website',\n * });\n * alert('Lead created!');\n * } catch (err) {\n * console.error('Error:', err);\n * }\n * };\n * \n * return <form onSubmit={handleSubmit}>...</form>;\n * }\n * ```\n */\nexport function useLeadCapture(): UseLeadCaptureReturn {\n const { client } = useFoxPixelContext();\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<ApiError | null>(null);\n\n const captureLead = async (data: CreateLeadRequest): Promise<Lead> => {\n try {\n setIsLoading(true);\n setError(null);\n\n const lead = await client.post<Lead>('/api/v1/leads', data);\n \n return lead;\n } catch (err) {\n const apiError = err as ApiError;\n setError(apiError);\n throw apiError;\n } finally {\n setIsLoading(false);\n }\n };\n\n return {\n captureLead,\n isLoading,\n error,\n };\n}\n","/**\n * Hook to capture contacts (CRM module)\n */\n\nimport { useState } from 'react';\nimport { useFoxPixelContext } from '../context/FoxPixelContext';\n\ninterface Contact {\n id: string;\n fullName: string;\n email?: string;\n phone?: string;\n company?: string;\n notes?: string;\n postalCode?: string;\n address?: string;\n city?: string;\n createdAt: string;\n}\n\ninterface CreateContactRequest {\n fullName: string;\n email?: string;\n phone?: string;\n company?: string;\n notes?: string;\n nif?: string;\n address?: string;\n postalCode?: string;\n city?: string;\n}\n\ninterface ApiError {\n message: string;\n status?: number;\n code?: string;\n}\n\ninterface UseContactCaptureReturn {\n captureContact: (data: CreateContactRequest) => Promise<Contact>;\n isLoading: boolean;\n error: ApiError | null;\n}\n\n/**\n * Capture a contact (create contact in CRM)\n * \n * The frontend/SDK decides which fields to fill.\n * This hook accepts any fields from CreateContactRequest.\n * \n * @example\n * ```tsx\n * function ContactForm() {\n * const { captureContact, isLoading, error } = useContactCapture();\n * \n * const handleSubmit = async (e) => {\n * e.preventDefault();\n * try {\n * const contact = await captureContact({\n * fullName: 'John Doe',\n * email: 'john@example.com',\n * phone: '+1234567890',\n * postalCode: '75001',\n * notes: 'Interested in garden maintenance',\n * });\n * alert('Contact created!');\n * } catch (err) {\n * console.error('Error:', err);\n * }\n * };\n * \n * return <form onSubmit={handleSubmit}>...</form>;\n * }\n * ```\n */\nexport function useContactCapture(): UseContactCaptureReturn {\n const { client } = useFoxPixelContext();\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<ApiError | null>(null);\n\n const captureContact = async (data: CreateContactRequest): Promise<Contact> => {\n try {\n setIsLoading(true);\n setError(null);\n\n const contact = await client.post<Contact>('/api/v1/contacts', data);\n \n return contact;\n } catch (err) {\n const apiError = err as ApiError;\n setError(apiError);\n throw apiError;\n } finally {\n setIsLoading(false);\n }\n };\n\n return {\n captureContact,\n isLoading,\n error,\n };\n}\n"],"mappings":";AAKA,SAAgB,eAAe,YAAY,eAA0B;;;ACArE,OAAO,WAA8D;AAG9D,IAAM,qBAAN,MAAyB;AAAA,EAM9B,YAAY,QAAwB;AAClC,UAAM,SAAS,OAAO,UAAU,QAAQ,IAAI,gCAAgC;AAE5E,SAAK,SAAS,MAAM,OAAO;AAAA,MACzB,SAAS;AAAA,MACT,SAAS;AAAA,QACP,gBAAgB;AAAA,MAClB;AAAA,MACA,iBAAiB;AAAA;AAAA,IACnB,CAAC;AAED,SAAK,SAAS,OAAO,UAAU,QAAQ,IAAI;AAC3C,SAAK,WAAW,OAAO;AAGvB,SAAK,OAAO,aAAa,QAAQ;AAAA,MAC/B,CAACA,YAAW;AAGV,YAAI,KAAK,cAAc;AAAA,QAGvB,WAAW,KAAK,QAAQ;AAGtB,UAAAA,QAAO,QAAQ,eAAe,IAAI,UAAU,KAAK,MAAM;AAAA,QACzD;AACA,eAAOA;AAAA,MACT;AAAA,MACA,CAAC,UAAU,QAAQ,OAAO,KAAK;AAAA,IACjC;AAGA,SAAK,OAAO,aAAa,SAAS;AAAA,MAChC,CAAC,aAAa;AAAA,MACd,CAAC,UAAsB;AACrB,cAAM,WAAqB;AAAA,UACzB,SAAS;AAAA,UACT,QAAQ,MAAM,UAAU;AAAA,QAC1B;AAEA,YAAI,MAAM,UAAU,MAAM;AACxB,gBAAM,OAAO,MAAM,SAAS;AAC5B,mBAAS,UAAU,KAAK,WAAW,KAAK,SAAS,SAAS;AAC1D,mBAAS,OAAO,KAAK;AAAA,QACvB;AAKA,cAAM,aAAa,MA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AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;;AChEA,SAAS,YAAAC,iBAAgB;AAuElB,SAAS,oBAA6C;AAC3D,QAAM,EAAE,OAAO,IAAI,mBAAmB;AACtC,QAAM,CAAC,WAAW,YAAY,IAAIC,UAAS,KAAK;AAChD,QAAM,CAAC,OAAO,QAAQ,IAAIA,UAA0B,IAAI;AAExD,QAAM,iBAAiB,OAAO,SAAiD;AAC7E,QAAI;AACF,mBAAa,IAAI;AACjB,eAAS,IAAI;AAEb,YAAM,UAAU,MAAM,OAAO,KAAc,oBAAoB,IAAI;AAEnE,aAAO;AAAA,IACT,SAAS,KAAK;AACZ,YAAM,WAAW;AACjB,eAAS,QAAQ;AACjB,YAAM;AAAA,IACR,UAAE;AACA,mBAAa,KAAK;AAAA,IACpB;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["config","createContext","useContext","jsx","createContext","useContext","useEffect","useState","jsx","useState","useEffect","useEffect","useState","Fragment","jsx","useState","useEffect","useEffect","useState","jsx","useState","useEffect","useState","useEffect","useState","useEffect","useState","useState","useState","useState"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@foxpixel/react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React SDK for FoxPixel API - Headless integration for custom sites and portals",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsup",
|
|
13
|
+
"dev": "tsup --watch",
|
|
14
|
+
"type-check": "tsc --noEmit",
|
|
15
|
+
"prepublishOnly": "npm run build"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"foxpixel",
|
|
19
|
+
"react",
|
|
20
|
+
"sdk",
|
|
21
|
+
"headless",
|
|
22
|
+
"cms"
|
|
23
|
+
],
|
|
24
|
+
"author": "FoxPixel",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"react": ">=18.0.0",
|
|
28
|
+
"react-dom": ">=18.0.0"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"axios": "^1.6.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/react": "^18.2.0",
|
|
35
|
+
"@types/react-dom": "^18.2.0",
|
|
36
|
+
"tsup": "^8.0.0",
|
|
37
|
+
"typescript": "^5.3.0"
|
|
38
|
+
}
|
|
39
|
+
}
|