@capibox/bridge-server 0.0.90 → 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 -10618
- package/dist/index.d.ts +603 -10618
- 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.js
CHANGED
|
@@ -71,6 +71,105 @@ __export(index_exports, {
|
|
|
71
71
|
});
|
|
72
72
|
module.exports = __toCommonJS(index_exports);
|
|
73
73
|
|
|
74
|
+
// src/browser/funnels/get-capibox-templates.ts
|
|
75
|
+
var import_memory_cache = __toESM(require("memory-cache"));
|
|
76
|
+
|
|
77
|
+
// src/server/cache/cache.ts
|
|
78
|
+
var CACHE_KEY_FUNNELS = "funnels-data";
|
|
79
|
+
var CACHE_KEY_SPLIT = "split-data";
|
|
80
|
+
|
|
81
|
+
// src/server/_utils/backend-url.ts
|
|
82
|
+
var getBackendUrl = () => {
|
|
83
|
+
return process.env.CLIENT_BACKEND_URL ? process.env.CLIENT_BACKEND_URL : "https://api.capibox.com";
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// src/browser/funnels/get-capibox-templates.ts
|
|
87
|
+
var getCapiboxTemplates = () => __async(null, null, function* () {
|
|
88
|
+
const cachedResponse = import_memory_cache.default.get(CACHE_KEY_FUNNELS);
|
|
89
|
+
if (cachedResponse) {
|
|
90
|
+
return cachedResponse;
|
|
91
|
+
} else {
|
|
92
|
+
const funnelRes = yield fetch(`${getBackendUrl()}/funnels/funnel`, {
|
|
93
|
+
headers: {
|
|
94
|
+
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
const responseBody = yield funnelRes.json();
|
|
98
|
+
import_memory_cache.default.put(CACHE_KEY_FUNNELS, responseBody, 2147483647);
|
|
99
|
+
return responseBody;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// src/browser/funnels/get.ts
|
|
104
|
+
var getFunnels = () => __async(null, null, function* () {
|
|
105
|
+
const tmpFunnels = yield getCapiboxTemplates();
|
|
106
|
+
const output = [];
|
|
107
|
+
for (const funnel of tmpFunnels) {
|
|
108
|
+
output.push({
|
|
109
|
+
landing: funnel.angle,
|
|
110
|
+
checkout: funnel.version,
|
|
111
|
+
angle: funnel.angle,
|
|
112
|
+
version: funnel.version,
|
|
113
|
+
homePageTemplate: funnel.home_page || "Default",
|
|
114
|
+
quizPageTemplate: funnel.quiz_page || "Default",
|
|
115
|
+
resultPageTemplate: funnel.results_page || "Default",
|
|
116
|
+
emailPageTemplate: funnel.email_page || "Default",
|
|
117
|
+
checkoutPageTemplate: funnel.checkout_page || "Default",
|
|
118
|
+
paymentWindowTemplate: funnel.payment_window || "Default",
|
|
119
|
+
upsellPageTemplate: funnel.upsell_page || "Default",
|
|
120
|
+
thankYouPageTemplate: funnel.thankyou_page_template || "Default",
|
|
121
|
+
options: funnel.options,
|
|
122
|
+
upsellOptions: funnel.upsell_options
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return output;
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// src/browser/funnels/get-templates.ts
|
|
129
|
+
var defaultTemplate = {
|
|
130
|
+
homePageTemplate: "Default",
|
|
131
|
+
quizPageTemplate: "Default",
|
|
132
|
+
resultPageTemplate: "Default",
|
|
133
|
+
emailPageTemplate: "Default",
|
|
134
|
+
checkoutPageTemplate: "Default",
|
|
135
|
+
paymentWindowTemplate: "Default",
|
|
136
|
+
upsellPageTemplate: "Default",
|
|
137
|
+
thankYouPageTemplate: "Default"
|
|
138
|
+
};
|
|
139
|
+
var getTemplates = (_0) => __async(null, [_0], function* ({
|
|
140
|
+
angle,
|
|
141
|
+
version,
|
|
142
|
+
searchParams
|
|
143
|
+
}) {
|
|
144
|
+
const funnelsData = yield getFunnels();
|
|
145
|
+
const filteredFunnelsData = funnelsData.filter((a) => {
|
|
146
|
+
if ((a.checkout === version || a.checkout === "any") && (a.landing === angle || a.landing === "any")) {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
return false;
|
|
150
|
+
});
|
|
151
|
+
if (filteredFunnelsData.length > 0) {
|
|
152
|
+
const _flowData = JSON.parse(
|
|
153
|
+
JSON.stringify(filteredFunnelsData[filteredFunnelsData.length - 1])
|
|
154
|
+
);
|
|
155
|
+
if (searchParams) {
|
|
156
|
+
const keys = Object.keys(defaultTemplate);
|
|
157
|
+
for (const key of keys) {
|
|
158
|
+
if (searchParams.get(key)) {
|
|
159
|
+
_flowData[key] = searchParams.get(key);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return _flowData;
|
|
164
|
+
}
|
|
165
|
+
return __spreadProps(__spreadValues({}, defaultTemplate), {
|
|
166
|
+
landing: angle,
|
|
167
|
+
checkout: version,
|
|
168
|
+
angle,
|
|
169
|
+
version
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
74
173
|
// src/server/middleware.ts
|
|
75
174
|
var import_server = require("next/server");
|
|
76
175
|
|
|
@@ -210,21 +309,10 @@ var serverProxyHeaders = () => {
|
|
|
210
309
|
// src/server/middleware.ts
|
|
211
310
|
var import_memory_cache3 = __toESM(require("memory-cache"));
|
|
212
311
|
|
|
213
|
-
// src/server/cache/cache.ts
|
|
214
|
-
var CACHE_KEY_FUNNELS = "funnels-data";
|
|
215
|
-
var CACHE_KEY_SPLIT = "split-data";
|
|
216
|
-
|
|
217
|
-
// src/server/split/get-split-data.ts
|
|
218
|
-
var import_memory_cache = __toESM(require("memory-cache"));
|
|
219
|
-
|
|
220
|
-
// src/server/_utils/backend-url.ts
|
|
221
|
-
var getBackendUrl = () => {
|
|
222
|
-
return process.env.CLIENT_BACKEND_URL ? process.env.CLIENT_BACKEND_URL : "https://api.capibox.com";
|
|
223
|
-
};
|
|
224
|
-
|
|
225
312
|
// src/server/split/get-split-data.ts
|
|
313
|
+
var import_memory_cache2 = __toESM(require("memory-cache"));
|
|
226
314
|
var getSplitData = () => __async(null, null, function* () {
|
|
227
|
-
const cachedResponse =
|
|
315
|
+
const cachedResponse = import_memory_cache2.default.get(CACHE_KEY_SPLIT);
|
|
228
316
|
if (cachedResponse) {
|
|
229
317
|
return cachedResponse;
|
|
230
318
|
} else {
|
|
@@ -239,7 +327,7 @@ var getSplitData = () => __async(null, null, function* () {
|
|
|
239
327
|
if (res.ok) {
|
|
240
328
|
resJson = yield res.json();
|
|
241
329
|
}
|
|
242
|
-
|
|
330
|
+
import_memory_cache2.default.put(CACHE_KEY_SPLIT, resJson, 2147483647);
|
|
243
331
|
return resJson;
|
|
244
332
|
} catch (e) {
|
|
245
333
|
return [];
|
|
@@ -298,24 +386,6 @@ var fillSplitItemUrlsRange = (item) => {
|
|
|
298
386
|
});
|
|
299
387
|
};
|
|
300
388
|
|
|
301
|
-
// src/browser/funnels/get-capibox-templates.ts
|
|
302
|
-
var import_memory_cache2 = __toESM(require("memory-cache"));
|
|
303
|
-
var getCapiboxTemplates = () => __async(null, null, function* () {
|
|
304
|
-
const cachedResponse = import_memory_cache2.default.get(CACHE_KEY_FUNNELS);
|
|
305
|
-
if (cachedResponse) {
|
|
306
|
-
return cachedResponse;
|
|
307
|
-
} else {
|
|
308
|
-
const funnelRes = yield fetch(`${getBackendUrl()}/funnels/funnel`, {
|
|
309
|
-
headers: {
|
|
310
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
const responseBody = yield funnelRes.json();
|
|
314
|
-
import_memory_cache2.default.put(CACHE_KEY_FUNNELS, responseBody, 2147483647);
|
|
315
|
-
return responseBody;
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
|
|
319
389
|
// src/server/middleware.ts
|
|
320
390
|
var middleware = (req, options) => __async(null, null, function* () {
|
|
321
391
|
if (req.nextUrl.pathname.startsWith("/app/clear-cache")) {
|
|
@@ -448,119 +518,6 @@ var middleware = (req, options) => __async(null, null, function* () {
|
|
|
448
518
|
}
|
|
449
519
|
});
|
|
450
520
|
|
|
451
|
-
// src/browser/funnels/get.ts
|
|
452
|
-
var getFunnels = () => __async(null, null, function* () {
|
|
453
|
-
const tmpFunnels = yield getCapiboxTemplates();
|
|
454
|
-
const output = [];
|
|
455
|
-
for (const funnel of tmpFunnels) {
|
|
456
|
-
output.push({
|
|
457
|
-
landing: funnel.angle,
|
|
458
|
-
checkout: funnel.version,
|
|
459
|
-
angle: funnel.angle,
|
|
460
|
-
version: funnel.version,
|
|
461
|
-
homePageTemplate: funnel.home_page || "Default",
|
|
462
|
-
quizPageTemplate: funnel.quiz_page || "Default",
|
|
463
|
-
resultPageTemplate: funnel.results_page || "Default",
|
|
464
|
-
emailPageTemplate: funnel.email_page || "Default",
|
|
465
|
-
checkoutPageTemplate: funnel.checkout_page || "Default",
|
|
466
|
-
paymentWindowTemplate: funnel.payment_window || "Default",
|
|
467
|
-
upsellPageTemplate: funnel.upsell_page || "Default",
|
|
468
|
-
thankYouPageTemplate: funnel.thankyou_page_template || "Default",
|
|
469
|
-
options: funnel.options,
|
|
470
|
-
upsellOptions: funnel.upsell_options
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
return output;
|
|
474
|
-
});
|
|
475
|
-
|
|
476
|
-
// src/browser/funnels/get-templates.ts
|
|
477
|
-
var defaultTemplate = {
|
|
478
|
-
homePageTemplate: "Default",
|
|
479
|
-
quizPageTemplate: "Default",
|
|
480
|
-
resultPageTemplate: "Default",
|
|
481
|
-
emailPageTemplate: "Default",
|
|
482
|
-
checkoutPageTemplate: "Default",
|
|
483
|
-
paymentWindowTemplate: "Default",
|
|
484
|
-
upsellPageTemplate: "Default",
|
|
485
|
-
thankYouPageTemplate: "Default"
|
|
486
|
-
};
|
|
487
|
-
var getTemplates = (_0) => __async(null, [_0], function* ({
|
|
488
|
-
angle,
|
|
489
|
-
version,
|
|
490
|
-
searchParams
|
|
491
|
-
}) {
|
|
492
|
-
const funnelsData = yield getFunnels();
|
|
493
|
-
const filteredFunnelsData = funnelsData.filter((a) => {
|
|
494
|
-
if ((a.checkout === version || a.checkout === "any") && (a.landing === angle || a.landing === "any")) {
|
|
495
|
-
return true;
|
|
496
|
-
}
|
|
497
|
-
return false;
|
|
498
|
-
});
|
|
499
|
-
if (filteredFunnelsData.length > 0) {
|
|
500
|
-
const _flowData = JSON.parse(
|
|
501
|
-
JSON.stringify(filteredFunnelsData[filteredFunnelsData.length - 1])
|
|
502
|
-
);
|
|
503
|
-
if (searchParams) {
|
|
504
|
-
const keys = Object.keys(defaultTemplate);
|
|
505
|
-
for (const key of keys) {
|
|
506
|
-
if (searchParams.get(key)) {
|
|
507
|
-
_flowData[key] = searchParams.get(key);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
return _flowData;
|
|
512
|
-
}
|
|
513
|
-
return __spreadProps(__spreadValues({}, defaultTemplate), {
|
|
514
|
-
landing: angle,
|
|
515
|
-
checkout: version,
|
|
516
|
-
angle,
|
|
517
|
-
version
|
|
518
|
-
});
|
|
519
|
-
});
|
|
520
|
-
|
|
521
|
-
// src/lib/api.ts
|
|
522
|
-
var import_openapi_fetch = __toESM(require("openapi-fetch"));
|
|
523
|
-
var $apiClient = (0, import_openapi_fetch.default)({
|
|
524
|
-
baseUrl: getBackendUrl(),
|
|
525
|
-
headers: {
|
|
526
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
527
|
-
}
|
|
528
|
-
});
|
|
529
|
-
|
|
530
|
-
// src/server/session/get.ts
|
|
531
|
-
var getSession = (uuid) => __async(null, null, function* () {
|
|
532
|
-
const res = yield $apiClient.GET(
|
|
533
|
-
"/session/{uuid}",
|
|
534
|
-
{
|
|
535
|
-
params: {
|
|
536
|
-
path: {
|
|
537
|
-
uuid
|
|
538
|
-
},
|
|
539
|
-
header: {
|
|
540
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
);
|
|
545
|
-
if (!res.data) {
|
|
546
|
-
throw new Error("Failed to get session.");
|
|
547
|
-
}
|
|
548
|
-
return res.data.data;
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
// src/server/capi/snapchat-s2s.ts
|
|
552
|
-
var snapchatS2s = (data) => __async(null, null, function* () {
|
|
553
|
-
yield $apiClient.POST("/analytics/capi/snapchat/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
521
|
// src/server/funnels/clear-cache.ts
|
|
565
522
|
var import_memory_cache4 = __toESM(require("memory-cache"));
|
|
566
523
|
var funnelsClearCache = () => {
|
|
@@ -568,481 +525,17 @@ var funnelsClearCache = () => {
|
|
|
568
525
|
import_memory_cache4.default.del(CACHE_KEY_SPLIT);
|
|
569
526
|
};
|
|
570
527
|
|
|
571
|
-
// src/server/capi/tiktok-s2s.ts
|
|
572
|
-
var tiktokS2S = (data) => __async(null, null, function* () {
|
|
573
|
-
yield $apiClient.POST("/analytics/capi/tiktok/event", {
|
|
574
|
-
params: {
|
|
575
|
-
header: {
|
|
576
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
577
|
-
}
|
|
578
|
-
},
|
|
579
|
-
body: data
|
|
580
|
-
});
|
|
581
|
-
return { success: true };
|
|
582
|
-
});
|
|
583
|
-
|
|
584
|
-
// src/server/capi/facebook-s2s.ts
|
|
585
|
-
var facebookS2S = (data) => __async(null, null, function* () {
|
|
586
|
-
yield $apiClient.POST("/analytics/capi/facebook/event", {
|
|
587
|
-
params: {
|
|
588
|
-
header: {
|
|
589
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
590
|
-
}
|
|
591
|
-
},
|
|
592
|
-
body: data
|
|
593
|
-
});
|
|
594
|
-
return { success: true };
|
|
595
|
-
});
|
|
596
|
-
|
|
597
|
-
// src/server/session/append.ts
|
|
598
|
-
var appendSession = (uuid, body) => __async(null, null, function* () {
|
|
599
|
-
const res = yield $apiClient.PUT(
|
|
600
|
-
"/session/{uuid}",
|
|
601
|
-
{
|
|
602
|
-
params: {
|
|
603
|
-
path: {
|
|
604
|
-
uuid
|
|
605
|
-
},
|
|
606
|
-
header: {
|
|
607
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
608
|
-
}
|
|
609
|
-
},
|
|
610
|
-
body
|
|
611
|
-
}
|
|
612
|
-
);
|
|
613
|
-
if (!res.data) {
|
|
614
|
-
throw new Error("Failed to append session.");
|
|
615
|
-
}
|
|
616
|
-
return res.data.data;
|
|
617
|
-
});
|
|
618
|
-
|
|
619
|
-
// src/server/session/getByEmail.ts
|
|
620
|
-
var getSessionByEmail = (email) => __async(null, null, function* () {
|
|
621
|
-
const res = yield $apiClient.GET(
|
|
622
|
-
"/session/email/{email}",
|
|
623
|
-
{
|
|
624
|
-
params: {
|
|
625
|
-
path: {
|
|
626
|
-
uuid: email
|
|
627
|
-
},
|
|
628
|
-
header: {
|
|
629
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
);
|
|
634
|
-
if (!res.data) {
|
|
635
|
-
throw new Error("Failed to get session.");
|
|
636
|
-
}
|
|
637
|
-
return res.data.data;
|
|
638
|
-
});
|
|
639
|
-
|
|
640
|
-
// src/server/klaviyo/klaviyo-send-event.ts
|
|
641
|
-
var klaviyoSendEvent = (dto) => __async(null, null, function* () {
|
|
642
|
-
const res = yield $apiClient.POST(
|
|
643
|
-
"/dynamic-public-direct/klaviyo/events",
|
|
644
|
-
{
|
|
645
|
-
params: {
|
|
646
|
-
header: {
|
|
647
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
648
|
-
}
|
|
649
|
-
},
|
|
650
|
-
body: dto
|
|
651
|
-
}
|
|
652
|
-
);
|
|
653
|
-
if (!res.data) {
|
|
654
|
-
throw new Error("Failed to create payment session.");
|
|
655
|
-
}
|
|
656
|
-
return res.data;
|
|
657
|
-
});
|
|
658
|
-
|
|
659
|
-
// src/server/klaviyo/klaviyo-send-bulk.ts
|
|
660
|
-
var klaviyoSendBulk = (dto) => __async(null, null, function* () {
|
|
661
|
-
const res = yield $apiClient.POST(
|
|
662
|
-
"/dynamic-public-direct/klaviyo/events/bulk",
|
|
663
|
-
{
|
|
664
|
-
params: {
|
|
665
|
-
header: {
|
|
666
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
667
|
-
}
|
|
668
|
-
},
|
|
669
|
-
body: dto
|
|
670
|
-
}
|
|
671
|
-
);
|
|
672
|
-
if (!res.data) {
|
|
673
|
-
throw new Error("Failed to create payment session.");
|
|
674
|
-
}
|
|
675
|
-
return res.data;
|
|
676
|
-
});
|
|
677
|
-
|
|
678
|
-
// src/server/realtime/realtime-utm-order-data.ts
|
|
679
|
-
var realtimeUtmOrderData = (uuid) => __async(null, null, function* () {
|
|
680
|
-
const res = yield $apiClient.GET(
|
|
681
|
-
"/realtime/events/utm-data/{uuid}",
|
|
682
|
-
{
|
|
683
|
-
params: {
|
|
684
|
-
path: {
|
|
685
|
-
uuid
|
|
686
|
-
},
|
|
687
|
-
header: {
|
|
688
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
);
|
|
693
|
-
if (!res.data) {
|
|
694
|
-
throw new Error("Failed to get realtime utm data.");
|
|
695
|
-
}
|
|
696
|
-
return res.data;
|
|
697
|
-
});
|
|
698
|
-
|
|
699
|
-
// src/server/order/order-get-by-uuid.ts
|
|
700
|
-
var orderGetByUuid = (uuid) => __async(null, null, function* () {
|
|
701
|
-
const res = yield $apiClient.GET(
|
|
702
|
-
"/dynamic-public/orders-management/report-item/order/{orderId}",
|
|
703
|
-
{
|
|
704
|
-
params: {
|
|
705
|
-
header: {
|
|
706
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
707
|
-
},
|
|
708
|
-
path: {
|
|
709
|
-
orderId: uuid
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
);
|
|
714
|
-
if (!res.data) {
|
|
715
|
-
throw new Error("Failed to get order by uuid.");
|
|
716
|
-
}
|
|
717
|
-
return res.data;
|
|
718
|
-
});
|
|
719
|
-
|
|
720
|
-
// src/server/order/order-get-by-email.ts
|
|
721
|
-
var orderGetByEmail = (email) => __async(null, null, function* () {
|
|
722
|
-
const res = yield $apiClient.GET(
|
|
723
|
-
"/dynamic-public/orders-management/report-item/email/{email}",
|
|
724
|
-
{
|
|
725
|
-
params: {
|
|
726
|
-
header: {
|
|
727
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
728
|
-
},
|
|
729
|
-
path: {
|
|
730
|
-
email
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
);
|
|
735
|
-
if (!res.data) {
|
|
736
|
-
throw new Error("Failed to get order by email.");
|
|
737
|
-
}
|
|
738
|
-
return res.data;
|
|
739
|
-
});
|
|
740
|
-
|
|
741
|
-
// src/server/payments/payment-first-payment.ts
|
|
742
|
-
var paymentFirstPayment = (uuid) => __async(null, null, function* () {
|
|
743
|
-
const res = yield $apiClient.GET(
|
|
744
|
-
"/dynamic-public/payments-management/payments/first-payment",
|
|
745
|
-
{
|
|
746
|
-
params: {
|
|
747
|
-
header: {
|
|
748
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
749
|
-
},
|
|
750
|
-
query: {
|
|
751
|
-
referenceId: uuid
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
);
|
|
756
|
-
if (!res.data) {
|
|
757
|
-
throw new Error("Failed to get first payment.");
|
|
758
|
-
}
|
|
759
|
-
return res.data;
|
|
760
|
-
});
|
|
761
|
-
|
|
762
|
-
// src/server/payments/payment-last-payments.ts
|
|
763
|
-
var paymentLastPayments = (uuid) => __async(null, null, function* () {
|
|
764
|
-
const res = yield $apiClient.GET(
|
|
765
|
-
"/dynamic-public/payments-management/payments/last-5-payments",
|
|
766
|
-
{
|
|
767
|
-
params: {
|
|
768
|
-
header: {
|
|
769
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
770
|
-
},
|
|
771
|
-
query: {
|
|
772
|
-
referenceId: uuid
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
);
|
|
777
|
-
if (!res.data) {
|
|
778
|
-
throw new Error("Failed to get last payments.");
|
|
779
|
-
}
|
|
780
|
-
return res.data;
|
|
781
|
-
});
|
|
782
|
-
|
|
783
|
-
// src/server/subscription/cancel-subscription-by-id.ts
|
|
784
|
-
var cancelSubscriptionById = (id, data) => __async(null, null, function* () {
|
|
785
|
-
const res = yield $apiClient.POST("/dynamic-public/subscriptions-management/subscriptions/{id}/cancel", {
|
|
786
|
-
params: {
|
|
787
|
-
header: {
|
|
788
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
789
|
-
},
|
|
790
|
-
path: {
|
|
791
|
-
id
|
|
792
|
-
}
|
|
793
|
-
},
|
|
794
|
-
body: data
|
|
795
|
-
});
|
|
796
|
-
if (!res.data) {
|
|
797
|
-
throw new Error("Failed to cancel subscription.");
|
|
798
|
-
}
|
|
799
|
-
return res.data;
|
|
800
|
-
});
|
|
801
|
-
|
|
802
|
-
// src/server/subscription/cancel-subscriptions-by-order-id.ts
|
|
803
|
-
var cancelSubscriptionsByOrderId = (uuid, data) => __async(null, null, function* () {
|
|
804
|
-
const res = yield $apiClient.POST("/dynamic-public/subscriptions-management/subscriptions/order/{orderId}/cancel", {
|
|
805
|
-
params: {
|
|
806
|
-
header: {
|
|
807
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
808
|
-
},
|
|
809
|
-
path: {
|
|
810
|
-
orderId: uuid
|
|
811
|
-
}
|
|
812
|
-
},
|
|
813
|
-
body: data
|
|
814
|
-
});
|
|
815
|
-
if (!res.data) {
|
|
816
|
-
throw new Error("Failed to cancel subscription.");
|
|
817
|
-
}
|
|
818
|
-
return res.data;
|
|
819
|
-
});
|
|
820
|
-
|
|
821
|
-
// src/server/subscription/subscription-apply-discount.ts
|
|
822
|
-
var subscriptionApplyDiscount = (data) => __async(null, null, function* () {
|
|
823
|
-
const res = yield $apiClient.POST("/dynamic-public/subscriptions-management/subscriptions/discount", {
|
|
824
|
-
params: {
|
|
825
|
-
header: {
|
|
826
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
827
|
-
}
|
|
828
|
-
},
|
|
829
|
-
body: data
|
|
830
|
-
});
|
|
831
|
-
if (!res.data) {
|
|
832
|
-
throw new Error("Failed to apply discount.");
|
|
833
|
-
}
|
|
834
|
-
return res.data;
|
|
835
|
-
});
|
|
836
|
-
|
|
837
|
-
// src/server/subscription/subscription-pause.ts
|
|
838
|
-
var subscriptionPause = (data) => __async(null, null, function* () {
|
|
839
|
-
const res = yield $apiClient.POST("/dynamic-public/subscriptions-management/subscriptions/pause", {
|
|
840
|
-
params: {
|
|
841
|
-
header: {
|
|
842
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
843
|
-
}
|
|
844
|
-
},
|
|
845
|
-
body: data
|
|
846
|
-
});
|
|
847
|
-
if (!res.data) {
|
|
848
|
-
throw new Error("Failed to pause subscription.");
|
|
849
|
-
}
|
|
850
|
-
return res.data;
|
|
851
|
-
});
|
|
852
|
-
|
|
853
|
-
// src/server/subscription/fill-subscription-cancel-request.ts
|
|
854
|
-
var fillSubscriptionCancelRequest = (data) => __async(null, null, function* () {
|
|
855
|
-
const res = yield $apiClient.POST("/dynamic-public/subscriptions-management/subscription-cancel-requests", {
|
|
856
|
-
params: {
|
|
857
|
-
header: {
|
|
858
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
859
|
-
}
|
|
860
|
-
},
|
|
861
|
-
body: data
|
|
862
|
-
});
|
|
863
|
-
if (!res.data) {
|
|
864
|
-
throw new Error("Failed to fill request.");
|
|
865
|
-
}
|
|
866
|
-
return res.data;
|
|
867
|
-
});
|
|
868
|
-
|
|
869
|
-
// src/server/subscription/get-subscriptions-by-order-id.ts
|
|
870
|
-
var getSubscriptionsByOrderId = (uuid) => __async(null, null, function* () {
|
|
871
|
-
const res = yield $apiClient.GET(
|
|
872
|
-
"/dynamic-public/subscriptions-management/subscriptions/info-by-orderid",
|
|
873
|
-
{
|
|
874
|
-
params: {
|
|
875
|
-
header: {
|
|
876
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
877
|
-
},
|
|
878
|
-
query: {
|
|
879
|
-
orderId: uuid
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
);
|
|
884
|
-
if (!res.data) {
|
|
885
|
-
throw new Error("Failed to get subscriptions by order id.");
|
|
886
|
-
}
|
|
887
|
-
return res.data;
|
|
888
|
-
});
|
|
889
|
-
|
|
890
|
-
// src/server/payments/primer/primer-refund-payment.ts
|
|
891
|
-
var primerRefundPayment = (transactionId, source, dto) => __async(null, null, function* () {
|
|
892
|
-
const res = yield $apiClient.POST(
|
|
893
|
-
"/dynamic-public/payments-primer/v1/primer-payment/{transactionId}/refund-or-cancel",
|
|
894
|
-
{
|
|
895
|
-
params: {
|
|
896
|
-
header: {
|
|
897
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`,
|
|
898
|
-
"x-source": source
|
|
899
|
-
},
|
|
900
|
-
path: {
|
|
901
|
-
transactionId
|
|
902
|
-
}
|
|
903
|
-
},
|
|
904
|
-
body: dto
|
|
905
|
-
}
|
|
906
|
-
);
|
|
907
|
-
if (!res.data) {
|
|
908
|
-
throw new Error("Failed to refund primer payment.");
|
|
909
|
-
}
|
|
910
|
-
return res.data;
|
|
911
|
-
});
|
|
912
|
-
|
|
913
|
-
// src/server/payments/paypal/paypal-refund-payment.ts
|
|
914
|
-
var paypalRefundPayment = (source, dto) => __async(null, null, function* () {
|
|
915
|
-
const res = yield $apiClient.POST(
|
|
916
|
-
"/dynamic-public/payments-paypal/payments/refund",
|
|
917
|
-
{
|
|
918
|
-
params: {
|
|
919
|
-
header: {
|
|
920
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`,
|
|
921
|
-
"x-source": source
|
|
922
|
-
}
|
|
923
|
-
},
|
|
924
|
-
body: dto
|
|
925
|
-
}
|
|
926
|
-
);
|
|
927
|
-
if (!res.data) {
|
|
928
|
-
throw new Error("Failed to refund paypal payment.");
|
|
929
|
-
}
|
|
930
|
-
return res.data;
|
|
931
|
-
});
|
|
932
|
-
|
|
933
|
-
// src/server/payments/payments-refund.ts
|
|
934
|
-
var paymentsRefund = (_0) => __async(null, [_0], function* ({
|
|
935
|
-
source,
|
|
936
|
-
transactionId,
|
|
937
|
-
amount,
|
|
938
|
-
reason,
|
|
939
|
-
orderId,
|
|
940
|
-
currency
|
|
941
|
-
}) {
|
|
942
|
-
if (source.startsWith("primer")) {
|
|
943
|
-
return yield primerRefundPayment(transactionId, source, {
|
|
944
|
-
amount,
|
|
945
|
-
reason
|
|
946
|
-
});
|
|
947
|
-
} else if (source.startsWith("paypal")) {
|
|
948
|
-
return yield paypalRefundPayment(
|
|
949
|
-
source,
|
|
950
|
-
{
|
|
951
|
-
amount,
|
|
952
|
-
orderId,
|
|
953
|
-
transactionId,
|
|
954
|
-
currency
|
|
955
|
-
}
|
|
956
|
-
);
|
|
957
|
-
}
|
|
958
|
-
throw new Error("Unknown payment source");
|
|
959
|
-
});
|
|
960
|
-
|
|
961
|
-
// src/server/payments/tax/get-tax-percent.ts
|
|
962
|
-
var getTaxPercent = (data) => __async(null, null, function* () {
|
|
963
|
-
const res = yield $apiClient.POST("/dynamic-public/tax/tax/get", {
|
|
964
|
-
params: {
|
|
965
|
-
header: {
|
|
966
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
967
|
-
}
|
|
968
|
-
},
|
|
969
|
-
body: data
|
|
970
|
-
});
|
|
971
|
-
if (!res.data) {
|
|
972
|
-
throw new Error("Failed to get tax percent.");
|
|
973
|
-
}
|
|
974
|
-
return res.data;
|
|
975
|
-
});
|
|
976
|
-
|
|
977
|
-
// src/server/payments/tax/tax-calculate-amount.ts
|
|
978
|
-
var taxCalculateAmount = (data) => __async(null, null, function* () {
|
|
979
|
-
const res = yield $apiClient.POST("/dynamic-public/tax/tax/calculate", {
|
|
980
|
-
params: {
|
|
981
|
-
header: {
|
|
982
|
-
"project-key": `${process.env.CAPIBOX_API_KEY}`
|
|
983
|
-
}
|
|
984
|
-
},
|
|
985
|
-
body: data
|
|
986
|
-
});
|
|
987
|
-
if (!res.data) {
|
|
988
|
-
throw new Error("Failed to create payment session.");
|
|
989
|
-
}
|
|
990
|
-
return res.data;
|
|
991
|
-
});
|
|
992
|
-
|
|
993
528
|
// src/index.ts
|
|
994
|
-
var
|
|
995
|
-
|
|
529
|
+
var import_bridge_server_sdk = require("@capibox/bridge-server-sdk");
|
|
530
|
+
var server = __spreadProps(__spreadValues({
|
|
531
|
+
middleware
|
|
532
|
+
}, import_bridge_server_sdk.server), {
|
|
996
533
|
funnels: {
|
|
997
534
|
get: getFunnels,
|
|
998
535
|
getTemplates,
|
|
999
536
|
clearCache: funnelsClearCache
|
|
1000
|
-
},
|
|
1001
|
-
session: {
|
|
1002
|
-
get: getSession,
|
|
1003
|
-
append: appendSession,
|
|
1004
|
-
getByEmail: getSessionByEmail
|
|
1005
|
-
},
|
|
1006
|
-
capi: {
|
|
1007
|
-
snapchat: snapchatS2s,
|
|
1008
|
-
tiktok: tiktokS2S,
|
|
1009
|
-
facebook: facebookS2S
|
|
1010
|
-
},
|
|
1011
|
-
klaviyo: {
|
|
1012
|
-
send: klaviyoSendEvent,
|
|
1013
|
-
sendBulk: klaviyoSendBulk
|
|
1014
|
-
},
|
|
1015
|
-
realtime: {
|
|
1016
|
-
orderUtmData: realtimeUtmOrderData
|
|
1017
|
-
},
|
|
1018
|
-
order: {
|
|
1019
|
-
getByUuid: orderGetByUuid,
|
|
1020
|
-
getByEmail: orderGetByEmail
|
|
1021
|
-
},
|
|
1022
|
-
payments: {
|
|
1023
|
-
firstPayment: paymentFirstPayment,
|
|
1024
|
-
last5Payments: paymentLastPayments,
|
|
1025
|
-
refund: paymentsRefund,
|
|
1026
|
-
primer: {
|
|
1027
|
-
refund: primerRefundPayment
|
|
1028
|
-
},
|
|
1029
|
-
paypal: {
|
|
1030
|
-
refund: paypalRefundPayment
|
|
1031
|
-
},
|
|
1032
|
-
tax: {
|
|
1033
|
-
getPercent: getTaxPercent,
|
|
1034
|
-
calculate: taxCalculateAmount
|
|
1035
|
-
}
|
|
1036
|
-
},
|
|
1037
|
-
subscription: {
|
|
1038
|
-
cancelById: cancelSubscriptionById,
|
|
1039
|
-
cancelByOrderId: cancelSubscriptionsByOrderId,
|
|
1040
|
-
applyDiscount: subscriptionApplyDiscount,
|
|
1041
|
-
pause: subscriptionPause,
|
|
1042
|
-
fillCancellationRequest: fillSubscriptionCancelRequest,
|
|
1043
|
-
get: getSubscriptionsByOrderId
|
|
1044
537
|
}
|
|
1045
|
-
};
|
|
538
|
+
});
|
|
1046
539
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1047
540
|
0 && (module.exports = {
|
|
1048
541
|
server
|