lago-javascript-client 1.47.0 → 1.47.1

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.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * This file was auto-generated by openapi-typescript.
3
+ * Do not make direct changes to the file.
4
+ */
5
+ export {};
@@ -0,0 +1,68 @@
1
+ import type { webhooks } from "./openapi/webhooks.js";
2
+ /** Extract the `application/json` body of a webhook's POST request. */
3
+ type _PayloadOf<K extends keyof webhooks> = webhooks[K] extends {
4
+ post: {
5
+ requestBody?: {
6
+ content: {
7
+ "application/json": infer P;
8
+ };
9
+ };
10
+ };
11
+ } ? P : never;
12
+ /** Extract the `webhook_type` literal (e.g. `"alert.triggered"`) from a payload. */
13
+ type _WebhookTypeOf<K extends keyof webhooks> = _PayloadOf<K> extends {
14
+ webhook_type: infer T;
15
+ } ? T extends string ? T : never : never;
16
+ /**
17
+ * Map of webhook event name to its typed payload.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import type { LagoWebhookPayloads } from "lago-javascript-client";
22
+ *
23
+ * app.post("/webhooks", (req, res) => {
24
+ * const event = req.body as LagoWebhookPayloads["alert.triggered"];
25
+ * console.log(event.triggered_alert.external_customer_id);
26
+ * });
27
+ * ```
28
+ */
29
+ export type LagoWebhookPayloads = {
30
+ [K in keyof webhooks as _WebhookTypeOf<K>]: _PayloadOf<K>;
31
+ };
32
+ /**
33
+ * Discriminated union of every webhook payload. Narrow with the `webhook_type`
34
+ * field in a `switch` to get a fully typed branch.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import type { LagoWebhookPayload } from "lago-javascript-client";
39
+ *
40
+ * function handle(event: LagoWebhookPayload) {
41
+ * switch (event.webhook_type) {
42
+ * case "alert.triggered":
43
+ * // event is narrowed; event.triggered_alert is fully typed
44
+ * break;
45
+ * case "invoice.created":
46
+ * // event.invoice is fully typed
47
+ * break;
48
+ * }
49
+ * }
50
+ * ```
51
+ */
52
+ export type LagoWebhookPayload = LagoWebhookPayloads[keyof LagoWebhookPayloads];
53
+ /**
54
+ * Union of every `webhook_type` string emitted by Lago, e.g.
55
+ * `"alert.triggered" | "invoice.created" | ...`.
56
+ */
57
+ export type LagoWebhookType = keyof LagoWebhookPayloads;
58
+ /**
59
+ * Helper to look up a single payload type by its `webhook_type` string.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * import type { WebhookOf } from "lago-javascript-client";
64
+ * type InvoiceCreated = WebhookOf<"invoice.created">;
65
+ * ```
66
+ */
67
+ export type WebhookOf<T extends LagoWebhookType> = LagoWebhookPayloads[T];
68
+ export {};
@@ -0,0 +1,23 @@
1
+ // User-facing TypeScript types for Lago webhook payloads.
2
+ //
3
+ // Backed by ./openapi/webhooks.ts, which is auto-generated from the Lago
4
+ // OpenAPI 3.1 spec (`webhooks:` key) via `deno task generate:webhooks`.
5
+ // This file is hand-written and is safe across regenerations.
6
+ //
7
+ // The generator output keys events by their snake_case operationId
8
+ // (e.g. `alert_triggered`). We re-key here by the dotted `webhook_type`
9
+ // literal (e.g. `alert.triggered`) so that the public API matches the
10
+ // string customers actually see on the wire.
11
+ //
12
+ // Note on nested types: the payload types here are produced by
13
+ // `openapi-typescript`, while the SDK's component exports (e.g.
14
+ // `CustomerObject`, `InvoiceObjectExtended`) are produced by
15
+ // `swagger-typescript-api`. The two generators interpret the same schema
16
+ // slightly differently for nullable fields, so a value typed as
17
+ // `LagoWebhookPayloads['customer.created']['customer']` is not always
18
+ // structurally equal to `CustomerObject` from the main SDK exports. Both
19
+ // are valid views of the same wire shape; the openapi-typescript view is
20
+ // the more accurate one for what actually arrives over the network. If
21
+ // you pass webhook objects into helpers typed with SDK components, a
22
+ // narrowing cast may be required.
23
+ export {};
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "main": "./script/mod.js",
4
4
  "name": "lago-javascript-client",
5
5
  "sideEffects": false,
6
- "version": "v1.47.0",
6
+ "version": "v1.47.1",
7
7
  "description": "Lago JavaScript API Client",
8
8
  "repository": {
9
9
  "type": "git",
package/script/mod.d.ts CHANGED
@@ -14,3 +14,4 @@ export { parseRateLimitHeaders, parseRateLimitInfo, type RateLimitHeaders, type
14
14
  export { createRateLimitFetch, type RateLimitFetchConfig, type RateLimitInfoCallback, } from "./rate_limit_fetch.js";
15
15
  export { DEFAULT_RATE_LIMIT_THRESHOLDS, loggingRateLimitObserver, type LoggingRateLimitObserverOptions, } from "./logging_rate_limit_observer.js";
16
16
  export * from "./openapi/client.js";
17
+ export type { LagoWebhookPayload, LagoWebhookPayloads, LagoWebhookType, WebhookOf, } from "./webhook_types.js";