@lucaapp/service-utils 4.7.0 → 4.9.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.
@@ -3,6 +3,7 @@ export type Location = {
3
3
  groupId?: string;
4
4
  timezone?: string;
5
5
  scannerId?: string;
6
+ country?: string;
6
7
  createdAt: Date;
7
8
  updatedAt: Date;
8
9
  };
@@ -38,7 +38,7 @@ declare class ServiceIdentity {
38
38
  }>;
39
39
  getIdentityJWKS: () => Promise<JWKS>;
40
40
  requireServiceIdentity: (service: string) => RequestHandler;
41
- requireServiceIdentityV3: (service: string) => import("../api/types/middleware").Middleware<never[], undefined, undefined, undefined, z.ZodObject<{
41
+ requireServiceIdentityV3: (...services: string[]) => import("../api/types/middleware").Middleware<never[], undefined, undefined, undefined, z.ZodObject<{
42
42
  'x-identity': z.ZodEffects<z.ZodString, string, string>;
43
43
  }, "strip", z.ZodTypeAny, {
44
44
  'x-identity': string;
@@ -142,7 +142,7 @@ class ServiceIdentity {
142
142
  request.body = payload.data;
143
143
  next();
144
144
  };
145
- this.requireServiceIdentityV3 = (service) => (0, api_1.createMiddleware)({
145
+ this.requireServiceIdentityV3 = (...services) => (0, api_1.createMiddleware)({
146
146
  schemas: {
147
147
  headers: zod_1.z.object({
148
148
  'x-identity': zod_1.z.string().refine(value => validator_1.default.isJWT(value)),
@@ -161,9 +161,19 @@ class ServiceIdentity {
161
161
  if (typeof jwt !== 'string') {
162
162
  throw new ServiceIdentityError(ServiceIdentityErrorType.NO_JWT_PROVIDED);
163
163
  }
164
- const { payload } = await jose.jwtVerify(jwt, this.getRemoteJWKS(service), this.getJwtVerifyOptions(service));
165
- if (request.originalUrl !== payload.url) {
166
- throw new ServiceIdentityError(ServiceIdentityErrorType.URL_MISMATCH, `${originalUrl} !== ${payload.url}`);
164
+ let payload = null;
165
+ for (const service of services) {
166
+ try {
167
+ const response = await jose.jwtVerify(jwt, this.getRemoteJWKS(service), this.getJwtVerifyOptions(service));
168
+ payload = response.payload;
169
+ break;
170
+ }
171
+ catch (error) {
172
+ continue;
173
+ }
174
+ }
175
+ if (request.originalUrl !== payload?.url) {
176
+ throw new ServiceIdentityError(ServiceIdentityErrorType.URL_MISMATCH, `${originalUrl} !== ${payload?.url}`);
167
177
  }
168
178
  if (method !== payload.method) {
169
179
  throw new ServiceIdentityError(ServiceIdentityErrorType.METHOD_MISMATCH, `${method} !== ${payload.method}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucaapp/service-utils",
3
- "version": "4.7.0",
3
+ "version": "4.9.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [