@gjsify/system-accounts 0.55.0 → 0.57.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.
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { createSystemAccounts } from './system-accounts.js';
|
|
2
|
+
export { isUnavailable } from './no-account-store.js';
|
|
3
|
+
export type { Account, AccountCapabilities, AccountService, ConnectionSecurity, CredentialKind, CredentialPurpose, Credentials, MailSettings, OAuth2Credentials, PasswordCredentials, ServerSettings, SystemAccounts, Unavailable, UnavailableReason, } from './types.js';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { AccountService, ConnectionSecurity, CredentialPurpose, MailSettings, ServerSettings } from './types.js';
|
|
2
|
+
export interface HostPort {
|
|
3
|
+
readonly host: string;
|
|
4
|
+
readonly port?: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Split `host`, `host:port` and `[v6]:port`. A bare IPv6 literal has several colons and no
|
|
8
|
+
* port. A port outside 1..65535 is dropped rather than guessed, so the caller falls back to
|
|
9
|
+
* the protocol default instead of dialling port 0.
|
|
10
|
+
*/
|
|
11
|
+
export declare function splitHostPort(raw: string): HostPort;
|
|
12
|
+
/**
|
|
13
|
+
* The two flags an account store keeps for transport security. When neither is set the
|
|
14
|
+
* port still tells: 993/465 is TLS from the first byte, which some stores leave unflagged.
|
|
15
|
+
*/
|
|
16
|
+
export declare function securityFromFlags(protocol: CredentialPurpose, useSsl: boolean, useTls: boolean, explicitPort?: number): ConnectionSecurity;
|
|
17
|
+
export interface ServerFields {
|
|
18
|
+
readonly host: string;
|
|
19
|
+
readonly userName: string;
|
|
20
|
+
readonly useSsl: boolean;
|
|
21
|
+
readonly useTls: boolean;
|
|
22
|
+
/** False for a server that takes no login: the user name is then not reported. */
|
|
23
|
+
readonly authenticate: boolean;
|
|
24
|
+
}
|
|
25
|
+
/** `undefined` when the account names no host. */
|
|
26
|
+
export declare function serverSettingsFrom(protocol: CredentialPurpose, fields: ServerFields): ServerSettings | undefined;
|
|
27
|
+
export interface MailFields {
|
|
28
|
+
readonly emailAddress: string;
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly imapSupported: boolean;
|
|
31
|
+
readonly imap: Omit<ServerFields, 'authenticate'>;
|
|
32
|
+
readonly smtpSupported: boolean;
|
|
33
|
+
readonly smtp: ServerFields;
|
|
34
|
+
}
|
|
35
|
+
/** `undefined` when the account has neither an IMAP nor an SMTP server. */
|
|
36
|
+
export declare function mailSettingsFrom(fields: MailFields): MailSettings | undefined;
|
|
37
|
+
/** The services an account is set up for and the user has not switched off. */
|
|
38
|
+
export declare function enabledServices(present: Readonly<Record<AccountService, boolean>>, disabled: Readonly<Record<AccountService, boolean>>): AccountService[];
|
|
39
|
+
/**
|
|
40
|
+
* The secret ids to try, in order. The store keeps the IMAP and the SMTP password under
|
|
41
|
+
* their own ids; the bare ids are what older account types used. SMTP falls back to the
|
|
42
|
+
* IMAP password because one login often serves both and the store keeps it once.
|
|
43
|
+
*/
|
|
44
|
+
export declare function passwordIds(purpose: CredentialPurpose): readonly string[];
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SystemAccounts, Unavailable } from './types.js';
|
|
2
|
+
/** The answer of a host with no account store: nothing is listed, every question gets a reason. */
|
|
3
|
+
export declare const noAccountStore: SystemAccounts;
|
|
4
|
+
export declare function isUnavailable<T extends object>(answer: T | Unavailable): answer is Unavailable;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export type AccountService = 'mail' | 'calendar' | 'contacts' | 'files';
|
|
2
|
+
/** Which login a credential is for. IMAP and SMTP can hold different secrets. */
|
|
3
|
+
export type CredentialPurpose = 'imap' | 'smtp';
|
|
4
|
+
export type CredentialKind = 'password' | 'oauth2';
|
|
5
|
+
/** `tls` is TLS from the first byte, `starttls` upgrades a plain connection, `none` stays plain. */
|
|
6
|
+
export type ConnectionSecurity = 'tls' | 'starttls' | 'none';
|
|
7
|
+
export interface Account {
|
|
8
|
+
/** Stable for one account on one host; opaque to the caller. */
|
|
9
|
+
readonly id: string;
|
|
10
|
+
/** The store's provider key, e.g. `google` or `imap_smtp`. For display and diagnostics, not for branching. */
|
|
11
|
+
readonly provider: string;
|
|
12
|
+
readonly providerName: string;
|
|
13
|
+
/** What the user logs in as, usually the mail address. */
|
|
14
|
+
readonly identity: string;
|
|
15
|
+
/** The name the system shows for the account. */
|
|
16
|
+
readonly label: string;
|
|
17
|
+
/** The services the account is set up for AND the user has not switched off. */
|
|
18
|
+
readonly services: readonly AccountService[];
|
|
19
|
+
}
|
|
20
|
+
export interface ServerSettings {
|
|
21
|
+
readonly host: string;
|
|
22
|
+
readonly port: number;
|
|
23
|
+
readonly security: ConnectionSecurity;
|
|
24
|
+
/** Absent when the server takes no login (an SMTP relay without authentication). */
|
|
25
|
+
readonly username?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface MailSettings {
|
|
28
|
+
readonly sender: {
|
|
29
|
+
readonly address: string;
|
|
30
|
+
readonly name?: string;
|
|
31
|
+
};
|
|
32
|
+
/** Absent when the account has no IMAP server configured. */
|
|
33
|
+
readonly imap?: ServerSettings;
|
|
34
|
+
/** Absent when the account has no SMTP server configured. */
|
|
35
|
+
readonly smtp?: ServerSettings;
|
|
36
|
+
}
|
|
37
|
+
export interface PasswordCredentials {
|
|
38
|
+
readonly kind: 'password';
|
|
39
|
+
readonly secret: string;
|
|
40
|
+
}
|
|
41
|
+
export interface OAuth2Credentials {
|
|
42
|
+
readonly kind: 'oauth2';
|
|
43
|
+
/** An access token, valid until `expiresAt`. Ask again afterwards; never store it. */
|
|
44
|
+
readonly token: string;
|
|
45
|
+
/** Milliseconds since the epoch. */
|
|
46
|
+
readonly expiresAt: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Why a question got no answer. A missing capability is a value, never an exception
|
|
50
|
+
* (ADR 0095), so callers branch on this instead of wrapping every call in try/catch.
|
|
51
|
+
*/
|
|
52
|
+
export type UnavailableReason =
|
|
53
|
+
/** The host has no account store, or it cannot be reached. */
|
|
54
|
+
'no-account-store' | 'unknown-account'
|
|
55
|
+
/** The account exists but is not set up for what was asked, e.g. no mail server. */
|
|
56
|
+
| 'not-supported'
|
|
57
|
+
/** The store would not hand the secret out: locked, cancelled, or none stored. */
|
|
58
|
+
| 'credentials-unavailable';
|
|
59
|
+
export interface Unavailable {
|
|
60
|
+
readonly kind: 'unavailable';
|
|
61
|
+
readonly reason: UnavailableReason;
|
|
62
|
+
}
|
|
63
|
+
export type Credentials = PasswordCredentials | OAuth2Credentials | Unavailable;
|
|
64
|
+
export interface AccountCapabilities {
|
|
65
|
+
/** Services `listAccounts` can report. Empty: this host has no account store. */
|
|
66
|
+
readonly services: readonly AccountService[];
|
|
67
|
+
/** Credential kinds `getCredentials` can hand out. Empty: accounts are listed but no secret is given. */
|
|
68
|
+
readonly credentials: readonly CredentialKind[];
|
|
69
|
+
}
|
|
70
|
+
export interface SystemAccounts {
|
|
71
|
+
/** What THIS host can answer. Synchronous and cheap: decided when the driver is created. */
|
|
72
|
+
capabilities(): AccountCapabilities;
|
|
73
|
+
/** Accounts, optionally only those set up for `service`. Empty when the store cannot be reached. */
|
|
74
|
+
listAccounts(service?: AccountService): Promise<Account[]>;
|
|
75
|
+
getMailSettings(account: Account): Promise<MailSettings | Unavailable>;
|
|
76
|
+
/** The caller owns the result: it is never logged, cached or put in an error by this package. */
|
|
77
|
+
getCredentials(account: Account, purpose: CredentialPurpose): Promise<Credentials>;
|
|
78
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/system-accounts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.57.0",
|
|
4
4
|
"description": "The accounts a user already set up on their system: find them, read their mail server settings, get credentials. GNOME Online Accounts on Linux.",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"@girs/goa-1.0": "5.4.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@gjsify/cli": "^0.
|
|
51
|
-
"@gjsify/unit": "^0.
|
|
50
|
+
"@gjsify/cli": "^0.57.0",
|
|
51
|
+
"@gjsify/unit": "^0.57.0",
|
|
52
52
|
"typescript": "^6.0.3"
|
|
53
53
|
},
|
|
54
54
|
"license": "MIT",
|