@chevre/domain 21.36.0-alpha.2 → 21.36.0-alpha.4

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.
@@ -0,0 +1,54 @@
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 project = { id: String(process.env.PROJECT_ID) };
8
+
9
+ async function main() {
10
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
+
12
+ const transactionRepo = await chevre.repository.Transaction.createInstance(mongoose.connection);
13
+
14
+ const cursor = transactionRepo.getCursor(
15
+ {
16
+ // typeOf: { $eq: chevre.factory.actionType.AuthorizeAction },
17
+ status: { $eq: chevre.factory.transactionStatusType.Confirmed },
18
+ startDate: {
19
+ $gte: moment()
20
+ // tslint:disable-next-line:no-magic-numbers
21
+ .add(-1, 'days')
22
+ .toDate()
23
+ }
24
+ },
25
+ {
26
+ // project: 1,
27
+ // typeOf: 1,
28
+ // startDate: 1,
29
+ // object: 1,
30
+ // result: 1
31
+ }
32
+ );
33
+ console.log('transactions found');
34
+
35
+ let i = 0;
36
+ await cursor.eachAsync(async (doc) => {
37
+ i += 1;
38
+ const transaction: chevre.factory.transaction.ITransaction<chevre.factory.transactionType> = doc.toObject();
39
+
40
+ const size = JSON.stringify(transaction).length;
41
+ // tslint:disable-next-line:no-magic-numbers
42
+ if (size > 4000) {
43
+ console.log(
44
+ 'size:', JSON.stringify(transaction).length,
45
+ transaction.typeOf, transaction.project.id, transaction.startDate, transaction.id, i);
46
+ }
47
+ });
48
+
49
+ console.log(i, 'transactions checked');
50
+ }
51
+
52
+ main()
53
+ .then()
54
+ .catch(console.error);
@@ -109,7 +109,7 @@ class CognitoRepository {
109
109
  // tslint:disable-next-line:no-single-line-block-comment
110
110
  /* istanbul ignore if */
111
111
  if (!phoneUtil.isValidNumber(phoneNumber)) {
112
- throw new Error('Invalid phone number');
112
+ throw new factory.errors.Argument('telephone', 'Invalid phone number');
113
113
  }
114
114
  formatedPhoneNumber = phoneUtil.format(phoneNumber, google_libphonenumber_1.PhoneNumberFormat.E164);
115
115
  }
@@ -153,7 +153,7 @@ class CognitoRepository {
153
153
  // tslint:disable-next-line:no-single-line-block-comment
154
154
  /* istanbul ignore if */
155
155
  if (!phoneUtil.isValidNumber(phoneNumber)) {
156
- throw new Error('Invalid phone number');
156
+ throw new factory.errors.Argument('custom:telephone', 'Invalid phone number');
157
157
  }
158
158
  userAttributesValue = phoneUtil.format(phoneNumber, google_libphonenumber_1.PhoneNumberFormat.E164);
159
159
  }
@@ -292,7 +292,7 @@ function createPermitServiceCredentials(params) {
292
292
  || typeof permitServiceAuthorizeServerDomain !== 'string' || permitServiceAuthorizeServerDomain.length === 0
293
293
  || typeof permitServiceClientId !== 'string' || permitServiceClientId.length === 0
294
294
  || typeof permitServiceClientSecret !== 'string' || permitServiceClientSecret.length === 0) {
295
- throw new Error('membershipService availableChannel invalid');
295
+ throw new factory.errors.Internal('membershipService availableChannel invalid');
296
296
  }
297
297
  return {
298
298
  permitServiceEndpoint,
@@ -155,7 +155,7 @@ function createPermitService(params) {
155
155
  || typeof permitServiceAuthorizeServerDomain !== 'string' || permitServiceAuthorizeServerDomain.length === 0
156
156
  || typeof permitServiceClientId !== 'string' || permitServiceClientId.length === 0
157
157
  || typeof permitServiceClientSecret !== 'string' || permitServiceClientSecret.length === 0) {
158
- throw new Error('product availableChannel invalid');
158
+ throw new factory.errors.Internal('product availableChannel invalid');
159
159
  }
160
160
  return new (yield pecorinoapi.loadPecorino()).service.Permit({
161
161
  endpoint: permitServiceEndpoint,
@@ -695,7 +695,7 @@ function createPermitService(params) {
695
695
  || typeof permitServiceAuthorizeServerDomain !== 'string' || permitServiceAuthorizeServerDomain.length === 0
696
696
  || typeof permitServiceClientId !== 'string' || permitServiceClientId.length === 0
697
697
  || typeof permitServiceClientSecret !== 'string' || permitServiceClientSecret.length === 0) {
698
- throw new Error('product availableChannel invalid');
698
+ throw new factory.errors.Internal('product availableChannel invalid');
699
699
  }
700
700
  return new (yield pecorinoapi.loadPecorino()).service.Permit({
701
701
  endpoint: permitServiceEndpoint,
@@ -348,7 +348,7 @@ function createPermitServiceCredentials(params) {
348
348
  || typeof permitServiceAuthorizeServerDomain !== 'string' || permitServiceAuthorizeServerDomain.length === 0
349
349
  || typeof permitServiceClientId !== 'string' || permitServiceClientId.length === 0
350
350
  || typeof permitServiceClientSecret !== 'string' || permitServiceClientSecret.length === 0) {
351
- throw new Error('membershipService availableChannel invalid');
351
+ throw new factory.errors.Internal('membershipService availableChannel invalid');
352
352
  }
353
353
  return {
354
354
  permitServiceEndpoint,
@@ -106,7 +106,7 @@ function sendEmailMessage(params) {
106
106
  const response = yield sgMail.sendMultiple(msg);
107
107
  // check the response.
108
108
  if (response[0].statusCode !== http_status_1.ACCEPTED) {
109
- throw new Error(`sendgrid request not accepted. response is ${util.inspect(response)}`);
109
+ throw new factory.errors.Internal(`sendgrid request not accepted. response is ${util.inspect(response)}`);
110
110
  }
111
111
  const { statusCode, statusMessage } = response[0];
112
112
  result = { statusCode, statusMessage };
@@ -130,7 +130,7 @@ function lineNotify({ subject, content, imageThumbnail, imageFullsize, logLevel
130
130
  var _a;
131
131
  const LINE_NOTIFY_URL = credentials_1.credentials.lineNotify.url;
132
132
  if (typeof LINE_NOTIFY_URL !== 'string') {
133
- throw new Error('Environment variable LINE_NOTIFY_URL not set');
133
+ throw new factory.errors.Internal('Environment variable LINE_NOTIFY_URL not set');
134
134
  }
135
135
  let accessToken;
136
136
  switch (logLevel) {
@@ -144,7 +144,7 @@ function lineNotify({ subject, content, imageThumbnail, imageFullsize, logLevel
144
144
  accessToken = credentials_1.credentials.lineNotify.accessToken;
145
145
  }
146
146
  if (typeof accessToken !== 'string') {
147
- throw new Error('credentials.lineNotify.accessToken not set');
147
+ throw new factory.errors.Internal('credentials.lineNotify.accessToken not set');
148
148
  }
149
149
  const shortSubject = (subject.length > MAX_LINE_NOTIFY_SUBJECT_LENGTH)
150
150
  ? `${subject.slice(0, MAX_LINE_NOTIFY_SUBJECT_LENGTH)}...`
@@ -178,7 +178,7 @@ function lineNotify({ subject, content, imageThumbnail, imageFullsize, logLevel
178
178
  case http_status_1.OK:
179
179
  break;
180
180
  default:
181
- throw new Error(`${res.status} ${body === null || body === void 0 ? void 0 : body.message}`);
181
+ throw new factory.errors.Internal(`${res.status} ${body === null || body === void 0 ? void 0 : body.message}`);
182
182
  }
183
183
  }
184
184
  catch (err) {
@@ -267,7 +267,7 @@ function processInformAction(params) {
267
267
  };
268
268
  break;
269
269
  default:
270
- throw new Error(`statusCode: ${res.status} body: ${body}`);
270
+ throw new factory.errors.Internal(`statusCode: ${res.status} body: ${body}`);
271
271
  }
272
272
  }
273
273
  catch (err) {
@@ -1,9 +1,7 @@
1
1
  import type { MongoRepository as TaskRepo } from '../../../../repo/task';
2
2
  import * as factory from '../../../../factory';
3
3
  declare function createSendEmailMessageTaskIfNotExist(params: {
4
- potentialActions?: {
5
- sendEmailMessage?: Pick<factory.action.transfer.send.message.email.IAttributes, 'object'>[];
6
- };
4
+ sendEmailMessage?: Pick<factory.action.transfer.send.message.email.IAttributes, 'object'>[];
7
5
  order: Pick<factory.order.IOrder, 'customer' | 'orderDate' | 'orderNumber' | 'price' | 'priceCurrency' | 'project' | 'typeOf'>;
8
6
  }): (repos: {
9
7
  task: TaskRepo;
@@ -14,8 +14,7 @@ const util = require("util");
14
14
  const factory = require("../../../../factory");
15
15
  function createSendEmailMessageTaskIfNotExist(params) {
16
16
  return (repos) => __awaiter(this, void 0, void 0, function* () {
17
- var _a;
18
- const sendEmailMessageActions = (_a = params.potentialActions) === null || _a === void 0 ? void 0 : _a.sendEmailMessage;
17
+ const sendEmailMessageActions = params.sendEmailMessage;
19
18
  const now = new Date();
20
19
  if (Array.isArray(sendEmailMessageActions)) {
21
20
  yield Promise.all(sendEmailMessageActions.map((sendEmailMessageAction, index) => __awaiter(this, void 0, void 0, function* () {
@@ -22,10 +22,11 @@ const factory_1 = require("./onOrderProcessing/factory");
22
22
  const debug = createDebug('chevre-domain:service:order');
23
23
  function onOrderProcessing(params) {
24
24
  return (repos) => __awaiter(this, void 0, void 0, function* () {
25
- var _a, _b, _c, _d, _e;
25
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
26
26
  debug('onOrderStatusChanged called.', params.order.orderNumber, params.order.orderStatus, params.order.orderDate);
27
27
  let tasks = [];
28
- const sendOrderPotentialActions = (_e = (_d = (_c = (_b = (_a = params.placeOrderTransaction) === null || _a === void 0 ? void 0 : _a.potentialActions) === null || _b === void 0 ? void 0 : _b.order) === null || _c === void 0 ? void 0 : _c.potentialActions) === null || _d === void 0 ? void 0 : _d.sendOrder) === null || _e === void 0 ? void 0 : _e.potentialActions;
28
+ const sendEmailMessageByOrderPotentialActions = (_f = (_e = (_d = (_c = (_b = (_a = params.placeOrderTransaction) === null || _a === void 0 ? void 0 : _a.potentialActions) === null || _b === void 0 ? void 0 : _b.order) === null || _c === void 0 ? void 0 : _c.potentialActions) === null || _d === void 0 ? void 0 : _d.sendOrder) === null || _e === void 0 ? void 0 : _e.potentialActions) === null || _f === void 0 ? void 0 : _f.sendEmailMessage;
29
+ const sendEmailMessageByOnOrderProcessing = (_k = (_j = (_h = (_g = params.placeOrderTransaction) === null || _g === void 0 ? void 0 : _g.potentialActions) === null || _h === void 0 ? void 0 : _h.order) === null || _j === void 0 ? void 0 : _j.onOrderProcessing) === null || _k === void 0 ? void 0 : _k.sendEmailMessage;
29
30
  // const maskedCustomer = createMaskedCustomer(params.order, { noProfile: true });
30
31
  const simpleOrder = {
31
32
  typeOf: params.order.typeOf,
@@ -70,7 +71,10 @@ function onOrderProcessing(params) {
70
71
  // })(repos);
71
72
  // OrderProcessingにおけるEメール送信に対応(2024-01-17~)
72
73
  yield (0, createSendEmailMessageTaskIfNotExist_1.createSendEmailMessageTaskIfNotExist)({
73
- potentialActions: sendOrderPotentialActions,
74
+ sendEmailMessage: [
75
+ ...(Array.isArray(sendEmailMessageByOrderPotentialActions)) ? sendEmailMessageByOrderPotentialActions : [],
76
+ ...(Array.isArray(sendEmailMessageByOnOrderProcessing)) ? sendEmailMessageByOnOrderProcessing : []
77
+ ],
74
78
  order: params.order
75
79
  })(repos);
76
80
  break;
@@ -54,7 +54,7 @@ function placeOrder(params) {
54
54
  const orderActionAttributes = {
55
55
  agent: (typeof ((_a = params.agent) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? params.agent : placeOrderTransaction.project,
56
56
  object: simpleOrder,
57
- potentialActions: {},
57
+ // potentialActions: {}, // discontinue(2024-06-28~)
58
58
  project: placeOrderTransaction.project,
59
59
  purpose: orderActionPurpose,
60
60
  typeOf: factory.actionType.OrderAction
@@ -34,7 +34,7 @@ function placeOrderWithoutTransaction(params) {
34
34
  const orderActionAttributes = {
35
35
  agent: (typeof ((_a = params.agent) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? params.agent : order.project,
36
36
  object: simpleOrder,
37
- potentialActions: {},
37
+ // potentialActions: {}, // discontinue(2024-06-28~)
38
38
  project: order.project,
39
39
  // purpose: { typeOf: placeOrderTransaction.typeOf, id: placeOrderTransaction.id },
40
40
  typeOf: factory.actionType.OrderAction
@@ -36,7 +36,7 @@ function onReturnFeePaid(params, project) {
36
36
  var _a, _b;
37
37
  const orderNumber = (_b = (_a = params.purpose) === null || _a === void 0 ? void 0 : _a.object) === null || _b === void 0 ? void 0 : _b.orderNumber;
38
38
  if (typeof orderNumber !== 'string') {
39
- throw new Error('params.purpose.object.orderNumber not string');
39
+ throw new factory.errors.Internal('params.purpose.object.orderNumber not string');
40
40
  }
41
41
  // 経理レポートに決済アクションを追加
42
42
  const action4save = Object.assign(Object.assign(Object.assign({}, params), { startDate: moment(params.startDate)
@@ -59,7 +59,7 @@ function onOrderPaid(params, project) {
59
59
  var _a;
60
60
  const orderNumber = (_a = params.purpose) === null || _a === void 0 ? void 0 : _a.orderNumber;
61
61
  if (typeof orderNumber !== 'string') {
62
- throw new Error('params.purpose.orderNumber not string');
62
+ throw new factory.errors.Internal('params.purpose.orderNumber not string');
63
63
  }
64
64
  // 経理レポートに決済アクションを追加
65
65
  const action4save = Object.assign(Object.assign(Object.assign({}, params), { startDate: moment(params.startDate)
@@ -32,7 +32,7 @@ function onOrderRefunded(params, project) {
32
32
  var _a, _b;
33
33
  const orderNumber = (_b = (_a = params.purpose) === null || _a === void 0 ? void 0 : _a.object) === null || _b === void 0 ? void 0 : _b.orderNumber;
34
34
  if (typeof orderNumber !== 'string') {
35
- throw new Error('params.purpose.orderNumber not string');
35
+ throw new factory.errors.Internal('params.purpose.orderNumber not string');
36
36
  }
37
37
  // 経理レポートに決済アクションを追加
38
38
  const action4save = Object.assign(Object.assign(Object.assign({}, params), { startDate: moment(params.startDate)
@@ -97,7 +97,7 @@ function execute(task) {
97
97
  const taskExpired = moment(now)
98
98
  .isAfter(task.expires);
99
99
  if (taskExpired) {
100
- throw new Error(`task expired [expires:${task.expires}]`);
100
+ throw new factory.errors.Internal(`task expired [expires:${task.expires}]`);
101
101
  }
102
102
  }
103
103
  // タスク名の関数が定義されていなければ、TypeErrorとなる
@@ -9,5 +9,5 @@ export declare function createSendEmailMessageActions(params: {
9
9
  useOptimizedSendEmailAction: boolean;
10
10
  }): Promise<{
11
11
  emailMessages: factory.action.transfer.send.message.email.IObjectAsEmailMessage[];
12
- sendEmailMessageActions: factory.action.trade.order.IPotentialSendEmailMessageAction[];
12
+ sendEmailMessageActions: factory.transaction.placeOrder.IPotentialSendEmailMessageAction[];
13
13
  }>;
@@ -11,32 +11,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.createPotentialActions = void 0;
13
13
  const sendEmailMessage_1 = require("./potentialActions/sendEmailMessage");
14
+ const settings_1 = require("../../../settings");
14
15
  /**
15
16
  * 取引のポストアクションを作成する
16
17
  */
17
18
  function createPotentialActions(params) {
18
19
  return __awaiter(this, void 0, void 0, function* () {
19
- // ポイントインセンティブに対する承認アクションの分だけ、ポイントインセンティブ付与アクションを作成する
20
- // const givePointAwardActions = await createGivePointAwardActions(params); // 完全廃止(2024-03-12~)
21
- // 注文配送メール送信設定
20
+ // 注文処理開始メール送信設定
22
21
  const { emailMessages, sendEmailMessageActions } = yield (0, sendEmailMessage_1.createSendEmailMessageActions)(params);
23
22
  const sendOrderActionAttributes = {
24
- potentialActions: {
25
- // moneyTransfer: moneyTransferActions, // 廃止(2024-01-29~)
26
- // registerService: registerServiceActions, // 廃止(2024-01-30~)
27
- sendEmailMessage: sendEmailMessageActions
28
- }
23
+ potentialActions: { sendEmailMessage: sendEmailMessageActions }
29
24
  };
30
25
  return {
31
26
  emailMessages,
32
- // optimize(2024-01-22~)
33
27
  potentialActions: {
34
- order: {
35
- potentialActions: {
36
- // givePointAward: givePointAwardActions, // 完全廃止(2024-03-12~)
37
- sendOrder: sendOrderActionAttributes // optimize(2024-01-16~)
38
- }
39
- }
28
+ order: Object.assign({}, (settings_1.USE_EXPERIMENTAL_FEATURE)
29
+ ? { onOrderProcessing: { sendEmailMessage: sendEmailMessageActions } }
30
+ : { potentialActions: { sendOrder: sendOrderActionAttributes } } // optimize(2024-01-16~)
31
+ )
40
32
  }
41
33
  };
42
34
  });
@@ -297,7 +297,7 @@ function getReturnPolicyByProject(params) {
297
297
  });
298
298
  let body;
299
299
  try {
300
- body = yield res.json();
300
+ body = (yield res.json());
301
301
  }
302
302
  catch (error) {
303
303
  // no op
@@ -309,7 +309,7 @@ function getReturnPolicyByProject(params) {
309
309
  case http_status_1.ACCEPTED:
310
310
  case http_status_1.NO_CONTENT:
311
311
  if (typeof ((_a = body === null || body === void 0 ? void 0 : body.restockingFee) === null || _a === void 0 ? void 0 : _a.value) !== 'number') {
312
- throw new Error('invalid return policy');
312
+ throw new factory.errors.Internal('invalid return policy');
313
313
  }
314
314
  else {
315
315
  returnPolicy = Object.assign({ typeOf: 'MerchantReturnPolicy', restockingFee: {
@@ -34,7 +34,7 @@ function fixCustomer(params) {
34
34
  const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
35
35
  const phoneNumber = phoneUtil.parse(params.agent.telephone, params.agent.telephoneRegion);
36
36
  if (!phoneUtil.isValidNumber(phoneNumber)) {
37
- throw new Error('Invalid phone number');
37
+ throw new factory.errors.Argument('telephone', 'Invalid phone number');
38
38
  }
39
39
  formattedTelephone = phoneUtil.format(phoneNumber, google_libphonenumber_1.PhoneNumberFormat.E164);
40
40
  }
package/package.json CHANGED
@@ -10,8 +10,8 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "@aws-sdk/credential-providers": "3.433.0",
13
- "@chevre/factory": "4.376.0-alpha.0",
14
- "@cinerino/sdk": "8.0.0-alpha.2",
13
+ "@chevre/factory": "4.376.0-alpha.2",
14
+ "@cinerino/sdk": "8.0.0-alpha.3",
15
15
  "@motionpicture/coa-service": "9.4.0",
16
16
  "@motionpicture/gmo-service": "5.3.0",
17
17
  "@sendgrid/mail": "6.4.0",
@@ -110,5 +110,5 @@
110
110
  "postversion": "git push origin --tags",
111
111
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
112
112
  },
113
- "version": "21.36.0-alpha.2"
113
+ "version": "21.36.0-alpha.4"
114
114
  }