@rigxyz/tapd 0.5.2 → 0.6.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/bin.js CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  ImportValidationFailed,
7
7
  InvalidInviteUrlError,
8
8
  NotInitializedError,
9
+ OrgForbiddenError,
9
10
  RelayClient,
10
11
  STATE_KEY_CONFLICT_COUNT,
11
12
  addImport,
@@ -23,11 +24,12 @@ import {
23
24
  readBindingConfig,
24
25
  removeImport,
25
26
  revoke,
27
+ safeResolveRigPath,
26
28
  start
27
- } from "./chunk-LQWX63LP.js";
29
+ } from "./chunk-GIL4KPR7.js";
28
30
 
29
31
  // src/bin.ts
30
- import { join as pathJoin, resolve as resolve2 } from "path";
32
+ import { join as pathJoin, resolve } from "path";
31
33
  import kleur from "kleur";
32
34
 
33
35
  // src/defaults.ts
@@ -187,7 +189,7 @@ async function history(opts) {
187
189
  // src/restore.ts
188
190
  import { createHash } from "crypto";
189
191
  import { existsSync as existsSync3, mkdirSync as mkdirSync2, renameSync, writeFileSync as writeFileSync2 } from "fs";
190
- import { dirname as dirname2, join as join3, resolve } from "path";
192
+ import { dirname as dirname2, join as join3 } from "path";
191
193
  var PathNeverExistedError = class extends Error {
192
194
  constructor(path) {
193
195
  super(`No events for path "${path}" \u2014 never written through this binding.`);
@@ -234,6 +236,7 @@ function sha256Hex(bytes) {
234
236
  return createHash("sha256").update(bytes).digest("hex");
235
237
  }
236
238
  async function restore(opts) {
239
+ const targetAbs = safeResolveRigPath(opts.rootDir, opts.path);
237
240
  const events = await history({
238
241
  rootDir: opts.rootDir,
239
242
  path: opts.path,
@@ -257,7 +260,6 @@ async function restore(opts) {
257
260
  if (actualHash !== writeEvent.hash) {
258
261
  throw new HashMismatchError(opts.path, writeEvent.hash, actualHash);
259
262
  }
260
- const targetAbs = resolve(opts.rootDir, opts.path);
261
263
  const overwrote = existsSync3(targetAbs);
262
264
  mkdirSync2(dirname2(targetAbs), { recursive: true });
263
265
  const tmp = `${targetAbs}.tap-restore-tmp.${Date.now().toString(36)}`;
@@ -278,7 +280,7 @@ import { existsSync as existsSync4 } from "fs";
278
280
  import { join as join4 } from "path";
279
281
 
280
282
  // src/version.ts
281
- var TAPD_VERSION = "0.5.1";
283
+ var TAPD_VERSION = "0.6.0";
282
284
 
283
285
  // src/status.ts
284
286
  var STATE_KEY_LAST_APPLY_ERROR = "last_apply_error";
@@ -587,6 +589,7 @@ ${C.bold().cyan("tapd init OPTIONS")}
587
589
  ${C.dim("--name <n>")} binding display name (required)
588
590
  ${C.dim("--relay <url>")} override (defaults to the logged-in relay)
589
591
  ${C.dim("--device-label <l>")} default 'owner'
592
+ ${C.dim("--org <slug>")} create this binding under an org you belong to
590
593
  ${C.dim("--dir <path>")} default cwd
591
594
 
592
595
  ${C.bold().cyan("tapd join OPTIONS")}
@@ -663,7 +666,7 @@ function collectPathGlobs(flags2) {
663
666
  async function runMembers(positional2, flags2) {
664
667
  const json = flags2.get("json") === true;
665
668
  const sub = positional2[0];
666
- const rootDir = resolve2(flags2.get("dir") ?? process.cwd());
669
+ const rootDir = resolve(flags2.get("dir") ?? process.cwd());
667
670
  const VALID_ROLES2 = /* @__PURE__ */ new Set(["owner", "editor", "viewer"]);
668
671
  try {
669
672
  if (sub === void 0 || sub === "list") {
@@ -759,7 +762,7 @@ async function runMembers(positional2, flags2) {
759
762
  async function runInvite(positional2, flags2) {
760
763
  const json = flags2.get("json") === true;
761
764
  const sub = positional2[0];
762
- const rootDir = resolve2(flags2.get("dir") ?? process.cwd());
765
+ const rootDir = resolve(flags2.get("dir") ?? process.cwd());
763
766
  try {
764
767
  if (sub === void 0 || sub === "create") {
765
768
  const ops = parseOps(flags2.get("ops"));
@@ -911,7 +914,7 @@ async function runJoin(positional2, flags2) {
911
914
  throw err;
912
915
  }
913
916
  }
914
- const rootDir = resolve2(flags2.get("dir") ?? process.cwd());
917
+ const rootDir = resolve(flags2.get("dir") ?? process.cwd());
915
918
  const deviceLabel = flags2.get("device-label");
916
919
  let result;
917
920
  try {
@@ -956,7 +959,7 @@ async function runJoin(positional2, flags2) {
956
959
  }
957
960
  async function runImport(positional2, flags2) {
958
961
  const json = flags2.get("json") === true;
959
- const rootDir = resolve2(flags2.get("dir") ?? process.cwd());
962
+ const rootDir = resolve(flags2.get("dir") ?? process.cwd());
960
963
  const sub = positional2[0];
961
964
  if (sub === "remove") {
962
965
  const name = positional2[1];
@@ -1079,7 +1082,7 @@ async function runImport(positional2, flags2) {
1079
1082
  }
1080
1083
  async function runStatus(flags2) {
1081
1084
  const json = flags2.get("json") === true;
1082
- const rootDir = resolve2(flags2.get("dir") ?? process.cwd());
1085
+ const rootDir = resolve(flags2.get("dir") ?? process.cwd());
1083
1086
  let report;
1084
1087
  try {
1085
1088
  report = await status({ rootDir });
@@ -1143,7 +1146,7 @@ async function runStatus(flags2) {
1143
1146
  async function runUninit(flags2) {
1144
1147
  const json = flags2.get("json") === true;
1145
1148
  const purge = flags2.get("purge") === true;
1146
- const rootDir = resolve2(flags2.get("dir") ?? process.cwd());
1149
+ const rootDir = resolve(flags2.get("dir") ?? process.cwd());
1147
1150
  let result;
1148
1151
  try {
1149
1152
  result = uninit({ rootDir, purge });
@@ -1200,7 +1203,7 @@ async function runUninit(flags2) {
1200
1203
  }
1201
1204
  }
1202
1205
  async function runStart(flags2) {
1203
- const rootDir = resolve2(flags2.get("dir") ?? process.cwd());
1206
+ const rootDir = resolve(flags2.get("dir") ?? process.cwd());
1204
1207
  const pollSeconds = flags2.has("poll-seconds") ? Number(flags2.get("poll-seconds")) : void 0;
1205
1208
  const pidfilePath = flags2.get("no-pidfile") === true ? null : pathJoin(rootDir, DAEMON_PIDFILE_REL3);
1206
1209
  let handle = null;
@@ -1246,7 +1249,7 @@ async function runStart(flags2) {
1246
1249
  }
1247
1250
  async function runHistory(flags2) {
1248
1251
  const json = flags2.get("json") === true;
1249
- const rootDir = resolve2(flags2.get("dir") ?? process.cwd());
1252
+ const rootDir = resolve(flags2.get("dir") ?? process.cwd());
1250
1253
  const path = flags2.get("path");
1251
1254
  const asOf = flags2.get("as-of");
1252
1255
  if (!path) {
@@ -1294,7 +1297,7 @@ async function runHistory(flags2) {
1294
1297
  }
1295
1298
  async function runRestore(flags2) {
1296
1299
  const json = flags2.get("json") === true;
1297
- const rootDir = resolve2(flags2.get("dir") ?? process.cwd());
1300
+ const rootDir = resolve(flags2.get("dir") ?? process.cwd());
1298
1301
  const path = flags2.get("path");
1299
1302
  const asOf = flags2.get("as-of");
1300
1303
  if (!path) {
@@ -1369,11 +1372,19 @@ async function runInit(flags2) {
1369
1372
  throw err;
1370
1373
  }
1371
1374
  const relayUrl = flags2.get("relay") ?? process.env.RIG_RELAY_URL ?? DEFAULT_RELAY_URL;
1372
- const rootDir = resolve2(flags2.get("dir") ?? process.cwd());
1375
+ const rootDir = resolve(flags2.get("dir") ?? process.cwd());
1373
1376
  const deviceLabel = flags2.get("device-label");
1377
+ const orgRaw = flags2.get("org");
1378
+ if (orgRaw !== void 0 && (typeof orgRaw !== "string" || !orgRaw.trim() || orgRaw.startsWith("-"))) {
1379
+ const msg = "--org requires a slug (e.g. --org acme-labs)";
1380
+ if (json) printJsonError("invalid_flag", msg);
1381
+ else console.error(kleur.red("error:"), msg);
1382
+ process.exit(2);
1383
+ }
1384
+ const org = orgRaw;
1374
1385
  let result;
1375
1386
  try {
1376
- result = await init({ rootDir, relayUrl, accessToken, bindingName: name, deviceLabel });
1387
+ result = await init({ rootDir, relayUrl, accessToken, bindingName: name, deviceLabel, org });
1377
1388
  } catch (err) {
1378
1389
  if (err instanceof AlreadyInitializedError) {
1379
1390
  if (json) printJsonError("already_initialized", err.message);
@@ -1383,6 +1394,11 @@ async function runInit(flags2) {
1383
1394
  }
1384
1395
  process.exit(1);
1385
1396
  }
1397
+ if (err instanceof OrgForbiddenError) {
1398
+ if (json) printJsonError("org_forbidden", err.message);
1399
+ else console.error(kleur.red("error:"), err.message);
1400
+ process.exit(1);
1401
+ }
1386
1402
  throw err;
1387
1403
  }
1388
1404
  if (json) {