@jetthai/cuora 1.0.107 → 1.0.109

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.109](https://github.com/jetthai/cuora-module/compare/v1.0.108...v1.0.109) (2022-04-08)
6
+
7
+ ### [1.0.108](https://github.com/jetthai/cuora-module/compare/v1.0.107...v1.0.108) (2022-04-07)
8
+
5
9
  ### [1.0.107](https://github.com/jetthai/cuora-module/compare/v1.0.106...v1.0.107) (2022-03-23)
6
10
 
7
11
  ### [1.0.106](https://github.com/jetthai/cuora-module/compare/v1.0.105...v1.0.106) (2022-03-22)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.107",
3
+ "version": "1.0.109",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
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',
@@ -48,9 +51,6 @@ export default function (request) {
48
51
  target: 'authentication',
49
52
  actions: 'setLoginLocal',
50
53
  },
51
- LOGIN_3PARTY: {
52
- actions: 'redirectTo3Party',
53
- },
54
54
  },
55
55
  },
56
56
  authentication: {
@@ -66,6 +66,19 @@ export default function (request) {
66
66
  },
67
67
  },
68
68
  },
69
+ authenticationGuest: {
70
+ invoke: {
71
+ src: 'authenticateGuest',
72
+ onDone: {
73
+ target: 'authenticated',
74
+ actions: 'setToken',
75
+ },
76
+ onError: {
77
+ target: 'idle',
78
+ actions: 'removeToken',
79
+ },
80
+ },
81
+ },
69
82
  authenticated: {
70
83
  invoke: {
71
84
  src: 'fetchUserInfo',
@@ -160,6 +173,9 @@ export default function (request) {
160
173
  CLEAR: {
161
174
  target: '.logout',
162
175
  },
176
+ LOGIN_3PARTY: {
177
+ actions: 'redirectTo3Party',
178
+ },
163
179
  },
164
180
  },
165
181
  {
@@ -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,