@flusys/nestjs-entity-builder 9.0.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.
Files changed (114) hide show
  1. package/README.md +111 -0
  2. package/config/entity-builder.constants.d.ts +6 -0
  3. package/config/event-actions.d.ts +8 -0
  4. package/config/index.d.ts +3 -0
  5. package/config/message-keys.d.ts +542 -0
  6. package/controllers/entity-definition.controller.d.ts +40 -0
  7. package/controllers/field-definition.controller.d.ts +22 -0
  8. package/controllers/flow-definition.controller.d.ts +51 -0
  9. package/controllers/flow-execution.controller.d.ts +21 -0
  10. package/controllers/flow-runtime.controller.d.ts +24 -0
  11. package/controllers/index.d.ts +5 -0
  12. package/docs/entity-builder-swagger.config.d.ts +3 -0
  13. package/docs/index.d.ts +1 -0
  14. package/dtos/entity-definition.dto.d.ts +58 -0
  15. package/dtos/field-definition.dto.d.ts +42 -0
  16. package/dtos/flow.dto.d.ts +76 -0
  17. package/dtos/index.d.ts +3 -0
  18. package/dtos/schema-change.dto.d.ts +53 -0
  19. package/entities/entity-definition.entity.d.ts +15 -0
  20. package/entities/field-definition.entity.d.ts +23 -0
  21. package/entities/flow-definition.entity.d.ts +14 -0
  22. package/entities/flow-execution.entity.d.ts +19 -0
  23. package/entities/flow-version.entity.d.ts +10 -0
  24. package/entities/index.d.ts +14 -0
  25. package/entities/schema-change-log.entity.d.ts +15 -0
  26. package/enums/ddl-operation.enum.d.ts +13 -0
  27. package/enums/entity-status.enum.d.ts +5 -0
  28. package/enums/field-type.enum.d.ts +15 -0
  29. package/enums/index.d.ts +3 -0
  30. package/fesm/21.js +576 -0
  31. package/fesm/362.js +1074 -0
  32. package/fesm/458.js +649 -0
  33. package/fesm/582.js +1247 -0
  34. package/fesm/677.js +7534 -0
  35. package/fesm/719.js +3597 -0
  36. package/fesm/794.js +979 -0
  37. package/fesm/913.js +1620 -0
  38. package/fesm/config/index.js +126 -0
  39. package/fesm/controllers/index.js +27 -0
  40. package/fesm/docs/index.js +82 -0
  41. package/fesm/dtos/index.js +327 -0
  42. package/fesm/entities/index.js +18 -0
  43. package/fesm/enums/index.js +97 -0
  44. package/fesm/guards/index.js +226 -0
  45. package/fesm/index.js +548 -0
  46. package/fesm/interfaces/index.js +80 -0
  47. package/fesm/modules/index.js +25 -0
  48. package/fesm/rule-engine/index.js +21 -0
  49. package/fesm/runtime.js +85 -0
  50. package/fesm/services/index.js +526 -0
  51. package/flow-engine/flow-api-key.d.ts +6 -0
  52. package/flow-engine/flow-code-sandbox.d.ts +5 -0
  53. package/flow-engine/flow-engine.d.ts +22 -0
  54. package/flow-engine/flow-graph.validator.d.ts +20 -0
  55. package/flow-engine/flow-http.client.d.ts +15 -0
  56. package/flow-engine/flow-input.validator.d.ts +7 -0
  57. package/flow-engine/flow-node-handlers.d.ts +5 -0
  58. package/flow-engine/flow-rate-limiter.d.ts +8 -0
  59. package/flow-engine/flow-reference.d.ts +7 -0
  60. package/flow-engine/flow-run.types.d.ts +131 -0
  61. package/flow-engine/flow.errors.d.ts +27 -0
  62. package/flow-engine/flow.types.d.ts +315 -0
  63. package/flow-engine/index.d.ts +4 -0
  64. package/flow-engine/redact.d.ts +3 -0
  65. package/flow-engine/ssrf-guard.d.ts +6 -0
  66. package/guards/flow-access.guard.d.ts +11 -0
  67. package/guards/index.d.ts +1 -0
  68. package/index.d.ts +11 -0
  69. package/interfaces/entity-builder-module.interface.d.ts +28 -0
  70. package/interfaces/field-definition.interface.d.ts +33 -0
  71. package/interfaces/flow-definition.interface.d.ts +24 -0
  72. package/interfaces/generic-record.interface.d.ts +15 -0
  73. package/interfaces/index.d.ts +5 -0
  74. package/interfaces/reference-provider.interface.d.ts +8 -0
  75. package/interfaces/schema-dialect-adapter.interface.d.ts +15 -0
  76. package/modules/entity-builder.module.d.ts +10 -0
  77. package/modules/index.d.ts +1 -0
  78. package/package.json +93 -0
  79. package/rule-engine/index.d.ts +3 -0
  80. package/rule-engine/rule-engine.service.d.ts +40 -0
  81. package/rule-engine/rule-evaluation-context.interface.d.ts +28 -0
  82. package/rule-engine/rule-ip.d.ts +3 -0
  83. package/rule-engine/rule-permission.d.ts +10 -0
  84. package/rule-engine/rule-regex.d.ts +4 -0
  85. package/rule-engine/rule-values.d.ts +5 -0
  86. package/rule-engine/rule.interface.d.ts +79 -0
  87. package/services/database-error.mapper.d.ts +2 -0
  88. package/services/definition-cache.service.d.ts +8 -0
  89. package/services/entity-builder-config.service.d.ts +12 -0
  90. package/services/entity-builder-datasource.provider.d.ts +24 -0
  91. package/services/entity-definition.service.d.ts +17 -0
  92. package/services/entity-flow-scaffold.d.ts +27 -0
  93. package/services/entity-permission.service.d.ts +8 -0
  94. package/services/field-definition.service.d.ts +17 -0
  95. package/services/field-type-conversion.d.ts +15 -0
  96. package/services/field-value-validator.d.ts +17 -0
  97. package/services/flow-definition.service.d.ts +62 -0
  98. package/services/flow-execution.service.d.ts +38 -0
  99. package/services/flow-executor.service.d.ts +41 -0
  100. package/services/flow-reference.provider.d.ts +13 -0
  101. package/services/flow-runtime.service.d.ts +30 -0
  102. package/services/generic-entity-service.factory.d.ts +12 -0
  103. package/services/generic-entity.service.d.ts +67 -0
  104. package/services/identifier-rules.d.ts +9 -0
  105. package/services/index.d.ts +26 -0
  106. package/services/reference-rewrite.d.ts +7 -0
  107. package/services/reference-scanner.service.d.ts +10 -0
  108. package/services/schema-change-executor.service.d.ts +39 -0
  109. package/services/schema-change.types.d.ts +59 -0
  110. package/services/schema-columns.d.ts +26 -0
  111. package/services/schema-dialect-adapter.service.d.ts +13 -0
  112. package/services/schema-evolution.service.d.ts +67 -0
  113. package/services/schema-registry.service.d.ts +13 -0
  114. package/services/schema-sync.service.d.ts +28 -0
@@ -0,0 +1,6 @@
1
+ import { type IFlowNode, type IStoredApiKey } from './flow.types.js';
2
+ export declare const hashApiKey: (key: string) => string;
3
+ export declare const apiKeyPrefix: (key: string) => string;
4
+ export declare function looksLikeApiKey(key: unknown): key is string;
5
+ export declare const apiKeyOpens: (stored: IStoredApiKey | null, presented: unknown) => boolean;
6
+ export declare function sealApiKeys(nodes: IFlowNode[]): IFlowNode[];
@@ -0,0 +1,5 @@
1
+ export interface ICodeRunResult {
2
+ output: unknown;
3
+ logs: string[];
4
+ }
5
+ export declare function runSandboxedCode(code: string, ctx: Record<string, unknown>, timeoutMs: number, node: string): Promise<ICodeRunResult>;
@@ -0,0 +1,22 @@
1
+ import { type IFlowGraph } from './flow.types.js';
2
+ import { type IFlowEnv, type IFlowRunState, type IFlowRunResult, type IFlowSavePoint, type IFlowTraceEntry } from './flow-run.types.js';
3
+ export declare class FlowEngine {
4
+ private readonly env;
5
+ private readonly nodes;
6
+ private readonly edgesFrom;
7
+ constructor(graph: IFlowGraph, env: IFlowEnv);
8
+ walk(state: IFlowRunState): Promise<void>;
9
+ private targets;
10
+ private run;
11
+ private follow;
12
+ private loop;
13
+ }
14
+ export interface IFailureMapping {
15
+ status: 'failed' | 'rejected';
16
+ statusCode: number;
17
+ body: Record<string, unknown>;
18
+ error: string;
19
+ }
20
+ export declare function mapFlowFailure(error: unknown, exposeDetails: boolean): IFailureMapping;
21
+ export declare function lastSavePoint(trace: IFlowTraceEntry[]): IFlowSavePoint | null;
22
+ export declare function successResult(state: IFlowRunState, startedAt: number): IFlowRunResult;
@@ -0,0 +1,20 @@
1
+ import { type IMessageRef } from '@flusys/nestjs-shared/interfaces';
2
+ import { type FlowMessageService, type IFlowEndpoint, type IFlowSettings } from './flow.types.js';
3
+ export interface IFlowValidationResult {
4
+ errors: IMessageRef[];
5
+ warnings: IMessageRef[];
6
+ }
7
+ export interface ICallableFlow {
8
+ isActive: boolean;
9
+ endpoints: Array<Omit<IFlowEndpoint, 'nodeId'>>;
10
+ calls: string[];
11
+ }
12
+ export interface IFlowValidationContext {
13
+ knownEntityCodes?: Set<string>;
14
+ knownFlows?: Map<string, ICallableFlow>;
15
+ messageServices?: Partial<Record<FlowMessageService, boolean>>;
16
+ companyMembers?: boolean;
17
+ }
18
+ export declare function usesPermissionFunction(value: unknown, depth?: number): boolean;
19
+ export declare function validateFlow(flow: IFlowSettings, context?: IFlowValidationContext): IFlowValidationResult;
20
+ export declare function callProblems(caller: IFlowSettings, slug: string, known: Map<string, ICallableFlow>): IMessageRef[];
@@ -0,0 +1,15 @@
1
+ export interface IFlowHttpRequest {
2
+ method: string;
3
+ url: string;
4
+ headers?: Record<string, string>;
5
+ body?: unknown;
6
+ timeoutMs: number;
7
+ allowPrivate?: boolean;
8
+ }
9
+ export interface IFlowHttpResponse {
10
+ status: number;
11
+ ok: boolean;
12
+ headers: Record<string, string>;
13
+ body: unknown;
14
+ }
15
+ export declare function flowHttpRequest(request: IFlowHttpRequest): Promise<IFlowHttpResponse>;
@@ -0,0 +1,7 @@
1
+ import { type IFieldError } from '../services/field-value-validator.js';
2
+ import { type FlowBodyType, type FlowInput, type IFlowInputField } from './flow.types.js';
3
+ export interface IFlowInputResult {
4
+ values: FlowInput;
5
+ errors: IFieldError[];
6
+ }
7
+ export declare function validateFlowInput(schema: IFlowInputField[], body: unknown, bodyType?: FlowBodyType): IFlowInputResult;
@@ -0,0 +1,5 @@
1
+ import { type RuleEvaluationContext } from '../rule-engine/index.js';
2
+ import { type IFlowNode } from './flow.types.js';
3
+ import { type IFlowEnv, type IFlowRunState, type INodeResult } from './flow-run.types.js';
4
+ export declare function evaluationContext(state: IFlowRunState, env?: IFlowEnv): RuleEvaluationContext;
5
+ export declare function runNode(node: IFlowNode, env: IFlowEnv, state: IFlowRunState): Promise<INodeResult>;
@@ -0,0 +1,8 @@
1
+ export declare class FlowRateLimiter {
2
+ private readonly maxKeys;
3
+ private readonly windows;
4
+ constructor(maxKeys?: number);
5
+ hit(key: string, limitPerMinute: number, now?: number): boolean;
6
+ get size(): number;
7
+ private dropExpired;
8
+ }
@@ -0,0 +1,7 @@
1
+ import { type IFlowNode } from './flow.types.js';
2
+ export declare function flowUsesEntity(nodes: IFlowNode[], entityCode: string): boolean;
3
+ export declare function flowRefersToField(nodes: IFlowNode[], entityCode: string, field: string): boolean;
4
+ export declare function rewriteFlowField(nodes: IFlowNode[], entityCode: string, from: string, to: string): {
5
+ nodes: IFlowNode[];
6
+ changed: boolean;
7
+ };
@@ -0,0 +1,131 @@
1
+ import { type IEmailAdapter, type ILoggedUserInfo, type IMessageRef, type INotificationAdapter, type IUserCompanyAccess } from '@flusys/nestjs-shared/interfaces';
2
+ import { type QueryRunner } from 'typeorm';
3
+ import { type IGenericRecord } from '../interfaces/generic-record.interface.js';
4
+ import { type IRulePermissionResolver, type RuleEngineService, type RuleExpression } from '../rule-engine/index.js';
5
+ import { type IFlowHttpRequest, type IFlowHttpResponse } from './flow-http.client.js';
6
+ import { type FlowInput, type FlowRunAs, type FlowRunMode } from './flow.types.js';
7
+ export interface IFlowTraceEntry {
8
+ nodeId: string;
9
+ name: string;
10
+ type: string;
11
+ status: 'ok' | 'error' | 'skipped';
12
+ durationMs: number;
13
+ iteration?: number;
14
+ output?: string;
15
+ error?: IMessageRef;
16
+ logs?: string[];
17
+ }
18
+ export interface IPendingRecordEvent {
19
+ entityCode: string;
20
+ action: 'created' | 'updated' | 'deleted' | 'purged';
21
+ row: IGenericRecord;
22
+ }
23
+ export interface IPendingFlowEvent {
24
+ eventName: string;
25
+ payload: Record<string, unknown>;
26
+ }
27
+ export interface IPendingDelivery {
28
+ delivery: string;
29
+ send: () => Promise<void>;
30
+ }
31
+ export type IPendingEvent = IPendingRecordEvent | IPendingFlowEvent | IPendingDelivery;
32
+ export interface IFlowLoopScope {
33
+ item: unknown;
34
+ index: number;
35
+ parent?: IFlowLoopScope;
36
+ }
37
+ export interface IFlowSavePoint {
38
+ nodeId: string;
39
+ name: string;
40
+ at: string;
41
+ }
42
+ export interface IFlowRunState {
43
+ startAt?: string;
44
+ input: FlowInput;
45
+ vars: Record<string, unknown>;
46
+ context: Record<string, unknown>;
47
+ loop?: IFlowLoopScope;
48
+ request: Record<string, unknown>;
49
+ user: ILoggedUserInfo | null;
50
+ authorization?: string;
51
+ permissions?: IRulePermissionResolver;
52
+ mode: FlowRunMode;
53
+ runAs: FlowRunAs;
54
+ systemAuthorized?: boolean;
55
+ steps: number;
56
+ httpCalls: number;
57
+ messages: number;
58
+ writes: number;
59
+ deadline: number;
60
+ qr?: QueryRunner;
61
+ ownsTransaction?: boolean;
62
+ savedUpTo?: IFlowSavePoint;
63
+ callStack: string[];
64
+ pendingEvents: IPendingEvent[];
65
+ trace: IFlowTraceEntry[];
66
+ response?: {
67
+ status: number;
68
+ body: unknown;
69
+ };
70
+ }
71
+ export interface IFlowEnv {
72
+ ruleEngine: RuleEngineService;
73
+ entityService(entityCode: string, queryRunner?: QueryRunner): Promise<IFlowEntityAccess>;
74
+ callFlow(slug: string, input: unknown, state: IFlowRunState, endpoint?: string): Promise<unknown>;
75
+ http(request: IFlowHttpRequest): Promise<IFlowHttpResponse>;
76
+ publish(eventName: string, payload: Record<string, unknown>, user: ILoggedUserInfo | null): Promise<void>;
77
+ atomic<T>(state: IFlowRunState, work: () => Promise<T>): Promise<T>;
78
+ commit(state: IFlowRunState): Promise<void>;
79
+ companyAccess(userId: string): Promise<IUserCompanyAccess>;
80
+ companyMembers?(companyId: string, branchIds?: string[]): Promise<string[]>;
81
+ assertPermission(code: string, user: ILoggedUserInfo | null): Promise<void>;
82
+ allowPrivateHttp: boolean;
83
+ notifications?: INotificationAdapter;
84
+ email?: IEmailAdapter;
85
+ }
86
+ export interface IFlowEntityAccess {
87
+ insert(dto: Record<string, unknown>, user: ILoggedUserInfo | null, options?: IFlowWriteOptions): Promise<IGenericRecord>;
88
+ update(dto: Record<string, unknown> & {
89
+ id: string;
90
+ }, user: ILoggedUserInfo | null, options?: IFlowWriteOptions): Promise<IGenericRecord>;
91
+ delete(id: string, user: ILoggedUserInfo | null, options?: IFlowWriteOptions): Promise<'deleted' | 'purged'>;
92
+ findById(id: string, options?: IFlowReadOptions): Promise<IGenericRecord>;
93
+ getAll(search: string | undefined, dto: {
94
+ filter?: Record<string, unknown>;
95
+ sort?: Record<string, 'ASC' | 'DESC'>;
96
+ pagination?: {
97
+ currentPage: number;
98
+ pageSize: number;
99
+ };
100
+ }, options?: IFlowReadOptions): Promise<{
101
+ data: IGenericRecord[];
102
+ total: number;
103
+ }>;
104
+ }
105
+ export interface IFlowReadOptions {
106
+ queryRunner?: QueryRunner;
107
+ }
108
+ export interface IFlowWriteOptions extends IFlowReadOptions {
109
+ publishEvents?: boolean;
110
+ }
111
+ export interface INodeResult {
112
+ output?: unknown;
113
+ port?: string;
114
+ items?: unknown[];
115
+ collect?: RuleExpression;
116
+ respond?: {
117
+ status: number;
118
+ body: unknown;
119
+ };
120
+ skipped?: boolean;
121
+ logs?: string[];
122
+ }
123
+ export interface IFlowRunResult {
124
+ status: 'success' | 'failed' | 'rejected';
125
+ statusCode: number;
126
+ body: unknown;
127
+ error?: string;
128
+ trace: IFlowTraceEntry[];
129
+ durationMs: number;
130
+ savedUpTo?: IFlowSavePoint;
131
+ }
@@ -0,0 +1,27 @@
1
+ import { type IValidationError } from '@flusys/nestjs-shared/exceptions';
2
+ import { type IMessageRef } from '@flusys/nestjs-shared/interfaces';
3
+ export declare class FlowKeyedError extends Error implements IMessageRef {
4
+ readonly messageKey: string;
5
+ readonly messageVariables?: Record<string, unknown> | undefined;
6
+ constructor(messageKey: string, messageVariables?: Record<string, unknown> | undefined, detail?: string);
7
+ }
8
+ export declare class FlowHttpError extends Error {
9
+ readonly status: number;
10
+ readonly errors?: IValidationError[] | undefined;
11
+ readonly messageKey: string;
12
+ readonly messageVariables: Record<string, unknown>;
13
+ constructor(status: number, message: string, errors?: IValidationError[] | undefined, reason?: IMessageRef);
14
+ }
15
+ export declare class FlowLimitError extends FlowKeyedError {
16
+ }
17
+ export declare class FlowCodeError extends FlowKeyedError {
18
+ readonly logs: string[];
19
+ constructor(messageKey: string, messageVariables: Record<string, unknown>, detail: string, logs?: string[]);
20
+ }
21
+ export declare class FlowNodeError extends Error {
22
+ readonly nodeId: string;
23
+ readonly nodeName: string;
24
+ readonly cause: unknown;
25
+ constructor(nodeId: string, nodeName: string, cause: unknown);
26
+ }
27
+ export declare function errorRef(error: unknown): IMessageRef;
@@ -0,0 +1,315 @@
1
+ import { type RecordFilterOp } from '../interfaces/generic-record.interface.js';
2
+ import { type RuleExpression, type RuleGroup } from '../rule-engine/index.js';
3
+ export declare const FLOW_NODE_TYPES: readonly ["trigger", "validate", "permission_check", "company_branch_check", "set", "condition", "switch", "foreach", "entity_insert", "entity_update", "entity_delete", "entity_get", "entity_query", "commit", "call_flow", "http_request", "publish_event", "send_notification", "send_email", "respond", "code"];
4
+ export type FlowNodeType = (typeof FLOW_NODE_TYPES)[number];
5
+ export declare const NON_CONTINUABLE_NODE_TYPES: ReadonlySet<FlowNodeType>;
6
+ export declare const FLOW_AUTH_MODES: readonly ["public", "api_key", "jwt", "permission", "internal"];
7
+ export type FlowAuthMode = (typeof FLOW_AUTH_MODES)[number];
8
+ export declare const DEFAULT_AUTH_MODE: FlowAuthMode;
9
+ export declare const KEYLESS_AUTH_MODES: ReadonlySet<FlowAuthMode>;
10
+ export declare const FLOW_RUN_AS: readonly ["caller", "system"];
11
+ export type FlowRunAs = (typeof FLOW_RUN_AS)[number];
12
+ export type FlowRunMode = 'live' | 'dry_run';
13
+ export declare const FLOW_BODY_TYPES: readonly ["object", "list"];
14
+ export type FlowBodyType = (typeof FLOW_BODY_TYPES)[number];
15
+ export type FlowInput = Record<string, unknown> | unknown[];
16
+ export declare const FLOW_INPUT_TYPES: readonly ["string", "text", "number", "integer", "boolean", "date", "datetime", "email", "uuid", "object", "array", "choice"];
17
+ export type FlowInputType = (typeof FLOW_INPUT_TYPES)[number];
18
+ export type FlowInputItemType = Exclude<FlowInputType, 'array'>;
19
+ export interface IFlowInputField {
20
+ name: string;
21
+ label?: string;
22
+ type: FlowInputType;
23
+ required?: boolean;
24
+ default?: unknown;
25
+ min?: number;
26
+ max?: number;
27
+ minLength?: number;
28
+ maxLength?: number;
29
+ options?: string[];
30
+ itemType?: FlowInputItemType;
31
+ fields?: IFlowInputField[];
32
+ }
33
+ export declare const nodeLabel: (node: Pick<IFlowNode, "id" | "name">) => string;
34
+ export interface IFlowNode {
35
+ id: string;
36
+ type: FlowNodeType;
37
+ name: string;
38
+ position: {
39
+ x: number;
40
+ y: number;
41
+ };
42
+ config: Record<string, unknown>;
43
+ onError?: 'stop' | 'continue';
44
+ }
45
+ export interface IFlowEdge {
46
+ id: string;
47
+ from: string;
48
+ port: string;
49
+ to: string;
50
+ }
51
+ export interface IFlowGraph {
52
+ nodes: IFlowNode[];
53
+ edges: IFlowEdge[];
54
+ }
55
+ export interface IFlowSettings extends IFlowGraph {
56
+ slug: string;
57
+ }
58
+ export type ExpressionMap = Record<string, RuleExpression>;
59
+ export interface IValidateCheck {
60
+ id: string;
61
+ rule: RuleGroup;
62
+ message: string;
63
+ field?: string;
64
+ }
65
+ export type ValidateMode = 'all' | 'first';
66
+ export interface IValidateConfig {
67
+ checks: IValidateCheck[];
68
+ mode?: ValidateMode;
69
+ statusCode?: number;
70
+ }
71
+ export type PermissionDeniedMode = 'reject' | 'branch';
72
+ export interface IPermissionCheckConfig {
73
+ codes: string[] | string;
74
+ match?: 'any' | 'all';
75
+ onDenied?: PermissionDeniedMode;
76
+ statusCode?: number;
77
+ message?: string;
78
+ }
79
+ export interface ICompanyBranchCheckConfig {
80
+ companyIds?: RuleExpression;
81
+ branchIds?: RuleExpression;
82
+ onDenied?: PermissionDeniedMode;
83
+ statusCode?: number;
84
+ message?: string;
85
+ }
86
+ export interface ISetConfig {
87
+ values: ExpressionMap;
88
+ }
89
+ export interface IConditionConfig {
90
+ rule: RuleGroup;
91
+ }
92
+ export interface ISwitchConfig {
93
+ value: RuleExpression;
94
+ cases: Array<{
95
+ id: string;
96
+ equals: string | number | boolean | null;
97
+ }>;
98
+ }
99
+ export interface IForeachConfig {
100
+ items: RuleExpression;
101
+ maxItems?: number;
102
+ collect?: RuleExpression;
103
+ }
104
+ export declare const RECORD_WRITE_TARGETS: readonly ["one", "many", "filter"];
105
+ export type RecordWriteTarget = (typeof RECORD_WRITE_TARGETS)[number];
106
+ export type RecordNotFoundMode = 'error' | 'skip' | 'insert';
107
+ export interface IChildInsert {
108
+ as: string;
109
+ entityCode: string;
110
+ parentField: string;
111
+ items: RuleExpression;
112
+ fields: ExpressionMap;
113
+ }
114
+ export interface IEntityInsertConfig {
115
+ entityCode: string;
116
+ target?: Extract<RecordWriteTarget, 'one' | 'many'>;
117
+ fields: ExpressionMap;
118
+ items?: RuleExpression;
119
+ children?: IChildInsert[];
120
+ }
121
+ export interface IEntityUpdateConfig {
122
+ entityCode: string;
123
+ target?: RecordWriteTarget;
124
+ id?: RuleExpression;
125
+ items?: RuleExpression;
126
+ filter?: FlowFilterMap;
127
+ limit?: number;
128
+ fields: ExpressionMap;
129
+ onNotFound?: RecordNotFoundMode;
130
+ }
131
+ export interface IEntityDeleteConfig {
132
+ entityCode: string;
133
+ target?: RecordWriteTarget;
134
+ id?: RuleExpression;
135
+ items?: RuleExpression;
136
+ filter?: FlowFilterMap;
137
+ limit?: number;
138
+ onNotFound?: Exclude<RecordNotFoundMode, 'insert'>;
139
+ }
140
+ export interface IEntityGetConfig {
141
+ entityCode: string;
142
+ id: RuleExpression;
143
+ onNotFound?: 'error' | 'null';
144
+ }
145
+ export interface IFlowFilterCondition {
146
+ op: RecordFilterOp;
147
+ value?: RuleExpression;
148
+ }
149
+ export type FlowFilterMap = Record<string, RuleExpression | IFlowFilterCondition>;
150
+ export interface IEntityQueryConfig {
151
+ entityCode: string;
152
+ filter?: FlowFilterMap;
153
+ search?: RuleExpression;
154
+ sort?: {
155
+ field: string;
156
+ direction: 'ASC' | 'DESC';
157
+ };
158
+ limit?: number;
159
+ }
160
+ export interface ITriggerConfig {
161
+ path?: string;
162
+ bodyType?: FlowBodyType;
163
+ inputSchema?: IFlowInputField[];
164
+ authMode?: FlowAuthMode;
165
+ permissionCode?: string;
166
+ runAs?: FlowRunAs;
167
+ isTransactional?: boolean;
168
+ timeoutMs?: number;
169
+ rateLimitPerMinute?: number;
170
+ apiKey?: string | IStoredApiKey;
171
+ }
172
+ export interface IStoredApiKey {
173
+ prefix: string;
174
+ hash: string;
175
+ }
176
+ export declare function isStoredApiKey(value: unknown): value is IStoredApiKey;
177
+ export interface ICallFlowConfig {
178
+ flowSlug: string;
179
+ endpoint?: string;
180
+ input?: ExpressionMap;
181
+ inputList?: RuleExpression;
182
+ }
183
+ export interface IHttpRequestConfig {
184
+ method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
185
+ url: RuleExpression;
186
+ headers?: ExpressionMap;
187
+ body?: ExpressionMap;
188
+ timeoutMs?: number;
189
+ forwardAuth?: boolean;
190
+ }
191
+ export interface IPublishEventConfig {
192
+ eventName: string;
193
+ payload: ExpressionMap;
194
+ }
195
+ export declare const FLOW_MESSAGE_SERVICES: {
196
+ readonly send_notification: "notification";
197
+ readonly send_email: "email";
198
+ };
199
+ export type FlowMessageNodeType = keyof typeof FLOW_MESSAGE_SERVICES;
200
+ export type FlowMessageService = (typeof FLOW_MESSAGE_SERVICES)[FlowMessageNodeType];
201
+ export declare const isMessageNode: (type: string) => type is FlowMessageNodeType;
202
+ export declare const FLOW_NOTIFICATION_TYPES: readonly ["info", "success", "warning", "error"];
203
+ export type FlowNotificationType = (typeof FLOW_NOTIFICATION_TYPES)[number];
204
+ export declare const FLOW_NOTIFICATION_TARGETS: readonly ["one", "many", "company"];
205
+ export type FlowNotificationTarget = (typeof FLOW_NOTIFICATION_TARGETS)[number];
206
+ export declare const FLOW_EMAIL_TARGETS: readonly ["one", "many"];
207
+ export type FlowEmailTarget = (typeof FLOW_EMAIL_TARGETS)[number];
208
+ export interface ISendNotificationConfig {
209
+ target?: FlowNotificationTarget;
210
+ items?: RuleExpression;
211
+ userIds?: RuleExpression;
212
+ companyIds?: RuleExpression;
213
+ branchIds?: RuleExpression;
214
+ title: RuleExpression;
215
+ message?: RuleExpression;
216
+ type?: FlowNotificationType;
217
+ data?: ExpressionMap;
218
+ companyId?: RuleExpression;
219
+ realtime?: boolean;
220
+ }
221
+ export declare const FLOW_EMAIL_MODES: readonly ["content", "template"];
222
+ export type FlowEmailMode = (typeof FLOW_EMAIL_MODES)[number];
223
+ export declare const FLOW_EMAIL_FORMATS: readonly ["text", "html"];
224
+ export type FlowEmailFormat = (typeof FLOW_EMAIL_FORMATS)[number];
225
+ export interface ISendEmailConfig {
226
+ target?: FlowEmailTarget;
227
+ items?: RuleExpression;
228
+ to: RuleExpression;
229
+ cc?: RuleExpression;
230
+ bcc?: RuleExpression;
231
+ replyTo?: RuleExpression;
232
+ mode?: FlowEmailMode;
233
+ subject?: RuleExpression;
234
+ body?: RuleExpression;
235
+ format?: FlowEmailFormat;
236
+ templateSlug?: string;
237
+ variables?: ExpressionMap;
238
+ emailConfigId?: string;
239
+ }
240
+ export interface IRespondConfig {
241
+ statusCode: number;
242
+ body?: ExpressionMap;
243
+ bodyExpression?: RuleExpression;
244
+ }
245
+ export interface ICodeConfig {
246
+ code: string;
247
+ timeoutMs?: number;
248
+ }
249
+ export declare const FLOW_LIMITS: {
250
+ readonly MAX_NODES: 100;
251
+ readonly MAX_EDGES: 300;
252
+ readonly MAX_STEPS_PER_RUN: 5000;
253
+ readonly MAX_FOREACH_ITEMS: 1000;
254
+ readonly MAX_LOOP_DEPTH: 3;
255
+ readonly MAX_CALL_DEPTH: 5;
256
+ readonly MAX_HTTP_CALLS: 10;
257
+ readonly MAX_MESSAGES_PER_RUN: 100;
258
+ readonly MAX_NOTIFICATION_RECIPIENTS: 500;
259
+ readonly MAX_COMPANY_NOTIFICATION_RECIPIENTS: 5000;
260
+ readonly MAX_EMAIL_RECIPIENTS: 50;
261
+ readonly MAX_NOTIFICATION_TITLE_LENGTH: 255;
262
+ readonly MAX_EMAIL_SUBJECT_LENGTH: 255;
263
+ readonly MAX_EMAIL_TEMPLATE_SLUG_LENGTH: 255;
264
+ readonly MAX_HTTP_TIMEOUT_MS: 15000;
265
+ readonly MAX_HTTP_RESPONSE_BYTES: 1000000;
266
+ readonly MAX_QUERY_LIMIT: 200;
267
+ readonly MAX_WRITE_ITEMS: 1000;
268
+ readonly DEFAULT_WRITE_FILTER_LIMIT: 100;
269
+ readonly MAX_CHILD_INSERTS: 10;
270
+ readonly MAX_WRITES_PER_RUN: 5000;
271
+ readonly DEFAULT_TIMEOUT_MS: 30000;
272
+ readonly MIN_TIMEOUT_MS: 1000;
273
+ readonly MAX_TIMEOUT_MS: 120000;
274
+ readonly DEFAULT_RATE_LIMIT_PER_MINUTE: 60;
275
+ readonly MAX_RATE_LIMIT_PER_MINUTE: 100000;
276
+ readonly TRACE_PREVIEW_CHARS: 2000;
277
+ readonly MAX_INPUT_FIELDS: 50;
278
+ readonly MAX_INPUT_DEPTH: 4;
279
+ readonly MAX_VALIDATE_CHECKS: 50;
280
+ readonly MAX_CODE_LENGTH: 20000;
281
+ readonly DEFAULT_CODE_TIMEOUT_MS: 1000;
282
+ readonly MIN_CODE_TIMEOUT_MS: 10;
283
+ readonly MAX_CODE_TIMEOUT_MS: 5000;
284
+ readonly CODE_MEMORY_LIMIT_BYTES: number;
285
+ readonly CODE_STACK_SIZE_BYTES: number;
286
+ readonly MAX_CODE_OUTPUT_BYTES: 1000000;
287
+ readonly MAX_CODE_LOG_LINES: 50;
288
+ readonly MAX_CODE_LOG_LINE_CHARS: 500;
289
+ };
290
+ export declare const FLOW_NODE_ID_PATTERN: RegExp;
291
+ export declare const FLOW_SLUG_PATTERN: RegExp;
292
+ export declare const FLOW_INPUT_NAME_PATTERN: RegExp;
293
+ export declare const FLOW_ENDPOINT_PATH_PATTERN: RegExp;
294
+ export declare const FLOW_ID_PATTERN: RegExp;
295
+ export interface IFlowEndpoint {
296
+ nodeId: string;
297
+ path: string | null;
298
+ bodyType: FlowBodyType;
299
+ inputSchema: IFlowInputField[];
300
+ authMode: FlowAuthMode;
301
+ permissionCode: string | null;
302
+ runAs: FlowRunAs;
303
+ isTransactional: boolean;
304
+ timeoutMs: number;
305
+ rateLimitPerMinute: number;
306
+ apiKey: IStoredApiKey | null;
307
+ }
308
+ type EndpointSource = Pick<IFlowSettings, 'nodes'>;
309
+ export declare const isFunctionFlow: (flow: EndpointSource) => boolean;
310
+ export declare function triggerPath(node: Pick<IFlowNode, 'config'>): string | null;
311
+ export declare function flowEndpoints(flow: EndpointSource): IFlowEndpoint[];
312
+ export declare function findEndpoint(flow: EndpointSource, path?: string | null): IFlowEndpoint | undefined;
313
+ export declare function startEndpoint(flow: EndpointSource, nodeId?: string): IFlowEndpoint | undefined;
314
+ export declare function portsOf(node: Pick<IFlowNode, 'type' | 'config'>): string[];
315
+ export {};
@@ -0,0 +1,4 @@
1
+ export * from './flow.types.js';
2
+ export * from './flow-run.types.js';
3
+ export * from './flow.errors.js';
4
+ export * from './flow-graph.validator.js';
@@ -0,0 +1,3 @@
1
+ export declare const SENSITIVE_KEY: RegExp;
2
+ export declare function redactSensitive(value: unknown, depth?: number): unknown;
3
+ export declare function preview(value: unknown, maxChars: number): string;
@@ -0,0 +1,6 @@
1
+ import { FlowKeyedError } from './flow.errors.js';
2
+ export declare function isPrivateAddress(address: string): boolean;
3
+ export declare class FlowUrlError extends FlowKeyedError {
4
+ }
5
+ export declare function assertUrlAllowed(rawUrl: string, allowPrivate: boolean): URL;
6
+ export declare function safeLookup(allowPrivate: boolean): (hostname: string, options: unknown, callback: (...args: unknown[]) => void) => void;
@@ -0,0 +1,11 @@
1
+ import { SharedPermissionCacheService } from '@flusys/nestjs-shared/modules';
2
+ import { type CanActivate, type ExecutionContext } from '@nestjs/common';
3
+ import { ModuleRef } from '@nestjs/core';
4
+ export declare class FlowAccessGuard implements CanActivate {
5
+ private readonly moduleRef;
6
+ private readonly permissionCache;
7
+ private jwtGuard?;
8
+ constructor(moduleRef: ModuleRef, permissionCache: SharedPermissionCacheService);
9
+ canActivate(context: ExecutionContext): Promise<boolean>;
10
+ private authenticate;
11
+ }
@@ -0,0 +1 @@
1
+ export * from './flow-access.guard.js';
package/index.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export * from './config/index.js';
2
+ export * from './controllers/index.js';
3
+ export * from './dtos/index.js';
4
+ export * from './entities/index.js';
5
+ export * from './flow-engine/index.js';
6
+ export * from './enums/index.js';
7
+ export * from './guards/index.js';
8
+ export * from './interfaces/index.js';
9
+ export * from './modules/index.js';
10
+ export * from './rule-engine/index.js';
11
+ export * from './services/index.js';
@@ -0,0 +1,28 @@
1
+ import { type ModuleMetadata, type Provider, type Type } from '@nestjs/common';
2
+ import { type IBootstrapAppConfig, type IDataSourceServiceOptions, type IDynamicModuleConfig } from '@flusys/nestjs-core';
3
+ import { type IModuleEventsConfig } from '@flusys/nestjs-shared/interfaces';
4
+ export interface IEntityBuilderConfig extends IDataSourceServiceOptions {
5
+ events?: IModuleEventsConfig;
6
+ flows?: {
7
+ allowPrivateHttp?: boolean;
8
+ };
9
+ }
10
+ export interface EntityBuilderModuleOptions extends IDynamicModuleConfig {
11
+ bootstrapAppConfig?: IBootstrapAppConfig;
12
+ config?: IEntityBuilderConfig;
13
+ providers?: Provider[];
14
+ }
15
+ export interface EntityBuilderOptionsFactory {
16
+ createEntityBuilderOptions(): Promise<IEntityBuilderConfig> | IEntityBuilderConfig;
17
+ }
18
+ export interface EntityBuilderModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
19
+ global?: boolean;
20
+ includeController?: boolean;
21
+ bootstrapAppConfig?: IBootstrapAppConfig;
22
+ useFactory?: (...args: any[]) => Promise<IEntityBuilderConfig> | IEntityBuilderConfig;
23
+ inject?: any[];
24
+ useExisting?: Type<EntityBuilderOptionsFactory>;
25
+ useClass?: Type<EntityBuilderOptionsFactory>;
26
+ config?: IEntityBuilderConfig;
27
+ providers?: Provider[];
28
+ }