@duhnny/whatsapp-cashbook-api 0.0.0-stage → 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/dist/index.d.ts +127 -0
- package/package.json +23 -4
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { FastifyRequest } from 'fastify';
|
|
2
|
+
import * as z from 'zod';
|
|
3
|
+
import z__default from 'zod';
|
|
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
|
+
|
|
23
|
+
type BasicUserData = {
|
|
24
|
+
id: ID;
|
|
25
|
+
phone: bigint | null;
|
|
26
|
+
email: string;
|
|
27
|
+
roles: Role[];
|
|
28
|
+
};
|
|
29
|
+
type BasicRequest = Omit<FastifyRequest, 'user'> & {
|
|
30
|
+
user: BasicUserData | undefined;
|
|
31
|
+
};
|
|
32
|
+
type TypedRequest<T extends {
|
|
33
|
+
params?: any;
|
|
34
|
+
query?: any;
|
|
35
|
+
body?: any;
|
|
36
|
+
} = {}> = BasicRequest & {
|
|
37
|
+
params: 'params' extends keyof T ? T['params'] : unknown;
|
|
38
|
+
query: 'query' extends keyof T ? T['query'] : unknown;
|
|
39
|
+
body: 'body' extends keyof T ? T['body'] : unknown;
|
|
40
|
+
};
|
|
41
|
+
type TypedAuthedRequest<T extends {
|
|
42
|
+
params?: any;
|
|
43
|
+
query?: any;
|
|
44
|
+
body?: any;
|
|
45
|
+
} = {}> = Omit<TypedRequest<T>, 'user'> & {
|
|
46
|
+
user: BasicUserData;
|
|
47
|
+
};
|
|
48
|
+
declare class UnauthenticatedError {
|
|
49
|
+
readonly _tag = "Unauthenticated";
|
|
50
|
+
message?: string;
|
|
51
|
+
constructor(message?: string);
|
|
52
|
+
}
|
|
53
|
+
declare class ValidationError<W extends 'params' | 'body' | 'query', E> {
|
|
54
|
+
readonly _tag = "ValidationError";
|
|
55
|
+
where: W;
|
|
56
|
+
parseError: E;
|
|
57
|
+
message?: string;
|
|
58
|
+
constructor(where: W, parseError: E, message?: string);
|
|
59
|
+
}
|
|
60
|
+
declare class InternalServerError {
|
|
61
|
+
readonly _tag = "InternalServerError";
|
|
62
|
+
message: string;
|
|
63
|
+
constructor(message: string);
|
|
64
|
+
}
|
|
65
|
+
declare const IdSchema: z__default.ZodInt;
|
|
66
|
+
type ID = z__default.infer<typeof IdSchema>;
|
|
67
|
+
|
|
68
|
+
declare class MalformedJWTError extends Error {
|
|
69
|
+
readonly _tag = "MalformedJWT";
|
|
70
|
+
message: string;
|
|
71
|
+
constructor(message: string);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
declare const RequestWhatsappVerificationRequestBodySchema: z__default.ZodObject<{
|
|
75
|
+
phone: z__default.ZodBigInt;
|
|
76
|
+
}, z__default.z.core.$strip>;
|
|
77
|
+
type RequestWhatsappVerificationRequestBody = z__default.infer<typeof RequestWhatsappVerificationRequestBodySchema>;
|
|
78
|
+
|
|
79
|
+
type AsyncReturn<T extends (arg0: any) => Promise<any>> = Awaited<ReturnType<T>>;
|
|
80
|
+
|
|
81
|
+
declare class NumberIsNotOnWhatsappError extends Error {
|
|
82
|
+
readonly _tag = "NumberIsNotOnWhatsapp";
|
|
83
|
+
message: string;
|
|
84
|
+
phone: bigint;
|
|
85
|
+
constructor(phone: bigint, message: string);
|
|
86
|
+
}
|
|
87
|
+
declare class ServerProcessingUserCreationError extends Error {
|
|
88
|
+
readonly _tag = "ServerProcessingUserCreation";
|
|
89
|
+
message: string;
|
|
90
|
+
constructor(message: string);
|
|
91
|
+
}
|
|
92
|
+
declare const requestWhatsappVerificationRoute: (req: Omit<Omit<TypedAuthedRequest<{
|
|
93
|
+
body: RequestWhatsappVerificationRequestBody;
|
|
94
|
+
}>, "params" | "query" | "body"> & {
|
|
95
|
+
params: unknown;
|
|
96
|
+
query: unknown;
|
|
97
|
+
body: unknown;
|
|
98
|
+
}, "user">) => Promise<Err<InternalServerError> | Ok<{
|
|
99
|
+
alreadyVerified: boolean;
|
|
100
|
+
message: "User has already verified whatsapp";
|
|
101
|
+
}> | Err<ServerProcessingUserCreationError> | Err<NumberIsNotOnWhatsappError> | Ok<{
|
|
102
|
+
alreadyVerified: boolean;
|
|
103
|
+
message: "Verification message sent";
|
|
104
|
+
}> | Err<ValidationError<"params", z.ZodError<unknown>>> | Err<ValidationError<"query", z.ZodError<unknown>>> | Err<ValidationError<"body", z.ZodError<{
|
|
105
|
+
phone: bigint;
|
|
106
|
+
}>>> | Err<UnauthenticatedError> | Err<MalformedJWTError>>;
|
|
107
|
+
type RequestWhatsappVerificationResponseBody = AsyncReturn<typeof requestWhatsappVerificationRoute>;
|
|
108
|
+
|
|
109
|
+
declare const checkHealth: (req: BasicRequest) => Promise<Ok<{
|
|
110
|
+
status: "up";
|
|
111
|
+
message: string;
|
|
112
|
+
}>>;
|
|
113
|
+
type CheckHealthResponseBody = AsyncReturn<typeof checkHealth>;
|
|
114
|
+
|
|
115
|
+
type ApiRoutes = {
|
|
116
|
+
'/auth/whatsapp-verification': {
|
|
117
|
+
method: 'POST';
|
|
118
|
+
body: RequestWhatsappVerificationRequestBody;
|
|
119
|
+
response: RequestWhatsappVerificationResponseBody;
|
|
120
|
+
};
|
|
121
|
+
'/health': {
|
|
122
|
+
method: 'GET';
|
|
123
|
+
response: CheckHealthResponseBody;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export type { ApiRoutes, CheckHealthResponseBody, RequestWhatsappVerificationRequestBody, RequestWhatsappVerificationResponseBody };
|
package/package.json
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@duhnny/whatsapp-cashbook-api",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
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