@chevre/domain 21.30.0-alpha.15 → 21.30.0-alpha.17

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.
@@ -0,0 +1,57 @@
1
+ // tslint:disable:no-console
2
+ import * as moment from 'moment';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../lib/index';
6
+
7
+ // const project = { id: String(process.env.PROJECT_ID) };
8
+ type IAction = chevre.factory.action.IAction<chevre.factory.action.IAttributes<chevre.factory.actionType, any, any>>;
9
+
10
+ // tslint:disable-next-line:max-func-body-length
11
+ async function main() {
12
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
13
+
14
+ const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
15
+
16
+ const cursor = actionRepo.getCursor(
17
+ {
18
+ // typeOf: { $eq: chevre.factory.actionType.AuthorizeAction },
19
+ // 'object.typeOf': { $eq: chevre.factory.action.authorize.paymentMethod.any.ResultType.Payment },
20
+ startDate: {
21
+ $gte: moment()
22
+ // tslint:disable-next-line:no-magic-numbers
23
+ .add(-1, 'days')
24
+ .toDate()
25
+ }
26
+ },
27
+ {
28
+ }
29
+ );
30
+ console.log('actions found');
31
+
32
+ let i = 0;
33
+ await cursor.eachAsync(async (doc) => {
34
+ i += 1;
35
+ const action = <IAction>doc.toObject();
36
+ const size = JSON.stringify(action).length;
37
+ // console.log(JSON.stringify(action).length);
38
+ if (action.typeOf !== chevre.factory.actionType.InformAction
39
+ && action.typeOf !== chevre.factory.actionType.AuthorizeAction
40
+ && action.typeOf !== chevre.factory.actionType.CheckAction
41
+ && size > 2000) {
42
+ console.log(action.typeOf, action.object?.typeOf);
43
+ console.log(size);
44
+
45
+ // if (action.typeOf === chevre.factory.actionType.PayAction) {
46
+ // console.log(action);
47
+ // console.log(size);
48
+ // }
49
+ }
50
+ });
51
+
52
+ console.log(i, 'actions checked');
53
+ }
54
+
55
+ main()
56
+ .then()
57
+ .catch(console.error);
@@ -16,8 +16,9 @@ async function main() {
16
16
  for (let index = 0; index < 24 * 1000; index++) {
17
17
  const updateResult = await actionRepo.unsetUnnecessaryFields({
18
18
  filter: {
19
- typeOf: { $eq: chevre.factory.actionType.SendAction },
20
- // 'agent.typeOf': { $exists: true, $eq: chevre.factory.creativeWorkType.WebApplication },
19
+ typeOf: { $eq: chevre.factory.actionType.ReturnAction },
20
+ 'object.typeOf': { $exists: true, $eq: 'Invoice' },
21
+ actionStatus: { $eq: chevre.factory.actionStatusType.CompletedActionStatus },
21
22
  startDate: {
22
23
  // $exists: true,
23
24
  $gte: moment()
@@ -30,12 +31,24 @@ async function main() {
30
31
  // _id: { $eq: '61da235d94a80f000af85f6b' }
31
32
  },
32
33
  $unset: {
33
- 'recipient.identifier': 1,
34
- 'recipient.memberOf': 1,
35
- 'recipient.email': 1,
36
- 'recipient.familyName': 1,
37
- 'recipient.givenName': 1,
38
- 'recipient.telephone': 1
34
+ 'result.refundTransaction.project': 1,
35
+ 'result.refundTransaction.status': 1,
36
+ 'result.refundTransaction.agent': 1,
37
+ 'result.refundTransaction.recipient': 1,
38
+ 'result.refundTransaction.object': 1,
39
+ 'result.refundTransaction.expires': 1,
40
+ 'result.refundTransaction.startDate': 1,
41
+ 'result.refundTransaction.tasksExportAction': 1,
42
+ 'result.refundTransaction.tasksExportationStatus': 1,
43
+ 'result.refundTransaction._id': 1,
44
+ 'result.refundTransaction.createdAt': 1,
45
+ 'result.refundTransaction.updatedAt': 1
46
+ // 'recipient.identifier': 1,
47
+ // 'recipient.memberOf': 1,
48
+ // 'recipient.email': 1,
49
+ // 'recipient.familyName': 1,
50
+ // 'recipient.givenName': 1,
51
+ // 'recipient.telephone': 1
39
52
  // 'object.project': 1,
40
53
  // 'object.seller': 1,
41
54
  // 'object.customer': 1,
@@ -0,0 +1,5 @@
1
+ import { IndexDefinition, IndexOptions, Schema } from 'mongoose';
2
+ declare const modelName = "Message";
3
+ declare const indexes: [d: IndexDefinition, o: IndexOptions][];
4
+ declare function createSchema(): Schema;
5
+ export { modelName, indexes, createSchema };
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSchema = exports.indexes = exports.modelName = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ const writeConcern_1 = require("../writeConcern");
6
+ const settings_1 = require("../../../settings");
7
+ const modelName = 'Message';
8
+ exports.modelName = modelName;
9
+ const schemaDefinition = {
10
+ project: {
11
+ type: mongoose_1.SchemaTypes.Mixed,
12
+ required: true
13
+ },
14
+ typeOf: {
15
+ type: String,
16
+ required: true
17
+ },
18
+ identifier: String,
19
+ name: mongoose_1.SchemaTypes.Mixed,
20
+ about: mongoose_1.SchemaTypes.Mixed,
21
+ sender: mongoose_1.SchemaTypes.Mixed,
22
+ text: String,
23
+ toRecipient: mongoose_1.SchemaTypes.Mixed
24
+ };
25
+ const schemaOptions = {
26
+ autoIndex: settings_1.MONGO_AUTO_INDEX,
27
+ autoCreate: false,
28
+ collection: 'messages',
29
+ id: true,
30
+ read: settings_1.MONGO_READ_PREFERENCE,
31
+ writeConcern: writeConcern_1.writeConcern,
32
+ strict: true,
33
+ strictQuery: false,
34
+ timestamps: {
35
+ createdAt: 'createdAt',
36
+ updatedAt: 'updatedAt'
37
+ },
38
+ toJSON: {
39
+ getters: false,
40
+ virtuals: false,
41
+ minimize: false,
42
+ versionKey: false
43
+ },
44
+ toObject: {
45
+ getters: false,
46
+ virtuals: true,
47
+ minimize: false,
48
+ versionKey: false
49
+ }
50
+ };
51
+ const indexes = [
52
+ [
53
+ { createdAt: 1 },
54
+ { name: 'searchByCreatedAt' }
55
+ ],
56
+ [
57
+ { updatedAt: 1 },
58
+ { name: 'searchByUpdatedAt' }
59
+ ]
60
+ ];
61
+ exports.indexes = indexes;
62
+ /**
63
+ * メッセージスキーマ
64
+ */
65
+ let schema;
66
+ function createSchema() {
67
+ if (schema === undefined) {
68
+ schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
69
+ if (settings_1.MONGO_AUTO_INDEX) {
70
+ indexes.forEach((indexParams) => {
71
+ schema === null || schema === void 0 ? void 0 : schema.index(...indexParams);
72
+ });
73
+ }
74
+ }
75
+ return schema;
76
+ }
77
+ exports.createSchema = createSchema;
@@ -87,12 +87,13 @@ function returnPayTransaction(params) {
87
87
  paymentServiceType,
88
88
  refundFee, seller: order.seller }));
89
89
  const refundPurpose = createRefundPurpose(params, order);
90
- refundTransaction = yield RefundTransactionService.start(startRefundTransactionParams)({
90
+ const { id, typeOf } = yield RefundTransactionService.start(startRefundTransactionParams)({
91
91
  action: repos.action,
92
92
  paymentService: repos.paymentService,
93
93
  product: repos.product,
94
94
  assetTransaction: repos.assetTransaction
95
95
  });
96
+ refundTransaction = { id, transactionNumber, typeOf };
96
97
  yield RefundTransactionService.confirm({
97
98
  transactionNumber,
98
99
  potentialActions: { refund: { purpose: refundPurpose } }
@@ -110,7 +111,8 @@ function returnPayTransaction(params) {
110
111
  }
111
112
  throw error;
112
113
  }
113
- const result = { refundTransaction };
114
+ // const result: factory.action.transfer.returnAction.paymentMethod.IResult = { refundTransaction };
115
+ const result = Object.assign({}, (typeof (refundTransaction === null || refundTransaction === void 0 ? void 0 : refundTransaction.id) === 'string') ? { refundTransaction } : undefined); // optimize(2024-04-27~)
114
116
  yield repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: result });
115
117
  // 潜在アクション
116
118
  yield onRefund(refundActionAttributes)({ task: repos.task });
@@ -33,6 +33,7 @@ type IConfirmParams = PlaceOrderFactory.IConfirmParams & {
33
33
  * 取引検証時にorderInTransactionからオファーを検索するかどうか
34
34
  */
35
35
  useAcceptedOffersFromOrderInTransaction: boolean;
36
+ useSaveMessages: boolean;
36
37
  };
37
38
  };
38
39
  /**
@@ -97,9 +97,13 @@ function confirm(params) {
97
97
  emailMessageOnOrderSent = searchEmailMessagesResult.shift();
98
98
  }
99
99
  // ポストアクションを作成
100
- const potentialActions = yield (0, potentialActions_1.createPotentialActions)(Object.assign(Object.assign({ order: result.order,
100
+ const { emailMessages, potentialActions } = yield (0, potentialActions_1.createPotentialActions)(Object.assign(Object.assign({ order: result.order,
101
101
  // order: orderWithAcceptedOffers, // 現時点でcreateEmailMessageでorder.acceptedOffersを使用している(2024-02-06~)
102
102
  transaction: transaction }, (params.potentialActions !== undefined) ? { potentialActions: params.potentialActions } : undefined), (emailMessageOnOrderSent !== undefined) ? { emailMessage: emailMessageOnOrderSent } : undefined));
103
+ // メッセージ保管(2024-04-28~)
104
+ if (params.options.useSaveMessages) {
105
+ debug('saving', emailMessages.length, 'emailMessages...', emailMessages);
106
+ }
103
107
  // ステータス変更
104
108
  try {
105
109
  yield repos.transaction.confirm({
@@ -3,4 +3,7 @@ export declare function createSendEmailMessageActions(params: {
3
3
  order: factory.order.IOrder;
4
4
  potentialActions?: factory.transaction.placeOrder.IPotentialActionsParams;
5
5
  emailMessage?: factory.creativeWork.message.email.ICreativeWork;
6
- }): Promise<factory.action.transfer.send.message.email.IAttributes[]>;
6
+ }): Promise<{
7
+ emailMessages: factory.creativeWork.message.email.ICreativeWork[];
8
+ sendEmailMessageActions: factory.action.transfer.send.message.email.IAttributes[];
9
+ }>;
@@ -17,6 +17,7 @@ function createSendEmailMessageActions(params) {
17
17
  var _a, _b, _c, _d, _e;
18
18
  return __awaiter(this, void 0, void 0, function* () {
19
19
  // 注文配送メール送信設定
20
+ const emailMessages = [];
20
21
  const sendEmailMessageActions = [];
21
22
  // const maskedCustomer = createMaskedCustomer(params.order, { noProfile: true });
22
23
  const sendActionPurpose = {
@@ -37,6 +38,7 @@ function createSendEmailMessageActions(params) {
37
38
  if (Array.isArray(sendEmailMessageOnOrderSentParams)) {
38
39
  yield Promise.all(sendEmailMessageOnOrderSentParams.map((s) => __awaiter(this, void 0, void 0, function* () {
39
40
  const emailMessage = yield emailMessageBuilder.createSendOrderMessage(Object.assign(Object.assign({ order: params.order }, (s.object !== undefined) ? { email: s.object } : undefined), (params.emailMessage !== undefined) ? { emailMessage: params.emailMessage } : undefined));
41
+ emailMessages.push(emailMessage);
40
42
  sendEmailMessageActions.push({
41
43
  project: params.order.project,
42
44
  typeOf: factory.actionType.SendAction,
@@ -52,7 +54,7 @@ function createSendEmailMessageActions(params) {
52
54
  });
53
55
  })));
54
56
  }
55
- return sendEmailMessageActions;
57
+ return { sendEmailMessageActions, emailMessages };
56
58
  });
57
59
  }
58
60
  exports.createSendEmailMessageActions = createSendEmailMessageActions;
@@ -7,4 +7,7 @@ export declare function createPotentialActions(params: {
7
7
  potentialActions?: factory.transaction.placeOrder.IPotentialActionsParams;
8
8
  transaction: factory.transaction.placeOrder.ITransaction;
9
9
  emailMessage?: factory.creativeWork.message.email.ICreativeWork;
10
- }): Promise<factory.transaction.placeOrder.IPotentialActions>;
10
+ }): Promise<{
11
+ potentialActions: factory.transaction.placeOrder.IPotentialActions;
12
+ emailMessages: factory.creativeWork.message.email.ICreativeWork[];
13
+ }>;
@@ -19,7 +19,7 @@ function createPotentialActions(params) {
19
19
  // ポイントインセンティブに対する承認アクションの分だけ、ポイントインセンティブ付与アクションを作成する
20
20
  // const givePointAwardActions = await createGivePointAwardActions(params); // 完全廃止(2024-03-12~)
21
21
  // 注文配送メール送信設定
22
- const sendEmailMessageActions = yield (0, sendEmailMessage_1.createSendEmailMessageActions)(params);
22
+ const { emailMessages, sendEmailMessageActions } = yield (0, sendEmailMessage_1.createSendEmailMessageActions)(params);
23
23
  const sendOrderActionAttributes = {
24
24
  potentialActions: {
25
25
  // moneyTransfer: moneyTransferActions, // 廃止(2024-01-29~)
@@ -27,12 +27,15 @@ function createPotentialActions(params) {
27
27
  sendEmailMessage: sendEmailMessageActions
28
28
  }
29
29
  };
30
- // optimize(2024-01-22~)
31
30
  return {
32
- order: {
33
- potentialActions: {
34
- // givePointAward: givePointAwardActions, // 完全廃止(2024-03-12~)
35
- sendOrder: sendOrderActionAttributes // optimize(2024-01-16~)
31
+ emailMessages,
32
+ // optimize(2024-01-22~)
33
+ potentialActions: {
34
+ order: {
35
+ potentialActions: {
36
+ // givePointAward: givePointAwardActions, // 完全廃止(2024-03-12~)
37
+ sendOrder: sendOrderActionAttributes // optimize(2024-01-16~)
38
+ }
36
39
  }
37
40
  }
38
41
  };
package/package.json CHANGED
@@ -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.30.0-alpha.15"
113
+ "version": "21.30.0-alpha.17"
114
114
  }