@invoiceleaf/integration-sdk 1.0.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.
Files changed (50) hide show
  1. package/README.md +317 -0
  2. package/dist/context/IntegrationContext.d.ts +102 -0
  3. package/dist/context/IntegrationContext.d.ts.map +1 -0
  4. package/dist/context/IntegrationContext.js +2 -0
  5. package/dist/context/IntegrationContext.js.map +1 -0
  6. package/dist/context/index.d.ts +3 -0
  7. package/dist/context/index.d.ts.map +1 -0
  8. package/dist/context/index.js +3 -0
  9. package/dist/context/index.js.map +1 -0
  10. package/dist/context/types.d.ts +109 -0
  11. package/dist/context/types.d.ts.map +1 -0
  12. package/dist/context/types.js +5 -0
  13. package/dist/context/types.js.map +1 -0
  14. package/dist/helpers/defineHandler.d.ts +116 -0
  15. package/dist/helpers/defineHandler.d.ts.map +1 -0
  16. package/dist/helpers/defineHandler.js +42 -0
  17. package/dist/helpers/defineHandler.js.map +1 -0
  18. package/dist/helpers/defineIntegration.d.ts +32 -0
  19. package/dist/helpers/defineIntegration.d.ts.map +1 -0
  20. package/dist/helpers/defineIntegration.js +69 -0
  21. package/dist/helpers/defineIntegration.js.map +1 -0
  22. package/dist/index.d.ts +33 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +36 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/types/actions.d.ts +41 -0
  27. package/dist/types/actions.d.ts.map +1 -0
  28. package/dist/types/actions.js +2 -0
  29. package/dist/types/actions.js.map +1 -0
  30. package/dist/types/index.d.ts +6 -0
  31. package/dist/types/index.d.ts.map +1 -0
  32. package/dist/types/index.js +6 -0
  33. package/dist/types/index.js.map +1 -0
  34. package/dist/types/manifest.d.ts +71 -0
  35. package/dist/types/manifest.d.ts.map +1 -0
  36. package/dist/types/manifest.js +2 -0
  37. package/dist/types/manifest.js.map +1 -0
  38. package/dist/types/schema.d.ts +88 -0
  39. package/dist/types/schema.d.ts.map +1 -0
  40. package/dist/types/schema.js +2 -0
  41. package/dist/types/schema.js.map +1 -0
  42. package/dist/types/triggers.d.ts +54 -0
  43. package/dist/types/triggers.d.ts.map +1 -0
  44. package/dist/types/triggers.js +2 -0
  45. package/dist/types/triggers.js.map +1 -0
  46. package/dist/types/ui.d.ts +180 -0
  47. package/dist/types/ui.d.ts.map +1 -0
  48. package/dist/types/ui.js +2 -0
  49. package/dist/types/ui.js.map +1 -0
  50. package/package.json +54 -0
package/README.md ADDED
@@ -0,0 +1,317 @@
1
+ # @invoiceleaf/integration-sdk
2
+
3
+ SDK for building InvoiceLeaf integrations.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @invoiceleaf/integration-sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import {
15
+ defineIntegration,
16
+ defineHandler,
17
+ IntegrationContext,
18
+ DocumentProcessedInput,
19
+ } from '@invoiceleaf/integration-sdk';
20
+
21
+ // Define your integration manifest
22
+ export const manifest = defineIntegration({
23
+ id: 'my-integration',
24
+ name: 'My Integration',
25
+ version: '1.0.0',
26
+ description: 'A sample integration',
27
+ dataAccess: ['documents', 'companies'],
28
+ triggers: [
29
+ {
30
+ id: 'on-document-processed',
31
+ name: 'On Document Processed',
32
+ type: 'event',
33
+ events: ['document.processed'],
34
+ handler: 'onDocumentProcessed',
35
+ },
36
+ ],
37
+ actions: [
38
+ {
39
+ id: 'sync-documents',
40
+ name: 'Sync Documents',
41
+ handler: 'syncDocuments',
42
+ },
43
+ ],
44
+ });
45
+
46
+ // Define handlers
47
+ export const onDocumentProcessed = defineHandler<DocumentProcessedInput>(
48
+ async (input, context) => {
49
+ context.logger.info('Document processed', { id: input.documentId });
50
+
51
+ const doc = await context.data.getDocument(input.documentId);
52
+ // Process the document...
53
+
54
+ return { success: true };
55
+ }
56
+ );
57
+
58
+ export const syncDocuments = defineHandler(async (input, context) => {
59
+ const documents = await context.data.listDocuments({
60
+ status: 'PROCESSED',
61
+ size: 100,
62
+ });
63
+
64
+ context.logger.info(`Found ${documents.total} documents to sync`);
65
+
66
+ // Sync documents to external service...
67
+
68
+ return { syncedCount: documents.items.length };
69
+ });
70
+ ```
71
+
72
+ ## Trigger Types
73
+
74
+ ### Event Triggers
75
+
76
+ Triggered by InvoiceLeaf events:
77
+
78
+ ```typescript
79
+ {
80
+ id: 'on-document-created',
81
+ type: 'event',
82
+ events: ['document.created', 'document.updated'],
83
+ handler: 'handleDocumentEvent',
84
+ }
85
+ ```
86
+
87
+ Available events:
88
+ - `document.created`
89
+ - `document.updated`
90
+ - `document.processed`
91
+ - `document.deleted`
92
+ - `company.created`
93
+ - `company.updated`
94
+ - `export.completed`
95
+
96
+ ### Schedule Triggers
97
+
98
+ Triggered on a schedule (cron):
99
+
100
+ ```typescript
101
+ {
102
+ id: 'daily-sync',
103
+ type: 'schedule',
104
+ schedule: '0 2 * * *', // 2 AM daily
105
+ handler: 'dailySync',
106
+ }
107
+ ```
108
+
109
+ ### Webhook Triggers
110
+
111
+ Triggered by external services:
112
+
113
+ ```typescript
114
+ {
115
+ id: 'stripe-webhook',
116
+ type: 'webhook',
117
+ webhook: {
118
+ methods: ['POST'],
119
+ signature: {
120
+ header: 'stripe-signature',
121
+ algorithm: 'hmac-sha256',
122
+ secretConfigKey: 'stripeWebhookSecret',
123
+ },
124
+ },
125
+ handler: 'handleStripeWebhook',
126
+ }
127
+ ```
128
+
129
+ ### User Action Triggers
130
+
131
+ Triggered by user clicks:
132
+
133
+ ```typescript
134
+ {
135
+ id: 'export-to-datev',
136
+ type: 'user_action',
137
+ userAction: {
138
+ label: 'Export to DATEV',
139
+ icon: '📤',
140
+ placement: ['document-list', 'toolbar'],
141
+ confirmMessage: 'Export selected documents to DATEV?',
142
+ },
143
+ handler: 'exportToDATEV',
144
+ }
145
+ ```
146
+
147
+ ## External Authentication
148
+
149
+ ### OAuth2
150
+
151
+ ```typescript
152
+ externalAuth: [
153
+ {
154
+ provider: 'google',
155
+ name: 'Google Drive',
156
+ type: 'oauth2',
157
+ oauth: {
158
+ authorizeUrl: 'https://accounts.google.com/o/oauth2/v2/auth',
159
+ tokenUrl: 'https://oauth2.googleapis.com/token',
160
+ scopes: ['https://www.googleapis.com/auth/drive.file'],
161
+ },
162
+ },
163
+ ],
164
+ ```
165
+
166
+ Usage in handler:
167
+
168
+ ```typescript
169
+ const accessToken = await context.credentials.getAccessToken('google');
170
+ ```
171
+
172
+ ### API Key
173
+
174
+ ```typescript
175
+ externalAuth: [
176
+ {
177
+ provider: 'openai',
178
+ name: 'OpenAI',
179
+ type: 'api_key',
180
+ apiKey: {
181
+ headerName: 'Authorization',
182
+ prefix: 'Bearer ',
183
+ instructions: 'Get your API key from https://platform.openai.com',
184
+ },
185
+ },
186
+ ],
187
+ ```
188
+
189
+ Usage in handler:
190
+
191
+ ```typescript
192
+ const apiKey = await context.credentials.getApiKey('openai');
193
+ ```
194
+
195
+ ## Custom UI Pages
196
+
197
+ Define custom dashboard pages:
198
+
199
+ ```typescript
200
+ pages: [
201
+ {
202
+ id: 'dashboard',
203
+ name: 'Dashboard',
204
+ route: '/dashboard',
205
+ dataSource: 'getDashboardData',
206
+ layout: {
207
+ type: 'dashboard',
208
+ widgets: [
209
+ {
210
+ type: 'metric',
211
+ title: 'Documents Synced',
212
+ value: '{{syncedCount}}',
213
+ format: 'number',
214
+ trend: { direction: 'up', value: 12 },
215
+ },
216
+ {
217
+ type: 'chart',
218
+ title: 'Sync History',
219
+ chartType: 'line',
220
+ dataSource: '{{syncHistory}}',
221
+ xField: 'date',
222
+ yField: 'count',
223
+ },
224
+ {
225
+ type: 'actionButton',
226
+ label: 'Sync Now',
227
+ actionId: 'sync-documents',
228
+ variant: 'primary',
229
+ },
230
+ ],
231
+ },
232
+ },
233
+ ],
234
+ ```
235
+
236
+ ## User Configuration
237
+
238
+ Define configuration options:
239
+
240
+ ```typescript
241
+ configSchema: {
242
+ type: 'object',
243
+ properties: {
244
+ syncEnabled: {
245
+ type: 'boolean',
246
+ title: 'Enable Auto-Sync',
247
+ default: true,
248
+ },
249
+ syncInterval: {
250
+ type: 'string',
251
+ title: 'Sync Interval',
252
+ enum: ['hourly', 'daily', 'weekly'],
253
+ default: 'daily',
254
+ },
255
+ apiEndpoint: {
256
+ type: 'string',
257
+ title: 'API Endpoint',
258
+ format: 'uri',
259
+ },
260
+ },
261
+ required: ['syncEnabled'],
262
+ },
263
+ ```
264
+
265
+ Access in handler:
266
+
267
+ ```typescript
268
+ const syncEnabled = context.config.syncEnabled as boolean;
269
+ ```
270
+
271
+ ## API Reference
272
+
273
+ ### IntegrationContext
274
+
275
+ | Property | Type | Description |
276
+ |----------|------|-------------|
277
+ | `spaceId` | `string` | Current space ID |
278
+ | `userId` | `string` | User who triggered execution |
279
+ | `installationId` | `string` | Installation ID |
280
+ | `config` | `Record<string, unknown>` | User configuration |
281
+ | `data` | `DataClient` | Data access client |
282
+ | `credentials` | `CredentialsClient` | Credential client |
283
+ | `logger` | `Logger` | Structured logger |
284
+
285
+ ### DataClient
286
+
287
+ | Method | Description |
288
+ |--------|-------------|
289
+ | `listDocuments(params?)` | List documents with filters |
290
+ | `getDocument(id)` | Get document by ID |
291
+ | `listCompanies(params?)` | List companies |
292
+ | `getCompany(id)` | Get company by ID |
293
+ | `listCategories()` | List all categories |
294
+ | `listTags()` | List all tags |
295
+ | `createExport(params)` | Create export job |
296
+ | `getExport(id)` | Get export status |
297
+
298
+ ### CredentialsClient
299
+
300
+ | Method | Description |
301
+ |--------|-------------|
302
+ | `getAccessToken(provider)` | Get OAuth access token |
303
+ | `getApiKey(provider)` | Get API key |
304
+ | `refreshToken(provider)` | Force token refresh |
305
+
306
+ ### Logger
307
+
308
+ | Method | Description |
309
+ |--------|-------------|
310
+ | `debug(message, data?)` | Debug log |
311
+ | `info(message, data?)` | Info log |
312
+ | `warn(message, data?)` | Warning log |
313
+ | `error(message, data?)` | Error log |
314
+
315
+ ## License
316
+
317
+ MIT
@@ -0,0 +1,102 @@
1
+ import type { Document, Company, Category, Tag, Export, DocumentListParams, ListParams, ListResult } from './types.js';
2
+ /**
3
+ * Integration Context - the main interface for plugins to interact with InvoiceLeaf.
4
+ *
5
+ * This context is automatically injected when your handler function is called.
6
+ * It provides access to:
7
+ * - InvoiceLeaf data (documents, companies, categories, tags)
8
+ * - External service credentials (OAuth tokens, API keys)
9
+ * - Structured logging
10
+ * - User-provided configuration
11
+ */
12
+ export interface IntegrationContext {
13
+ /** Current space ID */
14
+ readonly spaceId: string;
15
+ /** Current user ID (who triggered the execution) */
16
+ readonly userId: string;
17
+ /** Installation ID */
18
+ readonly installationId: string;
19
+ /** User-provided configuration */
20
+ readonly config: Record<string, unknown>;
21
+ /** Data access client */
22
+ readonly data: DataClient;
23
+ /** Credential access client */
24
+ readonly credentials: CredentialsClient;
25
+ /** Structured logger */
26
+ readonly logger: Logger;
27
+ }
28
+ /**
29
+ * Client for accessing InvoiceLeaf data.
30
+ * All operations are scoped to the current space.
31
+ */
32
+ export interface DataClient {
33
+ /**
34
+ * List documents with optional filters.
35
+ */
36
+ listDocuments(params?: DocumentListParams): Promise<ListResult<Document>>;
37
+ /**
38
+ * Get a document by ID.
39
+ */
40
+ getDocument(id: string): Promise<Document>;
41
+ /**
42
+ * List companies.
43
+ */
44
+ listCompanies(params?: ListParams): Promise<ListResult<Company>>;
45
+ /**
46
+ * Get a company by ID.
47
+ */
48
+ getCompany(id: string): Promise<Company>;
49
+ /**
50
+ * List all categories.
51
+ */
52
+ listCategories(): Promise<Category[]>;
53
+ /**
54
+ * Get a category by ID.
55
+ */
56
+ getCategory(id: string): Promise<Category>;
57
+ /**
58
+ * List all tags.
59
+ */
60
+ listTags(): Promise<Tag[]>;
61
+ /**
62
+ * Create an export job.
63
+ */
64
+ createExport(params: {
65
+ format: string;
66
+ documentIds?: string[];
67
+ filters?: DocumentListParams;
68
+ }): Promise<Export>;
69
+ /**
70
+ * Get export status by ID.
71
+ */
72
+ getExport(id: string): Promise<Export>;
73
+ }
74
+ /**
75
+ * Client for accessing external service credentials.
76
+ */
77
+ export interface CredentialsClient {
78
+ /**
79
+ * Get OAuth2 access token for a provider.
80
+ * Automatically refreshes if expired.
81
+ */
82
+ getAccessToken(provider: string): Promise<string>;
83
+ /**
84
+ * Get API key for a provider.
85
+ */
86
+ getApiKey(provider: string): Promise<string>;
87
+ /**
88
+ * Force refresh OAuth2 token.
89
+ */
90
+ refreshToken(provider: string): Promise<string>;
91
+ }
92
+ /**
93
+ * Structured logger for execution.
94
+ */
95
+ export interface Logger {
96
+ debug(message: string, data?: unknown): void;
97
+ info(message: string, data?: unknown): void;
98
+ warn(message: string, data?: unknown): void;
99
+ error(message: string, data?: unknown): void;
100
+ }
101
+ export type { Document, Company, Category, Tag, Export, DocumentListParams, ListParams, ListResult, } from './types.js';
102
+ //# sourceMappingURL=IntegrationContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntegrationContext.d.ts","sourceRoot":"","sources":["../../src/context/IntegrationContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,GAAG,EACH,MAAM,EACN,kBAAkB,EAClB,UAAU,EACV,UAAU,EACX,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;GASG;AACH,MAAM,WAAW,kBAAkB;IACjC,uBAAuB;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,sBAAsB;IACtB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAEhC,kCAAkC;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEzC,yBAAyB;IACzB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAE1B,+BAA+B;IAC/B,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAC;IAExC,wBAAwB;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;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ACjD;AAED;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC5C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC5C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC9C;AAGD,YAAY,EACV,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,GAAG,EACH,MAAM,EACN,kBAAkB,EAClB,UAAU,EACV,UAAU,GACX,MAAM,YAAY,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IntegrationContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntegrationContext.js","sourceRoot":"","sources":["../../src/context/IntegrationContext.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export * from './IntegrationContext.js';
2
+ export * from './types.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,YAAY,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './IntegrationContext.js';
2
+ export * from './types.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,YAAY,CAAC"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Types for the Integration Context API.
3
+ */
4
+ export interface Document {
5
+ id: string;
6
+ spaceId: string;
7
+ status: DocumentStatus;
8
+ fileName: string;
9
+ mimeType: string;
10
+ fileSize: number;
11
+ pageCount?: number;
12
+ companyId?: string;
13
+ company?: Company;
14
+ categoryId?: string;
15
+ category?: Category;
16
+ tags?: Tag[];
17
+ invoiceNumber?: string;
18
+ invoiceDate?: string;
19
+ dueDate?: string;
20
+ subtotal?: number;
21
+ taxAmount?: number;
22
+ totalAmount?: number;
23
+ currency?: string;
24
+ paymentStatus?: PaymentStatus;
25
+ notes?: string;
26
+ metadata?: Record<string, unknown>;
27
+ createdAt: string;
28
+ updatedAt: string;
29
+ }
30
+ export type DocumentStatus = 'UPLOADING' | 'UPLOADED' | 'PROCESSING' | 'PROCESSED' | 'FAILED' | 'ARCHIVED';
31
+ export type PaymentStatus = 'UNPAID' | 'PARTIAL' | 'PAID' | 'OVERDUE';
32
+ export interface Company {
33
+ id: string;
34
+ spaceId: string;
35
+ name: string;
36
+ displayName?: string;
37
+ taxId?: string;
38
+ email?: string;
39
+ phone?: string;
40
+ website?: string;
41
+ address?: Address;
42
+ metadata?: Record<string, unknown>;
43
+ createdAt: string;
44
+ updatedAt: string;
45
+ }
46
+ export interface Address {
47
+ street?: string;
48
+ city?: string;
49
+ state?: string;
50
+ postalCode?: string;
51
+ country?: string;
52
+ }
53
+ export interface Category {
54
+ id: string;
55
+ spaceId: string;
56
+ name: string;
57
+ color?: string;
58
+ icon?: string;
59
+ parentId?: string;
60
+ documentCount?: number;
61
+ createdAt: string;
62
+ updatedAt: string;
63
+ }
64
+ export interface Tag {
65
+ id: string;
66
+ spaceId: string;
67
+ name: string;
68
+ color?: string;
69
+ documentCount?: number;
70
+ createdAt: string;
71
+ updatedAt: string;
72
+ }
73
+ export interface Export {
74
+ id: string;
75
+ spaceId: string;
76
+ format: string;
77
+ status: ExportStatus;
78
+ fileName?: string;
79
+ fileSize?: number;
80
+ downloadUrl?: string;
81
+ expiresAt?: string;
82
+ documentCount?: number;
83
+ createdAt: string;
84
+ completedAt?: string;
85
+ }
86
+ export type ExportStatus = 'PENDING' | 'PROCESSING' | 'COMPLETED' | 'FAILED';
87
+ export interface ListParams {
88
+ page?: number;
89
+ size?: number;
90
+ sortBy?: string;
91
+ sortDirection?: 'asc' | 'desc';
92
+ }
93
+ export interface DocumentListParams extends ListParams {
94
+ status?: DocumentStatus;
95
+ companyId?: string;
96
+ categoryId?: string;
97
+ tagIds?: string[];
98
+ fromDate?: string;
99
+ toDate?: string;
100
+ search?: string;
101
+ }
102
+ export interface ListResult<T> {
103
+ items: T[];
104
+ total: number;
105
+ page: number;
106
+ size: number;
107
+ hasMore: boolean;
108
+ }
109
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/context/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,cAAc,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACb,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,KAAK,CAAC,EAAE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AE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;CAClB"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Types for the Integration Context API.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/context/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,116 @@
1
+ import type { IntegrationContext } from '../context/IntegrationContext.js';
2
+ /**
3
+ * Handler function type.
4
+ */
5
+ export type HandlerFunction<TInput = unknown, TOutput = unknown> = (input: TInput, context: IntegrationContext) => Promise<TOutput>;
6
+ /**
7
+ * Helper function to define a handler with type safety.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * interface ExportInput {
12
+ * fromDate: string;
13
+ * toDate: string;
14
+ * format: 'csv' | 'xml';
15
+ * }
16
+ *
17
+ * interface ExportOutput {
18
+ * exportId: string;
19
+ * documentCount: number;
20
+ * }
21
+ *
22
+ * export const exportToDATEV = defineHandler<ExportInput, ExportOutput>(
23
+ * async (input, context) => {
24
+ * context.logger.info('Starting export', { fromDate: input.fromDate });
25
+ *
26
+ * const documents = await context.data.listDocuments({
27
+ * fromDate: input.fromDate,
28
+ * toDate: input.toDate,
29
+ * });
30
+ *
31
+ * const exportResult = await context.data.createExport({
32
+ * format: input.format,
33
+ * documentIds: documents.items.map(d => d.id),
34
+ * });
35
+ *
36
+ * return {
37
+ * exportId: exportResult.id,
38
+ * documentCount: documents.items.length,
39
+ * };
40
+ * }
41
+ * );
42
+ * ```
43
+ */
44
+ export declare function defineHandler<TInput = unknown, TOutput = unknown>(handler: HandlerFunction<TInput, TOutput>): HandlerFunction<TInput, TOutput>;
45
+ /**
46
+ * Event handler input types for built-in events.
47
+ */
48
+ export interface DocumentCreatedInput {
49
+ documentId: string;
50
+ document: {
51
+ id: string;
52
+ fileName: string;
53
+ status: string;
54
+ companyId?: string;
55
+ categoryId?: string;
56
+ };
57
+ }
58
+ export interface DocumentUpdatedInput {
59
+ documentId: string;
60
+ document: {
61
+ id: string;
62
+ fileName: string;
63
+ status: string;
64
+ };
65
+ changes: string[];
66
+ }
67
+ export interface DocumentProcessedInput {
68
+ documentId: string;
69
+ document: {
70
+ id: string;
71
+ fileName: string;
72
+ status: string;
73
+ invoiceNumber?: string;
74
+ totalAmount?: number;
75
+ currency?: string;
76
+ };
77
+ }
78
+ export interface DocumentDeletedInput {
79
+ documentId: string;
80
+ }
81
+ export interface CompanyCreatedInput {
82
+ companyId: string;
83
+ company: {
84
+ id: string;
85
+ name: string;
86
+ taxId?: string;
87
+ };
88
+ }
89
+ export interface ExportCompletedInput {
90
+ exportId: string;
91
+ export: {
92
+ id: string;
93
+ format: string;
94
+ status: string;
95
+ downloadUrl?: string;
96
+ documentCount?: number;
97
+ };
98
+ }
99
+ export interface WebhookInput {
100
+ headers: Record<string, string>;
101
+ body: unknown;
102
+ query: Record<string, string>;
103
+ method: string;
104
+ path: string;
105
+ }
106
+ export interface ScheduleInput {
107
+ scheduledTime: string;
108
+ lastRunTime?: string;
109
+ }
110
+ export interface UserActionInput {
111
+ actionId: string;
112
+ targetId?: string;
113
+ targetType?: 'document' | 'company' | 'export';
114
+ selectedIds?: string[];
115
+ }
116
+ //# sourceMappingURL=defineHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defineHandler.d.ts","sourceRoot":"","sources":["../../src/helpers/defineHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAE3E;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,MAAM,GAAG,OAAO,EAAE,OA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