@chevre/domain 21.32.0-alpha.16 → 21.32.0-alpha.18

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.
@@ -4,7 +4,7 @@ import * as mongoose from 'mongoose';
4
4
 
5
5
  import { chevre } from '../../../../lib/index';
6
6
 
7
- // const project = { id: String(process.env.PROJECT_ID) };
7
+ const project = { id: String(process.env.PROJECT_ID) };
8
8
 
9
9
  // tslint:disable-next-line:max-func-body-length
10
10
  async function main() {
@@ -36,18 +36,23 @@ async function main() {
36
36
  kbnMgtk: ''
37
37
  }
38
38
  }
39
- ]
39
+ ],
40
+ appliesToSurfrock: {
41
+ identifier: '',
42
+ serviceOutput: { typeOf: '' }
43
+ },
44
+ flgMember: COA.factory.reserve.FlgMember.NonMember,
45
+ typeOf: chevre.factory.offerType.AggregateOffer
40
46
  },
41
47
  agent: {
48
+ id: 'xxx',
42
49
  typeOf: chevre.factory.creativeWorkType.WebApplication
43
50
  },
44
- purpose: { id: '664e80c79801179aabb0476f' },
45
- appliesToSurfrock: {
46
- identifier: '',
47
- serviceOutput: { typeOf: '' }
48
- },
49
- flgMember: COA.factory.reserve.FlgMember.NonMember,
50
- sameAs: { id: 'xxx' }
51
+ purpose: { id: '664e80c79801179aabb0476f', typeOf: chevre.factory.transactionType.PlaceOrder },
52
+ sameAs: { id: 'xxx', typeOf: 'Task' },
53
+ potentialActions: { typeOf: chevre.factory.actionType.AuthorizeAction },
54
+ typeOf: chevre.factory.actionType.AcceptAction,
55
+ project: { id: project.id, typeOf: chevre.factory.organizationType.Project }
51
56
  })({
52
57
  action: await chevre.repository.Action.createInstance(mongoose.connection),
53
58
  event: await chevre.repository.Event.createInstance(mongoose.connection),
@@ -49,6 +49,16 @@ interface IStatus {
49
49
  interface IAggregateAction {
50
50
  statuses: IStatus[];
51
51
  }
52
+ export interface ICancelActionAction {
53
+ typeOf: factory.actionType.CancelAction;
54
+ agent: factory.action.IParticipantAsPerson | factory.action.IParticipantAsProject | factory.action.IParticipantAsWebApplication;
55
+ endTime: Date;
56
+ startTime: Date;
57
+ sameAs?: {
58
+ id: string;
59
+ typeOf: 'Task';
60
+ };
61
+ }
52
62
  /**
53
63
  * アクションリポジトリ
54
64
  */
@@ -81,8 +91,9 @@ export declare class MongoRepository {
81
91
  * アクション取消
82
92
  */
83
93
  cancelWithVoid(params: {
84
- typeOf: factory.actionType;
94
+ typeOf: factory.actionType.AuthorizeAction;
85
95
  id: string;
96
+ cancelAction?: Pick<ICancelActionAction, 'agent' | 'sameAs' | 'startTime'>;
86
97
  }): Promise<void>;
87
98
  /**
88
99
  * アクション失敗
@@ -505,19 +505,30 @@ class MongoRepository {
505
505
  */
506
506
  cancelWithVoid(params) {
507
507
  return __awaiter(this, void 0, void 0, function* () {
508
+ const cancelDate = new Date();
509
+ const cancelAction = (params.cancelAction !== undefined)
510
+ ? Object.assign(Object.assign({}, params.cancelAction), { endTime: cancelDate, typeOf: factory.actionType.CancelAction }) : undefined;
508
511
  const doc = yield this.actionModel.findOneAndUpdate({
509
512
  _id: { $eq: params.id },
510
- typeOf: { $eq: params.typeOf }
511
- }, { $set: { actionStatus: factory.actionStatusType.CanceledActionStatus } }, { new: false, projection: { _id: 1 } })
513
+ typeOf: { $eq: params.typeOf },
514
+ actionStatus: { $ne: factory.actionStatusType.CanceledActionStatus } // 冪等性確保(2024-05-26~)
515
+ }, {
516
+ $set: Object.assign({ actionStatus: factory.actionStatusType.CanceledActionStatus }, (cancelAction !== undefined) ? { cancelAction } : undefined // cancelAction連携(2024-05-26~)
517
+ )
518
+ }, { new: false, projection: { _id: 1 } })
512
519
  .exec();
513
520
  if (doc === null) {
514
- throw new factory.errors.NotFound(this.actionModel.modelName);
521
+ // 既にCanceledActionStatusであればok
522
+ const existingAction = yield this.findById({ id: params.id, typeOf: params.typeOf }, ['actionStatus'], []);
523
+ if (existingAction.actionStatus !== factory.actionStatusType.CanceledActionStatus) {
524
+ throw new factory.errors.NotFound(this.actionModel.modelName);
525
+ }
515
526
  }
516
527
  // endDateが存在しなければセット(2024-04-22~)
517
528
  yield this.actionModel.updateOne({
518
529
  _id: { $eq: params.id },
519
530
  endDate: { $exists: false }
520
- }, { $set: { endDate: new Date() } })
531
+ }, { $set: { endDate: cancelDate } })
521
532
  .exec();
522
533
  });
523
534
  }
@@ -27,7 +27,8 @@ const schemaDefinition = {
27
27
  location: mongoose_1.SchemaTypes.Mixed,
28
28
  replacer: mongoose_1.SchemaTypes.Mixed,
29
29
  targetCollection: mongoose_1.SchemaTypes.Mixed,
30
- sameAs: mongoose_1.SchemaTypes.Mixed // タスク関連付けのために追加(2024-04-20~)
30
+ sameAs: mongoose_1.SchemaTypes.Mixed,
31
+ cancelAction: mongoose_1.SchemaTypes.Mixed // add(2024-05-26~)
31
32
  };
32
33
  const schemaOptions = {
33
34
  autoIndex: settings_1.MONGO_AUTO_INDEX,
@@ -22,5 +22,12 @@ interface IVoidTransactionRepos {
22
22
  * 興行オファー承認取消(タスクから実行 or apiから実行))
23
23
  * 取引中の承認アクション全てについて処理する or 特定の承認アクションについて処理する
24
24
  */
25
- export declare function voidTransaction(params: factory.task.IData<factory.taskName.VoidReserveTransaction>): (repos: IVoidTransactionRepos) => Promise<void>;
25
+ export declare function voidTransaction(params: factory.task.IData<factory.taskName.VoidReserveTransaction> & {
26
+ sameAs?: {
27
+ /**
28
+ * 実行元タスクID
29
+ */
30
+ id: string;
31
+ };
32
+ }): (repos: IVoidTransactionRepos) => Promise<void>;
26
33
  export {};
@@ -22,12 +22,13 @@ exports.WebAPIIdentifier = factory.service.webAPI.Identifier;
22
22
  */
23
23
  function voidTransaction(params) {
24
24
  return (repos) => __awaiter(this, void 0, void 0, function* () {
25
- var _a, _b;
25
+ var _a, _b, _c;
26
26
  // support void by action ID(2024-05-26~)
27
27
  if (typeof params.id === 'string') {
28
28
  yield (0, voidTransactionByActionId_1.voidTransactionByActionId)(params)(repos);
29
29
  return;
30
30
  }
31
+ const cancelAction = Object.assign({ startTime: new Date(), agent: { id: params.project.id, typeOf: factory.organizationType.Project } }, (typeof ((_a = params.sameAs) === null || _a === void 0 ? void 0 : _a.id) === 'string') ? { sameAs: { id: params.sameAs.id, typeOf: 'Task' } } : undefined);
31
32
  const transaction = yield repos.transaction.findById({
32
33
  typeOf: params.purpose.typeOf,
33
34
  id: params.purpose.id,
@@ -48,7 +49,7 @@ function voidTransaction(params) {
48
49
  // 確定取引に対応(2023-05-07~)
49
50
  case factory.transactionStatusType.Confirmed:
50
51
  // OrderCancelledを考慮(2023-08-30~)
51
- const orderCancelled = ((_b = (_a = params.purpose.result) === null || _a === void 0 ? void 0 : _a.order) === null || _b === void 0 ? void 0 : _b.orderStatus) === factory.orderStatus.OrderCancelled;
52
+ const orderCancelled = ((_c = (_b = params.purpose.result) === null || _b === void 0 ? void 0 : _b.order) === null || _c === void 0 ? void 0 : _c.orderStatus) === factory.orderStatus.OrderCancelled;
52
53
  if (!orderCancelled) {
53
54
  // 取り消すべきアクションに絞る
54
55
  authorizeActions = authorizeActions.filter((a) => a.actionStatus !== factory.actionStatusType.CompletedActionStatus);
@@ -76,7 +77,7 @@ function voidTransaction(params) {
76
77
  }
77
78
  }
78
79
  yield Promise.all(authorizeActions.map((action) => __awaiter(this, void 0, void 0, function* () {
79
- yield repos.action.cancelWithVoid({ typeOf: action.typeOf, id: action.id });
80
+ yield repos.action.cancelWithVoid({ typeOf: action.typeOf, id: action.id, cancelAction });
80
81
  switch (action.instrument.identifier) {
81
82
  case exports.WebAPIIdentifier.COA:
82
83
  yield (0, processVoidTransaction4coa_1.processVoidTransaction4coa)({
@@ -21,5 +21,12 @@ interface IVoidTransactionByActionIdRepos {
21
21
  * 興行オファー承認取消(apiから実行)
22
22
  * 特定の承認アクションについて処理する
23
23
  */
24
- declare function voidTransactionByActionId(params: factory.task.IData<factory.taskName.VoidReserveTransaction>): (repos: IVoidTransactionByActionIdRepos) => Promise<void>;
24
+ declare function voidTransactionByActionId(params: factory.task.IData<factory.taskName.VoidReserveTransaction> & {
25
+ sameAs?: {
26
+ /**
27
+ * 実行元タスクID
28
+ */
29
+ id: string;
30
+ };
31
+ }): (repos: IVoidTransactionByActionIdRepos) => Promise<void>;
25
32
  export { voidTransactionByActionId };
@@ -35,9 +35,11 @@ function voidTransactionByActionId(params) {
35
35
  // transaction: { id: string };
36
36
  // }) {
37
37
  return (repos) => __awaiter(this, void 0, void 0, function* () {
38
+ var _a;
38
39
  if (typeof params.id !== 'string' || params.id === '') {
39
40
  throw new factory.errors.ArgumentNull('id');
40
41
  }
42
+ const cancelAction = Object.assign({ startTime: new Date(), agent: { id: params.project.id, typeOf: factory.organizationType.Project } }, (typeof ((_a = params.sameAs) === null || _a === void 0 ? void 0 : _a.id) === 'string') ? { sameAs: { id: params.sameAs.id, typeOf: 'Task' } } : undefined);
41
43
  const transaction = yield repos.transaction.findInProgressById({
42
44
  typeOf: factory.transactionType.PlaceOrder,
43
45
  id: params.purpose.id
@@ -51,7 +53,7 @@ function voidTransactionByActionId(params) {
51
53
  }
52
54
  // MongoDBでcompleteステータスであるにも関わらず、Chevreでは削除されている、というのが最悪の状況
53
55
  // それだけは回避するためにMongoDBを先に変更
54
- yield repos.action.cancelWithVoid({ typeOf: factory.actionType.AuthorizeAction, id: params.id });
56
+ yield repos.action.cancelWithVoid({ typeOf: factory.actionType.AuthorizeAction, id: params.id, cancelAction });
55
57
  // add orderInTransaction(2024-01-15~)
56
58
  // USE_CREATE_ORDER_ON_OFFER_ACCEPTEDの場合、orderNumber発行済のはず
57
59
  const orderNumberByTransaction = transaction.object.orderNumber;
@@ -22,10 +22,5 @@ declare function acceptOffer(params: IAccepteOfferParams): (repos: IAcceptRepos)
22
22
  /**
23
23
  * COA興行オファー採用変更
24
24
  */
25
- declare function reAcceptOffer(params: IAccepteOfferParams & {
26
- /**
27
- * 元の承認アクションID
28
- */
29
- id: string;
30
- }): (repos: IAcceptRepos) => Promise<import("@chevre/factory/lib/action").IAction<import("@chevre/factory/lib/action").IAttributes<factory.actionType.AcceptAction, any, any>>>;
25
+ declare function reAcceptOffer(params: IAccepteOfferParams & {}): (repos: IAcceptRepos) => Promise<import("@chevre/factory/lib/action").IAction<import("@chevre/factory/lib/action").IAttributes<factory.actionType.AcceptAction, any, any>>>;
31
26
  export { acceptOffer, reAcceptOffer };
@@ -87,15 +87,17 @@ function acceptOffer(params) {
87
87
  const actionAttributes = {
88
88
  project: transaction.project,
89
89
  typeOf: factory.actionType.AcceptAction,
90
- object: {
91
- object: params.object,
92
- appliesToSurfrock: params.appliesToSurfrock,
93
- flgMember: params.flgMember,
94
- typeOf: factory.actionType.AuthorizeAction
95
- },
90
+ // object: {
91
+ // object: params.object,
92
+ // appliesToSurfrock: params.appliesToSurfrock,
93
+ // flgMember: params.flgMember,
94
+ // typeOf: factory.actionType.AuthorizeAction
95
+ // },
96
+ object: params.object,
96
97
  agent: { id: transaction.agent.id, typeOf: transaction.agent.typeOf },
97
98
  purpose: { id: transaction.id, typeOf: transaction.typeOf },
98
- sameAs: { id: params.sameAs.id, typeOf: 'Task' }
99
+ sameAs: { id: params.sameAs.id, typeOf: 'Task' },
100
+ potentialActions: params.potentialActions
99
101
  };
100
102
  let acceptedOffer;
101
103
  let requestBody;
@@ -107,9 +109,9 @@ function acceptOffer(params) {
107
109
  coaInfo
108
110
  })({ reserveService: repos.reserveService });
109
111
  acceptedOffer = yield (0, authorize_1.validateOffers)(coaInfo, acceptedOffersWithoutDetails, {
110
- identifier: params.appliesToSurfrock.identifier,
111
- serviceOutput: { typeOf: params.appliesToSurfrock.serviceOutput.typeOf }
112
- }, (params.agent.typeOf === factory.personType.Person), params.flgMember)({
112
+ identifier: params.object.appliesToSurfrock.identifier,
113
+ serviceOutput: { typeOf: params.object.appliesToSurfrock.serviceOutput.typeOf }
114
+ }, (params.agent.typeOf === factory.personType.Person), params.object.flgMember)({
113
115
  reserveService: repos.reserveService,
114
116
  masterService: repos.masterService
115
117
  });
@@ -160,16 +162,18 @@ function reAcceptOffer(params) {
160
162
  const actionAttributes = {
161
163
  project: transaction.project,
162
164
  typeOf: factory.actionType.AcceptAction,
163
- object: {
164
- object: params.object,
165
- appliesToSurfrock: params.appliesToSurfrock,
166
- flgMember: params.flgMember,
167
- typeOf: factory.actionType.AuthorizeAction,
168
- id: params.id
169
- },
165
+ // object: {
166
+ // object: params.object,
167
+ // appliesToSurfrock: params.appliesToSurfrock,
168
+ // flgMember: params.flgMember,
169
+ // typeOf: factory.actionType.AuthorizeAction,
170
+ // id: params.id
171
+ // },
172
+ object: params.object,
170
173
  agent: { id: transaction.agent.id, typeOf: transaction.agent.typeOf },
171
174
  purpose: { id: transaction.id, typeOf: transaction.typeOf },
172
- sameAs: { id: params.sameAs.id, typeOf: 'Task' }
175
+ sameAs: { id: params.sameAs.id, typeOf: 'Task' },
176
+ potentialActions: params.potentialActions
173
177
  };
174
178
  let acceptedOffer;
175
179
  // let requestBody: COA.factory.reserve.IUpdTmpReserveSeatArgs;
@@ -181,9 +185,9 @@ function reAcceptOffer(params) {
181
185
  }) });
182
186
  });
183
187
  acceptedOffer = yield (0, authorize_1.validateOffers)(coaInfo, acceptedOffersWithoutDetails, {
184
- identifier: params.appliesToSurfrock.identifier,
185
- serviceOutput: { typeOf: params.appliesToSurfrock.serviceOutput.typeOf }
186
- }, (params.agent.typeOf === factory.personType.Person), params.flgMember)({
188
+ identifier: params.object.appliesToSurfrock.identifier,
189
+ serviceOutput: { typeOf: params.object.appliesToSurfrock.serviceOutput.typeOf }
190
+ }, (params.agent.typeOf === factory.personType.Person), params.object.flgMember)({
187
191
  reserveService: repos.reserveService,
188
192
  masterService: repos.masterService
189
193
  });
@@ -15,6 +15,9 @@ interface ICancelResult {
15
15
  * COA興行オファー承認取消
16
16
  */
17
17
  export declare function cancel(params: {
18
+ project: {
19
+ id: string;
20
+ };
18
21
  /**
19
22
  * 承認アクションID
20
23
  */
@@ -18,6 +18,10 @@ exports.WebAPIIdentifier = factory.service.webAPI.Identifier;
18
18
  */
19
19
  function cancel(params) {
20
20
  return (repos) => __awaiter(this, void 0, void 0, function* () {
21
+ const cancelAction = {
22
+ startTime: new Date(),
23
+ agent: { id: params.project.id, typeOf: factory.organizationType.Project }
24
+ };
21
25
  const transaction = yield repos.transaction.findInProgressById({
22
26
  typeOf: factory.transactionType.PlaceOrder,
23
27
  id: params.transaction.id
@@ -30,7 +34,7 @@ function cancel(params) {
30
34
  if (action.purpose.typeOf !== transaction.typeOf || action.purpose.id !== transaction.id) {
31
35
  throw new factory.errors.Argument('Transaction', 'Action not found in the transaction');
32
36
  }
33
- yield repos.action.cancelWithVoid({ typeOf: factory.actionType.AuthorizeAction, id: params.id });
37
+ yield repos.action.cancelWithVoid({ typeOf: factory.actionType.AuthorizeAction, id: params.id, cancelAction });
34
38
  // add orderInTransaction(2024-01-15~)
35
39
  // USE_CREATE_ORDER_ON_OFFER_ACCEPTEDの場合、orderNumber発行済のはず
36
40
  const orderNumberByTransaction = transaction.object.orderNumber;
@@ -49,8 +49,10 @@ function call(params) {
49
49
  endpoint: credentials_1.credentials.coa.endpoint,
50
50
  auth: coaAuthClient
51
51
  }, { timeout: credentials_1.credentials.coa.timeout });
52
- if (typeof params.data.id === 'string') {
53
- yield (0, acceptOffer_1.reAcceptOffer)(Object.assign(Object.assign({}, params.data), { id: params.data.id, sameAs: { id: params.id } }))({
52
+ if (typeof params.data.potentialActions.id === 'string') {
53
+ yield (0, acceptOffer_1.reAcceptOffer)(Object.assign(Object.assign({}, params.data), {
54
+ // id: params.data.id,
55
+ sameAs: { id: params.id, typeOf: 'Task' } }))({
54
56
  action: actionRepo,
55
57
  event: new event_1.MongoRepository(settings.connection),
56
58
  transaction: new transaction_1.MongoRepository(settings.connection),
@@ -59,7 +61,7 @@ function call(params) {
59
61
  });
60
62
  }
61
63
  else {
62
- yield (0, acceptOffer_1.acceptOffer)(Object.assign(Object.assign({}, params.data), { sameAs: { id: params.id } }))({
64
+ yield (0, acceptOffer_1.acceptOffer)(Object.assign(Object.assign({}, params.data), { sameAs: { id: params.id, typeOf: 'Task' } }))({
63
65
  action: actionRepo,
64
66
  event: new event_1.MongoRepository(settings.connection),
65
67
  transaction: new transaction_1.MongoRepository(settings.connection),
@@ -39,7 +39,7 @@ function call(params) {
39
39
  }
40
40
  const transactionProcessRepo = new transactionProcess_1.TransactionProcessRepository(settings.redisClient, { lockExpiresInSeconds: 120 });
41
41
  try {
42
- yield (0, event_1.voidTransaction)(params.data)({
42
+ yield (0, event_1.voidTransaction)(Object.assign(Object.assign({}, params.data), { sameAs: { id: params.id } }))({
43
43
  action: new action_1.MongoRepository(settings.connection),
44
44
  assetTransaction: new assetTransaction_1.MongoRepository(settings.connection),
45
45
  stockHolder: new stockHolder_1.StockHolderRepository(settings.redisClient, settings.connection),
package/package.json CHANGED
@@ -10,8 +10,8 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "@aws-sdk/credential-providers": "3.433.0",
13
- "@chevre/factory": "4.371.0-alpha.3",
14
- "@cinerino/sdk": "7.0.0-alpha.6",
13
+ "@chevre/factory": "4.371.0-alpha.4",
14
+ "@cinerino/sdk": "7.0.0-alpha.7",
15
15
  "@motionpicture/coa-service": "9.4.0",
16
16
  "@motionpicture/gmo-service": "5.3.0",
17
17
  "@sendgrid/mail": "6.4.0",
@@ -110,5 +110,5 @@
110
110
  "postversion": "git push origin --tags",
111
111
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
112
112
  },
113
- "version": "21.32.0-alpha.16"
113
+ "version": "21.32.0-alpha.18"
114
114
  }