@monigo/sdk 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -23,7 +23,9 @@ export declare interface CreateCustomerRequest {
23
23
  /** Your internal ID for this customer. */
24
24
  external_id: string;
25
25
  name: string;
26
- email: string;
26
+ email?: string;
27
+ /** Phone number in E.164 international format (e.g. +2348012345678). Optional. */
28
+ phone?: string;
27
29
  metadata?: Record<string, unknown>;
28
30
  }
29
31
 
@@ -93,6 +95,8 @@ export declare interface Customer {
93
95
  external_id: string;
94
96
  name: string;
95
97
  email: string;
98
+ /** Phone number in E.164 international format (e.g. +2348012345678). */
99
+ phone: string;
96
100
  /** Arbitrary JSON metadata. */
97
101
  metadata: Record<string, unknown> | null;
98
102
  created_at: string;
@@ -118,7 +122,7 @@ export declare class CustomersResource {
118
122
  * })
119
123
  * ```
120
124
  */
121
- create(request: CreateCustomerRequest): Promise<Customer>;
125
+ create(request: CreateCustomerRequest, options?: MutationOptions): Promise<Customer>;
122
126
  /**
123
127
  * Return all customers in the authenticated organisation.
124
128
  *
@@ -144,7 +148,7 @@ export declare class CustomersResource {
144
148
  * })
145
149
  * ```
146
150
  */
147
- update(customerId: string, request: UpdateCustomerRequest): Promise<Customer>;
151
+ update(customerId: string, request: UpdateCustomerRequest, options?: MutationOptions): Promise<Customer>;
148
152
  /**
149
153
  * Permanently delete a customer record.
150
154
  *
@@ -200,7 +204,7 @@ export declare class EventsResource {
200
204
  * console.log('Duplicates:', result.duplicates.length)
201
205
  * ```
202
206
  */
203
- ingest(request: IngestRequest): Promise<IngestResponse>;
207
+ ingest(request: IngestRequest, options?: MutationOptions): Promise<IngestResponse>;
204
208
  /**
205
209
  * Start an asynchronous replay of all raw events in a given time window
206
210
  * through the current processing pipeline. Useful for backfilling usage
@@ -220,7 +224,7 @@ export declare class EventsResource {
220
224
  * console.log('Replay job:', job.id, job.status)
221
225
  * ```
222
226
  */
223
- startReplay(request: StartReplayRequest): Promise<EventReplayJob>;
227
+ startReplay(request: StartReplayRequest, options?: MutationOptions): Promise<EventReplayJob>;
224
228
  /**
225
229
  * Fetch the current status and progress of an event replay job.
226
230
  *
@@ -334,7 +338,7 @@ export declare class InvoicesResource {
334
338
  * console.log('Draft invoice total:', invoice.total)
335
339
  * ```
336
340
  */
337
- generate(subscriptionId: string): Promise<Invoice>;
341
+ generate(subscriptionId: string, options?: MutationOptions): Promise<Invoice>;
338
342
  /**
339
343
  * Return invoices, optionally filtered by status or customer.
340
344
  *
@@ -361,14 +365,14 @@ export declare class InvoicesResource {
361
365
  *
362
366
  * **Requires `write` scope.**
363
367
  */
364
- finalize(invoiceId: string): Promise<Invoice>;
368
+ finalize(invoiceId: string, options?: MutationOptions): Promise<Invoice>;
365
369
  /**
366
370
  * Void an invoice, making it permanently non-payable.
367
371
  * Only admins and owners can void invoices.
368
372
  *
369
373
  * **Requires `write` scope.**
370
374
  */
371
- void(invoiceId: string): Promise<Invoice>;
375
+ void(invoiceId: string, options?: MutationOptions): Promise<Invoice>;
372
376
  }
373
377
 
374
378
  export declare const InvoiceStatus: {
@@ -460,7 +464,7 @@ export declare class MetricsResource {
460
464
  * })
461
465
  * ```
462
466
  */
463
- create(request: CreateMetricRequest): Promise<Metric>;
467
+ create(request: CreateMetricRequest, options?: MutationOptions): Promise<Metric>;
464
468
  /**
465
469
  * Return all metrics in the authenticated organisation.
466
470
  *
@@ -478,7 +482,7 @@ export declare class MetricsResource {
478
482
  *
479
483
  * **Requires `write` scope.**
480
484
  */
481
- update(metricId: string, request: UpdateMetricRequest): Promise<Metric>;
485
+ update(metricId: string, request: UpdateMetricRequest, options?: MutationOptions): Promise<Metric>;
482
486
  /**
483
487
  * Permanently delete a metric.
484
488
  *
@@ -599,6 +603,18 @@ export declare interface MonigoClientOptions {
599
603
  timeout?: number;
600
604
  }
601
605
 
606
+ /**
607
+ * Options accepted by every mutating method (POST, PUT, PATCH).
608
+ */
609
+ export declare interface MutationOptions {
610
+ /**
611
+ * A unique key that prevents the same request from being processed more than
612
+ * once. Pass a stable value (e.g. a request ID from your own system) to make
613
+ * retries safe. When omitted, the SDK generates a UUID v4 automatically.
614
+ */
615
+ idempotencyKey?: string;
616
+ }
617
+
602
618
  /** A bank or mobile-money account that a customer can be paid to. */
603
619
  export declare interface PayoutAccount {
604
620
  id: string;
@@ -640,7 +656,7 @@ export declare class PayoutAccountsResource {
640
656
  * })
641
657
  * ```
642
658
  */
643
- create(customerId: string, request: CreatePayoutAccountRequest): Promise<PayoutAccount>;
659
+ create(customerId: string, request: CreatePayoutAccountRequest, options?: MutationOptions): Promise<PayoutAccount>;
644
660
  /**
645
661
  * Return all payout accounts for a customer.
646
662
  *
@@ -658,7 +674,7 @@ export declare class PayoutAccountsResource {
658
674
  *
659
675
  * **Requires `write` scope.**
660
676
  */
661
- update(customerId: string, accountId: string, request: UpdatePayoutAccountRequest): Promise<PayoutAccount>;
677
+ update(customerId: string, accountId: string, request: UpdatePayoutAccountRequest, options?: MutationOptions): Promise<PayoutAccount>;
662
678
  /**
663
679
  * Delete a payout account.
664
680
  *
@@ -715,7 +731,7 @@ export declare class PlansResource {
715
731
  * })
716
732
  * ```
717
733
  */
718
- create(request: CreatePlanRequest): Promise<Plan>;
734
+ create(request: CreatePlanRequest, options?: MutationOptions): Promise<Plan>;
719
735
  /**
720
736
  * Return all billing plans in the authenticated organisation.
721
737
  *
@@ -733,7 +749,7 @@ export declare class PlansResource {
733
749
  *
734
750
  * **Requires `write` scope.**
735
751
  */
736
- update(planId: string, request: UpdatePlanRequest): Promise<Plan>;
752
+ update(planId: string, request: UpdatePlanRequest, options?: MutationOptions): Promise<Plan>;
737
753
  /**
738
754
  * Permanently delete a plan.
739
755
  *
@@ -829,7 +845,7 @@ export declare class SubscriptionsResource {
829
845
  * })
830
846
  * ```
831
847
  */
832
- create(request: CreateSubscriptionRequest): Promise<Subscription>;
848
+ create(request: CreateSubscriptionRequest, options?: MutationOptions): Promise<Subscription>;
833
849
  /**
834
850
  * Return subscriptions, optionally filtered by customer, plan, or status.
835
851
  *
@@ -861,7 +877,7 @@ export declare class SubscriptionsResource {
861
877
  * await monigo.subscriptions.updateStatus(subId, SubscriptionStatus.Paused)
862
878
  * ```
863
879
  */
864
- updateStatus(subscriptionId: string, status: SubscriptionStatusValue): Promise<Subscription>;
880
+ updateStatus(subscriptionId: string, status: SubscriptionStatusValue, options?: MutationOptions): Promise<Subscription>;
865
881
  /**
866
882
  * Cancel and delete a subscription record.
867
883
  *
@@ -881,6 +897,8 @@ export declare type SubscriptionStatusValue = (typeof SubscriptionStatus)[keyof
881
897
  export declare interface UpdateCustomerRequest {
882
898
  name?: string;
883
899
  email?: string;
900
+ /** Phone number in E.164 international format (e.g. +2348012345678). Optional. */
901
+ phone?: string;
884
902
  metadata?: Record<string, unknown>;
885
903
  }
886
904
 
package/dist/monigo.cjs CHANGED
@@ -86,14 +86,17 @@ class EventsResource {
86
86
  * console.log('Duplicates:', result.duplicates.length)
87
87
  * ```
88
88
  */
89
- async ingest(request) {
89
+ async ingest(request, options) {
90
90
  const body = {
91
91
  events: request.events.map((e) => ({
92
92
  ...e,
93
93
  timestamp: e.timestamp ? MonigoClient.toISOString(e.timestamp) : (/* @__PURE__ */ new Date()).toISOString()
94
94
  }))
95
95
  };
96
- return this.client._request("POST", "/v1/ingest", { body });
96
+ return this.client._request("POST", "/v1/ingest", {
97
+ body,
98
+ idempotencyKey: options?.idempotencyKey
99
+ });
97
100
  }
98
101
  /**
99
102
  * Start an asynchronous replay of all raw events in a given time window
@@ -114,7 +117,7 @@ class EventsResource {
114
117
  * console.log('Replay job:', job.id, job.status)
115
118
  * ```
116
119
  */
117
- async startReplay(request) {
120
+ async startReplay(request, options) {
118
121
  const body = {
119
122
  from: MonigoClient.toISOString(request.from),
120
123
  to: MonigoClient.toISOString(request.to),
@@ -123,7 +126,7 @@ class EventsResource {
123
126
  const wrapper = await this.client._request(
124
127
  "POST",
125
128
  "/v1/events/replay",
126
- { body }
129
+ { body, idempotencyKey: options?.idempotencyKey }
127
130
  );
128
131
  return wrapper.job;
129
132
  }
@@ -167,11 +170,11 @@ class CustomersResource {
167
170
  * })
168
171
  * ```
169
172
  */
170
- async create(request) {
173
+ async create(request, options) {
171
174
  const wrapper = await this.client._request(
172
175
  "POST",
173
176
  "/v1/customers",
174
- { body: request }
177
+ { body: request, idempotencyKey: options?.idempotencyKey }
175
178
  );
176
179
  return wrapper.customer;
177
180
  }
@@ -208,11 +211,11 @@ class CustomersResource {
208
211
  * })
209
212
  * ```
210
213
  */
211
- async update(customerId, request) {
214
+ async update(customerId, request, options) {
212
215
  const wrapper = await this.client._request(
213
216
  "PUT",
214
217
  `/v1/customers/${customerId}`,
215
- { body: request }
218
+ { body: request, idempotencyKey: options?.idempotencyKey }
216
219
  );
217
220
  return wrapper.customer;
218
221
  }
@@ -243,11 +246,11 @@ class MetricsResource {
243
246
  * })
244
247
  * ```
245
248
  */
246
- async create(request) {
249
+ async create(request, options) {
247
250
  const wrapper = await this.client._request(
248
251
  "POST",
249
252
  "/v1/metrics",
250
- { body: request }
253
+ { body: request, idempotencyKey: options?.idempotencyKey }
251
254
  );
252
255
  return wrapper.metric;
253
256
  }
@@ -276,11 +279,11 @@ class MetricsResource {
276
279
  *
277
280
  * **Requires `write` scope.**
278
281
  */
279
- async update(metricId, request) {
282
+ async update(metricId, request, options) {
280
283
  const wrapper = await this.client._request(
281
284
  "PUT",
282
285
  `/v1/metrics/${metricId}`,
283
- { body: request }
286
+ { body: request, idempotencyKey: options?.idempotencyKey }
284
287
  );
285
288
  return wrapper.metric;
286
289
  }
@@ -316,11 +319,11 @@ class PlansResource {
316
319
  * })
317
320
  * ```
318
321
  */
319
- async create(request) {
322
+ async create(request, options) {
320
323
  const wrapper = await this.client._request(
321
324
  "POST",
322
325
  "/v1/plans",
323
- { body: request }
326
+ { body: request, idempotencyKey: options?.idempotencyKey }
324
327
  );
325
328
  return wrapper.plan;
326
329
  }
@@ -349,11 +352,11 @@ class PlansResource {
349
352
  *
350
353
  * **Requires `write` scope.**
351
354
  */
352
- async update(planId, request) {
355
+ async update(planId, request, options) {
353
356
  const wrapper = await this.client._request(
354
357
  "PUT",
355
358
  `/v1/plans/${planId}`,
356
- { body: request }
359
+ { body: request, idempotencyKey: options?.idempotencyKey }
357
360
  );
358
361
  return wrapper.plan;
359
362
  }
@@ -386,11 +389,11 @@ class SubscriptionsResource {
386
389
  * })
387
390
  * ```
388
391
  */
389
- async create(request) {
392
+ async create(request, options) {
390
393
  const wrapper = await this.client._request(
391
394
  "POST",
392
395
  "/v1/subscriptions",
393
- { body: request }
396
+ { body: request, idempotencyKey: options?.idempotencyKey }
394
397
  );
395
398
  return wrapper.subscription;
396
399
  }
@@ -439,11 +442,11 @@ class SubscriptionsResource {
439
442
  * await monigo.subscriptions.updateStatus(subId, SubscriptionStatus.Paused)
440
443
  * ```
441
444
  */
442
- async updateStatus(subscriptionId, status) {
445
+ async updateStatus(subscriptionId, status, options) {
443
446
  const wrapper = await this.client._request(
444
447
  "PATCH",
445
448
  `/v1/subscriptions/${subscriptionId}`,
446
- { body: { status } }
449
+ { body: { status }, idempotencyKey: options?.idempotencyKey }
447
450
  );
448
451
  return wrapper.subscription;
449
452
  }
@@ -478,11 +481,11 @@ class PayoutAccountsResource {
478
481
  * })
479
482
  * ```
480
483
  */
481
- async create(customerId, request) {
484
+ async create(customerId, request, options) {
482
485
  const wrapper = await this.client._request(
483
486
  "POST",
484
487
  `/v1/customers/${customerId}/payout-accounts`,
485
- { body: request }
488
+ { body: request, idempotencyKey: options?.idempotencyKey }
486
489
  );
487
490
  return wrapper.payout_account;
488
491
  }
@@ -514,11 +517,11 @@ class PayoutAccountsResource {
514
517
  *
515
518
  * **Requires `write` scope.**
516
519
  */
517
- async update(customerId, accountId, request) {
520
+ async update(customerId, accountId, request, options) {
518
521
  const wrapper = await this.client._request(
519
522
  "PUT",
520
523
  `/v1/customers/${customerId}/payout-accounts/${accountId}`,
521
- { body: request }
524
+ { body: request, idempotencyKey: options?.idempotencyKey }
522
525
  );
523
526
  return wrapper.payout_account;
524
527
  }
@@ -550,11 +553,11 @@ class InvoicesResource {
550
553
  * console.log('Draft invoice total:', invoice.total)
551
554
  * ```
552
555
  */
553
- async generate(subscriptionId) {
556
+ async generate(subscriptionId, options) {
554
557
  const wrapper = await this.client._request(
555
558
  "POST",
556
559
  "/v1/invoices/generate",
557
- { body: { subscription_id: subscriptionId } }
560
+ { body: { subscription_id: subscriptionId }, idempotencyKey: options?.idempotencyKey }
558
561
  );
559
562
  return wrapper.invoice;
560
563
  }
@@ -597,10 +600,11 @@ class InvoicesResource {
597
600
  *
598
601
  * **Requires `write` scope.**
599
602
  */
600
- async finalize(invoiceId) {
603
+ async finalize(invoiceId, options) {
601
604
  const wrapper = await this.client._request(
602
605
  "POST",
603
- `/v1/invoices/${invoiceId}/finalize`
606
+ `/v1/invoices/${invoiceId}/finalize`,
607
+ { idempotencyKey: options?.idempotencyKey }
604
608
  );
605
609
  return wrapper.invoice;
606
610
  }
@@ -610,10 +614,11 @@ class InvoicesResource {
610
614
  *
611
615
  * **Requires `write` scope.**
612
616
  */
613
- async void(invoiceId) {
617
+ async void(invoiceId, options) {
614
618
  const wrapper = await this.client._request(
615
619
  "POST",
616
- `/v1/invoices/${invoiceId}/void`
620
+ `/v1/invoices/${invoiceId}/void`,
621
+ { idempotencyKey: options?.idempotencyKey }
617
622
  );
618
623
  return wrapper.invoice;
619
624
  }
@@ -702,13 +707,16 @@ class MonigoClient {
702
707
  }
703
708
  const controller = new AbortController();
704
709
  const timeoutId = setTimeout(() => controller.abort(), this._timeout);
710
+ const isMutating = method === "POST" || method === "PUT" || method === "PATCH";
711
+ const idempotencyKey = isMutating ? options.idempotencyKey ?? globalThis.crypto.randomUUID() : void 0;
705
712
  try {
706
713
  const response = await this._fetchFn(url, {
707
714
  method,
708
715
  headers: {
709
716
  Authorization: `Bearer ${this._apiKey}`,
710
717
  "Content-Type": "application/json",
711
- Accept: "application/json"
718
+ Accept: "application/json",
719
+ ...idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {}
712
720
  },
713
721
  body: options.body != null ? JSON.stringify(options.body) : void 0,
714
722
  signal: controller.signal
@@ -1 +1 @@
1
- {"version":3,"file":"monigo.cjs","sources":["../src/errors.ts","../src/resources/events.ts","../src/resources/customers.ts","../src/resources/metrics.ts","../src/resources/plans.ts","../src/resources/subscriptions.ts","../src/resources/payout-accounts.ts","../src/resources/invoices.ts","../src/resources/usage.ts","../src/client.ts","../src/types.ts"],"sourcesContent":["/**\n * Thrown for any non-2xx response from the Monigo API.\n *\n * @example\n * ```ts\n * try {\n * await client.customers.get('bad-id')\n * } catch (err) {\n * if (MonigoAPIError.isNotFound(err)) {\n * console.log('Customer does not exist')\n * }\n * }\n * ```\n */\nexport class MonigoAPIError extends Error {\n /** HTTP status code returned by the API. */\n readonly statusCode: number\n /** Human-readable error message from the API. */\n readonly message: string\n /** Optional structured field-level validation details. */\n readonly details: Record<string, string> | undefined\n\n constructor(\n statusCode: number,\n message: string,\n details?: Record<string, string>,\n ) {\n super(message)\n this.name = 'MonigoAPIError'\n this.statusCode = statusCode\n this.message = message\n this.details = details\n // Maintain proper stack trace in V8 (Node.js / Chrome)\n const capture = (Error as unknown as Record<string, unknown>)[\n 'captureStackTrace'\n ] as ((target: Error, constructor: Function) => void) | undefined\n capture?.(this, MonigoAPIError)\n }\n\n // -------------------------------------------------------------------------\n // Instance guards (for use on a caught error known to be MonigoAPIError)\n // -------------------------------------------------------------------------\n\n get isNotFound(): boolean {\n return this.statusCode === 404\n }\n\n get isUnauthorized(): boolean {\n return this.statusCode === 401\n }\n\n get isForbidden(): boolean {\n return this.statusCode === 403\n }\n\n get isRateLimited(): boolean {\n return this.statusCode === 429\n }\n\n get isConflict(): boolean {\n return this.statusCode === 409\n }\n\n get isQuotaExceeded(): boolean {\n return this.statusCode === 402\n }\n\n get isServerError(): boolean {\n return this.statusCode >= 500\n }\n\n // -------------------------------------------------------------------------\n // Static type-narrowing helpers (for use in catch clauses on `unknown`)\n // -------------------------------------------------------------------------\n\n static isNotFound(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 404\n }\n\n static isUnauthorized(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 401\n }\n\n static isForbidden(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 403\n }\n\n static isRateLimited(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 429\n }\n\n static isConflict(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 409\n }\n\n static isQuotaExceeded(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 402\n }\n\n static isServerError(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode >= 500\n }\n}\n","import { MonigoClient } from '../client.js'\nimport type {\n IngestRequest,\n IngestResponse,\n StartReplayRequest,\n EventReplayJob,\n} from '../types.js'\n\n/** Handles usage event ingestion and asynchronous event replay. */\nexport class EventsResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Ingest one or more usage events into the Monigo pipeline.\n *\n * Events are processed asynchronously. The response confirms receipt\n * and reports any duplicate idempotency keys.\n *\n * **Requires `ingest` scope.**\n *\n * @example\n * ```ts\n * const result = await monigo.events.ingest({\n * events: [{\n * event_name: 'api_call',\n * customer_id: 'cust_abc',\n * idempotency_key: crypto.randomUUID(),\n * timestamp: new Date().toISOString(),\n * properties: { endpoint: '/checkout', region: 'eu-west-1' },\n * }],\n * })\n * console.log('Ingested:', result.ingested.length)\n * console.log('Duplicates:', result.duplicates.length)\n * ```\n */\n async ingest(request: IngestRequest): Promise<IngestResponse> {\n const body = {\n events: request.events.map((e) => ({\n ...e,\n timestamp: e.timestamp\n ? MonigoClient.toISOString(e.timestamp)\n : new Date().toISOString(),\n })),\n }\n return this.client._request<IngestResponse>('POST', '/v1/ingest', { body })\n }\n\n /**\n * Start an asynchronous replay of all raw events in a given time window\n * through the current processing pipeline. Useful for backfilling usage\n * data after changing metric definitions.\n *\n * Returns a replay job immediately — poll `getReplay()` to track progress.\n *\n * **Requires `ingest` scope.**\n *\n * @example\n * ```ts\n * const job = await monigo.events.startReplay({\n * from: '2025-01-01T00:00:00Z',\n * to: '2025-01-31T23:59:59Z',\n * event_name: 'api_call', // omit to replay all event types\n * })\n * console.log('Replay job:', job.id, job.status)\n * ```\n */\n async startReplay(request: StartReplayRequest): Promise<EventReplayJob> {\n const body = {\n from: MonigoClient.toISOString(request.from),\n to: MonigoClient.toISOString(request.to),\n ...(request.event_name ? { event_name: request.event_name } : {}),\n }\n const wrapper = await this.client._request<{ job: EventReplayJob }>(\n 'POST',\n '/v1/events/replay',\n { body },\n )\n return wrapper.job\n }\n\n /**\n * Fetch the current status and progress of an event replay job.\n *\n * **Requires `ingest` scope.**\n *\n * @example\n * ```ts\n * const job = await monigo.events.getReplay(jobId)\n * if (job.status === 'completed') {\n * console.log(`Replayed ${job.events_replayed} / ${job.events_total} events`)\n * }\n * ```\n */\n async getReplay(jobId: string): Promise<EventReplayJob> {\n const wrapper = await this.client._request<{ job: EventReplayJob }>(\n 'GET',\n `/v1/events/replay/${jobId}`,\n )\n return wrapper.job\n }\n}\n","import type { MonigoClient } from '../client.js'\nimport type {\n Customer,\n CreateCustomerRequest,\n UpdateCustomerRequest,\n ListCustomersResponse,\n} from '../types.js'\n\n/** Manage end-customers in your Monigo organisation. */\nexport class CustomersResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Register a new customer.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const customer = await monigo.customers.create({\n * external_id: 'usr_12345',\n * name: 'Acme Corp',\n * email: 'billing@acme.com',\n * metadata: { plan_tier: 'enterprise' },\n * })\n * ```\n */\n async create(request: CreateCustomerRequest): Promise<Customer> {\n const wrapper = await this.client._request<{ customer: Customer }>(\n 'POST',\n '/v1/customers',\n { body: request },\n )\n return wrapper.customer\n }\n\n /**\n * Return all customers in the authenticated organisation.\n *\n * **Requires `read` scope.**\n */\n async list(): Promise<ListCustomersResponse> {\n return this.client._request<ListCustomersResponse>('GET', '/v1/customers')\n }\n\n /**\n * Fetch a single customer by their Monigo UUID.\n *\n * **Requires `read` scope.**\n */\n async get(customerId: string): Promise<Customer> {\n const wrapper = await this.client._request<{ customer: Customer }>(\n 'GET',\n `/v1/customers/${customerId}`,\n )\n return wrapper.customer\n }\n\n /**\n * Update a customer's name, email, or metadata.\n * Only fields that are present in `request` are updated.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const updated = await monigo.customers.update(customerId, {\n * email: 'new@acme.com',\n * })\n * ```\n */\n async update(\n customerId: string,\n request: UpdateCustomerRequest,\n ): Promise<Customer> {\n const wrapper = await this.client._request<{ customer: Customer }>(\n 'PUT',\n `/v1/customers/${customerId}`,\n { body: request },\n )\n return wrapper.customer\n }\n\n /**\n * Permanently delete a customer record.\n *\n * **Requires `write` scope.**\n */\n async delete(customerId: string): Promise<void> {\n await this.client._request<void>('DELETE', `/v1/customers/${customerId}`)\n }\n}\n","import type { MonigoClient } from '../client.js'\nimport type {\n Metric,\n CreateMetricRequest,\n UpdateMetricRequest,\n ListMetricsResponse,\n} from '../types.js'\n\n/** Manage billing metrics — what usage gets counted and how it is aggregated. */\nexport class MetricsResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Create a new metric.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const metric = await monigo.metrics.create({\n * name: 'API Calls',\n * event_name: 'api_call',\n * aggregation: 'count',\n * })\n * ```\n */\n async create(request: CreateMetricRequest): Promise<Metric> {\n const wrapper = await this.client._request<{ metric: Metric }>(\n 'POST',\n '/v1/metrics',\n { body: request },\n )\n return wrapper.metric\n }\n\n /**\n * Return all metrics in the authenticated organisation.\n *\n * **Requires `read` scope.**\n */\n async list(): Promise<ListMetricsResponse> {\n return this.client._request<ListMetricsResponse>('GET', '/v1/metrics')\n }\n\n /**\n * Fetch a single metric by its UUID.\n *\n * **Requires `read` scope.**\n */\n async get(metricId: string): Promise<Metric> {\n const wrapper = await this.client._request<{ metric: Metric }>(\n 'GET',\n `/v1/metrics/${metricId}`,\n )\n return wrapper.metric\n }\n\n /**\n * Update a metric's name, event name, aggregation, or description.\n *\n * **Requires `write` scope.**\n */\n async update(metricId: string, request: UpdateMetricRequest): Promise<Metric> {\n const wrapper = await this.client._request<{ metric: Metric }>(\n 'PUT',\n `/v1/metrics/${metricId}`,\n { body: request },\n )\n return wrapper.metric\n }\n\n /**\n * Permanently delete a metric.\n *\n * **Requires `write` scope.**\n */\n async delete(metricId: string): Promise<void> {\n await this.client._request<void>('DELETE', `/v1/metrics/${metricId}`)\n }\n}\n","import type { MonigoClient } from '../client.js'\nimport type {\n Plan,\n CreatePlanRequest,\n UpdatePlanRequest,\n ListPlansResponse,\n} from '../types.js'\n\n/** Manage billing plans and their prices. */\nexport class PlansResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Create a new billing plan, optionally with prices attached.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const plan = await monigo.plans.create({\n * name: 'Pro',\n * currency: 'NGN',\n * billing_period: 'monthly',\n * prices: [{\n * metric_id: 'metric_abc',\n * model: 'flat',\n * unit_price: '2.500000',\n * }],\n * })\n * ```\n */\n async create(request: CreatePlanRequest): Promise<Plan> {\n const wrapper = await this.client._request<{ plan: Plan }>(\n 'POST',\n '/v1/plans',\n { body: request },\n )\n return wrapper.plan\n }\n\n /**\n * Return all billing plans in the authenticated organisation.\n *\n * **Requires `read` scope.**\n */\n async list(): Promise<ListPlansResponse> {\n return this.client._request<ListPlansResponse>('GET', '/v1/plans')\n }\n\n /**\n * Fetch a single plan by its UUID, including its prices.\n *\n * **Requires `read` scope.**\n */\n async get(planId: string): Promise<Plan> {\n const wrapper = await this.client._request<{ plan: Plan }>(\n 'GET',\n `/v1/plans/${planId}`,\n )\n return wrapper.plan\n }\n\n /**\n * Update a plan's name, description, currency, or prices.\n *\n * **Requires `write` scope.**\n */\n async update(planId: string, request: UpdatePlanRequest): Promise<Plan> {\n const wrapper = await this.client._request<{ plan: Plan }>(\n 'PUT',\n `/v1/plans/${planId}`,\n { body: request },\n )\n return wrapper.plan\n }\n\n /**\n * Permanently delete a plan.\n *\n * **Requires `write` scope.**\n */\n async delete(planId: string): Promise<void> {\n await this.client._request<void>('DELETE', `/v1/plans/${planId}`)\n }\n}\n","import type { MonigoClient } from '../client.js'\nimport type {\n Subscription,\n CreateSubscriptionRequest,\n ListSubscriptionsParams,\n ListSubscriptionsResponse,\n SubscriptionStatusValue,\n} from '../types.js'\n\n/** Link customers to billing plans and manage subscription lifecycle. */\nexport class SubscriptionsResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Subscribe a customer to a plan.\n *\n * Returns a 409 Conflict error (check with `MonigoAPIError.isConflict(err)`)\n * if the customer already has an active subscription to the same plan.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const sub = await monigo.subscriptions.create({\n * customer_id: 'cust_abc',\n * plan_id: 'plan_xyz',\n * })\n * ```\n */\n async create(request: CreateSubscriptionRequest): Promise<Subscription> {\n const wrapper = await this.client._request<{ subscription: Subscription }>(\n 'POST',\n '/v1/subscriptions',\n { body: request },\n )\n return wrapper.subscription\n }\n\n /**\n * Return subscriptions, optionally filtered by customer, plan, or status.\n *\n * **Requires `read` scope.**\n *\n * @example\n * ```ts\n * const { subscriptions } = await monigo.subscriptions.list({\n * customer_id: 'cust_abc',\n * status: 'active',\n * })\n * ```\n */\n async list(params: ListSubscriptionsParams = {}): Promise<ListSubscriptionsResponse> {\n return this.client._request<ListSubscriptionsResponse>('GET', '/v1/subscriptions', {\n query: {\n customer_id: params.customer_id,\n plan_id: params.plan_id,\n status: params.status,\n },\n })\n }\n\n /**\n * Fetch a single subscription by its UUID.\n *\n * **Requires `read` scope.**\n */\n async get(subscriptionId: string): Promise<Subscription> {\n const wrapper = await this.client._request<{ subscription: Subscription }>(\n 'GET',\n `/v1/subscriptions/${subscriptionId}`,\n )\n return wrapper.subscription\n }\n\n /**\n * Change the status of a subscription.\n * Use `SubscriptionStatus` constants: `\"active\"`, `\"paused\"`, `\"canceled\"`.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * await monigo.subscriptions.updateStatus(subId, SubscriptionStatus.Paused)\n * ```\n */\n async updateStatus(\n subscriptionId: string,\n status: SubscriptionStatusValue,\n ): Promise<Subscription> {\n const wrapper = await this.client._request<{ subscription: Subscription }>(\n 'PATCH',\n `/v1/subscriptions/${subscriptionId}`,\n { body: { status } },\n )\n return wrapper.subscription\n }\n\n /**\n * Cancel and delete a subscription record.\n *\n * **Requires `write` scope.**\n */\n async delete(subscriptionId: string): Promise<void> {\n await this.client._request<void>('DELETE', `/v1/subscriptions/${subscriptionId}`)\n }\n}\n","import type { MonigoClient } from '../client.js'\nimport type {\n PayoutAccount,\n CreatePayoutAccountRequest,\n UpdatePayoutAccountRequest,\n ListPayoutAccountsResponse,\n} from '../types.js'\n\n/** Manage bank and mobile-money payout accounts for customers. */\nexport class PayoutAccountsResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Add a payout account for a customer.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const account = await monigo.payoutAccounts.create('cust_abc', {\n * account_name: 'Acme Corp',\n * payout_method: 'bank_transfer',\n * bank_name: 'Zenith Bank',\n * bank_code: '057',\n * account_number: '1234567890',\n * currency: 'NGN',\n * is_default: true,\n * })\n * ```\n */\n async create(\n customerId: string,\n request: CreatePayoutAccountRequest,\n ): Promise<PayoutAccount> {\n const wrapper = await this.client._request<{ payout_account: PayoutAccount }>(\n 'POST',\n `/v1/customers/${customerId}/payout-accounts`,\n { body: request },\n )\n return wrapper.payout_account\n }\n\n /**\n * Return all payout accounts for a customer.\n *\n * **Requires `read` scope.**\n */\n async list(customerId: string): Promise<ListPayoutAccountsResponse> {\n return this.client._request<ListPayoutAccountsResponse>(\n 'GET',\n `/v1/customers/${customerId}/payout-accounts`,\n )\n }\n\n /**\n * Fetch a single payout account by its UUID.\n *\n * **Requires `read` scope.**\n */\n async get(customerId: string, accountId: string): Promise<PayoutAccount> {\n const wrapper = await this.client._request<{ payout_account: PayoutAccount }>(\n 'GET',\n `/v1/customers/${customerId}/payout-accounts/${accountId}`,\n )\n return wrapper.payout_account\n }\n\n /**\n * Update a payout account's details.\n *\n * **Requires `write` scope.**\n */\n async update(\n customerId: string,\n accountId: string,\n request: UpdatePayoutAccountRequest,\n ): Promise<PayoutAccount> {\n const wrapper = await this.client._request<{ payout_account: PayoutAccount }>(\n 'PUT',\n `/v1/customers/${customerId}/payout-accounts/${accountId}`,\n { body: request },\n )\n return wrapper.payout_account\n }\n\n /**\n * Delete a payout account.\n *\n * **Requires `write` scope.**\n */\n async delete(customerId: string, accountId: string): Promise<void> {\n await this.client._request<void>(\n 'DELETE',\n `/v1/customers/${customerId}/payout-accounts/${accountId}`,\n )\n }\n}\n","import type { MonigoClient } from '../client.js'\nimport type {\n Invoice,\n ListInvoicesParams,\n ListInvoicesResponse,\n} from '../types.js'\n\n/** Manage invoice generation, finalization, and voiding. */\nexport class InvoicesResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Generate a draft invoice for a subscription based on current period usage.\n * The invoice starts in `\"draft\"` status and is not sent to the customer yet.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const invoice = await monigo.invoices.generate('sub_xyz')\n * console.log('Draft invoice total:', invoice.total)\n * ```\n */\n async generate(subscriptionId: string): Promise<Invoice> {\n const wrapper = await this.client._request<{ invoice: Invoice }>(\n 'POST',\n '/v1/invoices/generate',\n { body: { subscription_id: subscriptionId } },\n )\n return wrapper.invoice\n }\n\n /**\n * Return invoices, optionally filtered by status or customer.\n *\n * **Requires `read` scope.**\n *\n * @example\n * ```ts\n * const { invoices } = await monigo.invoices.list({\n * status: 'finalized',\n * customer_id: 'cust_abc',\n * })\n * ```\n */\n async list(params: ListInvoicesParams = {}): Promise<ListInvoicesResponse> {\n return this.client._request<ListInvoicesResponse>('GET', '/v1/invoices', {\n query: {\n status: params.status,\n customer_id: params.customer_id,\n },\n })\n }\n\n /**\n * Fetch a single invoice by its UUID, including line items.\n *\n * **Requires `read` scope.**\n */\n async get(invoiceId: string): Promise<Invoice> {\n const wrapper = await this.client._request<{ invoice: Invoice }>(\n 'GET',\n `/v1/invoices/${invoiceId}`,\n )\n return wrapper.invoice\n }\n\n /**\n * Finalize a draft invoice, making it ready for payment.\n * A finalized invoice cannot be edited.\n *\n * **Requires `write` scope.**\n */\n async finalize(invoiceId: string): Promise<Invoice> {\n const wrapper = await this.client._request<{ invoice: Invoice }>(\n 'POST',\n `/v1/invoices/${invoiceId}/finalize`,\n )\n return wrapper.invoice\n }\n\n /**\n * Void an invoice, making it permanently non-payable.\n * Only admins and owners can void invoices.\n *\n * **Requires `write` scope.**\n */\n async void(invoiceId: string): Promise<Invoice> {\n const wrapper = await this.client._request<{ invoice: Invoice }>(\n 'POST',\n `/v1/invoices/${invoiceId}/void`,\n )\n return wrapper.invoice\n }\n}\n","import { MonigoClient } from '../client.js'\nimport type { UsageQueryParams, UsageQueryResult } from '../types.js'\n\n/** Query aggregated usage rollups from the Monigo metering pipeline. */\nexport class UsageResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Return per-customer, per-metric usage rollups for the organisation.\n * All parameters are optional — omitting them returns the full current\n * billing period for all customers and metrics.\n *\n * **Requires `read` scope.**\n *\n * @example\n * ```ts\n * // All usage for one customer this period\n * const { rollups } = await monigo.usage.query({\n * customer_id: 'cust_abc',\n * })\n *\n * // Filtered by metric and custom date range\n * const { rollups: filtered } = await monigo.usage.query({\n * metric_id: 'metric_xyz',\n * from: '2025-01-01T00:00:00Z',\n * to: '2025-01-31T23:59:59Z',\n * })\n * ```\n */\n async query(params: UsageQueryParams = {}): Promise<UsageQueryResult> {\n const query: Record<string, string | undefined> = {\n customer_id: params.customer_id,\n metric_id: params.metric_id,\n }\n if (params.from !== undefined) {\n query.from = MonigoClient.toISOString(params.from)\n }\n if (params.to !== undefined) {\n query.to = MonigoClient.toISOString(params.to)\n }\n return this.client._request<UsageQueryResult>('GET', '/v1/usage', { query })\n }\n}\n","import { MonigoAPIError } from './errors.js'\nimport { EventsResource } from './resources/events.js'\nimport { CustomersResource } from './resources/customers.js'\nimport { MetricsResource } from './resources/metrics.js'\nimport { PlansResource } from './resources/plans.js'\nimport { SubscriptionsResource } from './resources/subscriptions.js'\nimport { PayoutAccountsResource } from './resources/payout-accounts.js'\nimport { InvoicesResource } from './resources/invoices.js'\nimport { UsageResource } from './resources/usage.js'\n\nconst DEFAULT_BASE_URL = 'https://api.monigo.co'\nconst DEFAULT_TIMEOUT_MS = 30_000\n\nexport interface MonigoClientOptions {\n /**\n * Your Monigo API key. Obtain one from the API Keys section of your\n * Monigo dashboard. Never expose this key in client-side code.\n */\n apiKey: string\n /**\n * Override the default API base URL (`https://api.monigo.co`).\n * Useful for self-hosted deployments or pointing at a local dev server.\n *\n * @default \"https://api.monigo.co\"\n */\n baseURL?: string\n /**\n * Custom `fetch` implementation. Defaults to `globalThis.fetch`.\n * Pass a polyfill for environments that do not have native fetch\n * (Node.js < 18) or to inject a mock in tests.\n */\n fetch?: typeof globalThis.fetch\n /**\n * Request timeout in milliseconds.\n *\n * @default 30000\n */\n timeout?: number\n}\n\n/** @internal */\nexport interface RequestOptions {\n body?: unknown\n query?: Record<string, string | undefined>\n}\n\n/**\n * The Monigo API client.\n *\n * Instantiate once and reuse across your application:\n *\n * ```ts\n * import { MonigoClient } from '@monigo/sdk'\n *\n * const monigo = new MonigoClient({ apiKey: process.env.MONIGO_API_KEY! })\n *\n * // Ingest a usage event\n * await monigo.events.ingest({\n * events: [{\n * event_name: 'api_call',\n * customer_id: 'cust_abc123',\n * idempotency_key: crypto.randomUUID(),\n * }],\n * })\n * ```\n */\nexport class MonigoClient {\n /** @internal */\n readonly _apiKey: string\n /** @internal */\n readonly _baseURL: string\n /** @internal */\n readonly _fetchFn: typeof globalThis.fetch\n /** @internal */\n readonly _timeout: number\n\n /** Ingest usage events and manage event replays. Requires `ingest` scope. */\n readonly events: EventsResource\n /** Manage your end-customers (CRUD). Requires `read` / `write` scope. */\n readonly customers: CustomersResource\n /** Manage billing metrics — what gets counted and how. Requires `read` / `write` scope. */\n readonly metrics: MetricsResource\n /** Manage billing plans and their prices. Requires `read` / `write` scope. */\n readonly plans: PlansResource\n /** Link customers to plans and manage subscription lifecycle. Requires `read` / `write` scope. */\n readonly subscriptions: SubscriptionsResource\n /** Manage bank / mobile-money payout accounts for customers. Requires `read` / `write` scope. */\n readonly payoutAccounts: PayoutAccountsResource\n /** Generate, list, finalize, and void invoices. Requires `read` / `write` scope. */\n readonly invoices: InvoicesResource\n /** Query aggregated usage rollups per customer and metric. Requires `read` scope. */\n readonly usage: UsageResource\n\n constructor(options: MonigoClientOptions) {\n if (!options.apiKey) {\n throw new Error('MonigoClient: apiKey is required')\n }\n\n this._apiKey = options.apiKey\n this._baseURL = (options.baseURL ?? DEFAULT_BASE_URL).replace(/\\/$/, '')\n this._timeout = options.timeout ?? DEFAULT_TIMEOUT_MS\n\n const fetchFn = options.fetch ?? (typeof globalThis !== 'undefined' ? globalThis.fetch : undefined)\n if (!fetchFn) {\n throw new Error(\n 'MonigoClient: fetch is not available in this environment. ' +\n 'Pass a custom fetch implementation via options.fetch, ' +\n 'or upgrade to Node.js 18+.',\n )\n }\n this._fetchFn = fetchFn.bind(globalThis)\n\n this.events = new EventsResource(this)\n this.customers = new CustomersResource(this)\n this.metrics = new MetricsResource(this)\n this.plans = new PlansResource(this)\n this.subscriptions = new SubscriptionsResource(this)\n this.payoutAccounts = new PayoutAccountsResource(this)\n this.invoices = new InvoicesResource(this)\n this.usage = new UsageResource(this)\n }\n\n /**\n * Execute an authenticated HTTP request against the Monigo API.\n * @internal — use the resource methods instead.\n */\n async _request<T>(\n method: string,\n path: string,\n options: RequestOptions = {},\n ): Promise<T> {\n let url = this._baseURL + path\n\n if (options.query) {\n const params = new URLSearchParams()\n for (const [key, value] of Object.entries(options.query)) {\n if (value !== undefined && value !== '') {\n params.set(key, value)\n }\n }\n const qs = params.toString()\n if (qs) url += '?' + qs\n }\n\n const controller = new AbortController()\n const timeoutId = setTimeout(() => controller.abort(), this._timeout)\n\n try {\n const response = await this._fetchFn(url, {\n method,\n headers: {\n Authorization: `Bearer ${this._apiKey}`,\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n },\n body: options.body != null ? JSON.stringify(options.body) : undefined,\n signal: controller.signal,\n })\n\n const text = await response.text()\n\n if (!response.ok) {\n let message = text || response.statusText\n let details: Record<string, string> | undefined\n try {\n const parsed = JSON.parse(text) as {\n error?: string\n message?: string\n details?: Record<string, string>\n }\n message = parsed.error ?? parsed.message ?? message\n details = parsed.details\n } catch {\n // Use raw text as the error message\n }\n throw new MonigoAPIError(response.status, message, details)\n }\n\n if (!text) return undefined as T\n return JSON.parse(text) as T\n } catch (err) {\n if (err instanceof MonigoAPIError) throw err\n if (err instanceof Error && err.name === 'AbortError') {\n throw new Error(\n `MonigoClient: request to ${url} timed out after ${this._timeout}ms`,\n )\n }\n throw err\n } finally {\n clearTimeout(timeoutId)\n }\n }\n\n /** Normalise a `Date | string` value to an ISO 8601 string. */\n static toISOString(value: string | Date): string {\n return value instanceof Date ? value.toISOString() : value\n }\n}\n","// =============================================================================\n// Aggregation constants\n// =============================================================================\n\nexport const Aggregation = {\n Count: 'count',\n Sum: 'sum',\n Max: 'max',\n Min: 'minimum',\n Average: 'average',\n Unique: 'unique',\n} as const\n\nexport type AggregationType = (typeof Aggregation)[keyof typeof Aggregation]\n\n// =============================================================================\n// Pricing model constants\n// =============================================================================\n\nexport const PricingModel = {\n Flat: 'flat',\n Tiered: 'tiered',\n Volume: 'volume',\n Package: 'package',\n Overage: 'overage',\n WeightedTiered: 'weighted_tiered',\n} as const\n\nexport type PricingModelType = (typeof PricingModel)[keyof typeof PricingModel]\n\n// =============================================================================\n// Plan constants\n// =============================================================================\n\nexport const PlanType = {\n Collection: 'collection',\n Payout: 'payout',\n} as const\n\nexport type PlanTypeValue = (typeof PlanType)[keyof typeof PlanType]\n\nexport const BillingPeriod = {\n Daily: 'daily',\n Weekly: 'weekly',\n Monthly: 'monthly',\n Quarterly: 'quarterly',\n Annually: 'annually',\n} as const\n\nexport type BillingPeriodValue = (typeof BillingPeriod)[keyof typeof BillingPeriod]\n\n// =============================================================================\n// Subscription status constants\n// =============================================================================\n\nexport const SubscriptionStatus = {\n Active: 'active',\n Paused: 'paused',\n Canceled: 'canceled',\n} as const\n\nexport type SubscriptionStatusValue = (typeof SubscriptionStatus)[keyof typeof SubscriptionStatus]\n\n// =============================================================================\n// Invoice status constants\n// =============================================================================\n\nexport const InvoiceStatus = {\n Draft: 'draft',\n Finalized: 'finalized',\n Paid: 'paid',\n Void: 'void',\n} as const\n\nexport type InvoiceStatusValue = (typeof InvoiceStatus)[keyof typeof InvoiceStatus]\n\n// =============================================================================\n// Payout method constants\n// =============================================================================\n\nexport const PayoutMethod = {\n BankTransfer: 'bank_transfer',\n MobileMoney: 'mobile_money',\n} as const\n\nexport type PayoutMethodValue = (typeof PayoutMethod)[keyof typeof PayoutMethod]\n\n// =============================================================================\n// Events\n// =============================================================================\n\n/** A single usage event sent to the Monigo ingestion pipeline. */\nexport interface IngestEvent {\n /**\n * The name of the event, e.g. `\"api_call\"` or `\"storage.write\"`.\n * Must match the `event_name` on one or more metrics you have configured.\n */\n event_name: string\n /** The Monigo customer UUID this event belongs to. */\n customer_id: string\n /**\n * A unique key for this event. Re-sending the same key is safe — the server\n * will de-duplicate automatically. Use a UUID or any stable ID you control.\n */\n idempotency_key: string\n /**\n * ISO 8601 timestamp for when the event occurred. Backdated events are\n * accepted within the configured replay window. Defaults to now if omitted.\n */\n timestamp?: string | Date\n /**\n * Arbitrary key-value pairs attached to the event. Use these for dimensions\n * such as `{ endpoint: \"/checkout\", region: \"eu-west-1\" }`.\n */\n properties?: Record<string, unknown>\n}\n\n/** Request body for `POST /v1/ingest`. */\nexport interface IngestRequest {\n events: IngestEvent[]\n}\n\n/** Response from `POST /v1/ingest`. */\nexport interface IngestResponse {\n /** Idempotency keys of events that were successfully ingested. */\n ingested: string[]\n /** Idempotency keys that were skipped because they already existed. */\n duplicates: string[]\n}\n\n/** Request body for `POST /v1/events/replay`. */\nexport interface StartReplayRequest {\n /** Start of the replay window (ISO 8601). */\n from: string | Date\n /** End of the replay window (ISO 8601). */\n to: string | Date\n /** Optional event name to replay. Omit to replay all event types. */\n event_name?: string\n}\n\n/** Tracks the progress of an asynchronous event replay job. */\nexport interface EventReplayJob {\n id: string\n org_id: string\n initiated_by: string\n /** `pending` | `processing` | `completed` | `failed` */\n status: string\n from_timestamp: string\n to_timestamp: string\n event_name: string | null\n is_test: boolean\n events_total: number\n events_replayed: number\n error_message: string | null\n started_at: string | null\n completed_at: string | null\n created_at: string\n updated_at: string\n}\n\n// =============================================================================\n// Customers\n// =============================================================================\n\n/** An end-customer record in your Monigo organisation. */\nexport interface Customer {\n id: string\n org_id: string\n /** The ID for this customer in your own system. */\n external_id: string\n name: string\n email: string\n /** Arbitrary JSON metadata. */\n metadata: Record<string, unknown> | null\n created_at: string\n updated_at: string\n}\n\nexport interface CreateCustomerRequest {\n /** Your internal ID for this customer. */\n external_id: string\n name: string\n email: string\n metadata?: Record<string, unknown>\n}\n\nexport interface UpdateCustomerRequest {\n name?: string\n email?: string\n metadata?: Record<string, unknown>\n}\n\nexport interface ListCustomersResponse {\n customers: Customer[]\n count: number\n}\n\n// =============================================================================\n// Metrics\n// =============================================================================\n\n/** Defines what usage is counted and how. */\nexport interface Metric {\n id: string\n org_id: string\n name: string\n /** The `event_name` value that this metric tracks. */\n event_name: string\n /** How events are aggregated. Use `Aggregation` constants. */\n aggregation: AggregationType\n /** For sum/max/min/average: the Properties key whose value is used. */\n aggregation_property?: string\n description?: string\n created_at: string\n updated_at: string\n}\n\nexport interface CreateMetricRequest {\n /** Human-readable label, e.g. `\"API Calls\"`. */\n name: string\n /** The `event_name` value to track. */\n event_name: string\n /** How events are aggregated. Use `Aggregation` constants. */\n aggregation: AggregationType\n description?: string\n /** Required for sum/max/min/average aggregations. */\n aggregation_property?: string\n}\n\nexport interface UpdateMetricRequest {\n name?: string\n event_name?: string\n aggregation?: AggregationType\n description?: string\n aggregation_property?: string\n}\n\nexport interface ListMetricsResponse {\n metrics: Metric[]\n count: number\n}\n\n// =============================================================================\n// Plans & Prices\n// =============================================================================\n\n/**\n * One price step in a tiered/volume/weighted_tiered pricing model.\n * Set `up_to` to `null` for the final (infinite) tier.\n */\nexport interface PriceTier {\n up_to: number | null\n /** Price per unit in this tier as a decimal string, e.g. `\"0.50\"`. */\n unit_amount: string\n}\n\n/** Describes a price to attach when creating a plan. */\nexport interface CreatePriceRequest {\n /** UUID of the metric this price is based on. */\n metric_id: string\n /** Pricing model. Use `PricingModel` constants. */\n model: PricingModelType\n /** Flat price per unit as a decimal string (used for flat/overage/package models). */\n unit_price?: string\n /** Price tiers for tiered/volume/weighted_tiered models. */\n tiers?: PriceTier[]\n}\n\n/** Describes an updated price. Include `id` to update an existing price; omit to add a new one. */\nexport interface UpdatePriceRequest {\n id?: string\n metric_id?: string\n model?: PricingModelType\n unit_price?: string\n tiers?: PriceTier[]\n}\n\n/** A pricing rule attached to a plan. */\nexport interface Price {\n id: string\n plan_id: string\n metric_id: string\n model: PricingModelType\n unit_price: string\n tiers: PriceTier[] | null\n created_at: string\n updated_at: string\n}\n\n/** A billing plan that defines pricing for one or more metrics. */\nexport interface Plan {\n id: string\n org_id: string\n name: string\n description?: string\n /** ISO 4217 currency code, e.g. `\"NGN\"`. */\n currency: string\n /** Use `PlanType` constants. */\n plan_type: PlanTypeValue\n /** Use `BillingPeriod` constants. */\n billing_period: BillingPeriodValue\n trial_period_days: number\n prices?: Price[]\n created_at: string\n updated_at: string\n}\n\nexport interface CreatePlanRequest {\n name: string\n description?: string\n /** ISO 4217 currency code. Defaults to `\"NGN\"`. */\n currency?: string\n /** Use `PlanType` constants. Defaults to `\"collection\"`. */\n plan_type?: PlanTypeValue\n /** Use `BillingPeriod` constants. Defaults to `\"monthly\"`. */\n billing_period?: BillingPeriodValue\n /** Trial period in days. Set to `0` for no trial. */\n trial_period_days?: number\n prices?: CreatePriceRequest[]\n}\n\nexport interface UpdatePlanRequest {\n name?: string\n description?: string\n currency?: string\n plan_type?: PlanTypeValue\n billing_period?: BillingPeriodValue\n prices?: UpdatePriceRequest[]\n}\n\nexport interface ListPlansResponse {\n plans: Plan[]\n count: number\n}\n\n// =============================================================================\n// Subscriptions\n// =============================================================================\n\n/** Links a customer to a billing plan. */\nexport interface Subscription {\n id: string\n org_id: string\n customer_id: string\n plan_id: string\n /** Use `SubscriptionStatus` constants. */\n status: SubscriptionStatusValue\n current_period_start: string\n current_period_end: string\n trial_ends_at: string | null\n created_at: string\n updated_at: string\n}\n\nexport interface CreateSubscriptionRequest {\n /** UUID of the customer to subscribe. */\n customer_id: string\n /** UUID of the plan to subscribe the customer to. */\n plan_id: string\n}\n\nexport interface ListSubscriptionsParams {\n /** Filter to a specific customer UUID. */\n customer_id?: string\n /** Filter to a specific plan UUID. */\n plan_id?: string\n /** Filter by status. Use `SubscriptionStatus` constants. */\n status?: SubscriptionStatusValue\n}\n\nexport interface ListSubscriptionsResponse {\n subscriptions: Subscription[]\n count: number\n}\n\n// =============================================================================\n// Payout accounts\n// =============================================================================\n\n/** A bank or mobile-money account that a customer can be paid to. */\nexport interface PayoutAccount {\n id: string\n customer_id: string\n org_id: string\n account_name: string\n bank_name?: string\n bank_code?: string\n account_number?: string\n mobile_money_number?: string\n /** Use `PayoutMethod` constants. */\n payout_method: PayoutMethodValue\n currency: string\n is_default: boolean\n metadata: Record<string, unknown> | null\n created_at: string\n updated_at: string\n}\n\nexport interface CreatePayoutAccountRequest {\n account_name: string\n /** Use `PayoutMethod` constants. */\n payout_method: PayoutMethodValue\n bank_name?: string\n bank_code?: string\n account_number?: string\n mobile_money_number?: string\n currency?: string\n is_default?: boolean\n metadata?: Record<string, unknown>\n}\n\nexport interface UpdatePayoutAccountRequest {\n account_name?: string\n payout_method?: PayoutMethodValue\n bank_name?: string\n account_number?: string\n currency?: string\n is_default?: boolean\n metadata?: Record<string, unknown>\n}\n\nexport interface ListPayoutAccountsResponse {\n payout_accounts: PayoutAccount[]\n count: number\n}\n\n// =============================================================================\n// Invoices\n// =============================================================================\n\n/** One line item on an invoice. */\nexport interface InvoiceLineItem {\n id: string\n invoice_id: string\n metric_id: string\n price_id?: string\n description: string\n quantity: string\n unit_price: string\n /** Amount for this line as a decimal string. */\n amount: string\n created_at: string\n}\n\n/**\n * A billing invoice.\n * All monetary values (`subtotal`, `vat_amount`, `total`) are decimal strings\n * to avoid floating-point precision issues.\n */\nexport interface Invoice {\n id: string\n org_id: string\n customer_id: string\n subscription_id: string\n /** Use `InvoiceStatus` constants. */\n status: InvoiceStatusValue\n currency: string\n subtotal: string\n vat_enabled: boolean\n vat_rate?: string\n vat_amount?: string\n total: string\n period_start: string\n period_end: string\n finalized_at: string | null\n paid_at: string | null\n provider_invoice_id?: string\n line_items?: InvoiceLineItem[]\n created_at: string\n updated_at: string\n}\n\nexport interface ListInvoicesParams {\n /** Filter by status. Use `InvoiceStatus` constants. */\n status?: InvoiceStatusValue\n /** Filter to a specific customer UUID. */\n customer_id?: string\n}\n\nexport interface ListInvoicesResponse {\n invoices: Invoice[]\n count: number\n}\n\n// =============================================================================\n// Usage\n// =============================================================================\n\n/** One aggregated usage record for a (customer, metric, period) tuple. */\nexport interface UsageRollup {\n id: string\n org_id: string\n customer_id: string\n metric_id: string\n period_start: string\n period_end: string\n aggregation: AggregationType\n /** Aggregated value (count, sum, max, etc.). */\n value: number\n event_count: number\n last_event_at: string | null\n is_test: boolean\n created_at: string\n updated_at: string\n}\n\nexport interface UsageQueryParams {\n /** Filter rollups to a specific customer UUID. */\n customer_id?: string\n /** Filter rollups to a specific metric UUID. */\n metric_id?: string\n /**\n * Lower bound for `period_start` (ISO 8601).\n * Defaults to the start of the current billing period.\n */\n from?: string | Date\n /**\n * Exclusive upper bound for `period_start` (ISO 8601).\n * Defaults to the end of the current billing period.\n */\n to?: string | Date\n}\n\nexport interface UsageQueryResult {\n rollups: UsageRollup[]\n count: number\n}\n"],"names":[],"mappings":";;AAcO,MAAM,uBAAuB,MAAM;AAAA,EAQxC,YACE,YACA,SACA,SACA;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,UAAU;AACf,SAAK,UAAU;AAEf,UAAM,UAAW,MACf,mBACF;AACA,cAAU,MAAM,cAAc;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,aAAsB;AACxB,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAEA,IAAI,iBAA0B;AAC5B,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAEA,IAAI,cAAuB;AACzB,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAEA,IAAI,gBAAyB;AAC3B,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAEA,IAAI,aAAsB;AACxB,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAEA,IAAI,kBAA2B;AAC7B,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAEA,IAAI,gBAAyB;AAC3B,WAAO,KAAK,cAAc;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,WAAW,KAAqC;AACrD,WAAO,eAAe,kBAAkB,IAAI,eAAe;AAAA,EAC7D;AAAA,EAEA,OAAO,eAAe,KAAqC;AACzD,WAAO,eAAe,kBAAkB,IAAI,eAAe;AAAA,EAC7D;AAAA,EAEA,OAAO,YAAY,KAAqC;AACtD,WAAO,eAAe,kBAAkB,IAAI,eAAe;AAAA,EAC7D;AAAA,EAEA,OAAO,cAAc,KAAqC;AACxD,WAAO,eAAe,kBAAkB,IAAI,eAAe;AAAA,EAC7D;AAAA,EAEA,OAAO,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B,YAAY;AAAA,EACZ,QAAQ;AACV;AAIO,MAAM,gBAAgB;AAAA,EAC3B,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AACZ;AAQO,MAAM,qBAAqB;AAAA,EAChC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AACZ;AAQO,MAAM,gBAAgB;AAAA,EAC3B,OAAO;AAAA,EACP,WAAW;AAAA,EACX,MAAM;AAAA,EACN,MAAM;AACR;AAQO,MAAM,eAAe;AAAA,EAC1B,cAAc;AAAA,EACd,aAAa;AACf;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"monigo.cjs","sources":["../src/errors.ts","../src/resources/events.ts","../src/resources/customers.ts","../src/resources/metrics.ts","../src/resources/plans.ts","../src/resources/subscriptions.ts","../src/resources/payout-accounts.ts","../src/resources/invoices.ts","../src/resources/usage.ts","../src/client.ts","../src/types.ts"],"sourcesContent":["/**\n * Thrown for any non-2xx response from the Monigo API.\n *\n * @example\n * ```ts\n * try {\n * await client.customers.get('bad-id')\n * } catch (err) {\n * if (MonigoAPIError.isNotFound(err)) {\n * console.log('Customer does not exist')\n * }\n * }\n * ```\n */\nexport class MonigoAPIError extends Error {\n /** HTTP status code returned by the API. */\n readonly statusCode: number\n /** Human-readable error message from the API. */\n readonly message: string\n /** Optional structured field-level validation details. */\n readonly details: Record<string, string> | undefined\n\n constructor(\n statusCode: number,\n message: string,\n details?: Record<string, string>,\n ) {\n super(message)\n this.name = 'MonigoAPIError'\n this.statusCode = statusCode\n this.message = message\n this.details = details\n // Maintain proper stack trace in V8 (Node.js / Chrome)\n const capture = (Error as unknown as Record<string, unknown>)[\n 'captureStackTrace'\n ] as ((target: Error, constructor: Function) => void) | undefined\n capture?.(this, MonigoAPIError)\n }\n\n // -------------------------------------------------------------------------\n // Instance guards (for use on a caught error known to be MonigoAPIError)\n // -------------------------------------------------------------------------\n\n get isNotFound(): boolean {\n return this.statusCode === 404\n }\n\n get isUnauthorized(): boolean {\n return this.statusCode === 401\n }\n\n get isForbidden(): boolean {\n return this.statusCode === 403\n }\n\n get isRateLimited(): boolean {\n return this.statusCode === 429\n }\n\n get isConflict(): boolean {\n return this.statusCode === 409\n }\n\n get isQuotaExceeded(): boolean {\n return this.statusCode === 402\n }\n\n get isServerError(): boolean {\n return this.statusCode >= 500\n }\n\n // -------------------------------------------------------------------------\n // Static type-narrowing helpers (for use in catch clauses on `unknown`)\n // -------------------------------------------------------------------------\n\n static isNotFound(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 404\n }\n\n static isUnauthorized(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 401\n }\n\n static isForbidden(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 403\n }\n\n static isRateLimited(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 429\n }\n\n static isConflict(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 409\n }\n\n static isQuotaExceeded(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 402\n }\n\n static isServerError(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode >= 500\n }\n}\n","import { MonigoClient } from '../client.js'\nimport type { MutationOptions } from '../client.js'\nimport type {\n IngestRequest,\n IngestResponse,\n StartReplayRequest,\n EventReplayJob,\n} from '../types.js'\n\n/** Handles usage event ingestion and asynchronous event replay. */\nexport class EventsResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Ingest one or more usage events into the Monigo pipeline.\n *\n * Events are processed asynchronously. The response confirms receipt\n * and reports any duplicate idempotency keys.\n *\n * **Requires `ingest` scope.**\n *\n * @example\n * ```ts\n * const result = await monigo.events.ingest({\n * events: [{\n * event_name: 'api_call',\n * customer_id: 'cust_abc',\n * idempotency_key: crypto.randomUUID(),\n * timestamp: new Date().toISOString(),\n * properties: { endpoint: '/checkout', region: 'eu-west-1' },\n * }],\n * })\n * console.log('Ingested:', result.ingested.length)\n * console.log('Duplicates:', result.duplicates.length)\n * ```\n */\n async ingest(request: IngestRequest, options?: MutationOptions): Promise<IngestResponse> {\n const body = {\n events: request.events.map((e) => ({\n ...e,\n timestamp: e.timestamp\n ? MonigoClient.toISOString(e.timestamp)\n : new Date().toISOString(),\n })),\n }\n return this.client._request<IngestResponse>('POST', '/v1/ingest', {\n body,\n idempotencyKey: options?.idempotencyKey,\n })\n }\n\n /**\n * Start an asynchronous replay of all raw events in a given time window\n * through the current processing pipeline. Useful for backfilling usage\n * data after changing metric definitions.\n *\n * Returns a replay job immediately — poll `getReplay()` to track progress.\n *\n * **Requires `ingest` scope.**\n *\n * @example\n * ```ts\n * const job = await monigo.events.startReplay({\n * from: '2025-01-01T00:00:00Z',\n * to: '2025-01-31T23:59:59Z',\n * event_name: 'api_call', // omit to replay all event types\n * })\n * console.log('Replay job:', job.id, job.status)\n * ```\n */\n async startReplay(request: StartReplayRequest, options?: MutationOptions): Promise<EventReplayJob> {\n const body = {\n from: MonigoClient.toISOString(request.from),\n to: MonigoClient.toISOString(request.to),\n ...(request.event_name ? { event_name: request.event_name } : {}),\n }\n const wrapper = await this.client._request<{ job: EventReplayJob }>(\n 'POST',\n '/v1/events/replay',\n { body, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.job\n }\n\n /**\n * Fetch the current status and progress of an event replay job.\n *\n * **Requires `ingest` scope.**\n *\n * @example\n * ```ts\n * const job = await monigo.events.getReplay(jobId)\n * if (job.status === 'completed') {\n * console.log(`Replayed ${job.events_replayed} / ${job.events_total} events`)\n * }\n * ```\n */\n async getReplay(jobId: string): Promise<EventReplayJob> {\n const wrapper = await this.client._request<{ job: EventReplayJob }>(\n 'GET',\n `/v1/events/replay/${jobId}`,\n )\n return wrapper.job\n }\n}\n","import type { MonigoClient, MutationOptions } from '../client.js'\nimport type {\n Customer,\n CreateCustomerRequest,\n UpdateCustomerRequest,\n ListCustomersResponse,\n} from '../types.js'\n\n/** Manage end-customers in your Monigo organisation. */\nexport class CustomersResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Register a new customer.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const customer = await monigo.customers.create({\n * external_id: 'usr_12345',\n * name: 'Acme Corp',\n * email: 'billing@acme.com',\n * metadata: { plan_tier: 'enterprise' },\n * })\n * ```\n */\n async create(request: CreateCustomerRequest, options?: MutationOptions): Promise<Customer> {\n const wrapper = await this.client._request<{ customer: Customer }>(\n 'POST',\n '/v1/customers',\n { body: request, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.customer\n }\n\n /**\n * Return all customers in the authenticated organisation.\n *\n * **Requires `read` scope.**\n */\n async list(): Promise<ListCustomersResponse> {\n return this.client._request<ListCustomersResponse>('GET', '/v1/customers')\n }\n\n /**\n * Fetch a single customer by their Monigo UUID.\n *\n * **Requires `read` scope.**\n */\n async get(customerId: string): Promise<Customer> {\n const wrapper = await this.client._request<{ customer: Customer }>(\n 'GET',\n `/v1/customers/${customerId}`,\n )\n return wrapper.customer\n }\n\n /**\n * Update a customer's name, email, or metadata.\n * Only fields that are present in `request` are updated.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const updated = await monigo.customers.update(customerId, {\n * email: 'new@acme.com',\n * })\n * ```\n */\n async update(\n customerId: string,\n request: UpdateCustomerRequest,\n options?: MutationOptions,\n ): Promise<Customer> {\n const wrapper = await this.client._request<{ customer: Customer }>(\n 'PUT',\n `/v1/customers/${customerId}`,\n { body: request, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.customer\n }\n\n /**\n * Permanently delete a customer record.\n *\n * **Requires `write` scope.**\n */\n async delete(customerId: string): Promise<void> {\n await this.client._request<void>('DELETE', `/v1/customers/${customerId}`)\n }\n}\n","import type { MonigoClient, MutationOptions } from '../client.js'\nimport type {\n Metric,\n CreateMetricRequest,\n UpdateMetricRequest,\n ListMetricsResponse,\n} from '../types.js'\n\n/** Manage billing metrics — what usage gets counted and how it is aggregated. */\nexport class MetricsResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Create a new metric.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const metric = await monigo.metrics.create({\n * name: 'API Calls',\n * event_name: 'api_call',\n * aggregation: 'count',\n * })\n * ```\n */\n async create(request: CreateMetricRequest, options?: MutationOptions): Promise<Metric> {\n const wrapper = await this.client._request<{ metric: Metric }>(\n 'POST',\n '/v1/metrics',\n { body: request, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.metric\n }\n\n /**\n * Return all metrics in the authenticated organisation.\n *\n * **Requires `read` scope.**\n */\n async list(): Promise<ListMetricsResponse> {\n return this.client._request<ListMetricsResponse>('GET', '/v1/metrics')\n }\n\n /**\n * Fetch a single metric by its UUID.\n *\n * **Requires `read` scope.**\n */\n async get(metricId: string): Promise<Metric> {\n const wrapper = await this.client._request<{ metric: Metric }>(\n 'GET',\n `/v1/metrics/${metricId}`,\n )\n return wrapper.metric\n }\n\n /**\n * Update a metric's name, event name, aggregation, or description.\n *\n * **Requires `write` scope.**\n */\n async update(metricId: string, request: UpdateMetricRequest, options?: MutationOptions): Promise<Metric> {\n const wrapper = await this.client._request<{ metric: Metric }>(\n 'PUT',\n `/v1/metrics/${metricId}`,\n { body: request, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.metric\n }\n\n /**\n * Permanently delete a metric.\n *\n * **Requires `write` scope.**\n */\n async delete(metricId: string): Promise<void> {\n await this.client._request<void>('DELETE', `/v1/metrics/${metricId}`)\n }\n}\n","import type { MonigoClient, MutationOptions } from '../client.js'\nimport type {\n Plan,\n CreatePlanRequest,\n UpdatePlanRequest,\n ListPlansResponse,\n} from '../types.js'\n\n/** Manage billing plans and their prices. */\nexport class PlansResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Create a new billing plan, optionally with prices attached.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const plan = await monigo.plans.create({\n * name: 'Pro',\n * currency: 'NGN',\n * billing_period: 'monthly',\n * prices: [{\n * metric_id: 'metric_abc',\n * model: 'flat',\n * unit_price: '2.500000',\n * }],\n * })\n * ```\n */\n async create(request: CreatePlanRequest, options?: MutationOptions): Promise<Plan> {\n const wrapper = await this.client._request<{ plan: Plan }>(\n 'POST',\n '/v1/plans',\n { body: request, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.plan\n }\n\n /**\n * Return all billing plans in the authenticated organisation.\n *\n * **Requires `read` scope.**\n */\n async list(): Promise<ListPlansResponse> {\n return this.client._request<ListPlansResponse>('GET', '/v1/plans')\n }\n\n /**\n * Fetch a single plan by its UUID, including its prices.\n *\n * **Requires `read` scope.**\n */\n async get(planId: string): Promise<Plan> {\n const wrapper = await this.client._request<{ plan: Plan }>(\n 'GET',\n `/v1/plans/${planId}`,\n )\n return wrapper.plan\n }\n\n /**\n * Update a plan's name, description, currency, or prices.\n *\n * **Requires `write` scope.**\n */\n async update(planId: string, request: UpdatePlanRequest, options?: MutationOptions): Promise<Plan> {\n const wrapper = await this.client._request<{ plan: Plan }>(\n 'PUT',\n `/v1/plans/${planId}`,\n { body: request, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.plan\n }\n\n /**\n * Permanently delete a plan.\n *\n * **Requires `write` scope.**\n */\n async delete(planId: string): Promise<void> {\n await this.client._request<void>('DELETE', `/v1/plans/${planId}`)\n }\n}\n","import type { MonigoClient, MutationOptions } from '../client.js'\nimport type {\n Subscription,\n CreateSubscriptionRequest,\n ListSubscriptionsParams,\n ListSubscriptionsResponse,\n SubscriptionStatusValue,\n} from '../types.js'\n\n/** Link customers to billing plans and manage subscription lifecycle. */\nexport class SubscriptionsResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Subscribe a customer to a plan.\n *\n * Returns a 409 Conflict error (check with `MonigoAPIError.isConflict(err)`)\n * if the customer already has an active subscription to the same plan.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const sub = await monigo.subscriptions.create({\n * customer_id: 'cust_abc',\n * plan_id: 'plan_xyz',\n * })\n * ```\n */\n async create(request: CreateSubscriptionRequest, options?: MutationOptions): Promise<Subscription> {\n const wrapper = await this.client._request<{ subscription: Subscription }>(\n 'POST',\n '/v1/subscriptions',\n { body: request, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.subscription\n }\n\n /**\n * Return subscriptions, optionally filtered by customer, plan, or status.\n *\n * **Requires `read` scope.**\n *\n * @example\n * ```ts\n * const { subscriptions } = await monigo.subscriptions.list({\n * customer_id: 'cust_abc',\n * status: 'active',\n * })\n * ```\n */\n async list(params: ListSubscriptionsParams = {}): Promise<ListSubscriptionsResponse> {\n return this.client._request<ListSubscriptionsResponse>('GET', '/v1/subscriptions', {\n query: {\n customer_id: params.customer_id,\n plan_id: params.plan_id,\n status: params.status,\n },\n })\n }\n\n /**\n * Fetch a single subscription by its UUID.\n *\n * **Requires `read` scope.**\n */\n async get(subscriptionId: string): Promise<Subscription> {\n const wrapper = await this.client._request<{ subscription: Subscription }>(\n 'GET',\n `/v1/subscriptions/${subscriptionId}`,\n )\n return wrapper.subscription\n }\n\n /**\n * Change the status of a subscription.\n * Use `SubscriptionStatus` constants: `\"active\"`, `\"paused\"`, `\"canceled\"`.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * await monigo.subscriptions.updateStatus(subId, SubscriptionStatus.Paused)\n * ```\n */\n async updateStatus(\n subscriptionId: string,\n status: SubscriptionStatusValue,\n options?: MutationOptions,\n ): Promise<Subscription> {\n const wrapper = await this.client._request<{ subscription: Subscription }>(\n 'PATCH',\n `/v1/subscriptions/${subscriptionId}`,\n { body: { status }, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.subscription\n }\n\n /**\n * Cancel and delete a subscription record.\n *\n * **Requires `write` scope.**\n */\n async delete(subscriptionId: string): Promise<void> {\n await this.client._request<void>('DELETE', `/v1/subscriptions/${subscriptionId}`)\n }\n}\n","import type { MonigoClient, MutationOptions } from '../client.js'\nimport type {\n PayoutAccount,\n CreatePayoutAccountRequest,\n UpdatePayoutAccountRequest,\n ListPayoutAccountsResponse,\n} from '../types.js'\n\n/** Manage bank and mobile-money payout accounts for customers. */\nexport class PayoutAccountsResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Add a payout account for a customer.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const account = await monigo.payoutAccounts.create('cust_abc', {\n * account_name: 'Acme Corp',\n * payout_method: 'bank_transfer',\n * bank_name: 'Zenith Bank',\n * bank_code: '057',\n * account_number: '1234567890',\n * currency: 'NGN',\n * is_default: true,\n * })\n * ```\n */\n async create(\n customerId: string,\n request: CreatePayoutAccountRequest,\n options?: MutationOptions,\n ): Promise<PayoutAccount> {\n const wrapper = await this.client._request<{ payout_account: PayoutAccount }>(\n 'POST',\n `/v1/customers/${customerId}/payout-accounts`,\n { body: request, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.payout_account\n }\n\n /**\n * Return all payout accounts for a customer.\n *\n * **Requires `read` scope.**\n */\n async list(customerId: string): Promise<ListPayoutAccountsResponse> {\n return this.client._request<ListPayoutAccountsResponse>(\n 'GET',\n `/v1/customers/${customerId}/payout-accounts`,\n )\n }\n\n /**\n * Fetch a single payout account by its UUID.\n *\n * **Requires `read` scope.**\n */\n async get(customerId: string, accountId: string): Promise<PayoutAccount> {\n const wrapper = await this.client._request<{ payout_account: PayoutAccount }>(\n 'GET',\n `/v1/customers/${customerId}/payout-accounts/${accountId}`,\n )\n return wrapper.payout_account\n }\n\n /**\n * Update a payout account's details.\n *\n * **Requires `write` scope.**\n */\n async update(\n customerId: string,\n accountId: string,\n request: UpdatePayoutAccountRequest,\n options?: MutationOptions,\n ): Promise<PayoutAccount> {\n const wrapper = await this.client._request<{ payout_account: PayoutAccount }>(\n 'PUT',\n `/v1/customers/${customerId}/payout-accounts/${accountId}`,\n { body: request, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.payout_account\n }\n\n /**\n * Delete a payout account.\n *\n * **Requires `write` scope.**\n */\n async delete(customerId: string, accountId: string): Promise<void> {\n await this.client._request<void>(\n 'DELETE',\n `/v1/customers/${customerId}/payout-accounts/${accountId}`,\n )\n }\n}\n","import type { MonigoClient, MutationOptions } from '../client.js'\nimport type {\n Invoice,\n ListInvoicesParams,\n ListInvoicesResponse,\n} from '../types.js'\n\n/** Manage invoice generation, finalization, and voiding. */\nexport class InvoicesResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Generate a draft invoice for a subscription based on current period usage.\n * The invoice starts in `\"draft\"` status and is not sent to the customer yet.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const invoice = await monigo.invoices.generate('sub_xyz')\n * console.log('Draft invoice total:', invoice.total)\n * ```\n */\n async generate(subscriptionId: string, options?: MutationOptions): Promise<Invoice> {\n const wrapper = await this.client._request<{ invoice: Invoice }>(\n 'POST',\n '/v1/invoices/generate',\n { body: { subscription_id: subscriptionId }, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.invoice\n }\n\n /**\n * Return invoices, optionally filtered by status or customer.\n *\n * **Requires `read` scope.**\n *\n * @example\n * ```ts\n * const { invoices } = await monigo.invoices.list({\n * status: 'finalized',\n * customer_id: 'cust_abc',\n * })\n * ```\n */\n async list(params: ListInvoicesParams = {}): Promise<ListInvoicesResponse> {\n return this.client._request<ListInvoicesResponse>('GET', '/v1/invoices', {\n query: {\n status: params.status,\n customer_id: params.customer_id,\n },\n })\n }\n\n /**\n * Fetch a single invoice by its UUID, including line items.\n *\n * **Requires `read` scope.**\n */\n async get(invoiceId: string): Promise<Invoice> {\n const wrapper = await this.client._request<{ invoice: Invoice }>(\n 'GET',\n `/v1/invoices/${invoiceId}`,\n )\n return wrapper.invoice\n }\n\n /**\n * Finalize a draft invoice, making it ready for payment.\n * A finalized invoice cannot be edited.\n *\n * **Requires `write` scope.**\n */\n async finalize(invoiceId: string, options?: MutationOptions): Promise<Invoice> {\n const wrapper = await this.client._request<{ invoice: Invoice }>(\n 'POST',\n `/v1/invoices/${invoiceId}/finalize`,\n { idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.invoice\n }\n\n /**\n * Void an invoice, making it permanently non-payable.\n * Only admins and owners can void invoices.\n *\n * **Requires `write` scope.**\n */\n async void(invoiceId: string, options?: MutationOptions): Promise<Invoice> {\n const wrapper = await this.client._request<{ invoice: Invoice }>(\n 'POST',\n `/v1/invoices/${invoiceId}/void`,\n { idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.invoice\n }\n}\n","import { MonigoClient } from '../client.js'\nimport type { UsageQueryParams, UsageQueryResult } from '../types.js'\n\n/** Query aggregated usage rollups from the Monigo metering pipeline. */\nexport class UsageResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Return per-customer, per-metric usage rollups for the organisation.\n * All parameters are optional — omitting them returns the full current\n * billing period for all customers and metrics.\n *\n * **Requires `read` scope.**\n *\n * @example\n * ```ts\n * // All usage for one customer this period\n * const { rollups } = await monigo.usage.query({\n * customer_id: 'cust_abc',\n * })\n *\n * // Filtered by metric and custom date range\n * const { rollups: filtered } = await monigo.usage.query({\n * metric_id: 'metric_xyz',\n * from: '2025-01-01T00:00:00Z',\n * to: '2025-01-31T23:59:59Z',\n * })\n * ```\n */\n async query(params: UsageQueryParams = {}): Promise<UsageQueryResult> {\n const query: Record<string, string | undefined> = {\n customer_id: params.customer_id,\n metric_id: params.metric_id,\n }\n if (params.from !== undefined) {\n query.from = MonigoClient.toISOString(params.from)\n }\n if (params.to !== undefined) {\n query.to = MonigoClient.toISOString(params.to)\n }\n return this.client._request<UsageQueryResult>('GET', '/v1/usage', { query })\n }\n}\n","import { MonigoAPIError } from './errors.js'\nimport { EventsResource } from './resources/events.js'\nimport { CustomersResource } from './resources/customers.js'\nimport { MetricsResource } from './resources/metrics.js'\nimport { PlansResource } from './resources/plans.js'\nimport { SubscriptionsResource } from './resources/subscriptions.js'\nimport { PayoutAccountsResource } from './resources/payout-accounts.js'\nimport { InvoicesResource } from './resources/invoices.js'\nimport { UsageResource } from './resources/usage.js'\n\nconst DEFAULT_BASE_URL = 'https://api.monigo.co'\nconst DEFAULT_TIMEOUT_MS = 30_000\n\nexport interface MonigoClientOptions {\n /**\n * Your Monigo API key. Obtain one from the API Keys section of your\n * Monigo dashboard. Never expose this key in client-side code.\n */\n apiKey: string\n /**\n * Override the default API base URL (`https://api.monigo.co`).\n * Useful for self-hosted deployments or pointing at a local dev server.\n *\n * @default \"https://api.monigo.co\"\n */\n baseURL?: string\n /**\n * Custom `fetch` implementation. Defaults to `globalThis.fetch`.\n * Pass a polyfill for environments that do not have native fetch\n * (Node.js < 18) or to inject a mock in tests.\n */\n fetch?: typeof globalThis.fetch\n /**\n * Request timeout in milliseconds.\n *\n * @default 30000\n */\n timeout?: number\n}\n\n/**\n * Options accepted by every mutating method (POST, PUT, PATCH).\n */\nexport interface MutationOptions {\n /**\n * A unique key that prevents the same request from being processed more than\n * once. Pass a stable value (e.g. a request ID from your own system) to make\n * retries safe. When omitted, the SDK generates a UUID v4 automatically.\n */\n idempotencyKey?: string\n}\n\n/** @internal */\nexport interface RequestOptions {\n body?: unknown\n query?: Record<string, string | undefined>\n idempotencyKey?: string\n}\n\n/**\n * The Monigo API client.\n *\n * Instantiate once and reuse across your application:\n *\n * ```ts\n * import { MonigoClient } from '@monigo/sdk'\n *\n * const monigo = new MonigoClient({ apiKey: process.env.MONIGO_API_KEY! })\n *\n * // Ingest a usage event\n * await monigo.events.ingest({\n * events: [{\n * event_name: 'api_call',\n * customer_id: 'cust_abc123',\n * idempotency_key: crypto.randomUUID(),\n * }],\n * })\n * ```\n */\nexport class MonigoClient {\n /** @internal */\n readonly _apiKey: string\n /** @internal */\n readonly _baseURL: string\n /** @internal */\n readonly _fetchFn: typeof globalThis.fetch\n /** @internal */\n readonly _timeout: number\n\n /** Ingest usage events and manage event replays. Requires `ingest` scope. */\n readonly events: EventsResource\n /** Manage your end-customers (CRUD). Requires `read` / `write` scope. */\n readonly customers: CustomersResource\n /** Manage billing metrics — what gets counted and how. Requires `read` / `write` scope. */\n readonly metrics: MetricsResource\n /** Manage billing plans and their prices. Requires `read` / `write` scope. */\n readonly plans: PlansResource\n /** Link customers to plans and manage subscription lifecycle. Requires `read` / `write` scope. */\n readonly subscriptions: SubscriptionsResource\n /** Manage bank / mobile-money payout accounts for customers. Requires `read` / `write` scope. */\n readonly payoutAccounts: PayoutAccountsResource\n /** Generate, list, finalize, and void invoices. Requires `read` / `write` scope. */\n readonly invoices: InvoicesResource\n /** Query aggregated usage rollups per customer and metric. Requires `read` scope. */\n readonly usage: UsageResource\n\n constructor(options: MonigoClientOptions) {\n if (!options.apiKey) {\n throw new Error('MonigoClient: apiKey is required')\n }\n\n this._apiKey = options.apiKey\n this._baseURL = (options.baseURL ?? DEFAULT_BASE_URL).replace(/\\/$/, '')\n this._timeout = options.timeout ?? DEFAULT_TIMEOUT_MS\n\n const fetchFn = options.fetch ?? (typeof globalThis !== 'undefined' ? globalThis.fetch : undefined)\n if (!fetchFn) {\n throw new Error(\n 'MonigoClient: fetch is not available in this environment. ' +\n 'Pass a custom fetch implementation via options.fetch, ' +\n 'or upgrade to Node.js 18+.',\n )\n }\n this._fetchFn = fetchFn.bind(globalThis)\n\n this.events = new EventsResource(this)\n this.customers = new CustomersResource(this)\n this.metrics = new MetricsResource(this)\n this.plans = new PlansResource(this)\n this.subscriptions = new SubscriptionsResource(this)\n this.payoutAccounts = new PayoutAccountsResource(this)\n this.invoices = new InvoicesResource(this)\n this.usage = new UsageResource(this)\n }\n\n /**\n * Execute an authenticated HTTP request against the Monigo API.\n * @internal — use the resource methods instead.\n */\n async _request<T>(\n method: string,\n path: string,\n options: RequestOptions = {},\n ): Promise<T> {\n let url = this._baseURL + path\n\n if (options.query) {\n const params = new URLSearchParams()\n for (const [key, value] of Object.entries(options.query)) {\n if (value !== undefined && value !== '') {\n params.set(key, value)\n }\n }\n const qs = params.toString()\n if (qs) url += '?' + qs\n }\n\n const controller = new AbortController()\n const timeoutId = setTimeout(() => controller.abort(), this._timeout)\n\n const isMutating = method === 'POST' || method === 'PUT' || method === 'PATCH'\n const idempotencyKey = isMutating\n ? (options.idempotencyKey ?? globalThis.crypto.randomUUID())\n : undefined\n\n try {\n const response = await this._fetchFn(url, {\n method,\n headers: {\n Authorization: `Bearer ${this._apiKey}`,\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n ...(idempotencyKey ? { 'Idempotency-Key': idempotencyKey } : {}),\n },\n body: options.body != null ? JSON.stringify(options.body) : undefined,\n signal: controller.signal,\n })\n\n const text = await response.text()\n\n if (!response.ok) {\n let message = text || response.statusText\n let details: Record<string, string> | undefined\n try {\n const parsed = JSON.parse(text) as {\n error?: string\n message?: string\n details?: Record<string, string>\n }\n message = parsed.error ?? parsed.message ?? message\n details = parsed.details\n } catch {\n // Use raw text as the error message\n }\n throw new MonigoAPIError(response.status, message, details)\n }\n\n if (!text) return undefined as T\n return JSON.parse(text) as T\n } catch (err) {\n if (err instanceof MonigoAPIError) throw err\n if (err instanceof Error && err.name === 'AbortError') {\n throw new Error(\n `MonigoClient: request to ${url} timed out after ${this._timeout}ms`,\n )\n }\n throw err\n } finally {\n clearTimeout(timeoutId)\n }\n }\n\n /** Normalise a `Date | string` value to an ISO 8601 string. */\n static toISOString(value: string | Date): string {\n return value instanceof Date ? value.toISOString() : value\n }\n}\n","// =============================================================================\n// Aggregation constants\n// =============================================================================\n\nexport const Aggregation = {\n Count: 'count',\n Sum: 'sum',\n Max: 'max',\n Min: 'minimum',\n Average: 'average',\n Unique: 'unique',\n} as const\n\nexport type AggregationType = (typeof Aggregation)[keyof typeof Aggregation]\n\n// =============================================================================\n// Pricing model constants\n// =============================================================================\n\nexport const PricingModel = {\n Flat: 'flat',\n Tiered: 'tiered',\n Volume: 'volume',\n Package: 'package',\n Overage: 'overage',\n WeightedTiered: 'weighted_tiered',\n} as const\n\nexport type PricingModelType = (typeof PricingModel)[keyof typeof PricingModel]\n\n// =============================================================================\n// Plan constants\n// =============================================================================\n\nexport const PlanType = {\n Collection: 'collection',\n Payout: 'payout',\n} as const\n\nexport type PlanTypeValue = (typeof PlanType)[keyof typeof PlanType]\n\nexport const BillingPeriod = {\n Daily: 'daily',\n Weekly: 'weekly',\n Monthly: 'monthly',\n Quarterly: 'quarterly',\n Annually: 'annually',\n} as const\n\nexport type BillingPeriodValue = (typeof BillingPeriod)[keyof typeof BillingPeriod]\n\n// =============================================================================\n// Subscription status constants\n// =============================================================================\n\nexport const SubscriptionStatus = {\n Active: 'active',\n Paused: 'paused',\n Canceled: 'canceled',\n} as const\n\nexport type SubscriptionStatusValue = (typeof SubscriptionStatus)[keyof typeof SubscriptionStatus]\n\n// =============================================================================\n// Invoice status constants\n// =============================================================================\n\nexport const InvoiceStatus = {\n Draft: 'draft',\n Finalized: 'finalized',\n Paid: 'paid',\n Void: 'void',\n} as const\n\nexport type InvoiceStatusValue = (typeof InvoiceStatus)[keyof typeof InvoiceStatus]\n\n// =============================================================================\n// Payout method constants\n// =============================================================================\n\nexport const PayoutMethod = {\n BankTransfer: 'bank_transfer',\n MobileMoney: 'mobile_money',\n} as const\n\nexport type PayoutMethodValue = (typeof PayoutMethod)[keyof typeof PayoutMethod]\n\n// =============================================================================\n// Events\n// =============================================================================\n\n/** A single usage event sent to the Monigo ingestion pipeline. */\nexport interface IngestEvent {\n /**\n * The name of the event, e.g. `\"api_call\"` or `\"storage.write\"`.\n * Must match the `event_name` on one or more metrics you have configured.\n */\n event_name: string\n /** The Monigo customer UUID this event belongs to. */\n customer_id: string\n /**\n * A unique key for this event. Re-sending the same key is safe — the server\n * will de-duplicate automatically. Use a UUID or any stable ID you control.\n */\n idempotency_key: string\n /**\n * ISO 8601 timestamp for when the event occurred. Backdated events are\n * accepted within the configured replay window. Defaults to now if omitted.\n */\n timestamp?: string | Date\n /**\n * Arbitrary key-value pairs attached to the event. Use these for dimensions\n * such as `{ endpoint: \"/checkout\", region: \"eu-west-1\" }`.\n */\n properties?: Record<string, unknown>\n}\n\n/** Request body for `POST /v1/ingest`. */\nexport interface IngestRequest {\n events: IngestEvent[]\n}\n\n/** Response from `POST /v1/ingest`. */\nexport interface IngestResponse {\n /** Idempotency keys of events that were successfully ingested. */\n ingested: string[]\n /** Idempotency keys that were skipped because they already existed. */\n duplicates: string[]\n}\n\n/** Request body for `POST /v1/events/replay`. */\nexport interface StartReplayRequest {\n /** Start of the replay window (ISO 8601). */\n from: string | Date\n /** End of the replay window (ISO 8601). */\n to: string | Date\n /** Optional event name to replay. Omit to replay all event types. */\n event_name?: string\n}\n\n/** Tracks the progress of an asynchronous event replay job. */\nexport interface EventReplayJob {\n id: string\n org_id: string\n initiated_by: string\n /** `pending` | `processing` | `completed` | `failed` */\n status: string\n from_timestamp: string\n to_timestamp: string\n event_name: string | null\n is_test: boolean\n events_total: number\n events_replayed: number\n error_message: string | null\n started_at: string | null\n completed_at: string | null\n created_at: string\n updated_at: string\n}\n\n// =============================================================================\n// Customers\n// =============================================================================\n\n/** An end-customer record in your Monigo organisation. */\nexport interface Customer {\n id: string\n org_id: string\n /** The ID for this customer in your own system. */\n external_id: string\n name: string\n email: string\n /** Phone number in E.164 international format (e.g. +2348012345678). */\n phone: string\n /** Arbitrary JSON metadata. */\n metadata: Record<string, unknown> | null\n created_at: string\n updated_at: string\n}\n\nexport interface CreateCustomerRequest {\n /** Your internal ID for this customer. */\n external_id: string\n name: string\n email?: string\n /** Phone number in E.164 international format (e.g. +2348012345678). Optional. */\n phone?: string\n metadata?: Record<string, unknown>\n}\n\nexport interface UpdateCustomerRequest {\n name?: string\n email?: string\n /** Phone number in E.164 international format (e.g. +2348012345678). Optional. */\n phone?: string\n metadata?: Record<string, unknown>\n}\n\nexport interface ListCustomersResponse {\n customers: Customer[]\n count: number\n}\n\n// =============================================================================\n// Metrics\n// =============================================================================\n\n/** Defines what usage is counted and how. */\nexport interface Metric {\n id: string\n org_id: string\n name: string\n /** The `event_name` value that this metric tracks. */\n event_name: string\n /** How events are aggregated. Use `Aggregation` constants. */\n aggregation: AggregationType\n /** For sum/max/min/average: the Properties key whose value is used. */\n aggregation_property?: string\n description?: string\n created_at: string\n updated_at: string\n}\n\nexport interface CreateMetricRequest {\n /** Human-readable label, e.g. `\"API Calls\"`. */\n name: string\n /** The `event_name` value to track. */\n event_name: string\n /** How events are aggregated. Use `Aggregation` constants. */\n aggregation: AggregationType\n description?: string\n /** Required for sum/max/min/average aggregations. */\n aggregation_property?: string\n}\n\nexport interface UpdateMetricRequest {\n name?: string\n event_name?: string\n aggregation?: AggregationType\n description?: string\n aggregation_property?: string\n}\n\nexport interface ListMetricsResponse {\n metrics: Metric[]\n count: number\n}\n\n// =============================================================================\n// Plans & Prices\n// =============================================================================\n\n/**\n * One price step in a tiered/volume/weighted_tiered pricing model.\n * Set `up_to` to `null` for the final (infinite) tier.\n */\nexport interface PriceTier {\n up_to: number | null\n /** Price per unit in this tier as a decimal string, e.g. `\"0.50\"`. */\n unit_amount: string\n}\n\n/** Describes a price to attach when creating a plan. */\nexport interface CreatePriceRequest {\n /** UUID of the metric this price is based on. */\n metric_id: string\n /** Pricing model. Use `PricingModel` constants. */\n model: PricingModelType\n /** Flat price per unit as a decimal string (used for flat/overage/package models). */\n unit_price?: string\n /** Price tiers for tiered/volume/weighted_tiered models. */\n tiers?: PriceTier[]\n}\n\n/** Describes an updated price. Include `id` to update an existing price; omit to add a new one. */\nexport interface UpdatePriceRequest {\n id?: string\n metric_id?: string\n model?: PricingModelType\n unit_price?: string\n tiers?: PriceTier[]\n}\n\n/** A pricing rule attached to a plan. */\nexport interface Price {\n id: string\n plan_id: string\n metric_id: string\n model: PricingModelType\n unit_price: string\n tiers: PriceTier[] | null\n created_at: string\n updated_at: string\n}\n\n/** A billing plan that defines pricing for one or more metrics. */\nexport interface Plan {\n id: string\n org_id: string\n name: string\n description?: string\n /** ISO 4217 currency code, e.g. `\"NGN\"`. */\n currency: string\n /** Use `PlanType` constants. */\n plan_type: PlanTypeValue\n /** Use `BillingPeriod` constants. */\n billing_period: BillingPeriodValue\n trial_period_days: number\n prices?: Price[]\n created_at: string\n updated_at: string\n}\n\nexport interface CreatePlanRequest {\n name: string\n description?: string\n /** ISO 4217 currency code. Defaults to `\"NGN\"`. */\n currency?: string\n /** Use `PlanType` constants. Defaults to `\"collection\"`. */\n plan_type?: PlanTypeValue\n /** Use `BillingPeriod` constants. Defaults to `\"monthly\"`. */\n billing_period?: BillingPeriodValue\n /** Trial period in days. Set to `0` for no trial. */\n trial_period_days?: number\n prices?: CreatePriceRequest[]\n}\n\nexport interface UpdatePlanRequest {\n name?: string\n description?: string\n currency?: string\n plan_type?: PlanTypeValue\n billing_period?: BillingPeriodValue\n prices?: UpdatePriceRequest[]\n}\n\nexport interface ListPlansResponse {\n plans: Plan[]\n count: number\n}\n\n// =============================================================================\n// Subscriptions\n// =============================================================================\n\n/** Links a customer to a billing plan. */\nexport interface Subscription {\n id: string\n org_id: string\n customer_id: string\n plan_id: string\n /** Use `SubscriptionStatus` constants. */\n status: SubscriptionStatusValue\n current_period_start: string\n current_period_end: string\n trial_ends_at: string | null\n created_at: string\n updated_at: string\n}\n\nexport interface CreateSubscriptionRequest {\n /** UUID of the customer to subscribe. */\n customer_id: string\n /** UUID of the plan to subscribe the customer to. */\n plan_id: string\n}\n\nexport interface ListSubscriptionsParams {\n /** Filter to a specific customer UUID. */\n customer_id?: string\n /** Filter to a specific plan UUID. */\n plan_id?: string\n /** Filter by status. Use `SubscriptionStatus` constants. */\n status?: SubscriptionStatusValue\n}\n\nexport interface ListSubscriptionsResponse {\n subscriptions: Subscription[]\n count: number\n}\n\n// =============================================================================\n// Payout accounts\n// =============================================================================\n\n/** A bank or mobile-money account that a customer can be paid to. */\nexport interface PayoutAccount {\n id: string\n customer_id: string\n org_id: string\n account_name: string\n bank_name?: string\n bank_code?: string\n account_number?: string\n mobile_money_number?: string\n /** Use `PayoutMethod` constants. */\n payout_method: PayoutMethodValue\n currency: string\n is_default: boolean\n metadata: Record<string, unknown> | null\n created_at: string\n updated_at: string\n}\n\nexport interface CreatePayoutAccountRequest {\n account_name: string\n /** Use `PayoutMethod` constants. */\n payout_method: PayoutMethodValue\n bank_name?: string\n bank_code?: string\n account_number?: string\n mobile_money_number?: string\n currency?: string\n is_default?: boolean\n metadata?: Record<string, unknown>\n}\n\nexport interface UpdatePayoutAccountRequest {\n account_name?: string\n payout_method?: PayoutMethodValue\n bank_name?: string\n account_number?: string\n currency?: string\n is_default?: boolean\n metadata?: Record<string, unknown>\n}\n\nexport interface ListPayoutAccountsResponse {\n payout_accounts: PayoutAccount[]\n count: number\n}\n\n// =============================================================================\n// Invoices\n// =============================================================================\n\n/** One line item on an invoice. */\nexport interface InvoiceLineItem {\n id: string\n invoice_id: string\n metric_id: string\n price_id?: string\n description: string\n quantity: string\n unit_price: string\n /** Amount for this line as a decimal string. */\n amount: string\n created_at: string\n}\n\n/**\n * A billing invoice.\n * All monetary values (`subtotal`, `vat_amount`, `total`) are decimal strings\n * to avoid floating-point precision issues.\n */\nexport interface Invoice {\n id: string\n org_id: string\n customer_id: string\n subscription_id: string\n /** Use `InvoiceStatus` constants. */\n status: InvoiceStatusValue\n currency: string\n subtotal: string\n vat_enabled: boolean\n vat_rate?: string\n vat_amount?: string\n total: string\n period_start: string\n period_end: string\n finalized_at: string | null\n paid_at: string | null\n provider_invoice_id?: string\n line_items?: InvoiceLineItem[]\n created_at: string\n updated_at: string\n}\n\nexport interface ListInvoicesParams {\n /** Filter by status. Use `InvoiceStatus` constants. */\n status?: InvoiceStatusValue\n /** Filter to a specific customer UUID. */\n customer_id?: string\n}\n\nexport interface ListInvoicesResponse {\n invoices: Invoice[]\n count: number\n}\n\n// =============================================================================\n// Usage\n// =============================================================================\n\n/** One aggregated usage record for a (customer, metric, period) tuple. */\nexport interface UsageRollup {\n id: string\n org_id: string\n customer_id: string\n metric_id: string\n period_start: string\n period_end: string\n aggregation: AggregationType\n /** Aggregated value (count, sum, max, etc.). */\n value: number\n event_count: number\n last_event_at: string | null\n is_test: boolean\n created_at: string\n updated_at: string\n}\n\nexport interface UsageQueryParams {\n /** Filter rollups to a specific customer UUID. */\n customer_id?: string\n /** Filter rollups to a specific metric UUID. */\n metric_id?: string\n /**\n * Lower bound for `period_start` (ISO 8601).\n * Defaults to the start of the current billing period.\n */\n from?: string | Date\n /**\n * Exclusive upper bound for `period_start` (ISO 8601).\n * Defaults to the end of the current billing period.\n */\n to?: string | Date\n}\n\nexport interface UsageQueryResult {\n rollups: UsageRollup[]\n count: number\n}\n"],"names":[],"mappings":";;AAcO,MAAM,uBAAuB,MAAM;AAAA,EAQxC,YACE,YACA,SACA,SACA;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,UAAU;AACf,SAAK,UAAU;AAEf,UAAM,UAAW,MACf,mBACF;AACA,cAAU,MAAM,cAAc;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,aAAsB;AACxB,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAEA,IAAI,iBAA0B;AAC5B,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAEA,IAAI,cAAuB;AACzB,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAEA,IAAI,gBAAyB;AAC3B,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAEA,IAAI,aAAsB;AACxB,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAEA,IAAI,kBAA2B;AAC7B,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAEA,IAAI,gBAAyB;AAC3B,WAAO,KAAK,cAAc;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,WAAW,KAAqC;AACrD,WAAO,eAAe,kBAAkB,IAAI,eAAe;AAAA,EAC7D;AAAA,EAEA,OAAO,eAAe,KAAqC;AACzD,WAAO,eAAe,kBAAkB,IAAI,eAAe;AAAA,EAC7D;AAAA,EAEA,OAAO,YAAY,KAAqC;AACtD,WAAO,eAAe,kBA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duplicates.length)
85
85
  * ```
86
86
  */
87
- async ingest(request) {
87
+ async ingest(request, options) {
88
88
  const body = {
89
89
  events: request.events.map((e) => ({
90
90
  ...e,
91
91
  timestamp: e.timestamp ? MonigoClient.toISOString(e.timestamp) : (/* @__PURE__ */ new Date()).toISOString()
92
92
  }))
93
93
  };
94
- return this.client._request("POST", "/v1/ingest", { body });
94
+ return this.client._request("POST", "/v1/ingest", {
95
+ body,
96
+ idempotencyKey: options?.idempotencyKey
97
+ });
95
98
  }
96
99
  /**
97
100
  * Start an asynchronous replay of all raw events in a given time window
@@ -112,7 +115,7 @@ class EventsResource {
112
115
  * console.log('Replay job:', job.id, job.status)
113
116
  * ```
114
117
  */
115
- async startReplay(request) {
118
+ async startReplay(request, options) {
116
119
  const body = {
117
120
  from: MonigoClient.toISOString(request.from),
118
121
  to: MonigoClient.toISOString(request.to),
@@ -121,7 +124,7 @@ class EventsResource {
121
124
  const wrapper = await this.client._request(
122
125
  "POST",
123
126
  "/v1/events/replay",
124
- { body }
127
+ { body, idempotencyKey: options?.idempotencyKey }
125
128
  );
126
129
  return wrapper.job;
127
130
  }
@@ -165,11 +168,11 @@ class CustomersResource {
165
168
  * })
166
169
  * ```
167
170
  */
168
- async create(request) {
171
+ async create(request, options) {
169
172
  const wrapper = await this.client._request(
170
173
  "POST",
171
174
  "/v1/customers",
172
- { body: request }
175
+ { body: request, idempotencyKey: options?.idempotencyKey }
173
176
  );
174
177
  return wrapper.customer;
175
178
  }
@@ -206,11 +209,11 @@ class CustomersResource {
206
209
  * })
207
210
  * ```
208
211
  */
209
- async update(customerId, request) {
212
+ async update(customerId, request, options) {
210
213
  const wrapper = await this.client._request(
211
214
  "PUT",
212
215
  `/v1/customers/${customerId}`,
213
- { body: request }
216
+ { body: request, idempotencyKey: options?.idempotencyKey }
214
217
  );
215
218
  return wrapper.customer;
216
219
  }
@@ -241,11 +244,11 @@ class MetricsResource {
241
244
  * })
242
245
  * ```
243
246
  */
244
- async create(request) {
247
+ async create(request, options) {
245
248
  const wrapper = await this.client._request(
246
249
  "POST",
247
250
  "/v1/metrics",
248
- { body: request }
251
+ { body: request, idempotencyKey: options?.idempotencyKey }
249
252
  );
250
253
  return wrapper.metric;
251
254
  }
@@ -274,11 +277,11 @@ class MetricsResource {
274
277
  *
275
278
  * **Requires `write` scope.**
276
279
  */
277
- async update(metricId, request) {
280
+ async update(metricId, request, options) {
278
281
  const wrapper = await this.client._request(
279
282
  "PUT",
280
283
  `/v1/metrics/${metricId}`,
281
- { body: request }
284
+ { body: request, idempotencyKey: options?.idempotencyKey }
282
285
  );
283
286
  return wrapper.metric;
284
287
  }
@@ -314,11 +317,11 @@ class PlansResource {
314
317
  * })
315
318
  * ```
316
319
  */
317
- async create(request) {
320
+ async create(request, options) {
318
321
  const wrapper = await this.client._request(
319
322
  "POST",
320
323
  "/v1/plans",
321
- { body: request }
324
+ { body: request, idempotencyKey: options?.idempotencyKey }
322
325
  );
323
326
  return wrapper.plan;
324
327
  }
@@ -347,11 +350,11 @@ class PlansResource {
347
350
  *
348
351
  * **Requires `write` scope.**
349
352
  */
350
- async update(planId, request) {
353
+ async update(planId, request, options) {
351
354
  const wrapper = await this.client._request(
352
355
  "PUT",
353
356
  `/v1/plans/${planId}`,
354
- { body: request }
357
+ { body: request, idempotencyKey: options?.idempotencyKey }
355
358
  );
356
359
  return wrapper.plan;
357
360
  }
@@ -384,11 +387,11 @@ class SubscriptionsResource {
384
387
  * })
385
388
  * ```
386
389
  */
387
- async create(request) {
390
+ async create(request, options) {
388
391
  const wrapper = await this.client._request(
389
392
  "POST",
390
393
  "/v1/subscriptions",
391
- { body: request }
394
+ { body: request, idempotencyKey: options?.idempotencyKey }
392
395
  );
393
396
  return wrapper.subscription;
394
397
  }
@@ -437,11 +440,11 @@ class SubscriptionsResource {
437
440
  * await monigo.subscriptions.updateStatus(subId, SubscriptionStatus.Paused)
438
441
  * ```
439
442
  */
440
- async updateStatus(subscriptionId, status) {
443
+ async updateStatus(subscriptionId, status, options) {
441
444
  const wrapper = await this.client._request(
442
445
  "PATCH",
443
446
  `/v1/subscriptions/${subscriptionId}`,
444
- { body: { status } }
447
+ { body: { status }, idempotencyKey: options?.idempotencyKey }
445
448
  );
446
449
  return wrapper.subscription;
447
450
  }
@@ -476,11 +479,11 @@ class PayoutAccountsResource {
476
479
  * })
477
480
  * ```
478
481
  */
479
- async create(customerId, request) {
482
+ async create(customerId, request, options) {
480
483
  const wrapper = await this.client._request(
481
484
  "POST",
482
485
  `/v1/customers/${customerId}/payout-accounts`,
483
- { body: request }
486
+ { body: request, idempotencyKey: options?.idempotencyKey }
484
487
  );
485
488
  return wrapper.payout_account;
486
489
  }
@@ -512,11 +515,11 @@ class PayoutAccountsResource {
512
515
  *
513
516
  * **Requires `write` scope.**
514
517
  */
515
- async update(customerId, accountId, request) {
518
+ async update(customerId, accountId, request, options) {
516
519
  const wrapper = await this.client._request(
517
520
  "PUT",
518
521
  `/v1/customers/${customerId}/payout-accounts/${accountId}`,
519
- { body: request }
522
+ { body: request, idempotencyKey: options?.idempotencyKey }
520
523
  );
521
524
  return wrapper.payout_account;
522
525
  }
@@ -548,11 +551,11 @@ class InvoicesResource {
548
551
  * console.log('Draft invoice total:', invoice.total)
549
552
  * ```
550
553
  */
551
- async generate(subscriptionId) {
554
+ async generate(subscriptionId, options) {
552
555
  const wrapper = await this.client._request(
553
556
  "POST",
554
557
  "/v1/invoices/generate",
555
- { body: { subscription_id: subscriptionId } }
558
+ { body: { subscription_id: subscriptionId }, idempotencyKey: options?.idempotencyKey }
556
559
  );
557
560
  return wrapper.invoice;
558
561
  }
@@ -595,10 +598,11 @@ class InvoicesResource {
595
598
  *
596
599
  * **Requires `write` scope.**
597
600
  */
598
- async finalize(invoiceId) {
601
+ async finalize(invoiceId, options) {
599
602
  const wrapper = await this.client._request(
600
603
  "POST",
601
- `/v1/invoices/${invoiceId}/finalize`
604
+ `/v1/invoices/${invoiceId}/finalize`,
605
+ { idempotencyKey: options?.idempotencyKey }
602
606
  );
603
607
  return wrapper.invoice;
604
608
  }
@@ -608,10 +612,11 @@ class InvoicesResource {
608
612
  *
609
613
  * **Requires `write` scope.**
610
614
  */
611
- async void(invoiceId) {
615
+ async void(invoiceId, options) {
612
616
  const wrapper = await this.client._request(
613
617
  "POST",
614
- `/v1/invoices/${invoiceId}/void`
618
+ `/v1/invoices/${invoiceId}/void`,
619
+ { idempotencyKey: options?.idempotencyKey }
615
620
  );
616
621
  return wrapper.invoice;
617
622
  }
@@ -700,13 +705,16 @@ class MonigoClient {
700
705
  }
701
706
  const controller = new AbortController();
702
707
  const timeoutId = setTimeout(() => controller.abort(), this._timeout);
708
+ const isMutating = method === "POST" || method === "PUT" || method === "PATCH";
709
+ const idempotencyKey = isMutating ? options.idempotencyKey ?? globalThis.crypto.randomUUID() : void 0;
703
710
  try {
704
711
  const response = await this._fetchFn(url, {
705
712
  method,
706
713
  headers: {
707
714
  Authorization: `Bearer ${this._apiKey}`,
708
715
  "Content-Type": "application/json",
709
- Accept: "application/json"
716
+ Accept: "application/json",
717
+ ...idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {}
710
718
  },
711
719
  body: options.body != null ? JSON.stringify(options.body) : void 0,
712
720
  signal: controller.signal
@@ -1 +1 @@
1
- {"version":3,"file":"monigo.js","sources":["../src/errors.ts","../src/resources/events.ts","../src/resources/customers.ts","../src/resources/metrics.ts","../src/resources/plans.ts","../src/resources/subscriptions.ts","../src/resources/payout-accounts.ts","../src/resources/invoices.ts","../src/resources/usage.ts","../src/client.ts","../src/types.ts"],"sourcesContent":["/**\n * Thrown for any non-2xx response from the Monigo API.\n *\n * @example\n * ```ts\n * try {\n * await client.customers.get('bad-id')\n * } catch (err) {\n * if (MonigoAPIError.isNotFound(err)) {\n * console.log('Customer does not exist')\n * }\n * }\n * ```\n */\nexport class MonigoAPIError extends Error {\n /** HTTP status code returned by the API. */\n readonly statusCode: number\n /** Human-readable error message from the API. */\n readonly message: string\n /** Optional structured field-level validation details. */\n readonly details: Record<string, string> | undefined\n\n constructor(\n statusCode: number,\n message: string,\n details?: Record<string, string>,\n ) {\n super(message)\n this.name = 'MonigoAPIError'\n this.statusCode = statusCode\n this.message = message\n this.details = details\n // Maintain proper stack trace in V8 (Node.js / Chrome)\n const capture = (Error as unknown as Record<string, unknown>)[\n 'captureStackTrace'\n ] as ((target: Error, constructor: Function) => void) | undefined\n capture?.(this, MonigoAPIError)\n }\n\n // -------------------------------------------------------------------------\n // Instance guards (for use on a caught error known to be MonigoAPIError)\n // -------------------------------------------------------------------------\n\n get isNotFound(): boolean {\n return this.statusCode === 404\n }\n\n get isUnauthorized(): boolean {\n return this.statusCode === 401\n }\n\n get isForbidden(): boolean {\n return this.statusCode === 403\n }\n\n get isRateLimited(): boolean {\n return this.statusCode === 429\n }\n\n get isConflict(): boolean {\n return this.statusCode === 409\n }\n\n get isQuotaExceeded(): boolean {\n return this.statusCode === 402\n }\n\n get isServerError(): boolean {\n return this.statusCode >= 500\n }\n\n // -------------------------------------------------------------------------\n // Static type-narrowing helpers (for use in catch clauses on `unknown`)\n // -------------------------------------------------------------------------\n\n static isNotFound(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 404\n }\n\n static isUnauthorized(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 401\n }\n\n static isForbidden(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 403\n }\n\n static isRateLimited(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 429\n }\n\n static isConflict(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 409\n }\n\n static isQuotaExceeded(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 402\n }\n\n static isServerError(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode >= 500\n }\n}\n","import { MonigoClient } from '../client.js'\nimport type {\n IngestRequest,\n IngestResponse,\n StartReplayRequest,\n EventReplayJob,\n} from '../types.js'\n\n/** Handles usage event ingestion and asynchronous event replay. */\nexport class EventsResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Ingest one or more usage events into the Monigo pipeline.\n *\n * Events are processed asynchronously. The response confirms receipt\n * and reports any duplicate idempotency keys.\n *\n * **Requires `ingest` scope.**\n *\n * @example\n * ```ts\n * const result = await monigo.events.ingest({\n * events: [{\n * event_name: 'api_call',\n * customer_id: 'cust_abc',\n * idempotency_key: crypto.randomUUID(),\n * timestamp: new Date().toISOString(),\n * properties: { endpoint: '/checkout', region: 'eu-west-1' },\n * }],\n * })\n * console.log('Ingested:', result.ingested.length)\n * console.log('Duplicates:', result.duplicates.length)\n * ```\n */\n async ingest(request: IngestRequest): Promise<IngestResponse> {\n const body = {\n events: request.events.map((e) => ({\n ...e,\n timestamp: e.timestamp\n ? MonigoClient.toISOString(e.timestamp)\n : new Date().toISOString(),\n })),\n }\n return this.client._request<IngestResponse>('POST', '/v1/ingest', { body })\n }\n\n /**\n * Start an asynchronous replay of all raw events in a given time window\n * through the current processing pipeline. Useful for backfilling usage\n * data after changing metric definitions.\n *\n * Returns a replay job immediately — poll `getReplay()` to track progress.\n *\n * **Requires `ingest` scope.**\n *\n * @example\n * ```ts\n * const job = await monigo.events.startReplay({\n * from: '2025-01-01T00:00:00Z',\n * to: '2025-01-31T23:59:59Z',\n * event_name: 'api_call', // omit to replay all event types\n * })\n * console.log('Replay job:', job.id, job.status)\n * ```\n */\n async startReplay(request: StartReplayRequest): Promise<EventReplayJob> {\n const body = {\n from: MonigoClient.toISOString(request.from),\n to: MonigoClient.toISOString(request.to),\n ...(request.event_name ? { event_name: request.event_name } : {}),\n }\n const wrapper = await this.client._request<{ job: EventReplayJob }>(\n 'POST',\n '/v1/events/replay',\n { body },\n )\n return wrapper.job\n }\n\n /**\n * Fetch the current status and progress of an event replay job.\n *\n * **Requires `ingest` scope.**\n *\n * @example\n * ```ts\n * const job = await monigo.events.getReplay(jobId)\n * if (job.status === 'completed') {\n * console.log(`Replayed ${job.events_replayed} / ${job.events_total} events`)\n * }\n * ```\n */\n async getReplay(jobId: string): Promise<EventReplayJob> {\n const wrapper = await this.client._request<{ job: EventReplayJob }>(\n 'GET',\n `/v1/events/replay/${jobId}`,\n )\n return wrapper.job\n }\n}\n","import type { MonigoClient } from '../client.js'\nimport type {\n Customer,\n CreateCustomerRequest,\n UpdateCustomerRequest,\n ListCustomersResponse,\n} from '../types.js'\n\n/** Manage end-customers in your Monigo organisation. */\nexport class CustomersResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Register a new customer.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const customer = await monigo.customers.create({\n * external_id: 'usr_12345',\n * name: 'Acme Corp',\n * email: 'billing@acme.com',\n * metadata: { plan_tier: 'enterprise' },\n * })\n * ```\n */\n async create(request: CreateCustomerRequest): Promise<Customer> {\n const wrapper = await this.client._request<{ customer: Customer }>(\n 'POST',\n '/v1/customers',\n { body: request },\n )\n return wrapper.customer\n }\n\n /**\n * Return all customers in the authenticated organisation.\n *\n * **Requires `read` scope.**\n */\n async list(): Promise<ListCustomersResponse> {\n return this.client._request<ListCustomersResponse>('GET', '/v1/customers')\n }\n\n /**\n * Fetch a single customer by their Monigo UUID.\n *\n * **Requires `read` scope.**\n */\n async get(customerId: string): Promise<Customer> {\n const wrapper = await this.client._request<{ customer: Customer }>(\n 'GET',\n `/v1/customers/${customerId}`,\n )\n return wrapper.customer\n }\n\n /**\n * Update a customer's name, email, or metadata.\n * Only fields that are present in `request` are updated.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const updated = await monigo.customers.update(customerId, {\n * email: 'new@acme.com',\n * })\n * ```\n */\n async update(\n customerId: string,\n request: UpdateCustomerRequest,\n ): Promise<Customer> {\n const wrapper = await this.client._request<{ customer: Customer }>(\n 'PUT',\n `/v1/customers/${customerId}`,\n { body: request },\n )\n return wrapper.customer\n }\n\n /**\n * Permanently delete a customer record.\n *\n * **Requires `write` scope.**\n */\n async delete(customerId: string): Promise<void> {\n await this.client._request<void>('DELETE', `/v1/customers/${customerId}`)\n }\n}\n","import type { MonigoClient } from '../client.js'\nimport type {\n Metric,\n CreateMetricRequest,\n UpdateMetricRequest,\n ListMetricsResponse,\n} from '../types.js'\n\n/** Manage billing metrics — what usage gets counted and how it is aggregated. */\nexport class MetricsResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Create a new metric.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const metric = await monigo.metrics.create({\n * name: 'API Calls',\n * event_name: 'api_call',\n * aggregation: 'count',\n * })\n * ```\n */\n async create(request: CreateMetricRequest): Promise<Metric> {\n const wrapper = await this.client._request<{ metric: Metric }>(\n 'POST',\n '/v1/metrics',\n { body: request },\n )\n return wrapper.metric\n }\n\n /**\n * Return all metrics in the authenticated organisation.\n *\n * **Requires `read` scope.**\n */\n async list(): Promise<ListMetricsResponse> {\n return this.client._request<ListMetricsResponse>('GET', '/v1/metrics')\n }\n\n /**\n * Fetch a single metric by its UUID.\n *\n * **Requires `read` scope.**\n */\n async get(metricId: string): Promise<Metric> {\n const wrapper = await this.client._request<{ metric: Metric }>(\n 'GET',\n `/v1/metrics/${metricId}`,\n )\n return wrapper.metric\n }\n\n /**\n * Update a metric's name, event name, aggregation, or description.\n *\n * **Requires `write` scope.**\n */\n async update(metricId: string, request: UpdateMetricRequest): Promise<Metric> {\n const wrapper = await this.client._request<{ metric: Metric }>(\n 'PUT',\n `/v1/metrics/${metricId}`,\n { body: request },\n )\n return wrapper.metric\n }\n\n /**\n * Permanently delete a metric.\n *\n * **Requires `write` scope.**\n */\n async delete(metricId: string): Promise<void> {\n await this.client._request<void>('DELETE', `/v1/metrics/${metricId}`)\n }\n}\n","import type { MonigoClient } from '../client.js'\nimport type {\n Plan,\n CreatePlanRequest,\n UpdatePlanRequest,\n ListPlansResponse,\n} from '../types.js'\n\n/** Manage billing plans and their prices. */\nexport class PlansResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Create a new billing plan, optionally with prices attached.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const plan = await monigo.plans.create({\n * name: 'Pro',\n * currency: 'NGN',\n * billing_period: 'monthly',\n * prices: [{\n * metric_id: 'metric_abc',\n * model: 'flat',\n * unit_price: '2.500000',\n * }],\n * })\n * ```\n */\n async create(request: CreatePlanRequest): Promise<Plan> {\n const wrapper = await this.client._request<{ plan: Plan }>(\n 'POST',\n '/v1/plans',\n { body: request },\n )\n return wrapper.plan\n }\n\n /**\n * Return all billing plans in the authenticated organisation.\n *\n * **Requires `read` scope.**\n */\n async list(): Promise<ListPlansResponse> {\n return this.client._request<ListPlansResponse>('GET', '/v1/plans')\n }\n\n /**\n * Fetch a single plan by its UUID, including its prices.\n *\n * **Requires `read` scope.**\n */\n async get(planId: string): Promise<Plan> {\n const wrapper = await this.client._request<{ plan: Plan }>(\n 'GET',\n `/v1/plans/${planId}`,\n )\n return wrapper.plan\n }\n\n /**\n * Update a plan's name, description, currency, or prices.\n *\n * **Requires `write` scope.**\n */\n async update(planId: string, request: UpdatePlanRequest): Promise<Plan> {\n const wrapper = await this.client._request<{ plan: Plan }>(\n 'PUT',\n `/v1/plans/${planId}`,\n { body: request },\n )\n return wrapper.plan\n }\n\n /**\n * Permanently delete a plan.\n *\n * **Requires `write` scope.**\n */\n async delete(planId: string): Promise<void> {\n await this.client._request<void>('DELETE', `/v1/plans/${planId}`)\n }\n}\n","import type { MonigoClient } from '../client.js'\nimport type {\n Subscription,\n CreateSubscriptionRequest,\n ListSubscriptionsParams,\n ListSubscriptionsResponse,\n SubscriptionStatusValue,\n} from '../types.js'\n\n/** Link customers to billing plans and manage subscription lifecycle. */\nexport class SubscriptionsResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Subscribe a customer to a plan.\n *\n * Returns a 409 Conflict error (check with `MonigoAPIError.isConflict(err)`)\n * if the customer already has an active subscription to the same plan.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const sub = await monigo.subscriptions.create({\n * customer_id: 'cust_abc',\n * plan_id: 'plan_xyz',\n * })\n * ```\n */\n async create(request: CreateSubscriptionRequest): Promise<Subscription> {\n const wrapper = await this.client._request<{ subscription: Subscription }>(\n 'POST',\n '/v1/subscriptions',\n { body: request },\n )\n return wrapper.subscription\n }\n\n /**\n * Return subscriptions, optionally filtered by customer, plan, or status.\n *\n * **Requires `read` scope.**\n *\n * @example\n * ```ts\n * const { subscriptions } = await monigo.subscriptions.list({\n * customer_id: 'cust_abc',\n * status: 'active',\n * })\n * ```\n */\n async list(params: ListSubscriptionsParams = {}): Promise<ListSubscriptionsResponse> {\n return this.client._request<ListSubscriptionsResponse>('GET', '/v1/subscriptions', {\n query: {\n customer_id: params.customer_id,\n plan_id: params.plan_id,\n status: params.status,\n },\n })\n }\n\n /**\n * Fetch a single subscription by its UUID.\n *\n * **Requires `read` scope.**\n */\n async get(subscriptionId: string): Promise<Subscription> {\n const wrapper = await this.client._request<{ subscription: Subscription }>(\n 'GET',\n `/v1/subscriptions/${subscriptionId}`,\n )\n return wrapper.subscription\n }\n\n /**\n * Change the status of a subscription.\n * Use `SubscriptionStatus` constants: `\"active\"`, `\"paused\"`, `\"canceled\"`.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * await monigo.subscriptions.updateStatus(subId, SubscriptionStatus.Paused)\n * ```\n */\n async updateStatus(\n subscriptionId: string,\n status: SubscriptionStatusValue,\n ): Promise<Subscription> {\n const wrapper = await this.client._request<{ subscription: Subscription }>(\n 'PATCH',\n `/v1/subscriptions/${subscriptionId}`,\n { body: { status } },\n )\n return wrapper.subscription\n }\n\n /**\n * Cancel and delete a subscription record.\n *\n * **Requires `write` scope.**\n */\n async delete(subscriptionId: string): Promise<void> {\n await this.client._request<void>('DELETE', `/v1/subscriptions/${subscriptionId}`)\n }\n}\n","import type { MonigoClient } from '../client.js'\nimport type {\n PayoutAccount,\n CreatePayoutAccountRequest,\n UpdatePayoutAccountRequest,\n ListPayoutAccountsResponse,\n} from '../types.js'\n\n/** Manage bank and mobile-money payout accounts for customers. */\nexport class PayoutAccountsResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Add a payout account for a customer.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const account = await monigo.payoutAccounts.create('cust_abc', {\n * account_name: 'Acme Corp',\n * payout_method: 'bank_transfer',\n * bank_name: 'Zenith Bank',\n * bank_code: '057',\n * account_number: '1234567890',\n * currency: 'NGN',\n * is_default: true,\n * })\n * ```\n */\n async create(\n customerId: string,\n request: CreatePayoutAccountRequest,\n ): Promise<PayoutAccount> {\n const wrapper = await this.client._request<{ payout_account: PayoutAccount }>(\n 'POST',\n `/v1/customers/${customerId}/payout-accounts`,\n { body: request },\n )\n return wrapper.payout_account\n }\n\n /**\n * Return all payout accounts for a customer.\n *\n * **Requires `read` scope.**\n */\n async list(customerId: string): Promise<ListPayoutAccountsResponse> {\n return this.client._request<ListPayoutAccountsResponse>(\n 'GET',\n `/v1/customers/${customerId}/payout-accounts`,\n )\n }\n\n /**\n * Fetch a single payout account by its UUID.\n *\n * **Requires `read` scope.**\n */\n async get(customerId: string, accountId: string): Promise<PayoutAccount> {\n const wrapper = await this.client._request<{ payout_account: PayoutAccount }>(\n 'GET',\n `/v1/customers/${customerId}/payout-accounts/${accountId}`,\n )\n return wrapper.payout_account\n }\n\n /**\n * Update a payout account's details.\n *\n * **Requires `write` scope.**\n */\n async update(\n customerId: string,\n accountId: string,\n request: UpdatePayoutAccountRequest,\n ): Promise<PayoutAccount> {\n const wrapper = await this.client._request<{ payout_account: PayoutAccount }>(\n 'PUT',\n `/v1/customers/${customerId}/payout-accounts/${accountId}`,\n { body: request },\n )\n return wrapper.payout_account\n }\n\n /**\n * Delete a payout account.\n *\n * **Requires `write` scope.**\n */\n async delete(customerId: string, accountId: string): Promise<void> {\n await this.client._request<void>(\n 'DELETE',\n `/v1/customers/${customerId}/payout-accounts/${accountId}`,\n )\n }\n}\n","import type { MonigoClient } from '../client.js'\nimport type {\n Invoice,\n ListInvoicesParams,\n ListInvoicesResponse,\n} from '../types.js'\n\n/** Manage invoice generation, finalization, and voiding. */\nexport class InvoicesResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Generate a draft invoice for a subscription based on current period usage.\n * The invoice starts in `\"draft\"` status and is not sent to the customer yet.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const invoice = await monigo.invoices.generate('sub_xyz')\n * console.log('Draft invoice total:', invoice.total)\n * ```\n */\n async generate(subscriptionId: string): Promise<Invoice> {\n const wrapper = await this.client._request<{ invoice: Invoice }>(\n 'POST',\n '/v1/invoices/generate',\n { body: { subscription_id: subscriptionId } },\n )\n return wrapper.invoice\n }\n\n /**\n * Return invoices, optionally filtered by status or customer.\n *\n * **Requires `read` scope.**\n *\n * @example\n * ```ts\n * const { invoices } = await monigo.invoices.list({\n * status: 'finalized',\n * customer_id: 'cust_abc',\n * })\n * ```\n */\n async list(params: ListInvoicesParams = {}): Promise<ListInvoicesResponse> {\n return this.client._request<ListInvoicesResponse>('GET', '/v1/invoices', {\n query: {\n status: params.status,\n customer_id: params.customer_id,\n },\n })\n }\n\n /**\n * Fetch a single invoice by its UUID, including line items.\n *\n * **Requires `read` scope.**\n */\n async get(invoiceId: string): Promise<Invoice> {\n const wrapper = await this.client._request<{ invoice: Invoice }>(\n 'GET',\n `/v1/invoices/${invoiceId}`,\n )\n return wrapper.invoice\n }\n\n /**\n * Finalize a draft invoice, making it ready for payment.\n * A finalized invoice cannot be edited.\n *\n * **Requires `write` scope.**\n */\n async finalize(invoiceId: string): Promise<Invoice> {\n const wrapper = await this.client._request<{ invoice: Invoice }>(\n 'POST',\n `/v1/invoices/${invoiceId}/finalize`,\n )\n return wrapper.invoice\n }\n\n /**\n * Void an invoice, making it permanently non-payable.\n * Only admins and owners can void invoices.\n *\n * **Requires `write` scope.**\n */\n async void(invoiceId: string): Promise<Invoice> {\n const wrapper = await this.client._request<{ invoice: Invoice }>(\n 'POST',\n `/v1/invoices/${invoiceId}/void`,\n )\n return wrapper.invoice\n }\n}\n","import { MonigoClient } from '../client.js'\nimport type { UsageQueryParams, UsageQueryResult } from '../types.js'\n\n/** Query aggregated usage rollups from the Monigo metering pipeline. */\nexport class UsageResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Return per-customer, per-metric usage rollups for the organisation.\n * All parameters are optional — omitting them returns the full current\n * billing period for all customers and metrics.\n *\n * **Requires `read` scope.**\n *\n * @example\n * ```ts\n * // All usage for one customer this period\n * const { rollups } = await monigo.usage.query({\n * customer_id: 'cust_abc',\n * })\n *\n * // Filtered by metric and custom date range\n * const { rollups: filtered } = await monigo.usage.query({\n * metric_id: 'metric_xyz',\n * from: '2025-01-01T00:00:00Z',\n * to: '2025-01-31T23:59:59Z',\n * })\n * ```\n */\n async query(params: UsageQueryParams = {}): Promise<UsageQueryResult> {\n const query: Record<string, string | undefined> = {\n customer_id: params.customer_id,\n metric_id: params.metric_id,\n }\n if (params.from !== undefined) {\n query.from = MonigoClient.toISOString(params.from)\n }\n if (params.to !== undefined) {\n query.to = MonigoClient.toISOString(params.to)\n }\n return this.client._request<UsageQueryResult>('GET', '/v1/usage', { query })\n }\n}\n","import { MonigoAPIError } from './errors.js'\nimport { EventsResource } from './resources/events.js'\nimport { CustomersResource } from './resources/customers.js'\nimport { MetricsResource } from './resources/metrics.js'\nimport { PlansResource } from './resources/plans.js'\nimport { SubscriptionsResource } from './resources/subscriptions.js'\nimport { PayoutAccountsResource } from './resources/payout-accounts.js'\nimport { InvoicesResource } from './resources/invoices.js'\nimport { UsageResource } from './resources/usage.js'\n\nconst DEFAULT_BASE_URL = 'https://api.monigo.co'\nconst DEFAULT_TIMEOUT_MS = 30_000\n\nexport interface MonigoClientOptions {\n /**\n * Your Monigo API key. Obtain one from the API Keys section of your\n * Monigo dashboard. Never expose this key in client-side code.\n */\n apiKey: string\n /**\n * Override the default API base URL (`https://api.monigo.co`).\n * Useful for self-hosted deployments or pointing at a local dev server.\n *\n * @default \"https://api.monigo.co\"\n */\n baseURL?: string\n /**\n * Custom `fetch` implementation. Defaults to `globalThis.fetch`.\n * Pass a polyfill for environments that do not have native fetch\n * (Node.js < 18) or to inject a mock in tests.\n */\n fetch?: typeof globalThis.fetch\n /**\n * Request timeout in milliseconds.\n *\n * @default 30000\n */\n timeout?: number\n}\n\n/** @internal */\nexport interface RequestOptions {\n body?: unknown\n query?: Record<string, string | undefined>\n}\n\n/**\n * The Monigo API client.\n *\n * Instantiate once and reuse across your application:\n *\n * ```ts\n * import { MonigoClient } from '@monigo/sdk'\n *\n * const monigo = new MonigoClient({ apiKey: process.env.MONIGO_API_KEY! })\n *\n * // Ingest a usage event\n * await monigo.events.ingest({\n * events: [{\n * event_name: 'api_call',\n * customer_id: 'cust_abc123',\n * idempotency_key: crypto.randomUUID(),\n * }],\n * })\n * ```\n */\nexport class MonigoClient {\n /** @internal */\n readonly _apiKey: string\n /** @internal */\n readonly _baseURL: string\n /** @internal */\n readonly _fetchFn: typeof globalThis.fetch\n /** @internal */\n readonly _timeout: number\n\n /** Ingest usage events and manage event replays. Requires `ingest` scope. */\n readonly events: EventsResource\n /** Manage your end-customers (CRUD). Requires `read` / `write` scope. */\n readonly customers: CustomersResource\n /** Manage billing metrics — what gets counted and how. Requires `read` / `write` scope. */\n readonly metrics: MetricsResource\n /** Manage billing plans and their prices. Requires `read` / `write` scope. */\n readonly plans: PlansResource\n /** Link customers to plans and manage subscription lifecycle. Requires `read` / `write` scope. */\n readonly subscriptions: SubscriptionsResource\n /** Manage bank / mobile-money payout accounts for customers. Requires `read` / `write` scope. */\n readonly payoutAccounts: PayoutAccountsResource\n /** Generate, list, finalize, and void invoices. Requires `read` / `write` scope. */\n readonly invoices: InvoicesResource\n /** Query aggregated usage rollups per customer and metric. Requires `read` scope. */\n readonly usage: UsageResource\n\n constructor(options: MonigoClientOptions) {\n if (!options.apiKey) {\n throw new Error('MonigoClient: apiKey is required')\n }\n\n this._apiKey = options.apiKey\n this._baseURL = (options.baseURL ?? DEFAULT_BASE_URL).replace(/\\/$/, '')\n this._timeout = options.timeout ?? DEFAULT_TIMEOUT_MS\n\n const fetchFn = options.fetch ?? (typeof globalThis !== 'undefined' ? globalThis.fetch : undefined)\n if (!fetchFn) {\n throw new Error(\n 'MonigoClient: fetch is not available in this environment. ' +\n 'Pass a custom fetch implementation via options.fetch, ' +\n 'or upgrade to Node.js 18+.',\n )\n }\n this._fetchFn = fetchFn.bind(globalThis)\n\n this.events = new EventsResource(this)\n this.customers = new CustomersResource(this)\n this.metrics = new MetricsResource(this)\n this.plans = new PlansResource(this)\n this.subscriptions = new SubscriptionsResource(this)\n this.payoutAccounts = new PayoutAccountsResource(this)\n this.invoices = new InvoicesResource(this)\n this.usage = new UsageResource(this)\n }\n\n /**\n * Execute an authenticated HTTP request against the Monigo API.\n * @internal — use the resource methods instead.\n */\n async _request<T>(\n method: string,\n path: string,\n options: RequestOptions = {},\n ): Promise<T> {\n let url = this._baseURL + path\n\n if (options.query) {\n const params = new URLSearchParams()\n for (const [key, value] of Object.entries(options.query)) {\n if (value !== undefined && value !== '') {\n params.set(key, value)\n }\n }\n const qs = params.toString()\n if (qs) url += '?' + qs\n }\n\n const controller = new AbortController()\n const timeoutId = setTimeout(() => controller.abort(), this._timeout)\n\n try {\n const response = await this._fetchFn(url, {\n method,\n headers: {\n Authorization: `Bearer ${this._apiKey}`,\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n },\n body: options.body != null ? JSON.stringify(options.body) : undefined,\n signal: controller.signal,\n })\n\n const text = await response.text()\n\n if (!response.ok) {\n let message = text || response.statusText\n let details: Record<string, string> | undefined\n try {\n const parsed = JSON.parse(text) as {\n error?: string\n message?: string\n details?: Record<string, string>\n }\n message = parsed.error ?? parsed.message ?? message\n details = parsed.details\n } catch {\n // Use raw text as the error message\n }\n throw new MonigoAPIError(response.status, message, details)\n }\n\n if (!text) return undefined as T\n return JSON.parse(text) as T\n } catch (err) {\n if (err instanceof MonigoAPIError) throw err\n if (err instanceof Error && err.name === 'AbortError') {\n throw new Error(\n `MonigoClient: request to ${url} timed out after ${this._timeout}ms`,\n )\n }\n throw err\n } finally {\n clearTimeout(timeoutId)\n }\n }\n\n /** Normalise a `Date | string` value to an ISO 8601 string. */\n static toISOString(value: string | Date): string {\n return value instanceof Date ? value.toISOString() : value\n }\n}\n","// =============================================================================\n// Aggregation constants\n// =============================================================================\n\nexport const Aggregation = {\n Count: 'count',\n Sum: 'sum',\n Max: 'max',\n Min: 'minimum',\n Average: 'average',\n Unique: 'unique',\n} as const\n\nexport type AggregationType = (typeof Aggregation)[keyof typeof Aggregation]\n\n// =============================================================================\n// Pricing model constants\n// =============================================================================\n\nexport const PricingModel = {\n Flat: 'flat',\n Tiered: 'tiered',\n Volume: 'volume',\n Package: 'package',\n Overage: 'overage',\n WeightedTiered: 'weighted_tiered',\n} as const\n\nexport type PricingModelType = (typeof PricingModel)[keyof typeof PricingModel]\n\n// =============================================================================\n// Plan constants\n// =============================================================================\n\nexport const PlanType = {\n Collection: 'collection',\n Payout: 'payout',\n} as const\n\nexport type PlanTypeValue = (typeof PlanType)[keyof typeof PlanType]\n\nexport const BillingPeriod = {\n Daily: 'daily',\n Weekly: 'weekly',\n Monthly: 'monthly',\n Quarterly: 'quarterly',\n Annually: 'annually',\n} as const\n\nexport type BillingPeriodValue = (typeof BillingPeriod)[keyof typeof BillingPeriod]\n\n// =============================================================================\n// Subscription status constants\n// =============================================================================\n\nexport const SubscriptionStatus = {\n Active: 'active',\n Paused: 'paused',\n Canceled: 'canceled',\n} as const\n\nexport type SubscriptionStatusValue = (typeof SubscriptionStatus)[keyof typeof SubscriptionStatus]\n\n// =============================================================================\n// Invoice status constants\n// =============================================================================\n\nexport const InvoiceStatus = {\n Draft: 'draft',\n Finalized: 'finalized',\n Paid: 'paid',\n Void: 'void',\n} as const\n\nexport type InvoiceStatusValue = (typeof InvoiceStatus)[keyof typeof InvoiceStatus]\n\n// =============================================================================\n// Payout method constants\n// =============================================================================\n\nexport const PayoutMethod = {\n BankTransfer: 'bank_transfer',\n MobileMoney: 'mobile_money',\n} as const\n\nexport type PayoutMethodValue = (typeof PayoutMethod)[keyof typeof PayoutMethod]\n\n// =============================================================================\n// Events\n// =============================================================================\n\n/** A single usage event sent to the Monigo ingestion pipeline. */\nexport interface IngestEvent {\n /**\n * The name of the event, e.g. `\"api_call\"` or `\"storage.write\"`.\n * Must match the `event_name` on one or more metrics you have configured.\n */\n event_name: string\n /** The Monigo customer UUID this event belongs to. */\n customer_id: string\n /**\n * A unique key for this event. Re-sending the same key is safe — the server\n * will de-duplicate automatically. Use a UUID or any stable ID you control.\n */\n idempotency_key: string\n /**\n * ISO 8601 timestamp for when the event occurred. Backdated events are\n * accepted within the configured replay window. Defaults to now if omitted.\n */\n timestamp?: string | Date\n /**\n * Arbitrary key-value pairs attached to the event. Use these for dimensions\n * such as `{ endpoint: \"/checkout\", region: \"eu-west-1\" }`.\n */\n properties?: Record<string, unknown>\n}\n\n/** Request body for `POST /v1/ingest`. */\nexport interface IngestRequest {\n events: IngestEvent[]\n}\n\n/** Response from `POST /v1/ingest`. */\nexport interface IngestResponse {\n /** Idempotency keys of events that were successfully ingested. */\n ingested: string[]\n /** Idempotency keys that were skipped because they already existed. */\n duplicates: string[]\n}\n\n/** Request body for `POST /v1/events/replay`. */\nexport interface StartReplayRequest {\n /** Start of the replay window (ISO 8601). */\n from: string | Date\n /** End of the replay window (ISO 8601). */\n to: string | Date\n /** Optional event name to replay. Omit to replay all event types. */\n event_name?: string\n}\n\n/** Tracks the progress of an asynchronous event replay job. */\nexport interface EventReplayJob {\n id: string\n org_id: string\n initiated_by: string\n /** `pending` | `processing` | `completed` | `failed` */\n status: string\n from_timestamp: string\n to_timestamp: string\n event_name: string | null\n is_test: boolean\n events_total: number\n events_replayed: number\n error_message: string | null\n started_at: string | null\n completed_at: string | null\n created_at: string\n updated_at: string\n}\n\n// =============================================================================\n// Customers\n// =============================================================================\n\n/** An end-customer record in your Monigo organisation. */\nexport interface Customer {\n id: string\n org_id: string\n /** The ID for this customer in your own system. */\n external_id: string\n name: string\n email: string\n /** Arbitrary JSON metadata. */\n metadata: Record<string, unknown> | null\n created_at: string\n updated_at: string\n}\n\nexport interface CreateCustomerRequest {\n /** Your internal ID for this customer. */\n external_id: string\n name: string\n email: string\n metadata?: Record<string, unknown>\n}\n\nexport interface UpdateCustomerRequest {\n name?: string\n email?: string\n metadata?: Record<string, unknown>\n}\n\nexport interface ListCustomersResponse {\n customers: Customer[]\n count: number\n}\n\n// =============================================================================\n// Metrics\n// =============================================================================\n\n/** Defines what usage is counted and how. */\nexport interface Metric {\n id: string\n org_id: string\n name: string\n /** The `event_name` value that this metric tracks. */\n event_name: string\n /** How events are aggregated. Use `Aggregation` constants. */\n aggregation: AggregationType\n /** For sum/max/min/average: the Properties key whose value is used. */\n aggregation_property?: string\n description?: string\n created_at: string\n updated_at: string\n}\n\nexport interface CreateMetricRequest {\n /** Human-readable label, e.g. `\"API Calls\"`. */\n name: string\n /** The `event_name` value to track. */\n event_name: string\n /** How events are aggregated. Use `Aggregation` constants. */\n aggregation: AggregationType\n description?: string\n /** Required for sum/max/min/average aggregations. */\n aggregation_property?: string\n}\n\nexport interface UpdateMetricRequest {\n name?: string\n event_name?: string\n aggregation?: AggregationType\n description?: string\n aggregation_property?: string\n}\n\nexport interface ListMetricsResponse {\n metrics: Metric[]\n count: number\n}\n\n// =============================================================================\n// Plans & Prices\n// =============================================================================\n\n/**\n * One price step in a tiered/volume/weighted_tiered pricing model.\n * Set `up_to` to `null` for the final (infinite) tier.\n */\nexport interface PriceTier {\n up_to: number | null\n /** Price per unit in this tier as a decimal string, e.g. `\"0.50\"`. */\n unit_amount: string\n}\n\n/** Describes a price to attach when creating a plan. */\nexport interface CreatePriceRequest {\n /** UUID of the metric this price is based on. */\n metric_id: string\n /** Pricing model. Use `PricingModel` constants. */\n model: PricingModelType\n /** Flat price per unit as a decimal string (used for flat/overage/package models). */\n unit_price?: string\n /** Price tiers for tiered/volume/weighted_tiered models. */\n tiers?: PriceTier[]\n}\n\n/** Describes an updated price. Include `id` to update an existing price; omit to add a new one. */\nexport interface UpdatePriceRequest {\n id?: string\n metric_id?: string\n model?: PricingModelType\n unit_price?: string\n tiers?: PriceTier[]\n}\n\n/** A pricing rule attached to a plan. */\nexport interface Price {\n id: string\n plan_id: string\n metric_id: string\n model: PricingModelType\n unit_price: string\n tiers: PriceTier[] | null\n created_at: string\n updated_at: string\n}\n\n/** A billing plan that defines pricing for one or more metrics. */\nexport interface Plan {\n id: string\n org_id: string\n name: string\n description?: string\n /** ISO 4217 currency code, e.g. `\"NGN\"`. */\n currency: string\n /** Use `PlanType` constants. */\n plan_type: PlanTypeValue\n /** Use `BillingPeriod` constants. */\n billing_period: BillingPeriodValue\n trial_period_days: number\n prices?: Price[]\n created_at: string\n updated_at: string\n}\n\nexport interface CreatePlanRequest {\n name: string\n description?: string\n /** ISO 4217 currency code. Defaults to `\"NGN\"`. */\n currency?: string\n /** Use `PlanType` constants. Defaults to `\"collection\"`. */\n plan_type?: PlanTypeValue\n /** Use `BillingPeriod` constants. Defaults to `\"monthly\"`. */\n billing_period?: BillingPeriodValue\n /** Trial period in days. Set to `0` for no trial. */\n trial_period_days?: number\n prices?: CreatePriceRequest[]\n}\n\nexport interface UpdatePlanRequest {\n name?: string\n description?: string\n currency?: string\n plan_type?: PlanTypeValue\n billing_period?: BillingPeriodValue\n prices?: UpdatePriceRequest[]\n}\n\nexport interface ListPlansResponse {\n plans: Plan[]\n count: number\n}\n\n// =============================================================================\n// Subscriptions\n// =============================================================================\n\n/** Links a customer to a billing plan. */\nexport interface Subscription {\n id: string\n org_id: string\n customer_id: string\n plan_id: string\n /** Use `SubscriptionStatus` constants. */\n status: SubscriptionStatusValue\n current_period_start: string\n current_period_end: string\n trial_ends_at: string | null\n created_at: string\n updated_at: string\n}\n\nexport interface CreateSubscriptionRequest {\n /** UUID of the customer to subscribe. */\n customer_id: string\n /** UUID of the plan to subscribe the customer to. */\n plan_id: string\n}\n\nexport interface ListSubscriptionsParams {\n /** Filter to a specific customer UUID. */\n customer_id?: string\n /** Filter to a specific plan UUID. */\n plan_id?: string\n /** Filter by status. Use `SubscriptionStatus` constants. */\n status?: SubscriptionStatusValue\n}\n\nexport interface ListSubscriptionsResponse {\n subscriptions: Subscription[]\n count: number\n}\n\n// =============================================================================\n// Payout accounts\n// =============================================================================\n\n/** A bank or mobile-money account that a customer can be paid to. */\nexport interface PayoutAccount {\n id: string\n customer_id: string\n org_id: string\n account_name: string\n bank_name?: string\n bank_code?: string\n account_number?: string\n mobile_money_number?: string\n /** Use `PayoutMethod` constants. */\n payout_method: PayoutMethodValue\n currency: string\n is_default: boolean\n metadata: Record<string, unknown> | null\n created_at: string\n updated_at: string\n}\n\nexport interface CreatePayoutAccountRequest {\n account_name: string\n /** Use `PayoutMethod` constants. */\n payout_method: PayoutMethodValue\n bank_name?: string\n bank_code?: string\n account_number?: string\n mobile_money_number?: string\n currency?: string\n is_default?: boolean\n metadata?: Record<string, unknown>\n}\n\nexport interface UpdatePayoutAccountRequest {\n account_name?: string\n payout_method?: PayoutMethodValue\n bank_name?: string\n account_number?: string\n currency?: string\n is_default?: boolean\n metadata?: Record<string, unknown>\n}\n\nexport interface ListPayoutAccountsResponse {\n payout_accounts: PayoutAccount[]\n count: number\n}\n\n// =============================================================================\n// Invoices\n// =============================================================================\n\n/** One line item on an invoice. */\nexport interface InvoiceLineItem {\n id: string\n invoice_id: string\n metric_id: string\n price_id?: string\n description: string\n quantity: string\n unit_price: string\n /** Amount for this line as a decimal string. */\n amount: string\n created_at: string\n}\n\n/**\n * A billing invoice.\n * All monetary values (`subtotal`, `vat_amount`, `total`) are decimal strings\n * to avoid floating-point precision issues.\n */\nexport interface Invoice {\n id: string\n org_id: string\n customer_id: string\n subscription_id: string\n /** Use `InvoiceStatus` constants. */\n status: InvoiceStatusValue\n currency: string\n subtotal: string\n vat_enabled: boolean\n vat_rate?: string\n vat_amount?: string\n total: string\n period_start: string\n period_end: string\n finalized_at: string | null\n paid_at: string | null\n provider_invoice_id?: string\n line_items?: InvoiceLineItem[]\n created_at: string\n updated_at: string\n}\n\nexport interface ListInvoicesParams {\n /** Filter by status. Use `InvoiceStatus` constants. */\n status?: InvoiceStatusValue\n /** Filter to a specific customer UUID. */\n customer_id?: string\n}\n\nexport interface ListInvoicesResponse {\n invoices: Invoice[]\n count: number\n}\n\n// =============================================================================\n// Usage\n// =============================================================================\n\n/** One aggregated usage record for a (customer, metric, period) tuple. */\nexport interface UsageRollup {\n id: string\n org_id: string\n customer_id: string\n metric_id: string\n period_start: string\n period_end: string\n aggregation: AggregationType\n /** Aggregated value (count, sum, max, etc.). */\n value: number\n event_count: number\n last_event_at: string | null\n is_test: boolean\n created_at: string\n updated_at: string\n}\n\nexport interface UsageQueryParams {\n /** Filter rollups to a specific customer UUID. */\n customer_id?: string\n /** Filter rollups to a specific metric UUID. */\n metric_id?: string\n /**\n * Lower bound for `period_start` (ISO 8601).\n * Defaults to the start of the current billing period.\n */\n from?: string | Date\n /**\n * Exclusive upper bound for `period_start` (ISO 8601).\n * Defaults to the end of the current billing period.\n */\n to?: string | Date\n}\n\nexport interface UsageQueryResult {\n rollups: UsageRollup[]\n count: number\n}\n"],"names":[],"mappings":"AAcO,MAAM,uBAAuB,MAAM;AAAA,EAQxC,YACE,YACA,SACA,SACA;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,UAAU;AACf,SAAK,UAAU;AAEf,UAAM,UAAW,MACf,mBACF;AACA,cAAU,MAAM,cAAc;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,aAAsB;AACxB,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAEA,IAAI,iBAA0B;AAC5B,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAEA,IAAI,cAAuB;AACzB,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAEA,IA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I,eAAe,eAAgB,OAAM;AACzC,UAAI,eAAe,SAAS,IAAI,SAAS,cAAc;AACrD,cAAM,IAAI;AAAA,UACR,4BAA4B,GAAG,oBAAoB,KAAK,QAAQ;AAAA,QAAA;AAAA,MAEpE;AACA,YAAM;AAAA,IACR,UAAA;AACE,mBAAa,SAAS;AAAA,IACxB;AAAA,EACF;AAAA;AAAA,EAGA,OAAO,YAAY,OAA8B;AAC/C,WAAO,iBAAiB,OAAO,MAAM,YAAA,IAAgB;AAAA,EACvD;AACF;ACjMO,MAAM,cAAc;AAAA,EACzB,OAAO;AAAA,EACP,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,SAAS;AAAA,EACT,QAAQ;AACV;AAQO,MAAM,eAAe;AAAA,EAC1B,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,SAAS;AAAA,EACT,gBAAgB;AAClB;AAQO,MAAM,WAAW;AAAA,EACtB,YAAY;AAAA,EACZ,QAAQ;AACV;AAIO,MAAM,gBAAgB;AAAA,EAC3B,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AACZ;AAQO,MAAM,qBAAqB;AAAA,EAChC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AACZ;AAQO,MAAM,gBAAgB;AAAA,EAC3B,OAAO;AAAA,EACP,WAAW;AAAA,EACX,MAAM;AAAA,EACN,MAAM;AACR;AAQO,MAAM,eAAe;AAAA,EAC1B,cAAc;AAAA,EACd,aAAa;AACf;"}
1
+ {"version":3,"file":"monigo.js","sources":["../src/errors.ts","../src/resources/events.ts","../src/resources/customers.ts","../src/resources/metrics.ts","../src/resources/plans.ts","../src/resources/subscriptions.ts","../src/resources/payout-accounts.ts","../src/resources/invoices.ts","../src/resources/usage.ts","../src/client.ts","../src/types.ts"],"sourcesContent":["/**\n * Thrown for any non-2xx response from the Monigo API.\n *\n * @example\n * ```ts\n * try {\n * await client.customers.get('bad-id')\n * } catch (err) {\n * if (MonigoAPIError.isNotFound(err)) {\n * console.log('Customer does not exist')\n * }\n * }\n * ```\n */\nexport class MonigoAPIError extends Error {\n /** HTTP status code returned by the API. */\n readonly statusCode: number\n /** Human-readable error message from the API. */\n readonly message: string\n /** Optional structured field-level validation details. */\n readonly details: Record<string, string> | undefined\n\n constructor(\n statusCode: number,\n message: string,\n details?: Record<string, string>,\n ) {\n super(message)\n this.name = 'MonigoAPIError'\n this.statusCode = statusCode\n this.message = message\n this.details = details\n // Maintain proper stack trace in V8 (Node.js / Chrome)\n const capture = (Error as unknown as Record<string, unknown>)[\n 'captureStackTrace'\n ] as ((target: Error, constructor: Function) => void) | undefined\n capture?.(this, MonigoAPIError)\n }\n\n // -------------------------------------------------------------------------\n // Instance guards (for use on a caught error known to be MonigoAPIError)\n // -------------------------------------------------------------------------\n\n get isNotFound(): boolean {\n return this.statusCode === 404\n }\n\n get isUnauthorized(): boolean {\n return this.statusCode === 401\n }\n\n get isForbidden(): boolean {\n return this.statusCode === 403\n }\n\n get isRateLimited(): boolean {\n return this.statusCode === 429\n }\n\n get isConflict(): boolean {\n return this.statusCode === 409\n }\n\n get isQuotaExceeded(): boolean {\n return this.statusCode === 402\n }\n\n get isServerError(): boolean {\n return this.statusCode >= 500\n }\n\n // -------------------------------------------------------------------------\n // Static type-narrowing helpers (for use in catch clauses on `unknown`)\n // -------------------------------------------------------------------------\n\n static isNotFound(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 404\n }\n\n static isUnauthorized(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 401\n }\n\n static isForbidden(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 403\n }\n\n static isRateLimited(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 429\n }\n\n static isConflict(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 409\n }\n\n static isQuotaExceeded(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode === 402\n }\n\n static isServerError(err: unknown): err is MonigoAPIError {\n return err instanceof MonigoAPIError && err.statusCode >= 500\n }\n}\n","import { MonigoClient } from '../client.js'\nimport type { MutationOptions } from '../client.js'\nimport type {\n IngestRequest,\n IngestResponse,\n StartReplayRequest,\n EventReplayJob,\n} from '../types.js'\n\n/** Handles usage event ingestion and asynchronous event replay. */\nexport class EventsResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Ingest one or more usage events into the Monigo pipeline.\n *\n * Events are processed asynchronously. The response confirms receipt\n * and reports any duplicate idempotency keys.\n *\n * **Requires `ingest` scope.**\n *\n * @example\n * ```ts\n * const result = await monigo.events.ingest({\n * events: [{\n * event_name: 'api_call',\n * customer_id: 'cust_abc',\n * idempotency_key: crypto.randomUUID(),\n * timestamp: new Date().toISOString(),\n * properties: { endpoint: '/checkout', region: 'eu-west-1' },\n * }],\n * })\n * console.log('Ingested:', result.ingested.length)\n * console.log('Duplicates:', result.duplicates.length)\n * ```\n */\n async ingest(request: IngestRequest, options?: MutationOptions): Promise<IngestResponse> {\n const body = {\n events: request.events.map((e) => ({\n ...e,\n timestamp: e.timestamp\n ? MonigoClient.toISOString(e.timestamp)\n : new Date().toISOString(),\n })),\n }\n return this.client._request<IngestResponse>('POST', '/v1/ingest', {\n body,\n idempotencyKey: options?.idempotencyKey,\n })\n }\n\n /**\n * Start an asynchronous replay of all raw events in a given time window\n * through the current processing pipeline. Useful for backfilling usage\n * data after changing metric definitions.\n *\n * Returns a replay job immediately — poll `getReplay()` to track progress.\n *\n * **Requires `ingest` scope.**\n *\n * @example\n * ```ts\n * const job = await monigo.events.startReplay({\n * from: '2025-01-01T00:00:00Z',\n * to: '2025-01-31T23:59:59Z',\n * event_name: 'api_call', // omit to replay all event types\n * })\n * console.log('Replay job:', job.id, job.status)\n * ```\n */\n async startReplay(request: StartReplayRequest, options?: MutationOptions): Promise<EventReplayJob> {\n const body = {\n from: MonigoClient.toISOString(request.from),\n to: MonigoClient.toISOString(request.to),\n ...(request.event_name ? { event_name: request.event_name } : {}),\n }\n const wrapper = await this.client._request<{ job: EventReplayJob }>(\n 'POST',\n '/v1/events/replay',\n { body, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.job\n }\n\n /**\n * Fetch the current status and progress of an event replay job.\n *\n * **Requires `ingest` scope.**\n *\n * @example\n * ```ts\n * const job = await monigo.events.getReplay(jobId)\n * if (job.status === 'completed') {\n * console.log(`Replayed ${job.events_replayed} / ${job.events_total} events`)\n * }\n * ```\n */\n async getReplay(jobId: string): Promise<EventReplayJob> {\n const wrapper = await this.client._request<{ job: EventReplayJob }>(\n 'GET',\n `/v1/events/replay/${jobId}`,\n )\n return wrapper.job\n }\n}\n","import type { MonigoClient, MutationOptions } from '../client.js'\nimport type {\n Customer,\n CreateCustomerRequest,\n UpdateCustomerRequest,\n ListCustomersResponse,\n} from '../types.js'\n\n/** Manage end-customers in your Monigo organisation. */\nexport class CustomersResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Register a new customer.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const customer = await monigo.customers.create({\n * external_id: 'usr_12345',\n * name: 'Acme Corp',\n * email: 'billing@acme.com',\n * metadata: { plan_tier: 'enterprise' },\n * })\n * ```\n */\n async create(request: CreateCustomerRequest, options?: MutationOptions): Promise<Customer> {\n const wrapper = await this.client._request<{ customer: Customer }>(\n 'POST',\n '/v1/customers',\n { body: request, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.customer\n }\n\n /**\n * Return all customers in the authenticated organisation.\n *\n * **Requires `read` scope.**\n */\n async list(): Promise<ListCustomersResponse> {\n return this.client._request<ListCustomersResponse>('GET', '/v1/customers')\n }\n\n /**\n * Fetch a single customer by their Monigo UUID.\n *\n * **Requires `read` scope.**\n */\n async get(customerId: string): Promise<Customer> {\n const wrapper = await this.client._request<{ customer: Customer }>(\n 'GET',\n `/v1/customers/${customerId}`,\n )\n return wrapper.customer\n }\n\n /**\n * Update a customer's name, email, or metadata.\n * Only fields that are present in `request` are updated.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const updated = await monigo.customers.update(customerId, {\n * email: 'new@acme.com',\n * })\n * ```\n */\n async update(\n customerId: string,\n request: UpdateCustomerRequest,\n options?: MutationOptions,\n ): Promise<Customer> {\n const wrapper = await this.client._request<{ customer: Customer }>(\n 'PUT',\n `/v1/customers/${customerId}`,\n { body: request, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.customer\n }\n\n /**\n * Permanently delete a customer record.\n *\n * **Requires `write` scope.**\n */\n async delete(customerId: string): Promise<void> {\n await this.client._request<void>('DELETE', `/v1/customers/${customerId}`)\n }\n}\n","import type { MonigoClient, MutationOptions } from '../client.js'\nimport type {\n Metric,\n CreateMetricRequest,\n UpdateMetricRequest,\n ListMetricsResponse,\n} from '../types.js'\n\n/** Manage billing metrics — what usage gets counted and how it is aggregated. */\nexport class MetricsResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Create a new metric.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const metric = await monigo.metrics.create({\n * name: 'API Calls',\n * event_name: 'api_call',\n * aggregation: 'count',\n * })\n * ```\n */\n async create(request: CreateMetricRequest, options?: MutationOptions): Promise<Metric> {\n const wrapper = await this.client._request<{ metric: Metric }>(\n 'POST',\n '/v1/metrics',\n { body: request, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.metric\n }\n\n /**\n * Return all metrics in the authenticated organisation.\n *\n * **Requires `read` scope.**\n */\n async list(): Promise<ListMetricsResponse> {\n return this.client._request<ListMetricsResponse>('GET', '/v1/metrics')\n }\n\n /**\n * Fetch a single metric by its UUID.\n *\n * **Requires `read` scope.**\n */\n async get(metricId: string): Promise<Metric> {\n const wrapper = await this.client._request<{ metric: Metric }>(\n 'GET',\n `/v1/metrics/${metricId}`,\n )\n return wrapper.metric\n }\n\n /**\n * Update a metric's name, event name, aggregation, or description.\n *\n * **Requires `write` scope.**\n */\n async update(metricId: string, request: UpdateMetricRequest, options?: MutationOptions): Promise<Metric> {\n const wrapper = await this.client._request<{ metric: Metric }>(\n 'PUT',\n `/v1/metrics/${metricId}`,\n { body: request, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.metric\n }\n\n /**\n * Permanently delete a metric.\n *\n * **Requires `write` scope.**\n */\n async delete(metricId: string): Promise<void> {\n await this.client._request<void>('DELETE', `/v1/metrics/${metricId}`)\n }\n}\n","import type { MonigoClient, MutationOptions } from '../client.js'\nimport type {\n Plan,\n CreatePlanRequest,\n UpdatePlanRequest,\n ListPlansResponse,\n} from '../types.js'\n\n/** Manage billing plans and their prices. */\nexport class PlansResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Create a new billing plan, optionally with prices attached.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const plan = await monigo.plans.create({\n * name: 'Pro',\n * currency: 'NGN',\n * billing_period: 'monthly',\n * prices: [{\n * metric_id: 'metric_abc',\n * model: 'flat',\n * unit_price: '2.500000',\n * }],\n * })\n * ```\n */\n async create(request: CreatePlanRequest, options?: MutationOptions): Promise<Plan> {\n const wrapper = await this.client._request<{ plan: Plan }>(\n 'POST',\n '/v1/plans',\n { body: request, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.plan\n }\n\n /**\n * Return all billing plans in the authenticated organisation.\n *\n * **Requires `read` scope.**\n */\n async list(): Promise<ListPlansResponse> {\n return this.client._request<ListPlansResponse>('GET', '/v1/plans')\n }\n\n /**\n * Fetch a single plan by its UUID, including its prices.\n *\n * **Requires `read` scope.**\n */\n async get(planId: string): Promise<Plan> {\n const wrapper = await this.client._request<{ plan: Plan }>(\n 'GET',\n `/v1/plans/${planId}`,\n )\n return wrapper.plan\n }\n\n /**\n * Update a plan's name, description, currency, or prices.\n *\n * **Requires `write` scope.**\n */\n async update(planId: string, request: UpdatePlanRequest, options?: MutationOptions): Promise<Plan> {\n const wrapper = await this.client._request<{ plan: Plan }>(\n 'PUT',\n `/v1/plans/${planId}`,\n { body: request, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.plan\n }\n\n /**\n * Permanently delete a plan.\n *\n * **Requires `write` scope.**\n */\n async delete(planId: string): Promise<void> {\n await this.client._request<void>('DELETE', `/v1/plans/${planId}`)\n }\n}\n","import type { MonigoClient, MutationOptions } from '../client.js'\nimport type {\n Subscription,\n CreateSubscriptionRequest,\n ListSubscriptionsParams,\n ListSubscriptionsResponse,\n SubscriptionStatusValue,\n} from '../types.js'\n\n/** Link customers to billing plans and manage subscription lifecycle. */\nexport class SubscriptionsResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Subscribe a customer to a plan.\n *\n * Returns a 409 Conflict error (check with `MonigoAPIError.isConflict(err)`)\n * if the customer already has an active subscription to the same plan.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const sub = await monigo.subscriptions.create({\n * customer_id: 'cust_abc',\n * plan_id: 'plan_xyz',\n * })\n * ```\n */\n async create(request: CreateSubscriptionRequest, options?: MutationOptions): Promise<Subscription> {\n const wrapper = await this.client._request<{ subscription: Subscription }>(\n 'POST',\n '/v1/subscriptions',\n { body: request, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.subscription\n }\n\n /**\n * Return subscriptions, optionally filtered by customer, plan, or status.\n *\n * **Requires `read` scope.**\n *\n * @example\n * ```ts\n * const { subscriptions } = await monigo.subscriptions.list({\n * customer_id: 'cust_abc',\n * status: 'active',\n * })\n * ```\n */\n async list(params: ListSubscriptionsParams = {}): Promise<ListSubscriptionsResponse> {\n return this.client._request<ListSubscriptionsResponse>('GET', '/v1/subscriptions', {\n query: {\n customer_id: params.customer_id,\n plan_id: params.plan_id,\n status: params.status,\n },\n })\n }\n\n /**\n * Fetch a single subscription by its UUID.\n *\n * **Requires `read` scope.**\n */\n async get(subscriptionId: string): Promise<Subscription> {\n const wrapper = await this.client._request<{ subscription: Subscription }>(\n 'GET',\n `/v1/subscriptions/${subscriptionId}`,\n )\n return wrapper.subscription\n }\n\n /**\n * Change the status of a subscription.\n * Use `SubscriptionStatus` constants: `\"active\"`, `\"paused\"`, `\"canceled\"`.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * await monigo.subscriptions.updateStatus(subId, SubscriptionStatus.Paused)\n * ```\n */\n async updateStatus(\n subscriptionId: string,\n status: SubscriptionStatusValue,\n options?: MutationOptions,\n ): Promise<Subscription> {\n const wrapper = await this.client._request<{ subscription: Subscription }>(\n 'PATCH',\n `/v1/subscriptions/${subscriptionId}`,\n { body: { status }, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.subscription\n }\n\n /**\n * Cancel and delete a subscription record.\n *\n * **Requires `write` scope.**\n */\n async delete(subscriptionId: string): Promise<void> {\n await this.client._request<void>('DELETE', `/v1/subscriptions/${subscriptionId}`)\n }\n}\n","import type { MonigoClient, MutationOptions } from '../client.js'\nimport type {\n PayoutAccount,\n CreatePayoutAccountRequest,\n UpdatePayoutAccountRequest,\n ListPayoutAccountsResponse,\n} from '../types.js'\n\n/** Manage bank and mobile-money payout accounts for customers. */\nexport class PayoutAccountsResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Add a payout account for a customer.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const account = await monigo.payoutAccounts.create('cust_abc', {\n * account_name: 'Acme Corp',\n * payout_method: 'bank_transfer',\n * bank_name: 'Zenith Bank',\n * bank_code: '057',\n * account_number: '1234567890',\n * currency: 'NGN',\n * is_default: true,\n * })\n * ```\n */\n async create(\n customerId: string,\n request: CreatePayoutAccountRequest,\n options?: MutationOptions,\n ): Promise<PayoutAccount> {\n const wrapper = await this.client._request<{ payout_account: PayoutAccount }>(\n 'POST',\n `/v1/customers/${customerId}/payout-accounts`,\n { body: request, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.payout_account\n }\n\n /**\n * Return all payout accounts for a customer.\n *\n * **Requires `read` scope.**\n */\n async list(customerId: string): Promise<ListPayoutAccountsResponse> {\n return this.client._request<ListPayoutAccountsResponse>(\n 'GET',\n `/v1/customers/${customerId}/payout-accounts`,\n )\n }\n\n /**\n * Fetch a single payout account by its UUID.\n *\n * **Requires `read` scope.**\n */\n async get(customerId: string, accountId: string): Promise<PayoutAccount> {\n const wrapper = await this.client._request<{ payout_account: PayoutAccount }>(\n 'GET',\n `/v1/customers/${customerId}/payout-accounts/${accountId}`,\n )\n return wrapper.payout_account\n }\n\n /**\n * Update a payout account's details.\n *\n * **Requires `write` scope.**\n */\n async update(\n customerId: string,\n accountId: string,\n request: UpdatePayoutAccountRequest,\n options?: MutationOptions,\n ): Promise<PayoutAccount> {\n const wrapper = await this.client._request<{ payout_account: PayoutAccount }>(\n 'PUT',\n `/v1/customers/${customerId}/payout-accounts/${accountId}`,\n { body: request, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.payout_account\n }\n\n /**\n * Delete a payout account.\n *\n * **Requires `write` scope.**\n */\n async delete(customerId: string, accountId: string): Promise<void> {\n await this.client._request<void>(\n 'DELETE',\n `/v1/customers/${customerId}/payout-accounts/${accountId}`,\n )\n }\n}\n","import type { MonigoClient, MutationOptions } from '../client.js'\nimport type {\n Invoice,\n ListInvoicesParams,\n ListInvoicesResponse,\n} from '../types.js'\n\n/** Manage invoice generation, finalization, and voiding. */\nexport class InvoicesResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Generate a draft invoice for a subscription based on current period usage.\n * The invoice starts in `\"draft\"` status and is not sent to the customer yet.\n *\n * **Requires `write` scope.**\n *\n * @example\n * ```ts\n * const invoice = await monigo.invoices.generate('sub_xyz')\n * console.log('Draft invoice total:', invoice.total)\n * ```\n */\n async generate(subscriptionId: string, options?: MutationOptions): Promise<Invoice> {\n const wrapper = await this.client._request<{ invoice: Invoice }>(\n 'POST',\n '/v1/invoices/generate',\n { body: { subscription_id: subscriptionId }, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.invoice\n }\n\n /**\n * Return invoices, optionally filtered by status or customer.\n *\n * **Requires `read` scope.**\n *\n * @example\n * ```ts\n * const { invoices } = await monigo.invoices.list({\n * status: 'finalized',\n * customer_id: 'cust_abc',\n * })\n * ```\n */\n async list(params: ListInvoicesParams = {}): Promise<ListInvoicesResponse> {\n return this.client._request<ListInvoicesResponse>('GET', '/v1/invoices', {\n query: {\n status: params.status,\n customer_id: params.customer_id,\n },\n })\n }\n\n /**\n * Fetch a single invoice by its UUID, including line items.\n *\n * **Requires `read` scope.**\n */\n async get(invoiceId: string): Promise<Invoice> {\n const wrapper = await this.client._request<{ invoice: Invoice }>(\n 'GET',\n `/v1/invoices/${invoiceId}`,\n )\n return wrapper.invoice\n }\n\n /**\n * Finalize a draft invoice, making it ready for payment.\n * A finalized invoice cannot be edited.\n *\n * **Requires `write` scope.**\n */\n async finalize(invoiceId: string, options?: MutationOptions): Promise<Invoice> {\n const wrapper = await this.client._request<{ invoice: Invoice }>(\n 'POST',\n `/v1/invoices/${invoiceId}/finalize`,\n { idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.invoice\n }\n\n /**\n * Void an invoice, making it permanently non-payable.\n * Only admins and owners can void invoices.\n *\n * **Requires `write` scope.**\n */\n async void(invoiceId: string, options?: MutationOptions): Promise<Invoice> {\n const wrapper = await this.client._request<{ invoice: Invoice }>(\n 'POST',\n `/v1/invoices/${invoiceId}/void`,\n { idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.invoice\n }\n}\n","import { MonigoClient } from '../client.js'\nimport type { UsageQueryParams, UsageQueryResult } from '../types.js'\n\n/** Query aggregated usage rollups from the Monigo metering pipeline. */\nexport class UsageResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Return per-customer, per-metric usage rollups for the organisation.\n * All parameters are optional — omitting them returns the full current\n * billing period for all customers and metrics.\n *\n * **Requires `read` scope.**\n *\n * @example\n * ```ts\n * // All usage for one customer this period\n * const { rollups } = await monigo.usage.query({\n * customer_id: 'cust_abc',\n * })\n *\n * // Filtered by metric and custom date range\n * const { rollups: filtered } = await monigo.usage.query({\n * metric_id: 'metric_xyz',\n * from: '2025-01-01T00:00:00Z',\n * to: '2025-01-31T23:59:59Z',\n * })\n * ```\n */\n async query(params: UsageQueryParams = {}): Promise<UsageQueryResult> {\n const query: Record<string, string | undefined> = {\n customer_id: params.customer_id,\n metric_id: params.metric_id,\n }\n if (params.from !== undefined) {\n query.from = MonigoClient.toISOString(params.from)\n }\n if (params.to !== undefined) {\n query.to = MonigoClient.toISOString(params.to)\n }\n return this.client._request<UsageQueryResult>('GET', '/v1/usage', { query })\n }\n}\n","import { MonigoAPIError } from './errors.js'\nimport { EventsResource } from './resources/events.js'\nimport { CustomersResource } from './resources/customers.js'\nimport { MetricsResource } from './resources/metrics.js'\nimport { PlansResource } from './resources/plans.js'\nimport { SubscriptionsResource } from './resources/subscriptions.js'\nimport { PayoutAccountsResource } from './resources/payout-accounts.js'\nimport { InvoicesResource } from './resources/invoices.js'\nimport { UsageResource } from './resources/usage.js'\n\nconst DEFAULT_BASE_URL = 'https://api.monigo.co'\nconst DEFAULT_TIMEOUT_MS = 30_000\n\nexport interface MonigoClientOptions {\n /**\n * Your Monigo API key. Obtain one from the API Keys section of your\n * Monigo dashboard. Never expose this key in client-side code.\n */\n apiKey: string\n /**\n * Override the default API base URL (`https://api.monigo.co`).\n * Useful for self-hosted deployments or pointing at a local dev server.\n *\n * @default \"https://api.monigo.co\"\n */\n baseURL?: string\n /**\n * Custom `fetch` implementation. Defaults to `globalThis.fetch`.\n * Pass a polyfill for environments that do not have native fetch\n * (Node.js < 18) or to inject a mock in tests.\n */\n fetch?: typeof globalThis.fetch\n /**\n * Request timeout in milliseconds.\n *\n * @default 30000\n */\n timeout?: number\n}\n\n/**\n * Options accepted by every mutating method (POST, PUT, PATCH).\n */\nexport interface MutationOptions {\n /**\n * A unique key that prevents the same request from being processed more than\n * once. Pass a stable value (e.g. a request ID from your own system) to make\n * retries safe. When omitted, the SDK generates a UUID v4 automatically.\n */\n idempotencyKey?: string\n}\n\n/** @internal */\nexport interface RequestOptions {\n body?: unknown\n query?: Record<string, string | undefined>\n idempotencyKey?: string\n}\n\n/**\n * The Monigo API client.\n *\n * Instantiate once and reuse across your application:\n *\n * ```ts\n * import { MonigoClient } from '@monigo/sdk'\n *\n * const monigo = new MonigoClient({ apiKey: process.env.MONIGO_API_KEY! })\n *\n * // Ingest a usage event\n * await monigo.events.ingest({\n * events: [{\n * event_name: 'api_call',\n * customer_id: 'cust_abc123',\n * idempotency_key: crypto.randomUUID(),\n * }],\n * })\n * ```\n */\nexport class MonigoClient {\n /** @internal */\n readonly _apiKey: string\n /** @internal */\n readonly _baseURL: string\n /** @internal */\n readonly _fetchFn: typeof globalThis.fetch\n /** @internal */\n readonly _timeout: number\n\n /** Ingest usage events and manage event replays. Requires `ingest` scope. */\n readonly events: EventsResource\n /** Manage your end-customers (CRUD). Requires `read` / `write` scope. */\n readonly customers: CustomersResource\n /** Manage billing metrics — what gets counted and how. Requires `read` / `write` scope. */\n readonly metrics: MetricsResource\n /** Manage billing plans and their prices. Requires `read` / `write` scope. */\n readonly plans: PlansResource\n /** Link customers to plans and manage subscription lifecycle. Requires `read` / `write` scope. */\n readonly subscriptions: SubscriptionsResource\n /** Manage bank / mobile-money payout accounts for customers. Requires `read` / `write` scope. */\n readonly payoutAccounts: PayoutAccountsResource\n /** Generate, list, finalize, and void invoices. Requires `read` / `write` scope. */\n readonly invoices: InvoicesResource\n /** Query aggregated usage rollups per customer and metric. Requires `read` scope. */\n readonly usage: UsageResource\n\n constructor(options: MonigoClientOptions) {\n if (!options.apiKey) {\n throw new Error('MonigoClient: apiKey is required')\n }\n\n this._apiKey = options.apiKey\n this._baseURL = (options.baseURL ?? DEFAULT_BASE_URL).replace(/\\/$/, '')\n this._timeout = options.timeout ?? DEFAULT_TIMEOUT_MS\n\n const fetchFn = options.fetch ?? (typeof globalThis !== 'undefined' ? globalThis.fetch : undefined)\n if (!fetchFn) {\n throw new Error(\n 'MonigoClient: fetch is not available in this environment. ' +\n 'Pass a custom fetch implementation via options.fetch, ' +\n 'or upgrade to Node.js 18+.',\n )\n }\n this._fetchFn = fetchFn.bind(globalThis)\n\n this.events = new EventsResource(this)\n this.customers = new CustomersResource(this)\n this.metrics = new MetricsResource(this)\n this.plans = new PlansResource(this)\n this.subscriptions = new SubscriptionsResource(this)\n this.payoutAccounts = new PayoutAccountsResource(this)\n this.invoices = new InvoicesResource(this)\n this.usage = new UsageResource(this)\n }\n\n /**\n * Execute an authenticated HTTP request against the Monigo API.\n * @internal — use the resource methods instead.\n */\n async _request<T>(\n method: string,\n path: string,\n options: RequestOptions = {},\n ): Promise<T> {\n let url = this._baseURL + path\n\n if (options.query) {\n const params = new URLSearchParams()\n for (const [key, value] of Object.entries(options.query)) {\n if (value !== undefined && value !== '') {\n params.set(key, value)\n }\n }\n const qs = params.toString()\n if (qs) url += '?' + qs\n }\n\n const controller = new AbortController()\n const timeoutId = setTimeout(() => controller.abort(), this._timeout)\n\n const isMutating = method === 'POST' || method === 'PUT' || method === 'PATCH'\n const idempotencyKey = isMutating\n ? (options.idempotencyKey ?? globalThis.crypto.randomUUID())\n : undefined\n\n try {\n const response = await this._fetchFn(url, {\n method,\n headers: {\n Authorization: `Bearer ${this._apiKey}`,\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n ...(idempotencyKey ? { 'Idempotency-Key': idempotencyKey } : {}),\n },\n body: options.body != null ? JSON.stringify(options.body) : undefined,\n signal: controller.signal,\n })\n\n const text = await response.text()\n\n if (!response.ok) {\n let message = text || response.statusText\n let details: Record<string, string> | undefined\n try {\n const parsed = JSON.parse(text) as {\n error?: string\n message?: string\n details?: Record<string, string>\n }\n message = parsed.error ?? parsed.message ?? message\n details = parsed.details\n } catch {\n // Use raw text as the error message\n }\n throw new MonigoAPIError(response.status, message, details)\n }\n\n if (!text) return undefined as T\n return JSON.parse(text) as T\n } catch (err) {\n if (err instanceof MonigoAPIError) throw err\n if (err instanceof Error && err.name === 'AbortError') {\n throw new Error(\n `MonigoClient: request to ${url} timed out after ${this._timeout}ms`,\n )\n }\n throw err\n } finally {\n clearTimeout(timeoutId)\n }\n }\n\n /** Normalise a `Date | string` value to an ISO 8601 string. */\n static toISOString(value: string | Date): string {\n return value instanceof Date ? value.toISOString() : value\n }\n}\n","// =============================================================================\n// Aggregation constants\n// =============================================================================\n\nexport const Aggregation = {\n Count: 'count',\n Sum: 'sum',\n Max: 'max',\n Min: 'minimum',\n Average: 'average',\n Unique: 'unique',\n} as const\n\nexport type AggregationType = (typeof Aggregation)[keyof typeof Aggregation]\n\n// =============================================================================\n// Pricing model constants\n// =============================================================================\n\nexport const PricingModel = {\n Flat: 'flat',\n Tiered: 'tiered',\n Volume: 'volume',\n Package: 'package',\n Overage: 'overage',\n WeightedTiered: 'weighted_tiered',\n} as const\n\nexport type PricingModelType = (typeof PricingModel)[keyof typeof PricingModel]\n\n// =============================================================================\n// Plan constants\n// =============================================================================\n\nexport const PlanType = {\n Collection: 'collection',\n Payout: 'payout',\n} as const\n\nexport type PlanTypeValue = (typeof PlanType)[keyof typeof PlanType]\n\nexport const BillingPeriod = {\n Daily: 'daily',\n Weekly: 'weekly',\n Monthly: 'monthly',\n Quarterly: 'quarterly',\n Annually: 'annually',\n} as const\n\nexport type BillingPeriodValue = (typeof BillingPeriod)[keyof typeof BillingPeriod]\n\n// =============================================================================\n// Subscription status constants\n// =============================================================================\n\nexport const SubscriptionStatus = {\n Active: 'active',\n Paused: 'paused',\n Canceled: 'canceled',\n} as const\n\nexport type SubscriptionStatusValue = (typeof SubscriptionStatus)[keyof typeof SubscriptionStatus]\n\n// =============================================================================\n// Invoice status constants\n// =============================================================================\n\nexport const InvoiceStatus = {\n Draft: 'draft',\n Finalized: 'finalized',\n Paid: 'paid',\n Void: 'void',\n} as const\n\nexport type InvoiceStatusValue = (typeof InvoiceStatus)[keyof typeof InvoiceStatus]\n\n// =============================================================================\n// Payout method constants\n// =============================================================================\n\nexport const PayoutMethod = {\n BankTransfer: 'bank_transfer',\n MobileMoney: 'mobile_money',\n} as const\n\nexport type PayoutMethodValue = (typeof PayoutMethod)[keyof typeof PayoutMethod]\n\n// =============================================================================\n// Events\n// =============================================================================\n\n/** A single usage event sent to the Monigo ingestion pipeline. */\nexport interface IngestEvent {\n /**\n * The name of the event, e.g. `\"api_call\"` or `\"storage.write\"`.\n * Must match the `event_name` on one or more metrics you have configured.\n */\n event_name: string\n /** The Monigo customer UUID this event belongs to. */\n customer_id: string\n /**\n * A unique key for this event. Re-sending the same key is safe — the server\n * will de-duplicate automatically. Use a UUID or any stable ID you control.\n */\n idempotency_key: string\n /**\n * ISO 8601 timestamp for when the event occurred. Backdated events are\n * accepted within the configured replay window. Defaults to now if omitted.\n */\n timestamp?: string | Date\n /**\n * Arbitrary key-value pairs attached to the event. Use these for dimensions\n * such as `{ endpoint: \"/checkout\", region: \"eu-west-1\" }`.\n */\n properties?: Record<string, unknown>\n}\n\n/** Request body for `POST /v1/ingest`. */\nexport interface IngestRequest {\n events: IngestEvent[]\n}\n\n/** Response from `POST /v1/ingest`. */\nexport interface IngestResponse {\n /** Idempotency keys of events that were successfully ingested. */\n ingested: string[]\n /** Idempotency keys that were skipped because they already existed. */\n duplicates: string[]\n}\n\n/** Request body for `POST /v1/events/replay`. */\nexport interface StartReplayRequest {\n /** Start of the replay window (ISO 8601). */\n from: string | Date\n /** End of the replay window (ISO 8601). */\n to: string | Date\n /** Optional event name to replay. Omit to replay all event types. */\n event_name?: string\n}\n\n/** Tracks the progress of an asynchronous event replay job. */\nexport interface EventReplayJob {\n id: string\n org_id: string\n initiated_by: string\n /** `pending` | `processing` | `completed` | `failed` */\n status: string\n from_timestamp: string\n to_timestamp: string\n event_name: string | null\n is_test: boolean\n events_total: number\n events_replayed: number\n error_message: string | null\n started_at: string | null\n completed_at: string | null\n created_at: string\n updated_at: string\n}\n\n// =============================================================================\n// Customers\n// =============================================================================\n\n/** An end-customer record in your Monigo organisation. */\nexport interface Customer {\n id: string\n org_id: string\n /** The ID for this customer in your own system. */\n external_id: string\n name: string\n email: string\n /** Phone number in E.164 international format (e.g. +2348012345678). */\n phone: string\n /** Arbitrary JSON metadata. */\n metadata: Record<string, unknown> | null\n created_at: string\n updated_at: string\n}\n\nexport interface CreateCustomerRequest {\n /** Your internal ID for this customer. */\n external_id: string\n name: string\n email?: string\n /** Phone number in E.164 international format (e.g. +2348012345678). Optional. */\n phone?: string\n metadata?: Record<string, unknown>\n}\n\nexport interface UpdateCustomerRequest {\n name?: string\n email?: string\n /** Phone number in E.164 international format (e.g. +2348012345678). Optional. */\n phone?: string\n metadata?: Record<string, unknown>\n}\n\nexport interface ListCustomersResponse {\n customers: Customer[]\n count: number\n}\n\n// =============================================================================\n// Metrics\n// =============================================================================\n\n/** Defines what usage is counted and how. */\nexport interface Metric {\n id: string\n org_id: string\n name: string\n /** The `event_name` value that this metric tracks. */\n event_name: string\n /** How events are aggregated. Use `Aggregation` constants. */\n aggregation: AggregationType\n /** For sum/max/min/average: the Properties key whose value is used. */\n aggregation_property?: string\n description?: string\n created_at: string\n updated_at: string\n}\n\nexport interface CreateMetricRequest {\n /** Human-readable label, e.g. `\"API Calls\"`. */\n name: string\n /** The `event_name` value to track. */\n event_name: string\n /** How events are aggregated. Use `Aggregation` constants. */\n aggregation: AggregationType\n description?: string\n /** Required for sum/max/min/average aggregations. */\n aggregation_property?: string\n}\n\nexport interface UpdateMetricRequest {\n name?: string\n event_name?: string\n aggregation?: AggregationType\n description?: string\n aggregation_property?: string\n}\n\nexport interface ListMetricsResponse {\n metrics: Metric[]\n count: number\n}\n\n// =============================================================================\n// Plans & Prices\n// =============================================================================\n\n/**\n * One price step in a tiered/volume/weighted_tiered pricing model.\n * Set `up_to` to `null` for the final (infinite) tier.\n */\nexport interface PriceTier {\n up_to: number | null\n /** Price per unit in this tier as a decimal string, e.g. `\"0.50\"`. */\n unit_amount: string\n}\n\n/** Describes a price to attach when creating a plan. */\nexport interface CreatePriceRequest {\n /** UUID of the metric this price is based on. */\n metric_id: string\n /** Pricing model. Use `PricingModel` constants. */\n model: PricingModelType\n /** Flat price per unit as a decimal string (used for flat/overage/package models). */\n unit_price?: string\n /** Price tiers for tiered/volume/weighted_tiered models. */\n tiers?: PriceTier[]\n}\n\n/** Describes an updated price. Include `id` to update an existing price; omit to add a new one. */\nexport interface UpdatePriceRequest {\n id?: string\n metric_id?: string\n model?: PricingModelType\n unit_price?: string\n tiers?: PriceTier[]\n}\n\n/** A pricing rule attached to a plan. */\nexport interface Price {\n id: string\n plan_id: string\n metric_id: string\n model: PricingModelType\n unit_price: string\n tiers: PriceTier[] | null\n created_at: string\n updated_at: string\n}\n\n/** A billing plan that defines pricing for one or more metrics. */\nexport interface Plan {\n id: string\n org_id: string\n name: string\n description?: string\n /** ISO 4217 currency code, e.g. `\"NGN\"`. */\n currency: string\n /** Use `PlanType` constants. */\n plan_type: PlanTypeValue\n /** Use `BillingPeriod` constants. */\n billing_period: BillingPeriodValue\n trial_period_days: number\n prices?: Price[]\n created_at: string\n updated_at: string\n}\n\nexport interface CreatePlanRequest {\n name: string\n description?: string\n /** ISO 4217 currency code. Defaults to `\"NGN\"`. */\n currency?: string\n /** Use `PlanType` constants. Defaults to `\"collection\"`. */\n plan_type?: PlanTypeValue\n /** Use `BillingPeriod` constants. Defaults to `\"monthly\"`. */\n billing_period?: BillingPeriodValue\n /** Trial period in days. Set to `0` for no trial. */\n trial_period_days?: number\n prices?: CreatePriceRequest[]\n}\n\nexport interface UpdatePlanRequest {\n name?: string\n description?: string\n currency?: string\n plan_type?: PlanTypeValue\n billing_period?: BillingPeriodValue\n prices?: UpdatePriceRequest[]\n}\n\nexport interface ListPlansResponse {\n plans: Plan[]\n count: number\n}\n\n// =============================================================================\n// Subscriptions\n// =============================================================================\n\n/** Links a customer to a billing plan. */\nexport interface Subscription {\n id: string\n org_id: string\n customer_id: string\n plan_id: string\n /** Use `SubscriptionStatus` constants. */\n status: SubscriptionStatusValue\n current_period_start: string\n current_period_end: string\n trial_ends_at: string | null\n created_at: string\n updated_at: string\n}\n\nexport interface CreateSubscriptionRequest {\n /** UUID of the customer to subscribe. */\n customer_id: string\n /** UUID of the plan to subscribe the customer to. */\n plan_id: string\n}\n\nexport interface ListSubscriptionsParams {\n /** Filter to a specific customer UUID. */\n customer_id?: string\n /** Filter to a specific plan UUID. */\n plan_id?: string\n /** Filter by status. Use `SubscriptionStatus` constants. */\n status?: SubscriptionStatusValue\n}\n\nexport interface ListSubscriptionsResponse {\n subscriptions: Subscription[]\n count: number\n}\n\n// =============================================================================\n// Payout accounts\n// =============================================================================\n\n/** A bank or mobile-money account that a customer can be paid to. */\nexport interface PayoutAccount {\n id: string\n customer_id: string\n org_id: string\n account_name: string\n bank_name?: string\n bank_code?: string\n account_number?: string\n mobile_money_number?: string\n /** Use `PayoutMethod` constants. */\n payout_method: PayoutMethodValue\n currency: string\n is_default: boolean\n metadata: Record<string, unknown> | null\n created_at: string\n updated_at: string\n}\n\nexport interface CreatePayoutAccountRequest {\n account_name: string\n /** Use `PayoutMethod` constants. */\n payout_method: PayoutMethodValue\n bank_name?: string\n bank_code?: string\n account_number?: string\n mobile_money_number?: string\n currency?: string\n is_default?: boolean\n metadata?: Record<string, unknown>\n}\n\nexport interface UpdatePayoutAccountRequest {\n account_name?: string\n payout_method?: PayoutMethodValue\n bank_name?: string\n account_number?: string\n currency?: string\n is_default?: boolean\n metadata?: Record<string, unknown>\n}\n\nexport interface ListPayoutAccountsResponse {\n payout_accounts: PayoutAccount[]\n count: number\n}\n\n// =============================================================================\n// Invoices\n// =============================================================================\n\n/** One line item on an invoice. */\nexport interface InvoiceLineItem {\n id: string\n invoice_id: string\n metric_id: string\n price_id?: string\n description: string\n quantity: string\n unit_price: string\n /** Amount for this line as a decimal string. */\n amount: string\n created_at: string\n}\n\n/**\n * A billing invoice.\n * All monetary values (`subtotal`, `vat_amount`, `total`) are decimal strings\n * to avoid floating-point precision issues.\n */\nexport interface Invoice {\n id: string\n org_id: string\n customer_id: string\n subscription_id: string\n /** Use `InvoiceStatus` constants. */\n status: InvoiceStatusValue\n currency: string\n subtotal: string\n vat_enabled: boolean\n vat_rate?: string\n vat_amount?: string\n total: string\n period_start: string\n period_end: string\n finalized_at: string | null\n paid_at: string | null\n provider_invoice_id?: string\n line_items?: InvoiceLineItem[]\n created_at: string\n updated_at: string\n}\n\nexport interface ListInvoicesParams {\n /** Filter by status. Use `InvoiceStatus` constants. */\n status?: InvoiceStatusValue\n /** Filter to a specific customer UUID. */\n customer_id?: string\n}\n\nexport interface ListInvoicesResponse {\n invoices: Invoice[]\n count: number\n}\n\n// =============================================================================\n// Usage\n// =============================================================================\n\n/** One aggregated usage record for a (customer, metric, period) tuple. */\nexport interface UsageRollup {\n id: string\n org_id: string\n customer_id: string\n metric_id: string\n period_start: string\n period_end: string\n aggregation: AggregationType\n /** Aggregated value (count, sum, max, etc.). */\n value: number\n event_count: number\n last_event_at: string | null\n is_test: boolean\n created_at: string\n updated_at: string\n}\n\nexport interface UsageQueryParams {\n /** Filter rollups to a specific customer UUID. */\n customer_id?: string\n /** Filter rollups to a specific metric UUID. */\n metric_id?: string\n /**\n * Lower bound for `period_start` (ISO 8601).\n * Defaults to the start of the current billing period.\n */\n from?: string | Date\n /**\n * Exclusive upper bound for `period_start` (ISO 8601).\n * Defaults to the end of the current billing period.\n */\n to?: string | Date\n}\n\nexport interface UsageQueryResult {\n rollups: UsageRollup[]\n count: number\n}\n"],"names":[],"mappings":"AAcO,MAAM,uBAAuB,MAAM;AAAA,EAQxC,YACE,YACA,SACA,SACA;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,UAAU;AACf,SAAK,UAAU;AAEf,UAAM,UAAW,MACf,mBACF;AACA,cAAU,MAAM,cAAc;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,aAAsB;AACxB,WAAO,KAAK,eAAe;AAAA,EAC7B;AAAA,EAEA,IAAI,iBAA0B;AAC5B,W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AAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,SAAS;AAAA,EACT,gBAAgB;AAClB;AAQO,MAAM,WAAW;AAAA,EACtB,YAAY;AAAA,EACZ,QAAQ;AACV;AAIO,MAAM,gBAAgB;AAAA,EAC3B,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AACZ;AAQO,MAAM,qBAAqB;AAAA,EAChC,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AACZ;AAQO,MAAM,gBAAgB;AAAA,EAC3B,OAAO;AAAA,EACP,WAAW;AAAA,EACX,MAAM;AAAA,EACN,MAAM;AACR;AAQO,MAAM,eAAe;AAAA,EAC1B,cAAc;AAAA,EACd,aAAa;AACf;"}
package/package.json CHANGED
@@ -1,8 +1,15 @@
1
1
  {
2
2
  "name": "@monigo/sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Official Monigo JavaScript / TypeScript SDK — event ingestion, metering, billing, and usage for browser and Node.js",
5
- "keywords": ["monigo", "billing", "metering", "usage", "events", "sdk"],
5
+ "keywords": [
6
+ "monigo",
7
+ "billing",
8
+ "metering",
9
+ "usage",
10
+ "events",
11
+ "sdk"
12
+ ],
6
13
  "author": "Monigo <dev@monigo.co>",
7
14
  "license": "MIT",
8
15
  "type": "module",