chargebee 3.26.0 → 3.28.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 (172) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/README.md +131 -0
  3. package/cjs/RequestWrapper.js +130 -12
  4. package/cjs/chargebee.cjs.js +5 -0
  5. package/cjs/chargebee.cjs.worker.js +2 -0
  6. package/cjs/chargebeeZodValidationError.js +18 -0
  7. package/cjs/createChargebee.js +23 -2
  8. package/cjs/environment.js +1 -1
  9. package/cjs/schema/addon.schema.js +269 -0
  10. package/cjs/schema/address.schema.js +35 -0
  11. package/cjs/schema/alert.schema.js +74 -0
  12. package/cjs/schema/alert_status.schema.js +31 -0
  13. package/cjs/schema/attached_item.schema.js +144 -0
  14. package/cjs/schema/business_entity.schema.js +46 -0
  15. package/cjs/schema/card.schema.js +165 -0
  16. package/cjs/schema/comment.schema.js +69 -0
  17. package/cjs/schema/coupon.schema.js +323 -0
  18. package/cjs/schema/coupon_code.schema.js +49 -0
  19. package/cjs/schema/coupon_set.schema.js +88 -0
  20. package/cjs/schema/credit_note.schema.js +502 -0
  21. package/cjs/schema/currency.schema.js +32 -0
  22. package/cjs/schema/customer.schema.js +1201 -0
  23. package/cjs/schema/customer_entitlement.schema.js +14 -0
  24. package/cjs/schema/differential_price.schema.js +106 -0
  25. package/cjs/schema/entitlement.schema.js +54 -0
  26. package/cjs/schema/entitlement_override.schema.js +35 -0
  27. package/cjs/schema/estimate.schema.js +1535 -0
  28. package/cjs/schema/event.schema.js +1060 -0
  29. package/cjs/schema/export.schema.js +3385 -0
  30. package/cjs/schema/feature.schema.js +78 -0
  31. package/cjs/schema/gift.schema.js +293 -0
  32. package/cjs/schema/grant_block.schema.js +47 -0
  33. package/cjs/schema/hosted_page.schema.js +1777 -0
  34. package/cjs/schema/in_app_subscription.schema.js +68 -0
  35. package/cjs/schema/index.js +88 -0
  36. package/cjs/schema/invoice.schema.js +1685 -0
  37. package/cjs/schema/item.schema.js +195 -0
  38. package/cjs/schema/item_entitlement.schema.js +45 -0
  39. package/cjs/schema/item_family.schema.js +57 -0
  40. package/cjs/schema/item_price.schema.js +335 -0
  41. package/cjs/schema/ledger_account_balance.schema.js +21 -0
  42. package/cjs/schema/ledger_operation.schema.js +104 -0
  43. package/cjs/schema/meter.schema.js +13 -0
  44. package/cjs/schema/metered_feature.schema.js +20 -0
  45. package/cjs/schema/non_subscription.schema.js +28 -0
  46. package/cjs/schema/offer_event.schema.js +13 -0
  47. package/cjs/schema/offer_fulfillment.schema.js +20 -0
  48. package/cjs/schema/omnichannel_one_time_order.schema.js +26 -0
  49. package/cjs/schema/omnichannel_subscription.schema.js +122 -0
  50. package/cjs/schema/omnichannel_subscription_item.schema.js +13 -0
  51. package/cjs/schema/order.schema.js +441 -0
  52. package/cjs/schema/payment_intent.schema.js +127 -0
  53. package/cjs/schema/payment_schedule_scheme.schema.js +20 -0
  54. package/cjs/schema/payment_source.schema.js +630 -0
  55. package/cjs/schema/payment_voucher.schema.js +57 -0
  56. package/cjs/schema/personalized_offer.schema.js +28 -0
  57. package/cjs/schema/plan.schema.js +363 -0
  58. package/cjs/schema/portal_session.schema.js +22 -0
  59. package/cjs/schema/price_variant.schema.js +93 -0
  60. package/cjs/schema/pricing_page_session.schema.js +135 -0
  61. package/cjs/schema/promotional_credit.schema.js +78 -0
  62. package/cjs/schema/promotional_grant.schema.js +17 -0
  63. package/cjs/schema/purchase.schema.js +277 -0
  64. package/cjs/schema/quote.schema.js +1667 -0
  65. package/cjs/schema/ramp.schema.js +245 -0
  66. package/cjs/schema/recorded_purchase.schema.js +32 -0
  67. package/cjs/schema/resource_migration.schema.js +14 -0
  68. package/cjs/schema/site_migration_detail.schema.js +81 -0
  69. package/cjs/schema/subscription.schema.js +3344 -0
  70. package/cjs/schema/subscription_entitlement.schema.js +25 -0
  71. package/cjs/schema/time_machine.schema.js +17 -0
  72. package/cjs/schema/transaction.schema.js +744 -0
  73. package/cjs/schema/unbilled_charge.schema.js +139 -0
  74. package/cjs/schema/usage.schema.js +93 -0
  75. package/cjs/schema/usage_charge.schema.js +17 -0
  76. package/cjs/schema/usage_event.schema.js +28 -0
  77. package/cjs/schema/usage_file.schema.js +13 -0
  78. package/cjs/schema/usage_summary.schema.js +17 -0
  79. package/cjs/schema/virtual_bank_account.schema.js +71 -0
  80. package/cjs/schema/webhook_endpoint.schema.js +508 -0
  81. package/cjs/telemetry/TelemetryAdapter.js +145 -0
  82. package/cjs/telemetry/index.js +28 -0
  83. package/cjs/telemetry/otel.js +66 -0
  84. package/cjs/telemetry/types.js +47 -0
  85. package/cjs/validationLoader.js +59 -0
  86. package/esm/RequestWrapper.js +130 -12
  87. package/esm/chargebee.esm.js +3 -0
  88. package/esm/chargebee.esm.worker.js +1 -0
  89. package/esm/chargebeeZodValidationError.js +14 -0
  90. package/esm/createChargebee.js +23 -2
  91. package/esm/environment.js +1 -1
  92. package/esm/schema/addon.schema.js +266 -0
  93. package/esm/schema/address.schema.js +32 -0
  94. package/esm/schema/alert.schema.js +71 -0
  95. package/esm/schema/alert_status.schema.js +28 -0
  96. package/esm/schema/attached_item.schema.js +141 -0
  97. package/esm/schema/business_entity.schema.js +43 -0
  98. package/esm/schema/card.schema.js +162 -0
  99. package/esm/schema/comment.schema.js +66 -0
  100. package/esm/schema/coupon.schema.js +320 -0
  101. package/esm/schema/coupon_code.schema.js +46 -0
  102. package/esm/schema/coupon_set.schema.js +85 -0
  103. package/esm/schema/credit_note.schema.js +499 -0
  104. package/esm/schema/currency.schema.js +29 -0
  105. package/esm/schema/customer.schema.js +1198 -0
  106. package/esm/schema/customer_entitlement.schema.js +11 -0
  107. package/esm/schema/differential_price.schema.js +103 -0
  108. package/esm/schema/entitlement.schema.js +51 -0
  109. package/esm/schema/entitlement_override.schema.js +32 -0
  110. package/esm/schema/estimate.schema.js +1532 -0
  111. package/esm/schema/event.schema.js +1057 -0
  112. package/esm/schema/export.schema.js +3382 -0
  113. package/esm/schema/feature.schema.js +75 -0
  114. package/esm/schema/gift.schema.js +290 -0
  115. package/esm/schema/grant_block.schema.js +44 -0
  116. package/esm/schema/hosted_page.schema.js +1774 -0
  117. package/esm/schema/in_app_subscription.schema.js +65 -0
  118. package/esm/schema/index.js +72 -0
  119. package/esm/schema/invoice.schema.js +1682 -0
  120. package/esm/schema/item.schema.js +192 -0
  121. package/esm/schema/item_entitlement.schema.js +42 -0
  122. package/esm/schema/item_family.schema.js +54 -0
  123. package/esm/schema/item_price.schema.js +332 -0
  124. package/esm/schema/ledger_account_balance.schema.js +18 -0
  125. package/esm/schema/ledger_operation.schema.js +101 -0
  126. package/esm/schema/meter.schema.js +10 -0
  127. package/esm/schema/metered_feature.schema.js +17 -0
  128. package/esm/schema/non_subscription.schema.js +25 -0
  129. package/esm/schema/offer_event.schema.js +10 -0
  130. package/esm/schema/offer_fulfillment.schema.js +17 -0
  131. package/esm/schema/omnichannel_one_time_order.schema.js +23 -0
  132. package/esm/schema/omnichannel_subscription.schema.js +119 -0
  133. package/esm/schema/omnichannel_subscription_item.schema.js +10 -0
  134. package/esm/schema/order.schema.js +438 -0
  135. package/esm/schema/payment_intent.schema.js +124 -0
  136. package/esm/schema/payment_schedule_scheme.schema.js +17 -0
  137. package/esm/schema/payment_source.schema.js +627 -0
  138. package/esm/schema/payment_voucher.schema.js +54 -0
  139. package/esm/schema/personalized_offer.schema.js +25 -0
  140. package/esm/schema/plan.schema.js +360 -0
  141. package/esm/schema/portal_session.schema.js +19 -0
  142. package/esm/schema/price_variant.schema.js +90 -0
  143. package/esm/schema/pricing_page_session.schema.js +132 -0
  144. package/esm/schema/promotional_credit.schema.js +75 -0
  145. package/esm/schema/promotional_grant.schema.js +14 -0
  146. package/esm/schema/purchase.schema.js +274 -0
  147. package/esm/schema/quote.schema.js +1664 -0
  148. package/esm/schema/ramp.schema.js +242 -0
  149. package/esm/schema/recorded_purchase.schema.js +29 -0
  150. package/esm/schema/resource_migration.schema.js +11 -0
  151. package/esm/schema/site_migration_detail.schema.js +78 -0
  152. package/esm/schema/subscription.schema.js +3341 -0
  153. package/esm/schema/subscription_entitlement.schema.js +22 -0
  154. package/esm/schema/time_machine.schema.js +14 -0
  155. package/esm/schema/transaction.schema.js +741 -0
  156. package/esm/schema/unbilled_charge.schema.js +136 -0
  157. package/esm/schema/usage.schema.js +90 -0
  158. package/esm/schema/usage_charge.schema.js +14 -0
  159. package/esm/schema/usage_event.schema.js +25 -0
  160. package/esm/schema/usage_file.schema.js +10 -0
  161. package/esm/schema/usage_summary.schema.js +14 -0
  162. package/esm/schema/virtual_bank_account.schema.js +68 -0
  163. package/esm/schema/webhook_endpoint.schema.js +505 -0
  164. package/esm/telemetry/TelemetryAdapter.js +132 -0
  165. package/esm/telemetry/index.js +8 -0
  166. package/esm/telemetry/otel.js +62 -0
  167. package/esm/telemetry/types.js +44 -0
  168. package/esm/validationLoader.js +56 -0
  169. package/package.json +43 -24
  170. package/types/core.d.ts +2 -0
  171. package/types/index.d.ts +85 -0
  172. package/types/telemetry/otel.d.ts +22 -0
@@ -0,0 +1,62 @@
1
+ /*
2
+ * This file is auto-generated by Chargebee.
3
+ * For more information on how to make changes to this file, please see the README.
4
+ * Reach out to dx@chargebee.com for any questions.
5
+ * Copyright 2026 Chargebee Inc.
6
+ */
7
+ import { context, propagation, SpanKind, SpanStatusCode, trace, } from '@opentelemetry/api';
8
+ import { CHARGEBEE_SDK_NAME, } from './types.js';
9
+ const tracer = trace.getTracer(CHARGEBEE_SDK_NAME);
10
+ function toRecordedException(error) {
11
+ var _a;
12
+ const exception = new Error(error.message);
13
+ exception.name = (_a = error.chargebeeErrorCode) !== null && _a !== void 0 ? _a : 'ChargebeeAPIError';
14
+ return exception;
15
+ }
16
+ /**
17
+ * Ready-to-use OpenTelemetry adapter for the Chargebee SDK.
18
+ *
19
+ * Each SDK request becomes a CLIENT span attached to the active OpenTelemetry
20
+ * context (or a root span when none is active), and the W3C trace context is
21
+ * propagated to Chargebee so the trace continues server-side.
22
+ *
23
+ * Exporting (endpoint, service name, credentials) is configured by your own
24
+ * OpenTelemetry runtime via the standard `OTEL_*` environment variables — this
25
+ * adapter only uses the globally registered tracer from `@opentelemetry/api`.
26
+ *
27
+ * `@opentelemetry/api` is an optional peer dependency; install it to use this
28
+ * adapter. A default-exported, ready-to-use instance is provided.
29
+ */
30
+ export class OtelTelemetryAdapter {
31
+ onRequestStart(ctx, requestHeaders) {
32
+ // startSpan adopts the active context's span as parent (or starts a root span if none).
33
+ const span = tracer.startSpan(ctx.spanName, {
34
+ kind: SpanKind.CLIENT,
35
+ attributes: ctx.startAttributes,
36
+ });
37
+ // Propagate W3C trace context to Chargebee so the trace continues server-side.
38
+ propagation.inject(trace.setSpan(context.active(), span), requestHeaders);
39
+ return span;
40
+ }
41
+ onRequestEnd(span, result) {
42
+ if (!span) {
43
+ return;
44
+ }
45
+ for (const [key, value] of Object.entries(result.endAttributes)) {
46
+ span.setAttribute(key, value);
47
+ }
48
+ if (result.error) {
49
+ span.recordException(toRecordedException(result.error));
50
+ span.setStatus({
51
+ code: SpanStatusCode.ERROR,
52
+ message: result.error.message,
53
+ });
54
+ }
55
+ else {
56
+ span.setStatus({ code: SpanStatusCode.OK });
57
+ }
58
+ span.end();
59
+ }
60
+ }
61
+ const otelDefaultAdapter = new OtelTelemetryAdapter();
62
+ export default otelDefaultAdapter;
@@ -0,0 +1,44 @@
1
+ /*
2
+ * This file is auto-generated by Chargebee.
3
+ * For more information on how to make changes to this file, please see the README.
4
+ * Reach out to dx@chargebee.com for any questions.
5
+ * Copyright 2026 Chargebee Inc.
6
+ */
7
+ /** SDK identifier recorded on telemetry spans. */
8
+ export const CHARGEBEE_SDK_NAME = 'chargebee-node';
9
+ /** Standard span name prefix: chargebee.{resource}.{operation} */
10
+ export const TELEMETRY_SPAN_NAME_PREFIX = 'chargebee';
11
+ /**
12
+ * OTel HTTP semantic-convention prefix for request-header attributes:
13
+ * `http.request.header.<lowercased-name>` with string[] values.
14
+ */
15
+ export const HTTP_REQUEST_HEADER_ATTRIBUTE_PREFIX = 'http.request.header.';
16
+ /**
17
+ * Request headers whose (lowercased) name starts with this prefix are captured as span
18
+ * attributes. Using a prefix instead of a fixed list means any future `chargebee-*` header
19
+ * is picked up automatically, with no SDK upgrade required.
20
+ */
21
+ export const CHARGEBEE_TELEMETRY_HEADER_PREFIX = 'chargebee-';
22
+ /**
23
+ * Headers under this sub-prefix carry end-user PII (origin IP, email, device) and are
24
+ * excluded from spans by default. Chargebee namespaces such headers under
25
+ * `chargebee-request-origin-*`, so future PII headers stay excluded automatically.
26
+ */
27
+ export const CHARGEBEE_TELEMETRY_HEADER_EXCLUDE_PREFIX = 'chargebee-request-origin-';
28
+ /** Span attribute keys — shared across Chargebee SDKs. */
29
+ export const TelemetryAttributeKeys = {
30
+ URL_FULL: 'url.full',
31
+ HTTP_REQUEST_METHOD: 'http.request.method',
32
+ HTTP_RESPONSE_STATUS_CODE: 'http.response.status_code',
33
+ SERVER_ADDRESS: 'server.address',
34
+ ERROR_TYPE: 'error.type',
35
+ CHARGEBEE_SITE: 'chargebee.site',
36
+ CHARGEBEE_API_VERSION: 'chargebee.api_version',
37
+ CHARGEBEE_RESOURCE: 'chargebee.resource',
38
+ CHARGEBEE_OPERATION: 'chargebee.operation',
39
+ CHARGEBEE_SDK_NAME: 'chargebee.sdk.name',
40
+ CHARGEBEE_SDK_VERSION: 'chargebee.sdk.version',
41
+ CHARGEBEE_ERROR_CODE: 'chargebee.error.code',
42
+ CHARGEBEE_ERROR_TYPE: 'chargebee.error.type',
43
+ CHARGEBEE_ERROR_PARAM: 'chargebee.error.param',
44
+ };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Lazy schema loader for opt-in Zod validation.
3
+ *
4
+ * Schemas are loaded on first use. Node.js automatically caches imported modules,
5
+ * so repeated imports of the same schema file are efficient.
6
+ *
7
+ * Each resource module lives at {@code schema/<resource_snake>.schema.ts}
8
+ * and exports one body schema per action.
9
+ *
10
+ * The body schema const name follows {@code ZodNamingStrategy.bodySchemaName} in sdk-generator:
11
+ * {@code {PascalAction}{PascalResource}BodySchema}
12
+ *
13
+ * Uses native dynamic import() - TypeScript transpiles appropriately for ESM/CJS targets.
14
+ */
15
+ function toCamel(s) {
16
+ return s.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
17
+ }
18
+ function toPascal(s) {
19
+ const camel = toCamel(s);
20
+ return camel.charAt(0).toUpperCase() + camel.slice(1);
21
+ }
22
+ /** Matches ZodNamingStrategy.bodySchemaName() in sdk-generator. */
23
+ function schemaConstName(resourceKey, actionName) {
24
+ return toPascal(actionName) + toPascal(resourceKey) + 'BodySchema';
25
+ }
26
+ /** camelCase resource key → snake_case module basename (e.g. virtualBankAccount → virtual_bank_account). */
27
+ function resourceSchemaBasename(resourceKey) {
28
+ return resourceKey
29
+ .replace(/([A-Z])/g, '_$1')
30
+ .toLowerCase()
31
+ .replace(/^_/, '');
32
+ }
33
+ /**
34
+ * Load the Zod schema for a given resource + action.
35
+ * Returns null if no schema file exists for this combination.
36
+ *
37
+ * Node.js automatically caches the imported modules, so repeated calls
38
+ * for the same resource will reuse the cached module.
39
+ *
40
+ * TypeScript compiler handles module system differences:
41
+ * - ESM build: keeps await import() as-is
42
+ * - CJS build: transpiles to require() or Promise-based equivalent
43
+ */
44
+ export async function getSchema(resourceKey, actionName) {
45
+ var _a;
46
+ const base = resourceSchemaBasename(resourceKey);
47
+ const constName = schemaConstName(resourceKey, actionName);
48
+ try {
49
+ const mod = await import(`./schema/${base}.schema.js`);
50
+ const schema = (_a = mod[constName]) !== null && _a !== void 0 ? _a : null;
51
+ return schema;
52
+ }
53
+ catch (_b) {
54
+ return null;
55
+ }
56
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chargebee",
3
- "version": "3.26.0",
3
+ "version": "3.28.0",
4
4
  "description": "A library for integrating with Chargebee.",
5
5
  "scripts": {
6
6
  "prepack": "npm install && npm run build",
@@ -34,33 +34,49 @@
34
34
  }
35
35
  ],
36
36
  "exports": {
37
- "types": "./types/index.d.ts",
38
- "browser": {
39
- "import": "./esm/chargebee.esm.worker.js",
40
- "require": "./cjs/chargebee.cjs.worker.js"
37
+ ".": {
38
+ "types": "./types/index.d.ts",
39
+ "browser": {
40
+ "import": "./esm/chargebee.esm.worker.js",
41
+ "require": "./cjs/chargebee.cjs.worker.js"
42
+ },
43
+ "worker": {
44
+ "import": "./esm/chargebee.esm.worker.js",
45
+ "require": "./cjs/chargebee.cjs.worker.js"
46
+ },
47
+ "workerd": {
48
+ "import": "./esm/chargebee.esm.worker.js",
49
+ "require": "./cjs/chargebee.cjs.worker.js"
50
+ },
51
+ "deno": {
52
+ "import": "./esm/chargebee.esm.worker.js",
53
+ "require": "./cjs/chargebee.cjs.worker.js"
54
+ },
55
+ "bun": {
56
+ "import": "./esm/chargebee.esm.worker.js",
57
+ "require": "./cjs/chargebee.cjs.worker.js"
58
+ },
59
+ "default": {
60
+ "import": "./esm/chargebee.esm.js",
61
+ "require": "./cjs/chargebee.cjs.js"
62
+ }
41
63
  },
42
- "worker": {
43
- "import": "./esm/chargebee.esm.worker.js",
44
- "require": "./cjs/chargebee.cjs.worker.js"
45
- },
46
- "workerd": {
47
- "import": "./esm/chargebee.esm.worker.js",
48
- "require": "./cjs/chargebee.cjs.worker.js"
49
- },
50
- "deno": {
51
- "import": "./esm/chargebee.esm.worker.js",
52
- "require": "./cjs/chargebee.cjs.worker.js"
53
- },
54
- "bun": {
55
- "import": "./esm/chargebee.esm.worker.js",
56
- "require": "./cjs/chargebee.cjs.worker.js"
57
- },
58
- "default": {
59
- "import": "./esm/chargebee.esm.js",
60
- "require": "./cjs/chargebee.cjs.js"
64
+ "./telemetry/otel": {
65
+ "types": "./types/telemetry/otel.d.ts",
66
+ "import": "./esm/telemetry/otel.js",
67
+ "require": "./cjs/telemetry/otel.js"
68
+ }
69
+ },
70
+ "peerDependencies": {
71
+ "@opentelemetry/api": "^1.9.0"
72
+ },
73
+ "peerDependenciesMeta": {
74
+ "@opentelemetry/api": {
75
+ "optional": true
61
76
  }
62
77
  },
63
78
  "devDependencies": {
79
+ "@opentelemetry/api": "^1.9.0",
64
80
  "@types/chai": "^4.3.5",
65
81
  "@types/mocha": "^10.0.10",
66
82
  "@types/node": "20.12.0",
@@ -75,5 +91,8 @@
75
91
  "semi": true,
76
92
  "singleQuote": true,
77
93
  "parser": "typescript"
94
+ },
95
+ "dependencies": {
96
+ "zod": "^4.3.6"
78
97
  }
79
98
  }
package/types/core.d.ts CHANGED
@@ -5,6 +5,8 @@ declare module 'chargebee' {
5
5
  timeout?: number;
6
6
  timemachineWaitInMillis?: number;
7
7
  exportWaitInMillis?: number;
8
+ /** When true, request parameters are validated against Zod schemas before each HTTP call (where a schema exists). */
9
+ enableValidation?: boolean;
8
10
  }
9
11
  export type ChargebeeResponse<T> = T & {
10
12
  headers: { [key: string]: string };
package/types/index.d.ts CHANGED
@@ -168,12 +168,86 @@ declare module 'chargebee' {
168
168
  * @httpClient optional http client implementation, default http client will be used if not provided
169
169
  */
170
170
  httpClient?: HttpClientInterface;
171
+
172
+ /**
173
+ * @telemetryAdapter optional telemetry adapter for observability (e.g. OpenTelemetry)
174
+ */
175
+ telemetryAdapter?: TelemetryAdapter;
176
+
177
+ /**
178
+ * @enableValidation When true, every request's parameters are validated against each endpoint's generated Zod schema before the HTTP request is sent. Violations throw `ChargebeeZodValidationError` with structured Zod issues. Calls with no params argument are validated as `{}`. Required resource ids in the URL path are still checked separately.
179
+ */
180
+ enableValidation?: boolean;
171
181
  };
172
182
 
173
183
  export interface HttpClientInterface {
174
184
  makeApiRequest: (request: Request, timeout: number) => Promise<Response>;
175
185
  }
176
186
 
187
+ export type RequestTelemetryHandle = unknown;
188
+
189
+ export const TelemetryAttributeKeys: {
190
+ readonly URL_FULL: 'url.full';
191
+ readonly HTTP_REQUEST_METHOD: 'http.request.method';
192
+ readonly HTTP_RESPONSE_STATUS_CODE: 'http.response.status_code';
193
+ readonly SERVER_ADDRESS: 'server.address';
194
+ readonly ERROR_TYPE: 'error.type';
195
+ readonly CHARGEBEE_SITE: 'chargebee.site';
196
+ readonly CHARGEBEE_API_VERSION: 'chargebee.api_version';
197
+ readonly CHARGEBEE_RESOURCE: 'chargebee.resource';
198
+ readonly CHARGEBEE_OPERATION: 'chargebee.operation';
199
+ readonly CHARGEBEE_SDK_NAME: 'chargebee.sdk.name';
200
+ readonly CHARGEBEE_SDK_VERSION: 'chargebee.sdk.version';
201
+ readonly CHARGEBEE_ERROR_CODE: 'chargebee.error.code';
202
+ readonly CHARGEBEE_ERROR_TYPE: 'chargebee.error.type';
203
+ readonly CHARGEBEE_ERROR_PARAM: 'chargebee.error.param';
204
+ };
205
+
206
+ export type RequestTelemetryContext = {
207
+ spanName: string;
208
+ resource: string;
209
+ operation: string;
210
+ httpMethod: string;
211
+ httpUrl: string;
212
+ serverAddress: string;
213
+ chargebeeSite: string;
214
+ chargebeeApiVersion: 'v1' | 'v2';
215
+ sdkName: string;
216
+ sdkVersion: string;
217
+ /**
218
+ * Prebuilt span attributes — pass these to your tracer. Captured `chargebee-*` request
219
+ * headers appear as `http.request.header.<name>` with string[] values per OTel semconv.
220
+ */
221
+ startAttributes: Record<string, string | string[]>;
222
+ };
223
+
224
+ export type RequestTelemetryError = {
225
+ message: string;
226
+ chargebeeErrorCode?: string;
227
+ chargebeeApiErrorType?: string;
228
+ chargebeeErrorParam?: string;
229
+ };
230
+
231
+ export type RequestTelemetryResult = {
232
+ httpStatusCode: number;
233
+ durationMs: number;
234
+ error?: RequestTelemetryError;
235
+ /** Prebuilt span attributes — pass these to your tracer. */
236
+ endAttributes: Record<string, string | number>;
237
+ };
238
+
239
+ /**
240
+ * Optional telemetry adapter. Implement as a class or plain object — the SDK
241
+ * keeps it by reference (never deep-cloned). Wire OpenTelemetry or other tools here.
242
+ */
243
+ export interface TelemetryAdapter<THandle = RequestTelemetryHandle> {
244
+ onRequestStart(
245
+ context: RequestTelemetryContext,
246
+ requestHeaders: Record<string, string | number>,
247
+ ): THandle | void;
248
+ onRequestEnd(handle: THandle | void, result: RequestTelemetryResult): void;
249
+ }
250
+
177
251
  export type RetryConfig = {
178
252
  /**
179
253
  * @enabled whether to enable retry logic, default value is false
@@ -451,4 +525,15 @@ declare module 'chargebee' {
451
525
  name: string;
452
526
  readonly rawBody?: string;
453
527
  }
528
+
529
+ /**
530
+ * Thrown when `enableValidation` is on and request parameters fail the action's Zod schema.
531
+ * Carries `actionName` and the original `ZodError` (issues, `flatten()`, etc.) for programmatic handling.
532
+ */
533
+ export class ChargebeeZodValidationError extends Error {
534
+ constructor(actionName: string, zodError: import('zod').ZodError);
535
+ name: string;
536
+ readonly actionName: string;
537
+ readonly zodError: import('zod').ZodError;
538
+ }
454
539
  }
@@ -0,0 +1,22 @@
1
+ declare module 'chargebee/telemetry/otel' {
2
+ import type {
3
+ RequestTelemetryContext,
4
+ RequestTelemetryResult,
5
+ TelemetryAdapter,
6
+ } from 'chargebee';
7
+ /**
8
+ * Ready-to-use OpenTelemetry adapter for the Chargebee SDK. Exporting is
9
+ * configured by your own OpenTelemetry runtime via the standard `OTEL_*`
10
+ * environment variables; this adapter only uses the globally registered
11
+ * tracer from `@opentelemetry/api` (an optional peer dependency).
12
+ */
13
+ export class OtelTelemetryAdapter implements TelemetryAdapter {
14
+ onRequestStart(
15
+ ctx: RequestTelemetryContext,
16
+ requestHeaders: Record<string, string | number>,
17
+ ): unknown;
18
+ onRequestEnd(handle: unknown, result: RequestTelemetryResult): void;
19
+ }
20
+ const otelDefaultAdapter: OtelTelemetryAdapter;
21
+ export default otelDefaultAdapter;
22
+ }