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.
Files changed (147) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +81 -0
  3. package/dist/AuthAppClient.d.ts +1 -0
  4. package/dist/AuthAppClient.d.ts.map +1 -1
  5. package/dist/AuthAppClient.js +199 -1
  6. package/dist/CommercialAppClient.d.ts +178 -0
  7. package/dist/CommercialAppClient.d.ts.map +1 -0
  8. package/dist/CommercialAppClient.js +576 -0
  9. package/dist/ConnectorBuilder.js +104 -1
  10. package/dist/Events.d.ts +2 -0
  11. package/dist/Events.d.ts.map +1 -1
  12. package/dist/Events.js +325 -1
  13. package/dist/Flosync.js +296 -1
  14. package/dist/FlosyncClient.js +429 -1
  15. package/dist/FunctionBuilder.js +65 -1
  16. package/dist/IdentityAppClient.d.ts +23 -0
  17. package/dist/IdentityAppClient.d.ts.map +1 -0
  18. package/dist/IdentityAppClient.js +197 -0
  19. package/dist/MemoryAppClient.d.ts +28 -0
  20. package/dist/MemoryAppClient.d.ts.map +1 -0
  21. package/dist/MemoryAppClient.js +149 -0
  22. package/dist/MemoryClient.d.ts +8 -0
  23. package/dist/MemoryClient.d.ts.map +1 -0
  24. package/dist/MemoryClient.js +20 -0
  25. package/dist/OAuthAppClient.d.ts +1 -0
  26. package/dist/OAuthAppClient.d.ts.map +1 -1
  27. package/dist/OAuthAppClient.js +269 -1
  28. package/dist/ProviderServicesClient.d.ts +24 -0
  29. package/dist/ProviderServicesClient.d.ts.map +1 -0
  30. package/dist/ProviderServicesClient.js +158 -0
  31. package/dist/Surface.d.ts +2 -0
  32. package/dist/Surface.d.ts.map +1 -1
  33. package/dist/Surface.js +255 -1
  34. package/dist/ValidatorBuilder.js +24 -1
  35. package/dist/Webhooks.d.ts +20 -0
  36. package/dist/Webhooks.d.ts.map +1 -0
  37. package/dist/Webhooks.js +61 -0
  38. package/dist/WorkflowBuilder.js +279 -1
  39. package/dist/__tests__/CommercialAppClient.test.d.ts +2 -0
  40. package/dist/__tests__/CommercialAppClient.test.d.ts.map +1 -0
  41. package/dist/__tests__/CommercialAppClient.test.js +217 -0
  42. package/dist/__tests__/Events.test.js +191 -1
  43. package/dist/__tests__/IdentityAppClient.test.d.ts +2 -0
  44. package/dist/__tests__/IdentityAppClient.test.d.ts.map +1 -0
  45. package/dist/__tests__/IdentityAppClient.test.js +232 -0
  46. package/dist/__tests__/OAuthAppClient.test.js +300 -1
  47. package/dist/__tests__/ProviderServicesClient.test.d.ts +2 -0
  48. package/dist/__tests__/ProviderServicesClient.test.d.ts.map +1 -0
  49. package/dist/__tests__/ProviderServicesClient.test.js +131 -0
  50. package/dist/__tests__/Surface.test.js +150 -1
  51. package/dist/__tests__/errors.test.js +54 -1
  52. package/dist/__tests__/function.test.js +58 -1
  53. package/dist/__tests__/helpers.d.ts +5 -0
  54. package/dist/__tests__/helpers.d.ts.map +1 -0
  55. package/dist/__tests__/helpers.js +10 -0
  56. package/dist/__tests__/localhost-lookup.test.d.ts +2 -0
  57. package/dist/__tests__/localhost-lookup.test.d.ts.map +1 -0
  58. package/dist/__tests__/localhost-lookup.test.js +26 -0
  59. package/dist/__tests__/parse-api-error.test.js +26 -1
  60. package/dist/__tests__/runner.test.js +156 -1
  61. package/dist/connectors/builtin.js +354 -1
  62. package/dist/connectors/registry.js +300 -1
  63. package/dist/decorators/build.js +105 -1
  64. package/dist/decorators/connector.js +56 -1
  65. package/dist/decorators/index.js +34 -1
  66. package/dist/decorators/metadata.js +338 -1
  67. package/dist/decorators/steps.js +220 -1
  68. package/dist/decorators/workflow.js +52 -1
  69. package/dist/errors.js +76 -1
  70. package/dist/http/__tests__/cliodot-request.environment.test.d.ts +2 -0
  71. package/dist/http/__tests__/cliodot-request.environment.test.d.ts.map +1 -0
  72. package/dist/http/__tests__/cliodot-request.environment.test.js +37 -0
  73. package/dist/http/__tests__/cliodot-result.test.d.ts +2 -0
  74. package/dist/http/__tests__/cliodot-result.test.d.ts.map +1 -0
  75. package/dist/http/__tests__/cliodot-result.test.js +57 -0
  76. package/dist/http/__tests__/events-instance-id.test.d.ts +2 -0
  77. package/dist/http/__tests__/events-instance-id.test.d.ts.map +1 -0
  78. package/dist/http/__tests__/events-instance-id.test.js +45 -0
  79. package/dist/http/cliodot-request.d.ts +35 -0
  80. package/dist/http/cliodot-request.d.ts.map +1 -0
  81. package/dist/http/cliodot-request.js +105 -0
  82. package/dist/http/cliodot-result.d.ts +40 -0
  83. package/dist/http/cliodot-result.d.ts.map +1 -0
  84. package/dist/http/cliodot-result.js +139 -0
  85. package/dist/http/create-client.d.ts +3 -0
  86. package/dist/http/create-client.d.ts.map +1 -0
  87. package/dist/http/create-client.js +14 -0
  88. package/dist/http/events-instance-id.d.ts +11 -0
  89. package/dist/http/events-instance-id.d.ts.map +1 -0
  90. package/dist/http/events-instance-id.js +86 -0
  91. package/dist/http/localhost-lookup.d.ts +12 -0
  92. package/dist/http/localhost-lookup.d.ts.map +1 -0
  93. package/dist/http/localhost-lookup.js +67 -0
  94. package/dist/http/parse-api-error.js +56 -1
  95. package/dist/http/sanitize-execution-headers.js +79 -1
  96. package/dist/identity-offline-verify.d.ts +6 -0
  97. package/dist/identity-offline-verify.d.ts.map +1 -0
  98. package/dist/identity-offline-verify.js +174 -0
  99. package/dist/identity-token-cache.d.ts +6 -0
  100. package/dist/identity-token-cache.d.ts.map +1 -0
  101. package/dist/identity-token-cache.js +51 -0
  102. package/dist/index.d.ts +10 -0
  103. package/dist/index.d.ts.map +1 -1
  104. package/dist/index.js +108 -1
  105. package/dist/runner/ProcessorEngine.js +1311 -1
  106. package/dist/runner/connector.executor.js +1786 -1
  107. package/dist/runner/utilities/math.executor.js +153 -1
  108. package/dist/runner/utilities/random.executor.js +151 -1
  109. package/dist/runner/utilities/string.executor.js +825 -1
  110. package/dist/template.js +127 -1
  111. package/dist/transformers/StepsToNodesTransformer.js +214 -1
  112. package/dist/transformers/WorkflowTransformer.js +189 -1
  113. package/dist/types/auth-app.api.d.ts +2 -0
  114. package/dist/types/auth-app.api.d.ts.map +1 -1
  115. package/dist/types/auth-app.api.js +2 -1
  116. package/dist/types/builtin.js +2 -1
  117. package/dist/types/client.api.js +2 -1
  118. package/dist/types/commercial-app.api.d.ts +963 -0
  119. package/dist/types/commercial-app.api.d.ts.map +1 -0
  120. package/dist/types/commercial-app.api.js +2 -0
  121. package/dist/types/connector.js +2 -1
  122. package/dist/types/context.js +2 -1
  123. package/dist/types/event-app.api.d.ts +8 -0
  124. package/dist/types/event-app.api.d.ts.map +1 -1
  125. package/dist/types/event-app.api.js +2 -1
  126. package/dist/types/function.js +2 -1
  127. package/dist/types/identity-app.api.d.ts +99 -0
  128. package/dist/types/identity-app.api.d.ts.map +1 -0
  129. package/dist/types/identity-app.api.js +2 -0
  130. package/dist/types/index.js +23 -1
  131. package/dist/types/memory-app.api.d.ts +140 -0
  132. package/dist/types/memory-app.api.d.ts.map +1 -0
  133. package/dist/types/memory-app.api.js +2 -0
  134. package/dist/types/oauth-app.api.d.ts +2 -0
  135. package/dist/types/oauth-app.api.d.ts.map +1 -1
  136. package/dist/types/oauth-app.api.js +105 -1
  137. package/dist/types/provider-services.api.d.ts +98 -0
  138. package/dist/types/provider-services.api.d.ts.map +1 -0
  139. package/dist/types/provider-services.api.js +2 -0
  140. package/dist/types/validator.js +2 -1
  141. package/dist/types/webhook-app.api.d.ts +2 -0
  142. package/dist/types/webhook-app.api.d.ts.map +1 -0
  143. package/dist/types/webhook-app.api.js +2 -0
  144. package/dist/types/workflow.js +33 -1
  145. package/dist/validators/validators.js +478 -1
  146. package/dist/variable.js +37 -1
  147. 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;
@@ -1 +1,104 @@
1
- 'use strict';function _0x5211(){const _0x5d4876=['C2X1zW','y3vZDg9TrMXVDW','mte5tejNqwr2','y3vZDg9T','Cg9ZDa','Chv0','nZG1mZe2qwXxrM5o','yMvHCMvY','x2jHC2vvCMW','qM90ia','nZbsyKHcEvK','yxv0AenVBMzPzW','x3nSDwC','x3r5Cgu','Cgf0y2G','x19LC01VzhvSzq','x25HBwu','Dg9vChbLCKnHC2u','uKvtva','zw5KCg9PBNq','revmrvrf','ovn4ruTPvW','ChvZAa','x2LK','x2rLC2nYAxb0Aw9U','mtC3nJm2vvPSCurJ','x2f1DgG','qxv0Ag9YAxPHDgLVBG','mJyYmZu5Cg9gEuzt','yNvPBgq','x21LDge','ufvu','yxbPx2TLEq','yM90vg9Rzw4','Bwv0yq','odu0nZC4zuPOzePz','zgvSzxrL','zgvZy3jPChrPB24','ue9tva','x2vUzhbVAw50CW','CMvZDa','uefuq0G','mtaXotuYAvf3CLDe','r0vu','mtGWmtm1ntbQrfDYzfG','zgvMAw5LuhjVCgvYDhK','yxbPs2v5','yMfZzvvYBa','q29UBMvJDg9YqNvPBgrLCG','mtuZmtq4DLv2sezk'];_0x5211=function(){return _0x5d4876;};return _0x5211();}const _0x545fbf=_0x4189;(function(_0x354bac,_0x9f94c8){const _0x24ba55=_0x4189,_0x15687a=_0x354bac();while(!![]){try{const _0x3309d2=-parseInt(_0x24ba55(0x15f))/0x1+-parseInt(_0x24ba55(0x15c))/0x2+-parseInt(_0x24ba55(0x17b))/0x3+parseInt(_0x24ba55(0x174))/0x4*(-parseInt(_0x24ba55(0x17f))/0x5)+-parseInt(_0x24ba55(0x166))/0x6+parseInt(_0x24ba55(0x177))/0x7*(-parseInt(_0x24ba55(0x16d))/0x8)+-parseInt(_0x24ba55(0x158))/0x9*(-parseInt(_0x24ba55(0x16f))/0xa);if(_0x3309d2===_0x9f94c8)break;else _0x15687a['push'](_0x15687a['shift']());}catch(_0x1f0e23){_0x15687a['push'](_0x15687a['shift']());}}}(_0x5211,0x4799d));Object[_0x545fbf(0x170)](exports,_0x545fbf(0x184),{'value':!![]}),exports[_0x545fbf(0x173)]=void 0x0,exports['connector']=connector;function _0x4189(_0x131d74,_0xf22e3e){_0x131d74=_0x131d74-0x158;const _0x52111a=_0x5211();let _0x41892f=_0x52111a[_0x131d74];if(_0x4189['JpTtrB']===undefined){var _0x51dc3c=function(_0x16badb){const _0x371d4b='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0xbc63c6='',_0x12ff14='';for(let _0xc31506=0x0,_0x40dfac,_0x2796d8,_0x37f83a=0x0;_0x2796d8=_0x16badb['charAt'](_0x37f83a++);~_0x2796d8&&(_0x40dfac=_0xc31506%0x4?_0x40dfac*0x40+_0x2796d8:_0x2796d8,_0xc31506++%0x4)?_0xbc63c6+=String['fromCharCode'](0xff&_0x40dfac>>(-0x2*_0xc31506&0x6)):0x0){_0x2796d8=_0x371d4b['indexOf'](_0x2796d8);}for(let _0xf40479=0x0,_0x225332=_0xbc63c6['length'];_0xf40479<_0x225332;_0xf40479++){_0x12ff14+='%'+('00'+_0xbc63c6['charCodeAt'](_0xf40479)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x12ff14);};_0x4189['dSXdQc']=_0x51dc3c,_0x4189['UkRwCH']={},_0x4189['JpTtrB']=!![];}const _0x135765=_0x52111a[0x0],_0x3ffaa4=_0x131d74+_0x135765,_0x4c5c59=_0x4189['UkRwCH'][_0x3ffaa4];return!_0x4c5c59?(_0x41892f=_0x4189['dSXdQc'](_0x41892f),_0x4189['UkRwCH'][_0x3ffaa4]=_0x41892f):_0x41892f=_0x4c5c59,_0x41892f;}class ConnectorBuilder{constructor(_0xbc63c6,_0x12ff14){const _0x4ed75c=_0x545fbf;this[_0x4ed75c(0x182)]=_0x4ed75c(0x187),this['_baseUrl']='',this['_auth']={'type':_0x4ed75c(0x17c)},this[_0x4ed75c(0x16a)]=[],this['_id']=_0xbc63c6,this[_0x4ed75c(0x185)]=_0x12ff14??_0xbc63c6;}[_0x545fbf(0x16b)](){const _0x5c989b=_0x545fbf;return this[_0x5c989b(0x182)]='REST',this;}[_0x545fbf(0x172)](_0xc31506){const _0x1fda65=_0x545fbf;return this[_0x1fda65(0x17d)]=_0xc31506,this;}[_0x545fbf(0x17c)](_0x40dfac){const _0x5f2261=_0x545fbf;return this[_0x5f2261(0x15d)]={'type':'bearer','token':_0x40dfac},this;}[_0x545fbf(0x171)](_0x2796d8,_0x37f83a){const _0x3ff29e=_0x545fbf;return this['_auth']={'type':_0x3ff29e(0x163),'api_key':_0x2796d8,'key_name':_0x37f83a},this;}[_0x545fbf(0x164)](_0xf40479,_0x225332=_0x545fbf(0x17e)){const _0x1f7012=_0x545fbf;return this[_0x1f7012(0x15d)]={'type':_0x1f7012(0x17c),'token':_0xf40479,'header_name':_0x1f7012(0x15e),'prefix':_0x225332},this;}[_0x545fbf(0x176)](_0x3d732d){const _0x3519a8=_0x545fbf;return this['_auth']={'type':_0x3519a8(0x178),'flow':_0x3d732d},this;}[_0x545fbf(0x180)](_0x2b4cc9){const _0x26eae0=_0x545fbf;return this[_0x26eae0(0x15d)]=_0x2b4cc9,this;}[_0x545fbf(0x168)](_0x42c831){const _0x285049=_0x545fbf;return this[_0x285049(0x15b)]=_0x42c831,this;}['slug'](_0x26d573){const _0x50e102=_0x545fbf;return this[_0x50e102(0x181)]=_0x26d573,this;}[_0x545fbf(0x165)](_0x51365f){const _0x296ec9=_0x545fbf;return this[_0x296ec9(0x161)]=_0x51365f,this;}[_0x545fbf(0x188)](_0x14336b,_0x1e8ab3,_0x38ded4,_0x579a70){const _0x50a32b=_0x545fbf;return this['_endpoints'][_0x50a32b(0x159)]({'name':_0x14336b,'method':(_0x1e8ab3||_0x50a32b(0x16e))[_0x50a32b(0x186)](),'path':_0x38ded4,..._0x579a70}),this;}['get'](_0x221b7e,_0x113fdc,_0x3459f1){const _0x4e3503=_0x545fbf;return this[_0x4e3503(0x188)](_0x221b7e,_0x4e3503(0x16e),_0x113fdc,_0x3459f1);}[_0x545fbf(0x179)](_0x2f43a0,_0x47277a,_0x485295){const _0x915f83=_0x545fbf;return this['endpoint'](_0x2f43a0,_0x915f83(0x169),_0x47277a,_0x485295);}[_0x545fbf(0x17a)](_0x59d4a5,_0x191a3f,_0x17a7ba){const _0x556b09=_0x545fbf;return this['endpoint'](_0x59d4a5,_0x556b09(0x162),_0x191a3f,_0x17a7ba);}[_0x545fbf(0x183)](_0x39bde3,_0x50da33,_0x3302b7){const _0x515083=_0x545fbf;return this[_0x515083(0x188)](_0x39bde3,_0x515083(0x16c),_0x50da33,_0x3302b7);}[_0x545fbf(0x167)](_0x165f9c,_0x43d61c,_0x41748b){const _0x39d0bf=_0x545fbf;return this[_0x39d0bf(0x188)](_0x165f9c,_0x39d0bf(0x189),_0x43d61c,_0x41748b);}[_0x545fbf(0x160)](){const _0x336fd3=_0x545fbf,_0x24a8c2={'_id':this[_0x336fd3(0x15a)],'type':this[_0x336fd3(0x182)],'name':this[_0x336fd3(0x185)],'base_url':this[_0x336fd3(0x17d)],'auth':this[_0x336fd3(0x15d)],'endpoints':this['_endpoints']};if(this[_0x336fd3(0x181)])_0x24a8c2[_0x336fd3(0x175)]=this['_slug'];if(this[_0x336fd3(0x15b)])_0x24a8c2[_0x336fd3(0x168)]=this['_description'];return this[_0x336fd3(0x161)]&&(_0x24a8c2[_0x336fd3(0x165)]={...this[_0x336fd3(0x161)],'last_updated':this[_0x336fd3(0x161)]['last_updated']??new Date()['toISOString']()}),_0x24a8c2;}}exports[_0x545fbf(0x173)]=ConnectorBuilder;function connector(_0x157ecb,_0x348103){return new ConnectorBuilder(_0x157ecb,_0x348103);}
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
+ }