@cognior/iap-sdk 0.2.3 → 0.2.8
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/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +137 -12
- package/dist/index.esm.js +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -46,8 +46,6 @@ interface EnhancedStepData {
|
|
|
46
46
|
uxExperience?: {
|
|
47
47
|
uxExperienceType: string;
|
|
48
48
|
elementSelector?: string;
|
|
49
|
-
elementTrigger?: string;
|
|
50
|
-
elementLocation?: string;
|
|
51
49
|
position?: {
|
|
52
50
|
x: string;
|
|
53
51
|
y: string;
|
|
@@ -67,22 +65,121 @@ interface FlowData {
|
|
|
67
65
|
mode?: FlowExecutionMode;
|
|
68
66
|
multiPage?: boolean;
|
|
69
67
|
frequency?: {
|
|
70
|
-
type: 'OneTime' | 'Daily' | 'Weekly' | 'Monthly';
|
|
68
|
+
type: 'Always' | 'OneTime' | 'Recurring' | 'Daily' | 'Weekly' | 'Monthly';
|
|
71
69
|
maxRuns: number;
|
|
72
70
|
};
|
|
73
71
|
frequencyType?: string;
|
|
74
72
|
};
|
|
75
73
|
}
|
|
76
74
|
|
|
77
|
-
/**
|
|
78
|
-
|
|
79
|
-
*/
|
|
80
|
-
declare function init(opts: {
|
|
75
|
+
/** Options passed to {@link DapSDK.init}. */
|
|
76
|
+
interface DapInitOptions {
|
|
77
|
+
/** URL to the DAP configuration JSON (required). */
|
|
81
78
|
configUrl: string;
|
|
79
|
+
/** Enable verbose [DAP] console logging. Default: false. */
|
|
82
80
|
debug?: boolean;
|
|
81
|
+
/** Logical screen/view identifier for location-based flow matching. */
|
|
83
82
|
screenId?: string;
|
|
83
|
+
/** Authenticated user context. Can also be provided later via {@link DapSDK.setUser}. */
|
|
84
84
|
user?: DapUser;
|
|
85
|
-
}
|
|
85
|
+
}
|
|
86
|
+
/** A single step inside a {@link DapFlowDefinition}. */
|
|
87
|
+
interface DapFlowStep {
|
|
88
|
+
id?: string;
|
|
89
|
+
/** Experience type: 'tooltip' | 'modal' | 'banner' | 'survey' | 'walkthrough' | etc. */
|
|
90
|
+
type: string;
|
|
91
|
+
trigger?: {
|
|
92
|
+
selector?: string;
|
|
93
|
+
type?: string;
|
|
94
|
+
placement?: string;
|
|
95
|
+
};
|
|
96
|
+
content: Record<string, any>;
|
|
97
|
+
}
|
|
98
|
+
/** An inline flow definition used with {@link DapSDK.executeFlow}. */
|
|
99
|
+
interface DapFlowDefinition {
|
|
100
|
+
id: string;
|
|
101
|
+
name?: string;
|
|
102
|
+
steps: DapFlowStep[];
|
|
103
|
+
execution?: {
|
|
104
|
+
mode?: string;
|
|
105
|
+
multiPage?: boolean;
|
|
106
|
+
frequency?: {
|
|
107
|
+
type?: string;
|
|
108
|
+
maxRuns?: number;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
/** @deprecated Use execution.mode instead. */
|
|
112
|
+
executionMode?: string;
|
|
113
|
+
/** @deprecated Use execution.multiPage instead. */
|
|
114
|
+
isMultiPage?: boolean;
|
|
115
|
+
}
|
|
116
|
+
/** The complete public API surface of the DAP SDK. */
|
|
117
|
+
interface DapSDK {
|
|
118
|
+
/**
|
|
119
|
+
* Initialize the SDK. Must be called once before any other method.
|
|
120
|
+
* Fetches remote config, sets user/location context, and starts eligible flows.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* await dap.init({ configUrl: 'https://cdn.example.com/config.json', screenId: 'home' });
|
|
124
|
+
*/
|
|
125
|
+
init(opts: DapInitOptions): Promise<void>;
|
|
126
|
+
/** Set (or replace) the authenticated user context. Triggers pending flows. */
|
|
127
|
+
setUser(user: DapUser): void;
|
|
128
|
+
/** Merge partial fields into the existing user context. */
|
|
129
|
+
updateUser(partialUser: Partial<DapUser>): void;
|
|
130
|
+
/** Return the current user, or null if not set. */
|
|
131
|
+
getUser(): DapUser | null;
|
|
132
|
+
/** Clear the user context. */
|
|
133
|
+
clearUser(): void;
|
|
134
|
+
/**
|
|
135
|
+
* Register a pre-fetched or locally-defined flow for later use via {@link startFlow}.
|
|
136
|
+
* The registry is capped at 50 entries; oldest entries are evicted when exceeded.
|
|
137
|
+
*/
|
|
138
|
+
registerFlow(flowData: FlowData): void;
|
|
139
|
+
/**
|
|
140
|
+
* Start a flow by ID. Checks the in-memory registry first, then fetches from backend.
|
|
141
|
+
* Throws if the flow cannot be resolved.
|
|
142
|
+
*/
|
|
143
|
+
startFlow(flowId: string): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Execute an inline flow definition immediately without registering it.
|
|
146
|
+
* Ideal for A/B experiments, feature flags, and integration tests.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* await dap.executeFlow({
|
|
150
|
+
* id: 'quick-tip',
|
|
151
|
+
* steps: [{ type: 'tooltip', trigger: { selector: '#save-btn' }, content: { text: 'Save here!' } }]
|
|
152
|
+
* });
|
|
153
|
+
*/
|
|
154
|
+
executeFlow(flow: DapFlowDefinition): Promise<void>;
|
|
155
|
+
/**
|
|
156
|
+
* Reset the run-count / completion record for a specific flow (or all flows)
|
|
157
|
+
* stored in localStorage.
|
|
158
|
+
*
|
|
159
|
+
* Use this when a flow that has reached its `maxRuns` limit should be allowed
|
|
160
|
+
* to run again — e.g. after a user logs out, completes an upgrade, or during
|
|
161
|
+
* development / testing.
|
|
162
|
+
*
|
|
163
|
+
* @param flowId - ID of the flow to reset. Omit to reset **all** flows.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* // Reset a single flow
|
|
167
|
+
* dap.resetFlowRuns('019cc85a-5712-7dcd-a17f-ef116293fa41');
|
|
168
|
+
*
|
|
169
|
+
* // Reset every flow (e.g. on sign-out)
|
|
170
|
+
* dap.resetFlowRuns();
|
|
171
|
+
*/
|
|
172
|
+
resetFlowRuns(flowId?: string): void;
|
|
173
|
+
}
|
|
174
|
+
declare global {
|
|
175
|
+
interface Window {
|
|
176
|
+
DAP: DapSDK;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Initialize DAP SDK with optional user context
|
|
181
|
+
*/
|
|
182
|
+
declare function init(opts: DapInitOptions): Promise<void>;
|
|
86
183
|
/**
|
|
87
184
|
* Set user context and trigger flow re-evaluation
|
|
88
185
|
*/
|
|
@@ -99,15 +196,43 @@ declare function getUser(): DapUser | null;
|
|
|
99
196
|
* Clear user context
|
|
100
197
|
*/
|
|
101
198
|
declare function clearUser(): void;
|
|
102
|
-
declare function runModalSequence(): void;
|
|
103
|
-
declare function executeFlow(flow: any): Promise<void>;
|
|
104
199
|
/**
|
|
105
|
-
*
|
|
200
|
+
* Reset the run-count / completion record for a flow (or all flows) stored in localStorage.
|
|
201
|
+
*
|
|
202
|
+
* The engine tracks three keys per flow:
|
|
203
|
+
* - `dap_flow_runs_<id>` — cumulative run counter (OneTime / Recurring)
|
|
204
|
+
* - `dap_flow_completed_<id>` — completion marker (OneTime)
|
|
205
|
+
* - `dap_flow_last_run_<id>` — last-run timestamp (Daily / Weekly / Monthly)
|
|
206
|
+
*
|
|
207
|
+
* @param flowId - The flow ID to reset. Omit (or pass `undefined`) to reset ALL flows.
|
|
208
|
+
*/
|
|
209
|
+
declare function resetFlowRuns(flowId?: string): void;
|
|
210
|
+
declare function executeFlow(flow: DapFlowDefinition): Promise<void>;
|
|
211
|
+
/**
|
|
212
|
+
* Register a flow for later execution by ID.
|
|
213
|
+
* Evicts the oldest entry when the map exceeds MAX_REGISTERED_FLOWS to prevent
|
|
214
|
+
* unbounded growth in long-running SPAs.
|
|
106
215
|
*/
|
|
107
216
|
declare function registerFlow(flowData: FlowData): void;
|
|
108
217
|
/**
|
|
109
218
|
* Start a flow by ID (from registered flows or backend)
|
|
110
219
|
*/
|
|
111
220
|
declare function startFlow(flowId: string): Promise<void>;
|
|
221
|
+
/**
|
|
222
|
+
* The DAP SDK singleton — the primary way to interact with the SDK.
|
|
223
|
+
*
|
|
224
|
+
* **ESM / bundler (React, Vue, Angular, etc.):**
|
|
225
|
+
* ```ts
|
|
226
|
+
* import { dap } from '@cognior/iap-sdk';
|
|
227
|
+
* await dap.init({ configUrl: 'https://cdn.example.com/config.json', screenId: 'home' });
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* **Script tag (plain HTML):**
|
|
231
|
+
* ```html
|
|
232
|
+
* <script src="https://cdn.example.com/iap-sdk.umd.js"></script>
|
|
233
|
+
* <script>DAP.init({ configUrl: '...' });</script>
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
declare const dap: DapSDK;
|
|
112
237
|
|
|
113
|
-
export { type DapUser, clearUser, executeFlow, getUser, init, registerFlow,
|
|
238
|
+
export { type DapFlowDefinition, type DapFlowStep, type DapInitOptions, type DapSDK, type DapUser, type FlowData, clearUser, dap, executeFlow, getUser, init, registerFlow, resetFlowRuns, setUser, startFlow, updateUser };
|