@punks/backend-entity-manager 0.0.145 → 0.0.147

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -20558,7 +20558,7 @@ let UserRegistrationHandler = class UserRegistrationHandler {
20558
20558
  await this.emailService.sendTemplatedEmail({
20559
20559
  to: [user.email],
20560
20560
  templateId: AuthenticationEmailTemplates.Registration,
20561
- languageId,
20561
+ languageCode: languageId,
20562
20562
  payload: {
20563
20563
  firstName: user.profile.firstName,
20564
20564
  lastName: user.profile.lastName,
@@ -20761,17 +20761,17 @@ let UserPasswordResetRequestHandler = class UserPasswordResetRequestHandler {
20761
20761
  success: false,
20762
20762
  };
20763
20763
  }
20764
- await this.sendPasswordResetEmail(user, input.callback, input.languageId);
20764
+ await this.sendPasswordResetEmail(user, input.callback, input.languageCode);
20765
20765
  return {
20766
20766
  success: true,
20767
20767
  };
20768
20768
  }
20769
- async sendPasswordResetEmail(user, callback, languageId) {
20769
+ async sendPasswordResetEmail(user, callback, languageCode) {
20770
20770
  const token = await this.generatePasswordResetToken(user);
20771
20771
  await this.emailService.sendTemplatedEmail({
20772
20772
  to: [user.email],
20773
20773
  templateId: AuthenticationEmailTemplates.PasswordReset,
20774
- languageId,
20774
+ languageCode,
20775
20775
  payload: {
20776
20776
  firstName: user.profile.firstName,
20777
20777
  lastName: user.profile.lastName,
@@ -20886,7 +20886,7 @@ let UserVerifyRequestHandler = class UserVerifyRequestHandler {
20886
20886
  lastName: user.profile.lastName,
20887
20887
  callbackUrl: callback.urlTemplate.replace(callback.tokenPlaceholder, token),
20888
20888
  },
20889
- languageId,
20889
+ languageCode: languageId,
20890
20890
  });
20891
20891
  }
20892
20892
  async generateEmailVerifyToken(user) {
@@ -21166,6 +21166,11 @@ const mapPipelineErrorType = (stepError) => {
21166
21166
  }
21167
21167
  };
21168
21168
 
21169
+ const isOperationSuccessStatus = (type) => {
21170
+ return ["success", "skipped"].includes(type);
21171
+ };
21172
+ const isOperationRollbackErrorStatus = (type) => ["error"].includes(type);
21173
+
21169
21174
  class PipelineInstance {
21170
21175
  constructor(definition, input, context) {
21171
21176
  this.definition = definition;
@@ -21242,10 +21247,9 @@ class PipelineInstance {
21242
21247
  result: x,
21243
21248
  operation: step.operations[i],
21244
21249
  }));
21245
- // .filter((x) => x.result.type === "success")
21246
21250
  const rollbackOperations = completedOperations.map((x) => this.rollbackOperations(x.operation, x.result.input, getOperationOutput(x.result), state));
21247
21251
  const rollbackResults = await Promise.all(rollbackOperations);
21248
- const isRollbackError = rollbackResults.some((x) => x.type === "error");
21252
+ const isRollbackError = rollbackResults.some((x) => isOperationRollbackErrorStatus(x.type));
21249
21253
  if (isRollbackError) {
21250
21254
  return {
21251
21255
  type: "error",
@@ -21276,7 +21280,7 @@ class PipelineInstance {
21276
21280
  }
21277
21281
  const stepOperations = step.operations.map((x) => this.executeOperation(x, input, state));
21278
21282
  const operationResults = await Promise.all(stepOperations);
21279
- const isSuccess = operationResults.every((x) => x.type === "success");
21283
+ const isSuccess = operationResults.every((x) => isOperationSuccessStatus(x.type));
21280
21284
  if (isSuccess) {
21281
21285
  const output = step.outputsReducer
21282
21286
  ? step.outputsReducer(operationResults.map((x) => getOperationOutput(x)))
@@ -21297,6 +21301,16 @@ class PipelineInstance {
21297
21301
  }
21298
21302
  async executeOperation(operation, input, state) {
21299
21303
  try {
21304
+ const shouldSkip = await this.shouldSkipOperation(operation, input, state);
21305
+ if (shouldSkip) {
21306
+ this.logger.info(`Pipeline operation skipped -> operation:${operation.name}`, {
21307
+ input,
21308
+ });
21309
+ return {
21310
+ type: "skipped",
21311
+ input,
21312
+ };
21313
+ }
21300
21314
  const operationResult = await operation.operation.action(input, state);
21301
21315
  return {
21302
21316
  type: "success",
@@ -21315,6 +21329,12 @@ class PipelineInstance {
21315
21329
  };
21316
21330
  }
21317
21331
  }
21332
+ async shouldSkipOperation({ operation, }, input, state) {
21333
+ if (!operation.skipIf) {
21334
+ return false;
21335
+ }
21336
+ return await operation.skipIf(input, state);
21337
+ }
21318
21338
  async rollbackOperations(operation, operationInput, operationOutput, state) {
21319
21339
  if (!operation.rollbackOperations?.length) {
21320
21340
  return {
@@ -28017,13 +28037,13 @@ let SendgridEmailProvider = class SendgridEmailProvider {
28017
28037
  const processedPayload = await template.processPayload(input.payload);
28018
28038
  const templateData = await template.getTemplateData(processedPayload);
28019
28039
  if (templateData.type === "html") {
28020
- const body = getLocalizedText(templateData.bodyTemplate, input.languageId);
28040
+ const body = getLocalizedText(templateData.bodyTemplate, input.languageCode);
28021
28041
  if (!body) {
28022
- throw new Error(`Missing body template for language ${input.languageId}`);
28042
+ throw new Error(`Missing body template for language ${input.languageCode}`);
28023
28043
  }
28024
- const subject = getLocalizedText(templateData.subjectTemplate, input.languageId);
28044
+ const subject = getLocalizedText(templateData.subjectTemplate, input.languageCode);
28025
28045
  if (!subject) {
28026
- throw new Error(`Missing subject template for language ${input.languageId}`);
28046
+ throw new Error(`Missing subject template for language ${input.languageCode}`);
28027
28047
  }
28028
28048
  await this.sendHtmlEmail({
28029
28049
  bodyTemplate: body,