@griffin-app/griffin-cli 1.0.8 → 1.0.10

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.
@@ -0,0 +1,25 @@
1
+ import * as path from "path";
2
+ import { glob } from "glob";
3
+ /**
4
+ * Discovers test files in __griffin__ directories.
5
+ */
6
+ export function findTestFiles(basePath = ".") {
7
+ const absolutePath = path.resolve(basePath);
8
+ // Find all __griffin__ directories
9
+ const griffinDirs = findgriffinDirectories(absolutePath);
10
+ // Find all .ts files in those directories
11
+ const testFiles = [];
12
+ for (const griffinDir of griffinDirs) {
13
+ const tsFiles = findTsFiles(griffinDir);
14
+ testFiles.push(...tsFiles);
15
+ }
16
+ return testFiles;
17
+ }
18
+ function findgriffinDirectories(basePath) {
19
+ const pattern = path.join(basePath, "**", "__griffin__");
20
+ return glob.sync(pattern, { absolute: true });
21
+ }
22
+ function findTsFiles(griffinDir) {
23
+ const pattern = path.join(griffinDir, "*.ts");
24
+ return glob.sync(pattern, { absolute: true });
25
+ }
@@ -0,0 +1,6 @@
1
+ import "tsx";
2
+ import { ExecutionResult } from "@griffin-app/griffin-plan-executor";
3
+ /**
4
+ * Runs a TypeScript test file and executes the resulting JSON monitor.
5
+ */
6
+ export declare function runTestFile(filePath: string, envName: string): Promise<ExecutionResult>;
@@ -0,0 +1,56 @@
1
+ import "tsx";
2
+ import { Value } from "typebox/value";
3
+ import { executeMonitorV1, AxiosAdapter, } from "@griffin-app/griffin-plan-executor";
4
+ import { MonitorDSLSchema } from "@griffin-app/griffin-ts/schema";
5
+ import { randomUUID } from "crypto";
6
+ import { loadVariables } from "./core/variables.js";
7
+ import { getProjectId } from "./core/state.js";
8
+ import { resolveMonitor } from "./resolve.js";
9
+ import { terminal } from "./utils/terminal.js";
10
+ import { createSecretsProviderForCLI } from "./core/secrets.js";
11
+ function validateDsl(monitor) {
12
+ const errors = Value.Errors(MonitorDSLSchema, monitor);
13
+ if (errors.length > 0) {
14
+ throw new Error(`Invalid monitor: ${JSON.stringify([...errors], null, 2)}`);
15
+ }
16
+ return monitor;
17
+ }
18
+ /**
19
+ * Runs a TypeScript test file and executes the resulting JSON monitor.
20
+ */
21
+ export async function runTestFile(filePath, envName) {
22
+ const variables = await loadVariables(envName);
23
+ const projectId = await getProjectId();
24
+ const defaultExport = await import(filePath);
25
+ const rawMonitor = validateDsl(defaultExport.default);
26
+ terminal.dim(`Project ID: ${projectId}`);
27
+ const resolvedMonitor = resolveMonitor(rawMonitor, projectId, envName, variables);
28
+ // Create secret provider from environment configuration
29
+ const secretProvider = await createSecretsProviderForCLI();
30
+ try {
31
+ const result = await executeMonitorV1({
32
+ ...resolvedMonitor,
33
+ id: randomUUID(),
34
+ }, "default-org", {
35
+ mode: "local",
36
+ httpClient: new AxiosAdapter(),
37
+ secretProvider,
38
+ });
39
+ return result;
40
+ }
41
+ catch (error) {
42
+ throw new Error(`Error executing monitor: ${error instanceof Error ? error.message : String(error)}`);
43
+ }
44
+ }
45
+ //function findWorkspaceRoot(): string {
46
+ // let current = process.cwd();
47
+ // while (current !== path.dirname(current)) {
48
+ // const testCliPath = path.join(current, "griffin-cli");
49
+ // const testSystemPath = path.join(current, "griffin-ts");
50
+ // if (fs.existsSync(testCliPath) && fs.existsSync(testSystemPath)) {
51
+ // return current;
52
+ // }
53
+ // current = path.dirname(current);
54
+ // }
55
+ // return process.cwd();
56
+ //}
@@ -1,16 +1,12 @@
1
1
  import { Type, type Static } from "typebox";
2
- /**
3
- * State file schema for tracking project configuration
4
- * Stored in .griffin/state.json
5
- *
6
- * Note: The hub is now the source of truth for monitors.
7
- * This file only stores configuration (project, environments, runner connection).
8
- */
9
2
  export declare const EnvironmentConfigSchema: Type.TObject<{}>;
10
3
  export type EnvironmentConfig = Static<typeof EnvironmentConfigSchema>;
4
+ export declare const CloudConfigSchema: Type.TObject<{
5
+ authUrl: Type.TString;
6
+ }>;
11
7
  export declare const HubConfigSchema: Type.TObject<{
12
8
  baseUrl: Type.TString;
13
- clientId: Type.TString;
9
+ clientId: Type.TOptional<Type.TString>;
14
10
  }>;
15
11
  export type HubConfig = Static<typeof HubConfigSchema>;
16
12
  export declare const DiscoveryConfigSchema: Type.TObject<{
@@ -18,15 +14,22 @@ export declare const DiscoveryConfigSchema: Type.TObject<{
18
14
  ignore: Type.TOptional<Type.TArray<Type.TString>>;
19
15
  }>;
20
16
  export type DiscoveryConfig = Static<typeof DiscoveryConfigSchema>;
17
+ export declare const EnvironmentsConfigSchema: Type.TIntersect<[Type.TObject<{
18
+ default: Type.TObject<{}>;
19
+ }>, Type.TRecord<"^.*$", Type.TObject<{}>>]>;
21
20
  export declare const StateFileSchema: Type.TObject<{
22
21
  stateVersion: Type.TLiteral<1>;
23
22
  projectId: Type.TString;
24
- environments: Type.TRecord<"^.*$", Type.TObject<{}>>;
25
- defaultEnvironment: Type.TOptional<Type.TString>;
26
- hub: Type.TOptional<Type.TObject<{
23
+ environments: Type.TIntersect<[Type.TObject<{
24
+ default: Type.TObject<{}>;
25
+ }>, Type.TRecord<"^.*$", Type.TObject<{}>>]>;
26
+ hub: Type.TObject<{
27
27
  baseUrl: Type.TString;
28
- clientId: Type.TString;
29
- }>>;
28
+ clientId: Type.TOptional<Type.TString>;
29
+ }>;
30
+ cloud: Type.TObject<{
31
+ authUrl: Type.TString;
32
+ }>;
30
33
  discovery: Type.TOptional<Type.TObject<{
31
34
  pattern: Type.TOptional<Type.TString>;
32
35
  ignore: Type.TOptional<Type.TArray<Type.TString>>;
@@ -37,7 +40,3 @@ export type StateFile = Static<typeof StateFileSchema>;
37
40
  * Create an empty state file
38
41
  */
39
42
  export declare function createEmptyState(projectId: string): StateFile;
40
- /**
41
- * Create state file with a default local environment
42
- */
43
- export declare function createStateWithDefaultEnv(projectId: string): StateFile;
@@ -6,24 +6,35 @@ import { Type } from "typebox";
6
6
  * Note: The hub is now the source of truth for monitors.
7
7
  * This file only stores configuration (project, environments, runner connection).
8
8
  */
9
+ const authUrl = "https://www.getgriffinapp.com/api/auth";
10
+ const hubBaseUrl = "https://griffin-hub.fly.dev";
9
11
  export const EnvironmentConfigSchema = Type.Object({});
12
+ export const CloudConfigSchema = Type.Object({
13
+ authUrl: Type.String(),
14
+ });
10
15
  export const HubConfigSchema = Type.Object({
11
16
  baseUrl: Type.String(),
12
- clientId: Type.String(),
17
+ clientId: Type.Optional(Type.String()),
13
18
  });
14
19
  export const DiscoveryConfigSchema = Type.Object({
15
20
  pattern: Type.Optional(Type.String()),
16
21
  ignore: Type.Optional(Type.Array(Type.String())),
17
22
  });
23
+ export const EnvironmentsConfigSchema = Type.Intersect([
24
+ Type.Object({
25
+ default: EnvironmentConfigSchema,
26
+ }),
27
+ Type.Record(Type.String(), EnvironmentConfigSchema),
28
+ ]);
18
29
  // State schema (hub is source of truth for monitors)
19
30
  export const StateFileSchema = Type.Object({
20
31
  stateVersion: Type.Literal(1),
21
32
  projectId: Type.String(),
22
33
  // Environment configuration
23
- environments: Type.Record(Type.String(), EnvironmentConfigSchema),
24
- defaultEnvironment: Type.Optional(Type.String()),
34
+ environments: EnvironmentsConfigSchema,
25
35
  // Hub connection (for remote execution)
26
- hub: Type.Optional(HubConfigSchema),
36
+ hub: HubConfigSchema,
37
+ cloud: CloudConfigSchema,
27
38
  // Discovery settings
28
39
  discovery: Type.Optional(DiscoveryConfigSchema),
29
40
  });
@@ -31,22 +42,17 @@ export const StateFileSchema = Type.Object({
31
42
  * Create an empty state file
32
43
  */
33
44
  export function createEmptyState(projectId) {
34
- return {
35
- stateVersion: 1,
36
- projectId,
37
- environments: {},
38
- };
39
- }
40
- /**
41
- * Create state file with a default local environment
42
- */
43
- export function createStateWithDefaultEnv(projectId) {
44
45
  return {
45
46
  stateVersion: 1,
46
47
  projectId,
47
48
  environments: {
48
- local: {},
49
+ default: {},
50
+ },
51
+ hub: {
52
+ baseUrl: hubBaseUrl,
53
+ },
54
+ cloud: {
55
+ authUrl: authUrl,
49
56
  },
50
- defaultEnvironment: "local",
51
57
  };
52
58
  }
@@ -1,12 +1,13 @@
1
1
  import "tsx";
2
2
  import { Value } from "typebox/value";
3
- import { executeMonitorV1, AxiosAdapter, EnvSecretProvider, SecretProviderRegistry, } from "@griffin-app/griffin-plan-executor";
3
+ import { executeMonitorV1, AxiosAdapter, } from "@griffin-app/griffin-plan-executor";
4
4
  import { MonitorDSLSchema } from "@griffin-app/griffin-ts/schema";
5
5
  import { randomUUID } from "crypto";
6
6
  import { loadVariables } from "./core/variables.js";
7
7
  import { getProjectId } from "./core/state.js";
8
8
  import { resolveMonitor } from "./resolve.js";
9
9
  import { terminal } from "./utils/terminal.js";
10
+ import { createSecretsProviderForCLI } from "./core/secrets.js";
10
11
  function validateDsl(monitor) {
11
12
  const errors = Value.Errors(MonitorDSLSchema, monitor);
12
13
  if (errors.length > 0) {
@@ -24,8 +25,8 @@ export async function runTestFile(filePath, envName) {
24
25
  const rawMonitor = validateDsl(defaultExport.default);
25
26
  terminal.dim(`Project ID: ${projectId}`);
26
27
  const resolvedMonitor = resolveMonitor(rawMonitor, projectId, envName, variables);
27
- const secretRegistry = new SecretProviderRegistry();
28
- secretRegistry.register(new EnvSecretProvider());
28
+ // Create secret provider from environment configuration
29
+ const secretProvider = await createSecretsProviderForCLI();
29
30
  try {
30
31
  const result = await executeMonitorV1({
31
32
  ...resolvedMonitor,
@@ -33,7 +34,7 @@ export async function runTestFile(filePath, envName) {
33
34
  }, "default-org", {
34
35
  mode: "local",
35
36
  httpClient: new AxiosAdapter(),
36
- secretRegistry: secretRegistry,
37
+ secretProvider,
37
38
  });
38
39
  return result;
39
40
  }
@@ -109,8 +109,6 @@ export async function withSDKErrorHandling(fn, context) {
109
109
  return await fn();
110
110
  }
111
111
  catch (error) {
112
- console.error("error");
113
- console.error(error);
114
112
  handleSDKError(error, context);
115
113
  }
116
114
  }
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@griffin-app/griffin-cli",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "CLI tool for running and managing griffin API tests",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "bin": {
8
- "griffin": "./dist/cli.js"
8
+ "griffin": "./dist/cli.js",
9
+ "gr": "./dist/cli.js"
9
10
  },
10
11
  "scripts": {
11
12
  "build": "tsc",
@@ -23,9 +24,9 @@
23
24
  "author": "",
24
25
  "license": "MIT",
25
26
  "dependencies": {
26
- "@griffin-app/griffin-hub-sdk": "1.0.8",
27
- "@griffin-app/griffin-plan-executor": "0.1.14",
28
- "@griffin-app/griffin-ts": "0.1.14",
27
+ "@griffin-app/griffin-hub-sdk": "1.0.13",
28
+ "@griffin-app/griffin-plan-executor": "0.1.18",
29
+ "@griffin-app/griffin-ts": "0.1.16",
29
30
  "better-auth": "^1.4.17",
30
31
  "cli-table3": "^0.6.5",
31
32
  "commander": "^12.1.0",