@chevre/domain 22.9.0-alpha.73 → 22.9.0-alpha.74

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.
@@ -0,0 +1,56 @@
1
+ // tslint:disable:no-console
2
+ import * as moment from 'moment';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../lib/index';
6
+
7
+ // const project = { id: String(process.env.PROJECT_ID) };
8
+
9
+ async function main() {
10
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
+
12
+ const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
13
+ const sendGridCredentials = await chevre.credentials.SendGrid.createInstance({
14
+ apiKey: <string>process.env.SENDGRID_API_KEY,
15
+ alert: {
16
+ sender: {
17
+ name: 'xxx',
18
+ email: 'xxx'
19
+ },
20
+ toRecipient: [
21
+ { email: 'xxx' }
22
+ ]
23
+ }
24
+ });
25
+ const chevreSettings = new chevre.settings.Settings(<any>{
26
+ abortedTasksWithoutReport: [
27
+ chevre.factory.taskName.ImportEventCapacitiesFromCOA,
28
+ chevre.factory.taskName.ImportEventsFromCOA,
29
+ chevre.factory.taskName.ImportOffersFromCOA
30
+ ]
31
+ });
32
+
33
+ const result = await (await chevre.service.task.createService()).notifyAbortedTasksByEmail({
34
+ dateAbortedGte: moment()
35
+ // tslint:disable-next-line:no-magic-numbers
36
+ .add(-10, 'days')
37
+ .toDate()
38
+ })(
39
+ {
40
+ task: taskRepo
41
+ },
42
+ chevreSettings,
43
+ {
44
+ sendGrid: sendGridCredentials
45
+ }
46
+ );
47
+ // tslint:disable-next-line:no-null-keyword
48
+ console.dir(result, { depth: null });
49
+ }
50
+
51
+ main()
52
+ .then(console.log)
53
+ .catch((error) => {
54
+ // tslint:disable-next-line:no-null-keyword
55
+ console.dir(error, { depth: null });
56
+ });
@@ -1,5 +1,4 @@
1
1
  // tslint:disable:no-console
2
- import * as moment from 'moment';
3
2
  import * as mongoose from 'mongoose';
4
3
 
5
4
  import { chevre } from '../../../lib/index';
@@ -9,7 +8,6 @@ import { chevre } from '../../../lib/index';
9
8
  async function main() {
10
9
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
10
 
12
- const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
13
11
  const sendGridCredentials = await chevre.credentials.SendGrid.createInstance({
14
12
  apiKey: <string>process.env.SENDGRID_API_KEY,
15
13
  alert: {
@@ -22,24 +20,13 @@ async function main() {
22
20
  ]
23
21
  }
24
22
  });
25
- const chevreSettings = new chevre.settings.Settings(<any>{
26
- abortedTasksWithoutReport: [
27
- chevre.factory.taskName.ImportEventCapacitiesFromCOA,
28
- chevre.factory.taskName.ImportEventsFromCOA,
29
- chevre.factory.taskName.ImportOffersFromCOA
30
- ]
31
- });
32
23
 
33
- const result = await (await chevre.service.task.createService()).notifyAbortedTasksByEmail({
34
- dateAbortedGte: moment()
35
- // tslint:disable-next-line:no-magic-numbers
36
- .add(-10, 'days')
37
- .toDate()
24
+ const result = await (await chevre.service.notification.createService()).notifyByEmail({
25
+ subject: 'sample',
26
+ content: 'sample',
27
+ logLevel: 'error'
38
28
  })(
39
- {
40
- task: taskRepo
41
- },
42
- chevreSettings,
29
+ {},
43
30
  {
44
31
  sendGrid: sendGridCredentials
45
32
  }
@@ -0,0 +1,60 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ const project = { id: String(process.env.PROJECT_ID) };
7
+
8
+ async function main() {
9
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
+
11
+ const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
12
+ const messageRepo = await chevre.repository.Message.createInstance(mongoose.connection);
13
+ const projectRepo = await chevre.repository.Project.createInstance(mongoose.connection);
14
+ const sendGridCredentials = await chevre.credentials.SendGrid.createInstance({
15
+ apiKey: <string>process.env.SENDGRID_API_KEY
16
+ });
17
+
18
+ const result = await (await chevre.service.notification.createService()).sendEmailMessage({
19
+ agent: { id: project.id, typeOf: chevre.factory.organizationType.Project },
20
+ object: {
21
+ text: 'sample',
22
+ toRecipient: [{
23
+ name: 'sample',
24
+ email: 'xxx'
25
+ }],
26
+ typeOf: chevre.factory.creativeWorkType.EmailMessage,
27
+ sender: {
28
+ name: 'xxx',
29
+ email: 'xxx'
30
+ },
31
+ about: {
32
+ identifier: <any>'sample',
33
+ name: 'sample',
34
+ typeOf: 'Thing'
35
+ }
36
+ },
37
+ project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
38
+ purpose: <any>{},
39
+ recipient: { id: 'xxx', typeOf: chevre.factory.creativeWorkType.WebApplication },
40
+ typeOf: chevre.factory.actionType.SendAction
41
+ })(
42
+ {
43
+ action: actionRepo,
44
+ message: messageRepo,
45
+ project: projectRepo
46
+ },
47
+ {
48
+ sendGrid: sendGridCredentials
49
+ }
50
+ );
51
+ // tslint:disable-next-line:no-null-keyword
52
+ console.dir(result, { depth: null });
53
+ }
54
+
55
+ main()
56
+ .then(console.log)
57
+ .catch((error) => {
58
+ // tslint:disable-next-line:no-null-keyword
59
+ console.dir(error, { depth: null });
60
+ });
@@ -11,13 +11,11 @@ async function main() {
11
11
  // "limit": 10
12
12
  };
13
13
 
14
- const request = {
14
+ client.request({
15
15
  url: `/v3/messages`,
16
16
  method: 'GET',
17
17
  qs: queryParams
18
- };
19
-
20
- client.request(request)
18
+ })
21
19
  .then(([response, body]) => {
22
20
  console.log(response.statusCode);
23
21
  console.log(response.body, body);
@@ -13,7 +13,11 @@ exports.lineNotify = lineNotify;
13
13
  exports.notifyByEmail = notifyByEmail;
14
14
  exports.sendEmailMessage = sendEmailMessage;
15
15
  exports.triggerWebhook = triggerWebhook;
16
- const sgMail = require("@sendgrid/mail");
16
+ /**
17
+ * 通知サービス
18
+ */
19
+ const client_1 = require("@sendgrid/client");
20
+ // import * as sgMail from '@sendgrid/mail';
17
21
  const crypto = require("crypto");
18
22
  const http_status_1 = require("http-status");
19
23
  const util = require("util");
@@ -51,7 +55,7 @@ function sendEmailMessage(params) {
51
55
  if (typeof apiKey !== 'string') {
52
56
  throw new factory.errors.Internal('API Key not found');
53
57
  }
54
- sgMail.setApiKey(apiKey);
58
+ // sgMail.setApiKey(apiKey); // fix(2025-03-14~)
55
59
  let emailMessage;
56
60
  if (typeof params.object.text === 'string') {
57
61
  emailMessage = params.object;
@@ -107,14 +111,27 @@ function sendEmailMessage(params) {
107
111
  actionId: action.id,
108
112
  projectId: project.id
109
113
  } });
110
- // mlutiple recipients対応(2023-03-06~)
111
- const response = yield sgMail.sendMultiple(msg);
114
+ // reimplement using Client(2025-03-14~)
115
+ // const response = await sgMail.sendMultiple(msg);
116
+ const sgClient = new client_1.Client();
117
+ sgClient.setApiKey(apiKey);
118
+ // const response = await sgMail.sendMultiple(msg);
119
+ const response = yield sgClient.request({
120
+ body: {
121
+ content: [{ type: 'text/plain', value: msg.text }],
122
+ from: msg.from,
123
+ personalizations: [{ to: msg.to }],
124
+ subject: msg.subject
125
+ },
126
+ method: 'POST',
127
+ url: '/v3/mail/send'
128
+ });
112
129
  // check the response.
113
130
  if (response[0].statusCode !== http_status_1.ACCEPTED) {
114
131
  throw new factory.errors.Internal(`sendgrid request not accepted. response is ${util.inspect(response)}`);
115
132
  }
116
- const { statusCode, statusMessage } = response[0];
117
- result = { statusCode, statusMessage };
133
+ const { statusCode } = response[0];
134
+ result = { statusCode };
118
135
  recipe = (0, factory_1.createSendEmailMessageRecipe)({
119
136
  mailData: msg,
120
137
  afterMedia: result,
@@ -155,7 +172,6 @@ function notifyByEmail(params
155
172
  if (typeof apiKey !== 'string') {
156
173
  throw new factory.errors.Internal('API Key not found');
157
174
  }
158
- sgMail.setApiKey(apiKey);
159
175
  const senderName = (_b = (_a = credentials.sendGrid.alert) === null || _a === void 0 ? void 0 : _a.sender) === null || _b === void 0 ? void 0 : _b.name;
160
176
  const senderEmail = (_d = (_c = credentials.sendGrid.alert) === null || _c === void 0 ? void 0 : _c.sender) === null || _d === void 0 ? void 0 : _d.email;
161
177
  const toRecipientEmail = (Array.isArray((_e = credentials.sendGrid.alert) === null || _e === void 0 ? void 0 : _e.toRecipient))
@@ -227,14 +243,26 @@ function notifyByEmail(params
227
243
  // actionId: action.id,
228
244
  // projectId: project.id
229
245
  } });
230
- // mlutiple recipients対応(2023-03-06~)
231
- const response = yield sgMail.sendMultiple(msg);
246
+ const sgClient = new client_1.Client();
247
+ sgClient.setApiKey(apiKey);
248
+ // const response = await sgMail.sendMultiple(msg);
249
+ const response = yield sgClient.request({
250
+ body: {
251
+ content: [{ type: 'text/plain', value: msg.text }],
252
+ from: msg.from,
253
+ personalizations: [{ to: msg.to }],
254
+ subject: msg.subject
255
+ },
256
+ method: 'POST',
257
+ url: '/v3/mail/send'
258
+ });
232
259
  // check the response.
233
260
  if (response[0].statusCode !== http_status_1.ACCEPTED) {
234
261
  throw new factory.errors.Internal(`sendgrid request not accepted. response is ${util.inspect(response)}`);
235
262
  }
236
- const { statusCode, statusMessage } = response[0];
237
- result = { statusCode, statusMessage };
263
+ const { statusCode } = response[0];
264
+ // const statusMessage = response[1];
265
+ result = { statusCode };
238
266
  }
239
267
  catch (error) {
240
268
  throw error;
package/package.json CHANGED
@@ -15,6 +15,7 @@
15
15
  "@cinerino/sdk": "10.21.0-alpha.24",
16
16
  "@motionpicture/coa-service": "9.6.0",
17
17
  "@motionpicture/gmo-service": "5.3.0",
18
+ "@sendgrid/client": "8.1.4",
18
19
  "@sendgrid/mail": "6.4.0",
19
20
  "@surfrock/sdk": "1.4.0-alpha.1",
20
21
  "cdigit": "2.6.7",
@@ -112,5 +113,5 @@
112
113
  "postversion": "git push origin --tags",
113
114
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
114
115
  },
115
- "version": "22.9.0-alpha.73"
116
+ "version": "22.9.0-alpha.74"
116
117
  }