@chevre/domain 21.18.0-alpha.1 → 21.18.0-alpha.2

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,10 @@ async function main() {
25
25
  typeOf: chevre.factory.creativeWorkType.WebApplication
26
26
  },
27
27
  object: { sample: 'sample' }
28
- })({ action: await chevre.repository.Action.createInstance(mongoose.connection) });
28
+ })({
29
+ action: await chevre.repository.Action.createInstance(mongoose.connection),
30
+ useFetchAPI: true
31
+ });
29
32
  }
30
33
 
31
34
  main()
@@ -1,8 +1,9 @@
1
1
  import * as factory from '../factory';
2
2
  import type { MongoRepository as ActionRepo } from '../repo/action';
3
3
  import type { MongoRepository as ProjectRepo } from '../repo/project';
4
- export type Operation<T> = (repos: {
4
+ export type IReport2developersOperation<T> = (repos: {
5
5
  accessToken: string;
6
+ useFetchAPI: boolean;
6
7
  }) => Promise<T>;
7
8
  /**
8
9
  * Eメールメッセージを送信する
@@ -16,7 +17,13 @@ export declare function sendEmailMessage(params: factory.action.transfer.send.me
16
17
  * 開発者に報告する
17
18
  * https://notify-bot.line.me/doc/ja/
18
19
  */
19
- export declare function report2developers(subject: string, content: string, imageThumbnail?: string, imageFullsize?: string): Operation<void>;
20
+ export declare function report2developers({ subject, content, imageThumbnail, imageFullsize }: {
21
+ subject: string;
22
+ content: string;
23
+ imageThumbnail?: string;
24
+ imageFullsize?: string;
25
+ }): IReport2developersOperation<void>;
20
26
  export declare function triggerWebhook(params: factory.task.IData<factory.taskName.TriggerWebhook>): (repos: {
21
27
  action: ActionRepo;
28
+ useFetchAPI: boolean;
22
29
  }) => Promise<void>;
@@ -121,8 +121,8 @@ exports.sendEmailMessage = sendEmailMessage;
121
121
  * 開発者に報告する
122
122
  * https://notify-bot.line.me/doc/ja/
123
123
  */
124
- // tslint:disable-next-line:max-func-body-length
125
- function report2developers(subject, content, imageThumbnail, imageFullsize) {
124
+ function report2developers({ subject, content, imageThumbnail, imageFullsize }) {
125
+ // tslint:disable-next-line:max-func-body-length
126
126
  return (repos) => __awaiter(this, void 0, void 0, function* () {
127
127
  var _a;
128
128
  const LINE_NOTIFY_URL = credentials_1.credentials.lineNotify.url;
@@ -133,7 +133,7 @@ function report2developers(subject, content, imageThumbnail, imageFullsize) {
133
133
  ${subject}
134
134
  --------
135
135
  ${content}`;
136
- if (settings_1.USE_FETCH_API) {
136
+ if (repos.useFetchAPI) {
137
137
  try {
138
138
  const form = new FormData();
139
139
  form.set('message', message);
@@ -148,12 +148,18 @@ ${content}`;
148
148
  }, body: form }, (typeof ((_a = settings_1.settings.webhook) === null || _a === void 0 ? void 0 : _a.timeout) === 'number')
149
149
  ? { signal: AbortSignal.timeout(settings_1.settings.webhook.timeout) }
150
150
  : undefined));
151
- const body = yield res.json();
151
+ let body;
152
+ try {
153
+ body = yield res.json();
154
+ }
155
+ catch (error) {
156
+ // no op
157
+ }
152
158
  switch (res.status) {
153
159
  case http_status_1.OK:
154
160
  break;
155
161
  default:
156
- throw new Error(`${res.status} ${body.message}`);
162
+ throw new Error(`${res.status} ${body === null || body === void 0 ? void 0 : body.message}`);
157
163
  }
158
164
  }
159
165
  catch (err) {
@@ -257,7 +263,7 @@ function processInformAction(params) {
257
263
  try {
258
264
  if (typeof ((_a = params.recipient) === null || _a === void 0 ? void 0 : _a.url) === 'string') {
259
265
  const url = params.recipient.url;
260
- if (settings_1.USE_FETCH_API) {
266
+ if (repos.useFetchAPI) {
261
267
  try {
262
268
  const res = yield fetch(url, Object.assign({ method: 'POST', headers: {
263
269
  'Content-Type': 'application/json'
@@ -279,7 +285,8 @@ function processInformAction(params) {
279
285
  case http_status_1.ACCEPTED:
280
286
  case http_status_1.NO_CONTENT:
281
287
  result = {
282
- statusCode: res.status
288
+ statusCode: res.status,
289
+ useFetchAPI: repos.useFetchAPI
283
290
  };
284
291
  break;
285
292
  default:
@@ -329,7 +336,8 @@ function processInformAction(params) {
329
336
  case http_status_1.ACCEPTED:
330
337
  case http_status_1.NO_CONTENT:
331
338
  result = {
332
- statusCode: response.statusCode
339
+ statusCode: response.statusCode,
340
+ useFetchAPI: repos.useFetchAPI
333
341
  // body: body
334
342
  };
335
343
  resolve();
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.call = void 0;
13
+ const settings_1 = require("../../settings");
13
14
  const action_1 = require("../../repo/action");
14
15
  const NotificationService = require("../notification");
15
16
  /**
@@ -17,8 +18,10 @@ const NotificationService = require("../notification");
17
18
  */
18
19
  function call(data) {
19
20
  return (settings) => __awaiter(this, void 0, void 0, function* () {
20
- const actionRepo = new action_1.MongoRepository(settings.connection);
21
- yield NotificationService.triggerWebhook(data)({ action: actionRepo });
21
+ yield NotificationService.triggerWebhook(data)({
22
+ action: new action_1.MongoRepository(settings.connection),
23
+ useFetchAPI: settings_1.USE_FETCH_API
24
+ });
22
25
  });
23
26
  }
24
27
  exports.call = call;
@@ -143,8 +143,9 @@ function abort(params) {
143
143
  }
144
144
  // 開発者へ報告
145
145
  const message = (0, factory_1.task2lineNotify)({ task: abortedTask });
146
- yield notification.report2developers(message.subject, message.content)({
147
- accessToken: credentials_1.credentials.lineNotify.accessTokenAlert
146
+ yield notification.report2developers({ subject: message.subject, content: message.content })({
147
+ accessToken: credentials_1.credentials.lineNotify.accessTokenAlert,
148
+ useFetchAPI: settings_1.USE_FETCH_API
148
149
  });
149
150
  }
150
151
  });
@@ -155,18 +156,15 @@ function notifyAbortedTasks(params) {
155
156
  const abortedTasks = yield repos.task.search(Object.assign({ statuses: [factory.taskStatus.Aborted], dateAborted: { $gte: params.dateAbortedGte } }, (settings_1.ABORTED_TASKS_WITHOUT_REPORT.length > 0)
156
157
  ? { name: { $nin: settings_1.ABORTED_TASKS_WITHOUT_REPORT } }
157
158
  : undefined));
158
- // 中止を報告しないタスク以外にフィルター
159
- // abortedTasks = abortedTasks.filter((task) => {
160
- // return !ABORTED_TASKS_WITHOUT_REPORT.includes(task.name);
161
- // });
162
159
  if (abortedTasks.length > 0) {
163
160
  if (notification === undefined) {
164
161
  notification = yield Promise.resolve().then(() => require('./notification'));
165
162
  }
166
163
  // 開発者へ報告
167
164
  const message = (0, factory_1.tasks2lineNotify)({ tasks: abortedTasks });
168
- yield notification.report2developers(message.subject, message.content)({
169
- accessToken: credentials_1.credentials.lineNotify.accessTokenAlert
165
+ yield notification.report2developers({ subject: message.subject, content: message.content })({
166
+ accessToken: credentials_1.credentials.lineNotify.accessTokenAlert,
167
+ useFetchAPI: settings_1.USE_FETCH_API
170
168
  });
171
169
  }
172
170
  });
package/package.json CHANGED
@@ -43,8 +43,7 @@
43
43
  "@types/lodash.difference": "^4.5.6",
44
44
  "@types/mocha": "^5.2.7",
45
45
  "@types/moment-timezone": "^0.5.30",
46
- "@types/nock": "^9.3.1",
47
- "@types/node": "14.18.42",
46
+ "@types/node": "18.19.2",
48
47
  "@types/power-assert": "^1.5.3",
49
48
  "@types/pug": "^2.0.4",
50
49
  "@types/request": "^2.48.5",
@@ -59,13 +58,12 @@
59
58
  "json2csv": "4.5.4",
60
59
  "mocha": "^5.2.0",
61
60
  "mongoose": "7.0.5",
62
- "nock": "^9.6.1",
61
+ "nock": "13.4.0",
63
62
  "nyc": "^15.1.0",
64
63
  "power-assert": "^1.6.1",
65
64
  "redis": "4.6.5",
66
- "request-promise-native": "^1.0.9",
67
65
  "rimraf": "^2.7.1",
68
- "sinon": "^4.5.0",
66
+ "sinon": "4.5.0",
69
67
  "sinon-mongoose": "^2.3.0",
70
68
  "ts-node": "^10.9.1",
71
69
  "tslint": "^6.1.3",
@@ -78,7 +76,7 @@
78
76
  "redis": "^4.6.5"
79
77
  },
80
78
  "engines": {
81
- "node": ">=14.0.0",
79
+ "node": ">=18.0.0",
82
80
  "npm": ">=6.0.0"
83
81
  },
84
82
  "keywords": [],
@@ -117,5 +115,5 @@
117
115
  "postversion": "git push origin --tags",
118
116
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
117
  },
120
- "version": "21.18.0-alpha.1"
118
+ "version": "21.18.0-alpha.2"
121
119
  }