@n8n-plus/n8n-plus
Version:
n8n Workflow Automation Tool (plus edition)
86 lines • 4 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StubCredentialResolver = void 0;
const backend_common_1 = require("@n8n/backend-common");
const decorators_1 = require("@n8n/decorators");
const zod_1 = __importDefault(require("zod"));
const StubOptionsSchema = zod_1.default.object({
prefix: zod_1.default.string().default(''),
});
let StubCredentialResolver = class StubCredentialResolver {
constructor(logger) {
this.logger = logger;
this.secretsStore = new Map();
this.metadata = {
name: 'credential-resolver.stub-1.0',
description: 'A stub credential resolver for testing purposes',
displayName: 'Stub Resolver',
options: [
{
displayName: 'Prefix',
name: 'prefix',
type: 'string',
default: '',
placeholder: 'Optional prefix for stored credentials',
description: 'An optional prefix to namespace stored credentials (useful for testing)',
},
],
};
}
generateKey(credentialId, context, options) {
return `${options.prefix}:${credentialId}:${context.identity}`;
}
async getSecret(credentialId, context, handle) {
const parsedOptions = await this.parseOptions(handle.configuration);
const key = this.generateKey(credentialId, context, parsedOptions);
const secret = this.secretsStore.get(key);
if (!secret) {
throw new decorators_1.CredentialResolverDataNotFoundError();
}
return secret;
}
async setSecret(credentialId, context, data, handle) {
const parsedOptions = await this.parseOptions(handle.configuration);
const key = this.generateKey(credentialId, context, parsedOptions);
this.secretsStore.set(key, data);
}
async deleteSecret(credentialId, context, handle) {
const parsedOptions = await this.parseOptions(handle.configuration);
const key = this.generateKey(credentialId, context, parsedOptions);
this.secretsStore.delete(key);
}
async parseOptions(options) {
const result = await StubOptionsSchema.safeParseAsync(options);
if (result.error) {
this.logger.error('Invalid options provided to StubCredentialResolver', {
error: result.error,
});
throw new decorators_1.CredentialResolverValidationError(`Invalid options for StubCredentialResolver: ${result.error.message}`);
}
return result.data;
}
async validateOptions(options) {
await this.parseOptions(options);
}
async validateIdentity(_identity, _handle) {
return;
}
};
exports.StubCredentialResolver = StubCredentialResolver;
exports.StubCredentialResolver = StubCredentialResolver = __decorate([
(0, decorators_1.CredentialResolver)(),
__metadata("design:paramtypes", [backend_common_1.Logger])
], StubCredentialResolver);
//# sourceMappingURL=stub-credential-resolver.js.map