@chevre/domain 22.10.0-alpha.9 → 22.10.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.
- package/example/src/chevre/adminIdentities.ts +8 -8
- package/example/src/chevre/assetTransaction/processReserve.ts +4 -1
- package/example/src/chevre/concurrentLock/lockOfferRateLimit.ts +64 -0
- package/example/src/chevre/concurrentLock/lockTransactionProcess.ts +44 -0
- package/example/src/chevre/createTaskIfNotExistByAlternateName.ts +1 -1
- package/example/src/chevre/findOneAvailableHours.ts +11 -11
- package/example/src/chevre/identity/getCommonClients.ts +126 -0
- package/example/src/chevre/identity/migrateClients2oauth.ts +200 -0
- package/example/src/chevre/issuer/adminMemberProgramTiers.ts +55 -0
- package/example/src/chevre/maintenance/checkTransactionStatuses.ts +105 -0
- package/example/src/chevre/migrateIdentities.ts +24 -37
- package/example/src/chevre/reIndex.ts +1 -1
- package/example/src/chevre/roles/addPermissionIfNotExists.ts +27 -0
- package/example/src/chevre/roles/addRoleMembers.ts +75 -0
- package/example/src/chevre/saveWebSite.ts +14 -17
- package/example/src/chevre/stockHolder/checkRedisKeyCount.ts +43 -22
- package/example/src/chevre/transactionNumber/publishConfimationNumber.ts +37 -0
- package/example/src/chevre/transactionNumber/publishOrderNumber.ts +40 -0
- package/example/src/chevre/transactionNumber/setUseMongo4confirmationNumberFrom.ts +45 -0
- package/example/src/chevre/transactionNumber/setUseMongo4orderNumberFrom.ts +41 -0
- package/example/src/chevre/transactionNumber/setUseMongo4transactionNumberFrom.ts +41 -0
- package/example/src/redisMulti.ts +63 -0
- package/example/src/signPayload.ts +1 -1
- package/lib/chevre/eventEmitter/task.d.ts +36 -6
- package/lib/chevre/eventEmitter/task.js +5 -4
- package/lib/chevre/eventEmitter.d.ts +2 -2
- package/lib/chevre/eventEmitter.js +2 -2
- package/lib/chevre/repo/concurrentLock.d.ts +14 -0
- package/lib/chevre/repo/concurrentLock.js +48 -0
- package/lib/chevre/repo/concurrentLockAbstract.d.ts +42 -0
- package/lib/chevre/repo/concurrentLockAbstract.js +9 -0
- package/lib/chevre/repo/confirmationNumber.d.ts +17 -4
- package/lib/chevre/repo/confirmationNumber.js +89 -32
- package/lib/chevre/repo/identity.d.ts +42 -5
- package/lib/chevre/repo/identity.js +35 -4
- package/lib/chevre/repo/issuer.d.ts +10 -2
- package/lib/chevre/repo/member.js +2 -2
- package/lib/chevre/repo/memberProgram.d.ts +43 -2
- package/lib/chevre/repo/memberProgram.js +79 -8
- package/lib/chevre/repo/mongoose/schemas/issuer.d.ts +3 -1
- package/lib/chevre/repo/mongoose/schemas/issuer.js +10 -0
- package/lib/chevre/repo/mongoose/schemas/offer/event.js +30 -2
- package/lib/chevre/repo/mongoose/schemas/role.d.ts +2 -3
- package/lib/chevre/repo/mongoose/schemas/role.js +11 -1
- package/lib/chevre/repo/mongoose/schemas/setting.d.ts +3 -0
- package/lib/chevre/repo/mongoose/schemas/setting.js +4 -1
- package/lib/chevre/repo/mongoose/schemas/transactionNumber.d.ts +39 -0
- package/lib/chevre/repo/mongoose/schemas/transactionNumber.js +101 -0
- package/lib/chevre/repo/orderNumber.d.ts +15 -4
- package/lib/chevre/repo/orderNumber.js +71 -24
- package/lib/chevre/repo/passport.d.ts +1 -1
- package/lib/chevre/repo/passport.js +31 -13
- package/lib/chevre/repo/rateLimit/offer.d.ts +7 -2
- package/lib/chevre/repo/rateLimit/offer.js +41 -40
- package/lib/chevre/repo/role.d.ts +18 -4
- package/lib/chevre/repo/role.js +53 -4
- package/lib/chevre/repo/serviceOutputIdentifier.d.ts +8 -4
- package/lib/chevre/repo/serviceOutputIdentifier.js +54 -22
- package/lib/chevre/repo/stockHolder.d.ts +0 -2
- package/lib/chevre/repo/stockHolder.js +24 -31
- package/lib/chevre/repo/task.d.ts +10 -25
- package/lib/chevre/repo/task.js +65 -36
- package/lib/chevre/repo/transactionNumber.d.ts +15 -4
- package/lib/chevre/repo/transactionNumber.js +67 -22
- package/lib/chevre/repo/transactionNumberCounter.d.ts +28 -0
- package/lib/chevre/repo/transactionNumberCounter.js +128 -0
- package/lib/chevre/repo/transactionProcess.d.ts +7 -4
- package/lib/chevre/repo/transactionProcess.js +34 -13
- package/lib/chevre/service/aggregation/event/aggregateOffers.js +1 -0
- package/lib/chevre/service/assetTransaction/reserve/start.js +9 -1
- package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +1 -1
- package/lib/chevre/service/code.js +1 -1
- package/lib/chevre/service/offer/event/checkAvailability.d.ts +1 -1
- package/lib/chevre/service/offer/event/checkAvailability.js +1 -0
- package/lib/chevre/service/offer/product.js +0 -40
- package/lib/chevre/service/payment/any.d.ts +0 -2
- package/lib/chevre/service/payment/any.js +1 -0
- package/lib/chevre/service/reserve/cancelReservation.d.ts +3 -0
- package/lib/chevre/service/reserve/cancelReservation.js +5 -1
- package/lib/chevre/service/task/acceptCOAOffer.js +2 -2
- package/lib/chevre/service/task/authorizePayment.js +4 -4
- package/lib/chevre/service/task/givePointAward.js +1 -1
- package/lib/chevre/service/task/moneyTransfer.js +1 -1
- package/lib/chevre/service/task/publishPaymentUrl.js +2 -2
- package/lib/chevre/service/task/refund.js +1 -1
- package/lib/chevre/service/task/returnMoneyTransfer.js +1 -1
- package/lib/chevre/service/task/returnPayTransaction.js +1 -1
- package/lib/chevre/service/task/returnPointAward.js +1 -1
- package/lib/chevre/service/task/returnReserveTransaction.js +1 -1
- package/lib/chevre/service/task.d.ts +8 -17
- package/lib/chevre/service/task.js +14 -5
- package/lib/chevre/service/transaction/placeOrder/start/validateStartRequest.js +2 -2
- package/lib/chevre/service/transaction/returnOrder/preStart/factory.d.ts +20 -0
- package/lib/chevre/service/transaction/returnOrder/preStart/factory.js +2 -0
- package/lib/chevre/service/transaction/returnOrder/preStart/findApplicableReturnPolicy.d.ts +23 -0
- package/lib/chevre/service/transaction/returnOrder/preStart/findApplicableReturnPolicy.js +323 -0
- package/lib/chevre/service/transaction/returnOrder/preStart/getReturnPolicyByProject.d.ts +13 -0
- package/lib/chevre/service/transaction/returnOrder/preStart/getReturnPolicyByProject.js +132 -0
- package/lib/chevre/service/transaction/returnOrder/preStart.js +2 -391
- package/package.json +3 -3
- package/example/src/chevre/migrateMembers2identities.ts +0 -109
- package/example/src/chevre/publishConfimationNumber.ts +0 -27
|
@@ -8,23 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
12
|
exports.preStart = preStart;
|
|
24
13
|
const createDebug = require("debug");
|
|
25
|
-
const http_status_1 = require("http-status");
|
|
26
|
-
const moment = require("moment-timezone");
|
|
27
14
|
const factory = require("../../../factory");
|
|
15
|
+
const findApplicableReturnPolicy_1 = require("./preStart/findApplicableReturnPolicy");
|
|
28
16
|
const debug = createDebug('chevre-domain:service');
|
|
29
17
|
/**
|
|
30
18
|
* 返品取引開始前処理
|
|
@@ -87,7 +75,7 @@ function preStart(params) {
|
|
|
87
75
|
id: seller.project.id,
|
|
88
76
|
inclusion: ['hasMerchantReturnPolicy']
|
|
89
77
|
});
|
|
90
|
-
const appliedReturnPolicy = yield findApplicableReturnPolicy(Object.assign({ acceptedOffers,
|
|
78
|
+
const appliedReturnPolicy = yield (0, findApplicableReturnPolicy_1.findApplicableReturnPolicy)(Object.assign({ acceptedOffers,
|
|
91
79
|
events,
|
|
92
80
|
offerItemConditions,
|
|
93
81
|
orders, returningDate: now, reason: params.object.reason, returnPolicies,
|
|
@@ -247,383 +235,6 @@ function searchPoliciesByOffer(params) {
|
|
|
247
235
|
return policiesByOffer;
|
|
248
236
|
});
|
|
249
237
|
}
|
|
250
|
-
function createOrder4returnPolicy(params) {
|
|
251
|
-
return {
|
|
252
|
-
orderDate: params.order.orderDate,
|
|
253
|
-
orderNumber: params.order.orderNumber,
|
|
254
|
-
price: params.order.price,
|
|
255
|
-
acceptedOffers: params.order.acceptedOffers.map((o) => {
|
|
256
|
-
var _a;
|
|
257
|
-
if (o.itemOffered.typeOf === factory.reservationType.EventReservation) {
|
|
258
|
-
const reservation = o.itemOffered;
|
|
259
|
-
const priceComponent = (_a = o.priceSpecification) === null || _a === void 0 ? void 0 : _a.priceComponent;
|
|
260
|
-
return {
|
|
261
|
-
itemOffered: {
|
|
262
|
-
additionalProperty: reservation.additionalProperty,
|
|
263
|
-
reservationFor: {
|
|
264
|
-
doorTime: reservation.reservationFor.doorTime,
|
|
265
|
-
endDate: reservation.reservationFor.endDate,
|
|
266
|
-
startDate: reservation.reservationFor.startDate
|
|
267
|
-
// superEvent: reservation.reservationFor.superEvent
|
|
268
|
-
},
|
|
269
|
-
reservedTicket: {
|
|
270
|
-
ticketedSeat: reservation.reservedTicket.ticketedSeat
|
|
271
|
-
}
|
|
272
|
-
},
|
|
273
|
-
priceSpecification: {
|
|
274
|
-
priceComponent: (Array.isArray(priceComponent))
|
|
275
|
-
? priceComponent.map((component) => {
|
|
276
|
-
const { accounting, name, priceCurrency, valueAddedTaxIncluded } = component, postingComponent = __rest(component, ["accounting", "name", "priceCurrency", "valueAddedTaxIncluded"]);
|
|
277
|
-
return postingComponent;
|
|
278
|
-
})
|
|
279
|
-
: []
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
return {
|
|
285
|
-
priceSpecification: o.priceSpecification
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
})
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
const TIMEOUT = 5000;
|
|
292
|
-
function getReturnPolicyByProject(params) {
|
|
293
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
294
|
-
var _a;
|
|
295
|
-
// implement with fetch(2024-01-20~)
|
|
296
|
-
try {
|
|
297
|
-
const { identifier, sameAs } = params;
|
|
298
|
-
const res = yield fetch(sameAs, {
|
|
299
|
-
method: 'POST',
|
|
300
|
-
headers: {
|
|
301
|
-
'Content-Type': 'application/json'
|
|
302
|
-
},
|
|
303
|
-
body: JSON.stringify({
|
|
304
|
-
order: createOrder4returnPolicy({ order: params.order })
|
|
305
|
-
}),
|
|
306
|
-
// body data type must match "Content-Type" header
|
|
307
|
-
signal: AbortSignal.timeout(TIMEOUT)
|
|
308
|
-
});
|
|
309
|
-
let body;
|
|
310
|
-
try {
|
|
311
|
-
body = (yield res.json());
|
|
312
|
-
}
|
|
313
|
-
catch (error) {
|
|
314
|
-
// no op
|
|
315
|
-
}
|
|
316
|
-
let returnPolicy;
|
|
317
|
-
switch (res.status) {
|
|
318
|
-
case http_status_1.OK:
|
|
319
|
-
case http_status_1.CREATED:
|
|
320
|
-
case http_status_1.ACCEPTED:
|
|
321
|
-
case http_status_1.NO_CONTENT:
|
|
322
|
-
if (typeof ((_a = body === null || body === void 0 ? void 0 : body.restockingFee) === null || _a === void 0 ? void 0 : _a.value) !== 'number') {
|
|
323
|
-
throw new factory.errors.Internal('invalid return policy');
|
|
324
|
-
}
|
|
325
|
-
else {
|
|
326
|
-
returnPolicy = {
|
|
327
|
-
typeOf: 'MerchantReturnPolicy',
|
|
328
|
-
restockingFee: {
|
|
329
|
-
currency: factory.priceCurrency.JPY,
|
|
330
|
-
typeOf: 'MonetaryAmount',
|
|
331
|
-
value: body.restockingFee.value
|
|
332
|
-
},
|
|
333
|
-
// keep identifier(2024-06-26~)
|
|
334
|
-
identifier
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
break;
|
|
338
|
-
case http_status_1.NOT_FOUND:
|
|
339
|
-
throw new factory.errors.Argument('', `custom return policy returned statusCode: ${res.status}`);
|
|
340
|
-
// break;
|
|
341
|
-
default:
|
|
342
|
-
throw new factory.errors.Internal(`ProjectReturnPolicy unavailable. statusCode: ${res.status} body: ${body}`);
|
|
343
|
-
}
|
|
344
|
-
return returnPolicy;
|
|
345
|
-
}
|
|
346
|
-
catch (err) {
|
|
347
|
-
throw err;
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* 販売者の返品ポリシーを確認する
|
|
353
|
-
*/
|
|
354
|
-
// tslint:disable-next-line:max-func-body-length
|
|
355
|
-
function findApplicableReturnPolicy(params) {
|
|
356
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
357
|
-
var _a, _b, _c;
|
|
358
|
-
if (params.reason === factory.transaction.returnOrder.Reason.Seller) {
|
|
359
|
-
// 販売者都合の場合、手数料なしの返金返品ポリシーを適用
|
|
360
|
-
return {
|
|
361
|
-
typeOf: 'MerchantReturnPolicy',
|
|
362
|
-
returnFees: factory.merchantReturnPolicy.ReturnFeesEnumeration.FreeReturn
|
|
363
|
-
// no identifier in this case
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
const returnPolicies = params.returnPolicies;
|
|
367
|
-
let applicalbleReturnPolicies = [];
|
|
368
|
-
if (params.reason === factory.transaction.returnOrder.Reason.Customer) {
|
|
369
|
-
// プロジェクトの返品ポリシー設定を考慮(2023-11-14~)
|
|
370
|
-
const returnPolicySameAsByPoject = (_a = params.returnPolicySettingsByProject) === null || _a === void 0 ? void 0 : _a.sameAs;
|
|
371
|
-
if (typeof returnPolicySameAsByPoject === 'string' && returnPolicySameAsByPoject.length > 0) {
|
|
372
|
-
const returnPolicyByProject = yield getReturnPolicyByProject({
|
|
373
|
-
identifier: String((_b = params.returnPolicySettingsByProject) === null || _b === void 0 ? void 0 : _b.identifier),
|
|
374
|
-
sameAs: returnPolicySameAsByPoject,
|
|
375
|
-
order: Object.assign(Object.assign({}, params.orders[0]), { acceptedOffers: params.acceptedOffers })
|
|
376
|
-
});
|
|
377
|
-
applicalbleReturnPolicies.push(returnPolicyByProject);
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
// 適用可能なポリシーにフィルター
|
|
381
|
-
// tslint:disable-next-line:max-func-body-length
|
|
382
|
-
applicalbleReturnPolicies = returnPolicies.filter((returnPolicy) => {
|
|
383
|
-
return isSellerReturnPolicyApplicable({
|
|
384
|
-
returnPolicy,
|
|
385
|
-
events: params.events,
|
|
386
|
-
offerItemConditions: params.offerItemConditions,
|
|
387
|
-
orders: params.orders,
|
|
388
|
-
returningDate: params.returningDate,
|
|
389
|
-
usedReservationExists: params.usedReservationExists
|
|
390
|
-
});
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
// 販売者にポリシーが存在しなければ返品不可
|
|
395
|
-
if (applicalbleReturnPolicies.length === 0) {
|
|
396
|
-
throw new factory.errors.Argument('Seller', 'has no applicable return policies');
|
|
397
|
-
}
|
|
398
|
-
// オファーの返品ポリシーから返品手数料タイプを決定する
|
|
399
|
-
const { returnFees, returnFeesMovieTicket } = validateOffersReturnPolicy({
|
|
400
|
-
acceptedOffers: params.acceptedOffers,
|
|
401
|
-
offers: params.offers,
|
|
402
|
-
policiesByOffer: params.policiesByOffer
|
|
403
|
-
});
|
|
404
|
-
// restockingFeeが最低のポリシーを自動選択
|
|
405
|
-
let appliedReturnPolicy = applicalbleReturnPolicies[0];
|
|
406
|
-
applicalbleReturnPolicies.forEach((returnPolicy) => {
|
|
407
|
-
var _a, _b;
|
|
408
|
-
const appliedReturnPolicyRestockingFeeValue = (_a = appliedReturnPolicy.restockingFee) === null || _a === void 0 ? void 0 : _a.value;
|
|
409
|
-
const restockingFeeValue = (_b = returnPolicy.restockingFee) === null || _b === void 0 ? void 0 : _b.value;
|
|
410
|
-
const appliedReturnPolicyRestockingFee = (typeof appliedReturnPolicyRestockingFeeValue === 'number')
|
|
411
|
-
? appliedReturnPolicyRestockingFeeValue
|
|
412
|
-
: 0;
|
|
413
|
-
const restockingFeeAsNumber = (typeof restockingFeeValue === 'number') ? restockingFeeValue : 0;
|
|
414
|
-
if (restockingFeeAsNumber < appliedReturnPolicyRestockingFee) {
|
|
415
|
-
appliedReturnPolicy = returnPolicy;
|
|
416
|
-
}
|
|
417
|
-
});
|
|
418
|
-
let appliedItemCondition;
|
|
419
|
-
const appliedItemConditionId = (_c = appliedReturnPolicy.itemCondition) === null || _c === void 0 ? void 0 : _c.id;
|
|
420
|
-
if (typeof appliedItemConditionId === 'string') {
|
|
421
|
-
const appliedItemConditionFromDB = params.offerItemConditions.find((o) => o.id === appliedItemConditionId);
|
|
422
|
-
if (appliedItemConditionFromDB === undefined) {
|
|
423
|
-
throw new factory.errors.NotFound('OfferItemCondition');
|
|
424
|
-
}
|
|
425
|
-
appliedItemCondition = Object.assign({ identifier: appliedItemConditionFromDB.identifier, itemOffered: appliedItemConditionFromDB.itemOffered, typeOf: appliedItemConditionFromDB.typeOf }, (typeof appliedItemConditionFromDB.id === 'string') ? { id: appliedItemConditionFromDB.id } : undefined);
|
|
426
|
-
}
|
|
427
|
-
const { restockingFee, typeOf, identifier, merchantReturnDays } = appliedReturnPolicy;
|
|
428
|
-
return Object.assign(Object.assign(Object.assign({ restockingFee,
|
|
429
|
-
returnFees, // offerのreturnPolicyから決定する
|
|
430
|
-
returnFeesMovieTicket,
|
|
431
|
-
typeOf }, (typeof identifier === 'string') ? { identifier } : undefined), (typeof merchantReturnDays === 'number') ? { merchantReturnDays } : undefined), (typeof (appliedItemCondition === null || appliedItemCondition === void 0 ? void 0 : appliedItemCondition.typeOf) === 'string') ? { itemCondition: appliedItemCondition } : undefined);
|
|
432
|
-
});
|
|
433
|
-
}
|
|
434
|
-
// tslint:disable-next-line:cyclomatic-complexity max-func-body-length
|
|
435
|
-
function isSellerReturnPolicyApplicable(params) {
|
|
436
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
437
|
-
const returnPolicy = params.returnPolicy;
|
|
438
|
-
const returningDate = moment(params.returningDate);
|
|
439
|
-
let satisfyMerchantReturnDays = false;
|
|
440
|
-
let satisfyApplicablePaymentMethod = false;
|
|
441
|
-
let offerItemCondition;
|
|
442
|
-
const itemConditionId = (_a = returnPolicy.itemCondition) === null || _a === void 0 ? void 0 : _a.id;
|
|
443
|
-
if (typeof itemConditionId === 'string') {
|
|
444
|
-
offerItemCondition = params.offerItemConditions.find((o) => o.id === itemConditionId);
|
|
445
|
-
if (offerItemCondition === undefined) {
|
|
446
|
-
throw new factory.errors.NotFound('OfferItemCondition');
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
const merchantReturnDays = returnPolicy.merchantReturnDays;
|
|
450
|
-
if (typeof merchantReturnDays === 'number') {
|
|
451
|
-
// 返品適用日数を確認する
|
|
452
|
-
const everyOrderApplicable = params.orders.every((order) => {
|
|
453
|
-
const mustBeReturnedUntil = moment(order.orderDate)
|
|
454
|
-
.add(merchantReturnDays, 'days');
|
|
455
|
-
return mustBeReturnedUntil.isSameOrAfter(returningDate);
|
|
456
|
-
});
|
|
457
|
-
// 全注文について日数の確認ができれば適用
|
|
458
|
-
if (everyOrderApplicable) {
|
|
459
|
-
satisfyMerchantReturnDays = true;
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
else {
|
|
463
|
-
// 日数制限なし
|
|
464
|
-
satisfyMerchantReturnDays = true;
|
|
465
|
-
}
|
|
466
|
-
// 適用決済方法検証(2023-08-08~)
|
|
467
|
-
const applicablePaymentMethod = returnPolicy.applicablePaymentMethod;
|
|
468
|
-
if (Array.isArray(applicablePaymentMethod)) {
|
|
469
|
-
const everyOrderApplicable = params.orders.every((order) => {
|
|
470
|
-
// 全決済方法区分がapplicablePaymentMethodに含まれれば適用
|
|
471
|
-
return order.paymentMethods.every((invoice) => {
|
|
472
|
-
var _a;
|
|
473
|
-
return typeof ((_a = invoice.paymentMethod) === null || _a === void 0 ? void 0 : _a.identifier) === 'string'
|
|
474
|
-
&& applicablePaymentMethod.includes(invoice.paymentMethod.identifier);
|
|
475
|
-
});
|
|
476
|
-
});
|
|
477
|
-
// 全注文について確認ができれば適用
|
|
478
|
-
if (everyOrderApplicable) {
|
|
479
|
-
satisfyApplicablePaymentMethod = true;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
else {
|
|
483
|
-
satisfyApplicablePaymentMethod = true;
|
|
484
|
-
}
|
|
485
|
-
// イベント開始猶予を検証する(2023-05-22~)
|
|
486
|
-
let satisfyItemCondition = true;
|
|
487
|
-
if (offerItemCondition !== undefined) {
|
|
488
|
-
let satisfyGracePeriodMaxValue = true;
|
|
489
|
-
let satisfyGracePeriodMinValue = true;
|
|
490
|
-
// 全イベントについて猶予の確認ができれば適用
|
|
491
|
-
const gracePeriodMaxValue = (_c = (_b = offerItemCondition.itemOffered.serviceOutput) === null || _b === void 0 ? void 0 : _b.reservationFor.gracePeriodBeforeStart) === null || _c === void 0 ? void 0 : _c.maxValue;
|
|
492
|
-
const gracePeriodMinValue = (_e = (_d = offerItemCondition.itemOffered.serviceOutput) === null || _d === void 0 ? void 0 : _d.reservationFor.gracePeriodBeforeStart) === null || _e === void 0 ? void 0 : _e.minValue;
|
|
493
|
-
if (typeof gracePeriodMaxValue === 'number') {
|
|
494
|
-
satisfyGracePeriodMaxValue = params.events.every((event) => {
|
|
495
|
-
return moment(event.startDate)
|
|
496
|
-
.isSameOrBefore(moment(params.returningDate)
|
|
497
|
-
.add(gracePeriodMaxValue, 'seconds'));
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
if (typeof gracePeriodMinValue === 'number') {
|
|
501
|
-
satisfyGracePeriodMinValue = params.events.every((event) => {
|
|
502
|
-
debug('isSellerReturnPolicyApplicable: comparing by gracePeriodMinValue...', 'gracePeriodMinValue:', gracePeriodMinValue, event.startDate, '>', moment(params.returningDate)
|
|
503
|
-
.add(gracePeriodMinValue, 'seconds'), '?');
|
|
504
|
-
return moment(event.startDate)
|
|
505
|
-
.isAfter(moment(params.returningDate)
|
|
506
|
-
.add(gracePeriodMinValue, 'seconds'));
|
|
507
|
-
});
|
|
508
|
-
}
|
|
509
|
-
let satisfyGracePeriodInDaysMax = true;
|
|
510
|
-
let satisfyGracePeriodInDaysMin = true;
|
|
511
|
-
const gracePeriodBeforeStartInDaysMax = (_g = (_f = offerItemCondition.itemOffered.serviceOutput) === null || _f === void 0 ? void 0 : _f.reservationFor.gracePeriodBeforeStartInDays) === null || _g === void 0 ? void 0 : _g.max;
|
|
512
|
-
if (typeof (gracePeriodBeforeStartInDaysMax === null || gracePeriodBeforeStartInDaysMax === void 0 ? void 0 : gracePeriodBeforeStartInDaysMax.period.value) === 'number'
|
|
513
|
-
&& typeof gracePeriodBeforeStartInDaysMax.time === 'string') {
|
|
514
|
-
satisfyGracePeriodInDaysMax = params.events.every((event) => {
|
|
515
|
-
const maxDate = moment(event.startDate)
|
|
516
|
-
.tz(gracePeriodBeforeStartInDaysMax.timezone)
|
|
517
|
-
.startOf('days')
|
|
518
|
-
.subtract(gracePeriodBeforeStartInDaysMax.period.value, 'days')
|
|
519
|
-
.format('YYYY-MM-DD');
|
|
520
|
-
const returnMinDate = moment.tz(`${maxDate}T${gracePeriodBeforeStartInDaysMax.time}`, gracePeriodBeforeStartInDaysMax.timezone);
|
|
521
|
-
debug('returnMinDate:', returnMinDate, 'returningDate:', returningDate);
|
|
522
|
-
return returnMinDate.isSameOrBefore(moment(returningDate));
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
debug('gracePeriodBeforeStartInDaysMax:', gracePeriodBeforeStartInDaysMax);
|
|
526
|
-
const gracePeriodBeforeStartInDaysMin = (_j = (_h = offerItemCondition.itemOffered.serviceOutput) === null || _h === void 0 ? void 0 : _h.reservationFor.gracePeriodBeforeStartInDays) === null || _j === void 0 ? void 0 : _j.min;
|
|
527
|
-
if (typeof (gracePeriodBeforeStartInDaysMin === null || gracePeriodBeforeStartInDaysMin === void 0 ? void 0 : gracePeriodBeforeStartInDaysMin.period.value) === 'number'
|
|
528
|
-
&& typeof gracePeriodBeforeStartInDaysMin.time === 'string') {
|
|
529
|
-
satisfyGracePeriodInDaysMin = params.events.every((event) => {
|
|
530
|
-
const minDate = moment(event.startDate)
|
|
531
|
-
.tz(gracePeriodBeforeStartInDaysMin.timezone)
|
|
532
|
-
.startOf('days')
|
|
533
|
-
.subtract(gracePeriodBeforeStartInDaysMin.period.value, 'days')
|
|
534
|
-
.format('YYYY-MM-DD');
|
|
535
|
-
const returnMaxDate = moment.tz(`${minDate}T${gracePeriodBeforeStartInDaysMin.time}`, gracePeriodBeforeStartInDaysMin.timezone);
|
|
536
|
-
debug('returnMaxDate:', returnMaxDate, 'returningDate:', returningDate);
|
|
537
|
-
return returnMaxDate.isAfter(moment(returningDate));
|
|
538
|
-
});
|
|
539
|
-
}
|
|
540
|
-
debug('satisfyGracePeriodInDaysMin:', satisfyGracePeriodInDaysMin);
|
|
541
|
-
let satisfyOnlyUnused = true;
|
|
542
|
-
if (((_k = offerItemCondition.itemOffered.serviceOutput) === null || _k === void 0 ? void 0 : _k.onlyUnused) === true) {
|
|
543
|
-
if (params.usedReservationExists) {
|
|
544
|
-
satisfyOnlyUnused = false;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
debug('usedReservationExists:', params.usedReservationExists, 'satisfyOnlyUnused:', satisfyOnlyUnused);
|
|
548
|
-
satisfyItemCondition = satisfyGracePeriodMaxValue && satisfyGracePeriodMinValue
|
|
549
|
-
&& satisfyGracePeriodInDaysMax && satisfyGracePeriodInDaysMin && satisfyOnlyUnused;
|
|
550
|
-
}
|
|
551
|
-
return satisfyMerchantReturnDays && satisfyApplicablePaymentMethod && satisfyItemCondition;
|
|
552
|
-
}
|
|
553
|
-
/**
|
|
554
|
-
* 注文中のオファーの返品ポリシーを検証
|
|
555
|
-
*/
|
|
556
|
-
function validateOffersReturnPolicy(params) {
|
|
557
|
-
// オファーに返品ポリシーが設定されているか?
|
|
558
|
-
const everyOffersHaveReturnPolicy = params.offers.every((offer) => {
|
|
559
|
-
return Array.isArray(offer.hasMerchantReturnPolicy) && offer.hasMerchantReturnPolicy.length > 0;
|
|
560
|
-
});
|
|
561
|
-
if (!everyOffersHaveReturnPolicy) {
|
|
562
|
-
throw new factory.errors.NotFound('offer.hasMerchantReturnPolicy');
|
|
563
|
-
}
|
|
564
|
-
let returnFees;
|
|
565
|
-
// 返品手数料設定はどうか?
|
|
566
|
-
const somePolicyWithReturnFeesCustomerResponsibility = params.policiesByOffer.some((policy) => {
|
|
567
|
-
return policy.customerRemorseReturnFees === factory.merchantReturnPolicy.ReturnFeesEnumeration.ReturnFeesCustomerResponsibility;
|
|
568
|
-
});
|
|
569
|
-
const somePolicyWithRestockingFees = params.policiesByOffer.some((policy) => {
|
|
570
|
-
return policy.customerRemorseReturnFees === factory.merchantReturnPolicy.ReturnFeesEnumeration.RestockingFees;
|
|
571
|
-
});
|
|
572
|
-
const everyPolicyWithFreeReturn = params.policiesByOffer.every((policy) => {
|
|
573
|
-
return policy.customerRemorseReturnFees === factory.merchantReturnPolicy.ReturnFeesEnumeration.FreeReturn;
|
|
574
|
-
});
|
|
575
|
-
if (somePolicyWithReturnFeesCustomerResponsibility) {
|
|
576
|
-
// ひとつでも返金なしがあれば返金なし
|
|
577
|
-
returnFees = factory.merchantReturnPolicy.ReturnFeesEnumeration.ReturnFeesCustomerResponsibility;
|
|
578
|
-
}
|
|
579
|
-
else if (somePolicyWithRestockingFees) {
|
|
580
|
-
// ひとつでも手数料あり返金があれば手数料あり返金
|
|
581
|
-
returnFees = factory.merchantReturnPolicy.ReturnFeesEnumeration.RestockingFees;
|
|
582
|
-
}
|
|
583
|
-
else if (everyPolicyWithFreeReturn) {
|
|
584
|
-
// 全ポリシーが手数料なしであれば手数料なし返金
|
|
585
|
-
returnFees = factory.merchantReturnPolicy.ReturnFeesEnumeration.FreeReturn;
|
|
586
|
-
}
|
|
587
|
-
else {
|
|
588
|
-
throw new factory.errors.NotImplemented('returnFees not defined');
|
|
589
|
-
}
|
|
590
|
-
// 決済カード取消ポリシーを確定(2023-05-23~)
|
|
591
|
-
const returnFeesMovieTicket = [];
|
|
592
|
-
params.acceptedOffers.forEach((acceptedOffer) => {
|
|
593
|
-
var _a, _b;
|
|
594
|
-
const unitPriceOffer = params.offers.find((offer) => offer.id === acceptedOffer.id);
|
|
595
|
-
if (unitPriceOffer === undefined) {
|
|
596
|
-
throw new factory.errors.NotFound(`UnitPriceOffer ${acceptedOffer.id}`);
|
|
597
|
-
}
|
|
598
|
-
if (!Array.isArray(unitPriceOffer.hasMerchantReturnPolicy) || unitPriceOffer.hasMerchantReturnPolicy.length === 0) {
|
|
599
|
-
throw new factory.errors.NotFound(`offer.hasMerchantReturnPolicy ${acceptedOffer.id}`);
|
|
600
|
-
}
|
|
601
|
-
const hasMerchantReturnPolicy = unitPriceOffer.hasMerchantReturnPolicy[0];
|
|
602
|
-
const policyByOffer = params.policiesByOffer.find((policy) => policy.id === hasMerchantReturnPolicy.id);
|
|
603
|
-
if (policyByOffer === undefined) {
|
|
604
|
-
throw new factory.errors.NotFound(`MerchantReturnPolicy acceptedOffer:${acceptedOffer.id}`);
|
|
605
|
-
}
|
|
606
|
-
const movieTicketTypeChargeSpecExists = (_a = acceptedOffer.priceSpecification) === null || _a === void 0 ? void 0 : _a.priceComponent.some((component) => {
|
|
607
|
-
return component.typeOf === factory.priceSpecificationType.MovieTicketTypeChargeSpecification;
|
|
608
|
-
});
|
|
609
|
-
if (movieTicketTypeChargeSpecExists === true) {
|
|
610
|
-
(_b = acceptedOffer.priceSpecification) === null || _b === void 0 ? void 0 : _b.priceComponent.forEach((component) => {
|
|
611
|
-
if (component.typeOf === factory.priceSpecificationType.UnitPriceSpecification) {
|
|
612
|
-
if (Array.isArray(component.appliesToMovieTicket)) {
|
|
613
|
-
component.appliesToMovieTicket.forEach((appliesToMovieTicket) => {
|
|
614
|
-
returnFeesMovieTicket.push({
|
|
615
|
-
identifier: String(appliesToMovieTicket.identifier),
|
|
616
|
-
returnFees: policyByOffer.customerRemorseReturnFeesMovieTicket,
|
|
617
|
-
serviceOutput: { typeOf: appliesToMovieTicket.serviceOutput.typeOf }
|
|
618
|
-
});
|
|
619
|
-
});
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
});
|
|
625
|
-
return { returnFees, returnFeesMovieTicket };
|
|
626
|
-
}
|
|
627
238
|
function validateAppliedReturnPolicy(params) {
|
|
628
239
|
var _a;
|
|
629
240
|
const appliedReturnPolicy = params.merchantReturnPolicy;
|
package/package.json
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@aws-sdk/client-cognito-identity-provider": "3.600.0",
|
|
13
13
|
"@aws-sdk/credential-providers": "3.600.0",
|
|
14
|
-
"@chevre/factory": "4.
|
|
15
|
-
"@cinerino/sdk": "10.
|
|
14
|
+
"@chevre/factory": "4.395.0-alpha.0",
|
|
15
|
+
"@cinerino/sdk": "10.22.0-alpha.1",
|
|
16
16
|
"@motionpicture/coa-service": "9.6.0",
|
|
17
17
|
"@motionpicture/gmo-service": "5.3.0",
|
|
18
18
|
"@sendgrid/client": "8.1.4",
|
|
@@ -113,5 +113,5 @@
|
|
|
113
113
|
"postversion": "git push origin --tags",
|
|
114
114
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
115
115
|
},
|
|
116
|
-
"version": "22.10.0
|
|
116
|
+
"version": "22.10.0"
|
|
117
117
|
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as mongoose from 'mongoose';
|
|
3
|
-
|
|
4
|
-
import { chevre } from '../../../lib/index';
|
|
5
|
-
|
|
6
|
-
// const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
-
// const excludedProject = { id: String(process.env.EXCLUDED_PROJECT_ID) };
|
|
8
|
-
|
|
9
|
-
const AVAILABLE_ROLES = [
|
|
10
|
-
chevre.factory.iam.RoleName.Customer,
|
|
11
|
-
chevre.factory.iam.RoleName.EventsViewer,
|
|
12
|
-
chevre.factory.iam.RoleName.POS
|
|
13
|
-
];
|
|
14
|
-
|
|
15
|
-
// tslint:disable-next-line:max-func-body-length
|
|
16
|
-
async function main() {
|
|
17
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
18
|
-
|
|
19
|
-
const identityRepo = await chevre.repository.Identity.createInstance(mongoose.connection);
|
|
20
|
-
const memberRepo = await chevre.repository.Member.createInstance(mongoose.connection);
|
|
21
|
-
const projectRepo = await chevre.repository.Project.createInstance(mongoose.connection);
|
|
22
|
-
|
|
23
|
-
const cursor = memberRepo.getCursor(
|
|
24
|
-
{
|
|
25
|
-
// _id: { $eq: 'cinerino' }
|
|
26
|
-
'member.typeOf': { $eq: chevre.factory.creativeWorkType.WebApplication },
|
|
27
|
-
'project.id': { $ne: '*' }
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
_id: 1,
|
|
31
|
-
project: 1,
|
|
32
|
-
member: 1,
|
|
33
|
-
typeOf: 1
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
|
-
console.log('docs found');
|
|
37
|
-
|
|
38
|
-
let i = 0;
|
|
39
|
-
let updateCount = 0;
|
|
40
|
-
let projectIdsWithoutCustomProviders: string[] = [];
|
|
41
|
-
let projectIdsWithCustomProviders: string[] = [];
|
|
42
|
-
await cursor.eachAsync(async (doc) => {
|
|
43
|
-
i += 1;
|
|
44
|
-
const iamMember: Pick<chevre.factory.iam.IMember, 'project' | 'member' | 'typeOf'> = doc.toObject();
|
|
45
|
-
const roleNames = iamMember.member.hasRole.map(({ roleName }) => roleName)
|
|
46
|
-
.join(',');
|
|
47
|
-
const expectedRoles = iamMember.member.hasRole.length === 1 &&
|
|
48
|
-
iamMember.member.hasRole.every(({ roleName }) => AVAILABLE_ROLES.includes(roleName));
|
|
49
|
-
if (!expectedRoles) {
|
|
50
|
-
throw new Error('roles not expected');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const projectSettings = (await projectRepo.findById({
|
|
54
|
-
id: iamMember.project.id,
|
|
55
|
-
inclusion: ['settings']
|
|
56
|
-
})).settings;
|
|
57
|
-
const tokenIssuers: string[] = Array.isArray((<any>projectSettings).tokenIssuers) ? (<any>projectSettings).tokenIssuers : [];
|
|
58
|
-
if (tokenIssuers.length > 0) {
|
|
59
|
-
projectIdsWithCustomProviders.push(iamMember.project.id);
|
|
60
|
-
} else {
|
|
61
|
-
projectIdsWithoutCustomProviders.push(iamMember.project.id);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
console.log(
|
|
65
|
-
'alreadyMigrated?',
|
|
66
|
-
iamMember.member.id, iamMember.member.typeOf, iamMember.project.id, roleNames, tokenIssuers.length, 'tokenIssuers', i);
|
|
67
|
-
let alreadyMigrated = false;
|
|
68
|
-
const existingIdentity = (await identityRepo.projectFields(
|
|
69
|
-
{
|
|
70
|
-
limit: 1,
|
|
71
|
-
page: 1,
|
|
72
|
-
project: { id: { $eq: iamMember.project.id } },
|
|
73
|
-
about: { id: { $eq: iamMember.member.id } }
|
|
74
|
-
},
|
|
75
|
-
['about']
|
|
76
|
-
)).shift();
|
|
77
|
-
alreadyMigrated = existingIdentity?.about.id === iamMember.member.id
|
|
78
|
-
&& existingIdentity.about.typeOf === iamMember.member.typeOf;
|
|
79
|
-
|
|
80
|
-
if (alreadyMigrated) {
|
|
81
|
-
console.log(
|
|
82
|
-
'already migrated.', iamMember.member.id, iamMember.member.typeOf, iamMember.project.id, i);
|
|
83
|
-
} else {
|
|
84
|
-
if (tokenIssuers.length === 1) {
|
|
85
|
-
console.log(
|
|
86
|
-
'updating project...',
|
|
87
|
-
iamMember.member.id, iamMember.member.typeOf, iamMember.project.id, i);
|
|
88
|
-
// await identityProviderRepo.save({
|
|
89
|
-
// attributes: newProvider
|
|
90
|
-
// });
|
|
91
|
-
updateCount += 1;
|
|
92
|
-
console.log(
|
|
93
|
-
'updated.',
|
|
94
|
-
iamMember.member.id, iamMember.member.typeOf, iamMember.project.id, i);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
projectIdsWithoutCustomProviders = [...new Set(projectIdsWithoutCustomProviders)];
|
|
100
|
-
projectIdsWithCustomProviders = [...new Set(projectIdsWithCustomProviders)];
|
|
101
|
-
console.log(projectIdsWithoutCustomProviders);
|
|
102
|
-
console.log(projectIdsWithCustomProviders);
|
|
103
|
-
console.log(i, 'docs checked');
|
|
104
|
-
console.log(updateCount, 'docs updated');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
main()
|
|
108
|
-
.then()
|
|
109
|
-
.catch(console.error);
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as redis from 'redis';
|
|
3
|
-
import { chevre } from '../../../lib/index';
|
|
4
|
-
|
|
5
|
-
// const project = { id: String(process.env.PROJECT_ID) };
|
|
6
|
-
|
|
7
|
-
// tslint:disable-next-line:max-func-body-length
|
|
8
|
-
async function main() {
|
|
9
|
-
const client = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
|
|
10
|
-
socket: {
|
|
11
|
-
port: Number(<string>process.env.REDIS_PORT),
|
|
12
|
-
host: <string>process.env.REDIS_HOST
|
|
13
|
-
},
|
|
14
|
-
password: <string>process.env.REDIS_KEY
|
|
15
|
-
});
|
|
16
|
-
await client.connect();
|
|
17
|
-
|
|
18
|
-
const confirmationNumberRepo = await chevre.repository.ConfirmationNumber.createInstance(client);
|
|
19
|
-
const result = await confirmationNumberRepo.publish({ orderDate: new Date() });
|
|
20
|
-
console.log(result);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
main()
|
|
24
|
-
.then(() => {
|
|
25
|
-
console.log('success!');
|
|
26
|
-
})
|
|
27
|
-
.catch(console.error);
|