@chevre/domain 26.0.0-alpha.35 → 26.0.0-alpha.37

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.
@@ -1,7 +1,7 @@
1
1
  import { Connection } from 'mongoose';
2
2
  import { factory } from '../../factory';
3
3
  import { IModel as IActionModel } from '../mongoose/schemas/action';
4
- import { IModel as IActionRecipeModel } from '../mongoose/schemas/actionRecipe';
4
+ import { ActionRecipeRepo, IActionRecipe, IRecipeAsActionAttributes } from './actionRecipe';
5
5
  export type IAction4transaction<T extends factory.actionType.AcceptAction | factory.actionType.AuthorizeAction> = T extends factory.actionType.AcceptAction ? factory.action.accept.coaOffer.IAction | factory.action.accept.pay.IAction : T extends factory.actionType.AuthorizeAction ? (factory.action.authorize.offer.eventService.IAction | factory.action.authorize.paymentMethod.any.IAction) : never;
6
6
  export type IAction<T extends factory.actionType> = T extends factory.actionType.OrderAction ? factory.action.trade.order.IAction : T extends factory.actionType.AcceptAction ? IAction4transaction<factory.actionType.AcceptAction> : T extends factory.actionType.AuthorizeAction ? factory.action.authorize.IAction<factory.action.authorize.IAttributes<any, any>> : T extends factory.actionType.CheckAction ? factory.action.check.paymentMethod.movieTicket.IAction : T extends factory.actionType.CreateAction ? factory.action.create.IAction : factory.action.IAction<factory.action.IAttributes<T, any, any>>;
7
7
  export interface ICancelActionAction {
@@ -14,40 +14,29 @@ export interface ICancelActionAction {
14
14
  typeOf: 'Task';
15
15
  };
16
16
  }
17
- export type IActionRecipe<T extends factory.recipe.RecipeCategory> = T extends factory.recipe.RecipeCategory.checkMovieTicket ? factory.action.check.paymentMethod.movieTicket.IRecipe : T extends factory.recipe.RecipeCategory.payCreditCard ? factory.action.trade.pay.IPayCreditCardRecipe : T extends factory.recipe.RecipeCategory.payMovieTicket ? factory.action.trade.pay.IPayMovieTicketRecipe : T extends factory.recipe.RecipeCategory.publishPaymentUrl ? factory.action.accept.pay.IRecipe : T extends factory.recipe.RecipeCategory.refundCreditCard ? factory.action.trade.refund.IRefundCreditCardRecipe : T extends factory.recipe.RecipeCategory.refundMovieTicket ? factory.action.trade.refund.IRefundMovieTicketRecipe : T extends factory.recipe.RecipeCategory.authorizeInvoice ? factory.action.authorize.invoice.IAuthorizeInvoiceRecipe : T extends factory.recipe.RecipeCategory.authorizeInvoice3ds ? factory.action.authorize.invoice.IAuthorizeInvoice3dsRecipe : T extends factory.recipe.RecipeCategory.acceptCOAOffer ? factory.action.accept.coaOffer.IRecipe : T extends factory.recipe.RecipeCategory.confirmCOAReserve ? factory.action.interact.confirm.reservation.IConfirmCOAReserveRecipe : T extends factory.recipe.RecipeCategory.cancelPendingCOAReserve ? factory.action.cancel.coaReserve.ICancelPendingCOAReserveRecipe : T extends factory.recipe.RecipeCategory.returnCOAReserve ? factory.action.transfer.returnAction.reserveTransaction.IReturnCOAReserveRecipe : T extends factory.recipe.RecipeCategory.sendEmailMessage ? factory.action.transfer.send.message.email.IRecipe : never;
18
- export type IRecipeAsDocument = factory.recipe.IRecipe & {
19
- recipeFor: {
20
- id: string;
21
- typeOf: factory.actionType;
22
- };
23
- dateCreated: Date;
24
- dateModified?: Date;
25
- };
26
- export type IRecipeAsActionAttributes<T extends factory.recipe.RecipeCategory> = Pick<IActionRecipe<T>, 'project' | 'recipeCategory' | 'step' | 'typeOf'>;
27
- export type IMinimizedPurchaseNumberAuthResult = Pick<factory.action.check.paymentMethod.movieTicket.IPurchaseNumberAuthResult, 'mkknmiNumSum' | 'resultInfo' | 'ykknmiNumSum'> & {
28
- knyknrNoInfoOut: Omit<factory.action.check.paymentMethod.movieTicket.IPurchaseNumberInfo, 'ykknInfo' | 'mkknInfo'>[] | null;
29
- };
17
+ export { IActionRecipe };
30
18
  export type IKeyOfProjection = keyof IAction<factory.actionType> | keyof IAction<factory.actionType.AuthorizeAction> | keyof IAction<factory.actionType.ReplaceAction> | 'identifier';
31
19
  export declare const AVAILABLE_PROJECT_FIELDS: IKeyOfProjection[];
32
20
  /**
33
21
  * アクション状態管理リポジトリ
34
22
  */
35
- export declare class ActionProcessRepo<TAction extends IAction<factory.actionType>, TActionRecipe extends IActionRecipe<factory.recipe.RecipeCategory>> {
23
+ export declare class ActionProcessRepo<TAction extends IAction<factory.actionType>, TActionRecipe extends IActionRecipe<factory.recipe.RecipeCategory>> extends ActionRecipeRepo<TActionRecipe> {
36
24
  protected readonly actionModel: IActionModel;
37
- protected readonly actionRecipeModel: IActionRecipeModel;
38
25
  constructor(connection: Connection);
39
26
  static CREATE_MONGO_CONDITIONS(params: factory.action.ISearchConditions): any[];
40
27
  /**
41
28
  * アクション開始
42
29
  */
43
- start<T extends TAction['typeOf']>(attributes: factory.action.IAttributes<T, any, any>, // eslint-disable-line @typescript-eslint/no-explicit-any
44
- options?: {
30
+ start<T extends TAction['typeOf']>(attributes: factory.action.IAttributes<T, any, any> & {
31
+ expires?: Date;
32
+ }, options?: {
45
33
  recipe?: IRecipeAsActionAttributes<TActionRecipe['recipeCategory']>;
46
34
  }): Promise<Pick<IAction<T>, 'id' | 'typeOf' | 'startDate'>>;
47
35
  completeWithVoid(params: {
48
36
  typeOf: TAction['typeOf'];
49
37
  id: string;
50
38
  result: any;
39
+ expires?: Date;
51
40
  recipe?: IRecipeAsActionAttributes<TActionRecipe['recipeCategory']>;
52
41
  }): Promise<void>;
53
42
  /**
@@ -65,28 +54,9 @@ export declare class ActionProcessRepo<TAction extends IAction<factory.actionTyp
65
54
  typeOf: TAction['typeOf'];
66
55
  id: string;
67
56
  error: Error | Error[] | unknown;
57
+ expires?: Date;
68
58
  recipe?: IRecipeAsActionAttributes<TActionRecipe['recipeCategory']>;
69
59
  }): Promise<void>;
70
- /**
71
- * 一定期間ActiveActionStatusのアクションをFailedActionStatusにする
72
- */
73
- giveUpStartDatePassedCertainPeriod(params: {
74
- id?: {
75
- $eq?: string;
76
- };
77
- error: any;
78
- startDate: {
79
- $lt: Date;
80
- };
81
- }): Promise<import("mongoose").UpdateWriteOpResult>;
82
- findRecipeByAction<T extends TActionRecipe['recipeCategory']>(params: {
83
- project: {
84
- id: string;
85
- };
86
- recipeFor: {
87
- id: string;
88
- };
89
- }): Promise<Pick<IActionRecipe<T>, 'step' | 'recipeCategory'> | null>;
90
60
  findById(params: {
91
61
  typeOf: TAction['typeOf'];
92
62
  id: string;
@@ -140,5 +110,4 @@ export declare class ActionProcessRepo<TAction extends IAction<factory.actionTyp
140
110
  };
141
111
  sort?: factory.action.ISortOrder;
142
112
  }): Promise<TAction[]>;
143
- protected upsertRecipe(savingRecipe: Pick<IRecipeAsDocument, 'project' | 'recipeCategory' | 'recipeFor' | 'step' | 'typeOf'>): Promise<void>;
144
113
  }
@@ -4,8 +4,8 @@ exports.ActionProcessRepo = exports.AVAILABLE_PROJECT_FIELDS = void 0;
4
4
  const factory_1 = require("../../factory");
5
5
  const settings_1 = require("../../settings");
6
6
  const action_1 = require("../mongoose/schemas/action");
7
- const actionRecipe_1 = require("../mongoose/schemas/actionRecipe");
8
7
  const unknown2actionError_1 = require("./unknown2actionError");
8
+ const actionRecipe_1 = require("./actionRecipe");
9
9
  exports.AVAILABLE_PROJECT_FIELDS = [
10
10
  'project',
11
11
  'actionStatus',
@@ -27,15 +27,16 @@ exports.AVAILABLE_PROJECT_FIELDS = [
27
27
  'about',
28
28
  'identifier',
29
29
  ];
30
+ const DEFAULT_EXPIRE_AFTER_SECONDS = 17280000; // 200 days
31
+ const RECIPE_DEFAULT_EXPIRE_AFTER_SECONDS = 17280000; // 200 days
30
32
  /**
31
33
  * アクション状態管理リポジトリ
32
34
  */
33
- class ActionProcessRepo {
35
+ class ActionProcessRepo extends actionRecipe_1.ActionRecipeRepo {
34
36
  actionModel;
35
- actionRecipeModel;
36
37
  constructor(connection) {
38
+ super(connection);
37
39
  this.actionModel = connection.model(action_1.modelName, (0, action_1.createSchema)());
38
- this.actionRecipeModel = connection.model(actionRecipe_1.modelName, (0, actionRecipe_1.createSchema)());
39
40
  }
40
41
  static CREATE_MONGO_CONDITIONS(params) {
41
42
  const andConditions = []; // eslint-disable-line @typescript-eslint/no-explicit-any
@@ -436,15 +437,16 @@ class ActionProcessRepo {
436
437
  /**
437
438
  * アクション開始
438
439
  */
439
- async start(
440
- // public async start<T extends Exclude<TAction['typeOf'], factory.actionType.AcceptAction>>(
441
- attributes, // eslint-disable-line @typescript-eslint/no-explicit-any
442
- options) {
440
+ async start(attributes, options) {
443
441
  const startDate = new Date();
442
+ const expires = (attributes.expires instanceof Date)
443
+ ? attributes.expires
444
+ : new Date(startDate.getTime() + DEFAULT_EXPIRE_AFTER_SECONDS * 1000);
444
445
  const creatingAction = {
445
446
  ...attributes,
446
447
  actionStatus: factory_1.factory.actionStatusType.ActiveActionStatus,
447
- startDate
448
+ startDate,
449
+ expires
448
450
  };
449
451
  // reimplemnt with insertMany(2024-08-29~)
450
452
  const result = await this.actionModel.insertMany(creatingAction, { rawResult: true });
@@ -455,13 +457,17 @@ class ActionProcessRepo {
455
457
  // add recipe(2024-06-09~)
456
458
  const savingRecipe = options?.recipe;
457
459
  if (savingRecipe?.typeOf === 'Recipe') {
458
- await this.upsertRecipe({ ...savingRecipe, recipeFor: { id, typeOf: creatingAction.typeOf } });
460
+ await this.upsertRecipe({ ...savingRecipe, recipeFor: { id, typeOf: creatingAction.typeOf }, expires });
459
461
  }
460
462
  return { id, startDate, typeOf: creatingAction.typeOf };
461
463
  }
462
464
  async completeWithVoid(params) {
465
+ const endDate = new Date();
466
+ const recipeExpires = (params.expires instanceof Date)
467
+ ? params.expires
468
+ : new Date(endDate.getTime() + RECIPE_DEFAULT_EXPIRE_AFTER_SECONDS * 1000);
463
469
  if (params.recipe?.typeOf === 'Recipe') {
464
- await this.upsertRecipe({ ...params.recipe, recipeFor: { id: params.id, typeOf: params.typeOf } });
470
+ await this.upsertRecipe({ ...params.recipe, recipeFor: { id: params.id, typeOf: params.typeOf }, expires: recipeExpires });
465
471
  }
466
472
  const doc = await this.actionModel.findOneAndUpdate({
467
473
  _id: { $eq: params.id },
@@ -470,7 +476,7 @@ class ActionProcessRepo {
470
476
  $set: {
471
477
  actionStatus: factory_1.factory.actionStatusType.CompletedActionStatus,
472
478
  result: params.result,
473
- endDate: new Date()
479
+ endDate
474
480
  }
475
481
  }, { new: false, projection: { _id: 1 } })
476
482
  .lean()
@@ -521,14 +527,15 @@ class ActionProcessRepo {
521
527
  * アクション失敗
522
528
  */
523
529
  async giveUp(params) {
524
- // const actionError: IActionError | IActionError[] = (Array.isArray(params.error))
525
- // ? params.error.map((e) => ({ ...e, message: e.message, name: e.name }))
526
- // : { ...params.error, message: params.error.message, name: params.error.name };
530
+ const endDate = new Date();
531
+ const recipeExpires = (params.expires instanceof Date)
532
+ ? params.expires
533
+ : new Date(endDate.getTime() + RECIPE_DEFAULT_EXPIRE_AFTER_SECONDS * 1000);
527
534
  const actionError = Array.isArray(params.error)
528
535
  ? params.error.map(unknown2actionError_1.unknown2actionError)
529
536
  : (0, unknown2actionError_1.unknown2actionError)(params.error);
530
537
  if (params.recipe?.typeOf === 'Recipe') {
531
- await this.upsertRecipe({ ...params.recipe, recipeFor: { id: params.id, typeOf: params.typeOf } });
538
+ await this.upsertRecipe({ ...params.recipe, recipeFor: { id: params.id, typeOf: params.typeOf }, expires: recipeExpires });
532
539
  }
533
540
  const doc = await this.actionModel.findOneAndUpdate({
534
541
  typeOf: { $eq: params.typeOf },
@@ -537,7 +544,7 @@ class ActionProcessRepo {
537
544
  $set: {
538
545
  actionStatus: factory_1.factory.actionStatusType.FailedActionStatus,
539
546
  error: actionError,
540
- endDate: new Date()
547
+ endDate
541
548
  }
542
549
  }, { new: true, projection: { _id: 1 } })
543
550
  .lean()
@@ -546,36 +553,6 @@ class ActionProcessRepo {
546
553
  throw new factory_1.factory.errors.NotFound(this.actionModel.modelName);
547
554
  }
548
555
  }
549
- /**
550
- * 一定期間ActiveActionStatusのアクションをFailedActionStatusにする
551
- */
552
- async giveUpStartDatePassedCertainPeriod(params) {
553
- return this.actionModel.updateMany({
554
- actionStatus: { $eq: factory_1.factory.actionStatusType.ActiveActionStatus },
555
- // 一定期間過ぎたもの
556
- startDate: { $lt: params.startDate.$lt },
557
- ...(typeof params.id?.$eq === 'string') ? { _id: { $eq: params.id.$eq } } : undefined
558
- }, {
559
- actionStatus: factory_1.factory.actionStatusType.FailedActionStatus,
560
- error: params.error,
561
- endDate: new Date()
562
- })
563
- .exec();
564
- }
565
- async findRecipeByAction(params) {
566
- return this.actionRecipeModel.findOne({
567
- 'project.id': { $eq: params.project.id },
568
- 'recipeFor.id': { $eq: params.recipeFor.id }
569
- }, { step: 1, recipeCategory: 1 }
570
- // { lean: true }
571
- )
572
- .lean()
573
- .exec();
574
- // if (result === null) {
575
- // throw new factory.errors.NotFound(this.actionRecipeModel.modelName);
576
- // }
577
- // return result;
578
- }
579
556
  async findById(params, inclusion, exclusion) {
580
557
  let positiveProjectionFields = exports.AVAILABLE_PROJECT_FIELDS;
581
558
  if (Array.isArray(inclusion) && inclusion.length > 0) {
@@ -733,26 +710,5 @@ class ActionProcessRepo {
733
710
  .lean()
734
711
  .exec();
735
712
  }
736
- async upsertRecipe(savingRecipe) {
737
- const dateModified = new Date();
738
- const { typeOf, project, recipeCategory, recipeFor, step } = savingRecipe;
739
- const filter = {
740
- 'recipeFor.id': { $eq: recipeFor.id }
741
- };
742
- const setOnInsert = {
743
- project, typeOf, recipeCategory, recipeFor,
744
- dateCreated: dateModified
745
- };
746
- const setKeys = { step, dateModified };
747
- const update = {
748
- $setOnInsert: setOnInsert,
749
- $set: setKeys
750
- };
751
- await this.actionRecipeModel.updateOne(filter, update, {
752
- upsert: true
753
- // includeResultMetadata: true
754
- })
755
- .exec();
756
- }
757
713
  }
758
714
  exports.ActionProcessRepo = ActionProcessRepo;
@@ -0,0 +1,32 @@
1
+ import { Connection } from 'mongoose';
2
+ import { factory } from '../../factory';
3
+ import { IModel as IActionRecipeModel } from '../mongoose/schemas/actionRecipe';
4
+ export type IActionRecipe<T extends factory.recipe.RecipeCategory> = T extends factory.recipe.RecipeCategory.checkMovieTicket ? factory.action.check.paymentMethod.movieTicket.IRecipe : T extends factory.recipe.RecipeCategory.payCreditCard ? factory.action.trade.pay.IPayCreditCardRecipe : T extends factory.recipe.RecipeCategory.payMovieTicket ? factory.action.trade.pay.IPayMovieTicketRecipe : T extends factory.recipe.RecipeCategory.publishPaymentUrl ? factory.action.accept.pay.IRecipe : T extends factory.recipe.RecipeCategory.refundCreditCard ? factory.action.trade.refund.IRefundCreditCardRecipe : T extends factory.recipe.RecipeCategory.refundMovieTicket ? factory.action.trade.refund.IRefundMovieTicketRecipe : T extends factory.recipe.RecipeCategory.authorizeInvoice ? factory.action.authorize.invoice.IAuthorizeInvoiceRecipe : T extends factory.recipe.RecipeCategory.authorizeInvoice3ds ? factory.action.authorize.invoice.IAuthorizeInvoice3dsRecipe : T extends factory.recipe.RecipeCategory.acceptCOAOffer ? factory.action.accept.coaOffer.IRecipe : T extends factory.recipe.RecipeCategory.confirmCOAReserve ? factory.action.interact.confirm.reservation.IConfirmCOAReserveRecipe : T extends factory.recipe.RecipeCategory.cancelPendingCOAReserve ? factory.action.cancel.coaReserve.ICancelPendingCOAReserveRecipe : T extends factory.recipe.RecipeCategory.returnCOAReserve ? factory.action.transfer.returnAction.reserveTransaction.IReturnCOAReserveRecipe : T extends factory.recipe.RecipeCategory.sendEmailMessage ? factory.action.transfer.send.message.email.IRecipe : never;
5
+ export type IRecipeAsDocument = factory.recipe.IRecipe & {
6
+ recipeFor: {
7
+ id: string;
8
+ typeOf: factory.actionType;
9
+ };
10
+ dateCreated: Date;
11
+ dateModified?: Date;
12
+ expires: Date;
13
+ };
14
+ export type IRecipeAsActionAttributes<T extends factory.recipe.RecipeCategory> = Pick<IActionRecipe<T>, 'project' | 'recipeCategory' | 'step' | 'typeOf'>;
15
+ /**
16
+ * アクションレシピリポジトリ
17
+ */
18
+ export declare class ActionRecipeRepo<TActionRecipe extends IActionRecipe<factory.recipe.RecipeCategory>> {
19
+ protected readonly actionRecipeModel: IActionRecipeModel;
20
+ protected constructor(connection: Connection);
21
+ findRecipeByAction<T extends TActionRecipe['recipeCategory']>(params: {
22
+ project: {
23
+ id: string;
24
+ };
25
+ recipeFor: {
26
+ id: string;
27
+ };
28
+ }): Promise<Pick<IActionRecipe<T>, 'step' | 'recipeCategory'> | null>;
29
+ upsertRecipe(savingRecipe: Pick<IRecipeAsDocument, 'project' | 'recipeCategory' | 'recipeFor' | 'step' | 'typeOf'> & {
30
+ expires: Date;
31
+ }): Promise<void>;
32
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ActionRecipeRepo = void 0;
4
+ const actionRecipe_1 = require("../mongoose/schemas/actionRecipe");
5
+ /**
6
+ * アクションレシピリポジトリ
7
+ */
8
+ class ActionRecipeRepo {
9
+ actionRecipeModel;
10
+ constructor(connection) {
11
+ this.actionRecipeModel = connection.model(actionRecipe_1.modelName, (0, actionRecipe_1.createSchema)());
12
+ }
13
+ async findRecipeByAction(params) {
14
+ return this.actionRecipeModel.findOne({
15
+ 'project.id': { $eq: params.project.id },
16
+ 'recipeFor.id': { $eq: params.recipeFor.id }
17
+ }, { step: 1, recipeCategory: 1 }
18
+ // { lean: true }
19
+ )
20
+ .lean()
21
+ .exec();
22
+ // if (result === null) {
23
+ // throw new factory.errors.NotFound(this.actionRecipeModel.modelName);
24
+ // }
25
+ // return result;
26
+ }
27
+ async upsertRecipe(savingRecipe) {
28
+ const dateModified = new Date();
29
+ const { typeOf, project, recipeCategory, recipeFor, step, expires } = savingRecipe;
30
+ const filter = {
31
+ 'recipeFor.id': { $eq: recipeFor.id }
32
+ };
33
+ const setOnInsert = {
34
+ project, typeOf, recipeCategory, recipeFor,
35
+ dateCreated: dateModified,
36
+ expires // 必須化(2026-08-16~)
37
+ };
38
+ const setKeys = { step, dateModified };
39
+ const update = {
40
+ $setOnInsert: setOnInsert,
41
+ $set: setKeys
42
+ };
43
+ await this.actionRecipeModel.updateOne(filter, update, {
44
+ upsert: true
45
+ // includeResultMetadata: true
46
+ })
47
+ .exec();
48
+ }
49
+ }
50
+ exports.ActionRecipeRepo = ActionRecipeRepo;
@@ -18,8 +18,10 @@ const AVAILABLE_PROJECT_FIELDS = [
18
18
  'about',
19
19
  'purpose',
20
20
  'recipient',
21
- 'target'
21
+ 'target',
22
+ 'expires'
22
23
  ];
24
+ const EXPIRE_AFTER_SECONDS = 2592000; // 30 days
23
25
  /**
24
26
  * 通知アクションリポジトリ
25
27
  */
@@ -65,10 +67,12 @@ class InformActionRepo {
65
67
  */
66
68
  async startInformAction(attributes) {
67
69
  const startDate = new Date();
70
+ const expires = new Date(startDate.getTime() + EXPIRE_AFTER_SECONDS * 1000);
68
71
  const creatingAction = {
69
72
  ...attributes,
70
73
  actionStatus: factory_1.factory.actionStatusType.ActiveActionStatus,
71
- startDate
74
+ startDate,
75
+ expires
72
76
  };
73
77
  const result = await this.informActionModel.insertMany(creatingAction, { rawResult: true });
74
78
  const id = result.insertedIds?.[0]?.toHexString();
@@ -3,6 +3,7 @@ import { factory } from '../../factory';
3
3
  import { IDocType } from '../mongoose/schemas/action/update';
4
4
  type StartableActionType = factory.actionType.AddAction | factory.actionType.UpdateAction | factory.actionType.ReplaceAction | factory.actionType.DeleteAction;
5
5
  type IAction<T extends StartableActionType> = T extends factory.actionType.AddAction ? factory.action.update.add.IAction : T extends factory.actionType.ReplaceAction ? factory.action.update.replace.IAction : T extends factory.actionType.UpdateAction ? factory.action.update.update.IAction : T extends factory.actionType.DeleteAction ? factory.action.update.deleteAction.IAction : never;
6
+ type IActionAttributes<T extends StartableActionType> = T extends factory.actionType.AddAction ? factory.action.update.add.IAttributes : T extends factory.actionType.ReplaceAction ? factory.action.update.replace.IAttributes : T extends factory.actionType.UpdateAction ? factory.action.update.update.IAttributes : T extends factory.actionType.DeleteAction ? factory.action.update.deleteAction.IAttributes : never;
6
7
  type IKeyOfProjection = keyof IDocType;
7
8
  type IFindParams = factory.action.update.update.IFindParams;
8
9
  /**
@@ -15,7 +16,7 @@ export declare class UpdateActionRepo {
15
16
  /**
16
17
  * アクション開始
17
18
  */
18
- startUpdateAction<T extends StartableActionType>(attributes: factory.action.IAttributes<T, any, any>): Promise<Pick<IAction<T>, 'id' | 'typeOf' | 'startDate'>>;
19
+ startUpdateAction<T extends StartableActionType>(attributes: IActionAttributes<T>): Promise<Pick<IAction<T>, 'id' | 'typeOf' | 'startDate'>>;
19
20
  completeUpdateAction(params: {
20
21
  typeOf: StartableActionType;
21
22
  id: string;
@@ -18,7 +18,9 @@ const AVAILABLE_PROJECT_FIELDS = [
18
18
  'instrument',
19
19
  'targetCollection',
20
20
  'sameAs',
21
+ 'expires'
21
22
  ];
23
+ const EXPIRE_AFTER_SECONDS = 2592000; // 30 days
22
24
  /**
23
25
  * リソース編集アクションリポジトリ
24
26
  */
@@ -63,10 +65,12 @@ class UpdateActionRepo {
63
65
  */
64
66
  async startUpdateAction(attributes) {
65
67
  const startDate = new Date();
68
+ const expires = new Date(startDate.getTime() + EXPIRE_AFTER_SECONDS * 1000);
66
69
  const creatingAction = {
67
70
  ...attributes,
68
71
  actionStatus: factory_1.factory.actionStatusType.ActiveActionStatus,
69
- startDate
72
+ startDate,
73
+ expires
70
74
  };
71
75
  const result = await this.updateActionModel.insertMany(creatingAction, { rawResult: true });
72
76
  const id = result.insertedIds?.[0]?.toHexString();
@@ -15,8 +15,10 @@ const AVAILABLE_PROJECT_FIELDS = [
15
15
  'startDate',
16
16
  'endDate',
17
17
  'instrument',
18
- 'location'
18
+ 'location',
19
+ 'expires'
19
20
  ];
21
+ const EXPIRE_AFTER_SECONDS = 2592000; // 30 days
20
22
  /**
21
23
  * 予約使用アクションリポジトリ
22
24
  */
@@ -58,10 +60,12 @@ class UseActionRepo {
58
60
  */
59
61
  async startUseAction(attributes) {
60
62
  const startDate = new Date();
63
+ const expires = new Date(startDate.getTime() + EXPIRE_AFTER_SECONDS * 1000);
61
64
  const creatingAction = {
62
65
  ...attributes,
63
66
  actionStatus: factory_1.factory.actionStatusType.ActiveActionStatus,
64
- startDate
67
+ startDate,
68
+ expires
65
69
  };
66
70
  const result = await this.useActionModel.insertMany(creatingAction, { rawResult: true });
67
71
  const id = result.insertedIds?.[0]?.toHexString();
@@ -1,7 +1,7 @@
1
1
  import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
2
2
  import { IVirtuals } from '../../virtuals';
3
3
  import { factory } from '../../../../factory';
4
- type IDocType = Pick<factory.action.interact.inform.IAction, 'about' | 'actionStatus' | 'agent' | 'endDate' | 'object' | 'project' | 'recipient' | 'result' | 'startDate' | 'target' | 'typeOf' | 'purpose' | 'error'>;
4
+ type IDocType = Pick<factory.action.interact.inform.IAction, 'about' | 'actionStatus' | 'agent' | 'endDate' | 'object' | 'project' | 'recipient' | 'result' | 'startDate' | 'target' | 'typeOf' | 'purpose' | 'error' | 'expires'>;
5
5
  type IModel = Model<IDocType, Record<string, never>, Record<string, never>, IVirtuals>;
6
6
  type ISchemaDefinition = SchemaDefinition<IDocType>;
7
7
  type ISchema = Schema<IDocType, IModel, Record<string, never>, Record<string, never>, IVirtuals, Record<string, never>, ISchemaDefinition, IDocType>;
@@ -14,6 +14,7 @@ const schemaDefinition = {
14
14
  agent: { type: mongoose_1.SchemaTypes.Mixed, required: true },
15
15
  object: { type: mongoose_1.SchemaTypes.Mixed, required: true },
16
16
  startDate: { type: Date, required: true },
17
+ expires: { type: Date, required: true },
17
18
  target: { type: mongoose_1.SchemaTypes.Mixed, required: true },
18
19
  recipient: { type: mongoose_1.SchemaTypes.Mixed, required: true },
19
20
  result: mongoose_1.SchemaTypes.Mixed,
@@ -48,14 +49,18 @@ const schemaOptions = {
48
49
  };
49
50
  const indexes = [
50
51
  [
51
- { startDate: 1 },
52
+ { expires: 1 },
52
53
  {
53
- name: 'ttlByStartDate',
54
- expireAfterSeconds: 2592000 // 30 days
54
+ name: 'expires',
55
+ expireAfterSeconds: 0
55
56
  }
56
57
  ],
57
58
  [
58
- { 'project.id': 1, startDate: 1 },
59
+ { startDate: -1 },
60
+ { name: 'startDate' }
61
+ ],
62
+ [
63
+ { 'project.id': 1, startDate: -1 },
59
64
  { name: 'projectId' }
60
65
  ],
61
66
  ];
@@ -1,7 +1,7 @@
1
1
  import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
2
2
  import { IVirtuals } from '../../virtuals';
3
3
  import { factory } from '../../../../factory';
4
- type Keys = 'actionStatus' | 'agent' | 'endDate' | 'error' | 'instrument' | 'object' | 'project' | 'result' | 'sameAs' | 'startDate' | 'targetCollection' | 'typeOf';
4
+ type Keys = 'actionStatus' | 'agent' | 'endDate' | 'error' | 'instrument' | 'object' | 'project' | 'result' | 'sameAs' | 'startDate' | 'targetCollection' | 'typeOf' | 'expires';
5
5
  type IDocType = Pick<factory.action.update.add.IAction, Keys> | Pick<factory.action.update.replace.IAction, Keys> | Pick<factory.action.update.update.IAction, Keys> | Pick<factory.action.update.deleteAction.IAction, Keys>;
6
6
  type IModel = Model<IDocType, Record<string, never>, Record<string, never>, IVirtuals>;
7
7
  type ISchemaDefinition = SchemaDefinition<IDocType>;
@@ -14,6 +14,7 @@ const schemaDefinition = {
14
14
  agent: { type: mongoose_1.SchemaTypes.Mixed, required: true },
15
15
  object: { type: mongoose_1.SchemaTypes.Mixed, required: true },
16
16
  startDate: { type: Date, required: true },
17
+ expires: { type: Date, required: true },
17
18
  result: mongoose_1.SchemaTypes.Mixed,
18
19
  error: mongoose_1.SchemaTypes.Mixed,
19
20
  endDate: Date,
@@ -47,22 +48,26 @@ const schemaOptions = {
47
48
  };
48
49
  const indexes = [
49
50
  [
50
- { startDate: 1 },
51
+ { expires: 1 },
51
52
  {
52
- name: 'ttlByStartDate',
53
- expireAfterSeconds: 2592000 // 30 days
53
+ name: 'expires',
54
+ expireAfterSeconds: 0
54
55
  }
55
56
  ],
56
57
  [
57
- { 'project.id': 1, startDate: 1 },
58
+ { startDate: -1 },
59
+ { name: 'startDate' }
60
+ ],
61
+ [
62
+ { 'project.id': 1, startDate: -1 },
58
63
  { name: 'projectId' }
59
64
  ],
60
65
  [
61
- { typeOf: 1, startDate: 1 },
66
+ { typeOf: 1, startDate: -1 },
62
67
  { name: 'typeOf' }
63
68
  ],
64
69
  [
65
- { 'object.id': 1, startDate: 1 },
70
+ { 'object.id': 1, startDate: -1 },
66
71
  {
67
72
  name: 'objectId',
68
73
  partialFilterExpression: {
@@ -71,7 +76,7 @@ const indexes = [
71
76
  }
72
77
  ],
73
78
  [
74
- { 'result.id': 1, startDate: 1 },
79
+ { 'result.id': 1, startDate: -1 },
75
80
  {
76
81
  name: 'resultId',
77
82
  partialFilterExpression: {
@@ -80,7 +85,7 @@ const indexes = [
80
85
  }
81
86
  ],
82
87
  [
83
- { 'sameAs.id': 1, startDate: 1 },
88
+ { 'sameAs.id': 1, startDate: -1 },
84
89
  {
85
90
  name: 'sameAsId',
86
91
  partialFilterExpression: {
@@ -1,7 +1,7 @@
1
1
  import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
2
2
  import { IVirtuals } from '../../virtuals';
3
3
  import { factory } from '../../../../factory';
4
- type IDocType = Pick<factory.action.consume.use.reservation.IAction, 'actionStatus' | 'agent' | 'endDate' | 'error' | 'instrument' | 'location' | 'object' | 'project' | 'startDate' | 'typeOf'>;
4
+ type IDocType = Pick<factory.action.consume.use.reservation.IAction, 'actionStatus' | 'agent' | 'endDate' | 'error' | 'instrument' | 'location' | 'object' | 'project' | 'startDate' | 'typeOf' | 'expires'>;
5
5
  type IModel = Model<IDocType, Record<string, never>, Record<string, never>, IVirtuals>;
6
6
  type ISchemaDefinition = SchemaDefinition<IDocType>;
7
7
  type ISchema = Schema<IDocType, IModel, Record<string, never>, Record<string, never>, IVirtuals, Record<string, never>, ISchemaDefinition, IDocType>;
@@ -14,6 +14,7 @@ const schemaDefinition = {
14
14
  agent: { type: mongoose_1.SchemaTypes.Mixed, required: true },
15
15
  object: { type: mongoose_1.SchemaTypes.Mixed, required: true },
16
16
  startDate: { type: Date, required: true },
17
+ expires: { type: Date, required: true },
17
18
  instrument: mongoose_1.SchemaTypes.Mixed,
18
19
  location: mongoose_1.SchemaTypes.Mixed,
19
20
  error: mongoose_1.SchemaTypes.Mixed,
@@ -45,22 +46,26 @@ const schemaOptions = {
45
46
  };
46
47
  const indexes = [
47
48
  [
48
- { startDate: 1 },
49
+ { expires: 1 },
49
50
  {
50
- name: 'ttlByStartDate',
51
- expireAfterSeconds: 2592000 // 30 days
51
+ name: 'expires',
52
+ expireAfterSeconds: 0
52
53
  }
53
54
  ],
54
55
  [
55
- { 'project.id': 1, startDate: 1 },
56
+ { startDate: -1 },
57
+ { name: 'startDate' }
58
+ ],
59
+ [
60
+ { 'project.id': 1, startDate: -1 },
56
61
  { name: 'projectId' }
57
62
  ],
58
63
  [
59
- { actionStatus: 1, startDate: 1 },
64
+ { actionStatus: 1, startDate: -1 },
60
65
  { name: 'actionStatus' }
61
66
  ],
62
67
  [
63
- { 'object.id': 1, startDate: 1 },
68
+ { 'object.id': 1, startDate: -1 },
64
69
  {
65
70
  name: 'objectId',
66
71
  partialFilterExpression: {
@@ -27,6 +27,7 @@ const schemaDefinition = {
27
27
  cancelAction: mongoose_1.SchemaTypes.Mixed, // add(2024-05-26~)
28
28
  about: mongoose_1.SchemaTypes.Mixed, // add(2025-01-22~)
29
29
  identifier: mongoose_1.SchemaTypes.Mixed, // add(2025-02-06~)
30
+ expires: Date // support(2026-08-16~)
30
31
  // replacer: SchemaTypes.Mixed, // discontinue(2026-08-15~)
31
32
  // targetCollection: SchemaTypes.Mixed, // discontinue(2026-08-15~)
32
33
  // target: SchemaTypes.Mixed, // discontinue(2026-08-15~)
@@ -7,6 +7,7 @@ type IDocType = factory.recipe.IRecipe & {
7
7
  };
8
8
  dateCreated?: Date;
9
9
  dateModified?: Date;
10
+ expires?: Date;
10
11
  };
11
12
  type IModel = Model<IDocType, Record<string, never>, Record<string, never>, IVirtuals>;
12
13
  type ISchemaDefinition = SchemaDefinition<IDocType>;
@@ -29,7 +29,8 @@ const schemaDefinition = {
29
29
  type: Date,
30
30
  required: true
31
31
  },
32
- dateModified: Date
32
+ dateModified: Date,
33
+ expires: Date // support(2026-08-16~)
33
34
  };
34
35
  const schemaOptions = {
35
36
  autoIndex: settings_1.MONGO_AUTO_INDEX,
@@ -1,13 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.createSendEmailMessageTaskIfNotExist = createSendEmailMessageTaskIfNotExist;
7
- const debug_1 = __importDefault(require("debug"));
8
4
  const util_1 = require("util");
9
5
  const factory_1 = require("../../../../factory");
10
- const debug = (0, debug_1.default)('chevre-domain:service:order');
11
6
  function createSendEmailMessageTaskIfNotExist(params) {
12
7
  return async (repos) => {
13
8
  const sendEmailMessageActions = params.sendEmailMessage;
@@ -19,12 +14,10 @@ function createSendEmailMessageTaskIfNotExist(params) {
19
14
  about: { identifier: { $eq: factory_1.factory.creativeWork.message.email.AboutIdentifier.OnOrderSent } },
20
15
  mainEntity: { orderNumber: { $eq: params.order.orderNumber } }
21
16
  }, ['identifier'])).shift();
22
- debug('createSendEmailMessageTaskIfNotExist: message4order:', JSON.stringify(message4order));
23
17
  if (typeof message4order?.identifier === 'string') {
24
18
  // 取引のpotentialActionsが存在する間は、メッセージ識別子が想定通りか確認する
25
19
  const messageIdentifierByTransaction = sendEmailMessageActions?.at(0)?.object.identifier;
26
20
  if (typeof messageIdentifierByTransaction === 'string') {
27
- debug('createSendEmailMessageTaskIfNotExist: identifier matched?', message4order.identifier, messageIdentifierByTransaction);
28
21
  if (message4order.identifier !== messageIdentifierByTransaction) {
29
22
  throw new factory_1.factory.errors.Internal(`message identifier not matched. ${message4order.identifier} ${messageIdentifierByTransaction}`);
30
23
  }
@@ -44,7 +37,6 @@ function createSendEmailMessageTaskIfNotExist(params) {
44
37
  typeOf: factory_1.factory.creativeWorkType.EmailMessage
45
38
  },
46
39
  agent: params.order.project,
47
- recipient: { typeOf: params.order.customer.typeOf, id: params.order.customer.id },
48
40
  purpose: simpleOrder
49
41
  };
50
42
  const sendEmailMessageTask = {
@@ -123,8 +123,6 @@ function createOnOrderReturnedTasksByTransaction(params) {
123
123
  const simpleOrder = {
124
124
  typeOf: params.order.typeOf,
125
125
  orderNumber: params.order.orderNumber,
126
- // price: params.order.price,
127
- // priceCurrency: params.order.priceCurrency,
128
126
  orderDate: params.order.orderDate
129
127
  };
130
128
  sendEmailMessageAttributes.forEach((s) => {
@@ -133,8 +131,6 @@ function createOnOrderReturnedTasksByTransaction(params) {
133
131
  typeOf: factory_1.factory.actionType.SendAction,
134
132
  object: s.object,
135
133
  agent: params.order.project,
136
- recipient: { typeOf: params.order.customer.typeOf, id: params.order.customer.id },
137
- // potentialActions: {}, // discontinue(2024-06-25~)
138
134
  purpose: simpleOrder
139
135
  };
140
136
  const sendEmailMessageTask = {
@@ -3,7 +3,6 @@ import type { ActionRepo } from '../../repo/action';
3
3
  import type { OrderRepo } from '../../repo/order';
4
4
  import type { SettingRepo } from '../../repo/setting';
5
5
  import type { TaskRepo } from '../../repo/task';
6
- import type { PlaceOrderRepo } from '../../repo/transaction/placeOrder';
7
6
  import { factory } from '../../factory';
8
7
  interface ISendOrderRepos {
9
8
  acceptedOffer: AcceptedOfferRepo;
@@ -11,7 +10,6 @@ interface ISendOrderRepos {
11
10
  order: OrderRepo;
12
11
  setting: SettingRepo;
13
12
  task: TaskRepo;
14
- placeOrder: PlaceOrderRepo;
15
13
  }
16
14
  type ISendOperation<T> = (repos: ISendOrderRepos) => Promise<T>;
17
15
  /**
@@ -1,14 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.sendOrder = sendOrder;
7
- const debug_1 = __importDefault(require("debug"));
8
4
  // import { createOwnershipInfosFromOrder } from '../delivery/factory';
9
5
  const onOrderStatusChanged_1 = require("./onOrderStatusChanged");
10
6
  const factory_1 = require("../../factory");
11
- const debug = (0, debug_1.default)('chevre-domain:service:order');
12
7
  /**
13
8
  * 注文を配送する
14
9
  */
@@ -32,11 +27,6 @@ function sendOrder(params) {
32
27
  try {
33
28
  const orderNumber = params.object.orderNumber;
34
29
  const confirmationNumber = params.object.confirmationNumber;
35
- // const placeOrderTransaction = await findPlaceOrderTransaction({
36
- // project: { id: params.project.id },
37
- // confirmationNumber,
38
- // orderNumber
39
- // })(repos);
40
30
  // 注文取得
41
31
  let order = await repos.order.projectFieldsByOrderNumber({
42
32
  orderNumber,
@@ -66,12 +56,9 @@ function sendOrder(params) {
66
56
  agent: (typeof params.agent?.typeOf === 'string') ? params.agent : order.project,
67
57
  object: sendOrderObject,
68
58
  project: order.project,
69
- recipient: { id: order.customer.id, typeOf: order.customer.typeOf },
70
59
  typeOf: factory_1.factory.actionType.SendAction
71
60
  };
72
61
  const action = await repos.action.start(sendOrderActionAttributes);
73
- // let creatingOwnershipInfos: IOwnershipInfo[] = [];
74
- const createdOwnershipInfos = [];
75
62
  let allOffersDelivered = false;
76
63
  let acceptedOffers;
77
64
  // 所有権管理はひとまず廃止(2026-08-10~)
@@ -91,22 +78,8 @@ function sendOrder(params) {
91
78
  project: { id: { $eq: order.project.id } }
92
79
  });
93
80
  acceptedOffers = searchSlicedAcceptedOffersResult.acceptedOffers;
94
- debug('delivering...', order.orderNumber, params.object.acceptedOffers, 'offerIndexBase:', offerIndexBase);
95
81
  // 所有権管理はひとまず廃止(2026-08-10~)
96
82
  // if (createOwnerships) {
97
- // creatingOwnershipInfos = createOwnershipInfosFromOrder({
98
- // order: { ...order, acceptedOffers },
99
- // offerIndexBase
100
- // });
101
- // createdOwnershipInfos = await Promise.all(creatingOwnershipInfos.map(async (creatingOwnershipInfo) => {
102
- // const { id } = await repos.ownershipInfo.createIfNotExistByIdentifier(creatingOwnershipInfo);
103
- // return {
104
- // id,
105
- // ...(typeof creatingOwnershipInfo.identifier === 'string')
106
- // ? { identifier: creatingOwnershipInfo.identifier }
107
- // : undefined
108
- // };
109
- // }));
110
83
  // }
111
84
  if (acceptedOffers.length === 0) {
112
85
  order = await repos.order.changeStatus({
@@ -127,9 +100,8 @@ function sendOrder(params) {
127
100
  }
128
101
  throw error;
129
102
  }
130
- const result = createdOwnershipInfos;
103
+ const result = [];
131
104
  await repos.action.completeWithVoid({ typeOf: sendOrderActionAttributes.typeOf, id: action.id, result: result });
132
- debug('allOffersDelivered?:', allOffersDelivered, order.orderNumber);
133
105
  if (params.useOnOrderStatusChanged) {
134
106
  if (allOffersDelivered) {
135
107
  await (0, onOrderStatusChanged_1.onOrderDelivered)({
@@ -293,8 +293,6 @@ function onRefund(params) {
293
293
  const simpleOrder = {
294
294
  typeOf: order.typeOf,
295
295
  orderNumber: order.orderNumber,
296
- // price: order.price,
297
- // priceCurrency: order.priceCurrency,
298
296
  orderDate: order.orderDate
299
297
  };
300
298
  sendEmailMessageByPotentialActions.forEach((s) => {
@@ -303,7 +301,6 @@ function onRefund(params) {
303
301
  typeOf: factory_1.factory.actionType.SendAction,
304
302
  object: s.object,
305
303
  agent: refundActionAttributes.project,
306
- recipient: { typeOf: order.customer.typeOf, id: order.customer.id },
307
304
  purpose: simpleOrder
308
305
  };
309
306
  const sendEmailMessageTask = {
@@ -5,10 +5,8 @@ const factory_1 = require("../../factory");
5
5
  const acceptedOffer_1 = require("../../repo/acceptedOffer");
6
6
  const action_1 = require("../../repo/action");
7
7
  const order_1 = require("../../repo/order");
8
- // import { OwnershipInfoRepo } from '../../repo/ownershipInfo';
9
8
  const setting_1 = require("../../repo/setting");
10
9
  const task_1 = require("../../repo/task");
11
- const placeOrder_1 = require("../../repo/transaction/placeOrder");
12
10
  const sendOrder_1 = require("../order/sendOrder");
13
11
  /**
14
12
  * タスク実行関数
@@ -32,10 +30,8 @@ function call(params) {
32
30
  acceptedOffer: new acceptedOffer_1.AcceptedOfferRepo(connection),
33
31
  action: new action_1.ActionRepo(connection),
34
32
  order: new order_1.OrderRepo(connection),
35
- // ownershipInfo: new OwnershipInfoRepo(connection),
36
33
  setting: new setting_1.SettingRepo(connection),
37
34
  task: new task_1.TaskRepo(connection),
38
- placeOrder: new placeOrder_1.PlaceOrderRepo(connection)
39
35
  });
40
36
  };
41
37
  }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "dependencies": {
12
12
  "@aws-sdk/client-cognito-identity-provider": "3.1090.0",
13
13
  "@aws-sdk/credential-providers": "3.1090.0",
14
- "@chevre/factory": "10.3.0-alpha.9",
14
+ "@chevre/factory": "10.3.0-alpha.11",
15
15
  "@motionpicture/coa-service": "10.0.0",
16
16
  "@motionpicture/gmo-service": "6.1.0-alpha.0",
17
17
  "@sendgrid/client": "8.1.4",
@@ -88,5 +88,5 @@
88
88
  "postversion": "git push origin --tags",
89
89
  "prepublishOnly": "npm run clean && npm run build"
90
90
  },
91
- "version": "26.0.0-alpha.35"
91
+ "version": "26.0.0-alpha.37"
92
92
  }