@things-factory/shell 5.0.15 → 6.0.0-alpha.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/bin/things-factory-migration +18 -9
- package/client/elements/custom-alert.js +3 -0
- package/config/config.development.js +31 -22
- package/dist-server/graphql-local-client.d.ts +28 -0
- package/dist-server/index.d.ts +9 -0
- package/dist-server/index.js +1 -0
- package/dist-server/index.js.map +1 -1
- package/dist-server/initializers/database.d.ts +7 -0
- package/dist-server/initializers/database.js +40 -9
- package/dist-server/initializers/database.js.map +1 -1
- package/dist-server/initializers/naming-strategy.d.ts +6 -0
- package/dist-server/middlewares/domain-middleware.d.ts +1 -0
- package/dist-server/middlewares/index.d.ts +2 -0
- package/dist-server/migrations/1000000000000-SeedDomain.d.ts +5 -0
- package/dist-server/migrations/1000000000000-SeedDomain.js +4 -4
- package/dist-server/migrations/1000000000000-SeedDomain.js.map +1 -1
- package/dist-server/migrations/index.d.ts +1 -0
- package/dist-server/pubsub-log-transport.d.ts +8 -0
- package/dist-server/pubsub.d.ts +2 -0
- package/dist-server/routers/domain-router.d.ts +2 -0
- package/dist-server/routers/global-router.d.ts +2 -0
- package/dist-server/routers/index.d.ts +2 -0
- package/dist-server/schema.d.ts +2 -0
- package/dist-server/server-dev.d.ts +1 -0
- package/dist-server/server-dev.js +16 -12
- package/dist-server/server-dev.js.map +1 -1
- package/dist-server/server.d.ts +1 -0
- package/dist-server/server.js +9 -6
- package/dist-server/server.js.map +1 -1
- package/dist-server/service/common-types/index.d.ts +6 -0
- package/dist-server/service/common-types/list-param.d.ts +19 -0
- package/dist-server/service/common-types/list-param.js +1 -1
- package/dist-server/service/common-types/list-param.js.map +1 -1
- package/dist-server/service/common-types/log.d.ts +6 -0
- package/dist-server/service/common-types/log.js.map +1 -1
- package/dist-server/service/common-types/object-ref.d.ts +5 -0
- package/dist-server/service/common-types/object-ref.js.map +1 -1
- package/dist-server/service/common-types/scalar-any.d.ts +2 -0
- package/dist-server/service/common-types/scalar-date.d.ts +2 -0
- package/dist-server/service/common-types/scalar-object.d.ts +1 -0
- package/dist-server/service/directive-transaction/index.d.ts +1 -0
- package/dist-server/service/directive-transaction/transaction.d.ts +3 -0
- package/dist-server/service/directive-transaction/transaction.js +2 -2
- package/dist-server/service/directive-transaction/transaction.js.map +1 -1
- package/dist-server/service/domain/domain-resolver.d.ts +17 -0
- package/dist-server/service/domain/domain-resolver.js +14 -13
- package/dist-server/service/domain/domain-resolver.js.map +1 -1
- package/dist-server/service/domain/domain-types.d.ts +21 -0
- package/dist-server/service/domain/domain-types.js.map +1 -1
- package/dist-server/service/domain/domain.d.ts +16 -0
- package/dist-server/service/domain/domain.js.map +1 -1
- package/dist-server/service/domain/index.d.ts +4 -0
- package/dist-server/service/index.d.ts +14 -0
- package/dist-server/service/subscription-data/data-resolver.d.ts +6 -0
- package/dist-server/service/subscription-data/data-resolver.js.map +1 -1
- package/dist-server/service/subscription-data/data-types.d.ts +6 -0
- package/dist-server/service/subscription-data/data-types.js.map +1 -1
- package/dist-server/service/subscription-data/index.d.ts +3 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/dist-server/utils/condition-builder.d.ts +17 -0
- package/dist-server/utils/get-domain.d.ts +10 -0
- package/dist-server/utils/get-domain.js +2 -2
- package/dist-server/utils/get-domain.js.map +1 -1
- package/dist-server/utils/get-query-builder-from-list-params.d.ts +21 -0
- package/dist-server/utils/get-query-builder-from-list-params.js +26 -7
- package/dist-server/utils/get-query-builder-from-list-params.js.map +1 -1
- package/dist-server/utils/index.d.ts +7 -0
- package/dist-server/utils/list-param-adjuster.d.ts +2 -0
- package/dist-server/utils/list-params-converter.d.ts +16 -0
- package/dist-server/utils/list-params-converter.js.map +1 -1
- package/dist-server/utils/list-query-builder.d.ts +7 -0
- package/dist-server/utils/publish-progress.d.ts +6 -0
- package/dist-server/webpack/koa-webpack/client.d.ts +1 -0
- package/dist-server/webpack/koa-webpack/index.d.ts +2 -0
- package/dist-server/webpack/koa-webpack/middleware.d.ts +0 -0
- package/dist-server/webpack/koa-webpack/validate.d.ts +1 -0
- package/ormconfig.js +2 -3
- package/package.json +8 -7
- package/server/index.ts +1 -0
- package/server/initializers/database.ts +52 -10
- package/server/migrations/1000000000000-SeedDomain.ts +4 -2
- package/server/server-dev.ts +29 -16
- package/server/server.ts +8 -8
- package/server/service/common-types/list-param.ts +4 -3
- package/server/service/directive-transaction/transaction.ts +3 -2
- package/server/service/domain/domain-resolver.ts +7 -6
- package/server/utils/get-domain.ts +2 -2
- package/server/utils/get-query-builder-from-list-params.ts +30 -7
- package/server/utils/list-params-converter.ts +1 -1
@@ -48,7 +48,7 @@ async function doModePrompt() {
|
|
48
48
|
: await inquirer.prompt(MODE_QUESTION)
|
49
49
|
|
50
50
|
process.env.NODE_ENV = answers.mode == 'development' ? 'development' : 'production'
|
51
|
-
const {
|
51
|
+
const { config } = require('@things-factory/env')
|
52
52
|
|
53
53
|
var ormconfig = require('@things-factory/shell/ormconfig')
|
54
54
|
|
@@ -56,7 +56,8 @@ async function doModePrompt() {
|
|
56
56
|
await confirmHost(ormconfig.host)
|
57
57
|
}
|
58
58
|
|
59
|
-
|
59
|
+
const connectionConfig = config.get('ormconfig')
|
60
|
+
await migrate(ormconfig, connectionConfig)
|
60
61
|
}
|
61
62
|
|
62
63
|
async function confirmHost(host) {
|
@@ -75,19 +76,25 @@ async function confirmHost(host) {
|
|
75
76
|
])
|
76
77
|
}
|
77
78
|
|
78
|
-
function migrate(ormconfig) {
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
79
|
+
async function migrate(ormconfig, connectionConfig) {
|
80
|
+
try {
|
81
|
+
const connection = await createConnection({
|
82
|
+
...ormconfig,
|
83
|
+
...connectionConfig,
|
84
|
+
logging: true
|
85
|
+
})
|
86
|
+
|
83
87
|
debug('Database connection established')
|
84
88
|
|
85
|
-
if ((
|
89
|
+
if ((connectionConfig.type == 'sqlite' || connectionConfig.type == 'better-sqlite3') && connectionConfig.synchronize == false) {
|
86
90
|
await connection.query('PRAGMA foreign_keys=OFF')
|
87
91
|
await connection.synchronize()
|
88
92
|
await connection.query('PRAGMA foreign_keys=ON')
|
89
93
|
}
|
90
94
|
|
95
|
+
const { addDataSource } = require('@things-factory/shell')
|
96
|
+
addDataSource('default', connection)
|
97
|
+
|
91
98
|
if (flags.undo) {
|
92
99
|
await connection.undoLastMigration()
|
93
100
|
} else {
|
@@ -96,5 +103,7 @@ function migrate(ormconfig) {
|
|
96
103
|
|
97
104
|
await connection.close()
|
98
105
|
debug('Database Migration Done.')
|
99
|
-
})
|
106
|
+
} catch(error) {
|
107
|
+
console.error(error)
|
108
|
+
}
|
100
109
|
}
|
@@ -35,6 +35,7 @@ export async function CustomAlert({
|
|
35
35
|
footer,
|
36
36
|
position = 'center',
|
37
37
|
toast,
|
38
|
+
timer,
|
38
39
|
confirmButton = {},
|
39
40
|
cancelButton = {},
|
40
41
|
invertButton = false,
|
@@ -77,6 +78,8 @@ export async function CustomAlert({
|
|
77
78
|
icon: icon || type,
|
78
79
|
title: title,
|
79
80
|
text: text,
|
81
|
+
timer: timer ? timer:0,
|
82
|
+
timerProgressBar: timer ? true : 0,
|
80
83
|
allowOutsideClick: allowOutsideClick,
|
81
84
|
allowEscapeKey: allowEscapeKey,
|
82
85
|
footer: footer,
|
@@ -22,25 +22,25 @@ module.exports = {
|
|
22
22
|
level: 'silly'
|
23
23
|
}
|
24
24
|
},
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
25
|
+
/**
|
26
|
+
* requestBody configuration
|
27
|
+
* ie.
|
28
|
+
* requestBody: {
|
29
|
+
* formLimit: '100mb',
|
30
|
+
* jsonLimit: '100mb',
|
31
|
+
* textLimit: '100mb'
|
32
|
+
* }
|
33
|
+
**/
|
34
|
+
|
35
|
+
/**
|
36
|
+
* fileUpload configuration
|
37
|
+
* ie.
|
38
|
+
* fileUpload: {
|
39
|
+
* maxFileSize: '100mb',
|
40
|
+
* maxFiles: 10
|
41
|
+
* }
|
42
|
+
**/
|
34
43
|
|
35
|
-
/**
|
36
|
-
* fileUpload configuration
|
37
|
-
* ie.
|
38
|
-
* fileUpload: {
|
39
|
-
* maxFileSize: '100mb',
|
40
|
-
* maxFiles: 10
|
41
|
-
* }
|
42
|
-
**/
|
43
|
-
|
44
44
|
/*
|
45
45
|
* pubsub configuration
|
46
46
|
* ie.
|
@@ -52,7 +52,7 @@ module.exports = {
|
|
52
52
|
* ...
|
53
53
|
* }
|
54
54
|
* }
|
55
|
-
*
|
55
|
+
*
|
56
56
|
* pubsub: {
|
57
57
|
* middleware: 'redisCluster', // empty, redis, mqtt, redisCluster
|
58
58
|
* nodes: [
|
@@ -63,16 +63,16 @@ module.exports = {
|
|
63
63
|
* ...
|
64
64
|
* }
|
65
65
|
* }
|
66
|
-
*
|
66
|
+
*
|
67
67
|
* pubsub: {
|
68
68
|
* middleware: 'kafka',
|
69
69
|
* topic: 'operato-app-graphql-pubsub'
|
70
70
|
* host: 'b-3.kafka-server:9092,b-1.kafka-server:9092,b-2.kafka-server:9092',
|
71
71
|
* options: {
|
72
|
-
* ...
|
72
|
+
* ...
|
73
73
|
* }
|
74
74
|
* }
|
75
|
-
*
|
75
|
+
*
|
76
76
|
* pubsub: {
|
77
77
|
* middleware: 'kafka',
|
78
78
|
* host: 'confluent.cloud:9092',
|
@@ -103,5 +103,14 @@ module.exports = {
|
|
103
103
|
synchronize: false,
|
104
104
|
logging: true,
|
105
105
|
logger: 'debug'
|
106
|
+
},
|
107
|
+
|
108
|
+
ormconfig4Tx: {
|
109
|
+
name: 'tx',
|
110
|
+
type: 'sqlite',
|
111
|
+
database: 'db.sqlite',
|
112
|
+
synchronize: false,
|
113
|
+
logging: true,
|
114
|
+
logger: 'debug'
|
106
115
|
}
|
107
116
|
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { GraphQLResponse } from 'apollo-server-types';
|
2
|
+
import { DocumentNode } from 'graphql';
|
3
|
+
declare type StringOrAst = string | DocumentNode;
|
4
|
+
declare type Query = {
|
5
|
+
query: StringOrAst;
|
6
|
+
mutation?: undefined;
|
7
|
+
variables?: {
|
8
|
+
[name: string]: any;
|
9
|
+
};
|
10
|
+
operationName?: string;
|
11
|
+
};
|
12
|
+
declare type Mutation = {
|
13
|
+
mutation: StringOrAst;
|
14
|
+
query?: undefined;
|
15
|
+
variables?: {
|
16
|
+
[name: string]: any;
|
17
|
+
};
|
18
|
+
operationName?: string;
|
19
|
+
};
|
20
|
+
export interface ApolloServerLocalClient {
|
21
|
+
query: (query: Query) => Promise<GraphQLResponse>;
|
22
|
+
mutate: (mutation: Mutation) => Promise<GraphQLResponse>;
|
23
|
+
}
|
24
|
+
export declare class GraphqlLocalClient {
|
25
|
+
static client: ApolloServerLocalClient;
|
26
|
+
static init(schema: any, app: any): void;
|
27
|
+
}
|
28
|
+
export {};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
export * from './migrations';
|
2
|
+
export * from './initializers/naming-strategy';
|
3
|
+
export * from './initializers/database';
|
4
|
+
export * from './utils';
|
5
|
+
export * from './pubsub';
|
6
|
+
export * from './pubsub-log-transport';
|
7
|
+
export * from './middlewares';
|
8
|
+
export * from './graphql-local-client';
|
9
|
+
export * from './service';
|
package/dist-server/index.js
CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
4
4
|
tslib_1.__exportStar(require("./migrations"), exports);
|
5
5
|
tslib_1.__exportStar(require("./initializers/naming-strategy"), exports);
|
6
|
+
tslib_1.__exportStar(require("./initializers/database"), exports);
|
6
7
|
tslib_1.__exportStar(require("./utils"), exports);
|
7
8
|
tslib_1.__exportStar(require("./pubsub"), exports);
|
8
9
|
tslib_1.__exportStar(require("./pubsub-log-transport"), exports);
|
package/dist-server/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;AAAA,uDAA4B;AAC5B,yEAA8C;AAC9C,kDAAuB;AACvB,mDAAwB;AACxB,iEAAsC;AACtC,wDAA6B;AAC7B,iEAAsC;AACtC,oDAAyB","sourcesContent":["export * from './migrations'\nexport * from './initializers/naming-strategy'\nexport * from './utils'\nexport * from './pubsub'\nexport * from './pubsub-log-transport'\nexport * from './middlewares'\nexport * from './graphql-local-client'\nexport * from './service'\n"]}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;AAAA,uDAA4B;AAC5B,yEAA8C;AAC9C,kEAAuC;AACvC,kDAAuB;AACvB,mDAAwB;AACxB,iEAAsC;AACtC,wDAA6B;AAC7B,iEAAsC;AACtC,oDAAyB","sourcesContent":["export * from './migrations'\nexport * from './initializers/naming-strategy'\nexport * from './initializers/database'\nexport * from './utils'\nexport * from './pubsub'\nexport * from './pubsub-log-transport'\nexport * from './middlewares'\nexport * from './graphql-local-client'\nexport * from './service'\n"]}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { DataSource, EntityTarget, Repository } from 'typeorm';
|
2
|
+
export declare function getDataSource(name?: string): DataSource;
|
3
|
+
export declare function addDataSource(name: string, dataSource: DataSource): void;
|
4
|
+
export declare function removeDataSource(name: string): void;
|
5
|
+
export declare function getDataSourceNames(): string[];
|
6
|
+
export declare function getRepository<X>(target: EntityTarget<X>): Repository<X>;
|
7
|
+
export declare const databaseInitializer: () => Promise<void>;
|
@@ -1,9 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.databaseInitializer = void 0;
|
4
|
-
const path = require('path');
|
3
|
+
exports.databaseInitializer = exports.getRepository = exports.getDataSourceNames = exports.removeDataSource = exports.addDataSource = exports.getDataSource = void 0;
|
5
4
|
const typeorm_1 = require("typeorm");
|
6
5
|
const env_1 = require("@things-factory/env");
|
6
|
+
const path = require('path');
|
7
7
|
var ormconfig;
|
8
8
|
try {
|
9
9
|
ormconfig = require(path.resolve(env_1.appRootPath, 'ormconfig'));
|
@@ -11,16 +11,47 @@ try {
|
|
11
11
|
catch (e) {
|
12
12
|
ormconfig = require('@things-factory/shell/ormconfig');
|
13
13
|
}
|
14
|
+
const dataSources = {};
|
15
|
+
function getDataSource(name) {
|
16
|
+
return dataSources[name || 'default'];
|
17
|
+
}
|
18
|
+
exports.getDataSource = getDataSource;
|
19
|
+
function addDataSource(name, dataSource) {
|
20
|
+
dataSources[name] = dataSource;
|
21
|
+
}
|
22
|
+
exports.addDataSource = addDataSource;
|
23
|
+
function removeDataSource(name) {
|
24
|
+
delete dataSources[name];
|
25
|
+
}
|
26
|
+
exports.removeDataSource = removeDataSource;
|
27
|
+
function getDataSourceNames() {
|
28
|
+
return Object.keys(dataSources);
|
29
|
+
}
|
30
|
+
exports.getDataSourceNames = getDataSourceNames;
|
31
|
+
function getRepository(target) {
|
32
|
+
return getDataSource('default').getRepository(target);
|
33
|
+
}
|
34
|
+
exports.getRepository = getRepository;
|
14
35
|
const databaseInitializer = async () => {
|
15
36
|
try {
|
16
|
-
const
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
await
|
37
|
+
const readConnectionConfig = env_1.config.get('ormconfig');
|
38
|
+
const dataSource = await (0, typeorm_1.createConnection)(Object.assign(Object.assign({}, ormconfig), readConnectionConfig));
|
39
|
+
addDataSource('default', dataSource);
|
40
|
+
env_1.logger.info('Default DataSource established');
|
41
|
+
if (readConnectionConfig.type == 'sqlite' && readConnectionConfig.synchronize == false) {
|
42
|
+
await dataSource.query('PRAGMA foreign_keys=OFF');
|
43
|
+
await dataSource.synchronize();
|
44
|
+
await dataSource.query('PRAGMA foreign_keys=ON');
|
45
|
+
}
|
46
|
+
if (env_1.config.get('ormconfig4Tx')) {
|
47
|
+
const dataSource4Tx = new typeorm_1.DataSource(Object.assign(Object.assign({}, ormconfig), env_1.config.get('ormconfig4Tx')));
|
48
|
+
dataSource4Tx.initialize();
|
49
|
+
addDataSource('tx', dataSource4Tx);
|
50
|
+
env_1.logger.info('Transaction DataSource established');
|
51
|
+
}
|
52
|
+
else {
|
53
|
+
addDataSource('tx', dataSource);
|
22
54
|
}
|
23
|
-
return connection;
|
24
55
|
}
|
25
56
|
catch (e) {
|
26
57
|
env_1.logger.error(e);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../server/initializers/database.ts"],"names":[],"mappings":";;;AAAA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAE5B,
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../server/initializers/database.ts"],"names":[],"mappings":";;;AAAA,qCAAgF;AAEhF,6CAAiE;AAEjE,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAE5B,IAAI,SAAS,CAAA;AACb,IAAI;IACF,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,iBAAW,EAAE,WAAW,CAAC,CAAC,CAAA;CAC5D;AAAC,OAAO,CAAC,EAAE;IACV,SAAS,GAAG,OAAO,CAAC,iCAAiC,CAAC,CAAA;CACvD;AAED,MAAM,WAAW,GAAmC,EAAE,CAAA;AAEtD,SAAgB,aAAa,CAAC,IAAa;IACzC,OAAO,WAAW,CAAC,IAAI,IAAI,SAAS,CAAC,CAAA;AACvC,CAAC;AAFD,sCAEC;AAED,SAAgB,aAAa,CAAC,IAAY,EAAE,UAAsB;IAChE,WAAW,CAAC,IAAI,CAAC,GAAG,UAAU,CAAA;AAChC,CAAC;AAFD,sCAEC;AAED,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,OAAO,WAAW,CAAC,IAAI,CAAC,CAAA;AAC1B,CAAC;AAFD,4CAEC;AAED,SAAgB,kBAAkB;IAChC,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;AACjC,CAAC;AAFD,gDAEC;AAED,SAAg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Path, config, logger } from '@things-factory/env'\n\nconst path = require('path')\n\nvar ormconfig\ntry {\n ormconfig = require(path.resolve(appRootPath, 'ormconfig'))\n} catch (e) {\n ormconfig = require('@things-factory/shell/ormconfig')\n}\n\nconst dataSources: { [name: string]: DataSource } = {}\n\nexport function getDataSource(name?: string): DataSource {\n return dataSources[name || 'default']\n}\n\nexport function addDataSource(name: string, dataSource: DataSource) {\n dataSources[name] = dataSource\n}\n\nexport function removeDataSource(name: string) {\n delete dataSources[name]\n}\n\nexport function getDataSourceNames() {\n return Object.keys(dataSources)\n}\n\nexport function getRepository<X>(target: EntityTarget<X>): Repository<X> {\n return getDataSource('default').getRepository<X>(target)\n}\n\nexport const databaseInitializer = async () => {\n try {\n const readConnectionConfig = config.get('ormconfig')\n\n const dataSource = await createConnection({\n ...ormconfig,\n ...readConnectionConfig\n })\n\n addDataSource('default', dataSource)\n\n logger.info('Default DataSource established')\n\n if (readConnectionConfig.type == 'sqlite' && readConnectionConfig.synchronize == false) {\n await dataSource.query('PRAGMA foreign_keys=OFF')\n await dataSource.synchronize()\n await dataSource.query('PRAGMA foreign_keys=ON')\n }\n\n if (config.get('ormconfig4Tx')) {\n const dataSource4Tx = new DataSource({\n ...ormconfig,\n ...config.get('ormconfig4Tx')\n })\n dataSource4Tx.initialize()\n addDataSource('tx', dataSource4Tx)\n\n logger.info('Transaction DataSource established')\n } else {\n addDataSource('tx', dataSource)\n }\n } catch (e) {\n logger.error(e)\n }\n}\n"]}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { NamingStrategyInterface } from 'typeorm';
|
2
|
+
import { DefaultNamingStrategy } from 'typeorm';
|
3
|
+
export declare class NamingStrategy extends DefaultNamingStrategy implements NamingStrategyInterface {
|
4
|
+
tableName(targetName: string, userSpecifiedName: string): string;
|
5
|
+
columnName(propertyName: string, customName: string, embeddedPrefixes: string[]): string;
|
6
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function domainMiddleware(context: any, next: any): Promise<any>;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.SeedDomain1000000000000 = void 0;
|
4
|
-
const
|
4
|
+
const database_1 = require("../initializers/database");
|
5
5
|
const domain_1 = require("../service/domain/domain");
|
6
6
|
const SEED_DOMAINS = [
|
7
7
|
{
|
@@ -12,15 +12,15 @@ const SEED_DOMAINS = [
|
|
12
12
|
];
|
13
13
|
class SeedDomain1000000000000 {
|
14
14
|
async up(queryRunner) {
|
15
|
-
const repository = (0,
|
15
|
+
const repository = (0, database_1.getRepository)(domain_1.Domain);
|
16
16
|
return await Promise.all(SEED_DOMAINS.map(async (domain) => {
|
17
17
|
await repository.save(Object.assign({}, domain));
|
18
18
|
}));
|
19
19
|
}
|
20
20
|
async down(queryRunner) {
|
21
|
-
const repository = (0,
|
21
|
+
const repository = (0, database_1.getRepository)(domain_1.Domain);
|
22
22
|
return await Promise.all(SEED_DOMAINS.reverse().map(async (domain) => {
|
23
|
-
let recode = await repository.
|
23
|
+
let recode = await repository.findOneBy({ subdomain: domain.subdomain });
|
24
24
|
await repository.remove(recode);
|
25
25
|
}));
|
26
26
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"1000000000000-SeedDomain.js","sourceRoot":"","sources":["../../server/migrations/1000000000000-SeedDomain.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"1000000000000-SeedDomain.js","sourceRoot":"","sources":["../../server/migrations/1000000000000-SeedDomain.ts"],"names":[],"mappings":";;;AAEA,uDAAwD;AACxD,qDAAiD;AAEjD,MAAM,YAAY,GAAG;IACnB;QACE,IAAI,EAAE,QAAQ;QACd,SAAS,EAAE,QAAQ;QACnB,UAAU,EAAE,IAAI;KACjB;CACF,CAAA;AAED,MAAa,uBAAuB;IAC3B,KAAK,CAAC,EAAE,CAAC,WAAwB;QACtC,MAAM,UAAU,GAAG,IAAA,wBAAa,EAAC,eAAM,CAAC,CAAA;QAExC,OAAO,MAAM,OAAO,CAAC,GAAG,CACtB,YAAY,CAAC,GAAG,CAAC,KAAK,EAAC,MAAM,EAAC,EAAE;YAC9B,MAAM,UAAU,CAAC,IAAI,mBAChB,MAAM,EACT,CAAA;QACJ,CAAC,CAAC,CACH,CAAA;IACH,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,WAAwB;QACxC,MAAM,UAAU,GAAG,IAAA,wBAAa,EAAC,eAAM,CAAC,CAAA;QAExC,OAAO,MAAM,OAAO,CAAC,GAAG,CACtB,YAAY,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,KAAK,EAAC,MAAM,EAAC,EAAE;YACxC,IAAI,MAAM,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAA;YACxE,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QACjC,CAAC,CAAC,CACH,CAAA;IACH,CAAC;CACF;AAvBD,0DAuBC","sourcesContent":["import { MigrationInterface, QueryRunner } from 'typeorm'\n\nimport { getRepository } from '../initializers/database'\nimport { Domain } from '../service/domain/domain'\n\nconst SEED_DOMAINS = [\n {\n name: 'SYSTEM',\n subdomain: 'system',\n systemFlag: true\n }\n]\n\nexport class SeedDomain1000000000000 implements MigrationInterface {\n public async up(queryRunner: QueryRunner): Promise<any> {\n const repository = getRepository(Domain)\n\n return await Promise.all(\n SEED_DOMAINS.map(async domain => {\n await repository.save({\n ...domain\n })\n })\n )\n }\n\n public async down(queryRunner: QueryRunner): Promise<any> {\n const repository = getRepository(Domain)\n\n return await Promise.all(\n SEED_DOMAINS.reverse().map(async domain => {\n let recode = await repository.findOneBy({ subdomain: domain.subdomain })\n await repository.remove(recode)\n })\n )\n }\n}\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare var migrations: any[];
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -91,11 +91,16 @@ const bootstrap = async () => {
|
|
91
91
|
return ctx['context'];
|
92
92
|
},
|
93
93
|
onConnect: async (ctx) => {
|
94
|
+
var _a;
|
94
95
|
var { extra, connectionParams } = ctx;
|
95
96
|
var { request } = extra;
|
96
|
-
|
97
|
-
|
98
|
-
|
97
|
+
if ((_a = (connectionParams['headers'] || connectionParams)) === null || _a === void 0 ? void 0 : _a.referer) {
|
98
|
+
var url = new URL((connectionParams['headers'] || connectionParams).referer);
|
99
|
+
var accessToken = url.searchParams.get('access_token');
|
100
|
+
if (accessToken) {
|
101
|
+
connectionParams['headers']['authorization'] = accessToken;
|
102
|
+
}
|
103
|
+
}
|
99
104
|
request.headers = Object.assign(Object.assign({}, request.headers), (connectionParams['headers'] || connectionParams));
|
100
105
|
var koacontext = await app.createContext(request, {});
|
101
106
|
koacontext['state'] = {};
|
@@ -129,13 +134,11 @@ const bootstrap = async () => {
|
|
129
134
|
return ctx;
|
130
135
|
}
|
131
136
|
},
|
137
|
+
csrfPrevention: true,
|
132
138
|
plugins: [
|
133
|
-
|
134
|
-
settings: {
|
135
|
-
'request.credentials': 'same-origin'
|
136
|
-
}
|
137
|
-
}),
|
139
|
+
// Proper shutdown for the HTTP server.
|
138
140
|
(0, apollo_server_core_1.ApolloServerPluginDrainHttpServer)({ httpServer }),
|
141
|
+
// Proper shutdown for the WebSocket server.
|
139
142
|
{
|
140
143
|
async serverWillStart() {
|
141
144
|
return {
|
@@ -144,7 +147,10 @@ const bootstrap = async () => {
|
|
144
147
|
}
|
145
148
|
};
|
146
149
|
}
|
147
|
-
}
|
150
|
+
},
|
151
|
+
(0, apollo_server_core_1.ApolloServerPluginLandingPageLocalDefault)({
|
152
|
+
embed: true
|
153
|
+
})
|
148
154
|
],
|
149
155
|
cache: 'bounded'
|
150
156
|
});
|
@@ -177,9 +183,7 @@ const bootstrap = async () => {
|
|
177
183
|
});
|
178
184
|
app.use((0, koa_bodyparser_1.default)(bodyParserOption));
|
179
185
|
app.use((0, graphqlUploadKoa_js_1.default)(fileUploadOption));
|
180
|
-
|
181
|
-
path: '/graphql'
|
182
|
-
}));
|
186
|
+
server.applyMiddleware({ app, path: '/graphql' });
|
183
187
|
/* routers */
|
184
188
|
process.emit('bootstrap-module-global-public-route', app, routers_1.globalPublicRouter);
|
185
189
|
process.emit('bootstrap-module-global-private-route', app, routers_1.globalPrivateRouter);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"server-dev.js","sourceRoot":"","sources":["../server/server-dev.ts"],"names":[],"mappings":";AAAA,4BAA4B;;;AAE5B,4DAA4D;AAC5D,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,aAAa,CAAA;AACpC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;AAE1B,2DAAsH;AACtH,yDAAgD;AAChD,0DAA+B;AAC/B,qGAAiE;AACjE,8CAAiD;AACjD,+BAAmC;AACnC,sDAAqB;AACrB,4EAA0C;AAC1C,4DAAuB;AACvB,oEAAkC;AAClC,sEAAiC;AACjC,yFAAsE;AACtE,2BAAoC;AACpC,oDAAmB;AAEnB,gFAA8C;AAC9C,6DAA4B;AAC5B,6CAAgF;AAEhF,iEAA2D;AAC3D,sDAA6D;AAC7D,uCAA4G;AAC5G,qCAAiC;AAEjC,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,KAAK,CAAC,EAAE;IACtC,YAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAEnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAC,CAAA;AAEF,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAE5B,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,2CAA2C,EAAE,YAAM,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAA;AAC1F,IAAI,CAAC,MAAM,CACT,SAAS,EACT;kGACgG,EAChG,YAAM,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAC/B,CAAA;AAED,MAAM,KAAK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jC,GAAG,CAAC,6BAAmB,CAAC,cAAc,EAAE,CAAC;SACzC,GAAG,CAAC,4BAAkB,CAAC,MAAM,EAAE,CAAC;SAChC,GAAG,CAAC,4BAAkB,CAAC,cAAc,EAAE,CAAC;SACxC,GAAG,CAAC,6BAAmB,CAAC,MAAM,EAAE,CAAC;SACjC,GAAG,CAAC,6BAAmB,CAAC,cAAc,EAAE,CAAC,CAAA;IAE5C,oFAAoF;IACpF,GAAG,CAAC,GAAG,CAAC,IAAA,sDAAkB,EAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;IAE9C,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;IAEnB,GAAG,CAAC,GAAG,CACL,IAAA,oBAAS,EAAC,QAAQ,CAAC,UAAU,EAAE;QAC7B,KAAK,EAAE,KAAK;KACb,CAAC,CACH,CAAA;IAED,UAAU,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE;QACrC,YAAM,CAAC,IAAI,CAAC,qCAAqC,IAAI,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC,CAAA;QAC7E,YAAM,CAAC,IAAI,CAAC,0CAA0C,IAAI,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC,CAAA;QAElF,OAAO,CAAC,IAAI,CAAC,wBAA+B,EAAE,EAAE,GAAG,EAAE,MAAM,EAAN,YAAM,EAAE,WAAW,EAAE,UAAU,EAAS,CAAC,CAAA;IAChG,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,SAAS,EAAE,CAAA","sourcesContent":["// ts-import-sorter: disable\n\n/* following 2 lines should be located in top of the file */\nprocess.env.NODE_ENV = 'development'\nprocess.setMaxListeners(0)\n\nimport { ApolloServerPluginDrainHttpServer, ApolloServerPluginLandingPageGraphQLPlayground } from 'apollo-server-core'\nimport { ApolloServer } from 'apollo-server-koa'\nimport bytesFormat from 'bytes'\nimport graphqlUploadKoa from 'graphql-upload/graphqlUploadKoa.js'\nimport { useServer } from 'graphql-ws/lib/use/ws'\nimport { createServer } from 'http'\nimport Koa from 'koa'\nimport koaBodyParser from 'koa-bodyparser'\nimport ip from 'koa-ip'\nimport koaStatic from 'koa-static'\nimport compose from 'koa-compose'\nimport { historyApiFallback } from 'koa2-connect-history-api-fallback'\nimport { WebSocketServer } from 'ws'\nimport co from 'co'\n\nimport koaWebpack from '@hatiolab/koa-webpack'\nimport cors from '@koa/cors'\nimport { config, loader, logger, orderedModuleNames } from '@things-factory/env'\n\nimport { GraphqlLocalClient } from './graphql-local-client'\nimport { databaseInitializer } from './initializers/database'\nimport { domainPrivateRouter, domainPublicRouter, globalPrivateRouter, globalPublicRouter } from './routers'\nimport { schema } from './schema'\n\nprocess.on('uncaughtException', error => {\n logger.error(error)\n\n process.exit(1)\n})\n\nconst args = require('args')\n\nargs.option('port', 'The port on which the app will be running', config.get('port', 3000))\nargs.option(\n 'inspect',\n `The address on which the inspection will be running. Used in development mode only.\n This option is just to prevent termination for reasons of not recognizing the 'inspect' option.`,\n config.get('inspect', ':9229')\n)\n\nconst flags = args.parse(process.argv)\n\nconst path = require('path')\nconst webpack = require('webpack')\nconst webpackConfig = require('@things-factory/builder/webpack.config.dev.js')\n\nconst compiler = webpack(webpackConfig)\n\nconst PORT = (process.env.PORT = flags.port)\n\nconst requestBody = config.get('requestBody') || {}\n\nconst bodyParserOption = {\n formLimit: requestBody.formLimit || '10mb',\n jsonLimit: requestBody.jsonLimit || '10mb',\n textLimit: requestBody.textLimit || '10mb'\n}\n\nconst fileUpload = config.get('fileUpload') || {}\nconst fileUploadOption = {\n maxFileSize: bytesFormat.parse(fileUpload.maxFileSize) || bytesFormat.parse('10mb'),\n maxFiles: fileUpload.maxFiles || 10\n}\n\n/* bootstrap */\nconst bootstrap = async () => {\n await databaseInitializer()\n\n const app = new Koa()\n\n app.use(\n cors({\n origin: function (ctx) {\n return ctx.request.headers.origin || '*'\n },\n exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'],\n maxAge: 5,\n credentials: true,\n /* allowMethods: ['GET', 'POST', 'DELETE'], -- use default */\n allowHeaders: ['Content-Type', 'Authorization', 'Accept']\n })\n )\n\n const whitelist = config.get('whitelist')\n const blacklist = config.get('blacklist')\n\n if (whitelist || blacklist) {\n app.use(\n ip({\n whitelist,\n blacklist,\n handler: async (ctx, next) => {\n ctx.status = 403\n }\n })\n )\n }\n\n var subscriptionMiddleware = []\n process.emit('bootstrap-module-subscription' as any, app, subscriptionMiddleware)\n\n const builtSchema = await schema()\n\n const httpServer = createServer(app.callback())\n const websocketServer = new WebSocketServer({\n server: httpServer,\n path: '/graphql'\n })\n\n // Save the returned server's info so we can shut down this server later\n const serverCleanup = useServer(\n {\n schema: builtSchema,\n context: async (ctx, msg, args) => {\n return ctx['context']\n },\n onConnect: async ctx => {\n var { extra, connectionParams } = ctx\n var { request } = extra\n\n var url = new URL(((connectionParams['headers'] as any) || connectionParams).referer)\n var accessToken = url.searchParams.get('access_token')\n connectionParams['headers']['authorization'] = accessToken\n\n request.headers = {\n ...request.headers,\n ...(connectionParams['headers'] || (connectionParams as any))\n }\n\n var koacontext = await app.createContext(request, {} as any)\n koacontext['state'] = {}\n\n /* in case connect error(like a authentication error) just throw exception */\n var middlewares = [...subscriptionMiddleware]\n const fn = co.wrap(compose(middlewares))\n\n await fn(koacontext)\n\n return (ctx['context'] = koacontext)\n },\n onDisconnect(ctx, code, reason) {\n console.log('Disconnected!')\n },\n onError(ctx, msg, errors) {\n console.error(msg, errors)\n }\n },\n websocketServer\n )\n\n const server = new ApolloServer({\n schema: builtSchema,\n formatError: error => {\n logger.error(error)\n return error\n },\n formatResponse: response => {\n return response\n },\n context: async ({ connection, ctx }) => {\n if (connection) {\n return connection.context\n } else {\n return ctx\n }\n },\n plugins: [\n ApolloServerPluginLandingPageGraphQLPlayground({\n settings: {\n 'request.credentials': 'same-origin'\n }\n }),\n ApolloServerPluginDrainHttpServer({ httpServer }),\n {\n async serverWillStart() {\n return {\n async drainServer() {\n await serverCleanup.dispose()\n }\n }\n }\n }\n ],\n cache: 'bounded'\n })\n\n await server.start()\n\n GraphqlLocalClient.init(builtSchema, app)\n\n orderedModuleNames.forEach(name => {\n const { initMiddlewares } = loader(name)\n initMiddlewares && initMiddlewares(app)\n })\n\n const render = require('@things-factory/ejs-remote')\n render(app, {\n root: '/views',\n host: `http://127.0.0.1:${PORT}`,\n layout: false,\n viewExt: 'html',\n cache: false,\n debug: false\n })\n\n const middleware = await koaWebpack({\n compiler,\n hotClient: {},\n devMiddleware: {\n publicPath: webpackConfig.output.publicPath,\n stats: { colors: true }\n }\n })\n\n // only for development mode. triggered after webpack compilation is done.\n compiler.hooks.done.tap({ name: 'server-dev' }, stats => {\n process.emit('client-rebuilt' as any, app, compiler.outputFileSystem)\n })\n\n app.use(koaBodyParser(bodyParserOption))\n app.use(graphqlUploadKoa(fileUploadOption))\n\n app.use(\n server.getMiddleware({\n path: '/graphql'\n })\n )\n\n /* routers */\n process.emit('bootstrap-module-global-public-route' as any, app, globalPublicRouter)\n process.emit('bootstrap-module-global-private-route' as any, app, globalPrivateRouter)\n process.emit('bootstrap-module-domain-public-route' as any, app, domainPublicRouter)\n process.emit('bootstrap-module-domain-private-route' as any, app, domainPrivateRouter)\n\n app\n .use(globalPublicRouter.routes())\n .use(globalPublicRouter.allowedMethods())\n .use(globalPrivateRouter.routes())\n .use(globalPrivateRouter.allowedMethods())\n .use(domainPublicRouter.routes())\n .use(domainPublicRouter.allowedMethods())\n .use(domainPrivateRouter.routes())\n .use(domainPrivateRouter.allowedMethods())\n\n /* should follow this order : history-fallback => webpack-middleware => koaStatic */\n app.use(historyApiFallback({ whiteList: [] }))\n\n app.use(middleware)\n\n app.use(\n koaStatic(compiler.outputPath, {\n index: false\n })\n )\n\n httpServer.listen({ port: PORT }, () => {\n logger.info(`🚀 Server ready at http://0.0.0.0:${PORT}${server.graphqlPath}`)\n logger.info(`🚀 Subscriptions ready at ws://0.0.0.0:${PORT}${server.graphqlPath}`)\n\n process.emit('bootstrap-module-start' as any, { app, config, builtSchema, httpServer } as any)\n })\n}\n\nbootstrap()\n"]}
|
1
|
+
{"version":3,"file":"server-dev.js","sourceRoot":"","sources":["../server/server-dev.ts"],"names":[],"mappings":";AAAA,4BAA4B;;;AAE5B,4DAA4D;AAC5D,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,aAAa,CAAA;AACpC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;AAE1B,2DAAiH;AACjH,yDAAgD;AAChD,0DAA+B;AAC/B,qGAAiE;AACjE,8CAAiD;AACjD,+BAAmC;AACnC,sDAAqB;AACrB,4EAA0C;AAC1C,4DAAuB;AACvB,oEAAkC;AAClC,sEAAiC;AACjC,yFAAsE;AACtE,2BAAoC;AACpC,oDAAmB;AAEnB,gFAA8C;AAC9C,6DAA4B;AAC5B,6CAAgF;AAEhF,iEAA2D;AAC3D,sDAA6D;AAC7D,uCAA4G;AAC5G,qCAAiC;AAIjC,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,KAAK,CAAC,EAAE;IACtC,YAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAEnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAC,CAAA;AAEF,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAE5B,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,2CAA2C,EAAE,YAAM,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAA;AAC1F,IAAI,CAAC,MAAM,CACT,SAAS,EACT;kGACgG,EAChG,YAAM,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAC/B,CAAA;AAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;AAEtC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAC5B,MAAM,OAAO,GAAG,OA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ACjC,GAAG,CAAC,6BAAmB,CAAC,cAAc,EAAE,CAAC;SACzC,GAAG,CAAC,4BAAkB,CAAC,MAAM,EAAE,CAAC;SAChC,GAAG,CAAC,4BAAkB,CAAC,cAAc,EAAE,CAAC;SACxC,GAAG,CAAC,6BAAmB,CAAC,MAAM,EAAE,CAAC;SACjC,GAAG,CAAC,6BAAmB,CAAC,cAAc,EAAE,CAAC,CAAA;IAE5C,oFAAoF;IACpF,GAAG,CAAC,GAAG,CAAC,IAAA,sDAAkB,EAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;IAE9C,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;IAEnB,GAAG,CAAC,GAAG,CACL,IAAA,oBAAS,EAAC,QAAQ,CAAC,UAAU,EAAE;QAC7B,KAAK,EAAE,KAAK;KACb,CAAC,CACH,CAAA;IAED,UAAU,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE;QACrC,YAAM,CAAC,IAAI,CAAC,qCAAqC,IAAI,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC,CAAA;QAC7E,YAAM,CAAC,IAAI,CAAC,0CAA0C,IAAI,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC,CAAA;QAElF,OAAO,CAAC,IAAI,CAAC,wBAA+B,EAAE,EAAE,GAAG,EAAE,MAAM,EAAN,YAAM,EAAE,WAAW,EAAE,UAAU,EAAS,CAAC,CAAA;IAChG,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,SAAS,EAAE,CAAA","sourcesContent":["// ts-import-sorter: disable\n\n/* following 2 lines should be located in top of the file */\nprocess.env.NODE_ENV = 'development'\nprocess.setMaxListeners(0)\n\nimport { ApolloServerPluginDrainHttpServer, ApolloServerPluginLandingPageLocalDefault } from 'apollo-server-core'\nimport { ApolloServer } from 'apollo-server-koa'\nimport bytesFormat from 'bytes'\nimport graphqlUploadKoa from 'graphql-upload/graphqlUploadKoa.js'\nimport { useServer } from 'graphql-ws/lib/use/ws'\nimport { createServer } from 'http'\nimport Koa from 'koa'\nimport koaBodyParser from 'koa-bodyparser'\nimport ip from 'koa-ip'\nimport koaStatic from 'koa-static'\nimport compose from 'koa-compose'\nimport { historyApiFallback } from 'koa2-connect-history-api-fallback'\nimport { WebSocketServer } from 'ws'\nimport co from 'co'\n\nimport koaWebpack from '@hatiolab/koa-webpack'\nimport cors from '@koa/cors'\nimport { config, loader, logger, orderedModuleNames } from '@things-factory/env'\n\nimport { GraphqlLocalClient } from './graphql-local-client'\nimport { databaseInitializer } from './initializers/database'\nimport { domainPrivateRouter, domainPublicRouter, globalPrivateRouter, globalPublicRouter } from './routers'\nimport { schema } from './schema'\nimport { Domain } from './service'\nimport { EntityManager } from 'typeorm'\n\nprocess.on('uncaughtException', error => {\n logger.error(error)\n\n process.exit(1)\n})\n\nconst args = require('args')\n\nargs.option('port', 'The port on which the app will be running', config.get('port', 3000))\nargs.option(\n 'inspect',\n `The address on which the inspection will be running. Used in development mode only.\n This option is just to prevent termination for reasons of not recognizing the 'inspect' option.`,\n config.get('inspect', ':9229')\n)\n\nconst flags = args.parse(process.argv)\n\nconst path = require('path')\nconst webpack = require('webpack')\nconst webpackConfig = require('@things-factory/builder/webpack.config.dev.js')\n\nconst compiler = webpack(webpackConfig)\n\nconst PORT = (process.env.PORT = flags.port)\n\nconst requestBody = config.get('requestBody') || {}\n\nconst bodyParserOption = {\n formLimit: requestBody.formLimit || '10mb',\n jsonLimit: requestBody.jsonLimit || '10mb',\n textLimit: requestBody.textLimit || '10mb'\n}\n\nconst fileUpload = config.get('fileUpload') || {}\nconst fileUploadOption = {\n maxFileSize: bytesFormat.parse(fileUpload.maxFileSize) || bytesFormat.parse('10mb'),\n maxFiles: fileUpload.maxFiles || 10\n}\n\ninterface ICustomAppState {\n domain: Domain\n user: any\n tx: EntityManager\n}\n\ninterface ICustomAppContext {\n t: any\n}\n\n/* bootstrap */\nconst bootstrap = async () => {\n await databaseInitializer()\n\n const app = new Koa<ICustomAppState, ICustomAppContext>()\n\n app.use(\n cors({\n origin: function (ctx) {\n return ctx.request.headers.origin || '*'\n },\n exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'],\n maxAge: 5,\n credentials: true,\n /* allowMethods: ['GET', 'POST', 'DELETE'], -- use default */\n allowHeaders: ['Content-Type', 'Authorization', 'Accept']\n })\n )\n\n const whitelist = config.get('whitelist')\n const blacklist = config.get('blacklist')\n\n if (whitelist || blacklist) {\n app.use(\n ip({\n whitelist,\n blacklist,\n handler: async (ctx, next) => {\n ctx.status = 403\n }\n })\n )\n }\n\n var subscriptionMiddleware = []\n process.emit('bootstrap-module-subscription' as any, app, subscriptionMiddleware)\n\n const builtSchema = await schema()\n\n const httpServer = createServer(app.callback())\n const websocketServer = new WebSocketServer({\n server: httpServer,\n path: '/graphql'\n })\n\n // Save the returned server's info so we can shut down this server later\n const serverCleanup = useServer(\n {\n schema: builtSchema,\n context: async (ctx, msg, args) => {\n return ctx['context']\n },\n onConnect: async ctx => {\n var { extra, connectionParams } = ctx\n var { request } = extra\n\n if (((connectionParams['headers'] as any) || connectionParams)?.referer) {\n var url = new URL(((connectionParams['headers'] as any) || connectionParams).referer)\n var accessToken = url.searchParams.get('access_token')\n if (accessToken) {\n connectionParams['headers']['authorization'] = accessToken\n }\n }\n\n request.headers = {\n ...request.headers,\n ...(connectionParams['headers'] || (connectionParams as any))\n }\n\n var koacontext = await app.createContext(request, {} as any)\n koacontext['state'] = {}\n\n /* in case connect error(like a authentication error) just throw exception */\n var middlewares = [...subscriptionMiddleware]\n const fn = co.wrap(compose(middlewares))\n\n await fn(koacontext)\n\n return (ctx['context'] = koacontext)\n },\n onDisconnect(ctx, code, reason) {\n console.log('Disconnected!')\n },\n onError(ctx, msg, errors) {\n console.error(msg, errors)\n }\n },\n websocketServer\n )\n\n const server = new ApolloServer({\n schema: builtSchema,\n formatError: error => {\n logger.error(error)\n return error\n },\n formatResponse: response => {\n return response\n },\n context: async ({ connection, ctx }) => {\n if (connection) {\n return connection.context\n } else {\n return ctx\n }\n },\n csrfPrevention: true,\n plugins: [\n // Proper shutdown for the HTTP server.\n ApolloServerPluginDrainHttpServer({ httpServer }),\n // Proper shutdown for the WebSocket server.\n {\n async serverWillStart() {\n return {\n async drainServer() {\n await serverCleanup.dispose()\n }\n }\n }\n },\n ApolloServerPluginLandingPageLocalDefault({\n embed: true\n })\n ],\n cache: 'bounded'\n })\n\n await server.start()\n\n GraphqlLocalClient.init(builtSchema, app)\n\n orderedModuleNames.forEach(name => {\n const { initMiddlewares } = loader(name)\n initMiddlewares && initMiddlewares(app)\n })\n\n const render = require('@things-factory/ejs-remote')\n render(app, {\n root: '/views',\n host: `http://127.0.0.1:${PORT}`,\n layout: false,\n viewExt: 'html',\n cache: false,\n debug: false\n })\n\n const middleware = await koaWebpack({\n compiler,\n hotClient: {},\n devMiddleware: {\n publicPath: webpackConfig.output.publicPath,\n stats: { colors: true }\n }\n })\n\n // only for development mode. triggered after webpack compilation is done.\n compiler.hooks.done.tap({ name: 'server-dev' }, stats => {\n process.emit('client-rebuilt' as any, app, compiler.outputFileSystem)\n })\n\n app.use(koaBodyParser(bodyParserOption))\n app.use(graphqlUploadKoa(fileUploadOption))\n\n server.applyMiddleware({ app, path: '/graphql' })\n\n /* routers */\n process.emit('bootstrap-module-global-public-route' as any, app, globalPublicRouter)\n process.emit('bootstrap-module-global-private-route' as any, app, globalPrivateRouter)\n process.emit('bootstrap-module-domain-public-route' as any, app, domainPublicRouter)\n process.emit('bootstrap-module-domain-private-route' as any, app, domainPrivateRouter)\n\n app\n .use(globalPublicRouter.routes())\n .use(globalPublicRouter.allowedMethods())\n .use(globalPrivateRouter.routes())\n .use(globalPrivateRouter.allowedMethods())\n .use(domainPublicRouter.routes())\n .use(domainPublicRouter.allowedMethods())\n .use(domainPrivateRouter.routes())\n .use(domainPrivateRouter.allowedMethods())\n\n /* should follow this order : history-fallback => webpack-middleware => koaStatic */\n app.use(historyApiFallback({ whiteList: [] }))\n\n app.use(middleware)\n\n app.use(\n koaStatic(compiler.outputPath, {\n index: false\n })\n )\n\n httpServer.listen({ port: PORT }, () => {\n logger.info(`🚀 Server ready at http://0.0.0.0:${PORT}${server.graphqlPath}`)\n logger.info(`🚀 Subscriptions ready at ws://0.0.0.0:${PORT}${server.graphqlPath}`)\n\n process.emit('bootstrap-module-start' as any, { app, config, builtSchema, httpServer } as any)\n })\n}\n\nbootstrap()\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/dist-server/server.js
CHANGED
@@ -85,11 +85,16 @@ const bootstrap = async () => {
|
|
85
85
|
return ctx['context'];
|
86
86
|
},
|
87
87
|
onConnect: async (ctx) => {
|
88
|
+
var _a;
|
88
89
|
var { extra, connectionParams } = ctx;
|
89
90
|
var { request } = extra;
|
90
|
-
|
91
|
-
|
92
|
-
|
91
|
+
if ((_a = (connectionParams['headers'] || connectionParams)) === null || _a === void 0 ? void 0 : _a.referer) {
|
92
|
+
var url = new URL((connectionParams['headers'] || connectionParams).referer);
|
93
|
+
var accessToken = url.searchParams.get('access_token');
|
94
|
+
if (accessToken) {
|
95
|
+
connectionParams['headers']['authorization'] = accessToken;
|
96
|
+
}
|
97
|
+
}
|
93
98
|
request.headers = Object.assign(Object.assign({}, request.headers), (connectionParams['headers'] || connectionParams));
|
94
99
|
var koacontext = await app.createContext(request, {});
|
95
100
|
koacontext['state'] = {};
|
@@ -156,9 +161,7 @@ const bootstrap = async () => {
|
|
156
161
|
});
|
157
162
|
app.use((0, koa_bodyparser_1.default)(bodyParserOption));
|
158
163
|
app.use((0, graphqlUploadKoa_js_1.default)(fileUploadOption));
|
159
|
-
|
160
|
-
path: '/graphql'
|
161
|
-
}));
|
164
|
+
server.applyMiddleware({ app, path: '/graphql' });
|
162
165
|
/* routers */
|
163
166
|
process.emit('bootstrap-module-global-public-route', app, routers_1.globalPublicRouter);
|
164
167
|
process.emit('bootstrap-module-global-private-route', app, routers_1.globalPrivateRouter);
|