@orangecheck/me-client 0.42.0 → 0.43.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/server.mjs CHANGED
@@ -837,6 +837,11 @@ async function post2(url, tokens, timeoutMs) {
837
837
  }
838
838
 
839
839
  // src/server.ts
840
+ var VERIFIED = /* @__PURE__ */ new WeakSet();
841
+ function vouch(session) {
842
+ VERIFIED.add(session);
843
+ return session;
844
+ }
840
845
  function lacksHandle(session, requireHandle) {
841
846
  if (requireHandle === false) return false;
842
847
  const { aud, rh } = session;
@@ -868,7 +873,7 @@ async function verifyOcToken(token, options = {}) {
868
873
  warnNoHandle(session);
869
874
  return null;
870
875
  }
871
- return session;
876
+ return vouch(session);
872
877
  }
873
878
  async function checkOcToken(token, options = {}) {
874
879
  if (options === null || typeof options !== "object") {
@@ -883,7 +888,7 @@ async function checkOcToken(token, options = {}) {
883
888
  warnNoHandle(checked.session);
884
889
  return { status: "invalid", reason: "no_session_handle" };
885
890
  }
886
- return { status: "valid", session: checked.session };
891
+ return { status: "valid", session: vouch(checked.session) };
887
892
  }
888
893
  var sessionChecks = /* @__PURE__ */ new Map();
889
894
  var warnedUnchecked = false;
@@ -943,7 +948,7 @@ async function checkOcSession(headers, options = {}) {
943
948
  return { status: "unavailable", reason: "revocations_unavailable" };
944
949
  }
945
950
  }
946
- return { status: "signed_in", session };
951
+ return { status: "signed_in", session: vouch(session) };
947
952
  }
948
953
  var unavailable = (checked) => ({
949
954
  status: 503,
@@ -1113,6 +1118,33 @@ async function refusal(session, options, why) {
1113
1118
  }
1114
1119
  return null;
1115
1120
  }
1121
+ var SIGN_IN_RULE_OPTIONS = /* @__PURE__ */ new Set([
1122
+ "projectKey",
1123
+ "meOrigin",
1124
+ "requireBond"
1125
+ ]);
1126
+ async function checkSignInRule(session, options) {
1127
+ if (options === null || typeof options !== "object") {
1128
+ throw new TypeError("@orangecheck/me-client: options must be an object");
1129
+ }
1130
+ const unknown = Object.keys(options).filter((k) => !SIGN_IN_RULE_OPTIONS.has(k));
1131
+ if (unknown.length > 0) {
1132
+ throw new TypeError(
1133
+ `@orangecheck/me-client: unknown option ${unknown.join(", ")}. It reads only ${[...SIGN_IN_RULE_OPTIONS].join(", ")}.`
1134
+ );
1135
+ }
1136
+ checkOptions(options);
1137
+ if (!options.projectKey && !options.requireBond) {
1138
+ throw new TypeError("@orangecheck/me-client: checkSignInRule needs projectKey or requireBond");
1139
+ }
1140
+ if (session === null || typeof session !== "object" || !VERIFIED.has(session)) {
1141
+ throw new TypeError(
1142
+ "@orangecheck/me-client: checkSignInRule takes the session verifyOcToken, checkOcToken or getOcSession returned, as is, not claims read some other way"
1143
+ );
1144
+ }
1145
+ const refused2 = await refusal(session, options);
1146
+ return refused2 ? { ok: false, status: refused2.status, body: refused2.body } : { ok: true };
1147
+ }
1116
1148
  function withOcAuth(handler, options = {}) {
1117
1149
  checkOptions(options);
1118
1150
  return async (req, res) => {
@@ -1176,6 +1208,6 @@ function ocAuthHono(options = {}) {
1176
1208
  };
1177
1209
  }
1178
1210
 
1179
- export { BACK_ACCOUNT_URL, CONNECT_CONSENT_BLURB, CONNECT_CONSENT_LABEL, MemoryJtiStore, _resetSessionChecksForTests, checkOcSession, checkOcToken, connectClaimLink, connectDelete, connectProvision, getOcSession, identity, ocAuthExpress, ocAuthHono, refreshEnvelopeJwks, revokeToken, spendOnce, verifyActivityAttestation, verifyOcToken, withOcAuth };
1211
+ export { BACK_ACCOUNT_URL, CONNECT_CONSENT_BLURB, CONNECT_CONSENT_LABEL, MemoryJtiStore, _resetSessionChecksForTests, checkOcSession, checkOcToken, checkSignInRule, connectClaimLink, connectDelete, connectProvision, getOcSession, identity, ocAuthExpress, ocAuthHono, refreshEnvelopeJwks, revokeToken, spendOnce, verifyActivityAttestation, verifyOcToken, withOcAuth };
1180
1212
  //# sourceMappingURL=server.mjs.map
1181
1213
  //# sourceMappingURL=server.mjs.map