@tinycloud/operations 0.4.0-beta.12 → 0.4.0-beta.14

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.
@@ -257,8 +257,17 @@ function canonicalizeRecapCaveats(caveats) {
257
257
  }
258
258
  return `[${branches.join(",")}]`;
259
259
  }
260
+ var EXPLICIT_ONLY_ACTIONS = {
261
+ "tinycloud.kv/sync": true,
262
+ "tinycloud.kv/retain": true
263
+ };
264
+ function isExplicitOnlyAction(action) {
265
+ return Object.prototype.hasOwnProperty.call(EXPLICIT_ONLY_ACTIONS, action);
266
+ }
260
267
  function actionContains(grantedAction, requestedAction) {
261
- if (grantedAction === "*" || grantedAction === requestedAction) return true;
268
+ if (grantedAction === requestedAction) return true;
269
+ if (isExplicitOnlyAction(requestedAction)) return false;
270
+ if (grantedAction === "*") return true;
262
271
  if (!grantedAction.endsWith("/*")) return false;
263
272
  const service = grantedAction.slice(0, -2);
264
273
  return requestedAction === service || requestedAction.startsWith(`${service}/`);
@@ -573,7 +582,8 @@ async function acquireProfileLock(profile, options) {
573
582
  const lockPath = profileLockPath(profile);
574
583
  const turnDirectory = profileTurnLockPath(profile);
575
584
  const directory = profilePath(profile);
576
- await mkdir(directory, { recursive: true, mode: PRIVATE_DIR_MODE });
585
+ if (options.requireProfile && !await exists(profileConfigPath(profile))) throw new ProfileDeletedError(profile);
586
+ if (!options.requireProfile) await mkdir(directory, { recursive: true, mode: PRIVATE_DIR_MODE });
577
587
  await mkdir(dirname(turnDirectory), { recursive: true, mode: PRIVATE_DIR_MODE });
578
588
  for (const path of [tinycloudHomePath(), profilesPath(), directory]) {
579
589
  await chmod(path, PRIVATE_DIR_MODE).catch((error) => {
@@ -582,11 +592,15 @@ async function acquireProfileLock(profile, options) {
582
592
  }
583
593
  const { turn, firstWaitedTurn } = await acquireTurn(profile, turnDirectory, deadline);
584
594
  try {
595
+ if (options.requireProfile && !await exists(profileConfigPath(profile))) {
596
+ await rmdir(directory).catch(() => void 0);
597
+ throw new ProfileDeletedError(profile);
598
+ }
585
599
  const deletion = await readJson(join(turnDirectory, "deleted.json")).catch(() => null);
586
600
  const deletedWhileWaiting = typeof deletion?.slot === "number" && deletion.slot >= firstWaitedTurn;
587
601
  while (true) {
588
602
  const token = randomUUID();
589
- if (await publishProfileLock(profile, lockPath, token)) {
603
+ if (await publishProfileLock(profile, lockPath, token, options.requireProfile === true)) {
590
604
  return {
591
605
  deletedWhileWaiting,
592
606
  turnSlot: turn.slot,
@@ -837,12 +851,13 @@ async function collectTurns(profile, turn) {
837
851
  }
838
852
  }
839
853
  }
840
- async function publishProfileLock(profile, lockPath, token) {
854
+ async function publishProfileLock(profile, lockPath, token, requireProfile) {
841
855
  try {
842
856
  await mkdir(lockPath, { mode: PRIVATE_DIR_MODE });
843
857
  } catch (error) {
844
858
  if (isErrno(error, "EEXIST")) return false;
845
859
  if (!isErrno(error, "ENOENT")) throw error;
860
+ if (requireProfile) throw new ProfileDeletedError(profile);
846
861
  await mkdir(profilePath(profile), { recursive: true, mode: PRIVATE_DIR_MODE });
847
862
  return false;
848
863
  }