@capibox/bridge-server 0.0.86 → 0.0.92
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.d.mts +603 -9940
- package/dist/index.d.ts +603 -9940
- package/dist/index.js +107 -614
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +107 -614
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -38,6 +38,105 @@ var __async = (__this, __arguments, generator) => {
|
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
+
// src/browser/funnels/get-capibox-templates.ts
|
|
42
|
+
import cache from "memory-cache";
|
|
43
|
+
|
|
44
|
+
// src/server/cache/cache.ts
|
|
45
|
+
var CACHE_KEY_FUNNELS = "funnels-data";
|
|
46
|
+
var CACHE_KEY_SPLIT = "split-data";
|
|
47
|
+
|
|
48
|
+
// src/server/_utils/backend-url.ts
|
|
49
|
+
var getBackendUrl = () => {
|
|
50
|
+
return process.env.CLIENT_BACKEND_URL ? process.env.CLIENT_BACKEND_URL : "https://api.capibox.com";
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/browser/funnels/get-capibox-templates.ts
|
|
54
|
+
var getCapiboxTemplates = () => __async(null, null, function* () {
|
|
55
|
+
const cachedResponse = cache.get(CACHE_KEY_FUNNELS);
|
|
56
|
+
if (cachedResponse) {
|
|
57
|
+
return cachedResponse;
|
|
58
|
+
} else {
|
|
59
|
+
const funnelRes = yield fetch(`${getBackendUrl()}/funnels/funnel`, {
|
|
60
|
+
headers: {
|
|
61
|
+
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const responseBody = yield funnelRes.json();
|
|
65
|
+
cache.put(CACHE_KEY_FUNNELS, responseBody, 2147483647);
|
|
66
|
+
return responseBody;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// src/browser/funnels/get.ts
|
|
71
|
+
var getFunnels = () => __async(null, null, function* () {
|
|
72
|
+
const tmpFunnels = yield getCapiboxTemplates();
|
|
73
|
+
const output = [];
|
|
74
|
+
for (const funnel of tmpFunnels) {
|
|
75
|
+
output.push({
|
|
76
|
+
landing: funnel.angle,
|
|
77
|
+
checkout: funnel.version,
|
|
78
|
+
angle: funnel.angle,
|
|
79
|
+
version: funnel.version,
|
|
80
|
+
homePageTemplate: funnel.home_page || "Default",
|
|
81
|
+
quizPageTemplate: funnel.quiz_page || "Default",
|
|
82
|
+
resultPageTemplate: funnel.results_page || "Default",
|
|
83
|
+
emailPageTemplate: funnel.email_page || "Default",
|
|
84
|
+
checkoutPageTemplate: funnel.checkout_page || "Default",
|
|
85
|
+
paymentWindowTemplate: funnel.payment_window || "Default",
|
|
86
|
+
upsellPageTemplate: funnel.upsell_page || "Default",
|
|
87
|
+
thankYouPageTemplate: funnel.thankyou_page_template || "Default",
|
|
88
|
+
options: funnel.options,
|
|
89
|
+
upsellOptions: funnel.upsell_options
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return output;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// src/browser/funnels/get-templates.ts
|
|
96
|
+
var defaultTemplate = {
|
|
97
|
+
homePageTemplate: "Default",
|
|
98
|
+
quizPageTemplate: "Default",
|
|
99
|
+
resultPageTemplate: "Default",
|
|
100
|
+
emailPageTemplate: "Default",
|
|
101
|
+
checkoutPageTemplate: "Default",
|
|
102
|
+
paymentWindowTemplate: "Default",
|
|
103
|
+
upsellPageTemplate: "Default",
|
|
104
|
+
thankYouPageTemplate: "Default"
|
|
105
|
+
};
|
|
106
|
+
var getTemplates = (_0) => __async(null, [_0], function* ({
|
|
107
|
+
angle,
|
|
108
|
+
version,
|
|
109
|
+
searchParams
|
|
110
|
+
}) {
|
|
111
|
+
const funnelsData = yield getFunnels();
|
|
112
|
+
const filteredFunnelsData = funnelsData.filter((a) => {
|
|
113
|
+
if ((a.checkout === version || a.checkout === "any") && (a.landing === angle || a.landing === "any")) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
});
|
|
118
|
+
if (filteredFunnelsData.length > 0) {
|
|
119
|
+
const _flowData = JSON.parse(
|
|
120
|
+
JSON.stringify(filteredFunnelsData[filteredFunnelsData.length - 1])
|
|
121
|
+
);
|
|
122
|
+
if (searchParams) {
|
|
123
|
+
const keys = Object.keys(defaultTemplate);
|
|
124
|
+
for (const key of keys) {
|
|
125
|
+
if (searchParams.get(key)) {
|
|
126
|
+
_flowData[key] = searchParams.get(key);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return _flowData;
|
|
131
|
+
}
|
|
132
|
+
return __spreadProps(__spreadValues({}, defaultTemplate), {
|
|
133
|
+
landing: angle,
|
|
134
|
+
checkout: version,
|
|
135
|
+
angle,
|
|
136
|
+
version
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
41
140
|
// src/server/middleware.ts
|
|
42
141
|
import { NextResponse, userAgent } from "next/server";
|
|
43
142
|
|
|
@@ -177,21 +276,10 @@ var serverProxyHeaders = () => {
|
|
|
177
276
|
// src/server/middleware.ts
|
|
178
277
|
import cache3 from "memory-cache";
|
|
179
278
|
|
|
180
|
-
// src/server/cache/cache.ts
|
|
181
|
-
var CACHE_KEY_FUNNELS = "funnels-data";
|
|
182
|
-
var CACHE_KEY_SPLIT = "split-data";
|
|
183
|
-
|
|
184
|
-
// src/server/split/get-split-data.ts
|
|
185
|
-
import cache from "memory-cache";
|
|
186
|
-
|
|
187
|
-
// src/server/_utils/backend-url.ts
|
|
188
|
-
var getBackendUrl = () => {
|
|
189
|
-
return process.env.CLIENT_BACKEND_URL ? process.env.CLIENT_BACKEND_URL : "https://api.capibox.com";
|
|
190
|
-
};
|
|
191
|
-
|
|
192
279
|
// src/server/split/get-split-data.ts
|
|
280
|
+
import cache2 from "memory-cache";
|
|
193
281
|
var getSplitData = () => __async(null, null, function* () {
|
|
194
|
-
const cachedResponse =
|
|
282
|
+
const cachedResponse = cache2.get(CACHE_KEY_SPLIT);
|
|
195
283
|
if (cachedResponse) {
|
|
196
284
|
return cachedResponse;
|
|
197
285
|
} else {
|
|
@@ -206,7 +294,7 @@ var getSplitData = () => __async(null, null, function* () {
|
|
|
206
294
|
if (res.ok) {
|
|
207
295
|
resJson = yield res.json();
|
|
208
296
|
}
|
|
209
|
-
|
|
297
|
+
cache2.put(CACHE_KEY_SPLIT, resJson, 2147483647);
|
|
210
298
|
return resJson;
|
|
211
299
|
} catch (e) {
|
|
212
300
|
return [];
|
|
@@ -265,24 +353,6 @@ var fillSplitItemUrlsRange = (item) => {
|
|
|
265
353
|
});
|
|
266
354
|
};
|
|
267
355
|
|
|
268
|
-
// src/browser/funnels/get-capibox-templates.ts
|
|
269
|
-
import cache2 from "memory-cache";
|
|
270
|
-
var getCapiboxTemplates = () => __async(null, null, function* () {
|
|
271
|
-
const cachedResponse = cache2.get(CACHE_KEY_FUNNELS);
|
|
272
|
-
if (cachedResponse) {
|
|
273
|
-
return cachedResponse;
|
|
274
|
-
} else {
|
|
275
|
-
const funnelRes = yield fetch(`${getBackendUrl()}/funnels/funnel`, {
|
|
276
|
-
headers: {
|
|
277
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
const responseBody = yield funnelRes.json();
|
|
281
|
-
cache2.put(CACHE_KEY_FUNNELS, responseBody, 2147483647);
|
|
282
|
-
return responseBody;
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
|
|
286
356
|
// src/server/middleware.ts
|
|
287
357
|
var middleware = (req, options) => __async(null, null, function* () {
|
|
288
358
|
if (req.nextUrl.pathname.startsWith("/app/clear-cache")) {
|
|
@@ -415,119 +485,6 @@ var middleware = (req, options) => __async(null, null, function* () {
|
|
|
415
485
|
}
|
|
416
486
|
});
|
|
417
487
|
|
|
418
|
-
// src/browser/funnels/get.ts
|
|
419
|
-
var getFunnels = () => __async(null, null, function* () {
|
|
420
|
-
const tmpFunnels = yield getCapiboxTemplates();
|
|
421
|
-
const output = [];
|
|
422
|
-
for (const funnel of tmpFunnels) {
|
|
423
|
-
output.push({
|
|
424
|
-
landing: funnel.angle,
|
|
425
|
-
checkout: funnel.version,
|
|
426
|
-
angle: funnel.angle,
|
|
427
|
-
version: funnel.version,
|
|
428
|
-
homePageTemplate: funnel.home_page || "Default",
|
|
429
|
-
quizPageTemplate: funnel.quiz_page || "Default",
|
|
430
|
-
resultPageTemplate: funnel.results_page || "Default",
|
|
431
|
-
emailPageTemplate: funnel.email_page || "Default",
|
|
432
|
-
checkoutPageTemplate: funnel.checkout_page || "Default",
|
|
433
|
-
paymentWindowTemplate: funnel.payment_window || "Default",
|
|
434
|
-
upsellPageTemplate: funnel.upsell_page || "Default",
|
|
435
|
-
thankYouPageTemplate: funnel.thankyou_page_template || "Default",
|
|
436
|
-
options: funnel.options,
|
|
437
|
-
upsellOptions: funnel.upsell_options
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
return output;
|
|
441
|
-
});
|
|
442
|
-
|
|
443
|
-
// src/browser/funnels/get-templates.ts
|
|
444
|
-
var defaultTemplate = {
|
|
445
|
-
homePageTemplate: "Default",
|
|
446
|
-
quizPageTemplate: "Default",
|
|
447
|
-
resultPageTemplate: "Default",
|
|
448
|
-
emailPageTemplate: "Default",
|
|
449
|
-
checkoutPageTemplate: "Default",
|
|
450
|
-
paymentWindowTemplate: "Default",
|
|
451
|
-
upsellPageTemplate: "Default",
|
|
452
|
-
thankYouPageTemplate: "Default"
|
|
453
|
-
};
|
|
454
|
-
var getTemplates = (_0) => __async(null, [_0], function* ({
|
|
455
|
-
angle,
|
|
456
|
-
version,
|
|
457
|
-
searchParams
|
|
458
|
-
}) {
|
|
459
|
-
const funnelsData = yield getFunnels();
|
|
460
|
-
const filteredFunnelsData = funnelsData.filter((a) => {
|
|
461
|
-
if ((a.checkout === version || a.checkout === "any") && (a.landing === angle || a.landing === "any")) {
|
|
462
|
-
return true;
|
|
463
|
-
}
|
|
464
|
-
return false;
|
|
465
|
-
});
|
|
466
|
-
if (filteredFunnelsData.length > 0) {
|
|
467
|
-
const _flowData = JSON.parse(
|
|
468
|
-
JSON.stringify(filteredFunnelsData[filteredFunnelsData.length - 1])
|
|
469
|
-
);
|
|
470
|
-
if (searchParams) {
|
|
471
|
-
const keys = Object.keys(defaultTemplate);
|
|
472
|
-
for (const key of keys) {
|
|
473
|
-
if (searchParams.get(key)) {
|
|
474
|
-
_flowData[key] = searchParams.get(key);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
return _flowData;
|
|
479
|
-
}
|
|
480
|
-
return __spreadProps(__spreadValues({}, defaultTemplate), {
|
|
481
|
-
landing: angle,
|
|
482
|
-
checkout: version,
|
|
483
|
-
angle,
|
|
484
|
-
version
|
|
485
|
-
});
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
// src/lib/api.ts
|
|
489
|
-
import createFetchClient from "openapi-fetch";
|
|
490
|
-
var $apiClient = createFetchClient({
|
|
491
|
-
baseUrl: getBackendUrl(),
|
|
492
|
-
headers: {
|
|
493
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
494
|
-
}
|
|
495
|
-
});
|
|
496
|
-
|
|
497
|
-
// src/server/session/get.ts
|
|
498
|
-
var getSession = (uuid) => __async(null, null, function* () {
|
|
499
|
-
const res = yield $apiClient.GET(
|
|
500
|
-
"/session/{uuid}",
|
|
501
|
-
{
|
|
502
|
-
params: {
|
|
503
|
-
path: {
|
|
504
|
-
uuid
|
|
505
|
-
},
|
|
506
|
-
header: {
|
|
507
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
);
|
|
512
|
-
if (!res.data) {
|
|
513
|
-
throw new Error("Failed to get session.");
|
|
514
|
-
}
|
|
515
|
-
return res.data.data;
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
// src/server/capi/snapchat-s2s.ts
|
|
519
|
-
var snapchatS2s = (data) => __async(null, null, function* () {
|
|
520
|
-
yield $apiClient.POST("/analytics/capi/snapchat/event", {
|
|
521
|
-
params: {
|
|
522
|
-
header: {
|
|
523
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
524
|
-
}
|
|
525
|
-
},
|
|
526
|
-
body: data
|
|
527
|
-
});
|
|
528
|
-
return { success: true };
|
|
529
|
-
});
|
|
530
|
-
|
|
531
488
|
// src/server/funnels/clear-cache.ts
|
|
532
489
|
import cache4 from "memory-cache";
|
|
533
490
|
var funnelsClearCache = () => {
|
|
@@ -535,481 +492,17 @@ var funnelsClearCache = () => {
|
|
|
535
492
|
cache4.del(CACHE_KEY_SPLIT);
|
|
536
493
|
};
|
|
537
494
|
|
|
538
|
-
// src/server/capi/tiktok-s2s.ts
|
|
539
|
-
var tiktokS2S = (data) => __async(null, null, function* () {
|
|
540
|
-
yield $apiClient.POST("/analytics/capi/tiktok/event", {
|
|
541
|
-
params: {
|
|
542
|
-
header: {
|
|
543
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
544
|
-
}
|
|
545
|
-
},
|
|
546
|
-
body: data
|
|
547
|
-
});
|
|
548
|
-
return { success: true };
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
// src/server/capi/facebook-s2s.ts
|
|
552
|
-
var facebookS2S = (data) => __async(null, null, function* () {
|
|
553
|
-
yield $apiClient.POST("/analytics/capi/facebook/event", {
|
|
554
|
-
params: {
|
|
555
|
-
header: {
|
|
556
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
557
|
-
}
|
|
558
|
-
},
|
|
559
|
-
body: data
|
|
560
|
-
});
|
|
561
|
-
return { success: true };
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
// src/server/session/append.ts
|
|
565
|
-
var appendSession = (uuid, body) => __async(null, null, function* () {
|
|
566
|
-
const res = yield $apiClient.PUT(
|
|
567
|
-
"/session/{uuid}",
|
|
568
|
-
{
|
|
569
|
-
params: {
|
|
570
|
-
path: {
|
|
571
|
-
uuid
|
|
572
|
-
},
|
|
573
|
-
header: {
|
|
574
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
575
|
-
}
|
|
576
|
-
},
|
|
577
|
-
body
|
|
578
|
-
}
|
|
579
|
-
);
|
|
580
|
-
if (!res.data) {
|
|
581
|
-
throw new Error("Failed to append session.");
|
|
582
|
-
}
|
|
583
|
-
return res.data.data;
|
|
584
|
-
});
|
|
585
|
-
|
|
586
|
-
// src/server/session/getByEmail.ts
|
|
587
|
-
var getSessionByEmail = (email) => __async(null, null, function* () {
|
|
588
|
-
const res = yield $apiClient.GET(
|
|
589
|
-
"/session/email/{email}",
|
|
590
|
-
{
|
|
591
|
-
params: {
|
|
592
|
-
path: {
|
|
593
|
-
uuid: email
|
|
594
|
-
},
|
|
595
|
-
header: {
|
|
596
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
);
|
|
601
|
-
if (!res.data) {
|
|
602
|
-
throw new Error("Failed to get session.");
|
|
603
|
-
}
|
|
604
|
-
return res.data.data;
|
|
605
|
-
});
|
|
606
|
-
|
|
607
|
-
// src/server/klaviyo/klaviyo-send-event.ts
|
|
608
|
-
var klaviyoSendEvent = (dto) => __async(null, null, function* () {
|
|
609
|
-
const res = yield $apiClient.POST(
|
|
610
|
-
"/dynamic-public-direct/klaviyo/events",
|
|
611
|
-
{
|
|
612
|
-
params: {
|
|
613
|
-
header: {
|
|
614
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
615
|
-
}
|
|
616
|
-
},
|
|
617
|
-
body: dto
|
|
618
|
-
}
|
|
619
|
-
);
|
|
620
|
-
if (!res.data) {
|
|
621
|
-
throw new Error("Failed to create payment session.");
|
|
622
|
-
}
|
|
623
|
-
return res.data;
|
|
624
|
-
});
|
|
625
|
-
|
|
626
|
-
// src/server/klaviyo/klaviyo-send-bulk.ts
|
|
627
|
-
var klaviyoSendBulk = (dto) => __async(null, null, function* () {
|
|
628
|
-
const res = yield $apiClient.POST(
|
|
629
|
-
"/dynamic-public-direct/klaviyo/events/bulk",
|
|
630
|
-
{
|
|
631
|
-
params: {
|
|
632
|
-
header: {
|
|
633
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
634
|
-
}
|
|
635
|
-
},
|
|
636
|
-
body: dto
|
|
637
|
-
}
|
|
638
|
-
);
|
|
639
|
-
if (!res.data) {
|
|
640
|
-
throw new Error("Failed to create payment session.");
|
|
641
|
-
}
|
|
642
|
-
return res.data;
|
|
643
|
-
});
|
|
644
|
-
|
|
645
|
-
// src/server/realtime/realtime-utm-order-data.ts
|
|
646
|
-
var realtimeUtmOrderData = (uuid) => __async(null, null, function* () {
|
|
647
|
-
const res = yield $apiClient.GET(
|
|
648
|
-
"/realtime/events/utm-data/{uuid}",
|
|
649
|
-
{
|
|
650
|
-
params: {
|
|
651
|
-
path: {
|
|
652
|
-
uuid
|
|
653
|
-
},
|
|
654
|
-
header: {
|
|
655
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
);
|
|
660
|
-
if (!res.data) {
|
|
661
|
-
throw new Error("Failed to get realtime utm data.");
|
|
662
|
-
}
|
|
663
|
-
return res.data;
|
|
664
|
-
});
|
|
665
|
-
|
|
666
|
-
// src/server/order/order-get-by-uuid.ts
|
|
667
|
-
var orderGetByUuid = (uuid) => __async(null, null, function* () {
|
|
668
|
-
const res = yield $apiClient.GET(
|
|
669
|
-
"/dynamic-public/orders-management/report-item/order/{orderId}",
|
|
670
|
-
{
|
|
671
|
-
params: {
|
|
672
|
-
header: {
|
|
673
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
674
|
-
},
|
|
675
|
-
path: {
|
|
676
|
-
orderId: uuid
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
);
|
|
681
|
-
if (!res.data) {
|
|
682
|
-
throw new Error("Failed to get order by uuid.");
|
|
683
|
-
}
|
|
684
|
-
return res.data;
|
|
685
|
-
});
|
|
686
|
-
|
|
687
|
-
// src/server/order/order-get-by-email.ts
|
|
688
|
-
var orderGetByEmail = (email) => __async(null, null, function* () {
|
|
689
|
-
const res = yield $apiClient.GET(
|
|
690
|
-
"/dynamic-public/orders-management/report-item/email/{email}",
|
|
691
|
-
{
|
|
692
|
-
params: {
|
|
693
|
-
header: {
|
|
694
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
695
|
-
},
|
|
696
|
-
path: {
|
|
697
|
-
email
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
);
|
|
702
|
-
if (!res.data) {
|
|
703
|
-
throw new Error("Failed to get order by email.");
|
|
704
|
-
}
|
|
705
|
-
return res.data;
|
|
706
|
-
});
|
|
707
|
-
|
|
708
|
-
// src/server/payments/payment-first-payment.ts
|
|
709
|
-
var paymentFirstPayment = (uuid) => __async(null, null, function* () {
|
|
710
|
-
const res = yield $apiClient.GET(
|
|
711
|
-
"/dynamic-public/payments-management/payments/first-payment",
|
|
712
|
-
{
|
|
713
|
-
params: {
|
|
714
|
-
header: {
|
|
715
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
716
|
-
},
|
|
717
|
-
query: {
|
|
718
|
-
referenceId: uuid
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
);
|
|
723
|
-
if (!res.data) {
|
|
724
|
-
throw new Error("Failed to get first payment.");
|
|
725
|
-
}
|
|
726
|
-
return res.data;
|
|
727
|
-
});
|
|
728
|
-
|
|
729
|
-
// src/server/payments/payment-last-payments.ts
|
|
730
|
-
var paymentLastPayments = (uuid) => __async(null, null, function* () {
|
|
731
|
-
const res = yield $apiClient.GET(
|
|
732
|
-
"/dynamic-public/payments-management/payments/last-5-payments",
|
|
733
|
-
{
|
|
734
|
-
params: {
|
|
735
|
-
header: {
|
|
736
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
737
|
-
},
|
|
738
|
-
query: {
|
|
739
|
-
referenceId: uuid
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
);
|
|
744
|
-
if (!res.data) {
|
|
745
|
-
throw new Error("Failed to get last payments.");
|
|
746
|
-
}
|
|
747
|
-
return res.data;
|
|
748
|
-
});
|
|
749
|
-
|
|
750
|
-
// src/server/subscription/cancel-subscription-by-id.ts
|
|
751
|
-
var cancelSubscriptionById = (id, data) => __async(null, null, function* () {
|
|
752
|
-
const res = yield $apiClient.POST("/dynamic-public/subscriptions-management/subscriptions/{id}/cancel", {
|
|
753
|
-
params: {
|
|
754
|
-
header: {
|
|
755
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
756
|
-
},
|
|
757
|
-
path: {
|
|
758
|
-
id
|
|
759
|
-
}
|
|
760
|
-
},
|
|
761
|
-
body: data
|
|
762
|
-
});
|
|
763
|
-
if (!res.data) {
|
|
764
|
-
throw new Error("Failed to cancel subscription.");
|
|
765
|
-
}
|
|
766
|
-
return res.data;
|
|
767
|
-
});
|
|
768
|
-
|
|
769
|
-
// src/server/subscription/cancel-subscriptions-by-order-id.ts
|
|
770
|
-
var cancelSubscriptionsByOrderId = (uuid, data) => __async(null, null, function* () {
|
|
771
|
-
const res = yield $apiClient.POST("/dynamic-public/subscriptions-management/subscriptions/order/{orderId}/cancel", {
|
|
772
|
-
params: {
|
|
773
|
-
header: {
|
|
774
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
775
|
-
},
|
|
776
|
-
path: {
|
|
777
|
-
orderId: uuid
|
|
778
|
-
}
|
|
779
|
-
},
|
|
780
|
-
body: data
|
|
781
|
-
});
|
|
782
|
-
if (!res.data) {
|
|
783
|
-
throw new Error("Failed to cancel subscription.");
|
|
784
|
-
}
|
|
785
|
-
return res.data;
|
|
786
|
-
});
|
|
787
|
-
|
|
788
|
-
// src/server/subscription/subscription-apply-discount.ts
|
|
789
|
-
var subscriptionApplyDiscount = (data) => __async(null, null, function* () {
|
|
790
|
-
const res = yield $apiClient.POST("/dynamic-public/subscriptions-management/subscriptions/discount", {
|
|
791
|
-
params: {
|
|
792
|
-
header: {
|
|
793
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
794
|
-
}
|
|
795
|
-
},
|
|
796
|
-
body: data
|
|
797
|
-
});
|
|
798
|
-
if (!res.data) {
|
|
799
|
-
throw new Error("Failed to apply discount.");
|
|
800
|
-
}
|
|
801
|
-
return res.data;
|
|
802
|
-
});
|
|
803
|
-
|
|
804
|
-
// src/server/subscription/subscription-pause.ts
|
|
805
|
-
var subscriptionPause = (data) => __async(null, null, function* () {
|
|
806
|
-
const res = yield $apiClient.POST("/dynamic-public/subscriptions-management/subscriptions/pause", {
|
|
807
|
-
params: {
|
|
808
|
-
header: {
|
|
809
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
810
|
-
}
|
|
811
|
-
},
|
|
812
|
-
body: data
|
|
813
|
-
});
|
|
814
|
-
if (!res.data) {
|
|
815
|
-
throw new Error("Failed to pause subscription.");
|
|
816
|
-
}
|
|
817
|
-
return res.data;
|
|
818
|
-
});
|
|
819
|
-
|
|
820
|
-
// src/server/subscription/fill-subscription-cancel-request.ts
|
|
821
|
-
var fillSubscriptionCancelRequest = (data) => __async(null, null, function* () {
|
|
822
|
-
const res = yield $apiClient.POST("/dynamic-public/subscriptions-management/subscription-cancel-requests", {
|
|
823
|
-
params: {
|
|
824
|
-
header: {
|
|
825
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
826
|
-
}
|
|
827
|
-
},
|
|
828
|
-
body: data
|
|
829
|
-
});
|
|
830
|
-
if (!res.data) {
|
|
831
|
-
throw new Error("Failed to fill request.");
|
|
832
|
-
}
|
|
833
|
-
return res.data;
|
|
834
|
-
});
|
|
835
|
-
|
|
836
|
-
// src/server/subscription/get-subscriptions-by-order-id.ts
|
|
837
|
-
var getSubscriptionsByOrderId = (uuid) => __async(null, null, function* () {
|
|
838
|
-
const res = yield $apiClient.GET(
|
|
839
|
-
"/dynamic-public/subscriptions-management/subscriptions/info-by-orderid",
|
|
840
|
-
{
|
|
841
|
-
params: {
|
|
842
|
-
header: {
|
|
843
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
844
|
-
},
|
|
845
|
-
query: {
|
|
846
|
-
orderId: uuid
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
);
|
|
851
|
-
if (!res.data) {
|
|
852
|
-
throw new Error("Failed to get subscriptions by order id.");
|
|
853
|
-
}
|
|
854
|
-
return res.data;
|
|
855
|
-
});
|
|
856
|
-
|
|
857
|
-
// src/server/payments/primer/primer-refund-payment.ts
|
|
858
|
-
var primerRefundPayment = (transactionId, source, dto) => __async(null, null, function* () {
|
|
859
|
-
const res = yield $apiClient.POST(
|
|
860
|
-
"/dynamic-public/payments-primer/v1/primer-payment/{transactionId}/refund-or-cancel",
|
|
861
|
-
{
|
|
862
|
-
params: {
|
|
863
|
-
header: {
|
|
864
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`,
|
|
865
|
-
"x-source": source
|
|
866
|
-
},
|
|
867
|
-
path: {
|
|
868
|
-
transactionId
|
|
869
|
-
}
|
|
870
|
-
},
|
|
871
|
-
body: dto
|
|
872
|
-
}
|
|
873
|
-
);
|
|
874
|
-
if (!res.data) {
|
|
875
|
-
throw new Error("Failed to refund primer payment.");
|
|
876
|
-
}
|
|
877
|
-
return res.data;
|
|
878
|
-
});
|
|
879
|
-
|
|
880
|
-
// src/server/payments/paypal/paypal-refund-payment.ts
|
|
881
|
-
var paypalRefundPayment = (source, dto) => __async(null, null, function* () {
|
|
882
|
-
const res = yield $apiClient.POST(
|
|
883
|
-
"/dynamic-public/payments-paypal/payments/refund",
|
|
884
|
-
{
|
|
885
|
-
params: {
|
|
886
|
-
header: {
|
|
887
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`,
|
|
888
|
-
"x-source": source
|
|
889
|
-
}
|
|
890
|
-
},
|
|
891
|
-
body: dto
|
|
892
|
-
}
|
|
893
|
-
);
|
|
894
|
-
if (!res.data) {
|
|
895
|
-
throw new Error("Failed to refund paypal payment.");
|
|
896
|
-
}
|
|
897
|
-
return res.data;
|
|
898
|
-
});
|
|
899
|
-
|
|
900
|
-
// src/server/payments/payments-refund.ts
|
|
901
|
-
var paymentsRefund = (_0) => __async(null, [_0], function* ({
|
|
902
|
-
source,
|
|
903
|
-
transactionId,
|
|
904
|
-
amount,
|
|
905
|
-
reason,
|
|
906
|
-
orderId,
|
|
907
|
-
currency
|
|
908
|
-
}) {
|
|
909
|
-
if (source.startsWith("primer")) {
|
|
910
|
-
return yield primerRefundPayment(transactionId, source, {
|
|
911
|
-
amount,
|
|
912
|
-
reason
|
|
913
|
-
});
|
|
914
|
-
} else if (source.startsWith("paypal")) {
|
|
915
|
-
return yield paypalRefundPayment(
|
|
916
|
-
source,
|
|
917
|
-
{
|
|
918
|
-
amount,
|
|
919
|
-
orderId,
|
|
920
|
-
transactionId,
|
|
921
|
-
currency
|
|
922
|
-
}
|
|
923
|
-
);
|
|
924
|
-
}
|
|
925
|
-
throw new Error("Unknown payment source");
|
|
926
|
-
});
|
|
927
|
-
|
|
928
|
-
// src/server/payments/tax/get-tax-percent.ts
|
|
929
|
-
var getTaxPercent = (data) => __async(null, null, function* () {
|
|
930
|
-
const res = yield $apiClient.POST("/dynamic-public/tax/tax/get", {
|
|
931
|
-
params: {
|
|
932
|
-
header: {
|
|
933
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
934
|
-
}
|
|
935
|
-
},
|
|
936
|
-
body: data
|
|
937
|
-
});
|
|
938
|
-
if (!res.data) {
|
|
939
|
-
throw new Error("Failed to get tax percent.");
|
|
940
|
-
}
|
|
941
|
-
return res.data;
|
|
942
|
-
});
|
|
943
|
-
|
|
944
|
-
// src/server/payments/tax/tax-calculate-amount.ts
|
|
945
|
-
var taxCalculateAmount = (data) => __async(null, null, function* () {
|
|
946
|
-
const res = yield $apiClient.POST("/dynamic-public/tax/tax/calculate", {
|
|
947
|
-
params: {
|
|
948
|
-
header: {
|
|
949
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
950
|
-
}
|
|
951
|
-
},
|
|
952
|
-
body: data
|
|
953
|
-
});
|
|
954
|
-
if (!res.data) {
|
|
955
|
-
throw new Error("Failed to create payment session.");
|
|
956
|
-
}
|
|
957
|
-
return res.data;
|
|
958
|
-
});
|
|
959
|
-
|
|
960
495
|
// src/index.ts
|
|
961
|
-
|
|
962
|
-
|
|
496
|
+
import { server as serverSdk } from "@capibox/bridge-server-sdk";
|
|
497
|
+
var server = __spreadProps(__spreadValues({
|
|
498
|
+
middleware
|
|
499
|
+
}, serverSdk), {
|
|
963
500
|
funnels: {
|
|
964
501
|
get: getFunnels,
|
|
965
502
|
getTemplates,
|
|
966
503
|
clearCache: funnelsClearCache
|
|
967
|
-
},
|
|
968
|
-
session: {
|
|
969
|
-
get: getSession,
|
|
970
|
-
append: appendSession,
|
|
971
|
-
getByEmail: getSessionByEmail
|
|
972
|
-
},
|
|
973
|
-
capi: {
|
|
974
|
-
snapchat: snapchatS2s,
|
|
975
|
-
tiktok: tiktokS2S,
|
|
976
|
-
facebook: facebookS2S
|
|
977
|
-
},
|
|
978
|
-
klaviyo: {
|
|
979
|
-
send: klaviyoSendEvent,
|
|
980
|
-
sendBulk: klaviyoSendBulk
|
|
981
|
-
},
|
|
982
|
-
realtime: {
|
|
983
|
-
orderUtmData: realtimeUtmOrderData
|
|
984
|
-
},
|
|
985
|
-
order: {
|
|
986
|
-
getByUuid: orderGetByUuid,
|
|
987
|
-
getByEmail: orderGetByEmail
|
|
988
|
-
},
|
|
989
|
-
payments: {
|
|
990
|
-
firstPayment: paymentFirstPayment,
|
|
991
|
-
last5Payments: paymentLastPayments,
|
|
992
|
-
refund: paymentsRefund,
|
|
993
|
-
primer: {
|
|
994
|
-
refund: primerRefundPayment
|
|
995
|
-
},
|
|
996
|
-
paypal: {
|
|
997
|
-
refund: paypalRefundPayment
|
|
998
|
-
},
|
|
999
|
-
tax: {
|
|
1000
|
-
getPercent: getTaxPercent,
|
|
1001
|
-
calculate: taxCalculateAmount
|
|
1002
|
-
}
|
|
1003
|
-
},
|
|
1004
|
-
subscription: {
|
|
1005
|
-
cancelById: cancelSubscriptionById,
|
|
1006
|
-
cancelByOrderId: cancelSubscriptionsByOrderId,
|
|
1007
|
-
applyDiscount: subscriptionApplyDiscount,
|
|
1008
|
-
pause: subscriptionPause,
|
|
1009
|
-
fillCancellationRequest: fillSubscriptionCancelRequest,
|
|
1010
|
-
get: getSubscriptionsByOrderId
|
|
1011
504
|
}
|
|
1012
|
-
};
|
|
505
|
+
});
|
|
1013
506
|
export {
|
|
1014
507
|
server
|
|
1015
508
|
};
|