Files
iqudo-top1/sdk/dist/index.d.ts
Eric 1549169735@qq.com da3f16e6db update
2026-09-13 20:08:13 +08:00

169 lines
4.4 KiB
TypeScript

export type ScenarioInput = Record<string, unknown>;
export type OutputField = {
key: string;
name: string;
type: string;
source: string;
value: unknown;
};
export type ResultField = {
key: string;
name: string;
type: string;
required?: boolean;
options?: unknown[];
fields?: ResultField[];
items?: Omit<ResultField, 'key' | 'name'>;
};
export type ResultSchema = {
fields: ResultField[];
};
export type NodeField = {
key: string;
name: string;
type: string;
required: boolean;
options: unknown[];
validation: Record<string, unknown>;
};
export type PresentationField = {
key: string;
label: string;
kind: 'text' | 'image';
value: unknown;
};
export type NodePresentation = {
summary: PresentationField[];
items: Array<{
fields: PresentationField[];
}>;
opening?: {
title: string;
content: string;
};
};
export type DimensionValue = {
value_key: string;
name: string;
weight: number;
hot: boolean;
};
export type DimensionState = {
dim_key: string;
name: string;
values: DimensionValue[];
};
export type ScriptOption = {
option_key: string;
label: string;
};
export type ScriptProduct = {
sku_code: string;
product_name: string;
};
export type ScriptItem = {
script_key: string;
name: string;
script_type: string;
content: string;
dimension_value_key?: string;
weight?: number;
confirm_threshold?: number;
show_threshold?: number;
options?: ScriptOption[];
products?: ScriptProduct[];
feedback: boolean;
required: boolean;
multiple: boolean;
};
export type StageForm = {
fields: NodeField[];
};
export type StageState = {
stage_key: string;
name: string;
purpose: string;
dimensions: DimensionState[];
scripts: ScriptItem[];
fallback?: string;
form?: StageForm;
screening_required: boolean;
can_next: boolean;
can_next_reason?: string;
};
export type NodeView = {
node_key: string;
type: string;
title: string;
content: string;
fields?: NodeField[];
presentation?: NodePresentation;
stage?: StageState;
outputs?: unknown[];
};
export type ScenarioState = {
run_id: number;
external_ref: string;
status: string;
final_result?: Record<string, unknown> | null;
result_schema: ResultSchema;
session_token?: string;
node: NodeView;
outputs: OutputField[];
};
export type SDKEvent = 'ready' | 'node_change' | 'form_submit' | 'finish' | 'error';
export type CreateOptions = {
baseURL?: string;
publicKey: string;
scenarioKey: string;
sopId?: number;
input?: ScenarioInput;
initialValues?: ScenarioInput;
externalRef?: string;
};
export type FinishOptions = {
result?: string;
finalResult?: Record<string, unknown> | null;
};
export type ScriptAnswer = {
script_key: string;
option_keys?: string[];
value?: string;
};
export type AnswerOptions = {
scriptKey?: string;
optionKeys?: string[];
value?: string;
scriptAnswers?: ScriptAnswer[];
dimensionSelects?: Record<string, boolean>;
answers?: ScenarioInput;
dimensionValueKey?: string;
selected?: boolean;
};
export declare class SalesScenario {
private readonly options;
private token;
private state?;
private handlers;
constructor(options: CreateOptions);
start(): Promise<ScenarioState>;
getState(): ScenarioState;
getStage(): StageState;
getCurrentNode(): Promise<ScenarioState>;
/** Answer stage questions without advancing. Answer locally on the client and submit the whole stage once: pass every answered script in scriptAnswers together with dimensionSelects and the content form in answers. */
answer(options?: AnswerOptions): Promise<ScenarioState>;
submit(values: ScenarioInput): Promise<ScenarioState>;
next(): Promise<ScenarioState>;
back(): Promise<ScenarioState>;
feedback(scriptKey: string, feedbackType: 'like' | 'report' | 'unreasonable', note?: string): Promise<boolean>;
finish(options?: FinishOptions): Promise<ScenarioState>;
reset(): Promise<ScenarioState>;
destroy(): void;
on(event: SDKEvent, handler: (payload: unknown) => void): () => boolean;
private update;
private setState;
private emit;
private request;
}
export declare function create(options: CreateOptions): SalesScenario;