@antglobal/voyager-campaign-sdk 0.0.0 → 0.0.1788950302-dev.0

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.
@@ -0,0 +1,16 @@
1
+ /**
2
+ * CN 协议中心签约公共流程(mp 与 mp_web 共用,基于 @alipay/agreement-utils);
3
+ * 环境判断与工具库加载由各平台注入。
4
+ */
5
+ import type { AgreementUtilsPort } from './types';
6
+ import type { SignResult } from '../types';
7
+ export interface AgreementSignFlowOptions {
8
+ /** prod/pre 用正式签约产品,其余环境用联调签约产品 */
9
+ isProdOrPreEnv: () => boolean;
10
+ loadAgreementUtils: () => AgreementUtilsPort;
11
+ }
12
+ export interface AgreementSignFlow {
13
+ querySignStatus(): Promise<SignResult>;
14
+ sign(): Promise<SignResult>;
15
+ }
16
+ export declare function createAgreementSignFlow(options: AgreementSignFlowOptions): AgreementSignFlow;
@@ -0,0 +1,2 @@
1
+ import type { PlatformAdapter } from './types';
2
+ export declare function createMpAdapter(): PlatformAdapter;
@@ -0,0 +1,2 @@
1
+ import type { PlatformAdapter } from './types';
2
+ export declare function createMpWebAdapter(): PlatformAdapter;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * mp_web DEV 联调:URL 参数 `_voyager_dev_env`(格式 `sofa*pspId*userId*AppId`)
3
+ * 注入联调信息,缓存到 localStorage 持续生效,传空字符串清空。
4
+ */
5
+ export interface DevEnvInfo {
6
+ sofa?: string;
7
+ pspId?: string;
8
+ userId?: string;
9
+ AppId?: string;
10
+ }
11
+ /** 环境判断:injectInfo 优先,域名兜底,缺省 PROD */
12
+ export declare function getEnv(): string;
13
+ export declare function getDevEnvInfo(): DevEnvInfo | undefined;
14
+ /**
15
+ * 非 PROD 环境注入联调信息:sofa -> sofa-group-name 头,pspId -> 请求参数,
16
+ * userId -> mockAuth + userId 头,AppId -> AppId 头,并移除 _voyager_dev_env 参数
17
+ */
18
+ export declare function applyDevEnvInfo(headers: Record<string, string>, params: Record<string, unknown>): void;
19
+ /** headers 同步写入 requestData[0].extHeaders:兼容容器不支持自定义请求头 */
20
+ export declare function addExtHeaders(requestData: Array<Record<string, unknown>>, headers: Record<string, string>): void;
21
+ /** 按环境与钱包选联调网关;PRE 额外携带 workspaceId=pre */
22
+ export declare function getDevGatewayConfig(clientName: string): {
23
+ gateway?: string;
24
+ workspaceId?: string;
25
+ };
26
+ /** 联调环境判定:DEV/TEST 走无鉴权 HTTP 直连,PRE/PROD 走带鉴权容器通道 */
27
+ export declare function isDevLikeEnv(): boolean;
28
+ /** 测试用:重置模块级解析缓存 */
29
+ export declare function resetDevEnvCache(): void;
@@ -0,0 +1,63 @@
1
+ import type { SignResult, SystemInfo, VoyagerPlatform } from '../types';
2
+ export type { VoyagerPlatform };
3
+ export interface RpcPayload {
4
+ operationType: string;
5
+ requestData: Array<{
6
+ serviceCode: string;
7
+ params: Array<Record<string, unknown>>;
8
+ }>;
9
+ /** DEV/TEST/PRE 联调注入的请求头(_voyager_dev_env) */
10
+ headers?: Record<string, string>;
11
+ /** DEV/TEST/PRE 联调切换的网关地址 */
12
+ gateway?: string;
13
+ /** PRE 联调环境标识 */
14
+ workspaceId?: string;
15
+ }
16
+ export interface RequestInput<TParams extends Record<string, unknown> = Record<string, unknown>> {
17
+ serviceCode: string;
18
+ params: TParams;
19
+ }
20
+ export interface StoragePort {
21
+ read(key: string): Promise<unknown>;
22
+ write(key: string, data: unknown): Promise<void>;
23
+ remove(key: string): Promise<void>;
24
+ }
25
+ /**
26
+ * 平台适配器:mp 与 mp_web 各自实现,共享核心不直接触碰端能力
27
+ */
28
+ export interface PlatformAdapter {
29
+ platform: VoyagerPlatform;
30
+ rpc<TResponse>(payload: RpcPayload): Promise<TResponse>;
31
+ /** 发送前对 payload 做平台级加工(如 mp_web 联调环境的网关切换与请求头注入) */
32
+ decoratePayload?(payload: RpcPayload): Promise<RpcPayload> | RpcPayload;
33
+ getSystemInfo(): Promise<SystemInfo>;
34
+ /** 钱包标识(对齐 biz-base 取 hylid client):mp_web 用 client,mp 固定 alipay */
35
+ getClientName(): string;
36
+ /** 当前语言原始值:mp_web 用 hylid getCurrentLanguage,mp 用 systemInfo 语言字段 */
37
+ getLocale(systemInfo: SystemInfo): string;
38
+ /** 可选:获取风控 tokenId(envInfo.tokenId),未提供时不注入 */
39
+ getAppToken?(): Promise<string | undefined>;
40
+ storage: StoragePort;
41
+ fetchWhitelistConfig(): Promise<unknown>;
42
+ querySignStatus(): Promise<SignResult>;
43
+ sign(): Promise<SignResult>;
44
+ }
45
+ export interface AgreementUtilsPort {
46
+ querySignRecord(productCd: string): Promise<{
47
+ success?: boolean;
48
+ data?: {
49
+ userId?: string;
50
+ signRecordVOS?: Array<{
51
+ agreementId?: string;
52
+ status?: string;
53
+ }>;
54
+ };
55
+ }>;
56
+ signAgreement(options: {
57
+ productCd: string;
58
+ agreementIds: string[];
59
+ }): Promise<{
60
+ success?: boolean;
61
+ userId?: string;
62
+ }>;
63
+ }
@@ -0,0 +1,6 @@
1
+ export declare const VOYAGER_USER_INFO = "VOYAGER_USER_INFO";
2
+ export declare const VOYAGER_API_WHITELIST_CONFIG = "VOYAGER_API_WHITELIST_CONFIG";
3
+ import type { StoragePort } from '../adapter/types';
4
+ export declare function readCache<T>(storage: StoragePort, key: string): Promise<T | null>;
5
+ export declare function writeCache<T>(storage: StoragePort, key: string, value: T): Promise<void>;
6
+ export declare function removeCache(storage: StoragePort, key: string): Promise<void>;
@@ -0,0 +1,17 @@
1
+ import type { PlatformAdapter } from '../adapter/types';
2
+ import type { SystemInfo, VoyagerEnvInfo } from '../types';
3
+ export interface EnvInfoContext {
4
+ /** 钱包标识(hylid client),不再取 systemInfo.clientName/app */
5
+ clientName: string;
6
+ /** 当前语言原始值(hylid getCurrentLanguage),由 normalizeLocale 归一化 */
7
+ locale: string;
8
+ tokenId?: string;
9
+ }
10
+ /**
11
+ * 语言归一化,对齐 aplus-biz-base i18n/language.ts:
12
+ * 连字符转下划线、印尼语 id 转 in、region 大写,缺省 en_US
13
+ */
14
+ export declare function normalizeLocale(lang: string): string;
15
+ /** 字段取值对齐 aplus-biz-base getEnvInfo(不含 addRiskTokenId/getLocationFn 相关逻辑) */
16
+ export declare function createEnvInfo(info: SystemInfo, context: EnvInfoContext): VoyagerEnvInfo;
17
+ export declare function createEnvInfoLoader(adapter: PlatformAdapter): () => Promise<VoyagerEnvInfo>;
@@ -0,0 +1,6 @@
1
+ import type { PlatformAdapter } from '../adapter/types';
2
+ import type { VoyagerEnvInfo } from '../types';
3
+ import { createEnvInfoLoader } from './envInfo';
4
+ export type RawRequestFn = <TResponse>(serviceCode: string, params: Record<string, unknown>) => Promise<TResponse>;
5
+ export declare function createRawRequest(adapter: PlatformAdapter, getEnvInfo: () => Promise<VoyagerEnvInfo>): RawRequestFn;
6
+ export { createEnvInfoLoader };
@@ -0,0 +1,5 @@
1
+ import type { PlatformAdapter, RequestInput } from '../adapter/types';
2
+ export interface VoyagerRequestFn {
3
+ <TResponse = unknown, TParams extends Record<string, unknown> = Record<string, unknown>>(options: RequestInput<TParams>): Promise<TResponse>;
4
+ }
5
+ export declare function createRequest(adapter: PlatformAdapter): VoyagerRequestFn;
@@ -0,0 +1,17 @@
1
+ import type { SignResult, SignStatus } from '../types';
2
+ export interface WhitelistCacheValue {
3
+ serviceCodes: string[];
4
+ expiresAt: number;
5
+ }
6
+ export interface WhitelistSnapshot extends WhitelistCacheValue {
7
+ lookup: {
8
+ [key: string]: true;
9
+ };
10
+ }
11
+ export interface VoyagerRuntimeState {
12
+ signStatus: SignStatus | null;
13
+ signStatusTask: Promise<SignResult> | null;
14
+ whitelist: WhitelistSnapshot | null;
15
+ whitelistTask: Promise<WhitelistSnapshot> | null;
16
+ }
17
+ export declare function getRuntimeState(): VoyagerRuntimeState;
@@ -0,0 +1,9 @@
1
+ import type { PlatformAdapter } from '../adapter/types';
2
+ import type { SignResult, SignStatus } from '../types';
3
+ export interface SignCacheValue {
4
+ status: SignStatus;
5
+ userId?: string;
6
+ updatedAt: number;
7
+ }
8
+ export declare function getSignStatus(adapter: PlatformAdapter): Promise<SignResult>;
9
+ export declare function sign(adapter: PlatformAdapter): Promise<SignResult>;
@@ -0,0 +1,4 @@
1
+ import type { PlatformAdapter, StoragePort } from '../adapter/types';
2
+ import { WhitelistSnapshot } from './runtime';
3
+ export declare function loadWhitelist(adapter: PlatformAdapter, storage: StoragePort): Promise<WhitelistSnapshot>;
4
+ export declare function checkWhitelist(serviceCode: string): boolean;
@@ -0,0 +1,12 @@
1
+ import type { VoyagerPlatform } from '../types';
2
+ import type { MonitoredRequest, MonitorChannel, MonitorFields } from './types';
3
+ export { MonitorCode, MonitorMsg } from './utils/codes';
4
+ export declare function resolveChannelFromClientName(clientName: string): MonitorChannel;
5
+ export declare function configureMonitor(resolver: () => Promise<MonitorChannel>): void;
6
+ export declare function log(fields: MonitorFields): void;
7
+ export declare function startMonitor(): void;
8
+ export declare function reportRequestSuccess(request: MonitoredRequest, result: unknown, startedAt: number): void;
9
+ export declare function reportRequestFailure(request: MonitoredRequest, result: unknown, startedAt: number): void;
10
+ export declare function reportWhitelistHit(request: MonitoredRequest, hit: boolean): void;
11
+ export declare function reportWhitelistConfig(platform: VoyagerPlatform, success: boolean, error?: unknown): void;
12
+ export declare function reportSignStatus(request: MonitoredRequest, signed: boolean): void;
@@ -0,0 +1,21 @@
1
+ import type { VoyagerPlatform } from '../types';
2
+ export type MonitorChannel = 'APLUS' | 'CN' | 'UNKNOWN';
3
+ export interface MonitoredRequest {
4
+ platform: VoyagerPlatform;
5
+ serviceCode: string;
6
+ }
7
+ export interface MonitorFields {
8
+ code: string;
9
+ msg: string;
10
+ m1?: number;
11
+ c1?: string;
12
+ d1?: string;
13
+ d2?: string;
14
+ d3?: string;
15
+ d4?: string;
16
+ d5?: string;
17
+ }
18
+ export interface MonitorProvider {
19
+ report(fields: MonitorFields): void;
20
+ start(): void;
21
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * 监控 code 与营销三方白牌 SDK 监控平台一一对应,共四个:
3
+ * - 1033 接口请求:业务 API 请求结果(成功/失败合并到同一 code,用 msg 区分)
4
+ * - 1034 白名单是否命中:serviceCode 是否通过白名单校验
5
+ * - 1035 白名单配置请求:远程白名单配置拉取结果
6
+ * - 1036 是否签约:调用前用户签约状态校验结果
7
+ */
8
+ export declare enum MonitorCode {
9
+ REQUEST = "1033",
10
+ WHITELIST_HIT = "1034",
11
+ WHITELIST_CONFIG = "1035",
12
+ SIGN_STATUS = "1036"
13
+ }
14
+ /** 统一结果标识:所有 code 的 msg 只用 SUCCESS | FAILED 表示成功/失败 */
15
+ export declare enum MonitorMsg {
16
+ SUCCESS = "SUCCESS",
17
+ FAILED = "FAILED"
18
+ }
@@ -0,0 +1,3 @@
1
+ import type { MonitorFields } from '../types';
2
+ export declare function start(): void;
3
+ export declare function report(fields: MonitorFields): void;
@@ -0,0 +1,3 @@
1
+ import type { MonitorFields } from '../types';
2
+ export declare function start(): void;
3
+ export declare function report(fields: MonitorFields): void;
@@ -0,0 +1,2 @@
1
+ import type { VoyagerRequestOptions } from '../types';
2
+ export declare function request<TResponse = unknown, TParams extends Record<string, unknown> = Record<string, unknown>>(options: VoyagerRequestOptions<TParams>): Promise<TResponse>;