@gjsify/system-accounts 0.64.47 → 0.64.48
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 +1 -0
- package/lib/esm/dbus.js +1 -1
- package/lib/esm/goa.js +1 -1
- package/lib/esm/mapping.js +1 -1
- package/lib/esm/no-account-store.js +1 -1
- package/lib/types/fake-goa.d.ts +6 -2
- package/lib/types/index.d.ts +1 -1
- package/lib/types/mapping.d.ts +11 -3
- package/lib/types/types.d.ts +16 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -35,6 +35,7 @@ for (const account of await accounts.listAccounts('mail')) {
|
|
|
35
35
|
| `capabilities()` | what THIS host can answer: `services` it lists, `credentials` kinds it hands out. Both empty without an account store |
|
|
36
36
|
| `listAccounts(service?)` | `Account[]` (id, provider, identity, label, enabled services). Empty when the store cannot be reached |
|
|
37
37
|
| `getMailSettings(account)` | `{ sender, imap?, smtp? }`, each server as host, port, `security` (`tls` / `starttls` / `none`) and user name; or `Unavailable` |
|
|
38
|
+
| `getDavSettings(account, kind)` | CalDAV (`calendar`) or CardDAV (`contacts`): `{ url, username?, acceptInvalidCertificates }`, or `Unavailable`. Transport settings only; credentials via `getCredentials(account, 'dav')` |
|
|
38
39
|
| `getCredentials(account, purpose)` | `{ kind: 'password', secret }`, `{ kind: 'oauth2', token, expiresAt }`, or `Unavailable` |
|
|
39
40
|
|
|
40
41
|
**A missing capability is a value, never an exception.** `Unavailable` carries a `reason`: `no-account-store`, `unknown-account`, `not-supported` (the account has no mail server, no credentials) or `credentials-unavailable` (the store would not hand the secret out). The ADR's `Credentials` has two members; the third is how that rule is spelled for a call that has to return one.
|
package/lib/esm/dbus.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{accountFrom as e,
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{accountFrom as e,davSettingsFrom as t,mailSettingsFrom as n,passwordIds as r}from"./mapping.js";import{isUnavailable as i}from"./no-account-store.js";const a=`org.gnome.OnlineAccounts`,unavailable=e=>({kind:`unavailable`,reason:e}),str=(e,t)=>{let n=e?.[t];return typeof n==`string`?n:``},bool=(e,t)=>e?.[t]===!0;function accountOf(t){let n=t.properties(`Account`);if(n)return e({id:str(n,`Id`),provider:str(n,`ProviderType`),providerName:str(n,`ProviderName`),identity:str(n,`Identity`),label:str(n,`PresentationIdentity`),present:{mail:!!t.properties(`Mail`),calendar:!!t.properties(`Calendar`),contacts:!!t.properties(`Contacts`),files:!!t.properties(`Files`)},disabled:{mail:bool(n,`MailDisabled`),calendar:bool(n,`CalendarDisabled`),contacts:bool(n,`ContactsDisabled`),files:bool(n,`FilesDisabled`)}})}function createDbusAccounts({connect:e,now:a=Date.now}){let o,store=async()=>{o??=e();let t=await o;return t||(o=void 0),t};async function find(e){let t=await store();return t?t.objects().find(t=>str(t.properties(`Account`),`Id`)===e.id)??unavailable(`unknown-account`):unavailable(`no-account-store`)}return{capabilities:()=>({services:[`mail`,`calendar`,`contacts`,`files`],credentials:[`password`,`oauth2`]}),async listAccounts(e){let t=await store();if(!t)return[];let n=t.objects().flatMap(e=>accountOf(e)??[]);return e?n.filter(t=>t.services.includes(e)):n},async getMailSettings(e){let t=await find(e);if(i(t))return t;let r=t.properties(`Mail`);return r?n({emailAddress:str(r,`EmailAddress`),name:str(r,`Name`),imapSupported:bool(r,`ImapSupported`),imap:{host:str(r,`ImapHost`),userName:str(r,`ImapUserName`),useSsl:bool(r,`ImapUseSsl`),useTls:bool(r,`ImapUseTls`)},smtpSupported:bool(r,`SmtpSupported`),smtp:{host:str(r,`SmtpHost`),userName:str(r,`SmtpUserName`),useSsl:bool(r,`SmtpUseSsl`),useTls:bool(r,`SmtpUseTls`),authenticate:bool(r,`SmtpUseAuth`)}})??unavailable(`not-supported`):unavailable(`not-supported`)},async getDavSettings(e,n){let r=await find(e);if(i(r))return r;let a=r.properties(n===`calendar`?`Calendar`:`Contacts`);return a?t({uri:str(a,`Uri`),userName:str(r.properties(`Account`),`Identity`),acceptSslErrors:bool(a,`AcceptSslErrors`)})??unavailable(`not-supported`):unavailable(`not-supported`)},async getCredentials(e,t){let n=await find(e);if(i(n))return n;if(n.properties(`OAuth2Based`)){let[e,t]=await n.call(`OAuth2Based`,`GetAccessToken`,[])??[];return typeof e!=`string`||!e||typeof t!=`number`?unavailable(`credentials-unavailable`):{kind:`oauth2`,token:e,expiresAt:a()+t*1e3}}if(!n.properties(`PasswordBased`))return unavailable(`not-supported`);for(let e of r(t)){let[t]=await n.call(`PasswordBased`,`GetPassword`,[e])??[];if(typeof t==`string`&&t)return{kind:`password`,secret:t}}return unavailable(`credentials-unavailable`)}}}export{a as GOA_NAMESPACE,createDbusAccounts};
|
package/lib/esm/goa.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{accountFrom as e,
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{accountFrom as e,davSettingsFrom as t,mailSettingsFrom as n,passwordIds as r}from"./mapping.js";import{isUnavailable as i,noAccountStore as a}from"./no-account-store.js";import o from"gi://Gio?version=2.0";import s from"gi://GLib?version=2.0";const unavailable=e=>({kind:`unavailable`,reason:e});function newClient(e,t){return new Promise((n,r)=>{e.Client.new(t,(t,i)=>{try{n(e.Client.new_finish(i))}catch(e){r(e)}})})}async function connect(e,t){let n=new o.Cancellable,r=s.timeout_add(s.PRIORITY_DEFAULT,t,()=>(n.cancel(),s.SOURCE_REMOVE));try{return await newClient(e,n)}catch{return}finally{s.Source.remove(r)}}function secretOf(e,t){return new Promise(n=>{e.call_get_password(t,null,(t,r)=>{try{let[t,i]=e.call_get_password_finish(r);n(t&&i?i:void 0)}catch{n(void 0)}})})}function tokenOf(e){return new Promise(t=>{e.call_get_access_token(null,(n,r)=>{try{let[n,i,a]=e.call_get_access_token_finish(r);t(n&&i?[i,a]:void 0)}catch{t(void 0)}})})}function toAccount(t){let n=t.get_account();if(n)return e({id:n.id??``,provider:n.provider_type??``,providerName:n.provider_name??``,identity:n.identity??``,label:n.presentation_identity??``,present:{mail:!!t.get_mail(),calendar:!!t.get_calendar(),contacts:!!t.get_contacts(),files:!!t.get_files()},disabled:{mail:!!n.mail_disabled,calendar:!!n.calendar_disabled,contacts:!!n.contacts_disabled,files:!!n.files_disabled}})}function createGoaAccounts({goa:e,now:o=Date.now,connectTimeoutMs:s=5e3}){if(!e)return a;let c,client=async()=>{c??=connect(e,s);let t=await c;return t||(c=void 0),t};async function find(e){let t=await client();return t?t.lookup_by_id(e.id)??unavailable(`unknown-account`):unavailable(`no-account-store`)}return{capabilities:()=>({services:[`mail`,`calendar`,`contacts`,`files`],credentials:[`password`,`oauth2`]}),async listAccounts(e){let t=await client();if(!t)return[];let n=t.get_accounts().flatMap(e=>toAccount(e)??[]);return e?n.filter(t=>t.services.includes(e)):n},async getMailSettings(e){let t=await find(e);if(i(t))return t;let r=t.get_mail();return r?n({emailAddress:r.email_address??``,name:r.name??``,imapSupported:r.imap_supported,imap:{host:r.imap_host??``,userName:r.imap_user_name??``,useSsl:r.imap_use_ssl,useTls:r.imap_use_tls},smtpSupported:r.smtp_supported,smtp:{host:r.smtp_host??``,userName:r.smtp_user_name??``,useSsl:r.smtp_use_ssl,useTls:r.smtp_use_tls,authenticate:r.smtp_use_auth}})??unavailable(`not-supported`):unavailable(`not-supported`)},async getDavSettings(e,n){let r=await find(e);if(i(r))return r;let a=n===`calendar`?r.get_calendar():r.get_contacts();return a?t({uri:a.uri??``,userName:r.get_account()?.identity??``,acceptSslErrors:a.accept_ssl_errors})??unavailable(`not-supported`):unavailable(`not-supported`)},async getCredentials(e,t){let n=await find(e);if(i(n))return n;let a=n.get_oauth2_based();if(a){let e=await tokenOf(a);if(!e)return unavailable(`credentials-unavailable`);let[t,n]=e;return{kind:`oauth2`,token:t,expiresAt:o()+n*1e3}}let s=n.get_password_based();if(!s)return unavailable(`not-supported`);for(let e of r(t)){let t=await secretOf(s,e);if(t!==void 0)return{kind:`password`,secret:t}}return unavailable(`credentials-unavailable`)}}}export{createGoaAccounts};
|
package/lib/esm/mapping.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";function splitHostPort(e){let t=e.trim(),n=/^\[([^\]]+)\](?::(\d*))?$/.exec(t);if(n)return{host:n[1],port:parsePort(n[2])};let r=t.indexOf(`:`);return r===-1||r!==t.lastIndexOf(`:`)?{host:t}:{host:t.slice(0,r),port:parsePort(t.slice(r+1))}}function parsePort(e){if(!e||!/^\d+$/.test(e))return;let t=Number.parseInt(e,10);return t>=1&&t<=65535?t:void 0}const e={imap:993,smtp:465},t={imap:{tls:993,starttls:143,none:143},smtp:{tls:465,starttls:587,none:25}};function securityFromFlags(t,n,r,i){return n?`tls`:r?`starttls`:i===e[t]?`tls`:`none`}function serverSettingsFrom(e,n){let{host:r,port:i}=splitHostPort(n.host);if(!r)return;let a=securityFromFlags(e,n.useSsl,n.useTls,i);return{host:r,port:i??t[e][a],security:a,...n.authenticate&&n.userName?{username:n.userName}:{}}}function mailSettingsFrom(e){let t=e.imapSupported?serverSettingsFrom(`imap`,{...e.imap,authenticate:!0}):void 0,n=e.smtpSupported?serverSettingsFrom(`smtp`,e.smtp):void 0;if(!(!t&&!n))return{sender:{address:e.emailAddress,...e.name?{name:e.name}:{}},...t?{imap:t}:{},...n?{smtp:n}:{}}}function enabledServices(e,t){return[`mail`,`calendar`,`contacts`,`files`].filter(n=>e[n]&&!t[n])}function passwordIds(e){return e===`imap`?[`imap-password`,`password`,``]:[`smtp-password`,`imap-password`,`password`,``]}function accountFrom(e){return{id:e.id,provider:e.provider,providerName:e.providerName,identity:e.identity,label:e.label,services:enabledServices(e.present,e.disabled)}}export{accountFrom,enabledServices,mailSettingsFrom,passwordIds,securityFromFlags,serverSettingsFrom,splitHostPort};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";function splitHostPort(e){let t=e.trim(),n=/^\[([^\]]+)\](?::(\d*))?$/.exec(t);if(n)return{host:n[1],port:parsePort(n[2])};let r=t.indexOf(`:`);return r===-1||r!==t.lastIndexOf(`:`)?{host:t}:{host:t.slice(0,r),port:parsePort(t.slice(r+1))}}function parsePort(e){if(!e||!/^\d+$/.test(e))return;let t=Number.parseInt(e,10);return t>=1&&t<=65535?t:void 0}const e={imap:993,smtp:465},t={imap:{tls:993,starttls:143,none:143},smtp:{tls:465,starttls:587,none:25}};function securityFromFlags(t,n,r,i){return n?`tls`:r?`starttls`:i===e[t]?`tls`:`none`}function serverSettingsFrom(e,n){let{host:r,port:i}=splitHostPort(n.host);if(!r)return;let a=securityFromFlags(e,n.useSsl,n.useTls,i);return{host:r,port:i??t[e][a],security:a,...n.authenticate&&n.userName?{username:n.userName}:{}}}function mailSettingsFrom(e){let t=e.imapSupported?serverSettingsFrom(`imap`,{...e.imap,authenticate:!0}):void 0,n=e.smtpSupported?serverSettingsFrom(`smtp`,e.smtp):void 0;if(!(!t&&!n))return{sender:{address:e.emailAddress,...e.name?{name:e.name}:{}},...t?{imap:t}:{},...n?{smtp:n}:{}}}function enabledServices(e,t){return[`mail`,`calendar`,`contacts`,`files`].filter(n=>e[n]&&!t[n])}function passwordIds(e){return e===`dav`?[`password`,``]:e===`imap`?[`imap-password`,`password`,``]:[`smtp-password`,`imap-password`,`password`,``]}function accountFrom(e){return{id:e.id,provider:e.provider,providerName:e.providerName,identity:e.identity,label:e.label,services:enabledServices(e.present,e.disabled)}}function davSettingsFrom(e){let t=e.uri.trim();if(/^https?:\/\/[^/\s]+/i.test(t))return{url:t,...e.userName?{username:e.userName}:{},acceptInvalidCertificates:e.acceptSslErrors}}export{accountFrom,davSettingsFrom,enabledServices,mailSettingsFrom,passwordIds,securityFromFlags,serverSettingsFrom,splitHostPort};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";const e={kind:`unavailable`,reason:`no-account-store`},t={capabilities:()=>({services:[],credentials:[]}),listAccounts:async()=>[],getMailSettings:async()=>e,getCredentials:async()=>e};function isUnavailable(e){return`kind`in e&&e.kind===`unavailable`}export{isUnavailable,t as noAccountStore};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";const e={kind:`unavailable`,reason:`no-account-store`},t={capabilities:()=>({services:[],credentials:[]}),listAccounts:async()=>[],getMailSettings:async()=>e,getDavSettings:async()=>e,getCredentials:async()=>e};function isUnavailable(e){return`kind`in e&&e.kind===`unavailable`}export{isUnavailable,t as noAccountStore};
|
package/lib/types/fake-goa.d.ts
CHANGED
|
@@ -16,14 +16,18 @@ export interface FakeMail {
|
|
|
16
16
|
auth: boolean;
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
+
export interface FakeDav {
|
|
20
|
+
readonly uri: string;
|
|
21
|
+
readonly acceptSslErrors?: boolean;
|
|
22
|
+
}
|
|
19
23
|
export interface FakeAccount {
|
|
20
24
|
readonly id: string;
|
|
21
25
|
readonly provider?: string;
|
|
22
26
|
readonly identity?: string;
|
|
23
27
|
readonly disabled?: Partial<Record<AccountService, boolean>>;
|
|
24
28
|
readonly mail?: FakeMail;
|
|
25
|
-
readonly calendar?: boolean;
|
|
26
|
-
readonly contacts?: boolean;
|
|
29
|
+
readonly calendar?: boolean | FakeDav;
|
|
30
|
+
readonly contacts?: boolean | FakeDav;
|
|
27
31
|
readonly files?: boolean;
|
|
28
32
|
/** Secret id → dummy secret. */
|
|
29
33
|
readonly passwords?: Readonly<Record<string, string>>;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { createSystemAccounts } from './system-accounts.js';
|
|
2
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';
|
|
3
|
+
export type { Account, AccountCapabilities, AccountService, ConnectionSecurity, CredentialKind, CredentialPurpose, DavKind, DavSettings, Credentials, MailProtocol, MailSettings, OAuth2Credentials, PasswordCredentials, ServerSettings, SystemAccounts, Unavailable, UnavailableReason, } from './types.js';
|
package/lib/types/mapping.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Account, AccountService, ConnectionSecurity, CredentialPurpose, MailSettings, ServerSettings } from './types.js';
|
|
1
|
+
import type { Account, AccountService, ConnectionSecurity, CredentialPurpose, DavSettings, MailProtocol, MailSettings, ServerSettings } from './types.js';
|
|
2
2
|
export interface HostPort {
|
|
3
3
|
readonly host: string;
|
|
4
4
|
readonly port?: number;
|
|
@@ -13,7 +13,7 @@ export declare function splitHostPort(raw: string): HostPort;
|
|
|
13
13
|
* The two flags an account store keeps for transport security. When neither is set the
|
|
14
14
|
* port still tells: 993/465 is TLS from the first byte, which some stores leave unflagged.
|
|
15
15
|
*/
|
|
16
|
-
export declare function securityFromFlags(protocol:
|
|
16
|
+
export declare function securityFromFlags(protocol: MailProtocol, useSsl: boolean, useTls: boolean, explicitPort?: number): ConnectionSecurity;
|
|
17
17
|
export interface ServerFields {
|
|
18
18
|
readonly host: string;
|
|
19
19
|
readonly userName: string;
|
|
@@ -23,7 +23,7 @@ export interface ServerFields {
|
|
|
23
23
|
readonly authenticate: boolean;
|
|
24
24
|
}
|
|
25
25
|
/** `undefined` when the account names no host. */
|
|
26
|
-
export declare function serverSettingsFrom(protocol:
|
|
26
|
+
export declare function serverSettingsFrom(protocol: MailProtocol, fields: ServerFields): ServerSettings | undefined;
|
|
27
27
|
export interface MailFields {
|
|
28
28
|
readonly emailAddress: string;
|
|
29
29
|
readonly name: string;
|
|
@@ -53,3 +53,11 @@ export interface AccountFields {
|
|
|
53
53
|
}
|
|
54
54
|
/** The contract's `Account` from an account store's flat fields. */
|
|
55
55
|
export declare function accountFrom(fields: AccountFields): Account;
|
|
56
|
+
export interface DavFields {
|
|
57
|
+
readonly uri: string;
|
|
58
|
+
/** What the user logs in as; empty when the store names none. */
|
|
59
|
+
readonly userName: string;
|
|
60
|
+
readonly acceptSslErrors: boolean;
|
|
61
|
+
}
|
|
62
|
+
/** `undefined` when the store holds no usable http(s) URL for the service. */
|
|
63
|
+
export declare function davSettingsFrom(fields: DavFields): DavSettings | undefined;
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export type AccountService = 'mail' | 'calendar' | 'contacts' | 'files';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
export type MailProtocol = 'imap' | 'smtp';
|
|
3
|
+
/** Which login a credential is for. IMAP and SMTP can hold different secrets; `dav` is CalDAV and CardDAV. */
|
|
4
|
+
export type CredentialPurpose = MailProtocol | 'dav';
|
|
5
|
+
/** The DAV flavour asked for: CalDAV for `calendar`, CardDAV for `contacts`. */
|
|
6
|
+
export type DavKind = 'calendar' | 'contacts';
|
|
4
7
|
export type CredentialKind = 'password' | 'oauth2';
|
|
5
8
|
/** `tls` is TLS from the first byte, `starttls` upgrades a plain connection, `none` stays plain. */
|
|
6
9
|
export type ConnectionSecurity = 'tls' | 'starttls' | 'none';
|
|
@@ -34,6 +37,15 @@ export interface MailSettings {
|
|
|
34
37
|
/** Absent when the account has no SMTP server configured. */
|
|
35
38
|
readonly smtp?: ServerSettings;
|
|
36
39
|
}
|
|
40
|
+
/** Where a CalDAV or CardDAV client connects. Transport settings only: the data layer stays out (ADR 0095). */
|
|
41
|
+
export interface DavSettings {
|
|
42
|
+
/** The base URL the account store holds for the service (http or https). */
|
|
43
|
+
readonly url: string;
|
|
44
|
+
/** Absent when the store names no user. */
|
|
45
|
+
readonly username?: string;
|
|
46
|
+
/** The user told the store to accept an invalid certificate for this account. */
|
|
47
|
+
readonly acceptInvalidCertificates: boolean;
|
|
48
|
+
}
|
|
37
49
|
export interface PasswordCredentials {
|
|
38
50
|
readonly kind: 'password';
|
|
39
51
|
readonly secret: string;
|
|
@@ -73,6 +85,8 @@ export interface SystemAccounts {
|
|
|
73
85
|
/** Accounts, optionally only those set up for `service`. Empty when the store cannot be reached. */
|
|
74
86
|
listAccounts(service?: AccountService): Promise<Account[]>;
|
|
75
87
|
getMailSettings(account: Account): Promise<MailSettings | Unavailable>;
|
|
88
|
+
/** CalDAV (`calendar`) or CardDAV (`contacts`) base URL and user; `Unavailable` when the account has none. */
|
|
89
|
+
getDavSettings(account: Account, kind: DavKind): Promise<DavSettings | Unavailable>;
|
|
76
90
|
/** The caller owns the result: it is never logged, cached or put in an error by this package. */
|
|
77
91
|
getCredentials(account: Account, purpose: CredentialPurpose): Promise<Credentials>;
|
|
78
92
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/system-accounts",
|
|
3
|
-
"version": "0.64.
|
|
3
|
+
"version": "0.64.48",
|
|
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.64.
|
|
51
|
-
"@gjsify/unit": "0.64.
|
|
50
|
+
"@gjsify/cli": "0.64.48",
|
|
51
|
+
"@gjsify/unit": "0.64.48",
|
|
52
52
|
"typescript": "^6.0.3"
|
|
53
53
|
},
|
|
54
54
|
"license": "MIT",
|