@orangecheck/me-client 0.56.0 → 0.58.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/CHANGELOG.md +77 -4
- package/README.md +13 -9
- package/dist/index.d.mts +5 -33
- package/dist/index.d.ts +5 -33
- package/dist/index.js +38 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -12
- package/dist/index.mjs.map +1 -1
- package/dist/{integrator-DDeHg7vj.d.mts → integrator-fTchEeNJ.d.mts} +39 -5
- package/dist/{integrator-DDeHg7vj.d.ts → integrator-fTchEeNJ.d.ts} +39 -5
- package/dist/integrator.d.mts +1 -1
- package/dist/integrator.d.ts +1 -1
- package/dist/integrator.js.map +1 -1
- package/dist/integrator.mjs.map +1 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +13 -4
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +13 -4
- package/dist/server.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,83 @@ and [Semantic Versioning](https://semver.org/). Wire-format / canonical-message
|
|
|
8
8
|
changes are coordinated via the relevant `oc-*-protocol` spec repo's CHANGELOG;
|
|
9
9
|
this file tracks the package's TS / Node / runtime API surface.
|
|
10
10
|
|
|
11
|
+
## [Unreleased]
|
|
12
|
+
|
|
13
|
+
## [0.58.0] — 2026-11-09
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- `bearerToken` on `oc.payment.authorize`, for that call only, as on
|
|
18
|
+
`oc.event.fire`. `setBearerToken` holds one token for the whole process, so a
|
|
19
|
+
server serving many people passes each person's token per call instead. It
|
|
20
|
+
is sent as Authorization and never in the body. `setBearerToken` still works.
|
|
21
|
+
- The five scopes me.ochk.io already knows and `oc.scope.request` refused:
|
|
22
|
+
`cross_integrator_lifetime_sats`, `cross_integrator_distinct_count`,
|
|
23
|
+
`cross_integrator_oldest_event_at`, `cross_integrator_active_days` and
|
|
24
|
+
`trust_attestations_bundle`. `Scope` has all twelve, and `SCOPE_IDS` exports
|
|
25
|
+
them, frozen, in the order me.ochk.io lists them; a me.ochk.io test fails when
|
|
26
|
+
the two lists differ.
|
|
27
|
+
|
|
28
|
+
### Deprecated
|
|
29
|
+
|
|
30
|
+
- The `attest_tier` scope, as me.ochk.io already marks it. ochk.app no longer
|
|
31
|
+
asks for it, so a request for it asks the person nothing; a backed account
|
|
32
|
+
tells your site what backs it at sign-in. Old grants still resolve. The
|
|
33
|
+
`oc.scope` example asks for `email` and `bitcoin_address` instead.
|
|
34
|
+
|
|
35
|
+
### Changed
|
|
36
|
+
|
|
37
|
+
- `WebhookPayload.scopes` is keyed by `Scope`, so it names the four cross-app
|
|
38
|
+
scopes a delivery can carry beside the ones it already listed.
|
|
39
|
+
|
|
40
|
+
## [0.57.0] — 2026-11-09
|
|
41
|
+
|
|
42
|
+
### Deprecated
|
|
43
|
+
|
|
44
|
+
- The `display_name` scope. Signing in already gives your site the person's
|
|
45
|
+
display name, so ochk.app no longer offers the scope and me.ochk.io resolves
|
|
46
|
+
it to nothing. `oc.scope.request` still accepts it, so nothing that asks for
|
|
47
|
+
it breaks; read the name from the sign-in instead.
|
|
48
|
+
|
|
49
|
+
### Changed
|
|
50
|
+
|
|
51
|
+
- With `OC_REVOCATION_FEED_TOKEN` unset, a family session (no `aud`) is now
|
|
52
|
+
`unavailable` with `reason: 'revocation_feed_unconfigured'`, and the adapters
|
|
53
|
+
answer it 503 with that reason, where `checkOcSession`, `getOcSession`,
|
|
54
|
+
`withOcAuth`, `ocAuthExpress` and `ocAuthHono` used to throw (0.44.0). It is
|
|
55
|
+
still never read by its signature alone, reads and writes alike, and the
|
|
56
|
+
first one logs which setting is missing. `OcSessionUnavailable` gains the
|
|
57
|
+
reason.
|
|
58
|
+
|
|
59
|
+
### Added
|
|
60
|
+
|
|
61
|
+
- A rejected entry in `event.fireBatch`'s results can carry `code`, a
|
|
62
|
+
`BatchRejectCode` to switch on, beside `reason` in words. me.ochk.io sends
|
|
63
|
+
one on every rejected entry now; an older server sends `reason` alone, so
|
|
64
|
+
`code` is optional.
|
|
65
|
+
|
|
66
|
+
### Fixed
|
|
67
|
+
|
|
68
|
+
- `oc.scope.granted` works for an integrator: call it from your backend with
|
|
69
|
+
`accountId` (the person's did:oc) and `signingSecret`, and it signs the
|
|
70
|
+
question the way me.ochk.io's scopes route checks it. With neither, it reads
|
|
71
|
+
the session the request carries, which only ochk.app's own pages have, so a
|
|
72
|
+
browser on your site gets 401. Either option without the other, or an
|
|
73
|
+
`accountId` that is not a did:oc, throws before any request.
|
|
74
|
+
- `Session` and `SessionPolicy` say what me.ochk.io sends and takes:
|
|
75
|
+
`issued_at` (the type said `opens_at`, which never arrived), `refresh`
|
|
76
|
+
`'sliding' | 'rolling' | 'fixed'` and `sensitive_actions` `'re-auth' |
|
|
77
|
+
'allow'`. Code that read `opens_at` read `undefined`; read `issued_at`.
|
|
78
|
+
`oc.session.*`'s doc and the README say these calls work only from
|
|
79
|
+
ochk.app's own pages.
|
|
80
|
+
- A refusal whose words are in `detail` now carries them as the
|
|
81
|
+
`MeClientError`'s `message`: the event routes' `project_auth_required` 401
|
|
82
|
+
and any route's `row_busy` 503. The message used to be the bare code.
|
|
83
|
+
`reason` still comes first, and the code is the fallback when the body has
|
|
84
|
+
no words.
|
|
85
|
+
- `family.scopes`' doc names its 401 by the code me.ochk.io sends,
|
|
86
|
+
`sign_in_required`, not the old words.
|
|
87
|
+
|
|
11
88
|
## [0.56.0] — 2026-10-27
|
|
12
89
|
|
|
13
90
|
### Changed
|
|
@@ -783,10 +860,6 @@ Two independent defects, either of which was fatal:
|
|
|
783
860
|
that project into their own ledger. The docstring is published as SDK
|
|
784
861
|
reference on docs.ochk.io, so a stale one is a false published claim.
|
|
785
862
|
|
|
786
|
-
## [Unreleased]
|
|
787
|
-
|
|
788
|
-
- _(no pending changes)_
|
|
789
|
-
|
|
790
863
|
## [0.38.3] — 2026-10-23
|
|
791
864
|
|
|
792
865
|
### Changed
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
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
5
|
|
|
6
6
|
|
|
7
|
-
Client for [
|
|
7
|
+
Client for [ochk.app](https://ochk.app), the orangecheck account (its API answers at me.ochk.io). Popup sign-in for any site, framework-agnostic server-side verification, session lifecycle hooks, payment authorization, webhook signature verification, the canonical billable-event taxonomy as TypeScript types. Sign people in with `signInWithOc()` from `/popup`. No React needed.
|
|
8
8
|
|
|
9
9
|
> Sign-in is free. Paying your users is optional: always, in promos you schedule, or never.
|
|
10
10
|
|
|
@@ -17,8 +17,9 @@ import { oc } from '@orangecheck/me-client';
|
|
|
17
17
|
// The React provider and hook live in the companion package.
|
|
18
18
|
import { OcSessionProvider, useOcSession } from '@orangecheck/auth-client';
|
|
19
19
|
|
|
20
|
-
// Server-side verification — Next.js, Express, Hono.
|
|
21
|
-
//
|
|
20
|
+
// Server-side verification — Next.js, Express, Hono. No JWK handling:
|
|
21
|
+
// SDK lazy-fetches and caches the JWKS. Set OC_PROJECT_KEY and
|
|
22
|
+
// OC_SIGNING_SECRET (see "Sessions ended everywhere").
|
|
22
23
|
import { withOcAuth, ocAuthExpress, ocAuthHono } from '@orangecheck/me-client/server';
|
|
23
24
|
|
|
24
25
|
// Browser-only popup orchestrator — same shape Google / GitHub use.
|
|
@@ -136,7 +137,9 @@ if (!res.earned) {
|
|
|
136
137
|
|
|
137
138
|
## Session lifecycle
|
|
138
139
|
|
|
139
|
-
Sessions are the billable atom
|
|
140
|
+
Sessions are the billable atom on ochk.app: your server fires one `session_creation` event per real session with `oc.event.fire`. `oc.session.create` opens a session and records no charge, and a signin within a still-valid session is **free**. Site declares the policy at integration time; the OC verifier enforces it both client-side and server-side.
|
|
141
|
+
|
|
142
|
+
`oc.session.create`, `refresh` and `invalidate` need a session me.ochk.io accepts, which only ochk.app's own pages carry; from another site they answer 401. Your own site reads its sign-in with `withOcAuth` (or `ocAuthExpress`, `ocAuthHono`) and keeps its own session.
|
|
140
143
|
|
|
141
144
|
```ts
|
|
142
145
|
import { oc } from '@orangecheck/me-client';
|
|
@@ -168,15 +171,16 @@ await oc.session.invalidate(session.id);
|
|
|
168
171
|
|
|
169
172
|
## Payment authorization
|
|
170
173
|
|
|
171
|
-
Class B billable event. Sub-Stripe rates (0.5–1.0% percentage-based). The
|
|
174
|
+
Class B billable event. Sub-Stripe rates (0.5–1.0% percentage-based). The person earns the share you set per event (`user_share_pct`, 0 to 0.8 of the gross fee; OC keeps 20%, and the default templates give 0.8), and it lands in their balance at ochk.app.
|
|
172
175
|
|
|
173
176
|
```ts
|
|
174
177
|
import { oc } from '@orangecheck/me-client';
|
|
175
178
|
|
|
176
179
|
const payment = await oc.payment.authorize({
|
|
177
|
-
identity: session.identity,
|
|
178
180
|
amount_sats: 240_000,
|
|
179
181
|
description: 'breez · march invoice',
|
|
182
|
+
// On a server, the person's oc_session token for this call only.
|
|
183
|
+
bearerToken: token,
|
|
180
184
|
});
|
|
181
185
|
```
|
|
182
186
|
|
|
@@ -275,13 +279,13 @@ app.get('/api/me', (c) => {
|
|
|
275
279
|
|
|
276
280
|
### Sessions ended everywhere
|
|
277
281
|
|
|
278
|
-
A *.ochk.io site that reads the family cookie (no `audience`) sees family sessions, which ochk.io ends on its own feed. Set `OC_REVOCATION_FEED_TOKEN` (the site's feed token from ochk.io) and the helpers check every family session against it, once a minute per process; while the feed can't be read, reads go on and writes answer 503. With it unset, a family session
|
|
282
|
+
A *.ochk.io site that reads the family cookie (no `audience`) sees family sessions, which ochk.io ends on its own feed. Set `OC_REVOCATION_FEED_TOKEN` (the site's feed token from ochk.io) and the helpers check every family session against it, once a minute per process; while the feed can't be read, reads go on and writes answer 503. With it unset, they answer a family session 503 `revocation_feed_unconfigured` and log once which setting is missing, rather than accept it by signature alone; `revocation: false` reads it by signature alone on purpose. The feed is read from `OC_AUTH_ISSUER` (default https://ochk.io), so set it too if you verify another issuer.
|
|
279
283
|
|
|
280
284
|
Set `OC_PROJECT_KEY` and `OC_SIGNING_SECRET` (from ochk.app/me/projects) and `getOcSession`, `withOcAuth`, `ocAuthExpress` and `ocAuthHono` refuse a session the person ended everywhere: sign out everywhere, a passkey removed, the account deleted. A sign-in token carries `rh`, its revocation handle for your origin; they look it up in me.ochk.io's list of ended handles for that origin, read once a minute per origin with a request signed by your secret, so a refusal lands within about two minutes. The handles name nobody, and another site's handles for the same person never match yours. If the list can't be read, or is more than ten minutes old by its own clock, reads go on and writes are refused until it can: the adapters answer such a write `503 { reason: 'revocations_unavailable' }` (0.38.0), not 401, so a client retries instead of signing the person out, and `checkOcSession(headers, options)` tells the same apart for your own code (`signed_in`, `signed_out` or `unavailable`). Every token while the two variables are unset is checked by its signature alone and stays valid until it expires. A token bound to your site without `rh` is refused (`no_session_handle`, 0.40.0 or later), since sign out everywhere can't reach it; every token from the sign-in popup carries one, and `requireHandle: false` accepts one minted some other way. Needs 0.35.0 or later.
|
|
281
285
|
|
|
282
286
|
### Sign in from an app on the person's device
|
|
283
287
|
|
|
284
|
-
A desktop build or a game can't open the popup, and must not carry a secret. It signs the person in through their browser instead (0.50.0
|
|
288
|
+
A desktop build or a game can't open the popup, and must not carry a secret. It signs the person in through their browser instead (0.50.0; a test project signs in only its own developer, and a live project needs a verified domain): the app listens on `127.0.0.1`, opens ochk.io's `/native/authorize` with a PKCE challenge, and its listener receives a one-time `code`. The app hands the code, its verifier and its redirect to your server, which trades them:
|
|
285
289
|
|
|
286
290
|
```ts
|
|
287
291
|
import { exchangeNativeCode, spendOnce } from '@orangecheck/me-client/server';
|
|
@@ -302,7 +306,7 @@ if (out.status === 'valid' && (await spendOnce(out.session.jti, out.session.exp
|
|
|
302
306
|
|
|
303
307
|
Start a session only from `valid`. It means what a request through `withOcAuth` means: the token is the popup's, verified for your `audience`, with `azp: "native"`; the person has not ended it everywhere; and the account meets your project's "who can sign in" rule. The key decides whose rule and list of ended sessions apply, so it comes from your config (`projectKey`, default `OC_PROJECT_KEY`), and a `projectKey` in the input throws. The list of ended sessions is read with your project key and `OC_SIGNING_SECRET`, as the adapters read it, or pass `revocation`; the trade counts as a write, so a list that can't be read answers `unavailable`.
|
|
304
308
|
|
|
305
|
-
`invalid` names why: `invalid_grant` (start again), `session_ended`, or `bond_required` with `need`, `have` and `back_url`, as the adapters' 403 carries them. `unavailable` is an outage (`revocations_unavailable` and `bond_policy_unavailable` among them), so answer it 503. Each code works once, whatever the answer. Turn native sign-in on for
|
|
309
|
+
`invalid` names why: `invalid_grant` (start again), `session_ended`, or `bond_required` with `need`, `have` and `back_url`, as the adapters' 403 carries them. `unavailable` is an outage (`revocations_unavailable` and `bond_policy_unavailable` among them), so answer it 503. Each code works once, whatever the answer. Turn native sign-in on for your project on ochk.app, under **Sign-in → Sign in from apps**; the app's half, with a Godot example, is at ochk.io/docs/integration/native-sign-in.
|
|
306
310
|
|
|
307
311
|
## Keep your own login: OC Connect
|
|
308
312
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,39 +1,9 @@
|
|
|
1
1
|
import { v as verifyActivityAttestation, r as refreshEnvelopeJwks } from './identity-DfxCvxuH.mjs';
|
|
2
2
|
export { A as ActivityAttestation, a as ActivityAttestationBundle, b as ActivityVerifyCheck, c as ActivityVerifyResult, V as VerifyActivityOptions, i as identity } from './identity-DfxCvxuH.mjs';
|
|
3
|
-
import { B as BillableEvent, E as EventKey, I as IntegratorPriceConfig, T as TelemetryEvent,
|
|
4
|
-
export {
|
|
3
|
+
import { S as Scope, B as BillableEvent, E as EventKey, I as IntegratorPriceConfig, T as TelemetryEvent, a as SignInOptions, b as Session, P as PaymentAuthorizeOptions, c as PaymentResult, V as ValidationResult, f as fromTemplate, g as getArchetypeTemplate, A as ArchetypeTemplate, F as Federation, G as GrantedOptions, d as GrantedResult, r as request, p as parseTrustAttestationCount } from './integrator-fTchEeNJ.mjs';
|
|
4
|
+
export { e as ALL_EVENT_SUBTYPES, h as ARCHETYPE_TEMPLATES, i as AgentClassOverride, j as AttestTier, C as CUSTOM_EVENT_KEY_RE, k as ClassASubtype, l as ClassBSubtype, m as ClassCSubtype, n as ComputedFees, D as DropCadence, o as DropClosedWebhookPayload, q as DropResponseBlock, s as DropScheduleSummary, t as EVENT_SUBTYPES, u as EventClass, v as EventSubtype, w as EventSubtypeMetadata, x as FederationMigratingWebhookPayload, y as FederationMigrationCancelledWebhookPayload, z as FederationStatus, H as FederationSuccessor, J as IntegratorArchetype, K as IntegratorEventConfig, M as MAX_DROP_WINDOW_DAYS, L as MIN_INTEGRATOR_PRICE_SATS, N as PLATFORM_FEE_POLICY, R as RequestOptions, O as SCOPE_IDS, Q as SessionPolicy, U as SigningMethod, W as SiteFeeShape, X as SystemWebhookPayload, Y as TrustAttestationCount, Z as WebhookHeaders, _ as WebhookPayload, $ as computeFees, a0 as isEventClass, a1 as isInheritedName, a2 as scope, a3 as subtypesForClass, a4 as validateIntegratorConfig } from './integrator-fTchEeNJ.mjs';
|
|
5
5
|
export { CONNECT_CONSENT_BLURB, CONNECT_CONSENT_LABEL } from './connect-consent.mjs';
|
|
6
6
|
|
|
7
|
-
type Scope = 'bitcoin_address' | 'email' | 'attest_tier' | 'display_name' | 'cross_integrator_event_count' | 'cross_integrator_human_event_count' | 'trust_attestation_count';
|
|
8
|
-
interface TrustAttestationCount {
|
|
9
|
-
total: number;
|
|
10
|
-
good: number;
|
|
11
|
-
distinct_good_issuers: number;
|
|
12
|
-
caution: number;
|
|
13
|
-
}
|
|
14
|
-
declare function parseTrustAttestationCount(value: string): TrustAttestationCount | null;
|
|
15
|
-
interface GrantedOptions {
|
|
16
|
-
project_key: string;
|
|
17
|
-
signal?: AbortSignal;
|
|
18
|
-
}
|
|
19
|
-
interface GrantedResult {
|
|
20
|
-
sub: string;
|
|
21
|
-
scopes_granted: Scope[];
|
|
22
|
-
scopes: Partial<Record<Scope, string>>;
|
|
23
|
-
}
|
|
24
|
-
declare function granted(options: GrantedOptions): Promise<GrantedResult>;
|
|
25
|
-
interface RequestOptions {
|
|
26
|
-
project_key: string;
|
|
27
|
-
return_to: string;
|
|
28
|
-
origin?: string;
|
|
29
|
-
}
|
|
30
|
-
declare function request(scopes: Scope[], options: RequestOptions): never;
|
|
31
|
-
declare const scope: {
|
|
32
|
-
granted: typeof granted;
|
|
33
|
-
request: typeof request;
|
|
34
|
-
parseTrustAttestationCount: typeof parseTrustAttestationCount;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
7
|
type FamilyVerb = 'oc-vote' | 'oc-stamp' | 'oc-agent' | 'oc-attest' | 'oc-lock' | 'oc-pledge';
|
|
38
8
|
interface FamilyScopesOptions {
|
|
39
9
|
origin?: string;
|
|
@@ -131,6 +101,7 @@ interface BatchEventInput {
|
|
|
131
101
|
idempotency_key?: string;
|
|
132
102
|
is_agent?: boolean;
|
|
133
103
|
}
|
|
104
|
+
type BatchRejectCode = 'subtype_required' | 'invalid_note' | 'invalid_action_label' | 'event_not_enabled' | 'event_class_invalid' | 'payment_amount_sats_required' | 'agent_refused' | 'earning_below_one_sat' | 'site_cap_exceeded' | 'idempotency_key_too_long' | 'duplicate_idempotency_key' | 'idempotency_key_in_flight' | 'identity_cap_reached' | 'escrow_depleted' | 'write_failed' | 'outcome_unknown';
|
|
134
105
|
type BatchEventResult = {
|
|
135
106
|
index: number;
|
|
136
107
|
status: 'recorded';
|
|
@@ -142,6 +113,7 @@ type BatchEventResult = {
|
|
|
142
113
|
} | {
|
|
143
114
|
index: number;
|
|
144
115
|
status: 'rejected';
|
|
116
|
+
code?: BatchRejectCode;
|
|
145
117
|
reason: string;
|
|
146
118
|
} | {
|
|
147
119
|
index: number;
|
|
@@ -289,4 +261,4 @@ declare const oc: {
|
|
|
289
261
|
};
|
|
290
262
|
};
|
|
291
263
|
|
|
292
|
-
export { ArchetypeTemplate, type BatchEventResult, BillableEvent, EventKey, type FamilyScopesOptions, type FamilyScopesResult, type FamilyVerb, Federation, type FireBatchResponse, type FireEventOptions, type FireEventResult,
|
|
264
|
+
export { ArchetypeTemplate, type BatchEventResult, type BatchRejectCode, BillableEvent, EventKey, type FamilyScopesOptions, type FamilyScopesResult, type FamilyVerb, Federation, type FireBatchResponse, type FireEventOptions, type FireEventResult, GrantedOptions, GrantedResult, IntegratorPriceConfig, MeClientError, type OcPublicJwk, type PayPeriod, type PayingState, PaymentAuthorizeOptions, PaymentResult, Scope, Session, SignInOptions, TelemetryEvent, ValidationResult, type VerifyEventResult, type VerifyOptions, type VerifyResult, type WithRateLimitRetryOptions, clearBearerToken, config, fromTemplate as configFromTemplate, event, family, federations, getArchetypeTemplate, getBearerToken, getOrigin, oc, onTelemetry, parseTrustAttestationCount, payingAt, payment, refreshEnvelopeJwks, safeReturnPath, session, setBearerToken, setOrigin, verifyActivityAttestation, webhook, withRateLimitRetry };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,39 +1,9 @@
|
|
|
1
1
|
import { v as verifyActivityAttestation, r as refreshEnvelopeJwks } from './identity-DfxCvxuH.js';
|
|
2
2
|
export { A as ActivityAttestation, a as ActivityAttestationBundle, b as ActivityVerifyCheck, c as ActivityVerifyResult, V as VerifyActivityOptions, i as identity } from './identity-DfxCvxuH.js';
|
|
3
|
-
import { B as BillableEvent, E as EventKey, I as IntegratorPriceConfig, T as TelemetryEvent,
|
|
4
|
-
export {
|
|
3
|
+
import { S as Scope, B as BillableEvent, E as EventKey, I as IntegratorPriceConfig, T as TelemetryEvent, a as SignInOptions, b as Session, P as PaymentAuthorizeOptions, c as PaymentResult, V as ValidationResult, f as fromTemplate, g as getArchetypeTemplate, A as ArchetypeTemplate, F as Federation, G as GrantedOptions, d as GrantedResult, r as request, p as parseTrustAttestationCount } from './integrator-fTchEeNJ.js';
|
|
4
|
+
export { e as ALL_EVENT_SUBTYPES, h as ARCHETYPE_TEMPLATES, i as AgentClassOverride, j as AttestTier, C as CUSTOM_EVENT_KEY_RE, k as ClassASubtype, l as ClassBSubtype, m as ClassCSubtype, n as ComputedFees, D as DropCadence, o as DropClosedWebhookPayload, q as DropResponseBlock, s as DropScheduleSummary, t as EVENT_SUBTYPES, u as EventClass, v as EventSubtype, w as EventSubtypeMetadata, x as FederationMigratingWebhookPayload, y as FederationMigrationCancelledWebhookPayload, z as FederationStatus, H as FederationSuccessor, J as IntegratorArchetype, K as IntegratorEventConfig, M as MAX_DROP_WINDOW_DAYS, L as MIN_INTEGRATOR_PRICE_SATS, N as PLATFORM_FEE_POLICY, R as RequestOptions, O as SCOPE_IDS, Q as SessionPolicy, U as SigningMethod, W as SiteFeeShape, X as SystemWebhookPayload, Y as TrustAttestationCount, Z as WebhookHeaders, _ as WebhookPayload, $ as computeFees, a0 as isEventClass, a1 as isInheritedName, a2 as scope, a3 as subtypesForClass, a4 as validateIntegratorConfig } from './integrator-fTchEeNJ.js';
|
|
5
5
|
export { CONNECT_CONSENT_BLURB, CONNECT_CONSENT_LABEL } from './connect-consent.js';
|
|
6
6
|
|
|
7
|
-
type Scope = 'bitcoin_address' | 'email' | 'attest_tier' | 'display_name' | 'cross_integrator_event_count' | 'cross_integrator_human_event_count' | 'trust_attestation_count';
|
|
8
|
-
interface TrustAttestationCount {
|
|
9
|
-
total: number;
|
|
10
|
-
good: number;
|
|
11
|
-
distinct_good_issuers: number;
|
|
12
|
-
caution: number;
|
|
13
|
-
}
|
|
14
|
-
declare function parseTrustAttestationCount(value: string): TrustAttestationCount | null;
|
|
15
|
-
interface GrantedOptions {
|
|
16
|
-
project_key: string;
|
|
17
|
-
signal?: AbortSignal;
|
|
18
|
-
}
|
|
19
|
-
interface GrantedResult {
|
|
20
|
-
sub: string;
|
|
21
|
-
scopes_granted: Scope[];
|
|
22
|
-
scopes: Partial<Record<Scope, string>>;
|
|
23
|
-
}
|
|
24
|
-
declare function granted(options: GrantedOptions): Promise<GrantedResult>;
|
|
25
|
-
interface RequestOptions {
|
|
26
|
-
project_key: string;
|
|
27
|
-
return_to: string;
|
|
28
|
-
origin?: string;
|
|
29
|
-
}
|
|
30
|
-
declare function request(scopes: Scope[], options: RequestOptions): never;
|
|
31
|
-
declare const scope: {
|
|
32
|
-
granted: typeof granted;
|
|
33
|
-
request: typeof request;
|
|
34
|
-
parseTrustAttestationCount: typeof parseTrustAttestationCount;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
7
|
type FamilyVerb = 'oc-vote' | 'oc-stamp' | 'oc-agent' | 'oc-attest' | 'oc-lock' | 'oc-pledge';
|
|
38
8
|
interface FamilyScopesOptions {
|
|
39
9
|
origin?: string;
|
|
@@ -131,6 +101,7 @@ interface BatchEventInput {
|
|
|
131
101
|
idempotency_key?: string;
|
|
132
102
|
is_agent?: boolean;
|
|
133
103
|
}
|
|
104
|
+
type BatchRejectCode = 'subtype_required' | 'invalid_note' | 'invalid_action_label' | 'event_not_enabled' | 'event_class_invalid' | 'payment_amount_sats_required' | 'agent_refused' | 'earning_below_one_sat' | 'site_cap_exceeded' | 'idempotency_key_too_long' | 'duplicate_idempotency_key' | 'idempotency_key_in_flight' | 'identity_cap_reached' | 'escrow_depleted' | 'write_failed' | 'outcome_unknown';
|
|
134
105
|
type BatchEventResult = {
|
|
135
106
|
index: number;
|
|
136
107
|
status: 'recorded';
|
|
@@ -142,6 +113,7 @@ type BatchEventResult = {
|
|
|
142
113
|
} | {
|
|
143
114
|
index: number;
|
|
144
115
|
status: 'rejected';
|
|
116
|
+
code?: BatchRejectCode;
|
|
145
117
|
reason: string;
|
|
146
118
|
} | {
|
|
147
119
|
index: number;
|
|
@@ -289,4 +261,4 @@ declare const oc: {
|
|
|
289
261
|
};
|
|
290
262
|
};
|
|
291
263
|
|
|
292
|
-
export { ArchetypeTemplate, type BatchEventResult, BillableEvent, EventKey, type FamilyScopesOptions, type FamilyScopesResult, type FamilyVerb, Federation, type FireBatchResponse, type FireEventOptions, type FireEventResult,
|
|
264
|
+
export { ArchetypeTemplate, type BatchEventResult, type BatchRejectCode, BillableEvent, EventKey, type FamilyScopesOptions, type FamilyScopesResult, type FamilyVerb, Federation, type FireBatchResponse, type FireEventOptions, type FireEventResult, GrantedOptions, GrantedResult, IntegratorPriceConfig, MeClientError, type OcPublicJwk, type PayPeriod, type PayingState, PaymentAuthorizeOptions, PaymentResult, Scope, Session, SignInOptions, TelemetryEvent, ValidationResult, type VerifyEventResult, type VerifyOptions, type VerifyResult, type WithRateLimitRetryOptions, clearBearerToken, config, fromTemplate as configFromTemplate, event, family, federations, getArchetypeTemplate, getBearerToken, getOrigin, oc, onTelemetry, parseTrustAttestationCount, payingAt, payment, refreshEnvelopeJwks, safeReturnPath, session, setBearerToken, setOrigin, verifyActivityAttestation, webhook, withRateLimitRetry };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var identifiers = require('@orangecheck/auth-core/identifiers');
|
|
4
|
+
|
|
3
5
|
var __defProp = Object.defineProperty;
|
|
4
6
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
7
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
@@ -46,7 +48,7 @@ async function api(path, opts = {}) {
|
|
|
46
48
|
body = data;
|
|
47
49
|
if (data?.error) {
|
|
48
50
|
errorCode = data.error;
|
|
49
|
-
message = data.reason ?? data.error;
|
|
51
|
+
message = data.reason ?? data.detail ?? data.error;
|
|
50
52
|
}
|
|
51
53
|
} catch {
|
|
52
54
|
}
|
|
@@ -162,9 +164,11 @@ async function authorize(opts) {
|
|
|
162
164
|
if (opts.amount_sats == null && opts.usd_cents == null) {
|
|
163
165
|
throw new Error("payment.authorize requires amount_sats or usd_cents");
|
|
164
166
|
}
|
|
167
|
+
const { bearerToken: bearerToken2, ...body } = opts;
|
|
165
168
|
return api("/api/payment/authorize", {
|
|
166
169
|
method: "POST",
|
|
167
|
-
body
|
|
170
|
+
body,
|
|
171
|
+
bearerToken: bearerToken2
|
|
168
172
|
});
|
|
169
173
|
}
|
|
170
174
|
var payment = { authorize };
|
|
@@ -1298,18 +1302,21 @@ async function defaultLive() {
|
|
|
1298
1302
|
return all[0] ?? null;
|
|
1299
1303
|
}
|
|
1300
1304
|
var federations = { list, live, get, defaultLive };
|
|
1301
|
-
|
|
1302
|
-
// src/scope.ts
|
|
1303
1305
|
var CONSENT_ORIGIN = "https://ochk.app";
|
|
1304
|
-
var
|
|
1306
|
+
var SCOPE_IDS = Object.freeze([
|
|
1305
1307
|
"bitcoin_address",
|
|
1306
1308
|
"email",
|
|
1307
1309
|
"attest_tier",
|
|
1308
1310
|
"display_name",
|
|
1309
1311
|
"cross_integrator_event_count",
|
|
1310
1312
|
"cross_integrator_human_event_count",
|
|
1311
|
-
"
|
|
1312
|
-
|
|
1313
|
+
"cross_integrator_lifetime_sats",
|
|
1314
|
+
"cross_integrator_distinct_count",
|
|
1315
|
+
"cross_integrator_oldest_event_at",
|
|
1316
|
+
"cross_integrator_active_days",
|
|
1317
|
+
"trust_attestation_count",
|
|
1318
|
+
"trust_attestations_bundle"
|
|
1319
|
+
]);
|
|
1313
1320
|
function parseTrustAttestationCount(value) {
|
|
1314
1321
|
const parts = value.split(",");
|
|
1315
1322
|
if (parts.length !== 4) return null;
|
|
@@ -1326,9 +1333,28 @@ async function granted(options) {
|
|
|
1326
1333
|
if (!options.project_key) {
|
|
1327
1334
|
throw new Error("oc.scope.granted: project_key is required");
|
|
1328
1335
|
}
|
|
1336
|
+
const { accountId, signingSecret } = options;
|
|
1337
|
+
if (accountId !== void 0 && !signingSecret) {
|
|
1338
|
+
throw new Error("oc.scope.granted: accountId names the person, so it requires signingSecret");
|
|
1339
|
+
}
|
|
1340
|
+
if (signingSecret && accountId === void 0) {
|
|
1341
|
+
throw new Error("oc.scope.granted: signingSecret signs a question about one person, so it requires accountId");
|
|
1342
|
+
}
|
|
1343
|
+
if (accountId !== void 0 && !identifiers.isDidOc(accountId)) {
|
|
1344
|
+
throw new Error("oc.scope.granted: accountId must be a did:oc exactly as issued (did:oc: and 32 lowercase hex)");
|
|
1345
|
+
}
|
|
1346
|
+
let path = `/api/integrator/scopes/${encodeURIComponent(options.project_key)}`;
|
|
1347
|
+
const headers = {};
|
|
1348
|
+
if (accountId !== void 0 && signingSecret) {
|
|
1349
|
+
path += `?user=${encodeURIComponent(accountId)}`;
|
|
1350
|
+
headers["x-oc-signature"] = await signBody(
|
|
1351
|
+
signingSecret,
|
|
1352
|
+
`project_key=${options.project_key}&user=${accountId}`
|
|
1353
|
+
);
|
|
1354
|
+
}
|
|
1329
1355
|
const r = await api(
|
|
1330
|
-
|
|
1331
|
-
{ method: "GET", signal: options.signal }
|
|
1356
|
+
path,
|
|
1357
|
+
{ method: "GET", signal: options.signal, headers }
|
|
1332
1358
|
);
|
|
1333
1359
|
return {
|
|
1334
1360
|
sub: r.sub,
|
|
@@ -1347,9 +1373,9 @@ function request(scopes2, options) {
|
|
|
1347
1373
|
throw new Error("oc.scope.request: scopes must be a non-empty array");
|
|
1348
1374
|
}
|
|
1349
1375
|
for (const s of scopes2) {
|
|
1350
|
-
if (!
|
|
1376
|
+
if (!SCOPE_IDS.includes(s)) {
|
|
1351
1377
|
throw new Error(
|
|
1352
|
-
`oc.scope.request: unknown scope "${s}" \xB7 valid: ${
|
|
1378
|
+
`oc.scope.request: unknown scope "${s}" \xB7 valid: ${SCOPE_IDS.join(", ")}`
|
|
1353
1379
|
);
|
|
1354
1380
|
}
|
|
1355
1381
|
}
|
|
@@ -1721,6 +1747,7 @@ exports.MAX_DROP_WINDOW_DAYS = MAX_DROP_WINDOW_DAYS;
|
|
|
1721
1747
|
exports.MIN_INTEGRATOR_PRICE_SATS = MIN_INTEGRATOR_PRICE_SATS;
|
|
1722
1748
|
exports.MeClientError = MeClientError;
|
|
1723
1749
|
exports.PLATFORM_FEE_POLICY = PLATFORM_FEE_POLICY;
|
|
1750
|
+
exports.SCOPE_IDS = SCOPE_IDS;
|
|
1724
1751
|
exports.clearBearerToken = clearBearerToken;
|
|
1725
1752
|
exports.computeFees = computeFees;
|
|
1726
1753
|
exports.config = config;
|