@sortlist/cli 0.36.0 → 0.37.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/bin/sl.mjs +20 -7
- package/dist/index.js +1579 -0
- package/dist/index.js.map +1 -0
- package/package.json +8 -7
- package/src/codegen.ts +0 -34
- package/src/commands/config.ts +0 -95
- package/src/commands/dynamic.test.ts +0 -87
- package/src/commands/dynamic.ts +0 -569
- package/src/commands/login.ts +0 -155
- package/src/commands/logout.ts +0 -45
- package/src/commands/token.ts +0 -23
- package/src/commands/whoami.ts +0 -55
- package/src/graphql/client.ts +0 -259
- package/src/graphql/generated/gql.ts +0 -70
- package/src/graphql/generated/graphql.ts +0 -4757
- package/src/graphql/generated/index.ts +0 -1
- package/src/graphql/introspection.ts +0 -240
- package/src/graphql/operations/common.ts +0 -16
- package/src/graphql/operations/hermes.ts +0 -54
- package/src/graphql/query-builder.test.ts +0 -114
- package/src/graphql/query-builder.ts +0 -239
- package/src/index.ts +0 -186
- package/src/lib/auth.test.ts +0 -30
- package/src/lib/auth.ts +0 -58
- package/src/lib/browser.ts +0 -11
- package/src/lib/company.ts +0 -15
- package/src/lib/config.ts +0 -80
- package/src/lib/env.ts +0 -10
- package/src/lib/output.ts +0 -58
- package/src/lib/sentry.ts +0 -70
- package/src/lib/version-check.ts +0 -88
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sortlist/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"description": "Sortlist platform CLI — GraphQL federation client",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"bin/",
|
|
17
|
-
"
|
|
18
|
-
"codegen.ts",
|
|
17
|
+
"dist/",
|
|
19
18
|
".published"
|
|
20
19
|
],
|
|
21
20
|
"scripts": {
|
|
22
21
|
"codegen": "graphql-codegen --config src/codegen.ts",
|
|
23
22
|
"generate": "npm run codegen",
|
|
23
|
+
"build": "tsup",
|
|
24
24
|
"type-check": "tsc --noEmit",
|
|
25
25
|
"test": "vitest run",
|
|
26
26
|
"lint": "eslint . --ext .ts,.tsx,.js,.cjs --quiet",
|
|
@@ -29,16 +29,15 @@
|
|
|
29
29
|
"prepare": "[ -n \"$CI\" ] && exit 0; command -v git >/dev/null 2>&1 && git config --unset core.hooksPath || true; command -v lefthook >/dev/null 2>&1 && lefthook install || true"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@graphql-codegen/cli": "^6.2.1",
|
|
33
|
-
"@graphql-codegen/client-preset": "^5.2.4",
|
|
34
32
|
"@graphql-typed-document-node/core": "^3.2.0",
|
|
35
33
|
"@sentry/node": "^10.29.0",
|
|
36
34
|
"commander": "^13.0.0",
|
|
37
|
-
"graphql": "^16.13.2"
|
|
38
|
-
"tsx": "^4.19.0"
|
|
35
|
+
"graphql": "^16.13.2"
|
|
39
36
|
},
|
|
40
37
|
"devDependencies": {
|
|
41
38
|
"@commitlint/config-conventional": "^18.6.1",
|
|
39
|
+
"@graphql-codegen/cli": "^6.2.1",
|
|
40
|
+
"@graphql-codegen/client-preset": "^5.2.4",
|
|
42
41
|
"@ianvs/prettier-plugin-sort-imports": "^4.1.1",
|
|
43
42
|
"@types/node": "^22.10.0",
|
|
44
43
|
"@typescript-eslint/eslint-plugin": "^8.13.0",
|
|
@@ -53,6 +52,8 @@
|
|
|
53
52
|
"eslint-plugin-sonarjs": "^0.24.0",
|
|
54
53
|
"lefthook": "^1.11.5",
|
|
55
54
|
"prettier": "^3.5.3",
|
|
55
|
+
"tsup": "^8.5.1",
|
|
56
|
+
"tsx": "^4.19.0",
|
|
56
57
|
"typescript": "^5.7.0",
|
|
57
58
|
"vitest": "^4.1.10"
|
|
58
59
|
}
|
package/src/codegen.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
3
|
-
|
|
4
|
-
// Schema resolution: SUPERGRAPH_PATH env → ../backend/supergraph.graphql
|
|
5
|
-
function resolveSchema(): string {
|
|
6
|
-
if (process.env.SUPERGRAPH_PATH && fs.existsSync(process.env.SUPERGRAPH_PATH)) {
|
|
7
|
-
return process.env.SUPERGRAPH_PATH;
|
|
8
|
-
}
|
|
9
|
-
const local = '../../backend/supergraph.graphql';
|
|
10
|
-
if (fs.existsSync(local)) return local;
|
|
11
|
-
throw new Error('Supergraph not found. Set SUPERGRAPH_PATH or ensure ../backend/supergraph.graphql exists.');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const config: CodegenConfig = {
|
|
15
|
-
overwrite: true,
|
|
16
|
-
schema: resolveSchema(),
|
|
17
|
-
documents: ['src/graphql/operations/*.ts'],
|
|
18
|
-
emitLegacyCommonJSImports: false,
|
|
19
|
-
generates: {
|
|
20
|
-
'src/graphql/generated/': {
|
|
21
|
-
preset: 'client',
|
|
22
|
-
config: {
|
|
23
|
-
useTypeImports: true,
|
|
24
|
-
enumsAsTypes: true,
|
|
25
|
-
},
|
|
26
|
-
presetConfig: {
|
|
27
|
-
gqlTagName: 'gql',
|
|
28
|
-
fragmentMasking: false,
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export default config;
|
package/src/commands/config.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
|
|
3
|
-
import { clearCredentials } from '../lib/auth.ts';
|
|
4
|
-
import { loadConfig, resetConfig, saveConfig } from '../lib/config.ts';
|
|
5
|
-
import { isLocalDev } from '../lib/env.ts';
|
|
6
|
-
import { error, hint, info, isJsonMode, printJson, success } from '../lib/output.ts';
|
|
7
|
-
|
|
8
|
-
const PRODUCTION_ENDPOINT = 'https://federation.sortlist.com/graphql';
|
|
9
|
-
const STAGING_ENDPOINT = 'https://federation.sortlist-test.com/graphql';
|
|
10
|
-
const LOCAL_ENDPOINT = 'http://localhost:4020/graphql';
|
|
11
|
-
|
|
12
|
-
export const configCommand = new Command('config')
|
|
13
|
-
.summary('View or update CLI configuration')
|
|
14
|
-
.description(
|
|
15
|
-
'View or update CLI configuration\n\n' +
|
|
16
|
-
'Manage your company context and credentials.\n\n' +
|
|
17
|
-
'Examples:\n' +
|
|
18
|
-
' sl config show See current endpoint and company\n' +
|
|
19
|
-
(isLocalDev ? ' sl config set endpoint <url> Point to a custom endpoint\n' : '') +
|
|
20
|
-
' sl config reset Clear all config and credentials',
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
configCommand
|
|
24
|
-
.command('show')
|
|
25
|
-
.description('Show current configuration')
|
|
26
|
-
.action(function (this: Command) {
|
|
27
|
-
const opts = this.optsWithGlobals();
|
|
28
|
-
const config = loadConfig();
|
|
29
|
-
if (isJsonMode(opts)) {
|
|
30
|
-
printJson(config);
|
|
31
|
-
} else {
|
|
32
|
-
info(`Endpoint: ${config.endpoint}`);
|
|
33
|
-
if (config.oauthId) info(`User: ${config.oauthId}`);
|
|
34
|
-
if (config.companyId) info(`Company ID: ${config.companyId}`);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
configCommand
|
|
39
|
-
.command('set <key> <value>')
|
|
40
|
-
.description(`Set a config value (${isLocalDev ? 'endpoint, ' : ''}companyId)`)
|
|
41
|
-
.action((key: string, value: string) => {
|
|
42
|
-
// `endpoint` is dev-only — published builds always target production, so the
|
|
43
|
-
// endpoint must not be overridable there (mirrors the gated use-* commands).
|
|
44
|
-
const allowed = [...(isLocalDev ? ['endpoint'] : []), 'companyId', 'oauthId'];
|
|
45
|
-
if (!allowed.includes(key)) {
|
|
46
|
-
error(`Unknown config key: "${key}".`);
|
|
47
|
-
info('');
|
|
48
|
-
info(' Allowed keys:');
|
|
49
|
-
for (const k of allowed) {
|
|
50
|
-
info(` ${k}`);
|
|
51
|
-
}
|
|
52
|
-
hint('Usage: sl config set <key> <value>');
|
|
53
|
-
process.exit(1);
|
|
54
|
-
}
|
|
55
|
-
saveConfig({ [key]: value });
|
|
56
|
-
success(`Set ${key} = ${value}`);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
if (isLocalDev) {
|
|
60
|
-
configCommand
|
|
61
|
-
.command('use-production')
|
|
62
|
-
.description('Point CLI to production (federation.sortlist.com)')
|
|
63
|
-
.action(() => {
|
|
64
|
-
saveConfig({ endpoint: PRODUCTION_ENDPOINT });
|
|
65
|
-
success(`Endpoint set to ${PRODUCTION_ENDPOINT}`);
|
|
66
|
-
hint('Run `sl login` to authenticate against production.');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
configCommand
|
|
70
|
-
.command('use-staging')
|
|
71
|
-
.description('Point CLI to staging (federation.sortlist-test.com)')
|
|
72
|
-
.action(() => {
|
|
73
|
-
saveConfig({ endpoint: STAGING_ENDPOINT });
|
|
74
|
-
success(`Endpoint set to ${STAGING_ENDPOINT}`);
|
|
75
|
-
hint('Run `sl login` to authenticate against staging.');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
configCommand
|
|
79
|
-
.command('use-local')
|
|
80
|
-
.description('Point CLI to local development (localhost:4020)')
|
|
81
|
-
.action(() => {
|
|
82
|
-
saveConfig({ endpoint: LOCAL_ENDPOINT });
|
|
83
|
-
success(`Endpoint set to ${LOCAL_ENDPOINT}`);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
configCommand
|
|
88
|
-
.command('reset')
|
|
89
|
-
.description('Reset all config and credentials')
|
|
90
|
-
.action(() => {
|
|
91
|
-
resetConfig();
|
|
92
|
-
clearCredentials();
|
|
93
|
-
success('Config and credentials cleared.');
|
|
94
|
-
hint('Run `sl login` to re-authenticate.');
|
|
95
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { buildSchema, GraphQLBoolean, GraphQLFloat, GraphQLInt, GraphQLString, type GraphQLInputType } from 'graphql';
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import { coerceValue, formatTypeInspection } from './dynamic.ts';
|
|
5
|
-
|
|
6
|
-
describe('coerceValue', () => {
|
|
7
|
-
it('parses Int values', () => {
|
|
8
|
-
expect(coerceValue('42', GraphQLInt, 'limit')).toBe(42);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('rejects malformed Int values', () => {
|
|
12
|
-
expect(() => coerceValue('abc', GraphQLInt, 'limit')).toThrow('--limit expects an integer, got "abc".');
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('parses Float values', () => {
|
|
16
|
-
expect(coerceValue('1.5', GraphQLFloat, 'score')).toBe(1.5);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('rejects malformed Float values', () => {
|
|
20
|
-
expect(() => coerceValue('abc', GraphQLFloat, 'score')).toThrow('--score expects a number, got "abc".');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('parses Boolean literals strictly', () => {
|
|
24
|
-
expect(coerceValue('true', GraphQLBoolean, 'archived')).toBe(true);
|
|
25
|
-
expect(coerceValue('false', GraphQLBoolean, 'archived')).toBe(false);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('rejects non-literal Boolean values', () => {
|
|
29
|
-
expect(() => coerceValue('yes', GraphQLBoolean, 'archived')).toThrow(
|
|
30
|
-
'--archived expects "true" or "false", got "yes".',
|
|
31
|
-
);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('passes plain strings through', () => {
|
|
35
|
-
expect(coerceValue('hello', GraphQLString, 'name')).toBe('hello');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('parses JSON for structured inputs', () => {
|
|
39
|
-
const schema = buildSchema(`
|
|
40
|
-
input FilterInput { country: String }
|
|
41
|
-
type Query { q(filter: FilterInput): String }
|
|
42
|
-
`);
|
|
43
|
-
const filterType = schema.getType('FilterInput') as GraphQLInputType;
|
|
44
|
-
expect(coerceValue('{"country":"BE"}', filterType, 'filter')).toEqual({ country: 'BE' });
|
|
45
|
-
expect(() => coerceValue('{oops', filterType, 'filter')).toThrow('--filter expects JSON');
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe('formatTypeInspection', () => {
|
|
50
|
-
const schema = buildSchema(`
|
|
51
|
-
"A contact filter"
|
|
52
|
-
input ContactFilterInput {
|
|
53
|
-
"Country code"
|
|
54
|
-
country: String
|
|
55
|
-
status: ContactStatus
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
enum ContactStatus {
|
|
59
|
-
ACTIVE
|
|
60
|
-
ARCHIVED
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
type Query { q(filter: ContactFilterInput): String }
|
|
64
|
-
`);
|
|
65
|
-
|
|
66
|
-
it('renders input object fields with descriptions', () => {
|
|
67
|
-
const out = formatTypeInspection(schema, 'ContactFilterInput');
|
|
68
|
-
expect(out).toContain('input ContactFilterInput — A contact filter');
|
|
69
|
-
expect(out).toContain('country: String');
|
|
70
|
-
expect(out).toContain('Country code');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('points at nested inspectable types', () => {
|
|
74
|
-
const out = formatTypeInspection(schema, 'ContactFilterInput');
|
|
75
|
-
expect(out).toContain('sl schema inspect ContactStatus');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('renders enum values', () => {
|
|
79
|
-
const out = formatTypeInspection(schema, 'ContactStatus');
|
|
80
|
-
expect(out).toContain('enum ContactStatus');
|
|
81
|
-
expect(out).toContain('ACTIVE');
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('returns null for unknown types', () => {
|
|
85
|
-
expect(formatTypeInspection(schema, 'Nope')).toBeNull();
|
|
86
|
-
});
|
|
87
|
-
});
|