@tinycloud/operations 0.4.0-beta.9 → 0.5.0-beta.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.
@@ -2,7 +2,7 @@ import { PermissionEntry } from '@tinycloud/sdk-core';
2
2
  import { z } from 'zod';
3
3
  import { O as OperationSpaceResolver } from './authority-ofwbEqmj.cjs';
4
4
  export { e as evaluateAuthority } from './authority-ofwbEqmj.cjs';
5
- import { T as TinyCloudPosture, O as OperationOperatorType } from './contract-CjuEjE-M.cjs';
5
+ import { T as TinyCloudPosture, O as OperationOperatorType } from './contract-DfyrluLB.cjs';
6
6
 
7
7
  /** The shared wire schema for SDK PermissionEntry values, including signed ReCap caveats. */
8
8
  declare const PermissionEntrySchema: z.ZodObject<{
@@ -2,7 +2,7 @@ import { PermissionEntry } from '@tinycloud/sdk-core';
2
2
  import { z } from 'zod';
3
3
  import { O as OperationSpaceResolver } from './authority-ofwbEqmj.js';
4
4
  export { e as evaluateAuthority } from './authority-ofwbEqmj.js';
5
- import { T as TinyCloudPosture, O as OperationOperatorType } from './contract-CjuEjE-M.js';
5
+ import { T as TinyCloudPosture, O as OperationOperatorType } from './contract-DfyrluLB.js';
6
6
 
7
7
  /** The shared wire schema for SDK PermissionEntry values, including signed ReCap caveats. */
8
8
  declare const PermissionEntrySchema: z.ZodObject<{
package/dist/artifacts.js CHANGED
@@ -253,8 +253,17 @@ function canonicalizeRecapCaveats(caveats) {
253
253
  }
254
254
  return `[${branches.join(",")}]`;
255
255
  }
256
+ var EXPLICIT_ONLY_ACTIONS = {
257
+ "tinycloud.kv/sync": true,
258
+ "tinycloud.kv/retain": true
259
+ };
260
+ function isExplicitOnlyAction(action) {
261
+ return Object.prototype.hasOwnProperty.call(EXPLICIT_ONLY_ACTIONS, action);
262
+ }
256
263
  function actionContains(grantedAction, requestedAction) {
257
- if (grantedAction === "*" || grantedAction === requestedAction) return true;
264
+ if (grantedAction === requestedAction) return true;
265
+ if (isExplicitOnlyAction(requestedAction)) return false;
266
+ if (grantedAction === "*") return true;
258
267
  if (!grantedAction.endsWith("/*")) return false;
259
268
  const service = grantedAction.slice(0, -2);
260
269
  return requestedAction === service || requestedAction.startsWith(`${service}/`);
@@ -568,7 +577,8 @@ async function acquireProfileLock(profile, options) {
568
577
  const lockPath = profileLockPath(profile);
569
578
  const turnDirectory = profileTurnLockPath(profile);
570
579
  const directory = profilePath(profile);
571
- await mkdir(directory, { recursive: true, mode: PRIVATE_DIR_MODE });
580
+ if (options.requireProfile && !await exists(profileConfigPath(profile))) throw new ProfileDeletedError(profile);
581
+ if (!options.requireProfile) await mkdir(directory, { recursive: true, mode: PRIVATE_DIR_MODE });
572
582
  await mkdir(dirname(turnDirectory), { recursive: true, mode: PRIVATE_DIR_MODE });
573
583
  for (const path of [tinycloudHomePath(), profilesPath(), directory]) {
574
584
  await chmod(path, PRIVATE_DIR_MODE).catch((error) => {
@@ -577,11 +587,15 @@ async function acquireProfileLock(profile, options) {
577
587
  }
578
588
  const { turn, firstWaitedTurn } = await acquireTurn(profile, turnDirectory, deadline);
579
589
  try {
590
+ if (options.requireProfile && !await exists(profileConfigPath(profile))) {
591
+ await rmdir(directory).catch(() => void 0);
592
+ throw new ProfileDeletedError(profile);
593
+ }
580
594
  const deletion = await readJson(join(turnDirectory, "deleted.json")).catch(() => null);
581
595
  const deletedWhileWaiting = typeof deletion?.slot === "number" && deletion.slot >= firstWaitedTurn;
582
596
  while (true) {
583
597
  const token = randomUUID();
584
- if (await publishProfileLock(profile, lockPath, token)) {
598
+ if (await publishProfileLock(profile, lockPath, token, options.requireProfile === true)) {
585
599
  return {
586
600
  deletedWhileWaiting,
587
601
  turnSlot: turn.slot,
@@ -832,12 +846,13 @@ async function collectTurns(profile, turn) {
832
846
  }
833
847
  }
834
848
  }
835
- async function publishProfileLock(profile, lockPath, token) {
849
+ async function publishProfileLock(profile, lockPath, token, requireProfile) {
836
850
  try {
837
851
  await mkdir(lockPath, { mode: PRIVATE_DIR_MODE });
838
852
  } catch (error) {
839
853
  if (isErrno(error, "EEXIST")) return false;
840
854
  if (!isErrno(error, "ENOENT")) throw error;
855
+ if (requireProfile) throw new ProfileDeletedError(profile);
841
856
  await mkdir(profilePath(profile), { recursive: true, mode: PRIVATE_DIR_MODE });
842
857
  return false;
843
858
  }