-
Notifications
You must be signed in to change notification settings - Fork 567
/
index.ts
142 lines (122 loc) · 3.95 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { NativeModules } from "react-native";
import NativeContacts from "./src/NativeContacts";
import { Contact, Group, PermissionType } from "./type";
const isTurboModuleEnabled = global.__turboModuleProxy != null;
const Contacts = isTurboModuleEnabled ? NativeContacts : NativeModules.Contacts;
async function getAll(): Promise<Contact[]> {
return Contacts.getAll();
}
async function getAllWithoutPhotos(): Promise<Contact[]> {
return Contacts.getAllWithoutPhotos();
}
async function getContactById(contactId: string): Promise<Contact | null> {
return Contacts.getContactById(contactId);
}
async function getCount(): Promise<number> {
return Contacts.getCount();
}
async function getPhotoForId(contactId: string): Promise<string> {
return Contacts.getPhotoForId(contactId);
}
async function addContact(contact: Partial<Contact>): Promise<Contact> {
return Contacts.addContact(contact);
}
async function openContactForm(contact: Partial<Contact>): Promise<Contact> {
return Contacts.openContactForm(contact);
}
async function openExistingContact(contact: Contact): Promise<Contact> {
return Contacts.openExistingContact(contact);
}
async function viewExistingContact(contact: {
recordID: string;
}): Promise<Contact | void> {
return Contacts.viewExistingContact(contact);
}
async function editExistingContact(contact: Contact): Promise<Contact> {
return Contacts.editExistingContact(contact);
}
async function updateContact(
contact: Partial<Contact> & { recordID: string }
): Promise<void> {
return Contacts.updateContact(contact);
}
async function deleteContact(contact: Contact): Promise<void> {
return Contacts.deleteContact(contact);
}
async function getContactsMatchingString(str: string): Promise<Contact[]> {
return Contacts.getContactsMatchingString(str);
}
async function getContactsByPhoneNumber(
phoneNumber: string
): Promise<Contact[]> {
return Contacts.getContactsByPhoneNumber(phoneNumber);
}
async function getContactsByEmailAddress(
emailAddress: string
): Promise<Contact[]> {
return Contacts.getContactsByEmailAddress(emailAddress);
}
async function checkPermission(): Promise<PermissionType> {
return Contacts.checkPermission();
}
async function requestPermission(): Promise<PermissionType> {
return Contacts.requestPermission();
}
async function writePhotoToPath(
contactId: string,
file: string
): Promise<boolean> {
return Contacts.writePhotoToPath(contactId, file);
}
async function getGroups(): Promise<Group[]> {
return Contacts.getGroups();
}
async function getGroup(identifier: string): Promise<Group | null> {
return Contacts.getGroup(identifier);
}
async function deleteGroup(identifier: string): Promise<boolean> {
return Contacts.deleteGroup(identifier);
}
async function updateGroup(identifier: string, groupData: Pick<Group, 'name'>): Promise<Group> {
return Contacts.updateGroup(identifier, groupData);
}
async function addGroup(group: Pick<Group, 'name'>): Promise<Group>{
return Contacts.addGroup(group);
}
async function contactsInGroup(identifier: string): Promise<Contact[]> {
return Contacts.contactsInGroup(identifier);
}
async function addContactsToGroup(groupIdentifier: string, contactIdentifiers: string[]): Promise<boolean> {
return Contacts.addContactsToGroup(groupIdentifier, contactIdentifiers);
}
async function removeContactsFromGroup(groupIdentifier: string, contactIdentifiers: string[]): Promise<boolean> {
return Contacts.removeContactsFromGroup(groupIdentifier, contactIdentifiers);
}
export default {
getAll,
getAllWithoutPhotos,
getContactById,
getCount,
getPhotoForId,
addContact,
openContactForm,
openExistingContact,
viewExistingContact,
editExistingContact,
updateContact,
deleteContact,
getContactsMatchingString,
getContactsByPhoneNumber,
getContactsByEmailAddress,
checkPermission,
requestPermission,
writePhotoToPath,
getGroups,
getGroup,
deleteGroup,
updateGroup,
addGroup,
contactsInGroup,
addContactsToGroup,
removeContactsFromGroup
};