@qawolf/ci-sdk 0.23.1 → 1.0.1

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/dist/index.cjs ADDED
@@ -0,0 +1,628 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
+
6
+ // src/lib/other.ts
7
+ function sleep(ms) {
8
+ return new Promise((resolve) => setTimeout(resolve, ms));
9
+ }
10
+ __name(sleep, "sleep");
11
+ function pluralize(count) {
12
+ return count === 1 ? "" : "s";
13
+ }
14
+ __name(pluralize, "pluralize");
15
+ var buildFetchWithTimeout = /* @__PURE__ */ __name((fetch, timeout) => async (...args) => fetch(args[0], {
16
+ ...args[1],
17
+ signal: AbortSignal.timeout(timeout)
18
+ }), "buildFetchWithTimeout");
19
+
20
+ // src/lib/sdk/defaults/fetch.ts
21
+ var defaultFetch = globalThis.fetch;
22
+
23
+ // src/lib/sdk/defaults/log.ts
24
+ var defaultLogDriver = {
25
+ error(message, error) {
26
+ console.error(message, error);
27
+ },
28
+ info(message) {
29
+ console.log(message);
30
+ },
31
+ warn(message) {
32
+ console.warn(message);
33
+ }
34
+ };
35
+
36
+ // src/lib/sdk/defaults/serviceBase.ts
37
+ var defaultServiceBase = "https://app.qawolf.com/";
38
+
39
+ // package.json
40
+ var package_default = {
41
+ name: "@qawolf/ci-sdk",
42
+ version: "1.0.1",
43
+ private: false,
44
+ description: "A simple SDK for interacting with QAWolf in CI scripts.",
45
+ keywords: [],
46
+ license: "MIT",
47
+ author: "Jules Sam. Randolph<jules@qawolf.com>",
48
+ type: "module",
49
+ exports: {
50
+ ".": {
51
+ types: "./dist/index.d.ts",
52
+ require: "./dist/index.cjs",
53
+ import: "./dist/index.js",
54
+ default: "./dist/index.js"
55
+ }
56
+ },
57
+ main: "./dist/index.cjs",
58
+ module: "./dist/index.js",
59
+ types: "./dist/index.d.ts",
60
+ files: [
61
+ "/dist",
62
+ "/README.md"
63
+ ],
64
+ scripts: {
65
+ build: "tsup src/index.ts --format esm,cjs --dts --clean --splitting --treeshake --sourcemap --outDir dist --target es2022",
66
+ lint: "cycle-import-scan . && eslint . --ext js,jsx,mjs,ts,tsx --quiet && prettier --check .",
67
+ "lint:fix": "eslint . --ext js,jsx,mjs,ts,tsx --fix --quiet && prettier --log-level=warn --write .",
68
+ "lint:warnings": "eslint . --ext js,jsx,mjs,ts,tsx",
69
+ prepublishOnly: "nx run ci-sdk:build",
70
+ test: 'NODE_OPTIONS="--experimental-vm-modules" NODE_NO_WARNINGS=1 jest',
71
+ "tsc:check": "tsc --noEmit"
72
+ },
73
+ dependencies: {
74
+ "@qawolf/ci-utils": "^1.0.0",
75
+ "@sinonjs/fake-timers": "^10.3.0",
76
+ slugify: "^1.6.6",
77
+ tslib: "^2.6.2"
78
+ },
79
+ devDependencies: {
80
+ tsup: "8.3.5"
81
+ },
82
+ engines: {
83
+ node: ">=16"
84
+ }
85
+ };
86
+
87
+ // src/lib/sdk/defaults/userAgent.ts
88
+ var defaultUserAgent = `ci-sdk/${package_default.version}`;
89
+
90
+ // src/lib/api/log.ts
91
+ async function logFetchError({ log, methodName, response }) {
92
+ if (response.ok) return;
93
+ const { eventId, failureMessage } = await (async () => {
94
+ try {
95
+ const body = await response.json().catch(() => response.text());
96
+ if (typeof body === "object" && body !== null) {
97
+ return {
98
+ eventId: body.eventId,
99
+ failureMessage: body.failureMessage
100
+ };
101
+ }
102
+ return {
103
+ eventId: void 0,
104
+ failureMessage: body
105
+ };
106
+ } catch {
107
+ return {
108
+ eventId: undefined,
109
+ failureMessage: undefined
110
+ };
111
+ }
112
+ })();
113
+ const eventIdSuffix = eventId ? ` (Event ID: ${eventId})` : "";
114
+ const messageSuffix = failureMessage ? `: ${failureMessage}` : "";
115
+ const statusText = response.status >= 500 ? "Server Error" : response.statusText || "Unknown Error";
116
+ log.error(`\u274C [${methodName}] ${response.status} ${statusText}${eventIdSuffix}${messageSuffix}`);
117
+ }
118
+ __name(logFetchError, "logFetchError");
119
+
120
+ // src/lib/sdk/domain/attemptDeploy/index.ts
121
+ async function attemptNotifyDeploy(deps, apiConfig, config) {
122
+ const { fetch: localFetch, log } = deps;
123
+ try {
124
+ const response = await localFetch(new URL("/api/webhooks/deploy_success", apiConfig.serviceBase), {
125
+ body: JSON.stringify({
126
+ branch: config.branch,
127
+ commit_url: config.commitUrl,
128
+ deduplication_key: config.deduplicationKey,
129
+ deployment_type: config.deploymentType,
130
+ deployment_url: config.deploymentUrl,
131
+ hosting_service: config.hostingService,
132
+ merge_request_number: config.hostingService === "GitLab" ? config.mergeRequestNumber : void 0,
133
+ pull_request_number: config.hostingService === "GitHub" ? config.pullRequestNumber : void 0,
134
+ repository: config.repository,
135
+ sha: config.sha,
136
+ variables: config.variables
137
+ }),
138
+ headers: {
139
+ Authorization: `Bearer ${apiConfig.apiKey}`,
140
+ "Content-Type": "application/json",
141
+ "User-Agent": apiConfig.userAgent
142
+ },
143
+ method: "POST"
144
+ });
145
+ if (!response.ok) return handleErrorResponse(response, log);
146
+ const data = await response.json();
147
+ return handleSuccessResponse(data, log);
148
+ } catch (error) {
149
+ log.error(`\u{1F6AB} Network error from deploy_success, aborting.`);
150
+ return {
151
+ abortReason: "network-error",
152
+ httpStatus: undefined,
153
+ outcome: "aborted"
154
+ };
155
+ }
156
+ }
157
+ __name(attemptNotifyDeploy, "attemptNotifyDeploy");
158
+ async function handleErrorResponse(response, log) {
159
+ const status = response.status;
160
+ let abortReason;
161
+ if (status === undefined) abortReason = "network-error";
162
+ else if (status === 401) abortReason = "401-unauthorized";
163
+ else if (status === 403) abortReason = "403-forbidden";
164
+ else if (status >= 500) abortReason = "5XX-server-error";
165
+ else abortReason = "4XX-client-error";
166
+ await logFetchError({
167
+ log,
168
+ methodName: "attemptNotifyDeploy",
169
+ response
170
+ });
171
+ return {
172
+ abortReason,
173
+ httpStatus: status,
174
+ outcome: "aborted"
175
+ };
176
+ }
177
+ __name(handleErrorResponse, "handleErrorResponse");
178
+ async function handleSuccessResponse(data, log) {
179
+ const { environment, results } = data;
180
+ const isPreviewDeployment = environment && !environment.isStatic;
181
+ if (environment) {
182
+ const logPrefix = environment.isStatic ? "Static environment" : "Preview environment";
183
+ log.info(`${logPrefix}: ${environment.alias} (id: ${environment.id})`);
184
+ }
185
+ if (results.length === 0) {
186
+ if (isPreviewDeployment) {
187
+ log.info(`\u2705 Deployment notification was successful. No run was created for this deployment.`);
188
+ return {
189
+ environmentId: environment.id,
190
+ outcome: "success",
191
+ runId: undefined
192
+ };
193
+ }
194
+ log.error(`\u{1F6AB} No trigger matched the request. Please contact support.`);
195
+ return {
196
+ failReason: "no-matched-trigger",
197
+ outcome: "failed"
198
+ };
199
+ }
200
+ if (!environment) {
201
+ log.error(`\u{1F6AB} No environment matched the request. Please contact support.`);
202
+ return {
203
+ failReason: "no-environment",
204
+ outcome: "failed"
205
+ };
206
+ }
207
+ const failedTrigger = results.find((t) => "failure_reason" in t);
208
+ if (failedTrigger) {
209
+ log.error(`\u{1F6AB} Run could not be created. Reason: "${failedTrigger.failure_reason}". Please contact support.`);
210
+ return {
211
+ failReason: "run-could-not-be-created",
212
+ outcome: "failed"
213
+ };
214
+ }
215
+ const duplicateSuite = results.find((t) => "duplicate_suite_id" in t);
216
+ if (duplicateSuite) {
217
+ log.info(`\u2705 Deployment notification was successful. Previous run ID: ${duplicateSuite.duplicate_suite_id} already exists for this deployment.`);
218
+ return {
219
+ environmentId: environment.id,
220
+ outcome: "success",
221
+ runId: duplicateSuite.duplicate_suite_id
222
+ };
223
+ }
224
+ const successfulTrigger = results.find((t) => "created_suite_id" in t);
225
+ if (!successfulTrigger) {
226
+ log.error(`\u{1F6AB} No trigger matched the request. Please contact support.`);
227
+ return {
228
+ failReason: "no-matched-trigger",
229
+ outcome: "failed"
230
+ };
231
+ }
232
+ log.info(`\u2705 Deployment notification was successful. Run created with ID: ${successfulTrigger.created_suite_id}`);
233
+ return {
234
+ environmentId: environment.id,
235
+ outcome: "success",
236
+ runId: successfulTrigger.created_suite_id
237
+ };
238
+ }
239
+ __name(handleSuccessResponse, "handleSuccessResponse");
240
+
241
+ // src/lib/api/generate-signed-url-for-run-inputs-executables.ts
242
+ async function callGenerateSignedUrlForRunInputsExecutablesStorage({ apiKey, serviceBase, userAgent }, { destinationFilePath }, { fetch: localFetch, log }) {
243
+ try {
244
+ const response = await localFetch(new URL(`${serviceBase}/api/v0/run-inputs-executables-signed-urls?file=${encodeURIComponent(destinationFilePath)}`), {
245
+ headers: {
246
+ Authorization: `Bearer ${apiKey}`,
247
+ "Content-Type": "application/json",
248
+ "User-Agent": userAgent
249
+ },
250
+ method: "GET"
251
+ });
252
+ if (response.status === 200) {
253
+ const json = await response.json();
254
+ return {
255
+ fileLocation: json.fileLocation,
256
+ httpStatus: response.status,
257
+ playgroundFileLocation: json.playgroundFileLocation,
258
+ signedUrl: json.signedUrl,
259
+ success: true
260
+ };
261
+ }
262
+ await logFetchError({
263
+ log,
264
+ methodName: "callGenerateSignedUrlForRunInputsExecutablesStorage",
265
+ response
266
+ });
267
+ return {
268
+ errorMessage: await response.text(),
269
+ httpStatus: response.status,
270
+ success: false
271
+ };
272
+ } catch (e) {
273
+ return {
274
+ errorMessage: "Network error, aborting request to generate signed URL",
275
+ httpStatus: 0,
276
+ success: false
277
+ };
278
+ }
279
+ }
280
+ __name(callGenerateSignedUrlForRunInputsExecutablesStorage, "callGenerateSignedUrlForRunInputsExecutablesStorage");
281
+
282
+ // src/lib/sdk/domain/generateSignedUrls/generate-signed-url-for-run-inputs-executables.ts
283
+ async function generateSignedUrlForRunInputsExecutablesStorage(deps, apiConfig, config) {
284
+ const { log } = deps;
285
+ if (!config.destinationFilePath) {
286
+ log.error(`\u{1F6AB} destinationFilePath is a required config parameter`);
287
+ return {
288
+ abortReason: "sdk-argument-validation-failed",
289
+ success: false
290
+ };
291
+ }
292
+ const responseState = await callGenerateSignedUrlForRunInputsExecutablesStorage(apiConfig, config, deps);
293
+ if (!responseState.success) {
294
+ let abortReason = "XXX-other-http-code";
295
+ if (responseState.httpStatus >= 500) {
296
+ abortReason = "5XX-server-error";
297
+ log.error(`\u{1F6AB} Unrecoverable error (status ${responseState.httpStatus}) when generating signed upload url: aborting.`);
298
+ } else {
299
+ if (responseState.httpStatus === 400) abortReason = "400-invalid-request";
300
+ else if (responseState.httpStatus === 401) abortReason = "401-invalid-credentials";
301
+ else if (responseState.httpStatus === 403) abortReason = "403-forbidden";
302
+ else if (responseState.httpStatus === 0) abortReason = "client-network-error";
303
+ log.error(`\u{1F6AB} Unrecoverable error (status ${responseState.httpStatus}) when generating signed upload url: ${responseState.errorMessage ? `${responseState.errorMessage}.` : ""} aborting.`);
304
+ }
305
+ return {
306
+ abortReason,
307
+ httpStatus: responseState.httpStatus,
308
+ success: false
309
+ };
310
+ }
311
+ log.info(`\u2705 Generated Signed Upload URL: ${responseState.signedUrl}.`);
312
+ return {
313
+ fileLocation: responseState.fileLocation,
314
+ playgroundFileLocation: responseState.playgroundFileLocation,
315
+ success: true,
316
+ uploadUrl: responseState.signedUrl
317
+ };
318
+ }
319
+ __name(generateSignedUrlForRunInputsExecutablesStorage, "generateSignedUrlForRunInputsExecutablesStorage");
320
+
321
+ // src/lib/api/generate-signed-url-for-team-storage.ts
322
+ async function callGenerateSignedUrlForTempTeamStorage({ apiKey, serviceBase, userAgent }, { destinationFilePath }, { fetch: localFetch, log }) {
323
+ try {
324
+ const response = await localFetch(new URL(`${serviceBase}/api/v0/team-storage-signed-url?file=${destinationFilePath}`), {
325
+ headers: {
326
+ Authorization: `Bearer ${apiKey}`,
327
+ "Content-Type": "application/json",
328
+ "User-Agent": userAgent
329
+ },
330
+ method: "GET"
331
+ });
332
+ if (response.status === 200) {
333
+ const json = await response.json();
334
+ return {
335
+ fileLocation: json.fileLocation,
336
+ httpStatus: response.status,
337
+ playgroundFileLocation: json.playgroundFileLocation,
338
+ signedUrl: json.signedUrl,
339
+ success: true
340
+ };
341
+ }
342
+ await logFetchError({
343
+ log,
344
+ methodName: "callGenerateSignedUrlForTempTeamStorage",
345
+ response
346
+ });
347
+ return {
348
+ errorMessage: await response.text(),
349
+ httpStatus: response.status,
350
+ success: false
351
+ };
352
+ } catch (e) {
353
+ return {
354
+ errorMessage: "Network error, aborting request to generate signed URL",
355
+ httpStatus: 0,
356
+ success: false
357
+ };
358
+ }
359
+ }
360
+ __name(callGenerateSignedUrlForTempTeamStorage, "callGenerateSignedUrlForTempTeamStorage");
361
+
362
+ // src/lib/sdk/domain/generateSignedUrls/generate-signed-url-for-team-storage.ts
363
+ async function generateSignedUrlForTempTeamStorage(deps, apiConfig, config) {
364
+ const { log } = deps;
365
+ if (!config.destinationFilePath) {
366
+ log.error(`\u{1F6AB} destinationFilePath is a required config parameter`);
367
+ return {
368
+ abortReason: "sdk-argument-validation-failed",
369
+ success: false
370
+ };
371
+ }
372
+ const responseState = await callGenerateSignedUrlForTempTeamStorage(apiConfig, config, deps);
373
+ if (!responseState.success) {
374
+ let abortReason = "XXX-other-http-code";
375
+ if (responseState.httpStatus >= 500) {
376
+ abortReason = "5XX-server-error";
377
+ log.error(`\u{1F6AB} Unrecoverable error (status ${responseState.httpStatus}) when generating signed upload url: aborting.`);
378
+ } else {
379
+ if (responseState.httpStatus === 400) abortReason = "400-invalid-request";
380
+ else if (responseState.httpStatus === 401) abortReason = "401-invalid-credentials";
381
+ else if (responseState.httpStatus === 403) abortReason = "403-forbidden";
382
+ else if (responseState.httpStatus === 0) abortReason = "client-network-error";
383
+ log.error(`\u{1F6AB} Unrecoverable error (status ${responseState.httpStatus}) when generating signed upload url: ${responseState.errorMessage ? `${responseState.errorMessage}.` : ""} aborting.`);
384
+ }
385
+ return {
386
+ abortReason,
387
+ httpStatus: responseState.httpStatus,
388
+ success: false
389
+ };
390
+ }
391
+ log.info(`\u2705 Generated Signed Upload URL: ${responseState.signedUrl}.`);
392
+ return {
393
+ fileLocation: responseState.fileLocation,
394
+ playgroundFileLocation: responseState.playgroundFileLocation,
395
+ success: true,
396
+ uploadUrl: responseState.signedUrl
397
+ };
398
+ }
399
+ __name(generateSignedUrlForTempTeamStorage, "generateSignedUrlForTempTeamStorage");
400
+
401
+ // src/lib/api/ci-greenlight.ts
402
+ async function fetchCiGreenlightStatus({ apiKey, serviceBase, userAgent }, { runId }, { fetch: localFetch, log }) {
403
+ try {
404
+ const resp = await localFetch(new URL(`/api/v0/ci-greenlight/${encodeURIComponent(runId)}`, serviceBase), {
405
+ headers: {
406
+ Authorization: `Bearer ${apiKey}`,
407
+ "User-Agent": userAgent
408
+ }
409
+ });
410
+ if (resp.ok) {
411
+ const greenlightStatus = await resp.json();
412
+ return {
413
+ greenlightStatus,
414
+ httpStatus: resp.status,
415
+ ok: true
416
+ };
417
+ }
418
+ await logFetchError({
419
+ log,
420
+ methodName: "fetchCiGreenlightStatus",
421
+ response: resp
422
+ });
423
+ if (resp.status === 404) {
424
+ return {
425
+ canRetry: true,
426
+ errorType: "not-found",
427
+ httpStatus: resp.status,
428
+ ok: false
429
+ };
430
+ }
431
+ if (resp.status >= 500) {
432
+ return {
433
+ canRetry: true,
434
+ errorType: "server",
435
+ httpStatus: resp.status,
436
+ ok: false
437
+ };
438
+ }
439
+ return {
440
+ canRetry: false,
441
+ errorType: "client",
442
+ httpStatus: resp.status,
443
+ ok: false
444
+ };
445
+ } catch (e) {
446
+ return {
447
+ canRetry: true,
448
+ errorType: "network",
449
+ httpStatus: 0,
450
+ ok: false
451
+ };
452
+ }
453
+ }
454
+ __name(fetchCiGreenlightStatus, "fetchCiGreenlightStatus");
455
+
456
+ // src/lib/sdk/domain/poll-ci-greenlight.ts
457
+ var safeDefaults = {
458
+ abortOnSuperseded: false,
459
+ maxRetries: 10,
460
+ pollTimeout: 120 * 60 * 1e3,
461
+ retryInterval: 10 * 1e3,
462
+ runInProgressInterval: 30 * 1e3,
463
+ runUnderReviewInterval: 60 * 1e3
464
+ };
465
+ async function pollCiGreenlightStatus(deps, apiConfig, { onRunStageChanged = /* @__PURE__ */ __name(() => undefined, "onRunStageChanged"), runId, ...pollConfig }) {
466
+ let retries = 0;
467
+ const { log } = deps;
468
+ const { abortOnSuperseded = safeDefaults.abortOnSuperseded, maxRetries = safeDefaults.maxRetries, pollTimeout = safeDefaults.pollTimeout, retryInterval = safeDefaults.retryInterval, runInProgressInterval = safeDefaults.runInProgressInterval, runUnderReviewInterval = safeDefaults.runUnderReviewInterval } = pollConfig;
469
+ let currentStatus = undefined;
470
+ const startedAt = Date.now();
471
+ let hasTimedOut = false;
472
+ while (!(hasTimedOut = Date.now() - startedAt > pollTimeout)) {
473
+ const responseState = await fetchCiGreenlightStatus(apiConfig, {
474
+ runId
475
+ }, deps);
476
+ if (!responseState.ok && !responseState.canRetry) {
477
+ log.error(`\u{1F6AB} Unrecoverable error (status ${responseState.httpStatus}) from CI greenlight, aborting.`);
478
+ return {
479
+ abortReason: "4XX-client-error",
480
+ httpStatus: responseState.httpStatus,
481
+ outcome: "aborted"
482
+ };
483
+ }
484
+ if (!responseState.ok) {
485
+ retries += 1;
486
+ if (retries > maxRetries) {
487
+ log.error(`\u{1F6AB} Unrecoverable error${responseState.httpStatus ? ` (status ${responseState.httpStatus})` : ""} from CI greenlight, aborting after ${maxRetries} attempts.`);
488
+ if (responseState.errorType === "network") {
489
+ return {
490
+ abortReason: "network-error",
491
+ httpStatus: undefined,
492
+ outcome: "aborted"
493
+ };
494
+ }
495
+ let abortReason = "XXX-other-http-code";
496
+ if (responseState.errorType === "not-found") abortReason = "404-run-not-found";
497
+ else if (responseState.errorType === "server") abortReason = "5XX-server-error";
498
+ else ;
499
+ return {
500
+ abortReason,
501
+ httpStatus: responseState.httpStatus,
502
+ outcome: "aborted"
503
+ };
504
+ }
505
+ const { errorType, httpStatus } = responseState;
506
+ const retryLabel = `${httpStatus ? ` (status ${httpStatus})` : ""}, will try again... (${retries}/${maxRetries})`;
507
+ if (errorType === "network") log.warn(`\u274C Network error${retryLabel}`);
508
+ else if (errorType === "not-found") log.info(`\u23F3 Run not found${retryLabel}`);
509
+ else if (errorType === "server") log.warn(`\u274C Server error${retryLabel}`);
510
+ await sleep(retryInterval);
511
+ continue;
512
+ }
513
+ retries = 0;
514
+ const { greenlightStatus } = responseState;
515
+ const previousStatus = currentStatus;
516
+ currentStatus = greenlightStatus;
517
+ if (!previousStatus || previousStatus.runStage !== greenlightStatus.runStage) {
518
+ try {
519
+ await onRunStageChanged(greenlightStatus, previousStatus);
520
+ } catch (e) {
521
+ log.error(`Error in onRunStageChanged callback`, e);
522
+ }
523
+ }
524
+ const urlInfo = `See ${greenlightStatus.relevantRunUrl}`;
525
+ const { greenlight, relevantRunId, relevantRunUrl, relevantRunWithBugsUrl, rootRunId, rootRunUrl, runStage } = greenlightStatus;
526
+ if (rootRunId !== relevantRunId) {
527
+ const supersedingDetails = `
528
+ - Root: ${rootRunUrl}
529
+ - Superseding: ${relevantRunUrl}`;
530
+ if (abortOnSuperseded) {
531
+ log.warn(`\u274C Aborting due to superseded run (option 'abortOnSuperseded' is enabled).${supersedingDetails}`);
532
+ return {
533
+ abortReason: "superseded-run",
534
+ httpStatus: undefined,
535
+ outcome: "aborted"
536
+ };
537
+ }
538
+ log.info(`Root run was superseded:${supersedingDetails}`);
539
+ }
540
+ if (runStage === "completed") {
541
+ const { blockingBugsCount, blockingBugUrls = [], nonBlockingBugsCount, nonBlockingBugUrls = [] } = greenlightStatus;
542
+ const blockingBugList = blockingBugUrls.map((url) => `
543
+ \u2022 ${url}`).join("");
544
+ const nonBlockingBugList = nonBlockingBugUrls.map((url) => `
545
+ \u2022 ${url}`).join("");
546
+ const bugsListInText = `${blockingBugUrls.length > 0 ? `
547
+ BLOCKING BUGS:${blockingBugList}` : ""}${nonBlockingBugUrls.length > 0 ? `
548
+ NON BLOCKING BUGS:${nonBlockingBugList}` : ""}`;
549
+ if (greenlight) {
550
+ log.info(`\u2705 Run passed and no blocking bugs found${nonBlockingBugsCount > 0 ? ` and ${nonBlockingBugsCount} non-blocking bug${pluralize(nonBlockingBugsCount)} found` : ""}.
551
+ ${urlInfo}`);
552
+ return {
553
+ greenlightStatus,
554
+ outcome: "success"
555
+ };
556
+ } else {
557
+ log.warn(`\u274C Run failed and ${blockingBugsCount} blocking bug${pluralize(blockingBugsCount)} found${nonBlockingBugsCount ? ` and ${nonBlockingBugsCount} non-blocking bug${pluralize(nonBlockingBugsCount)}` : ""}.
558
+ See ${relevantRunWithBugsUrl}
559
+ You may review the priority of certain bugs to mark these non-blocking and retry the job.
560
+ ` + bugsListInText);
561
+ return {
562
+ greenlightStatus,
563
+ outcome: "failed"
564
+ };
565
+ }
566
+ }
567
+ if (runStage === "canceled") {
568
+ log.info(`\u{1F6AB} Run was canceled. Aborting... Please contact support.
569
+ ${urlInfo}`);
570
+ return {
571
+ abortReason: "run-canceled",
572
+ httpStatus: undefined,
573
+ outcome: "aborted"
574
+ };
575
+ }
576
+ if (hasTimedOut) {
577
+ log.warn(`\u274C Poll timed out after ${pollTimeout / 1e3}s. Aborting...`);
578
+ return {
579
+ abortReason: "poll-timed-out",
580
+ httpStatus: undefined,
581
+ outcome: "aborted"
582
+ };
583
+ }
584
+ if (runStage === "initializing") {
585
+ log.info(`\u23F3 Run is in progress... ${urlInfo}`);
586
+ await sleep(runInProgressInterval);
587
+ } else if (runStage === "underReview") {
588
+ log.info(`\u{1F575}\uFE0F Run is under review... ${urlInfo}`);
589
+ await sleep(runUnderReviewInterval);
590
+ } else throw Error(`Unexpected run stage: ${runStage}`);
591
+ }
592
+ log.warn(`\u274C Poll timed out after ${pollTimeout / 1e3}s. Aborting...`);
593
+ return {
594
+ abortReason: "poll-timed-out",
595
+ httpStatus: undefined,
596
+ outcome: "aborted"
597
+ };
598
+ }
599
+ __name(pollCiGreenlightStatus, "pollCiGreenlightStatus");
600
+
601
+ // src/lib/sdk/index.ts
602
+ function makeQaWolfSdk({ apiKey, serviceBase = defaultServiceBase, userAgent = defaultUserAgent }, { fetch = defaultFetch, log = defaultLogDriver } = {}) {
603
+ if (typeof fetch !== "function") {
604
+ throw Error(`QA Wolf CI-SDK requires fetch to be defined. Make sure you are using NodeJS 18+, OR pass a fetch polyfill to the makeQaWolfSdk function.
605
+ We recommend 'undici' package for that purpose. See the Requirement section of our README for more guidance.`);
606
+ }
607
+ const deps = {
608
+ // Versions of fetch may have different default timeouts. For consistency, we explicitly set it to 60 seconds here.
609
+ fetch: buildFetchWithTimeout(fetch, 6e4),
610
+ log
611
+ };
612
+ const apiConfig = {
613
+ apiKey,
614
+ serviceBase,
615
+ userAgent
616
+ };
617
+ return {
618
+ attemptNotifyDeploy: attemptNotifyDeploy.bind(null, deps, apiConfig),
619
+ generateSignedUrlForRunInputsExecutablesStorage: generateSignedUrlForRunInputsExecutablesStorage.bind(null, deps, apiConfig),
620
+ generateSignedUrlForTempTeamStorage: generateSignedUrlForTempTeamStorage.bind(null, deps, apiConfig),
621
+ pollCiGreenlightStatus: pollCiGreenlightStatus.bind(null, deps, apiConfig)
622
+ };
623
+ }
624
+ __name(makeQaWolfSdk, "makeQaWolfSdk");
625
+
626
+ exports.makeQaWolfSdk = makeQaWolfSdk;
627
+ //# sourceMappingURL=index.cjs.map
628
+ //# sourceMappingURL=index.cjs.map