@duhnny/whatsapp-cashbook-api 0.0.1 → 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.
Files changed (2) hide show
  1. package/dist/index.d.ts +255 -10
  2. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { FastifyRequest } from 'fastify';
2
1
  import * as z from 'zod';
3
2
  import z__default from 'zod';
3
+ import { FastifyRequest } from 'fastify';
4
4
 
5
5
  declare class Ok<T> {
6
6
  readonly _tag = "ok";
@@ -19,6 +19,18 @@ declare const Role: {
19
19
  readonly SUPERADMIN: "SUPERADMIN";
20
20
  };
21
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];
22
34
 
23
35
  type BasicUserData = {
24
36
  id: ID;
@@ -29,6 +41,9 @@ type BasicUserData = {
29
41
  type BasicRequest = Omit<FastifyRequest, 'user'> & {
30
42
  user: BasicUserData | undefined;
31
43
  };
44
+ type AuthedRequest = Omit<BasicRequest, 'user'> & {
45
+ user: BasicUserData;
46
+ };
32
47
  type TypedRequest<T extends {
33
48
  params?: any;
34
49
  query?: any;
@@ -50,6 +65,11 @@ declare class UnauthenticatedError {
50
65
  message?: string;
51
66
  constructor(message?: string);
52
67
  }
68
+ declare class ForbiddenError {
69
+ readonly _tag = "Forbidden";
70
+ message?: string;
71
+ constructor(message?: string);
72
+ }
53
73
  declare class ValidationError<W extends 'params' | 'body' | 'query', E> {
54
74
  readonly _tag = "ValidationError";
55
75
  where: W;
@@ -72,12 +92,16 @@ declare class MalformedJWTError extends Error {
72
92
  }
73
93
 
74
94
  declare const RequestWhatsappVerificationRequestBodySchema: z__default.ZodObject<{
75
- phone: z__default.ZodBigInt;
95
+ phone: z__default.z.ZodCoercedBigInt<unknown>;
76
96
  }, z__default.z.core.$strip>;
77
97
  type RequestWhatsappVerificationRequestBody = z__default.infer<typeof RequestWhatsappVerificationRequestBodySchema>;
78
98
 
79
99
  type AsyncReturn<T extends (arg0: any) => Promise<any>> = Awaited<ReturnType<T>>;
80
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>;
81
105
  declare class NumberIsNotOnWhatsappError extends Error {
82
106
  readonly _tag = "NumberIsNotOnWhatsapp";
83
107
  message: string;
@@ -95,7 +119,7 @@ declare const requestWhatsappVerificationRoute: (req: Omit<Omit<TypedAuthedReque
95
119
  params: unknown;
96
120
  query: unknown;
97
121
  body: unknown;
98
- }, "user">) => Promise<Err<InternalServerError> | Ok<{
122
+ }, "user">) => Promise<Err<InternalServerError> | Err<UnauthenticatedError> | Err<MalformedJWTError> | Ok<{
99
123
  alreadyVerified: boolean;
100
124
  message: "User has already verified whatsapp";
101
125
  }> | Err<ServerProcessingUserCreationError> | Err<NumberIsNotOnWhatsappError> | Ok<{
@@ -103,7 +127,7 @@ declare const requestWhatsappVerificationRoute: (req: Omit<Omit<TypedAuthedReque
103
127
  message: "Verification message sent";
104
128
  }> | Err<ValidationError<"params", z.ZodError<unknown>>> | Err<ValidationError<"query", z.ZodError<unknown>>> | Err<ValidationError<"body", z.ZodError<{
105
129
  phone: bigint;
106
- }>>> | Err<UnauthenticatedError> | Err<MalformedJWTError>>;
130
+ }>>>>;
107
131
  type RequestWhatsappVerificationResponseBody = AsyncReturn<typeof requestWhatsappVerificationRoute>;
108
132
 
109
133
  declare const checkHealth: (req: BasicRequest) => Promise<Ok<{
@@ -112,16 +136,237 @@ declare const checkHealth: (req: BasicRequest) => Promise<Ok<{
112
136
  }>>;
113
137
  type CheckHealthResponseBody = AsyncReturn<typeof checkHealth>;
114
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
+
115
332
  type ApiRoutes = {
116
333
  '/auth/whatsapp-verification': {
117
- method: 'POST';
118
- body: RequestWhatsappVerificationRequestBody;
119
- response: RequestWhatsappVerificationResponseBody;
334
+ GET: {
335
+ response: IsUserWhatsappVerifiedResponseBody;
336
+ };
337
+ POST: {
338
+ body: RequestWhatsappVerificationRequestBody;
339
+ response: RequestWhatsappVerificationResponseBody;
340
+ };
120
341
  };
121
342
  '/health': {
122
- method: 'GET';
123
- response: CheckHealthResponseBody;
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
+ };
124
369
  };
125
370
  };
126
371
 
127
- export type { ApiRoutes, CheckHealthResponseBody, RequestWhatsappVerificationRequestBody, RequestWhatsappVerificationResponseBody };
372
+ export type { ApiRoutes, CheckHealthResponseBody, CreateTransactionRequestBody, CreateTransactionResponseBody, GetTransactionsSummaryRequestQuery, GetTransactionsSummaryResponseBody, IsUserWhatsappVerifiedResponseBody, ListTransactionsRequestQuery, ListTransactionsResponseBody, RequestWhatsappVerificationRequestBody, RequestWhatsappVerificationResponseBody, UpdateTransactionRequestBody, UpdateTransactionRequestParams, UpdateTransactionResponseBody };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duhnny/whatsapp-cashbook-api",
3
- "version": "0.0.1",
3
+ "version": "0.2.0",
4
4
  "description": "Type definitions for the whatsapp cashbook API",
5
5
  "license": "ISC",
6
6
  "author": "Daniel Betoret",