@toa.io/extensions.origins 0.8.0-dev.1 → 0.8.0-dev.3
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 +6 -6
- package/readme.md +18 -3
- package/source/manifest.js +18 -5
- package/source/manifest.test.js +18 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/extensions.origins",
|
|
3
|
-
"version": "0.8.0-dev.
|
|
3
|
+
"version": "0.8.0-dev.3",
|
|
4
4
|
"description": "Toa Origins",
|
|
5
5
|
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/toa-io/toa#readme",
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@toa.io/core": "0.8.0-dev.
|
|
23
|
-
"@toa.io/generic": "0.8.0-dev.
|
|
24
|
-
"@toa.io/schemas": "0.8.0-dev.
|
|
25
|
-
"@toa.io/yaml": "0.7.2-dev.
|
|
22
|
+
"@toa.io/core": "0.8.0-dev.3",
|
|
23
|
+
"@toa.io/generic": "0.8.0-dev.3",
|
|
24
|
+
"@toa.io/schemas": "0.8.0-dev.3",
|
|
25
|
+
"@toa.io/yaml": "0.7.2-dev.4",
|
|
26
26
|
"comq": "0.6.0",
|
|
27
27
|
"node-fetch": "2.6.7"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node-fetch": "2.6.2"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "d72b4c2362e928dba56f4743cc956aa5486f82a4"
|
|
33
33
|
}
|
package/readme.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Toa Origins
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Enables external communications over supported protocols (HTTP and AMQP).
|
|
4
4
|
|
|
5
5
|
## TL;DR
|
|
6
6
|
|
|
@@ -36,7 +36,22 @@ origins:
|
|
|
36
36
|
|
|
37
37
|
## Manifest
|
|
38
38
|
|
|
39
|
-
`origins` manifest is an object
|
|
39
|
+
`origins` manifest is an object with origin names as keys an origin URLs as values.
|
|
40
|
+
Component's `origins` manifest can be overridden by the Context `origins` annotation.
|
|
41
|
+
|
|
42
|
+
### Sharded Connections
|
|
43
|
+
|
|
44
|
+
Origin value may contain [shards](/libraries/generic/readme.md#shards) placeholders.
|
|
45
|
+
|
|
46
|
+
### Environment Variables
|
|
47
|
+
|
|
48
|
+
Origin value may contain environment variable placeholders.
|
|
49
|
+
|
|
50
|
+
```yaml
|
|
51
|
+
# manifest.toa.yaml
|
|
52
|
+
origins:
|
|
53
|
+
foo@dev: stage${STAGE_NUMBER}.stages.com
|
|
54
|
+
```
|
|
40
55
|
|
|
41
56
|
## HTTP Aspect
|
|
42
57
|
|
|
@@ -85,7 +100,7 @@ async function transition (input, object, context) {
|
|
|
85
100
|
}
|
|
86
101
|
```
|
|
87
102
|
|
|
88
|
-
#### `null`
|
|
103
|
+
#### `null` manifest
|
|
89
104
|
|
|
90
105
|
To enable the extension for a component that uses arbitrary URLs without any specific origins to
|
|
91
106
|
declare, the Origins manifest should be set to `null`.
|
package/source/manifest.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const { remap, echo, shards } = require('@toa.io/generic')
|
|
3
4
|
const schemas = require('./schemas')
|
|
4
5
|
const protocols = require('./protocols')
|
|
5
6
|
|
|
@@ -10,16 +11,28 @@ const protocols = require('./protocols')
|
|
|
10
11
|
function manifest (manifest) {
|
|
11
12
|
if (manifest === null) return {}
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
manifest = remap(manifest, echo)
|
|
15
|
+
validate(manifest)
|
|
14
16
|
|
|
15
|
-
for (const
|
|
16
|
-
const
|
|
17
|
-
const supported = protocols.find((provider) => provider.protocols.includes(protocol))
|
|
17
|
+
for (const url of Object.values(manifest)) {
|
|
18
|
+
const supported = protocols.find((provider) => supports(provider, url))
|
|
18
19
|
|
|
19
|
-
if (supported === undefined) throw new Error(`'${
|
|
20
|
+
if (supported === undefined) throw new Error(`'${url}' protocol is not supported`)
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
return manifest
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
/**
|
|
27
|
+
* @param {toa.origins.Manifest} manifest
|
|
28
|
+
*/
|
|
29
|
+
function validate (manifest) {
|
|
30
|
+
manifest = remap(manifest, (value) => shards(value)[0])
|
|
31
|
+
schemas.manifest.validate(manifest)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function supports (provider, url) {
|
|
35
|
+
return provider.protocols.findIndex((protocol) => url.substring(0, protocol.length) === protocol) !== -1
|
|
36
|
+
}
|
|
37
|
+
|
|
25
38
|
exports.manifest = manifest
|
package/source/manifest.test.js
CHANGED
|
@@ -55,3 +55,21 @@ it.each(PROTOCOLS)('should support %s protocol', async (protocol) => {
|
|
|
55
55
|
|
|
56
56
|
expect(() => manifest(input)).not.toThrow()
|
|
57
57
|
})
|
|
58
|
+
|
|
59
|
+
it('should handle placeholders', async () => {
|
|
60
|
+
const input = { foo: 'http://${FOO}' + generate() + ':${BAR}/' } // eslint-disable-line no-template-curly-in-string
|
|
61
|
+
|
|
62
|
+
expect(() => manifest(input)).not.toThrow()
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('should handle host shards', async () => {
|
|
66
|
+
const input = { foo: 'http://{0-3}' + generate() }
|
|
67
|
+
|
|
68
|
+
expect(() => manifest(input)).not.toThrow()
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('should handle port shards', async () => {
|
|
72
|
+
const input = { foo: 'http://' + generate() + ':888{0-9}' }
|
|
73
|
+
|
|
74
|
+
expect(() => manifest(input)).not.toThrow()
|
|
75
|
+
})
|