@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 +34 -2
- package/dist/index.d.ts +34 -2
- package/dist/index.js +57 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -793,8 +793,21 @@ var VALID_SCOPES = [
|
|
|
793
793
|
"attest_tier",
|
|
794
794
|
"display_name",
|
|
795
795
|
"cross_integrator_event_count",
|
|
796
|
-
"cross_integrator_human_event_count"
|
|
796
|
+
"cross_integrator_human_event_count",
|
|
797
|
+
"trust_attestation_count"
|
|
797
798
|
];
|
|
799
|
+
function parseTrustAttestationCount(value) {
|
|
800
|
+
const parts = value.split(",");
|
|
801
|
+
if (parts.length !== 4) return null;
|
|
802
|
+
const ints = parts.map((p) => Number.parseInt(p, 10));
|
|
803
|
+
if (ints.some((n) => !Number.isInteger(n) || n < 0)) return null;
|
|
804
|
+
return {
|
|
805
|
+
total: ints[0],
|
|
806
|
+
good: ints[1],
|
|
807
|
+
distinct_good_issuers: ints[2],
|
|
808
|
+
caution: ints[3]
|
|
809
|
+
};
|
|
810
|
+
}
|
|
798
811
|
async function granted(options) {
|
|
799
812
|
if (!options.project_key) {
|
|
800
813
|
throw new Error("oc.scope.granted: project_key is required");
|
|
@@ -809,17 +822,17 @@ async function granted(options) {
|
|
|
809
822
|
scopes: r.scopes
|
|
810
823
|
};
|
|
811
824
|
}
|
|
812
|
-
function request(
|
|
825
|
+
function request(scopes2, options) {
|
|
813
826
|
if (!options.project_key) {
|
|
814
827
|
throw new Error("oc.scope.request: project_key is required");
|
|
815
828
|
}
|
|
816
829
|
if (!options.return_to) {
|
|
817
830
|
throw new Error("oc.scope.request: return_to is required");
|
|
818
831
|
}
|
|
819
|
-
if (!Array.isArray(
|
|
832
|
+
if (!Array.isArray(scopes2) || scopes2.length === 0) {
|
|
820
833
|
throw new Error("oc.scope.request: scopes must be a non-empty array");
|
|
821
834
|
}
|
|
822
|
-
for (const s of
|
|
835
|
+
for (const s of scopes2) {
|
|
823
836
|
if (!VALID_SCOPES.includes(s)) {
|
|
824
837
|
throw new Error(
|
|
825
838
|
`oc.scope.request: unknown scope "${s}" \xB7 valid: ${VALID_SCOPES.join(", ")}`
|
|
@@ -832,16 +845,51 @@ function request(scopes, options) {
|
|
|
832
845
|
const origin2 = options.origin ?? getOrigin();
|
|
833
846
|
const url = new URL("/me/scope-grant", origin2);
|
|
834
847
|
url.searchParams.set("project_key", options.project_key);
|
|
835
|
-
url.searchParams.set("scopes",
|
|
848
|
+
url.searchParams.set("scopes", scopes2.join(","));
|
|
836
849
|
url.searchParams.set("return_to", options.return_to);
|
|
837
850
|
window.location.assign(url.toString());
|
|
838
851
|
throw new Error("oc.scope.request: redirected to consent prompt");
|
|
839
852
|
}
|
|
840
|
-
var scope = { granted, request };
|
|
853
|
+
var scope = { granted, request, parseTrustAttestationCount };
|
|
854
|
+
|
|
855
|
+
// src/family.ts
|
|
856
|
+
var VALID_VERBS = [
|
|
857
|
+
"oc-vote",
|
|
858
|
+
"oc-stamp",
|
|
859
|
+
"oc-agent",
|
|
860
|
+
"oc-attest",
|
|
861
|
+
"oc-lock"
|
|
862
|
+
];
|
|
863
|
+
async function scopes(verb, options) {
|
|
864
|
+
if (!VALID_VERBS.includes(verb)) {
|
|
865
|
+
throw new Error(
|
|
866
|
+
`oc.family.scopes: unknown verb "${verb}" \xB7 valid: ${VALID_VERBS.join(", ")}`
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
const origin2 = options?.origin ?? "https://me.ochk.io";
|
|
870
|
+
const url = `${origin2}/api/family/scopes/${encodeURIComponent(verb)}`;
|
|
871
|
+
const res = await fetch(url, {
|
|
872
|
+
method: "GET",
|
|
873
|
+
credentials: "include",
|
|
874
|
+
signal: options?.signal
|
|
875
|
+
});
|
|
876
|
+
if (!res.ok) {
|
|
877
|
+
const txt = await res.text().catch(() => "");
|
|
878
|
+
throw new Error(`oc.family.scopes: ${res.status} ${txt || res.statusText}`);
|
|
879
|
+
}
|
|
880
|
+
const json = await res.json();
|
|
881
|
+
return {
|
|
882
|
+
sub: json.sub,
|
|
883
|
+
family_product: json.family_product,
|
|
884
|
+
scopes_granted: json.scopes_granted,
|
|
885
|
+
scopes: json.scopes
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
var family = { scopes };
|
|
841
889
|
|
|
842
890
|
// src/index.ts
|
|
843
|
-
var oc = { session, payment, event, config, webhook, federations, scope };
|
|
891
|
+
var oc = { session, payment, event, config, webhook, federations, scope, family };
|
|
844
892
|
|
|
845
|
-
export { MIN_INTEGRATOR_PRICE_SATS, MeClientError, OcSignInButton, PLATFORM_FEE_POLICY, clearBearerToken, computeFees, config, event, federations, getBearerToken, getOrigin, oc, onTelemetry, payment, scope, session, setBearerToken, setOrigin, validateIntegratorConfig, webhook, withRateLimitRetry };
|
|
893
|
+
export { MIN_INTEGRATOR_PRICE_SATS, MeClientError, OcSignInButton, PLATFORM_FEE_POLICY, clearBearerToken, computeFees, config, event, family, federations, getBearerToken, getOrigin, oc, onTelemetry, parseTrustAttestationCount, payment, scope, session, setBearerToken, setOrigin, validateIntegratorConfig, webhook, withRateLimitRetry };
|
|
846
894
|
//# sourceMappingURL=index.mjs.map
|
|
847
895
|
//# sourceMappingURL=index.mjs.map
|