e621-client 1.2.0 → 1.2.2
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.
|
@@ -23,6 +23,7 @@ class E621ApiClient {
|
|
|
23
23
|
this.isBrowser = options.isBrowser;
|
|
24
24
|
this.credentials = options.credentials || null;
|
|
25
25
|
this.batchRateLimit = options.batchRateLimit || 0;
|
|
26
|
+
this.debugLogs = options.debugLogs || false;
|
|
26
27
|
}
|
|
27
28
|
// Users
|
|
28
29
|
getUsers() {
|
|
@@ -120,7 +121,7 @@ class E621ApiClient {
|
|
|
120
121
|
return null;
|
|
121
122
|
}
|
|
122
123
|
else {
|
|
123
|
-
throw new Error(`Request to ${route} failed with status code ${response.status}`);
|
|
124
|
+
throw new Error(`Request to ${route} failed with status code ${response.status}: "${response.statusText}"`);
|
|
124
125
|
}
|
|
125
126
|
});
|
|
126
127
|
}
|
package/package.json
CHANGED
|
@@ -79,7 +79,7 @@ describe("E621ApiClient", () => {
|
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
it("should add the query parameters properly", async () => {
|
|
82
|
-
const client = createClient(
|
|
82
|
+
const client = createClient();
|
|
83
83
|
|
|
84
84
|
await client.get({
|
|
85
85
|
route: "test",
|
|
@@ -93,6 +93,41 @@ describe("E621ApiClient", () => {
|
|
|
93
93
|
expect.anything(),
|
|
94
94
|
);
|
|
95
95
|
});
|
|
96
|
+
|
|
97
|
+
it("should pass the credentials in the Authorization header", async () => {
|
|
98
|
+
const client = createClient();
|
|
99
|
+
client.setCredentials({ username: "jest", apiKey: "key" });
|
|
100
|
+
|
|
101
|
+
const expectedHeader = {
|
|
102
|
+
Authorization: `Basic ${Buffer.from("jest:key").toString("base64")}`,
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
await client.get({ route: "test" });
|
|
106
|
+
|
|
107
|
+
expect(fetchMock).toHaveBeenCalledWith(
|
|
108
|
+
expect.anything(),
|
|
109
|
+
expect.objectContaining({
|
|
110
|
+
headers: expect.objectContaining(expectedHeader),
|
|
111
|
+
}),
|
|
112
|
+
);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("should stop passing the credentials when clearing them", async () => {
|
|
116
|
+
const client = createClient();
|
|
117
|
+
client.setCredentials({ username: "jest", apiKey: "key" });
|
|
118
|
+
client.setCredentials(null);
|
|
119
|
+
|
|
120
|
+
await client.get({ route: "test" });
|
|
121
|
+
|
|
122
|
+
expect(fetchMock).toHaveBeenCalledWith(
|
|
123
|
+
expect.anything(),
|
|
124
|
+
expect.objectContaining({
|
|
125
|
+
headers: expect.not.objectContaining({
|
|
126
|
+
Authorization: expect.anything(),
|
|
127
|
+
}),
|
|
128
|
+
}),
|
|
129
|
+
);
|
|
130
|
+
});
|
|
96
131
|
});
|
|
97
132
|
|
|
98
133
|
describe("specific endpoints", () => {
|
|
@@ -80,6 +80,7 @@ export class E621ApiClient {
|
|
|
80
80
|
this.isBrowser = options.isBrowser;
|
|
81
81
|
this.credentials = options.credentials || null;
|
|
82
82
|
this.batchRateLimit = options.batchRateLimit || 0;
|
|
83
|
+
this.debugLogs = options.debugLogs || false;
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
// Users
|
|
@@ -186,7 +187,7 @@ export class E621ApiClient {
|
|
|
186
187
|
return null;
|
|
187
188
|
} else {
|
|
188
189
|
throw new Error(
|
|
189
|
-
`Request to ${route} failed with status code ${response.status}`,
|
|
190
|
+
`Request to ${route} failed with status code ${response.status}: "${response.statusText}"`,
|
|
190
191
|
);
|
|
191
192
|
}
|
|
192
193
|
}
|