@things-factory/api 8.0.5 → 9.0.0-beta.12

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/api",
3
- "version": "8.0.5",
3
+ "version": "9.0.0-beta.12",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -24,12 +24,12 @@
24
24
  "migration:create": "node ../../node_modules/typeorm/cli.js migration:create ./server/migrations/migration"
25
25
  },
26
26
  "dependencies": {
27
- "@things-factory/auth-base": "^8.0.5",
28
- "@things-factory/component-ui": "^8.0.0",
29
- "@things-factory/shell": "^8.0.2",
27
+ "@things-factory/auth-base": "^9.0.0-beta.12",
28
+ "@things-factory/component-ui": "^9.0.0-beta.5",
29
+ "@things-factory/shell": "^9.0.0-beta.12",
30
30
  "koa2-swagger-ui": "^5.0.2",
31
31
  "swagger-jsdoc": "^6.2.8",
32
32
  "yamljs": "^0.3.0"
33
33
  },
34
- "gitHead": "9ab6fca18eeb58b9d2f3411661508a39d0ab6aee"
34
+ "gitHead": "5e9ade1c2d4b4c96b89396e36c3afa1caaf18ef0"
35
35
  }
package/server/index.ts DELETED
@@ -1,3 +0,0 @@
1
- import './routes'
2
-
3
- export * from './routers'
@@ -1,74 +0,0 @@
1
- import Router from 'koa-router'
2
- import { koaSwagger } from 'koa2-swagger-ui'
3
- import { merge } from 'lodash'
4
- import path from 'path'
5
- import yaml from 'yamljs'
6
-
7
- import { appRootPath } from '@things-factory/env'
8
-
9
- const openapiDir = path.join(appRootPath, 'dist-app', 'openapi')
10
-
11
- export const PREFIX = '/api-docs'
12
- export const apiDocsRouter = new Router()
13
-
14
- export function initMiddlewares(app) {
15
- var fs = require('fs')
16
-
17
- var spec = {}
18
-
19
- function build() {
20
- try {
21
- if (!fs.existsSync(openapiDir)) {
22
- return
23
- }
24
-
25
- var files = fs.readdirSync(openapiDir)
26
-
27
- files
28
- .filter(filename => /\.yaml$/.test(filename))
29
- .forEach(file => {
30
- const version = path.basename(file, path.extname(file))
31
-
32
- if (fs.existsSync(path.join(openapiDir, version))) {
33
- spec[version] = fs
34
- .readdirSync(path.join(openapiDir, version))
35
- .filter(filename => /\.yaml$/.test(filename))
36
- .reduce(
37
- (merged, file) => {
38
- const parsed = yaml.parse(fs.readFileSync(path.join(openapiDir, version, file)).toString())
39
- return merge(merged, parsed)
40
- },
41
- {
42
- ...yaml.parse(fs.readFileSync(path.join(openapiDir, file)).toString())
43
- }
44
- )
45
- } else {
46
- spec[version] = yaml.parse(fs.readFileSync(path.join(openapiDir, file)).toString())
47
- }
48
- })
49
- } catch (err) {
50
- console.error('build error', err)
51
- }
52
- }
53
-
54
- build()
55
-
56
- process.on('client-rebuilt' as any, (app, compilerFileSystem) => {
57
- /* change filesystem whenever webpacking assets done. only for development mode. */
58
- fs = compilerFileSystem
59
- build()
60
- })
61
-
62
- apiDocsRouter.get(`/:version`, async (context, next) => {
63
- let { version } = context.params
64
-
65
- return await koaSwagger({ routePrefix: false, swaggerOptions: { spec: spec[version] || {} } })(context, next)
66
- })
67
-
68
- // fallback
69
- apiDocsRouter.get('(.*)', async (context, next) => {
70
- var defaultVersion = Object.keys(spec)[0]
71
-
72
- context.redirect(`${PREFIX}/${defaultVersion}`)
73
- })
74
- }
@@ -1,2 +0,0 @@
1
- export * from './restful-api-router'
2
- export * from './api-docs-router'
@@ -1,24 +0,0 @@
1
- import Router from 'koa-router'
2
-
3
- import { domainAuthenticateMiddleware, jwtAuthenticateMiddleware } from '@things-factory/auth-base'
4
- import { GraphqlLocalClient } from '@things-factory/shell'
5
-
6
- export const restfulApiRouter = new Router()
7
-
8
- restfulApiRouter.use(jwtAuthenticateMiddleware)
9
- restfulApiRouter.use(domainAuthenticateMiddleware)
10
-
11
- restfulApiRouter.use(async (context, next) => {
12
- context.state.version = context.path.split('/')[2]
13
- context.state.client = GraphqlLocalClient.client
14
-
15
- const { user, domain, version } = context.state
16
-
17
- if (!user) {
18
- context.status = 401
19
- context.body = context.t('error.user not found')
20
- return
21
- }
22
-
23
- await next()
24
- })
package/server/routes.ts DELETED
@@ -1,10 +0,0 @@
1
- import { apiDocsRouter, PREFIX as apiDocsPrefix, restfulApiRouter } from './routers'
2
-
3
- process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {
4
- globalPublicRouter.use(apiDocsPrefix, apiDocsRouter.routes(), apiDocsRouter.allowedMethods())
5
- })
6
-
7
- process.on('bootstrap-module-domain-public-route' as any, (app, domainPublicRouter) => {
8
- /* API nested-routers authentication with jwtAuthenticateMiddleware based on domain-public-router */
9
- domainPublicRouter.use('/api', restfulApiRouter.routes(), restfulApiRouter.allowedMethods())
10
- })
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../tsconfig-base.json",
3
- "compilerOptions": {
4
- "outDir": "./dist-server",
5
- "baseUrl": "./"
6
- },
7
- "include": ["./server/**/*"],
8
- "exclude": ["**/*.spec.ts"]
9
- }