@spike-forms/sdk 0.2.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 +89 -0
- package/dist/index.d.mts +2345 -0
- package/dist/index.d.ts +2345 -0
- package/dist/index.js +1569 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1552 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +62 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2345 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Client for the Spike Forms SDK
|
|
3
|
+
*
|
|
4
|
+
* Provides a wrapper around fetch that handles:
|
|
5
|
+
* - Authentication with Bearer token
|
|
6
|
+
* - Request timeout with AbortController
|
|
7
|
+
* - Query parameter encoding
|
|
8
|
+
* - Error response mapping to SDK error types
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Options for HTTP requests
|
|
12
|
+
*/
|
|
13
|
+
interface RequestOptions {
|
|
14
|
+
/** Query parameters to append to the URL */
|
|
15
|
+
params?: Record<string, string | number | boolean | undefined>;
|
|
16
|
+
/** Additional headers to include in the request */
|
|
17
|
+
headers?: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Configuration for the HTTP client
|
|
21
|
+
*/
|
|
22
|
+
interface HttpClientConfig {
|
|
23
|
+
/** API key for authentication */
|
|
24
|
+
apiKey: string;
|
|
25
|
+
/** Base URL for API requests */
|
|
26
|
+
baseUrl: string;
|
|
27
|
+
/** Request timeout in milliseconds */
|
|
28
|
+
timeout: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* HTTP client for making authenticated requests to the Spike Forms API.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const http = new HttpClient({
|
|
36
|
+
* apiKey: 'sk_test_123',
|
|
37
|
+
* baseUrl: 'https://spike.ac',
|
|
38
|
+
* timeout: 30000
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* const forms = await http.get<Form[]>('/api/forms');
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare class HttpClient {
|
|
45
|
+
private readonly apiKey;
|
|
46
|
+
private readonly baseUrl;
|
|
47
|
+
private readonly timeout;
|
|
48
|
+
constructor(config: HttpClientConfig);
|
|
49
|
+
/**
|
|
50
|
+
* Make a GET request
|
|
51
|
+
*/
|
|
52
|
+
get<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
53
|
+
/**
|
|
54
|
+
* Make a POST request with authentication
|
|
55
|
+
*/
|
|
56
|
+
post<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
57
|
+
/**
|
|
58
|
+
* Make a PATCH request
|
|
59
|
+
*/
|
|
60
|
+
patch<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
61
|
+
/**
|
|
62
|
+
* Make a PUT request
|
|
63
|
+
*/
|
|
64
|
+
put<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
65
|
+
/**
|
|
66
|
+
* Make a DELETE request
|
|
67
|
+
*/
|
|
68
|
+
delete<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
69
|
+
/**
|
|
70
|
+
* Make a POST request without authentication (for public form submissions)
|
|
71
|
+
*/
|
|
72
|
+
postPublic<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
73
|
+
/**
|
|
74
|
+
* Build a URL with query parameters
|
|
75
|
+
*/
|
|
76
|
+
buildUrl(path: string, params?: Record<string, string | number | boolean | undefined>): string;
|
|
77
|
+
/**
|
|
78
|
+
* Make an HTTP request with timeout and error handling
|
|
79
|
+
*/
|
|
80
|
+
private request;
|
|
81
|
+
/**
|
|
82
|
+
* Handle error responses and throw appropriate SDK errors
|
|
83
|
+
*/
|
|
84
|
+
private handleErrorResponse;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Type definitions for the Spike Forms SDK
|
|
89
|
+
*
|
|
90
|
+
* This file contains all TypeScript interfaces for:
|
|
91
|
+
* - Core entities (Form, Submission, Project, Team, User, etc.)
|
|
92
|
+
* - Request/response types for all API operations
|
|
93
|
+
* - Pagination parameter types
|
|
94
|
+
*
|
|
95
|
+
* @module types
|
|
96
|
+
*/
|
|
97
|
+
/**
|
|
98
|
+
* Represents a form in Spike Forms
|
|
99
|
+
*/
|
|
100
|
+
interface Form {
|
|
101
|
+
/** Unique identifier for the form */
|
|
102
|
+
id: string;
|
|
103
|
+
/** URL-friendly slug for the form */
|
|
104
|
+
slug: string;
|
|
105
|
+
/** Display name of the form */
|
|
106
|
+
name: string;
|
|
107
|
+
/** ID of the project this form belongs to, or null if not in a project */
|
|
108
|
+
project_id: string | null;
|
|
109
|
+
/** ID of the user who owns this form */
|
|
110
|
+
user_id: string;
|
|
111
|
+
/** Whether the form is currently accepting submissions */
|
|
112
|
+
is_active: boolean;
|
|
113
|
+
/** Total number of submissions received */
|
|
114
|
+
submission_count: number;
|
|
115
|
+
/** ISO 8601 timestamp of when the form was created */
|
|
116
|
+
created_at: string;
|
|
117
|
+
/** ISO 8601 timestamp of when the form was last updated */
|
|
118
|
+
updated_at: string;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Represents a submission to a form
|
|
122
|
+
*/
|
|
123
|
+
interface Submission {
|
|
124
|
+
/** Unique identifier for the submission */
|
|
125
|
+
id: string;
|
|
126
|
+
/** ID of the form this submission belongs to */
|
|
127
|
+
form_id: string;
|
|
128
|
+
/** The submitted form data as key-value pairs */
|
|
129
|
+
data: Record<string, unknown>;
|
|
130
|
+
/** Whether this submission has been marked as spam */
|
|
131
|
+
is_spam: boolean;
|
|
132
|
+
/** Whether this submission has been read */
|
|
133
|
+
is_read: boolean;
|
|
134
|
+
/** Whether this submission has been starred */
|
|
135
|
+
is_starred: boolean;
|
|
136
|
+
/** IP address of the submitter, or null if not captured */
|
|
137
|
+
ip_address: string | null;
|
|
138
|
+
/** User agent string of the submitter, or null if not captured */
|
|
139
|
+
user_agent: string | null;
|
|
140
|
+
/** ISO 8601 timestamp of when the submission was created */
|
|
141
|
+
created_at: string;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Statistics about submissions for a form
|
|
145
|
+
*/
|
|
146
|
+
interface SubmissionStats {
|
|
147
|
+
/** Total number of submissions */
|
|
148
|
+
total: number;
|
|
149
|
+
/** Number of submissions marked as spam */
|
|
150
|
+
spam: number;
|
|
151
|
+
/** Number of unread submissions */
|
|
152
|
+
unread: number;
|
|
153
|
+
/** Number of starred submissions */
|
|
154
|
+
starred: number;
|
|
155
|
+
/** Number of submissions received today */
|
|
156
|
+
today: number;
|
|
157
|
+
/** Number of submissions received this week */
|
|
158
|
+
this_week: number;
|
|
159
|
+
/** Number of submissions received this month */
|
|
160
|
+
this_month: number;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Represents a project for organizing forms
|
|
164
|
+
*/
|
|
165
|
+
interface Project {
|
|
166
|
+
/** Unique identifier for the project */
|
|
167
|
+
id: string;
|
|
168
|
+
/** Display name of the project */
|
|
169
|
+
name: string;
|
|
170
|
+
/** ID of the user who owns this project */
|
|
171
|
+
user_id: string;
|
|
172
|
+
/** Number of forms in this project */
|
|
173
|
+
form_count: number;
|
|
174
|
+
/** ISO 8601 timestamp of when the project was created */
|
|
175
|
+
created_at: string;
|
|
176
|
+
/** ISO 8601 timestamp of when the project was last updated */
|
|
177
|
+
updated_at: string;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Represents a team for collaborative form management
|
|
181
|
+
*/
|
|
182
|
+
interface Team {
|
|
183
|
+
/** Unique identifier for the team */
|
|
184
|
+
id: string;
|
|
185
|
+
/** Display name of the team */
|
|
186
|
+
name: string;
|
|
187
|
+
/** ID of the user who owns this team */
|
|
188
|
+
owner_id: string;
|
|
189
|
+
/** Number of members in this team */
|
|
190
|
+
member_count: number;
|
|
191
|
+
/** ISO 8601 timestamp of when the team was created */
|
|
192
|
+
created_at: string;
|
|
193
|
+
/** ISO 8601 timestamp of when the team was last updated */
|
|
194
|
+
updated_at: string;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Role types for team members
|
|
198
|
+
*/
|
|
199
|
+
type TeamMemberRole = 'owner' | 'admin' | 'member';
|
|
200
|
+
/**
|
|
201
|
+
* Role types for team invitations (owner cannot be invited)
|
|
202
|
+
*/
|
|
203
|
+
type TeamInvitationRole = 'admin' | 'member';
|
|
204
|
+
/**
|
|
205
|
+
* Represents a member of a team
|
|
206
|
+
*/
|
|
207
|
+
interface TeamMember {
|
|
208
|
+
/** Unique identifier for the team membership */
|
|
209
|
+
id: string;
|
|
210
|
+
/** ID of the team */
|
|
211
|
+
team_id: string;
|
|
212
|
+
/** ID of the user */
|
|
213
|
+
user_id: string;
|
|
214
|
+
/** Role of the member in the team */
|
|
215
|
+
role: TeamMemberRole;
|
|
216
|
+
/** Basic user information */
|
|
217
|
+
user: {
|
|
218
|
+
/** User's unique identifier */
|
|
219
|
+
id: string;
|
|
220
|
+
/** User's display name */
|
|
221
|
+
name: string;
|
|
222
|
+
/** User's email address */
|
|
223
|
+
email: string;
|
|
224
|
+
};
|
|
225
|
+
/** ISO 8601 timestamp of when the member joined */
|
|
226
|
+
created_at: string;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Represents a pending invitation to join a team
|
|
230
|
+
*/
|
|
231
|
+
interface TeamInvitation {
|
|
232
|
+
/** Unique identifier for the invitation */
|
|
233
|
+
id: string;
|
|
234
|
+
/** ID of the team being invited to */
|
|
235
|
+
team_id: string;
|
|
236
|
+
/** Email address of the invitee */
|
|
237
|
+
email: string;
|
|
238
|
+
/** Role the invitee will have upon accepting */
|
|
239
|
+
role: TeamInvitationRole;
|
|
240
|
+
/** Unique token for accepting the invitation */
|
|
241
|
+
token: string;
|
|
242
|
+
/** ISO 8601 timestamp of when the invitation expires */
|
|
243
|
+
expires_at: string;
|
|
244
|
+
/** ISO 8601 timestamp of when the invitation was created */
|
|
245
|
+
created_at: string;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Represents a user account
|
|
249
|
+
*/
|
|
250
|
+
interface User {
|
|
251
|
+
/** Unique identifier for the user */
|
|
252
|
+
id: string;
|
|
253
|
+
/** User's display name */
|
|
254
|
+
name: string;
|
|
255
|
+
/** User's email address */
|
|
256
|
+
email: string;
|
|
257
|
+
/** Whether two-factor authentication is enabled */
|
|
258
|
+
two_factor_enabled: boolean;
|
|
259
|
+
/** ISO 8601 timestamp of when the user was created */
|
|
260
|
+
created_at: string;
|
|
261
|
+
/** ISO 8601 timestamp of when the user was last updated */
|
|
262
|
+
updated_at: string;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Represents an API key for authentication
|
|
266
|
+
*/
|
|
267
|
+
interface ApiKey {
|
|
268
|
+
/** Unique identifier for the API key */
|
|
269
|
+
id: string;
|
|
270
|
+
/** Display name for the API key */
|
|
271
|
+
name: string;
|
|
272
|
+
/** The API key value (only shown on creation) */
|
|
273
|
+
key: string;
|
|
274
|
+
/** ISO 8601 timestamp of when the key was last used, or null if never used */
|
|
275
|
+
last_used_at: string | null;
|
|
276
|
+
/** ISO 8601 timestamp of when the key was created */
|
|
277
|
+
created_at: string;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Operators available for rule conditions
|
|
281
|
+
*/
|
|
282
|
+
type RuleConditionOperator = 'equals' | 'contains' | 'starts_with' | 'ends_with' | 'regex';
|
|
283
|
+
/**
|
|
284
|
+
* Action types available for rules
|
|
285
|
+
*/
|
|
286
|
+
type RuleActionType = 'email' | 'webhook' | 'slack' | 'discord';
|
|
287
|
+
/**
|
|
288
|
+
* Represents a condition in a rule
|
|
289
|
+
*/
|
|
290
|
+
interface RuleCondition {
|
|
291
|
+
/** The field name to evaluate */
|
|
292
|
+
field: string;
|
|
293
|
+
/** The comparison operator */
|
|
294
|
+
operator: RuleConditionOperator;
|
|
295
|
+
/** The value to compare against */
|
|
296
|
+
value: string;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Represents an action to take when rule conditions are met
|
|
300
|
+
*/
|
|
301
|
+
interface RuleAction {
|
|
302
|
+
/** The type of action */
|
|
303
|
+
type: RuleActionType;
|
|
304
|
+
/** Configuration specific to the action type */
|
|
305
|
+
config: Record<string, unknown>;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Represents a rule for conditional processing of submissions
|
|
309
|
+
*/
|
|
310
|
+
interface Rule {
|
|
311
|
+
/** Unique identifier for the rule */
|
|
312
|
+
id: string;
|
|
313
|
+
/** ID of the form this rule belongs to */
|
|
314
|
+
form_id: string;
|
|
315
|
+
/** Display name of the rule */
|
|
316
|
+
name: string;
|
|
317
|
+
/** Conditions that must be met for the rule to trigger */
|
|
318
|
+
conditions: RuleCondition[];
|
|
319
|
+
/** Actions to take when conditions are met */
|
|
320
|
+
actions: RuleAction[];
|
|
321
|
+
/** Whether the rule is currently active */
|
|
322
|
+
is_active: boolean;
|
|
323
|
+
/** ISO 8601 timestamp of when the rule was created */
|
|
324
|
+
created_at: string;
|
|
325
|
+
/** ISO 8601 timestamp of when the rule was last updated */
|
|
326
|
+
updated_at: string;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Generic success response
|
|
330
|
+
*/
|
|
331
|
+
interface SuccessResponse {
|
|
332
|
+
/** Whether the operation was successful */
|
|
333
|
+
success: boolean;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Response from submitting to a form
|
|
337
|
+
*/
|
|
338
|
+
interface SubmissionResponse {
|
|
339
|
+
/** Whether the submission was successful */
|
|
340
|
+
success: boolean;
|
|
341
|
+
/** ID of the created submission (if successful) */
|
|
342
|
+
submission_id?: string;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Parameters for listing forms
|
|
346
|
+
*/
|
|
347
|
+
interface ListFormsParams {
|
|
348
|
+
/** Maximum number of forms to return */
|
|
349
|
+
limit?: number;
|
|
350
|
+
/** Number of forms to skip for pagination */
|
|
351
|
+
offset?: number;
|
|
352
|
+
/** Filter forms by project ID */
|
|
353
|
+
project_id?: string;
|
|
354
|
+
/** Include inactive forms in the results */
|
|
355
|
+
include_inactive?: boolean;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Request body for creating a form
|
|
359
|
+
*/
|
|
360
|
+
interface CreateFormRequest {
|
|
361
|
+
/** Display name for the form */
|
|
362
|
+
name: string;
|
|
363
|
+
/** ID of the project to add the form to */
|
|
364
|
+
project_id?: string;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Request body for updating a form
|
|
368
|
+
*/
|
|
369
|
+
interface UpdateFormRequest {
|
|
370
|
+
/** New display name for the form */
|
|
371
|
+
name?: string;
|
|
372
|
+
/** ID of the project to move the form to */
|
|
373
|
+
project_id?: string | null;
|
|
374
|
+
/** Whether the form should be active */
|
|
375
|
+
is_active?: boolean;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Sort order for submissions
|
|
379
|
+
*/
|
|
380
|
+
type SubmissionOrder = 'asc' | 'desc';
|
|
381
|
+
/**
|
|
382
|
+
* Parameters for listing submissions
|
|
383
|
+
*/
|
|
384
|
+
interface ListSubmissionsParams {
|
|
385
|
+
/** Maximum number of submissions to return */
|
|
386
|
+
limit?: number;
|
|
387
|
+
/** Number of submissions to skip for pagination */
|
|
388
|
+
offset?: number;
|
|
389
|
+
/** Only return submissions created after this ISO 8601 timestamp */
|
|
390
|
+
since?: string;
|
|
391
|
+
/** Sort order for submissions */
|
|
392
|
+
order?: SubmissionOrder;
|
|
393
|
+
/** Filter string for searching submissions */
|
|
394
|
+
filter?: string;
|
|
395
|
+
/** Filter by spam status */
|
|
396
|
+
is_spam?: boolean;
|
|
397
|
+
/** Filter by read status */
|
|
398
|
+
is_read?: boolean;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Available bulk actions for submissions
|
|
402
|
+
*/
|
|
403
|
+
type BulkAction = 'markRead' | 'markUnread' | 'star' | 'unstar' | 'markSpam' | 'notSpam';
|
|
404
|
+
/**
|
|
405
|
+
* Request body for bulk updating submissions
|
|
406
|
+
*/
|
|
407
|
+
interface BulkUpdateRequest {
|
|
408
|
+
/** The action to perform */
|
|
409
|
+
action: BulkAction;
|
|
410
|
+
/** IDs of submissions to update */
|
|
411
|
+
submission_ids: string[];
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Request body for creating a rule
|
|
415
|
+
*/
|
|
416
|
+
interface CreateRuleRequest {
|
|
417
|
+
/** Display name for the rule */
|
|
418
|
+
name: string;
|
|
419
|
+
/** Conditions that must be met for the rule to trigger */
|
|
420
|
+
conditions: RuleCondition[];
|
|
421
|
+
/** Actions to take when conditions are met */
|
|
422
|
+
actions: RuleAction[];
|
|
423
|
+
/** Whether the rule should be active (defaults to true) */
|
|
424
|
+
is_active?: boolean;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Request body for updating a rule
|
|
428
|
+
*/
|
|
429
|
+
interface UpdateRuleRequest {
|
|
430
|
+
/** New display name for the rule */
|
|
431
|
+
name?: string;
|
|
432
|
+
/** New conditions for the rule */
|
|
433
|
+
conditions?: RuleCondition[];
|
|
434
|
+
/** New actions for the rule */
|
|
435
|
+
actions?: RuleAction[];
|
|
436
|
+
/** Whether the rule should be active */
|
|
437
|
+
is_active?: boolean;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Request body for creating a project
|
|
441
|
+
*/
|
|
442
|
+
interface CreateProjectRequest {
|
|
443
|
+
/** Display name for the project */
|
|
444
|
+
name: string;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Request body for updating a project
|
|
448
|
+
*/
|
|
449
|
+
interface UpdateProjectRequest {
|
|
450
|
+
/** New display name for the project */
|
|
451
|
+
name?: string;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Request body for creating a team
|
|
455
|
+
*/
|
|
456
|
+
interface CreateTeamRequest {
|
|
457
|
+
/** Display name for the team */
|
|
458
|
+
name: string;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Request body for updating a team
|
|
462
|
+
*/
|
|
463
|
+
interface UpdateTeamRequest {
|
|
464
|
+
/** New display name for the team */
|
|
465
|
+
name?: string;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Request body for inviting a member to a team
|
|
469
|
+
*/
|
|
470
|
+
interface InviteMemberRequest {
|
|
471
|
+
/** Email address of the person to invite */
|
|
472
|
+
email: string;
|
|
473
|
+
/** Role to assign to the new member */
|
|
474
|
+
role: TeamInvitationRole;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Request body for updating a team member's role
|
|
478
|
+
*/
|
|
479
|
+
interface UpdateMemberRequest {
|
|
480
|
+
/** New role for the member */
|
|
481
|
+
role: TeamInvitationRole;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Request body for updating user profile
|
|
485
|
+
*/
|
|
486
|
+
interface UpdateUserRequest {
|
|
487
|
+
/** New display name */
|
|
488
|
+
name?: string;
|
|
489
|
+
/** New email address */
|
|
490
|
+
email?: string;
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Response from initiating 2FA setup
|
|
494
|
+
*/
|
|
495
|
+
interface Setup2FAResponse {
|
|
496
|
+
/** The TOTP secret for the authenticator app */
|
|
497
|
+
secret: string;
|
|
498
|
+
/** QR code image data for scanning */
|
|
499
|
+
qr_code: string;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Request body for creating an API key
|
|
503
|
+
*/
|
|
504
|
+
interface CreateApiKeyRequest {
|
|
505
|
+
/** Display name for the API key */
|
|
506
|
+
name: string;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Request body for creating a checkout session
|
|
510
|
+
*/
|
|
511
|
+
interface CreateCheckoutRequest {
|
|
512
|
+
/** Stripe price ID for the subscription */
|
|
513
|
+
price_id: string;
|
|
514
|
+
/** URL to redirect to on successful checkout */
|
|
515
|
+
success_url: string;
|
|
516
|
+
/** URL to redirect to if checkout is cancelled */
|
|
517
|
+
cancel_url: string;
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Response from creating a checkout session
|
|
521
|
+
*/
|
|
522
|
+
interface CheckoutResponse {
|
|
523
|
+
/** URL to redirect the user to for checkout */
|
|
524
|
+
url: string;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Response from creating a billing portal session
|
|
528
|
+
*/
|
|
529
|
+
interface PortalResponse {
|
|
530
|
+
/** URL to redirect the user to for the billing portal */
|
|
531
|
+
url: string;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Response from getting a file download URL
|
|
535
|
+
*/
|
|
536
|
+
interface FileDownloadResponse {
|
|
537
|
+
/** Signed URL for downloading the file */
|
|
538
|
+
url: string;
|
|
539
|
+
/** ISO 8601 timestamp of when the URL expires */
|
|
540
|
+
expires_at: string;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Common pagination parameters
|
|
544
|
+
*/
|
|
545
|
+
interface PaginationParams {
|
|
546
|
+
/** Maximum number of items to return */
|
|
547
|
+
limit?: number;
|
|
548
|
+
/** Number of items to skip */
|
|
549
|
+
offset?: number;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Paginated response wrapper
|
|
553
|
+
*/
|
|
554
|
+
interface PaginatedResponse<T> {
|
|
555
|
+
/** Array of items */
|
|
556
|
+
data: T[];
|
|
557
|
+
/** Total number of items available */
|
|
558
|
+
total: number;
|
|
559
|
+
/** Number of items returned */
|
|
560
|
+
count: number;
|
|
561
|
+
/** Current offset */
|
|
562
|
+
offset: number;
|
|
563
|
+
/** Whether there are more items available */
|
|
564
|
+
has_more: boolean;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Forms Resource for the Spike Forms SDK
|
|
569
|
+
*
|
|
570
|
+
* Provides methods for managing forms:
|
|
571
|
+
* - list: Get all forms with pagination support
|
|
572
|
+
* - create: Create a new form
|
|
573
|
+
* - get: Retrieve a single form by ID
|
|
574
|
+
* - update: Update form properties
|
|
575
|
+
* - delete: Delete a form by ID
|
|
576
|
+
* - submit: Submit data to a form (public, no auth required)
|
|
577
|
+
* - getHtml: Get the HTML template for a form
|
|
578
|
+
* - saveHtml: Save HTML template for a form
|
|
579
|
+
*
|
|
580
|
+
* @module resources/forms
|
|
581
|
+
*/
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Response type for getHtml method.
|
|
585
|
+
*/
|
|
586
|
+
interface FormHtmlResponse {
|
|
587
|
+
html: string;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Response type for saveHtml method.
|
|
591
|
+
*/
|
|
592
|
+
interface SaveFormHtmlResponse {
|
|
593
|
+
success: boolean;
|
|
594
|
+
html_url: string | null;
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Resource class for managing forms in Spike Forms.
|
|
598
|
+
*
|
|
599
|
+
* @example
|
|
600
|
+
* ```typescript
|
|
601
|
+
* // List all forms
|
|
602
|
+
* const forms = await client.forms.list({ limit: 10 });
|
|
603
|
+
*
|
|
604
|
+
* // Create a new form
|
|
605
|
+
* const form = await client.forms.create({ name: 'Contact Form' });
|
|
606
|
+
*
|
|
607
|
+
* // Get a specific form
|
|
608
|
+
* const form = await client.forms.get('form_123');
|
|
609
|
+
*
|
|
610
|
+
* // Update a form
|
|
611
|
+
* const updated = await client.forms.update('form_123', { name: 'New Name' });
|
|
612
|
+
*
|
|
613
|
+
* // Delete a form
|
|
614
|
+
* await client.forms.delete('form_123');
|
|
615
|
+
*
|
|
616
|
+
* // Submit to a form (public, no auth)
|
|
617
|
+
* const result = await client.forms.submit('my-form-slug', { email: 'user@example.com' });
|
|
618
|
+
*
|
|
619
|
+
* // Get form HTML template
|
|
620
|
+
* const { html } = await client.forms.getHtml('form_123');
|
|
621
|
+
*
|
|
622
|
+
* // Save form HTML template
|
|
623
|
+
* await client.forms.saveHtml('form_123', '<html>...</html>');
|
|
624
|
+
* ```
|
|
625
|
+
*/
|
|
626
|
+
declare class FormsResource {
|
|
627
|
+
private readonly http;
|
|
628
|
+
/**
|
|
629
|
+
* Create a new FormsResource instance
|
|
630
|
+
* @param http - The HTTP client to use for API requests
|
|
631
|
+
*/
|
|
632
|
+
constructor(http: HttpClient);
|
|
633
|
+
/**
|
|
634
|
+
* List all forms with optional pagination and filtering.
|
|
635
|
+
*
|
|
636
|
+
* @param params - Optional parameters for filtering and pagination
|
|
637
|
+
* @param params.limit - Maximum number of forms to return
|
|
638
|
+
* @param params.offset - Number of forms to skip for pagination
|
|
639
|
+
* @param params.project_id - Filter forms by project ID
|
|
640
|
+
* @param params.include_inactive - Include inactive forms in the results
|
|
641
|
+
* @returns Promise resolving to an array of forms
|
|
642
|
+
*
|
|
643
|
+
* @example
|
|
644
|
+
* ```typescript
|
|
645
|
+
* // Get all forms
|
|
646
|
+
* const forms = await client.forms.list();
|
|
647
|
+
*
|
|
648
|
+
* // Get forms with pagination
|
|
649
|
+
* const forms = await client.forms.list({ limit: 10, offset: 20 });
|
|
650
|
+
*
|
|
651
|
+
* // Get forms for a specific project
|
|
652
|
+
* const forms = await client.forms.list({ project_id: 'proj_123' });
|
|
653
|
+
*
|
|
654
|
+
* // Include inactive forms
|
|
655
|
+
* const forms = await client.forms.list({ include_inactive: true });
|
|
656
|
+
* ```
|
|
657
|
+
*
|
|
658
|
+
* @see Requirements 4.1
|
|
659
|
+
*/
|
|
660
|
+
list(params?: ListFormsParams): Promise<Form[]>;
|
|
661
|
+
/**
|
|
662
|
+
* Create a new form.
|
|
663
|
+
*
|
|
664
|
+
* @param data - The form data to create
|
|
665
|
+
* @param data.name - Display name for the form (required)
|
|
666
|
+
* @param data.project_id - ID of the project to add the form to (optional)
|
|
667
|
+
* @returns Promise resolving to the created form
|
|
668
|
+
*
|
|
669
|
+
* @example
|
|
670
|
+
* ```typescript
|
|
671
|
+
* // Create a simple form
|
|
672
|
+
* const form = await client.forms.create({ name: 'Contact Form' });
|
|
673
|
+
*
|
|
674
|
+
* // Create a form in a project
|
|
675
|
+
* const form = await client.forms.create({
|
|
676
|
+
* name: 'Feedback Form',
|
|
677
|
+
* project_id: 'proj_123'
|
|
678
|
+
* });
|
|
679
|
+
* ```
|
|
680
|
+
*
|
|
681
|
+
* @see Requirements 4.2
|
|
682
|
+
*/
|
|
683
|
+
create(data: CreateFormRequest): Promise<Form>;
|
|
684
|
+
/**
|
|
685
|
+
* Get a single form by ID.
|
|
686
|
+
*
|
|
687
|
+
* @param id - The unique identifier of the form
|
|
688
|
+
* @returns Promise resolving to the form
|
|
689
|
+
* @throws NotFoundError if the form does not exist
|
|
690
|
+
*
|
|
691
|
+
* @example
|
|
692
|
+
* ```typescript
|
|
693
|
+
* const form = await client.forms.get('form_123');
|
|
694
|
+
* console.log(form.name, form.submission_count);
|
|
695
|
+
* ```
|
|
696
|
+
*
|
|
697
|
+
* @see Requirements 4.3
|
|
698
|
+
*/
|
|
699
|
+
get(id: string): Promise<Form>;
|
|
700
|
+
/**
|
|
701
|
+
* Update a form's properties.
|
|
702
|
+
*
|
|
703
|
+
* @param id - The unique identifier of the form to update
|
|
704
|
+
* @param data - The properties to update
|
|
705
|
+
* @param data.name - New display name for the form
|
|
706
|
+
* @param data.project_id - ID of the project to move the form to (or null to remove from project)
|
|
707
|
+
* @param data.is_active - Whether the form should be active
|
|
708
|
+
* @returns Promise resolving to the updated form
|
|
709
|
+
* @throws NotFoundError if the form does not exist
|
|
710
|
+
*
|
|
711
|
+
* @example
|
|
712
|
+
* ```typescript
|
|
713
|
+
* // Update form name
|
|
714
|
+
* const form = await client.forms.update('form_123', { name: 'New Name' });
|
|
715
|
+
*
|
|
716
|
+
* // Deactivate a form
|
|
717
|
+
* const form = await client.forms.update('form_123', { is_active: false });
|
|
718
|
+
*
|
|
719
|
+
* // Move form to a different project
|
|
720
|
+
* const form = await client.forms.update('form_123', { project_id: 'proj_456' });
|
|
721
|
+
* ```
|
|
722
|
+
*
|
|
723
|
+
* @see Requirements 4.4
|
|
724
|
+
*/
|
|
725
|
+
update(id: string, data: UpdateFormRequest): Promise<Form>;
|
|
726
|
+
/**
|
|
727
|
+
* Delete a form by ID.
|
|
728
|
+
*
|
|
729
|
+
* @param id - The unique identifier of the form to delete
|
|
730
|
+
* @returns Promise resolving to a success response
|
|
731
|
+
* @throws NotFoundError if the form does not exist
|
|
732
|
+
*
|
|
733
|
+
* @example
|
|
734
|
+
* ```typescript
|
|
735
|
+
* await client.forms.delete('form_123');
|
|
736
|
+
* ```
|
|
737
|
+
*
|
|
738
|
+
* @see Requirements 4.5
|
|
739
|
+
*/
|
|
740
|
+
delete(id: string): Promise<SuccessResponse>;
|
|
741
|
+
/**
|
|
742
|
+
* Submit data to a form. This is a public endpoint that does not require authentication.
|
|
743
|
+
*
|
|
744
|
+
* @param slug - The URL-friendly slug of the form
|
|
745
|
+
* @param data - The form data to submit as key-value pairs
|
|
746
|
+
* @returns Promise resolving to the submission response
|
|
747
|
+
* @throws NotFoundError if the form does not exist
|
|
748
|
+
* @throws ValidationError if the form is inactive or data is invalid
|
|
749
|
+
*
|
|
750
|
+
* @example
|
|
751
|
+
* ```typescript
|
|
752
|
+
* // Submit to a contact form
|
|
753
|
+
* const result = await client.forms.submit('contact-form', {
|
|
754
|
+
* name: 'John Doe',
|
|
755
|
+
* email: 'john@example.com',
|
|
756
|
+
* message: 'Hello!'
|
|
757
|
+
* });
|
|
758
|
+
*
|
|
759
|
+
* if (result.success) {
|
|
760
|
+
* console.log('Submission ID:', result.submission_id);
|
|
761
|
+
* }
|
|
762
|
+
* ```
|
|
763
|
+
*
|
|
764
|
+
* @see Requirements 4.6
|
|
765
|
+
*/
|
|
766
|
+
submit(slug: string, data: Record<string, unknown>): Promise<SubmissionResponse>;
|
|
767
|
+
/**
|
|
768
|
+
* Get the HTML template for a form.
|
|
769
|
+
*
|
|
770
|
+
* Returns the stored HTML from S3 or a default template if none exists.
|
|
771
|
+
*
|
|
772
|
+
* @param id - The unique identifier of the form
|
|
773
|
+
* @returns Promise resolving to the HTML content
|
|
774
|
+
* @throws NotFoundError if the form does not exist
|
|
775
|
+
*
|
|
776
|
+
* @example
|
|
777
|
+
* ```typescript
|
|
778
|
+
* const { html } = await client.forms.getHtml('form_123');
|
|
779
|
+
* console.log(html);
|
|
780
|
+
* ```
|
|
781
|
+
*/
|
|
782
|
+
getHtml(id: string): Promise<FormHtmlResponse>;
|
|
783
|
+
/**
|
|
784
|
+
* Save HTML template for a form to S3 storage.
|
|
785
|
+
*
|
|
786
|
+
* @param id - The unique identifier of the form
|
|
787
|
+
* @param html - The HTML content to save
|
|
788
|
+
* @returns Promise resolving to the save response with the S3 URL
|
|
789
|
+
* @throws NotFoundError if the form does not exist
|
|
790
|
+
*
|
|
791
|
+
* @example
|
|
792
|
+
* ```typescript
|
|
793
|
+
* const result = await client.forms.saveHtml('form_123', '<html>...</html>');
|
|
794
|
+
* if (result.success) {
|
|
795
|
+
* console.log('Saved to:', result.html_url);
|
|
796
|
+
* }
|
|
797
|
+
* ```
|
|
798
|
+
*/
|
|
799
|
+
saveHtml(id: string, html: string): Promise<SaveFormHtmlResponse>;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* Submissions Resource for the Spike Forms SDK
|
|
804
|
+
*
|
|
805
|
+
* Provides methods for managing form submissions:
|
|
806
|
+
* - list: Get submissions with filtering options
|
|
807
|
+
* - getStats: Get submission statistics for a form
|
|
808
|
+
* - export: Export all submissions as JSON
|
|
809
|
+
* - bulkUpdate: Perform batch operations on submissions
|
|
810
|
+
* - bulkDelete: Delete multiple submissions
|
|
811
|
+
*
|
|
812
|
+
* @module resources/submissions
|
|
813
|
+
*/
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* Resource class for managing form submissions in Spike Forms.
|
|
817
|
+
*
|
|
818
|
+
* @example
|
|
819
|
+
* ```typescript
|
|
820
|
+
* // List submissions for a form
|
|
821
|
+
* const submissions = await client.submissions.list('form_123', { limit: 10 });
|
|
822
|
+
*
|
|
823
|
+
* // Get submission statistics
|
|
824
|
+
* const stats = await client.submissions.getStats('form_123');
|
|
825
|
+
*
|
|
826
|
+
* // Export all submissions
|
|
827
|
+
* const allSubmissions = await client.submissions.export('form_123');
|
|
828
|
+
*
|
|
829
|
+
* // Bulk update submissions
|
|
830
|
+
* await client.submissions.bulkUpdate('form_123', {
|
|
831
|
+
* action: 'markRead',
|
|
832
|
+
* submission_ids: ['sub_1', 'sub_2']
|
|
833
|
+
* });
|
|
834
|
+
*
|
|
835
|
+
* // Bulk delete submissions
|
|
836
|
+
* await client.submissions.bulkDelete('form_123', ['sub_1', 'sub_2']);
|
|
837
|
+
* ```
|
|
838
|
+
*/
|
|
839
|
+
declare class SubmissionsResource {
|
|
840
|
+
private readonly http;
|
|
841
|
+
/**
|
|
842
|
+
* Create a new SubmissionsResource instance
|
|
843
|
+
* @param http - The HTTP client to use for API requests
|
|
844
|
+
*/
|
|
845
|
+
constructor(http: HttpClient);
|
|
846
|
+
/**
|
|
847
|
+
* List submissions for a form with optional filtering and pagination.
|
|
848
|
+
*
|
|
849
|
+
* @param formId - The unique identifier of the form
|
|
850
|
+
* @param params - Optional parameters for filtering and pagination
|
|
851
|
+
* @param params.limit - Maximum number of submissions to return
|
|
852
|
+
* @param params.offset - Number of submissions to skip for pagination
|
|
853
|
+
* @param params.since - Only return submissions created after this ISO 8601 timestamp
|
|
854
|
+
* @param params.order - Sort order for submissions ('asc' or 'desc')
|
|
855
|
+
* @param params.filter - Filter string for searching submissions
|
|
856
|
+
* @param params.is_spam - Filter by spam status
|
|
857
|
+
* @param params.is_read - Filter by read status
|
|
858
|
+
* @returns Promise resolving to an array of submissions
|
|
859
|
+
* @throws NotFoundError if the form does not exist
|
|
860
|
+
*
|
|
861
|
+
* @example
|
|
862
|
+
* ```typescript
|
|
863
|
+
* // Get all submissions for a form
|
|
864
|
+
* const submissions = await client.submissions.list('form_123');
|
|
865
|
+
*
|
|
866
|
+
* // Get submissions with pagination
|
|
867
|
+
* const submissions = await client.submissions.list('form_123', {
|
|
868
|
+
* limit: 10,
|
|
869
|
+
* offset: 20
|
|
870
|
+
* });
|
|
871
|
+
*
|
|
872
|
+
* // Get unread submissions
|
|
873
|
+
* const unread = await client.submissions.list('form_123', {
|
|
874
|
+
* is_read: false
|
|
875
|
+
* });
|
|
876
|
+
*
|
|
877
|
+
* // Get non-spam submissions since a date
|
|
878
|
+
* const recent = await client.submissions.list('form_123', {
|
|
879
|
+
* since: '2024-01-01T00:00:00Z',
|
|
880
|
+
* is_spam: false,
|
|
881
|
+
* order: 'desc'
|
|
882
|
+
* });
|
|
883
|
+
*
|
|
884
|
+
* // Search submissions
|
|
885
|
+
* const filtered = await client.submissions.list('form_123', {
|
|
886
|
+
* filter: 'john@example.com'
|
|
887
|
+
* });
|
|
888
|
+
* ```
|
|
889
|
+
*
|
|
890
|
+
* @see Requirements 5.1
|
|
891
|
+
*/
|
|
892
|
+
list(formId: string, params?: ListSubmissionsParams): Promise<Submission[]>;
|
|
893
|
+
/**
|
|
894
|
+
* Get submission statistics for a form.
|
|
895
|
+
*
|
|
896
|
+
* @param formId - The unique identifier of the form
|
|
897
|
+
* @returns Promise resolving to submission statistics
|
|
898
|
+
* @throws NotFoundError if the form does not exist
|
|
899
|
+
*
|
|
900
|
+
* @example
|
|
901
|
+
* ```typescript
|
|
902
|
+
* const stats = await client.submissions.getStats('form_123');
|
|
903
|
+
* console.log(`Total: ${stats.total}, Unread: ${stats.unread}, Spam: ${stats.spam}`);
|
|
904
|
+
* console.log(`Today: ${stats.today}, This week: ${stats.this_week}`);
|
|
905
|
+
* ```
|
|
906
|
+
*
|
|
907
|
+
* @see Requirements 5.2
|
|
908
|
+
*/
|
|
909
|
+
getStats(formId: string): Promise<SubmissionStats>;
|
|
910
|
+
/**
|
|
911
|
+
* Export all submissions for a form as JSON.
|
|
912
|
+
*
|
|
913
|
+
* @param formId - The unique identifier of the form
|
|
914
|
+
* @returns Promise resolving to an array of all submissions
|
|
915
|
+
* @throws NotFoundError if the form does not exist
|
|
916
|
+
*
|
|
917
|
+
* @example
|
|
918
|
+
* ```typescript
|
|
919
|
+
* // Export all submissions
|
|
920
|
+
* const allSubmissions = await client.submissions.export('form_123');
|
|
921
|
+
*
|
|
922
|
+
* // Process exported data
|
|
923
|
+
* for (const submission of allSubmissions) {
|
|
924
|
+
* console.log(submission.data);
|
|
925
|
+
* }
|
|
926
|
+
* ```
|
|
927
|
+
*
|
|
928
|
+
* @see Requirements 5.3
|
|
929
|
+
*/
|
|
930
|
+
export(formId: string): Promise<Submission[]>;
|
|
931
|
+
/**
|
|
932
|
+
* Perform a bulk update operation on multiple submissions.
|
|
933
|
+
*
|
|
934
|
+
* @param formId - The unique identifier of the form
|
|
935
|
+
* @param data - The bulk update request
|
|
936
|
+
* @param data.action - The action to perform ('markRead', 'markUnread', 'star', 'unstar', 'markSpam', 'notSpam')
|
|
937
|
+
* @param data.submission_ids - Array of submission IDs to update
|
|
938
|
+
* @returns Promise resolving to a success response
|
|
939
|
+
* @throws NotFoundError if the form does not exist
|
|
940
|
+
* @throws ValidationError if the action is invalid or submission IDs are empty
|
|
941
|
+
*
|
|
942
|
+
* @example
|
|
943
|
+
* ```typescript
|
|
944
|
+
* // Mark submissions as read
|
|
945
|
+
* await client.submissions.bulkUpdate('form_123', {
|
|
946
|
+
* action: 'markRead',
|
|
947
|
+
* submission_ids: ['sub_1', 'sub_2', 'sub_3']
|
|
948
|
+
* });
|
|
949
|
+
*
|
|
950
|
+
* // Star submissions
|
|
951
|
+
* await client.submissions.bulkUpdate('form_123', {
|
|
952
|
+
* action: 'star',
|
|
953
|
+
* submission_ids: ['sub_1']
|
|
954
|
+
* });
|
|
955
|
+
*
|
|
956
|
+
* // Mark submissions as spam
|
|
957
|
+
* await client.submissions.bulkUpdate('form_123', {
|
|
958
|
+
* action: 'markSpam',
|
|
959
|
+
* submission_ids: ['sub_4', 'sub_5']
|
|
960
|
+
* });
|
|
961
|
+
*
|
|
962
|
+
* // Mark submissions as not spam
|
|
963
|
+
* await client.submissions.bulkUpdate('form_123', {
|
|
964
|
+
* action: 'notSpam',
|
|
965
|
+
* submission_ids: ['sub_6']
|
|
966
|
+
* });
|
|
967
|
+
* ```
|
|
968
|
+
*
|
|
969
|
+
* @see Requirements 5.4
|
|
970
|
+
*/
|
|
971
|
+
bulkUpdate(formId: string, data: BulkUpdateRequest): Promise<SuccessResponse>;
|
|
972
|
+
/**
|
|
973
|
+
* Delete multiple submissions from a form.
|
|
974
|
+
*
|
|
975
|
+
* @param formId - The unique identifier of the form
|
|
976
|
+
* @param submissionIds - Array of submission IDs to delete
|
|
977
|
+
* @returns Promise resolving to a success response
|
|
978
|
+
* @throws NotFoundError if the form does not exist
|
|
979
|
+
* @throws ValidationError if submission IDs are empty
|
|
980
|
+
*
|
|
981
|
+
* @example
|
|
982
|
+
* ```typescript
|
|
983
|
+
* // Delete multiple submissions
|
|
984
|
+
* await client.submissions.bulkDelete('form_123', ['sub_1', 'sub_2', 'sub_3']);
|
|
985
|
+
* ```
|
|
986
|
+
*
|
|
987
|
+
* @see Requirements 5.5
|
|
988
|
+
*/
|
|
989
|
+
bulkDelete(formId: string, submissionIds: string[]): Promise<SuccessResponse>;
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* Rules Resource for the Spike Forms SDK
|
|
994
|
+
*
|
|
995
|
+
* Provides methods for managing form rules:
|
|
996
|
+
* - list: Get all rules for a form
|
|
997
|
+
* - create: Create a new rule for a form
|
|
998
|
+
* - update: Update a rule by ID
|
|
999
|
+
* - delete: Delete a rule by ID
|
|
1000
|
+
*
|
|
1001
|
+
* @module resources/rules
|
|
1002
|
+
*/
|
|
1003
|
+
|
|
1004
|
+
/**
|
|
1005
|
+
* Resource class for managing form rules in Spike Forms.
|
|
1006
|
+
*
|
|
1007
|
+
* Rules allow you to configure conditional routing and processing for form submissions.
|
|
1008
|
+
* Each rule consists of conditions that must be met and actions to take when they are.
|
|
1009
|
+
*
|
|
1010
|
+
* @example
|
|
1011
|
+
* ```typescript
|
|
1012
|
+
* // List all rules for a form
|
|
1013
|
+
* const rules = await client.rules.list('form_123');
|
|
1014
|
+
*
|
|
1015
|
+
* // Create a new rule
|
|
1016
|
+
* const rule = await client.rules.create('form_123', {
|
|
1017
|
+
* name: 'Email notification',
|
|
1018
|
+
* conditions: [{ field: 'email', operator: 'contains', value: '@company.com' }],
|
|
1019
|
+
* actions: [{ type: 'email', config: { to: 'team@company.com' } }]
|
|
1020
|
+
* });
|
|
1021
|
+
*
|
|
1022
|
+
* // Update a rule
|
|
1023
|
+
* const updated = await client.rules.update('form_123', 'rule_456', {
|
|
1024
|
+
* is_active: false
|
|
1025
|
+
* });
|
|
1026
|
+
*
|
|
1027
|
+
* // Delete a rule
|
|
1028
|
+
* await client.rules.delete('form_123', 'rule_456');
|
|
1029
|
+
* ```
|
|
1030
|
+
*/
|
|
1031
|
+
declare class RulesResource {
|
|
1032
|
+
private readonly http;
|
|
1033
|
+
/**
|
|
1034
|
+
* Create a new RulesResource instance
|
|
1035
|
+
* @param http - The HTTP client to use for API requests
|
|
1036
|
+
*/
|
|
1037
|
+
constructor(http: HttpClient);
|
|
1038
|
+
/**
|
|
1039
|
+
* List all rules for a form.
|
|
1040
|
+
*
|
|
1041
|
+
* @param formId - The unique identifier of the form
|
|
1042
|
+
* @returns Promise resolving to an array of rules
|
|
1043
|
+
* @throws NotFoundError if the form does not exist
|
|
1044
|
+
*
|
|
1045
|
+
* @example
|
|
1046
|
+
* ```typescript
|
|
1047
|
+
* // Get all rules for a form
|
|
1048
|
+
* const rules = await client.rules.list('form_123');
|
|
1049
|
+
*
|
|
1050
|
+
* // Filter active rules
|
|
1051
|
+
* const activeRules = rules.filter(rule => rule.is_active);
|
|
1052
|
+
*
|
|
1053
|
+
* // Check rule conditions
|
|
1054
|
+
* for (const rule of rules) {
|
|
1055
|
+
* console.log(`Rule: ${rule.name}, Conditions: ${rule.conditions.length}`);
|
|
1056
|
+
* }
|
|
1057
|
+
* ```
|
|
1058
|
+
*
|
|
1059
|
+
* @see Requirements 6.1
|
|
1060
|
+
*/
|
|
1061
|
+
list(formId: string): Promise<Rule[]>;
|
|
1062
|
+
/**
|
|
1063
|
+
* Create a new rule for a form.
|
|
1064
|
+
*
|
|
1065
|
+
* @param formId - The unique identifier of the form
|
|
1066
|
+
* @param data - The rule data to create
|
|
1067
|
+
* @param data.name - Display name for the rule (required)
|
|
1068
|
+
* @param data.conditions - Array of conditions that must be met (required)
|
|
1069
|
+
* @param data.actions - Array of actions to take when conditions are met (required)
|
|
1070
|
+
* @param data.is_active - Whether the rule should be active (defaults to true)
|
|
1071
|
+
* @returns Promise resolving to the created rule
|
|
1072
|
+
* @throws NotFoundError if the form does not exist
|
|
1073
|
+
* @throws ValidationError if the rule data is invalid
|
|
1074
|
+
*
|
|
1075
|
+
* @example
|
|
1076
|
+
* ```typescript
|
|
1077
|
+
* // Create a simple email notification rule
|
|
1078
|
+
* const rule = await client.rules.create('form_123', {
|
|
1079
|
+
* name: 'Notify on VIP submission',
|
|
1080
|
+
* conditions: [
|
|
1081
|
+
* { field: 'email', operator: 'ends_with', value: '@vip.com' }
|
|
1082
|
+
* ],
|
|
1083
|
+
* actions: [
|
|
1084
|
+
* { type: 'email', config: { to: 'sales@company.com', subject: 'VIP Lead!' } }
|
|
1085
|
+
* ]
|
|
1086
|
+
* });
|
|
1087
|
+
*
|
|
1088
|
+
* // Create a webhook rule with multiple conditions
|
|
1089
|
+
* const webhookRule = await client.rules.create('form_123', {
|
|
1090
|
+
* name: 'Send to CRM',
|
|
1091
|
+
* conditions: [
|
|
1092
|
+
* { field: 'type', operator: 'equals', value: 'enterprise' },
|
|
1093
|
+
* { field: 'budget', operator: 'contains', value: '10000' }
|
|
1094
|
+
* ],
|
|
1095
|
+
* actions: [
|
|
1096
|
+
* { type: 'webhook', config: { url: 'https://crm.example.com/leads' } }
|
|
1097
|
+
* ],
|
|
1098
|
+
* is_active: true
|
|
1099
|
+
* });
|
|
1100
|
+
*
|
|
1101
|
+
* // Create an inactive rule (for testing)
|
|
1102
|
+
* const testRule = await client.rules.create('form_123', {
|
|
1103
|
+
* name: 'Test Rule',
|
|
1104
|
+
* conditions: [{ field: 'test', operator: 'equals', value: 'true' }],
|
|
1105
|
+
* actions: [{ type: 'slack', config: { channel: '#test' } }],
|
|
1106
|
+
* is_active: false
|
|
1107
|
+
* });
|
|
1108
|
+
* ```
|
|
1109
|
+
*
|
|
1110
|
+
* @see Requirements 6.2
|
|
1111
|
+
*/
|
|
1112
|
+
create(formId: string, data: CreateRuleRequest): Promise<Rule>;
|
|
1113
|
+
/**
|
|
1114
|
+
* Update a rule's properties.
|
|
1115
|
+
*
|
|
1116
|
+
* @param formId - The unique identifier of the form
|
|
1117
|
+
* @param ruleId - The unique identifier of the rule to update
|
|
1118
|
+
* @param data - The properties to update
|
|
1119
|
+
* @param data.name - New display name for the rule
|
|
1120
|
+
* @param data.conditions - New conditions for the rule
|
|
1121
|
+
* @param data.actions - New actions for the rule
|
|
1122
|
+
* @param data.is_active - Whether the rule should be active
|
|
1123
|
+
* @returns Promise resolving to the updated rule
|
|
1124
|
+
* @throws NotFoundError if the form or rule does not exist
|
|
1125
|
+
* @throws ValidationError if the update data is invalid
|
|
1126
|
+
*
|
|
1127
|
+
* @example
|
|
1128
|
+
* ```typescript
|
|
1129
|
+
* // Update rule name
|
|
1130
|
+
* const rule = await client.rules.update('form_123', 'rule_456', {
|
|
1131
|
+
* name: 'Updated Rule Name'
|
|
1132
|
+
* });
|
|
1133
|
+
*
|
|
1134
|
+
* // Deactivate a rule
|
|
1135
|
+
* const rule = await client.rules.update('form_123', 'rule_456', {
|
|
1136
|
+
* is_active: false
|
|
1137
|
+
* });
|
|
1138
|
+
*
|
|
1139
|
+
* // Update conditions
|
|
1140
|
+
* const rule = await client.rules.update('form_123', 'rule_456', {
|
|
1141
|
+
* conditions: [
|
|
1142
|
+
* { field: 'email', operator: 'contains', value: '@newdomain.com' }
|
|
1143
|
+
* ]
|
|
1144
|
+
* });
|
|
1145
|
+
*
|
|
1146
|
+
* // Update actions
|
|
1147
|
+
* const rule = await client.rules.update('form_123', 'rule_456', {
|
|
1148
|
+
* actions: [
|
|
1149
|
+
* { type: 'discord', config: { webhook_url: 'https://discord.com/api/webhooks/...' } }
|
|
1150
|
+
* ]
|
|
1151
|
+
* });
|
|
1152
|
+
*
|
|
1153
|
+
* // Update multiple properties at once
|
|
1154
|
+
* const rule = await client.rules.update('form_123', 'rule_456', {
|
|
1155
|
+
* name: 'New Name',
|
|
1156
|
+
* is_active: true,
|
|
1157
|
+
* conditions: [{ field: 'status', operator: 'equals', value: 'urgent' }],
|
|
1158
|
+
* actions: [{ type: 'email', config: { to: 'urgent@company.com' } }]
|
|
1159
|
+
* });
|
|
1160
|
+
* ```
|
|
1161
|
+
*
|
|
1162
|
+
* @see Requirements 6.3
|
|
1163
|
+
*/
|
|
1164
|
+
update(formId: string, ruleId: string, data: UpdateRuleRequest): Promise<Rule>;
|
|
1165
|
+
/**
|
|
1166
|
+
* Delete a rule by ID.
|
|
1167
|
+
*
|
|
1168
|
+
* @param formId - The unique identifier of the form
|
|
1169
|
+
* @param ruleId - The unique identifier of the rule to delete
|
|
1170
|
+
* @returns Promise resolving to a success response
|
|
1171
|
+
* @throws NotFoundError if the form or rule does not exist
|
|
1172
|
+
*
|
|
1173
|
+
* @example
|
|
1174
|
+
* ```typescript
|
|
1175
|
+
* // Delete a rule
|
|
1176
|
+
* await client.rules.delete('form_123', 'rule_456');
|
|
1177
|
+
*
|
|
1178
|
+
* // Delete multiple rules
|
|
1179
|
+
* const ruleIds = ['rule_1', 'rule_2', 'rule_3'];
|
|
1180
|
+
* for (const ruleId of ruleIds) {
|
|
1181
|
+
* await client.rules.delete('form_123', ruleId);
|
|
1182
|
+
* }
|
|
1183
|
+
* ```
|
|
1184
|
+
*
|
|
1185
|
+
* @see Requirements 6.4
|
|
1186
|
+
*/
|
|
1187
|
+
delete(formId: string, ruleId: string): Promise<SuccessResponse>;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
/**
|
|
1191
|
+
* Projects Resource for the Spike Forms SDK
|
|
1192
|
+
*
|
|
1193
|
+
* Provides methods for managing projects:
|
|
1194
|
+
* - list: Get all projects
|
|
1195
|
+
* - create: Create a new project
|
|
1196
|
+
* - get: Retrieve a single project by ID
|
|
1197
|
+
* - update: Update project properties
|
|
1198
|
+
* - delete: Delete a project by ID
|
|
1199
|
+
*
|
|
1200
|
+
* @module resources/projects
|
|
1201
|
+
*/
|
|
1202
|
+
|
|
1203
|
+
/**
|
|
1204
|
+
* Resource class for managing projects in Spike Forms.
|
|
1205
|
+
*
|
|
1206
|
+
* Projects are used to organize forms into logical groups.
|
|
1207
|
+
*
|
|
1208
|
+
* @example
|
|
1209
|
+
* ```typescript
|
|
1210
|
+
* // List all projects
|
|
1211
|
+
* const projects = await client.projects.list();
|
|
1212
|
+
*
|
|
1213
|
+
* // Create a new project
|
|
1214
|
+
* const project = await client.projects.create({ name: 'Marketing Forms' });
|
|
1215
|
+
*
|
|
1216
|
+
* // Get a specific project
|
|
1217
|
+
* const project = await client.projects.get('proj_123');
|
|
1218
|
+
*
|
|
1219
|
+
* // Update a project
|
|
1220
|
+
* const updated = await client.projects.update('proj_123', { name: 'New Name' });
|
|
1221
|
+
*
|
|
1222
|
+
* // Delete a project
|
|
1223
|
+
* await client.projects.delete('proj_123');
|
|
1224
|
+
* ```
|
|
1225
|
+
*/
|
|
1226
|
+
declare class ProjectsResource {
|
|
1227
|
+
private readonly http;
|
|
1228
|
+
/**
|
|
1229
|
+
* Create a new ProjectsResource instance
|
|
1230
|
+
* @param http - The HTTP client to use for API requests
|
|
1231
|
+
*/
|
|
1232
|
+
constructor(http: HttpClient);
|
|
1233
|
+
/**
|
|
1234
|
+
* List all projects.
|
|
1235
|
+
*
|
|
1236
|
+
* @returns Promise resolving to an array of projects
|
|
1237
|
+
*
|
|
1238
|
+
* @example
|
|
1239
|
+
* ```typescript
|
|
1240
|
+
* const projects = await client.projects.list();
|
|
1241
|
+
* console.log(`Found ${projects.length} projects`);
|
|
1242
|
+
* ```
|
|
1243
|
+
*
|
|
1244
|
+
* @see Requirements 7.1
|
|
1245
|
+
*/
|
|
1246
|
+
list(): Promise<Project[]>;
|
|
1247
|
+
/**
|
|
1248
|
+
* Create a new project.
|
|
1249
|
+
*
|
|
1250
|
+
* @param data - The project data to create
|
|
1251
|
+
* @param data.name - Display name for the project (required)
|
|
1252
|
+
* @returns Promise resolving to the created project
|
|
1253
|
+
*
|
|
1254
|
+
* @example
|
|
1255
|
+
* ```typescript
|
|
1256
|
+
* const project = await client.projects.create({ name: 'Marketing Forms' });
|
|
1257
|
+
* console.log('Created project:', project.id);
|
|
1258
|
+
* ```
|
|
1259
|
+
*
|
|
1260
|
+
* @see Requirements 7.2
|
|
1261
|
+
*/
|
|
1262
|
+
create(data: CreateProjectRequest): Promise<Project>;
|
|
1263
|
+
/**
|
|
1264
|
+
* Get a single project by ID.
|
|
1265
|
+
*
|
|
1266
|
+
* @param id - The unique identifier of the project
|
|
1267
|
+
* @returns Promise resolving to the project
|
|
1268
|
+
* @throws NotFoundError if the project does not exist
|
|
1269
|
+
*
|
|
1270
|
+
* @example
|
|
1271
|
+
* ```typescript
|
|
1272
|
+
* const project = await client.projects.get('proj_123');
|
|
1273
|
+
* console.log(project.name, project.form_count);
|
|
1274
|
+
* ```
|
|
1275
|
+
*
|
|
1276
|
+
* @see Requirements 7.3
|
|
1277
|
+
*/
|
|
1278
|
+
get(id: string): Promise<Project>;
|
|
1279
|
+
/**
|
|
1280
|
+
* Update a project's properties.
|
|
1281
|
+
*
|
|
1282
|
+
* @param id - The unique identifier of the project to update
|
|
1283
|
+
* @param data - The properties to update
|
|
1284
|
+
* @param data.name - New display name for the project
|
|
1285
|
+
* @returns Promise resolving to the updated project
|
|
1286
|
+
* @throws NotFoundError if the project does not exist
|
|
1287
|
+
*
|
|
1288
|
+
* @example
|
|
1289
|
+
* ```typescript
|
|
1290
|
+
* const project = await client.projects.update('proj_123', { name: 'New Name' });
|
|
1291
|
+
* console.log('Updated project:', project.name);
|
|
1292
|
+
* ```
|
|
1293
|
+
*
|
|
1294
|
+
* @see Requirements 7.4
|
|
1295
|
+
*/
|
|
1296
|
+
update(id: string, data: UpdateProjectRequest): Promise<Project>;
|
|
1297
|
+
/**
|
|
1298
|
+
* Delete a project by ID.
|
|
1299
|
+
*
|
|
1300
|
+
* @param id - The unique identifier of the project to delete
|
|
1301
|
+
* @returns Promise resolving to a success response
|
|
1302
|
+
* @throws NotFoundError if the project does not exist
|
|
1303
|
+
*
|
|
1304
|
+
* @example
|
|
1305
|
+
* ```typescript
|
|
1306
|
+
* await client.projects.delete('proj_123');
|
|
1307
|
+
* ```
|
|
1308
|
+
*
|
|
1309
|
+
* @see Requirements 7.5
|
|
1310
|
+
*/
|
|
1311
|
+
delete(id: string): Promise<SuccessResponse>;
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
/**
|
|
1315
|
+
* Teams Resource for the Spike Forms SDK
|
|
1316
|
+
*
|
|
1317
|
+
* Provides methods for managing teams and team collaboration:
|
|
1318
|
+
* - list: Get all teams
|
|
1319
|
+
* - create: Create a new team
|
|
1320
|
+
* - get: Retrieve a single team by ID
|
|
1321
|
+
* - update: Update team properties
|
|
1322
|
+
* - delete: Delete a team by ID
|
|
1323
|
+
* - listMembers: Get all members of a team
|
|
1324
|
+
* - addMember: Add a user to a team
|
|
1325
|
+
* - updateMember: Update a member's role
|
|
1326
|
+
* - removeMember: Remove a member from a team
|
|
1327
|
+
* - listInvitations: Get pending invitations for a team
|
|
1328
|
+
* - invite: Create a new invitation
|
|
1329
|
+
* - cancelInvitation: Cancel a pending invitation
|
|
1330
|
+
* - acceptInvitation: Accept an invitation
|
|
1331
|
+
*
|
|
1332
|
+
* @module resources/teams
|
|
1333
|
+
*/
|
|
1334
|
+
|
|
1335
|
+
/**
|
|
1336
|
+
* Resource class for managing teams in Spike Forms.
|
|
1337
|
+
*
|
|
1338
|
+
* Teams enable collaborative form management with role-based access control.
|
|
1339
|
+
*
|
|
1340
|
+
* @example
|
|
1341
|
+
* ```typescript
|
|
1342
|
+
* // List all teams
|
|
1343
|
+
* const teams = await client.teams.list();
|
|
1344
|
+
*
|
|
1345
|
+
* // Create a new team
|
|
1346
|
+
* const team = await client.teams.create({ name: 'Marketing Team' });
|
|
1347
|
+
*
|
|
1348
|
+
* // Get a specific team
|
|
1349
|
+
* const team = await client.teams.get('team_123');
|
|
1350
|
+
*
|
|
1351
|
+
* // Update a team
|
|
1352
|
+
* const updated = await client.teams.update('team_123', { name: 'New Name' });
|
|
1353
|
+
*
|
|
1354
|
+
* // Delete a team
|
|
1355
|
+
* await client.teams.delete('team_123');
|
|
1356
|
+
*
|
|
1357
|
+
* // Manage team members
|
|
1358
|
+
* const members = await client.teams.listMembers('team_123');
|
|
1359
|
+
* await client.teams.invite('team_123', { email: 'user@example.com', role: 'member' });
|
|
1360
|
+
* ```
|
|
1361
|
+
*/
|
|
1362
|
+
declare class TeamsResource {
|
|
1363
|
+
private readonly http;
|
|
1364
|
+
/**
|
|
1365
|
+
* Create a new TeamsResource instance
|
|
1366
|
+
* @param http - The HTTP client to use for API requests
|
|
1367
|
+
*/
|
|
1368
|
+
constructor(http: HttpClient);
|
|
1369
|
+
/**
|
|
1370
|
+
* List all teams.
|
|
1371
|
+
*
|
|
1372
|
+
* @returns Promise resolving to an array of teams
|
|
1373
|
+
*
|
|
1374
|
+
* @example
|
|
1375
|
+
* ```typescript
|
|
1376
|
+
* const teams = await client.teams.list();
|
|
1377
|
+
* console.log(`Found ${teams.length} teams`);
|
|
1378
|
+
* ```
|
|
1379
|
+
*
|
|
1380
|
+
* @see Requirements 8.1
|
|
1381
|
+
*/
|
|
1382
|
+
list(): Promise<Team[]>;
|
|
1383
|
+
/**
|
|
1384
|
+
* Create a new team.
|
|
1385
|
+
*
|
|
1386
|
+
* @param data - The team data to create
|
|
1387
|
+
* @param data.name - Display name for the team (required)
|
|
1388
|
+
* @returns Promise resolving to the created team
|
|
1389
|
+
*
|
|
1390
|
+
* @example
|
|
1391
|
+
* ```typescript
|
|
1392
|
+
* const team = await client.teams.create({ name: 'Marketing Team' });
|
|
1393
|
+
* console.log('Created team:', team.id);
|
|
1394
|
+
* ```
|
|
1395
|
+
*
|
|
1396
|
+
* @see Requirements 8.2
|
|
1397
|
+
*/
|
|
1398
|
+
create(data: CreateTeamRequest): Promise<Team>;
|
|
1399
|
+
/**
|
|
1400
|
+
* Get a single team by ID.
|
|
1401
|
+
*
|
|
1402
|
+
* @param id - The unique identifier of the team
|
|
1403
|
+
* @returns Promise resolving to the team
|
|
1404
|
+
* @throws NotFoundError if the team does not exist
|
|
1405
|
+
*
|
|
1406
|
+
* @example
|
|
1407
|
+
* ```typescript
|
|
1408
|
+
* const team = await client.teams.get('team_123');
|
|
1409
|
+
* console.log(team.name, team.member_count);
|
|
1410
|
+
* ```
|
|
1411
|
+
*
|
|
1412
|
+
* @see Requirements 8.3
|
|
1413
|
+
*/
|
|
1414
|
+
get(id: string): Promise<Team>;
|
|
1415
|
+
/**
|
|
1416
|
+
* Update a team's properties.
|
|
1417
|
+
*
|
|
1418
|
+
* @param id - The unique identifier of the team to update
|
|
1419
|
+
* @param data - The properties to update
|
|
1420
|
+
* @param data.name - New display name for the team
|
|
1421
|
+
* @returns Promise resolving to the updated team
|
|
1422
|
+
* @throws NotFoundError if the team does not exist
|
|
1423
|
+
*
|
|
1424
|
+
* @example
|
|
1425
|
+
* ```typescript
|
|
1426
|
+
* const team = await client.teams.update('team_123', { name: 'New Name' });
|
|
1427
|
+
* console.log('Updated team:', team.name);
|
|
1428
|
+
* ```
|
|
1429
|
+
*
|
|
1430
|
+
* @see Requirements 8.4
|
|
1431
|
+
*/
|
|
1432
|
+
update(id: string, data: UpdateTeamRequest): Promise<Team>;
|
|
1433
|
+
/**
|
|
1434
|
+
* Delete a team by ID.
|
|
1435
|
+
*
|
|
1436
|
+
* @param id - The unique identifier of the team to delete
|
|
1437
|
+
* @returns Promise resolving to a success response
|
|
1438
|
+
* @throws NotFoundError if the team does not exist
|
|
1439
|
+
*
|
|
1440
|
+
* @example
|
|
1441
|
+
* ```typescript
|
|
1442
|
+
* await client.teams.delete('team_123');
|
|
1443
|
+
* ```
|
|
1444
|
+
*
|
|
1445
|
+
* @see Requirements 8.5
|
|
1446
|
+
*/
|
|
1447
|
+
delete(id: string): Promise<SuccessResponse>;
|
|
1448
|
+
/**
|
|
1449
|
+
* List all members of a team.
|
|
1450
|
+
*
|
|
1451
|
+
* @param teamId - The unique identifier of the team
|
|
1452
|
+
* @returns Promise resolving to an array of team members
|
|
1453
|
+
* @throws NotFoundError if the team does not exist
|
|
1454
|
+
*
|
|
1455
|
+
* @example
|
|
1456
|
+
* ```typescript
|
|
1457
|
+
* const members = await client.teams.listMembers('team_123');
|
|
1458
|
+
* members.forEach(member => {
|
|
1459
|
+
* console.log(`${member.user.name} (${member.role})`);
|
|
1460
|
+
* });
|
|
1461
|
+
* ```
|
|
1462
|
+
*
|
|
1463
|
+
* @see Requirements 8.6
|
|
1464
|
+
*/
|
|
1465
|
+
listMembers(teamId: string): Promise<TeamMember[]>;
|
|
1466
|
+
/**
|
|
1467
|
+
* Add a user to a team.
|
|
1468
|
+
*
|
|
1469
|
+
* @param teamId - The unique identifier of the team
|
|
1470
|
+
* @param data - The member data
|
|
1471
|
+
* @param data.email - Email address of the user to add
|
|
1472
|
+
* @param data.role - Role to assign ('admin' or 'member')
|
|
1473
|
+
* @returns Promise resolving to the created team member
|
|
1474
|
+
* @throws NotFoundError if the team does not exist
|
|
1475
|
+
* @throws ValidationError if the user is already a member
|
|
1476
|
+
*
|
|
1477
|
+
* @example
|
|
1478
|
+
* ```typescript
|
|
1479
|
+
* const member = await client.teams.addMember('team_123', {
|
|
1480
|
+
* email: 'user@example.com',
|
|
1481
|
+
* role: 'member'
|
|
1482
|
+
* });
|
|
1483
|
+
* console.log('Added member:', member.user.name);
|
|
1484
|
+
* ```
|
|
1485
|
+
*
|
|
1486
|
+
* @see Requirements 8.7
|
|
1487
|
+
*/
|
|
1488
|
+
addMember(teamId: string, data: InviteMemberRequest): Promise<TeamMember>;
|
|
1489
|
+
/**
|
|
1490
|
+
* Update a team member's role.
|
|
1491
|
+
*
|
|
1492
|
+
* @param teamId - The unique identifier of the team
|
|
1493
|
+
* @param memberId - The unique identifier of the team member
|
|
1494
|
+
* @param data - The properties to update
|
|
1495
|
+
* @param data.role - New role for the member ('admin' or 'member')
|
|
1496
|
+
* @returns Promise resolving to the updated team member
|
|
1497
|
+
* @throws NotFoundError if the team or member does not exist
|
|
1498
|
+
*
|
|
1499
|
+
* @example
|
|
1500
|
+
* ```typescript
|
|
1501
|
+
* const member = await client.teams.updateMember('team_123', 'member_456', {
|
|
1502
|
+
* role: 'admin'
|
|
1503
|
+
* });
|
|
1504
|
+
* console.log('Updated role to:', member.role);
|
|
1505
|
+
* ```
|
|
1506
|
+
*
|
|
1507
|
+
* @see Requirements 8.8
|
|
1508
|
+
*/
|
|
1509
|
+
updateMember(teamId: string, memberId: string, data: UpdateMemberRequest): Promise<TeamMember>;
|
|
1510
|
+
/**
|
|
1511
|
+
* Remove a member from a team.
|
|
1512
|
+
*
|
|
1513
|
+
* @param teamId - The unique identifier of the team
|
|
1514
|
+
* @param memberId - The unique identifier of the team member to remove
|
|
1515
|
+
* @returns Promise resolving to a success response
|
|
1516
|
+
* @throws NotFoundError if the team or member does not exist
|
|
1517
|
+
*
|
|
1518
|
+
* @example
|
|
1519
|
+
* ```typescript
|
|
1520
|
+
* await client.teams.removeMember('team_123', 'member_456');
|
|
1521
|
+
* ```
|
|
1522
|
+
*
|
|
1523
|
+
* @see Requirements 8.9
|
|
1524
|
+
*/
|
|
1525
|
+
removeMember(teamId: string, memberId: string): Promise<SuccessResponse>;
|
|
1526
|
+
/**
|
|
1527
|
+
* List all pending invitations for a team.
|
|
1528
|
+
*
|
|
1529
|
+
* @param teamId - The unique identifier of the team
|
|
1530
|
+
* @returns Promise resolving to an array of pending invitations
|
|
1531
|
+
* @throws NotFoundError if the team does not exist
|
|
1532
|
+
*
|
|
1533
|
+
* @example
|
|
1534
|
+
* ```typescript
|
|
1535
|
+
* const invitations = await client.teams.listInvitations('team_123');
|
|
1536
|
+
* invitations.forEach(inv => {
|
|
1537
|
+
* console.log(`${inv.email} invited as ${inv.role}`);
|
|
1538
|
+
* });
|
|
1539
|
+
* ```
|
|
1540
|
+
*
|
|
1541
|
+
* @see Requirements 8.10
|
|
1542
|
+
*/
|
|
1543
|
+
listInvitations(teamId: string): Promise<TeamInvitation[]>;
|
|
1544
|
+
/**
|
|
1545
|
+
* Create a new invitation to join a team.
|
|
1546
|
+
*
|
|
1547
|
+
* @param teamId - The unique identifier of the team
|
|
1548
|
+
* @param data - The invitation data
|
|
1549
|
+
* @param data.email - Email address of the person to invite
|
|
1550
|
+
* @param data.role - Role to assign upon acceptance ('admin' or 'member')
|
|
1551
|
+
* @returns Promise resolving to the created invitation
|
|
1552
|
+
* @throws NotFoundError if the team does not exist
|
|
1553
|
+
* @throws ValidationError if an invitation already exists for this email
|
|
1554
|
+
*
|
|
1555
|
+
* @example
|
|
1556
|
+
* ```typescript
|
|
1557
|
+
* const invitation = await client.teams.invite('team_123', {
|
|
1558
|
+
* email: 'newuser@example.com',
|
|
1559
|
+
* role: 'member'
|
|
1560
|
+
* });
|
|
1561
|
+
* console.log('Invitation token:', invitation.token);
|
|
1562
|
+
* ```
|
|
1563
|
+
*
|
|
1564
|
+
* @see Requirements 8.11
|
|
1565
|
+
*/
|
|
1566
|
+
invite(teamId: string, data: InviteMemberRequest): Promise<TeamInvitation>;
|
|
1567
|
+
/**
|
|
1568
|
+
* Cancel a pending invitation.
|
|
1569
|
+
*
|
|
1570
|
+
* @param teamId - The unique identifier of the team
|
|
1571
|
+
* @param invitationId - The unique identifier of the invitation to cancel
|
|
1572
|
+
* @returns Promise resolving to a success response
|
|
1573
|
+
* @throws NotFoundError if the team or invitation does not exist
|
|
1574
|
+
*
|
|
1575
|
+
* @example
|
|
1576
|
+
* ```typescript
|
|
1577
|
+
* await client.teams.cancelInvitation('team_123', 'inv_456');
|
|
1578
|
+
* ```
|
|
1579
|
+
*
|
|
1580
|
+
* @see Requirements 8.12
|
|
1581
|
+
*/
|
|
1582
|
+
cancelInvitation(teamId: string, invitationId: string): Promise<SuccessResponse>;
|
|
1583
|
+
/**
|
|
1584
|
+
* Accept a team invitation using the invitation token.
|
|
1585
|
+
*
|
|
1586
|
+
* @param token - The unique invitation token
|
|
1587
|
+
* @returns Promise resolving to a success response
|
|
1588
|
+
* @throws NotFoundError if the invitation does not exist or has expired
|
|
1589
|
+
*
|
|
1590
|
+
* @example
|
|
1591
|
+
* ```typescript
|
|
1592
|
+
* await client.teams.acceptInvitation('inv_token_abc123');
|
|
1593
|
+
* ```
|
|
1594
|
+
*
|
|
1595
|
+
* @see Requirements 8.13
|
|
1596
|
+
*/
|
|
1597
|
+
acceptInvitation(token: string): Promise<SuccessResponse>;
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
/**
|
|
1601
|
+
* User Resource for the Spike Forms SDK
|
|
1602
|
+
*
|
|
1603
|
+
* Provides methods for managing user profile and security settings:
|
|
1604
|
+
* - get: Get the current user profile
|
|
1605
|
+
* - update: Update user profile properties
|
|
1606
|
+
* - delete: Delete the user account
|
|
1607
|
+
* - setup2FA: Initiate 2FA setup and get secret
|
|
1608
|
+
* - enable2FA: Enable 2FA with a verification code
|
|
1609
|
+
* - disable2FA: Disable 2FA with a verification code
|
|
1610
|
+
* - verify2FA: Verify a 2FA code
|
|
1611
|
+
* - listApiKeys: Get all user API keys
|
|
1612
|
+
* - createApiKey: Create a new API key
|
|
1613
|
+
* - deleteApiKey: Delete an API key
|
|
1614
|
+
*
|
|
1615
|
+
* @module resources/user
|
|
1616
|
+
*/
|
|
1617
|
+
|
|
1618
|
+
/**
|
|
1619
|
+
* Resource class for managing user profile and security settings in Spike Forms.
|
|
1620
|
+
*
|
|
1621
|
+
* Provides access to user profile management, two-factor authentication,
|
|
1622
|
+
* and API key management.
|
|
1623
|
+
*
|
|
1624
|
+
* @example
|
|
1625
|
+
* ```typescript
|
|
1626
|
+
* // Get current user profile
|
|
1627
|
+
* const user = await client.user.get();
|
|
1628
|
+
*
|
|
1629
|
+
* // Update user profile
|
|
1630
|
+
* const updated = await client.user.update({ name: 'New Name' });
|
|
1631
|
+
*
|
|
1632
|
+
* // Set up 2FA
|
|
1633
|
+
* const setup = await client.user.setup2FA();
|
|
1634
|
+
* console.log('Scan QR code:', setup.qr_code);
|
|
1635
|
+
*
|
|
1636
|
+
* // Enable 2FA with verification code
|
|
1637
|
+
* await client.user.enable2FA('123456');
|
|
1638
|
+
*
|
|
1639
|
+
* // Manage API keys
|
|
1640
|
+
* const keys = await client.user.listApiKeys();
|
|
1641
|
+
* const newKey = await client.user.createApiKey({ name: 'My App' });
|
|
1642
|
+
* ```
|
|
1643
|
+
*/
|
|
1644
|
+
declare class UserResource {
|
|
1645
|
+
private readonly http;
|
|
1646
|
+
/**
|
|
1647
|
+
* Create a new UserResource instance
|
|
1648
|
+
* @param http - The HTTP client to use for API requests
|
|
1649
|
+
*/
|
|
1650
|
+
constructor(http: HttpClient);
|
|
1651
|
+
/**
|
|
1652
|
+
* Get the current user profile.
|
|
1653
|
+
*
|
|
1654
|
+
* @returns Promise resolving to the current user
|
|
1655
|
+
*
|
|
1656
|
+
* @example
|
|
1657
|
+
* ```typescript
|
|
1658
|
+
* const user = await client.user.get();
|
|
1659
|
+
* console.log(`Hello, ${user.name}!`);
|
|
1660
|
+
* console.log(`2FA enabled: ${user.two_factor_enabled}`);
|
|
1661
|
+
* ```
|
|
1662
|
+
*
|
|
1663
|
+
* @see Requirements 9.1
|
|
1664
|
+
*/
|
|
1665
|
+
get(): Promise<User>;
|
|
1666
|
+
/**
|
|
1667
|
+
* Update the current user's profile properties.
|
|
1668
|
+
*
|
|
1669
|
+
* @param data - The properties to update
|
|
1670
|
+
* @param data.name - New display name for the user
|
|
1671
|
+
* @param data.email - New email address for the user
|
|
1672
|
+
* @returns Promise resolving to the updated user
|
|
1673
|
+
*
|
|
1674
|
+
* @example
|
|
1675
|
+
* ```typescript
|
|
1676
|
+
* const user = await client.user.update({ name: 'New Name' });
|
|
1677
|
+
* console.log('Updated name:', user.name);
|
|
1678
|
+
* ```
|
|
1679
|
+
*
|
|
1680
|
+
* @see Requirements 9.2
|
|
1681
|
+
*/
|
|
1682
|
+
update(data: UpdateUserRequest): Promise<User>;
|
|
1683
|
+
/**
|
|
1684
|
+
* Delete the current user's account.
|
|
1685
|
+
*
|
|
1686
|
+
* This action is irreversible and will delete all associated data.
|
|
1687
|
+
*
|
|
1688
|
+
* @returns Promise resolving to a success response
|
|
1689
|
+
*
|
|
1690
|
+
* @example
|
|
1691
|
+
* ```typescript
|
|
1692
|
+
* await client.user.delete();
|
|
1693
|
+
* console.log('Account deleted');
|
|
1694
|
+
* ```
|
|
1695
|
+
*
|
|
1696
|
+
* @see Requirements 9.3
|
|
1697
|
+
*/
|
|
1698
|
+
delete(): Promise<SuccessResponse>;
|
|
1699
|
+
/**
|
|
1700
|
+
* Initiate two-factor authentication setup.
|
|
1701
|
+
*
|
|
1702
|
+
* Returns a secret and QR code for configuring an authenticator app.
|
|
1703
|
+
*
|
|
1704
|
+
* @returns Promise resolving to the 2FA setup response with secret and QR code
|
|
1705
|
+
*
|
|
1706
|
+
* @example
|
|
1707
|
+
* ```typescript
|
|
1708
|
+
* const setup = await client.user.setup2FA();
|
|
1709
|
+
* console.log('Secret:', setup.secret);
|
|
1710
|
+
* console.log('QR Code:', setup.qr_code);
|
|
1711
|
+
* // Display QR code to user for scanning with authenticator app
|
|
1712
|
+
* ```
|
|
1713
|
+
*
|
|
1714
|
+
* @see Requirements 9.4
|
|
1715
|
+
*/
|
|
1716
|
+
setup2FA(): Promise<Setup2FAResponse>;
|
|
1717
|
+
/**
|
|
1718
|
+
* Enable two-factor authentication with a verification code.
|
|
1719
|
+
*
|
|
1720
|
+
* Call this after setup2FA to confirm the user has configured their
|
|
1721
|
+
* authenticator app correctly.
|
|
1722
|
+
*
|
|
1723
|
+
* @param code - The 6-digit verification code from the authenticator app
|
|
1724
|
+
* @returns Promise resolving to a success response
|
|
1725
|
+
* @throws ValidationError if the code is invalid
|
|
1726
|
+
*
|
|
1727
|
+
* @example
|
|
1728
|
+
* ```typescript
|
|
1729
|
+
* await client.user.enable2FA('123456');
|
|
1730
|
+
* console.log('2FA enabled successfully');
|
|
1731
|
+
* ```
|
|
1732
|
+
*
|
|
1733
|
+
* @see Requirements 9.5
|
|
1734
|
+
*/
|
|
1735
|
+
enable2FA(code: string): Promise<SuccessResponse>;
|
|
1736
|
+
/**
|
|
1737
|
+
* Disable two-factor authentication.
|
|
1738
|
+
*
|
|
1739
|
+
* Requires a valid verification code to confirm the user's identity.
|
|
1740
|
+
*
|
|
1741
|
+
* @param code - The 6-digit verification code from the authenticator app
|
|
1742
|
+
* @returns Promise resolving to a success response
|
|
1743
|
+
* @throws ValidationError if the code is invalid
|
|
1744
|
+
*
|
|
1745
|
+
* @example
|
|
1746
|
+
* ```typescript
|
|
1747
|
+
* await client.user.disable2FA('123456');
|
|
1748
|
+
* console.log('2FA disabled');
|
|
1749
|
+
* ```
|
|
1750
|
+
*
|
|
1751
|
+
* @see Requirements 9.6
|
|
1752
|
+
*/
|
|
1753
|
+
disable2FA(code: string): Promise<SuccessResponse>;
|
|
1754
|
+
/**
|
|
1755
|
+
* Verify a two-factor authentication code.
|
|
1756
|
+
*
|
|
1757
|
+
* Use this to verify a 2FA code during login or sensitive operations.
|
|
1758
|
+
*
|
|
1759
|
+
* @param code - The 6-digit verification code from the authenticator app
|
|
1760
|
+
* @returns Promise resolving to a success response
|
|
1761
|
+
* @throws ValidationError if the code is invalid
|
|
1762
|
+
*
|
|
1763
|
+
* @example
|
|
1764
|
+
* ```typescript
|
|
1765
|
+
* await client.user.verify2FA('123456');
|
|
1766
|
+
* console.log('2FA code verified');
|
|
1767
|
+
* ```
|
|
1768
|
+
*
|
|
1769
|
+
* @see Requirements 9.7
|
|
1770
|
+
*/
|
|
1771
|
+
verify2FA(code: string): Promise<SuccessResponse>;
|
|
1772
|
+
/**
|
|
1773
|
+
* List all API keys for the current user.
|
|
1774
|
+
*
|
|
1775
|
+
* Note: The `key` field will only contain the full key value when
|
|
1776
|
+
* the key is first created. For existing keys, it may be masked.
|
|
1777
|
+
*
|
|
1778
|
+
* @returns Promise resolving to an array of API keys
|
|
1779
|
+
*
|
|
1780
|
+
* @example
|
|
1781
|
+
* ```typescript
|
|
1782
|
+
* const keys = await client.user.listApiKeys();
|
|
1783
|
+
* keys.forEach(key => {
|
|
1784
|
+
* console.log(`${key.name}: last used ${key.last_used_at || 'never'}`);
|
|
1785
|
+
* });
|
|
1786
|
+
* ```
|
|
1787
|
+
*
|
|
1788
|
+
* @see Requirements 9.8
|
|
1789
|
+
*/
|
|
1790
|
+
listApiKeys(): Promise<ApiKey[]>;
|
|
1791
|
+
/**
|
|
1792
|
+
* Create a new API key.
|
|
1793
|
+
*
|
|
1794
|
+
* The returned API key will include the full key value in the `key` field.
|
|
1795
|
+
* This is the only time the full key is available - store it securely.
|
|
1796
|
+
*
|
|
1797
|
+
* @param data - The API key data
|
|
1798
|
+
* @param data.name - Display name for the API key (required)
|
|
1799
|
+
* @returns Promise resolving to the created API key with full key value
|
|
1800
|
+
*
|
|
1801
|
+
* @example
|
|
1802
|
+
* ```typescript
|
|
1803
|
+
* const apiKey = await client.user.createApiKey({ name: 'My Application' });
|
|
1804
|
+
* console.log('API Key created:', apiKey.key);
|
|
1805
|
+
* // Store this key securely - it won't be shown again!
|
|
1806
|
+
* ```
|
|
1807
|
+
*
|
|
1808
|
+
* @see Requirements 9.9
|
|
1809
|
+
*/
|
|
1810
|
+
createApiKey(data: CreateApiKeyRequest): Promise<ApiKey>;
|
|
1811
|
+
/**
|
|
1812
|
+
* Delete an API key by ID.
|
|
1813
|
+
*
|
|
1814
|
+
* @param id - The unique identifier of the API key to delete
|
|
1815
|
+
* @returns Promise resolving to a success response
|
|
1816
|
+
* @throws NotFoundError if the API key does not exist
|
|
1817
|
+
*
|
|
1818
|
+
* @example
|
|
1819
|
+
* ```typescript
|
|
1820
|
+
* await client.user.deleteApiKey('key_123');
|
|
1821
|
+
* console.log('API key deleted');
|
|
1822
|
+
* ```
|
|
1823
|
+
*
|
|
1824
|
+
* @see Requirements 9.10
|
|
1825
|
+
*/
|
|
1826
|
+
deleteApiKey(id: string): Promise<SuccessResponse>;
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
/**
|
|
1830
|
+
* Billing Resource for the Spike Forms SDK
|
|
1831
|
+
*
|
|
1832
|
+
* Provides methods for managing billing and subscriptions:
|
|
1833
|
+
* - createCheckout: Create a Stripe checkout session for subscription
|
|
1834
|
+
* - createPortal: Create a Stripe billing portal session for managing subscription
|
|
1835
|
+
*
|
|
1836
|
+
* @module resources/billing
|
|
1837
|
+
*/
|
|
1838
|
+
|
|
1839
|
+
/**
|
|
1840
|
+
* Resource class for managing billing and subscriptions in Spike Forms.
|
|
1841
|
+
*
|
|
1842
|
+
* Provides access to Stripe checkout and billing portal functionality
|
|
1843
|
+
* for managing user subscriptions.
|
|
1844
|
+
*
|
|
1845
|
+
* @example
|
|
1846
|
+
* ```typescript
|
|
1847
|
+
* // Create a checkout session for a new subscription
|
|
1848
|
+
* const checkout = await client.billing.createCheckout({
|
|
1849
|
+
* price_id: 'price_123',
|
|
1850
|
+
* success_url: 'https://myapp.com/success',
|
|
1851
|
+
* cancel_url: 'https://myapp.com/cancel'
|
|
1852
|
+
* });
|
|
1853
|
+
* // Redirect user to checkout.url
|
|
1854
|
+
*
|
|
1855
|
+
* // Create a billing portal session for managing subscription
|
|
1856
|
+
* const portal = await client.billing.createPortal();
|
|
1857
|
+
* // Redirect user to portal.url
|
|
1858
|
+
* ```
|
|
1859
|
+
*/
|
|
1860
|
+
declare class BillingResource {
|
|
1861
|
+
private readonly http;
|
|
1862
|
+
/**
|
|
1863
|
+
* Create a new BillingResource instance
|
|
1864
|
+
* @param http - The HTTP client to use for API requests
|
|
1865
|
+
*/
|
|
1866
|
+
constructor(http: HttpClient);
|
|
1867
|
+
/**
|
|
1868
|
+
* Create a Stripe checkout session for starting a new subscription.
|
|
1869
|
+
*
|
|
1870
|
+
* Returns a URL that the user should be redirected to in order to
|
|
1871
|
+
* complete the checkout process on Stripe's hosted checkout page.
|
|
1872
|
+
*
|
|
1873
|
+
* @param data - The checkout session configuration
|
|
1874
|
+
* @param data.price_id - The Stripe price ID for the subscription plan
|
|
1875
|
+
* @param data.success_url - URL to redirect to after successful checkout
|
|
1876
|
+
* @param data.cancel_url - URL to redirect to if checkout is cancelled
|
|
1877
|
+
* @returns Promise resolving to the checkout response with redirect URL
|
|
1878
|
+
*
|
|
1879
|
+
* @example
|
|
1880
|
+
* ```typescript
|
|
1881
|
+
* const checkout = await client.billing.createCheckout({
|
|
1882
|
+
* price_id: 'price_1234567890',
|
|
1883
|
+
* success_url: 'https://myapp.com/checkout/success',
|
|
1884
|
+
* cancel_url: 'https://myapp.com/checkout/cancel'
|
|
1885
|
+
* });
|
|
1886
|
+
*
|
|
1887
|
+
* // Redirect the user to complete checkout
|
|
1888
|
+
* window.location.href = checkout.url;
|
|
1889
|
+
* ```
|
|
1890
|
+
*
|
|
1891
|
+
* @see Requirements 10.1
|
|
1892
|
+
*/
|
|
1893
|
+
createCheckout(data: CreateCheckoutRequest): Promise<CheckoutResponse>;
|
|
1894
|
+
/**
|
|
1895
|
+
* Create a Stripe billing portal session for managing an existing subscription.
|
|
1896
|
+
*
|
|
1897
|
+
* Returns a URL that the user should be redirected to in order to
|
|
1898
|
+
* access the Stripe billing portal where they can:
|
|
1899
|
+
* - View and update payment methods
|
|
1900
|
+
* - View billing history and invoices
|
|
1901
|
+
* - Upgrade, downgrade, or cancel their subscription
|
|
1902
|
+
*
|
|
1903
|
+
* @returns Promise resolving to the portal response with redirect URL
|
|
1904
|
+
*
|
|
1905
|
+
* @example
|
|
1906
|
+
* ```typescript
|
|
1907
|
+
* const portal = await client.billing.createPortal();
|
|
1908
|
+
*
|
|
1909
|
+
* // Redirect the user to the billing portal
|
|
1910
|
+
* window.location.href = portal.url;
|
|
1911
|
+
* ```
|
|
1912
|
+
*
|
|
1913
|
+
* @see Requirements 10.2
|
|
1914
|
+
*/
|
|
1915
|
+
createPortal(): Promise<PortalResponse>;
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
/**
|
|
1919
|
+
* Files Resource for the Spike Forms SDK
|
|
1920
|
+
*
|
|
1921
|
+
* Provides methods for managing uploaded files:
|
|
1922
|
+
* - getDownloadUrl: Get a signed download URL for a file
|
|
1923
|
+
* - delete: Delete a file by ID
|
|
1924
|
+
*
|
|
1925
|
+
* @module resources/files
|
|
1926
|
+
*/
|
|
1927
|
+
|
|
1928
|
+
/**
|
|
1929
|
+
* Resource class for managing uploaded files in Spike Forms.
|
|
1930
|
+
*
|
|
1931
|
+
* Provides access to file download URLs and deletion functionality
|
|
1932
|
+
* for files attached to form submissions.
|
|
1933
|
+
*
|
|
1934
|
+
* @example
|
|
1935
|
+
* ```typescript
|
|
1936
|
+
* // Get a signed download URL for a file
|
|
1937
|
+
* const download = await client.files.getDownloadUrl('file_123');
|
|
1938
|
+
* console.log(download.url); // Signed URL for downloading
|
|
1939
|
+
* console.log(download.expires_at); // When the URL expires
|
|
1940
|
+
*
|
|
1941
|
+
* // Delete a file
|
|
1942
|
+
* const result = await client.files.delete('file_123');
|
|
1943
|
+
* console.log(result.success); // true
|
|
1944
|
+
* ```
|
|
1945
|
+
*/
|
|
1946
|
+
declare class FilesResource {
|
|
1947
|
+
private readonly http;
|
|
1948
|
+
/**
|
|
1949
|
+
* Create a new FilesResource instance
|
|
1950
|
+
* @param http - The HTTP client to use for API requests
|
|
1951
|
+
*/
|
|
1952
|
+
constructor(http: HttpClient);
|
|
1953
|
+
/**
|
|
1954
|
+
* Get a signed download URL for a file.
|
|
1955
|
+
*
|
|
1956
|
+
* Returns a temporary signed URL that can be used to download the file.
|
|
1957
|
+
* The URL will expire at the time indicated in the response.
|
|
1958
|
+
*
|
|
1959
|
+
* @param id - The unique identifier of the file
|
|
1960
|
+
* @returns Promise resolving to the download response with signed URL and expiration
|
|
1961
|
+
*
|
|
1962
|
+
* @example
|
|
1963
|
+
* ```typescript
|
|
1964
|
+
* const download = await client.files.getDownloadUrl('file_abc123');
|
|
1965
|
+
*
|
|
1966
|
+
* // Use the signed URL to download the file
|
|
1967
|
+
* const response = await fetch(download.url);
|
|
1968
|
+
* const blob = await response.blob();
|
|
1969
|
+
*
|
|
1970
|
+
* // Check when the URL expires
|
|
1971
|
+
* console.log(`URL expires at: ${download.expires_at}`);
|
|
1972
|
+
* ```
|
|
1973
|
+
*
|
|
1974
|
+
* @see Requirements 11.1
|
|
1975
|
+
*/
|
|
1976
|
+
getDownloadUrl(id: string): Promise<FileDownloadResponse>;
|
|
1977
|
+
/**
|
|
1978
|
+
* Delete a file by ID.
|
|
1979
|
+
*
|
|
1980
|
+
* Permanently removes the file from storage. This action cannot be undone.
|
|
1981
|
+
*
|
|
1982
|
+
* @param id - The unique identifier of the file to delete
|
|
1983
|
+
* @returns Promise resolving to a success response
|
|
1984
|
+
*
|
|
1985
|
+
* @example
|
|
1986
|
+
* ```typescript
|
|
1987
|
+
* const result = await client.files.delete('file_abc123');
|
|
1988
|
+
*
|
|
1989
|
+
* if (result.success) {
|
|
1990
|
+
* console.log('File deleted successfully');
|
|
1991
|
+
* }
|
|
1992
|
+
* ```
|
|
1993
|
+
*
|
|
1994
|
+
* @see Requirements 11.2
|
|
1995
|
+
*/
|
|
1996
|
+
delete(id: string): Promise<SuccessResponse>;
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1999
|
+
/**
|
|
2000
|
+
* Spike Client for the Spike Forms SDK
|
|
2001
|
+
*
|
|
2002
|
+
* The main entry point for the SDK. Initializes all resource classes
|
|
2003
|
+
* and manages configuration for authenticated API requests.
|
|
2004
|
+
*
|
|
2005
|
+
* @module client
|
|
2006
|
+
*/
|
|
2007
|
+
|
|
2008
|
+
/**
|
|
2009
|
+
* Configuration options for the Spike client.
|
|
2010
|
+
*
|
|
2011
|
+
* @example
|
|
2012
|
+
* ```typescript
|
|
2013
|
+
* const config: SpikeClientConfig = {
|
|
2014
|
+
* apiKey: 'sk_live_abc123',
|
|
2015
|
+
* baseUrl: 'https://spike.ac',
|
|
2016
|
+
* timeout: 30000
|
|
2017
|
+
* };
|
|
2018
|
+
* ```
|
|
2019
|
+
*/
|
|
2020
|
+
interface SpikeClientConfig {
|
|
2021
|
+
/**
|
|
2022
|
+
* API key for authentication.
|
|
2023
|
+
* User API keys are prefixed with `sk_`.
|
|
2024
|
+
* @see Requirements 1.1, 1.6
|
|
2025
|
+
*/
|
|
2026
|
+
apiKey: string;
|
|
2027
|
+
/**
|
|
2028
|
+
* Base URL for API requests.
|
|
2029
|
+
* @default 'https://api.spike.ac'
|
|
2030
|
+
* @see Requirements 2.2
|
|
2031
|
+
*/
|
|
2032
|
+
baseUrl?: string;
|
|
2033
|
+
/**
|
|
2034
|
+
* Request timeout in milliseconds.
|
|
2035
|
+
* @default 30000
|
|
2036
|
+
* @see Requirements 1.5
|
|
2037
|
+
*/
|
|
2038
|
+
timeout?: number;
|
|
2039
|
+
}
|
|
2040
|
+
/**
|
|
2041
|
+
* The main Spike Forms SDK client.
|
|
2042
|
+
*
|
|
2043
|
+
* Provides access to all Spike Forms API resources through a unified interface.
|
|
2044
|
+
* Initialize with your API key to start making authenticated requests.
|
|
2045
|
+
*
|
|
2046
|
+
* @example
|
|
2047
|
+
* ```typescript
|
|
2048
|
+
* // Basic initialization
|
|
2049
|
+
* const client = new SpikeClient({ apiKey: 'sk_live_abc123' });
|
|
2050
|
+
*
|
|
2051
|
+
* // With custom configuration
|
|
2052
|
+
* const client = new SpikeClient({
|
|
2053
|
+
* apiKey: 'sk_live_abc123',
|
|
2054
|
+
* baseUrl: 'https://custom.spike.ac',
|
|
2055
|
+
* timeout: 60000
|
|
2056
|
+
* });
|
|
2057
|
+
*
|
|
2058
|
+
* // Use resources
|
|
2059
|
+
* const forms = await client.forms.list();
|
|
2060
|
+
* const projects = await client.projects.list();
|
|
2061
|
+
* const user = await client.user.get();
|
|
2062
|
+
* ```
|
|
2063
|
+
*
|
|
2064
|
+
* @see Requirements 1.1, 1.2, 1.3, 1.4, 1.5, 1.6
|
|
2065
|
+
*/
|
|
2066
|
+
declare class SpikeClient {
|
|
2067
|
+
/**
|
|
2068
|
+
* Resource for managing forms.
|
|
2069
|
+
* @see FormsResource
|
|
2070
|
+
*/
|
|
2071
|
+
readonly forms: FormsResource;
|
|
2072
|
+
/**
|
|
2073
|
+
* Resource for managing form submissions.
|
|
2074
|
+
* @see SubmissionsResource
|
|
2075
|
+
*/
|
|
2076
|
+
readonly submissions: SubmissionsResource;
|
|
2077
|
+
/**
|
|
2078
|
+
* Resource for managing form rules.
|
|
2079
|
+
* @see RulesResource
|
|
2080
|
+
*/
|
|
2081
|
+
readonly rules: RulesResource;
|
|
2082
|
+
/**
|
|
2083
|
+
* Resource for managing projects.
|
|
2084
|
+
* @see ProjectsResource
|
|
2085
|
+
*/
|
|
2086
|
+
readonly projects: ProjectsResource;
|
|
2087
|
+
/**
|
|
2088
|
+
* Resource for managing teams.
|
|
2089
|
+
* @see TeamsResource
|
|
2090
|
+
*/
|
|
2091
|
+
readonly teams: TeamsResource;
|
|
2092
|
+
/**
|
|
2093
|
+
* Resource for managing user profile and settings.
|
|
2094
|
+
* @see UserResource
|
|
2095
|
+
*/
|
|
2096
|
+
readonly user: UserResource;
|
|
2097
|
+
/**
|
|
2098
|
+
* Resource for managing billing and subscriptions.
|
|
2099
|
+
* @see BillingResource
|
|
2100
|
+
*/
|
|
2101
|
+
readonly billing: BillingResource;
|
|
2102
|
+
/**
|
|
2103
|
+
* Resource for managing uploaded files.
|
|
2104
|
+
* @see FilesResource
|
|
2105
|
+
*/
|
|
2106
|
+
readonly files: FilesResource;
|
|
2107
|
+
/**
|
|
2108
|
+
* The HTTP client used for API requests.
|
|
2109
|
+
* @internal
|
|
2110
|
+
*/
|
|
2111
|
+
private readonly http;
|
|
2112
|
+
/**
|
|
2113
|
+
* Create a new Spike client instance.
|
|
2114
|
+
*
|
|
2115
|
+
* @param config - Configuration options for the client
|
|
2116
|
+
* @throws ValidationError if the API key is missing or empty
|
|
2117
|
+
*
|
|
2118
|
+
* @example
|
|
2119
|
+
* ```typescript
|
|
2120
|
+
* // Basic usage with API key
|
|
2121
|
+
* const client = new SpikeClient({ apiKey: 'sk_live_abc123' });
|
|
2122
|
+
*
|
|
2123
|
+
* // With all configuration options
|
|
2124
|
+
* const client = new SpikeClient({
|
|
2125
|
+
* apiKey: 'sk_live_abc123',
|
|
2126
|
+
* baseUrl: 'https://spike.ac',
|
|
2127
|
+
* timeout: 30000
|
|
2128
|
+
* });
|
|
2129
|
+
* ```
|
|
2130
|
+
*
|
|
2131
|
+
* @see Requirements 1.1, 1.2, 1.3, 1.4, 1.5
|
|
2132
|
+
*/
|
|
2133
|
+
constructor(config: SpikeClientConfig);
|
|
2134
|
+
}
|
|
2135
|
+
|
|
2136
|
+
/**
|
|
2137
|
+
* Error classes for the Spike Forms SDK
|
|
2138
|
+
*
|
|
2139
|
+
* Provides a hierarchy of error types for different API error conditions:
|
|
2140
|
+
* - SpikeError: Base error class for all SDK errors
|
|
2141
|
+
* - AuthenticationError: 401 Unauthorized errors
|
|
2142
|
+
* - NotFoundError: 404 Not Found errors
|
|
2143
|
+
* - RateLimitError: 429 Too Many Requests errors
|
|
2144
|
+
* - ValidationError: 400 Bad Request errors
|
|
2145
|
+
* - NetworkError: Network/connection failures
|
|
2146
|
+
*/
|
|
2147
|
+
/**
|
|
2148
|
+
* Base error class for all Spike SDK errors.
|
|
2149
|
+
*
|
|
2150
|
+
* @example
|
|
2151
|
+
* ```typescript
|
|
2152
|
+
* try {
|
|
2153
|
+
* await client.forms.get('invalid-id');
|
|
2154
|
+
* } catch (error) {
|
|
2155
|
+
* if (error instanceof SpikeError) {
|
|
2156
|
+
* console.log(error.statusCode); // HTTP status code
|
|
2157
|
+
* console.log(error.code); // Error code from API
|
|
2158
|
+
* console.log(error.requestId); // Request ID for debugging
|
|
2159
|
+
* }
|
|
2160
|
+
* }
|
|
2161
|
+
* ```
|
|
2162
|
+
*/
|
|
2163
|
+
declare class SpikeError extends Error {
|
|
2164
|
+
/** HTTP status code from the API response */
|
|
2165
|
+
statusCode?: number;
|
|
2166
|
+
/** Error code from the API (e.g., 'INVALID_API_KEY', 'FORM_NOT_FOUND') */
|
|
2167
|
+
code?: string;
|
|
2168
|
+
/** Request ID for debugging and support purposes */
|
|
2169
|
+
requestId?: string;
|
|
2170
|
+
constructor(message: string, options?: {
|
|
2171
|
+
statusCode?: number;
|
|
2172
|
+
code?: string;
|
|
2173
|
+
requestId?: string;
|
|
2174
|
+
});
|
|
2175
|
+
}
|
|
2176
|
+
/**
|
|
2177
|
+
* Error thrown when authentication fails (HTTP 401).
|
|
2178
|
+
*
|
|
2179
|
+
* This error is thrown when:
|
|
2180
|
+
* - The API key is invalid or expired
|
|
2181
|
+
* - The API key is missing from the request
|
|
2182
|
+
* - The API key doesn't have permission for the requested resource
|
|
2183
|
+
*
|
|
2184
|
+
* @example
|
|
2185
|
+
* ```typescript
|
|
2186
|
+
* try {
|
|
2187
|
+
* await client.forms.list();
|
|
2188
|
+
* } catch (error) {
|
|
2189
|
+
* if (error instanceof AuthenticationError) {
|
|
2190
|
+
* console.log('Please check your API key');
|
|
2191
|
+
* }
|
|
2192
|
+
* }
|
|
2193
|
+
* ```
|
|
2194
|
+
*/
|
|
2195
|
+
declare class AuthenticationError extends SpikeError {
|
|
2196
|
+
constructor(message: string, options?: {
|
|
2197
|
+
code?: string;
|
|
2198
|
+
requestId?: string;
|
|
2199
|
+
});
|
|
2200
|
+
}
|
|
2201
|
+
/**
|
|
2202
|
+
* Error thrown when a resource is not found (HTTP 404).
|
|
2203
|
+
*
|
|
2204
|
+
* This error is thrown when:
|
|
2205
|
+
* - The requested form, project, team, or other resource doesn't exist
|
|
2206
|
+
* - The resource ID is invalid
|
|
2207
|
+
* - The resource was deleted
|
|
2208
|
+
*
|
|
2209
|
+
* @example
|
|
2210
|
+
* ```typescript
|
|
2211
|
+
* try {
|
|
2212
|
+
* await client.forms.get('non-existent-id');
|
|
2213
|
+
* } catch (error) {
|
|
2214
|
+
* if (error instanceof NotFoundError) {
|
|
2215
|
+
* console.log('Form not found');
|
|
2216
|
+
* }
|
|
2217
|
+
* }
|
|
2218
|
+
* ```
|
|
2219
|
+
*/
|
|
2220
|
+
declare class NotFoundError extends SpikeError {
|
|
2221
|
+
constructor(message: string, options?: {
|
|
2222
|
+
code?: string;
|
|
2223
|
+
requestId?: string;
|
|
2224
|
+
});
|
|
2225
|
+
}
|
|
2226
|
+
/**
|
|
2227
|
+
* Error thrown when rate limit is exceeded (HTTP 429).
|
|
2228
|
+
*
|
|
2229
|
+
* This error is thrown when too many requests are made in a short period.
|
|
2230
|
+
* The `retryAfter` property indicates how many seconds to wait before retrying.
|
|
2231
|
+
*
|
|
2232
|
+
* @example
|
|
2233
|
+
* ```typescript
|
|
2234
|
+
* try {
|
|
2235
|
+
* await client.forms.list();
|
|
2236
|
+
* } catch (error) {
|
|
2237
|
+
* if (error instanceof RateLimitError) {
|
|
2238
|
+
* console.log(`Rate limited. Retry after ${error.retryAfter} seconds`);
|
|
2239
|
+
* await sleep(error.retryAfter * 1000);
|
|
2240
|
+
* // Retry the request
|
|
2241
|
+
* }
|
|
2242
|
+
* }
|
|
2243
|
+
* ```
|
|
2244
|
+
*/
|
|
2245
|
+
declare class RateLimitError extends SpikeError {
|
|
2246
|
+
/** Number of seconds to wait before retrying the request */
|
|
2247
|
+
retryAfter?: number;
|
|
2248
|
+
constructor(message: string, options?: {
|
|
2249
|
+
code?: string;
|
|
2250
|
+
requestId?: string;
|
|
2251
|
+
retryAfter?: number;
|
|
2252
|
+
});
|
|
2253
|
+
}
|
|
2254
|
+
/**
|
|
2255
|
+
* Error thrown when request validation fails (HTTP 400).
|
|
2256
|
+
*
|
|
2257
|
+
* This error is thrown when:
|
|
2258
|
+
* - Required fields are missing
|
|
2259
|
+
* - Field values are invalid
|
|
2260
|
+
* - Request body format is incorrect
|
|
2261
|
+
*
|
|
2262
|
+
* The `details` property contains field-specific validation errors.
|
|
2263
|
+
*
|
|
2264
|
+
* @example
|
|
2265
|
+
* ```typescript
|
|
2266
|
+
* try {
|
|
2267
|
+
* await client.forms.create({ name: '' });
|
|
2268
|
+
* } catch (error) {
|
|
2269
|
+
* if (error instanceof ValidationError) {
|
|
2270
|
+
* console.log('Validation failed:', error.details);
|
|
2271
|
+
* // { name: 'Name is required' }
|
|
2272
|
+
* }
|
|
2273
|
+
* }
|
|
2274
|
+
* ```
|
|
2275
|
+
*/
|
|
2276
|
+
declare class ValidationError extends SpikeError {
|
|
2277
|
+
/** Field-specific validation error details */
|
|
2278
|
+
details?: Record<string, unknown>;
|
|
2279
|
+
constructor(message: string, options?: {
|
|
2280
|
+
code?: string;
|
|
2281
|
+
requestId?: string;
|
|
2282
|
+
details?: Record<string, unknown>;
|
|
2283
|
+
});
|
|
2284
|
+
}
|
|
2285
|
+
/**
|
|
2286
|
+
* Error thrown when a network error occurs.
|
|
2287
|
+
*
|
|
2288
|
+
* This error is thrown when:
|
|
2289
|
+
* - The network connection fails
|
|
2290
|
+
* - The request times out
|
|
2291
|
+
* - DNS resolution fails
|
|
2292
|
+
* - The server is unreachable
|
|
2293
|
+
*
|
|
2294
|
+
* @example
|
|
2295
|
+
* ```typescript
|
|
2296
|
+
* try {
|
|
2297
|
+
* await client.forms.list();
|
|
2298
|
+
* } catch (error) {
|
|
2299
|
+
* if (error instanceof NetworkError) {
|
|
2300
|
+
* console.log('Network error:', error.message);
|
|
2301
|
+
* // Retry with exponential backoff
|
|
2302
|
+
* }
|
|
2303
|
+
* }
|
|
2304
|
+
* ```
|
|
2305
|
+
*/
|
|
2306
|
+
declare class NetworkError extends SpikeError {
|
|
2307
|
+
constructor(message: string, options?: {
|
|
2308
|
+
code?: string;
|
|
2309
|
+
requestId?: string;
|
|
2310
|
+
});
|
|
2311
|
+
}
|
|
2312
|
+
|
|
2313
|
+
/**
|
|
2314
|
+
* @spike-forms/sdk
|
|
2315
|
+
* TypeScript SDK for the Spike Forms API
|
|
2316
|
+
*
|
|
2317
|
+
* This module exports all SDK components including:
|
|
2318
|
+
* - SpikeClient: The main client class for API access
|
|
2319
|
+
* - Error classes: Custom error types for different error conditions
|
|
2320
|
+
* - Type definitions: TypeScript interfaces for all entities and requests
|
|
2321
|
+
* - Resource classes: Individual resource classes for direct use
|
|
2322
|
+
*
|
|
2323
|
+
* @example
|
|
2324
|
+
* ```typescript
|
|
2325
|
+
* import { SpikeClient, SpikeError, NotFoundError } from '@spike-forms/sdk';
|
|
2326
|
+
*
|
|
2327
|
+
* const client = new SpikeClient({ apiKey: 'sk_live_abc123' });
|
|
2328
|
+
*
|
|
2329
|
+
* try {
|
|
2330
|
+
* const forms = await client.forms.list();
|
|
2331
|
+
* console.log(forms);
|
|
2332
|
+
* } catch (error) {
|
|
2333
|
+
* if (error instanceof NotFoundError) {
|
|
2334
|
+
* console.log('Resource not found');
|
|
2335
|
+
* } else if (error instanceof SpikeError) {
|
|
2336
|
+
* console.log('API error:', error.message);
|
|
2337
|
+
* }
|
|
2338
|
+
* }
|
|
2339
|
+
* ```
|
|
2340
|
+
*
|
|
2341
|
+
* @module @spike-forms/sdk
|
|
2342
|
+
*/
|
|
2343
|
+
declare const VERSION = "0.1.0";
|
|
2344
|
+
|
|
2345
|
+
export { type ApiKey, AuthenticationError, BillingResource, type BulkAction, type BulkUpdateRequest, type CheckoutResponse, type CreateApiKeyRequest, type CreateCheckoutRequest, type CreateFormRequest, type CreateProjectRequest, type CreateRuleRequest, type CreateTeamRequest, type FileDownloadResponse, FilesResource, type Form, FormsResource, type InviteMemberRequest, type ListFormsParams, type ListSubmissionsParams, NetworkError, NotFoundError, type PaginatedResponse, type PaginationParams, type PortalResponse, type Project, ProjectsResource, RateLimitError, type Rule, type RuleAction, type RuleActionType, type RuleCondition, type RuleConditionOperator, RulesResource, type Setup2FAResponse, SpikeClient, type SpikeClientConfig, SpikeError, type Submission, type SubmissionOrder, type SubmissionResponse, type SubmissionStats, SubmissionsResource, type SuccessResponse, type Team, type TeamInvitation, type TeamInvitationRole, type TeamMember, type TeamMemberRole, TeamsResource, type UpdateFormRequest, type UpdateMemberRequest, type UpdateProjectRequest, type UpdateRuleRequest, type UpdateTeamRequest, type UpdateUserRequest, type User, UserResource, VERSION, ValidationError };
|