@oxyhq/core 12.7.0 → 12.8.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.
@@ -11,6 +11,7 @@ const jwt_decode_1 = require("jwt-decode");
11
11
  const protocol_1 = require("@oxyhq/protocol");
12
12
  const apiUtils_1 = require("../utils/apiUtils");
13
13
  const logger_1 = require("../logger");
14
+ const oxyServiceEnvironment_1 = require("../utils/oxyServiceEnvironment");
14
15
  /**
15
16
  * Expected JWT audience for tokens issued by the Oxy auth service.
16
17
  */
@@ -42,6 +43,10 @@ class ServiceTokenClaimError extends Error {
42
43
  this.name = 'ServiceTokenClaimError';
43
44
  }
44
45
  }
46
+ function isOxyServiceEnvironment(value) {
47
+ return (typeof value === 'string' &&
48
+ oxyServiceEnvironment_1.OXY_SERVICE_ENVIRONMENTS.includes(value));
49
+ }
45
50
  function OxyServicesUtilityMixin(Base) {
46
51
  return class extends Base {
47
52
  // TypeScript's mixin pattern requires `(...args: any[])` here — the
@@ -338,7 +343,11 @@ function OxyServicesUtilityMixin(Base) {
338
343
  // Validate required service token fields
339
344
  const appId = decoded.appId;
340
345
  const credentialId = decoded.credentialId;
341
- if (!appId || typeof credentialId !== 'string' || credentialId.length === 0) {
346
+ const environment = decoded.environment;
347
+ if (!appId ||
348
+ typeof credentialId !== 'string' ||
349
+ credentialId.length === 0 ||
350
+ !isOxyServiceEnvironment(environment)) {
342
351
  if (optional) {
343
352
  req.userId = null;
344
353
  req.user = null;
@@ -391,6 +400,7 @@ function OxyServicesUtilityMixin(Base) {
391
400
  appName: decoded.appName || 'unknown',
392
401
  credentialId,
393
402
  scopes: Array.isArray(decoded.scopes) ? decoded.scopes : [],
403
+ environment,
394
404
  };
395
405
  if (debug) {
396
406
  logger_1.logger.debug(`[oxy.auth] Service token OK app=${decoded.appName} delegateUser=${oxyUserId || '(none)'}`, {
@@ -1,11 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OXY_SERVICE_ENVIRONMENTS = void 0;
3
4
  exports.getOxyUserId = getOxyUserId;
4
5
  exports.isOxyAuthenticated = isOxyAuthenticated;
5
6
  exports.getRequiredOxyUserId = getRequiredOxyUserId;
6
7
  exports.requireOxyAuth = requireOxyAuth;
7
8
  exports.createOptionalOxyAuth = createOptionalOxyAuth;
8
9
  exports.createOxyAuthMiddleware = createOxyAuthMiddleware;
10
+ const oxyServiceEnvironment_1 = require("../utils/oxyServiceEnvironment");
11
+ Object.defineProperty(exports, "OXY_SERVICE_ENVIRONMENTS", { enumerable: true, get: function () { return oxyServiceEnvironment_1.OXY_SERVICE_ENVIRONMENTS; } });
9
12
  function normalizeId(value) {
10
13
  const normalized = value?.trim();
11
14
  return normalized && normalized.length > 0 ? normalized : null;
@@ -16,7 +16,7 @@
16
16
  * ```
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.parseHubSyncReturnUrl = exports.normalizeOfficialReturnOrigin = exports.isOfficialWebOrigin = exports.isIdpHubOrigin = exports.buildHubSyncUrl = exports.buildIdpHubOrigin = exports.registrableApex = exports.verifySecret = exports.createOxyCors = exports.UPSTREAM_HEADERS_TIMEOUT_MS = exports.MAX_URL_LENGTH = exports.MAX_REDIRECTS = exports.DEFAULT_USER_AGENT = exports.BLOCKED_HOSTNAMES = exports.ALLOWED_PROTOCOLS = exports.ALLOWED_PORTS = exports.UpstreamError = exports.SsrfRejection = exports.safeFetch = exports.isBlockedIp = exports.assertSafePublicUrl = exports.createOxyRateLimit = exports.requireOxyAuth = exports.isOxyAuthenticated = exports.getRequiredOxyUserId = exports.getOxyUserId = exports.createOxyAuthMiddleware = exports.createOptionalOxyAuth = void 0;
19
+ exports.parseHubSyncReturnUrl = exports.normalizeOfficialReturnOrigin = exports.isOfficialWebOrigin = exports.isIdpHubOrigin = exports.buildHubSyncUrl = exports.buildIdpHubOrigin = exports.registrableApex = exports.verifySecret = exports.createOxyCors = exports.UPSTREAM_HEADERS_TIMEOUT_MS = exports.MAX_URL_LENGTH = exports.MAX_REDIRECTS = exports.DEFAULT_USER_AGENT = exports.BLOCKED_HOSTNAMES = exports.ALLOWED_PROTOCOLS = exports.ALLOWED_PORTS = exports.UpstreamError = exports.SsrfRejection = exports.safeFetch = exports.isBlockedIp = exports.assertSafePublicUrl = exports.createOxyRateLimit = exports.OXY_SERVICE_ENVIRONMENTS = exports.requireOxyAuth = exports.isOxyAuthenticated = exports.getRequiredOxyUserId = exports.getOxyUserId = exports.createOxyAuthMiddleware = exports.createOptionalOxyAuth = void 0;
20
20
  var auth_1 = require("./auth");
21
21
  Object.defineProperty(exports, "createOptionalOxyAuth", { enumerable: true, get: function () { return auth_1.createOptionalOxyAuth; } });
22
22
  Object.defineProperty(exports, "createOxyAuthMiddleware", { enumerable: true, get: function () { return auth_1.createOxyAuthMiddleware; } });
@@ -24,6 +24,7 @@ Object.defineProperty(exports, "getOxyUserId", { enumerable: true, get: function
24
24
  Object.defineProperty(exports, "getRequiredOxyUserId", { enumerable: true, get: function () { return auth_1.getRequiredOxyUserId; } });
25
25
  Object.defineProperty(exports, "isOxyAuthenticated", { enumerable: true, get: function () { return auth_1.isOxyAuthenticated; } });
26
26
  Object.defineProperty(exports, "requireOxyAuth", { enumerable: true, get: function () { return auth_1.requireOxyAuth; } });
27
+ Object.defineProperty(exports, "OXY_SERVICE_ENVIRONMENTS", { enumerable: true, get: function () { return auth_1.OXY_SERVICE_ENVIRONMENTS; } });
27
28
  var rateLimit_1 = require("./rateLimit");
28
29
  Object.defineProperty(exports, "createOxyRateLimit", { enumerable: true, get: function () { return rateLimit_1.createOxyRateLimit; } });
29
30
  // SSRF-safe upstream fetch + URL validation (Node-only).
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OXY_SERVICE_ENVIRONMENTS = void 0;
4
+ /**
5
+ * Environment segregation for Oxy service-token JWTs (test/live isolation).
6
+ * Mirrors `ApplicationCredentialEnvironment` on the API's `ApplicationCredential`
7
+ * model (`packages/api/src/models/ApplicationCredential.ts`) as an INDEPENDENT
8
+ * literal union — `@oxyhq/core` has zero dependency on `@oxyhq/api`, so this is
9
+ * kept in sync by hand, not by import.
10
+ *
11
+ * Defined here (not in `server/auth.ts` or `mixins/OxyServices.utility.ts`
12
+ * directly) because BOTH of those files need it and neither may import from
13
+ * the other: `server/` types import `express` (Node-only, a peer dependency
14
+ * `mixins/` deliberately avoids so it stays safe to bundle into RN/browser
15
+ * consumers — see the "Local request/response/socket typing" comment in
16
+ * `OxyServices.utility.ts`). This file has zero imports, so both sides can
17
+ * depend on it without crossing that boundary.
18
+ */
19
+ exports.OXY_SERVICE_ENVIRONMENTS = ['development', 'staging', 'production'];