cawdev-cli 0.9.0 → 1.0.0-beta

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.
@@ -60,6 +60,18 @@ export async function loadToken(url) {
60
60
  return typeof stored?.token === 'string' && stored.token ? stored.token : null;
61
61
  }
62
62
 
63
+ /**
64
+ * The whole record for one instance — R283, and the reason it exists beside
65
+ * {@link loadToken} rather than replacing it: widening this token's grants
66
+ * (`PUT /api/tokens/{id}/grants`, R173's own mechanism) needs the token's
67
+ * PUBLIC id, which is not the secret and was never stored before this. A
68
+ * record with no `id` — every token minted before R283 — is not an error;
69
+ * the caller falls back to looking it up by label.
70
+ */
71
+ export async function loadTokenRecord(url) {
72
+ return (await readAll())[key(url)] ?? null;
73
+ }
74
+
63
75
  /**
64
76
  * The instances this machine holds a token for.
65
77
  *
@@ -79,9 +91,9 @@ export async function storedUrls() {
79
91
  * that already exists — so asking for 0600 and getting 0644 is the ordinary
80
92
  * outcome rather than the unusual one.
81
93
  */
82
- export async function saveToken(url, token, { name = null } = {}) {
94
+ export async function saveToken(url, token, { name = null, id = null } = {}) {
83
95
  const all = await readAll();
84
- all[key(url)] = { token, name, mintedAt: new Date().toISOString() };
96
+ all[key(url)] = { token, name, id, mintedAt: new Date().toISOString() };
85
97
  await mkdir(dirname(tokenFile()), { recursive: true, mode: 0o700 });
86
98
  await writeFile(tokenFile(), `${JSON.stringify(all, null, 2)}\n`, { mode: 0o600 });
87
99
  await chmod(tokenFile(), 0o600).catch(() => undefined);