nesoi 3.3.2 → 3.3.4
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/lib/bundler/distributed/distributed.bundler.d.ts +1 -1
- package/lib/bundler/distributed/distributed.bundler.js +1 -1
- package/lib/bundler/distributed/stages/1_mkdir_stage.d.ts +1 -1
- package/lib/bundler/distributed/stages/2_build_typescript_stage.d.ts +1 -1
- package/lib/bundler/distributed/stages/3_copy_types_stage.d.ts +1 -1
- package/lib/bundler/distributed/stages/4_dump_modules_stage.d.ts +1 -1
- package/lib/bundler/distributed/stages/5_copy_static_stage.js +1 -1
- package/lib/bundler/distributed/stages/6_dump_cli_stage.js +1 -1
- package/lib/bundler/distributed/stages/7_dump_package_json_stage.js +1 -1
- package/lib/bundler/monolyth/monolyth.bundler.d.ts +2 -8
- package/lib/bundler/monolyth/monolyth.bundler.js +1 -1
- package/lib/bundler/monolyth/stages/1_mkdir_stage.d.ts +1 -1
- package/lib/bundler/monolyth/stages/2_build_typescript_stage.d.ts +1 -1
- package/lib/bundler/monolyth/stages/3_copy_types_stage.d.ts +1 -1
- package/lib/bundler/monolyth/stages/4_dump_modules_stage.d.ts +1 -1
- package/lib/bundler/monolyth/stages/5_copy_static_stage.d.ts +1 -1
- package/lib/bundler/monolyth/stages/6_dump_cli_stage.d.ts +1 -1
- package/lib/bundler/monolyth/stages/7_dump_package_json_stage.d.ts +1 -1
- package/lib/bundler/monolyth/stages/7_dump_package_json_stage.js +1 -1
- package/lib/{bundler/browser → engine/app/native}/browser.app.d.ts +8 -11
- package/lib/{bundler/browser → engine/app/native}/browser.app.js +3 -9
- package/lib/{bundler/distributed → engine/app/native}/distributed.app.config.d.ts +6 -6
- package/lib/{bundler/distributed → engine/app/native}/distributed.app.d.ts +6 -9
- package/lib/{bundler/distributed → engine/app/native}/distributed.app.js +2 -7
- package/lib/{bundler/distributed → engine/app/native}/distributed_node.app.d.ts +8 -8
- package/lib/{bundler/distributed → engine/app/native}/distributed_node.app.js +8 -8
- package/lib/engine/app/native/monolyth.app.config.d.ts +7 -0
- package/lib/engine/app/native/monolyth.app.config.js +2 -0
- package/lib/{bundler/monolyth → engine/app/native}/monolyth.app.d.ts +9 -12
- package/lib/{bundler/monolyth → engine/app/native}/monolyth.app.js +6 -12
- package/lib/engine/daemon.d.ts +11 -3
- package/lib/engine/daemon.js +23 -4
- package/lib/engine/transaction/nodes/bucket.trx_node.d.ts +3 -2
- package/lib/engine/transaction/nodes/bucket.trx_node.js +16 -10
- package/lib/engine/transaction/nodes/external.trx_node.js +3 -1
- package/lib/engine/transaction/nodes/machine.trx_node.d.ts +7 -3
- package/lib/engine/transaction/nodes/machine.trx_node.js +43 -23
- package/lib/engine/transaction/nodes/queue.trx_node.d.ts +7 -3
- package/lib/engine/transaction/nodes/queue.trx_node.js +40 -11
- package/lib/engine/transaction/nodes/topic.trx_node.d.ts +7 -3
- package/lib/engine/transaction/nodes/topic.trx_node.js +46 -30
- package/lib/engine/transaction/trx_engine.d.ts +4 -4
- package/lib/engine/transaction/trx_engine.js +10 -10
- package/lib/engine/transaction/trx_node.d.ts +1 -1
- package/lib/engine/transaction/trx_node.js +21 -27
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- /package/lib/{bundler/distributed → engine/app/native}/distributed.app.config.js +0 -0
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { $Module } from "../../../schema";
|
|
2
|
-
import { TrxNode } from '../trx_node';
|
|
2
|
+
import { AnyTrxNode, TrxNode } from '../trx_node';
|
|
3
3
|
import { $Machine } from "../../../elements/blocks/machine/machine.schema";
|
|
4
4
|
import { Machine, MachineOutput } from "../../../elements/blocks/machine/machine";
|
|
5
5
|
import { Message } from "../../../elements/entities/message/message";
|
|
6
|
+
import { Tag } from "../../dependency";
|
|
6
7
|
/**
|
|
7
8
|
* @category Engine
|
|
8
9
|
* @subcategory Transaction
|
|
9
10
|
*/
|
|
10
11
|
export declare class MachineTrxNode<M extends $Module, $ extends $Machine> {
|
|
11
12
|
private trx;
|
|
12
|
-
private
|
|
13
|
-
|
|
13
|
+
private tag;
|
|
14
|
+
private external;
|
|
15
|
+
private machine?;
|
|
16
|
+
constructor(trx: TrxNode<any, M, any>, tag: Tag);
|
|
17
|
+
wrap(action: string, input: Record<string, any>, fn: (trx: AnyTrxNode, element: Machine<any, M, $>) => Promise<any>, fmtTrxOut?: (out: any) => any): Promise<any>;
|
|
14
18
|
run(message: $['#input']['#raw']): Promise<MachineOutput>;
|
|
15
19
|
forward(message: Message<$['#input']>): Promise<MachineOutput>;
|
|
16
20
|
}
|
|
@@ -2,40 +2,60 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MachineTrxNode = void 0;
|
|
4
4
|
const trx_node_1 = require("../trx_node");
|
|
5
|
+
const dependency_1 = require("../../dependency");
|
|
6
|
+
const error_1 = require("../../data/error");
|
|
7
|
+
const external_trx_node_1 = require("./external.trx_node");
|
|
5
8
|
/**
|
|
6
9
|
* @category Engine
|
|
7
10
|
* @subcategory Transaction
|
|
8
11
|
*/
|
|
9
12
|
class MachineTrxNode {
|
|
10
|
-
constructor(trx,
|
|
13
|
+
constructor(trx, tag) {
|
|
11
14
|
this.trx = trx;
|
|
12
|
-
this.
|
|
15
|
+
this.tag = tag;
|
|
16
|
+
const module = trx_node_1.TrxNode.getModule(trx);
|
|
17
|
+
this.external = tag.module !== module.name;
|
|
18
|
+
if (!this.external) {
|
|
19
|
+
this.machine = dependency_1.Tag.element(tag, trx);
|
|
20
|
+
if (!this.machine) {
|
|
21
|
+
throw error_1.NesoiError.Trx.NodeNotFound(this.tag.full, trx.globalId);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
13
24
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
/*
|
|
26
|
+
Wrap
|
|
27
|
+
*/
|
|
28
|
+
async wrap(action, input, fn, fmtTrxOut) {
|
|
29
|
+
const wrapped = async (parentTrx, machine) => {
|
|
30
|
+
const trx = trx_node_1.TrxNode.makeChildNode(parentTrx, machine.schema.module, 'machine', machine.schema.name);
|
|
31
|
+
trx_node_1.TrxNode.open(trx, action, input);
|
|
32
|
+
let out;
|
|
33
|
+
try {
|
|
34
|
+
out = await fn(trx, machine);
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
throw trx_node_1.TrxNode.error(trx, e);
|
|
38
|
+
}
|
|
39
|
+
trx_node_1.TrxNode.ok(trx, fmtTrxOut ? fmtTrxOut(out) : out);
|
|
40
|
+
return out;
|
|
41
|
+
};
|
|
42
|
+
if (this.external) {
|
|
43
|
+
const ext = new external_trx_node_1.ExternalTrxNode(this.trx, this.tag);
|
|
44
|
+
return ext.run(trx => dependency_1.Tag.element(this.tag, trx), wrapped);
|
|
20
45
|
}
|
|
21
|
-
|
|
22
|
-
|
|
46
|
+
else {
|
|
47
|
+
return wrapped(this.trx, this.machine);
|
|
23
48
|
}
|
|
24
|
-
|
|
25
|
-
|
|
49
|
+
}
|
|
50
|
+
async run(message) {
|
|
51
|
+
return this.wrap('run', message, (trx, machine) => {
|
|
52
|
+
return machine.consumeRaw(trx, message);
|
|
53
|
+
});
|
|
26
54
|
}
|
|
27
55
|
async forward(message) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
response = await this.machine.consume(trx, message);
|
|
33
|
-
}
|
|
34
|
-
catch (e) {
|
|
35
|
-
throw trx_node_1.TrxNode.error(trx, e);
|
|
36
|
-
}
|
|
37
|
-
trx_node_1.TrxNode.ok(trx, response);
|
|
38
|
-
return response;
|
|
56
|
+
return this.wrap('forward', message, (trx, machine) => {
|
|
57
|
+
return machine.consume(trx, message);
|
|
58
|
+
});
|
|
39
59
|
}
|
|
40
60
|
}
|
|
41
61
|
exports.MachineTrxNode = MachineTrxNode;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { $Module, RawMessageInput } from "../../../schema";
|
|
2
|
-
import { TrxNode } from '../trx_node';
|
|
2
|
+
import { AnyTrxNode, TrxNode } from '../trx_node';
|
|
3
3
|
import { $Queue } from "../../../elements/blocks/queue/queue.schema";
|
|
4
|
+
import { Tag } from "../../dependency";
|
|
4
5
|
import { Queue } from "../../../elements/blocks/queue/queue";
|
|
5
6
|
/**
|
|
6
7
|
* @category Engine
|
|
@@ -8,7 +9,10 @@ import { Queue } from "../../../elements/blocks/queue/queue";
|
|
|
8
9
|
*/
|
|
9
10
|
export declare class QueueTrxNode<M extends $Module, $ extends $Queue> {
|
|
10
11
|
private trx;
|
|
11
|
-
private
|
|
12
|
-
|
|
12
|
+
private tag;
|
|
13
|
+
private external;
|
|
14
|
+
private queue?;
|
|
15
|
+
constructor(trx: TrxNode<any, M, any>, tag: Tag);
|
|
16
|
+
wrap(action: string, input: Record<string, any>, fn: (trx: AnyTrxNode, element: Queue<M, $>) => Promise<any>, fmtTrxOut?: (out: any) => any): Promise<any>;
|
|
13
17
|
push(raw: RawMessageInput<M, keyof M['messages']>): Promise<void>;
|
|
14
18
|
}
|
|
@@ -2,26 +2,55 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QueueTrxNode = void 0;
|
|
4
4
|
const trx_node_1 = require("../trx_node");
|
|
5
|
+
const external_trx_node_1 = require("./external.trx_node");
|
|
6
|
+
const dependency_1 = require("../../dependency");
|
|
7
|
+
const error_1 = require("../../data/error");
|
|
5
8
|
/**
|
|
6
9
|
* @category Engine
|
|
7
10
|
* @subcategory Transaction
|
|
8
11
|
*/
|
|
9
12
|
class QueueTrxNode {
|
|
10
|
-
constructor(trx,
|
|
13
|
+
constructor(trx, tag) {
|
|
11
14
|
this.trx = trx;
|
|
12
|
-
this.
|
|
15
|
+
this.tag = tag;
|
|
16
|
+
const module = trx_node_1.TrxNode.getModule(trx);
|
|
17
|
+
this.external = tag.module !== module.name;
|
|
18
|
+
if (!this.external) {
|
|
19
|
+
this.queue = dependency_1.Tag.element(tag, trx);
|
|
20
|
+
if (!this.queue) {
|
|
21
|
+
throw error_1.NesoiError.Trx.NodeNotFound(this.tag.full, trx.globalId);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
13
24
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
/*
|
|
26
|
+
Wrap
|
|
27
|
+
*/
|
|
28
|
+
async wrap(action, input, fn, fmtTrxOut) {
|
|
29
|
+
const wrapped = async (parentTrx, queue) => {
|
|
30
|
+
const trx = trx_node_1.TrxNode.makeChildNode(parentTrx, queue.schema.module, 'queue', queue.schema.name);
|
|
31
|
+
trx_node_1.TrxNode.open(trx, action, input);
|
|
32
|
+
let out;
|
|
33
|
+
try {
|
|
34
|
+
out = await fn(trx, queue);
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
throw trx_node_1.TrxNode.error(trx, e);
|
|
38
|
+
}
|
|
39
|
+
trx_node_1.TrxNode.ok(trx, fmtTrxOut ? fmtTrxOut(out) : out);
|
|
40
|
+
return out;
|
|
41
|
+
};
|
|
42
|
+
if (this.external) {
|
|
43
|
+
const ext = new external_trx_node_1.ExternalTrxNode(this.trx, this.tag);
|
|
44
|
+
return ext.run(trx => dependency_1.Tag.element(this.tag, trx), wrapped);
|
|
20
45
|
}
|
|
21
|
-
|
|
22
|
-
|
|
46
|
+
else {
|
|
47
|
+
return wrapped(this.trx, this.queue);
|
|
23
48
|
}
|
|
24
|
-
|
|
49
|
+
}
|
|
50
|
+
async push(raw) {
|
|
51
|
+
// return this.wrap('push', raw, (trx, queue) => {
|
|
52
|
+
// return queue.push(trx, message)
|
|
53
|
+
// })
|
|
25
54
|
}
|
|
26
55
|
}
|
|
27
56
|
exports.QueueTrxNode = QueueTrxNode;
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { $Module } from "../../../schema";
|
|
2
|
-
import { TrxNode } from '../trx_node';
|
|
2
|
+
import { AnyTrxNode, TrxNode } from '../trx_node';
|
|
3
3
|
import { $Topic } from "../../../elements/blocks/topic/topic.schema";
|
|
4
4
|
import { Topic } from "../../../elements/blocks/topic/topic";
|
|
5
5
|
import { AnyMessage } from "../../../elements/entities/message/message";
|
|
6
|
+
import { Tag } from "../../dependency";
|
|
6
7
|
/**
|
|
7
8
|
* @category Engine
|
|
8
9
|
* @subcategory Transaction
|
|
9
10
|
*/
|
|
10
11
|
export declare class TopicTrxNode<M extends $Module, $ extends $Topic> {
|
|
11
12
|
private trx;
|
|
12
|
-
private
|
|
13
|
-
|
|
13
|
+
private tag;
|
|
14
|
+
private external;
|
|
15
|
+
private resource?;
|
|
16
|
+
constructor(trx: TrxNode<any, M, any>, tag: Tag);
|
|
17
|
+
wrap(action: string, input: Record<string, any>, fn: (trx: AnyTrxNode, element: Topic<any, M, $>) => Promise<any>, fmtTrxOut?: (out: any) => any): Promise<any>;
|
|
14
18
|
subscribe(fn: (msg: AnyMessage) => void): Promise<string>;
|
|
15
19
|
unsubscribe(id: string): Promise<void>;
|
|
16
20
|
publish(raw: $['#input']['#raw']): Promise<void>;
|
|
@@ -2,49 +2,65 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TopicTrxNode = void 0;
|
|
4
4
|
const trx_node_1 = require("../trx_node");
|
|
5
|
+
const dependency_1 = require("../../dependency");
|
|
6
|
+
const error_1 = require("../../data/error");
|
|
7
|
+
const external_trx_node_1 = require("./external.trx_node");
|
|
5
8
|
/**
|
|
6
9
|
* @category Engine
|
|
7
10
|
* @subcategory Transaction
|
|
8
11
|
*/
|
|
9
12
|
class TopicTrxNode {
|
|
10
|
-
constructor(trx,
|
|
13
|
+
constructor(trx, tag) {
|
|
11
14
|
this.trx = trx;
|
|
12
|
-
this.
|
|
15
|
+
this.tag = tag;
|
|
16
|
+
const module = trx_node_1.TrxNode.getModule(trx);
|
|
17
|
+
this.external = tag.module !== module.name;
|
|
18
|
+
if (!this.external) {
|
|
19
|
+
this.resource = dependency_1.Tag.element(tag, trx);
|
|
20
|
+
if (!this.resource) {
|
|
21
|
+
throw error_1.NesoiError.Trx.NodeNotFound(this.tag.full, trx.globalId);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
13
24
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
/*
|
|
26
|
+
Wrap
|
|
27
|
+
*/
|
|
28
|
+
async wrap(action, input, fn, fmtTrxOut) {
|
|
29
|
+
const wrapped = async (parentTrx, resource) => {
|
|
30
|
+
const trx = trx_node_1.TrxNode.makeChildNode(parentTrx, resource.schema.module, 'topic', resource.schema.name);
|
|
31
|
+
trx_node_1.TrxNode.open(trx, action, input);
|
|
32
|
+
let out;
|
|
33
|
+
try {
|
|
34
|
+
out = await fn(trx, resource);
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
throw trx_node_1.TrxNode.error(trx, e);
|
|
38
|
+
}
|
|
39
|
+
trx_node_1.TrxNode.ok(trx, fmtTrxOut ? fmtTrxOut(out) : out);
|
|
40
|
+
return out;
|
|
41
|
+
};
|
|
42
|
+
if (this.external) {
|
|
43
|
+
const ext = new external_trx_node_1.ExternalTrxNode(this.trx, this.tag);
|
|
44
|
+
return ext.run(trx => dependency_1.Tag.element(this.tag, trx), wrapped);
|
|
20
45
|
}
|
|
21
|
-
|
|
22
|
-
|
|
46
|
+
else {
|
|
47
|
+
return wrapped(this.trx, this.resource);
|
|
23
48
|
}
|
|
24
|
-
|
|
25
|
-
|
|
49
|
+
}
|
|
50
|
+
async subscribe(fn) {
|
|
51
|
+
return this.wrap('subscribe', {}, (trx, topic) => {
|
|
52
|
+
return topic.subscribe(trx, fn);
|
|
53
|
+
});
|
|
26
54
|
}
|
|
27
55
|
async unsubscribe(id) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
await this.topic.unsubscribe(this.trx, id);
|
|
32
|
-
}
|
|
33
|
-
catch (e) {
|
|
34
|
-
throw trx_node_1.TrxNode.error(trx, e);
|
|
35
|
-
}
|
|
36
|
-
trx_node_1.TrxNode.ok(trx, undefined);
|
|
56
|
+
return this.wrap('unsubscribe', { id }, (trx, topic) => {
|
|
57
|
+
return topic.unsubscribe(trx, id);
|
|
58
|
+
});
|
|
37
59
|
}
|
|
38
60
|
async publish(raw) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
await this.topic.consumeRaw(trx, raw);
|
|
43
|
-
}
|
|
44
|
-
catch (e) {
|
|
45
|
-
throw trx_node_1.TrxNode.error(trx, e);
|
|
46
|
-
}
|
|
47
|
-
trx_node_1.TrxNode.ok(trx, undefined);
|
|
61
|
+
return this.wrap('publish', { raw }, (trx, topic) => {
|
|
62
|
+
return topic.consumeRaw(trx, raw);
|
|
63
|
+
});
|
|
48
64
|
}
|
|
49
65
|
}
|
|
50
66
|
exports.TopicTrxNode = TopicTrxNode;
|
|
@@ -2,7 +2,7 @@ import { $Module, $Space } from "../../schema";
|
|
|
2
2
|
import { Module } from '../module';
|
|
3
3
|
import { AnyTrx, Trx, TrxStatus } from './trx';
|
|
4
4
|
import { TrxNode, TrxNodeStatus } from './trx_node';
|
|
5
|
-
import { AnyAuthnProviders, AuthRequest } from '../auth/authn';
|
|
5
|
+
import { AnyAuthnProviders, AnyUsers, AuthRequest } from '../auth/authn';
|
|
6
6
|
import { BucketAdapterConfig } from "../../elements/entities/bucket/adapters/bucket_adapter";
|
|
7
7
|
import { TrxEngineConfig } from './trx_engine.config';
|
|
8
8
|
import { IService } from '../app/service';
|
|
@@ -46,11 +46,11 @@ export declare class TrxEngine<S extends $Space, M extends $Module, AuthUsers ex
|
|
|
46
46
|
constructor(origin: TrxEngineOrigin, module: Module<S, M>, authnProviders?: AuthUsers | undefined, config?: TrxEngineConfig<S, M, any, any> | undefined, services?: Record<string, IService>);
|
|
47
47
|
getModule(): Module<S, M>;
|
|
48
48
|
get(id?: string): Promise<Trx<S, M, any>>;
|
|
49
|
-
trx(fn: (trx: TrxNode<S, M, any>) => Promise<TrxNodeStatus>, id?: string,
|
|
50
|
-
trx_hold(fn: (trx: TrxNode<S, M, any>) => Promise<any>, id?: string, authn?: AuthRequest<keyof AuthUsers>): Promise<HeldTrxNode<any>>;
|
|
49
|
+
trx(fn: (trx: TrxNode<S, M, any>) => Promise<TrxNodeStatus>, id?: string, tokens?: AuthRequest<keyof AuthUsers>, users?: Partial<AuthUsers>): Promise<TrxStatus<any>>;
|
|
50
|
+
trx_hold(fn: (trx: TrxNode<S, M, any>) => Promise<any>, id?: string, authn?: AuthRequest<keyof AuthUsers>, users?: Partial<AuthUsers>): Promise<HeldTrxNode<any>>;
|
|
51
51
|
getBucketMetadata(tag: Tag): BucketMetadata;
|
|
52
52
|
getBucketDrive(tag: Tag): DriveAdapter | undefined;
|
|
53
|
-
authenticate(node: TrxNode<S, M, any>,
|
|
53
|
+
authenticate(node: TrxNode<S, M, any>, tokens?: AuthRequest<keyof AuthUsers>, users?: AnyUsers, force?: boolean): Promise<void>;
|
|
54
54
|
private hold;
|
|
55
55
|
private commit;
|
|
56
56
|
private rollback;
|
|
@@ -75,10 +75,10 @@ class TrxEngine {
|
|
|
75
75
|
}
|
|
76
76
|
return trx;
|
|
77
77
|
}
|
|
78
|
-
async trx(fn, id,
|
|
78
|
+
async trx(fn, id, tokens, users) {
|
|
79
79
|
const trx = await this.get(id);
|
|
80
80
|
try {
|
|
81
|
-
await this.authenticate(trx.root,
|
|
81
|
+
await this.authenticate(trx.root, tokens, users);
|
|
82
82
|
let output;
|
|
83
83
|
if (this.config?.wrap) {
|
|
84
84
|
output = await this.config?.wrap(trx, fn, this.services);
|
|
@@ -93,11 +93,11 @@ class TrxEngine {
|
|
|
93
93
|
}
|
|
94
94
|
return trx.status();
|
|
95
95
|
}
|
|
96
|
-
async trx_hold(fn, id, authn) {
|
|
96
|
+
async trx_hold(fn, id, authn, users) {
|
|
97
97
|
const trx = await this.get(id);
|
|
98
98
|
let output = {};
|
|
99
99
|
try {
|
|
100
|
-
await this.authenticate(trx.root, authn);
|
|
100
|
+
await this.authenticate(trx.root, authn, users);
|
|
101
101
|
if (this.config?.wrap) {
|
|
102
102
|
output = await this.config?.wrap(trx, fn, this.services);
|
|
103
103
|
}
|
|
@@ -128,27 +128,27 @@ class TrxEngine {
|
|
|
128
128
|
return this.module.buckets[tag.name].drive;
|
|
129
129
|
}
|
|
130
130
|
// authentication
|
|
131
|
-
async authenticate(node,
|
|
131
|
+
async authenticate(node, tokens = {}, users = {}, force = false) {
|
|
132
132
|
if (!this.authnProviders) {
|
|
133
133
|
throw error_1.NesoiError.Auth.NoProvidersRegisteredForModule(this.module.name);
|
|
134
134
|
}
|
|
135
|
-
const
|
|
136
|
-
const
|
|
135
|
+
const _users = { ...users };
|
|
136
|
+
const _tokens = {};
|
|
137
137
|
for (const providerName in this.authnProviders) {
|
|
138
138
|
const provider = this.authnProviders[providerName];
|
|
139
139
|
if (!provider) {
|
|
140
140
|
throw error_1.NesoiError.Auth.NoProviderRegisteredForModule(this.module.name, providerName);
|
|
141
141
|
}
|
|
142
|
-
const token =
|
|
142
|
+
const token = tokens[providerName];
|
|
143
143
|
if (token) {
|
|
144
|
-
|
|
144
|
+
_tokens[providerName] = token;
|
|
145
145
|
if (provider.eager || force) {
|
|
146
146
|
const { user } = await provider.authenticate({ trx: node, token });
|
|
147
147
|
users[providerName] = user;
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
-
trx_node_1.TrxNode.addAuthn(node,
|
|
151
|
+
trx_node_1.TrxNode.addAuthn(node, _tokens, _users);
|
|
152
152
|
}
|
|
153
153
|
//
|
|
154
154
|
async hold(trx, output) {
|
|
@@ -63,7 +63,7 @@ export declare class TrxNode<Space extends $Space, M extends $Module, AuthUsers
|
|
|
63
63
|
machine<Name extends keyof M['machines'], Machine extends M['machines'][Name]>(name: Name): MachineTrxNode<M, Machine>;
|
|
64
64
|
queue<Name extends keyof M['queues'], Queue extends M['queues'][Name]>(name: Name): QueueTrxNode<M, Queue>;
|
|
65
65
|
topic<Name extends keyof M['topics'], topic extends M['topics'][Name]>(name: Name): TopicTrxNode<M, topic>;
|
|
66
|
-
authenticate(
|
|
66
|
+
authenticate(tokens: AuthRequest<keyof AuthUsers>): Promise<TrxNode<$Space, $Module, AuthUsers>>;
|
|
67
67
|
token<U extends keyof AuthUsers & keyof M['#authn']>(provider: U): Promise<string>;
|
|
68
68
|
user<U extends keyof AuthUsers & keyof M['#authn']>(provider: U): Promise<M['#authn'][U]>;
|
|
69
69
|
virtual<T>(def: VirtualModuleDef, fn: ($: AnyTrxNode) => T | Promise<T>): Promise<T>;
|
|
@@ -128,33 +128,21 @@ class TrxNode {
|
|
|
128
128
|
return new resource_trx_node_1.ResourceTrxNode(this, tag);
|
|
129
129
|
}
|
|
130
130
|
machine(name) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (!machine) {
|
|
134
|
-
throw error_1.NesoiError.Module.MachineNotIncluded(this.module, name);
|
|
135
|
-
}
|
|
136
|
-
return new machine_trx_node_1.MachineTrxNode(this, machine);
|
|
131
|
+
const tag = dependency_1.Tag.fromNameOrShort(this.module.name, 'machine', name);
|
|
132
|
+
return new machine_trx_node_1.MachineTrxNode(this, tag);
|
|
137
133
|
}
|
|
138
134
|
queue(name) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (!queue) {
|
|
142
|
-
throw error_1.NesoiError.Module.QueueNotIncluded(this.module, name);
|
|
143
|
-
}
|
|
144
|
-
return new queue_trx_node_1.QueueTrxNode(this, queue);
|
|
135
|
+
const tag = dependency_1.Tag.fromNameOrShort(this.module.name, 'queue', name);
|
|
136
|
+
return new queue_trx_node_1.QueueTrxNode(this, tag);
|
|
145
137
|
}
|
|
146
138
|
topic(name) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (!topic) {
|
|
150
|
-
throw error_1.NesoiError.Module.TopicNotIncluded(this.module, name);
|
|
151
|
-
}
|
|
152
|
-
return new topic_trx_node_1.TopicTrxNode(this, topic);
|
|
139
|
+
const tag = dependency_1.Tag.fromNameOrShort(this.module.name, 'topic', name);
|
|
140
|
+
return new topic_trx_node_1.TopicTrxNode(this, tag);
|
|
153
141
|
}
|
|
154
142
|
// Authentication
|
|
155
|
-
async authenticate(
|
|
143
|
+
async authenticate(tokens) {
|
|
156
144
|
const newNode = new TrxNode(this.scope, this.trx, this, this.module, this.auth);
|
|
157
|
-
await this.trx.engine.authenticate(newNode,
|
|
145
|
+
await this.trx.engine.authenticate(newNode, tokens);
|
|
158
146
|
return newNode;
|
|
159
147
|
}
|
|
160
148
|
async token(provider) {
|
|
@@ -219,6 +207,10 @@ class TrxNode {
|
|
|
219
207
|
}
|
|
220
208
|
static addAuthn(node, tokens, users) {
|
|
221
209
|
var _a, _b;
|
|
210
|
+
log_1.Log.trace('trx', node.globalId, 'Transaction authenticated', {
|
|
211
|
+
tokens,
|
|
212
|
+
users
|
|
213
|
+
});
|
|
222
214
|
node.auth ?? (node.auth = {
|
|
223
215
|
tokens: {},
|
|
224
216
|
users: {}
|
|
@@ -245,13 +237,15 @@ class TrxNode {
|
|
|
245
237
|
static async checkAuth(node, options) {
|
|
246
238
|
if (!options?.length)
|
|
247
239
|
return;
|
|
248
|
-
if (!node.auth?.
|
|
240
|
+
if (!Object.keys(node.auth?.tokens || {}).length) {
|
|
249
241
|
throw error_1.NesoiError.Trx.Unauthorized({ providers: options.map(opt => opt.provider) });
|
|
250
242
|
}
|
|
243
|
+
const users = node.auth?.users || {};
|
|
244
|
+
const tokens = node.auth?.tokens || {};
|
|
251
245
|
for (const opt of options) {
|
|
252
246
|
// Eager provider or previously authenticated user
|
|
253
|
-
if (opt.provider in
|
|
254
|
-
const user =
|
|
247
|
+
if (opt.provider in users) {
|
|
248
|
+
const user = users[opt.provider];
|
|
255
249
|
if (opt.resolver && !opt.resolver(user)) {
|
|
256
250
|
log_1.Log.debug('trx', node.globalId, `User from provider '${opt.provider}' didn't pass the authorization resolver`);
|
|
257
251
|
continue;
|
|
@@ -260,17 +254,17 @@ class TrxNode {
|
|
|
260
254
|
return;
|
|
261
255
|
}
|
|
262
256
|
// Non-eager providers
|
|
263
|
-
else if (opt.provider in
|
|
257
|
+
else if (opt.provider in tokens) {
|
|
264
258
|
try {
|
|
265
259
|
await node.trx.engine.authenticate(node, {
|
|
266
|
-
[opt.provider]:
|
|
267
|
-
}, true);
|
|
260
|
+
[opt.provider]: tokens[opt.provider]
|
|
261
|
+
}, {}, true);
|
|
268
262
|
}
|
|
269
263
|
catch {
|
|
270
264
|
log_1.Log.debug('trx', node.globalId, `Attempt to authenticate with provider '${opt.provider}' failed`);
|
|
271
265
|
continue;
|
|
272
266
|
}
|
|
273
|
-
const user =
|
|
267
|
+
const user = users[opt.provider];
|
|
274
268
|
if (opt.resolver && !opt.resolver(user)) {
|
|
275
269
|
log_1.Log.debug('trx', node.globalId, `User from provider '${opt.provider}' didn't pass the authorization resolver`);
|
|
276
270
|
continue;
|