@n8n/engine 0.17.0 → 0.18.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/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 +2 -1
- package/dist/auth/authenticate.js +3 -2
- package/dist/auth/authenticate.js.map +1 -1
- package/dist/auth/identity-token.d.ts +3 -5
- package/dist/auth/identity-token.js +17 -38
- package/dist/auth/identity-token.js.map +1 -1
- package/dist/auth/index.d.ts +3 -1
- package/dist/auth/index.js +7 -5
- package/dist/auth/index.js.map +1 -1
- 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 +2 -0
- 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 +0 -1
- package/dist/database/entities/workflow-execution.entity.js +0 -11
- package/dist/database/entities/workflow-execution.entity.js.map +1 -1
- package/dist/database/entities/workflow-step-execution.entity.d.ts +1 -2
- package/dist/database/entities/workflow-step-execution.entity.js.map +1 -1
- package/dist/database/index.d.ts +1 -0
- package/dist/database/index.js +3 -1
- package/dist/database/index.js.map +1 -1
- package/dist/database/typeorm-execution-store.d.ts +1 -3
- package/dist/database/typeorm-execution-store.js +0 -1
- 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 +3 -2
- package/dist/database/typeorm-step-store.js +6 -1
- 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.js.map +1 -1
- 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 +10 -1
- package/dist/execution/execution-start-handler.js.map +1 -1
- package/dist/execution/execution-store.d.ts +2 -3
- 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 +6 -0
- package/dist/execution/execution.types.js.map +1 -1
- package/dist/execution/index.d.ts +4 -2
- package/dist/execution/index.js +3 -1
- package/dist/execution/index.js.map +1 -1
- package/dist/execution/loop-ledger.d.ts +2 -2
- package/dist/execution/loop-ledger.js +4 -3
- package/dist/execution/loop-ledger.js.map +1 -1
- package/dist/execution/settlement.js.map +1 -1
- package/dist/execution/start-execution.service.d.ts +1 -0
- package/dist/execution/start-execution.service.js +5 -3
- package/dist/execution/start-execution.service.js.map +1 -1
- package/dist/execution/step-ready-handler.d.ts +4 -1
- package/dist/execution/step-ready-handler.js +37 -3
- package/dist/execution/step-ready-handler.js.map +1 -1
- package/dist/execution/step-settled-handler.d.ts +3 -1
- package/dist/execution/step-settled-handler.js +25 -7
- package/dist/execution/step-settled-handler.js.map +1 -1
- package/dist/execution/step-store.d.ts +2 -9
- 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/index.d.ts +2 -1
- package/dist/graph/index.js +3 -1
- package/dist/graph/index.js.map +1 -1
- package/dist/graph/loops.d.ts +1 -1
- package/dist/graph/loops.js +11 -0
- package/dist/graph/loops.js.map +1 -1
- package/dist/graph/validate-executable-graph.js +4 -3
- 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 +9 -5
- package/dist/index.js +13 -1
- 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 +3 -1
- package/dist/runtime/create-engine-runtime.js +19 -7
- package/dist/runtime/create-engine-runtime.js.map +1 -1
- package/dist/serve.js +7 -4
- 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 -1
- package/dist/server/create-engine-server.js +3 -3
- package/dist/server/create-engine-server.js.map +1 -1
- package/dist/server/index.d.ts +2 -0
- 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 +10 -13
- package/dist/server/routes/workflow-executions.js.map +1 -1
- package/dist/testing/start-engine-server.d.ts +2 -3
- package/dist/testing/start-engine-server.js +2 -2
- package/dist/testing/start-engine-server.js.map +1 -1
- package/package.json +7 -6
|
@@ -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"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { RequestHandler } from 'express';
|
|
2
2
|
import type { IdentityVerifier } from './identity.types';
|
|
3
|
-
|
|
3
|
+
import { type EngineLogger } from '../logging';
|
|
4
|
+
export declare function createAuthenticationMiddleware(verifier: IdentityVerifier, logger?: EngineLogger): RequestHandler;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createAuthenticationMiddleware = createAuthenticationMiddleware;
|
|
4
|
+
const logging_1 = require("../logging");
|
|
4
5
|
const error_response_1 = require("../server/error-response");
|
|
5
6
|
const BEARER_PREFIX = /^bearer /i;
|
|
6
|
-
function createAuthenticationMiddleware(verifier) {
|
|
7
|
+
function createAuthenticationMiddleware(verifier, logger = (0, logging_1.createConsoleLogger)()) {
|
|
7
8
|
return (req, res, next) => {
|
|
8
9
|
const reject = (reason) => {
|
|
9
10
|
const path = req.originalUrl.split('?')[0];
|
|
10
|
-
|
|
11
|
+
logger.warn(`rejected ${req.method} ${path} - ${reason}`);
|
|
11
12
|
(0, error_response_1.fail)(res, 401, { error: 'unauthenticated' });
|
|
12
13
|
};
|
|
13
14
|
const header = req.header('authorization');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticate.js","sourceRoot":"","sources":["../../src/auth/authenticate.ts"],"names":[],"mappings":";;;AAGA,6DAAgD;AAEhD,MAAM,aAAa,GAAG,WAAW,CAAC;AAGlC,
|
|
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"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { AuthenticatedCaller, IdentityVerifier } from './identity.types';
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const IDENTITY_TOKEN_CLOCK_TOLERANCE_SECONDS = 30;
|
|
6
|
-
export declare const MIN_SECRET_LENGTH = 32;
|
|
2
|
+
import { MIN_SECRET_LENGTH, type SharedSecretTokenSpec } from './shared-secret-token';
|
|
3
|
+
export { MIN_SECRET_LENGTH };
|
|
4
|
+
export declare const IDENTITY_TOKEN: SharedSecretTokenSpec;
|
|
7
5
|
export declare class InvalidIdentityTokenError extends Error {
|
|
8
6
|
}
|
|
9
7
|
export declare function mintIdentityToken(secret: string, caller: AuthenticatedCaller): string;
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SharedSecretIdentityVerifier = exports.InvalidIdentityTokenError = exports.
|
|
3
|
+
exports.SharedSecretIdentityVerifier = exports.InvalidIdentityTokenError = exports.IDENTITY_TOKEN = exports.MIN_SECRET_LENGTH = void 0;
|
|
7
4
|
exports.mintIdentityToken = mintIdentityToken;
|
|
8
|
-
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
9
5
|
const zod_1 = require("zod");
|
|
10
|
-
|
|
11
|
-
exports.
|
|
12
|
-
exports.
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
});
|
|
15
14
|
const identityClaimsSchema = zod_1.z.object({
|
|
16
15
|
sub: zod_1.z.string().min(1),
|
|
17
16
|
tenant_id: zod_1.z.string().min(1),
|
|
@@ -22,44 +21,24 @@ class InvalidIdentityTokenError extends Error {
|
|
|
22
21
|
}
|
|
23
22
|
exports.InvalidIdentityTokenError = InvalidIdentityTokenError;
|
|
24
23
|
function mintIdentityToken(secret, caller) {
|
|
25
|
-
return
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
audience: exports.IDENTITY_AUDIENCE,
|
|
29
|
-
expiresIn: exports.IDENTITY_TOKEN_TTL_SECONDS,
|
|
24
|
+
return (0, shared_secret_token_1.signSharedSecretToken)(exports.IDENTITY_TOKEN, secret, {
|
|
25
|
+
sub: caller.cpId,
|
|
26
|
+
tenant_id: caller.tenantId,
|
|
30
27
|
});
|
|
31
28
|
}
|
|
32
29
|
class SharedSecretIdentityVerifier {
|
|
33
30
|
secret;
|
|
34
31
|
constructor(secret) {
|
|
35
32
|
this.secret = secret;
|
|
36
|
-
if (!secret || secret.length <
|
|
37
|
-
throw new Error(`Identity verifier secret must be at least ${
|
|
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`);
|
|
38
35
|
}
|
|
39
36
|
}
|
|
40
37
|
verify(token) {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
claims = jsonwebtoken_1.default.verify(token, this.secret, {
|
|
45
|
-
algorithms: ['HS256'],
|
|
46
|
-
issuer: exports.IDENTITY_ISSUER,
|
|
47
|
-
audience: exports.IDENTITY_AUDIENCE,
|
|
48
|
-
maxAge: exports.IDENTITY_TOKEN_TTL_SECONDS,
|
|
49
|
-
clockTolerance: exports.IDENTITY_TOKEN_CLOCK_TOLERANCE_SECONDS,
|
|
50
|
-
clockTimestamp: now,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
throw new InvalidIdentityTokenError();
|
|
55
|
-
}
|
|
56
|
-
const parsed = identityClaimsSchema.safeParse(claims);
|
|
57
|
-
if (!parsed.success)
|
|
58
|
-
throw new InvalidIdentityTokenError();
|
|
59
|
-
if (parsed.data.iat > now + exports.IDENTITY_TOKEN_CLOCK_TOLERANCE_SECONDS) {
|
|
38
|
+
const claims = (0, shared_secret_token_1.verifySharedSecretToken)(exports.IDENTITY_TOKEN, this.secret, token, identityClaimsSchema);
|
|
39
|
+
if (!claims)
|
|
60
40
|
throw new InvalidIdentityTokenError();
|
|
61
|
-
}
|
|
62
|
-
return { cpId: parsed.data.sub, tenantId: parsed.data.tenant_id };
|
|
41
|
+
return { cpId: claims.sub, tenantId: claims.tenant_id };
|
|
63
42
|
}
|
|
64
43
|
}
|
|
65
44
|
exports.SharedSecretIdentityVerifier = SharedSecretIdentityVerifier;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity-token.js","sourceRoot":"","sources":["../../src/auth/identity-token.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { createAuthenticationMiddleware } from './authenticate';
|
|
2
|
-
export {
|
|
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';
|
|
3
5
|
export type { AuthenticatedCaller, IdentityVerifier } from './identity.types';
|
package/dist/auth/index.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SharedSecretIdentityVerifier = exports.mintIdentityToken = exports.MIN_SECRET_LENGTH = exports.InvalidIdentityTokenError = exports.
|
|
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
4
|
var authenticate_1 = require("./authenticate");
|
|
5
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; } });
|
|
6
11
|
var identity_token_1 = require("./identity-token");
|
|
7
|
-
Object.defineProperty(exports, "
|
|
8
|
-
Object.defineProperty(exports, "IDENTITY_ISSUER", { enumerable: true, get: function () { return identity_token_1.IDENTITY_ISSUER; } });
|
|
9
|
-
Object.defineProperty(exports, "IDENTITY_TOKEN_CLOCK_TOLERANCE_SECONDS", { enumerable: true, get: function () { return identity_token_1.IDENTITY_TOKEN_CLOCK_TOLERANCE_SECONDS; } });
|
|
10
|
-
Object.defineProperty(exports, "IDENTITY_TOKEN_TTL_SECONDS", { enumerable: true, get: function () { return identity_token_1.IDENTITY_TOKEN_TTL_SECONDS; } });
|
|
12
|
+
Object.defineProperty(exports, "IDENTITY_TOKEN", { enumerable: true, get: function () { return identity_token_1.IDENTITY_TOKEN; } });
|
|
11
13
|
Object.defineProperty(exports, "InvalidIdentityTokenError", { enumerable: true, get: function () { return identity_token_1.InvalidIdentityTokenError; } });
|
|
12
14
|
Object.defineProperty(exports, "MIN_SECRET_LENGTH", { enumerable: true, get: function () { return identity_token_1.MIN_SECRET_LENGTH; } });
|
|
13
15
|
Object.defineProperty(exports, "mintIdentityToken", { enumerable: true, get: function () { return identity_token_1.mintIdentityToken; } });
|
package/dist/auth/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":";;;AAAA,+CAAgE;AAAvD,8HAAA,8BAA8B,OAAA;AACvC,
|
|
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"}
|