powr-sdk-web 6.11.0 → 6.12.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.
- package/dist/config.js +8 -1
- package/dist/index.js +12 -0
- package/dist/onboarding/utils.js +6 -4
- package/dist/sso/api.js +28 -0
- package/dist/sso/index.js +12 -0
- package/dist/sso/openPowrLogin.js +1 -7
- package/dist/utils/auth.js +3 -6
- package/package.json +1 -1
package/dist/config.js
CHANGED
|
@@ -7,5 +7,12 @@ var config = {
|
|
|
7
7
|
powrUrl: process.env.NEXT_PUBLIC_POWR_URL,
|
|
8
8
|
defaultPowrUrl: DEFAULT_POWR_API_URL
|
|
9
9
|
};
|
|
10
|
+
|
|
11
|
+
/** Prop, then NEXT_PUBLIC_POWR_URL, then the stable host. Empty prop must not become the URL "undefined". */
|
|
12
|
+
function resolvePowrApiUrl(apiUrl) {
|
|
13
|
+
var raw = apiUrl || config.powrUrl || config.defaultPowrUrl || "";
|
|
14
|
+
return String(raw).replace(/\/$/, "");
|
|
15
|
+
}
|
|
10
16
|
module.exports = config;
|
|
11
|
-
module.exports.DEFAULT_POWR_API_URL = DEFAULT_POWR_API_URL;
|
|
17
|
+
module.exports.DEFAULT_POWR_API_URL = DEFAULT_POWR_API_URL;
|
|
18
|
+
module.exports.resolvePowrApiUrl = resolvePowrApiUrl;
|
package/dist/index.js
CHANGED
|
@@ -405,6 +405,12 @@ Object.defineProperty(exports, "coercePhoneForStorage", {
|
|
|
405
405
|
return _phone.coercePhoneForStorage;
|
|
406
406
|
}
|
|
407
407
|
});
|
|
408
|
+
Object.defineProperty(exports, "currentReturnPath", {
|
|
409
|
+
enumerable: true,
|
|
410
|
+
get: function get() {
|
|
411
|
+
return _sso.currentReturnPath;
|
|
412
|
+
}
|
|
413
|
+
});
|
|
408
414
|
Object.defineProperty(exports, "defineAppStep", {
|
|
409
415
|
enumerable: true,
|
|
410
416
|
get: function get() {
|
|
@@ -519,6 +525,12 @@ Object.defineProperty(exports, "issueLoginCode", {
|
|
|
519
525
|
return _sso.issueLoginCode;
|
|
520
526
|
}
|
|
521
527
|
});
|
|
528
|
+
Object.defineProperty(exports, "loginHrefWithNext", {
|
|
529
|
+
enumerable: true,
|
|
530
|
+
get: function get() {
|
|
531
|
+
return _sso.loginHrefWithNext;
|
|
532
|
+
}
|
|
533
|
+
});
|
|
522
534
|
Object.defineProperty(exports, "loginWithCode", {
|
|
523
535
|
enumerable: true,
|
|
524
536
|
get: function get() {
|
package/dist/onboarding/utils.js
CHANGED
|
@@ -111,6 +111,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
111
111
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
112
112
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
113
113
|
function _toPrimitive(t, e) { if ("object" != _typeof(t) || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
|
|
114
|
+
var config = require('../config');
|
|
114
115
|
function getUserId(user) {
|
|
115
116
|
if (!user) return null;
|
|
116
117
|
var id = user.powrId || user._id || user.id;
|
|
@@ -267,7 +268,7 @@ function _refreshAccessToken() {
|
|
|
267
268
|
}
|
|
268
269
|
});
|
|
269
270
|
case 1:
|
|
270
|
-
url = "".concat(apiUrl, "/auth/refresh-token?projectId=").concat(projectId);
|
|
271
|
+
url = "".concat(config.resolvePowrApiUrl(apiUrl), "/auth/refresh-token?projectId=").concat(projectId);
|
|
271
272
|
_context3.n = 2;
|
|
272
273
|
return fetch(url, {
|
|
273
274
|
method: 'POST',
|
|
@@ -310,19 +311,20 @@ function updatePowrUser(_x5) {
|
|
|
310
311
|
}
|
|
311
312
|
function _updatePowrUser() {
|
|
312
313
|
_updatePowrUser = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(_ref2) {
|
|
313
|
-
var apiUrl, projectId, userId, token, refreshToken, body, onTokenRefreshed, activeToken, putUser, response, data, refreshed;
|
|
314
|
+
var apiUrl, projectId, userId, token, refreshToken, body, onTokenRefreshed, activeToken, host, putUser, response, data, refreshed;
|
|
314
315
|
return _regenerator().w(function (_context5) {
|
|
315
316
|
while (1) switch (_context5.n) {
|
|
316
317
|
case 0:
|
|
317
318
|
apiUrl = _ref2.apiUrl, projectId = _ref2.projectId, userId = _ref2.userId, token = _ref2.token, refreshToken = _ref2.refreshToken, body = _ref2.body, onTokenRefreshed = _ref2.onTokenRefreshed;
|
|
318
319
|
activeToken = token;
|
|
320
|
+
host = config.resolvePowrApiUrl(apiUrl);
|
|
319
321
|
putUser = /*#__PURE__*/function () {
|
|
320
322
|
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
|
|
321
323
|
var url;
|
|
322
324
|
return _regenerator().w(function (_context4) {
|
|
323
325
|
while (1) switch (_context4.n) {
|
|
324
326
|
case 0:
|
|
325
|
-
url = "".concat(
|
|
327
|
+
url = "".concat(host, "/users/").concat(userId, "?projectId=").concat(projectId);
|
|
326
328
|
return _context4.a(2, fetch(url, {
|
|
327
329
|
method: 'PUT',
|
|
328
330
|
headers: {
|
|
@@ -354,7 +356,7 @@ function _updatePowrUser() {
|
|
|
354
356
|
}
|
|
355
357
|
_context5.n = 3;
|
|
356
358
|
return refreshAccessToken({
|
|
357
|
-
apiUrl:
|
|
359
|
+
apiUrl: host,
|
|
358
360
|
projectId: projectId,
|
|
359
361
|
refreshToken: refreshToken
|
|
360
362
|
});
|
package/dist/sso/api.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.currentReturnPath = currentReturnPath;
|
|
6
7
|
exports.issueLoginCode = issueLoginCode;
|
|
8
|
+
exports.loginHrefWithNext = loginHrefWithNext;
|
|
7
9
|
exports.loginWithCode = loginWithCode;
|
|
8
10
|
exports.readHandoffParams = readHandoffParams;
|
|
9
11
|
exports.safeNextPath = safeNextPath;
|
|
@@ -27,6 +29,32 @@ function safeNextPath(next) {
|
|
|
27
29
|
return fallback;
|
|
28
30
|
}
|
|
29
31
|
|
|
32
|
+
/** Current path+search for return-after-login (browser only). */
|
|
33
|
+
function currentReturnPath() {
|
|
34
|
+
if (typeof window === "undefined") return "/";
|
|
35
|
+
return "".concat(window.location.pathname).concat(window.location.search || "");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Build `/login?next=…` so post-login can restore the deep link.
|
|
40
|
+
* Skips when already on login or `next` is empty/unsafe.
|
|
41
|
+
* @param {string} [returnPath] - defaults to currentReturnPath()
|
|
42
|
+
* @param {string} [loginPath="/login"]
|
|
43
|
+
*/
|
|
44
|
+
function loginHrefWithNext(returnPath) {
|
|
45
|
+
var loginPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "/login";
|
|
46
|
+
var login = loginPath || "/login";
|
|
47
|
+
var next = returnPath == null ? currentReturnPath() : String(returnPath || "");
|
|
48
|
+
if (!next || next === login || next.startsWith("".concat(login, "?")) || next.startsWith("".concat(login, "/"))) {
|
|
49
|
+
return login;
|
|
50
|
+
}
|
|
51
|
+
var safe = safeNextPath(next, "");
|
|
52
|
+
if (!safe || safe === login || safe.startsWith("".concat(login, "?")) || safe.startsWith("".concat(login, "/"))) {
|
|
53
|
+
return login;
|
|
54
|
+
}
|
|
55
|
+
return "".concat(login, "?next=").concat(encodeURIComponent(safe));
|
|
56
|
+
}
|
|
57
|
+
|
|
30
58
|
/**
|
|
31
59
|
* Issue a one-time login code (caller must already be authenticated).
|
|
32
60
|
* Host `injectProjectId` needs destination `projectId` on the body.
|
package/dist/sso/index.js
CHANGED
|
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "buildPowrSsoUrl", {
|
|
|
15
15
|
return _openPowrLogin.buildPowrSsoUrl;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "currentReturnPath", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _api.currentReturnPath;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
18
24
|
exports["default"] = PowrBaseSso;
|
|
19
25
|
Object.defineProperty(exports, "issueLoginCode", {
|
|
20
26
|
enumerable: true,
|
|
@@ -22,6 +28,12 @@ Object.defineProperty(exports, "issueLoginCode", {
|
|
|
22
28
|
return _api.issueLoginCode;
|
|
23
29
|
}
|
|
24
30
|
});
|
|
31
|
+
Object.defineProperty(exports, "loginHrefWithNext", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function get() {
|
|
34
|
+
return _api.loginHrefWithNext;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
25
37
|
Object.defineProperty(exports, "loginWithCode", {
|
|
26
38
|
enumerable: true,
|
|
27
39
|
get: function get() {
|
|
@@ -72,12 +72,6 @@ function parseDest(url) {
|
|
|
72
72
|
return null;
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
function resolvePowrApiUrl(apiUrl) {
|
|
76
|
-
if (apiUrl) return String(apiUrl).replace(/\/$/, "");
|
|
77
|
-
if (config.powrUrl) return String(config.powrUrl).replace(/\/$/, "");
|
|
78
|
-
if (config.defaultPowrUrl) return String(config.defaultPowrUrl).replace(/\/$/, "");
|
|
79
|
-
return "";
|
|
80
|
-
}
|
|
81
75
|
|
|
82
76
|
/**
|
|
83
77
|
* @param {string} url
|
|
@@ -163,7 +157,7 @@ function _openPowrLogin() {
|
|
|
163
157
|
apiUrl = options.apiUrl, projectIdOpt = options.projectId, origins = options.origins, _options$ssoPath = options.ssoPath, ssoPath = _options$ssoPath === void 0 ? "/sso" : _options$ssoPath, _options$onFallback = options.onFallback, onFallback = _options$onFallback === void 0 ? openPlain : _options$onFallback, _options$navigate = options.navigate, navigate = _options$navigate === void 0 ? function (ssoUrl) {
|
|
164
158
|
if (typeof window !== "undefined") window.location.assign(ssoUrl);
|
|
165
159
|
} : _options$navigate;
|
|
166
|
-
powrApi = resolvePowrApiUrl(apiUrl);
|
|
160
|
+
powrApi = config.resolvePowrApiUrl(apiUrl);
|
|
167
161
|
dest = matchPowrTarget(url, origins);
|
|
168
162
|
projectId = projectIdOpt || (dest === null || dest === void 0 ? void 0 : dest.projectId);
|
|
169
163
|
if (!(!dest || !token || !powrApi || !projectId)) {
|
package/dist/utils/auth.js
CHANGED
|
@@ -69,6 +69,7 @@ var createAuthHeaders = exports.createAuthHeaders = function createAuthHeaders()
|
|
|
69
69
|
var apiCall = exports.apiCall = /*#__PURE__*/function () {
|
|
70
70
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(apiUrl, endpoint, projectId) {
|
|
71
71
|
var options,
|
|
72
|
+
host,
|
|
72
73
|
url,
|
|
73
74
|
separator,
|
|
74
75
|
optionHeaders,
|
|
@@ -82,12 +83,8 @@ var apiCall = exports.apiCall = /*#__PURE__*/function () {
|
|
|
82
83
|
while (1) switch (_context.n) {
|
|
83
84
|
case 0:
|
|
84
85
|
options = _args.length > 3 && _args[3] !== undefined ? _args[3] : {};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
} else {
|
|
88
|
-
apiUrl = config.defaultPowrUrl;
|
|
89
|
-
}
|
|
90
|
-
url = "".concat(apiUrl).concat(endpoint); // Prop wins; NEXT_PUBLIC_PROJECT_ID is the default for every component.
|
|
86
|
+
host = config.resolvePowrApiUrl(apiUrl);
|
|
87
|
+
url = "".concat(host).concat(endpoint); // Prop wins; NEXT_PUBLIC_PROJECT_ID is the default for every component.
|
|
91
88
|
if (!projectId && config.projectId) {
|
|
92
89
|
projectId = config.projectId;
|
|
93
90
|
}
|