@orangecheck/me-client 0.14.0 → 0.16.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 CHANGED
@@ -1,7 +1,14 @@
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' | 'cross_integrator_event_count' | 'cross_integrator_human_event_count';
4
+ type Scope = 'bitcoin_address' | 'email' | 'attest_tier' | 'display_name' | 'cross_integrator_event_count' | 'cross_integrator_human_event_count' | 'trust_attestation_count';
5
+ interface TrustAttestationCount {
6
+ total: number;
7
+ good: number;
8
+ distinct_good_issuers: number;
9
+ caution: number;
10
+ }
11
+ declare function parseTrustAttestationCount(value: string): TrustAttestationCount | null;
5
12
  interface GrantedOptions {
6
13
  project_key: string;
7
14
  signal?: AbortSignal;
@@ -21,6 +28,27 @@ declare function request(scopes: Scope[], options: RequestOptions): never;
21
28
  declare const scope: {
22
29
  granted: typeof granted;
23
30
  request: typeof request;
31
+ parseTrustAttestationCount: typeof parseTrustAttestationCount;
32
+ };
33
+
34
+ type FamilyVerb = 'oc-vote' | 'oc-stamp' | 'oc-agent' | 'oc-attest' | 'oc-lock';
35
+ interface FamilyScopesOptions {
36
+ origin?: string;
37
+ signal?: AbortSignal;
38
+ }
39
+ interface FamilyScopesResult {
40
+ sub: string;
41
+ family_product: {
42
+ verb: FamilyVerb;
43
+ name: string;
44
+ origin: string;
45
+ };
46
+ scopes_granted: Scope[];
47
+ scopes: Partial<Record<Scope, string>>;
48
+ }
49
+ declare function scopes(verb: FamilyVerb, options?: FamilyScopesOptions): Promise<FamilyScopesResult>;
50
+ declare const family: {
51
+ scopes: typeof scopes;
24
52
  };
25
53
 
26
54
  interface VerifyResult {
@@ -322,7 +350,11 @@ declare const oc: {
322
350
  scope: {
323
351
  granted: (options: GrantedOptions) => Promise<GrantedResult>;
324
352
  request: typeof request;
353
+ parseTrustAttestationCount: typeof parseTrustAttestationCount;
354
+ };
355
+ family: {
356
+ scopes: (verb: FamilyVerb, options?: FamilyScopesOptions) => Promise<FamilyScopesResult>;
325
357
  };
326
358
  };
327
359
 
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 };
360
+ export { type AttestTier, type BillableEvent, type ClassASubtype, type ClassBSubtype, type ClassCSubtype, type ComputedFees, type EventClass, type EventSubtype, type FamilyScopesOptions, type FamilyScopesResult, type FamilyVerb, 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 TrustAttestationCount, type ValidationResult, type VerifyEventResult, type VerifyOptions, type VerifyResult, type WithRateLimitRetryOptions, clearBearerToken, computeFees, config, event, family, federations, getBearerToken, getOrigin, oc, onTelemetry, parseTrustAttestationCount, payment, scope, session, setBearerToken, setOrigin, validateIntegratorConfig, webhook, withRateLimitRetry };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,14 @@
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' | 'cross_integrator_event_count' | 'cross_integrator_human_event_count';
4
+ type Scope = 'bitcoin_address' | 'email' | 'attest_tier' | 'display_name' | 'cross_integrator_event_count' | 'cross_integrator_human_event_count' | 'trust_attestation_count';
5
+ interface TrustAttestationCount {
6
+ total: number;
7
+ good: number;
8
+ distinct_good_issuers: number;
9
+ caution: number;
10
+ }
11
+ declare function parseTrustAttestationCount(value: string): TrustAttestationCount | null;
5
12
  interface GrantedOptions {
6
13
  project_key: string;
7
14
  signal?: AbortSignal;
@@ -21,6 +28,27 @@ declare function request(scopes: Scope[], options: RequestOptions): never;
21
28
  declare const scope: {
22
29
  granted: typeof granted;
23
30
  request: typeof request;
31
+ parseTrustAttestationCount: typeof parseTrustAttestationCount;
32
+ };
33
+
34
+ type FamilyVerb = 'oc-vote' | 'oc-stamp' | 'oc-agent' | 'oc-attest' | 'oc-lock';
35
+ interface FamilyScopesOptions {
36
+ origin?: string;
37
+ signal?: AbortSignal;
38
+ }
39
+ interface FamilyScopesResult {
40
+ sub: string;
41
+ family_product: {
42
+ verb: FamilyVerb;
43
+ name: string;
44
+ origin: string;
45
+ };
46
+ scopes_granted: Scope[];
47
+ scopes: Partial<Record<Scope, string>>;
48
+ }
49
+ declare function scopes(verb: FamilyVerb, options?: FamilyScopesOptions): Promise<FamilyScopesResult>;
50
+ declare const family: {
51
+ scopes: typeof scopes;
24
52
  };
25
53
 
26
54
  interface VerifyResult {
@@ -322,7 +350,11 @@ declare const oc: {
322
350
  scope: {
323
351
  granted: (options: GrantedOptions) => Promise<GrantedResult>;
324
352
  request: typeof request;
353
+ parseTrustAttestationCount: typeof parseTrustAttestationCount;
354
+ };
355
+ family: {
356
+ scopes: (verb: FamilyVerb, options?: FamilyScopesOptions) => Promise<FamilyScopesResult>;
325
357
  };
326
358
  };
327
359
 
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 };
360
+ export { type AttestTier, type BillableEvent, type ClassASubtype, type ClassBSubtype, type ClassCSubtype, type ComputedFees, type EventClass, type EventSubtype, type FamilyScopesOptions, type FamilyScopesResult, type FamilyVerb, 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 TrustAttestationCount, type ValidationResult, type VerifyEventResult, type VerifyOptions, type VerifyResult, type WithRateLimitRetryOptions, clearBearerToken, computeFees, config, event, family, federations, getBearerToken, getOrigin, oc, onTelemetry, parseTrustAttestationCount, payment, scope, session, setBearerToken, setOrigin, validateIntegratorConfig, webhook, withRateLimitRetry };
package/dist/index.js CHANGED
@@ -815,8 +815,21 @@ var VALID_SCOPES = [
815
815
  "attest_tier",
816
816
  "display_name",
817
817
  "cross_integrator_event_count",
818
- "cross_integrator_human_event_count"
818
+ "cross_integrator_human_event_count",
819
+ "trust_attestation_count"
819
820
  ];
821
+ function parseTrustAttestationCount(value) {
822
+ const parts = value.split(",");
823
+ if (parts.length !== 4) return null;
824
+ const ints = parts.map((p) => Number.parseInt(p, 10));
825
+ if (ints.some((n) => !Number.isInteger(n) || n < 0)) return null;
826
+ return {
827
+ total: ints[0],
828
+ good: ints[1],
829
+ distinct_good_issuers: ints[2],
830
+ caution: ints[3]
831
+ };
832
+ }
820
833
  async function granted(options) {
821
834
  if (!options.project_key) {
822
835
  throw new Error("oc.scope.granted: project_key is required");
@@ -831,17 +844,17 @@ async function granted(options) {
831
844
  scopes: r.scopes
832
845
  };
833
846
  }
834
- function request(scopes, options) {
847
+ function request(scopes2, options) {
835
848
  if (!options.project_key) {
836
849
  throw new Error("oc.scope.request: project_key is required");
837
850
  }
838
851
  if (!options.return_to) {
839
852
  throw new Error("oc.scope.request: return_to is required");
840
853
  }
841
- if (!Array.isArray(scopes) || scopes.length === 0) {
854
+ if (!Array.isArray(scopes2) || scopes2.length === 0) {
842
855
  throw new Error("oc.scope.request: scopes must be a non-empty array");
843
856
  }
844
- for (const s of scopes) {
857
+ for (const s of scopes2) {
845
858
  if (!VALID_SCOPES.includes(s)) {
846
859
  throw new Error(
847
860
  `oc.scope.request: unknown scope "${s}" \xB7 valid: ${VALID_SCOPES.join(", ")}`
@@ -854,15 +867,50 @@ function request(scopes, options) {
854
867
  const origin2 = options.origin ?? getOrigin();
855
868
  const url = new URL("/me/scope-grant", origin2);
856
869
  url.searchParams.set("project_key", options.project_key);
857
- url.searchParams.set("scopes", scopes.join(","));
870
+ url.searchParams.set("scopes", scopes2.join(","));
858
871
  url.searchParams.set("return_to", options.return_to);
859
872
  window.location.assign(url.toString());
860
873
  throw new Error("oc.scope.request: redirected to consent prompt");
861
874
  }
862
- var scope = { granted, request };
875
+ var scope = { granted, request, parseTrustAttestationCount };
876
+
877
+ // src/family.ts
878
+ var VALID_VERBS = [
879
+ "oc-vote",
880
+ "oc-stamp",
881
+ "oc-agent",
882
+ "oc-attest",
883
+ "oc-lock"
884
+ ];
885
+ async function scopes(verb, options) {
886
+ if (!VALID_VERBS.includes(verb)) {
887
+ throw new Error(
888
+ `oc.family.scopes: unknown verb "${verb}" \xB7 valid: ${VALID_VERBS.join(", ")}`
889
+ );
890
+ }
891
+ const origin2 = options?.origin ?? "https://me.ochk.io";
892
+ const url = `${origin2}/api/family/scopes/${encodeURIComponent(verb)}`;
893
+ const res = await fetch(url, {
894
+ method: "GET",
895
+ credentials: "include",
896
+ signal: options?.signal
897
+ });
898
+ if (!res.ok) {
899
+ const txt = await res.text().catch(() => "");
900
+ throw new Error(`oc.family.scopes: ${res.status} ${txt || res.statusText}`);
901
+ }
902
+ const json = await res.json();
903
+ return {
904
+ sub: json.sub,
905
+ family_product: json.family_product,
906
+ scopes_granted: json.scopes_granted,
907
+ scopes: json.scopes
908
+ };
909
+ }
910
+ var family = { scopes };
863
911
 
864
912
  // src/index.ts
865
- var oc = { session, payment, event, config, webhook, federations, scope };
913
+ var oc = { session, payment, event, config, webhook, federations, scope, family };
866
914
 
867
915
  exports.MIN_INTEGRATOR_PRICE_SATS = MIN_INTEGRATOR_PRICE_SATS;
868
916
  exports.MeClientError = MeClientError;
@@ -872,11 +920,13 @@ exports.clearBearerToken = clearBearerToken;
872
920
  exports.computeFees = computeFees;
873
921
  exports.config = config;
874
922
  exports.event = event;
923
+ exports.family = family;
875
924
  exports.federations = federations;
876
925
  exports.getBearerToken = getBearerToken;
877
926
  exports.getOrigin = getOrigin;
878
927
  exports.oc = oc;
879
928
  exports.onTelemetry = onTelemetry;
929
+ exports.parseTrustAttestationCount = parseTrustAttestationCount;
880
930
  exports.payment = payment;
881
931
  exports.scope = scope;
882
932
  exports.session = session;