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

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,28 @@ 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
+ custom_args: msg.customArgs
126
+ },
127
+ method: 'POST',
128
+ url: '/v3/mail/send'
129
+ });
112
130
  // check the response.
113
131
  if (response[0].statusCode !== http_status_1.ACCEPTED) {
114
132
  throw new factory.errors.Internal(`sendgrid request not accepted. response is ${util.inspect(response)}`);
115
133
  }
116
- const { statusCode, statusMessage } = response[0];
117
- result = { statusCode, statusMessage };
134
+ const { statusCode } = response[0];
135
+ result = { statusCode };
118
136
  recipe = (0, factory_1.createSendEmailMessageRecipe)({
119
137
  mailData: msg,
120
138
  afterMedia: result,
@@ -155,7 +173,6 @@ function notifyByEmail(params
155
173
  if (typeof apiKey !== 'string') {
156
174
  throw new factory.errors.Internal('API Key not found');
157
175
  }
158
- sgMail.setApiKey(apiKey);
159
176
  const senderName = (_b = (_a = credentials.sendGrid.alert) === null || _a === void 0 ? void 0 : _a.sender) === null || _b === void 0 ? void 0 : _b.name;
160
177
  const senderEmail = (_d = (_c = credentials.sendGrid.alert) === null || _c === void 0 ? void 0 : _c.sender) === null || _d === void 0 ? void 0 : _d.email;
161
178
  const toRecipientEmail = (Array.isArray((_e = credentials.sendGrid.alert) === null || _e === void 0 ? void 0 : _e.toRecipient))
@@ -227,14 +244,27 @@ function notifyByEmail(params
227
244
  // actionId: action.id,
228
245
  // projectId: project.id
229
246
  } });
230
- // mlutiple recipients対応(2023-03-06~)
231
- const response = yield sgMail.sendMultiple(msg);
247
+ const sgClient = new client_1.Client();
248
+ sgClient.setApiKey(apiKey);
249
+ // const response = await sgMail.sendMultiple(msg);
250
+ const response = yield sgClient.request({
251
+ body: {
252
+ content: [{ type: 'text/plain', value: msg.text }],
253
+ from: msg.from,
254
+ personalizations: [{ to: msg.to }],
255
+ subject: msg.subject,
256
+ custom_args: msg.customArgs
257
+ },
258
+ method: 'POST',
259
+ url: '/v3/mail/send'
260
+ });
232
261
  // check the response.
233
262
  if (response[0].statusCode !== http_status_1.ACCEPTED) {
234
263
  throw new factory.errors.Internal(`sendgrid request not accepted. response is ${util.inspect(response)}`);
235
264
  }
236
- const { statusCode, statusMessage } = response[0];
237
- result = { statusCode, statusMessage };
265
+ const { statusCode } = response[0];
266
+ // const statusMessage = response[1];
267
+ result = { statusCode };
238
268
  }
239
269
  catch (error) {
240
270
  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.75"
116
117
  }