@chevre/domain 22.7.0-alpha.16 → 22.7.0-alpha.17
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/deleteDiscontinuedPeople.ts +60 -56
- package/example/src/chevre/upsertManyEventsByAdditionalProperty.ts +1 -2
- package/lib/chevre/repo/event.d.ts +27 -2
- package/lib/chevre/repo/event.js +73 -15
- package/lib/chevre/repo/mongoose/schemas/setting.d.ts +13 -0
- package/lib/chevre/repo/setting/jwt.js +11 -2
- package/lib/chevre/service/code.d.ts +1 -26
- package/lib/chevre/service/code.js +18 -129
- package/lib/chevre/service/task/deletePerson.js +8 -12
- package/package.json +1 -1
|
@@ -48,7 +48,7 @@ async function main() {
|
|
|
48
48
|
$eq: chevre.factory.product.ProductType.EventService
|
|
49
49
|
},
|
|
50
50
|
ownedFrom: {
|
|
51
|
-
$lte: moment('2024-
|
|
51
|
+
$lte: moment('2024-02-25T00:00:00Z')
|
|
52
52
|
.toDate()
|
|
53
53
|
}
|
|
54
54
|
},
|
|
@@ -82,62 +82,66 @@ async function main() {
|
|
|
82
82
|
'deleting person...',
|
|
83
83
|
personId, deletingOwnershipInfo.project.id, deletingOwnershipInfo.id, deletingOwnershipInfo.ownedFrom, i
|
|
84
84
|
);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
physically: true,
|
|
101
|
-
userPoolId,
|
|
102
|
-
project: { id: DISCONTINUE_PEOPLE_PROJECT },
|
|
103
|
-
migrate: false,
|
|
104
|
-
useUsernameAsGMOMemberId: true,
|
|
105
|
-
executeBackground: true
|
|
106
|
-
}
|
|
107
|
-
})(
|
|
108
|
-
{
|
|
109
|
-
connection: mongoose.connection,
|
|
110
|
-
settings: new chevre.settings.Settings({
|
|
111
|
-
abortedTasksWithoutReport: [],
|
|
112
|
-
numTryConfirmReserveTransaction: 10,
|
|
113
|
-
deliverOrderLimit: 1,
|
|
114
|
-
coa: {
|
|
115
|
-
timeout: 20000
|
|
116
|
-
},
|
|
117
|
-
gmo: {
|
|
118
|
-
timeout: 5000,
|
|
119
|
-
timeoutBackground: 5000,
|
|
120
|
-
useFetch: true
|
|
85
|
+
try {
|
|
86
|
+
await deletePerson({
|
|
87
|
+
id: '',
|
|
88
|
+
project: { typeOf: chevre.factory.organizationType.Project, id: DISCONTINUE_PEOPLE_PROJECT },
|
|
89
|
+
name: chevre.factory.taskName.DeletePerson,
|
|
90
|
+
status: chevre.factory.taskStatus.Ready,
|
|
91
|
+
runsAt,
|
|
92
|
+
remainingNumberOfTries: 10,
|
|
93
|
+
numberOfTried: 0,
|
|
94
|
+
data: {
|
|
95
|
+
id: personId,
|
|
96
|
+
agent: {
|
|
97
|
+
id: DISCONTINUE_PEOPLE_PROJECT,
|
|
98
|
+
typeOf: chevre.factory.organizationType.Project,
|
|
99
|
+
name: 'example'
|
|
121
100
|
},
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
101
|
+
physically: true,
|
|
102
|
+
userPoolId,
|
|
103
|
+
project: { id: DISCONTINUE_PEOPLE_PROJECT },
|
|
104
|
+
migrate: false,
|
|
105
|
+
useUsernameAsGMOMemberId: true,
|
|
106
|
+
executeBackground: true
|
|
107
|
+
}
|
|
108
|
+
})(
|
|
109
|
+
{
|
|
110
|
+
connection: mongoose.connection,
|
|
111
|
+
settings: new chevre.settings.Settings({
|
|
112
|
+
abortedTasksWithoutReport: [],
|
|
113
|
+
numTryConfirmReserveTransaction: 10,
|
|
114
|
+
deliverOrderLimit: 1,
|
|
115
|
+
coa: {
|
|
116
|
+
timeout: 20000
|
|
117
|
+
},
|
|
118
|
+
gmo: {
|
|
119
|
+
timeout: 5000,
|
|
120
|
+
timeoutBackground: 5000,
|
|
121
|
+
useFetch: true
|
|
122
|
+
},
|
|
123
|
+
movieticketReserve: {
|
|
124
|
+
timeout: 1000,
|
|
125
|
+
timeoutCheck: 1000,
|
|
126
|
+
minIntervalBetweenPayAndRefund: 1000,
|
|
127
|
+
credentialsExpireInSeconds: 1000
|
|
128
|
+
},
|
|
129
|
+
useExperimentalFeature: false
|
|
130
|
+
}),
|
|
131
|
+
credentials: <any>{}
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
executeById: false,
|
|
135
|
+
executeByName: true
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
console.log(
|
|
139
|
+
'deleted',
|
|
140
|
+
personId, deletingOwnershipInfo.project.id, deletingOwnershipInfo.id, deletingOwnershipInfo.ownedFrom, i
|
|
141
|
+
);
|
|
142
|
+
} catch (error) {
|
|
143
|
+
// no op
|
|
144
|
+
}
|
|
141
145
|
});
|
|
142
146
|
|
|
143
147
|
console.log(i, 'docs checked');
|
|
@@ -80,6 +80,11 @@ type IKeyOfProjection4minimizedEvent<T extends AvailableEventType> = T extends f
|
|
|
80
80
|
type IUnset<T extends AvailableEventType> = {
|
|
81
81
|
[key in keyof factory.event.IEvent<T>]?: 1;
|
|
82
82
|
};
|
|
83
|
+
type IEvent4updateManyByAdditionalProperty = Pick<factory.event.IAttributes<factory.eventType.ScreeningEvent>, 'additionalProperty' | 'project' | 'typeOf'> & {
|
|
84
|
+
offers: {
|
|
85
|
+
seller: Pick<factory.event.screeningEvent.ISeller, 'makesOffer'>;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
83
88
|
/**
|
|
84
89
|
* イベントリポジトリ
|
|
85
90
|
*/
|
|
@@ -116,8 +121,28 @@ export declare class EventRepo {
|
|
|
116
121
|
*/
|
|
117
122
|
branchCode: string;
|
|
118
123
|
};
|
|
119
|
-
|
|
120
|
-
|
|
124
|
+
}): Promise<{
|
|
125
|
+
bulkWriteResult: BulkWriteResult;
|
|
126
|
+
modifiedEvents: {
|
|
127
|
+
id: string;
|
|
128
|
+
}[];
|
|
129
|
+
} | void>;
|
|
130
|
+
/**
|
|
131
|
+
* 特定の追加特性をキーにして、イベントを更新する
|
|
132
|
+
* イベントは既に存在する前提(insertしない)
|
|
133
|
+
* 施設コンテンツは1つに限定
|
|
134
|
+
* 特定の属性のみ更新する
|
|
135
|
+
*/
|
|
136
|
+
updateManyByAdditionalProperty(params: {
|
|
137
|
+
events: IEvent4updateManyByAdditionalProperty[];
|
|
138
|
+
additionalPropertyFilter: {
|
|
139
|
+
name: string;
|
|
140
|
+
};
|
|
141
|
+
eventSeries: {
|
|
142
|
+
/**
|
|
143
|
+
* 施設コンテンツID
|
|
144
|
+
*/
|
|
145
|
+
id: string;
|
|
121
146
|
};
|
|
122
147
|
}): Promise<{
|
|
123
148
|
bulkWriteResult: BulkWriteResult;
|
package/lib/chevre/repo/event.js
CHANGED
|
@@ -390,7 +390,6 @@ class EventRepo {
|
|
|
390
390
|
// tslint:disable-next-line:max-func-body-length
|
|
391
391
|
upsertManyByAdditionalProperty(params) {
|
|
392
392
|
return __awaiter(this, void 0, void 0, function* () {
|
|
393
|
-
const { updateOffersSeller } = params.options;
|
|
394
393
|
const uniqid = yield Promise.resolve().then(() => require('uniqid'));
|
|
395
394
|
const bulkWriteOps = [];
|
|
396
395
|
const additionalProperties = [];
|
|
@@ -406,9 +405,10 @@ class EventRepo {
|
|
|
406
405
|
throw new factory.errors.ArgumentNull('additionalProperty.value');
|
|
407
406
|
}
|
|
408
407
|
additionalProperties.push({ name: additionalPropertyFilter.name, value: additionalPropertyValue });
|
|
409
|
-
const { coaInfo, // ←適用しない
|
|
408
|
+
const { coaInfo, identifier, // ←適用しない
|
|
410
409
|
maximumAttendeeCapacity, remainingAttendeeCapacity, checkInCount, attendeeCount, aggregateReservation, // ←適用しない
|
|
411
|
-
eventStatus, superEvent
|
|
410
|
+
eventStatus, superEvent } = creatingEventParams, // <-上書き可能な属性を限定的に
|
|
411
|
+
setOnInsertFields = __rest(creatingEventParams, ["coaInfo", "identifier", "maximumAttendeeCapacity", "remainingAttendeeCapacity", "checkInCount", "attendeeCount", "aggregateReservation", "eventStatus", "superEvent"]);
|
|
412
412
|
if (superEvent.id !== eventSeries.id) {
|
|
413
413
|
throw new factory.errors.Argument('superEvent.id', 'superEvent.id not matched');
|
|
414
414
|
}
|
|
@@ -426,23 +426,17 @@ class EventRepo {
|
|
|
426
426
|
},
|
|
427
427
|
'superEvent.id': { $exists: true, $eq: superEvent.id } // add superEvent.id(2024-09-15~)
|
|
428
428
|
};
|
|
429
|
-
|
|
430
|
-
if (updateOffersSeller) {
|
|
431
|
-
setOnInsert = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, setOnInsertFields), { 'offers.typeOf': offers.typeOf, 'offers.eligibleQuantity': offers.eligibleQuantity, 'offers.itemOffered': offers.itemOffered }), (offers.offeredThrough !== undefined) ? { 'offers.offeredThrough': offers.offeredThrough } : undefined), (offers.unacceptedPaymentMethod !== undefined)
|
|
432
|
-
? { 'offers.unacceptedPaymentMethod': offers.unacceptedPaymentMethod }
|
|
433
|
-
: undefined), { _id: uniqid() });
|
|
434
|
-
}
|
|
435
|
-
else {
|
|
436
|
-
setOnInsert = Object.assign(Object.assign({}, setOnInsertFields), { offers, _id: uniqid() });
|
|
437
|
-
}
|
|
429
|
+
const setOnInsert = Object.assign(Object.assign({}, setOnInsertFields), { _id: uniqid() });
|
|
438
430
|
bulkWriteOps.push({
|
|
439
431
|
updateOne: {
|
|
440
432
|
filter,
|
|
441
433
|
update: {
|
|
442
434
|
$setOnInsert: setOnInsert,
|
|
443
435
|
// 変更可能な属性のみ上書き
|
|
444
|
-
$set:
|
|
445
|
-
|
|
436
|
+
$set: {
|
|
437
|
+
eventStatus,
|
|
438
|
+
superEvent // add superEvent(2024-09-15~)
|
|
439
|
+
}
|
|
446
440
|
},
|
|
447
441
|
upsert: true
|
|
448
442
|
}
|
|
@@ -461,13 +455,77 @@ class EventRepo {
|
|
|
461
455
|
_id: 0,
|
|
462
456
|
id: { $toString: '$_id' }
|
|
463
457
|
})
|
|
464
|
-
// .select(['_id'])
|
|
465
458
|
.lean() // lean(2024-09-15~)
|
|
466
459
|
.exec();
|
|
467
460
|
return { bulkWriteResult, modifiedEvents };
|
|
468
461
|
}
|
|
469
462
|
});
|
|
470
463
|
}
|
|
464
|
+
/**
|
|
465
|
+
* 特定の追加特性をキーにして、イベントを更新する
|
|
466
|
+
* イベントは既に存在する前提(insertしない)
|
|
467
|
+
* 施設コンテンツは1つに限定
|
|
468
|
+
* 特定の属性のみ更新する
|
|
469
|
+
*/
|
|
470
|
+
// tslint:disable-next-line:max-func-body-length
|
|
471
|
+
updateManyByAdditionalProperty(params) {
|
|
472
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
473
|
+
const bulkWriteOps = [];
|
|
474
|
+
const additionalProperties = [];
|
|
475
|
+
const { events, additionalPropertyFilter, eventSeries } = params;
|
|
476
|
+
if (Array.isArray(events)) {
|
|
477
|
+
events.forEach((creatingEventParams) => {
|
|
478
|
+
var _a, _b;
|
|
479
|
+
if (creatingEventParams.typeOf !== factory.eventType.ScreeningEvent) {
|
|
480
|
+
throw new factory.errors.NotImplemented(`only ${factory.eventType.ScreeningEvent} implemented`);
|
|
481
|
+
}
|
|
482
|
+
const additionalPropertyValue = (_b = (_a = creatingEventParams.additionalProperty) === null || _a === void 0 ? void 0 : _a.find((property) => property.name === additionalPropertyFilter.name)) === null || _b === void 0 ? void 0 : _b.value;
|
|
483
|
+
if (typeof additionalPropertyValue !== 'string' || additionalPropertyValue === '') {
|
|
484
|
+
throw new factory.errors.ArgumentNull('additionalProperty.value');
|
|
485
|
+
}
|
|
486
|
+
additionalProperties.push({ name: additionalPropertyFilter.name, value: additionalPropertyValue });
|
|
487
|
+
const { offers // <-上書き可能な属性を限定的に
|
|
488
|
+
} = creatingEventParams;
|
|
489
|
+
const filter = {
|
|
490
|
+
typeOf: { $eq: creatingEventParams.typeOf },
|
|
491
|
+
'project.id': { $eq: creatingEventParams.project.id },
|
|
492
|
+
additionalProperty: {
|
|
493
|
+
$exists: true,
|
|
494
|
+
$all: [{ name: additionalPropertyFilter.name, value: additionalPropertyValue }]
|
|
495
|
+
},
|
|
496
|
+
'superEvent.id': { $exists: true, $eq: eventSeries.id }
|
|
497
|
+
};
|
|
498
|
+
bulkWriteOps.push({
|
|
499
|
+
updateOne: {
|
|
500
|
+
filter,
|
|
501
|
+
update: {
|
|
502
|
+
$set: {
|
|
503
|
+
'offers.seller.makesOffer': offers.seller.makesOffer
|
|
504
|
+
}
|
|
505
|
+
},
|
|
506
|
+
upsert: false
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
if (bulkWriteOps.length > 0) {
|
|
512
|
+
const bulkWriteResult = yield this.eventModel.bulkWrite(bulkWriteOps, { ordered: false });
|
|
513
|
+
// modifiedの場合upsertedIdsに含まれないので、idを検索する
|
|
514
|
+
const modifiedEvents = yield this.eventModel.find({
|
|
515
|
+
typeOf: { $eq: params.events[0].typeOf },
|
|
516
|
+
'project.id': { $eq: params.events[0].project.id },
|
|
517
|
+
additionalProperty: { $exists: true, $in: additionalProperties },
|
|
518
|
+
'superEvent.id': { $exists: true, $eq: eventSeries.id } // add superEvent.id(2024-09-15~)
|
|
519
|
+
}, {
|
|
520
|
+
_id: 0,
|
|
521
|
+
id: { $toString: '$_id' }
|
|
522
|
+
})
|
|
523
|
+
.lean()
|
|
524
|
+
.exec();
|
|
525
|
+
return { bulkWriteResult, modifiedEvents };
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
}
|
|
471
529
|
/**
|
|
472
530
|
* イベント部分更新
|
|
473
531
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Algorithm } from 'jsonwebtoken';
|
|
1
2
|
import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
|
|
2
3
|
import * as factory from '../../../factory';
|
|
3
4
|
interface IOnOrderStatusChanged {
|
|
@@ -82,6 +83,18 @@ export interface IJWTSetting {
|
|
|
82
83
|
issuers: string[];
|
|
83
84
|
version: string;
|
|
84
85
|
payloadTypPrefix: string;
|
|
86
|
+
/**
|
|
87
|
+
* auth.apisによるトークン発行時のissuer
|
|
88
|
+
*/
|
|
89
|
+
issuer: string;
|
|
90
|
+
/**
|
|
91
|
+
* auth.apisのトークン発行エンドポイント
|
|
92
|
+
*/
|
|
93
|
+
issueEndpoint: string;
|
|
94
|
+
/**
|
|
95
|
+
* トークン署名アルゴリズム
|
|
96
|
+
*/
|
|
97
|
+
algorithm: Algorithm;
|
|
85
98
|
}
|
|
86
99
|
export interface ISetting {
|
|
87
100
|
defaultSenderEmail?: string;
|
|
@@ -34,7 +34,7 @@ class JWTSettingRepo {
|
|
|
34
34
|
if (jwtSetting === null || jwtSetting.jwt === undefined) {
|
|
35
35
|
throw new factory.errors.NotFound('setting.jwt');
|
|
36
36
|
}
|
|
37
|
-
const { secret, version, payloadTypPrefix, issuers } = jwtSetting.jwt;
|
|
37
|
+
const { secret, version, payloadTypPrefix, issuers, issueEndpoint, issuer, algorithm } = jwtSetting.jwt;
|
|
38
38
|
if (typeof secret !== 'string' || secret.length === 0) {
|
|
39
39
|
throw new factory.errors.NotFound('setting.jwt.secret');
|
|
40
40
|
}
|
|
@@ -44,11 +44,20 @@ class JWTSettingRepo {
|
|
|
44
44
|
if (typeof payloadTypPrefix !== 'string' || payloadTypPrefix.length === 0) {
|
|
45
45
|
throw new factory.errors.NotFound('setting.jwt.payloadTypPrefix');
|
|
46
46
|
}
|
|
47
|
+
if (typeof issueEndpoint !== 'string' || issueEndpoint.length === 0) {
|
|
48
|
+
throw new factory.errors.NotFound('setting.jwt.issueEndpoint');
|
|
49
|
+
}
|
|
50
|
+
if (typeof issuer !== 'string' || issuer.length === 0) {
|
|
51
|
+
throw new factory.errors.NotFound('setting.jwt.issuer');
|
|
52
|
+
}
|
|
53
|
+
if (typeof algorithm !== 'string' || algorithm.length === 0) {
|
|
54
|
+
throw new factory.errors.NotFound('setting.jwt.algorithm');
|
|
55
|
+
}
|
|
47
56
|
if (!Array.isArray(issuers)) {
|
|
48
57
|
throw new factory.errors.NotFound('setting.jwt.issuers');
|
|
49
58
|
}
|
|
50
59
|
return {
|
|
51
|
-
secret, version, payloadTypPrefix, issuers
|
|
60
|
+
secret, version, payloadTypPrefix, issuers, issueEndpoint, issuer, algorithm
|
|
52
61
|
};
|
|
53
62
|
});
|
|
54
63
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ActionRepo } from '../repo/action';
|
|
2
1
|
import type { AuthorizationRepo } from '../repo/authorization';
|
|
3
2
|
import type { JWTSettingRepo } from '../repo/setting/jwt';
|
|
4
3
|
import type { TicketRepo } from '../repo/ticket';
|
|
@@ -9,7 +8,6 @@ interface IPayload extends Pick<factory.clientUser.IClientUser, 'aud' | 'exp' |
|
|
|
9
8
|
typ: string;
|
|
10
9
|
jti?: string;
|
|
11
10
|
}
|
|
12
|
-
type IAuthorizedObject = factory.authorization.IObject;
|
|
13
11
|
/**
|
|
14
12
|
* コードをトークンに変換する
|
|
15
13
|
*/
|
|
@@ -23,14 +21,6 @@ declare function getToken(params: {
|
|
|
23
21
|
};
|
|
24
22
|
code: string;
|
|
25
23
|
expiresIn: number;
|
|
26
|
-
/**
|
|
27
|
-
* jtw.payload.iss
|
|
28
|
-
*/
|
|
29
|
-
issuer: string;
|
|
30
|
-
/**
|
|
31
|
-
* jtw.payload.aud
|
|
32
|
-
*/
|
|
33
|
-
audience: string;
|
|
34
24
|
}): (repos: {
|
|
35
25
|
authorization: AuthorizationRepo;
|
|
36
26
|
jwtSetting: JWTSettingRepo;
|
|
@@ -38,19 +28,4 @@ declare function getToken(params: {
|
|
|
38
28
|
}) => Promise<{
|
|
39
29
|
token: IToken;
|
|
40
30
|
}>;
|
|
41
|
-
|
|
42
|
-
project: {
|
|
43
|
-
id: string;
|
|
44
|
-
};
|
|
45
|
-
agent: factory.action.check.token.IAgent;
|
|
46
|
-
token: string;
|
|
47
|
-
audience?: string[];
|
|
48
|
-
}): (repos: {
|
|
49
|
-
action?: ActionRepo;
|
|
50
|
-
authorization: AuthorizationRepo;
|
|
51
|
-
jwtSetting: JWTSettingRepo;
|
|
52
|
-
ticket: TicketRepo;
|
|
53
|
-
}) => Promise<{
|
|
54
|
-
authorizedObject: IAuthorizedObject;
|
|
55
|
-
}>;
|
|
56
|
-
export { IPayload, getToken, verifyToken };
|
|
31
|
+
export { IPayload, getToken };
|
|
@@ -9,27 +9,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.getToken = void 0;
|
|
13
13
|
/**
|
|
14
14
|
* 承認サービス
|
|
15
15
|
*/
|
|
16
16
|
const jwt = require("jsonwebtoken");
|
|
17
|
-
// import { JWTCredentials } from '../credentials/jwt';
|
|
18
17
|
const factory = require("../factory");
|
|
19
|
-
const ALGORITHM = 'HS256';
|
|
20
18
|
/**
|
|
21
19
|
* コードをトークンに変換する
|
|
22
20
|
*/
|
|
23
21
|
function getToken(params) {
|
|
24
|
-
return (repos
|
|
25
|
-
// credentials: {
|
|
26
|
-
// jwt: JWTCredentials;
|
|
27
|
-
// }
|
|
28
|
-
) => __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
29
23
|
var _a;
|
|
30
|
-
const
|
|
31
|
-
jwt: yield repos.jwtSetting.findDefault()
|
|
32
|
-
};
|
|
24
|
+
const jwtSetting = yield repos.jwtSetting.findDefault();
|
|
33
25
|
if (typeof params.project.id !== 'string' || params.project.id.length === 0) {
|
|
34
26
|
throw new factory.errors.ArgumentNull('project.id');
|
|
35
27
|
}
|
|
@@ -40,38 +32,39 @@ function getToken(params) {
|
|
|
40
32
|
project: { id: params.project.id },
|
|
41
33
|
code: params.code
|
|
42
34
|
});
|
|
43
|
-
if (typeof params.issuer !== 'string' || params.issuer.length === 0) {
|
|
44
|
-
|
|
45
|
-
}
|
|
35
|
+
// if (typeof params.issuer !== 'string' || params.issuer.length === 0) {
|
|
36
|
+
// throw new factory.errors.ArgumentNull('issuer');
|
|
37
|
+
// }
|
|
46
38
|
let subject;
|
|
47
39
|
let typ;
|
|
48
|
-
let jti;
|
|
49
|
-
// let subject: string = authorization.id;
|
|
50
|
-
// let typ: string = `${credentials.jwt.payloadTypPrefix}:${authorization.typeOf}`;
|
|
51
40
|
// jti必須化(2024-08-22~)
|
|
52
|
-
// let jti: string | undefined;
|
|
53
41
|
const { id } = yield repos.ticket.issueByTicketToken(Object.assign({ project: { id: params.project.id }, ticketToken: params.code }, (typeof ((_a = authorization.issuedBy) === null || _a === void 0 ? void 0 : _a.id) === 'string') ? { issuedBy: authorization.issuedBy } : undefined));
|
|
54
|
-
jti = id;
|
|
42
|
+
const jti = id;
|
|
55
43
|
// ロール承認の場合、subjectはメンバーID,typはメンバータイプ
|
|
56
44
|
if (authorization.object.typeOf === factory.iam.RoleType.OrganizationRole) {
|
|
57
45
|
subject = authorization.object.member.id;
|
|
58
|
-
typ = `${
|
|
46
|
+
typ = `${jwtSetting.payloadTypPrefix}:${authorization.object.member.typeOf}`;
|
|
59
47
|
}
|
|
60
48
|
else {
|
|
61
49
|
// useJtiの場合、subject,typはagent(2024-05-09~)
|
|
62
50
|
subject = params.agent.id;
|
|
63
|
-
typ = `${
|
|
51
|
+
typ = `${jwtSetting.payloadTypPrefix}:${params.agent.typeOf}`;
|
|
64
52
|
}
|
|
65
53
|
const payload = {
|
|
66
|
-
// sub: authorization.id, // 拡張(2024-05-01~)
|
|
67
54
|
token_use: 'access',
|
|
68
|
-
version:
|
|
55
|
+
version: jwtSetting.version,
|
|
69
56
|
typ // 拡張(2024-05-07~)
|
|
70
57
|
};
|
|
71
58
|
const token = yield new Promise((resolve, reject) => {
|
|
72
59
|
// 所有権を暗号化する
|
|
73
|
-
jwt.sign(payload,
|
|
74
|
-
|
|
60
|
+
jwt.sign(payload, jwtSetting.secret, {
|
|
61
|
+
algorithm: jwtSetting.algorithm,
|
|
62
|
+
issuer: jwtSetting.issuer,
|
|
63
|
+
expiresIn: params.expiresIn,
|
|
64
|
+
subject,
|
|
65
|
+
audience: jwtSetting.issuer,
|
|
66
|
+
jwtid: jti // 拡張(2024-05-08~)
|
|
67
|
+
}, (err, encoded) => {
|
|
75
68
|
if (err instanceof Error) {
|
|
76
69
|
reject(err);
|
|
77
70
|
}
|
|
@@ -89,107 +82,3 @@ function getToken(params) {
|
|
|
89
82
|
});
|
|
90
83
|
}
|
|
91
84
|
exports.getToken = getToken;
|
|
92
|
-
function payload2authorizeObject(params) {
|
|
93
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
const { payload } = params;
|
|
95
|
-
let authorizedObject;
|
|
96
|
-
// token.payloadが承認のケースに対応(2024-05-02~)
|
|
97
|
-
if (typeof payload.version === 'string') {
|
|
98
|
-
if (typeof payload.sub !== 'string' || payload.sub.length === 0) {
|
|
99
|
-
throw new factory.errors.Unauthorized(`invalid token [sub:${payload.sub}]`);
|
|
100
|
-
}
|
|
101
|
-
if (typeof payload.jti === 'string') {
|
|
102
|
-
// jtiに対応(2024-05-08~)
|
|
103
|
-
const ticket = (yield repos.ticket.projectFields({
|
|
104
|
-
limit: 1,
|
|
105
|
-
page: 1,
|
|
106
|
-
project: { id: { $eq: params.project.id } },
|
|
107
|
-
id: { $eq: payload.jti }
|
|
108
|
-
}, ['ticketToken'])).shift();
|
|
109
|
-
if (ticket === undefined) {
|
|
110
|
-
throw new factory.errors.NotFound('Ticket');
|
|
111
|
-
}
|
|
112
|
-
// 承認を参照
|
|
113
|
-
const { object } = yield repos.authorization.findValidOneByCode({
|
|
114
|
-
project: { id: params.project.id },
|
|
115
|
-
code: ticket.ticketToken
|
|
116
|
-
});
|
|
117
|
-
authorizedObject = object;
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
// 基本的にはsubで承認を参照
|
|
121
|
-
const { object } = yield repos.authorization.findValidOneById({
|
|
122
|
-
project: { id: params.project.id },
|
|
123
|
-
id: payload.sub
|
|
124
|
-
});
|
|
125
|
-
authorizedObject = object;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
// NO_VERSIONを廃止(2024-05-06~)
|
|
130
|
-
throw new factory.errors.NotImplemented('USE_TOKEN_WITH_NO_VERSION discontinued');
|
|
131
|
-
}
|
|
132
|
-
return { authorizedObject };
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
function verifyToken(params) {
|
|
136
|
-
return (repos
|
|
137
|
-
// credentials: {
|
|
138
|
-
// jwt: JWTCredentials;
|
|
139
|
-
// }
|
|
140
|
-
) => __awaiter(this, void 0, void 0, function* () {
|
|
141
|
-
let payload;
|
|
142
|
-
let action;
|
|
143
|
-
if (repos.action !== undefined) {
|
|
144
|
-
const actionAttributes = {
|
|
145
|
-
project: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
146
|
-
typeOf: factory.actionType.CheckAction,
|
|
147
|
-
agent: params.agent,
|
|
148
|
-
object: {
|
|
149
|
-
token: params.token,
|
|
150
|
-
typeOf: factory.action.check.token.ObjectType.Ticket
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
action = yield repos.action.start(actionAttributes);
|
|
154
|
-
}
|
|
155
|
-
try {
|
|
156
|
-
const credentials = {
|
|
157
|
-
jwt: yield repos.jwtSetting.findDefault()
|
|
158
|
-
};
|
|
159
|
-
// payload = await new Promise<IPayloadWithNoVersion | IPayload>((resolve, reject) => {
|
|
160
|
-
payload = yield new Promise((resolve, reject) => {
|
|
161
|
-
jwt.verify(params.token, credentials.jwt.secret, Object.assign({ algorithms: [ALGORITHM],
|
|
162
|
-
// 互換性維持のために複数対応(2024-05-02~)
|
|
163
|
-
// issuer: credentials.jwt.issuer,
|
|
164
|
-
issuer: credentials.jwt.issuers }, (Array.isArray(params.audience)) ? { audience: params.audience } : undefined), (err, decoded) => {
|
|
165
|
-
if (err instanceof Error) {
|
|
166
|
-
reject(err);
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
resolve(decoded);
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
catch (error) {
|
|
175
|
-
if (repos.action !== undefined && action !== undefined) {
|
|
176
|
-
try {
|
|
177
|
-
yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error });
|
|
178
|
-
}
|
|
179
|
-
catch (__) {
|
|
180
|
-
// 失敗したら仕方ない
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
// JWTエラーをハンドリング
|
|
184
|
-
if (error instanceof jwt.TokenExpiredError) {
|
|
185
|
-
throw new factory.errors.Argument('token', `${error.message} expiredAt:${error.expiredAt}`);
|
|
186
|
-
}
|
|
187
|
-
throw error;
|
|
188
|
-
}
|
|
189
|
-
if (repos.action !== undefined && action !== undefined) {
|
|
190
|
-
yield repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: payload });
|
|
191
|
-
}
|
|
192
|
-
return payload2authorizeObject({ payload, project: { id: params.project.id } })(repos);
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
exports.verifyToken = verifyToken;
|
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.call = void 0;
|
|
13
13
|
const GMO = require("@motionpicture/gmo-service");
|
|
14
|
+
const createDebug = require("debug");
|
|
14
15
|
const factory = require("../../factory");
|
|
15
16
|
// import { Settings } from '../../settings';
|
|
16
17
|
const person2username_1 = require("../payment/any/person2username");
|
|
@@ -23,6 +24,7 @@ const person_1 = require("../../repo/person");
|
|
|
23
24
|
const project_1 = require("../../repo/project");
|
|
24
25
|
const setting_1 = require("../../repo/setting");
|
|
25
26
|
const task_1 = require("../../repo/task");
|
|
27
|
+
const debug = createDebug('chevre-domain:service:task:deletePerson');
|
|
26
28
|
const DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD = 'CreditCard';
|
|
27
29
|
let cognitoIdentityServiceProvider;
|
|
28
30
|
/**
|
|
@@ -129,8 +131,7 @@ function deleteById(params, setting) {
|
|
|
129
131
|
})({ task: repos.task });
|
|
130
132
|
}
|
|
131
133
|
existingPeople = yield repos.newPerson.search({ id: params.id });
|
|
132
|
-
|
|
133
|
-
console.log('admin:people:deleteById: existingPeople:', JSON.stringify(existingPeople));
|
|
134
|
+
debug('admin:people:deleteById: existingPeople:', JSON.stringify(existingPeople));
|
|
134
135
|
if (existingPeople.length > 0) {
|
|
135
136
|
// クレジットカード削除
|
|
136
137
|
yield deleteCreditCardsById({
|
|
@@ -145,8 +146,7 @@ function deleteById(params, setting) {
|
|
|
145
146
|
);
|
|
146
147
|
}
|
|
147
148
|
// 所有権削除
|
|
148
|
-
|
|
149
|
-
console.log('admin:people:deleteById: deleteOwnershipInfosById processing... personId:', params.id);
|
|
149
|
+
debug('admin:people:deleteById: deleteOwnershipInfosById processing... personId:', params.id);
|
|
150
150
|
yield deleteOwnershipInfosById({
|
|
151
151
|
id: params.id,
|
|
152
152
|
project: { id: project.id }
|
|
@@ -154,8 +154,7 @@ function deleteById(params, setting) {
|
|
|
154
154
|
if (existingPeople.length > 0) {
|
|
155
155
|
// 会員削除
|
|
156
156
|
if (params.physically === true) {
|
|
157
|
-
|
|
158
|
-
console.log('admin:people:deleteById: deleteById processing...userId:', params.id);
|
|
157
|
+
debug('admin:people:deleteById: deleteById processing...userId:', params.id);
|
|
159
158
|
yield repos.newPerson.deleteById({ userId: params.id });
|
|
160
159
|
}
|
|
161
160
|
else {
|
|
@@ -404,8 +403,7 @@ function deleteCreditCardsById(params, setting) {
|
|
|
404
403
|
let throwsPerson2usernameError = true;
|
|
405
404
|
// oldUserが存在しないケースをハンドル
|
|
406
405
|
if (error instanceof factory.errors.NotFound && error.entityName === 'User') {
|
|
407
|
-
|
|
408
|
-
console.log('admin:people:deleteById: deleteCreditCardsById oldUsername not found', 'personId:', params.id, 'numberOfTry:', numberOfTry);
|
|
406
|
+
debug('admin:people:deleteById: deleteCreditCardsById oldUsername not found', 'personId:', params.id, 'numberOfTry:', numberOfTry);
|
|
409
407
|
throwsPerson2usernameError = false;
|
|
410
408
|
}
|
|
411
409
|
if (throwsPerson2usernameError) {
|
|
@@ -413,16 +411,14 @@ function deleteCreditCardsById(params, setting) {
|
|
|
413
411
|
}
|
|
414
412
|
}
|
|
415
413
|
if (typeof oldUsername === 'string') {
|
|
416
|
-
|
|
417
|
-
console.log('admin:people:deleteById: deleteCreditCardsById processing... oldUsername:', oldUsername, 'personId:', params.id, 'numberOfTry:', numberOfTry);
|
|
414
|
+
debug('admin:people:deleteById: deleteCreditCardsById processing... oldUsername:', oldUsername, 'personId:', params.id, 'numberOfTry:', numberOfTry);
|
|
418
415
|
yield repos.creditCard.deleteAll({ personId: oldUsername });
|
|
419
416
|
}
|
|
420
417
|
}
|
|
421
418
|
else {
|
|
422
419
|
yield repos.creditCard.deleteAll({ personId: params.id });
|
|
423
420
|
}
|
|
424
|
-
|
|
425
|
-
console.log('admin:people:deleteById: deleteCreditCardsById processed. personId:', params.id, 'numberOfTry:', numberOfTry);
|
|
421
|
+
debug('admin:people:deleteById: deleteCreditCardsById processed. personId:', params.id, 'numberOfTry:', numberOfTry);
|
|
426
422
|
break;
|
|
427
423
|
}
|
|
428
424
|
catch (error) {
|
package/package.json
CHANGED