@helpdice/sdk 0.4.9 → 0.5.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.
Files changed (92) hide show
  1. package/dist/index.js +65 -23
  2. package/dist/index.js.map +1 -1
  3. package/dist/types/config/index.d.ts +2 -24
  4. package/dist/types/config/state.d.ts +31 -0
  5. package/dist/types/lms/endpoint.d.ts +1 -0
  6. package/dist/types/lms/enroll_course.d.ts +2 -2
  7. package/dist/types/lms/index.d.ts +13 -3
  8. package/dist/types/lms/post_course.d.ts +2 -2
  9. package/dist/types/lms/post_session.d.ts +12 -0
  10. package/dist/types/lms/types.d.ts +18 -4
  11. package/package.json +9 -9
  12. package/dist/cjs/account/endpoint.js +0 -8
  13. package/dist/cjs/account/index.js +0 -17
  14. package/dist/cjs/account/types.js +0 -2
  15. package/dist/cjs/account/update_profile.js +0 -17
  16. package/dist/cjs/accounting/createInvoice.js +0 -17
  17. package/dist/cjs/accounting/endpoint.js +0 -14
  18. package/dist/cjs/accounting/index.js +0 -25
  19. package/dist/cjs/accounting/submitInvoice.js +0 -17
  20. package/dist/cjs/accounting/types.js +0 -2
  21. package/dist/cjs/accounting/updateInvoice.js +0 -17
  22. package/dist/cjs/apis/cities.js +0 -17
  23. package/dist/cjs/apis/countries.js +0 -17
  24. package/dist/cjs/apis/index.js +0 -14
  25. package/dist/cjs/apis/states.js +0 -17
  26. package/dist/cjs/assets/endpoint.js +0 -9
  27. package/dist/cjs/assets/index.js +0 -11
  28. package/dist/cjs/auth/authWithKey.js +0 -17
  29. package/dist/cjs/auth/authWithToken.js +0 -17
  30. package/dist/cjs/auth/endpoint.js +0 -15
  31. package/dist/cjs/auth/index.js +0 -94
  32. package/dist/cjs/auth/logout.js +0 -22
  33. package/dist/cjs/auth/register.js +0 -17
  34. package/dist/cjs/auth/resetPassword.js +0 -17
  35. package/dist/cjs/auth/signInWithGoogle.js +0 -56
  36. package/dist/cjs/auth/signin.js +0 -17
  37. package/dist/cjs/auth/signup.js +0 -17
  38. package/dist/cjs/auth/types.js +0 -2
  39. package/dist/cjs/config/axios.js +0 -120
  40. package/dist/cjs/config/constants.js +0 -12
  41. package/dist/cjs/config/fetch.js +0 -37
  42. package/dist/cjs/config/handler.js +0 -32
  43. package/dist/cjs/config/index.js +0 -37
  44. package/dist/cjs/config/local-storage.js +0 -29
  45. package/dist/cjs/config/route.js +0 -47
  46. package/dist/cjs/config/validate.js +0 -15
  47. package/dist/cjs/content/endpoint.js +0 -17
  48. package/dist/cjs/content/index.js +0 -29
  49. package/dist/cjs/hooks/index.js +0 -10
  50. package/dist/cjs/hooks/useAuth.js +0 -23
  51. package/dist/cjs/hooks/usePrivate.js +0 -15
  52. package/dist/cjs/hooks/useUser.js +0 -15
  53. package/dist/cjs/index.js +0 -59
  54. package/dist/cjs/inventory/endpoint.js +0 -9
  55. package/dist/cjs/inventory/index.js +0 -26
  56. package/dist/cjs/linkie/endpoint.js +0 -8
  57. package/dist/cjs/linkie/index.js +0 -20
  58. package/dist/cjs/linkie/shortUrl.js +0 -17
  59. package/dist/cjs/linkie/types.js +0 -2
  60. package/dist/cjs/order/create.js +0 -17
  61. package/dist/cjs/order/endpoint.js +0 -8
  62. package/dist/cjs/order/index.js +0 -10
  63. package/dist/cjs/order/types.js +0 -2
  64. package/dist/cjs/payment/components/ProcessPayment.js +0 -266
  65. package/dist/cjs/payment/endpoint.js +0 -9
  66. package/dist/cjs/payment/index.js +0 -12
  67. package/dist/cjs/payment/start.js +0 -38
  68. package/dist/cjs/payment/types.js +0 -2
  69. package/dist/cjs/payment/verify.js +0 -17
  70. package/dist/cjs/sales/endpoint.js +0 -8
  71. package/dist/cjs/sales/index.js +0 -7
  72. package/dist/cjs/sales/lead.js +0 -22
  73. package/dist/cjs/sales/types.js +0 -17
  74. package/dist/cjs/support/endpoint.js +0 -10
  75. package/dist/cjs/support/index.js +0 -15
  76. package/dist/cjs/support/newsletter.js +0 -17
  77. package/dist/cjs/support/ticket.js +0 -17
  78. package/dist/cjs/tools/endpoint.js +0 -8
  79. package/dist/cjs/tools/exchangeRates.js +0 -30
  80. package/dist/cjs/tools/index.js +0 -10
  81. package/dist/cjs/types.js +0 -9
  82. package/dist/cjs/utils/auth.js +0 -23
  83. package/dist/cjs/utils/handler.js +0 -35
  84. package/dist/cjs/utils/localStorage.js +0 -137
  85. package/dist/cjs/utils/share.js +0 -25
  86. package/dist/types/config/local-storage.d.ts +0 -0
  87. package/dist/types/config/validate.d.ts +0 -4
  88. package/dist/types/hooks/index.d.ts +0 -1
  89. package/dist/types/hooks/useAuth.d.ts +0 -0
  90. package/dist/types/hooks/usePrivate.d.ts +0 -0
  91. package/dist/types/hooks/useUser.d.ts +0 -8
  92. package/dist/types/payment/components/ProcessPayment.d.ts +0 -0
package/dist/index.js CHANGED
@@ -5,18 +5,6 @@ import CryptoJS from 'crypto-js';
5
5
  import axios from 'axios';
6
6
  import { GoogleAuthProvider, getAuth, signInWithPopup } from 'firebase/auth';
7
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
8
  let config = {
21
9
  tokenKey: '',
22
10
  apiKey: null,
@@ -27,6 +15,17 @@ let config = {
27
15
  environment: 'production',
28
16
  firebase: undefined
29
17
  };
18
+ function validateConfig(requiredKeys) {
19
+ const config = getConfig();
20
+ const missingKeys = requiredKeys.filter((key) => {
21
+ return !config[key]; // null, undefined, empty string → treated as missing
22
+ });
23
+ if (missingKeys.length > 0) {
24
+ throw new Error(`SDK configuration error: Missing required config value(s): ${missingKeys.join(', ')}\n` +
25
+ '👉 Please ensure these keys are set using setConfig({ ... }) before making requests.');
26
+ }
27
+ return true;
28
+ }
30
29
  function initializeSDK(newConfig) {
31
30
  config = { ...config, ...newConfig };
32
31
  validateConfig(['apiKey', 'tokenKey']);
@@ -266,8 +265,7 @@ chttp.interceptors.request.use((config) => {
266
265
  config.headers["Content-Type"] = "application/json";
267
266
  config.headers['TODAY'] = YYYY_MM_DD(Date.now());
268
267
  config.headers.Authorization = localStorage.getItem(TOKEN_KEY) || "";
269
- config.headers["HB-API-KEY"] =
270
- `Bearer ${getConfig().apiKey}` || "";
268
+ config.headers["HB-API-KEY"] = `Bearer ${getConfig().apiKey}` || "";
271
269
  }
272
270
  return config;
273
271
  }, Promise.reject);
@@ -319,16 +317,44 @@ const lhttp = axios.create({
319
317
  });
320
318
  lhttp.interceptors.request.use((config) => {
321
319
  validateConfig(['apiKey', 'tokenKey', 'lmsUrl']);
322
- const { lmsUrl } = getConfig();
320
+ let reqConfig = null;
321
+ const { lmsUrl, lmsRequestInceptor } = getConfig();
323
322
  config.baseURL = lmsUrl;
324
- if (config.headers) {
325
- config.headers["Content-Type"] = "application/json";
326
- config.headers['TODAY'] = YYYY_MM_DD(Date.now());
327
- config.headers.Authorization = localStorage.getItem(TOKEN_KEY) || "";
328
- config.headers["HB-API-KEY"] = `Bearer ${getConfig().apiKey}` || "";
323
+ // if (config.headers) {
324
+ // config.headers["Content-Type"] = "application/json";
325
+ // config.headers['TODAY'] = YYYY_MM_DD(Date.now());
326
+ // config.headers.Authorization = localStorage.getItem(TOKEN_KEY) || "";
327
+ // config.headers["HB-API-KEY"] = `Bearer ${getConfig().apiKey}` || "";
328
+ // }
329
+ if (lmsRequestInceptor) {
330
+ reqConfig = lmsRequestInceptor(config);
329
331
  }
330
- return config;
332
+ else {
333
+ reqConfig = config;
334
+ }
335
+ return reqConfig;
331
336
  }, Promise.reject);
337
+ lhttp.interceptors.response.use((response) => {
338
+ let resConfig = null;
339
+ const { lmsResponseInterceptor } = getConfig();
340
+ if (lmsResponseInterceptor) {
341
+ resConfig = lmsResponseInterceptor(response);
342
+ }
343
+ else {
344
+ resConfig = response;
345
+ }
346
+ return resConfig;
347
+ }, async (error) => {
348
+ let resError = null;
349
+ const { lmsErrorInterceptor } = getConfig();
350
+ if (lmsErrorInterceptor) {
351
+ resError = lmsErrorInterceptor(error);
352
+ }
353
+ else {
354
+ resError = error;
355
+ }
356
+ return Promise.reject(resError);
357
+ });
332
358
  const lmsPost = (endpoint, data, config) => new Promise((resolve, reject) => lhttp
333
359
  .post(endpoint, data, config)
334
360
  .then(resolve)
@@ -463,6 +489,7 @@ const lms = {
463
489
  modules: "courses/modules",
464
490
  courseSlug: "courses/slug",
465
491
  progress: "courses/progress",
492
+ session: "session",
466
493
  course: "courses/course",
467
494
  myCourses: "enrollments/my-courses",
468
495
  enrollCourse: "enrollments",
@@ -1171,7 +1198,7 @@ const Hr = {
1171
1198
  };
1172
1199
 
1173
1200
  const enrollCourse = (data, { config, onFetching, onSuccess, onError, onSettled }) => {
1174
- return handler$1(lmsPut(getUrl("lms", "v1", "enrollments", true), data, config), {
1201
+ return handler$1(lmsPut(getUrl("lms", "v1", "enrollCourse", true), data, config), {
1175
1202
  onFetching: () => onFetching?.(),
1176
1203
  onError: (error) => onError?.(error),
1177
1204
  onSuccess: (data) => onSuccess?.(data),
@@ -1206,6 +1233,15 @@ const postProgress = (data, { config, onFetching, onSuccess, onError, onSettled
1206
1233
  });
1207
1234
  };
1208
1235
 
1236
+ const postSession = (data, { config, onFetching, onSuccess, onError, onSettled }) => {
1237
+ return handler$1(lmsPost(getUrl("lms", "v1", "session", true), data, config), {
1238
+ onFetching: () => onFetching?.(),
1239
+ onError: (error) => onError?.(error),
1240
+ onSuccess: (data) => onSuccess?.(data),
1241
+ onSettled: () => onSettled?.(),
1242
+ });
1243
+ };
1244
+
1209
1245
  const LMS = {
1210
1246
  getCourseById: (id) => lmsGet(getUrl("lms", "v1", "course", true), {
1211
1247
  params: {
@@ -1236,10 +1272,16 @@ const LMS = {
1236
1272
  id,
1237
1273
  },
1238
1274
  }),
1275
+ getUserSession: (id) => lmsGet(getUrl("lms", "v1", "session", true), {
1276
+ params: {
1277
+ id,
1278
+ },
1279
+ }),
1239
1280
  postCourse,
1240
1281
  postModule,
1241
1282
  postProgress,
1242
- enrollCourse
1283
+ enrollCourse,
1284
+ postSession
1243
1285
  };
1244
1286
 
1245
1287
  export { Account, Accounting, Apis, App, Assets, Auth, Content, Hr, Inventory, LMS, Linkie, Order, Payment, Sales, Support, Tools, getConfig, getCookie, getUrl, initializeSDK, handler as requestHandler, shareUrl };