@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.
- package/dist/index.js +65 -23
- package/dist/index.js.map +1 -1
- package/dist/types/config/index.d.ts +2 -24
- package/dist/types/config/state.d.ts +31 -0
- package/dist/types/lms/endpoint.d.ts +1 -0
- package/dist/types/lms/enroll_course.d.ts +2 -2
- package/dist/types/lms/index.d.ts +13 -3
- package/dist/types/lms/post_course.d.ts +2 -2
- package/dist/types/lms/post_session.d.ts +12 -0
- package/dist/types/lms/types.d.ts +18 -4
- package/package.json +9 -9
- package/dist/cjs/account/endpoint.js +0 -8
- package/dist/cjs/account/index.js +0 -17
- package/dist/cjs/account/types.js +0 -2
- package/dist/cjs/account/update_profile.js +0 -17
- package/dist/cjs/accounting/createInvoice.js +0 -17
- package/dist/cjs/accounting/endpoint.js +0 -14
- package/dist/cjs/accounting/index.js +0 -25
- package/dist/cjs/accounting/submitInvoice.js +0 -17
- package/dist/cjs/accounting/types.js +0 -2
- package/dist/cjs/accounting/updateInvoice.js +0 -17
- package/dist/cjs/apis/cities.js +0 -17
- package/dist/cjs/apis/countries.js +0 -17
- package/dist/cjs/apis/index.js +0 -14
- package/dist/cjs/apis/states.js +0 -17
- package/dist/cjs/assets/endpoint.js +0 -9
- package/dist/cjs/assets/index.js +0 -11
- package/dist/cjs/auth/authWithKey.js +0 -17
- package/dist/cjs/auth/authWithToken.js +0 -17
- package/dist/cjs/auth/endpoint.js +0 -15
- package/dist/cjs/auth/index.js +0 -94
- package/dist/cjs/auth/logout.js +0 -22
- package/dist/cjs/auth/register.js +0 -17
- package/dist/cjs/auth/resetPassword.js +0 -17
- package/dist/cjs/auth/signInWithGoogle.js +0 -56
- package/dist/cjs/auth/signin.js +0 -17
- package/dist/cjs/auth/signup.js +0 -17
- package/dist/cjs/auth/types.js +0 -2
- package/dist/cjs/config/axios.js +0 -120
- package/dist/cjs/config/constants.js +0 -12
- package/dist/cjs/config/fetch.js +0 -37
- package/dist/cjs/config/handler.js +0 -32
- package/dist/cjs/config/index.js +0 -37
- package/dist/cjs/config/local-storage.js +0 -29
- package/dist/cjs/config/route.js +0 -47
- package/dist/cjs/config/validate.js +0 -15
- package/dist/cjs/content/endpoint.js +0 -17
- package/dist/cjs/content/index.js +0 -29
- package/dist/cjs/hooks/index.js +0 -10
- package/dist/cjs/hooks/useAuth.js +0 -23
- package/dist/cjs/hooks/usePrivate.js +0 -15
- package/dist/cjs/hooks/useUser.js +0 -15
- package/dist/cjs/index.js +0 -59
- package/dist/cjs/inventory/endpoint.js +0 -9
- package/dist/cjs/inventory/index.js +0 -26
- package/dist/cjs/linkie/endpoint.js +0 -8
- package/dist/cjs/linkie/index.js +0 -20
- package/dist/cjs/linkie/shortUrl.js +0 -17
- package/dist/cjs/linkie/types.js +0 -2
- package/dist/cjs/order/create.js +0 -17
- package/dist/cjs/order/endpoint.js +0 -8
- package/dist/cjs/order/index.js +0 -10
- package/dist/cjs/order/types.js +0 -2
- package/dist/cjs/payment/components/ProcessPayment.js +0 -266
- package/dist/cjs/payment/endpoint.js +0 -9
- package/dist/cjs/payment/index.js +0 -12
- package/dist/cjs/payment/start.js +0 -38
- package/dist/cjs/payment/types.js +0 -2
- package/dist/cjs/payment/verify.js +0 -17
- package/dist/cjs/sales/endpoint.js +0 -8
- package/dist/cjs/sales/index.js +0 -7
- package/dist/cjs/sales/lead.js +0 -22
- package/dist/cjs/sales/types.js +0 -17
- package/dist/cjs/support/endpoint.js +0 -10
- package/dist/cjs/support/index.js +0 -15
- package/dist/cjs/support/newsletter.js +0 -17
- package/dist/cjs/support/ticket.js +0 -17
- package/dist/cjs/tools/endpoint.js +0 -8
- package/dist/cjs/tools/exchangeRates.js +0 -30
- package/dist/cjs/tools/index.js +0 -10
- package/dist/cjs/types.js +0 -9
- package/dist/cjs/utils/auth.js +0 -23
- package/dist/cjs/utils/handler.js +0 -35
- package/dist/cjs/utils/localStorage.js +0 -137
- package/dist/cjs/utils/share.js +0 -25
- package/dist/types/config/local-storage.d.ts +0 -0
- package/dist/types/config/validate.d.ts +0 -4
- package/dist/types/hooks/index.d.ts +0 -1
- package/dist/types/hooks/useAuth.d.ts +0 -0
- package/dist/types/hooks/usePrivate.d.ts +0 -0
- package/dist/types/hooks/useUser.d.ts +0 -8
- 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
|
-
|
|
320
|
+
let reqConfig = null;
|
|
321
|
+
const { lmsUrl, lmsRequestInceptor } = getConfig();
|
|
323
322
|
config.baseURL = lmsUrl;
|
|
324
|
-
if (config.headers) {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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
|
-
|
|
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", "
|
|
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 };
|