@chevre/domain 24.1.0-alpha.40 → 24.1.0-alpha.41
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/lib/chevre/index.d.ts +1 -2
- package/lib/chevre/index.js +1 -3
- package/lib/chevre/repo/mongoose/schemas/setting.d.ts +20 -0
- package/lib/chevre/repo/setting/integration.d.ts +2 -1
- package/lib/chevre/repo/setting/integration.js +8 -0
- package/lib/chevre/service/notification/notifyAbortedTasksByEmail.d.ts +2 -4
- package/lib/chevre/service/notification/notifyAbortedTasksByEmail.js +3 -3
- package/lib/chevre/service/notification/notifyByEmail.d.ts +3 -3
- package/lib/chevre/service/notification/notifyByEmail.js +7 -6
- package/lib/chevre/service/notification/sendEmailMessage.d.ts +2 -3
- package/lib/chevre/service/notification/sendEmailMessage.js +5 -4
- package/lib/chevre/service/task/sendEmailMessage.js +5 -3
- package/lib/chevre/service/task.d.ts +0 -5
- package/lib/chevre/taskSettings.d.ts +0 -5
- package/package.json +1 -1
- package/lib/chevre/credentials/sendGrid.d.ts +0 -24
- package/lib/chevre/credentials/sendGrid.js +0 -18
- package/lib/chevre/credentials.d.ts +0 -8
- package/lib/chevre/credentials.js +0 -14
package/lib/chevre/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as credentials from './credentials';
|
|
2
1
|
import * as errorHandler from './errorHandler';
|
|
3
2
|
import * as eventEmitter from './eventEmitter';
|
|
4
3
|
import { factory } from './factory';
|
|
@@ -6,4 +5,4 @@ import * as repository from './repository';
|
|
|
6
5
|
import * as service from './service';
|
|
7
6
|
import * as settings from './settings';
|
|
8
7
|
import * as taskSettings from './taskSettings';
|
|
9
|
-
export {
|
|
8
|
+
export { errorHandler, eventEmitter, factory, repository, service, settings, taskSettings };
|
package/lib/chevre/index.js
CHANGED
|
@@ -33,9 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.taskSettings = exports.settings = exports.service = exports.repository = exports.factory = exports.eventEmitter = exports.errorHandler =
|
|
37
|
-
const credentials = __importStar(require("./credentials"));
|
|
38
|
-
exports.credentials = credentials;
|
|
36
|
+
exports.taskSettings = exports.settings = exports.service = exports.repository = exports.factory = exports.eventEmitter = exports.errorHandler = void 0;
|
|
39
37
|
const errorHandler = __importStar(require("./errorHandler"));
|
|
40
38
|
exports.errorHandler = errorHandler;
|
|
41
39
|
const eventEmitter = __importStar(require("./eventEmitter"));
|
|
@@ -178,6 +178,21 @@ interface ISurfrockSettings {
|
|
|
178
178
|
*/
|
|
179
179
|
credentialsExpireInSeconds?: number;
|
|
180
180
|
}
|
|
181
|
+
export interface ISendGridAlert {
|
|
182
|
+
sender?: {
|
|
183
|
+
name: string;
|
|
184
|
+
email: string;
|
|
185
|
+
};
|
|
186
|
+
toRecipient?: [
|
|
187
|
+
{
|
|
188
|
+
email: string;
|
|
189
|
+
}
|
|
190
|
+
];
|
|
191
|
+
}
|
|
192
|
+
export interface ISendGridSettings {
|
|
193
|
+
apiKey: string;
|
|
194
|
+
alert?: ISendGridAlert;
|
|
195
|
+
}
|
|
181
196
|
export interface IIntegrationSettings {
|
|
182
197
|
abortedTasksWithoutReport: string[];
|
|
183
198
|
numTryConfirmReserveTransaction: number;
|
|
@@ -185,6 +200,11 @@ export interface IIntegrationSettings {
|
|
|
185
200
|
coa: ICOAIntegrationSettings;
|
|
186
201
|
gmo: IGMOIntegrationSettings;
|
|
187
202
|
movieticketReserve: ISurfrockSettings;
|
|
203
|
+
/**
|
|
204
|
+
* SendGrid認証情報
|
|
205
|
+
* 2026-05-29~
|
|
206
|
+
*/
|
|
207
|
+
sendGrid?: ISendGridSettings;
|
|
188
208
|
useExperimentalFeature: boolean;
|
|
189
209
|
}
|
|
190
210
|
export interface ISetting {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Connection } from 'mongoose';
|
|
2
|
-
import { IIntegrationSettings } from '../mongoose/schemas/setting';
|
|
2
|
+
import { IIntegrationSettings, ISendGridSettings } from '../mongoose/schemas/setting';
|
|
3
3
|
interface IDBOptions {
|
|
4
4
|
connection: Connection;
|
|
5
5
|
}
|
|
@@ -21,5 +21,6 @@ export declare class IntegrationSettingRepo {
|
|
|
21
21
|
* 設定名称から設定を参照する
|
|
22
22
|
*/
|
|
23
23
|
getByKey<T extends keyof IIntegrationSettings>(key: T): Promise<IIntegrationSettings[T]>;
|
|
24
|
+
addSendGridSettings(params: ISendGridSettings): Promise<import("mongoose").UpdateWriteOpResult>;
|
|
24
25
|
}
|
|
25
26
|
export {};
|
|
@@ -82,5 +82,13 @@ class IntegrationSettingRepo {
|
|
|
82
82
|
const settings = await this.getAllSettings();
|
|
83
83
|
return settings[key];
|
|
84
84
|
}
|
|
85
|
+
async addSendGridSettings(params) {
|
|
86
|
+
return this.settingModel.updateOne({ 'project.id': { $eq: '*' } }, {
|
|
87
|
+
$set: {
|
|
88
|
+
'integration.sendGrid': params
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
.exec();
|
|
92
|
+
}
|
|
85
93
|
}
|
|
86
94
|
exports.IntegrationSettingRepo = IntegrationSettingRepo;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { SendGridCredentials } from '../../credentials/sendGrid';
|
|
2
1
|
import type { TaskRepo } from '../../repo/task';
|
|
3
|
-
import type { IntegrationSettingRepo
|
|
2
|
+
import type { IntegrationSettingRepo } from '../../repo/setting/integration';
|
|
4
3
|
/**
|
|
5
4
|
* 中止されたタスクリストをEメールで通知する
|
|
6
5
|
* add(2025-03-13~)
|
|
@@ -9,7 +8,6 @@ declare function notifyAbortedTasksByEmail(params: {
|
|
|
9
8
|
dateAbortedGte: Date;
|
|
10
9
|
}): (repos: {
|
|
11
10
|
task: TaskRepo;
|
|
12
|
-
|
|
13
|
-
sendGrid: SendGridCredentials;
|
|
11
|
+
integrationSetting: IntegrationSettingRepo;
|
|
14
12
|
}) => Promise<void>;
|
|
15
13
|
export { notifyAbortedTasksByEmail };
|
|
@@ -14,8 +14,8 @@ const debug = (0, debug_1.default)('chevre-domain:service:notification');
|
|
|
14
14
|
* add(2025-03-13~)
|
|
15
15
|
*/
|
|
16
16
|
function notifyAbortedTasksByEmail(params) {
|
|
17
|
-
return async (repos
|
|
18
|
-
const abortedTasksWithoutReport = await
|
|
17
|
+
return async (repos) => {
|
|
18
|
+
const abortedTasksWithoutReport = await repos.integrationSetting.getByKey('abortedTasksWithoutReport');
|
|
19
19
|
const abortedTasks = await repos.task.projectFields({
|
|
20
20
|
status: { $eq: factory_1.factory.taskStatus.Aborted },
|
|
21
21
|
dateAborted: { $gte: params.dateAbortedGte },
|
|
@@ -30,7 +30,7 @@ function notifyAbortedTasksByEmail(params) {
|
|
|
30
30
|
const notifyResult = await (0, notifyByEmail_1.notifyByEmail)({
|
|
31
31
|
subject: message.subject, content: message.content,
|
|
32
32
|
logLevel: 'error'
|
|
33
|
-
})(
|
|
33
|
+
})(repos);
|
|
34
34
|
debug('notifyResult:', notifyResult);
|
|
35
35
|
}
|
|
36
36
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { IntegrationSettingRepo } from '../../repo/setting/integration';
|
|
2
2
|
declare function notifyByEmail(params: {
|
|
3
3
|
subject: string;
|
|
4
4
|
content: string;
|
|
5
5
|
logLevel: LineNotifyLogLevel;
|
|
6
|
-
}): (
|
|
7
|
-
|
|
6
|
+
}): (repos: {
|
|
7
|
+
integrationSetting: IntegrationSettingRepo;
|
|
8
8
|
}) => Promise<{
|
|
9
9
|
result: import("@chevre/factory/lib/chevre/action/transfer/send/message/email").IResult;
|
|
10
10
|
}>;
|
|
@@ -6,20 +6,21 @@ const http_status_1 = require("http-status");
|
|
|
6
6
|
const util_1 = require("util");
|
|
7
7
|
const factory_1 = require("../../factory");
|
|
8
8
|
function notifyByEmail(params) {
|
|
9
|
-
return async (
|
|
9
|
+
return async (repos) => {
|
|
10
10
|
const { logLevel } = params;
|
|
11
11
|
const shortSubject = params.subject;
|
|
12
12
|
const message = (0, util_1.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}`,
|
|
13
13
|
// `GAE_INSTANCE:${process.env.GAE_INSTANCE}`,
|
|
14
14
|
`GAE_SERVICE:${process.env.GAE_SERVICE}`, params.content);
|
|
15
|
-
const
|
|
15
|
+
const sendGridSettings = await repos.integrationSetting.getByKey('sendGrid');
|
|
16
|
+
const apiKey = sendGridSettings?.apiKey;
|
|
16
17
|
if (typeof apiKey !== 'string') {
|
|
17
18
|
throw new factory_1.factory.errors.Internal('API Key not found');
|
|
18
19
|
}
|
|
19
|
-
const senderName =
|
|
20
|
-
const senderEmail =
|
|
21
|
-
const toRecipientEmail = (Array.isArray(
|
|
22
|
-
?
|
|
20
|
+
const senderName = sendGridSettings?.alert?.sender?.name;
|
|
21
|
+
const senderEmail = sendGridSettings?.alert?.sender?.email;
|
|
22
|
+
const toRecipientEmail = (Array.isArray(sendGridSettings?.alert?.toRecipient))
|
|
23
|
+
? sendGridSettings.alert?.toRecipient.at(0)?.email
|
|
23
24
|
: undefined;
|
|
24
25
|
if (typeof senderName !== 'string') {
|
|
25
26
|
throw new factory_1.factory.errors.Internal('senderName not found');
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { SendGridCredentials } from '../../credentials/sendGrid';
|
|
2
1
|
import { factory } from '../../factory';
|
|
3
2
|
import type { ActionRepo } from '../../repo/action';
|
|
4
3
|
import type { MessageRepo } from '../../repo/message';
|
|
5
4
|
import type { ProjectRepo } from '../../repo/project';
|
|
5
|
+
import type { IntegrationSettingRepo } from '../../repo/setting/integration';
|
|
6
6
|
/**
|
|
7
7
|
* https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html
|
|
8
8
|
*/
|
|
@@ -14,7 +14,6 @@ declare function sendEmailMessage(params: factory.task.sendEmailMessage.IActionA
|
|
|
14
14
|
action: ActionRepo;
|
|
15
15
|
message: MessageRepo;
|
|
16
16
|
project: ProjectRepo;
|
|
17
|
-
|
|
18
|
-
sendGrid: SendGridCredentials;
|
|
17
|
+
integrationSetting: IntegrationSettingRepo;
|
|
19
18
|
}) => Promise<void>;
|
|
20
19
|
export { sendEmailMessage };
|
|
@@ -15,12 +15,13 @@ function createSendEmailMessageActionAttributes(params) {
|
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
function createMailData(params) {
|
|
18
|
-
return async (repos
|
|
18
|
+
return async (repos) => {
|
|
19
19
|
const project = await repos.project.findById({
|
|
20
20
|
id: params.project.id,
|
|
21
21
|
inclusion: ['settings']
|
|
22
22
|
});
|
|
23
|
-
|
|
23
|
+
const sendGridSettings = await repos.integrationSetting.getByKey('sendGrid');
|
|
24
|
+
let apiKey = sendGridSettings?.apiKey;
|
|
24
25
|
// プロジェクト固有のSendGrid設定があれば、そちらを使用
|
|
25
26
|
if (typeof project.settings?.sendgridApiKey === 'string' && project.settings.sendgridApiKey.length > 0) {
|
|
26
27
|
apiKey = project.settings.sendgridApiKey;
|
|
@@ -71,8 +72,8 @@ function createMailData(params) {
|
|
|
71
72
|
* https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html
|
|
72
73
|
*/
|
|
73
74
|
function sendEmailMessage(params) {
|
|
74
|
-
return async (repos
|
|
75
|
-
const { mailData, emailMessage, apiKey } = await createMailData(params)(repos
|
|
75
|
+
return async (repos) => {
|
|
76
|
+
const { mailData, emailMessage, apiKey } = await createMailData(params)(repos);
|
|
76
77
|
// add recipe(2025-03-12~)
|
|
77
78
|
let recipe = (0, factory_2.createSendEmailMessageRecipe)({
|
|
78
79
|
mailData,
|
|
@@ -4,19 +4,21 @@ exports.call = call;
|
|
|
4
4
|
const action_1 = require("../../repo/action");
|
|
5
5
|
const message_1 = require("../../repo/message");
|
|
6
6
|
const project_1 = require("../../repo/project");
|
|
7
|
+
const integration_1 = require("../../repo/setting/integration");
|
|
7
8
|
const notification_1 = require("../notification");
|
|
8
9
|
/**
|
|
9
10
|
* タスク実行関数
|
|
10
11
|
*/
|
|
11
12
|
function call(params) {
|
|
12
|
-
return async ({ connection
|
|
13
|
+
return async ({ connection }) => {
|
|
13
14
|
await (0, notification_1.sendEmailMessage)({
|
|
14
15
|
...params.data.actionAttributes,
|
|
15
16
|
sameAs: { id: params.id } // タスクIDを関連付け(2024-06-25~)
|
|
16
17
|
})({
|
|
17
18
|
action: new action_1.ActionRepo(connection),
|
|
18
19
|
message: new message_1.MessageRepo(connection),
|
|
19
|
-
project: new project_1.ProjectRepo(connection)
|
|
20
|
-
|
|
20
|
+
project: new project_1.ProjectRepo(connection),
|
|
21
|
+
integrationSetting: new integration_1.IntegrationSettingRepo({ connection })
|
|
22
|
+
});
|
|
21
23
|
};
|
|
22
24
|
}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { SendGridCredentials } from '../credentials/sendGrid';
|
|
2
1
|
import type { IExecuteSettings as IMinimumExecuteSettings, INextFunction, IReadyTask, IRunningTask } from '../eventEmitter/task';
|
|
3
2
|
import { factory } from '../factory';
|
|
4
3
|
import type { AggregationSettings } from '../taskSettings';
|
|
5
|
-
interface ICredentialSettings {
|
|
6
|
-
sendGrid: SendGridCredentials;
|
|
7
|
-
}
|
|
8
4
|
interface IExecuteSettings extends IMinimumExecuteSettings {
|
|
9
|
-
credentials: ICredentialSettings;
|
|
10
5
|
aggregationSettings?: AggregationSettings;
|
|
11
6
|
}
|
|
12
7
|
type IOperation<T> = (settings: IExecuteSettings) => Promise<T>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { SendGridCredentials } from './credentials/sendGrid';
|
|
2
1
|
import type { IExecuteSettings as IMinimumExecuteSettings } from './eventEmitter/task';
|
|
3
2
|
import { factory } from './factory';
|
|
4
3
|
import type { IntegrationSettingRepo } from './repo/setting/integration';
|
|
@@ -34,11 +33,7 @@ declare class AggregationSettings {
|
|
|
34
33
|
readonly onTaskStatusChanged: IOnTaskStatusChanged;
|
|
35
34
|
constructor(options: IOptions);
|
|
36
35
|
}
|
|
37
|
-
interface ICredentialSettings {
|
|
38
|
-
sendGrid: SendGridCredentials;
|
|
39
|
-
}
|
|
40
36
|
interface IExecuteSettings extends IMinimumExecuteSettings {
|
|
41
|
-
credentials: ICredentialSettings;
|
|
42
37
|
/**
|
|
43
38
|
* 外部連携設定リポジトリ
|
|
44
39
|
*/
|
package/package.json
CHANGED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
interface IAlert {
|
|
2
|
-
sender?: {
|
|
3
|
-
name: string;
|
|
4
|
-
email: string;
|
|
5
|
-
};
|
|
6
|
-
toRecipient?: [
|
|
7
|
-
{
|
|
8
|
-
email: string;
|
|
9
|
-
}
|
|
10
|
-
];
|
|
11
|
-
}
|
|
12
|
-
interface IOptions {
|
|
13
|
-
apiKey: string;
|
|
14
|
-
alert?: IAlert;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* SendGrid認証情報
|
|
18
|
-
*/
|
|
19
|
-
declare class SendGridCredentials {
|
|
20
|
-
readonly apiKey: string;
|
|
21
|
-
readonly alert?: IAlert;
|
|
22
|
-
constructor(options: IOptions);
|
|
23
|
-
}
|
|
24
|
-
export { SendGridCredentials };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SendGridCredentials = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* SendGrid認証情報
|
|
6
|
-
*/
|
|
7
|
-
class SendGridCredentials {
|
|
8
|
-
apiKey;
|
|
9
|
-
alert;
|
|
10
|
-
constructor(options) {
|
|
11
|
-
const { apiKey, alert } = options;
|
|
12
|
-
this.apiKey = apiKey;
|
|
13
|
-
if (alert !== undefined) {
|
|
14
|
-
this.alert = alert;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.SendGridCredentials = SendGridCredentials;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 外部サービス認証情報
|
|
3
|
-
*/
|
|
4
|
-
import type { SendGridCredentials } from './credentials/sendGrid';
|
|
5
|
-
export type SendGrid = SendGridCredentials;
|
|
6
|
-
export declare namespace SendGrid {
|
|
7
|
-
function createInstance(...params: ConstructorParameters<typeof SendGridCredentials>): Promise<SendGridCredentials>;
|
|
8
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SendGrid = void 0;
|
|
4
|
-
var SendGrid;
|
|
5
|
-
(function (SendGrid) {
|
|
6
|
-
let cred;
|
|
7
|
-
async function createInstance(...params) {
|
|
8
|
-
if (cred === undefined) {
|
|
9
|
-
cred = (await import('./credentials/sendGrid.js')).SendGridCredentials;
|
|
10
|
-
}
|
|
11
|
-
return new cred(...params);
|
|
12
|
-
}
|
|
13
|
-
SendGrid.createInstance = createInstance;
|
|
14
|
-
})(SendGrid || (exports.SendGrid = SendGrid = {}));
|