gwirian-cli 1.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/README.md +164 -0
- package/bin/gwirian.js +3 -0
- package/dist/api.d.ts +105 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +112 -0
- package/dist/api.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +485 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +10 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +59 -0
- package/dist/config.js.map +1 -0
- package/dist/format.d.ts +16 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +118 -0
- package/dist/format.js.map +1 -0
- package/dist/runTui.d.ts +2 -0
- package/dist/runTui.d.ts.map +1 -0
- package/dist/runTui.js +20 -0
- package/dist/runTui.js.map +1 -0
- package/dist/tui/Main.d.ts +7 -0
- package/dist/tui/Main.d.ts.map +1 -0
- package/dist/tui/Main.js +105 -0
- package/dist/tui/Main.js.map +1 -0
- package/dist/tui/Setup.d.ts +2 -0
- package/dist/tui/Setup.d.ts.map +1 -0
- package/dist/tui/Setup.js +57 -0
- package/dist/tui/Setup.js.map +1 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# Gwirian CLI
|
|
2
|
+
|
|
3
|
+
CLI for the [Gwirian](https://www.gwirian.com) API, with a modern terminal (TUI) interface.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- Node.js >= 18
|
|
8
|
+
|
|
9
|
+
## Quick start (install from npm)
|
|
10
|
+
|
|
11
|
+
Install the CLI globally:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install -g gwirian-cli
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Configure your API token (get it from Gwirian: workspace → API token):
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
gwirian auth
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Optionally test the connection:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
gwirian auth --test
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Then run the TUI or any command:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
gwirian
|
|
33
|
+
# or
|
|
34
|
+
gwirian projects list
|
|
35
|
+
gwirian --help
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Installation (from source)
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
cd gwirian-cli
|
|
42
|
+
npm install
|
|
43
|
+
npm run build
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Run the binary:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm start
|
|
50
|
+
# or
|
|
51
|
+
node dist/cli.js
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
During development (no build step):
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm run dev
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Using the `gwirian` command everywhere
|
|
61
|
+
|
|
62
|
+
To run the CLI as `gwirian` (without prefixing with `node` or `npm start`):
|
|
63
|
+
|
|
64
|
+
**Development (global link)**
|
|
65
|
+
From the project root:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npm run build
|
|
69
|
+
npm link
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
After that, the `gwirian` command is available in your terminal. To remove the link: `npm unlink -g gwirian-cli`.
|
|
73
|
+
|
|
74
|
+
**Global install (permanent binary)**
|
|
75
|
+
From the project root:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npm run build
|
|
79
|
+
npm install -g .
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The `gwirian` command is then installed globally (e.g. in the same prefix as your `node`).
|
|
83
|
+
|
|
84
|
+
## Configuration
|
|
85
|
+
|
|
86
|
+
- **Token**: Generated in Gwirian (workspace member → API token). Enter it once via the TUI or the `gwirian auth` command.
|
|
87
|
+
- **Base URL**: Default `https://www.gwirian.com`. Can be changed in the TUI setup or with `gwirian config set base-url <url>`.
|
|
88
|
+
|
|
89
|
+
The config file is stored at:
|
|
90
|
+
|
|
91
|
+
- `$XDG_CONFIG_HOME/gwirian-cli/config.json` if `XDG_CONFIG_HOME` is set;
|
|
92
|
+
- otherwise `~/.config/gwirian-cli/config.json`.
|
|
93
|
+
|
|
94
|
+
The token is never displayed (including in `config get`).
|
|
95
|
+
|
|
96
|
+
## Usage
|
|
97
|
+
|
|
98
|
+
### No arguments (TUI)
|
|
99
|
+
|
|
100
|
+
In an interactive terminal:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
gwirian
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
- If no token is configured: setup form (token + base URL).
|
|
107
|
+
- Otherwise: browse projects → features → scenarios.
|
|
108
|
+
|
|
109
|
+
### Command-line commands
|
|
110
|
+
|
|
111
|
+
**Auth and configuration**
|
|
112
|
+
|
|
113
|
+
| Command | Description |
|
|
114
|
+
|---------|-------------|
|
|
115
|
+
| `gwirian auth` | Prompt for token (use `-t` / `--test` to verify connection) |
|
|
116
|
+
| `gwirian logout` | Clear stored token |
|
|
117
|
+
| `gwirian config get` | Show base URL and whether a token is set |
|
|
118
|
+
| `gwirian config set base-url <url>` | Set API base URL |
|
|
119
|
+
|
|
120
|
+
**Projects**
|
|
121
|
+
|
|
122
|
+
- `gwirian projects list`
|
|
123
|
+
- `gwirian projects show <project-id>`
|
|
124
|
+
|
|
125
|
+
**Features**
|
|
126
|
+
|
|
127
|
+
- `gwirian features list <project-id>`
|
|
128
|
+
- `gwirian features show <project-id> <feature-id>`
|
|
129
|
+
- `gwirian features create <project-id> [--title] [--description] [--tag-list]`
|
|
130
|
+
- `gwirian features update <project-id> <feature-id> [--title] [--description] [--tag-list]`
|
|
131
|
+
- `gwirian features delete <project-id> <feature-id>`
|
|
132
|
+
|
|
133
|
+
**Scenarios**
|
|
134
|
+
|
|
135
|
+
- `gwirian scenarios list <project-id> <feature-id>`
|
|
136
|
+
- `gwirian scenarios show <project-id> <feature-id> <scenario-id>`
|
|
137
|
+
- `gwirian scenarios create <project-id> <feature-id> [--title] [--given] [--when] [--then] [--position]`
|
|
138
|
+
- `gwirian scenarios update <project-id> <feature-id> <scenario-id> [...]`
|
|
139
|
+
- `gwirian scenarios delete <project-id> <feature-id> <scenario-id>`
|
|
140
|
+
|
|
141
|
+
**Scenario executions**
|
|
142
|
+
|
|
143
|
+
- `gwirian scenario-executions list <project-id> <feature-id> <scenario-id>`
|
|
144
|
+
- `gwirian scenario-executions show <project-id> <feature-id> <scenario-id> <execution-id>`
|
|
145
|
+
- `gwirian scenario-executions create <project-id> <feature-id> <scenario-id> [--status] [--notes] [--executed-at]`
|
|
146
|
+
- `gwirian scenario-executions update ...`
|
|
147
|
+
- `gwirian scenario-executions delete ...`
|
|
148
|
+
|
|
149
|
+
**Global options**
|
|
150
|
+
|
|
151
|
+
- `--base-url <url>`: Override base URL for the command.
|
|
152
|
+
- `--json`: Raw JSON output (instead of formatted tables for list/show).
|
|
153
|
+
|
|
154
|
+
Examples:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
gwirian --help
|
|
158
|
+
gwirian --json projects list
|
|
159
|
+
gwirian --base-url https://staging.gwirian.com projects list
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## License
|
|
163
|
+
|
|
164
|
+
MIT.
|
package/bin/gwirian.js
ADDED
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
export declare class TokenInvalidOrExpiredError extends Error {
|
|
2
|
+
constructor(message?: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class ApiError extends Error {
|
|
5
|
+
statusCode: number;
|
|
6
|
+
body?: unknown | undefined;
|
|
7
|
+
constructor(message: string, statusCode: number, body?: unknown | undefined);
|
|
8
|
+
}
|
|
9
|
+
export interface Project {
|
|
10
|
+
id: number;
|
|
11
|
+
name: string;
|
|
12
|
+
description: string | null;
|
|
13
|
+
created_at: string;
|
|
14
|
+
updated_at: string;
|
|
15
|
+
}
|
|
16
|
+
export interface Feature {
|
|
17
|
+
id: number;
|
|
18
|
+
title: string;
|
|
19
|
+
description: string | null;
|
|
20
|
+
created_at: string;
|
|
21
|
+
updated_at: string;
|
|
22
|
+
project_id: number;
|
|
23
|
+
}
|
|
24
|
+
export interface Scenario {
|
|
25
|
+
id: number;
|
|
26
|
+
title: string;
|
|
27
|
+
given: string | null;
|
|
28
|
+
when: string | null;
|
|
29
|
+
then: string | null;
|
|
30
|
+
position: number;
|
|
31
|
+
feature_id: number;
|
|
32
|
+
created_at: string;
|
|
33
|
+
updated_at: string;
|
|
34
|
+
}
|
|
35
|
+
export interface ScenarioExecution {
|
|
36
|
+
id: number;
|
|
37
|
+
scenario_id: number;
|
|
38
|
+
user_id: number;
|
|
39
|
+
status: string | null;
|
|
40
|
+
notes: string | null;
|
|
41
|
+
executed_at: string | null;
|
|
42
|
+
created_at: string;
|
|
43
|
+
updated_at: string;
|
|
44
|
+
}
|
|
45
|
+
export interface CreateFeatureBody {
|
|
46
|
+
title?: string;
|
|
47
|
+
description?: string;
|
|
48
|
+
tag_list?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface UpdateFeatureBody {
|
|
51
|
+
title?: string;
|
|
52
|
+
description?: string;
|
|
53
|
+
tag_list?: string;
|
|
54
|
+
}
|
|
55
|
+
export interface CreateScenarioBody {
|
|
56
|
+
title?: string;
|
|
57
|
+
given?: string;
|
|
58
|
+
when?: string;
|
|
59
|
+
then?: string;
|
|
60
|
+
position?: number;
|
|
61
|
+
}
|
|
62
|
+
export interface UpdateScenarioBody {
|
|
63
|
+
title?: string;
|
|
64
|
+
given?: string;
|
|
65
|
+
when?: string;
|
|
66
|
+
then?: string;
|
|
67
|
+
position?: number;
|
|
68
|
+
}
|
|
69
|
+
export interface CreateScenarioExecutionBody {
|
|
70
|
+
status?: string;
|
|
71
|
+
notes?: string;
|
|
72
|
+
executed_at?: string;
|
|
73
|
+
}
|
|
74
|
+
export interface UpdateScenarioExecutionBody {
|
|
75
|
+
status?: string;
|
|
76
|
+
notes?: string;
|
|
77
|
+
executed_at?: string;
|
|
78
|
+
}
|
|
79
|
+
export declare function createApiClient(baseUrl: string, token: string): {
|
|
80
|
+
getProjects(): Promise<Project[]>;
|
|
81
|
+
getProject(projectId: string | number): Promise<Project>;
|
|
82
|
+
getFeatures(projectId: string | number): Promise<Feature[]>;
|
|
83
|
+
getFeature(projectId: string | number, featureId: string | number): Promise<Feature>;
|
|
84
|
+
createFeature(projectId: string | number, body: CreateFeatureBody): Promise<Feature>;
|
|
85
|
+
updateFeature(projectId: string | number, featureId: string | number, body: UpdateFeatureBody): Promise<Feature>;
|
|
86
|
+
deleteFeature(projectId: string | number, featureId: string | number): Promise<{
|
|
87
|
+
message?: string;
|
|
88
|
+
}>;
|
|
89
|
+
getScenarios(projectId: string | number, featureId: string | number): Promise<Scenario[]>;
|
|
90
|
+
getScenario(projectId: string | number, featureId: string | number, scenarioId: string | number): Promise<Scenario>;
|
|
91
|
+
createScenario(projectId: string | number, featureId: string | number, body: CreateScenarioBody): Promise<Scenario>;
|
|
92
|
+
updateScenario(projectId: string | number, featureId: string | number, scenarioId: string | number, body: UpdateScenarioBody): Promise<Scenario>;
|
|
93
|
+
deleteScenario(projectId: string | number, featureId: string | number, scenarioId: string | number): Promise<{
|
|
94
|
+
message?: string;
|
|
95
|
+
}>;
|
|
96
|
+
getScenarioExecutions(projectId: string | number, featureId: string | number, scenarioId: string | number): Promise<ScenarioExecution[]>;
|
|
97
|
+
getScenarioExecution(projectId: string | number, featureId: string | number, scenarioId: string | number, executionId: string | number): Promise<ScenarioExecution>;
|
|
98
|
+
createScenarioExecution(projectId: string | number, featureId: string | number, scenarioId: string | number, body: CreateScenarioExecutionBody): Promise<ScenarioExecution>;
|
|
99
|
+
updateScenarioExecution(projectId: string | number, featureId: string | number, scenarioId: string | number, executionId: string | number, body: UpdateScenarioExecutionBody): Promise<ScenarioExecution>;
|
|
100
|
+
deleteScenarioExecution(projectId: string | number, featureId: string | number, scenarioId: string | number, executionId: string | number): Promise<{
|
|
101
|
+
message?: string;
|
|
102
|
+
}>;
|
|
103
|
+
};
|
|
104
|
+
export type ApiClient = ReturnType<typeof createApiClient>;
|
|
105
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,qBAAa,0BAA2B,SAAQ,KAAK;gBACvC,OAAO,SAA6B;CAIjD;AAED,qBAAa,QAAS,SAAQ,KAAK;IAGxB,UAAU,EAAE,MAAM;IAClB,IAAI,CAAC,EAAE,OAAO;gBAFrB,OAAO,EAAE,MAAM,EACR,UAAU,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE,OAAO,YAAA;CAKxB;AAED,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB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AAO,CAAC;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;qCASnB,MAAM,GAAG,MAAM,aACf,MAAM,GAAG,MAAM,cACd,MAAM,GAAG,MAAM,GAC1B,OAAO,CAAC,iBAAiB,EAAE,CAAC;oCAOlB,MAAM,GAAG,MAAM,aACf,MAAM,GAAG,MAAM,cACd,MAAM,GAAG,MAAM,eACd,MAAM,GAAG,MAAM,GAC3B,OAAO,CAAC,iBAAiB,CAAC;uCAOhB,MAAM,GAAG,MAAM,aACf,MAAM,GAAG,MAAM,cACd,MAAM,GAAG,MAAM,QACrB,2BAA2B,GAChC,OAAO,CAAC,iBAAiB,CAAC;uCAQhB,MAAM,GAAG,MAAM,aACf,MAAM,GAAG,MAAM,cACd,MAAM,GAAG,MAAM,eACd,MAAM,GAAG,MAAM,QACtB,2BAA2B,GAChC,OAAO,CAAC,iBAAiB,CAAC;uCAQhB,MAAM,GAAG,MAAM,aACf,MAAM,GAAG,MAAM,cACd,MAAM,GAAG,MAAM,eACd,MAAM,GAAG,MAAM,GAC3B,OAAO,CAAC;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;EAOnC;AAED,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC"}
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
export class TokenInvalidOrExpiredError extends Error {
|
|
2
|
+
constructor(message = 'Token invalid or expired') {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = 'TokenInvalidOrExpiredError';
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export class ApiError extends Error {
|
|
8
|
+
statusCode;
|
|
9
|
+
body;
|
|
10
|
+
constructor(message, statusCode, body) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.statusCode = statusCode;
|
|
13
|
+
this.body = body;
|
|
14
|
+
this.name = 'ApiError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function createApiClient(baseUrl, token) {
|
|
18
|
+
const base = baseUrl.replace(/\/$/, '');
|
|
19
|
+
const prefix = `${base}/api/v1`;
|
|
20
|
+
async function request(method, path, body) {
|
|
21
|
+
const url = path.startsWith('http') ? path : `${prefix}${path}`;
|
|
22
|
+
const headers = {
|
|
23
|
+
Authorization: `Bearer ${token}`,
|
|
24
|
+
'Content-Type': 'application/json',
|
|
25
|
+
};
|
|
26
|
+
const res = await fetch(url, {
|
|
27
|
+
method,
|
|
28
|
+
headers,
|
|
29
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
30
|
+
});
|
|
31
|
+
let json;
|
|
32
|
+
const text = await res.text();
|
|
33
|
+
if (text) {
|
|
34
|
+
try {
|
|
35
|
+
json = JSON.parse(text);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
json = text;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (res.status === 401) {
|
|
42
|
+
throw new TokenInvalidOrExpiredError();
|
|
43
|
+
}
|
|
44
|
+
if (!res.ok) {
|
|
45
|
+
const message = typeof json === 'object' && json !== null && 'error' in json
|
|
46
|
+
? String(json.error)
|
|
47
|
+
: `Request failed: ${res.status} ${res.statusText}`;
|
|
48
|
+
throw new ApiError(message, res.status, json);
|
|
49
|
+
}
|
|
50
|
+
return json;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
// Projects
|
|
54
|
+
getProjects() {
|
|
55
|
+
return request('GET', '/projects');
|
|
56
|
+
},
|
|
57
|
+
getProject(projectId) {
|
|
58
|
+
return request('GET', `/projects/${projectId}`);
|
|
59
|
+
},
|
|
60
|
+
// Features
|
|
61
|
+
getFeatures(projectId) {
|
|
62
|
+
return request('GET', `/projects/${projectId}/features`);
|
|
63
|
+
},
|
|
64
|
+
getFeature(projectId, featureId) {
|
|
65
|
+
return request('GET', `/projects/${projectId}/features/${featureId}`);
|
|
66
|
+
},
|
|
67
|
+
createFeature(projectId, body) {
|
|
68
|
+
return request('POST', `/projects/${projectId}/features`, {
|
|
69
|
+
feature: body,
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
updateFeature(projectId, featureId, body) {
|
|
73
|
+
return request('PATCH', `/projects/${projectId}/features/${featureId}`, { feature: body });
|
|
74
|
+
},
|
|
75
|
+
deleteFeature(projectId, featureId) {
|
|
76
|
+
return request('DELETE', `/projects/${projectId}/features/${featureId}`);
|
|
77
|
+
},
|
|
78
|
+
// Scenarios
|
|
79
|
+
getScenarios(projectId, featureId) {
|
|
80
|
+
return request('GET', `/projects/${projectId}/features/${featureId}/scenarios`);
|
|
81
|
+
},
|
|
82
|
+
getScenario(projectId, featureId, scenarioId) {
|
|
83
|
+
return request('GET', `/projects/${projectId}/features/${featureId}/scenarios/${scenarioId}`);
|
|
84
|
+
},
|
|
85
|
+
createScenario(projectId, featureId, body) {
|
|
86
|
+
return request('POST', `/projects/${projectId}/features/${featureId}/scenarios`, { scenario: body });
|
|
87
|
+
},
|
|
88
|
+
updateScenario(projectId, featureId, scenarioId, body) {
|
|
89
|
+
return request('PATCH', `/projects/${projectId}/features/${featureId}/scenarios/${scenarioId}`, { scenario: body });
|
|
90
|
+
},
|
|
91
|
+
deleteScenario(projectId, featureId, scenarioId) {
|
|
92
|
+
return request('DELETE', `/projects/${projectId}/features/${featureId}/scenarios/${scenarioId}`);
|
|
93
|
+
},
|
|
94
|
+
// Scenario executions
|
|
95
|
+
getScenarioExecutions(projectId, featureId, scenarioId) {
|
|
96
|
+
return request('GET', `/projects/${projectId}/features/${featureId}/scenarios/${scenarioId}/scenario_executions`);
|
|
97
|
+
},
|
|
98
|
+
getScenarioExecution(projectId, featureId, scenarioId, executionId) {
|
|
99
|
+
return request('GET', `/projects/${projectId}/features/${featureId}/scenarios/${scenarioId}/scenario_executions/${executionId}`);
|
|
100
|
+
},
|
|
101
|
+
createScenarioExecution(projectId, featureId, scenarioId, body) {
|
|
102
|
+
return request('POST', `/projects/${projectId}/features/${featureId}/scenarios/${scenarioId}/scenario_executions`, { scenario_execution: body });
|
|
103
|
+
},
|
|
104
|
+
updateScenarioExecution(projectId, featureId, scenarioId, executionId, body) {
|
|
105
|
+
return request('PATCH', `/projects/${projectId}/features/${featureId}/scenarios/${scenarioId}/scenario_executions/${executionId}`, { scenario_execution: body });
|
|
106
|
+
},
|
|
107
|
+
deleteScenarioExecution(projectId, featureId, scenarioId, executionId) {
|
|
108
|
+
return request('DELETE', `/projects/${projectId}/features/${featureId}/scenarios/${scenarioId}/scenario_executions/${executionId}`);
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IACnD,YAAY,OAAO,GAAG,0BAA0B;QAC9C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AAED,MAAM,OAAO,QAAS,SAAQ,KAAK;IAGxB;IACA;IAHT,YACE,OAAe,EACR,UAAkB,EAClB,IAAc;QAErB,KAAK,CAAC,OAAO,CAAC,CAAC;QAHR,eAAU,GAAV,UAAU,CAAQ;QAClB,SAAI,GAAJ,IAAI,CAAU;QAGrB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAkFD,MAAM,UAAU,eAAe,CAAC,OAAe,EAAE,KAAa;IAC5D,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACxC,MAAM,MAAM,GAAG,GAAG,IAAI,SAAS,CAAC;IAEhC,KAAK,UAAU,OAAO,CACpB,MAAc,EACd,IAAY,EACZ,IAAa;QAEb,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI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