@foliwake/cli 0.0.0-stage → 0.7.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.
Files changed (256) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/LICENSE +202 -0
  3. package/README.md +654 -2
  4. package/dist/bin.d.ts +2 -0
  5. package/dist/bin.js +9 -0
  6. package/dist/command-words.d.ts +13 -0
  7. package/dist/command-words.js +53 -0
  8. package/dist/commands/account/keys/create.d.ts +12 -0
  9. package/dist/commands/account/keys/create.js +36 -0
  10. package/dist/commands/account/keys/list.d.ts +9 -0
  11. package/dist/commands/account/keys/list.js +23 -0
  12. package/dist/commands/account/keys/revoke.d.ts +12 -0
  13. package/dist/commands/account/keys/revoke.js +15 -0
  14. package/dist/commands/branch/bootstrap.d.ts +11 -0
  15. package/dist/commands/branch/bootstrap.js +23 -0
  16. package/dist/commands/branch/delete.d.ts +17 -0
  17. package/dist/commands/branch/delete.js +38 -0
  18. package/dist/commands/branch/history.d.ts +14 -0
  19. package/dist/commands/branch/history.js +24 -0
  20. package/dist/commands/branch/list.d.ts +11 -0
  21. package/dist/commands/branch/list.js +15 -0
  22. package/dist/commands/branch/update.d.ts +19 -0
  23. package/dist/commands/branch/update.js +49 -0
  24. package/dist/commands/code/deploy.d.ts +15 -0
  25. package/dist/commands/code/deploy.js +78 -0
  26. package/dist/commands/code/prepare.d.ts +13 -0
  27. package/dist/commands/code/prepare.js +54 -0
  28. package/dist/commands/code/release.d.ts +19 -0
  29. package/dist/commands/code/release.js +51 -0
  30. package/dist/commands/code/rollback.d.ts +17 -0
  31. package/dist/commands/code/rollback.js +38 -0
  32. package/dist/commands/connect.d.ts +19 -0
  33. package/dist/commands/connect.js +100 -0
  34. package/dist/commands/create.d.ts +32 -0
  35. package/dist/commands/create.js +171 -0
  36. package/dist/commands/credential/list.d.ts +10 -0
  37. package/dist/commands/credential/list.js +21 -0
  38. package/dist/commands/credential/rm.d.ts +12 -0
  39. package/dist/commands/credential/rm.js +18 -0
  40. package/dist/commands/credential/set.d.ts +15 -0
  41. package/dist/commands/credential/set.js +58 -0
  42. package/dist/commands/dev.d.ts +30 -0
  43. package/dist/commands/dev.js +144 -0
  44. package/dist/commands/login.d.ts +20 -0
  45. package/dist/commands/login.js +94 -0
  46. package/dist/commands/logout.d.ts +14 -0
  47. package/dist/commands/logout.js +61 -0
  48. package/dist/commands/migration/commit.d.ts +13 -0
  49. package/dist/commands/migration/commit.js +42 -0
  50. package/dist/commands/migration/prepare.d.ts +18 -0
  51. package/dist/commands/migration/prepare.js +53 -0
  52. package/dist/commands/operation/cancel.d.ts +14 -0
  53. package/dist/commands/operation/cancel.js +21 -0
  54. package/dist/commands/operation/get.d.ts +14 -0
  55. package/dist/commands/operation/get.js +26 -0
  56. package/dist/commands/operation/list.d.ts +12 -0
  57. package/dist/commands/operation/list.js +25 -0
  58. package/dist/commands/operation/recover.d.ts +20 -0
  59. package/dist/commands/operation/recover.js +61 -0
  60. package/dist/commands/page/changes.d.ts +13 -0
  61. package/dist/commands/page/changes.js +26 -0
  62. package/dist/commands/page/check.d.ts +12 -0
  63. package/dist/commands/page/check.js +25 -0
  64. package/dist/commands/page/replace.d.ts +13 -0
  65. package/dist/commands/page/replace.js +59 -0
  66. package/dist/commands/page/unpreview.d.ts +17 -0
  67. package/dist/commands/page/unpreview.js +54 -0
  68. package/dist/commands/page/unpublish.d.ts +18 -0
  69. package/dist/commands/page/unpublish.js +36 -0
  70. package/dist/commands/project/preview.d.ts +8 -0
  71. package/dist/commands/project/preview.js +20 -0
  72. package/dist/commands/project/publish.d.ts +16 -0
  73. package/dist/commands/project/publish.js +40 -0
  74. package/dist/commands/project/unpublish.d.ts +16 -0
  75. package/dist/commands/project/unpublish.js +33 -0
  76. package/dist/commands/release/rollback.d.ts +17 -0
  77. package/dist/commands/release/rollback.js +38 -0
  78. package/dist/commands/servers/index.d.ts +20 -0
  79. package/dist/commands/servers/index.js +36 -0
  80. package/dist/commands/servers/use.d.ts +11 -0
  81. package/dist/commands/servers/use.js +30 -0
  82. package/dist/commands/site/adopt.d.ts +11 -0
  83. package/dist/commands/site/adopt.js +21 -0
  84. package/dist/commands/site/create.d.ts +18 -0
  85. package/dist/commands/site/create.js +61 -0
  86. package/dist/commands/site/edit.d.ts +11 -0
  87. package/dist/commands/site/edit.js +56 -0
  88. package/dist/commands/site/history.d.ts +11 -0
  89. package/dist/commands/site/history.js +25 -0
  90. package/dist/commands/site/link.d.ts +15 -0
  91. package/dist/commands/site/link.js +35 -0
  92. package/dist/commands/site/list.d.ts +9 -0
  93. package/dist/commands/site/list.js +29 -0
  94. package/dist/commands/site/reset-storage.d.ts +15 -0
  95. package/dist/commands/site/reset-storage.js +61 -0
  96. package/dist/commands/site/set.d.ts +16 -0
  97. package/dist/commands/site/set.js +45 -0
  98. package/dist/commands/site/show.d.ts +10 -0
  99. package/dist/commands/site/show.js +19 -0
  100. package/dist/commands/site/status.d.ts +11 -0
  101. package/dist/commands/site/status.js +15 -0
  102. package/dist/commands/site/unlink.d.ts +11 -0
  103. package/dist/commands/site/unlink.js +28 -0
  104. package/dist/commands/source/add.d.ts +32 -0
  105. package/dist/commands/source/add.js +103 -0
  106. package/dist/commands/source/adopt-pages.d.ts +14 -0
  107. package/dist/commands/source/adopt-pages.js +30 -0
  108. package/dist/commands/source/check.d.ts +17 -0
  109. package/dist/commands/source/check.js +52 -0
  110. package/dist/commands/source/list.d.ts +11 -0
  111. package/dist/commands/source/list.js +15 -0
  112. package/dist/commands/source/mappings/check.d.ts +13 -0
  113. package/dist/commands/source/mappings/check.js +69 -0
  114. package/dist/commands/source/pending.d.ts +12 -0
  115. package/dist/commands/source/pending.js +25 -0
  116. package/dist/commands/source/plugins.d.ts +6 -0
  117. package/dist/commands/source/plugins.js +17 -0
  118. package/dist/commands/source/sync.d.ts +16 -0
  119. package/dist/commands/source/sync.js +58 -0
  120. package/dist/commands/whoami.d.ts +6 -0
  121. package/dist/commands/whoami.js +22 -0
  122. package/dist/connect-prompts.d.ts +16 -0
  123. package/dist/connect-prompts.js +24 -0
  124. package/dist/connect.d.ts +133 -0
  125. package/dist/connect.js +416 -0
  126. package/dist/core-command.d.ts +99 -0
  127. package/dist/core-command.js +332 -0
  128. package/dist/core-types.d.ts +21 -0
  129. package/dist/core-types.js +1 -0
  130. package/dist/create-connect.d.ts +26 -0
  131. package/dist/create-connect.js +93 -0
  132. package/dist/dev/code-watcher.d.ts +66 -0
  133. package/dist/dev/code-watcher.js +254 -0
  134. package/dist/dev/dev-checks.d.ts +14 -0
  135. package/dist/dev/dev-checks.js +138 -0
  136. package/dist/dev/dev-reload.d.ts +51 -0
  137. package/dist/dev/dev-reload.js +345 -0
  138. package/dist/dev/flags.d.ts +19 -0
  139. package/dist/dev/flags.js +54 -0
  140. package/dist/dev/html.d.ts +30 -0
  141. package/dist/dev/html.js +106 -0
  142. package/dist/dev/kit-files.d.ts +7 -0
  143. package/dist/dev/kit-files.js +33 -0
  144. package/dist/dev/local-code.d.ts +22 -0
  145. package/dist/dev/local-code.js +101 -0
  146. package/dist/dev/remote-config.d.ts +57 -0
  147. package/dist/dev/remote-config.js +100 -0
  148. package/dist/dev/remote-dev.d.ts +41 -0
  149. package/dist/dev/remote-dev.js +527 -0
  150. package/dist/dev/remote-fetch.d.ts +5 -0
  151. package/dist/dev/remote-fetch.js +36 -0
  152. package/dist/dev/remote-html.d.ts +10 -0
  153. package/dist/dev/remote-html.js +60 -0
  154. package/dist/dev/remote-page.d.ts +34 -0
  155. package/dist/dev/remote-page.js +183 -0
  156. package/dist/dev/remote-routes.d.ts +63 -0
  157. package/dist/dev/remote-routes.js +114 -0
  158. package/dist/dev/signal-stop.d.ts +17 -0
  159. package/dist/dev/signal-stop.js +46 -0
  160. package/dist/dev/start.d.ts +18 -0
  161. package/dist/dev/start.js +80 -0
  162. package/dist/index.d.ts +6 -0
  163. package/dist/index.js +8 -0
  164. package/dist/lib/diagnostics.d.ts +15 -0
  165. package/dist/lib/diagnostics.js +12 -0
  166. package/dist/lib/front-matter.d.ts +6 -0
  167. package/dist/lib/front-matter.js +59 -0
  168. package/dist/lib/operation-result.d.ts +3 -0
  169. package/dist/lib/operation-result.js +16 -0
  170. package/dist/lib/problem-groups.d.ts +27 -0
  171. package/dist/lib/problem-groups.js +49 -0
  172. package/dist/lib/problems.d.ts +50 -0
  173. package/dist/lib/problems.js +94 -0
  174. package/dist/lib/prompts.d.ts +38 -0
  175. package/dist/lib/prompts.js +77 -0
  176. package/dist/lib/result-types.d.ts +198 -0
  177. package/dist/lib/result-types.js +3 -0
  178. package/dist/lib/rules.d.ts +15 -0
  179. package/dist/lib/rules.js +26 -0
  180. package/dist/lib/summaries.d.ts +19 -0
  181. package/dist/lib/summaries.js +22 -0
  182. package/dist/lib/sync-problems.d.ts +21 -0
  183. package/dist/lib/sync-problems.js +19 -0
  184. package/dist/local-runtime.d.ts +78 -0
  185. package/dist/local-runtime.js +11 -0
  186. package/dist/local-target.d.ts +6 -0
  187. package/dist/local-target.js +23 -0
  188. package/dist/main.d.ts +2 -0
  189. package/dist/main.js +40 -0
  190. package/dist/project-preview.d.ts +35 -0
  191. package/dist/project-preview.js +156 -0
  192. package/dist/project-publish.d.ts +28 -0
  193. package/dist/project-publish.js +173 -0
  194. package/dist/remote/connection.d.ts +8 -0
  195. package/dist/remote/connection.js +19 -0
  196. package/dist/remote/core-failure.d.ts +8 -0
  197. package/dist/remote/core-failure.js +15 -0
  198. package/dist/remote/credentials.d.ts +15 -0
  199. package/dist/remote/credentials.js +112 -0
  200. package/dist/remote/device-login.d.ts +33 -0
  201. package/dist/remote/device-login.js +161 -0
  202. package/dist/remote/remote-caller.d.ts +14 -0
  203. package/dist/remote/remote-caller.js +52 -0
  204. package/dist/remote/rpc-wire.d.ts +18 -0
  205. package/dist/remote/rpc-wire.js +57 -0
  206. package/dist/remote/servers.d.ts +80 -0
  207. package/dist/remote/servers.js +162 -0
  208. package/dist/remote/session.d.ts +53 -0
  209. package/dist/remote/session.js +132 -0
  210. package/dist/remote/sign-in-here.d.ts +5 -0
  211. package/dist/remote/sign-in-here.js +33 -0
  212. package/dist/remote/sign-in.d.ts +25 -0
  213. package/dist/remote/sign-in.js +55 -0
  214. package/dist/remote/wait-slices.d.ts +16 -0
  215. package/dist/remote/wait-slices.js +21 -0
  216. package/dist/render/add.d.ts +3 -0
  217. package/dist/render/add.js +9 -0
  218. package/dist/render/branch-write.d.ts +9 -0
  219. package/dist/render/branch-write.js +28 -0
  220. package/dist/render/branches.d.ts +5 -0
  221. package/dist/render/branches.js +28 -0
  222. package/dist/render/credentials.d.ts +5 -0
  223. package/dist/render/credentials.js +39 -0
  224. package/dist/render/operation-result.d.ts +16 -0
  225. package/dist/render/operation-result.js +65 -0
  226. package/dist/render/operation.d.ts +7 -0
  227. package/dist/render/operation.js +15 -0
  228. package/dist/render/page-changes.d.ts +3 -0
  229. package/dist/render/page-changes.js +36 -0
  230. package/dist/render/pending.d.ts +3 -0
  231. package/dist/render/pending.js +46 -0
  232. package/dist/render/plugin-list.d.ts +3 -0
  233. package/dist/render/plugin-list.js +30 -0
  234. package/dist/render/probe.d.ts +3 -0
  235. package/dist/render/probe.js +61 -0
  236. package/dist/render/problems.d.ts +35 -0
  237. package/dist/render/problems.js +64 -0
  238. package/dist/render/recovery.d.ts +2 -0
  239. package/dist/render/recovery.js +36 -0
  240. package/dist/render/reset-storage.d.ts +4 -0
  241. package/dist/render/reset-storage.js +70 -0
  242. package/dist/render/site-status.d.ts +2 -0
  243. package/dist/render/site-status.js +81 -0
  244. package/dist/render/source-list.d.ts +2 -0
  245. package/dist/render/source-list.js +37 -0
  246. package/dist/render/sync.d.ts +5 -0
  247. package/dist/render/sync.js +66 -0
  248. package/dist/settings.d.ts +10 -0
  249. package/dist/settings.js +45 -0
  250. package/dist/site-entry-edit.d.ts +5 -0
  251. package/dist/site-entry-edit.js +44 -0
  252. package/dist/source-entry.d.ts +32 -0
  253. package/dist/source-entry.js +89 -0
  254. package/dist/version.d.ts +3 -0
  255. package/dist/version.js +10 -0
  256. package/package.json +112 -3
@@ -0,0 +1,162 @@
1
+ // Foliwake servers this computer is signed in to: one profile per server (by name: "cloud" for Foliwake
2
+ // Cloud, else the origin), without secrets (the token is in a credential store), and which server a command
3
+ // calls. The profiles file and the credential store are the engine CLI's own: a sign-in made with either
4
+ // CLI serves both.
5
+ import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
6
+ import path from 'node:path';
7
+ import { COMMAND, configDir, isLoopbackHost, setting } from '../settings.js';
8
+ import { readConnection } from './connection.js';
9
+ /**
10
+ * Foliwake Cloud: the reserved server name `cloud`. The Cloud is not available yet; its origin is
11
+ * CLOUD_ORIGIN (FOLIWAKE_CLOUD_ORIGIN overrides it, for tests or a move). A sign-in to it is kept under
12
+ * "cloud", never by its URL.
13
+ */
14
+ export const CLOUD = 'cloud';
15
+ export const CLOUD_ORIGIN = 'https://cloud.foliwake.org';
16
+ export const CLOUD_TITLE = 'Foliwake Cloud';
17
+ /** Said when someone names the cloud: it does not exist yet. */
18
+ export const CLOUD_NOTE = `${CLOUD_TITLE} is not available yet; sign in to your own Foliwake server instead, ` +
19
+ `e.g. \`${COMMAND} login https://foliwake.example\`.`;
20
+ /** True when the cloud's origin was set for this run (FOLIWAKE_CLOUD_ORIGIN): only then may `cloud` be used. */
21
+ export function cloudConfigured(env = process.env) {
22
+ return Boolean(setting('CLOUD_ORIGIN', env));
23
+ }
24
+ export class ServerAddressError extends Error {
25
+ }
26
+ /** The cloud's origin: FOLIWAKE_CLOUD_ORIGIN, else CLOUD_ORIGIN. */
27
+ export function cloudOrigin(env = process.env) {
28
+ const own = setting('CLOUD_ORIGIN', env);
29
+ return own ? plainOrigin(own) : CLOUD_ORIGIN;
30
+ }
31
+ /** A server's origin from what a person typed: "cloud", an origin, or a host meaning https. */
32
+ export function serverOrigin(typed, env = process.env) {
33
+ return typed.trim().toLowerCase() === CLOUD ? cloudOrigin(env) : plainOrigin(typed);
34
+ }
35
+ /** The name this computer remembers a server by: "cloud" for the cloud's origin, else the origin. */
36
+ export function serverName(origin, env = process.env) {
37
+ return origin === cloudOrigin(env) ? CLOUD : origin;
38
+ }
39
+ /** The origin of a remembered name ("cloud" or an origin); null for a name that is neither. */
40
+ export function nameOrigin(name, env = process.env) {
41
+ try {
42
+ return serverOrigin(name, env);
43
+ }
44
+ catch {
45
+ return null;
46
+ }
47
+ }
48
+ /** How a server is printed: "cloud (https://foliwake.dev)" for the cloud, else its origin. */
49
+ export function serverDisplay(origin, env = process.env) {
50
+ return serverName(origin, env) === CLOUD ? `${CLOUD} (${origin})` : origin;
51
+ }
52
+ function parsedUrl(typed) {
53
+ const text = typed.trim();
54
+ try {
55
+ return new URL(/^[a-z][a-z0-9+.-]*:\/\//i.test(text) ? text : `https://${text}`);
56
+ }
57
+ catch {
58
+ const example = 'give an origin such as https://foliwake.example or a host name.';
59
+ throw new ServerAddressError(`"${typed}" is not a server address; ${example}`);
60
+ }
61
+ }
62
+ /** Plain http only for loopback; an origin only: no path, query or credentials. */
63
+ function plainOrigin(typed) {
64
+ const url = parsedUrl(typed);
65
+ if (url.protocol !== 'https:' && url.protocol !== 'http:') {
66
+ throw new ServerAddressError(`A server address uses https; got ${url.protocol}.`);
67
+ }
68
+ if (url.protocol === 'http:' && !isLoopbackHost(url.host)) {
69
+ throw new ServerAddressError('Plain http is allowed only for a loopback server (127.0.0.1, localhost); use https.');
70
+ }
71
+ const hasPath = url.pathname !== '/' && url.pathname !== '';
72
+ if (url.username || url.password || hasPath || url.search || url.hash) {
73
+ throw new ServerAddressError('A server address is an origin only: no path, query or credentials.');
74
+ }
75
+ return url.origin;
76
+ }
77
+ const profilesFile = (env) => path.join(configDir(env), 'servers.json');
78
+ const strings = (value) => Array.isArray(value) ? value.filter((item) => typeof item === 'string') : [];
79
+ export function readProfiles(env) {
80
+ let raw;
81
+ try {
82
+ raw = readFileSync(profilesFile(env), 'utf8');
83
+ }
84
+ catch (error) {
85
+ if (error.code === 'ENOENT')
86
+ return { default: null, servers: {}, signedOut: [] };
87
+ throw error;
88
+ }
89
+ const parsed = JSON.parse(raw);
90
+ return {
91
+ default: typeof parsed.default === 'string' ? parsed.default : null,
92
+ servers: parsed.servers && typeof parsed.servers === 'object' ? parsed.servers : {},
93
+ signedOut: strings(parsed.signedOut),
94
+ };
95
+ }
96
+ export function writeProfiles(profiles, env) {
97
+ const file = profilesFile(env);
98
+ mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
99
+ const temp = `${file}.${process.pid}.tmp`;
100
+ writeFileSync(temp, `${JSON.stringify(profiles, null, 2)}\n`, { mode: 0o600 });
101
+ renameSync(temp, file);
102
+ }
103
+ /** The origin that issued a profile's token: recorded, else its key when that is an origin. */
104
+ export function issuerOf(key, profile) {
105
+ if (typeof profile.origin === 'string')
106
+ return profile.origin;
107
+ return key === CLOUD ? null : key;
108
+ }
109
+ /** The sign-in remembered for a server (by its origin), whether or not it may be used there. */
110
+ export function signInEntry(origin, env = process.env, profiles = readProfiles(env)) {
111
+ const name = serverName(origin, env);
112
+ const keptByOrigin = name === CLOUD && profiles.servers[origin];
113
+ const key = profiles.servers[name] ? name : keptByOrigin ? origin : null;
114
+ return key === null ? null : { key, profile: profiles.servers[key], issuer: issuerOf(key, profiles.servers[key]) };
115
+ }
116
+ /** The profile of a server (by its origin) when its token was issued there, or null. */
117
+ export function profileOf(origin, env = process.env) {
118
+ const entry = signInEntry(origin, env);
119
+ return entry && entry.issuer === origin ? entry.profile : null;
120
+ }
121
+ /** Why the sign-in kept for this origin may not be used there (issued by another origin); null otherwise. */
122
+ export function signInMoved(origin, env = process.env) {
123
+ const entry = signInEntry(origin, env);
124
+ if (!entry || entry.issuer === origin)
125
+ return null;
126
+ const now = setting('CLOUD_ORIGIN', env) ? ' (FOLIWAKE_CLOUD_ORIGIN)' : '';
127
+ const login = `${COMMAND} login ${entry.key === CLOUD ? CLOUD : origin}`;
128
+ return (`This computer's sign-in to ${entry.key} was made at ${entry.issuer ?? 'an unknown address'}, ` +
129
+ `but ${entry.key} now means ${origin}${now}; its token is not sent there. Sign in to ${origin}: \`${login}\`.`);
130
+ }
131
+ /** Makes a signed-in server the default; false when this computer is not signed in to it. */
132
+ export function useServer(origin, env = process.env) {
133
+ const profiles = readProfiles(env);
134
+ const entry = signInEntry(origin, env, profiles);
135
+ if (!entry || entry.issuer !== origin)
136
+ return false;
137
+ profiles.default = entry.key;
138
+ writeProfiles(profiles, env);
139
+ return true;
140
+ }
141
+ /** The origin of the default server (the last `login`), or null. */
142
+ export function defaultOrigin(env = process.env) {
143
+ const name = readProfiles(env).default;
144
+ return name ? nameOrigin(name, env) : null;
145
+ }
146
+ /**
147
+ * `--server`, then the folder's `.foliwake/connection.json`, then `FOLIWAKE_SERVER`, then the last `login`.
148
+ * Null: nothing names a server. Unlike the engine's CLI, nothing here is local: FOLIWAKE_CONFIG and
149
+ * foliwake.config.json are not read.
150
+ */
151
+ export function resolveTarget({ server }, env = process.env, cwd = process.cwd()) {
152
+ if (server !== undefined)
153
+ return { origin: serverOrigin(server, env), from: 'flag' };
154
+ const connection = readConnection(cwd);
155
+ if (connection)
156
+ return { origin: serverOrigin(connection.server, env), from: 'connection' };
157
+ const fromEnv = setting('SERVER', env);
158
+ if (fromEnv)
159
+ return { origin: serverOrigin(fromEnv, env), from: 'environment' };
160
+ const fallback = defaultOrigin(env);
161
+ return fallback ? { origin: fallback, from: 'login' } : null;
162
+ }
@@ -0,0 +1,53 @@
1
+ import type { CoreCaller } from '@foliwake/core-contract';
2
+ import { type CredentialStore } from './credentials.js';
3
+ import { type Grant } from './servers.js';
4
+ /** A sign-in kept for a server name now resolving to another origin: its token is not sent. */
5
+ export declare class SignInMovedError extends Error {
6
+ }
7
+ /**
8
+ * `FOLIWAKE_TOKEN` belongs to `FOLIWAKE_SERVER` only: it is never sent to another server, so a CI key
9
+ * cannot leak to whatever `--server` names. Without that pair: the stored sign-in, or none.
10
+ */
11
+ export declare function tokenFor(origin: string, env?: NodeJS.ProcessEnv): string | null;
12
+ /** The caller of a server with this computer's token for it; SignInMovedError rather than call without it. */
13
+ export declare function remoteCallerFor(origin: string, env?: NodeJS.ProcessEnv): CoreCaller;
14
+ /** A remembered sign-in for a server, whether or not its token may be sent to `origin`: for logout. */
15
+ export declare function storedSignIn(origin: string, env?: NodeJS.ProcessEnv): {
16
+ key: string;
17
+ issuer: string | null;
18
+ token: string | null;
19
+ } | null;
20
+ type Rehomed = {
21
+ kept: string;
22
+ } | {
23
+ orphan: {
24
+ issuer: string | null;
25
+ token: string | null;
26
+ };
27
+ };
28
+ /**
29
+ * Before a new sign-in to `origin`: a sign-in kept by the same name but issued elsewhere ("cloud" moved from
30
+ * A to B) is kept as a sign-in to A (`kept`). When that cannot be, it is handed back as `orphan` for the caller
31
+ * to revoke at A before the new sign-in replaces it. Null: nothing to do.
32
+ */
33
+ export declare function rehomeMovedSignIn(origin: string, env?: NodeJS.ProcessEnv): Rehomed | null;
34
+ export interface NewSignIn {
35
+ origin: string;
36
+ token: string;
37
+ grant: Grant;
38
+ store: CredentialStore;
39
+ email?: string | null;
40
+ /** Make this server the default even when another one is: `login --default`. */
41
+ makeDefault?: boolean;
42
+ }
43
+ /**
44
+ * Keeps a new sign-in; its server becomes the default only when asked (`makeDefault`) or when there is no
45
+ * other default. Returns the token it replaced, which the caller revokes. The new token is read back first:
46
+ * if the store did not keep it, the earlier sign-in stays.
47
+ */
48
+ export declare function saveSignIn({ origin, token, grant, store, email, makeDefault }: NewSignIn, env?: NodeJS.ProcessEnv): string | null;
49
+ /** The stored token for a server, or null: only for the origin that issued it. */
50
+ export declare function storedToken(origin: string, env?: NodeJS.ProcessEnv): string | null;
51
+ /** Forgets a sign-in on this computer (a moved one too); false when there is none. */
52
+ export declare function forgetSignIn(origin: string, env?: NodeJS.ProcessEnv): boolean;
53
+ export {};
@@ -0,0 +1,132 @@
1
+ import { setting } from '../settings.js';
2
+ import { credentialStore } from './credentials.js';
3
+ import { createRemoteCaller } from './remote-caller.js';
4
+ import { readProfiles, serverName, serverOrigin, signInEntry, signInMoved, writeProfiles, } from './servers.js';
5
+ /** A sign-in kept for a server name now resolving to another origin: its token is not sent. */
6
+ export class SignInMovedError extends Error {
7
+ }
8
+ function originOrNull(typed, env) {
9
+ try {
10
+ return serverOrigin(typed, env);
11
+ }
12
+ catch {
13
+ return null;
14
+ }
15
+ }
16
+ /**
17
+ * `FOLIWAKE_TOKEN` belongs to `FOLIWAKE_SERVER` only: it is never sent to another server, so a CI key
18
+ * cannot leak to whatever `--server` names. Without that pair: the stored sign-in, or none.
19
+ */
20
+ export function tokenFor(origin, env = process.env) {
21
+ const fromEnv = setting('TOKEN', env);
22
+ const envServer = setting('SERVER', env);
23
+ if (fromEnv && envServer && originOrNull(envServer, env) === origin)
24
+ return fromEnv;
25
+ return storedToken(origin, env);
26
+ }
27
+ /** The caller of a server with this computer's token for it; SignInMovedError rather than call without it. */
28
+ export function remoteCallerFor(origin, env = process.env) {
29
+ const token = tokenFor(origin, env);
30
+ if (token === null) {
31
+ const moved = signInMoved(origin, env);
32
+ if (moved)
33
+ throw new SignInMovedError(moved);
34
+ }
35
+ return createRemoteCaller({ origin, token });
36
+ }
37
+ /** A remembered sign-in for a server, whether or not its token may be sent to `origin`: for logout. */
38
+ export function storedSignIn(origin, env = process.env) {
39
+ const entry = signInEntry(origin, env);
40
+ if (!entry)
41
+ return null;
42
+ return { key: entry.key, issuer: entry.issuer, token: credentialStore(entry.profile.store, env).get(entry.key) };
43
+ }
44
+ /**
45
+ * Before a new sign-in to `origin`: a sign-in kept by the same name but issued elsewhere ("cloud" moved from
46
+ * A to B) is kept as a sign-in to A (`kept`). When that cannot be, it is handed back as `orphan` for the caller
47
+ * to revoke at A before the new sign-in replaces it. Null: nothing to do.
48
+ */
49
+ export function rehomeMovedSignIn(origin, env = process.env) {
50
+ const profiles = readProfiles(env);
51
+ const entry = signInEntry(origin, env, profiles);
52
+ if (!entry || entry.issuer === origin)
53
+ return null;
54
+ const store = credentialStore(entry.profile.store, env);
55
+ const token = store.get(entry.key);
56
+ const issuer = entry.issuer;
57
+ if (issuer === null || profiles.servers[issuer] || token === null)
58
+ return { orphan: { issuer, token } };
59
+ store.set(issuer, token);
60
+ if (store.get(issuer) !== token)
61
+ return { orphan: { issuer, token } };
62
+ store.delete(entry.key);
63
+ profiles.servers[issuer] = { ...entry.profile, origin: issuer };
64
+ delete profiles.servers[entry.key];
65
+ if (profiles.default === entry.key)
66
+ profiles.default = issuer;
67
+ writeProfiles(profiles, env);
68
+ return { kept: issuer };
69
+ }
70
+ function keepToken(store, name, token, previous) {
71
+ store.set(name, token);
72
+ if (store.get(name) === token)
73
+ return;
74
+ if (previous)
75
+ store.set(name, previous);
76
+ throw new Error(`The ${store.kind} did not keep the token.`);
77
+ }
78
+ /** The default after a sign-in to `name`: it, when asked or when the default is none or gone; else unchanged. */
79
+ function defaultAfter(profiles, name, makeDefault) {
80
+ const current = profiles.default;
81
+ const usable = current !== null && current !== name && Boolean(profiles.servers[current]);
82
+ return makeDefault || !usable ? name : current;
83
+ }
84
+ /**
85
+ * Keeps a new sign-in; its server becomes the default only when asked (`makeDefault`) or when there is no
86
+ * other default. Returns the token it replaced, which the caller revokes. The new token is read back first:
87
+ * if the store did not keep it, the earlier sign-in stays.
88
+ */
89
+ export function saveSignIn({ origin, token, grant, store, email = null, makeDefault = false }, env = process.env) {
90
+ const name = serverName(origin, env);
91
+ const profiles = readProfiles(env);
92
+ const entry = signInEntry(origin, env, profiles);
93
+ // The earlier token is revoked by the caller at `origin`: only when it was issued there.
94
+ const previous = entry && entry.issuer === origin ? entry : null;
95
+ const superseded = previous ? credentialStore(previous.profile.store, env).get(previous.key) : null;
96
+ const sameSlot = entry !== null && entry.key === name && entry.profile.store === store.kind;
97
+ keepToken(store, name, token, sameSlot && previous ? superseded : null);
98
+ // Replaced: the earlier credential of this name, and a cloud sign-in still kept by its origin.
99
+ if (entry && !sameSlot)
100
+ credentialStore(entry.profile.store, env).delete(entry.key);
101
+ if (entry && entry.key !== name)
102
+ delete profiles.servers[entry.key];
103
+ const { principal, memberships, installation } = grant;
104
+ const signedInAt = new Date().toISOString();
105
+ const profile = { principal, memberships, installation, signedInAt, store: store.kind, origin };
106
+ profiles.servers[name] = { ...profile, ...(email ? { email } : {}) };
107
+ profiles.default = defaultAfter(profiles, name, makeDefault);
108
+ profiles.signedOut = profiles.signedOut.filter((known) => known !== name);
109
+ writeProfiles(profiles, env);
110
+ return superseded && superseded !== token ? superseded : null;
111
+ }
112
+ /** The stored token for a server, or null: only for the origin that issued it. */
113
+ export function storedToken(origin, env = process.env) {
114
+ const entry = signInEntry(origin, env);
115
+ return entry && entry.issuer === origin ? credentialStore(entry.profile.store, env).get(entry.key) : null;
116
+ }
117
+ /** Forgets a sign-in on this computer (a moved one too); false when there is none. */
118
+ export function forgetSignIn(origin, env = process.env) {
119
+ const name = serverName(origin, env);
120
+ const profiles = readProfiles(env);
121
+ const entry = signInEntry(origin, env, profiles);
122
+ if (!entry)
123
+ return false;
124
+ credentialStore(entry.profile.store, env).delete(entry.key);
125
+ delete profiles.servers[entry.key];
126
+ if (!profiles.signedOut.includes(name))
127
+ profiles.signedOut.push(name);
128
+ if (profiles.default === entry.key)
129
+ profiles.default = Object.keys(profiles.servers)[0] ?? null;
130
+ writeProfiles(profiles, env);
131
+ return true;
132
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * `foliwake login <origin>` inline, for `create` and `connect`: Ctrl+C stops only the wait, a failure is printed;
3
+ * false in both cases.
4
+ */
5
+ export declare function signInHere(origin: string): Promise<boolean>;
@@ -0,0 +1,33 @@
1
+ // A sign-in in the middle of another command (`create`, `connect`).
2
+ /**
3
+ * `foliwake login <origin>` inline, for `create` and `connect`: Ctrl+C stops only the wait, a failure is printed;
4
+ * false in both cases.
5
+ */
6
+ export async function signInHere(origin) {
7
+ const { deviceSignIn } = await import('./sign-in.js');
8
+ const controller = new AbortController();
9
+ const onInterrupt = () => controller.abort();
10
+ process.on('SIGINT', onInterrupt);
11
+ try {
12
+ const signed = await deviceSignIn(origin, {
13
+ browser: true,
14
+ tty: process.stdout.isTTY === true,
15
+ insecureStorage: false,
16
+ log: (text) => void process.stderr.write(text),
17
+ signal: controller.signal,
18
+ });
19
+ const { serverDisplay } = await import('./servers.js');
20
+ process.stdout.write(`Signed in to ${serverDisplay(origin)} as ${signed.email ?? signed.grant.principal}.\n`);
21
+ return true;
22
+ }
23
+ catch (error) {
24
+ const { SignInCancelled } = await import('./device-login.js');
25
+ const cancelled = error instanceof SignInCancelled;
26
+ const why = cancelled ? 'was cancelled' : `failed: ${error.message}`;
27
+ process.stderr.write(`The sign-in to ${origin} ${why}.\n`);
28
+ return false;
29
+ }
30
+ finally {
31
+ process.off('SIGINT', onInterrupt);
32
+ }
33
+ }
@@ -0,0 +1,25 @@
1
+ import { type CredentialStore } from './credentials.js';
2
+ import { type Grant } from './servers.js';
3
+ export interface SignInOptions {
4
+ /** Open the approval page in the browser (only when `tty`). */
5
+ browser: boolean;
6
+ tty: boolean;
7
+ insecureStorage: boolean;
8
+ /** Where the code, the address and warnings go. */
9
+ log: (text: string) => void;
10
+ /** Make the server the default even when another one is (`login --default`). */
11
+ makeDefault?: boolean;
12
+ /** Aborting stops the wait (SignInCancelled). */
13
+ signal?: AbortSignal;
14
+ env?: NodeJS.ProcessEnv;
15
+ }
16
+ export interface SignedIn {
17
+ origin: string;
18
+ grant: Grant;
19
+ email: string | null;
20
+ store: CredentialStore['kind'];
21
+ }
22
+ /** Signs this computer in to `origin`; throws SignInError (SignInCancelled too) or CredentialStoreError. */
23
+ export declare function deviceSignIn(origin: string, options: SignInOptions): Promise<SignedIn>;
24
+ /** The cloud is not available yet: say so instead of only "cannot be reached". */
25
+ export declare function cloudHint(error: unknown, origin: string, env?: NodeJS.ProcessEnv): unknown;
@@ -0,0 +1,55 @@
1
+ // The device-code sign-in of `foliwake login`, shared with `site create|link` when they need one: the code
2
+ // and the approval page on stderr, the browser opened in a terminal, the token kept in the credential store
3
+ // and the server made the default. It never prints the token.
4
+ import { COMMAND, openBrowser } from '../settings.js';
5
+ import { storeForSignIn } from './credentials.js';
6
+ import { SignInError, abortableSleep, revokeToken, startDeviceSignIn, waitForSignIn } from './device-login.js';
7
+ import { createRemoteCaller } from './remote-caller.js';
8
+ import { CLOUD_NOTE, cloudOrigin } from './servers.js';
9
+ import { rehomeMovedSignIn, saveSignIn } from './session.js';
10
+ /** A sign-in by the same name issued elsewhere (the cloud moved) is kept there, or revoked there. */
11
+ async function settleMovedSignIn(origin, log, env) {
12
+ const moved = rehomeMovedSignIn(origin, env);
13
+ if (moved && 'kept' in moved) {
14
+ const logout = `\`${COMMAND} logout ${moved.kept}\``;
15
+ log(`Your earlier sign-in, made at ${moved.kept}, is kept as a sign-in to ${moved.kept}; ${logout} revokes it.\n`);
16
+ }
17
+ if (!moved || !('orphan' in moved))
18
+ return;
19
+ const { issuer, token } = moved.orphan;
20
+ const revoked = issuer !== null && token !== null && (await revokeToken(issuer, token));
21
+ const where = issuer ? `, made at ${issuer},` : '';
22
+ log(revoked
23
+ ? `Your earlier sign-in, made at ${issuer}, was revoked there and replaced.\n`
24
+ : `Warning: your earlier sign-in${where} could not be revoked and is replaced here; ` +
25
+ 'it stays valid there until 90 days after its last use.\n');
26
+ }
27
+ /** Signs this computer in to `origin`; throws SignInError (SignInCancelled too) or CredentialStoreError. */
28
+ export async function deviceSignIn(origin, options) {
29
+ const { browser, tty, insecureStorage, log, signal, makeDefault = false, env = process.env } = options;
30
+ const store = storeForSignIn({ insecureStorage }, env);
31
+ const start = await startDeviceSignIn(origin).catch((error) => {
32
+ throw cloudHint(error, origin, env);
33
+ });
34
+ log(`Your one-time code: ${start.userCode}\nApprove it at ${start.verificationUriComplete}\n`);
35
+ if (browser && tty)
36
+ openBrowser(start.verificationUriComplete);
37
+ log('Waiting for approval…\n');
38
+ const { token, email } = await waitForSignIn(origin, start, signal ? { sleep: abortableSleep(signal) } : {});
39
+ const grant = await createRemoteCaller({ origin, token }).whoami();
40
+ await settleMovedSignIn(origin, log, env);
41
+ const superseded = saveSignIn({ origin, token, grant, store, email, makeDefault }, env);
42
+ // The earlier sign-in of this computer would stay valid on the server until it expired.
43
+ if (superseded && !(await revokeToken(origin, superseded))) {
44
+ log(`Warning: ${origin} could not revoke this computer's earlier token; it expires 90 days after its last use.\n`);
45
+ }
46
+ return { origin, grant, email, store: store.kind };
47
+ }
48
+ /** The cloud is not available yet: say so instead of only "cannot be reached". */
49
+ export function cloudHint(error, origin, env = process.env) {
50
+ if (!(error instanceof SignInError) || origin !== cloudOrigin(env))
51
+ return error;
52
+ if (error.code !== 'SERVER_UNREACHABLE' && error.code !== 'SERVER_FAILED')
53
+ return error;
54
+ return new SignInError(error.code, `${error.message} ${CLOUD_NOTE}`);
55
+ }
@@ -0,0 +1,16 @@
1
+ import type { CoreOutput } from '@foliwake/core-contract';
2
+ export type Operation = CoreOutput<'operations.get'>;
3
+ /** One wait request to a server: well under its request timeout. */
4
+ export declare const REMOTE_WAIT_SLICE_MS = 25000;
5
+ /**
6
+ * Far enough, as the server decides it: past the commit (or finished, for kinds without one), and for
7
+ * `delivery` also past the cache refresh: done, or pending with a reason (nobody waits for it any more).
8
+ */
9
+ export declare function waitReached(operation: Operation, until: 'commit' | 'delivery'): boolean;
10
+ export interface SliceOptions {
11
+ until: 'commit' | 'delivery';
12
+ timeoutMs: number;
13
+ sliceMs?: number;
14
+ now?: () => number;
15
+ }
16
+ export declare function waitInSlices(wait: (sliceMs: number) => Promise<Operation>, { until, timeoutMs, sliceMs, now }: SliceOptions): Promise<Operation>;
@@ -0,0 +1,21 @@
1
+ /** One wait request to a server: well under its request timeout. */
2
+ export const REMOTE_WAIT_SLICE_MS = 25_000;
3
+ /**
4
+ * Far enough, as the server decides it: past the commit (or finished, for kinds without one), and for
5
+ * `delivery` also past the cache refresh: done, or pending with a reason (nobody waits for it any more).
6
+ */
7
+ export function waitReached(operation, until) {
8
+ if (operation.state === 'queued' || operation.state === 'running')
9
+ return false;
10
+ const delivery = operation.delivery;
11
+ return until === 'commit' || delivery?.state !== 'pending' || delivery.reason !== undefined;
12
+ }
13
+ export async function waitInSlices(wait, { until, timeoutMs, sliceMs = REMOTE_WAIT_SLICE_MS, now = Date.now }) {
14
+ const deadline = now() + timeoutMs;
15
+ for (;;) {
16
+ const remaining = Math.max(0, deadline - now());
17
+ const operation = await wait(Math.min(remaining, sliceMs));
18
+ if (waitReached(operation, until) || remaining <= sliceMs)
19
+ return operation;
20
+ }
21
+ }
@@ -0,0 +1,3 @@
1
+ import type { AddAnswer } from '../core-types.js';
2
+ /** The lines `foliwake source add` prints after the save. */
3
+ export declare function addLines(answer: AddAnswer): string[];
@@ -0,0 +1,9 @@
1
+ /** The lines `foliwake source add` prints after the save. */
2
+ export function addLines(answer) {
3
+ const { source } = answer;
4
+ const rules = source.mappings ? `, ${source.mappings} path rule(s)` : '';
5
+ const head = answer.unchanged
6
+ ? `Source ${source.id} is already in site ${answer.site} exactly like this; nothing was written.`
7
+ : `Saved source ${source.id} (${source.plugin}, owns ${source.owns.join(' ')}${rules}). Nothing was fetched yet.`;
8
+ return [head, ...answer.nextSteps.map((step) => `Next: ${step}`)];
9
+ }
@@ -0,0 +1,9 @@
1
+ import type { Operation } from '../core-types.js';
2
+ import type { BranchResultCore } from '../core-types.js';
3
+ /** The lines of a branch write, and its exit status: 0 when it did what was asked (a no-op included), else 1. */
4
+ export declare function branchWriteReport(operation: Operation, done: (result: BranchResultCore) => string[]): {
5
+ lines: string[];
6
+ exitCode: number;
7
+ };
8
+ /** Where a branch is shown: its site branch host first, then its readable host, then its label host. */
9
+ export declare const branchUrls: (result: BranchResultCore) => string;
@@ -0,0 +1,28 @@
1
+ import { COMMAND } from '../settings.js';
2
+ import { describeBranchUrls } from '../lib/rules.js';
3
+ const C = COMMAND;
4
+ /** The lines of a branch write, and its exit status: 0 when it did what was asked (a no-op included), else 1. */
5
+ export function branchWriteReport(operation, done) {
6
+ // The result was checked against its kind's schema when it was stored.
7
+ const result = (operation.result ?? null);
8
+ const lines = [];
9
+ if (result?.prepared && result.prepared.codeRelease)
10
+ lines.push(`Prepared ${result.prepared.codeRelease} from ${result.prepared.sourceRevision ?? 'an unknown commit'}.`);
11
+ if (operation.state === 'succeeded' && result) {
12
+ lines.push(...(result.state === 'noop' ? [`Nothing to do: ${result.message ?? 'already so.'}`] : done(result)));
13
+ if (result.hostNote)
14
+ lines.push(`Note: ${result.hostNote}`);
15
+ return { lines, exitCode: 0 };
16
+ }
17
+ const error = operation.error;
18
+ if (operation.state === 'unknown')
19
+ lines.push(`${operation.kind}: whether it committed is not known yet (${error?.code ?? 'COMMIT_UNKNOWN'}); \`${C} ` +
20
+ `operation recover\` finds out and never runs it again.`);
21
+ else
22
+ lines.push(`${operation.kind} ${operation.state}${error ? ` (${error.code}): ${error.message}` : ''}`);
23
+ for (const item of result?.prepared?.diagnostics ?? [])
24
+ lines.push(` ${item.severity} ${item.code} ${item.file}:${item.line}:${item.column} ${item.message}`);
25
+ return { lines, exitCode: 1 };
26
+ }
27
+ /** Where a branch is shown: its site branch host first, then its readable host, then its label host. */
28
+ export const branchUrls = (result) => describeBranchUrls({ site: result.siteBranchUrl, readable: null, label: result.previewUrl ?? '' });
@@ -0,0 +1,5 @@
1
+ import type { BranchHistory, BranchList } from '../core-types.js';
2
+ /** The lines `foliwake branch list` prints. */
3
+ export declare function branchListLines(rows: BranchList): string[];
4
+ /** The lines `foliwake branch history` prints. */
5
+ export declare function branchHistoryLines(history: BranchHistory): string[];
@@ -0,0 +1,28 @@
1
+ import { COMMAND } from '../settings.js';
2
+ import { describeBranchUrls } from '../lib/rules.js';
3
+ const C = COMMAND;
4
+ /** The lines `foliwake branch list` prints. */
5
+ export function branchListLines(rows) {
6
+ if (!rows.length)
7
+ return [`No branch previews yet. Seed the default branch with \`${C} branch bootstrap\`.`];
8
+ return rows.map((row) => {
9
+ const where = row.previewUrl === null
10
+ ? `deleted ${row.retired?.at ?? ''}`
11
+ : describeBranchUrls({ site: row.siteBranchUrl, readable: row.readableUrl, label: row.previewUrl });
12
+ return (`${(row.branch + (row.isDefault ? ' (default)' : '')).padEnd(26)}${row.codeRelease} ` +
13
+ `${row.sourceRevision ?? '-'} ${where}`);
14
+ });
15
+ }
16
+ /** The lines `foliwake branch history` prints. */
17
+ export function branchHistoryLines(history) {
18
+ if (!history.exists)
19
+ return [`Branch ${history.branch} has no selections.`];
20
+ const head = history.retired
21
+ ? `Branch ${history.branch} was deleted ${history.retired.at}; no host serves it. Selections, newest first:`
22
+ : `Branch ${history.branch} (${history.previewUrl}), newest first:`;
23
+ return [
24
+ head,
25
+ ...history.selections.map((entry) => ` ${String(entry.generation).padEnd(4)}${entry.codeRelease} ${entry.sourceRevision ?? '-'} ` +
26
+ `${entry.createdAt}`),
27
+ ];
28
+ }
@@ -0,0 +1,5 @@
1
+ import type { CredentialList, CredentialRemoveResult, CredentialSetResult } from '../core-types.js';
2
+ /** The lines `foliwake credential list` prints. Values are never part of the answer. */
3
+ export declare function credentialListLines(list: CredentialList): string[];
4
+ export declare function credentialSetLines(result: CredentialSetResult): string[];
5
+ export declare function credentialRemoveLines(result: CredentialRemoveResult): string[];
@@ -0,0 +1,39 @@
1
+ function stateOf(entry) {
2
+ if (!entry.set)
3
+ return 'not set';
4
+ const when = entry.updatedAt ? ` · updated ${entry.updatedAt}` : '';
5
+ return `set (${entry.source})${when}`;
6
+ }
7
+ function usesOf(entry) {
8
+ if (entry.usedBy.length === 0)
9
+ return 'not used by a source';
10
+ return `used by ${entry.usedBy.map((use) => `${use.site}/${use.source}`).join(', ')}`;
11
+ }
12
+ /** The lines `foliwake credential list` prints. Values are never part of the answer. */
13
+ export function credentialListLines(list) {
14
+ if (list.credentials.length === 0)
15
+ return ['No credentials are stored or used by a content source.'];
16
+ const lines = [];
17
+ for (const entry of list.credentials) {
18
+ lines.push(`${entry.name}: ${stateOf(entry)} · ${usesOf(entry)}`);
19
+ if (entry.serviceAccount)
20
+ lines.push(` service account ${entry.serviceAccount.clientEmail}`);
21
+ }
22
+ if (!list.writable)
23
+ lines.push('', 'This server has no credentials folder: values come from its environment only.');
24
+ return lines;
25
+ }
26
+ export function credentialSetLines(result) {
27
+ const lines = [`Stored ${result.name} (${result.updatedAt}). The next sync or check uses it; no restart is needed.`];
28
+ if (result.serviceAccount)
29
+ lines.push(`Share the Drive folder with ${result.serviceAccount.clientEmail} (Viewer).`);
30
+ if (result.shadowedByEnv)
31
+ lines.push(`The server environment also sets ${result.name}; that value wins until it is removed there.`);
32
+ return lines;
33
+ }
34
+ export function credentialRemoveLines(result) {
35
+ const done = result.removed
36
+ ? `Removed the stored value of ${result.name}.`
37
+ : `No value of ${result.name} was stored.`;
38
+ return result.stillSetByEnv ? [done, `The server environment still sets ${result.name}.`] : [done];
39
+ }