@chevre/domain 21.7.0-alpha.12 → 21.7.0-alpha.13
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/example/src/chevre/countDelayedTasks.ts +1 -1
- package/example/src/chevre/createDeleteTransactionTasks.ts +1 -1
- package/example/src/chevre/deleteRunsAtPassedCertainPeriod.ts +28 -0
- package/example/src/chevre/deleteTasksByName.ts +1 -1
- package/example/src/chevre/migrateAuthorizePaymentActionResult.ts +1 -1
- package/example/src/chevre/migrateOwnershipInfos2newUserPool.ts +4 -1
- package/lib/chevre/repo/task.d.ts +2 -2
- package/lib/chevre/repo/task.js +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +1 -1
- package/lib/chevre/service/task/confirmRegisterServiceTransaction.d.ts +1 -1
- package/lib/chevre/service/task/confirmRegisterServiceTransaction.js +6 -6
- package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.d.ts +4 -0
- package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.js +92 -88
- package/lib/chevre/settings.d.ts +0 -1
- package/lib/chevre/settings.js +1 -2
- package/package.json +3 -3
- package/example/src/chevre/checkOrderMembershipTasks.ts +0 -127
- package/lib/chevre/service/task/orderProgramMembership.d.ts +0 -6
- package/lib/chevre/service/task/orderProgramMembership.js +0 -98
- package/lib/chevre/service/transaction/orderProgramMembership.d.ts +0 -50
- package/lib/chevre/service/transaction/orderProgramMembership.js +0 -349
|
@@ -11,7 +11,7 @@ export async function main() {
|
|
|
11
11
|
const count = await taskRepo.countDelayedTasks({
|
|
12
12
|
delayInSeconds: 60,
|
|
13
13
|
name: {
|
|
14
|
-
$nin: [
|
|
14
|
+
$nin: [<any>'orderProgramMembership']
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
17
|
console.log('count:', count);
|
|
@@ -13,7 +13,7 @@ async function main() {
|
|
|
13
13
|
// tslint:disable-next-line:no-magic-numbers
|
|
14
14
|
.add(-365, 'days')
|
|
15
15
|
.toDate();
|
|
16
|
-
const startDateLt: Date = moment('2021-
|
|
16
|
+
const startDateLt: Date = moment('2021-09-01T00:00:00Z')
|
|
17
17
|
.toDate();
|
|
18
18
|
|
|
19
19
|
const taskRepo = new chevre.repository.Task(mongoose.connection);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as moment from 'moment';
|
|
3
|
+
import * as mongoose from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { chevre } from '../../../lib/index';
|
|
6
|
+
|
|
7
|
+
const TASK_STORAGE_PERIOD_IN_DAYS = 365;
|
|
8
|
+
|
|
9
|
+
async function main() {
|
|
10
|
+
const now = new Date();
|
|
11
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
12
|
+
|
|
13
|
+
const taskRepo = new chevre.repository.Task(mongoose.connection);
|
|
14
|
+
|
|
15
|
+
const result = await taskRepo.deleteRunsAtPassedCertainPeriod({
|
|
16
|
+
runsAt: {
|
|
17
|
+
$lt: moment(now)
|
|
18
|
+
.add(-TASK_STORAGE_PERIOD_IN_DAYS, 'days')
|
|
19
|
+
.toDate()
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
console.log('deleted', result);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
main()
|
|
27
|
+
.then()
|
|
28
|
+
.catch(console.error);
|
|
@@ -12,7 +12,7 @@ async function main() {
|
|
|
12
12
|
const taskRepo = new chevre.repository.Task(mongoose.connection);
|
|
13
13
|
|
|
14
14
|
const result = await taskRepo.deleteByName({
|
|
15
|
-
name:
|
|
15
|
+
name: <any>'orderProgramMembership',
|
|
16
16
|
status: { $eq: chevre.factory.taskStatus.Ready }
|
|
17
17
|
// runsAt: {
|
|
18
18
|
// $gte: moment('2023-05-20T00:00:00Z')
|
|
@@ -46,7 +46,7 @@ async function main() {
|
|
|
46
46
|
'id' | 'project' | 'result' | 'typeOf' | 'startDate' | 'actionStatus'
|
|
47
47
|
> = doc.toObject();
|
|
48
48
|
|
|
49
|
-
const oldPaymentMethodType = action.result?.paymentMethod;
|
|
49
|
+
const oldPaymentMethodType = (<any>action).result?.paymentMethod;
|
|
50
50
|
const paymentMethodType = action.result?.paymentMethodAsObject?.typeOf;
|
|
51
51
|
const alreadyMigrated = typeof paymentMethodType === 'string' && oldPaymentMethodType === paymentMethodType;
|
|
52
52
|
|
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
import * as mongoose from 'mongoose';
|
|
4
4
|
|
|
5
5
|
import { chevre } from '../../../lib/index';
|
|
6
|
-
import { ISS_PREFIX, USERPOOL_ID_NEW } from './checkOrderMembershipTasks';
|
|
7
6
|
import { migrateUser } from './migrateCognitoUser';
|
|
8
7
|
|
|
8
|
+
// export const USERPOOL_ID_OLD = String(process.env.USERPOOL_ID_OLD);
|
|
9
|
+
export const USERPOOL_ID_NEW = String(process.env.USERPOOL_ID_NEW);
|
|
10
|
+
export const ISS_PREFIX = 'https://cognito-idp.ap-northeast-1.amazonaws.com/';
|
|
11
|
+
|
|
9
12
|
const project = { id: String(process.env.PROJECT_ID) };
|
|
10
13
|
const PRODUCT_TYPE = chevre.factory.product.ProductType.EventService;
|
|
11
14
|
|
|
@@ -63,7 +63,7 @@ export declare class MongoRepository {
|
|
|
63
63
|
*/
|
|
64
64
|
$nin?: factory.taskName[];
|
|
65
65
|
};
|
|
66
|
-
}): Promise<Pick<import("@chevre/factory/lib/task").ITask | import("@chevre/factory/lib/task/confirmMoneyTransfer").ITask | import("@chevre/factory/lib/task/confirmRegisterService").ITask | import("@chevre/factory/lib/task/confirmPayTransaction").ITask | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").ITask | import("@chevre/factory/lib/task/confirmReserveTransaction").ITask | import("@chevre/factory/lib/task/createEvent").ITask | import("@chevre/factory/lib/task/deleteTransaction").ITask | import("@chevre/factory/lib/task/givePointAward").ITask | import("@chevre/factory/lib/task/onAuthorizationCreated").ITask | import("@chevre/factory/lib/task/onEventChanged").ITask | import("@chevre/factory/lib/task/onResourceUpdated").ITask | import("@chevre/factory/lib/task/
|
|
66
|
+
}): Promise<Pick<import("@chevre/factory/lib/task").ITask | import("@chevre/factory/lib/task/confirmMoneyTransfer").ITask | import("@chevre/factory/lib/task/confirmRegisterService").ITask | import("@chevre/factory/lib/task/confirmPayTransaction").ITask | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").ITask | import("@chevre/factory/lib/task/confirmReserveTransaction").ITask | import("@chevre/factory/lib/task/createEvent").ITask | import("@chevre/factory/lib/task/deleteTransaction").ITask | import("@chevre/factory/lib/task/givePointAward").ITask | import("@chevre/factory/lib/task/onAuthorizationCreated").ITask | import("@chevre/factory/lib/task/onEventChanged").ITask | import("@chevre/factory/lib/task/onResourceUpdated").ITask | import("@chevre/factory/lib/task/placeOrder").ITask | import("@chevre/factory/lib/task/returnOrder").ITask | import("@chevre/factory/lib/task/returnMoneyTransfer").ITask | import("@chevre/factory/lib/task/returnPayTransaction").ITask | import("@chevre/factory/lib/task/returnPointAward").ITask | import("@chevre/factory/lib/task/returnReserveTransaction").ITask | import("@chevre/factory/lib/task/sendEmailMessage").ITask | import("@chevre/factory/lib/task/sendOrder").ITask | import("@chevre/factory/lib/task/syncScreeningRooms").ITask | import("@chevre/factory/lib/task/triggerWebhook").ITask | import("@chevre/factory/lib/task/useReservation").ITask | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").ITask | import("@chevre/factory/lib/task/voidPayTransaction").ITask | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").ITask | import("@chevre/factory/lib/task/voidReserveTransaction").ITask, "id" | "name" | "status">[]>;
|
|
67
67
|
retry(params: {
|
|
68
68
|
intervalInMinutes: number;
|
|
69
69
|
}): Promise<void>;
|
|
@@ -108,7 +108,7 @@ export declare class MongoRepository {
|
|
|
108
108
|
runsAt: {
|
|
109
109
|
$lt: Date;
|
|
110
110
|
};
|
|
111
|
-
}): Promise<
|
|
111
|
+
}): Promise<import("mongodb").DeleteResult>;
|
|
112
112
|
countDelayedTasks(params: {
|
|
113
113
|
delayInSeconds: number;
|
|
114
114
|
name: {
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -427,7 +427,7 @@ class MongoRepository {
|
|
|
427
427
|
*/
|
|
428
428
|
deleteRunsAtPassedCertainPeriod(params) {
|
|
429
429
|
return __awaiter(this, void 0, void 0, function* () {
|
|
430
|
-
|
|
430
|
+
return this.taskModel.deleteMany({
|
|
431
431
|
runsAt: { $lt: params.runsAt.$lt },
|
|
432
432
|
status: { $in: [factory.taskStatus.Aborted, factory.taskStatus.Executed] }
|
|
433
433
|
})
|
|
@@ -33,5 +33,5 @@ export declare function createOnPlaceOrderTasksByTransaction(params: {
|
|
|
33
33
|
*/
|
|
34
34
|
export declare function createOnOrderSentTasksByTransaction(params: {
|
|
35
35
|
potentialActions?: factory.action.transfer.send.order.IPotentialActions;
|
|
36
|
-
}): (import("@chevre/factory/lib/task").IAttributes | import("@chevre/factory/lib/task/confirmMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/confirmRegisterService").IAttributes | import("@chevre/factory/lib/task/confirmPayTransaction").IAttributes | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/confirmReserveTransaction").IAttributes | import("@chevre/factory/lib/task/createEvent").IAttributes | import("@chevre/factory/lib/task/deleteTransaction").IAttributes | import("@chevre/factory/lib/task/givePointAward").IAttributes | import("@chevre/factory/lib/task/onAuthorizationCreated").IAttributes | import("@chevre/factory/lib/task/onEventChanged").IAttributes | import("@chevre/factory/lib/task/onResourceUpdated").IAttributes | import("@chevre/factory/lib/task/
|
|
36
|
+
}): (import("@chevre/factory/lib/task").IAttributes | import("@chevre/factory/lib/task/confirmMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/confirmRegisterService").IAttributes | import("@chevre/factory/lib/task/confirmPayTransaction").IAttributes | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/confirmReserveTransaction").IAttributes | import("@chevre/factory/lib/task/createEvent").IAttributes | import("@chevre/factory/lib/task/deleteTransaction").IAttributes | import("@chevre/factory/lib/task/givePointAward").IAttributes | import("@chevre/factory/lib/task/onAuthorizationCreated").IAttributes | import("@chevre/factory/lib/task/onEventChanged").IAttributes | import("@chevre/factory/lib/task/onResourceUpdated").IAttributes | import("@chevre/factory/lib/task/placeOrder").IAttributes | import("@chevre/factory/lib/task/returnOrder").IAttributes | import("@chevre/factory/lib/task/returnMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/returnPayTransaction").IAttributes | import("@chevre/factory/lib/task/returnPointAward").IAttributes | import("@chevre/factory/lib/task/returnReserveTransaction").IAttributes | import("@chevre/factory/lib/task/sendEmailMessage").IAttributes | import("@chevre/factory/lib/task/sendOrder").IAttributes | import("@chevre/factory/lib/task/syncScreeningRooms").IAttributes | import("@chevre/factory/lib/task/triggerWebhook").IAttributes | import("@chevre/factory/lib/task/useReservation").IAttributes | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").IAttributes | import("@chevre/factory/lib/task/voidPayTransaction").IAttributes | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/voidReserveTransaction").IAttributes)[];
|
|
37
37
|
export {};
|
|
@@ -12,6 +12,6 @@ export declare function confirmRegisterServiceTransaction(params: factory.action
|
|
|
12
12
|
assetTransaction: AssetTransactionRepo;
|
|
13
13
|
task: TaskRepo;
|
|
14
14
|
}) => Promise<void>;
|
|
15
|
-
export declare function onRegistered(
|
|
15
|
+
export declare function onRegistered(__: factory.action.interact.confirm.registerService.IAttributes): (repos: {
|
|
16
16
|
task: TaskRepo;
|
|
17
17
|
}) => Promise<void>;
|
|
@@ -85,15 +85,15 @@ function confirmRegisterServiceTransaction(params) {
|
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
87
|
exports.confirmRegisterServiceTransaction = confirmRegisterServiceTransaction;
|
|
88
|
-
function onRegistered(
|
|
88
|
+
function onRegistered(__) {
|
|
89
89
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
var _a;
|
|
91
90
|
const taskAttributes = [];
|
|
92
91
|
// 次のメンバーシップ注文タスクを作成
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
// 廃止(2023-08-18~)
|
|
93
|
+
// const orderProgramMembershipTasks = actionAttributes.potentialActions?.orderProgramMembership;
|
|
94
|
+
// if (Array.isArray(orderProgramMembershipTasks)) {
|
|
95
|
+
// taskAttributes.push(...orderProgramMembershipTasks);
|
|
96
|
+
// }
|
|
97
97
|
// タスク保管
|
|
98
98
|
yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
|
|
99
99
|
});
|
package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.d.ts
CHANGED
|
@@ -4,3 +4,7 @@ export declare function createRegisterServiceActions(params: {
|
|
|
4
4
|
transaction: factory.transaction.placeOrder.ITransaction;
|
|
5
5
|
authorizeActions: factory.action.authorize.IAction<factory.action.authorize.IAttributes<any, any>>[];
|
|
6
6
|
}): Promise<factory.action.interact.confirm.registerService.IAttributes[]>;
|
|
7
|
+
/**
|
|
8
|
+
* ssktsへの互換性対応として
|
|
9
|
+
* 次回メンバーシップ注文タスクを作成する
|
|
10
|
+
*/
|
package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.js
CHANGED
|
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.createRegisterServiceActions = void 0;
|
|
13
|
-
const moment = require("moment");
|
|
14
13
|
const factory = require("../../../../factory");
|
|
15
14
|
const availableProductTypes_1 = require("../../../../factory/availableProductTypes");
|
|
16
15
|
const order_1 = require("../../../../factory/order");
|
|
@@ -47,20 +46,22 @@ function createRegisterServiceActions(params) {
|
|
|
47
46
|
transaction: params.transaction,
|
|
48
47
|
transactionNumber: (_a = a.instrument) === null || _a === void 0 ? void 0 : _a.transactionNumber
|
|
49
48
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
49
|
+
// 廃止(2023-08-18~)
|
|
50
|
+
// const orderProgramMembershipTask = createOrderProgramMembershipTask({
|
|
51
|
+
// order: params.order,
|
|
52
|
+
// authorizeAction: a
|
|
53
|
+
// });
|
|
55
54
|
registerServiceActions.push({
|
|
56
55
|
project: params.transaction.project,
|
|
57
56
|
typeOf: factory.actionType.ConfirmAction,
|
|
58
57
|
object: registerServiceObject,
|
|
59
58
|
agent: params.transaction.project,
|
|
60
59
|
purpose: registerServicePurpose,
|
|
61
|
-
potentialActions:
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
potentialActions: {
|
|
61
|
+
// ...(orderProgramMembershipTask !== undefined)
|
|
62
|
+
// ? { orderProgramMembership: [orderProgramMembershipTask] }
|
|
63
|
+
// : undefined
|
|
64
|
+
}
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
67
|
});
|
|
@@ -80,82 +81,85 @@ function createRegisterServiceActionObject(params) {
|
|
|
80
81
|
* ssktsへの互換性対応として
|
|
81
82
|
* 次回メンバーシップ注文タスクを作成する
|
|
82
83
|
*/
|
|
83
|
-
function createOrderProgramMembershipTask(params
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
84
|
+
// function createOrderProgramMembershipTask(params: {
|
|
85
|
+
// order: factory.order.IOrder;
|
|
86
|
+
// authorizeAction: factory.action.authorize.offer.product.IAction;
|
|
87
|
+
// }): factory.task.IAttributes<factory.taskName.OrderProgramMembership> | undefined {
|
|
88
|
+
// let orderMembershipTask: factory.task.IAttributes<factory.taskName.OrderProgramMembership> | undefined;
|
|
89
|
+
// const acceptedOffer = params.authorizeAction.object[0];
|
|
90
|
+
// // ssktsへの互換性対応なので、限定的に(暫定対応のautomaticRenewal設定で判定)
|
|
91
|
+
// const serviceOutput = acceptedOffer.itemOffered.serviceOutput;
|
|
92
|
+
// if (acceptedOffer.itemOffered.typeOf === factory.product.ProductType.MembershipService
|
|
93
|
+
// && typeof serviceOutput?.typeOf === 'string'
|
|
94
|
+
// && serviceOutput.typeOf.length > 0
|
|
95
|
+
// && serviceOutput.automaticRenewal === true) {
|
|
96
|
+
// const memebershipFor: Pick<factory.product.IProduct, 'project' | 'typeOf' | 'id'> = {
|
|
97
|
+
// project: { typeOf: factory.organizationType.Project, id: params.order.project.id },
|
|
98
|
+
// typeOf: acceptedOffer.itemOffered.typeOf,
|
|
99
|
+
// id: String(acceptedOffer.itemOffered.id)
|
|
100
|
+
// };
|
|
101
|
+
// const orderMembershipObject: factory.task.orderProgramMembership.IAcceptedOffer = {
|
|
102
|
+
// seller: { id: String(acceptedOffer.seller.id) },
|
|
103
|
+
// typeOf: acceptedOffer.typeOf,
|
|
104
|
+
// itemOffered: {
|
|
105
|
+
// typeOf: serviceOutput.typeOf,
|
|
106
|
+
// name: (typeof serviceOutput.name === 'string') ? serviceOutput.name : serviceOutput.typeOf,
|
|
107
|
+
// issuedThrough: { id: String(memebershipFor.id), typeOf: factory.product.ProductType.MembershipService }
|
|
108
|
+
// },
|
|
109
|
+
// id: String(acceptedOffer.id),
|
|
110
|
+
// identifier: String(acceptedOffer.identifier)
|
|
111
|
+
// };
|
|
112
|
+
// // 次回のメンバーシップ注文タスクを生成
|
|
113
|
+
// const orderProgramMembershipTaskData: factory.task.IData<factory.taskName.OrderProgramMembership> = {
|
|
114
|
+
// // 最低限の情報のみagentに設定
|
|
115
|
+
// agent: {
|
|
116
|
+
// typeOf: factory.personType.Person,
|
|
117
|
+
// id: params.order.customer.id,
|
|
118
|
+
// // transaction.agent.identifierにissがあれば情報を引き継ぐ
|
|
119
|
+
// identifier: (Array.isArray(params.order.customer.identifier))
|
|
120
|
+
// ? params.order.customer.identifier
|
|
121
|
+
// : []
|
|
122
|
+
// },
|
|
123
|
+
// object: orderMembershipObject,
|
|
124
|
+
// project: params.order.project,
|
|
125
|
+
// typeOf: factory.actionType.OrderAction
|
|
126
|
+
// };
|
|
127
|
+
// // どういう期間でいくらのオファーなのか
|
|
128
|
+
// const priceSpec = <factory.compoundPriceSpecification.IPriceSpecification<factory.priceSpecificationType>>
|
|
129
|
+
// acceptedOffer.priceSpecification;
|
|
130
|
+
// if (priceSpec === undefined) {
|
|
131
|
+
// throw new factory.errors.NotFound('Order.acceptedOffers.priceSpecification');
|
|
132
|
+
// }
|
|
133
|
+
// const unitPriceSpec =
|
|
134
|
+
// <factory.priceSpecification.IPriceSpecification<factory.priceSpecificationType.UnitPriceSpecification>>
|
|
135
|
+
// priceSpec.priceComponent.find(
|
|
136
|
+
// (p) => p.typeOf === factory.priceSpecificationType.UnitPriceSpecification
|
|
137
|
+
// );
|
|
138
|
+
// if (unitPriceSpec === undefined) {
|
|
139
|
+
// throw new factory.errors.NotFound('Unit Price Specification in Order.acceptedOffers.priceSpecification');
|
|
140
|
+
// }
|
|
141
|
+
// // 期間単位としては秒のみ実装
|
|
142
|
+
// if (unitPriceSpec.referenceQuantity.unitCode !== factory.unitCode.Sec) {
|
|
143
|
+
// throw new factory.errors.NotImplemented('Only \'SEC\' is implemented for priceSpecification.referenceQuantity.unitCode ');
|
|
144
|
+
// }
|
|
145
|
+
// const referenceQuantityValue = unitPriceSpec.referenceQuantity.value;
|
|
146
|
+
// if (typeof referenceQuantityValue !== 'number') {
|
|
147
|
+
// throw new factory.errors.NotFound('Order.acceptedOffers.priceSpecification.referenceQuantity.value');
|
|
148
|
+
// }
|
|
149
|
+
// // プログラム更新日時は、今回のプログラムの所有期限
|
|
150
|
+
// const runsAt = moment(params.order.orderDate)
|
|
151
|
+
// .add(referenceQuantityValue, 'seconds')
|
|
152
|
+
// .toDate();
|
|
153
|
+
// orderMembershipTask = {
|
|
154
|
+
// data: orderProgramMembershipTaskData,
|
|
155
|
+
// executionResults: [],
|
|
156
|
+
// name: <factory.taskName.OrderProgramMembership>factory.taskName.OrderProgramMembership,
|
|
157
|
+
// numberOfTried: 0,
|
|
158
|
+
// project: params.order.project,
|
|
159
|
+
// remainingNumberOfTries: 10,
|
|
160
|
+
// runsAt: runsAt,
|
|
161
|
+
// status: factory.taskStatus.Ready
|
|
162
|
+
// };
|
|
163
|
+
// }
|
|
164
|
+
// return orderMembershipTask;
|
|
165
|
+
// }
|
package/lib/chevre/settings.d.ts
CHANGED
|
@@ -34,7 +34,6 @@ export type ISettings = factory.project.ISettings & {
|
|
|
34
34
|
useAggregateOfferProjects: string[];
|
|
35
35
|
useOfferRateLimitProjects: string[];
|
|
36
36
|
};
|
|
37
|
-
export declare const DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD: string;
|
|
38
37
|
export declare const DEFAULT_TASKS_EXPORT_AGENT_NAME: string;
|
|
39
38
|
export declare const USE_ASSET_TRANSACTION_SYNC_PROCESSING: boolean;
|
|
40
39
|
export declare const USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING: boolean;
|
package/lib/chevre/settings.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.settings = exports.MONGO_MAX_TIME_MS = exports.INFORM_RESERVATION_TASK_DELAY_IN_SECONDS = exports.USE_DELETE_EVENT_BY_ORDER = exports.USE_OBJECT_AS_PAY_TRANSACTION_AMOUNT = exports.USE_ADVANCE_BOOKING_REQUIREMENT = exports.USE_NEW_EVENT_AVAILABILITY_KEY_FROM = exports.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING = exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = exports.DEFAULT_TASKS_EXPORT_AGENT_NAME = exports.
|
|
3
|
+
exports.settings = exports.MONGO_MAX_TIME_MS = exports.INFORM_RESERVATION_TASK_DELAY_IN_SECONDS = exports.USE_DELETE_EVENT_BY_ORDER = exports.USE_OBJECT_AS_PAY_TRANSACTION_AMOUNT = exports.USE_ADVANCE_BOOKING_REQUIREMENT = exports.USE_NEW_EVENT_AVAILABILITY_KEY_FROM = exports.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING = exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = exports.DEFAULT_TASKS_EXPORT_AGENT_NAME = exports.DEFAULT_SENDER_EMAIL = exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = exports.TRANSACTION_CONFIRMED_STORAGE_PERIOD_IN_DAYS = exports.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS = exports.ABORTED_TASKS_WITHOUT_REPORT = exports.TRIGGER_WEBHOOK_RETRY_INTERVAL_IN_MS = exports.TRIGGER_WEBHOOK_MAX_RETRY_COUNT = void 0;
|
|
4
4
|
const moment = require("moment");
|
|
5
5
|
const factory = require("./factory");
|
|
6
6
|
const transactionWebhookUrls = (typeof process.env.INFORM_TRANSACTION_URL === 'string')
|
|
@@ -58,7 +58,6 @@ exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = (typeof process.env.TRANSA
|
|
|
58
58
|
// tslint:disable-next-line:no-magic-numbers
|
|
59
59
|
: 7;
|
|
60
60
|
exports.DEFAULT_SENDER_EMAIL = process.env.DEFAULT_SENDER_EMAIL;
|
|
61
|
-
exports.DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD = String(process.env.DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD);
|
|
62
61
|
exports.DEFAULT_TASKS_EXPORT_AGENT_NAME = `${process.env.GAE_APPLICATION}:${process.env.GAE_SERVICE}:jobs`;
|
|
63
62
|
exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = process.env.USE_ASSET_TRANSACTION_SYNC_PROCESSING === '1';
|
|
64
63
|
exports.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING = process.env.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING === '1';
|
package/package.json
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
}
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@chevre/factory": "4.
|
|
13
|
-
"@cinerino/sdk": "3.
|
|
12
|
+
"@chevre/factory": "4.326.0-alpha.0",
|
|
13
|
+
"@cinerino/sdk": "3.165.0",
|
|
14
14
|
"@motionpicture/coa-service": "9.2.0",
|
|
15
15
|
"@motionpicture/gmo-service": "5.2.0",
|
|
16
16
|
"@sendgrid/mail": "6.4.0",
|
|
@@ -117,5 +117,5 @@
|
|
|
117
117
|
"postversion": "git push origin --tags",
|
|
118
118
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
119
119
|
},
|
|
120
|
-
"version": "21.7.0-alpha.
|
|
120
|
+
"version": "21.7.0-alpha.13"
|
|
121
121
|
}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
// import * as moment from 'moment';
|
|
3
|
-
import * as mongoose from 'mongoose';
|
|
4
|
-
|
|
5
|
-
import { chevre } from '../../../lib/index';
|
|
6
|
-
|
|
7
|
-
import { migrateUser } from './migrateCognitoUser';
|
|
8
|
-
|
|
9
|
-
const project = { id: String(process.env.PROJECT_ID) };
|
|
10
|
-
export const USERPOOL_ID_OLD = String(process.env.USERPOOL_ID_OLD);
|
|
11
|
-
export const USERPOOL_ID_NEW = String(process.env.USERPOOL_ID_NEW);
|
|
12
|
-
export const ISS_PREFIX = 'https://cognito-idp.ap-northeast-1.amazonaws.com/';
|
|
13
|
-
|
|
14
|
-
// tslint:disable-next-line:max-func-body-length
|
|
15
|
-
export async function main() {
|
|
16
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
17
|
-
|
|
18
|
-
const taskRepo = new chevre.repository.Task(mongoose.connection);
|
|
19
|
-
|
|
20
|
-
// const now = new Date();
|
|
21
|
-
const cursor = await taskRepo.taskModel.find(
|
|
22
|
-
{
|
|
23
|
-
// _id: { $eq: '60398ca3bdadde000a308709' },
|
|
24
|
-
status: { $eq: chevre.factory.taskStatus.Ready },
|
|
25
|
-
name: { $eq: chevre.factory.taskName.OrderProgramMembership },
|
|
26
|
-
'project.id': { $eq: project.id }
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
// _id: 1,
|
|
30
|
-
}
|
|
31
|
-
)
|
|
32
|
-
.sort({ runsAt: chevre.factory.sortType.Ascending })
|
|
33
|
-
.cursor();
|
|
34
|
-
console.log('tasks found');
|
|
35
|
-
|
|
36
|
-
let i = 0;
|
|
37
|
-
let notFoundCount = 0;
|
|
38
|
-
let updateCount = 0;
|
|
39
|
-
await cursor.eachAsync(async (doc) => {
|
|
40
|
-
i += 1;
|
|
41
|
-
const task = <chevre.factory.task.ITask<chevre.factory.taskName.OrderProgramMembership>>doc.toObject();
|
|
42
|
-
|
|
43
|
-
const owner = <chevre.factory.person.IPerson>task.data.agent;
|
|
44
|
-
let iss =
|
|
45
|
-
(<chevre.factory.propertyValue.IPropertyValue<string>[] | undefined>owner.identifier)?.find((p) => p.name === 'iss')?.value;
|
|
46
|
-
if (typeof iss === 'string') {
|
|
47
|
-
iss = iss.replace(ISS_PREFIX, '');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// 新会員ならok
|
|
51
|
-
if (iss === USERPOOL_ID_NEW) {
|
|
52
|
-
console.log('already new userPool', task.runsAt, i, notFoundCount);
|
|
53
|
-
} else {
|
|
54
|
-
// 旧会員の場合、新会員の存在確認
|
|
55
|
-
console.log(
|
|
56
|
-
'checking...',
|
|
57
|
-
task.runsAt,
|
|
58
|
-
owner.id, owner.memberOf?.membershipNumber, i, notFoundCount);
|
|
59
|
-
const personRepo = new chevre.repository.Person({ userPoolId: USERPOOL_ID_NEW });
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
const newUserAttributes = await personRepo.getUserAttributes({ username: `SSKTS_${owner.id}` });
|
|
63
|
-
const newUserId = newUserAttributes.additionalProperty?.find((p) => p.name === 'sub')?.value;
|
|
64
|
-
const person = await personRepo.findById({ userId: String(newUserId) });
|
|
65
|
-
console.log(
|
|
66
|
-
'found',
|
|
67
|
-
task.runsAt,
|
|
68
|
-
owner.id,
|
|
69
|
-
owner.memberOf?.membershipNumber,
|
|
70
|
-
person.id, i, notFoundCount);
|
|
71
|
-
|
|
72
|
-
// 所有権の所有者を新会員に置換
|
|
73
|
-
const newOwner: chevre.factory.person.IPerson = {
|
|
74
|
-
...owner,
|
|
75
|
-
id: person.id,
|
|
76
|
-
identifier: [
|
|
77
|
-
...(Array.isArray(person.identifier)) ? person.identifier : [],
|
|
78
|
-
// 手動移行した証拠を残す
|
|
79
|
-
{ name: 'dataAgentMigratedManually', value: '1' }
|
|
80
|
-
]
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
updateCount += 1;
|
|
84
|
-
console.log(
|
|
85
|
-
'updating data.agent...',
|
|
86
|
-
task.runsAt,
|
|
87
|
-
owner.id,
|
|
88
|
-
owner.memberOf?.membershipNumber,
|
|
89
|
-
person.id, i, notFoundCount, updateCount);
|
|
90
|
-
const result = await taskRepo.taskModel.updateOne(
|
|
91
|
-
{ _id: task.id },
|
|
92
|
-
{ 'data.agent': newOwner }
|
|
93
|
-
)
|
|
94
|
-
.exec();
|
|
95
|
-
console.log(
|
|
96
|
-
'data.agent updated',
|
|
97
|
-
task.runsAt,
|
|
98
|
-
owner.id,
|
|
99
|
-
owner.memberOf?.membershipNumber,
|
|
100
|
-
person.id, i, notFoundCount, updateCount,
|
|
101
|
-
result);
|
|
102
|
-
|
|
103
|
-
} catch (error) {
|
|
104
|
-
// NotFoundエラーは、新ユーザープールでのユーザーがまだ存在しないだけ
|
|
105
|
-
if (error.code === 'UserNotFoundException') {
|
|
106
|
-
notFoundCount += 1;
|
|
107
|
-
console.log(
|
|
108
|
-
'not found',
|
|
109
|
-
task.runsAt,
|
|
110
|
-
owner.id, owner.memberOf?.membershipNumber, i, notFoundCount);
|
|
111
|
-
// migrateUser
|
|
112
|
-
await migrateUser({ id: owner.id });
|
|
113
|
-
} else {
|
|
114
|
-
throw error;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
console.log(i, 'infos checked');
|
|
121
|
-
console.log(notFoundCount, 'people not found');
|
|
122
|
-
console.log(updateCount, 'tasks updated');
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
main()
|
|
126
|
-
.then()
|
|
127
|
-
.catch(console.error);
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.call = void 0;
|
|
13
|
-
const account_1 = require("../../repo/account");
|
|
14
|
-
const accountingReport_1 = require("../../repo/accountingReport");
|
|
15
|
-
const action_1 = require("../../repo/action");
|
|
16
|
-
const assetTransaction_1 = require("../../repo/assetTransaction");
|
|
17
|
-
const event_1 = require("../../repo/event");
|
|
18
|
-
const offer_1 = require("../../repo/offer");
|
|
19
|
-
const offerCatalog_1 = require("../../repo/offerCatalog");
|
|
20
|
-
const ownershipInfo_1 = require("../../repo/ownershipInfo");
|
|
21
|
-
const person_1 = require("../../repo/person");
|
|
22
|
-
const product_1 = require("../../repo/product");
|
|
23
|
-
const project_1 = require("../../repo/project");
|
|
24
|
-
const seller_1 = require("../../repo/seller");
|
|
25
|
-
const serviceOutput_1 = require("../../repo/serviceOutput");
|
|
26
|
-
const task_1 = require("../../repo/task");
|
|
27
|
-
const transaction_1 = require("../../repo/transaction");
|
|
28
|
-
const registerServiceInProgress_1 = require("../../repo/action/registerServiceInProgress");
|
|
29
|
-
const confirmationNumber_1 = require("../../repo/confirmationNumber");
|
|
30
|
-
const orderNumber_1 = require("../../repo/orderNumber");
|
|
31
|
-
const serviceOutputIdentifier_1 = require("../../repo/serviceOutputIdentifier");
|
|
32
|
-
const transactionNumber_1 = require("../../repo/transactionNumber");
|
|
33
|
-
const orderProgramMembership_1 = require("../../service/transaction/orderProgramMembership");
|
|
34
|
-
const settings_1 = require("../../settings");
|
|
35
|
-
/**
|
|
36
|
-
* タスク実行関数
|
|
37
|
-
*/
|
|
38
|
-
function call(data) {
|
|
39
|
-
// tslint:disable-next-line:max-func-body-length
|
|
40
|
-
return (settings) => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
var _a, _b;
|
|
42
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
43
|
-
/* istanbul ignore if */
|
|
44
|
-
if (settings.redisClient === undefined) {
|
|
45
|
-
throw new Error('settings.redisClient undefined.');
|
|
46
|
-
}
|
|
47
|
-
let iss = '';
|
|
48
|
-
if (Array.isArray(data.agent.identifier)) {
|
|
49
|
-
const issByAgent = (_b = (_a = data.agent.identifier) === null || _a === void 0 ? void 0 : _a.find((p) => p.name === 'iss')) === null || _b === void 0 ? void 0 : _b.value;
|
|
50
|
-
if (typeof issByAgent === 'string' && issByAgent.length > 0) {
|
|
51
|
-
iss = issByAgent.replace(orderProgramMembership_1.ISS_PREFIX, '');
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const personRepo = new person_1.CognitoRepository({ userPoolId: iss });
|
|
55
|
-
const accountingReportRepo = new accountingReport_1.MongoRepository(settings.connection);
|
|
56
|
-
const actionRepo = new action_1.MongoRepository(settings.connection);
|
|
57
|
-
const accountRepo = new account_1.MongoRepository(settings.connection);
|
|
58
|
-
const assetTransactionRepo = new assetTransaction_1.MongoRepository(settings.connection);
|
|
59
|
-
const eventRepo = new event_1.MongoRepository(settings.connection);
|
|
60
|
-
const offerRepo = new offer_1.MongoRepository(settings.connection);
|
|
61
|
-
const offerCatalogRepo = new offerCatalog_1.MongoRepository(settings.connection);
|
|
62
|
-
const productRepo = new product_1.MongoRepository(settings.connection);
|
|
63
|
-
const projectRepo = new project_1.MongoRepository(settings.connection);
|
|
64
|
-
const ownershipInfoRepo = new ownershipInfo_1.MongoRepository(settings.connection);
|
|
65
|
-
const sellerRepo = new seller_1.MongoRepository(settings.connection);
|
|
66
|
-
const serviceOutputRepo = new serviceOutput_1.MongoRepository(settings.connection);
|
|
67
|
-
const taskRepo = new task_1.MongoRepository(settings.connection);
|
|
68
|
-
const transactionRepo = new transaction_1.MongoRepository(settings.connection);
|
|
69
|
-
const confirmationNumberRepo = new confirmationNumber_1.RedisRepository(settings.redisClient);
|
|
70
|
-
const orderNumberRepo = new orderNumber_1.RedisRepository(settings.redisClient);
|
|
71
|
-
const registerServiceInProgressRepo = new registerServiceInProgress_1.RedisRepository(settings.redisClient);
|
|
72
|
-
const transactionNumberRepo = new transactionNumber_1.RedisRepository(settings.redisClient);
|
|
73
|
-
const serviceOutputIdentifierRepo = new serviceOutputIdentifier_1.RedisRepository(settings.redisClient);
|
|
74
|
-
yield (0, orderProgramMembership_1.orderProgramMembership)(data, settings_1.DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD)({
|
|
75
|
-
account: accountRepo,
|
|
76
|
-
accountingReport: accountingReportRepo,
|
|
77
|
-
action: actionRepo,
|
|
78
|
-
assetTransaction: assetTransactionRepo,
|
|
79
|
-
confirmationNumber: confirmationNumberRepo,
|
|
80
|
-
event: eventRepo,
|
|
81
|
-
offer: offerRepo,
|
|
82
|
-
offerCatalog: offerCatalogRepo,
|
|
83
|
-
orderNumber: orderNumberRepo,
|
|
84
|
-
ownershipInfo: ownershipInfoRepo,
|
|
85
|
-
person: personRepo,
|
|
86
|
-
product: productRepo,
|
|
87
|
-
project: projectRepo,
|
|
88
|
-
registerActionInProgress: registerServiceInProgressRepo,
|
|
89
|
-
seller: sellerRepo,
|
|
90
|
-
serviceOutput: serviceOutputRepo,
|
|
91
|
-
serviceOutputIdentifier: serviceOutputIdentifierRepo,
|
|
92
|
-
task: taskRepo,
|
|
93
|
-
transaction: transactionRepo,
|
|
94
|
-
transactionNumber: transactionNumberRepo
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
exports.call = call;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { MongoRepository as AccountRepo } from '../../repo/account';
|
|
2
|
-
import { MongoRepository as AccountingReportRepo } from '../../repo/accountingReport';
|
|
3
|
-
import { MongoRepository as ActionRepo } from '../../repo/action';
|
|
4
|
-
import { RedisRepository as RegisterServiceInProgressRepo } from '../../repo/action/registerServiceInProgress';
|
|
5
|
-
import { MongoRepository as AssetTransactionRepo } from '../../repo/assetTransaction';
|
|
6
|
-
import { RedisRepository as ConfirmationNumberRepo } from '../../repo/confirmationNumber';
|
|
7
|
-
import { MongoRepository as EventRepo } from '../../repo/event';
|
|
8
|
-
import { MongoRepository as OfferRepo } from '../../repo/offer';
|
|
9
|
-
import { MongoRepository as OfferCatalogRepo } from '../../repo/offerCatalog';
|
|
10
|
-
import { RedisRepository as OrderNumberRepo } from '../../repo/orderNumber';
|
|
11
|
-
import { MongoRepository as OwnershipInfoRepo } from '../../repo/ownershipInfo';
|
|
12
|
-
import { CognitoRepository as PersonRepo } from '../../repo/person';
|
|
13
|
-
import { MongoRepository as ProductRepo } from '../../repo/product';
|
|
14
|
-
import { MongoRepository as ProjectRepo } from '../../repo/project';
|
|
15
|
-
import { MongoRepository as SellerRepo } from '../../repo/seller';
|
|
16
|
-
import { MongoRepository as ServiceOutputRepo } from '../../repo/serviceOutput';
|
|
17
|
-
import { RedisRepository as ServiceOutputIdentifierRepo } from '../../repo/serviceOutputIdentifier';
|
|
18
|
-
import { MongoRepository as TaskRepo } from '../../repo/task';
|
|
19
|
-
import { MongoRepository as TransactionRepo } from '../../repo/transaction';
|
|
20
|
-
import { RedisRepository as TransactionNumberRepo } from '../../repo/transactionNumber';
|
|
21
|
-
import * as factory from '../../factory';
|
|
22
|
-
export declare const ISS_PREFIX = "https://cognito-idp.ap-northeast-1.amazonaws.com/";
|
|
23
|
-
interface IOrderOperationRepos {
|
|
24
|
-
account: AccountRepo;
|
|
25
|
-
accountingReport: AccountingReportRepo;
|
|
26
|
-
action: ActionRepo;
|
|
27
|
-
assetTransaction: AssetTransactionRepo;
|
|
28
|
-
confirmationNumber: ConfirmationNumberRepo;
|
|
29
|
-
event: EventRepo;
|
|
30
|
-
offer: OfferRepo;
|
|
31
|
-
offerCatalog: OfferCatalogRepo;
|
|
32
|
-
orderNumber: OrderNumberRepo;
|
|
33
|
-
ownershipInfo: OwnershipInfoRepo;
|
|
34
|
-
person: PersonRepo;
|
|
35
|
-
product: ProductRepo;
|
|
36
|
-
project: ProjectRepo;
|
|
37
|
-
registerActionInProgress: RegisterServiceInProgressRepo;
|
|
38
|
-
seller: SellerRepo;
|
|
39
|
-
serviceOutput: ServiceOutputRepo;
|
|
40
|
-
serviceOutputIdentifier: ServiceOutputIdentifierRepo;
|
|
41
|
-
task: TaskRepo;
|
|
42
|
-
transaction: TransactionRepo;
|
|
43
|
-
transactionNumber: TransactionNumberRepo;
|
|
44
|
-
}
|
|
45
|
-
type IOrderOperation<T> = (repos: IOrderOperationRepos) => Promise<T>;
|
|
46
|
-
/**
|
|
47
|
-
* メンバーシップ注文
|
|
48
|
-
*/
|
|
49
|
-
export declare function orderProgramMembership(params: factory.task.IData<factory.taskName.OrderProgramMembership>, paymentMethodType: string): IOrderOperation<void>;
|
|
50
|
-
export {};
|
|
@@ -1,349 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.orderProgramMembership = exports.ISS_PREFIX = void 0;
|
|
13
|
-
/**
|
|
14
|
-
* メンバーシップ注文サービス
|
|
15
|
-
*/
|
|
16
|
-
const GMO = require("@motionpicture/gmo-service");
|
|
17
|
-
const createDebug = require("debug");
|
|
18
|
-
const accountTransactionIdentifier_1 = require("../../factory/accountTransactionIdentifier");
|
|
19
|
-
const OfferService = require("../offer");
|
|
20
|
-
const AnyPaymentService = require("../payment/any");
|
|
21
|
-
const TransactionService = require("../transaction");
|
|
22
|
-
const findCreditCard_1 = require("./orderProgramMembership/findCreditCard");
|
|
23
|
-
const findPaymentCardPermit_1 = require("./orderProgramMembership/findPaymentCardPermit");
|
|
24
|
-
const factory = require("../../factory");
|
|
25
|
-
// import { credentials } from '../../credentials';
|
|
26
|
-
// import { settings } from '../../settings';
|
|
27
|
-
const debug = createDebug('chevre-domain:service:orderProgramMembership');
|
|
28
|
-
exports.ISS_PREFIX = 'https://cognito-idp.ap-northeast-1.amazonaws.com/';
|
|
29
|
-
/**
|
|
30
|
-
* メンバーシップ注文
|
|
31
|
-
*/
|
|
32
|
-
function orderProgramMembership(params, paymentMethodType) {
|
|
33
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
var _a, _b, _c;
|
|
35
|
-
let customer;
|
|
36
|
-
try {
|
|
37
|
-
customer = yield repos.person.findById({ userId: String(params.agent.id) });
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
// Not Found: User.をハンドル(2023-03-31~)
|
|
41
|
-
if (error instanceof factory.errors.NotFound) {
|
|
42
|
-
// no op
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (customer === undefined) {
|
|
49
|
-
// Userが存在しなければリトライは不要
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
// issに依存するので存在確認
|
|
53
|
-
const issByCustomer = (_b = (_a = customer.identifier) === null || _a === void 0 ? void 0 : _a.find((p) => p.name === 'iss')) === null || _b === void 0 ? void 0 : _b.value;
|
|
54
|
-
if (typeof issByCustomer !== 'string' || issByCustomer.length === 0) {
|
|
55
|
-
throw new factory.errors.NotFound(`iss of customer ${customer.id}`);
|
|
56
|
-
}
|
|
57
|
-
const acceptedOffer = params.object;
|
|
58
|
-
const sellerId = (_c = acceptedOffer.seller) === null || _c === void 0 ? void 0 : _c.id;
|
|
59
|
-
// if (typeof sellerId !== 'string') {
|
|
60
|
-
// // 互換性維持対応として↓
|
|
61
|
-
// sellerId = (<any>acceptedOffer.itemOffered)?.hostingOrganization?.id;
|
|
62
|
-
// }
|
|
63
|
-
if (typeof sellerId !== 'string') {
|
|
64
|
-
throw new factory.errors.NotFound('acceptedOffer seller ID undefined');
|
|
65
|
-
}
|
|
66
|
-
let transaction;
|
|
67
|
-
try {
|
|
68
|
-
// 注文取引開始
|
|
69
|
-
const startParams = createStartPlaceOrderInProgressParams({
|
|
70
|
-
project: params.project,
|
|
71
|
-
customer,
|
|
72
|
-
seller: { id: sellerId }
|
|
73
|
-
});
|
|
74
|
-
transaction = yield TransactionService.placeOrderInProgress.start(startParams)(repos);
|
|
75
|
-
// 取引ID上で注文プロセス
|
|
76
|
-
yield processPlaceOrder({
|
|
77
|
-
acceptedOffer: acceptedOffer,
|
|
78
|
-
customer: customer,
|
|
79
|
-
potentialActions: params.potentialActions,
|
|
80
|
-
project: { id: params.project.id },
|
|
81
|
-
transaction: transaction,
|
|
82
|
-
paymentMethodType
|
|
83
|
-
// iss
|
|
84
|
-
})(repos);
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
debug('processPlaceOrder throwed an error.', error);
|
|
88
|
-
try {
|
|
89
|
-
if (typeof (transaction === null || transaction === void 0 ? void 0 : transaction.id) === 'string') {
|
|
90
|
-
yield OfferService.product.voidTransaction({
|
|
91
|
-
agent: { id: customer.id },
|
|
92
|
-
project: { typeOf: factory.organizationType.Project, id: params.project.id },
|
|
93
|
-
purpose: { typeOf: transaction.typeOf, id: transaction.id }
|
|
94
|
-
})(repos);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
// 失敗したら仕方ない
|
|
99
|
-
}
|
|
100
|
-
// 決済に関してクライアントエラーであれば、リトライしても無駄なので、正常終了
|
|
101
|
-
if (error instanceof factory.errors.Argument
|
|
102
|
-
&& (error.argumentName === 'payment' || error.argumentName === 'ChevreArgument')) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
// すでに登録済のエラーハンドリング
|
|
106
|
-
if (error instanceof factory.errors.Argument && error.message
|
|
107
|
-
=== OfferService.product.ERROR_MESSAGE_ALREADY_REGISTERED) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
// Not Found: OwnershipInfos of PaymentCard.をハンドル(2023-03-31~)
|
|
111
|
-
if (error instanceof factory.errors.NotFound && error.entityName === 'OwnershipInfos of PaymentCard') {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
throw error;
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
exports.orderProgramMembership = orderProgramMembership;
|
|
119
|
-
function createStartPlaceOrderInProgressParams(params) {
|
|
120
|
-
var _a;
|
|
121
|
-
const customer = params.customer;
|
|
122
|
-
const agent = {
|
|
123
|
-
typeOf: customer.typeOf,
|
|
124
|
-
id: customer.id,
|
|
125
|
-
identifier: customer.identifier,
|
|
126
|
-
memberOf: customer.memberOf
|
|
127
|
-
};
|
|
128
|
-
return {
|
|
129
|
-
project: { typeOf: factory.organizationType.Project, id: params.project.id },
|
|
130
|
-
// expiresInSeconds指定に変更(2022-11-29~)
|
|
131
|
-
// expires: moment()
|
|
132
|
-
// // tslint:disable-next-line:no-magic-numbers
|
|
133
|
-
// .add(5, 'minutes')
|
|
134
|
-
// .toDate(),
|
|
135
|
-
expiresInSeconds: 300,
|
|
136
|
-
agent,
|
|
137
|
-
seller: { id: params.seller.id },
|
|
138
|
-
object: {
|
|
139
|
-
customer: Object.assign(Object.assign({ typeOf: customer.typeOf, id: customer.id }, (Array.isArray(customer.identifier)) ? { identifier: customer.identifier } : undefined), (typeof ((_a = customer.memberOf) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? { memberOf: customer.memberOf } : undefined)
|
|
140
|
-
},
|
|
141
|
-
validateSeller: false
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* メンバーシップを注文する
|
|
146
|
-
*/
|
|
147
|
-
function processPlaceOrder(params) {
|
|
148
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
149
|
-
var _a, _b, _c;
|
|
150
|
-
const now = new Date();
|
|
151
|
-
const acceptedOffer = params.acceptedOffer;
|
|
152
|
-
const customer = params.customer;
|
|
153
|
-
const transaction = params.transaction;
|
|
154
|
-
// プロダクト情報取得
|
|
155
|
-
// membershipForへの依存排除
|
|
156
|
-
let productId = (_a = acceptedOffer.itemOffered.issuedThrough) === null || _a === void 0 ? void 0 : _a.id;
|
|
157
|
-
if (typeof productId !== 'string') {
|
|
158
|
-
// 互換性維持対応として↓
|
|
159
|
-
productId = (_b = acceptedOffer.itemOffered.membershipFor) === null || _b === void 0 ? void 0 : _b.id;
|
|
160
|
-
}
|
|
161
|
-
if (typeof productId !== 'string') {
|
|
162
|
-
throw new Error('acceptedOffer.itemOffered.issuedThrough.id or acceptedOffer.itemOffered.membershipFor.id undefined');
|
|
163
|
-
}
|
|
164
|
-
// 注文番号を先に発行
|
|
165
|
-
const orderNumber = yield TransactionService.placeOrderInProgress.publishOrderNumberIfNotExist({
|
|
166
|
-
project: { id: transaction.project.id },
|
|
167
|
-
id: transaction.id,
|
|
168
|
-
object: { orderDate: now }
|
|
169
|
-
})(repos);
|
|
170
|
-
// メンバーシップオファー承認
|
|
171
|
-
let authorizeProductOfferAction;
|
|
172
|
-
authorizeProductOfferAction = yield processAuthorizeProductOffer({
|
|
173
|
-
project: { id: params.project.id },
|
|
174
|
-
orderNumber,
|
|
175
|
-
customer: customer,
|
|
176
|
-
transaction: transaction,
|
|
177
|
-
acceptedOffer: acceptedOffer,
|
|
178
|
-
product: { id: productId },
|
|
179
|
-
// iss: params.iss,
|
|
180
|
-
now
|
|
181
|
-
})(repos);
|
|
182
|
-
const amount = Number((_c = authorizeProductOfferAction.result) === null || _c === void 0 ? void 0 : _c.price);
|
|
183
|
-
if (amount > 0) {
|
|
184
|
-
yield processAuthorizeCreditCard({
|
|
185
|
-
project: { id: params.project.id },
|
|
186
|
-
customer: customer,
|
|
187
|
-
object: { amount },
|
|
188
|
-
purpose: transaction,
|
|
189
|
-
paymentMethodType: params.paymentMethodType
|
|
190
|
-
// iss: params.iss
|
|
191
|
-
})(repos);
|
|
192
|
-
}
|
|
193
|
-
yield TransactionService.updateAgent({
|
|
194
|
-
typeOf: transaction.typeOf,
|
|
195
|
-
id: transaction.id,
|
|
196
|
-
agent: {
|
|
197
|
-
typeOf: customer.typeOf,
|
|
198
|
-
id: customer.id,
|
|
199
|
-
email: customer.email,
|
|
200
|
-
familyName: customer.familyName,
|
|
201
|
-
givenName: customer.givenName,
|
|
202
|
-
telephone: customer.telephone
|
|
203
|
-
}
|
|
204
|
-
})(repos);
|
|
205
|
-
// 取引確定
|
|
206
|
-
return TransactionService.placeOrderInProgress.confirm({
|
|
207
|
-
project: { id: params.project.id },
|
|
208
|
-
id: transaction.id,
|
|
209
|
-
agent: { id: customer.id },
|
|
210
|
-
result: {
|
|
211
|
-
order: {
|
|
212
|
-
// new DateにしないとここまでのAuthorizeActionが取引に含まれない
|
|
213
|
-
orderDate: new Date()
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
potentialActions: params.potentialActions
|
|
217
|
-
})(repos);
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
function processAuthorizeProductOffer(params) {
|
|
221
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
222
|
-
var _a, _b, _c, _d;
|
|
223
|
-
const acceptedOffer = params.acceptedOffer;
|
|
224
|
-
const customer = params.customer;
|
|
225
|
-
const transaction = params.transaction;
|
|
226
|
-
const project = { typeOf: factory.organizationType.Project, id: params.project.id };
|
|
227
|
-
const seller = {
|
|
228
|
-
// project: project,
|
|
229
|
-
typeOf: transaction.seller.typeOf,
|
|
230
|
-
id: transaction.seller.id,
|
|
231
|
-
name: transaction.seller.name
|
|
232
|
-
};
|
|
233
|
-
// オファーにポイント特典設定があるかどうか確認
|
|
234
|
-
let pointAward;
|
|
235
|
-
const { offers } = yield OfferService.product.search({
|
|
236
|
-
project: { id: params.project.id },
|
|
237
|
-
itemOffered: { id: params.product.id },
|
|
238
|
-
seller: { id: String(seller.id) },
|
|
239
|
-
onlyValid: true,
|
|
240
|
-
addSortIndex: false
|
|
241
|
-
})(repos);
|
|
242
|
-
const acceptedProductOffer = offers.find((o) => o.identifier === acceptedOffer.identifier);
|
|
243
|
-
if (acceptedProductOffer === undefined) {
|
|
244
|
-
throw new factory.errors.NotFound('Offer', `Accepted offer ${acceptedOffer.identifier} not found`);
|
|
245
|
-
}
|
|
246
|
-
const pointAwardByOffer = (_a = acceptedProductOffer.itemOffered) === null || _a === void 0 ? void 0 : _a.pointAward;
|
|
247
|
-
const pointAwardAccountType = (_b = pointAwardByOffer === null || pointAwardByOffer === void 0 ? void 0 : pointAwardByOffer.amount) === null || _b === void 0 ? void 0 : _b.currency;
|
|
248
|
-
if (typeof ((_c = pointAwardByOffer === null || pointAwardByOffer === void 0 ? void 0 : pointAwardByOffer.amount) === null || _c === void 0 ? void 0 : _c.value) === 'number' && typeof pointAwardAccountType === 'string') {
|
|
249
|
-
const toPermit = yield (0, findPaymentCardPermit_1.findPaymentCardPermit)({
|
|
250
|
-
customer: { id: params.customer.id },
|
|
251
|
-
project: transaction.project,
|
|
252
|
-
now: params.now,
|
|
253
|
-
accountType: pointAwardAccountType
|
|
254
|
-
// iss: params.iss
|
|
255
|
-
})(repos);
|
|
256
|
-
const identifier = (0, accountTransactionIdentifier_1.createPointAwardIdentifier)({
|
|
257
|
-
project: params.project,
|
|
258
|
-
purpose: { orderNumber: params.orderNumber },
|
|
259
|
-
toLocation: { identifier: String(toPermit.identifier) }
|
|
260
|
-
});
|
|
261
|
-
const toLocationIssuedThroughId = (_d = toPermit.issuedThrough) === null || _d === void 0 ? void 0 : _d.id;
|
|
262
|
-
if (typeof toLocationIssuedThroughId !== 'string' || toLocationIssuedThroughId.length === 0) {
|
|
263
|
-
throw new factory.errors.NotFound('toPermit.issuedThrough.id');
|
|
264
|
-
}
|
|
265
|
-
pointAward = {
|
|
266
|
-
typeOf: factory.actionType.MoneyTransfer,
|
|
267
|
-
toLocation: {
|
|
268
|
-
identifier: String(toPermit.identifier),
|
|
269
|
-
issuedThrough: { id: toLocationIssuedThroughId },
|
|
270
|
-
typeOf: factory.permit.PermitType.Permit
|
|
271
|
-
},
|
|
272
|
-
recipient: {
|
|
273
|
-
id: customer.id,
|
|
274
|
-
name: `${customer.givenName} ${customer.familyName}`,
|
|
275
|
-
typeOf: customer.typeOf
|
|
276
|
-
},
|
|
277
|
-
// 特典識別子を指定(ユニークネスを保証するため)
|
|
278
|
-
purpose: { identifier }
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
const serviceOutputName = (typeof acceptedOffer.itemOffered.name === 'string')
|
|
282
|
-
? acceptedOffer.itemOffered.name
|
|
283
|
-
: undefined;
|
|
284
|
-
const object = [{
|
|
285
|
-
// project: project,
|
|
286
|
-
typeOf: acceptedProductOffer.typeOf,
|
|
287
|
-
id: acceptedProductOffer.id,
|
|
288
|
-
priceCurrency: acceptedProductOffer.priceCurrency,
|
|
289
|
-
itemOffered: Object.assign({
|
|
290
|
-
// project: project,
|
|
291
|
-
typeOf: factory.product.ProductType.MembershipService, id: params.product.id, serviceOutput: Object.assign({ project: project, typeOf: acceptedOffer.itemOffered.typeOf }, (typeof serviceOutputName === 'string') ? { name: serviceOutputName } : undefined) }, (pointAward !== undefined) ? { pointAward } : undefined),
|
|
292
|
-
seller: seller
|
|
293
|
-
}];
|
|
294
|
-
// メンバーシップオファー承認
|
|
295
|
-
return OfferService.product.authorize({
|
|
296
|
-
project: { typeOf: factory.organizationType.Project, id: params.project.id },
|
|
297
|
-
agent: { id: customer.id, typeOf: customer.typeOf },
|
|
298
|
-
object: object,
|
|
299
|
-
transaction: { id: transaction.id }
|
|
300
|
-
// iss: params.iss
|
|
301
|
-
})(repos);
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
function processAuthorizeCreditCard(params) {
|
|
305
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
306
|
-
// 会員クレジットカード検索(事前にクレジットカードを登録しているはず)
|
|
307
|
-
const creditCard = yield (0, findCreditCard_1.findCreditCard)({
|
|
308
|
-
project: { id: params.project.id },
|
|
309
|
-
customer: { id: params.customer.id },
|
|
310
|
-
paymentMethodType: params.paymentMethodType
|
|
311
|
-
})(repos);
|
|
312
|
-
// 決済サービスを検索
|
|
313
|
-
const searchCreditCardPaymentServicesResult = yield repos.product.search({
|
|
314
|
-
limit: 1,
|
|
315
|
-
page: 1,
|
|
316
|
-
project: { id: { $eq: params.project.id } },
|
|
317
|
-
typeOf: { $eq: factory.service.paymentService.PaymentServiceType.CreditCard },
|
|
318
|
-
serviceType: { codeValue: { $eq: params.paymentMethodType } }
|
|
319
|
-
}, [], []);
|
|
320
|
-
const creditCardPaymentService = searchCreditCardPaymentServicesResult.shift();
|
|
321
|
-
if (creditCardPaymentService === undefined) {
|
|
322
|
-
throw new factory.errors.NotFound('CreditCardPaymentService');
|
|
323
|
-
}
|
|
324
|
-
yield AnyPaymentService.authorize({
|
|
325
|
-
project: { id: params.project.id },
|
|
326
|
-
agent: params.customer,
|
|
327
|
-
object: {
|
|
328
|
-
typeOf: factory.action.authorize.paymentMethod.any.ResultType.Payment,
|
|
329
|
-
paymentMethod: params.paymentMethodType,
|
|
330
|
-
amount: params.object.amount,
|
|
331
|
-
method: GMO.utils.util.Method.Lump,
|
|
332
|
-
creditCard: {
|
|
333
|
-
// memberId: creditCard.memberId, // chevre側で自動変換される
|
|
334
|
-
memberId: params.customer.id,
|
|
335
|
-
cardSeq: Number(creditCard.cardSeq)
|
|
336
|
-
},
|
|
337
|
-
issuedThrough: { id: String(creditCardPaymentService.id) }
|
|
338
|
-
},
|
|
339
|
-
purpose: params.purpose,
|
|
340
|
-
paymentServiceType: factory.service.paymentService.PaymentServiceType.CreditCard,
|
|
341
|
-
options: {
|
|
342
|
-
useCancelPayTransactionOnFailed: false,
|
|
343
|
-
useCheckMovieTicketBeforePay: false,
|
|
344
|
-
useCheckByIdentifierIfNotYet: false,
|
|
345
|
-
useSearchTrade4accountId: false
|
|
346
|
-
}
|
|
347
|
-
})(repos);
|
|
348
|
-
});
|
|
349
|
-
}
|