@pofsis-nbt/pofsis-auth 2.0.0 → 2.1.0

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 (45) hide show
  1. package/Documentation.md +151 -143
  2. package/README.md +143 -130
  3. package/dist/PofsisAuth.d.ts +1 -1
  4. package/dist/PofsisAuth.d.ts.map +1 -1
  5. package/dist/{PofsisAuthClient-CEw_lL5S.js → PofsisAuthClient-Duybofpq.js} +162 -46
  6. package/dist/PofsisAuthClient-Duybofpq.js.map +1 -0
  7. package/dist/PofsisAuthClient-c4lzLzjV.cjs +2 -0
  8. package/dist/PofsisAuthClient-c4lzLzjV.cjs.map +1 -0
  9. package/dist/{RequireAuth-CPhXupYh.cjs → RequireAuth-BkYhk-9p.cjs} +2 -2
  10. package/dist/{RequireAuth-CPhXupYh.cjs.map → RequireAuth-BkYhk-9p.cjs.map} +1 -1
  11. package/dist/{RequireAuth-DFa8_MR1.js → RequireAuth-DroX56rd.js} +67 -62
  12. package/dist/{RequireAuth-DFa8_MR1.js.map → RequireAuth-DroX56rd.js.map} +1 -1
  13. package/dist/auth/authLaunch.d.ts.map +1 -1
  14. package/dist/auth/config.d.ts.map +1 -1
  15. package/dist/core/PofsisAuthClient.d.ts +2 -0
  16. package/dist/core/PofsisAuthClient.d.ts.map +1 -1
  17. package/dist/core/index.d.ts +2 -2
  18. package/dist/core/index.d.ts.map +1 -1
  19. package/dist/core/popupProtocol.d.ts +11 -1
  20. package/dist/core/popupProtocol.d.ts.map +1 -1
  21. package/dist/core.cjs +1 -1
  22. package/dist/core.js +2 -2
  23. package/dist/elements/index.d.ts.map +1 -1
  24. package/dist/elements.cjs +1 -1
  25. package/dist/elements.cjs.map +1 -1
  26. package/dist/elements.js +8 -3
  27. package/dist/elements.js.map +1 -1
  28. package/dist/index.cjs +1 -1
  29. package/dist/index.d.ts +2 -2
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +3 -3
  32. package/dist/pofsis-auth-elements.js +1 -1
  33. package/dist/pofsis-auth-elements.js.map +1 -1
  34. package/dist/react/index.d.ts +1 -1
  35. package/dist/react/index.d.ts.map +1 -1
  36. package/dist/react.cjs +1 -1
  37. package/dist/react.js +1 -1
  38. package/dist/types.d.ts +13 -2
  39. package/dist/types.d.ts.map +1 -1
  40. package/docs/application-id-consumer-migration.md +180 -0
  41. package/docs/popup-integration.md +188 -162
  42. package/package.json +87 -87
  43. package/dist/PofsisAuthClient-B3YHqgZL.cjs +0 -2
  44. package/dist/PofsisAuthClient-B3YHqgZL.cjs.map +0 -1
  45. package/dist/PofsisAuthClient-CEw_lL5S.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { a as e, c as t, i as n, l as r, o as i, r as a, s as o, t as s } from "./PofsisAuthClient-CEw_lL5S.js";
1
+ import { a as e, c as t, l as n, o as r, r as i, s as a, t as o, u as s } from "./PofsisAuthClient-Duybofpq.js";
2
2
  import { createContext as c, useCallback as l, useContext as u, useEffect as d, useMemo as f, useRef as p, useState as m } from "react";
3
3
  import { Fragment as h, jsx as g, jsxs as _ } from "react/jsx-runtime";
4
4
  //#region src/assets/auth-error-illustration.png
@@ -160,21 +160,21 @@ function A({ callback: e = !1 }) {
160
160
  var j = c(null);
161
161
  //#endregion
162
162
  //#region src/components/AuthPathShell.tsx
163
- function M({ auth: e, LoadingScreen: t }) {
163
+ function M({ auth: t, LoadingScreen: n }) {
164
164
  let r = p(!1);
165
165
  return d(() => {
166
- r.current || (r.current = !0, e.login({
167
- ...n(window.location.search),
166
+ r.current || (r.current = !0, t.login({
167
+ ...e(window.location.search),
168
168
  presentation: "redirect"
169
169
  }).catch(() => {
170
170
  window.location.replace("/auth/error");
171
171
  }));
172
- }, [e]), /* @__PURE__ */ g(t, { callback: !0 });
172
+ }, [t]), /* @__PURE__ */ g(n, { callback: !0 });
173
173
  }
174
174
  function N({ auth: e, postLoginPath: t, returnPathKey: n, LoadingScreen: r }) {
175
- let i = p(!1);
175
+ let a = p(!1);
176
176
  return d(() => {
177
- if (i.current || (i.current = !0, a())) return;
177
+ if (a.current || (a.current = !0, i())) return;
178
178
  let r = new URLSearchParams(window.location.search), o = r.get("code"), s = r.get("state"), c = r.get("error");
179
179
  if (c || !o || !s) {
180
180
  window.location.replace(`/auth/error${c ? `?reason=${encodeURIComponent(c)}` : ""}`);
@@ -218,23 +218,23 @@ function R() {
218
218
  localStorage.setItem(L, String(Date.now()));
219
219
  } catch {}
220
220
  }
221
- function z({ children: e, client: n, postLoginPath: a, components: s }) {
222
- let [c, u] = m(n.getSession()), [p, h] = m(!0);
223
- d(() => n.subscribe(u), [n]), d(() => () => n.destroy(), [n]), d(() => {
221
+ function z({ children: e, client: r, postLoginPath: i, components: o }) {
222
+ let [c, u] = m(r.getSession()), [p, h] = m(!0);
223
+ d(() => r.subscribe(u), [r]), d(() => () => r.destroy(), [r]), d(() => {
224
224
  let e = !1;
225
- if (window.location.pathname.startsWith(n.config.callbackPath)) {
225
+ if (window.location.pathname.startsWith(r.config.callbackPath)) {
226
226
  h(!1);
227
227
  return;
228
228
  }
229
- return n.refreshSession().catch(() => void 0).finally(() => {
229
+ return r.refreshSession().catch(() => void 0).finally(() => {
230
230
  e || h(!1);
231
231
  }), () => {
232
232
  e = !0;
233
233
  };
234
- }, [n]);
234
+ }, [r]);
235
235
  let _ = l(() => {
236
- n.getSession() && (n.clearSession(), n.getOAuthClient().then((e) => window.location.assign(e.logout_uri)));
237
- }, [n]);
236
+ r.getSession() && (r.clearSession(), r.getOAuthClient().then((e) => window.location.assign(e.logout_uri)));
237
+ }, [r]);
238
238
  d(() => {
239
239
  let e = null;
240
240
  try {
@@ -252,104 +252,109 @@ function z({ children: e, client: n, postLoginPath: a, components: s }) {
252
252
  };
253
253
  }, [_]), d(() => {
254
254
  let e = () => {
255
- document.visibilityState !== "hidden" && n.getSession() && n.isRemoteSessionActive().then((e) => {
255
+ document.visibilityState !== "hidden" && r.getSession() && r.isRemoteSessionActive().then((e) => {
256
256
  e || _();
257
257
  });
258
258
  };
259
259
  return window.addEventListener("focus", e), document.addEventListener("visibilitychange", e), () => {
260
260
  window.removeEventListener("focus", e), document.removeEventListener("visibilitychange", e);
261
261
  };
262
- }, [n, _]);
262
+ }, [r, _]);
263
263
  let v = l(async () => {
264
- let e = await n.getOAuthClient();
264
+ let e = await r.getOAuthClient();
265
265
  try {
266
- await n.logout();
266
+ await r.logout();
267
267
  } finally {
268
268
  R(), window.location.assign(e.logout_uri || `${window.location.origin}/login`);
269
269
  }
270
- }, [n]), y = l((e) => {
271
- let t = n.getUser();
270
+ }, [r]), y = l((e) => {
271
+ let t = r.getUser();
272
272
  if (!t) return e;
273
- let r = [e.firstName, e.lastName].filter(Boolean).join(" "), i = {
273
+ let n = [e.firstName, e.lastName].filter(Boolean).join(" "), i = {
274
274
  ...t,
275
275
  accountId: e.accountId,
276
276
  firstName: e.firstName || void 0,
277
277
  lastName: e.lastName || void 0,
278
- displayName: r || t.email || t.displayName,
278
+ displayName: n || t.email || t.displayName,
279
279
  avatarUrl: e.profilePhotoUrl || void 0,
280
280
  coverUrl: e.coverPhotoUrl || void 0
281
281
  };
282
- return n.replaceUser(i), e;
283
- }, [n]), b = l(async () => {
284
- n.getAccessToken() || await n.refreshSession();
285
- let e = n.getAccessToken();
282
+ return r.replaceUser(i), e;
283
+ }, [r]), b = l(async () => {
284
+ r.getAccessToken() || await r.refreshSession();
285
+ let e = r.getAccessToken();
286
286
  if (!e) throw Error("Authentication required");
287
287
  return e;
288
- }, [n]), x = f(() => ({
288
+ }, [r]), x = f(() => ({
289
289
  user: c?.user ?? null,
290
290
  session: c,
291
291
  isAuthenticated: !!c,
292
292
  isLoading: p,
293
- login: n.login.bind(n),
294
- signup: n.signup.bind(n),
295
- resetPassword: n.resetPassword.bind(n),
293
+ login: r.login.bind(r),
294
+ signup: r.signup.bind(r),
295
+ resetPassword: r.resetPassword.bind(r),
296
296
  logout: v,
297
- refreshSession: () => n.refreshSession(),
298
- getAccessToken: () => n.getAccessToken(),
299
- getAccountProfile: async () => y(await o(n.config, await b())),
300
- updateAccountProfile: async (e) => y(await t(n.config, await b(), e)),
301
- uploadAccountProfileImage: async (e, t) => y(await r(n.config, await b(), e, t)),
302
- deleteAccountProfileImage: async (e) => y(await i(n.config, await b(), e)),
303
- completeCallback: (e, t) => n.completeRedirectCallback(e, t)
297
+ refreshSession: () => r.refreshSession(),
298
+ getAccessToken: () => r.getAccessToken(),
299
+ getAccountProfile: async () => y(await t(r.config, await b())),
300
+ updateAccountProfile: async (e) => y(await n(r.config, await b(), e)),
301
+ uploadAccountProfileImage: async (e, t) => y(await s(r.config, await b(), e, t)),
302
+ deleteAccountProfileImage: async (e) => y(await a(r.config, await b(), e)),
303
+ completeCallback: (e, t) => r.completeRedirectCallback(e, t)
304
304
  }), [
305
305
  y,
306
- n,
306
+ r,
307
307
  p,
308
308
  v,
309
309
  b,
310
310
  c
311
311
  ]);
312
312
  return /* @__PURE__ */ g(F.Provider, {
313
- value: s,
313
+ value: o,
314
314
  children: /* @__PURE__ */ g(j.Provider, {
315
315
  value: x,
316
316
  children: /* @__PURE__ */ g(P, {
317
- callbackPath: n.config.callbackPath,
318
- components: s,
319
- postLoginPath: a,
320
- returnPathKey: `${n.config.applicationId}.auth.return-path`,
317
+ callbackPath: r.config.callbackPath,
318
+ components: o,
319
+ postLoginPath: i,
320
+ returnPathKey: `${r.config.applicationId}.auth.return-path`,
321
321
  children: e
322
322
  })
323
323
  })
324
324
  });
325
325
  }
326
- function B({ children: t, applicationId: n, apiBaseUrl: r, authUrl: i, scope: a, callbackPath: o, popup: c, postLoginPath: l = "/", components: u }) {
327
- let d = f(() => e({
328
- applicationId: n,
329
- apiBaseUrl: r,
326
+ function B({ children: e, applicationId: t, apiBaseUrl: n, authUrl: i, scope: a, callbackPath: s, popup: c, modal: l, postLoginPath: u = "/", components: d }) {
327
+ let p = f(() => r({
328
+ applicationId: t,
329
+ apiBaseUrl: n,
330
330
  authUrl: i,
331
331
  scope: a,
332
- callbackPath: o,
333
- popup: c
332
+ callbackPath: s,
333
+ popup: c,
334
+ modal: l
334
335
  }), [
336
+ t,
335
337
  n,
336
- r,
337
338
  i,
338
339
  a,
339
- o,
340
+ s,
340
341
  c?.width,
341
342
  c?.height,
342
343
  c?.name,
343
- c?.timeoutMs
344
- ]), p = f(() => new s(d), [d]), m = f(() => ({
345
- LoadingScreen: u?.LoadingScreen ?? A,
346
- ErrorScreen: u?.ErrorScreen ?? E
347
- }), [u?.ErrorScreen, u?.LoadingScreen]);
344
+ c?.timeoutMs,
345
+ l?.width,
346
+ l?.height,
347
+ l?.timeoutMs,
348
+ l?.readyTimeoutMs
349
+ ]), m = f(() => new o(p), [p]), h = f(() => ({
350
+ LoadingScreen: d?.LoadingScreen ?? A,
351
+ ErrorScreen: d?.ErrorScreen ?? E
352
+ }), [d?.ErrorScreen, d?.LoadingScreen]);
348
353
  return /* @__PURE__ */ g(z, {
349
- client: p,
350
- postLoginPath: l,
351
- components: m,
352
- children: t
354
+ client: m,
355
+ postLoginPath: u,
356
+ components: h,
357
+ children: e
353
358
  });
354
359
  }
355
360
  //#endregion
@@ -400,4 +405,4 @@ function U({ children: e, fallback: t, onUnauthenticated: n }) {
400
405
  //#endregion
401
406
  export { A as a, B as i, H as n, E as o, V as r, U as t };
402
407
 
403
- //# sourceMappingURL=RequireAuth-DFa8_MR1.js.map
408
+ //# sourceMappingURL=RequireAuth-DroX56rd.js.map