@n8n/engine 0.16.2 → 0.18.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/auth/action-token.d.ts +7 -0
- package/dist/auth/action-token.js +30 -0
- package/dist/auth/action-token.js.map +1 -0
- package/dist/auth/authenticate.d.ts +4 -0
- package/dist/auth/authenticate.js +30 -0
- package/dist/auth/authenticate.js.map +1 -0
- package/dist/auth/identity-token.d.ts +12 -0
- package/dist/auth/identity-token.js +45 -0
- package/dist/auth/identity-token.js.map +1 -0
- package/dist/auth/identity.types.d.ts +7 -0
- package/dist/auth/identity.types.js +3 -0
- package/dist/auth/identity.types.js.map +1 -0
- package/dist/auth/index.d.ts +5 -0
- package/dist/auth/index.js +17 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/shared-secret-token.d.ts +12 -0
- package/dist/auth/shared-secret-token.js +44 -0
- package/dist/auth/shared-secret-token.js.map +1 -0
- package/dist/build.tsbuildinfo +1 -1
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.js +3 -1
- package/dist/common/index.js.map +1 -1
- package/dist/common/json.schema.d.ts +3 -0
- package/dist/common/json.schema.js +13 -0
- package/dist/common/json.schema.js.map +1 -0
- package/dist/database/create-stores.d.ts +5 -2
- package/dist/database/create-stores.js +6 -2
- package/dist/database/create-stores.js.map +1 -1
- package/dist/database/entities/workflow-execution.entity.d.ts +2 -4
- package/dist/database/entities/workflow-execution.entity.js +3 -14
- package/dist/database/entities/workflow-execution.entity.js.map +1 -1
- package/dist/database/entities/workflow-step-execution.entity.d.ts +2 -2
- package/dist/database/entities/workflow-step-execution.entity.js +7 -3
- package/dist/database/entities/workflow-step-execution.entity.js.map +1 -1
- package/dist/database/index.d.ts +2 -0
- package/dist/database/index.js +3 -1
- package/dist/database/index.js.map +1 -1
- package/dist/database/migrations/1778529600000-CreateWorkflowExecution.js +1 -1
- package/dist/database/migrations/1784890100000-CreateWorkflowStepExecution.js +13 -2
- package/dist/database/migrations/1784890100000-CreateWorkflowStepExecution.js.map +1 -1
- package/dist/database/typeorm-execution-store.d.ts +1 -3
- package/dist/database/typeorm-execution-store.js +1 -2
- package/dist/database/typeorm-execution-store.js.map +1 -1
- package/dist/database/typeorm-execution-view-store.d.ts +10 -0
- package/dist/database/typeorm-execution-view-store.js +49 -0
- package/dist/database/typeorm-execution-view-store.js.map +1 -0
- package/dist/database/typeorm-step-store.d.ts +7 -6
- package/dist/database/typeorm-step-store.js +63 -14
- package/dist/database/typeorm-step-store.js.map +1 -1
- package/dist/dependencies/external-dependencies.d.ts +3 -0
- package/dist/execution/batch-step.d.ts +8 -0
- package/dist/execution/batch-step.js +28 -0
- package/dist/execution/batch-step.js.map +1 -0
- package/dist/execution/completion.d.ts +2 -0
- package/dist/execution/completion.js +21 -0
- package/dist/execution/completion.js.map +1 -0
- package/dist/execution/execution-query.service.d.ts +7 -0
- package/dist/execution/execution-query.service.js +17 -0
- package/dist/execution/execution-query.service.js.map +1 -0
- package/dist/execution/execution-start-handler.d.ts +3 -1
- package/dist/execution/execution-start-handler.js +13 -2
- package/dist/execution/execution-start-handler.js.map +1 -1
- package/dist/execution/execution-store.d.ts +5 -7
- package/dist/execution/execution-store.js.map +1 -1
- package/dist/execution/execution-view-store.d.ts +26 -0
- package/dist/execution/execution-view-store.js +3 -0
- package/dist/execution/execution-view-store.js.map +1 -0
- package/dist/execution/execution.types.d.ts +14 -0
- package/dist/execution/execution.types.js +6 -1
- package/dist/execution/execution.types.js.map +1 -1
- package/dist/execution/index.d.ts +5 -2
- package/dist/execution/index.js +5 -1
- package/dist/execution/index.js.map +1 -1
- package/dist/execution/iteration-mapping.d.ts +14 -0
- package/dist/execution/iteration-mapping.js +48 -0
- package/dist/execution/iteration-mapping.js.map +1 -0
- package/dist/execution/loop-ledger.d.ts +7 -0
- package/dist/execution/loop-ledger.js +39 -0
- package/dist/execution/loop-ledger.js.map +1 -0
- package/dist/execution/settlement.d.ts +6 -4
- package/dist/execution/settlement.js +73 -17
- package/dist/execution/settlement.js.map +1 -1
- package/dist/execution/start-execution.service.d.ts +3 -3
- package/dist/execution/start-execution.service.js +6 -4
- package/dist/execution/start-execution.service.js.map +1 -1
- package/dist/execution/step-ready-handler.d.ts +11 -2
- package/dist/execution/step-ready-handler.js +66 -13
- package/dist/execution/step-ready-handler.js.map +1 -1
- package/dist/execution/step-settled-handler.d.ts +4 -3
- package/dist/execution/step-settled-handler.js +52 -30
- package/dist/execution/step-settled-handler.js.map +1 -1
- package/dist/execution/step-store.d.ts +9 -13
- package/dist/execution/step-store.js.map +1 -1
- package/dist/execution/store-loop-reader.d.ts +4 -0
- package/dist/execution/store-loop-reader.js +48 -0
- package/dist/execution/store-loop-reader.js.map +1 -0
- package/dist/graph/graph-validation.error.d.ts +3 -0
- package/dist/graph/graph-validation.error.js +11 -0
- package/dist/graph/graph-validation.error.js.map +1 -0
- package/dist/graph/index.d.ts +6 -2
- package/dist/graph/index.js +9 -2
- package/dist/graph/index.js.map +1 -1
- package/dist/graph/loops.d.ts +10 -0
- package/dist/graph/loops.js +172 -0
- package/dist/graph/loops.js.map +1 -0
- package/dist/graph/validate-executable-graph.d.ts +1 -3
- package/dist/graph/validate-executable-graph.js +13 -18
- package/dist/graph/validate-executable-graph.js.map +1 -1
- package/dist/graph/workflow-graph.d.ts +4 -0
- package/dist/graph/workflow-graph.js +7 -0
- package/dist/graph/workflow-graph.js.map +1 -1
- package/dist/index.d.ts +14 -7
- package/dist/index.js +19 -12
- package/dist/index.js.map +1 -1
- package/dist/lifecycle-events/batching-lifecycle-event-publisher.d.ts +26 -0
- package/dist/lifecycle-events/batching-lifecycle-event-publisher.js +121 -0
- package/dist/lifecycle-events/batching-lifecycle-event-publisher.js.map +1 -0
- package/dist/lifecycle-events/index.d.ts +6 -0
- package/dist/lifecycle-events/index.js +15 -0
- package/dist/lifecycle-events/index.js.map +1 -0
- package/dist/lifecycle-events/lifecycle-event-publisher.d.ts +6 -0
- package/dist/lifecycle-events/lifecycle-event-publisher.js +8 -0
- package/dist/lifecycle-events/lifecycle-event-publisher.js.map +1 -0
- package/dist/lifecycle-events/lifecycle-event.schema.d.ts +339 -0
- package/dist/lifecycle-events/lifecycle-event.schema.js +39 -0
- package/dist/lifecycle-events/lifecycle-event.schema.js.map +1 -0
- package/dist/lifecycle-events/lifecycle-event.types.d.ts +4 -0
- package/dist/lifecycle-events/lifecycle-event.types.js +3 -0
- package/dist/lifecycle-events/lifecycle-event.types.js.map +1 -0
- package/dist/logging/console-logger.d.ts +2 -0
- package/dist/logging/console-logger.js +18 -0
- package/dist/logging/console-logger.js.map +1 -0
- package/dist/logging/index.d.ts +2 -0
- package/dist/logging/index.js +6 -0
- package/dist/logging/index.js.map +1 -0
- package/dist/logging/logger.types.d.ts +6 -0
- package/dist/logging/logger.types.js +3 -0
- package/dist/logging/logger.types.js.map +1 -0
- package/dist/queue/in-memory-work-queue.d.ts +3 -0
- package/dist/queue/in-memory-work-queue.js +7 -2
- package/dist/queue/in-memory-work-queue.js.map +1 -1
- package/dist/runtime/create-engine-runtime.d.ts +20 -0
- package/dist/runtime/create-engine-runtime.js +38 -0
- package/dist/runtime/create-engine-runtime.js.map +1 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +6 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/serve.js +25 -34
- package/dist/serve.js.map +1 -1
- package/dist/server/api.types.d.ts +25 -0
- package/dist/server/api.types.js +3 -0
- package/dist/server/api.types.js.map +1 -0
- package/dist/server/create-engine-server.d.ts +9 -7
- package/dist/server/create-engine-server.js +4 -8
- package/dist/server/create-engine-server.js.map +1 -1
- package/dist/server/error-response.d.ts +7 -0
- package/dist/server/error-response.js +12 -0
- package/dist/server/error-response.js.map +1 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +3 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/routes/workflow-executions.d.ts +2 -2
- package/dist/server/routes/workflow-executions.handlers.d.ts +4 -0
- package/dist/server/routes/workflow-executions.handlers.js +68 -0
- package/dist/server/routes/workflow-executions.handlers.js.map +1 -0
- package/dist/server/routes/workflow-executions.js +16 -21
- package/dist/server/routes/workflow-executions.js.map +1 -1
- package/dist/testing/start-engine-server.d.ts +1 -1
- package/dist/testing/start-engine-server.js.map +1 -1
- package/package.json +10 -7
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type SharedSecretTokenSpec } from './shared-secret-token';
|
|
2
|
+
export type ActionScope = 'lifecycle-events:write';
|
|
3
|
+
export declare const ACTION_TOKEN: SharedSecretTokenSpec;
|
|
4
|
+
export declare class InvalidActionTokenError extends Error {
|
|
5
|
+
}
|
|
6
|
+
export declare function mintActionToken(secret: string, scope: ActionScope): string;
|
|
7
|
+
export declare function verifyActionToken(secret: string, token: string, requiredScope: ActionScope): void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InvalidActionTokenError = exports.ACTION_TOKEN = void 0;
|
|
4
|
+
exports.mintActionToken = mintActionToken;
|
|
5
|
+
exports.verifyActionToken = verifyActionToken;
|
|
6
|
+
const zod_1 = require("zod");
|
|
7
|
+
const shared_secret_token_1 = require("./shared-secret-token");
|
|
8
|
+
exports.ACTION_TOKEN = Object.freeze({
|
|
9
|
+
issuer: 'n8n-engine-dp',
|
|
10
|
+
audience: 'n8n-cp',
|
|
11
|
+
ttlSeconds: 60,
|
|
12
|
+
clockToleranceSeconds: 30,
|
|
13
|
+
});
|
|
14
|
+
const actionClaimsSchema = zod_1.z.object({
|
|
15
|
+
scope: zod_1.z.enum(['lifecycle-events:write']),
|
|
16
|
+
iat: zod_1.z.number().int(),
|
|
17
|
+
exp: zod_1.z.number().int(),
|
|
18
|
+
});
|
|
19
|
+
class InvalidActionTokenError extends Error {
|
|
20
|
+
}
|
|
21
|
+
exports.InvalidActionTokenError = InvalidActionTokenError;
|
|
22
|
+
function mintActionToken(secret, scope) {
|
|
23
|
+
return (0, shared_secret_token_1.signSharedSecretToken)(exports.ACTION_TOKEN, secret, { scope });
|
|
24
|
+
}
|
|
25
|
+
function verifyActionToken(secret, token, requiredScope) {
|
|
26
|
+
const claims = (0, shared_secret_token_1.verifySharedSecretToken)(exports.ACTION_TOKEN, secret, token, actionClaimsSchema);
|
|
27
|
+
if (!claims || claims.scope !== requiredScope)
|
|
28
|
+
throw new InvalidActionTokenError();
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=action-token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action-token.js","sourceRoot":"","sources":["../../src/auth/action-token.ts"],"names":[],"mappings":";;;;;AAAA,6BAAwB;AAExB,+DAI+B;AAclB,QAAA,YAAY,GAA0B,MAAM,CAAC,MAAM,CAAC;IAChE,MAAM,EAAE,eAAe;IACvB,QAAQ,EAAE,QAAQ;IAClB,UAAU,EAAE,EAAE;IACd,qBAAqB,EAAE,EAAE;CACzB,CAAC,CAAC;AAEH,MAAM,kBAAkB,GAAG,OAAC,CAAC,MAAM,CAAC;IACnC,KAAK,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,wBAAwB,CAAC,CAAC;IACzC,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE;IACrB,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE;CACrB,CAAC,CAAC;AAGH,6BAAqC,SAAQ,KAAK;CAAG;;AAGrD,yBAAgC,MAAc,EAAE,KAAkB;IACjE,OAAO,IAAA,2CAAqB,EAAC,QAAA,YAAY,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAC/D,CAAC;AAMD,2BAAkC,MAAc,EAAE,KAAa,EAAE,aAA0B;IAC1F,MAAM,MAAM,GAAG,IAAA,6CAAuB,EAAC,QAAA,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC;IACxF,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,KAAK,aAAa;QAAE,MAAM,IAAI,uBAAuB,EAAE,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RequestHandler } from 'express';
|
|
2
|
+
import type { IdentityVerifier } from './identity.types';
|
|
3
|
+
import { type EngineLogger } from '../logging';
|
|
4
|
+
export declare function createAuthenticationMiddleware(verifier: IdentityVerifier, logger?: EngineLogger): RequestHandler;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAuthenticationMiddleware = createAuthenticationMiddleware;
|
|
4
|
+
const logging_1 = require("../logging");
|
|
5
|
+
const error_response_1 = require("../server/error-response");
|
|
6
|
+
const BEARER_PREFIX = /^bearer /i;
|
|
7
|
+
function createAuthenticationMiddleware(verifier, logger = (0, logging_1.createConsoleLogger)()) {
|
|
8
|
+
return (req, res, next) => {
|
|
9
|
+
const reject = (reason) => {
|
|
10
|
+
const path = req.originalUrl.split('?')[0];
|
|
11
|
+
logger.warn(`rejected ${req.method} ${path} - ${reason}`);
|
|
12
|
+
(0, error_response_1.fail)(res, 401, { error: 'unauthenticated' });
|
|
13
|
+
};
|
|
14
|
+
const header = req.header('authorization');
|
|
15
|
+
if (!header || !BEARER_PREFIX.test(header)) {
|
|
16
|
+
reject('no bearer token');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const token = header.replace(BEARER_PREFIX, '');
|
|
20
|
+
try {
|
|
21
|
+
req.caller = verifier.verify(token);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
reject('token rejected');
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
next();
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=authenticate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticate.js","sourceRoot":"","sources":["../../src/auth/authenticate.ts"],"names":[],"mappings":";;;AAGA,wCAAoE;AACpE,6DAAgD;AAEhD,MAAM,aAAa,GAAG,WAAW,CAAC;AAGlC,wCACC,QAA0B,EAC1B,MAAM,GAAiB,IAAA,6BAAmB,GAAE;IAE5C,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAEzB,MAAM,MAAM,GAAG,CAAC,MAAc,EAAQ,EAAE;YAEvC,MAAM,IAAI,GAAG,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3C,MAAM,CAAC,IAAI,CAAC,YAAY,GAAG,CAAC,MAAM,IAAI,IAAI,MAAM,MAAM,EAAE,CAAC,CAAC;YAC1D,IAAA,qBAAI,EAAC,GAAG,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC,CAAC;QAC9C,CAAC,CAAC;QAEF,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QAC3C,IAAI,CAAC,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5C,MAAM,CAAC,iBAAiB,CAAC,CAAC;YAC1B,OAAO;QACR,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;QAEhD,IAAI,CAAC;YACJ,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACrC,CAAC;QAAC,MAAM,CAAC;YACR,MAAM,CAAC,gBAAgB,CAAC,CAAC;YACzB,OAAO;QACR,CAAC;QAED,IAAI,EAAE,CAAC;IACR,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AuthenticatedCaller, IdentityVerifier } from './identity.types';
|
|
2
|
+
import { MIN_SECRET_LENGTH, type SharedSecretTokenSpec } from './shared-secret-token';
|
|
3
|
+
export { MIN_SECRET_LENGTH };
|
|
4
|
+
export declare const IDENTITY_TOKEN: SharedSecretTokenSpec;
|
|
5
|
+
export declare class InvalidIdentityTokenError extends Error {
|
|
6
|
+
}
|
|
7
|
+
export declare function mintIdentityToken(secret: string, caller: AuthenticatedCaller): string;
|
|
8
|
+
export declare class SharedSecretIdentityVerifier implements IdentityVerifier {
|
|
9
|
+
private readonly secret;
|
|
10
|
+
constructor(secret: string);
|
|
11
|
+
verify(token: string): AuthenticatedCaller;
|
|
12
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SharedSecretIdentityVerifier = exports.InvalidIdentityTokenError = exports.IDENTITY_TOKEN = exports.MIN_SECRET_LENGTH = void 0;
|
|
4
|
+
exports.mintIdentityToken = mintIdentityToken;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const shared_secret_token_1 = require("./shared-secret-token");
|
|
7
|
+
Object.defineProperty(exports, "MIN_SECRET_LENGTH", { enumerable: true, get: function () { return shared_secret_token_1.MIN_SECRET_LENGTH; } });
|
|
8
|
+
exports.IDENTITY_TOKEN = Object.freeze({
|
|
9
|
+
issuer: 'n8n-cp',
|
|
10
|
+
audience: 'n8n-engine-dp',
|
|
11
|
+
ttlSeconds: 60,
|
|
12
|
+
clockToleranceSeconds: 30,
|
|
13
|
+
});
|
|
14
|
+
const identityClaimsSchema = zod_1.z.object({
|
|
15
|
+
sub: zod_1.z.string().min(1),
|
|
16
|
+
tenant_id: zod_1.z.string().min(1),
|
|
17
|
+
iat: zod_1.z.number().int(),
|
|
18
|
+
exp: zod_1.z.number().int(),
|
|
19
|
+
});
|
|
20
|
+
class InvalidIdentityTokenError extends Error {
|
|
21
|
+
}
|
|
22
|
+
exports.InvalidIdentityTokenError = InvalidIdentityTokenError;
|
|
23
|
+
function mintIdentityToken(secret, caller) {
|
|
24
|
+
return (0, shared_secret_token_1.signSharedSecretToken)(exports.IDENTITY_TOKEN, secret, {
|
|
25
|
+
sub: caller.cpId,
|
|
26
|
+
tenant_id: caller.tenantId,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
class SharedSecretIdentityVerifier {
|
|
30
|
+
secret;
|
|
31
|
+
constructor(secret) {
|
|
32
|
+
this.secret = secret;
|
|
33
|
+
if (!secret || secret.length < shared_secret_token_1.MIN_SECRET_LENGTH) {
|
|
34
|
+
throw new Error(`Identity verifier secret must be at least ${shared_secret_token_1.MIN_SECRET_LENGTH} chars`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
verify(token) {
|
|
38
|
+
const claims = (0, shared_secret_token_1.verifySharedSecretToken)(exports.IDENTITY_TOKEN, this.secret, token, identityClaimsSchema);
|
|
39
|
+
if (!claims)
|
|
40
|
+
throw new InvalidIdentityTokenError();
|
|
41
|
+
return { cpId: claims.sub, tenantId: claims.tenant_id };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.SharedSecretIdentityVerifier = SharedSecretIdentityVerifier;
|
|
45
|
+
//# sourceMappingURL=identity-token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity-token.js","sourceRoot":"","sources":["../../src/auth/identity-token.ts"],"names":[],"mappings":";;;;AAAA,6BAAwB;AAGxB,+DAK+B;kGAJ9B,uCAAiB;AASL,QAAA,cAAc,GAA0B,MAAM,CAAC,MAAM,CAAC;IAClE,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,eAAe;IACzB,UAAU,EAAE,EAAE;IACd,qBAAqB,EAAE,EAAE;CACzB,CAAC,CAAC;AAEH,MAAM,oBAAoB,GAAG,OAAC,CAAC,MAAM,CAAC;IACrC,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACtB,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5B,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE;IACrB,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE;CACrB,CAAC,CAAC;AAGH,+BAAuC,SAAQ,KAAK;CAAG;;AAGvD,2BAAkC,MAAc,EAAE,MAA2B;IAC5E,OAAO,IAAA,2CAAqB,EAAC,QAAA,cAAc,EAAE,MAAM,EAAE;QACpD,GAAG,EAAE,MAAM,CAAC,IAAI;QAChB,SAAS,EAAE,MAAM,CAAC,QAAQ;KAC1B,CAAC,CAAC;AACJ,CAAC;AAGD;IAC8B,MAAM;IAAnC,YAA6B,MAAc;sBAAd,MAAM;QAClC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,uCAAiB,EAAE,CAAC;YAClD,MAAM,IAAI,KAAK,CAAC,6CAA6C,uCAAiB,QAAQ,CAAC,CAAC;QACzF,CAAC;IACF,CAAC;IAED,MAAM,CAAC,KAAa;QACnB,MAAM,MAAM,GAAG,IAAA,6CAAuB,EACrC,QAAA,cAAc,EACd,IAAI,CAAC,MAAM,EACX,KAAK,EACL,oBAAoB,CACpB,CAAC;QACF,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,yBAAyB,EAAE,CAAC;QAEnD,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC;IACzD,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.types.js","sourceRoot":"","sources":["../../src/auth/identity.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createAuthenticationMiddleware } from './authenticate';
|
|
2
|
+
export { ACTION_TOKEN, InvalidActionTokenError, mintActionToken, verifyActionToken, } from './action-token';
|
|
3
|
+
export type { ActionScope } from './action-token';
|
|
4
|
+
export { IDENTITY_TOKEN, InvalidIdentityTokenError, MIN_SECRET_LENGTH, mintIdentityToken, SharedSecretIdentityVerifier, } from './identity-token';
|
|
5
|
+
export type { AuthenticatedCaller, IdentityVerifier } from './identity.types';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SharedSecretIdentityVerifier = exports.mintIdentityToken = exports.MIN_SECRET_LENGTH = exports.InvalidIdentityTokenError = exports.IDENTITY_TOKEN = exports.verifyActionToken = exports.mintActionToken = exports.InvalidActionTokenError = exports.ACTION_TOKEN = exports.createAuthenticationMiddleware = void 0;
|
|
4
|
+
var authenticate_1 = require("./authenticate");
|
|
5
|
+
Object.defineProperty(exports, "createAuthenticationMiddleware", { enumerable: true, get: function () { return authenticate_1.createAuthenticationMiddleware; } });
|
|
6
|
+
var action_token_1 = require("./action-token");
|
|
7
|
+
Object.defineProperty(exports, "ACTION_TOKEN", { enumerable: true, get: function () { return action_token_1.ACTION_TOKEN; } });
|
|
8
|
+
Object.defineProperty(exports, "InvalidActionTokenError", { enumerable: true, get: function () { return action_token_1.InvalidActionTokenError; } });
|
|
9
|
+
Object.defineProperty(exports, "mintActionToken", { enumerable: true, get: function () { return action_token_1.mintActionToken; } });
|
|
10
|
+
Object.defineProperty(exports, "verifyActionToken", { enumerable: true, get: function () { return action_token_1.verifyActionToken; } });
|
|
11
|
+
var identity_token_1 = require("./identity-token");
|
|
12
|
+
Object.defineProperty(exports, "IDENTITY_TOKEN", { enumerable: true, get: function () { return identity_token_1.IDENTITY_TOKEN; } });
|
|
13
|
+
Object.defineProperty(exports, "InvalidIdentityTokenError", { enumerable: true, get: function () { return identity_token_1.InvalidIdentityTokenError; } });
|
|
14
|
+
Object.defineProperty(exports, "MIN_SECRET_LENGTH", { enumerable: true, get: function () { return identity_token_1.MIN_SECRET_LENGTH; } });
|
|
15
|
+
Object.defineProperty(exports, "mintIdentityToken", { enumerable: true, get: function () { return identity_token_1.mintIdentityToken; } });
|
|
16
|
+
Object.defineProperty(exports, "SharedSecretIdentityVerifier", { enumerable: true, get: function () { return identity_token_1.SharedSecretIdentityVerifier; } });
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":";;;AAAA,+CAAgE;AAAvD,8HAAA,8BAA8B,OAAA;AACvC,+CAKwB;AAJvB,4GAAA,YAAY,OAAA;AACZ,uHAAA,uBAAuB,OAAA;AACvB,+GAAA,eAAe,OAAA;AACf,iHAAA,iBAAiB,OAAA;AAGlB,mDAM0B;AALzB,gHAAA,cAAc,OAAA;AACd,2HAAA,yBAAyB,OAAA;AACzB,mHAAA,iBAAiB,OAAA;AACjB,mHAAA,iBAAiB,OAAA;AACjB,8HAAA,4BAA4B,OAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
export declare const MIN_SECRET_LENGTH = 32;
|
|
3
|
+
export interface SharedSecretTokenSpec {
|
|
4
|
+
readonly issuer: string;
|
|
5
|
+
readonly audience: string;
|
|
6
|
+
readonly ttlSeconds: number;
|
|
7
|
+
readonly clockToleranceSeconds: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function signSharedSecretToken(spec: SharedSecretTokenSpec, secret: string, claims: object): string;
|
|
10
|
+
export declare function verifySharedSecretToken<T extends {
|
|
11
|
+
iat: number;
|
|
12
|
+
}>(spec: SharedSecretTokenSpec, secret: string, token: string, schema: z.ZodType<T>): T | undefined;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MIN_SECRET_LENGTH = void 0;
|
|
7
|
+
exports.signSharedSecretToken = signSharedSecretToken;
|
|
8
|
+
exports.verifySharedSecretToken = verifySharedSecretToken;
|
|
9
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
10
|
+
exports.MIN_SECRET_LENGTH = 32;
|
|
11
|
+
function signSharedSecretToken(spec, secret, claims) {
|
|
12
|
+
return jsonwebtoken_1.default.sign(claims, secret, {
|
|
13
|
+
algorithm: 'HS256',
|
|
14
|
+
issuer: spec.issuer,
|
|
15
|
+
audience: spec.audience,
|
|
16
|
+
expiresIn: spec.ttlSeconds,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function verifySharedSecretToken(spec, secret, token, schema) {
|
|
20
|
+
if (!secret || secret.length < exports.MIN_SECRET_LENGTH)
|
|
21
|
+
return undefined;
|
|
22
|
+
const now = Math.floor(Date.now() / 1000);
|
|
23
|
+
let claims;
|
|
24
|
+
try {
|
|
25
|
+
claims = jsonwebtoken_1.default.verify(token, secret, {
|
|
26
|
+
algorithms: ['HS256'],
|
|
27
|
+
issuer: spec.issuer,
|
|
28
|
+
audience: spec.audience,
|
|
29
|
+
maxAge: spec.ttlSeconds,
|
|
30
|
+
clockTolerance: spec.clockToleranceSeconds,
|
|
31
|
+
clockTimestamp: now,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
const parsed = schema.safeParse(claims);
|
|
38
|
+
if (!parsed.success)
|
|
39
|
+
return undefined;
|
|
40
|
+
if (parsed.data.iat > now + spec.clockToleranceSeconds)
|
|
41
|
+
return undefined;
|
|
42
|
+
return parsed.data;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=shared-secret-token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-secret-token.js","sourceRoot":"","sources":["../../src/auth/shared-secret-token.ts"],"names":[],"mappings":";;;;;;;;AAAA,gEAA+B;AAOlB,QAAA,iBAAiB,GAAG,EAAE,CAAC;AAUpC,+BACC,IAA2B,EAC3B,MAAc,EACd,MAAc;IAEd,OAAO,sBAAG,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE;QAC/B,SAAS,EAAE,OAAO;QAClB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,SAAS,EAAE,IAAI,CAAC,UAAU;KAC1B,CAAC,CAAC;AACJ,CAAC;AAUD,iCACC,IAA2B,EAC3B,MAAc,EACd,KAAa,EACb,MAAoB;IAEpB,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,QAAA,iBAAiB;QAAE,OAAO,SAAS,CAAC;IAEnE,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAC1C,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QAIJ,MAAM,GAAG,sBAAG,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE;YAClC,UAAU,EAAE,CAAC,OAAO,CAAC;YACrB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,MAAM,EAAE,IAAI,CAAC,UAAU;YACvB,cAAc,EAAE,IAAI,CAAC,qBAAqB;YAC1C,cAAc,EAAE,GAAG;SACnB,CAAC,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACxC,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAGtC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC,qBAAqB;QAAE,OAAO,SAAS,CAAC;IAEzE,OAAO,MAAM,CAAC,IAAI,CAAC;AACpB,CAAC"}
|