@orangecheck/me-client 0.38.3 → 0.39.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 +29 -0
- package/dist/connect-consent.d.mts +4 -0
- package/dist/connect-consent.d.ts +4 -0
- package/dist/connect-consent.js +10 -0
- package/dist/connect-consent.js.map +1 -0
- package/dist/connect-consent.mjs +7 -0
- package/dist/connect-consent.mjs.map +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -1
- package/dist/index.mjs.map +1 -1
- package/dist/server.d.mts +38 -1
- package/dist/server.d.ts +38 -1
- package/dist/server.js +176 -7
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +172 -8
- package/dist/server.mjs.map +1 -1
- package/package.json +6 -1
package/dist/server.d.mts
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
import { SessionPayload, VerifyOcOptions, RevocationCheck, SessionRequestHeaders } from '@orangecheck/auth-core';
|
|
2
2
|
export { BondClaim, SessionPayload, VerifyOcOptions, bondMeets, readBondClaim, verifyOcToken } from '@orangecheck/auth-core';
|
|
3
3
|
export { A as ActivityAttestation, a as ActivityAttestationBundle, b as ActivityVerifyCheck, c as ActivityVerifyResult, V as VerifyActivityOptions, i as identity, r as refreshEnvelopeJwks, v as verifyActivityAttestation } from './identity-DfxCvxuH.mjs';
|
|
4
|
+
export { CONNECT_CONSENT_BLURB, CONNECT_CONSENT_LABEL } from './connect-consent.mjs';
|
|
5
|
+
|
|
6
|
+
interface ConnectOptions {
|
|
7
|
+
apiKey: string;
|
|
8
|
+
userId: string;
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
}
|
|
11
|
+
interface ConnectProvisionOptions extends ConnectOptions {
|
|
12
|
+
consent?: true;
|
|
13
|
+
email?: string;
|
|
14
|
+
emailVerified?: boolean;
|
|
15
|
+
}
|
|
16
|
+
type ConnectProvisionRefusal = 'account_deleted' | 'daily_limit' | 'rate_limited' | 'invalid_api_key' | 'app_suspended' | 'bad_request' | 'unavailable';
|
|
17
|
+
type ConnectDeleteRefusal = 'unknown_user' | 'holds_earnings' | 'not_deletable' | 'rate_limited' | 'invalid_api_key' | 'bad_request' | 'unavailable';
|
|
18
|
+
type ConnectClaimLinkRefusal = 'unknown_user' | 'already_claimed' | 'rate_limited' | 'invalid_api_key' | 'app_suspended' | 'bad_request' | 'unavailable';
|
|
19
|
+
interface ConnectRefused<R extends string> {
|
|
20
|
+
ok: false;
|
|
21
|
+
reason: R;
|
|
22
|
+
status: number;
|
|
23
|
+
}
|
|
24
|
+
type ConnectProvisionResult = {
|
|
25
|
+
ok: true;
|
|
26
|
+
did_oc: string;
|
|
27
|
+
is_new: boolean;
|
|
28
|
+
} | ConnectRefused<ConnectProvisionRefusal>;
|
|
29
|
+
type ConnectDeleteResult = {
|
|
30
|
+
ok: true;
|
|
31
|
+
result: 'deleted' | 'detached' | 'already_deleted';
|
|
32
|
+
} | ConnectRefused<ConnectDeleteRefusal>;
|
|
33
|
+
type ConnectClaimLinkResult = {
|
|
34
|
+
ok: true;
|
|
35
|
+
url: string;
|
|
36
|
+
expires_at: string;
|
|
37
|
+
} | ConnectRefused<ConnectClaimLinkRefusal>;
|
|
38
|
+
declare function connectProvision(options: ConnectProvisionOptions): Promise<ConnectProvisionResult>;
|
|
39
|
+
declare function connectClaimLink(options: ConnectOptions): Promise<ConnectClaimLinkResult>;
|
|
40
|
+
declare function connectDelete(options: ConnectOptions): Promise<ConnectDeleteResult>;
|
|
4
41
|
|
|
5
42
|
interface OcSessionOptions extends VerifyOcOptions {
|
|
6
43
|
method?: string;
|
|
@@ -89,4 +126,4 @@ interface HonoContextLike {
|
|
|
89
126
|
type HonoNextLike = () => Promise<void>;
|
|
90
127
|
declare function ocAuthHono(options?: WithOcAuthOptions): (c: HonoContextLike, next: HonoNextLike) => Promise<unknown>;
|
|
91
128
|
|
|
92
|
-
export { BACK_ACCOUNT_URL, type OcHonoEnv, type OcSessionCheck, type OcSessionOptions, type WithOcAuthOptions, type WithOcSession, _resetSessionChecksForTests, checkOcSession, getOcSession, ocAuthExpress, ocAuthHono, withOcAuth };
|
|
129
|
+
export { BACK_ACCOUNT_URL, type ConnectClaimLinkRefusal, type ConnectClaimLinkResult, type ConnectDeleteRefusal, type ConnectDeleteResult, type ConnectOptions, type ConnectProvisionOptions, type ConnectProvisionRefusal, type ConnectProvisionResult, type ConnectRefused, type OcHonoEnv, type OcSessionCheck, type OcSessionOptions, type WithOcAuthOptions, type WithOcSession, _resetSessionChecksForTests, checkOcSession, connectClaimLink, connectDelete, connectProvision, getOcSession, ocAuthExpress, ocAuthHono, withOcAuth };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
import { SessionPayload, VerifyOcOptions, RevocationCheck, SessionRequestHeaders } from '@orangecheck/auth-core';
|
|
2
2
|
export { BondClaim, SessionPayload, VerifyOcOptions, bondMeets, readBondClaim, verifyOcToken } from '@orangecheck/auth-core';
|
|
3
3
|
export { A as ActivityAttestation, a as ActivityAttestationBundle, b as ActivityVerifyCheck, c as ActivityVerifyResult, V as VerifyActivityOptions, i as identity, r as refreshEnvelopeJwks, v as verifyActivityAttestation } from './identity-DfxCvxuH.js';
|
|
4
|
+
export { CONNECT_CONSENT_BLURB, CONNECT_CONSENT_LABEL } from './connect-consent.js';
|
|
5
|
+
|
|
6
|
+
interface ConnectOptions {
|
|
7
|
+
apiKey: string;
|
|
8
|
+
userId: string;
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
}
|
|
11
|
+
interface ConnectProvisionOptions extends ConnectOptions {
|
|
12
|
+
consent?: true;
|
|
13
|
+
email?: string;
|
|
14
|
+
emailVerified?: boolean;
|
|
15
|
+
}
|
|
16
|
+
type ConnectProvisionRefusal = 'account_deleted' | 'daily_limit' | 'rate_limited' | 'invalid_api_key' | 'app_suspended' | 'bad_request' | 'unavailable';
|
|
17
|
+
type ConnectDeleteRefusal = 'unknown_user' | 'holds_earnings' | 'not_deletable' | 'rate_limited' | 'invalid_api_key' | 'bad_request' | 'unavailable';
|
|
18
|
+
type ConnectClaimLinkRefusal = 'unknown_user' | 'already_claimed' | 'rate_limited' | 'invalid_api_key' | 'app_suspended' | 'bad_request' | 'unavailable';
|
|
19
|
+
interface ConnectRefused<R extends string> {
|
|
20
|
+
ok: false;
|
|
21
|
+
reason: R;
|
|
22
|
+
status: number;
|
|
23
|
+
}
|
|
24
|
+
type ConnectProvisionResult = {
|
|
25
|
+
ok: true;
|
|
26
|
+
did_oc: string;
|
|
27
|
+
is_new: boolean;
|
|
28
|
+
} | ConnectRefused<ConnectProvisionRefusal>;
|
|
29
|
+
type ConnectDeleteResult = {
|
|
30
|
+
ok: true;
|
|
31
|
+
result: 'deleted' | 'detached' | 'already_deleted';
|
|
32
|
+
} | ConnectRefused<ConnectDeleteRefusal>;
|
|
33
|
+
type ConnectClaimLinkResult = {
|
|
34
|
+
ok: true;
|
|
35
|
+
url: string;
|
|
36
|
+
expires_at: string;
|
|
37
|
+
} | ConnectRefused<ConnectClaimLinkRefusal>;
|
|
38
|
+
declare function connectProvision(options: ConnectProvisionOptions): Promise<ConnectProvisionResult>;
|
|
39
|
+
declare function connectClaimLink(options: ConnectOptions): Promise<ConnectClaimLinkResult>;
|
|
40
|
+
declare function connectDelete(options: ConnectOptions): Promise<ConnectDeleteResult>;
|
|
4
41
|
|
|
5
42
|
interface OcSessionOptions extends VerifyOcOptions {
|
|
6
43
|
method?: string;
|
|
@@ -89,4 +126,4 @@ interface HonoContextLike {
|
|
|
89
126
|
type HonoNextLike = () => Promise<void>;
|
|
90
127
|
declare function ocAuthHono(options?: WithOcAuthOptions): (c: HonoContextLike, next: HonoNextLike) => Promise<unknown>;
|
|
91
128
|
|
|
92
|
-
export { BACK_ACCOUNT_URL, type OcHonoEnv, type OcSessionCheck, type OcSessionOptions, type WithOcAuthOptions, type WithOcSession, _resetSessionChecksForTests, checkOcSession, getOcSession, ocAuthExpress, ocAuthHono, withOcAuth };
|
|
129
|
+
export { BACK_ACCOUNT_URL, type ConnectClaimLinkRefusal, type ConnectClaimLinkResult, type ConnectDeleteRefusal, type ConnectDeleteResult, type ConnectOptions, type ConnectProvisionOptions, type ConnectProvisionRefusal, type ConnectProvisionResult, type ConnectRefused, type OcHonoEnv, type OcSessionCheck, type OcSessionOptions, type WithOcAuthOptions, type WithOcSession, _resetSessionChecksForTests, checkOcSession, connectClaimLink, connectDelete, connectProvision, getOcSession, ocAuthExpress, ocAuthHono, withOcAuth };
|
package/dist/server.js
CHANGED
|
@@ -569,6 +569,170 @@ var identity = {
|
|
|
569
569
|
refreshEnvelopeJwks
|
|
570
570
|
};
|
|
571
571
|
|
|
572
|
+
// src/connect.ts
|
|
573
|
+
var ORIGIN = "https://ochk.io";
|
|
574
|
+
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
575
|
+
var MAX_TIMEOUT_MS = 3e4;
|
|
576
|
+
var DID_OC = /^did:oc:[0-9a-f]{32}$/;
|
|
577
|
+
var BASE_KEYS = ["apiKey", "userId", "timeoutMs"];
|
|
578
|
+
var PROVISION_KEYS = /* @__PURE__ */ new Set([...BASE_KEYS, "consent", "email", "emailVerified"]);
|
|
579
|
+
var USER_KEYS = new Set(BASE_KEYS);
|
|
580
|
+
var PROVISION_REASONS = /* @__PURE__ */ new Set([
|
|
581
|
+
"account_deleted",
|
|
582
|
+
"daily_limit",
|
|
583
|
+
"rate_limited",
|
|
584
|
+
"invalid_api_key",
|
|
585
|
+
"app_suspended",
|
|
586
|
+
"bad_request"
|
|
587
|
+
]);
|
|
588
|
+
var DELETE_REASONS = /* @__PURE__ */ new Set([
|
|
589
|
+
"unknown_user",
|
|
590
|
+
"holds_earnings",
|
|
591
|
+
"not_deletable",
|
|
592
|
+
"rate_limited",
|
|
593
|
+
"invalid_api_key",
|
|
594
|
+
"bad_request"
|
|
595
|
+
]);
|
|
596
|
+
var CLAIM_LINK_REASONS = /* @__PURE__ */ new Set([
|
|
597
|
+
"unknown_user",
|
|
598
|
+
"already_claimed",
|
|
599
|
+
"rate_limited",
|
|
600
|
+
"invalid_api_key",
|
|
601
|
+
"app_suspended",
|
|
602
|
+
"bad_request"
|
|
603
|
+
]);
|
|
604
|
+
var DELETE_RESULTS = /* @__PURE__ */ new Set(["deleted", "detached", "already_deleted"]);
|
|
605
|
+
function fail(message) {
|
|
606
|
+
throw new TypeError(`@orangecheck/me-client: ${message}`);
|
|
607
|
+
}
|
|
608
|
+
function checkCall(name, options, known) {
|
|
609
|
+
if (typeof document !== "undefined") {
|
|
610
|
+
fail(`${name} runs on your server only: in a browser your API key would be exposed`);
|
|
611
|
+
}
|
|
612
|
+
if (options === null || typeof options !== "object") fail(`${name}: options must be an object`);
|
|
613
|
+
const unknown = Object.keys(options).filter((k) => !known.has(k));
|
|
614
|
+
if (unknown.length > 0) {
|
|
615
|
+
const only = [...known].join(", ");
|
|
616
|
+
fail(`${name}: unknown option ${unknown.join(", ")}. It reads only ${only}.`);
|
|
617
|
+
}
|
|
618
|
+
const o = Object.assign(/* @__PURE__ */ Object.create(null), options);
|
|
619
|
+
if (typeof o.apiKey !== "string" || o.apiKey.trim() === "") {
|
|
620
|
+
fail(`${name}: apiKey is required (your Connect API key)`);
|
|
621
|
+
}
|
|
622
|
+
const id = o.userId;
|
|
623
|
+
if (typeof id !== "string" || id.length < 1 || id.length > 256) {
|
|
624
|
+
fail(`${name}: userId must be your user's id, 1 to 256 characters`);
|
|
625
|
+
}
|
|
626
|
+
const t = o.timeoutMs;
|
|
627
|
+
if (t !== void 0 && !(typeof t === "number" && t > 0 && t <= MAX_TIMEOUT_MS)) {
|
|
628
|
+
fail(`${name}: timeoutMs must be above 0 and at most ${MAX_TIMEOUT_MS}`);
|
|
629
|
+
}
|
|
630
|
+
return o;
|
|
631
|
+
}
|
|
632
|
+
async function post(path, apiKey, body, timeoutMs) {
|
|
633
|
+
const controller = new AbortController();
|
|
634
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
635
|
+
try {
|
|
636
|
+
const res = await fetch(`${ORIGIN}${path}`, {
|
|
637
|
+
method: "POST",
|
|
638
|
+
// These endpoints never redirect, so a redirect is an error: the key and
|
|
639
|
+
// the body go to ochk.io and nowhere else.
|
|
640
|
+
redirect: "error",
|
|
641
|
+
headers: {
|
|
642
|
+
"content-type": "application/json",
|
|
643
|
+
authorization: `Bearer ${apiKey}`
|
|
644
|
+
},
|
|
645
|
+
body: JSON.stringify(body),
|
|
646
|
+
signal: controller.signal
|
|
647
|
+
});
|
|
648
|
+
let parsed = null;
|
|
649
|
+
try {
|
|
650
|
+
parsed = await res.json();
|
|
651
|
+
} catch {
|
|
652
|
+
parsed = null;
|
|
653
|
+
}
|
|
654
|
+
const ok = parsed !== null && typeof parsed === "object" && !Array.isArray(parsed);
|
|
655
|
+
return { status: res.status, body: ok ? parsed : null };
|
|
656
|
+
} catch {
|
|
657
|
+
return { status: 0, body: null };
|
|
658
|
+
} finally {
|
|
659
|
+
clearTimeout(timer);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
function refused(answer, known) {
|
|
663
|
+
const raw = answer.body?.reason;
|
|
664
|
+
const said = raw === "missing_api_key" ? "invalid_api_key" : raw;
|
|
665
|
+
const reason = typeof said === "string" && known.has(said) ? said : "unavailable";
|
|
666
|
+
return { ok: false, reason, status: answer.status };
|
|
667
|
+
}
|
|
668
|
+
function connectProvision(options) {
|
|
669
|
+
const o = checkCall("connectProvision", options, PROVISION_KEYS);
|
|
670
|
+
if (o.consent !== void 0 && o.consent !== true) {
|
|
671
|
+
fail(
|
|
672
|
+
"connectProvision: consent must be true or left out. An unticked box means no call at all; a call without consent makes an account nobody asked for"
|
|
673
|
+
);
|
|
674
|
+
}
|
|
675
|
+
const { email, emailVerified } = o;
|
|
676
|
+
if (email !== void 0 && (typeof email !== "string" || email === "")) {
|
|
677
|
+
fail("connectProvision: email must be a non-empty string");
|
|
678
|
+
}
|
|
679
|
+
if (emailVerified !== void 0 && typeof emailVerified !== "boolean") {
|
|
680
|
+
fail("connectProvision: emailVerified must be a boolean");
|
|
681
|
+
}
|
|
682
|
+
if (emailVerified !== void 0 && email === void 0) {
|
|
683
|
+
fail("connectProvision: emailVerified describes email, so pass email too");
|
|
684
|
+
}
|
|
685
|
+
const body = { user_id: o.userId };
|
|
686
|
+
if (o.consent === true) body.consent = true;
|
|
687
|
+
if (email !== void 0) body.email = email;
|
|
688
|
+
if (emailVerified !== void 0) body.email_verified = emailVerified;
|
|
689
|
+
return call("/api/connect/provision", o, body).then(
|
|
690
|
+
(answer) => {
|
|
691
|
+
const b = answer.body;
|
|
692
|
+
if (answer.status !== 200) return refused(answer, PROVISION_REASONS);
|
|
693
|
+
const good = b?.ok === true && typeof b.did_oc === "string" && DID_OC.test(b.did_oc) && typeof b.is_new === "boolean";
|
|
694
|
+
return good ? { ok: true, did_oc: b.did_oc, is_new: b.is_new } : { ok: false, reason: "unavailable", status: 200 };
|
|
695
|
+
}
|
|
696
|
+
);
|
|
697
|
+
}
|
|
698
|
+
function connectClaimLink(options) {
|
|
699
|
+
const o = checkCall("connectClaimLink", options, USER_KEYS);
|
|
700
|
+
return call("/api/connect/claim-link", o, { user_id: o.userId }).then(
|
|
701
|
+
(answer) => {
|
|
702
|
+
const b = answer.body;
|
|
703
|
+
if (answer.status !== 200) return refused(answer, CLAIM_LINK_REASONS);
|
|
704
|
+
const good = b?.ok === true && isClaimUrl(b.url) && typeof b.expires_at === "string" && b.expires_at !== "";
|
|
705
|
+
return good ? { ok: true, url: b.url, expires_at: b.expires_at } : { ok: false, reason: "unavailable", status: 200 };
|
|
706
|
+
}
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
function connectDelete(options) {
|
|
710
|
+
const o = checkCall("connectDelete", options, USER_KEYS);
|
|
711
|
+
return call("/api/connect/delete", o, { user_id: o.userId }).then(
|
|
712
|
+
(answer) => {
|
|
713
|
+
const b = answer.body;
|
|
714
|
+
if (answer.status !== 200) return refused(answer, DELETE_REASONS);
|
|
715
|
+
return b?.ok === true && typeof b.result === "string" && DELETE_RESULTS.has(b.result) ? { ok: true, result: b.result } : { ok: false, reason: "unavailable", status: 200 };
|
|
716
|
+
}
|
|
717
|
+
);
|
|
718
|
+
}
|
|
719
|
+
function call(path, o, body) {
|
|
720
|
+
return post(path, o.apiKey, body, o.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
721
|
+
}
|
|
722
|
+
function isClaimUrl(v) {
|
|
723
|
+
if (typeof v !== "string") return false;
|
|
724
|
+
try {
|
|
725
|
+
const url = new URL(v);
|
|
726
|
+
return url.protocol === "https:" && url.hostname === "ochk.app" && url.port === "" && url.username === "" && url.password === "";
|
|
727
|
+
} catch {
|
|
728
|
+
return false;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
// src/connect-consent.ts
|
|
733
|
+
var CONNECT_CONSENT_LABEL = "Also create my orangecheck account";
|
|
734
|
+
var CONNECT_CONSENT_BLURB = "It stays with orangecheck until you claim it at ochk.app. Then you can use it on other sites, or delete it.";
|
|
735
|
+
|
|
572
736
|
// src/server.ts
|
|
573
737
|
var sessionChecks = /* @__PURE__ */ new Map();
|
|
574
738
|
var warnedUnchecked = false;
|
|
@@ -801,8 +965,8 @@ function withOcAuth(handler, options = {}) {
|
|
|
801
965
|
const session = checked.status === "signed_in" ? checked.session : null;
|
|
802
966
|
const withSession = req;
|
|
803
967
|
withSession.ocSession = session;
|
|
804
|
-
const
|
|
805
|
-
if (
|
|
968
|
+
const refused2 = checked.status === "unavailable" ? UNAVAILABLE : await refusal(session, options);
|
|
969
|
+
if (refused2) return res.status(refused2.status).json(refused2.body);
|
|
806
970
|
return handler(withSession, res);
|
|
807
971
|
};
|
|
808
972
|
}
|
|
@@ -821,9 +985,9 @@ function ocAuthExpress(options = {}) {
|
|
|
821
985
|
);
|
|
822
986
|
const session = checked.status === "signed_in" ? checked.session : null;
|
|
823
987
|
req.ocSession = session;
|
|
824
|
-
const
|
|
825
|
-
if (
|
|
826
|
-
res.status(
|
|
988
|
+
const refused2 = checked.status === "unavailable" ? UNAVAILABLE : await refusal(session, options);
|
|
989
|
+
if (refused2) {
|
|
990
|
+
res.status(refused2.status).json(refused2.body);
|
|
827
991
|
return;
|
|
828
992
|
}
|
|
829
993
|
next();
|
|
@@ -843,8 +1007,8 @@ function ocAuthHono(options = {}) {
|
|
|
843
1007
|
});
|
|
844
1008
|
const session = checked.status === "signed_in" ? checked.session : null;
|
|
845
1009
|
c.set("ocSession", session);
|
|
846
|
-
const
|
|
847
|
-
if (
|
|
1010
|
+
const refused2 = checked.status === "unavailable" ? UNAVAILABLE : await refusal(session, options);
|
|
1011
|
+
if (refused2) return c.json(refused2.body, refused2.status);
|
|
848
1012
|
await next();
|
|
849
1013
|
};
|
|
850
1014
|
}
|
|
@@ -862,8 +1026,13 @@ Object.defineProperty(exports, "verifyOcToken", {
|
|
|
862
1026
|
get: function () { return authCore.verifyOcToken; }
|
|
863
1027
|
});
|
|
864
1028
|
exports.BACK_ACCOUNT_URL = BACK_ACCOUNT_URL;
|
|
1029
|
+
exports.CONNECT_CONSENT_BLURB = CONNECT_CONSENT_BLURB;
|
|
1030
|
+
exports.CONNECT_CONSENT_LABEL = CONNECT_CONSENT_LABEL;
|
|
865
1031
|
exports._resetSessionChecksForTests = _resetSessionChecksForTests;
|
|
866
1032
|
exports.checkOcSession = checkOcSession;
|
|
1033
|
+
exports.connectClaimLink = connectClaimLink;
|
|
1034
|
+
exports.connectDelete = connectDelete;
|
|
1035
|
+
exports.connectProvision = connectProvision;
|
|
867
1036
|
exports.getOcSession = getOcSession;
|
|
868
1037
|
exports.identity = identity;
|
|
869
1038
|
exports.ocAuthExpress = ocAuthExpress;
|