@chevre/domain 22.7.0-alpha.5 → 22.7.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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({}, ['quota']);
28
+ const result = await settingRepo.findOne({}, ['triggerWebhook']);
29
29
  // tslint:disable-next-line:no-null-keyword
30
30
  console.dir(result, { depth: null });
31
31
 
@@ -53,11 +53,13 @@ async function main() {
53
53
  const updateResult = await settingRepo.updateByProject(
54
54
  { project: { id: { $eq: '*' } } },
55
55
  {
56
- quota: {
57
- codeExpiresInSecondsDefault: 600,
58
- codeExpiresInSecondsMax: 8035200,
59
- placeOrderExpiresInSecondsMax: 3600,
60
- placeOrderExpiresInSecondsMin: 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
61
63
  }
62
64
  }
63
65
  );
@@ -5,7 +5,9 @@ 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: {}, credentials: {
8
+ type ILineNotifyOperation<T> = (repos: {
9
+ setting: SettingRepo;
10
+ }, credentials: {
9
11
  lineNotify: LINENotifyCredentials;
10
12
  }) => Promise<T>;
11
13
  /**
@@ -30,9 +32,6 @@ declare function lineNotify({ subject, content, imageThumbnail, imageFullsize, l
30
32
  imageThumbnail?: string;
31
33
  imageFullsize?: string;
32
34
  logLevel: LineNotifyLogLevel;
33
- }, options: {
34
- timeout: number;
35
- useFetchAPI: boolean;
36
35
  }): ILineNotifyOperation<void>;
37
36
  declare function triggerWebhook(params: factory.task.IData<factory.taskName.TriggerWebhook> & {
38
37
  project: {
@@ -122,9 +122,21 @@ 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 }, options) {
126
- return (__, credentials) => __awaiter(this, void 0, void 0, function* () {
127
- const { timeout, useFetchAPI } = options;
125
+ function lineNotify({ subject, content, imageThumbnail, imageFullsize, logLevel }
126
+ // options: {
127
+ // timeout: number;
128
+ // useFetchAPI: boolean;
129
+ // }
130
+ ) {
131
+ return (repos, credentials) => __awaiter(this, void 0, void 0, function* () {
132
+ var _a, _b;
133
+ // const { timeout, useFetchAPI } = options;
134
+ const setting = yield repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['triggerWebhook']);
135
+ const timeout = (_a = setting === null || setting === void 0 ? void 0 : setting.triggerWebhook) === null || _a === void 0 ? void 0 : _a.timeout;
136
+ const useFetchAPI = ((_b = setting === null || setting === void 0 ? void 0 : setting.triggerWebhook) === null || _b === void 0 ? void 0 : _b.useFetchAPI) === true;
137
+ if (typeof timeout !== 'number') {
138
+ throw new factory.errors.NotFound('setting.triggerWebhook.timeout');
139
+ }
128
140
  const LINE_NOTIFY_URL = credentials.lineNotify.url;
129
141
  if (typeof LINE_NOTIFY_URL !== 'string') {
130
142
  throw new factory.errors.Internal('Environment variable LINE_NOTIFY_URL not set');
@@ -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
- }, { timeout, useFetchAPI })({}, credentials);
175
+ }
176
+ // { timeout, useFetchAPI }
177
+ )(repos, 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
- }, { timeout, useFetchAPI })({}, credentials);
197
+ }
198
+ // { timeout, useFetchAPI }
199
+ )(repos, credentials);
210
200
  }
211
201
  });
212
202
  }
package/package.json CHANGED
@@ -108,5 +108,5 @@
108
108
  "postversion": "git push origin --tags",
109
109
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
110
110
  },
111
- "version": "22.7.0-alpha.5"
111
+ "version": "22.7.0-alpha.6"
112
112
  }