@chevre/domain 22.7.0-alpha.5 → 22.7.0-alpha.7
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/findSetting.ts +15 -6
- package/lib/chevre/repo/mongoose/schemas/setting.d.ts +8 -1
- package/lib/chevre/repo/mongoose/schemas/setting.js +2 -1
- package/lib/chevre/repo/setting.d.ts +3 -3
- package/lib/chevre/repo/setting.js +2 -2
- package/lib/chevre/service/notification.d.ts +1 -4
- package/lib/chevre/service/notification.js +33 -33
- package/lib/chevre/service/task.js +6 -16
- package/package.json +1 -1
|
@@ -25,7 +25,7 @@ async function main() {
|
|
|
25
25
|
|
|
26
26
|
const settingRepo = await chevre.repository.Setting.createInstance(mongoose.connection);
|
|
27
27
|
|
|
28
|
-
const result = await settingRepo.findOne({}, ['
|
|
28
|
+
const result = await settingRepo.findOne({}, ['triggerWebhook', 'waiter']);
|
|
29
29
|
// tslint:disable-next-line:no-null-keyword
|
|
30
30
|
console.dir(result, { depth: null });
|
|
31
31
|
|
|
@@ -53,11 +53,20 @@ async function main() {
|
|
|
53
53
|
const updateResult = await settingRepo.updateByProject(
|
|
54
54
|
{ project: { id: { $eq: '*' } } },
|
|
55
55
|
{
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
triggerWebhook: {
|
|
57
|
+
timeout: 15000,
|
|
58
|
+
useFetchAPI: true,
|
|
59
|
+
secretKey: String(process.env.TRIGGER_WEBHOOK_SECRET_KEY),
|
|
60
|
+
headerIdentifier: String(process.env.TRIGGER_WEBHOOK_HEADER_IDENTIFIER),
|
|
61
|
+
retryCountMax: 2,
|
|
62
|
+
retryIntervalInMS: 1000
|
|
63
|
+
},
|
|
64
|
+
waiter: {
|
|
65
|
+
disabled: process.env.WAITER_DISABLED === '1',
|
|
66
|
+
passportUnavailable: process.env.WAITER_PASSPORT_UNAVAILABLE === '1',
|
|
67
|
+
passportIssuers: String(process.env.WAITER_PASSPORT_ISSUER)
|
|
68
|
+
.split(' '),
|
|
69
|
+
secret: String(process.env.WAITER_SECRET)
|
|
61
70
|
}
|
|
62
71
|
}
|
|
63
72
|
);
|
|
@@ -48,7 +48,7 @@ interface IQuotaSettings {
|
|
|
48
48
|
placeOrderExpiresInSecondsMax?: number;
|
|
49
49
|
placeOrderExpiresInSecondsMin?: number;
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
interface ITriggerWebhookSettings {
|
|
52
52
|
/**
|
|
53
53
|
* リクエストタイムアウト
|
|
54
54
|
*/
|
|
@@ -65,6 +65,12 @@ export interface ITriggerWebhookSettings {
|
|
|
65
65
|
retryCountMax?: number;
|
|
66
66
|
retryIntervalInMS?: number;
|
|
67
67
|
}
|
|
68
|
+
interface IWaiterSettings {
|
|
69
|
+
disabled?: boolean;
|
|
70
|
+
passportUnavailable?: boolean;
|
|
71
|
+
passportIssuers: string[];
|
|
72
|
+
secret: string;
|
|
73
|
+
}
|
|
68
74
|
export interface ISetting {
|
|
69
75
|
defaultSenderEmail?: string;
|
|
70
76
|
onEventChanged?: IOnEventChanged;
|
|
@@ -87,6 +93,7 @@ export interface ISetting {
|
|
|
87
93
|
useInformResourceTypes?: string[];
|
|
88
94
|
userPoolIdOld?: string;
|
|
89
95
|
userPoolIdNew?: string;
|
|
96
|
+
waiter?: IWaiterSettings;
|
|
90
97
|
}
|
|
91
98
|
type IDocType = ISetting;
|
|
92
99
|
type IModel = Model<IDocType>;
|
|
@@ -19,7 +19,8 @@ const schemaDefinition = {
|
|
|
19
19
|
triggerWebhook: mongoose_1.SchemaTypes.Mixed,
|
|
20
20
|
useInformResourceTypes: [String],
|
|
21
21
|
userPoolIdOld: String,
|
|
22
|
-
userPoolIdNew: String
|
|
22
|
+
userPoolIdNew: String,
|
|
23
|
+
waiter: mongoose_1.SchemaTypes.Mixed
|
|
23
24
|
};
|
|
24
25
|
const schemaOptions = {
|
|
25
26
|
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
/// <reference types="mongoose/types/virtuals" />
|
|
24
24
|
/// <reference types="mongoose/types/inferschematype" />
|
|
25
25
|
import type { Connection } from 'mongoose';
|
|
26
|
-
import { ISetting
|
|
26
|
+
import { ISetting } from './mongoose/schemas/setting';
|
|
27
27
|
type IKeyOfProjection = keyof ISetting;
|
|
28
|
-
export { ISetting
|
|
28
|
+
export { ISetting };
|
|
29
29
|
/**
|
|
30
30
|
* 設定リポジトリ
|
|
31
31
|
*/
|
|
@@ -46,5 +46,5 @@ export declare class SettingRepo {
|
|
|
46
46
|
$eq: string;
|
|
47
47
|
};
|
|
48
48
|
};
|
|
49
|
-
}, update: Pick<ISetting, 'onEventChanged' | 'onReservationStatusChanged' | 'onResourceUpdated' | 'defaultSenderEmail' | 'useInformResourceTypes' | 'userPoolIdNew' | 'userPoolIdOld' | 'storage' | 'quota' | 'triggerWebhook'>): Promise<import("mongoose").UpdateWriteOpResult>;
|
|
49
|
+
}, update: Pick<ISetting, 'onEventChanged' | 'onReservationStatusChanged' | 'onResourceUpdated' | 'defaultSenderEmail' | 'useInformResourceTypes' | 'userPoolIdNew' | 'userPoolIdOld' | 'storage' | 'quota' | 'triggerWebhook' | 'waiter'>): Promise<import("mongoose").UpdateWriteOpResult>;
|
|
50
50
|
}
|
|
@@ -49,9 +49,9 @@ class SettingRepo {
|
|
|
49
49
|
}
|
|
50
50
|
updateByProject(filter, update) {
|
|
51
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
const { onEventChanged, onReservationStatusChanged, onResourceUpdated, defaultSenderEmail, useInformResourceTypes, userPoolIdNew, userPoolIdOld, storage, quota, triggerWebhook } = update;
|
|
52
|
+
const { onEventChanged, onReservationStatusChanged, onResourceUpdated, defaultSenderEmail, useInformResourceTypes, userPoolIdNew, userPoolIdOld, storage, quota, triggerWebhook, waiter } = update;
|
|
53
53
|
return this.settingModel.updateOne({ 'project.id': { $eq: filter.project.id.$eq } }, {
|
|
54
|
-
$set: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (onEventChanged !== undefined) ? { onEventChanged } : undefined), (onReservationStatusChanged !== undefined) ? { onReservationStatusChanged } : undefined), (onResourceUpdated !== undefined) ? { onResourceUpdated } : undefined), (defaultSenderEmail !== undefined) ? { defaultSenderEmail } : undefined), (useInformResourceTypes !== undefined) ? { useInformResourceTypes } : undefined), (userPoolIdNew !== undefined) ? { userPoolIdNew } : undefined), (userPoolIdOld !== undefined) ? { userPoolIdOld } : undefined), (storage !== undefined) ? { storage } : undefined), (quota !== undefined) ? { quota } : undefined), (triggerWebhook !== undefined) ? { triggerWebhook } : undefined)
|
|
54
|
+
$set: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (onEventChanged !== undefined) ? { onEventChanged } : undefined), (onReservationStatusChanged !== undefined) ? { onReservationStatusChanged } : undefined), (onResourceUpdated !== undefined) ? { onResourceUpdated } : undefined), (defaultSenderEmail !== undefined) ? { defaultSenderEmail } : undefined), (useInformResourceTypes !== undefined) ? { useInformResourceTypes } : undefined), (userPoolIdNew !== undefined) ? { userPoolIdNew } : undefined), (userPoolIdOld !== undefined) ? { userPoolIdOld } : undefined), (storage !== undefined) ? { storage } : undefined), (quota !== undefined) ? { quota } : undefined), (triggerWebhook !== undefined) ? { triggerWebhook } : undefined), (waiter !== undefined) ? { waiter } : undefined)
|
|
55
55
|
})
|
|
56
56
|
.exec();
|
|
57
57
|
});
|
|
@@ -5,7 +5,7 @@ import type { ActionRepo } from '../repo/action';
|
|
|
5
5
|
import type { MessageRepo } from '../repo/message';
|
|
6
6
|
import type { ProjectRepo } from '../repo/project';
|
|
7
7
|
import type { SettingRepo } from '../repo/setting';
|
|
8
|
-
type ILineNotifyOperation<T> = (repos:
|
|
8
|
+
type ILineNotifyOperation<T> = (repos: undefined, credentials: {
|
|
9
9
|
lineNotify: LINENotifyCredentials;
|
|
10
10
|
}) => Promise<T>;
|
|
11
11
|
/**
|
|
@@ -30,9 +30,6 @@ declare function lineNotify({ subject, content, imageThumbnail, imageFullsize, l
|
|
|
30
30
|
imageThumbnail?: string;
|
|
31
31
|
imageFullsize?: string;
|
|
32
32
|
logLevel: LineNotifyLogLevel;
|
|
33
|
-
}, options: {
|
|
34
|
-
timeout: number;
|
|
35
|
-
useFetchAPI: boolean;
|
|
36
33
|
}): ILineNotifyOperation<void>;
|
|
37
34
|
declare function triggerWebhook(params: factory.task.IData<factory.taskName.TriggerWebhook> & {
|
|
38
35
|
project: {
|
|
@@ -122,9 +122,14 @@ function sendEmailMessage(params) {
|
|
|
122
122
|
}
|
|
123
123
|
exports.sendEmailMessage = sendEmailMessage;
|
|
124
124
|
const MAX_LINE_NOTIFY_SUBJECT_LENGTH = 100;
|
|
125
|
-
function lineNotify({ subject, content, imageThumbnail, imageFullsize, logLevel }
|
|
125
|
+
function lineNotify({ subject, content, imageThumbnail, imageFullsize, logLevel }
|
|
126
|
+
// options: {
|
|
127
|
+
// timeout: number;
|
|
128
|
+
// useFetchAPI: boolean;
|
|
129
|
+
// }
|
|
130
|
+
) {
|
|
126
131
|
return (__, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
127
|
-
const
|
|
132
|
+
const timeout = 10000;
|
|
128
133
|
const LINE_NOTIFY_URL = credentials.lineNotify.url;
|
|
129
134
|
if (typeof LINE_NOTIFY_URL !== 'string') {
|
|
130
135
|
throw new factory.errors.Internal('Environment variable LINE_NOTIFY_URL not set');
|
|
@@ -149,41 +154,36 @@ function lineNotify({ subject, content, imageThumbnail, imageFullsize, logLevel
|
|
|
149
154
|
const message = util.format('\n%s\n%s\n%s\n%s\n%s\n\n%s', `[${logLevel}] ${shortSubject}`, `now:${(new Date()).toISOString()}`, `pid:${process.pid}`, `GAE_APPLICATION:${process.env.GAE_APPLICATION}`,
|
|
150
155
|
// `GAE_INSTANCE:${process.env.GAE_INSTANCE}`,
|
|
151
156
|
`GAE_SERVICE:${process.env.GAE_SERVICE}`, content);
|
|
152
|
-
|
|
157
|
+
try {
|
|
158
|
+
const form = new FormData();
|
|
159
|
+
form.set('message', message);
|
|
160
|
+
if (typeof imageThumbnail === 'string') {
|
|
161
|
+
form.set('imageThumbnail', imageThumbnail);
|
|
162
|
+
}
|
|
163
|
+
if (typeof imageFullsize === 'string') {
|
|
164
|
+
form.set('imageFullsize', imageFullsize);
|
|
165
|
+
}
|
|
166
|
+
const res = yield fetch(LINE_NOTIFY_URL, Object.assign({ method: 'POST', headers: {
|
|
167
|
+
Authorization: `Bearer ${accessToken}`
|
|
168
|
+
}, body: form }, (typeof timeout === 'number')
|
|
169
|
+
? { signal: AbortSignal.timeout(timeout) }
|
|
170
|
+
: undefined));
|
|
171
|
+
let body;
|
|
153
172
|
try {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
if (typeof imageFullsize === 'string') {
|
|
160
|
-
form.set('imageFullsize', imageFullsize);
|
|
161
|
-
}
|
|
162
|
-
const res = yield fetch(LINE_NOTIFY_URL, Object.assign({ method: 'POST', headers: {
|
|
163
|
-
Authorization: `Bearer ${accessToken}`
|
|
164
|
-
}, body: form }, (typeof timeout === 'number')
|
|
165
|
-
? { signal: AbortSignal.timeout(timeout) }
|
|
166
|
-
: undefined));
|
|
167
|
-
let body;
|
|
168
|
-
try {
|
|
169
|
-
body = yield res.json();
|
|
170
|
-
}
|
|
171
|
-
catch (error) {
|
|
172
|
-
// no op
|
|
173
|
-
}
|
|
174
|
-
switch (res.status) {
|
|
175
|
-
case http_status_1.OK:
|
|
176
|
-
break;
|
|
177
|
-
default:
|
|
178
|
-
throw new factory.errors.Internal(`${res.status} ${body === null || body === void 0 ? void 0 : body.message}`);
|
|
179
|
-
}
|
|
173
|
+
body = yield res.json();
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
// no op
|
|
180
177
|
}
|
|
181
|
-
|
|
182
|
-
|
|
178
|
+
switch (res.status) {
|
|
179
|
+
case http_status_1.OK:
|
|
180
|
+
break;
|
|
181
|
+
default:
|
|
182
|
+
throw new factory.errors.Internal(`${res.status} ${body === null || body === void 0 ? void 0 : body.message}`);
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
|
-
|
|
186
|
-
throw
|
|
185
|
+
catch (err) {
|
|
186
|
+
throw err;
|
|
187
187
|
}
|
|
188
188
|
});
|
|
189
189
|
}
|
|
@@ -152,13 +152,6 @@ let notification;
|
|
|
152
152
|
*/
|
|
153
153
|
function abort(params) {
|
|
154
154
|
return (repos, settings, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
155
|
-
var _a, _b;
|
|
156
|
-
const setting = yield repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['triggerWebhook']);
|
|
157
|
-
const timeout = (_a = setting === null || setting === void 0 ? void 0 : setting.triggerWebhook) === null || _a === void 0 ? void 0 : _a.timeout;
|
|
158
|
-
const useFetchAPI = ((_b = setting === null || setting === void 0 ? void 0 : setting.triggerWebhook) === null || _b === void 0 ? void 0 : _b.useFetchAPI) === true;
|
|
159
|
-
if (typeof timeout !== 'number') {
|
|
160
|
-
throw new factory.errors.NotFound('setting.triggerWebhook.timeout');
|
|
161
|
-
}
|
|
162
155
|
const { abortedTasksWithoutReport } = settings;
|
|
163
156
|
const abortedTask = yield repos.task.abortOne(params);
|
|
164
157
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
@@ -179,20 +172,15 @@ function abort(params) {
|
|
|
179
172
|
yield notification.lineNotify({
|
|
180
173
|
subject: message.subject, content: message.content,
|
|
181
174
|
logLevel: 'error'
|
|
182
|
-
}
|
|
175
|
+
}
|
|
176
|
+
// { timeout, useFetchAPI }
|
|
177
|
+
)(undefined, credentials);
|
|
183
178
|
}
|
|
184
179
|
});
|
|
185
180
|
}
|
|
186
181
|
exports.abort = abort;
|
|
187
182
|
function notifyAbortedTasks(params) {
|
|
188
183
|
return (repos, settings, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
189
|
-
var _a, _b;
|
|
190
|
-
const setting = yield repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['triggerWebhook']);
|
|
191
|
-
const timeout = (_a = setting === null || setting === void 0 ? void 0 : setting.triggerWebhook) === null || _a === void 0 ? void 0 : _a.timeout;
|
|
192
|
-
const useFetchAPI = ((_b = setting === null || setting === void 0 ? void 0 : setting.triggerWebhook) === null || _b === void 0 ? void 0 : _b.useFetchAPI) === true;
|
|
193
|
-
if (typeof timeout !== 'number') {
|
|
194
|
-
throw new factory.errors.NotFound('setting.triggerWebhook.timeout');
|
|
195
|
-
}
|
|
196
184
|
const { abortedTasksWithoutReport } = settings;
|
|
197
185
|
const abortedTasks = yield repos.task.projectFields(Object.assign({ statuses: [factory.taskStatus.Aborted], dateAborted: { $gte: params.dateAbortedGte } }, (abortedTasksWithoutReport.length > 0)
|
|
198
186
|
? { name: { $nin: abortedTasksWithoutReport } }
|
|
@@ -206,7 +194,9 @@ function notifyAbortedTasks(params) {
|
|
|
206
194
|
yield notification.lineNotify({
|
|
207
195
|
subject: message.subject, content: message.content,
|
|
208
196
|
logLevel: 'error'
|
|
209
|
-
}
|
|
197
|
+
}
|
|
198
|
+
// { timeout, useFetchAPI }
|
|
199
|
+
)(undefined, credentials);
|
|
210
200
|
}
|
|
211
201
|
});
|
|
212
202
|
}
|
package/package.json
CHANGED