@chevre/domain 25.2.0-alpha.26 → 25.2.0-alpha.28

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.
Files changed (23) hide show
  1. package/lib/chevre/factory/customerTelephone2COATelNum.d.ts +3 -0
  2. package/lib/chevre/factory/customerTelephone2COATelNum.js +23 -0
  3. package/lib/chevre/repo/message.d.ts +1 -1
  4. package/lib/chevre/repo/message.js +1 -1
  5. package/lib/chevre/repo/person.d.ts +0 -15
  6. package/lib/chevre/repo/person.js +122 -108
  7. package/lib/chevre/service/order/onAssetTransactionStatusChanged/onPayTransactionConfirmed.d.ts +2 -0
  8. package/lib/chevre/service/order/onAssetTransactionStatusChanged/paymentDue2Processing.d.ts +2 -0
  9. package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +2 -0
  10. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.d.ts +5 -1
  11. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +95 -33
  12. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.d.ts +2 -0
  13. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.js +2 -6
  14. package/lib/chevre/service/order/payOrder.d.ts +2 -0
  15. package/lib/chevre/service/order/placeOrder.d.ts +2 -0
  16. package/lib/chevre/service/reserve/searchByOrder.js +2 -6
  17. package/lib/chevre/service/task/confirmReserveTransaction.js +2 -7
  18. package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +2 -2
  19. package/lib/chevre/service/task/onOrderPaymentCompleted.js +2 -0
  20. package/lib/chevre/service/task/placeOrder.js +2 -2
  21. package/lib/chevre/service/transaction/placeOrder/updateAgent.d.ts +2 -0
  22. package/lib/chevre/service/transaction/placeOrder/updateAgent.js +19 -9
  23. package/package.json +5 -4
@@ -0,0 +1,3 @@
1
+ export declare function customerTelephone2COATelNum(params: {
2
+ telephone: string;
3
+ }): string;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.customerTelephone2COATelNum = customerTelephone2COATelNum;
4
+ // import { PhoneNumberFormat, PhoneNumberUtil } from 'google-libphonenumber';
5
+ const libphonenumber_js_1 = require("libphonenumber-js");
6
+ const factory_1 = require("../factory");
7
+ function customerTelephone2COATelNum(params) {
8
+ const { telephone } = params;
9
+ // 電話番号のフォーマットを日本人にリーダブルに調整(COAではこのフォーマットで扱うので)
10
+ // const phoneUtil = PhoneNumberUtil.getInstance();
11
+ // const phoneNumber = phoneUtil.parse(telephone, 'JP');
12
+ // let telNum = phoneUtil.format(phoneNumber, PhoneNumberFormat.NATIONAL);
13
+ const phoneNumber = (0, libphonenumber_js_1.parsePhoneNumberFromString)(telephone, 'JP');
14
+ // isValid検証はgoogle-libphonenumber時代にしていなかったため、ひとまずなし
15
+ // if (phoneNumber === undefined || !phoneNumber.isValid()) {
16
+ if (phoneNumber === undefined) {
17
+ throw new factory_1.factory.errors.Internal(`phoneNumber undefined. telephone: ${telephone}`);
18
+ }
19
+ let telNum = phoneNumber.format('NATIONAL');
20
+ // COAでは数字のみ受け付けるので数字以外を除去
21
+ telNum = telNum.replace(/[^\d]/g, '');
22
+ return telNum;
23
+ }
@@ -43,7 +43,7 @@ export declare class MessageRepo {
43
43
  /**
44
44
  * 検索
45
45
  */
46
- projectFields(params: ISearchConditions, inclusion: IKeyOfProjection[]): Promise<(IEmailMessage & {
46
+ findMessages(params: ISearchConditions, inclusion: IKeyOfProjection[]): Promise<(IEmailMessage & {
47
47
  id: string;
48
48
  })[]>;
49
49
  /**
@@ -53,7 +53,7 @@ class MessageRepo {
53
53
  /**
54
54
  * 検索
55
55
  */
56
- async projectFields(params, inclusion) {
56
+ async findMessages(params, inclusion) {
57
57
  const conditions = MessageRepo.CREATE_MONGO_CONDITIONS(params);
58
58
  let positiveProjectionFields;
59
59
  if (Array.isArray(inclusion) && inclusion.length > 0) {
@@ -21,20 +21,12 @@ export declare class PersonRepo {
21
21
  userPoolId?: string;
22
22
  attributes?: AttributeType[];
23
23
  }): factory.person.IPerson;
24
- static PROFILE2ATTRIBUTE(params: factory.person.IProfile): AttributeType[];
25
24
  /**
26
25
  * 管理者権限でユーザー属性を取得する
27
26
  */
28
27
  getUserAttributes(params: {
29
28
  username: string;
30
29
  }): Promise<factory.person.IProfile>;
31
- /**
32
- * 管理者権限でプロフィール更新
33
- */
34
- updateProfile(params: {
35
- username: string;
36
- profile: factory.person.IProfile;
37
- }): Promise<void>;
38
30
  /**
39
31
  * 管理者権限でsubでユーザーを検索する
40
32
  */
@@ -45,13 +37,6 @@ export declare class PersonRepo {
45
37
  * アクセストークンでユーザー属性を取得する
46
38
  */
47
39
  getUserAttributesByAccessToken(accessToken: string): Promise<factory.person.IProfile>;
48
- /**
49
- * 会員プロフィール更新
50
- */
51
- updateProfileByAccessToken(params: {
52
- accessToken: string;
53
- profile: factory.person.IProfile;
54
- }): Promise<void>;
55
40
  /**
56
41
  * 削除
57
42
  */
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PersonRepo = void 0;
4
- // import { fromEnv } from '@aws-sdk/credential-providers';
5
- const google_libphonenumber_1 = require("google-libphonenumber");
6
4
  const factory_1 = require("../factory");
7
5
  /**
8
6
  * 会員リポジトリ
@@ -92,73 +90,81 @@ class PersonRepo {
92
90
  }
93
91
  return person;
94
92
  }
95
- static PROFILE2ATTRIBUTE(params) {
96
- let formatedPhoneNumber;
97
- if (typeof params.telephone === 'string' && params.telephone.length > 0) {
98
- try {
99
- const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
100
- const phoneNumber = phoneUtil.parse(params.telephone);
101
- /* istanbul ignore if */
102
- if (!phoneUtil.isValidNumber(phoneNumber)) {
103
- throw new factory_1.factory.errors.Argument('telephone', 'Invalid phone number');
104
- }
105
- formatedPhoneNumber = phoneUtil.format(phoneNumber, google_libphonenumber_1.PhoneNumberFormat.E164);
106
- }
107
- catch (_error) {
108
- throw new factory_1.factory.errors.Argument('telephone', 'Invalid phone number');
109
- }
110
- }
111
- const userAttributes = [];
112
- if (typeof params.givenName === 'string') {
113
- userAttributes.push({
114
- Name: 'given_name',
115
- Value: params.givenName
116
- });
117
- }
118
- if (typeof params.familyName === 'string') {
119
- userAttributes.push({
120
- Name: 'family_name',
121
- Value: params.familyName
122
- });
123
- }
124
- if (typeof params.email === 'string') {
125
- userAttributes.push({
126
- Name: 'email',
127
- Value: params.email
128
- });
129
- }
130
- if (typeof formatedPhoneNumber === 'string') {
131
- userAttributes.push({
132
- Name: 'phone_number',
133
- Value: formatedPhoneNumber
134
- });
135
- }
136
- if (Array.isArray(params.additionalProperty)) {
137
- userAttributes.push(...params.additionalProperty.map((a) => {
138
- let userAttributesValue = a.value;
139
- // custom:telephoneに関してもtelephoneと同様のバリデーションを追加
140
- if (a.name === 'custom:telephone') {
141
- try {
142
- const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
143
- const phoneNumber = phoneUtil.parse(String(a.value));
144
- /* istanbul ignore if */
145
- if (!phoneUtil.isValidNumber(phoneNumber)) {
146
- throw new factory_1.factory.errors.Argument('custom:telephone', 'Invalid phone number');
147
- }
148
- userAttributesValue = phoneUtil.format(phoneNumber, google_libphonenumber_1.PhoneNumberFormat.E164);
149
- }
150
- catch (_error) {
151
- throw new factory_1.factory.errors.Argument('custome:telephone', 'Invalid phone number');
152
- }
153
- }
154
- return {
155
- Name: a.name,
156
- Value: userAttributesValue
157
- };
158
- }));
159
- }
160
- return userAttributes;
161
- }
93
+ // public static PROFILE2ATTRIBUTE(params: factory.person.IProfile): AttributeType[] {
94
+ // let formatedPhoneNumber: string | undefined;
95
+ // if (typeof params.telephone === 'string' && params.telephone.length > 0) {
96
+ // try {
97
+ // // const phoneUtil = PhoneNumberUtil.getInstance();
98
+ // // const phoneNumber = phoneUtil.parse(params.telephone);
99
+ // // /* istanbul ignore if */
100
+ // // if (!phoneUtil.isValidNumber(phoneNumber)) {
101
+ // // throw new factory.errors.Argument('telephone', 'Invalid phone number');
102
+ // // }
103
+ // // formatedPhoneNumber = phoneUtil.format(phoneNumber, PhoneNumberFormat.E164);
104
+ // const phoneNumber = parsePhoneNumberFromString(params.telephone);
105
+ // if (phoneNumber === undefined || !phoneNumber.isValid()) {
106
+ // throw new factory.errors.Argument('telephone', 'Invalid phone number');
107
+ // }
108
+ // formatedPhoneNumber = phoneNumber.format('E.164');
109
+ // } catch (_error) {
110
+ // throw new factory.errors.Argument('telephone', 'Invalid phone number');
111
+ // }
112
+ // }
113
+ // const userAttributes: AttributeType[] = [];
114
+ // if (typeof params.givenName === 'string') {
115
+ // userAttributes.push({
116
+ // Name: 'given_name',
117
+ // Value: params.givenName
118
+ // });
119
+ // }
120
+ // if (typeof params.familyName === 'string') {
121
+ // userAttributes.push({
122
+ // Name: 'family_name',
123
+ // Value: params.familyName
124
+ // });
125
+ // }
126
+ // if (typeof params.email === 'string') {
127
+ // userAttributes.push({
128
+ // Name: 'email',
129
+ // Value: params.email
130
+ // });
131
+ // }
132
+ // if (typeof formatedPhoneNumber === 'string') {
133
+ // userAttributes.push({
134
+ // Name: 'phone_number',
135
+ // Value: formatedPhoneNumber
136
+ // });
137
+ // }
138
+ // if (Array.isArray(params.additionalProperty)) {
139
+ // userAttributes.push(...params.additionalProperty.map((a) => {
140
+ // let userAttributesValue: string = a.value;
141
+ // // custom:telephoneに関してもtelephoneと同様のバリデーションを追加
142
+ // if (a.name === 'custom:telephone') {
143
+ // try {
144
+ // // const phoneUtil = PhoneNumberUtil.getInstance();
145
+ // // const phoneNumber = phoneUtil.parse(String(a.value));
146
+ // // /* istanbul ignore if */
147
+ // // if (!phoneUtil.isValidNumber(phoneNumber)) {
148
+ // // throw new factory.errors.Argument('custom:telephone', 'Invalid phone number');
149
+ // // }
150
+ // // userAttributesValue = phoneUtil.format(phoneNumber, PhoneNumberFormat.E164);
151
+ // const phoneNumber = parsePhoneNumberFromString(String(a.value));
152
+ // if (phoneNumber === undefined || !phoneNumber.isValid()) {
153
+ // throw new factory.errors.Argument('telephone', 'Invalid phone number');
154
+ // }
155
+ // userAttributesValue = phoneNumber.format('E.164');
156
+ // } catch (_error) {
157
+ // throw new factory.errors.Argument('custome:telephone', 'Invalid phone number');
158
+ // }
159
+ // }
160
+ // return {
161
+ // Name: a.name,
162
+ // Value: userAttributesValue
163
+ // };
164
+ // }));
165
+ // }
166
+ // return userAttributes;
167
+ // }
162
168
  /**
163
169
  * 管理者権限でユーザー属性を取得する
164
170
  */
@@ -177,26 +183,30 @@ class PersonRepo {
177
183
  });
178
184
  });
179
185
  }
180
- /**
181
- * 管理者権限でプロフィール更新
182
- */
183
- async updateProfile(params) {
184
- return new Promise((resolve, reject) => {
185
- const userAttributes = PersonRepo.PROFILE2ATTRIBUTE(params.profile);
186
- this.cognitoIdentityServiceProvider.adminUpdateUserAttributes({
187
- UserPoolId: this.userPoolId,
188
- Username: params.username,
189
- UserAttributes: userAttributes
190
- }, (err) => {
191
- if (err instanceof Error) {
192
- reject(new factory_1.factory.errors.Argument('profile', err.message));
193
- }
194
- else {
195
- resolve();
196
- }
197
- });
198
- });
199
- }
186
+ // /**
187
+ // * 管理者権限でプロフィール更新
188
+ // */
189
+ // public async updateProfile(params: {
190
+ // username: string;
191
+ // profile: factory.person.IProfile;
192
+ // }): Promise<void> {
193
+ // return new Promise<void>((resolve, reject) => {
194
+ // const userAttributes = PersonRepo.PROFILE2ATTRIBUTE(params.profile);
195
+ // this.cognitoIdentityServiceProvider.adminUpdateUserAttributes(
196
+ // {
197
+ // UserPoolId: this.userPoolId,
198
+ // Username: params.username,
199
+ // UserAttributes: userAttributes
200
+ // },
201
+ // (err) => {
202
+ // if (err instanceof Error) {
203
+ // reject(new factory.errors.Argument('profile', err.message));
204
+ // } else {
205
+ // resolve();
206
+ // }
207
+ // });
208
+ // });
209
+ // }
200
210
  /**
201
211
  * 管理者権限でsubでユーザーを検索する
202
212
  */
@@ -249,25 +259,29 @@ class PersonRepo {
249
259
  });
250
260
  });
251
261
  }
252
- /**
253
- * 会員プロフィール更新
254
- */
255
- async updateProfileByAccessToken(params) {
256
- return new Promise((resolve, reject) => {
257
- const userAttributes = PersonRepo.PROFILE2ATTRIBUTE(params.profile);
258
- this.cognitoIdentityServiceProvider.updateUserAttributes({
259
- AccessToken: params.accessToken,
260
- UserAttributes: userAttributes
261
- }, (err) => {
262
- if (err instanceof Error) {
263
- reject(new factory_1.factory.errors.Argument('profile', err.message));
264
- }
265
- else {
266
- resolve();
267
- }
268
- });
269
- });
270
- }
262
+ // /**
263
+ // * 会員プロフィール更新
264
+ // */
265
+ // public async updateProfileByAccessToken(params: {
266
+ // accessToken: string;
267
+ // profile: factory.person.IProfile;
268
+ // }): Promise<void> {
269
+ // return new Promise<void>((resolve, reject) => {
270
+ // const userAttributes = PersonRepo.PROFILE2ATTRIBUTE(params.profile);
271
+ // this.cognitoIdentityServiceProvider.updateUserAttributes(
272
+ // {
273
+ // AccessToken: params.accessToken,
274
+ // UserAttributes: userAttributes
275
+ // },
276
+ // (err) => {
277
+ // if (err instanceof Error) {
278
+ // reject(new factory.errors.Argument('profile', err.message));
279
+ // } else {
280
+ // resolve();
281
+ // }
282
+ // });
283
+ // });
284
+ // }
271
285
  /**
272
286
  * 削除
273
287
  */
@@ -1,5 +1,6 @@
1
1
  import type { AcceptedOfferRepo } from '../../../repo/acceptedOffer';
2
2
  import type { AssetTransactionRepo } from '../../../repo/assetTransaction';
3
+ import type { MessageRepo } from '../../../repo/message';
3
4
  import type { OrderRepo } from '../../../repo/order';
4
5
  import type { SettingRepo } from '../../../repo/setting';
5
6
  import type { TaskRepo } from '../../../repo/task';
@@ -9,6 +10,7 @@ import type { IntegrationSettingRepo as Settings } from '../../../repo/setting/i
9
10
  interface IOnPayTransactionConfirmedRepos {
10
11
  acceptedOffer: AcceptedOfferRepo;
11
12
  assetTransaction: AssetTransactionRepo;
13
+ message: MessageRepo;
12
14
  order: OrderRepo;
13
15
  setting: SettingRepo;
14
16
  task: TaskRepo;
@@ -1,4 +1,5 @@
1
1
  import type { AcceptedOfferRepo } from '../../../repo/acceptedOffer';
2
+ import type { MessageRepo } from '../../../repo/message';
2
3
  import type { OrderRepo } from '../../../repo/order';
3
4
  import type { SettingRepo } from '../../../repo/setting';
4
5
  import type { TaskRepo } from '../../../repo/task';
@@ -6,6 +7,7 @@ import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
6
7
  import type { IntegrationSettingRepo as Settings } from '../../../repo/setting/integration';
7
8
  interface IPaymentDue2ProcessingRepos {
8
9
  acceptedOffer: AcceptedOfferRepo;
10
+ message: MessageRepo;
9
11
  order: OrderRepo;
10
12
  setting: SettingRepo;
11
13
  task: TaskRepo;
@@ -1,5 +1,6 @@
1
1
  import type { AcceptedOfferRepo } from '../../repo/acceptedOffer';
2
2
  import type { AssetTransactionRepo } from '../../repo/assetTransaction';
3
+ import type { MessageRepo } from '../../repo/message';
3
4
  import type { OrderRepo } from '../../repo/order';
4
5
  import type { SettingRepo } from '../../repo/setting';
5
6
  import type { TaskRepo } from '../../repo/task';
@@ -11,6 +12,7 @@ import type { IntegrationSettingRepo as Settings } from '../../repo/setting/inte
11
12
  interface IOnAssetTransactionStatusChangedRepos {
12
13
  acceptedOffer: AcceptedOfferRepo;
13
14
  assetTransaction: AssetTransactionRepo;
15
+ message: MessageRepo;
14
16
  order: OrderRepo;
15
17
  setting: SettingRepo;
16
18
  task: TaskRepo;
@@ -1,9 +1,13 @@
1
+ import type { MessageRepo } from '../../../../repo/message';
1
2
  import type { TaskRepo } from '../../../../repo/task';
2
3
  import { factory } from '../../../../factory';
3
4
  declare function createSendEmailMessageTaskIfNotExist(params: {
4
- sendEmailMessage?: Pick<factory.action.transfer.send.message.email.IAttributes, 'object'>[];
5
+ sendEmailMessage?: {
6
+ object: factory.action.transfer.send.message.email.IOptimizedObject;
7
+ }[];
5
8
  order: Pick<factory.order.IOrder, 'customer' | 'orderDate' | 'orderNumber' | 'price' | 'priceCurrency' | 'project' | 'typeOf'>;
6
9
  }): (repos: {
10
+ message: MessageRepo;
7
11
  task: TaskRepo;
8
12
  }) => Promise<void>;
9
13
  export { createSendEmailMessageTaskIfNotExist };
@@ -1,45 +1,107 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.createSendEmailMessageTaskIfNotExist = createSendEmailMessageTaskIfNotExist;
7
+ const debug_1 = __importDefault(require("debug"));
4
8
  const util_1 = require("util");
5
9
  const factory_1 = require("../../../../factory");
10
+ const debug = (0, debug_1.default)('chevre-domain:service:order');
6
11
  function createSendEmailMessageTaskIfNotExist(params) {
7
12
  return async (repos) => {
8
13
  const sendEmailMessageActions = params.sendEmailMessage;
9
14
  const now = new Date();
10
- if (Array.isArray(sendEmailMessageActions)) {
11
- await Promise.all(sendEmailMessageActions.map(async (sendEmailMessageAction, index) => {
12
- const taskIdentifier = (0, util_1.format)('%s:%s:%s:%s:%s:%s', params.order.project.id, factory_1.factory.taskName.SendEmailMessage, params.order.typeOf, params.order.orderNumber, factory_1.factory.orderStatus.OrderProcessing, index);
13
- const simpleOrder = {
14
- typeOf: params.order.typeOf,
15
- orderNumber: params.order.orderNumber,
16
- // price: params.order.price,
17
- // priceCurrency: params.order.priceCurrency,
18
- orderDate: params.order.orderDate
19
- };
20
- const actionAttributes = {
21
- project: params.order.project,
22
- typeOf: factory_1.factory.actionType.SendAction,
23
- object: sendEmailMessageAction.object,
24
- agent: params.order.project,
25
- recipient: { typeOf: params.order.customer.typeOf, id: params.order.customer.id },
26
- // potentialActions: {}, // discontinue(2024-06-25~)
27
- purpose: simpleOrder
28
- };
29
- const sendEmailMessageTask = {
30
- alternateName: taskIdentifier,
31
- identifier: taskIdentifier,
32
- project: params.order.project,
33
- name: factory_1.factory.taskName.SendEmailMessage,
34
- status: factory_1.factory.taskStatus.Ready,
35
- runsAt: now, // なるはやで実行
36
- remainingNumberOfTries: 10,
37
- numberOfTried: 0,
38
- executionResults: [],
39
- data: { actionAttributes }
40
- };
41
- await repos.task.createIfNotExistByAlternateName(sendEmailMessageTask, { emitImmediately: true });
42
- }));
15
+ // 取引のpotentialActions参照を廃止して、messageリポジトリを参照して存在すればタスクを作成(2026-07-16~)
16
+ const message4order = (await repos.message.findMessages({
17
+ limit: 1,
18
+ page: 1,
19
+ about: { identifier: { $eq: factory_1.factory.creativeWork.message.email.AboutIdentifier.OnOrderSent } },
20
+ mainEntity: { orderNumber: { $eq: params.order.orderNumber } }
21
+ }, ['identifier'])).shift();
22
+ debug('createSendEmailMessageTaskIfNotExist: message4order:', JSON.stringify(message4order));
23
+ if (typeof message4order?.identifier === 'string') {
24
+ // 取引のpotentialActionsが存在する間は、メッセージ識別子が想定通りか確認する
25
+ const messageIdentifierByTransaction = sendEmailMessageActions?.at(0)?.object.identifier;
26
+ if (typeof messageIdentifierByTransaction === 'string') {
27
+ debug('createSendEmailMessageTaskIfNotExist: identifier matched?', message4order.identifier, messageIdentifierByTransaction);
28
+ if (message4order.identifier !== messageIdentifierByTransaction) {
29
+ throw new factory_1.factory.errors.Internal(`message identifier not matched. ${message4order.identifier} ${messageIdentifierByTransaction}`);
30
+ }
31
+ }
32
+ const taskIdentifier = (0, util_1.format)('%s:%s:%s:%s:%s:%s', params.order.project.id, factory_1.factory.taskName.SendEmailMessage, params.order.typeOf, params.order.orderNumber, factory_1.factory.orderStatus.OrderProcessing, 0 // 複数メッセージに対応していた時期の名残(2026-07-16~)
33
+ );
34
+ const simpleOrder = {
35
+ typeOf: params.order.typeOf,
36
+ orderNumber: params.order.orderNumber,
37
+ orderDate: params.order.orderDate
38
+ };
39
+ const actionAttributes = {
40
+ project: params.order.project,
41
+ typeOf: factory_1.factory.actionType.SendAction,
42
+ object: {
43
+ identifier: message4order.identifier,
44
+ typeOf: factory_1.factory.creativeWorkType.EmailMessage
45
+ },
46
+ agent: params.order.project,
47
+ recipient: { typeOf: params.order.customer.typeOf, id: params.order.customer.id },
48
+ purpose: simpleOrder
49
+ };
50
+ const sendEmailMessageTask = {
51
+ alternateName: taskIdentifier,
52
+ identifier: taskIdentifier,
53
+ project: params.order.project,
54
+ name: factory_1.factory.taskName.SendEmailMessage,
55
+ status: factory_1.factory.taskStatus.Ready,
56
+ runsAt: now, // なるはやで実行
57
+ remainingNumberOfTries: 10,
58
+ numberOfTried: 0,
59
+ executionResults: [],
60
+ data: { actionAttributes }
61
+ };
62
+ await repos.task.createIfNotExistByAlternateName(sendEmailMessageTask, { emitImmediately: true });
43
63
  }
64
+ // if (Array.isArray(sendEmailMessageActions)) {
65
+ // await Promise.all(sendEmailMessageActions.map(async (sendEmailMessageAction, index) => {
66
+ // const taskIdentifier: string = format(
67
+ // '%s:%s:%s:%s:%s:%s',
68
+ // params.order.project.id,
69
+ // factory.taskName.SendEmailMessage,
70
+ // params.order.typeOf,
71
+ // params.order.orderNumber,
72
+ // factory.orderStatus.OrderProcessing,
73
+ // index
74
+ // );
75
+ // const simpleOrder: factory.order.ISimpleOrder = {
76
+ // typeOf: params.order.typeOf,
77
+ // orderNumber: params.order.orderNumber,
78
+ // orderDate: params.order.orderDate
79
+ // };
80
+ // const actionAttributes: factory.task.sendEmailMessage.IData['actionAttributes'] = {
81
+ // project: params.order.project,
82
+ // typeOf: factory.actionType.SendAction,
83
+ // object: sendEmailMessageAction.object,
84
+ // agent: params.order.project,
85
+ // recipient: { typeOf: params.order.customer.typeOf, id: params.order.customer.id },
86
+ // purpose: simpleOrder
87
+ // };
88
+ // const sendEmailMessageTask: factory.task.IAttributes<factory.taskName.SendEmailMessage> & {
89
+ // alternateName: string;
90
+ // identifier: string;
91
+ // } = {
92
+ // alternateName: taskIdentifier,
93
+ // identifier: taskIdentifier,
94
+ // project: params.order.project,
95
+ // name: factory.taskName.SendEmailMessage,
96
+ // status: factory.taskStatus.Ready,
97
+ // runsAt: now, // なるはやで実行
98
+ // remainingNumberOfTries: 10,
99
+ // numberOfTried: 0,
100
+ // executionResults: [],
101
+ // data: { actionAttributes }
102
+ // };
103
+ // await repos.task.createIfNotExistByAlternateName(sendEmailMessageTask, { emitImmediately: true });
104
+ // }));
105
+ // }
44
106
  };
45
107
  }
@@ -1,3 +1,4 @@
1
+ import type { MessageRepo } from '../../../repo/message';
1
2
  import type { SettingRepo } from '../../../repo/setting';
2
3
  import type { TaskRepo } from '../../../repo/task';
3
4
  import { factory } from '../../../factory';
@@ -13,6 +14,7 @@ declare function onOrderProcessing(params: {
13
14
  };
14
15
  placeOrderTransaction?: IPlaceOrderTransaction;
15
16
  }): (repos: {
17
+ message: MessageRepo;
16
18
  setting: SettingRepo;
17
19
  task: TaskRepo;
18
20
  }, settings: Settings) => Promise<void>;
@@ -8,7 +8,7 @@ exports.onOrderReturned = onOrderReturned;
8
8
  * 注文返品時処理
9
9
  */
10
10
  const debug_1 = __importDefault(require("debug"));
11
- const google_libphonenumber_1 = require("google-libphonenumber");
11
+ const customerTelephone2COATelNum_1 = require("../../../factory/customerTelephone2COATelNum");
12
12
  const factory_1 = require("../../../factory");
13
13
  // import { createMaskedCustomer } from '../../../factory/order';
14
14
  const factory_2 = require("./onOrderReturned/factory");
@@ -104,11 +104,7 @@ function createReturnReserveTransactionTasks(order, simpleOrder) {
104
104
  if (typeof superEventLocationBranchCode !== 'string') {
105
105
  throw new factory_1.factory.errors.ArgumentNull('order.reservationForSuperEventLocationBranchCodes');
106
106
  }
107
- const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
108
- const phoneNumber = phoneUtil.parse(order.customer.telephone, 'JP');
109
- let telNum = phoneUtil.format(phoneNumber, google_libphonenumber_1.PhoneNumberFormat.NATIONAL);
110
- // COAでは数字のみ受け付けるので数字以外を除去
111
- telNum = telNum.replace(/[^\d]/g, '');
107
+ const telNum = (0, customerTelephone2COATelNum_1.customerTelephone2COATelNum)({ telephone: String(order.customer.telephone) });
112
108
  returnReserveTransactionAction = {
113
109
  project: order.project,
114
110
  typeOf: factory_1.factory.actionType.ReturnAction,
@@ -1,4 +1,5 @@
1
1
  import type { AcceptedOfferRepo } from '../../repo/acceptedOffer';
2
+ import type { MessageRepo } from '../../repo/message';
2
3
  import type { OrderRepo } from '../../repo/order';
3
4
  import type { SettingRepo } from '../../repo/setting';
4
5
  import type { TaskRepo } from '../../repo/task';
@@ -10,6 +11,7 @@ import type { IntegrationSettingRepo as Settings } from '../../repo/setting/inte
10
11
  */
11
12
  declare function payOrder(params: factory.task.IData<factory.taskName.OnOrderPaymentCompleted>): (repos: {
12
13
  acceptedOffer: AcceptedOfferRepo;
14
+ message: MessageRepo;
13
15
  order: OrderRepo;
14
16
  setting: SettingRepo;
15
17
  task: TaskRepo;
@@ -3,6 +3,7 @@ import type { AccountingReportRepo } from '../../repo/accountingReport';
3
3
  import type { ActionRepo } from '../../repo/action';
4
4
  import type { AuthorizeOfferActionRepo } from '../../repo/action/authorizeOffer';
5
5
  import type { AuthorizePaymentMethodActionRepo } from '../../repo/action/authorizePaymentMethod';
6
+ import type { MessageRepo } from '../../repo/message';
6
7
  import type { OrderRepo } from '../../repo/order';
7
8
  import type { OrderInTransactionRepo } from '../../repo/orderInTransaction';
8
9
  import type { SettingRepo } from '../../repo/setting';
@@ -17,6 +18,7 @@ interface IPlaceOrderRepos {
17
18
  action: ActionRepo;
18
19
  authorizeOfferAction: AuthorizeOfferActionRepo;
19
20
  authorizePaymentMethodAction: AuthorizePaymentMethodActionRepo;
21
+ message: MessageRepo;
20
22
  order: OrderRepo;
21
23
  orderInTransaction: OrderInTransactionRepo;
22
24
  setting: SettingRepo;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.searchByOrder = searchByOrder;
4
- const google_libphonenumber_1 = require("google-libphonenumber");
4
+ const customerTelephone2COATelNum_1 = require("../../factory/customerTelephone2COATelNum");
5
5
  const factory_1 = require("../../factory");
6
6
  function searchByOrder(params) {
7
7
  return async (repos) => {
@@ -42,11 +42,7 @@ function searchByOrder(params) {
42
42
  if (order === undefined) {
43
43
  throw new factory_1.factory.errors.NotFound(factory_1.factory.order.OrderType.Order);
44
44
  }
45
- const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
46
- const phoneNumber = phoneUtil.parse(order.customer.telephone, 'JP');
47
- let telNum = phoneUtil.format(phoneNumber, google_libphonenumber_1.PhoneNumberFormat.NATIONAL);
48
- // COAでは数字のみ受け付けるので数字以外を除去
49
- telNum = telNum.replace(/[^\d]/g, '');
45
+ const telNum = (0, customerTelephone2COATelNum_1.customerTelephone2COATelNum)({ telephone: String(order.customer.telephone) });
50
46
  const reservationNumber = (await repos.acceptedOffer.distinctValues({
51
47
  orderNumber: { $in: [params.orderNumber] }
52
48
  }, 'acceptedOffers.itemOffered.reservationNumber')).shift();
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.call = call;
4
4
  exports.confirmReserveTransaction = confirmReserveTransaction;
5
5
  const coa_service_1 = require("@motionpicture/coa-service");
6
- const google_libphonenumber_1 = require("google-libphonenumber");
7
6
  const util_1 = require("util");
7
+ const customerTelephone2COATelNum_1 = require("../../factory/customerTelephone2COATelNum");
8
8
  const factory_1 = require("../../factory");
9
9
  const confirm_1 = require("../assetTransaction/reserve/confirm");
10
10
  const reserveCOA_1 = require("../assetTransaction/reserveCOA");
@@ -71,12 +71,7 @@ function createConfirmObject4COAByOrder(params) {
71
71
  && o.offeredThrough?.identifier === factory_1.factory.service.webAPI.Identifier.COA;
72
72
  });
73
73
  const customer = params.order.customer;
74
- // 電話番号のフォーマットを日本人にリーダブルに調整(COAではこのフォーマットで扱うので)
75
- const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
76
- const phoneNumber = phoneUtil.parse(customer.telephone, 'JP');
77
- let telNum = phoneUtil.format(phoneNumber, google_libphonenumber_1.PhoneNumberFormat.NATIONAL);
78
- // COAでは数字のみ受け付けるので数字以外を除去
79
- telNum = telNum.replace(/[^\d]/g, '');
74
+ const telNum = (0, customerTelephone2COATelNum_1.customerTelephone2COATelNum)({ telephone: String(customer.telephone) });
80
75
  const mailAddr = customer.email;
81
76
  if (mailAddr === undefined) {
82
77
  throw new factory_1.factory.errors.Argument('order', 'order.customer.email undefined');
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.call = call;
4
4
  const acceptedOffer_1 = require("../../repo/acceptedOffer");
5
5
  const assetTransaction_1 = require("../../repo/assetTransaction");
6
+ const message_1 = require("../../repo/message");
6
7
  const order_1 = require("../../repo/order");
7
8
  const setting_1 = require("../../repo/setting");
8
9
  const integration_1 = require("../../repo/setting/integration");
9
10
  const task_1 = require("../../repo/task");
10
- // import { TransactionRepo } from '../../repo/transaction';
11
11
  const placeOrder_1 = require("../../repo/transaction/placeOrder");
12
12
  const onAssetTransactionStatusChanged_1 = require("../order/onAssetTransactionStatusChanged");
13
13
  /**
@@ -19,10 +19,10 @@ function call(data) {
19
19
  await (0, onAssetTransactionStatusChanged_1.onAssetTransactionStatusChanged)(data)({
20
20
  acceptedOffer: new acceptedOffer_1.AcceptedOfferRepo(connection),
21
21
  assetTransaction: new assetTransaction_1.AssetTransactionRepo(connection),
22
+ message: new message_1.MessageRepo(connection),
22
23
  order: new order_1.OrderRepo(connection),
23
24
  setting: new setting_1.SettingRepo(connection),
24
25
  task: new task_1.TaskRepo(connection),
25
- // transaction: new TransactionRepo(connection),
26
26
  placeOrder: new placeOrder_1.PlaceOrderRepo(connection)
27
27
  }, settings);
28
28
  };
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.call = call;
4
4
  const acceptedOffer_1 = require("../../repo/acceptedOffer");
5
+ const message_1 = require("../../repo/message");
5
6
  const order_1 = require("../../repo/order");
6
7
  const setting_1 = require("../../repo/setting");
7
8
  const integration_1 = require("../../repo/setting/integration");
@@ -16,6 +17,7 @@ function call(data) {
16
17
  const settings = new integration_1.IntegrationSettingRepo({ connection });
17
18
  await (0, payOrder_1.payOrder)(data)({
18
19
  acceptedOffer: new acceptedOffer_1.AcceptedOfferRepo(connection),
20
+ message: new message_1.MessageRepo(connection),
19
21
  order: new order_1.OrderRepo(connection),
20
22
  setting: new setting_1.SettingRepo(connection),
21
23
  task: new task_1.TaskRepo(connection),
@@ -6,12 +6,12 @@ const accountingReport_1 = require("../../repo/accountingReport");
6
6
  const action_1 = require("../../repo/action");
7
7
  const authorizeOffer_1 = require("../../repo/action/authorizeOffer");
8
8
  const authorizePaymentMethod_1 = require("../../repo/action/authorizePaymentMethod");
9
+ const message_1 = require("../../repo/message");
9
10
  const order_1 = require("../../repo/order");
10
11
  const orderInTransaction_1 = require("../../repo/orderInTransaction");
11
12
  const setting_1 = require("../../repo/setting");
12
13
  const integration_1 = require("../../repo/setting/integration");
13
14
  const task_1 = require("../../repo/task");
14
- // import { TransactionRepo } from '../../repo/transaction';
15
15
  const placeOrder_1 = require("../../repo/transaction/placeOrder");
16
16
  const placeOrder_2 = require("../order/placeOrder");
17
17
  /**
@@ -29,11 +29,11 @@ function call(data) {
29
29
  action: new action_1.ActionRepo(connection),
30
30
  authorizeOfferAction: new authorizeOffer_1.AuthorizeOfferActionRepo(connection),
31
31
  authorizePaymentMethodAction: new authorizePaymentMethod_1.AuthorizePaymentMethodActionRepo(connection),
32
+ message: new message_1.MessageRepo(connection),
32
33
  order: new order_1.OrderRepo(connection),
33
34
  orderInTransaction: new orderInTransaction_1.OrderInTransactionRepo(connection),
34
35
  setting: new setting_1.SettingRepo(connection),
35
36
  task: new task_1.TaskRepo(connection),
36
- // transaction: new TransactionRepo(connection),
37
37
  placeOrder: new placeOrder_1.PlaceOrderRepo(connection)
38
38
  }, settings);
39
39
  };
@@ -13,6 +13,8 @@ export declare function updateAgent(params: {
13
13
  agent: factory.order.ICustomer & {
14
14
  telephoneRegion?: string;
15
15
  };
16
+ }, options: {
17
+ useLibphonenumber: boolean;
16
18
  }): (repos: {
17
19
  orderInTransaction: OrderInTransactionRepo;
18
20
  placeOrder: PlaceOrderRepo;
@@ -2,17 +2,28 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateAgent = updateAgent;
4
4
  const google_libphonenumber_1 = require("google-libphonenumber");
5
+ const libphonenumber_js_1 = require("libphonenumber-js");
5
6
  const factory_1 = require("../../../factory");
6
- function fixCustomer(params) {
7
+ function fixCustomer(params, options) {
7
8
  return async (repos) => {
9
+ const { useLibphonenumber } = options;
8
10
  let formattedTelephone;
9
11
  try {
10
- const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
11
- const phoneNumber = phoneUtil.parse(params.agent.telephone, params.agent.telephoneRegion);
12
- if (!phoneUtil.isValidNumber(phoneNumber)) {
13
- throw new factory_1.factory.errors.Argument('telephone', 'Invalid phone number');
12
+ if (useLibphonenumber) {
13
+ const phoneNumber = (0, libphonenumber_js_1.parsePhoneNumberFromString)(String(params.agent.telephone), params.agent.telephoneRegion);
14
+ if (phoneNumber === undefined || !phoneNumber.isValid()) {
15
+ throw new factory_1.factory.errors.Argument('telephone', 'Invalid phone number');
16
+ }
17
+ formattedTelephone = phoneNumber.format('E.164');
18
+ }
19
+ else {
20
+ const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
21
+ const phoneNumber = phoneUtil.parse(params.agent.telephone, params.agent.telephoneRegion);
22
+ if (!phoneUtil.isValidNumber(phoneNumber)) {
23
+ throw new factory_1.factory.errors.Argument('telephone', 'Invalid phone number');
24
+ }
25
+ formattedTelephone = phoneUtil.format(phoneNumber, google_libphonenumber_1.PhoneNumberFormat.E164);
14
26
  }
15
- formattedTelephone = phoneUtil.format(phoneNumber, google_libphonenumber_1.PhoneNumberFormat.E164);
16
27
  }
17
28
  catch (error) {
18
29
  throw new factory_1.factory.errors.Argument('telephone', (error instanceof Error) ? error.message : String(error));
@@ -68,9 +79,9 @@ function fixCustomer(params) {
68
79
  /**
69
80
  * 取引人プロフィール更新
70
81
  */
71
- function updateAgent(params) {
82
+ function updateAgent(params, options) {
72
83
  return async (repos) => {
73
- const { customer, transaction } = await fixCustomer(params)(repos);
84
+ const { customer, transaction } = await fixCustomer(params, options)(repos);
74
85
  // also save in orderInTransaction(2024-06-20~)
75
86
  if (customer !== undefined) {
76
87
  // // 注文ドキュメントを参照(2026-06-24~)
@@ -95,6 +106,5 @@ function updateAgent(params) {
95
106
  customer: customerInOrder
96
107
  });
97
108
  }
98
- // return newAgent;
99
109
  };
100
110
  }
package/package.json CHANGED
@@ -11,15 +11,16 @@
11
11
  "dependencies": {
12
12
  "@aws-sdk/client-cognito-identity-provider": "3.600.0",
13
13
  "@aws-sdk/credential-providers": "3.600.0",
14
- "@chevre/factory": "9.5.0-alpha.9",
14
+ "@chevre/factory": "9.5.0-alpha.10",
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",
18
18
  "@surfrock/sdk": "2.0.0",
19
19
  "debug": "4.4.3",
20
- "google-libphonenumber": "^3.2.18",
20
+ "google-libphonenumber": "3.2.18",
21
21
  "http-status": "2.1.0",
22
22
  "jsonwebtoken": "9.0.0",
23
+ "libphonenumber-js": "1.13.8",
23
24
  "lodash.difference": "^4.5.0",
24
25
  "moment": "^2.29.1",
25
26
  "moment-timezone": "^0.5.33",
@@ -34,7 +35,7 @@
34
35
  "@sendgrid/helpers": "8.0.0",
35
36
  "@size-limit/preset-big-lib": "12.0.0",
36
37
  "@types/debug": "4.1.13",
37
- "@types/google-libphonenumber": "^7.4.19",
38
+ "@types/google-libphonenumber": "7.4.19",
38
39
  "@types/jsonwebtoken": "9.0.1",
39
40
  "@types/lodash.difference": "^4.5.6",
40
41
  "@types/node": "22.19.7",
@@ -91,5 +92,5 @@
91
92
  "postversion": "git push origin --tags",
92
93
  "prepublishOnly": "npm run clean && npm run build"
93
94
  },
94
- "version": "25.2.0-alpha.26"
95
+ "version": "25.2.0-alpha.28"
95
96
  }