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

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,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
+ }
@@ -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
  */
@@ -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,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');
@@ -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
@@ -17,9 +17,10 @@
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.27"
95
96
  }