@chevre/domain 25.2.0-alpha.33 → 25.2.0-alpha.35

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 (37) hide show
  1. package/lib/chevre/factory/customerTelephone2COATelNum.js +0 -1
  2. package/lib/chevre/repo/aggregateOffer.d.ts +2 -3
  3. package/lib/chevre/repo/creativeWork.d.ts +2 -3
  4. package/lib/chevre/repo/customerType.d.ts +2 -3
  5. package/lib/chevre/repo/event.d.ts +10 -11
  6. package/lib/chevre/repo/eventOffer.d.ts +4 -5
  7. package/lib/chevre/repo/eventSellerMakesOffer.d.ts +2 -3
  8. package/lib/chevre/repo/eventSeries.d.ts +4 -5
  9. package/lib/chevre/repo/note.d.ts +3 -4
  10. package/lib/chevre/repo/noteAboutOrder.d.ts +2 -3
  11. package/lib/chevre/repo/offerCatalog.d.ts +2 -3
  12. package/lib/chevre/repo/offerCatalogItem.d.ts +2 -3
  13. package/lib/chevre/repo/place/entranceGate.d.ts +4 -5
  14. package/lib/chevre/repo/place/movieTheater.d.ts +3 -4
  15. package/lib/chevre/repo/place/screeningRoom.d.ts +4 -5
  16. package/lib/chevre/repo/place/seat.d.ts +4 -5
  17. package/lib/chevre/repo/place/section.d.ts +3 -4
  18. package/lib/chevre/repo/product.d.ts +3 -4
  19. package/lib/chevre/repo/rateLimit/offer.js +0 -12
  20. package/lib/chevre/repo/reservation.d.ts +2 -3
  21. package/lib/chevre/repo/sellerMakesOffer.d.ts +3 -4
  22. package/lib/chevre/repo/stockHolder.d.ts +1 -1
  23. package/lib/chevre/repo/stockHolder.js +0 -146
  24. package/lib/chevre/repo/transactionNumberCounter.js +0 -34
  25. package/lib/chevre/repo/transactionProcess.js +0 -13
  26. package/lib/chevre/service/reserve/adminFindReservations.d.ts +15 -0
  27. package/lib/chevre/service/reserve/adminFindReservations.js +35 -0
  28. package/lib/chevre/service/reserve.d.ts +2 -2
  29. package/lib/chevre/service/reserve.js +3 -3
  30. package/lib/chevre/service/transaction/placeOrder/start.d.ts +1 -1
  31. package/lib/chevre/service/transaction/placeOrder/updateAgent/fixCustomer.d.ts +20 -0
  32. package/lib/chevre/service/transaction/placeOrder/updateAgent/fixCustomer.js +63 -0
  33. package/lib/chevre/service/transaction/placeOrder/updateAgent.d.ts +0 -3
  34. package/lib/chevre/service/transaction/placeOrder/updateAgent.js +17 -96
  35. package/package.json +6 -10
  36. package/lib/chevre/service/reserve/findReservations.d.ts +0 -33
  37. package/lib/chevre/service/reserve/findReservations.js +0 -61
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StockHolderRepo = void 0;
4
- // import type { RedisClientType } from 'redis';
5
4
  const factory_1 = require("../factory");
6
5
  const pendingReservation_1 = require("./pendingReservation");
7
6
  const SEARCH_OFFERS_MAX_LENGTH = 100;
@@ -9,36 +8,11 @@ const SEARCH_OFFERS_MAX_LENGTH = 100;
9
8
  * 保留予約リポジトリ
10
9
  */
11
10
  class StockHolderRepo {
12
- // public static KEY_PREFIX_NEW: string = 'stockHolder';
13
- // private readonly redisClient: RedisClientType | undefined;
14
11
  pendingReservationRepo;
15
12
  constructor(params) {
16
13
  const { connection } = params;
17
- // this.redisClient = redisClient;
18
14
  this.pendingReservationRepo = new pendingReservation_1.PendingReservationRepo(connection);
19
15
  }
20
- // private static offer2field(params: IOffer, hasTicketedSeat: boolean) {
21
- // if (hasTicketedSeat) {
22
- // return `${params.seatSection}:${params.seatNumber}`;
23
- // } else {
24
- // // 予約IDをfieldにする場合
25
- // const serviceOutputId = params.itemOffered?.serviceOutput?.id;
26
- // if (typeof serviceOutputId === 'string') {
27
- // return serviceOutputId;
28
- // } else {
29
- // throw new factory.errors.Internal('offer2field requires itemOffered.serviceOutput.id');
30
- // }
31
- // }
32
- // }
33
- // private static createKey(params: {
34
- // eventId: string;
35
- // startDate: Date;
36
- // }): string {
37
- // if (!(params.startDate instanceof Date)) {
38
- // throw new factory.errors.Argument('startDate', 'must be Date');
39
- // }
40
- // return `${StockHolderRepo.KEY_PREFIX_NEW}:${params.eventId}`;
41
- // }
42
16
  /**
43
17
  * 座席をロックする(maxキャパシティチェック有)
44
18
  */
@@ -54,16 +28,6 @@ class StockHolderRepo {
54
28
  }
55
29
  else {
56
30
  throw new factory_1.factory.errors.NotImplemented('useRedis discontinued.');
57
- // if (this.redisClient === undefined) {
58
- // throw new factory.errors.Internal('redisClient required');
59
- // }
60
- // const key = StockHolderRepo.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
61
- // await this.redisClient.watch(key);
62
- // const hashCount = await this.redisClient.hLen(key);
63
- // if (hashCount + lockKey.offers.length > maximum) {
64
- // throw new factory.errors.Argument('Event', 'maximumAttendeeCapacity exceeded');
65
- // }
66
- // await this.lock(lockKey);
67
31
  }
68
32
  }
69
33
  /**
@@ -79,59 +43,11 @@ class StockHolderRepo {
79
43
  startDate: lockKey.startDate,
80
44
  hasTicketedSeat: lockKey.hasTicketedSeat
81
45
  });
82
- // const key = StockHolderRepo.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
83
- // await this.checkIfConflicted({ key, eventId: lockKey.eventId, useMongoose });
84
46
  if (useMongoose) {
85
47
  return this.pendingReservationRepo.lock(lockKey);
86
48
  }
87
49
  else {
88
50
  throw new factory_1.factory.errors.NotImplemented('useRedis discontinued.');
89
- // if (this.redisClient === undefined) {
90
- // throw new factory.errors.Internal('redisClient required');
91
- // }
92
- // const value = lockKey.holder;
93
- // const multi = this.redisClient.multi();
94
- // const fields = lockKey.offers.map((offer) => StockHolderRepo.offer2field(offer, lockKey.hasTicketedSeat));
95
- // // check uniqueness(2025-04-20~)
96
- // const uniqueFields = [...new Set(fields)];
97
- // if (uniqueFields.length !== fields.length) {
98
- // throw new factory.errors.Argument('offers', 'offers must be unique');
99
- // }
100
- // fields.forEach((field) => {
101
- // multi.hSetNX(key, field, value);
102
- // });
103
- // const results = await multi.expireAt(
104
- // key,
105
- // moment(lockKey.expires)
106
- // .unix()
107
- // )
108
- // .exec();
109
- // const lockedFields: string[] = [];
110
- // if (Array.isArray(results)) {
111
- // results.slice(0, fields.length)
112
- // .forEach((r, index) => {
113
- // if (r === 1 || (<any>r) === true) {
114
- // lockedFields.push(fields[index]);
115
- // }
116
- // });
117
- // }
118
- // const lockedAll = lockedFields.length === fields.length;
119
- // // expireAtReplyの検証も追加する(2023-04-19~)
120
- // const expiredAll = results.slice(fields.length)
121
- // .every((r) => (r === 1 || (<any>r) === true));
122
- // if (!lockedAll || !expiredAll) {
123
- // if (lockedFields.length > 0) {
124
- // // 全て仮押さえできなければ仮押さえできたものは解除
125
- // await this.redisClient.multi()
126
- // .hDel(key, lockedFields)
127
- // .exec();
128
- // }
129
- // if (!lockedAll) {
130
- // throw new factory.errors.AlreadyInUse(factory.reservationType.EventReservation, ['ticketedSeat'], 'Already hold');
131
- // } else {
132
- // throw new factory.errors.Internal('timeout cannot be set unexpectedly');
133
- // }
134
- // }
135
51
  }
136
52
  }
137
53
  /**
@@ -144,20 +60,11 @@ class StockHolderRepo {
144
60
  startDate: params.startDate,
145
61
  hasTicketedSeat: params.hasTicketedSeat
146
62
  });
147
- // const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
148
- // await this.checkIfConflicted({ key, eventId: params.eventId, useMongoose });
149
63
  if (useMongoose) {
150
64
  return this.pendingReservationRepo.unlock(params);
151
65
  }
152
66
  else {
153
67
  throw new factory_1.factory.errors.NotImplemented('useRedis discontinued.');
154
- // if (this.redisClient === undefined) {
155
- // throw new factory.errors.Internal('redisClient required');
156
- // }
157
- // const field = StockHolderRepo.offer2field(params.offer, params.hasTicketedSeat);
158
- // await this.redisClient.multi()
159
- // .hDel(key, field)
160
- // .exec();
161
68
  }
162
69
  }
163
70
  /**
@@ -174,16 +81,6 @@ class StockHolderRepo {
174
81
  }
175
82
  else {
176
83
  throw new factory_1.factory.errors.NotImplemented('useRedis discontinued.');
177
- // if (this.redisClient === undefined) {
178
- // throw new factory.errors.Internal('redisClient required');
179
- // }
180
- // const key = StockHolderRepo.createKey({ eventId: params.event.id, startDate: params.event.startDate });
181
- // const reply = await this.redisClient.hLen(key);
182
- // let fieldCount: number = 0;
183
- // if (typeof reply === 'number') {
184
- // fieldCount = Number(reply);
185
- // }
186
- // return fieldCount;
187
84
  }
188
85
  }
189
86
  /**
@@ -200,12 +97,6 @@ class StockHolderRepo {
200
97
  }
201
98
  else {
202
99
  throw new factory_1.factory.errors.NotImplemented('useRedis discontinued.');
203
- // if (this.redisClient === undefined) {
204
- // throw new factory.errors.Internal('redisClient required');
205
- // }
206
- // const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
207
- // const field = StockHolderRepo.offer2field(params.offer, params.hasTicketedSeat);
208
- // return this.redisClient.hGet(key, field);
209
100
  }
210
101
  }
211
102
  async searchHolders(params) {
@@ -223,32 +114,8 @@ class StockHolderRepo {
223
114
  }
224
115
  else {
225
116
  throw new factory_1.factory.errors.NotImplemented('useRedis discontinued.');
226
- // if (this.redisClient === undefined) {
227
- // throw new factory.errors.Internal('redisClient required');
228
- // }
229
- // const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
230
- // const fields = params.offers.map((o) => {
231
- // return StockHolderRepo.offer2field(o, params.hasTicketedSeat);
232
- // });
233
- // // Array reply: list of values associated with the given fields, in the same order as they are requested.
234
- // const result = await this.redisClient.hmGet(key, fields);
235
- // if (!Array.isArray(result)) {
236
- // throw new factory.errors.Internal(`searchAvailability got non-array: ${typeof result}`);
237
- // }
238
- // // そのまま返却(2023-04-17~)
239
- // return result;
240
117
  }
241
118
  }
242
- // public async checkIfConflicted(params: {
243
- // eventId: string;
244
- // startDate: Date;
245
- // }): Promise<void> {
246
- // const redisKeyExists = await this.redisKeyExists(params);
247
- // const mongoDocExists = await this.pendingReservationRepo.docExists(params);
248
- // if (redisKeyExists && mongoDocExists) {
249
- // throw new factory.errors.Internal(`repository conflicted. eventId:${params.eventId}`);
250
- // }
251
- // }
252
119
  /**
253
120
  * 新リポジトリを使用するかどうか
254
121
  */
@@ -258,19 +125,6 @@ class StockHolderRepo {
258
125
  }
259
126
  // always use mongo(2025-08-17~)
260
127
  return true;
261
- // let useMongoose = false;
262
- // const redisKeyExists = await this.redisKeyExists(params);
263
- // if (redisKeyExists) {
264
- // useMongoose = false;
265
- // } else {
266
- // // redis keyが存在しなければmongo利用
267
- // useMongoose = true;
268
- // }
269
- // // check confliction for test
270
- // if (USE_STOCK_HOLDER_CHECK_CONFLICT) {
271
- // await this.checkIfConflicted(params);
272
- // }
273
- // return useMongoose;
274
128
  }
275
129
  }
276
130
  exports.StockHolderRepo = StockHolderRepo;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TransactionNumberCounterRepo = void 0;
4
- // import { RedisClientType } from 'redis';
5
4
  const errorHandler_1 = require("../errorHandler");
6
5
  const factory_1 = require("../factory");
7
6
  const transactionNumber_1 = require("./mongoose/schemas/transactionNumber");
@@ -10,44 +9,11 @@ const MAX_RETRY_INCREMENT = 1;
10
9
  * 取引番号カウンターリポジトリ
11
10
  */
12
11
  class TransactionNumberCounterRepo {
13
- // private readonly redisClient: RedisClientType;
14
12
  transactionNumberModel;
15
13
  constructor(params) {
16
14
  const { connection } = params;
17
- // this.redisClient = redisClient;
18
15
  this.transactionNumberModel = connection.model(transactionNumber_1.modelName, (0, transactionNumber_1.createSchema)());
19
16
  }
20
- // public async incrementByRedis(params: {
21
- // identifier: string;
22
- // includedInDataCatalog: {
23
- // identifier: DataCatalogIdentifier;
24
- // };
25
- // expires: Date;
26
- // }): Promise<number> {
27
- // // const now = moment();
28
- // const { expires } = params;
29
- // const key = `${params.includedInDataCatalog.identifier}:${params.identifier}`;
30
- // // const TTL = moment(expires)
31
- // // .diff(now, 'seconds');
32
- // const [incrReply, expireAtReply] = await this.redisClient.multi()
33
- // .incr(key)
34
- // // .expire(key, TTL)
35
- // .expireAt(key, expires)
36
- // .exec();
37
- // // tslint:disable-next-line:no-single-line-block-comment
38
- // /* istanbul ignore else: please write tests */
39
- // if (typeof incrReply !== 'number') {
40
- // // 基本的にありえないフロー
41
- // throw new factory.errors.Internal('transaction number not incremented unexpectedly');
42
- // }
43
- // // expireAtReplyの検証も追加する(2023-04-19~)
44
- // const expiredSet = expireAtReply === 1 || <any>expireAtReply === true;
45
- // if (!expiredSet) {
46
- // // 基本的にありえないフロー
47
- // throw new factory.errors.Internal('transaction number expiration not set unexpectedly');
48
- // }
49
- // return incrReply;
50
- // }
51
17
  async incrementByMongo(params) {
52
18
  const now = new Date();
53
19
  const dataFeedExpires = params.expires;
@@ -16,10 +16,8 @@ const DEFAULT_LOCK_EXPIRES = 120;
16
16
  class TransactionProcessRepo {
17
17
  concurrentLockRepo;
18
18
  options;
19
- // private readonly redisClient: RedisClientType;
20
19
  constructor(redisClient, options) {
21
20
  this.concurrentLockRepo = new concurrentLock_1.ConcurrentLockRepo({ redisClient });
22
- // this.redisClient = redisClient;
23
21
  this.options = options;
24
22
  }
25
23
  static CREATE_REDIS_KEY(params) {
@@ -44,16 +42,6 @@ class TransactionProcessRepo {
44
42
  catch (_error) {
45
43
  throw new factory_1.factory.errors.AlreadyInUse(params.typeOf, [], 'Another transaction process in progress');
46
44
  }
47
- // const results = await this.redisClient.multi()
48
- // .setNX(key, '1')
49
- // .expire(key, ttl)
50
- // .exec();
51
- // debug('locked,', params.id, results);
52
- // if (Array.isArray(results) && (results[0] === 1 || (<any>results)[0] === true)) {
53
- // return;
54
- // } else {
55
- // throw new factory.errors.AlreadyInUse(params.typeOf, [], 'Another transaction process in progress');
56
- // }
57
45
  }
58
46
  async unlock(params) {
59
47
  const key = TransactionProcessRepo.CREATE_REDIS_KEY(params);
@@ -62,7 +50,6 @@ class TransactionProcessRepo {
62
50
  about: { identifier: key, typeOf: 'Thing' },
63
51
  audience: { identifier: '1', typeOf: 'Audience' }
64
52
  });
65
- // await this.redisClient.del([key]);
66
53
  }
67
54
  }
68
55
  exports.TransactionProcessRepo = TransactionProcessRepo;
@@ -0,0 +1,15 @@
1
+ import { factory } from '../../factory';
2
+ import type { IKeyOfProjection, ReservationRepo } from '../../repo/reservation';
3
+ /**
4
+ * 予約検索レスポンスとしての予約
5
+ */
6
+ type IReservationAsFindResult = Pick<factory.reservation.eventReservation.IReservation, 'additionalTicketText' | 'attended' | 'bookingTime' | 'checkedIn' | 'id' | 'reservationFor' | 'reservationNumber' | 'reservationStatus' | 'reservedTicket'>;
7
+ /**
8
+ * 管理者による予約検索
9
+ */
10
+ export declare function adminFindReservations(params: factory.reservation.eventReservation.ISearchConditions, options: {
11
+ inclusion: Partial<Record<IKeyOfProjection, 1>>;
12
+ }): (repos: {
13
+ reservation: ReservationRepo;
14
+ }) => Promise<IReservationAsFindResult[]>;
15
+ export {};
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.adminFindReservations = adminFindReservations;
4
+ /**
5
+ * 管理者による予約検索
6
+ */
7
+ function adminFindReservations(params, options) {
8
+ return async (repos) => {
9
+ const { inclusion } = options;
10
+ const rawReservations = await repos.reservation.findReservations(params, inclusion);
11
+ if (rawReservations.length === 0) {
12
+ return [];
13
+ }
14
+ else {
15
+ // const requireUnderName = Object.keys(inclusion).includes('underName');
16
+ // const requireReservedTicket = Object.keys(inclusion).includes('reservedTicket');
17
+ // const requireReservationFor = Object.keys(inclusion).includes('reservationFor');
18
+ // const reservationIds = rawReservations.map(({ id }) => id);
19
+ // const subReservations = await repos.assetTransaction.reserve.findSubReservationsById({
20
+ // ids: reservationIds
21
+ // });
22
+ return rawReservations.map((reservation) => {
23
+ // const subReservationByTransaction = subReservations.find((s) => s.id === reservation.id);
24
+ // const underNameByTransaction = subReservationByTransaction?.underName;
25
+ const { reservationFor, issuedThrough: _issuedThrough, priceCurrency: _priceCurrency, numSeats: _numSeats, reservedTicket, ...rawReservation4result } = reservation;
26
+ return {
27
+ ...rawReservation4result, // 予約ドキュメントはそのまま返す
28
+ reservedTicket, // 予約検索レスポンスからticketTypeは廃止(2026-06-01~)
29
+ reservationFor // 予約検索レスポンスのreservationForはそのまま返す(2026-06-01~)
30
+ // ...(requireUnderName && underNameByTransaction !== undefined) ? { underName: underNameByTransaction } : undefined, // underNameがあれば上書き
31
+ };
32
+ });
33
+ }
34
+ };
35
+ }
@@ -5,7 +5,7 @@ import { cancelPendingReservation, cancelReservation } from './reserve/cancelRes
5
5
  import { checkInReservation } from './reserve/checkInReservation';
6
6
  import { confirmReservation } from './reserve/confirmReservation';
7
7
  import { findByCode } from './reserve/findByCode';
8
- import { findReservations } from './reserve/findReservations';
8
+ import { adminFindReservations } from './reserve/adminFindReservations';
9
9
  import { searchByOrder } from './reserve/searchByOrder';
10
10
  import { verifyToken4reservation } from './reserve/verifyToken4reservation';
11
- export { cancelPendingReservation, cancelReservation, checkInReservation, confirmReservation, findByCode, findReservations, searchByOrder, verifyToken4reservation };
11
+ export { cancelPendingReservation, cancelReservation, checkInReservation, confirmReservation, findByCode, adminFindReservations, searchByOrder, verifyToken4reservation };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verifyToken4reservation = exports.searchByOrder = exports.findReservations = exports.findByCode = exports.confirmReservation = exports.checkInReservation = exports.cancelReservation = exports.cancelPendingReservation = void 0;
3
+ exports.verifyToken4reservation = exports.searchByOrder = exports.adminFindReservations = exports.findByCode = exports.confirmReservation = exports.checkInReservation = exports.cancelReservation = exports.cancelPendingReservation = void 0;
4
4
  /**
5
5
  * 予約サービス
6
6
  */
@@ -13,8 +13,8 @@ const confirmReservation_1 = require("./reserve/confirmReservation");
13
13
  Object.defineProperty(exports, "confirmReservation", { enumerable: true, get: function () { return confirmReservation_1.confirmReservation; } });
14
14
  const findByCode_1 = require("./reserve/findByCode");
15
15
  Object.defineProperty(exports, "findByCode", { enumerable: true, get: function () { return findByCode_1.findByCode; } });
16
- const findReservations_1 = require("./reserve/findReservations");
17
- Object.defineProperty(exports, "findReservations", { enumerable: true, get: function () { return findReservations_1.findReservations; } });
16
+ const adminFindReservations_1 = require("./reserve/adminFindReservations");
17
+ Object.defineProperty(exports, "adminFindReservations", { enumerable: true, get: function () { return adminFindReservations_1.adminFindReservations; } });
18
18
  const searchByOrder_1 = require("./reserve/searchByOrder");
19
19
  Object.defineProperty(exports, "searchByOrder", { enumerable: true, get: function () { return searchByOrder_1.searchByOrder; } });
20
20
  const verifyToken4reservation_1 = require("./reserve/verifyToken4reservation");
@@ -9,7 +9,7 @@ import type { ProjectMakesOfferRepo } from '../../../repo/projectMakesOffer';
9
9
  import type { SellerRepo } from '../../../repo/seller';
10
10
  import type { IStartedPlaceOrder, PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
11
11
  import { IStartPlaceOrderParams } from './start/factory';
12
- interface IStartOperationRepos {
12
+ export interface IStartOperationRepos {
13
13
  issuer: IssuerRepo;
14
14
  member: MemberRepo;
15
15
  memberProgram: MemberProgramRepo;
@@ -0,0 +1,20 @@
1
+ import { factory } from '../../../../factory';
2
+ import type { OrderInTransactionRepo } from '../../../../repo/orderInTransaction';
3
+ export interface IFixCustomerRepos {
4
+ orderInTransaction: OrderInTransactionRepo;
5
+ }
6
+ export type IProfileByRequest = Pick<factory.order.ICustomer, 'additionalProperty' | 'address' | 'age' | 'email' | 'familyName' | 'gender' | 'givenName' | 'name' | 'telephone' | 'url'> & {
7
+ telephoneRegion?: string;
8
+ };
9
+ /**
10
+ * 進行中取引からカスタマー属性を決定する
11
+ */
12
+ export declare function fixCustomer(params: {
13
+ /**
14
+ * 注文取引ID
15
+ */
16
+ id: string;
17
+ profileByRequest: IProfileByRequest;
18
+ }): (repos: IFixCustomerRepos) => Promise<{
19
+ customer: factory.order.ICustomer;
20
+ }>;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fixCustomer = fixCustomer;
4
+ const libphonenumber_js_1 = require("libphonenumber-js");
5
+ const factory_1 = require("../../../../factory");
6
+ /**
7
+ * 進行中取引からカスタマー属性を決定する
8
+ */
9
+ function fixCustomer(params) {
10
+ return async (repos) => {
11
+ const { profileByRequest } = params;
12
+ let formattedTelephone;
13
+ try {
14
+ const phoneNumber = (0, libphonenumber_js_1.parsePhoneNumberFromString)(String(profileByRequest.telephone), profileByRequest.telephoneRegion);
15
+ if (phoneNumber === undefined || !phoneNumber.isValid()) {
16
+ throw new factory_1.factory.errors.Argument('telephone', 'Invalid phone number');
17
+ }
18
+ formattedTelephone = phoneNumber.format('E.164');
19
+ // if (useLibphonenumber) {
20
+ // const phoneNumber = parsePhoneNumberFromString(String(params.agent.telephone), params.agent.telephoneRegion as CountryCode | undefined);
21
+ // if (phoneNumber === undefined || !phoneNumber.isValid()) {
22
+ // throw new factory.errors.Argument('telephone', 'Invalid phone number');
23
+ // }
24
+ // formattedTelephone = phoneNumber.format('E.164');
25
+ // } else {
26
+ // const phoneUtil = PhoneNumberUtil.getInstance();
27
+ // const phoneNumber = phoneUtil.parse(params.agent.telephone, params.agent.telephoneRegion);
28
+ // if (!phoneUtil.isValidNumber(phoneNumber)) {
29
+ // throw new factory.errors.Argument('telephone', 'Invalid phone number');
30
+ // }
31
+ // formattedTelephone = phoneUtil.format(phoneNumber, PhoneNumberFormat.E164);
32
+ // }
33
+ }
34
+ catch (error) {
35
+ throw new factory_1.factory.errors.Argument('telephone', (error instanceof Error) ? error.message : /* istanbul ignore next */ String(error));
36
+ }
37
+ // orderInTransaction.customer?.typeOfは取引開始時にセットされている前提で再実装(2026-06-24~)
38
+ const customerByTransaction = await repos.orderInTransaction.findCustomerByOrderIdentifier({ identifier: params.id });
39
+ const customerName = (typeof profileByRequest.name === 'string' && profileByRequest.name !== '')
40
+ ? profileByRequest.name
41
+ : /* istanbul ignore next */ (typeof profileByRequest.givenName === 'string' && typeof profileByRequest.familyName === 'string'
42
+ && profileByRequest.givenName !== '' && profileByRequest.familyName !== '')
43
+ ? `${profileByRequest.givenName} ${profileByRequest.familyName}`
44
+ : undefined;
45
+ const identifier = (Array.isArray(customerByTransaction.identifier)) ? customerByTransaction.identifier : /* istanbul ignore next */ [];
46
+ const customer = {
47
+ typeOf: customerByTransaction.typeOf, // 取引開始時で固定
48
+ id: customerByTransaction.id, // 取引開始時で固定
49
+ identifier, // 取引開始時で固定
50
+ ...((Array.isArray(profileByRequest.additionalProperty)) && { additionalProperty: profileByRequest.additionalProperty }),
51
+ ...((typeof profileByRequest.age === 'string') && { age: profileByRequest.age }),
52
+ ...((typeof profileByRequest.address === 'string') && { address: profileByRequest.address }),
53
+ ...((typeof profileByRequest.email === 'string') && { email: profileByRequest.email }),
54
+ ...((typeof profileByRequest.familyName === 'string') && { familyName: profileByRequest.familyName }),
55
+ ...((typeof profileByRequest.gender === 'string') && { gender: profileByRequest.gender }),
56
+ ...((typeof profileByRequest.givenName === 'string') && { givenName: profileByRequest.givenName }),
57
+ ...((typeof customerName === 'string') && { name: customerName }),
58
+ ...((typeof formattedTelephone === 'string') && { telephone: formattedTelephone }),
59
+ ...((typeof profileByRequest.url === 'string') && { url: profileByRequest.url })
60
+ };
61
+ return { customer };
62
+ };
63
+ }
@@ -5,7 +5,6 @@ import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
5
5
  * 取引人プロフィール更新
6
6
  */
7
7
  export declare function updateAgent(params: {
8
- typeOf: factory.transactionType.PlaceOrder;
9
8
  /**
10
9
  * 取引ID
11
10
  */
@@ -13,8 +12,6 @@ export declare function updateAgent(params: {
13
12
  agent: factory.order.ICustomer & {
14
13
  telephoneRegion?: string;
15
14
  };
16
- }, options: {
17
- useLibphonenumber: boolean;
18
15
  }): (repos: {
19
16
  orderInTransaction: OrderInTransactionRepo;
20
17
  placeOrder: PlaceOrderRepo;
@@ -1,33 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateAgent = updateAgent;
4
- const google_libphonenumber_1 = require("google-libphonenumber");
5
- const libphonenumber_js_1 = require("libphonenumber-js");
6
4
  const factory_1 = require("../../../factory");
7
- function fixCustomer(params, options) {
5
+ const fixCustomer_1 = require("./updateAgent/fixCustomer");
6
+ /**
7
+ * 取引人プロフィール更新
8
+ */
9
+ function updateAgent(params) {
8
10
  return async (repos) => {
9
- const { useLibphonenumber } = options;
10
- let formattedTelephone;
11
- try {
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);
26
- }
27
- }
28
- catch (error) {
29
- throw new factory_1.factory.errors.Argument('telephone', (error instanceof Error) ? error.message : String(error));
30
- }
31
11
  const transaction = await repos.placeOrder.findPlaceOrderInProgressById({
32
12
  typeOf: factory_1.factory.transactionType.PlaceOrder,
33
13
  id: params.id
@@ -35,76 +15,17 @@ function fixCustomer(params, options) {
35
15
  if (transaction.agent.id !== params.agent.id) {
36
16
  throw new factory_1.factory.errors.Forbidden('Transaction not yours');
37
17
  }
38
- // 注文取引の場合、object.customerにも適用
39
- let customer;
40
- if (transaction.typeOf === factory_1.factory.transactionType.PlaceOrder) {
41
- // orderInTransaction.customer?.typeOfは取引開始時にセットされている前提で再実装(2026-06-24~)
42
- const customerByTransaction = await repos.orderInTransaction.findCustomerByOrderIdentifier({
43
- identifier: params.id,
44
- // project: { id: transaction.project.id }
45
- });
46
- // // いったんtransaction.object.customer?.typeOfは取引開始時にセットされている前提
47
- // const customerByTransaction = transaction.object.customer;
48
- if (typeof customerByTransaction?.typeOf === 'string') {
49
- customer = {
50
- typeOf: customerByTransaction.typeOf,
51
- id: customerByTransaction.id,
52
- ...(Array.isArray(customerByTransaction.identifier))
53
- ? { identifier: customerByTransaction.identifier }
54
- : /* istanbul ignore next */ undefined,
55
- ...(Array.isArray(params.agent.additionalProperty))
56
- ? { additionalProperty: params.agent.additionalProperty }
57
- : /* istanbul ignore next */ undefined,
58
- ...(typeof params.agent.age === 'string') ? { age: params.agent.age }
59
- : /* istanbul ignore next */ undefined,
60
- ...(typeof params.agent.address === 'string') ? { address: params.agent.address }
61
- : /* istanbul ignore next */ undefined,
62
- ...(typeof params.agent.email === 'string') ? { email: params.agent.email }
63
- : /* istanbul ignore next */ undefined,
64
- ...(typeof params.agent.familyName === 'string') ? { familyName: params.agent.familyName }
65
- : /* istanbul ignore next */ undefined,
66
- ...(typeof params.agent.gender === 'string') ? { gender: params.agent.gender }
67
- : /* istanbul ignore next */ undefined,
68
- ...(typeof params.agent.givenName === 'string') ? { givenName: params.agent.givenName }
69
- : /* istanbul ignore next */ undefined,
70
- ...(typeof params.agent.name === 'string') ? { name: params.agent.name } : /* istanbul ignore next */ undefined,
71
- ...(typeof formattedTelephone === 'string') ? { telephone: formattedTelephone } : /* istanbul ignore next */ undefined,
72
- ...(typeof params.agent.url === 'string') ? { url: params.agent.url } : /* istanbul ignore next */ undefined
73
- };
74
- }
75
- }
76
- return { customer, transaction };
77
- };
78
- }
79
- /**
80
- * 取引人プロフィール更新
81
- */
82
- function updateAgent(params, options) {
83
- return async (repos) => {
84
- const { customer, transaction } = await fixCustomer(params, options)(repos);
85
- // also save in orderInTransaction(2024-06-20~)
86
- if (customer !== undefined) {
87
- // // 注文ドキュメントを参照(2026-06-24~)
88
- // const orderNumber = await repos.orderInTransaction.findOrderNumberByIdentifier({
89
- // identifier: params.id,
90
- // project: { id: transaction.project.id },
91
- // }, { onlyPlaceOrder: true });
92
- const customerName = (typeof customer.name === 'string' && customer.name !== '')
93
- ? customer.name
94
- : (typeof customer.givenName === 'string' && typeof customer.familyName === 'string'
95
- && customer.givenName !== '' && customer.familyName !== '')
96
- ? `${customer.givenName} ${customer.familyName}`
97
- : undefined;
98
- const customerInOrder = {
99
- ...customer,
100
- identifier: (Array.isArray(customer.identifier)) ? customer.identifier : [],
101
- ...(typeof customerName === 'string') ? { name: customerName } : undefined
102
- };
103
- await repos.orderInTransaction.setCustomerByIdentifier({
104
- project: transaction.project,
105
- identifier: params.id,
106
- customer: customerInOrder
107
- });
108
- }
18
+ const { id: _id, typeOf: _typeOf, ...profileByRequest } = params.agent;
19
+ const { customer } = await (0, fixCustomer_1.fixCustomer)({ id: params.id, profileByRequest })(repos);
20
+ // // 注文ドキュメントを参照(2026-06-24~)
21
+ // const orderNumber = await repos.orderInTransaction.findOrderNumberByIdentifier({
22
+ // identifier: params.id,
23
+ // project: { id: transaction.project.id },
24
+ // }, { onlyPlaceOrder: true });
25
+ await repos.orderInTransaction.setCustomerByIdentifier({
26
+ project: transaction.project,
27
+ identifier: params.id,
28
+ customer
29
+ });
109
30
  };
110
31
  }