@wenlarge/communication 1.2.5 → 1.2.8

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.
@@ -14,6 +14,7 @@ export interface RegisterRequest {
14
14
  name: string;
15
15
  email: string;
16
16
  password: string;
17
+ phoneNumber?: string | undefined;
17
18
  }
18
19
  export interface GetMeRequest {
19
20
  jwt: string;
@@ -7,12 +7,6 @@ export interface ExecuteNodeRequest {
7
7
  config?: {
8
8
  [key: string]: any;
9
9
  } | undefined;
10
- inputSchema?: {
11
- [key: string]: any;
12
- } | undefined;
13
- env?: {
14
- [key: string]: any;
15
- } | undefined;
16
10
  }
17
11
  export interface ExecuteNodeResponse {
18
12
  output?: {
@@ -8,8 +8,9 @@ function sanitize(value) {
8
8
  return value;
9
9
  if (typeof value === "function")
10
10
  return undefined;
11
- if (Array.isArray(value))
11
+ if (Array.isArray(value)) {
12
12
  return value.map(sanitize);
13
+ }
13
14
  if (typeof value === "object") {
14
15
  const clean = Object.create(null);
15
16
  for (const key of Object.keys(value)) {
@@ -21,10 +22,8 @@ function sanitize(value) {
21
22
  }
22
23
  return value;
23
24
  }
24
- function resolveConfigValue(value, input, env) {
25
+ function resolveStringValue(value, input, env) {
25
26
  var _a;
26
- if (typeof value !== "string")
27
- return value;
28
27
  const parser = new expr_eval_1.Parser();
29
28
  parser.consts = {};
30
29
  parser.functions = {};
@@ -77,3 +76,21 @@ function resolveConfigValue(value, input, env) {
77
76
  }
78
77
  return value;
79
78
  }
79
+ function resolveConfigValue(value, input, env) {
80
+ if (typeof value === "string") {
81
+ return resolveStringValue(value, input, env);
82
+ }
83
+ if (Array.isArray(value)) {
84
+ return value.map((item) => resolveConfigValue(item, input, env));
85
+ }
86
+ if (value && typeof value === "object") {
87
+ const clean = Object.create(null);
88
+ for (const key of Object.keys(value)) {
89
+ if (FORBIDDEN_KEYS.has(key))
90
+ continue;
91
+ clean[key] = resolveConfigValue(value[key], input, env);
92
+ }
93
+ return clean;
94
+ }
95
+ return value;
96
+ }
package/dist/index.d.ts CHANGED
@@ -13,4 +13,5 @@ export * as ExecutorCore from "./generated/executor-core";
13
13
  export * from "./config/notification-config";
14
14
  export * as Notification from "./generated/notification";
15
15
  export * from "./kafka/kafka-topics";
16
+ export * from "./kafka/commit-kafka-offset";
16
17
  export { Struct, Value, ListValue } from "./generated/google/protobuf/struct";
package/dist/index.js CHANGED
@@ -53,6 +53,7 @@ exports.ExecutorCore = __importStar(require("./generated/executor-core"));
53
53
  __exportStar(require("./config/notification-config"), exports);
54
54
  exports.Notification = __importStar(require("./generated/notification"));
55
55
  __exportStar(require("./kafka/kafka-topics"), exports);
56
+ __exportStar(require("./kafka/commit-kafka-offset"), exports);
56
57
  var struct_1 = require("./generated/google/protobuf/struct");
57
58
  Object.defineProperty(exports, "Struct", { enumerable: true, get: function () { return struct_1.Struct; } });
58
59
  Object.defineProperty(exports, "Value", { enumerable: true, get: function () { return struct_1.Value; } });
@@ -0,0 +1,16 @@
1
+ type KafkaOffsetContext = {
2
+ getConsumer(): {
3
+ commitOffsets(offsets: Array<{
4
+ topic: string;
5
+ partition: number;
6
+ offset: string;
7
+ }>): Promise<void>;
8
+ };
9
+ getTopic(): string;
10
+ getPartition(): number;
11
+ getMessage(): {
12
+ offset: string;
13
+ };
14
+ };
15
+ export declare function commitKafkaOffset(ctx: KafkaOffsetContext): Promise<void>;
16
+ export {};
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.commitKafkaOffset = commitKafkaOffset;
4
+ async function commitKafkaOffset(ctx) {
5
+ const consumer = ctx.getConsumer();
6
+ const topic = ctx.getTopic();
7
+ const partition = ctx.getPartition();
8
+ const message = ctx.getMessage();
9
+ const nextOffset = (BigInt(message.offset) + BigInt(1)).toString();
10
+ await consumer.commitOffsets([{ topic, partition, offset: nextOffset }]);
11
+ }
@@ -2,6 +2,10 @@ export declare const KafkaTopics: {
2
2
  readonly EXECUTION_COMPLETED: "execution.completed";
3
3
  readonly EXECUTION_FAILED: "execution.failed";
4
4
  readonly EXECUTION_WAITING: "execution.waiting";
5
- readonly NOTIFICATION_EMAIL: "notification.email";
6
- readonly NOTIFICATION_SMS: "notification.sms";
5
+ readonly EMAIL_WAITING: "email.waiting";
6
+ readonly EMAIL_COMPLETED: "email.completed";
7
+ readonly EMAIL_FAILED: "email.failed";
8
+ readonly SMS_WAITING: "sms.waiting";
9
+ readonly SMS_COMPLETED: "sms.completed";
10
+ readonly SMS_FAILED: "sms.failed";
7
11
  };
@@ -5,6 +5,10 @@ exports.KafkaTopics = {
5
5
  EXECUTION_COMPLETED: "execution.completed",
6
6
  EXECUTION_FAILED: "execution.failed",
7
7
  EXECUTION_WAITING: "execution.waiting",
8
- NOTIFICATION_EMAIL: "notification.email",
9
- NOTIFICATION_SMS: "notification.sms",
8
+ EMAIL_WAITING: "email.waiting",
9
+ EMAIL_COMPLETED: "email.completed",
10
+ EMAIL_FAILED: "email.failed",
11
+ SMS_WAITING: "sms.waiting",
12
+ SMS_COMPLETED: "sms.completed",
13
+ SMS_FAILED: "sms.failed",
10
14
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wenlarge/communication",
3
- "version": "1.2.5",
3
+ "version": "1.2.8",
4
4
  "description": "Shared gRPC proto interfaces and generated clients for Wenlarge microservices.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/proto/auth.proto CHANGED
@@ -29,6 +29,7 @@ message RegisterRequest {
29
29
  string name = 1;
30
30
  string email = 2;
31
31
  string password = 3;
32
+ optional string phoneNumber = 4;
32
33
  }
33
34
 
34
35
  message GetMeRequest {
@@ -7,8 +7,6 @@ message ExecuteNodeRequest {
7
7
  string nodeTypeId = 1;
8
8
  string nodeId = 2;
9
9
  google.protobuf.Struct config = 3;
10
- google.protobuf.Struct inputSchema = 4;
11
- google.protobuf.Struct env = 5;
12
10
  }
13
11
 
14
12
  message ExecuteNodeResponse {
@@ -26,6 +26,7 @@ export interface RegisterRequest {
26
26
  name: string;
27
27
  email: string;
28
28
  password: string;
29
+ phoneNumber?: string | undefined;
29
30
  }
30
31
 
31
32
  export interface GetMeRequest {
@@ -17,8 +17,6 @@ export interface ExecuteNodeRequest {
17
17
  nodeTypeId: string;
18
18
  nodeId: string;
19
19
  config?: { [key: string]: any } | undefined;
20
- inputSchema?: { [key: string]: any } | undefined;
21
- env?: { [key: string]: any } | undefined;
22
20
  }
23
21
 
24
22
  export interface ExecuteNodeResponse {
@@ -1,31 +0,0 @@
1
- import { CallHandler, ExecutionContext, NestInterceptor } from "@nestjs/common";
2
- import { Observable } from "rxjs";
3
- export interface GrpcStructInterceptorOptions {
4
- /**
5
- * Recursively unwrap `google.protobuf.Struct` in the incoming RPC payload (default: true).
6
- */
7
- unwrapRequest?: boolean;
8
- /**
9
- * Top-level response keys whose plain JSON values should be wrapped to Struct before serialization.
10
- * Example: `['output']` for ExecuteNodeResponse.
11
- */
12
- wrapResponsePaths?: string[];
13
- }
14
- /**
15
- * gRPC RPC interceptor: unwrap Struct in requests, optionally wrap plain objects to Struct on responses.
16
- *
17
- * @example
18
- * ```ts
19
- * app.useGlobalInterceptors(
20
- * new GrpcStructInterceptor({
21
- * unwrapRequest: true,
22
- * wrapResponsePaths: ['output'],
23
- * }),
24
- * );
25
- * ```
26
- */
27
- export declare class GrpcStructInterceptor implements NestInterceptor {
28
- private readonly options;
29
- constructor(options?: GrpcStructInterceptorOptions);
30
- intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
31
- }
@@ -1,97 +0,0 @@
1
- "use strict";
2
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
- var _, done = false;
8
- for (var i = decorators.length - 1; i >= 0; i--) {
9
- var context = {};
10
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
- if (kind === "accessor") {
15
- if (result === void 0) continue;
16
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
- if (_ = accept(result.get)) descriptor.get = _;
18
- if (_ = accept(result.set)) descriptor.set = _;
19
- if (_ = accept(result.init)) initializers.unshift(_);
20
- }
21
- else if (_ = accept(result)) {
22
- if (kind === "field") initializers.unshift(_);
23
- else descriptor[key] = _;
24
- }
25
- }
26
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
- done = true;
28
- };
29
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
- var useValue = arguments.length > 2;
31
- for (var i = 0; i < initializers.length; i++) {
32
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
- }
34
- return useValue ? value : void 0;
35
- };
36
- var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
37
- if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
38
- return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
39
- };
40
- Object.defineProperty(exports, "__esModule", { value: true });
41
- exports.GrpcStructInterceptor = void 0;
42
- const common_1 = require("@nestjs/common");
43
- const operators_1 = require("rxjs/operators");
44
- const struct_deep_1 = require("../helpers/struct-deep");
45
- /**
46
- * gRPC RPC interceptor: unwrap Struct in requests, optionally wrap plain objects to Struct on responses.
47
- *
48
- * @example
49
- * ```ts
50
- * app.useGlobalInterceptors(
51
- * new GrpcStructInterceptor({
52
- * unwrapRequest: true,
53
- * wrapResponsePaths: ['output'],
54
- * }),
55
- * );
56
- * ```
57
- */
58
- let GrpcStructInterceptor = (() => {
59
- let _classDecorators = [(0, common_1.Injectable)()];
60
- let _classDescriptor;
61
- let _classExtraInitializers = [];
62
- let _classThis;
63
- var GrpcStructInterceptor = _classThis = class {
64
- constructor(options = {}) {
65
- this.options = options;
66
- }
67
- intercept(context, next) {
68
- var _a;
69
- if (context.getType() !== "rpc") {
70
- return next.handle();
71
- }
72
- const args = context.getArgs();
73
- if (this.options.unwrapRequest !== false && args[0] != null) {
74
- args[0] = (0, struct_deep_1.deepUnwrapStructs)(args[0]);
75
- }
76
- const paths = (_a = this.options.wrapResponsePaths) !== null && _a !== void 0 ? _a : [];
77
- if (paths.length === 0) {
78
- return next.handle();
79
- }
80
- return next.handle().pipe((0, operators_1.map)((data) => {
81
- if (data == null || typeof data !== "object")
82
- return data;
83
- return (0, struct_deep_1.wrapPlainObjectsAtPaths)(data, paths);
84
- }));
85
- }
86
- };
87
- __setFunctionName(_classThis, "GrpcStructInterceptor");
88
- (() => {
89
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
90
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
91
- GrpcStructInterceptor = _classThis = _classDescriptor.value;
92
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
93
- __runInitializers(_classThis, _classExtraInitializers);
94
- })();
95
- return GrpcStructInterceptor = _classThis;
96
- })();
97
- exports.GrpcStructInterceptor = GrpcStructInterceptor;
@@ -1,19 +0,0 @@
1
- import type { Struct } from "../generated/google/protobuf/struct";
2
- /**
3
- * Heuristic: value is a wire-format google.protobuf.Struct (fields map to protobuf Values).
4
- */
5
- export declare function isStructLike(value: unknown): value is Struct;
6
- /**
7
- * Recursively converts nested protobuf Struct instances to plain JSON objects.
8
- */
9
- export declare function deepUnwrapStructs(value: unknown): unknown;
10
- /**
11
- * If the value is still wire-format Struct, unwrap once; otherwise return as-is.
12
- * Use in services when an interceptor may or may not have run.
13
- */
14
- export declare function normalizeMaybeStruct<T>(value: T | undefined): T | Record<string, unknown> | undefined;
15
- /**
16
- * Wraps plain objects at the given top-level keys into google.protobuf.Struct.
17
- * Skips values that already look like Struct.
18
- */
19
- export declare function wrapPlainObjectsAtPaths(data: Record<string, unknown>, paths: string[]): Record<string, unknown>;
@@ -1,88 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isStructLike = isStructLike;
4
- exports.deepUnwrapStructs = deepUnwrapStructs;
5
- exports.normalizeMaybeStruct = normalizeMaybeStruct;
6
- exports.wrapPlainObjectsAtPaths = wrapPlainObjectsAtPaths;
7
- const struct_1 = require("../generated/google/protobuf/struct");
8
- /**
9
- * Heuristic: value is a wire-format google.protobuf.Struct (fields map to protobuf Values).
10
- */
11
- function isStructLike(value) {
12
- if (!value || typeof value !== "object" || Array.isArray(value))
13
- return false;
14
- if (!("fields" in value))
15
- return false;
16
- const fields = value.fields;
17
- if (fields === null || typeof fields !== "object")
18
- return false;
19
- const keys = Object.keys(fields);
20
- if (keys.length === 0)
21
- return true;
22
- const sample = fields[keys[0]];
23
- if (!sample || typeof sample !== "object" || Array.isArray(sample)) {
24
- return false;
25
- }
26
- return ("stringValue" in sample ||
27
- "numberValue" in sample ||
28
- "boolValue" in sample ||
29
- "nullValue" in sample ||
30
- "structValue" in sample ||
31
- "listValue" in sample);
32
- }
33
- /**
34
- * Recursively converts nested protobuf Struct instances to plain JSON objects.
35
- */
36
- function deepUnwrapStructs(value) {
37
- if (value === null || value === undefined)
38
- return value;
39
- if (value instanceof Date)
40
- return value;
41
- if (typeof Buffer !== "undefined" && Buffer.isBuffer(value))
42
- return value;
43
- if (Array.isArray(value))
44
- return value.map(deepUnwrapStructs);
45
- if (typeof value !== "object")
46
- return value;
47
- if (isStructLike(value)) {
48
- return struct_1.Struct.unwrap(value);
49
- }
50
- const obj = value;
51
- const out = {};
52
- for (const k of Object.keys(obj)) {
53
- out[k] = deepUnwrapStructs(obj[k]);
54
- }
55
- return out;
56
- }
57
- /**
58
- * If the value is still wire-format Struct, unwrap once; otherwise return as-is.
59
- * Use in services when an interceptor may or may not have run.
60
- */
61
- function normalizeMaybeStruct(value) {
62
- if (value === undefined || value === null)
63
- return value;
64
- if (typeof value === "object" && !Array.isArray(value) && isStructLike(value)) {
65
- return struct_1.Struct.unwrap(value);
66
- }
67
- return value;
68
- }
69
- /**
70
- * Wraps plain objects at the given top-level keys into google.protobuf.Struct.
71
- * Skips values that already look like Struct.
72
- */
73
- function wrapPlainObjectsAtPaths(data, paths) {
74
- if (!data || typeof data !== "object")
75
- return data;
76
- const result = { ...data };
77
- for (const key of paths) {
78
- if (!(key in result))
79
- continue;
80
- const v = result[key];
81
- if (v == null || typeof v !== "object" || Array.isArray(v))
82
- continue;
83
- if (isStructLike(v))
84
- continue;
85
- result[key] = struct_1.Struct.wrap(v);
86
- }
87
- return result;
88
- }