@octane-xplat/contacts 0.19.0 → 0.20.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.
@@ -4,341 +4,380 @@
4
4
  // it is excluded from fetch keys and `note` stays absent unless the store
5
5
  // reports the key available.
6
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,
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
28
  } from '@octane-xplat/platform/macos'
29
+
29
30
  import type {
30
- Contact,
31
- ContactAddress,
32
- ContactField,
33
- Contacts,
34
- GetContactsOptions,
35
- NewContact,
36
- PermissionResult,
31
+ Contact,
32
+ ContactAddress,
33
+ ContactField,
34
+ Contacts,
35
+ GetContactsOptions,
36
+ NewContact,
37
+ PermissionResult,
37
38
  } from './types'
38
39
 
39
40
  let store: any = null
40
41
  const contactStore = () => {
41
- if (store) {
42
- return store
43
- }
44
-
45
- try {
46
- if (typeof CNContactStore?.authorizationStatusForEntityType !== 'function') {
47
- return null
48
- }
49
- return (store = CNContactStore.new())
50
- } catch {
51
- return null
52
- }
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
+ }
53
55
  }
54
56
 
55
57
  // CNAuthorizationStatus: 0 notDetermined 1 restricted 2 denied 3 authorized
56
58
  const rawStatus = () =>
57
- Number(CNContactStore.authorizationStatusForEntityType(CNEntityType.CNEntityTypeContacts ?? 0))
59
+ Number(CNContactStore.authorizationStatusForEntityType(CNEntityType.CNEntityTypeContacts ?? 0))
58
60
 
59
61
  function ensureAccess(): Promise<PermissionResult> {
60
- const s = contactStore()
61
- if (!s) {
62
- return Promise.resolve('unsupported')
63
- }
64
-
65
- const status = rawStatus()
66
- if (status === 3) {
67
- return Promise.resolve('granted')
68
- }
69
-
70
- if (status === 1 || status === 2) {
71
- return Promise.resolve('denied')
72
- }
73
-
74
- return new Promise((resolve) => {
75
- s.requestAccessForEntityTypeCompletionHandler(CNEntityType.CNEntityTypeContacts ?? 0, (granted: boolean) =>
76
- resolve(granted ? 'granted' : 'denied'),
77
- )
78
- })
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
+ })
79
84
  }
80
85
 
81
86
  const BASE_KEYS = [
82
- CNContactIdentifierKey,
83
- CNContactGivenNameKey,
84
- CNContactMiddleNameKey,
85
- CNContactFamilyNameKey,
86
- CNContactNicknameKey,
87
+ CNContactIdentifierKey,
88
+ CNContactGivenNameKey,
89
+ CNContactMiddleNameKey,
90
+ CNContactFamilyNameKey,
91
+ CNContactNicknameKey,
87
92
  ]
88
93
 
89
94
  const FIELD_KEYS: Record<Exclude<ContactField, 'name'>, string[]> = {
90
- emails: [CNContactEmailAddressesKey],
91
- phoneNumbers: [CNContactPhoneNumbersKey],
92
- addresses: [CNContactPostalAddressesKey],
93
- urls: [CNContactUrlAddressesKey],
94
- company: [CNContactOrganizationNameKey, CNContactJobTitleKey],
95
- note: [], // entitlement-gated on macOS too — read only when the key is available
96
- image: [CNContactImageDataKey],
97
- nickname: [],
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: [],
98
103
  }
99
104
 
100
105
  function fetchKeys(fields?: ContactField[]): string[] {
101
- const keys = [...BASE_KEYS]
102
- for (const field of fields ?? (Object.keys(FIELD_KEYS) as ContactField[])) {
103
- for (const key of FIELD_KEYS[field as keyof typeof FIELD_KEYS] ?? []) {
104
- if (!keys.includes(key)) {
105
- keys.push(key)
106
- }
107
- }
108
- }
109
- return keys
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
110
117
  }
111
118
 
112
119
  const nsarray = (list: any): any[] => {
113
- if (!list) {
114
- return []
115
- }
116
-
117
- if (Array.isArray(list)) {
118
- return list
119
- }
120
-
121
- const out: any[] = []
122
- for (let i = 0, count = Number(list.count ?? 0); i < count; i++) {
123
- out.push(list.objectAtIndex(i))
124
- }
125
- return out
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
126
135
  }
127
136
 
128
137
  const labeled = (list: any, value: (entry: any) => unknown) =>
129
- nsarray(list).map((entry) => ({ label: entry?.label ? String(entry.label) : undefined, value: value(entry) }))
138
+ nsarray(list).map((entry) => ({
139
+ label: entry?.label ? String(entry.label) : undefined,
140
+ value: value(entry),
141
+ }))
130
142
 
131
143
  function asContact(native: any): Contact {
132
- const firstName = native?.givenName ? String(native.givenName) : undefined
133
- const lastName = native?.familyName ? String(native.familyName) : undefined
134
- const name =
135
- native?.name && typeof native.name === 'string'
136
- ? native.name
137
- : [firstName, lastName].filter(Boolean).join(' ') ||
138
- (native?.organizationName ? String(native.organizationName) : '')
139
-
140
- const contact: Contact = {
141
- id: String(native?.identifier ?? ''),
142
- name,
143
- firstName,
144
- middleName: native?.middleName ? String(native.middleName) : undefined,
145
- lastName,
146
- nickname: native?.nickname ? String(native.nickname) : undefined,
147
- emails: labeled(native?.emailAddresses, (e) => String(e?.value ?? '')).map(
148
- ({ label, value }) => ({ label, email: value as string }),
149
- ),
150
- phoneNumbers: labeled(native?.phoneNumbers, (e) => String(e?.value?.stringValue ?? '')).map(
151
- ({ label, value }) => ({ label, number: value as string }),
152
- ),
153
- addresses: labeled(
154
- native?.postalAddresses,
155
- (e): ContactAddress => ({
156
- street: e?.value?.street ? String(e.value.street) : undefined,
157
- city: e?.value?.city ? String(e.value.city) : undefined,
158
- region: e?.value?.state ? String(e.value.state) : undefined,
159
- postalCode: e?.value?.postalCode ? String(e.value.postalCode) : undefined,
160
- country: e?.value?.country ? String(e.value.country) : undefined,
161
- }),
162
- ).map(({ label, value }) => ({ label, ...(value as ContactAddress) })),
163
- urls: labeled(native?.urlAddresses, (e) => String(e?.value ?? '')).map(
164
- ({ label, value }) => ({ label, url: value as string }),
165
- ),
166
- company: native?.organizationName ? String(native.organizationName) : undefined,
167
- jobTitle: native?.jobTitle ? String(native.jobTitle) : undefined,
168
- }
169
-
170
- // The notes entitlement is a distribution choice; read it only when the
171
- // fetched keys already carry it.
172
- try {
173
- if (native?.isKeyAvailable?.(CNContactNoteKey) && native?.note) {
174
- contact.note = String(native.note)
175
- }
176
- } catch {
177
- // A store without the notes entitlement leaves the field absent.
178
- }
179
-
180
- try {
181
- if (native?.imageDataAvailable) {
182
- const data = native?.imageData
183
- const base64 = data?.base64EncodedStringWithOptions?.(0)
184
- if (base64) {
185
- contact.image = { data: String(base64) }
186
- }
187
- }
188
- } catch {
189
- // Unfetched or unreadable image data is omitted, never fatal.
190
- }
191
-
192
- return 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
193
204
  }
194
205
 
195
206
  function applySort(list: Contact[], sort?: GetContactsOptions['sort']): Contact[] {
196
- if (!sort || sort === 'none') {
197
- return list
198
- }
207
+ if (!sort || sort === 'none') {
208
+ return list
209
+ }
210
+
211
+ const key = sort === 'firstName' ? 'firstName' : 'lastName'
199
212
 
200
- const key = sort === 'firstName' ? 'firstName' : 'lastName'
201
- return [...list].sort((a, b) => (a[key] ?? a.name).localeCompare(b[key] ?? b.name))
213
+ return [...list].sort((a, b) => (a[key] ?? a.name).localeCompare(b[key] ?? b.name))
202
214
  }
203
215
 
204
216
  function applyPage(list: Contact[], options?: GetContactsOptions): Contact[] {
205
- const start = options?.pageOffset ?? 0
206
- const size = options?.pageSize
207
- return size === undefined ? list.slice(start) : list.slice(start, start + size)
217
+ const start = options?.pageOffset ?? 0
218
+ const size = options?.pageSize
219
+
220
+ return size === undefined ? list.slice(start) : list.slice(start, start + size)
208
221
  }
209
222
 
210
223
  function requireStore(): any {
211
- const s = contactStore()
212
- if (!s) {
213
- throw new Error('contacts: the Contacts store is unavailable on this host')
214
- }
215
- return s
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
216
231
  }
217
232
 
218
233
  function applyNewContact(target: any, source: NewContact): void {
219
- target.givenName = source.firstName ?? ''
220
- target.middleName = source.middleName ?? ''
221
- target.familyName = source.lastName ?? ''
222
- target.nickname = source.nickname ?? ''
223
- target.organizationName = source.company ?? ''
224
- target.jobTitle = source.jobTitle ?? ''
225
- target.emailAddresses = (source.emails ?? []).map((e) =>
226
- CNLabeledValue.labeledValueWithLabelValue(e.label ?? null, e.email),
227
- )
228
- target.phoneNumbers = (source.phoneNumbers ?? []).map((p) =>
229
- CNLabeledValue.labeledValueWithLabelValue(
230
- p.label ?? null,
231
- CNPhoneNumber.phoneNumberWithStringValue(p.number),
232
- ),
233
- )
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
+ )
234
250
  }
235
251
 
236
252
  /** Contacts service — system address book. */
237
253
  export const contacts: Contacts = {
238
- get supported() {
239
- return contactStore() !== null
240
- },
241
-
242
- ensure(): Promise<PermissionResult> {
243
- return ensureAccess()
244
- },
245
-
246
- async getAll(options?: GetContactsOptions): Promise<Contact[]> {
247
- const s = requireStore()
248
- const request = CNContactFetchRequest.alloc().initWithKeysToFetch(fetchKeys(options?.fields))
249
- const out: Contact[] = []
250
- if (
251
- !s.enumerateContactsWithFetchRequestErrorUsingBlock(request, null, (contact: any) => {
252
- out.push(asContact(contact))
253
- })
254
- ) {
255
- throw new Error('contacts.getAll: the store refused the fetch request')
256
- }
257
-
258
- return applyPage(applySort(out, options?.sort), options)
259
- },
260
-
261
- async getByName(predicate: string, fields?: ContactField[]): Promise<Contact[]> {
262
- const s = requireStore()
263
- const list = s.unifiedContactsMatchingPredicateKeysToFetchError(
264
- CNContact.predicateForContactsMatchingName(predicate),
265
- fetchKeys(fields),
266
- null,
267
- )
268
- return nsarray(list).map(asContact)
269
- },
270
-
271
- async getById(id: string, fields?: ContactField[]): Promise<Contact | null> {
272
- const s = requireStore()
273
- const native = s.unifiedContactWithIdentifierKeysToFetchError(id, fetchKeys(fields), null)
274
- return native ? asContact(native) : null
275
- },
276
-
277
- async add(contact: NewContact): Promise<string> {
278
- const s = requireStore()
279
- const native = CNMutableContact.new()
280
- applyNewContact(native, contact)
281
- const request = CNSaveRequest.new()
282
- request.addContactToContainerWithIdentifier(native, null)
283
- if (!s.executeSaveRequestError(request, null)) {
284
- throw new Error('contacts.add: the store refused the save request')
285
- }
286
- return String(native.identifier ?? '')
287
- },
288
-
289
- async update(id: string, contact: NewContact): Promise<string> {
290
- const s = requireStore()
291
- const existing = s.unifiedContactWithIdentifierKeysToFetchError(
292
- id,
293
- fetchKeys(),
294
- null,
295
- )
296
- if (!existing) {
297
- throw new Error(`contacts.update: no contact with id ${id}`)
298
- }
299
-
300
- const native = existing.mutableCopy()
301
- applyNewContact(native, contact)
302
- const request = CNSaveRequest.new()
303
- request.updateContact(native)
304
- if (!s.executeSaveRequestError(request, null)) {
305
- throw new Error('contacts.update: the store refused the save request')
306
- }
307
- return id
308
- },
309
-
310
- async remove(id: string): Promise<void> {
311
- const s = requireStore()
312
- const existing = s.unifiedContactWithIdentifierKeysToFetchError(id, [CNContactIdentifierKey], null)
313
- if (!existing) {
314
- return
315
- }
316
-
317
- const request = CNSaveRequest.new()
318
- request.deleteContact(existing.mutableCopy())
319
- if (!s.executeSaveRequestError(request, null)) {
320
- throw new Error('contacts.remove: the store refused the save request')
321
- }
322
- },
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
+ },
323
353
  }
324
354
 
325
355
  const permissionOwners = ((globalThis as any).__xplatPermissionOwners ??= {})
356
+
326
357
  permissionOwners.contacts = {
327
- getPermissions: async () => {
328
- const s = contactStore()
329
- if (!s) {
330
- return { status: 'unsupported' as const, granted: false, canAskAgain: false }
331
- }
332
-
333
- const status = rawStatus()
334
- return {
335
- status: status === 3 ? ('granted' as const) : status === 0 ? ('undetermined' as const) : ('denied' as const),
336
- granted: status === 3,
337
- canAskAgain: status === 0 || status === 3,
338
- }
339
- },
340
- requestPermissions: async () => {
341
- const result = await contacts.ensure()
342
- return { status: result, granted: result === 'granted', canAskAgain: result === 'granted' }
343
- },
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
+ },
344
383
  }