@orangecheck/me-client 0.9.0 → 0.11.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/index.d.mts +60 -1
- package/dist/index.d.ts +60 -1
- package/dist/index.js +73 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
|
|
4
|
+
type Scope = 'bitcoin_address' | 'email' | 'attest_tier' | 'display_name';
|
|
5
|
+
interface GrantedOptions {
|
|
6
|
+
project_key: string;
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
}
|
|
9
|
+
interface GrantedResult {
|
|
10
|
+
sub: string;
|
|
11
|
+
scopes_granted: Scope[];
|
|
12
|
+
scopes: Partial<Record<Scope, string>>;
|
|
13
|
+
}
|
|
14
|
+
declare function granted(options: GrantedOptions): Promise<GrantedResult>;
|
|
15
|
+
interface RequestOptions {
|
|
16
|
+
project_key: string;
|
|
17
|
+
return_to: string;
|
|
18
|
+
origin?: string;
|
|
19
|
+
}
|
|
20
|
+
declare function request(scopes: Scope[], options: RequestOptions): never;
|
|
21
|
+
declare const scope: {
|
|
22
|
+
granted: typeof granted;
|
|
23
|
+
request: typeof request;
|
|
24
|
+
};
|
|
25
|
+
|
|
4
26
|
interface VerifyResult {
|
|
5
27
|
ok: boolean;
|
|
6
28
|
reason?: string;
|
|
@@ -152,6 +174,37 @@ interface FireEventOptions {
|
|
|
152
174
|
metadata?: Record<string, unknown>;
|
|
153
175
|
}
|
|
154
176
|
declare function fire(options: FireEventOptions): Promise<BillableEvent>;
|
|
177
|
+
interface BatchEventInput {
|
|
178
|
+
subtype: EventSubtype;
|
|
179
|
+
payment_amount_sats?: number;
|
|
180
|
+
action_label?: string;
|
|
181
|
+
note?: string;
|
|
182
|
+
idempotency_key?: string;
|
|
183
|
+
}
|
|
184
|
+
type BatchEventResult = {
|
|
185
|
+
index: number;
|
|
186
|
+
status: 'recorded';
|
|
187
|
+
event: BillableEvent;
|
|
188
|
+
} | {
|
|
189
|
+
index: number;
|
|
190
|
+
status: 'duplicate';
|
|
191
|
+
event: BillableEvent;
|
|
192
|
+
} | {
|
|
193
|
+
index: number;
|
|
194
|
+
status: 'rejected';
|
|
195
|
+
reason: string;
|
|
196
|
+
};
|
|
197
|
+
interface FireBatchOptions {
|
|
198
|
+
project_key: string;
|
|
199
|
+
events: BatchEventInput[];
|
|
200
|
+
}
|
|
201
|
+
interface FireBatchResponse {
|
|
202
|
+
ok: boolean;
|
|
203
|
+
results: BatchEventResult[];
|
|
204
|
+
escrow_mode: 'simulation' | 'live';
|
|
205
|
+
simulation_mode_note?: string;
|
|
206
|
+
}
|
|
207
|
+
declare function fireBatch(options: FireBatchOptions): Promise<FireBatchResponse>;
|
|
155
208
|
interface VerifyEventResult {
|
|
156
209
|
ok: boolean;
|
|
157
210
|
issues: Array<{
|
|
@@ -170,6 +223,7 @@ interface VerifyEventResult {
|
|
|
170
223
|
declare function verify(envelope: BillableEvent, config: IntegratorPriceConfig, payment_amount_sats?: number): VerifyEventResult;
|
|
171
224
|
declare const event: {
|
|
172
225
|
fire: typeof fire;
|
|
226
|
+
fireBatch: typeof fireBatch;
|
|
173
227
|
verify: typeof verify;
|
|
174
228
|
};
|
|
175
229
|
|
|
@@ -235,6 +289,7 @@ declare const oc: {
|
|
|
235
289
|
};
|
|
236
290
|
event: {
|
|
237
291
|
fire: (options: FireEventOptions) => Promise<BillableEvent>;
|
|
292
|
+
fireBatch: (options: FireBatchOptions) => Promise<FireBatchResponse>;
|
|
238
293
|
verify: (envelope: BillableEvent, config: IntegratorPriceConfig, payment_amount_sats?: number) => VerifyEventResult;
|
|
239
294
|
};
|
|
240
295
|
config: {
|
|
@@ -250,6 +305,10 @@ declare const oc: {
|
|
|
250
305
|
get: (slug: string) => Promise<Federation | null>;
|
|
251
306
|
defaultLive: () => Promise<Federation | null>;
|
|
252
307
|
};
|
|
308
|
+
scope: {
|
|
309
|
+
granted: (options: GrantedOptions) => Promise<GrantedResult>;
|
|
310
|
+
request: typeof request;
|
|
311
|
+
};
|
|
253
312
|
};
|
|
254
313
|
|
|
255
|
-
export { type AttestTier, type BillableEvent, type ClassASubtype, type ClassBSubtype, type ClassCSubtype, type ComputedFees, type EventClass, type EventSubtype, type Federation, type FederationStatus, type FireEventOptions, type IntegratorEventConfig, type IntegratorPriceConfig, MIN_INTEGRATOR_PRICE_SATS, MeClientError, type OcPublicJwk, OcSignInButton, type OcSignInButtonProps, PLATFORM_FEE_POLICY, type PaymentAuthorizeOptions, type PaymentResult, 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, session, setBearerToken, setOrigin, validateIntegratorConfig, webhook };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
|
|
4
|
+
type Scope = 'bitcoin_address' | 'email' | 'attest_tier' | 'display_name';
|
|
5
|
+
interface GrantedOptions {
|
|
6
|
+
project_key: string;
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
}
|
|
9
|
+
interface GrantedResult {
|
|
10
|
+
sub: string;
|
|
11
|
+
scopes_granted: Scope[];
|
|
12
|
+
scopes: Partial<Record<Scope, string>>;
|
|
13
|
+
}
|
|
14
|
+
declare function granted(options: GrantedOptions): Promise<GrantedResult>;
|
|
15
|
+
interface RequestOptions {
|
|
16
|
+
project_key: string;
|
|
17
|
+
return_to: string;
|
|
18
|
+
origin?: string;
|
|
19
|
+
}
|
|
20
|
+
declare function request(scopes: Scope[], options: RequestOptions): never;
|
|
21
|
+
declare const scope: {
|
|
22
|
+
granted: typeof granted;
|
|
23
|
+
request: typeof request;
|
|
24
|
+
};
|
|
25
|
+
|
|
4
26
|
interface VerifyResult {
|
|
5
27
|
ok: boolean;
|
|
6
28
|
reason?: string;
|
|
@@ -152,6 +174,37 @@ interface FireEventOptions {
|
|
|
152
174
|
metadata?: Record<string, unknown>;
|
|
153
175
|
}
|
|
154
176
|
declare function fire(options: FireEventOptions): Promise<BillableEvent>;
|
|
177
|
+
interface BatchEventInput {
|
|
178
|
+
subtype: EventSubtype;
|
|
179
|
+
payment_amount_sats?: number;
|
|
180
|
+
action_label?: string;
|
|
181
|
+
note?: string;
|
|
182
|
+
idempotency_key?: string;
|
|
183
|
+
}
|
|
184
|
+
type BatchEventResult = {
|
|
185
|
+
index: number;
|
|
186
|
+
status: 'recorded';
|
|
187
|
+
event: BillableEvent;
|
|
188
|
+
} | {
|
|
189
|
+
index: number;
|
|
190
|
+
status: 'duplicate';
|
|
191
|
+
event: BillableEvent;
|
|
192
|
+
} | {
|
|
193
|
+
index: number;
|
|
194
|
+
status: 'rejected';
|
|
195
|
+
reason: string;
|
|
196
|
+
};
|
|
197
|
+
interface FireBatchOptions {
|
|
198
|
+
project_key: string;
|
|
199
|
+
events: BatchEventInput[];
|
|
200
|
+
}
|
|
201
|
+
interface FireBatchResponse {
|
|
202
|
+
ok: boolean;
|
|
203
|
+
results: BatchEventResult[];
|
|
204
|
+
escrow_mode: 'simulation' | 'live';
|
|
205
|
+
simulation_mode_note?: string;
|
|
206
|
+
}
|
|
207
|
+
declare function fireBatch(options: FireBatchOptions): Promise<FireBatchResponse>;
|
|
155
208
|
interface VerifyEventResult {
|
|
156
209
|
ok: boolean;
|
|
157
210
|
issues: Array<{
|
|
@@ -170,6 +223,7 @@ interface VerifyEventResult {
|
|
|
170
223
|
declare function verify(envelope: BillableEvent, config: IntegratorPriceConfig, payment_amount_sats?: number): VerifyEventResult;
|
|
171
224
|
declare const event: {
|
|
172
225
|
fire: typeof fire;
|
|
226
|
+
fireBatch: typeof fireBatch;
|
|
173
227
|
verify: typeof verify;
|
|
174
228
|
};
|
|
175
229
|
|
|
@@ -235,6 +289,7 @@ declare const oc: {
|
|
|
235
289
|
};
|
|
236
290
|
event: {
|
|
237
291
|
fire: (options: FireEventOptions) => Promise<BillableEvent>;
|
|
292
|
+
fireBatch: (options: FireBatchOptions) => Promise<FireBatchResponse>;
|
|
238
293
|
verify: (envelope: BillableEvent, config: IntegratorPriceConfig, payment_amount_sats?: number) => VerifyEventResult;
|
|
239
294
|
};
|
|
240
295
|
config: {
|
|
@@ -250,6 +305,10 @@ declare const oc: {
|
|
|
250
305
|
get: (slug: string) => Promise<Federation | null>;
|
|
251
306
|
defaultLive: () => Promise<Federation | null>;
|
|
252
307
|
};
|
|
308
|
+
scope: {
|
|
309
|
+
granted: (options: GrantedOptions) => Promise<GrantedResult>;
|
|
310
|
+
request: typeof request;
|
|
311
|
+
};
|
|
253
312
|
};
|
|
254
313
|
|
|
255
|
-
export { type AttestTier, type BillableEvent, type ClassASubtype, type ClassBSubtype, type ClassCSubtype, type ComputedFees, type EventClass, type EventSubtype, type Federation, type FederationStatus, type FireEventOptions, type IntegratorEventConfig, type IntegratorPriceConfig, MIN_INTEGRATOR_PRICE_SATS, MeClientError, type OcPublicJwk, OcSignInButton, type OcSignInButtonProps, PLATFORM_FEE_POLICY, type PaymentAuthorizeOptions, type PaymentResult, 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, session, setBearerToken, setOrigin, validateIntegratorConfig, webhook };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -131,7 +131,7 @@ async function invalidate(sessionId) {
|
|
|
131
131
|
}
|
|
132
132
|
var session = { create, refresh, invalidate };
|
|
133
133
|
function OcSignInButton({
|
|
134
|
-
scope,
|
|
134
|
+
scope: scope2,
|
|
135
135
|
sessionPolicy,
|
|
136
136
|
returnTo,
|
|
137
137
|
onSignin,
|
|
@@ -152,7 +152,7 @@ function OcSignInButton({
|
|
|
152
152
|
if (event2.defaultPrevented) return;
|
|
153
153
|
setPending(true);
|
|
154
154
|
try {
|
|
155
|
-
const result = await session.create({ scope, sessionPolicy, returnTo });
|
|
155
|
+
const result = await session.create({ scope: scope2, sessionPolicy, returnTo });
|
|
156
156
|
onSignin?.(result);
|
|
157
157
|
} catch (err) {
|
|
158
158
|
onSignInError?.(err instanceof Error ? err : new Error(String(err)));
|
|
@@ -294,6 +294,23 @@ async function fire(options) {
|
|
|
294
294
|
body: options
|
|
295
295
|
});
|
|
296
296
|
}
|
|
297
|
+
async function fireBatch(options) {
|
|
298
|
+
if (!options.project_key) {
|
|
299
|
+
throw new Error("event.fireBatch requires project_key");
|
|
300
|
+
}
|
|
301
|
+
if (!Array.isArray(options.events) || options.events.length === 0) {
|
|
302
|
+
throw new Error("event.fireBatch requires at least one event");
|
|
303
|
+
}
|
|
304
|
+
if (options.events.length > 100) {
|
|
305
|
+
throw new Error(
|
|
306
|
+
`event.fireBatch \xB7 max 100 events per call (got ${options.events.length}). Split client-side.`
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
return api("/api/integrator/event/batch", {
|
|
310
|
+
method: "POST",
|
|
311
|
+
body: options
|
|
312
|
+
});
|
|
313
|
+
}
|
|
297
314
|
function verify(envelope, config2, payment_amount_sats) {
|
|
298
315
|
const issues = [];
|
|
299
316
|
const eventCfg = config2.events[envelope.subtype];
|
|
@@ -378,7 +395,7 @@ function verify(envelope, config2, payment_amount_sats) {
|
|
|
378
395
|
issues
|
|
379
396
|
};
|
|
380
397
|
}
|
|
381
|
-
var event = { fire, verify };
|
|
398
|
+
var event = { fire, fireBatch, verify };
|
|
382
399
|
|
|
383
400
|
// src/config.ts
|
|
384
401
|
function validate(cfg) {
|
|
@@ -744,8 +761,59 @@ async function defaultLive() {
|
|
|
744
761
|
}
|
|
745
762
|
var federations = { list, live, get, defaultLive };
|
|
746
763
|
|
|
764
|
+
// src/scope.ts
|
|
765
|
+
var VALID_SCOPES = [
|
|
766
|
+
"bitcoin_address",
|
|
767
|
+
"email",
|
|
768
|
+
"attest_tier",
|
|
769
|
+
"display_name"
|
|
770
|
+
];
|
|
771
|
+
async function granted(options) {
|
|
772
|
+
if (!options.project_key) {
|
|
773
|
+
throw new Error("oc.scope.granted: project_key is required");
|
|
774
|
+
}
|
|
775
|
+
const r = await api(
|
|
776
|
+
`/api/integrator/scopes/${encodeURIComponent(options.project_key)}`,
|
|
777
|
+
{ method: "GET", signal: options.signal }
|
|
778
|
+
);
|
|
779
|
+
return {
|
|
780
|
+
sub: r.sub,
|
|
781
|
+
scopes_granted: r.scopes_granted,
|
|
782
|
+
scopes: r.scopes
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
function request(scopes, options) {
|
|
786
|
+
if (!options.project_key) {
|
|
787
|
+
throw new Error("oc.scope.request: project_key is required");
|
|
788
|
+
}
|
|
789
|
+
if (!options.return_to) {
|
|
790
|
+
throw new Error("oc.scope.request: return_to is required");
|
|
791
|
+
}
|
|
792
|
+
if (!Array.isArray(scopes) || scopes.length === 0) {
|
|
793
|
+
throw new Error("oc.scope.request: scopes must be a non-empty array");
|
|
794
|
+
}
|
|
795
|
+
for (const s of scopes) {
|
|
796
|
+
if (!VALID_SCOPES.includes(s)) {
|
|
797
|
+
throw new Error(
|
|
798
|
+
`oc.scope.request: unknown scope "${s}" \xB7 valid: ${VALID_SCOPES.join(", ")}`
|
|
799
|
+
);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
if (typeof window === "undefined") {
|
|
803
|
+
throw new Error("oc.scope.request: must be called in a browser environment");
|
|
804
|
+
}
|
|
805
|
+
const origin2 = options.origin ?? getOrigin();
|
|
806
|
+
const url = new URL("/me/scope-grant", origin2);
|
|
807
|
+
url.searchParams.set("project_key", options.project_key);
|
|
808
|
+
url.searchParams.set("scopes", scopes.join(","));
|
|
809
|
+
url.searchParams.set("return_to", options.return_to);
|
|
810
|
+
window.location.assign(url.toString());
|
|
811
|
+
throw new Error("oc.scope.request: redirected to consent prompt");
|
|
812
|
+
}
|
|
813
|
+
var scope = { granted, request };
|
|
814
|
+
|
|
747
815
|
// src/index.ts
|
|
748
|
-
var oc = { session, payment, event, config, webhook, federations };
|
|
816
|
+
var oc = { session, payment, event, config, webhook, federations, scope };
|
|
749
817
|
|
|
750
818
|
exports.MIN_INTEGRATOR_PRICE_SATS = MIN_INTEGRATOR_PRICE_SATS;
|
|
751
819
|
exports.MeClientError = MeClientError;
|
|
@@ -761,6 +829,7 @@ exports.getOrigin = getOrigin;
|
|
|
761
829
|
exports.oc = oc;
|
|
762
830
|
exports.onTelemetry = onTelemetry;
|
|
763
831
|
exports.payment = payment;
|
|
832
|
+
exports.scope = scope;
|
|
764
833
|
exports.session = session;
|
|
765
834
|
exports.setBearerToken = setBearerToken;
|
|
766
835
|
exports.setOrigin = setOrigin;
|