flakiness 0.149.0 → 0.150.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.
@@ -1,168 +0,0 @@
1
- // src/flakinessSession.ts
2
- import fs from "fs/promises";
3
- import os from "os";
4
- import path from "path";
5
-
6
- // src/serverapi.ts
7
- import { TypedHTTP } from "@flakiness/shared/common/typedHttp.js";
8
-
9
- // src/utils.ts
10
- import { ReportUtils } from "@flakiness/sdk";
11
- import http from "http";
12
- import https from "https";
13
- var FLAKINESS_DBG = !!process.env.FLAKINESS_DBG;
14
- function errorText(error) {
15
- return FLAKINESS_DBG ? error.stack : error.message;
16
- }
17
- async function retryWithBackoff(job, backoff = []) {
18
- for (const timeout of backoff) {
19
- try {
20
- return await job();
21
- } catch (e) {
22
- if (e instanceof AggregateError)
23
- console.error(`[flakiness.io err]`, errorText(e.errors[0]));
24
- else if (e instanceof Error)
25
- console.error(`[flakiness.io err]`, errorText(e));
26
- else
27
- console.error(`[flakiness.io err]`, e);
28
- await new Promise((x) => setTimeout(x, timeout));
29
- }
30
- }
31
- return await job();
32
- }
33
- var httpUtils;
34
- ((httpUtils2) => {
35
- function createRequest({ url, method = "get", headers = {} }) {
36
- let resolve;
37
- let reject;
38
- const responseDataPromise = new Promise((a, b) => {
39
- resolve = a;
40
- reject = b;
41
- });
42
- const protocol = url.startsWith("https") ? https : http;
43
- headers = Object.fromEntries(Object.entries(headers).filter(([key, value]) => value !== void 0));
44
- const request = protocol.request(url, { method, headers }, (res) => {
45
- const chunks = [];
46
- res.on("data", (chunk) => chunks.push(chunk));
47
- res.on("end", () => {
48
- if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300)
49
- resolve(Buffer.concat(chunks));
50
- else
51
- reject(new Error(`Request to ${url} failed with ${res.statusCode}`));
52
- });
53
- res.on("error", (error) => reject(error));
54
- });
55
- request.on("error", reject);
56
- return { request, responseDataPromise };
57
- }
58
- httpUtils2.createRequest = createRequest;
59
- async function getBuffer(url, backoff) {
60
- return await retryWithBackoff(async () => {
61
- const { request, responseDataPromise } = createRequest({ url });
62
- request.end();
63
- return await responseDataPromise;
64
- }, backoff);
65
- }
66
- httpUtils2.getBuffer = getBuffer;
67
- async function getText(url, backoff) {
68
- const buffer = await getBuffer(url, backoff);
69
- return buffer.toString("utf-8");
70
- }
71
- httpUtils2.getText = getText;
72
- async function getJSON(url) {
73
- return JSON.parse(await getText(url));
74
- }
75
- httpUtils2.getJSON = getJSON;
76
- async function postText(url, text, backoff) {
77
- const headers = {
78
- "Content-Type": "application/json",
79
- "Content-Length": Buffer.byteLength(text) + ""
80
- };
81
- return await retryWithBackoff(async () => {
82
- const { request, responseDataPromise } = createRequest({ url, headers, method: "post" });
83
- request.write(text);
84
- request.end();
85
- return await responseDataPromise;
86
- }, backoff);
87
- }
88
- httpUtils2.postText = postText;
89
- async function postJSON(url, json, backoff) {
90
- const buffer = await postText(url, JSON.stringify(json), backoff);
91
- return JSON.parse(buffer.toString("utf-8"));
92
- }
93
- httpUtils2.postJSON = postJSON;
94
- })(httpUtils || (httpUtils = {}));
95
- var ansiRegex = new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))", "g");
96
-
97
- // src/serverapi.ts
98
- function createServerAPI(endpoint, options) {
99
- endpoint += "/api/";
100
- const fetcher = options?.auth ? (url, init) => fetch(url, {
101
- ...init,
102
- headers: {
103
- ...init.headers,
104
- "Authorization": `Bearer ${options.auth}`
105
- }
106
- }) : fetch;
107
- if (options?.retries)
108
- return TypedHTTP.createClient(endpoint, (url, init) => retryWithBackoff(() => fetcher(url, init), options.retries));
109
- return TypedHTTP.createClient(endpoint, fetcher);
110
- }
111
-
112
- // src/flakinessSession.ts
113
- var CONFIG_DIR = (() => {
114
- const configDir = process.platform === "darwin" ? path.join(os.homedir(), "Library", "Application Support", "flakiness") : process.platform === "win32" ? path.join(os.homedir(), "AppData", "Roaming", "flakiness") : path.join(os.homedir(), ".config", "flakiness");
115
- return configDir;
116
- })();
117
- var CONFIG_PATH = path.join(CONFIG_DIR, "config.json");
118
- var FlakinessSession = class _FlakinessSession {
119
- constructor(_config) {
120
- this._config = _config;
121
- this.api = createServerAPI(this._config.endpoint, { auth: this._config.token });
122
- }
123
- static async loadOrDie() {
124
- const session = await _FlakinessSession.load();
125
- if (!session)
126
- throw new Error(`Please login first with 'npx flakiness login'`);
127
- return session;
128
- }
129
- static async load() {
130
- const data = await fs.readFile(CONFIG_PATH, "utf-8").catch((e) => void 0);
131
- if (!data)
132
- return void 0;
133
- const json = JSON.parse(data);
134
- return new _FlakinessSession(json);
135
- }
136
- static async remove() {
137
- await fs.unlink(CONFIG_PATH).catch((e) => void 0);
138
- }
139
- api;
140
- endpoint() {
141
- return this._config.endpoint;
142
- }
143
- path() {
144
- return CONFIG_PATH;
145
- }
146
- sessionToken() {
147
- return this._config.token;
148
- }
149
- async save() {
150
- await fs.mkdir(CONFIG_DIR, { recursive: true });
151
- await fs.writeFile(CONFIG_PATH, JSON.stringify(this._config, null, 2));
152
- }
153
- };
154
-
155
- // src/cli/cmd-logout.ts
156
- async function cmdLogout() {
157
- const session = await FlakinessSession.load();
158
- if (!session)
159
- return;
160
- const currentSession = await session.api.user.currentSession.GET().catch((e) => void 0);
161
- if (currentSession)
162
- await session.api.user.logoutSession.POST({ sessionId: currentSession.sessionPublicId }).catch((e) => void 0);
163
- await FlakinessSession.remove();
164
- }
165
- export {
166
- cmdLogout
167
- };
168
- //# sourceMappingURL=cmd-logout.js.map
@@ -1,179 +0,0 @@
1
- // src/cli/cmd-status.ts
2
- import { FlakinessProjectConfig } from "@flakiness/sdk";
3
-
4
- // src/flakinessSession.ts
5
- import fs from "fs/promises";
6
- import os from "os";
7
- import path from "path";
8
-
9
- // src/serverapi.ts
10
- import { TypedHTTP } from "@flakiness/shared/common/typedHttp.js";
11
-
12
- // src/utils.ts
13
- import { ReportUtils } from "@flakiness/sdk";
14
- import http from "http";
15
- import https from "https";
16
- var FLAKINESS_DBG = !!process.env.FLAKINESS_DBG;
17
- function errorText(error) {
18
- return FLAKINESS_DBG ? error.stack : error.message;
19
- }
20
- async function retryWithBackoff(job, backoff = []) {
21
- for (const timeout of backoff) {
22
- try {
23
- return await job();
24
- } catch (e) {
25
- if (e instanceof AggregateError)
26
- console.error(`[flakiness.io err]`, errorText(e.errors[0]));
27
- else if (e instanceof Error)
28
- console.error(`[flakiness.io err]`, errorText(e));
29
- else
30
- console.error(`[flakiness.io err]`, e);
31
- await new Promise((x) => setTimeout(x, timeout));
32
- }
33
- }
34
- return await job();
35
- }
36
- var httpUtils;
37
- ((httpUtils2) => {
38
- function createRequest({ url, method = "get", headers = {} }) {
39
- let resolve;
40
- let reject;
41
- const responseDataPromise = new Promise((a, b) => {
42
- resolve = a;
43
- reject = b;
44
- });
45
- const protocol = url.startsWith("https") ? https : http;
46
- headers = Object.fromEntries(Object.entries(headers).filter(([key, value]) => value !== void 0));
47
- const request = protocol.request(url, { method, headers }, (res) => {
48
- const chunks = [];
49
- res.on("data", (chunk) => chunks.push(chunk));
50
- res.on("end", () => {
51
- if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300)
52
- resolve(Buffer.concat(chunks));
53
- else
54
- reject(new Error(`Request to ${url} failed with ${res.statusCode}`));
55
- });
56
- res.on("error", (error) => reject(error));
57
- });
58
- request.on("error", reject);
59
- return { request, responseDataPromise };
60
- }
61
- httpUtils2.createRequest = createRequest;
62
- async function getBuffer(url, backoff) {
63
- return await retryWithBackoff(async () => {
64
- const { request, responseDataPromise } = createRequest({ url });
65
- request.end();
66
- return await responseDataPromise;
67
- }, backoff);
68
- }
69
- httpUtils2.getBuffer = getBuffer;
70
- async function getText(url, backoff) {
71
- const buffer = await getBuffer(url, backoff);
72
- return buffer.toString("utf-8");
73
- }
74
- httpUtils2.getText = getText;
75
- async function getJSON(url) {
76
- return JSON.parse(await getText(url));
77
- }
78
- httpUtils2.getJSON = getJSON;
79
- async function postText(url, text, backoff) {
80
- const headers = {
81
- "Content-Type": "application/json",
82
- "Content-Length": Buffer.byteLength(text) + ""
83
- };
84
- return await retryWithBackoff(async () => {
85
- const { request, responseDataPromise } = createRequest({ url, headers, method: "post" });
86
- request.write(text);
87
- request.end();
88
- return await responseDataPromise;
89
- }, backoff);
90
- }
91
- httpUtils2.postText = postText;
92
- async function postJSON(url, json, backoff) {
93
- const buffer = await postText(url, JSON.stringify(json), backoff);
94
- return JSON.parse(buffer.toString("utf-8"));
95
- }
96
- httpUtils2.postJSON = postJSON;
97
- })(httpUtils || (httpUtils = {}));
98
- var ansiRegex = new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))", "g");
99
-
100
- // src/serverapi.ts
101
- function createServerAPI(endpoint, options) {
102
- endpoint += "/api/";
103
- const fetcher = options?.auth ? (url, init) => fetch(url, {
104
- ...init,
105
- headers: {
106
- ...init.headers,
107
- "Authorization": `Bearer ${options.auth}`
108
- }
109
- }) : fetch;
110
- if (options?.retries)
111
- return TypedHTTP.createClient(endpoint, (url, init) => retryWithBackoff(() => fetcher(url, init), options.retries));
112
- return TypedHTTP.createClient(endpoint, fetcher);
113
- }
114
-
115
- // src/flakinessSession.ts
116
- var CONFIG_DIR = (() => {
117
- const configDir = process.platform === "darwin" ? path.join(os.homedir(), "Library", "Application Support", "flakiness") : process.platform === "win32" ? path.join(os.homedir(), "AppData", "Roaming", "flakiness") : path.join(os.homedir(), ".config", "flakiness");
118
- return configDir;
119
- })();
120
- var CONFIG_PATH = path.join(CONFIG_DIR, "config.json");
121
- var FlakinessSession = class _FlakinessSession {
122
- constructor(_config) {
123
- this._config = _config;
124
- this.api = createServerAPI(this._config.endpoint, { auth: this._config.token });
125
- }
126
- static async loadOrDie() {
127
- const session = await _FlakinessSession.load();
128
- if (!session)
129
- throw new Error(`Please login first with 'npx flakiness login'`);
130
- return session;
131
- }
132
- static async load() {
133
- const data = await fs.readFile(CONFIG_PATH, "utf-8").catch((e) => void 0);
134
- if (!data)
135
- return void 0;
136
- const json = JSON.parse(data);
137
- return new _FlakinessSession(json);
138
- }
139
- static async remove() {
140
- await fs.unlink(CONFIG_PATH).catch((e) => void 0);
141
- }
142
- api;
143
- endpoint() {
144
- return this._config.endpoint;
145
- }
146
- path() {
147
- return CONFIG_PATH;
148
- }
149
- sessionToken() {
150
- return this._config.token;
151
- }
152
- async save() {
153
- await fs.mkdir(CONFIG_DIR, { recursive: true });
154
- await fs.writeFile(CONFIG_PATH, JSON.stringify(this._config, null, 2));
155
- }
156
- };
157
-
158
- // src/cli/cmd-status.ts
159
- async function cmdStatus() {
160
- const session = await FlakinessSession.load();
161
- if (!session) {
162
- console.log(`user: not logged in`);
163
- return;
164
- }
165
- const user = await session.api.user.whoami.GET();
166
- console.log(`user: ${user.userName} (${user.userLogin})`);
167
- const config = await FlakinessProjectConfig.load();
168
- const projectPublicId = config.projectPublicId();
169
- if (!projectPublicId) {
170
- console.log(`project: <not linked>`);
171
- return;
172
- }
173
- const project = await session.api.project.getProject.GET({ projectPublicId });
174
- console.log(`project: ${session.endpoint()}/${project.org.orgSlug}/${project.projectSlug}`);
175
- }
176
- export {
177
- cmdStatus
178
- };
179
- //# sourceMappingURL=cmd-status.js.map
@@ -1,13 +0,0 @@
1
- // src/cli/cmd-unlink.ts
2
- import { FlakinessProjectConfig } from "@flakiness/sdk";
3
- async function cmdUnlink() {
4
- const config = await FlakinessProjectConfig.load();
5
- if (!config.projectPublicId())
6
- return;
7
- config.setProjectPublicId(void 0);
8
- await config.save();
9
- }
10
- export {
11
- cmdUnlink
12
- };
13
- //# sourceMappingURL=cmd-unlink.js.map
@@ -1,160 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // src/cli/cmd-upload.ts
4
- import { uploadReport } from "@flakiness/sdk";
5
- import chalk from "chalk";
6
- import fs2 from "fs/promises";
7
- import path2 from "path";
8
-
9
- // src/utils.ts
10
- import { ReportUtils } from "@flakiness/sdk";
11
- import fs from "fs";
12
- import http from "http";
13
- import https from "https";
14
- import path from "path";
15
- var FLAKINESS_DBG = !!process.env.FLAKINESS_DBG;
16
- function errorText(error) {
17
- return FLAKINESS_DBG ? error.stack : error.message;
18
- }
19
- async function retryWithBackoff(job, backoff = []) {
20
- for (const timeout of backoff) {
21
- try {
22
- return await job();
23
- } catch (e) {
24
- if (e instanceof AggregateError)
25
- console.error(`[flakiness.io err]`, errorText(e.errors[0]));
26
- else if (e instanceof Error)
27
- console.error(`[flakiness.io err]`, errorText(e));
28
- else
29
- console.error(`[flakiness.io err]`, e);
30
- await new Promise((x) => setTimeout(x, timeout));
31
- }
32
- }
33
- return await job();
34
- }
35
- var httpUtils;
36
- ((httpUtils2) => {
37
- function createRequest({ url, method = "get", headers = {} }) {
38
- let resolve;
39
- let reject;
40
- const responseDataPromise = new Promise((a, b) => {
41
- resolve = a;
42
- reject = b;
43
- });
44
- const protocol = url.startsWith("https") ? https : http;
45
- headers = Object.fromEntries(Object.entries(headers).filter(([key, value]) => value !== void 0));
46
- const request = protocol.request(url, { method, headers }, (res) => {
47
- const chunks = [];
48
- res.on("data", (chunk) => chunks.push(chunk));
49
- res.on("end", () => {
50
- if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300)
51
- resolve(Buffer.concat(chunks));
52
- else
53
- reject(new Error(`Request to ${url} failed with ${res.statusCode}`));
54
- });
55
- res.on("error", (error) => reject(error));
56
- });
57
- request.on("error", reject);
58
- return { request, responseDataPromise };
59
- }
60
- httpUtils2.createRequest = createRequest;
61
- async function getBuffer(url, backoff) {
62
- return await retryWithBackoff(async () => {
63
- const { request, responseDataPromise } = createRequest({ url });
64
- request.end();
65
- return await responseDataPromise;
66
- }, backoff);
67
- }
68
- httpUtils2.getBuffer = getBuffer;
69
- async function getText(url, backoff) {
70
- const buffer = await getBuffer(url, backoff);
71
- return buffer.toString("utf-8");
72
- }
73
- httpUtils2.getText = getText;
74
- async function getJSON(url) {
75
- return JSON.parse(await getText(url));
76
- }
77
- httpUtils2.getJSON = getJSON;
78
- async function postText(url, text, backoff) {
79
- const headers = {
80
- "Content-Type": "application/json",
81
- "Content-Length": Buffer.byteLength(text) + ""
82
- };
83
- return await retryWithBackoff(async () => {
84
- const { request, responseDataPromise } = createRequest({ url, headers, method: "post" });
85
- request.write(text);
86
- request.end();
87
- return await responseDataPromise;
88
- }, backoff);
89
- }
90
- httpUtils2.postText = postText;
91
- async function postJSON(url, json, backoff) {
92
- const buffer = await postText(url, JSON.stringify(json), backoff);
93
- return JSON.parse(buffer.toString("utf-8"));
94
- }
95
- httpUtils2.postJSON = postJSON;
96
- })(httpUtils || (httpUtils = {}));
97
- var ansiRegex = new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))", "g");
98
- async function resolveAttachmentPaths(report, attachmentsDir) {
99
- const attachmentFiles = await listFilesRecursively(attachmentsDir);
100
- const filenameToPath = new Map(attachmentFiles.map((file) => [path.basename(file), file]));
101
- const attachmentIdToPath = /* @__PURE__ */ new Map();
102
- const missingAttachments = /* @__PURE__ */ new Set();
103
- ReportUtils.visitTests(report, (test) => {
104
- for (const attempt of test.attempts) {
105
- for (const attachment of attempt.attachments ?? []) {
106
- const attachmentPath = filenameToPath.get(attachment.id);
107
- if (!attachmentPath) {
108
- missingAttachments.add(attachment.id);
109
- } else {
110
- attachmentIdToPath.set(attachment.id, {
111
- contentType: attachment.contentType,
112
- id: attachment.id,
113
- path: attachmentPath,
114
- type: "file"
115
- });
116
- }
117
- }
118
- }
119
- });
120
- return { attachmentIdToPath, missingAttachments: Array.from(missingAttachments) };
121
- }
122
- async function listFilesRecursively(dir, result = []) {
123
- const entries = await fs.promises.readdir(dir, { withFileTypes: true });
124
- for (const entry of entries) {
125
- const fullPath = path.join(dir, entry.name);
126
- if (entry.isDirectory())
127
- await listFilesRecursively(fullPath, result);
128
- else
129
- result.push(fullPath);
130
- }
131
- return result;
132
- }
133
-
134
- // src/cli/cmd-upload.ts
135
- var warn = (txt) => console.warn(chalk.yellow(`[flakiness.io] WARN: ${txt}`));
136
- var err = (txt) => console.error(chalk.red(`[flakiness.io] Error: ${txt}`));
137
- async function cmdUpload(relativePaths, options) {
138
- for (const relativePath of relativePaths) {
139
- const fullPath = path2.resolve(relativePath);
140
- if (!await fs2.access(fullPath, fs2.constants.F_OK).then(() => true).catch(() => false)) {
141
- err(`Path ${fullPath} is not accessible!`);
142
- process.exit(1);
143
- }
144
- const text = await fs2.readFile(fullPath, "utf-8");
145
- const report = JSON.parse(text);
146
- const attachmentsDir = options.attachmentsDir ?? path2.dirname(fullPath);
147
- const { attachmentIdToPath, missingAttachments } = await resolveAttachmentPaths(report, attachmentsDir);
148
- if (missingAttachments.length) {
149
- warn(`Missing ${missingAttachments.length} attachments`);
150
- }
151
- await uploadReport(report, Array.from(attachmentIdToPath.values()), {
152
- flakinessAccessToken: options.accessToken,
153
- flakinessEndpoint: options.endpoint
154
- });
155
- }
156
- }
157
- export {
158
- cmdUpload
159
- };
160
- //# sourceMappingURL=cmd-upload.js.map
@@ -1,171 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // src/flakinessSession.ts
4
- import fs from "fs/promises";
5
- import os from "os";
6
- import path from "path";
7
-
8
- // src/serverapi.ts
9
- import { TypedHTTP } from "@flakiness/shared/common/typedHttp.js";
10
-
11
- // src/utils.ts
12
- import { ReportUtils } from "@flakiness/sdk";
13
- import http from "http";
14
- import https from "https";
15
- var FLAKINESS_DBG = !!process.env.FLAKINESS_DBG;
16
- function errorText(error) {
17
- return FLAKINESS_DBG ? error.stack : error.message;
18
- }
19
- async function retryWithBackoff(job, backoff = []) {
20
- for (const timeout of backoff) {
21
- try {
22
- return await job();
23
- } catch (e) {
24
- if (e instanceof AggregateError)
25
- console.error(`[flakiness.io err]`, errorText(e.errors[0]));
26
- else if (e instanceof Error)
27
- console.error(`[flakiness.io err]`, errorText(e));
28
- else
29
- console.error(`[flakiness.io err]`, e);
30
- await new Promise((x) => setTimeout(x, timeout));
31
- }
32
- }
33
- return await job();
34
- }
35
- var httpUtils;
36
- ((httpUtils2) => {
37
- function createRequest({ url, method = "get", headers = {} }) {
38
- let resolve;
39
- let reject;
40
- const responseDataPromise = new Promise((a, b) => {
41
- resolve = a;
42
- reject = b;
43
- });
44
- const protocol = url.startsWith("https") ? https : http;
45
- headers = Object.fromEntries(Object.entries(headers).filter(([key, value]) => value !== void 0));
46
- const request = protocol.request(url, { method, headers }, (res) => {
47
- const chunks = [];
48
- res.on("data", (chunk) => chunks.push(chunk));
49
- res.on("end", () => {
50
- if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300)
51
- resolve(Buffer.concat(chunks));
52
- else
53
- reject(new Error(`Request to ${url} failed with ${res.statusCode}`));
54
- });
55
- res.on("error", (error) => reject(error));
56
- });
57
- request.on("error", reject);
58
- return { request, responseDataPromise };
59
- }
60
- httpUtils2.createRequest = createRequest;
61
- async function getBuffer(url, backoff) {
62
- return await retryWithBackoff(async () => {
63
- const { request, responseDataPromise } = createRequest({ url });
64
- request.end();
65
- return await responseDataPromise;
66
- }, backoff);
67
- }
68
- httpUtils2.getBuffer = getBuffer;
69
- async function getText(url, backoff) {
70
- const buffer = await getBuffer(url, backoff);
71
- return buffer.toString("utf-8");
72
- }
73
- httpUtils2.getText = getText;
74
- async function getJSON(url) {
75
- return JSON.parse(await getText(url));
76
- }
77
- httpUtils2.getJSON = getJSON;
78
- async function postText(url, text, backoff) {
79
- const headers = {
80
- "Content-Type": "application/json",
81
- "Content-Length": Buffer.byteLength(text) + ""
82
- };
83
- return await retryWithBackoff(async () => {
84
- const { request, responseDataPromise } = createRequest({ url, headers, method: "post" });
85
- request.write(text);
86
- request.end();
87
- return await responseDataPromise;
88
- }, backoff);
89
- }
90
- httpUtils2.postText = postText;
91
- async function postJSON(url, json, backoff) {
92
- const buffer = await postText(url, JSON.stringify(json), backoff);
93
- return JSON.parse(buffer.toString("utf-8"));
94
- }
95
- httpUtils2.postJSON = postJSON;
96
- })(httpUtils || (httpUtils = {}));
97
- var ansiRegex = new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))", "g");
98
-
99
- // src/serverapi.ts
100
- function createServerAPI(endpoint, options) {
101
- endpoint += "/api/";
102
- const fetcher = options?.auth ? (url, init) => fetch(url, {
103
- ...init,
104
- headers: {
105
- ...init.headers,
106
- "Authorization": `Bearer ${options.auth}`
107
- }
108
- }) : fetch;
109
- if (options?.retries)
110
- return TypedHTTP.createClient(endpoint, (url, init) => retryWithBackoff(() => fetcher(url, init), options.retries));
111
- return TypedHTTP.createClient(endpoint, fetcher);
112
- }
113
-
114
- // src/flakinessSession.ts
115
- var CONFIG_DIR = (() => {
116
- const configDir = process.platform === "darwin" ? path.join(os.homedir(), "Library", "Application Support", "flakiness") : process.platform === "win32" ? path.join(os.homedir(), "AppData", "Roaming", "flakiness") : path.join(os.homedir(), ".config", "flakiness");
117
- return configDir;
118
- })();
119
- var CONFIG_PATH = path.join(CONFIG_DIR, "config.json");
120
- var FlakinessSession = class _FlakinessSession {
121
- constructor(_config) {
122
- this._config = _config;
123
- this.api = createServerAPI(this._config.endpoint, { auth: this._config.token });
124
- }
125
- static async loadOrDie() {
126
- const session = await _FlakinessSession.load();
127
- if (!session)
128
- throw new Error(`Please login first with 'npx flakiness login'`);
129
- return session;
130
- }
131
- static async load() {
132
- const data = await fs.readFile(CONFIG_PATH, "utf-8").catch((e) => void 0);
133
- if (!data)
134
- return void 0;
135
- const json = JSON.parse(data);
136
- return new _FlakinessSession(json);
137
- }
138
- static async remove() {
139
- await fs.unlink(CONFIG_PATH).catch((e) => void 0);
140
- }
141
- api;
142
- endpoint() {
143
- return this._config.endpoint;
144
- }
145
- path() {
146
- return CONFIG_PATH;
147
- }
148
- sessionToken() {
149
- return this._config.token;
150
- }
151
- async save() {
152
- await fs.mkdir(CONFIG_DIR, { recursive: true });
153
- await fs.writeFile(CONFIG_PATH, JSON.stringify(this._config, null, 2));
154
- }
155
- };
156
-
157
- // src/cli/cmd-whoami.ts
158
- async function cmdWhoami() {
159
- const session = await FlakinessSession.load();
160
- if (!session) {
161
- console.log('Not logged in. Run "flakiness login" first.');
162
- process.exit(1);
163
- }
164
- console.log(`Logged into ${session.endpoint()}`);
165
- const user = await session.api.user.whoami.GET();
166
- console.log(user);
167
- }
168
- export {
169
- cmdWhoami
170
- };
171
- //# sourceMappingURL=cmd-whoami.js.map