@driveflux/api-functions 1.0.77-next.1 → 1.0.77
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/dist/auth/confirm.d.ts +5 -2
- package/dist/auth/confirm.d.ts.map +1 -1
- package/dist/auth/confirm.js +52 -36
- package/dist/auth/confirm.js.map +1 -1
- package/dist/auth/consent.d.ts +17 -0
- package/dist/auth/consent.d.ts.map +1 -0
- package/dist/auth/consent.js +58 -0
- package/dist/auth/consent.js.map +1 -0
- package/dist/auth/emails.js +13 -12
- package/dist/auth/formatter.js +5 -5
- package/dist/auth/otp.js +51 -67
- package/dist/auth/otp.js.map +1 -1
- package/dist/auth/register.d.ts +10 -5
- package/dist/auth/register.d.ts.map +1 -1
- package/dist/auth/register.js +77 -74
- package/dist/auth/register.js.map +1 -1
- package/dist/auth/tokens.js +55 -58
- package/dist/auth/verifications.js +52 -53
- package/dist/constants.js +1 -0
- package/dist/create-logger.js +2 -1
- package/dist/mailjet/calls/manage-contacts-in-list.js +6 -5
- package/dist/mailjet/calls/manage-subscription-status.js +5 -4
- package/dist/mailjet/calls/request-service.js +6 -7
- package/dist/mailjet/refresh-email-preferences.js +12 -11
- package/dist/mailjet/set-contact.js +12 -11
- package/dist/mailjet/types.js +2 -1
- package/dist/mailjet/utils/convert-to-array.js +6 -8
- package/dist/mailjet/utils/extract-email-preferences.js +15 -14
- package/dist/mailjet/utils/lists.js +8 -7
- package/dist/mailjet/utils/update-email-references.js +15 -16
- package/dist/notion/client.js +19 -22
- package/dist/notion/helpful.js +9 -6
- package/dist/notion/schemas/block.js +48 -42
- package/dist/notion/schemas/common.js +14 -9
- package/dist/notion/schemas/database.js +60 -62
- package/dist/notion/schemas/emoji.js +2 -1
- package/dist/notion/schemas/file.js +9 -9
- package/dist/notion/schemas/kb.js +6 -5
- package/dist/notion/schemas/page.js +61 -72
- package/dist/notion/schemas/parent.js +5 -4
- package/dist/notion/schemas/user.js +19 -18
- package/dist/reservation/agree.d.ts +2 -308
- package/dist/reservation/agree.d.ts.map +1 -1
- package/dist/reservation/agree.js +23 -21
- package/dist/reservation/agree.js.map +1 -1
- package/dist/reservation/checks.js +4 -3
- package/dist/reservation/display-vehicle.d.ts +36 -36
- package/dist/reservation/display-vehicle.js +83 -73
- package/dist/reservation/display-vehicle.js.map +1 -1
- package/dist/reservation/ensure-user-billing-address.js +11 -9
- package/dist/reservation/fetch-or-create.d.ts +1 -1
- package/dist/reservation/fetch-or-create.d.ts.map +1 -1
- package/dist/reservation/fetch-or-create.js +56 -51
- package/dist/reservation/fetch-or-create.js.map +1 -1
- package/dist/reservation/invoice.js +88 -77
- package/dist/reservation/payer.js +6 -5
- package/dist/reservation/payment-intent-sync.js +6 -4
- package/dist/reservation/reserve.d.ts.map +1 -1
- package/dist/reservation/reserve.js +9 -5
- package/dist/reservation/reserve.js.map +1 -1
- package/dist/reservation/types.d.ts +9 -1
- package/dist/reservation/types.d.ts.map +1 -1
- package/dist/reservation/types.js +2 -1
- package/dist/reservation/vehicle.js +16 -13
- package/dist/slack.js +29 -24
- package/dist/validation.js +79 -77
- package/dist/vehicle/vehicle-pricing/constants.js +19 -22
- package/dist/vehicle/vehicle-pricing/index.js +42 -28
- package/dist/vehicle/vehicle-pricing/types.js +2 -1
- package/package.json +10 -10
|
@@ -3,16 +3,16 @@ import { Err } from '@driveflux/result';
|
|
|
3
3
|
import { getListByRef } from '../utils/lists.js';
|
|
4
4
|
import { callMailjet } from './request-service.js';
|
|
5
5
|
// Add a contact to a contact list in Mailjet
|
|
6
|
-
export const manageContactsInList = async ({ users, list, action = 'addnoforce' })=>{
|
|
7
|
-
const contacts = users.map((u)=>{
|
|
6
|
+
export const manageContactsInList = async ({ users, list, action = 'addnoforce', }) => {
|
|
7
|
+
const contacts = users.map((u) => {
|
|
8
8
|
return {
|
|
9
9
|
Email: u.email,
|
|
10
10
|
IsExcludedFromCampaigns: false,
|
|
11
11
|
Name: `${u.firstName} ${u.lastName}`,
|
|
12
12
|
Properties: {
|
|
13
13
|
FirstName: u.firstName,
|
|
14
|
-
LastName: u.lastName
|
|
15
|
-
}
|
|
14
|
+
LastName: u.lastName,
|
|
15
|
+
},
|
|
16
16
|
};
|
|
17
17
|
});
|
|
18
18
|
const listOjbect = await getListByRef(list);
|
|
@@ -21,7 +21,8 @@ export const manageContactsInList = async ({ users, list, action = 'addnoforce'
|
|
|
21
21
|
}
|
|
22
22
|
const result = await callMailjet(`contactslist/${listOjbect.id}/managemanycontacts`, {
|
|
23
23
|
Action: action,
|
|
24
|
-
Contacts: contacts
|
|
24
|
+
Contacts: contacts,
|
|
25
25
|
});
|
|
26
26
|
return result;
|
|
27
27
|
};
|
|
28
|
+
//# sourceMappingURL=manage-contacts-in-list.js.map
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { getLists } from '../utils/lists.js';
|
|
2
2
|
import { callMailjet } from './request-service.js';
|
|
3
|
-
export const manageSubscriptionStatus = async (email, updatedLists)=>{
|
|
3
|
+
export const manageSubscriptionStatus = async (email, updatedLists) => {
|
|
4
4
|
const lists = await getLists();
|
|
5
5
|
const data = {
|
|
6
|
-
ContactsLists: updatedLists.map((item)=>{
|
|
6
|
+
ContactsLists: updatedLists.map((item) => {
|
|
7
7
|
return {
|
|
8
8
|
Action: item.action,
|
|
9
|
-
ListID: lists[item.list]
|
|
9
|
+
ListID: lists[item.list],
|
|
10
10
|
};
|
|
11
|
-
})
|
|
11
|
+
}),
|
|
12
12
|
};
|
|
13
13
|
const result = await callMailjet(`/contact/${email}/managecontactslists`, data);
|
|
14
14
|
return result;
|
|
15
15
|
};
|
|
16
|
+
//# sourceMappingURL=manage-subscription-status.js.map
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import { config } from '@driveflux/email';
|
|
2
2
|
import { enhancedFetch } from '@driveflux/fetch';
|
|
3
|
-
const getAuth = ()=>{
|
|
3
|
+
const getAuth = () => {
|
|
4
4
|
const authData = {
|
|
5
5
|
publicKey: config.mailjet.apiKeyPublic || process.env.MAILJET_API_KEY_PUBLIC,
|
|
6
|
-
privateKey: config.mailjet.apiKeyPrivate || process.env.MAILJET_API_KEY_PRIVATE
|
|
6
|
+
privateKey: config.mailjet.apiKeyPrivate || process.env.MAILJET_API_KEY_PRIVATE,
|
|
7
7
|
};
|
|
8
8
|
const authLine = `${authData.publicKey}:${authData.privateKey}`;
|
|
9
9
|
return `Basic ${Buffer.from(authLine).toString('base64')}`;
|
|
10
10
|
};
|
|
11
11
|
const baseUrl = 'https://api.mailjet.com/v3/REST';
|
|
12
|
-
export const callMailjet = async (path, data, method = 'POST')=>{
|
|
12
|
+
export const callMailjet = async (path, data, method = 'POST') => {
|
|
13
13
|
const url = `${baseUrl}${path}`;
|
|
14
14
|
const result = await enhancedFetch(url, {
|
|
15
15
|
method,
|
|
16
16
|
headers: {
|
|
17
17
|
'Content-Type': 'application/json',
|
|
18
|
-
Authorization: getAuth()
|
|
18
|
+
Authorization: getAuth(),
|
|
19
19
|
},
|
|
20
|
-
...method !== 'GET' ? {
|
|
21
|
-
body: JSON.stringify(data)
|
|
22
|
-
} : {}
|
|
20
|
+
...(method !== 'GET' ? { body: JSON.stringify(data) } : {}),
|
|
23
21
|
});
|
|
24
22
|
return result;
|
|
25
23
|
};
|
|
24
|
+
//# sourceMappingURL=request-service.js.map
|
|
@@ -14,18 +14,18 @@ const userForRefreshEmailPreferencesQuery = {
|
|
|
14
14
|
subscriptions: {
|
|
15
15
|
select: {
|
|
16
16
|
ended: true,
|
|
17
|
-
active: true
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
export const refreshEmailPreferences = async (idOrUserForRefreshEmailPreferences)=>{
|
|
23
|
-
const user = typeof idOrUserForRefreshEmailPreferences === 'string' ? await prisma.user.findUnique({
|
|
24
|
-
where: {
|
|
25
|
-
id: idOrUserForRefreshEmailPreferences
|
|
17
|
+
active: true,
|
|
18
|
+
},
|
|
26
19
|
},
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
export const refreshEmailPreferences = async (idOrUserForRefreshEmailPreferences) => {
|
|
23
|
+
const user = typeof idOrUserForRefreshEmailPreferences === 'string'
|
|
24
|
+
? await prisma.user.findUnique({
|
|
25
|
+
where: { id: idOrUserForRefreshEmailPreferences },
|
|
26
|
+
...userForRefreshEmailPreferencesQuery,
|
|
27
|
+
})
|
|
28
|
+
: idOrUserForRefreshEmailPreferences;
|
|
29
29
|
if (!user) {
|
|
30
30
|
return new Err(makeProblem(PROBLEM_NOT_FOUND, 'User not found'));
|
|
31
31
|
}
|
|
@@ -40,3 +40,4 @@ export const refreshEmailPreferences = async (idOrUserForRefreshEmailPreferences
|
|
|
40
40
|
const items = convertToArray(preferences, !!updated?.businessId);
|
|
41
41
|
return await manageSubscriptionStatus(user.email, items);
|
|
42
42
|
};
|
|
43
|
+
//# sourceMappingURL=refresh-email-preferences.js.map
|
|
@@ -13,18 +13,18 @@ const userForSetInContactListlPreferencesQuery = {
|
|
|
13
13
|
subscriptions: {
|
|
14
14
|
select: {
|
|
15
15
|
ended: true,
|
|
16
|
-
active: true
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
export const setContactInList = async (idOrUserForSetInContactListlPreferences, preferences)=>{
|
|
22
|
-
const user = typeof idOrUserForSetInContactListlPreferences === 'string' ? await prisma.user.findUnique({
|
|
23
|
-
where: {
|
|
24
|
-
id: idOrUserForSetInContactListlPreferences
|
|
16
|
+
active: true,
|
|
17
|
+
},
|
|
25
18
|
},
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
export const setContactInList = async (idOrUserForSetInContactListlPreferences, preferences) => {
|
|
22
|
+
const user = typeof idOrUserForSetInContactListlPreferences === 'string'
|
|
23
|
+
? await prisma.user.findUnique({
|
|
24
|
+
where: { id: idOrUserForSetInContactListlPreferences },
|
|
25
|
+
...userForSetInContactListlPreferencesQuery,
|
|
26
|
+
})
|
|
27
|
+
: idOrUserForSetInContactListlPreferences;
|
|
28
28
|
if (!user) {
|
|
29
29
|
return new Err(makeProblem(PROBLEM_NOT_FOUND, 'User not found'));
|
|
30
30
|
}
|
|
@@ -36,3 +36,4 @@ export const setContactInList = async (idOrUserForSetInContactListlPreferences,
|
|
|
36
36
|
const results = await manageSubscriptionStatus(user.email, items);
|
|
37
37
|
return new Ok(results);
|
|
38
38
|
};
|
|
39
|
+
//# sourceMappingURL=set-contact.js.map
|
package/dist/mailjet/types.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const convertToArray = (preferences, isBusiness)=>{
|
|
1
|
+
export const convertToArray = (preferences, isBusiness) => {
|
|
2
2
|
if (!preferences) {
|
|
3
3
|
return [];
|
|
4
4
|
}
|
|
@@ -6,20 +6,18 @@ export const convertToArray = (preferences, isBusiness)=>{
|
|
|
6
6
|
if (typeof isBusiness === 'boolean') {
|
|
7
7
|
preferencesArray.push([
|
|
8
8
|
'activeSubBusiness',
|
|
9
|
-
!!preferences?.activeSub && isBusiness
|
|
9
|
+
!!preferences?.activeSub && isBusiness,
|
|
10
10
|
]);
|
|
11
11
|
preferencesArray.push([
|
|
12
12
|
'activeSubPersonal',
|
|
13
|
-
!!preferences?.activeSub && !isBusiness
|
|
13
|
+
!!preferences?.activeSub && !isBusiness,
|
|
14
14
|
]);
|
|
15
15
|
}
|
|
16
|
-
const items = preferencesArray.map(([key, value])=>{
|
|
16
|
+
const items = preferencesArray.map(([key, value]) => {
|
|
17
17
|
const list = key;
|
|
18
18
|
const action = value ? 'addnoforce' : 'unsub';
|
|
19
|
-
return {
|
|
20
|
-
list,
|
|
21
|
-
action
|
|
22
|
-
};
|
|
19
|
+
return { list, action };
|
|
23
20
|
});
|
|
24
21
|
return items;
|
|
25
22
|
};
|
|
23
|
+
//# sourceMappingURL=convert-to-array.js.map
|
|
@@ -6,18 +6,18 @@ export const userForEmailPreferencesQuery = {
|
|
|
6
6
|
subscriptions: {
|
|
7
7
|
select: {
|
|
8
8
|
ended: true,
|
|
9
|
-
active: true
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
export const extractUserEmailPreferences = async (idOrUserForEmailPreferences)=>{
|
|
15
|
-
const user = typeof idOrUserForEmailPreferences === 'string' ? await prisma.user.findUnique({
|
|
16
|
-
where: {
|
|
17
|
-
id: idOrUserForEmailPreferences
|
|
9
|
+
active: true,
|
|
10
|
+
},
|
|
18
11
|
},
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
export const extractUserEmailPreferences = async (idOrUserForEmailPreferences) => {
|
|
15
|
+
const user = typeof idOrUserForEmailPreferences === 'string'
|
|
16
|
+
? await prisma.user.findUnique({
|
|
17
|
+
where: { id: idOrUserForEmailPreferences },
|
|
18
|
+
...userForEmailPreferencesQuery,
|
|
19
|
+
})
|
|
20
|
+
: idOrUserForEmailPreferences;
|
|
21
21
|
if (!user?.emailPreferences?.generalMarketing) {
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
@@ -26,13 +26,13 @@ export const extractUserEmailPreferences = async (idOrUserForEmailPreferences)=>
|
|
|
26
26
|
if (subscriptions.length > 0) {
|
|
27
27
|
list = 'noActiveSubs';
|
|
28
28
|
}
|
|
29
|
-
for(let i = 0; i < subscriptions.length; i++){
|
|
29
|
+
for (let i = 0; i < subscriptions.length; i++) {
|
|
30
30
|
if (subscriptions[i].ended) {
|
|
31
31
|
list = 'expiredSub';
|
|
32
32
|
break;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
for(let i = 0; i < subscriptions.length; i++){
|
|
35
|
+
for (let i = 0; i < subscriptions.length; i++) {
|
|
36
36
|
if (subscriptions[i].active && !subscriptions[i].ended) {
|
|
37
37
|
list = 'activeSub';
|
|
38
38
|
break;
|
|
@@ -44,7 +44,8 @@ export const extractUserEmailPreferences = async (idOrUserForEmailPreferences)=>
|
|
|
44
44
|
signUpPaymentAdded: false,
|
|
45
45
|
activeSub: false,
|
|
46
46
|
expiredSub: false,
|
|
47
|
-
[list]: true
|
|
47
|
+
[list]: true,
|
|
48
48
|
};
|
|
49
49
|
return newList;
|
|
50
50
|
};
|
|
51
|
+
//# sourceMappingURL=extract-email-preferences.js.map
|
|
@@ -7,13 +7,13 @@ export const listsNames = [
|
|
|
7
7
|
'activeSub',
|
|
8
8
|
'expiredSub',
|
|
9
9
|
'activeSubBusiness',
|
|
10
|
-
'activeSubPersonal'
|
|
10
|
+
'activeSubPersonal',
|
|
11
11
|
];
|
|
12
|
-
export const getLists = async ()=>{
|
|
12
|
+
export const getLists = async () => {
|
|
13
13
|
const listObject = await prisma.platformConfig.findFirst({
|
|
14
14
|
where: {
|
|
15
|
-
key: 'mailjetLists'
|
|
16
|
-
}
|
|
15
|
+
key: 'mailjetLists',
|
|
16
|
+
},
|
|
17
17
|
});
|
|
18
18
|
if (listObject?.value) {
|
|
19
19
|
const lists = JSON.parse(listObject.value);
|
|
@@ -21,14 +21,14 @@ export const getLists = async ()=>{
|
|
|
21
21
|
}
|
|
22
22
|
return {};
|
|
23
23
|
};
|
|
24
|
-
export const getListByRef = async (ref)=>{
|
|
24
|
+
export const getListByRef = async (ref) => {
|
|
25
25
|
const lists = await getLists();
|
|
26
26
|
let list;
|
|
27
|
-
for (const [name, id] of Object.entries(lists)){
|
|
27
|
+
for (const [name, id] of Object.entries(lists)) {
|
|
28
28
|
if (name === ref || id === ref) {
|
|
29
29
|
list = {
|
|
30
30
|
name: name,
|
|
31
|
-
id
|
|
31
|
+
id,
|
|
32
32
|
};
|
|
33
33
|
break;
|
|
34
34
|
}
|
|
@@ -38,3 +38,4 @@ export const getListByRef = async (ref)=>{
|
|
|
38
38
|
}
|
|
39
39
|
return list;
|
|
40
40
|
};
|
|
41
|
+
//# sourceMappingURL=lists.js.map
|
|
@@ -1,32 +1,31 @@
|
|
|
1
1
|
import { prisma } from '@driveflux/db';
|
|
2
|
-
import { userForEmailPreferencesQuery } from './extract-email-preferences.js';
|
|
3
|
-
export const updateEmailPreferences = async (idOrUserForEmailPreferences, preferences)=>{
|
|
4
|
-
const user = typeof idOrUserForEmailPreferences === 'string'
|
|
5
|
-
|
|
6
|
-
id: idOrUserForEmailPreferences
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
import { userForEmailPreferencesQuery, } from './extract-email-preferences.js';
|
|
3
|
+
export const updateEmailPreferences = async (idOrUserForEmailPreferences, preferences) => {
|
|
4
|
+
const user = typeof idOrUserForEmailPreferences === 'string'
|
|
5
|
+
? await prisma.user.findUnique({
|
|
6
|
+
where: { id: idOrUserForEmailPreferences },
|
|
7
|
+
...userForEmailPreferencesQuery,
|
|
8
|
+
})
|
|
9
|
+
: idOrUserForEmailPreferences;
|
|
10
10
|
if (!user) {
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
13
13
|
const merged = {
|
|
14
14
|
...user.emailPreferences,
|
|
15
|
-
...preferences
|
|
15
|
+
...preferences,
|
|
16
16
|
};
|
|
17
17
|
const updated = await prisma.user.update({
|
|
18
|
-
where: {
|
|
19
|
-
id: user.id
|
|
20
|
-
},
|
|
18
|
+
where: { id: user.id },
|
|
21
19
|
data: {
|
|
22
20
|
emailPreferences: {
|
|
23
21
|
upsert: {
|
|
24
22
|
set: merged,
|
|
25
|
-
update: merged
|
|
26
|
-
}
|
|
27
|
-
}
|
|
23
|
+
update: merged,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
28
26
|
},
|
|
29
|
-
...userForEmailPreferencesQuery
|
|
27
|
+
...userForEmailPreferencesQuery,
|
|
30
28
|
});
|
|
31
29
|
return updated;
|
|
32
30
|
};
|
|
31
|
+
//# sourceMappingURL=update-email-references.js.map
|
package/dist/notion/client.js
CHANGED
|
@@ -2,23 +2,20 @@ import { slackLater } from '@driveflux/api-functions/slack';
|
|
|
2
2
|
import { config } from '@driveflux/config/backend';
|
|
3
3
|
import { initSingleton } from '@driveflux/singleton';
|
|
4
4
|
import { Client } from '@notionhq/client';
|
|
5
|
-
export const getNotion = ()=>{
|
|
6
|
-
return initSingleton('notionClient', ()=>new Client({
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
export const getNotion = () => {
|
|
6
|
+
return initSingleton('notionClient', () => new Client({
|
|
7
|
+
auth: config.notion.secret,
|
|
8
|
+
}));
|
|
9
9
|
};
|
|
10
|
-
export const announceFluxstersAnniversaries = async (property, constructMessage)=>{
|
|
10
|
+
export const announceFluxstersAnniversaries = async (property, constructMessage) => {
|
|
11
11
|
if (!config.notion.fluxstersDatabaseId) {
|
|
12
|
-
return {
|
|
13
|
-
counts: -1,
|
|
14
|
-
message: 'No fluxsters database id configured'
|
|
15
|
-
};
|
|
12
|
+
return { counts: -1, message: 'No fluxsters database id configured' };
|
|
16
13
|
}
|
|
17
14
|
const notion = getNotion();
|
|
18
15
|
const { results } = await notion.dataSources.query({
|
|
19
|
-
data_source_id: config.notion.fluxstersDatabaseId
|
|
16
|
+
data_source_id: config.notion.fluxstersDatabaseId,
|
|
20
17
|
});
|
|
21
|
-
const relevantPeople = results.filter((result)=>{
|
|
18
|
+
const relevantPeople = results.filter((result) => {
|
|
22
19
|
const resultPropperty = result.properties[property];
|
|
23
20
|
if (resultPropperty.type !== 'date' || !resultPropperty.date?.start) {
|
|
24
21
|
return false;
|
|
@@ -28,11 +25,15 @@ export const announceFluxstersAnniversaries = async (property, constructMessage)
|
|
|
28
25
|
}
|
|
29
26
|
const date = new Date(resultPropperty.date.start);
|
|
30
27
|
const todayDate = new Date();
|
|
31
|
-
if (todayDate.getDate() === date.getDate() &&
|
|
28
|
+
if (todayDate.getDate() === date.getDate() &&
|
|
29
|
+
todayDate.getMonth() === date.getMonth()) {
|
|
32
30
|
return true;
|
|
33
31
|
}
|
|
34
32
|
// leap year
|
|
35
|
-
if (todayDate.getDate() === 28 &&
|
|
33
|
+
if (todayDate.getDate() === 28 &&
|
|
34
|
+
date.getDate() === 29 &&
|
|
35
|
+
todayDate.getMonth() === 1 &&
|
|
36
|
+
date.getMonth() === 1) {
|
|
36
37
|
return true;
|
|
37
38
|
}
|
|
38
39
|
return false;
|
|
@@ -40,23 +41,18 @@ export const announceFluxstersAnniversaries = async (property, constructMessage)
|
|
|
40
41
|
if (relevantPeople.length > 0) {
|
|
41
42
|
const message = constructMessage(relevantPeople);
|
|
42
43
|
slackLater(message, config.slack.mainFluxChannel);
|
|
43
|
-
return {
|
|
44
|
-
counts: relevantPeople.length,
|
|
45
|
-
message
|
|
46
|
-
};
|
|
44
|
+
return { counts: relevantPeople.length, message };
|
|
47
45
|
}
|
|
48
|
-
return {
|
|
49
|
-
counts: relevantPeople.length
|
|
50
|
-
};
|
|
46
|
+
return { counts: relevantPeople.length };
|
|
51
47
|
};
|
|
52
|
-
export const getNameFrom = (person)=>{
|
|
48
|
+
export const getNameFrom = (person) => {
|
|
53
49
|
const nameProperty = person.properties.Name;
|
|
54
50
|
if (nameProperty.type !== 'title') {
|
|
55
51
|
return '';
|
|
56
52
|
}
|
|
57
53
|
return nameProperty.title[0].plain_text;
|
|
58
54
|
};
|
|
59
|
-
export const calculateYears = (person, property)=>{
|
|
55
|
+
export const calculateYears = (person, property) => {
|
|
60
56
|
const joinedDateProperty = person.properties[property];
|
|
61
57
|
if (joinedDateProperty.type !== 'date' || !joinedDateProperty.date?.start) {
|
|
62
58
|
return 0;
|
|
@@ -65,3 +61,4 @@ export const calculateYears = (person, property)=>{
|
|
|
65
61
|
const joinedDate = new Date(joinedDateProperty.date?.start);
|
|
66
62
|
return today.getFullYear() - joinedDate.getFullYear();
|
|
67
63
|
};
|
|
64
|
+
//# sourceMappingURL=client.js.map
|
package/dist/notion/helpful.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { getNotion } from '@driveflux/api-functions/notion';
|
|
2
2
|
import { knowledgeBaseRetrievePageSchema } from './schemas/kb.js';
|
|
3
|
-
export const processHelpful = async (options)=>{
|
|
3
|
+
export const processHelpful = async (options) => {
|
|
4
4
|
const { pageId, isHelpful, hasSubmittedBefore } = options;
|
|
5
5
|
// get original page
|
|
6
6
|
const notion = getNotion();
|
|
7
7
|
const page = await notion.pages.retrieve({
|
|
8
|
-
page_id: pageId
|
|
8
|
+
page_id: pageId,
|
|
9
9
|
});
|
|
10
10
|
// validate page
|
|
11
11
|
const kbPageValidation = knowledgeBaseRetrievePageSchema.safeParse(page);
|
|
@@ -18,12 +18,15 @@ export const processHelpful = async (options)=>{
|
|
|
18
18
|
page_id: pageId,
|
|
19
19
|
properties: {
|
|
20
20
|
Helpful: {
|
|
21
|
-
number: (validatedPage.properties.Helpful.number || 0) +
|
|
21
|
+
number: (validatedPage.properties.Helpful.number || 0) +
|
|
22
|
+
(hasSubmittedBefore && !isHelpful ? -1 : isHelpful ? 1 : 0),
|
|
22
23
|
},
|
|
23
24
|
Unhelpful: {
|
|
24
|
-
number: (validatedPage.properties.Unhelpful.number || 0) +
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
number: (validatedPage.properties.Unhelpful.number || 0) +
|
|
26
|
+
(hasSubmittedBefore && isHelpful ? -1 : !isHelpful ? 1 : 0),
|
|
27
|
+
},
|
|
28
|
+
},
|
|
27
29
|
});
|
|
28
30
|
return true;
|
|
29
31
|
};
|
|
32
|
+
//# sourceMappingURL=helpful.js.map
|
|
@@ -2,54 +2,59 @@ import { z } from 'zod';
|
|
|
2
2
|
import { notionDateSchema } from './common.js';
|
|
3
3
|
import { notionPartialUserSchema } from './user.js';
|
|
4
4
|
export const notionRichTextSchema = z.object({
|
|
5
|
-
type: z.enum([
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
mention: z.object({
|
|
5
|
+
type: z.enum(['text', 'mention', 'equation']),
|
|
6
|
+
equation: z
|
|
7
|
+
.object({
|
|
8
|
+
expression: z.string(),
|
|
9
|
+
})
|
|
10
|
+
.optional(),
|
|
11
|
+
mention: z
|
|
12
|
+
.object({
|
|
14
13
|
type: z.enum([
|
|
15
14
|
'database',
|
|
16
15
|
'date',
|
|
17
16
|
'link_preview',
|
|
18
17
|
'page',
|
|
19
18
|
'template_mention',
|
|
20
|
-
'user'
|
|
19
|
+
'user',
|
|
21
20
|
]),
|
|
22
|
-
database: z
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
database: z
|
|
22
|
+
.object({
|
|
23
|
+
id: z.string(),
|
|
24
|
+
})
|
|
25
|
+
.optional(),
|
|
25
26
|
date: notionDateSchema.optional(),
|
|
26
|
-
link_preview: z
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
]).optional(),
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
27
|
+
link_preview: z
|
|
28
|
+
.object({
|
|
29
|
+
url: z.string().url(),
|
|
30
|
+
})
|
|
31
|
+
.optional(),
|
|
32
|
+
page: z
|
|
33
|
+
.object({
|
|
34
|
+
id: z.string(),
|
|
35
|
+
})
|
|
36
|
+
.optional(),
|
|
37
|
+
template_mention: z
|
|
38
|
+
.object({
|
|
39
|
+
type: z.enum(['template_mention_date', 'template_mention_user']),
|
|
40
|
+
template_mention_date: z.enum(['today', 'now']).optional(),
|
|
41
|
+
template_mention_user: z.enum(['me']).optional(),
|
|
42
|
+
})
|
|
43
|
+
.optional(),
|
|
44
|
+
user: notionPartialUserSchema.optional(),
|
|
45
|
+
})
|
|
46
|
+
.optional(),
|
|
47
|
+
text: z
|
|
48
|
+
.object({
|
|
48
49
|
content: z.string(),
|
|
49
|
-
link: z
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
link: z
|
|
51
|
+
.object({
|
|
52
|
+
url: z.string().url(),
|
|
53
|
+
})
|
|
54
|
+
.nullable()
|
|
55
|
+
.optional(),
|
|
56
|
+
})
|
|
57
|
+
.optional(),
|
|
53
58
|
annotations: z.object({
|
|
54
59
|
bold: z.boolean(),
|
|
55
60
|
italic: z.boolean(),
|
|
@@ -75,9 +80,10 @@ export const notionRichTextSchema = z.object({
|
|
|
75
80
|
'red',
|
|
76
81
|
'red_background',
|
|
77
82
|
'yellow',
|
|
78
|
-
'yellow_background'
|
|
79
|
-
])
|
|
83
|
+
'yellow_background',
|
|
84
|
+
]),
|
|
80
85
|
}),
|
|
81
86
|
plain_text: z.string(),
|
|
82
|
-
href: z.string().url().nullable().optional()
|
|
87
|
+
href: z.string().url().nullable().optional(),
|
|
83
88
|
});
|
|
89
|
+
//# sourceMappingURL=block.js.map
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
export const notionDateOrTimeFormat = z
|
|
2
|
+
export const notionDateOrTimeFormat = z
|
|
3
|
+
.string()
|
|
4
|
+
.regex(/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d{3})?(Z|\+\d{2}:\d{2}))?$/);
|
|
3
5
|
export const notionDateFormat = z.string().regex(/^\d{4}-\d{2}-\d{2}$/);
|
|
4
|
-
export const notionTimeFormat = z
|
|
6
|
+
export const notionTimeFormat = z
|
|
7
|
+
.string()
|
|
8
|
+
.regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/);
|
|
5
9
|
export const notionCommonColorEnum = z.enum([
|
|
6
10
|
'blue',
|
|
7
11
|
'brown',
|
|
@@ -12,15 +16,16 @@ export const notionCommonColorEnum = z.enum([
|
|
|
12
16
|
'pink',
|
|
13
17
|
'purple',
|
|
14
18
|
'red',
|
|
15
|
-
'yellow'
|
|
19
|
+
'yellow',
|
|
16
20
|
]);
|
|
17
21
|
export const notionDateSchema = z.object({
|
|
18
22
|
start: notionDateOrTimeFormat,
|
|
19
23
|
end: notionDateOrTimeFormat.nullable().optional(),
|
|
20
|
-
time_zone: z.string().nullable().optional()
|
|
24
|
+
time_zone: z.string().nullable().optional(),
|
|
21
25
|
});
|
|
22
|
-
export const commonPropertyValues = (type)=>({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
export const commonPropertyValues = (type) => ({
|
|
27
|
+
id: z.string(),
|
|
28
|
+
type: z.literal(type),
|
|
29
|
+
name: z.string().optional(),
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=common.js.map
|