@orangecheck/me-client 0.11.0 → 0.13.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 +4 -0
- package/dist/index.d.mts +16 -2
- package/dist/index.d.ts +16 -2
- package/dist/index.js +51 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# @orangecheck/me-client
|
|
2
2
|
|
|
3
|
+
> **Full reference:** [docs.ochk.io/sdk/me-client](https://docs.ochk.io/sdk/me-client) — auto-generated from the TypeScript source on every release.
|
|
4
|
+
> Hand-written prose below is the high-level overview; the docs site is the source of truth for every export, type, and signature.
|
|
5
|
+
|
|
6
|
+
|
|
3
7
|
Drop-in client for [me.ochk.io](https://me.ochk.io). Sign-in-with-OC button, popup signin orchestrator, framework-agnostic server-side verification, session lifecycle hooks, payment authorization, webhook signature verification, the canonical billable-event taxonomy as TypeScript types.
|
|
4
8
|
|
|
5
9
|
> You pay for sessions and actions, not for clicks.
|
package/dist/index.d.mts
CHANGED
|
@@ -172,6 +172,7 @@ interface FireEventOptions {
|
|
|
172
172
|
payment_amount_sats?: number;
|
|
173
173
|
user_address?: string;
|
|
174
174
|
metadata?: Record<string, unknown>;
|
|
175
|
+
is_agent?: boolean;
|
|
175
176
|
}
|
|
176
177
|
declare function fire(options: FireEventOptions): Promise<BillableEvent>;
|
|
177
178
|
interface BatchEventInput {
|
|
@@ -180,6 +181,7 @@ interface BatchEventInput {
|
|
|
180
181
|
action_label?: string;
|
|
181
182
|
note?: string;
|
|
182
183
|
idempotency_key?: string;
|
|
184
|
+
is_agent?: boolean;
|
|
183
185
|
}
|
|
184
186
|
type BatchEventResult = {
|
|
185
187
|
index: number;
|
|
@@ -275,8 +277,20 @@ declare function getBearerToken(): string | null;
|
|
|
275
277
|
declare function clearBearerToken(): void;
|
|
276
278
|
declare class MeClientError extends Error {
|
|
277
279
|
readonly status: number;
|
|
278
|
-
|
|
280
|
+
readonly errorCode: string | undefined;
|
|
281
|
+
readonly retryAfterSeconds: number | undefined;
|
|
282
|
+
constructor(message: string, status: number, opts?: {
|
|
283
|
+
errorCode?: string;
|
|
284
|
+
retryAfterSeconds?: number;
|
|
285
|
+
});
|
|
286
|
+
get isRateLimited(): boolean;
|
|
279
287
|
}
|
|
288
|
+
interface WithRateLimitRetryOptions {
|
|
289
|
+
maxRetries?: number;
|
|
290
|
+
maxRetryAfterSeconds?: number;
|
|
291
|
+
baseBackoffMs?: number;
|
|
292
|
+
}
|
|
293
|
+
declare function withRateLimitRetry<T>(fn: () => Promise<T>, opts?: WithRateLimitRetryOptions): Promise<T>;
|
|
280
294
|
|
|
281
295
|
declare const oc: {
|
|
282
296
|
session: {
|
|
@@ -311,4 +325,4 @@ declare const oc: {
|
|
|
311
325
|
};
|
|
312
326
|
};
|
|
313
327
|
|
|
314
|
-
export { type AttestTier, type BillableEvent, type ClassASubtype, type ClassBSubtype, type ClassCSubtype, type ComputedFees, type EventClass, type EventSubtype, type Federation, type FederationStatus, type FireEventOptions, type GrantedOptions, type GrantedResult, type IntegratorEventConfig, type IntegratorPriceConfig, MIN_INTEGRATOR_PRICE_SATS, MeClientError, type OcPublicJwk, OcSignInButton, type OcSignInButtonProps, PLATFORM_FEE_POLICY, type PaymentAuthorizeOptions, type PaymentResult, type RequestOptions, type Scope, type Session, type SessionPolicy, type SignInOptions, type SigningMethod, type SiteFeeShape, type TelemetryEvent, type ValidationResult, type VerifyEventResult, type VerifyOptions, type VerifyResult, clearBearerToken, computeFees, config, event, federations, getBearerToken, getOrigin, oc, onTelemetry, payment, scope, session, setBearerToken, setOrigin, validateIntegratorConfig, webhook };
|
|
328
|
+
export { type AttestTier, type BillableEvent, type ClassASubtype, type ClassBSubtype, type ClassCSubtype, type ComputedFees, type EventClass, type EventSubtype, type Federation, type FederationStatus, type FireEventOptions, type GrantedOptions, type GrantedResult, type IntegratorEventConfig, type IntegratorPriceConfig, MIN_INTEGRATOR_PRICE_SATS, MeClientError, type OcPublicJwk, OcSignInButton, type OcSignInButtonProps, PLATFORM_FEE_POLICY, type PaymentAuthorizeOptions, type PaymentResult, type RequestOptions, type Scope, type Session, type SessionPolicy, type SignInOptions, type SigningMethod, type SiteFeeShape, type TelemetryEvent, type ValidationResult, type VerifyEventResult, type VerifyOptions, type VerifyResult, type WithRateLimitRetryOptions, clearBearerToken, computeFees, config, event, federations, getBearerToken, getOrigin, oc, onTelemetry, payment, scope, session, setBearerToken, setOrigin, validateIntegratorConfig, webhook, withRateLimitRetry };
|
package/dist/index.d.ts
CHANGED
|
@@ -172,6 +172,7 @@ interface FireEventOptions {
|
|
|
172
172
|
payment_amount_sats?: number;
|
|
173
173
|
user_address?: string;
|
|
174
174
|
metadata?: Record<string, unknown>;
|
|
175
|
+
is_agent?: boolean;
|
|
175
176
|
}
|
|
176
177
|
declare function fire(options: FireEventOptions): Promise<BillableEvent>;
|
|
177
178
|
interface BatchEventInput {
|
|
@@ -180,6 +181,7 @@ interface BatchEventInput {
|
|
|
180
181
|
action_label?: string;
|
|
181
182
|
note?: string;
|
|
182
183
|
idempotency_key?: string;
|
|
184
|
+
is_agent?: boolean;
|
|
183
185
|
}
|
|
184
186
|
type BatchEventResult = {
|
|
185
187
|
index: number;
|
|
@@ -275,8 +277,20 @@ declare function getBearerToken(): string | null;
|
|
|
275
277
|
declare function clearBearerToken(): void;
|
|
276
278
|
declare class MeClientError extends Error {
|
|
277
279
|
readonly status: number;
|
|
278
|
-
|
|
280
|
+
readonly errorCode: string | undefined;
|
|
281
|
+
readonly retryAfterSeconds: number | undefined;
|
|
282
|
+
constructor(message: string, status: number, opts?: {
|
|
283
|
+
errorCode?: string;
|
|
284
|
+
retryAfterSeconds?: number;
|
|
285
|
+
});
|
|
286
|
+
get isRateLimited(): boolean;
|
|
279
287
|
}
|
|
288
|
+
interface WithRateLimitRetryOptions {
|
|
289
|
+
maxRetries?: number;
|
|
290
|
+
maxRetryAfterSeconds?: number;
|
|
291
|
+
baseBackoffMs?: number;
|
|
292
|
+
}
|
|
293
|
+
declare function withRateLimitRetry<T>(fn: () => Promise<T>, opts?: WithRateLimitRetryOptions): Promise<T>;
|
|
280
294
|
|
|
281
295
|
declare const oc: {
|
|
282
296
|
session: {
|
|
@@ -311,4 +325,4 @@ declare const oc: {
|
|
|
311
325
|
};
|
|
312
326
|
};
|
|
313
327
|
|
|
314
|
-
export { type AttestTier, type BillableEvent, type ClassASubtype, type ClassBSubtype, type ClassCSubtype, type ComputedFees, type EventClass, type EventSubtype, type Federation, type FederationStatus, type FireEventOptions, type GrantedOptions, type GrantedResult, type IntegratorEventConfig, type IntegratorPriceConfig, MIN_INTEGRATOR_PRICE_SATS, MeClientError, type OcPublicJwk, OcSignInButton, type OcSignInButtonProps, PLATFORM_FEE_POLICY, type PaymentAuthorizeOptions, type PaymentResult, type RequestOptions, type Scope, type Session, type SessionPolicy, type SignInOptions, type SigningMethod, type SiteFeeShape, type TelemetryEvent, type ValidationResult, type VerifyEventResult, type VerifyOptions, type VerifyResult, clearBearerToken, computeFees, config, event, federations, getBearerToken, getOrigin, oc, onTelemetry, payment, scope, session, setBearerToken, setOrigin, validateIntegratorConfig, webhook };
|
|
328
|
+
export { type AttestTier, type BillableEvent, type ClassASubtype, type ClassBSubtype, type ClassCSubtype, type ComputedFees, type EventClass, type EventSubtype, type Federation, type FederationStatus, type FireEventOptions, type GrantedOptions, type GrantedResult, type IntegratorEventConfig, type IntegratorPriceConfig, MIN_INTEGRATOR_PRICE_SATS, MeClientError, type OcPublicJwk, OcSignInButton, type OcSignInButtonProps, PLATFORM_FEE_POLICY, type PaymentAuthorizeOptions, type PaymentResult, type RequestOptions, type Scope, type Session, type SessionPolicy, type SignInOptions, type SigningMethod, type SiteFeeShape, type TelemetryEvent, type ValidationResult, type VerifyEventResult, type VerifyOptions, type VerifyResult, type WithRateLimitRetryOptions, clearBearerToken, computeFees, config, event, federations, getBearerToken, getOrigin, oc, onTelemetry, payment, scope, session, setBearerToken, setOrigin, validateIntegratorConfig, webhook, withRateLimitRetry };
|
package/dist/index.js
CHANGED
|
@@ -60,22 +60,69 @@ async function api(path, opts = {}) {
|
|
|
60
60
|
});
|
|
61
61
|
if (!res.ok) {
|
|
62
62
|
let message = `me.ochk.io ${res.status}`;
|
|
63
|
+
let errorCode;
|
|
64
|
+
let body;
|
|
63
65
|
try {
|
|
64
66
|
const data = await res.json();
|
|
65
|
-
|
|
67
|
+
body = data;
|
|
68
|
+
if (data?.error) {
|
|
69
|
+
errorCode = data.error;
|
|
70
|
+
message = data.reason ?? data.error;
|
|
71
|
+
}
|
|
66
72
|
} catch {
|
|
67
73
|
}
|
|
68
|
-
|
|
74
|
+
let retryAfterSeconds;
|
|
75
|
+
if (res.status === 429) {
|
|
76
|
+
const headerValue = res.headers.get("retry-after");
|
|
77
|
+
if (headerValue) {
|
|
78
|
+
const parsed = Number.parseInt(headerValue, 10);
|
|
79
|
+
if (Number.isFinite(parsed) && parsed >= 0) retryAfterSeconds = parsed;
|
|
80
|
+
}
|
|
81
|
+
if (retryAfterSeconds == null && typeof body?.retry_after_seconds === "number") {
|
|
82
|
+
retryAfterSeconds = body.retry_after_seconds;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
throw new MeClientError(message, res.status, { errorCode, retryAfterSeconds });
|
|
69
86
|
}
|
|
70
87
|
return await res.json();
|
|
71
88
|
}
|
|
72
89
|
var MeClientError = class extends Error {
|
|
73
|
-
constructor(message, status) {
|
|
90
|
+
constructor(message, status, opts) {
|
|
74
91
|
super(message);
|
|
75
92
|
this.name = "MeClientError";
|
|
76
93
|
this.status = status;
|
|
94
|
+
this.errorCode = opts?.errorCode;
|
|
95
|
+
this.retryAfterSeconds = opts?.retryAfterSeconds;
|
|
96
|
+
}
|
|
97
|
+
/** True for the 429 surface · convenience boolean so callers don't
|
|
98
|
+
* have to compare status === 429 every time. */
|
|
99
|
+
get isRateLimited() {
|
|
100
|
+
return this.status === 429;
|
|
77
101
|
}
|
|
78
102
|
};
|
|
103
|
+
async function withRateLimitRetry(fn, opts = {}) {
|
|
104
|
+
const maxRetries = opts.maxRetries ?? 2;
|
|
105
|
+
const maxRetryAfter = opts.maxRetryAfterSeconds ?? 30;
|
|
106
|
+
const baseBackoff = opts.baseBackoffMs ?? 250;
|
|
107
|
+
let attempt = 0;
|
|
108
|
+
while (true) {
|
|
109
|
+
try {
|
|
110
|
+
return await fn();
|
|
111
|
+
} catch (err) {
|
|
112
|
+
if (!(err instanceof MeClientError) || !err.isRateLimited) throw err;
|
|
113
|
+
if (attempt >= maxRetries) throw err;
|
|
114
|
+
let waitMs;
|
|
115
|
+
if (err.retryAfterSeconds != null) {
|
|
116
|
+
if (err.retryAfterSeconds > maxRetryAfter) throw err;
|
|
117
|
+
waitMs = err.retryAfterSeconds * 1e3;
|
|
118
|
+
} else {
|
|
119
|
+
waitMs = baseBackoff * 2 ** attempt;
|
|
120
|
+
}
|
|
121
|
+
await new Promise((resolve) => setTimeout(resolve, waitMs));
|
|
122
|
+
attempt++;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
79
126
|
|
|
80
127
|
// src/session.ts
|
|
81
128
|
var DEFAULT_POLICY = {
|
|
@@ -835,5 +882,6 @@ exports.setBearerToken = setBearerToken;
|
|
|
835
882
|
exports.setOrigin = setOrigin;
|
|
836
883
|
exports.validateIntegratorConfig = validateIntegratorConfig;
|
|
837
884
|
exports.webhook = webhook;
|
|
885
|
+
exports.withRateLimitRetry = withRateLimitRetry;
|
|
838
886
|
//# sourceMappingURL=index.js.map
|
|
839
887
|
//# sourceMappingURL=index.js.map
|