@chevre/domain 21.13.0-alpha.4 → 21.13.0-alpha.6

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,82 @@
1
+ // tslint:disable:no-console
2
+ import * as moment from 'moment';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ let connection: mongoose.Connection | undefined;
6
+ let mongoLastConnected: Date | undefined;
7
+ const MONGO_RETRY_INTERVAL_IN_MILLISECONDS = 1000;
8
+ const MONGO_GIVE_UP_IN_SECONDS = 5;
9
+ async function getConnection(): Promise<mongoose.Connection> {
10
+ if (mongoLastConnected instanceof Date) {
11
+ if (connection === undefined) {
12
+ if (moment()
13
+ .isAfter(moment(mongoLastConnected)
14
+ .add(MONGO_GIVE_UP_IN_SECONDS, 'seconds'))
15
+ ) {
16
+ mongoLastConnected = void 0;
17
+ }
18
+
19
+ // 最終接続から一定期間経過していればリトライ
20
+ connection = await new Promise<mongoose.Connection>((resolve, reject) => {
21
+ setTimeout(
22
+ async () => {
23
+ console.log('retrying...', mongoLastConnected);
24
+ try {
25
+ resolve(await getConnection());
26
+ } catch (error) {
27
+ reject(error);
28
+ }
29
+ },
30
+ MONGO_RETRY_INTERVAL_IN_MILLISECONDS
31
+ );
32
+ });
33
+ }
34
+ } else {
35
+ mongoLastConnected = new Date();
36
+ console.log('creating connection...', mongoLastConnected);
37
+ if (connection === undefined) {
38
+ connection = await new Promise<mongoose.Connection>((resolve) => {
39
+ setTimeout(
40
+ async () => {
41
+ resolve(await mongoose.createConnection(<string>process.env.MONGOLAB_URI, { autoIndex: false }));
42
+ },
43
+ // tslint:disable-next-line:no-magic-numbers
44
+ 2000
45
+ );
46
+ });
47
+ // throw new Error('failed in createConnection')
48
+ }
49
+ }
50
+
51
+ return connection;
52
+ }
53
+
54
+ getConnection()
55
+ .then(() => {
56
+ console.log('sucess!', mongoose.connections.length);
57
+ })
58
+ .catch((error) => {
59
+ console.error(error, mongoose.connections.length);
60
+ });
61
+ getConnection()
62
+ .then(() => {
63
+ console.log('sucess!', mongoose.connections.length);
64
+ })
65
+ .catch((error) => {
66
+ console.error(error, mongoose.connections.length);
67
+ });
68
+ getConnection()
69
+ .then(() => {
70
+ console.log('sucess!', mongoose.connections.length);
71
+ })
72
+ .catch((error) => {
73
+ console.error(error, mongoose.connections.length);
74
+ });
75
+ // setInterval(
76
+ // () => {
77
+ // getConnection()
78
+ // .then(console.log)
79
+ // .catch(console.error);
80
+ // },
81
+ // 1000
82
+ // );
@@ -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.loadGMO = exports.loadPecorinoapi = exports.settings = exports.service = exports.repository = exports.factory = exports.eventEmitter = exports.errorHandler = exports.credentials = void 0;
13
- // import * as surfrock from '@surfrock/sdk';
14
13
  const credentials_1 = require("./credentials");
15
14
  Object.defineProperty(exports, "credentials", { enumerable: true, get: function () { return credentials_1.credentials; } });
16
15
  const errorHandler = require("./errorHandler");
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * Pecorino API Client
3
3
  */
4
- import { auth, pecorino } from '@cinerino/sdk';
5
- export import service = pecorino.service;
6
- export import auth = auth;
4
+ import { auth, loadPecorino, pecorino } from '@cinerino/sdk';
5
+ export { auth, loadPecorino, pecorino };
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.auth = exports.service = void 0;
3
+ exports.loadPecorino = exports.auth = void 0;
4
4
  /**
5
5
  * Pecorino API Client
6
6
  */
7
7
  const sdk_1 = require("@cinerino/sdk");
8
- exports.service = sdk_1.pecorino.service;
9
- exports.auth = sdk_1.auth;
8
+ Object.defineProperty(exports, "auth", { enumerable: true, get: function () { return sdk_1.auth; } });
9
+ Object.defineProperty(exports, "loadPecorino", { enumerable: true, get: function () { return sdk_1.loadPecorino; } });
@@ -139,13 +139,6 @@ export declare class MongoRepository {
139
139
  }): Promise<Omit<factory.order.IOrder[], 'acceptedOffers'> & {
140
140
  acceptedOffers?: factory.order.IAcceptedOffer<factory.order.IItemOffered> | factory.order.IAcceptedOffer<factory.order.IItemOffered>[];
141
141
  }>;
142
- /**
143
- * 特典口座情報が未保管であれば保管する
144
- */
145
- saveAwardAccountsIfNotExist(parmas: {
146
- orderNumber: string;
147
- awardAccounts: factory.transaction.placeOrder.IAwardAccount[];
148
- }): Promise<void>;
149
142
  /**
150
143
  * 注文に含まれる予約番号を検索する
151
144
  */
@@ -13,7 +13,6 @@ exports.MongoRepository = void 0;
13
13
  const factory = require("../factory");
14
14
  const order_1 = require("./mongoose/schemas/order");
15
15
  const errorHandler_1 = require("../errorHandler");
16
- const order_2 = require("../factory/order");
17
16
  const settings_1 = require("../settings");
18
17
  /**
19
18
  * 注文リポジトリ
@@ -1022,21 +1021,25 @@ class MongoRepository {
1022
1021
  .exec();
1023
1022
  });
1024
1023
  }
1025
- /**
1026
- * 特典口座情報が未保管であれば保管する
1027
- */
1028
- saveAwardAccountsIfNotExist(parmas) {
1029
- return __awaiter(this, void 0, void 0, function* () {
1030
- if (Array.isArray(parmas.awardAccounts)) {
1031
- const newIdentifier = { name: order_2.AWARD_ACCOUNTS_IDENTIFIER_NAME, value: JSON.stringify(parmas.awardAccounts) };
1032
- yield this.orderModel.findOneAndUpdate({
1033
- orderNumber: { $eq: parmas.orderNumber },
1034
- 'identifier.name': { $ne: order_2.AWARD_ACCOUNTS_IDENTIFIER_NAME }
1035
- }, { $push: { identifier: newIdentifier } }, { new: true })
1036
- .exec();
1037
- }
1038
- });
1039
- }
1024
+ // 廃止(2023-10-15~)
1025
+ // public async saveAwardAccountsIfNotExist(parmas: {
1026
+ // orderNumber: string;
1027
+ // awardAccounts: factory.transaction.placeOrder.IAwardAccount[];
1028
+ // }) {
1029
+ // if (Array.isArray(parmas.awardAccounts)) {
1030
+ // const newIdentifier: factory.propertyValue.IPropertyValue<string>
1031
+ // = { name: AWARD_ACCOUNTS_IDENTIFIER_NAME, value: JSON.stringify(parmas.awardAccounts) };
1032
+ // await this.orderModel.findOneAndUpdate(
1033
+ // {
1034
+ // orderNumber: { $eq: parmas.orderNumber },
1035
+ // 'identifier.name': { $ne: AWARD_ACCOUNTS_IDENTIFIER_NAME }
1036
+ // },
1037
+ // { $push: { identifier: newIdentifier } },
1038
+ // { new: true }
1039
+ // )
1040
+ // .exec();
1041
+ // }
1042
+ // }
1040
1043
  /**
1041
1044
  * 注文に含まれる予約番号を検索する
1042
1045
  */
@@ -174,9 +174,9 @@ function fixFromLocation(params, product) {
174
174
  throw new factory.errors.ArgumentNull('amount.value');
175
175
  }
176
176
  const { permitServiceEndpoint, permitServiceAuthorizeServerDomain, permitServiceClientId, permitServiceClientSecret } = createPermitServiceCredentials({ product });
177
- const permitService = new pecorinoapi.service.Permit({
177
+ const permitService = new (yield pecorinoapi.loadPecorino()).service.Permit({
178
178
  endpoint: permitServiceEndpoint,
179
- auth: new pecorinoapi.auth.ClientCredentials({
179
+ auth: yield pecorinoapi.auth.ClientCredentials.createInstance({
180
180
  domain: permitServiceAuthorizeServerDomain,
181
181
  clientId: permitServiceClientId,
182
182
  clientSecret: permitServiceClientSecret,
@@ -233,9 +233,9 @@ function fixToLocation(params, product) {
233
233
  throw new factory.errors.ArgumentNull('amount.value');
234
234
  }
235
235
  const { permitServiceEndpoint, permitServiceAuthorizeServerDomain, permitServiceClientId, permitServiceClientSecret } = createPermitServiceCredentials({ product });
236
- const permitService = new pecorinoapi.service.Permit({
236
+ const permitService = new (yield pecorinoapi.loadPecorino()).service.Permit({
237
237
  endpoint: permitServiceEndpoint,
238
- auth: new pecorinoapi.auth.ClientCredentials({
238
+ auth: yield pecorinoapi.auth.ClientCredentials.createInstance({
239
239
  domain: permitServiceAuthorizeServerDomain,
240
240
  clientId: permitServiceClientId,
241
241
  clientSecret: permitServiceClientSecret,
@@ -141,9 +141,9 @@ function createPermitService(params) {
141
141
  || typeof permitServiceClientSecret !== 'string' || permitServiceClientSecret.length === 0) {
142
142
  throw new Error('product availableChannel invalid');
143
143
  }
144
- return new pecorinoapi.service.Permit({
144
+ return new (yield pecorinoapi.loadPecorino()).service.Permit({
145
145
  endpoint: permitServiceEndpoint,
146
- auth: new pecorinoapi.auth.ClientCredentials({
146
+ auth: yield pecorinoapi.auth.ClientCredentials.createInstance({
147
147
  domain: permitServiceAuthorizeServerDomain,
148
148
  clientId: permitServiceClientId,
149
149
  clientSecret: permitServiceClientSecret,
@@ -648,9 +648,9 @@ function createPermitService(params) {
648
648
  || typeof permitServiceClientSecret !== 'string' || permitServiceClientSecret.length === 0) {
649
649
  throw new Error('product availableChannel invalid');
650
650
  }
651
- return new pecorinoapi.service.Permit({
651
+ return new (yield pecorinoapi.loadPecorino()).service.Permit({
652
652
  endpoint: permitServiceEndpoint,
653
- auth: new pecorinoapi.auth.ClientCredentials({
653
+ auth: yield pecorinoapi.auth.ClientCredentials.createInstance({
654
654
  domain: permitServiceAuthorizeServerDomain,
655
655
  clientId: permitServiceClientId,
656
656
  clientSecret: permitServiceClientSecret,
@@ -66,9 +66,9 @@ function processAccountTransaction(params) {
66
66
  .toDate();
67
67
  const issuedThroughId = getIssuedThroughId(params);
68
68
  const permitServiceCredentials = yield createPermitServiceCredentials({ issuedThrough: { id: issuedThroughId } })(repos);
69
- const permitService = new pecorinoapi.service.Permit({
69
+ const permitService = new (yield pecorinoapi.loadPecorino()).service.Permit({
70
70
  endpoint: permitServiceCredentials.permitServiceEndpoint,
71
- auth: new pecorinoapi.auth.ClientCredentials({
71
+ auth: yield pecorinoapi.auth.ClientCredentials.createInstance({
72
72
  domain: permitServiceCredentials.permitServiceAuthorizeServerDomain,
73
73
  clientId: permitServiceCredentials.permitServiceClientId,
74
74
  clientSecret: permitServiceCredentials.permitServiceClientSecret,
@@ -125,9 +125,9 @@ function processAccountTransaction(params) {
125
125
  function processDepositTransaction(params) {
126
126
  return (repos) => __awaiter(this, void 0, void 0, function* () {
127
127
  var _a;
128
- const accountTransactionService = new pecorinoapi.service.AccountTransaction({
128
+ const accountTransactionService = new (yield pecorinoapi.loadPecorino()).service.AccountTransaction({
129
129
  endpoint: params.permitServiceCredentials.permitServiceEndpoint,
130
- auth: new pecorinoapi.auth.ClientCredentials({
130
+ auth: yield pecorinoapi.auth.ClientCredentials.createInstance({
131
131
  domain: params.permitServiceCredentials.permitServiceAuthorizeServerDomain,
132
132
  clientId: params.permitServiceCredentials.permitServiceClientId,
133
133
  clientSecret: params.permitServiceCredentials.permitServiceClientSecret,
@@ -155,9 +155,9 @@ function processDepositTransaction(params) {
155
155
  function processTransferTransaction(params) {
156
156
  return (repos) => __awaiter(this, void 0, void 0, function* () {
157
157
  var _a, _b;
158
- const accountTransactionService = new pecorinoapi.service.AccountTransaction({
158
+ const accountTransactionService = new (yield pecorinoapi.loadPecorino()).service.AccountTransaction({
159
159
  endpoint: params.permitServiceCredentials.permitServiceEndpoint,
160
- auth: new pecorinoapi.auth.ClientCredentials({
160
+ auth: yield pecorinoapi.auth.ClientCredentials.createInstance({
161
161
  domain: params.permitServiceCredentials.permitServiceAuthorizeServerDomain,
162
162
  clientId: params.permitServiceCredentials.permitServiceClientId,
163
163
  clientSecret: params.permitServiceCredentials.permitServiceClientSecret,
@@ -207,9 +207,9 @@ function processWithdrawTransaction(params) {
207
207
  return (repos) => __awaiter(this, void 0, void 0, function* () {
208
208
  var _a;
209
209
  // 転送先口座が指定されていない場合は、出金取引
210
- const accountTransactionService = new pecorinoapi.service.AccountTransaction({
210
+ const accountTransactionService = new (yield pecorinoapi.loadPecorino()).service.AccountTransaction({
211
211
  endpoint: params.permitServiceCredentials.permitServiceEndpoint,
212
- auth: new pecorinoapi.auth.ClientCredentials({
212
+ auth: yield pecorinoapi.auth.ClientCredentials.createInstance({
213
213
  domain: params.permitServiceCredentials.permitServiceAuthorizeServerDomain,
214
214
  clientId: params.permitServiceCredentials.permitServiceClientId,
215
215
  clientSecret: params.permitServiceCredentials.permitServiceClientSecret,
@@ -362,9 +362,9 @@ function cancelMoneyTransfer(params) {
362
362
  const issuedThroughId = getIssuedThroughIdByTransaction({ transaction });
363
363
  const { permitServiceEndpoint, permitServiceAuthorizeServerDomain, permitServiceClientId, permitServiceClientSecret } = yield createPermitServiceCredentials({ issuedThrough: { id: issuedThroughId } })(repos);
364
364
  // 汎用中止サービスを使用(2022-09-27~)
365
- const accountTransactionService = new pecorinoapi.service.AccountTransaction({
365
+ const accountTransactionService = new (yield pecorinoapi.loadPecorino()).service.AccountTransaction({
366
366
  endpoint: permitServiceEndpoint,
367
- auth: new pecorinoapi.auth.ClientCredentials({
367
+ auth: yield pecorinoapi.auth.ClientCredentials.createInstance({
368
368
  domain: permitServiceAuthorizeServerDomain,
369
369
  clientId: permitServiceClientId,
370
370
  clientSecret: permitServiceClientSecret,
@@ -399,9 +399,9 @@ function moneyTransfer(params) {
399
399
  const transactionNumber = yield fixAccountTransactionNumber(params)({ transactionNumber: repos.transactionNumber });
400
400
  const issuedThroughId = getIssuedThroughIdByAction({ action, pendingTransactionType: transactionType });
401
401
  const permitServiceCredentials = yield createPermitServiceCredentials({ issuedThrough: { id: issuedThroughId } })(repos);
402
- const accountTransactionService = new pecorinoapi.service.AccountTransaction({
402
+ const accountTransactionService = new (yield pecorinoapi.loadPecorino()).service.AccountTransaction({
403
403
  endpoint: permitServiceCredentials.permitServiceEndpoint,
404
- auth: new pecorinoapi.auth.ClientCredentials({
404
+ auth: yield pecorinoapi.auth.ClientCredentials.createInstance({
405
405
  domain: permitServiceCredentials.permitServiceAuthorizeServerDomain,
406
406
  clientId: permitServiceCredentials.permitServiceClientId,
407
407
  clientSecret: permitServiceCredentials.permitServiceClientSecret,
@@ -496,9 +496,9 @@ function processDepositFromNow(params, permitServiceCredentials, transactionNumb
496
496
  const description = (typeof params.description === 'string') ? params.description : params.purpose.typeOf;
497
497
  const permitIdentifier = String(params.toLocation.identifier);
498
498
  // Permitの存在確認
499
- const permitService = new pecorinoapi.service.Permit({
499
+ const permitService = new (yield pecorinoapi.loadPecorino()).service.Permit({
500
500
  endpoint: permitServiceCredentials.permitServiceEndpoint,
501
- auth: new pecorinoapi.auth.ClientCredentials({
501
+ auth: yield pecorinoapi.auth.ClientCredentials.createInstance({
502
502
  domain: permitServiceCredentials.permitServiceAuthorizeServerDomain,
503
503
  clientId: permitServiceCredentials.permitServiceClientId,
504
504
  clientSecret: permitServiceCredentials.permitServiceClientSecret,
@@ -90,9 +90,9 @@ function validatePaymentMethod(params, paymentServiceId) {
90
90
  typeOf: factory.service.paymentService.PaymentServiceType.PaymentCard,
91
91
  id: paymentServiceId
92
92
  });
93
- const permitService = new pecorinoapi.service.Permit({
93
+ const permitService = new (yield pecorinoapi.loadPecorino()).service.Permit({
94
94
  endpoint: String(availableChannel.serviceUrl),
95
- auth: new pecorinoapi.auth.ClientCredentials({
95
+ auth: yield pecorinoapi.auth.ClientCredentials.createInstance({
96
96
  domain: String((_f = availableChannel.credentials) === null || _f === void 0 ? void 0 : _f.authorizeServerDomain),
97
97
  clientId: String((_g = availableChannel.credentials) === null || _g === void 0 ? void 0 : _g.clientId),
98
98
  clientSecret: String((_h = availableChannel.credentials) === null || _h === void 0 ? void 0 : _h.clientSecret),
@@ -146,9 +146,9 @@ function processAccountTransaction(params) {
146
146
  typeOf: factory.service.paymentService.PaymentServiceType.PaymentCard,
147
147
  id: params.paymentServiceId
148
148
  });
149
- const accountTransactionService = new pecorinoapi.service.AccountTransaction({
149
+ const accountTransactionService = new (yield pecorinoapi.loadPecorino()).service.AccountTransaction({
150
150
  endpoint: String(availableChannel.serviceUrl),
151
- auth: new pecorinoapi.auth.ClientCredentials({
151
+ auth: yield pecorinoapi.auth.ClientCredentials.createInstance({
152
152
  domain: String((_c = availableChannel.credentials) === null || _c === void 0 ? void 0 : _c.authorizeServerDomain),
153
153
  clientId: String((_d = availableChannel.credentials) === null || _d === void 0 ? void 0 : _d.clientId),
154
154
  clientSecret: String((_e = availableChannel.credentials) === null || _e === void 0 ? void 0 : _e.clientSecret),
@@ -198,9 +198,9 @@ function voidTransaction(params) {
198
198
  id: paymentServiceId
199
199
  });
200
200
  // 汎用中止サービスを使用(2022-09-27~)
201
- const accountTransactionService = new pecorinoapi.service.AccountTransaction({
201
+ const accountTransactionService = new (yield pecorinoapi.loadPecorino()).service.AccountTransaction({
202
202
  endpoint: String(availableChannel.serviceUrl),
203
- auth: new pecorinoapi.auth.ClientCredentials({
203
+ auth: yield pecorinoapi.auth.ClientCredentials.createInstance({
204
204
  domain: String((_a = availableChannel.credentials) === null || _a === void 0 ? void 0 : _a.authorizeServerDomain),
205
205
  clientId: String((_b = availableChannel.credentials) === null || _b === void 0 ? void 0 : _b.clientId),
206
206
  clientSecret: String((_c = availableChannel.credentials) === null || _c === void 0 ? void 0 : _c.clientSecret),
@@ -234,9 +234,9 @@ function payPaymentCard(params) {
234
234
  typeOf: factory.service.paymentService.PaymentServiceType.PaymentCard,
235
235
  id: paymentServiceId
236
236
  });
237
- const accountTransactionService = new pecorinoapi.service.AccountTransaction({
237
+ const accountTransactionService = new (yield pecorinoapi.loadPecorino()).service.AccountTransaction({
238
238
  endpoint: String(availableChannel.serviceUrl),
239
- auth: new pecorinoapi.auth.ClientCredentials({
239
+ auth: yield pecorinoapi.auth.ClientCredentials.createInstance({
240
240
  domain: String((_a = availableChannel.credentials) === null || _a === void 0 ? void 0 : _a.authorizeServerDomain),
241
241
  clientId: String((_b = availableChannel.credentials) === null || _b === void 0 ? void 0 : _b.clientId),
242
242
  clientSecret: String((_c = availableChannel.credentials) === null || _c === void 0 ? void 0 : _c.clientSecret),
@@ -288,9 +288,9 @@ function refundPaymentCard(params) {
288
288
  typeOf: factory.service.paymentService.PaymentServiceType.PaymentCard,
289
289
  id: paymentServiceId
290
290
  });
291
- const accountTransactionService = new pecorinoapi.service.AccountTransaction({
291
+ const accountTransactionService = new (yield pecorinoapi.loadPecorino()).service.AccountTransaction({
292
292
  endpoint: String(availableChannel.serviceUrl),
293
- auth: new pecorinoapi.auth.ClientCredentials({
293
+ auth: yield pecorinoapi.auth.ClientCredentials.createInstance({
294
294
  domain: String((_e = availableChannel.credentials) === null || _e === void 0 ? void 0 : _e.authorizeServerDomain),
295
295
  clientId: String((_f = availableChannel.credentials) === null || _f === void 0 ? void 0 : _f.clientId),
296
296
  clientSecret: String((_g = availableChannel.credentials) === null || _g === void 0 ? void 0 : _g.clientSecret),
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "@chevre/factory": "4.334.0",
13
- "@cinerino/sdk": "3.172.0",
13
+ "@cinerino/sdk": "4.0.0-alpha.1",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
16
16
  "@sendgrid/mail": "6.4.0",
@@ -115,5 +115,5 @@
115
115
  "postversion": "git push origin --tags",
116
116
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
117
117
  },
118
- "version": "21.13.0-alpha.4"
118
+ "version": "21.13.0-alpha.6"
119
119
  }