@octane-xplat/contacts 0.0.0-nightly.g1b95ef7

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 ADDED
@@ -0,0 +1,5 @@
1
+ # @octane-xplat/contacts
2
+
3
+ [Documentation](https://octane-xplat.goddardai.org/package-contacts).
4
+
5
+ [API reference](https://octane-xplat.goddardai.org/api-contacts).
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "@octane-xplat/contacts",
3
+ "version": "0.0.0-nightly.g1b95ef7",
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
+ "types": "./types/generated/index.d.ts",
32
+ "macos": "./src/index.macos.ts",
33
+ "web": "./src/index.web.ts",
34
+ "native": "./src/index.ts",
35
+ "default": "./src/index.ts"
36
+ },
37
+ "./*": {
38
+ "types": "./types/generated/*.d.ts",
39
+ "default": "./src/*"
40
+ },
41
+ "./*.ts": {
42
+ "types": "./types/generated/*.d.ts",
43
+ "default": "./src/*.ts"
44
+ }
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "scripts": {
50
+ "typegen": "tsrx-typegen --target octane",
51
+ "prepack": "bun run typegen && tsrx-typegen --pack-check",
52
+ "pack:check": "tsrx-typegen --pack-check",
53
+ "typecheck": "node ../../scripts/typecheck.ts",
54
+ "test": "node --test tests/*.test.ts"
55
+ },
56
+ "devDependencies": {
57
+ "@octane-xplat/nativescript-octane": "0.0.0-nightly.g1b95ef7",
58
+ "@nativescript/core": "9.1.3",
59
+ "@nativescript/types": "9.1.4",
60
+ "octane": "0.23.2",
61
+ "tsrx-typegen": "0.6.2",
62
+ "typescript": "7.1.0-dev.20261121.1",
63
+ "@tsrx/content-mapper": "0.1.2"
64
+ },
65
+ "peerDependencies": {
66
+ "@octane-xplat/nativescript-octane": "0.0.0-nightly.g1b95ef7",
67
+ "@nativescript/core": ">=9.1.0 <10",
68
+ "octane": ">=0.6.3 <1"
69
+ },
70
+ "peerDependenciesMeta": {
71
+ "@octane-xplat/nativescript-octane": {
72
+ "optional": true
73
+ },
74
+ "@nativescript/core": {
75
+ "optional": true
76
+ }
77
+ },
78
+ "nativescript": {
79
+ "platforms": {
80
+ "android": "9.1.0",
81
+ "ios": "9.1.0"
82
+ }
83
+ },
84
+ "dependencies": {
85
+ "@nativescript/contacts": "3.0.0",
86
+ "@octane-xplat/platform": "0.0.0-nightly.g1b95ef7"
87
+ }
88
+ }
@@ -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,85 @@
1
+ import { Application } from '@nativescript/core'
2
+ import { Contact as NativeContact, Contacts as NativeContacts } from '@nativescript/contacts'
3
+ import type { PermissionStatus } from '@octane-xplat/platform'
4
+ import { android } from '@octane-xplat/platform/android'
5
+ import type { ContactFetchResult, NativeContactHandle } from './contacts-store.mobile'
6
+ import type { PermissionResult } from './types'
7
+
8
+ let contactRequestCode = 7719
9
+
10
+ export function contactsPermissionStatus(): PermissionStatus {
11
+ const activity = Application.android.foregroundActivity ?? Application.android.startActivity
12
+
13
+ // Android can't distinguish never-asked from denied without the rationale
14
+ // hook — report undetermined and let request resolve it.
15
+ return activity?.checkSelfPermission?.('android.permission.READ_CONTACTS') ===
16
+ android.content.pm.PackageManager.PERMISSION_GRANTED
17
+ ? 'granted'
18
+ : 'undetermined'
19
+ }
20
+
21
+ export function ensureContactsPermission(): Promise<PermissionResult> {
22
+ const perm = 'android.permission.READ_CONTACTS'
23
+ const activity = Application.android.foregroundActivity ?? Application.android.startActivity
24
+
25
+ try {
26
+ if (
27
+ activity?.checkSelfPermission?.(perm) === android.content.pm.PackageManager.PERMISSION_GRANTED
28
+ ) {
29
+ return Promise.resolve('granted')
30
+ }
31
+
32
+ if (!activity) {
33
+ return Promise.resolve('denied')
34
+ }
35
+
36
+ return new Promise<PermissionResult>((resolve) => {
37
+ const requestCode = contactRequestCode++
38
+ const event = Application.android.activityRequestPermissionsEvent
39
+ const onResult = (args: any) => {
40
+ if (args.requestCode !== requestCode) {
41
+ return
42
+ }
43
+
44
+ Application.android.off(event, onResult)
45
+ resolve(
46
+ args.grantResults?.[0] === android.content.pm.PackageManager.PERMISSION_GRANTED
47
+ ? 'granted'
48
+ : 'denied',
49
+ )
50
+ }
51
+
52
+ Application.android.on(event, onResult)
53
+ try {
54
+ activity.requestPermissions([perm], requestCode)
55
+ } catch {
56
+ Application.android.off(event, onResult)
57
+ resolve('denied')
58
+ }
59
+ })
60
+ } catch {
61
+ return Promise.resolve('denied')
62
+ }
63
+ }
64
+
65
+ export async function fetchContacts(fields: string[]): Promise<ContactFetchResult> {
66
+ return (await NativeContacts.getAllContacts(fields)) as ContactFetchResult
67
+ }
68
+
69
+ export async function fetchContactsByName(
70
+ predicate: string,
71
+ fields: string[],
72
+ ): Promise<ContactFetchResult> {
73
+ return (await NativeContacts.getContactsByName(predicate, fields)) as ContactFetchResult
74
+ }
75
+
76
+ export async function fetchContactById(id: string, fields: string[]): Promise<any> {
77
+ // Plugin ships getContactById for iOS only — full-store fetch + filter.
78
+ const result = (await NativeContacts.getAllContactsWithoutWorker(fields)) as ContactFetchResult
79
+
80
+ return (result?.data ?? []).find((c: any) => String(c?.id) === id) ?? null
81
+ }
82
+
83
+ export function createNativeContact(): NativeContactHandle {
84
+ return new (NativeContact as any)()
85
+ }
@@ -0,0 +1,65 @@
1
+ import { Contact as NativeContact, Contacts as NativeContacts } from '@nativescript/contacts'
2
+ import type { PermissionStatus } from '@octane-xplat/platform'
3
+ import type { ContactFetchResult, NativeContactHandle } from './contacts-store.mobile'
4
+ import type { PermissionResult } from './types'
5
+
6
+ // iOS CNContactStore — outside the @nativescript/types default subset.
7
+ declare const CNContactStore: any
8
+ declare const CNEntityTypeContacts: number | undefined
9
+
10
+ export function contactsPermissionStatus(): PermissionStatus {
11
+ if (typeof CNContactStore === 'undefined' || typeof CNEntityTypeContacts === 'undefined') {
12
+ return 'unsupported'
13
+ }
14
+
15
+ // CNAuthorizationStatus: 0 notDetermined, 1 restricted, 2 denied, 3 authorized
16
+ const status = CNContactStore.authorizationStatusForEntityType(CNEntityTypeContacts)
17
+
18
+ return status === 3 ? 'granted' : status === 0 ? 'undetermined' : 'denied'
19
+ }
20
+
21
+ export function ensureContactsPermission(): Promise<PermissionResult> {
22
+ const store = typeof CNContactStore === 'undefined' ? null : CNContactStore.new?.()
23
+
24
+ if (!store || typeof CNEntityTypeContacts === 'undefined') {
25
+ return Promise.resolve('unsupported')
26
+ }
27
+
28
+ // CNAuthorizationStatus: 0 notDetermined, 1 restricted, 2 denied, 3 authorized
29
+ const status = CNContactStore.authorizationStatusForEntityType(CNEntityTypeContacts)
30
+
31
+ if (status === 3) {
32
+ return Promise.resolve('granted')
33
+ }
34
+
35
+ if (status === 1 || status === 2) {
36
+ return Promise.resolve('denied')
37
+ }
38
+
39
+ return new Promise((resolve) => {
40
+ store.requestAccessForEntityTypeCompletionHandler(CNEntityTypeContacts, (granted: boolean) =>
41
+ resolve(granted ? 'granted' : 'denied'),
42
+ )
43
+ })
44
+ }
45
+
46
+ export async function fetchContacts(fields: string[]): Promise<ContactFetchResult> {
47
+ return (await NativeContacts.getAllContacts(fields)) as ContactFetchResult
48
+ }
49
+
50
+ export async function fetchContactsByName(
51
+ predicate: string,
52
+ fields: string[],
53
+ ): Promise<ContactFetchResult> {
54
+ return (await NativeContacts.getContactsByName(predicate, fields)) as ContactFetchResult
55
+ }
56
+
57
+ export async function fetchContactById(id: string, fields: string[]): Promise<any> {
58
+ const result = await NativeContacts.getContactById(id, fields)
59
+
60
+ return (result as ContactFetchResult)?.data ?? result
61
+ }
62
+
63
+ export function createNativeContact(): NativeContactHandle {
64
+ return new (NativeContact as any)()
65
+ }
@@ -0,0 +1,13 @@
1
+ // Shared contract for the contacts-store platform leaves. The
2
+ // @nativescript/contacts plugin surfaces differ per platform (getContactById
3
+ // is iOS-only, getAllContactsWithoutWorker Android-only) and both declare
4
+ // Promise<unknown>, so the leaves own every plugin call and bind the result
5
+ // to these shapes at the boundary.
6
+
7
+ /** Result the plugin's worker fetches resolve with. */
8
+ export interface ContactFetchResult {
9
+ data?: any[]
10
+ }
11
+
12
+ /** Unsaved native contact instance returned by create(). */
13
+ export type NativeContactHandle = any
@@ -0,0 +1,2 @@
1
+ // Linux's system webview runs the shared web implementation.
2
+ export { contacts } from './contacts.web'
@@ -0,0 +1,383 @@
1
+ // Contacts — AppKit leaf over CNContactStore. The Contacts framework is
2
+ // bridgeable through the JSC host; semantics mirror the iOS leaf.
3
+ // CNContactNoteKey requires a contacts-notes entitlement even on macOS —
4
+ // it is excluded from fetch keys and `note` stays absent unless the store
5
+ // reports the key available.
6
+ import {
7
+ CNContact,
8
+ CNContactFetchRequest,
9
+ CNContactIdentifierKey,
10
+ CNContactEmailAddressesKey,
11
+ CNContactFamilyNameKey,
12
+ CNContactGivenNameKey,
13
+ CNContactImageDataKey,
14
+ CNContactJobTitleKey,
15
+ CNContactMiddleNameKey,
16
+ CNContactNicknameKey,
17
+ CNContactNoteKey,
18
+ CNContactOrganizationNameKey,
19
+ CNContactPhoneNumbersKey,
20
+ CNContactPostalAddressesKey,
21
+ CNContactStore,
22
+ CNContactUrlAddressesKey,
23
+ CNEntityType,
24
+ CNLabeledValue,
25
+ CNMutableContact,
26
+ CNPhoneNumber,
27
+ CNSaveRequest,
28
+ } from '@octane-xplat/platform/macos'
29
+
30
+ import type {
31
+ Contact,
32
+ ContactAddress,
33
+ ContactField,
34
+ Contacts,
35
+ GetContactsOptions,
36
+ NewContact,
37
+ PermissionResult,
38
+ } from './types'
39
+
40
+ let store: any = null
41
+ const contactStore = () => {
42
+ if (store) {
43
+ return store
44
+ }
45
+
46
+ try {
47
+ if (typeof CNContactStore?.authorizationStatusForEntityType !== 'function') {
48
+ return null
49
+ }
50
+
51
+ return (store = CNContactStore.new())
52
+ } catch {
53
+ return null
54
+ }
55
+ }
56
+
57
+ // CNAuthorizationStatus: 0 notDetermined 1 restricted 2 denied 3 authorized
58
+ const rawStatus = () =>
59
+ Number(CNContactStore.authorizationStatusForEntityType(CNEntityType.CNEntityTypeContacts ?? 0))
60
+
61
+ function ensureAccess(): Promise<PermissionResult> {
62
+ const s = contactStore()
63
+
64
+ if (!s) {
65
+ return Promise.resolve('unsupported')
66
+ }
67
+
68
+ const status = rawStatus()
69
+
70
+ if (status === 3) {
71
+ return Promise.resolve('granted')
72
+ }
73
+
74
+ if (status === 1 || status === 2) {
75
+ return Promise.resolve('denied')
76
+ }
77
+
78
+ return new Promise((resolve) => {
79
+ s.requestAccessForEntityTypeCompletionHandler(
80
+ CNEntityType.CNEntityTypeContacts ?? 0,
81
+ (granted: boolean) => resolve(granted ? 'granted' : 'denied'),
82
+ )
83
+ })
84
+ }
85
+
86
+ const BASE_KEYS = [
87
+ CNContactIdentifierKey,
88
+ CNContactGivenNameKey,
89
+ CNContactMiddleNameKey,
90
+ CNContactFamilyNameKey,
91
+ CNContactNicknameKey,
92
+ ]
93
+
94
+ const FIELD_KEYS: Record<Exclude<ContactField, 'name'>, string[]> = {
95
+ emails: [CNContactEmailAddressesKey],
96
+ phoneNumbers: [CNContactPhoneNumbersKey],
97
+ addresses: [CNContactPostalAddressesKey],
98
+ urls: [CNContactUrlAddressesKey],
99
+ company: [CNContactOrganizationNameKey, CNContactJobTitleKey],
100
+ note: [], // entitlement-gated on macOS too — read only when the key is available
101
+ image: [CNContactImageDataKey],
102
+ nickname: [],
103
+ }
104
+
105
+ function fetchKeys(fields?: ContactField[]): string[] {
106
+ const keys = [...BASE_KEYS]
107
+
108
+ for (const field of fields ?? (Object.keys(FIELD_KEYS) as ContactField[])) {
109
+ for (const key of FIELD_KEYS[field as keyof typeof FIELD_KEYS] ?? []) {
110
+ if (!keys.includes(key)) {
111
+ keys.push(key)
112
+ }
113
+ }
114
+ }
115
+
116
+ return keys
117
+ }
118
+
119
+ const nsarray = (list: any): any[] => {
120
+ if (!list) {
121
+ return []
122
+ }
123
+
124
+ if (Array.isArray(list)) {
125
+ return list
126
+ }
127
+
128
+ const out: any[] = []
129
+
130
+ for (let i = 0, count = Number(list.count ?? 0); i < count; i++) {
131
+ out.push(list.objectAtIndex(i))
132
+ }
133
+
134
+ return out
135
+ }
136
+
137
+ const labeled = (list: any, value: (entry: any) => unknown) =>
138
+ nsarray(list).map((entry) => ({
139
+ label: entry?.label ? String(entry.label) : undefined,
140
+ value: value(entry),
141
+ }))
142
+
143
+ function asContact(native: any): Contact {
144
+ const firstName = native?.givenName ? String(native.givenName) : undefined
145
+ const lastName = native?.familyName ? String(native.familyName) : undefined
146
+ const name =
147
+ native?.name && typeof native.name === 'string'
148
+ ? native.name
149
+ : [firstName, lastName].filter(Boolean).join(' ') ||
150
+ (native?.organizationName ? String(native.organizationName) : '')
151
+
152
+ const contact: Contact = {
153
+ id: String(native?.identifier ?? ''),
154
+ name,
155
+ firstName,
156
+ middleName: native?.middleName ? String(native.middleName) : undefined,
157
+ lastName,
158
+ nickname: native?.nickname ? String(native.nickname) : undefined,
159
+ emails: labeled(native?.emailAddresses, (e) => String(e?.value ?? '')).map(
160
+ ({ label, value }) => ({ label, email: value as string }),
161
+ ),
162
+ phoneNumbers: labeled(native?.phoneNumbers, (e) => String(e?.value?.stringValue ?? '')).map(
163
+ ({ label, value }) => ({ label, number: value as string }),
164
+ ),
165
+ addresses: labeled(native?.postalAddresses, (e): ContactAddress => ({
166
+ street: e?.value?.street ? String(e.value.street) : undefined,
167
+ city: e?.value?.city ? String(e.value.city) : undefined,
168
+ region: e?.value?.state ? String(e.value.state) : undefined,
169
+ postalCode: e?.value?.postalCode ? String(e.value.postalCode) : undefined,
170
+ country: e?.value?.country ? String(e.value.country) : undefined,
171
+ })).map(({ label, value }) => ({ label, ...(value as ContactAddress) })),
172
+ urls: labeled(native?.urlAddresses, (e) => String(e?.value ?? '')).map(({ label, value }) => ({
173
+ label,
174
+ url: value as string,
175
+ })),
176
+ company: native?.organizationName ? String(native.organizationName) : undefined,
177
+ jobTitle: native?.jobTitle ? String(native.jobTitle) : undefined,
178
+ }
179
+
180
+ // The notes entitlement is a distribution choice; read it only when the
181
+ // fetched keys already carry it.
182
+ try {
183
+ if (native?.isKeyAvailable?.(CNContactNoteKey) && native?.note) {
184
+ contact.note = String(native.note)
185
+ }
186
+ } catch {
187
+ // A store without the notes entitlement leaves the field absent.
188
+ }
189
+
190
+ try {
191
+ if (native?.imageDataAvailable) {
192
+ const data = native?.imageData
193
+ const base64 = data?.base64EncodedStringWithOptions?.(0)
194
+
195
+ if (base64) {
196
+ contact.image = { data: String(base64) }
197
+ }
198
+ }
199
+ } catch {
200
+ // Unfetched or unreadable image data is omitted, never fatal.
201
+ }
202
+
203
+ return contact
204
+ }
205
+
206
+ function applySort(list: Contact[], sort?: GetContactsOptions['sort']): Contact[] {
207
+ if (!sort || sort === 'none') {
208
+ return list
209
+ }
210
+
211
+ const key = sort === 'firstName' ? 'firstName' : 'lastName'
212
+
213
+ return [...list].sort((a, b) => (a[key] ?? a.name).localeCompare(b[key] ?? b.name))
214
+ }
215
+
216
+ function applyPage(list: Contact[], options?: GetContactsOptions): Contact[] {
217
+ const start = options?.pageOffset ?? 0
218
+ const size = options?.pageSize
219
+
220
+ return size === undefined ? list.slice(start) : list.slice(start, start + size)
221
+ }
222
+
223
+ function requireStore(): any {
224
+ const s = contactStore()
225
+
226
+ if (!s) {
227
+ throw new Error('contacts: the Contacts store is unavailable on this host')
228
+ }
229
+
230
+ return s
231
+ }
232
+
233
+ function applyNewContact(target: any, source: NewContact): void {
234
+ target.givenName = source.firstName ?? ''
235
+ target.middleName = source.middleName ?? ''
236
+ target.familyName = source.lastName ?? ''
237
+ target.nickname = source.nickname ?? ''
238
+ target.organizationName = source.company ?? ''
239
+ target.jobTitle = source.jobTitle ?? ''
240
+ target.emailAddresses = (source.emails ?? []).map((e) =>
241
+ CNLabeledValue.labeledValueWithLabelValue(e.label ?? null, e.email),
242
+ )
243
+
244
+ target.phoneNumbers = (source.phoneNumbers ?? []).map((p) =>
245
+ CNLabeledValue.labeledValueWithLabelValue(
246
+ p.label ?? null,
247
+ CNPhoneNumber.phoneNumberWithStringValue(p.number),
248
+ ),
249
+ )
250
+ }
251
+
252
+ /** Contacts service — system address book. */
253
+ export const contacts: Contacts = {
254
+ get supported() {
255
+ return contactStore() !== null
256
+ },
257
+
258
+ ensure(): Promise<PermissionResult> {
259
+ return ensureAccess()
260
+ },
261
+
262
+ async getAll(options?: GetContactsOptions): Promise<Contact[]> {
263
+ const s = requireStore()
264
+ const request = CNContactFetchRequest.alloc().initWithKeysToFetch(fetchKeys(options?.fields))
265
+ const out: Contact[] = []
266
+
267
+ if (
268
+ !s.enumerateContactsWithFetchRequestErrorUsingBlock(request, null, (contact: any) => {
269
+ out.push(asContact(contact))
270
+ })
271
+ ) {
272
+ throw new Error('contacts.getAll: the store refused the fetch request')
273
+ }
274
+
275
+ return applyPage(applySort(out, options?.sort), options)
276
+ },
277
+
278
+ async getByName(predicate: string, fields?: ContactField[]): Promise<Contact[]> {
279
+ const s = requireStore()
280
+ const list = s.unifiedContactsMatchingPredicateKeysToFetchError(
281
+ CNContact.predicateForContactsMatchingName(predicate),
282
+ fetchKeys(fields),
283
+ null,
284
+ )
285
+
286
+ return nsarray(list).map(asContact)
287
+ },
288
+
289
+ async getById(id: string, fields?: ContactField[]): Promise<Contact | null> {
290
+ const s = requireStore()
291
+ const native = s.unifiedContactWithIdentifierKeysToFetchError(id, fetchKeys(fields), null)
292
+
293
+ return native ? asContact(native) : null
294
+ },
295
+
296
+ async add(contact: NewContact): Promise<string> {
297
+ const s = requireStore()
298
+ const native = CNMutableContact.new()
299
+
300
+ applyNewContact(native, contact)
301
+
302
+ const request = CNSaveRequest.new()
303
+
304
+ request.addContactToContainerWithIdentifier(native, null)
305
+ if (!s.executeSaveRequestError(request, null)) {
306
+ throw new Error('contacts.add: the store refused the save request')
307
+ }
308
+
309
+ return String(native.identifier ?? '')
310
+ },
311
+
312
+ async update(id: string, contact: NewContact): Promise<string> {
313
+ const s = requireStore()
314
+ const existing = s.unifiedContactWithIdentifierKeysToFetchError(id, fetchKeys(), null)
315
+
316
+ if (!existing) {
317
+ throw new Error(`contacts.update: no contact with id ${id}`)
318
+ }
319
+
320
+ const native = existing.mutableCopy()
321
+
322
+ applyNewContact(native, contact)
323
+
324
+ const request = CNSaveRequest.new()
325
+
326
+ request.updateContact(native)
327
+ if (!s.executeSaveRequestError(request, null)) {
328
+ throw new Error('contacts.update: the store refused the save request')
329
+ }
330
+
331
+ return id
332
+ },
333
+
334
+ async remove(id: string): Promise<void> {
335
+ const s = requireStore()
336
+ const existing = s.unifiedContactWithIdentifierKeysToFetchError(
337
+ id,
338
+ [CNContactIdentifierKey],
339
+ null,
340
+ )
341
+
342
+ if (!existing) {
343
+ return
344
+ }
345
+
346
+ const request = CNSaveRequest.new()
347
+
348
+ request.deleteContact(existing.mutableCopy())
349
+ if (!s.executeSaveRequestError(request, null)) {
350
+ throw new Error('contacts.remove: the store refused the save request')
351
+ }
352
+ },
353
+ }
354
+
355
+ const permissionOwners = ((globalThis as any).__xplatPermissionOwners ??= {})
356
+
357
+ permissionOwners.contacts = {
358
+ getPermissions: async () => {
359
+ const s = contactStore()
360
+
361
+ if (!s) {
362
+ return { status: 'unsupported' as const, granted: false, canAskAgain: false }
363
+ }
364
+
365
+ const status = rawStatus()
366
+
367
+ return {
368
+ status:
369
+ status === 3
370
+ ? ('granted' as const)
371
+ : status === 0
372
+ ? ('undetermined' as const)
373
+ : ('denied' as const),
374
+ granted: status === 3,
375
+ canAskAgain: status === 0 || status === 3,
376
+ }
377
+ },
378
+ requestPermissions: async () => {
379
+ const result = await contacts.ensure()
380
+
381
+ return { status: result, granted: result === 'granted', canAskAgain: result === 'granted' }
382
+ },
383
+ }
@@ -0,0 +1,217 @@
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). Plugin surfaces differ per
5
+ // platform, so every plugin call lives in the contacts-store leaves.
6
+ import {
7
+ contactsPermissionStatus,
8
+ createNativeContact,
9
+ ensureContactsPermission,
10
+ fetchContactById,
11
+ fetchContacts,
12
+ fetchContactsByName,
13
+ } from './contacts-store'
14
+ import type { PermissionStatus } from '@octane-xplat/platform'
15
+ import type {
16
+ Contact,
17
+ ContactAddress,
18
+ ContactField,
19
+ Contacts,
20
+ GetContactsOptions,
21
+ NewContact,
22
+ PermissionResult,
23
+ } from './types'
24
+
25
+ const ALL_FIELDS: ContactField[] = [
26
+ 'name',
27
+ 'emails',
28
+ 'phoneNumbers',
29
+ 'addresses',
30
+ 'urls',
31
+ 'company',
32
+ 'note',
33
+ 'image',
34
+ 'nickname',
35
+ ]
36
+
37
+ // Our field names → the plugin's contactFields vocabulary.
38
+ const PLUGIN_FIELDS: Record<ContactField, string> = {
39
+ name: 'name',
40
+ emails: 'emailAddresses',
41
+ phoneNumbers: 'phoneNumbers',
42
+ addresses: 'postalAddresses',
43
+ urls: 'urls',
44
+ company: 'organization',
45
+ note: 'notes',
46
+ image: 'photo',
47
+ nickname: 'nickname',
48
+ }
49
+
50
+ function pluginFields(fields?: ContactField[]): string[] {
51
+ const wanted = fields ?? ALL_FIELDS
52
+ const mapped = wanted.map((f) => PLUGIN_FIELDS[f])
53
+
54
+ // The plugin reads `name` for the display string regardless of selection.
55
+ if (!mapped.includes('name')) {
56
+ mapped.push('name')
57
+ }
58
+
59
+ return mapped
60
+ }
61
+
62
+ function asContact(native: any): Contact {
63
+ const collection = (list: any, key: string) =>
64
+ (list ?? []).map((c: any) => ({ label: c?.label, [key]: c?.value }))
65
+
66
+ const address = (list: any): ContactAddress[] =>
67
+ (list ?? []).map((c: any) => {
68
+ const v = c?.value ?? {}
69
+
70
+ return {
71
+ label: c?.label,
72
+ street: v.street ?? v.Street,
73
+ city: v.city ?? v.City,
74
+ region: v.state ?? v.State ?? v.region,
75
+ postalCode: v.postalCode ?? v.postcode ?? v.PostalCode,
76
+ country: v.country ?? v.Country,
77
+ }
78
+ })
79
+
80
+ const given = native?.name?.given
81
+ const family = native?.name?.family
82
+
83
+ return {
84
+ id: String(native?.id ?? ''),
85
+ name: native?.name?.displayname ?? [given, family].filter(Boolean).join(' ') ?? '',
86
+ firstName: given,
87
+ middleName: native?.name?.middle,
88
+ lastName: family,
89
+ nickname: native?.nickname,
90
+ emails: collection(native?.emailAddresses, 'email'),
91
+ phoneNumbers: collection(native?.phoneNumbers, 'number'),
92
+ addresses: address(native?.postalAddresses),
93
+ urls: collection(native?.urls, 'url'),
94
+ company: native?.organization?.name,
95
+ jobTitle: native?.organization?.jobTitle,
96
+ note: native?.notes,
97
+ image: native?.photo,
98
+ }
99
+ }
100
+
101
+ function applySort(list: Contact[], sort?: GetContactsOptions['sort']): Contact[] {
102
+ if (!sort || sort === 'none') {
103
+ return list
104
+ }
105
+
106
+ const key = sort === 'firstName' ? 'firstName' : 'lastName'
107
+
108
+ return [...list].sort((a, b) => (a[key] ?? a.name).localeCompare(b[key] ?? b.name))
109
+ }
110
+
111
+ function applyPage(list: Contact[], options?: GetContactsOptions): Contact[] {
112
+ const start = options?.pageOffset ?? 0
113
+ const size = options?.pageSize
114
+
115
+ return size === undefined ? list.slice(start) : list.slice(start, start + size)
116
+ }
117
+
118
+ function applyNewContact(target: any, source: NewContact): void {
119
+ // The plugin's save() reads every name member incl. phonetic — unset
120
+ // members are native crashes, not omissions.
121
+ target.name = {
122
+ given: source.firstName ?? '',
123
+ middle: source.middleName ?? '',
124
+ family: source.lastName ?? '',
125
+ prefix: '',
126
+ suffix: '',
127
+ phonetic: { given: '', middle: '', family: '' },
128
+ }
129
+
130
+ target.nickname = source.nickname
131
+ target.notes = source.note
132
+ if (source.company || source.jobTitle) {
133
+ target.organization = { name: source.company, jobTitle: source.jobTitle }
134
+ }
135
+
136
+ target.emailAddresses = (source.emails ?? []).map((e) => ({ label: e.label, value: e.email }))
137
+ target.phoneNumbers = (source.phoneNumbers ?? []).map((p) => ({
138
+ label: p.label,
139
+ value: p.number,
140
+ }))
141
+
142
+ // save() also maps postalAddresses/urls unconditionally.
143
+ target.postalAddresses = []
144
+ target.urls = []
145
+ target.photo = null
146
+ }
147
+
148
+ /** Contacts service — system address book. */
149
+ export const contacts: Contacts = {
150
+ supported: true,
151
+
152
+ ensure(): Promise<PermissionResult> {
153
+ return ensureContactsPermission()
154
+ },
155
+
156
+ async getAll(options?: GetContactsOptions): Promise<Contact[]> {
157
+ const result = await fetchContacts(pluginFields(options?.fields))
158
+
159
+ return applyPage(applySort((result?.data ?? []).map(asContact), options?.sort), options)
160
+ },
161
+
162
+ async getByName(predicate: string, fields?: ContactField[]): Promise<Contact[]> {
163
+ const result = await fetchContactsByName(predicate, pluginFields(fields))
164
+
165
+ return (result?.data ?? []).map(asContact)
166
+ },
167
+
168
+ async getById(id: string, fields?: ContactField[]): Promise<Contact | null> {
169
+ const native = await fetchContactById(id, pluginFields(fields))
170
+
171
+ return native ? asContact(native) : null
172
+ },
173
+
174
+ async add(contact: NewContact): Promise<string> {
175
+ const native = createNativeContact()
176
+
177
+ applyNewContact(native, contact)
178
+ native.save()
179
+ return String(native.id ?? '')
180
+ },
181
+
182
+ async update(id: string, contact: NewContact): Promise<string> {
183
+ const existing = await contacts.getById(id)
184
+
185
+ if (!existing) {
186
+ throw new Error(`contacts.update: no contact with id ${id}`)
187
+ }
188
+
189
+ const native = createNativeContact()
190
+
191
+ native.id = id
192
+ applyNewContact(native, contact)
193
+ native.save()
194
+ return id
195
+ },
196
+
197
+ async remove(id: string): Promise<void> {
198
+ const native = createNativeContact()
199
+
200
+ native.id = id
201
+ native.delete()
202
+ },
203
+ }
204
+
205
+ // Register the permission kind this leaf owns for the platform dispatcher.
206
+ const permissionOwners = ((globalThis as any).__xplatPermissionOwners ??= {})
207
+
208
+ const toResponse = (status: PermissionStatus) => ({
209
+ status,
210
+ granted: status === 'granted',
211
+ canAskAgain: status === 'granted' || status === 'undetermined',
212
+ })
213
+
214
+ permissionOwners.contacts = {
215
+ getPermissions: async () => toResponse(contactsPermissionStatus()),
216
+ requestPermissions: async () => toResponse(await contacts.ensure()),
217
+ }
@@ -0,0 +1,73 @@
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
+
15
+ return typeof nav?.contacts?.select === 'function' ? (nav.contacts as ContactPicker) : null
16
+ }
17
+
18
+ function asContact(native: any): Contact {
19
+ return {
20
+ id: '',
21
+ name: Array.isArray(native?.name) ? native.name.join(' ') : (native?.name ?? ''),
22
+ emails: (native?.email ?? []).map((e: string) => ({ email: e })),
23
+ phoneNumbers: (native?.tel ?? []).map((t: string) => ({ number: t })),
24
+ }
25
+ }
26
+
27
+ const unsupported = (what: string) => () =>
28
+ Promise.reject(
29
+ new Error(`unsupported: contact ${what} is not available through the web Contact Picker`),
30
+ )
31
+
32
+ /** Contacts service — system address book. */
33
+ export const contacts: Contacts = {
34
+ supported: picker() !== null,
35
+
36
+ // The picker has no permission state to query — choosing contacts IS the
37
+ // grant. Report granted when the API exists so apps don't gate on it.
38
+ ensure(): Promise<PermissionResult> {
39
+ return Promise.resolve(picker() ? 'granted' : 'unsupported')
40
+ },
41
+
42
+ async getAll(_options?: GetContactsOptions): Promise<Contact[]> {
43
+ const p = picker()
44
+
45
+ if (!p) {
46
+ throw new Error('unsupported: navigator.contacts.select is not available')
47
+ }
48
+
49
+ const selected = await p.select(['name', 'email', 'tel'], { multiple: true })
50
+
51
+ return (selected ?? []).map(asContact)
52
+ },
53
+
54
+ getByName: unsupported('lookup'),
55
+ getById: unsupported('lookup'),
56
+ add: (_contact: NewContact) => unsupported('writes')(),
57
+ update: (_id: string, _contact: NewContact) => unsupported('writes')(),
58
+ remove: unsupported('writes'),
59
+ }
60
+
61
+ const permissionOwners = ((globalThis as any).__xplatPermissionOwners ??= {})
62
+
63
+ const toResponse = (status: PermissionResult) => ({
64
+ status,
65
+ granted: status === 'granted',
66
+ canAskAgain: status === 'granted',
67
+ })
68
+
69
+ // The picker has no separate read — ensure() never prompts on this leaf.
70
+ permissionOwners.contacts = {
71
+ getPermissions: async () => toResponse(await contacts.ensure()),
72
+ requestPermissions: async () => toResponse(await contacts.ensure()),
73
+ }
@@ -0,0 +1,31 @@
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 = () =>
6
+ Promise.reject(new Error('unsupported: contacts is not available on windows'))
7
+
8
+ /** Contacts service — system address book. */
9
+ export const contacts: Contacts = {
10
+ supported: false,
11
+ ensure: async (): Promise<PermissionResult> => 'unsupported',
12
+ getAll: unsupported,
13
+ getByName: unsupported,
14
+ getById: unsupported,
15
+ add: unsupported,
16
+ update: unsupported,
17
+ remove: unsupported,
18
+ }
19
+
20
+ const permissionOwners = ((globalThis as any).__xplatPermissionOwners ??= {})
21
+
22
+ const toResponse = (status: PermissionResult) => ({
23
+ status,
24
+ granted: status === 'granted',
25
+ canAskAgain: status === 'granted',
26
+ })
27
+
28
+ permissionOwners.contacts = {
29
+ getPermissions: async () => toResponse(await contacts.ensure()),
30
+ requestPermissions: async () => toResponse(await contacts.ensure()),
31
+ }
@@ -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,147 @@
1
+ /** Coarse permission answer; unsupported means no contacts/permission path. */
2
+ export type PermissionResult = 'granted' | 'denied' | 'unsupported'
3
+
4
+ /** Fields the app asks for — a superset is fetched natively, this selects
5
+ * which members are populated on the returned Contact. */
6
+ export type ContactField =
7
+ | 'name'
8
+ | 'emails'
9
+ | 'phoneNumbers'
10
+ | 'addresses'
11
+ | 'urls'
12
+ | 'company'
13
+ | 'note'
14
+ | 'image'
15
+ | 'nickname'
16
+
17
+ /** One labeled email field. */
18
+ export interface ContactEmail {
19
+ /** Free-form label (home/work/custom) as stored. */
20
+ label?: string
21
+ /** Email address value. */
22
+ email: string
23
+ }
24
+
25
+ /** One labeled phone field. */
26
+ export interface ContactPhone {
27
+ /** Free-form label (home/work/custom) as stored. */
28
+ label?: string
29
+ /** Phone number string as stored. */
30
+ number: string
31
+ }
32
+
33
+ /** One labeled postal address. */
34
+ export interface ContactAddress {
35
+ /** Free-form label (home/work/custom) as stored. */
36
+ label?: string
37
+ /** Street line(s). */
38
+ street?: string
39
+ /** City. */
40
+ city?: string
41
+ /** State/province region. */
42
+ region?: string
43
+ /** Postal/ZIP code. */
44
+ postalCode?: string
45
+ /** Country name or code. */
46
+ country?: string
47
+ }
48
+
49
+ /** One labeled URL field. */
50
+ export interface ContactUrl {
51
+ /** Free-form label (home/work/custom) as stored. */
52
+ label?: string
53
+ /** URL value. */
54
+ url: string
55
+ }
56
+
57
+ /** A stored contact record. */
58
+ export interface Contact {
59
+ /** Store-assigned contact id. */
60
+ id: string
61
+ /** Display name — falls back to composed given/family when the store
62
+ * lacks a display string. */
63
+ name: string
64
+ /** Given name. */
65
+ firstName?: string
66
+ /** Middle name(s). */
67
+ middleName?: string
68
+ /** Family name. */
69
+ lastName?: string
70
+ /** Nickname. */
71
+ nickname?: string
72
+ /** Email addresses with labels. */
73
+ emails?: ContactEmail[]
74
+ /** Phone numbers with labels. */
75
+ phoneNumbers?: ContactPhone[]
76
+ /** Postal addresses with labels. */
77
+ addresses?: ContactAddress[]
78
+ /** Associated URLs with labels. */
79
+ urls?: ContactUrl[]
80
+ /** Organization name. */
81
+ company?: string
82
+ /** Role within the organization. */
83
+ jobTitle?: string
84
+ /** Free-text note field. */
85
+ note?: string
86
+ /** Platform image reference when 'image' was requested — a file path or
87
+ * data reference; shape is platform-dependent. */
88
+ image?: unknown
89
+ }
90
+
91
+ /** Contact fields for add/update — no store id. */
92
+ export interface NewContact {
93
+ /** Given name. */
94
+ firstName?: string
95
+ /** Middle name(s). */
96
+ middleName?: string
97
+ /** Family name. */
98
+ lastName?: string
99
+ /** Nickname. */
100
+ nickname?: string
101
+ /** Email addresses with labels. */
102
+ emails?: ContactEmail[]
103
+ /** Phone numbers with labels. */
104
+ phoneNumbers?: ContactPhone[]
105
+ /** Organization name. */
106
+ company?: string
107
+ /** Role within the organization. */
108
+ jobTitle?: string
109
+ /** Free-text note field. */
110
+ note?: string
111
+ }
112
+
113
+ /** Paging options for getAll(). */
114
+ export interface GetContactsOptions {
115
+ /** Restrict which members are populated (all fetched by default). */
116
+ fields?: ContactField[]
117
+ /** Client-side sort — the native stores return an unspecified order. */
118
+ sort?: 'firstName' | 'lastName' | 'none'
119
+ /** Max contacts per page. */
120
+ pageSize?: number
121
+ /** Start offset into the result set. */
122
+ pageOffset?: number
123
+ }
124
+
125
+ /** System address-book facade; false supported off mobile. */
126
+ export interface Contacts {
127
+ /** Whether the system address book is reachable on this target — false off mobile. */
128
+ readonly supported: boolean
129
+ /** Ensure the contacts permission without prompting twice — returns the
130
+ * post-request grant state, 'unsupported' when the store can't be reached. */
131
+ ensure(): Promise<PermissionResult>
132
+ /** Fetch contacts in pages. */
133
+ getAll(options?: GetContactsOptions): Promise<Contact[]>
134
+ /** Substring search over display names. */
135
+ getByName(predicate: string, fields?: ContactField[]): Promise<Contact[]>
136
+ /** iOS: direct id fetch. Android: the plugin ships no id lookup, so this
137
+ * fetches the full store and filters — read-all cost, call sparingly. */
138
+ getById(id: string, fields?: ContactField[]): Promise<Contact | null>
139
+ /** Insert a contact; resolves the store-assigned id. */
140
+ add(contact: NewContact): Promise<string>
141
+ /** Patch fields of an existing contact by id. */
142
+ update(id: string, contact: NewContact): Promise<string>
143
+ /** Delete a contact by id. */
144
+ remove(id: string): Promise<void>
145
+ }
146
+
147
+ export declare const contacts: Contacts
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 1,
3
+ "files": [
4
+ "contacts-store.android.d.ts",
5
+ "contacts-store.ios.d.ts",
6
+ "contacts-store.mobile.d.ts",
7
+ "contacts.d.ts",
8
+ "index.d.ts",
9
+ "types.d.ts"
10
+ ]
11
+ }
@@ -0,0 +1,9 @@
1
+ import type { PermissionStatus } from '@octane-xplat/platform';
2
+ import type { ContactFetchResult, NativeContactHandle } from './contacts-store.mobile.js';
3
+ import type { PermissionResult } from './types.js';
4
+ export declare function contactsPermissionStatus(): PermissionStatus;
5
+ export declare function ensureContactsPermission(): Promise<PermissionResult>;
6
+ export declare function fetchContacts(fields: string[]): Promise<ContactFetchResult>;
7
+ export declare function fetchContactsByName(predicate: string, fields: string[]): Promise<ContactFetchResult>;
8
+ export declare function fetchContactById(id: string, fields: string[]): Promise<any>;
9
+ export declare function createNativeContact(): NativeContactHandle;
@@ -0,0 +1,9 @@
1
+ import type { PermissionStatus } from '@octane-xplat/platform';
2
+ import type { ContactFetchResult, NativeContactHandle } from './contacts-store.mobile.js';
3
+ import type { PermissionResult } from './types.js';
4
+ export declare function contactsPermissionStatus(): PermissionStatus;
5
+ export declare function ensureContactsPermission(): Promise<PermissionResult>;
6
+ export declare function fetchContacts(fields: string[]): Promise<ContactFetchResult>;
7
+ export declare function fetchContactsByName(predicate: string, fields: string[]): Promise<ContactFetchResult>;
8
+ export declare function fetchContactById(id: string, fields: string[]): Promise<any>;
9
+ export declare function createNativeContact(): NativeContactHandle;
@@ -0,0 +1,6 @@
1
+ /** Result the plugin's worker fetches resolve with. */
2
+ export interface ContactFetchResult {
3
+ data?: any[];
4
+ }
5
+ /** Unsaved native contact instance returned by create(). */
6
+ export type NativeContactHandle = any;
@@ -0,0 +1,3 @@
1
+ import type { Contacts } from './types.js';
2
+ /** Contacts service — system address book. */
3
+ export declare const contacts: Contacts;
@@ -0,0 +1,2 @@
1
+ export * from './types.js';
2
+ export { contacts } from './contacts.js';
@@ -0,0 +1,128 @@
1
+ /** Coarse permission answer; unsupported means no contacts/permission path. */
2
+ export type PermissionResult = 'granted' | 'denied' | 'unsupported';
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 = 'name' | 'emails' | 'phoneNumbers' | 'addresses' | 'urls' | 'company' | 'note' | 'image' | 'nickname';
6
+ /** One labeled email field. */
7
+ export interface ContactEmail {
8
+ /** Free-form label (home/work/custom) as stored. */
9
+ label?: string;
10
+ /** Email address value. */
11
+ email: string;
12
+ }
13
+ /** One labeled phone field. */
14
+ export interface ContactPhone {
15
+ /** Free-form label (home/work/custom) as stored. */
16
+ label?: string;
17
+ /** Phone number string as stored. */
18
+ number: string;
19
+ }
20
+ /** One labeled postal address. */
21
+ export interface ContactAddress {
22
+ /** Free-form label (home/work/custom) as stored. */
23
+ label?: string;
24
+ /** Street line(s). */
25
+ street?: string;
26
+ /** City. */
27
+ city?: string;
28
+ /** State/province region. */
29
+ region?: string;
30
+ /** Postal/ZIP code. */
31
+ postalCode?: string;
32
+ /** Country name or code. */
33
+ country?: string;
34
+ }
35
+ /** One labeled URL field. */
36
+ export interface ContactUrl {
37
+ /** Free-form label (home/work/custom) as stored. */
38
+ label?: string;
39
+ /** URL value. */
40
+ url: string;
41
+ }
42
+ /** A stored contact record. */
43
+ export interface Contact {
44
+ /** Store-assigned contact id. */
45
+ id: string;
46
+ /** Display name — falls back to composed given/family when the store
47
+ * lacks a display string. */
48
+ name: string;
49
+ /** Given name. */
50
+ firstName?: string;
51
+ /** Middle name(s). */
52
+ middleName?: string;
53
+ /** Family name. */
54
+ lastName?: string;
55
+ /** Nickname. */
56
+ nickname?: string;
57
+ /** Email addresses with labels. */
58
+ emails?: ContactEmail[];
59
+ /** Phone numbers with labels. */
60
+ phoneNumbers?: ContactPhone[];
61
+ /** Postal addresses with labels. */
62
+ addresses?: ContactAddress[];
63
+ /** Associated URLs with labels. */
64
+ urls?: ContactUrl[];
65
+ /** Organization name. */
66
+ company?: string;
67
+ /** Role within the organization. */
68
+ jobTitle?: string;
69
+ /** Free-text note field. */
70
+ note?: string;
71
+ /** Platform image reference when 'image' was requested — a file path or
72
+ * data reference; shape is platform-dependent. */
73
+ image?: unknown;
74
+ }
75
+ /** Contact fields for add/update — no store id. */
76
+ export interface NewContact {
77
+ /** Given name. */
78
+ firstName?: string;
79
+ /** Middle name(s). */
80
+ middleName?: string;
81
+ /** Family name. */
82
+ lastName?: string;
83
+ /** Nickname. */
84
+ nickname?: string;
85
+ /** Email addresses with labels. */
86
+ emails?: ContactEmail[];
87
+ /** Phone numbers with labels. */
88
+ phoneNumbers?: ContactPhone[];
89
+ /** Organization name. */
90
+ company?: string;
91
+ /** Role within the organization. */
92
+ jobTitle?: string;
93
+ /** Free-text note field. */
94
+ note?: string;
95
+ }
96
+ /** Paging options for getAll(). */
97
+ export interface GetContactsOptions {
98
+ /** Restrict which members are populated (all fetched by default). */
99
+ fields?: ContactField[];
100
+ /** Client-side sort — the native stores return an unspecified order. */
101
+ sort?: 'firstName' | 'lastName' | 'none';
102
+ /** Max contacts per page. */
103
+ pageSize?: number;
104
+ /** Start offset into the result set. */
105
+ pageOffset?: number;
106
+ }
107
+ /** System address-book facade; false supported off mobile. */
108
+ export interface Contacts {
109
+ /** Whether the system address book is reachable on this target — false off mobile. */
110
+ readonly supported: boolean;
111
+ /** Ensure the contacts permission without prompting twice — returns the
112
+ * post-request grant state, 'unsupported' when the store can't be reached. */
113
+ ensure(): Promise<PermissionResult>;
114
+ /** Fetch contacts in pages. */
115
+ getAll(options?: GetContactsOptions): Promise<Contact[]>;
116
+ /** Substring search over display names. */
117
+ getByName(predicate: string, fields?: ContactField[]): Promise<Contact[]>;
118
+ /** iOS: direct id fetch. Android: the plugin ships no id lookup, so this
119
+ * fetches the full store and filters — read-all cost, call sparingly. */
120
+ getById(id: string, fields?: ContactField[]): Promise<Contact | null>;
121
+ /** Insert a contact; resolves the store-assigned id. */
122
+ add(contact: NewContact): Promise<string>;
123
+ /** Patch fields of an existing contact by id. */
124
+ update(id: string, contact: NewContact): Promise<string>;
125
+ /** Delete a contact by id. */
126
+ remove(id: string): Promise<void>;
127
+ }
128
+ export declare const contacts: Contacts;