@middy/service-discovery 3.0.1 → 3.0.4
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/LICENSE +1 -1
- package/README.md +4 -3
- package/index.cjs +65 -1
- package/index.js +54 -1
- package/package.json +4 -4
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2017-2022 Luciano Mammino, will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
|
|
3
|
+
Copyright (c) 2017-2022 [Luciano Mammino](https://github.com/lmammino), [will Farrell](https://github.com/willfarrell) and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
<a href="https://packagephobia.com/result?p=@middy/service-discovery">
|
|
10
10
|
<img src="https://packagephobia.com/badge?p=@middy/service-discovery" alt="npm install size" style="max-width:100%;">
|
|
11
11
|
</a>
|
|
12
|
-
<a href="https://github.com/middyjs/middy/actions">
|
|
13
|
-
<img src="https://github.com/middyjs/middy/workflows/
|
|
12
|
+
<a href="https://github.com/middyjs/middy/actions/workflows/tests.yml">
|
|
13
|
+
<img src="https://github.com/middyjs/middy/actions/workflows/tests.yml/badge.svg?branch=main&event=push" alt="GitHub Actions CI status badge" style="max-width:100%;">
|
|
14
14
|
</a>
|
|
15
15
|
<br/>
|
|
16
16
|
<a href="https://standardjs.com/">
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
<img src="https://img.shields.io/badge/StackOverflow-[middy]-yellow" alt="Ask questions on StackOverflow" style="max-width:100%;">
|
|
34
34
|
</a>
|
|
35
35
|
</p>
|
|
36
|
+
<p>You can read the documentation at: <a href="https://middy.js.org/docs/middlewares/service-discovery">https://middy.js.org/docs/middlewares/service-discovery</a></p>
|
|
36
37
|
</div>
|
|
37
38
|
|
|
38
39
|
Fetches Service Discovery instances to be used when connecting to other AWS services.
|
|
@@ -101,7 +102,7 @@ Everyone is very welcome to contribute to this repository. Feel free to [raise i
|
|
|
101
102
|
|
|
102
103
|
## License
|
|
103
104
|
|
|
104
|
-
Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
|
|
105
|
+
Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 [Luciano Mammino](https://github.com/lmammino), [will Farrell](https://github.com/willfarrell), and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
|
|
105
106
|
|
|
106
107
|
<a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
|
|
107
108
|
<img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
|
package/index.cjs
CHANGED
|
@@ -1,3 +1,67 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
module.exports = void 0;
|
|
6
|
+
var _util = require("@middy/util");
|
|
7
|
+
var _servicediscoveryJs = _interopRequireDefault(require("aws-sdk/clients/servicediscovery.js"));
|
|
8
|
+
function _interopRequireDefault(obj) {
|
|
9
|
+
return obj && obj.__esModule ? obj : {
|
|
10
|
+
default: obj
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const defaults = {
|
|
14
|
+
AwsClient: _servicediscoveryJs.default,
|
|
15
|
+
awsClientOptions: {},
|
|
16
|
+
awsClientAssumeRole: undefined,
|
|
17
|
+
awsClientCapture: undefined,
|
|
18
|
+
fetchData: {},
|
|
19
|
+
disablePrefetch: false,
|
|
20
|
+
cacheKey: 'cloud-map',
|
|
21
|
+
cacheExpiry: -1,
|
|
22
|
+
setToContext: false
|
|
23
|
+
};
|
|
24
|
+
const serviceDiscoveryMiddleware = (opts = {})=>{
|
|
25
|
+
const options = {
|
|
26
|
+
...defaults,
|
|
27
|
+
...opts
|
|
28
|
+
};
|
|
29
|
+
const fetch = (request, cachedValues = {})=>{
|
|
30
|
+
const values = {};
|
|
31
|
+
for (const internalKey of Object.keys(options.fetchData)){
|
|
32
|
+
if (cachedValues[internalKey]) continue;
|
|
33
|
+
values[internalKey] = client.discoverInstances(options.fetchData[internalKey]).promise().then((resp)=>resp.Instances).catch((e)=>{
|
|
34
|
+
const value = (0, _util).getCache(options.cacheKey).value ?? {};
|
|
35
|
+
value[internalKey] = undefined;
|
|
36
|
+
(0, _util).modifyCache(options.cacheKey, value);
|
|
37
|
+
throw e;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return values;
|
|
41
|
+
};
|
|
42
|
+
let prefetch, client;
|
|
43
|
+
if ((0, _util).canPrefetch(options)) {
|
|
44
|
+
client = (0, _util).createPrefetchClient(options);
|
|
45
|
+
prefetch = (0, _util).processCache(options, fetch);
|
|
46
|
+
}
|
|
47
|
+
const serviceDiscoveryMiddlewareBefore = async (request)=>{
|
|
48
|
+
if (!client) {
|
|
49
|
+
client = await (0, _util).createClient(options, request);
|
|
50
|
+
}
|
|
51
|
+
const { value } = prefetch ?? (0, _util).processCache(options, fetch, request);
|
|
52
|
+
Object.assign(request.internal, value);
|
|
53
|
+
if (options.setToContext) {
|
|
54
|
+
const data = await (0, _util).getInternal(Object.keys(options.fetchData), request);
|
|
55
|
+
if (options.setToContext) Object.assign(request.context, data);
|
|
56
|
+
}
|
|
57
|
+
prefetch = null;
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
before: serviceDiscoveryMiddlewareBefore
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
var _default = serviceDiscoveryMiddleware;
|
|
64
|
+
module.exports = _default;
|
|
65
|
+
|
|
2
66
|
|
|
3
67
|
//# sourceMappingURL=index.cjs.map
|
package/index.js
CHANGED
|
@@ -1,3 +1,56 @@
|
|
|
1
|
-
import{canPrefetch,createPrefetchClient,createClient,getCache,getInternal,processCache,modifyCache}from
|
|
1
|
+
import { canPrefetch, createPrefetchClient, createClient, getCache, getInternal, processCache, modifyCache } from '@middy/util';
|
|
2
|
+
import ServiceDiscovery from 'aws-sdk/clients/servicediscovery.js';
|
|
3
|
+
const defaults = {
|
|
4
|
+
AwsClient: ServiceDiscovery,
|
|
5
|
+
awsClientOptions: {},
|
|
6
|
+
awsClientAssumeRole: undefined,
|
|
7
|
+
awsClientCapture: undefined,
|
|
8
|
+
fetchData: {},
|
|
9
|
+
disablePrefetch: false,
|
|
10
|
+
cacheKey: 'cloud-map',
|
|
11
|
+
cacheExpiry: -1,
|
|
12
|
+
setToContext: false
|
|
13
|
+
};
|
|
14
|
+
const serviceDiscoveryMiddleware = (opts = {})=>{
|
|
15
|
+
const options = {
|
|
16
|
+
...defaults,
|
|
17
|
+
...opts
|
|
18
|
+
};
|
|
19
|
+
const fetch = (request, cachedValues = {})=>{
|
|
20
|
+
const values = {};
|
|
21
|
+
for (const internalKey of Object.keys(options.fetchData)){
|
|
22
|
+
if (cachedValues[internalKey]) continue;
|
|
23
|
+
values[internalKey] = client.discoverInstances(options.fetchData[internalKey]).promise().then((resp)=>resp.Instances).catch((e)=>{
|
|
24
|
+
const value = getCache(options.cacheKey).value ?? {};
|
|
25
|
+
value[internalKey] = undefined;
|
|
26
|
+
modifyCache(options.cacheKey, value);
|
|
27
|
+
throw e;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return values;
|
|
31
|
+
};
|
|
32
|
+
let prefetch, client;
|
|
33
|
+
if (canPrefetch(options)) {
|
|
34
|
+
client = createPrefetchClient(options);
|
|
35
|
+
prefetch = processCache(options, fetch);
|
|
36
|
+
}
|
|
37
|
+
const serviceDiscoveryMiddlewareBefore = async (request)=>{
|
|
38
|
+
if (!client) {
|
|
39
|
+
client = await createClient(options, request);
|
|
40
|
+
}
|
|
41
|
+
const { value } = prefetch ?? processCache(options, fetch, request);
|
|
42
|
+
Object.assign(request.internal, value);
|
|
43
|
+
if (options.setToContext) {
|
|
44
|
+
const data = await getInternal(Object.keys(options.fetchData), request);
|
|
45
|
+
if (options.setToContext) Object.assign(request.context, data);
|
|
46
|
+
}
|
|
47
|
+
prefetch = null;
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
before: serviceDiscoveryMiddlewareBefore
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
export default serviceDiscoveryMiddleware;
|
|
54
|
+
|
|
2
55
|
|
|
3
56
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/service-discovery",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"description": "Service Discovery (Cloud Map) instances middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -54,12 +54,12 @@
|
|
|
54
54
|
},
|
|
55
55
|
"homepage": "https://middy.js.org",
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@middy/util": "
|
|
57
|
+
"@middy/util": "3.0.4"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@middy/core": "
|
|
60
|
+
"@middy/core": "3.0.4",
|
|
61
61
|
"aws-sdk": "^2.939.0",
|
|
62
62
|
"aws-xray-sdk": "^3.3.3"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "3e9bc83e791f943c71cd7003fc27f0a3692d83a1"
|
|
65
65
|
}
|