@somewhere-cloud/cli 0.38.168 → 0.38.170

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.38.170
4
+
5
+ - Import app users from a CSV with bcrypt password hashes using `somewhere db import --source users users.csv`.
6
+
7
+ ## 0.38.169
8
+
9
+ - Fix the API path used by `somewhere db import --source supabase`.
10
+
3
11
  ## 0.38.168
4
12
 
5
13
  - Use `somewhere db import --source supabase` to plan a copy, import rows into declared tables, and read the job receipt.
@@ -20314,7 +20314,7 @@ var require_snapshot_utils = __commonJS({
20314
20314
  var require_snapshot_recorder = __commonJS({
20315
20315
  "node_modules/undici/lib/mock/snapshot-recorder.js"(exports, module) {
20316
20316
  "use strict";
20317
- var { writeFile: writeFile2, readFile: readFile2, mkdir } = __require("node:fs/promises");
20317
+ var { writeFile: writeFile2, readFile: readFile3, mkdir } = __require("node:fs/promises");
20318
20318
  var { dirname: dirname17, resolve: resolve27 } = __require("node:path");
20319
20319
  var { setTimeout: setTimeout2, clearTimeout: clearTimeout2 } = __require("node:timers");
20320
20320
  var { InvalidArgumentError: InvalidArgumentError2, UndiciError } = require_errors();
@@ -20541,7 +20541,7 @@ var require_snapshot_recorder = __commonJS({
20541
20541
  throw new InvalidArgumentError2("Snapshot path is required");
20542
20542
  }
20543
20543
  try {
20544
- const data2 = await readFile2(resolve27(path3), "utf8");
20544
+ const data2 = await readFile3(resolve27(path3), "utf8");
20545
20545
  const parsed = JSON.parse(data2);
20546
20546
  if (Array.isArray(parsed)) {
20547
20547
  this.#snapshots.clear();
@@ -76655,8 +76655,8 @@ var init_esm4 = __esm({
76655
76655
  }
76656
76656
  return this._userIgnored(path3, stats);
76657
76657
  }
76658
- _isntIgnored(path3, stat6) {
76659
- return !this._isIgnored(path3, stat6);
76658
+ _isntIgnored(path3, stat7) {
76659
+ return !this._isIgnored(path3, stat7);
76660
76660
  }
76661
76661
  /**
76662
76662
  * Provides a set of common helpers and properties relating to symlink handling.
@@ -80412,19 +80412,19 @@ function resolveBrowserUpload(raw, baseDir = process.cwd()) {
80412
80412
  return inline;
80413
80413
  }
80414
80414
  const absolute = resolve12(baseDir, raw);
80415
- let stat6;
80415
+ let stat7;
80416
80416
  try {
80417
- stat6 = statSync4(absolute);
80417
+ stat7 = statSync4(absolute);
80418
80418
  } catch {
80419
80419
  const inline = inlineBrowserUpload(raw);
80420
80420
  if (inline)
80421
80421
  return inline;
80422
80422
  throw new Error(`upload file is not readable: ${absolute}`);
80423
80423
  }
80424
- if (!stat6.isFile())
80424
+ if (!stat7.isFile())
80425
80425
  throw new Error(`upload path is not a regular file: ${absolute}`);
80426
- if (stat6.size > MAX_BROWSER_UPLOAD_BYTES) {
80427
- throw new Error(`BROWSER_UPLOAD_TOO_LARGE: Upload file is ${stat6.size} bytes; the browser upload limit is ${MAX_BROWSER_UPLOAD_BYTES} bytes (10 MB).`);
80426
+ if (stat7.size > MAX_BROWSER_UPLOAD_BYTES) {
80427
+ throw new Error(`BROWSER_UPLOAD_TOO_LARGE: Upload file is ${stat7.size} bytes; the browser upload limit is ${MAX_BROWSER_UPLOAD_BYTES} bytes (10 MB).`);
80428
80428
  }
80429
80429
  const name = basename4(absolute);
80430
80430
  const contentType2 = MIME_TYPES[extname4(name).toLowerCase()] ?? "application/octet-stream";
@@ -85971,10 +85971,10 @@ function registerPull(program2) {
85971
85971
  throw new Error(`Conflicting exported source path: ${path3}`);
85972
85972
  }
85973
85973
  const target2 = join35(outDir, ...parts.slice(0, i));
85974
- const stat6 = lstatSync4(target2, { throwIfNoEntry: false });
85975
- if (!stat6)
85974
+ const stat7 = lstatSync4(target2, { throwIfNoEntry: false });
85975
+ if (!stat7)
85976
85976
  continue;
85977
- if (stat6.isSymbolicLink() || (i < parts.length ? !stat6.isDirectory() : !stat6.isFile())) {
85977
+ if (stat7.isSymbolicLink() || (i < parts.length ? !stat7.isDirectory() : !stat7.isFile())) {
85978
85978
  throw new Error(`Pull would conflict with local path ${path3}. Pull into a fresh folder.`);
85979
85979
  }
85980
85980
  }
@@ -86846,13 +86846,39 @@ var init_restore = __esm({
86846
86846
  });
86847
86847
 
86848
86848
  // dist/commands/db-import.js
86849
+ import { readFile as readFile2, stat as stat4 } from "node:fs/promises";
86849
86850
  function registerDbImport(db) {
86850
- db.command("import [tables...]").description("Generate a table declaration or plan and copy rows from Supabase").option("--source <source>", "Set to supabase to import from the app\u2019s Supabase Data API").option("--project <id>", "Project ID (defaults to the linked project)").option("--all", "Copy all exposed Supabase tables").option("--order-by <column>", "Stable unique column for a table without a single supported primary key").option("--resume", "Skip existing destination primary keys").option("--job <id>", "Read the progress and receipt of a Supabase import job").action(async (tables, options2) => {
86851
- if (options2.source !== void 0 && options2.source !== "supabase") {
86852
- error("--source must be supabase when provided.");
86851
+ db.command("import [tables...]").description("Generate a table declaration or import Supabase tables or app users").option("--source <source>", "Import Supabase tables or import user CSV with the project owner\u2019s full-scope developer key").option("--project <id>", "Project ID (defaults to the linked project)").option("--all", "Copy all exposed Supabase tables").option("--order-by <column>", "Stable unique column for a table without a single supported primary key").option("--resume", "Skip existing destination primary keys").option("--job <id>", "Read the progress and receipt of a Supabase import job").action(async (tables, options2) => {
86852
+ if (options2.source !== void 0 && options2.source !== "supabase" && options2.source !== "users") {
86853
+ error("--source must be supabase or users when provided.");
86853
86854
  process.exitCode = 1;
86854
86855
  return;
86855
86856
  }
86857
+ if (options2.source === "users") {
86858
+ if (tables.length !== 1 || tables[0] === "-" || options2.all || options2.orderBy || options2.resume || options2.job) {
86859
+ error("Use somewhere db import --source users users.csv with one CSV file.");
86860
+ process.exitCode = 1;
86861
+ return;
86862
+ }
86863
+ let csv;
86864
+ try {
86865
+ const file = await stat4(tables[0]);
86866
+ if (!file.isFile() || file.size > 5 * 1024 * 1024) {
86867
+ error("Send a user CSV file up to 5 MB.");
86868
+ process.exitCode = 1;
86869
+ return;
86870
+ }
86871
+ csv = await readFile2(tables[0], "utf8");
86872
+ } catch {
86873
+ error("Could not read the user CSV file.");
86874
+ process.exitCode = 1;
86875
+ return;
86876
+ }
86877
+ const project2 = resolveProjectRef(options2.project);
86878
+ const client2 = new ApiClient(getToken());
86879
+ printJson(await client2.call("POST", "/auth/import", { project_id: project2, csv }, void 0, { timeoutMs: 9e4 }));
86880
+ return;
86881
+ }
86856
86882
  const supabase = options2.source === "supabase";
86857
86883
  if (!supabase && (tables.length !== 1 || options2.all || options2.orderBy || options2.resume || options2.job)) {
86858
86884
  error("Name one table to generate its declaration, or use --source supabase.");
@@ -86873,7 +86899,7 @@ function registerDbImport(db) {
86873
86899
  job_id: options2.job
86874
86900
  } : { table: tables[0] };
86875
86901
  const client = new ApiClient(getToken());
86876
- printJson(await client.call("POST", "/v1/db/import", { project_id: project, ...body }, void 0, { timeoutMs: 9e4 }));
86902
+ printJson(await client.call("POST", "/db/import", { project_id: project, ...body }, void 0, { timeoutMs: 9e4 }));
86877
86903
  });
86878
86904
  }
86879
86905
  var init_db_import = __esm({
@@ -87731,8 +87757,8 @@ function isDotenvPath(path3) {
87731
87757
  function buildAdvisorContext(filePath) {
87732
87758
  const context = {};
87733
87759
  if (filePath) {
87734
- const stat6 = statSync6(filePath);
87735
- if (!stat6.isFile())
87760
+ const stat7 = statSync6(filePath);
87761
+ if (!stat7.isFile())
87736
87762
  throw new Error("--file must name a regular file.");
87737
87763
  const content = readFileSync34(filePath, "utf8");
87738
87764
  context.file = {
@@ -91919,7 +91945,7 @@ var init_check = __esm({
91919
91945
 
91920
91946
  // dist/commands/api.js
91921
91947
  import { createReadStream } from "node:fs";
91922
- import { stat as stat4 } from "node:fs/promises";
91948
+ import { stat as stat5 } from "node:fs/promises";
91923
91949
  import { extname as extname5, resolve as resolve22 } from "node:path";
91924
91950
  function registerApi(program2) {
91925
91951
  program2.command("api <method> <path>").description("Make a raw API call (adds auth automatically)").option("-d, --data <json>", "JSON body").option("--data-file <path>", "Stream the request body from a file; use - for stdin").option("--content-type <type>", "Content type for --data-file (defaults to JSON for .json/stdin, otherwise octet-stream)").option("--raw", "Print the response body as-is without JSON-parsing \u2014 for non-JSON endpoints (e.g. a SQL db dump); a 200 non-JSON body is not treated as an error").option("--json", "Print parsed JSON (the default; accepted for automation consistency)").action(async (method, path3, opts) => {
@@ -91972,7 +91998,7 @@ function registerApi(program2) {
91972
91998
  try {
91973
91999
  const stdin = opts.dataFile === "-";
91974
92000
  const source = stdin ? void 0 : resolve22(opts.dataFile);
91975
- const file = source ? await stat4(source) : void 0;
92001
+ const file = source ? await stat5(source) : void 0;
91976
92002
  if (file && !file.isFile())
91977
92003
  throw new Error(`${opts.dataFile} is not a file.`);
91978
92004
  const headers = {
@@ -92140,7 +92166,7 @@ var init_api2 = __esm({
92140
92166
 
92141
92167
  // dist/commands/fs.js
92142
92168
  import { createReadStream as createReadStream2, createWriteStream as createWriteStream3 } from "node:fs";
92143
- import { stat as stat5, rename as rename2, unlink as unlink2 } from "node:fs/promises";
92169
+ import { stat as stat6, rename as rename2, unlink as unlink2 } from "node:fs/promises";
92144
92170
  import { randomUUID as randomUUID10 } from "node:crypto";
92145
92171
  import { basename as basename9, dirname as dirname14, extname as extname6, join as join43, resolve as resolve23 } from "node:path";
92146
92172
  import { pipeline as pipeline3 } from "node:stream/promises";
@@ -92152,7 +92178,7 @@ function registerFs(program2) {
92152
92178
  throw new CliApiError("INVALID_REMOTE_PATH", "Upload destination must name a file and cannot end with `/`.", 0);
92153
92179
  }
92154
92180
  const source = resolve23(local);
92155
- const file = await stat5(source);
92181
+ const file = await stat6(source);
92156
92182
  if (!file.isFile())
92157
92183
  throw new Error(`${local} is not a file.`);
92158
92184
  const project = resolveProject(opts.project);
@@ -109988,7 +110014,7 @@ var require_polyfill = __commonJS({
109988
110014
  mkdir,
109989
110015
  readdir: readdir3,
109990
110016
  readlink,
109991
- stat: stat6,
110017
+ stat: stat7,
109992
110018
  symlink,
109993
110019
  unlink: unlink3,
109994
110020
  utimes
@@ -110085,7 +110111,7 @@ var require_polyfill = __commonJS({
110085
110111
  }
110086
110112
  __name(areIdentical, "areIdentical");
110087
110113
  function getStats(src, dest, opts) {
110088
- const statFunc = opts.dereference ? (file) => stat6(file, { bigint: true }) : (file) => lstat3(file, { bigint: true });
110114
+ const statFunc = opts.dereference ? (file) => stat7(file, { bigint: true }) : (file) => lstat3(file, { bigint: true });
110089
110115
  return Promise.all([
110090
110116
  statFunc(src),
110091
110117
  statFunc(dest).catch((err) => {
@@ -110108,7 +110134,7 @@ var require_polyfill = __commonJS({
110108
110134
  }
110109
110135
  __name(checkParentDir, "checkParentDir");
110110
110136
  function pathExists(dest) {
110111
- return stat6(dest).then(
110137
+ return stat7(dest).then(
110112
110138
  () => true,
110113
110139
  // istanbul ignore next: not sure when this would occur
110114
110140
  (err) => err.code === "ENOENT" ? false : Promise.reject(err)
@@ -110123,7 +110149,7 @@ var require_polyfill = __commonJS({
110123
110149
  }
110124
110150
  let destStat;
110125
110151
  try {
110126
- destStat = await stat6(destParent, { bigint: true });
110152
+ destStat = await stat7(destParent, { bigint: true });
110127
110153
  } catch (err) {
110128
110154
  if (err.code === "ENOENT") {
110129
110155
  return;
@@ -110163,7 +110189,7 @@ var require_polyfill = __commonJS({
110163
110189
  }
110164
110190
  __name(startCopy, "startCopy");
110165
110191
  async function getStatsForCopy(destStat, src, dest, opts) {
110166
- const statFn = opts.dereference ? stat6 : lstat3;
110192
+ const statFn = opts.dereference ? stat7 : lstat3;
110167
110193
  const srcStat = await statFn(src);
110168
110194
  if (srcStat.isDirectory() && opts.recursive) {
110169
110195
  return onDir(srcStat, destStat, src, dest, opts);
@@ -110256,7 +110282,7 @@ var require_polyfill = __commonJS({
110256
110282
  }
110257
110283
  __name(setDestMode, "setDestMode");
110258
110284
  async function setDestTimestamps(src, dest) {
110259
- const updatedSrcStat = await stat6(src);
110285
+ const updatedSrcStat = await stat7(src);
110260
110286
  return utimes(dest, updatedSrcStat.atime, updatedSrcStat.mtime);
110261
110287
  }
110262
110288
  __name(setDestTimestamps, "setDestTimestamps");
@@ -110312,7 +110338,7 @@ var require_polyfill = __commonJS({
110312
110338
  errno: EINVAL
110313
110339
  });
110314
110340
  }
110315
- const srcStat = await stat6(src);
110341
+ const srcStat = await stat7(src);
110316
110342
  if (srcStat.isDirectory() && isSrcSubdir(resolvedDest, resolvedSrc)) {
110317
110343
  throw new ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY({
110318
110344
  message: `cannot overwrite ${resolvedDest} with ${resolvedSrc}`,
@@ -110870,7 +110896,7 @@ var require_entry_index = __commonJS({
110870
110896
  var {
110871
110897
  appendFile,
110872
110898
  mkdir,
110873
- readFile: readFile2,
110899
+ readFile: readFile3,
110874
110900
  readdir: readdir3,
110875
110901
  rm,
110876
110902
  writeFile: writeFile2
@@ -111062,7 +111088,7 @@ ${hashEntry(stringified)} ${stringified}`);
111062
111088
  __name(ls2, "ls");
111063
111089
  module.exports.bucketEntries = bucketEntries;
111064
111090
  async function bucketEntries(bucket, filter) {
111065
- const data2 = await readFile2(bucket, "utf8");
111091
+ const data2 = await readFile3(bucket, "utf8");
111066
111092
  return _bucketEntries(data2, filter);
111067
111093
  }
111068
111094
  __name(bucketEntries, "bucketEntries");
@@ -112242,16 +112268,16 @@ var require_read = __commonJS({
112242
112268
  var MAX_SINGLE_READ_SIZE = 64 * 1024 * 1024;
112243
112269
  async function read(cache, integrity, opts = {}) {
112244
112270
  const { size } = opts;
112245
- const { stat: stat6, cpath, sri } = await withContentSri(cache, integrity, async (cpath2, sri2) => {
112246
- const stat7 = size ? { size } : await fs2.stat(cpath2);
112247
- return { stat: stat7, cpath: cpath2, sri: sri2 };
112271
+ const { stat: stat7, cpath, sri } = await withContentSri(cache, integrity, async (cpath2, sri2) => {
112272
+ const stat8 = size ? { size } : await fs2.stat(cpath2);
112273
+ return { stat: stat8, cpath: cpath2, sri: sri2 };
112248
112274
  });
112249
- if (stat6.size > MAX_SINGLE_READ_SIZE) {
112250
- return readPipeline(cpath, stat6.size, sri, new Pipeline()).concat();
112275
+ if (stat7.size > MAX_SINGLE_READ_SIZE) {
112276
+ return readPipeline(cpath, stat7.size, sri, new Pipeline()).concat();
112251
112277
  }
112252
112278
  const data2 = await fs2.readFile(cpath, { encoding: null });
112253
- if (stat6.size !== data2.length) {
112254
- throw sizeError(stat6.size, data2.length);
112279
+ if (stat7.size !== data2.length) {
112280
+ throw sizeError(stat7.size, data2.length);
112255
112281
  }
112256
112282
  if (!ssri.checkData(data2, sri)) {
112257
112283
  throw integrityError(sri, cpath);
@@ -112278,11 +112304,11 @@ var require_read = __commonJS({
112278
112304
  const { size } = opts;
112279
112305
  const stream = new Pipeline();
112280
112306
  Promise.resolve().then(async () => {
112281
- const { stat: stat6, cpath, sri } = await withContentSri(cache, integrity, async (cpath2, sri2) => {
112282
- const stat7 = size ? { size } : await fs2.stat(cpath2);
112283
- return { stat: stat7, cpath: cpath2, sri: sri2 };
112307
+ const { stat: stat7, cpath, sri } = await withContentSri(cache, integrity, async (cpath2, sri2) => {
112308
+ const stat8 = size ? { size } : await fs2.stat(cpath2);
112309
+ return { stat: stat8, cpath: cpath2, sri: sri2 };
112284
112310
  });
112285
- return readPipeline(cpath, stat6.size, sri, stream);
112311
+ return readPipeline(cpath, stat7.size, sri, stream);
112286
112312
  }).catch((err) => stream.emit("error", err));
112287
112313
  return stream;
112288
112314
  }
@@ -112301,8 +112327,8 @@ var require_read = __commonJS({
112301
112327
  }
112302
112328
  try {
112303
112329
  return await withContentSri(cache, integrity, async (cpath, sri) => {
112304
- const stat6 = await fs2.stat(cpath);
112305
- return { size: stat6.size, sri, stat: stat6 };
112330
+ const stat7 = await fs2.stat(cpath);
112331
+ return { size: stat7.size, sri, stat: stat7 };
112306
112332
  });
112307
112333
  } catch (err) {
112308
112334
  if (err.code === "ENOENT") {
@@ -115989,9 +116015,9 @@ var require_verify = __commonJS({
115989
116015
  "use strict";
115990
116016
  var {
115991
116017
  mkdir,
115992
- readFile: readFile2,
116018
+ readFile: readFile3,
115993
116019
  rm,
115994
- stat: stat6,
116020
+ stat: stat7,
115995
116021
  truncate: truncate2,
115996
116022
  writeFile: writeFile2
115997
116023
  } = __require("fs/promises");
@@ -116111,7 +116137,7 @@ var require_verify = __commonJS({
116111
116137
  }
116112
116138
  } else {
116113
116139
  stats.reclaimedCount++;
116114
- const s3 = await stat6(f2);
116140
+ const s3 = await stat7(f2);
116115
116141
  await rm(f2, { recursive: true, force: true });
116116
116142
  stats.reclaimedSize += s3.size;
116117
116143
  }
@@ -116125,7 +116151,7 @@ var require_verify = __commonJS({
116125
116151
  async function verifyContent(filepath, sri) {
116126
116152
  const contentInfo = {};
116127
116153
  try {
116128
- const { size } = await stat6(filepath);
116154
+ const { size } = await stat7(filepath);
116129
116155
  contentInfo.size = size;
116130
116156
  contentInfo.valid = true;
116131
116157
  await ssri.checkStream(new fsm.ReadStream(filepath), sri);
@@ -116185,7 +116211,7 @@ var require_verify = __commonJS({
116185
116211
  for (const entry of bucket) {
116186
116212
  const content = contentPath(cache, entry.integrity);
116187
116213
  try {
116188
- await stat6(content);
116214
+ await stat7(content);
116189
116215
  await index.insert(cache, entry.key, entry.integrity, {
116190
116216
  metadata: entry.metadata,
116191
116217
  size: entry.size,
@@ -116216,7 +116242,7 @@ var require_verify = __commonJS({
116216
116242
  __name(writeVerifile, "writeVerifile");
116217
116243
  module.exports.lastRun = lastRun;
116218
116244
  async function lastRun(cache) {
116219
- const data2 = await readFile2(path3.join(cache, "_lastverified"), { encoding: "utf8" });
116245
+ const data2 = await readFile3(path3.join(cache, "_lastverified"), { encoding: "utf8" });
116220
116246
  return /* @__PURE__ */ new Date(+data2);
116221
116247
  }
116222
116248
  __name(lastRun, "lastRun");
@@ -132706,12 +132732,12 @@ async function runPinnedNpm(args, cwd, ambientEnvironment, userConfigPath, globa
132706
132732
  function snapshotAuthenticatedArtifact(tarballPath) {
132707
132733
  const fd = openSync5(tarballPath, constants2.O_RDONLY | (constants2.O_NOFOLLOW ?? 0));
132708
132734
  try {
132709
- const stat6 = fstatSync(fd);
132710
- if (!stat6.isFile() || stat6.size <= 0 || stat6.size > MAX_UPDATE_BYTES) {
132735
+ const stat7 = fstatSync(fd);
132736
+ if (!stat7.isFile() || stat7.size <= 0 || stat7.size > MAX_UPDATE_BYTES) {
132711
132737
  throw new Error("the downloaded update artifact is not a usable regular file");
132712
132738
  }
132713
132739
  unlinkSync5(tarballPath);
132714
- return readOpenArtifact(fd, stat6.size);
132740
+ return readOpenArtifact(fd, stat7.size);
132715
132741
  } finally {
132716
132742
  closeSync5(fd);
132717
132743
  }