cliodot 1.2.2 → 1.2.4
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/LICENSE +201 -0
- package/README.md +81 -0
- package/dist/AuthAppClient.d.ts +1 -0
- package/dist/AuthAppClient.d.ts.map +1 -1
- package/dist/AuthAppClient.js +199 -1
- package/dist/CommercialAppClient.d.ts +178 -0
- package/dist/CommercialAppClient.d.ts.map +1 -0
- package/dist/CommercialAppClient.js +576 -0
- package/dist/ConnectorBuilder.js +104 -1
- package/dist/Events.d.ts +2 -0
- package/dist/Events.d.ts.map +1 -1
- package/dist/Events.js +325 -1
- package/dist/Flosync.js +296 -1
- package/dist/FlosyncClient.js +429 -1
- package/dist/FunctionBuilder.js +65 -1
- package/dist/IdentityAppClient.d.ts +23 -0
- package/dist/IdentityAppClient.d.ts.map +1 -0
- package/dist/IdentityAppClient.js +197 -0
- package/dist/MemoryAppClient.d.ts +28 -0
- package/dist/MemoryAppClient.d.ts.map +1 -0
- package/dist/MemoryAppClient.js +149 -0
- package/dist/MemoryClient.d.ts +8 -0
- package/dist/MemoryClient.d.ts.map +1 -0
- package/dist/MemoryClient.js +20 -0
- package/dist/OAuthAppClient.d.ts +1 -0
- package/dist/OAuthAppClient.d.ts.map +1 -1
- package/dist/OAuthAppClient.js +269 -1
- package/dist/ProviderServicesClient.d.ts +24 -0
- package/dist/ProviderServicesClient.d.ts.map +1 -0
- package/dist/ProviderServicesClient.js +158 -0
- package/dist/Surface.d.ts +2 -0
- package/dist/Surface.d.ts.map +1 -1
- package/dist/Surface.js +255 -1
- package/dist/ValidatorBuilder.js +24 -1
- package/dist/Webhooks.d.ts +20 -0
- package/dist/Webhooks.d.ts.map +1 -0
- package/dist/Webhooks.js +61 -0
- package/dist/WorkflowBuilder.js +279 -1
- package/dist/__tests__/CommercialAppClient.test.d.ts +2 -0
- package/dist/__tests__/CommercialAppClient.test.d.ts.map +1 -0
- package/dist/__tests__/CommercialAppClient.test.js +217 -0
- package/dist/__tests__/Events.test.js +191 -1
- package/dist/__tests__/IdentityAppClient.test.d.ts +2 -0
- package/dist/__tests__/IdentityAppClient.test.d.ts.map +1 -0
- package/dist/__tests__/IdentityAppClient.test.js +232 -0
- package/dist/__tests__/OAuthAppClient.test.js +300 -1
- package/dist/__tests__/ProviderServicesClient.test.d.ts +2 -0
- package/dist/__tests__/ProviderServicesClient.test.d.ts.map +1 -0
- package/dist/__tests__/ProviderServicesClient.test.js +131 -0
- package/dist/__tests__/Surface.test.js +150 -1
- package/dist/__tests__/errors.test.js +54 -1
- package/dist/__tests__/function.test.js +58 -1
- package/dist/__tests__/helpers.d.ts +5 -0
- package/dist/__tests__/helpers.d.ts.map +1 -0
- package/dist/__tests__/helpers.js +10 -0
- package/dist/__tests__/localhost-lookup.test.d.ts +2 -0
- package/dist/__tests__/localhost-lookup.test.d.ts.map +1 -0
- package/dist/__tests__/localhost-lookup.test.js +26 -0
- package/dist/__tests__/parse-api-error.test.js +26 -1
- package/dist/__tests__/runner.test.js +156 -1
- package/dist/connectors/builtin.js +354 -1
- package/dist/connectors/registry.js +300 -1
- package/dist/decorators/build.js +105 -1
- package/dist/decorators/connector.js +56 -1
- package/dist/decorators/index.js +34 -1
- package/dist/decorators/metadata.js +338 -1
- package/dist/decorators/steps.js +220 -1
- package/dist/decorators/workflow.js +52 -1
- package/dist/errors.js +76 -1
- package/dist/http/__tests__/cliodot-request.environment.test.d.ts +2 -0
- package/dist/http/__tests__/cliodot-request.environment.test.d.ts.map +1 -0
- package/dist/http/__tests__/cliodot-request.environment.test.js +37 -0
- package/dist/http/__tests__/cliodot-result.test.d.ts +2 -0
- package/dist/http/__tests__/cliodot-result.test.d.ts.map +1 -0
- package/dist/http/__tests__/cliodot-result.test.js +57 -0
- package/dist/http/__tests__/events-instance-id.test.d.ts +2 -0
- package/dist/http/__tests__/events-instance-id.test.d.ts.map +1 -0
- package/dist/http/__tests__/events-instance-id.test.js +45 -0
- package/dist/http/cliodot-request.d.ts +35 -0
- package/dist/http/cliodot-request.d.ts.map +1 -0
- package/dist/http/cliodot-request.js +105 -0
- package/dist/http/cliodot-result.d.ts +40 -0
- package/dist/http/cliodot-result.d.ts.map +1 -0
- package/dist/http/cliodot-result.js +139 -0
- package/dist/http/create-client.d.ts +3 -0
- package/dist/http/create-client.d.ts.map +1 -0
- package/dist/http/create-client.js +14 -0
- package/dist/http/events-instance-id.d.ts +11 -0
- package/dist/http/events-instance-id.d.ts.map +1 -0
- package/dist/http/events-instance-id.js +86 -0
- package/dist/http/localhost-lookup.d.ts +12 -0
- package/dist/http/localhost-lookup.d.ts.map +1 -0
- package/dist/http/localhost-lookup.js +67 -0
- package/dist/http/parse-api-error.js +56 -1
- package/dist/http/sanitize-execution-headers.js +79 -1
- package/dist/identity-offline-verify.d.ts +6 -0
- package/dist/identity-offline-verify.d.ts.map +1 -0
- package/dist/identity-offline-verify.js +174 -0
- package/dist/identity-token-cache.d.ts +6 -0
- package/dist/identity-token-cache.d.ts.map +1 -0
- package/dist/identity-token-cache.js +51 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +108 -1
- package/dist/runner/ProcessorEngine.js +1311 -1
- package/dist/runner/connector.executor.js +1786 -1
- package/dist/runner/utilities/math.executor.js +153 -1
- package/dist/runner/utilities/random.executor.js +151 -1
- package/dist/runner/utilities/string.executor.js +825 -1
- package/dist/template.js +127 -1
- package/dist/transformers/StepsToNodesTransformer.js +214 -1
- package/dist/transformers/WorkflowTransformer.js +189 -1
- package/dist/types/auth-app.api.d.ts +2 -0
- package/dist/types/auth-app.api.d.ts.map +1 -1
- package/dist/types/auth-app.api.js +2 -1
- package/dist/types/builtin.js +2 -1
- package/dist/types/client.api.js +2 -1
- package/dist/types/commercial-app.api.d.ts +963 -0
- package/dist/types/commercial-app.api.d.ts.map +1 -0
- package/dist/types/commercial-app.api.js +2 -0
- package/dist/types/connector.js +2 -1
- package/dist/types/context.js +2 -1
- package/dist/types/event-app.api.d.ts +8 -0
- package/dist/types/event-app.api.d.ts.map +1 -1
- package/dist/types/event-app.api.js +2 -1
- package/dist/types/function.js +2 -1
- package/dist/types/identity-app.api.d.ts +99 -0
- package/dist/types/identity-app.api.d.ts.map +1 -0
- package/dist/types/identity-app.api.js +2 -0
- package/dist/types/index.js +23 -1
- package/dist/types/memory-app.api.d.ts +140 -0
- package/dist/types/memory-app.api.d.ts.map +1 -0
- package/dist/types/memory-app.api.js +2 -0
- package/dist/types/oauth-app.api.d.ts +2 -0
- package/dist/types/oauth-app.api.d.ts.map +1 -1
- package/dist/types/oauth-app.api.js +105 -1
- package/dist/types/provider-services.api.d.ts +98 -0
- package/dist/types/provider-services.api.d.ts.map +1 -0
- package/dist/types/provider-services.api.js +2 -0
- package/dist/types/validator.js +2 -1
- package/dist/types/webhook-app.api.d.ts +2 -0
- package/dist/types/webhook-app.api.d.ts.map +1 -0
- package/dist/types/webhook-app.api.js +2 -0
- package/dist/types/workflow.js +33 -1
- package/dist/validators/validators.js +478 -1
- package/dist/variable.js +37 -1
- package/package.json +3 -2
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CommercialAppClient = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const errors_1 = require("./errors");
|
|
9
|
+
const parse_api_error_1 = require("./http/parse-api-error");
|
|
10
|
+
const cliodot_request_1 = require("./http/cliodot-request");
|
|
11
|
+
function trimBaseUrl(url) {
|
|
12
|
+
return url.trim().replace(/\/+$/, "");
|
|
13
|
+
}
|
|
14
|
+
function resolveIdRef(value, keys = ["_id", "id"]) {
|
|
15
|
+
if (typeof value === "string")
|
|
16
|
+
return value.trim();
|
|
17
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
18
|
+
return String(value);
|
|
19
|
+
}
|
|
20
|
+
if (value && typeof value === "object") {
|
|
21
|
+
const obj = value;
|
|
22
|
+
for (const key of keys) {
|
|
23
|
+
const candidate = obj[key];
|
|
24
|
+
if (typeof candidate === "string" && candidate.trim()) {
|
|
25
|
+
return candidate.trim();
|
|
26
|
+
}
|
|
27
|
+
if (typeof candidate === "number" && Number.isFinite(candidate)) {
|
|
28
|
+
return String(candidate);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return "";
|
|
33
|
+
}
|
|
34
|
+
function cleanParams(params) {
|
|
35
|
+
if (!params)
|
|
36
|
+
return undefined;
|
|
37
|
+
const out = {};
|
|
38
|
+
for (const [key, value] of Object.entries(params)) {
|
|
39
|
+
if (value === undefined || value === null)
|
|
40
|
+
continue;
|
|
41
|
+
if (Array.isArray(value)) {
|
|
42
|
+
out[key] = value.join(",");
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (typeof value === "string" ||
|
|
46
|
+
typeof value === "number" ||
|
|
47
|
+
typeof value === "boolean") {
|
|
48
|
+
out[key] = value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return Object.keys(out).length ? out : undefined;
|
|
52
|
+
}
|
|
53
|
+
class CommercialAppClient {
|
|
54
|
+
constructor(config) {
|
|
55
|
+
if (!config.baseUrl?.trim()) {
|
|
56
|
+
throw new errors_1.CliodotApiError("CommercialAppClient requires baseUrl");
|
|
57
|
+
}
|
|
58
|
+
if (!config.appId?.trim()) {
|
|
59
|
+
throw new errors_1.CliodotApiError("CommercialAppClient requires appId");
|
|
60
|
+
}
|
|
61
|
+
this.baseUrl = trimBaseUrl(config.baseUrl);
|
|
62
|
+
this.appId = config.appId.trim();
|
|
63
|
+
this.apiKey =
|
|
64
|
+
config.apiKey?.trim() || config.appApiKey?.trim() || undefined;
|
|
65
|
+
this.appSecret = config.appSecret?.trim() || undefined;
|
|
66
|
+
this.environment = config.environment;
|
|
67
|
+
this.debug = config.debug ?? false;
|
|
68
|
+
this.axios = axios_1.default.create({
|
|
69
|
+
baseURL: `${this.baseUrl}/commercial`,
|
|
70
|
+
timeout: 60000,
|
|
71
|
+
headers: { "Content-Type": "application/json" },
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
check(input) {
|
|
75
|
+
if (!input?.customer?.trim() || !input?.feature?.trim()) {
|
|
76
|
+
throw new errors_1.CliodotApiError("customer and feature are required");
|
|
77
|
+
}
|
|
78
|
+
return this.request("POST", "/v1/check", {
|
|
79
|
+
body: {
|
|
80
|
+
customer: input.customer.trim(),
|
|
81
|
+
feature: input.feature.trim(),
|
|
82
|
+
quantity: input.quantity,
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
consume(input) {
|
|
87
|
+
if (!input?.customer?.trim() || !input?.feature?.trim()) {
|
|
88
|
+
throw new errors_1.CliodotApiError("customer and feature are required");
|
|
89
|
+
}
|
|
90
|
+
return this.request("POST", "/v1/consume", {
|
|
91
|
+
body: {
|
|
92
|
+
customer: input.customer.trim(),
|
|
93
|
+
feature: input.feature.trim(),
|
|
94
|
+
quantity: input.quantity,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
state(input) {
|
|
99
|
+
if (!input?.customer?.trim()) {
|
|
100
|
+
throw new errors_1.CliodotApiError("customer is required");
|
|
101
|
+
}
|
|
102
|
+
return this.request("GET", "/v1/state", {
|
|
103
|
+
params: {
|
|
104
|
+
customer: input.customer.trim(),
|
|
105
|
+
include_billing: input.include_billing ? "true" : undefined,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
getCustomerSubscription(customerId, options) {
|
|
110
|
+
if (!customerId?.trim()) {
|
|
111
|
+
throw new errors_1.CliodotApiError("customerId is required");
|
|
112
|
+
}
|
|
113
|
+
return this.request("GET", `/v1/customers/${encodeURIComponent(customerId.trim())}/subscription`, {
|
|
114
|
+
params: {
|
|
115
|
+
include_billing: options?.include_billing ? "true" : undefined,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
listCustomers(params) {
|
|
120
|
+
return this.request("GET", "/v1/customers", {
|
|
121
|
+
params: cleanParams(params),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
getCustomer(customerId) {
|
|
125
|
+
if (!customerId?.trim()) {
|
|
126
|
+
throw new errors_1.CliodotApiError("customerId is required");
|
|
127
|
+
}
|
|
128
|
+
return this.request("GET", `/v1/customers/${encodeURIComponent(customerId.trim())}`);
|
|
129
|
+
}
|
|
130
|
+
listCredits(customerId, params) {
|
|
131
|
+
if (!customerId?.trim()) {
|
|
132
|
+
throw new errors_1.CliodotApiError("customerId is required");
|
|
133
|
+
}
|
|
134
|
+
return this.request("GET", `/v1/customers/${encodeURIComponent(customerId.trim())}/credits`, { params: cleanParams(params) });
|
|
135
|
+
}
|
|
136
|
+
topupCredits(input) {
|
|
137
|
+
if (!input?.customerId?.trim() || !input?.currency?.trim()) {
|
|
138
|
+
throw new errors_1.CliodotApiError("customerId and currency are required");
|
|
139
|
+
}
|
|
140
|
+
if (!Number.isFinite(input.amount) || input.amount <= 0) {
|
|
141
|
+
throw new errors_1.CliodotApiError("amount must be a positive number");
|
|
142
|
+
}
|
|
143
|
+
return this.request("POST", `/v1/customers/${encodeURIComponent(input.customerId.trim())}/credits/topup`, {
|
|
144
|
+
body: {
|
|
145
|
+
currency: input.currency.trim(),
|
|
146
|
+
amount: input.amount,
|
|
147
|
+
payment_method: input.payment_method,
|
|
148
|
+
card: input.card,
|
|
149
|
+
card_id: input.card_id,
|
|
150
|
+
payment_input: input.payment_input,
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
listCards(customerId, params) {
|
|
155
|
+
if (!customerId?.trim()) {
|
|
156
|
+
throw new errors_1.CliodotApiError("customerId is required");
|
|
157
|
+
}
|
|
158
|
+
return this.request("GET", `/v1/customers/${encodeURIComponent(customerId.trim())}/cards`, { params: cleanParams(params) });
|
|
159
|
+
}
|
|
160
|
+
addCard(customerId, input = {}) {
|
|
161
|
+
if (!customerId?.trim()) {
|
|
162
|
+
throw new errors_1.CliodotApiError("customerId is required");
|
|
163
|
+
}
|
|
164
|
+
return this.request("POST", `/v1/customers/${encodeURIComponent(customerId.trim())}/cards`, { body: input });
|
|
165
|
+
}
|
|
166
|
+
updateCard(customerId, cardId, input = {}) {
|
|
167
|
+
if (!customerId?.trim() || !cardId?.trim()) {
|
|
168
|
+
throw new errors_1.CliodotApiError("customerId and cardId are required");
|
|
169
|
+
}
|
|
170
|
+
return this.request("PATCH", `/v1/customers/${encodeURIComponent(customerId.trim())}/cards/${encodeURIComponent(cardId.trim())}`, { body: input });
|
|
171
|
+
}
|
|
172
|
+
removeCard(customerId, cardId) {
|
|
173
|
+
if (!customerId?.trim() || !cardId?.trim()) {
|
|
174
|
+
throw new errors_1.CliodotApiError("customerId and cardId are required");
|
|
175
|
+
}
|
|
176
|
+
return this.request("DELETE", `/v1/customers/${encodeURIComponent(customerId.trim())}/cards/${encodeURIComponent(cardId.trim())}`);
|
|
177
|
+
}
|
|
178
|
+
setDefaultCard(customerId, cardId) {
|
|
179
|
+
if (!customerId?.trim() || !cardId?.trim()) {
|
|
180
|
+
throw new errors_1.CliodotApiError("customerId and cardId are required");
|
|
181
|
+
}
|
|
182
|
+
return this.request("POST", `/v1/customers/${encodeURIComponent(customerId.trim())}/cards/${encodeURIComponent(cardId.trim())}/default`);
|
|
183
|
+
}
|
|
184
|
+
createCustomer(input) {
|
|
185
|
+
if (!input?.customer_key?.trim() || !input?.name?.trim()) {
|
|
186
|
+
throw new errors_1.CliodotApiError("customer_key and name are required");
|
|
187
|
+
}
|
|
188
|
+
return this.request("POST", "/v1/customers", {
|
|
189
|
+
body: {
|
|
190
|
+
customer_key: input.customer_key.trim(),
|
|
191
|
+
name: input.name.trim(),
|
|
192
|
+
email: input.email,
|
|
193
|
+
preferred_currency: input.preferred_currency,
|
|
194
|
+
tax_ids: input.tax_ids,
|
|
195
|
+
billing_address: input.billing_address,
|
|
196
|
+
metadata: input.metadata,
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
listFeatures(params) {
|
|
201
|
+
return this.request("GET", "/v1/features", {
|
|
202
|
+
params: cleanParams(params),
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
getFeature(featureId) {
|
|
206
|
+
if (!featureId?.trim()) {
|
|
207
|
+
throw new errors_1.CliodotApiError("featureId is required");
|
|
208
|
+
}
|
|
209
|
+
return this.request("GET", `/v1/features/${encodeURIComponent(featureId.trim())}`);
|
|
210
|
+
}
|
|
211
|
+
listPlans(params) {
|
|
212
|
+
return this.request("GET", "/v1/plans", {
|
|
213
|
+
params: cleanParams(params),
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
getPlan(planId) {
|
|
217
|
+
if (!planId?.trim()) {
|
|
218
|
+
throw new errors_1.CliodotApiError("planId is required");
|
|
219
|
+
}
|
|
220
|
+
return this.request("GET", `/v1/plans/${encodeURIComponent(planId.trim())}`);
|
|
221
|
+
}
|
|
222
|
+
listSubscriptions(params) {
|
|
223
|
+
return this.request("GET", "/v1/subscriptions", {
|
|
224
|
+
params: cleanParams(params),
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
getSubscription(subscriptionId) {
|
|
228
|
+
if (!subscriptionId?.trim()) {
|
|
229
|
+
throw new errors_1.CliodotApiError("subscriptionId is required");
|
|
230
|
+
}
|
|
231
|
+
return this.request("GET", `/v1/subscriptions/${encodeURIComponent(subscriptionId.trim())}`);
|
|
232
|
+
}
|
|
233
|
+
listInvoices(params) {
|
|
234
|
+
return this.request("GET", "/v1/invoices", {
|
|
235
|
+
params: cleanParams(params),
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
getInvoice(invoiceId) {
|
|
239
|
+
const id = resolveIdRef(invoiceId, [
|
|
240
|
+
"invoiceId",
|
|
241
|
+
"_id",
|
|
242
|
+
"id",
|
|
243
|
+
"reference",
|
|
244
|
+
]);
|
|
245
|
+
if (!id) {
|
|
246
|
+
throw new errors_1.CliodotApiError("invoiceId is required");
|
|
247
|
+
}
|
|
248
|
+
return this.request("GET", `/v1/invoices/${encodeURIComponent(id)}`);
|
|
249
|
+
}
|
|
250
|
+
createSubscription(input) {
|
|
251
|
+
if (!input?.customer?.trim() || !input?.plan?.trim()) {
|
|
252
|
+
throw new errors_1.CliodotApiError("customer and plan are required");
|
|
253
|
+
}
|
|
254
|
+
return this.request("POST", "/v1/subscriptions", {
|
|
255
|
+
body: {
|
|
256
|
+
customer: input.customer.trim(),
|
|
257
|
+
plan: input.plan.trim(),
|
|
258
|
+
status: input.status,
|
|
259
|
+
currency: input.currency,
|
|
260
|
+
discount_code: input.discount_code,
|
|
261
|
+
tax_rate: input.tax_rate,
|
|
262
|
+
addons: input.addons,
|
|
263
|
+
seats_purchased: input.seats_purchased,
|
|
264
|
+
metadata: input.metadata,
|
|
265
|
+
payment_method: input.payment_method,
|
|
266
|
+
card: input.card,
|
|
267
|
+
card_id: input.card_id,
|
|
268
|
+
payment_input: input.payment_input,
|
|
269
|
+
auto_renew: input.auto_renew,
|
|
270
|
+
renewal_mode: input.renewal_mode,
|
|
271
|
+
skip_trial: input.skip_trial,
|
|
272
|
+
usage_rollover: input.usage_rollover,
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
subscribe(input) {
|
|
277
|
+
return this.createSubscription(input);
|
|
278
|
+
}
|
|
279
|
+
updatePendingSubscription(input) {
|
|
280
|
+
if (!input?.subscriptionId?.trim()) {
|
|
281
|
+
throw new errors_1.CliodotApiError("subscriptionId is required");
|
|
282
|
+
}
|
|
283
|
+
return this.request("PATCH", `/v1/subscriptions/${encodeURIComponent(input.subscriptionId.trim())}`, {
|
|
284
|
+
body: {
|
|
285
|
+
plan: input.plan,
|
|
286
|
+
currency: input.currency,
|
|
287
|
+
discount_code: input.discount_code,
|
|
288
|
+
tax_rate: input.tax_rate,
|
|
289
|
+
addons: input.addons,
|
|
290
|
+
seats_purchased: input.seats_purchased,
|
|
291
|
+
payment_method: input.payment_method,
|
|
292
|
+
card: input.card,
|
|
293
|
+
card_id: input.card_id,
|
|
294
|
+
payment_input: input.payment_input,
|
|
295
|
+
auto_renew: input.auto_renew,
|
|
296
|
+
renewal_mode: input.renewal_mode,
|
|
297
|
+
skip_trial: input.skip_trial,
|
|
298
|
+
metadata: input.metadata,
|
|
299
|
+
},
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
changePlan(input) {
|
|
303
|
+
if (!input?.subscriptionId?.trim() || !input?.plan?.trim()) {
|
|
304
|
+
throw new errors_1.CliodotApiError("subscriptionId and plan are required");
|
|
305
|
+
}
|
|
306
|
+
return this.request("POST", `/v1/subscriptions/${encodeURIComponent(input.subscriptionId.trim())}/change-plan`, {
|
|
307
|
+
body: {
|
|
308
|
+
plan: input.plan.trim(),
|
|
309
|
+
currency: input.currency,
|
|
310
|
+
discount_code: input.discount_code,
|
|
311
|
+
tax_rate: input.tax_rate,
|
|
312
|
+
addons: input.addons,
|
|
313
|
+
seats_purchased: input.seats_purchased,
|
|
314
|
+
payment_method: input.payment_method,
|
|
315
|
+
card: input.card,
|
|
316
|
+
card_id: input.card_id,
|
|
317
|
+
payment_input: input.payment_input,
|
|
318
|
+
auto_renew: input.auto_renew,
|
|
319
|
+
renewal_mode: input.renewal_mode,
|
|
320
|
+
apply_at: input.apply_at,
|
|
321
|
+
usage_rollover: input.usage_rollover,
|
|
322
|
+
},
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
entitlementTopup(input) {
|
|
326
|
+
if (!input?.subscriptionId?.trim() || !input?.feature?.trim()) {
|
|
327
|
+
throw new errors_1.CliodotApiError("subscriptionId and feature are required");
|
|
328
|
+
}
|
|
329
|
+
return this.request("POST", `/v1/subscriptions/${encodeURIComponent(input.subscriptionId.trim())}/entitlement-topup`, {
|
|
330
|
+
body: {
|
|
331
|
+
feature: input.feature.trim(),
|
|
332
|
+
pack_units: input.pack_units,
|
|
333
|
+
pack_index: input.pack_index,
|
|
334
|
+
payment_method: input.payment_method,
|
|
335
|
+
card: input.card,
|
|
336
|
+
card_id: input.card_id,
|
|
337
|
+
payment_input: input.payment_input,
|
|
338
|
+
},
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
chargeUsage(input) {
|
|
342
|
+
if (!input?.subscriptionId?.trim()) {
|
|
343
|
+
throw new errors_1.CliodotApiError("subscriptionId is required");
|
|
344
|
+
}
|
|
345
|
+
return this.request("POST", `/v1/subscriptions/${encodeURIComponent(input.subscriptionId.trim())}/charge-usage`, {
|
|
346
|
+
body: {
|
|
347
|
+
amount: input.amount,
|
|
348
|
+
payment_method: input.payment_method,
|
|
349
|
+
card: input.card,
|
|
350
|
+
card_id: input.card_id,
|
|
351
|
+
payment_input: input.payment_input,
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
renewSubscription(input) {
|
|
356
|
+
if (!input?.subscriptionId?.trim()) {
|
|
357
|
+
throw new errors_1.CliodotApiError("subscriptionId is required");
|
|
358
|
+
}
|
|
359
|
+
return this.request("POST", `/v1/subscriptions/${encodeURIComponent(input.subscriptionId.trim())}/renew`, {
|
|
360
|
+
body: {
|
|
361
|
+
payment_method: input.payment_method,
|
|
362
|
+
},
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
renew(input) {
|
|
366
|
+
return this.renewSubscription(input);
|
|
367
|
+
}
|
|
368
|
+
listEvents(customerId, params) {
|
|
369
|
+
if (!customerId?.trim()) {
|
|
370
|
+
throw new errors_1.CliodotApiError("customerId is required");
|
|
371
|
+
}
|
|
372
|
+
return this.request("GET", `/v1/customers/${encodeURIComponent(customerId.trim())}/events`, { params: cleanParams(params) });
|
|
373
|
+
}
|
|
374
|
+
listUsageEvents(customerId, params) {
|
|
375
|
+
if (!customerId?.trim()) {
|
|
376
|
+
throw new errors_1.CliodotApiError("customerId is required");
|
|
377
|
+
}
|
|
378
|
+
return this.request("GET", `/v1/customers/${encodeURIComponent(customerId.trim())}/usage-events`, { params: cleanParams(params) });
|
|
379
|
+
}
|
|
380
|
+
listEventTypes() {
|
|
381
|
+
return this.request("GET", "/v1/event-types");
|
|
382
|
+
}
|
|
383
|
+
listPaymentMethods() {
|
|
384
|
+
return this.request("GET", "/v1/payment-methods");
|
|
385
|
+
}
|
|
386
|
+
initiatePayment(input) {
|
|
387
|
+
if (!input?.customer?.trim()) {
|
|
388
|
+
throw new errors_1.CliodotApiError("customer is required");
|
|
389
|
+
}
|
|
390
|
+
return this.request("POST", "/v1/payments/initiate", {
|
|
391
|
+
body: {
|
|
392
|
+
customer: input.customer.trim(),
|
|
393
|
+
subscription: input.subscription,
|
|
394
|
+
invoice: input.invoice,
|
|
395
|
+
payment_method: input.payment_method,
|
|
396
|
+
card: input.card,
|
|
397
|
+
card_id: input.card_id,
|
|
398
|
+
input: input.input,
|
|
399
|
+
currency: input.currency,
|
|
400
|
+
discount_code: input.discount_code,
|
|
401
|
+
},
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
confirmPayment(input) {
|
|
405
|
+
if (!input?.reference?.trim() || !input?.status?.trim()) {
|
|
406
|
+
throw new errors_1.CliodotApiError("reference and status are required");
|
|
407
|
+
}
|
|
408
|
+
return this.request("POST", "/v1/payments/confirm", {
|
|
409
|
+
body: {
|
|
410
|
+
reference: input.reference.trim(),
|
|
411
|
+
status: input.status,
|
|
412
|
+
provider_payment_id: input.provider_payment_id,
|
|
413
|
+
failure_reason: input.failure_reason,
|
|
414
|
+
metadata: input.metadata,
|
|
415
|
+
},
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
quote(input) {
|
|
419
|
+
if (!input?.plan?.trim()) {
|
|
420
|
+
throw new errors_1.CliodotApiError("plan is required");
|
|
421
|
+
}
|
|
422
|
+
return this.request("POST", "/v1/pricing/quote", {
|
|
423
|
+
body: {
|
|
424
|
+
plan: input.plan.trim(),
|
|
425
|
+
customer: input.customer,
|
|
426
|
+
currency: input.currency,
|
|
427
|
+
discount_code: input.discount_code,
|
|
428
|
+
tax_rate: input.tax_rate,
|
|
429
|
+
addons: input.addons,
|
|
430
|
+
seats_purchased: input.seats_purchased,
|
|
431
|
+
metadata: input.metadata,
|
|
432
|
+
},
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
previewDiscount(input) {
|
|
436
|
+
if (!input?.code?.trim() || !input?.plan?.trim()) {
|
|
437
|
+
throw new errors_1.CliodotApiError("code and plan are required");
|
|
438
|
+
}
|
|
439
|
+
return this.request("POST", "/v1/discounts/preview", {
|
|
440
|
+
body: {
|
|
441
|
+
code: input.code.trim(),
|
|
442
|
+
plan: input.plan.trim(),
|
|
443
|
+
currency: input.currency,
|
|
444
|
+
customer: input.customer,
|
|
445
|
+
},
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
listDiscounts(params) {
|
|
449
|
+
return this.request("GET", "/v1/discounts", {
|
|
450
|
+
params: cleanParams(params),
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
listTaxRates(params) {
|
|
454
|
+
return this.request("GET", "/v1/tax-rates", {
|
|
455
|
+
params: cleanParams(params),
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
listAddons(params) {
|
|
459
|
+
return this.request("GET", "/v1/addons", {
|
|
460
|
+
params: cleanParams(params),
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
updateSubscriptionStatus(input) {
|
|
464
|
+
if (!input?.subscriptionId?.trim() || !input?.status?.trim()) {
|
|
465
|
+
throw new errors_1.CliodotApiError("subscriptionId and status are required");
|
|
466
|
+
}
|
|
467
|
+
return this.request("PATCH", `/v1/subscriptions/${encodeURIComponent(input.subscriptionId.trim())}/status`, { body: { status: input.status.trim() } });
|
|
468
|
+
}
|
|
469
|
+
archiveSubscription(subscriptionId) {
|
|
470
|
+
if (!subscriptionId?.trim()) {
|
|
471
|
+
throw new errors_1.CliodotApiError("subscriptionId is required");
|
|
472
|
+
}
|
|
473
|
+
return this.request("POST", `/v1/subscriptions/${encodeURIComponent(subscriptionId.trim())}/archive`);
|
|
474
|
+
}
|
|
475
|
+
assignSeat(input) {
|
|
476
|
+
if (!input?.customer?.trim() || !input?.subject_key?.trim()) {
|
|
477
|
+
throw new errors_1.CliodotApiError("customer and subject_key are required");
|
|
478
|
+
}
|
|
479
|
+
return this.request("POST", "/v1/seats/assign", {
|
|
480
|
+
body: {
|
|
481
|
+
customer: input.customer.trim(),
|
|
482
|
+
subject_key: input.subject_key.trim(),
|
|
483
|
+
email: input.email,
|
|
484
|
+
metadata: input.metadata,
|
|
485
|
+
},
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
unassignSeat(input) {
|
|
489
|
+
if (!input?.customer?.trim() || !input?.subject_key?.trim()) {
|
|
490
|
+
throw new errors_1.CliodotApiError("customer and subject_key are required");
|
|
491
|
+
}
|
|
492
|
+
return this.request("POST", "/v1/seats/unassign", {
|
|
493
|
+
body: {
|
|
494
|
+
customer: input.customer.trim(),
|
|
495
|
+
subject_key: input.subject_key.trim(),
|
|
496
|
+
email: input.email,
|
|
497
|
+
metadata: input.metadata,
|
|
498
|
+
},
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
issueLicense(input) {
|
|
502
|
+
if (!input?.customer?.trim()) {
|
|
503
|
+
throw new errors_1.CliodotApiError("customer is required");
|
|
504
|
+
}
|
|
505
|
+
return this.request("POST", "/v1/licenses/issue", {
|
|
506
|
+
body: {
|
|
507
|
+
customer: input.customer.trim(),
|
|
508
|
+
expires_at: input.expires_at,
|
|
509
|
+
metadata: input.metadata,
|
|
510
|
+
},
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
validateLicense(input) {
|
|
514
|
+
if (!input?.license_key?.trim()) {
|
|
515
|
+
throw new errors_1.CliodotApiError("license_key is required");
|
|
516
|
+
}
|
|
517
|
+
return this.request("POST", "/v1/licenses/validate", {
|
|
518
|
+
body: { license_key: input.license_key.trim() },
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
revokeLicense(licenseId) {
|
|
522
|
+
if (!licenseId?.trim()) {
|
|
523
|
+
throw new errors_1.CliodotApiError("licenseId is required");
|
|
524
|
+
}
|
|
525
|
+
return this.request("POST", `/v1/licenses/${encodeURIComponent(licenseId.trim())}/revoke`);
|
|
526
|
+
}
|
|
527
|
+
analytics(params) {
|
|
528
|
+
return this.request("GET", "/v1/analytics", {
|
|
529
|
+
params: cleanParams(params),
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
analyticsCharts(params) {
|
|
533
|
+
return this.request("GET", "/v1/analytics/charts", {
|
|
534
|
+
params: cleanParams(params),
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
buildAuthHeaders() {
|
|
538
|
+
const headers = (0, cliodot_request_1.applyEnvironmentHeader)({
|
|
539
|
+
"x-cliodot-app-id": this.appId,
|
|
540
|
+
}, this.environment);
|
|
541
|
+
if (this.apiKey) {
|
|
542
|
+
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
543
|
+
return headers;
|
|
544
|
+
}
|
|
545
|
+
if (this.appSecret) {
|
|
546
|
+
headers["x-cliodot-app-secret"] = this.appSecret;
|
|
547
|
+
return headers;
|
|
548
|
+
}
|
|
549
|
+
throw new errors_1.CliodotApiError("CommercialAppClient credentials required (apiKey/appApiKey or appSecret)");
|
|
550
|
+
}
|
|
551
|
+
async request(method, path, options) {
|
|
552
|
+
try {
|
|
553
|
+
const { data } = await this.axios({
|
|
554
|
+
method,
|
|
555
|
+
url: path,
|
|
556
|
+
headers: this.buildAuthHeaders(),
|
|
557
|
+
data: options?.body,
|
|
558
|
+
params: cleanParams(options?.params),
|
|
559
|
+
});
|
|
560
|
+
if (data?.ok === false) {
|
|
561
|
+
throw new errors_1.CliodotApiError((0, parse_api_error_1.parseApiErrorMessage)(data) || "Commercial request failed", {
|
|
562
|
+
data,
|
|
563
|
+
code: (0, parse_api_error_1.parseApiErrorCode)(data),
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
return data;
|
|
567
|
+
}
|
|
568
|
+
catch (err) {
|
|
569
|
+
if (err instanceof errors_1.CliodotApiError) {
|
|
570
|
+
throw err;
|
|
571
|
+
}
|
|
572
|
+
throw (0, errors_1.cliodotApiErrorFromAxios)(err, `Request failed: ${method} ${path}`);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
exports.CommercialAppClient = CommercialAppClient;
|
package/dist/ConnectorBuilder.js
CHANGED
|
@@ -1 +1,104 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectorBuilder = void 0;
|
|
4
|
+
exports.connector = connector;
|
|
5
|
+
class ConnectorBuilder {
|
|
6
|
+
constructor(id, name) {
|
|
7
|
+
this._type = "REST";
|
|
8
|
+
this._baseUrl = "";
|
|
9
|
+
this._auth = { type: "bearer" };
|
|
10
|
+
this._endpoints = [];
|
|
11
|
+
this._id = id;
|
|
12
|
+
this._name = name ?? id;
|
|
13
|
+
}
|
|
14
|
+
rest() {
|
|
15
|
+
this._type = "REST";
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
baseUrl(url) {
|
|
19
|
+
this._baseUrl = url;
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
bearer(token) {
|
|
23
|
+
this._auth = { type: "bearer", token };
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
apiKey(key, keyName) {
|
|
27
|
+
this._auth = { type: "api_key", api_key: key, key_name: keyName };
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
botToken(token, prefix = "Bot ") {
|
|
31
|
+
this._auth = { type: "bearer", token, header_name: "Authorization", prefix };
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
customFlow(flow) {
|
|
35
|
+
this._auth = { type: "custom", flow };
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
authConfig(auth) {
|
|
39
|
+
this._auth = auth;
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
description(desc) {
|
|
43
|
+
this._description = desc;
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
slug(s) {
|
|
47
|
+
this._slug = s;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
meta(m) {
|
|
51
|
+
this._meta = m;
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
endpoint(name, method, path, opts) {
|
|
55
|
+
this._endpoints.push({
|
|
56
|
+
name,
|
|
57
|
+
// action: opts?.action ?? name,
|
|
58
|
+
method: (method || "GET").toUpperCase(),
|
|
59
|
+
path,
|
|
60
|
+
...opts,
|
|
61
|
+
});
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
get(name, path, opts) {
|
|
65
|
+
return this.endpoint(name, "GET", path, opts);
|
|
66
|
+
}
|
|
67
|
+
post(name, path, opts) {
|
|
68
|
+
return this.endpoint(name, "POST", path, opts);
|
|
69
|
+
}
|
|
70
|
+
put(name, path, opts) {
|
|
71
|
+
return this.endpoint(name, "PUT", path, opts);
|
|
72
|
+
}
|
|
73
|
+
patch(name, path, opts) {
|
|
74
|
+
return this.endpoint(name, "PATCH", path, opts);
|
|
75
|
+
}
|
|
76
|
+
delete(name, path, opts) {
|
|
77
|
+
return this.endpoint(name, "DELETE", path, opts);
|
|
78
|
+
}
|
|
79
|
+
build() {
|
|
80
|
+
const out = {
|
|
81
|
+
_id: this._id,
|
|
82
|
+
type: this._type,
|
|
83
|
+
name: this._name,
|
|
84
|
+
base_url: this._baseUrl,
|
|
85
|
+
auth: this._auth,
|
|
86
|
+
endpoints: this._endpoints,
|
|
87
|
+
};
|
|
88
|
+
if (this._slug)
|
|
89
|
+
out.slug = this._slug;
|
|
90
|
+
if (this._description)
|
|
91
|
+
out.description = this._description;
|
|
92
|
+
if (this._meta) {
|
|
93
|
+
out.meta = {
|
|
94
|
+
...this._meta,
|
|
95
|
+
last_updated: this._meta.last_updated ?? new Date().toISOString(),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.ConnectorBuilder = ConnectorBuilder;
|
|
102
|
+
function connector(id, name) {
|
|
103
|
+
return new ConnectorBuilder(id, name);
|
|
104
|
+
}
|