@wokuapp/react-native 0.1.0 → 0.3.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.
- package/README.md +103 -14
- package/dist/index.cjs +309 -93
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +96 -63
- package/dist/index.d.ts +96 -63
- package/dist/index.js +309 -93
- package/dist/index.js.map +1 -1
- package/package.json +27 -18
package/dist/index.d.ts
CHANGED
|
@@ -16,7 +16,13 @@ interface HttpRequest {
|
|
|
16
16
|
method: string;
|
|
17
17
|
url: string;
|
|
18
18
|
headers: Record<string, string>;
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* JSON string for text/rating captures, or a `FormData` for audio captures
|
|
21
|
+
* (multipart). For `FormData` the host's `fetch` sets the
|
|
22
|
+
* `multipart/form-data` Content-Type (with boundary) itself.
|
|
23
|
+
*/
|
|
24
|
+
body?: string | FormData;
|
|
25
|
+
signal?: AbortSignal;
|
|
20
26
|
}
|
|
21
27
|
/** HTTP transport. Defaults to global `fetch`. */
|
|
22
28
|
interface HttpClient {
|
|
@@ -55,8 +61,14 @@ declare const noopLogger: Logger;
|
|
|
55
61
|
* capture payloads and hands them to injectable adapters (HTTP, storage,
|
|
56
62
|
* audio). React Native apps wire those adapters at init time.
|
|
57
63
|
*/
|
|
58
|
-
/** The
|
|
59
|
-
type CaptureKind = 'woku' | 'nps';
|
|
64
|
+
/** The four capture instruments supported by API v1. */
|
|
65
|
+
type CaptureKind = 'woku' | 'nps' | 'csat' | 'ces';
|
|
66
|
+
type CaptureLanguage = 'es' | 'en';
|
|
67
|
+
/** Capture provenance, declared when the response is first created. */
|
|
68
|
+
interface CaptureContext {
|
|
69
|
+
collectionKind?: 'standalone' | 'flow';
|
|
70
|
+
flowId?: string;
|
|
71
|
+
}
|
|
60
72
|
/** An audio attachment for a text/voice comment. */
|
|
61
73
|
interface AudioAttachment {
|
|
62
74
|
/** URI or local path to the recorded audio file. */
|
|
@@ -74,7 +86,7 @@ interface Respondent {
|
|
|
74
86
|
externalId?: string;
|
|
75
87
|
}
|
|
76
88
|
/** Input for a Woku capture (1-tap rating 1..5 + optional comment/audio). */
|
|
77
|
-
interface WokuCaptureInput {
|
|
89
|
+
interface WokuCaptureInput extends CaptureContext {
|
|
78
90
|
wokuId: string;
|
|
79
91
|
/** Integer 1..5. */
|
|
80
92
|
rating: number;
|
|
@@ -83,30 +95,36 @@ interface WokuCaptureInput {
|
|
|
83
95
|
respondent?: Respondent;
|
|
84
96
|
/** Arbitrary context tags attached to the submission. */
|
|
85
97
|
metadata?: Record<string, unknown>;
|
|
98
|
+
dispatchToken?: string;
|
|
99
|
+
language?: CaptureLanguage;
|
|
86
100
|
}
|
|
87
101
|
/** Input for an NPS capture (score 0..10 + optional review). */
|
|
88
|
-
interface NpsCaptureInput {
|
|
89
|
-
npsId
|
|
102
|
+
interface NpsCaptureInput extends CaptureContext {
|
|
103
|
+
npsId?: string;
|
|
90
104
|
/** Integer 0..10. */
|
|
91
105
|
score: number;
|
|
92
106
|
comment?: string;
|
|
93
107
|
audio?: AudioAttachment;
|
|
94
108
|
respondent?: Respondent;
|
|
95
109
|
metadata?: Record<string, unknown>;
|
|
110
|
+
dispatchToken?: string;
|
|
111
|
+
language?: CaptureLanguage;
|
|
96
112
|
}
|
|
97
113
|
/** Normalized submission persisted in the offline queue and sent to Woku. */
|
|
98
|
-
interface CaptureSubmission {
|
|
114
|
+
interface CaptureSubmission extends CaptureContext {
|
|
99
115
|
/** Client-generated idempotency id. */
|
|
100
116
|
id: string;
|
|
101
117
|
kind: CaptureKind;
|
|
102
118
|
companyId: string;
|
|
103
|
-
targetId
|
|
119
|
+
targetId?: string;
|
|
104
120
|
rating?: number;
|
|
105
121
|
score?: number;
|
|
106
122
|
comment?: string;
|
|
107
123
|
audio?: AudioAttachment;
|
|
108
124
|
respondent?: Respondent;
|
|
109
125
|
metadata?: Record<string, unknown>;
|
|
126
|
+
dispatchToken?: string;
|
|
127
|
+
language?: CaptureLanguage;
|
|
110
128
|
/** Unix epoch ms when the capture was created on the device. */
|
|
111
129
|
createdAt: number;
|
|
112
130
|
}
|
|
@@ -117,10 +135,67 @@ interface SubmissionResult {
|
|
|
117
135
|
/** Server id once accepted. */
|
|
118
136
|
remoteId?: string;
|
|
119
137
|
error?: string;
|
|
138
|
+
retryable?: boolean;
|
|
139
|
+
}
|
|
140
|
+
/** Focused satisfaction/effort scores; audio is not supported by these API kinds. */
|
|
141
|
+
interface CsatCaptureInput extends CaptureContext {
|
|
142
|
+
csatId: string;
|
|
143
|
+
score: number;
|
|
144
|
+
comment?: string;
|
|
145
|
+
respondent?: Respondent;
|
|
146
|
+
metadata?: Record<string, unknown>;
|
|
147
|
+
dispatchToken?: string;
|
|
148
|
+
}
|
|
149
|
+
interface CesCaptureInput extends CaptureContext {
|
|
150
|
+
cesId: string;
|
|
151
|
+
score: number;
|
|
152
|
+
comment?: string;
|
|
153
|
+
respondent?: Respondent;
|
|
154
|
+
metadata?: Record<string, unknown>;
|
|
155
|
+
dispatchToken?: string;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
interface FailedCapture {
|
|
159
|
+
submission: CaptureSubmission;
|
|
160
|
+
reason: string;
|
|
161
|
+
}
|
|
162
|
+
interface OfflineQueueOptions {
|
|
163
|
+
storage?: Storage;
|
|
164
|
+
storageKey?: string;
|
|
165
|
+
maxAttempts?: number;
|
|
166
|
+
/** Restrict reads, delivery and clearing to this company, including legacy rows. */
|
|
167
|
+
companyId?: string;
|
|
168
|
+
}
|
|
169
|
+
interface FlushResult {
|
|
170
|
+
sent: number;
|
|
171
|
+
failed: number;
|
|
172
|
+
remaining: number;
|
|
173
|
+
quarantined?: boolean;
|
|
174
|
+
}
|
|
175
|
+
/** Persistent FIFO with scoped ownership, atomic local mutations and retained failures. */
|
|
176
|
+
declare class OfflineQueue {
|
|
177
|
+
private readonly storage;
|
|
178
|
+
private readonly key;
|
|
179
|
+
private readonly maxAttempts;
|
|
180
|
+
private readonly companyId?;
|
|
181
|
+
constructor(opts?: OfflineQueueOptions);
|
|
182
|
+
private owned;
|
|
183
|
+
private load;
|
|
184
|
+
private persist;
|
|
185
|
+
private mutation;
|
|
186
|
+
enqueue(submission: CaptureSubmission): Promise<void>;
|
|
187
|
+
size(): Promise<number>;
|
|
188
|
+
pending(): Promise<CaptureSubmission[]>;
|
|
189
|
+
failures(): Promise<FailedCapture[]>;
|
|
190
|
+
acknowledge(submission: CaptureSubmission): Promise<void>;
|
|
191
|
+
reject(submission: CaptureSubmission, reason: string): Promise<void>;
|
|
192
|
+
flush(send: (submission: CaptureSubmission) => Promise<SubmissionResult>): Promise<FlushResult>;
|
|
193
|
+
private runFlush;
|
|
194
|
+
clear(): Promise<void>;
|
|
120
195
|
}
|
|
121
196
|
|
|
122
197
|
interface WokuClientConfig {
|
|
123
|
-
/** Base URL of the Woku API, e.g. `https://
|
|
198
|
+
/** Base URL of the Woku API, e.g. `https://clientapi.woku.app`. */
|
|
124
199
|
apiUrl: string;
|
|
125
200
|
/** Public SDK key issued per company for capture ingestion. */
|
|
126
201
|
publicKey: string;
|
|
@@ -129,8 +204,12 @@ interface WokuClientConfig {
|
|
|
129
204
|
/** HTTP transport. Defaults to the global `fetch`. */
|
|
130
205
|
http?: HttpClient;
|
|
131
206
|
logger?: Logger;
|
|
132
|
-
/** Ingest path appended to `apiUrl`. Defaults to `/
|
|
207
|
+
/** Ingest path appended to `apiUrl`. Defaults to `/v1/captures`. */
|
|
133
208
|
capturePath?: string;
|
|
209
|
+
/** Default audio language for WokuSdk builders; send() preserves payloads. */
|
|
210
|
+
language?: 'es' | 'en';
|
|
211
|
+
/** Bound a transport attempt, including injected adapters. Default 30s. */
|
|
212
|
+
timeoutMs?: number;
|
|
134
213
|
}
|
|
135
214
|
/**
|
|
136
215
|
* Thin, typed transport to the Woku capture ingest endpoint. Stateless:
|
|
@@ -153,61 +232,10 @@ declare class WokuClient {
|
|
|
153
232
|
private safeJson;
|
|
154
233
|
}
|
|
155
234
|
|
|
156
|
-
interface OfflineQueueOptions {
|
|
157
|
-
storage?: Storage;
|
|
158
|
-
/** Storage key for the persisted queue. */
|
|
159
|
-
storageKey?: string;
|
|
160
|
-
/** Drop a submission after this many failed delivery attempts. */
|
|
161
|
-
maxAttempts?: number;
|
|
162
|
-
}
|
|
163
|
-
interface FlushResult {
|
|
164
|
-
sent: number;
|
|
165
|
-
failed: number;
|
|
166
|
-
remaining: number;
|
|
167
|
-
/** Set when flushing stopped early due to quarantine. */
|
|
168
|
-
quarantined?: boolean;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Durable, FIFO offline buffer for captures. Persists through an
|
|
172
|
-
* injectable {@link Storage} so submissions survive app restarts, and
|
|
173
|
-
* flushes them through a caller-provided `send` function. Pure and
|
|
174
|
-
* deterministic: no timers, no platform APIs.
|
|
175
|
-
*
|
|
176
|
-
* Delivery semantics on flush:
|
|
177
|
-
* - `sent` -> removed from the queue.
|
|
178
|
-
* - quarantine -> flush stops (server is rate-limiting the
|
|
179
|
-
* respondent); items are kept for the next attempt.
|
|
180
|
-
* - network error -> attempt count bumped, item kept, flush continues.
|
|
181
|
-
* - `failed` -> attempt count bumped; dropped once maxAttempts is
|
|
182
|
-
* reached so a permanently-bad item can't wedge it.
|
|
183
|
-
*/
|
|
184
|
-
declare class OfflineQueue {
|
|
185
|
-
private readonly storage;
|
|
186
|
-
private readonly key;
|
|
187
|
-
private readonly maxAttempts;
|
|
188
|
-
private items;
|
|
189
|
-
constructor(opts?: OfflineQueueOptions);
|
|
190
|
-
private load;
|
|
191
|
-
private persist;
|
|
192
|
-
/** Adds a submission to the tail of the queue (dedup by id). */
|
|
193
|
-
enqueue(submission: CaptureSubmission): Promise<void>;
|
|
194
|
-
size(): Promise<number>;
|
|
195
|
-
/** Returns a copy of the pending submissions (oldest first). */
|
|
196
|
-
pending(): Promise<CaptureSubmission[]>;
|
|
197
|
-
/**
|
|
198
|
-
* Attempts to deliver every queued submission through `send`, applying
|
|
199
|
-
* the delivery semantics documented on the class. Persists once at the
|
|
200
|
-
* end and returns a summary.
|
|
201
|
-
*/
|
|
202
|
-
flush(send: (submission: CaptureSubmission) => Promise<SubmissionResult>): Promise<FlushResult>;
|
|
203
|
-
/** Clears the queue (e.g. on logout). */
|
|
204
|
-
clear(): Promise<void>;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
235
|
interface WokuSdkConfig extends WokuClientConfig {
|
|
208
236
|
/** Storage adapter for the offline queue (MMKV/AsyncStorage in RN). */
|
|
209
237
|
storage?: Storage;
|
|
210
|
-
/**
|
|
238
|
+
/** Retain a failed submission for inspection after this many flush attempts. */
|
|
211
239
|
maxQueueAttempts?: number;
|
|
212
240
|
}
|
|
213
241
|
/**
|
|
@@ -230,16 +258,21 @@ declare class WokuSdk {
|
|
|
230
258
|
private readonly queue;
|
|
231
259
|
private readonly logger;
|
|
232
260
|
private readonly companyId;
|
|
261
|
+
private readonly language;
|
|
233
262
|
constructor(config: WokuSdkConfig);
|
|
234
263
|
/** Captures a Woku rating (1..5) with optional text/audio comment. */
|
|
235
264
|
captureWoku(input: WokuCaptureInput): Promise<SubmissionResult>;
|
|
236
265
|
/** Captures an NPS score (0..10) with optional text/audio review. */
|
|
237
266
|
captureNps(input: NpsCaptureInput): Promise<SubmissionResult>;
|
|
267
|
+
captureCsat(input: CsatCaptureInput): Promise<SubmissionResult>;
|
|
268
|
+
captureCes(input: CesCaptureInput): Promise<SubmissionResult>;
|
|
238
269
|
/** Retries every queued submission. Safe to call on app foreground or
|
|
239
270
|
* when connectivity is regained. */
|
|
240
271
|
flush(): Promise<FlushResult>;
|
|
241
272
|
/** Number of submissions waiting to be delivered. */
|
|
242
273
|
pendingCount(): Promise<number>;
|
|
274
|
+
/** Inspect retained captures whose automatic attempt budget was exhausted. */
|
|
275
|
+
failedCaptures(): Promise<FailedCapture[]>;
|
|
243
276
|
/** Clears the offline queue (e.g. on user logout). */
|
|
244
277
|
clearQueue(): Promise<void>;
|
|
245
278
|
/**
|
|
@@ -276,4 +309,4 @@ declare class WokuNetworkError extends WokuError {
|
|
|
276
309
|
constructor(message: string);
|
|
277
310
|
}
|
|
278
311
|
|
|
279
|
-
export { type AudioAttachment, type CaptureKind, type CaptureSubmission, type FlushResult, type HttpClient, type HttpRequest, type HttpResponse, InMemoryStorage, type Logger, type NpsCaptureInput, OfflineQueue, type OfflineQueueOptions, type Respondent, type Storage, type SubmissionResult, type WokuCaptureInput, WokuClient, type WokuClientConfig, WokuConfigError, WokuError, WokuNetworkError, WokuQuarantineError, WokuSdk, type WokuSdkConfig, WokuValidationError, fetchHttpClient, noopLogger };
|
|
312
|
+
export { type AudioAttachment, type CaptureContext, type CaptureKind, type CaptureLanguage, type CaptureSubmission, type CesCaptureInput, type CsatCaptureInput, type FailedCapture, type FlushResult, type HttpClient, type HttpRequest, type HttpResponse, InMemoryStorage, type Logger, type NpsCaptureInput, OfflineQueue, type OfflineQueueOptions, type Respondent, type Storage, type SubmissionResult, type WokuCaptureInput, WokuClient, type WokuClientConfig, WokuConfigError, WokuError, WokuNetworkError, WokuQuarantineError, WokuSdk, type WokuSdkConfig, WokuValidationError, fetchHttpClient, noopLogger };
|