@chevre/domain 20.4.0 → 20.6.0
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/example/src/chevre/createManyEventsIfNotExist.ts +0 -4
- package/example/src/chevre/sendEmailMessage.ts +81 -0
- package/lib/chevre/emailMessageBuilder.js +72 -30
- package/lib/chevre/repo/comment.js +1 -1
- package/lib/chevre/repo/mongoose/model/comments.js +1 -0
- package/lib/chevre/service/notification.js +18 -7
- package/lib/chevre/service/payment/movieTicket.js +4 -9
- package/package.json +3 -3
|
@@ -175,10 +175,6 @@ async function main() {
|
|
|
175
175
|
typeOf: 'CategoryCodeSet',
|
|
176
176
|
identifier: chevre.factory.categoryCode.CategorySetIdentifier.ServiceType
|
|
177
177
|
},
|
|
178
|
-
project: {
|
|
179
|
-
typeOf: chevre.factory.organizationType.Project,
|
|
180
|
-
id: 'cinerino'
|
|
181
|
-
},
|
|
182
178
|
typeOf: 'CategoryCode'
|
|
183
179
|
}
|
|
184
180
|
},
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
const SENDER_EMAIL = String(process.env.SENDER_EMAIL);
|
|
9
|
+
const RECIPIENT_EMAIL = String(process.env.RECIPIENT_EMAIL);
|
|
10
|
+
|
|
11
|
+
async function main() {
|
|
12
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
13
|
+
|
|
14
|
+
const actionRepo = new chevre.repository.Action(mongoose.connection);
|
|
15
|
+
const projectRepo = new chevre.repository.Project(mongoose.connection);
|
|
16
|
+
|
|
17
|
+
await chevre.service.notification.sendEmailMessage({
|
|
18
|
+
project: {
|
|
19
|
+
typeOf: chevre.factory.organizationType.Project,
|
|
20
|
+
id: project.id
|
|
21
|
+
},
|
|
22
|
+
typeOf: chevre.factory.actionType.SendAction,
|
|
23
|
+
object: {
|
|
24
|
+
typeOf: chevre.factory.creativeWorkType.EmailMessage,
|
|
25
|
+
identifier: 'SendOrder-CIN1-3970498-5700993',
|
|
26
|
+
name: 'SendOrder-CIN1-3970498-5700993',
|
|
27
|
+
sender: {
|
|
28
|
+
typeOf: 'Corporation',
|
|
29
|
+
name: 'sample sender ',
|
|
30
|
+
email: SENDER_EMAIL
|
|
31
|
+
},
|
|
32
|
+
toRecipient: [
|
|
33
|
+
{
|
|
34
|
+
typeOf: 'WebApplication',
|
|
35
|
+
name: 'sample recipient 2',
|
|
36
|
+
email: RECIPIENT_EMAIL
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
about: {
|
|
40
|
+
typeOf: 'Thing',
|
|
41
|
+
identifier: chevre.factory.creativeWork.message.email.AboutIdentifier.OnOrderSent,
|
|
42
|
+
name: 'sample about'
|
|
43
|
+
},
|
|
44
|
+
text: 'sample text'
|
|
45
|
+
},
|
|
46
|
+
agent: {
|
|
47
|
+
typeOf: chevre.factory.organizationType.Project,
|
|
48
|
+
id: project.id
|
|
49
|
+
},
|
|
50
|
+
recipient: {
|
|
51
|
+
typeOf: chevre.factory.creativeWorkType.WebApplication,
|
|
52
|
+
id: 'xxxx',
|
|
53
|
+
name: 'sample recipient'
|
|
54
|
+
},
|
|
55
|
+
purpose: {
|
|
56
|
+
typeOf: chevre.factory.order.OrderType.Order,
|
|
57
|
+
seller: {
|
|
58
|
+
id: '59d20831e53ebc2b4e774466',
|
|
59
|
+
name: 'seller name',
|
|
60
|
+
typeOf: chevre.factory.organizationType.Corporation
|
|
61
|
+
},
|
|
62
|
+
customer: {
|
|
63
|
+
typeOf: chevre.factory.creativeWorkType.WebApplication,
|
|
64
|
+
id: 'xxxx',
|
|
65
|
+
name: '****'
|
|
66
|
+
},
|
|
67
|
+
orderNumber: 'CIN1-3970498-5700993',
|
|
68
|
+
price: 0,
|
|
69
|
+
priceCurrency: chevre.factory.priceCurrency.JPY,
|
|
70
|
+
orderDate: moment('2023-03-06T01:02:58.866Z')
|
|
71
|
+
.toDate()
|
|
72
|
+
}
|
|
73
|
+
})({
|
|
74
|
+
action: actionRepo,
|
|
75
|
+
project: projectRepo
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
main()
|
|
80
|
+
.then(console.log)
|
|
81
|
+
.catch(console.error);
|
|
@@ -124,7 +124,7 @@ function createEmailMessageSender(params) {
|
|
|
124
124
|
* 注文配送メッセージを作成する
|
|
125
125
|
*/
|
|
126
126
|
function createSendOrderMessage(params) {
|
|
127
|
-
var _a
|
|
127
|
+
var _a;
|
|
128
128
|
return __awaiter(this, void 0, void 0, function* () {
|
|
129
129
|
const emailMessageText = yield createEmailMessageText({
|
|
130
130
|
order: params.order,
|
|
@@ -142,16 +142,30 @@ function createSendOrderMessage(params) {
|
|
|
142
142
|
if (defaultToRecipientEmail === undefined) {
|
|
143
143
|
throw new factory.errors.Argument('order', 'order.customer.email undefined');
|
|
144
144
|
}
|
|
145
|
+
const defaultRecipientName = `${params.order.customer.familyName} ${params.order.customer.givenName}`;
|
|
145
146
|
const sender = createEmailMessageSender(params);
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
147
|
+
const toRecipientCustomization = (_a = params.email) === null || _a === void 0 ? void 0 : _a.toRecipient;
|
|
148
|
+
const toRecipient = (Array.isArray(toRecipientCustomization))
|
|
149
|
+
? toRecipientCustomization.map((customizedRecipient) => {
|
|
150
|
+
return {
|
|
151
|
+
typeOf: params.order.customer.typeOf,
|
|
152
|
+
name: (typeof customizedRecipient.name === 'string')
|
|
153
|
+
? customizedRecipient.name
|
|
154
|
+
: defaultRecipientName,
|
|
155
|
+
email: (typeof customizedRecipient.email === 'string')
|
|
156
|
+
? customizedRecipient.email
|
|
157
|
+
: defaultToRecipientEmail
|
|
158
|
+
};
|
|
159
|
+
})
|
|
160
|
+
: [{
|
|
161
|
+
typeOf: params.order.customer.typeOf,
|
|
162
|
+
name: (typeof (toRecipientCustomization === null || toRecipientCustomization === void 0 ? void 0 : toRecipientCustomization.name) === 'string')
|
|
163
|
+
? toRecipientCustomization.name
|
|
164
|
+
: defaultRecipientName,
|
|
165
|
+
email: (typeof (toRecipientCustomization === null || toRecipientCustomization === void 0 ? void 0 : toRecipientCustomization.email) === 'string')
|
|
166
|
+
? toRecipientCustomization.email
|
|
167
|
+
: defaultToRecipientEmail
|
|
168
|
+
}];
|
|
155
169
|
return {
|
|
156
170
|
typeOf: factory.creativeWorkType.EmailMessage,
|
|
157
171
|
identifier: `SendOrder-${params.order.orderNumber}`,
|
|
@@ -168,7 +182,7 @@ exports.createSendOrderMessage = createSendOrderMessage;
|
|
|
168
182
|
* 注文返品メッセージを作成する
|
|
169
183
|
*/
|
|
170
184
|
function createReturnOrderMessage(params) {
|
|
171
|
-
var _a
|
|
185
|
+
var _a;
|
|
172
186
|
return __awaiter(this, void 0, void 0, function* () {
|
|
173
187
|
const emailMessageText = yield createEmailMessageText({
|
|
174
188
|
order: params.order,
|
|
@@ -186,16 +200,30 @@ function createReturnOrderMessage(params) {
|
|
|
186
200
|
if (defaultToRecipientEmail === undefined) {
|
|
187
201
|
throw new factory.errors.Argument('order', 'order.customer.email undefined');
|
|
188
202
|
}
|
|
203
|
+
const defaultRecipientName = `${params.order.customer.familyName} ${params.order.customer.givenName}`;
|
|
189
204
|
const sender = createEmailMessageSender(params);
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
205
|
+
const toRecipientCustomization = (_a = params.email) === null || _a === void 0 ? void 0 : _a.toRecipient;
|
|
206
|
+
const toRecipient = (Array.isArray(toRecipientCustomization))
|
|
207
|
+
? toRecipientCustomization.map((customizedRecipient) => {
|
|
208
|
+
return {
|
|
209
|
+
typeOf: params.order.customer.typeOf,
|
|
210
|
+
name: (typeof customizedRecipient.name === 'string')
|
|
211
|
+
? customizedRecipient.name
|
|
212
|
+
: defaultRecipientName,
|
|
213
|
+
email: (typeof customizedRecipient.email === 'string')
|
|
214
|
+
? customizedRecipient.email
|
|
215
|
+
: defaultToRecipientEmail
|
|
216
|
+
};
|
|
217
|
+
})
|
|
218
|
+
: [{
|
|
219
|
+
typeOf: params.order.customer.typeOf,
|
|
220
|
+
name: (typeof (toRecipientCustomization === null || toRecipientCustomization === void 0 ? void 0 : toRecipientCustomization.name) === 'string')
|
|
221
|
+
? toRecipientCustomization.name
|
|
222
|
+
: defaultRecipientName,
|
|
223
|
+
email: (typeof (toRecipientCustomization === null || toRecipientCustomization === void 0 ? void 0 : toRecipientCustomization.email) === 'string')
|
|
224
|
+
? toRecipientCustomization.email
|
|
225
|
+
: defaultToRecipientEmail
|
|
226
|
+
}];
|
|
199
227
|
return {
|
|
200
228
|
typeOf: factory.creativeWorkType.EmailMessage,
|
|
201
229
|
identifier: `ReturnOrder-${params.order.orderNumber}`,
|
|
@@ -212,7 +240,7 @@ exports.createReturnOrderMessage = createReturnOrderMessage;
|
|
|
212
240
|
* 返金メッセージを作成する
|
|
213
241
|
*/
|
|
214
242
|
function createRefundMessage(params) {
|
|
215
|
-
var _a
|
|
243
|
+
var _a;
|
|
216
244
|
return __awaiter(this, void 0, void 0, function* () {
|
|
217
245
|
const emailMessageText = yield createEmailMessageText({
|
|
218
246
|
order: params.order,
|
|
@@ -228,16 +256,30 @@ function createRefundMessage(params) {
|
|
|
228
256
|
if (defaultToRecipientEmail === undefined) {
|
|
229
257
|
throw new factory.errors.Argument('order', 'order.customer.email undefined');
|
|
230
258
|
}
|
|
259
|
+
const defaultRecipientName = `${params.order.customer.familyName} ${params.order.customer.givenName}`;
|
|
231
260
|
const sender = createEmailMessageSender(params);
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
261
|
+
const toRecipientCustomization = (_a = params.email) === null || _a === void 0 ? void 0 : _a.toRecipient;
|
|
262
|
+
const toRecipient = (Array.isArray(toRecipientCustomization))
|
|
263
|
+
? toRecipientCustomization.map((customizedRecipient) => {
|
|
264
|
+
return {
|
|
265
|
+
typeOf: params.order.customer.typeOf,
|
|
266
|
+
name: (typeof customizedRecipient.name === 'string')
|
|
267
|
+
? customizedRecipient.name
|
|
268
|
+
: defaultRecipientName,
|
|
269
|
+
email: (typeof customizedRecipient.email === 'string')
|
|
270
|
+
? customizedRecipient.email
|
|
271
|
+
: defaultToRecipientEmail
|
|
272
|
+
};
|
|
273
|
+
})
|
|
274
|
+
: [{
|
|
275
|
+
typeOf: params.order.customer.typeOf,
|
|
276
|
+
name: (typeof (toRecipientCustomization === null || toRecipientCustomization === void 0 ? void 0 : toRecipientCustomization.name) === 'string')
|
|
277
|
+
? toRecipientCustomization.name
|
|
278
|
+
: defaultRecipientName,
|
|
279
|
+
email: (typeof (toRecipientCustomization === null || toRecipientCustomization === void 0 ? void 0 : toRecipientCustomization.email) === 'string')
|
|
280
|
+
? toRecipientCustomization.email
|
|
281
|
+
: defaultToRecipientEmail
|
|
282
|
+
}];
|
|
241
283
|
return {
|
|
242
284
|
typeOf: factory.creativeWorkType.EmailMessage,
|
|
243
285
|
identifier: `RefundOrder-${params.order.orderNumber}`,
|
|
@@ -78,7 +78,7 @@ class MongoRepository {
|
|
|
78
78
|
}
|
|
79
79
|
create(params) {
|
|
80
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
const creatingDoc = Object.assign({ about: params.about, author: params.author, dateCreated: new Date(), project: params.project, text: params.text, typeOf: factory.creativeWorkType.Comment }, (Array.isArray(params.additionalProperty)) ? { additionalProperty: params.additionalProperty } : undefined);
|
|
81
|
+
const creatingDoc = Object.assign(Object.assign({ about: params.about, author: params.author, dateCreated: new Date(), project: params.project, text: params.text, typeOf: factory.creativeWorkType.Comment }, (Array.isArray(params.additionalProperty)) ? { additionalProperty: params.additionalProperty } : undefined), (Array.isArray(params.mentions)) ? { mentions: params.mentions } : undefined);
|
|
82
82
|
const doc = yield this.commentModel.create(creatingDoc);
|
|
83
83
|
return doc.toObject();
|
|
84
84
|
});
|
|
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.triggerWebhook = exports.report2developers = exports.sendEmailMessage = void 0;
|
|
13
|
-
// tslint:disable-next-line:no-require-imports
|
|
14
13
|
const sgMail = require("@sendgrid/mail");
|
|
15
14
|
const createDebug = require("debug");
|
|
16
15
|
const http_status_1 = require("http-status");
|
|
@@ -54,10 +53,19 @@ function sendEmailMessage(params) {
|
|
|
54
53
|
subject = emailMessage.about.name;
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
const emailDatas = (Array.isArray(emailMessage.toRecipient))
|
|
57
|
+
? emailMessage.toRecipient.map((toRecipient) => {
|
|
58
|
+
return {
|
|
59
|
+
name: toRecipient.name,
|
|
60
|
+
email: toRecipient.email
|
|
61
|
+
};
|
|
62
|
+
})
|
|
63
|
+
// Arrayでない時期への互換性維持対応
|
|
64
|
+
: [{
|
|
65
|
+
name: emailMessage.toRecipient.name,
|
|
66
|
+
email: emailMessage.toRecipient.email
|
|
67
|
+
}];
|
|
68
|
+
const msg = Object.assign(Object.assign(Object.assign({ to: emailDatas, from: {
|
|
61
69
|
name: emailMessage.sender.name,
|
|
62
70
|
email: emailMessage.sender.email
|
|
63
71
|
} }, (typeof subject === 'string') ? { subject } : undefined), (String(emailMessage.text).length > 0) ? { text: String(emailMessage.text) } : undefined), {
|
|
@@ -71,12 +79,15 @@ function sendEmailMessage(params) {
|
|
|
71
79
|
actionId: action.id,
|
|
72
80
|
projectId: project.id
|
|
73
81
|
} });
|
|
74
|
-
|
|
82
|
+
// mlutiple recipients対応(2023-03-06~)
|
|
83
|
+
// const response = await sgMail.send(msg);
|
|
84
|
+
const response = yield sgMail.sendMultiple(msg);
|
|
75
85
|
// check the response.
|
|
76
86
|
if (response[0].statusCode !== http_status_1.ACCEPTED) {
|
|
77
87
|
throw new Error(`sendgrid request not accepted. response is ${util.inspect(response)}`);
|
|
78
88
|
}
|
|
79
|
-
|
|
89
|
+
const { statusCode, statusMessage } = response[0];
|
|
90
|
+
result = { statusCode, statusMessage };
|
|
80
91
|
}
|
|
81
92
|
catch (error) {
|
|
82
93
|
// actionにエラー結果を追加
|
|
@@ -28,7 +28,7 @@ const onRefund_1 = require("./any/onRefund");
|
|
|
28
28
|
*/
|
|
29
29
|
function checkMovieTicket(params) {
|
|
30
30
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
var _a, _b, _c, _d, _e;
|
|
31
|
+
var _a, _b, _c, _d, _e, _f;
|
|
32
32
|
// 決済方法区分
|
|
33
33
|
const paymentMethodType = (_a = params.object[0]) === null || _a === void 0 ? void 0 : _a.paymentMethod.typeOf;
|
|
34
34
|
const paymentServiceId = (_b = params.object[0]) === null || _b === void 0 ? void 0 : _b.id;
|
|
@@ -36,12 +36,7 @@ function checkMovieTicket(params) {
|
|
|
36
36
|
if (!Array.isArray(movieTickets)) {
|
|
37
37
|
throw new factory.errors.Argument('object.movieTickets must be an array');
|
|
38
38
|
}
|
|
39
|
-
const actionAttributes = {
|
|
40
|
-
project: params.project,
|
|
41
|
-
typeOf: factory.actionType.CheckAction,
|
|
42
|
-
agent: params.agent,
|
|
43
|
-
object: params.object
|
|
44
|
-
};
|
|
39
|
+
const actionAttributes = Object.assign({ project: params.project, typeOf: factory.actionType.CheckAction, agent: params.agent, object: params.object }, (typeof ((_d = params.purpose) === null || _d === void 0 ? void 0 : _d.typeOf) === 'string') ? { purpose: params.purpose } : undefined);
|
|
45
40
|
const action = yield repos.action.start(actionAttributes);
|
|
46
41
|
let checkResult;
|
|
47
42
|
try {
|
|
@@ -62,8 +57,8 @@ function checkMovieTicket(params) {
|
|
|
62
57
|
id: eventIds[0]
|
|
63
58
|
});
|
|
64
59
|
// ショップ情報取得
|
|
65
|
-
const seller = yield repos.seller.findById({ id: (
|
|
66
|
-
const paymentAccepted = (
|
|
60
|
+
const seller = yield repos.seller.findById({ id: (_e = params.object[0]) === null || _e === void 0 ? void 0 : _e.seller.id });
|
|
61
|
+
const paymentAccepted = (_f = seller.paymentAccepted) === null || _f === void 0 ? void 0 : _f.some((a) => a.paymentMethodType === paymentMethodType);
|
|
67
62
|
if (paymentAccepted !== true) {
|
|
68
63
|
throw new factory.errors.Argument('transactionId', 'payment not accepted');
|
|
69
64
|
}
|
package/package.json
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
}
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@chevre/factory": "4.
|
|
13
|
-
"@cinerino/sdk": "3.
|
|
12
|
+
"@chevre/factory": "4.298.0",
|
|
13
|
+
"@cinerino/sdk": "3.146.0",
|
|
14
14
|
"@motionpicture/coa-service": "9.2.0",
|
|
15
15
|
"@motionpicture/gmo-service": "5.2.0",
|
|
16
16
|
"@sendgrid/mail": "6.4.0",
|
|
@@ -120,5 +120,5 @@
|
|
|
120
120
|
"postversion": "git push origin --tags",
|
|
121
121
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
122
122
|
},
|
|
123
|
-
"version": "20.
|
|
123
|
+
"version": "20.6.0"
|
|
124
124
|
}
|