@jetthai/cuora 1.0.75 → 1.0.77

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.77](https://github.com/jetthai/cuora-module/compare/v1.0.76...v1.0.77) (2022-01-12)
6
+
7
+ ### [1.0.76](https://github.com/jetthai/cuora-module/compare/v1.0.75...v1.0.76) (2022-01-11)
8
+
5
9
  ### [1.0.75](https://github.com/jetthai/cuora-module/compare/v1.0.74...v1.0.75) (2022-01-07)
6
10
 
7
11
  ### [1.0.74](https://github.com/jetthai/cuora-module/compare/v1.0.73...v1.0.74) (2022-01-06)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.75",
3
+ "version": "1.0.77",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -59,7 +59,7 @@ export default function (request) {
59
59
  invoke: {
60
60
  src: 'authenticate',
61
61
  onDone: {
62
- target: 'login',
62
+ target: 'authenticated',
63
63
  actions: 'setToken',
64
64
  },
65
65
  onError: {
@@ -68,65 +68,97 @@ export default function (request) {
68
68
  },
69
69
  },
70
70
  },
71
- login: {
72
- type: 'parallel',
71
+ authenticated: {
72
+ invoke: {
73
+ src: 'fetchUserInfo',
74
+ onDone: {
75
+ target: 'inline',
76
+ actions: ['setUserInfo', 'extendToken'],
77
+ },
78
+ onError: {
79
+ target: 'leaving',
80
+ },
81
+ },
82
+ },
83
+ inline: {
84
+ initial: 'pending',
73
85
  states: {
74
- timer: {
75
- initial: 'running',
76
- states: {
77
- running: {
78
- invoke: {
79
- src: 'fetchUserInfo',
80
- onDone: {
81
- target: 'pending',
82
- actions: ['setUserInfo', 'extendToken', send({ type: 'CHECK' })],
83
- },
84
- onError: {
85
- target: '#auth.logout',
86
- },
87
- },
86
+ pending: {
87
+ always: [{ target: '#auth.login', cond: 'isNotInline' }],
88
+ after: {
89
+ TIMEOUT: {
90
+ target: 'fetching',
88
91
  },
89
- pending: {
90
- after: {
91
- TIMEOUT: {
92
- target: 'running',
93
- },
94
- },
92
+ },
93
+ },
94
+ fetching: {
95
+ invoke: {
96
+ src: 'fetchUserInfo',
97
+ onDone: {
98
+ target: 'pending',
99
+ actions: ['setUserInfo', 'extendToken'],
100
+ },
101
+ onError: {
102
+ target: '#auth.leaving',
95
103
  },
96
104
  },
97
105
  },
98
- user: {
99
- initial: 'idle',
100
- states: {
101
- idle: {},
102
- normal: {},
103
- inline: {},
106
+ },
107
+ },
108
+ login: {
109
+ initial: 'fetching',
110
+ states: {
111
+ fetching: {
112
+ invoke: {
113
+ src: 'fetchUserInfo',
114
+ onDone: {
115
+ target: 'pending',
116
+ actions: ['setUserInfo', 'extendToken'],
117
+ },
118
+ onError: {
119
+ target: '#auth.leaving',
120
+ },
104
121
  },
105
- on: {
106
- CHECK: [{ target: '.inline', cond: 'isInline' }, { target: '.normal' }],
122
+ },
123
+ pending: {
124
+ after: {
125
+ TIMEOUT: {
126
+ target: 'fetching',
127
+ },
107
128
  },
108
129
  },
109
130
  },
110
131
  on: {
111
132
  LOGOUT: {
112
- target: '#auth.logout',
133
+ target: 'leaving',
113
134
  },
114
135
  },
115
136
  },
116
- logout: {
137
+ leaving: {
117
138
  invoke: {
118
139
  src: 'logout',
119
140
  onDone: {
120
- target: 'idle',
121
- actions: 'removeToken',
141
+ target: 'logout',
122
142
  },
123
143
  onError: {
144
+ target: 'logout',
145
+ },
146
+ },
147
+ },
148
+ logout: {
149
+ after: {
150
+ 0: {
124
151
  target: 'idle',
125
152
  actions: 'removeToken',
126
153
  },
127
154
  },
128
155
  },
129
156
  },
157
+ on: {
158
+ CLEAR: {
159
+ target: '.logout',
160
+ },
161
+ },
130
162
  },
131
163
  {
132
164
  delays: {
@@ -142,6 +174,9 @@ export default function (request) {
142
174
  isInline: (context, event) => {
143
175
  return context.userInfo?.rank >= 0
144
176
  },
177
+ isNotInline: (context, event) => {
178
+ return !(context.userInfo?.rank >= 0)
179
+ },
145
180
  },
146
181
  actions: {
147
182
  setLoginPhone: assign((context, event) => {
@@ -210,14 +245,15 @@ export default function (request) {
210
245
  return { token }
211
246
  }),
212
247
  redirectTo3Party: (context, event) => {
248
+ const { provider, channel = 'official', subchannel = 'pwa' } = event.data
213
249
  const redirectURL = urljoin(
214
250
  request.config.fullURL,
215
251
  'login?' +
216
252
  qs.stringify({
217
- provider: event.data,
253
+ provider,
218
254
  redirectURI: `${window.location.protocol}//${window.location.host}`,
219
- channel: 'official',
220
- subchannel: 'pwa',
255
+ channel,
256
+ subchannel,
221
257
  })
222
258
  )
223
259
  window.location.href = redirectURL
@@ -57,7 +57,7 @@ export default function () {
57
57
  },
58
58
  guards: {
59
59
  isLogout: (context, event) => {
60
- return ['ERR_A201', 'ERR_A204', 'ERR_A103', 'ERR_A104', 'ERR_A108', 'ERR_F108'].includes(context.error.code)
60
+ return ['ERR_A201', 'ERR_A204', 'ERR_A103', 'ERR_A104', 'ERR_A108', 'ERR_F108', 'ERR_A113'].includes(context.error.code)
61
61
  },
62
62
  isNoBalance: (context, event) => {
63
63
  return context.error.code === 'ERR_G106'
@@ -9,6 +9,8 @@ export default function (request) {
9
9
  context: {
10
10
  email: '',
11
11
  password: '',
12
+ channel: null,
13
+ subchannel: null,
12
14
  },
13
15
  states: {
14
16
  idle: {
@@ -67,10 +69,12 @@ export default function (request) {
67
69
  {
68
70
  actions: {
69
71
  setForm: assign((context, event) => {
70
- const { email, password } = event.data
72
+ const { email, password, channel, subchannel } = event.data
71
73
  return {
72
74
  email,
73
75
  password,
76
+ channel,
77
+ subchannel,
74
78
  }
75
79
  }),
76
80
  },
@@ -84,8 +88,8 @@ export default function (request) {
84
88
  },
85
89
  services: {
86
90
  signUp: async (context, event) => {
87
- const { email, password } = context
88
- return await request.send(auth.register({ provider: 'email', email, password }))
91
+ const { email, password, channel, subchannel } = context
92
+ return await request.send(auth.register({ provider: 'email', email, password, channel, subchannel }))
89
93
  },
90
94
  },
91
95
  }
@@ -71,14 +71,6 @@ export default class Request {
71
71
 
72
72
  _createConfig(req, cancelToken) {
73
73
  const { method, url, params, isPublic, isFormData } = req
74
- // const config = { baseURL: this.config.fullURL, method, url, cancelToken, isPublic: req.isPublic }
75
- // if (method.toUpperCase() === 'GET') {
76
- // config.params = pickBy(params, isValid)
77
- // } else {
78
- // config.data = pickBy(params, isValid)
79
- // }
80
- // return config
81
-
82
74
  if (isFormData) {
83
75
  return {
84
76
  baseURL: this.config.fullURL,