@varius.io/framework 9.0.0 → 9.0.2
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.
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { UserRef } from "./user";
|
|
2
2
|
interface PointsUser {
|
|
3
3
|
id: string;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
points: {
|
|
7
|
-
[channel: string]: number;
|
|
8
|
-
};
|
|
4
|
+
channel: string;
|
|
5
|
+
points: number;
|
|
9
6
|
}
|
|
10
7
|
export declare function updateUserPoints(businessId: string, recipientUserRef: UserRef, campaignId: string, points: number, channel?: string, objectDefinitionIds?: string[]): Promise<{
|
|
11
8
|
[channel: string]: number;
|
|
@@ -16,13 +13,10 @@ declare type RaffleWinner = {
|
|
|
16
13
|
winningUser: PointsUser;
|
|
17
14
|
};
|
|
18
15
|
export declare function selectRaffleWinner(businessId: string, campaignId: string, channel: string): Promise<RaffleWinner>;
|
|
19
|
-
export declare function setUserPoints(businessId: string, recipientUserRef: UserRef, campaignId: string, points: number, channel
|
|
16
|
+
export declare function setUserPoints(businessId: string, recipientUserRef: UserRef, campaignId: string, points: number, channel: string, updateVatoms?: boolean): Promise<{
|
|
20
17
|
[channel: string]: number;
|
|
21
18
|
}>;
|
|
22
|
-
export declare function
|
|
23
|
-
[channel: string]: number;
|
|
24
|
-
}>;
|
|
25
|
-
export declare function getUserPoints(businessId: string, recipientUserRef: any, campaignUri: string): Promise<{
|
|
19
|
+
export declare function getUserPoints(recipientUserRef: any, campaignId: string): Promise<{
|
|
26
20
|
[channel: string]: number;
|
|
27
21
|
}>;
|
|
28
22
|
export declare function getCampaignPoints(businessId: string, campaignId: string): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"points.d.ts","sourceRoot":"","sources":["../../src/services/points.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"points.d.ts","sourceRoot":"","sources":["../../src/services/points.ts"],"names":[],"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AM,CAAA;CAAE,CAAC,CAGtH;AAGD,wBAAsB,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAezG;AAGD,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAYzG"}
|
package/build/services/points.js
CHANGED
|
@@ -9,38 +9,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getUser = exports.listUsers = exports.getCampaignPoints = exports.getUserPoints = exports.
|
|
13
|
-
const DynamoDB = require("aws-sdk/clients/dynamodb");
|
|
14
|
-
const logger_1 = require("../utils/logger");
|
|
15
|
-
const uri = require("../utils/uri");
|
|
12
|
+
exports.getUser = exports.listUsers = exports.getCampaignPoints = exports.getUserPoints = exports.setUserPoints = exports.selectRaffleWinner = exports.updateUserPoints = void 0;
|
|
16
13
|
const NodeCache = require("node-cache");
|
|
17
14
|
const __1 = require("..");
|
|
18
|
-
const
|
|
19
|
-
const api_1 = require("./api");
|
|
15
|
+
const assert = require("assert");
|
|
20
16
|
const user_1 = require("./user");
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
let dynamodb;
|
|
35
|
-
let iotdata;
|
|
36
|
-
function initialize() {
|
|
37
|
-
if (!dynamodb) {
|
|
38
|
-
dynamodb = new DynamoDB.DocumentClient();
|
|
39
|
-
iotdata = new aws_sdk_1.IotData({
|
|
40
|
-
endpoint: process.env.IOT_ENDPOINT,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
17
|
+
const axios_1 = require("axios");
|
|
18
|
+
const { POINTS_API_BASE, POINTS_API_KEY } = process.env;
|
|
19
|
+
const ax = axios_1.default.create({
|
|
20
|
+
baseURL: POINTS_API_BASE,
|
|
21
|
+
headers: {
|
|
22
|
+
"x-api-key": process.env.POINTS_API_KEY,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
ax.interceptors.request.use((config) => {
|
|
26
|
+
assert.notStrictEqual(POINTS_API_BASE, undefined);
|
|
27
|
+
assert.notStrictEqual(POINTS_API_KEY, undefined);
|
|
28
|
+
return config;
|
|
29
|
+
});
|
|
44
30
|
// The purpose of this is to convert the dynamo result set to a standard one
|
|
45
31
|
function createPaginatedResultSet(data) {
|
|
46
32
|
const cursor = data.LastEvaluatedKey;
|
|
@@ -49,271 +35,70 @@ function createPaginatedResultSet(data) {
|
|
|
49
35
|
cursor,
|
|
50
36
|
};
|
|
51
37
|
}
|
|
52
|
-
function createPointsList(respAttrs) {
|
|
53
|
-
const points = {
|
|
54
|
-
total: respAttrs.points,
|
|
55
|
-
};
|
|
56
|
-
for (const columnName of Object.keys(respAttrs)) {
|
|
57
|
-
if (columnName.startsWith("channel_")) {
|
|
58
|
-
points[columnName.substring(columnName.indexOf("_") + 1)] = respAttrs[columnName];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return points;
|
|
62
|
-
// const pointsResponse: PointsList = {
|
|
63
|
-
// total: respAttrs.points,
|
|
64
|
-
// items: []
|
|
65
|
-
// };
|
|
66
|
-
// for (const columnName of Object.keys(respAttrs)) {
|
|
67
|
-
// if (columnName.startsWith("channel_")) {
|
|
68
|
-
// const channelPoints: Points = {
|
|
69
|
-
// channel: columnName.substring(columnName.indexOf("_") + 1),
|
|
70
|
-
// points: respAttrs[columnName],
|
|
71
|
-
// }
|
|
72
|
-
// pointsResponse.items.push(channelPoints);
|
|
73
|
-
// }
|
|
74
|
-
// }
|
|
75
|
-
// Sort items in array
|
|
76
|
-
// pointsResponse.items.sort((a, b) => b.points - a.points)
|
|
77
|
-
// return pointsResponse;
|
|
78
|
-
}
|
|
79
|
-
function updateCampaignPointsDB(campaignId, points, channel) {
|
|
80
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
logger_1.default.debug("updateCampaignPointsDB", campaignId, points);
|
|
82
|
-
let updateExpression = `SET #AP = if_not_exists(#AP, :zero) + :p`;
|
|
83
|
-
const ExpressionAttributeNames = {
|
|
84
|
-
"#AP": "points",
|
|
85
|
-
};
|
|
86
|
-
const ExpressionAttributeValues = {
|
|
87
|
-
":p": points,
|
|
88
|
-
":zero": 0,
|
|
89
|
-
};
|
|
90
|
-
if (channel) {
|
|
91
|
-
updateExpression = `${updateExpression}, #CH = if_not_exists(#CH, :zero) + :ch`;
|
|
92
|
-
ExpressionAttributeNames["#CH"] = `channel_${channel}`;
|
|
93
|
-
ExpressionAttributeValues[":ch"] = points;
|
|
94
|
-
}
|
|
95
|
-
logger_1.default.debug("updateExpression", updateExpression, ExpressionAttributeNames, ExpressionAttributeValues);
|
|
96
|
-
const updateParams = {
|
|
97
|
-
ExpressionAttributeNames,
|
|
98
|
-
ExpressionAttributeValues,
|
|
99
|
-
Key: {
|
|
100
|
-
id: campaignId,
|
|
101
|
-
},
|
|
102
|
-
ReturnValues: "ALL_NEW",
|
|
103
|
-
TableName: campaignPointsTable,
|
|
104
|
-
UpdateExpression: updateExpression,
|
|
105
|
-
};
|
|
106
|
-
const resp = yield dynamodb.update(updateParams).promise();
|
|
107
|
-
logger_1.default.debug("Response from update:", JSON.stringify(resp));
|
|
108
|
-
const respAttrs = resp.Attributes;
|
|
109
|
-
return createPointsList(respAttrs);
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
function getCampaignPointsDB(campaignUri) {
|
|
113
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
const getParams = {
|
|
115
|
-
Key: {
|
|
116
|
-
id: campaignUri,
|
|
117
|
-
},
|
|
118
|
-
TableName: campaignPointsTable,
|
|
119
|
-
};
|
|
120
|
-
const resp = yield dynamodb.get(getParams).promise();
|
|
121
|
-
logger_1.default.debug("Response from get:", JSON.stringify(resp));
|
|
122
|
-
const respItem = resp.Item;
|
|
123
|
-
if (!respItem) {
|
|
124
|
-
return ({
|
|
125
|
-
total: 0
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
return createPointsList(respItem);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
function sendLeaderboardEvent(campaignUri, points, userRef) {
|
|
132
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
-
const topic = `campaign-rules/${campaignUri}/leaderboard/on-update-points-v2`;
|
|
134
|
-
const msg = {
|
|
135
|
-
userRef,
|
|
136
|
-
campaignId: uri.parseEntityUriString(campaignUri).identifier,
|
|
137
|
-
points,
|
|
138
|
-
stage: "post",
|
|
139
|
-
};
|
|
140
|
-
const params = {
|
|
141
|
-
topic: topic,
|
|
142
|
-
payload: JSON.stringify(msg),
|
|
143
|
-
qos: 0,
|
|
144
|
-
};
|
|
145
|
-
yield iotdata.publish(params).promise();
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
38
|
function updateUserPoints(businessId, recipientUserRef, campaignId, points, channel, objectDefinitionIds) {
|
|
149
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
method: "patch",
|
|
155
|
-
body: {
|
|
156
|
-
points,
|
|
157
|
-
channel,
|
|
158
|
-
objectDefinitionIds
|
|
159
|
-
}
|
|
40
|
+
const { data, status } = yield ax.patch(`/u/${recipientUserRef.id}/campaign/${campaignId}/points`, {
|
|
41
|
+
points,
|
|
42
|
+
channel,
|
|
43
|
+
objectDefinitionIds
|
|
160
44
|
});
|
|
161
|
-
if (
|
|
162
|
-
throw new Error(`Could not update user points for user ${recipientUserRef} and campaignId ${campaignId} res: ${JSON.stringify(
|
|
45
|
+
if (status !== 200) {
|
|
46
|
+
throw new Error(`Could not update user points for user ${recipientUserRef} and campaignId ${campaignId} res: ${JSON.stringify(data)}`);
|
|
163
47
|
}
|
|
164
|
-
return
|
|
48
|
+
return data;
|
|
165
49
|
});
|
|
166
50
|
}
|
|
167
51
|
exports.updateUserPoints = updateUserPoints;
|
|
168
52
|
function selectRaffleWinner(businessId, campaignId, channel) {
|
|
169
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
apiKey,
|
|
174
|
-
method: "get",
|
|
175
|
-
});
|
|
176
|
-
if (res.status !== 200) {
|
|
177
|
-
throw new Error(`Could not select raffle winner campaignId ${campaignId} and channel ${channel} res: ${JSON.stringify(res.body)}`);
|
|
54
|
+
const { data, status } = yield ax.get(`/b/${businessId}/campaign/${campaignId}/channel/${channel}/raffle`);
|
|
55
|
+
if (status !== 200) {
|
|
56
|
+
throw new Error(`Could not select raffle winner campaignId ${campaignId} and channel ${channel} res: ${JSON.stringify(data)}`);
|
|
178
57
|
}
|
|
179
|
-
return
|
|
58
|
+
return data;
|
|
180
59
|
});
|
|
181
60
|
}
|
|
182
61
|
exports.selectRaffleWinner = selectRaffleWinner;
|
|
183
62
|
function setUserPoints(businessId, recipientUserRef, campaignId, points, channel, updateVatoms = false) {
|
|
184
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
method: "post",
|
|
190
|
-
body: {
|
|
191
|
-
points,
|
|
192
|
-
channel,
|
|
193
|
-
updateVatoms,
|
|
194
|
-
}
|
|
64
|
+
const { data, status } = yield ax.post(`/u/${recipientUserRef.id}/campaign/${campaignId}/points`, {
|
|
65
|
+
points,
|
|
66
|
+
channel,
|
|
67
|
+
updateVatoms,
|
|
195
68
|
});
|
|
196
|
-
if (
|
|
197
|
-
throw new Error(`Could not set user points for user ${recipientUserRef} and campaignId ${campaignId} res: ${JSON.stringify(
|
|
69
|
+
if (status !== 200) {
|
|
70
|
+
throw new Error(`Could not set user points for user ${recipientUserRef} and campaignId ${campaignId} res: ${JSON.stringify(data)}`);
|
|
198
71
|
}
|
|
199
|
-
return
|
|
72
|
+
return data;
|
|
200
73
|
});
|
|
201
74
|
}
|
|
202
75
|
exports.setUserPoints = setUserPoints;
|
|
203
|
-
function
|
|
76
|
+
function getUserPoints(recipientUserRef, campaignId) {
|
|
204
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
logger_1.default.debug("campaignPoints", campaignPoints);
|
|
208
|
-
// TODO - need to think about points triggers at the campaign level
|
|
209
|
-
// const providerList = await providers.getProviders(businessId, "points");
|
|
210
|
-
// await sendRelevantPointsEvents(businessId, campaignUri, providerList, pointsSummary, points);
|
|
211
|
-
// This is to send an update event to the leaderboard
|
|
212
|
-
yield sendLeaderboardEvent(campaignUri, campaignPoints);
|
|
213
|
-
return campaignPoints;
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
exports.updateCampaignPoints = updateCampaignPoints;
|
|
217
|
-
function getUserPoints(businessId, recipientUserRef, campaignUri) {
|
|
218
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
219
|
-
initialize();
|
|
220
|
-
const pointsUser = yield getUserDB(campaignUri, recipientUserRef.id);
|
|
221
|
-
logger_1.default.debug("pointsUser", pointsUser);
|
|
222
|
-
return pointsUser.points;
|
|
78
|
+
const { data, status } = yield ax.get(`/u/${recipientUserRef.id}/campaign/${campaignId}/points`);
|
|
79
|
+
return data;
|
|
223
80
|
});
|
|
224
81
|
}
|
|
225
82
|
exports.getUserPoints = getUserPoints;
|
|
226
83
|
function getCampaignPoints(businessId, campaignId) {
|
|
227
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const campaignPoints = yield getCampaignPointsDB(campaignUri);
|
|
231
|
-
logger_1.default.debug("campaignPoints", campaignPoints);
|
|
232
|
-
return campaignPoints;
|
|
85
|
+
const { data, status } = yield ax.get(`/b/${businessId}/campaign/${campaignId}/points`);
|
|
86
|
+
return data;
|
|
233
87
|
});
|
|
234
88
|
}
|
|
235
89
|
exports.getCampaignPoints = getCampaignPoints;
|
|
236
|
-
function listUsersDB(campaignId, limit = 20, cursor) {
|
|
237
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
238
|
-
const params = {
|
|
239
|
-
ExpressionAttributeValues: {
|
|
240
|
-
":cId": campaignId,
|
|
241
|
-
},
|
|
242
|
-
KeyConditionExpression: "campaign_id = :cId",
|
|
243
|
-
TableName: userPointsTable,
|
|
244
|
-
IndexName: usersIndex,
|
|
245
|
-
ScanIndexForward: false,
|
|
246
|
-
Limit: limit,
|
|
247
|
-
};
|
|
248
|
-
if (cursor) {
|
|
249
|
-
params.ExclusiveStartKey = cursor;
|
|
250
|
-
}
|
|
251
|
-
__1.utils.logger.debug(params);
|
|
252
|
-
const resp = yield dynamodb.query(params).promise();
|
|
253
|
-
return createPaginatedResultSet(resp);
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
function getUserDB(campaignId, userId) {
|
|
257
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
258
|
-
const params = {
|
|
259
|
-
ExpressionAttributeValues: {
|
|
260
|
-
":uId": userId,
|
|
261
|
-
":cId": campaignId,
|
|
262
|
-
},
|
|
263
|
-
KeyConditionExpression: "id = :uId AND campaign_id = :cId",
|
|
264
|
-
TableName: userPointsTable,
|
|
265
|
-
};
|
|
266
|
-
const res = yield dynamodb.query(params).promise();
|
|
267
|
-
const user = res.Items[0];
|
|
268
|
-
if (!user) {
|
|
269
|
-
return ({
|
|
270
|
-
id: userId,
|
|
271
|
-
// urn: uri.entityUri(uri.EntityType.User, userId),
|
|
272
|
-
name: "",
|
|
273
|
-
points: {
|
|
274
|
-
total: 0,
|
|
275
|
-
},
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
const points = {
|
|
280
|
-
total: user.points,
|
|
281
|
-
};
|
|
282
|
-
for (const columnName of Object.keys(user)) {
|
|
283
|
-
if (columnName.startsWith("channel_")) {
|
|
284
|
-
points[columnName.substring(columnName.indexOf("_") + 1)] = user[columnName];
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
return ({
|
|
288
|
-
id: user.id,
|
|
289
|
-
// urn: uri.entityUri(uri.EntityType.User, user.id),
|
|
290
|
-
name: `${user.first_name} ${user.last_name}`,
|
|
291
|
-
points,
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
90
|
const userListCache = new NodeCache({ stdTTL: 30, checkperiod: 10 });
|
|
297
91
|
function listUsers(campaignId, limit, cursor) {
|
|
298
92
|
return __awaiter(this, void 0, void 0, function* () {
|
|
299
|
-
initialize();
|
|
300
93
|
const cacheKey = `${campaignId}${cursor || ""}${limit}`;
|
|
301
94
|
__1.utils.logger.debug("cacheKey", cacheKey);
|
|
302
95
|
let users = userListCache.get(cacheKey);
|
|
303
96
|
__1.utils.logger.debug("users in cache", users);
|
|
304
97
|
if (!users) {
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
// urn: uri.entityUri(uri.EntityType.User, row.id),
|
|
310
|
-
name: `${row.first_name} ${row.last_name}`,
|
|
311
|
-
points: {
|
|
312
|
-
total: row.points
|
|
313
|
-
},
|
|
314
|
-
}));
|
|
315
|
-
__1.utils.logger.debug("adding users to cache", cacheKey, users);
|
|
316
|
-
userListCache.set(cacheKey, users);
|
|
98
|
+
const { data, status } = yield ax.get(`/b/todo/campaign/${campaignId}/users`);
|
|
99
|
+
__1.utils.logger.debug("adding users to cache", cacheKey, data);
|
|
100
|
+
userListCache.set(cacheKey, data);
|
|
101
|
+
return data;
|
|
317
102
|
}
|
|
318
103
|
return users;
|
|
319
104
|
});
|
|
@@ -323,17 +108,16 @@ const userCache = new NodeCache({ stdTTL: 30, checkperiod: 10 });
|
|
|
323
108
|
function getUser(userId, businessId, campaignId) {
|
|
324
109
|
var _a, _b, _c, _d;
|
|
325
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
326
|
-
initialize();
|
|
327
111
|
const cacheKey = `${campaignId}${userId}`;
|
|
328
112
|
let user = userCache.get(cacheKey);
|
|
329
113
|
if (user)
|
|
330
114
|
return user;
|
|
331
|
-
|
|
115
|
+
const { data, status } = yield ax.get(`/b/todo/campaign/${campaignId}/users/${userId}`);
|
|
332
116
|
const p = yield (0, user_1.getPublicProfile)(userId);
|
|
333
117
|
if (((_d = (_c = (_b = (_a = p === null || p === void 0 ? void 0 : p.name) === null || _a === void 0 ? void 0 : _a.trim) === null || _b === void 0 ? void 0 : _b.call(_a)) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) > 0)
|
|
334
|
-
|
|
335
|
-
userCache.set(cacheKey,
|
|
336
|
-
return
|
|
118
|
+
data.name = p.name;
|
|
119
|
+
userCache.set(cacheKey, data);
|
|
120
|
+
return data;
|
|
337
121
|
});
|
|
338
122
|
}
|
|
339
123
|
exports.getUser = getUser;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"points.js","sourceRoot":"","sources":["../../src/services/points.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"points.js","sourceRoot":"","sources":["../../src/services/points.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,wCAAyC;AACzC,0BAA2B;AAC3B,iCAAiC;AACjC,iCAAmD;AACnD,iCAA0B;AAE1B,MAAM,EACL,eAAe,EACf,cAAc,EACd,GAAG,OAAO,CAAC,GAAG,CAAA;AAEf,MAAM,EAAE,GAAG,eAAK,CAAC,MAAM,CAAC;IACvB,OAAO,EAAE,eAAe;IACxB,OAAO,EAAE;QACR,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,cAAe;KACxC;CACD,CAAC,CAAC;AAEH,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