acsi-core 1.0.0 → 1.1.1

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.
@@ -1,5 +1,5 @@
1
- export declare const getGoogleClientId: () => Promise<import("axios").AxiosResponse<any, any>>;
2
- export declare const apiLoginGoogle: (body: any) => Promise<import("axios").AxiosResponse<any, any>>;
3
- export declare const apiSendEmailCode: (body: any) => Promise<import("axios").AxiosResponse<any, any>>;
4
- export declare const apiCheckEmailCode: (params: any) => Promise<import("axios").AxiosResponse<any, any>>;
5
- export declare const apiGetImage: () => Promise<import("axios").AxiosResponse<any, any>>;
1
+ export declare const getGoogleClientId: () => Promise<import("axios").AxiosResponse<any, any, {}>>;
2
+ export declare const apiLoginGoogle: (body: any) => Promise<import("axios").AxiosResponse<any, any, {}>>;
3
+ export declare const apiSendEmailCode: (body: any) => Promise<import("axios").AxiosResponse<any, any, {}>>;
4
+ export declare const apiCheckEmailCode: (params: any) => Promise<import("axios").AxiosResponse<any, any, {}>>;
5
+ export declare const apiGetImage: () => Promise<import("axios").AxiosResponse<any, any, {}>>;
package/dist/index.js CHANGED
@@ -20,14 +20,15 @@ var rehypeRaw = _interopDefault(require('rehype-raw'));
20
20
  require('katex/dist/katex.min.css');
21
21
  var Cookies = _interopDefault(require('js-cookie'));
22
22
  var moment = _interopDefault(require('moment'));
23
+ var msalBrowser = require('@azure/msal-browser');
23
24
  var reactToastify = require('react-toastify');
24
25
  var reactGoogleLogin = require('@leecheuk/react-google-login');
25
26
  var material = require('@mui/material');
26
- require('@azure/msal-browser');
27
27
  var amplitude = require('@amplitude/analytics-browser');
28
28
  var Sentry = require('@sentry/react');
29
29
  var fa = require('react-icons/fa');
30
30
  var CreatableSelect = _interopDefault(require('react-select/creatable'));
31
+ var moment$1 = _interopDefault(require('moment-timezone'));
31
32
 
32
33
  var setLoading = toolkit.createAction("common/setLoading");
33
34
  var setLoadingPage = toolkit.createAction("common/setLoadingPage");
@@ -57,6 +58,7 @@ var PUSHER_CONFIG = {
57
58
  };
58
59
  var MICROSOFT_CLIENT_ID = process.env.REACT_APP_MICROSOFT_CLIENT_ID || "";
59
60
  var MICROSOFT_URL_DIRECT = process.env.REACT_APP_MICROSOFT_URL_DIRECT || "";
61
+ var MICROSOFT_SSO_ENABLED = process.env.REACT_APP_MICROSOFT_SSO_ENABLED || "false";
60
62
  var OPENSALT_BASE_URL = process.env.REACT_APP_OPENSALT || "";
61
63
  var ACCESS_TOKEN = "ACCESS_TOKEN";
62
64
  var AUTH_COOKIE = "auth";
@@ -88,25 +90,6 @@ var ORGANIZATION_TEAM = "ORGANIZATION_TEAM";
88
90
 
89
91
  var styleGlobal = {"signup_wrap":"_1KLz9","box-signin":"_2Jo1o","signin_title":"_3egBO","signup_link":"_1DoIT","google_button":"_34hK_","microsoft_button":"_19ESb","box-field":"_2e9xO","box-input":"_3zXRp","box-text":"_8NJga","box-button-email":"_21FPk","box-signin-container":"_1QERu","box-signin-text":"_2-znH","box-signin-logo":"_1aB2m","box-right":"_3qndF","image-slideshow":"_1aM7m","active":"_Vx1zf","box-right-body":"_JzdCr","box-right-footer":"_19aCA","pr-30":"_2HB5r","width-400":"_4ehXP"};
90
92
 
91
- // A type of promise-like that resolves synchronously and supports only one observer
92
-
93
- const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";
94
-
95
- const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";
96
-
97
- // Asynchronously call a function and send errors to recovery continuation
98
- function _catch(body, recover) {
99
- try {
100
- var result = body();
101
- } catch(e) {
102
- return recover(e);
103
- }
104
- if (result && result.then) {
105
- return result.then(void 0, recover);
106
- }
107
- return result;
108
- }
109
-
110
93
  function _arrayLikeToArray(r, a) {
111
94
  (null == a || a > r.length) && (a = r.length);
112
95
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
@@ -155,6 +138,25 @@ function _unsupportedIterableToArray(r, a) {
155
138
  }
156
139
  }
157
140
 
141
+ // A type of promise-like that resolves synchronously and supports only one observer
142
+
143
+ const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";
144
+
145
+ const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";
146
+
147
+ // Asynchronously call a function and send errors to recovery continuation
148
+ function _catch(body, recover) {
149
+ try {
150
+ var result = body();
151
+ } catch(e) {
152
+ return recover(e);
153
+ }
154
+ if (result && result.then) {
155
+ return result.then(void 0, recover);
156
+ }
157
+ return result;
158
+ }
159
+
158
160
  var styles = {"core-button":"_xvNBN","primary":"_U9Qyp","secondary":"_1VzMy","text":"_pZNuj","danger":"_2uYm1","light":"_wxH5S"};
159
161
 
160
162
  var _excluded = ["type", "children", "onClick", "icon", "disabled", "htmlType"];
@@ -1746,6 +1748,55 @@ var TypeLogin;
1746
1748
  TypeLogin[TypeLogin["Microsoft"] = 3] = "Microsoft";
1747
1749
  })(TypeLogin || (TypeLogin = {}));
1748
1750
 
1751
+ var AuthenticationMessage;
1752
+ (function (AuthenticationMessage) {
1753
+ AuthenticationMessage["NotAllowedToRegister"] = "NotAllowedToRegister";
1754
+ AuthenticationMessage["InvalidGoogleToken"] = "InvalidGoogleToken";
1755
+ })(AuthenticationMessage || (AuthenticationMessage = {}));
1756
+ (function (Role) {
1757
+ Role["Student"] = "Student";
1758
+ Role["Teacher"] = "Teacher";
1759
+ Role["Admin"] = "Admin";
1760
+ })(exports.Role || (exports.Role = {}));
1761
+ var msalConfig = function msalConfig(clientId, redirectUri) {
1762
+ return {
1763
+ auth: {
1764
+ clientId: clientId,
1765
+ authority: "https://login.microsoftonline.com/common",
1766
+ redirectUri: redirectUri
1767
+ },
1768
+ cache: {
1769
+ cacheLocation: "sessionStorage",
1770
+ storeAuthStateInCookie: false
1771
+ },
1772
+ system: {
1773
+ loggerOptions: {
1774
+ loggerCallback: function loggerCallback(level, message, containsPii) {
1775
+ if (containsPii) {
1776
+ return;
1777
+ }
1778
+ switch (level) {
1779
+ case msalBrowser.LogLevel.Error:
1780
+ console.error(message);
1781
+ return;
1782
+ case msalBrowser.LogLevel.Info:
1783
+ console.info(message);
1784
+ return;
1785
+ case msalBrowser.LogLevel.Verbose:
1786
+ console.debug(message);
1787
+ return;
1788
+ case msalBrowser.LogLevel.Warning:
1789
+ console.warn(message);
1790
+ return;
1791
+ default:
1792
+ return;
1793
+ }
1794
+ }
1795
+ }
1796
+ }
1797
+ };
1798
+ };
1799
+
1749
1800
  var BlockLogin = function BlockLogin(_ref) {
1750
1801
  var onNavigate = _ref.onNavigate,
1751
1802
  role = _ref.role,
@@ -1880,6 +1931,91 @@ var BlockLogin = function BlockLogin(_ref) {
1880
1931
  return console.log(errorResponse);
1881
1932
  }
1882
1933
  });
1934
+ var fnLoginMicrosoft = function fnLoginMicrosoft() {
1935
+ try {
1936
+ var msalInstance = new msalBrowser.PublicClientApplication(msalConfig(MICROSOFT_CLIENT_ID, MICROSOFT_URL_DIRECT));
1937
+ if (!msalInstance) {
1938
+ console.error("MSAL instance not initialized");
1939
+ return Promise.resolve();
1940
+ }
1941
+ return Promise.resolve(_catch(function () {
1942
+ return Promise.resolve(msalInstance.initialize()).then(function () {
1943
+ var loginRequest = {
1944
+ scopes: ["openid", "profile", "email"]
1945
+ };
1946
+ var silentRequest = _extends({}, loginRequest, {
1947
+ prompt: "select_account"
1948
+ });
1949
+ return Promise.resolve(msalInstance.loginPopup(silentRequest)).then(function (response) {
1950
+ return function () {
1951
+ if (response && response.account) {
1952
+ var account = response.account;
1953
+ var fullName = (account === null || account === void 0 ? void 0 : account.name) || "";
1954
+ var infoLogin = {
1955
+ firstName: fullName.split(' ').slice(0, -1).join(' '),
1956
+ lastName: fullName.split(' ').slice(-1).join(' '),
1957
+ fullName: fullName,
1958
+ imageUrl: "",
1959
+ email: (account === null || account === void 0 ? void 0 : account.username) || "",
1960
+ token: (response === null || response === void 0 ? void 0 : response.accessToken) || "",
1961
+ googleId: (account === null || account === void 0 ? void 0 : account.homeAccountId) || "",
1962
+ role: role,
1963
+ type: TypeLogin.Microsoft
1964
+ };
1965
+ dispatch(setLoading(true));
1966
+ return Promise.resolve(apiLoginGoogle(infoLogin)).then(function (authResult) {
1967
+ var _authResult$data2;
1968
+ if (((_authResult$data2 = authResult.data) === null || _authResult$data2 === void 0 ? void 0 : _authResult$data2.id) == null) {
1969
+ dispatch(setLoading(false));
1970
+ alert("Please contact admin.");
1971
+ return;
1972
+ }
1973
+ localStorage.clear();
1974
+ var tokenJWT = authResult.data.token;
1975
+ trackEvent === null || trackEvent === void 0 ? void 0 : trackEvent({
1976
+ eventName: exports.AmplitudeEvent.LOGIN,
1977
+ eventProperties: {
1978
+ email: email,
1979
+ login_method: 'microsoft',
1980
+ user_role: authResult.data.role,
1981
+ success: true,
1982
+ timestamp: new Date().toISOString()
1983
+ }
1984
+ });
1985
+ if (role === "LandingPage") {
1986
+ CookieService.setAuthCookie({
1987
+ token: tokenJWT,
1988
+ expiresAt: Date.now() + 24 * 60 * 60 * 1000
1989
+ });
1990
+ var getRedirectUrl = function getRedirectUrl(role) {
1991
+ switch (role) {
1992
+ case "Admin":
1993
+ return ADMIN_ORIGIN;
1994
+ case "Teacher":
1995
+ return TEACHER_ORIGIN;
1996
+ default:
1997
+ return role + "." + REQUEST_ORIGIN;
1998
+ }
1999
+ };
2000
+ var redirectUrl = getRedirectUrl(authResult.data.role);
2001
+ window.location.href = redirectUrl + "/dashboard";
2002
+ dispatch(setLoading(false));
2003
+ }
2004
+ localStorage.setItem(ACCESS_TOKEN, tokenJWT);
2005
+ onNavigate("/dashboard");
2006
+ dispatch(setLoading(false));
2007
+ });
2008
+ }
2009
+ }();
2010
+ });
2011
+ });
2012
+ }, function (error) {
2013
+ console.error("Microsoft login error:", error);
2014
+ }));
2015
+ } catch (e) {
2016
+ return Promise.reject(e);
2017
+ }
2018
+ };
1883
2019
  React__default.useEffect(function () {
1884
2020
  return function () {
1885
2021
  if (resendTimer) {
@@ -1987,7 +2123,18 @@ var BlockLogin = function BlockLogin(_ref) {
1987
2123
  height: 24,
1988
2124
  alt: "Google sign-in",
1989
2125
  src: "/images/icons/Google__G__logo.png"
1990
- }), "Sign in with Google")), React__default.createElement("span", {
2126
+ }), "Sign in with Google")), MICROSOFT_SSO_ENABLED === "true" && React__default.createElement("div", {
2127
+ className: "" + styleGlobal["microsoft_button"]
2128
+ }, React__default.createElement("button", {
2129
+ onClick: function onClick() {
2130
+ return fnLoginMicrosoft();
2131
+ }
2132
+ }, React__default.createElement("img", {
2133
+ width: 24,
2134
+ height: 24,
2135
+ alt: "Google sign-in",
2136
+ src: "/images/Single-Sign-On-logo.png"
2137
+ }), "Sign in with Microsoft")), React__default.createElement("span", {
1991
2138
  className: "" + styleGlobal["box-field"]
1992
2139
  }, "OR"), React__default.createElement("div", {
1993
2140
  className: "" + styleGlobal["box-input"]
@@ -2820,17 +2967,6 @@ var CommonDialog = function CommonDialog(_ref) {
2820
2967
  }, title)), children);
2821
2968
  };
2822
2969
 
2823
- var AuthenticationMessage;
2824
- (function (AuthenticationMessage) {
2825
- AuthenticationMessage["NotAllowedToRegister"] = "NotAllowedToRegister";
2826
- AuthenticationMessage["InvalidGoogleToken"] = "InvalidGoogleToken";
2827
- })(AuthenticationMessage || (AuthenticationMessage = {}));
2828
- (function (Role) {
2829
- Role["Student"] = "Student";
2830
- Role["Teacher"] = "Teacher";
2831
- Role["Admin"] = "Admin";
2832
- })(exports.Role || (exports.Role = {}));
2833
-
2834
2970
  var CustomPagination = function CustomPagination(_ref) {
2835
2971
  var currentPage = _ref.currentPage,
2836
2972
  totalPage = _ref.totalPage,
@@ -3333,13 +3469,19 @@ var utcToLocalTime = (function (time, FORMAT) {
3333
3469
  }
3334
3470
  });
3335
3471
 
3336
- var timeSpanToLocalMoment = (function (time) {
3472
+ var timeSpanToLocalMoment = (function (time, timezone) {
3473
+ if (timezone === void 0) {
3474
+ timezone = "UTC";
3475
+ }
3337
3476
  if (!time) return null;
3338
- var times = time.split(":");
3339
- if (times.length !== 3) return null;
3340
- var totalSeconds = +times[0] * 60 * 60 + +times[1] * 60 + +times[2];
3341
- var startOfDay = moment.utc().startOf("day");
3342
- var dateTime = startOfDay.add(totalSeconds, "seconds");
3477
+ if (time.split(":").length !== 3) return null;
3478
+ var dateTime;
3479
+ var isOffset = /^(UTC|GMT)?[+-]/.test(timezone);
3480
+ if (isOffset) {
3481
+ dateTime = moment$1.utc(time, "HH:mm:ss").utcOffset(timezone);
3482
+ } else {
3483
+ dateTime = moment$1.tz(time, "HH:mm:ss", timezone);
3484
+ }
3343
3485
  return dateTime.local();
3344
3486
  });
3345
3487