@inngest/middleware-encryption
Version:
E2E encryption middleware for Inngest.
51 lines (50 loc) • 1.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EncryptionService = exports.encryptionMiddleware = void 0;
const inngest_1 = require("inngest");
const stages_1 = require("./stages");
/**
* Encrypts and decrypts data sent to and from Inngest.
*/
const encryptionMiddleware = (
/**
* Options used to configure the encryption middleware. If a custom
* `encryptionService` is not provided, the `key` option is required.
*/
opts) => {
const { encrypt, decrypt } = (0, stages_1.getEncryptionStages)(opts);
return new inngest_1.InngestMiddleware({
name: "@inngest/middleware-encryption",
init: () => {
return {
onFunctionRun: (...args) => {
return Object.assign(Object.assign({}, encrypt.onFunctionRun(...args)), decrypt.onFunctionRun(...args));
},
onSendEvent: encrypt.onSendEvent,
};
},
});
};
exports.encryptionMiddleware = encryptionMiddleware;
/**
* A service that encrypts and decrypts data. You can implement this abstract
* class to provide your own encryption service, or use the default encryption
* service provided by this package.
*/
class EncryptionService {
}
exports.EncryptionService = EncryptionService;
(function (EncryptionService) {
/**
* A marker used to identify encrypted values without having to guess.
*/
EncryptionService.ENCRYPTION_MARKER = "__ENCRYPTED__";
/**
* A marker used to identify the strategy used for encryption.
*/
EncryptionService.STRATEGY_MARKER = "__STRATEGY__";
/**
* The default field used to store encrypted values in events.
*/
EncryptionService.DEFAULT_ENCRYPTED_EVENT_FIELD = "encrypted";
})(EncryptionService || (exports.EncryptionService = EncryptionService = {}));