@lark-apaas/db-schema-sync 0.1.6-alpha.3 → 0.1.6-alpha.5

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/bin.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  __toESM,
7
7
  generateSchema,
8
8
  resolveEnvOptions
9
- } from "./chunk-HRE26HBV.js";
9
+ } from "./chunk-PV4EVRKJ.js";
10
10
 
11
11
  // node_modules/dotenv/package.json
12
12
  var require_package = __commonJS({
@@ -424,10 +424,12 @@ function parseArgs(argv) {
424
424
 
425
425
  // src/bin.ts
426
426
  async function main() {
427
- const envPath = resolve(process.cwd(), ".env");
428
- if (existsSync(envPath)) {
429
- (0, import_dotenv.config)({ path: envPath });
430
- console.log("[db-schema-sync] \u2713 Loaded .env file");
427
+ for (const name of [".env.local", ".env"]) {
428
+ const envPath = resolve(process.cwd(), name);
429
+ if (existsSync(envPath)) {
430
+ (0, import_dotenv.config)({ path: envPath });
431
+ console.log(`[db-schema-sync] \u2713 Loaded ${name}`);
432
+ }
431
433
  }
432
434
  const cliArgs = parseArgs(process.argv);
433
435
  const output = cliArgs.output || process.env.DB_SCHEMA_OUTPUT || "server/database/schema.ts";
@@ -56,6 +56,7 @@ var require_dist = __commonJS({
56
56
  __export(index_exports, {
57
57
  DEFAULT_CLOCK_TOLERANCE_SEC: () => DEFAULT_CLOCK_TOLERANCE_SEC,
58
58
  DEFAULT_JWT_EXPIRE_TIME_MS: () => DEFAULT_JWT_EXPIRE_TIME_MS,
59
+ FileTokenProvider: () => FileTokenProvider,
59
60
  HttpClient: () => HttpClient2,
60
61
  HttpError: () => HttpError,
61
62
  generateJWTToken: () => generateJWTToken,
@@ -228,6 +229,77 @@ var require_dist = __commonJS({
228
229
  };
229
230
  }
230
231
  };
232
+ var import_fs = __require("fs");
233
+ var DEFAULT_REFRESH_BEFORE_MS = 5 * 60 * 1e3;
234
+ var DEFAULT_TOKEN_PATHS = [
235
+ "/home/gem/workspace/.force/openclaw/miaoda-provider-key"
236
+ ];
237
+ var FileTokenProvider = class {
238
+ cache = /* @__PURE__ */ new Map();
239
+ paths;
240
+ refreshBeforeMs;
241
+ constructor(config) {
242
+ this.paths = config?.paths ?? DEFAULT_TOKEN_PATHS;
243
+ this.refreshBeforeMs = config?.refreshBeforeMs ?? DEFAULT_REFRESH_BEFORE_MS;
244
+ }
245
+ /**
246
+ * 获取 token,按路径优先级依次尝试
247
+ *
248
+ * 1. 缓存有效且不在刷新窗口 → 直接返回
249
+ * 2. 进入刷新窗口 → 重读文件,更新缓存
250
+ * 3. 文件未更新但缓存未过期 → 仍返回旧缓存
251
+ * 4. 所有路径均无有效 token → 返回 null
252
+ */
253
+ getToken() {
254
+ const now = Date.now();
255
+ for (const filePath of this.paths) {
256
+ const cached = this.cache.get(filePath);
257
+ if (cached && cached.expiresAtMs - now > this.refreshBeforeMs) {
258
+ return { token: cached.token, accessKey: cached.accessKey };
259
+ }
260
+ const result = this.readAndParse(filePath);
261
+ if (result) {
262
+ this.cache.set(filePath, result);
263
+ if (result.expiresAtMs > now) {
264
+ return { token: result.token, accessKey: result.accessKey };
265
+ }
266
+ }
267
+ if (cached && cached.expiresAtMs > now) {
268
+ return { token: cached.token, accessKey: cached.accessKey };
269
+ }
270
+ }
271
+ return null;
272
+ }
273
+ clearCache() {
274
+ this.cache.clear();
275
+ }
276
+ readAndParse(filePath) {
277
+ try {
278
+ const token = (0, import_fs.readFileSync)(filePath, "utf-8").trim();
279
+ if (!token) return null;
280
+ const payload = this.decodePayload(token);
281
+ if (!payload?.exp) return null;
282
+ return {
283
+ token,
284
+ accessKey: payload.access_key ?? "",
285
+ expiresAtMs: payload.exp * 1e3
286
+ };
287
+ } catch {
288
+ return null;
289
+ }
290
+ }
291
+ decodePayload(token) {
292
+ try {
293
+ const segments = token.split(".");
294
+ if (segments.length !== 3) return null;
295
+ const padLength = (4 - (segments[1].length % 4 || 4)) % 4;
296
+ const padded = `${segments[1]}${"=".repeat(padLength)}`.replace(/-/g, "+").replace(/_/g, "/");
297
+ return JSON.parse(Buffer.from(padded, "base64").toString("utf8"));
298
+ } catch {
299
+ return null;
300
+ }
301
+ }
302
+ };
231
303
  var DEFAULT_DOMAIN_ENV = "FORCE_AUTHN_INNERAPI_DOMAIN";
232
304
  var DEFAULT_ACCESS_KEY_ENV = "FORCE_AUTHN_ACCESS_KEY";
233
305
  var DEFAULT_SECRET_KEY_ENV = "FORCE_AUTHN_ACCESS_SECRET";
@@ -253,6 +325,13 @@ var require_dist = __commonJS({
253
325
  return void 0;
254
326
  }
255
327
  ensureNoAccessKeyOverride("platform.defaultClaims", options.defaultClaims);
328
+ let fileTokenProvider;
329
+ if (options.tokenProvider?.type === "file") {
330
+ fileTokenProvider = new FileTokenProvider({
331
+ paths: options.tokenProvider.paths,
332
+ refreshBeforeMs: options.refreshBeforeMs
333
+ });
334
+ }
256
335
  const accessKeyEnv = options.accessKeyEnv || DEFAULT_ACCESS_KEY_ENV;
257
336
  const secretKeyEnv = options.secretKeyEnv || DEFAULT_SECRET_KEY_ENV;
258
337
  const accessKey = options.accessKey ?? (process.env[accessKeyEnv] || "");
@@ -266,6 +345,17 @@ var require_dist = __commonJS({
266
345
  });
267
346
  const clientTokenEnv = options.clientTokenEnv || DEFAULT_CLIENT_TOKEN_ENV;
268
347
  interceptors.request.use((config) => {
348
+ if (fileTokenProvider) {
349
+ const fileToken = fileTokenProvider.getToken();
350
+ if (fileToken) {
351
+ const headers2 = {
352
+ ...config.headers,
353
+ "Authorization": `Bearer ${fileToken.token}`,
354
+ "x-api-key": fileToken.accessKey
355
+ };
356
+ return { ...config, headers: headers2 };
357
+ }
358
+ }
269
359
  ensureNoAccessKeyOverride("request.platformAuth.customClaims", config.platformAuth?.customClaims);
270
360
  const claims = {
271
361
  ...options.defaultClaims || {},
@@ -1276,11 +1366,17 @@ var primitiveMappers = [
1276
1366
  generate: (f) => `uuid("${escapeDoubleQuote(f.fieldName)}")`,
1277
1367
  imports: () => [{ name: "uuid", from: PG_CORE }]
1278
1368
  },
1279
- // varchar
1369
+ // varchar (honors extraInfo.max_length from listTableView API)
1280
1370
  {
1281
1371
  name: "varchar",
1282
1372
  match: (f) => f.type === "varchar",
1283
- generate: (f) => `varchar("${escapeDoubleQuote(f.fieldName)}")`,
1373
+ generate: (f) => {
1374
+ const maxLength = f.extraInfo?.max_length;
1375
+ if (typeof maxLength === "number" && Number.isInteger(maxLength) && maxLength > 0) {
1376
+ return `varchar("${escapeDoubleQuote(f.fieldName)}", { length: ${maxLength} })`;
1377
+ }
1378
+ return `varchar("${escapeDoubleQuote(f.fieldName)}")`;
1379
+ },
1284
1380
  imports: () => [{ name: "varchar", from: PG_CORE }]
1285
1381
  },
1286
1382
  // text
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  generateSchemaFromData,
6
6
  normalizeApiResponse,
7
7
  resolveEnvOptions
8
- } from "./chunk-HRE26HBV.js";
8
+ } from "./chunk-PV4EVRKJ.js";
9
9
  export {
10
10
  generateSchema,
11
11
  generateSchemaCode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/db-schema-sync",
3
- "version": "0.1.6-alpha.3",
3
+ "version": "0.1.6-alpha.5",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  "node": ">=18.0.0"
30
30
  },
31
31
  "dependencies": {
32
- "@lark-apaas/http-client": "^0.1.6",
32
+ "@lark-apaas/http-client": "0.1.7-alpha.10",
33
33
  "dotenv": "^17.3.1",
34
34
  "tiny-pinyin": "^1.3.2"
35
35
  },