@xemahq/platform-common 0.2.20 → 0.2.21

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.
@@ -1,6 +1,6 @@
1
- import { AdapterKey, ConnectorKind, WebhookEntityKind } from '../../lib/integration-webhooks';
1
+ import { AdapterKey, WebhookEntityKind } from '../../lib/integration-webhooks';
2
2
  export declare class IntegrationWebhookEnvelopeDto<TPayload = unknown> {
3
- provider: ConnectorKind;
3
+ provider: string;
4
4
  adapterKey: AdapterKey;
5
5
  event: string;
6
6
  entityKind: WebhookEntityKind;
@@ -1 +1 @@
1
- {"version":3,"file":"integration-webhook-envelope.dto.d.ts","sourceRoot":"","sources":["../../../src/nestjs/integration-webhooks/integration-webhook-envelope.dto.ts"],"names":[],"mappings":"AASA,OAAO,EACL,UAAU,EACV,aAAa,EACb,iBAAiB,EAClB,MAAM,gCAAgC,CAAC;AAqBxC,qBAAa,6BAA6B,CAAC,QAAQ,GAAG,OAAO;IAQ3D,QAAQ,EAAG,aAAa,CAAC;IASzB,UAAU,EAAG,UAAU,CAAC;IAQxB,KAAK,EAAG,MAAM,CAAC;IAIf,UAAU,EAAG,iBAAiB,CAAC;IAQ/B,UAAU,EAAG,MAAM,CAAC;IAOpB,UAAU,EAAG,MAAM,CAAC;IAQpB,aAAa,EAAG,MAAM,CAAC;IASvB,UAAU,CAAC,EAAE,MAAM,CAAC;IASpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAK1B,OAAO,EAAG,QAAQ,CAAC;CACpB"}
1
+ {"version":3,"file":"integration-webhook-envelope.dto.d.ts","sourceRoot":"","sources":["../../../src/nestjs/integration-webhooks/integration-webhook-envelope.dto.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,UAAU,EACV,iBAAiB,EAClB,MAAM,gCAAgC,CAAC;AAqBxC,qBAAa,6BAA6B,CAAC,QAAQ,GAAG,OAAO;IAa3D,QAAQ,EAAG,MAAM,CAAC;IASlB,UAAU,EAAG,UAAU,CAAC;IAQxB,KAAK,EAAG,MAAM,CAAC;IAIf,UAAU,EAAG,iBAAiB,CAAC;IAQ/B,UAAU,EAAG,MAAM,CAAC;IAOpB,UAAU,EAAG,MAAM,CAAC;IAQpB,aAAa,EAAG,MAAM,CAAC;IASvB,UAAU,CAAC,EAAE,MAAM,CAAC;IASpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAK1B,OAAO,EAAG,QAAQ,CAAC;CACpB"}
@@ -28,12 +28,16 @@ class IntegrationWebhookEnvelopeDto {
28
28
  exports.IntegrationWebhookEnvelopeDto = IntegrationWebhookEnvelopeDto;
29
29
  __decorate([
30
30
  (0, swagger_1.ApiProperty)({
31
- enum: integration_webhooks_1.ConnectorKind,
32
- enumName: 'ConnectorKind',
33
- description: 'External provider that emitted the webhook.',
34
- example: integration_webhooks_1.ConnectorKind.GITHUB,
31
+ type: String,
32
+ description: 'Open provider key of the external provider that emitted the webhook. ' +
33
+ 'Any curated ConnectorKind value (e.g. "GITHUB") OR a contributed ' +
34
+ 'provider key (UPPER_SNAKE) is valid — validity is enforced at the ' +
35
+ 'ingress seam by the connector registry (assertKnownConnectionProviderKey), ' +
36
+ 'not by this DTO. See the H1 open-provider design.',
37
+ example: 'GITHUB',
35
38
  }),
36
- (0, class_validator_1.IsEnum)(integration_webhooks_1.ConnectorKind),
39
+ (0, class_validator_1.IsString)(),
40
+ (0, class_validator_1.IsNotEmpty)(),
37
41
  __metadata("design:type", String)
38
42
  ], IntegrationWebhookEnvelopeDto.prototype, "provider", void 0);
39
43
  __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"integration-webhook-envelope.dto.js","sourceRoot":"","sources":["../../../src/nestjs/integration-webhooks/integration-webhook-envelope.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAAmE;AACnE,qDAMyB;AAEzB,yEAIwC;AAqBxC,MAAa,6BAA6B;IAQxC,QAAQ,CAAiB;IASzB,UAAU,CAAc;IAQxB,KAAK,CAAU;IAIf,UA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AE;IACZ,IAAA,0BAAQ,GAAE;;uEACe"}
1
+ {"version":3,"file":"integration-webhook-envelope.dto.js","sourceRoot":"","sources":["../../../src/nestjs/integration-webhooks/integration-webhook-envelope.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAAmE;AACnE,qDAOyB;AAEzB,yEAGwC;AAqBxC,MAAa,6BAA6B;IAaxC,QAAQ,CAAU;IASlB,UAAU,CAAc;IAQxB,KAAK,CAAU;IAIf,UAAU,CAAqB;IAQ/B,UAAU,CAAU;IAOpB,UAAU,CAAU;IAQpB,aAAa,CAAU;IASvB,UAAU,CAAU;IASpB,gBAAgB,CAAU;IAK1B,OAAO,CAAY;CACpB;AAjFD,sEAiFC;AApEC;IAZC,IAAA,qBAAW,EAAC;QACX,IAAI,EAAE,MAAM;QACZ,WAAW,EACT,uEAAuE;YACvE,mEAAmE;YACnE,oEAAoE;YACpE,6EAA6E;YAC7E,mDAAmD;QACrD,OAAO,EAAE,QAAQ;KAClB,CAAC;IACD,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;+DACK;AASlB;IADC,IAAA,wBAAM,EAAC,iCAAU,CAAC;;iEACK;AAQxB;IANC,IAAA,qBAAW,EAAC;QACX,WAAW,EACT,2HAA2H;QAC7H,OAAO,EAAE,kBAAkB;KAC5B,CAAC;IACD,IAAA,0BAAQ,GAAE;;4DACI;AAIf;IADC,IAAA,wBAAM,EAAC,wCAAiB,CAAC;;iEACK;AAQ/B;IANC,IAAA,qBAAW,EAAC;QACX,WAAW,EACT,yHAAyH;QAC3H,OAAO,EAAE,sCAAsC;KAChD,CAAC;IACD,IAAA,0BAAQ,GAAE;;iEACS;AAOpB;IALC,IAAA,qBAAW,EAAC;QACX,WAAW,EAAE,0DAA0D;QACvE,OAAO,EAAE,0BAA0B;KACpC,CAAC;IACD,IAAA,2BAAS,GAAE;;iEACQ;AAQpB;IANC,IAAA,qBAAW,EAAC;QACX,WAAW,EACT,uFAAuF;QACzF,OAAO,EAAE,sCAAsC;KAChD,CAAC;IACD,IAAA,wBAAM,GAAE;;oEACc;AASvB;IAPC,IAAA,6BAAmB,EAAC;QACnB,WAAW,EACT,4EAA4E;QAC9E,OAAO,EAAE,WAAW;KACrB,CAAC;IACD,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;iEACS;AASpB;IAPC,IAAA,6BAAmB,EAAC;QACnB,WAAW,EACT,gGAAgG;QAClG,OAAO,EAAE,cAAc;KACxB,CAAC;IACD,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;uEACe"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xemahq/platform-common",
3
- "version": "0.2.20",
3
+ "version": "0.2.21",
4
4
  "description": "Shared NestJS building blocks for Xema services — auth guards, response redaction, CORS configuration, and crypto helpers.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Neuralchowder Inc. <developer@xema.dev> (https://xema.dev)",
@@ -1,7 +0,0 @@
1
- export declare class IssuerMetadataResolver {
2
- private readonly cacheTtlMs;
3
- private readonly cache;
4
- constructor(cacheTtlMs?: number);
5
- resolveJwksUri(discoveryUrl: string): Promise<string>;
6
- }
7
- //# sourceMappingURL=issuer-metadata-resolver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"issuer-metadata-resolver.d.ts","sourceRoot":"","sources":["../../../src/nestjs/jwks/issuer-metadata-resolver.ts"],"names":[],"mappings":"AAuBA,qBAAa,sBAAsB;IAOrB,OAAO,CAAC,QAAQ,CAAC,UAAU;IANvC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA6D;gBAMtD,UAAU,GAAE,MAAkB;IAOrD,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAgC5D"}
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IssuerMetadataResolver = void 0;
4
- const jwks_verifier_1 = require("./jwks-verifier");
5
- class IssuerMetadataResolver {
6
- cacheTtlMs;
7
- cache = new Map();
8
- constructor(cacheTtlMs = 3_600_000) {
9
- this.cacheTtlMs = cacheTtlMs;
10
- }
11
- async resolveJwksUri(discoveryUrl) {
12
- const cached = this.cache.get(discoveryUrl);
13
- if (cached && Date.now() - cached.fetchedAt < this.cacheTtlMs) {
14
- return cached.jwksUri;
15
- }
16
- let response;
17
- try {
18
- response = await fetch(discoveryUrl);
19
- }
20
- catch (error) {
21
- const msg = error instanceof Error ? error.message : String(error);
22
- throw new jwks_verifier_1.JwksVerificationError(`Failed to reach OIDC discovery endpoint ${discoveryUrl}: ${msg}`);
23
- }
24
- if (!response.ok) {
25
- throw new jwks_verifier_1.JwksVerificationError(`Failed to fetch OIDC discovery from ${discoveryUrl}: ${response.status}`);
26
- }
27
- const doc = (await response.json());
28
- if (typeof doc.jwks_uri !== 'string' || doc.jwks_uri.length === 0) {
29
- throw new jwks_verifier_1.JwksVerificationError(`OIDC discovery at ${discoveryUrl} did not provide a jwks_uri`);
30
- }
31
- this.cache.set(discoveryUrl, { jwksUri: doc.jwks_uri, fetchedAt: Date.now() });
32
- return doc.jwks_uri;
33
- }
34
- }
35
- exports.IssuerMetadataResolver = IssuerMetadataResolver;
36
- //# sourceMappingURL=issuer-metadata-resolver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"issuer-metadata-resolver.js","sourceRoot":"","sources":["../../../src/nestjs/jwks/issuer-metadata-resolver.ts"],"names":[],"mappings":";;;AAAA,mDAAwD;AAuBxD,MAAa,sBAAsB;IAOJ;IANZ,KAAK,GAAG,IAAI,GAAG,EAAkD,CAAC;IAMnF,YAA6B,aAAqB,SAAS;QAA9B,eAAU,GAAV,UAAU,CAAoB;IAAG,CAAC;IAO/D,KAAK,CAAC,cAAc,CAAC,YAAoB;QACvC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAC5C,IAAI,MAAM,IAAI,IAAI,C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- iss?: string;
8
- sub?: string;
9
- exp?: number;
10
- iat?: number;
11
- nbf?: number;
12
- aud?: string | string[];
13
- [key: string]: unknown;
14
- }
15
- export interface Jwk {
16
- kty: string;
17
- kid: string;
18
- use?: string;
19
- n?: string;
20
- e?: string;
21
- x5c?: string[];
22
- alg?: string;
23
- }
24
- export declare class JwksVerificationError extends Error {
25
- constructor(message: string);
26
- }
27
- export interface JwksVerifyOptions {
28
- jwksUrl: string;
29
- cacheKey: string;
30
- expectedIssuers?: readonly string[];
31
- }
32
- export declare class JwksVerifier {
33
- private readonly cacheTtlMs;
34
- private readonly caches;
35
- constructor(cacheTtlMs?: number);
36
- decode(jwt: string): {
37
- header: DecodedJwtHeader;
38
- payload: DecodedJwtPayload;
39
- };
40
- verify(jwt: string, options: JwksVerifyOptions): Promise<DecodedJwtPayload>;
41
- private assertIssuer;
42
- private verifySignature;
43
- private getSigningKey;
44
- private fetchJwks;
45
- private resolveKey;
46
- private mapAlgorithm;
47
- }
48
- //# sourceMappingURL=jwks-verifier.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jwks-verifier.d.ts","sourceRoot":"","sources":["../../../src/nestjs/jwks/jwks-verifier.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAOD,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAMD,MAAM,WAAW,GAAG;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAuBD,qBAAa,qBAAsB,SAAQ,KAAK;gBAClC,OAAO,EAAE,MAAM;CAI5B;AAKD,MAAM,WAAW,iBAAiB;IAKhC,OAAO,EAAE,MAAM,CAAC;IAMhB,QAAQ,EAAE,MAAM,CAAC;IASjB,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAkBD,qBAAa,YAAY;IASX,OAAO,CAAC,QAAQ,CAAC,UAAU;IAPvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoC;gBAO9B,UAAU,GAAE,MAAgB;IAQzD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,MAAM,EAAE,gBAAgB,CAAC;QAAC,OAAO,EAAE,iBAAiB,CAAA;KAAE;IAyBvE,MAAM,CACV,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,iBAAiB,CAAC;IAoC7B,OAAO,CAAC,YAAY;IAsBpB,OAAO,CAAC,eAAe;YAqBT,aAAa;YAsBb,SAAS;IAiCvB,OAAO,CAAC,UAAU;IAkBlB,OAAO,CAAC,YAAY;CAYrB"}
@@ -1,177 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.JwksVerifier = exports.JwksVerificationError = void 0;
37
- const crypto = __importStar(require("node:crypto"));
38
- class JwksVerificationError extends Error {
39
- constructor(message) {
40
- super(message);
41
- this.name = 'JwksVerificationError';
42
- }
43
- }
44
- exports.JwksVerificationError = JwksVerificationError;
45
- class JwksVerifier {
46
- cacheTtlMs;
47
- caches = new Map();
48
- constructor(cacheTtlMs = 600_000) {
49
- this.cacheTtlMs = cacheTtlMs;
50
- }
51
- decode(jwt) {
52
- const [headerB64, payloadB64, signatureB64] = jwt.split('.');
53
- if (!headerB64 || !payloadB64 || !signatureB64) {
54
- throw new JwksVerificationError('Invalid token format');
55
- }
56
- let header;
57
- let payload;
58
- try {
59
- header = JSON.parse(Buffer.from(headerB64, 'base64url').toString('utf8'));
60
- payload = JSON.parse(Buffer.from(payloadB64, 'base64url').toString('utf8'));
61
- }
62
- catch {
63
- throw new JwksVerificationError('Invalid token format');
64
- }
65
- return { header, payload };
66
- }
67
- async verify(jwt, options) {
68
- const [headerB64, payloadB64, signatureB64] = jwt.split('.');
69
- if (!headerB64 || !payloadB64 || !signatureB64) {
70
- throw new JwksVerificationError('Invalid token format');
71
- }
72
- const { header, payload } = this.decode(jwt);
73
- const nowMs = Date.now();
74
- if (typeof payload.exp === 'number' && nowMs >= payload.exp * 1000) {
75
- throw new JwksVerificationError('Token expired');
76
- }
77
- if (typeof payload.nbf === 'number' && nowMs < payload.nbf * 1000) {
78
- throw new JwksVerificationError('Token not yet valid');
79
- }
80
- if (options.expectedIssuers && options.expectedIssuers.length > 0) {
81
- this.assertIssuer(payload.iss, options.expectedIssuers);
82
- }
83
- const publicKey = await this.getSigningKey(options.cacheKey, options.jwksUrl, header.kid);
84
- this.verifySignature(headerB64, payloadB64, signatureB64, header.alg, publicKey);
85
- return payload;
86
- }
87
- assertIssuer(iss, expectedIssuers) {
88
- if (!iss) {
89
- throw new JwksVerificationError('Token missing required issuer claim');
90
- }
91
- const realmSuffixes = [
92
- ...new Set(expectedIssuers
93
- .map((candidate) => candidate.match(/(\/realms\/[^/]+)$/)?.[1])
94
- .filter((suffix) => Boolean(suffix))),
95
- ];
96
- const matched = expectedIssuers.includes(iss) ||
97
- realmSuffixes.some((suffix) => iss.endsWith(suffix));
98
- if (!matched) {
99
- throw new JwksVerificationError('Invalid token issuer');
100
- }
101
- }
102
- verifySignature(headerB64, payloadB64, signatureB64, alg, publicKey) {
103
- const data = `${headerB64}.${payloadB64}`;
104
- const signature = Buffer.from(signatureB64, 'base64url');
105
- const algorithm = this.mapAlgorithm(alg);
106
- const isValid = crypto.verify(algorithm, Buffer.from(data), publicKey, signature);
107
- if (!isValid) {
108
- throw new JwksVerificationError('Invalid token signature');
109
- }
110
- }
111
- async getSigningKey(cacheKey, jwksUrl, kid) {
112
- let cache = this.caches.get(cacheKey);
113
- if (cache &&
114
- kid &&
115
- cache.keys.has(kid) &&
116
- Date.now() - cache.lastFetch < this.cacheTtlMs) {
117
- return cache.keys.get(kid);
118
- }
119
- const keys = await this.fetchJwks(jwksUrl);
120
- cache = { keys, lastFetch: Date.now() };
121
- this.caches.set(cacheKey, cache);
122
- return this.resolveKey(cache, kid);
123
- }
124
- async fetchJwks(jwksUrl) {
125
- let response;
126
- try {
127
- response = await fetch(jwksUrl);
128
- }
129
- catch (error) {
130
- const msg = error instanceof Error ? error.message : String(error);
131
- throw new JwksVerificationError(`Failed to reach JWKS endpoint ${jwksUrl}: ${msg}`);
132
- }
133
- if (!response.ok) {
134
- throw new JwksVerificationError(`Failed to fetch JWKS from ${jwksUrl}: ${response.status}`);
135
- }
136
- const jwks = (await response.json());
137
- const keys = new Map();
138
- for (const key of jwks.keys) {
139
- if (key.kty === 'RSA' && key.n && key.e) {
140
- const publicKey = crypto.createPublicKey({
141
- key: { kty: 'RSA', n: key.n, e: key.e },
142
- format: 'jwk',
143
- });
144
- keys.set(key.kid, publicKey);
145
- }
146
- }
147
- return keys;
148
- }
149
- resolveKey(cache, kid) {
150
- if (kid) {
151
- const key = cache.keys.get(kid);
152
- if (!key) {
153
- throw new JwksVerificationError(`Signing key not found for kid: ${kid}`);
154
- }
155
- return key;
156
- }
157
- const firstKey = cache.keys.values().next().value;
158
- if (!firstKey) {
159
- throw new JwksVerificationError('No valid signing keys found in JWKS');
160
- }
161
- return firstKey;
162
- }
163
- mapAlgorithm(alg) {
164
- switch (alg) {
165
- case 'RS256':
166
- return 'sha256';
167
- case 'RS384':
168
- return 'sha384';
169
- case 'RS512':
170
- return 'sha512';
171
- default:
172
- throw new JwksVerificationError(`Unsupported JWT algorithm: ${alg}`);
173
- }
174
- }
175
- }
176
- exports.JwksVerifier = JwksVerifier;
177
- //# sourceMappingURL=jwks-verifier.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jwks-verifier.js","sourceRoot":"","sources":["../../../src/nestjs/jwks/jwks-verifier.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsC;AA6DtC,MAAa,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,I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UTE = "xema:public-route";
2
- export declare const XEMA_INTERNAL_ROUTE = "xema:internal-route";
3
- //# sourceMappingURL=route-metadata-keys.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"route-metadata-keys.d.ts","sourceRoot":"","sources":["../../src/nestjs/route-metadata-keys.ts"],"names":[],"mappings":"AAwBA,eAAO,MAAM,iBAAiB,sBAAsB,CAAC;AAGrD,eAAO,MAAM,mBAAmB,wBAAwB,CAAC"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.XEMA_INTERNAL_ROUTE = exports.XEMA_PUBLIC_ROUTE = void 0;
4
- exports.XEMA_PUBLIC_ROUTE = 'xema:public-route';
5
- exports.XEMA_INTERNAL_ROUTE = 'xema:internal-route';
6
- //# sourceMappingURL=route-metadata-keys.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"route-metadata-keys.js","sourceRoot":"","sources":["../../src/nestjs/route-metadata-keys.ts"],"names":[],"mappings":";;;AAwBa,QAAA,iBAAiB,GAAG,mBAAmB,CAAC;AAGxC,QAAA,mBAAmB,GAAG,qBAAqB,CAAC"}