@constructive-io/graphql-server 3.1.1 → 4.0.0
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/errors/404-message.js +1 -1
- package/errors/api-errors.d.ts +200 -0
- package/errors/api-errors.js +276 -0
- package/esm/errors/404-message.js +1 -1
- package/esm/errors/api-errors.js +261 -0
- package/esm/index.js +2 -0
- package/esm/middleware/api.js +355 -277
- package/esm/middleware/auth.js +25 -7
- package/esm/middleware/error-handler.js +86 -0
- package/esm/middleware/favicon.js +12 -0
- package/esm/middleware/graphile.js +149 -64
- package/esm/options.js +232 -0
- package/esm/schema.js +24 -11
- package/esm/server.js +41 -5
- package/index.d.ts +1 -0
- package/index.js +2 -0
- package/middleware/api.d.ts +3 -15
- package/middleware/api.js +359 -283
- package/middleware/auth.js +25 -7
- package/middleware/error-handler.d.ts +4 -0
- package/middleware/error-handler.js +94 -0
- package/middleware/favicon.d.ts +2 -0
- package/middleware/favicon.js +16 -0
- package/middleware/graphile.d.ts +14 -0
- package/middleware/graphile.js +149 -64
- package/options.d.ts +131 -0
- package/options.js +244 -0
- package/package.json +23 -24
- package/schema.d.ts +2 -2
- package/schema.js +23 -10
- package/server.d.ts +24 -2
- package/server.js +39 -3
- package/codegen/orm/client.d.ts +0 -55
- package/codegen/orm/client.js +0 -75
- package/codegen/orm/index.d.ts +0 -36
- package/codegen/orm/index.js +0 -59
- package/codegen/orm/input-types.d.ts +0 -20140
- package/codegen/orm/input-types.js +0 -2
- package/codegen/orm/models/api.d.ts +0 -42
- package/codegen/orm/models/api.js +0 -76
- package/codegen/orm/models/domain.d.ts +0 -42
- package/codegen/orm/models/domain.js +0 -76
- package/codegen/orm/models/index.d.ts +0 -7
- package/codegen/orm/models/index.js +0 -12
- package/codegen/orm/mutation/index.d.ts +0 -7
- package/codegen/orm/mutation/index.js +0 -7
- package/codegen/orm/query/index.d.ts +0 -20
- package/codegen/orm/query/index.js +0 -24
- package/codegen/orm/query-builder.d.ts +0 -81
- package/codegen/orm/query-builder.js +0 -496
- package/codegen/orm/select-types.d.ts +0 -83
- package/codegen/orm/select-types.js +0 -7
- package/codegen/orm/types.d.ts +0 -6
- package/codegen/orm/types.js +0 -23
- package/esm/codegen/orm/client.js +0 -70
- package/esm/codegen/orm/index.js +0 -39
- package/esm/codegen/orm/input-types.js +0 -1
- package/esm/codegen/orm/models/api.js +0 -72
- package/esm/codegen/orm/models/domain.js +0 -72
- package/esm/codegen/orm/models/index.js +0 -7
- package/esm/codegen/orm/mutation/index.js +0 -4
- package/esm/codegen/orm/query/index.js +0 -21
- package/esm/codegen/orm/query-builder.js +0 -452
- package/esm/codegen/orm/select-types.js +0 -6
- package/esm/codegen/orm/types.js +0 -7
- package/esm/middleware/gql.js +0 -116
- package/esm/plugins/PublicKeySignature.js +0 -114
- package/esm/scripts/codegen-schema.js +0 -71
- package/esm/scripts/create-bucket.js +0 -40
- package/middleware/gql.d.ts +0 -164
- package/middleware/gql.js +0 -121
- package/plugins/PublicKeySignature.d.ts +0 -11
- package/plugins/PublicKeySignature.js +0 -121
- package/scripts/codegen-schema.d.ts +0 -1
- package/scripts/codegen-schema.js +0 -76
- package/scripts/create-bucket.d.ts +0 -1
- package/scripts/create-bucket.js +0 -42
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PublicKeySignature = void 0;
|
|
7
|
-
const graphile_utils_1 = require("graphile-utils");
|
|
8
|
-
const pg_query_context_1 = __importDefault(require("pg-query-context"));
|
|
9
|
-
const PublicKeySignature = (pubkey_challenge) => {
|
|
10
|
-
const { schema, crypto_network, sign_up_with_key, sign_in_request_challenge, sign_in_record_failure, sign_in_with_challenge } = pubkey_challenge;
|
|
11
|
-
return (0, graphile_utils_1.makeExtendSchemaPlugin)(() => ({
|
|
12
|
-
typeDefs: (0, graphile_utils_1.gql) `
|
|
13
|
-
input CreateUserAccountWithPublicKeyInput {
|
|
14
|
-
publicKey: String!
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
input GetMessageForSigningInput {
|
|
18
|
-
publicKey: String!
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
input VerifyMessageForSigningInput {
|
|
22
|
-
publicKey: String!
|
|
23
|
-
message: String!
|
|
24
|
-
signature: String!
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
type createUserAccountWithPublicKeyPayload {
|
|
28
|
-
message: String!
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
type getMessageForSigningPayload {
|
|
32
|
-
message: String!
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
type verifyMessageForSigningPayload {
|
|
36
|
-
access_token: String!
|
|
37
|
-
access_token_expires_at: Datetime!
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
extend type Mutation {
|
|
41
|
-
createUserAccountWithPublicKey(
|
|
42
|
-
input: CreateUserAccountWithPublicKeyInput
|
|
43
|
-
): createUserAccountWithPublicKeyPayload
|
|
44
|
-
|
|
45
|
-
getMessageForSigning(
|
|
46
|
-
input: GetMessageForSigningInput
|
|
47
|
-
): getMessageForSigningPayload
|
|
48
|
-
|
|
49
|
-
verifyMessageForSigning(
|
|
50
|
-
input: VerifyMessageForSigningInput
|
|
51
|
-
): verifyMessageForSigningPayload
|
|
52
|
-
}
|
|
53
|
-
`,
|
|
54
|
-
resolvers: {
|
|
55
|
-
Mutation: {
|
|
56
|
-
async createUserAccountWithPublicKey(_parent, args, context) {
|
|
57
|
-
const { pgClient } = context;
|
|
58
|
-
const { publicKey } = args.input;
|
|
59
|
-
await (0, pg_query_context_1.default)({
|
|
60
|
-
client: pgClient,
|
|
61
|
-
context: { role: 'anonymous' },
|
|
62
|
-
query: `SELECT * FROM "${schema}".${sign_up_with_key}($1)`,
|
|
63
|
-
variables: [publicKey]
|
|
64
|
-
});
|
|
65
|
-
const { rows: [{ [sign_in_request_challenge]: message }] } = await (0, pg_query_context_1.default)({
|
|
66
|
-
client: pgClient,
|
|
67
|
-
context: { role: 'anonymous' },
|
|
68
|
-
query: `SELECT * FROM "${schema}".${sign_in_request_challenge}($1)`,
|
|
69
|
-
variables: [publicKey]
|
|
70
|
-
});
|
|
71
|
-
return { message };
|
|
72
|
-
},
|
|
73
|
-
async getMessageForSigning(_parent, args, context) {
|
|
74
|
-
const { pgClient } = context;
|
|
75
|
-
const { publicKey } = args.input;
|
|
76
|
-
const { rows: [{ [sign_in_request_challenge]: message }] } = await (0, pg_query_context_1.default)({
|
|
77
|
-
client: pgClient,
|
|
78
|
-
context: { role: 'anonymous' },
|
|
79
|
-
query: `SELECT * FROM "${schema}".${sign_in_request_challenge}($1)`,
|
|
80
|
-
variables: [publicKey]
|
|
81
|
-
});
|
|
82
|
-
if (!message)
|
|
83
|
-
throw new Error('NO_ACCOUNT_EXISTS');
|
|
84
|
-
return { message };
|
|
85
|
-
},
|
|
86
|
-
async verifyMessageForSigning(_parent, args, context) {
|
|
87
|
-
const { pgClient } = context;
|
|
88
|
-
const { publicKey, message, signature } = args.input;
|
|
89
|
-
// const network = Networks[crypto_network];
|
|
90
|
-
const network = 'btc';
|
|
91
|
-
// const result = verifyMessage(message, publicKey, signature, network);
|
|
92
|
-
// TODO implement using interchainJS?
|
|
93
|
-
const result = false;
|
|
94
|
-
if (!result) {
|
|
95
|
-
await (0, pg_query_context_1.default)({
|
|
96
|
-
client: pgClient,
|
|
97
|
-
context: { role: 'anonymous' },
|
|
98
|
-
query: `SELECT * FROM "${schema}".${sign_in_record_failure}($1)`,
|
|
99
|
-
variables: [publicKey]
|
|
100
|
-
});
|
|
101
|
-
throw new Error('BAD_SIGNIN');
|
|
102
|
-
}
|
|
103
|
-
const { rows: [token] } = await (0, pg_query_context_1.default)({
|
|
104
|
-
client: pgClient,
|
|
105
|
-
context: { role: 'anonymous' },
|
|
106
|
-
query: `SELECT * FROM "${schema}".${sign_in_with_challenge}($1, $2)`,
|
|
107
|
-
variables: [publicKey, message]
|
|
108
|
-
});
|
|
109
|
-
if (!token?.access_token)
|
|
110
|
-
throw new Error('BAD_SIGNIN');
|
|
111
|
-
return {
|
|
112
|
-
access_token: token.access_token,
|
|
113
|
-
access_token_expires_at: token.access_token_expires_at
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}));
|
|
119
|
-
};
|
|
120
|
-
exports.PublicKeySignature = PublicKeySignature;
|
|
121
|
-
exports.default = exports.PublicKeySignature;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const graphql_env_1 = require("@constructive-io/graphql-env");
|
|
7
|
-
const logger_1 = require("@pgpmjs/logger");
|
|
8
|
-
const graphile_settings_1 = require("graphile-settings");
|
|
9
|
-
const pg_cache_1 = require("pg-cache");
|
|
10
|
-
const graphile_query_1 = require("graphile-query");
|
|
11
|
-
const graphql_1 = require("graphql");
|
|
12
|
-
const node_fs_1 = require("node:fs");
|
|
13
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
14
|
-
const log = new logger_1.Logger('codegen-schema');
|
|
15
|
-
const getSchemaOutputPath = () => process.env.CODEGEN_SCHEMA_OUT ??
|
|
16
|
-
node_path_1.default.resolve(__dirname, '../../codegen/schema.graphql');
|
|
17
|
-
(async () => {
|
|
18
|
-
try {
|
|
19
|
-
const opts = (0, graphql_env_1.getEnvOptions)();
|
|
20
|
-
const apiOpts = opts.api || {};
|
|
21
|
-
const metaSchemas = Array.isArray(apiOpts.metaSchemas)
|
|
22
|
-
? apiOpts.metaSchemas
|
|
23
|
-
: [];
|
|
24
|
-
let schemas;
|
|
25
|
-
let usingFallback = false;
|
|
26
|
-
const dbName = process.env.CODEGEN_DATABASE || process.env.PGDATABASE || 'constructive';
|
|
27
|
-
const pgConfig = { ...opts.pg, database: dbName };
|
|
28
|
-
log.info(`Target database for codegen: ${dbName}`);
|
|
29
|
-
if (metaSchemas.length) {
|
|
30
|
-
schemas = metaSchemas;
|
|
31
|
-
log.info(`Using meta schemas: ${schemas.join(', ')}`);
|
|
32
|
-
const pool = (0, pg_cache_1.getPgPool)(pgConfig);
|
|
33
|
-
const checkResult = await pool.query(`SELECT schema_name FROM information_schema.schemata
|
|
34
|
-
WHERE schema_name = ANY($1::text[])
|
|
35
|
-
ORDER BY schema_name`, [schemas]);
|
|
36
|
-
const foundSchemas = checkResult.rows.map((r) => r.schema_name);
|
|
37
|
-
const missing = schemas.filter((s) => !foundSchemas.includes(s));
|
|
38
|
-
if (missing.length > 0) {
|
|
39
|
-
log.warn(`Missing schemas: ${missing.join(', ')}. Falling back to 'public'.`);
|
|
40
|
-
schemas = ['public'];
|
|
41
|
-
usingFallback = true;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
schemas = ['public'];
|
|
46
|
-
log.info('No meta schemas configured, using: public');
|
|
47
|
-
usingFallback = true;
|
|
48
|
-
}
|
|
49
|
-
if (usingFallback) {
|
|
50
|
-
log.warn('Schema will be generated from public schema only. To generate full meta schema, ensure meta tables exist.');
|
|
51
|
-
}
|
|
52
|
-
const settings = (0, graphile_settings_1.getGraphileSettings)({
|
|
53
|
-
...opts,
|
|
54
|
-
pg: pgConfig,
|
|
55
|
-
graphile: {
|
|
56
|
-
...opts.graphile,
|
|
57
|
-
schema: schemas,
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
const pool = (0, pg_cache_1.getPgPool)(pgConfig);
|
|
61
|
-
log.debug(`Connecting to database: ${dbName}`);
|
|
62
|
-
log.debug(`Connecting to host: ${opts.pg?.host || '(default)'}`);
|
|
63
|
-
const dbInfo = await pool.query('SELECT current_database() AS current_database, current_user AS current_user');
|
|
64
|
-
log.info(`Connected to database: ${dbInfo.rows[0]?.current_database} as user: ${dbInfo.rows[0]?.current_user}`);
|
|
65
|
-
const graphqlSchema = await (0, graphile_query_1.getSchema)(pool, settings);
|
|
66
|
-
const sdl = (0, graphql_1.printSchema)(graphqlSchema);
|
|
67
|
-
const outputPath = getSchemaOutputPath();
|
|
68
|
-
await node_fs_1.promises.mkdir(node_path_1.default.dirname(outputPath), { recursive: true });
|
|
69
|
-
await node_fs_1.promises.writeFile(outputPath, sdl, 'utf8');
|
|
70
|
-
log.success(`Schema written to ${outputPath}`);
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
log.error('Failed to write schema', error?.stack || error);
|
|
74
|
-
process.exitCode = 1;
|
|
75
|
-
}
|
|
76
|
-
})();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/scripts/create-bucket.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Minimal script to create a bucket in MinIO/S3 using @constructive-io/s3-utils
|
|
3
|
-
// Avoid strict type coupling between different @aws-sdk/client-s3 versions
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
6
|
-
const s3_utils_1 = require("@constructive-io/s3-utils");
|
|
7
|
-
const graphql_env_1 = require("@constructive-io/graphql-env");
|
|
8
|
-
const logger_1 = require("@pgpmjs/logger");
|
|
9
|
-
const log = new logger_1.Logger('create-bucket');
|
|
10
|
-
(async () => {
|
|
11
|
-
try {
|
|
12
|
-
const opts = (0, graphql_env_1.getEnvOptions)();
|
|
13
|
-
const { cdn } = opts;
|
|
14
|
-
const provider = cdn?.provider || 'minio';
|
|
15
|
-
const isMinio = provider === 'minio';
|
|
16
|
-
const bucket = cdn?.bucketName || 'test-bucket';
|
|
17
|
-
const region = cdn?.awsRegion || 'us-east-1';
|
|
18
|
-
const accessKey = cdn?.awsAccessKey || 'minioadmin';
|
|
19
|
-
const secretKey = cdn?.awsSecretKey || 'minioadmin';
|
|
20
|
-
const endpoint = cdn?.minioEndpoint || 'http://localhost:9000';
|
|
21
|
-
const client = new client_s3_1.S3Client({
|
|
22
|
-
region,
|
|
23
|
-
credentials: { accessKeyId: accessKey, secretAccessKey: secretKey },
|
|
24
|
-
...(isMinio ? {
|
|
25
|
-
endpoint,
|
|
26
|
-
forcePathStyle: true,
|
|
27
|
-
} : {}),
|
|
28
|
-
});
|
|
29
|
-
const res = await (0, s3_utils_1.createS3Bucket)(client, bucket, { provider });
|
|
30
|
-
if (res.success) {
|
|
31
|
-
log.success(`${bucket} (provider: ${provider})`);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
log.error(`Failed to create bucket ${bucket}`);
|
|
35
|
-
}
|
|
36
|
-
client.destroy();
|
|
37
|
-
}
|
|
38
|
-
catch (e) {
|
|
39
|
-
log.error('error', e);
|
|
40
|
-
process.exitCode = 1;
|
|
41
|
-
}
|
|
42
|
-
})();
|