e621-client 1.2.0 → 1.2.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.
@@ -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() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "e621-client",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -79,7 +79,7 @@ describe("E621ApiClient", () => {
79
79
  });
80
80
 
81
81
  it("should add the query parameters properly", async () => {
82
- const client = createClient({ isBrowser: false });
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