@chevre/domain 24.0.0-alpha.78 → 24.0.0-alpha.79
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.
- package/lib/chevre/repo/action/actionProcess.d.ts +3 -3
- package/lib/chevre/repo/action/authorizeOffer.d.ts +2 -3
- package/lib/chevre/repo/action/authorizeOffer.js +2 -2
- package/lib/chevre/repo/action.d.ts +2 -2
- package/lib/chevre/repo/assetTransaction.d.ts +3 -27
- package/lib/chevre/repo/assetTransaction.js +21 -21
- package/lib/chevre/repo/mongoose/schemas/assetTransaction.d.ts +1 -1
- package/lib/chevre/repo/task.d.ts +1 -1
- package/lib/chevre/repository.d.ts +0 -5
- package/lib/chevre/repository.js +0 -11
- package/lib/chevre/service/assetTransaction.d.ts +0 -2
- package/lib/chevre/service/assetTransaction.js +8 -10
- package/lib/chevre/service/delivery/factory.js +13 -13
- package/lib/chevre/service/offer/any.d.ts +1 -1
- package/lib/chevre/service/offer/product.d.ts +0 -62
- package/lib/chevre/service/offer/product.js +0 -409
- package/lib/chevre/service/order/onAssetTransactionStatusChanged/isDeliverable.d.ts +1 -1
- package/lib/chevre/service/order/onAssetTransactionStatusChanged/isDeliverable.js +22 -18
- package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +20 -20
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.d.ts +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.d.ts +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +2 -96
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.d.ts +1 -1
- package/lib/chevre/service/order/placeOrder/factory/orderedItem.d.ts +0 -1
- package/lib/chevre/service/order/placeOrder/factory/orderedItem.js +3 -28
- package/lib/chevre/service/order/placeOrder/factory.js +5 -5
- package/lib/chevre/service/transaction/placeOrder/confirm/validation/factory.d.ts +0 -1
- package/lib/chevre/service/transaction/placeOrder/confirm/validation/validatePrice.d.ts +2 -2
- package/lib/chevre/service/transaction/placeOrder/confirm/validation/validatePrice.js +2 -2
- package/lib/chevre/service/transaction/placeOrder/confirm/validation.d.ts +3 -3
- package/lib/chevre/service/transaction/placeOrder/confirm/validation.js +4 -2
- package/lib/chevre/service/transaction/placeOrder/confirm.js +21 -23
- package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +0 -21
- package/lib/chevre/service/validation/validateOrder.js +11 -10
- package/package.json +2 -2
- package/lib/chevre/repo/action/authorizeProductOffer.d.ts +0 -26
- package/lib/chevre/repo/action/authorizeProductOffer.js +0 -32
- package/lib/chevre/service/assetTransaction/registerService/factory.d.ts +0 -14
- package/lib/chevre/service/assetTransaction/registerService/factory.js +0 -140
- package/lib/chevre/service/assetTransaction/registerService/potentialActions.d.ts +0 -8
- package/lib/chevre/service/assetTransaction/registerService/potentialActions.js +0 -120
- package/lib/chevre/service/assetTransaction/registerService.d.ts +0 -54
- package/lib/chevre/service/assetTransaction/registerService.js +0 -274
- package/lib/chevre/service/delivery/product/factory.d.ts +0 -13
- package/lib/chevre/service/delivery/product/factory.js +0 -81
- package/lib/chevre/service/offer/product/factory.d.ts +0 -37
- package/lib/chevre/service/offer/product/factory.js +0 -208
- package/lib/chevre/service/task/confirmRegisterService.d.ts +0 -6
- package/lib/chevre/service/task/confirmRegisterService.js +0 -19
- package/lib/chevre/service/task/confirmRegisterServiceTransaction.d.ts +0 -17
- package/lib/chevre/service/task/confirmRegisterServiceTransaction.js +0 -116
- package/lib/chevre/service/task/voidRegisterServiceTransaction.d.ts +0 -6
- package/lib/chevre/service/task/voidRegisterServiceTransaction.js +0 -23
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createServiceOutput = createServiceOutput;
|
|
7
|
-
const moment_1 = __importDefault(require("moment"));
|
|
8
|
-
const factory_1 = require("../../../factory");
|
|
9
|
-
/**
|
|
10
|
-
* サービスアウトプットを作成する
|
|
11
|
-
*/
|
|
12
|
-
function createServiceOutput(params) {
|
|
13
|
-
const product = params.product;
|
|
14
|
-
const acceptedOffer = params.acceptedOffer;
|
|
15
|
-
const serviceOutputType = product.serviceOutput?.typeOf;
|
|
16
|
-
if (typeof serviceOutputType !== 'string' || serviceOutputType.length === 0) {
|
|
17
|
-
throw new factory_1.factory.errors.NotFound('Product serviceOutput type undefined');
|
|
18
|
-
}
|
|
19
|
-
const identifier = acceptedOffer.itemOffered?.serviceOutput?.identifier;
|
|
20
|
-
if (typeof identifier !== 'string' || identifier.length === 0) {
|
|
21
|
-
throw new factory_1.factory.errors.ArgumentNull('object.itemOffered.serviceOutput.identifier');
|
|
22
|
-
}
|
|
23
|
-
const accessCode = acceptedOffer.itemOffered?.serviceOutput?.accessCode;
|
|
24
|
-
const name = acceptedOffer.itemOffered?.serviceOutput?.name;
|
|
25
|
-
const additionalProperty = acceptedOffer.itemOffered?.serviceOutput?.additionalProperty;
|
|
26
|
-
const issuedBy = acceptedOffer.itemOffered?.serviceOutput?.issuedBy;
|
|
27
|
-
const { amount, depositAmount, paymentAmount } = createServiceOutputMonetaryAmount({ product, offer: params.offer });
|
|
28
|
-
const validFor = offer2validFor({ offer: params.offer });
|
|
29
|
-
// 決済口座
|
|
30
|
-
let paymentAccount;
|
|
31
|
-
switch (product.typeOf) {
|
|
32
|
-
case factory_1.factory.product.ProductType.PaymentCard:
|
|
33
|
-
if (typeof accessCode !== 'string' || accessCode.length === 0) {
|
|
34
|
-
throw new factory_1.factory.errors.ArgumentNull('object.itemOffered.serviceOutput.accessCode');
|
|
35
|
-
}
|
|
36
|
-
paymentAccount = {
|
|
37
|
-
// 廃止(2023-02-20~)
|
|
38
|
-
// project: { typeOf: product.project.typeOf, id: product.project.id },
|
|
39
|
-
// ひとまず固定
|
|
40
|
-
// 口座は複数のプロダクトに結合する可能性もあり、どのように利用されるかは知らない。ただbalanceを管理するだけ。通貨は知っている。
|
|
41
|
-
typeOf: factory_1.factory.accountType.Account,
|
|
42
|
-
// ひとまずPermit識別子と口座番号は同一
|
|
43
|
-
accountNumber: identifier
|
|
44
|
-
// 廃止(2023-02-16~)
|
|
45
|
-
// accountType: amount.currency
|
|
46
|
-
};
|
|
47
|
-
break;
|
|
48
|
-
case factory_1.factory.product.ProductType.MembershipService:
|
|
49
|
-
break;
|
|
50
|
-
// case 'MoneyTransfer':
|
|
51
|
-
default:
|
|
52
|
-
throw new factory_1.factory.errors.NotImplemented(`Product type ${product.typeOf} not implemented`);
|
|
53
|
-
}
|
|
54
|
-
const issuedThrough = {
|
|
55
|
-
// 廃止(2023-02-20~)
|
|
56
|
-
// project: { typeOf: product.project.typeOf, id: product.project.id },
|
|
57
|
-
typeOf: product.typeOf,
|
|
58
|
-
id: product.id,
|
|
59
|
-
...(typeof product.serviceType?.typeOf === 'string') ? { serviceType: product.serviceType } : undefined
|
|
60
|
-
};
|
|
61
|
-
return {
|
|
62
|
-
project: { typeOf: product.project.typeOf, id: product.project.id },
|
|
63
|
-
identifier: identifier,
|
|
64
|
-
issuedThrough,
|
|
65
|
-
typeOf: serviceOutputType,
|
|
66
|
-
dateIssued: params.dateIssued,
|
|
67
|
-
...(typeof accessCode === 'string') ? { accessCode } : undefined,
|
|
68
|
-
...(Array.isArray(additionalProperty)) ? { additionalProperty } : undefined,
|
|
69
|
-
...(typeof validFor === 'string') ? { validFor } : undefined,
|
|
70
|
-
...(name !== undefined) ? { name } : undefined,
|
|
71
|
-
...(amount !== undefined) ? { amount } : undefined,
|
|
72
|
-
...(depositAmount !== undefined) ? { depositAmount } : undefined,
|
|
73
|
-
...(paymentAmount !== undefined) ? { paymentAmount } : undefined,
|
|
74
|
-
...(paymentAccount !== undefined) ? { paymentAccount } : undefined,
|
|
75
|
-
...(issuedBy !== undefined) ? { issuedBy } : undefined
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
function createServiceOutputMonetaryAmount(params) {
|
|
79
|
-
const product = params.product;
|
|
80
|
-
const currency = (typeof product.serviceOutput?.amount?.currency === 'string')
|
|
81
|
-
? product.serviceOutput?.amount.currency
|
|
82
|
-
: factory_1.factory.priceCurrency.JPY;
|
|
83
|
-
// 初期金額
|
|
84
|
-
const amount = {
|
|
85
|
-
...product.serviceOutput?.amount,
|
|
86
|
-
...params.offer.itemOffered?.serviceOutput?.amount,
|
|
87
|
-
currency,
|
|
88
|
-
typeOf: 'MonetaryAmount'
|
|
89
|
-
};
|
|
90
|
-
// 入金設定
|
|
91
|
-
const depositAmount = {
|
|
92
|
-
// ...product.serviceOutput?.depositAmount,
|
|
93
|
-
...params.offer.itemOffered?.serviceOutput?.depositAmount,
|
|
94
|
-
currency,
|
|
95
|
-
typeOf: 'MonetaryAmount'
|
|
96
|
-
};
|
|
97
|
-
// 取引設定
|
|
98
|
-
const paymentAmount = {
|
|
99
|
-
// ...product.serviceOutput?.paymentAmount,
|
|
100
|
-
...params.offer.itemOffered?.serviceOutput?.paymentAmount,
|
|
101
|
-
currency,
|
|
102
|
-
typeOf: 'MonetaryAmount'
|
|
103
|
-
};
|
|
104
|
-
return { amount, depositAmount, paymentAmount };
|
|
105
|
-
}
|
|
106
|
-
function offer2validFor(params) {
|
|
107
|
-
let validFor;
|
|
108
|
-
// オファーからアウトプットの有効期間を決定
|
|
109
|
-
const unitPriceSpec = params.offer.priceSpecification.priceComponent.find((c) => c.typeOf === factory_1.factory.priceSpecificationType.UnitPriceSpecification);
|
|
110
|
-
if (unitPriceSpec === undefined) {
|
|
111
|
-
throw new factory_1.factory.errors.NotFound(`UnitPriceSpecification for ${params.offer.id}`);
|
|
112
|
-
}
|
|
113
|
-
// unitPriceSpec.referenceQuantity.value: 'Infinity'に対応
|
|
114
|
-
const referenceQuantityValue = unitPriceSpec.referenceQuantity.value;
|
|
115
|
-
if (referenceQuantityValue === factory_1.factory.quantitativeValue.StringValue.Infinity) {
|
|
116
|
-
// Infinityの場合validForはundefined
|
|
117
|
-
}
|
|
118
|
-
else if (typeof referenceQuantityValue === 'number') {
|
|
119
|
-
switch (unitPriceSpec.referenceQuantity.unitCode) {
|
|
120
|
-
case factory_1.factory.unitCode.Ann:
|
|
121
|
-
validFor = moment_1.default.duration(referenceQuantityValue, 'years')
|
|
122
|
-
.toISOString();
|
|
123
|
-
break;
|
|
124
|
-
case factory_1.factory.unitCode.Day:
|
|
125
|
-
validFor = moment_1.default.duration(referenceQuantityValue, 'days')
|
|
126
|
-
.toISOString();
|
|
127
|
-
break;
|
|
128
|
-
case factory_1.factory.unitCode.Sec:
|
|
129
|
-
validFor = moment_1.default.duration(referenceQuantityValue, 'seconds')
|
|
130
|
-
.toISOString();
|
|
131
|
-
break;
|
|
132
|
-
default:
|
|
133
|
-
throw new factory_1.factory.errors.NotImplemented(`Reference quantity unit code '${unitPriceSpec.referenceQuantity.unitCode}' not implemented`);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
throw new factory_1.factory.errors.NotImplemented(`Reference quantity value '${referenceQuantityValue}' not implemented`);
|
|
138
|
-
}
|
|
139
|
-
return validFor;
|
|
140
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { factory } from '../../../factory';
|
|
2
|
-
/**
|
|
3
|
-
* 取引のポストアクションを作成する
|
|
4
|
-
*/
|
|
5
|
-
export declare function createPotentialActions(params: {
|
|
6
|
-
transaction: factory.assetTransaction.ITransaction<factory.assetTransactionType.RegisterService>;
|
|
7
|
-
endDate?: Date;
|
|
8
|
-
}): Promise<factory.assetTransaction.IPotentialActions<factory.assetTransactionType.RegisterService>>;
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createPotentialActions = createPotentialActions;
|
|
7
|
-
const moment_1 = __importDefault(require("moment"));
|
|
8
|
-
const factory_1 = require("../../../factory");
|
|
9
|
-
const MAX_VALID_UNTIL = '3000-01-01T00:00:00Z';
|
|
10
|
-
function createRegisterServiceActions(params) {
|
|
11
|
-
const validFrom = (params.endDate instanceof Date) ? params.endDate : new Date();
|
|
12
|
-
return params.transaction.object.map((o) => {
|
|
13
|
-
// const pointAward = o.itemOffered.pointAward;
|
|
14
|
-
const serviceOutput = o.itemOffered.serviceOutput;
|
|
15
|
-
// validFor:undefinedに対応
|
|
16
|
-
let validUntil;
|
|
17
|
-
if (typeof serviceOutput?.validFor === 'string') {
|
|
18
|
-
// オファーの単価単位で有効期限を決定
|
|
19
|
-
validUntil = (0, moment_1.default)(validFrom)
|
|
20
|
-
.add(moment_1.default.duration(serviceOutput.validFor))
|
|
21
|
-
.toDate();
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
validUntil = (0, moment_1.default)(MAX_VALID_UNTIL)
|
|
25
|
-
.toDate();
|
|
26
|
-
}
|
|
27
|
-
// const moneyTransfer: factory.action.transfer.moneyTransfer.IAttributes[] = [];
|
|
28
|
-
// // ポイント特典があれば適用
|
|
29
|
-
// const pointAwardToLocationIdentifier = pointAward?.toLocation?.identifier;
|
|
30
|
-
// const pointAwardToLocationTypeOf = pointAward?.toLocation?.typeOf;
|
|
31
|
-
// if (typeof pointAward?.amount?.value === 'number'
|
|
32
|
-
// && typeof pointAwardToLocationIdentifier === 'string'
|
|
33
|
-
// && typeof pointAwardToLocationTypeOf === 'string'
|
|
34
|
-
// ) {
|
|
35
|
-
// const fromLocation: factory.action.transfer.moneyTransfer.IAnonymousLocation = {
|
|
36
|
-
// typeOf: (typeof serviceOutput?.issuedBy?.typeOf === 'string')
|
|
37
|
-
// ? serviceOutput?.issuedBy?.typeOf
|
|
38
|
-
// : params.transaction.typeOf,
|
|
39
|
-
// name: (serviceOutput?.issuedBy?.name !== undefined)
|
|
40
|
-
// ? (typeof serviceOutput?.issuedBy?.name === 'string')
|
|
41
|
-
// ? serviceOutput?.issuedBy?.name
|
|
42
|
-
// : serviceOutput?.issuedBy?.name.ja
|
|
43
|
-
// : params.transaction.id
|
|
44
|
-
// };
|
|
45
|
-
// const toLocation: factory.action.transfer.moneyTransfer.IPaymentCard = {
|
|
46
|
-
// identifier: pointAwardToLocationIdentifier,
|
|
47
|
-
// typeOf: factory.permit.PermitType.Permit,
|
|
48
|
-
// issuedThrough: { id: String(pointAward.toLocation?.issuedThrough?.id) }
|
|
49
|
-
// };
|
|
50
|
-
// const recipient: factory.action.transfer.moneyTransfer.IRecipient = {
|
|
51
|
-
// typeOf: factory.personType.Person,
|
|
52
|
-
// id: '',
|
|
53
|
-
// name: String(fromLocation)
|
|
54
|
-
// };
|
|
55
|
-
// moneyTransfer.push({
|
|
56
|
-
// project: params.transaction.project,
|
|
57
|
-
// typeOf: factory.actionType.MoneyTransfer,
|
|
58
|
-
// agent: params.transaction.project,
|
|
59
|
-
// recipient,
|
|
60
|
-
// object: {
|
|
61
|
-
// typeOf: factory.account.transactionType.Deposit
|
|
62
|
-
// },
|
|
63
|
-
// purpose: {
|
|
64
|
-
// typeOf: params.transaction.typeOf,
|
|
65
|
-
// id: params.transaction.id,
|
|
66
|
-
// // 入金取引に識別子を指定する
|
|
67
|
-
// ...(typeof pointAward.purpose?.identifier === 'string') ? { identifier: pointAward.purpose.identifier } : undefined
|
|
68
|
-
// },
|
|
69
|
-
// amount: {
|
|
70
|
-
// typeOf: 'MonetaryAmount',
|
|
71
|
-
// value: pointAward.amount?.value,
|
|
72
|
-
// currency: pointAward.amount?.currency
|
|
73
|
-
// },
|
|
74
|
-
// fromLocation: fromLocation,
|
|
75
|
-
// toLocation: toLocation,
|
|
76
|
-
// ...(typeof pointAward.description === 'string') ? { description: pointAward.description } : undefined,
|
|
77
|
-
// ...(pointAward.recipient !== undefined) ? { recipient: pointAward.recipient } : undefined
|
|
78
|
-
// });
|
|
79
|
-
// }
|
|
80
|
-
const object = {
|
|
81
|
-
...serviceOutput,
|
|
82
|
-
validFrom: validFrom,
|
|
83
|
-
validUntil: validUntil
|
|
84
|
-
};
|
|
85
|
-
return {
|
|
86
|
-
project: params.transaction.project,
|
|
87
|
-
typeOf: factory_1.factory.actionType.RegisterAction,
|
|
88
|
-
result: {},
|
|
89
|
-
object,
|
|
90
|
-
// プロジェクトに変更(2022-05-26~)
|
|
91
|
-
// agent: <factory.creativeWork.softwareApplication.webApplication.ICreativeWork | factory.person.IPerson>params.transaction.agent,
|
|
92
|
-
agent: params.transaction.project,
|
|
93
|
-
potentialActions: {
|
|
94
|
-
// discontinue(2026-04-18~)
|
|
95
|
-
// moneyTransfer: moneyTransfer
|
|
96
|
-
},
|
|
97
|
-
purpose: {
|
|
98
|
-
typeOf: params.transaction.typeOf,
|
|
99
|
-
id: params.transaction.id
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* 取引のポストアクションを作成する
|
|
106
|
-
*/
|
|
107
|
-
async function createPotentialActions(params) {
|
|
108
|
-
// 通貨転送アクション属性作成
|
|
109
|
-
// const moneyTransferActionAttributesList = createMoneyTransferActions(params);
|
|
110
|
-
// // まずは1転送アクションのみ対応
|
|
111
|
-
// if (moneyTransferActionAttributesList.length > 1) {
|
|
112
|
-
// throw new factory.errors.Argument('Transaction', 'Number of moneyTransfer actions must be 1');
|
|
113
|
-
// }
|
|
114
|
-
const registerServiceActionAttributes = createRegisterServiceActions(params);
|
|
115
|
-
return {
|
|
116
|
-
// discontinue(2026-04-18~)
|
|
117
|
-
// moneyTransfer: moneyTransferActionAttributesList,
|
|
118
|
-
registerService: registerServiceActionAttributes
|
|
119
|
-
};
|
|
120
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* サービス登録取引サービス
|
|
3
|
-
*/
|
|
4
|
-
import { factory } from '../../factory';
|
|
5
|
-
import type { AccountRepo } from '../../repo/account';
|
|
6
|
-
import type { AssetTransactionRepo } from '../../repo/assetTransaction';
|
|
7
|
-
import type { OfferRepo } from '../../repo/offer/unitPriceInCatalog';
|
|
8
|
-
import type { OfferCatalogRepo } from '../../repo/offerCatalog';
|
|
9
|
-
import type { ProductRepo } from '../../repo/product';
|
|
10
|
-
import type { ProjectRepo } from '../../repo/project';
|
|
11
|
-
import type { ServiceOutputRepo } from '../../repo/serviceOutput';
|
|
12
|
-
import type { TaskRepo } from '../../repo/task';
|
|
13
|
-
export type IStartOperation<T> = (repos: {
|
|
14
|
-
account: AccountRepo;
|
|
15
|
-
offer: OfferRepo;
|
|
16
|
-
offerCatalog: OfferCatalogRepo;
|
|
17
|
-
product: ProductRepo;
|
|
18
|
-
serviceOutput: ServiceOutputRepo;
|
|
19
|
-
project: ProjectRepo;
|
|
20
|
-
assetTransaction: AssetTransactionRepo;
|
|
21
|
-
}) => Promise<T>;
|
|
22
|
-
export type ICancelOperation<T> = (repos: {
|
|
23
|
-
assetTransaction: AssetTransactionRepo;
|
|
24
|
-
}) => Promise<T>;
|
|
25
|
-
export type IConfirmOperation<T> = (repos: {
|
|
26
|
-
assetTransaction: AssetTransactionRepo;
|
|
27
|
-
}) => Promise<T>;
|
|
28
|
-
export type IExportTasksOperation<T> = (repos: {
|
|
29
|
-
task: TaskRepo;
|
|
30
|
-
assetTransaction: AssetTransactionRepo;
|
|
31
|
-
}) => Promise<T>;
|
|
32
|
-
/**
|
|
33
|
-
* 取引開始
|
|
34
|
-
*/
|
|
35
|
-
export declare function start(params: factory.assetTransaction.registerService.IStartParamsWithoutDetail): IStartOperation<factory.assetTransaction.ITransaction<factory.assetTransactionType.RegisterService>>;
|
|
36
|
-
/**
|
|
37
|
-
* 取引確定
|
|
38
|
-
*/
|
|
39
|
-
export declare function confirm(params: factory.assetTransaction.registerService.IConfirmParams): IConfirmOperation<void>;
|
|
40
|
-
/**
|
|
41
|
-
* 取引中止
|
|
42
|
-
*/
|
|
43
|
-
export declare function cancel(params: {
|
|
44
|
-
id?: string;
|
|
45
|
-
transactionNumber?: string;
|
|
46
|
-
}): ICancelOperation<void>;
|
|
47
|
-
/**
|
|
48
|
-
* 取引タスク出力
|
|
49
|
-
*/
|
|
50
|
-
export declare function exportTasksById(params: {
|
|
51
|
-
id: string;
|
|
52
|
-
}): IExportTasksOperation<{
|
|
53
|
-
id: string;
|
|
54
|
-
}[]>;
|
|
@@ -1,274 +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 () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.start = start;
|
|
37
|
-
exports.confirm = confirm;
|
|
38
|
-
exports.cancel = cancel;
|
|
39
|
-
exports.exportTasksById = exportTasksById;
|
|
40
|
-
/**
|
|
41
|
-
* サービス登録取引サービス
|
|
42
|
-
*/
|
|
43
|
-
const factory_1 = require("../../factory");
|
|
44
|
-
const searchProductOffers_1 = require("../offer/product/searchProductOffers");
|
|
45
|
-
const factory_2 = require("./registerService/factory");
|
|
46
|
-
const potentialActions_1 = require("./registerService/potentialActions");
|
|
47
|
-
// import * as AccountService from '../account';
|
|
48
|
-
const PermitService = __importStar(require("../permit"));
|
|
49
|
-
/**
|
|
50
|
-
* 取引開始
|
|
51
|
-
*/
|
|
52
|
-
function start(params) {
|
|
53
|
-
return async (repos) => {
|
|
54
|
-
const project = await repos.project.findById({
|
|
55
|
-
id: params.project.id,
|
|
56
|
-
inclusion: ['typeOf']
|
|
57
|
-
});
|
|
58
|
-
// objectはオファー
|
|
59
|
-
let acceptedOffers = params.object;
|
|
60
|
-
if (!Array.isArray(acceptedOffers)) {
|
|
61
|
-
acceptedOffers = [acceptedOffers];
|
|
62
|
-
}
|
|
63
|
-
const productIds = [...new Set(acceptedOffers.map((o) => String(o.itemOffered.id)))];
|
|
64
|
-
if (productIds.length !== 1) {
|
|
65
|
-
throw new factory_1.factory.errors.Argument('object.itemOffered.id', 'Number of product ID must be 1');
|
|
66
|
-
}
|
|
67
|
-
const productId = productIds[0];
|
|
68
|
-
if (typeof productId !== 'string') {
|
|
69
|
-
throw new factory_1.factory.errors.ArgumentNull('object.itemOffered.id');
|
|
70
|
-
}
|
|
71
|
-
// プロダクト確認
|
|
72
|
-
const product = (await repos.product.projectFields({
|
|
73
|
-
limit: 1,
|
|
74
|
-
page: 1,
|
|
75
|
-
id: { $eq: productId }
|
|
76
|
-
}, ['id', 'project', 'serviceOutput', 'serviceType', 'typeOf']
|
|
77
|
-
// []
|
|
78
|
-
)).shift();
|
|
79
|
-
if (product === undefined) {
|
|
80
|
-
throw new factory_1.factory.errors.NotFound('Product');
|
|
81
|
-
}
|
|
82
|
-
if (product.typeOf !== factory_1.factory.product.ProductType.MembershipService
|
|
83
|
-
&& product.typeOf !== factory_1.factory.product.ProductType.PaymentCard) {
|
|
84
|
-
throw new factory_1.factory.errors.Argument('object.itemOffered.id', `invalid product type: ${product.typeOf}`);
|
|
85
|
-
}
|
|
86
|
-
const transactionNumber = params.transactionNumber;
|
|
87
|
-
if (typeof transactionNumber !== 'string' || transactionNumber.length === 0) {
|
|
88
|
-
throw new factory_1.factory.errors.ArgumentNull('transactionNumber');
|
|
89
|
-
}
|
|
90
|
-
// サービスアウトプット作成
|
|
91
|
-
const dateIssued = new Date();
|
|
92
|
-
const transactionObject = await createTransactionObject({
|
|
93
|
-
acceptedOffers,
|
|
94
|
-
dateIssued,
|
|
95
|
-
product,
|
|
96
|
-
project: { id: project.id },
|
|
97
|
-
transactionNumber
|
|
98
|
-
})(repos);
|
|
99
|
-
// 取引開始
|
|
100
|
-
const startParams = {
|
|
101
|
-
project: { typeOf: project.typeOf, id: project.id },
|
|
102
|
-
typeOf: factory_1.factory.assetTransactionType.RegisterService,
|
|
103
|
-
agent: params.agent,
|
|
104
|
-
object: transactionObject,
|
|
105
|
-
expires: params.expires,
|
|
106
|
-
transactionNumber: transactionNumber
|
|
107
|
-
};
|
|
108
|
-
// 取引作成
|
|
109
|
-
const transaction = await repos.assetTransaction.start(startParams);
|
|
110
|
-
// 必要あれば在庫確認など
|
|
111
|
-
const serviceOutputs = transactionObject.map((o) => o.itemOffered?.serviceOutput);
|
|
112
|
-
// サービスアウトプット保管
|
|
113
|
-
await PermitService.issue({
|
|
114
|
-
project: { id: project.id },
|
|
115
|
-
issuedThrough: { typeOf: product.typeOf },
|
|
116
|
-
serviceOutputs
|
|
117
|
-
})(repos);
|
|
118
|
-
return transaction;
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
function createTransactionObject(params) {
|
|
122
|
-
return async (repos) => {
|
|
123
|
-
// オファー検索
|
|
124
|
-
const offers = await (0, searchProductOffers_1.searchProductOffers)({
|
|
125
|
-
ids: params.acceptedOffers.map((o) => o.id),
|
|
126
|
-
itemOffered: { id: String(params.product.id) },
|
|
127
|
-
onlyValid: true,
|
|
128
|
-
includedInDataCatalog: { id: '' }, // 承認時はカタログ指定の必要なし
|
|
129
|
-
addSortIndex: false,
|
|
130
|
-
useIncludeInDataCatalog: false
|
|
131
|
-
})(repos);
|
|
132
|
-
const transactionObject = [];
|
|
133
|
-
for (const acceptedOffer of params.acceptedOffers) {
|
|
134
|
-
const offer = offers.find((o) => o.id === acceptedOffer.id);
|
|
135
|
-
if (offer === undefined) {
|
|
136
|
-
throw new factory_1.factory.errors.NotFound('Offer', `Offer ${acceptedOffer.id} not found`);
|
|
137
|
-
}
|
|
138
|
-
// discontinue(2026-04-17~)
|
|
139
|
-
// await validatePointAward({ project: { id: params.project.id }, acceptedOffer })(repos);
|
|
140
|
-
// const pointAward = createPointAward({
|
|
141
|
-
// acceptedOffer: acceptedOffer,
|
|
142
|
-
// offer: offer
|
|
143
|
-
// });
|
|
144
|
-
const serviceOutput = (0, factory_2.createServiceOutput)({
|
|
145
|
-
dateIssued: params.dateIssued,
|
|
146
|
-
product: params.product,
|
|
147
|
-
acceptedOffer: acceptedOffer,
|
|
148
|
-
offer: offer,
|
|
149
|
-
transactionNumber: params.transactionNumber
|
|
150
|
-
});
|
|
151
|
-
transactionObject.push({
|
|
152
|
-
typeOf: factory_1.factory.offerType.Offer,
|
|
153
|
-
id: String(offer.id),
|
|
154
|
-
itemOffered: {
|
|
155
|
-
// project: params.product.project,
|
|
156
|
-
typeOf: params.product.typeOf,
|
|
157
|
-
id: String(params.product.id),
|
|
158
|
-
serviceOutput: serviceOutput,
|
|
159
|
-
// discontinue(2026-04-18~)
|
|
160
|
-
// ...(pointAward !== undefined) ? { pointAward } : undefined
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
return transactionObject;
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* 取引確定
|
|
169
|
-
*/
|
|
170
|
-
function confirm(params) {
|
|
171
|
-
return async (repos) => {
|
|
172
|
-
let transaction;
|
|
173
|
-
// 取引存在確認
|
|
174
|
-
if (typeof params.id === 'string') {
|
|
175
|
-
transaction = await repos.assetTransaction.findById({
|
|
176
|
-
typeOf: factory_1.factory.assetTransactionType.RegisterService,
|
|
177
|
-
id: params.id
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
else if (typeof params.transactionNumber === 'string') {
|
|
181
|
-
transaction = await repos.assetTransaction.findByTransactionNumber({
|
|
182
|
-
typeOf: factory_1.factory.assetTransactionType.RegisterService,
|
|
183
|
-
transactionNumber: params.transactionNumber
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
throw new factory_1.factory.errors.ArgumentNull('Transaction ID or Transaction Number');
|
|
188
|
-
}
|
|
189
|
-
const potentialActions = await (0, potentialActions_1.createPotentialActions)({
|
|
190
|
-
transaction: transaction,
|
|
191
|
-
endDate: params.endDate
|
|
192
|
-
});
|
|
193
|
-
// 取引確定
|
|
194
|
-
const result = {};
|
|
195
|
-
await repos.assetTransaction.confirm({
|
|
196
|
-
typeOf: factory_1.factory.assetTransactionType.RegisterService,
|
|
197
|
-
id: transaction.id,
|
|
198
|
-
result: result,
|
|
199
|
-
potentialActions: potentialActions
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* 取引中止
|
|
205
|
-
*/
|
|
206
|
-
function cancel(params) {
|
|
207
|
-
return async (repos) => {
|
|
208
|
-
await repos.assetTransaction.cancel({
|
|
209
|
-
typeOf: factory_1.factory.assetTransactionType.RegisterService,
|
|
210
|
-
id: params.id,
|
|
211
|
-
transactionNumber: params.transactionNumber
|
|
212
|
-
});
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* 取引タスク出力
|
|
217
|
-
*/
|
|
218
|
-
function exportTasksById(params) {
|
|
219
|
-
return async (repos) => {
|
|
220
|
-
const transaction = await repos.assetTransaction.findById({
|
|
221
|
-
typeOf: factory_1.factory.assetTransactionType.RegisterService,
|
|
222
|
-
id: params.id
|
|
223
|
-
});
|
|
224
|
-
const potentialActions = transaction.potentialActions;
|
|
225
|
-
const taskAttributes = [];
|
|
226
|
-
const taskRunsAt = new Date();
|
|
227
|
-
switch (transaction.status) {
|
|
228
|
-
case factory_1.factory.transactionStatusType.Confirmed:
|
|
229
|
-
/* istanbul ignore else */
|
|
230
|
-
if (potentialActions !== undefined) {
|
|
231
|
-
/* istanbul ignore else */
|
|
232
|
-
if (Array.isArray(potentialActions.registerService)
|
|
233
|
-
&& potentialActions.registerService.length > 0) {
|
|
234
|
-
const registerServiceTask = {
|
|
235
|
-
project: transaction.project,
|
|
236
|
-
name: factory_1.factory.taskName.RegisterService,
|
|
237
|
-
status: factory_1.factory.taskStatus.Ready,
|
|
238
|
-
runsAt: taskRunsAt, // なるはやで実行
|
|
239
|
-
remainingNumberOfTries: 10,
|
|
240
|
-
numberOfTried: 0,
|
|
241
|
-
executionResults: [],
|
|
242
|
-
data: potentialActions.registerService
|
|
243
|
-
};
|
|
244
|
-
taskAttributes.push(registerServiceTask);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
/* istanbul ignore else */
|
|
248
|
-
if (potentialActions !== undefined) {
|
|
249
|
-
// discontinue(2026-04-18~)
|
|
250
|
-
// if (potentialActions.moneyTransfer !== undefined) {
|
|
251
|
-
// taskAttributes.push(...potentialActions.moneyTransfer.map((a) => {
|
|
252
|
-
// return {
|
|
253
|
-
// project: transaction.project,
|
|
254
|
-
// name: factory.taskName.MoneyTransfer as factory.taskName.MoneyTransfer,
|
|
255
|
-
// status: factory.taskStatus.Ready,
|
|
256
|
-
// runsAt: taskRunsAt,
|
|
257
|
-
// remainingNumberOfTries: 10,
|
|
258
|
-
// numberOfTried: 0,
|
|
259
|
-
// executionResults: [],
|
|
260
|
-
// data: a
|
|
261
|
-
// };
|
|
262
|
-
// }));
|
|
263
|
-
// }
|
|
264
|
-
}
|
|
265
|
-
break;
|
|
266
|
-
case factory_1.factory.transactionStatusType.Canceled:
|
|
267
|
-
case factory_1.factory.transactionStatusType.Expired:
|
|
268
|
-
break;
|
|
269
|
-
default:
|
|
270
|
-
throw new factory_1.factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
|
|
271
|
-
}
|
|
272
|
-
return repos.task.saveMany(taskAttributes, { emitImmediately: true });
|
|
273
|
-
};
|
|
274
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { factory } from '../../../factory';
|
|
2
|
-
export type IOwnershipInfo = factory.ownershipInfo.IOwnershipInfo<factory.ownershipInfo.IPermitAsGood>;
|
|
3
|
-
export declare function createProductOwnershipInfo(params: {
|
|
4
|
-
project: {
|
|
5
|
-
typeOf: factory.organizationType.Project;
|
|
6
|
-
id: string;
|
|
7
|
-
};
|
|
8
|
-
ownedBy: factory.ownershipInfo.IOwner[];
|
|
9
|
-
acceptedOffer: factory.order.IAcceptedOffer<factory.order.IPermit>;
|
|
10
|
-
ownedFrom: Date;
|
|
11
|
-
identifier: string;
|
|
12
|
-
acquiredFrom: factory.ownershipInfo.IAcquiredFrom;
|
|
13
|
-
}): IOwnershipInfo;
|