@capibox/bridge-nextjs-client 0.0.49 → 0.0.55
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 +1 -1
- package/dist/index.d.mts +247 -1445
- package/dist/index.d.ts +247 -1445
- package/dist/index.js +20 -846
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -845
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -1
package/dist/index.mjs
CHANGED
|
@@ -17,18 +17,6 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
20
|
var __async = (__this, __arguments, generator) => {
|
|
33
21
|
return new Promise((resolve, reject) => {
|
|
34
22
|
var fulfilled = (value) => {
|
|
@@ -50,539 +38,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
50
38
|
});
|
|
51
39
|
};
|
|
52
40
|
|
|
53
|
-
// src/lib/api.ts
|
|
54
|
-
import createFetchClient from "openapi-fetch";
|
|
55
|
-
var endpoint = "/api-client-proxy";
|
|
56
|
-
var $apiClient = createFetchClient({
|
|
57
|
-
baseUrl: endpoint,
|
|
58
|
-
headers: {
|
|
59
|
-
"project-key": "Frontend"
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// src/browser/mail/send-to-recipient.ts
|
|
64
|
-
var sendToRecipient = (data) => __async(null, null, function* () {
|
|
65
|
-
const res = yield $apiClient.POST(
|
|
66
|
-
"/mail/send-to-recipient",
|
|
67
|
-
{
|
|
68
|
-
params: {
|
|
69
|
-
header: {
|
|
70
|
-
"project-key": "Frontend"
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
body: data
|
|
74
|
-
}
|
|
75
|
-
);
|
|
76
|
-
if (!res.data) {
|
|
77
|
-
throw new Error(res.error);
|
|
78
|
-
}
|
|
79
|
-
return res.data;
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// src/browser/mail/send-to-support.ts
|
|
83
|
-
var sendToSupport = (data) => __async(null, null, function* () {
|
|
84
|
-
const res = yield $apiClient.POST(
|
|
85
|
-
"/mail/send-to-support",
|
|
86
|
-
{
|
|
87
|
-
params: {
|
|
88
|
-
header: {
|
|
89
|
-
"project-key": "Frontend"
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
body: data
|
|
93
|
-
}
|
|
94
|
-
);
|
|
95
|
-
if (!res.data) {
|
|
96
|
-
throw new Error(res.error);
|
|
97
|
-
}
|
|
98
|
-
return res.data;
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
// src/browser/session/append.ts
|
|
102
|
-
var appendSession = (uuid, body) => __async(null, null, function* () {
|
|
103
|
-
const res = yield $apiClient.PUT(
|
|
104
|
-
"/session/{uuid}",
|
|
105
|
-
{
|
|
106
|
-
params: {
|
|
107
|
-
path: {
|
|
108
|
-
uuid
|
|
109
|
-
},
|
|
110
|
-
header: {
|
|
111
|
-
"project-key": "Frontend"
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
body
|
|
115
|
-
}
|
|
116
|
-
);
|
|
117
|
-
if (!res.data) {
|
|
118
|
-
throw new Error("Failed to append session.");
|
|
119
|
-
}
|
|
120
|
-
return res.data.data;
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
// src/server/middleware.ts
|
|
124
|
-
import { NextResponse, userAgent } from "next/server";
|
|
125
|
-
|
|
126
|
-
// src/server/_utils/is.ts
|
|
127
|
-
var regexes = {
|
|
128
|
-
ipv4: /^(?:(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/,
|
|
129
|
-
ipv6: /^((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\3)::|:\b|$))|(?!\2\3)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i
|
|
130
|
-
};
|
|
131
|
-
function not(func) {
|
|
132
|
-
return function() {
|
|
133
|
-
return !func.apply(null, Array.prototype.slice.call(arguments));
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
function existy(value) {
|
|
137
|
-
return value != null;
|
|
138
|
-
}
|
|
139
|
-
function ip(value) {
|
|
140
|
-
return existy(value) && regexes.ipv4.test(value) || regexes.ipv6.test(value);
|
|
141
|
-
}
|
|
142
|
-
function object(value) {
|
|
143
|
-
return Object(value) === value;
|
|
144
|
-
}
|
|
145
|
-
function string(value) {
|
|
146
|
-
return Object.prototype.toString.call(value) === "[object String]";
|
|
147
|
-
}
|
|
148
|
-
var is = {
|
|
149
|
-
existy,
|
|
150
|
-
ip,
|
|
151
|
-
object,
|
|
152
|
-
string,
|
|
153
|
-
not: {
|
|
154
|
-
existy: not(existy),
|
|
155
|
-
ip: not(ip),
|
|
156
|
-
object: not(object),
|
|
157
|
-
string: not(string)
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
var is_default = is;
|
|
161
|
-
|
|
162
|
-
// src/server/_utils/client-ip.ts
|
|
163
|
-
function getClientIpFromXForwardedFor(value) {
|
|
164
|
-
if (!is_default.existy(value)) {
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
const forwardedIps = value.split(",").map(function(e) {
|
|
168
|
-
const ip2 = e.trim();
|
|
169
|
-
if (ip2.includes(":")) {
|
|
170
|
-
const splitted = ip2.split(":");
|
|
171
|
-
if (splitted.length === 2) {
|
|
172
|
-
return splitted[0];
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return ip2;
|
|
176
|
-
});
|
|
177
|
-
for (let i = 0; i < forwardedIps.length; i++) {
|
|
178
|
-
if (is_default.ip(forwardedIps[i])) {
|
|
179
|
-
return forwardedIps[i];
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return null;
|
|
183
|
-
}
|
|
184
|
-
function getClientIp(req) {
|
|
185
|
-
if (req.headers) {
|
|
186
|
-
if (is_default.ip(req.headers["x-client-ip"])) {
|
|
187
|
-
return req.headers["x-client-ip"];
|
|
188
|
-
}
|
|
189
|
-
const xForwardedFor = getClientIpFromXForwardedFor(req.headers["x-forwarded-for"]);
|
|
190
|
-
if (is_default.ip(req.headers["cf-connecting-ip"])) {
|
|
191
|
-
return req.headers["cf-connecting-ip"];
|
|
192
|
-
}
|
|
193
|
-
if (is_default.ip(req.headers["fastly-client-ip"])) {
|
|
194
|
-
return req.headers["fastly-client-ip"];
|
|
195
|
-
}
|
|
196
|
-
if (is_default.ip(req.headers["true-client-ip"])) {
|
|
197
|
-
return req.headers["true-client-ip"];
|
|
198
|
-
}
|
|
199
|
-
if (is_default.ip(req.headers["x-real-ip"])) {
|
|
200
|
-
return req.headers["x-real-ip"];
|
|
201
|
-
}
|
|
202
|
-
if (is_default.ip(req.headers["x-cluster-client-ip"])) {
|
|
203
|
-
return req.headers["x-cluster-client-ip"];
|
|
204
|
-
}
|
|
205
|
-
if (is_default.ip(req.headers["x-forwarded"])) {
|
|
206
|
-
return req.headers["x-forwarded"];
|
|
207
|
-
}
|
|
208
|
-
if (is_default.ip(req.headers["forwarded-for"])) {
|
|
209
|
-
return req.headers["forwarded-for"];
|
|
210
|
-
}
|
|
211
|
-
if (is_default.ip(xForwardedFor)) {
|
|
212
|
-
return xForwardedFor;
|
|
213
|
-
}
|
|
214
|
-
if (is_default.ip(req.headers.forwarded)) {
|
|
215
|
-
return req.headers.forwarded;
|
|
216
|
-
}
|
|
217
|
-
if (is_default.ip(req.headers["x-appengine-user-ip"])) {
|
|
218
|
-
return req.headers["x-appengine-user-ip"];
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
if (is_default.existy(req.connection) && !!req.connection) {
|
|
222
|
-
if (is_default.ip(req.connection.remoteAddress)) {
|
|
223
|
-
return req.connection.remoteAddress;
|
|
224
|
-
}
|
|
225
|
-
if (is_default.existy(req.connection.socket) && !!req.connection.socket && !!req.connection.socket.remoteAddress && is_default.ip(req.connection.socket.remoteAddress)) {
|
|
226
|
-
return req.connection.socket.remoteAddress;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
if (is_default.existy(req.socket) && !!req.socket && !!req.socket.remoteAddress && is_default.ip(req.socket.remoteAddress)) {
|
|
230
|
-
return req.socket.remoteAddress;
|
|
231
|
-
}
|
|
232
|
-
if (is_default.existy(req.info) && !!req.info && !!req.info.remoteAddress && is_default.ip(req.info.remoteAddress)) {
|
|
233
|
-
return req.info.remoteAddress;
|
|
234
|
-
}
|
|
235
|
-
if (is_default.existy(req.requestContext) && !!req.requestContext && is_default.existy(req.requestContext.identity) && !!req.requestContext.identity && !!req.requestContext.identity.sourceIp && is_default.ip(req.requestContext.identity.sourceIp)) {
|
|
236
|
-
return req.requestContext.identity.sourceIp;
|
|
237
|
-
}
|
|
238
|
-
if (req.headers) {
|
|
239
|
-
if (is_default.ip(req.headers["Cf-Pseudo-IPv4"])) {
|
|
240
|
-
return req.headers["Cf-Pseudo-IPv4"];
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return "127.0.0.2";
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// src/browser/crm-auth/path.ts
|
|
247
|
-
var CRM_AUTH_SIGN_IN_PATH = "/api/crm-auth/sign-in";
|
|
248
|
-
var CRM_AUTH_SIGN_OUT_PATH = "/api/crm-auth/sign-out";
|
|
249
|
-
var CRM_AUTH_VERIFY_PATH = "/api/crm-auth/verify";
|
|
250
|
-
|
|
251
|
-
// src/server/_utils/server-fetch-utils.ts
|
|
252
|
-
var serverProxyHeaders = () => {
|
|
253
|
-
return {
|
|
254
|
-
"Content-Type": "application/json",
|
|
255
|
-
"Authorization": `${process.env.CAPIBOX_ENV}`.toLowerCase() === "prod" ? `${process.env.CAPIBOX_API_KEY}` : "dev"
|
|
256
|
-
};
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
// src/server/middleware.ts
|
|
260
|
-
import cache3 from "memory-cache";
|
|
261
|
-
|
|
262
|
-
// src/server/cache/cache.ts
|
|
263
|
-
var CACHE_KEY_FUNNELS = "funnels-data";
|
|
264
|
-
var CACHE_KEY_SPLIT = "split-data";
|
|
265
|
-
|
|
266
|
-
// src/server/split/get-split-data.ts
|
|
267
|
-
import cache from "memory-cache";
|
|
268
|
-
|
|
269
|
-
// src/server/_utils/backend-url.ts
|
|
270
|
-
var getBackendUrl = () => {
|
|
271
|
-
return process.env.CLIENT_BACKEND_URL ? process.env.CLIENT_BACKEND_URL : "https://api.capibox.com";
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
// src/server/split/get-split-data.ts
|
|
275
|
-
var getSplitData = () => __async(null, null, function* () {
|
|
276
|
-
const cachedResponse = cache.get(CACHE_KEY_SPLIT);
|
|
277
|
-
if (cachedResponse) {
|
|
278
|
-
return cachedResponse;
|
|
279
|
-
} else {
|
|
280
|
-
try {
|
|
281
|
-
const res = yield fetch(`${getBackendUrl()}/funnels/split`, {
|
|
282
|
-
headers: {
|
|
283
|
-
"Content-Type": "application/json",
|
|
284
|
-
"Authorization": `${process.env.CAPIBOX_API_KEY}`
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
let resJson = [];
|
|
288
|
-
if (res.ok) {
|
|
289
|
-
resJson = yield res.json();
|
|
290
|
-
}
|
|
291
|
-
cache.put(CACHE_KEY_SPLIT, resJson, 2147483647);
|
|
292
|
-
return resJson;
|
|
293
|
-
} catch (e) {
|
|
294
|
-
return [];
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
// src/server/_utils/trim-char.ts
|
|
300
|
-
var trimChar = (string2, charToRemove) => {
|
|
301
|
-
while (string2.charAt(0) == charToRemove) {
|
|
302
|
-
string2 = string2.substring(1);
|
|
303
|
-
}
|
|
304
|
-
while (string2.charAt(string2.length - 1) == charToRemove) {
|
|
305
|
-
string2 = string2.substring(0, string2.length - 1);
|
|
306
|
-
}
|
|
307
|
-
return string2;
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
// src/server/split/get-split-item.ts
|
|
311
|
-
var getSplitItemForPath = (_0) => __async(null, [_0], function* ({ path }) {
|
|
312
|
-
const splits = yield getSplitData();
|
|
313
|
-
const inputs = splits.filter((i) => i.active).map((i) => `/${trimChar(i.url ? i.url : "", "/")}`);
|
|
314
|
-
const inputIndex = inputs.indexOf(path);
|
|
315
|
-
if (inputIndex >= 0) {
|
|
316
|
-
return splits[inputIndex];
|
|
317
|
-
}
|
|
318
|
-
return void 0;
|
|
319
|
-
});
|
|
320
|
-
var getSplitItemForReq = (_0) => __async(null, [_0], function* ({ req }) {
|
|
321
|
-
return yield getSplitItemForPath({ path: req.nextUrl.pathname });
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
// src/server/split/get-split-winner.ts
|
|
325
|
-
var getSplitItemUrlWinner = (item) => {
|
|
326
|
-
const splitValues = fillSplitItemUrlsRange(item);
|
|
327
|
-
const _time = (/* @__PURE__ */ new Date()).getTime();
|
|
328
|
-
const _seed100 = _time % 100;
|
|
329
|
-
let currentSplit = splitValues.find(
|
|
330
|
-
(e) => e.range.start <= _seed100 && e.range.finish > _seed100
|
|
331
|
-
);
|
|
332
|
-
if (!currentSplit) {
|
|
333
|
-
currentSplit = splitValues[0];
|
|
334
|
-
}
|
|
335
|
-
return currentSplit;
|
|
336
|
-
};
|
|
337
|
-
var fillSplitItemUrlsRange = (item) => {
|
|
338
|
-
const splits = item.splits ? item.splits : [];
|
|
339
|
-
return splits.map((curr, i, data) => {
|
|
340
|
-
const minPercent = data.slice(0, i).map((a) => a.split).reduce((a, b) => a + b, 0);
|
|
341
|
-
return __spreadProps(__spreadValues({}, curr), {
|
|
342
|
-
range: {
|
|
343
|
-
start: minPercent,
|
|
344
|
-
finish: minPercent + curr.split
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
// src/browser/funnels/get-capibox-templates.ts
|
|
351
|
-
import cache2 from "memory-cache";
|
|
352
|
-
var getCapiboxTemplates = () => __async(null, null, function* () {
|
|
353
|
-
const cachedResponse = cache2.get(CACHE_KEY_FUNNELS);
|
|
354
|
-
if (cachedResponse) {
|
|
355
|
-
return cachedResponse;
|
|
356
|
-
} else {
|
|
357
|
-
const funnelRes = yield fetch(`${getBackendUrl()}/funnels/funnel`, {
|
|
358
|
-
headers: {
|
|
359
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
const responseBody = yield funnelRes.json();
|
|
363
|
-
cache2.put(CACHE_KEY_FUNNELS, responseBody, 2147483647);
|
|
364
|
-
return responseBody;
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
// src/server/middleware.ts
|
|
369
|
-
var middleware = (req, options) => __async(null, null, function* () {
|
|
370
|
-
if (req.nextUrl.pathname.startsWith("/app/clear-cache")) {
|
|
371
|
-
cache3.del(CACHE_KEY_FUNNELS);
|
|
372
|
-
cache3.del(CACHE_KEY_SPLIT);
|
|
373
|
-
const res = NextResponse.json({ s: (/* @__PURE__ */ new Date()).getTime() });
|
|
374
|
-
res.headers.append("Access-Control-Allow-Credentials", "true");
|
|
375
|
-
res.headers.append("Access-Control-Allow-Origin", "*");
|
|
376
|
-
res.headers.append("Access-Control-Allow-Methods", "GET,DELETE,PATCH,POST,PUT");
|
|
377
|
-
res.headers.append(
|
|
378
|
-
"Access-Control-Allow-Headers",
|
|
379
|
-
"X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version"
|
|
380
|
-
);
|
|
381
|
-
return res;
|
|
382
|
-
}
|
|
383
|
-
if ((options == null ? void 0 : options.templates) && req.nextUrl.pathname.startsWith("/app/get-templates")) {
|
|
384
|
-
const res = NextResponse.json({
|
|
385
|
-
success: true,
|
|
386
|
-
data: options.templates
|
|
387
|
-
});
|
|
388
|
-
res.headers.append("Access-Control-Allow-Credentials", "true");
|
|
389
|
-
res.headers.append("Access-Control-Allow-Origin", "*");
|
|
390
|
-
res.headers.append("Access-Control-Allow-Methods", "GET,DELETE,PATCH,POST,PUT");
|
|
391
|
-
res.headers.append(
|
|
392
|
-
"Access-Control-Allow-Headers",
|
|
393
|
-
"X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version"
|
|
394
|
-
);
|
|
395
|
-
return res;
|
|
396
|
-
}
|
|
397
|
-
const input = yield getSplitItemForReq({ req });
|
|
398
|
-
if (input) {
|
|
399
|
-
const currentSplit = getSplitItemUrlWinner(input);
|
|
400
|
-
return NextResponse.redirect(
|
|
401
|
-
new URL(`/${trimChar(currentSplit.url, "/")}${req.nextUrl.search}`, req.url)
|
|
402
|
-
);
|
|
403
|
-
}
|
|
404
|
-
if (req.nextUrl.pathname.startsWith("/api-client-proxy")) {
|
|
405
|
-
if (req.nextUrl.pathname === "/api-client-proxy/funnels/funnel") {
|
|
406
|
-
const capiboxTemplates = yield getCapiboxTemplates();
|
|
407
|
-
const res = NextResponse.json(capiboxTemplates);
|
|
408
|
-
res.headers.set("X-Cache", "HIT");
|
|
409
|
-
return res;
|
|
410
|
-
}
|
|
411
|
-
let urlClone = req.nextUrl.clone();
|
|
412
|
-
const targetUrl = new URL(getBackendUrl());
|
|
413
|
-
const requestHeaders = new Headers(req.headers);
|
|
414
|
-
requestHeaders.set("host", targetUrl.hostname);
|
|
415
|
-
requestHeaders.set("project-key", `${process.env.CAPIBOX_API_KEY}`);
|
|
416
|
-
if (req.nextUrl.pathname.includes("/realtime/")) {
|
|
417
|
-
const ip2 = getClientIp({ headers: Object.fromEntries(req.headers) });
|
|
418
|
-
const { device, browser: browser2, os } = userAgent(req);
|
|
419
|
-
requestHeaders.set("x-client-ip", ip2);
|
|
420
|
-
requestHeaders.set("x-os", `${os.name} / ${os.version}`);
|
|
421
|
-
requestHeaders.set("x-browser", `${browser2.name} / ${browser2.version}`);
|
|
422
|
-
requestHeaders.set("x-device", device.type ? device.type : "-");
|
|
423
|
-
const anUuidV3Cookie = req.cookies.get("an_uuid_v3");
|
|
424
|
-
if (anUuidV3Cookie) {
|
|
425
|
-
requestHeaders.set("x-realtime", anUuidV3Cookie == null ? void 0 : anUuidV3Cookie.value);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
if (req.nextUrl.pathname === "/api-client-proxy/session") {
|
|
429
|
-
const ip2 = getClientIp({ headers: Object.fromEntries(req.headers) });
|
|
430
|
-
const { ua } = userAgent(req);
|
|
431
|
-
requestHeaders.set("x-client-ip", ip2);
|
|
432
|
-
requestHeaders.set("x-user-agent", ua);
|
|
433
|
-
}
|
|
434
|
-
urlClone.protocol = targetUrl.protocol;
|
|
435
|
-
urlClone.hostname = targetUrl.hostname;
|
|
436
|
-
urlClone.port = targetUrl.port;
|
|
437
|
-
urlClone.pathname = urlClone.pathname.replace(/^\/api-client-proxy/, "");
|
|
438
|
-
return NextResponse.rewrite(urlClone, {
|
|
439
|
-
headers: requestHeaders
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
if (req.nextUrl.pathname === CRM_AUTH_SIGN_IN_PATH) {
|
|
443
|
-
const res = yield fetch(
|
|
444
|
-
"https://auth.crm.apidata.app/api/sign-in",
|
|
445
|
-
{
|
|
446
|
-
method: "POST",
|
|
447
|
-
body: JSON.stringify(yield req.json()),
|
|
448
|
-
headers: serverProxyHeaders()
|
|
449
|
-
}
|
|
450
|
-
);
|
|
451
|
-
const resJson = yield res.json();
|
|
452
|
-
const result = NextResponse.json(resJson);
|
|
453
|
-
if (!!resJson.action && !!resJson.token && resJson.action === "logged-in") {
|
|
454
|
-
result.cookies.set({
|
|
455
|
-
name: "token",
|
|
456
|
-
value: resJson.token,
|
|
457
|
-
maxAge: 60 * 60 * 24 * 30,
|
|
458
|
-
httpOnly: true
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
return result;
|
|
462
|
-
}
|
|
463
|
-
if (req.nextUrl.pathname === CRM_AUTH_VERIFY_PATH) {
|
|
464
|
-
const tokenCookie = req.cookies.get("token");
|
|
465
|
-
if (!tokenCookie || !tokenCookie.value) {
|
|
466
|
-
return NextResponse.json({ success: 0 });
|
|
467
|
-
}
|
|
468
|
-
const payload = {
|
|
469
|
-
data: {
|
|
470
|
-
token: tokenCookie.value
|
|
471
|
-
}
|
|
472
|
-
};
|
|
473
|
-
const res = yield fetch(
|
|
474
|
-
"https://auth.crm.apidata.app/api/check",
|
|
475
|
-
{
|
|
476
|
-
method: "POST",
|
|
477
|
-
body: JSON.stringify(payload),
|
|
478
|
-
headers: serverProxyHeaders()
|
|
479
|
-
}
|
|
480
|
-
);
|
|
481
|
-
const resJson = yield res.json();
|
|
482
|
-
const result = NextResponse.json(resJson);
|
|
483
|
-
if (!("id" in resJson && resJson.id > 0)) {
|
|
484
|
-
result.cookies.delete("token");
|
|
485
|
-
}
|
|
486
|
-
return result;
|
|
487
|
-
}
|
|
488
|
-
if (req.nextUrl.pathname === CRM_AUTH_SIGN_OUT_PATH) {
|
|
489
|
-
const res = NextResponse.json({ success: 1 });
|
|
490
|
-
res.cookies.delete("token");
|
|
491
|
-
return res;
|
|
492
|
-
}
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
// src/browser/_utils/browser-get-cookie.ts
|
|
496
|
-
var getCookie = (name) => {
|
|
497
|
-
const value = `; ${document.cookie}`;
|
|
498
|
-
const parts = value.split(`; ${name}=`);
|
|
499
|
-
if (parts.length === 2) {
|
|
500
|
-
const res = parts.pop();
|
|
501
|
-
if (res) {
|
|
502
|
-
return res.split(";").shift();
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
return "";
|
|
506
|
-
};
|
|
507
|
-
|
|
508
|
-
// src/browser/session/create.ts
|
|
509
|
-
var createSession = (_a) => __async(null, null, function* () {
|
|
510
|
-
var _b = _a, { language, email, currency, quiz } = _b, data = __objRest(_b, ["language", "email", "currency", "quiz"]);
|
|
511
|
-
const urlSearchParams = new URLSearchParams(window.location.search);
|
|
512
|
-
const params = Object.fromEntries(urlSearchParams.entries());
|
|
513
|
-
const cookies = window.document.cookie;
|
|
514
|
-
const referer = window.document.referrer;
|
|
515
|
-
const origin = window.location.origin;
|
|
516
|
-
const slug = window.location.pathname;
|
|
517
|
-
const res = yield $apiClient.POST(
|
|
518
|
-
"/session",
|
|
519
|
-
{
|
|
520
|
-
params: {
|
|
521
|
-
header: {
|
|
522
|
-
"project-key": "Frontend"
|
|
523
|
-
}
|
|
524
|
-
},
|
|
525
|
-
body: __spreadProps(__spreadValues({}, data), {
|
|
526
|
-
origin,
|
|
527
|
-
referer,
|
|
528
|
-
cookies,
|
|
529
|
-
query: params,
|
|
530
|
-
slug,
|
|
531
|
-
analyticsId: getCookie("an_uuid"),
|
|
532
|
-
analyticsIdv3: getCookie("an_uuid_v3"),
|
|
533
|
-
extraData: __spreadProps(__spreadValues({}, data.extraData), {
|
|
534
|
-
language,
|
|
535
|
-
currency,
|
|
536
|
-
email,
|
|
537
|
-
quiz: quiz ? quiz : void 0
|
|
538
|
-
})
|
|
539
|
-
})
|
|
540
|
-
}
|
|
541
|
-
);
|
|
542
|
-
if (!res.data) {
|
|
543
|
-
throw new Error("Failed to create session.");
|
|
544
|
-
}
|
|
545
|
-
return res.data.data;
|
|
546
|
-
});
|
|
547
|
-
|
|
548
|
-
// src/browser/_utils/browser-fetch-utils.ts
|
|
549
|
-
var fetchJsonPostOptions = (data) => {
|
|
550
|
-
return {
|
|
551
|
-
method: "POST",
|
|
552
|
-
body: JSON.stringify(data),
|
|
553
|
-
headers: {
|
|
554
|
-
"Content-Type": "application/json"
|
|
555
|
-
}
|
|
556
|
-
};
|
|
557
|
-
};
|
|
558
|
-
|
|
559
|
-
// src/browser/crm-auth/sign-in.ts
|
|
560
|
-
var signIn = (data) => __async(null, null, function* () {
|
|
561
|
-
const res = yield fetch(
|
|
562
|
-
CRM_AUTH_SIGN_IN_PATH,
|
|
563
|
-
fetchJsonPostOptions(data)
|
|
564
|
-
);
|
|
565
|
-
return yield res.json();
|
|
566
|
-
});
|
|
567
|
-
|
|
568
|
-
// src/browser/crm-auth/sign-out.ts
|
|
569
|
-
var signOut = () => __async(null, null, function* () {
|
|
570
|
-
const res = yield fetch(
|
|
571
|
-
CRM_AUTH_SIGN_OUT_PATH,
|
|
572
|
-
fetchJsonPostOptions({})
|
|
573
|
-
);
|
|
574
|
-
return yield res.json();
|
|
575
|
-
});
|
|
576
|
-
|
|
577
|
-
// src/browser/crm-auth/veirfy.ts
|
|
578
|
-
var verify = () => __async(null, null, function* () {
|
|
579
|
-
const res = yield fetch(
|
|
580
|
-
CRM_AUTH_VERIFY_PATH,
|
|
581
|
-
fetchJsonPostOptions({})
|
|
582
|
-
);
|
|
583
|
-
return yield res.json();
|
|
584
|
-
});
|
|
585
|
-
|
|
586
41
|
// src/browser/hooks/useParamsLandingPage.ts
|
|
587
42
|
import { useParams } from "next/navigation";
|
|
588
43
|
var useParamsLandingPage = () => {
|
|
@@ -602,63 +57,28 @@ var useParamsLandingPage = () => {
|
|
|
602
57
|
};
|
|
603
58
|
};
|
|
604
59
|
|
|
605
|
-
// src/
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
}
|
|
613
|
-
};
|
|
614
|
-
|
|
615
|
-
// src/browser/realtime/track-event.ts
|
|
616
|
-
var trackEvent = (type, uuid, options) => __async(null, null, function* () {
|
|
617
|
-
try {
|
|
618
|
-
const skipGa = !!(!!options && options.skipGa);
|
|
619
|
-
if (!skipGa) {
|
|
620
|
-
const gaOptions = !!options && !!options.ga ? options.ga : void 0;
|
|
621
|
-
gaTrackEvent(type, gaOptions);
|
|
622
|
-
}
|
|
623
|
-
const urlSearchParams = new URLSearchParams(window.location.search);
|
|
624
|
-
const params = Object.fromEntries(urlSearchParams.entries());
|
|
625
|
-
const pathLength = !!options && !!options.path && !!options.path.length ? options.path.length : 3;
|
|
626
|
-
const pathname = !!options && !!options.path && !!options.path.pathname ? options.path.pathname : window.location.pathname.split("/").slice(1, pathLength).join("/");
|
|
627
|
-
const referer = !!options && !!options.path && !!options.path.referer ? options.path.referer : window.document.referrer;
|
|
628
|
-
const origin = !!options && !!options.path && !!options.path.origin ? options.path.origin : window.location.origin;
|
|
629
|
-
const eventData = {
|
|
630
|
-
type,
|
|
631
|
-
uuid,
|
|
632
|
-
pathname,
|
|
633
|
-
referer,
|
|
634
|
-
origin,
|
|
635
|
-
query: params,
|
|
636
|
-
attr: options == null ? void 0 : options.attr,
|
|
637
|
-
eventData: options == null ? void 0 : options.eventData
|
|
638
|
-
};
|
|
639
|
-
yield $apiClient.POST("/realtime/events/track-event", {
|
|
640
|
-
body: eventData
|
|
641
|
-
});
|
|
642
|
-
} catch (e) {
|
|
60
|
+
// src/lib/api.ts
|
|
61
|
+
import createFetchClient from "openapi-fetch";
|
|
62
|
+
var endpoint = "/api-client-proxy";
|
|
63
|
+
var $apiClient = createFetchClient({
|
|
64
|
+
baseUrl: endpoint,
|
|
65
|
+
headers: {
|
|
66
|
+
"project-key": "Frontend"
|
|
643
67
|
}
|
|
644
68
|
});
|
|
645
69
|
|
|
646
70
|
// src/browser/funnels/get.ts
|
|
647
71
|
var getFunnels = () => __async(null, null, function* () {
|
|
648
72
|
let response = [];
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
params: {
|
|
654
|
-
header: {
|
|
655
|
-
"project-key": "Frontend"
|
|
656
|
-
}
|
|
73
|
+
const res = yield $apiClient.GET("/funnels/funnel", {
|
|
74
|
+
params: {
|
|
75
|
+
header: {
|
|
76
|
+
"project-key": "Frontend"
|
|
657
77
|
}
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
if (!res || !res.data) return [];
|
|
81
|
+
response = res.data;
|
|
662
82
|
const tmpFunnels = response;
|
|
663
83
|
const output = [];
|
|
664
84
|
for (const funnel of tmpFunnels) {
|
|
@@ -681,206 +101,6 @@ var getFunnels = () => __async(null, null, function* () {
|
|
|
681
101
|
return output;
|
|
682
102
|
});
|
|
683
103
|
|
|
684
|
-
// src/browser/verify/email/verify-email.ts
|
|
685
|
-
var verifyEmail = (email) => __async(null, null, function* () {
|
|
686
|
-
const res = yield $apiClient.GET(
|
|
687
|
-
"/verify/email",
|
|
688
|
-
{
|
|
689
|
-
params: {
|
|
690
|
-
query: {
|
|
691
|
-
email
|
|
692
|
-
},
|
|
693
|
-
header: {
|
|
694
|
-
"project-key": "FrontEnd"
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
);
|
|
699
|
-
return res.data;
|
|
700
|
-
});
|
|
701
|
-
|
|
702
|
-
// src/browser/verify/phone/verify-phone.ts
|
|
703
|
-
var verifyPhone = (phone) => __async(null, null, function* () {
|
|
704
|
-
const res = yield $apiClient.GET(
|
|
705
|
-
"/verify/phone",
|
|
706
|
-
{
|
|
707
|
-
params: {
|
|
708
|
-
query: {
|
|
709
|
-
phone
|
|
710
|
-
},
|
|
711
|
-
header: {
|
|
712
|
-
"project-key": "FrontEnd"
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
);
|
|
717
|
-
return res.data;
|
|
718
|
-
});
|
|
719
|
-
|
|
720
|
-
// src/browser/session/get.ts
|
|
721
|
-
var getSession = (uuid) => __async(null, null, function* () {
|
|
722
|
-
const res = yield $apiClient.GET(
|
|
723
|
-
"/session/{uuid}",
|
|
724
|
-
{
|
|
725
|
-
params: {
|
|
726
|
-
path: {
|
|
727
|
-
uuid
|
|
728
|
-
},
|
|
729
|
-
header: {
|
|
730
|
-
"project-key": "Frontend"
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
);
|
|
735
|
-
if (!res.data) {
|
|
736
|
-
throw new Error("Failed to append session.");
|
|
737
|
-
}
|
|
738
|
-
return res.data.data;
|
|
739
|
-
});
|
|
740
|
-
|
|
741
|
-
// src/browser/quiz/get.ts
|
|
742
|
-
var getQuiz = (uuid) => __async(null, null, function* () {
|
|
743
|
-
const res = yield $apiClient.GET(
|
|
744
|
-
"/quiz/{uuid}",
|
|
745
|
-
{
|
|
746
|
-
params: {
|
|
747
|
-
path: {
|
|
748
|
-
uuid
|
|
749
|
-
},
|
|
750
|
-
header: {
|
|
751
|
-
"project-key": "Frontend"
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
);
|
|
756
|
-
if (!res.data) {
|
|
757
|
-
throw new Error("Failed to append session.");
|
|
758
|
-
}
|
|
759
|
-
return res.data.data;
|
|
760
|
-
});
|
|
761
|
-
|
|
762
|
-
// src/browser/capi/facebook-s2s.ts
|
|
763
|
-
var facebookS2S = (data) => __async(null, null, function* () {
|
|
764
|
-
yield $apiClient.POST("/analytics/capi/facebook/event", {
|
|
765
|
-
params: {
|
|
766
|
-
header: {
|
|
767
|
-
"project-key": "Frontend"
|
|
768
|
-
}
|
|
769
|
-
},
|
|
770
|
-
body: data
|
|
771
|
-
});
|
|
772
|
-
return { success: true };
|
|
773
|
-
});
|
|
774
|
-
|
|
775
|
-
// src/browser/payments/create-session.ts
|
|
776
|
-
var createSession2 = (data) => __async(null, null, function* () {
|
|
777
|
-
const res = yield $apiClient.POST("/payments/create-session", {
|
|
778
|
-
params: {
|
|
779
|
-
header: {
|
|
780
|
-
"project-key": "Frontend"
|
|
781
|
-
}
|
|
782
|
-
},
|
|
783
|
-
body: data
|
|
784
|
-
});
|
|
785
|
-
if (!res.data) {
|
|
786
|
-
throw new Error("Failed to create payment session.");
|
|
787
|
-
}
|
|
788
|
-
return res.data;
|
|
789
|
-
});
|
|
790
|
-
|
|
791
|
-
// src/browser/payments/paypal/paypal-start-order.ts
|
|
792
|
-
var paypalStartOrder = (uuid) => __async(null, null, function* () {
|
|
793
|
-
const res = yield $apiClient.GET(
|
|
794
|
-
"/payments/paypal/order/{id}/start",
|
|
795
|
-
{
|
|
796
|
-
params: {
|
|
797
|
-
header: {
|
|
798
|
-
"project-key": "Frontend"
|
|
799
|
-
},
|
|
800
|
-
path: {
|
|
801
|
-
id: uuid
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
);
|
|
806
|
-
if (!res.data) {
|
|
807
|
-
throw new Error("Failed to create payment session.");
|
|
808
|
-
}
|
|
809
|
-
return res.data;
|
|
810
|
-
});
|
|
811
|
-
|
|
812
|
-
// src/browser/payments/paypal/paypal-capture-order.ts
|
|
813
|
-
var paypalCaptureOrder = (uuid) => __async(null, null, function* () {
|
|
814
|
-
const res = yield $apiClient.GET(
|
|
815
|
-
"/payments/paypal/order/{id}/capture",
|
|
816
|
-
{
|
|
817
|
-
params: {
|
|
818
|
-
header: {
|
|
819
|
-
"project-key": "Frontend"
|
|
820
|
-
},
|
|
821
|
-
path: {
|
|
822
|
-
id: uuid
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
);
|
|
827
|
-
if (!res.data) {
|
|
828
|
-
throw new Error("Failed to create payment session.");
|
|
829
|
-
}
|
|
830
|
-
return res.data;
|
|
831
|
-
});
|
|
832
|
-
|
|
833
|
-
// src/browser/trustpilot/get-link.ts
|
|
834
|
-
var trustpilotGetLink = (data) => __async(null, null, function* () {
|
|
835
|
-
const res = yield $apiClient.POST("/trustpilot/get-link", {
|
|
836
|
-
params: {
|
|
837
|
-
header: {
|
|
838
|
-
"project-key": "Frontend"
|
|
839
|
-
}
|
|
840
|
-
},
|
|
841
|
-
body: data
|
|
842
|
-
});
|
|
843
|
-
if (!res.data) {
|
|
844
|
-
throw new Error("Failed to create payment session.");
|
|
845
|
-
}
|
|
846
|
-
return res.data;
|
|
847
|
-
});
|
|
848
|
-
|
|
849
|
-
// src/browser/trustpilot/send-invintation.ts
|
|
850
|
-
var trustpilotSendInvitation = (data) => __async(null, null, function* () {
|
|
851
|
-
const res = yield $apiClient.POST("/trustpilot/send-invitation", {
|
|
852
|
-
params: {
|
|
853
|
-
header: {
|
|
854
|
-
"project-key": "Frontend"
|
|
855
|
-
}
|
|
856
|
-
},
|
|
857
|
-
body: data
|
|
858
|
-
});
|
|
859
|
-
if (!res.data) {
|
|
860
|
-
throw new Error("Failed to create payment session.");
|
|
861
|
-
}
|
|
862
|
-
return res.data;
|
|
863
|
-
});
|
|
864
|
-
|
|
865
|
-
// src/browser/payments/yuno/yuno-create-payment.ts
|
|
866
|
-
var yunoCreatePayment = (dto) => __async(null, null, function* () {
|
|
867
|
-
const res = yield $apiClient.POST(
|
|
868
|
-
"/payments/yuno/create-payment",
|
|
869
|
-
{
|
|
870
|
-
params: {
|
|
871
|
-
header: {
|
|
872
|
-
"project-key": "Frontend"
|
|
873
|
-
}
|
|
874
|
-
},
|
|
875
|
-
body: dto
|
|
876
|
-
}
|
|
877
|
-
);
|
|
878
|
-
if (!res.data) {
|
|
879
|
-
throw new Error("Failed to create payment session.");
|
|
880
|
-
}
|
|
881
|
-
return res.data;
|
|
882
|
-
});
|
|
883
|
-
|
|
884
104
|
// src/browser/funnels/get-templates.ts
|
|
885
105
|
var defaultTemplate = {
|
|
886
106
|
homePageTemplate: "Default",
|
|
@@ -926,63 +146,17 @@ var getTemplates = (_0) => __async(null, [_0], function* ({
|
|
|
926
146
|
});
|
|
927
147
|
|
|
928
148
|
// src/index.ts
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
},
|
|
933
|
-
mail: {
|
|
934
|
-
sendToRecipient,
|
|
935
|
-
sendToSupport
|
|
936
|
-
},
|
|
937
|
-
session: {
|
|
938
|
-
append: appendSession,
|
|
939
|
-
create: createSession,
|
|
940
|
-
get: getSession
|
|
941
|
-
},
|
|
942
|
-
crmAuth: {
|
|
943
|
-
signIn,
|
|
944
|
-
signOut,
|
|
945
|
-
verify
|
|
946
|
-
},
|
|
149
|
+
import { server } from "@capibox/bridge-server";
|
|
150
|
+
import { browser as clientBrowser } from "@capibox/bridge-browser";
|
|
151
|
+
var browser = __spreadValues({
|
|
947
152
|
hooks: {
|
|
948
153
|
useParamsLandingPage
|
|
949
154
|
},
|
|
950
|
-
realtime: {
|
|
951
|
-
trackEvent
|
|
952
|
-
},
|
|
953
|
-
funnels: {
|
|
954
|
-
get: getFunnels,
|
|
955
|
-
getTemplates
|
|
956
|
-
},
|
|
957
|
-
verify: {
|
|
958
|
-
email: verifyEmail,
|
|
959
|
-
phone: verifyPhone
|
|
960
|
-
},
|
|
961
|
-
quiz: {
|
|
962
|
-
get: getQuiz
|
|
963
|
-
},
|
|
964
|
-
payments: {
|
|
965
|
-
createSession: createSession2,
|
|
966
|
-
paypal: {
|
|
967
|
-
startOrder: paypalStartOrder,
|
|
968
|
-
captureOrder: paypalCaptureOrder
|
|
969
|
-
},
|
|
970
|
-
yuno: {
|
|
971
|
-
createPayment: yunoCreatePayment
|
|
972
|
-
}
|
|
973
|
-
},
|
|
974
|
-
trustpilot: {
|
|
975
|
-
getLink: trustpilotGetLink,
|
|
976
|
-
sendInvitation: trustpilotSendInvitation
|
|
977
|
-
}
|
|
978
|
-
};
|
|
979
|
-
var server = {
|
|
980
|
-
middleware,
|
|
981
155
|
funnels: {
|
|
982
156
|
get: getFunnels,
|
|
983
157
|
getTemplates
|
|
984
158
|
}
|
|
985
|
-
};
|
|
159
|
+
}, clientBrowser);
|
|
986
160
|
if (typeof window !== "undefined") {
|
|
987
161
|
window.capibox = browser;
|
|
988
162
|
}
|