Added option to connect to self-hosted Grist instance.

This commit is contained in:
Thorsten Freitag 2022-02-19 22:29:28 +11:00
parent 1ea57eff5d
commit 134845bb08
4 changed files with 32 additions and 6 deletions

View file

@ -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',
],
},
},
},
];
}

View file

@ -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,

View file

@ -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,
};

View file

@ -1,7 +1,8 @@
export type GristCredentials = {
apiKey: string;
planType: 'free' | 'paid';
planType: 'free' | 'paid' | 'selfhosted';
customSubdomain?: string;
selfHostedUrl?: string;
}
export type GristColumns = {