Basic Application
A Basic Application is the simplest Application type. It handles services that authenticate with a static credential: API key, bearer token, basic auth, or no authentication at all. For OAuth2 see OAuth2 Application.
For background see Concepts: Connectors and Applications.
Class to extend #
| SDK | Base class |
|---|---|
| Node.js | ABasicApplication (extends AApplication) |
| PHP | BasicApplicationAbstract (extends ApplicationAbstract) |
Minimal example #
// worker/src/Hubspot/HubspotApplication.ts
import ABasicApplication from '@orchesty/nodejs-sdk/dist/lib/Authorization/Type/Basic/ABasicApplication';
import ApplicationInstall from '@orchesty/nodejs-sdk/dist/lib/Application/Database/ApplicationInstall';
import RequestDto from '@orchesty/nodejs-sdk/dist/lib/Transport/Curl/RequestDto';
import { HttpMethods } from '@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods';
import Form from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/Form';
import Field from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/Field';
import FieldType from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/FieldType';
import FormStack from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/FormStack';
import CoreFormsEnum from '@orchesty/nodejs-sdk/dist/lib/Application/Base/CoreFormsEnum';
export const NAME = 'hubspot';
const API_KEY = 'api_key';
export default class HubspotApplication extends ABasicApplication {
public getName(): string { return NAME; }
public getPublicName(): string { return 'Hubspot'; }
public getDescription(): string { return 'Hubspot CRM integration'; }
public getFormStack(): FormStack {
const form = new Form(CoreFormsEnum.AUTHORIZATION_FORM, 'Authorization');
form.addField(new Field(FieldType.TEXT, API_KEY, 'API key', undefined, true));
return new FormStack().addForm(form);
}
public getRequestDto(
dto: ProcessDto,
applicationInstall: ApplicationInstall,
method: HttpMethods,
url?: string,
data?: unknown,
): RequestDto {
const apiKey = applicationInstall.getSettings()[CoreFormsEnum.AUTHORIZATION_FORM][API_KEY];
return new RequestDto(url ?? '', method, dto, JSON.stringify(data ?? {}), {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`,
});
}
}
Register the application and a connector #
// worker/src/index.ts
const hubspotApp = new HubspotApplication();
container.setApplication(hubspotApp);
container.setNode(new HubspotListContacts(), hubspotApp);
What goes in getFormStack() #
Every Application declares a FormStack of one or more Forms. Each Form has a list of Fields that the Admin UI renders. Use the reserved form key CoreFormsEnum.AUTHORIZATION_FORM (authorization_form in PHP) for credentials so the Admin UI displays them in the right tab.
For the field types and validation options, see Reference: Node.js / Field or Reference: PHP / Field.