@jetthai/cuora 1.0.106 → 1.0.108

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/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.0.108](https://github.com/jetthai/cuora-module/compare/v1.0.107...v1.0.108) (2022-04-07)
6
+
7
+ ### [1.0.107](https://github.com/jetthai/cuora-module/compare/v1.0.106...v1.0.107) (2022-03-23)
8
+
5
9
  ### [1.0.106](https://github.com/jetthai/cuora-module/compare/v1.0.105...v1.0.106) (2022-03-22)
6
10
 
7
11
  ### [1.0.105](https://github.com/jetthai/cuora-module/compare/v1.0.104...v1.0.105) (2022-03-22)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.106",
3
+ "version": "1.0.108",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -17,7 +17,7 @@
17
17
  "standard-version": "^9.3.1"
18
18
  },
19
19
  "dependencies": {
20
- "@fingerprintjs/fingerprintjs-pro": "^3.5.5",
20
+ "@fingerprintjs/fingerprintjs-pro": "^3.5.7",
21
21
  "lodash": "^4.17.21",
22
22
  "qs": "^6.10.1",
23
23
  "ua-parser-js": "^0.7.28",
package/src/api/auth.js CHANGED
@@ -1,4 +1,10 @@
1
1
  export default {
2
+ guestLogin: ({ dt }) => ({
3
+ url: 'guestLogin',
4
+ method: 'post',
5
+ params: { dt },
6
+ isPublic: true,
7
+ }),
2
8
  login: ({ username, password, provider, countryCode, phone, email, dt }) => ({
3
9
  url: 'login',
4
10
  method: 'post',
@@ -36,6 +36,9 @@ export default function (request) {
36
36
  entry: 'fetchToken',
37
37
  always: [{ target: 'authenticated', cond: 'hasToken' }],
38
38
  on: {
39
+ LOGIN_GUEST: {
40
+ target: 'authenticationGuest',
41
+ },
39
42
  LOGIN_PHONE: {
40
43
  target: 'authentication',
41
44
  actions: 'setLoginPhone',
@@ -66,6 +69,19 @@ export default function (request) {
66
69
  },
67
70
  },
68
71
  },
72
+ authenticationGuest: {
73
+ invoke: {
74
+ src: 'authenticateGuest',
75
+ onDone: {
76
+ target: 'authenticated',
77
+ actions: 'setToken',
78
+ },
79
+ onError: {
80
+ target: 'idle',
81
+ actions: 'removeToken',
82
+ },
83
+ },
84
+ },
69
85
  authenticated: {
70
86
  invoke: {
71
87
  src: 'fetchUserInfo',
@@ -252,14 +268,14 @@ export default function (request) {
252
268
  const redirectURL = urljoin(
253
269
  request.config.fullURL,
254
270
  'login?' +
255
- qs.stringify({
256
- provider,
257
- redirectURI: `${window.location.protocol}//${window.location.host}`,
258
- channel: cookies.get('channel') || channel || 'official',
259
- subchannel: cookies.get('subchannel') || subchannel || 'pwa',
260
- dt,
261
- platform: 'pwa',
262
- })
271
+ qs.stringify({
272
+ provider,
273
+ redirectURI: `${window.location.protocol}//${window.location.host}`,
274
+ channel: cookies.get('channel') || channel || 'official',
275
+ subchannel: cookies.get('subchannel') || subchannel || 'pwa',
276
+ dt,
277
+ platform: 'pwa',
278
+ })
263
279
  )
264
280
  window.location.href = redirectURL
265
281
  },
@@ -276,6 +292,11 @@ export default function (request) {
276
292
  const { token } = await request.send(auth.login(data))
277
293
  return token
278
294
  },
295
+ authenticateGuest: async (context, event) => {
296
+ const dt = await getDeviceToken({ fpToken, sentry, apiURL: request.config.apiURL })
297
+ const { token } = await request.send(auth.guestLogin({ dt }))
298
+ return token
299
+ },
279
300
  logout: async (context, event) => {
280
301
  return await request.send(auth.logout())
281
302
  },
@@ -11,94 +11,74 @@ export default function (request) {
11
11
  id: 'user_sign_up',
12
12
  initial: 'idle',
13
13
  context: {
14
- email: '',
15
- password: '',
14
+ provider: null,
16
15
  channel: null,
17
16
  subchannel: null,
17
+ signUpData: {},
18
18
  },
19
19
  states: {
20
20
  idle: {
21
21
  on: {
22
- SIGN_UP: {
23
- target: 'validating',
24
- actions: 'setForm',
22
+ SIGN_UP_PHONE: {
23
+ target: 'authentication',
24
+ actions: 'setSignUpPhone',
25
25
  },
26
- },
27
- },
28
- invalidFormat: {
29
- on: {
30
- SIGN_UP: {
31
- target: 'validating',
32
- actions: 'setForm',
33
- },
34
- },
35
- },
36
- shortPassword: {
37
- on: {
38
- SIGN_UP: {
39
- target: 'validating',
40
- actions: 'setForm',
26
+ SIGN_UP_EMAIL: {
27
+ target: 'authentication',
28
+ actions: 'setSignUpEmail',
41
29
  },
42
30
  },
43
31
  },
44
- validating: {
45
- always: [
46
- {
47
- target: 'invalidFormat',
48
- cond: 'isInvalidFormat',
49
- },
50
- {
51
- target: 'shortPassword',
52
- cond: 'isLessThan6Characters',
53
- },
54
- {
55
- target: 'submitting',
56
- },
57
- ],
58
- },
59
- submitting: {
32
+ authentication: {
60
33
  invoke: {
61
- src: 'signUp',
34
+ src: 'authenticate',
62
35
  onDone: {
63
- target: 'success',
36
+ target: 'authenticated',
64
37
  },
65
38
  onError: {
66
39
  target: 'idle',
67
40
  },
68
41
  },
69
42
  },
70
- success: {},
43
+ authenticated: {},
71
44
  },
72
45
  },
73
46
  {
74
47
  actions: {
75
- setForm: assign((context, event) => {
48
+ setSignUpPhone: assign((context, event) => {
49
+ const { countryCode, phone, password, channel, subchannel } = event.data
50
+ return {
51
+ signUpData: {
52
+ provider: 'phone',
53
+ countryCode,
54
+ phone,
55
+ password
56
+ },
57
+ channel,
58
+ subchannel,
59
+ }
60
+ }),
61
+ setSignUpEmail: assign((context, event) => {
76
62
  const { email, password, channel, subchannel } = event.data
77
63
  return {
78
- email,
79
- password,
64
+ signUpData: {
65
+ provider: 'email',
66
+ email,
67
+ password
68
+ },
80
69
  channel,
81
70
  subchannel,
82
71
  }
83
72
  }),
84
73
  },
85
- guards: {
86
- isInvalidFormat: (context, event) => {
87
- // return !context.email || /[+-]/.test(context.email)
88
- },
89
- isLessThan6Characters: (context, event) => {
90
- // return context.password.length < 6
91
- },
92
- },
93
74
  services: {
94
- signUp: async (context, event) => {
95
- const { email, password, channel, subchannel } = context
75
+ authenticate: async (context, event) => {
76
+ const { channel, subchannel, signUpData } = context
96
77
  const dt = await getDeviceToken({ fpToken, sentry, apiURL: request.config.apiURL })
78
+
97
79
  return await request.send(
98
80
  auth.register({
99
- provider: 'email',
100
- email,
101
- password,
81
+ ...signUpData,
102
82
  channel: cookies.get('channel') || channel,
103
83
  subchannel: cookies.get('subchannel') || subchannel,
104
84
  dt,
@@ -6,8 +6,8 @@ const getDeviceToken = async ({ fpToken, sentry, apiURL }) => {
6
6
  let dt, endpoint
7
7
  try {
8
8
  endpoint = apiURL.replace(reg, 'fp')
9
- const fp = await FingerprintJS.load({ token: fpToken, endpoint })
10
- const result = await fp.get()
9
+ const fp = await FingerprintJS.load({ apiKey: fpToken, endpoint })
10
+ const result = await fp.get({ timeout: 30000 })
11
11
  dt = result.visitorId
12
12
 
13
13
  if (!dt) {