powr-sdk-web 5.10.2 → 5.10.6
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 +6 -2
- package/dist/index.js +6 -0
- package/dist/sso/index.js +12 -4
- package/dist/sso/openPowrLogin.js +69 -69
- package/dist/utils/auth.js +1 -2
- package/package.json +1 -1
package/dist/config.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
/** Stable PowrBase host. Override with apiUrl or NEXT_PUBLIC_POWR_URL. */
|
|
4
|
+
var DEFAULT_POWR_API_URL = "https://powr-api.lawazia.tech";
|
|
3
5
|
var config = {
|
|
4
6
|
projectId: process.env.NEXT_PUBLIC_PROJECT_ID,
|
|
5
|
-
powrUrl: process.env.NEXT_PUBLIC_POWR_URL
|
|
7
|
+
powrUrl: process.env.NEXT_PUBLIC_POWR_URL,
|
|
8
|
+
defaultPowrUrl: DEFAULT_POWR_API_URL
|
|
6
9
|
};
|
|
7
|
-
module.exports = config;
|
|
10
|
+
module.exports = config;
|
|
11
|
+
module.exports.DEFAULT_POWR_API_URL = DEFAULT_POWR_API_URL;
|
package/dist/index.js
CHANGED
|
@@ -334,6 +334,12 @@ Object.defineProperty(exports, "openPowrLogin", {
|
|
|
334
334
|
return _sso.openPowrLogin;
|
|
335
335
|
}
|
|
336
336
|
});
|
|
337
|
+
Object.defineProperty(exports, "originsFromApps", {
|
|
338
|
+
enumerable: true,
|
|
339
|
+
get: function get() {
|
|
340
|
+
return _sso.originsFromApps;
|
|
341
|
+
}
|
|
342
|
+
});
|
|
337
343
|
Object.defineProperty(exports, "parsePhone", {
|
|
338
344
|
enumerable: true,
|
|
339
345
|
get: function get() {
|
package/dist/sso/index.js
CHANGED
|
@@ -40,6 +40,12 @@ Object.defineProperty(exports, "openPowrLogin", {
|
|
|
40
40
|
return _openPowrLogin.openPowrLogin;
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
|
+
Object.defineProperty(exports, "originsFromApps", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function get() {
|
|
46
|
+
return _openPowrLogin.originsFromApps;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
43
49
|
Object.defineProperty(exports, "readHandoffParams", {
|
|
44
50
|
enumerable: true,
|
|
45
51
|
get: function get() {
|
|
@@ -78,6 +84,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
78
84
|
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; }
|
|
79
85
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
80
86
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
87
|
+
var config = require("../config");
|
|
81
88
|
var shellStyle = {
|
|
82
89
|
display: "flex",
|
|
83
90
|
minHeight: "100vh",
|
|
@@ -143,7 +150,7 @@ var btnStyle = {
|
|
|
143
150
|
* Apps keep a thin `/sso` page that renders this with `apiUrl` + `onSuccess`.
|
|
144
151
|
*
|
|
145
152
|
* @param {object} props
|
|
146
|
-
* @param {string} props.apiUrl - Powr
|
|
153
|
+
* @param {string} [props.apiUrl] - Powr host. Defaults to https://powr-api.lawazia.tech
|
|
147
154
|
* @param {string} [props.appName]
|
|
148
155
|
* @param {boolean} [props.ready=true] - Wait (e.g. auth hydrate) before exchanging code
|
|
149
156
|
* @param {string} [props.loginHref="/login"]
|
|
@@ -176,6 +183,7 @@ function PowrBaseSso(_ref) {
|
|
|
176
183
|
})[0];
|
|
177
184
|
var loginId = loginIdProp !== undefined ? loginIdProp : fromUrl.loginId;
|
|
178
185
|
var next = nextProp !== undefined ? nextProp : fromUrl.next;
|
|
186
|
+
var powrApi = String(apiUrl || config.defaultPowrUrl || "").replace(/\/$/, "");
|
|
179
187
|
var _useState = (0, _react.useState)(loginId ? null : "Missing login link"),
|
|
180
188
|
_useState2 = _slicedToArray(_useState, 2),
|
|
181
189
|
error = _useState2[0],
|
|
@@ -188,10 +196,10 @@ function PowrBaseSso(_ref) {
|
|
|
188
196
|
var onSuccessRef = (0, _react.useRef)(onSuccess);
|
|
189
197
|
onSuccessRef.current = onSuccess;
|
|
190
198
|
(0, _react.useEffect)(function () {
|
|
191
|
-
if (!loginId || !ready || !
|
|
199
|
+
if (!loginId || !ready || !powrApi || started.current) return;
|
|
192
200
|
started.current = true;
|
|
193
201
|
setBusy(true);
|
|
194
|
-
(0, _api.loginWithCode)(
|
|
202
|
+
(0, _api.loginWithCode)(powrApi, loginId).then(/*#__PURE__*/function () {
|
|
195
203
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(data) {
|
|
196
204
|
var cb;
|
|
197
205
|
return _regenerator().w(function (_context) {
|
|
@@ -221,7 +229,7 @@ function PowrBaseSso(_ref) {
|
|
|
221
229
|
setError((err === null || err === void 0 ? void 0 : err.message) || "Could not finish sign-in");
|
|
222
230
|
setBusy(false);
|
|
223
231
|
});
|
|
224
|
-
}, [loginId, next, ready,
|
|
232
|
+
}, [loginId, next, ready, powrApi]);
|
|
225
233
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
226
234
|
style: shellStyle
|
|
227
235
|
}, /*#__PURE__*/_react["default"].createElement("style", null, "@keyframes powr-sso-spin{to{transform:rotate(360deg)}}"), /*#__PURE__*/_react["default"].createElement("p", {
|
|
@@ -7,75 +7,75 @@ exports.DEFAULT_POWR_TARGETS = void 0;
|
|
|
7
7
|
exports.buildPowrSsoUrl = buildPowrSsoUrl;
|
|
8
8
|
exports.matchPowrTarget = matchPowrTarget;
|
|
9
9
|
exports.openPowrLogin = openPowrLogin;
|
|
10
|
+
exports.originsFromApps = originsFromApps;
|
|
10
11
|
var _api = require("./api");
|
|
11
12
|
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
12
13
|
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
13
14
|
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
14
15
|
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
15
|
-
|
|
16
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
17
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
16
|
+
var config = require("../config");
|
|
18
17
|
function normalizeOrigin(value) {
|
|
19
18
|
return String(value || "").replace(/\/$/, "").toLowerCase();
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Default Lawazia Powr app origin → /powr API map (prod + common local Quiz).
|
|
24
|
-
* Host apps can pass `targets` to override (e.g. from NEXT_PUBLIC_* env).
|
|
25
|
-
*/
|
|
26
|
-
var DEFAULT_POWR_TARGETS = exports.DEFAULT_POWR_TARGETS = [{
|
|
27
|
-
origins: ["https://rasoi.lawazia.tech"],
|
|
28
|
-
powrApiUrl: "https://rasoiapp-api-690167968218.europe-west1.run.app/powr"
|
|
29
|
-
}, {
|
|
30
|
-
origins: ["https://win.urbanstall.app"],
|
|
31
|
-
powrApiUrl: "https://quizapp-api-new-762437065717.asia-south1.run.app/powr"
|
|
32
|
-
}, {
|
|
33
|
-
origins: ["http://localhost:3001", "http://127.0.0.1:3001", "http://localhost:3010", "http://127.0.0.1:3010"],
|
|
34
|
-
powrApiUrl: "http://localhost:3000/powr"
|
|
35
|
-
}, {
|
|
36
|
-
origins: ["https://earn.urbanstall.app"],
|
|
37
|
-
powrApiUrl: "https://ads-app-api-429552207832.asia-east1.run.app/powr"
|
|
38
|
-
}];
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @param {string} url
|
|
42
|
-
* @param {Array<{ origins: string[], powrApiUrl: string }>} [targets]
|
|
43
|
-
* @returns {{ origin: string, powrApiUrl: string, pathname: string, search: string, hash: string } | null}
|
|
44
|
-
*/
|
|
45
|
-
function matchPowrTarget(url) {
|
|
46
|
-
var targets = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_POWR_TARGETS;
|
|
47
|
-
var parsed;
|
|
20
|
+
function originFromEntry(value) {
|
|
48
21
|
try {
|
|
49
|
-
|
|
22
|
+
return new URL(value).origin;
|
|
50
23
|
} catch (_unused) {
|
|
51
|
-
return
|
|
24
|
+
return String(value || "").replace(/\/$/, "");
|
|
52
25
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Pull origin strings from a card list (`{ url }`) or a raw origin list. */
|
|
29
|
+
function originsFromApps(apps) {
|
|
30
|
+
if (!Array.isArray(apps)) return [];
|
|
31
|
+
return apps.map(function (item) {
|
|
32
|
+
if (typeof item === "string") return originFromEntry(item);
|
|
33
|
+
if (item && item.url) return originFromEntry(item.url);
|
|
34
|
+
return "";
|
|
35
|
+
}).filter(Boolean);
|
|
36
|
+
}
|
|
37
|
+
function parseDest(url) {
|
|
56
38
|
try {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
search: parsed.search || "",
|
|
67
|
-
hash: parsed.hash || ""
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
} catch (err) {
|
|
72
|
-
_iterator.e(err);
|
|
73
|
-
} finally {
|
|
74
|
-
_iterator.f();
|
|
39
|
+
var parsed = new URL(url);
|
|
40
|
+
return {
|
|
41
|
+
origin: parsed.origin.replace(/\/$/, ""),
|
|
42
|
+
pathname: parsed.pathname || "/",
|
|
43
|
+
search: parsed.search || "",
|
|
44
|
+
hash: parsed.hash || ""
|
|
45
|
+
};
|
|
46
|
+
} catch (_unused2) {
|
|
47
|
+
return null;
|
|
75
48
|
}
|
|
49
|
+
}
|
|
50
|
+
function resolvePowrApiUrl(apiUrl) {
|
|
51
|
+
if (apiUrl) return String(apiUrl).replace(/\/$/, "");
|
|
52
|
+
if (config.powrUrl) return String(config.powrUrl).replace(/\/$/, "");
|
|
53
|
+
if (config.defaultPowrUrl) return String(config.defaultPowrUrl).replace(/\/$/, "");
|
|
54
|
+
return "";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {string} url
|
|
59
|
+
* @param {string[]|Array<{url?: string}>} [origins] - sibling card list or origins
|
|
60
|
+
* @returns {{ origin: string, pathname: string, search: string, hash: string } | null}
|
|
61
|
+
*/
|
|
62
|
+
function matchPowrTarget(url, origins) {
|
|
63
|
+
var dest = parseDest(url);
|
|
64
|
+
if (!dest) return null;
|
|
65
|
+
var list = originsFromApps(origins);
|
|
66
|
+
if (!list.length) return dest;
|
|
67
|
+
var origin = normalizeOrigin(dest.origin);
|
|
68
|
+
if (list.some(function (o) {
|
|
69
|
+
return normalizeOrigin(o) === origin;
|
|
70
|
+
})) return dest;
|
|
76
71
|
return null;
|
|
77
72
|
}
|
|
78
73
|
|
|
74
|
+
/**
|
|
75
|
+
* @deprecated Product `/powr` URLs are gone. Pass `apiUrl` + the card list as `origins`.
|
|
76
|
+
*/
|
|
77
|
+
var DEFAULT_POWR_TARGETS = exports.DEFAULT_POWR_TARGETS = [];
|
|
78
|
+
|
|
79
79
|
/**
|
|
80
80
|
* Build destination `/sso?loginId=` (+ optional `next`) on the sibling app.
|
|
81
81
|
*/
|
|
@@ -98,16 +98,14 @@ function openPlain(url) {
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
|
-
* Issue a login code
|
|
102
|
-
*
|
|
101
|
+
* Issue a login code and navigate to `/sso?loginId=`.
|
|
102
|
+
* Same as login/admin: `apiUrl` comes from the app (or NEXT_PUBLIC_POWR_URL).
|
|
103
103
|
*
|
|
104
|
-
* @param {string} url - Destination app URL (
|
|
105
|
-
* @param {string|null|undefined} token
|
|
104
|
+
* @param {string} url - Destination app URL (from the sibling card / banner)
|
|
105
|
+
* @param {string|null|undefined} token
|
|
106
106
|
* @param {object} [options]
|
|
107
|
-
* @param {
|
|
108
|
-
* @param {string} [options.
|
|
109
|
-
* @param {(url: string) => void} [options.onFallback] - default window.open
|
|
110
|
-
* @param {(ssoUrl: string) => void} [options.navigate] - default location.assign
|
|
107
|
+
* @param {string} [options.apiUrl] - Powr API (`…/powr`). Pass from the app.
|
|
108
|
+
* @param {string[]|Array<{url?: string}>} [options.origins] - The card list
|
|
111
109
|
*/
|
|
112
110
|
function openPowrLogin(_x, _x2) {
|
|
113
111
|
return _openPowrLogin.apply(this, arguments);
|
|
@@ -115,15 +113,16 @@ function openPowrLogin(_x, _x2) {
|
|
|
115
113
|
function _openPowrLogin() {
|
|
116
114
|
_openPowrLogin = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(url, token) {
|
|
117
115
|
var options,
|
|
118
|
-
|
|
119
|
-
|
|
116
|
+
apiUrl,
|
|
117
|
+
origins,
|
|
120
118
|
_options$ssoPath,
|
|
121
119
|
ssoPath,
|
|
122
120
|
_options$onFallback,
|
|
123
121
|
onFallback,
|
|
124
122
|
_options$navigate,
|
|
125
123
|
navigate,
|
|
126
|
-
|
|
124
|
+
powrApi,
|
|
125
|
+
dest,
|
|
127
126
|
data,
|
|
128
127
|
_args = arguments,
|
|
129
128
|
_t;
|
|
@@ -131,11 +130,12 @@ function _openPowrLogin() {
|
|
|
131
130
|
while (1) switch (_context.p = _context.n) {
|
|
132
131
|
case 0:
|
|
133
132
|
options = _args.length > 2 && _args[2] !== undefined ? _args[2] : {};
|
|
134
|
-
|
|
133
|
+
apiUrl = options.apiUrl, 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) {
|
|
135
134
|
if (typeof window !== "undefined") window.location.assign(ssoUrl);
|
|
136
135
|
} : _options$navigate;
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
powrApi = resolvePowrApiUrl(apiUrl);
|
|
137
|
+
dest = matchPowrTarget(url, origins);
|
|
138
|
+
if (!(!dest || !token || !powrApi)) {
|
|
139
139
|
_context.n = 1;
|
|
140
140
|
break;
|
|
141
141
|
}
|
|
@@ -144,10 +144,10 @@ function _openPowrLogin() {
|
|
|
144
144
|
case 1:
|
|
145
145
|
_context.p = 1;
|
|
146
146
|
_context.n = 2;
|
|
147
|
-
return (0, _api.issueLoginCode)(
|
|
147
|
+
return (0, _api.issueLoginCode)(powrApi, token);
|
|
148
148
|
case 2:
|
|
149
149
|
data = _context.v;
|
|
150
|
-
navigate(buildPowrSsoUrl(
|
|
150
|
+
navigate(buildPowrSsoUrl(dest, data.loginId, {
|
|
151
151
|
ssoPath: ssoPath
|
|
152
152
|
}));
|
|
153
153
|
_context.n = 4;
|
package/dist/utils/auth.js
CHANGED
|
@@ -81,9 +81,8 @@ var apiCall = exports.apiCall = /*#__PURE__*/function () {
|
|
|
81
81
|
options = _args.length > 3 && _args[3] !== undefined ? _args[3] : {};
|
|
82
82
|
if (apiUrl) {} else if (config.powrUrl) {
|
|
83
83
|
apiUrl = config.powrUrl;
|
|
84
|
-
projectId = null;
|
|
85
84
|
} else {
|
|
86
|
-
apiUrl =
|
|
85
|
+
apiUrl = config.defaultPowrUrl;
|
|
87
86
|
}
|
|
88
87
|
url = "".concat(apiUrl).concat(endpoint);
|
|
89
88
|
if (projectId) {
|