Skip to content

Commit 5d7f81c

Browse files
committed
debug options is now accessible from instantiation of the API but also possible...
... to override it at the .fetch() level
1 parent 61cdb78 commit 5d7f81c

4 files changed

Lines changed: 10 additions & 2 deletions

File tree

packages/ts-ghost-admin-api/src/admin-api.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
baseSiteSchema,
88
baseTagsSchema,
99
BasicFetcher,
10+
DebugOption,
1011
emailOrIdSchema,
1112
HTTPClientFactory,
1213
slugOrIdSchema,
@@ -31,13 +32,15 @@ export class TSGhostAdminAPI<Version extends `v5.${string}` | `v6.${string}` = a
3132
protected readonly url: string,
3233
protected readonly key: string,
3334
protected readonly version: Version,
35+
protected readonly options?: DebugOption,
3436
) {
3537
const apiCredentials = adminAPICredentialsSchema.parse({
3638
key,
3739
version,
3840
url,
3941
});
4042
this.httpClientFactory = new HTTPClientFactory({
43+
...options,
4144
...apiCredentials,
4245
endpoint: "admin",
4346
});

packages/ts-ghost-content-api/src/content-api.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
HTTPClientFactory,
66
slugOrIdSchema,
77
} from "@ts-ghost/core-api";
8+
import { DebugOption } from "@ts-ghost/core-api/helpers/debug";
89

910
import { authorsIncludeSchema, authorsSchema } from "./authors/schemas";
1011
import { pagesIncludeSchema, pagesSchema } from "./pages/schemas";
@@ -31,13 +32,15 @@ export class TSGhostContentAPI<Version extends `v5.${string}` | `v6.${string}` =
3132
protected readonly url: string,
3233
protected readonly key: string,
3334
protected readonly version: Version,
35+
protected readonly options?: DebugOption,
3436
) {
3537
const apiCredentials = contentAPICredentialsSchema.parse({
3638
key,
3739
version,
3840
url,
3941
});
4042
this.HTTPClientFactoryFactory = new HTTPClientFactory({
43+
...options,
4144
...apiCredentials,
4245
endpoint: "content",
4346
});

packages/ts-ghost-core-api/src/helpers/http-client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type HTTPClientOptions = {
88
version: APICredentials["version"];
99
url: APICredentials["url"];
1010
endpoint: "content" | "admin";
11-
};
11+
} & DebugOption;
1212

1313
export interface IHTTPClient {
1414
get baseURL(): URL | undefined;
@@ -111,7 +111,7 @@ export class HTTPClient<const Options extends HTTPClientOptions = any> implement
111111
options?: RequestInit & DebugOption;
112112
pathnameIdentity?: string;
113113
}) {
114-
const debug = resolveDebugLogger(options);
114+
const debug = resolveDebugLogger({ ...this.config, ...options });
115115
if (this._baseURL === undefined) throw new Error("URL is undefined");
116116
let path = `${resource}/`;
117117
if (pathnameIdentity !== undefined) {
@@ -136,6 +136,7 @@ export class HTTPClient<const Options extends HTTPClientOptions = any> implement
136136
headers,
137137
})
138138
).json();
139+
debug("result", result, "status", result.status);
139140
} catch (e) {
140141
debug("error", e);
141142
return {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from "./browse-params";
22
export * from "./fields";
33
export * from "./http-client";
4+
export * from "./debug";

0 commit comments

Comments
 (0)