@orangecheck/me-client 0.52.0 → 0.53.1

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
@@ -1,11 +1,16 @@
1
- import { verifyOcToken as verifyOcToken$1, checkOcToken as checkOcToken$1, readOcSessionToken, SAFE_METHODS, familyRevocationCheck, integratorRevocationCheck, bondMeets, readBondClaim } from '@orangecheck/auth-core';
2
- export { bondMeets, readBondClaim } from '@orangecheck/auth-core';
1
+ import { verifyOcToken as verifyOcToken$1, checkOcToken as checkOcToken$1, readOcSessionToken, SAFE_METHODS, readBondNeed, familyRevocationCheck, integratorRevocationCheck, bondMeets, readBondClaim } from '@orangecheck/auth-core';
2
+ export { bondMeets, readBondClaim, readBondNeed } from '@orangecheck/auth-core';
3
3
  import { isDidOc } from '@orangecheck/auth-core/identifiers';
4
4
 
5
5
  var __defProp = Object.defineProperty;
6
6
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
7
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
8
 
9
+ // src/own-options.ts
10
+ function inheritedKeys(opts, known) {
11
+ return [...known].filter((k) => k in opts && !Object.prototype.hasOwnProperty.call(opts, k));
12
+ }
13
+
9
14
  // node_modules/jose/dist/webapi/lib/buffer_utils.js
10
15
  new TextEncoder();
11
16
  var decoder = new TextDecoder();
@@ -612,6 +617,8 @@ function checkCall(name, options, known) {
612
617
  const only = [...known].join(", ");
613
618
  fail(`${name}: unknown option ${unknown.join(", ")}. It reads only ${only}.`);
614
619
  }
620
+ const inherited = inheritedKeys(options, known);
621
+ if (inherited.length > 0) fail(`${name}: option ${inherited.join(", ")} is inherited, not set by the caller`);
615
622
  const o = Object.assign(/* @__PURE__ */ Object.create(null), options);
616
623
  if (typeof o.apiKey !== "string" || o.apiKey.trim() === "") {
617
624
  fail(`${name}: apiKey is required (your Connect API key)`);
@@ -790,6 +797,8 @@ function revokeToken(token, options = {}) {
790
797
  if (unknown.length > 0) {
791
798
  fail2(`revokeToken: unknown option ${unknown.join(", ")}. It reads only ${[...REVOKE_OPTIONS].join(", ")}.`);
792
799
  }
800
+ const inherited = inheritedKeys(options, REVOKE_OPTIONS);
801
+ if (inherited.length > 0) fail2(`revokeToken: option ${inherited.join(", ")} is inherited, not set by the caller`);
793
802
  const tokens = typeof token === "string" ? [token] : Array.isArray(token) ? [...token] : null;
794
803
  if (!tokens || tokens.length < 1 || tokens.length > MAX_TOKENS || !tokens.every((t) => typeof t === "string" && t.length > 0 && t.length <= MAX_TOKEN_LENGTH)) {
795
804
  fail2(`revokeToken: pass one token, or 1 to ${MAX_TOKENS}, each a non-empty string of at most ${MAX_TOKEN_LENGTH} characters`);
@@ -853,11 +862,13 @@ function fail3(message) {
853
862
  }
854
863
  async function exchangeNativeCode(input, options = {}) {
855
864
  if (input === null || typeof input !== "object") fail3("input must be an object");
856
- if ("projectKey" in input) {
865
+ if (Object.prototype.hasOwnProperty.call(input, "projectKey")) {
857
866
  fail3("projectKey is your own key: pass it in options, or set OC_PROJECT_KEY, never from the request");
858
867
  }
859
868
  const extra = Object.keys(input).filter((k) => !FIELDS.includes(k));
860
869
  if (extra.length > 0) fail3(`unknown input ${extra.join(", ")}. It reads only ${FIELDS.join(", ")}.`);
870
+ const inheritedInput = inheritedKeys(input, FIELDS);
871
+ if (inheritedInput.length > 0) fail3(`input ${inheritedInput.join(", ")} is inherited, not set by the caller`);
861
872
  for (const f of FIELDS) {
862
873
  const v = input[f];
863
874
  if (typeof v !== "string" || v.length === 0 || v.length > MAX_FIELD_LENGTH) {
@@ -868,6 +879,8 @@ async function exchangeNativeCode(input, options = {}) {
868
879
  if (options === null || typeof options !== "object") fail3("options must be an object");
869
880
  const unknown = Object.keys(options).filter((k) => !OPTIONS.has(k));
870
881
  if (unknown.length > 0) fail3(`unknown option ${unknown.join(", ")}. It reads only ${[...OPTIONS].join(", ")}.`);
882
+ const inherited = inheritedKeys(options, OPTIONS);
883
+ if (inherited.length > 0) fail3(`option ${inherited.join(", ")} is inherited, not set by the caller`);
871
884
  const projectKey = options.projectKey ?? (typeof process !== "undefined" ? process.env?.OC_PROJECT_KEY?.trim() : void 0);
872
885
  if (typeof projectKey !== "string" || projectKey.length === 0 || projectKey.length > MAX_FIELD_LENGTH) {
873
886
  fail3("needs your project key: options.projectKey, or OC_PROJECT_KEY");
@@ -1007,6 +1020,7 @@ async function verifyOcToken(token, options = {}) {
1007
1020
  if (options === null || typeof options !== "object") {
1008
1021
  throw new TypeError("@orangecheck/me-client: options must be an object");
1009
1022
  }
1023
+ refuseInherited("", options, KNOWN_OPTIONS);
1010
1024
  const { requireHandle, ...core } = options;
1011
1025
  checkRequireHandle(requireHandle);
1012
1026
  const session = await verifyOcToken$1(token, core);
@@ -1021,6 +1035,7 @@ async function checkOcToken(token, options = {}) {
1021
1035
  if (options === null || typeof options !== "object") {
1022
1036
  throw new TypeError("@orangecheck/me-client: options must be an object");
1023
1037
  }
1038
+ refuseInherited("", options, KNOWN_OPTIONS);
1024
1039
  const { requireHandle, ...core } = options;
1025
1040
  checkRequireHandle(requireHandle);
1026
1041
  const checked = await checkOcToken$1(token, core);
@@ -1145,6 +1160,12 @@ var KNOWN_OPTIONS = /* @__PURE__ */ new Set([
1145
1160
  "requireBond"
1146
1161
  ]);
1147
1162
  var BOND_OPTIONS = /* @__PURE__ */ new Set(["minSats", "minDays", "maxAgeSecs"]);
1163
+ function refuseInherited(where, opts, known) {
1164
+ const inherited = inheritedKeys(opts, known);
1165
+ if (inherited.length > 0) {
1166
+ throw new TypeError(`@orangecheck/me-client: ${where}option ${inherited.join(", ")} is inherited, not set by the caller`);
1167
+ }
1168
+ }
1148
1169
  function checkOptions(options) {
1149
1170
  if (options === null || typeof options !== "object") {
1150
1171
  throw new TypeError("@orangecheck/me-client: options must be an object");
@@ -1155,6 +1176,7 @@ function checkOptions(options) {
1155
1176
  `@orangecheck/me-client: unknown option ${unknown.join(", ")}. It reads only ${[...KNOWN_OPTIONS].join(", ")}.`
1156
1177
  );
1157
1178
  }
1179
+ refuseInherited("", options, KNOWN_OPTIONS);
1158
1180
  checkRequireHandle(options.requireHandle);
1159
1181
  const bond = options.requireBond;
1160
1182
  if (bond === void 0) return;
@@ -1167,6 +1189,12 @@ function checkOptions(options) {
1167
1189
  `@orangecheck/me-client: requireBond: unknown option ${extra.join(", ")}. It reads only ${[...BOND_OPTIONS].join(", ")}.`
1168
1190
  );
1169
1191
  }
1192
+ refuseInherited("requireBond: ", bond, BOND_OPTIONS);
1193
+ if (!readBondNeed(bond)) {
1194
+ throw new TypeError(
1195
+ "@orangecheck/me-client: requireBond: minSats, minDays and maxAgeSecs must each be left out or a whole number of 0 or more"
1196
+ );
1197
+ }
1170
1198
  }
1171
1199
  var BACK_ACCOUNT_URL = "https://ochk.app/me/account#backing";
1172
1200
  var stamp = () => ({ mono: performance.now(), wall: Date.now() });