2023-01-27 03:22:44 -08:00
|
|
|
import type {
|
2022-08-24 01:26:48 -07:00
|
|
|
ICredentialDataDecryptedObject,
|
|
|
|
ICredentialType,
|
|
|
|
IHttpRequestOptions,
|
|
|
|
INodeProperties,
|
|
|
|
} from 'n8n-workflow';
|
2020-01-23 09:27:28 -08:00
|
|
|
|
|
|
|
export class SegmentApi implements ICredentialType {
|
|
|
|
name = 'segmentApi';
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2020-01-23 09:27:28 -08:00
|
|
|
displayName = 'Segment API';
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2020-08-17 05:42:09 -07:00
|
|
|
documentationUrl = 'segment';
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2021-06-12 09:39:55 -07:00
|
|
|
properties: INodeProperties[] = [
|
2020-01-23 09:27:28 -08:00
|
|
|
{
|
|
|
|
displayName: 'Write Key',
|
|
|
|
name: 'writekey',
|
2021-06-12 09:39:55 -07:00
|
|
|
type: 'string',
|
2023-08-01 04:08:25 -07:00
|
|
|
typeOptions: { password: true },
|
2020-01-23 09:27:28 -08:00
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
];
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2022-08-24 01:26:48 -07:00
|
|
|
async authenticate(
|
|
|
|
credentials: ICredentialDataDecryptedObject,
|
|
|
|
requestOptions: IHttpRequestOptions,
|
|
|
|
): Promise<IHttpRequestOptions> {
|
|
|
|
const base64Key = Buffer.from(`${credentials.writekey}:`).toString('base64');
|
2022-12-02 12:54:28 -08:00
|
|
|
requestOptions.headers!.Authorization = `Basic ${base64Key}`;
|
2022-08-24 01:26:48 -07:00
|
|
|
return requestOptions;
|
|
|
|
}
|
2020-01-23 09:27:28 -08:00
|
|
|
}
|