New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

testing-farm

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

testing-farm - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

{
"name": "testing-farm",
"version": "1.1.0",
"version": "1.2.0",
"description": "A NodeJS module to access Testing Farm instances through the REST API.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -17,3 +17,3 @@ # Testing Farm

[codecov]: https://codecov.io/github/redhat-plumbers-in-action/testing-farm
[codecov]: https://app.codecov.io/gh/redhat-plumbers-in-action/testing-farm
[codecov-status]: https://codecov.io/github/redhat-plumbers-in-action/testing-farm/branch/main/graph/badge.svg?token=EqTfXgwKz2

@@ -46,3 +46,3 @@

documentation of - [`GET /requests`](https://testing-farm.gitlab.io/api/#operation/requestsGet)
documentation of - [`GET /requests/{request_id}`](https://testing-farm.gitlab.io/api/#operation/requestsGet)

@@ -49,0 +49,0 @@ ```typescript

@@ -9,2 +9,3 @@ import { PublicLink } from './link';

Request,
ErrorResponse,
} from './schema';

@@ -22,3 +23,11 @@ import {

export type { Ranch, NewRequest, NewRequestResponse, Request, Composes, About };
export type {
Ranch,
NewRequest,
NewRequestResponse,
Request,
Composes,
About,
ErrorResponse,
};

@@ -25,0 +34,0 @@ export default class TestingFarmAPI {

@@ -0,18 +1,5 @@

import axios, { AxiosRequestConfig } from 'axios';
import { URL } from 'url';
import { z, ZodSchema } from 'zod';
import axios, { AxiosRequestConfig } from 'axios';
interface ApiError {
error: true;
message: string;
}
function isError(payload: unknown): payload is ApiError {
// TODO: Make this better by using zod ...
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return payload && typeof payload == 'object' && payload.error;
}
async function performRequest<

@@ -31,10 +18,6 @@ TSchema extends ZodSchema,

if (isError(response.data)) {
throw new Error(response.data.message);
}
return schema.parse(response.data);
} catch (e: unknown) {
if (axios.isAxiosError(e)) {
throw new Error(e.message);
throw new Error(JSON.stringify(e.response?.data));
} else {

@@ -46,7 +29,2 @@ throw e;

/**
* Responsible for requesting data from the bugzilla instance handling any
* necessary authentication and error handling that must happen. The chief
* access is through the `get`, `post` and `put` methods.
*/
export abstract class TestingFarmLink {

@@ -71,4 +49,3 @@ protected readonly instance: URL;

path: string,
schema: TSchema,
data?: D
schema: TSchema
): Promise<KValues> {

@@ -80,28 +57,20 @@ const config: AxiosRequestConfig<D> = {

if (data) {
config.data = data;
config.headers = {
'Content-Type': 'application/json',
};
}
return this.request(config, schema);
}
async post<R, TSchema extends ZodSchema, KValues extends z.infer<TSchema>>(
async post<D, TSchema extends ZodSchema, KValues extends z.infer<TSchema>>(
path: string,
schema: TSchema,
data: R
data: D
): Promise<KValues> {
return this.request(
{
url: this.buildURL(path).toString(),
method: 'POST',
data: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
},
const config: AxiosRequestConfig<D> = {
url: this.buildURL(path).toString(),
method: 'POST',
data,
headers: {
'Content-Type': 'application/json',
},
schema
);
};
return this.request(config, schema);
}

@@ -118,18 +87,1 @@ }

}
// TODO ...
// /**
// * Handles authentication using an API key.
// */
// export class ApiKeyLink extends TestingFarmLink {
// constructor(instance: string, private readonly apiKey: string) {
// super(instance);
// }
// protected async request<T>(
// config: AxiosRequestConfig,
// validator: Validator<T>
// ): Promise<T> {
// return performRequest(config, validator);
// }
// }

@@ -28,7 +28,3 @@ import { z } from 'zod';

playbooks: z.array(z.string().min(1)).optional(),
extra_variables: z
.object({
// [key: string]: string;
})
.optional(),
extra_variables: z.record(z.string()).optional(),
})

@@ -46,12 +42,4 @@ .optional(),

pool: z.string().min(1).optional(),
variables: z
.object({
// [key: string]: string;
})
.optional(),
secrets: z
.object({
// [key: string]: string;
})
.optional(),
variables: z.record(z.string()).optional(),
secrets: z.record(z.string()).optional(),
artifacts: z

@@ -84,7 +72,3 @@ .array(

post_install_script: z.string().min(1).optional(),
tags: z
.object({
// [key: string]: string;
})
.optional(),
tags: z.record(z.string()).optional(),
})

@@ -224,1 +208,8 @@ .optional(),

export type About = z.infer<typeof aboutSchema>;
export const errorResponseSchema = z.object({
code: z.number(),
message: z.string(),
});
export type ErrorResponse = z.infer<typeof errorResponseSchema>;