@chevre/domain 21.7.0-alpha.9 → 21.7.0

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 (49) hide show
  1. package/example/src/chevre/countDelayedTasks.ts +1 -1
  2. package/example/src/chevre/createDeleteTransactionTasks.ts +108 -0
  3. package/example/src/chevre/createDeleteTransactionTasksIfNotExist.ts +98 -0
  4. package/example/src/chevre/deleteRunsAtPassedCertainPeriod.ts +28 -0
  5. package/example/src/chevre/deleteTasksByName.ts +1 -1
  6. package/example/src/chevre/migrateAuthorizePaymentActionResult.ts +1 -1
  7. package/example/src/chevre/migrateOwnershipInfos2newUserPool.ts +4 -1
  8. package/example/src/chevre/unsetUnnecessaryFields.ts +1 -1
  9. package/lib/chevre/repo/mongoose/schemas/offer.d.ts +4 -4
  10. package/lib/chevre/repo/mongoose/schemas/offer.js +5 -6
  11. package/lib/chevre/repo/project.d.ts +1 -0
  12. package/lib/chevre/repo/project.js +10 -4
  13. package/lib/chevre/repo/task.d.ts +6 -2
  14. package/lib/chevre/repo/task.js +25 -1
  15. package/lib/chevre/repo/transaction.d.ts +25 -1
  16. package/lib/chevre/repo/transaction.js +6 -1
  17. package/lib/chevre/service/notification.js +13 -6
  18. package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +20 -0
  19. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +242 -1
  20. package/lib/chevre/service/order/onOrderStatusChanged.d.ts +2 -1
  21. package/lib/chevre/service/order/onOrderStatusChanged.js +120 -106
  22. package/lib/chevre/service/order/placeOrder.d.ts +1 -3
  23. package/lib/chevre/service/order/placeOrder.js +15 -74
  24. package/lib/chevre/service/order/returnOrder.d.ts +1 -2
  25. package/lib/chevre/service/order/returnOrder.js +15 -97
  26. package/lib/chevre/service/order/sendOrder.d.ts +0 -1
  27. package/lib/chevre/service/order/sendOrder.js +6 -68
  28. package/lib/chevre/service/payment/any/factory.js +2 -1
  29. package/lib/chevre/service/task/confirmRegisterServiceTransaction.d.ts +1 -1
  30. package/lib/chevre/service/task/confirmRegisterServiceTransaction.js +6 -6
  31. package/lib/chevre/service/transaction/moneyTransfer/factory.js +1 -5
  32. package/lib/chevre/service/transaction/moneyTransfer.js +0 -1
  33. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +12 -6
  34. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.d.ts +4 -0
  35. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.js +92 -88
  36. package/lib/chevre/service/transaction/placeOrderInProgress.js +0 -2
  37. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +8 -1
  38. package/lib/chevre/service/transaction/returnOrder/potentialActions.js +7 -4
  39. package/lib/chevre/service/transaction/returnOrder.js +0 -1
  40. package/lib/chevre/settings.d.ts +0 -1
  41. package/lib/chevre/settings.js +1 -2
  42. package/package.json +3 -3
  43. package/example/src/chevre/checkOrderMembershipTasks.ts +0 -127
  44. package/example/src/chevre/transaction/callOrderMembershipServiceTask.ts +0 -65
  45. package/example/src/chevre/transaction/orderMembershipService.ts +0 -105
  46. package/lib/chevre/service/task/orderProgramMembership.d.ts +0 -6
  47. package/lib/chevre/service/task/orderProgramMembership.js +0 -98
  48. package/lib/chevre/service/transaction/orderProgramMembership.d.ts +0 -50
  49. package/lib/chevre/service/transaction/orderProgramMembership.js +0 -349
@@ -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
- const orderProgramMembershipTask = createOrderProgramMembershipTask({
51
- order: params.order,
52
- // transaction: params.transaction,
53
- authorizeAction: a
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: Object.assign({}, (orderProgramMembershipTask !== undefined)
62
- ? { orderProgramMembership: [orderProgramMembershipTask] }
63
- : undefined)
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
- let orderMembershipTask;
85
- const acceptedOffer = params.authorizeAction.object[0];
86
- // ssktsへの互換性対応なので、限定的に(暫定対応のautomaticRenewal設定で判定)
87
- const serviceOutput = acceptedOffer.itemOffered.serviceOutput;
88
- if (acceptedOffer.itemOffered.typeOf === factory.product.ProductType.MembershipService
89
- && typeof (serviceOutput === null || serviceOutput === void 0 ? void 0 : serviceOutput.typeOf) === 'string'
90
- && serviceOutput.typeOf.length > 0
91
- && serviceOutput.automaticRenewal === true) {
92
- const memebershipFor = {
93
- project: { typeOf: factory.organizationType.Project, id: params.order.project.id },
94
- typeOf: acceptedOffer.itemOffered.typeOf,
95
- id: String(acceptedOffer.itemOffered.id)
96
- };
97
- const orderMembershipObject = {
98
- // ...acceptedOffer,
99
- // project: acceptedOffer.project,
100
- // priceCurrency: acceptedOffer.priceCurrency,
101
- // seller: acceptedOffer.seller,
102
- seller: { id: String(acceptedOffer.seller.id) },
103
- typeOf: acceptedOffer.typeOf,
104
- itemOffered: {
105
- // project: { typeOf: factory.organizationType.Project, id: params.order.project.id },
106
- typeOf: serviceOutput.typeOf,
107
- name: (typeof serviceOutput.name === 'string') ? serviceOutput.name : serviceOutput.typeOf,
108
- issuedThrough: { id: String(memebershipFor.id), typeOf: factory.product.ProductType.MembershipService }
109
- },
110
- id: String(acceptedOffer.id),
111
- identifier: String(acceptedOffer.identifier)
112
- };
113
- // 次回のメンバーシップ注文タスクを生成
114
- const orderProgramMembershipTaskData = {
115
- // 最低限の情報のみagentに設定
116
- agent: {
117
- typeOf: factory.personType.Person,
118
- id: params.order.customer.id,
119
- // transaction.agent.identifierにissがあれば情報を引き継ぐ
120
- identifier: (Array.isArray(params.order.customer.identifier))
121
- ? params.order.customer.identifier
122
- : []
123
- },
124
- object: orderMembershipObject,
125
- project: params.order.project,
126
- typeOf: factory.actionType.OrderAction
127
- };
128
- // どういう期間でいくらのオファーなのか
129
- const priceSpec = acceptedOffer.priceSpecification;
130
- if (priceSpec === undefined) {
131
- throw new factory.errors.NotFound('Order.acceptedOffers.priceSpecification');
132
- }
133
- const unitPriceSpec = priceSpec.priceComponent.find((p) => p.typeOf === factory.priceSpecificationType.UnitPriceSpecification);
134
- if (unitPriceSpec === undefined) {
135
- throw new factory.errors.NotFound('Unit Price Specification in Order.acceptedOffers.priceSpecification');
136
- }
137
- // 期間単位としては秒のみ実装
138
- if (unitPriceSpec.referenceQuantity.unitCode !== factory.unitCode.Sec) {
139
- throw new factory.errors.NotImplemented('Only \'SEC\' is implemented for priceSpecification.referenceQuantity.unitCode ');
140
- }
141
- const referenceQuantityValue = unitPriceSpec.referenceQuantity.value;
142
- if (typeof referenceQuantityValue !== 'number') {
143
- throw new factory.errors.NotFound('Order.acceptedOffers.priceSpecification.referenceQuantity.value');
144
- }
145
- // プログラム更新日時は、今回のプログラムの所有期限
146
- const runsAt = moment(params.order.orderDate)
147
- .add(referenceQuantityValue, 'seconds')
148
- .toDate();
149
- orderMembershipTask = {
150
- data: orderProgramMembershipTaskData,
151
- executionResults: [],
152
- name: factory.taskName.OrderProgramMembership,
153
- numberOfTried: 0,
154
- project: params.order.project,
155
- remainingNumberOfTries: 10,
156
- runsAt: runsAt,
157
- status: factory.taskStatus.Ready
158
- };
159
- }
160
- return orderMembershipTask;
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
+ // }
@@ -133,8 +133,6 @@ function confirm(params) {
133
133
  yield repos.transaction.confirm({
134
134
  typeOf: transaction.typeOf,
135
135
  id: transaction.id,
136
- // 保管有無を設定化(2023-05-16~)
137
- authorizeActions: [],
138
136
  result: result,
139
137
  potentialActions: potentialActions
140
138
  });
@@ -56,6 +56,13 @@ function createTasks(params) {
56
56
  if (Array.isArray(returnOrderPotentialActions)) {
57
57
  // 返品タスク
58
58
  const returnOrderTask = returnOrderPotentialActions.map((r) => {
59
+ // data最適化(2023-08-22~)
60
+ const returnOrderTaskData = {
61
+ agent: r.agent,
62
+ object: r.object,
63
+ project: transaction.project,
64
+ typeOf: r.typeOf
65
+ };
59
66
  return {
60
67
  project: transaction.project,
61
68
  name: factory.taskName.ReturnOrder,
@@ -64,7 +71,7 @@ function createTasks(params) {
64
71
  remainingNumberOfTries: 10,
65
72
  numberOfTried: 0,
66
73
  executionResults: [],
67
- data: r
74
+ data: returnOrderTaskData
68
75
  };
69
76
  });
70
77
  taskAttributes.push(...returnOrderTask);
@@ -52,7 +52,6 @@ function createPotentialActions(params) {
52
52
  },
53
53
  // mask
54
54
  customer: (0, order_1.createMaskedCustomer)(order, { noProfile: true }),
55
- // confirmationNumber: order.confirmationNumber,
56
55
  orderNumber: order.orderNumber,
57
56
  price: order.price,
58
57
  priceCurrency: order.priceCurrency,
@@ -60,9 +59,13 @@ function createPotentialActions(params) {
60
59
  dateReturned: params.dateReturned
61
60
  };
62
61
  // recipientを最低限の情報に
63
- const recipient = Object.assign({ id: order.seller.id, typeOf: order.seller.typeOf }, (order.seller.name !== undefined) ? { name: order.seller.name } : undefined);
62
+ // const recipient: factory.action.IParticipantAsSeller = {
63
+ // id: order.seller.id,
64
+ // typeOf: order.seller.typeOf,
65
+ // ...(order.seller.name !== undefined) ? { name: order.seller.name } : undefined
66
+ // };
64
67
  return {
65
- project: order.project,
68
+ // project: order.project,
66
69
  typeOf: factory.actionType.ReturnAction,
67
70
  object: returnOrderObject,
68
71
  // ↓agentは注文のreturnerに反映される
@@ -70,7 +73,7 @@ function createPotentialActions(params) {
70
73
  typeOf: params.transaction.agent.typeOf,
71
74
  id: params.transaction.agent.id
72
75
  },
73
- recipient,
76
+ // recipient,
74
77
  potentialActions: potentialActionsOnReturnOrder
75
78
  };
76
79
  })));
@@ -588,7 +588,6 @@ function confirm(params) {
588
588
  yield repos.transaction.confirm({
589
589
  typeOf: transaction.typeOf,
590
590
  id: transaction.id,
591
- authorizeActions: [],
592
591
  result: result,
593
592
  potentialActions: potentialActions
594
593
  });
@@ -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;
@@ -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.DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD = 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;
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.325.0-alpha.5",
13
- "@cinerino/sdk": "3.164.0",
12
+ "@chevre/factory": "4.326.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.9"
120
+ "version": "21.7.0"
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,65 +0,0 @@
1
- // tslint:disable:no-console
2
- import * as mongoose from 'mongoose';
3
- import * as redis from 'redis';
4
-
5
- import { chevre } from '../../../../lib/index';
6
-
7
- import { call } from '../../../../lib/chevre/service/task/orderProgramMembership';
8
-
9
- const project = { id: String(process.env.PROJECT_ID) };
10
- async function main() {
11
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
-
13
- const redisClient = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
14
- socket: {
15
- port: Number(<string>process.env.REDIS_PORT),
16
- host: <string>process.env.REDIS_HOST
17
- },
18
- password: <string>process.env.REDIS_KEY
19
- });
20
- await redisClient.connect();
21
-
22
- const result = await call(
23
- {
24
- agent: {
25
- typeOf: chevre.factory.personType.Person,
26
- id: 'b2bc2b6d-aea2-41fc-9f6e-e4ec89c11d2e',
27
- identifier: [
28
- {
29
- name: 'iss',
30
- value: String(process.env.ISS)
31
- }
32
- ]
33
- },
34
- object: {
35
- seller: {
36
- id: '5d0abf30ac3fb200198ebb2c'
37
- },
38
- typeOf: chevre.factory.offerType.Offer,
39
- itemOffered: {
40
- typeOf: chevre.factory.permit.PermitType.Permit,
41
- name: '[development]会員ポイントプログラム',
42
- issuedThrough: {
43
- id: '5afff104d51e59232c7b481b',
44
- typeOf: chevre.factory.product.ProductType.MembershipService
45
- }
46
- },
47
- id: '7k9f3ht34',
48
- identifier: 'AnnualPlan'
49
- },
50
- project: {
51
- typeOf: chevre.factory.organizationType.Project,
52
- id: project.id
53
- },
54
- typeOf: chevre.factory.actionType.OrderAction
55
- }
56
- )({
57
- connection: mongoose.connection,
58
- redisClient
59
- });
60
- console.log(result);
61
- }
62
-
63
- main()
64
- .then(console.log)
65
- .catch(console.error);
@@ -1,105 +0,0 @@
1
- // tslint:disable:no-console
2
- import * as mongoose from 'mongoose';
3
- import * as redis from 'redis';
4
-
5
- import { chevre } from '../../../../lib/index';
6
-
7
- import { orderProgramMembership } from '../../../../lib/chevre/service/transaction/orderProgramMembership';
8
-
9
- const project = { id: String(process.env.PROJECT_ID) };
10
- async function main() {
11
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
-
13
- const redisClient = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
14
- socket: {
15
- port: Number(<string>process.env.REDIS_PORT),
16
- host: <string>process.env.REDIS_HOST
17
- },
18
- password: <string>process.env.REDIS_KEY
19
- });
20
- await redisClient.connect();
21
-
22
- const personRepo = new chevre.repository.Person({ userPoolId: chevre.settings.settings.userPoolIdNew });
23
- const actionRepo = new chevre.repository.Action(mongoose.connection);
24
- const accountRepo = new chevre.repository.Account(mongoose.connection);
25
- const accountingReportRepo = new chevre.repository.AccountingReport(mongoose.connection);
26
- const assetTransactionRepo = new chevre.repository.AssetTransaction(mongoose.connection);
27
- const eventRepo = new chevre.repository.Event(mongoose.connection);
28
- const offerRepo = new chevre.repository.Offer(mongoose.connection);
29
- const offerCatalogRepo = new chevre.repository.OfferCatalog(mongoose.connection);
30
- const productRepo = new chevre.repository.Product(mongoose.connection);
31
- const projectRepo = new chevre.repository.Project(mongoose.connection);
32
- const ownershipInfoRepo = new chevre.repository.OwnershipInfo(mongoose.connection);
33
- const sellerRepo = new chevre.repository.Seller(mongoose.connection);
34
- const serviceOutputRepo = new chevre.repository.ServiceOutput(mongoose.connection);
35
- const taskRepo = new chevre.repository.Task(mongoose.connection);
36
- const transactionRepo = new chevre.repository.Transaction(mongoose.connection);
37
- const confirmationNumberRepo = new chevre.repository.ConfirmationNumber(redisClient);
38
- const orderNumberRepo = new chevre.repository.OrderNumber(redisClient);
39
- const registerServiceInProgressRepo = new chevre.repository.action.RegisterServiceInProgress(redisClient);
40
- const transactionNumberRepo = new chevre.repository.TransactionNumber(redisClient);
41
- const serviceOutputIdentifierRepo = new chevre.repository.ServiceOutputIdentifier(redisClient);
42
-
43
- const result = await orderProgramMembership(
44
- {
45
- agent: {
46
- typeOf: chevre.factory.personType.Person,
47
- id: 'b2bc2b6d-aea2-41fc-9f6e-e4ec89c11d2e',
48
- identifier: [
49
- {
50
- name: 'iss',
51
- value: String(process.env.ISS)
52
- }
53
- ]
54
- },
55
- object: {
56
- seller: {
57
- id: '5d0abf30ac3fb200198ebb2c'
58
- },
59
- typeOf: chevre.factory.offerType.Offer,
60
- itemOffered: {
61
- typeOf: chevre.factory.permit.PermitType.Permit,
62
- name: '[development]会員ポイントプログラム',
63
- issuedThrough: {
64
- id: '5afff104d51e59232c7b481b',
65
- typeOf: chevre.factory.product.ProductType.MembershipService
66
- }
67
- },
68
- id: '7k9f3ht34',
69
- identifier: 'AnnualPlan'
70
- },
71
- project: {
72
- typeOf: chevre.factory.organizationType.Project,
73
- id: project.id
74
- },
75
- typeOf: chevre.factory.actionType.OrderAction
76
- },
77
- 'CreditCard'
78
- )({
79
- account: accountRepo,
80
- accountingReport: accountingReportRepo,
81
- action: actionRepo,
82
- assetTransaction: assetTransactionRepo,
83
- confirmationNumber: confirmationNumberRepo,
84
- event: eventRepo,
85
- offer: offerRepo,
86
- offerCatalog: offerCatalogRepo,
87
- orderNumber: orderNumberRepo,
88
- ownershipInfo: ownershipInfoRepo,
89
- person: personRepo,
90
- product: productRepo,
91
- project: projectRepo,
92
- registerActionInProgress: registerServiceInProgressRepo,
93
- seller: sellerRepo,
94
- serviceOutput: serviceOutputRepo,
95
- serviceOutputIdentifier: serviceOutputIdentifierRepo,
96
- task: taskRepo,
97
- transaction: transactionRepo,
98
- transactionNumber: transactionNumberRepo
99
- });
100
- console.log(result);
101
- }
102
-
103
- main()
104
- .then(console.log)
105
- .catch(console.error);
@@ -1,6 +0,0 @@
1
- import { IOperation } from '../task';
2
- import * as factory from '../../factory';
3
- /**
4
- * タスク実行関数
5
- */
6
- export declare function call(data: factory.task.IData<factory.taskName.OrderProgramMembership>): IOperation<void>;