@qawolf/ci-sdk 2.0.0 → 2.1.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 +4 -0
- package/dist/index.cjs +91 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +46 -39
- package/dist/index.d.ts +46 -39
- package/dist/index.js +91 -8
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -144,41 +144,6 @@ type GenerateSignedUrlResponse = {
|
|
|
144
144
|
success: boolean;
|
|
145
145
|
};
|
|
146
146
|
|
|
147
|
-
type WireSuiteResult = {
|
|
148
|
-
created_suite_id: string;
|
|
149
|
-
trigger_id: string;
|
|
150
|
-
} | {
|
|
151
|
-
failure_reason: string;
|
|
152
|
-
trigger_id: string;
|
|
153
|
-
} | {
|
|
154
|
-
duplicate_suite_id: string;
|
|
155
|
-
skip_reason: string;
|
|
156
|
-
trigger_id: string;
|
|
157
|
-
};
|
|
158
|
-
type DeploySuccessWireResponse = {
|
|
159
|
-
environment: {
|
|
160
|
-
alias?: string;
|
|
161
|
-
id: string;
|
|
162
|
-
isStatic: boolean;
|
|
163
|
-
} | undefined;
|
|
164
|
-
results: WireSuiteResult[];
|
|
165
|
-
skipped_deployment?: {
|
|
166
|
-
message: string;
|
|
167
|
-
reason: string;
|
|
168
|
-
};
|
|
169
|
-
skipped_triggers?: {
|
|
170
|
-
environment_id: string;
|
|
171
|
-
message: string;
|
|
172
|
-
reason: string;
|
|
173
|
-
trigger_id: string;
|
|
174
|
-
}[];
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Refer to our official documentation for more information:
|
|
179
|
-
* https://qawolf.notion.site/dd72e46ceb7f451dae4e9ef06f64a2cc
|
|
180
|
-
*/
|
|
181
|
-
|
|
182
147
|
type BaseDeployConfig = {
|
|
183
148
|
branch: string | undefined;
|
|
184
149
|
commitUrl: string | undefined;
|
|
@@ -209,6 +174,39 @@ type EphemeralDeployConfig = BaseDeployConfig & {
|
|
|
209
174
|
ephemeralEnvironment: true;
|
|
210
175
|
};
|
|
211
176
|
type DeployConfig = GitHubDeployConfig | GitLabDeployConfig | EphemeralDeployConfig;
|
|
177
|
+
|
|
178
|
+
type WireSuiteResult = {
|
|
179
|
+
created_suite_id: string;
|
|
180
|
+
trigger_id: string;
|
|
181
|
+
} | {
|
|
182
|
+
failure_reason: string;
|
|
183
|
+
trigger_id: string;
|
|
184
|
+
} | {
|
|
185
|
+
duplicate_suite_id: string;
|
|
186
|
+
skip_reason: string;
|
|
187
|
+
trigger_id: string;
|
|
188
|
+
} | {
|
|
189
|
+
trigger_id: string;
|
|
190
|
+
};
|
|
191
|
+
type DeploySuccessWireResponse = {
|
|
192
|
+
environment: {
|
|
193
|
+
alias?: string;
|
|
194
|
+
id: string;
|
|
195
|
+
isStatic: boolean;
|
|
196
|
+
} | undefined;
|
|
197
|
+
results: WireSuiteResult[];
|
|
198
|
+
skipped_deployment?: {
|
|
199
|
+
message: string;
|
|
200
|
+
reason: string;
|
|
201
|
+
};
|
|
202
|
+
skipped_triggers?: {
|
|
203
|
+
environment_id: string;
|
|
204
|
+
message: string;
|
|
205
|
+
reason: string;
|
|
206
|
+
trigger_id: string;
|
|
207
|
+
}[];
|
|
208
|
+
};
|
|
209
|
+
|
|
212
210
|
type DeploySuccessSuiteCreatedResult = {
|
|
213
211
|
createdSuiteId: string;
|
|
214
212
|
triggerId: string;
|
|
@@ -222,7 +220,11 @@ type DeploySuccessSuiteAlreadyExistsResult = {
|
|
|
222
220
|
skipReason: string;
|
|
223
221
|
triggerId: string;
|
|
224
222
|
};
|
|
225
|
-
type
|
|
223
|
+
type DeploySuccessSuiteUnrecognizedResult = {
|
|
224
|
+
triggerId: string;
|
|
225
|
+
unrecognized: true;
|
|
226
|
+
};
|
|
227
|
+
type DeploySuccessSuiteResult = DeploySuccessSuiteCreatedResult | DeploySuccessSuiteCreationFailureResult | DeploySuccessSuiteAlreadyExistsResult | DeploySuccessSuiteUnrecognizedResult;
|
|
226
228
|
type DeploySuccessSkippedTrigger = {
|
|
227
229
|
environmentId: string;
|
|
228
230
|
message: string;
|
|
@@ -255,7 +257,7 @@ type DeployStatusErrorResponse = {
|
|
|
255
257
|
};
|
|
256
258
|
type DeployStatusResponse = DeployStatusSuccessResponse | DeployStatusErrorResponse;
|
|
257
259
|
type AttemptDeployHttpAbortReason = "4XX-client-error" | "401-unauthorized" | "403-forbidden" | "5XX-server-error" | "network-error";
|
|
258
|
-
type AttemptDeployNonHttpAbortReason = "network-error";
|
|
260
|
+
type AttemptDeployNonHttpAbortReason = "network-error" | "invalid-response-body";
|
|
259
261
|
type AttemptDeployAbortReason = AttemptDeployHttpAbortReason | AttemptDeployNonHttpAbortReason;
|
|
260
262
|
type NotifyDeployStatus = {
|
|
261
263
|
/**
|
|
@@ -293,7 +295,12 @@ type NotifyDeployStatus = {
|
|
|
293
295
|
outcome: "skipped";
|
|
294
296
|
skippedDeployment: DeploySuccessDeploymentSkipped | undefined;
|
|
295
297
|
} | {
|
|
296
|
-
|
|
298
|
+
/**
|
|
299
|
+
* `unknown-result` means the response carried a result arm this SDK
|
|
300
|
+
* version does not recognize (the backend is newer). The caller should
|
|
301
|
+
* upgrade the SDK; the outcome could not be classified.
|
|
302
|
+
*/
|
|
303
|
+
failReason: "no-environment" | "run-could-not-be-created" | "unknown-result";
|
|
297
304
|
/**
|
|
298
305
|
* A run could not be created.
|
|
299
306
|
*/
|
|
@@ -524,4 +531,4 @@ declare function makeQaWolfSdk({ apiKey, serviceBase, userAgent, }: {
|
|
|
524
531
|
pollCiGreenlightStatus: (args_0: PollCiGreenlightParams) => Promise<PollCiGreenlightStatus>;
|
|
525
532
|
};
|
|
526
533
|
|
|
527
|
-
export { type AttemptDeployAbortReason, type AttemptDeployFailedReason, type AttemptDeployHttpAbortReason, type AttemptDeployNonHttpAbortReason, type CiGreenlightStatus, type CiGreenlightStatusBase, type DeployConfig, type DeployStatus, type DeployStatusErrorResponse, type DeployStatusResponse, type DeployStatusSuccessResponse, type DeploySuccessDeploymentSkipped, type DeploySuccessSkippedTrigger, type DeploySuccessSuiteAlreadyExistsResult, type DeploySuccessSuiteCreatedResult, type DeploySuccessSuiteCreationFailureResult, type DeploySuccessSuiteResult, type DeploySuccessWireResponse, type EphemeralDeployConfig, type FetchDriver, type GenerateSignedUrlAbortReason$1 as GenerateSignedUrlAbortReason, type GenerateSignedUrlConfig, type GenerateSignedUrlResponse, type GenerateSignedUrlStatus, type GitHubDeployConfig, type GitLabDeployConfig, type MakePollCiGreenlightStatusIteratorParams, type NotifyDeployStatus, type NotifyTerminatedEphemeralEnvironmentAbortReason, type NotifyTerminatedEphemeralEnvironmentFailedReason, type NotifyTerminatedEphemeralEnvironmentHttpAbortReason, type NotifyTerminatedEphemeralEnvironmentInput, type NotifyTerminatedEphemeralEnvironmentNonHttpAbortReason, type NotifyTerminatedEphemeralEnvironmentResult, type PollCiGreenlightAbortReason, type PollCiGreenlightHttpAbortReason, type PollCiGreenlightIteration, type PollCiGreenlightIteratorHttpAborted, type PollCiGreenlightIteratorNonHttpAborted, type PollCiGreenlightNonHttpAbortReason, type PollCiGreenlightParams, type PollCiGreenlightPollConfig, type PollCiGreenlightStatus, type PollCiGreenlightStatusIteration, type SdkDependencies, type TerminatedEphemeralEnvironmentSuccessResult, attemptNotifyDeploy, makeQaWolfSdk };
|
|
534
|
+
export { type AttemptDeployAbortReason, type AttemptDeployFailedReason, type AttemptDeployHttpAbortReason, type AttemptDeployNonHttpAbortReason, type CiGreenlightStatus, type CiGreenlightStatusBase, type DeployConfig, type DeployStatus, type DeployStatusErrorResponse, type DeployStatusResponse, type DeployStatusSuccessResponse, type DeploySuccessDeploymentSkipped, type DeploySuccessSkippedTrigger, type DeploySuccessSuiteAlreadyExistsResult, type DeploySuccessSuiteCreatedResult, type DeploySuccessSuiteCreationFailureResult, type DeploySuccessSuiteResult, type DeploySuccessSuiteUnrecognizedResult, type DeploySuccessWireResponse, type EphemeralDeployConfig, type FetchDriver, type GenerateSignedUrlAbortReason$1 as GenerateSignedUrlAbortReason, type GenerateSignedUrlConfig, type GenerateSignedUrlResponse, type GenerateSignedUrlStatus, type GitHubDeployConfig, type GitLabDeployConfig, type MakePollCiGreenlightStatusIteratorParams, type NotifyDeployStatus, type NotifyTerminatedEphemeralEnvironmentAbortReason, type NotifyTerminatedEphemeralEnvironmentFailedReason, type NotifyTerminatedEphemeralEnvironmentHttpAbortReason, type NotifyTerminatedEphemeralEnvironmentInput, type NotifyTerminatedEphemeralEnvironmentNonHttpAbortReason, type NotifyTerminatedEphemeralEnvironmentResult, type PollCiGreenlightAbortReason, type PollCiGreenlightHttpAbortReason, type PollCiGreenlightIteration, type PollCiGreenlightIteratorHttpAborted, type PollCiGreenlightIteratorNonHttpAborted, type PollCiGreenlightNonHttpAbortReason, type PollCiGreenlightParams, type PollCiGreenlightPollConfig, type PollCiGreenlightStatus, type PollCiGreenlightStatusIteration, type SdkDependencies, type TerminatedEphemeralEnvironmentSuccessResult, attemptNotifyDeploy, makeQaWolfSdk };
|
package/dist/index.d.ts
CHANGED
|
@@ -144,41 +144,6 @@ type GenerateSignedUrlResponse = {
|
|
|
144
144
|
success: boolean;
|
|
145
145
|
};
|
|
146
146
|
|
|
147
|
-
type WireSuiteResult = {
|
|
148
|
-
created_suite_id: string;
|
|
149
|
-
trigger_id: string;
|
|
150
|
-
} | {
|
|
151
|
-
failure_reason: string;
|
|
152
|
-
trigger_id: string;
|
|
153
|
-
} | {
|
|
154
|
-
duplicate_suite_id: string;
|
|
155
|
-
skip_reason: string;
|
|
156
|
-
trigger_id: string;
|
|
157
|
-
};
|
|
158
|
-
type DeploySuccessWireResponse = {
|
|
159
|
-
environment: {
|
|
160
|
-
alias?: string;
|
|
161
|
-
id: string;
|
|
162
|
-
isStatic: boolean;
|
|
163
|
-
} | undefined;
|
|
164
|
-
results: WireSuiteResult[];
|
|
165
|
-
skipped_deployment?: {
|
|
166
|
-
message: string;
|
|
167
|
-
reason: string;
|
|
168
|
-
};
|
|
169
|
-
skipped_triggers?: {
|
|
170
|
-
environment_id: string;
|
|
171
|
-
message: string;
|
|
172
|
-
reason: string;
|
|
173
|
-
trigger_id: string;
|
|
174
|
-
}[];
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Refer to our official documentation for more information:
|
|
179
|
-
* https://qawolf.notion.site/dd72e46ceb7f451dae4e9ef06f64a2cc
|
|
180
|
-
*/
|
|
181
|
-
|
|
182
147
|
type BaseDeployConfig = {
|
|
183
148
|
branch: string | undefined;
|
|
184
149
|
commitUrl: string | undefined;
|
|
@@ -209,6 +174,39 @@ type EphemeralDeployConfig = BaseDeployConfig & {
|
|
|
209
174
|
ephemeralEnvironment: true;
|
|
210
175
|
};
|
|
211
176
|
type DeployConfig = GitHubDeployConfig | GitLabDeployConfig | EphemeralDeployConfig;
|
|
177
|
+
|
|
178
|
+
type WireSuiteResult = {
|
|
179
|
+
created_suite_id: string;
|
|
180
|
+
trigger_id: string;
|
|
181
|
+
} | {
|
|
182
|
+
failure_reason: string;
|
|
183
|
+
trigger_id: string;
|
|
184
|
+
} | {
|
|
185
|
+
duplicate_suite_id: string;
|
|
186
|
+
skip_reason: string;
|
|
187
|
+
trigger_id: string;
|
|
188
|
+
} | {
|
|
189
|
+
trigger_id: string;
|
|
190
|
+
};
|
|
191
|
+
type DeploySuccessWireResponse = {
|
|
192
|
+
environment: {
|
|
193
|
+
alias?: string;
|
|
194
|
+
id: string;
|
|
195
|
+
isStatic: boolean;
|
|
196
|
+
} | undefined;
|
|
197
|
+
results: WireSuiteResult[];
|
|
198
|
+
skipped_deployment?: {
|
|
199
|
+
message: string;
|
|
200
|
+
reason: string;
|
|
201
|
+
};
|
|
202
|
+
skipped_triggers?: {
|
|
203
|
+
environment_id: string;
|
|
204
|
+
message: string;
|
|
205
|
+
reason: string;
|
|
206
|
+
trigger_id: string;
|
|
207
|
+
}[];
|
|
208
|
+
};
|
|
209
|
+
|
|
212
210
|
type DeploySuccessSuiteCreatedResult = {
|
|
213
211
|
createdSuiteId: string;
|
|
214
212
|
triggerId: string;
|
|
@@ -222,7 +220,11 @@ type DeploySuccessSuiteAlreadyExistsResult = {
|
|
|
222
220
|
skipReason: string;
|
|
223
221
|
triggerId: string;
|
|
224
222
|
};
|
|
225
|
-
type
|
|
223
|
+
type DeploySuccessSuiteUnrecognizedResult = {
|
|
224
|
+
triggerId: string;
|
|
225
|
+
unrecognized: true;
|
|
226
|
+
};
|
|
227
|
+
type DeploySuccessSuiteResult = DeploySuccessSuiteCreatedResult | DeploySuccessSuiteCreationFailureResult | DeploySuccessSuiteAlreadyExistsResult | DeploySuccessSuiteUnrecognizedResult;
|
|
226
228
|
type DeploySuccessSkippedTrigger = {
|
|
227
229
|
environmentId: string;
|
|
228
230
|
message: string;
|
|
@@ -255,7 +257,7 @@ type DeployStatusErrorResponse = {
|
|
|
255
257
|
};
|
|
256
258
|
type DeployStatusResponse = DeployStatusSuccessResponse | DeployStatusErrorResponse;
|
|
257
259
|
type AttemptDeployHttpAbortReason = "4XX-client-error" | "401-unauthorized" | "403-forbidden" | "5XX-server-error" | "network-error";
|
|
258
|
-
type AttemptDeployNonHttpAbortReason = "network-error";
|
|
260
|
+
type AttemptDeployNonHttpAbortReason = "network-error" | "invalid-response-body";
|
|
259
261
|
type AttemptDeployAbortReason = AttemptDeployHttpAbortReason | AttemptDeployNonHttpAbortReason;
|
|
260
262
|
type NotifyDeployStatus = {
|
|
261
263
|
/**
|
|
@@ -293,7 +295,12 @@ type NotifyDeployStatus = {
|
|
|
293
295
|
outcome: "skipped";
|
|
294
296
|
skippedDeployment: DeploySuccessDeploymentSkipped | undefined;
|
|
295
297
|
} | {
|
|
296
|
-
|
|
298
|
+
/**
|
|
299
|
+
* `unknown-result` means the response carried a result arm this SDK
|
|
300
|
+
* version does not recognize (the backend is newer). The caller should
|
|
301
|
+
* upgrade the SDK; the outcome could not be classified.
|
|
302
|
+
*/
|
|
303
|
+
failReason: "no-environment" | "run-could-not-be-created" | "unknown-result";
|
|
297
304
|
/**
|
|
298
305
|
* A run could not be created.
|
|
299
306
|
*/
|
|
@@ -524,4 +531,4 @@ declare function makeQaWolfSdk({ apiKey, serviceBase, userAgent, }: {
|
|
|
524
531
|
pollCiGreenlightStatus: (args_0: PollCiGreenlightParams) => Promise<PollCiGreenlightStatus>;
|
|
525
532
|
};
|
|
526
533
|
|
|
527
|
-
export { type AttemptDeployAbortReason, type AttemptDeployFailedReason, type AttemptDeployHttpAbortReason, type AttemptDeployNonHttpAbortReason, type CiGreenlightStatus, type CiGreenlightStatusBase, type DeployConfig, type DeployStatus, type DeployStatusErrorResponse, type DeployStatusResponse, type DeployStatusSuccessResponse, type DeploySuccessDeploymentSkipped, type DeploySuccessSkippedTrigger, type DeploySuccessSuiteAlreadyExistsResult, type DeploySuccessSuiteCreatedResult, type DeploySuccessSuiteCreationFailureResult, type DeploySuccessSuiteResult, type DeploySuccessWireResponse, type EphemeralDeployConfig, type FetchDriver, type GenerateSignedUrlAbortReason$1 as GenerateSignedUrlAbortReason, type GenerateSignedUrlConfig, type GenerateSignedUrlResponse, type GenerateSignedUrlStatus, type GitHubDeployConfig, type GitLabDeployConfig, type MakePollCiGreenlightStatusIteratorParams, type NotifyDeployStatus, type NotifyTerminatedEphemeralEnvironmentAbortReason, type NotifyTerminatedEphemeralEnvironmentFailedReason, type NotifyTerminatedEphemeralEnvironmentHttpAbortReason, type NotifyTerminatedEphemeralEnvironmentInput, type NotifyTerminatedEphemeralEnvironmentNonHttpAbortReason, type NotifyTerminatedEphemeralEnvironmentResult, type PollCiGreenlightAbortReason, type PollCiGreenlightHttpAbortReason, type PollCiGreenlightIteration, type PollCiGreenlightIteratorHttpAborted, type PollCiGreenlightIteratorNonHttpAborted, type PollCiGreenlightNonHttpAbortReason, type PollCiGreenlightParams, type PollCiGreenlightPollConfig, type PollCiGreenlightStatus, type PollCiGreenlightStatusIteration, type SdkDependencies, type TerminatedEphemeralEnvironmentSuccessResult, attemptNotifyDeploy, makeQaWolfSdk };
|
|
534
|
+
export { type AttemptDeployAbortReason, type AttemptDeployFailedReason, type AttemptDeployHttpAbortReason, type AttemptDeployNonHttpAbortReason, type CiGreenlightStatus, type CiGreenlightStatusBase, type DeployConfig, type DeployStatus, type DeployStatusErrorResponse, type DeployStatusResponse, type DeployStatusSuccessResponse, type DeploySuccessDeploymentSkipped, type DeploySuccessSkippedTrigger, type DeploySuccessSuiteAlreadyExistsResult, type DeploySuccessSuiteCreatedResult, type DeploySuccessSuiteCreationFailureResult, type DeploySuccessSuiteResult, type DeploySuccessSuiteUnrecognizedResult, type DeploySuccessWireResponse, type EphemeralDeployConfig, type FetchDriver, type GenerateSignedUrlAbortReason$1 as GenerateSignedUrlAbortReason, type GenerateSignedUrlConfig, type GenerateSignedUrlResponse, type GenerateSignedUrlStatus, type GitHubDeployConfig, type GitLabDeployConfig, type MakePollCiGreenlightStatusIteratorParams, type NotifyDeployStatus, type NotifyTerminatedEphemeralEnvironmentAbortReason, type NotifyTerminatedEphemeralEnvironmentFailedReason, type NotifyTerminatedEphemeralEnvironmentHttpAbortReason, type NotifyTerminatedEphemeralEnvironmentInput, type NotifyTerminatedEphemeralEnvironmentNonHttpAbortReason, type NotifyTerminatedEphemeralEnvironmentResult, type PollCiGreenlightAbortReason, type PollCiGreenlightHttpAbortReason, type PollCiGreenlightIteration, type PollCiGreenlightIteratorHttpAborted, type PollCiGreenlightIteratorNonHttpAborted, type PollCiGreenlightNonHttpAbortReason, type PollCiGreenlightParams, type PollCiGreenlightPollConfig, type PollCiGreenlightStatus, type PollCiGreenlightStatusIteration, type SdkDependencies, type TerminatedEphemeralEnvironmentSuccessResult, attemptNotifyDeploy, makeQaWolfSdk };
|
package/dist/index.js
CHANGED
|
@@ -39,7 +39,7 @@ var defaultServiceBase = "https://app.qawolf.com/";
|
|
|
39
39
|
|
|
40
40
|
// package.json
|
|
41
41
|
var package_default = {
|
|
42
|
-
version: "2.
|
|
42
|
+
version: "2.1.0"};
|
|
43
43
|
|
|
44
44
|
// src/lib/sdk/defaults/userAgent.ts
|
|
45
45
|
var defaultUserAgent = `ci-sdk/${package_default.version}`;
|
|
@@ -121,6 +121,14 @@ async function handleSuccessResponse(data, log) {
|
|
|
121
121
|
outcome: "failed"
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
|
+
const unrecognizedResult = results.find((result) => "unrecognized" in result);
|
|
125
|
+
if (unrecognizedResult) {
|
|
126
|
+
log.error(`\u{1F6AB} The deployment response contained an unrecognized result. Please upgrade @qawolf/ci-sdk.`);
|
|
127
|
+
return {
|
|
128
|
+
failReason: "unknown-result",
|
|
129
|
+
outcome: "failed"
|
|
130
|
+
};
|
|
131
|
+
}
|
|
124
132
|
const failedTrigger = results.find((result) => "failureReason" in result);
|
|
125
133
|
if (failedTrigger) {
|
|
126
134
|
log.error(`\u{1F6AB} Run could not be created. Reason: "${failedTrigger.failureReason}". Please contact support.`);
|
|
@@ -169,10 +177,16 @@ function mapSuiteResult(result) {
|
|
|
169
177
|
triggerId: result.trigger_id
|
|
170
178
|
};
|
|
171
179
|
}
|
|
180
|
+
if ("duplicate_suite_id" in result) {
|
|
181
|
+
return {
|
|
182
|
+
duplicateSuiteId: result.duplicate_suite_id,
|
|
183
|
+
skipReason: result.skip_reason,
|
|
184
|
+
triggerId: result.trigger_id
|
|
185
|
+
};
|
|
186
|
+
}
|
|
172
187
|
return {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
triggerId: result.trigger_id
|
|
188
|
+
triggerId: result.trigger_id,
|
|
189
|
+
unrecognized: true
|
|
176
190
|
};
|
|
177
191
|
}
|
|
178
192
|
__name(mapSuiteResult, "mapSuiteResult");
|
|
@@ -194,11 +208,61 @@ function mapDeploySuccessResponse(wire) {
|
|
|
194
208
|
}
|
|
195
209
|
__name(mapDeploySuccessResponse, "mapDeploySuccessResponse");
|
|
196
210
|
|
|
211
|
+
// src/lib/sdk/domain/attemptDeploy/parseDeploySuccessWireResponse.ts
|
|
212
|
+
function isRecord(value) {
|
|
213
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
214
|
+
}
|
|
215
|
+
__name(isRecord, "isRecord");
|
|
216
|
+
function isWireSuiteResult(value) {
|
|
217
|
+
if (!isRecord(value)) return false;
|
|
218
|
+
if (typeof value.trigger_id !== "string") return false;
|
|
219
|
+
if ("created_suite_id" in value) return typeof value.created_suite_id === "string";
|
|
220
|
+
if ("failure_reason" in value) return typeof value.failure_reason === "string";
|
|
221
|
+
if ("duplicate_suite_id" in value) {
|
|
222
|
+
return typeof value.duplicate_suite_id === "string" && typeof value.skip_reason === "string";
|
|
223
|
+
}
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
__name(isWireSuiteResult, "isWireSuiteResult");
|
|
227
|
+
function isEnvironment(value) {
|
|
228
|
+
if (!isRecord(value)) return false;
|
|
229
|
+
if (typeof value.id !== "string") return false;
|
|
230
|
+
if (typeof value.isStatic !== "boolean") return false;
|
|
231
|
+
if (value.alias !== void 0 && typeof value.alias !== "string") return false;
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
__name(isEnvironment, "isEnvironment");
|
|
235
|
+
function isSkippedDeployment(value) {
|
|
236
|
+
if (!isRecord(value)) return false;
|
|
237
|
+
return typeof value.message === "string" && typeof value.reason === "string";
|
|
238
|
+
}
|
|
239
|
+
__name(isSkippedDeployment, "isSkippedDeployment");
|
|
240
|
+
function isSkippedTrigger(value) {
|
|
241
|
+
if (!isRecord(value)) return false;
|
|
242
|
+
return typeof value.environment_id === "string" && typeof value.message === "string" && typeof value.reason === "string" && typeof value.trigger_id === "string";
|
|
243
|
+
}
|
|
244
|
+
__name(isSkippedTrigger, "isSkippedTrigger");
|
|
245
|
+
function isDeploySuccessWireResponse(value) {
|
|
246
|
+
if (!isRecord(value)) return false;
|
|
247
|
+
if (value.environment !== void 0 && !isEnvironment(value.environment)) return false;
|
|
248
|
+
if (!Array.isArray(value.results) || !value.results.every(isWireSuiteResult)) return false;
|
|
249
|
+
if (value.skipped_deployment !== void 0 && !isSkippedDeployment(value.skipped_deployment)) return false;
|
|
250
|
+
if (value.skipped_triggers !== void 0 && (!Array.isArray(value.skipped_triggers) || !value.skipped_triggers.every(isSkippedTrigger))) return false;
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
__name(isDeploySuccessWireResponse, "isDeploySuccessWireResponse");
|
|
254
|
+
function parseDeploySuccessWireResponse(value) {
|
|
255
|
+
return isDeploySuccessWireResponse(value) ? value : "invalid";
|
|
256
|
+
}
|
|
257
|
+
__name(parseDeploySuccessWireResponse, "parseDeploySuccessWireResponse");
|
|
258
|
+
|
|
197
259
|
// src/lib/sdk/domain/attemptDeploy/index.ts
|
|
198
260
|
async function attemptNotifyDeploy(deps, apiConfig, config) {
|
|
199
261
|
const { fetch: localFetch, log } = deps;
|
|
262
|
+
let response;
|
|
263
|
+
let bodyText;
|
|
200
264
|
try {
|
|
201
|
-
|
|
265
|
+
response = await localFetch(new URL("/api/webhooks/deploy_success", apiConfig.serviceBase), {
|
|
202
266
|
body: JSON.stringify({
|
|
203
267
|
branch: config.branch,
|
|
204
268
|
commit_url: config.commitUrl,
|
|
@@ -227,9 +291,7 @@ async function attemptNotifyDeploy(deps, apiConfig, config) {
|
|
|
227
291
|
signal: AbortSignal.timeout(5 * 60 * 1e3)
|
|
228
292
|
});
|
|
229
293
|
if (!response.ok) return handleErrorResponse(response, log);
|
|
230
|
-
|
|
231
|
-
const data = mapDeploySuccessResponse(wire);
|
|
232
|
-
return handleSuccessResponse(data, log);
|
|
294
|
+
bodyText = await response.text();
|
|
233
295
|
} catch {
|
|
234
296
|
log.error(`\u{1F6AB} Network error from deploy_success, aborting.`);
|
|
235
297
|
return {
|
|
@@ -238,8 +300,29 @@ async function attemptNotifyDeploy(deps, apiConfig, config) {
|
|
|
238
300
|
outcome: "aborted"
|
|
239
301
|
};
|
|
240
302
|
}
|
|
303
|
+
let rawBody;
|
|
304
|
+
try {
|
|
305
|
+
rawBody = JSON.parse(bodyText);
|
|
306
|
+
} catch {
|
|
307
|
+
return abortInvalidResponseBody(log, "the response body was not JSON");
|
|
308
|
+
}
|
|
309
|
+
const wire = parseDeploySuccessWireResponse(rawBody);
|
|
310
|
+
if (wire === "invalid") {
|
|
311
|
+
return abortInvalidResponseBody(log, "the response body did not match the expected shape");
|
|
312
|
+
}
|
|
313
|
+
const data = mapDeploySuccessResponse(wire);
|
|
314
|
+
return handleSuccessResponse(data, log);
|
|
241
315
|
}
|
|
242
316
|
__name(attemptNotifyDeploy, "attemptNotifyDeploy");
|
|
317
|
+
function abortInvalidResponseBody(log, detail) {
|
|
318
|
+
log.error(`\u{1F6AB} Invalid response from deploy_success (${detail}), aborting.`);
|
|
319
|
+
return {
|
|
320
|
+
abortReason: "invalid-response-body",
|
|
321
|
+
httpStatus: void 0,
|
|
322
|
+
outcome: "aborted"
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
__name(abortInvalidResponseBody, "abortInvalidResponseBody");
|
|
243
326
|
async function handleErrorResponse(response, log) {
|
|
244
327
|
const status = response.status;
|
|
245
328
|
let abortReason;
|