@chevre/domain 21.30.0-alpha.18 → 21.30.0-alpha.19

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,6 +4,7 @@ import * as mongoose from 'mongoose';
4
4
 
5
5
  import { chevre } from '../../../lib/index';
6
6
 
7
+ const CONSOLE_CLIENT_ID = 'xxx';
7
8
  // const project = { id: String(process.env.PROJECT_ID) };
8
9
  type IAction = chevre.factory.action.IAction<chevre.factory.action.IAttributes<chevre.factory.actionType, any, any>>;
9
10
 
@@ -15,12 +16,12 @@ async function main() {
15
16
 
16
17
  const cursor = actionRepo.getCursor(
17
18
  {
18
- // typeOf: { $eq: chevre.factory.actionType.AuthorizeAction },
19
- // 'object.typeOf': { $eq: chevre.factory.action.authorize.paymentMethod.any.ResultType.Payment },
19
+ typeOf: { $eq: chevre.factory.actionType.CreateAction },
20
+ 'object.typeOf': { $exists: true, $eq: chevre.factory.eventType.ScreeningEvent },
20
21
  startDate: {
21
22
  $gte: moment()
22
23
  // tslint:disable-next-line:no-magic-numbers
23
- .add(-1, 'days')
24
+ .add(-60, 'days')
24
25
  .toDate()
25
26
  }
26
27
  },
@@ -33,19 +34,26 @@ async function main() {
33
34
  await cursor.eachAsync(async (doc) => {
34
35
  i += 1;
35
36
  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
- // }
37
+ // const size = JSON.stringify(action).length;
38
+ // // console.log(JSON.stringify(action).length);
39
+ // if (action.typeOf !== chevre.factory.actionType.InformAction
40
+ // && action.typeOf !== chevre.factory.actionType.AuthorizeAction
41
+ // && action.typeOf !== chevre.factory.actionType.CheckAction
42
+ // && size > 2000) {
43
+ // console.log(action.typeOf, action.object?.typeOf);
44
+ // console.log(size);
45
+ // }
46
+
47
+ const eventCount = (Array.isArray(action.result))
48
+ ? action.result.filter(({ typeOf }) => typeOf === chevre.factory.eventType.ScreeningEvent)
49
+ .length
50
+ : 0;
51
+ if (action.instrument?.id !== CONSOLE_CLIENT_ID) {
52
+ console.log(eventCount, 'events created', action.project.id, action.startDate, action.instrument?.id, i);
53
+ // tslint:disable-next-line:no-magic-numbers
54
+ if (eventCount > 10) {
55
+ throw new Error('eventCount too large');
56
+ }
49
57
  }
50
58
  });
51
59
 
@@ -0,0 +1,65 @@
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 CONSOLE_CLIENT_ID = 'xxx';
8
+ // const project = { id: String(process.env.PROJECT_ID) };
9
+ type IAction = chevre.factory.action.IAction<chevre.factory.action.IAttributes<chevre.factory.actionType, any, any>>;
10
+
11
+ // tslint:disable-next-line:max-func-body-length
12
+ async function main() {
13
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
14
+
15
+ const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
16
+
17
+ const cursor = actionRepo.getCursor(
18
+ {
19
+ typeOf: { $eq: chevre.factory.actionType.ReplaceAction },
20
+ 'object.typeOf': { $exists: true, $eq: chevre.factory.eventType.ScreeningEventSeries },
21
+ startDate: {
22
+ $gte: moment()
23
+ // tslint:disable-next-line:no-magic-numbers
24
+ .add(-60, 'days')
25
+ .toDate()
26
+ }
27
+ },
28
+ {
29
+ }
30
+ );
31
+ console.log('actions found');
32
+
33
+ let i = 0;
34
+ await cursor.eachAsync(async (doc) => {
35
+ i += 1;
36
+ const action = <IAction>doc.toObject();
37
+ // const size = JSON.stringify(action).length;
38
+ // // console.log(JSON.stringify(action).length);
39
+ // if (action.typeOf !== chevre.factory.actionType.InformAction
40
+ // && action.typeOf !== chevre.factory.actionType.AuthorizeAction
41
+ // && action.typeOf !== chevre.factory.actionType.CheckAction
42
+ // && size > 2000) {
43
+ // console.log(action.typeOf, action.object?.typeOf);
44
+ // console.log(size);
45
+ // }
46
+
47
+ const eventCount = (Array.isArray(action.object))
48
+ ? action.object.filter(({ typeOf }) => typeOf === chevre.factory.eventType.ScreeningEventSeries)
49
+ .length
50
+ : 0;
51
+ if (action.instrument?.id !== CONSOLE_CLIENT_ID) {
52
+ console.log(eventCount, 'events created', action.project.id, action.startDate, action.instrument?.id, i);
53
+ // tslint:disable-next-line:no-magic-numbers
54
+ if (eventCount > 20) {
55
+ throw new Error('eventCount too large');
56
+ }
57
+ }
58
+ });
59
+
60
+ console.log(i, 'actions checked');
61
+ }
62
+
63
+ main()
64
+ .then()
65
+ .catch(console.error);
@@ -6,7 +6,9 @@ export declare function createSendOrderMessage(params: {
6
6
  order: factory.order.IOrder;
7
7
  email?: factory.creativeWork.message.email.ICustomization;
8
8
  emailMessage?: factory.creativeWork.message.email.ICreativeWork;
9
- }): Promise<factory.creativeWork.message.email.ICreativeWork>;
9
+ }): Promise<factory.action.transfer.send.message.email.IObjectAsEmailMessage & {
10
+ identifier: string;
11
+ }>;
10
12
  /**
11
13
  * 注文返品メッセージを作成する
12
14
  */
@@ -9,6 +9,7 @@ type IEmailMessage = factory.creativeWork.message.email.ICreativeWork & {
9
9
  typeOf: factory.organizationType.Project;
10
10
  };
11
11
  };
12
+ type IFindByIdentifierResult = Pick<IEmailMessage, 'about' | 'identifier' | 'name' | 'sender' | 'text' | 'toRecipient' | 'typeOf'>;
12
13
  /**
13
14
  * メッセージリポジトリ
14
15
  */
@@ -19,5 +20,14 @@ export declare class MessageRepo {
19
20
  * コードをキーにしてなければ作成する(複数対応)
20
21
  */
21
22
  upsertByIdentifier(params: Pick<IEmailMessage, 'about' | 'identifier' | 'mainEntity' | 'name' | 'project' | 'sender' | 'text' | 'toRecipient'>[]): Promise<BulkWriteResult | void>;
23
+ /**
24
+ * コードで参照
25
+ */
26
+ findByIdentifier(params: {
27
+ identifier: string;
28
+ project: {
29
+ id: string;
30
+ };
31
+ }): Promise<IFindByIdentifierResult>;
22
32
  }
23
33
  export {};
@@ -70,5 +70,29 @@ class MessageRepo {
70
70
  }
71
71
  });
72
72
  }
73
+ /**
74
+ * コードで参照
75
+ */
76
+ findByIdentifier(params) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ const doc = yield this.messageModel.findOne({
79
+ 'project.id': { $eq: params.project.id },
80
+ identifier: { $eq: params.identifier }
81
+ }, {
82
+ typeOf: 1,
83
+ identifier: 1,
84
+ name: 1,
85
+ about: 1,
86
+ sender: 1,
87
+ text: 1,
88
+ toRecipient: 1
89
+ })
90
+ .exec();
91
+ if (doc === null) {
92
+ throw new factory.errors.NotFound(factory.creativeWorkType.EmailMessage);
93
+ }
94
+ return doc.toObject();
95
+ });
96
+ }
73
97
  }
74
98
  exports.MessageRepo = MessageRepo;
@@ -1,5 +1,6 @@
1
1
  import * as factory from '../factory';
2
2
  import type { MongoRepository as ActionRepo } from '../repo/action';
3
+ import type { MessageRepo } from '../repo/message';
3
4
  import type { MongoRepository as ProjectRepo } from '../repo/project';
4
5
  export type IReport2developersOperation<T> = (repos: {
5
6
  accessToken: string;
@@ -11,6 +12,7 @@ export type IReport2developersOperation<T> = (repos: {
11
12
  */
12
13
  export declare function sendEmailMessage(params: factory.action.transfer.send.message.email.IAttributes): (repos: {
13
14
  action: ActionRepo;
15
+ message: MessageRepo;
14
16
  project: ProjectRepo;
15
17
  }) => Promise<void>;
16
18
  /**
@@ -43,7 +43,17 @@ function sendEmailMessage(params) {
43
43
  throw new factory.errors.ServiceUnavailable('API Key not found');
44
44
  }
45
45
  sgMail.setApiKey(apiKey);
46
- const emailMessage = params.object;
46
+ let emailMessage;
47
+ if (typeof params.object.text === 'string') {
48
+ emailMessage = params.object;
49
+ }
50
+ else {
51
+ // メッセージリポジトリに対応(2024-04-29~)
52
+ emailMessage = yield repos.message.findByIdentifier({
53
+ identifier: params.object.identifier,
54
+ project: { id: action.project.id }
55
+ });
56
+ }
47
57
  const emailMessageFrom = {
48
58
  name: emailMessage.sender.name,
49
59
  email: emailMessage.sender.email
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.call = void 0;
13
13
  const action_1 = require("../../repo/action");
14
+ const message_1 = require("../../repo/message");
14
15
  const project_1 = require("../../repo/project");
15
16
  const NotificationService = require("../notification");
16
17
  /**
@@ -20,6 +21,7 @@ function call(data) {
20
21
  return (settings) => __awaiter(this, void 0, void 0, function* () {
21
22
  yield NotificationService.sendEmailMessage(data.actionAttributes)({
22
23
  action: new action_1.MongoRepository(settings.connection),
24
+ message: new message_1.MessageRepo(settings.connection),
23
25
  project: new project_1.MongoRepository(settings.connection)
24
26
  });
25
27
  });
@@ -36,6 +36,7 @@ type IConfirmParams = PlaceOrderFactory.IConfirmParams & {
36
36
  */
37
37
  useAcceptedOffersFromOrderInTransaction: boolean;
38
38
  useSaveMessages: boolean;
39
+ useOptimizedSendEmailAction: boolean;
39
40
  };
40
41
  };
41
42
  /**
@@ -99,7 +99,7 @@ function confirm(params) {
99
99
  // ポストアクションを作成
100
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
- transaction: transaction }, (params.potentialActions !== undefined) ? { potentialActions: params.potentialActions } : undefined), (emailMessageOnOrderSent !== undefined) ? { emailMessage: emailMessageOnOrderSent } : undefined));
102
+ transaction: transaction, useOptimizedSendEmailAction: params.options.useOptimizedSendEmailAction }, (params.potentialActions !== undefined) ? { potentialActions: params.potentialActions } : undefined), (emailMessageOnOrderSent !== undefined) ? { emailMessage: emailMessageOnOrderSent } : undefined));
103
103
  // メッセージ保管(2024-04-28~)
104
104
  yield saveMessagesIfNeeded({ options: params.options }, result.order, emailMessages)(repos);
105
105
  // ステータス変更
@@ -3,7 +3,8 @@ 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
+ useOptimizedSendEmailAction: boolean;
6
7
  }): Promise<{
7
- emailMessages: factory.creativeWork.message.email.ICreativeWork[];
8
+ emailMessages: factory.action.transfer.send.message.email.IObjectAsEmailMessage[];
8
9
  sendEmailMessageActions: factory.action.transfer.send.message.email.IAttributes[];
9
10
  }>;
@@ -39,10 +39,18 @@ function createSendEmailMessageActions(params) {
39
39
  yield Promise.all(sendEmailMessageOnOrderSentParams.map((s) => __awaiter(this, void 0, void 0, function* () {
40
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
41
  emailMessages.push(emailMessage);
42
+ let sendEmailMessageActionObject = emailMessage;
43
+ // 送信アクション最適化に対応(2024-04-29~)
44
+ if (params.useOptimizedSendEmailAction) {
45
+ sendEmailMessageActionObject = {
46
+ identifier: emailMessage.identifier,
47
+ typeOf: factory.creativeWorkType.EmailMessage
48
+ };
49
+ }
42
50
  sendEmailMessageActions.push({
43
51
  project: params.order.project,
44
52
  typeOf: factory.actionType.SendAction,
45
- object: emailMessage,
53
+ object: sendEmailMessageActionObject,
46
54
  agent: params.order.project,
47
55
  recipient: {
48
56
  typeOf: params.order.customer.typeOf,
@@ -7,6 +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
+ useOptimizedSendEmailAction: boolean;
10
11
  }): Promise<{
11
12
  potentialActions: factory.transaction.placeOrder.IPotentialActions;
12
13
  emailMessages: factory.creativeWork.message.email.ICreativeWork[];
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "@aws-sdk/credential-providers": "3.433.0",
13
- "@chevre/factory": "4.368.0-alpha.3",
13
+ "@chevre/factory": "4.369.0-alpha.1",
14
14
  "@cinerino/sdk": "5.17.1",
15
15
  "@motionpicture/coa-service": "9.4.0",
16
16
  "@motionpicture/gmo-service": "5.3.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.30.0-alpha.18"
113
+ "version": "21.30.0-alpha.19"
114
114
  }