lemon-core 4.1.15 → 4.2.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/dist/common/test-helper.d.ts +2 -2
- package/dist/common/test-helper.js +24 -26
- package/dist/common/test-helper.js.map +1 -1
- package/dist/controllers/dummy-controller.js +39 -46
- package/dist/controllers/dummy-controller.js.map +1 -1
- package/dist/controllers/general-api-controller.js +95 -100
- package/dist/controllers/general-api-controller.js.map +1 -1
- package/dist/controllers/general-controller.js +81 -82
- package/dist/controllers/general-controller.js.map +1 -1
- package/dist/cores/api/api-service.d.ts +1 -1
- package/dist/cores/api/api-service.js +228 -269
- package/dist/cores/api/api-service.js.map +1 -1
- package/dist/cores/aws/aws-kms-service.d.ts +1 -2
- package/dist/cores/aws/aws-kms-service.js +143 -153
- package/dist/cores/aws/aws-kms-service.js.map +1 -1
- package/dist/cores/aws/aws-s3-service.d.ts +2 -4
- package/dist/cores/aws/aws-s3-service.js +306 -330
- package/dist/cores/aws/aws-s3-service.js.map +1 -1
- package/dist/cores/aws/aws-sns-service.js +147 -153
- package/dist/cores/aws/aws-sns-service.js.map +1 -1
- package/dist/cores/aws/aws-sqs-service.js +149 -170
- package/dist/cores/aws/aws-sqs-service.js.map +1 -1
- package/dist/cores/aws/index.js +10 -20
- package/dist/cores/aws/index.js.map +1 -1
- package/dist/cores/cache/cache-service.d.ts +2 -2
- package/dist/cores/cache/cache-service.js +435 -499
- package/dist/cores/cache/cache-service.js.map +1 -1
- package/dist/cores/config/config-service.d.ts +1 -1
- package/dist/cores/config/config-service.js +56 -63
- package/dist/cores/config/config-service.js.map +1 -1
- package/dist/cores/config/index.js +14 -24
- package/dist/cores/config/index.js.map +1 -1
- package/dist/cores/core-services.d.ts +1 -1
- package/dist/cores/dynamo/dynamo-query-service.js +37 -51
- package/dist/cores/dynamo/dynamo-query-service.js.map +1 -1
- package/dist/cores/dynamo/dynamo-scan-service.d.ts +2 -2
- package/dist/cores/dynamo/dynamo-scan-service.js +29 -40
- package/dist/cores/dynamo/dynamo-scan-service.js.map +1 -1
- package/dist/cores/dynamo/dynamo-service.d.ts +2 -2
- package/dist/cores/dynamo/dynamo-service.js +528 -601
- package/dist/cores/dynamo/dynamo-service.js.map +1 -1
- package/dist/cores/dynamo/tools/expressions.js +17 -7
- package/dist/cores/dynamo/tools/expressions.js.map +1 -1
- package/dist/cores/dynamo/tools/query.js +142 -127
- package/dist/cores/dynamo/tools/query.js.map +1 -1
- package/dist/cores/dynamo/tools/scan.js +111 -97
- package/dist/cores/dynamo/tools/scan.js.map +1 -1
- package/dist/cores/dynamo/tools/serializer.js +17 -7
- package/dist/cores/dynamo/tools/serializer.js.map +1 -1
- package/dist/cores/dynamo/tools/utils.d.ts +0 -2
- package/dist/cores/dynamo/tools/utils.js.map +1 -1
- package/dist/cores/elastic/elastic6-query-service.js +307 -324
- package/dist/cores/elastic/elastic6-query-service.js.map +1 -1
- package/dist/cores/elastic/elastic6-service.d.ts +3 -3
- package/dist/cores/elastic/elastic6-service.js +568 -647
- package/dist/cores/elastic/elastic6-service.js.map +1 -1
- package/dist/cores/elastic/hangul-service.js +52 -54
- package/dist/cores/elastic/hangul-service.js.map +1 -1
- package/dist/cores/lambda/index.js +42 -36
- package/dist/cores/lambda/index.js.map +1 -1
- package/dist/cores/lambda/lambda-alb-handler.d.ts +2 -2
- package/dist/cores/lambda/lambda-alb-handler.js +59 -72
- package/dist/cores/lambda/lambda-alb-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-cognito-handler.js +10 -19
- package/dist/cores/lambda/lambda-cognito-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-cron-handler.d.ts +1 -1
- package/dist/cores/lambda/lambda-cron-handler.js +14 -23
- package/dist/cores/lambda/lambda-cron-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-dynamo-stream-handler.d.ts +2 -2
- package/dist/cores/lambda/lambda-dynamo-stream-handler.js +57 -67
- package/dist/cores/lambda/lambda-dynamo-stream-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-handler.d.ts +22 -22
- package/dist/cores/lambda/lambda-handler.js +93 -106
- package/dist/cores/lambda/lambda-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-notification-handler.d.ts +1 -1
- package/dist/cores/lambda/lambda-notification-handler.js +39 -50
- package/dist/cores/lambda/lambda-notification-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-sns-handler.js +79 -88
- package/dist/cores/lambda/lambda-sns-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-sqs-handler.js +79 -88
- package/dist/cores/lambda/lambda-sqs-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-web-handler.d.ts +6 -6
- package/dist/cores/lambda/lambda-web-handler.js +387 -412
- package/dist/cores/lambda/lambda-web-handler.js.map +1 -1
- package/dist/cores/lambda/lambda-wss-handler.js +23 -32
- package/dist/cores/lambda/lambda-wss-handler.js.map +1 -1
- package/dist/cores/protocol/index.js +10 -20
- package/dist/cores/protocol/index.js.map +1 -1
- package/dist/cores/protocol/protocol-service.d.ts +3 -3
- package/dist/cores/protocol/protocol-service.js +235 -227
- package/dist/cores/protocol/protocol-service.js.map +1 -1
- package/dist/cores/storage/http-storage-service.js +65 -85
- package/dist/cores/storage/http-storage-service.js.map +1 -1
- package/dist/cores/storage/model-manager.js +66 -85
- package/dist/cores/storage/model-manager.js.map +1 -1
- package/dist/cores/storage/proxy-storage-service.d.ts +2 -2
- package/dist/cores/storage/proxy-storage-service.js +562 -599
- package/dist/cores/storage/proxy-storage-service.js.map +1 -1
- package/dist/cores/storage/redis-storage-service.js +163 -177
- package/dist/cores/storage/redis-storage-service.js.map +1 -1
- package/dist/cores/storage/storage-service.js +281 -322
- package/dist/cores/storage/storage-service.js.map +1 -1
- package/dist/engine/builder.d.ts +1 -1
- package/dist/engine/builder.js +59 -63
- package/dist/engine/builder.js.map +1 -1
- package/dist/engine/engine.d.ts +4 -4
- package/dist/engine/engine.js +9 -18
- package/dist/engine/engine.js.map +1 -1
- package/dist/engine/types.d.ts +1 -1
- package/dist/engine/utilities.d.ts +5 -5
- package/dist/engine/utilities.js +301 -293
- package/dist/engine/utilities.js.map +1 -1
- package/dist/environ.js +4 -6
- package/dist/environ.js.map +1 -1
- package/dist/extended/abstract-service.js +595 -645
- package/dist/extended/abstract-service.js.map +1 -1
- package/dist/extended/libs/sig-v4.js.map +1 -1
- package/dist/generated/field-registry.d.ts +10 -0
- package/dist/generated/field-registry.js +17 -0
- package/dist/generated/field-registry.js.map +1 -0
- package/dist/helpers/helpers.d.ts +17 -9
- package/dist/helpers/helpers.js +88 -78
- package/dist/helpers/helpers.js.map +1 -1
- package/dist/index.js +17 -7
- package/dist/index.js.map +1 -1
- package/dist/lib/dynamodb-value.js +2 -3
- package/dist/lib/dynamodb-value.js.map +1 -1
- package/dist/tools/express.js +4 -5
- package/dist/tools/express.js.map +1 -1
- package/dist/tools/tools.d.ts +3 -1
- package/dist/tools/tools.js +14 -21
- package/dist/tools/tools.js.map +1 -1
- package/package.json +19 -18
- package/dist/exec-cli.d.ts +0 -2
- package/dist/exec-cli.js +0 -211
- package/dist/exec-cli.js.map +0 -1
- package/dist/lib/dynamo/expressions.d.ts +0 -14
- package/dist/lib/dynamo/expressions.js +0 -212
- package/dist/lib/dynamo/expressions.js.map +0 -1
- package/dist/lib/dynamo/query.d.ts +0 -43
- package/dist/lib/dynamo/query.js +0 -246
- package/dist/lib/dynamo/query.js.map +0 -1
- package/dist/lib/dynamo/scan.d.ts +0 -33
- package/dist/lib/dynamo/scan.js +0 -172
- package/dist/lib/dynamo/scan.js.map +0 -1
- package/dist/lib/dynamo/serializer.d.ts +0 -12
- package/dist/lib/dynamo/serializer.js +0 -243
- package/dist/lib/dynamo/serializer.js.map +0 -1
- package/dist/lib/dynamo/utils.d.ts +0 -15
- package/dist/lib/dynamo/utils.js +0 -129
- package/dist/lib/dynamo/utils.js.map +0 -1
- package/dist/tools/shared.d.ts +0 -28
- package/dist/tools/shared.js +0 -143
- package/dist/tools/shared.js.map +0 -1
|
@@ -15,22 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
34
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
37
|
};
|
|
@@ -69,6 +70,16 @@ exports.HEADER_PROTOCOL_CONTEXT = engine_1.$U.env('HEADER_PROTOCOL_CONTEXT', 'x-
|
|
|
69
70
|
* - support protocol via `API(WEB)` + `SNS` + `SQS`
|
|
70
71
|
*/
|
|
71
72
|
class MyProtocolService {
|
|
73
|
+
//* shared config.
|
|
74
|
+
static REPORT_ERROR = lambda_handler_1.LambdaHandler.REPORT_ERROR;
|
|
75
|
+
//* transformers
|
|
76
|
+
web = new WEBProtocolTransformer(this);
|
|
77
|
+
sns = new SNSProtocolTransformer(this);
|
|
78
|
+
sqs = new SQSProtocolTransformer(this);
|
|
79
|
+
// config-service to use.
|
|
80
|
+
config;
|
|
81
|
+
// self service name
|
|
82
|
+
selfService;
|
|
72
83
|
/**
|
|
73
84
|
* default constructor.
|
|
74
85
|
*
|
|
@@ -76,18 +87,34 @@ class MyProtocolService {
|
|
|
76
87
|
* @param config config-service to use (for debug)
|
|
77
88
|
*/
|
|
78
89
|
constructor(service, config) {
|
|
79
|
-
//* transformers
|
|
80
|
-
this.web = new WEBProtocolTransformer(this);
|
|
81
|
-
this.sns = new SNSProtocolTransformer(this);
|
|
82
|
-
this.sqs = new SQSProtocolTransformer(this);
|
|
83
|
-
/**
|
|
84
|
-
* say hello() of this service
|
|
85
|
-
*/
|
|
86
|
-
this.hello = () => `protocol-service:${this.selfService || ''}`;
|
|
87
90
|
// _log(NS, `MyProtocolService()..`);
|
|
88
91
|
this.selfService = `${service || ''}`;
|
|
89
92
|
this.config = config ? config : config_1.default.config; // use default config-service.
|
|
90
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* say hello() of this service
|
|
96
|
+
*/
|
|
97
|
+
hello = () => `protocol-service:${this.selfService || ''}`;
|
|
98
|
+
//* determine path part
|
|
99
|
+
static asPath = (type, id, cmd) => {
|
|
100
|
+
const buf = [''];
|
|
101
|
+
const enc = (_) => encodeURIComponent(_);
|
|
102
|
+
const esc = (_) => encodeURI(_);
|
|
103
|
+
//* add type by default
|
|
104
|
+
buf.push(enc(`${type || ''}`));
|
|
105
|
+
if (id !== undefined && id !== null) {
|
|
106
|
+
buf.push(enc(`${id}`));
|
|
107
|
+
if (cmd) {
|
|
108
|
+
buf.push(esc(`${cmd}`));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else if (cmd) {
|
|
112
|
+
buf.push('');
|
|
113
|
+
buf.push(esc(`${cmd}`));
|
|
114
|
+
}
|
|
115
|
+
const path = buf.join('/');
|
|
116
|
+
return path && path != '/' ? path : '';
|
|
117
|
+
};
|
|
91
118
|
/**
|
|
92
119
|
* load transformer
|
|
93
120
|
*/
|
|
@@ -203,16 +230,14 @@ class MyProtocolService {
|
|
|
203
230
|
/**
|
|
204
231
|
* internal safe report-error.
|
|
205
232
|
*/
|
|
206
|
-
doReportError(e, context, event, data) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
throw e instanceof Error ? e : new Error(typeof e == 'string' ? e : engine_1.$U.json(e));
|
|
215
|
-
});
|
|
233
|
+
async doReportError(e, context, event, data) {
|
|
234
|
+
if (!MyProtocolService.REPORT_ERROR)
|
|
235
|
+
throw e;
|
|
236
|
+
(0, engine_1._err)(NS, `! err@report =`, e);
|
|
237
|
+
return (0, engine_1.doReportError)(e, context, event, data)
|
|
238
|
+
.catch(() => { })
|
|
239
|
+
.then(() => {
|
|
240
|
+
throw e instanceof Error ? e : new Error(typeof e == 'string' ? e : engine_1.$U.json(e));
|
|
216
241
|
});
|
|
217
242
|
}
|
|
218
243
|
/**
|
|
@@ -245,7 +270,7 @@ class MyProtocolService {
|
|
|
245
270
|
const qs = uri.query;
|
|
246
271
|
if (qs) {
|
|
247
272
|
const qs2 = engine_1.$U.qs.parse(qs);
|
|
248
|
-
param =
|
|
273
|
+
param = { ...qs2, ...param };
|
|
249
274
|
}
|
|
250
275
|
//* prepare protocol-param.
|
|
251
276
|
const proto = {
|
|
@@ -255,7 +280,7 @@ class MyProtocolService {
|
|
|
255
280
|
stage,
|
|
256
281
|
id: id ? decodeURIComponent(id) : id,
|
|
257
282
|
cmd: cmd ? decodeURI(cmd) : cmd,
|
|
258
|
-
context:
|
|
283
|
+
context: { ...context },
|
|
259
284
|
};
|
|
260
285
|
if (param !== undefined)
|
|
261
286
|
proto.param = param;
|
|
@@ -281,68 +306,66 @@ class MyProtocolService {
|
|
|
281
306
|
* @param config config service (for debug)
|
|
282
307
|
* @param uri (optional) if useing custom uri.
|
|
283
308
|
*/
|
|
284
|
-
execute(param, config, uri) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
return payload.body;
|
|
331
|
-
}
|
|
332
|
-
})();
|
|
333
|
-
//* returns
|
|
334
|
-
if (statusCode == 400 || statusCode == 404)
|
|
335
|
-
return Promise.reject(new Error(engine_1.$U.S(body) || '404 NOT FOUND'));
|
|
336
|
-
else if (statusCode != 200 && statusCode != 201) {
|
|
337
|
-
if (typeof body == 'string' && body.startsWith('404 NOT FOUND'))
|
|
338
|
-
throw new Error(body);
|
|
339
|
-
throw new Error(engine_1.$U.S(body) || `Lambda Error. status:${statusCode}`);
|
|
309
|
+
async execute(param, config, uri) {
|
|
310
|
+
// const _log = console.info;
|
|
311
|
+
config = config || this.config;
|
|
312
|
+
(0, engine_1._log)(NS, `execute(${param.service || ''})..`);
|
|
313
|
+
//* execute via lambda call.
|
|
314
|
+
uri = uri || this.asProtocolURI('web', param, config);
|
|
315
|
+
(0, engine_1._inf)(NS, `> uri =`, uri);
|
|
316
|
+
// const url = new URL(uri);
|
|
317
|
+
const url = url_1.default.parse(uri);
|
|
318
|
+
const payload = this.transformEvent(uri, param);
|
|
319
|
+
//* prepare lambda payload.
|
|
320
|
+
const params = {
|
|
321
|
+
FunctionName: url.hostname,
|
|
322
|
+
Payload: payload ? new TextEncoder().encode(engine_1.$U.json(payload)) : undefined,
|
|
323
|
+
ClientContext: undefined,
|
|
324
|
+
// InvocationType: 'Event',
|
|
325
|
+
};
|
|
326
|
+
// _log(NS, `> params =`, $U.json(params));
|
|
327
|
+
//* call lambda.
|
|
328
|
+
const region = 'ap-northeast-2'; //TODO - optimize of aws region....
|
|
329
|
+
const lambda = new client_lambda_1.LambdaClient((0, tools_1.awsConfig)(engine_1.default, region));
|
|
330
|
+
const response = await lambda
|
|
331
|
+
.send(new client_lambda_1.InvokeCommand(params))
|
|
332
|
+
.catch((e) => {
|
|
333
|
+
(0, engine_1._err)(NS, `! execute[${param.service || ''}].err =`, typeof e, e);
|
|
334
|
+
// return this.doReportError(e, param.context, null, { protocol: uri, param });
|
|
335
|
+
throw e;
|
|
336
|
+
})
|
|
337
|
+
.then((data) => {
|
|
338
|
+
(0, engine_1._log)(NS, `! execute[${param.service || ''}].res =`, engine_1.$U.S(data, 320, 64, ' .... '));
|
|
339
|
+
const payload = data && data?.Payload ? JSON.parse(Buffer.from(data.Payload).toString()) : {};
|
|
340
|
+
const statusCode = engine_1.$U.N(payload.statusCode || (data && data.StatusCode), 200);
|
|
341
|
+
(0, engine_1._log)(NS, `> Lambda[${params.FunctionName}].StatusCode :=`, statusCode);
|
|
342
|
+
[200, 201].includes(statusCode) || (0, engine_1._inf)(NS, `> WARN! status[${statusCode}] data =`, engine_1.$U.S(data)); // print whole data if not 200.
|
|
343
|
+
//* safe parse payload.body.
|
|
344
|
+
const body = (() => {
|
|
345
|
+
try {
|
|
346
|
+
if (payload.text && typeof payload.text == 'string')
|
|
347
|
+
return payload.text;
|
|
348
|
+
return payload.body && typeof payload.body == 'string'
|
|
349
|
+
? JSON.parse(payload.body)
|
|
350
|
+
: payload.body;
|
|
351
|
+
}
|
|
352
|
+
catch (e) {
|
|
353
|
+
(0, engine_1._log)(NS, `> WARN! payload.body =`, engine_1.$U.S(payload.body));
|
|
354
|
+
return payload.body;
|
|
340
355
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
356
|
+
})();
|
|
357
|
+
//* returns
|
|
358
|
+
if (statusCode == 400 || statusCode == 404)
|
|
359
|
+
return Promise.reject(new Error(engine_1.$U.S(body) || '404 NOT FOUND'));
|
|
360
|
+
else if (statusCode != 200 && statusCode != 201) {
|
|
361
|
+
if (typeof body == 'string' && body.startsWith('404 NOT FOUND'))
|
|
362
|
+
throw new Error(body);
|
|
363
|
+
throw new Error(engine_1.$U.S(body) || `Lambda Error. status:${statusCode}`);
|
|
364
|
+
}
|
|
365
|
+
return body;
|
|
345
366
|
});
|
|
367
|
+
const res = response;
|
|
368
|
+
return res;
|
|
346
369
|
}
|
|
347
370
|
/**
|
|
348
371
|
* Asynchronized call to target function via `SNS`
|
|
@@ -351,34 +374,32 @@ class MyProtocolService {
|
|
|
351
374
|
* @param callback the return target
|
|
352
375
|
* @param config config service (for debug)
|
|
353
376
|
*/
|
|
354
|
-
notify(param, callback, config) {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
return data.MessageId;
|
|
379
|
-
});
|
|
380
|
-
return res;
|
|
377
|
+
async notify(param, callback, config) {
|
|
378
|
+
// const _log = console.info;
|
|
379
|
+
config = config || this.config;
|
|
380
|
+
const service = `${param.service || config.getService() || ''}`;
|
|
381
|
+
(0, engine_1._log)(NS, `notify(${service})..`);
|
|
382
|
+
const uri = this.asProtocolURI('sns', param, config);
|
|
383
|
+
(0, engine_1._inf)(NS, `> uri[${service}] =`, uri);
|
|
384
|
+
const cbUrl = callback ? this.asCallbackURI(param.context, callback) : null;
|
|
385
|
+
const params = this.sns.transformToEvent(uri, param, cbUrl);
|
|
386
|
+
const arn = params.TopicArn; // "arn:aws:sns:ap-northeast-2:796730245826:lemon-metrics-sns-dev"
|
|
387
|
+
// _inf(NS, `> arn[${service}] =`, arn);
|
|
388
|
+
(0, engine_1._inf)(NS, `> payload[${arn}] =`, engine_1.$U.json(params));
|
|
389
|
+
//* call sns
|
|
390
|
+
const region = arn.split(':')[3] || 'ap-northeast-2';
|
|
391
|
+
const sns = new client_sns_1.SNSClient((0, tools_1.awsConfig)(engine_1.default, region));
|
|
392
|
+
const res = await sns
|
|
393
|
+
.send(new client_sns_1.PublishCommand(params))
|
|
394
|
+
.catch((e) => {
|
|
395
|
+
(0, engine_1._err)(NS, `! notify[${param.service || ''}].err =`, typeof e, e);
|
|
396
|
+
return this.doReportError(e, param.context, null, { protocol: uri, param });
|
|
397
|
+
})
|
|
398
|
+
.then((data) => {
|
|
399
|
+
(0, engine_1._log)(NS, `> res[${service}] =`, engine_1.$U.json(data));
|
|
400
|
+
return data.MessageId;
|
|
381
401
|
});
|
|
402
|
+
return res;
|
|
382
403
|
}
|
|
383
404
|
/**
|
|
384
405
|
* Asynchronized call to target function via `SQS`
|
|
@@ -388,40 +409,38 @@ class MyProtocolService {
|
|
|
388
409
|
* @param delaySeconds the delayed seconds
|
|
389
410
|
* @param config config service (for debug)
|
|
390
411
|
*/
|
|
391
|
-
enqueue(param, callback, delaySeconds, config) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
return data.MessageId;
|
|
422
|
-
});
|
|
423
|
-
return res;
|
|
412
|
+
async enqueue(param, callback, delaySeconds, config) {
|
|
413
|
+
// const _log = console.info;
|
|
414
|
+
config = config || this.config;
|
|
415
|
+
const service = `${param.service || config.getService() || ''}`;
|
|
416
|
+
const stage = `${param.stage || config.getStage() || ''}`;
|
|
417
|
+
(0, engine_1._log)(NS, `enqueue(${service}-${stage})..`);
|
|
418
|
+
const uri = this.asProtocolURI('sqs', param, config);
|
|
419
|
+
(0, engine_1._inf)(NS, `> uri[${service}] =`, uri);
|
|
420
|
+
delaySeconds = engine_1.$U.N(delaySeconds, 10);
|
|
421
|
+
if (delaySeconds < 0)
|
|
422
|
+
throw new Error(`@delaySeconds (number) should be >= 0. but ${delaySeconds}`);
|
|
423
|
+
const cbUrl = callback ? this.asCallbackURI(param.context, callback) : null;
|
|
424
|
+
(0, engine_1._inf)(NS, `> callback[${service}] =`, cbUrl);
|
|
425
|
+
const params = this.sqs.transformToEvent(uri, param, cbUrl);
|
|
426
|
+
params.DelaySeconds = delaySeconds;
|
|
427
|
+
const endpoint = params.QueueUrl; // https://sqs.${arr[3]}.amazonaws.com
|
|
428
|
+
// _inf(NS, `> endpoint[${service}] =`, endpoint);
|
|
429
|
+
(0, engine_1._inf)(NS, `> payload[${endpoint}] =`, engine_1.$U.json(params));
|
|
430
|
+
//* call sns
|
|
431
|
+
const region = endpoint.split('.')[1] || 'ap-northeast-2';
|
|
432
|
+
const sqs = new client_sqs_1.SQSClient((0, tools_1.awsConfig)(engine_1.default, region));
|
|
433
|
+
const res = await sqs
|
|
434
|
+
.send(new client_sqs_1.SendMessageCommand(params))
|
|
435
|
+
.catch((e) => {
|
|
436
|
+
(0, engine_1._err)(NS, `! enqueue[${param.service || ''}].err =`, typeof e, e);
|
|
437
|
+
return this.doReportError(e, param.context, null, { protocol: uri, param });
|
|
438
|
+
})
|
|
439
|
+
.then((data) => {
|
|
440
|
+
(0, engine_1._log)(NS, `> res[${endpoint}] =`, engine_1.$U.json(data));
|
|
441
|
+
return data.MessageId;
|
|
424
442
|
});
|
|
443
|
+
return res;
|
|
425
444
|
}
|
|
426
445
|
/**
|
|
427
446
|
* broadcast body message via shared `SNS` Subscritions. (see `NotificationHandler`)
|
|
@@ -432,70 +451,46 @@ class MyProtocolService {
|
|
|
432
451
|
* @param body the message body to broadcast.
|
|
433
452
|
* @returns the message-id if applicable.
|
|
434
453
|
*/
|
|
435
|
-
broadcast(context, endpoint, body) {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
return data.MessageId;
|
|
471
|
-
});
|
|
472
|
-
return res;
|
|
454
|
+
async broadcast(context, endpoint, body) {
|
|
455
|
+
const service = this.myProtocolURI(context);
|
|
456
|
+
(0, engine_1._log)(NS, `broadcast(${service})..`);
|
|
457
|
+
(0, engine_1._log)(NS, `> body[${service}] =`, engine_1.$U.json(body));
|
|
458
|
+
const arn = await aws_1.default.sns.endpoint(endpoint);
|
|
459
|
+
(0, engine_1._inf)(NS, `> arn[${endpoint}] =`, arn);
|
|
460
|
+
const accountId = `${(context && context.accountId) || ''}`;
|
|
461
|
+
const requestId = `${(context && context.requestId) || ''}`;
|
|
462
|
+
const params = {
|
|
463
|
+
TopicArn: arn,
|
|
464
|
+
Subject: `x-protocol-service/broadcast`, //NOTE! - can be no 'Subject' if subscribed as HTTP SNS.
|
|
465
|
+
Message: JSON.stringify({ default: engine_1.$U.json(body) }), //NOTE! - only body data is required.
|
|
466
|
+
// Message: JSON.stringify({ default: param }),
|
|
467
|
+
MessageAttributes: {
|
|
468
|
+
// accountId: { DataType: 'String', StringValue: accountId },
|
|
469
|
+
// requestId: { DataType: 'String', StringValue: requestId },
|
|
470
|
+
},
|
|
471
|
+
MessageStructure: 'json',
|
|
472
|
+
};
|
|
473
|
+
if (accountId)
|
|
474
|
+
params.MessageAttributes['accountId'] = { DataType: 'String', StringValue: accountId };
|
|
475
|
+
if (requestId)
|
|
476
|
+
params.MessageAttributes['requestId'] = { DataType: 'String', StringValue: requestId };
|
|
477
|
+
//* call sns
|
|
478
|
+
const region = arn.split(':')[3] || 'ap-northeast-2';
|
|
479
|
+
const sns = new client_sns_1.SNSClient((0, tools_1.awsConfig)(engine_1.default, region));
|
|
480
|
+
const res = await sns
|
|
481
|
+
.send(new client_sns_1.PublishCommand(params))
|
|
482
|
+
.catch((e) => {
|
|
483
|
+
(0, engine_1._err)(NS, `! broadcast[${service || ''}].err =`, typeof e, e);
|
|
484
|
+
return this.doReportError(e, context, null, { endpoint, body });
|
|
485
|
+
})
|
|
486
|
+
.then((data) => {
|
|
487
|
+
(0, engine_1._log)(NS, `> res[${service}] =`, engine_1.$U.json(data));
|
|
488
|
+
return data.MessageId;
|
|
473
489
|
});
|
|
490
|
+
return res;
|
|
474
491
|
}
|
|
475
492
|
}
|
|
476
493
|
exports.MyProtocolService = MyProtocolService;
|
|
477
|
-
//* shared config.
|
|
478
|
-
MyProtocolService.REPORT_ERROR = lambda_handler_1.LambdaHandler.REPORT_ERROR;
|
|
479
|
-
//* determine path part
|
|
480
|
-
MyProtocolService.asPath = (type, id, cmd) => {
|
|
481
|
-
const buf = [''];
|
|
482
|
-
const enc = (_) => encodeURIComponent(_);
|
|
483
|
-
const esc = (_) => encodeURI(_);
|
|
484
|
-
//* add type by default
|
|
485
|
-
buf.push(enc(`${type || ''}`));
|
|
486
|
-
if (id !== undefined && id !== null) {
|
|
487
|
-
buf.push(enc(`${id}`));
|
|
488
|
-
if (cmd) {
|
|
489
|
-
buf.push(esc(`${cmd}`));
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
else if (cmd) {
|
|
493
|
-
buf.push('');
|
|
494
|
-
buf.push(esc(`${cmd}`));
|
|
495
|
-
}
|
|
496
|
-
const path = buf.join('/');
|
|
497
|
-
return path && path != '/' ? path : '';
|
|
498
|
-
};
|
|
499
494
|
/**
|
|
500
495
|
* class: `WEBProtocolTransformer`
|
|
501
496
|
* - transformer for `WEB` Handler
|
|
@@ -524,14 +519,26 @@ class WEBProtocolTransformer {
|
|
|
524
519
|
//* build http parameter
|
|
525
520
|
const base = {};
|
|
526
521
|
const $ctx = {};
|
|
527
|
-
const event =
|
|
522
|
+
const event = {
|
|
523
|
+
...base,
|
|
524
|
+
headers: {
|
|
528
525
|
[exports.HEADER_PROTOCOL_CONTEXT]: engine_1.$U.json(context),
|
|
529
|
-
},
|
|
530
|
-
|
|
531
|
-
|
|
526
|
+
},
|
|
527
|
+
path,
|
|
528
|
+
httpMethod,
|
|
529
|
+
pathParameters: { type, id, cmd },
|
|
530
|
+
queryStringParameters: param.param,
|
|
531
|
+
requestContext: {
|
|
532
|
+
...$ctx,
|
|
533
|
+
path,
|
|
534
|
+
httpMethod,
|
|
535
|
+
identity: null, // must be 'null' due to not compartible with AWS auth.
|
|
532
536
|
stage,
|
|
533
537
|
accountId,
|
|
534
|
-
requestId
|
|
538
|
+
requestId,
|
|
539
|
+
},
|
|
540
|
+
body: param.body ? engine_1.$U.json(param.body) : null,
|
|
541
|
+
};
|
|
535
542
|
const res = event;
|
|
536
543
|
return res;
|
|
537
544
|
}
|
|
@@ -540,8 +547,7 @@ class WEBProtocolTransformer {
|
|
|
540
547
|
* @param event the lambda compartible event data.
|
|
541
548
|
*/
|
|
542
549
|
transformToParam(event, context) {
|
|
543
|
-
|
|
544
|
-
const errScope = `web.transformToParam(${(_a = event === null || event === void 0 ? void 0 : event.path) !== null && _a !== void 0 ? _a : ''})`;
|
|
550
|
+
const errScope = `web.transformToParam(${event?.path ?? ''})`;
|
|
545
551
|
if (!event)
|
|
546
552
|
throw new Error(`@event (API Event) is required - ${errScope}`); // avoid null exception.
|
|
547
553
|
const headers = event.headers;
|
|
@@ -606,10 +612,10 @@ class WEBProtocolTransformer {
|
|
|
606
612
|
const type = $path.type || `${resource || path || ''}`.split('/')[1] || ''; // 1st path param will be type of resource.
|
|
607
613
|
const mode = httpMethod == 'GET' && !$path.id && !$path.cmd ? 'LIST' : `${httpMethod}`.toUpperCase();
|
|
608
614
|
//* validate values.
|
|
609
|
-
if (
|
|
610
|
-
throw new Error(`400 INVALID CONTEXT - accountId:${
|
|
611
|
-
if (
|
|
612
|
-
throw new Error(`400 INVALID CONTEXT - requestId:${
|
|
615
|
+
if (context?.accountId && requestContext.accountId != context.accountId)
|
|
616
|
+
throw new Error(`400 INVALID CONTEXT - accountId:${context.accountId ?? ''} @${errScope}`);
|
|
617
|
+
if (context?.requestId && requestContext.requestId != context.requestId)
|
|
618
|
+
throw new Error(`400 INVALID CONTEXT - requestId:${context.requestId ?? ''} @${errScope}`);
|
|
613
619
|
//* pack as protocol-param.
|
|
614
620
|
const res = { service, stage, type, mode, id: $path.id, cmd: $path.cmd, param, body, context };
|
|
615
621
|
return res;
|
|
@@ -621,6 +627,7 @@ exports.WEBProtocolTransformer = WEBProtocolTransformer;
|
|
|
621
627
|
* - transformer for `SNS` Handler
|
|
622
628
|
*/
|
|
623
629
|
class SNSProtocolTransformer {
|
|
630
|
+
service;
|
|
624
631
|
constructor(service) {
|
|
625
632
|
this.service = service;
|
|
626
633
|
}
|
|
@@ -696,6 +703,7 @@ exports.SNSProtocolTransformer = SNSProtocolTransformer;
|
|
|
696
703
|
* - transformer for `SQS` Handler
|
|
697
704
|
*/
|
|
698
705
|
class SQSProtocolTransformer {
|
|
706
|
+
service;
|
|
699
707
|
constructor(service) {
|
|
700
708
|
this.service = service;
|
|
701
709
|
}
|