@modelrelay/sdk 1.28.0 → 1.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-jqOwvH6O.d.cts +4761 -0
- package/dist/api-jqOwvH6O.d.ts +4761 -0
- package/dist/billing/index.cjs +151 -0
- package/dist/billing/index.d.cts +178 -0
- package/dist/billing/index.d.ts +178 -0
- package/dist/billing/index.js +128 -0
- package/dist/chunk-ADQ74R7T.js +1194 -0
- package/dist/{chunk-BL7GWXRZ.js → chunk-CV3DTA6P.js} +1 -1
- package/dist/{chunk-G5H7EY4F.js → chunk-EMQKOEF3.js} +1 -1
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/chunk-ZBQKY2W2.js +1194 -0
- package/dist/index.cjs +295 -1246
- package/dist/index.d.cts +163 -4760
- package/dist/index.d.ts +163 -4760
- package/dist/index.js +9 -955
- package/dist/node.cjs +603 -9
- package/dist/node.d.cts +201 -2
- package/dist/node.d.ts +201 -2
- package/dist/node.js +582 -2
- package/dist/tools-Cnl2MgVa.d.cts +1174 -0
- package/dist/tools-Cnl2MgVa.d.ts +1174 -0
- package/dist/{tools-Db-F5rIL.d.cts → tools-DAqAFZ8F.d.cts} +9 -6
- package/dist/{tools-Db-F5rIL.d.ts → tools-DAqAFZ8F.d.ts} +9 -6
- package/package.json +14 -9
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/billing/index.ts
|
|
21
|
+
var billing_exports = {};
|
|
22
|
+
__export(billing_exports, {
|
|
23
|
+
BillingClient: () => BillingClient
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(billing_exports);
|
|
26
|
+
var BillingClient = class {
|
|
27
|
+
constructor(http, accessToken) {
|
|
28
|
+
this.http = http;
|
|
29
|
+
this.accessToken = accessToken;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get the authenticated customer's profile.
|
|
33
|
+
*
|
|
34
|
+
* Returns customer details including ID, email, external ID, and metadata.
|
|
35
|
+
*
|
|
36
|
+
* @returns Customer profile with optional subscription and tier
|
|
37
|
+
*/
|
|
38
|
+
async me() {
|
|
39
|
+
const response = await this.http.json("/customers/me", {
|
|
40
|
+
method: "GET",
|
|
41
|
+
accessToken: this.accessToken
|
|
42
|
+
});
|
|
43
|
+
return response.customer;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get the authenticated customer's subscription details.
|
|
47
|
+
*
|
|
48
|
+
* Returns subscription status, tier information, and billing provider.
|
|
49
|
+
*
|
|
50
|
+
* @returns Subscription details
|
|
51
|
+
*/
|
|
52
|
+
async subscription() {
|
|
53
|
+
const response = await this.http.json("/customers/me/subscription", {
|
|
54
|
+
method: "GET",
|
|
55
|
+
accessToken: this.accessToken
|
|
56
|
+
});
|
|
57
|
+
return response.subscription;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get the authenticated customer's usage metrics.
|
|
61
|
+
*
|
|
62
|
+
* Returns token usage, request counts, and cost for the current billing window.
|
|
63
|
+
*
|
|
64
|
+
* @returns Usage metrics
|
|
65
|
+
*/
|
|
66
|
+
async usage() {
|
|
67
|
+
const response = await this.http.json("/customers/me/usage", {
|
|
68
|
+
method: "GET",
|
|
69
|
+
accessToken: this.accessToken
|
|
70
|
+
});
|
|
71
|
+
return response.usage;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get the authenticated customer's credit balance.
|
|
75
|
+
*
|
|
76
|
+
* For PAYGO (pay-as-you-go) subscriptions, returns the current balance
|
|
77
|
+
* and reserved amount.
|
|
78
|
+
*
|
|
79
|
+
* @returns Balance information
|
|
80
|
+
*/
|
|
81
|
+
async balance() {
|
|
82
|
+
return await this.http.json("/customers/me/balance", {
|
|
83
|
+
method: "GET",
|
|
84
|
+
accessToken: this.accessToken
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get the authenticated customer's balance transaction history.
|
|
89
|
+
*
|
|
90
|
+
* Returns a list of ledger entries showing credits and debits.
|
|
91
|
+
*
|
|
92
|
+
* @returns Ledger entries
|
|
93
|
+
*/
|
|
94
|
+
async balanceHistory() {
|
|
95
|
+
return await this.http.json("/customers/me/balance/history", {
|
|
96
|
+
method: "GET",
|
|
97
|
+
accessToken: this.accessToken
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Create a top-up checkout session.
|
|
102
|
+
*
|
|
103
|
+
* For PAYGO subscriptions, creates a Stripe Checkout session to add credits.
|
|
104
|
+
*
|
|
105
|
+
* @param request - Top-up request with amount and redirect URLs
|
|
106
|
+
* @returns Checkout session with redirect URL
|
|
107
|
+
*/
|
|
108
|
+
async topup(request) {
|
|
109
|
+
return await this.http.json("/customers/me/topup", {
|
|
110
|
+
method: "POST",
|
|
111
|
+
body: request,
|
|
112
|
+
accessToken: this.accessToken
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Change the authenticated customer's subscription tier.
|
|
117
|
+
*
|
|
118
|
+
* Switches to a different tier within the same project.
|
|
119
|
+
*
|
|
120
|
+
* @param tierCode - The tier code to switch to
|
|
121
|
+
* @returns Updated subscription details
|
|
122
|
+
*/
|
|
123
|
+
async changeTier(tierCode) {
|
|
124
|
+
const request = { tier_code: tierCode };
|
|
125
|
+
const response = await this.http.json("/customers/me/change-tier", {
|
|
126
|
+
method: "POST",
|
|
127
|
+
body: request,
|
|
128
|
+
accessToken: this.accessToken
|
|
129
|
+
});
|
|
130
|
+
return response.subscription;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Create a subscription checkout session.
|
|
134
|
+
*
|
|
135
|
+
* Creates a Stripe Checkout session for subscribing to a tier.
|
|
136
|
+
*
|
|
137
|
+
* @param request - Checkout request with tier and redirect URLs
|
|
138
|
+
* @returns Checkout session with redirect URL
|
|
139
|
+
*/
|
|
140
|
+
async checkout(request) {
|
|
141
|
+
return await this.http.json("/customers/me/checkout", {
|
|
142
|
+
method: "POST",
|
|
143
|
+
body: request,
|
|
144
|
+
accessToken: this.accessToken
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
149
|
+
0 && (module.exports = {
|
|
150
|
+
BillingClient
|
|
151
|
+
});
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { c as components } from '../api-jqOwvH6O.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Billing client for customer self-service operations.
|
|
5
|
+
*
|
|
6
|
+
* This module provides helpers for customer billing operations like viewing
|
|
7
|
+
* subscription status, usage metrics, balance, and managing subscriptions.
|
|
8
|
+
*
|
|
9
|
+
* Requires a customer bearer token for authentication (not API keys).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { ModelRelay } from "@modelrelay/sdk";
|
|
14
|
+
* import { BillingClient } from "@modelrelay/sdk/billing";
|
|
15
|
+
*
|
|
16
|
+
* // Customer token from device flow or OIDC exchange
|
|
17
|
+
* const client = new ModelRelay({ token: customerToken });
|
|
18
|
+
* const billing = new BillingClient(client.http);
|
|
19
|
+
*
|
|
20
|
+
* // Get customer info
|
|
21
|
+
* const me = await billing.me();
|
|
22
|
+
* console.log("Customer:", me.customer.email);
|
|
23
|
+
* console.log("Tier:", me.tier?.code);
|
|
24
|
+
*
|
|
25
|
+
* // Get usage metrics
|
|
26
|
+
* const usage = await billing.usage();
|
|
27
|
+
* console.log("Tokens used:", usage.total_tokens);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Customer profile returned by GET /customers/me.
|
|
33
|
+
*/
|
|
34
|
+
type CustomerMe = components["schemas"]["CustomerMe"];
|
|
35
|
+
/**
|
|
36
|
+
* Customer usage metrics.
|
|
37
|
+
*/
|
|
38
|
+
type CustomerMeUsage = components["schemas"]["CustomerMeUsage"];
|
|
39
|
+
/**
|
|
40
|
+
* Customer subscription details.
|
|
41
|
+
*/
|
|
42
|
+
type CustomerMeSubscription = components["schemas"]["CustomerMeSubscription"];
|
|
43
|
+
/**
|
|
44
|
+
* Customer credit balance.
|
|
45
|
+
*/
|
|
46
|
+
type CustomerBalanceResponse = components["schemas"]["CustomerBalanceResponse"];
|
|
47
|
+
/**
|
|
48
|
+
* Customer ledger entry for balance history.
|
|
49
|
+
*/
|
|
50
|
+
type CustomerLedgerEntry = components["schemas"]["CustomerLedgerEntry"];
|
|
51
|
+
/**
|
|
52
|
+
* Customer ledger response with transaction history.
|
|
53
|
+
*/
|
|
54
|
+
type CustomerLedgerResponse = components["schemas"]["CustomerLedgerResponse"];
|
|
55
|
+
/**
|
|
56
|
+
* Request to create a top-up checkout session.
|
|
57
|
+
*/
|
|
58
|
+
type CustomerTopupRequest = components["schemas"]["CustomerTopupRequest"];
|
|
59
|
+
/**
|
|
60
|
+
* Response from top-up checkout session creation.
|
|
61
|
+
*/
|
|
62
|
+
type CustomerTopupResponse = components["schemas"]["CustomerTopupResponse"];
|
|
63
|
+
/**
|
|
64
|
+
* Request to change subscription tier.
|
|
65
|
+
*/
|
|
66
|
+
type ChangeTierRequest = components["schemas"]["ChangeTierRequest"];
|
|
67
|
+
/**
|
|
68
|
+
* Request to create a subscription checkout session.
|
|
69
|
+
*/
|
|
70
|
+
type CustomerMeCheckoutRequest = components["schemas"]["CustomerMeCheckoutRequest"];
|
|
71
|
+
/**
|
|
72
|
+
* Response from checkout session creation.
|
|
73
|
+
*/
|
|
74
|
+
type CheckoutSessionResponse = components["schemas"]["CheckoutSessionResponse"];
|
|
75
|
+
/**
|
|
76
|
+
* Minimal HTTP client interface for billing operations.
|
|
77
|
+
*/
|
|
78
|
+
interface HTTPClientLike {
|
|
79
|
+
json<T>(path: string, options: {
|
|
80
|
+
method: string;
|
|
81
|
+
body?: unknown;
|
|
82
|
+
accessToken?: string;
|
|
83
|
+
}): Promise<T>;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Client for customer billing self-service operations.
|
|
87
|
+
*
|
|
88
|
+
* These endpoints require a customer bearer token (from device flow or OIDC exchange).
|
|
89
|
+
* API keys are not accepted.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* import { ModelRelay } from "@modelrelay/sdk";
|
|
94
|
+
* import { BillingClient } from "@modelrelay/sdk/billing";
|
|
95
|
+
*
|
|
96
|
+
* const client = new ModelRelay({ token: customerToken });
|
|
97
|
+
* const billing = new BillingClient(client.http);
|
|
98
|
+
*
|
|
99
|
+
* const me = await billing.me();
|
|
100
|
+
* const usage = await billing.usage();
|
|
101
|
+
* const subscription = await billing.subscription();
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
declare class BillingClient {
|
|
105
|
+
private readonly http;
|
|
106
|
+
private readonly accessToken?;
|
|
107
|
+
constructor(http: HTTPClientLike, accessToken?: string);
|
|
108
|
+
/**
|
|
109
|
+
* Get the authenticated customer's profile.
|
|
110
|
+
*
|
|
111
|
+
* Returns customer details including ID, email, external ID, and metadata.
|
|
112
|
+
*
|
|
113
|
+
* @returns Customer profile with optional subscription and tier
|
|
114
|
+
*/
|
|
115
|
+
me(): Promise<CustomerMe>;
|
|
116
|
+
/**
|
|
117
|
+
* Get the authenticated customer's subscription details.
|
|
118
|
+
*
|
|
119
|
+
* Returns subscription status, tier information, and billing provider.
|
|
120
|
+
*
|
|
121
|
+
* @returns Subscription details
|
|
122
|
+
*/
|
|
123
|
+
subscription(): Promise<CustomerMeSubscription>;
|
|
124
|
+
/**
|
|
125
|
+
* Get the authenticated customer's usage metrics.
|
|
126
|
+
*
|
|
127
|
+
* Returns token usage, request counts, and cost for the current billing window.
|
|
128
|
+
*
|
|
129
|
+
* @returns Usage metrics
|
|
130
|
+
*/
|
|
131
|
+
usage(): Promise<CustomerMeUsage>;
|
|
132
|
+
/**
|
|
133
|
+
* Get the authenticated customer's credit balance.
|
|
134
|
+
*
|
|
135
|
+
* For PAYGO (pay-as-you-go) subscriptions, returns the current balance
|
|
136
|
+
* and reserved amount.
|
|
137
|
+
*
|
|
138
|
+
* @returns Balance information
|
|
139
|
+
*/
|
|
140
|
+
balance(): Promise<CustomerBalanceResponse>;
|
|
141
|
+
/**
|
|
142
|
+
* Get the authenticated customer's balance transaction history.
|
|
143
|
+
*
|
|
144
|
+
* Returns a list of ledger entries showing credits and debits.
|
|
145
|
+
*
|
|
146
|
+
* @returns Ledger entries
|
|
147
|
+
*/
|
|
148
|
+
balanceHistory(): Promise<CustomerLedgerResponse>;
|
|
149
|
+
/**
|
|
150
|
+
* Create a top-up checkout session.
|
|
151
|
+
*
|
|
152
|
+
* For PAYGO subscriptions, creates a Stripe Checkout session to add credits.
|
|
153
|
+
*
|
|
154
|
+
* @param request - Top-up request with amount and redirect URLs
|
|
155
|
+
* @returns Checkout session with redirect URL
|
|
156
|
+
*/
|
|
157
|
+
topup(request: CustomerTopupRequest): Promise<CustomerTopupResponse>;
|
|
158
|
+
/**
|
|
159
|
+
* Change the authenticated customer's subscription tier.
|
|
160
|
+
*
|
|
161
|
+
* Switches to a different tier within the same project.
|
|
162
|
+
*
|
|
163
|
+
* @param tierCode - The tier code to switch to
|
|
164
|
+
* @returns Updated subscription details
|
|
165
|
+
*/
|
|
166
|
+
changeTier(tierCode: string): Promise<CustomerMeSubscription>;
|
|
167
|
+
/**
|
|
168
|
+
* Create a subscription checkout session.
|
|
169
|
+
*
|
|
170
|
+
* Creates a Stripe Checkout session for subscribing to a tier.
|
|
171
|
+
*
|
|
172
|
+
* @param request - Checkout request with tier and redirect URLs
|
|
173
|
+
* @returns Checkout session with redirect URL
|
|
174
|
+
*/
|
|
175
|
+
checkout(request: CustomerMeCheckoutRequest): Promise<CheckoutSessionResponse>;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export { BillingClient, type ChangeTierRequest, type CheckoutSessionResponse, type CustomerBalanceResponse, type CustomerLedgerEntry, type CustomerLedgerResponse, type CustomerMe, type CustomerMeCheckoutRequest, type CustomerMeSubscription, type CustomerMeUsage, type CustomerTopupRequest, type CustomerTopupResponse };
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { c as components } from '../api-jqOwvH6O.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Billing client for customer self-service operations.
|
|
5
|
+
*
|
|
6
|
+
* This module provides helpers for customer billing operations like viewing
|
|
7
|
+
* subscription status, usage metrics, balance, and managing subscriptions.
|
|
8
|
+
*
|
|
9
|
+
* Requires a customer bearer token for authentication (not API keys).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { ModelRelay } from "@modelrelay/sdk";
|
|
14
|
+
* import { BillingClient } from "@modelrelay/sdk/billing";
|
|
15
|
+
*
|
|
16
|
+
* // Customer token from device flow or OIDC exchange
|
|
17
|
+
* const client = new ModelRelay({ token: customerToken });
|
|
18
|
+
* const billing = new BillingClient(client.http);
|
|
19
|
+
*
|
|
20
|
+
* // Get customer info
|
|
21
|
+
* const me = await billing.me();
|
|
22
|
+
* console.log("Customer:", me.customer.email);
|
|
23
|
+
* console.log("Tier:", me.tier?.code);
|
|
24
|
+
*
|
|
25
|
+
* // Get usage metrics
|
|
26
|
+
* const usage = await billing.usage();
|
|
27
|
+
* console.log("Tokens used:", usage.total_tokens);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Customer profile returned by GET /customers/me.
|
|
33
|
+
*/
|
|
34
|
+
type CustomerMe = components["schemas"]["CustomerMe"];
|
|
35
|
+
/**
|
|
36
|
+
* Customer usage metrics.
|
|
37
|
+
*/
|
|
38
|
+
type CustomerMeUsage = components["schemas"]["CustomerMeUsage"];
|
|
39
|
+
/**
|
|
40
|
+
* Customer subscription details.
|
|
41
|
+
*/
|
|
42
|
+
type CustomerMeSubscription = components["schemas"]["CustomerMeSubscription"];
|
|
43
|
+
/**
|
|
44
|
+
* Customer credit balance.
|
|
45
|
+
*/
|
|
46
|
+
type CustomerBalanceResponse = components["schemas"]["CustomerBalanceResponse"];
|
|
47
|
+
/**
|
|
48
|
+
* Customer ledger entry for balance history.
|
|
49
|
+
*/
|
|
50
|
+
type CustomerLedgerEntry = components["schemas"]["CustomerLedgerEntry"];
|
|
51
|
+
/**
|
|
52
|
+
* Customer ledger response with transaction history.
|
|
53
|
+
*/
|
|
54
|
+
type CustomerLedgerResponse = components["schemas"]["CustomerLedgerResponse"];
|
|
55
|
+
/**
|
|
56
|
+
* Request to create a top-up checkout session.
|
|
57
|
+
*/
|
|
58
|
+
type CustomerTopupRequest = components["schemas"]["CustomerTopupRequest"];
|
|
59
|
+
/**
|
|
60
|
+
* Response from top-up checkout session creation.
|
|
61
|
+
*/
|
|
62
|
+
type CustomerTopupResponse = components["schemas"]["CustomerTopupResponse"];
|
|
63
|
+
/**
|
|
64
|
+
* Request to change subscription tier.
|
|
65
|
+
*/
|
|
66
|
+
type ChangeTierRequest = components["schemas"]["ChangeTierRequest"];
|
|
67
|
+
/**
|
|
68
|
+
* Request to create a subscription checkout session.
|
|
69
|
+
*/
|
|
70
|
+
type CustomerMeCheckoutRequest = components["schemas"]["CustomerMeCheckoutRequest"];
|
|
71
|
+
/**
|
|
72
|
+
* Response from checkout session creation.
|
|
73
|
+
*/
|
|
74
|
+
type CheckoutSessionResponse = components["schemas"]["CheckoutSessionResponse"];
|
|
75
|
+
/**
|
|
76
|
+
* Minimal HTTP client interface for billing operations.
|
|
77
|
+
*/
|
|
78
|
+
interface HTTPClientLike {
|
|
79
|
+
json<T>(path: string, options: {
|
|
80
|
+
method: string;
|
|
81
|
+
body?: unknown;
|
|
82
|
+
accessToken?: string;
|
|
83
|
+
}): Promise<T>;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Client for customer billing self-service operations.
|
|
87
|
+
*
|
|
88
|
+
* These endpoints require a customer bearer token (from device flow or OIDC exchange).
|
|
89
|
+
* API keys are not accepted.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* import { ModelRelay } from "@modelrelay/sdk";
|
|
94
|
+
* import { BillingClient } from "@modelrelay/sdk/billing";
|
|
95
|
+
*
|
|
96
|
+
* const client = new ModelRelay({ token: customerToken });
|
|
97
|
+
* const billing = new BillingClient(client.http);
|
|
98
|
+
*
|
|
99
|
+
* const me = await billing.me();
|
|
100
|
+
* const usage = await billing.usage();
|
|
101
|
+
* const subscription = await billing.subscription();
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
declare class BillingClient {
|
|
105
|
+
private readonly http;
|
|
106
|
+
private readonly accessToken?;
|
|
107
|
+
constructor(http: HTTPClientLike, accessToken?: string);
|
|
108
|
+
/**
|
|
109
|
+
* Get the authenticated customer's profile.
|
|
110
|
+
*
|
|
111
|
+
* Returns customer details including ID, email, external ID, and metadata.
|
|
112
|
+
*
|
|
113
|
+
* @returns Customer profile with optional subscription and tier
|
|
114
|
+
*/
|
|
115
|
+
me(): Promise<CustomerMe>;
|
|
116
|
+
/**
|
|
117
|
+
* Get the authenticated customer's subscription details.
|
|
118
|
+
*
|
|
119
|
+
* Returns subscription status, tier information, and billing provider.
|
|
120
|
+
*
|
|
121
|
+
* @returns Subscription details
|
|
122
|
+
*/
|
|
123
|
+
subscription(): Promise<CustomerMeSubscription>;
|
|
124
|
+
/**
|
|
125
|
+
* Get the authenticated customer's usage metrics.
|
|
126
|
+
*
|
|
127
|
+
* Returns token usage, request counts, and cost for the current billing window.
|
|
128
|
+
*
|
|
129
|
+
* @returns Usage metrics
|
|
130
|
+
*/
|
|
131
|
+
usage(): Promise<CustomerMeUsage>;
|
|
132
|
+
/**
|
|
133
|
+
* Get the authenticated customer's credit balance.
|
|
134
|
+
*
|
|
135
|
+
* For PAYGO (pay-as-you-go) subscriptions, returns the current balance
|
|
136
|
+
* and reserved amount.
|
|
137
|
+
*
|
|
138
|
+
* @returns Balance information
|
|
139
|
+
*/
|
|
140
|
+
balance(): Promise<CustomerBalanceResponse>;
|
|
141
|
+
/**
|
|
142
|
+
* Get the authenticated customer's balance transaction history.
|
|
143
|
+
*
|
|
144
|
+
* Returns a list of ledger entries showing credits and debits.
|
|
145
|
+
*
|
|
146
|
+
* @returns Ledger entries
|
|
147
|
+
*/
|
|
148
|
+
balanceHistory(): Promise<CustomerLedgerResponse>;
|
|
149
|
+
/**
|
|
150
|
+
* Create a top-up checkout session.
|
|
151
|
+
*
|
|
152
|
+
* For PAYGO subscriptions, creates a Stripe Checkout session to add credits.
|
|
153
|
+
*
|
|
154
|
+
* @param request - Top-up request with amount and redirect URLs
|
|
155
|
+
* @returns Checkout session with redirect URL
|
|
156
|
+
*/
|
|
157
|
+
topup(request: CustomerTopupRequest): Promise<CustomerTopupResponse>;
|
|
158
|
+
/**
|
|
159
|
+
* Change the authenticated customer's subscription tier.
|
|
160
|
+
*
|
|
161
|
+
* Switches to a different tier within the same project.
|
|
162
|
+
*
|
|
163
|
+
* @param tierCode - The tier code to switch to
|
|
164
|
+
* @returns Updated subscription details
|
|
165
|
+
*/
|
|
166
|
+
changeTier(tierCode: string): Promise<CustomerMeSubscription>;
|
|
167
|
+
/**
|
|
168
|
+
* Create a subscription checkout session.
|
|
169
|
+
*
|
|
170
|
+
* Creates a Stripe Checkout session for subscribing to a tier.
|
|
171
|
+
*
|
|
172
|
+
* @param request - Checkout request with tier and redirect URLs
|
|
173
|
+
* @returns Checkout session with redirect URL
|
|
174
|
+
*/
|
|
175
|
+
checkout(request: CustomerMeCheckoutRequest): Promise<CheckoutSessionResponse>;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export { BillingClient, type ChangeTierRequest, type CheckoutSessionResponse, type CustomerBalanceResponse, type CustomerLedgerEntry, type CustomerLedgerResponse, type CustomerMe, type CustomerMeCheckoutRequest, type CustomerMeSubscription, type CustomerMeUsage, type CustomerTopupRequest, type CustomerTopupResponse };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import "../chunk-MLKGABMK.js";
|
|
2
|
+
|
|
3
|
+
// src/billing/index.ts
|
|
4
|
+
var BillingClient = class {
|
|
5
|
+
constructor(http, accessToken) {
|
|
6
|
+
this.http = http;
|
|
7
|
+
this.accessToken = accessToken;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Get the authenticated customer's profile.
|
|
11
|
+
*
|
|
12
|
+
* Returns customer details including ID, email, external ID, and metadata.
|
|
13
|
+
*
|
|
14
|
+
* @returns Customer profile with optional subscription and tier
|
|
15
|
+
*/
|
|
16
|
+
async me() {
|
|
17
|
+
const response = await this.http.json("/customers/me", {
|
|
18
|
+
method: "GET",
|
|
19
|
+
accessToken: this.accessToken
|
|
20
|
+
});
|
|
21
|
+
return response.customer;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get the authenticated customer's subscription details.
|
|
25
|
+
*
|
|
26
|
+
* Returns subscription status, tier information, and billing provider.
|
|
27
|
+
*
|
|
28
|
+
* @returns Subscription details
|
|
29
|
+
*/
|
|
30
|
+
async subscription() {
|
|
31
|
+
const response = await this.http.json("/customers/me/subscription", {
|
|
32
|
+
method: "GET",
|
|
33
|
+
accessToken: this.accessToken
|
|
34
|
+
});
|
|
35
|
+
return response.subscription;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get the authenticated customer's usage metrics.
|
|
39
|
+
*
|
|
40
|
+
* Returns token usage, request counts, and cost for the current billing window.
|
|
41
|
+
*
|
|
42
|
+
* @returns Usage metrics
|
|
43
|
+
*/
|
|
44
|
+
async usage() {
|
|
45
|
+
const response = await this.http.json("/customers/me/usage", {
|
|
46
|
+
method: "GET",
|
|
47
|
+
accessToken: this.accessToken
|
|
48
|
+
});
|
|
49
|
+
return response.usage;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get the authenticated customer's credit balance.
|
|
53
|
+
*
|
|
54
|
+
* For PAYGO (pay-as-you-go) subscriptions, returns the current balance
|
|
55
|
+
* and reserved amount.
|
|
56
|
+
*
|
|
57
|
+
* @returns Balance information
|
|
58
|
+
*/
|
|
59
|
+
async balance() {
|
|
60
|
+
return await this.http.json("/customers/me/balance", {
|
|
61
|
+
method: "GET",
|
|
62
|
+
accessToken: this.accessToken
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get the authenticated customer's balance transaction history.
|
|
67
|
+
*
|
|
68
|
+
* Returns a list of ledger entries showing credits and debits.
|
|
69
|
+
*
|
|
70
|
+
* @returns Ledger entries
|
|
71
|
+
*/
|
|
72
|
+
async balanceHistory() {
|
|
73
|
+
return await this.http.json("/customers/me/balance/history", {
|
|
74
|
+
method: "GET",
|
|
75
|
+
accessToken: this.accessToken
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Create a top-up checkout session.
|
|
80
|
+
*
|
|
81
|
+
* For PAYGO subscriptions, creates a Stripe Checkout session to add credits.
|
|
82
|
+
*
|
|
83
|
+
* @param request - Top-up request with amount and redirect URLs
|
|
84
|
+
* @returns Checkout session with redirect URL
|
|
85
|
+
*/
|
|
86
|
+
async topup(request) {
|
|
87
|
+
return await this.http.json("/customers/me/topup", {
|
|
88
|
+
method: "POST",
|
|
89
|
+
body: request,
|
|
90
|
+
accessToken: this.accessToken
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Change the authenticated customer's subscription tier.
|
|
95
|
+
*
|
|
96
|
+
* Switches to a different tier within the same project.
|
|
97
|
+
*
|
|
98
|
+
* @param tierCode - The tier code to switch to
|
|
99
|
+
* @returns Updated subscription details
|
|
100
|
+
*/
|
|
101
|
+
async changeTier(tierCode) {
|
|
102
|
+
const request = { tier_code: tierCode };
|
|
103
|
+
const response = await this.http.json("/customers/me/change-tier", {
|
|
104
|
+
method: "POST",
|
|
105
|
+
body: request,
|
|
106
|
+
accessToken: this.accessToken
|
|
107
|
+
});
|
|
108
|
+
return response.subscription;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Create a subscription checkout session.
|
|
112
|
+
*
|
|
113
|
+
* Creates a Stripe Checkout session for subscribing to a tier.
|
|
114
|
+
*
|
|
115
|
+
* @param request - Checkout request with tier and redirect URLs
|
|
116
|
+
* @returns Checkout session with redirect URL
|
|
117
|
+
*/
|
|
118
|
+
async checkout(request) {
|
|
119
|
+
return await this.http.json("/customers/me/checkout", {
|
|
120
|
+
method: "POST",
|
|
121
|
+
body: request,
|
|
122
|
+
accessToken: this.accessToken
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
export {
|
|
127
|
+
BillingClient
|
|
128
|
+
};
|