@cyberskill/shared 2.19.0 → 2.20.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 (58) hide show
  1. package/dist/config/eslint/index.d.ts +5 -0
  2. package/dist/config/storybook/index.cjs +1 -0
  3. package/dist/config/storybook/index.d.ts +2 -0
  4. package/dist/config/storybook/index.js +6 -0
  5. package/dist/config/storybook/storybook.main.cjs +1 -0
  6. package/dist/config/storybook/storybook.main.d.ts +17 -0
  7. package/dist/config/storybook/storybook.main.js +18 -0
  8. package/dist/config/storybook/storybook.preview.cjs +1 -0
  9. package/dist/config/storybook/storybook.preview.d.ts +18 -0
  10. package/dist/config/storybook/storybook.preview.js +39 -0
  11. package/dist/config/vitest/vitest.e2e.cjs +1 -1
  12. package/dist/config/vitest/vitest.e2e.js +1 -1
  13. package/dist/config/vitest/vitest.unit.cjs +1 -1
  14. package/dist/config/vitest/vitest.unit.js +1 -1
  15. package/dist/node/cli/index.cjs +2 -2
  16. package/dist/node/cli/index.js +51 -41
  17. package/dist/node/express/express.util.cjs +1 -1
  18. package/dist/node/express/express.util.js +21 -21
  19. package/dist/node/mongo/mongo.type.d.ts +3 -3
  20. package/dist/node/mongo/mongo.util.cjs +1 -1
  21. package/dist/node/mongo/mongo.util.d.ts +1019 -125
  22. package/dist/node/mongo/mongo.util.js +1 -1
  23. package/dist/node/path/index.cjs +1 -1
  24. package/dist/node/path/index.js +27 -25
  25. package/dist/node/path/path.constant.cjs +1 -1
  26. package/dist/node/path/path.constant.d.ts +6 -0
  27. package/dist/node/path/path.constant.js +152 -128
  28. package/dist/node/storage/index.cjs +1 -1
  29. package/dist/node/storage/index.d.ts +2 -0
  30. package/dist/node/storage/index.js +7 -2
  31. package/dist/node/storage/storage.constant.cjs +1 -0
  32. package/dist/node/storage/storage.constant.d.ts +4 -0
  33. package/dist/node/storage/storage.constant.js +7 -0
  34. package/dist/node/storage/storage.type.d.ts +14 -0
  35. package/dist/node/storage/storage.util.cjs +1 -1
  36. package/dist/node/storage/storage.util.d.ts +1 -1
  37. package/dist/node/storage/storage.util.js +160 -50
  38. package/dist/react/apollo-client/apollo-client.component.cjs +1 -1
  39. package/dist/react/apollo-client/apollo-client.component.d.ts +3 -2
  40. package/dist/react/apollo-client/apollo-client.component.js +12 -12
  41. package/dist/react/apollo-client/apollo-client.type.d.ts +6 -0
  42. package/dist/react/apollo-client/apollo-client.util.cjs +1 -1
  43. package/dist/react/apollo-client/apollo-client.util.js +32 -34
  44. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.cjs +1 -1
  45. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.d.ts +3 -2
  46. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.js +10 -10
  47. package/dist/react/apollo-error/apollo-error.provider.cjs +1 -1
  48. package/dist/react/apollo-error/apollo-error.provider.d.ts +5 -4
  49. package/dist/react/apollo-error/apollo-error.provider.js +21 -15
  50. package/dist/react/apollo-error/apollo-error.type.d.ts +5 -0
  51. package/dist/react/apollo-error/apollo-error.util.cjs +1 -1
  52. package/dist/react/apollo-error/apollo-error.util.d.ts +13 -1
  53. package/dist/react/apollo-error/apollo-error.util.js +15 -7
  54. package/dist/react/apollo-error/index.cjs +1 -1
  55. package/dist/react/apollo-error/index.js +8 -6
  56. package/package.json +45 -41
  57. /package/dist/node_modules/.pnpm/{vitest@4.0.6_@types_debug@4.1.12_@types_node@24.9.2_jiti@2.6.1_jsdom@27.1.0_sass@1.93.3_tsx@4.20.6_yaml@2.8.1 → vitest@4.0.13_@types_debug@4.1.12_@types_node@24.10.1_jiti@2.6.1_jsdom@27.2.0_sass@1.94.2_tsx@4.20.6_yaml@2.8.1}/node_modules/vitest/dist/config.cjs +0 -0
  58. /package/dist/node_modules/.pnpm/{vitest@4.0.6_@types_debug@4.1.12_@types_node@24.9.2_jiti@2.6.1_jsdom@27.1.0_sass@1.93.3_tsx@4.20.6_yaml@2.8.1 → vitest@4.0.13_@types_debug@4.1.12_@types_node@24.10.1_jiti@2.6.1_jsdom@27.2.0_sass@1.94.2_tsx@4.20.6_yaml@2.8.1}/node_modules/vitest/dist/config.js +0 -0
@@ -0,0 +1,7 @@
1
+ const E = "localforage-node-fs", o = ".json", _ = "cyberskill", s = "node-storage";
2
+ export {
3
+ E as NODE_FS_DRIVER_NAME,
4
+ _ as STORAGE_INSTANCE_NAME,
5
+ o as STORAGE_KEY_EXTENSION,
6
+ s as STORAGE_STORE_NAME
7
+ };
@@ -0,0 +1,14 @@
1
+ import { default as localForage } from 'localforage';
2
+ export type LocalForageDriver = Parameters<typeof localForage.defineDriver>[0];
3
+ export interface NodeLocalForageOptions {
4
+ driver?: string | string[];
5
+ size?: number;
6
+ version?: number;
7
+ description?: string;
8
+ name?: string;
9
+ storeName?: string;
10
+ baseDir?: string;
11
+ }
12
+ export interface NodeFsDriverState {
13
+ baseDir: string;
14
+ }
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("node-persist"),f=require("../../config/env/env.util.cjs"),u=require("../log/log.util.cjs");var l=(r,e,n)=>new Promise((h,a)=>{var d=t=>{try{c(n.next(t))}catch(s){a(s)}},v=t=>{try{c(n.throw(t))}catch(s){a(s)}},c=t=>t.done?h(t.value):Promise.resolve(t.value).then(d,v);c((n=n.apply(r,e)).next())});const y=f.getEnv();function o(){return l(this,null,function*(){i.defaultInstance||(yield i.init({dir:y.CYBERSKILL_STORAGE_DIRECTORY}))})}const E={get(r){return l(this,null,function*(){try{yield o();const e=yield i.getItem(r);return e!=null?e:null}catch(e){return u.catchError(e,{returnValue:null})}})},set(r,e){return l(this,null,function*(){try{yield o(),yield i.setItem(r,e)}catch(n){u.catchError(n)}})},remove(r){return l(this,null,function*(){try{yield o(),yield i.removeItem(r)}catch(e){u.catchError(e)}})},keys(){return l(this,null,function*(){try{yield o();const r=yield i.keys();return Array.isArray(r)?r:(u.log.warn("[Storage:keys] Invalid keys response:",r),[])}catch(r){return u.catchError(r,{returnValue:[]})}})},getLogLink(r){return l(this,null,function*(){try{return`${y.CYBERSKILL_STORAGE_DIRECTORY} (key: ${r})`}catch(e){return u.catchError(e,{returnValue:null})}})}};exports.storage=E;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("localforage"),o=require("node:fs/promises"),D=require("node:path"),c=require("./storage.constant.cjs"),I=require("../../config/env/env.util.cjs"),s=require("../log/log.util.cjs");var n=(e,r,t)=>new Promise((i,y)=>{var h=u=>{try{v(t.next(u))}catch(_){y(_)}},O=u=>{try{v(t.throw(u))}catch(_){y(_)}},v=u=>u.done?i(u.value):Promise.resolve(u.value).then(h,O);v((t=t.apply(e,r)).next())});const E=I.getEnv(),l={baseDir:E.CYBERSKILL_STORAGE_DIRECTORY};function m(e){return`${encodeURIComponent(e)}${c.STORAGE_KEY_EXTENSION}`}function N(e){return decodeURIComponent(e.slice(0,-c.STORAGE_KEY_EXTENSION.length))}function R(e,r){return D.join(r,m(e))}const d={_driver:c.NODE_FS_DRIVER_NAME,_support:!0,_initStorage(e){return n(this,null,function*(){try{const r=typeof e=="object"&&e!==null&&"baseDir"in e?e.baseDir:void 0;typeof r=="string"&&r.length>0?l.baseDir=r:l.baseDir=E.CYBERSKILL_STORAGE_DIRECTORY,yield o.mkdir(l.baseDir,{recursive:!0})}catch(r){throw s.log.error("[Storage:init]",r),r}})},clear(){return n(this,null,function*(){const{baseDir:e}=l;yield o.rm(e,{recursive:!0,force:!0}),yield o.mkdir(e,{recursive:!0})})},getItem(e){return n(this,null,function*(){const{baseDir:r}=l,t=R(e,r);try{const i=yield o.readFile(t,"utf8");return JSON.parse(i)}catch(i){if(i.code==="ENOENT")return null;throw i}})},iterate(e){return n(this,null,function*(){const r=yield d.keys();let t=1;for(const i of r){const y=yield d.getItem(i),h=e(y,i,t);if(h!==void 0)return h;t+=1}})},key(e){return n(this,null,function*(){var r;return(r=(yield d.keys())[e])!=null?r:null})},keys(){return n(this,null,function*(){const{baseDir:e}=l;try{return(yield o.readdir(e)).filter(t=>t.endsWith(c.STORAGE_KEY_EXTENSION)).map(N)}catch(r){if(r.code==="ENOENT")return[];throw r}})},length(){return n(this,null,function*(){return(yield d.keys()).length})},removeItem(e){return n(this,null,function*(){const{baseDir:r}=l,t=R(e,r);yield o.rm(t,{force:!0})})},setItem(e,r){return n(this,null,function*(){const{baseDir:t}=l,i=R(e,t);return yield o.mkdir(t,{recursive:!0}),yield o.writeFile(i,JSON.stringify(r),"utf8"),r})}};let a=null,S=null;function f(){return n(this,null,function*(){return a?(yield a,S):(a=n(null,null,function*(){yield g.defineDriver(d),l.baseDir=E.CYBERSKILL_STORAGE_DIRECTORY;const e=yield g.getDriver(c.NODE_FS_DRIVER_NAME),r={baseDir:l.baseDir,name:c.STORAGE_INSTANCE_NAME,storeName:c.STORAGE_STORE_NAME};yield e._initStorage(r),S=e}).catch(e=>{throw a=null,e}),yield a,S)})}const T={get(e){return n(this,null,function*(){try{const t=yield(yield f()).getItem(e);return t!=null?t:null}catch(r){return s.catchError(r,{returnValue:null})}})},set(e,r){return n(this,null,function*(){try{yield(yield f()).setItem(e,r)}catch(t){s.catchError(t)}})},remove(e){return n(this,null,function*(){try{yield(yield f()).removeItem(e)}catch(r){s.catchError(r)}})},keys(){return n(this,null,function*(){try{const r=yield(yield f()).keys();return Array.isArray(r)?r:(s.log.warn("[Storage:keys] Invalid keys response:",r),[])}catch(e){return s.catchError(e,{returnValue:[]})}})},getLogLink(e){return n(this,null,function*(){try{return`${D.join(E.CYBERSKILL_STORAGE_DIRECTORY,m(e))} (key: ${e})`}catch(r){return s.catchError(r,{returnValue:null})}})}};exports.storage=T;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Persistent storage utility object for data persistence across application sessions.
3
- * This object provides methods for storing, retrieving, and managing data using node-persist,
3
+ * This object provides methods for storing, retrieving, and managing data using localForage,
4
4
  * with automatic initialization and error handling.
5
5
  */
6
6
  export declare const storage: {
@@ -1,31 +1,143 @@
1
- import u from "node-persist";
2
- import { getEnv as m } from "../../config/env/env.util.js";
3
- import { catchError as i, log as v } from "../log/log.util.js";
4
- var l = (r, e, n) => new Promise((h, a) => {
5
- var d = (t) => {
1
+ import _ from "localforage";
2
+ import l from "node:fs/promises";
3
+ import g from "node:path";
4
+ import { STORAGE_KEY_EXTENSION as R, NODE_FS_DRIVER_NAME as I, STORAGE_STORE_NAME as p, STORAGE_INSTANCE_NAME as b } from "./storage.constant.js";
5
+ import { getEnv as N } from "../../config/env/env.util.js";
6
+ import { catchError as s, log as S } from "../log/log.util.js";
7
+ var n = (e, r, t) => new Promise((i, d) => {
8
+ var y = (u) => {
6
9
  try {
7
- s(n.next(t));
8
- } catch (c) {
9
- a(c);
10
+ m(t.next(u));
11
+ } catch (v) {
12
+ d(v);
10
13
  }
11
- }, f = (t) => {
14
+ }, O = (u) => {
12
15
  try {
13
- s(n.throw(t));
14
- } catch (c) {
15
- a(c);
16
+ m(t.throw(u));
17
+ } catch (v) {
18
+ d(v);
16
19
  }
17
- }, s = (t) => t.done ? h(t.value) : Promise.resolve(t.value).then(d, f);
18
- s((n = n.apply(r, e)).next());
20
+ }, m = (u) => u.done ? i(u.value) : Promise.resolve(u.value).then(y, O);
21
+ m((t = t.apply(e, r)).next());
19
22
  });
20
- const y = m();
21
- function o() {
22
- return l(this, null, function* () {
23
- u.defaultInstance || (yield u.init({
24
- dir: y.CYBERSKILL_STORAGE_DIRECTORY
25
- }));
23
+ const h = N(), o = {
24
+ baseDir: h.CYBERSKILL_STORAGE_DIRECTORY
25
+ };
26
+ function k(e) {
27
+ return `${encodeURIComponent(e)}${R}`;
28
+ }
29
+ function T(e) {
30
+ return decodeURIComponent(e.slice(0, -R.length));
31
+ }
32
+ function E(e, r) {
33
+ return g.join(r, k(e));
34
+ }
35
+ const a = {
36
+ _driver: I,
37
+ _support: !0,
38
+ /** Ensures the storage directory exists and respects custom baseDir overrides. */
39
+ _initStorage(e) {
40
+ return n(this, null, function* () {
41
+ try {
42
+ const r = typeof e == "object" && e !== null && "baseDir" in e ? e.baseDir : void 0;
43
+ typeof r == "string" && r.length > 0 ? o.baseDir = r : o.baseDir = h.CYBERSKILL_STORAGE_DIRECTORY, yield l.mkdir(o.baseDir, { recursive: !0 });
44
+ } catch (r) {
45
+ throw S.error("[Storage:init]", r), r;
46
+ }
47
+ });
48
+ },
49
+ /** Deletes all stored entries by recreating the directory. */
50
+ clear() {
51
+ return n(this, null, function* () {
52
+ const { baseDir: e } = o;
53
+ yield l.rm(e, { recursive: !0, force: !0 }), yield l.mkdir(e, { recursive: !0 });
54
+ });
55
+ },
56
+ /** Reads and parses a stored value; returns null when the file is missing. */
57
+ getItem(e) {
58
+ return n(this, null, function* () {
59
+ const { baseDir: r } = o, t = E(e, r);
60
+ try {
61
+ const i = yield l.readFile(t, "utf8");
62
+ return JSON.parse(i);
63
+ } catch (i) {
64
+ if (i.code === "ENOENT")
65
+ return null;
66
+ throw i;
67
+ }
68
+ });
69
+ },
70
+ /** Iterates through all keys, invoking the iterator until it returns a value. */
71
+ iterate(e) {
72
+ return n(this, null, function* () {
73
+ const r = yield a.keys();
74
+ let t = 1;
75
+ for (const i of r) {
76
+ const d = yield a.getItem(i), y = e(d, i, t);
77
+ if (y !== void 0)
78
+ return y;
79
+ t += 1;
80
+ }
81
+ });
82
+ },
83
+ /** Returns the key name at the given index or null when out of bounds. */
84
+ key(e) {
85
+ return n(this, null, function* () {
86
+ var r;
87
+ return (r = (yield a.keys())[e]) != null ? r : null;
88
+ });
89
+ },
90
+ /** Lists all stored keys. */
91
+ keys() {
92
+ return n(this, null, function* () {
93
+ const { baseDir: e } = o;
94
+ try {
95
+ return (yield l.readdir(e)).filter((t) => t.endsWith(R)).map(T);
96
+ } catch (r) {
97
+ if (r.code === "ENOENT")
98
+ return [];
99
+ throw r;
100
+ }
101
+ });
102
+ },
103
+ /** Returns the count of stored keys. */
104
+ length() {
105
+ return n(this, null, function* () {
106
+ return (yield a.keys()).length;
107
+ });
108
+ },
109
+ /** Removes a stored value for the given key. */
110
+ removeItem(e) {
111
+ return n(this, null, function* () {
112
+ const { baseDir: r } = o, t = E(e, r);
113
+ yield l.rm(t, { force: !0 });
114
+ });
115
+ },
116
+ /** Stores a value as JSON on disk. */
117
+ setItem(e, r) {
118
+ return n(this, null, function* () {
119
+ const { baseDir: t } = o, i = E(e, t);
120
+ return yield l.mkdir(t, { recursive: !0 }), yield l.writeFile(i, JSON.stringify(r), "utf8"), r;
121
+ });
122
+ }
123
+ };
124
+ let c = null, D = null;
125
+ function f() {
126
+ return n(this, null, function* () {
127
+ return c ? (yield c, D) : (c = n(null, null, function* () {
128
+ yield _.defineDriver(a), o.baseDir = h.CYBERSKILL_STORAGE_DIRECTORY;
129
+ const e = yield _.getDriver(I), r = {
130
+ baseDir: o.baseDir,
131
+ name: b,
132
+ storeName: p
133
+ };
134
+ yield e._initStorage(r), D = e;
135
+ }).catch((e) => {
136
+ throw c = null, e;
137
+ }), yield c, D);
26
138
  });
27
139
  }
28
- const R = {
140
+ const w = {
29
141
  /**
30
142
  * Retrieves a value from persistent storage by key.
31
143
  * This method fetches data that was previously stored using the set method.
@@ -34,14 +146,13 @@ const R = {
34
146
  * @param key - The unique identifier for the stored value.
35
147
  * @returns A promise that resolves to the stored value or null if not found.
36
148
  */
37
- get(r) {
38
- return l(this, null, function* () {
149
+ get(e) {
150
+ return n(this, null, function* () {
39
151
  try {
40
- yield o();
41
- const e = yield u.getItem(r);
42
- return e != null ? e : null;
43
- } catch (e) {
44
- return i(e, { returnValue: null });
152
+ const t = yield (yield f()).getItem(e);
153
+ return t != null ? t : null;
154
+ } catch (r) {
155
+ return s(r, { returnValue: null });
45
156
  }
46
157
  });
47
158
  },
@@ -54,12 +165,12 @@ const R = {
54
165
  * @param value - The data to store (will be automatically serialized).
55
166
  * @returns A promise that resolves when the storage operation is complete.
56
167
  */
57
- set(r, e) {
58
- return l(this, null, function* () {
168
+ set(e, r) {
169
+ return n(this, null, function* () {
59
170
  try {
60
- yield o(), yield u.setItem(r, e);
61
- } catch (n) {
62
- i(n);
171
+ yield (yield f()).setItem(e, r);
172
+ } catch (t) {
173
+ s(t);
63
174
  }
64
175
  });
65
176
  },
@@ -70,12 +181,12 @@ const R = {
70
181
  * @param key - The unique identifier of the value to remove.
71
182
  * @returns A promise that resolves when the removal operation is complete.
72
183
  */
73
- remove(r) {
74
- return l(this, null, function* () {
184
+ remove(e) {
185
+ return n(this, null, function* () {
75
186
  try {
76
- yield o(), yield u.removeItem(r);
77
- } catch (e) {
78
- i(e);
187
+ yield (yield f()).removeItem(e);
188
+ } catch (r) {
189
+ s(r);
79
190
  }
80
191
  });
81
192
  },
@@ -87,13 +198,12 @@ const R = {
87
198
  * @returns A promise that resolves to an array of storage keys.
88
199
  */
89
200
  keys() {
90
- return l(this, null, function* () {
201
+ return n(this, null, function* () {
91
202
  try {
92
- yield o();
93
- const r = yield u.keys();
94
- return Array.isArray(r) ? r : (v.warn("[Storage:keys] Invalid keys response:", r), []);
95
- } catch (r) {
96
- return i(r, { returnValue: [] });
203
+ const r = yield (yield f()).keys();
204
+ return Array.isArray(r) ? r : (S.warn("[Storage:keys] Invalid keys response:", r), []);
205
+ } catch (e) {
206
+ return s(e, { returnValue: [] });
97
207
  }
98
208
  });
99
209
  },
@@ -105,16 +215,16 @@ const R = {
105
215
  * @param key - The storage key to generate a log link for.
106
216
  * @returns A promise that resolves to a formatted log link string or null if an error occurs.
107
217
  */
108
- getLogLink(r) {
109
- return l(this, null, function* () {
218
+ getLogLink(e) {
219
+ return n(this, null, function* () {
110
220
  try {
111
- return `${y.CYBERSKILL_STORAGE_DIRECTORY} (key: ${r})`;
112
- } catch (e) {
113
- return i(e, { returnValue: null });
221
+ return `${g.join(h.CYBERSKILL_STORAGE_DIRECTORY, k(e))} (key: ${e})`;
222
+ } catch (r) {
223
+ return s(r, { returnValue: null });
114
224
  }
115
225
  });
116
226
  }
117
227
  };
118
228
  export {
119
- R as storage
229
+ w as storage
120
230
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@apollo/client/react"),e=require("react"),n=require("./apollo-client.context.cjs"),i=require("./apollo-client.util.cjs"),a=require("../apollo-error/apollo-error.provider.cjs"),u=require("../apollo-error/apollo-error.component.cjs"),c=require("react-hot-toast");function p({options:r,children:l}){const o=e.useMemo(()=>i.getClient(r!=null?r:{}),[r]);return e.createElement(e.Fragment,null,e.createElement(a.ApolloErrorProvider,null,e.createElement(n.ApolloClientProvider,{client:o},e.createElement(t.ApolloProvider,{client:o},l)),e.createElement(u.ApolloErrorComponent,null)),e.createElement(c.Toaster,{position:"top-right"}))}exports.ApolloProvider=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@apollo/client/react"),e=require("react"),i=require("./apollo-client.context.cjs"),a=require("./apollo-client.util.cjs"),c=require("../apollo-error/apollo-error.provider.cjs"),u=require("../apollo-error/apollo-error.component.cjs"),p=require("react-hot-toast");function m({options:r,children:t,onError:o}){const l=e.useMemo(()=>a.getClient(r!=null?r:{}),[r]);return e.createElement(e.Fragment,null,e.createElement(c.ApolloErrorProvider,{onError:o},e.createElement(i.ApolloClientProvider,{client:l},e.createElement(n.ApolloProvider,{client:l},t)),!o&&e.createElement(u.ApolloErrorComponent,null)),e.createElement(p.Toaster,{position:"top-right"}))}exports.ApolloProvider=m;
@@ -13,9 +13,10 @@ import { I_ApolloProviderProps } from './apollo-client.type.js';
13
13
  * - Automatic error handling
14
14
  * - Development and production optimizations
15
15
  *
16
- * @param props - Component props containing options and children.
16
+ * @param props - Component props containing options, children, and optional error override.
17
17
  * @param props.options - Apollo Client configuration options.
18
18
  * @param props.children - React children that will have access to Apollo Client context.
19
+ * @param props.onError - Optional callback to override the default modal/toast error handling.
19
20
  * @returns A React component that provides Apollo Client context to its children.
20
21
  */
21
- export declare function ApolloProvider({ options, children }: I_ApolloProviderProps): React.JSX.Element;
22
+ export declare function ApolloProvider({ options, children, onError }: I_ApolloProviderProps): React.JSX.Element;
@@ -1,17 +1,17 @@
1
- import { ApolloProvider as l } from "@apollo/client/react";
2
- import r, { useMemo as m } from "react";
1
+ import { ApolloProvider as m } from "@apollo/client/react";
2
+ import e, { useMemo as i } from "react";
3
3
  import { ApolloClientProvider as n } from "./apollo-client.context.js";
4
- import { getClient as i } from "./apollo-client.util.js";
5
- import { ApolloErrorProvider as p } from "../apollo-error/apollo-error.provider.js";
6
- import { ApolloErrorComponent as a } from "../apollo-error/apollo-error.component.js";
7
- import { Toaster as c } from "react-hot-toast";
8
- function g({ options: e, children: t }) {
9
- const o = m(
10
- () => i(e != null ? e : {}),
11
- [e]
4
+ import { getClient as p } from "./apollo-client.util.js";
5
+ import { ApolloErrorProvider as a } from "../apollo-error/apollo-error.provider.js";
6
+ import { ApolloErrorComponent as c } from "../apollo-error/apollo-error.component.js";
7
+ import { Toaster as f } from "react-hot-toast";
8
+ function s({ options: r, children: l, onError: o }) {
9
+ const t = i(
10
+ () => p(r != null ? r : {}),
11
+ [r]
12
12
  );
13
- return /* @__PURE__ */ r.createElement(r.Fragment, null, /* @__PURE__ */ r.createElement(p, null, /* @__PURE__ */ r.createElement(n, { client: o }, /* @__PURE__ */ r.createElement(l, { client: o }, t)), /* @__PURE__ */ r.createElement(a, null)), /* @__PURE__ */ r.createElement(c, { position: "top-right" }));
13
+ return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(a, { onError: o }, /* @__PURE__ */ e.createElement(n, { client: t }, /* @__PURE__ */ e.createElement(m, { client: t }, l)), !o && /* @__PURE__ */ e.createElement(c, null)), /* @__PURE__ */ e.createElement(f, { position: "top-right" }));
14
14
  }
15
15
  export {
16
- g as ApolloProvider
16
+ s as ApolloProvider
17
17
  };
@@ -1,5 +1,6 @@
1
1
  import { ApolloClient } from '@apollo/client';
2
2
  import { ApolloLink } from '@apollo/client/link';
3
+ import { GraphQLError } from 'graphql';
3
4
  import { I_Children } from '../../typescript/index.js';
4
5
  export interface I_ApolloOptions extends Omit<ApolloClient.Options, 'link' | 'cache'> {
5
6
  uri?: string;
@@ -9,5 +10,10 @@ export interface I_ApolloOptions extends Omit<ApolloClient.Options, 'link' | 'ca
9
10
  export interface I_ApolloProviderProps extends I_Children {
10
11
  isNextJS?: boolean;
11
12
  options?: I_ApolloOptions;
13
+ /**
14
+ * Optional callback to override the default Apollo error modal/toast handling.
15
+ * When provided, the consumer is responsible for surfacing GraphQL errors.
16
+ */
17
+ onError?: (error: GraphQLError | Error) => void;
12
18
  }
13
19
  export type { ApolloCache, ApolloClient, ErrorLike } from '@apollo/client';
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@apollo/client/core"),p=require("@apollo/client/link"),_=require("@apollo/client/link/error"),y=require("@apollo/client/link/remove-typename"),q=require("@apollo/client/link/subscriptions"),h=require("graphql"),v=require("graphql-ws"),c=require("react"),E=require("rxjs"),m=require("./apollo-client.constant.cjs"),f=require("./apollo-client.module.scss.cjs"),b=require("./links/upload.cjs"),P=require("../apollo-error/apollo-error.util.cjs"),l=require("../log/log.util.cjs"),d=require("react-hot-toast");var A=Object.defineProperty,L=Object.getOwnPropertySymbols,C=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,g=(e,r,o)=>r in e?A(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,T=(e,r)=>{for(var o in r||(r={}))C.call(r,o)&&g(e,o,r[o]);if(L)for(var o of L(r))O.call(r,o)&&g(e,o,r[o]);return e};const N=new p.ApolloLink((e,r)=>(e.setContext({start:new Date}),r(e).pipe(E.tap(()=>{const o=new Date().getTime()-e.getContext().start;l.log.info(`Operation ${e.operationName} took ${o}ms to complete`)})))),$=new _.ErrorLink(({error:e,operation:r})=>{const o=(r==null?void 0:r.operationName)||"Unknown";let t="";a.CombinedGraphQLErrors.is(e)?e.errors.forEach(({message:n,locations:i,path:s},u)=>{u===0&&(t=n),l.log.error(`[GraphQL error] ${o}: ${n}, Location: ${JSON.stringify(i,null,4)}, Path: ${s}`)}):a.CombinedProtocolErrors.is(e)?e.errors.forEach(({message:n,extensions:i},s)=>{s===0&&(t=n),l.log.error(`[Protocol error]: ${n}, Extensions: ${JSON.stringify(i,null,4)}`)}):a.ServerError.is(e)?(t=e.message,l.log.error(`[Server error]: ${e.message}`)):(t=e.message,l.log.error(`[Network error]: ${e.message}`)),e&&t&&typeof window!="undefined"&&d.toast.error(n=>c.createElement("div",{className:f.default["error-container"]},t,c.createElement("button",{type:"button",className:f.default["error-details-button"],onClick:()=>{setTimeout(()=>{P.showGlobalApolloError(e)},0),d.toast.dismiss(n.id)}},"Error Details")))});function k(e){const{uri:r,wsUrl:o,customLinks:t}=e,n=new y.RemoveTypenameFromVariablesLink;r||l.log.warn(`[Apollo] No GraphQL URI provided — using "${m.GRAPHQL_URI_DEFAULT}" as default`);const i=b.createUploadLink({uri:r!=null?r:m.GRAPHQL_URI_DEFAULT,credentials:"include",headers:{"apollo-require-preflight":"true"}}),s=o?new q.GraphQLWsLink(v.createClient({url:o})):p.ApolloLink.empty(),u=o?p.ApolloLink.split(({operationType:w})=>w===h.OperationTypeNode.SUBSCRIPTION,s,i):i;return o&&u===i&&l.log.warn("[Apollo] WS URL is set, but subscriptions fallback to HTTP. Check your wsLink config."),[N,$,n,...t!=null?t:[],u]}function S(e){const r=p.ApolloLink.from(k(e));return new a.ApolloClient(T({link:r,cache:new a.InMemoryCache},e))}exports.createApolloLinks=k;exports.getClient=S;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@apollo/client/core"),p=require("@apollo/client/link"),h=require("@apollo/client/link/error"),y=require("@apollo/client/link/remove-typename"),q=require("@apollo/client/link/subscriptions"),E=require("graphql"),b=require("graphql-ws"),f=require("react"),v=require("rxjs"),m=require("./apollo-client.constant.cjs"),d=require("./apollo-client.module.scss.cjs"),A=require("./links/upload.cjs"),c=require("../apollo-error/apollo-error.util.cjs"),i=require("../log/log.util.cjs"),L=require("react-hot-toast");var C=Object.defineProperty,g=Object.getOwnPropertySymbols,P=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,k=(e,r,o)=>r in e?C(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,T=(e,r)=>{for(var o in r||(r={}))P.call(r,o)&&k(e,o,r[o]);if(g)for(var o of g(r))O.call(r,o)&&k(e,o,r[o]);return e};const N=new p.ApolloLink((e,r)=>(e.setContext({start:new Date}),r(e).pipe(v.tap(()=>{const o=new Date().getTime()-e.getContext().start;i.log.info(`Operation ${e.operationName} took ${o}ms to complete`)})))),$=new h.ErrorLink(({error:e,operation:r})=>{const o=(r==null?void 0:r.operationName)||"Unknown";let t="";a.CombinedGraphQLErrors.is(e)?e.errors.forEach(({message:l,locations:n,path:s},u)=>{u===0&&(t=l),i.log.error(`[GraphQL error] ${o}: ${l}, Location: ${JSON.stringify(n,null,4)}, Path: ${s}`)}):a.CombinedProtocolErrors.is(e)?e.errors.forEach(({message:l,extensions:n},s)=>{s===0&&(t=l),i.log.error(`[Protocol error]: ${l}, Extensions: ${JSON.stringify(n,null,4)}`)}):a.ServerError.is(e)?(t=e.message,i.log.error(`[Server error]: ${e.message}`)):(t=e.message,i.log.error(`[Network error]: ${e.message}`)),e&&t&&typeof window!="undefined"&&(c.hasCustomApolloErrorHandler()?c.showGlobalApolloError(e):L.toast.error(l=>f.createElement("div",{className:d.default["error-container"]},t,f.createElement("button",{type:"button",className:d.default["error-details-button"],onClick:()=>{c.showGlobalApolloError(e),L.toast.dismiss(l.id)}},"Error Details"))))});function w(e){const{uri:r,wsUrl:o,customLinks:t}=e,l=new y.RemoveTypenameFromVariablesLink;r||i.log.warn(`[Apollo] No GraphQL URI provided — using "${m.GRAPHQL_URI_DEFAULT}" as default`);const n=A.createUploadLink({uri:r!=null?r:m.GRAPHQL_URI_DEFAULT,credentials:"include",headers:{"apollo-require-preflight":"true"}}),s=o?new q.GraphQLWsLink(b.createClient({url:o})):p.ApolloLink.empty(),u=o?p.ApolloLink.split(({operationType:_})=>_===E.OperationTypeNode.SUBSCRIPTION,s,n):n;return o&&u===n&&i.log.warn("[Apollo] WS URL is set, but subscriptions fallback to HTTP. Check your wsLink config."),[N,$,l,...t!=null?t:[],u]}function S(e){const r=p.ApolloLink.from(w(e));return new a.ApolloClient(T({link:r,cache:new a.InMemoryCache},e))}exports.createApolloLinks=w;exports.getClient=S;
@@ -1,86 +1,84 @@
1
- import { ApolloClient as k, InMemoryCache as y, CombinedGraphQLErrors as g, CombinedProtocolErrors as h, ServerError as v } from "@apollo/client/core";
1
+ import { ApolloClient as y, InMemoryCache as h, CombinedGraphQLErrors as g, CombinedProtocolErrors as E, ServerError as v } from "@apollo/client/core";
2
2
  import { ApolloLink as m } from "@apollo/client/link";
3
- import { ErrorLink as E } from "@apollo/client/link/error";
4
- import { RemoveTypenameFromVariablesLink as _ } from "@apollo/client/link/remove-typename";
5
- import { GraphQLWsLink as O } from "@apollo/client/link/subscriptions";
6
- import { OperationTypeNode as P } from "graphql";
7
- import { createClient as b } from "graphql-ws";
3
+ import { ErrorLink as _ } from "@apollo/client/link/error";
4
+ import { RemoveTypenameFromVariablesLink as O } from "@apollo/client/link/remove-typename";
5
+ import { GraphQLWsLink as P } from "@apollo/client/link/subscriptions";
6
+ import { OperationTypeNode as b } from "graphql";
7
+ import { createClient as C } from "graphql-ws";
8
8
  import p from "react";
9
9
  import { tap as N } from "rxjs";
10
10
  import { GRAPHQL_URI_DEFAULT as f } from "./apollo-client.constant.js";
11
11
  import c from "./apollo-client.module.scss.js";
12
- import { createUploadLink as C } from "./links/upload.js";
13
- import { showGlobalApolloError as $ } from "../apollo-error/apollo-error.util.js";
12
+ import { createUploadLink as $ } from "./links/upload.js";
13
+ import { hasCustomApolloErrorHandler as A, showGlobalApolloError as u } from "../apollo-error/apollo-error.util.js";
14
14
  import { log as s } from "../log/log.util.js";
15
- import { toast as u } from "react-hot-toast";
16
- var T = Object.defineProperty, d = Object.getOwnPropertySymbols, S = Object.prototype.hasOwnProperty, A = Object.prototype.propertyIsEnumerable, w = (r, e, o) => e in r ? T(r, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : r[e] = o, U = (r, e) => {
15
+ import { toast as d } from "react-hot-toast";
16
+ var S = Object.defineProperty, w = Object.getOwnPropertySymbols, T = Object.prototype.hasOwnProperty, U = Object.prototype.propertyIsEnumerable, L = (r, e, o) => e in r ? S(r, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : r[e] = o, I = (r, e) => {
17
17
  for (var o in e || (e = {}))
18
- S.call(e, o) && w(r, o, e[o]);
19
- if (d)
20
- for (var o of d(e))
21
- A.call(e, o) && w(r, o, e[o]);
18
+ T.call(e, o) && L(r, o, e[o]);
19
+ if (w)
20
+ for (var o of w(e))
21
+ U.call(e, o) && L(r, o, e[o]);
22
22
  return r;
23
23
  };
24
- const I = new m((r, e) => (r.setContext({ start: /* @__PURE__ */ new Date() }), e(r).pipe(
24
+ const R = new m((r, e) => (r.setContext({ start: /* @__PURE__ */ new Date() }), e(r).pipe(
25
25
  N(() => {
26
26
  const o = (/* @__PURE__ */ new Date()).getTime() - r.getContext().start;
27
27
  s.info(`Operation ${r.operationName} took ${o}ms to complete`);
28
28
  })
29
- ))), R = new E(({ error: r, operation: e }) => {
29
+ ))), G = new _(({ error: r, operation: e }) => {
30
30
  const o = (e == null ? void 0 : e.operationName) || "Unknown";
31
31
  let t = "";
32
32
  g.is(r) ? r.errors.forEach(({ message: n, locations: i, path: l }, a) => {
33
33
  a === 0 && (t = n), s.error(
34
34
  `[GraphQL error] ${o}: ${n}, Location: ${JSON.stringify(i, null, 4)}, Path: ${l}`
35
35
  );
36
- }) : h.is(r) ? r.errors.forEach(({ message: n, extensions: i }, l) => {
36
+ }) : E.is(r) ? r.errors.forEach(({ message: n, extensions: i }, l) => {
37
37
  l === 0 && (t = n), s.error(
38
38
  `[Protocol error]: ${n}, Extensions: ${JSON.stringify(i, null, 4)}`
39
39
  );
40
- }) : v.is(r) ? (t = r.message, s.error(`[Server error]: ${r.message}`)) : (t = r.message, s.error(`[Network error]: ${r.message}`)), r && t && typeof window != "undefined" && u.error((n) => /* @__PURE__ */ p.createElement("div", { className: c["error-container"] }, t, /* @__PURE__ */ p.createElement(
40
+ }) : v.is(r) ? (t = r.message, s.error(`[Server error]: ${r.message}`)) : (t = r.message, s.error(`[Network error]: ${r.message}`)), r && t && typeof window != "undefined" && (A() ? u(r) : d.error((n) => /* @__PURE__ */ p.createElement("div", { className: c["error-container"] }, t, /* @__PURE__ */ p.createElement(
41
41
  "button",
42
42
  {
43
43
  type: "button",
44
44
  className: c["error-details-button"],
45
45
  onClick: () => {
46
- setTimeout(() => {
47
- $(r);
48
- }, 0), u.dismiss(n.id);
46
+ u(r), d.dismiss(n.id);
49
47
  }
50
48
  },
51
49
  "Error Details"
52
- )));
50
+ ))));
53
51
  });
54
- function G(r) {
55
- const { uri: e, wsUrl: o, customLinks: t } = r, n = new _();
52
+ function Q(r) {
53
+ const { uri: e, wsUrl: o, customLinks: t } = r, n = new O();
56
54
  e || s.warn(`[Apollo] No GraphQL URI provided — using "${f}" as default`);
57
- const i = C({
55
+ const i = $({
58
56
  uri: e != null ? e : f,
59
57
  credentials: "include",
60
58
  headers: {
61
59
  "apollo-require-preflight": "true"
62
60
  }
63
- }), l = o ? new O(b({ url: o })) : m.empty(), a = o ? m.split(
64
- ({ operationType: L }) => L === P.SUBSCRIPTION,
61
+ }), l = o ? new P(C({ url: o })) : m.empty(), a = o ? m.split(
62
+ ({ operationType: k }) => k === b.SUBSCRIPTION,
65
63
  l,
66
64
  i
67
65
  ) : i;
68
66
  return o && a === i && s.warn("[Apollo] WS URL is set, but subscriptions fallback to HTTP. Check your wsLink config."), [
69
- I,
70
67
  R,
68
+ G,
71
69
  n,
72
70
  ...t != null ? t : [],
73
71
  a
74
72
  ];
75
73
  }
76
- function Y(r) {
77
- const e = m.from(G(r));
78
- return new k(U({
74
+ function Z(r) {
75
+ const e = m.from(Q(r));
76
+ return new y(I({
79
77
  link: e,
80
- cache: new y()
78
+ cache: new h()
81
79
  }, r));
82
80
  }
83
81
  export {
84
- G as createApolloLinks,
85
- Y as getClient
82
+ Q as createApolloLinks,
83
+ Z as getClient
86
84
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@apollo/client-integration-nextjs"),e=require("react"),n=require("./apollo-client-nextjs.util.cjs"),i=require("../apollo-error/apollo-error.provider.cjs"),a=require("../apollo-error/apollo-error.component.cjs"),u=require("react-hot-toast");function p({options:r,children:o}){const t=e.useMemo(()=>()=>n.getClient(r||{}),[r]);return e.createElement(e.Fragment,null,e.createElement(i.ApolloErrorProvider,null,e.createElement(l.ApolloNextAppProvider,{makeClient:t},o),e.createElement(a.ApolloErrorComponent,null)),e.createElement(u.Toaster,{position:"top-right"}))}exports.ApolloProvider=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@apollo/client-integration-nextjs"),e=require("react"),i=require("./apollo-client-nextjs.util.cjs"),a=require("../apollo-error/apollo-error.provider.cjs"),p=require("../apollo-error/apollo-error.component.cjs"),u=require("react-hot-toast");function c({options:r,children:o,onError:t}){const l=e.useMemo(()=>()=>i.getClient(r||{}),[r]);return e.createElement(e.Fragment,null,e.createElement(a.ApolloErrorProvider,{onError:t},e.createElement(n.ApolloNextAppProvider,{makeClient:l},o),!t&&e.createElement(p.ApolloErrorComponent,null)),e.createElement(u.Toaster,{position:"top-right"}))}exports.ApolloProvider=c;
@@ -13,9 +13,10 @@ import { I_ApolloProviderProps } from '../apollo-client/index.js';
13
13
  * - Automatic error handling
14
14
  * - Next.js specific optimizations
15
15
  *
16
- * @param props - Component props containing options and children.
16
+ * @param props - Component props containing options, children, and optional error override.
17
17
  * @param props.options - Apollo Client configuration options.
18
18
  * @param props.children - React children that will have access to Apollo Client context.
19
+ * @param props.onError - Optional callback to override the default modal/toast error handling.
19
20
  * @returns A React component that provides Apollo Client context to its children.
20
21
  */
21
- export declare function ApolloProvider({ options, children }: I_ApolloProviderProps): React.JSX.Element;
22
+ export declare function ApolloProvider({ options, children, onError }: I_ApolloProviderProps): React.JSX.Element;
@@ -1,16 +1,16 @@
1
1
  import { ApolloNextAppProvider as l } from "@apollo/client-integration-nextjs";
2
- import e, { useMemo as m } from "react";
3
- import { getClient as n } from "./apollo-client-nextjs.util.js";
4
- import { ApolloErrorProvider as p } from "../apollo-error/apollo-error.provider.js";
5
- import { ApolloErrorComponent as i } from "../apollo-error/apollo-error.component.js";
6
- import { Toaster as a } from "react-hot-toast";
7
- function g({ options: r, children: o }) {
8
- const t = m(
9
- () => () => n(r || {}),
2
+ import e, { useMemo as n } from "react";
3
+ import { getClient as p } from "./apollo-client-nextjs.util.js";
4
+ import { ApolloErrorProvider as i } from "../apollo-error/apollo-error.provider.js";
5
+ import { ApolloErrorComponent as a } from "../apollo-error/apollo-error.component.js";
6
+ import { Toaster as c } from "react-hot-toast";
7
+ function s({ options: r, children: t, onError: o }) {
8
+ const m = n(
9
+ () => () => p(r || {}),
10
10
  [r]
11
11
  );
12
- return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(p, null, /* @__PURE__ */ e.createElement(l, { makeClient: t }, o), /* @__PURE__ */ e.createElement(i, null)), /* @__PURE__ */ e.createElement(a, { position: "top-right" }));
12
+ return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(i, { onError: o }, /* @__PURE__ */ e.createElement(l, { makeClient: m }, t), !o && /* @__PURE__ */ e.createElement(a, null)), /* @__PURE__ */ e.createElement(c, { position: "top-right" }));
13
13
  }
14
14
  export {
15
- g as ApolloProvider
15
+ s as ApolloProvider
16
16
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),u=require("./apollo-error.context.cjs"),n=require("./apollo-error.util.cjs");function a({children:l}){const[e,o]=r.useState(null);r.useEffect(()=>{n.setGlobalApolloErrorCallback(o)},[]);const t=r.useMemo(()=>({error:e,showError:o,hideError:()=>o(null)}),[e]);return r.createElement(u.ApolloErrorContext,{value:t},l)}exports.ApolloErrorProvider=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react"),i=require("./apollo-error.context.cjs"),c=require("./apollo-error.util.cjs");function b({children:n,onError:e}){const[o,t]=l.useState(null),r=l.useCallback(u=>{if(e){e(u);return}t(u)},[e]);l.useEffect(()=>(c.setGlobalApolloErrorCallback(r,!!e),()=>{c.clearGlobalApolloErrorCallback()}),[r,e]);const a=l.useCallback(()=>t(null),[]),s=l.useMemo(()=>({error:e?null:o,showError:r,hideError:a}),[o,r,a,e]);return l.createElement(i.ApolloErrorContext,{value:s},n)}exports.ApolloErrorProvider=b;
@@ -1,4 +1,5 @@
1
- import { ReactNode, default as React } from 'react';
1
+ import { default as React } from 'react';
2
+ import { I_ApolloErrorProviderProps } from './apollo-error.type.js';
2
3
  /**
3
4
  * Provider component that manages Apollo error state and provides error context.
4
5
  * This component sets up error handling for Apollo Client operations and provides
@@ -8,12 +9,12 @@ import { ReactNode, default as React } from 'react';
8
9
  * - Global Apollo error state management
9
10
  * - Error context provision to child components
10
11
  * - Automatic error handling and display
12
+ * - Optional custom error handling callbacks
11
13
  * - Integration with error boundaries
12
14
  *
13
15
  * @param props - Component props containing children.
14
16
  * @param props.children - React children that will have access to the error context.
17
+ * @param props.onError - Optional callback to override the default error modal/toast flow.
15
18
  * @returns A React component that provides Apollo error context to its children.
16
19
  */
17
- export declare function ApolloErrorProvider({ children }: {
18
- children: ReactNode;
19
- }): React.JSX.Element;
20
+ export declare function ApolloErrorProvider({ children, onError }: I_ApolloErrorProviderProps): React.JSX.Element;