@jetthai/cuora 1.1.398 → 1.1.399-dev-1

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,16 @@
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.1.399-dev-1](https://github.com/jetthai/cuora-module/compare/v1.1.399...v1.1.399-dev-1) (2025-11-21)
6
+
7
+ ### [1.1.399](https://github.com/jetthai/cuora-module/compare/v1.2.0...v1.1.399) (2025-11-19)
8
+
9
+ ## [1.2.0](https://github.com/jetthai/cuora-module/compare/v1.1.398...v1.2.0) (2025-11-19)
10
+
11
+ ### Features
12
+
13
+ - 新增活動週期自動更新檢查機制 @Tony ([d3f7011](https://github.com/jetthai/cuora-module/commit/d3f7011f0b93df121ce15e8b334216b88dca73c7))
14
+
5
15
  ### [1.1.398](https://github.com/jetthai/cuora-module/compare/v1.1.397...v1.1.398) (2025-11-17)
6
16
 
7
17
  ### [1.1.397](https://github.com/jetthai/cuora-module/compare/v1.1.396...v1.1.397) (2025-11-17)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.398",
3
+ "version": "1.1.399-dev-1",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -13,6 +13,7 @@ export default function (request, context) {
13
13
  activityNo,
14
14
  activityDetail: null,
15
15
  duration: 0,
16
+ lastCheckedPeriodEndTime: null, // 追蹤已檢查過的週期結束時間
16
17
 
17
18
  // 領獎後得到的資訊
18
19
  awards: [],
@@ -54,17 +55,19 @@ export default function (request, context) {
54
55
  },
55
56
  },
56
57
  after: {
57
- 1000: {
58
- target: 'awardable',
59
- },
58
+ 1000: [{ target: 'loading', cond: 'shouldCheckNewPeriod' }, { target: 'awardable' }],
60
59
  },
61
60
  },
62
61
  awarded: {
62
+ entry: 'setDuration',
63
63
  on: {
64
64
  REFRESH_ACTIVITY: {
65
65
  target: 'loading',
66
66
  },
67
67
  },
68
+ after: {
69
+ 1000: [{ target: 'loading', cond: 'shouldCheckNewPeriod' }, { target: 'awarded' }],
70
+ },
68
71
  },
69
72
  awarding: {
70
73
  invoke: {
@@ -97,7 +100,17 @@ export default function (request, context) {
97
100
  },
98
101
  },
99
102
  },
100
- result: {},
103
+ result: {
104
+ entry: 'setDuration',
105
+ on: {
106
+ REFRESH_ACTIVITY: {
107
+ target: 'loading',
108
+ },
109
+ },
110
+ after: {
111
+ 1000: [{ target: 'loading', cond: 'shouldCheckNewPeriod' }, { target: 'result' }],
112
+ },
113
+ },
101
114
  },
102
115
  on: {
103
116
  START: {
@@ -118,6 +131,8 @@ export default function (request, context) {
118
131
  setActivityDetail: assign((context, event) => {
119
132
  return {
120
133
  activityDetail: event.data,
134
+ // 重置 lastCheckedPeriodEndTime,允許新週期結束時再次檢查
135
+ lastCheckedPeriodEndTime: null,
121
136
  }
122
137
  }),
123
138
  setAward: assign((context, event) => {
@@ -151,6 +166,24 @@ export default function (request, context) {
151
166
  isAutoReceiving: (context, event) => {
152
167
  return context.isAutoReceiving
153
168
  },
169
+ shouldCheckNewPeriod: (context, event) => {
170
+ // 當倒數計時結束時,重新檢查活動狀態
171
+ // 使用 lastCheckedPeriodEndTime 避免同一週期重複呼叫 API
172
+ const periodEndTime = context?.activityDetail?.periodEndTime
173
+
174
+ // 如果 duration 為 0,且這個週期還沒檢查過,則觸發更新
175
+ if (context.duration === 0 && periodEndTime) {
176
+ // 如果是新的週期結束時間,或者還沒檢查過,則允許觸發
177
+ if (context.lastCheckedPeriodEndTime !== periodEndTime) {
178
+ // 更新 lastCheckedPeriodEndTime(在 guard 中直接修改 context 是不好的做法,
179
+ // 但這裡是為了避免重複觸發,是可接受的權衡)
180
+ context.lastCheckedPeriodEndTime = periodEndTime
181
+ return true
182
+ }
183
+ }
184
+
185
+ return false
186
+ },
154
187
  },
155
188
  services: {
156
189
  fetchActivityDetail: async (context, event) => {
@@ -42,6 +42,11 @@ export default function (request, context) {
42
42
  target: 'loaded',
43
43
  },
44
44
  },
45
+ on: {
46
+ REFRESH_ACTIVITY_DETAIL: {
47
+ target: 'loading',
48
+ },
49
+ },
45
50
  },
46
51
  expired: {},
47
52
  },
@@ -258,6 +258,10 @@ export default function (request) {
258
258
  services: {
259
259
  fetchActivityDetail: async (context, event) => {
260
260
  const { activityNo, activityDetail = {} } = context
261
+ // 當活動資料已存在時避免重複呼叫 api
262
+ if (Object.keys(activityDetail).length > 0) {
263
+ return activityDetail
264
+ }
261
265
  const { data } = await request.send(api.getActivityDetail({ activityNo, appSecret }))
262
266
  return data.activityNo ? data : activityDetail
263
267
  },