@monigo/sdk 0.1.4 → 0.1.7
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 +144 -9
- package/dist/monigo.cjs +75 -5
- package/dist/monigo.cjs.map +1 -1
- package/dist/monigo.js +75 -5
- package/dist/monigo.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -68,16 +68,38 @@ export declare interface CreatePlanRequest {
|
|
|
68
68
|
prices?: CreatePriceRequest[];
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
/** Request body for `portalTokens.create()`. */
|
|
72
|
+
export declare interface CreatePortalTokenRequest {
|
|
73
|
+
/**
|
|
74
|
+
* The `external_id` you assigned this customer when you called
|
|
75
|
+
* `customers.create()`.
|
|
76
|
+
*/
|
|
77
|
+
customer_external_id: string;
|
|
78
|
+
/** Optional human-readable label, e.g. `"Main portal link"`. */
|
|
79
|
+
label?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Optional RFC 3339 expiry timestamp. Omit to create a permanent link.
|
|
82
|
+
* Example: `"2027-01-01T00:00:00Z"`
|
|
83
|
+
*/
|
|
84
|
+
expires_at?: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
71
87
|
/** Describes a price to attach when creating a plan. */
|
|
72
88
|
export declare interface CreatePriceRequest {
|
|
73
89
|
/** UUID of the metric this price is based on. */
|
|
74
90
|
metric_id: string;
|
|
75
91
|
/** Pricing model. Use `PricingModel` constants. */
|
|
76
92
|
model: PricingModelType;
|
|
77
|
-
/** Flat price per unit as a decimal string
|
|
93
|
+
/** Flat price per unit as a decimal string.
|
|
94
|
+
* Required for `PricingModel.Flat` / `PricingModel.PerUnit`. */
|
|
78
95
|
unit_price?: string;
|
|
79
|
-
/**
|
|
80
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Model-specific configuration:
|
|
98
|
+
* - `PricingModel.Tiered` → `PriceTier[]`
|
|
99
|
+
* - `PricingModel.Package` → `PackageConfig`
|
|
100
|
+
* - `PricingModel.Overage` → `OverageConfig`
|
|
101
|
+
*/
|
|
102
|
+
tiers?: PriceTier[] | PackageConfig | OverageConfig;
|
|
81
103
|
}
|
|
82
104
|
|
|
83
105
|
export declare interface CreateSubscriptionRequest {
|
|
@@ -416,6 +438,11 @@ export declare interface ListPlansResponse {
|
|
|
416
438
|
count: number;
|
|
417
439
|
}
|
|
418
440
|
|
|
441
|
+
export declare interface ListPortalTokensResponse {
|
|
442
|
+
tokens: PortalToken[];
|
|
443
|
+
count: number;
|
|
444
|
+
}
|
|
445
|
+
|
|
419
446
|
export declare interface ListSubscriptionsParams {
|
|
420
447
|
/** Filter to a specific customer UUID. */
|
|
421
448
|
customer_id?: string;
|
|
@@ -570,6 +597,8 @@ export declare class MonigoClient {
|
|
|
570
597
|
readonly invoices: InvoicesResource;
|
|
571
598
|
/** Query aggregated usage rollups per customer and metric. Requires `read` scope. */
|
|
572
599
|
readonly usage: UsageResource;
|
|
600
|
+
/** Manage customer portal access links. Requires `read` / `write` scope. */
|
|
601
|
+
readonly portalTokens: PortalTokensResource;
|
|
573
602
|
constructor(options: MonigoClientOptions);
|
|
574
603
|
/* Excluded from this release type: _request */
|
|
575
604
|
/** Normalise a `Date | string` value to an ISO 8601 string. */
|
|
@@ -615,6 +644,34 @@ export declare interface MutationOptions {
|
|
|
615
644
|
idempotencyKey?: string;
|
|
616
645
|
}
|
|
617
646
|
|
|
647
|
+
/**
|
|
648
|
+
* Configuration for the `overage` pricing model.
|
|
649
|
+
* Pass this as the `tiers` field when `model` is `PricingModel.Overage`.
|
|
650
|
+
*/
|
|
651
|
+
export declare interface OverageConfig {
|
|
652
|
+
/** Free quota. Usage at or below this threshold is charged `base_price`. */
|
|
653
|
+
included_units: number;
|
|
654
|
+
/** Flat fee for usage up to `included_units` as a decimal string.
|
|
655
|
+
* Set to `"0.000000"` when there is no base fee. */
|
|
656
|
+
base_price: string;
|
|
657
|
+
/** Per-unit rate applied to every unit above `included_units`,
|
|
658
|
+
* as a decimal string, e.g. `"1.500000"`. */
|
|
659
|
+
overage_price: string;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* Configuration for the `package` pricing model.
|
|
664
|
+
* Pass this as the `tiers` field when `model` is `PricingModel.Package`.
|
|
665
|
+
*/
|
|
666
|
+
export declare interface PackageConfig {
|
|
667
|
+
/** Number of units per bundle, e.g. `1000` for "1 000 SMS per bundle". */
|
|
668
|
+
package_size: number;
|
|
669
|
+
/** Price per complete bundle as a decimal string, e.g. `"500.000000"`. */
|
|
670
|
+
package_price: string;
|
|
671
|
+
/** If `true`, partial bundles are rounded up to the next whole bundle. */
|
|
672
|
+
round_up_partial_block: boolean;
|
|
673
|
+
}
|
|
674
|
+
|
|
618
675
|
/** A bank or mobile-money account that a customer can be paid to. */
|
|
619
676
|
export declare interface PayoutAccount {
|
|
620
677
|
id: string;
|
|
@@ -725,7 +782,7 @@ export declare class PlansResource {
|
|
|
725
782
|
* billing_period: 'monthly',
|
|
726
783
|
* prices: [{
|
|
727
784
|
* metric_id: 'metric_abc',
|
|
728
|
-
* model: '
|
|
785
|
+
* model: 'flat_unit',
|
|
729
786
|
* unit_price: '2.500000',
|
|
730
787
|
* }],
|
|
731
788
|
* })
|
|
@@ -765,6 +822,77 @@ export declare const PlanType: {
|
|
|
765
822
|
|
|
766
823
|
export declare type PlanTypeValue = (typeof PlanType)[keyof typeof PlanType];
|
|
767
824
|
|
|
825
|
+
/**
|
|
826
|
+
* A portal token grants an end-customer read-only access to their invoices,
|
|
827
|
+
* payout slips, subscriptions, and payout accounts in the Monigo hosted portal.
|
|
828
|
+
*/
|
|
829
|
+
export declare interface PortalToken {
|
|
830
|
+
id: string;
|
|
831
|
+
org_id: string;
|
|
832
|
+
customer_id: string;
|
|
833
|
+
/** The opaque 64-character hex token embedded in the portal URL. */
|
|
834
|
+
token: string;
|
|
835
|
+
label: string;
|
|
836
|
+
/** ISO 8601 expiry timestamp, or `null` for a permanent link. */
|
|
837
|
+
expires_at: string | null;
|
|
838
|
+
/** ISO 8601 revocation timestamp, or `null` if still active. */
|
|
839
|
+
revoked_at: string | null;
|
|
840
|
+
created_at: string;
|
|
841
|
+
updated_at: string;
|
|
842
|
+
/** Fully-qualified URL to share with the customer, e.g. `https://app.monigo.co/portal/<token>`. */
|
|
843
|
+
portal_url: string;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* Manage customer portal access links.
|
|
848
|
+
*
|
|
849
|
+
* Portal tokens grant an end-customer read-only access to their invoices,
|
|
850
|
+
* payout slips, subscriptions, and payout accounts in the Monigo hosted portal.
|
|
851
|
+
* All operations require a write-scoped API key; the organisation is inferred
|
|
852
|
+
* automatically from the key.
|
|
853
|
+
*/
|
|
854
|
+
export declare class PortalTokensResource {
|
|
855
|
+
private readonly client;
|
|
856
|
+
constructor(client: MonigoClient);
|
|
857
|
+
/**
|
|
858
|
+
* Generate a new portal link for a customer.
|
|
859
|
+
*
|
|
860
|
+
* **Requires `write` scope.**
|
|
861
|
+
*
|
|
862
|
+
* The returned `portal_url` is what you share with your customer — embed it
|
|
863
|
+
* in an email, open it in an iframe, or redirect the browser to it directly.
|
|
864
|
+
*
|
|
865
|
+
* @example
|
|
866
|
+
* ```ts
|
|
867
|
+
* const { portal_url } = await monigo.portalTokens.create({
|
|
868
|
+
* customer_external_id: 'usr_abc123',
|
|
869
|
+
* label: 'March 2026 invoice link',
|
|
870
|
+
* })
|
|
871
|
+
* await sendEmail(customer.email, { portalLink: portal_url })
|
|
872
|
+
* ```
|
|
873
|
+
*/
|
|
874
|
+
create(request: CreatePortalTokenRequest, options?: MutationOptions): Promise<PortalToken>;
|
|
875
|
+
/**
|
|
876
|
+
* List all portal tokens for a customer.
|
|
877
|
+
*
|
|
878
|
+
* **Requires `read` scope.**
|
|
879
|
+
*
|
|
880
|
+
* @param customerId - The customer's Monigo UUID or their `external_id`.
|
|
881
|
+
*/
|
|
882
|
+
list(customerId: string): Promise<ListPortalTokensResponse>;
|
|
883
|
+
/**
|
|
884
|
+
* Immediately revoke a portal token.
|
|
885
|
+
*
|
|
886
|
+
* **Requires `write` scope.**
|
|
887
|
+
*
|
|
888
|
+
* Any customer holding the corresponding URL will receive a 401 on their
|
|
889
|
+
* next request. This action is irreversible.
|
|
890
|
+
*
|
|
891
|
+
* @param tokenId - The UUID of the portal token record (not the raw token string).
|
|
892
|
+
*/
|
|
893
|
+
revoke(tokenId: string, options?: MutationOptions): Promise<void>;
|
|
894
|
+
}
|
|
895
|
+
|
|
768
896
|
/** A pricing rule attached to a plan. */
|
|
769
897
|
export declare interface Price {
|
|
770
898
|
id: string;
|
|
@@ -778,7 +906,7 @@ export declare interface Price {
|
|
|
778
906
|
}
|
|
779
907
|
|
|
780
908
|
/**
|
|
781
|
-
* One
|
|
909
|
+
* One step in a `tiered` pricing model.
|
|
782
910
|
* Set `up_to` to `null` for the final (infinite) tier.
|
|
783
911
|
*/
|
|
784
912
|
export declare interface PriceTier {
|
|
@@ -788,12 +916,19 @@ export declare interface PriceTier {
|
|
|
788
916
|
}
|
|
789
917
|
|
|
790
918
|
export declare const PricingModel: {
|
|
791
|
-
|
|
919
|
+
/** Fixed price per unit. Requires `unit_price`. */
|
|
920
|
+
readonly Flat: "flat_unit";
|
|
921
|
+
/** Alias for `Flat`. */
|
|
922
|
+
readonly PerUnit: "per_unit";
|
|
923
|
+
/** Graduated tiers — each unit charged at the rate of the tier it falls into.
|
|
924
|
+
* Requires a `PriceTier[]` in the `tiers` field. */
|
|
792
925
|
readonly Tiered: "tiered";
|
|
793
|
-
|
|
926
|
+
/** Charge per bundle of N units. Partial bundles round up.
|
|
927
|
+
* Requires a `PackageConfig` object in the `tiers` field. */
|
|
794
928
|
readonly Package: "package";
|
|
929
|
+
/** Flat base fee covers an included quota; per-unit rate beyond it.
|
|
930
|
+
* Requires an `OverageConfig` object in the `tiers` field. */
|
|
795
931
|
readonly Overage: "overage";
|
|
796
|
-
readonly WeightedTiered: "weighted_tiered";
|
|
797
932
|
};
|
|
798
933
|
|
|
799
934
|
export declare type PricingModelType = (typeof PricingModel)[keyof typeof PricingModel];
|
|
@@ -935,7 +1070,7 @@ export declare interface UpdatePriceRequest {
|
|
|
935
1070
|
metric_id?: string;
|
|
936
1071
|
model?: PricingModelType;
|
|
937
1072
|
unit_price?: string;
|
|
938
|
-
tiers?: PriceTier[];
|
|
1073
|
+
tiers?: PriceTier[] | PackageConfig | OverageConfig;
|
|
939
1074
|
}
|
|
940
1075
|
|
|
941
1076
|
export declare interface UsageQueryParams {
|
package/dist/monigo.cjs
CHANGED
|
@@ -313,7 +313,7 @@ class PlansResource {
|
|
|
313
313
|
* billing_period: 'monthly',
|
|
314
314
|
* prices: [{
|
|
315
315
|
* metric_id: 'metric_abc',
|
|
316
|
-
* model: '
|
|
316
|
+
* model: 'flat_unit',
|
|
317
317
|
* unit_price: '2.500000',
|
|
318
318
|
* }],
|
|
319
319
|
* })
|
|
@@ -663,6 +663,67 @@ class UsageResource {
|
|
|
663
663
|
return this.client._request("GET", "/v1/usage", { query });
|
|
664
664
|
}
|
|
665
665
|
}
|
|
666
|
+
class PortalTokensResource {
|
|
667
|
+
constructor(client) {
|
|
668
|
+
this.client = client;
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* Generate a new portal link for a customer.
|
|
672
|
+
*
|
|
673
|
+
* **Requires `write` scope.**
|
|
674
|
+
*
|
|
675
|
+
* The returned `portal_url` is what you share with your customer — embed it
|
|
676
|
+
* in an email, open it in an iframe, or redirect the browser to it directly.
|
|
677
|
+
*
|
|
678
|
+
* @example
|
|
679
|
+
* ```ts
|
|
680
|
+
* const { portal_url } = await monigo.portalTokens.create({
|
|
681
|
+
* customer_external_id: 'usr_abc123',
|
|
682
|
+
* label: 'March 2026 invoice link',
|
|
683
|
+
* })
|
|
684
|
+
* await sendEmail(customer.email, { portalLink: portal_url })
|
|
685
|
+
* ```
|
|
686
|
+
*/
|
|
687
|
+
async create(request, options) {
|
|
688
|
+
const wrapper = await this.client._request(
|
|
689
|
+
"POST",
|
|
690
|
+
"/v1/portal/tokens",
|
|
691
|
+
{ body: request, idempotencyKey: options?.idempotencyKey }
|
|
692
|
+
);
|
|
693
|
+
return wrapper.token;
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* List all portal tokens for a customer.
|
|
697
|
+
*
|
|
698
|
+
* **Requires `read` scope.**
|
|
699
|
+
*
|
|
700
|
+
* @param customerId - The customer's Monigo UUID or their `external_id`.
|
|
701
|
+
*/
|
|
702
|
+
async list(customerId) {
|
|
703
|
+
return this.client._request(
|
|
704
|
+
"GET",
|
|
705
|
+
"/v1/portal/tokens",
|
|
706
|
+
{ query: { customer_id: customerId } }
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Immediately revoke a portal token.
|
|
711
|
+
*
|
|
712
|
+
* **Requires `write` scope.**
|
|
713
|
+
*
|
|
714
|
+
* Any customer holding the corresponding URL will receive a 401 on their
|
|
715
|
+
* next request. This action is irreversible.
|
|
716
|
+
*
|
|
717
|
+
* @param tokenId - The UUID of the portal token record (not the raw token string).
|
|
718
|
+
*/
|
|
719
|
+
async revoke(tokenId, options) {
|
|
720
|
+
await this.client._request(
|
|
721
|
+
"DELETE",
|
|
722
|
+
`/v1/portal/tokens/${tokenId}`,
|
|
723
|
+
{ idempotencyKey: options?.idempotencyKey }
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
666
727
|
const DEFAULT_BASE_URL = "https://api.monigo.co";
|
|
667
728
|
const DEFAULT_TIMEOUT_MS = 3e4;
|
|
668
729
|
class MonigoClient {
|
|
@@ -688,6 +749,7 @@ class MonigoClient {
|
|
|
688
749
|
this.payoutAccounts = new PayoutAccountsResource(this);
|
|
689
750
|
this.invoices = new InvoicesResource(this);
|
|
690
751
|
this.usage = new UsageResource(this);
|
|
752
|
+
this.portalTokens = new PortalTokensResource(this);
|
|
691
753
|
}
|
|
692
754
|
/**
|
|
693
755
|
* Execute an authenticated HTTP request against the Monigo API.
|
|
@@ -761,12 +823,19 @@ const Aggregation = {
|
|
|
761
823
|
Unique: "unique"
|
|
762
824
|
};
|
|
763
825
|
const PricingModel = {
|
|
764
|
-
|
|
826
|
+
/** Fixed price per unit. Requires `unit_price`. */
|
|
827
|
+
Flat: "flat_unit",
|
|
828
|
+
/** Alias for `Flat`. */
|
|
829
|
+
PerUnit: "per_unit",
|
|
830
|
+
/** Graduated tiers — each unit charged at the rate of the tier it falls into.
|
|
831
|
+
* Requires a `PriceTier[]` in the `tiers` field. */
|
|
765
832
|
Tiered: "tiered",
|
|
766
|
-
|
|
833
|
+
/** Charge per bundle of N units. Partial bundles round up.
|
|
834
|
+
* Requires a `PackageConfig` object in the `tiers` field. */
|
|
767
835
|
Package: "package",
|
|
768
|
-
|
|
769
|
-
|
|
836
|
+
/** Flat base fee covers an included quota; per-unit rate beyond it.
|
|
837
|
+
* Requires an `OverageConfig` object in the `tiers` field. */
|
|
838
|
+
Overage: "overage"
|
|
770
839
|
};
|
|
771
840
|
const PlanType = {
|
|
772
841
|
Collection: "collection",
|
|
@@ -807,6 +876,7 @@ exports.PayoutAccountsResource = PayoutAccountsResource;
|
|
|
807
876
|
exports.PayoutMethod = PayoutMethod;
|
|
808
877
|
exports.PlanType = PlanType;
|
|
809
878
|
exports.PlansResource = PlansResource;
|
|
879
|
+
exports.PortalTokensResource = PortalTokensResource;
|
|
810
880
|
exports.PricingModel = PricingModel;
|
|
811
881
|
exports.SubscriptionStatus = SubscriptionStatus;
|
|
812
882
|
exports.SubscriptionsResource = SubscriptionsResource;
|
package/dist/monigo.cjs.map
CHANGED
|
@@ -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 { 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,WA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T,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.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/resources/portal-tokens.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_unit',\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 type { MonigoClient, MutationOptions } from '../client.js'\nimport type {\n PortalToken,\n CreatePortalTokenRequest,\n ListPortalTokensResponse,\n} from '../types.js'\n\n/**\n * Manage customer portal access links.\n *\n * Portal tokens grant an end-customer read-only access to their invoices,\n * payout slips, subscriptions, and payout accounts in the Monigo hosted portal.\n * All operations require a write-scoped API key; the organisation is inferred\n * automatically from the key.\n */\nexport class PortalTokensResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Generate a new portal link for a customer.\n *\n * **Requires `write` scope.**\n *\n * The returned `portal_url` is what you share with your customer — embed it\n * in an email, open it in an iframe, or redirect the browser to it directly.\n *\n * @example\n * ```ts\n * const { portal_url } = await monigo.portalTokens.create({\n * customer_external_id: 'usr_abc123',\n * label: 'March 2026 invoice link',\n * })\n * await sendEmail(customer.email, { portalLink: portal_url })\n * ```\n */\n async create(\n request: CreatePortalTokenRequest,\n options?: MutationOptions,\n ): Promise<PortalToken> {\n const wrapper = await this.client._request<{ token: PortalToken }>(\n 'POST',\n '/v1/portal/tokens',\n { body: request, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.token\n }\n\n /**\n * List all portal tokens for a customer.\n *\n * **Requires `read` scope.**\n *\n * @param customerId - The customer's Monigo UUID or their `external_id`.\n */\n async list(customerId: string): Promise<ListPortalTokensResponse> {\n return this.client._request<ListPortalTokensResponse>(\n 'GET',\n '/v1/portal/tokens',\n { query: { customer_id: customerId } },\n )\n }\n\n /**\n * Immediately revoke a portal token.\n *\n * **Requires `write` scope.**\n *\n * Any customer holding the corresponding URL will receive a 401 on their\n * next request. This action is irreversible.\n *\n * @param tokenId - The UUID of the portal token record (not the raw token string).\n */\n async revoke(tokenId: string, options?: MutationOptions): Promise<void> {\n await this.client._request<void>(\n 'DELETE',\n `/v1/portal/tokens/${tokenId}`,\n { idempotencyKey: options?.idempotencyKey },\n )\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'\nimport { PortalTokensResource } from './resources/portal-tokens.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 /** Manage customer portal access links. Requires `read` / `write` scope. */\n readonly portalTokens: PortalTokensResource\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 this.portalTokens = new PortalTokensResource(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 /** Fixed price per unit. Requires `unit_price`. */\n Flat: 'flat_unit',\n /** Alias for `Flat`. */\n PerUnit: 'per_unit',\n /** Graduated tiers — each unit charged at the rate of the tier it falls into.\n * Requires a `PriceTier[]` in the `tiers` field. */\n Tiered: 'tiered',\n /** Charge per bundle of N units. Partial bundles round up.\n * Requires a `PackageConfig` object in the `tiers` field. */\n Package: 'package',\n /** Flat base fee covers an included quota; per-unit rate beyond it.\n * Requires an `OverageConfig` object in the `tiers` field. */\n Overage: 'overage',\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 step in a `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/**\n * Configuration for the `package` pricing model.\n * Pass this as the `tiers` field when `model` is `PricingModel.Package`.\n */\nexport interface PackageConfig {\n /** Number of units per bundle, e.g. `1000` for \"1 000 SMS per bundle\". */\n package_size: number\n /** Price per complete bundle as a decimal string, e.g. `\"500.000000\"`. */\n package_price: string\n /** If `true`, partial bundles are rounded up to the next whole bundle. */\n round_up_partial_block: boolean\n}\n\n/**\n * Configuration for the `overage` pricing model.\n * Pass this as the `tiers` field when `model` is `PricingModel.Overage`.\n */\nexport interface OverageConfig {\n /** Free quota. Usage at or below this threshold is charged `base_price`. */\n included_units: number\n /** Flat fee for usage up to `included_units` as a decimal string.\n * Set to `\"0.000000\"` when there is no base fee. */\n base_price: string\n /** Per-unit rate applied to every unit above `included_units`,\n * as a decimal string, e.g. `\"1.500000\"`. */\n overage_price: 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.\n * Required for `PricingModel.Flat` / `PricingModel.PerUnit`. */\n unit_price?: string\n /**\n * Model-specific configuration:\n * - `PricingModel.Tiered` → `PriceTier[]`\n * - `PricingModel.Package` → `PackageConfig`\n * - `PricingModel.Overage` → `OverageConfig`\n */\n tiers?: PriceTier[] | PackageConfig | OverageConfig\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[] | PackageConfig | OverageConfig\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\n// =============================================================================\n// Portal tokens\n// =============================================================================\n\n/**\n * A portal token grants an end-customer read-only access to their invoices,\n * payout slips, subscriptions, and payout accounts in the Monigo hosted portal.\n */\nexport interface PortalToken {\n id: string\n org_id: string\n customer_id: string\n /** The opaque 64-character hex token embedded in the portal URL. */\n token: string\n label: string\n /** ISO 8601 expiry timestamp, or `null` for a permanent link. */\n expires_at: string | null\n /** ISO 8601 revocation timestamp, or `null` if still active. */\n revoked_at: string | null\n created_at: string\n updated_at: string\n /** Fully-qualified URL to share with the customer, e.g. `https://app.monigo.co/portal/<token>`. */\n portal_url: string\n}\n\n/** Request body for `portalTokens.create()`. */\nexport interface CreatePortalTokenRequest {\n /**\n * The `external_id` you assigned this customer when you called\n * `customers.create()`.\n */\n customer_external_id: string\n /** Optional human-readable label, e.g. `\"Main portal link\"`. */\n label?: string\n /**\n * Optional RFC 3339 expiry timestamp. Omit to create a permanent link.\n * Example: `\"2027-01-01T00:00:00Z\"`\n */\n expires_at?: string\n}\n\nexport interface ListPortalTokensResponse {\n tokens: PortalToken[]\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,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A,EACN,MAAM;AACR;AAQO,MAAM,eAAe;AAAA,EAC1B,cAAc;AAAA,EACd,aAAa;AACf;;;;;;;;;;;;;;;;;;;"}
|
package/dist/monigo.js
CHANGED
|
@@ -311,7 +311,7 @@ class PlansResource {
|
|
|
311
311
|
* billing_period: 'monthly',
|
|
312
312
|
* prices: [{
|
|
313
313
|
* metric_id: 'metric_abc',
|
|
314
|
-
* model: '
|
|
314
|
+
* model: 'flat_unit',
|
|
315
315
|
* unit_price: '2.500000',
|
|
316
316
|
* }],
|
|
317
317
|
* })
|
|
@@ -661,6 +661,67 @@ class UsageResource {
|
|
|
661
661
|
return this.client._request("GET", "/v1/usage", { query });
|
|
662
662
|
}
|
|
663
663
|
}
|
|
664
|
+
class PortalTokensResource {
|
|
665
|
+
constructor(client) {
|
|
666
|
+
this.client = client;
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Generate a new portal link for a customer.
|
|
670
|
+
*
|
|
671
|
+
* **Requires `write` scope.**
|
|
672
|
+
*
|
|
673
|
+
* The returned `portal_url` is what you share with your customer — embed it
|
|
674
|
+
* in an email, open it in an iframe, or redirect the browser to it directly.
|
|
675
|
+
*
|
|
676
|
+
* @example
|
|
677
|
+
* ```ts
|
|
678
|
+
* const { portal_url } = await monigo.portalTokens.create({
|
|
679
|
+
* customer_external_id: 'usr_abc123',
|
|
680
|
+
* label: 'March 2026 invoice link',
|
|
681
|
+
* })
|
|
682
|
+
* await sendEmail(customer.email, { portalLink: portal_url })
|
|
683
|
+
* ```
|
|
684
|
+
*/
|
|
685
|
+
async create(request, options) {
|
|
686
|
+
const wrapper = await this.client._request(
|
|
687
|
+
"POST",
|
|
688
|
+
"/v1/portal/tokens",
|
|
689
|
+
{ body: request, idempotencyKey: options?.idempotencyKey }
|
|
690
|
+
);
|
|
691
|
+
return wrapper.token;
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* List all portal tokens for a customer.
|
|
695
|
+
*
|
|
696
|
+
* **Requires `read` scope.**
|
|
697
|
+
*
|
|
698
|
+
* @param customerId - The customer's Monigo UUID or their `external_id`.
|
|
699
|
+
*/
|
|
700
|
+
async list(customerId) {
|
|
701
|
+
return this.client._request(
|
|
702
|
+
"GET",
|
|
703
|
+
"/v1/portal/tokens",
|
|
704
|
+
{ query: { customer_id: customerId } }
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Immediately revoke a portal token.
|
|
709
|
+
*
|
|
710
|
+
* **Requires `write` scope.**
|
|
711
|
+
*
|
|
712
|
+
* Any customer holding the corresponding URL will receive a 401 on their
|
|
713
|
+
* next request. This action is irreversible.
|
|
714
|
+
*
|
|
715
|
+
* @param tokenId - The UUID of the portal token record (not the raw token string).
|
|
716
|
+
*/
|
|
717
|
+
async revoke(tokenId, options) {
|
|
718
|
+
await this.client._request(
|
|
719
|
+
"DELETE",
|
|
720
|
+
`/v1/portal/tokens/${tokenId}`,
|
|
721
|
+
{ idempotencyKey: options?.idempotencyKey }
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
664
725
|
const DEFAULT_BASE_URL = "https://api.monigo.co";
|
|
665
726
|
const DEFAULT_TIMEOUT_MS = 3e4;
|
|
666
727
|
class MonigoClient {
|
|
@@ -686,6 +747,7 @@ class MonigoClient {
|
|
|
686
747
|
this.payoutAccounts = new PayoutAccountsResource(this);
|
|
687
748
|
this.invoices = new InvoicesResource(this);
|
|
688
749
|
this.usage = new UsageResource(this);
|
|
750
|
+
this.portalTokens = new PortalTokensResource(this);
|
|
689
751
|
}
|
|
690
752
|
/**
|
|
691
753
|
* Execute an authenticated HTTP request against the Monigo API.
|
|
@@ -759,12 +821,19 @@ const Aggregation = {
|
|
|
759
821
|
Unique: "unique"
|
|
760
822
|
};
|
|
761
823
|
const PricingModel = {
|
|
762
|
-
|
|
824
|
+
/** Fixed price per unit. Requires `unit_price`. */
|
|
825
|
+
Flat: "flat_unit",
|
|
826
|
+
/** Alias for `Flat`. */
|
|
827
|
+
PerUnit: "per_unit",
|
|
828
|
+
/** Graduated tiers — each unit charged at the rate of the tier it falls into.
|
|
829
|
+
* Requires a `PriceTier[]` in the `tiers` field. */
|
|
763
830
|
Tiered: "tiered",
|
|
764
|
-
|
|
831
|
+
/** Charge per bundle of N units. Partial bundles round up.
|
|
832
|
+
* Requires a `PackageConfig` object in the `tiers` field. */
|
|
765
833
|
Package: "package",
|
|
766
|
-
|
|
767
|
-
|
|
834
|
+
/** Flat base fee covers an included quota; per-unit rate beyond it.
|
|
835
|
+
* Requires an `OverageConfig` object in the `tiers` field. */
|
|
836
|
+
Overage: "overage"
|
|
768
837
|
};
|
|
769
838
|
const PlanType = {
|
|
770
839
|
Collection: "collection",
|
|
@@ -806,6 +875,7 @@ export {
|
|
|
806
875
|
PayoutMethod,
|
|
807
876
|
PlanType,
|
|
808
877
|
PlansResource,
|
|
878
|
+
PortalTokensResource,
|
|
809
879
|
PricingModel,
|
|
810
880
|
SubscriptionStatus,
|
|
811
881
|
SubscriptionsResource,
|
package/dist/monigo.js.map
CHANGED
|
@@ -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 { 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;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Q;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/resources/portal-tokens.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_unit',\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 type { MonigoClient, MutationOptions } from '../client.js'\nimport type {\n PortalToken,\n CreatePortalTokenRequest,\n ListPortalTokensResponse,\n} from '../types.js'\n\n/**\n * Manage customer portal access links.\n *\n * Portal tokens grant an end-customer read-only access to their invoices,\n * payout slips, subscriptions, and payout accounts in the Monigo hosted portal.\n * All operations require a write-scoped API key; the organisation is inferred\n * automatically from the key.\n */\nexport class PortalTokensResource {\n constructor(private readonly client: MonigoClient) {}\n\n /**\n * Generate a new portal link for a customer.\n *\n * **Requires `write` scope.**\n *\n * The returned `portal_url` is what you share with your customer — embed it\n * in an email, open it in an iframe, or redirect the browser to it directly.\n *\n * @example\n * ```ts\n * const { portal_url } = await monigo.portalTokens.create({\n * customer_external_id: 'usr_abc123',\n * label: 'March 2026 invoice link',\n * })\n * await sendEmail(customer.email, { portalLink: portal_url })\n * ```\n */\n async create(\n request: CreatePortalTokenRequest,\n options?: MutationOptions,\n ): Promise<PortalToken> {\n const wrapper = await this.client._request<{ token: PortalToken }>(\n 'POST',\n '/v1/portal/tokens',\n { body: request, idempotencyKey: options?.idempotencyKey },\n )\n return wrapper.token\n }\n\n /**\n * List all portal tokens for a customer.\n *\n * **Requires `read` scope.**\n *\n * @param customerId - The customer's Monigo UUID or their `external_id`.\n */\n async list(customerId: string): Promise<ListPortalTokensResponse> {\n return this.client._request<ListPortalTokensResponse>(\n 'GET',\n '/v1/portal/tokens',\n { query: { customer_id: customerId } },\n )\n }\n\n /**\n * Immediately revoke a portal token.\n *\n * **Requires `write` scope.**\n *\n * Any customer holding the corresponding URL will receive a 401 on their\n * next request. This action is irreversible.\n *\n * @param tokenId - The UUID of the portal token record (not the raw token string).\n */\n async revoke(tokenId: string, options?: MutationOptions): Promise<void> {\n await this.client._request<void>(\n 'DELETE',\n `/v1/portal/tokens/${tokenId}`,\n { idempotencyKey: options?.idempotencyKey },\n )\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'\nimport { PortalTokensResource } from './resources/portal-tokens.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 /** Manage customer portal access links. Requires `read` / `write` scope. */\n readonly portalTokens: PortalTokensResource\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 this.portalTokens = new PortalTokensResource(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 /** Fixed price per unit. Requires `unit_price`. */\n Flat: 'flat_unit',\n /** Alias for `Flat`. */\n PerUnit: 'per_unit',\n /** Graduated tiers — each unit charged at the rate of the tier it falls into.\n * Requires a `PriceTier[]` in the `tiers` field. */\n Tiered: 'tiered',\n /** Charge per bundle of N units. Partial bundles round up.\n * Requires a `PackageConfig` object in the `tiers` field. */\n Package: 'package',\n /** Flat base fee covers an included quota; per-unit rate beyond it.\n * Requires an `OverageConfig` object in the `tiers` field. */\n Overage: 'overage',\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 step in a `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/**\n * Configuration for the `package` pricing model.\n * Pass this as the `tiers` field when `model` is `PricingModel.Package`.\n */\nexport interface PackageConfig {\n /** Number of units per bundle, e.g. `1000` for \"1 000 SMS per bundle\". */\n package_size: number\n /** Price per complete bundle as a decimal string, e.g. `\"500.000000\"`. */\n package_price: string\n /** If `true`, partial bundles are rounded up to the next whole bundle. */\n round_up_partial_block: boolean\n}\n\n/**\n * Configuration for the `overage` pricing model.\n * Pass this as the `tiers` field when `model` is `PricingModel.Overage`.\n */\nexport interface OverageConfig {\n /** Free quota. Usage at or below this threshold is charged `base_price`. */\n included_units: number\n /** Flat fee for usage up to `included_units` as a decimal string.\n * Set to `\"0.000000\"` when there is no base fee. */\n base_price: string\n /** Per-unit rate applied to every unit above `included_units`,\n * as a decimal string, e.g. `\"1.500000\"`. */\n overage_price: 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.\n * Required for `PricingModel.Flat` / `PricingModel.PerUnit`. */\n unit_price?: string\n /**\n * Model-specific configuration:\n * - `PricingModel.Tiered` → `PriceTier[]`\n * - `PricingModel.Package` → `PackageConfig`\n * - `PricingModel.Overage` → `OverageConfig`\n */\n tiers?: PriceTier[] | PackageConfig | OverageConfig\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[] | PackageConfig | OverageConfig\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\n// =============================================================================\n// Portal tokens\n// =============================================================================\n\n/**\n * A portal token grants an end-customer read-only access to their invoices,\n * payout slips, subscriptions, and payout accounts in the Monigo hosted portal.\n */\nexport interface PortalToken {\n id: string\n org_id: string\n customer_id: string\n /** The opaque 64-character hex token embedded in the portal URL. */\n token: string\n label: string\n /** ISO 8601 expiry timestamp, or `null` for a permanent link. */\n expires_at: string | null\n /** ISO 8601 revocation timestamp, or `null` if still active. */\n revoked_at: string | null\n created_at: string\n updated_at: string\n /** Fully-qualified URL to share with the customer, e.g. `https://app.monigo.co/portal/<token>`. */\n portal_url: string\n}\n\n/** Request body for `portalTokens.create()`. */\nexport interface CreatePortalTokenRequest {\n /**\n * The `external_id` you assigned this customer when you called\n * `customers.create()`.\n */\n customer_external_id: string\n /** Optional human-readable label, e.g. `\"Main portal link\"`. */\n label?: string\n /**\n * Optional RFC 3339 expiry timestamp. Omit to create a permanent link.\n * Example: `\"2027-01-01T00:00:00Z\"`\n */\n expires_at?: string\n}\n\nexport interface ListPortalTokensResponse {\n tokens: PortalToken[]\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;AAA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