@duhnny/whatsapp-cashbook-api 0.0.0-stage → 0.2.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.
@@ -0,0 +1,372 @@
1
+ import * as z from 'zod';
2
+ import z__default from 'zod';
3
+ import { FastifyRequest } from 'fastify';
4
+
5
+ declare class Ok<T> {
6
+ readonly _tag = "ok";
7
+ value: T;
8
+ constructor(value: T);
9
+ }
10
+ declare class Err<E> {
11
+ readonly _tag = "err";
12
+ error: E;
13
+ constructor(error: E);
14
+ }
15
+
16
+ declare const Role: {
17
+ readonly USER: "USER";
18
+ readonly ADMIN: "ADMIN";
19
+ readonly SUPERADMIN: "SUPERADMIN";
20
+ };
21
+ type Role = (typeof Role)[keyof typeof Role];
22
+ declare const TransactionCategory: {
23
+ readonly payment: "payment";
24
+ readonly transportation: "transportation";
25
+ readonly food_and_beverage: "food_and_beverage";
26
+ readonly groceries: "groceries";
27
+ readonly bills: "bills";
28
+ readonly subscriptions: "subscriptions";
29
+ readonly health: "health";
30
+ readonly appearance: "appearance";
31
+ readonly others: "others";
32
+ };
33
+ type TransactionCategory = (typeof TransactionCategory)[keyof typeof TransactionCategory];
34
+
35
+ type BasicUserData = {
36
+ id: ID;
37
+ phone: bigint | null;
38
+ email: string;
39
+ roles: Role[];
40
+ };
41
+ type BasicRequest = Omit<FastifyRequest, 'user'> & {
42
+ user: BasicUserData | undefined;
43
+ };
44
+ type AuthedRequest = Omit<BasicRequest, 'user'> & {
45
+ user: BasicUserData;
46
+ };
47
+ type TypedRequest<T extends {
48
+ params?: any;
49
+ query?: any;
50
+ body?: any;
51
+ } = {}> = BasicRequest & {
52
+ params: 'params' extends keyof T ? T['params'] : unknown;
53
+ query: 'query' extends keyof T ? T['query'] : unknown;
54
+ body: 'body' extends keyof T ? T['body'] : unknown;
55
+ };
56
+ type TypedAuthedRequest<T extends {
57
+ params?: any;
58
+ query?: any;
59
+ body?: any;
60
+ } = {}> = Omit<TypedRequest<T>, 'user'> & {
61
+ user: BasicUserData;
62
+ };
63
+ declare class UnauthenticatedError {
64
+ readonly _tag = "Unauthenticated";
65
+ message?: string;
66
+ constructor(message?: string);
67
+ }
68
+ declare class ForbiddenError {
69
+ readonly _tag = "Forbidden";
70
+ message?: string;
71
+ constructor(message?: string);
72
+ }
73
+ declare class ValidationError<W extends 'params' | 'body' | 'query', E> {
74
+ readonly _tag = "ValidationError";
75
+ where: W;
76
+ parseError: E;
77
+ message?: string;
78
+ constructor(where: W, parseError: E, message?: string);
79
+ }
80
+ declare class InternalServerError {
81
+ readonly _tag = "InternalServerError";
82
+ message: string;
83
+ constructor(message: string);
84
+ }
85
+ declare const IdSchema: z__default.ZodInt;
86
+ type ID = z__default.infer<typeof IdSchema>;
87
+
88
+ declare class MalformedJWTError extends Error {
89
+ readonly _tag = "MalformedJWT";
90
+ message: string;
91
+ constructor(message: string);
92
+ }
93
+
94
+ declare const RequestWhatsappVerificationRequestBodySchema: z__default.ZodObject<{
95
+ phone: z__default.z.ZodCoercedBigInt<unknown>;
96
+ }, z__default.z.core.$strip>;
97
+ type RequestWhatsappVerificationRequestBody = z__default.infer<typeof RequestWhatsappVerificationRequestBodySchema>;
98
+
99
+ type AsyncReturn<T extends (arg0: any) => Promise<any>> = Awaited<ReturnType<T>>;
100
+
101
+ declare const isUserWhatsappVerifiedRoute: (req: Omit<AuthedRequest, "user">) => Promise<Err<InternalServerError> | Ok<{
102
+ whatsappVerified: boolean;
103
+ }> | Err<UnauthenticatedError> | Err<MalformedJWTError>>;
104
+ type IsUserWhatsappVerifiedResponseBody = AsyncReturn<typeof isUserWhatsappVerifiedRoute>;
105
+ declare class NumberIsNotOnWhatsappError extends Error {
106
+ readonly _tag = "NumberIsNotOnWhatsapp";
107
+ message: string;
108
+ phone: bigint;
109
+ constructor(phone: bigint, message: string);
110
+ }
111
+ declare class ServerProcessingUserCreationError extends Error {
112
+ readonly _tag = "ServerProcessingUserCreation";
113
+ message: string;
114
+ constructor(message: string);
115
+ }
116
+ declare const requestWhatsappVerificationRoute: (req: Omit<Omit<TypedAuthedRequest<{
117
+ body: RequestWhatsappVerificationRequestBody;
118
+ }>, "params" | "query" | "body"> & {
119
+ params: unknown;
120
+ query: unknown;
121
+ body: unknown;
122
+ }, "user">) => Promise<Err<InternalServerError> | Err<UnauthenticatedError> | Err<MalformedJWTError> | Ok<{
123
+ alreadyVerified: boolean;
124
+ message: "User has already verified whatsapp";
125
+ }> | Err<ServerProcessingUserCreationError> | Err<NumberIsNotOnWhatsappError> | Ok<{
126
+ alreadyVerified: boolean;
127
+ message: "Verification message sent";
128
+ }> | Err<ValidationError<"params", z.ZodError<unknown>>> | Err<ValidationError<"query", z.ZodError<unknown>>> | Err<ValidationError<"body", z.ZodError<{
129
+ phone: bigint;
130
+ }>>>>;
131
+ type RequestWhatsappVerificationResponseBody = AsyncReturn<typeof requestWhatsappVerificationRoute>;
132
+
133
+ declare const checkHealth: (req: BasicRequest) => Promise<Ok<{
134
+ status: "up";
135
+ message: string;
136
+ }>>;
137
+ type CheckHealthResponseBody = AsyncReturn<typeof checkHealth>;
138
+
139
+ declare const ListTransactionsRequestQuerySchema: z__default.ZodObject<{
140
+ categories: z__default.ZodOptional<z__default.ZodArray<z__default.ZodEnum<{
141
+ readonly payment: "payment";
142
+ readonly transportation: "transportation";
143
+ readonly food_and_beverage: "food_and_beverage";
144
+ readonly groceries: "groceries";
145
+ readonly bills: "bills";
146
+ readonly subscriptions: "subscriptions";
147
+ readonly health: "health";
148
+ readonly appearance: "appearance";
149
+ readonly others: "others";
150
+ }>>>;
151
+ dates: z__default.ZodOptional<z__default.ZodDiscriminatedUnion<[z__default.ZodObject<{
152
+ kind: z__default.ZodLiteral<"between">;
153
+ start: z__default.ZodOptional<z__default.z.ZodCoercedDate<unknown>>;
154
+ end: z__default.ZodOptional<z__default.z.ZodCoercedDate<unknown>>;
155
+ }, z__default.z.core.$strip>, z__default.ZodObject<{
156
+ kind: z__default.ZodLiteral<"relative">;
157
+ when: z__default.ZodEnum<{
158
+ "this week": "this week";
159
+ "this month": "this month";
160
+ "past week": "past week";
161
+ "past month": "past month";
162
+ }>;
163
+ }, z__default.z.core.$strip>], "kind">>;
164
+ }, z__default.z.core.$strip>;
165
+ type ListTransactionsRequestQuery = z__default.infer<typeof ListTransactionsRequestQuerySchema>;
166
+ declare const GetTransactionsSummaryRequestQuerySchema: z__default.ZodObject<{
167
+ categories: z__default.ZodOptional<z__default.ZodArray<z__default.ZodEnum<{
168
+ readonly payment: "payment";
169
+ readonly transportation: "transportation";
170
+ readonly food_and_beverage: "food_and_beverage";
171
+ readonly groceries: "groceries";
172
+ readonly bills: "bills";
173
+ readonly subscriptions: "subscriptions";
174
+ readonly health: "health";
175
+ readonly appearance: "appearance";
176
+ readonly others: "others";
177
+ }>>>;
178
+ dates: z__default.ZodOptional<z__default.ZodDiscriminatedUnion<[z__default.ZodObject<{
179
+ kind: z__default.ZodLiteral<"between">;
180
+ start: z__default.ZodOptional<z__default.z.ZodCoercedDate<unknown>>;
181
+ end: z__default.ZodOptional<z__default.z.ZodCoercedDate<unknown>>;
182
+ }, z__default.z.core.$strip>, z__default.ZodObject<{
183
+ kind: z__default.ZodLiteral<"relative">;
184
+ when: z__default.ZodEnum<{
185
+ "this week": "this week";
186
+ "this month": "this month";
187
+ "past week": "past week";
188
+ "past month": "past month";
189
+ }>;
190
+ }, z__default.z.core.$strip>], "kind">>;
191
+ }, z__default.z.core.$strip>;
192
+ type GetTransactionsSummaryRequestQuery = z__default.infer<typeof GetTransactionsSummaryRequestQuerySchema>;
193
+ declare const CreateTransactionRequestBodySchema: z__default.ZodObject<{
194
+ description: z__default.ZodString;
195
+ amount: z__default.ZodNumber;
196
+ category: z__default.ZodEnum<{
197
+ readonly payment: "payment";
198
+ readonly transportation: "transportation";
199
+ readonly food_and_beverage: "food_and_beverage";
200
+ readonly groceries: "groceries";
201
+ readonly bills: "bills";
202
+ readonly subscriptions: "subscriptions";
203
+ readonly health: "health";
204
+ readonly appearance: "appearance";
205
+ readonly others: "others";
206
+ }>;
207
+ timestamp: z__default.ZodOptional<z__default.z.ZodISODateTime>;
208
+ }, z__default.z.core.$strip>;
209
+ type CreateTransactionRequestBody = z__default.infer<typeof CreateTransactionRequestBodySchema>;
210
+ declare const UpdateTransactionRequestParamsSchema: z__default.ZodObject<{
211
+ id: z__default.ZodInt;
212
+ }, z__default.z.core.$strip>;
213
+ type UpdateTransactionRequestParams = z__default.infer<typeof UpdateTransactionRequestParamsSchema>;
214
+ declare const UpdateTransactionRequestBodySchema: z__default.ZodObject<{
215
+ description: z__default.ZodOptional<z__default.ZodString>;
216
+ amount: z__default.ZodOptional<z__default.ZodNumber>;
217
+ category: z__default.ZodOptional<z__default.ZodEnum<{
218
+ readonly payment: "payment";
219
+ readonly transportation: "transportation";
220
+ readonly food_and_beverage: "food_and_beverage";
221
+ readonly groceries: "groceries";
222
+ readonly bills: "bills";
223
+ readonly subscriptions: "subscriptions";
224
+ readonly health: "health";
225
+ readonly appearance: "appearance";
226
+ readonly others: "others";
227
+ }>>;
228
+ timestamp: z__default.ZodOptional<z__default.z.ZodISODateTime>;
229
+ }, z__default.z.core.$strip>;
230
+ type UpdateTransactionRequestBody = z__default.infer<typeof UpdateTransactionRequestBodySchema>;
231
+
232
+ declare const listTransactionsRoute: (req: Omit<Omit<TypedAuthedRequest<{
233
+ query: ListTransactionsRequestQuery;
234
+ }>, "params" | "query" | "body"> & {
235
+ params: unknown;
236
+ query: unknown;
237
+ body: unknown;
238
+ }, "user">) => Promise<Err<InternalServerError> | Err<UnauthenticatedError> | Err<MalformedJWTError> | Err<ValidationError<"params", z.ZodError<unknown>>> | Ok<{
239
+ amount: number;
240
+ id: number;
241
+ createdAt: Date;
242
+ description: string;
243
+ category: TransactionCategory;
244
+ }[]> | Err<ValidationError<"query", z.ZodError<{
245
+ categories?: ("payment" | "transportation" | "food_and_beverage" | "groceries" | "bills" | "subscriptions" | "health" | "appearance" | "others")[];
246
+ dates?: {
247
+ kind: "between";
248
+ start?: Date;
249
+ end?: Date;
250
+ } | {
251
+ kind: "relative";
252
+ when: "this week" | "this month" | "past week" | "past month";
253
+ };
254
+ }>>> | Err<ValidationError<"body", z.ZodError<unknown>>>>;
255
+ type ListTransactionsResponseBody = AsyncReturn<typeof listTransactionsRoute>;
256
+ type SpendByMonth = {
257
+ month: Date;
258
+ total: number;
259
+ };
260
+ declare const getTransactionsSummaryRoute: (req: Omit<Omit<TypedAuthedRequest<{
261
+ query: GetTransactionsSummaryRequestQuery;
262
+ }>, "params" | "query" | "body"> & {
263
+ params: unknown;
264
+ query: unknown;
265
+ body: unknown;
266
+ }, "user">) => Promise<Err<InternalServerError> | Err<UnauthenticatedError> | Err<MalformedJWTError> | Err<ValidationError<"params", z.ZodError<unknown>>> | Err<ValidationError<"query", z.ZodError<{
267
+ categories?: ("payment" | "transportation" | "food_and_beverage" | "groceries" | "bills" | "subscriptions" | "health" | "appearance" | "others")[];
268
+ dates?: {
269
+ kind: "between";
270
+ start?: Date;
271
+ end?: Date;
272
+ } | {
273
+ kind: "relative";
274
+ when: "this week" | "this month" | "past week" | "past month";
275
+ };
276
+ }>>> | Err<ValidationError<"body", z.ZodError<unknown>>> | Ok<{
277
+ balance: number;
278
+ spendByCategory: {
279
+ category: TransactionCategory;
280
+ total: number;
281
+ }[];
282
+ spendByMonth: SpendByMonth[];
283
+ }>>;
284
+ type GetTransactionsSummaryResponseBody = AsyncReturn<typeof getTransactionsSummaryRoute>;
285
+ declare const createTransactionRoute: (req: Omit<Omit<TypedAuthedRequest<{
286
+ body: CreateTransactionRequestBody;
287
+ }>, "params" | "query" | "body"> & {
288
+ params: unknown;
289
+ query: unknown;
290
+ body: unknown;
291
+ }, "user">) => Promise<Err<InternalServerError> | Err<UnauthenticatedError> | Err<MalformedJWTError> | Err<ValidationError<"params", z.ZodError<unknown>>> | Err<ValidationError<"query", z.ZodError<unknown>>> | Ok<{
292
+ amount: number;
293
+ id: number;
294
+ createdAt: Date;
295
+ description: string;
296
+ category: TransactionCategory;
297
+ }> | Err<ValidationError<"body", z.ZodError<{
298
+ description: string;
299
+ amount: number;
300
+ category: "payment" | "transportation" | "food_and_beverage" | "groceries" | "bills" | "subscriptions" | "health" | "appearance" | "others";
301
+ timestamp?: string;
302
+ }>>>>;
303
+ type CreateTransactionResponseBody = AsyncReturn<typeof createTransactionRoute>;
304
+ declare class TransactionNotFoundError extends Error {
305
+ readonly _tag = "TransactionNotFound";
306
+ message: string;
307
+ constructor(message: string);
308
+ }
309
+ declare const updateTransactionRoute: (req: Omit<Omit<TypedAuthedRequest<{
310
+ params: UpdateTransactionRequestParams;
311
+ body: UpdateTransactionRequestBody;
312
+ }>, "params" | "query" | "body"> & {
313
+ params: unknown;
314
+ query: unknown;
315
+ body: unknown;
316
+ }, "user">) => Promise<Err<InternalServerError> | Err<UnauthenticatedError> | Err<MalformedJWTError> | Err<ValidationError<"query", z.ZodError<unknown>>> | Err<TransactionNotFoundError> | Err<ForbiddenError> | Ok<{
317
+ amount: number;
318
+ id: number;
319
+ createdAt: Date;
320
+ description: string;
321
+ category: TransactionCategory;
322
+ }> | Err<ValidationError<"params", z.ZodError<{
323
+ id: number;
324
+ }>>> | Err<ValidationError<"body", z.ZodError<{
325
+ description?: string;
326
+ amount?: number;
327
+ category?: "payment" | "transportation" | "food_and_beverage" | "groceries" | "bills" | "subscriptions" | "health" | "appearance" | "others";
328
+ timestamp?: string;
329
+ }>>>>;
330
+ type UpdateTransactionResponseBody = AsyncReturn<typeof updateTransactionRoute>;
331
+
332
+ type ApiRoutes = {
333
+ '/auth/whatsapp-verification': {
334
+ GET: {
335
+ response: IsUserWhatsappVerifiedResponseBody;
336
+ };
337
+ POST: {
338
+ body: RequestWhatsappVerificationRequestBody;
339
+ response: RequestWhatsappVerificationResponseBody;
340
+ };
341
+ };
342
+ '/health': {
343
+ GET: {
344
+ response: CheckHealthResponseBody;
345
+ };
346
+ };
347
+ '/transactions': {
348
+ GET: {
349
+ query: ListTransactionsRequestQuery;
350
+ response: ListTransactionsResponseBody;
351
+ };
352
+ POST: {
353
+ body: CreateTransactionRequestBody;
354
+ response: CreateTransactionResponseBody;
355
+ };
356
+ };
357
+ '/transactions/summary': {
358
+ GET: {
359
+ query: GetTransactionsSummaryRequestQuery;
360
+ response: GetTransactionsSummaryResponseBody;
361
+ };
362
+ };
363
+ '/transactions/:id': {
364
+ PUT: {
365
+ params: UpdateTransactionRequestParams;
366
+ body: UpdateTransactionRequestBody;
367
+ response: UpdateTransactionResponseBody;
368
+ };
369
+ };
370
+ };
371
+
372
+ export type { ApiRoutes, CheckHealthResponseBody, CreateTransactionRequestBody, CreateTransactionResponseBody, GetTransactionsSummaryRequestQuery, GetTransactionsSummaryResponseBody, IsUserWhatsappVerifiedResponseBody, ListTransactionsRequestQuery, ListTransactionsResponseBody, RequestWhatsappVerificationRequestBody, RequestWhatsappVerificationResponseBody, UpdateTransactionRequestBody, UpdateTransactionRequestParams, UpdateTransactionResponseBody };
package/package.json CHANGED
@@ -1,6 +1,25 @@
1
1
  {
2
2
  "name": "@duhnny/whatsapp-cashbook-api",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Type definitions for the whatsapp cashbook API",
5
+ "license": "ISC",
6
+ "author": "Daniel Betoret",
7
+ "type": "module",
8
+ "main": "",
9
+ "types": "dist/index.d.ts",
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "build": "tsup",
15
+ "prepublishOnly": "npm run build"
16
+ },
17
+ "dependencies": {
18
+ "fastify": "^5.12.8",
19
+ "zod": "^4.6.7"
20
+ },
21
+ "devDependencies": {
22
+ "tsup": "^9.0.0",
23
+ "typescript": "^6.0.3"
24
+ }
25
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.