@verbatims/sdk 1.0.0
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 +21 -0
- package/README.md +61 -0
- package/dist/client.d.ts +35 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +156 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +26 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +51 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/pagination.d.ts +9 -0
- package/dist/pagination.d.ts.map +1 -0
- package/dist/pagination.js +16 -0
- package/dist/pagination.js.map +1 -0
- package/dist/resources/authors.d.ts +145 -0
- package/dist/resources/authors.d.ts.map +1 -0
- package/dist/resources/authors.js +48 -0
- package/dist/resources/authors.js.map +1 -0
- package/dist/resources/collections.d.ts +57 -0
- package/dist/resources/collections.d.ts.map +1 -0
- package/dist/resources/collections.js +32 -0
- package/dist/resources/collections.js.map +1 -0
- package/dist/resources/index.d.ts +7 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +7 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/quotes.d.ts +226 -0
- package/dist/resources/quotes.d.ts.map +1 -0
- package/dist/resources/quotes.js +69 -0
- package/dist/resources/quotes.js.map +1 -0
- package/dist/resources/references.d.ts +135 -0
- package/dist/resources/references.d.ts.map +1 -0
- package/dist/resources/references.js +46 -0
- package/dist/resources/references.js.map +1 -0
- package/dist/resources/search.d.ts +36 -0
- package/dist/resources/search.d.ts.map +1 -0
- package/dist/resources/search.js +27 -0
- package/dist/resources/search.js.map +1 -0
- package/dist/resources/tags.d.ts +39 -0
- package/dist/resources/tags.d.ts.map +1 -0
- package/dist/resources/tags.js +26 -0
- package/dist/resources/tags.js.map +1 -0
- package/dist/types.d.ts +203 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +23 -0
- package/dist/types.js.map +1 -0
- package/nuxt/composables.ts +31 -0
- package/nuxt/module.ts +31 -0
- package/package.json +85 -0
- package/src/__tests__/client.test.ts +304 -0
- package/src/__tests__/errors.test.ts +85 -0
- package/src/__tests__/pagination.test.ts +100 -0
- package/src/client.ts +213 -0
- package/src/errors.ts +54 -0
- package/src/index.ts +58 -0
- package/src/pagination.ts +25 -0
- package/src/resources/__tests__/resources.test.ts +386 -0
- package/src/resources/authors.ts +58 -0
- package/src/resources/collections.ts +45 -0
- package/src/resources/index.ts +6 -0
- package/src/resources/quotes.ts +80 -0
- package/src/resources/references.ts +56 -0
- package/src/resources/search.ts +34 -0
- package/src/resources/tags.ts +32 -0
- package/src/types.ts +221 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { z } from 'zod/v4'
|
|
2
|
+
import type { VerbatimsClient } from '../client'
|
|
3
|
+
import { apiResponseSchema } from '../types'
|
|
4
|
+
import { paginate } from '../pagination'
|
|
5
|
+
import type { QuoteWithRelations, ListQuotesParams, CreateQuoteData, UpdateQuoteData } from '../types'
|
|
6
|
+
|
|
7
|
+
const quoteSchema = z.object({
|
|
8
|
+
id: z.number(),
|
|
9
|
+
name: z.string(),
|
|
10
|
+
language: z.string(),
|
|
11
|
+
author_id: z.number().optional(),
|
|
12
|
+
reference_id: z.number().optional(),
|
|
13
|
+
status: z.string(),
|
|
14
|
+
views_count: z.number(),
|
|
15
|
+
likes_count: z.number(),
|
|
16
|
+
shares_count: z.number(),
|
|
17
|
+
is_featured: z.boolean().optional(),
|
|
18
|
+
created_at: z.string(),
|
|
19
|
+
updated_at: z.string(),
|
|
20
|
+
author: z.object({
|
|
21
|
+
id: z.number(),
|
|
22
|
+
name: z.string(),
|
|
23
|
+
is_fictional: z.boolean().optional(),
|
|
24
|
+
image_url: z.string().nullable().optional(),
|
|
25
|
+
description: z.string().nullable().optional(),
|
|
26
|
+
}).optional(),
|
|
27
|
+
reference: z.object({
|
|
28
|
+
id: z.number(),
|
|
29
|
+
name: z.string(),
|
|
30
|
+
primary_type: z.string().optional(),
|
|
31
|
+
}).optional(),
|
|
32
|
+
tags: z.array(z.object({
|
|
33
|
+
id: z.number().optional(),
|
|
34
|
+
name: z.string(),
|
|
35
|
+
color: z.string().nullable().optional(),
|
|
36
|
+
})).optional(),
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const quoteListResponseSchema = apiResponseSchema(z.array(quoteSchema))
|
|
40
|
+
const quoteSingleResponseSchema = apiResponseSchema(quoteSchema)
|
|
41
|
+
const quoteDeleteResponseSchema = apiResponseSchema(z.undefined()).or(z.object({
|
|
42
|
+
success: z.literal(true),
|
|
43
|
+
message: z.string().optional(),
|
|
44
|
+
data: z.unknown().optional(),
|
|
45
|
+
}))
|
|
46
|
+
|
|
47
|
+
type QuoteItem = z.infer<typeof quoteSchema>
|
|
48
|
+
|
|
49
|
+
export class QuotesResource {
|
|
50
|
+
constructor(private client: VerbatimsClient) {}
|
|
51
|
+
|
|
52
|
+
async list(params?: ListQuotesParams) {
|
|
53
|
+
return this.client.get('/quotes', { params: params as Record<string, unknown> }, quoteListResponseSchema)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
paginate(params?: ListQuotesParams): AsyncGenerator<QuoteItem> {
|
|
57
|
+
return paginate<QuoteItem>((page) =>
|
|
58
|
+
this.list({ ...params, page }).then(r => ({
|
|
59
|
+
data: r.data,
|
|
60
|
+
pagination: r.pagination,
|
|
61
|
+
}))
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async get(id: number) {
|
|
66
|
+
return this.client.get(`/quotes/${id}`, {}, quoteSingleResponseSchema)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async create(data: CreateQuoteData) {
|
|
70
|
+
return this.client.post('/quotes', data, {}, quoteSingleResponseSchema)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async update(id: number, data: UpdateQuoteData) {
|
|
74
|
+
return this.client.put(`/quotes/${id}`, data, {}, quoteSingleResponseSchema)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async delete(id: number) {
|
|
78
|
+
return this.client.delete(`/quotes/${id}`, {}, quoteDeleteResponseSchema)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from 'zod/v4'
|
|
2
|
+
import type { VerbatimsClient } from '../client'
|
|
3
|
+
import { apiResponseSchema } from '../types'
|
|
4
|
+
import { paginate } from '../pagination'
|
|
5
|
+
import type { ListReferencesParams, CreateReferenceData, UpdateReferenceData } from '../types'
|
|
6
|
+
|
|
7
|
+
const referenceSchema = z.object({
|
|
8
|
+
id: z.number(),
|
|
9
|
+
name: z.string(),
|
|
10
|
+
primary_type: z.string(),
|
|
11
|
+
secondary_type: z.string().nullable().optional(),
|
|
12
|
+
original_language: z.string().optional(),
|
|
13
|
+
release_date: z.string().nullable().optional(),
|
|
14
|
+
description: z.string().nullable().optional(),
|
|
15
|
+
image_url: z.string().nullable().optional(),
|
|
16
|
+
views_count: z.number(),
|
|
17
|
+
likes_count: z.number(),
|
|
18
|
+
shares_count: z.number(),
|
|
19
|
+
quotes_count: z.number().optional(),
|
|
20
|
+
created_at: z.string(),
|
|
21
|
+
updated_at: z.string(),
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const referenceListResponseSchema = apiResponseSchema(z.array(referenceSchema))
|
|
25
|
+
const referenceSingleResponseSchema = apiResponseSchema(referenceSchema)
|
|
26
|
+
|
|
27
|
+
type ReferenceItem = z.infer<typeof referenceSchema>
|
|
28
|
+
|
|
29
|
+
export class ReferencesResource {
|
|
30
|
+
constructor(private client: VerbatimsClient) {}
|
|
31
|
+
|
|
32
|
+
async list(params?: ListReferencesParams) {
|
|
33
|
+
return this.client.get('/references', { params: params as Record<string, unknown> }, referenceListResponseSchema)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
paginate(params?: ListReferencesParams): AsyncGenerator<ReferenceItem> {
|
|
37
|
+
return paginate<ReferenceItem>((page) =>
|
|
38
|
+
this.list({ ...params, page }).then(r => ({
|
|
39
|
+
data: r.data,
|
|
40
|
+
pagination: r.pagination,
|
|
41
|
+
}))
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async get(id: number) {
|
|
46
|
+
return this.client.get(`/references/${id}`, {}, referenceSingleResponseSchema)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async create(data: CreateReferenceData) {
|
|
50
|
+
return this.client.post('/references', data, {}, referenceSingleResponseSchema)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async update(id: number, data: UpdateReferenceData) {
|
|
54
|
+
return this.client.put(`/references/${id}`, data, {}, referenceSingleResponseSchema)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod/v4'
|
|
2
|
+
import type { VerbatimsClient } from '../client'
|
|
3
|
+
import { apiResponseSchema } from '../types'
|
|
4
|
+
import { paginate } from '../pagination'
|
|
5
|
+
import type { SearchParams } from '../types'
|
|
6
|
+
|
|
7
|
+
const searchResultSchema = z.object({
|
|
8
|
+
id: z.number(),
|
|
9
|
+
type: z.string(),
|
|
10
|
+
name: z.string(),
|
|
11
|
+
description: z.string().optional(),
|
|
12
|
+
match: z.string().optional(),
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
type SearchResultItem = z.infer<typeof searchResultSchema>
|
|
16
|
+
|
|
17
|
+
const searchResponseSchema = apiResponseSchema(z.array(searchResultSchema))
|
|
18
|
+
|
|
19
|
+
export class SearchResource {
|
|
20
|
+
constructor(private client: VerbatimsClient) {}
|
|
21
|
+
|
|
22
|
+
async query(params: SearchParams) {
|
|
23
|
+
return this.client.get('/search', { params: params as unknown as Record<string, unknown> }, searchResponseSchema)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
paginate(params: SearchParams): AsyncGenerator<SearchResultItem> {
|
|
27
|
+
return paginate<SearchResultItem>((page) =>
|
|
28
|
+
this.query({ ...params, page }).then(r => ({
|
|
29
|
+
data: r.data,
|
|
30
|
+
pagination: r.pagination,
|
|
31
|
+
}))
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from 'zod/v4'
|
|
2
|
+
import type { VerbatimsClient } from '../client'
|
|
3
|
+
import { apiResponseSchema } from '../types'
|
|
4
|
+
import { paginate } from '../pagination'
|
|
5
|
+
|
|
6
|
+
const tagSchema = z.object({
|
|
7
|
+
id: z.number(),
|
|
8
|
+
name: z.string(),
|
|
9
|
+
color: z.string().nullable().optional(),
|
|
10
|
+
usage_count: z.number().optional(),
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
type TagItem = z.infer<typeof tagSchema>
|
|
14
|
+
|
|
15
|
+
const tagListResponseSchema = apiResponseSchema(z.array(tagSchema))
|
|
16
|
+
|
|
17
|
+
export class TagsResource {
|
|
18
|
+
constructor(private client: VerbatimsClient) {}
|
|
19
|
+
|
|
20
|
+
async list(params?: { page?: number; limit?: number }) {
|
|
21
|
+
return this.client.get('/tags', { params: params as Record<string, unknown> }, tagListResponseSchema)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
paginate(params?: { page?: number; limit?: number }): AsyncGenerator<TagItem> {
|
|
25
|
+
return paginate<TagItem>((page) =>
|
|
26
|
+
this.list({ ...params, page }).then(r => ({
|
|
27
|
+
data: r.data,
|
|
28
|
+
pagination: r.pagination,
|
|
29
|
+
}))
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { z } from 'zod/v4'
|
|
2
|
+
|
|
3
|
+
// --- Zod schemas for response validation ---
|
|
4
|
+
|
|
5
|
+
export const paginationMetaSchema = z.object({
|
|
6
|
+
page: z.number(),
|
|
7
|
+
limit: z.number(),
|
|
8
|
+
total: z.number(),
|
|
9
|
+
totalPages: z.number(),
|
|
10
|
+
hasMore: z.boolean(),
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
export function apiResponseSchema<T extends z.ZodTypeAny>(dataSchema: T) {
|
|
14
|
+
return z.object({
|
|
15
|
+
success: z.literal(true),
|
|
16
|
+
data: dataSchema.optional(),
|
|
17
|
+
message: z.string().optional(),
|
|
18
|
+
pagination: paginationMetaSchema.optional(),
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const errorResponseSchema = z.object({
|
|
23
|
+
success: z.literal(false),
|
|
24
|
+
message: z.string().optional(),
|
|
25
|
+
errors: z.array(z.string()).optional(),
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
export type PaginationMeta = z.infer<typeof paginationMetaSchema>
|
|
29
|
+
|
|
30
|
+
export interface ApiResponse<T = unknown> {
|
|
31
|
+
success: boolean
|
|
32
|
+
data?: T
|
|
33
|
+
message?: string
|
|
34
|
+
pagination?: PaginationMeta
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// --- API entity types (subset of shared types, inlined for portability) ---
|
|
38
|
+
|
|
39
|
+
export interface QuoteAuthor {
|
|
40
|
+
id: number
|
|
41
|
+
name: string
|
|
42
|
+
is_fictional?: boolean
|
|
43
|
+
image_url?: string | null
|
|
44
|
+
description?: string | null
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface QuoteReferenceInfo {
|
|
48
|
+
id: number
|
|
49
|
+
name: string
|
|
50
|
+
primary_type?: string
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface QuoteWithRelations {
|
|
54
|
+
id: number
|
|
55
|
+
name: string
|
|
56
|
+
language: string
|
|
57
|
+
author_id?: number
|
|
58
|
+
reference_id?: number
|
|
59
|
+
status: string
|
|
60
|
+
views_count: number
|
|
61
|
+
likes_count: number
|
|
62
|
+
shares_count: number
|
|
63
|
+
is_featured?: boolean
|
|
64
|
+
created_at: string
|
|
65
|
+
updated_at: string
|
|
66
|
+
author?: QuoteAuthor
|
|
67
|
+
reference?: QuoteReferenceInfo
|
|
68
|
+
tags?: Array<{ id?: number; name: string; color?: string | null }>
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface Author {
|
|
72
|
+
id: number
|
|
73
|
+
name: string
|
|
74
|
+
is_fictional?: boolean
|
|
75
|
+
image_url?: string | null
|
|
76
|
+
job?: string | null
|
|
77
|
+
description?: string | null
|
|
78
|
+
birth_date?: string | null
|
|
79
|
+
birth_location?: string | null
|
|
80
|
+
death_date?: string | null
|
|
81
|
+
death_location?: string | null
|
|
82
|
+
views_count: number
|
|
83
|
+
likes_count: number
|
|
84
|
+
shares_count: number
|
|
85
|
+
quotes_count?: number
|
|
86
|
+
created_at: string
|
|
87
|
+
updated_at: string
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface QuoteReference {
|
|
91
|
+
id: number
|
|
92
|
+
name: string
|
|
93
|
+
primary_type: string
|
|
94
|
+
secondary_type?: string | null
|
|
95
|
+
original_language?: string
|
|
96
|
+
release_date?: string | null
|
|
97
|
+
description?: string | null
|
|
98
|
+
image_url?: string | null
|
|
99
|
+
views_count: number
|
|
100
|
+
likes_count: number
|
|
101
|
+
shares_count: number
|
|
102
|
+
quotes_count?: number
|
|
103
|
+
created_at: string
|
|
104
|
+
updated_at: string
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// --- Parameter types for SDK methods ---
|
|
108
|
+
|
|
109
|
+
export interface ListQuotesParams {
|
|
110
|
+
page?: number
|
|
111
|
+
limit?: number
|
|
112
|
+
language?: string
|
|
113
|
+
author_id?: number
|
|
114
|
+
reference_id?: number
|
|
115
|
+
search?: string
|
|
116
|
+
tag?: string
|
|
117
|
+
sort_by?: string
|
|
118
|
+
sort_order?: 'asc' | 'desc'
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface ListAuthorsParams {
|
|
122
|
+
page?: number
|
|
123
|
+
limit?: number
|
|
124
|
+
search?: string
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface ListReferencesParams {
|
|
128
|
+
page?: number
|
|
129
|
+
limit?: number
|
|
130
|
+
search?: string
|
|
131
|
+
type?: string
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface SearchParams {
|
|
135
|
+
q: string
|
|
136
|
+
type?: 'quotes' | 'authors' | 'references'
|
|
137
|
+
page?: number
|
|
138
|
+
limit?: number
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface CreateQuoteData {
|
|
142
|
+
name: string
|
|
143
|
+
language?: string
|
|
144
|
+
author_id?: number
|
|
145
|
+
reference_id?: number
|
|
146
|
+
new_author?: {
|
|
147
|
+
name: string
|
|
148
|
+
is_fictional?: boolean
|
|
149
|
+
job?: string | null
|
|
150
|
+
description?: string | null
|
|
151
|
+
}
|
|
152
|
+
new_reference?: {
|
|
153
|
+
name: string
|
|
154
|
+
primary_type: string
|
|
155
|
+
original_language?: string
|
|
156
|
+
description?: string | null
|
|
157
|
+
release_date?: string | null
|
|
158
|
+
}
|
|
159
|
+
tags?: number[]
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface UpdateQuoteData {
|
|
163
|
+
name?: string
|
|
164
|
+
language?: string
|
|
165
|
+
author_id?: number | null
|
|
166
|
+
reference_id?: number | null
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface CreateAuthorData {
|
|
170
|
+
name: string
|
|
171
|
+
is_fictional?: boolean
|
|
172
|
+
job?: string | null
|
|
173
|
+
description?: string | null
|
|
174
|
+
birth_date?: string | null
|
|
175
|
+
birth_location?: string | null
|
|
176
|
+
death_date?: string | null
|
|
177
|
+
death_location?: string | null
|
|
178
|
+
image_url?: string | null
|
|
179
|
+
socials?: Record<string, string> | null
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface UpdateAuthorData {
|
|
183
|
+
name?: string
|
|
184
|
+
is_fictional?: boolean
|
|
185
|
+
job?: string | null
|
|
186
|
+
description?: string | null
|
|
187
|
+
birth_date?: string | null
|
|
188
|
+
birth_location?: string | null
|
|
189
|
+
death_date?: string | null
|
|
190
|
+
death_location?: string | null
|
|
191
|
+
image_url?: string | null
|
|
192
|
+
socials?: Record<string, string> | null
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export interface CreateReferenceData {
|
|
196
|
+
name: string
|
|
197
|
+
primary_type: string
|
|
198
|
+
secondary_type?: string | null
|
|
199
|
+
description?: string | null
|
|
200
|
+
release_date?: string | null
|
|
201
|
+
original_language?: string
|
|
202
|
+
image_url?: string | null
|
|
203
|
+
urls?: Record<string, string> | null
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export interface UpdateReferenceData {
|
|
207
|
+
name?: string
|
|
208
|
+
primary_type?: string
|
|
209
|
+
secondary_type?: string | null
|
|
210
|
+
description?: string | null
|
|
211
|
+
release_date?: string | null
|
|
212
|
+
original_language?: string
|
|
213
|
+
image_url?: string | null
|
|
214
|
+
urls?: Record<string, string> | null
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export interface CreateCollectionData {
|
|
218
|
+
name: string
|
|
219
|
+
description?: string | null
|
|
220
|
+
is_public?: boolean
|
|
221
|
+
}
|