@jetthai/cuora 1.0.115 → 1.0.117

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,7 +2,11 @@
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.115](https://github.com/jetthai/cuora-module/compare/v1.0.114...v1.0.115) (2022-04-29)
5
+ ### [1.0.117](https://github.com/jetthai/cuora-module/compare/v1.0.116...v1.0.117) (2022-05-18)
6
+
7
+ ### [1.0.116](https://github.com/jetthai/cuora-module/compare/v1.0.115...v1.0.116) (2022-05-12)
8
+
9
+ ### [1.0.115](https://github.com/jetthai/cuora-module/compare/v1.0.114...v1.0.115) (2022-05-12)
6
10
 
7
11
  ### [1.0.114](https://github.com/jetthai/cuora-module/compare/v1.0.113...v1.0.114) (2022-04-27)
8
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.115",
3
+ "version": "1.0.117",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -40,7 +40,12 @@ export default {
40
40
  method: 'post',
41
41
  params: { activityNo, receiveNo, appSecret, attended },
42
42
  }),
43
- getRewardList: ({ count, appSecret }) => ({ url: 'activities/rewards', method: 'get', params: { count, appSecret } }),
43
+ getTotalReward: ({ rewardType }) => ({
44
+ url: 'activities/rewardAmount',
45
+ method: 'get',
46
+ params: { rewardType },
47
+ }),
48
+ getRewardList: ({ rewardType, count, appSecret }) => ({ url: 'activities/rewards', method: 'get', params: { rewardType, count, appSecret } }),
44
49
  exchange: (data) => ({ url: 'activities/exchange', method: 'post', params: data }),
45
- collect: ({ appSecret }) => ({ url: 'activities/collect', method: 'post', params: { appSecret } }),
50
+ collect: (data) => ({ url: 'activities/collect', method: 'post', params: data }),
46
51
  }
@@ -264,18 +264,18 @@ export default function (request) {
264
264
  }),
265
265
  redirectTo3Party: async (context, event) => {
266
266
  const { provider, channel, subchannel } = event.data
267
- const dt = await getDeviceToken({ fpToken, sentry, apiURL: request.config.apiURL })
267
+ // const dt = await getDeviceToken({ fpToken, sentry, apiURL: request.config.apiURL })
268
268
  const redirectURL = urljoin(
269
269
  request.config.fullURL,
270
270
  'login?' +
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
- })
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
+ })
279
279
  )
280
280
  window.location.href = redirectURL
281
281
  },
@@ -0,0 +1,254 @@
1
+ import { createMachine, assign } from 'xstate'
2
+ import api from '../api/user'
3
+ import user from '../api/user'
4
+
5
+ export default function (request) {
6
+ return createMachine(
7
+ {
8
+ id: 'auth_otp',
9
+ initial: 'idle',
10
+ context: {
11
+ strategy: null,
12
+ userInfo: null,
13
+ error: null,
14
+ countryCode: null,
15
+ phone: null,
16
+ email: null,
17
+ target: null,
18
+ requestId: null,
19
+ ttl: 0,
20
+ },
21
+ states: {
22
+ idle: {
23
+ on: {
24
+ SET_STRATEGY: {
25
+ target: 'fetching',
26
+ actions: 'setStrategy',
27
+ },
28
+ },
29
+ },
30
+ fetching: {
31
+ invoke: {
32
+ src: 'fetchUserInfo',
33
+ onDone: {
34
+ target: 'checking',
35
+ actions: 'setUserInfo',
36
+ },
37
+ onError: {
38
+ target: 'fail',
39
+ },
40
+ },
41
+ },
42
+ checking: {
43
+ always: [
44
+ { target: 'verified', cond: 'isVerified' },
45
+ { target: 'notVerified.email', cond: 'isEmailNotVerified' },
46
+ { target: 'notVerified.phone', cond: 'isPhoneNotVerified' },
47
+ { target: 'notVerified', cond: 'isNotVerified' },
48
+ ],
49
+ },
50
+ notVerified: {
51
+ initial: 'checkingStatus',
52
+ states: {
53
+ checkingStatus: {
54
+ invoke: {
55
+ src: 'verify',
56
+ onDone: {
57
+ target: 'otp',
58
+ actions: 'setVerificationData',
59
+ },
60
+ onError: {
61
+ target: 'errorChecking',
62
+ actions: 'setError',
63
+ },
64
+ },
65
+ },
66
+ errorChecking: {
67
+ always: [{ target: 'phone', cond: 'hasNoPhone' }, { target: '#auth_otp.fail' }],
68
+ },
69
+ phone: {
70
+ on: {
71
+ SEND_PHONE: {
72
+ target: 'sendingPhone',
73
+ actions: 'setPhone',
74
+ },
75
+ },
76
+ },
77
+ email: {
78
+ on: {
79
+ SEND_EMAIL: {
80
+ target: 'sendingEmail',
81
+ actions: 'setEmail',
82
+ },
83
+ },
84
+ },
85
+ sendingPhone: {
86
+ invoke: {
87
+ src: 'sendPhone',
88
+ onDone: {
89
+ target: 'checkingStatus',
90
+ },
91
+ onError: { target: 'phone' },
92
+ },
93
+ },
94
+ sendingEmail: {
95
+ invoke: {
96
+ src: 'sendEmail',
97
+ onDone: {
98
+ target: 'checkingStatus',
99
+ },
100
+ onError: { target: 'email' },
101
+ },
102
+ },
103
+ otp: {
104
+ type: 'parallel',
105
+ states: {
106
+ countdown: {
107
+ after: {
108
+ 1000: {
109
+ target: 'countdown',
110
+ actions: 'decreaseTtl',
111
+ cond: (context) => context.ttl > 0,
112
+ },
113
+ },
114
+ },
115
+ verification: {
116
+ initial: 'idle',
117
+ states: {
118
+ idle: {
119
+ on: {
120
+ SEND_OTP: {
121
+ target: 'acknowledging',
122
+ },
123
+ RESET_OTP: {
124
+ target: 'reset',
125
+ },
126
+ RESEND_PHONE: {
127
+ target: '#auth_otp.notVerified.phone',
128
+ },
129
+ },
130
+ },
131
+ acknowledging: {
132
+ invoke: {
133
+ src: 'acknowledge',
134
+ onDone: {
135
+ target: '#auth_otp.verified',
136
+ },
137
+ onError: {
138
+ target: 'idle',
139
+ },
140
+ },
141
+ },
142
+ reset: {
143
+ invoke: {
144
+ src: 'resetOtp',
145
+ onDone: {
146
+ target: 'idle',
147
+ actions: 'setVerificationData',
148
+ },
149
+ onError: { target: 'idle' },
150
+ },
151
+ },
152
+ },
153
+ },
154
+ },
155
+ },
156
+ },
157
+ },
158
+ verified: {},
159
+ fail: {},
160
+ },
161
+ },
162
+ {
163
+ actions: {
164
+ setStrategy: assign((context, event) => {
165
+ return {
166
+ strategy: event.data,
167
+ }
168
+ }),
169
+ setUserInfo: assign((context, event) => {
170
+ return {
171
+ userInfo: event.data,
172
+ }
173
+ }),
174
+ setVerificationData: assign((context, event) => {
175
+ const { requestId, ttl, target } = event.data
176
+ return {
177
+ requestId,
178
+ ttl: ttl * 1000,
179
+ target,
180
+ }
181
+ }),
182
+ decreaseTtl: assign((context, evnet) => {
183
+ const ms = context.ttl
184
+ return {
185
+ ttl: Math.max(ms - 1000, 0),
186
+ }
187
+ }),
188
+ setError: assign((context, event) => {
189
+ return {
190
+ error: event.data,
191
+ }
192
+ }),
193
+ setPhone: assign((context, event) => {
194
+ const { countryCode, phone } = event.data
195
+ return {
196
+ countryCode,
197
+ phone,
198
+ }
199
+ }),
200
+ setEmail: assign((context, event) => {
201
+ const { email } = event.data
202
+ return {
203
+ email,
204
+ }
205
+ }),
206
+ },
207
+ guards: {
208
+ isVerified: (context, event) => {
209
+ return context.userInfo?.verification_status === 1
210
+ },
211
+ isNotVerified: (context, event) => {
212
+ return context.userInfo && context.userInfo.verification_status !== 1
213
+ },
214
+ isPhoneNotVerified: (context, event) => {
215
+ const { strategy, userInfo } = context
216
+ return strategy === 'phone' && userInfo && userInfo.verification_status !== 1 && !userInfo.phone
217
+ },
218
+ isEmailNotVerified: (context, event) => {
219
+ const { strategy, userInfo } = context
220
+ return strategy === 'email' && userInfo && userInfo.verification_status !== 1 && !userInfo.email
221
+ },
222
+ hasNoPhone: (context, event) => {
223
+ const { error } = context
224
+ return error.code === 'ERR_F106'
225
+ },
226
+ },
227
+ services: {
228
+ fetchUserInfo: async (context, event) => {
229
+ return await request.send(api.getUserInfo())
230
+ },
231
+ verify: async (context, event) => {
232
+ return await request.send(api.verifyV2Initiate({ strategy: context.strategy }))
233
+ },
234
+ sendPhone: async (context, event) => {
235
+ const { countryCode, phone } = context
236
+ return await request.send(api.updateUserInfo({ countryCode, phone }))
237
+ },
238
+ sendEmail: async (context, event) => {
239
+ const { email } = context
240
+ return await request.send(api.updateUserInfo({ email }))
241
+ },
242
+ resetOtp: async (context, event) => {
243
+ const { requestId, target } = context
244
+ return await request.send(api.otpReset({ requestId, target }))
245
+ },
246
+ acknowledge: async (context, event) => {
247
+ const { requestId, target } = context
248
+ const code = event.data
249
+ return await request.send(user.otpAcknowledge({ requestId, target, code }))
250
+ },
251
+ },
252
+ }
253
+ )
254
+ }
@@ -35,7 +35,7 @@ export default function (request) {
35
35
  emergencyBroadcast: null,
36
36
  normalBroadcast: null,
37
37
  sentEmergencyBroadcastList: [],
38
- sentNormalBroadcastList: []
38
+ sentNormalBroadcastList: [],
39
39
  },
40
40
  states: {
41
41
  config: {
@@ -187,7 +187,7 @@ export default function (request) {
187
187
  emergencyBroadcast: nextEmergencyBroadcast,
188
188
  sentEmergencyBroadcastList: sentEmergencyList,
189
189
  normalBroadcast: nextNormalBroadcast,
190
- sentNormalBroadcastList: sentNormalList
190
+ sentNormalBroadcastList: sentNormalList,
191
191
  }
192
192
  }),
193
193
  resetBroadcast: assign((context, event) => {
@@ -195,7 +195,7 @@ export default function (request) {
195
195
  emergencyBroadcast: null,
196
196
  sentEmergencyBroadcastList: [],
197
197
  normalBroadcast: null,
198
- sentNormalBroadcastList: []
198
+ sentNormalBroadcastList: [],
199
199
  }
200
200
  }),
201
201
  },
@@ -2,8 +2,6 @@ import { assign, createMachine } from 'xstate'
2
2
  import mailbox from '../api/mailbox'
3
3
  import activity from '../api/activity'
4
4
 
5
- // todo - 自動開啟系統信
6
- // todo - 更新未讀數量
7
5
  const messageState = {
8
6
  // always: [{ actions: 'showUnread', cond: 'isShowUnread' }],
9
7
  initial: 'idle',
@@ -224,7 +222,7 @@ export default function (request) {
224
222
  },
225
223
  fetchMessages: async (context, event) => {
226
224
  const { isRewardListEnable, currentTab, inbox } = JSON.parse(JSON.stringify(context))
227
- if (isRewardListEnable && currentTab === 'REWARD') {
225
+ if (isRewardListEnable && (currentTab === 'REWARD' || currentTab === 'DIAMOND')) {
228
226
  const { data } = await request.send(activity.getRewardList({ count: 30, appSecret }))
229
227
  inbox[currentTab] = { data, page: 0, totalPage: 1 }
230
228
  } else {
@@ -25,6 +25,7 @@ import deposit from './deposit'
25
25
  import bonus from './bonus'
26
26
  import leaderboard from './leaderboard'
27
27
  import auth_otp_v2 from './auth_otp_v2'
28
+ import auth_otp_v3 from './auth_otp_v3'
28
29
 
29
30
  export default {
30
31
  ...activity,
@@ -55,4 +56,5 @@ export default {
55
56
  bonus,
56
57
  leaderboard,
57
58
  auth_otp_v2,
59
+ auth_otp_v3,
58
60
  }
@@ -8,7 +8,8 @@ export default function (request) {
8
8
  id: 'reward',
9
9
  type: 'parallel',
10
10
  context: {
11
- rewardList: [],
11
+ otherRewardList: [],
12
+ pointsRewardList: [],
12
13
  callback: () => {},
13
14
  },
14
15
  states: {
@@ -48,6 +49,10 @@ export default function (request) {
48
49
  target: 'receiving',
49
50
  actions: 'setCallback',
50
51
  },
52
+ RECEIVE_ALL_POINTS: {
53
+ target: 'allPointsReceiving',
54
+ actions: 'setCallback',
55
+ },
51
56
  },
52
57
  },
53
58
  receiving: {
@@ -62,6 +67,18 @@ export default function (request) {
62
67
  },
63
68
  },
64
69
  },
70
+ allPointsReceiving: {
71
+ invoke: {
72
+ src: 'receiveAllPoints',
73
+ onDone: {
74
+ target: 'idle',
75
+ actions: [send({ type: 'REFRESH' }), 'doCallback'],
76
+ },
77
+ onError: {
78
+ target: 'idle',
79
+ },
80
+ },
81
+ },
65
82
  },
66
83
  },
67
84
  },
@@ -70,7 +87,8 @@ export default function (request) {
70
87
  actions: {
71
88
  setRewardList: assign((context, event) => {
72
89
  return {
73
- rewardList: event.data || [],
90
+ otherRewardList: event.data[0]?.data || [],
91
+ pointsRewardList: event.data[1]?.data || [],
74
92
  }
75
93
  }),
76
94
  setCallback: assign((context, event) => {
@@ -84,13 +102,18 @@ export default function (request) {
84
102
  },
85
103
  services: {
86
104
  fetchRewardList: async (context, event) => {
87
- const { data } = await request.send(activity.getRewardList({ count: 30, appSecret }))
88
- return data
105
+ const getPointsRewardAPI = request.send(activity.getRewardList({ rewardType: 'POINTS', count: 30, appSecret }))
106
+ const getOtherRewardAPI = request.send(activity.getRewardList({ rewardType: 'CASH,FREE', count: 30, appSecret }))
107
+ const [otherRewardList, pointsRewardList] = await Promise.all([getOtherRewardAPI, getPointsRewardAPI])
108
+ return [otherRewardList, pointsRewardList]
89
109
  },
90
110
  receiveReward: async (context, event) => {
91
111
  const { activityNo, receiveNo, attended } = event.data
92
112
  return await request.send(activity.getReward({ activityNo, receiveNo, appSecret, attended }))
93
113
  },
114
+ receiveAllPoints: async (context, event) => {
115
+ return await request.send(activity.collect({ collectType: 'collectPoints', appSecret }))
116
+ },
94
117
  },
95
118
  }
96
119
  )