@octane-xplat/contacts 0.0.0-nightly.gaffaece

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Alec Larson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # `@octane-xplat/contacts`
2
+
3
+ ```sh
4
+ pnpm add @octane-xplat/contacts
5
+ ```
6
+
7
+ The device address book — reads and basic writes through
8
+ `@nativescript/contacts` on iOS/Android, the Contact Picker API
9
+ (`navigator.contacts.select`) on web where it exists.
10
+
11
+ ```ts
12
+ import { contacts } from '@octane-xplat/contacts'
13
+
14
+ if ((await contacts.ensure()) === 'granted') {
15
+ const people = await contacts.getAll({ fields: ['name', 'phoneNumbers'], sort: 'lastName' })
16
+ const jane = await contacts.getByName('Jane')
17
+ await contacts.add({ firstName: 'Ada', emails: [{ label: 'work', email: 'ada@example.com' }] })
18
+ }
19
+ ```
20
+
21
+ Notes:
22
+
23
+ - `getById` is a direct lookup on iOS; on Android the plugin ships no id
24
+ query, so it fetches the store and filters — call sparingly.
25
+ - Web is read-only and picker-shaped: the user selects contacts per call;
26
+ writes and id/name lookups report `unsupported`.
27
+ - macOS and Windows report `supported: false` (bridging not wired).
package/package.json ADDED
@@ -0,0 +1,95 @@
1
+ {
2
+ "name": "@octane-xplat/contacts",
3
+ "version": "0.0.0-nightly.gaffaece",
4
+ "description": "Device address book for Octane xplat — contact reads and writes on iOS/Android, Contact Picker API on web",
5
+ "keywords": [
6
+ "android",
7
+ "cross-platform",
8
+ "nativescript",
9
+ "octane",
10
+ "xplat",
11
+ "contacts",
12
+ "address-book"
13
+ ],
14
+ "homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/contacts",
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/octane-xplat/octane-xplat",
19
+ "directory": "packages/contacts"
20
+ },
21
+ "files": [
22
+ "src",
23
+ "platforms",
24
+ "types",
25
+ "!src/**/*.test.*",
26
+ "!src/**/*.spec.*"
27
+ ],
28
+ "type": "module",
29
+ "exports": {
30
+ ".": {
31
+ "macos": {
32
+ "types": "./types/generated/index.macos.d.ts",
33
+ "default": "./src/index.macos.ts"
34
+ },
35
+ "web": {
36
+ "types": "./types/generated/index.web.d.ts",
37
+ "default": "./src/index.web.ts"
38
+ },
39
+ "native": {
40
+ "types": "./types/generated/index.d.ts",
41
+ "default": "./src/index.ts"
42
+ },
43
+ "types": "./types/generated/index.d.ts",
44
+ "default": "./src/index.ts"
45
+ },
46
+ "./*": {
47
+ "types": "./types/generated/*.d.ts",
48
+ "default": "./src/*"
49
+ },
50
+ "./*.ts": {
51
+ "types": "./types/generated/*.d.ts",
52
+ "default": "./src/*.ts"
53
+ }
54
+ },
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "devDependencies": {
59
+ "@nativescript-community/octane": "0.2.5",
60
+ "@nativescript/core": "9.1.3",
61
+ "@nativescript/types": "9.1.4",
62
+ "@tsrx/typescript-plugin": "0.4.11",
63
+ "octane": "0.14.0",
64
+ "tsrx-typegen": "0.4.0",
65
+ "typescript": "5.9.3"
66
+ },
67
+ "peerDependencies": {
68
+ "@nativescript-community/octane": ">=0.2.1 <1",
69
+ "@nativescript/core": ">=9.1.0 <10",
70
+ "octane": ">=0.6.3 <1"
71
+ },
72
+ "peerDependenciesMeta": {
73
+ "@nativescript-community/octane": {
74
+ "optional": true
75
+ },
76
+ "@nativescript/core": {
77
+ "optional": true
78
+ }
79
+ },
80
+ "nativescript": {
81
+ "platforms": {
82
+ "android": "9.1.0",
83
+ "ios": "9.1.0"
84
+ }
85
+ },
86
+ "dependencies": {
87
+ "@nativescript/contacts": "3.0.0",
88
+ "@octane-xplat/platform": "0.0.0-nightly.gaffaece"
89
+ },
90
+ "scripts": {
91
+ "typegen": "tsrx-typegen --target octane",
92
+ "pack:check": "tsrx-typegen --pack-check",
93
+ "typecheck": "node ../../scripts/typecheck.ts"
94
+ }
95
+ }
@@ -0,0 +1,4 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <uses-permission android:name="android.permission.READ_CONTACTS" />
3
+ <uses-permission android:name="android.permission.WRITE_CONTACTS" />
4
+ </manifest>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>NSContactsUsageDescription</key>
6
+ <string>Contacts access is required to read and write the address book.</string>
7
+ </dict>
8
+ </plist>
@@ -0,0 +1,2 @@
1
+ // Linux's system webview runs the shared web implementation.
2
+ export { contacts } from './contacts.web'
@@ -0,0 +1,19 @@
1
+ // Contacts — macOS leaf. CNContactStore is bridgeable through the AppKit host
2
+ // but not yet wired; report unsupported rather than leaving a hole.
3
+ import type { Contacts, PermissionResult } from './types'
4
+
5
+ const unsupported = () => Promise.reject(new Error('unsupported: contacts is not wired on macOS'))
6
+
7
+ export const contacts: Contacts = {
8
+ supported: false,
9
+ ensure: async (): Promise<PermissionResult> => 'unsupported',
10
+ getAll: unsupported,
11
+ getByName: unsupported,
12
+ getById: unsupported,
13
+ add: unsupported,
14
+ update: unsupported,
15
+ remove: unsupported,
16
+ }
17
+
18
+ const permissionOwners = ((globalThis as any).__xplatPermissionOwners ??= {})
19
+ permissionOwners.contacts = () => contacts.ensure()
@@ -0,0 +1,251 @@
1
+ // Contacts — native leaf over @nativescript/contacts. The plugin's worker
2
+ // fetch is normalized into our Expo-shaped Contact; permission goes through
3
+ // the platform primitives directly (same rationale as media's ensureCamera:
4
+ // plugin-side request helpers can't drift).
5
+ import { Application } from '@nativescript/core'
6
+ import { Contact as NativeContact, Contacts as NativeContacts } from '@nativescript/contacts'
7
+ import { android } from '@octane-xplat/platform/android'
8
+ import type {
9
+ Contact,
10
+ ContactAddress,
11
+ ContactField,
12
+ Contacts,
13
+ GetContactsOptions,
14
+ NewContact,
15
+ PermissionResult,
16
+ } from './types'
17
+
18
+ // iOS CNContactStore — outside the @nativescript/types default subset.
19
+ declare const CNContactStore: any
20
+ declare const CNEntityTypeContacts: number | undefined
21
+
22
+ const ALL_FIELDS: ContactField[] = [
23
+ 'name',
24
+ 'emails',
25
+ 'phoneNumbers',
26
+ 'addresses',
27
+ 'urls',
28
+ 'company',
29
+ 'note',
30
+ 'image',
31
+ 'nickname',
32
+ ]
33
+
34
+ // Our field names → the plugin's contactFields vocabulary.
35
+ const PLUGIN_FIELDS: Record<ContactField, string> = {
36
+ name: 'name',
37
+ emails: 'emailAddresses',
38
+ phoneNumbers: 'phoneNumbers',
39
+ addresses: 'postalAddresses',
40
+ urls: 'urls',
41
+ company: 'organization',
42
+ note: 'notes',
43
+ image: 'photo',
44
+ nickname: 'nickname',
45
+ }
46
+
47
+ function pluginFields(fields?: ContactField[]): string[] {
48
+ const wanted = fields ?? ALL_FIELDS
49
+ const mapped = wanted.map((f) => PLUGIN_FIELDS[f])
50
+ // The plugin reads `name` for the display string regardless of selection.
51
+ if (!mapped.includes('name')) {
52
+ mapped.push('name')
53
+ }
54
+ return mapped
55
+ }
56
+
57
+ function iosEnsure(): Promise<PermissionResult> {
58
+ const store = typeof CNContactStore === 'undefined' ? null : CNContactStore.new?.()
59
+ if (!store || typeof CNEntityTypeContacts === 'undefined') {
60
+ return Promise.resolve('unsupported')
61
+ }
62
+ // CNAuthorizationStatus: 0 notDetermined, 1 restricted, 2 denied, 3 authorized
63
+ const status = CNContactStore.authorizationStatusForEntityType(CNEntityTypeContacts)
64
+ if (status === 3) {
65
+ return Promise.resolve('granted')
66
+ }
67
+ if (status === 1 || status === 2) {
68
+ return Promise.resolve('denied')
69
+ }
70
+ return new Promise((resolve) => {
71
+ store.requestAccessForEntityTypeCompletionHandler(CNEntityTypeContacts, (granted: boolean) =>
72
+ resolve(granted ? 'granted' : 'denied'),
73
+ )
74
+ })
75
+ }
76
+
77
+ let contactRequestCode = 7719
78
+
79
+ function androidEnsure(): Promise<PermissionResult> {
80
+ const perm = 'android.permission.READ_CONTACTS'
81
+ const activity = Application.android.foregroundActivity ?? Application.android.startActivity
82
+ try {
83
+ if (
84
+ activity?.checkSelfPermission?.(perm) === android.content.pm.PackageManager.PERMISSION_GRANTED
85
+ ) {
86
+ return Promise.resolve('granted')
87
+ }
88
+ if (!activity) {
89
+ return Promise.resolve('denied')
90
+ }
91
+ return new Promise<PermissionResult>((resolve) => {
92
+ const requestCode = contactRequestCode++
93
+ const event = Application.android.activityRequestPermissionsEvent
94
+ const onResult = (args: any) => {
95
+ if (args.requestCode !== requestCode) {
96
+ return
97
+ }
98
+ Application.android.off(event, onResult)
99
+ resolve(
100
+ args.grantResults?.[0] === android.content.pm.PackageManager.PERMISSION_GRANTED
101
+ ? 'granted'
102
+ : 'denied',
103
+ )
104
+ }
105
+ Application.android.on(event, onResult)
106
+ try {
107
+ activity.requestPermissions([perm], requestCode)
108
+ } catch {
109
+ Application.android.off(event, onResult)
110
+ resolve('denied')
111
+ }
112
+ })
113
+ } catch {
114
+ return Promise.resolve('denied')
115
+ }
116
+ }
117
+
118
+ function asContact(native: any): Contact {
119
+ const collection = (list: any, key: string) =>
120
+ (list ?? []).map((c: any) => ({ label: c?.label, [key]: c?.value }))
121
+ const address = (list: any): ContactAddress[] =>
122
+ (list ?? []).map((c: any) => {
123
+ const v = c?.value ?? {}
124
+ return {
125
+ label: c?.label,
126
+ street: v.street ?? v.Street,
127
+ city: v.city ?? v.City,
128
+ region: v.state ?? v.State ?? v.region,
129
+ postalCode: v.postalCode ?? v.postcode ?? v.PostalCode,
130
+ country: v.country ?? v.Country,
131
+ }
132
+ })
133
+ const given = native?.name?.given
134
+ const family = native?.name?.family
135
+ return {
136
+ id: String(native?.id ?? ''),
137
+ name: native?.name?.displayname ?? [given, family].filter(Boolean).join(' ') ?? '',
138
+ firstName: given,
139
+ middleName: native?.name?.middle,
140
+ lastName: family,
141
+ nickname: native?.nickname,
142
+ emails: collection(native?.emailAddresses, 'email'),
143
+ phoneNumbers: collection(native?.phoneNumbers, 'number'),
144
+ addresses: address(native?.postalAddresses),
145
+ urls: collection(native?.urls, 'url'),
146
+ company: native?.organization?.name,
147
+ jobTitle: native?.organization?.jobTitle,
148
+ note: native?.notes,
149
+ image: native?.photo,
150
+ }
151
+ }
152
+
153
+ function applySort(list: Contact[], sort?: GetContactsOptions['sort']): Contact[] {
154
+ if (!sort || sort === 'none') {
155
+ return list
156
+ }
157
+ const key = sort === 'firstName' ? 'firstName' : 'lastName'
158
+ return [...list].sort((a, b) => (a[key] ?? a.name).localeCompare(b[key] ?? b.name))
159
+ }
160
+
161
+ function applyPage(list: Contact[], options?: GetContactsOptions): Contact[] {
162
+ const start = options?.pageOffset ?? 0
163
+ const size = options?.pageSize
164
+ return size === undefined ? list.slice(start) : list.slice(start, start + size)
165
+ }
166
+
167
+ function applyNewContact(target: any, source: NewContact): void {
168
+ // The plugin's save() reads every name member incl. phonetic — unset
169
+ // members are native crashes, not omissions.
170
+ target.name = {
171
+ given: source.firstName ?? '',
172
+ middle: source.middleName ?? '',
173
+ family: source.lastName ?? '',
174
+ prefix: '',
175
+ suffix: '',
176
+ phonetic: { given: '', middle: '', family: '' },
177
+ }
178
+ target.nickname = source.nickname
179
+ target.notes = source.note
180
+ if (source.company || source.jobTitle) {
181
+ target.organization = { name: source.company, jobTitle: source.jobTitle }
182
+ }
183
+ target.emailAddresses = (source.emails ?? []).map((e) => ({ label: e.label, value: e.email }))
184
+ target.phoneNumbers = (source.phoneNumbers ?? []).map((p) => ({
185
+ label: p.label,
186
+ value: p.number,
187
+ }))
188
+ // save() also maps postalAddresses/urls unconditionally.
189
+ target.postalAddresses = []
190
+ target.urls = []
191
+ target.photo = null
192
+ }
193
+
194
+ export const contacts: Contacts = {
195
+ supported: true,
196
+
197
+ ensure(): Promise<PermissionResult> {
198
+ return Application.ios ? iosEnsure() : androidEnsure()
199
+ },
200
+
201
+ async getAll(options?: GetContactsOptions): Promise<Contact[]> {
202
+ const result = await NativeContacts.getAllContacts(pluginFields(options?.fields))
203
+ return applyPage(applySort((result?.data ?? []).map(asContact), options?.sort), options)
204
+ },
205
+
206
+ async getByName(predicate: string, fields?: ContactField[]): Promise<Contact[]> {
207
+ const result = await NativeContacts.getContactsByName(predicate, pluginFields(fields))
208
+ return (result?.data ?? []).map(asContact)
209
+ },
210
+
211
+ async getById(id: string, fields?: ContactField[]): Promise<Contact | null> {
212
+ if (Application.ios) {
213
+ const result = await NativeContacts.getContactById(id, pluginFields(fields))
214
+ const native = result?.data ?? result
215
+ return native ? asContact(native) : null
216
+ }
217
+ // Plugin ships getContactById for iOS only — full-store fetch + filter.
218
+ const result = await NativeContacts.getAllContactsWithoutWorker(pluginFields(fields))
219
+ const native = (result?.data ?? []).find((c: any) => String(c?.id) === id)
220
+ return native ? asContact(native) : null
221
+ },
222
+
223
+ async add(contact: NewContact): Promise<string> {
224
+ const native = new (NativeContact as any)()
225
+ applyNewContact(native, contact)
226
+ native.save()
227
+ return String(native.id ?? '')
228
+ },
229
+
230
+ async update(id: string, contact: NewContact): Promise<string> {
231
+ const existing = await contacts.getById(id)
232
+ if (!existing) {
233
+ throw new Error(`contacts.update: no contact with id ${id}`)
234
+ }
235
+ const native = new (NativeContact as any)()
236
+ native.id = id
237
+ applyNewContact(native, contact)
238
+ native.save()
239
+ return id
240
+ },
241
+
242
+ async remove(id: string): Promise<void> {
243
+ const native = new (NativeContact as any)()
244
+ native.id = id
245
+ native.delete()
246
+ },
247
+ }
248
+
249
+ // Register the permission kind this leaf owns for the platform dispatcher.
250
+ const permissionOwners = ((globalThis as any).__xplatPermissionOwners ??= {})
251
+ permissionOwners.contacts = () => contacts.ensure()
@@ -0,0 +1,55 @@
1
+ // Contacts — web leaf over the Contact Picker API. Chromium-only, picker UX
2
+ // (the user picks contacts per call — there is no store scan), read-only,
3
+ // and limited to name/email/tel fields. Everything the picker can't express
4
+ // reports unsupported rather than faking a store.
5
+ import type { Contact, Contacts, GetContactsOptions, NewContact, PermissionResult } from './types'
6
+
7
+ interface ContactPicker {
8
+ select(properties: string[], options?: { multiple?: boolean }): Promise<any[]>
9
+ getProperties(): Promise<string[]>
10
+ }
11
+
12
+ const picker = (): ContactPicker | null => {
13
+ const nav = (globalThis as any).navigator
14
+ return typeof nav?.contacts?.select === 'function' ? (nav.contacts as ContactPicker) : null
15
+ }
16
+
17
+ function asContact(native: any): Contact {
18
+ return {
19
+ id: '',
20
+ name: Array.isArray(native?.name) ? native.name.join(' ') : (native?.name ?? ''),
21
+ emails: (native?.email ?? []).map((e: string) => ({ email: e })),
22
+ phoneNumbers: (native?.tel ?? []).map((t: string) => ({ number: t })),
23
+ }
24
+ }
25
+
26
+ const unsupported = (what: string) => () =>
27
+ Promise.reject(new Error(`unsupported: contact ${what} is not available through the web Contact Picker`))
28
+
29
+ export const contacts: Contacts = {
30
+ supported: picker() !== null,
31
+
32
+ // The picker has no permission state to query — choosing contacts IS the
33
+ // grant. Report granted when the API exists so apps don't gate on it.
34
+ ensure(): Promise<PermissionResult> {
35
+ return Promise.resolve(picker() ? 'granted' : 'unsupported')
36
+ },
37
+
38
+ async getAll(options?: GetContactsOptions): Promise<Contact[]> {
39
+ const p = picker()
40
+ if (!p) {
41
+ throw new Error('unsupported: navigator.contacts.select is not available')
42
+ }
43
+ const selected = await p.select(['name', 'email', 'tel'], { multiple: true })
44
+ return (selected ?? []).map(asContact)
45
+ },
46
+
47
+ getByName: unsupported('lookup'),
48
+ getById: unsupported('lookup'),
49
+ add: (_contact: NewContact) => unsupported('writes')(),
50
+ update: (_id: string, _contact: NewContact) => unsupported('writes')(),
51
+ remove: unsupported('writes'),
52
+ }
53
+
54
+ const permissionOwners = ((globalThis as any).__xplatPermissionOwners ??= {})
55
+ permissionOwners.contacts = () => contacts.ensure()
@@ -0,0 +1,19 @@
1
+ // Windows leaf — @nativescript/contacts ships no windows backend; report
2
+ // unsupported rather than breaking the import graph.
3
+ import type { Contacts, PermissionResult } from './types'
4
+
5
+ const unsupported = () => Promise.reject(new Error('unsupported: contacts is not available on windows'))
6
+
7
+ export const contacts: Contacts = {
8
+ supported: false,
9
+ ensure: async (): Promise<PermissionResult> => 'unsupported',
10
+ getAll: unsupported,
11
+ getByName: unsupported,
12
+ getById: unsupported,
13
+ add: unsupported,
14
+ update: unsupported,
15
+ remove: unsupported,
16
+ }
17
+
18
+ const permissionOwners = ((globalThis as any).__xplatPermissionOwners ??= {})
19
+ permissionOwners.contacts = () => contacts.ensure()
@@ -0,0 +1,2 @@
1
+ export * from './types'
2
+ export { contacts } from './contacts.macos'
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './types'
2
+ export { contacts } from './contacts'
@@ -0,0 +1,2 @@
1
+ export * from './types'
2
+ export { contacts } from './contacts.web'
package/src/types.ts ADDED
@@ -0,0 +1,97 @@
1
+ export type PermissionResult = 'granted' | 'denied' | 'unsupported'
2
+
3
+ /** Fields the app asks for — a superset is fetched natively, this selects
4
+ * which members are populated on the returned Contact. */
5
+ export type ContactField =
6
+ | 'name'
7
+ | 'emails'
8
+ | 'phoneNumbers'
9
+ | 'addresses'
10
+ | 'urls'
11
+ | 'company'
12
+ | 'note'
13
+ | 'image'
14
+ | 'nickname'
15
+
16
+ export interface ContactEmail {
17
+ label?: string
18
+ email: string
19
+ }
20
+
21
+ export interface ContactPhone {
22
+ label?: string
23
+ number: string
24
+ }
25
+
26
+ export interface ContactAddress {
27
+ label?: string
28
+ street?: string
29
+ city?: string
30
+ region?: string
31
+ postalCode?: string
32
+ country?: string
33
+ }
34
+
35
+ export interface ContactUrl {
36
+ label?: string
37
+ url: string
38
+ }
39
+
40
+ export interface Contact {
41
+ id: string
42
+ /** Display name — falls back to composed given/family when the store
43
+ * lacks a display string. */
44
+ name: string
45
+ firstName?: string
46
+ middleName?: string
47
+ lastName?: string
48
+ nickname?: string
49
+ emails?: ContactEmail[]
50
+ phoneNumbers?: ContactPhone[]
51
+ addresses?: ContactAddress[]
52
+ urls?: ContactUrl[]
53
+ company?: string
54
+ jobTitle?: string
55
+ note?: string
56
+ /** Platform image reference when 'image' was requested — a file path or
57
+ * data reference; shape is platform-dependent. */
58
+ image?: unknown
59
+ }
60
+
61
+ export interface NewContact {
62
+ firstName?: string
63
+ middleName?: string
64
+ lastName?: string
65
+ nickname?: string
66
+ emails?: ContactEmail[]
67
+ phoneNumbers?: ContactPhone[]
68
+ company?: string
69
+ jobTitle?: string
70
+ note?: string
71
+ }
72
+
73
+ export interface GetContactsOptions {
74
+ /** Restrict which members are populated (all fetched by default). */
75
+ fields?: ContactField[]
76
+ /** Client-side sort — the native stores return an unspecified order. */
77
+ sort?: 'firstName' | 'lastName' | 'none'
78
+ pageSize?: number
79
+ pageOffset?: number
80
+ }
81
+
82
+ export interface Contacts {
83
+ readonly supported: boolean
84
+ /** Ensure the contacts permission without prompting twice — returns the
85
+ * post-request grant state, 'unsupported' when the store can't be reached. */
86
+ ensure(): Promise<PermissionResult>
87
+ getAll(options?: GetContactsOptions): Promise<Contact[]>
88
+ getByName(predicate: string, fields?: ContactField[]): Promise<Contact[]>
89
+ /** iOS: direct id fetch. Android: the plugin ships no id lookup, so this
90
+ * fetches the full store and filters — read-all cost, call sparingly. */
91
+ getById(id: string, fields?: ContactField[]): Promise<Contact | null>
92
+ add(contact: NewContact): Promise<string>
93
+ update(id: string, contact: NewContact): Promise<string>
94
+ remove(id: string): Promise<void>
95
+ }
96
+
97
+ export declare const contacts: Contacts
@@ -0,0 +1,14 @@
1
+ {
2
+ "version": 1,
3
+ "files": [
4
+ "contacts.d.ts",
5
+ "contacts.linux.d.ts",
6
+ "contacts.macos.d.ts",
7
+ "contacts.web.d.ts",
8
+ "contacts.windows.d.ts",
9
+ "index.d.ts",
10
+ "index.macos.d.ts",
11
+ "index.web.d.ts",
12
+ "types.d.ts"
13
+ ]
14
+ }
@@ -0,0 +1,2 @@
1
+ import type { Contacts } from './types.js';
2
+ export declare const contacts: Contacts;
@@ -0,0 +1 @@
1
+ export { contacts } from './contacts.web.js';
@@ -0,0 +1,2 @@
1
+ import type { Contacts } from './types.js';
2
+ export declare const contacts: Contacts;
@@ -0,0 +1,2 @@
1
+ import type { Contacts } from './types.js';
2
+ export declare const contacts: Contacts;
@@ -0,0 +1,2 @@
1
+ import type { Contacts } from './types.js';
2
+ export declare const contacts: Contacts;
@@ -0,0 +1,2 @@
1
+ export * from './types.js';
2
+ export { contacts } from './contacts.js';
@@ -0,0 +1,2 @@
1
+ export * from './types.js';
2
+ export { contacts } from './contacts.macos.js';
@@ -0,0 +1,2 @@
1
+ export * from './types.js';
2
+ export { contacts } from './contacts.web.js';
@@ -0,0 +1,78 @@
1
+ export type PermissionResult = 'granted' | 'denied' | 'unsupported';
2
+ /** Fields the app asks for — a superset is fetched natively, this selects
3
+ * which members are populated on the returned Contact. */
4
+ export type ContactField = 'name' | 'emails' | 'phoneNumbers' | 'addresses' | 'urls' | 'company' | 'note' | 'image' | 'nickname';
5
+ export interface ContactEmail {
6
+ label?: string;
7
+ email: string;
8
+ }
9
+ export interface ContactPhone {
10
+ label?: string;
11
+ number: string;
12
+ }
13
+ export interface ContactAddress {
14
+ label?: string;
15
+ street?: string;
16
+ city?: string;
17
+ region?: string;
18
+ postalCode?: string;
19
+ country?: string;
20
+ }
21
+ export interface ContactUrl {
22
+ label?: string;
23
+ url: string;
24
+ }
25
+ export interface Contact {
26
+ id: string;
27
+ /** Display name — falls back to composed given/family when the store
28
+ * lacks a display string. */
29
+ name: string;
30
+ firstName?: string;
31
+ middleName?: string;
32
+ lastName?: string;
33
+ nickname?: string;
34
+ emails?: ContactEmail[];
35
+ phoneNumbers?: ContactPhone[];
36
+ addresses?: ContactAddress[];
37
+ urls?: ContactUrl[];
38
+ company?: string;
39
+ jobTitle?: string;
40
+ note?: string;
41
+ /** Platform image reference when 'image' was requested — a file path or
42
+ * data reference; shape is platform-dependent. */
43
+ image?: unknown;
44
+ }
45
+ export interface NewContact {
46
+ firstName?: string;
47
+ middleName?: string;
48
+ lastName?: string;
49
+ nickname?: string;
50
+ emails?: ContactEmail[];
51
+ phoneNumbers?: ContactPhone[];
52
+ company?: string;
53
+ jobTitle?: string;
54
+ note?: string;
55
+ }
56
+ export interface GetContactsOptions {
57
+ /** Restrict which members are populated (all fetched by default). */
58
+ fields?: ContactField[];
59
+ /** Client-side sort — the native stores return an unspecified order. */
60
+ sort?: 'firstName' | 'lastName' | 'none';
61
+ pageSize?: number;
62
+ pageOffset?: number;
63
+ }
64
+ export interface Contacts {
65
+ readonly supported: boolean;
66
+ /** Ensure the contacts permission without prompting twice — returns the
67
+ * post-request grant state, 'unsupported' when the store can't be reached. */
68
+ ensure(): Promise<PermissionResult>;
69
+ getAll(options?: GetContactsOptions): Promise<Contact[]>;
70
+ getByName(predicate: string, fields?: ContactField[]): Promise<Contact[]>;
71
+ /** iOS: direct id fetch. Android: the plugin ships no id lookup, so this
72
+ * fetches the full store and filters — read-all cost, call sparingly. */
73
+ getById(id: string, fields?: ContactField[]): Promise<Contact | null>;
74
+ add(contact: NewContact): Promise<string>;
75
+ update(id: string, contact: NewContact): Promise<string>;
76
+ remove(id: string): Promise<void>;
77
+ }
78
+ export declare const contacts: Contacts;