From 134845bb085c6b9b58e473f26f8dd32b266d65b5 Mon Sep 17 00:00:00 2001 From: Thorsten Freitag Date: Sat, 19 Feb 2022 22:29:28 +1100 Subject: [PATCH 1/2] Added option to connect to self-hosted Grist instance. --- .../credentials/GristApi.credentials.ts | 19 +++++++++++++++++++ .../nodes/Grist/GenericFunctions.ts | 7 +++++-- packages/nodes-base/nodes/Grist/Grist.node.ts | 9 ++++++--- packages/nodes-base/nodes/Grist/types.d.ts | 3 ++- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/packages/nodes-base/credentials/GristApi.credentials.ts b/packages/nodes-base/credentials/GristApi.credentials.ts index 9ac52c09fb..8458675948 100644 --- a/packages/nodes-base/credentials/GristApi.credentials.ts +++ b/packages/nodes-base/credentials/GristApi.credentials.ts @@ -29,6 +29,10 @@ export class GristApi implements ICredentialType { name: 'Paid', value: 'paid', }, + { + name: 'Self-hosted', + value: 'selfhosted', + }, ], }, { @@ -46,5 +50,20 @@ export class GristApi implements ICredentialType { }, }, }, + { + displayName: 'Self-hosted URL', + name: 'selfHostedUrl', + type: 'string', + default: '', + required: true, + description: 'URL of your Grist instance (include http/https without /api and no trailing slash)', + displayOptions: { + show: { + planType: [ + 'selfhosted', + ], + }, + }, + }, ]; } diff --git a/packages/nodes-base/nodes/Grist/GenericFunctions.ts b/packages/nodes-base/nodes/Grist/GenericFunctions.ts index f7ef0768f1..b154b4644f 100644 --- a/packages/nodes-base/nodes/Grist/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Grist/GenericFunctions.ts @@ -31,16 +31,19 @@ export async function gristApiRequest( apiKey, planType, customSubdomain, + selfHostedUrl, } = await this.getCredentials('gristApi') as GristCredentials; - const subdomain = planType === 'free' ? 'docs' : customSubdomain; + const gristapiurl = (planType === 'free') ? `https://docs.getgrist.com/api${endpoint}` : + (planType === 'paid') ? `https://${customSubdomain}.getgrist.com/api${endpoint}` : + `${selfHostedUrl}/api${endpoint}`; const options: OptionsWithUri = { headers: { Authorization: `Bearer ${apiKey}`, }, method, - uri: `https://${subdomain}.getgrist.com/api${endpoint}`, + uri: gristapiurl, qs, body, json: true, diff --git a/packages/nodes-base/nodes/Grist/Grist.node.ts b/packages/nodes-base/nodes/Grist/Grist.node.ts index bacb209b96..dccdbc72cb 100644 --- a/packages/nodes-base/nodes/Grist/Grist.node.ts +++ b/packages/nodes-base/nodes/Grist/Grist.node.ts @@ -85,18 +85,21 @@ export class Grist implements INodeType { apiKey, planType, customSubdomain, + selfHostedUrl, } = credential.data as GristCredentials; - const subdomain = planType === 'free' ? 'docs' : customSubdomain; - const endpoint = '/orgs'; + const gristapiurl = (planType === 'free') ? `https://docs.getgrist.com/api${endpoint}` : + (planType === 'paid') ? `https://${customSubdomain}.getgrist.com/api${endpoint}` : + `${selfHostedUrl}/api${endpoint}`; + const options: OptionsWithUri = { headers: { Authorization: `Bearer ${apiKey}`, }, method: 'GET', - uri: `https://${subdomain}.getgrist.com/api${endpoint}`, + uri: gristapiurl, qs: { limit: 1 }, json: true, }; diff --git a/packages/nodes-base/nodes/Grist/types.d.ts b/packages/nodes-base/nodes/Grist/types.d.ts index d45afae160..a2841ff68c 100644 --- a/packages/nodes-base/nodes/Grist/types.d.ts +++ b/packages/nodes-base/nodes/Grist/types.d.ts @@ -1,7 +1,8 @@ export type GristCredentials = { apiKey: string; - planType: 'free' | 'paid'; + planType: 'free' | 'paid' | 'selfhosted'; customSubdomain?: string; + selfHostedUrl?: string; } export type GristColumns = { From f6001da91e6e459c56b95d6e9c53c1eecd0d71c1 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Sat, 19 Feb 2022 14:38:16 +0100 Subject: [PATCH 2/2] :zap: Minor improvements to Grist Node --- packages/nodes-base/credentials/GristApi.credentials.ts | 9 +++++---- packages/nodes-base/nodes/Grist/types.d.ts | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/nodes-base/credentials/GristApi.credentials.ts b/packages/nodes-base/credentials/GristApi.credentials.ts index 8458675948..bf6ef314be 100644 --- a/packages/nodes-base/credentials/GristApi.credentials.ts +++ b/packages/nodes-base/credentials/GristApi.credentials.ts @@ -31,8 +31,8 @@ export class GristApi implements ICredentialType { }, { name: 'Self-hosted', - value: 'selfhosted', - }, + value: 'selfHosted', + }, ], }, { @@ -55,12 +55,13 @@ export class GristApi implements ICredentialType { name: 'selfHostedUrl', type: 'string', default: '', + placeholder: 'http://localhost:8484', required: true, - description: 'URL of your Grist instance (include http/https without /api and no trailing slash)', + description: 'URL of your Grist instance. Include http/https without /api and no trailing slash.', displayOptions: { show: { planType: [ - 'selfhosted', + 'selfHosted', ], }, }, diff --git a/packages/nodes-base/nodes/Grist/types.d.ts b/packages/nodes-base/nodes/Grist/types.d.ts index a2841ff68c..c8fec6c93f 100644 --- a/packages/nodes-base/nodes/Grist/types.d.ts +++ b/packages/nodes-base/nodes/Grist/types.d.ts @@ -1,6 +1,6 @@ export type GristCredentials = { apiKey: string; - planType: 'free' | 'paid' | 'selfhosted'; + planType: 'free' | 'paid' | 'selfHosted'; customSubdomain?: string; selfHostedUrl?: string; }