mubaro 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.
Files changed (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +149 -0
  3. package/dist/client/Mubaro.d.ts +9 -0
  4. package/dist/client/Mubaro.js +16 -0
  5. package/dist/client/Mubaro.js.map +1 -0
  6. package/dist/core/HttpClient.d.ts +7 -0
  7. package/dist/core/HttpClient.js +25 -0
  8. package/dist/core/HttpClient.js.map +1 -0
  9. package/dist/core/constants.d.ts +2 -0
  10. package/dist/core/constants.js +3 -0
  11. package/dist/core/constants.js.map +1 -0
  12. package/dist/errors/AuthenticationError.d.ts +4 -0
  13. package/dist/errors/AuthenticationError.js +8 -0
  14. package/dist/errors/AuthenticationError.js.map +1 -0
  15. package/dist/errors/EmailDeliveryError.d.ts +4 -0
  16. package/dist/errors/EmailDeliveryError.js +8 -0
  17. package/dist/errors/EmailDeliveryError.js.map +1 -0
  18. package/dist/errors/InvalidOtpError.d.ts +4 -0
  19. package/dist/errors/InvalidOtpError.js +8 -0
  20. package/dist/errors/InvalidOtpError.js.map +1 -0
  21. package/dist/errors/MubaroError.d.ts +4 -0
  22. package/dist/errors/MubaroError.js +10 -0
  23. package/dist/errors/MubaroError.js.map +1 -0
  24. package/dist/errors/NotFoundError.d.ts +4 -0
  25. package/dist/errors/NotFoundError.js +8 -0
  26. package/dist/errors/NotFoundError.js.map +1 -0
  27. package/dist/errors/OtpAlreadyUsedError.d.ts +4 -0
  28. package/dist/errors/OtpAlreadyUsedError.js +8 -0
  29. package/dist/errors/OtpAlreadyUsedError.js.map +1 -0
  30. package/dist/errors/OtpExpiredError.d.ts +4 -0
  31. package/dist/errors/OtpExpiredError.js +8 -0
  32. package/dist/errors/OtpExpiredError.js.map +1 -0
  33. package/dist/errors/RateLimitError.d.ts +4 -0
  34. package/dist/errors/RateLimitError.js +8 -0
  35. package/dist/errors/RateLimitError.js.map +1 -0
  36. package/dist/errors/ValidationError.d.ts +4 -0
  37. package/dist/errors/ValidationError.js +8 -0
  38. package/dist/errors/ValidationError.js.map +1 -0
  39. package/dist/errors/createError.d.ts +1 -0
  40. package/dist/errors/createError.js +30 -0
  41. package/dist/errors/createError.js.map +1 -0
  42. package/dist/errors/index.d.ts +9 -0
  43. package/dist/errors/index.js +10 -0
  44. package/dist/errors/index.js.map +1 -0
  45. package/dist/index.d.ts +2 -0
  46. package/dist/index.js +3 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/modules/otp.d.ts +9 -0
  49. package/dist/modules/otp.js +13 -0
  50. package/dist/modules/otp.js.map +1 -0
  51. package/dist/requests/otp.d.ts +11 -0
  52. package/dist/requests/otp.js +2 -0
  53. package/dist/requests/otp.js.map +1 -0
  54. package/dist/responses/otp.d.ts +12 -0
  55. package/dist/responses/otp.js +2 -0
  56. package/dist/responses/otp.js.map +1 -0
  57. package/dist/types/Config.d.ts +4 -0
  58. package/dist/types/Config.js +2 -0
  59. package/dist/types/Config.js.map +1 -0
  60. package/dist/types/http.d.ts +1 -0
  61. package/dist/types/http.js +2 -0
  62. package/dist/types/http.js.map +1 -0
  63. package/dist/types/otp.d.ts +1 -0
  64. package/dist/types/otp.js +2 -0
  65. package/dist/types/otp.js.map +1 -0
  66. package/package.json +59 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ismail Mubarak
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,149 @@
1
+ # Mubaro Node.js SDK
2
+
3
+ Official Node.js SDK for Mubaro.
4
+
5
+ Send and verify one-time passwords (OTPs) with Mubaro's official Node.js SDK. Built with TypeScript for a fast, reliable, and developer-friendly authentication experience.
6
+
7
+ ---
8
+
9
+ ## Features
10
+
11
+ - 🚀 Simple API
12
+ - 🔐 Send OTPs with one method
13
+ - ✅ Verify OTPs with one method
14
+ - 🛡️ Typed errors
15
+ - 💙 First-class TypeScript support
16
+
17
+ ---
18
+
19
+ ## Requirements
20
+
21
+ - Node.js 18+
22
+ - Mubaro API Key
23
+
24
+ ---
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ npm install mubaro
30
+ ```
31
+
32
+ ---
33
+
34
+ ## Quick Start
35
+
36
+ ```ts
37
+ import { Mubaro } from "mubaro";
38
+
39
+ const mubaro = new Mubaro({
40
+ apiKey: process.env.MUBARO_API_KEY!,
41
+ });
42
+ ```
43
+
44
+ ---
45
+
46
+ ## Send an OTP
47
+
48
+ ```ts
49
+ const response = await mubaro.otp.sendOtp({
50
+ email: "user@example.com",
51
+ });
52
+
53
+ console.log(response);
54
+ ```
55
+
56
+ Example response
57
+
58
+ ```json
59
+ {
60
+ "id": "...",
61
+ "status": "sent",
62
+ "expires_at": "..."
63
+ }
64
+ ```
65
+
66
+ ---
67
+
68
+ ## Verify an OTP
69
+
70
+ ```ts
71
+ const response = await mubaro.otp.verifyOtp({
72
+ email: "user@example.com",
73
+ otp: "123456",
74
+ });
75
+
76
+ console.log(response);
77
+ ```
78
+
79
+ Example response
80
+
81
+ ```json
82
+ {
83
+ "id": "...",
84
+ "status": "verified",
85
+ "verified": true,
86
+ "code": "OTP_VERIFIED",
87
+ "message": "OTP verified successfully."
88
+ }
89
+ ```
90
+
91
+ ---
92
+
93
+ ## Error Handling
94
+
95
+ ```ts
96
+ import {
97
+ InvalidOtpError,
98
+ OtpExpiredError,
99
+ OtpAlreadyUsedError,
100
+ } from "mubaro";
101
+
102
+ try {
103
+ await mubaro.otp.verifyOtp({
104
+ email,
105
+ otp,
106
+ });
107
+ } catch (error) {
108
+ if (error instanceof InvalidOtpError) {
109
+ console.log("Incorrect OTP.");
110
+ }
111
+
112
+ if (error instanceof OtpExpiredError) {
113
+ console.log("OTP expired.");
114
+ }
115
+
116
+ if (error instanceof OtpAlreadyUsedError) {
117
+ console.log("OTP already used.");
118
+ }
119
+ }
120
+ ```
121
+
122
+ ---
123
+
124
+ ## API
125
+
126
+ | Method | Description |
127
+ |----------|-------------|
128
+ | sendOtp() | Sends an OTP |
129
+ | verifyOtp() | Verifies an OTP |
130
+
131
+ ---
132
+
133
+ ## TypeScript
134
+
135
+ The Mubaro SDK is written in TypeScript and ships with complete type definitions.
136
+
137
+ No additional typings are required.
138
+
139
+ ---
140
+
141
+ ## Documentation
142
+
143
+ https://www.mubaro.app/docs
144
+
145
+ ---
146
+
147
+ ## License
148
+
149
+ MIT
@@ -0,0 +1,9 @@
1
+ import type { MubaroConfig } from "../types/config.js";
2
+ import { Otp } from "../modules/Otp.js";
3
+ export declare class Mubaro {
4
+ readonly apiKey: string;
5
+ readonly baseUrl: string;
6
+ private readonly http;
7
+ readonly otp: Otp;
8
+ constructor(config: MubaroConfig);
9
+ }
@@ -0,0 +1,16 @@
1
+ import { DEFAULT_BASE_URL } from "../core/constants.js";
2
+ import { HttpClient } from "../core/HttpClient.js";
3
+ import { Otp } from "../modules/Otp.js";
4
+ export class Mubaro {
5
+ apiKey;
6
+ baseUrl;
7
+ http;
8
+ otp;
9
+ constructor(config) {
10
+ this.apiKey = config.apiKey;
11
+ this.baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
12
+ this.http = new HttpClient(this.baseUrl, this.apiKey);
13
+ this.otp = new Otp(this.http);
14
+ }
15
+ }
16
+ //# sourceMappingURL=Mubaro.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Mubaro.js","sourceRoot":"","sources":["../../src/client/Mubaro.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAExC,MAAM,OAAO,MAAM;IACD,MAAM,CAAS;IACf,OAAO,CAAS;IACf,IAAI,CAAa;IAClB,GAAG,CAAM;IACzB,YAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,gBAAgB,CAAC;QAClD,IAAI,CAAC,IAAI,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACtD,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;CAGF"}
@@ -0,0 +1,7 @@
1
+ import type { HttpMethod } from "../types/http.js";
2
+ export declare class HttpClient {
3
+ private readonly baseUrl;
4
+ private readonly apiKey;
5
+ constructor(baseUrl: string, apiKey: string);
6
+ request<T>(method: HttpMethod, path: string, body?: unknown): Promise<T>;
7
+ }
@@ -0,0 +1,25 @@
1
+ import { createError } from "../errors/createError.js";
2
+ export class HttpClient {
3
+ baseUrl;
4
+ apiKey;
5
+ constructor(baseUrl, apiKey) {
6
+ this.baseUrl = baseUrl;
7
+ this.apiKey = apiKey;
8
+ }
9
+ async request(method, path, body) {
10
+ const response = await fetch(`${this.baseUrl}${path}`, {
11
+ method,
12
+ headers: {
13
+ "Content-Type": "application/json",
14
+ "x-api-key": this.apiKey,
15
+ },
16
+ body: body ? JSON.stringify(body) : undefined,
17
+ });
18
+ const data = await response.json().catch(() => ({}));
19
+ if (!response.ok) {
20
+ throw createError(response.status, data.code, data.message ?? "Unknown error");
21
+ }
22
+ return data;
23
+ }
24
+ }
25
+ //# sourceMappingURL=HttpClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpClient.js","sourceRoot":"","sources":["../../src/core/HttpClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAC,MAAM,0BAA0B,CAAC;AACrD,MAAM,OAAO,UAAU;IAEF,OAAO;IACP,MAAM;IAFzB,YACmB,OAAe,EACf,MAAc;uBADd,OAAO;sBACP,MAAM;IACtB,CAAC;IAEJ,KAAK,CAAC,OAAO,CACX,MAAkB,EAClB,IAAY,EACZ,IAAc;QAEd,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,EAAE,EAAE;YACrD,MAAM;YACN,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,WAAW,EAAE,IAAI,CAAC,MAAM;aACzB;YACD,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;SAC9C,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAErD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YAChB,MAAM,WAAW,CACf,QAAQ,CAAC,MAAM,EACf,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,OAAO,IAAI,eAAe,CAChC,CAAC;QACL,CAAC;QAED,OAAO,IAAS,CAAC;IACnB,CAAC;CAGF"}
@@ -0,0 +1,2 @@
1
+ export declare const DEFAULT_BASE_URL = "https://api.mubaro.app/api";
2
+ export declare const API_KEY_HEADER = "x-api-key";
@@ -0,0 +1,3 @@
1
+ export const DEFAULT_BASE_URL = "https://api.mubaro.app/api";
2
+ export const API_KEY_HEADER = "x-api-key";
3
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/core/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,4BAA4B,CAAC;AAC7D,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { MubaroError } from "./MubaroError.js";
2
+ export declare class AuthenticationError extends MubaroError {
3
+ constructor(message: string, code?: string);
4
+ }
@@ -0,0 +1,8 @@
1
+ import { MubaroError } from "./MubaroError.js";
2
+ export class AuthenticationError extends MubaroError {
3
+ constructor(message, code) {
4
+ super(message, code);
5
+ this.name = "AuthenticationError";
6
+ }
7
+ }
8
+ //# sourceMappingURL=AuthenticationError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthenticationError.js","sourceRoot":"","sources":["../../src/errors/AuthenticationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAE7C,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAClD,YAAY,OAAe,EAAE,IAAa;QACxC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAErB,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ import { MubaroError } from "./MubaroError.js";
2
+ export declare class EmailDeliveryError extends MubaroError {
3
+ constructor(message: string, code?: string);
4
+ }
@@ -0,0 +1,8 @@
1
+ import { MubaroError } from "./MubaroError.js";
2
+ export class EmailDeliveryError extends MubaroError {
3
+ constructor(message, code) {
4
+ super(message, code);
5
+ this.name = "EmailDeliveryError";
6
+ }
7
+ }
8
+ //# sourceMappingURL=EmailDeliveryError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EmailDeliveryError.js","sourceRoot":"","sources":["../../src/errors/EmailDeliveryError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IACjD,YAAY,OAAe,EAAE,IAAa;QACxC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAErB,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ import { MubaroError } from "./MubaroError.js";
2
+ export declare class InvalidOtpError extends MubaroError {
3
+ constructor(message: string, code?: string);
4
+ }
@@ -0,0 +1,8 @@
1
+ import { MubaroError } from "./MubaroError.js";
2
+ export class InvalidOtpError extends MubaroError {
3
+ constructor(message, code) {
4
+ super(message, code);
5
+ this.name = "InvalidOtpError";
6
+ }
7
+ }
8
+ //# sourceMappingURL=InvalidOtpError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InvalidOtpError.js","sourceRoot":"","sources":["../../src/errors/InvalidOtpError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,OAAO,eAAgB,SAAQ,WAAW;IAC9C,YAAY,OAAe,EAAE,IAAa;QACxC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAErB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ export declare class MubaroError extends Error {
2
+ readonly code?: string;
3
+ constructor(message: string, code?: string);
4
+ }
@@ -0,0 +1,10 @@
1
+ export class MubaroError extends Error {
2
+ code;
3
+ constructor(message, code) {
4
+ super(message);
5
+ this.name = "MubaroError";
6
+ this.code = code;
7
+ Object.setPrototypeOf(this, new.target.prototype);
8
+ }
9
+ }
10
+ //# sourceMappingURL=MubaroError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MubaroError.js","sourceRoot":"","sources":["../../src/errors/MubaroError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpB,IAAI,CAAU;IAE9B,YAAY,OAAe,EAAE,IAAa;QACxC,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QAEjB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ import { MubaroError } from "./MubaroError.js";
2
+ export declare class NotFoundError extends MubaroError {
3
+ constructor(message: string, code?: string);
4
+ }
@@ -0,0 +1,8 @@
1
+ import { MubaroError } from "./MubaroError.js";
2
+ export class NotFoundError extends MubaroError {
3
+ constructor(message, code) {
4
+ super(message, code);
5
+ this.name = "NotFoundError";
6
+ }
7
+ }
8
+ //# sourceMappingURL=NotFoundError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotFoundError.js","sourceRoot":"","sources":["../../src/errors/NotFoundError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,OAAO,aAAc,SAAQ,WAAW;IAC5C,YAAY,OAAe,EAAE,IAAa;QACxC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAErB,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ import { MubaroError } from "./MubaroError.js";
2
+ export declare class OtpAlreadyUsedError extends MubaroError {
3
+ constructor(message: string, code?: string);
4
+ }
@@ -0,0 +1,8 @@
1
+ import { MubaroError } from "./MubaroError.js";
2
+ export class OtpAlreadyUsedError extends MubaroError {
3
+ constructor(message, code) {
4
+ super(message, code);
5
+ this.name = "OtpAlreadyUsedError";
6
+ }
7
+ }
8
+ //# sourceMappingURL=OtpAlreadyUsedError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OtpAlreadyUsedError.js","sourceRoot":"","sources":["../../src/errors/OtpAlreadyUsedError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAClD,YAAY,OAAe,EAAE,IAAa;QACxC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAErB,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ import { MubaroError } from "./MubaroError.js";
2
+ export declare class OtpExpiredError extends MubaroError {
3
+ constructor(message: string, code?: string);
4
+ }
@@ -0,0 +1,8 @@
1
+ import { MubaroError } from "./MubaroError.js";
2
+ export class OtpExpiredError extends MubaroError {
3
+ constructor(message, code) {
4
+ super(message, code);
5
+ this.name = "OtpExpiredError";
6
+ }
7
+ }
8
+ //# sourceMappingURL=OtpExpiredError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OtpExpiredError.js","sourceRoot":"","sources":["../../src/errors/OtpExpiredError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,OAAO,eAAgB,SAAQ,WAAW;IAC9C,YAAY,OAAe,EAAE,IAAc;QACzC,KAAK,CAAC,OAAO,EAAC,IAAI,CAAC,CAAC;QAEpB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ import { MubaroError } from "./MubaroError.js";
2
+ export declare class RateLimitError extends MubaroError {
3
+ constructor(message: string, code?: string);
4
+ }
@@ -0,0 +1,8 @@
1
+ import { MubaroError } from "./MubaroError.js";
2
+ export class RateLimitError extends MubaroError {
3
+ constructor(message, code) {
4
+ super(message, code);
5
+ this.name = "RateLimitError";
6
+ }
7
+ }
8
+ //# sourceMappingURL=RateLimitError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RateLimitError.js","sourceRoot":"","sources":["../../src/errors/RateLimitError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,OAAO,cAAe,SAAQ,WAAW;IAC7C,YAAY,OAAe,EAAE,IAAa;QACxC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAErB,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ import { MubaroError } from "./MubaroError.js";
2
+ export declare class ValidationError extends MubaroError {
3
+ constructor(message: string, code?: string);
4
+ }
@@ -0,0 +1,8 @@
1
+ import { MubaroError } from "./MubaroError.js";
2
+ export class ValidationError extends MubaroError {
3
+ constructor(message, code) {
4
+ super(message, code);
5
+ this.name = "ValidationError";
6
+ }
7
+ }
8
+ //# sourceMappingURL=ValidationError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidationError.js","sourceRoot":"","sources":["../../src/errors/ValidationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,OAAO,eAAgB,SAAQ,WAAW;IAC9C,YAAY,OAAe,EAAE,IAAa;QACxC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAErB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF"}
@@ -0,0 +1 @@
1
+ export declare function createError(status: number, code: string | undefined, message: string): Error;
@@ -0,0 +1,30 @@
1
+ import { MubaroError, ValidationError, AuthenticationError, RateLimitError, NotFoundError, InvalidOtpError, OtpExpiredError, OtpAlreadyUsedError, EmailDeliveryError, } from "./index.js";
2
+ export function createError(status, code, message) {
3
+ switch (code) {
4
+ case "INVALID_OTP":
5
+ return new InvalidOtpError(message, code);
6
+ case "OTP_EXPIRED":
7
+ return new OtpExpiredError(message, code);
8
+ case "OTP_ALREADY_USED":
9
+ return new OtpAlreadyUsedError(message, code);
10
+ case "EMAIL_DELIVERY_FAILED":
11
+ return new EmailDeliveryError(message, code);
12
+ case "OTP_NOT_FOUND":
13
+ return new NotFoundError(message, code);
14
+ }
15
+ switch (status) {
16
+ case 400:
17
+ case 422:
18
+ return new ValidationError(message);
19
+ case 401:
20
+ case 403:
21
+ return new AuthenticationError(message);
22
+ case 404:
23
+ return new NotFoundError(message);
24
+ case 429:
25
+ return new RateLimitError(message);
26
+ default:
27
+ return new MubaroError(message);
28
+ }
29
+ }
30
+ //# sourceMappingURL=createError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createError.js","sourceRoot":"","sources":["../../src/errors/createError.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,eAAe,EACf,eAAe,EACf,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAEpB,MAAM,UAAU,WAAW,CACzB,MAAc,EACd,IAAwB,EACxB,OAAe;IAEf,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,aAAa;YAChB,OAAO,IAAI,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAE5C,KAAK,aAAa;YAChB,OAAO,IAAI,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAE5C,KAAK,kBAAkB;YACrB,OAAO,IAAI,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAEhD,KAAK,uBAAuB;YAC1B,OAAO,IAAI,kBAAkB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAE/C,KAAK,eAAe;YAClB,OAAO,IAAI,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC5C,CAAC;IAED,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,GAAG,CAAC;QACT,KAAK,GAAG;YACN,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;QAEtC,KAAK,GAAG,CAAC;QACT,KAAK,GAAG;YACN,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAE1C,KAAK,GAAG;YACN,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;QAEpC,KAAK,GAAG;YACN,OAAO,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;QAErC;YACE,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;AACH,CAAC"}
@@ -0,0 +1,9 @@
1
+ export * from "./MubaroError.js";
2
+ export * from "./AuthenticationError.js";
3
+ export * from "./ValidationError.js";
4
+ export * from "./RateLimitError.js";
5
+ export * from "./NotFoundError.js";
6
+ export * from "./InvalidOtpError.js";
7
+ export * from "./OtpExpiredError.js";
8
+ export * from "./OtpAlreadyUsedError.js";
9
+ export * from "./EmailDeliveryError.js";
@@ -0,0 +1,10 @@
1
+ export * from "./MubaroError.js";
2
+ export * from "./AuthenticationError.js";
3
+ export * from "./ValidationError.js";
4
+ export * from "./RateLimitError.js";
5
+ export * from "./NotFoundError.js";
6
+ export * from "./InvalidOtpError.js";
7
+ export * from "./OtpExpiredError.js";
8
+ export * from "./OtpAlreadyUsedError.js";
9
+ export * from "./EmailDeliveryError.js";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { Mubaro } from "./client/Mubaro.js";
2
+ export { MubaroError, AuthenticationError, RateLimitError, InvalidOtpError, OtpExpiredError, OtpAlreadyUsedError, EmailDeliveryError, } from "./errors/index.js";
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { Mubaro } from "./client/Mubaro.js";
2
+ export { MubaroError, AuthenticationError, RateLimitError, InvalidOtpError, OtpExpiredError, OtpAlreadyUsedError, EmailDeliveryError, } from "./errors/index.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,eAAe,EACf,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { HttpClient } from "../core/HttpClient.js";
2
+ import type { SendOtpRequest, VerifyOtpRequest } from "../requests/otp.js";
3
+ import type { SendOtpResponse, VerifyOtpResponse } from "../responses/otp.js";
4
+ export declare class Otp {
5
+ private readonly http;
6
+ constructor(http: HttpClient);
7
+ sendOtp(data: SendOtpRequest): Promise<SendOtpResponse>;
8
+ verifyOtp(data: VerifyOtpRequest): Promise<VerifyOtpResponse>;
9
+ }
@@ -0,0 +1,13 @@
1
+ export class Otp {
2
+ http;
3
+ constructor(http) {
4
+ this.http = http;
5
+ }
6
+ sendOtp(data) {
7
+ return this.http.request("POST", "/otp-services/send-otp", data);
8
+ }
9
+ verifyOtp(data) {
10
+ return this.http.request("POST", "/otp-services/verify-otp", data);
11
+ }
12
+ }
13
+ //# sourceMappingURL=Otp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Otp.js","sourceRoot":"","sources":["../../src/modules/Otp.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,GAAG;IACe,IAAI;IAAjC,YAA6B,IAAgB;oBAAhB,IAAI;IAAe,CAAC;IAEjD,OAAO,CAAC,IAAoB;QAC1B,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CACtB,MAAM,EACN,wBAAwB,EACxB,IAAI,CACL,CAAC;IACJ,CAAC;IAED,SAAS,CAAC,IAAsB;QAC9B,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CACtB,MAAM,EACN,0BAA0B,EAC1B,IAAI,CACL,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,11 @@
1
+ export interface SendOtpRequest {
2
+ email: string;
3
+ subject?: string;
4
+ html?: string;
5
+ text?: string;
6
+ template?: string;
7
+ }
8
+ export interface VerifyOtpRequest {
9
+ email: string;
10
+ otp: string;
11
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=otp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otp.js","sourceRoot":"","sources":["../../src/requests/otp.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ export interface SendOtpResponse {
2
+ id: string;
3
+ status: string;
4
+ expires_at: string;
5
+ }
6
+ export interface VerifyOtpResponse {
7
+ id: string;
8
+ status: string;
9
+ verified: boolean;
10
+ code: string;
11
+ message: string;
12
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=otp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otp.js","sourceRoot":"","sources":["../../src/responses/otp.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export interface MubaroConfig {
2
+ apiKey: string;
3
+ baseUrl?: string;
4
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/types/http.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=otp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otp.js","sourceRoot":"","sources":["../../src/types/otp.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "mubaro",
3
+ "version": "1.0.0",
4
+ "description": "Official Node.js SDK for sending and verifying OTPs with Mubaro.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "sideEffects": false,
18
+ "engines": {
19
+ "node": ">=18"
20
+ },
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "dev": "tsc --watch",
24
+ "example": "tsx examples/basic.ts",
25
+ "prepublishOnly": "npm run build"
26
+ },
27
+ "keywords": [
28
+ "mubaro",
29
+ "otp",
30
+ "authentication",
31
+ "verification",
32
+ "email",
33
+ "2fa",
34
+ "sdk",
35
+ "node",
36
+ "typescript",
37
+ "passwordless"
38
+ ],
39
+ "author": "Ismail Mubarak",
40
+ "license": "MIT",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/mubarsky/Mubaro-node.git"
44
+ },
45
+ "homepage": "https://www.mubaro.app/docs",
46
+ "bugs": {
47
+ "url": "https://github.com/mubarsky/Mubaro-node/issues"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "devDependencies": {
53
+ "tsx": "^4.23.1",
54
+ "typescript": "^7.0.2"
55
+ },
56
+ "dependencies": {
57
+ "mubaro": "file:mubaro-1.0.0.tgz"
58
+ }
59
+ }