pi-dent-office 0.1.1 → 0.2.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/README.md +14 -6
- package/lib/config.ts +150 -70
- package/lib/http.ts +15 -5
- package/lib/tool.ts +3 -1
- package/package.json +1 -1
- package/specs/office.md +61 -26
package/README.md
CHANGED
|
@@ -46,22 +46,30 @@ Then `/office login work` or `/office login personal` (or both), `/office status
|
|
|
46
46
|
default client is Microsoft's public "Microsoft Graph Command Line Tools" app. To use your own app
|
|
47
47
|
registration (a public client with the device code flow allowed), or a specific tenant, set them
|
|
48
48
|
in `pi-dent.conf` (`~/.pi/pi-dent/`, or `.pi/pi-dent/` in a project) or in
|
|
49
|
-
`
|
|
50
|
-
(the default kind):
|
|
49
|
+
`PI_DENT_OFFICE_WORK_CLIENT_ID`, `PI_DENT_OFFICE_WORK_TENANT`, `PI_DENT_OFFICE_PERSONAL_CLIENT_ID`
|
|
50
|
+
and `PI_DENT_OFFICE_ACCOUNT` (the default kind). Each kind can use its own app registration:
|
|
51
|
+
`office.work` and `office.personal` each take a `clientId` and `scopes` (`work` also a `tenant`),
|
|
52
|
+
and a kind left out uses the default client:
|
|
51
53
|
|
|
52
54
|
```jsonc
|
|
53
55
|
{
|
|
54
56
|
"office": {
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
"work": {
|
|
58
|
+
"clientId": "00000000-0000-0000-0000-000000000000",
|
|
59
|
+
"tenant": "contoso.onmicrosoft.com",
|
|
60
|
+
"scopes": ["User.Read", "Mail.ReadWrite", "Mail.Send", "ChannelMessage.Read.All"],
|
|
61
|
+
},
|
|
59
62
|
"defaultAccount": "work",
|
|
60
63
|
"confirmWrites": true,
|
|
61
64
|
},
|
|
62
65
|
}
|
|
63
66
|
```
|
|
64
67
|
|
|
68
|
+
The work tenant cannot be `consumers`: that tenant is for personal accounts only.
|
|
69
|
+
|
|
70
|
+
Accounts stored under the old shared client ID are no longer used once you set a per-kind
|
|
71
|
+
`clientId`: run `/office logout work` and `/office logout personal` before changing a client ID.
|
|
72
|
+
|
|
65
73
|
With `confirmWrites` `true`, every write asks you to confirm in the UI before signing in, and fails
|
|
66
74
|
without a UI; the default is `false`.
|
|
67
75
|
|
package/lib/config.ts
CHANGED
|
@@ -13,14 +13,6 @@ import { join } from "node:path";
|
|
|
13
13
|
import { parseTree, type Node, type ParseError } from "jsonc-parser";
|
|
14
14
|
|
|
15
15
|
const ROOT_KEY = "office";
|
|
16
|
-
const ROOT_KEYS: readonly string[] = [
|
|
17
|
-
"clientId",
|
|
18
|
-
"tenant",
|
|
19
|
-
"scopes",
|
|
20
|
-
"personalScopes",
|
|
21
|
-
"defaultAccount",
|
|
22
|
-
"confirmWrites",
|
|
23
|
-
];
|
|
24
16
|
|
|
25
17
|
export type Environment = Readonly<Record<string, string | undefined>>;
|
|
26
18
|
|
|
@@ -224,11 +216,7 @@ export function isUuid(value: string): boolean {
|
|
|
224
216
|
}
|
|
225
217
|
|
|
226
218
|
export function isTenant(value: string): boolean {
|
|
227
|
-
return (
|
|
228
|
-
["common", "organizations", "consumers"].includes(value) ||
|
|
229
|
-
UUID.test(value) ||
|
|
230
|
-
DOMAIN.test(value)
|
|
231
|
-
);
|
|
219
|
+
return ["common", "organizations"].includes(value) || UUID.test(value) || DOMAIN.test(value);
|
|
232
220
|
}
|
|
233
221
|
|
|
234
222
|
function withAlways(scopes: readonly string[]): string[] {
|
|
@@ -241,7 +229,86 @@ function scopeList(value: unknown): string[] | undefined {
|
|
|
241
229
|
return items.length > 0 && valid.length === items.length ? withAlways(valid) : undefined;
|
|
242
230
|
}
|
|
243
231
|
|
|
244
|
-
const TENANT_FORMS = "common, organizations,
|
|
232
|
+
const TENANT_FORMS = "common, organizations, a UUID or a domain";
|
|
233
|
+
const SCOPE_FORM = "a non-empty array of scope names";
|
|
234
|
+
const ROOT_KEYS: readonly string[] = ["work", "personal", "defaultAccount", "confirmWrites"];
|
|
235
|
+
const WORK_KEYS: readonly string[] = ["clientId", "tenant", "scopes"];
|
|
236
|
+
const PERSONAL_KEYS: readonly string[] = ["clientId", "scopes"];
|
|
237
|
+
/** Keys of the earlier flat layout and what replaces them. */
|
|
238
|
+
const LEGACY_KEYS: readonly (readonly [string, string])[] = [
|
|
239
|
+
["clientId", "office.work.clientId and office.personal.clientId"],
|
|
240
|
+
["tenant", "office.work.tenant"],
|
|
241
|
+
["scopes", "office.work.scopes"],
|
|
242
|
+
["personalScopes", "office.personal.scopes"],
|
|
243
|
+
];
|
|
244
|
+
const LEGACY_ENV: readonly (readonly [string, string])[] = [
|
|
245
|
+
[
|
|
246
|
+
"PI_DENT_OFFICE_CLIENT_ID",
|
|
247
|
+
"PI_DENT_OFFICE_WORK_CLIENT_ID and PI_DENT_OFFICE_PERSONAL_CLIENT_ID",
|
|
248
|
+
],
|
|
249
|
+
["PI_DENT_OFFICE_TENANT", "PI_DENT_OFFICE_WORK_TENANT"],
|
|
250
|
+
];
|
|
251
|
+
|
|
252
|
+
interface Finding {
|
|
253
|
+
readonly owner: string;
|
|
254
|
+
readonly order: number;
|
|
255
|
+
readonly text: string;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
interface EnvironmentValues {
|
|
259
|
+
readonly diagnostics: string[];
|
|
260
|
+
readonly workClient: string | undefined;
|
|
261
|
+
readonly workTenant: string | undefined;
|
|
262
|
+
readonly personalClient: string | undefined;
|
|
263
|
+
readonly envAccount: AccountKind | undefined;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** The environment fallbacks and their diagnostics, in the order of the spec. */
|
|
267
|
+
function readEnvironment(env: Environment): EnvironmentValues {
|
|
268
|
+
const diagnostics: string[] = [];
|
|
269
|
+
const read = (name: string, valid: (value: string) => boolean, message: string) => {
|
|
270
|
+
const value = nonEmpty(env[name]);
|
|
271
|
+
if (value !== undefined && !valid(value)) {
|
|
272
|
+
diagnostics.push(`pi-dent-office: ${name} must be ${message}`);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
return value;
|
|
276
|
+
};
|
|
277
|
+
const workClient = read("PI_DENT_OFFICE_WORK_CLIENT_ID", isUuid, "a UUID");
|
|
278
|
+
const workTenant = read("PI_DENT_OFFICE_WORK_TENANT", isTenant, TENANT_FORMS);
|
|
279
|
+
const personalClient = read("PI_DENT_OFFICE_PERSONAL_CLIENT_ID", isUuid, "a UUID");
|
|
280
|
+
const account = read("PI_DENT_OFFICE_ACCOUNT", isAccountKind, "work or personal");
|
|
281
|
+
for (const [name, replacement] of LEGACY_ENV) {
|
|
282
|
+
if (nonEmpty(env[name]) !== undefined) {
|
|
283
|
+
diagnostics.push(`pi-dent-office: ${name} is no longer read; use ${replacement}`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
diagnostics,
|
|
288
|
+
workClient,
|
|
289
|
+
workTenant,
|
|
290
|
+
personalClient,
|
|
291
|
+
envAccount: isAccountKind(account) ? account : undefined,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function clientOf(value: unknown): string | undefined {
|
|
296
|
+
const text = nonEmpty(value);
|
|
297
|
+
return text !== undefined && isUuid(text) ? text : undefined;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function tenantOf(value: unknown): string | undefined {
|
|
301
|
+
const text = nonEmpty(value);
|
|
302
|
+
return text !== undefined && isTenant(text) ? text : undefined;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** The findings' texts, global layer first, each layer's in the order found. */
|
|
306
|
+
function sortedTexts(findings: readonly Finding[], layers: readonly ConfigLayer[]): string[] {
|
|
307
|
+
const rank = (path: string): number => layers.findIndex((layer) => layer.path === path);
|
|
308
|
+
return findings
|
|
309
|
+
.toSorted((a, b) => rank(a.owner) - rank(b.owner) || a.order - b.order)
|
|
310
|
+
.map((finding) => finding.text);
|
|
311
|
+
}
|
|
245
312
|
|
|
246
313
|
/** The configuration from the parsed layers and the environment (specs/office.md#configuration). */
|
|
247
314
|
export function resolveConfig(
|
|
@@ -254,82 +321,95 @@ export function resolveConfig(
|
|
|
254
321
|
const ownerOf = (...path: string[]): string =>
|
|
255
322
|
[...ordered].toReversed().find((layer) => declares(layer.root, [ROOT_KEY, ...path]))?.path ??
|
|
256
323
|
"";
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
const value = nonEmpty(env[name]);
|
|
270
|
-
if (value !== undefined && !valid(value))
|
|
271
|
-
diagnostics.push(`pi-dent-office: ${name} must be ${message}`);
|
|
272
|
-
return value !== undefined && valid(value) ? value : undefined;
|
|
324
|
+
const {
|
|
325
|
+
diagnostics: envDiagnostics,
|
|
326
|
+
workClient,
|
|
327
|
+
workTenant,
|
|
328
|
+
personalClient,
|
|
329
|
+
envAccount,
|
|
330
|
+
} = readEnvironment(env);
|
|
331
|
+
const findings: Finding[] = [];
|
|
332
|
+
let order = 0;
|
|
333
|
+
const found = (owner: string, text: string): void => {
|
|
334
|
+
findings.push({ owner, order, text: `pi-dent-office: ${owner}: ${text}` });
|
|
335
|
+
order += 1;
|
|
273
336
|
};
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const envAccount = fromEnv("PI_DENT_OFFICE_ACCOUNT", isAccountKind, "work or personal");
|
|
277
|
-
if (isAccountKind(envAccount)) defaultAccount = envAccount;
|
|
337
|
+
let defaultAccount: AccountKind | undefined = envAccount;
|
|
338
|
+
let confirmWrites = false;
|
|
278
339
|
|
|
279
340
|
let merged: unknown;
|
|
280
341
|
for (const layer of ordered) {
|
|
281
342
|
if (declares(layer.root, [ROOT_KEY])) merged = mergeValues(merged, layer.root[ROOT_KEY]);
|
|
282
343
|
}
|
|
283
344
|
const settings = isRecord(merged) ? merged : {};
|
|
284
|
-
if (merged !== undefined && !isRecord(merged))
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
345
|
+
if (merged !== undefined && !isRecord(merged)) found(ownerOf(), "office must be an object");
|
|
346
|
+
|
|
347
|
+
const kindSettings = (kind: AccountKind): Record<string, unknown> => {
|
|
348
|
+
if (!Object.hasOwn(settings, kind)) return {};
|
|
349
|
+
const value = settings[kind];
|
|
350
|
+
if (isRecord(value)) return value;
|
|
351
|
+
found(ownerOf(kind), `office.${kind} must be an object`);
|
|
352
|
+
return {};
|
|
353
|
+
};
|
|
354
|
+
const kindObject = (kind: AccountKind): Record<string, unknown> => {
|
|
355
|
+
const value = settings[kind];
|
|
356
|
+
return isRecord(value) ? value : {};
|
|
357
|
+
};
|
|
358
|
+
const fieldIn =
|
|
359
|
+
(kind: AccountKind, object: Record<string, unknown>) =>
|
|
360
|
+
<T>(key: string, parse: (value: unknown) => T | undefined, form: string, fallback: T): T => {
|
|
361
|
+
if (!Object.hasOwn(object, key)) return fallback;
|
|
362
|
+
const value = parse(object[key]);
|
|
363
|
+
if (value !== undefined) return value;
|
|
364
|
+
found(ownerOf(kind, key), `office.${kind}.${key} must be ${form}`);
|
|
365
|
+
return fallback;
|
|
366
|
+
};
|
|
367
|
+
const workField = fieldIn("work", kindSettings("work"));
|
|
368
|
+
const work: Profile = {
|
|
369
|
+
kind: "work",
|
|
370
|
+
clientId: workField("clientId", clientOf, "a UUID", workClient ?? DEFAULT_CLIENT_ID),
|
|
371
|
+
tenant: workField("tenant", tenantOf, TENANT_FORMS, workTenant ?? DEFAULT_TENANT),
|
|
372
|
+
scopes: workField("scopes", scopeList, SCOPE_FORM, withAlways(DEFAULT_SCOPES)),
|
|
373
|
+
};
|
|
374
|
+
const personalField = fieldIn("personal", kindSettings("personal"));
|
|
375
|
+
const personal: Profile = {
|
|
376
|
+
kind: "personal",
|
|
377
|
+
clientId: personalField("clientId", clientOf, "a UUID", personalClient ?? DEFAULT_CLIENT_ID),
|
|
378
|
+
tenant: PERSONAL_TENANT,
|
|
379
|
+
scopes: personalField("scopes", scopeList, SCOPE_FORM, withAlways(DEFAULT_PERSONAL_SCOPES)),
|
|
289
380
|
};
|
|
290
|
-
if (Object.hasOwn(settings, "clientId")) {
|
|
291
|
-
const value = nonEmpty(settings.clientId);
|
|
292
|
-
if (value !== undefined && isUuid(value)) clientId = value;
|
|
293
|
-
else report("clientId", "a UUID");
|
|
294
|
-
}
|
|
295
|
-
if (Object.hasOwn(settings, "tenant")) {
|
|
296
|
-
const value = nonEmpty(settings.tenant);
|
|
297
|
-
if (value !== undefined && isTenant(value)) tenant = value;
|
|
298
|
-
else report("tenant", TENANT_FORMS);
|
|
299
|
-
}
|
|
300
|
-
if (Object.hasOwn(settings, "scopes")) {
|
|
301
|
-
const value = scopeList(settings.scopes);
|
|
302
|
-
if (value === undefined) report("scopes", "a non-empty array of scope names");
|
|
303
|
-
else scopes = value;
|
|
304
|
-
}
|
|
305
|
-
if (Object.hasOwn(settings, "personalScopes")) {
|
|
306
|
-
const value = scopeList(settings.personalScopes);
|
|
307
|
-
if (value === undefined) report("personalScopes", "a non-empty array of scope names");
|
|
308
|
-
else personalScopes = value;
|
|
309
|
-
}
|
|
310
381
|
if (Object.hasOwn(settings, "defaultAccount")) {
|
|
311
382
|
const value = nonEmpty(settings.defaultAccount);
|
|
312
383
|
if (isAccountKind(value)) defaultAccount = value;
|
|
313
|
-
else
|
|
384
|
+
else found(ownerOf("defaultAccount"), "office.defaultAccount must be work or personal");
|
|
314
385
|
}
|
|
315
386
|
if (Object.hasOwn(settings, "confirmWrites")) {
|
|
316
387
|
if (typeof settings.confirmWrites === "boolean") confirmWrites = settings.confirmWrites;
|
|
317
|
-
else
|
|
388
|
+
else found(ownerOf("confirmWrites"), "office.confirmWrites must be a boolean");
|
|
318
389
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
390
|
+
const legacy = LEGACY_KEYS.filter(([key]) => Object.hasOwn(settings, key));
|
|
391
|
+
const unknown = (path: string[], object: Record<string, unknown>, known: readonly string[]) => {
|
|
392
|
+
const skip = path.length === 0 ? legacy.map(([key]) => key) : [];
|
|
393
|
+
const extra = unknownKeys(object, [...known, ...skip]);
|
|
394
|
+
const label = ["office", ...path].join(".");
|
|
395
|
+
for (const layer of ordered) {
|
|
396
|
+
const owned = extra.filter((key) => ownerOf(...path, key) === layer.path);
|
|
397
|
+
if (owned.length > 0) found(layer.path, `${label} has unknown keys ${owned.join(", ")}`);
|
|
325
398
|
}
|
|
399
|
+
};
|
|
400
|
+
unknown([], settings, ROOT_KEYS);
|
|
401
|
+
for (const [key, replacement] of legacy) {
|
|
402
|
+
found(ownerOf(key), `office.${key} is no longer read; use ${replacement}`);
|
|
326
403
|
}
|
|
404
|
+
unknown(["work"], kindObject("work"), WORK_KEYS);
|
|
405
|
+
unknown(["personal"], kindObject("personal"), PERSONAL_KEYS);
|
|
406
|
+
|
|
327
407
|
return {
|
|
328
|
-
work
|
|
329
|
-
personal
|
|
408
|
+
work,
|
|
409
|
+
personal,
|
|
330
410
|
...(defaultAccount === undefined ? {} : { defaultAccount }),
|
|
331
411
|
confirmWrites,
|
|
332
|
-
diagnostics,
|
|
412
|
+
diagnostics: [...envDiagnostics, ...sortedTexts(findings, ordered)],
|
|
333
413
|
};
|
|
334
414
|
}
|
|
335
415
|
|
package/lib/http.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { readFileSync } from "node:fs";
|
|
4
4
|
|
|
5
|
+
import type { AccountKind } from "./config.ts";
|
|
5
6
|
import { cleanLine } from "./text.ts";
|
|
6
7
|
|
|
7
8
|
export const REQUEST_TIMEOUT_MS = 30_000;
|
|
@@ -29,10 +30,20 @@ export class Cancelled extends OfficeError {
|
|
|
29
30
|
/** A request failure; the caller prefixes it with `Office: <service>.<action> failed: `. */
|
|
30
31
|
export class RequestFailure extends Error {
|
|
31
32
|
readonly reason: string;
|
|
32
|
-
|
|
33
|
+
/** Set for 401 and 403: the reason then takes the scopes hint of the call's account kind. */
|
|
34
|
+
readonly scopesHint: boolean;
|
|
35
|
+
constructor(reason: string, scopesHint = false) {
|
|
33
36
|
super(reason);
|
|
34
37
|
this.name = "RequestFailure";
|
|
35
38
|
this.reason = reason;
|
|
39
|
+
this.scopesHint = scopesHint;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The reason as the tool error shows it, for a call of account kind `kind`. */
|
|
43
|
+
reasonFor(kind: AccountKind): string {
|
|
44
|
+
return this.scopesHint
|
|
45
|
+
? `${this.reason} (check the account's permissions and the scopes of office.${kind})`
|
|
46
|
+
: this.reason;
|
|
36
47
|
}
|
|
37
48
|
}
|
|
38
49
|
|
|
@@ -170,11 +181,10 @@ export function statusFailure(response: HttpResponse): RequestFailure {
|
|
|
170
181
|
detail = "";
|
|
171
182
|
}
|
|
172
183
|
let hint = "";
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
} else if (response.status === 429 || response.status === 503) {
|
|
184
|
+
const scopesHint = response.status === 401 || response.status === 403;
|
|
185
|
+
if (!scopesHint && (response.status === 429 || response.status === 503)) {
|
|
176
186
|
const after = response.headers.get("retry-after")?.trim() ?? "";
|
|
177
187
|
if (/^\d+$/.test(after)) hint = ` (retry after ${after} s)`;
|
|
178
188
|
}
|
|
179
|
-
return new RequestFailure(`HTTP ${response.status}${detail}${hint}
|
|
189
|
+
return new RequestFailure(`HTTP ${response.status}${detail}${hint}`, scopesHint);
|
|
180
190
|
}
|
package/lib/tool.ts
CHANGED
|
@@ -274,7 +274,9 @@ export async function runOffice(
|
|
|
274
274
|
output = await run(input, new Graph(options.fetch, token, signal), options.now);
|
|
275
275
|
} catch (error) {
|
|
276
276
|
if (error instanceof RequestFailure) {
|
|
277
|
-
throw new OfficeError(
|
|
277
|
+
throw new OfficeError(
|
|
278
|
+
`Office: ${input.service}.${input.action} failed: ${error.reasonFor(kind)}`,
|
|
279
|
+
);
|
|
278
280
|
}
|
|
279
281
|
throw error;
|
|
280
282
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-dent-office",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A pi extension whose Office tool reads and writes Microsoft 365 (Outlook mail, calendar, Teams and SharePoint) through Microsoft Graph, signed in with the device code flow",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"microsoft-365",
|
package/specs/office.md
CHANGED
|
@@ -229,7 +229,8 @@ be aborted after 30 s, and a response body read past 4194304 bytes MUST be aband
|
|
|
229
229
|
outside 200–299 is the tool error `Office: <service>.<action> failed: HTTP <status>`, followed by
|
|
230
230
|
`: <code>: <message>` when the body's `error.code` and `error.message` are strings, with the
|
|
231
231
|
message cut to 300 UTF-16 code units and `…` appended when cut. On 401 or 403 the error MUST also
|
|
232
|
-
end with ` (check the account's permissions and
|
|
232
|
+
end with ` (check the account's permissions and the scopes of office.<kind>)`, where `<kind>` is
|
|
233
|
+
the call's account kind; on 429 or 503 with a
|
|
233
234
|
`Retry-After` header of whole seconds, with ` (retry after <n> s)`. A timeout is
|
|
234
235
|
`Office: <service>.<action> failed: timed out after 30 s`, a cut body
|
|
235
236
|
`Office: <service>.<action> failed: response exceeds 4194304 bytes`, any other network failure
|
|
@@ -250,7 +251,7 @@ the call's account kind ([account choice](#account-choice), [configuration](#con
|
|
|
250
251
|
1. A stored access token that expires more than 60 s after `now` is used.
|
|
251
252
|
2. Otherwise, a stored refresh token is redeemed at
|
|
252
253
|
`https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token` with `grant_type`
|
|
253
|
-
`refresh_token` and the
|
|
254
|
+
`refresh_token` and the scopes of the call's account kind; the new tokens are stored. When the token endpoint
|
|
254
255
|
answers `invalid_grant`, the account is removed from the store and step 3 follows; any other
|
|
255
256
|
failure is the tool error of [sign-in errors](#sign-in-errors).
|
|
256
257
|
3. Otherwise a [device sign-in](#device-sign-in) is needed.
|
|
@@ -397,34 +398,68 @@ The extension reads the root key `office` of pi-dent's `pi-dent.conf`, global an
|
|
|
397
398
|
as pi-dent-agent `specs/config-file.md` specifies, once per extension instance at its
|
|
398
399
|
first `session_start` or first call.
|
|
399
400
|
|
|
400
|
-
| Key
|
|
401
|
-
|
|
|
402
|
-
| `office.
|
|
403
|
-
| `office.
|
|
404
|
-
| `office.
|
|
405
|
-
| `office.
|
|
406
|
-
| `office.
|
|
407
|
-
| `office.
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
`
|
|
401
|
+
| Key | Type | Default |
|
|
402
|
+
| -------------------------- | -------------------- | -------------------------------------------------------------------------------- |
|
|
403
|
+
| `office.work` | object | the defaults of its keys |
|
|
404
|
+
| `office.work.clientId` | UUID string | `PI_DENT_OFFICE_WORK_CLIENT_ID`, else `14d82eec-204b-4c2f-b7e8-296a70dab67e` |
|
|
405
|
+
| `office.work.tenant` | string | `PI_DENT_OFFICE_WORK_TENANT`, else `organizations` |
|
|
406
|
+
| `office.work.scopes` | array of strings | the default work scopes below |
|
|
407
|
+
| `office.personal` | object | the defaults of its keys |
|
|
408
|
+
| `office.personal.clientId` | UUID string | `PI_DENT_OFFICE_PERSONAL_CLIENT_ID`, else `14d82eec-204b-4c2f-b7e8-296a70dab67e` |
|
|
409
|
+
| `office.personal.scopes` | array of strings | the default personal scopes below |
|
|
410
|
+
| `office.defaultAccount` | `work` or `personal` | `PI_DENT_OFFICE_ACCOUNT`, else none |
|
|
411
|
+
| `office.confirmWrites` | boolean | `false` |
|
|
412
|
+
|
|
413
|
+
`office.work` and `office.personal` each describe the app registration one account kind signs in
|
|
414
|
+
with: its client ID, and its scopes; the `work` kind also its tenant, while the `personal` kind
|
|
415
|
+
always uses the tenant `consumers`. The two kinds can name different app registrations; a kind
|
|
416
|
+
without settings uses Microsoft's public client. Default work scopes:
|
|
411
417
|
`User.Read`, `Mail.ReadWrite`, `Mail.Send`, `Calendars.ReadWrite`, `Chat.ReadWrite`,
|
|
412
418
|
`ChannelMessage.Send`, `Team.ReadBasic.All`, `Channel.ReadBasic.All`, `Files.ReadWrite.All`,
|
|
413
419
|
`Sites.ReadWrite.All`. Default personal scopes: `User.Read`, `Mail.ReadWrite`, `Mail.Send`,
|
|
414
420
|
`Calendars.ReadWrite`, `Files.ReadWrite.All`. The scopes sent are a kind's scopes plus
|
|
415
|
-
`offline_access`, `openid` and `profile`, each once. A tenant is `common`, `organizations`,
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
`
|
|
423
|
-
is the file that set
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
421
|
+
`offline_access`, `openid` and `profile`, each once. A work tenant is `common`, `organizations`, a
|
|
422
|
+
UUID, or a domain name; `consumers` is not one, so the two kinds never share a stored account. String values may use the placeholders of pi-dent-agent
|
|
423
|
+
`specs/config-file.md`, such as `${env.MY_CLIENT_ID}`; pi-dent reports a placeholder that does not
|
|
424
|
+
expand, and the value is then absent (an array element removed), as that spec says. String values
|
|
425
|
+
and environment variables are trimmed, and an empty or white-space-only environment variable counts
|
|
426
|
+
as unset.
|
|
427
|
+
|
|
428
|
+
Diagnostics, each shown through `notify` at level `warning` at `session_start` with a UI, where
|
|
429
|
+
`<source>` is the file that set the key:
|
|
430
|
+
|
|
431
|
+
- A value of the wrong type or form: `pi-dent-office: <source>: office.<path> must be <form>`, where
|
|
432
|
+
`<path>` is the key below `office` (such as `work.clientId`) and `<form>` is `a UUID` for a
|
|
433
|
+
client ID, `common, organizations, a UUID or a domain` for a tenant,
|
|
434
|
+
`a non-empty array of scope names` for a scope list, `work or personal` for an account kind,
|
|
435
|
+
`a boolean` for `office.confirmWrites`, and `an object` for `office.work` and `office.personal`.
|
|
436
|
+
- `office` not an object: `pi-dent-office: <source>: office must be an object`.
|
|
437
|
+
- Unknown keys of `office`, `office.work` or `office.personal`:
|
|
438
|
+
`pi-dent-office: <source>: office<.path> has unknown keys <keys>` (`, `-joined, sorted), except
|
|
439
|
+
the keys of the next item.
|
|
440
|
+
- A key of the earlier flat layout, which is no longer read:
|
|
441
|
+
`pi-dent-office: <source>: office.<key> is no longer read; use <replacement>`, with the
|
|
442
|
+
replacement `office.work.clientId and office.personal.clientId` for `clientId`,
|
|
443
|
+
`office.work.tenant` for `tenant`, `office.work.scopes` for `scopes` and
|
|
444
|
+
`office.personal.scopes` for `personalScopes`.
|
|
445
|
+
- An environment variable of the wrong form: `pi-dent-office: <variable> must be <form>`, falling
|
|
446
|
+
back the same way; a configuration key wins over its environment variable.
|
|
447
|
+
- `PI_DENT_OFFICE_CLIENT_ID` or `PI_DENT_OFFICE_TENANT` set and non-empty:
|
|
448
|
+
`pi-dent-office: <variable> is no longer read; use <replacement>`, with
|
|
449
|
+
`PI_DENT_OFFICE_WORK_CLIENT_ID and PI_DENT_OFFICE_PERSONAL_CLIENT_ID` and
|
|
450
|
+
`PI_DENT_OFFICE_WORK_TENANT` respectively.
|
|
451
|
+
|
|
452
|
+
Diagnostics of environment variables come first (wrong forms in the order of the table, then the
|
|
453
|
+
no-longer-read ones), then those of the layers, global first. Within a layer: wrong values in the
|
|
454
|
+
order of the table, then unknown keys of `office`, then no-longer-read keys, then unknown keys of
|
|
455
|
+
`office.work` and of `office.personal`. A key set in both layers is attributed to the project
|
|
456
|
+
layer only. An invalid configuration value falls back to its environment variable when that is
|
|
457
|
+
valid, else to the default. A wrong-form environment variable is reported also when a
|
|
458
|
+
configuration key overrides it. Values are validated after the layers are merged, so a value
|
|
459
|
+
overridden by the project layer is not checked. `office must be an object` is the only diagnostic
|
|
460
|
+
of its layer. Unknown keys set in both layers give one diagnostic per layer, global first. The
|
|
461
|
+
no-longer-read keys, and the no-longer-read variables, are reported in the order of their list
|
|
462
|
+
above.
|
|
428
463
|
|
|
429
464
|
> Note (non-normative): the default client ID is Microsoft's public "Microsoft Graph Command Line
|
|
430
465
|
> Tools" app, so sign-in needs no app registration; `ChannelMessage.Read.All`, needed by
|