Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 8x 4x 4x 4x 4x 1x 4x | import CoreFormsEnum, { getFormName } from '@orchesty/nodejs-sdk/dist/lib/Application/Base/CoreFormsEnum';
import { ApplicationInstall } from '@orchesty/nodejs-sdk/dist/lib/Application/Database/ApplicationInstall';
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 Form from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/Form';
import FormStack from '@orchesty/nodejs-sdk/dist/lib/Application/Model/Form/FormStack';
import ScopeSeparatorEnum from '@orchesty/nodejs-sdk/dist/lib/Authorization/ScopeSeparatorEnum';
import AOAuth2Application from '@orchesty/nodejs-sdk/dist/lib/Authorization/Type/OAuth2/AOAuth2Application';
import { CLIENT_ID, CLIENT_SECRET } from '@orchesty/nodejs-sdk/dist/lib/Authorization/Type/OAuth2/IOAuth2Application';
import RequestDto from '@orchesty/nodejs-sdk/dist/lib/Transport/Curl/RequestDto';
import { HttpMethods } from '@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods';
import AProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/AProcessDto';
import { CommonHeaders, JSON_TYPE } from '@orchesty/nodejs-sdk/dist/lib/Utils/Headers';
export const NAME = 'mergado';
export default class MergadoApplication extends AOAuth2Application {
public getName(): string {
return NAME;
}
public getPublicName(): string {
return 'Mergado';
}
public getDescription(): string {
return 'Software with which you can automate the data flowing from your e-shop to search engines and other advertising systems';
}
public getAuthUrl(): string {
return 'https://app.mergado.com/oauth2/authorize/';
}
public getTokenUrl(): string {
return 'https://app.mergado.com/oauth2/token/';
}
public getLogo(): string {
return 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDI1LjAuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IlZyc3R2YV8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCIKCSB2aWV3Qm94PSIwIDAgMTAwIDEwMCIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgMTAwIDEwMDsiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgoJLnN0MHtmaWxsOiM3RkI5MkY7fQoJLnN0MXtmaWxsOiM0MjdCMjc7fQoJLnN0MntmaWxsOiM0NEE4Qjc7fQo8L3N0eWxlPgo8Zz4KCTxwYXRoIGNsYXNzPSJzdDAiIGQ9Ik0wLDBsNTAsNTBMMCwxMDBWMHoiLz4KCTxwYXRoIGNsYXNzPSJzdDEiIGQ9Ik01MCw1MGw1MCw1MEgwTDUwLDUweiIvPgoJPHBhdGggY2xhc3M9InN0MiIgZD0iTTUwLDUwbDUwLTUwdjEwMEw1MCw1MHoiLz4KPC9nPgo8L3N2Zz4K';
}
public getRequestDto(
dto: AProcessDto,
applicationInstall: ApplicationInstall,
method: HttpMethods,
_url?: string,
data?: unknown,
): RequestDto {
const url = `https://api.mergado.com/${_url}`;
const request = new RequestDto(url ?? '', method, dto);
request.setHeaders({
[CommonHeaders.CONTENT_TYPE]: JSON_TYPE,
[CommonHeaders.ACCEPT]: JSON_TYPE,
[CommonHeaders.AUTHORIZATION]: `Bearer ${this.getAccessToken(applicationInstall)}`,
});
if (data) {
request.setJsonBody(data);
}
return request;
}
public getFormStack(): FormStack {
const form = new Form(CoreFormsEnum.AUTHORIZATION_FORM, getFormName(CoreFormsEnum.AUTHORIZATION_FORM))
.addField(new Field(FieldType.TEXT, CLIENT_ID, 'Client Id', null, true))
.addField(new Field(FieldType.TEXT, CLIENT_SECRET, 'Client Secret', null, true));
return new FormStack()
.addForm(form);
}
public isAuthorized(applicationInstall: ApplicationInstall): boolean {
const authorizationForm = applicationInstall.getSettings()[CoreFormsEnum.AUTHORIZATION_FORM];
return super.isAuthorized(applicationInstall)
&& authorizationForm?.[CLIENT_ID]
&& authorizationForm?.[CLIENT_SECRET];
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public getScopes(applicationInstall: ApplicationInstall): string[] {
return [
'shop.read',
'user.read',
'project.read',
'project.elements.write',
];
}
protected _getScopesSeparator(): string {
return ScopeSeparatorEnum.SPACE;
}
}
|