@kelviq/mcp-server 0.2.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.
Files changed (149) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +322 -0
  3. package/dist/config.d.ts +16 -0
  4. package/dist/config.js +45 -0
  5. package/dist/config.js.map +1 -0
  6. package/dist/docs/README.md +128 -0
  7. package/dist/docs/api-reference/authentication.md +41 -0
  8. package/dist/docs/backend-integration/node-sdk.md +1040 -0
  9. package/dist/docs/backend-integration/python-sdk.md +1198 -0
  10. package/dist/docs/changelog/app.md +80 -0
  11. package/dist/docs/changelog/checkout-api.md +59 -0
  12. package/dist/docs/changelog/js-promotions-ui.md +14 -0
  13. package/dist/docs/changelog/js-sdk.md +281 -0
  14. package/dist/docs/changelog/node-sdk.md +378 -0
  15. package/dist/docs/changelog/python-sdk.md +456 -0
  16. package/dist/docs/changelog/react-sdk.md +580 -0
  17. package/dist/docs/checkout/checkout-configuration.md +434 -0
  18. package/dist/docs/coustomers-management/overview.md +111 -0
  19. package/dist/docs/customer-portal/overview.md +81 -0
  20. package/dist/docs/frontend-integration/js-sdk.md +676 -0
  21. package/dist/docs/frontend-integration/promotions-ui-js.md +265 -0
  22. package/dist/docs/frontend-integration/react-promotions-ui.md +361 -0
  23. package/dist/docs/frontend-integration/react-sdk.md +1187 -0
  24. package/dist/docs/frontend-integration/react-ui.md +771 -0
  25. package/dist/docs/getstarted/fees.md +160 -0
  26. package/dist/docs/getstarted/introduction-to-kelviq.md +80 -0
  27. package/dist/docs/getstarted/merchant-of-record.md +64 -0
  28. package/dist/docs/getstarted/review-process.md +190 -0
  29. package/dist/docs/guides/subscription-integration-for-nextjs.md +512 -0
  30. package/dist/docs/guides/subscription-integration.md +291 -0
  31. package/dist/docs/guides/webhooks.md +963 -0
  32. package/dist/docs/legal/approved-prohibited-policy.md +252 -0
  33. package/dist/docs/legal/buyer-terms.md +177 -0
  34. package/dist/docs/legal/compliant-user-flow.md +216 -0
  35. package/dist/docs/legal/master-service-agreement.md +404 -0
  36. package/dist/docs/legal/payment-flow-diagram.md +188 -0
  37. package/dist/docs/legal/seller-terms.md +169 -0
  38. package/dist/docs/manifest.json +415 -0
  39. package/dist/docs/monetization/offerings.md +156 -0
  40. package/dist/docs/monetization/pricing-tables.md +226 -0
  41. package/dist/docs/monetization/targeting-rules.md +278 -0
  42. package/dist/docs/openapi.json +5479 -0
  43. package/dist/docs/payouts/overview.md +43 -0
  44. package/dist/docs/payouts/payout-account.md +12 -0
  45. package/dist/docs/payouts/transactions.md +23 -0
  46. package/dist/docs/product-catalog/digital-downloads.md +117 -0
  47. package/dist/docs/product-catalog/discounts.md +69 -0
  48. package/dist/docs/product-catalog/entitlements.md +428 -0
  49. package/dist/docs/product-catalog/free-and-trials.md +36 -0
  50. package/dist/docs/product-catalog/license-keys.md +324 -0
  51. package/dist/docs/product-catalog/links.md +92 -0
  52. package/dist/docs/product-catalog/location-based-pricing.md +41 -0
  53. package/dist/docs/product-catalog/one-time-payments.md +24 -0
  54. package/dist/docs/product-catalog/plans.md +199 -0
  55. package/dist/docs/product-catalog/products.md +60 -0
  56. package/dist/docs/product-catalog/subscriptions.md +29 -0
  57. package/dist/docs/product-catalog/tax-settings.md +37 -0
  58. package/dist/docs/product-catalog/usage-based-billing.md +119 -0
  59. package/dist/docs/promotions/create-a-promotion.md +75 -0
  60. package/dist/docs/promotions/customize-banner.md +41 -0
  61. package/dist/docs/promotions/integrate.md +38 -0
  62. package/dist/docs/promotions/overview.md +51 -0
  63. package/dist/docs/quickstart/core-concepts.md +146 -0
  64. package/dist/docs/quickstart/dashboard-setup.md +129 -0
  65. package/dist/docs/quickstart/integrate-with-your-app.md +149 -0
  66. package/dist/docs/sales/checkout-sessions.md +58 -0
  67. package/dist/docs/sales/orders.md +76 -0
  68. package/dist/http/client.d.ts +28 -0
  69. package/dist/http/client.js +76 -0
  70. package/dist/http/client.js.map +1 -0
  71. package/dist/http/errors.d.ts +20 -0
  72. package/dist/http/errors.js +58 -0
  73. package/dist/http/errors.js.map +1 -0
  74. package/dist/resources/docs-index.d.ts +25 -0
  75. package/dist/resources/docs-index.js +109 -0
  76. package/dist/resources/docs-index.js.map +1 -0
  77. package/dist/resources/index.d.ts +2 -0
  78. package/dist/resources/index.js +73 -0
  79. package/dist/resources/index.js.map +1 -0
  80. package/dist/schemas/kelviq.d.ts +1304 -0
  81. package/dist/schemas/kelviq.js +468 -0
  82. package/dist/schemas/kelviq.js.map +1 -0
  83. package/dist/server.d.ts +2 -0
  84. package/dist/server.js +41 -0
  85. package/dist/server.js.map +1 -0
  86. package/dist/tools/_util.d.ts +15 -0
  87. package/dist/tools/_util.js +15 -0
  88. package/dist/tools/_util.js.map +1 -0
  89. package/dist/tools/checkout.d.ts +3 -0
  90. package/dist/tools/checkout.js +18 -0
  91. package/dist/tools/checkout.js.map +1 -0
  92. package/dist/tools/customers.d.ts +3 -0
  93. package/dist/tools/customers.js +32 -0
  94. package/dist/tools/customers.js.map +1 -0
  95. package/dist/tools/docs.d.ts +2 -0
  96. package/dist/tools/docs.js +43 -0
  97. package/dist/tools/docs.js.map +1 -0
  98. package/dist/tools/entitlements.d.ts +3 -0
  99. package/dist/tools/entitlements.js +22 -0
  100. package/dist/tools/entitlements.js.map +1 -0
  101. package/dist/tools/features.d.ts +3 -0
  102. package/dist/tools/features.js +55 -0
  103. package/dist/tools/features.js.map +1 -0
  104. package/dist/tools/index.d.ts +3 -0
  105. package/dist/tools/index.js +44 -0
  106. package/dist/tools/index.js.map +1 -0
  107. package/dist/tools/licenses.d.ts +3 -0
  108. package/dist/tools/licenses.js +44 -0
  109. package/dist/tools/licenses.js.map +1 -0
  110. package/dist/tools/media.d.ts +3 -0
  111. package/dist/tools/media.js +18 -0
  112. package/dist/tools/media.js.map +1 -0
  113. package/dist/tools/offerings.d.ts +3 -0
  114. package/dist/tools/offerings.js +21 -0
  115. package/dist/tools/offerings.js.map +1 -0
  116. package/dist/tools/partner.d.ts +3 -0
  117. package/dist/tools/partner.js +55 -0
  118. package/dist/tools/partner.js.map +1 -0
  119. package/dist/tools/plan-entitlements.d.ts +3 -0
  120. package/dist/tools/plan-entitlements.js +56 -0
  121. package/dist/tools/plan-entitlements.js.map +1 -0
  122. package/dist/tools/plan-files.d.ts +3 -0
  123. package/dist/tools/plan-files.js +43 -0
  124. package/dist/tools/plan-files.js.map +1 -0
  125. package/dist/tools/plans.d.ts +3 -0
  126. package/dist/tools/plans.js +120 -0
  127. package/dist/tools/plans.js.map +1 -0
  128. package/dist/tools/portal.d.ts +3 -0
  129. package/dist/tools/portal.js +18 -0
  130. package/dist/tools/portal.js.map +1 -0
  131. package/dist/tools/product-files.d.ts +3 -0
  132. package/dist/tools/product-files.js +31 -0
  133. package/dist/tools/product-files.js.map +1 -0
  134. package/dist/tools/product-settings.d.ts +3 -0
  135. package/dist/tools/product-settings.js +31 -0
  136. package/dist/tools/product-settings.js.map +1 -0
  137. package/dist/tools/products.d.ts +3 -0
  138. package/dist/tools/products.js +69 -0
  139. package/dist/tools/products.js.map +1 -0
  140. package/dist/tools/promotions.d.ts +3 -0
  141. package/dist/tools/promotions.js +19 -0
  142. package/dist/tools/promotions.js.map +1 -0
  143. package/dist/tools/subscriptions.d.ts +3 -0
  144. package/dist/tools/subscriptions.js +63 -0
  145. package/dist/tools/subscriptions.js.map +1 -0
  146. package/dist/tools/usage.d.ts +3 -0
  147. package/dist/tools/usage.js +18 -0
  148. package/dist/tools/usage.js.map +1 -0
  149. package/package.json +88 -0
@@ -0,0 +1,1040 @@
1
+ ---
2
+ title: "Node SDK"
3
+ slug: "backend-integration/node-sdk"
4
+ section: "backend-integration"
5
+ description: "Documentation for the Kelviq Node SDK"
6
+ ---
7
+ ## Overview
8
+
9
+ The Kelviq Node SDK provides a convenient way to interact with the Kelviq REST APIs from your Node application.
10
+
11
+ ## Installation
12
+
13
+ Install the Kelviq SDK using npm or yarn:
14
+
15
+ ```shell
16
+ npm install @kelviq/node-sdk
17
+ ```
18
+ or
19
+
20
+ ```shell
21
+ yarn add @kelviq/node-sdk
22
+ ```
23
+
24
+ ## Prerequisites
25
+
26
+ Before you can initialize the client and use the SDK methods, you need a **Server API Key**.
27
+
28
+ You can obtain this key from the Kelviq application:
29
+
30
+ 1. Navigate to Settings.
31
+ 2. Go to the [API keys](https://app.kelviq.com/settings/api-keys) section.
32
+ 3. Copy the **Server API Key**.
33
+
34
+ **Security Warning:** The Server API Key should never be exposed in client-side code. Use it only in your backend services. For client-side applications, use the Client API Key with the [React SDK](/frontend-integration/react-sdk) or [JavaScript SDK](/frontend-integration/js-sdk).
35
+
36
+ Once copied, add this key to your environment variables (recommended for security):
37
+
38
+ ```typescript
39
+ // Example of setting it in your code (environment variables recommended)
40
+ const ACCESS_TOKEN = process.env.KELVIQ_SERVER_API_KEY;
41
+ ```
42
+
43
+ ## Configuring the Client
44
+
45
+ The SDK provides a main `Kelviq` client class. You instantiate it directly with your configuration options.
46
+
47
+ ```typescript
48
+
49
+ const ACCESS_TOKEN: string = "YOUR_SECRET_ACCESS_TOKEN";
50
+ ```
51
+
52
+ #### How to Create a Client
53
+
54
+ ```typescript
55
+ import { Kelviq } from '@kelviq/node-sdk';
56
+
57
+ const client = new Kelviq({ accessToken: ACCESS_TOKEN });
58
+
59
+ ```
60
+
61
+ ## Supported Functionalities
62
+
63
+ The SDK currently supports the following operations:
64
+
65
+ 1. [Customers](/backend-integration/node-sdk#customers)
66
+
67
+ 2. [Checkout](/backend-integration/node-sdk#checkout)
68
+
69
+ 3. [Entitlements](/backend-integration/node-sdk#entitlements)
70
+
71
+ 4. [Reporting](/backend-integration/node-sdk#reporting)
72
+
73
+ 5. [Subscriptions](/backend-integration/node-sdk#subscriptions)
74
+
75
+ 6. [License](/backend-integration/node-sdk#license)
76
+
77
+ 7. [Portal](/backend-integration/node-sdk#portal)
78
+
79
+ ---
80
+
81
+ ## Customers
82
+
83
+ The `customers` module allows you to manage customer records within Kelviq. You can access these operations via the `customers` attribute on an initialized `Kelviq` client instance.
84
+
85
+ ---
86
+
87
+ ### Creates a new customer
88
+
89
+ ```typescript
90
+ const newCustomer = await client.customers.create({
91
+ customerId: "unique-customer-id-789",
92
+ email: "new.node.customer@example.com",
93
+ name: "Node SDK User",
94
+ metadata: { source: "sdk_import", priority: "high" }
95
+ });
96
+ ```
97
+
98
+ ```json
99
+ {
100
+ "id": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
101
+ "customerId": "unique-customer-id-789",
102
+ "name": "Node SDK User",
103
+ "email": "new.node.customer@example.com",
104
+ "details": {},
105
+ "metadata": {
106
+ "source": "sdk_import",
107
+ "priority": "high"
108
+ },
109
+ "createdOn": "2025-06-04T06:03:30.195790Z",
110
+ "modifiedOn": "2025-06-04T06:03:30.195831Z"
111
+ }
112
+ ```
113
+
114
+ **Required Parameters:**
115
+
116
+ * `customerId` : A unique identifier for the customer that you define. This ID will be used to reference the customer in subsequent API calls.
117
+
118
+ **Optional Parameters:**
119
+
120
+ * `email` : The email address of the customer. Must be a valid email format.
121
+ * `name` : The name of the customer.
122
+ * `metadata` : An object of custom key-value pairs to store additional information about the customer.
123
+
124
+ **Returns:**
125
+ An instance of `CustomerResponse` (TypeScript Interface), representing the newly created customer record. Key attributes include:
126
+
127
+ * `id` : The server-generated unique UUID for the customer record.
128
+ * `customerId` : The client-provided customer identifier.
129
+ * `name` : The customer's name.
130
+ * `email` : The customer's email.
131
+ * `details` : Any server-added details about the customer (typically read-only).
132
+ * `metadata` : The metadata associated with the customer.
133
+ * `createdOn` : ISO 8601 timestamp of when the customer was created.
134
+ * `modifiedOn` : ISO 8601 timestamp of when the customer was last modified.
135
+
136
+ ### Updates an existing customer
137
+
138
+ This operation performs a partial update (PATCH), so you only need to provide the fields you want to change.
139
+
140
+ ```typescript
141
+ const updatedCustomer = await client.customers.update({
142
+ customerId: "unique-customer-id-789",
143
+ name: "Node SDK User (Updated)",
144
+ metadata: { tier: "premium_plus" }
145
+ });
146
+ ```
147
+
148
+ ```json
149
+ {
150
+ "id": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
151
+ "customerId": "unique-customer-id-789",
152
+ "name": "Node SDK User (Updated)",
153
+ "email": "new.node.customer@example.com",
154
+ "details": {},
155
+ "metadata": {
156
+ "tier": "premium_plus"
157
+ },
158
+ "createdOn": "2025-06-04T06:03:30.195790Z",
159
+ "modifiedOn": "2025-06-04T06:03:30.195831Z"
160
+ }
161
+ ```
162
+
163
+ **Parameters:**
164
+
165
+ **Required Parameters:**
166
+
167
+ * `customerId` : A unique identifier for the customer that you define. This ID will be used to reference the customer in subsequent API calls.
168
+
169
+ **Optional Parameters:**
170
+
171
+ * `email` : The email address of the customer. Must be a valid email format.
172
+ * `name` : The name of the customer.
173
+ * `metadata` : An object of custom key-value pairs to store additional information about the customer.
174
+
175
+ **Returns:**
176
+ An instance of `CustomerResponse` (TypeScript Interface), representing the updated customer record. Key attributes include:
177
+
178
+ * `id` : The server-generated unique UUID for the customer record.
179
+ * `customerId` : The client-provided customer identifier.
180
+ * `name` : The customer's name.
181
+ * `email` : The customer's email.
182
+ * `details` : Any server-added details about the customer (typically read-only).
183
+ * `metadata` : The metadata associated with the customer.
184
+ * `createdOn` : ISO 8601 timestamp of when the customer was created.
185
+ * `modifiedOn` : ISO 8601 timestamp of when the customer was last modified.
186
+
187
+ ---
188
+
189
+ ## Checkout
190
+
191
+ The checkout module provides functionalities for creating and managing checkout sessions. You can access these operations via the checkout attribute on an initialized Kelviq client instance.
192
+
193
+ This operation creates a new checkout session for a customer, allowing them to proceed with a purchase or subscription.
194
+
195
+ ```typescript
196
+ import { Kelviq, CHARGE_PERIOD_CHOICES } from '@kelviq/node-sdk';
197
+
198
+ const response = await client.checkout.createSession({
199
+ planIdentifier: "plan-pro-monthly",
200
+ chargePeriod: CHARGE_PERIOD_CHOICES.MONTHLY,
201
+ successUrl: "https://yourwebsite.com/checkout/success",
202
+ customerId: "cust_789", // Recommended, otherwise it will create a new customer
203
+ });
204
+
205
+ ```
206
+
207
+ ```json
208
+ {
209
+ "checkoutUrl": "https://www.kelviq.com/checkout/cs_fBhCIBerpe1pAsRW6P4wYc8WHqMdfdr457hd3oOLjhAFx/",
210
+ "checkoutSessionId": "cs_test_b1sNi7D6u9iMCUFV1UZi9ZwerfaiXKdOOmr3DCUW6XdCZIr5Id1F7G"
211
+ }
212
+ ```
213
+
214
+ **Required Parameters:**
215
+
216
+ * `planIdentifier` : The identifier of the specific plan the customer is checking out with. planIdentifier is mandatory.
217
+
218
+ * `successUrl` : The URL to which the user will be redirected after a successful checkout.
219
+
220
+ * `chargePeriod` : The billing cycle for the subscription. Must be one of:
221
+
222
+ * `"ONE_TIME"`
223
+
224
+ * `"MONTHLY"`
225
+
226
+ * `"YEARLY"`
227
+
228
+ * `"WEEKLY"`
229
+
230
+ * `"DAILY"`
231
+
232
+ * `"THREE_MONTHS"`
233
+
234
+ * `"SIX_MONTHS"`
235
+
236
+ **Optional Parameters:**
237
+
238
+ * `offeringId` : The ID (uuid) of the offering the customer is checking out with.
239
+
240
+ * `pricingTableId` : The id (uuid) of the pricing table being used for this checkout. (Considered only if `offeringId` is not provided)
241
+
242
+ * `ruleId` : The id (uuid) of the pricing rule being applied. (Considered only if `offeringId` is not provided)
243
+
244
+ * `customerId` : The ID of the customer initiating the checkout. (If not provided, a new customer will be created)
245
+
246
+ * `features`: A list of objects, where each object represents a feature and its desired quantity. Each object **must** have two keys:
247
+ * `"identifier"` : The unique identifier for the feature.
248
+ * `"quantity"`: The desired quantity for this feature.
249
+ * Example: `[{"identifier": "seats", "quantity": 10}, {"identifier": "api-calls-tier1", "quantity": 5000}]`
250
+
251
+ * `ipAddress` : The IP Address of the customer, used for location based pricing.
252
+
253
+ * `currencyCode` : The currency code for the checkout session (e.g. `"USD"`). Required when `customAmount` is provided.
254
+
255
+ * `customAmount` : A custom amount to charge for this checkout session. When provided, `taxBehavior` and `currencyCode` are also required.
256
+
257
+ * `taxBehavior` : Specifies how taxes are applied to the `customAmount`. Required when `customAmount` is provided. Must be one of:
258
+ * `"INCLUSIVE"` — Tax is included in the custom amount.
259
+ * `"EXCLUSIVE"` — Tax is added on top of the custom amount.
260
+
261
+ * `discountsEnabled` : Whether the discount/coupon code field is shown on the checkout page. Defaults to `true`.
262
+
263
+ * `lockEmail` : When `true`, the email field is pre-filled and locked so the customer cannot change it. Defaults to `false`.
264
+
265
+ * `defaultBillingCountry` : ISO 3166-1 alpha-2 country code (e.g. `"US"`, `"GB"`) used to pre-fill the billing address country on the checkout page.
266
+
267
+ **Returns**:
268
+
269
+ An instance of CreateCheckoutSessionResponse (Object), which includes:
270
+
271
+ * `checkoutSessionId` : The unique ID for the created checkout session.
272
+
273
+ * `checkoutUrl` : The URL that the customer should be redirected to in order to complete the payment and activate the subscription/purchase.
274
+
275
+ ---
276
+
277
+ ## Entitlements
278
+
279
+ The entitlements module allows you to check and retrieve customer entitlements for various features. These operations target a specific edge API endpoint ( `https://edge.api.kelviq.com` by default) and use the GET HTTP method with query parameters.
280
+
281
+ ### Checks if a specific customer has access to a particular feature.
282
+ This method directly returns a boolean indicating access status.
283
+
284
+ ```typescript
285
+ const hasAccess = await client.entitlements.hasAccess({
286
+ customerId: "cust_node_ent_123",
287
+ featureId: "premium-reporting-node"
288
+ });
289
+ ```
290
+
291
+ ```shell
292
+ true
293
+ ```
294
+
295
+ **Required Parameters**:
296
+
297
+ * `customerId` : The unique identifier for the customer.
298
+
299
+ * `featureId` : The unique identifier for the feature whose access is being checked.
300
+
301
+ **Returns**:
302
+
303
+ * `boolean`: `true` if the customer has access to the specified feature (considering feature type, limits, etc.), `false` otherwise or if the feature is not found in their entitlements.
304
+
305
+ ### Retrieves the aggregated entitlement for a specific feature for a given customer.
306
+
307
+ ```typescript
308
+ const entitlement = await client.entitlements.getEntitlement({
309
+ customerId: "cust_node_ent_123",
310
+ featureId: "premium-reporting-node"
311
+ });
312
+ ```
313
+
314
+ ```json
315
+ {
316
+ "featureId": "advanced-analytics",
317
+ "featureType": "METER",
318
+ "hasAccess": true,
319
+ "hardLimit": false,
320
+ "usageLimit": 3,
321
+ "currentUsage": 0,
322
+ "remaining": 3,
323
+ "items": [
324
+ {
325
+ "featureId": "advanced-analytics",
326
+ "featureType": "METER",
327
+ "hasAccess": true,
328
+ "resetAt": "2025-05-22 08:27:45",
329
+ "hardLimit": false,
330
+ "usageLimit": 3,
331
+ "currentUsage": 0,
332
+ "remaining": 3
333
+ }
334
+ ]
335
+ }
336
+ ```
337
+
338
+ **Required Parameters**:
339
+
340
+ * `customerId` : The unique identifier for the customer.
341
+
342
+ * `featureId` : The unique identifier for the feature whose access is being checked.
343
+
344
+ **Returns**:
345
+
346
+ An aggregated `Entitlement` object, or `null` if the feature is not found. If the customer has multiple subscriptions, there can be multiple raw entries for the same featureId. The SDK aggregates them and keeps raw entries in the `items` array. Note: `resetAt` is only available on individual items (not at the top level) because it can differ across subscriptions. The structure includes:
347
+
348
+ * `featureId`: string
349
+
350
+ * `hasAccess`: boolean — For **METER** features, computed as `remaining === null || remaining > 0`. For **BOOLEAN** and **CUSTOMIZABLE** features, `true` if at least one item grants access.
351
+
352
+ * `featureType`: string — `"METER"`, `"BOOLEAN"`, or `"CUSTOMIZABLE"`.
353
+
354
+ * `hardLimit`: boolean | null — For **METER**, `true` if any item has a hard limit. For **BOOLEAN**, always `false`.
355
+
356
+ * `usageLimit`: number | null — For **METER**, summed across all items. For **CUSTOMIZABLE**, taken from the first item. For **BOOLEAN**, always `null`.
357
+
358
+ * `currentUsage`: number | null — For **METER**, summed across all items. For **CUSTOMIZABLE**, taken from the first item. For **BOOLEAN**, always `0`.
359
+
360
+ * `remaining`: number | null — For **METER**, computed as `usageLimit - currentUsage`. For **CUSTOMIZABLE**, taken from the first item. For **BOOLEAN**, always `null`.
361
+
362
+ * `items` (`EntitlementDetail[]`): An array containing all raw entitlement entries for this featureId. Each item includes `resetAt`.
363
+
364
+ ### Retrieves all aggregated entitlements for a given customer.
365
+
366
+ ```typescript
367
+ const entitlements = await client.entitlements.getEntitlements({
368
+ customerId: "cust_node_ent_123"
369
+ });
370
+
371
+ // Access a specific feature directly by featureId
372
+ const analytics = entitlements["advanced-analytics"];
373
+ ```
374
+
375
+ ```json
376
+ {
377
+ "advanced-analytics": {
378
+ "featureId": "advanced-analytics",
379
+ "featureType": "METER",
380
+ "hasAccess": true,
381
+ "hardLimit": false,
382
+ "usageLimit": 3,
383
+ "currentUsage": 0,
384
+ "remaining": 3,
385
+ "items": [
386
+ {
387
+ "featureId": "advanced-analytics",
388
+ "featureType": "METER",
389
+ "hasAccess": true,
390
+ "resetAt": "2025-05-22 08:27:45",
391
+ "hardLimit": false,
392
+ "usageLimit": 3,
393
+ "currentUsage": 0,
394
+ "remaining": 3
395
+ }
396
+ ]
397
+ }
398
+ }
399
+ ```
400
+
401
+ **Required Parameters**:
402
+
403
+ * `customerId` : The unique identifier for the customer.
404
+
405
+ **Returns**:
406
+
407
+ A `Record<string, Entitlement>` keyed by `featureId`. If the customer has multiple subscriptions, there can be multiple raw entries for the same featureId. The SDK aggregates them and keeps raw entries in the `items` array. Note: `resetAt` is only available on individual items (not at the top level) because it can differ across subscriptions. Each `Entitlement` value has the same structure as described in `getEntitlement` above.
408
+
409
+ ### Retrieves the raw entitlement from the API for a specific feature.
410
+
411
+ ```typescript
412
+ const response = await client.entitlements.getRawEntitlement({
413
+ customerId: "cust_node_ent_123",
414
+ featureId: "premium-reporting-node"
415
+ });
416
+ ```
417
+
418
+ ```json
419
+ {
420
+ "customerId": "cust_456",
421
+ "entitlements": [
422
+ {
423
+ "featureId": "advanced-analytics",
424
+ "featureType": "METER",
425
+ "hasAccess": true,
426
+ "resetAt": "2025-05-22 08:27:45",
427
+ "hardLimit": false,
428
+ "usageLimit": 3,
429
+ "currentUsage": 0,
430
+ "remaining": 3
431
+ }
432
+ ]
433
+ }
434
+ ```
435
+
436
+ **Required Parameters**:
437
+
438
+ * `customerId` : The unique identifier for the customer.
439
+
440
+ * `featureId` : The unique identifier for the feature.
441
+
442
+ **Returns**:
443
+
444
+ An instance of `CheckEntitlementsResponse` (Object). This returns the raw API response without aggregation. The structure includes:
445
+
446
+ * `customerId` : The customer's ID.
447
+
448
+ * `entitlements` (`EntitlementDetail[]`): A list containing raw entitlement details. Each `EntitlementDetail` has fields like:
449
+
450
+ * `featureId`: string
451
+
452
+ * `hasAccess`: boolean
453
+
454
+ * `featureType`: string
455
+
456
+ * `resetAt`: string
457
+
458
+ * `hardLimit`: boolean | null
459
+
460
+ * `usageLimit`: number | null
461
+
462
+ * `currentUsage`: number | null
463
+
464
+ * `remaining`: number | null
465
+
466
+ ### Retrieves all raw entitlements from the API without aggregation.
467
+
468
+ ```typescript
469
+ const response = await client.entitlements.getRawEntitlements({
470
+ customerId: "cust_node_ent_123"
471
+ });
472
+ ```
473
+
474
+ ```json
475
+ {
476
+ "customerId": "cust_456",
477
+ "entitlements": [
478
+ {
479
+ "featureId": "advanced-analytics",
480
+ "featureType": "METER",
481
+ "hasAccess": true,
482
+ "resetAt": "2025-05-22 08:27:45",
483
+ "hardLimit": false,
484
+ "usageLimit": 3,
485
+ "currentUsage": 0,
486
+ "remaining": 3
487
+ }
488
+ ]
489
+ }
490
+ ```
491
+
492
+ **Required Parameters**:
493
+
494
+ * `customerId` : The unique identifier for the customer.
495
+
496
+ **Returns**:
497
+
498
+ An instance of `CheckEntitlementsResponse` (Object). This returns the raw API response without aggregation. The structure includes:
499
+
500
+ * `customerId` : The customer's ID.
501
+
502
+ * `entitlements` (`EntitlementDetail[]`): A list containing raw entitlement details. Each `EntitlementDetail` has fields like:
503
+
504
+ * `featureId`: string
505
+
506
+ * `hasAccess`: boolean
507
+
508
+ * `featureType`: string
509
+
510
+ * `resetAt`: string
511
+
512
+ * `hardLimit`: boolean | null
513
+
514
+ * `usageLimit`: number | null
515
+
516
+ * `currentUsage`: number | null
517
+
518
+ * `remaining`: number | null
519
+
520
+ ---
521
+
522
+ ## Reporting
523
+
524
+ ### Reporting pre-aggregated usages for customer
525
+
526
+ This endpoint is used for reporting the pre-aggregated feature usage from your application (client-level) to the Kelviq application. It allows you to update the usage count for a specific feature associated with a customer.
527
+
528
+ ```typescript
529
+ import { BEHAVIOUR_CHOICES } from '@kelviq/node-sdk';
530
+
531
+ const response = await client.reporting.reportUsage({
532
+ value: 150,
533
+ customerId: "customer_001",
534
+ featureId: "seats",
535
+ behaviour: BEHAVIOUR_CHOICES.SET
536
+ });
537
+ ```
538
+
539
+ ```json
540
+ {
541
+ "value": 150,
542
+ "customerId": "customer_001",
543
+ "featureId": "seats",
544
+ "behaviour": "SET",
545
+ "orgId": "1",
546
+ "eventName": "aggregated.usage",
547
+ "idempotencyKey": "597ee95063c744ed9bcc9b1cf5676a8a",
548
+ "timestamp": "2025-05-22 08:27:45.430732"
549
+ }
550
+ ```
551
+
552
+ **Required Parameters**:
553
+
554
+ * `value`: The usage value being reported.
555
+
556
+ * `customerId` : The unique identifier for the customer associated with this usage.
557
+
558
+ * `featureId` : The unique identifier for the feature for which usage is being reported.
559
+
560
+ * `behaviour` parameter dictates how the usage is updated:
561
+
562
+ * `SET`: This will replace the current usage value for the feature with the new `value` provided.
563
+
564
+ * `DELTA`: This will increment the existing usage value for the feature by the amount specified in the `value` parameter
565
+
566
+ **Returns**:
567
+
568
+ An instance of ReportUsageResponse (Object), which includes:
569
+
570
+ * `value`: The usage value that was recorded.
571
+
572
+ * `customerId` : The customer ID associated with the usage.
573
+
574
+ * `featureId` : The feature Identifier for which usage was recorded.
575
+
576
+ * `behaviour` : The behaviour type ("SET" or "DELTA") that was processed.
577
+
578
+ * `orgId` : The organization ID associated with this record, as determined by the server.
579
+
580
+ * `eventName` : An internal event name generated by the server for this usage report (e.g., "aggregated.usage").
581
+
582
+ * `idempotencyKey` : A unique idempotency key generated by the server for this specific usage report instance.
583
+
584
+ * `timestamp` : The server-generated UTC timestamp (string format) indicating when the usage report was processed.
585
+
586
+ ## Subscriptions
587
+
588
+ The subscriptions module allows you to manage customer subscriptions, including updates and cancellation. You can access these operations via the `subscriptions` attribute on an initialized Kelviq client instance.
589
+
590
+ ### Updates an existing subscription to a new plan
591
+
592
+ ```typescript
593
+ import { CHARGE_PERIOD_CHOICES } from '@kelviq/node-sdk';
594
+
595
+ try {
596
+ const response = await client.subscriptions.update({
597
+ subscriptionId: "sub_node_78058918",
598
+ planIdentifier: "premium-plan-node",
599
+ chargePeriod: CHARGE_PERIOD_CHOICES.MONTHLY,
600
+ trialEnd: "2025-12-31T23:59:59Z" // or "now" to end the trial immediately
601
+ });
602
+ } catch (e) {
603
+ console.error(`Error updating subscription: ${e}`);
604
+ }
605
+ ```
606
+
607
+ ```json
608
+ {
609
+ "subscriptionId": "dffaf07e-4517-47db-ba3a-59a05aa2d465"
610
+ }
611
+ ```
612
+
613
+ **Required Parameters**:
614
+
615
+ * `subscriptionId` : The unique identifier of the subscription to be updated.
616
+ * `planIdentifier` : The identifier of the new plan.
617
+ * `chargePeriod` : The new charging period for the subscription. Must be one of:
618
+ * `"ONE_TIME"`
619
+ * `"MONTHLY"`
620
+ * `"YEARLY"`
621
+ * `"WEEKLY"`
622
+ * `"DAILY"`
623
+ * `"THREE_MONTHS"`
624
+ * `"SIX_MONTHS"`
625
+
626
+ **Optional Parameters:**
627
+
628
+ * `offeringId` : The ID of the new offering, if applicable.
629
+ * `pricingTableId` : The ID of the new pricing table, if applicable.
630
+ * `ruleId` : The ID of the new pricing rule, if applicable.
631
+ * `ipAddress` : The IP Address of the customer, used for location based pricing.
632
+ * `features`: An array of objects, where each object represents a feature and its desired quantity to update for the subscription. Each object **must** have two keys:
633
+ * `"identifier"` : The unique identifier for the feature.
634
+ * `"quantity"` : The desired quantity for this feature.
635
+ * Example: `[{"identifier": "seats", "quantity": 10}, {"identifier": "projects", "quantity": 5}]`
636
+ * `trialEnd` (string): Controls the trial period for the updated subscription. Accepts either:
637
+ * The literal string `"now"` to end any active trial immediately.
638
+ * An ISO 8601 datetime string (e.g. `"2025-12-31T23:59:59Z"`) to set a new trial end date. The datetime must be in the future. Naive datetimes (no timezone designator) are interpreted as UTC.
639
+ * If omitted, the existing trial behavior on the subscription is preserved.
640
+
641
+ The SDK validates `trialEnd` client-side — invalid datetime strings or past datetimes throw `InvalidRequestError` before the request is sent.
642
+
643
+ **Returns**:
644
+
645
+ An instance of `UpdateSubscriptionResponse`, which includes:
646
+
647
+ * `subscriptionId` (string): UUID of the updated subscription.
648
+
649
+ ### Cancel an active subscription for a customer.
650
+
651
+ ```typescript
652
+ import { CANCELLATION_TYPES } from '@kelviq/node-sdk';
653
+
654
+ try {
655
+ const response = await client.subscriptions.cancel({
656
+ subscriptionId: "sub_node_78058918",
657
+ cancellationType: CANCELLATION_TYPES.CURRENT_PERIOD_ENDS
658
+ });
659
+ } catch (e) {
660
+ console.error(`Error cancelling subscription: ${e}`);
661
+ }
662
+ ```
663
+
664
+ ```json
665
+ {
666
+ "message": "Subscription cancellation processed successfully."
667
+ }
668
+ ```
669
+
670
+ **Required Parameters**:
671
+
672
+ * `subscriptionId` : The unique identifier of the subscription to be cancelled.
673
+
674
+ * `cancellationType` : The type of cancellation to perform. Must be one of:
675
+
676
+ * `"IMMEDIATE"`: The subscription is cancelled immediately.
677
+ * `"CURRENT_PERIOD_ENDS"`: The subscription will remain active until the end of the current billing period and then cancel.
678
+ * `"SPECIFIC_DATE"`: The subscription will be cancelled on the specified `cancellationDate`.
679
+
680
+ * `cancellationDate` : The specific date for cancellation if `cancellationType` is `"SPECIFIC_DATE"`. Must be in `YYYY-MM-DD` format. This parameter is **required** if `cancellationType` is `"SPECIFIC_DATE"`.
681
+
682
+ **Returns**:
683
+
684
+ An instance of `CancelSubscriptionResponse`, which includes:
685
+
686
+ * `message` : A confirmation message indicating the result of the cancellation request.
687
+
688
+ ---
689
+
690
+ ## License
691
+
692
+ The `license` module allows you to activate, deactivate, and validate software licenses. You can access these operations via the `license` attribute on an initialized `Kelviq` client instance.
693
+
694
+ ---
695
+
696
+ ### Activate a license key
697
+
698
+ Creates a new license instance for a given license key, optionally associating it with a customer.
699
+
700
+ ```typescript
701
+ const response = await client.license.activate({
702
+ licenseKey: "LIC-XXXX-YYYY-ZZZZ",
703
+ customerId: "cust_789",
704
+ instanceName: "My MacBook Pro",
705
+ metadata: { os: "macOS", arch: "arm64" }
706
+ });
707
+
708
+ console.log(response.instanceId);
709
+ ```
710
+
711
+ ```json
712
+ {
713
+ "instanceId": "8f3e2b1a-5c6d-4e9f-8a0b-1c2d3e4f5g6h",
714
+ "activatedAt": "2026-01-27T10:33:00Z",
715
+ "expiresOn": "2027-01-27T10:33:00Z",
716
+ "license": {
717
+ "id": "7be7a5b6-7a0e-4178-a085-8ef48f0649ab",
718
+ "licenseKey": "LIC-A8D5F89E-B46B-472C-9BED-66EE2545B85E",
719
+ "activatedOn": "2026-01-22T03:26:56Z",
720
+ "expiresOn": "2026-01-23T03:26:56Z",
721
+ "activationUsage": 1,
722
+ "activationLimit": 4,
723
+ "enabled": true,
724
+ "customer": {
725
+ "customerId": "cfa95cf8c8d24e8b9d3d2d1ada98a94d",
726
+ "name": "Geo",
727
+ "email": "geo@kelviq.com"
728
+ },
729
+ "plan": {
730
+ "identifier": "pro-yearly",
731
+ "name": "Pro Yearly",
732
+ "description": "Pro plan billed yearly",
733
+ "product": {
734
+ "id": "d970ab2d-834f-4c52-8742-2e6ed7e8a31f",
735
+ "identifier": "kelviq-engine",
736
+ "name": "Kelviq Engine",
737
+ "taxCode": "software",
738
+ "createdOn": "2025-01-01T00:00:00Z",
739
+ "modifiedOn": "2025-06-01T00:00:00Z"
740
+ },
741
+ "version": 1,
742
+ "isLatest": true
743
+ },
744
+ "subscription": {
745
+ "id": "09d706ca-58f3-4fb2-818f-5b8623d67e6e",
746
+ "recurrence": "1 month",
747
+ "billingPeriodStartTime": "2026-01-22T03:26:56Z",
748
+ "billingPeriodEndTime": "2026-02-22T03:26:56Z",
749
+ "startDate": "2026-01-22",
750
+ "endDate": null,
751
+ "status": "active",
752
+ "amount": "49.00",
753
+ "currency": "usd",
754
+ "trialDaysRemaining": 0,
755
+ "billingType": "SUBSCRIPTION",
756
+ "recurrenceUnit": 1,
757
+ "recurrenceType": "MONTH"
758
+ }
759
+ }
760
+ }
761
+ ```
762
+
763
+ **Required Parameters:**
764
+
765
+ * `licenseKey` : The license key string to activate.
766
+
767
+ **Optional Parameters:**
768
+
769
+ * `customerId` : The ID of the customer this instance is associated with.
770
+ * `instanceName` : A human-readable name for this instance (e.g. device name).
771
+ * `metadata` : An object of custom key-value pairs to attach to the instance.
772
+
773
+ **Returns:**
774
+
775
+ An instance of `LicenseActivateResponse`, which includes:
776
+
777
+ * `instanceId` (string): The unique ID of the newly created license instance.
778
+ * `activatedAt` (string): ISO 8601 timestamp of when the instance was activated.
779
+ * `expiresOn` (string | null): ISO 8601 timestamp of when the instance expires, if applicable.
780
+ * `license` (`LicenseDetails`): The full license object. Key fields:
781
+ * `id` : Server-generated UUID for the license.
782
+ * `licenseKey` : The license key string.
783
+ * `activatedOn` (string | null): ISO 8601 timestamp of when the license was first activated.
784
+ * `expiresOn` (string | null): ISO 8601 timestamp of when the license expires.
785
+ * `activationUsage` : Number of currently active instances.
786
+ * `activationLimit` : Maximum number of allowed concurrent activations.
787
+ * `enabled` : Whether the license is active.
788
+ * `customer` (object | null): The associated customer, if any. Fields: `customerId`, `name`, `email`.
789
+ * `plan` (object | null): The plan associated with this license, if any. Fields: `identifier`, `name`, `description`, `version`, `isLatest`, and `product` (object with `id`, `identifier`, `name`, `taxCode`, `createdOn`, `modifiedOn`).
790
+ * `subscription` (object | null): Subscription details, if any. Fields: `id`, `recurrence`, `billingPeriodStartTime`, `billingPeriodEndTime`, `startDate`, `endDate`, `status`, `amount`, `currency`, `trialDaysRemaining`, `billingType`, `recurrenceUnit`, `recurrenceType`.
791
+
792
+ ---
793
+
794
+ ### Deactivate a license instance
795
+
796
+ Deactivates a specific license instance by its instance ID.
797
+
798
+ ```typescript
799
+ try {
800
+ const response = await client.license.deactivate({
801
+ licenseKey: "LIC-XXXX-YYYY-ZZZZ",
802
+ instanceId: "8f3e2b1a-5c6d-4e9f-8a0b-1c2d3e4f5a6b"
803
+ });
804
+ console.log(response.message);
805
+ } catch (e) {
806
+ console.error(`Error deactivating license: ${e}`);
807
+ }
808
+ ```
809
+
810
+ ```json
811
+ {
812
+ "message": "License instance deactivated successfully.",
813
+ "deactivatedAt": "2026-01-27T10:35:00Z"
814
+ }
815
+ ```
816
+
817
+ **Required Parameters:**
818
+
819
+ * `licenseKey` : The license key string.
820
+ * `instanceId` : The unique ID of the instance to deactivate.
821
+
822
+ **Returns:**
823
+
824
+ An instance of `LicenseDeactivateResponse`, which includes:
825
+
826
+ * `message` (string): Confirmation message.
827
+ * `deactivatedAt` (string): ISO 8601 timestamp of when the instance was deactivated.
828
+
829
+ ---
830
+
831
+ ### Validate a license key
832
+
833
+ Checks whether a license key (and optionally a specific instance) is valid.
834
+
835
+ ```typescript
836
+ const response = await client.license.validate({
837
+ licenseKey: "LIC-XXXX-YYYY-ZZZZ",
838
+ instanceId: "8f3e2b1a-5c6d-4e9f-8a0b-1c2d3e4f5a6b" // optional
839
+ });
840
+
841
+ if (response.valid) {
842
+ console.log("License is valid:", response.code);
843
+ } else {
844
+ console.log("License invalid:", response.detail);
845
+ }
846
+ ```
847
+
848
+ ```json
849
+ {
850
+ "valid": true,
851
+ "code": "VALID",
852
+ "detail": "Instance ID valid for this license.",
853
+ "metadata": {
854
+ "os": "macOS",
855
+ "arch": "arm64"
856
+ },
857
+ "license": {
858
+ "id": "7be7a5b6-7a0e-4178-a085-8ef48f0649ab",
859
+ "licenseKey": "LIC-A8D5F89E-B46B-472C-9BED-66EE2545B85E",
860
+ "activatedOn": "2026-01-22T03:26:56Z",
861
+ "expiresOn": "2026-01-23T03:26:56Z",
862
+ "activationUsage": 1,
863
+ "activationLimit": 4,
864
+ "enabled": true,
865
+ "customer": {
866
+ "customerId": "cfa95cf8c8d24e8b9d3d2d1ada98a94d",
867
+ "name": "Geo",
868
+ "email": "geo@kelviq.com"
869
+ },
870
+ "plan": {
871
+ "identifier": "pro-yearly",
872
+ "name": "Pro Yearly",
873
+ "product": {
874
+ "id": "d970ab2d-834f-4c52-8742-2e6ed7e8a31f",
875
+ "identifier": "kelviq-engine",
876
+ "name": "Kelviq Engine",
877
+ "taxCode": "software"
878
+ }
879
+ },
880
+ "subscription": {
881
+ "id": "09d706ca-58f3-4fb2-818f-5b8623d67e6e",
882
+ "recurrence": "1 month",
883
+ "billingPeriodStartTime": "2026-01-22T03:26:56Z",
884
+ "billingPeriodEndTime": "2026-02-22T03:26:56Z",
885
+ "startDate": "2026-01-22",
886
+ "endDate": null,
887
+ "status": "active",
888
+ "amount": "49.00",
889
+ "currency": "usd",
890
+ "trialDaysRemaining": 0,
891
+ "billingType": "SUBSCRIPTION",
892
+ "recurrenceUnit": 1,
893
+ "recurrenceType": "MONTH"
894
+ }
895
+ }
896
+ }
897
+ ```
898
+
899
+ **Required Parameters:**
900
+
901
+ * `licenseKey` : The license key string to validate.
902
+
903
+ **Optional Parameters:**
904
+
905
+ * `instanceId` : If provided, also validates that this specific instance is active for the given license key.
906
+
907
+ **Returns:**
908
+
909
+ An instance of `LicenseValidateResponse`, which includes:
910
+
911
+ * `valid` (boolean): Whether the license (and instance, if provided) is valid.
912
+ * `code` (string): A short status code (e.g. `"VALID"`, `"INVALID"`, `"EXPIRED"`).
913
+ * `detail` (string): A human-readable description of the validation result.
914
+ * `metadata` (object | null): Any metadata attached to the instance, if applicable.
915
+ * `license` (`LicenseDetails | null`): The full license object (same structure as in `activate`), or `null` if not found.
916
+
917
+ ---
918
+
919
+ ## Portal
920
+
921
+ The portal module allows you to create authenticated customer portal sessions. Once a session is created, you can redirect your customer directly to their self-serve customer portal without requiring them to log in manually. You can access these operations via the `portal` attribute on an initialized `Kelviq` client instance.
922
+
923
+ ### Creates a new customer portal session
924
+
925
+ ```typescript
926
+ const session = await client.portal.createSession({
927
+ customerId: "cust_789",
928
+ });
929
+
930
+ // Redirect your customer to the portal
931
+ res.redirect(session.customerPortalUrl);
932
+ ```
933
+
934
+ ```json
935
+ {
936
+ "token": "cpt-4f7c5dc4-da9f-447b-d447-6206d835ed6d:23fca530-ajeb-4685-b3d5-9918h6d38275",
937
+ "email": "geo@example.com",
938
+ "customerPortalUrl": "https://www.kelviq.com/portal/paritydeals/"
939
+ }
940
+ ```
941
+
942
+ **Required Parameters:**
943
+
944
+ * `customerId` : The unique identifier of the customer for whom the portal session is being created.
945
+
946
+ **Returns:**
947
+
948
+ An instance of `CreatePortalSessionResponse` (TypeScript Interface), which includes:
949
+
950
+ * `token` : The session token that authenticates the customer portal session.
951
+ * `email` : The email address of the customer.
952
+ * `customerPortalUrl` : The URL to redirect the customer to their customer portal. This link is pre-authenticated — no login required.
953
+
954
+ ---
955
+ ## Webhooks
956
+
957
+ Kelviq can send real-time webhook notifications to your server when events occur in your account — for example, when a subscription is created or an invoice is paid.
958
+
959
+ ### Verifying webhook signatures
960
+
961
+ Every webhook request includes three headers that you must use to verify the request is genuinely from Kelviq:
962
+
963
+ | Header | Description |
964
+ |---|---|
965
+ | `webhook-id` | Unique identifier for the event |
966
+ | `webhook-timestamp` | Unix timestamp of when the event was sent |
967
+ | `webhook-signature` | HMAC-SHA256 signature, prefixed with `v1,` |
968
+
969
+ Use the `validateEvent` helper to verify the signature and parse the event in one step. It throws `WebhookVerificationError` if the signature is invalid.
970
+
971
+ ```typescript
972
+ import { validateEvent, WebhookVerificationError } from '@kelviq/node-sdk';
973
+ import express from 'express';
974
+
975
+ const app = express();
976
+
977
+ app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
978
+ try {
979
+ const event = validateEvent(
980
+ req.body,
981
+ req.headers,
982
+ '<YOUR_WEBHOOK_SECRET>',
983
+ );
984
+
985
+ // Process the event
986
+ console.log('Event type:', event.type);
987
+
988
+ res.sendStatus(202);
989
+ } catch (err) {
990
+ if (err instanceof WebhookVerificationError) {
991
+ return res.sendStatus(403);
992
+ }
993
+ throw err;
994
+ }
995
+ });
996
+ ```
997
+
998
+ Use `express.raw()` (not `express.json()`) so that the raw request body is preserved for signature verification. Parsing the body as JSON before verification will break the signature check.
999
+
1000
+ ### Webhook event types
1001
+
1002
+ | Event | Description |
1003
+ |---|---|
1004
+ | `checkout.completed` | A checkout session was completed |
1005
+ | `customer.created` | A new customer was created |
1006
+ | `customer.updated` | A customer's details were updated |
1007
+ | `order.created` | A new order was placed |
1008
+ | `order.updated` | An order was updated |
1009
+ | `order.refunded` | An order was refunded |
1010
+ | `subscription.created` | A new subscription was created |
1011
+ | `subscription.updated` | A subscription was updated |
1012
+ | `subscription.cancelled` | A subscription was cancelled |
1013
+ | `subscription.plan_changed` | A subscription plan was changed |
1014
+ | `invoice.created` | A new invoice was created |
1015
+ | `invoice.paid` | An invoice was paid |
1016
+ | `refund.created` | A refund was initiated |
1017
+ | `refund.updated` | A refund status changed |
1018
+
1019
+ ### Best practices
1020
+
1021
+ * **Return quickly** — respond with a `2xx` status before doing any heavy processing. Kelviq retries up to 3 times at 60-second intervals if it does not receive a `2xx`.
1022
+ * **Use idempotency** — use the `webhook-id` header (or the event `id` field) to detect and skip duplicate deliveries.
1023
+ * **Validate every request** — always verify the signature before trusting the payload.
1024
+
1025
+ ---
1026
+ ## Using the Sandbox Environment
1027
+
1028
+ For testing and development, you can configure the client to use the sandbox environment. This ensures that no production data is affected. To do this, set the environment option to 'sandbox' during client initialization.
1029
+
1030
+ ```typescript
1031
+ import { Kelviq } from '@kelviq/node-sdk';
1032
+
1033
+ const client = new Kelviq({
1034
+ accessToken: 'YOUR_SANDBOX_ACCESS_TOKEN',
1035
+ environment: 'sandbox'
1036
+ });
1037
+
1038
+ ```
1039
+
1040
+ The sandbox environment is completely separate from production. You will need to use a different set of API keys, and any data created (customers, subscriptions, etc.) will only exist in the sandbox.