@sortlist/cli 0.34.0 → 0.36.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/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@sortlist/cli",
3
- "version": "0.34.0",
3
+ "version": "0.36.0",
4
4
  "description": "Sortlist platform CLI — GraphQL federation client",
5
5
  "type": "module",
6
+ "engines": {
7
+ "node": ">=20"
8
+ },
6
9
  "publishConfig": {
7
10
  "access": "public"
8
11
  },
@@ -19,16 +22,17 @@
19
22
  "codegen": "graphql-codegen --config src/codegen.ts",
20
23
  "generate": "npm run codegen",
21
24
  "type-check": "tsc --noEmit",
25
+ "test": "vitest run",
22
26
  "lint": "eslint . --ext .ts,.tsx,.js,.cjs --quiet",
23
27
  "format": "prettier --write \"src/**/*.{ts,tsx,js,cjs,json}\"",
24
28
  "format:check": "prettier --check \"src/**/*.{ts,tsx,js,cjs,json}\"",
25
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"
26
30
  },
27
31
  "dependencies": {
28
- "@sentry/node": "^10.29.0",
29
32
  "@graphql-codegen/cli": "^6.2.1",
30
33
  "@graphql-codegen/client-preset": "^5.2.4",
31
34
  "@graphql-typed-document-node/core": "^3.2.0",
35
+ "@sentry/node": "^10.29.0",
32
36
  "commander": "^13.0.0",
33
37
  "graphql": "^16.13.2",
34
38
  "tsx": "^4.19.0"
@@ -39,7 +43,7 @@
39
43
  "@types/node": "^22.10.0",
40
44
  "@typescript-eslint/eslint-plugin": "^8.13.0",
41
45
  "@typescript-eslint/parser": "^8.13.0",
42
- "branch-name-lint": "^2.1.1",
46
+ "branch-name-lint": "^3.0.1",
43
47
  "commitlint": "^18.6.1",
44
48
  "eslint": "^8.56.0",
45
49
  "eslint-config-prettier": "^9.1.0",
@@ -49,6 +53,7 @@
49
53
  "eslint-plugin-sonarjs": "^0.24.0",
50
54
  "lefthook": "^1.11.5",
51
55
  "prettier": "^3.5.3",
52
- "typescript": "^5.7.0"
56
+ "typescript": "^5.7.0",
57
+ "vitest": "^4.1.10"
53
58
  }
54
59
  }
@@ -0,0 +1,87 @@
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
+ });
@@ -116,7 +116,7 @@ function isStructuredInput(type: GraphQLInputType): boolean {
116
116
  * enums) are parsed as JSON. Throws a readable error on malformed JSON so the
117
117
  * action can surface it instead of silently sending a bad string.
118
118
  */
119
- function coerceValue(raw: string, type: GraphQLInputType, flagName: string): unknown {
119
+ export function coerceValue(raw: string, type: GraphQLInputType, flagName: string): unknown {
120
120
  if (isStructuredInput(type)) {
121
121
  try {
122
122
  return JSON.parse(raw);
@@ -129,9 +129,22 @@ function coerceValue(raw: string, type: GraphQLInputType, flagName: string): unk
129
129
  }
130
130
 
131
131
  const typeName = unwrap(type).name;
132
- if (typeName === 'Int') return parseInt(raw, 10);
133
- if (typeName === 'Float') return parseFloat(raw);
134
- if (typeName === 'Boolean') return raw === 'true';
132
+ if (typeName === 'Int') {
133
+ const parsed = parseInt(raw, 10);
134
+ if (Number.isNaN(parsed)) throw new Error(`--${flagName} expects an integer, got "${raw}".`);
135
+ return parsed;
136
+ }
137
+ if (typeName === 'Float') {
138
+ const parsed = parseFloat(raw);
139
+ if (Number.isNaN(parsed)) throw new Error(`--${flagName} expects a number, got "${raw}".`);
140
+ return parsed;
141
+ }
142
+ if (typeName === 'Boolean') {
143
+ if (raw !== 'true' && raw !== 'false') {
144
+ throw new Error(`--${flagName} expects "true" or "false", got "${raw}".`);
145
+ }
146
+ return raw === 'true';
147
+ }
135
148
  return raw;
136
149
  }
137
150
 
@@ -131,7 +131,9 @@ async function executeQuery<T = Record<string, unknown>>(
131
131
  headers['Authorization'] = `Bearer ${creds.accessToken}`;
132
132
 
133
133
  if (verbose) {
134
- info(`[debug] JWT: ${creds.accessToken}`);
134
+ // Never print the full token — debug output ends up in pasted logs.
135
+ // `sl token` is the deliberate way to get the raw value.
136
+ info(`[debug] JWT: ...${creds.accessToken.slice(-8)}`);
135
137
  }
136
138
  }
137
139