@mirai/core 0.1.28 → 0.1.29

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.
@@ -5,13 +5,22 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.fetchSession = void 0;
7
7
  var _dataSources = require("@mirai/data-sources");
8
- const SESSION_STORAGE_ID = 'CLUB';
8
+ const CACHE_LIMIT = 1000 * 60 * 60 * 24 * 7;
9
+ const SESSION_STORAGE_LEGACY_ID = 'CLUB';
10
+ const SESSION_STORAGE_ID = 'MIRAI:SERVICE:USER:session';
9
11
  const fetchSession = function () {
10
12
  let urlParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
11
- const storage = new _dataSources.Storage({
12
- adapter: _dataSources.SessionAdapter
13
+ let storage = new _dataSources.Storage({
14
+ adapter: _dataSources.LocalAdapter,
15
+ cache: CACHE_LIMIT
13
16
  });
14
17
  let session = storage.get(SESSION_STORAGE_ID);
18
+ if (!session) {
19
+ storage = new _dataSources.Storage({
20
+ adapter: _dataSources.SessionAdapter
21
+ });
22
+ session = storage.get(SESSION_STORAGE_LEGACY_ID);
23
+ }
15
24
  if (!session && urlParams.session) {
16
25
  try {
17
26
  session = JSON.parse(urlParams.session);
@@ -22,18 +31,36 @@ const fetchSession = function () {
22
31
  }
23
32
  const {
24
33
  accessToken,
34
+ authorization,
25
35
  email,
26
36
  firstName,
27
- lastName
28
- // ? Not sure we should get this data
29
- // clubId,
30
- // clubName,
37
+ lastName,
38
+ country,
39
+ dateOfBirth,
40
+ club: {
41
+ name,
42
+ id,
43
+ level
44
+ } = {},
45
+ subscribed,
46
+ // ? Not sure we should get this data from legacy
47
+ idClub: clubId,
48
+ clubName,
49
+ level: clubLevel
31
50
  } = session || {};
32
- return accessToken ? {
33
- accessToken,
51
+ return accessToken || authorization ? {
52
+ authorization: authorization || accessToken,
34
53
  email,
35
54
  firstName,
36
- lastName
55
+ lastName,
56
+ country,
57
+ dateOfBirth,
58
+ club: {
59
+ name: name || clubName,
60
+ id: id || clubId,
61
+ level: level || clubLevel
62
+ },
63
+ subscribed
37
64
  } : undefined;
38
65
  };
39
66
  exports.fetchSession = fetchSession;
@@ -1 +1 @@
1
- {"version":3,"file":"fetchSession.js","names":["SESSION_STORAGE_ID","fetchSession","urlParams","storage","Storage","adapter","SessionAdapter","session","get","JSON","parse","error","console","accessToken","email","firstName","lastName","undefined"],"sources":["../../src/helpers/fetchSession.js"],"sourcesContent":["import { SessionAdapter, Storage } from '@mirai/data-sources';\n\nconst SESSION_STORAGE_ID = 'CLUB';\n\nexport const fetchSession = (urlParams = {}) => {\n const storage = new Storage({ adapter: SessionAdapter });\n let session = storage.get(SESSION_STORAGE_ID);\n\n if (!session && urlParams.session) {\n try {\n session = JSON.parse(urlParams.session);\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('', error);\n }\n }\n\n const {\n accessToken,\n email,\n firstName,\n lastName,\n // ? Not sure we should get this data\n // clubId,\n // clubName,\n } = session || {};\n\n return accessToken ? { accessToken, email, firstName, lastName } : undefined;\n};\n"],"mappings":";;;;;;AAAA;AAEA,MAAMA,kBAAkB,GAAG,MAAM;AAE1B,MAAMC,YAAY,GAAG,YAAoB;EAAA,IAAnBC,SAAS,uEAAG,CAAC,CAAC;EACzC,MAAMC,OAAO,GAAG,IAAIC,oBAAO,CAAC;IAAEC,OAAO,EAAEC;EAAe,CAAC,CAAC;EACxD,IAAIC,OAAO,GAAGJ,OAAO,CAACK,GAAG,CAACR,kBAAkB,CAAC;EAE7C,IAAI,CAACO,OAAO,IAAIL,SAAS,CAACK,OAAO,EAAE;IACjC,IAAI;MACFA,OAAO,GAAGE,IAAI,CAACC,KAAK,CAACR,SAAS,CAACK,OAAO,CAAC;IACzC,CAAC,CAAC,OAAOI,KAAK,EAAE;MACd;MACAC,OAAO,CAACD,KAAK,CAAC,EAAE,EAAEA,KAAK,CAAC;IAC1B;EACF;EAEA,MAAM;IACJE,WAAW;IACXC,KAAK;IACLC,SAAS;IACTC;IACA;IACA;IACA;EACF,CAAC,GAAGT,OAAO,IAAI,CAAC,CAAC;EAEjB,OAAOM,WAAW,GAAG;IAAEA,WAAW;IAAEC,KAAK;IAAEC,SAAS;IAAEC;EAAS,CAAC,GAAGC,SAAS;AAC9E,CAAC;AAAC"}
1
+ {"version":3,"file":"fetchSession.js","names":["CACHE_LIMIT","SESSION_STORAGE_LEGACY_ID","SESSION_STORAGE_ID","fetchSession","urlParams","storage","Storage","adapter","LocalAdapter","cache","session","get","SessionAdapter","JSON","parse","error","console","accessToken","authorization","email","firstName","lastName","country","dateOfBirth","club","name","id","level","subscribed","idClub","clubId","clubName","clubLevel","undefined"],"sources":["../../src/helpers/fetchSession.js"],"sourcesContent":["import { LocalAdapter, SessionAdapter, Storage } from '@mirai/data-sources';\n\nconst CACHE_LIMIT = 1000 * 60 * 60 * 24 * 7;\nconst SESSION_STORAGE_LEGACY_ID = 'CLUB';\nconst SESSION_STORAGE_ID = 'MIRAI:SERVICE:USER:session';\n\nexport const fetchSession = (urlParams = {}) => {\n let storage = new Storage({ adapter: LocalAdapter, cache: CACHE_LIMIT });\n let session = storage.get(SESSION_STORAGE_ID);\n\n if (!session) {\n storage = new Storage({ adapter: SessionAdapter });\n session = storage.get(SESSION_STORAGE_LEGACY_ID);\n }\n\n if (!session && urlParams.session) {\n try {\n session = JSON.parse(urlParams.session);\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('', error);\n }\n }\n\n const {\n accessToken,\n authorization,\n email,\n firstName,\n lastName,\n country,\n dateOfBirth,\n club: { name, id, level } = {},\n subscribed,\n // ? Not sure we should get this data from legacy\n idClub: clubId,\n clubName,\n level: clubLevel,\n } = session || {};\n\n return accessToken || authorization\n ? {\n authorization: authorization || accessToken,\n email,\n firstName,\n lastName,\n country,\n dateOfBirth,\n club: { name: name || clubName, id: id || clubId, level: level || clubLevel },\n subscribed,\n }\n : undefined;\n};\n"],"mappings":";;;;;;AAAA;AAEA,MAAMA,WAAW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ACPC,WAAW;IACXC,IAAI,EAAE;MAAEC,IAAI,EAAEA,IAAI,IAAIM,QAAQ;MAAEL,EAAE,EAAEA,EAAE,IAAII,MAAM;MAAEH,KAAK,EAAEA,KAAK,IAAIK;IAAU,CAAC;IAC7EJ;EACF,CAAC,GACDK,SAAS;AACf,CAAC;AAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mirai/core",
3
- "version": "0.1.28",
3
+ "version": "0.1.29",
4
4
  "source": "src/index.js",
5
5
  "repository": "https://gitlab.com/miraicorp/dev/frontend/core",
6
6
  "author": "JΛVI <hello@soyjavi.com>",