mp-js-api 0.0.21 → 0.0.22
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/.gitattributes +2 -2
- package/dist/api.js +2 -2
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/tables/contact-email-addresses.d.ts +1 -1
- package/dist/tables/contact-email-addresses.d.ts.map +1 -1
- package/dist/tables/form-responses.d.ts +2 -2
- package/dist/tables/form-responses.d.ts.map +1 -1
- package/dist/utils/converters.d.ts +0 -1
- package/dist/utils/converters.d.ts.map +1 -1
- package/dist/utils/converters.js +4 -1
- package/dist/utils/json-sql.d.ts +2 -0
- package/dist/utils/json-sql.d.ts.map +1 -0
- package/dist/utils/json-sql.js +111 -0
- package/dist/utils/strings.d.ts +3 -0
- package/dist/utils/strings.d.ts.map +1 -0
- package/dist/utils/strings.js +16 -0
- package/package.json +1 -1
- package/src/api.ts +2 -2
- package/src/index.ts +31 -0
- package/src/tables/contact-email-addresses.ts +1 -1
- package/src/tables/form-responses.ts +2 -2
- package/src/utils/converters.ts +5 -5
- package/src/utils/json-sql.ts +132 -0
- package/src/utils/strings.ts +15 -0
package/.gitattributes
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
# Auto detect text files and perform LF normalization
|
|
2
|
-
* text=auto
|
|
1
|
+
# Auto detect text files and perform LF normalization
|
|
2
|
+
* text=auto
|
package/dist/api.js
CHANGED
|
@@ -62,8 +62,8 @@ const createApiBase = ({ auth }) => {
|
|
|
62
62
|
const getMany = async ({ path, mpOptions, config }) => {
|
|
63
63
|
try {
|
|
64
64
|
const url = path + '/get'; //+ stringifyURLParams(mpOptions);
|
|
65
|
-
const data = mpOptions && (0, converters_1.convertToSnakeCase)(mpOptions);
|
|
66
|
-
const res = await api.post(url,
|
|
65
|
+
const data = mpOptions && (0, converters_1.escapeApostrophes)((0, converters_1.convertToSnakeCase)(mpOptions));
|
|
66
|
+
const res = await api.post(url, data, {
|
|
67
67
|
...config,
|
|
68
68
|
...{
|
|
69
69
|
headers: {
|
package/dist/index.d.ts
CHANGED
|
@@ -27,6 +27,13 @@ export type CreateContactAttributeParams = WithRequired<Partial<ContactAttribute
|
|
|
27
27
|
export type CreateFormResponseParams = WithRequired<Omit<Partial<FormResponse>, 'formResponseID'>, 'formID' | 'responseDate'>;
|
|
28
28
|
export type CreateFormResponseAnswerParams = WithRequired<Omit<Partial<FormResponseAnswer>, 'formResponseAnswerID'>, 'formFieldID' | 'formResponseID'>;
|
|
29
29
|
export type CreateContactEmailAddressParams = WithRequired<Omit<Partial<ContactEmailAddress>, 'emailAddressID'>, 'emailAddress' | 'contactID'>;
|
|
30
|
+
export interface ContactDetails extends Contact, Participant, Household {
|
|
31
|
+
householdID: number;
|
|
32
|
+
gender: 'Male' | 'Female' | null;
|
|
33
|
+
memberStatus: string;
|
|
34
|
+
maritalStatus: string;
|
|
35
|
+
imageID: string | null;
|
|
36
|
+
}
|
|
30
37
|
export type MPInstance = {
|
|
31
38
|
get: AxiosInstance['get'];
|
|
32
39
|
put: AxiosInstance['put'];
|
|
@@ -39,6 +46,9 @@ export type MPInstance = {
|
|
|
39
46
|
getContact(id: number, options?: MPGetOptions): Promise<Contact | undefined | {
|
|
40
47
|
error: ErrorDetails;
|
|
41
48
|
}>;
|
|
49
|
+
getContactDetails(id: number, options?: MPGetOptions): Promise<ContactDetails | undefined | {
|
|
50
|
+
error: ErrorDetails;
|
|
51
|
+
}>;
|
|
42
52
|
getContactAttribute(id: number, options?: MPGetOptions): Promise<ContactAttribute | undefined | {
|
|
43
53
|
error: ErrorDetails;
|
|
44
54
|
}>;
|
|
@@ -138,6 +148,9 @@ export type MPInstance = {
|
|
|
138
148
|
updateContacts(contacts: WithRequired<Partial<Contact>, 'contactID'>[], options?: MPUpdateOptions): Promise<Contact[] | {
|
|
139
149
|
error: ErrorDetails;
|
|
140
150
|
}>;
|
|
151
|
+
updateHouseholds(households: WithRequired<Partial<Household>, 'householdID'>[], options?: MPUpdateOptions): Promise<Household[] | {
|
|
152
|
+
error: ErrorDetails;
|
|
153
|
+
}>;
|
|
141
154
|
updateEventParticipants(participants: WithRequired<Partial<EventParticipant>, 'eventParticipantID'>[], options?: MPUpdateOptions): Promise<EventParticipant[] | {
|
|
142
155
|
error: ErrorDetails;
|
|
143
156
|
}>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAiB,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAClI,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC3G,OAAO,EAAE,OAAO,EAAiB,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAe,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAe,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAiB,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAmB,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAqB,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAA0B,MAAM,6BAA6B,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAA0B,MAAM,6BAA6B,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAA0B,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAC7G,OAAO,EAAE,YAAY,EAAsB,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAA6B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kBAAkB,EAClB,SAAS,EACV,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,12 @@ const createMPInstance = ({ auth }) => {
|
|
|
21
21
|
async getContact(id, mpOptions = {}) {
|
|
22
22
|
return getOne({ path: `/tables/contacts`, id, mpOptions });
|
|
23
23
|
},
|
|
24
|
+
async getContactDetails(id, mpOptions) {
|
|
25
|
+
return getOne({ path: `/tables/contacts`, id,
|
|
26
|
+
mpOptions: { ...mpOptions,
|
|
27
|
+
select: 'Contacts.*, Participant_Record_Table.*, Household_ID_Table.*, Gender_ID_Table.Gender, Participant_Record_Table_Member_Status_ID_Table.Member_Status, Marital_Status_ID_Table.Marital_Status, dp_fileUniqueId as Image_ID' }
|
|
28
|
+
});
|
|
29
|
+
},
|
|
24
30
|
async getContactAttribute(id, mpOptions = {}) {
|
|
25
31
|
return getOne({ path: `/tables/contact_attributes`, id, mpOptions });
|
|
26
32
|
},
|
|
@@ -125,6 +131,9 @@ const createMPInstance = ({ auth }) => {
|
|
|
125
131
|
async updateContacts(params, mpOptions) {
|
|
126
132
|
return update({ path: `/tables/contacts`, mpOptions, params });
|
|
127
133
|
},
|
|
134
|
+
async updateHouseholds(params, mpOptions) {
|
|
135
|
+
return update({ path: `/tables/households`, mpOptions, params });
|
|
136
|
+
},
|
|
128
137
|
async updateEventParticipants(params, mpOptions) {
|
|
129
138
|
return update({ path: `/tables/event_participants`, mpOptions, params });
|
|
130
139
|
},
|
|
@@ -19,7 +19,7 @@ export interface ContactEmailAddress {
|
|
|
19
19
|
export interface ContactWithEmailAddress extends Contact, Omit<ContactEmailAddress, "emailAddress"> {
|
|
20
20
|
alternateEmail: string;
|
|
21
21
|
}
|
|
22
|
-
export interface ContactWithEmailAddresses extends Contact
|
|
22
|
+
export interface ContactWithEmailAddresses extends Contact {
|
|
23
23
|
emailAddresses: string[];
|
|
24
24
|
}
|
|
25
25
|
//# sourceMappingURL=contact-email-addresses.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contact-email-addresses.d.ts","sourceRoot":"","sources":["../../src/tables/contact-email-addresses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,WAAW,yBAAyB;IACxC,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACpC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,mBAAmB;IAClC,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACnC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,uBAAwB,SAAQ,OAAO,EAAE,IAAI,CAAC,mBAAmB,EAAE,cAAc,CAAC;IACjG,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,yBAA0B,SAAQ,OAAO
|
|
1
|
+
{"version":3,"file":"contact-email-addresses.d.ts","sourceRoot":"","sources":["../../src/tables/contact-email-addresses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,WAAW,yBAAyB;IACxC,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACpC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,mBAAmB;IAClC,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACnC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,uBAAwB,SAAQ,OAAO,EAAE,IAAI,CAAC,mBAAmB,EAAE,cAAc,CAAC;IACjG,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,yBAA0B,SAAQ,OAAO;IACxD,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B"}
|
|
@@ -13,7 +13,7 @@ export interface FormResponseRecord {
|
|
|
13
13
|
Address_City: string | null;
|
|
14
14
|
Address_State: string | null;
|
|
15
15
|
Address_Zip: number | null;
|
|
16
|
-
Event_ID: number;
|
|
16
|
+
Event_ID: number | null;
|
|
17
17
|
Pledge_Campaign_ID: null;
|
|
18
18
|
Opportunity_ID: null;
|
|
19
19
|
Opportunity_Response: null;
|
|
@@ -37,7 +37,7 @@ export interface FormResponse {
|
|
|
37
37
|
addressCity: string | null;
|
|
38
38
|
addressState: string | null;
|
|
39
39
|
addressZip: string | null;
|
|
40
|
-
eventID: number;
|
|
40
|
+
eventID: number | null;
|
|
41
41
|
pledgeCampaignID: null;
|
|
42
42
|
opportunityID: null;
|
|
43
43
|
opportunityResponse: null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-responses.d.ts","sourceRoot":"","sources":["../../src/tables/form-responses.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,kBAAkB;IACjC,gBAAgB,EAAE,MAAM,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAA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B,oBAAoB,EAAE,IAAI,CAAC;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,OAAO,EAAE,IAAI,CAAC;IACd,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;CACrC;AAGD,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,OAAO,EAAE,MAAM,GAAE,IAAI,CAAC;IACtB,gBAAgB,EAAE,IAAI,CAAC;IACvB,aAAa,EAAE,IAAI,CAAC;IACpB,mBAAmB,EAAE,IAAI,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,OAAO,EAAE,IAAI,CAAC;IACd,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC"}
|
|
@@ -7,7 +7,6 @@ export declare function toCamelCase(str: string, { capitalIds }?: {
|
|
|
7
7
|
}): string;
|
|
8
8
|
export declare function toCapitalSnakeCase(str: string, { capitalIds }?: {
|
|
9
9
|
capitalIds?: boolean;
|
|
10
|
-
capitalSnake?: boolean;
|
|
11
10
|
}): string;
|
|
12
11
|
export declare function caseConverter<T>(obj: T, { type, capitalIds }: {
|
|
13
12
|
type: 'toCamel' | 'toSnake';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../src/utils/converters.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAAE,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAM,UAS5E;
|
|
1
|
+
{"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../src/utils/converters.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAAE,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAM,UAS5E;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,UA2BpC;AAED,wBAAgB,gBAAgB,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,CAU3D;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,KAgB1C;AAGD,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,UAAkB,EAAE,GAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAC;CAAO,UAQ9F;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,UAAkB,EAAE,GAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,UAKpG;AAGD,wBAAgB,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,UAAkB,EAAE,EAAE;IAAE,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAC;CAAE,OAkB5H;AAED,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,UAAU,UAAO,GAAG,CAAC,CAE1F;AAED,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,UAAU,UAAO,GAAG,CAAC,CAE1F"}
|
package/dist/utils/converters.js
CHANGED
|
@@ -65,7 +65,10 @@ function escapeApostrophes(obj) {
|
|
|
65
65
|
for (const key in obj) {
|
|
66
66
|
if (obj.hasOwnProperty(key)) {
|
|
67
67
|
const value = obj[key];
|
|
68
|
-
|
|
68
|
+
if (typeof value === 'string')
|
|
69
|
+
obj[key] = escapeApostrophe(value);
|
|
70
|
+
else
|
|
71
|
+
obj[key] = value;
|
|
69
72
|
}
|
|
70
73
|
}
|
|
71
74
|
return obj;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-sql.d.ts","sourceRoot":"","sources":["../../src/utils/json-sql.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function jsonToSqlFilter(json) {
|
|
4
|
+
const conditions = [];
|
|
5
|
+
// Loop through each key-value pair in the JSON object
|
|
6
|
+
for (const [key, value] of Object.entries(json)) {
|
|
7
|
+
let condition = '';
|
|
8
|
+
// If the value is a string, wrap it in quotes
|
|
9
|
+
if (typeof value === 'string') {
|
|
10
|
+
condition = `${key} = '${value}'`;
|
|
11
|
+
}
|
|
12
|
+
// If the value is a number or boolean, no quotes are needed
|
|
13
|
+
else if (typeof value === 'number' || typeof value === 'boolean') {
|
|
14
|
+
condition = `${key} = ${value}`;
|
|
15
|
+
}
|
|
16
|
+
// If the value is an array, assume it represents an IN condition
|
|
17
|
+
else if (Array.isArray(value)) {
|
|
18
|
+
const valueList = value.map(val => typeof val === 'string' ? `'${val}'` : val).join(', ');
|
|
19
|
+
condition = `${key} IN (${valueList})`;
|
|
20
|
+
}
|
|
21
|
+
// If the value is an object, we can assume it's a nested condition (e.g., for complex queries)
|
|
22
|
+
else if (typeof value === 'object') {
|
|
23
|
+
const subConditions = Object.entries(value).map(([subKey, subValue]) => {
|
|
24
|
+
if (typeof subValue === 'string') {
|
|
25
|
+
return `${subKey} = '${subValue}'`;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return `${subKey} = ${subValue}`;
|
|
29
|
+
}
|
|
30
|
+
}).join(' AND ');
|
|
31
|
+
condition = `${key} (${subConditions})`;
|
|
32
|
+
}
|
|
33
|
+
conditions.push(condition);
|
|
34
|
+
}
|
|
35
|
+
// Join the conditions with 'AND'
|
|
36
|
+
return conditions.length ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
37
|
+
}
|
|
38
|
+
// Example Usage
|
|
39
|
+
const json1 = {
|
|
40
|
+
name: "John",
|
|
41
|
+
age: 30,
|
|
42
|
+
active: true,
|
|
43
|
+
hobbies: ["reading", "gaming"],
|
|
44
|
+
address: {
|
|
45
|
+
city: "New York",
|
|
46
|
+
zip: "10001"
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const query1 = jsonToSqlFilter(json1);
|
|
50
|
+
console.log(query1);
|
|
51
|
+
function jsonToSqlQuery(json) {
|
|
52
|
+
const conditions = [];
|
|
53
|
+
// Loop through each key-value pair in the JSON object
|
|
54
|
+
for (const [key, value] of Object.entries(json)) {
|
|
55
|
+
let condition = '';
|
|
56
|
+
// If the value is an object (operator condition)
|
|
57
|
+
if (typeof value === 'object' && value !== null) {
|
|
58
|
+
const operatorConditions = [];
|
|
59
|
+
let [operator, operatorValue] = [null, null];
|
|
60
|
+
for ([operator, operatorValue] of Object.entries(value)) {
|
|
61
|
+
switch (operator) {
|
|
62
|
+
case "$eq":
|
|
63
|
+
operatorConditions.push(`${key} = '${operatorValue}'`);
|
|
64
|
+
break;
|
|
65
|
+
case "$gt":
|
|
66
|
+
operatorConditions.push(`${key} > ${operatorValue}`);
|
|
67
|
+
break;
|
|
68
|
+
case "$lt":
|
|
69
|
+
operatorConditions.push(`${key} < ${operatorValue}`);
|
|
70
|
+
break;
|
|
71
|
+
case "$gte":
|
|
72
|
+
operatorConditions.push(`${key} >= ${operatorValue}`);
|
|
73
|
+
break;
|
|
74
|
+
case "$lte":
|
|
75
|
+
operatorConditions.push(`${key} <= ${operatorValue}`);
|
|
76
|
+
break;
|
|
77
|
+
case "$ne":
|
|
78
|
+
operatorConditions.push(`${key} != '${operatorValue}'`);
|
|
79
|
+
break;
|
|
80
|
+
case "$in":
|
|
81
|
+
const inValues = operatorValue.map((val) => typeof val === 'string' ? `'${val}'` : val).join(', ');
|
|
82
|
+
operatorConditions.push(`${key} IN (${inValues})`);
|
|
83
|
+
break;
|
|
84
|
+
case "$like":
|
|
85
|
+
operatorConditions.push(`${key} LIKE '%${operatorValue}%'`);
|
|
86
|
+
break;
|
|
87
|
+
default:
|
|
88
|
+
throw new Error(`Unsupported operator: ${operator}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Join all conditions for a field with AND
|
|
92
|
+
condition = operatorConditions.join(' AND ');
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// For simple equality condition
|
|
96
|
+
condition = `${key} = '${value}'`;
|
|
97
|
+
}
|
|
98
|
+
conditions.push(condition);
|
|
99
|
+
}
|
|
100
|
+
// Join the conditions with AND
|
|
101
|
+
return conditions.length ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
102
|
+
}
|
|
103
|
+
// Example Usage
|
|
104
|
+
const json = {
|
|
105
|
+
"age": { "$gt": 30 },
|
|
106
|
+
"name": { "$eq": "John" },
|
|
107
|
+
"status": { "$in": ["active", "pending"] },
|
|
108
|
+
"address.city": { "$eq": "New York" }
|
|
109
|
+
};
|
|
110
|
+
const query = jsonToSqlQuery(json);
|
|
111
|
+
console.log(query);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/utils/strings.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,CAUrE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,UAExC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cleanPhoneNumber = cleanPhoneNumber;
|
|
4
|
+
exports.formatPhone = formatPhone;
|
|
5
|
+
function cleanPhoneNumber(num) {
|
|
6
|
+
if (!num)
|
|
7
|
+
return '';
|
|
8
|
+
const cleaned = String(num).trim()
|
|
9
|
+
.replace(/(?<!^)\+|[^\d+]+/g, '') // Remove non digits and keep the +
|
|
10
|
+
.replace(/^00/, '+') // Remove preceding '00'
|
|
11
|
+
.replace(/^\+?1(?=\d{10})/, ''); // Remove preceding '+1' or '1' for American numbers
|
|
12
|
+
return cleaned;
|
|
13
|
+
}
|
|
14
|
+
function formatPhone(phone) {
|
|
15
|
+
return String(cleanPhoneNumber(phone)).replace(/^(\d{3})(\d{3})(\d{4})/, '$1-$2-$3');
|
|
16
|
+
}
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -97,8 +97,8 @@ export const createApiBase = ({ auth }: { auth: { username: string; password: st
|
|
|
97
97
|
const getMany: APIGetMultipleInstance = async <T, R>({ path, mpOptions, config }: APIGetParameter): Promise<R[] | { error: ErrorDetails; }> => {
|
|
98
98
|
try {
|
|
99
99
|
const url = path + '/get'; //+ stringifyURLParams(mpOptions);
|
|
100
|
-
const data = mpOptions && convertToSnakeCase<MPGetOptions>(mpOptions);
|
|
101
|
-
const res = await api.post<T[]>(url,
|
|
100
|
+
const data = mpOptions && escapeApostrophes(convertToSnakeCase<MPGetOptions>(mpOptions));
|
|
101
|
+
const res = await api.post<T[]>(url, data, {
|
|
102
102
|
...config,
|
|
103
103
|
...{
|
|
104
104
|
headers: {
|
package/src/index.ts
CHANGED
|
@@ -60,6 +60,16 @@ export type CreateContactEmailAddressParams = WithRequired<
|
|
|
60
60
|
>;
|
|
61
61
|
|
|
62
62
|
|
|
63
|
+
|
|
64
|
+
export interface ContactDetails extends Contact, Participant, Household {
|
|
65
|
+
householdID: number;
|
|
66
|
+
gender: 'Male' | 'Female' | null;
|
|
67
|
+
memberStatus: string;
|
|
68
|
+
maritalStatus: string;
|
|
69
|
+
imageID: string | null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
63
73
|
export type MPInstance = {
|
|
64
74
|
|
|
65
75
|
get: AxiosInstance['get'];
|
|
@@ -75,6 +85,10 @@ export type MPInstance = {
|
|
|
75
85
|
id: number,
|
|
76
86
|
options?: MPGetOptions
|
|
77
87
|
): Promise<Contact | undefined | { error: ErrorDetails; }>;
|
|
88
|
+
getContactDetails(
|
|
89
|
+
id: number,
|
|
90
|
+
options?: MPGetOptions
|
|
91
|
+
): Promise<ContactDetails | undefined | { error: ErrorDetails; }>;
|
|
78
92
|
getContactAttribute(
|
|
79
93
|
id: number,
|
|
80
94
|
options?: MPGetOptions
|
|
@@ -198,6 +212,10 @@ export type MPInstance = {
|
|
|
198
212
|
contacts: WithRequired<Partial<Contact>, 'contactID'>[],
|
|
199
213
|
options?: MPUpdateOptions
|
|
200
214
|
): Promise<Contact[] | { error: ErrorDetails; }>;
|
|
215
|
+
updateHouseholds(
|
|
216
|
+
households: WithRequired<Partial<Household>, 'householdID'>[],
|
|
217
|
+
options?: MPUpdateOptions
|
|
218
|
+
): Promise<Household[] | { error: ErrorDetails; }>;
|
|
201
219
|
updateEventParticipants(
|
|
202
220
|
participants: WithRequired<Partial<EventParticipant>, 'eventParticipantID'>[],
|
|
203
221
|
options?: MPUpdateOptions
|
|
@@ -223,6 +241,14 @@ export const createMPInstance = ({ auth }: { auth: { username: string; password:
|
|
|
223
241
|
{ path: `/tables/contacts`, id, mpOptions }
|
|
224
242
|
);
|
|
225
243
|
},
|
|
244
|
+
async getContactDetails(id, mpOptions) {
|
|
245
|
+
return getOne<ContactRecord, ContactDetails>(
|
|
246
|
+
{ path: `/tables/contacts`, id,
|
|
247
|
+
mpOptions: { ...mpOptions,
|
|
248
|
+
select: 'Contacts.*, Participant_Record_Table.*, Household_ID_Table.*, Gender_ID_Table.Gender, Participant_Record_Table_Member_Status_ID_Table.Member_Status, Marital_Status_ID_Table.Marital_Status, dp_fileUniqueId as Image_ID' }
|
|
249
|
+
}
|
|
250
|
+
);
|
|
251
|
+
},
|
|
226
252
|
async getContactAttribute(id, mpOptions = {}) {
|
|
227
253
|
return getOne<ContactAttributeRecord, ContactAttribute>(
|
|
228
254
|
{ path: `/tables/contact_attributes`, id, mpOptions }
|
|
@@ -394,6 +420,11 @@ export const createMPInstance = ({ auth }: { auth: { username: string; password:
|
|
|
394
420
|
{ path: `/tables/contacts`, mpOptions, params }
|
|
395
421
|
);
|
|
396
422
|
},
|
|
423
|
+
async updateHouseholds(params, mpOptions) {
|
|
424
|
+
return update<Partial<Household>, Household>(
|
|
425
|
+
{ path: `/tables/households`, mpOptions, params }
|
|
426
|
+
);
|
|
427
|
+
},
|
|
397
428
|
async updateEventParticipants(params, mpOptions) {
|
|
398
429
|
return update<Partial<EventParticipant>, EventParticipant>(
|
|
399
430
|
{ path: `/tables/event_participants`, mpOptions, params }
|
|
@@ -23,6 +23,6 @@ export interface ContactWithEmailAddress extends Contact, Omit<ContactEmailAddre
|
|
|
23
23
|
alternateEmail: string;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export interface ContactWithEmailAddresses extends Contact
|
|
26
|
+
export interface ContactWithEmailAddresses extends Contact {
|
|
27
27
|
emailAddresses: string[];
|
|
28
28
|
}
|
|
@@ -14,7 +14,7 @@ export interface FormResponseRecord {
|
|
|
14
14
|
Address_City: string | null;
|
|
15
15
|
Address_State: string | null;
|
|
16
16
|
Address_Zip: number | null;
|
|
17
|
-
Event_ID: number;
|
|
17
|
+
Event_ID: number| null;
|
|
18
18
|
Pledge_Campaign_ID: null;
|
|
19
19
|
Opportunity_ID: null;
|
|
20
20
|
Opportunity_Response: null;
|
|
@@ -40,7 +40,7 @@ export interface FormResponse {
|
|
|
40
40
|
addressCity: string | null;
|
|
41
41
|
addressState: string | null;
|
|
42
42
|
addressZip: string | null;
|
|
43
|
-
eventID: number;
|
|
43
|
+
eventID: number| null;
|
|
44
44
|
pledgeCampaignID: null;
|
|
45
45
|
opportunityID: null;
|
|
46
46
|
opportunityResponse: null;
|
package/src/utils/converters.ts
CHANGED
|
@@ -9,7 +9,6 @@ export function stringifyURLParams<T = any>(mpOptions: Record<string, T> = {}) {
|
|
|
9
9
|
}, ''));
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
13
12
|
export function escapeSql(str: string) {
|
|
14
13
|
return str.replace(/%|(?<=\w)'(?=\w)/g, function (char: string) {
|
|
15
14
|
switch (char) {
|
|
@@ -57,7 +56,10 @@ export function escapeApostrophes<T>(obj: T) {
|
|
|
57
56
|
for (const key in obj) {
|
|
58
57
|
if (obj.hasOwnProperty(key)) {
|
|
59
58
|
const value = obj[key];
|
|
60
|
-
|
|
59
|
+
if (typeof value === 'string')
|
|
60
|
+
obj[key] = escapeApostrophe<typeof value>(value as string);
|
|
61
|
+
else
|
|
62
|
+
obj[key] = value;
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
return obj;
|
|
@@ -67,8 +69,6 @@ export function escapeApostrophes<T>(obj: T) {
|
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
|
|
70
|
-
|
|
71
|
-
|
|
72
72
|
export function toCamelCase(str: string, { capitalIds = false }: { capitalIds?: boolean; } = {}) {
|
|
73
73
|
// str = str.replace('-', '');
|
|
74
74
|
str = str.toLowerCase();
|
|
@@ -79,7 +79,7 @@ export function toCamelCase(str: string, { capitalIds = false }: { capitalIds?:
|
|
|
79
79
|
return capitalIds ? str.replace(/id$/i, 'ID') : str;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
export function toCapitalSnakeCase(str: string, { capitalIds = false }: { capitalIds?: boolean
|
|
82
|
+
export function toCapitalSnakeCase(str: string, { capitalIds = false }: { capitalIds?: boolean } = {}) {
|
|
83
83
|
str = str.replace(/(?<=^_|^__)[^\W_]/, match => match.at(0)?.toUpperCase() || '');
|
|
84
84
|
str = str.replace(/(?<!_|\/)(ID|[A-Z]|\d)/g, match => `_${match}`);
|
|
85
85
|
str = str.charAt(0).toUpperCase() + str.slice(1);
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
function jsonToSqlFilter(json: Record<string, any>): string {
|
|
2
|
+
const conditions: string[] = [];
|
|
3
|
+
|
|
4
|
+
// Loop through each key-value pair in the JSON object
|
|
5
|
+
for (const [key, value] of Object.entries(json)) {
|
|
6
|
+
let condition = '';
|
|
7
|
+
|
|
8
|
+
// If the value is a string, wrap it in quotes
|
|
9
|
+
if (typeof value === 'string') {
|
|
10
|
+
condition = `${key} = '${value}'`;
|
|
11
|
+
}
|
|
12
|
+
// If the value is a number or boolean, no quotes are needed
|
|
13
|
+
else if (typeof value === 'number' || typeof value === 'boolean') {
|
|
14
|
+
condition = `${key} = ${value}`;
|
|
15
|
+
}
|
|
16
|
+
// If the value is an array, assume it represents an IN condition
|
|
17
|
+
else if (Array.isArray(value)) {
|
|
18
|
+
const valueList = value.map(val =>
|
|
19
|
+
typeof val === 'string' ? `'${val}'` : val
|
|
20
|
+
).join(', ');
|
|
21
|
+
condition = `${key} IN (${valueList})`;
|
|
22
|
+
}
|
|
23
|
+
// If the value is an object, we can assume it's a nested condition (e.g., for complex queries)
|
|
24
|
+
else if (typeof value === 'object') {
|
|
25
|
+
const subConditions = Object.entries(value).map(([subKey, subValue]) => {
|
|
26
|
+
if (typeof subValue === 'string') {
|
|
27
|
+
return `${subKey} = '${subValue}'`;
|
|
28
|
+
} else {
|
|
29
|
+
return `${subKey} = ${subValue}`;
|
|
30
|
+
}
|
|
31
|
+
}).join(' AND ');
|
|
32
|
+
condition = `${key} (${subConditions})`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
conditions.push(condition);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Join the conditions with 'AND'
|
|
39
|
+
return conditions.length ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Example Usage
|
|
43
|
+
const json1 = {
|
|
44
|
+
name: "John",
|
|
45
|
+
age: 30,
|
|
46
|
+
active: true,
|
|
47
|
+
hobbies: ["reading", "gaming"],
|
|
48
|
+
address: {
|
|
49
|
+
city: "New York",
|
|
50
|
+
zip: "10001"
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const query1 = jsonToSqlFilter(json1);
|
|
55
|
+
console.log(query1);
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
type QueryCondition = {
|
|
64
|
+
[key: string]: any; // key is field, value is condition or value
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
function jsonToSqlQuery(json: QueryCondition): string {
|
|
68
|
+
const conditions: string[] = [];
|
|
69
|
+
|
|
70
|
+
// Loop through each key-value pair in the JSON object
|
|
71
|
+
for (const [key, value] of Object.entries(json)) {
|
|
72
|
+
let condition = '';
|
|
73
|
+
|
|
74
|
+
// If the value is an object (operator condition)
|
|
75
|
+
if (typeof value === 'object' && value !== null) {
|
|
76
|
+
const operatorConditions: string[] = [];
|
|
77
|
+
let [operator, operatorValue]: any[] = [null, null];
|
|
78
|
+
for ([operator, operatorValue] of Object.entries(value)) {
|
|
79
|
+
switch (operator) {
|
|
80
|
+
case "$eq":
|
|
81
|
+
operatorConditions.push(`${key} = '${operatorValue}'`);
|
|
82
|
+
break;
|
|
83
|
+
case "$gt":
|
|
84
|
+
operatorConditions.push(`${key} > ${operatorValue}`);
|
|
85
|
+
break;
|
|
86
|
+
case "$lt":
|
|
87
|
+
operatorConditions.push(`${key} < ${operatorValue}`);
|
|
88
|
+
break;
|
|
89
|
+
case "$gte":
|
|
90
|
+
operatorConditions.push(`${key} >= ${operatorValue}`);
|
|
91
|
+
break;
|
|
92
|
+
case "$lte":
|
|
93
|
+
operatorConditions.push(`${key} <= ${operatorValue}`);
|
|
94
|
+
break;
|
|
95
|
+
case "$ne":
|
|
96
|
+
operatorConditions.push(`${key} != '${operatorValue}'`);
|
|
97
|
+
break;
|
|
98
|
+
case "$in":
|
|
99
|
+
const inValues = operatorValue.map((val: any) => typeof val === 'string' ? `'${val}'` : val).join(', ');
|
|
100
|
+
operatorConditions.push(`${key} IN (${inValues})`);
|
|
101
|
+
break;
|
|
102
|
+
case "$like":
|
|
103
|
+
operatorConditions.push(`${key} LIKE '%${operatorValue}%'`);
|
|
104
|
+
break;
|
|
105
|
+
default:
|
|
106
|
+
throw new Error(`Unsupported operator: ${operator}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Join all conditions for a field with AND
|
|
110
|
+
condition = operatorConditions.join(' AND ');
|
|
111
|
+
} else {
|
|
112
|
+
// For simple equality condition
|
|
113
|
+
condition = `${key} = '${value}'`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
conditions.push(condition);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Join the conditions with AND
|
|
120
|
+
return conditions.length ? `WHERE ${conditions.join(' AND ')}` : '';
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Example Usage
|
|
124
|
+
const json = {
|
|
125
|
+
"age": { "$gt": 30 },
|
|
126
|
+
"name": { "$eq": "John" },
|
|
127
|
+
"status": { "$in": ["active", "pending"] },
|
|
128
|
+
"address.city": { "$eq": "New York" }
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const query = jsonToSqlQuery(json);
|
|
132
|
+
console.log(query);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function cleanPhoneNumber(num?: string | number | null): string {
|
|
2
|
+
|
|
3
|
+
if (!num) return '';
|
|
4
|
+
|
|
5
|
+
const cleaned = String(num).trim()
|
|
6
|
+
.replace(/(?<!^)\+|[^\d+]+/g, '') // Remove non digits and keep the +
|
|
7
|
+
.replace(/^00/, '+') // Remove preceding '00'
|
|
8
|
+
.replace(/^\+?1(?=\d{10})/, ''); // Remove preceding '+1' or '1' for American numbers
|
|
9
|
+
|
|
10
|
+
return cleaned;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function formatPhone(phone: string) {
|
|
14
|
+
return String(cleanPhoneNumber(phone)).replace(/^(\d{3})(\d{3})(\d{4})/, '$1-$2-$3');
|
|
15
|
+
}
|