Comparing version 1.1.6 to 2.0.0
@@ -21,1 +21,2 @@ /// <reference types="node" /> | ||
} | ||
//# sourceMappingURL=index.d.ts.map |
@@ -10,37 +10,36 @@ "use strict"; | ||
constructor(instance, user, password, restrictLogin = false) { | ||
if (!(instance instanceof url_1.URL)) { | ||
instance = new url_1.URL(instance); | ||
} | ||
let url = instance instanceof url_1.URL ? instance : new url_1.URL(instance); | ||
if (!user) { | ||
this.link = new link_1.PublicLink(instance); | ||
this.link = new link_1.PublicLink(url); | ||
} | ||
else if (password !== undefined) { | ||
this.link = new link_1.PasswordLink(instance, user, password, restrictLogin); | ||
this.link = new link_1.PasswordLink(url, user, password, restrictLogin); | ||
} | ||
else { | ||
this.link = new link_1.ApiKeyLink(instance, user); | ||
this.link = new link_1.ApiKeyLink(url, user); | ||
} | ||
} | ||
async version() { | ||
let version = await this.link.get("version", validators_1.object(types_1.VersionSpec)); | ||
let version = await this.link.get("version", (0, validators_1.object)(types_1.VersionSpec)); | ||
return version.version; | ||
} | ||
whoami() { | ||
return this.link.get("whoami", validators_1.object(types_1.UserSpec)); | ||
return this.link.get("whoami", (0, validators_1.object)(types_1.UserSpec)); | ||
} | ||
async bugHistory(bugId, since) { | ||
let params = undefined; | ||
let searchParams; | ||
if (since) { | ||
params = new url_1.URLSearchParams(); | ||
params.set("new_since", since.toISODate()); | ||
searchParams = new url_1.URLSearchParams(); | ||
searchParams.set("new_since", since.toISODate()); | ||
} | ||
let bugs = await this.link.get(`bug/${bugId}/history`, validators_1.object(types_1.HistoryLookupSpec), params); | ||
if (bugs.bugs.length == 0) { | ||
let bugs = await this.link.get(`bug/${bugId}/history`, (0, validators_1.object)(types_1.HistoryLookupSpec), searchParams); | ||
let [bug] = bugs.bugs; | ||
if (!bug) { | ||
throw new Error("Bug not found."); | ||
} | ||
return bugs.bugs[0].history; | ||
return bug.history; | ||
} | ||
searchBugs(query) { | ||
return new query_1.FilteredQuery(async (includes, excludes) => { | ||
let search = link_1.params(query); | ||
let search = (0, link_1.params)(query); | ||
if (includes) { | ||
@@ -52,4 +51,4 @@ search.set("include_fields", includes.join(",")); | ||
} | ||
let result = await this.link.get("bug", validators_1.object({ | ||
bugs: validators_1.array(validators_1.object(types_1.BugSpec, includes, excludes)), | ||
let result = await this.link.get("bug", (0, validators_1.object)({ | ||
bugs: (0, validators_1.array)((0, validators_1.object)(types_1.BugSpec, includes, excludes)), | ||
}), search); | ||
@@ -70,13 +69,17 @@ return result.bugs; | ||
advancedSearch(query) { | ||
let searchParams; | ||
if (query instanceof url_1.URL) { | ||
query = query.searchParams; | ||
searchParams = query.searchParams; | ||
} | ||
else if (typeof query == "string" && query.startsWith("http")) { | ||
query = new url_1.URL(query).searchParams; | ||
searchParams = new url_1.URL(query).searchParams; | ||
} | ||
if (!(query instanceof url_1.URLSearchParams)) { | ||
query = new url_1.URLSearchParams(query); | ||
else if (query instanceof url_1.URLSearchParams) { | ||
searchParams = query; | ||
} | ||
query.delete("list_id"); | ||
return this.searchBugs(query); | ||
else { | ||
searchParams = new url_1.URLSearchParams(query); | ||
} | ||
searchParams.delete("list_id"); | ||
return this.searchBugs(searchParams); | ||
} | ||
@@ -83,0 +86,0 @@ } |
/// <reference types="node" /> | ||
import { URLSearchParams, URL } from "url"; | ||
import type { RequestInit, Response } from "node-fetch"; | ||
import type { Validator } from "./validators"; | ||
import { AxiosRequestConfig } from "axios"; | ||
import { Validator } from "./validators"; | ||
export declare type SearchParams = Record<string, string> | [string, string][] | string | URLSearchParams; | ||
@@ -15,10 +15,9 @@ export declare function params(search: SearchParams): URLSearchParams; | ||
constructor(instance: URL); | ||
protected abstract request(url: URL, options: RequestInit): Promise<Response>; | ||
protected abstract request<T>(config: AxiosRequestConfig, validator: Validator<T>): Promise<T>; | ||
protected buildURL(path: string, query?: SearchParams): URL; | ||
protected processResponse<T>(response: Response, validator: Validator<T>): Promise<T>; | ||
get<T>(path: string, validator: Validator<T>, params?: SearchParams): Promise<T>; | ||
post<R, T>(path: string, validator: Validator<T>, content: R, params?: SearchParams): Promise<T>; | ||
get<T>(path: string, validator: Validator<T>, searchParams?: SearchParams): Promise<T>; | ||
post<R, T>(path: string, validator: Validator<T>, content: R, searchParams?: SearchParams): Promise<T>; | ||
} | ||
export declare class PublicLink extends BugzillaLink { | ||
protected request(url: URL, options: RequestInit): Promise<Response>; | ||
protected request<T>(config: AxiosRequestConfig, validator: Validator<T>): Promise<T>; | ||
} | ||
@@ -31,3 +30,3 @@ /** | ||
constructor(instance: URL, apiKey: string); | ||
protected request(url: URL, options: RequestInit): Promise<Response>; | ||
protected request<T>(config: AxiosRequestConfig, validator: Validator<T>): Promise<T>; | ||
} | ||
@@ -44,3 +43,4 @@ /** | ||
private login; | ||
protected request(url: URL, options: RequestInit): Promise<Response>; | ||
protected request<T>(config: AxiosRequestConfig, validator: Validator<T>): Promise<T>; | ||
} | ||
//# sourceMappingURL=link.d.ts.map |
128
dist/link.js
@@ -8,3 +8,5 @@ "use strict"; | ||
const url_1 = require("url"); | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
const axios_1 = __importDefault(require("axios")); | ||
const validators_1 = require("./validators"); | ||
const types_1 = require("./types"); | ||
function params(search) { | ||
@@ -17,2 +19,31 @@ if (search instanceof url_1.URLSearchParams) { | ||
exports.params = params; | ||
function isError(payload) { | ||
// @ts-ignore | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
return payload && typeof payload == "object" && payload.error; | ||
} | ||
async function performRequest(config, validator) { | ||
var _a; | ||
try { | ||
let response = await axios_1.default.request({ | ||
...config, | ||
headers: { | ||
Accept: "application/json", | ||
...((_a = config.headers) !== null && _a !== void 0 ? _a : {}), | ||
}, | ||
}); | ||
if (isError(response.data)) { | ||
throw new Error(response.data.message); | ||
} | ||
return validator(response.data); | ||
} | ||
catch (e) { | ||
if (axios_1.default.isAxiosError(e)) { | ||
throw new Error(e.message); | ||
} | ||
else { | ||
throw e; | ||
} | ||
} | ||
} | ||
/** | ||
@@ -34,36 +65,16 @@ * Responsible for requesting data from the bugzilla instance handling any | ||
} | ||
async processResponse(response, validator) { | ||
if (!response.ok) { | ||
throw new Error(response.statusText); | ||
} | ||
let body = await response.json(); | ||
if (body.error) { | ||
throw new Error(body.message); | ||
} | ||
return validator(body); | ||
async get(path, validator, searchParams) { | ||
return this.request({ | ||
url: this.buildURL(path, searchParams).toString(), | ||
}, validator); | ||
} | ||
async get(path, validator, params) { | ||
let response = await this.request(this.buildURL(path, params), { | ||
method: "GET", | ||
redirect: "follow", | ||
headers: { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
Accept: "application/json", | ||
}, | ||
}); | ||
return this.processResponse(response, validator); | ||
} | ||
async post(path, validator, content, params) { | ||
let response = await this.request(this.buildURL(path, params), { | ||
async post(path, validator, content, searchParams) { | ||
return this.request({ | ||
url: this.buildURL(path, searchParams).toString(), | ||
method: "POST", | ||
body: JSON.stringify(content), | ||
redirect: "follow", | ||
data: JSON.stringify(content), | ||
headers: { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
"Accept": "application/json", | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
return this.processResponse(response, validator); | ||
}, validator); | ||
} | ||
@@ -73,4 +84,4 @@ } | ||
class PublicLink extends BugzillaLink { | ||
async request(url, options) { | ||
return node_fetch_1.default(url, options); | ||
async request(config, validator) { | ||
return performRequest(config, validator); | ||
} | ||
@@ -87,12 +98,11 @@ } | ||
} | ||
async request(url, options) { | ||
async request(config, validator) { | ||
var _a; | ||
return node_fetch_1.default(url, { | ||
...options, | ||
return performRequest({ | ||
...config, | ||
headers: { | ||
...(_a = options.headers) !== null && _a !== void 0 ? _a : {}, | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
...((_a = config.headers) !== null && _a !== void 0 ? _a : {}), | ||
"X-BUGZILLA-API-KEY": this.apiKey, | ||
}, | ||
}); | ||
}, validator); | ||
} | ||
@@ -110,25 +120,15 @@ } | ||
this.restrictLogin = restrictLogin; | ||
this.token = "bad"; | ||
this.token = null; | ||
} | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
async login() { | ||
let response = await node_fetch_1.default(this.buildURL("/rest/login", { | ||
restrict_login: String(this.restrictLogin), | ||
}), { | ||
method: "GET", | ||
redirect: "follow", | ||
headers: { | ||
"Accept": "application/json", | ||
"X-BUGZILLA-LOGIN": this.username, | ||
"X-BUGZILLA-PASSWORD": this.password, | ||
}, | ||
}); | ||
if (!response.ok) { | ||
let body = await response.json(); | ||
throw new Error(body.message); | ||
} | ||
throw new Error("Block"); | ||
let loginInfo = await performRequest({ | ||
url: this.buildURL("login", { | ||
login: this.username, | ||
password: this.password, | ||
restrict_login: String(this.restrictLogin), | ||
}).toString(), | ||
}, (0, validators_1.object)(types_1.LoginResponseSpec)); | ||
return loginInfo.token; | ||
} | ||
/* eslint-enable @typescript-eslint/naming-convention */ | ||
async request(url, options) { | ||
async request(config, validator) { | ||
var _a; | ||
@@ -138,13 +138,9 @@ if (!this.token) { | ||
} | ||
let response = await node_fetch_1.default(url, { | ||
...options, | ||
return performRequest({ | ||
...config, | ||
headers: { | ||
...(_a = options.headers) !== null && _a !== void 0 ? _a : {}, | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
...((_a = config.headers) !== null && _a !== void 0 ? _a : {}), | ||
"X-BUGZILLA-TOKEN": this.token, | ||
}, | ||
}); | ||
console.log(response.ok, response.status, response.statusText); | ||
console.log(await response.json()); | ||
return response; | ||
}, validator); | ||
} | ||
@@ -151,0 +147,0 @@ } |
@@ -24,1 +24,2 @@ declare type ExposedPromiseKeys = "then" | "finally" | "catch"; | ||
export {}; | ||
//# sourceMappingURL=query.d.ts.map |
import type { DateTime } from "luxon"; | ||
import { int, datetime } from "./validators"; | ||
import { int, datetime, ObjectSpec } from "./validators"; | ||
declare type int = number; | ||
declare type datetime = DateTime; | ||
export interface LoginResponse { | ||
id: int; | ||
token: string; | ||
} | ||
export declare const LoginResponseSpec: ObjectSpec<LoginResponse>; | ||
export interface Version { | ||
version: string; | ||
} | ||
export declare const VersionSpec: { | ||
version: import("./validators").Validator<string>; | ||
}; | ||
export declare const VersionSpec: ObjectSpec<Version>; | ||
export interface User { | ||
id: number; | ||
id: int; | ||
name: string; | ||
real_name: string; | ||
} | ||
export declare const UserSpec: { | ||
id: import("./validators").Validator<number>; | ||
name: import("./validators").Validator<string>; | ||
real_name: import("./validators").Validator<string>; | ||
}; | ||
export declare const UserSpec: ObjectSpec<User>; | ||
export interface Flag { | ||
@@ -31,14 +30,5 @@ id: int; | ||
} | ||
export declare const FlagSpec: { | ||
id: import("./validators").Validator<number>; | ||
name: import("./validators").Validator<string>; | ||
type_id: import("./validators").Validator<number>; | ||
creation_date: typeof datetime; | ||
modification_date: typeof datetime; | ||
status: import("./validators").Validator<string>; | ||
setter: import("./validators").Validator<string>; | ||
requestee: import("./validators").Validator<string | undefined>; | ||
}; | ||
export declare const FlagSpec: ObjectSpec<Flag>; | ||
export interface Bug { | ||
alias: string[]; | ||
alias: string | string[]; | ||
assigned_to: string; | ||
@@ -50,3 +40,3 @@ assigned_to_detail: User; | ||
classification: string; | ||
component: string; | ||
component: string | string[]; | ||
creation_time: datetime; | ||
@@ -57,3 +47,3 @@ creator: string; | ||
dupe_of: int | null; | ||
flags: Flag[]; | ||
flags: Flag[] | undefined; | ||
groups: string[]; | ||
@@ -72,3 +62,3 @@ id: int; | ||
qa_contact: string; | ||
qa_contact_detail?: User[]; | ||
qa_contact_detail?: User; | ||
resolution: string; | ||
@@ -82,70 +72,6 @@ see_also: string[]; | ||
url: string; | ||
version: string; | ||
version: string | string[]; | ||
whiteboard: string; | ||
} | ||
export declare const BugSpec: { | ||
alias: import("./validators").Validator<string[]>; | ||
assigned_to: import("./validators").Validator<string>; | ||
assigned_to_detail: import("./validators").Validator<{ | ||
id: number; | ||
name: string; | ||
real_name: string; | ||
}>; | ||
blocks: import("./validators").Validator<number[]>; | ||
cc: import("./validators").Validator<string[]>; | ||
cc_detail: import("./validators").Validator<{ | ||
id: number; | ||
name: string; | ||
real_name: string; | ||
}[]>; | ||
classification: import("./validators").Validator<string>; | ||
component: import("./validators").Validator<string>; | ||
creation_time: typeof datetime; | ||
creator: import("./validators").Validator<string>; | ||
creator_detail: import("./validators").Validator<{ | ||
id: number; | ||
name: string; | ||
real_name: string; | ||
}>; | ||
depends_on: import("./validators").Validator<number[]>; | ||
dupe_of: import("./validators").Validator<number | null>; | ||
flags: import("./validators").Validator<{ | ||
id: number; | ||
name: string; | ||
type_id: number; | ||
creation_date: DateTime; | ||
modification_date: DateTime; | ||
status: string; | ||
setter: string; | ||
requestee: string | undefined; | ||
}[]>; | ||
groups: import("./validators").Validator<string[]>; | ||
id: import("./validators").Validator<number>; | ||
is_cc_accessible: import("./validators").Validator<boolean>; | ||
is_confirmed: import("./validators").Validator<boolean>; | ||
is_open: import("./validators").Validator<boolean>; | ||
is_creator_accessible: import("./validators").Validator<boolean>; | ||
keywords: import("./validators").Validator<string[]>; | ||
last_change_time: typeof datetime; | ||
op_sys: import("./validators").Validator<string>; | ||
platform: import("./validators").Validator<string>; | ||
priority: import("./validators").Validator<string>; | ||
product: import("./validators").Validator<string>; | ||
qa_contact: import("./validators").Validator<string>; | ||
qa_contact_detail: import("./validators").Validator<{ | ||
id: number; | ||
name: string; | ||
real_name: string; | ||
}[] | undefined>; | ||
resolution: import("./validators").Validator<string>; | ||
see_also: import("./validators").Validator<string[]>; | ||
severity: import("./validators").Validator<string>; | ||
status: import("./validators").Validator<string>; | ||
summary: import("./validators").Validator<string>; | ||
target_milestone: import("./validators").Validator<string>; | ||
update_token: import("./validators").Validator<string | undefined>; | ||
url: import("./validators").Validator<string>; | ||
version: import("./validators").Validator<string>; | ||
whiteboard: import("./validators").Validator<string>; | ||
}; | ||
export declare const BugSpec: ObjectSpec<Bug>; | ||
export interface Change { | ||
@@ -157,8 +83,3 @@ field_name: string; | ||
} | ||
export declare const ChangeSpec: { | ||
field_name: import("./validators").Validator<string>; | ||
removed: import("./validators").Validator<string>; | ||
added: import("./validators").Validator<string>; | ||
attachment_id: import("./validators").Validator<number | undefined>; | ||
}; | ||
export declare const ChangeSpec: ObjectSpec<Change>; | ||
export interface History { | ||
@@ -169,12 +90,3 @@ when: datetime; | ||
} | ||
export declare const HistorySpec: { | ||
when: typeof datetime; | ||
who: import("./validators").Validator<string>; | ||
changes: import("./validators").Validator<{ | ||
field_name: string; | ||
removed: string; | ||
added: string; | ||
attachment_id: number | undefined; | ||
}[]>; | ||
}; | ||
export declare const HistorySpec: ObjectSpec<History>; | ||
export interface BugHistory { | ||
@@ -185,30 +97,8 @@ id: int; | ||
} | ||
export declare const BugHistorySpec: { | ||
id: import("./validators").Validator<number>; | ||
alias: import("./validators").Validator<string[]>; | ||
history: import("./validators").Validator<{ | ||
when: DateTime; | ||
who: string; | ||
changes: { | ||
field_name: any; | ||
removed: any; | ||
added: any; | ||
attachment_id: any; | ||
}[]; | ||
}[]>; | ||
}; | ||
export declare const BugHistorySpec: ObjectSpec<BugHistory>; | ||
export interface HistoryLookup { | ||
bugs: BugHistory[]; | ||
} | ||
export declare const HistoryLookupSpec: { | ||
bugs: import("./validators").Validator<{ | ||
id: number; | ||
alias: string[]; | ||
history: { | ||
when: any; | ||
who: any; | ||
changes: any; | ||
}[]; | ||
}[]>; | ||
}; | ||
export declare const HistoryLookupSpec: ObjectSpec<HistoryLookup>; | ||
export {}; | ||
//# sourceMappingURL=types.d.ts.map |
"use strict"; | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.HistoryLookupSpec = exports.BugHistorySpec = exports.HistorySpec = exports.ChangeSpec = exports.BugSpec = exports.FlagSpec = exports.UserSpec = exports.VersionSpec = void 0; | ||
exports.HistoryLookupSpec = exports.BugHistorySpec = exports.HistorySpec = exports.ChangeSpec = exports.BugSpec = exports.FlagSpec = exports.UserSpec = exports.VersionSpec = exports.LoginResponseSpec = void 0; | ||
const validators_1 = require("./validators"); | ||
exports.LoginResponseSpec = { | ||
id: validators_1.int, | ||
token: validators_1.string, | ||
}; | ||
exports.VersionSpec = { | ||
@@ -22,20 +25,20 @@ version: validators_1.string, | ||
setter: validators_1.string, | ||
requestee: validators_1.optional(validators_1.string), | ||
requestee: (0, validators_1.optional)(validators_1.string), | ||
}; | ||
exports.BugSpec = { | ||
alias: validators_1.array(validators_1.string), | ||
alias: (0, validators_1.nullable)((0, validators_1.maybeArray)(validators_1.string), []), | ||
assigned_to: validators_1.string, | ||
assigned_to_detail: validators_1.object(exports.UserSpec), | ||
blocks: validators_1.array(validators_1.int), | ||
cc: validators_1.array(validators_1.string), | ||
cc_detail: validators_1.array(validators_1.object(exports.UserSpec)), | ||
assigned_to_detail: (0, validators_1.object)(exports.UserSpec), | ||
blocks: (0, validators_1.array)(validators_1.int), | ||
cc: (0, validators_1.array)(validators_1.string), | ||
cc_detail: (0, validators_1.array)((0, validators_1.object)(exports.UserSpec)), | ||
classification: validators_1.string, | ||
component: validators_1.string, | ||
component: (0, validators_1.maybeArray)(validators_1.string), | ||
creation_time: validators_1.datetime, | ||
creator: validators_1.string, | ||
creator_detail: validators_1.object(exports.UserSpec), | ||
depends_on: validators_1.array(validators_1.int), | ||
dupe_of: validators_1.nullable(validators_1.int), | ||
flags: validators_1.array(validators_1.object(exports.FlagSpec)), | ||
groups: validators_1.array(validators_1.string), | ||
creator_detail: (0, validators_1.object)(exports.UserSpec), | ||
depends_on: (0, validators_1.array)(validators_1.int), | ||
dupe_of: (0, validators_1.nullable)(validators_1.int), | ||
flags: (0, validators_1.optional)((0, validators_1.array)((0, validators_1.object)(exports.FlagSpec))), | ||
groups: (0, validators_1.array)(validators_1.string), | ||
id: validators_1.int, | ||
@@ -46,3 +49,3 @@ is_cc_accessible: validators_1.boolean, | ||
is_creator_accessible: validators_1.boolean, | ||
keywords: validators_1.array(validators_1.string), | ||
keywords: (0, validators_1.array)(validators_1.string), | ||
last_change_time: validators_1.datetime, | ||
@@ -54,5 +57,5 @@ op_sys: validators_1.string, | ||
qa_contact: validators_1.string, | ||
qa_contact_detail: validators_1.optional(validators_1.array(validators_1.object(exports.UserSpec))), | ||
qa_contact_detail: (0, validators_1.optional)((0, validators_1.object)(exports.UserSpec)), | ||
resolution: validators_1.string, | ||
see_also: validators_1.array(validators_1.string), | ||
see_also: (0, validators_1.array)(validators_1.string), | ||
severity: validators_1.string, | ||
@@ -62,5 +65,5 @@ status: validators_1.string, | ||
target_milestone: validators_1.string, | ||
update_token: validators_1.optional(validators_1.string), | ||
update_token: (0, validators_1.optional)(validators_1.string), | ||
url: validators_1.string, | ||
version: validators_1.string, | ||
version: (0, validators_1.maybeArray)(validators_1.string), | ||
whiteboard: validators_1.string, | ||
@@ -72,3 +75,3 @@ }; | ||
added: validators_1.string, | ||
attachment_id: validators_1.optional(validators_1.int), | ||
attachment_id: (0, validators_1.optional)(validators_1.int), | ||
}; | ||
@@ -78,12 +81,12 @@ exports.HistorySpec = { | ||
who: validators_1.string, | ||
changes: validators_1.array(validators_1.object(exports.ChangeSpec)), | ||
changes: (0, validators_1.array)((0, validators_1.object)(exports.ChangeSpec)), | ||
}; | ||
exports.BugHistorySpec = { | ||
id: validators_1.int, | ||
alias: validators_1.array(validators_1.string), | ||
history: validators_1.array(validators_1.object(exports.HistorySpec)), | ||
alias: (0, validators_1.array)(validators_1.string), | ||
history: (0, validators_1.array)((0, validators_1.object)(exports.HistorySpec)), | ||
}; | ||
exports.HistoryLookupSpec = { | ||
bugs: validators_1.array(validators_1.object(exports.BugHistorySpec)), | ||
bugs: (0, validators_1.array)((0, validators_1.object)(exports.BugHistorySpec)), | ||
}; | ||
//# sourceMappingURL=types.js.map |
import { DateTime } from "luxon"; | ||
export declare type Validator<T> = (val: any) => T; | ||
declare type ObjectValidator<T> = { | ||
export declare type ObjectSpec<T> = Record<string, Validator<any>> & { | ||
[K in keyof T]: Validator<T[K]>; | ||
}; | ||
export declare function object<T>(validator: ObjectValidator<T>, includes?: string[], excludes?: string[]): Validator<T>; | ||
export declare function object<T>(validator: ObjectSpec<T>, includes?: string[], excludes?: string[]): Validator<T>; | ||
export declare function array<T>(validator: Validator<T>): Validator<T[]>; | ||
@@ -17,2 +17,3 @@ export declare function datetime(val: any): DateTime; | ||
export declare function optional<T>(validator: Validator<T>, result: T): Validator<T>; | ||
export {}; | ||
export declare function maybeArray<T>(validator: Validator<T>): Validator<T | T[]>; | ||
//# sourceMappingURL=validators.d.ts.map |
"use strict"; | ||
/* eslint-disable @typescript-eslint/no-unsafe-return */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.optional = exports.nullable = exports.string = exports.double = exports.int = exports.boolean = exports.datetime = exports.array = exports.object = void 0; | ||
exports.maybeArray = exports.optional = exports.nullable = exports.string = exports.double = exports.int = exports.boolean = exports.datetime = exports.array = exports.object = void 0; | ||
const luxon_1 = require("luxon"); | ||
function repr(val) { | ||
return `\`${JSON.stringify(val)}\``; | ||
} | ||
function object(validator, includes = Object.keys(validator), excludes = []) { | ||
return (val) => { | ||
if (!val || typeof val != "object") { | ||
throw new Error(`Expected an object but received '${val}'`); | ||
throw new Error(`Expected an object but received ${repr(val)}`); | ||
} | ||
@@ -18,6 +18,6 @@ let result = {}; | ||
} | ||
if (!(field in validator)) { | ||
let fieldValidator = validator[field]; | ||
if (!fieldValidator) { | ||
continue; | ||
} | ||
let fieldValidator = validator[field]; | ||
try { | ||
@@ -36,8 +36,4 @@ result[field] = fieldValidator(val[field]); | ||
return (val) => { | ||
// Empty arrays are returned as null. | ||
if (val === null) { | ||
return []; | ||
} | ||
if (!Array.isArray(val)) { | ||
return [validator(val)]; | ||
throw new Error(`Expected an array but received ${repr(val)}`); | ||
} | ||
@@ -56,3 +52,3 @@ try { | ||
if (val === null || typeof val != type) { | ||
throw new Error(`Expected a ${type} but received '${val}'`); | ||
throw new Error(`Expected a ${type} but received ${repr(val)}`); | ||
} | ||
@@ -64,5 +60,9 @@ return val; | ||
if (typeof val != "string") { | ||
throw new Error(`Expected a string but received '${val}'`); | ||
throw new Error(`Expected an ISO-8601 string but received ${repr(val)}`); | ||
} | ||
return luxon_1.DateTime.fromISO(val); | ||
let dt = luxon_1.DateTime.fromISO(val); | ||
if (!dt.isValid) { | ||
throw new Error(`Expected an ISO-8601 string but received ${repr(val)}`); | ||
} | ||
return dt; | ||
} | ||
@@ -92,2 +92,16 @@ exports.datetime = datetime; | ||
exports.optional = optional; | ||
function maybeArray(validator) { | ||
return (val) => { | ||
if (Array.isArray(val)) { | ||
try { | ||
return val.map(validator); | ||
} | ||
catch (e) { | ||
throw new Error(`Error validating array: ${e.message}`); | ||
} | ||
} | ||
return validator(val); | ||
}; | ||
} | ||
exports.maybeArray = maybeArray; | ||
//# sourceMappingURL=validators.js.map |
{ | ||
"name": "bugzilla", | ||
"version": "1.1.6", | ||
"version": "2.0.0", | ||
"description": "A NodeJS module to access Bugzilla instances through the REST API.", | ||
@@ -10,5 +10,8 @@ "main": "dist/index.js", | ||
"build": "tsc -b tsconfig.build.json", | ||
"lint": "eslint .", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"prepack": "npm run build" | ||
"lint": "eslint . && prettier --check .", | ||
"prettier": "prettier --write .", | ||
"test": "jest --coverage", | ||
"prepack": "npm run build", | ||
"version": "node scripts/version.js", | ||
"postversion": "node scripts/post-version.js && git add CHANGELOG.md && git commit -m 'Update CHANGELOG.md'" | ||
}, | ||
@@ -33,17 +36,24 @@ "repository": { | ||
"devDependencies": { | ||
"@types/luxon": "^1.26.0", | ||
"@types/node": "^14.14.28", | ||
"@types/node-fetch": "^2.5.8", | ||
"@typescript-eslint/eslint-plugin": "^4.15.1", | ||
"@typescript-eslint/parser": "^4.15.1", | ||
"eslint": "^7.20.0", | ||
"@mossop/config": "1.0.5", | ||
"@types/jest": "^27.4.0", | ||
"@types/luxon": "^2.0.9", | ||
"@types/node": "^17.0.9", | ||
"@typescript-eslint/eslint-plugin": "^5.9.1", | ||
"@typescript-eslint/parser": "^5.9.1", | ||
"eslint": "^8.7.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-config-airbnb-typescript": "^16.1.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-import-resolver-ts": "^0.4.2", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-mossop": "github:Mossop/eslint-plugin-mossop#1.0.12", | ||
"typescript": "^4.1.5" | ||
"eslint-plugin-import": "^2.25.4", | ||
"jest": "^27.4.7", | ||
"msw": "^0.36.4", | ||
"prettier": "^2.5.1", | ||
"ts-jest": "^27.1.3", | ||
"typescript": "^4.5.4" | ||
}, | ||
"dependencies": { | ||
"luxon": "^1.26.0", | ||
"node-fetch": "^2.6.1" | ||
"axios": "^0.26.0", | ||
"luxon": "^2.3.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# Bugzilla | ||
# Bugzilla | [](https://www.npmjs.com/package/bugzilla) [](https://github.com/Mossop/bugzilla-ts/actions/workflows/build.yml) [](https://codecov.io/gh/Mossop/bugzilla-ts) | ||
@@ -26,3 +26,7 @@ Typesafe access to [Bugzilla's REST API](https://bugzilla.readthedocs.io/en/latest/api/index.html). | ||
let api = new BugzillaAPI("https://bugzilla.mozilla.org", "<username>", "<password>"); | ||
let api = new BugzillaAPI( | ||
"https://bugzilla.mozilla.org", | ||
"<username>", | ||
"<password>", | ||
); | ||
await api.version(); | ||
@@ -34,4 +38,2 @@ ``` | ||
```javascript | ||
let bug = await api.getBug(123456); | ||
let bugs = await api.getBugs([123456, 123457]); | ||
@@ -42,3 +44,3 @@ ``` | ||
You can use a quicksearch string: | ||
You can use a `quicksearch` string: | ||
@@ -53,6 +55,10 @@ ```javascript | ||
// You can just pass a full advanced search url: | ||
let bugs = await api.advancedSearch("https://bugzilla.mozilla.org/buglist.cgi?email1=dtownsend%40mozilla.com&emailassigned_to1=1&resolution=---&emailtype1=exact&list_id=15603348"); | ||
let bugs = await api.advancedSearch( | ||
"https://bugzilla.mozilla.org/buglist.cgi?email1=dtownsend%40mozilla.com&emailassigned_to1=1&resolution=---&emailtype1=exact&list_id=15603348", | ||
); | ||
// Or just the query string part: | ||
let bugs = await api.advancedSearch("email1=dtownsend%40mozilla.com&emailassigned_to1=1&resolution=---&emailtype1=exact&list_id=15603348"); | ||
let bugs = await api.advancedSearch( | ||
"email1=dtownsend%40mozilla.com&emailassigned_to1=1&resolution=---&emailtype1=exact&list_id=15603348", | ||
); | ||
@@ -75,6 +81,6 @@ // Or as a record: | ||
// To only retrieve certain fields. | ||
let bug = await api.getBug(123456).include(["id", "product", "component"]); | ||
let bug = await api.getBugs([123456]).include(["id", "product", "component"]); | ||
// Or to filter out certain fields. | ||
let bug = await api.getBug(123456).exclude(["cc_detail"]); | ||
let bug = await api.getBugs([123456]).exclude(["cc_detail"]); | ||
``` | ||
@@ -81,0 +87,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
68094
29
1299
0
89
17
1
+ Addedaxios@^0.26.0
+ Addedaxios@0.26.1(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
+ Addedluxon@2.5.2(transitive)
- Removednode-fetch@^2.6.1
- Removedluxon@1.28.1(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removedtr46@0.0.3(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)
Updatedluxon@^2.3.0