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