@adep/cli 0.1.12 → 0.1.13

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/index.js CHANGED
@@ -54,7 +54,8 @@ async function loadCredentials(paths) {
54
54
  return {
55
55
  server: parsed["server"],
56
56
  email: parsed["email"],
57
- encodedToken: parsed["encodedToken"]
57
+ encodedToken: parsed["encodedToken"],
58
+ ...typeof parsed["cookieName"] === "string" ? { cookieName: parsed["cookieName"] } : {}
58
59
  };
59
60
  } catch {
60
61
  return null;
@@ -69,6 +70,10 @@ function encodeToken(token) {
69
70
  function decodeToken(encoded) {
70
71
  return Buffer.from(encoded, "base64").toString("utf8");
71
72
  }
73
+ function sessionCookieHeader(credentials) {
74
+ const name = credentials.cookieName ?? (credentials.server.startsWith("https://") ? "__Secure-better-auth.session_token" : "better-auth.session_token");
75
+ return `${name}=${decodeToken(credentials.encodedToken)}`;
76
+ }
72
77
  var init_credentials = __esm({
73
78
  "packages/cli/src/credentials.ts"() {
74
79
  "use strict";
@@ -149,7 +154,7 @@ var init_net = __esm({
149
154
  // packages/cli/src/auth.ts
150
155
  function sessionCookieOf(setCookie) {
151
156
  const line = setCookie.find(
152
- (entry) => entry.startsWith("better-auth.session_token=") && !/max-age=0/i.test(entry)
157
+ (entry) => !/max-age=0/i.test(entry) && /^(?:__Secure-)?better-auth\.session_token=/.test(entry)
153
158
  );
154
159
  if (line === void 0) {
155
160
  throw new CliError("LOGIN_FAILED", "\u767B\u5F55\u6210\u529F\u4F46\u672A\u8FD4\u56DE\u4F1A\u8BDD token\uFF0C\u8BF7\u68C0\u67E5\u5E73\u53F0\u7248\u672C");
@@ -176,11 +181,14 @@ async function login(paths, input) {
176
181
  throw new CliError("LOGIN_FAILED", "\u767B\u5F55\u5931\u8D25\uFF1A\u90AE\u7BB1\u6216\u5BC6\u7801\u4E0D\u6B63\u786E\uFF08\u6216\u8BE5\u8D26\u53F7\u672A\u6CE8\u518C\uFF09");
177
182
  }
178
183
  const cookie = sessionCookieOf(response.headers.getSetCookie());
179
- const token = cookie.slice(cookie.indexOf("=") + 1);
184
+ const eq = cookie.indexOf("=");
185
+ const cookieName = cookie.slice(0, eq);
186
+ const token = cookie.slice(eq + 1);
180
187
  await saveCredentials(paths, {
181
188
  server,
182
189
  email: input.email,
183
- encodedToken: encodeToken(token)
190
+ encodedToken: encodeToken(token),
191
+ cookieName
184
192
  });
185
193
  return { email: input.email };
186
194
  }
@@ -191,7 +199,7 @@ async function whoami(paths) {
191
199
  throw new CliError("NOT_LOGGED_IN", "\u672A\u767B\u5F55\uFF1A\u8BF7\u5148\u6267\u884C adep login");
192
200
  }
193
201
  const response = await fetch(`${credentials.server}/api/auth/get-session`, {
194
- headers: { cookie: `better-auth.session_token=${decodeToken(credentials.encodedToken)}` }
202
+ headers: { cookie: sessionCookieHeader(credentials) }
195
203
  });
196
204
  if (response.status !== 200) {
197
205
  throw new CliError("SESSION_EXPIRED", "\u4F1A\u8BDD\u5DF2\u5931\u6548\uFF1A\u8BF7\u91CD\u65B0\u6267\u884C adep login");
@@ -209,7 +217,7 @@ async function logout(paths) {
209
217
  try {
210
218
  await fetch(`${credentials.server}/api/auth/sign-out`, {
211
219
  method: "POST",
212
- headers: { cookie: `better-auth.session_token=${decodeToken(credentials.encodedToken)}` }
220
+ headers: { cookie: sessionCookieHeader(credentials) }
213
221
  });
214
222
  } catch {
215
223
  }
@@ -1683,6 +1691,10 @@ function toNumber(raw) {
1683
1691
  const n = Number(t);
1684
1692
  return Number.isNaN(n) ? null : n;
1685
1693
  }
1694
+ function arithmeticOperand(v) {
1695
+ const n = Number(v);
1696
+ return Number.isFinite(n) ? n : 0;
1697
+ }
1686
1698
  function stripQuotes(raw) {
1687
1699
  const t = raw.trim();
1688
1700
  if (/^'.*'$/.test(t)) return t.slice(1, -1);
@@ -1837,10 +1849,6 @@ function resolveSetValue(value, existing, row) {
1837
1849
  return value;
1838
1850
  }
1839
1851
  function evalArithmetic(src, existing, row) {
1840
- const num = (v) => {
1841
- const n2 = Number(v);
1842
- return Number.isFinite(n2) ? n2 : 0;
1843
- };
1844
1852
  let i = 0;
1845
1853
  const n = src.length;
1846
1854
  const skip = () => {
@@ -1885,7 +1893,7 @@ function evalArithmetic(src, existing, row) {
1885
1893
  const id = parseIdent();
1886
1894
  if (id !== null) {
1887
1895
  const v = id.excluded ? row[id.col] : existing[id.col];
1888
- return num(v);
1896
+ return arithmeticOperand(v);
1889
1897
  }
1890
1898
  return 0;
1891
1899
  };
@@ -2035,6 +2043,9 @@ function parseSelectItem(raw) {
2035
2043
  const plain = unqualifyColumn(ident(name));
2036
2044
  return { name: plain, qualified, alias: as === null ? plain : ident(as[1] ?? ""), star: false };
2037
2045
  }
2046
+ function projectValueOf(row, item) {
2047
+ return item.qualified !== "" && row[item.qualified] !== void 0 ? row[item.qualified] : row[item.name];
2048
+ }
2038
2049
  function project(rows, selectRaw) {
2039
2050
  if (/^count\s*\(\s*\*/i.test(selectRaw) || /^count\s*\(\s*1\)/i.test(selectRaw)) {
2040
2051
  const alias = selectRaw.match(/\bAS\s+([A-Za-z_][A-Za-z0-9_]*)/i)?.[1] ?? "n";
@@ -2046,20 +2057,19 @@ function project(rows, selectRaw) {
2046
2057
  }
2047
2058
  if (selectRaw.trim() === "*") return rows;
2048
2059
  const items = selectRaw.split(",").map(parseSelectItem);
2049
- const valueOf = (row, item) => item.qualified !== "" && row[item.qualified] !== void 0 ? row[item.qualified] : row[item.name];
2050
2060
  if (items.some((item) => item.star)) {
2051
2061
  return rows.map((row) => {
2052
2062
  const out = { ...row };
2053
2063
  for (const item of items) {
2054
2064
  if (item.star) continue;
2055
- out[item.alias] = valueOf(row, item);
2065
+ out[item.alias] = projectValueOf(row, item);
2056
2066
  }
2057
2067
  return out;
2058
2068
  });
2059
2069
  }
2060
2070
  return rows.map((row) => {
2061
2071
  const out = {};
2062
- for (const item of items) out[item.alias] = valueOf(row, item);
2072
+ for (const item of items) out[item.alias] = projectValueOf(row, item);
2063
2073
  return out;
2064
2074
  });
2065
2075
  }
@@ -2581,7 +2591,7 @@ var init_driver = __esm({
2581
2591
  function compress(h, block, w) {
2582
2592
  for (let i = 0; i < 16; i += 1) {
2583
2593
  const j = i * 4;
2584
- w[i] = (block[j] ?? 0) << 24 | (block[j + 1] ?? 0) << 16 | (block[j + 2] ?? 0) << 8 | (block[j + 3] ?? 0);
2594
+ w[i] = block[j] << 24 | block[j + 1] << 16 | block[j + 2] << 8 | block[j + 3];
2585
2595
  }
2586
2596
  for (let i = 16; i < 64; i += 1) {
2587
2597
  const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ w[i - 15] >>> 3;
@@ -5159,7 +5169,7 @@ async function createClient(paths) {
5159
5169
  throw new CliError("NOT_LOGGED_IN", "\u672A\u767B\u5F55\uFF1A\u8BF7\u5148\u6267\u884C adep login");
5160
5170
  }
5161
5171
  const server = credentials.server;
5162
- const cookie = `better-auth.session_token=${decodeToken(credentials.encodedToken)}`;
5172
+ const cookie = sessionCookieHeader(credentials);
5163
5173
  const request = async (path, init = {}, fallbackCode = "API_REQUEST_FAILED") => {
5164
5174
  const method = init.method ?? (init.body === void 0 ? "GET" : "POST");
5165
5175
  let response;
package/dist/vite.js CHANGED
@@ -1134,6 +1134,10 @@ function toNumber(raw) {
1134
1134
  const n = Number(t);
1135
1135
  return Number.isNaN(n) ? null : n;
1136
1136
  }
1137
+ function arithmeticOperand(v) {
1138
+ const n = Number(v);
1139
+ return Number.isFinite(n) ? n : 0;
1140
+ }
1137
1141
  function stripQuotes(raw) {
1138
1142
  const t = raw.trim();
1139
1143
  if (/^'.*'$/.test(t)) return t.slice(1, -1);
@@ -1303,10 +1307,6 @@ function resolveSetValue(value, existing, row) {
1303
1307
  return value;
1304
1308
  }
1305
1309
  function evalArithmetic(src, existing, row) {
1306
- const num = (v) => {
1307
- const n2 = Number(v);
1308
- return Number.isFinite(n2) ? n2 : 0;
1309
- };
1310
1310
  let i = 0;
1311
1311
  const n = src.length;
1312
1312
  const skip = () => {
@@ -1351,7 +1351,7 @@ function evalArithmetic(src, existing, row) {
1351
1351
  const id = parseIdent();
1352
1352
  if (id !== null) {
1353
1353
  const v = id.excluded ? row[id.col] : existing[id.col];
1354
- return num(v);
1354
+ return arithmeticOperand(v);
1355
1355
  }
1356
1356
  return 0;
1357
1357
  };
@@ -1781,6 +1781,9 @@ function parseSelectItem(raw) {
1781
1781
  const plain = unqualifyColumn(ident(name));
1782
1782
  return { name: plain, qualified, alias: as === null ? plain : ident(as[1] ?? ""), star: false };
1783
1783
  }
1784
+ function projectValueOf(row, item) {
1785
+ return item.qualified !== "" && row[item.qualified] !== void 0 ? row[item.qualified] : row[item.name];
1786
+ }
1784
1787
  function project(rows, selectRaw) {
1785
1788
  if (/^count\s*\(\s*\*/i.test(selectRaw) || /^count\s*\(\s*1\)/i.test(selectRaw)) {
1786
1789
  const alias = selectRaw.match(/\bAS\s+([A-Za-z_][A-Za-z0-9_]*)/i)?.[1] ?? "n";
@@ -1792,20 +1795,19 @@ function project(rows, selectRaw) {
1792
1795
  }
1793
1796
  if (selectRaw.trim() === "*") return rows;
1794
1797
  const items = selectRaw.split(",").map(parseSelectItem);
1795
- const valueOf = (row, item) => item.qualified !== "" && row[item.qualified] !== void 0 ? row[item.qualified] : row[item.name];
1796
1798
  if (items.some((item) => item.star)) {
1797
1799
  return rows.map((row) => {
1798
1800
  const out = { ...row };
1799
1801
  for (const item of items) {
1800
1802
  if (item.star) continue;
1801
- out[item.alias] = valueOf(row, item);
1803
+ out[item.alias] = projectValueOf(row, item);
1802
1804
  }
1803
1805
  return out;
1804
1806
  });
1805
1807
  }
1806
1808
  return rows.map((row) => {
1807
1809
  const out = {};
1808
- for (const item of items) out[item.alias] = valueOf(row, item);
1810
+ for (const item of items) out[item.alias] = projectValueOf(row, item);
1809
1811
  return out;
1810
1812
  });
1811
1813
  }
@@ -2058,7 +2060,7 @@ var rotr = (x, n) => x >>> n | x << 32 - n;
2058
2060
  function compress(h, block, w) {
2059
2061
  for (let i = 0; i < 16; i += 1) {
2060
2062
  const j = i * 4;
2061
- w[i] = (block[j] ?? 0) << 24 | (block[j + 1] ?? 0) << 16 | (block[j + 2] ?? 0) << 8 | (block[j + 3] ?? 0);
2063
+ w[i] = block[j] << 24 | block[j + 1] << 16 | block[j + 2] << 8 | block[j + 3];
2062
2064
  }
2063
2065
  for (let i = 16; i < 64; i += 1) {
2064
2066
  const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ w[i - 15] >>> 3;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adep/cli",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "type": "module",
5
5
  "description": "`adep` 命令行工具包位:登录 / 初始化 / 本地调试 / 部署 / 数据库维护 / 云存储 / 静态托管 / 微前端组件(widget),实现见任务单 CLI-001 ~ CLI-003 与 FE-002;子路径 `@adep/cli/vite` 提供云函数 vite 插件(CLI-014)",
6
6
  "bin": {
@@ -24,8 +24,8 @@
24
24
  "@adep/vite-plugin": "0.1.5"
25
25
  },
26
26
  "devDependencies": {
27
- "@adep/types": "0.2.3",
28
- "@adep/runtime": "0.2.5"
27
+ "@adep/runtime": "0.2.6",
28
+ "@adep/types": "0.2.3"
29
29
  },
30
30
  "scripts": {
31
31
  "test": "vitest run",