n8n-nodes-wechat
Version:
This is an n8n-wechat-nodes Library
54 lines • 2.35 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
class HttpRequest {
constructor(baseOptions = {}) {
this.credentialsType = '';
this.reqOptions = {};
this.baseOptions = baseOptions;
}
static create(baseOptions, credentialsType) {
if (!HttpRequest.instance) {
HttpRequest.instance = new HttpRequest(baseOptions);
if (credentialsType)
HttpRequest.instance.credentialsType = credentialsType;
}
return HttpRequest.instance;
}
async preAuthentication(ctx, cred, options) {
var _a, _b;
const credType = this.credentialsType;
const reqOptions = { ...this.baseOptions, ...options };
const { id, name } = (_b = (_a = ctx.getNode()) === null || _a === void 0 ? void 0 : _a.credentials) === null || _b === void 0 ? void 0 : _b[credType];
const credentialsDecrypted = { id, name, type: credType, data: { ...cred, sessionToken: '' } };
return await ctx.helpers.httpRequestWithAuthentication.call(ctx, credType, reqOptions, {
credentialsDecrypted,
});
}
async retry(ctx) {
var _a, _b;
const { credentialsType, reqOptions } = this;
const { id, name } = (_b = (_a = ctx.getNode()) === null || _a === void 0 ? void 0 : _a.credentials) === null || _b === void 0 ? void 0 : _b[credentialsType];
const credentialsDecrypted = { id, name, type: credentialsType, data: { sessionToken: '' } };
if (credentialsType) {
return await ctx.helpers.httpRequestWithAuthentication.call(ctx, credentialsType, reqOptions, { credentialsDecrypted });
}
else {
return await ctx.helpers.httpRequest.call(ctx, reqOptions);
}
}
async request(ctx, reqOptions = {}) {
this.reqOptions = {
...this.baseOptions,
...reqOptions,
headers: { ...this.baseOptions.headers, ...reqOptions.headers },
};
if (this.credentialsType) {
return await ctx.helpers.httpRequestWithAuthentication.call(ctx, this.credentialsType, this.reqOptions);
}
else {
return await ctx.helpers.httpRequest.call(ctx, this.reqOptions);
}
}
}
exports.default = HttpRequest;
//# sourceMappingURL=HttpRequest.js.map
;