@regojs/erp-sdk 1.1.1 → 1.1.2

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.
@@ -3,7 +3,7 @@ export declare class RegoProvider implements IRegoProvider {
3
3
  #private;
4
4
  private readonly window;
5
5
  constructor(window: Window);
6
- fetchRoute({ origin, search, pathname, cache }?: Parameters<IRegoProvider["fetchRoute"]>[number]): ReturnType<IRegoProvider["fetchRoute"]>;
6
+ fetchRoute({ cache, ...payload }?: Parameters<IRegoProvider["fetchRoute"]>[number]): ReturnType<IRegoProvider["fetchRoute"]>;
7
7
  get routes(): {
8
8
  path: string;
9
9
  component: string;
@@ -1,4 +1,4 @@
1
- import type { TData, TMetadata, TRoute, TStaticData } from "../validators";
1
+ import type { TData, TFullData, TMetadata, TRoute, TStaticData } from "../validators";
2
2
  export interface IRegoProvider {
3
3
  routes: Array<TRoute> | undefined;
4
4
  staticData: TStaticData;
@@ -8,6 +8,9 @@ export interface IRegoProvider {
8
8
  origin: string;
9
9
  pathname: string;
10
10
  search: string;
11
- cache: boolean;
12
- }): Promise<void>;
11
+ cache?: boolean;
12
+ } | {
13
+ url: URL;
14
+ cache?: boolean;
15
+ }): Promise<Readonly<TFullData> | undefined>;
13
16
  }
@@ -0,0 +1,7 @@
1
+ import type { output } from "zod";
2
+ export declare const fullDataSchema: import("zod").ZodObject<{
3
+ metadata: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>>>>;
4
+ data: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>>;
5
+ staticData: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodUnion<readonly [import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>, import("zod").ZodArray<import("zod").ZodUnknown>]>>>;
6
+ }, import("zod/v4/core").$strip>;
7
+ export type TFullData = output<typeof fullDataSchema>;
@@ -1,8 +1,10 @@
1
1
  export * from "./data";
2
+ export * from "./fullData";
2
3
  export * from "./metadata";
3
4
  export * from "./routes";
4
5
  export * from "./staticData";
5
6
  export type * from "./data";
7
+ export type * from "./fullData";
6
8
  export type * from "./metadata";
7
9
  export type * from "./routes";
8
10
  export type * from "./staticData";
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  },
6
6
  "dependencies": {
7
7
  "jose": "^6.2.12",
8
- "zod": "^4.6.1"
8
+ "zod": "^4.6.2"
9
9
  },
10
10
  "devDependencies": {
11
11
  "@types/bun": "^1.4.2",
@@ -44,7 +44,7 @@
44
44
  "test": "bun --hot run __test/index.ts"
45
45
  },
46
46
  "types": "./dist/index.d.ts",
47
- "version": "1.1.1",
47
+ "version": "1.1.2",
48
48
  "exports": {
49
49
  ".": {
50
50
  "import": "./dist/index.js",
@@ -1,20 +1,14 @@
1
1
  import type { IRegoProvider } from "../types";
2
2
 
3
- import { object } from "zod";
4
3
  import { Enums } from "../constants";
5
4
  import {
6
5
  dataSchema,
6
+ fullDataSchema,
7
7
  metadataSchema,
8
8
  routeSchema,
9
9
  staticDataSchema
10
10
  } from "../validators";
11
11
 
12
- const fullDataSchema = object({
13
- metadata: metadataSchema,
14
- data: dataSchema,
15
- staticData: staticDataSchema
16
- });
17
-
18
12
  export class RegoProvider implements IRegoProvider {
19
13
  #routes: IRegoProvider["routes"];
20
14
  #staticDatas: Map<string, IRegoProvider["staticData"]> = new Map();
@@ -137,10 +131,8 @@ export class RegoProvider implements IRegoProvider {
137
131
 
138
132
  async fetchRoute(
139
133
  {
140
- origin,
141
- search,
142
- pathname,
143
- cache
134
+ cache,
135
+ ...payload
144
136
  }: Parameters<IRegoProvider["fetchRoute"]>[number] = {
145
137
  pathname: this.window.location.pathname,
146
138
  search: this.window.location.search,
@@ -148,15 +140,23 @@ export class RegoProvider implements IRegoProvider {
148
140
  cache: false
149
141
  }
150
142
  ): ReturnType<IRegoProvider["fetchRoute"]> {
151
- const uri = `${pathname}${search}`;
152
-
153
- if (
154
- cache &&
155
- this.#datas.has(uri) &&
156
- this.#metadatas.has(uri) &&
157
- this.#staticDatas.has(uri)
158
- ) {
159
- return;
143
+ const uri =
144
+ "url" in payload
145
+ ? `${payload.url.pathname}${payload.url.search}`
146
+ : `${payload.pathname}${payload.search}`;
147
+
148
+ if (cache) {
149
+ const data = this.#datas.get(uri),
150
+ metadata = this.#metadatas.get(uri),
151
+ staticData = this.#staticDatas.get(uri);
152
+
153
+ if (data && metadata && staticData) {
154
+ return Object.freeze({
155
+ data,
156
+ metadata,
157
+ staticData
158
+ });
159
+ }
160
160
  }
161
161
 
162
162
  try {
@@ -184,6 +184,8 @@ export class RegoProvider implements IRegoProvider {
184
184
  this.#datas.set(uri, validation.data.data);
185
185
  this.#metadatas.set(uri, validation.data.metadata);
186
186
  this.#staticDatas.set(uri, validation.data.staticData);
187
+
188
+ return Object.freeze(validation.data);
187
189
  } catch (error) {
188
190
  console.error("Error on fetch full route data:", error);
189
191
  return;
@@ -1,4 +1,10 @@
1
- import type { TData, TMetadata, TRoute, TStaticData } from "../validators";
1
+ import type {
2
+ TData,
3
+ TFullData,
4
+ TMetadata,
5
+ TRoute,
6
+ TStaticData
7
+ } from "../validators";
2
8
 
3
9
  export interface IRegoProvider {
4
10
  routes: Array<TRoute> | undefined;
@@ -6,10 +12,17 @@ export interface IRegoProvider {
6
12
  data: TData;
7
13
  metadata: TMetadata;
8
14
 
9
- fetchRoute(payload: {
10
- origin: string;
11
- pathname: string;
12
- search: string;
13
- cache: boolean;
14
- }): Promise<void>;
15
+ fetchRoute(
16
+ payload:
17
+ | {
18
+ origin: string;
19
+ pathname: string;
20
+ search: string;
21
+ cache?: boolean;
22
+ }
23
+ | {
24
+ url: URL;
25
+ cache?: boolean;
26
+ }
27
+ ): Promise<Readonly<TFullData> | undefined>;
15
28
  }
@@ -0,0 +1,14 @@
1
+ import type { output } from "zod";
2
+
3
+ import { object } from "zod";
4
+ import { dataSchema } from "./data";
5
+ import { metadataSchema } from "./metadata";
6
+ import { staticDataSchema } from "./staticData";
7
+
8
+ export const fullDataSchema = object({
9
+ metadata: metadataSchema,
10
+ data: dataSchema,
11
+ staticData: staticDataSchema
12
+ });
13
+
14
+ export type TFullData = output<typeof fullDataSchema>;
@@ -1,9 +1,11 @@
1
1
  export * from "./data";
2
+ export * from "./fullData";
2
3
  export * from "./metadata";
3
4
  export * from "./routes";
4
5
  export * from "./staticData";
5
6
 
6
7
  export type * from "./data";
8
+ export type * from "./fullData";
7
9
  export type * from "./metadata";
8
10
  export type * from "./routes";
9
11
  export type * from "./staticData";