@chevre/domain 22.7.0-alpha.16 → 22.7.0-alpha.18

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.
@@ -48,7 +48,7 @@ async function main() {
48
48
  $eq: chevre.factory.product.ProductType.EventService
49
49
  },
50
50
  ownedFrom: {
51
- $lte: moment('2024-03-01T00:00:00Z')
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
- await deletePerson({
86
- id: '',
87
- project: { typeOf: chevre.factory.organizationType.Project, id: DISCONTINUE_PEOPLE_PROJECT },
88
- name: chevre.factory.taskName.DeletePerson,
89
- status: chevre.factory.taskStatus.Ready,
90
- runsAt,
91
- remainingNumberOfTries: 10,
92
- numberOfTried: 0,
93
- data: {
94
- id: personId,
95
- agent: {
96
- id: DISCONTINUE_PEOPLE_PROJECT,
97
- typeOf: chevre.factory.organizationType.Project,
98
- name: 'example'
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
- movieticketReserve: {
123
- timeout: 1000,
124
- timeoutCheck: 1000,
125
- minIntervalBetweenPayAndRefund: 1000,
126
- credentialsExpireInSeconds: 1000
127
- },
128
- useExperimentalFeature: false
129
- }),
130
- credentials: <any>{}
131
- },
132
- {
133
- executeById: false,
134
- executeByName: true
135
- }
136
- );
137
- console.log(
138
- 'deleted',
139
- personId, deletingOwnershipInfo.project.id, deletingOwnershipInfo.id, deletingOwnershipInfo.ownedFrom, i
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');
@@ -0,0 +1,39 @@
1
+ // tslint:disable:no-console
2
+ // import * as moment from 'moment';
3
+
4
+ const TIMEOUT_MS = 5000;
5
+ const INTERVAL_MS = 5000;
6
+
7
+ let i = 0;
8
+ setInterval(
9
+ async () => {
10
+ i += 1;
11
+ try {
12
+ const url = 'https://cron2-dot-chevre-api-production.appspot.com/cron/deleteDiscontinuedPeople';
13
+
14
+ const res = await fetch(
15
+ url,
16
+ {
17
+ signal: AbortSignal.timeout(TIMEOUT_MS),
18
+ method: 'GET'
19
+ }
20
+ );
21
+ const result = await res.text();
22
+ console.log('result', result, i);
23
+ console.log('res.status', res.status, i);
24
+ } catch (err) {
25
+ console.error(err);
26
+ if (err.name === 'TimeoutError') {
27
+ console.error('Timeout: It took more than 5 seconds to get the result!');
28
+ } else if (err.name === 'AbortError') {
29
+ console.error('Fetch aborted by user action (browser stop button, closing tab, etc.');
30
+ } else if (err.name === 'TypeError') {
31
+ console.error('AbortSignal.timeout() method is not supported');
32
+ } else {
33
+ // A network error, or some other problem.
34
+ console.error(`Error: type: ${err.name}, message: ${err.message}`);
35
+ }
36
+ }
37
+ },
38
+ INTERVAL_MS
39
+ );
@@ -10,178 +10,180 @@ async function main() {
10
10
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
11
 
12
12
  const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
13
- const result = await eventRepo.upsertManyByAdditionalProperty({
14
- events: [
15
- {
16
- additionalProperty: [
17
- {
18
- name: 'sampleCreateId',
19
- value: 'akeuu512i-202410171410-01'
20
- }
21
- ],
22
- project: {
23
- id: PROJECT_ID,
24
- typeOf: chevre.factory.organizationType.Project
25
- },
26
- typeOf: chevre.factory.eventType.ScreeningEvent,
27
- doorTime: new Date('2024-10-17T05:30:00.000Z'),
28
- endDate: new Date('2024-10-17T05:45:00.000Z'),
29
- eventStatus: chevre.factory.eventStatusType.EventScheduled,
30
- // eventStatus: chevre.factory.eventStatusType.EventCancelled,
31
- location: {
32
- typeOf: chevre.factory.placeType.ScreeningRoom,
33
- branchCode: '10',
34
- name: {
35
- ja: 'シネマ1',
36
- en: 'CINEMA1'
37
- },
38
- address: {
39
- ja: '7階',
40
- en: '7F'
41
- }
42
- },
43
- name: {
44
- en: 'Ocean\'s Eight',
45
- ja: 'オーシャンズ8'
46
- },
47
- offers: {
48
- typeOf: chevre.factory.offerType.Offer,
49
- // availabilityEnds: new Date('2024-09-15T11:45:00.000Z'),
50
- // availabilityStarts: new Date('2024-09-01T15:00:00.000Z'),
51
- eligibleQuantity: {
52
- typeOf: 'QuantitativeValue',
53
- unitCode: chevre.factory.unitCode.C62,
54
- maxValue: 10
13
+ const result = await eventRepo.upsertManyByAdditionalProperty(
14
+ {
15
+ events: [
16
+ {
17
+ additionalProperty: [
18
+ {
19
+ name: 'sampleCreateId',
20
+ value: 'akeuu512i-202410171410-01'
21
+ }
22
+ ],
23
+ project: {
24
+ id: PROJECT_ID,
25
+ typeOf: chevre.factory.organizationType.Project
55
26
  },
56
- itemOffered: {
57
- id: '6603a61f0c914b6c7fd18f99',
27
+ typeOf: chevre.factory.eventType.ScreeningEvent,
28
+ doorTime: new Date('2024-10-17T05:30:00.000Z'),
29
+ endDate: new Date('2024-10-17T05:45:00.000Z'),
30
+ eventStatus: chevre.factory.eventStatusType.EventScheduled,
31
+ // eventStatus: chevre.factory.eventStatusType.EventCancelled,
32
+ location: {
33
+ typeOf: chevre.factory.placeType.ScreeningRoom,
34
+ branchCode: '10',
58
35
  name: {
59
- ja: 'アップロードテスト用(ムビチケあり)'
36
+ ja: 'シネマ1',
37
+ en: 'CINEMA1'
60
38
  },
61
- serviceOutput: {
62
- typeOf: chevre.factory.reservationType.EventReservation,
63
- reservedTicket: {
64
- typeOf: 'Ticket',
65
- ticketedSeat: {
66
- typeOf: chevre.factory.placeType.Seat
67
- }
68
- }
39
+ address: {
40
+ ja: '7階',
41
+ en: '7F'
42
+ }
43
+ },
44
+ name: {
45
+ en: 'Ocean\'s Eight',
46
+ ja: 'オーシャンズ8'
47
+ },
48
+ offers: {
49
+ typeOf: chevre.factory.offerType.Offer,
50
+ // availabilityEnds: new Date('2024-09-15T11:45:00.000Z'),
51
+ // availabilityStarts: new Date('2024-09-01T15:00:00.000Z'),
52
+ eligibleQuantity: {
53
+ typeOf: 'QuantitativeValue',
54
+ unitCode: chevre.factory.unitCode.C62,
55
+ maxValue: 10
69
56
  },
70
- typeOf: chevre.factory.product.ProductType.EventService,
71
- availableChannel: {
72
- typeOf: 'ServiceChannel',
73
- serviceLocation: {
74
- typeOf: chevre.factory.placeType.ScreeningRoom,
75
- branchCode: '10',
76
- name: {
77
- ja: 'シネマ1',
78
- en: 'CINEMA1'
79
- },
80
- containedInPlace: {
81
- typeOf: chevre.factory.placeType.MovieTheater,
82
- id: '5bfb841d5a78d7948369979a',
83
- branchCode: '118',
57
+ itemOffered: {
58
+ id: '6603a61f0c914b6c7fd18f99',
59
+ name: {
60
+ ja: 'アップロードテスト用(ムビチケあり)'
61
+ },
62
+ serviceOutput: {
63
+ typeOf: chevre.factory.reservationType.EventReservation,
64
+ reservedTicket: {
65
+ typeOf: 'Ticket',
66
+ ticketedSeat: {
67
+ typeOf: chevre.factory.placeType.Seat
68
+ }
69
+ }
70
+ },
71
+ typeOf: chevre.factory.product.ProductType.EventService,
72
+ availableChannel: {
73
+ typeOf: 'ServiceChannel',
74
+ serviceLocation: {
75
+ typeOf: chevre.factory.placeType.ScreeningRoom,
76
+ branchCode: '10',
84
77
  name: {
85
- ja: 'シネモーション赤坂 ',
86
- en: 'CineMotion Akasaka'
78
+ ja: 'シネマ1',
79
+ en: 'CINEMA1'
80
+ },
81
+ containedInPlace: {
82
+ typeOf: chevre.factory.placeType.MovieTheater,
83
+ id: '5bfb841d5a78d7948369979a',
84
+ branchCode: '118',
85
+ name: {
86
+ ja: 'シネモーション赤坂 ',
87
+ en: 'CineMotion Akasaka'
88
+ }
87
89
  }
88
90
  }
91
+ },
92
+ serviceType: {
93
+ codeValue: '0001',
94
+ id: '64caf203c73a205ccefe80c5',
95
+ inCodeSet: {
96
+ typeOf: 'CategoryCodeSet',
97
+ identifier: chevre.factory.categoryCode.CategorySetIdentifier.ServiceType
98
+ },
99
+ typeOf: 'CategoryCode'
89
100
  }
90
101
  },
91
- serviceType: {
92
- codeValue: '0001',
93
- id: '64caf203c73a205ccefe80c5',
94
- inCodeSet: {
95
- typeOf: 'CategoryCodeSet',
96
- identifier: chevre.factory.categoryCode.CategorySetIdentifier.ServiceType
102
+ // validFrom: new Date('2024-09-01T15:00:00.000Z'),
103
+ // validThrough: new Date('2024-09-15T11:45:00.000Z'),
104
+ seller: {
105
+ typeOf: chevre.factory.organizationType.Corporation,
106
+ id: '59d20831e53ebc2b4e774466',
107
+ name: {
108
+ ja: 'シネモーション赤坂',
109
+ en: 'CineMotion Akasaka'
97
110
  },
98
- typeOf: 'CategoryCode'
99
- }
100
- },
101
- // validFrom: new Date('2024-09-01T15:00:00.000Z'),
102
- // validThrough: new Date('2024-09-15T11:45:00.000Z'),
103
- seller: {
104
- typeOf: chevre.factory.organizationType.Corporation,
105
- id: '59d20831e53ebc2b4e774466',
106
- name: {
107
- ja: 'シネモーション赤坂',
108
- en: 'CineMotion Akasaka'
111
+ makesOffer: [
112
+ {
113
+ typeOf: chevre.factory.offerType.Offer,
114
+ availableAtOrFrom: { id: '51qbjcfr72h62m06vtv5kkhgje' },
115
+ availabilityEnds: now,
116
+ availabilityStarts: now,
117
+ validFrom: now,
118
+ validThrough: now
119
+ }
120
+ ]
109
121
  },
110
- makesOffer: [
111
- {
112
- typeOf: chevre.factory.offerType.Offer,
113
- availableAtOrFrom: { id: '51qbjcfr72h62m06vtv5kkhgje' },
114
- availabilityEnds: now,
115
- availabilityStarts: now,
116
- validFrom: now,
117
- validThrough: now
118
- }
122
+ unacceptedPaymentMethod: [
123
+ 'MovieTicket'
119
124
  ]
120
125
  },
121
- unacceptedPaymentMethod: [
122
- 'MovieTicket'
123
- ]
124
- },
125
- organizer: {
126
- id: '59d20831e53ebc2b4e774466'
127
- },
128
- startDate: new Date('2024-10-17T05:30:00.000Z'),
129
- superEvent: {
130
- typeOf: chevre.factory.eventType.ScreeningEventSeries,
131
- id: 'akeuu512i',
132
- videoFormat: [
133
- {
134
- typeOf: '2D',
135
- name: '2D'
136
- }
137
- ],
138
- soundFormat: [],
139
- workPerformed: {
140
- typeOf: chevre.factory.creativeWorkType.Movie,
141
- identifier: '00002',
142
- id: '5bfb841d5a78d79483699803',
126
+ organizer: {
127
+ id: '59d20831e53ebc2b4e774466'
128
+ },
129
+ startDate: new Date('2024-10-17T05:30:00.000Z'),
130
+ superEvent: {
131
+ typeOf: chevre.factory.eventType.ScreeningEventSeries,
132
+ id: 'akeuu512i',
133
+ videoFormat: [
134
+ {
135
+ typeOf: '2D',
136
+ name: '2D'
137
+ }
138
+ ],
139
+ soundFormat: [],
140
+ workPerformed: {
141
+ typeOf: chevre.factory.creativeWorkType.Movie,
142
+ identifier: '00002',
143
+ id: '5bfb841d5a78d79483699803',
144
+ name: {
145
+ en: 'Ocean\'s Eight',
146
+ ja: 'オーシャンズ8'
147
+ },
148
+ duration: 'PT1H50M'
149
+ },
150
+ location: {
151
+ typeOf: chevre.factory.placeType.MovieTheater,
152
+ id: '5bfb841d5a78d7948369979a',
153
+ branchCode: '118',
154
+ name: {
155
+ ja: 'シネモーション赤坂 ',
156
+ en: 'CineMotion Akasaka'
157
+ }
158
+ },
159
+ kanaName: '',
143
160
  name: {
144
161
  en: 'Ocean\'s Eight',
145
162
  ja: 'オーシャンズ8'
146
163
  },
147
- duration: 'PT1H50M'
148
- },
149
- location: {
150
- typeOf: chevre.factory.placeType.MovieTheater,
151
- id: '5bfb841d5a78d7948369979a',
152
- branchCode: '118',
153
- name: {
154
- ja: 'シネモーション赤坂 ',
155
- en: 'CineMotion Akasaka'
164
+ additionalProperty: [],
165
+ startDate: new Date('2020-08-31T15:00:00.000Z'),
166
+ endDate: new Date('2030-01-01T15:00:00.000Z'),
167
+ description: {
168
+ en: '2018 United States crime movie.',
169
+ ja: '2018年のアメリカ合衆国の犯罪映画。'
170
+ },
171
+ headline: {
172
+ ja: '2018/12/14'
156
173
  }
157
- },
158
- kanaName: '',
159
- name: {
160
- en: 'Ocean\'s Eight',
161
- ja: 'オーシャンズ8'
162
- },
163
- additionalProperty: [],
164
- startDate: new Date('2020-08-31T15:00:00.000Z'),
165
- endDate: new Date('2030-01-01T15:00:00.000Z'),
166
- description: {
167
- en: '2018 United States crime movie.',
168
- ja: '2018年のアメリカ合衆国の犯罪映画。'
169
- },
170
- headline: {
171
- ja: '2018/12/14'
172
174
  }
173
175
  }
176
+ ],
177
+ additionalPropertyFilter: { name: 'sampleCreateId' },
178
+ eventSeries: {
179
+ id: 'akeuu512i'
180
+ },
181
+ screeningRoom: {
182
+ branchCode: '10'
174
183
  }
175
- ],
176
- additionalPropertyFilter: { name: 'sampleCreateId' },
177
- eventSeries: {
178
- id: 'akeuu512i'
179
- },
180
- screeningRoom: {
181
- branchCode: '10'
182
184
  },
183
- options: { updateOffersSeller: false }
184
- });
185
+ { update: false }
186
+ );
185
187
  // tslint:disable-next-line:no-null-keyword
186
188
  console.dir(result, { depth: null });
187
189
  }
@@ -116,9 +116,12 @@ export declare class EventRepo {
116
116
  */
117
117
  branchCode: string;
118
118
  };
119
- options: {
120
- updateOffersSeller: boolean;
121
- };
119
+ }, options: {
120
+ /**
121
+ * falseの場合setOnInsertのみ
122
+ * trueの場合setのみ
123
+ */
124
+ update: boolean;
122
125
  }): Promise<{
123
126
  bulkWriteResult: BulkWriteResult;
124
127
  modifiedEvents: {
@@ -388,9 +388,9 @@ class EventRepo {
388
388
  * 存在すれば、特定の属性のみ更新する
389
389
  */
390
390
  // tslint:disable-next-line:max-func-body-length
391
- upsertManyByAdditionalProperty(params) {
391
+ upsertManyByAdditionalProperty(params, options) {
392
392
  return __awaiter(this, void 0, void 0, function* () {
393
- const { updateOffersSeller } = params.options;
393
+ const { update } = options;
394
394
  const uniqid = yield Promise.resolve().then(() => require('uniqid'));
395
395
  const bulkWriteOps = [];
396
396
  const additionalProperties = [];
@@ -406,10 +406,7 @@ class EventRepo {
406
406
  throw new factory.errors.ArgumentNull('additionalProperty.value');
407
407
  }
408
408
  additionalProperties.push({ name: additionalPropertyFilter.name, value: additionalPropertyValue });
409
- const { coaInfo, // ←適用しない
410
- maximumAttendeeCapacity, remainingAttendeeCapacity, checkInCount, attendeeCount, aggregateReservation, // ←適用しない
411
- eventStatus, superEvent, offers } = creatingEventParams, setOnInsertFields = __rest(creatingEventParams, ["coaInfo", "maximumAttendeeCapacity", "remainingAttendeeCapacity", "checkInCount", "attendeeCount", "aggregateReservation", "eventStatus", "superEvent", "offers"]);
412
- if (superEvent.id !== eventSeries.id) {
409
+ if (creatingEventParams.superEvent.id !== eventSeries.id) {
413
410
  throw new factory.errors.Argument('superEvent.id', 'superEvent.id not matched');
414
411
  }
415
412
  if (creatingEventParams.location.branchCode !== screeningRoom.branchCode) {
@@ -417,36 +414,53 @@ class EventRepo {
417
414
  }
418
415
  const filter = {
419
416
  typeOf: { $eq: creatingEventParams.typeOf },
420
- // 追加特性をキーにした冪等イベント作成時のfilterにproject.idを追加(2023-04-06~)
421
417
  'project.id': { $eq: creatingEventParams.project.id },
422
418
  // 追加特性をキーに更新
423
419
  additionalProperty: {
424
420
  $exists: true,
425
421
  $all: [{ name: additionalPropertyFilter.name, value: additionalPropertyValue }]
426
422
  },
427
- 'superEvent.id': { $exists: true, $eq: superEvent.id } // add superEvent.id(2024-09-15~)
423
+ 'superEvent.id': { $exists: true, $eq: creatingEventParams.superEvent.id } // add superEvent.id(2024-09-15~)
428
424
  };
429
- let setOnInsert;
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() });
425
+ if (update === true) {
426
+ // implemente(2024-12-20~)
427
+ const { eventStatus, superEvent, offers // <-上書き可能な属性を限定的に
428
+ } = creatingEventParams;
429
+ bulkWriteOps.push({
430
+ updateOne: {
431
+ filter,
432
+ update: {
433
+ $set: {
434
+ eventStatus,
435
+ superEvent,
436
+ 'offers.seller.makesOffer': offers.seller.makesOffer
437
+ }
438
+ },
439
+ upsert: false
440
+ }
441
+ });
434
442
  }
435
443
  else {
436
- setOnInsert = Object.assign(Object.assign({}, setOnInsertFields), { offers, _id: uniqid() });
444
+ const { coaInfo, identifier, // ←適用しない
445
+ maximumAttendeeCapacity, remainingAttendeeCapacity, checkInCount, attendeeCount, aggregateReservation, // ←適用しない
446
+ eventStatus, superEvent } = creatingEventParams, // <-上書き可能な属性を限定的に
447
+ setOnInsertFields = __rest(creatingEventParams, ["coaInfo", "identifier", "maximumAttendeeCapacity", "remainingAttendeeCapacity", "checkInCount", "attendeeCount", "aggregateReservation", "eventStatus", "superEvent"]);
448
+ const setOnInsert = Object.assign(Object.assign({}, setOnInsertFields), { _id: uniqid() });
449
+ bulkWriteOps.push({
450
+ updateOne: {
451
+ filter,
452
+ update: {
453
+ $setOnInsert: setOnInsert,
454
+ // 変更可能な属性のみ上書き
455
+ $set: {
456
+ eventStatus,
457
+ superEvent // add superEvent(2024-09-15~)
458
+ }
459
+ },
460
+ upsert: true
461
+ }
462
+ });
437
463
  }
438
- bulkWriteOps.push({
439
- updateOne: {
440
- filter,
441
- update: {
442
- $setOnInsert: setOnInsert,
443
- // 変更可能な属性のみ上書き
444
- $set: Object.assign({ eventStatus,
445
- superEvent }, (updateOffersSeller) ? { 'offers.seller': offers.seller } : undefined)
446
- },
447
- upsert: true
448
- }
449
- });
450
464
  });
451
465
  }
452
466
  if (bulkWriteOps.length > 0) {
@@ -461,7 +475,6 @@ class EventRepo {
461
475
  _id: 0,
462
476
  id: { $toString: '$_id' }
463
477
  })
464
- // .select(['_id'])
465
478
  .lean() // lean(2024-09-15~)
466
479
  .exec();
467
480
  return { bulkWriteResult, modifiedEvents };
@@ -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
- declare function verifyToken(params: {
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.verifyToken = exports.getToken = void 0;
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 credentials = {
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
- throw new factory.errors.ArgumentNull('issuer');
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 = `${credentials.jwt.payloadTypPrefix}:${authorization.object.member.typeOf}`;
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 = `${credentials.jwt.payloadTypPrefix}:${params.agent.typeOf}`;
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: credentials.jwt.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, credentials.jwt.secret, Object.assign(Object.assign({ algorithm: ALGORITHM, issuer: params.issuer, expiresIn: params.expiresIn, subject }, (typeof params.audience === 'string') ? { audience: params.audience } : undefined), (typeof jti === 'string') ? { jwtid: jti } : undefined // 拡張(2024-05-08~)
74
- ), (err, encoded) => {
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
- // tslint:disable-next-line:no-console
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
- // tslint:disable-next-line:no-console
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
- // tslint:disable-next-line:no-console
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
- // tslint:disable-next-line:no-console
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
- // tslint:disable-next-line:no-console
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
- // tslint:disable-next-line:no-console
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
@@ -112,5 +112,5 @@
112
112
  "postversion": "git push origin --tags",
113
113
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
114
114
  },
115
- "version": "22.7.0-alpha.16"
115
+ "version": "22.7.0-alpha.18"
116
116
  }