@interopio/gateway-server 0.5.2-beta → 0.6.0-beta

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,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/gateway/metrics/rest.ts"],
4
- "sourcesContent": ["import * as rest from '@interopio/gateway/metrics/publisher/rest';\nimport {IOGateway} from '@interopio/gateway';\nimport {CookieAgent} from 'http-cookie-agent/undici/v6';\nimport {CookieJar} from 'tough-cookie';\n\nexport const fetchWithCookies = (existing?: typeof fetch): typeof fetch => {\n const fetchFn = existing ?? globalThis.fetch;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const jar: any = new CookieJar();\n const dispatcher = new CookieAgent({cookies: {jar}});\n return async (input: RequestInfo | URL, request?: RequestInit) => {\n const requestWithDispatcher = {...request, dispatcher};\n return await fetchFn(input, requestWithDispatcher);\n }\n}\nexport const name = rest.name;\n\nexport function create(cfg: rest.RestPublisherConfig, logger: IOGateway.Logging.Logger) {\n return rest.create({...cfg, fetch: fetchWithCookies(cfg.fetch)}, logger);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,gBAAAA;AAAA,EAAA;AAAA,cAAAC;AAAA;AAAA;AAAA,WAAsB;AAEtB,gBAA0B;AAC1B,0BAAwB;AAEjB,IAAM,mBAAmB,CAAC,aAA0C;AACvE,QAAM,UAAU,YAAY,WAAW;AAEvC,QAAM,MAAW,IAAI,8BAAU;AAC/B,QAAM,aAAa,IAAI,sBAAY,EAAC,SAAS,EAAC,IAAG,EAAC,CAAC;AACnD,SAAO,OAAO,OAA0B,YAA0B;AAC9D,UAAM,wBAAwB,EAAC,GAAG,SAAS,WAAU;AACrD,WAAO,MAAM,QAAQ,OAAO,qBAAqB;AAAA,EACrD;AACJ;AACO,IAAMA,QAAY;AAElB,SAASD,QAAO,KAA+B,QAAkC;AACpF,SAAY,YAAO,EAAC,GAAG,KAAK,OAAO,iBAAiB,IAAI,KAAK,EAAC,GAAG,MAAM;AAC3E;",
4
+ "sourcesContent": ["import * as rest from '@interopio/gateway/metrics/publisher/rest';\nimport {IOGateway} from '@interopio/gateway';\nimport {CookieAgent} from 'http-cookie-agent/undici/v6';\nimport {CookieJar} from 'tough-cookie';\n\nexport const fetchWithCookies = (existing?: typeof fetch): typeof fetch => {\n const fetchFn = existing ?? globalThis.fetch;\n const jar = new CookieJar();\n const dispatcher = new CookieAgent({cookies: {jar}});\n return async (input: RequestInfo | URL, request?: RequestInit) => {\n const requestWithDispatcher = {...request, dispatcher};\n return await fetchFn(input, requestWithDispatcher);\n }\n}\nexport const name = rest.name;\n\nexport function create(cfg: rest.RestPublisherConfig, logger: IOGateway.Logging.Logger) {\n return rest.create({...cfg, fetch: fetchWithCookies(cfg.fetch)}, logger);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,gBAAAA;AAAA,EAAA;AAAA,cAAAC;AAAA;AAAA;AAAA,WAAsB;AAEtB,gBAA0B;AAC1B,0BAAwB;AAEjB,IAAM,mBAAmB,CAAC,aAA0C;AACvE,QAAM,UAAU,YAAY,WAAW;AACvC,QAAM,MAAM,IAAI,8BAAU;AAC1B,QAAM,aAAa,IAAI,sBAAY,EAAC,SAAS,EAAC,IAAG,EAAC,CAAC;AACnD,SAAO,OAAO,OAA0B,YAA0B;AAC9D,UAAM,wBAAwB,EAAC,GAAG,SAAS,WAAU;AACrD,WAAO,MAAM,QAAQ,OAAO,qBAAqB;AAAA,EACrD;AACJ;AACO,IAAMA,QAAY;AAElB,SAASD,QAAO,KAA+B,QAAkC;AACpF,SAAY,YAAO,EAAC,GAAG,KAAK,OAAO,iBAAiB,IAAI,KAAK,EAAC,GAAG,MAAM;AAC3E;",
6
6
  "names": ["create", "name"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/gateway/metrics/rest.ts"],
4
- "sourcesContent": ["import * as rest from '@interopio/gateway/metrics/publisher/rest';\nimport {IOGateway} from '@interopio/gateway';\nimport {CookieAgent} from 'http-cookie-agent/undici/v6';\nimport {CookieJar} from 'tough-cookie';\n\nexport const fetchWithCookies = (existing?: typeof fetch): typeof fetch => {\n const fetchFn = existing ?? globalThis.fetch;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const jar: any = new CookieJar();\n const dispatcher = new CookieAgent({cookies: {jar}});\n return async (input: RequestInfo | URL, request?: RequestInit) => {\n const requestWithDispatcher = {...request, dispatcher};\n return await fetchFn(input, requestWithDispatcher);\n }\n}\nexport const name = rest.name;\n\nexport function create(cfg: rest.RestPublisherConfig, logger: IOGateway.Logging.Logger) {\n return rest.create({...cfg, fetch: fetchWithCookies(cfg.fetch)}, logger);\n}\n"],
5
- "mappings": ";AAAA,YAAY,UAAU;AAEtB,SAAQ,mBAAkB;AAC1B,SAAQ,iBAAgB;AAEjB,IAAM,mBAAmB,CAAC,aAA0C;AACvE,QAAM,UAAU,YAAY,WAAW;AAEvC,QAAM,MAAW,IAAI,UAAU;AAC/B,QAAM,aAAa,IAAI,YAAY,EAAC,SAAS,EAAC,IAAG,EAAC,CAAC;AACnD,SAAO,OAAO,OAA0B,YAA0B;AAC9D,UAAM,wBAAwB,EAAC,GAAG,SAAS,WAAU;AACrD,WAAO,MAAM,QAAQ,OAAO,qBAAqB;AAAA,EACrD;AACJ;AACO,IAAMA,QAAY;AAElB,SAASC,QAAO,KAA+B,QAAkC;AACpF,SAAY,YAAO,EAAC,GAAG,KAAK,OAAO,iBAAiB,IAAI,KAAK,EAAC,GAAG,MAAM;AAC3E;",
4
+ "sourcesContent": ["import * as rest from '@interopio/gateway/metrics/publisher/rest';\nimport {IOGateway} from '@interopio/gateway';\nimport {CookieAgent} from 'http-cookie-agent/undici/v6';\nimport {CookieJar} from 'tough-cookie';\n\nexport const fetchWithCookies = (existing?: typeof fetch): typeof fetch => {\n const fetchFn = existing ?? globalThis.fetch;\n const jar = new CookieJar();\n const dispatcher = new CookieAgent({cookies: {jar}});\n return async (input: RequestInfo | URL, request?: RequestInit) => {\n const requestWithDispatcher = {...request, dispatcher};\n return await fetchFn(input, requestWithDispatcher);\n }\n}\nexport const name = rest.name;\n\nexport function create(cfg: rest.RestPublisherConfig, logger: IOGateway.Logging.Logger) {\n return rest.create({...cfg, fetch: fetchWithCookies(cfg.fetch)}, logger);\n}\n"],
5
+ "mappings": ";AAAA,YAAY,UAAU;AAEtB,SAAQ,mBAAkB;AAC1B,SAAQ,iBAAgB;AAEjB,IAAM,mBAAmB,CAAC,aAA0C;AACvE,QAAM,UAAU,YAAY,WAAW;AACvC,QAAM,MAAM,IAAI,UAAU;AAC1B,QAAM,aAAa,IAAI,YAAY,EAAC,SAAS,EAAC,IAAG,EAAC,CAAC;AACnD,SAAO,OAAO,OAA0B,YAA0B;AAC9D,UAAM,wBAAwB,EAAC,GAAG,SAAS,WAAU;AACrD,WAAO,MAAM,QAAQ,OAAO,qBAAqB;AAAA,EACrD;AACJ;AACO,IAAMA,QAAY;AAElB,SAASC,QAAO,KAA+B,QAAkC;AACpF,SAAY,YAAO,EAAC,GAAG,KAAK,OAAO,iBAAiB,IAAI,KAAK,EAAC,GAAG,MAAM;AAC3E;",
6
6
  "names": ["name", "create"]
7
7
  }
@@ -4,8 +4,9 @@ import {FilePublisherConfig} from '@interopio/gateway/metrics/publisher/file';
4
4
  export default GatewayServer.Factory;
5
5
 
6
6
  export namespace GatewayServer {
7
- export const Factory: (options: ServerConfig) => Promise<Server>;
8
- export type SslConfig = {key?: string, cert?: string, ca?: string};
7
+ export const Factory: (options: ServerConfig) => Promise<Server>
8
+ export type SslConfig = { key?: string, cert?: string, ca?: string }
9
+ export type AuthorizationRule = { access: 'permitted' | 'denied' | 'authenticated' }
9
10
  export type OriginFilters = {
10
11
  non_matched?: IOGateway.Filtering.Action
11
12
  missing?: IOGateway.Filtering.Action
@@ -23,13 +24,28 @@ export namespace GatewayServer {
23
24
  whitelist?: IOGateway.Filtering.Matcher[]
24
25
  }
25
26
  export import LoggerConfig = IOGateway.Logging.LogConfig;
27
+ export type AuthConfig = Readonly<{
28
+ type: 'none' | 'basic' | 'oauth2',
29
+ basic?: { user?: {name: string, password?: string}, realm?: string }
30
+ oauth2?: { jwt: { issuerUri: string, issuer?: string, audience?: string | string[] } }
31
+ }>;
32
+ export type CorsConfig = Readonly<{
33
+ allowOrigin?: '*' | IOGateway.Filtering.Matcher[]
34
+ allowHeaders?: string[]
35
+ allowMethods?: string[]
36
+ exposeHeaders?: string[]
37
+ allowCredentials?: boolean
38
+ allowPrivateNetwork?: boolean
39
+ maxAge?: number
40
+ }>;
41
+
26
42
  export type ServerConfig = {
27
43
  /**
28
44
  * The port to bind for network communication.
29
- * Accepts a single valuer or a range.
45
+ * Accepts a single value or a range.
30
46
  * If a range is specified, will bind to the first available port in the range.
31
47
  *
32
- * Defaults to 0 - a random port.
48
+ * Default: 0 - a random port.
33
49
  */
34
50
  port?: number | string
35
51
  /**
@@ -38,6 +54,12 @@ export namespace GatewayServer {
38
54
  host?: string
39
55
  ssl?: SslConfig,
40
56
 
57
+ auth?: AuthConfig,
58
+ /**
59
+ * CORS configuration.
60
+ */
61
+ cors?: CorsConfig,
62
+
41
63
  memory?: {
42
64
  memory_limit?: number
43
65
  dump_location?: string,
@@ -53,17 +75,23 @@ export namespace GatewayServer {
53
75
  limits?: {
54
76
  max_connections?: number
55
77
  },
78
+ authorize?: AuthorizationRule
56
79
  }
57
80
  mesh?: {
58
81
  timeout?: number // defaults to 60000
59
82
  ping?: number // defaults to 30000
83
+ authorize?: AuthorizationRule
84
+ origins?: OriginFilters
60
85
  }
61
86
  metrics?: {
62
87
  file: FilePublisherConfig
88
+ authorize?: AuthorizationRule
63
89
  }
64
90
  }
91
+
65
92
  export interface Server {
66
93
  readonly gateway: IOGateway.Gateway
94
+
67
95
  close(): Promise<void>
68
96
  }
69
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interopio/gateway-server",
3
- "version": "0.5.2-beta",
3
+ "version": "0.6.0-beta",
4
4
  "keywords": [
5
5
  "gateway",
6
6
  "server",
@@ -53,7 +53,7 @@
53
53
  "node": ">=20"
54
54
  },
55
55
  "dependencies": {
56
- "@interopio/gateway": "^0.10.0-beta",
56
+ "@interopio/gateway": "^0.11.0-beta",
57
57
  "ws": "^8.18.2",
58
58
  "http-cookie-agent": "^7.0.1",
59
59
  "undici": "^6.21.3",
package/readme.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # io.Gateway Server
2
2
 
3
+ ## Getting Started
4
+
5
+ ```typescript
6
+ import GatewayServer, {type Server} from '@interopio/gateway-server';
7
+
8
+ const server: Server = await GatewayServer({
9
+ port: 8385,
10
+ gateway: {
11
+ route: '/gw',
12
+ access: 'authenticated'
13
+ }
14
+ });
15
+
16
+ await server.close();
17
+ ```
18
+
19
+ ## Configure HTTPS
20
+
21
+ ```typescript
22
+ import GatewayServer, {type Server} from '@interopio/gateway-server';
23
+
24
+ const server: Server = await GatewayServer({
25
+ port: 8443,
26
+ ssl: {
27
+ cert: "glue42.crt",
28
+ ca: "intermediate.crt",
29
+ key: "glue42.key"
30
+ },
31
+ metrics: {
32
+ access: 'permitted'
33
+ }
34
+ });
35
+
36
+ await server.close();
37
+
38
+ ```
39
+
3
40
  ## `@glue42/gateway-ent` compatibility
4
41
 
5
42
  This package aims to provide compatibility with `@glue42/gateway-ent` package