@openapi-typescript-infra/service 4.4.0 → 4.5.1

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.
@@ -6,10 +6,5 @@
6
6
  "server": {
7
7
  "port": 0,
8
8
  "internalPort": 0
9
- },
10
- "connections": {
11
- "default": {
12
- "proxy": "http://localhost:9990"
13
- }
14
9
  }
15
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openapi-typescript-infra/service",
3
- "version": "4.4.0",
3
+ "version": "4.5.1",
4
4
  "description": "An opinionated framework for building configuration driven services - web, api, or ob. Uses OpenAPI, pino logging, express, confit, Typescript and vitest.",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
@@ -121,3 +121,4 @@ export function insertConfigurationBefore(
121
121
  }
122
122
 
123
123
  export * from './schema';
124
+ export * from './validation';
@@ -1,14 +1,6 @@
1
1
  import type { BaseConfitSchema } from '@sesamecare-oss/confit';
2
2
  import type { Level } from 'pino';
3
3
 
4
- export interface ServiceConfiguration {
5
- protocol?: string;
6
- port?: number;
7
- host?: string;
8
- basePath?: string;
9
- proxy?: string | false;
10
- }
11
-
12
4
  export interface ConfigurationItemEnabled {
13
5
  enabled?: boolean;
14
6
  }
@@ -66,10 +58,9 @@ export interface ConfigurationSchema extends BaseConfitSchema {
66
58
  // Note that generally it's better to offload tls termination,
67
59
  // but this is useful for dev.
68
60
  key?: string | Uint8Array;
69
- certificate?: string;
61
+ certificate?: string | Uint8Array;
70
62
  // If you have an alternate host name (other than localhost) that
71
63
  // should be used when referring to this service, set it here.
72
64
  hostname?: string;
73
65
  };
74
- connections: Record<string, ServiceConfiguration>;
75
66
  }
@@ -0,0 +1,22 @@
1
+ import { ConfigurationSchema } from './schema';
2
+
3
+ export interface ConfigValidationError {
4
+ path: string;
5
+ message: string;
6
+ }
7
+
8
+ export type ConfigurationValidator<Config extends ConfigurationSchema> = (config: Config) => {
9
+ success: boolean;
10
+ errors: ConfigValidationError[];
11
+ };
12
+
13
+ export function validateConfiguration<Config extends ConfigurationSchema>(
14
+ config: Config,
15
+ validator: ConfigurationValidator<Config>,
16
+ ) {
17
+ const result = validator(config);
18
+ if (!result.success) {
19
+ throw new Error(`Configuration validation failed:
20
+ ${result.errors.map((e) => ` - ${e.path}: ${e.message}`).join('\n')}`);
21
+ }
22
+ }
@@ -271,7 +271,7 @@ function httpServer<
271
271
  return https.createServer(
272
272
  {
273
273
  key: config.key ? Buffer.from(config.key) : undefined,
274
- cert: config.certificate,
274
+ cert: config.certificate ? Buffer.from(config.certificate) : undefined,
275
275
  },
276
276
  app,
277
277
  );
@@ -1,48 +0,0 @@
1
- name: Node.js Package
2
-
3
- on:
4
- push:
5
- branches:
6
- - main
7
-
8
- permissions:
9
- contents: read
10
-
11
- jobs:
12
- build:
13
- runs-on: ubuntu-latest
14
- steps:
15
- - uses: actions/checkout@v3
16
-
17
- - uses: actions/setup-node@v3
18
- with:
19
- node-version: 18
20
- - run: yarn install --immutable
21
- - run: yarn build
22
- - run: yarn lint
23
- - run: yarn test
24
-
25
- publish-npm:
26
- needs: build
27
- permissions:
28
- contents: write
29
- issues: write
30
- id-token: write
31
- pull-requests: write
32
- runs-on: ubuntu-latest
33
- steps:
34
- - uses: actions/checkout@v1
35
-
36
- - uses: actions/setup-node@v3
37
- with:
38
- node-version: 18
39
- registry-url: https://registry.npmjs.org/
40
- - run: yarn install --immutable
41
- - run: yarn build
42
-
43
- - name: Release
44
- env:
45
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
47
- run: |
48
- yarn dlx semantic-release