Skip to content

Commit d5ebe1e

Browse files
committed
refactor: remove unnecesary schema for main class options
1 parent 2ce6197 commit d5ebe1e

File tree

3 files changed

+13
-30
lines changed

3 files changed

+13
-30
lines changed

packages/server/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export { GenerateQR } from "./qr";
1111
export { Reports } from "./reports";
1212
export * from "./schemas";
1313
export { Subscription } from "./subscriptions";
14-
export type { NequiOptions, SdkResponse } from "./types";
14+
export type { SdkResponse } from "./types";
1515
export { buildRequestHeader, buildRequestMessage } from "./utils/builders";
1616
export {
1717
handleValidationError,

packages/server/src/nequi.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { z } from "zod";
2-
31
import { nequiAuth } from "@/auth";
42
import { getUrls } from "@/constants";
53
import { Dispersions } from "@/dispersions";
@@ -9,9 +7,15 @@ import { GenerateQR } from "@/qr";
97
import { Reports } from "@/reports";
108
import { Subscription } from "@/subscriptions";
119
import type { SdkResponse } from "@/types";
12-
import { NequiOptionsSchema } from "@/types";
1310
import { handleValidationError } from "@/utils/validation";
1411

12+
export interface NequiOptions {
13+
apiKey: string;
14+
clientId: string;
15+
clientSecret: string;
16+
env: "development" | "production";
17+
}
18+
1519
export class Nequi {
1620
private readonly apiKey: string;
1721
private readonly clientId: string;
@@ -26,21 +30,11 @@ export class Nequi {
2630
readonly dispersions: Dispersions;
2731
readonly reports: Reports;
2832

29-
constructor(opts: z.input<typeof NequiOptionsSchema>) {
30-
const parsed = NequiOptionsSchema.safeParse(opts);
31-
32-
if (!parsed.success) {
33-
throw NequiError.from({
34-
message: `[Nequi SDK]: Invalid configuration - ${parsed.error.issues.map((e) => e.message).join(", ")}`,
35-
name: "missing_required_field",
36-
status: 422,
37-
});
38-
}
39-
40-
this.apiKey = parsed.data.apiKey;
41-
this.clientId = parsed.data.clientId;
42-
this.clientSecret = parsed.data.clientSecret;
43-
this.env = parsed.data.env;
33+
constructor(opts: NequiOptions) {
34+
this.apiKey = opts.apiKey;
35+
this.clientId = opts.clientId;
36+
this.clientSecret = opts.clientSecret;
37+
this.env = opts.env;
4438

4539
const urls = getUrls(this.env);
4640
this.basePath = urls.BASE_PATH;

packages/server/src/types.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
import type { output } from "zod";
2-
import { z } from "zod";
3-
41
import type { NequiError } from "./error";
52

6-
export const NequiOptionsSchema = z.object({
7-
apiKey: z.string().min(1, "API key is required"),
8-
clientId: z.string().min(1, "Client ID is required"),
9-
clientSecret: z.string().min(1, "Client secret is required"),
10-
env: z.enum(["development", "production"]).default("development"),
11-
});
12-
133
export type SdkResponse<T> = readonly [NequiError, null] | readonly [null, T];
14-
export type NequiOptions = output<typeof NequiOptionsSchema>;

0 commit comments

Comments
 (0)