diff --git a/packages/v1-ready/zoho-crm/src/api.ts b/packages/v1-ready/zoho-crm/src/api.ts index 06ddfd5..cd05fa0 100644 --- a/packages/v1-ready/zoho-crm/src/api.ts +++ b/packages/v1-ready/zoho-crm/src/api.ts @@ -36,7 +36,7 @@ const LOCATION_CONFIG: Record = in: { accounts: 'https://accounts.zoho.in', api: 'https://www.zohoapis.in' }, au: { accounts: 'https://accounts.zoho.com.au', api: 'https://www.zohoapis.com.au' }, cn: { accounts: 'https://accounts.zoho.com.cn', api: 'https://www.zohoapis.com.cn' }, - ca: { accounts: 'https://accounts.zoho.ca', api: 'https://www.zohoapis.ca' }, + ca: { accounts: 'https://accounts.zohocloud.ca', api: 'https://www.zohoapis.ca' }, jp: { accounts: 'https://accounts.zoho.jp', api: 'https://www.zohoapis.jp' }, sa: { accounts: 'https://accounts.zoho.sa', api: 'https://www.zohoapis.sa' }, }; @@ -46,7 +46,6 @@ const DEFAULT_LOCATION: ZohoLocation = 'us'; export class Api extends OAuth2Requester { public URLs: Record string)>; public location: ZohoLocation; - public accountsServer: string | null; private static readonly CONTACTS_DEFAULT_FIELDS = 'id,First_Name,Last_Name,Email,Phone,Mobile,Account_Name,Company,Owner,Lead_Source,Created_Time,Modified_Time'; private static readonly LEADS_DEFAULT_FIELDS = 'id,First_Name,Last_Name,Email,Phone,Mobile,Company,Industry,Lead_Source,Lead_Status,Owner,Created_Time,Modified_Time,Converted__s,Converted_Date_Time'; @@ -55,7 +54,6 @@ export class Api extends OAuth2Requester { constructor(params: ZohoConfig) { super(params); - this.accountsServer = get(params, 'accountsServer', null) as string | null; this.location = get(params, 'location', DEFAULT_LOCATION) as ZohoLocation; if (!LOCATION_CONFIG[this.location]) { this.location = DEFAULT_LOCATION; @@ -63,9 +61,7 @@ export class Api extends OAuth2Requester { const locationConfig = LOCATION_CONFIG[this.location]; this.baseUrl = `${locationConfig.api}/crm/v8`; - this.tokenUri = this.accountsServer - ? `${this.accountsServer}/oauth/v2/token` - : `${locationConfig.accounts}/oauth/v2/token`; + this.tokenUri = `${locationConfig.accounts}/oauth/v2/token`; 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` ); @@ -97,10 +93,6 @@ export class Api extends OAuth2Requester { return this.authorizationUri; } - /** - * Sets the datacenter location and updates URLs accordingly. - * Note: tokenUri is only updated if accountsServer is not set. - */ setLocation(location: ZohoLocation): void { if (!LOCATION_CONFIG[location]) { throw new Error( @@ -111,23 +103,12 @@ export class Api extends OAuth2Requester { this.location = location; const locationConfig = LOCATION_CONFIG[location]; this.baseUrl = `${locationConfig.api}/crm/v8`; - if (!this.accountsServer) { - this.tokenUri = `${locationConfig.accounts}/oauth/v2/token`; - } + this.tokenUri = `${locationConfig.accounts}/oauth/v2/token`; 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` ); } - /** - * Sets the accounts server URL for token operations. - * Call this when accounts-server is provided in OAuth callback. - */ - setAccountsServer(accountsServer: string): void { - this.accountsServer = accountsServer; - this.tokenUri = `${accountsServer}/oauth/v2/token`; - } - async getTokenFromCode(code: string): Promise { const formData = new FormData(); formData.append('grant_type', 'authorization_code'); @@ -141,6 +122,7 @@ export class Api extends OAuth2Requester { headers: (formData as any).getHeaders(), url: this.tokenUri, }; + const response = await this._post(options, false); await this.setTokens(response); return response; diff --git a/packages/v1-ready/zoho-crm/src/definition.ts b/packages/v1-ready/zoho-crm/src/definition.ts index 25d1c11..001bf57 100644 --- a/packages/v1-ready/zoho-crm/src/definition.ts +++ b/packages/v1-ready/zoho-crm/src/definition.ts @@ -15,20 +15,16 @@ export const Definition = { getToken: async function(api: Api, params: any): Promise { const code = get(params, 'code'); const location = get(params, 'location', null) as ZohoLocation | null; - const accountsServer = get(params, 'accounts-server', null) as string | null; if (location) { api.setLocation(location); } - if (accountsServer) { - api.setAccountsServer(accountsServer); - } await api.getTokenFromCode(code); }, apiPropertiesToPersist: { credential: ['access_token', 'refresh_token'], - entity: ['location', 'accountsServer'], + entity: ['location'], }, getCredentialDetails: async function (api: Api, userId: string): Promise { const response = await api.listUsers({type: 'CurrentUser'}); @@ -46,7 +42,6 @@ export const Definition = { details: { name: currentUser.email, location: api.location, - accountsServer: api.accountsServer, }, }; }, diff --git a/packages/v1-ready/zoho-crm/src/types.ts b/packages/v1-ready/zoho-crm/src/types.ts index bf5d0a9..ef12d08 100644 --- a/packages/v1-ready/zoho-crm/src/types.ts +++ b/packages/v1-ready/zoho-crm/src/types.ts @@ -12,7 +12,6 @@ export interface ZohoConfig { access_token?: string | null; refresh_token?: string | null; location?: ZohoLocation; - accountsServer?: string | null; } export interface PaginationInfo {