@helpdice/sdk 0.2.6 → 0.2.7

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 (293) hide show
  1. package/dist/cjs/account/endpoint.js +8 -0
  2. package/dist/cjs/account/index.js +17 -0
  3. package/dist/cjs/account/types.js +2 -0
  4. package/dist/cjs/account/update_profile.js +17 -0
  5. package/dist/cjs/accounting/createInvoice.js +17 -0
  6. package/dist/{accounting → cjs/accounting}/endpoint.js +3 -2
  7. package/dist/cjs/accounting/index.js +25 -0
  8. package/dist/cjs/accounting/submitInvoice.js +17 -0
  9. package/dist/cjs/accounting/types.js +2 -0
  10. package/dist/cjs/accounting/updateInvoice.js +17 -0
  11. package/dist/cjs/apis/cities.js +17 -0
  12. package/dist/cjs/apis/countries.js +17 -0
  13. package/dist/cjs/apis/index.js +14 -0
  14. package/dist/cjs/apis/states.js +17 -0
  15. package/dist/{assets → cjs/assets}/endpoint.js +3 -2
  16. package/dist/cjs/assets/index.js +11 -0
  17. package/dist/cjs/auth/authWithKey.js +17 -0
  18. package/dist/cjs/auth/authWithToken.js +17 -0
  19. package/dist/{auth → cjs/auth}/endpoint.js +3 -2
  20. package/dist/cjs/auth/index.js +94 -0
  21. package/dist/cjs/auth/logout.js +22 -0
  22. package/dist/cjs/auth/register.js +17 -0
  23. package/dist/cjs/auth/resetPassword.js +17 -0
  24. package/dist/{auth → cjs/auth}/signInWithGoogle.js +14 -10
  25. package/dist/cjs/auth/signin.js +17 -0
  26. package/dist/cjs/auth/signup.js +17 -0
  27. package/dist/cjs/auth/types.js +2 -0
  28. package/dist/{config → cjs/config}/axios.js +42 -30
  29. package/dist/cjs/config/constants.js +12 -0
  30. package/dist/{config → cjs/config}/fetch.js +5 -4
  31. package/dist/{config → cjs/config}/handler.js +3 -2
  32. package/dist/cjs/config/index.js +37 -0
  33. package/dist/{config → cjs/config}/local-storage.js +1 -2
  34. package/dist/cjs/config/route.js +47 -0
  35. package/dist/{config → cjs/config}/validate.js +6 -5
  36. package/dist/{content → cjs/content}/endpoint.js +3 -2
  37. package/dist/cjs/content/index.js +29 -0
  38. package/dist/cjs/hooks/index.js +10 -0
  39. package/dist/{hooks → cjs/hooks}/useAuth.js +2 -3
  40. package/dist/{hooks → cjs/hooks}/usePrivate.js +2 -3
  41. package/dist/cjs/hooks/useUser.js +15 -0
  42. package/dist/cjs/index.js +59 -0
  43. package/dist/{inventory → cjs/inventory}/endpoint.js +3 -2
  44. package/dist/cjs/inventory/index.js +26 -0
  45. package/dist/cjs/linkie/endpoint.js +8 -0
  46. package/dist/cjs/linkie/index.js +20 -0
  47. package/dist/cjs/linkie/shortUrl.js +17 -0
  48. package/dist/cjs/linkie/types.js +2 -0
  49. package/dist/cjs/order/create.js +17 -0
  50. package/dist/cjs/order/endpoint.js +8 -0
  51. package/dist/cjs/order/index.js +10 -0
  52. package/dist/cjs/order/types.js +2 -0
  53. package/dist/{payment → cjs/payment}/components/ProcessPayment.js +3 -4
  54. package/dist/cjs/payment/endpoint.js +9 -0
  55. package/dist/cjs/payment/index.js +12 -0
  56. package/dist/{payment → cjs/payment}/start.js +11 -7
  57. package/dist/cjs/payment/types.js +2 -0
  58. package/dist/cjs/payment/verify.js +17 -0
  59. package/dist/cjs/sales/endpoint.js +8 -0
  60. package/dist/cjs/sales/index.js +7 -0
  61. package/dist/cjs/sales/lead.js +22 -0
  62. package/dist/{sales → cjs/sales}/types.js +7 -5
  63. package/dist/{support → cjs/support}/endpoint.js +3 -2
  64. package/dist/cjs/support/index.js +15 -0
  65. package/dist/cjs/support/newsletter.js +17 -0
  66. package/dist/cjs/support/ticket.js +17 -0
  67. package/dist/cjs/tools/endpoint.js +8 -0
  68. package/dist/{tools → cjs/tools}/exchangeRates.js +10 -6
  69. package/dist/cjs/tools/index.js +10 -0
  70. package/dist/cjs/types.js +9 -0
  71. package/dist/cjs/utils/auth.js +23 -0
  72. package/dist/{utils → cjs/utils}/handler.js +3 -2
  73. package/dist/{utils → cjs/utils}/localStorage.js +28 -18
  74. package/dist/{utils → cjs/utils}/share.js +4 -2
  75. package/dist/index.js +974 -23
  76. package/dist/index.js.map +1 -1
  77. package/dist/{account → types/account}/index.d.ts +2 -2
  78. package/dist/{account → types/account}/update_profile.d.ts +2 -2
  79. package/dist/{accounting → types/accounting}/createInvoice.d.ts +2 -2
  80. package/dist/{accounting → types/accounting}/index.d.ts +6 -6
  81. package/dist/{accounting → types/accounting}/submitInvoice.d.ts +2 -2
  82. package/dist/{accounting → types/accounting}/updateInvoice.d.ts +2 -2
  83. package/dist/types/apis/cities.d.ts +11 -0
  84. package/dist/types/apis/countries.d.ts +11 -0
  85. package/dist/types/apis/index.d.ts +30 -0
  86. package/dist/types/apis/states.d.ts +11 -0
  87. package/dist/{auth → types/auth}/authWithKey.d.ts +1 -1
  88. package/dist/{auth → types/auth}/authWithToken.d.ts +1 -1
  89. package/dist/{auth → types/auth}/index.d.ts +13 -13
  90. package/dist/{auth → types/auth}/register.d.ts +1 -1
  91. package/dist/{auth → types/auth}/resetPassword.d.ts +1 -1
  92. package/dist/{auth → types/auth}/signin.d.ts +1 -1
  93. package/dist/{auth → types/auth}/signup.d.ts +1 -1
  94. package/dist/{config → types/config}/axios.d.ts +4 -3
  95. package/dist/{config → types/config}/index.d.ts +2 -1
  96. package/dist/types/config/local-storage.d.ts +0 -0
  97. package/dist/{config → types/config}/validate.d.ts +1 -1
  98. package/dist/types/hooks/index.d.ts +1 -0
  99. package/dist/types/hooks/useAuth.d.ts +0 -0
  100. package/dist/types/hooks/usePrivate.d.ts +0 -0
  101. package/dist/types/index.d.ts +18 -0
  102. package/dist/{linkie → types/linkie}/index.d.ts +2 -2
  103. package/dist/{linkie → types/linkie}/shortUrl.d.ts +2 -2
  104. package/dist/{order → types/order}/create.d.ts +1 -1
  105. package/dist/{order → types/order}/index.d.ts +1 -1
  106. package/dist/types/payment/components/ProcessPayment.d.ts +0 -0
  107. package/dist/{payment → types/payment}/index.d.ts +3 -3
  108. package/dist/{payment → types/payment}/verify.d.ts +2 -2
  109. package/dist/{sales → types/sales}/index.d.ts +1 -1
  110. package/dist/{sales → types/sales}/lead.d.ts +1 -1
  111. package/dist/{sales → types/sales}/types.d.ts +1 -1
  112. package/package.json +11 -4
  113. package/dist/account/endpoint.js +0 -7
  114. package/dist/account/endpoint.js.map +0 -1
  115. package/dist/account/index.js +0 -13
  116. package/dist/account/index.js.map +0 -1
  117. package/dist/account/types.js +0 -2
  118. package/dist/account/types.js.map +0 -1
  119. package/dist/account/update_profile.js +0 -13
  120. package/dist/account/update_profile.js.map +0 -1
  121. package/dist/account/updateprofile.d.ts +0 -12
  122. package/dist/account/updateprofile.js +0 -13
  123. package/dist/account/updateprofile.js.map +0 -1
  124. package/dist/accounting/createInvoice.js +0 -13
  125. package/dist/accounting/createInvoice.js.map +0 -1
  126. package/dist/accounting/endpoint.js.map +0 -1
  127. package/dist/accounting/index.js +0 -21
  128. package/dist/accounting/index.js.map +0 -1
  129. package/dist/accounting/invoice.d.ts +0 -12
  130. package/dist/accounting/invoice.js +0 -13
  131. package/dist/accounting/invoice.js.map +0 -1
  132. package/dist/accounting/submitInvoice.js +0 -13
  133. package/dist/accounting/submitInvoice.js.map +0 -1
  134. package/dist/accounting/types.js +0 -2
  135. package/dist/accounting/types.js.map +0 -1
  136. package/dist/accounting/updateInvoice.js +0 -13
  137. package/dist/accounting/updateInvoice.js.map +0 -1
  138. package/dist/assets/endpoint.js.map +0 -1
  139. package/dist/assets/index.js +0 -10
  140. package/dist/assets/index.js.map +0 -1
  141. package/dist/auth/authWithKey.js +0 -13
  142. package/dist/auth/authWithKey.js.map +0 -1
  143. package/dist/auth/authWithToken.js +0 -13
  144. package/dist/auth/authWithToken.js.map +0 -1
  145. package/dist/auth/endpoint.js.map +0 -1
  146. package/dist/auth/index.js +0 -90
  147. package/dist/auth/index.js.map +0 -1
  148. package/dist/auth/logout.js +0 -18
  149. package/dist/auth/logout.js.map +0 -1
  150. package/dist/auth/register.js +0 -13
  151. package/dist/auth/register.js.map +0 -1
  152. package/dist/auth/resetPassword.js +0 -13
  153. package/dist/auth/resetPassword.js.map +0 -1
  154. package/dist/auth/signInWithGoogle.js.map +0 -1
  155. package/dist/auth/signin.js +0 -13
  156. package/dist/auth/signin.js.map +0 -1
  157. package/dist/auth/signup.js +0 -13
  158. package/dist/auth/signup.js.map +0 -1
  159. package/dist/auth/types.js +0 -2
  160. package/dist/auth/types.js.map +0 -1
  161. package/dist/auth/verifyToken.d.ts +0 -11
  162. package/dist/auth/verifyToken.js +0 -13
  163. package/dist/auth/verifyToken.js.map +0 -1
  164. package/dist/config/Env.d.ts +0 -40
  165. package/dist/config/Env.js +0 -52
  166. package/dist/config/Env.js.map +0 -1
  167. package/dist/config/axios.js.map +0 -1
  168. package/dist/config/constants.js +0 -10
  169. package/dist/config/constants.js.map +0 -1
  170. package/dist/config/fetch.js.map +0 -1
  171. package/dist/config/firebase.d.ts +0 -3
  172. package/dist/config/firebase.js +0 -16
  173. package/dist/config/firebase.js.map +0 -1
  174. package/dist/config/handler.js.map +0 -1
  175. package/dist/config/index.js +0 -26
  176. package/dist/config/index.js.map +0 -1
  177. package/dist/config/local-storage.d.ts +0 -1
  178. package/dist/config/local-storage.js.map +0 -1
  179. package/dist/config/route.js +0 -42
  180. package/dist/config/route.js.map +0 -1
  181. package/dist/config/validate.js.map +0 -1
  182. package/dist/content/endpoint.js.map +0 -1
  183. package/dist/content/index.js +0 -28
  184. package/dist/content/index.js.map +0 -1
  185. package/dist/hooks/index.d.ts +0 -1
  186. package/dist/hooks/index.js +0 -4
  187. package/dist/hooks/index.js.map +0 -1
  188. package/dist/hooks/useAuth.d.ts +0 -1
  189. package/dist/hooks/useAuth.js.map +0 -1
  190. package/dist/hooks/usePrivate.d.ts +0 -1
  191. package/dist/hooks/usePrivate.js.map +0 -1
  192. package/dist/hooks/useUser.js +0 -11
  193. package/dist/hooks/useUser.js.map +0 -1
  194. package/dist/index.d.ts +0 -17
  195. package/dist/inventory/endpoint.js.map +0 -1
  196. package/dist/inventory/index.js +0 -25
  197. package/dist/inventory/index.js.map +0 -1
  198. package/dist/linkie/endpoint.js +0 -7
  199. package/dist/linkie/endpoint.js.map +0 -1
  200. package/dist/linkie/index.js +0 -16
  201. package/dist/linkie/index.js.map +0 -1
  202. package/dist/linkie/shortUrl.js +0 -13
  203. package/dist/linkie/shortUrl.js.map +0 -1
  204. package/dist/linkie/types.js +0 -2
  205. package/dist/linkie/types.js.map +0 -1
  206. package/dist/order/create.js +0 -13
  207. package/dist/order/create.js.map +0 -1
  208. package/dist/order/endpoint.js +0 -7
  209. package/dist/order/endpoint.js.map +0 -1
  210. package/dist/order/index.js +0 -6
  211. package/dist/order/index.js.map +0 -1
  212. package/dist/order/types.js +0 -2
  213. package/dist/order/types.js.map +0 -1
  214. package/dist/package.json +0 -48
  215. package/dist/payment/components/ProcessPayment.d.ts +0 -1
  216. package/dist/payment/components/ProcessPayment.js.map +0 -1
  217. package/dist/payment/endpoint.js +0 -8
  218. package/dist/payment/endpoint.js.map +0 -1
  219. package/dist/payment/index.js +0 -8
  220. package/dist/payment/index.js.map +0 -1
  221. package/dist/payment/start.js.map +0 -1
  222. package/dist/payment/types.js +0 -2
  223. package/dist/payment/types.js.map +0 -1
  224. package/dist/payment/verify.js +0 -13
  225. package/dist/payment/verify.js.map +0 -1
  226. package/dist/sales/endpoint.js +0 -7
  227. package/dist/sales/endpoint.js.map +0 -1
  228. package/dist/sales/index.js +0 -6
  229. package/dist/sales/index.js.map +0 -1
  230. package/dist/sales/lead.js +0 -17
  231. package/dist/sales/lead.js.map +0 -1
  232. package/dist/sales/types.js.map +0 -1
  233. package/dist/support/endpoint.js.map +0 -1
  234. package/dist/support/index.js +0 -11
  235. package/dist/support/index.js.map +0 -1
  236. package/dist/support/newsletter.js +0 -13
  237. package/dist/support/newsletter.js.map +0 -1
  238. package/dist/support/ticket.js +0 -13
  239. package/dist/support/ticket.js.map +0 -1
  240. package/dist/tools/endpoint.js +0 -7
  241. package/dist/tools/endpoint.js.map +0 -1
  242. package/dist/tools/exchangeRates.js.map +0 -1
  243. package/dist/tools/index.js +0 -6
  244. package/dist/tools/index.js.map +0 -1
  245. package/dist/types.js +0 -7
  246. package/dist/types.js.map +0 -1
  247. package/dist/utils/auth.js +0 -16
  248. package/dist/utils/auth.js.map +0 -1
  249. package/dist/utils/exchangeRates.d.ts +0 -1
  250. package/dist/utils/exchangeRates.js +0 -27
  251. package/dist/utils/exchangeRates.js.map +0 -1
  252. package/dist/utils/handler.js.map +0 -1
  253. package/dist/utils/localStorage.js.map +0 -1
  254. package/dist/utils/share.js.map +0 -1
  255. /package/dist/{account → types/account}/endpoint.d.ts +0 -0
  256. /package/dist/{account → types/account}/types.d.ts +0 -0
  257. /package/dist/{accounting → types/accounting}/endpoint.d.ts +0 -0
  258. /package/dist/{accounting → types/accounting}/types.d.ts +0 -0
  259. /package/dist/{assets → types/assets}/endpoint.d.ts +0 -0
  260. /package/dist/{assets → types/assets}/index.d.ts +0 -0
  261. /package/dist/{auth → types/auth}/endpoint.d.ts +0 -0
  262. /package/dist/{auth → types/auth}/logout.d.ts +0 -0
  263. /package/dist/{auth → types/auth}/signInWithGoogle.d.ts +0 -0
  264. /package/dist/{auth → types/auth}/types.d.ts +0 -0
  265. /package/dist/{config → types/config}/constants.d.ts +0 -0
  266. /package/dist/{config → types/config}/fetch.d.ts +0 -0
  267. /package/dist/{config → types/config}/handler.d.ts +0 -0
  268. /package/dist/{config → types/config}/route.d.ts +0 -0
  269. /package/dist/{content → types/content}/endpoint.d.ts +0 -0
  270. /package/dist/{content → types/content}/index.d.ts +0 -0
  271. /package/dist/{hooks → types/hooks}/useUser.d.ts +0 -0
  272. /package/dist/{inventory → types/inventory}/endpoint.d.ts +0 -0
  273. /package/dist/{inventory → types/inventory}/index.d.ts +0 -0
  274. /package/dist/{linkie → types/linkie}/endpoint.d.ts +0 -0
  275. /package/dist/{linkie → types/linkie}/types.d.ts +0 -0
  276. /package/dist/{order → types/order}/endpoint.d.ts +0 -0
  277. /package/dist/{order → types/order}/types.d.ts +0 -0
  278. /package/dist/{payment → types/payment}/endpoint.d.ts +0 -0
  279. /package/dist/{payment → types/payment}/start.d.ts +0 -0
  280. /package/dist/{payment → types/payment}/types.d.ts +0 -0
  281. /package/dist/{sales → types/sales}/endpoint.d.ts +0 -0
  282. /package/dist/{support → types/support}/endpoint.d.ts +0 -0
  283. /package/dist/{support → types/support}/index.d.ts +0 -0
  284. /package/dist/{support → types/support}/newsletter.d.ts +0 -0
  285. /package/dist/{support → types/support}/ticket.d.ts +0 -0
  286. /package/dist/{tools → types/tools}/endpoint.d.ts +0 -0
  287. /package/dist/{tools → types/tools}/exchangeRates.d.ts +0 -0
  288. /package/dist/{tools → types/tools}/index.d.ts +0 -0
  289. /package/dist/{types.d.ts → types/types.d.ts} +0 -0
  290. /package/dist/{utils → types/utils}/auth.d.ts +0 -0
  291. /package/dist/{utils → types/utils}/handler.d.ts +0 -0
  292. /package/dist/{utils → types/utils}/localStorage.d.ts +0 -0
  293. /package/dist/{utils → types/utils}/share.d.ts +0 -0
package/dist/index.js CHANGED
@@ -1,23 +1,974 @@
1
- // @ts-ignore
2
- /// <reference types="styled-jsx" />
3
- // export { isAuth } from './utils/auth';
4
- export { getCookie } from "./utils/auth.js";
5
- export { getUrl } from "./config/route.js";
6
- export { default as Auth } from "./auth/index.js";
7
- export { default as Order } from "./order/index.js";
8
- export { default as Payment } from "./payment/index.js";
9
- export { default as Content } from "./content/index.js";
10
- export { default as Accounting } from "./accounting/index.js";
11
- export { default as Support } from "./support/index.js";
12
- export { default as Assets } from "./assets/index.js";
13
- export { default as Account } from "./account/index.js";
14
- export { default as shareUrl } from "./utils/share.js";
15
- export { default as Sales } from "./sales/index.js";
16
- export { default as Inventory } from "./inventory/index.js";
17
- export { default as Tools } from "./tools/index.js";
18
- export { default as Linkie } from "./linkie/index.js";
19
- export { getConfig, initializeSDK } from './config/index.js';
20
- // export { useUser, usePrivate, useAuth } from './hooks';
21
- // Types
22
- export * from './sales/types.js';
23
- //# sourceMappingURL=index.js.map
1
+ import Cookies from 'js-cookie';
2
+ import { jwtDecode } from 'jwt-decode';
3
+ import firebase from 'firebase/compat/app';
4
+ import CryptoJS from 'crypto-js';
5
+ import axios from 'axios';
6
+ import { GoogleAuthProvider, getAuth, signInWithPopup } from 'firebase/auth';
7
+
8
+ // validateConfig
9
+ function validateConfig(requiredKeys) {
10
+ const config = getConfig();
11
+ const missingKeys = requiredKeys.filter((key) => {
12
+ return !config[key]; // null, undefined, empty string → treated as missing
13
+ });
14
+ if (missingKeys.length > 0) {
15
+ throw new Error(`SDK configuration error: Missing required config value(s): ${missingKeys.join(', ')}\n` +
16
+ '👉 Please ensure these keys are set using setConfig({ ... }) before making requests.');
17
+ }
18
+ }
19
+
20
+ let config = {
21
+ tokenKey: '',
22
+ apiKey: null,
23
+ apiUrl: 'https://api.helpdice.com',
24
+ appUrl: '',
25
+ apisUrl: 'https://apis.helpdice.com',
26
+ environment: 'production',
27
+ firebase: undefined
28
+ };
29
+ function initializeSDK(newConfig) {
30
+ config = { ...config, ...newConfig };
31
+ validateConfig(['apiKey', 'tokenKey']);
32
+ }
33
+ function getFirebase() {
34
+ validateConfig(['firebase']);
35
+ const appConfig = getConfig();
36
+ if (appConfig.firebase) {
37
+ // if (firebase?.default != undefined) {
38
+ // return firebase.default.initializeApp(appConfig.firebase)
39
+ // }
40
+ return firebase.initializeApp(appConfig.firebase);
41
+ }
42
+ throw new Error(`SDK configuration error: Firebase is not configured properly`);
43
+ }
44
+ function getConfig() {
45
+ return config;
46
+ }
47
+
48
+ const getCookie = (key = getConfig().tokenKey) => {
49
+ // console.log(Cookies.get(key));
50
+ if (key)
51
+ return Cookies.get(key);
52
+ return "";
53
+ };
54
+ const isAuth = () => !!getCookie();
55
+ // export const getServerSideToken = (ctx: NextPageContext) => {
56
+ // const { token } = parseCookies(ctx);
57
+ // return token;
58
+ // };
59
+
60
+ /**
61
+ * Function to set encryption key
62
+ * @param {string} key - encryption key name
63
+ * @param {string} value string value to be set as encryption key
64
+ */
65
+ function setEncryptionKey(key, value) {
66
+ if (value) {
67
+ const sha256Key = CryptoJS.SHA256(key).toString();
68
+ // console.log('setting key: ', key, value);
69
+ const sha256Data = CryptoJS.SHA256(value).toString();
70
+ localStorage.setItem(sha256Key, JSON.stringify(sha256Data));
71
+ }
72
+ else {
73
+ console.error("No data provided");
74
+ }
75
+ }
76
+ /**
77
+ * function to get the encryption key
78
+ * @param {string} - name of the key to get encryption key for
79
+ * @returns {string}
80
+ */
81
+ // eslint-disable-next-line consistent-return
82
+ function getEncryptionKey(key) {
83
+ try {
84
+ const shaKey = CryptoJS.SHA256(key).toString();
85
+ // console.log('getting key: ', key, localStorage.getItem(shaKey));
86
+ return localStorage.getItem(shaKey);
87
+ }
88
+ catch (err) {
89
+ console.error("something went wrong man hoho");
90
+ }
91
+ }
92
+ /**
93
+ * Funtion to store data in local storage
94
+ * Pass second argument as true if setting data for employee side
95
+ * @param {string} key key for the value to be stored
96
+ * @param {*} data actual data to be stored with the provided key
97
+ * @param {boolean} [useEmployeeKey] - flag to decide which encyption key to use, (employee's or admin's)
98
+ */
99
+ function setDataInStorage(key, data) {
100
+ // Encrypt key
101
+ const shaKey = CryptoJS.SHA256(key).toString();
102
+ const encKeyName = "account_key";
103
+ const encryptionKey = getEncryptionKey(encKeyName);
104
+ // console.log('setting data: ', encryption_key, key, shaKey, data);
105
+ if (encryptionKey) {
106
+ // Encrypt data
107
+ const dataCipher = CryptoJS.AES.encrypt(JSON.stringify(data), encryptionKey).toString();
108
+ localStorage.setItem(shaKey, JSON.stringify(dataCipher));
109
+ }
110
+ }
111
+ /**
112
+ * Function to get data from local storage
113
+ * Pass second argument as true if getting data for employee side
114
+ * @param {string} key - key of the item to fetch from local storage
115
+ * @param {boolean} [useEmployeeKey] - flag to decide which encyption key to use, (employee's or admin's)
116
+ * @returns {*} value associated with the key
117
+ */
118
+ // eslint-disable-next-line consistent-return
119
+ function getDataFromStorage(key) {
120
+ try {
121
+ const shaKey = CryptoJS.SHA256(key).toString();
122
+ const encKeyName = "account_key";
123
+ const encryptionKey = getEncryptionKey(encKeyName);
124
+ // console.log(
125
+ // 'from getting data: ',
126
+ // key,
127
+ // 'encryption-key',
128
+ // typeof encryption_key,
129
+ // encryption_key
130
+ // );
131
+ if (encryptionKey && shaKey) {
132
+ const ciphertext = JSON.parse(String(localStorage.getItem(shaKey)));
133
+ if (ciphertext) {
134
+ // Decrypt
135
+ const bytes = CryptoJS.AES.decrypt(ciphertext, encryptionKey);
136
+ const originalData = bytes.toString(CryptoJS.enc.Utf8);
137
+ // console.log('getting data: ', key, shaKey, originalData);
138
+ return JSON.parse(originalData);
139
+ }
140
+ }
141
+ }
142
+ catch (err) {
143
+ // console.error('Error getting data from storage boi boi');
144
+ }
145
+ }
146
+ /**
147
+ * Function to clear items from local storage
148
+ * @param {(string|string[])} keys - key to remove or array of keys
149
+ */
150
+ // export function clearStorage(keys: string[]) {
151
+ // try {
152
+ // if (Array.isArray(keys)) {
153
+ // keys.forEach((key) => {
154
+ // const shaKey = CryptoJS.SHA256(key).toString();
155
+ // localStorage.removeItem(shaKey);
156
+ // });
157
+ // } else if (typeof keys === "string") {
158
+ // const shaKey = CryptoJS.SHA256(keys).toString();
159
+ // localStorage.removeItem(shaKey);
160
+ // }
161
+ // } catch (err) {
162
+ // console.error("Error clearing storage", err);
163
+ // }
164
+ // }
165
+ function clearStorage(keys) {
166
+ try {
167
+ if (Array.isArray(keys)) {
168
+ for (const key of keys) {
169
+ const shaKey = CryptoJS.SHA256(key).toString();
170
+ localStorage.removeItem(shaKey);
171
+ }
172
+ }
173
+ else if (typeof keys === "string") {
174
+ const shaKey = CryptoJS.SHA256(keys).toString();
175
+ localStorage.removeItem(shaKey);
176
+ }
177
+ }
178
+ catch (err) {
179
+ console.error("Error clearing storage", err);
180
+ }
181
+ }
182
+
183
+ const TOKEN_KEY = "access-token";
184
+ /* eslint-enable */
185
+
186
+ const http = axios.create({
187
+ withCredentials: true,
188
+ headers: {
189
+ "Access-Control-Allow-Origin": "*",
190
+ "Content-Type": "application/json",
191
+ },
192
+ });
193
+ http.interceptors.request.use((config) => {
194
+ validateConfig(['apiKey', 'apiUrl']);
195
+ const { apiUrl } = getConfig();
196
+ config.baseURL = apiUrl;
197
+ if (config.headers) {
198
+ config.headers["Content-Type"] = "application/json";
199
+ config.headers.Authorization = `Bearer ${getCookie()}` || "";
200
+ config.headers["HB-API-KEY"] =
201
+ `Bearer ${getConfig().apiKey}` || "";
202
+ }
203
+ return config;
204
+ }, Promise.reject);
205
+ const post = (endpoint, data, config) => new Promise((resolve, reject) => http
206
+ .post(endpoint, data, config)
207
+ .then(resolve)
208
+ .catch((e) => reject(e.response?.data)));
209
+ const put = (endpoint, data, config) => new Promise((resolve, reject) => http
210
+ .put(endpoint, data, config)
211
+ .then(resolve)
212
+ .catch((e) => reject(e.response?.data)));
213
+ const get = (endpoint, config) => {
214
+ // console.log('Get Request Config :', config);
215
+ return new Promise((resolve, reject) => http
216
+ .get(endpoint, config)
217
+ .then(resolve)
218
+ .catch((e) => reject(e.response?.data)));
219
+ };
220
+ /* ======================================================================================================= */
221
+ /* ------------------------------------ For Linkie App --------------------------------------------------- */
222
+ /* ======================================================================================================= */
223
+ const chttp = axios.create({
224
+ withCredentials: true,
225
+ headers: {
226
+ "Access-Control-Allow-Origin": "*",
227
+ "Content-Type": "application/json",
228
+ },
229
+ });
230
+ chttp.interceptors.request.use((config) => {
231
+ validateConfig(['apiKey', 'tokenKey', 'linkieUrl']);
232
+ const { linkieUrl } = getConfig();
233
+ config.baseURL = linkieUrl;
234
+ if (config.headers) {
235
+ config.headers["Content-Type"] = "application/json";
236
+ config.headers.Authorization = localStorage.getItem(TOKEN_KEY) || "";
237
+ config.headers["HB-API-KEY"] =
238
+ `Bearer ${getConfig().apiKey}` || "";
239
+ }
240
+ return config;
241
+ }, Promise.reject);
242
+ // chttp.interceptors.response.use(
243
+ // (response) => response,
244
+ // async (error) => {
245
+ // if (error.code === "ERR_NETWORK") {
246
+ // return Promise.reject(error);
247
+ // }
248
+ // const refreshToken = localStorage.getItem(REFRESH_TOKEN_KEY);
249
+ // if (!refreshToken) {
250
+ // return Promise.reject(error);
251
+ // }
252
+ // // const originalRequest = error.config;
253
+ // // if (error.response.status === 401 && !originalRequest._retry) {
254
+ // // originalRequest._retry = true;
255
+ // // if (http.defaults.headers) {
256
+ // // http.defaults.headers.Authorization = `Bearer ${refreshToken}`;
257
+ // // }
258
+ // // try {
259
+ // // const res = await post('auth/token');
260
+ // // const { access_token, threshold } = res.data;
261
+ // // // handleItem(TOKEN_KEY, access_token);
262
+ // // // handleItem(TOKEN_THRESHOLD_KEY, setThreshold(threshold));
263
+ // // if (http.defaults.headers) {
264
+ // // http.defaults.headers.Authorization = access_token;
265
+ // // }
266
+ // // return await http(originalRequest);
267
+ // // } catch (reason) {
268
+ // // return Promise.reject(reason);
269
+ // // }
270
+ // // }
271
+ // return Promise.reject(error);
272
+ // },
273
+ // );
274
+ const linkiePost = (endpoint, data, config) => new Promise((resolve, reject) => chttp
275
+ .post(endpoint, data, config)
276
+ .then(resolve)
277
+ .catch((e) => reject(e.response?.data)));
278
+
279
+ // The fetchDataWithCallbacks function that accepts a Promise and a callbacks object
280
+ async function handler$1(promise, callbacks) {
281
+ // Destructure callbacks from the object
282
+ const { onFetching, onSuccess, onError, onSettled } = callbacks ?? {};
283
+ // Call the onFetching callback before making the request
284
+ if (onFetching)
285
+ onFetching();
286
+ // Handle the Promise passed as an argument
287
+ promise
288
+ .then((response) => {
289
+ // Call the onSuccess callback if the Promise resolves successfully
290
+ if (onSuccess)
291
+ onSuccess({
292
+ data: response.data,
293
+ status: response.status,
294
+ statusText: response.statusText,
295
+ });
296
+ })
297
+ .catch((error) => {
298
+ // Call the onError callback if the Promise is rejected
299
+ if (onError)
300
+ onError(error);
301
+ })
302
+ .finally(() => {
303
+ // Call the onSettled callback after the Promise is settled
304
+ if (onSettled)
305
+ onSettled();
306
+ });
307
+ }
308
+
309
+ const account = {
310
+ v1: {
311
+ profile: "profile",
312
+ },
313
+ };
314
+
315
+ const accounting = {
316
+ v1: {
317
+ item: "item",
318
+ items: "items",
319
+ invoice: "invoice",
320
+ submit_invoice: "invoice/submit",
321
+ invoices: "invoices",
322
+ item_categories: "item/category",
323
+ item_brands: "item/brand",
324
+ },
325
+ };
326
+
327
+ const assets = {
328
+ v1: {
329
+ imagePlaceholder: "images/image-placeholder.webp",
330
+ avatar: "images/avatar.webp",
331
+ },
332
+ };
333
+
334
+ const auth = {
335
+ v1: {
336
+ signin: "signin",
337
+ register: "signup",
338
+ signup: "register",
339
+ logout: "logout",
340
+ auth_with_token: "authenticate",
341
+ auth_with_key: "verify",
342
+ reset_password: "recovery-password",
343
+ change_password: "change-password"
344
+ },
345
+ };
346
+
347
+ const cms = {
348
+ v1: {
349
+ article: "article",
350
+ articles: "articles",
351
+ articleCategories: "article/categories",
352
+ mcq: "mcq",
353
+ mcqs: "mcqs",
354
+ all_mcqs: "mcqs/all",
355
+ mcqCategories: "mcq/categories",
356
+ qna: "qna",
357
+ qnas: "qnas",
358
+ qnaCategories: "qna/categories",
359
+ },
360
+ };
361
+
362
+ const inventory = {
363
+ v1: {
364
+ store: "store",
365
+ store_products: "store/products",
366
+ },
367
+ };
368
+
369
+ const linkie = {
370
+ v1: {
371
+ shorten: "shorten",
372
+ },
373
+ };
374
+
375
+ const payment = {
376
+ v1: {
377
+ create: "",
378
+ verify: "verify",
379
+ },
380
+ };
381
+
382
+ const sales = {
383
+ v1: {
384
+ addLead: "lead"
385
+ },
386
+ };
387
+
388
+ const support = {
389
+ v1: {
390
+ ticket: "ticket",
391
+ tickets: "tickets",
392
+ newsletter: "newsletter",
393
+ },
394
+ };
395
+
396
+ const tools = {
397
+ v1: {
398
+ exchangeRates: "exchange-rates",
399
+ },
400
+ };
401
+
402
+ const urls = {
403
+ auth,
404
+ cms,
405
+ account,
406
+ accounting,
407
+ support,
408
+ assets,
409
+ payment,
410
+ inventory,
411
+ tools,
412
+ sales,
413
+ linkie
414
+ };
415
+ // Function to get the URL dynamically based on category, version, and action
416
+ function getUrl(category, version, action, omitCategory = false) {
417
+ const categoryData = urls[category]; // Access the correct category dynamically
418
+ if (categoryData) {
419
+ const versionData = categoryData[version]; // Access the correct version dynamically
420
+ // console.log(versionData?.[action]);
421
+ if (versionData !== undefined) {
422
+ console.log(versionData[action]);
423
+ if (omitCategory) {
424
+ return `/api/${version}/${versionData[action]}`;
425
+ }
426
+ return `/api/${version}/${category}/${versionData[action]}`; // Construct the URL
427
+ }
428
+ throw new Error(`Invalid action: ${action} for version: ${version} in category: ${category}`);
429
+ }
430
+ throw new Error(`Invalid category: ${category}`);
431
+ }
432
+
433
+ const logout = (data, { config, onFetching, onSuccess, onError, onSettled, }) => {
434
+ return handler$1(post(getUrl("auth", "v1", "logout"), { ...data, fcm_token: getDataFromStorage("fcm_token") }, config), {
435
+ onFetching: () => onFetching?.(),
436
+ onError: (error) => onError?.(error),
437
+ onSuccess: (data) => {
438
+ clearStorage(["accountAccessToken", "accountInfo", "account_key"]);
439
+ onSuccess?.(data);
440
+ window.location.href = "/";
441
+ },
442
+ onSettled: () => onSettled?.(),
443
+ });
444
+ };
445
+
446
+ const register = (data, { config, onFetching, onSuccess, onError, onSettled, }) => {
447
+ return handler$1(post(getUrl("auth", "v1", "register"), data, config), {
448
+ onFetching: () => onFetching?.(),
449
+ onError: (error) => onError?.(error),
450
+ onSuccess: (data) => onSuccess?.(data),
451
+ onSettled: () => onSettled?.(),
452
+ });
453
+ };
454
+
455
+ const signup = (data, { config, onFetching, onSuccess, onError, onSettled, }) => {
456
+ return handler$1(post(getUrl("auth", "v1", "signup"), data, config), {
457
+ onFetching: () => onFetching?.(),
458
+ onError: (error) => onError?.(error),
459
+ onSuccess: (data) => onSuccess?.(data),
460
+ onSettled: () => onSettled?.(),
461
+ });
462
+ };
463
+
464
+ // import signin from "./signin";
465
+ // Function to handle Google Sign-In
466
+ async function signInWithGoogle({ onSuccess, onError, onFetching, onSettled, }) {
467
+ try {
468
+ const provider = new GoogleAuthProvider();
469
+ const auth = getAuth(getFirebase());
470
+ signInWithPopup(auth, provider)
471
+ .then((result) => {
472
+ // This gives you a Google Access Token. You can use it to access the Google API.
473
+ const credential = GoogleAuthProvider.credentialFromResult(result);
474
+ // const token = credential?.accessToken;
475
+ // The signed-in user info.
476
+ const user = result.user;
477
+ // console.log(user);
478
+ return signup({
479
+ provider: "Google",
480
+ uid: user.uid,
481
+ name: String(user.displayName),
482
+ email: String(user.email),
483
+ username: String(user.email),
484
+ password: user.uid.substring(0, user.uid.length / 2),
485
+ // token: token,
486
+ today: new Date(),
487
+ }, {
488
+ onFetching: () => onFetching?.(),
489
+ onError: (error) => onError?.(error),
490
+ onSuccess: (data) => onSuccess?.(data),
491
+ onSettled: () => onSettled?.(),
492
+ });
493
+ })
494
+ .catch((error) => {
495
+ onError?.(error);
496
+ return Promise.reject("Something Went Wrong");
497
+ // Handle Errors here.
498
+ // const errorCode = error.code;
499
+ // const errorMessage = error.message;
500
+ // The email of the user's account used.
501
+ // const email = error.customData.email;
502
+ // The AuthCredential type that was used.
503
+ // const credential = GoogleAuthProvider.credentialFromError(error);
504
+ // ...
505
+ });
506
+ }
507
+ catch (err) {
508
+ onError?.(err);
509
+ }
510
+ }
511
+
512
+ const signin = (data, { config, onFetching, onSuccess, onError, onSettled, }) => {
513
+ return handler$1(post(getUrl("auth", "v1", "signin"), data, config), {
514
+ onFetching: () => onFetching?.(),
515
+ onError: (error) => onError?.(error),
516
+ onSuccess: (data) => onSuccess?.(data),
517
+ onSettled: () => onSettled?.(),
518
+ });
519
+ };
520
+
521
+ const authWithToken = (data, { config, onFetching, onSuccess, onError, onSettled, }) => {
522
+ return handler$1(post(getUrl("auth", "v1", "auth_with_token"), data, config), {
523
+ onFetching: () => onFetching?.(),
524
+ onError: (error) => onError?.(error),
525
+ onSuccess: (data) => onSuccess?.(data),
526
+ onSettled: () => onSettled?.(),
527
+ });
528
+ };
529
+
530
+ const authWithKey = (data, { config, onFetching, onSuccess, onError, onSettled, }) => {
531
+ return handler$1(post(getUrl("auth", "v1", "auth_with_key"), data, config), {
532
+ onFetching: () => onFetching?.(),
533
+ onError: (error) => onError?.(error),
534
+ onSuccess: (data) => onSuccess?.(data),
535
+ onSettled: () => onSettled?.(),
536
+ });
537
+ };
538
+
539
+ const resetPassword = (data, { config, onFetching, onSuccess, onError, onSettled, }) => {
540
+ return handler$1(post(getUrl("auth", "v1", "reset_password"), data, config), {
541
+ onFetching: () => onFetching?.(),
542
+ onError: (error) => onError?.(error),
543
+ onSuccess: (data) => onSuccess?.(data),
544
+ onSettled: () => onSettled?.(),
545
+ });
546
+ };
547
+
548
+ const Auth = {
549
+ signIn: signin,
550
+ signUp: signup,
551
+ register,
552
+ resetPassword,
553
+ signInWithGoogle,
554
+ saveTokenToCookie: (token) => {
555
+ validateConfig(['tokenKey']);
556
+ const { tokenKey } = getConfig();
557
+ if (tokenKey) {
558
+ Cookies.set(tokenKey, token, { expires: 900000 });
559
+ }
560
+ window.location.href = "/";
561
+ },
562
+ saveTokenToStorage: (token) => {
563
+ const accountInfo = jwtDecode(token);
564
+ if (accountInfo) {
565
+ setEncryptionKey("account_key", accountInfo._id + accountInfo.createdAt);
566
+ setDataInStorage("accountAccessToken", token);
567
+ setDataInStorage("accountInfo", accountInfo);
568
+ }
569
+ },
570
+ getTokenFromStorage: () => {
571
+ return getDataFromStorage("accountAccessToken");
572
+ },
573
+ getUserFromStrorage: () => {
574
+ return getDataFromStorage("accountInfo");
575
+ },
576
+ /**
577
+ * Action to update stored admin info in the redux
578
+ * @param {string | object} key key or an object with key: value of the fields to be updated
579
+ * @param {any} value value of the field to be updated (only if the key passed is of type string)
580
+ */
581
+ updateUserInfo: (key, value) => () => {
582
+ console.log("typeof key: ", typeof key, key);
583
+ try {
584
+ // console.log(key);
585
+ const accountInfo = getDataFromStorage("accountInfo");
586
+ if (typeof key === "object") {
587
+ let updatedInfo = { ...accountInfo };
588
+ // for..of
589
+ for (const [ky, value] of Object.entries(key)) {
590
+ updatedInfo = { ...updatedInfo, [ky]: value };
591
+ }
592
+ // console.log(updatedInfo);
593
+ setDataInStorage("accountInfo", updatedInfo);
594
+ }
595
+ else if (typeof key === "string") {
596
+ if (value) {
597
+ setDataInStorage("accountInfo", { ...accountInfo, [key]: value });
598
+ }
599
+ else {
600
+ console.error("Value is not provided for the given key to update admin info");
601
+ }
602
+ }
603
+ }
604
+ catch (error) {
605
+ console.error("update logo action ", error);
606
+ }
607
+ },
608
+ isAuthenticated: (cookie) => {
609
+ if (cookie) {
610
+ return isAuth();
611
+ }
612
+ return getDataFromStorage("accountAccessToken") !== undefined;
613
+ },
614
+ // getServerToken: (ctx: NextPageContext) => getServerSideToken(ctx),
615
+ logout,
616
+ Server: {
617
+ authWithToken,
618
+ authWithKey
619
+ }
620
+ };
621
+
622
+ const create = (data, { config, onFetching, onSuccess, onError, onSettled, }) => {
623
+ return handler$1(post(getUrl("order", "v1", "create"), data, config), {
624
+ onFetching: () => onFetching?.(),
625
+ onError: (error) => onError?.(error),
626
+ onSuccess: (data) => onSuccess?.(data),
627
+ onSettled: () => onSettled?.(),
628
+ });
629
+ };
630
+
631
+ const Order = {
632
+ create,
633
+ };
634
+
635
+ const handler = ({ promise, onLoading = () => { }, onSuccess = () => { }, onError = () => { }, onSettled = () => { }, onProgress = () => { }, }) => {
636
+ // Call onLoading at the start to show loading state
637
+ onLoading(true);
638
+ // Handling the passed promise
639
+ promise
640
+ .then((response) => {
641
+ // Show success state
642
+ console.log("Request Success:", response);
643
+ // Execute success callback if provided
644
+ if (onSuccess) {
645
+ onSuccess(response.data);
646
+ }
647
+ })
648
+ .catch((error) => {
649
+ // Show error state
650
+ console.error("Request Error:", error);
651
+ // Execute error callback if provided
652
+ if (onError) {
653
+ onError(error);
654
+ }
655
+ })
656
+ .finally(() => {
657
+ // Execute settled callback (on success or error)
658
+ if (onSettled) {
659
+ onSettled();
660
+ }
661
+ // Call onLoading to hide loading indicator after completion
662
+ onLoading(false);
663
+ // Hide loading indicator
664
+ console.log("Request Completed");
665
+ });
666
+ };
667
+
668
+ function start(data, { config = null, onLoading = () => { }, onSuccess = () => { }, onError = () => { }, onSettled = () => { }, } = {}) {
669
+ return handler({
670
+ promise: post(getUrl("payment", "v1", "create"), {
671
+ ...data,
672
+ method: {
673
+ label: data.paymentService,
674
+ currency: data.currency,
675
+ },
676
+ }, config || undefined),
677
+ onLoading,
678
+ onError: (error) => onError(error),
679
+ onSuccess: (responseData) => {
680
+ if (responseData?.method === "Razor Pay") {
681
+ const options = responseData.options;
682
+ options.handler = async (response) => {
683
+ // console.log("Payment Success:", response);
684
+ onSuccess(response);
685
+ // Validation call (if needed)
686
+ };
687
+ const rzp1 = new window.Razorpay(options);
688
+ rzp1.on("payment.failed", (response) => {
689
+ onError(response);
690
+ });
691
+ rzp1.open();
692
+ }
693
+ },
694
+ onSettled,
695
+ });
696
+ }
697
+
698
+ const verify = (data, { config, onFetching, onSuccess, onError, onSettled, }) => {
699
+ return handler$1(post(getUrl("payment", "v1", "verify"), data, config), {
700
+ onFetching: () => onFetching?.(),
701
+ onError: (error) => onError?.(error),
702
+ onSuccess: (data) => onSuccess?.(data),
703
+ onSettled: () => onSettled?.(),
704
+ });
705
+ };
706
+
707
+ const Payment = {
708
+ start,
709
+ verify,
710
+ };
711
+
712
+ const Content = {
713
+ article: (slug) => get(getUrl("cms", "v1", "article"), {
714
+ params: {
715
+ slug,
716
+ },
717
+ }),
718
+ articles: (config) => get(getUrl("cms", "v1", "articles"), config),
719
+ articleCategories: (config) => get(getUrl("cms", "v1", "articleCategories"), config),
720
+ mcq: (slug) => get(getUrl("cms", "v1", "mcq"), {
721
+ params: {
722
+ slug,
723
+ },
724
+ }),
725
+ mcqs: (config) => get(getUrl("cms", "v1", "mcqs"), config),
726
+ allMcqs: (config) => get(getUrl("cms", "v1", "all_mcqs"), config),
727
+ mcqsCategories: (config) => get(getUrl("cms", "v1", "mcqCategories"), config),
728
+ qna: (slug) => get(getUrl("cms", "v1", "qna"), {
729
+ params: {
730
+ slug,
731
+ },
732
+ }),
733
+ qnas: (config) => get(getUrl("cms", "v1", "qnas"), config),
734
+ qnasCategories: (config) => get(getUrl("cms", "v1", "qnaCategories"), config),
735
+ };
736
+
737
+ const createInvoice = (data, { config, onFetching, onSuccess, onError, onSettled, }) => {
738
+ return handler$1(post(getUrl("accounting", "v1", "invoice"), data, config), {
739
+ onFetching: () => onFetching?.(),
740
+ onError: (error) => onError?.(error),
741
+ onSuccess: (data) => onSuccess?.(data),
742
+ onSettled: () => onSettled?.(),
743
+ });
744
+ };
745
+
746
+ const submitInvoice = (data, { config, onFetching, onSuccess, onError, onSettled, }) => {
747
+ return handler$1(post(getUrl("accounting", "v1", "submit_invoice"), data, config), {
748
+ onFetching: () => onFetching?.(),
749
+ onError: (error) => onError?.(error),
750
+ onSuccess: (data) => onSuccess?.(data),
751
+ onSettled: () => onSettled?.(),
752
+ });
753
+ };
754
+
755
+ const updateInvoice = (data, { config, onFetching, onSuccess, onError, onSettled, }) => {
756
+ return handler$1(put(getUrl("accounting", "v1", "invoice"), data, config), {
757
+ onFetching: () => onFetching?.(),
758
+ onError: (error) => onError?.(error),
759
+ onSuccess: (data) => onSuccess?.(data),
760
+ onSettled: () => onSettled?.(),
761
+ });
762
+ };
763
+
764
+ const Accounting = {
765
+ item: (slug) => get(getUrl("accounting", "v1", "item"), {
766
+ params: {
767
+ slug,
768
+ },
769
+ }),
770
+ items: (config) => get(getUrl("accounting", "v1", "items"), config),
771
+ createInvoice,
772
+ updateInvoice,
773
+ invoices: (config) => get(getUrl("accounting", "v1", "invoices"), config),
774
+ submitInvoice,
775
+ itemCategories: () => get(getUrl("accounting", "v1", "item_categories")),
776
+ itemBrands: () => get(getUrl("accounting", "v1", "item_brands")),
777
+ };
778
+
779
+ const newsletter = (data, { config, onFetching, onSuccess, onError, onSettled, }) => {
780
+ return handler$1(post(getUrl("support", "v1", "newsletter"), data, config), {
781
+ onFetching: () => onFetching?.(),
782
+ onError: (error) => onError?.(error),
783
+ onSuccess: (data) => onSuccess?.(data),
784
+ onSettled: () => onSettled?.(),
785
+ });
786
+ };
787
+
788
+ const ticket = (data, { config, onFetching, onSuccess, onError, onSettled, }) => {
789
+ return handler$1(post(getUrl("support", "v1", "ticket"), data, config), {
790
+ onFetching: () => onFetching?.(),
791
+ onError: (error) => onError?.(error),
792
+ onSuccess: (data) => onSuccess?.(data),
793
+ onSettled: () => onSettled?.(),
794
+ });
795
+ };
796
+
797
+ const Support = {
798
+ ticket,
799
+ newsletter,
800
+ tickets: (config) => get(getUrl("support", "v1", "tickets"), config),
801
+ };
802
+
803
+ const Assets = {
804
+ images: {
805
+ imagePlaceholder: getConfig().apiUrl + getUrl("assets", "v1", "imagePlaceholder"),
806
+ avatar: getConfig().apiUrl + getUrl("assets", "v1", "avatar"),
807
+ },
808
+ };
809
+
810
+ const updateProfile = (data, { config, onFetching, onSuccess, onError, onSettled }) => {
811
+ return handler$1(put(getUrl("account", "v1", "profile"), data, config), {
812
+ onFetching: () => onFetching?.(),
813
+ onError: (error) => onError?.(error),
814
+ onSuccess: (data) => onSuccess?.(data),
815
+ onSettled: () => onSettled?.(),
816
+ });
817
+ };
818
+
819
+ const Account = {
820
+ profile: (id) => get(getUrl("account", "v1", "profile"), {
821
+ params: {
822
+ id,
823
+ },
824
+ }),
825
+ updateProfile,
826
+ };
827
+
828
+ function shareUrl(title, url) {
829
+ // URL encoding to ensure special characters are handled properly
830
+ const encodedTitle = encodeURIComponent(title);
831
+ const encodedUrl = encodeURIComponent(url);
832
+ const target = "_blank";
833
+ const dimension = "width=600,height=400";
834
+ // Social media share URLs
835
+ const shareLinks = {
836
+ facebook: `https://www.facebook.com/sharer/sharer.php?u=${encodedUrl}`,
837
+ twitter: `https://twitter.com/intent/tweet?text=${encodedTitle}&url=${encodedUrl}`,
838
+ linkedin: `https://www.linkedin.com/sharing/share-offsite/?url=${encodedUrl}`,
839
+ whatsapp: `https://api.whatsapp.com/send?text=${encodedTitle} ${encodedUrl}`,
840
+ pinterest: `https://www.pinterest.com/pin/create/button/?url=${encodedUrl}&description=${encodedTitle}`,
841
+ };
842
+ return {
843
+ facebook: () => window.open(shareLinks.facebook, target, dimension),
844
+ twitter: () => window.open(shareLinks.twitter, target, dimension),
845
+ linkedin: () => window.open(shareLinks.linkedin, target, dimension),
846
+ whatsapp: () => window.open(shareLinks.whatsapp, target, dimension),
847
+ pinterest: () => window.open(shareLinks.pinterest, target, dimension),
848
+ };
849
+ }
850
+
851
+ function addLead(data, { config = null, onLoading = () => { }, onSuccess = () => { }, onError = () => { }, onSettled = () => { }, } = {}) {
852
+ return handler({
853
+ promise: post(getUrl("sales", "v1", "addLead"), {
854
+ ...data
855
+ }, config || undefined),
856
+ onLoading,
857
+ onError: (error) => onError(error),
858
+ onSuccess: (responseData) => {
859
+ onSuccess(responseData);
860
+ },
861
+ onSettled,
862
+ });
863
+ }
864
+
865
+ const Sales = {
866
+ addLead,
867
+ };
868
+
869
+ const Inventory = {
870
+ getStoreById: (id) => get(getUrl("inventory", "v1", "store"), {
871
+ params: {
872
+ id,
873
+ },
874
+ }),
875
+ getStoreBySlug: (slug) => get(getUrl("inventory", "v1", "store"), {
876
+ params: {
877
+ slug,
878
+ },
879
+ }),
880
+ getStoreProducts: (slug, category, brand, price, search) => get(getUrl("inventory", "v1", "store_products"), {
881
+ params: {
882
+ slug,
883
+ category,
884
+ brand,
885
+ price,
886
+ search,
887
+ },
888
+ }),
889
+ };
890
+
891
+ const exchangeRates = (data, { config, onFetching, onSuccess, onError, onSettled, }) => {
892
+ return handler$1(get(getUrl("tools", "v1", "exchangeRates"), config), {
893
+ onFetching: () => onFetching?.(),
894
+ onError: (error) => onError?.(error),
895
+ onSuccess: (data) => onSuccess?.(data),
896
+ onSettled: () => onSettled?.(),
897
+ });
898
+ };
899
+ // export async function convertCurrency(amount: number, fromCurrency?: string, toCurrency?: string) {
900
+ // try {
901
+ // const rates = await getExchangeRates(fromCurrency);
902
+ // if (!rates[toCurrency]) {
903
+ // throw new Error(`Currency ${toCurrency} is not available.`);
904
+ // }
905
+ // const convertedAmount = (amount * rates[toCurrency]).toFixed(2);
906
+ // return convertedAmount;
907
+ // } catch (error) {
908
+ // console.error('Error converting currency:', error);
909
+ // throw error;
910
+ // }
911
+ // }
912
+
913
+ const Tools = {
914
+ exchangeRates,
915
+ };
916
+
917
+ const shortUrl = (data, { config, onFetching, onSuccess, onError, onSettled, }) => {
918
+ return handler$1(linkiePost(getUrl("linkie", "v1", "shorten", true), data, config), {
919
+ onFetching: () => onFetching?.(),
920
+ onError: (error) => onError?.(error),
921
+ onSuccess: (data) => onSuccess?.(data),
922
+ onSettled: () => onSettled?.(),
923
+ });
924
+ };
925
+
926
+ // import cookie from "js-cookie";
927
+ // import { jwtDecode } from "jwt-decode";
928
+ // import type { NextPageContext } from "next";
929
+ // import { getConfig } from "../config/index";
930
+ // import { isAuth } from "../utils/auth";
931
+ // import {
932
+ // getDataFromStorage,
933
+ // setDataInStorage,
934
+ // setEncryptionKey,
935
+ // } from "../utils/localStorage";
936
+ const Linkie = {
937
+ shortUrl
938
+ };
939
+
940
+ const getCities = ({ config, onFetching, onSuccess, onError, onSettled }) => {
941
+ return handler$1(get(`${getConfig().apisUrl}/api/countries/v1/city`, config), {
942
+ onFetching: () => onFetching?.(),
943
+ onError: (error) => onError?.(error),
944
+ onSuccess: (data) => onSuccess?.(data),
945
+ onSettled: () => onSettled?.(),
946
+ });
947
+ };
948
+
949
+ const getCountries = ({ config, onFetching, onSuccess, onError, onSettled }) => {
950
+ return handler$1(get(`${getConfig().apisUrl}/api/countries/v1`, config), {
951
+ onFetching: () => onFetching?.(),
952
+ onError: (error) => onError?.(error),
953
+ onSuccess: (data) => onSuccess?.(data),
954
+ onSettled: () => onSettled?.(),
955
+ });
956
+ };
957
+
958
+ const getStates = ({ config, onFetching, onSuccess, onError, onSettled }) => {
959
+ return handler$1(get(`${getConfig().apisUrl}/api/countries/v1/state`, config), {
960
+ onFetching: () => onFetching?.(),
961
+ onError: (error) => onError?.(error),
962
+ onSuccess: (data) => onSuccess?.(data),
963
+ onSettled: () => onSettled?.(),
964
+ });
965
+ };
966
+
967
+ const Apis = {
968
+ getCountries,
969
+ getStates,
970
+ getCities
971
+ };
972
+
973
+ export { Account, Accounting, Apis, Assets, Auth, Content, Inventory, Linkie, Order, Payment, Sales, Support, Tools, getConfig, getCookie, getUrl, initializeSDK, shareUrl };
974
+ //# sourceMappingURL=index.js.map