@cinerino/sdk 3.70.0 → 3.71.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/package.json +2 -2
- package/example/src/updateEventStatus.ts +0 -170
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cinerino/sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.71.0",
|
|
4
4
|
"description": "Cinerino SDK",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"browser": {
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"watchify": "^3.11.1"
|
|
98
98
|
},
|
|
99
99
|
"dependencies": {
|
|
100
|
-
"@cinerino/api-abstract-client": "3.
|
|
100
|
+
"@cinerino/api-abstract-client": "3.71.0",
|
|
101
101
|
"debug": "^3.2.6",
|
|
102
102
|
"http-status": "^1.4.2",
|
|
103
103
|
"idtoken-verifier": "^2.0.3",
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console no-implicit-dependencies
|
|
2
|
-
/**
|
|
3
|
-
* イベントステータス更新
|
|
4
|
-
*/
|
|
5
|
-
import * as moment from 'moment';
|
|
6
|
-
import * as pug from 'pug';
|
|
7
|
-
import * as client from '../../lib/index';
|
|
8
|
-
import * as auth from './auth/authAsAdmin';
|
|
9
|
-
|
|
10
|
-
const project = { id: 'cinerino' };
|
|
11
|
-
|
|
12
|
-
async function main() {
|
|
13
|
-
const authClient = await auth.login();
|
|
14
|
-
await authClient.refreshAccessToken();
|
|
15
|
-
const loginTicket = authClient.verifyIdToken({});
|
|
16
|
-
console.log('username is', loginTicket.getUsername());
|
|
17
|
-
|
|
18
|
-
const eventService = new client.service.Event({
|
|
19
|
-
endpoint: <string>process.env.API_ENDPOINT,
|
|
20
|
-
auth: authClient,
|
|
21
|
-
project
|
|
22
|
-
});
|
|
23
|
-
const emailMessageService = new client.service.EmailMessage({
|
|
24
|
-
endpoint: <string>process.env.API_ENDPOINT,
|
|
25
|
-
auth: authClient,
|
|
26
|
-
project
|
|
27
|
-
});
|
|
28
|
-
const orderService = new client.service.Order({
|
|
29
|
-
endpoint: <string>process.env.API_ENDPOINT,
|
|
30
|
-
auth: authClient,
|
|
31
|
-
project
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const searchEmailMessagesResult = await emailMessageService.search({
|
|
35
|
-
limit: 1,
|
|
36
|
-
page: 1,
|
|
37
|
-
about: { identifier: { $eq: client.factory.creativeWork.message.email.AboutIdentifier.OnEventStatusChanged } }
|
|
38
|
-
});
|
|
39
|
-
const emailMessageOnCanceled = searchEmailMessagesResult.data.shift();
|
|
40
|
-
if (emailMessageOnCanceled === undefined) {
|
|
41
|
-
throw new Error('Eメールメッセージテンプレートが見つかりません');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const eventId = 'akrdohgg7';
|
|
45
|
-
const eventStatus = client.factory.eventStatusType.EventCancelled;
|
|
46
|
-
// const eventStatus = client.factory.eventStatusType.EventScheduled;
|
|
47
|
-
// Eメールカスタムテキスト
|
|
48
|
-
const notice = 'カスタムテキスト';
|
|
49
|
-
|
|
50
|
-
let sendEmailMessageParams: client.factory.action.transfer.send.message.email.IAttributes[] = [];
|
|
51
|
-
|
|
52
|
-
if (eventStatus === client.factory.eventStatusType.EventCancelled) {
|
|
53
|
-
// イベントに対する注文検索
|
|
54
|
-
const searchOrdersResult = await orderService.search({
|
|
55
|
-
// project: { id: { $eq: req.project?.id } },
|
|
56
|
-
acceptedOffers: {
|
|
57
|
-
itemOffered: {
|
|
58
|
-
// アイテムが予約
|
|
59
|
-
typeOf: { $in: [client.factory.reservationType.EventReservation] },
|
|
60
|
-
// 予約対象イベント
|
|
61
|
-
reservationFor: { ids: [eventId] }
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
// 返品済は除く
|
|
65
|
-
orderStatuses: [client.factory.orderStatus.OrderDelivered, client.factory.orderStatus.OrderProcessing]
|
|
66
|
-
});
|
|
67
|
-
const orders = searchOrdersResult.data;
|
|
68
|
-
sendEmailMessageParams = await Promise.all(orders.map(async (order) => {
|
|
69
|
-
return createEmail(order, notice, emailMessageOnCanceled);
|
|
70
|
-
}));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
await eventService.updateEventStatus({
|
|
74
|
-
id: eventId,
|
|
75
|
-
eventStatus: eventStatus,
|
|
76
|
-
onUpdated: {
|
|
77
|
-
sendEmailMessage: sendEmailMessageParams
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
async function createEmail(
|
|
84
|
-
order: client.factory.order.IOrder,
|
|
85
|
-
notice: string,
|
|
86
|
-
emailMessageOnCanceled: client.factory.creativeWork.message.email.ICreativeWork
|
|
87
|
-
): Promise<client.factory.action.transfer.send.message.email.IAttributes> {
|
|
88
|
-
const content = await new Promise<string>((resolve, reject) => {
|
|
89
|
-
pug.render(
|
|
90
|
-
emailMessageOnCanceled.text,
|
|
91
|
-
{
|
|
92
|
-
// moment使う場合
|
|
93
|
-
moment,
|
|
94
|
-
// order変数使える
|
|
95
|
-
order,
|
|
96
|
-
// カスタムテキスト変数使える
|
|
97
|
-
notice
|
|
98
|
-
},
|
|
99
|
-
(err, message) => {
|
|
100
|
-
if (err instanceof Error) {
|
|
101
|
-
reject(new client.factory.errors.Argument('emailTemplate', err.message));
|
|
102
|
-
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
resolve(message);
|
|
107
|
-
}
|
|
108
|
-
);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
// メール作成
|
|
112
|
-
const emailMessage: client.factory.creativeWork.message.email.ICreativeWork = {
|
|
113
|
-
typeOf: client.factory.creativeWorkType.EmailMessage,
|
|
114
|
-
identifier: `updateEventStatus-${order.orderNumber}`,
|
|
115
|
-
name: `updateEventStatus-${order.orderNumber}`,
|
|
116
|
-
sender: {
|
|
117
|
-
typeOf: order.seller.typeOf,
|
|
118
|
-
name: emailMessageOnCanceled.sender.name,
|
|
119
|
-
email: emailMessageOnCanceled.sender.email
|
|
120
|
-
},
|
|
121
|
-
toRecipient: {
|
|
122
|
-
typeOf: order.customer.typeOf,
|
|
123
|
-
name: String(order.customer.name),
|
|
124
|
-
email: String(order.customer.email)
|
|
125
|
-
},
|
|
126
|
-
about: {
|
|
127
|
-
typeOf: 'Thing',
|
|
128
|
-
identifier: emailMessageOnCanceled.about.identifier,
|
|
129
|
-
name: emailMessageOnCanceled.about.name
|
|
130
|
-
},
|
|
131
|
-
text: content
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const purpose = {
|
|
135
|
-
project: { typeOf: order.project.typeOf, id: order.project.id },
|
|
136
|
-
typeOf: order.typeOf,
|
|
137
|
-
seller: order.seller,
|
|
138
|
-
customer: order.customer,
|
|
139
|
-
confirmationNumber: order.confirmationNumber,
|
|
140
|
-
orderNumber: order.orderNumber,
|
|
141
|
-
price: order.price,
|
|
142
|
-
priceCurrency: order.priceCurrency,
|
|
143
|
-
orderDate: moment(order.orderDate)
|
|
144
|
-
.toDate()
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
const recipient: any = {
|
|
148
|
-
id: order.customer.id,
|
|
149
|
-
name: emailMessage.toRecipient.name,
|
|
150
|
-
typeOf: order.customer.typeOf
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
return {
|
|
154
|
-
typeOf: client.factory.actionType.SendAction,
|
|
155
|
-
agent: {
|
|
156
|
-
typeOf: client.factory.personType.Person,
|
|
157
|
-
id: ''
|
|
158
|
-
},
|
|
159
|
-
object: emailMessage,
|
|
160
|
-
project: { typeOf: order.project.typeOf, id: order.project.id },
|
|
161
|
-
purpose: purpose,
|
|
162
|
-
recipient
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
main()
|
|
167
|
-
.then(() => {
|
|
168
|
-
console.log('success!');
|
|
169
|
-
})
|
|
170
|
-
.catch(console.error);
|