@regojs/erp-sdk 1.0.3 → 1.0.4

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,5 @@
1
+ export declare enum EScriptIds {
2
+ routesId = "rego-routes",
3
+ dataId = "rego-data",
4
+ metadataId = "rego-metadata"
5
+ }
@@ -0,0 +1 @@
1
+ export * as Enums from "./enums";
@@ -0,0 +1,4 @@
1
+ export * from "./constants";
2
+ export * from "./providers";
3
+ export * from "./types";
4
+ export * from "./validators";
@@ -0,0 +1 @@
1
+ export { RegoProvider } from "./regoProvider";
@@ -0,0 +1,6 @@
1
+ import type { IRegoProvider } from "../types";
2
+ export declare class RegoProvider implements IRegoProvider {
3
+ private readonly document;
4
+ constructor(document: Document);
5
+ getRoutes(): ReturnType<IRegoProvider["getRoutes"]>;
6
+ }
@@ -0,0 +1 @@
1
+ export type * from "./regoProvider";
@@ -0,0 +1,4 @@
1
+ import type { TRoute } from "../validators";
2
+ export interface IRegoProvider {
3
+ getRoutes(): Array<TRoute> | undefined;
4
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./routes";
2
+ export type * from "./routes";
@@ -0,0 +1,6 @@
1
+ import type { output } from "zod";
2
+ export declare const routeSchema: import("zod").ZodObject<{
3
+ path: import("zod").ZodString;
4
+ component: import("zod").ZodString;
5
+ }, import("zod/v4/core").$strip>;
6
+ export type TRoute = output<typeof routeSchema>;
package/package.json CHANGED
@@ -4,10 +4,11 @@
4
4
  "url": "https://github.com/rego-solution/erp-sdk/issues"
5
5
  },
6
6
  "dependencies": {
7
- "jose": "^6.2.12"
7
+ "jose": "^6.2.12",
8
+ "zod": "^4.6.1"
8
9
  },
9
10
  "devDependencies": {
10
- "@types/bun": "^1.4.1",
11
+ "@types/bun": "^1.4.2",
11
12
  "@types/node": "^26.5.0",
12
13
  "prettier": "^3.9.6",
13
14
  "typescript": "^7.0.2"
@@ -22,7 +23,8 @@
22
23
  "ts",
23
24
  "bun",
24
25
  "node",
25
- "SDK"
26
+ "SDK",
27
+ "zod"
26
28
  ],
27
29
  "license": "MIT",
28
30
  "main": "./dist/index.js",
@@ -42,22 +44,27 @@
42
44
  "test": "bun --hot run __test/index.ts"
43
45
  },
44
46
  "types": "./dist/index.d.ts",
45
- "version": "1.0.3",
47
+ "version": "1.0.4",
46
48
  "exports": {
47
49
  ".": {
48
50
  "import": "./dist/index.js",
49
51
  "require": "./dist/index.js",
50
52
  "types": "./dist/index.d.ts"
51
53
  },
54
+ "./server": {
55
+ "import": "./dist/server/index.js",
56
+ "require": "./dist/server/index.js",
57
+ "types": "./dist/server/index.d.ts"
58
+ },
52
59
  "./browser": {
53
60
  "import": "./dist/browser/index.js",
54
61
  "require": "./dist/browser/index.js",
55
62
  "types": "./dist/browser/index.d.ts"
56
63
  },
57
- "./server": {
58
- "import": "./dist/server/index.js",
59
- "require": "./dist/server/index.js",
60
- "types": "./dist/server/index.d.ts"
64
+ "./browser/vanilla": {
65
+ "import": "./dist/browser/vanilla/index.js",
66
+ "require": "./dist/browser/vanilla/index.js",
67
+ "types": "./dist/browser/vanilla/index.d.ts"
61
68
  }
62
69
  }
63
70
  }
@@ -0,0 +1 @@
1
+ export * as Vanilla from "./vanilla";
@@ -0,0 +1,5 @@
1
+ export enum EScriptIds {
2
+ routesId = "rego-routes",
3
+ dataId = "rego-data",
4
+ metadataId = "rego-metadata"
5
+ }
@@ -0,0 +1 @@
1
+ export * as Enums from "./enums";
@@ -0,0 +1,4 @@
1
+ export * from "./constants";
2
+ export * from "./providers";
3
+ export * from "./types";
4
+ export * from "./validators";
@@ -0,0 +1 @@
1
+ export { RegoProvider } from "./regoProvider";
@@ -0,0 +1,37 @@
1
+ import type { IRegoProvider } from "../types";
2
+
3
+ import { Enums } from "../constants";
4
+ import { routeSchema } from "../validators";
5
+
6
+ export class RegoProvider implements IRegoProvider {
7
+ constructor(private readonly document: Document) {}
8
+
9
+ getRoutes(): ReturnType<IRegoProvider["getRoutes"]> {
10
+ const scriptElement = this.document.querySelector(
11
+ `script#${Enums.EScriptIds.routesId}[type="application/json"]`
12
+ );
13
+
14
+ if (!scriptElement) {
15
+ return;
16
+ }
17
+
18
+ try {
19
+ const jsonString = scriptElement.textContent.trim();
20
+ const parsedData = JSON.parse(jsonString);
21
+
22
+ if (!Array.isArray(parsedData)) {
23
+ return;
24
+ }
25
+
26
+ return parsedData
27
+ .map((route) => {
28
+ const validation = routeSchema.safeParse(route);
29
+ return !validation.success ? null : validation.data;
30
+ })
31
+ .filter((route) => !!route);
32
+ } catch (error) {
33
+ console.error("Error on parse JSON:", error);
34
+ return;
35
+ }
36
+ }
37
+ }
@@ -0,0 +1 @@
1
+ export type * from "./regoProvider";
@@ -0,0 +1,5 @@
1
+ import type { TRoute } from "../validators";
2
+
3
+ export interface IRegoProvider {
4
+ getRoutes(): Array<TRoute> | undefined;
5
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./routes";
2
+
3
+ export type * from "./routes";
@@ -0,0 +1,10 @@
1
+ import type { output } from "zod";
2
+
3
+ import { object, string } from "zod";
4
+
5
+ export const routeSchema = object({
6
+ path: string().trim().nonempty(),
7
+ component: string().trim().nonempty()
8
+ });
9
+
10
+ export type TRoute = output<typeof routeSchema>;