@friggframework/api-module-zoho-crm 2.0.0-next.6 → 2.0.0-next.8
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/api.d.ts +8 -0
- package/dist/api.js +63 -1
- package/package.json +2 -2
package/dist/api.d.ts
CHANGED
|
@@ -87,6 +87,14 @@ export declare class Api extends OAuth2Requester {
|
|
|
87
87
|
* @see https://www.zoho.com/crm/developer/docs/api/v8/notifications/enable.html
|
|
88
88
|
*/
|
|
89
89
|
enableNotification(body: NotificationWatchConfig): Promise<NotificationResponse>;
|
|
90
|
+
/**
|
|
91
|
+
* Update/renew notification channel configuration
|
|
92
|
+
* Use this to extend the channel_expiry before it expires (max 7 days from now)
|
|
93
|
+
* @param body - Notification configuration with watch items to update
|
|
94
|
+
* @returns Promise<NotificationResponse> Response with updated channel details
|
|
95
|
+
* @see https://www.zoho.com/crm/developer/docs/api/v8/notifications/update.html
|
|
96
|
+
*/
|
|
97
|
+
updateNotification(body: NotificationWatchConfig): Promise<NotificationResponse>;
|
|
90
98
|
/**
|
|
91
99
|
* Disable notification channels
|
|
92
100
|
* @param channelIds - Array of channel IDs to disable
|
package/dist/api.js
CHANGED
|
@@ -18,6 +18,15 @@ const LOCATION_CONFIG = {
|
|
|
18
18
|
sa: { accounts: 'https://accounts.zoho.sa', api: 'https://www.zohoapis.sa' },
|
|
19
19
|
};
|
|
20
20
|
const DEFAULT_LOCATION = 'us';
|
|
21
|
+
/**
|
|
22
|
+
* Formats datetime for Zoho API (removes milliseconds, converts Z to +00:00)
|
|
23
|
+
* Zoho expects format: 2019-05-02T15:00:00+05:30
|
|
24
|
+
*/
|
|
25
|
+
function formatDateTimeForZoho(dateStr) {
|
|
26
|
+
if (!dateStr)
|
|
27
|
+
return dateStr;
|
|
28
|
+
return dateStr.replace(/\.\d{3}Z$/, '+00:00').replace(/Z$/, '+00:00');
|
|
29
|
+
}
|
|
21
30
|
class Api extends core_1.OAuth2Requester {
|
|
22
31
|
constructor(params) {
|
|
23
32
|
super(params);
|
|
@@ -78,6 +87,9 @@ class Api extends core_1.OAuth2Requester {
|
|
|
78
87
|
url: this.tokenUri,
|
|
79
88
|
};
|
|
80
89
|
const response = await this._post(options, false);
|
|
90
|
+
if (response.error) {
|
|
91
|
+
throw new Error(`[Zoho API] Zoho token exchange failed: ${response.error}`);
|
|
92
|
+
}
|
|
81
93
|
await this.setTokens(response);
|
|
82
94
|
return response;
|
|
83
95
|
}
|
|
@@ -515,10 +527,60 @@ class Api extends core_1.OAuth2Requester {
|
|
|
515
527
|
throw new Error(`watch[${index}].token must be 50 characters or less`);
|
|
516
528
|
}
|
|
517
529
|
});
|
|
530
|
+
const formattedBody = {
|
|
531
|
+
...body,
|
|
532
|
+
watch: body.watch.map(item => ({
|
|
533
|
+
...item,
|
|
534
|
+
...(item.channel_expiry && { channel_expiry: formatDateTimeForZoho(item.channel_expiry) })
|
|
535
|
+
}))
|
|
536
|
+
};
|
|
518
537
|
try {
|
|
519
538
|
return await this._post({
|
|
520
539
|
url: this.baseUrl + this.URLs.notificationsWatch,
|
|
521
|
-
body:
|
|
540
|
+
body: formattedBody,
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
catch (error) {
|
|
544
|
+
throw error;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Update/renew notification channel configuration
|
|
549
|
+
* Use this to extend the channel_expiry before it expires (max 7 days from now)
|
|
550
|
+
* @param body - Notification configuration with watch items to update
|
|
551
|
+
* @returns Promise<NotificationResponse> Response with updated channel details
|
|
552
|
+
* @see https://www.zoho.com/crm/developer/docs/api/v8/notifications/update.html
|
|
553
|
+
*/
|
|
554
|
+
async updateNotification(body) {
|
|
555
|
+
if (!body || !body.watch || !Array.isArray(body.watch)) {
|
|
556
|
+
throw new Error('Body must contain watch array');
|
|
557
|
+
}
|
|
558
|
+
// Validate each watch item
|
|
559
|
+
body.watch.forEach((item, index) => {
|
|
560
|
+
if (!item.channel_id) {
|
|
561
|
+
throw new Error(`watch[${index}].channel_id is required`);
|
|
562
|
+
}
|
|
563
|
+
if (!item.events || !Array.isArray(item.events) || item.events.length === 0) {
|
|
564
|
+
throw new Error(`watch[${index}].events must be a non-empty array`);
|
|
565
|
+
}
|
|
566
|
+
if (!item.notify_url) {
|
|
567
|
+
throw new Error(`watch[${index}].notify_url is required`);
|
|
568
|
+
}
|
|
569
|
+
if (item.token && item.token.length > 50) {
|
|
570
|
+
throw new Error(`watch[${index}].token must be 50 characters or less`);
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
const formattedBody = {
|
|
574
|
+
...body,
|
|
575
|
+
watch: body.watch.map(item => ({
|
|
576
|
+
...item,
|
|
577
|
+
...(item.channel_expiry && { channel_expiry: formatDateTimeForZoho(item.channel_expiry) })
|
|
578
|
+
}))
|
|
579
|
+
};
|
|
580
|
+
try {
|
|
581
|
+
return await this._patch({
|
|
582
|
+
url: this.baseUrl + this.URLs.notificationsWatch,
|
|
583
|
+
body: formattedBody,
|
|
522
584
|
});
|
|
523
585
|
}
|
|
524
586
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/api-module-zoho-crm",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.8",
|
|
4
4
|
"prettier": "@friggframework/prettier-config",
|
|
5
5
|
"description": "Zoho CRM API module that lets the Frigg Framework interact with Zoho CRM",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "a22e16b0dc4087f3b52b64f3213f42f19a03a967"
|
|
40
40
|
}
|