@wenlarge/ostrol-communication 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/astro-engine-config.d.ts +1 -0
- package/dist/config/astro-engine-config.js +4 -0
- package/dist/config/astrology-config.d.ts +1 -0
- package/dist/config/astrology-config.js +4 -0
- package/dist/config/auth-config.d.ts +1 -0
- package/dist/config/auth-config.js +4 -0
- package/dist/config/billing-config.d.ts +1 -0
- package/dist/config/billing-config.js +4 -0
- package/dist/generated/astro_engine.d.ts +93 -0
- package/dist/generated/astro_engine.js +30 -0
- package/dist/generated/astrology.d.ts +92 -0
- package/dist/generated/astrology.js +50 -0
- package/dist/generated/auth.d.ts +131 -0
- package/dist/generated/auth.js +53 -0
- package/dist/generated/billing.d.ts +62 -0
- package/dist/generated/billing.js +41 -0
- package/dist/generated/common.d.ts +17 -0
- package/dist/generated/common.js +18 -0
- package/dist/generated/google/protobuf/empty.d.ts +13 -0
- package/dist/generated/google/protobuf/empty.js +11 -0
- package/dist/generated/google/protobuf/struct.d.ts +82 -0
- package/dist/generated/google/protobuf/struct.js +117 -0
- package/dist/grpc-client/grpc-client.module.d.ts +10 -0
- package/dist/grpc-client/grpc-client.module.js +68 -0
- package/dist/grpc-client/index.d.ts +1 -0
- package/dist/grpc-client/index.js +17 -0
- package/dist/helpers/helper.d.ts +12 -0
- package/dist/helpers/helper.js +31 -0
- package/dist/helpers/struct-to-json.d.ts +3 -0
- package/dist/helpers/struct-to-json.js +46 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +69 -0
- package/dist/kafka/commit-kafka-offset.d.ts +16 -0
- package/dist/kafka/commit-kafka-offset.js +14 -0
- package/dist/kafka/kafka-topics.d.ts +13 -0
- package/dist/kafka/kafka-topics.js +19 -0
- package/dist/kafka/payloads.d.ts +67 -0
- package/dist/kafka/payloads.js +3 -0
- package/dist/pagination/cursor.d.ts +17 -0
- package/dist/pagination/cursor.js +42 -0
- package/package.json +49 -0
- package/proto/astro_engine.proto +60 -0
- package/proto/astrology.proto +78 -0
- package/proto/auth.proto +123 -0
- package/proto/billing.proto +56 -0
- package/proto/common.proto +17 -0
- package/src/generated/astro_engine.ts +144 -0
- package/src/generated/astrology.ts +135 -0
- package/src/generated/auth.ts +215 -0
- package/src/generated/billing.ts +117 -0
- package/src/generated/common.ts +28 -0
- package/src/generated/google/protobuf/empty.ts +23 -0
- package/src/generated/google/protobuf/struct.ts +179 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export declare const protobufPackage = "google.protobuf";
|
|
2
|
+
/**
|
|
3
|
+
* `NullValue` is a singleton enumeration to represent the null value for the
|
|
4
|
+
* `Value` type union.
|
|
5
|
+
*
|
|
6
|
+
* The JSON representation for `NullValue` is JSON `null`.
|
|
7
|
+
*/
|
|
8
|
+
export declare enum NullValue {
|
|
9
|
+
/** NULL_VALUE - Null value. */
|
|
10
|
+
NULL_VALUE = "NULL_VALUE",
|
|
11
|
+
UNRECOGNIZED = "UNRECOGNIZED"
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* `Struct` represents a structured data value, consisting of fields
|
|
15
|
+
* which map to dynamically typed values. In some languages, `Struct`
|
|
16
|
+
* might be supported by a native representation. For example, in
|
|
17
|
+
* scripting languages like JS a struct is represented as an
|
|
18
|
+
* object. The details of that representation are described together
|
|
19
|
+
* with the proto support for the language.
|
|
20
|
+
*
|
|
21
|
+
* The JSON representation for `Struct` is JSON object.
|
|
22
|
+
*/
|
|
23
|
+
export interface Struct {
|
|
24
|
+
/** Unordered map of dynamically typed values. */
|
|
25
|
+
fields: {
|
|
26
|
+
[key: string]: any | undefined;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface Struct_FieldsEntry {
|
|
30
|
+
key: string;
|
|
31
|
+
value?: any | undefined;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* `Value` represents a dynamically typed value which can be either
|
|
35
|
+
* null, a number, a string, a boolean, a recursive struct value, or a
|
|
36
|
+
* list of values. A producer of value is expected to set one of these
|
|
37
|
+
* variants. Absence of any variant indicates an error.
|
|
38
|
+
*
|
|
39
|
+
* The JSON representation for `Value` is JSON value.
|
|
40
|
+
*/
|
|
41
|
+
export interface Value {
|
|
42
|
+
/** Represents a null value. */
|
|
43
|
+
nullValue?: NullValue | undefined;
|
|
44
|
+
/** Represents a double value. */
|
|
45
|
+
numberValue?: number | undefined;
|
|
46
|
+
/** Represents a string value. */
|
|
47
|
+
stringValue?: string | undefined;
|
|
48
|
+
/** Represents a boolean value. */
|
|
49
|
+
boolValue?: boolean | undefined;
|
|
50
|
+
/** Represents a structured value. */
|
|
51
|
+
structValue?: {
|
|
52
|
+
[key: string]: any;
|
|
53
|
+
} | undefined;
|
|
54
|
+
/** Represents a repeated `Value`. */
|
|
55
|
+
listValue?: Array<any> | undefined;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* `ListValue` is a wrapper around a repeated field of values.
|
|
59
|
+
*
|
|
60
|
+
* The JSON representation for `ListValue` is JSON array.
|
|
61
|
+
*/
|
|
62
|
+
export interface ListValue {
|
|
63
|
+
/** Repeated field of dynamically typed values. */
|
|
64
|
+
values: any[];
|
|
65
|
+
}
|
|
66
|
+
export declare const GOOGLE_PROTOBUF_PACKAGE_NAME = "google.protobuf";
|
|
67
|
+
export declare const Struct: {
|
|
68
|
+
wrap(object: {
|
|
69
|
+
[key: string]: any;
|
|
70
|
+
} | undefined): Struct;
|
|
71
|
+
unwrap(message: Struct): {
|
|
72
|
+
[key: string]: any;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
export declare const Value: {
|
|
76
|
+
wrap(value: any): Value;
|
|
77
|
+
unwrap(message: any): string | number | boolean | Object | null | Array<any> | undefined;
|
|
78
|
+
};
|
|
79
|
+
export declare const ListValue: {
|
|
80
|
+
wrap(array: Array<any> | undefined): ListValue;
|
|
81
|
+
unwrap(message: ListValue): Array<any>;
|
|
82
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
3
|
+
// versions:
|
|
4
|
+
// protoc-gen-ts_proto v1.181.2
|
|
5
|
+
// protoc v3.21.5
|
|
6
|
+
// source: google/protobuf/struct.proto
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.ListValue = exports.Value = exports.Struct = exports.GOOGLE_PROTOBUF_PACKAGE_NAME = exports.NullValue = exports.protobufPackage = void 0;
|
|
9
|
+
/* eslint-disable */
|
|
10
|
+
const protobufjs_1 = require("protobufjs");
|
|
11
|
+
exports.protobufPackage = "google.protobuf";
|
|
12
|
+
/**
|
|
13
|
+
* `NullValue` is a singleton enumeration to represent the null value for the
|
|
14
|
+
* `Value` type union.
|
|
15
|
+
*
|
|
16
|
+
* The JSON representation for `NullValue` is JSON `null`.
|
|
17
|
+
*/
|
|
18
|
+
var NullValue;
|
|
19
|
+
(function (NullValue) {
|
|
20
|
+
/** NULL_VALUE - Null value. */
|
|
21
|
+
NullValue["NULL_VALUE"] = "NULL_VALUE";
|
|
22
|
+
NullValue["UNRECOGNIZED"] = "UNRECOGNIZED";
|
|
23
|
+
})(NullValue || (exports.NullValue = NullValue = {}));
|
|
24
|
+
exports.GOOGLE_PROTOBUF_PACKAGE_NAME = "google.protobuf";
|
|
25
|
+
function createBaseStruct() {
|
|
26
|
+
return { fields: {} };
|
|
27
|
+
}
|
|
28
|
+
exports.Struct = {
|
|
29
|
+
wrap(object) {
|
|
30
|
+
const struct = createBaseStruct();
|
|
31
|
+
if (object !== undefined) {
|
|
32
|
+
for (const key of Object.keys(object)) {
|
|
33
|
+
struct.fields[key] = exports.Value.wrap(object[key]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return struct;
|
|
37
|
+
},
|
|
38
|
+
unwrap(message) {
|
|
39
|
+
const object = {};
|
|
40
|
+
if (message.fields) {
|
|
41
|
+
for (const key of Object.keys(message.fields)) {
|
|
42
|
+
object[key] = exports.Value.unwrap(message.fields[key]);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return object;
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
function createBaseValue() {
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
exports.Value = {
|
|
52
|
+
wrap(value) {
|
|
53
|
+
const result = {};
|
|
54
|
+
if (value === null) {
|
|
55
|
+
result.nullValue = NullValue.NULL_VALUE;
|
|
56
|
+
}
|
|
57
|
+
else if (typeof value === "boolean") {
|
|
58
|
+
result.boolValue = value;
|
|
59
|
+
}
|
|
60
|
+
else if (typeof value === "number") {
|
|
61
|
+
result.numberValue = value;
|
|
62
|
+
}
|
|
63
|
+
else if (typeof value === "string") {
|
|
64
|
+
result.stringValue = value;
|
|
65
|
+
}
|
|
66
|
+
else if (globalThis.Array.isArray(value)) {
|
|
67
|
+
result.listValue = exports.ListValue.wrap(value);
|
|
68
|
+
}
|
|
69
|
+
else if (typeof value === "object") {
|
|
70
|
+
result.structValue = exports.Struct.wrap(value);
|
|
71
|
+
}
|
|
72
|
+
else if (typeof value !== "undefined") {
|
|
73
|
+
throw new globalThis.Error("Unsupported any value type: " + typeof value);
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
},
|
|
77
|
+
unwrap(message) {
|
|
78
|
+
if (message?.hasOwnProperty("stringValue") && message.stringValue !== undefined) {
|
|
79
|
+
return message.stringValue;
|
|
80
|
+
}
|
|
81
|
+
else if (message?.hasOwnProperty("numberValue") && message?.numberValue !== undefined) {
|
|
82
|
+
return message.numberValue;
|
|
83
|
+
}
|
|
84
|
+
else if (message?.hasOwnProperty("boolValue") && message?.boolValue !== undefined) {
|
|
85
|
+
return message.boolValue;
|
|
86
|
+
}
|
|
87
|
+
else if (message?.hasOwnProperty("structValue") && message?.structValue !== undefined) {
|
|
88
|
+
return exports.Struct.unwrap(message.structValue);
|
|
89
|
+
}
|
|
90
|
+
else if (message?.hasOwnProperty("listValue") && message?.listValue !== undefined) {
|
|
91
|
+
return exports.ListValue.unwrap(message.listValue);
|
|
92
|
+
}
|
|
93
|
+
else if (message?.hasOwnProperty("nullValue") && message?.nullValue !== undefined) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
return undefined;
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
function createBaseListValue() {
|
|
100
|
+
return { values: [] };
|
|
101
|
+
}
|
|
102
|
+
exports.ListValue = {
|
|
103
|
+
wrap(array) {
|
|
104
|
+
const result = createBaseListValue();
|
|
105
|
+
result.values = (array ?? []).map(exports.Value.wrap);
|
|
106
|
+
return result;
|
|
107
|
+
},
|
|
108
|
+
unwrap(message) {
|
|
109
|
+
if (message?.hasOwnProperty("values") && globalThis.Array.isArray(message.values)) {
|
|
110
|
+
return message.values.map(exports.Value.unwrap);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
return message;
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
protobufjs_1.wrappers[".google.protobuf.Struct"] = { fromObject: exports.Struct.wrap, toObject: exports.Struct.unwrap };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DynamicModule } from "@nestjs/common";
|
|
2
|
+
export interface GrpcClientModuleOptions {
|
|
3
|
+
authServiceUrl?: string;
|
|
4
|
+
astrologyServiceUrl?: string;
|
|
5
|
+
billingServiceUrl?: string;
|
|
6
|
+
astroEngineServiceUrl?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class GrpcClientModule {
|
|
9
|
+
static forRoot(options: GrpcClientModuleOptions): DynamicModule;
|
|
10
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var GrpcClientModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.GrpcClientModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const microservices_1 = require("@nestjs/microservices");
|
|
13
|
+
const path_1 = require("path");
|
|
14
|
+
const auth_1 = require("../generated/auth");
|
|
15
|
+
const astrology_1 = require("../generated/astrology");
|
|
16
|
+
const billing_1 = require("../generated/billing");
|
|
17
|
+
const astro_engine_1 = require("../generated/astro_engine");
|
|
18
|
+
const auth_config_1 = require("../config/auth-config");
|
|
19
|
+
const astrology_config_1 = require("../config/astrology-config");
|
|
20
|
+
const billing_config_1 = require("../config/billing-config");
|
|
21
|
+
const astro_engine_config_1 = require("../config/astro-engine-config");
|
|
22
|
+
// proto/ is shipped at the package root; from dist/grpc-client that is ../../proto.
|
|
23
|
+
const PROTO_DIR = (0, path_1.join)(__dirname, "../../proto");
|
|
24
|
+
const loaderOptions = {
|
|
25
|
+
keepCase: true,
|
|
26
|
+
longs: String,
|
|
27
|
+
enums: String,
|
|
28
|
+
defaults: true,
|
|
29
|
+
oneofs: true,
|
|
30
|
+
includeDirs: [PROTO_DIR], // resolves `import "common.proto"`
|
|
31
|
+
};
|
|
32
|
+
const grpcClient = (name, pkg, protoPaths, url) => ({
|
|
33
|
+
name,
|
|
34
|
+
transport: microservices_1.Transport.GRPC,
|
|
35
|
+
options: {
|
|
36
|
+
package: pkg,
|
|
37
|
+
protoPath: protoPaths.map((p) => (0, path_1.join)(__dirname, "../../" + p)),
|
|
38
|
+
url,
|
|
39
|
+
loader: loaderOptions,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
let GrpcClientModule = GrpcClientModule_1 = class GrpcClientModule {
|
|
43
|
+
static forRoot(options) {
|
|
44
|
+
const clients = [];
|
|
45
|
+
if (options.authServiceUrl) {
|
|
46
|
+
clients.push(grpcClient(auth_1.AUTH_SERVICE_NAME, auth_1.AUTH_PACKAGE_NAME, auth_config_1.AUTH_PROTO_PATH, options.authServiceUrl));
|
|
47
|
+
}
|
|
48
|
+
if (options.astrologyServiceUrl) {
|
|
49
|
+
clients.push(grpcClient(astrology_1.ASTROLOGY_SERVICE_NAME, astrology_1.ASTROLOGY_PACKAGE_NAME, astrology_config_1.ASTROLOGY_PROTO_PATH, options.astrologyServiceUrl));
|
|
50
|
+
}
|
|
51
|
+
if (options.billingServiceUrl) {
|
|
52
|
+
clients.push(grpcClient(billing_1.BILLING_SERVICE_NAME, billing_1.BILLING_PACKAGE_NAME, billing_config_1.BILLING_PROTO_PATH, options.billingServiceUrl));
|
|
53
|
+
}
|
|
54
|
+
if (options.astroEngineServiceUrl) {
|
|
55
|
+
clients.push(grpcClient(astro_engine_1.ASTRO_ENGINE_SERVICE_NAME, astro_engine_1.ASTRO_ENGINE_PACKAGE_NAME, astro_engine_config_1.ASTRO_ENGINE_PROTO_PATH, options.astroEngineServiceUrl));
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
module: GrpcClientModule_1,
|
|
59
|
+
global: true,
|
|
60
|
+
imports: [microservices_1.ClientsModule.register(clients)],
|
|
61
|
+
exports: [microservices_1.ClientsModule],
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
exports.GrpcClientModule = GrpcClientModule;
|
|
66
|
+
exports.GrpcClientModule = GrpcClientModule = GrpcClientModule_1 = __decorate([
|
|
67
|
+
(0, common_1.Module)({})
|
|
68
|
+
], GrpcClientModule);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./grpc-client.module";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./grpc-client.module"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Metadata } from "@grpc/grpc-js";
|
|
2
|
+
import type { PlanString } from "../kafka/payloads";
|
|
3
|
+
export declare const USER_METADATA_KEY = "user";
|
|
4
|
+
export declare const REQUEST_ID_METADATA_KEY = "x-request-id";
|
|
5
|
+
export interface UserContext {
|
|
6
|
+
userId: string;
|
|
7
|
+
plan: PlanString;
|
|
8
|
+
language?: string;
|
|
9
|
+
email?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function parseUserFromMetadata(metadata: Metadata): UserContext | null;
|
|
12
|
+
export declare function buildUserMetadata(user: UserContext, requestId?: string): Metadata;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REQUEST_ID_METADATA_KEY = exports.USER_METADATA_KEY = void 0;
|
|
4
|
+
exports.parseUserFromMetadata = parseUserFromMetadata;
|
|
5
|
+
exports.buildUserMetadata = buildUserMetadata;
|
|
6
|
+
const grpc_js_1 = require("@grpc/grpc-js");
|
|
7
|
+
exports.USER_METADATA_KEY = "user";
|
|
8
|
+
exports.REQUEST_ID_METADATA_KEY = "x-request-id";
|
|
9
|
+
// Reads + decodes the base64 JSON `user` metadata blob. Returns null when absent
|
|
10
|
+
// or malformed (e.g. a public/unauthenticated route).
|
|
11
|
+
function parseUserFromMetadata(metadata) {
|
|
12
|
+
const raw = metadata.get(exports.USER_METADATA_KEY)[0];
|
|
13
|
+
if (!raw || typeof raw !== "string")
|
|
14
|
+
return null;
|
|
15
|
+
try {
|
|
16
|
+
const decoded = Buffer.from(raw, "base64").toString("utf8");
|
|
17
|
+
return JSON.parse(decoded);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// Builds gRPC metadata carrying the user context (and optional request id). Used by
|
|
24
|
+
// the gateway's client layer to forward auth context downstream.
|
|
25
|
+
function buildUserMetadata(user, requestId) {
|
|
26
|
+
const metadata = new grpc_js_1.Metadata();
|
|
27
|
+
metadata.set(exports.USER_METADATA_KEY, Buffer.from(JSON.stringify(user), "utf8").toString("base64"));
|
|
28
|
+
if (requestId)
|
|
29
|
+
metadata.set(exports.REQUEST_ID_METADATA_KEY, requestId);
|
|
30
|
+
return metadata;
|
|
31
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Struct } from "../generated/google/protobuf/struct";
|
|
2
|
+
export declare function wrapStruct(obj: Record<string, any> | null | undefined): Struct | undefined;
|
|
3
|
+
export declare function unwrapStruct(struct: Struct | Record<string, any> | null | undefined): Record<string, any> | undefined;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wrapStruct = wrapStruct;
|
|
4
|
+
exports.unwrapStruct = unwrapStruct;
|
|
5
|
+
const struct_1 = require("../generated/google/protobuf/struct");
|
|
6
|
+
// Wrap a plain JS object into a protobuf Struct for fields typed as
|
|
7
|
+
// google.protobuf.Struct (e.g. NatalChart.rawData, astro-engine outputs).
|
|
8
|
+
function wrapStruct(obj) {
|
|
9
|
+
if (obj == null)
|
|
10
|
+
return undefined;
|
|
11
|
+
return struct_1.Struct.wrap(obj);
|
|
12
|
+
}
|
|
13
|
+
// Unwrap a protobuf Struct (or its `.fields`) back into a plain JS object.
|
|
14
|
+
function unwrapStruct(struct) {
|
|
15
|
+
if (struct == null)
|
|
16
|
+
return undefined;
|
|
17
|
+
const fields = "fields" in struct ? struct.fields : struct;
|
|
18
|
+
if (fields == null)
|
|
19
|
+
return undefined;
|
|
20
|
+
const result = {};
|
|
21
|
+
for (const key in fields) {
|
|
22
|
+
const value = fields[key];
|
|
23
|
+
if (value == null) {
|
|
24
|
+
result[key] = null;
|
|
25
|
+
}
|
|
26
|
+
else if ("stringValue" in value) {
|
|
27
|
+
result[key] = value.stringValue;
|
|
28
|
+
}
|
|
29
|
+
else if ("numberValue" in value) {
|
|
30
|
+
result[key] = value.numberValue;
|
|
31
|
+
}
|
|
32
|
+
else if ("boolValue" in value) {
|
|
33
|
+
result[key] = value.boolValue;
|
|
34
|
+
}
|
|
35
|
+
else if ("structValue" in value) {
|
|
36
|
+
result[key] = unwrapStruct(value.structValue?.fields ?? {});
|
|
37
|
+
}
|
|
38
|
+
else if ("listValue" in value) {
|
|
39
|
+
result[key] = value.listValue?.values?.map((v) => unwrapStruct({ tmp: v })?.tmp);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
result[key] = null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * as Common from "./generated/common";
|
|
2
|
+
export * as Auth from "./generated/auth";
|
|
3
|
+
export * as Astrology from "./generated/astrology";
|
|
4
|
+
export * as Billing from "./generated/billing";
|
|
5
|
+
export * as AstroEngine from "./generated/astro_engine";
|
|
6
|
+
export * from "./config/auth-config";
|
|
7
|
+
export * from "./config/astrology-config";
|
|
8
|
+
export * from "./config/billing-config";
|
|
9
|
+
export * from "./config/astro-engine-config";
|
|
10
|
+
export * from "./grpc-client";
|
|
11
|
+
export * from "./kafka/kafka-topics";
|
|
12
|
+
export * from "./kafka/payloads";
|
|
13
|
+
export * from "./kafka/commit-kafka-offset";
|
|
14
|
+
export * from "./helpers/helper";
|
|
15
|
+
export * from "./helpers/struct-to-json";
|
|
16
|
+
export * from "./pagination/cursor";
|
|
17
|
+
export { Metadata } from "@grpc/grpc-js";
|
|
18
|
+
export { Struct, Value, ListValue } from "./generated/google/protobuf/struct";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ListValue = exports.Value = exports.Struct = exports.Metadata = exports.AstroEngine = exports.Billing = exports.Astrology = exports.Auth = exports.Common = void 0;
|
|
40
|
+
// Generated gRPC types are namespaced to avoid cross-proto name collisions
|
|
41
|
+
// (e.g. each package's enums/messages live under their own namespace).
|
|
42
|
+
exports.Common = __importStar(require("./generated/common"));
|
|
43
|
+
exports.Auth = __importStar(require("./generated/auth"));
|
|
44
|
+
exports.Astrology = __importStar(require("./generated/astrology"));
|
|
45
|
+
exports.Billing = __importStar(require("./generated/billing"));
|
|
46
|
+
exports.AstroEngine = __importStar(require("./generated/astro_engine"));
|
|
47
|
+
// proto path config (consumed by GrpcClientModule + service main bootstrap)
|
|
48
|
+
__exportStar(require("./config/auth-config"), exports);
|
|
49
|
+
__exportStar(require("./config/astrology-config"), exports);
|
|
50
|
+
__exportStar(require("./config/billing-config"), exports);
|
|
51
|
+
__exportStar(require("./config/astro-engine-config"), exports);
|
|
52
|
+
// gRPC client dynamic module
|
|
53
|
+
__exportStar(require("./grpc-client"), exports);
|
|
54
|
+
// Kafka
|
|
55
|
+
__exportStar(require("./kafka/kafka-topics"), exports);
|
|
56
|
+
__exportStar(require("./kafka/payloads"), exports);
|
|
57
|
+
__exportStar(require("./kafka/commit-kafka-offset"), exports);
|
|
58
|
+
// helpers
|
|
59
|
+
__exportStar(require("./helpers/helper"), exports);
|
|
60
|
+
__exportStar(require("./helpers/struct-to-json"), exports);
|
|
61
|
+
// pagination
|
|
62
|
+
__exportStar(require("./pagination/cursor"), exports);
|
|
63
|
+
// re-exports for convenience
|
|
64
|
+
var grpc_js_1 = require("@grpc/grpc-js");
|
|
65
|
+
Object.defineProperty(exports, "Metadata", { enumerable: true, get: function () { return grpc_js_1.Metadata; } });
|
|
66
|
+
var struct_1 = require("./generated/google/protobuf/struct");
|
|
67
|
+
Object.defineProperty(exports, "Struct", { enumerable: true, get: function () { return struct_1.Struct; } });
|
|
68
|
+
Object.defineProperty(exports, "Value", { enumerable: true, get: function () { return struct_1.Value; } });
|
|
69
|
+
Object.defineProperty(exports, "ListValue", { enumerable: true, get: function () { return struct_1.ListValue; } });
|
|
@@ -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,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.commitKafkaOffset = commitKafkaOffset;
|
|
4
|
+
// Manually commits the next offset for a consumed message. Use after a handler has
|
|
5
|
+
// durably processed (and idempotently deduped) a message, so a crash mid-handler
|
|
6
|
+
// reprocesses rather than silently skips.
|
|
7
|
+
async function commitKafkaOffset(ctx) {
|
|
8
|
+
const consumer = ctx.getConsumer();
|
|
9
|
+
const topic = ctx.getTopic();
|
|
10
|
+
const partition = ctx.getPartition();
|
|
11
|
+
const message = ctx.getMessage();
|
|
12
|
+
const nextOffset = (BigInt(message.offset) + BigInt(1)).toString();
|
|
13
|
+
await consumer.commitOffsets([{ topic, partition, offset: nextOffset }]);
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const KafkaTopics: {
|
|
2
|
+
readonly USER_REGISTERED: "user.registered";
|
|
3
|
+
readonly USER_PROFILE_UPDATED: "user.profile_updated";
|
|
4
|
+
readonly USER_DELETED: "user.deleted";
|
|
5
|
+
readonly PLAN_CHANGED: "plan.changed";
|
|
6
|
+
readonly ASTROLOGY_CALC_REQUESTED: "astrology.calc.requested";
|
|
7
|
+
readonly ASTROLOGY_GENERATION_REQUESTED: "astrology.generation.requested";
|
|
8
|
+
readonly ASTROLOGY_FORECAST_REQUESTED: "astrology.forecast.requested";
|
|
9
|
+
readonly ASTROLOGY_TRANSIT_FIRE: "astrology.transit.fire";
|
|
10
|
+
readonly NOTIFICATION_PUSH: "notification.push";
|
|
11
|
+
};
|
|
12
|
+
export type KafkaTopic = (typeof KafkaTopics)[keyof typeof KafkaTopics];
|
|
13
|
+
export declare const dlq: (topic: KafkaTopic | string) => string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dlq = exports.KafkaTopics = void 0;
|
|
4
|
+
// Kafka topic backbone. Partition key = userId (ordering per user + parallelism).
|
|
5
|
+
// All consumers are idempotent; every topic has a derived `.dlq` (see dlq()).
|
|
6
|
+
exports.KafkaTopics = {
|
|
7
|
+
USER_REGISTERED: "user.registered",
|
|
8
|
+
USER_PROFILE_UPDATED: "user.profile_updated",
|
|
9
|
+
USER_DELETED: "user.deleted",
|
|
10
|
+
PLAN_CHANGED: "plan.changed",
|
|
11
|
+
ASTROLOGY_CALC_REQUESTED: "astrology.calc.requested",
|
|
12
|
+
ASTROLOGY_GENERATION_REQUESTED: "astrology.generation.requested",
|
|
13
|
+
ASTROLOGY_FORECAST_REQUESTED: "astrology.forecast.requested",
|
|
14
|
+
ASTROLOGY_TRANSIT_FIRE: "astrology.transit.fire",
|
|
15
|
+
NOTIFICATION_PUSH: "notification.push",
|
|
16
|
+
};
|
|
17
|
+
// Dead-letter topic for a given topic, used after N failed retries.
|
|
18
|
+
const dlq = (topic) => `${topic}.dlq`;
|
|
19
|
+
exports.dlq = dlq;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { KafkaTopics } from "./kafka-topics";
|
|
2
|
+
export type PlanString = "free" | "premium";
|
|
3
|
+
export type PersonalPostType = "daily" | "weekly" | "monthly";
|
|
4
|
+
export interface UserRegisteredPayload {
|
|
5
|
+
userId: string;
|
|
6
|
+
email: string;
|
|
7
|
+
language?: string;
|
|
8
|
+
birthAt?: string;
|
|
9
|
+
birthLat?: number;
|
|
10
|
+
birthLng?: number;
|
|
11
|
+
timezone?: string;
|
|
12
|
+
plan: PlanString;
|
|
13
|
+
}
|
|
14
|
+
export type UserProfileUpdatedPayload = UserRegisteredPayload & {
|
|
15
|
+
recalc?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export interface UserDeletedPayload {
|
|
18
|
+
userId: string;
|
|
19
|
+
email: string;
|
|
20
|
+
}
|
|
21
|
+
export interface PlanChangedPayload {
|
|
22
|
+
userId: string;
|
|
23
|
+
plan: PlanString;
|
|
24
|
+
previousPlan: PlanString;
|
|
25
|
+
subscriptionStatus: string;
|
|
26
|
+
}
|
|
27
|
+
export interface AstrologyCalcRequestedPayload {
|
|
28
|
+
userId: string;
|
|
29
|
+
scope: "natal" | "deep";
|
|
30
|
+
}
|
|
31
|
+
export interface AstrologyGenerationRequestedPayload {
|
|
32
|
+
userId: string;
|
|
33
|
+
type: PersonalPostType | "general" | "general_translation";
|
|
34
|
+
periodKey: string;
|
|
35
|
+
plan?: PlanString;
|
|
36
|
+
language?: string;
|
|
37
|
+
sourcePostId?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface AstrologyForecastRequestedPayload {
|
|
40
|
+
userId: string;
|
|
41
|
+
fromAt: string;
|
|
42
|
+
toAt: string;
|
|
43
|
+
}
|
|
44
|
+
export interface AstrologyTransitFirePayload {
|
|
45
|
+
userId: string;
|
|
46
|
+
transitEventId: string;
|
|
47
|
+
}
|
|
48
|
+
export interface NotificationPushPayload {
|
|
49
|
+
userId?: string;
|
|
50
|
+
email: string;
|
|
51
|
+
type: string;
|
|
52
|
+
subject: string;
|
|
53
|
+
body: string;
|
|
54
|
+
referenceId?: string;
|
|
55
|
+
dedupKey: string;
|
|
56
|
+
}
|
|
57
|
+
export interface KafkaPayloadMap {
|
|
58
|
+
[KafkaTopics.USER_REGISTERED]: UserRegisteredPayload;
|
|
59
|
+
[KafkaTopics.USER_PROFILE_UPDATED]: UserProfileUpdatedPayload;
|
|
60
|
+
[KafkaTopics.USER_DELETED]: UserDeletedPayload;
|
|
61
|
+
[KafkaTopics.PLAN_CHANGED]: PlanChangedPayload;
|
|
62
|
+
[KafkaTopics.ASTROLOGY_CALC_REQUESTED]: AstrologyCalcRequestedPayload;
|
|
63
|
+
[KafkaTopics.ASTROLOGY_GENERATION_REQUESTED]: AstrologyGenerationRequestedPayload;
|
|
64
|
+
[KafkaTopics.ASTROLOGY_FORECAST_REQUESTED]: AstrologyForecastRequestedPayload;
|
|
65
|
+
[KafkaTopics.ASTROLOGY_TRANSIT_FIRE]: AstrologyTransitFirePayload;
|
|
66
|
+
[KafkaTopics.NOTIFICATION_PUSH]: NotificationPushPayload;
|
|
67
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface CursorRequest {
|
|
2
|
+
cursor?: string;
|
|
3
|
+
limit: number;
|
|
4
|
+
}
|
|
5
|
+
export interface CursorResponse<T> {
|
|
6
|
+
data: T[];
|
|
7
|
+
nextCursor: string | null;
|
|
8
|
+
hasMore: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface DecodedCursor {
|
|
11
|
+
v: string;
|
|
12
|
+
id: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function encodeCursor(v: string, id: string): string;
|
|
15
|
+
export declare function decodeCursor(cursor?: string): DecodedCursor | null;
|
|
16
|
+
export declare function clampLimit(limit: number, max?: number, def?: number): number;
|
|
17
|
+
export declare function buildCursorPage<T>(rows: T[], limit: number, toKey: (row: T) => DecodedCursor): CursorResponse<T>;
|