@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.
- package/AGENTS.md +16 -0
- package/LICENSE +21 -0
- package/README.md +48 -0
- package/dist/bumpin-VKHLYCKG.css +527 -0
- package/dist/chunk-RM7IUA3M.js +634 -0
- package/dist/client/index.d.ts +11 -0
- package/dist/client/index.js +235 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +26 -0
- package/dist/linked-card-background-MVGUOJ7J.jpg +0 -0
- package/dist/server/index.d.ts +224 -0
- package/dist/server/index.js +28 -0
- package/package.json +69 -0
- package/schemas/credentials/alipay-open-v1.json +12 -0
- package/skills/alipay-activity/SKILL.md +59 -0
- package/src/client/assets/linked-card-background.jpg +0 -0
- package/src/client/assets.d.ts +10 -0
- package/src/client/cards/bumpin-activity/index.tsx +213 -0
- package/src/client/components/ImageWithFallback.tsx +37 -0
- package/src/client/index.ts +18 -0
- package/src/client/styles/bumpin.css +527 -0
- package/src/client/utils/sanitize-activity-html.ts +40 -0
- package/src/index.ts +1 -0
- package/src/server/cards/bumpin-activity/meta.ts +44 -0
- package/src/server/cards/bumpin-activity/samples.ts +164 -0
- package/src/server/handler.ts +87 -0
- package/src/server/index.ts +79 -0
- package/src/server/integrations/alipay/adapter.ts +210 -0
- package/src/server/integrations/alipay/client.ts +127 -0
- package/src/server/integrations/alipay/provider.ts +9 -0
- package/src/server/ports.ts +68 -0
- package/src/server/tools.ts +212 -0
- package/tbox.module.json +39 -0
- package/tests/adapter.test.ts +178 -0
- package/tests/bumpin-card-status.test.tsx +80 -0
- package/tests/client.test.ts +93 -0
- package/tests/intent-routing.test.ts +118 -0
- package/tests/ports.test.ts +160 -0
- package/tests/pretool-routing.test.ts +37 -0
- package/tests/samples.test.ts +29 -0
- package/tests/skill.test.ts +39 -0
- package/tests/tools.test.ts +193 -0
- package/tsconfig.json +8 -0
- package/tsup.config.ts +36 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// src/client/index.ts
|
|
2
|
+
import "../bumpin-VKHLYCKG.css";
|
|
3
|
+
|
|
4
|
+
// src/client/cards/bumpin-activity/index.tsx
|
|
5
|
+
import { useState as useState2 } from "react";
|
|
6
|
+
import { CaretDown, CaretUp, Lock, Trophy } from "@phosphor-icons/react";
|
|
7
|
+
|
|
8
|
+
// src/client/components/ImageWithFallback.tsx
|
|
9
|
+
import { useState } from "react";
|
|
10
|
+
import { ImageSquare } from "@phosphor-icons/react";
|
|
11
|
+
import { jsx } from "react/jsx-runtime";
|
|
12
|
+
function ImageWithFallback(props) {
|
|
13
|
+
const { src, alt, className, size = 40 } = props;
|
|
14
|
+
const [failed, setFailed] = useState(false);
|
|
15
|
+
if (!src || failed) {
|
|
16
|
+
return /* @__PURE__ */ jsx(
|
|
17
|
+
"div",
|
|
18
|
+
{
|
|
19
|
+
className: `img-fallback promotion-image--fallback ${className ?? ""}`.trim(),
|
|
20
|
+
"aria-label": alt,
|
|
21
|
+
role: "img",
|
|
22
|
+
children: /* @__PURE__ */ jsx(ImageSquare, { weight: "duotone", size: Math.round(size * 0.45) })
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
return /* @__PURE__ */ jsx(
|
|
27
|
+
"img",
|
|
28
|
+
{
|
|
29
|
+
className,
|
|
30
|
+
src,
|
|
31
|
+
alt,
|
|
32
|
+
loading: "eager",
|
|
33
|
+
decoding: "async",
|
|
34
|
+
referrerPolicy: "no-referrer",
|
|
35
|
+
onError: () => setFailed(true)
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/client/utils/sanitize-activity-html.ts
|
|
41
|
+
var DROP_TAGS = /* @__PURE__ */ new Set([
|
|
42
|
+
"script",
|
|
43
|
+
"iframe",
|
|
44
|
+
"object",
|
|
45
|
+
"embed",
|
|
46
|
+
"style",
|
|
47
|
+
"link",
|
|
48
|
+
"meta",
|
|
49
|
+
"base",
|
|
50
|
+
"form",
|
|
51
|
+
"input",
|
|
52
|
+
"svg",
|
|
53
|
+
"math"
|
|
54
|
+
]);
|
|
55
|
+
var URL_ATTRS = /* @__PURE__ */ new Set(["href", "src", "xlink:href", "formaction", "action", "poster", "background"]);
|
|
56
|
+
function sanitizeActivityHtml(html) {
|
|
57
|
+
if (typeof DOMParser === "undefined") return "";
|
|
58
|
+
const doc = new DOMParser().parseFromString(html, "text/html");
|
|
59
|
+
const walk = (node) => {
|
|
60
|
+
for (const child of [...node.children]) {
|
|
61
|
+
if (DROP_TAGS.has(child.tagName.toLowerCase())) {
|
|
62
|
+
child.remove();
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
for (const attr of [...child.attributes]) {
|
|
66
|
+
const name = attr.name.toLowerCase();
|
|
67
|
+
if (name.startsWith("on")) {
|
|
68
|
+
child.removeAttribute(attr.name);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (URL_ATTRS.has(name)) {
|
|
72
|
+
const value = attr.value.trim().toLowerCase();
|
|
73
|
+
const isJs = value.startsWith("javascript:");
|
|
74
|
+
const isData = value.startsWith("data:") && !value.startsWith("data:image/");
|
|
75
|
+
if (isJs || isData) child.removeAttribute(attr.name);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
walk(child);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
walk(doc.body);
|
|
82
|
+
return doc.body.innerHTML;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/client/assets/linked-card-background.jpg
|
|
86
|
+
var linked_card_background_default = "../linked-card-background-MVGUOJ7J.jpg";
|
|
87
|
+
|
|
88
|
+
// src/client/cards/bumpin-activity/index.tsx
|
|
89
|
+
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
90
|
+
var PRIZES_PREVIEW_COUNT = 3;
|
|
91
|
+
function StepsProgress({
|
|
92
|
+
total,
|
|
93
|
+
current,
|
|
94
|
+
unit
|
|
95
|
+
}) {
|
|
96
|
+
const steps = Array.from({ length: total }, (_, index) => index + 1);
|
|
97
|
+
return /* @__PURE__ */ jsx2("div", { className: "promotion-bumpin__steps", children: steps.map((stepNumber, index) => {
|
|
98
|
+
const isDone = stepNumber <= current;
|
|
99
|
+
const isLast = index === steps.length - 1;
|
|
100
|
+
const isLocked = isLast && !isDone;
|
|
101
|
+
return /* @__PURE__ */ jsxs("div", { className: "promotion-bumpin__step-item", children: [
|
|
102
|
+
index > 0 && /* @__PURE__ */ jsx2(
|
|
103
|
+
"div",
|
|
104
|
+
{
|
|
105
|
+
className: `promotion-bumpin__step-line${isDone && steps[index - 1] <= current ? " promotion-bumpin__step-line--done" : ""}`
|
|
106
|
+
}
|
|
107
|
+
),
|
|
108
|
+
/* @__PURE__ */ jsx2(
|
|
109
|
+
"div",
|
|
110
|
+
{
|
|
111
|
+
className: `promotion-bumpin__step-node${isDone ? " promotion-bumpin__step-node--done" : ""}${isLocked ? " promotion-bumpin__step-node--locked" : ""}`,
|
|
112
|
+
children: isLocked ? /* @__PURE__ */ jsx2(Lock, { weight: "fill", size: 20 }) : /* @__PURE__ */ jsx2("span", { children: stepNumber })
|
|
113
|
+
}
|
|
114
|
+
),
|
|
115
|
+
/* @__PURE__ */ jsxs("span", { className: "promotion-bumpin__step-label", children: [
|
|
116
|
+
stepNumber,
|
|
117
|
+
" ",
|
|
118
|
+
unit
|
|
119
|
+
] })
|
|
120
|
+
] }, stepNumber);
|
|
121
|
+
}) });
|
|
122
|
+
}
|
|
123
|
+
function AlipayActivityBumpInCard(props) {
|
|
124
|
+
const { data } = props;
|
|
125
|
+
const isBanner = data.mode === "banner";
|
|
126
|
+
const isStepsMode = data.progressStyle === "steps";
|
|
127
|
+
const resolvedBgUrl = data.backgroundUrl ?? (isStepsMode ? linked_card_background_default : void 0);
|
|
128
|
+
const hasBackground = Boolean(resolvedBgUrl);
|
|
129
|
+
const [prizesExpanded, setPrizesExpanded] = useState2(false);
|
|
130
|
+
const totalNum = Number(data.totalProgress ?? "0");
|
|
131
|
+
const currentNum = Number(data.currentProgress ?? "0");
|
|
132
|
+
const progressPercent = totalNum > 0 ? Math.min(100, Math.round(currentNum / totalNum * 100)) : 0;
|
|
133
|
+
const visibleVouchers = prizesExpanded ? data.vouchers : data.vouchers.slice(0, PRIZES_PREVIEW_COUNT);
|
|
134
|
+
const hiddenCount = data.vouchers.length - PRIZES_PREVIEW_COUNT;
|
|
135
|
+
const statusBadge = data.actStatus === "NOT_START" ? "\u672A\u5F00\u59CB" : data.actStatus === "FINISH" ? "\u5DF2\u7ED3\u675F" : data.actStatus === "RECEIVED" ? "\u5DF2\u9886\u5956" : void 0;
|
|
136
|
+
const statusClass = data.actStatus === "NOT_START" ? "promotion-bumpin__status--pending" : data.actStatus === "RECEIVED" ? "promotion-bumpin__status--received" : "promotion-bumpin__status--terminal";
|
|
137
|
+
const notStarted = data.actStatus === "NOT_START";
|
|
138
|
+
const periodDateText = notStarted ? data.startAtText ?? data.endAtText : data.endAtText;
|
|
139
|
+
const periodText = periodDateText ? periodDateText.replace(/^\d{4}-/, "").replace("-", " \u6708 ").concat(notStarted && data.startAtText ? " \u65E5\u5F00\u59CB" : " \u65E5\u524D\u6709\u6548") : void 0;
|
|
140
|
+
return /* @__PURE__ */ jsxs("section", { className: "promotion-card promotion-bumpin", children: [
|
|
141
|
+
/* @__PURE__ */ jsxs(
|
|
142
|
+
"div",
|
|
143
|
+
{
|
|
144
|
+
className: `promotion-bumpin__header${hasBackground ? " promotion-bumpin__header--bg" : ""}`,
|
|
145
|
+
style: resolvedBgUrl ? { backgroundImage: `url(${resolvedBgUrl})` } : void 0,
|
|
146
|
+
children: [
|
|
147
|
+
!hasBackground && data.coverUrl && /* @__PURE__ */ jsx2(ImageWithFallback, { src: data.coverUrl, alt: data.title, className: "promotion-bumpin__cover" }),
|
|
148
|
+
!hasBackground && !data.coverUrl && /* @__PURE__ */ jsx2("div", { className: "promotion-bumpin__cover-placeholder" }),
|
|
149
|
+
/* @__PURE__ */ jsxs("div", { className: "promotion-bumpin__header-copy", children: [
|
|
150
|
+
(data.tagLabel || statusBadge) && /* @__PURE__ */ jsxs("div", { className: "promotion-bumpin__tag-row", children: [
|
|
151
|
+
data.tagLabel && /* @__PURE__ */ jsx2("span", { className: "promotion-bumpin__tag", children: data.tagLabel }),
|
|
152
|
+
statusBadge && /* @__PURE__ */ jsx2("span", { className: `promotion-bumpin__status ${statusClass}`, children: statusBadge })
|
|
153
|
+
] }),
|
|
154
|
+
/* @__PURE__ */ jsx2("h3", { className: "promotion-bumpin__title", children: data.mainTitle || data.title }),
|
|
155
|
+
periodText && /* @__PURE__ */ jsx2("small", { className: "promotion-bumpin__period", children: periodText })
|
|
156
|
+
] })
|
|
157
|
+
]
|
|
158
|
+
}
|
|
159
|
+
),
|
|
160
|
+
data.totalProgress && /* @__PURE__ */ jsx2("div", { className: "promotion-bumpin__progress", children: isStepsMode ? /* @__PURE__ */ jsx2(
|
|
161
|
+
StepsProgress,
|
|
162
|
+
{
|
|
163
|
+
total: totalNum,
|
|
164
|
+
current: currentNum,
|
|
165
|
+
unit: data.progressUnit ?? "\u6B21"
|
|
166
|
+
}
|
|
167
|
+
) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
168
|
+
/* @__PURE__ */ jsx2("div", { className: "promotion-bumpin__progress-bar", children: /* @__PURE__ */ jsx2("div", { className: "promotion-bumpin__progress-fill", style: { width: `${progressPercent}%` } }) }),
|
|
169
|
+
/* @__PURE__ */ jsx2("span", { className: "promotion-bumpin__progress-text", children: notStarted ? "\u5C1A\u672A\u5F00\u59CB" : `\u5DF2\u5B8C\u6210 ${data.currentProgress ?? "0"} / ${data.totalProgress} ${data.progressUnit ?? "\u6B21"}` })
|
|
170
|
+
] }) }),
|
|
171
|
+
!isBanner && data.vouchers.length > 0 && /* @__PURE__ */ jsxs("div", { className: "promotion-bumpin__prizes", children: [
|
|
172
|
+
/* @__PURE__ */ jsxs("header", { className: "promotion-bumpin__prizes-header", children: [
|
|
173
|
+
/* @__PURE__ */ jsx2(Trophy, { weight: "fill" }),
|
|
174
|
+
data.actStatus === "RECEIVED" ? "\u5DF2\u9886\u53D6 \xB7 \u5956\u52B1\u6C60" : "\u5956\u52B1\u6C60"
|
|
175
|
+
] }),
|
|
176
|
+
/* @__PURE__ */ jsx2("ul", { className: "promotion-bumpin__prizes-list", children: visibleVouchers.map((voucher) => /* @__PURE__ */ jsxs("li", { className: "promotion-bumpin__prize-item", children: [
|
|
177
|
+
voucher.itemLogo ? /* @__PURE__ */ jsx2(
|
|
178
|
+
ImageWithFallback,
|
|
179
|
+
{
|
|
180
|
+
src: voucher.itemLogo,
|
|
181
|
+
alt: voucher.voucherName,
|
|
182
|
+
className: "promotion-bumpin__prize-logo"
|
|
183
|
+
}
|
|
184
|
+
) : /* @__PURE__ */ jsx2("span", { className: "promotion-bumpin__prize-logo-placeholder" }),
|
|
185
|
+
/* @__PURE__ */ jsxs("span", { className: "promotion-bumpin__prize-copy", children: [
|
|
186
|
+
/* @__PURE__ */ jsx2("strong", { children: voucher.voucherName }),
|
|
187
|
+
/* @__PURE__ */ jsx2("small", { children: voucher.thresholdAmountText || voucher.merchantName })
|
|
188
|
+
] })
|
|
189
|
+
] }, voucher.prizeId)) }),
|
|
190
|
+
data.vouchers.length > PRIZES_PREVIEW_COUNT && /* @__PURE__ */ jsx2(
|
|
191
|
+
"button",
|
|
192
|
+
{
|
|
193
|
+
type: "button",
|
|
194
|
+
className: "promotion-bumpin__prizes-toggle",
|
|
195
|
+
onClick: () => setPrizesExpanded((prev) => !prev),
|
|
196
|
+
children: prizesExpanded ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
197
|
+
/* @__PURE__ */ jsx2(CaretUp, { weight: "bold", size: 12 }),
|
|
198
|
+
"\u6536\u8D77"
|
|
199
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
200
|
+
/* @__PURE__ */ jsx2(CaretDown, { weight: "bold", size: 12 }),
|
|
201
|
+
"\u8FD8\u6709 ",
|
|
202
|
+
hiddenCount,
|
|
203
|
+
" \u5F20\uFF0C\u70B9\u51FB\u5C55\u5F00"
|
|
204
|
+
] })
|
|
205
|
+
}
|
|
206
|
+
)
|
|
207
|
+
] }),
|
|
208
|
+
data.description && /* @__PURE__ */ jsxs("div", { className: "promotion-bumpin__rules", children: [
|
|
209
|
+
/* @__PURE__ */ jsx2("header", { className: "promotion-bumpin__rules-header", children: "\u6D3B\u52A8\u89C4\u5219" }),
|
|
210
|
+
/* @__PURE__ */ jsx2(
|
|
211
|
+
"div",
|
|
212
|
+
{
|
|
213
|
+
className: "promotion-bumpin__rules-content",
|
|
214
|
+
dangerouslySetInnerHTML: { __html: sanitizeActivityHtml(data.description) }
|
|
215
|
+
}
|
|
216
|
+
)
|
|
217
|
+
] })
|
|
218
|
+
] });
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// src/client/index.ts
|
|
222
|
+
var cards = {
|
|
223
|
+
"promotion-bumpin-activity": AlipayActivityBumpInCard
|
|
224
|
+
};
|
|
225
|
+
var clientModule = {
|
|
226
|
+
cards,
|
|
227
|
+
register(ctx) {
|
|
228
|
+
ctx.cards.registerMap(cards);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
var client_default = clientModule;
|
|
232
|
+
export {
|
|
233
|
+
clientModule,
|
|
234
|
+
client_default as default
|
|
235
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { AlipayActivityBumpInCardData, AlipayBumpInFileConfig, AlipayBumpInService, alipayBumpInAuthStrategy, bumpInActivityMeta, configureAlipayBumpIn, createAlipayActivityHandler, createBumpInTools, parseAlipayRichText, readAlipayBumpInConfig, resolveAlipayBumpInService, default as serverModule, toBumpInCardData } from './server/index.js';
|
|
2
|
+
import '@mastra/core/tools';
|
|
3
|
+
import '@tbox.cn/app-sdk/server';
|
|
4
|
+
import '@tbox.cn/app-contracts';
|
|
5
|
+
import 'zod';
|
|
6
|
+
import 'alipay-sdk';
|
|
7
|
+
import '@tbox.cn/app-contracts-mall';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AlipayBumpInService,
|
|
3
|
+
alipayBumpInAuthStrategy,
|
|
4
|
+
configureAlipayBumpIn,
|
|
5
|
+
createAlipayActivityHandler,
|
|
6
|
+
createBumpInTools,
|
|
7
|
+
meta_default,
|
|
8
|
+
parseAlipayRichText,
|
|
9
|
+
readAlipayBumpInConfig,
|
|
10
|
+
resolveAlipayBumpInService,
|
|
11
|
+
serverModule,
|
|
12
|
+
toBumpInCardData
|
|
13
|
+
} from "./chunk-RM7IUA3M.js";
|
|
14
|
+
export {
|
|
15
|
+
AlipayBumpInService,
|
|
16
|
+
alipayBumpInAuthStrategy,
|
|
17
|
+
meta_default as bumpInActivityMeta,
|
|
18
|
+
configureAlipayBumpIn,
|
|
19
|
+
createAlipayActivityHandler,
|
|
20
|
+
createBumpInTools,
|
|
21
|
+
parseAlipayRichText,
|
|
22
|
+
readAlipayBumpInConfig,
|
|
23
|
+
resolveAlipayBumpInService,
|
|
24
|
+
serverModule,
|
|
25
|
+
toBumpInCardData
|
|
26
|
+
};
|
|
Binary file
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import * as _mastra_core_tools from '@mastra/core/tools';
|
|
2
|
+
import * as _tbox_cn_app_sdk_server from '@tbox.cn/app-sdk/server';
|
|
3
|
+
import { ServerContext, HandlerDefinition, ProviderAuthStrategy, PreToolDef } from '@tbox.cn/app-sdk/server';
|
|
4
|
+
import * as _tbox_cn_app_contracts from '@tbox.cn/app-contracts';
|
|
5
|
+
import { CardMeta } from '@tbox.cn/app-contracts';
|
|
6
|
+
import * as zod from 'zod';
|
|
7
|
+
import { AlipaySdk } from 'alipay-sdk';
|
|
8
|
+
import { PromotionActivityPort, PromotionQueryContext, PromotionActivityPage, PromotionActivityDetail, ActivitySession, PromotionActivityCategoryRecord, PromotionBumpInActivityCardData, promotionBumpInActivityCardDataSchema } from '@tbox.cn/app-contracts-mall';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 支付宝「碰出惊喜」互动营销活动 adapter。
|
|
12
|
+
*
|
|
13
|
+
* 实现 PromotionActivityPort(listActivities / getActivityDetail)。
|
|
14
|
+
* 调用支付宝开放平台 IoT NSP PlayCenter 活动查询接口:
|
|
15
|
+
* alipay.commerce.iotnspplaycenter.activity.query
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
declare class AlipayBumpInService implements PromotionActivityPort {
|
|
19
|
+
private readonly sdk;
|
|
20
|
+
private readonly actSchemeId;
|
|
21
|
+
constructor(sdk: AlipaySdk, actSchemeId: string);
|
|
22
|
+
listActivities(q: PromotionQueryContext, _input: {
|
|
23
|
+
keyword?: string;
|
|
24
|
+
cursor?: string;
|
|
25
|
+
limit?: number;
|
|
26
|
+
categoryId?: string;
|
|
27
|
+
dataScope?: string;
|
|
28
|
+
registrationRequired?: boolean;
|
|
29
|
+
startsAfter?: string;
|
|
30
|
+
endsBefore?: string;
|
|
31
|
+
}): Promise<PromotionActivityPage>;
|
|
32
|
+
getActivityDetail(q: PromotionQueryContext, activityRef: string): Promise<PromotionActivityDetail | null>;
|
|
33
|
+
listActivitySessions(_q: PromotionQueryContext, _activityRef: string): Promise<readonly ActivitySession[]>;
|
|
34
|
+
listActivityCategories(): Promise<readonly PromotionActivityCategoryRecord[]>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** bumpin.json 文件形状(模板 ENV.md 同步记载) */
|
|
38
|
+
interface AlipayBumpInFileConfig {
|
|
39
|
+
readonly gateway: string;
|
|
40
|
+
readonly actSchemeId: string;
|
|
41
|
+
readonly linkedCardBackgroundUrl?: string;
|
|
42
|
+
readonly credentialRef?: string;
|
|
43
|
+
}
|
|
44
|
+
/** 应用 entry 注入 bumpin 配置路径(CONFIG_DIR 锚定;模板 index.ts / 测试均可调用) */
|
|
45
|
+
declare function configureAlipayBumpIn(configPath: string): void;
|
|
46
|
+
/** 读取 bumpin 配置(fail-soft:未注入/缺文件/解析失败/缺必填字段 → null + warn) */
|
|
47
|
+
declare function readAlipayBumpInConfig(ctx?: ServerContext): AlipayBumpInFileConfig | null;
|
|
48
|
+
declare function resolveAlipayBumpInService(ctx: ServerContext): Promise<AlipayBumpInService | null>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 解析支付宝自定义富文本格式 #{{"color":"#E84749","customStyle":true,"text":"2"}}# → 纯文本 "2"
|
|
52
|
+
*/
|
|
53
|
+
declare function parseAlipayRichText(text: string | undefined): string;
|
|
54
|
+
/**
|
|
55
|
+
* 将 PromotionActivityDetail 中 bumpIn 特有字段格式化为 card data。
|
|
56
|
+
* guide.conditions[1] 存 progressText,guide.notice 存序列化的 voucherList。
|
|
57
|
+
* @param backgroundUrl 可选,联单活动全幅背景图 URL;来自部署配置 linkedCardBackgroundUrl,不传时前端 fallback 到模块内置图
|
|
58
|
+
*/
|
|
59
|
+
declare function toBumpInCardData(detail: PromotionActivityDetail, mode: 'detail' | 'banner', backgroundUrl?: string): PromotionBumpInActivityCardData;
|
|
60
|
+
declare function createBumpInTools(getCtx: () => ServerContext): {
|
|
61
|
+
getBumpInActivity: _mastra_core_tools.Tool<{}, unknown, unknown, unknown, _mastra_core_tools.ToolExecutionContext<unknown, unknown, unknown>, "getBumpInActivity", unknown>;
|
|
62
|
+
getBumpInActivityBanner: _mastra_core_tools.Tool<{}, unknown, unknown, unknown, _mastra_core_tools.ToolExecutionContext<unknown, unknown, unknown>, "getBumpInActivityBanner", unknown>;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 支付宝「碰出惊喜」意图处理器。
|
|
67
|
+
* 意图 bumpin-activity:用户主动询问碰出惊喜活动。
|
|
68
|
+
* 意图路由收窄(BM25 bigram 泄漏防护):patterns 只保留碰/惊字族域词、不含「支付宝」/「活动」
|
|
69
|
+
* 子串——pattern 内子串会经 bigram 展开泄漏为子串敏感(「支付宝互动活动」曾致「支付宝哪里
|
|
70
|
+
* 可以充值」类无关长句误入本模块直出卡);「支付宝碰一下」/「我的惊喜活动」等句式仍可靠
|
|
71
|
+
* 碰一/一下/惊喜 bigram 桥接命中。
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
declare function createAlipayActivityHandler(ctx: ServerContext): HandlerDefinition;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 占位认证策略(credentialType = alipay-open-v1,与凭据文件 .type 统一键)。
|
|
78
|
+
* 仅用于向 ctx.authStrategies 注册,让 SDK integrations registry 在创建 transport 时
|
|
79
|
+
* 不抛"未知认证类型"。alipay-bumpin 的实际签名由 AlipaySdk 自行完成,SDK transport 不会被调用。
|
|
80
|
+
*/
|
|
81
|
+
declare const alipayBumpInAuthStrategy: ProviderAuthStrategy;
|
|
82
|
+
|
|
83
|
+
type AlipayActivityBumpInCardData = PromotionBumpInActivityCardData;
|
|
84
|
+
declare const meta: CardMeta<typeof promotionBumpInActivityCardDataSchema>;
|
|
85
|
+
|
|
86
|
+
declare const serverModule: {
|
|
87
|
+
declaration: {
|
|
88
|
+
moduleId: string;
|
|
89
|
+
};
|
|
90
|
+
cards: {
|
|
91
|
+
readonly 'promotion-bumpin-activity': _tbox_cn_app_contracts.CardMeta<zod.ZodObject<{
|
|
92
|
+
activityRef: zod.ZodString;
|
|
93
|
+
title: zod.ZodString;
|
|
94
|
+
mainTitle: zod.ZodOptional<zod.ZodString>;
|
|
95
|
+
coverUrl: zod.ZodOptional<zod.ZodString>;
|
|
96
|
+
backgroundUrl: zod.ZodOptional<zod.ZodString>;
|
|
97
|
+
tagLabel: zod.ZodOptional<zod.ZodString>;
|
|
98
|
+
cardLogoUrl: zod.ZodOptional<zod.ZodString>;
|
|
99
|
+
actStatus: zod.ZodEnum<["NOT_START", "INIT", "PROCESSING", "FINISH", "RECEIVED"]>;
|
|
100
|
+
totalProgress: zod.ZodOptional<zod.ZodString>;
|
|
101
|
+
currentProgress: zod.ZodOptional<zod.ZodString>;
|
|
102
|
+
progressUnit: zod.ZodOptional<zod.ZodString>;
|
|
103
|
+
startAtText: zod.ZodOptional<zod.ZodString>;
|
|
104
|
+
endAtText: zod.ZodOptional<zod.ZodString>;
|
|
105
|
+
description: zod.ZodOptional<zod.ZodString>;
|
|
106
|
+
vouchers: zod.ZodArray<zod.ZodObject<{
|
|
107
|
+
prizeId: zod.ZodString;
|
|
108
|
+
voucherName: zod.ZodString;
|
|
109
|
+
voucherType: zod.ZodString;
|
|
110
|
+
reductionAmount: zod.ZodString;
|
|
111
|
+
thresholdAmountText: zod.ZodString;
|
|
112
|
+
unit: zod.ZodString;
|
|
113
|
+
merchantName: zod.ZodString;
|
|
114
|
+
merchantLogo: zod.ZodOptional<zod.ZodString>;
|
|
115
|
+
itemLogo: zod.ZodOptional<zod.ZodString>;
|
|
116
|
+
}, "strip", zod.ZodTypeAny, {
|
|
117
|
+
merchantName: string;
|
|
118
|
+
prizeId: string;
|
|
119
|
+
voucherName: string;
|
|
120
|
+
voucherType: string;
|
|
121
|
+
reductionAmount: string;
|
|
122
|
+
thresholdAmountText: string;
|
|
123
|
+
unit: string;
|
|
124
|
+
merchantLogo?: string | undefined;
|
|
125
|
+
itemLogo?: string | undefined;
|
|
126
|
+
}, {
|
|
127
|
+
merchantName: string;
|
|
128
|
+
prizeId: string;
|
|
129
|
+
voucherName: string;
|
|
130
|
+
voucherType: string;
|
|
131
|
+
reductionAmount: string;
|
|
132
|
+
thresholdAmountText: string;
|
|
133
|
+
unit: string;
|
|
134
|
+
merchantLogo?: string | undefined;
|
|
135
|
+
itemLogo?: string | undefined;
|
|
136
|
+
}>, "many">;
|
|
137
|
+
mode: zod.ZodDefault<zod.ZodEnum<["detail", "banner"]>>;
|
|
138
|
+
progressStyle: zod.ZodDefault<zod.ZodEnum<["bar", "steps"]>>;
|
|
139
|
+
steps: zod.ZodOptional<zod.ZodArray<zod.ZodObject<{
|
|
140
|
+
title: zod.ZodString;
|
|
141
|
+
description: zod.ZodOptional<zod.ZodString>;
|
|
142
|
+
}, "strip", zod.ZodTypeAny, {
|
|
143
|
+
title: string;
|
|
144
|
+
description?: string | undefined;
|
|
145
|
+
}, {
|
|
146
|
+
title: string;
|
|
147
|
+
description?: string | undefined;
|
|
148
|
+
}>, "many">>;
|
|
149
|
+
}, "strip", zod.ZodTypeAny, {
|
|
150
|
+
title: string;
|
|
151
|
+
mode: "detail" | "banner";
|
|
152
|
+
activityRef: string;
|
|
153
|
+
actStatus: "NOT_START" | "INIT" | "PROCESSING" | "FINISH" | "RECEIVED";
|
|
154
|
+
vouchers: {
|
|
155
|
+
merchantName: string;
|
|
156
|
+
prizeId: string;
|
|
157
|
+
voucherName: string;
|
|
158
|
+
voucherType: string;
|
|
159
|
+
reductionAmount: string;
|
|
160
|
+
thresholdAmountText: string;
|
|
161
|
+
unit: string;
|
|
162
|
+
merchantLogo?: string | undefined;
|
|
163
|
+
itemLogo?: string | undefined;
|
|
164
|
+
}[];
|
|
165
|
+
progressStyle: "steps" | "bar";
|
|
166
|
+
description?: string | undefined;
|
|
167
|
+
steps?: {
|
|
168
|
+
title: string;
|
|
169
|
+
description?: string | undefined;
|
|
170
|
+
}[] | undefined;
|
|
171
|
+
coverUrl?: string | undefined;
|
|
172
|
+
mainTitle?: string | undefined;
|
|
173
|
+
backgroundUrl?: string | undefined;
|
|
174
|
+
tagLabel?: string | undefined;
|
|
175
|
+
cardLogoUrl?: string | undefined;
|
|
176
|
+
totalProgress?: string | undefined;
|
|
177
|
+
currentProgress?: string | undefined;
|
|
178
|
+
progressUnit?: string | undefined;
|
|
179
|
+
startAtText?: string | undefined;
|
|
180
|
+
endAtText?: string | undefined;
|
|
181
|
+
}, {
|
|
182
|
+
title: string;
|
|
183
|
+
activityRef: string;
|
|
184
|
+
actStatus: "NOT_START" | "INIT" | "PROCESSING" | "FINISH" | "RECEIVED";
|
|
185
|
+
vouchers: {
|
|
186
|
+
merchantName: string;
|
|
187
|
+
prizeId: string;
|
|
188
|
+
voucherName: string;
|
|
189
|
+
voucherType: string;
|
|
190
|
+
reductionAmount: string;
|
|
191
|
+
thresholdAmountText: string;
|
|
192
|
+
unit: string;
|
|
193
|
+
merchantLogo?: string | undefined;
|
|
194
|
+
itemLogo?: string | undefined;
|
|
195
|
+
}[];
|
|
196
|
+
description?: string | undefined;
|
|
197
|
+
mode?: "detail" | "banner" | undefined;
|
|
198
|
+
steps?: {
|
|
199
|
+
title: string;
|
|
200
|
+
description?: string | undefined;
|
|
201
|
+
}[] | undefined;
|
|
202
|
+
coverUrl?: string | undefined;
|
|
203
|
+
mainTitle?: string | undefined;
|
|
204
|
+
backgroundUrl?: string | undefined;
|
|
205
|
+
tagLabel?: string | undefined;
|
|
206
|
+
cardLogoUrl?: string | undefined;
|
|
207
|
+
totalProgress?: string | undefined;
|
|
208
|
+
currentProgress?: string | undefined;
|
|
209
|
+
progressUnit?: string | undefined;
|
|
210
|
+
startAtText?: string | undefined;
|
|
211
|
+
endAtText?: string | undefined;
|
|
212
|
+
progressStyle?: "steps" | "bar" | undefined;
|
|
213
|
+
}>>;
|
|
214
|
+
};
|
|
215
|
+
skills: {
|
|
216
|
+
[k: string]: _tbox_cn_app_sdk_server.LocalSkill;
|
|
217
|
+
};
|
|
218
|
+
preTools: {
|
|
219
|
+
getBumpInActivity: PreToolDef<_mastra_core_tools.Tool<{}, unknown, unknown, unknown, _mastra_core_tools.ToolExecutionContext<unknown, unknown, unknown>, "getBumpInActivity", unknown>>;
|
|
220
|
+
};
|
|
221
|
+
register(ctx: ServerContext): void;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
export { type AlipayActivityBumpInCardData, type AlipayBumpInFileConfig, AlipayBumpInService, alipayBumpInAuthStrategy, meta as bumpInActivityMeta, configureAlipayBumpIn, createAlipayActivityHandler, createBumpInTools, serverModule as default, parseAlipayRichText, readAlipayBumpInConfig, resolveAlipayBumpInService, serverModule, toBumpInCardData };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AlipayBumpInService,
|
|
3
|
+
alipayBumpInAuthStrategy,
|
|
4
|
+
configureAlipayBumpIn,
|
|
5
|
+
createAlipayActivityHandler,
|
|
6
|
+
createBumpInTools,
|
|
7
|
+
meta_default,
|
|
8
|
+
parseAlipayRichText,
|
|
9
|
+
readAlipayBumpInConfig,
|
|
10
|
+
resolveAlipayBumpInService,
|
|
11
|
+
serverModule,
|
|
12
|
+
server_default,
|
|
13
|
+
toBumpInCardData
|
|
14
|
+
} from "../chunk-RM7IUA3M.js";
|
|
15
|
+
export {
|
|
16
|
+
AlipayBumpInService,
|
|
17
|
+
alipayBumpInAuthStrategy,
|
|
18
|
+
meta_default as bumpInActivityMeta,
|
|
19
|
+
configureAlipayBumpIn,
|
|
20
|
+
createAlipayActivityHandler,
|
|
21
|
+
createBumpInTools,
|
|
22
|
+
server_default as default,
|
|
23
|
+
parseAlipayRichText,
|
|
24
|
+
readAlipayBumpInConfig,
|
|
25
|
+
resolveAlipayBumpInService,
|
|
26
|
+
serverModule,
|
|
27
|
+
toBumpInCardData
|
|
28
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tbox.cn/app-module-alipay-activity",
|
|
3
|
+
"version": "0.2.3",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "支付宝互动营销活动模块:碰出惊喜(碰一下)活动查询与展示(codegen 源)。",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./server": {
|
|
12
|
+
"types": "./dist/server/index.d.ts",
|
|
13
|
+
"import": "./dist/server/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./client": {
|
|
16
|
+
"types": "./dist/client/index.d.ts",
|
|
17
|
+
"import": "./dist/client/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@tbox.cn/app-sdk": "0.17.0",
|
|
22
|
+
"@tbox.cn/app-contracts": "0.9.0",
|
|
23
|
+
"@tbox.cn/app-contracts-mall": "0.9.0",
|
|
24
|
+
"alipay-sdk": "4.14.0"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"zod": "3.25.76",
|
|
28
|
+
"react": "18.3.1",
|
|
29
|
+
"@phosphor-icons/react": "2.1.10"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/react": "18.3.31",
|
|
33
|
+
"@types/node": "24.13.3",
|
|
34
|
+
"typescript": "5.9.3",
|
|
35
|
+
"vitest": "4.1.10",
|
|
36
|
+
"zod": "3.25.76",
|
|
37
|
+
"tsup": "8.5.1",
|
|
38
|
+
"react-dom": "18.3.1",
|
|
39
|
+
"@types/react-dom": "18.3.7"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"src",
|
|
44
|
+
"tests",
|
|
45
|
+
"skills",
|
|
46
|
+
"schemas",
|
|
47
|
+
"tbox.module.json",
|
|
48
|
+
"tsconfig.json",
|
|
49
|
+
"tsup.config.ts",
|
|
50
|
+
"README.md",
|
|
51
|
+
"LICENSE",
|
|
52
|
+
"AGENTS.md"
|
|
53
|
+
],
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=20.0.0"
|
|
56
|
+
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public"
|
|
59
|
+
},
|
|
60
|
+
"license": "MIT",
|
|
61
|
+
"sideEffects": [
|
|
62
|
+
"**/*.css"
|
|
63
|
+
],
|
|
64
|
+
"scripts": {
|
|
65
|
+
"typecheck": "tsc --noEmit",
|
|
66
|
+
"test": "vitest run",
|
|
67
|
+
"build": "tsup"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"title": "支付宝碰出惊喜凭证(alipay-open-v1)",
|
|
4
|
+
"description": "值域掩码声明——真值经 credentialRef 指向 secret 存储(文件/environment 双通道),恒不入包。",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"appId": { "type": "string", "title": "支付宝小程序 appId" },
|
|
8
|
+
"alipayPublicKey": { "type": "string", "title": "支付宝公钥(验签)" },
|
|
9
|
+
"privateKey": { "type": "string", "writeOnly": true, "title": "商户私钥(签名源)" }
|
|
10
|
+
},
|
|
11
|
+
"required": ["appId", "privateKey", "alipayPublicKey"]
|
|
12
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: alipay-activity
|
|
3
|
+
description: 碰出惊喜活动 SOP——活动详情、参与进度与奖励的查询与转述规范。
|
|
4
|
+
routingTerms:
|
|
5
|
+
- 碰一碰
|
|
6
|
+
- 碰一下
|
|
7
|
+
- 碰出惊喜
|
|
8
|
+
- 惊喜活动
|
|
9
|
+
- NFC
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# 碰出惊喜活动 SOP
|
|
13
|
+
|
|
14
|
+
## 你是谁
|
|
15
|
+
|
|
16
|
+
你是支付宝「碰出惊喜」互动营销活动的专属助手,熟悉活动玩法、参与进度与奖励规则。像活动现场的工作人员一样,用一句话讲清「怎么玩、到哪一步、能拿什么」。
|
|
17
|
+
|
|
18
|
+
- **结果先行**:先说进度或结论("你已完成 2 笔,还差 3 笔"),再给下一步动作
|
|
19
|
+
- **奖励讲清楚**:奖励名称、门槛、领取方式逐项对应,不笼统说"有惊喜"
|
|
20
|
+
|
|
21
|
+
## 工作方式
|
|
22
|
+
|
|
23
|
+
碰一碰类问句通常已由系统**预查询**:本轮 user 消息前部会有 `<system-reminder pre-tool="getBumpInActivity">` 数据块(活动详情/进度/奖励已就位,详情卡也已在本轮候选池)。有块时直接基于块内数据作答,正文末尾引用块内卡 id 即可,**无需重复调用工具**;仅在无注入块、或用户明确要刷新进度时才调 `getBumpInActivity`(userId/openId 从会话上下文自动获取,无需追问)。
|
|
24
|
+
|
|
25
|
+
## 能力地图
|
|
26
|
+
|
|
27
|
+
| 用户问什么 | 工具 | 出卡 |
|
|
28
|
+
| --- | --- | --- |
|
|
29
|
+
| 活动详情、参与进度、奖励内容、参与方式 | `getBumpInActivity` | `promotion-bumpin-activity`(详情卡) |
|
|
30
|
+
|
|
31
|
+
## 场景走法
|
|
32
|
+
|
|
33
|
+
### 活动详情与进度
|
|
34
|
+
|
|
35
|
+
有预查询注入块时直接转述:进度用「已完成 X / Y」形态,奖励逐项列名称与门槛。未参与时如实说明并给出参与引导(在门店内用支付宝「碰一下」触碰活动区域)。注入块显示活动未配置或查不到时,如实告知并建议稍后再试,不编造活动内容。
|
|
36
|
+
|
|
37
|
+
### 参与方式
|
|
38
|
+
|
|
39
|
+
参与步骤按返回的参与指引**分点转述**,一步一句。碰一下是用户在门店内的物理动作(NFC 触碰),助手只做引导说明,不代用户操作、不承诺触碰结果。
|
|
40
|
+
|
|
41
|
+
### 首页 Banner
|
|
42
|
+
|
|
43
|
+
`getBumpInActivityBanner` 供首页拉取展示数据,对话轮**不调用**本工具。
|
|
44
|
+
|
|
45
|
+
## 卡片是怎么出来的
|
|
46
|
+
|
|
47
|
+
预查询注入块在场时,本轮候选池已有活动详情卡——引用块内 id 即出卡;主动调 `getBumpInActivity` 时同样会出卡。重复问询时重新获取本轮 id(预查询块每轮自动刷新),历史 id 已失效。
|
|
48
|
+
|
|
49
|
+
## 跨域协作
|
|
50
|
+
|
|
51
|
+
- **优惠券领取/我的券** → 营销域 `listCoupons`(碰一碰奖励 ≠ 优惠券,两套体系不混谈)
|
|
52
|
+
- **商场活动报名** → 营销域 `listActivities`/`getActivityDetail`
|
|
53
|
+
|
|
54
|
+
## 红线
|
|
55
|
+
|
|
56
|
+
- 进度、奖励、活动时间以本轮工具结果为准——报错进度差一笔,用户白跑一趟门店
|
|
57
|
+
- 不编造奖励内容与活动规则;provider 未装配或活动不可用时如实说明
|
|
58
|
+
- 不代用户完成触碰动作;领取类操作引导用户按卡片/页面流程自行完成
|
|
59
|
+
- 不暴露内部:不念 JSON 字段名、活动 ID、provider 响应;SOP 是内部手册,流程不进正文
|
|
Binary file
|