@tbox.cn/app-module-alipay-activity 0.2.3

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.
Files changed (44) hide show
  1. package/AGENTS.md +16 -0
  2. package/LICENSE +21 -0
  3. package/README.md +48 -0
  4. package/dist/bumpin-VKHLYCKG.css +527 -0
  5. package/dist/chunk-RM7IUA3M.js +634 -0
  6. package/dist/client/index.d.ts +11 -0
  7. package/dist/client/index.js +235 -0
  8. package/dist/index.d.ts +7 -0
  9. package/dist/index.js +26 -0
  10. package/dist/linked-card-background-MVGUOJ7J.jpg +0 -0
  11. package/dist/server/index.d.ts +224 -0
  12. package/dist/server/index.js +28 -0
  13. package/package.json +69 -0
  14. package/schemas/credentials/alipay-open-v1.json +12 -0
  15. package/skills/alipay-activity/SKILL.md +59 -0
  16. package/src/client/assets/linked-card-background.jpg +0 -0
  17. package/src/client/assets.d.ts +10 -0
  18. package/src/client/cards/bumpin-activity/index.tsx +213 -0
  19. package/src/client/components/ImageWithFallback.tsx +37 -0
  20. package/src/client/index.ts +18 -0
  21. package/src/client/styles/bumpin.css +527 -0
  22. package/src/client/utils/sanitize-activity-html.ts +40 -0
  23. package/src/index.ts +1 -0
  24. package/src/server/cards/bumpin-activity/meta.ts +44 -0
  25. package/src/server/cards/bumpin-activity/samples.ts +164 -0
  26. package/src/server/handler.ts +87 -0
  27. package/src/server/index.ts +79 -0
  28. package/src/server/integrations/alipay/adapter.ts +210 -0
  29. package/src/server/integrations/alipay/client.ts +127 -0
  30. package/src/server/integrations/alipay/provider.ts +9 -0
  31. package/src/server/ports.ts +68 -0
  32. package/src/server/tools.ts +212 -0
  33. package/tbox.module.json +39 -0
  34. package/tests/adapter.test.ts +178 -0
  35. package/tests/bumpin-card-status.test.tsx +80 -0
  36. package/tests/client.test.ts +93 -0
  37. package/tests/intent-routing.test.ts +118 -0
  38. package/tests/ports.test.ts +160 -0
  39. package/tests/pretool-routing.test.ts +37 -0
  40. package/tests/samples.test.ts +29 -0
  41. package/tests/skill.test.ts +39 -0
  42. package/tests/tools.test.ts +193 -0
  43. package/tsconfig.json +8 -0
  44. package/tsup.config.ts +36 -0
@@ -0,0 +1,10 @@
1
+ /** 静态图片资产类型声明(Vite asset import) */
2
+ declare module '*.png' {
3
+ const url: string;
4
+ export default url;
5
+ }
6
+
7
+ declare module '*.jpg' {
8
+ const url: string;
9
+ export default url;
10
+ }
@@ -0,0 +1,213 @@
1
+ import { useState } from 'react';
2
+ import { CaretDown, CaretUp, Lock, Trophy } from '@phosphor-icons/react';
3
+ import type { AlipayActivityBumpInCardData } from '../../../server/cards/bumpin-activity/meta';
4
+ import { ImageWithFallback } from '../../components/ImageWithFallback';
5
+ import { sanitizeActivityHtml } from '../../utils/sanitize-activity-html';
6
+ // 联单活动本地背景图(steps 模式下作为 fallback,优先使用服务端下发的 backgroundUrl)
7
+ import linkedCardBgUrl from '../../assets/linked-card-background.jpg';
8
+
9
+ const PRIZES_PREVIEW_COUNT = 3;
10
+
11
+ /** 联单「步骤节点」进度渲染(圆形节点 + 发光连接线) */
12
+ function StepsProgress({
13
+ total,
14
+ current,
15
+ unit,
16
+ }: {
17
+ total: number;
18
+ current: number;
19
+ unit: string;
20
+ }) {
21
+ const steps = Array.from({ length: total }, (_, index) => index + 1);
22
+ return (
23
+ <div className="promotion-bumpin__steps">
24
+ {steps.map((stepNumber, index) => {
25
+ const isDone = stepNumber <= current;
26
+ const isLast = index === steps.length - 1;
27
+ const isLocked = isLast && !isDone;
28
+ return (
29
+ <div key={stepNumber} className="promotion-bumpin__step-item">
30
+ {index > 0 && (
31
+ <div
32
+ className={`promotion-bumpin__step-line${isDone && steps[index - 1] <= current ? ' promotion-bumpin__step-line--done' : ''}`}
33
+ />
34
+ )}
35
+ <div
36
+ className={`promotion-bumpin__step-node${isDone ? ' promotion-bumpin__step-node--done' : ''}${isLocked ? ' promotion-bumpin__step-node--locked' : ''}`}
37
+ >
38
+ {isLocked ? (
39
+ <Lock weight="fill" size={20} />
40
+ ) : (
41
+ <span>{stepNumber}</span>
42
+ )}
43
+ </div>
44
+ <span className="promotion-bumpin__step-label">{stepNumber} {unit}</span>
45
+ </div>
46
+ );
47
+ })}
48
+ </div>
49
+ );
50
+ }
51
+
52
+ export function AlipayActivityBumpInCard(props: {
53
+ data: AlipayActivityBumpInCardData;
54
+ cardId?: string;
55
+ isHistory?: boolean;
56
+ }) {
57
+ const { data } = props;
58
+ const isBanner = data.mode === 'banner';
59
+ const isStepsMode = data.progressStyle === 'steps';
60
+ // steps 模式下:优先使用服务端下发的 backgroundUrl,没有则 fallback 到本地联单背景图
61
+ const resolvedBgUrl = data.backgroundUrl ?? (isStepsMode ? linkedCardBgUrl : undefined);
62
+ const hasBackground = Boolean(resolvedBgUrl);
63
+
64
+ const [prizesExpanded, setPrizesExpanded] = useState(false);
65
+
66
+ const totalNum = Number(data.totalProgress ?? '0');
67
+ const currentNum = Number(data.currentProgress ?? '0');
68
+ const progressPercent =
69
+ totalNum > 0 ? Math.min(100, Math.round((currentNum / totalNum) * 100)) : 0;
70
+
71
+ const visibleVouchers = prizesExpanded ? data.vouchers : data.vouchers.slice(0, PRIZES_PREVIEW_COUNT);
72
+ const hiddenCount = data.vouchers.length - PRIZES_PREVIEW_COUNT;
73
+
74
+ // 状态化展示:INIT/PROCESSING 维持现状(不渲染角标);其余三态出角标 + 专属文案变体
75
+ const statusBadge =
76
+ data.actStatus === 'NOT_START'
77
+ ? '未开始'
78
+ : data.actStatus === 'FINISH'
79
+ ? '已结束'
80
+ : data.actStatus === 'RECEIVED'
81
+ ? '已领奖'
82
+ : undefined;
83
+ const statusClass =
84
+ data.actStatus === 'NOT_START'
85
+ ? 'promotion-bumpin__status--pending'
86
+ : data.actStatus === 'RECEIVED'
87
+ ? 'promotion-bumpin__status--received'
88
+ : 'promotion-bumpin__status--terminal';
89
+ // 未开始:有效期行改「{startAtText} 开始」(活动尚未开始,"日前有效"是误导)
90
+ const notStarted = data.actStatus === 'NOT_START';
91
+ const periodDateText = notStarted ? (data.startAtText ?? data.endAtText) : data.endAtText;
92
+ const periodText = periodDateText
93
+ ? periodDateText
94
+ .replace(/^\d{4}-/, '')
95
+ .replace('-', ' 月 ')
96
+ .concat(notStarted && data.startAtText ? ' 日开始' : ' 日前有效')
97
+ : undefined;
98
+
99
+ return (
100
+ <section className="promotion-card promotion-bumpin">
101
+ {/* ── 头部:全幅背景图(联单)或 cover 小图(普通)── */}
102
+ <div
103
+ className={`promotion-bumpin__header${hasBackground ? ' promotion-bumpin__header--bg' : ''}`}
104
+ style={resolvedBgUrl ? { backgroundImage: `url(${resolvedBgUrl})` } : undefined}
105
+ >
106
+ {!hasBackground && data.coverUrl && (
107
+ <ImageWithFallback src={data.coverUrl} alt={data.title} className="promotion-bumpin__cover" />
108
+ )}
109
+ {!hasBackground && !data.coverUrl && (
110
+ <div className="promotion-bumpin__cover-placeholder" />
111
+ )}
112
+
113
+ <div className="promotion-bumpin__header-copy">
114
+ {(data.tagLabel || statusBadge) && (
115
+ <div className="promotion-bumpin__tag-row">
116
+ {data.tagLabel && (
117
+ <span className="promotion-bumpin__tag">{data.tagLabel}</span>
118
+ )}
119
+ {statusBadge && <span className={`promotion-bumpin__status ${statusClass}`}>{statusBadge}</span>}
120
+ </div>
121
+ )}
122
+ <h3 className="promotion-bumpin__title">{data.mainTitle || data.title}</h3>
123
+ {periodText && <small className="promotion-bumpin__period">{periodText}</small>}
124
+ </div>
125
+ </div>
126
+
127
+ {/* ── 进度:steps 步骤节点 或 bar 线性条 ── */}
128
+ {data.totalProgress && (
129
+ <div className="promotion-bumpin__progress">
130
+ {isStepsMode ? (
131
+ <StepsProgress
132
+ total={totalNum}
133
+ current={currentNum}
134
+ unit={data.progressUnit ?? '次'}
135
+ />
136
+ ) : (
137
+ <>
138
+ <div className="promotion-bumpin__progress-bar">
139
+ <div className="promotion-bumpin__progress-fill" style={{ width: `${progressPercent}%` }} />
140
+ </div>
141
+ <span className="promotion-bumpin__progress-text">
142
+ {notStarted
143
+ ? '尚未开始'
144
+ : `已完成 ${data.currentProgress ?? '0'} / ${data.totalProgress} ${data.progressUnit ?? '次'}`}
145
+ </span>
146
+ </>
147
+ )}
148
+ </div>
149
+ )}
150
+
151
+ {/* ── 奖励池 ── */}
152
+ {!isBanner && data.vouchers.length > 0 && (
153
+ <div className="promotion-bumpin__prizes">
154
+ <header className="promotion-bumpin__prizes-header">
155
+ <Trophy weight="fill" />
156
+ {data.actStatus === 'RECEIVED' ? '已领取 · 奖励池' : '奖励池'}
157
+ </header>
158
+ <ul className="promotion-bumpin__prizes-list">
159
+ {visibleVouchers.map((voucher) => (
160
+ <li key={voucher.prizeId} className="promotion-bumpin__prize-item">
161
+ {voucher.itemLogo ? (
162
+ <ImageWithFallback
163
+ src={voucher.itemLogo}
164
+ alt={voucher.voucherName}
165
+ className="promotion-bumpin__prize-logo"
166
+ />
167
+ ) : (
168
+ <span className="promotion-bumpin__prize-logo-placeholder" />
169
+ )}
170
+ <span className="promotion-bumpin__prize-copy">
171
+ <strong>{voucher.voucherName}</strong>
172
+ <small>{voucher.thresholdAmountText || voucher.merchantName}</small>
173
+ </span>
174
+ </li>
175
+ ))}
176
+ </ul>
177
+ {data.vouchers.length > PRIZES_PREVIEW_COUNT && (
178
+ <button
179
+ type="button"
180
+ className="promotion-bumpin__prizes-toggle"
181
+ onClick={() => setPrizesExpanded((prev) => !prev)}
182
+ >
183
+ {prizesExpanded ? (
184
+ <>
185
+ <CaretUp weight="bold" size={12} />
186
+ 收起
187
+ </>
188
+ ) : (
189
+ <>
190
+ <CaretDown weight="bold" size={12} />
191
+ 还有 {hiddenCount} 张,点击展开
192
+ </>
193
+ )}
194
+ </button>
195
+ )}
196
+ </div>
197
+ )}
198
+
199
+ {/* ── 活动规则 ── */}
200
+ {data.description && (
201
+ <div className="promotion-bumpin__rules">
202
+ <header className="promotion-bumpin__rules-header">活动规则</header>
203
+ <div
204
+ className="promotion-bumpin__rules-content"
205
+ dangerouslySetInnerHTML={{ __html: sanitizeActivityHtml(data.description) }}
206
+ />
207
+ </div>
208
+ )}
209
+ </section>
210
+ );
211
+ }
212
+
213
+ export default AlipayActivityBumpInCard;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * 图片 + 加载失败占位(模块自持,禁跨模块依赖)。
3
+ */
4
+ import { useState } from 'react';
5
+ import { ImageSquare } from '@phosphor-icons/react';
6
+
7
+ export function ImageWithFallback(props: {
8
+ src?: string;
9
+ alt: string;
10
+ className?: string;
11
+ size?: number;
12
+ }) {
13
+ const { src, alt, className, size = 40 } = props;
14
+ const [failed, setFailed] = useState(false);
15
+ if (!src || failed) {
16
+ return (
17
+ <div
18
+ className={`img-fallback promotion-image--fallback ${className ?? ''}`.trim()}
19
+ aria-label={alt}
20
+ role="img"
21
+ >
22
+ <ImageSquare weight="duotone" size={Math.round(size * 0.45)} />
23
+ </div>
24
+ );
25
+ }
26
+ return (
27
+ <img
28
+ className={className}
29
+ src={src}
30
+ alt={alt}
31
+ loading="eager"
32
+ decoding="async"
33
+ referrerPolicy="no-referrer"
34
+ onError={() => setFailed(true)}
35
+ />
36
+ );
37
+ }
@@ -0,0 +1,18 @@
1
+ import './styles/bumpin.css';
2
+
3
+ import type { CardComponent } from '@tbox.cn/app-contracts';
4
+ import type { ClientContext, ClientModule } from '@tbox.cn/app-sdk/client';
5
+ import { AlipayActivityBumpInCard } from './cards/bumpin-activity/index';
6
+
7
+ const cards = {
8
+ 'promotion-bumpin-activity': AlipayActivityBumpInCard as CardComponent,
9
+ } as const;
10
+
11
+ export const clientModule = {
12
+ cards,
13
+ register(ctx: ClientContext): void {
14
+ ctx.cards.registerMap(cards);
15
+ },
16
+ } satisfies ClientModule;
17
+
18
+ export default clientModule;