@chevre/domain 24.0.0-alpha.73 → 24.0.0-alpha.75

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 (86) hide show
  1. package/lib/chevre/credentials.js +3 -26
  2. package/lib/chevre/errorHandler.js +15 -38
  3. package/lib/chevre/eventEmitter.js +17 -7
  4. package/lib/chevre/index.d.ts +0 -2
  5. package/lib/chevre/index.js +17 -29
  6. package/lib/chevre/repo/aggregateOffer.js +3 -26
  7. package/lib/chevre/repo/event.js +17 -7
  8. package/lib/chevre/repo/eventSeries.js +1 -24
  9. package/lib/chevre/repo/offerCatalog.js +3 -26
  10. package/lib/chevre/repository.js +103 -126
  11. package/lib/chevre/service/accountTransaction.js +17 -7
  12. package/lib/chevre/service/aggregation.js +17 -7
  13. package/lib/chevre/service/assetTransaction/pay/check.js +17 -7
  14. package/lib/chevre/service/assetTransaction/pay/publishPaymentUrl.js +17 -7
  15. package/lib/chevre/service/assetTransaction/pay/searchGMOTrade.js +17 -7
  16. package/lib/chevre/service/assetTransaction/pay/start/processAuthorize.js +5 -5
  17. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeCreditCard.js +17 -7
  18. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeMovieTicket.js +17 -7
  19. package/lib/chevre/service/assetTransaction/registerService/potentialActions.js +0 -1
  20. package/lib/chevre/service/assetTransaction/registerService.d.ts +3 -0
  21. package/lib/chevre/service/assetTransaction/registerService.js +19 -62
  22. package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +52 -76
  23. package/lib/chevre/service/assetTransaction/reserve/start.js +18 -75
  24. package/lib/chevre/service/assetTransaction.d.ts +0 -2
  25. package/lib/chevre/service/assetTransaction.js +18 -17
  26. package/lib/chevre/service/notification/notifyByEmail.js +1 -1
  27. package/lib/chevre/service/notification/sendEmailMessage.js +1 -1
  28. package/lib/chevre/service/notification/triggerWebhook.js +22 -12
  29. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.js +17 -7
  30. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer/authorize.js +2 -2
  31. package/lib/chevre/service/offer/product.js +17 -7
  32. package/lib/chevre/service/offer.js +17 -7
  33. package/lib/chevre/service/order/confirmPayTransaction.js +17 -7
  34. package/lib/chevre/service/payment/any/authorize.js +17 -7
  35. package/lib/chevre/service/payment/any/processVoidPayTransaction.js +17 -7
  36. package/lib/chevre/service/payment/any/publishPaymentUrl.js +17 -7
  37. package/lib/chevre/service/payment/creditCard/authorize/handleAuthorizeError.js +1 -1
  38. package/lib/chevre/service/payment/movieTicket/payMovieTicket/processSeatInfoSync.js +1 -1
  39. package/lib/chevre/service/payment/movieTicket/refundMovieTicket/processSeatInfoSync.js +4 -4
  40. package/lib/chevre/service/payment/movieTicket/refundMovieTicket/processSeatInfoSyncCancel.js +1 -1
  41. package/lib/chevre/service/permit.js +17 -7
  42. package/lib/chevre/service/reserveCOA/cancelReservation.js +1 -1
  43. package/lib/chevre/service/task/aggregateScreeningEvent.js +17 -7
  44. package/lib/chevre/service/task/deletePerson.js +2 -25
  45. package/lib/chevre/service/task/deleteTransaction.js +17 -7
  46. package/lib/chevre/service/task/importEventCapacitiesFromCOA.js +17 -7
  47. package/lib/chevre/service/task/importEventsFromCOA.js +17 -7
  48. package/lib/chevre/service/task/importOffersFromCOA.js +17 -7
  49. package/lib/chevre/service/task/payment/invalidatePaymentUrlByTask.js +17 -7
  50. package/lib/chevre/service/task/payment/payByTask.js +21 -11
  51. package/lib/chevre/service/task/payment/refundByTask.js +21 -11
  52. package/lib/chevre/service/task/payment/voidPaymentByTask.js +21 -11
  53. package/lib/chevre/service/task/returnPayTransaction.js +17 -7
  54. package/lib/chevre/service/task/returnReserveTransaction.js +17 -7
  55. package/lib/chevre/service/task.js +2 -25
  56. package/lib/chevre/service/taskHandler.js +3 -26
  57. package/lib/chevre/service/transaction/returnOrder/preStart/getReturnPolicyByProject.js +5 -5
  58. package/lib/chevre/service/transaction.js +17 -7
  59. package/lib/chevre/service.d.ts +0 -4
  60. package/lib/chevre/service.js +33 -43
  61. package/lib/index.js +17 -7
  62. package/package.json +9 -14
  63. package/lib/chevre/pecorinoapi.d.ts +0 -5
  64. package/lib/chevre/pecorinoapi.js +0 -9
  65. package/lib/chevre/service/assetTransaction/moneyTransfer/potentialActions.d.ts +0 -7
  66. package/lib/chevre/service/assetTransaction/moneyTransfer/potentialActions.js +0 -104
  67. package/lib/chevre/service/assetTransaction/moneyTransfer.d.ts +0 -51
  68. package/lib/chevre/service/assetTransaction/moneyTransfer.js +0 -434
  69. package/lib/chevre/service/assetTransaction/pay/start/account/validation.d.ts +0 -8
  70. package/lib/chevre/service/assetTransaction/pay/start/account/validation.js +0 -43
  71. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeAccount.d.ts +0 -13
  72. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeAccount.js +0 -62
  73. package/lib/chevre/service/delivery.d.ts +0 -27
  74. package/lib/chevre/service/delivery.js +0 -305
  75. package/lib/chevre/service/moneyTransfer.d.ts +0 -76
  76. package/lib/chevre/service/moneyTransfer.js +0 -659
  77. package/lib/chevre/service/payment/paymentCard.d.ts +0 -42
  78. package/lib/chevre/service/payment/paymentCard.js +0 -442
  79. package/lib/chevre/service/task/cancelMoneyTransfer.d.ts +0 -6
  80. package/lib/chevre/service/task/cancelMoneyTransfer.js +0 -19
  81. package/lib/chevre/service/task/givePointAward.d.ts +0 -6
  82. package/lib/chevre/service/task/givePointAward.js +0 -55
  83. package/lib/chevre/service/task/moneyTransfer.d.ts +0 -6
  84. package/lib/chevre/service/task/moneyTransfer.js +0 -49
  85. package/lib/chevre/service/task/returnPointAward.d.ts +0 -6
  86. package/lib/chevre/service/task/returnPointAward.js +0 -55
@@ -1,305 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.givePointAward = givePointAward;
30
- exports.returnPointAward = returnPointAward;
31
- /**
32
- * 配送サービス
33
- * ここでいう「配送」とは、「エンドユーザーが獲得した所有権を利用可能な状態にすること」を指します。
34
- * 物理的なモノの配送だけに限らず、
35
- * 所有権コードを発行できること
36
- * 特典が口座に振り込まれること
37
- * などが配送処理として考えられます。
38
- */
39
- const moment_1 = __importDefault(require("moment"));
40
- const factory_1 = require("../factory");
41
- const MoneyTransferAssetTransactionService = __importStar(require("./assetTransaction/moneyTransfer"));
42
- const accountTransactionIdentifier_1 = require("../factory/accountTransactionIdentifier");
43
- /**
44
- * 特典付与
45
- */
46
- function givePointAward(params) {
47
- return async (repos) => {
48
- // 入金識別子が存在する場合、冪等性の確保(2023-08-24~)
49
- const pendingTransactionIdentifier = params.object.identifier;
50
- if (typeof pendingTransactionIdentifier === 'string' && pendingTransactionIdentifier.length > 0) {
51
- // すでにConfirmedのMoneyTransfer取引が存在すれば何もしない
52
- const assetTransactions = await repos.assetTransaction.search({
53
- limit: 1,
54
- project: { id: { $eq: params.project.id } },
55
- typeOf: factory_1.factory.assetTransactionType.MoneyTransfer,
56
- statuses: [factory_1.factory.transactionStatusType.Confirmed],
57
- object: {
58
- pendingTransaction: { identifier: { $eq: pendingTransactionIdentifier } }
59
- }
60
- }, ['_id']);
61
- if (assetTransactions.length > 0) {
62
- return;
63
- }
64
- }
65
- // アクション開始
66
- const action = await repos.action.start(params);
67
- try {
68
- const { transactionNumber } = await repos.transactionNumber.publishByTimestamp({ startDate: new Date() });
69
- const startParams = createGivePointAwardStartParams4moneyTransfer(params, transactionNumber);
70
- await MoneyTransferAssetTransactionService.start(startParams)(repos);
71
- await MoneyTransferAssetTransactionService.confirm({ transactionNumber })(repos);
72
- }
73
- catch (error) {
74
- try {
75
- await repos.action.giveUp({ typeOf: params.typeOf, id: action.id, error });
76
- }
77
- catch (__) {
78
- // 失敗したら仕方ない
79
- }
80
- throw error;
81
- }
82
- // アクション完了
83
- const actionResult = {};
84
- await repos.action.completeWithVoid({ typeOf: params.typeOf, id: action.id, result: actionResult });
85
- };
86
- }
87
- function createGivePointAwardStartParams4moneyTransfer(params, transactionNumber) {
88
- // Sellerに変更(2022-05-30~)
89
- const agent = {
90
- typeOf: params.agent.typeOf,
91
- id: params.agent.id,
92
- name: String(params.agent.name)
93
- };
94
- const recipient = {
95
- typeOf: params.recipient.typeOf,
96
- id: params.recipient.id,
97
- name: String(params.recipient.name)
98
- };
99
- const toLocation = {
100
- typeOf: factory_1.factory.permit.PermitType.Permit,
101
- identifier: params.object.toLocation.accountNumber,
102
- issuedThrough: { id: params.object.toLocation.issuedThrough?.id },
103
- hasNoPermit: false // Permitが存在するはず
104
- };
105
- return {
106
- transactionNumber: transactionNumber,
107
- project: { typeOf: params.project.typeOf, id: params.project.id },
108
- typeOf: factory_1.factory.assetTransactionType.MoneyTransfer,
109
- agent: agent,
110
- expires: (0, moment_1.default)()
111
- .add(1, 'minutes')
112
- .toDate(),
113
- recipient: recipient,
114
- object: {
115
- amount: {
116
- typeOf: 'MonetaryAmount',
117
- value: params.object.amount,
118
- currency: '' // サーバーサイドで自動取得される
119
- },
120
- description: (typeof params.object.description === 'string')
121
- ? params.object.description
122
- : params.purpose.typeOf,
123
- fromLocation: agent,
124
- toLocation,
125
- pendingTransaction: {
126
- typeOf: factory_1.factory.account.transactionType.Deposit,
127
- transactionNumber
128
- }
129
- },
130
- // ユニークネスを保証するために識別子を指定する
131
- ...(typeof params.object.identifier === 'string') ? { identifier: params.object.identifier } : undefined
132
- };
133
- }
134
- /**
135
- * 特典返却
136
- */
137
- function returnPointAward(params) {
138
- return async (repos) => {
139
- // アクション開始
140
- const moneyTransferTransactions = [];
141
- const action = await repos.action.start(params);
142
- try {
143
- const moenyTransferAssetTransactionIdentifier = params.object.identifier;
144
- const moenyTransferAssetTransactionFromLocationIdentifier = params.object
145
- .object?.fromLocation?.identifier;
146
- if (typeof moenyTransferAssetTransactionIdentifier === 'string') {
147
- moneyTransferTransactions.push(await processReturnPointAwardByTransactionIdentifier(params)(repos));
148
- }
149
- if (typeof moenyTransferAssetTransactionFromLocationIdentifier === 'string') {
150
- moneyTransferTransactions.push(...await processReturnPointAwardByTransactionFromLocationIdentifier(params)(repos));
151
- }
152
- }
153
- catch (error) {
154
- try {
155
- await repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error });
156
- }
157
- catch (__) {
158
- // 失敗したら仕方ない
159
- }
160
- throw error;
161
- }
162
- // アクション完了
163
- const actionResult = {
164
- moneyTransferTransaction: moneyTransferTransactions
165
- };
166
- await repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: actionResult });
167
- };
168
- }
169
- function processReturnPointAwardByTransactionIdentifier(params) {
170
- return async (repos) => {
171
- let moneyTransferTransaction;
172
- const moenyTransferAssetTransactionIdentifier = params.object.identifier;
173
- const assetTransactions = await repos.assetTransaction.search({
174
- limit: 1,
175
- project: { id: { $eq: params.project.id } },
176
- typeOf: factory_1.factory.assetTransactionType.MoneyTransfer,
177
- statuses: [factory_1.factory.transactionStatusType.Confirmed],
178
- object: {
179
- pendingTransaction: { identifier: { $eq: moenyTransferAssetTransactionIdentifier } }
180
- }
181
- });
182
- // 資産取引が存在すれば、出金取引を実行
183
- const depositTransaction = assetTransactions.shift();
184
- if (depositTransaction !== undefined) {
185
- const { transactionNumber } = await repos.transactionNumber.publishByTimestamp({ startDate: new Date() });
186
- // 冪等性の確保
187
- // 入金時の資産取引に対して一意な識別子をMoneyTransfer資産取引指定する
188
- const identifier2withdrawAssetTransaction = (0, accountTransactionIdentifier_1.createReturnPointAwardIdentifier)({
189
- project: { id: params.project.id },
190
- accountTransaction4givePointAward: { transactionNumber: depositTransaction.transactionNumber }
191
- });
192
- const fromLocation = {
193
- typeOf: depositTransaction.object.toLocation.typeOf,
194
- identifier: depositTransaction.object.toLocation.identifier,
195
- issuedThrough: depositTransaction.object.toLocation.issuedThrough,
196
- hasNoPermit: false // Permitが存在するはず
197
- };
198
- moneyTransferTransaction = await MoneyTransferAssetTransactionService.start({
199
- transactionNumber: transactionNumber,
200
- identifier: identifier2withdrawAssetTransaction,
201
- project: depositTransaction.project,
202
- typeOf: factory_1.factory.assetTransactionType.MoneyTransfer,
203
- expires: (0, moment_1.default)()
204
- .add(1, 'minute')
205
- .toDate(),
206
- // Sellerに変更(2022-05-30~)
207
- agent: {
208
- typeOf: params.recipient.typeOf,
209
- id: params.recipient.id,
210
- name: String(params.recipient.name)
211
- },
212
- recipient: depositTransaction.agent, // 入金と逆
213
- object: {
214
- amount: depositTransaction.object.amount,
215
- fromLocation,
216
- toLocation: depositTransaction.object.fromLocation,
217
- description: `[Return Award]${depositTransaction.object.description}`,
218
- pendingTransaction: {
219
- typeOf: factory_1.factory.account.transactionType.Withdraw,
220
- transactionNumber
221
- },
222
- force: true
223
- }
224
- })(repos);
225
- await MoneyTransferAssetTransactionService.confirm({ transactionNumber })(repos);
226
- }
227
- else {
228
- throw new factory_1.factory.errors.NotFound('AssetTransaction', `Deposit transaction '${moenyTransferAssetTransactionIdentifier}' not found`);
229
- }
230
- return moneyTransferTransaction;
231
- };
232
- }
233
- function processReturnPointAwardByTransactionFromLocationIdentifier(params) {
234
- return async (repos) => {
235
- const moneyTransferTransactions = [];
236
- const moenyTransferAssetTransactionFromLocationIdentifier = params.object
237
- .object?.fromLocation?.identifier;
238
- const assetTransactions = await repos.assetTransaction.search({
239
- // limit: 100,
240
- project: { id: { $eq: params.project.id } },
241
- typeOf: factory_1.factory.assetTransactionType.MoneyTransfer,
242
- statuses: [factory_1.factory.transactionStatusType.Confirmed],
243
- object: {
244
- fromLocation: { identifier: { $eq: moenyTransferAssetTransactionFromLocationIdentifier } }
245
- }
246
- });
247
- // 資産取引が存在すれば、逆の取引を実行
248
- if (assetTransactions.length > 0) {
249
- // 返却対象取引はTransfer取引(注文口座→Permit)のはず
250
- const returningTransactions = assetTransactions.filter((d) => d.object.pendingTransaction?.typeOf === factory_1.factory.account.transactionType.Transfer);
251
- for (const returningTransaction of returningTransactions) {
252
- const { transactionNumber } = await repos.transactionNumber.publishByTimestamp({ startDate: new Date() });
253
- // 冪等性の確保
254
- // 入金時の資産取引に対して一意な識別子をMoneyTransfer資産取引指定する
255
- const identifier2withdrawAssetTransaction = (0, accountTransactionIdentifier_1.createReturnPointAwardIdentifier)({
256
- project: { id: params.project.id },
257
- accountTransaction4givePointAward: { transactionNumber: returningTransaction.transactionNumber }
258
- });
259
- const fromLocation = {
260
- typeOf: returningTransaction.object.toLocation.typeOf,
261
- identifier: returningTransaction.object.toLocation.identifier,
262
- issuedThrough: returningTransaction.object.toLocation.issuedThrough,
263
- hasNoPermit: false // Permitが存在するはず
264
- };
265
- const toLocation = {
266
- typeOf: factory_1.factory.permit.PermitType.Permit,
267
- identifier: moenyTransferAssetTransactionFromLocationIdentifier,
268
- // ↓指定しないとPermitのチェックが実行される(注文口座にはPermitが存在しない)
269
- hasNoPermit: true,
270
- issuedThrough: { id: fromLocation.issuedThrough.id }
271
- };
272
- const moneyTransferTransaction = await MoneyTransferAssetTransactionService.start({
273
- transactionNumber: transactionNumber,
274
- identifier: identifier2withdrawAssetTransaction,
275
- project: returningTransaction.project,
276
- typeOf: factory_1.factory.assetTransactionType.MoneyTransfer,
277
- expires: (0, moment_1.default)()
278
- .add(1, 'minute')
279
- .toDate(),
280
- // Sellerに変更(2022-05-30~)
281
- agent: {
282
- typeOf: params.recipient.typeOf,
283
- id: params.recipient.id,
284
- name: String(params.recipient.name)
285
- },
286
- recipient: returningTransaction.agent, // 入金と逆
287
- object: {
288
- amount: returningTransaction.object.amount,
289
- fromLocation,
290
- toLocation,
291
- description: `[Return Award]${returningTransaction.object.description}`,
292
- pendingTransaction: {
293
- typeOf: factory_1.factory.account.transactionType.Transfer,
294
- transactionNumber
295
- },
296
- force: true
297
- }
298
- })(repos);
299
- await MoneyTransferAssetTransactionService.confirm({ transactionNumber })(repos);
300
- moneyTransferTransactions.push(moneyTransferTransaction);
301
- }
302
- }
303
- return moneyTransferTransactions;
304
- };
305
- }
@@ -1,76 +0,0 @@
1
- import { factory } from '../factory';
2
- import type { ActionRepo } from '../repo/action';
3
- import type { AssetTransactionRepo } from '../repo/assetTransaction';
4
- import type { ProductRepo } from '../repo/product';
5
- import type { ProjectRepo } from '../repo/project';
6
- import type { TransactionNumberRepo } from '../repo/transactionNumber';
7
- export type IAuthorizeOperation<T> = (repos: {
8
- product: ProductRepo;
9
- project: ProjectRepo;
10
- assetTransaction: AssetTransactionRepo;
11
- }) => Promise<T>;
12
- export interface IObject {
13
- amount: number;
14
- description?: string;
15
- fromLocation: {
16
- identifier?: string;
17
- hasNoPermit?: boolean;
18
- issuedThrough?: {
19
- /**
20
- * カード発行サービスID
21
- */
22
- id: string;
23
- };
24
- };
25
- toLocation: {
26
- identifier?: string;
27
- hasNoPermit?: boolean;
28
- issuedThrough?: {
29
- /**
30
- * カード発行サービスID
31
- */
32
- id: string;
33
- };
34
- };
35
- force: boolean;
36
- }
37
- /**
38
- * 口座残高差し押さえ
39
- */
40
- export declare function authorize(params: {
41
- typeOf: factory.account.transactionType;
42
- identifier?: string;
43
- transactionNumber: string;
44
- project: {
45
- id: string;
46
- typeOf: factory.organizationType.Project;
47
- };
48
- agent: factory.action.transfer.moneyTransfer.IAgent;
49
- object: IObject;
50
- recipient: factory.action.transfer.moneyTransfer.IRecipient;
51
- purpose: {
52
- typeOf: factory.assetTransactionType;
53
- id: string;
54
- };
55
- }): IAuthorizeOperation<void>;
56
- /**
57
- * 口座承認取消
58
- */
59
- export declare function cancelMoneyTransfer(params: {
60
- purpose: {
61
- typeOf: factory.assetTransactionType;
62
- id: string;
63
- };
64
- }): (repos: {
65
- product: ProductRepo;
66
- assetTransaction: AssetTransactionRepo;
67
- }) => Promise<void>;
68
- export declare function moneyTransfer(params: factory.task.moneyTransfer.IData): (repos: {
69
- action: ActionRepo;
70
- product: ProductRepo;
71
- transactionNumber: TransactionNumberRepo;
72
- }) => Promise<void>;
73
- /**
74
- * 返金後のアクション
75
- * @param refundActionAttributes 返金アクション属性
76
- */