@friggframework/api-module-zoho-crm 2.0.0-next.3 → 2.0.0-next.4

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 CHANGED
@@ -1,12 +1,24 @@
1
1
  import { OAuth2Requester } from '@friggframework/core';
2
- import { ZohoConfig, QueryParams, SearchParams, UsersResponse, RolesResponse, ProfilesResponse, ContactsResponse, ContactResponse, LeadsResponse, LeadResponse, AccountsResponse, AccountResponse, TokenResponse, CreateNoteData, NotesResponse, NoteListResponse, NotificationWatchConfig, NotificationResponse, NotificationDetailsResponse, ZohoCallData, CallsResponse } from './types';
2
+ import { ZohoConfig, ZohoLocation, QueryParams, SearchParams, UsersResponse, RolesResponse, ProfilesResponse, ContactsResponse, ContactResponse, LeadsResponse, LeadResponse, AccountsResponse, AccountResponse, TokenResponse, CreateNoteData, NotesResponse, NoteListResponse, NotificationWatchConfig, NotificationResponse, NotificationDetailsResponse, ZohoCallData, CallsResponse } from './types';
3
3
  export declare class Api extends OAuth2Requester {
4
4
  URLs: Record<string, string | ((id: string) => string)>;
5
+ location: ZohoLocation;
6
+ accountsServer: string | null;
5
7
  private static readonly CONTACTS_DEFAULT_FIELDS;
6
8
  private static readonly LEADS_DEFAULT_FIELDS;
7
9
  private static readonly ACCOUNTS_DEFAULT_FIELDS;
8
10
  constructor(params: ZohoConfig);
9
11
  getAuthUri(): string;
12
+ /**
13
+ * Sets the datacenter location and updates URLs accordingly.
14
+ * Note: tokenUri is only updated if accountsServer is not set.
15
+ */
16
+ setLocation(location: ZohoLocation): void;
17
+ /**
18
+ * Sets the accounts server URL for token operations.
19
+ * Call this when accounts-server is provided in OAuth callback.
20
+ */
21
+ setAccountsServer(accountsServer: string): void;
10
22
  getTokenFromCode(code: string): Promise<TokenResponse>;
11
23
  _delete(options: any): Promise<any>;
12
24
  /**
package/dist/api.js CHANGED
@@ -3,12 +3,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Api = void 0;
4
4
  const FormData = require("form-data");
5
5
  const core_1 = require("@friggframework/core");
6
+ /**
7
+ * Zoho datacenter URL configuration
8
+ * @see https://www.zoho.com/crm/developer/docs/api/v8/multi-dc.html
9
+ */
10
+ const LOCATION_CONFIG = {
11
+ us: { accounts: 'https://accounts.zoho.com', api: 'https://www.zohoapis.com' },
12
+ eu: { accounts: 'https://accounts.zoho.eu', api: 'https://www.zohoapis.eu' },
13
+ in: { accounts: 'https://accounts.zoho.in', api: 'https://www.zohoapis.in' },
14
+ au: { accounts: 'https://accounts.zoho.com.au', api: 'https://www.zohoapis.com.au' },
15
+ cn: { accounts: 'https://accounts.zoho.com.cn', api: 'https://www.zohoapis.com.cn' },
16
+ ca: { accounts: 'https://accounts.zoho.ca', api: 'https://www.zohoapis.ca' },
17
+ jp: { accounts: 'https://accounts.zoho.jp', api: 'https://www.zohoapis.jp' },
18
+ sa: { accounts: 'https://accounts.zoho.sa', api: 'https://www.zohoapis.sa' },
19
+ };
20
+ const DEFAULT_LOCATION = 'us';
6
21
  class Api extends core_1.OAuth2Requester {
7
22
  constructor(params) {
8
23
  super(params);
9
- this.baseUrl = 'https://www.zohoapis.com/crm/v8';
10
- this.authorizationUri = encodeURI(`https://accounts.zoho.com/oauth/v2/auth?scope=${this.scope}&client_id=${this.client_id}&redirect_uri=${this.redirect_uri}&response_type=code&access_type=offline`);
11
- this.tokenUri = 'https://accounts.zoho.com/oauth/v2/token';
24
+ this.accountsServer = (0, core_1.get)(params, 'accountsServer', null);
25
+ this.location = (0, core_1.get)(params, 'location', DEFAULT_LOCATION);
26
+ if (!LOCATION_CONFIG[this.location]) {
27
+ this.location = DEFAULT_LOCATION;
28
+ }
29
+ const locationConfig = LOCATION_CONFIG[this.location];
30
+ this.baseUrl = `${locationConfig.api}/crm/v8`;
31
+ this.tokenUri = this.accountsServer
32
+ ? `${this.accountsServer}/oauth/v2/token`
33
+ : `${locationConfig.accounts}/oauth/v2/token`;
34
+ this.authorizationUri = encodeURI(`${locationConfig.accounts}/oauth/v2/auth?scope=${this.scope}&client_id=${this.client_id}&redirect_uri=${this.redirect_uri}&response_type=code&access_type=offline`);
12
35
  this.access_token = (0, core_1.get)(params, 'access_token', null);
13
36
  this.refresh_token = (0, core_1.get)(params, 'refresh_token', null);
14
37
  this.URLs = {
@@ -34,6 +57,30 @@ class Api extends core_1.OAuth2Requester {
34
57
  getAuthUri() {
35
58
  return this.authorizationUri;
36
59
  }
60
+ /**
61
+ * Sets the datacenter location and updates URLs accordingly.
62
+ * Note: tokenUri is only updated if accountsServer is not set.
63
+ */
64
+ setLocation(location) {
65
+ if (!LOCATION_CONFIG[location]) {
66
+ throw new Error(`Invalid Zoho location: ${location}. Must be one of: ${Object.keys(LOCATION_CONFIG).join(', ')}`);
67
+ }
68
+ this.location = location;
69
+ const locationConfig = LOCATION_CONFIG[location];
70
+ this.baseUrl = `${locationConfig.api}/crm/v8`;
71
+ if (!this.accountsServer) {
72
+ this.tokenUri = `${locationConfig.accounts}/oauth/v2/token`;
73
+ }
74
+ this.authorizationUri = encodeURI(`${locationConfig.accounts}/oauth/v2/auth?scope=${this.scope}&client_id=${this.client_id}&redirect_uri=${this.redirect_uri}&response_type=code&access_type=offline`);
75
+ }
76
+ /**
77
+ * Sets the accounts server URL for token operations.
78
+ * Call this when accounts-server is provided in OAuth callback.
79
+ */
80
+ setAccountsServer(accountsServer) {
81
+ this.accountsServer = accountsServer;
82
+ this.tokenUri = `${accountsServer}/oauth/v2/token`;
83
+ }
37
84
  async getTokenFromCode(code) {
38
85
  const formData = new FormData();
39
86
  formData.append('grant_type', 'authorization_code');
@@ -7,7 +7,7 @@ export declare const Definition: {
7
7
  getToken: (api: Api, params: any) => Promise<void>;
8
8
  apiPropertiesToPersist: {
9
9
  credential: string[];
10
- entity: never[];
10
+ entity: string[];
11
11
  };
12
12
  getCredentialDetails: (api: Api, userId: string) => Promise<any>;
13
13
  getEntityDetails: (api: Api, callbackParams: any, tokenResponse: any, userId: string) => Promise<any>;
@@ -38,11 +38,19 @@ exports.Definition = {
38
38
  requiredAuthMethods: {
39
39
  getToken: async function (api, params) {
40
40
  const code = (0, core_1.get)(params, 'code');
41
+ const location = (0, core_1.get)(params, 'location', null);
42
+ const accountsServer = (0, core_1.get)(params, 'accounts-server', null);
43
+ if (location) {
44
+ api.setLocation(location);
45
+ }
46
+ if (accountsServer) {
47
+ api.setAccountsServer(accountsServer);
48
+ }
41
49
  await api.getTokenFromCode(code);
42
50
  },
43
51
  apiPropertiesToPersist: {
44
52
  credential: ['access_token', 'refresh_token'],
45
- entity: [],
53
+ entity: ['location', 'accountsServer'],
46
54
  },
47
55
  getCredentialDetails: async function (api, userId) {
48
56
  const response = await api.listUsers({ type: 'CurrentUser' });
@@ -58,7 +66,9 @@ exports.Definition = {
58
66
  return {
59
67
  identifiers: { externalId: currentUser.id, user: userId },
60
68
  details: {
61
- name: currentUser.email
69
+ name: currentUser.email,
70
+ location: api.location,
71
+ accountsServer: api.accountsServer,
62
72
  },
63
73
  };
64
74
  },
package/dist/types.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Zoho datacenter locations
3
+ * @see https://www.zoho.com/crm/developer/docs/api/v8/multi-dc.html
4
+ */
5
+ export type ZohoLocation = 'us' | 'eu' | 'in' | 'au' | 'cn' | 'ca' | 'jp' | 'sa';
1
6
  export interface ZohoConfig {
2
7
  client_id: string;
3
8
  client_secret: string;
@@ -5,6 +10,8 @@ export interface ZohoConfig {
5
10
  redirect_uri: string;
6
11
  access_token?: string | null;
7
12
  refresh_token?: string | null;
13
+ location?: ZohoLocation;
14
+ accountsServer?: string | null;
8
15
  }
9
16
  export interface PaginationInfo {
10
17
  per_page: number;
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",
3
+ "version": "2.0.0-next.4",
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",
@@ -21,8 +21,8 @@
21
21
  "author": "",
22
22
  "license": "MIT",
23
23
  "devDependencies": {
24
- "@friggframework/devtools": "^2.0.0-next.16",
25
- "@friggframework/test": "^2.0.0-next.16",
24
+ "@friggframework/devtools": "^2.0.0-next.68",
25
+ "@friggframework/test": "^2.0.0-next.68",
26
26
  "@types/node": "^20.8.0",
27
27
  "dotenv": "^16.0.3",
28
28
  "eslint": "^8.22.0",
@@ -31,10 +31,10 @@
31
31
  "vitest": "^1.0.0"
32
32
  },
33
33
  "dependencies": {
34
- "@friggframework/core": "^2.0.0-next.16"
34
+ "@friggframework/core": "^2.0.0-next.68"
35
35
  },
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "fd8e7d7ad197886b7bd94a68fd26c179358f4b67"
39
+ "gitHead": "e067a887c7a7674018dc7e47bcf02a684400de70"
40
40
  }