plenna_utilities 1.2.0 → 1.3.1
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/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/src/airTable/index.d.ts +5 -0
- package/dist/src/airTable/index.js +27 -0
- package/dist/src/customerio/index.d.ts +7 -0
- package/dist/src/customerio/index.js +24 -0
- package/dist/src/mailer/index.d.ts +9 -0
- package/dist/src/mailer/index.js +32 -0
- package/dist/src/time/index.d.ts +1 -0
- package/dist/src/time/index.js +12 -1
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -19,3 +19,6 @@ __exportStar(require("./src/time"), exports);
|
|
|
19
19
|
__exportStar(require("./src/s3"), exports);
|
|
20
20
|
__exportStar(require("./src/google"), exports);
|
|
21
21
|
__exportStar(require("./src/general"), exports);
|
|
22
|
+
__exportStar(require("./src/customerio"), exports);
|
|
23
|
+
__exportStar(require("./src/mailer"), exports);
|
|
24
|
+
__exportStar(require("./src/airTable"), exports);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AirTable = void 0;
|
|
4
|
+
class AirTable {
|
|
5
|
+
webhook;
|
|
6
|
+
constructor(webhook) {
|
|
7
|
+
this.webhook = webhook;
|
|
8
|
+
}
|
|
9
|
+
async sendToAirTable(payload) {
|
|
10
|
+
try {
|
|
11
|
+
const response = await fetch(this.webhook, {
|
|
12
|
+
method: 'post',
|
|
13
|
+
body: JSON.stringify(payload),
|
|
14
|
+
headers: {
|
|
15
|
+
'Content-Type': 'application/json'
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
console.log(response);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.log(error);
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.AirTable = AirTable;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type SendPushRequestOptions } from 'customerio-node/dist/lib/api/requests';
|
|
2
|
+
export type PushRequestOptions = SendPushRequestOptions;
|
|
3
|
+
export declare class CustomerIo {
|
|
4
|
+
private readonly key;
|
|
5
|
+
constructor(key: string);
|
|
6
|
+
sendPushNotification(requestOptions: PushRequestOptions): Promise<boolean>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomerIo = void 0;
|
|
4
|
+
const customerio_node_1 = require("customerio-node");
|
|
5
|
+
class CustomerIo {
|
|
6
|
+
key;
|
|
7
|
+
constructor(key) {
|
|
8
|
+
this.key = key;
|
|
9
|
+
}
|
|
10
|
+
async sendPushNotification(requestOptions) {
|
|
11
|
+
try {
|
|
12
|
+
const request = new customerio_node_1.SendPushRequest(requestOptions);
|
|
13
|
+
const api = new customerio_node_1.APIClient(this.key, { region: customerio_node_1.RegionUS });
|
|
14
|
+
const response = await api.sendPush(request);
|
|
15
|
+
console.log('Sent push notification success: ', response);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
console.error('Failed to send push notification: ', error);
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.CustomerIo = CustomerIo;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Mailer = void 0;
|
|
4
|
+
class Mailer {
|
|
5
|
+
apiKey;
|
|
6
|
+
constructor(apiKey) {
|
|
7
|
+
this.apiKey = apiKey;
|
|
8
|
+
}
|
|
9
|
+
async sendEmail(templateId, destiny, params) {
|
|
10
|
+
try {
|
|
11
|
+
await fetch('https://api.sendinblue.com/v3/smtp/email', {
|
|
12
|
+
method: 'post',
|
|
13
|
+
headers: {
|
|
14
|
+
accept: 'application/json',
|
|
15
|
+
'api-key': this.apiKey,
|
|
16
|
+
'content-type': 'application/json'
|
|
17
|
+
},
|
|
18
|
+
body: JSON.stringify({
|
|
19
|
+
to: destiny,
|
|
20
|
+
params,
|
|
21
|
+
templateId
|
|
22
|
+
})
|
|
23
|
+
});
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
console.log('error sending email');
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.Mailer = Mailer;
|
package/dist/src/time/index.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ export declare const compare: (left: Date, right: Date) => boolean;
|
|
|
4
4
|
export declare const getAge: (date: Date) => string;
|
|
5
5
|
export declare const getDeltaTime: (start: Date, end: Date) => number;
|
|
6
6
|
export declare const getMonthDifference: (startDate: Date, endDate: Date) => number;
|
|
7
|
+
export declare const addWorkDays: (startDate: Date, days: number) => Date;
|
package/dist/src/time/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMonthDifference = exports.getDeltaTime = exports.getAge = exports.compare = exports.isValidNumeric = exports.fixAppointmentDateStart = void 0;
|
|
3
|
+
exports.addWorkDays = exports.getMonthDifference = exports.getDeltaTime = exports.getAge = exports.compare = exports.isValidNumeric = exports.fixAppointmentDateStart = void 0;
|
|
4
4
|
const fixAppointmentDateStart = (date, start) => {
|
|
5
5
|
const [hour, minutes] = start.split(':');
|
|
6
6
|
const fixedDate = new Date(date).setUTCHours(parseInt(hour ?? 0) + 6, parseInt(minutes ?? 0));
|
|
@@ -36,3 +36,14 @@ const getMonthDifference = (startDate, endDate) => {
|
|
|
36
36
|
return calculated;
|
|
37
37
|
};
|
|
38
38
|
exports.getMonthDifference = getMonthDifference;
|
|
39
|
+
const addWorkDays = (startDate, days) => {
|
|
40
|
+
const targetDate = new Date(startDate);
|
|
41
|
+
while (days > 0) {
|
|
42
|
+
targetDate.setUTCDate(targetDate.getUTCDate() + 1);
|
|
43
|
+
if (![6, 0].includes(targetDate.getUTCDay())) {
|
|
44
|
+
days--;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return targetDate;
|
|
48
|
+
};
|
|
49
|
+
exports.addWorkDays = addWorkDays;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "plenna_utilities",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "plenna's utils for backend projects",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"@googleapis/docs": "^3.0.2",
|
|
39
39
|
"@googleapis/drive": "^8.10.0",
|
|
40
40
|
"@googleapis/sheets": "^8.0.0",
|
|
41
|
+
"customerio-node": "^4.1.1",
|
|
41
42
|
"google-auth-library": "^9.11.0"
|
|
42
43
|
}
|
|
43
44
|
}
|