@servora/proto-utils 0.0.2 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/dist/client/errors.d.ts +32 -0
  2. package/dist/client/errors.d.ts.map +1 -0
  3. package/dist/client/errors.js +37 -0
  4. package/dist/client/errors.js.map +1 -0
  5. package/dist/client/index.d.ts +3 -0
  6. package/dist/client/index.d.ts.map +1 -0
  7. package/dist/client/index.js +3 -0
  8. package/dist/client/index.js.map +1 -0
  9. package/dist/client/request.d.ts +54 -0
  10. package/dist/client/request.d.ts.map +1 -0
  11. package/dist/client/request.js +149 -0
  12. package/dist/client/request.js.map +1 -0
  13. package/dist/gen/servora/audit/v1/index.d.ts +26 -0
  14. package/dist/gen/servora/audit/v1/index.d.ts.map +1 -0
  15. package/dist/gen/servora/audit/v1/index.js +6 -0
  16. package/dist/gen/servora/audit/v1/index.js.map +1 -0
  17. package/dist/gen/servora/authn/v1/index.d.ts +6 -0
  18. package/dist/gen/servora/authn/v1/index.d.ts.map +1 -0
  19. package/dist/gen/servora/authn/v1/index.js +6 -0
  20. package/dist/gen/servora/authn/v1/index.js.map +1 -0
  21. package/dist/gen/servora/authz/v1/index.d.ts +8 -0
  22. package/dist/gen/servora/authz/v1/index.d.ts.map +1 -0
  23. package/dist/gen/servora/authz/v1/index.js +6 -0
  24. package/dist/gen/servora/authz/v1/index.js.map +1 -0
  25. package/dist/gen/servora/cloudevents/v1/index.d.ts +31 -0
  26. package/dist/gen/servora/cloudevents/v1/index.d.ts.map +1 -0
  27. package/dist/gen/servora/cloudevents/v1/index.js +6 -0
  28. package/dist/gen/servora/cloudevents/v1/index.js.map +1 -0
  29. package/dist/gen/servora/conf/v1/index.d.ts +9 -0
  30. package/dist/gen/servora/conf/v1/index.d.ts.map +1 -0
  31. package/dist/gen/servora/conf/v1/index.js +6 -0
  32. package/dist/gen/servora/conf/v1/index.js.map +1 -0
  33. package/dist/gen/servora/core/v1/index.d.ts +157 -0
  34. package/dist/gen/servora/core/v1/index.d.ts.map +1 -0
  35. package/dist/gen/servora/core/v1/index.js +6 -0
  36. package/dist/gen/servora/core/v1/index.js.map +1 -0
  37. package/dist/gen/servora/infra/db/clickhouse/v1/index.d.ts +22 -0
  38. package/dist/gen/servora/infra/db/clickhouse/v1/index.d.ts.map +1 -0
  39. package/dist/gen/servora/infra/db/clickhouse/v1/index.js +6 -0
  40. package/dist/gen/servora/infra/db/clickhouse/v1/index.js.map +1 -0
  41. package/dist/gen/servora/infra/kafka/v1/index.d.ts +28 -0
  42. package/dist/gen/servora/infra/kafka/v1/index.d.ts.map +1 -0
  43. package/dist/gen/servora/infra/kafka/v1/index.js +6 -0
  44. package/dist/gen/servora/infra/kafka/v1/index.js.map +1 -0
  45. package/dist/gen/servora/infra/mail/v1/index.d.ts +20 -0
  46. package/dist/gen/servora/infra/mail/v1/index.d.ts.map +1 -0
  47. package/dist/gen/servora/infra/mail/v1/index.js +6 -0
  48. package/dist/gen/servora/infra/mail/v1/index.js.map +1 -0
  49. package/dist/gen/servora/infra/redis/v1/index.d.ts +13 -0
  50. package/dist/gen/servora/infra/redis/v1/index.d.ts.map +1 -0
  51. package/dist/gen/servora/infra/redis/v1/index.js +6 -0
  52. package/dist/gen/servora/infra/redis/v1/index.js.map +1 -0
  53. package/dist/gen/servora/mapper/v1/index.d.ts +7 -0
  54. package/dist/gen/servora/mapper/v1/index.d.ts.map +1 -0
  55. package/dist/gen/servora/mapper/v1/index.js +6 -0
  56. package/dist/gen/servora/mapper/v1/index.js.map +1 -0
  57. package/dist/gen/servora/obs/audit/v1/index.d.ts +7 -0
  58. package/dist/gen/servora/obs/audit/v1/index.d.ts.map +1 -0
  59. package/dist/gen/servora/obs/audit/v1/index.js +6 -0
  60. package/dist/gen/servora/obs/audit/v1/index.js.map +1 -0
  61. package/dist/gen/servora/pagination/v1/index.d.ts +26 -0
  62. package/dist/gen/servora/pagination/v1/index.d.ts.map +1 -0
  63. package/dist/gen/servora/pagination/v1/index.js +6 -0
  64. package/dist/gen/servora/pagination/v1/index.js.map +1 -0
  65. package/dist/gen/servora/security/authn/oidc/v1/index.d.ts +7 -0
  66. package/dist/gen/servora/security/authn/oidc/v1/index.d.ts.map +1 -0
  67. package/dist/gen/servora/security/authn/oidc/v1/index.js +6 -0
  68. package/dist/gen/servora/security/authn/oidc/v1/index.js.map +1 -0
  69. package/dist/gen/servora/security/authz/openfga/v1/index.d.ts +7 -0
  70. package/dist/gen/servora/security/authz/openfga/v1/index.d.ts.map +1 -0
  71. package/dist/gen/servora/security/authz/openfga/v1/index.js +6 -0
  72. package/dist/gen/servora/security/authz/openfga/v1/index.js.map +1 -0
  73. package/dist/gen/servora/security/jwt/v1/index.d.ts +9 -0
  74. package/dist/gen/servora/security/jwt/v1/index.d.ts.map +1 -0
  75. package/dist/gen/servora/security/jwt/v1/index.js +6 -0
  76. package/dist/gen/servora/security/jwt/v1/index.js.map +1 -0
  77. package/dist/gen/servora/security/tls/v1/index.d.ts +7 -0
  78. package/dist/gen/servora/security/tls/v1/index.d.ts.map +1 -0
  79. package/dist/gen/servora/security/tls/v1/index.js +6 -0
  80. package/dist/gen/servora/security/tls/v1/index.js.map +1 -0
  81. package/dist/gen/servora/transport/http/cors/v1/index.d.ts +12 -0
  82. package/dist/gen/servora/transport/http/cors/v1/index.d.ts.map +1 -0
  83. package/dist/gen/servora/transport/http/cors/v1/index.js +6 -0
  84. package/dist/gen/servora/transport/http/cors/v1/index.js.map +1 -0
  85. package/dist/index.d.ts +3 -0
  86. package/dist/index.d.ts.map +1 -0
  87. package/dist/index.js +3 -0
  88. package/dist/index.js.map +1 -0
  89. package/dist/query.d.ts +1 -0
  90. package/dist/query.d.ts.map +1 -1
  91. package/dist/query.js +8 -6
  92. package/dist/query.js.map +1 -1
  93. package/package.json +37 -6
  94. package/src/client/errors.ts +54 -0
  95. package/src/client/index.ts +2 -0
  96. package/src/client/request.ts +233 -0
  97. package/src/gen/servora/audit/v1/index.ts +64 -0
  98. package/src/gen/servora/authn/v1/index.ts +25 -0
  99. package/src/gen/servora/authz/v1/index.ts +28 -0
  100. package/src/gen/servora/cloudevents/v1/index.ts +49 -0
  101. package/src/gen/servora/conf/v1/index.ts +32 -0
  102. package/src/gen/servora/core/v1/index.ts +221 -0
  103. package/src/gen/servora/infra/db/clickhouse/v1/index.ts +33 -0
  104. package/src/gen/servora/infra/kafka/v1/index.ts +41 -0
  105. package/src/gen/servora/infra/mail/v1/index.ts +32 -0
  106. package/src/gen/servora/infra/redis/v1/index.ts +23 -0
  107. package/src/gen/servora/mapper/v1/index.ts +18 -0
  108. package/src/gen/servora/obs/audit/v1/index.ts +13 -0
  109. package/src/gen/servora/pagination/v1/index.ts +37 -0
  110. package/src/gen/servora/security/authn/oidc/v1/index.ts +13 -0
  111. package/src/gen/servora/security/authz/openfga/v1/index.ts +13 -0
  112. package/src/gen/servora/security/jwt/v1/index.ts +17 -0
  113. package/src/gen/servora/security/tls/v1/index.ts +13 -0
  114. package/src/gen/servora/transport/http/cors/v1/index.ts +22 -0
  115. package/src/index.ts +2 -0
  116. package/src/query.ts +13 -11
@@ -0,0 +1,233 @@
1
+ /**
2
+ * @servora/proto-utils/client — 通用 HTTP 请求处理器
3
+ *
4
+ * 为 proto 生成的 TypeScript client 提供标准 RequestHandler 实现,包含:
5
+ * - Bearer token 自动注入
6
+ * - Token 自动刷新(单例防重复)
7
+ * - 结构化 ApiError(区分 http / network / timeout)
8
+ * - 全局 onError 回调(延迟到宏任务,避免与 toast.promise 竞态)
9
+ *
10
+ * 消费方通过 @servora/proto-utils 使用本实现,ofetch 由本包依赖提供。
11
+ */
12
+
13
+ import type { FetchOptions } from "ofetch";
14
+ import { ofetch } from "ofetch";
15
+
16
+ export type RequestType = {
17
+ path: string;
18
+ method: string;
19
+ body: string | null;
20
+ };
21
+
22
+ export type RequestMeta = {
23
+ service: string;
24
+ method: string;
25
+ };
26
+
27
+ export type RequestHandler = (
28
+ request: RequestType,
29
+ meta: RequestMeta,
30
+ ) => Promise<unknown>;
31
+
32
+ export interface TokenStore {
33
+ getAccessToken: () => string | null;
34
+ getRefreshToken: () => string | null;
35
+ setTokens: (accessToken: string, refreshToken: string) => void;
36
+ clear: () => void;
37
+ }
38
+
39
+ export interface RequestHandlerOptions {
40
+ baseUrl?: string;
41
+ tokenStore?: TokenStore;
42
+ contextHeaders?: (meta: RequestMeta) => Record<string, string>;
43
+ timeoutMs?: number;
44
+ onError?: (error: ApiError, meta: RequestMeta) => void;
45
+ autoRefreshToken?: boolean;
46
+ }
47
+
48
+ export type ApiErrorKind = "http" | "network" | "timeout";
49
+
50
+ export class ApiError extends Error {
51
+ readonly kind: ApiErrorKind;
52
+ readonly httpStatus?: number;
53
+ readonly responseBody?: unknown;
54
+ readonly service: string;
55
+ readonly method: string;
56
+
57
+ constructor(opts: {
58
+ kind: ApiErrorKind;
59
+ message: string;
60
+ httpStatus?: number;
61
+ responseBody?: unknown;
62
+ service: string;
63
+ method: string;
64
+ cause?: unknown;
65
+ }) {
66
+ super(opts.message, { cause: opts.cause });
67
+ this.name = "ApiError";
68
+ this.kind = opts.kind;
69
+ this.httpStatus = opts.httpStatus;
70
+ this.responseBody = opts.responseBody;
71
+ this.service = opts.service;
72
+ this.method = opts.method;
73
+ }
74
+ }
75
+
76
+ function ensureLeadingSlash(path: string): string {
77
+ return path.startsWith("/") ? path : `/${path}`;
78
+ }
79
+
80
+ const REFRESH_PATH = "/v1/auth/refresh-token";
81
+ const AUTH_PATH_PREFIX = "/v1/auth/";
82
+
83
+ export function createRequestHandler(
84
+ options: RequestHandlerOptions = {},
85
+ ): RequestHandler {
86
+ const {
87
+ baseUrl = "",
88
+ tokenStore,
89
+ contextHeaders,
90
+ timeoutMs = 30_000,
91
+ onError,
92
+ autoRefreshToken = false,
93
+ } = options;
94
+
95
+ let refreshPromise: Promise<boolean> | null = null;
96
+
97
+ async function tryRefreshToken(): Promise<boolean> {
98
+ if (!tokenStore) return false;
99
+ const refreshToken = tokenStore.getRefreshToken();
100
+ if (!refreshToken) return false;
101
+
102
+ if (refreshPromise) return refreshPromise;
103
+
104
+ refreshPromise = (async () => {
105
+ try {
106
+ const data = await ofetch<{
107
+ accessToken: string;
108
+ refreshToken: string;
109
+ }>(REFRESH_PATH, {
110
+ baseURL: baseUrl,
111
+ method: "POST",
112
+ body: { refreshToken },
113
+ timeout: timeoutMs,
114
+ });
115
+ tokenStore.setTokens(data.accessToken, data.refreshToken);
116
+ return true;
117
+ } catch {
118
+ tokenStore.clear();
119
+ return false;
120
+ } finally {
121
+ refreshPromise = null;
122
+ }
123
+ })();
124
+
125
+ return refreshPromise;
126
+ }
127
+
128
+ async function doRequest(
129
+ request: RequestType,
130
+ meta: RequestMeta,
131
+ isRetry = false,
132
+ ): Promise<unknown> {
133
+ const headers: Record<string, string> = {
134
+ Accept: "application/json",
135
+ };
136
+
137
+ if (request.body) {
138
+ headers["Content-Type"] = "application/json";
139
+ }
140
+
141
+ if (tokenStore) {
142
+ const token = tokenStore.getAccessToken();
143
+ if (token) {
144
+ headers.Authorization = `Bearer ${token}`;
145
+ }
146
+ }
147
+
148
+ if (contextHeaders) {
149
+ Object.assign(headers, contextHeaders(meta));
150
+ }
151
+
152
+ const fetchOptions: FetchOptions = {
153
+ baseURL: baseUrl,
154
+ method: request.method as FetchOptions["method"],
155
+ headers,
156
+ timeout: timeoutMs,
157
+ };
158
+
159
+ if (request.body) {
160
+ fetchOptions.body = request.body;
161
+ }
162
+
163
+ const normalizedPath = ensureLeadingSlash(request.path);
164
+
165
+ try {
166
+ return await ofetch(normalizedPath, fetchOptions);
167
+ } catch (err: unknown) {
168
+ const fetchError =
169
+ err != null && typeof err === "object"
170
+ ? (err as Record<string, unknown>)
171
+ : {};
172
+ const response = fetchError.response as
173
+ | { status: number; _data?: unknown }
174
+ | undefined;
175
+
176
+ if (response) {
177
+ const status = response.status;
178
+ const body = response._data;
179
+
180
+ const apiErr = new ApiError({
181
+ kind: "http",
182
+ message: `HTTP ${status} on ${meta.service}.${meta.method}`,
183
+ httpStatus: status,
184
+ responseBody: body,
185
+ service: meta.service,
186
+ method: meta.method,
187
+ cause: err,
188
+ });
189
+
190
+ if (
191
+ autoRefreshToken &&
192
+ status === 401 &&
193
+ !isRetry &&
194
+ !normalizedPath.startsWith(AUTH_PATH_PREFIX)
195
+ ) {
196
+ const refreshed = await tryRefreshToken();
197
+ if (refreshed) {
198
+ return doRequest(request, meta, true);
199
+ }
200
+ }
201
+
202
+ // 延迟到宏任务再调 onError,让 promise 链先跑完(含 toast.promise 的 _mark),
203
+ // 避免全局 handler 与 sonner.promise error callback 同时弹出双重 toast。
204
+ if (onError) {
205
+ const _err = apiErr;
206
+ setTimeout(() => onError(_err, meta), 0);
207
+ }
208
+ throw apiErr;
209
+ }
210
+
211
+ const rawMessage =
212
+ typeof fetchError.message === "string" ? fetchError.message : "";
213
+ const kind: ApiErrorKind = rawMessage.toLowerCase().includes("timeout")
214
+ ? "timeout"
215
+ : "network";
216
+
217
+ const apiErr = new ApiError({
218
+ kind,
219
+ message: `${kind} error on ${meta.service}.${meta.method}: ${rawMessage}`,
220
+ service: meta.service,
221
+ method: meta.method,
222
+ cause: err,
223
+ });
224
+ if (onError) {
225
+ const _err = apiErr;
226
+ setTimeout(() => onError(_err, meta), 0);
227
+ }
228
+ throw apiErr;
229
+ }
230
+ }
231
+
232
+ return doRequest;
233
+ }
@@ -0,0 +1,64 @@
1
+ // Code generated by protoc-gen-typescript-http. DO NOT EDIT.
2
+ /* eslint-disable camelcase */
3
+ // @ts-nocheck
4
+
5
+ // AuditMode 表达审计开关三态。
6
+ // 引入「服务级默认 + 方法级覆盖」机制后,proto3 bool 默认值与「未指定」无法区分;
7
+ // 用 enum 三态可让方法级显式继承(UNSPECIFIED)/ 显式覆盖(DISABLED/ENABLED)语义清晰。
8
+ // 迁移说明:从 v0.x 起替代原 `bool enabled` 字段;旧写法 `enabled: true` 迁移为
9
+ // `mode: AUDIT_MODE_ENABLED`,`enabled: false` 迁移为 `mode: AUDIT_MODE_DISABLED`,
10
+ // 未指定保留为 `AUDIT_MODE_UNSPECIFIED` 表示继承服务级默认。
11
+ export type AuditMode =
12
+ | "AUDIT_MODE_UNSPECIFIED"
13
+ | "AUDIT_MODE_DISABLED"
14
+ | "AUDIT_MODE_ENABLED";
15
+ // ExtensionMapping 将一个 CloudEvents 扩展属性映射到请求/响应字段或字面值。
16
+ // 用于在注解中声明运行时需要从请求/响应消息中提取哪些值作为事件扩展属性。
17
+ export type ExtensionMapping = {
18
+ // CloudEvents 扩展属性名称(如 "mutation"、"resourcetype")。
19
+ name: string | undefined;
20
+ // 从请求/响应消息的 proto field path 提取(如 "req.id"、"resp.name")。
21
+ fromField?: string;
22
+ // 字面值,直接写入事件扩展属性。
23
+ literal?: servoracloudeventsv1_CloudEvent_CloudEventAttributeValue;
24
+ };
25
+
26
+ // The CloudEvent specification defines seven attribute value types.
27
+ export type servoracloudeventsv1_CloudEvent_CloudEventAttributeValue = {
28
+ ceBoolean?: boolean;
29
+ ceInteger?: number;
30
+ ceString?: string;
31
+ ceBytes?: string;
32
+ ceUri?: string;
33
+ ceUriRef?: string;
34
+ ceTimestamp?: wellKnownTimestamp;
35
+ };
36
+
37
+ // Encoded using RFC 3339, where generated output will always be Z-normalized
38
+ // and uses 0, 3, 6 or 9 fractional digits.
39
+ // Offsets other than "Z" are also accepted.
40
+ type wellKnownTimestamp = string;
41
+
42
+ // AuditRule 声明一个 RPC 方法的审计规则。
43
+ // 与 CloudEvents 对齐:event_type 和 severity 映射到 CloudEvents type 与扩展属性,
44
+ // extensions 允许声明式地从请求/响应中提取任意扩展属性。
45
+ export type AuditRule = {
46
+ // 是否产生审计事件。UNSPECIFIED 表示沿用服务级默认或框架默认。
47
+ mode: AuditMode | undefined;
48
+ // CloudEvents type 属性值(如 "servora.audit.resource_mutation")。
49
+ eventType: string | undefined;
50
+ // 事件严重级别(如 "info"、"warning"、"critical")。
51
+ // 映射到 CloudEvents 扩展属性 "severity"。
52
+ severity: string | undefined;
53
+ // detail message 的 proto field path(如 "req"),
54
+ // 运行时序列化后作为 CloudEvent data 载荷。留空则不附带详情。
55
+ detailMessageField: string | undefined;
56
+ // 目标 ID 的 proto field path(如 "req.id"、"resp.id")。
57
+ // 由 protoc-gen-servora-audit 生成提取函数,留空则不提取。
58
+ targetIdField: string | undefined;
59
+ // 额外的 CloudEvents 扩展属性映射。
60
+ extensions: ExtensionMapping[] | undefined;
61
+ };
62
+
63
+
64
+ // @@protoc_insertion_point(typescript-http-eof)
@@ -0,0 +1,25 @@
1
+ // Code generated by protoc-gen-typescript-http. DO NOT EDIT.
2
+ /* eslint-disable camelcase */
3
+ // @ts-nocheck
4
+
5
+ // AuthnRule 声明 RPC 方法的认证策略。
6
+ export type AuthnRule = {
7
+ // 认证模式。
8
+ mode: AuthnRule_Mode | undefined;
9
+ // 接受的认证机制;空列表表示沿用框架默认引擎。
10
+ // 取值是各 wrapper 子包持有的私有 method 字符串常量(如 `jwt`、`mtls`、`api_key`、`aksk`);
11
+ // framework 不枚举这些值,业务自定义引擎也可填任意字符串。
12
+ // 多个值表示"任一通过即可"。
13
+ schemes: string[] | undefined;
14
+ };
15
+
16
+ // Mode 表达认证模式三态。
17
+ export type AuthnRule_Mode =
18
+ // 未指定,等价"未写注解":私有 + 框架默认引擎(fail-closed 默认)。
19
+ | "MODE_UNSPECIFIED"
20
+ // 显式公开。schemes 必须为空。
21
+ | "MODE_PUBLIC"
22
+ // 必须用 schemes 指定的认证机制。schemes 必须非空。
23
+ | "MODE_REQUIRED";
24
+
25
+ // @@protoc_insertion_point(typescript-http-eof)
@@ -0,0 +1,28 @@
1
+ // Code generated by protoc-gen-typescript-http. DO NOT EDIT.
2
+ /* eslint-disable camelcase */
3
+ // @ts-nocheck
4
+
5
+ // AuthzMode defines the authorization mode for an RPC method.
6
+ export type AuthzMode =
7
+ // Unspecified — treated as fail-closed.
8
+ | "AUTHZ_MODE_UNSPECIFIED"
9
+ // Skip authorization entirely (public endpoint).
10
+ | "AUTHZ_MODE_NONE"
11
+ // Perform an authorization check using action / resource_type / resource_id_field.
12
+ | "AUTHZ_MODE_CHECK";
13
+ // AuthzRule binds authorization requirements to an RPC method.
14
+ // action and resource_type are free strings matching the authorization model.
15
+ export type AuthzRule = {
16
+ // Authorization mode.
17
+ mode: AuthzMode | undefined;
18
+ // Action to check, e.g. "admin", "can_delete", "view".
19
+ action: string | undefined;
20
+ // Resource type, e.g. "platform", "video", "server".
21
+ resourceType: string | undefined;
22
+ // Proto field name in the request that carries the resource ID, e.g. "id".
23
+ // When empty, a static default resource ID is used (singleton/platform-level checks).
24
+ resourceIdField: string | undefined;
25
+ };
26
+
27
+
28
+ // @@protoc_insertion_point(typescript-http-eof)
@@ -0,0 +1,49 @@
1
+ // Code generated by protoc-gen-typescript-http. DO NOT EDIT.
2
+ /* eslint-disable camelcase */
3
+ // @ts-nocheck
4
+
5
+ export type CloudEvent = {
6
+ // Required Attributes
7
+ id: string | undefined;
8
+ source: string | undefined;
9
+ specVersion: string | undefined;
10
+ type: string | undefined;
11
+ // Optional & Extension Attributes
12
+ attributes: { [key: string]: CloudEvent_CloudEventAttributeValue } | undefined;
13
+ binaryData?: string;
14
+ textData?: string;
15
+ protoData?: wellKnownAny;
16
+ };
17
+
18
+ // The CloudEvent specification defines seven attribute value types.
19
+ export type CloudEvent_CloudEventAttributeValue = {
20
+ ceBoolean?: boolean;
21
+ ceInteger?: number;
22
+ ceString?: string;
23
+ ceBytes?: string;
24
+ ceUri?: string;
25
+ ceUriRef?: string;
26
+ ceTimestamp?: wellKnownTimestamp;
27
+ };
28
+
29
+ // Encoded using RFC 3339, where generated output will always be Z-normalized
30
+ // and uses 0, 3, 6 or 9 fractional digits.
31
+ // Offsets other than "Z" are also accepted.
32
+ type wellKnownTimestamp = string;
33
+
34
+ // If the Any contains a value that has a special JSON mapping,
35
+ // it will be converted as follows:
36
+ // {"@type": xxx, "value": yyy}.
37
+ // Otherwise, the value will be converted into a JSON object,
38
+ // and the "@type" field will be inserted to indicate the actual data type.
39
+ interface wellKnownAny {
40
+ "@type": string;
41
+ [key: string]: unknown;
42
+ }
43
+
44
+ export type CloudEventBatch = {
45
+ events: CloudEvent[] | undefined;
46
+ };
47
+
48
+
49
+ // @@protoc_insertion_point(typescript-http-eof)
@@ -0,0 +1,32 @@
1
+ // Code generated by protoc-gen-typescript-http. DO NOT EDIT.
2
+ /* eslint-disable camelcase */
3
+ // @ts-nocheck
4
+
5
+ // SectionRule 声明一个配置 message 在外部 yaml / json 配置中的定位键。
6
+ // 应用方通过 bootstrap.Scan 按该 key 在 kratos config 中定向 scan。
7
+ export type SectionRule = {
8
+ // 配置文件中的定位键(支持 dotted path,如 "audit" 或 "authn.oidc")。
9
+ // 不应留空。
10
+ key: string | undefined;
11
+ // 是否允许该 section 在配置中缺失而不报错。
12
+ // optional=true:缺失静默跳过 scan,但 message 仍会经 ApplyDefaults 填默认值;
13
+ // optional=false(默认):缺失视为配置错误。
14
+ optional: boolean | undefined;
15
+ };
16
+
17
+ // FieldRule 声明一个配置字段的默认值与必填语义。
18
+ // default 与 required 互斥使用:required=true 表示用户必须显式提供(零值不接受),
19
+ // default 表示用户未提供时填入字面量。
20
+ export type FieldRule = {
21
+ // 字段默认值的字面量表达。
22
+ // - string 字段:直接字面量(如 "tcp");
23
+ // - 数字 / bool 字段:可解析为对应类型的字符串(如 "8080" / "true");
24
+ // - google.protobuf.Duration:Go duration 字符串(如 "24h" / "5s");
25
+ // - repeated 标量:逗号分隔(如 "GET,POST,OPTIONS")。
26
+ default: string | undefined;
27
+ // 是否必填。若 true,由 plugin 生成 Validate() 在零值时返回 error。
28
+ required: boolean | undefined;
29
+ };
30
+
31
+
32
+ // @@protoc_insertion_point(typescript-http-eof)
@@ -0,0 +1,221 @@
1
+ // Code generated by protoc-gen-typescript-http. DO NOT EDIT.
2
+ /* eslint-disable camelcase */
3
+ // @ts-nocheck
4
+
5
+ export type Bootstrap = {
6
+ app: App | undefined;
7
+ server: Server | undefined;
8
+ data: Data | undefined;
9
+ registry: Registry | undefined;
10
+ source: Source | undefined;
11
+ obs: Observability | undefined;
12
+ };
13
+
14
+ export type App = {
15
+ env: string | undefined;
16
+ name: string | undefined;
17
+ version: string | undefined;
18
+ // field 5 reserved (was App.Log, moved to Bootstrap.obs.log)
19
+ metadata: { [key: string]: string } | undefined;
20
+ externalUrl: string | undefined;
21
+ };
22
+
23
+ // 通信服务端配置
24
+ export type Server = {
25
+ http: Server_HTTP | undefined;
26
+ grpc: Server_GRPC | undefined;
27
+ };
28
+
29
+ export type Server_HTTP = {
30
+ listen: Server_Listen | undefined;
31
+ tls: servorasecuritytlsv1_TLS | undefined;
32
+ advertise: Server_Advertise | undefined;
33
+ };
34
+
35
+ // 监听配置(面向 net.Listen 参数)
36
+ export type Server_Listen = {
37
+ network: string | undefined;
38
+ addr: string | undefined;
39
+ timeout: wellKnownDuration | undefined;
40
+ };
41
+
42
+ // Generated output always contains 0, 3, 6, or 9 fractional digits,
43
+ // depending on required precision, followed by the suffix "s".
44
+ // Accepted are any fractional digits (also none) as long as they fit
45
+ // into nano-seconds precision and the suffix "s" is required.
46
+ type wellKnownDuration = string;
47
+
48
+ export type servorasecuritytlsv1_TLS = {
49
+ enable: boolean | undefined;
50
+ certPath: string | undefined;
51
+ keyPath: string | undefined;
52
+ caPath: string | undefined;
53
+ };
54
+
55
+ // 服务注册端点覆盖(用于注册中心对外公布地址)
56
+ export type Server_Advertise = {
57
+ endpoint: string | undefined;
58
+ host: string | undefined;
59
+ };
60
+
61
+ export type Server_GRPC = {
62
+ listen: Server_Listen | undefined;
63
+ tls: servorasecuritytlsv1_TLS | undefined;
64
+ advertise: Server_Advertise | undefined;
65
+ };
66
+
67
+ // 数据源配置(仅保留 database / client 等核心数据源)
68
+ export type Data = {
69
+ database: Data_Database | undefined;
70
+ client: Data_Client | undefined;
71
+ };
72
+
73
+ export type Data_Database = {
74
+ driver: string | undefined;
75
+ source: string | undefined;
76
+ };
77
+
78
+ export type Data_Client = {
79
+ services: Data_Client_Service[] | undefined;
80
+ };
81
+
82
+ export type Data_Client_Service = {
83
+ name: string | undefined;
84
+ endpoints: Data_Client_Endpoint[] | undefined;
85
+ };
86
+
87
+ export type Data_Client_Endpoint = {
88
+ protocol: string | undefined;
89
+ endpoint: string | undefined;
90
+ timeout: wellKnownDuration | undefined;
91
+ tls: servorasecuritytlsv1_TLS | undefined;
92
+ options: wellKnownStruct | undefined;
93
+ };
94
+
95
+ // Any JSON value.
96
+ type wellKnownStruct = Record<string, unknown>;
97
+
98
+ // 注册中心配置
99
+ export type Registry = {
100
+ consul?: Consul;
101
+ etcd?: Etcd;
102
+ nacos?: Nacos;
103
+ kubernetes?: Kubernetes;
104
+ };
105
+
106
+ // 通用 Consul 配置
107
+ export type Consul = {
108
+ addr: string | undefined;
109
+ scheme: string | undefined;
110
+ token: string | undefined;
111
+ datacenter: string | undefined;
112
+ timeout: wellKnownDuration | undefined;
113
+ tags: string[] | undefined;
114
+ key: string | undefined;
115
+ };
116
+
117
+ // 通用 Etcd 配置
118
+ export type Etcd = {
119
+ endpoints: string[] | undefined;
120
+ username: string | undefined;
121
+ password: string | undefined;
122
+ timeout: wellKnownDuration | undefined;
123
+ key: string | undefined;
124
+ namespace: string | undefined;
125
+ };
126
+
127
+ // 通用 Nacos 配置
128
+ export type Nacos = {
129
+ addr: string | undefined;
130
+ port: number | undefined;
131
+ namespace: string | undefined;
132
+ group: string | undefined;
133
+ username: string | undefined;
134
+ password: string | undefined;
135
+ timeout: wellKnownDuration | undefined;
136
+ dataId: string | undefined;
137
+ };
138
+
139
+ // 通用 Kubernetes 配置
140
+ export type Kubernetes = {
141
+ enable: boolean | undefined;
142
+ };
143
+
144
+ // 配置中心配置
145
+ export type Source = {
146
+ consul?: Consul;
147
+ etcd?: Etcd;
148
+ nacos?: Nacos;
149
+ };
150
+
151
+ // 可观测性配置
152
+ export type Observability = {
153
+ log: Log | undefined;
154
+ trace: Trace | undefined;
155
+ metrics: Metrics | undefined;
156
+ };
157
+
158
+ // 日志配置(与 App 同级,所有 message/enum nested)
159
+ export type Log = {
160
+ level: Log_LogLevel | undefined;
161
+ backends: Log_LogBackend[] | undefined;
162
+ };
163
+
164
+ export type Log_LogLevel =
165
+ | "LOG_LEVEL_UNSPECIFIED"
166
+ | "LOG_LEVEL_DEBUG"
167
+ | "LOG_LEVEL_INFO"
168
+ | "LOG_LEVEL_WARN"
169
+ | "LOG_LEVEL_ERROR";
170
+ export type Log_LogBackend = {
171
+ stdout?: Log_StdoutBackend;
172
+ file?: Log_FileBackend;
173
+ otel?: Log_OtelBackend;
174
+ noop?: Log_NoopBackend;
175
+ };
176
+
177
+ export type Log_StdoutBackend = {
178
+ format: Log_LogFormat | undefined;
179
+ };
180
+
181
+ export type Log_LogFormat =
182
+ | "LOG_FORMAT_UNSPECIFIED"
183
+ | "LOG_FORMAT_JSON"
184
+ | "LOG_FORMAT_TEXT";
185
+ export type Log_FileBackend = {
186
+ path: string | undefined;
187
+ maxSize: number | undefined;
188
+ maxBackups: number | undefined;
189
+ maxAge: number | undefined;
190
+ compress: boolean | undefined;
191
+ format: Log_LogFormat | undefined;
192
+ };
193
+
194
+ export type Log_OtelBackend = {
195
+ endpoint: string | undefined;
196
+ protocol: Log_OtelProtocol | undefined;
197
+ insecure: boolean | undefined;
198
+ };
199
+
200
+ export type Log_OtelProtocol =
201
+ | "OTEL_PROTOCOL_UNSPECIFIED"
202
+ | "OTEL_PROTOCOL_GRPC"
203
+ | "OTEL_PROTOCOL_HTTP_PROTOBUF";
204
+ export type Log_NoopBackend = {
205
+ };
206
+
207
+ // 链路追踪配置
208
+ export type Trace = {
209
+ endpoint: string | undefined;
210
+ insecure: boolean | undefined;
211
+ samplingRatio: number | undefined;
212
+ caPath: string | undefined;
213
+ };
214
+
215
+ // Metrics 配置
216
+ export type Metrics = {
217
+ enable: boolean | undefined;
218
+ };
219
+
220
+
221
+ // @@protoc_insertion_point(typescript-http-eof)
@@ -0,0 +1,33 @@
1
+ // Code generated by protoc-gen-typescript-http. DO NOT EDIT.
2
+ /* eslint-disable camelcase */
3
+ // @ts-nocheck
4
+
5
+ export type ClickHouse = {
6
+ addrs: string[] | undefined;
7
+ database: string | undefined;
8
+ username: string | undefined;
9
+ password: string | undefined;
10
+ dialTimeout: wellKnownDuration | undefined;
11
+ readTimeout: wellKnownDuration | undefined;
12
+ maxOpenConns: number | undefined;
13
+ maxIdleConns: number | undefined;
14
+ connMaxLifetime: wellKnownDuration | undefined;
15
+ tls: servorasecuritytlsv1_TLS | undefined;
16
+ compression: string | undefined;
17
+ };
18
+
19
+ // Generated output always contains 0, 3, 6, or 9 fractional digits,
20
+ // depending on required precision, followed by the suffix "s".
21
+ // Accepted are any fractional digits (also none) as long as they fit
22
+ // into nano-seconds precision and the suffix "s" is required.
23
+ type wellKnownDuration = string;
24
+
25
+ export type servorasecuritytlsv1_TLS = {
26
+ enable: boolean | undefined;
27
+ certPath: string | undefined;
28
+ keyPath: string | undefined;
29
+ caPath: string | undefined;
30
+ };
31
+
32
+
33
+ // @@protoc_insertion_point(typescript-http-eof)