@planescrm/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 +155 -0
- package/dist/index.d.mts +596 -0
- package/dist/index.d.ts +596 -0
- package/dist/index.js +646 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +581 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +36 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,596 @@
|
|
|
1
|
+
import * as http from 'node:http';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for the BlueprintClient.
|
|
5
|
+
*/
|
|
6
|
+
interface BlueprintConfig {
|
|
7
|
+
/** API base URL (defaults to https://api.planescrm.com/api/v1) */
|
|
8
|
+
baseUrl?: string;
|
|
9
|
+
/** OAuth access token (mutually exclusive with apiKey) */
|
|
10
|
+
accessToken?: string;
|
|
11
|
+
/** API key (mutually exclusive with accessToken) */
|
|
12
|
+
apiKey?: string;
|
|
13
|
+
/** Request timeout in milliseconds (default 30000) */
|
|
14
|
+
timeout?: number;
|
|
15
|
+
/** Automatically retry on 429 rate limit responses (default true) */
|
|
16
|
+
retryOnRateLimit?: boolean;
|
|
17
|
+
/** Maximum number of retries for rate-limited requests (default 3) */
|
|
18
|
+
maxRetries?: number;
|
|
19
|
+
}
|
|
20
|
+
declare const DEFAULT_BASE_URL = "https://api.planescrm.com/api/v1";
|
|
21
|
+
declare const DEFAULT_TIMEOUT = 30000;
|
|
22
|
+
declare const DEFAULT_MAX_RETRIES = 3;
|
|
23
|
+
|
|
24
|
+
interface HttpRequestOptions {
|
|
25
|
+
method: string;
|
|
26
|
+
path: string;
|
|
27
|
+
body?: unknown;
|
|
28
|
+
params?: Record<string, unknown>;
|
|
29
|
+
headers?: Record<string, string>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Internal HTTP client wrapper using native fetch.
|
|
33
|
+
* Handles authentication, rate limit retries, and error mapping.
|
|
34
|
+
*/
|
|
35
|
+
declare class HttpClient {
|
|
36
|
+
private readonly baseUrl;
|
|
37
|
+
private readonly accessToken;
|
|
38
|
+
private readonly apiKey;
|
|
39
|
+
private readonly timeout;
|
|
40
|
+
private readonly retryOnRateLimit;
|
|
41
|
+
private readonly maxRetries;
|
|
42
|
+
constructor(config: BlueprintConfig);
|
|
43
|
+
request<T>(options: HttpRequestOptions): Promise<T>;
|
|
44
|
+
getAuthHeaders(): Record<string, string>;
|
|
45
|
+
private buildUrl;
|
|
46
|
+
private parseRetryAfter;
|
|
47
|
+
private mapError;
|
|
48
|
+
private sleep;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Paginated list response wrapper.
|
|
53
|
+
*/
|
|
54
|
+
interface PaginatedResponse<T> {
|
|
55
|
+
data: T[];
|
|
56
|
+
meta: {
|
|
57
|
+
page: number;
|
|
58
|
+
limit: number;
|
|
59
|
+
total: number;
|
|
60
|
+
totalPages: number;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Common filter/pagination parameters for list endpoints.
|
|
65
|
+
*/
|
|
66
|
+
interface ListParams {
|
|
67
|
+
page?: number;
|
|
68
|
+
limit?: number;
|
|
69
|
+
sort?: string;
|
|
70
|
+
order?: 'asc' | 'desc';
|
|
71
|
+
search?: string;
|
|
72
|
+
[key: string]: unknown;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Abstract base resource with standard CRUD methods.
|
|
77
|
+
* Generic parameters:
|
|
78
|
+
* - TEntity: the entity response type
|
|
79
|
+
* - TCreate: the create request body type
|
|
80
|
+
* - TUpdate: the update request body type
|
|
81
|
+
*/
|
|
82
|
+
declare abstract class BaseResource<TEntity = Record<string, unknown>, TCreate = Record<string, unknown>, TUpdate = Record<string, unknown>> {
|
|
83
|
+
protected readonly http: HttpClient;
|
|
84
|
+
protected readonly basePath: string;
|
|
85
|
+
constructor(http: HttpClient, basePath: string);
|
|
86
|
+
/**
|
|
87
|
+
* List entities with optional filters and pagination.
|
|
88
|
+
*/
|
|
89
|
+
list(params?: ListParams): Promise<PaginatedResponse<TEntity>>;
|
|
90
|
+
/**
|
|
91
|
+
* Get a single entity by ID.
|
|
92
|
+
*/
|
|
93
|
+
get(id: string): Promise<TEntity>;
|
|
94
|
+
/**
|
|
95
|
+
* Create a new entity.
|
|
96
|
+
*/
|
|
97
|
+
create(data: TCreate): Promise<TEntity>;
|
|
98
|
+
/**
|
|
99
|
+
* Update an existing entity.
|
|
100
|
+
*/
|
|
101
|
+
update(id: string, data: TUpdate): Promise<TEntity>;
|
|
102
|
+
/**
|
|
103
|
+
* Delete an entity by ID.
|
|
104
|
+
*/
|
|
105
|
+
delete(id: string): Promise<void>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Opportunity resource — CRUD operations on /opportunities. */
|
|
109
|
+
declare class OpportunityResource extends BaseResource {
|
|
110
|
+
constructor(http: ConstructorParameters<typeof BaseResource>[0]);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Customer resource — CRUD operations on /customers. */
|
|
114
|
+
declare class CustomerResource extends BaseResource {
|
|
115
|
+
constructor(http: ConstructorParameters<typeof BaseResource>[0]);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Property resource — CRUD operations on /properties. */
|
|
119
|
+
declare class PropertyResource extends BaseResource {
|
|
120
|
+
constructor(http: ConstructorParameters<typeof BaseResource>[0]);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Calendar event resource — CRUD operations on /calendar-events. */
|
|
124
|
+
declare class CalendarEventResource extends BaseResource {
|
|
125
|
+
constructor(http: ConstructorParameters<typeof BaseResource>[0]);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Contract resource — CRUD operations on /contracts. */
|
|
129
|
+
declare class ContractResource extends BaseResource {
|
|
130
|
+
constructor(http: ConstructorParameters<typeof BaseResource>[0]);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Job resource — CRUD operations on /jobs. */
|
|
134
|
+
declare class JobResource extends BaseResource {
|
|
135
|
+
constructor(http: ConstructorParameters<typeof BaseResource>[0]);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Estimate resource — CRUD operations on /estimates. */
|
|
139
|
+
declare class EstimateResource extends BaseResource {
|
|
140
|
+
constructor(http: ConstructorParameters<typeof BaseResource>[0]);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Invoice resource — CRUD operations on /invoices. */
|
|
144
|
+
declare class InvoiceResource extends BaseResource {
|
|
145
|
+
constructor(http: ConstructorParameters<typeof BaseResource>[0]);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Inventory resource — CRUD operations on /inventory/items. */
|
|
149
|
+
declare class InventoryResource extends BaseResource {
|
|
150
|
+
constructor(http: ConstructorParameters<typeof BaseResource>[0]);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* BlueprintClient — typed API client for the Planes CRM platform.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* const client = new BlueprintClient({ accessToken: 'tok_...' });
|
|
159
|
+
* const opps = await client.opportunities.list({ page: 1, limit: 20 });
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
declare class BlueprintClient {
|
|
163
|
+
private readonly http;
|
|
164
|
+
private _opportunities?;
|
|
165
|
+
private _customers?;
|
|
166
|
+
private _properties?;
|
|
167
|
+
private _calendarEvents?;
|
|
168
|
+
private _contracts?;
|
|
169
|
+
private _jobs?;
|
|
170
|
+
private _estimates?;
|
|
171
|
+
private _invoices?;
|
|
172
|
+
private _inventory?;
|
|
173
|
+
constructor(config: BlueprintConfig);
|
|
174
|
+
get opportunities(): OpportunityResource;
|
|
175
|
+
get customers(): CustomerResource;
|
|
176
|
+
get properties(): PropertyResource;
|
|
177
|
+
get calendarEvents(): CalendarEventResource;
|
|
178
|
+
get contracts(): ContractResource;
|
|
179
|
+
get jobs(): JobResource;
|
|
180
|
+
get estimates(): EstimateResource;
|
|
181
|
+
get invoices(): InvoiceResource;
|
|
182
|
+
get inventory(): InventoryResource;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Base error class for all Planes SDK errors.
|
|
187
|
+
*/
|
|
188
|
+
declare class BlueprintError extends Error {
|
|
189
|
+
readonly status: number;
|
|
190
|
+
readonly code: string;
|
|
191
|
+
constructor(message: string, status: number, code: string);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Thrown when authentication fails (401).
|
|
195
|
+
*/
|
|
196
|
+
declare class AuthenticationError extends BlueprintError {
|
|
197
|
+
constructor(message?: string);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Thrown when the user lacks permission (403).
|
|
201
|
+
*/
|
|
202
|
+
declare class AuthorizationError extends BlueprintError {
|
|
203
|
+
constructor(message?: string);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Thrown when a resource is not found (404).
|
|
207
|
+
*/
|
|
208
|
+
declare class NotFoundError extends BlueprintError {
|
|
209
|
+
constructor(message?: string);
|
|
210
|
+
}
|
|
211
|
+
/** Field-level validation error detail. */
|
|
212
|
+
interface FieldError {
|
|
213
|
+
field: string;
|
|
214
|
+
message: string;
|
|
215
|
+
code?: string;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Thrown for validation failures (400) with field-level error details.
|
|
219
|
+
*/
|
|
220
|
+
declare class ValidationError extends BlueprintError {
|
|
221
|
+
readonly fieldErrors: FieldError[];
|
|
222
|
+
constructor(message?: string, fieldErrors?: FieldError[]);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Thrown when rate limited (429). Includes retryAfter in seconds.
|
|
226
|
+
*/
|
|
227
|
+
declare class RateLimitError extends BlueprintError {
|
|
228
|
+
readonly retryAfter: number;
|
|
229
|
+
constructor(retryAfter?: number, message?: string);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Thrown for server errors (500+).
|
|
233
|
+
*/
|
|
234
|
+
declare class ServerError extends BlueprintError {
|
|
235
|
+
constructor(message?: string);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Thrown when webhook signature verification fails.
|
|
239
|
+
*/
|
|
240
|
+
declare class WebhookVerificationError extends BlueprintError {
|
|
241
|
+
constructor(message?: string);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Thrown for OAuth flow errors.
|
|
245
|
+
*/
|
|
246
|
+
declare class OAuthError extends BlueprintError {
|
|
247
|
+
readonly errorCode: string;
|
|
248
|
+
constructor(errorCode: string, message?: string);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* ActionHandler, ActionContext, and ActionResult types for the SDK.
|
|
253
|
+
*
|
|
254
|
+
* These mirror the types in @blueprint/shared/types/agent-execution.ts
|
|
255
|
+
* but are self-contained to avoid requiring @blueprint/shared as a dependency.
|
|
256
|
+
* The SDK is a standalone package for external developers.
|
|
257
|
+
*/
|
|
258
|
+
/** Trigger types for action execution. */
|
|
259
|
+
type TriggerType = 'workflow_transition' | 'schedule' | 'event' | 'agent';
|
|
260
|
+
/** Permission levels (1 = most restricted, 4 = most powerful). */
|
|
261
|
+
type PermissionLevel = 1 | 2 | 3 | 4;
|
|
262
|
+
/**
|
|
263
|
+
* ActionContext envelope — passed to handlers on each invocation.
|
|
264
|
+
*/
|
|
265
|
+
interface ActionContext {
|
|
266
|
+
trigger: {
|
|
267
|
+
type: TriggerType;
|
|
268
|
+
source_id: string;
|
|
269
|
+
triggered_by: string;
|
|
270
|
+
};
|
|
271
|
+
entity: {
|
|
272
|
+
type: string;
|
|
273
|
+
id: string;
|
|
274
|
+
snapshot: Record<string, unknown>;
|
|
275
|
+
};
|
|
276
|
+
action: {
|
|
277
|
+
id: string;
|
|
278
|
+
type: string;
|
|
279
|
+
config: Record<string, unknown>;
|
|
280
|
+
};
|
|
281
|
+
tenant: {
|
|
282
|
+
id: string;
|
|
283
|
+
scope_paths?: string[];
|
|
284
|
+
};
|
|
285
|
+
/** Agent installation ID — set for agent-type actions. */
|
|
286
|
+
agent_installation_id?: string;
|
|
287
|
+
permissions: {
|
|
288
|
+
level: PermissionLevel;
|
|
289
|
+
allowed_actions: string[];
|
|
290
|
+
spending_limit?: number;
|
|
291
|
+
spending_limit_daily?: number;
|
|
292
|
+
requires_approval: string[];
|
|
293
|
+
max_actions_per_execution?: number;
|
|
294
|
+
max_execution_time_ms?: number;
|
|
295
|
+
};
|
|
296
|
+
execution: {
|
|
297
|
+
id: string;
|
|
298
|
+
correlation_id: string;
|
|
299
|
+
attempt: number;
|
|
300
|
+
timeout_ms: number;
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
/** A follow-up action request (used with delegated status). */
|
|
304
|
+
interface ActionRequest {
|
|
305
|
+
action_type: string;
|
|
306
|
+
config: Record<string, unknown>;
|
|
307
|
+
priority?: number;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* ActionResult — the return value from a handler's execute() method.
|
|
311
|
+
*/
|
|
312
|
+
type ActionResult = {
|
|
313
|
+
status: 'completed';
|
|
314
|
+
output?: unknown;
|
|
315
|
+
} | {
|
|
316
|
+
status: 'failed';
|
|
317
|
+
error: string;
|
|
318
|
+
retryable: boolean;
|
|
319
|
+
} | {
|
|
320
|
+
status: 'needs_human';
|
|
321
|
+
reason: string;
|
|
322
|
+
context: unknown;
|
|
323
|
+
} | {
|
|
324
|
+
status: 'delegated';
|
|
325
|
+
follow_up_actions: ActionRequest[];
|
|
326
|
+
};
|
|
327
|
+
/**
|
|
328
|
+
* ActionHandler interface — the core unit of agent logic.
|
|
329
|
+
*/
|
|
330
|
+
interface ActionHandler {
|
|
331
|
+
readonly type: string;
|
|
332
|
+
execute(ctx: ActionContext): Promise<ActionResult>;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Generic typed version of ActionHandler for specific input/output shapes.
|
|
336
|
+
*/
|
|
337
|
+
interface AgentHandler<TInput = Record<string, unknown>, TOutput = unknown> {
|
|
338
|
+
readonly type: string;
|
|
339
|
+
execute(ctx: ActionContext & {
|
|
340
|
+
action: {
|
|
341
|
+
config: TInput;
|
|
342
|
+
};
|
|
343
|
+
}): Promise<{
|
|
344
|
+
status: 'completed';
|
|
345
|
+
output?: TOutput;
|
|
346
|
+
} | {
|
|
347
|
+
status: 'failed';
|
|
348
|
+
error: string;
|
|
349
|
+
retryable: boolean;
|
|
350
|
+
} | {
|
|
351
|
+
status: 'needs_human';
|
|
352
|
+
reason: string;
|
|
353
|
+
context: unknown;
|
|
354
|
+
} | {
|
|
355
|
+
status: 'delegated';
|
|
356
|
+
follow_up_actions: ActionRequest[];
|
|
357
|
+
}>;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Record of action type string to handler — for type-safe handler registration.
|
|
361
|
+
*/
|
|
362
|
+
type HandlerMap = Record<string, ActionHandler>;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Options for Blueprint.register().
|
|
366
|
+
*/
|
|
367
|
+
interface RegisterOptions {
|
|
368
|
+
/** Port to listen on (default 3000). */
|
|
369
|
+
port?: number;
|
|
370
|
+
/** HTTP path to listen on (default '/actions'). */
|
|
371
|
+
path?: string;
|
|
372
|
+
/** Whether to verify incoming request signatures (default true). */
|
|
373
|
+
verifySignature?: boolean;
|
|
374
|
+
/** Error callback for unhandled errors. */
|
|
375
|
+
onError?: (error: Error) => void;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Blueprint agent registration namespace.
|
|
379
|
+
* Provides a convenient way to register action handlers as an HTTP server.
|
|
380
|
+
*/
|
|
381
|
+
declare const Blueprint: {
|
|
382
|
+
/**
|
|
383
|
+
* Register action handlers and start an HTTP server to receive action requests.
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* ```ts
|
|
387
|
+
* Blueprint.register([
|
|
388
|
+
* {
|
|
389
|
+
* type: 'send_email',
|
|
390
|
+
* async execute(ctx) {
|
|
391
|
+
* // ... send email logic
|
|
392
|
+
* return { status: 'completed', output: { sent: true } };
|
|
393
|
+
* },
|
|
394
|
+
* },
|
|
395
|
+
* ], { port: 3000 });
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
register(handlers: ActionHandler[], options?: RegisterOptions): http.Server;
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Typed webhook event payload from Planes.
|
|
403
|
+
*/
|
|
404
|
+
interface WebhookEvent<T = unknown> {
|
|
405
|
+
/** Event ID (e.g. evt_abc123). */
|
|
406
|
+
id: string;
|
|
407
|
+
/** Event type (e.g. opportunity.created). */
|
|
408
|
+
type: string;
|
|
409
|
+
/** Tenant ID that owns this event. */
|
|
410
|
+
tenant_id: string;
|
|
411
|
+
/** ISO 8601 timestamp of when the event occurred. */
|
|
412
|
+
timestamp: string;
|
|
413
|
+
/** Entity snapshot at the time of the event. */
|
|
414
|
+
data: T;
|
|
415
|
+
/** Metadata about the event trigger. */
|
|
416
|
+
metadata: {
|
|
417
|
+
correlation_id: string;
|
|
418
|
+
triggered_by: 'workflow' | 'api' | 'user';
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Verify an HMAC-SHA256 webhook signature using timing-safe comparison.
|
|
423
|
+
*
|
|
424
|
+
* The signature header format is: `sha256=<hex-digest>`
|
|
425
|
+
*
|
|
426
|
+
* @param payload - The raw request body (string or Buffer)
|
|
427
|
+
* @param signature - The X-Blueprint-Signature header value
|
|
428
|
+
* @param secret - The webhook signing secret
|
|
429
|
+
* @returns true if the signature is valid, false otherwise
|
|
430
|
+
*/
|
|
431
|
+
declare function verifyWebhookSignature(payload: string | Buffer, signature: string, secret: string): boolean;
|
|
432
|
+
/**
|
|
433
|
+
* Parse and verify a webhook event payload.
|
|
434
|
+
*
|
|
435
|
+
* @param body - The raw request body as a string
|
|
436
|
+
* @param signature - The X-Blueprint-Signature header value
|
|
437
|
+
* @param secret - The webhook signing secret
|
|
438
|
+
* @returns The parsed and typed webhook event
|
|
439
|
+
* @throws WebhookVerificationError if signature is invalid
|
|
440
|
+
*/
|
|
441
|
+
declare function parseWebhookEvent<T = unknown>(body: string, signature: string, secret: string): WebhookEvent<T>;
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Options for building an OAuth authorization URL.
|
|
445
|
+
*/
|
|
446
|
+
interface AuthorizeOptions {
|
|
447
|
+
/** Planes API base URL (e.g. https://api.planescrm.com/api/v1). */
|
|
448
|
+
baseUrl: string;
|
|
449
|
+
/** OAuth client ID. */
|
|
450
|
+
clientId: string;
|
|
451
|
+
/** Redirect URI after authorization. */
|
|
452
|
+
redirectUri: string;
|
|
453
|
+
/** Requested OAuth scopes. */
|
|
454
|
+
scopes: string[];
|
|
455
|
+
/** CSRF state parameter (auto-generated if not provided). */
|
|
456
|
+
state?: string;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Options for exchanging an authorization code for tokens.
|
|
460
|
+
*/
|
|
461
|
+
interface ExchangeCodeOptions {
|
|
462
|
+
/** Planes API base URL. */
|
|
463
|
+
baseUrl: string;
|
|
464
|
+
/** OAuth client ID. */
|
|
465
|
+
clientId: string;
|
|
466
|
+
/** OAuth client secret. */
|
|
467
|
+
clientSecret: string;
|
|
468
|
+
/** Authorization code from the callback. */
|
|
469
|
+
code: string;
|
|
470
|
+
/** Redirect URI (must match the one used in authorization). */
|
|
471
|
+
redirectUri: string;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Options for refreshing an access token.
|
|
475
|
+
*/
|
|
476
|
+
interface RefreshOptions {
|
|
477
|
+
/** Planes API base URL. */
|
|
478
|
+
baseUrl: string;
|
|
479
|
+
/** OAuth client ID. */
|
|
480
|
+
clientId: string;
|
|
481
|
+
/** OAuth client secret. */
|
|
482
|
+
clientSecret: string;
|
|
483
|
+
/** Refresh token. */
|
|
484
|
+
refreshToken: string;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* OAuth token response.
|
|
488
|
+
*/
|
|
489
|
+
interface TokenResponse {
|
|
490
|
+
access_token: string;
|
|
491
|
+
refresh_token: string;
|
|
492
|
+
expires_in: number;
|
|
493
|
+
token_type: string;
|
|
494
|
+
scope: string;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Build an OAuth authorization URL for the Planes platform.
|
|
498
|
+
*
|
|
499
|
+
* @param options - Authorization options
|
|
500
|
+
* @returns The full authorization URL to redirect the user to
|
|
501
|
+
*/
|
|
502
|
+
declare function buildAuthorizeUrl(options: AuthorizeOptions): string;
|
|
503
|
+
/**
|
|
504
|
+
* Exchange an authorization code for access and refresh tokens.
|
|
505
|
+
*
|
|
506
|
+
* @param options - Exchange options
|
|
507
|
+
* @returns Token response with access_token, refresh_token, etc.
|
|
508
|
+
* @throws OAuthError on failure
|
|
509
|
+
*/
|
|
510
|
+
declare function exchangeCode(options: ExchangeCodeOptions): Promise<TokenResponse>;
|
|
511
|
+
/**
|
|
512
|
+
* Refresh an access token using a refresh token.
|
|
513
|
+
*
|
|
514
|
+
* @param options - Refresh options
|
|
515
|
+
* @returns New token response
|
|
516
|
+
* @throws OAuthError on failure
|
|
517
|
+
*/
|
|
518
|
+
declare function refreshAccessToken(options: RefreshOptions): Promise<TokenResponse>;
|
|
519
|
+
|
|
520
|
+
interface OpportunityDto {
|
|
521
|
+
id: string;
|
|
522
|
+
name: string;
|
|
523
|
+
status: string;
|
|
524
|
+
priority?: 'low' | 'medium' | 'high' | 'urgent';
|
|
525
|
+
customerId?: string;
|
|
526
|
+
createdAt: string;
|
|
527
|
+
updatedAt: string;
|
|
528
|
+
}
|
|
529
|
+
interface CreateOpportunityDto {
|
|
530
|
+
name: string;
|
|
531
|
+
priority?: 'low' | 'medium' | 'high' | 'urgent';
|
|
532
|
+
customerId?: string;
|
|
533
|
+
}
|
|
534
|
+
interface UpdateOpportunityDto {
|
|
535
|
+
name?: string;
|
|
536
|
+
priority?: 'low' | 'medium' | 'high' | 'urgent';
|
|
537
|
+
customerId?: string;
|
|
538
|
+
}
|
|
539
|
+
interface PaginatedOpportunityResponse {
|
|
540
|
+
data: Array<OpportunityDto>;
|
|
541
|
+
meta: PaginationMeta;
|
|
542
|
+
}
|
|
543
|
+
interface CustomerDto {
|
|
544
|
+
id: string;
|
|
545
|
+
firstName: string;
|
|
546
|
+
lastName: string;
|
|
547
|
+
email?: string;
|
|
548
|
+
phone?: string;
|
|
549
|
+
createdAt: string;
|
|
550
|
+
}
|
|
551
|
+
interface CreateCustomerDto {
|
|
552
|
+
firstName: string;
|
|
553
|
+
lastName: string;
|
|
554
|
+
email?: string;
|
|
555
|
+
phone?: string;
|
|
556
|
+
}
|
|
557
|
+
interface PaginatedCustomerResponse {
|
|
558
|
+
data: Array<CustomerDto>;
|
|
559
|
+
meta: PaginationMeta;
|
|
560
|
+
}
|
|
561
|
+
interface PaginationMeta {
|
|
562
|
+
page: number;
|
|
563
|
+
limit: number;
|
|
564
|
+
total: number;
|
|
565
|
+
totalPages: number;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/** Generated resource methods for Opportunities */
|
|
569
|
+
interface OpportunitiesGeneratedResource {
|
|
570
|
+
/** List opportunities with pagination */
|
|
571
|
+
listOpportunities(params?: {
|
|
572
|
+
page?: number;
|
|
573
|
+
limit?: number;
|
|
574
|
+
search?: string;
|
|
575
|
+
}): Promise<PaginatedOpportunityResponse>;
|
|
576
|
+
/** Create a new opportunity */
|
|
577
|
+
createOpportunity(data: CreateOpportunityDto): Promise<OpportunityDto>;
|
|
578
|
+
/** Get opportunity by ID */
|
|
579
|
+
getOpportunity(id: string): Promise<OpportunityDto>;
|
|
580
|
+
/** Update an opportunity */
|
|
581
|
+
updateOpportunity(id: string, data: UpdateOpportunityDto): Promise<OpportunityDto>;
|
|
582
|
+
/** Delete an opportunity */
|
|
583
|
+
deleteOpportunity(id: string): Promise<void>;
|
|
584
|
+
}
|
|
585
|
+
/** Generated resource methods for Customers */
|
|
586
|
+
interface CustomersGeneratedResource {
|
|
587
|
+
/** List customers with pagination */
|
|
588
|
+
listCustomers(params?: {
|
|
589
|
+
page?: number;
|
|
590
|
+
limit?: number;
|
|
591
|
+
}): Promise<PaginatedCustomerResponse>;
|
|
592
|
+
/** Create a new customer */
|
|
593
|
+
createCustomer(data: CreateCustomerDto): Promise<CustomerDto>;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
export { type ActionContext, type ActionHandler, type ActionRequest, type ActionResult, type AgentHandler, AuthenticationError, AuthorizationError, type AuthorizeOptions, BaseResource, Blueprint, BlueprintClient, type BlueprintConfig, BlueprintError, CalendarEventResource, ContractResource, type CreateCustomerDto, type CreateOpportunityDto, type CustomerDto, CustomerResource, type CustomersGeneratedResource, DEFAULT_BASE_URL, DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT, EstimateResource, type ExchangeCodeOptions, type FieldError, type HandlerMap, InventoryResource, InvoiceResource, JobResource, type ListParams, NotFoundError, OAuthError, type OpportunitiesGeneratedResource, type OpportunityDto, OpportunityResource, type PaginatedCustomerResponse, type PaginatedOpportunityResponse, type PaginatedResponse, type PaginationMeta, type PermissionLevel, PropertyResource, RateLimitError, type RefreshOptions, type RegisterOptions, ServerError, type TokenResponse, type TriggerType, type UpdateOpportunityDto, ValidationError, type WebhookEvent, WebhookVerificationError, buildAuthorizeUrl, exchangeCode, parseWebhookEvent, refreshAccessToken, verifyWebhookSignature };
|