@intlayer/api 9.5.12 → 9.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/distantDictionary/fetchDistantDictionaries.cjs.map +1 -1
- package/dist/cjs/distantDictionary/fetchDistantDictionary.cjs.map +1 -1
- package/dist/cjs/fetcher.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/ai.cjs +76 -22
- package/dist/cjs/getIntlayerAPI/ai.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/analytics.cjs +44 -10
- package/dist/cjs/getIntlayerAPI/analytics.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/asset.cjs +38 -8
- package/dist/cjs/getIntlayerAPI/asset.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/audit.cjs +70 -16
- package/dist/cjs/getIntlayerAPI/audit.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/bitbucket.cjs +39 -9
- package/dist/cjs/getIntlayerAPI/bitbucket.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/codeberg.cjs +21 -0
- package/dist/cjs/getIntlayerAPI/codeberg.cjs.map +1 -0
- package/dist/cjs/getIntlayerAPI/dictionary.cjs +59 -13
- package/dist/cjs/getIntlayerAPI/dictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/editor.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/environment.cjs +44 -10
- package/dist/cjs/getIntlayerAPI/environment.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/forge.cjs +64 -0
- package/dist/cjs/getIntlayerAPI/forge.cjs.map +1 -0
- package/dist/cjs/getIntlayerAPI/gitee.cjs +21 -0
- package/dist/cjs/getIntlayerAPI/gitee.cjs.map +1 -0
- package/dist/cjs/getIntlayerAPI/github.cjs +44 -10
- package/dist/cjs/getIntlayerAPI/github.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/gitlab.cjs +39 -9
- package/dist/cjs/getIntlayerAPI/gitlab.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/index.cjs +4 -0
- package/dist/cjs/getIntlayerAPI/index.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/newsletter.cjs +28 -6
- package/dist/cjs/getIntlayerAPI/newsletter.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/oAuth.cjs +31 -5
- package/dist/cjs/getIntlayerAPI/oAuth.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/organization.cjs +72 -20
- package/dist/cjs/getIntlayerAPI/organization.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/project.cjs +112 -29
- package/dist/cjs/getIntlayerAPI/project.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/reviewer.cjs +142 -31
- package/dist/cjs/getIntlayerAPI/reviewer.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/search.cjs +15 -3
- package/dist/cjs/getIntlayerAPI/search.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/showcaseProject.cjs +61 -15
- package/dist/cjs/getIntlayerAPI/showcaseProject.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/status.cjs +16 -3
- package/dist/cjs/getIntlayerAPI/status.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/stripe.cjs +141 -35
- package/dist/cjs/getIntlayerAPI/stripe.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/tag.cjs +33 -7
- package/dist/cjs/getIntlayerAPI/tag.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/translate.cjs +46 -8
- package/dist/cjs/getIntlayerAPI/translate.cjs.map +1 -1
- package/dist/cjs/getIntlayerAPI/user.cjs +58 -14
- package/dist/cjs/getIntlayerAPI/user.cjs.map +1 -1
- package/dist/cjs/index.cjs +8 -0
- package/dist/cjs/proxy.cjs +4 -0
- package/dist/cjs/proxy.cjs.map +1 -1
- package/dist/cjs/public/createPublicClient.cjs +25 -5
- package/dist/cjs/public/createPublicClient.cjs.map +1 -1
- package/dist/esm/distantDictionary/fetchDistantDictionaries.mjs.map +1 -1
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +1 -1
- package/dist/esm/fetcher.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/ai.mjs +76 -22
- package/dist/esm/getIntlayerAPI/ai.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/analytics.mjs +44 -10
- package/dist/esm/getIntlayerAPI/analytics.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/asset.mjs +38 -8
- package/dist/esm/getIntlayerAPI/asset.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/audit.mjs +70 -16
- package/dist/esm/getIntlayerAPI/audit.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/bitbucket.mjs +39 -9
- package/dist/esm/getIntlayerAPI/bitbucket.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/codeberg.mjs +19 -0
- package/dist/esm/getIntlayerAPI/codeberg.mjs.map +1 -0
- package/dist/esm/getIntlayerAPI/dictionary.mjs +59 -13
- package/dist/esm/getIntlayerAPI/dictionary.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/editor.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/environment.mjs +44 -10
- package/dist/esm/getIntlayerAPI/environment.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/forge.mjs +63 -0
- package/dist/esm/getIntlayerAPI/forge.mjs.map +1 -0
- package/dist/esm/getIntlayerAPI/gitee.mjs +19 -0
- package/dist/esm/getIntlayerAPI/gitee.mjs.map +1 -0
- package/dist/esm/getIntlayerAPI/github.mjs +44 -10
- package/dist/esm/getIntlayerAPI/github.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/gitlab.mjs +39 -9
- package/dist/esm/getIntlayerAPI/gitlab.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/index.mjs +4 -0
- package/dist/esm/getIntlayerAPI/index.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/newsletter.mjs +28 -6
- package/dist/esm/getIntlayerAPI/newsletter.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/oAuth.mjs +31 -5
- package/dist/esm/getIntlayerAPI/oAuth.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/organization.mjs +72 -20
- package/dist/esm/getIntlayerAPI/organization.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/project.mjs +112 -29
- package/dist/esm/getIntlayerAPI/project.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/reviewer.mjs +142 -31
- package/dist/esm/getIntlayerAPI/reviewer.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/search.mjs +15 -3
- package/dist/esm/getIntlayerAPI/search.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/showcaseProject.mjs +61 -15
- package/dist/esm/getIntlayerAPI/showcaseProject.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/status.mjs +16 -3
- package/dist/esm/getIntlayerAPI/status.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/stripe.mjs +141 -35
- package/dist/esm/getIntlayerAPI/stripe.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/tag.mjs +33 -7
- package/dist/esm/getIntlayerAPI/tag.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/translate.mjs +46 -8
- package/dist/esm/getIntlayerAPI/translate.mjs.map +1 -1
- package/dist/esm/getIntlayerAPI/user.mjs +58 -14
- package/dist/esm/getIntlayerAPI/user.mjs.map +1 -1
- package/dist/esm/index.mjs +4 -1
- package/dist/esm/proxy.mjs +4 -0
- package/dist/esm/proxy.mjs.map +1 -1
- package/dist/esm/public/createPublicClient.mjs +25 -5
- package/dist/esm/public/createPublicClient.mjs.map +1 -1
- package/dist/types/distantDictionary/fetchDistantDictionaries.d.ts +1 -1
- package/dist/types/distantDictionary/fetchDistantDictionary.d.ts +1 -1
- package/dist/types/fetcher.d.ts +1 -1
- package/dist/types/fetcher.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/ai.d.ts +1 -1
- package/dist/types/getIntlayerAPI/ai.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/analytics.d.ts +1 -1
- package/dist/types/getIntlayerAPI/analytics.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/asset.d.ts +1 -0
- package/dist/types/getIntlayerAPI/asset.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/audit.d.ts +47 -3
- package/dist/types/getIntlayerAPI/audit.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/bitbucket.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/codeberg.d.ts +23 -0
- package/dist/types/getIntlayerAPI/codeberg.d.ts.map +1 -0
- package/dist/types/getIntlayerAPI/dictionary.d.ts +1 -1
- package/dist/types/getIntlayerAPI/dictionary.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/editor.d.ts +2 -1
- package/dist/types/getIntlayerAPI/editor.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/environment.d.ts +1 -1
- package/dist/types/getIntlayerAPI/environment.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/forge.d.ts +17 -0
- package/dist/types/getIntlayerAPI/forge.d.ts.map +1 -0
- package/dist/types/getIntlayerAPI/gitee.d.ts +23 -0
- package/dist/types/getIntlayerAPI/gitee.d.ts.map +1 -0
- package/dist/types/getIntlayerAPI/github.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/gitlab.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/index.d.ts +4 -0
- package/dist/types/getIntlayerAPI/index.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/newsletter.d.ts +1 -1
- package/dist/types/getIntlayerAPI/newsletter.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/oAuth.d.ts +2 -0
- package/dist/types/getIntlayerAPI/oAuth.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/organization.d.ts +1 -3
- package/dist/types/getIntlayerAPI/organization.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/project.d.ts +2 -1
- package/dist/types/getIntlayerAPI/project.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/reviewer.d.ts +680 -35
- package/dist/types/getIntlayerAPI/reviewer.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/search.d.ts +1 -1
- package/dist/types/getIntlayerAPI/search.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/showcaseProject.d.ts +1 -1
- package/dist/types/getIntlayerAPI/showcaseProject.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/status.d.ts +3 -4
- package/dist/types/getIntlayerAPI/status.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/stripe.d.ts +1 -1
- package/dist/types/getIntlayerAPI/stripe.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/tag.d.ts +1 -1
- package/dist/types/getIntlayerAPI/tag.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/translate.d.ts +1 -1
- package/dist/types/getIntlayerAPI/translate.d.ts.map +1 -1
- package/dist/types/getIntlayerAPI/user.d.ts +4 -4
- package/dist/types/getIntlayerAPI/user.d.ts.map +1 -1
- package/dist/types/index.d.ts +7 -4
- package/dist/types/proxy.d.ts.map +1 -1
- package/dist/types/public/createPublicClient.d.ts +1 -7
- package/dist/types/public/createPublicClient.d.ts.map +1 -1
- package/dist/types/types.d.ts +5 -2
- package/package.json +22 -5
|
@@ -1,81 +1,187 @@
|
|
|
1
1
|
import { fetcher } from "../fetcher.mjs";
|
|
2
2
|
import { createEndpoint } from "../cms/createIntlayerCMS.mjs";
|
|
3
3
|
import { editor } from "@intlayer/config/built";
|
|
4
|
+
import { buildRouteURL } from "@intlayer/backend-contract/defineRoute";
|
|
5
|
+
import { BACKEND_URL } from "@intlayer/config/defaultValues";
|
|
4
6
|
|
|
5
7
|
//#region src/getIntlayerAPI/stripe.ts
|
|
8
|
+
/** Prefix of the routes, checked against the backend contract. */
|
|
9
|
+
const stripeGroup = { prefix: "/api/stripe" };
|
|
10
|
+
/**
|
|
11
|
+
* Method and path of every route, checked against the backend contract at
|
|
12
|
+
* compile time (the contract's zod schemas are never loaded).
|
|
13
|
+
*/
|
|
14
|
+
const stripeEndpoints = {
|
|
15
|
+
getPricing: {
|
|
16
|
+
method: "POST",
|
|
17
|
+
path: "/pricing"
|
|
18
|
+
},
|
|
19
|
+
createSubscription: {
|
|
20
|
+
method: "POST",
|
|
21
|
+
path: "/create-subscription"
|
|
22
|
+
},
|
|
23
|
+
cancelSubscription: {
|
|
24
|
+
method: "POST",
|
|
25
|
+
path: "/cancel-subscription"
|
|
26
|
+
},
|
|
27
|
+
getInvoices: {
|
|
28
|
+
method: "GET",
|
|
29
|
+
path: "/invoices"
|
|
30
|
+
},
|
|
31
|
+
getPaymentMethod: {
|
|
32
|
+
method: "GET",
|
|
33
|
+
path: "/payment-method"
|
|
34
|
+
},
|
|
35
|
+
createPortalSession: {
|
|
36
|
+
method: "POST",
|
|
37
|
+
path: "/portal-session"
|
|
38
|
+
},
|
|
39
|
+
grantAffiliateAccess: {
|
|
40
|
+
method: "POST",
|
|
41
|
+
path: "/affiliate/grant"
|
|
42
|
+
},
|
|
43
|
+
getAffiliates: {
|
|
44
|
+
method: "GET",
|
|
45
|
+
path: "/affiliates"
|
|
46
|
+
},
|
|
47
|
+
getAffiliateById: {
|
|
48
|
+
method: "GET",
|
|
49
|
+
path: "/affiliates/:id"
|
|
50
|
+
},
|
|
51
|
+
getAffiliate: {
|
|
52
|
+
method: "GET",
|
|
53
|
+
path: "/affiliate"
|
|
54
|
+
},
|
|
55
|
+
getAffiliateAccountSession: {
|
|
56
|
+
method: "POST",
|
|
57
|
+
path: "/affiliate/account-session"
|
|
58
|
+
},
|
|
59
|
+
getAffiliateOnboardingLink: {
|
|
60
|
+
method: "GET",
|
|
61
|
+
path: "/affiliate/onboarding-link"
|
|
62
|
+
},
|
|
63
|
+
getAffiliateStats: {
|
|
64
|
+
method: "GET",
|
|
65
|
+
path: "/affiliate/stats"
|
|
66
|
+
},
|
|
67
|
+
getAffiliateInvitations: {
|
|
68
|
+
method: "GET",
|
|
69
|
+
path: "/affiliate/invitations"
|
|
70
|
+
},
|
|
71
|
+
sendAffiliateInvitation: {
|
|
72
|
+
method: "POST",
|
|
73
|
+
path: "/affiliate/invite"
|
|
74
|
+
},
|
|
75
|
+
getAffiliateInvitation: {
|
|
76
|
+
method: "GET",
|
|
77
|
+
path: "/affiliate/invitation/:token"
|
|
78
|
+
},
|
|
79
|
+
acceptAffiliateInvitation: {
|
|
80
|
+
method: "POST",
|
|
81
|
+
path: "/affiliate/invitation/:token/accept"
|
|
82
|
+
},
|
|
83
|
+
updateAffiliateStatus: {
|
|
84
|
+
method: "PATCH",
|
|
85
|
+
path: "/affiliates/:id/status"
|
|
86
|
+
},
|
|
87
|
+
getPromoCodes: {
|
|
88
|
+
method: "GET",
|
|
89
|
+
path: "/promo-codes"
|
|
90
|
+
},
|
|
91
|
+
getPromoCodeById: {
|
|
92
|
+
method: "GET",
|
|
93
|
+
path: "/promo-codes/:id"
|
|
94
|
+
},
|
|
95
|
+
createPromoCode: {
|
|
96
|
+
method: "POST",
|
|
97
|
+
path: "/promo-codes"
|
|
98
|
+
},
|
|
99
|
+
updatePromoCode: {
|
|
100
|
+
method: "PATCH",
|
|
101
|
+
path: "/promo-codes/:id"
|
|
102
|
+
},
|
|
103
|
+
deletePromoCode: {
|
|
104
|
+
method: "DELETE",
|
|
105
|
+
path: "/promo-codes/:id"
|
|
106
|
+
},
|
|
107
|
+
getAffiliatePromoCode: {
|
|
108
|
+
method: "GET",
|
|
109
|
+
path: "/affiliate-promo-code/:referralCode"
|
|
110
|
+
}
|
|
111
|
+
};
|
|
6
112
|
const getStripeAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
7
|
-
const
|
|
113
|
+
const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL ?? BACKEND_URL;
|
|
8
114
|
/**
|
|
9
115
|
* Get a pricing plan calculated for a given promotion code.
|
|
10
116
|
* @param body - Pricing plan body.
|
|
11
117
|
*/
|
|
12
|
-
const getPricing = async (body, otherOptions = {}) => await fetcher(
|
|
13
|
-
method:
|
|
118
|
+
const getPricing = async (body, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getPricing), authAPIOptions, otherOptions, {
|
|
119
|
+
method: stripeEndpoints.getPricing.method,
|
|
14
120
|
body
|
|
15
121
|
});
|
|
16
122
|
/**
|
|
17
123
|
* Retrieves a checkout session.
|
|
18
124
|
* @param body - Checkout session body.
|
|
19
125
|
*/
|
|
20
|
-
const getSubscription = async (body, otherOptions = {}) => await fetcher(
|
|
21
|
-
method:
|
|
126
|
+
const getSubscription = async (body, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.createSubscription), authAPIOptions, otherOptions, {
|
|
127
|
+
method: stripeEndpoints.createSubscription.method,
|
|
22
128
|
body
|
|
23
129
|
});
|
|
24
130
|
/**
|
|
25
131
|
* Cancels a subscription.
|
|
26
132
|
* @param body - Checkout session body.
|
|
27
133
|
*/
|
|
28
|
-
const cancelSubscription = async (otherOptions = {}) => await fetcher(
|
|
134
|
+
const cancelSubscription = async (otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.cancelSubscription), authAPIOptions, otherOptions, { method: stripeEndpoints.cancelSubscription.method });
|
|
29
135
|
/**
|
|
30
136
|
* Lists invoices for the authenticated organization's Stripe customer.
|
|
31
137
|
*/
|
|
32
|
-
const getInvoices = async (otherOptions = {}) => await fetcher(
|
|
138
|
+
const getInvoices = async (otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getInvoices), authAPIOptions, otherOptions, { method: stripeEndpoints.getInvoices.method });
|
|
33
139
|
/**
|
|
34
140
|
* Returns the first card payment method for the authenticated organization's
|
|
35
141
|
* Stripe customer (or null if none).
|
|
36
142
|
*/
|
|
37
|
-
const getPaymentMethod = async (otherOptions = {}) => await fetcher(
|
|
143
|
+
const getPaymentMethod = async (otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getPaymentMethod), authAPIOptions, otherOptions, { method: stripeEndpoints.getPaymentMethod.method });
|
|
38
144
|
/**
|
|
39
145
|
* Creates a Stripe Billing Portal session for the authenticated organization.
|
|
40
146
|
*/
|
|
41
|
-
const createPortalSession = async (otherOptions = {}) => await fetcher(
|
|
147
|
+
const createPortalSession = async (otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.createPortalSession), authAPIOptions, otherOptions, { method: stripeEndpoints.createPortalSession.method });
|
|
42
148
|
/**
|
|
43
149
|
* Admin-only: grants affiliate access to a user by creating their Stripe Connect account.
|
|
44
150
|
*/
|
|
45
|
-
const grantAffiliateAccess = async (body, otherOptions = {}) => await fetcher(
|
|
46
|
-
method:
|
|
151
|
+
const grantAffiliateAccess = async (body, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.grantAffiliateAccess), authAPIOptions, otherOptions, {
|
|
152
|
+
method: stripeEndpoints.grantAffiliateAccess.method,
|
|
47
153
|
body
|
|
48
154
|
});
|
|
49
155
|
/**
|
|
50
156
|
* Admin-only: returns a paginated list of all affiliates.
|
|
51
157
|
*/
|
|
52
|
-
const getAffiliates = async (params, otherOptions = {}) => await fetcher(
|
|
53
|
-
method:
|
|
158
|
+
const getAffiliates = async (params, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getAffiliates), authAPIOptions, otherOptions, {
|
|
159
|
+
method: stripeEndpoints.getAffiliates.method,
|
|
54
160
|
params
|
|
55
161
|
});
|
|
56
162
|
/**
|
|
57
163
|
* Admin-only: returns a single affiliate by ID.
|
|
58
164
|
*/
|
|
59
|
-
const getAffiliateById = async ({ id }, otherOptions = {}) => await fetcher(
|
|
165
|
+
const getAffiliateById = async ({ id }, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getAffiliateById, { id }), authAPIOptions, otherOptions, { method: stripeEndpoints.getAffiliateById.method });
|
|
60
166
|
/**
|
|
61
167
|
* Returns the affiliate record for the authenticated user (null if not an affiliate).
|
|
62
168
|
*/
|
|
63
|
-
const getAffiliate = async (otherOptions = {}) => await fetcher(
|
|
169
|
+
const getAffiliate = async (otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getAffiliate), authAPIOptions, otherOptions, { method: stripeEndpoints.getAffiliate.method });
|
|
64
170
|
/**
|
|
65
171
|
* Creates a Stripe Connect account session for the authenticated affiliate (embedded onboarding).
|
|
66
172
|
*/
|
|
67
|
-
const getAffiliateAccountSession = async (otherOptions = {}) => await fetcher(
|
|
173
|
+
const getAffiliateAccountSession = async (otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getAffiliateAccountSession), authAPIOptions, otherOptions, { method: stripeEndpoints.getAffiliateAccountSession.method });
|
|
68
174
|
/**
|
|
69
175
|
* Returns a Stripe-hosted onboarding URL for the authenticated affiliate.
|
|
70
176
|
*/
|
|
71
|
-
const getAffiliateOnboardingLink = async (params, otherOptions = {}) => await fetcher(
|
|
72
|
-
method:
|
|
177
|
+
const getAffiliateOnboardingLink = async (params, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getAffiliateOnboardingLink), authAPIOptions, otherOptions, {
|
|
178
|
+
method: stripeEndpoints.getAffiliateOnboardingLink.method,
|
|
73
179
|
params
|
|
74
180
|
});
|
|
75
181
|
/**
|
|
76
182
|
* Returns referral stats for the authenticated affiliate.
|
|
77
183
|
*/
|
|
78
|
-
const getAffiliateStats = async (otherOptions = {}) => await fetcher(
|
|
184
|
+
const getAffiliateStats = async (otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getAffiliateStats), authAPIOptions, otherOptions, { method: stripeEndpoints.getAffiliateStats.method });
|
|
79
185
|
/**
|
|
80
186
|
* Admin-only: returns a paginated list of all affiliate invitations.
|
|
81
187
|
*/
|
|
@@ -85,31 +191,31 @@ const getStripeAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
85
191
|
if (params.pageSize) qs.set("pageSize", String(params.pageSize));
|
|
86
192
|
if (params.search) qs.set("search", params.search);
|
|
87
193
|
const query = qs.toString() ? `?${qs.toString()}` : "";
|
|
88
|
-
return await fetcher(`${
|
|
194
|
+
return await fetcher(`${buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getAffiliateInvitations)}${query}`, authAPIOptions, otherOptions, { method: "GET" });
|
|
89
195
|
};
|
|
90
196
|
/**
|
|
91
197
|
* Sends an affiliate invitation email to the given address (admin only).
|
|
92
198
|
*/
|
|
93
|
-
const sendAffiliateInvitation = async (body, otherOptions = {}) => await fetcher(
|
|
94
|
-
method:
|
|
199
|
+
const sendAffiliateInvitation = async (body, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.sendAffiliateInvitation), authAPIOptions, otherOptions, {
|
|
200
|
+
method: stripeEndpoints.sendAffiliateInvitation.method,
|
|
95
201
|
body
|
|
96
202
|
});
|
|
97
203
|
/**
|
|
98
204
|
* Retrieves an affiliate invitation by token (public — no auth required).
|
|
99
205
|
*/
|
|
100
|
-
const getAffiliateInvitation = async ({ token }, otherOptions = {}) => await fetcher(
|
|
206
|
+
const getAffiliateInvitation = async ({ token }, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getAffiliateInvitation, { token }), authAPIOptions, otherOptions, { method: stripeEndpoints.getAffiliateInvitation.method });
|
|
101
207
|
/**
|
|
102
208
|
* Admin-only: updates an affiliate's status and/or category.
|
|
103
209
|
*/
|
|
104
|
-
const updateAffiliateStatus = async ({ id }, body, otherOptions = {}) => await fetcher(
|
|
105
|
-
method:
|
|
210
|
+
const updateAffiliateStatus = async ({ id }, body, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.updateAffiliateStatus, { id }), authAPIOptions, otherOptions, {
|
|
211
|
+
method: stripeEndpoints.updateAffiliateStatus.method,
|
|
106
212
|
body
|
|
107
213
|
});
|
|
108
214
|
/**
|
|
109
215
|
* Accepts an affiliate invitation and creates the affiliate account.
|
|
110
216
|
*/
|
|
111
|
-
const acceptAffiliateInvitation = async ({ token, country, stripeAccountType }, otherOptions = {}) => await fetcher(
|
|
112
|
-
method:
|
|
217
|
+
const acceptAffiliateInvitation = async ({ token, country, stripeAccountType }, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.acceptAffiliateInvitation, { token }), authAPIOptions, otherOptions, {
|
|
218
|
+
method: stripeEndpoints.acceptAffiliateInvitation.method,
|
|
113
219
|
body: {
|
|
114
220
|
country,
|
|
115
221
|
stripeAccountType
|
|
@@ -118,33 +224,33 @@ const getStripeAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
118
224
|
/**
|
|
119
225
|
* Admin-only: returns a paginated list of all promo codes.
|
|
120
226
|
*/
|
|
121
|
-
const getPromoCodeById = async (id, otherOptions = {}) => await fetcher(
|
|
227
|
+
const getPromoCodeById = async (id, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getPromoCodeById, { id }), authAPIOptions, otherOptions, { method: stripeEndpoints.getPromoCodeById.method });
|
|
122
228
|
const getPromoCodes = async (params = {}, otherOptions = {}) => {
|
|
123
229
|
const qs = params.affiliateId ? `?affiliateId=${encodeURIComponent(params.affiliateId)}` : "";
|
|
124
|
-
return await fetcher(`${
|
|
230
|
+
return await fetcher(`${buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getPromoCodes)}${qs}`, authAPIOptions, otherOptions, { method: "GET" });
|
|
125
231
|
};
|
|
126
232
|
/**
|
|
127
233
|
* Admin-only: creates a new promo code (Stripe coupon + promotion code).
|
|
128
234
|
*/
|
|
129
|
-
const createPromoCode = async (body, otherOptions = {}) => await fetcher(
|
|
130
|
-
method:
|
|
235
|
+
const createPromoCode = async (body, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.createPromoCode), authAPIOptions, otherOptions, {
|
|
236
|
+
method: stripeEndpoints.createPromoCode.method,
|
|
131
237
|
body
|
|
132
238
|
});
|
|
133
239
|
/**
|
|
134
240
|
* Admin-only: updates a promo code.
|
|
135
241
|
*/
|
|
136
|
-
const updatePromoCode = async ({ id, ...body }, otherOptions = {}) => await fetcher(
|
|
137
|
-
method:
|
|
242
|
+
const updatePromoCode = async ({ id, ...body }, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.updatePromoCode, { id }), authAPIOptions, otherOptions, {
|
|
243
|
+
method: stripeEndpoints.updatePromoCode.method,
|
|
138
244
|
body
|
|
139
245
|
});
|
|
140
246
|
/**
|
|
141
247
|
* Admin-only: deactivates a promo code (sets active=false, disables Stripe promotion code).
|
|
142
248
|
*/
|
|
143
|
-
const deletePromoCode = async ({ id }, otherOptions = {}) => await fetcher(
|
|
249
|
+
const deletePromoCode = async ({ id }, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.deletePromoCode, { id }), authAPIOptions, otherOptions, { method: stripeEndpoints.deletePromoCode.method });
|
|
144
250
|
/**
|
|
145
251
|
* Retrieves the active promo code associated with a given affiliate referral code.
|
|
146
252
|
*/
|
|
147
|
-
const getAffiliatePromoCode = async (referralCode, otherOptions = {}) => await fetcher(
|
|
253
|
+
const getAffiliatePromoCode = async (referralCode, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getAffiliatePromoCode, { referralCode }), authAPIOptions, otherOptions, { method: stripeEndpoints.getAffiliatePromoCode.method });
|
|
148
254
|
return {
|
|
149
255
|
getPricing,
|
|
150
256
|
getSubscription,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripe.mjs","names":[],"sources":["../../../src/getIntlayerAPI/stripe.ts"],"sourcesContent":["import type {\n AcceptAffiliateInvitationResult,\n CreatePortalSessionResult,\n CreatePromoCodeBody,\n CreatePromoCodeResult,\n DeletePromoCodeResult,\n GetAffiliateAccountSessionResult,\n GetAffiliateByIdResult,\n GetAffiliateInvitationResult,\n GetAffiliateInvitationsResult,\n GetAffiliateOnboardingLinkResult,\n GetAffiliateResult,\n GetAffiliateStatsResult,\n GetAffiliatesParams,\n GetAffiliatesResult,\n GetCheckoutSessionBody,\n GetCheckoutSessionResult,\n GetInvoicesResult,\n GetPaymentMethodResult,\n GetPricingBody,\n GetPricingResult,\n GetPromoCodeByIdResult,\n GetPromoCodesResult,\n GrantAffiliateAccessBody,\n GrantAffiliateAccessResult,\n SendAffiliateInvitationBody,\n SendAffiliateInvitationResult,\n UpdateAffiliateStatusBody,\n UpdateAffiliateStatusResult,\n UpdatePromoCodeBody,\n UpdatePromoCodeResult,\n} from '@intlayer/backend';\nimport { editor } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { createEndpoint } from '../cms/createIntlayerCMS';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport const getStripeAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL;\n\n const STRIPE_API_ROUTE = `${backendURL}/api/stripe`;\n\n /**\n * Get a pricing plan calculated for a given promotion code.\n * @param body - Pricing plan body.\n */\n const getPricing = async (\n body?: GetPricingBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetPricingResult>(\n `${STRIPE_API_ROUTE}/pricing`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body,\n }\n );\n\n /**\n * Retrieves a checkout session.\n * @param body - Checkout session body.\n */\n const getSubscription = async (\n body?: GetCheckoutSessionBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetCheckoutSessionResult>(\n `${STRIPE_API_ROUTE}/create-subscription`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n body,\n }\n );\n\n /**\n * Cancels a subscription.\n * @param body - Checkout session body.\n */\n const cancelSubscription = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetCheckoutSessionResult>(\n `${STRIPE_API_ROUTE}/cancel-subscription`,\n authAPIOptions,\n otherOptions,\n {\n method: 'POST',\n }\n );\n\n /**\n * Lists invoices for the authenticated organization's Stripe customer.\n */\n const getInvoices = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetInvoicesResult>(\n `${STRIPE_API_ROUTE}/invoices`,\n authAPIOptions,\n otherOptions,\n { method: 'GET' }\n );\n\n /**\n * Returns the first card payment method for the authenticated organization's\n * Stripe customer (or null if none).\n */\n const getPaymentMethod = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetPaymentMethodResult>(\n `${STRIPE_API_ROUTE}/payment-method`,\n authAPIOptions,\n otherOptions,\n { method: 'GET' }\n );\n\n /**\n * Creates a Stripe Billing Portal session for the authenticated organization.\n */\n const createPortalSession = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<CreatePortalSessionResult>(\n `${STRIPE_API_ROUTE}/portal-session`,\n authAPIOptions,\n otherOptions,\n { method: 'POST' }\n );\n\n /**\n * Admin-only: grants affiliate access to a user by creating their Stripe Connect account.\n */\n const grantAffiliateAccess = async (\n body: GrantAffiliateAccessBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GrantAffiliateAccessResult>(\n `${STRIPE_API_ROUTE}/affiliate/grant`,\n authAPIOptions,\n otherOptions,\n { method: 'POST', body }\n );\n\n /**\n * Admin-only: returns a paginated list of all affiliates.\n */\n const getAffiliates = async (\n params?: GetAffiliatesParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAffiliatesResult>(\n `${STRIPE_API_ROUTE}/affiliates`,\n authAPIOptions,\n otherOptions,\n { method: 'GET', params: params as Record<string, string> }\n );\n\n /**\n * Admin-only: returns a single affiliate by ID.\n */\n const getAffiliateById = async (\n { id }: { id: string },\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAffiliateByIdResult>(\n `${STRIPE_API_ROUTE}/affiliates/${id}`,\n authAPIOptions,\n otherOptions,\n { method: 'GET' }\n );\n\n /**\n * Returns the affiliate record for the authenticated user (null if not an affiliate).\n */\n const getAffiliate = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetAffiliateResult>(\n `${STRIPE_API_ROUTE}/affiliate`,\n authAPIOptions,\n otherOptions,\n { method: 'GET' }\n );\n\n /**\n * Creates a Stripe Connect account session for the authenticated affiliate (embedded onboarding).\n */\n const getAffiliateAccountSession = async (\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAffiliateAccountSessionResult>(\n `${STRIPE_API_ROUTE}/affiliate/account-session`,\n authAPIOptions,\n otherOptions,\n { method: 'POST' }\n );\n\n /**\n * Returns a Stripe-hosted onboarding URL for the authenticated affiliate.\n */\n const getAffiliateOnboardingLink = async (\n params?: { returnUrl?: string },\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAffiliateOnboardingLinkResult>(\n `${STRIPE_API_ROUTE}/affiliate/onboarding-link`,\n authAPIOptions,\n otherOptions,\n { method: 'GET', params }\n );\n\n /**\n * Returns referral stats for the authenticated affiliate.\n */\n const getAffiliateStats = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetAffiliateStatsResult>(\n `${STRIPE_API_ROUTE}/affiliate/stats`,\n authAPIOptions,\n otherOptions,\n { method: 'GET' }\n );\n\n /**\n * Admin-only: returns a paginated list of all affiliate invitations.\n */\n const getAffiliateInvitations = async (\n params: GetAffiliatesParams = {},\n otherOptions: FetcherOptions = {}\n ) => {\n const qs = new URLSearchParams();\n if (params.page) qs.set('page', String(params.page));\n if (params.pageSize) qs.set('pageSize', String(params.pageSize));\n if (params.search) qs.set('search', params.search);\n const query = qs.toString() ? `?${qs.toString()}` : '';\n return await fetcher<GetAffiliateInvitationsResult>(\n `${STRIPE_API_ROUTE}/affiliate/invitations${query}`,\n authAPIOptions,\n otherOptions,\n { method: 'GET' }\n );\n };\n\n /**\n * Sends an affiliate invitation email to the given address (admin only).\n */\n const sendAffiliateInvitation = async (\n body: SendAffiliateInvitationBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<SendAffiliateInvitationResult>(\n `${STRIPE_API_ROUTE}/affiliate/invite`,\n authAPIOptions,\n otherOptions,\n { method: 'POST', body }\n );\n\n /**\n * Retrieves an affiliate invitation by token (public — no auth required).\n */\n const getAffiliateInvitation = async (\n { token }: { token: string },\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAffiliateInvitationResult>(\n `${STRIPE_API_ROUTE}/affiliate/invitation/${token}`,\n authAPIOptions,\n otherOptions,\n { method: 'GET' }\n );\n\n /**\n * Admin-only: updates an affiliate's status and/or category.\n */\n const updateAffiliateStatus = async (\n { id }: { id: string },\n body: UpdateAffiliateStatusBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateAffiliateStatusResult>(\n `${STRIPE_API_ROUTE}/affiliates/${id}/status`,\n authAPIOptions,\n otherOptions,\n { method: 'PATCH', body }\n );\n\n /**\n * Accepts an affiliate invitation and creates the affiliate account.\n */\n const acceptAffiliateInvitation = async (\n {\n token,\n country,\n stripeAccountType,\n }: {\n token: string;\n country?: string;\n stripeAccountType?: 'express' | 'standard';\n },\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AcceptAffiliateInvitationResult>(\n `${STRIPE_API_ROUTE}/affiliate/invitation/${token}/accept`,\n authAPIOptions,\n otherOptions,\n { method: 'POST', body: { country, stripeAccountType } }\n );\n\n /**\n * Admin-only: returns a paginated list of all promo codes.\n */\n const getPromoCodeById = async (\n id: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetPromoCodeByIdResult>(\n `${STRIPE_API_ROUTE}/promo-codes/${id}`,\n authAPIOptions,\n otherOptions,\n { method: 'GET' }\n );\n\n const getPromoCodes = async (\n params: { affiliateId?: string } = {},\n otherOptions: FetcherOptions = {}\n ) => {\n const qs = params.affiliateId\n ? `?affiliateId=${encodeURIComponent(params.affiliateId)}`\n : '';\n return await fetcher<GetPromoCodesResult>(\n `${STRIPE_API_ROUTE}/promo-codes${qs}`,\n authAPIOptions,\n otherOptions,\n { method: 'GET' }\n );\n };\n\n /**\n * Admin-only: creates a new promo code (Stripe coupon + promotion code).\n */\n const createPromoCode = async (\n body: CreatePromoCodeBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<CreatePromoCodeResult>(\n `${STRIPE_API_ROUTE}/promo-codes`,\n authAPIOptions,\n otherOptions,\n { method: 'POST', body }\n );\n\n /**\n * Admin-only: updates a promo code.\n */\n const updatePromoCode = async (\n { id, ...body }: { id: string } & UpdatePromoCodeBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdatePromoCodeResult>(\n `${STRIPE_API_ROUTE}/promo-codes/${id}`,\n authAPIOptions,\n otherOptions,\n { method: 'PATCH', body }\n );\n\n /**\n * Admin-only: deactivates a promo code (sets active=false, disables Stripe promotion code).\n */\n const deletePromoCode = async (\n { id }: { id: string },\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DeletePromoCodeResult>(\n `${STRIPE_API_ROUTE}/promo-codes/${id}`,\n authAPIOptions,\n otherOptions,\n { method: 'DELETE' }\n );\n\n /**\n * Retrieves the active promo code associated with a given affiliate referral code.\n */\n const getAffiliatePromoCode = async (\n referralCode: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<any>(\n `${STRIPE_API_ROUTE}/affiliate-promo-code/${referralCode}`,\n authAPIOptions,\n otherOptions,\n { method: 'GET' }\n );\n\n return {\n getPricing,\n getSubscription,\n cancelSubscription,\n getInvoices,\n getPaymentMethod,\n createPortalSession,\n grantAffiliateAccess,\n getAffiliates,\n getAffiliateById,\n getAffiliate,\n getAffiliateAccountSession,\n getAffiliateOnboardingLink,\n getAffiliateStats,\n getAffiliateInvitations,\n sendAffiliateInvitation,\n getAffiliateInvitation,\n acceptAffiliateInvitation,\n updateAffiliateStatus,\n getPromoCodeById,\n getPromoCodes,\n createPromoCode,\n updatePromoCode,\n deletePromoCode,\n getAffiliatePromoCode,\n };\n};\n\n/**\n * Authenticated `stripe` endpoint bound to an Intlayer CMS authenticator.\n *\n * Pass an authenticator created with `createIntlayerCMS`, or omit it to use\n * the build-time configuration (`@intlayer/config/built`).\n */\nexport const stripeEndpoint = createEndpoint(getStripeAPI);\n"],"mappings":";;;;;AAqCA,MAAa,gBACX,iBAAiC,CAAC,GAClC,mBACG;CAGH,MAAM,mBAAmB,GAFN,gBAAgB,QAAQ,cAAc,OAAO,WAEzB;;;;;CAMvC,MAAM,aAAa,OACjB,MACA,eAA+B,CAAC,MAEhC,MAAM,QACJ,GAAG,iBAAiB,WACpB,gBACA,cACA;EACE,QAAQ;EACR;CACF,CACF;;;;;CAMF,MAAM,kBAAkB,OACtB,MACA,eAA+B,CAAC,MAEhC,MAAM,QACJ,GAAG,iBAAiB,uBACpB,gBACA,cACA;EACE,QAAQ;EACR;CACF,CACF;;;;;CAMF,MAAM,qBAAqB,OAAO,eAA+B,CAAC,MAChE,MAAM,QACJ,GAAG,iBAAiB,uBACpB,gBACA,cACA,EACE,QAAQ,OACV,CACF;;;;CAKF,MAAM,cAAc,OAAO,eAA+B,CAAC,MACzD,MAAM,QACJ,GAAG,iBAAiB,YACpB,gBACA,cACA,EAAE,QAAQ,MAAM,CAClB;;;;;CAMF,MAAM,mBAAmB,OAAO,eAA+B,CAAC,MAC9D,MAAM,QACJ,GAAG,iBAAiB,kBACpB,gBACA,cACA,EAAE,QAAQ,MAAM,CAClB;;;;CAKF,MAAM,sBAAsB,OAAO,eAA+B,CAAC,MACjE,MAAM,QACJ,GAAG,iBAAiB,kBACpB,gBACA,cACA,EAAE,QAAQ,OAAO,CACnB;;;;CAKF,MAAM,uBAAuB,OAC3B,MACA,eAA+B,CAAC,MAEhC,MAAM,QACJ,GAAG,iBAAiB,mBACpB,gBACA,cACA;EAAE,QAAQ;EAAQ;CAAK,CACzB;;;;CAKF,MAAM,gBAAgB,OACpB,QACA,eAA+B,CAAC,MAEhC,MAAM,QACJ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ACJ,GAAG,iBAAiB,eAAe,MACnC,gBACA,cACA,EAAE,QAAQ,SAAS,CACrB;;;;CAKF,MAAM,wBAAwB,OAC5B,cACA,eAA+B,CAAC,MAEhC,MAAM,QACJ,GAAG,iBAAiB,wBAAwB,gBAC5C,gBACA,cACA,EAAE,QAAQ,MAAM,CAClB;CAEF,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF;;;;;;;AAQA,MAAa,iBAAiB,eAAe,YAAY"}
|
|
1
|
+
{"version":3,"file":"stripe.mjs","names":[],"sources":["../../../src/getIntlayerAPI/stripe.ts"],"sourcesContent":["import type { RouteEndpoints } from '@intlayer/backend-contract/defineRoute';\nimport { buildRouteURL } from '@intlayer/backend-contract/defineRoute';\nimport type {\n AcceptAffiliateInvitationResult,\n CreatePortalSessionResult,\n CreatePromoCodeBody,\n CreatePromoCodeResult,\n DeletePromoCodeResult,\n GetAffiliateAccountSessionResult,\n GetAffiliateByIdResult,\n GetAffiliateInvitationResult,\n GetAffiliateInvitationsResult,\n GetAffiliateOnboardingLinkResult,\n GetAffiliateResult,\n GetAffiliateStatsResult,\n GetAffiliatesParams,\n GetAffiliatesResult,\n GetCheckoutSessionBody,\n GetCheckoutSessionResult,\n GetInvoicesResult,\n GetPaymentMethodResult,\n GetPricingBody,\n GetPricingResult,\n GetPromoCodeByIdResult,\n GetPromoCodesResult,\n GrantAffiliateAccessBody,\n GrantAffiliateAccessResult,\n SendAffiliateInvitationBody,\n SendAffiliateInvitationResult,\n StripeRoutes,\n stripeContract,\n UpdateAffiliateStatusBody,\n UpdateAffiliateStatusResult,\n UpdatePromoCodeBody,\n UpdatePromoCodeResult,\n} from '@intlayer/backend-contract/stripe';\nimport { editor } from '@intlayer/config/built';\nimport { BACKEND_URL } from '@intlayer/config/defaultValues';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { createEndpoint } from '../cms/createIntlayerCMS';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\n/** Prefix of the routes, checked against the backend contract. */\nconst stripeGroup = {\n prefix: '/api/stripe',\n} as const satisfies Pick<typeof stripeContract, 'prefix'>;\n\n/**\n * Method and path of every route, checked against the backend contract at\n * compile time (the contract's zod schemas are never loaded).\n */\nconst stripeEndpoints = {\n getPricing: { method: 'POST', path: '/pricing' },\n createSubscription: { method: 'POST', path: '/create-subscription' },\n cancelSubscription: { method: 'POST', path: '/cancel-subscription' },\n getInvoices: { method: 'GET', path: '/invoices' },\n getPaymentMethod: { method: 'GET', path: '/payment-method' },\n createPortalSession: { method: 'POST', path: '/portal-session' },\n grantAffiliateAccess: { method: 'POST', path: '/affiliate/grant' },\n getAffiliates: { method: 'GET', path: '/affiliates' },\n getAffiliateById: { method: 'GET', path: '/affiliates/:id' },\n getAffiliate: { method: 'GET', path: '/affiliate' },\n getAffiliateAccountSession: {\n method: 'POST',\n path: '/affiliate/account-session',\n },\n getAffiliateOnboardingLink: {\n method: 'GET',\n path: '/affiliate/onboarding-link',\n },\n getAffiliateStats: { method: 'GET', path: '/affiliate/stats' },\n getAffiliateInvitations: { method: 'GET', path: '/affiliate/invitations' },\n sendAffiliateInvitation: { method: 'POST', path: '/affiliate/invite' },\n getAffiliateInvitation: {\n method: 'GET',\n path: '/affiliate/invitation/:token',\n },\n acceptAffiliateInvitation: {\n method: 'POST',\n path: '/affiliate/invitation/:token/accept',\n },\n updateAffiliateStatus: { method: 'PATCH', path: '/affiliates/:id/status' },\n getPromoCodes: { method: 'GET', path: '/promo-codes' },\n getPromoCodeById: { method: 'GET', path: '/promo-codes/:id' },\n createPromoCode: { method: 'POST', path: '/promo-codes' },\n updatePromoCode: { method: 'PATCH', path: '/promo-codes/:id' },\n deletePromoCode: { method: 'DELETE', path: '/promo-codes/:id' },\n getAffiliatePromoCode: {\n method: 'GET',\n path: '/affiliate-promo-code/:referralCode',\n },\n} as const satisfies RouteEndpoints<StripeRoutes>;\n\nexport const getStripeAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL =\n intlayerConfig?.editor?.backendURL ?? editor.backendURL ?? BACKEND_URL;\n\n /**\n * Get a pricing plan calculated for a given promotion code.\n * @param body - Pricing plan body.\n */\n const getPricing = async (\n body?: GetPricingBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetPricingResult>(\n buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getPricing),\n authAPIOptions,\n otherOptions,\n {\n method: stripeEndpoints.getPricing.method,\n body,\n }\n );\n\n /**\n * Retrieves a checkout session.\n * @param body - Checkout session body.\n */\n const getSubscription = async (\n body?: GetCheckoutSessionBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetCheckoutSessionResult>(\n buildRouteURL(\n backendURL,\n stripeGroup,\n stripeEndpoints.createSubscription\n ),\n authAPIOptions,\n otherOptions,\n {\n method: stripeEndpoints.createSubscription.method,\n body,\n }\n );\n\n /**\n * Cancels a subscription.\n * @param body - Checkout session body.\n */\n const cancelSubscription = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetCheckoutSessionResult>(\n buildRouteURL(\n backendURL,\n stripeGroup,\n stripeEndpoints.cancelSubscription\n ),\n authAPIOptions,\n otherOptions,\n {\n method: stripeEndpoints.cancelSubscription.method,\n }\n );\n\n /**\n * Lists invoices for the authenticated organization's Stripe customer.\n */\n const getInvoices = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetInvoicesResult>(\n buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getInvoices),\n authAPIOptions,\n otherOptions,\n { method: stripeEndpoints.getInvoices.method }\n );\n\n /**\n * Returns the first card payment method for the authenticated organization's\n * Stripe customer (or null if none).\n */\n const getPaymentMethod = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetPaymentMethodResult>(\n buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getPaymentMethod),\n authAPIOptions,\n otherOptions,\n { method: stripeEndpoints.getPaymentMethod.method }\n );\n\n /**\n * Creates a Stripe Billing Portal session for the authenticated organization.\n */\n const createPortalSession = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<CreatePortalSessionResult>(\n buildRouteURL(\n backendURL,\n stripeGroup,\n stripeEndpoints.createPortalSession\n ),\n authAPIOptions,\n otherOptions,\n { method: stripeEndpoints.createPortalSession.method }\n );\n\n /**\n * Admin-only: grants affiliate access to a user by creating their Stripe Connect account.\n */\n const grantAffiliateAccess = async (\n body: GrantAffiliateAccessBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GrantAffiliateAccessResult>(\n buildRouteURL(\n backendURL,\n stripeGroup,\n stripeEndpoints.grantAffiliateAccess\n ),\n authAPIOptions,\n otherOptions,\n { method: stripeEndpoints.grantAffiliateAccess.method, body }\n );\n\n /**\n * Admin-only: returns a paginated list of all affiliates.\n */\n const getAffiliates = async (\n params?: GetAffiliatesParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAffiliatesResult>(\n buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getAffiliates),\n authAPIOptions,\n otherOptions,\n {\n method: stripeEndpoints.getAffiliates.method,\n params: params as Record<string, string>,\n }\n );\n\n /**\n * Admin-only: returns a single affiliate by ID.\n */\n const getAffiliateById = async (\n { id }: { id: string },\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAffiliateByIdResult>(\n buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getAffiliateById, {\n id,\n }),\n authAPIOptions,\n otherOptions,\n { method: stripeEndpoints.getAffiliateById.method }\n );\n\n /**\n * Returns the affiliate record for the authenticated user (null if not an affiliate).\n */\n const getAffiliate = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetAffiliateResult>(\n buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getAffiliate),\n authAPIOptions,\n otherOptions,\n { method: stripeEndpoints.getAffiliate.method }\n );\n\n /**\n * Creates a Stripe Connect account session for the authenticated affiliate (embedded onboarding).\n */\n const getAffiliateAccountSession = async (\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAffiliateAccountSessionResult>(\n buildRouteURL(\n backendURL,\n stripeGroup,\n stripeEndpoints.getAffiliateAccountSession\n ),\n authAPIOptions,\n otherOptions,\n { method: stripeEndpoints.getAffiliateAccountSession.method }\n );\n\n /**\n * Returns a Stripe-hosted onboarding URL for the authenticated affiliate.\n */\n const getAffiliateOnboardingLink = async (\n params?: { returnUrl?: string },\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAffiliateOnboardingLinkResult>(\n buildRouteURL(\n backendURL,\n stripeGroup,\n stripeEndpoints.getAffiliateOnboardingLink\n ),\n authAPIOptions,\n otherOptions,\n { method: stripeEndpoints.getAffiliateOnboardingLink.method, params }\n );\n\n /**\n * Returns referral stats for the authenticated affiliate.\n */\n const getAffiliateStats = async (otherOptions: FetcherOptions = {}) =>\n await fetcher<GetAffiliateStatsResult>(\n buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getAffiliateStats),\n authAPIOptions,\n otherOptions,\n { method: stripeEndpoints.getAffiliateStats.method }\n );\n\n /**\n * Admin-only: returns a paginated list of all affiliate invitations.\n */\n const getAffiliateInvitations = async (\n params: GetAffiliatesParams = {},\n otherOptions: FetcherOptions = {}\n ) => {\n const qs = new URLSearchParams();\n if (params.page) qs.set('page', String(params.page));\n if (params.pageSize) qs.set('pageSize', String(params.pageSize));\n if (params.search) qs.set('search', params.search);\n const query = qs.toString() ? `?${qs.toString()}` : '';\n return await fetcher<GetAffiliateInvitationsResult>(\n `${buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getAffiliateInvitations)}${query}`,\n authAPIOptions,\n otherOptions,\n { method: 'GET' }\n );\n };\n\n /**\n * Sends an affiliate invitation email to the given address (admin only).\n */\n const sendAffiliateInvitation = async (\n body: SendAffiliateInvitationBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<SendAffiliateInvitationResult>(\n buildRouteURL(\n backendURL,\n stripeGroup,\n stripeEndpoints.sendAffiliateInvitation\n ),\n authAPIOptions,\n otherOptions,\n { method: stripeEndpoints.sendAffiliateInvitation.method, body }\n );\n\n /**\n * Retrieves an affiliate invitation by token (public — no auth required).\n */\n const getAffiliateInvitation = async (\n { token }: { token: string },\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetAffiliateInvitationResult>(\n buildRouteURL(\n backendURL,\n stripeGroup,\n stripeEndpoints.getAffiliateInvitation,\n { token }\n ),\n authAPIOptions,\n otherOptions,\n { method: stripeEndpoints.getAffiliateInvitation.method }\n );\n\n /**\n * Admin-only: updates an affiliate's status and/or category.\n */\n const updateAffiliateStatus = async (\n { id }: { id: string },\n body: UpdateAffiliateStatusBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateAffiliateStatusResult>(\n buildRouteURL(\n backendURL,\n stripeGroup,\n stripeEndpoints.updateAffiliateStatus,\n { id }\n ),\n authAPIOptions,\n otherOptions,\n { method: stripeEndpoints.updateAffiliateStatus.method, body }\n );\n\n /**\n * Accepts an affiliate invitation and creates the affiliate account.\n */\n const acceptAffiliateInvitation = async (\n {\n token,\n country,\n stripeAccountType,\n }: {\n token: string;\n country?: string;\n stripeAccountType?: 'express' | 'standard';\n },\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<AcceptAffiliateInvitationResult>(\n buildRouteURL(\n backendURL,\n stripeGroup,\n stripeEndpoints.acceptAffiliateInvitation,\n { token }\n ),\n authAPIOptions,\n otherOptions,\n {\n method: stripeEndpoints.acceptAffiliateInvitation.method,\n body: { country, stripeAccountType },\n }\n );\n\n /**\n * Admin-only: returns a paginated list of all promo codes.\n */\n const getPromoCodeById = async (\n id: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetPromoCodeByIdResult>(\n buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getPromoCodeById, {\n id,\n }),\n authAPIOptions,\n otherOptions,\n { method: stripeEndpoints.getPromoCodeById.method }\n );\n\n const getPromoCodes = async (\n params: { affiliateId?: string } = {},\n otherOptions: FetcherOptions = {}\n ) => {\n const qs = params.affiliateId\n ? `?affiliateId=${encodeURIComponent(params.affiliateId)}`\n : '';\n return await fetcher<GetPromoCodesResult>(\n `${buildRouteURL(backendURL, stripeGroup, stripeEndpoints.getPromoCodes)}${qs}`,\n authAPIOptions,\n otherOptions,\n { method: 'GET' }\n );\n };\n\n /**\n * Admin-only: creates a new promo code (Stripe coupon + promotion code).\n */\n const createPromoCode = async (\n body: CreatePromoCodeBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<CreatePromoCodeResult>(\n buildRouteURL(backendURL, stripeGroup, stripeEndpoints.createPromoCode),\n authAPIOptions,\n otherOptions,\n { method: stripeEndpoints.createPromoCode.method, body }\n );\n\n /**\n * Admin-only: updates a promo code.\n */\n const updatePromoCode = async (\n { id, ...body }: { id: string } & UpdatePromoCodeBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdatePromoCodeResult>(\n buildRouteURL(backendURL, stripeGroup, stripeEndpoints.updatePromoCode, {\n id,\n }),\n authAPIOptions,\n otherOptions,\n { method: stripeEndpoints.updatePromoCode.method, body }\n );\n\n /**\n * Admin-only: deactivates a promo code (sets active=false, disables Stripe promotion code).\n */\n const deletePromoCode = async (\n { id }: { id: string },\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DeletePromoCodeResult>(\n buildRouteURL(backendURL, stripeGroup, stripeEndpoints.deletePromoCode, {\n id,\n }),\n authAPIOptions,\n otherOptions,\n { method: stripeEndpoints.deletePromoCode.method }\n );\n\n /**\n * Retrieves the active promo code associated with a given affiliate referral code.\n */\n const getAffiliatePromoCode = async (\n referralCode: string,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<any>(\n buildRouteURL(\n backendURL,\n stripeGroup,\n stripeEndpoints.getAffiliatePromoCode,\n { referralCode }\n ),\n authAPIOptions,\n otherOptions,\n { method: stripeEndpoints.getAffiliatePromoCode.method }\n );\n\n return {\n getPricing,\n getSubscription,\n cancelSubscription,\n getInvoices,\n getPaymentMethod,\n createPortalSession,\n grantAffiliateAccess,\n getAffiliates,\n getAffiliateById,\n getAffiliate,\n getAffiliateAccountSession,\n getAffiliateOnboardingLink,\n getAffiliateStats,\n getAffiliateInvitations,\n sendAffiliateInvitation,\n getAffiliateInvitation,\n acceptAffiliateInvitation,\n updateAffiliateStatus,\n getPromoCodeById,\n getPromoCodes,\n createPromoCode,\n updatePromoCode,\n deletePromoCode,\n getAffiliatePromoCode,\n };\n};\n\n/**\n * Authenticated `stripe` endpoint bound to an Intlayer CMS authenticator.\n *\n * Pass an authenticator created with `createIntlayerCMS`, or omit it to use\n * the build-time configuration (`@intlayer/config/built`).\n */\nexport const stripeEndpoint = createEndpoint(getStripeAPI);\n"],"mappings":";;;;;;;;AA2CA,MAAM,cAAc,EAClB,QAAQ,cACV;;;;;AAMA,MAAM,kBAAkB;CACtB,YAAY;EAAE,QAAQ;EAAQ,MAAM;CAAW;CAC/C,oBAAoB;EAAE,QAAQ;EAAQ,MAAM;CAAuB;CACnE,oBAAoB;EAAE,QAAQ;EAAQ,MAAM;CAAuB;CACnE,aAAa;EAAE,QAAQ;EAAO,MAAM;CAAY;CAChD,kBAAkB;EAAE,QAAQ;EAAO,MAAM;CAAkB;CAC3D,qBAAqB;EAAE,QAAQ;EAAQ,MAAM;CAAkB;CAC/D,sBAAsB;EAAE,QAAQ;EAAQ,MAAM;CAAmB;CACjE,eAAe;EAAE,QAAQ;EAAO,MAAM;CAAc;CACpD,kBAAkB;EAAE,QAAQ;EAAO,MAAM;CAAkB;CAC3D,cAAc;EAAE,QAAQ;EAAO,MAAM;CAAa;CAClD,4BAA4B;EAC1B,QAAQ;EACR,MAAM;CACR;CACA,4BAA4B;EAC1B,QAAQ;EACR,MAAM;CACR;CACA,mBAAmB;EAAE,QAAQ;EAAO,MAAM;CAAmB;CAC7D,yBAAyB;EAAE,QAAQ;EAAO,M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Aa,CACjB,GACA,gBACA,cACA,EAAE,QAAQ,gBAAgB,sBAAsB,OAAO,CACzD;CAEF,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF;;;;;;;AAQA,MAAa,iBAAiB,eAAe,YAAY"}
|
|
@@ -1,15 +1,41 @@
|
|
|
1
1
|
import { fetcher } from "../fetcher.mjs";
|
|
2
2
|
import { createEndpoint } from "../cms/createIntlayerCMS.mjs";
|
|
3
3
|
import { editor } from "@intlayer/config/built";
|
|
4
|
+
import { buildRouteURL } from "@intlayer/backend-contract/defineRoute";
|
|
5
|
+
import { BACKEND_URL } from "@intlayer/config/defaultValues";
|
|
4
6
|
|
|
5
7
|
//#region src/getIntlayerAPI/tag.ts
|
|
8
|
+
/** Prefix of the routes, checked against the backend contract. */
|
|
9
|
+
const tagGroup = { prefix: "/api/tag" };
|
|
10
|
+
/**
|
|
11
|
+
* Method and path of every route, checked against the backend contract at
|
|
12
|
+
* compile time (the contract's zod schemas are never loaded).
|
|
13
|
+
*/
|
|
14
|
+
const tagEndpoints = {
|
|
15
|
+
getTags: {
|
|
16
|
+
method: "GET",
|
|
17
|
+
path: "/"
|
|
18
|
+
},
|
|
19
|
+
addTag: {
|
|
20
|
+
method: "POST",
|
|
21
|
+
path: "/"
|
|
22
|
+
},
|
|
23
|
+
updateTag: {
|
|
24
|
+
method: "PUT",
|
|
25
|
+
path: "/:tagId"
|
|
26
|
+
},
|
|
27
|
+
deleteTag: {
|
|
28
|
+
method: "DELETE",
|
|
29
|
+
path: "/:tagId"
|
|
30
|
+
}
|
|
31
|
+
};
|
|
6
32
|
const getTagAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
7
|
-
const
|
|
33
|
+
const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL ?? BACKEND_URL;
|
|
8
34
|
/**
|
|
9
35
|
* Retrieves a list of tags based on filters and pagination.
|
|
10
36
|
* @param filters - Filters and pagination options.
|
|
11
37
|
*/
|
|
12
|
-
const getTags = async (filters, otherOptions = {}) => await fetcher(
|
|
38
|
+
const getTags = async (filters, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, tagGroup, tagEndpoints.getTags), authAPIOptions, otherOptions, {
|
|
13
39
|
cache: "no-store",
|
|
14
40
|
params: filters
|
|
15
41
|
});
|
|
@@ -17,23 +43,23 @@ const getTagAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
|
17
43
|
* Adds a new tag to the database.
|
|
18
44
|
* @param tag - Tag data.
|
|
19
45
|
*/
|
|
20
|
-
const addTag = async (tag, otherOptions = {}) => await fetcher(
|
|
21
|
-
method:
|
|
46
|
+
const addTag = async (tag, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, tagGroup, tagEndpoints.addTag), authAPIOptions, otherOptions, {
|
|
47
|
+
method: tagEndpoints.addTag.method,
|
|
22
48
|
body: tag
|
|
23
49
|
});
|
|
24
50
|
/**
|
|
25
51
|
* Updates an existing tag in the database.
|
|
26
52
|
* @param tag - Updated tag data.
|
|
27
53
|
*/
|
|
28
|
-
const updateTag = async (tagId, tag, otherOptions = {}) => await fetcher(
|
|
29
|
-
method:
|
|
54
|
+
const updateTag = async (tagId, tag, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, tagGroup, tagEndpoints.updateTag, { tagId: String(tagId) }), authAPIOptions, otherOptions, {
|
|
55
|
+
method: tagEndpoints.updateTag.method,
|
|
30
56
|
body: tag
|
|
31
57
|
});
|
|
32
58
|
/**
|
|
33
59
|
* Deletes a tag from the database by its ID.
|
|
34
60
|
* @param tagId - Tag ID.
|
|
35
61
|
*/
|
|
36
|
-
const deleteTag = async (tagId, otherOptions = {}) => await fetcher(
|
|
62
|
+
const deleteTag = async (tagId, otherOptions = {}) => await fetcher(buildRouteURL(backendURL, tagGroup, tagEndpoints.deleteTag, { tagId: String(tagId) }), authAPIOptions, otherOptions, { method: tagEndpoints.deleteTag.method });
|
|
37
63
|
return {
|
|
38
64
|
getTags,
|
|
39
65
|
addTag,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tag.mjs","names":[],"sources":["../../../src/getIntlayerAPI/tag.ts"],"sourcesContent":["import type {\n AddTagBody,\n AddTagResult,\n DeleteTagParams,\n DeleteTagResult,\n GetTagsParams,\n GetTagsResult,\n UpdateTagBody,\n UpdateTagParams,\n UpdateTagResult,\n} from '@intlayer/backend';\nimport { editor } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { createEndpoint } from '../cms/createIntlayerCMS';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport const getTagAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL
|
|
1
|
+
{"version":3,"file":"tag.mjs","names":[],"sources":["../../../src/getIntlayerAPI/tag.ts"],"sourcesContent":["import type { RouteEndpoints } from '@intlayer/backend-contract/defineRoute';\nimport { buildRouteURL } from '@intlayer/backend-contract/defineRoute';\nimport type {\n AddTagBody,\n AddTagResult,\n DeleteTagParams,\n DeleteTagResult,\n GetTagsParams,\n GetTagsResult,\n TagRoutes,\n tagContract,\n UpdateTagBody,\n UpdateTagParams,\n UpdateTagResult,\n} from '@intlayer/backend-contract/tag';\nimport { editor } from '@intlayer/config/built';\nimport { BACKEND_URL } from '@intlayer/config/defaultValues';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { createEndpoint } from '../cms/createIntlayerCMS';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\n/** Prefix of the routes, checked against the backend contract. */\nconst tagGroup = {\n prefix: '/api/tag',\n} as const satisfies Pick<typeof tagContract, 'prefix'>;\n\n/**\n * Method and path of every route, checked against the backend contract at\n * compile time (the contract's zod schemas are never loaded).\n */\nconst tagEndpoints = {\n getTags: { method: 'GET', path: '/' },\n addTag: { method: 'POST', path: '/' },\n updateTag: { method: 'PUT', path: '/:tagId' },\n deleteTag: { method: 'DELETE', path: '/:tagId' },\n} as const satisfies RouteEndpoints<TagRoutes>;\n\nexport const getTagAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL =\n intlayerConfig?.editor?.backendURL ?? editor.backendURL ?? BACKEND_URL;\n\n /**\n * Retrieves a list of tags based on filters and pagination.\n * @param filters - Filters and pagination options.\n */\n const getTags = async (\n filters?: GetTagsParams,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<GetTagsResult>(\n buildRouteURL(backendURL, tagGroup, tagEndpoints.getTags),\n authAPIOptions,\n otherOptions,\n {\n cache: 'no-store',\n // @ts-ignore Number of parameter will be stringified by the fetcher\n params: filters,\n }\n );\n\n /**\n * Adds a new tag to the database.\n * @param tag - Tag data.\n */\n const addTag = async (tag: AddTagBody, otherOptions: FetcherOptions = {}) =>\n await fetcher<AddTagResult>(\n buildRouteURL(backendURL, tagGroup, tagEndpoints.addTag),\n authAPIOptions,\n otherOptions,\n {\n method: tagEndpoints.addTag.method,\n body: tag,\n }\n );\n\n /**\n * Updates an existing tag in the database.\n * @param tag - Updated tag data.\n */\n const updateTag = async (\n tagId: UpdateTagParams['tagId'],\n tag: UpdateTagBody,\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<UpdateTagResult>(\n buildRouteURL(backendURL, tagGroup, tagEndpoints.updateTag, {\n tagId: String(tagId),\n }),\n authAPIOptions,\n otherOptions,\n {\n method: tagEndpoints.updateTag.method,\n body: tag,\n }\n );\n\n /**\n * Deletes a tag from the database by its ID.\n * @param tagId - Tag ID.\n */\n const deleteTag = async (\n tagId: DeleteTagParams['tagId'],\n\n otherOptions: FetcherOptions = {}\n ) =>\n await fetcher<DeleteTagResult>(\n buildRouteURL(backendURL, tagGroup, tagEndpoints.deleteTag, {\n tagId: String(tagId),\n }),\n authAPIOptions,\n otherOptions,\n {\n method: tagEndpoints.deleteTag.method,\n }\n );\n\n return {\n getTags,\n addTag,\n updateTag,\n deleteTag,\n };\n};\n\n/**\n * Authenticated `tag` endpoint bound to an Intlayer CMS authenticator.\n *\n * Pass an authenticator created with `createIntlayerCMS`, or omit it to use\n * the build-time configuration (`@intlayer/config/built`).\n */\nexport const tagEndpoint = createEndpoint(getTagAPI);\n"],"mappings":";;;;;;;;AAsBA,MAAM,WAAW,EACf,QAAQ,WACV;;;;;AAMA,MAAM,eAAe;CACnB,SAAS;EAAE,QAAQ;EAAO,MAAM;CAAI;CACpC,QAAQ;EAAE,QAAQ;EAAQ,MAAM;CAAI;CACpC,WAAW;EAAE,QAAQ;EAAO,MAAM;CAAU;CAC5C,WAAW;EAAE,QAAQ;EAAU,MAAM;CAAU;AACjD;AAEA,MAAa,aACX,iBAAiC,CAAC,GAClC,mBACG;CACH,MAAM,aACJ,gBAAgB,QAAQ,cAAc,OAAO,cAAc;;;;;CAM7D,MAAM,UAAU,OACd,SACA,eAA+B,CAAC,MAEhC,MAAM,QACJ,cAAc,YAAY,UAAU,aAAa,OAAO,GACxD,gBACA,cACA;EACE,OAAO;EAEP,QAAQ;CACV,CACF;;;;;CAMF,MAAM,SAAS,OAAO,KAAiB,eAA+B,CAAC,MACrE,MAAM,QACJ,cAAc,YAAY,UAAU,aAAa,MAAM,GACvD,gBACA,cACA;EACE,QAAQ,aAAa,OAAO;EAC5B,MAAM;CACR,CACF;;;;;CAMF,MAAM,YAAY,OAChB,OACA,KACA,eAA+B,CAAC,MAEhC,MAAM,QACJ,cAAc,YAAY,UAAU,aAAa,WAAW,EAC1D,OAAO,OAAO,KAAK,EACrB,CAAC,GACD,gBACA,cACA;EACE,QAAQ,aAAa,UAAU;EAC/B,MAAM;CACR,CACF;;;;;CAMF,MAAM,YAAY,OAChB,OAEA,eAA+B,CAAC,MAEhC,MAAM,QACJ,cAAc,YAAY,UAAU,aAAa,WAAW,EAC1D,OAAO,OAAO,KAAK,EACrB,CAAC,GACD,gBACA,cACA,EACE,QAAQ,aAAa,UAAU,OACjC,CACF;CAEF,OAAO;EACL;EACA;EACA;EACA;CACF;AACF;;;;;;;AAQA,MAAa,cAAc,eAAe,SAAS"}
|
|
@@ -1,19 +1,57 @@
|
|
|
1
1
|
import { fetcher } from "../fetcher.mjs";
|
|
2
2
|
import { createEndpoint } from "../cms/createIntlayerCMS.mjs";
|
|
3
3
|
import { editor } from "@intlayer/config/built";
|
|
4
|
+
import { buildRouteURL } from "@intlayer/backend-contract/defineRoute";
|
|
5
|
+
import { BACKEND_URL } from "@intlayer/config/defaultValues";
|
|
4
6
|
|
|
5
7
|
//#region src/getIntlayerAPI/translate.ts
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
/** Prefix of the routes, checked against the backend contract. */
|
|
9
|
+
const translationGroup = { prefix: "/api/translate" };
|
|
10
|
+
/**
|
|
11
|
+
* Method and path of every route, checked against the backend contract at
|
|
12
|
+
* compile time (the contract's zod schemas are never loaded).
|
|
13
|
+
*/
|
|
14
|
+
const translationEndpoints = {
|
|
15
|
+
translateDictionaries: {
|
|
16
|
+
method: "POST",
|
|
17
|
+
path: "/dictionaries"
|
|
18
|
+
},
|
|
19
|
+
getTranslationStatus: {
|
|
20
|
+
method: "GET",
|
|
21
|
+
path: "/status"
|
|
22
|
+
},
|
|
23
|
+
pauseTranslationJob: {
|
|
24
|
+
method: "POST",
|
|
25
|
+
path: "/:jobId/pause"
|
|
26
|
+
},
|
|
27
|
+
resumeTranslationJob: {
|
|
9
28
|
method: "POST",
|
|
29
|
+
path: "/:jobId/resume"
|
|
30
|
+
},
|
|
31
|
+
stopTranslationJob: {
|
|
32
|
+
method: "POST",
|
|
33
|
+
path: "/:jobId/stop"
|
|
34
|
+
},
|
|
35
|
+
retryTranslationJob: {
|
|
36
|
+
method: "POST",
|
|
37
|
+
path: "/:jobId/retry"
|
|
38
|
+
},
|
|
39
|
+
restartTranslationJob: {
|
|
40
|
+
method: "POST",
|
|
41
|
+
path: "/:jobId/restart"
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const getTranslateAPI = (authAPIOptions = {}, intlayerConfig) => {
|
|
45
|
+
const backendURL = intlayerConfig?.editor?.backendURL ?? editor.backendURL ?? BACKEND_URL;
|
|
46
|
+
const translateDictionaries = async (body, otherOptions = {}) => fetcher(buildRouteURL(backendURL, translationGroup, translationEndpoints.translateDictionaries), authAPIOptions, otherOptions, {
|
|
47
|
+
method: translationEndpoints.translateDictionaries.method,
|
|
10
48
|
body
|
|
11
49
|
});
|
|
12
|
-
const pauseTranslationJob = async (jobId, otherOptions = {}) => fetcher(
|
|
13
|
-
const resumeTranslationJob = async (jobId, otherOptions = {}) => fetcher(
|
|
14
|
-
const stopTranslationJob = async (jobId, otherOptions = {}) => fetcher(
|
|
15
|
-
const retryTranslationJob = async (jobId, otherOptions = {}) => fetcher(
|
|
16
|
-
const restartTranslationJob = async (jobId, otherOptions = {}) => fetcher(
|
|
50
|
+
const pauseTranslationJob = async (jobId, otherOptions = {}) => fetcher(buildRouteURL(backendURL, translationGroup, translationEndpoints.pauseTranslationJob, { jobId }), authAPIOptions, otherOptions, { method: translationEndpoints.pauseTranslationJob.method });
|
|
51
|
+
const resumeTranslationJob = async (jobId, otherOptions = {}) => fetcher(buildRouteURL(backendURL, translationGroup, translationEndpoints.resumeTranslationJob, { jobId }), authAPIOptions, otherOptions, { method: translationEndpoints.resumeTranslationJob.method });
|
|
52
|
+
const stopTranslationJob = async (jobId, otherOptions = {}) => fetcher(buildRouteURL(backendURL, translationGroup, translationEndpoints.stopTranslationJob, { jobId }), authAPIOptions, otherOptions, { method: translationEndpoints.stopTranslationJob.method });
|
|
53
|
+
const retryTranslationJob = async (jobId, otherOptions = {}) => fetcher(buildRouteURL(backendURL, translationGroup, translationEndpoints.retryTranslationJob, { jobId }), authAPIOptions, otherOptions, { method: translationEndpoints.retryTranslationJob.method });
|
|
54
|
+
const restartTranslationJob = async (jobId, otherOptions = {}) => fetcher(buildRouteURL(backendURL, translationGroup, translationEndpoints.restartTranslationJob, { jobId }), authAPIOptions, otherOptions, { method: translationEndpoints.restartTranslationJob.method });
|
|
17
55
|
return {
|
|
18
56
|
translateDictionaries,
|
|
19
57
|
pauseTranslationJob,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translate.mjs","names":[],"sources":["../../../src/getIntlayerAPI/translate.ts"],"sourcesContent":["import type {\n TranslateDictionariesBody,\n TranslateDictionariesResult,\n} from '@intlayer/backend';\nimport { editor } from '@intlayer/config/built';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { createEndpoint } from '../cms/createIntlayerCMS';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport type { TranslateDictionariesBody, TranslateDictionariesResult };\n\nexport const getTranslateAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL
|
|
1
|
+
{"version":3,"file":"translate.mjs","names":[],"sources":["../../../src/getIntlayerAPI/translate.ts"],"sourcesContent":["import type { RouteEndpoints } from '@intlayer/backend-contract/defineRoute';\nimport { buildRouteURL } from '@intlayer/backend-contract/defineRoute';\nimport type {\n TranslateDictionariesBody,\n TranslateDictionariesResult,\n TranslationRoutes,\n translationContract,\n} from '@intlayer/backend-contract/translation';\nimport { editor } from '@intlayer/config/built';\nimport { BACKEND_URL } from '@intlayer/config/defaultValues';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport { createEndpoint } from '../cms/createIntlayerCMS';\nimport { type FetcherOptions, fetcher } from '../fetcher';\n\nexport type { TranslateDictionariesBody, TranslateDictionariesResult };\n\n/** Prefix of the routes, checked against the backend contract. */\nconst translationGroup = {\n prefix: '/api/translate',\n} as const satisfies Pick<typeof translationContract, 'prefix'>;\n\n/**\n * Method and path of every route, checked against the backend contract at\n * compile time (the contract's zod schemas are never loaded).\n */\nconst translationEndpoints = {\n translateDictionaries: { method: 'POST', path: '/dictionaries' },\n getTranslationStatus: { method: 'GET', path: '/status' },\n pauseTranslationJob: { method: 'POST', path: '/:jobId/pause' },\n resumeTranslationJob: { method: 'POST', path: '/:jobId/resume' },\n stopTranslationJob: { method: 'POST', path: '/:jobId/stop' },\n retryTranslationJob: { method: 'POST', path: '/:jobId/retry' },\n restartTranslationJob: { method: 'POST', path: '/:jobId/restart' },\n} as const satisfies RouteEndpoints<TranslationRoutes>;\n\nexport const getTranslateAPI = (\n authAPIOptions: FetcherOptions = {},\n intlayerConfig?: IntlayerConfig\n) => {\n const backendURL =\n intlayerConfig?.editor?.backendURL ?? editor.backendURL ?? BACKEND_URL;\n\n const translateDictionaries = async (\n body: TranslateDictionariesBody,\n otherOptions: FetcherOptions = {}\n ) =>\n fetcher<TranslateDictionariesResult>(\n buildRouteURL(\n backendURL,\n translationGroup,\n translationEndpoints.translateDictionaries\n ),\n authAPIOptions,\n otherOptions,\n { method: translationEndpoints.translateDictionaries.method, body }\n );\n\n const pauseTranslationJob = async (\n jobId: string,\n otherOptions: FetcherOptions = {}\n ) =>\n fetcher<{ data: { jobId: string } }>(\n buildRouteURL(\n backendURL,\n translationGroup,\n translationEndpoints.pauseTranslationJob,\n { jobId }\n ),\n authAPIOptions,\n otherOptions,\n { method: translationEndpoints.pauseTranslationJob.method }\n );\n\n const resumeTranslationJob = async (\n jobId: string,\n otherOptions: FetcherOptions = {}\n ) =>\n fetcher<{ data: { jobId: string } }>(\n buildRouteURL(\n backendURL,\n translationGroup,\n translationEndpoints.resumeTranslationJob,\n { jobId }\n ),\n authAPIOptions,\n otherOptions,\n { method: translationEndpoints.resumeTranslationJob.method }\n );\n\n const stopTranslationJob = async (\n jobId: string,\n otherOptions: FetcherOptions = {}\n ) =>\n fetcher<{ data: { jobId: string } }>(\n buildRouteURL(\n backendURL,\n translationGroup,\n translationEndpoints.stopTranslationJob,\n { jobId }\n ),\n authAPIOptions,\n otherOptions,\n { method: translationEndpoints.stopTranslationJob.method }\n );\n\n const retryTranslationJob = async (\n jobId: string,\n otherOptions: FetcherOptions = {}\n ) =>\n fetcher<{ data: { jobId: string } }>(\n buildRouteURL(\n backendURL,\n translationGroup,\n translationEndpoints.retryTranslationJob,\n { jobId }\n ),\n authAPIOptions,\n otherOptions,\n { method: translationEndpoints.retryTranslationJob.method }\n );\n\n const restartTranslationJob = async (\n jobId: string,\n otherOptions: FetcherOptions = {}\n ) =>\n fetcher<{ data: { jobId: string } }>(\n buildRouteURL(\n backendURL,\n translationGroup,\n translationEndpoints.restartTranslationJob,\n { jobId }\n ),\n authAPIOptions,\n otherOptions,\n { method: translationEndpoints.restartTranslationJob.method }\n );\n\n return {\n translateDictionaries,\n pauseTranslationJob,\n resumeTranslationJob,\n stopTranslationJob,\n retryTranslationJob,\n restartTranslationJob,\n };\n};\n\n/**\n * Authenticated `translate` endpoint bound to an Intlayer CMS authenticator.\n *\n * Pass an authenticator created with `createIntlayerCMS`, or omit it to use\n * the build-time configuration (`@intlayer/config/built`).\n */\nexport const translateEndpoint = createEndpoint(getTranslateAPI);\n"],"mappings":";;;;;;;;AAiBA,MAAM,mBAAmB,EACvB,QAAQ,iBACV;;;;;AAMA,MAAM,uBAAuB;CAC3B,uBAAuB;EAAE,QAAQ;EAAQ,MAAM;CAAgB;CAC/D,sBAAsB;EAAE,QAAQ;EAAO,MAAM;CAAU;CACvD,qBAAqB;EAAE,QAAQ;EAAQ,MAAM;CAAgB;CAC7D,sBAAsB;EAAE,QAAQ;EAAQ,MAAM;CAAiB;CAC/D,oBAAoB;EAAE,QAAQ;EAAQ,MAAM;CAAe;CAC3D,qBAAqB;EAAE,QAAQ;EAAQ,MAAM;CAAgB;CAC7D,uBAAuB;EAAE,QAAQ;EAAQ,MAAM;CAAkB;AACnE;AAEA,MAAa,mBACX,iBAAiC,CAAC,GAClC,mBACG;CACH,MAAM,aACJ,gBAAgB,QAAQ,cAAc,OAAO,cAAc;CAE7D,MAAM,wBAAwB,OAC5B,MACA,eAA+B,CAAC,MAEhC,QACE,cACE,YACA,kBACA,qBAAqB,qBACvB,GACA,gBACA,cACA;EAAE,QAAQ,qBAAqB,sBAAsB;EAAQ;CAAK,CACp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