@articlesq/sdk 0.0.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.
- package/LICENSE +201 -0
- package/README.md +88 -0
- package/dist/index.cjs +956 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +736 -0
- package/dist/index.d.ts +736 -0
- package/dist/index.js +928 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,736 @@
|
|
|
1
|
+
type AuthToken = string | undefined;
|
|
2
|
+
interface Auth {
|
|
3
|
+
/**
|
|
4
|
+
* Which part of the request do we use to send the auth?
|
|
5
|
+
*
|
|
6
|
+
* @default 'header'
|
|
7
|
+
*/
|
|
8
|
+
in?: "header" | "query" | "cookie";
|
|
9
|
+
/**
|
|
10
|
+
* Header or query parameter name.
|
|
11
|
+
*
|
|
12
|
+
* @default 'Authorization'
|
|
13
|
+
*/
|
|
14
|
+
name?: string;
|
|
15
|
+
scheme?: "basic" | "bearer";
|
|
16
|
+
type: "apiKey" | "http";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface SerializerOptions<T> {
|
|
20
|
+
/**
|
|
21
|
+
* @default true
|
|
22
|
+
*/
|
|
23
|
+
explode: boolean;
|
|
24
|
+
style: T;
|
|
25
|
+
}
|
|
26
|
+
type ArrayStyle = "form" | "spaceDelimited" | "pipeDelimited";
|
|
27
|
+
type ObjectStyle = "form" | "deepObject";
|
|
28
|
+
|
|
29
|
+
type QuerySerializer = (query: Record<string, unknown>) => string;
|
|
30
|
+
type BodySerializer = (body: unknown) => unknown;
|
|
31
|
+
type QuerySerializerOptionsObject = {
|
|
32
|
+
allowReserved?: boolean;
|
|
33
|
+
array?: Partial<SerializerOptions<ArrayStyle>>;
|
|
34
|
+
object?: Partial<SerializerOptions<ObjectStyle>>;
|
|
35
|
+
};
|
|
36
|
+
type QuerySerializerOptions = QuerySerializerOptionsObject & {
|
|
37
|
+
/**
|
|
38
|
+
* Per-parameter serialization overrides. When provided, these settings
|
|
39
|
+
* override the global array/object settings for specific parameter names.
|
|
40
|
+
*/
|
|
41
|
+
parameters?: Record<string, QuerySerializerOptionsObject>;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
type HttpMethod = "connect" | "delete" | "get" | "head" | "options" | "patch" | "post" | "put" | "trace";
|
|
45
|
+
type Client$1<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never, SseFn = never> = {
|
|
46
|
+
/**
|
|
47
|
+
* Returns the final request URL.
|
|
48
|
+
*/
|
|
49
|
+
buildUrl: BuildUrlFn;
|
|
50
|
+
getConfig: () => Config;
|
|
51
|
+
request: RequestFn;
|
|
52
|
+
setConfig: (config: Config) => Config;
|
|
53
|
+
} & {
|
|
54
|
+
[K in HttpMethod]: MethodFn;
|
|
55
|
+
} & ([SseFn] extends [never] ? {
|
|
56
|
+
sse?: never;
|
|
57
|
+
} : {
|
|
58
|
+
sse: {
|
|
59
|
+
[K in HttpMethod]: SseFn;
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
interface Config$1 {
|
|
63
|
+
/**
|
|
64
|
+
* Auth token or a function returning auth token. The resolved value will be
|
|
65
|
+
* added to the request payload as defined by its `security` array.
|
|
66
|
+
*/
|
|
67
|
+
auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
|
|
68
|
+
/**
|
|
69
|
+
* A function for serializing request body parameter. By default,
|
|
70
|
+
* {@link JSON.stringify()} will be used.
|
|
71
|
+
*/
|
|
72
|
+
bodySerializer?: BodySerializer | null;
|
|
73
|
+
/**
|
|
74
|
+
* An object containing any HTTP headers that you want to pre-populate your
|
|
75
|
+
* `Headers` object with.
|
|
76
|
+
*
|
|
77
|
+
* {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
|
|
78
|
+
*/
|
|
79
|
+
headers?: RequestInit["headers"] | Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>;
|
|
80
|
+
/**
|
|
81
|
+
* The request method.
|
|
82
|
+
*
|
|
83
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
|
|
84
|
+
*/
|
|
85
|
+
method?: Uppercase<HttpMethod>;
|
|
86
|
+
/**
|
|
87
|
+
* A function for serializing request query parameters. By default, arrays
|
|
88
|
+
* will be exploded in form style, objects will be exploded in deepObject
|
|
89
|
+
* style, and reserved characters are percent-encoded.
|
|
90
|
+
*
|
|
91
|
+
* This method will have no effect if the native `paramsSerializer()` Axios
|
|
92
|
+
* API function is used.
|
|
93
|
+
*
|
|
94
|
+
* {@link https://swagger.io/docs/specification/serialization/#query View examples}
|
|
95
|
+
*/
|
|
96
|
+
querySerializer?: QuerySerializer | QuerySerializerOptions;
|
|
97
|
+
/**
|
|
98
|
+
* A function validating request data. This is useful if you want to ensure
|
|
99
|
+
* the request conforms to the desired shape, so it can be safely sent to
|
|
100
|
+
* the server.
|
|
101
|
+
*/
|
|
102
|
+
requestValidator?: (data: unknown) => Promise<unknown>;
|
|
103
|
+
/**
|
|
104
|
+
* A function transforming response data before it's returned. This is useful
|
|
105
|
+
* for post-processing data, e.g., converting ISO strings into Date objects.
|
|
106
|
+
*/
|
|
107
|
+
responseTransformer?: (data: unknown) => Promise<unknown>;
|
|
108
|
+
/**
|
|
109
|
+
* A function validating response data. This is useful if you want to ensure
|
|
110
|
+
* the response conforms to the desired shape, so it can be safely passed to
|
|
111
|
+
* the transformers and returned to the user.
|
|
112
|
+
*/
|
|
113
|
+
responseValidator?: (data: unknown) => Promise<unknown>;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
type ServerSentEventsOptions<TData = unknown> = Omit<RequestInit, "method"> & Pick<Config$1, "method" | "responseTransformer" | "responseValidator"> & {
|
|
117
|
+
/**
|
|
118
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
119
|
+
* fetch instance.
|
|
120
|
+
*
|
|
121
|
+
* @default globalThis.fetch
|
|
122
|
+
*/
|
|
123
|
+
fetch?: typeof fetch;
|
|
124
|
+
/**
|
|
125
|
+
* Implementing clients can call request interceptors inside this hook.
|
|
126
|
+
*/
|
|
127
|
+
onRequest?: (url: string, init: RequestInit) => Promise<Request>;
|
|
128
|
+
/**
|
|
129
|
+
* Callback invoked when a network or parsing error occurs during streaming.
|
|
130
|
+
*
|
|
131
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
132
|
+
*
|
|
133
|
+
* @param error The error that occurred.
|
|
134
|
+
*/
|
|
135
|
+
onSseError?: (error: unknown) => void;
|
|
136
|
+
/**
|
|
137
|
+
* Callback invoked when an event is streamed from the server.
|
|
138
|
+
*
|
|
139
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
140
|
+
*
|
|
141
|
+
* @param event Event streamed from the server.
|
|
142
|
+
* @returns Nothing (void).
|
|
143
|
+
*/
|
|
144
|
+
onSseEvent?: (event: StreamEvent<TData>) => void;
|
|
145
|
+
serializedBody?: RequestInit["body"];
|
|
146
|
+
/**
|
|
147
|
+
* Default retry delay in milliseconds.
|
|
148
|
+
*
|
|
149
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
150
|
+
*
|
|
151
|
+
* @default 3000
|
|
152
|
+
*/
|
|
153
|
+
sseDefaultRetryDelay?: number;
|
|
154
|
+
/**
|
|
155
|
+
* Maximum number of retry attempts before giving up.
|
|
156
|
+
*/
|
|
157
|
+
sseMaxRetryAttempts?: number;
|
|
158
|
+
/**
|
|
159
|
+
* Maximum retry delay in milliseconds.
|
|
160
|
+
*
|
|
161
|
+
* Applies only when exponential backoff is used.
|
|
162
|
+
*
|
|
163
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
164
|
+
*
|
|
165
|
+
* @default 30000
|
|
166
|
+
*/
|
|
167
|
+
sseMaxRetryDelay?: number;
|
|
168
|
+
/**
|
|
169
|
+
* Optional sleep function for retry backoff.
|
|
170
|
+
*
|
|
171
|
+
* Defaults to using `setTimeout`.
|
|
172
|
+
*/
|
|
173
|
+
sseSleepFn?: (ms: number) => Promise<void>;
|
|
174
|
+
url: string;
|
|
175
|
+
};
|
|
176
|
+
interface StreamEvent<TData = unknown> {
|
|
177
|
+
data: TData;
|
|
178
|
+
event?: string;
|
|
179
|
+
id?: string;
|
|
180
|
+
retry?: number;
|
|
181
|
+
}
|
|
182
|
+
type ServerSentEventsResult<TData = unknown, TReturn = void, TNext = unknown> = {
|
|
183
|
+
stream: AsyncGenerator<TData extends Record<string, unknown> ? TData[keyof TData] : TData, TReturn, TNext>;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
type ErrInterceptor<Err, Res, Req, Options> = (error: Err,
|
|
187
|
+
/** response may be undefined due to a network error where no response object is produced */
|
|
188
|
+
response: Res | undefined,
|
|
189
|
+
/** request may be undefined, because error may be from building the request object itself */
|
|
190
|
+
request: Req | undefined, options: Options) => Err | Promise<Err>;
|
|
191
|
+
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
|
|
192
|
+
type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>;
|
|
193
|
+
declare class Interceptors<Interceptor> {
|
|
194
|
+
fns: Array<Interceptor | null>;
|
|
195
|
+
clear(): void;
|
|
196
|
+
eject(id: number | Interceptor): void;
|
|
197
|
+
exists(id: number | Interceptor): boolean;
|
|
198
|
+
getInterceptorIndex(id: number | Interceptor): number;
|
|
199
|
+
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false;
|
|
200
|
+
use(fn: Interceptor): number;
|
|
201
|
+
}
|
|
202
|
+
interface Middleware<Req, Res, Err, Options> {
|
|
203
|
+
error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
|
|
204
|
+
request: Interceptors<ReqInterceptor<Req, Options>>;
|
|
205
|
+
response: Interceptors<ResInterceptor<Res, Req, Options>>;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
type ResponseStyle = "data" | "fields";
|
|
209
|
+
interface Config<T extends ClientOptions$1 = ClientOptions$1> extends Omit<RequestInit, "body" | "headers" | "method">, Config$1 {
|
|
210
|
+
/**
|
|
211
|
+
* Base URL for all requests made by this client.
|
|
212
|
+
*/
|
|
213
|
+
baseUrl?: T["baseUrl"];
|
|
214
|
+
/**
|
|
215
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
216
|
+
* fetch instance.
|
|
217
|
+
*
|
|
218
|
+
* @default globalThis.fetch
|
|
219
|
+
*/
|
|
220
|
+
fetch?: typeof fetch;
|
|
221
|
+
/**
|
|
222
|
+
* Please don't use the Fetch client for Next.js applications. The `next`
|
|
223
|
+
* options won't have any effect.
|
|
224
|
+
*
|
|
225
|
+
* Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead.
|
|
226
|
+
*/
|
|
227
|
+
next?: never;
|
|
228
|
+
/**
|
|
229
|
+
* Return the response data parsed in a specified format. By default, `auto`
|
|
230
|
+
* will infer the appropriate method from the `Content-Type` response header.
|
|
231
|
+
* You can override this behavior with any of the {@link Body} methods.
|
|
232
|
+
* Select `stream` if you don't want to parse response data at all.
|
|
233
|
+
*
|
|
234
|
+
* @default 'auto'
|
|
235
|
+
*/
|
|
236
|
+
parseAs?: "arrayBuffer" | "auto" | "blob" | "formData" | "json" | "stream" | "text";
|
|
237
|
+
/**
|
|
238
|
+
* Should we return only data or multiple fields (data, error, response, etc.)?
|
|
239
|
+
*
|
|
240
|
+
* @default 'fields'
|
|
241
|
+
*/
|
|
242
|
+
responseStyle?: ResponseStyle;
|
|
243
|
+
/**
|
|
244
|
+
* Throw an error instead of returning it in the response?
|
|
245
|
+
*
|
|
246
|
+
* @default false
|
|
247
|
+
*/
|
|
248
|
+
throwOnError?: T["throwOnError"];
|
|
249
|
+
}
|
|
250
|
+
interface RequestOptions<TData = unknown, TResponseStyle extends ResponseStyle = "fields", ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
|
|
251
|
+
responseStyle: TResponseStyle;
|
|
252
|
+
throwOnError: ThrowOnError;
|
|
253
|
+
}>, Pick<ServerSentEventsOptions<TData>, "onRequest" | "onSseError" | "onSseEvent" | "sseDefaultRetryDelay" | "sseMaxRetryAttempts" | "sseMaxRetryDelay"> {
|
|
254
|
+
/**
|
|
255
|
+
* Any body that you want to add to your request.
|
|
256
|
+
*
|
|
257
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
|
|
258
|
+
*/
|
|
259
|
+
body?: unknown;
|
|
260
|
+
path?: Record<string, unknown>;
|
|
261
|
+
query?: Record<string, unknown>;
|
|
262
|
+
/**
|
|
263
|
+
* Security mechanism(s) to use for the request.
|
|
264
|
+
*/
|
|
265
|
+
security?: ReadonlyArray<Auth>;
|
|
266
|
+
url: Url;
|
|
267
|
+
}
|
|
268
|
+
interface ResolvedRequestOptions<TResponseStyle extends ResponseStyle = "fields", ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
|
|
269
|
+
headers: Headers;
|
|
270
|
+
serializedBody?: string;
|
|
271
|
+
}
|
|
272
|
+
type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = "fields"> = ThrowOnError extends true ? Promise<TResponseStyle extends "data" ? TData extends Record<string, unknown> ? TData[keyof TData] : TData : {
|
|
273
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
274
|
+
request: Request;
|
|
275
|
+
response: Response;
|
|
276
|
+
}> : Promise<TResponseStyle extends "data" ? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined : ({
|
|
277
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
278
|
+
error: undefined;
|
|
279
|
+
} | {
|
|
280
|
+
data: undefined;
|
|
281
|
+
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
282
|
+
}) & {
|
|
283
|
+
/** request may be undefined, because error may be from building the request object itself */
|
|
284
|
+
request?: Request;
|
|
285
|
+
/** response may be undefined, because error may be from building the request object itself or from a network error */
|
|
286
|
+
response?: Response;
|
|
287
|
+
}>;
|
|
288
|
+
interface ClientOptions$1 {
|
|
289
|
+
baseUrl?: string;
|
|
290
|
+
responseStyle?: ResponseStyle;
|
|
291
|
+
throwOnError?: boolean;
|
|
292
|
+
}
|
|
293
|
+
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = "fields">(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method">) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
294
|
+
type SseFn = <TData = unknown, _TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = "fields">(options: Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, "method">) => Promise<ServerSentEventsResult<TData>>;
|
|
295
|
+
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = "fields">(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method"> & Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, "method">) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
296
|
+
type BuildUrlFn = <TData extends {
|
|
297
|
+
body?: unknown;
|
|
298
|
+
path?: Record<string, unknown>;
|
|
299
|
+
query?: Record<string, unknown>;
|
|
300
|
+
url: string;
|
|
301
|
+
}>(options: TData & Options$1<TData>) => string;
|
|
302
|
+
type Client = Client$1<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
303
|
+
interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
|
|
304
|
+
};
|
|
305
|
+
interface TDataShape {
|
|
306
|
+
body?: unknown;
|
|
307
|
+
headers?: unknown;
|
|
308
|
+
path?: unknown;
|
|
309
|
+
query?: unknown;
|
|
310
|
+
url: string;
|
|
311
|
+
}
|
|
312
|
+
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
313
|
+
type Options$1<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown, TResponseStyle extends ResponseStyle = "fields"> = OmitKeys<RequestOptions<TResponse, TResponseStyle, ThrowOnError>, "body" | "path" | "query" | "url"> & ([TData] extends [never] ? unknown : Omit<TData, "url">);
|
|
314
|
+
|
|
315
|
+
type ClientOptions = {
|
|
316
|
+
baseUrl: "https://articlesq.com/api/v1" | (string & {});
|
|
317
|
+
};
|
|
318
|
+
type ApiError = {
|
|
319
|
+
error: {
|
|
320
|
+
title: string;
|
|
321
|
+
status: number;
|
|
322
|
+
code: ApiErrorCode;
|
|
323
|
+
message: string;
|
|
324
|
+
instance?: string;
|
|
325
|
+
details?: {
|
|
326
|
+
[key: string]: {
|
|
327
|
+
[key: string]: unknown;
|
|
328
|
+
};
|
|
329
|
+
};
|
|
330
|
+
};
|
|
331
|
+
};
|
|
332
|
+
type ApiErrorCode = "missing_auth" | "invalid_auth_format" | "invalid_api_key" | "api_key_expired" | "insufficient_scope" | "not_found" | "route_not_found" | "validation_failed" | "slug_conflict" | "internal_error";
|
|
333
|
+
type Pagination = {
|
|
334
|
+
/**
|
|
335
|
+
* Current page number (starting from 1).
|
|
336
|
+
*/
|
|
337
|
+
page: number;
|
|
338
|
+
/**
|
|
339
|
+
* Maximum number of items returned per page.
|
|
340
|
+
*/
|
|
341
|
+
limit: number;
|
|
342
|
+
/**
|
|
343
|
+
* Total number of matching items.
|
|
344
|
+
*/
|
|
345
|
+
total: number;
|
|
346
|
+
/**
|
|
347
|
+
* Total number of pages for the current limit.
|
|
348
|
+
*/
|
|
349
|
+
totalPages: number;
|
|
350
|
+
/**
|
|
351
|
+
* Whether another page exists after the current one.
|
|
352
|
+
*/
|
|
353
|
+
hasNext: boolean;
|
|
354
|
+
/**
|
|
355
|
+
* Whether another page exists before the current one.
|
|
356
|
+
*/
|
|
357
|
+
hasPrev: boolean;
|
|
358
|
+
};
|
|
359
|
+
type FaqItem = {
|
|
360
|
+
/**
|
|
361
|
+
* The question. Plain text, no markdown.
|
|
362
|
+
*/
|
|
363
|
+
q: string;
|
|
364
|
+
/**
|
|
365
|
+
* The answer. Plain text, no markdown.
|
|
366
|
+
*/
|
|
367
|
+
a: string;
|
|
368
|
+
};
|
|
369
|
+
type Article = {
|
|
370
|
+
id: string;
|
|
371
|
+
slug: string;
|
|
372
|
+
title: string;
|
|
373
|
+
keyword: string;
|
|
374
|
+
metaDescription: string | null;
|
|
375
|
+
/**
|
|
376
|
+
* Markdown body of the article.
|
|
377
|
+
*/
|
|
378
|
+
content: string;
|
|
379
|
+
/**
|
|
380
|
+
* Public URL of the generated cover image. Null while pending or if image generation failed.
|
|
381
|
+
*/
|
|
382
|
+
coverImage: string | null;
|
|
383
|
+
/**
|
|
384
|
+
* Structured FAQ as plain-text Q/A pairs. Empty array when the article has no FAQ. By default the project also appends this FAQ as markdown to `content`; toggle `inlineFaqInContent` on the project (or pass `?inlineFaq=false`) to receive `content` without the FAQ section.
|
|
385
|
+
*/
|
|
386
|
+
faq: Array<FaqItem>;
|
|
387
|
+
status: ArticleStatus;
|
|
388
|
+
/**
|
|
389
|
+
* Public publish date (schema.org `datePublished`) as an ISO 8601 string. Null when no specific date is set. Editable from the dashboard.
|
|
390
|
+
*/
|
|
391
|
+
datePublished: string | null;
|
|
392
|
+
/**
|
|
393
|
+
* Last meaningful content update (schema.org `dateModified`) as an ISO 8601 string. Null until the article is edited after being published.
|
|
394
|
+
*/
|
|
395
|
+
dateModified: string | null;
|
|
396
|
+
};
|
|
397
|
+
type ArticleStatus = "draft" | "published";
|
|
398
|
+
type ListArticlesResponse = {
|
|
399
|
+
articles: Array<Article>;
|
|
400
|
+
pagination: Pagination;
|
|
401
|
+
};
|
|
402
|
+
type ArticleResponse = {
|
|
403
|
+
article: Article;
|
|
404
|
+
};
|
|
405
|
+
type CreateArticleBody = {
|
|
406
|
+
/**
|
|
407
|
+
* URL slug. Must be lowercase kebab-case and unique within the project.
|
|
408
|
+
*/
|
|
409
|
+
slug: string;
|
|
410
|
+
/**
|
|
411
|
+
* Article title — also used as the SEO title tag.
|
|
412
|
+
*/
|
|
413
|
+
title: string;
|
|
414
|
+
/**
|
|
415
|
+
* Primary keyword the article targets.
|
|
416
|
+
*/
|
|
417
|
+
keyword: string;
|
|
418
|
+
/**
|
|
419
|
+
* Markdown body of the article. Defaults to an empty string when omitted — useful when creating a stub to fill in later.
|
|
420
|
+
*/
|
|
421
|
+
content?: string;
|
|
422
|
+
/**
|
|
423
|
+
* SEO meta description, recommended < 155 characters.
|
|
424
|
+
*/
|
|
425
|
+
metaDescription?: string;
|
|
426
|
+
/**
|
|
427
|
+
* Defaults to `draft`.
|
|
428
|
+
*/
|
|
429
|
+
status?: "draft" | "published";
|
|
430
|
+
/**
|
|
431
|
+
* Structured FAQ as plain-text Q/A pairs. Server trims whitespace, drops fully-empty pairs, and rejects half-filled ones (only `q` or only `a`).
|
|
432
|
+
*/
|
|
433
|
+
faq?: Array<FaqItem>;
|
|
434
|
+
};
|
|
435
|
+
type UpdateArticleBody = {
|
|
436
|
+
/**
|
|
437
|
+
* Article title. Empty strings are rejected.
|
|
438
|
+
*/
|
|
439
|
+
title?: string;
|
|
440
|
+
/**
|
|
441
|
+
* URL-friendly slug. Empty strings are rejected. Must be unique within the project. Can only be changed while the article is in draft status.
|
|
442
|
+
*/
|
|
443
|
+
slug?: string;
|
|
444
|
+
/**
|
|
445
|
+
* New markdown body. Empty strings are rejected — you can clear other fields, but the article body must stay non-empty.
|
|
446
|
+
*/
|
|
447
|
+
content?: string;
|
|
448
|
+
/**
|
|
449
|
+
* SEO meta description, recommended < 155 characters.
|
|
450
|
+
*/
|
|
451
|
+
metaDescription?: string;
|
|
452
|
+
/**
|
|
453
|
+
* Replace the structured FAQ. Server trims whitespace, drops fully-empty pairs, rejects half-filled ones. Pass `[]` to remove all items. Omit to leave it unchanged.
|
|
454
|
+
*/
|
|
455
|
+
faq?: Array<FaqItem>;
|
|
456
|
+
};
|
|
457
|
+
type ListArticlesData = {
|
|
458
|
+
body?: never;
|
|
459
|
+
path?: never;
|
|
460
|
+
query?: {
|
|
461
|
+
page?: number;
|
|
462
|
+
limit?: number;
|
|
463
|
+
/**
|
|
464
|
+
* By default only `published` articles are returned. Set to `true` to also include `draft` articles (e.g. to preview work in progress).
|
|
465
|
+
*/
|
|
466
|
+
includeDrafts?: boolean;
|
|
467
|
+
};
|
|
468
|
+
url: "/articles";
|
|
469
|
+
};
|
|
470
|
+
type ListArticlesErrors = {
|
|
471
|
+
/**
|
|
472
|
+
* Invalid query parameters
|
|
473
|
+
*/
|
|
474
|
+
400: ApiError;
|
|
475
|
+
/**
|
|
476
|
+
* Invalid or missing API key
|
|
477
|
+
*/
|
|
478
|
+
401: ApiError;
|
|
479
|
+
/**
|
|
480
|
+
* API key lacks the required scope
|
|
481
|
+
*/
|
|
482
|
+
403: ApiError;
|
|
483
|
+
};
|
|
484
|
+
type ListArticlesError = ListArticlesErrors[keyof ListArticlesErrors];
|
|
485
|
+
type ListArticlesResponses = {
|
|
486
|
+
/**
|
|
487
|
+
* Articles retrieved successfully
|
|
488
|
+
*/
|
|
489
|
+
200: ListArticlesResponse;
|
|
490
|
+
};
|
|
491
|
+
type ListArticlesResponse2 = ListArticlesResponses[keyof ListArticlesResponses];
|
|
492
|
+
type CreateArticleData = {
|
|
493
|
+
body: CreateArticleBody;
|
|
494
|
+
path?: never;
|
|
495
|
+
query?: never;
|
|
496
|
+
url: "/articles";
|
|
497
|
+
};
|
|
498
|
+
type CreateArticleErrors = {
|
|
499
|
+
/**
|
|
500
|
+
* Invalid request body
|
|
501
|
+
*/
|
|
502
|
+
400: ApiError;
|
|
503
|
+
/**
|
|
504
|
+
* Invalid or missing API key
|
|
505
|
+
*/
|
|
506
|
+
401: ApiError;
|
|
507
|
+
/**
|
|
508
|
+
* API key lacks the required scope
|
|
509
|
+
*/
|
|
510
|
+
403: ApiError;
|
|
511
|
+
/**
|
|
512
|
+
* An article with the requested slug already exists in this project
|
|
513
|
+
*/
|
|
514
|
+
409: ApiError;
|
|
515
|
+
};
|
|
516
|
+
type CreateArticleError = CreateArticleErrors[keyof CreateArticleErrors];
|
|
517
|
+
type CreateArticleResponses = {
|
|
518
|
+
/**
|
|
519
|
+
* Article created
|
|
520
|
+
*/
|
|
521
|
+
201: ArticleResponse;
|
|
522
|
+
};
|
|
523
|
+
type CreateArticleResponse = CreateArticleResponses[keyof CreateArticleResponses];
|
|
524
|
+
type GetArticleData = {
|
|
525
|
+
body?: never;
|
|
526
|
+
path: {
|
|
527
|
+
slug: string;
|
|
528
|
+
};
|
|
529
|
+
query?: {
|
|
530
|
+
/**
|
|
531
|
+
* Whether to append the FAQ as a `## FAQ` markdown section to `content`. `true` forces inlining, `false` returns `content` without it. Omit to use the project's `inlineFaqInContent` default (on by default). The structured `faq` field is always returned either way.
|
|
532
|
+
*/
|
|
533
|
+
inlineFaq?: boolean;
|
|
534
|
+
/**
|
|
535
|
+
* By default a `draft` article returns 404 on this endpoint — only `published` articles are fetchable. Set to `true` to fetch a draft (e.g. to preview work in progress).
|
|
536
|
+
*/
|
|
537
|
+
includeDrafts?: boolean;
|
|
538
|
+
};
|
|
539
|
+
url: "/articles/{slug}";
|
|
540
|
+
};
|
|
541
|
+
type GetArticleErrors = {
|
|
542
|
+
/**
|
|
543
|
+
* Invalid or missing API key
|
|
544
|
+
*/
|
|
545
|
+
401: ApiError;
|
|
546
|
+
/**
|
|
547
|
+
* API key lacks the required scope
|
|
548
|
+
*/
|
|
549
|
+
403: ApiError;
|
|
550
|
+
/**
|
|
551
|
+
* Article not found in this project
|
|
552
|
+
*/
|
|
553
|
+
404: ApiError;
|
|
554
|
+
};
|
|
555
|
+
type GetArticleError = GetArticleErrors[keyof GetArticleErrors];
|
|
556
|
+
type GetArticleResponses = {
|
|
557
|
+
/**
|
|
558
|
+
* Article retrieved successfully
|
|
559
|
+
*/
|
|
560
|
+
200: ArticleResponse;
|
|
561
|
+
};
|
|
562
|
+
type GetArticleResponse = GetArticleResponses[keyof GetArticleResponses];
|
|
563
|
+
type UpdateArticleData = {
|
|
564
|
+
body: UpdateArticleBody;
|
|
565
|
+
path: {
|
|
566
|
+
slug: string;
|
|
567
|
+
};
|
|
568
|
+
query?: never;
|
|
569
|
+
url: "/articles/{slug}";
|
|
570
|
+
};
|
|
571
|
+
type UpdateArticleErrors = {
|
|
572
|
+
/**
|
|
573
|
+
* Invalid request body
|
|
574
|
+
*/
|
|
575
|
+
400: ApiError;
|
|
576
|
+
/**
|
|
577
|
+
* Invalid or missing API key
|
|
578
|
+
*/
|
|
579
|
+
401: ApiError;
|
|
580
|
+
/**
|
|
581
|
+
* API key lacks the required scope
|
|
582
|
+
*/
|
|
583
|
+
403: ApiError;
|
|
584
|
+
/**
|
|
585
|
+
* Article not found in this project
|
|
586
|
+
*/
|
|
587
|
+
404: ApiError;
|
|
588
|
+
};
|
|
589
|
+
type UpdateArticleError = UpdateArticleErrors[keyof UpdateArticleErrors];
|
|
590
|
+
type UpdateArticleResponses = {
|
|
591
|
+
/**
|
|
592
|
+
* Article updated
|
|
593
|
+
*/
|
|
594
|
+
200: ArticleResponse;
|
|
595
|
+
};
|
|
596
|
+
type UpdateArticleResponse = UpdateArticleResponses[keyof UpdateArticleResponses];
|
|
597
|
+
|
|
598
|
+
type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown> = Options$1<TData, ThrowOnError, TResponse> & {
|
|
599
|
+
/**
|
|
600
|
+
* You can provide a client instance returned by `createClient()` instead of
|
|
601
|
+
* individual options. This might be also useful if you want to implement a
|
|
602
|
+
* custom client.
|
|
603
|
+
*/
|
|
604
|
+
client?: Client;
|
|
605
|
+
/**
|
|
606
|
+
* You can pass arbitrary values through the `meta` object. This can be
|
|
607
|
+
* used to access values that aren't defined as part of the SDK function.
|
|
608
|
+
*/
|
|
609
|
+
meta?: Record<string, unknown>;
|
|
610
|
+
};
|
|
611
|
+
declare class Articles {
|
|
612
|
+
/**
|
|
613
|
+
* List articles
|
|
614
|
+
*
|
|
615
|
+
* Returns a paginated list of articles for the project the API key is scoped to. The article body is included for each item.
|
|
616
|
+
*/
|
|
617
|
+
static listArticles<ThrowOnError extends boolean = false>(options?: Options<ListArticlesData, ThrowOnError>): RequestResult<ListArticlesResponses, ListArticlesErrors, ThrowOnError, "fields">;
|
|
618
|
+
/**
|
|
619
|
+
* Create an article
|
|
620
|
+
*
|
|
621
|
+
* Creates a new article in the project the API key is scoped to. Use this when you generate content with your own agents and want ArticlesQ to host it (e.g. for the backlinks exchange). The article body is markdown.
|
|
622
|
+
*/
|
|
623
|
+
static createArticle<ThrowOnError extends boolean = false>(options: Options<CreateArticleData, ThrowOnError>): RequestResult<CreateArticleResponses, CreateArticleErrors, ThrowOnError, "fields">;
|
|
624
|
+
/**
|
|
625
|
+
* Get article by slug
|
|
626
|
+
*
|
|
627
|
+
* Returns a single article by slug, scoped to the project the API key authorises. Slugs are unique within a project.
|
|
628
|
+
*/
|
|
629
|
+
static getArticle<ThrowOnError extends boolean = false>(options: Options<GetArticleData, ThrowOnError>): RequestResult<GetArticleResponses, GetArticleErrors, ThrowOnError, "fields">;
|
|
630
|
+
/**
|
|
631
|
+
* Update an article
|
|
632
|
+
*
|
|
633
|
+
* Update editable fields on an article — currently `content` and `metaDescription`. Send only the fields you want to change. Returns the full updated article.
|
|
634
|
+
*/
|
|
635
|
+
static updateArticle<ThrowOnError extends boolean = false>(options: Options<UpdateArticleData, ThrowOnError>): RequestResult<UpdateArticleResponses, UpdateArticleErrors, ThrowOnError, "fields">;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
interface ArticlesQOptions {
|
|
639
|
+
/**
|
|
640
|
+
* Your ArticlesQ API key (begins with `aq_live_`). Create one in the
|
|
641
|
+
* dashboard under **Settings → Integrations & API**.
|
|
642
|
+
*/
|
|
643
|
+
apiKey: string;
|
|
644
|
+
/**
|
|
645
|
+
* Override the API base URL. Defaults to `https://articlesq.com/api/v1`.
|
|
646
|
+
* Mostly useful for staging or local development.
|
|
647
|
+
*/
|
|
648
|
+
baseUrl?: string;
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Official TypeScript SDK for the ArticlesQ API.
|
|
652
|
+
*
|
|
653
|
+
* @example
|
|
654
|
+
* ```ts
|
|
655
|
+
* import { ArticlesQ } from "@articlesq/sdk";
|
|
656
|
+
*
|
|
657
|
+
* const articlesq = new ArticlesQ({ apiKey: process.env.ARTICLESQ_API_KEY! });
|
|
658
|
+
*
|
|
659
|
+
* const { data } = await articlesq.articles.list({ page: 1, limit: 20 });
|
|
660
|
+
* if (data) {
|
|
661
|
+
* for (const article of data.articles) {
|
|
662
|
+
* console.log(article.title);
|
|
663
|
+
* }
|
|
664
|
+
* }
|
|
665
|
+
* ```
|
|
666
|
+
*/
|
|
667
|
+
declare class ArticlesQ {
|
|
668
|
+
/**
|
|
669
|
+
* Article resources — list and fetch articles for the project this API
|
|
670
|
+
* key is scoped to.
|
|
671
|
+
*/
|
|
672
|
+
readonly articles: ReturnType<typeof createArticlesNamespace>;
|
|
673
|
+
constructor(options: ArticlesQOptions);
|
|
674
|
+
}
|
|
675
|
+
declare function createArticlesNamespace(client: Client): {
|
|
676
|
+
/** List articles in the current project. Wraps `Articles.listArticles`. */
|
|
677
|
+
list: (query?: ListArticlesData["query"]) => Promise<({
|
|
678
|
+
data: ListArticlesResponse;
|
|
679
|
+
error: undefined;
|
|
680
|
+
} | {
|
|
681
|
+
data: undefined;
|
|
682
|
+
error: ApiError;
|
|
683
|
+
}) & {
|
|
684
|
+
request?: Request;
|
|
685
|
+
response?: Response;
|
|
686
|
+
}>;
|
|
687
|
+
/** Fetch a single article by slug. Wraps `Articles.getArticle`. */
|
|
688
|
+
get: (slug: string, query?: GetArticleData["query"]) => Promise<({
|
|
689
|
+
data: ArticleResponse;
|
|
690
|
+
error: undefined;
|
|
691
|
+
} | {
|
|
692
|
+
data: undefined;
|
|
693
|
+
error: ApiError;
|
|
694
|
+
}) & {
|
|
695
|
+
request?: Request;
|
|
696
|
+
response?: Response;
|
|
697
|
+
}>;
|
|
698
|
+
/**
|
|
699
|
+
* Create a new article in the current project. Wraps `Articles.createArticle`.
|
|
700
|
+
*
|
|
701
|
+
* Use this when you generate content with your own agents and want
|
|
702
|
+
* ArticlesQ to host it (e.g. for the backlinks exchange). The body
|
|
703
|
+
* is markdown.
|
|
704
|
+
*
|
|
705
|
+
* Slugs are unique within a project — reusing one returns 409
|
|
706
|
+
* `slug_conflict` in the error channel.
|
|
707
|
+
*/
|
|
708
|
+
create: (body: CreateArticleData["body"]) => Promise<({
|
|
709
|
+
data: ArticleResponse;
|
|
710
|
+
error: undefined;
|
|
711
|
+
} | {
|
|
712
|
+
data: undefined;
|
|
713
|
+
error: ApiError;
|
|
714
|
+
}) & {
|
|
715
|
+
request?: Request;
|
|
716
|
+
response?: Response;
|
|
717
|
+
}>;
|
|
718
|
+
/**
|
|
719
|
+
* Update editable fields on an article. Wraps `Articles.updateArticle`.
|
|
720
|
+
*
|
|
721
|
+
* Send only the fields you want to change (currently `content` and
|
|
722
|
+
* `metaDescription`). Returns the full updated article on success.
|
|
723
|
+
*/
|
|
724
|
+
update: (slug: string, body: UpdateArticleData["body"]) => Promise<({
|
|
725
|
+
data: ArticleResponse;
|
|
726
|
+
error: undefined;
|
|
727
|
+
} | {
|
|
728
|
+
data: undefined;
|
|
729
|
+
error: ApiError;
|
|
730
|
+
}) & {
|
|
731
|
+
request?: Request;
|
|
732
|
+
response?: Response;
|
|
733
|
+
}>;
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
export { type ApiError, type ApiErrorCode, type Article, type ArticleResponse, type ArticleStatus, Articles, ArticlesQ, type ArticlesQOptions, type ClientOptions, type CreateArticleBody, type CreateArticleData, type CreateArticleError, type CreateArticleErrors, type CreateArticleResponse, type CreateArticleResponses, type FaqItem, type GetArticleData, type GetArticleError, type GetArticleErrors, type GetArticleResponse, type GetArticleResponses, type ListArticlesData, type ListArticlesError, type ListArticlesErrors, type ListArticlesResponse, type ListArticlesResponse2, type ListArticlesResponses, type Options, type Pagination, type UpdateArticleBody, type UpdateArticleData, type UpdateArticleError, type UpdateArticleErrors, type UpdateArticleResponse, type UpdateArticleResponses, ArticlesQ as default };
|