@pymthouse/builder-sdk 0.0.8 → 0.3.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/README.md +106 -2
- package/dist/client-BHfjDvIe.d.ts +129 -0
- package/dist/client-CvhJEhjV.d.cts +129 -0
- package/dist/config.cjs +122 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +29 -0
- package/dist/config.d.ts +29 -0
- package/dist/config.js +111 -0
- package/dist/config.js.map +1 -0
- package/dist/device-initiate.cjs +88 -0
- package/dist/device-initiate.cjs.map +1 -0
- package/dist/device-initiate.d.cts +32 -0
- package/dist/device-initiate.d.ts +32 -0
- package/dist/device-initiate.js +84 -0
- package/dist/device-initiate.js.map +1 -0
- package/dist/device.cjs +1 -1
- package/dist/device.cjs.map +1 -1
- package/dist/device.d.cts +1 -1
- package/dist/device.d.ts +1 -1
- package/dist/device.js +1 -1
- package/dist/device.js.map +1 -1
- package/dist/env.cjs +1071 -28
- package/dist/env.cjs.map +1 -1
- package/dist/env.d.cts +15 -2
- package/dist/env.d.ts +15 -2
- package/dist/env.js +1071 -28
- package/dist/env.js.map +1 -1
- package/dist/gateway/client/index.cjs +492 -0
- package/dist/gateway/client/index.cjs.map +1 -0
- package/dist/gateway/client/index.d.cts +63 -0
- package/dist/gateway/client/index.d.ts +63 -0
- package/dist/gateway/client/index.js +489 -0
- package/dist/gateway/client/index.js.map +1 -0
- package/dist/gateway/index.cjs +16 -0
- package/dist/gateway/index.cjs.map +1 -0
- package/dist/gateway/index.d.cts +52 -0
- package/dist/gateway/index.d.ts +52 -0
- package/dist/gateway/index.js +10 -0
- package/dist/gateway/index.js.map +1 -0
- package/dist/gateway/server/index.cjs +1248 -0
- package/dist/gateway/server/index.cjs.map +1 -0
- package/dist/gateway/server/index.d.cts +31 -0
- package/dist/gateway/server/index.d.ts +31 -0
- package/dist/gateway/server/index.js +1233 -0
- package/dist/gateway/server/index.js.map +1 -0
- package/dist/index.cjs +1401 -137
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -5
- package/dist/index.d.ts +41 -5
- package/dist/index.js +1334 -105
- package/dist/index.js.map +1 -1
- package/dist/ingest-B3Yi8Tb1.d.cts +271 -0
- package/dist/ingest-DoKJTWU9.d.ts +271 -0
- package/dist/plan-pricing.cjs +108 -0
- package/dist/plan-pricing.cjs.map +1 -0
- package/dist/plan-pricing.d.cts +15 -0
- package/dist/plan-pricing.d.ts +15 -0
- package/dist/plan-pricing.js +98 -0
- package/dist/plan-pricing.js.map +1 -0
- package/dist/signer/server.cjs +1366 -0
- package/dist/signer/server.cjs.map +1 -0
- package/dist/signer/server.d.cts +73 -0
- package/dist/signer/server.d.ts +73 -0
- package/dist/signer/server.js +1331 -0
- package/dist/signer/server.js.map +1 -0
- package/dist/tokens.cjs +75 -0
- package/dist/tokens.cjs.map +1 -0
- package/dist/tokens.d.cts +48 -0
- package/dist/tokens.d.ts +48 -0
- package/dist/tokens.js +64 -0
- package/dist/tokens.js.map +1 -0
- package/dist/types-_R1AwEZp.d.cts +343 -0
- package/dist/types-_R1AwEZp.d.ts +343 -0
- package/dist/verify.cjs +1 -1
- package/dist/verify.cjs.map +1 -1
- package/dist/verify.d.cts +1 -1
- package/dist/verify.d.ts +1 -1
- package/dist/verify.js +1 -1
- package/dist/verify.js.map +1 -1
- package/gateway/proto/lp_rpc.proto +542 -0
- package/package.json +57 -1
- package/dist/env-4YmzarGJ.d.ts +0 -68
- package/dist/env-CZczUMzR.d.cts +0 -68
- package/dist/types-W9PJAspR.d.cts +0 -136
- package/dist/types-W9PJAspR.d.ts +0 -136
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { F as FetchLike, S as SignedTicketIngestInput, f as SignedTicketIngestResult } from './types-_R1AwEZp.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* - `pymthouse_hosted`: after sign, POST usage to Builder API (`/usage/signed-tickets`).
|
|
5
|
+
* - `platform_ingest` / `byo_openmeter`: platform calls ingest explicitly (no auto POST).
|
|
6
|
+
*/
|
|
7
|
+
type SignerMeteringMode = "pymthouse_hosted" | "platform_ingest" | "byo_openmeter";
|
|
8
|
+
declare function resolvesToHostedMetering(mode: SignerMeteringMode | undefined): boolean;
|
|
9
|
+
declare function resolvesToPlatformMetering(mode: SignerMeteringMode | undefined): boolean;
|
|
10
|
+
type SignerDmzGate = "http" | "cli";
|
|
11
|
+
interface SignerMeteringConfig {
|
|
12
|
+
mode: SignerMeteringMode;
|
|
13
|
+
openMeterBaseUrl?: string;
|
|
14
|
+
openMeterApiKey?: string;
|
|
15
|
+
meterSlug?: string;
|
|
16
|
+
featureKey?: string;
|
|
17
|
+
}
|
|
18
|
+
interface DirectSignerProxyConfig {
|
|
19
|
+
pymthouseIssuerUrl: string;
|
|
20
|
+
/** Public Builder app client id (`app_…`); used for cache keys and JWT `client_id`. */
|
|
21
|
+
pymthouseClientId: string;
|
|
22
|
+
pymthouseM2MClientId: string;
|
|
23
|
+
pymthouseM2MClientSecret: string;
|
|
24
|
+
remoteSignerUrl: string | URL;
|
|
25
|
+
fetch?: FetchLike;
|
|
26
|
+
allowInsecureHttp?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* When set, incoming request paths matching this prefix are rewritten to the remote signer base.
|
|
29
|
+
* Example: `/api/signer/proxy` → remote `/generate-live-payment` when the suffix is empty.
|
|
30
|
+
*/
|
|
31
|
+
proxyPathPrefix?: string;
|
|
32
|
+
/** Remote path used when the proxied suffix is empty. Defaults to `/generate-live-payment`. */
|
|
33
|
+
defaultRemotePath?: string;
|
|
34
|
+
metering?: SignerMeteringConfig;
|
|
35
|
+
authenticate: (request: Request) => Promise<unknown>;
|
|
36
|
+
resolveExternalUserId: (session: unknown) => Promise<string>;
|
|
37
|
+
beforeSign?: (context: DirectSignerBeforeSignContext) => Promise<DirectSignerBeforeSignResult | void>;
|
|
38
|
+
}
|
|
39
|
+
interface CachedSignerToken {
|
|
40
|
+
jwt: string;
|
|
41
|
+
expiresAt: number;
|
|
42
|
+
refreshAt: number;
|
|
43
|
+
balanceUsdMicros: string;
|
|
44
|
+
lifetimeGrantedUsdMicros: string;
|
|
45
|
+
}
|
|
46
|
+
interface DirectSignerBeforeSignContext {
|
|
47
|
+
token: CachedSignerToken;
|
|
48
|
+
externalUserId: string;
|
|
49
|
+
request: Request;
|
|
50
|
+
}
|
|
51
|
+
type DirectSignerBeforeSignResult = Response | {
|
|
52
|
+
status: number;
|
|
53
|
+
body?: unknown;
|
|
54
|
+
};
|
|
55
|
+
interface MintUserSignerTokenOptions {
|
|
56
|
+
issuerUrl: string;
|
|
57
|
+
m2mClientId: string;
|
|
58
|
+
m2mClientSecret: string;
|
|
59
|
+
externalUserId: string;
|
|
60
|
+
fetch?: FetchLike;
|
|
61
|
+
allowInsecureHttp?: boolean;
|
|
62
|
+
}
|
|
63
|
+
interface MintUserSignerTokenResponse {
|
|
64
|
+
access_token: string;
|
|
65
|
+
expires_in: number;
|
|
66
|
+
balanceUsdMicros: string;
|
|
67
|
+
lifetimeGrantedUsdMicros: string;
|
|
68
|
+
}
|
|
69
|
+
interface SignerTokenManagerOptions {
|
|
70
|
+
publicClientId: string;
|
|
71
|
+
mint: (externalUserId: string) => Promise<CachedSignerToken>;
|
|
72
|
+
/** Fraction of TTL after which a proactive refresh runs. Defaults to `0.8`. */
|
|
73
|
+
ttlRefreshRatio?: number;
|
|
74
|
+
fetch?: FetchLike;
|
|
75
|
+
}
|
|
76
|
+
interface ForwardDirectSignerRequestOptions {
|
|
77
|
+
request: Request;
|
|
78
|
+
remoteSignerUrl: string | URL;
|
|
79
|
+
jwt: string;
|
|
80
|
+
proxyPathPrefix?: string;
|
|
81
|
+
defaultRemotePath?: string;
|
|
82
|
+
fetch?: FetchLike;
|
|
83
|
+
}
|
|
84
|
+
interface ForwardToSignerOptions {
|
|
85
|
+
baseUrl: string;
|
|
86
|
+
path: string;
|
|
87
|
+
method: string;
|
|
88
|
+
body?: unknown;
|
|
89
|
+
subject: string;
|
|
90
|
+
getDmzToken: (subject: string, gate: SignerDmzGate) => Promise<string>;
|
|
91
|
+
forwardJwt?: boolean;
|
|
92
|
+
/** Merged after Authorization; used for go-livepeer trusted_headers identity. */
|
|
93
|
+
extraHeaders?: Record<string, string>;
|
|
94
|
+
timeoutMs?: number;
|
|
95
|
+
fetch?: FetchLike;
|
|
96
|
+
}
|
|
97
|
+
interface ForwardToSignerResult {
|
|
98
|
+
response: Response;
|
|
99
|
+
requestUrl: string;
|
|
100
|
+
authorizationHeader?: string;
|
|
101
|
+
}
|
|
102
|
+
interface ProbeSignerHttpReachabilityOptions {
|
|
103
|
+
signerUrl: string;
|
|
104
|
+
getDmzToken: (subject: string, gate: SignerDmzGate) => Promise<string>;
|
|
105
|
+
probeSubject?: string;
|
|
106
|
+
timeoutMs?: number;
|
|
107
|
+
forwardJwt?: boolean;
|
|
108
|
+
fetch?: FetchLike;
|
|
109
|
+
}
|
|
110
|
+
interface SignerJwtIdentity {
|
|
111
|
+
issuer: string;
|
|
112
|
+
clientId: string;
|
|
113
|
+
usageSubject: string;
|
|
114
|
+
usageSubjectType: string;
|
|
115
|
+
}
|
|
116
|
+
interface DeviceExchangeRequestBody {
|
|
117
|
+
deviceToken: string;
|
|
118
|
+
scope?: string;
|
|
119
|
+
clientId?: string;
|
|
120
|
+
}
|
|
121
|
+
interface DeviceExchangeResponse {
|
|
122
|
+
access_token: string;
|
|
123
|
+
token_type: "Bearer";
|
|
124
|
+
expires_in: number;
|
|
125
|
+
scope: string;
|
|
126
|
+
balanceUsdMicros: string;
|
|
127
|
+
lifetimeGrantedUsdMicros: string;
|
|
128
|
+
/** Public signer DMZ base URL clients should call directly (no trailing slash). */
|
|
129
|
+
signerUrl?: string;
|
|
130
|
+
token?: {
|
|
131
|
+
accessToken: string;
|
|
132
|
+
access_token: string;
|
|
133
|
+
expiresIn: number;
|
|
134
|
+
expires_in: number;
|
|
135
|
+
scope: string;
|
|
136
|
+
balanceUsdMicros: string;
|
|
137
|
+
lifetimeGrantedUsdMicros: string;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
interface ExchangeDeviceTokenForSignerOptions {
|
|
141
|
+
facadeUrl: string;
|
|
142
|
+
deviceToken: string;
|
|
143
|
+
scope?: string;
|
|
144
|
+
clientId?: string;
|
|
145
|
+
fetch?: FetchLike;
|
|
146
|
+
}
|
|
147
|
+
interface MintSignerTokenFromDeviceTokenOptions {
|
|
148
|
+
issuerUrl: string;
|
|
149
|
+
m2mClientId: string;
|
|
150
|
+
m2mClientSecret: string;
|
|
151
|
+
deviceToken: string;
|
|
152
|
+
scope?: string;
|
|
153
|
+
audience?: string;
|
|
154
|
+
fetch?: FetchLike;
|
|
155
|
+
allowInsecureHttp?: boolean;
|
|
156
|
+
}
|
|
157
|
+
interface DeviceExchangeMintContext {
|
|
158
|
+
scope?: string;
|
|
159
|
+
clientId?: string;
|
|
160
|
+
}
|
|
161
|
+
interface DeviceExchangeMintResult {
|
|
162
|
+
access_token: string;
|
|
163
|
+
expires_in: number;
|
|
164
|
+
scope: string;
|
|
165
|
+
balanceUsdMicros: string;
|
|
166
|
+
lifetimeGrantedUsdMicros: string;
|
|
167
|
+
}
|
|
168
|
+
interface DeviceExchangeHandlerConfig {
|
|
169
|
+
mint: (deviceToken: string, context: DeviceExchangeMintContext) => Promise<DeviceExchangeMintResult>;
|
|
170
|
+
/** Resolved signer DMZ base URL included in the exchange response. */
|
|
171
|
+
getSignerUrl?: () => string | Promise<string>;
|
|
172
|
+
signerUrl?: string;
|
|
173
|
+
}
|
|
174
|
+
interface DeviceExchangeHandlerConfigRemote extends Omit<MintSignerTokenFromDeviceTokenOptions, "deviceToken"> {
|
|
175
|
+
mint?: never;
|
|
176
|
+
getSignerUrl?: () => string | Promise<string>;
|
|
177
|
+
signerUrl?: string;
|
|
178
|
+
}
|
|
179
|
+
interface ApiKeyExchangeRequestBody {
|
|
180
|
+
apiKey: string;
|
|
181
|
+
scope?: string;
|
|
182
|
+
clientId?: string;
|
|
183
|
+
}
|
|
184
|
+
type ApiKeyExchangeMintResult = DeviceExchangeMintResult;
|
|
185
|
+
interface ApiKeyExchangeHandlerConfig {
|
|
186
|
+
issuerUrl: string;
|
|
187
|
+
publicClientId: string;
|
|
188
|
+
m2mClientId: string;
|
|
189
|
+
m2mClientSecret: string;
|
|
190
|
+
signerUrl?: string;
|
|
191
|
+
audience?: string;
|
|
192
|
+
fetch?: FetchLike;
|
|
193
|
+
allowInsecureHttp?: boolean;
|
|
194
|
+
}
|
|
195
|
+
interface ExchangeApiKeyForSignerOptions {
|
|
196
|
+
facadeUrl: string;
|
|
197
|
+
apiKey: string;
|
|
198
|
+
scope?: string;
|
|
199
|
+
clientId?: string;
|
|
200
|
+
fetch?: FetchLike;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
type SignerUsageSnapshot = {
|
|
204
|
+
requestId: string;
|
|
205
|
+
computedFeeWei: string;
|
|
206
|
+
computedFeeUsdMicros: bigint;
|
|
207
|
+
ethUsdPrice?: string;
|
|
208
|
+
ethUsdRoundId?: string;
|
|
209
|
+
ethUsdObservedAt?: string;
|
|
210
|
+
pixels?: string;
|
|
211
|
+
billableSecs?: string;
|
|
212
|
+
pipeline?: string;
|
|
213
|
+
modelId?: string;
|
|
214
|
+
};
|
|
215
|
+
declare function normalizeSignerBaseUrl(base: string): string;
|
|
216
|
+
declare function resolveSignerBaseUrl(input: {
|
|
217
|
+
envUrl?: string | null;
|
|
218
|
+
storedUrl?: string | null;
|
|
219
|
+
storedPort?: number | null;
|
|
220
|
+
testSignerUrl?: string | null;
|
|
221
|
+
defaultPort?: number;
|
|
222
|
+
}): string;
|
|
223
|
+
declare function getCachedDmzBearerToken(subject: string, gate: SignerDmzGate, getDmzToken: (subject: string, gate: SignerDmzGate) => Promise<string>): Promise<string>;
|
|
224
|
+
declare function readSignerUpstreamBody(response: Response): Promise<unknown>;
|
|
225
|
+
declare function pickConflictingStringAliases(body: Record<string, unknown>, ...keys: string[]): {
|
|
226
|
+
ok: true;
|
|
227
|
+
value: string | undefined;
|
|
228
|
+
} | {
|
|
229
|
+
ok: false;
|
|
230
|
+
message: string;
|
|
231
|
+
};
|
|
232
|
+
declare function pickConflictingNumberAliases(body: Record<string, unknown>, ...keys: string[]): {
|
|
233
|
+
ok: true;
|
|
234
|
+
value: number | undefined;
|
|
235
|
+
} | {
|
|
236
|
+
ok: false;
|
|
237
|
+
message: string;
|
|
238
|
+
};
|
|
239
|
+
declare function parseSignerUsageSnapshot(body: unknown): SignerUsageSnapshot | null;
|
|
240
|
+
declare function stripSignerUsageFromResponse(body: unknown): void;
|
|
241
|
+
declare function forwardToSigner(options: ForwardToSignerOptions): Promise<ForwardToSignerResult>;
|
|
242
|
+
declare function probeSignerHttpReachability(options: ProbeSignerHttpReachabilityOptions): Promise<{
|
|
243
|
+
reachable: boolean;
|
|
244
|
+
ethAddress?: string;
|
|
245
|
+
}>;
|
|
246
|
+
|
|
247
|
+
type IngestSignedTicketOptions = {
|
|
248
|
+
issuerUrl: string;
|
|
249
|
+
publicClientId: string;
|
|
250
|
+
m2mClientId: string;
|
|
251
|
+
m2mClientSecret: string;
|
|
252
|
+
ticket: SignedTicketIngestInput;
|
|
253
|
+
fetch?: FetchLike;
|
|
254
|
+
};
|
|
255
|
+
type IngestSignedTicketsBatchOptions = Omit<IngestSignedTicketOptions, "ticket"> & {
|
|
256
|
+
tickets: SignedTicketIngestInput[];
|
|
257
|
+
};
|
|
258
|
+
declare function signerSnapshotToIngestPayload(input: {
|
|
259
|
+
snapshot: SignerUsageSnapshot;
|
|
260
|
+
externalUserId: string;
|
|
261
|
+
gatewayRequestId?: string;
|
|
262
|
+
}): SignedTicketIngestInput;
|
|
263
|
+
declare function ingestSignedTicket(options: IngestSignedTicketOptions): Promise<SignedTicketIngestResult>;
|
|
264
|
+
declare function ingestSignedTicketsBatch(options: IngestSignedTicketsBatchOptions): Promise<{
|
|
265
|
+
results: Array<SignedTicketIngestResult & {
|
|
266
|
+
requestId?: string;
|
|
267
|
+
ok?: boolean;
|
|
268
|
+
}>;
|
|
269
|
+
}>;
|
|
270
|
+
|
|
271
|
+
export { type ApiKeyExchangeHandlerConfig as A, parseSignerUsageSnapshot as B, type CachedSignerToken as C, type DeviceExchangeHandlerConfig as D, type ExchangeDeviceTokenForSignerOptions as E, type ForwardDirectSignerRequestOptions as F, pickConflictingNumberAliases as G, pickConflictingStringAliases as H, probeSignerHttpReachability as I, readSignerUpstreamBody as J, resolveSignerBaseUrl as K, resolvesToHostedMetering as L, type MintUserSignerTokenOptions as M, resolvesToPlatformMetering as N, stripSignerUsageFromResponse as O, type ProbeSignerHttpReachabilityOptions as P, type SignerTokenManagerOptions as S, ingestSignedTicketsBatch as a, type SignerJwtIdentity as b, type DeviceExchangeHandlerConfigRemote as c, type DeviceExchangeResponse as d, type MintSignerTokenFromDeviceTokenOptions as e, type DeviceExchangeMintResult as f, type DeviceExchangeRequestBody as g, type ExchangeApiKeyForSignerOptions as h, ingestSignedTicket as i, type ApiKeyExchangeMintResult as j, type ApiKeyExchangeRequestBody as k, type DirectSignerProxyConfig as l, type DeviceExchangeMintContext as m, type DirectSignerBeforeSignContext as n, type DirectSignerBeforeSignResult as o, type ForwardToSignerOptions as p, type ForwardToSignerResult as q, type MintUserSignerTokenResponse as r, signerSnapshotToIngestPayload as s, type SignerDmzGate as t, type SignerMeteringConfig as u, type SignerMeteringMode as v, type SignerUsageSnapshot as w, forwardToSigner as x, getCachedDmzBearerToken as y, normalizeSignerBaseUrl as z };
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { F as FetchLike, S as SignedTicketIngestInput, f as SignedTicketIngestResult } from './types-_R1AwEZp.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* - `pymthouse_hosted`: after sign, POST usage to Builder API (`/usage/signed-tickets`).
|
|
5
|
+
* - `platform_ingest` / `byo_openmeter`: platform calls ingest explicitly (no auto POST).
|
|
6
|
+
*/
|
|
7
|
+
type SignerMeteringMode = "pymthouse_hosted" | "platform_ingest" | "byo_openmeter";
|
|
8
|
+
declare function resolvesToHostedMetering(mode: SignerMeteringMode | undefined): boolean;
|
|
9
|
+
declare function resolvesToPlatformMetering(mode: SignerMeteringMode | undefined): boolean;
|
|
10
|
+
type SignerDmzGate = "http" | "cli";
|
|
11
|
+
interface SignerMeteringConfig {
|
|
12
|
+
mode: SignerMeteringMode;
|
|
13
|
+
openMeterBaseUrl?: string;
|
|
14
|
+
openMeterApiKey?: string;
|
|
15
|
+
meterSlug?: string;
|
|
16
|
+
featureKey?: string;
|
|
17
|
+
}
|
|
18
|
+
interface DirectSignerProxyConfig {
|
|
19
|
+
pymthouseIssuerUrl: string;
|
|
20
|
+
/** Public Builder app client id (`app_…`); used for cache keys and JWT `client_id`. */
|
|
21
|
+
pymthouseClientId: string;
|
|
22
|
+
pymthouseM2MClientId: string;
|
|
23
|
+
pymthouseM2MClientSecret: string;
|
|
24
|
+
remoteSignerUrl: string | URL;
|
|
25
|
+
fetch?: FetchLike;
|
|
26
|
+
allowInsecureHttp?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* When set, incoming request paths matching this prefix are rewritten to the remote signer base.
|
|
29
|
+
* Example: `/api/signer/proxy` → remote `/generate-live-payment` when the suffix is empty.
|
|
30
|
+
*/
|
|
31
|
+
proxyPathPrefix?: string;
|
|
32
|
+
/** Remote path used when the proxied suffix is empty. Defaults to `/generate-live-payment`. */
|
|
33
|
+
defaultRemotePath?: string;
|
|
34
|
+
metering?: SignerMeteringConfig;
|
|
35
|
+
authenticate: (request: Request) => Promise<unknown>;
|
|
36
|
+
resolveExternalUserId: (session: unknown) => Promise<string>;
|
|
37
|
+
beforeSign?: (context: DirectSignerBeforeSignContext) => Promise<DirectSignerBeforeSignResult | void>;
|
|
38
|
+
}
|
|
39
|
+
interface CachedSignerToken {
|
|
40
|
+
jwt: string;
|
|
41
|
+
expiresAt: number;
|
|
42
|
+
refreshAt: number;
|
|
43
|
+
balanceUsdMicros: string;
|
|
44
|
+
lifetimeGrantedUsdMicros: string;
|
|
45
|
+
}
|
|
46
|
+
interface DirectSignerBeforeSignContext {
|
|
47
|
+
token: CachedSignerToken;
|
|
48
|
+
externalUserId: string;
|
|
49
|
+
request: Request;
|
|
50
|
+
}
|
|
51
|
+
type DirectSignerBeforeSignResult = Response | {
|
|
52
|
+
status: number;
|
|
53
|
+
body?: unknown;
|
|
54
|
+
};
|
|
55
|
+
interface MintUserSignerTokenOptions {
|
|
56
|
+
issuerUrl: string;
|
|
57
|
+
m2mClientId: string;
|
|
58
|
+
m2mClientSecret: string;
|
|
59
|
+
externalUserId: string;
|
|
60
|
+
fetch?: FetchLike;
|
|
61
|
+
allowInsecureHttp?: boolean;
|
|
62
|
+
}
|
|
63
|
+
interface MintUserSignerTokenResponse {
|
|
64
|
+
access_token: string;
|
|
65
|
+
expires_in: number;
|
|
66
|
+
balanceUsdMicros: string;
|
|
67
|
+
lifetimeGrantedUsdMicros: string;
|
|
68
|
+
}
|
|
69
|
+
interface SignerTokenManagerOptions {
|
|
70
|
+
publicClientId: string;
|
|
71
|
+
mint: (externalUserId: string) => Promise<CachedSignerToken>;
|
|
72
|
+
/** Fraction of TTL after which a proactive refresh runs. Defaults to `0.8`. */
|
|
73
|
+
ttlRefreshRatio?: number;
|
|
74
|
+
fetch?: FetchLike;
|
|
75
|
+
}
|
|
76
|
+
interface ForwardDirectSignerRequestOptions {
|
|
77
|
+
request: Request;
|
|
78
|
+
remoteSignerUrl: string | URL;
|
|
79
|
+
jwt: string;
|
|
80
|
+
proxyPathPrefix?: string;
|
|
81
|
+
defaultRemotePath?: string;
|
|
82
|
+
fetch?: FetchLike;
|
|
83
|
+
}
|
|
84
|
+
interface ForwardToSignerOptions {
|
|
85
|
+
baseUrl: string;
|
|
86
|
+
path: string;
|
|
87
|
+
method: string;
|
|
88
|
+
body?: unknown;
|
|
89
|
+
subject: string;
|
|
90
|
+
getDmzToken: (subject: string, gate: SignerDmzGate) => Promise<string>;
|
|
91
|
+
forwardJwt?: boolean;
|
|
92
|
+
/** Merged after Authorization; used for go-livepeer trusted_headers identity. */
|
|
93
|
+
extraHeaders?: Record<string, string>;
|
|
94
|
+
timeoutMs?: number;
|
|
95
|
+
fetch?: FetchLike;
|
|
96
|
+
}
|
|
97
|
+
interface ForwardToSignerResult {
|
|
98
|
+
response: Response;
|
|
99
|
+
requestUrl: string;
|
|
100
|
+
authorizationHeader?: string;
|
|
101
|
+
}
|
|
102
|
+
interface ProbeSignerHttpReachabilityOptions {
|
|
103
|
+
signerUrl: string;
|
|
104
|
+
getDmzToken: (subject: string, gate: SignerDmzGate) => Promise<string>;
|
|
105
|
+
probeSubject?: string;
|
|
106
|
+
timeoutMs?: number;
|
|
107
|
+
forwardJwt?: boolean;
|
|
108
|
+
fetch?: FetchLike;
|
|
109
|
+
}
|
|
110
|
+
interface SignerJwtIdentity {
|
|
111
|
+
issuer: string;
|
|
112
|
+
clientId: string;
|
|
113
|
+
usageSubject: string;
|
|
114
|
+
usageSubjectType: string;
|
|
115
|
+
}
|
|
116
|
+
interface DeviceExchangeRequestBody {
|
|
117
|
+
deviceToken: string;
|
|
118
|
+
scope?: string;
|
|
119
|
+
clientId?: string;
|
|
120
|
+
}
|
|
121
|
+
interface DeviceExchangeResponse {
|
|
122
|
+
access_token: string;
|
|
123
|
+
token_type: "Bearer";
|
|
124
|
+
expires_in: number;
|
|
125
|
+
scope: string;
|
|
126
|
+
balanceUsdMicros: string;
|
|
127
|
+
lifetimeGrantedUsdMicros: string;
|
|
128
|
+
/** Public signer DMZ base URL clients should call directly (no trailing slash). */
|
|
129
|
+
signerUrl?: string;
|
|
130
|
+
token?: {
|
|
131
|
+
accessToken: string;
|
|
132
|
+
access_token: string;
|
|
133
|
+
expiresIn: number;
|
|
134
|
+
expires_in: number;
|
|
135
|
+
scope: string;
|
|
136
|
+
balanceUsdMicros: string;
|
|
137
|
+
lifetimeGrantedUsdMicros: string;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
interface ExchangeDeviceTokenForSignerOptions {
|
|
141
|
+
facadeUrl: string;
|
|
142
|
+
deviceToken: string;
|
|
143
|
+
scope?: string;
|
|
144
|
+
clientId?: string;
|
|
145
|
+
fetch?: FetchLike;
|
|
146
|
+
}
|
|
147
|
+
interface MintSignerTokenFromDeviceTokenOptions {
|
|
148
|
+
issuerUrl: string;
|
|
149
|
+
m2mClientId: string;
|
|
150
|
+
m2mClientSecret: string;
|
|
151
|
+
deviceToken: string;
|
|
152
|
+
scope?: string;
|
|
153
|
+
audience?: string;
|
|
154
|
+
fetch?: FetchLike;
|
|
155
|
+
allowInsecureHttp?: boolean;
|
|
156
|
+
}
|
|
157
|
+
interface DeviceExchangeMintContext {
|
|
158
|
+
scope?: string;
|
|
159
|
+
clientId?: string;
|
|
160
|
+
}
|
|
161
|
+
interface DeviceExchangeMintResult {
|
|
162
|
+
access_token: string;
|
|
163
|
+
expires_in: number;
|
|
164
|
+
scope: string;
|
|
165
|
+
balanceUsdMicros: string;
|
|
166
|
+
lifetimeGrantedUsdMicros: string;
|
|
167
|
+
}
|
|
168
|
+
interface DeviceExchangeHandlerConfig {
|
|
169
|
+
mint: (deviceToken: string, context: DeviceExchangeMintContext) => Promise<DeviceExchangeMintResult>;
|
|
170
|
+
/** Resolved signer DMZ base URL included in the exchange response. */
|
|
171
|
+
getSignerUrl?: () => string | Promise<string>;
|
|
172
|
+
signerUrl?: string;
|
|
173
|
+
}
|
|
174
|
+
interface DeviceExchangeHandlerConfigRemote extends Omit<MintSignerTokenFromDeviceTokenOptions, "deviceToken"> {
|
|
175
|
+
mint?: never;
|
|
176
|
+
getSignerUrl?: () => string | Promise<string>;
|
|
177
|
+
signerUrl?: string;
|
|
178
|
+
}
|
|
179
|
+
interface ApiKeyExchangeRequestBody {
|
|
180
|
+
apiKey: string;
|
|
181
|
+
scope?: string;
|
|
182
|
+
clientId?: string;
|
|
183
|
+
}
|
|
184
|
+
type ApiKeyExchangeMintResult = DeviceExchangeMintResult;
|
|
185
|
+
interface ApiKeyExchangeHandlerConfig {
|
|
186
|
+
issuerUrl: string;
|
|
187
|
+
publicClientId: string;
|
|
188
|
+
m2mClientId: string;
|
|
189
|
+
m2mClientSecret: string;
|
|
190
|
+
signerUrl?: string;
|
|
191
|
+
audience?: string;
|
|
192
|
+
fetch?: FetchLike;
|
|
193
|
+
allowInsecureHttp?: boolean;
|
|
194
|
+
}
|
|
195
|
+
interface ExchangeApiKeyForSignerOptions {
|
|
196
|
+
facadeUrl: string;
|
|
197
|
+
apiKey: string;
|
|
198
|
+
scope?: string;
|
|
199
|
+
clientId?: string;
|
|
200
|
+
fetch?: FetchLike;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
type SignerUsageSnapshot = {
|
|
204
|
+
requestId: string;
|
|
205
|
+
computedFeeWei: string;
|
|
206
|
+
computedFeeUsdMicros: bigint;
|
|
207
|
+
ethUsdPrice?: string;
|
|
208
|
+
ethUsdRoundId?: string;
|
|
209
|
+
ethUsdObservedAt?: string;
|
|
210
|
+
pixels?: string;
|
|
211
|
+
billableSecs?: string;
|
|
212
|
+
pipeline?: string;
|
|
213
|
+
modelId?: string;
|
|
214
|
+
};
|
|
215
|
+
declare function normalizeSignerBaseUrl(base: string): string;
|
|
216
|
+
declare function resolveSignerBaseUrl(input: {
|
|
217
|
+
envUrl?: string | null;
|
|
218
|
+
storedUrl?: string | null;
|
|
219
|
+
storedPort?: number | null;
|
|
220
|
+
testSignerUrl?: string | null;
|
|
221
|
+
defaultPort?: number;
|
|
222
|
+
}): string;
|
|
223
|
+
declare function getCachedDmzBearerToken(subject: string, gate: SignerDmzGate, getDmzToken: (subject: string, gate: SignerDmzGate) => Promise<string>): Promise<string>;
|
|
224
|
+
declare function readSignerUpstreamBody(response: Response): Promise<unknown>;
|
|
225
|
+
declare function pickConflictingStringAliases(body: Record<string, unknown>, ...keys: string[]): {
|
|
226
|
+
ok: true;
|
|
227
|
+
value: string | undefined;
|
|
228
|
+
} | {
|
|
229
|
+
ok: false;
|
|
230
|
+
message: string;
|
|
231
|
+
};
|
|
232
|
+
declare function pickConflictingNumberAliases(body: Record<string, unknown>, ...keys: string[]): {
|
|
233
|
+
ok: true;
|
|
234
|
+
value: number | undefined;
|
|
235
|
+
} | {
|
|
236
|
+
ok: false;
|
|
237
|
+
message: string;
|
|
238
|
+
};
|
|
239
|
+
declare function parseSignerUsageSnapshot(body: unknown): SignerUsageSnapshot | null;
|
|
240
|
+
declare function stripSignerUsageFromResponse(body: unknown): void;
|
|
241
|
+
declare function forwardToSigner(options: ForwardToSignerOptions): Promise<ForwardToSignerResult>;
|
|
242
|
+
declare function probeSignerHttpReachability(options: ProbeSignerHttpReachabilityOptions): Promise<{
|
|
243
|
+
reachable: boolean;
|
|
244
|
+
ethAddress?: string;
|
|
245
|
+
}>;
|
|
246
|
+
|
|
247
|
+
type IngestSignedTicketOptions = {
|
|
248
|
+
issuerUrl: string;
|
|
249
|
+
publicClientId: string;
|
|
250
|
+
m2mClientId: string;
|
|
251
|
+
m2mClientSecret: string;
|
|
252
|
+
ticket: SignedTicketIngestInput;
|
|
253
|
+
fetch?: FetchLike;
|
|
254
|
+
};
|
|
255
|
+
type IngestSignedTicketsBatchOptions = Omit<IngestSignedTicketOptions, "ticket"> & {
|
|
256
|
+
tickets: SignedTicketIngestInput[];
|
|
257
|
+
};
|
|
258
|
+
declare function signerSnapshotToIngestPayload(input: {
|
|
259
|
+
snapshot: SignerUsageSnapshot;
|
|
260
|
+
externalUserId: string;
|
|
261
|
+
gatewayRequestId?: string;
|
|
262
|
+
}): SignedTicketIngestInput;
|
|
263
|
+
declare function ingestSignedTicket(options: IngestSignedTicketOptions): Promise<SignedTicketIngestResult>;
|
|
264
|
+
declare function ingestSignedTicketsBatch(options: IngestSignedTicketsBatchOptions): Promise<{
|
|
265
|
+
results: Array<SignedTicketIngestResult & {
|
|
266
|
+
requestId?: string;
|
|
267
|
+
ok?: boolean;
|
|
268
|
+
}>;
|
|
269
|
+
}>;
|
|
270
|
+
|
|
271
|
+
export { type ApiKeyExchangeHandlerConfig as A, parseSignerUsageSnapshot as B, type CachedSignerToken as C, type DeviceExchangeHandlerConfig as D, type ExchangeDeviceTokenForSignerOptions as E, type ForwardDirectSignerRequestOptions as F, pickConflictingNumberAliases as G, pickConflictingStringAliases as H, probeSignerHttpReachability as I, readSignerUpstreamBody as J, resolveSignerBaseUrl as K, resolvesToHostedMetering as L, type MintUserSignerTokenOptions as M, resolvesToPlatformMetering as N, stripSignerUsageFromResponse as O, type ProbeSignerHttpReachabilityOptions as P, type SignerTokenManagerOptions as S, ingestSignedTicketsBatch as a, type SignerJwtIdentity as b, type DeviceExchangeHandlerConfigRemote as c, type DeviceExchangeResponse as d, type MintSignerTokenFromDeviceTokenOptions as e, type DeviceExchangeMintResult as f, type DeviceExchangeRequestBody as g, type ExchangeApiKeyForSignerOptions as h, ingestSignedTicket as i, type ApiKeyExchangeMintResult as j, type ApiKeyExchangeRequestBody as k, type DirectSignerProxyConfig as l, type DeviceExchangeMintContext as m, type DirectSignerBeforeSignContext as n, type DirectSignerBeforeSignResult as o, type ForwardToSignerOptions as p, type ForwardToSignerResult as q, type MintUserSignerTokenResponse as r, signerSnapshotToIngestPayload as s, type SignerDmzGate as t, type SignerMeteringConfig as u, type SignerMeteringMode as v, type SignerUsageSnapshot as w, forwardToSigner as x, getCachedDmzBearerToken as y, normalizeSignerBaseUrl as z };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/plan-pricing.ts
|
|
4
|
+
var NETWORK_USD_PER_MICRO = 1e-6;
|
|
5
|
+
var RETAIL_RATE_DECIMALS = 9;
|
|
6
|
+
function trimFixedDecimalZeros(fixed) {
|
|
7
|
+
const dotIndex = fixed.indexOf(".");
|
|
8
|
+
if (dotIndex === -1) {
|
|
9
|
+
return fixed;
|
|
10
|
+
}
|
|
11
|
+
let end = fixed.length;
|
|
12
|
+
while (end > dotIndex + 1 && fixed[end - 1] === "0") {
|
|
13
|
+
end -= 1;
|
|
14
|
+
}
|
|
15
|
+
if (end === dotIndex + 1) {
|
|
16
|
+
end = dotIndex;
|
|
17
|
+
}
|
|
18
|
+
const trimmed = fixed.slice(0, end);
|
|
19
|
+
return trimmed.length > 0 ? trimmed : "0";
|
|
20
|
+
}
|
|
21
|
+
function defaultRetailRateUsd() {
|
|
22
|
+
return formatRetailRateUsd(NETWORK_USD_PER_MICRO);
|
|
23
|
+
}
|
|
24
|
+
function formatRetailRateUsd(value) {
|
|
25
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
26
|
+
return defaultRetailRateUsd();
|
|
27
|
+
}
|
|
28
|
+
return trimFixedDecimalZeros(value.toFixed(RETAIL_RATE_DECIMALS));
|
|
29
|
+
}
|
|
30
|
+
function parseRetailRateUsd(raw) {
|
|
31
|
+
if (raw === null || raw === void 0) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const trimmed = String(raw).trim();
|
|
35
|
+
if (!trimmed) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const n = Number(trimmed);
|
|
39
|
+
if (!Number.isFinite(n) || n < 0) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return formatRetailRateUsd(n);
|
|
43
|
+
}
|
|
44
|
+
function markupPercentToRetailRateUsd(markupPercent) {
|
|
45
|
+
const pct = Number.isFinite(markupPercent) ? Math.max(0, markupPercent) : 0;
|
|
46
|
+
return formatRetailRateUsd(NETWORK_USD_PER_MICRO * (1 + pct / 100));
|
|
47
|
+
}
|
|
48
|
+
function retailRateUsdToMarkupPercent(raw) {
|
|
49
|
+
const rate = parseRetailRateUsd(raw);
|
|
50
|
+
if (!rate) {
|
|
51
|
+
return "";
|
|
52
|
+
}
|
|
53
|
+
const n = Number(rate);
|
|
54
|
+
if (!Number.isFinite(n) || n <= NETWORK_USD_PER_MICRO) {
|
|
55
|
+
return n === NETWORK_USD_PER_MICRO ? "0" : "";
|
|
56
|
+
}
|
|
57
|
+
const pct = (n / NETWORK_USD_PER_MICRO - 1) * 100;
|
|
58
|
+
if (!Number.isFinite(pct) || pct <= 0) {
|
|
59
|
+
return "";
|
|
60
|
+
}
|
|
61
|
+
return pct % 1 === 0 ? String(Math.round(pct)) : pct.toFixed(1);
|
|
62
|
+
}
|
|
63
|
+
function retailRateUsdPerMillion(raw) {
|
|
64
|
+
const rate = parseRetailRateUsd(raw);
|
|
65
|
+
if (!rate) {
|
|
66
|
+
return "";
|
|
67
|
+
}
|
|
68
|
+
const perM = Number(rate) * 1e6;
|
|
69
|
+
if (!Number.isFinite(perM)) {
|
|
70
|
+
return "";
|
|
71
|
+
}
|
|
72
|
+
return perM.toFixed(2);
|
|
73
|
+
}
|
|
74
|
+
function parseMarkupPercentInput(raw) {
|
|
75
|
+
const trimmed = raw.trim();
|
|
76
|
+
if (!trimmed) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
const n = Number(trimmed);
|
|
80
|
+
if (!Number.isFinite(n) || n < 0) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
return n;
|
|
84
|
+
}
|
|
85
|
+
function applyRetailRateToNetworkMicros(networkFeeUsdMicros, retailRateUsd) {
|
|
86
|
+
const networkPerMicro = NETWORK_USD_PER_MICRO;
|
|
87
|
+
const retail = Number(retailRateUsd);
|
|
88
|
+
if (!Number.isFinite(retail) || retail <= 0) {
|
|
89
|
+
return networkFeeUsdMicros;
|
|
90
|
+
}
|
|
91
|
+
const ratio = retail / networkPerMicro;
|
|
92
|
+
if (!Number.isFinite(ratio) || ratio <= 0) {
|
|
93
|
+
return networkFeeUsdMicros;
|
|
94
|
+
}
|
|
95
|
+
return networkFeeUsdMicros * BigInt(Math.round(ratio * 1e6)) / 1000000n;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
exports.NETWORK_USD_PER_MICRO = NETWORK_USD_PER_MICRO;
|
|
99
|
+
exports.applyRetailRateToNetworkMicros = applyRetailRateToNetworkMicros;
|
|
100
|
+
exports.defaultRetailRateUsd = defaultRetailRateUsd;
|
|
101
|
+
exports.formatRetailRateUsd = formatRetailRateUsd;
|
|
102
|
+
exports.markupPercentToRetailRateUsd = markupPercentToRetailRateUsd;
|
|
103
|
+
exports.parseMarkupPercentInput = parseMarkupPercentInput;
|
|
104
|
+
exports.parseRetailRateUsd = parseRetailRateUsd;
|
|
105
|
+
exports.retailRateUsdPerMillion = retailRateUsdPerMillion;
|
|
106
|
+
exports.retailRateUsdToMarkupPercent = retailRateUsdToMarkupPercent;
|
|
107
|
+
//# sourceMappingURL=plan-pricing.cjs.map
|
|
108
|
+
//# sourceMappingURL=plan-pricing.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plan-pricing.ts"],"names":[],"mappings":"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","file":"plan-pricing.cjs","sourcesContent":["/** Network cost pass-through: $1 retail per $1M of network USD-micros metered. */\nexport const NETWORK_USD_PER_MICRO = 0.000001;\n\nconst RETAIL_RATE_DECIMALS = 9;\n\n/** Strip trailing fractional zeros without regex (avoids ReDoS on user-facing inputs). */\nfunction trimFixedDecimalZeros(fixed: string): string {\n const dotIndex = fixed.indexOf(\".\");\n if (dotIndex === -1) {\n return fixed;\n }\n let end = fixed.length;\n while (end > dotIndex + 1 && fixed[end - 1] === \"0\") {\n end -= 1;\n }\n if (end === dotIndex + 1) {\n end = dotIndex;\n }\n const trimmed = fixed.slice(0, end);\n return trimmed.length > 0 ? trimmed : \"0\";\n}\n\nexport function defaultRetailRateUsd(): string {\n return formatRetailRateUsd(NETWORK_USD_PER_MICRO);\n}\n\nexport function formatRetailRateUsd(value: number): string {\n if (!Number.isFinite(value) || value < 0) {\n return defaultRetailRateUsd();\n }\n return trimFixedDecimalZeros(value.toFixed(RETAIL_RATE_DECIMALS));\n}\n\nexport function parseRetailRateUsd(raw: string | null | undefined): string | null {\n if (raw === null || raw === undefined) {\n return null;\n }\n const trimmed = String(raw).trim();\n if (!trimmed) {\n return null;\n }\n const n = Number(trimmed);\n if (!Number.isFinite(n) || n < 0) {\n return null;\n }\n return formatRetailRateUsd(n);\n}\n\n/** Markup percent (e.g. 50 = 50%) → retail USD per network USD-micro. */\nexport function markupPercentToRetailRateUsd(markupPercent: number): string {\n const pct = Number.isFinite(markupPercent) ? Math.max(0, markupPercent) : 0;\n return formatRetailRateUsd(NETWORK_USD_PER_MICRO * (1 + pct / 100));\n}\n\n/** Retail USD per micro → markup percent string for UI (one decimal). */\nexport function retailRateUsdToMarkupPercent(raw: string | null | undefined): string {\n const rate = parseRetailRateUsd(raw);\n if (!rate) {\n return \"\";\n }\n const n = Number(rate);\n if (!Number.isFinite(n) || n <= NETWORK_USD_PER_MICRO) {\n return n === NETWORK_USD_PER_MICRO ? \"0\" : \"\";\n }\n const pct = (n / NETWORK_USD_PER_MICRO - 1) * 100;\n if (!Number.isFinite(pct) || pct <= 0) {\n return \"\";\n }\n return pct % 1 === 0 ? String(Math.round(pct)) : pct.toFixed(1);\n}\n\nexport function retailRateUsdPerMillion(raw: string | null | undefined): string {\n const rate = parseRetailRateUsd(raw);\n if (!rate) {\n return \"\";\n }\n const perM = Number(rate) * 1_000_000;\n if (!Number.isFinite(perM)) {\n return \"\";\n }\n return perM.toFixed(2);\n}\n\nexport function parseMarkupPercentInput(raw: string): number | null {\n const trimmed = raw.trim();\n if (!trimmed) {\n return null;\n }\n const n = Number(trimmed);\n if (!Number.isFinite(n) || n < 0) {\n return null;\n }\n return n;\n}\n\n/** Apply retail rate (USD per network micro) to network fee micros. */\nexport function applyRetailRateToNetworkMicros(\n networkFeeUsdMicros: bigint,\n retailRateUsd: string,\n): bigint {\n const networkPerMicro = NETWORK_USD_PER_MICRO;\n const retail = Number(retailRateUsd);\n if (!Number.isFinite(retail) || retail <= 0) {\n return networkFeeUsdMicros;\n }\n const ratio = retail / networkPerMicro;\n if (!Number.isFinite(ratio) || ratio <= 0) {\n return networkFeeUsdMicros;\n }\n return (networkFeeUsdMicros * BigInt(Math.round(ratio * 1_000_000))) / 1_000_000n;\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Network cost pass-through: $1 retail per $1M of network USD-micros metered. */
|
|
2
|
+
declare const NETWORK_USD_PER_MICRO = 0.000001;
|
|
3
|
+
declare function defaultRetailRateUsd(): string;
|
|
4
|
+
declare function formatRetailRateUsd(value: number): string;
|
|
5
|
+
declare function parseRetailRateUsd(raw: string | null | undefined): string | null;
|
|
6
|
+
/** Markup percent (e.g. 50 = 50%) → retail USD per network USD-micro. */
|
|
7
|
+
declare function markupPercentToRetailRateUsd(markupPercent: number): string;
|
|
8
|
+
/** Retail USD per micro → markup percent string for UI (one decimal). */
|
|
9
|
+
declare function retailRateUsdToMarkupPercent(raw: string | null | undefined): string;
|
|
10
|
+
declare function retailRateUsdPerMillion(raw: string | null | undefined): string;
|
|
11
|
+
declare function parseMarkupPercentInput(raw: string): number | null;
|
|
12
|
+
/** Apply retail rate (USD per network micro) to network fee micros. */
|
|
13
|
+
declare function applyRetailRateToNetworkMicros(networkFeeUsdMicros: bigint, retailRateUsd: string): bigint;
|
|
14
|
+
|
|
15
|
+
export { NETWORK_USD_PER_MICRO, applyRetailRateToNetworkMicros, defaultRetailRateUsd, formatRetailRateUsd, markupPercentToRetailRateUsd, parseMarkupPercentInput, parseRetailRateUsd, retailRateUsdPerMillion, retailRateUsdToMarkupPercent };
|