n8n/packages/nodes-base/credentials/NotionApi.credentials.ts
Iván Ovejero b03e358a12
refactor: Integrate consistent-type-imports in nodes-base (no-changelog) (#5267)
* 👕 Enable `consistent-type-imports` for nodes-base

* 👕 Apply to nodes-base

*  Undo unrelated changes

* 🚚 Move to `.eslintrc.js` in nodes-base

*  Revert "Enable `consistent-type-imports` for nodes-base"

This reverts commit 529ad72b05.

* 👕 Fix severity
2023-01-27 12:22:44 +01:00

55 lines
1.2 KiB
TypeScript

import type {
ICredentialDataDecryptedObject,
ICredentialTestRequest,
ICredentialType,
IHttpRequestOptions,
INodeProperties,
} from 'n8n-workflow';
export class NotionApi implements ICredentialType {
name = 'notionApi';
displayName = 'Notion API';
documentationUrl = 'notion';
properties: INodeProperties[] = [
{
displayName: 'API Key',
name: 'apiKey',
type: 'string',
typeOptions: { password: true },
default: '',
},
];
test: ICredentialTestRequest = {
request: {
baseURL: 'https://api.notion.com/v1',
url: '/users',
},
};
async authenticate(
credentials: ICredentialDataDecryptedObject,
requestOptions: IHttpRequestOptions,
): Promise<IHttpRequestOptions> {
requestOptions.headers = {
...requestOptions.headers,
Authorization: `Bearer ${credentials.apiKey} `,
};
// if version it's not set, set it to last one
// version is only set when the request is made from
// the notion node, or was set explicitly in the http node
if (!requestOptions.headers['Notion-Version']) {
requestOptions.headers = {
...requestOptions.headers,
'Notion-Version': '2022-02-22',
};
}
return requestOptions;
}
}