n8n-nodes-lemonsqueezy 0.4.0 → 0.6.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.
@@ -0,0 +1,99 @@
1
+ import type { INodeProperties } from 'n8n-workflow';
2
+ /**
3
+ * Shared field definitions for advanced query options
4
+ * Used across multiple resources for consistent sorting and relationship expansion
5
+ *
6
+ * This module reduces code duplication by providing reusable field definitions
7
+ * for common patterns like pagination (returnAll, limit), sorting, and filtering.
8
+ */
9
+ /**
10
+ * Creates a 'Return All' toggle field for a resource
11
+ * @param resource - The resource name (e.g., 'product', 'order')
12
+ * @param operations - Operations where this field applies (default: ['getAll'])
13
+ */
14
+ export declare function createReturnAllField(resource: string, operations?: string[]): INodeProperties;
15
+ /**
16
+ * Creates a 'Limit' number field for a resource
17
+ * @param resource - The resource name
18
+ * @param operations - Operations where this field applies
19
+ */
20
+ export declare function createLimitField(resource: string, operations?: string[]): INodeProperties;
21
+ /**
22
+ * Creates a resource ID field
23
+ * @param resource - The resource name
24
+ * @param idName - The parameter name for the ID (e.g., 'productId')
25
+ * @param displayName - Display name shown in UI
26
+ * @param operations - Operations where this field applies
27
+ */
28
+ export declare function createIdField(resource: string, idName: string, displayName: string, operations?: string[]): INodeProperties;
29
+ /**
30
+ * Sort direction options for API queries
31
+ */
32
+ export declare const SORT_DIRECTIONS: {
33
+ name: string;
34
+ value: string;
35
+ }[];
36
+ /**
37
+ * Common sortable fields across resources
38
+ */
39
+ export declare const COMMON_SORT_FIELDS: {
40
+ name: string;
41
+ value: string;
42
+ }[];
43
+ /**
44
+ * Resource-specific includable relationships
45
+ */
46
+ export declare const RESOURCE_INCLUDES: Record<string, Array<{
47
+ name: string;
48
+ value: string;
49
+ }>>;
50
+ /**
51
+ * Creates a filters collection field for a resource
52
+ * @param resource - The resource name
53
+ * @param filterOptions - Array of filter field definitions
54
+ * @param operations - Operations where this field applies
55
+ */
56
+ export declare function createFiltersField(resource: string, filterOptions: INodeProperties['options'], operations?: string[]): INodeProperties;
57
+ /**
58
+ * Common filter field: Store ID
59
+ */
60
+ export declare const storeIdFilter: INodeProperties;
61
+ /**
62
+ * Common filter field: Status (generic)
63
+ */
64
+ export declare function createStatusFilter(statusOptions: Array<{
65
+ name: string;
66
+ value: string;
67
+ }>): INodeProperties;
68
+ /**
69
+ * Common filter field: Email
70
+ */
71
+ export declare const emailFilter: INodeProperties;
72
+ /**
73
+ * Common filter field: Product ID
74
+ */
75
+ export declare const productIdFilter: INodeProperties;
76
+ /**
77
+ * Common filter field: Variant ID
78
+ */
79
+ export declare const variantIdFilter: INodeProperties;
80
+ /**
81
+ * Common filter field: Order ID
82
+ */
83
+ export declare const orderIdFilter: INodeProperties;
84
+ /**
85
+ * Generate advanced options field for a specific resource
86
+ * Includes sorting, relationship expansion, and pagination timeout
87
+ */
88
+ export declare function createAdvancedOptionsField(resource: string, operations?: string[]): INodeProperties;
89
+ /**
90
+ * Pre-built advanced options fields for each resource
91
+ */
92
+ export declare const orderAdvancedOptions: INodeProperties;
93
+ export declare const subscriptionAdvancedOptions: INodeProperties;
94
+ export declare const customerAdvancedOptions: INodeProperties;
95
+ export declare const licenseKeyAdvancedOptions: INodeProperties;
96
+ export declare const productAdvancedOptions: INodeProperties;
97
+ export declare const variantAdvancedOptions: INodeProperties;
98
+ export declare const checkoutAdvancedOptions: INodeProperties;
99
+ export declare const discountAdvancedOptions: INodeProperties;
@@ -0,0 +1,289 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.discountAdvancedOptions = exports.checkoutAdvancedOptions = exports.variantAdvancedOptions = exports.productAdvancedOptions = exports.licenseKeyAdvancedOptions = exports.customerAdvancedOptions = exports.subscriptionAdvancedOptions = exports.orderAdvancedOptions = exports.orderIdFilter = exports.variantIdFilter = exports.productIdFilter = exports.emailFilter = exports.storeIdFilter = exports.RESOURCE_INCLUDES = exports.COMMON_SORT_FIELDS = exports.SORT_DIRECTIONS = void 0;
4
+ exports.createReturnAllField = createReturnAllField;
5
+ exports.createLimitField = createLimitField;
6
+ exports.createIdField = createIdField;
7
+ exports.createFiltersField = createFiltersField;
8
+ exports.createStatusFilter = createStatusFilter;
9
+ exports.createAdvancedOptionsField = createAdvancedOptionsField;
10
+ /**
11
+ * Shared field definitions for advanced query options
12
+ * Used across multiple resources for consistent sorting and relationship expansion
13
+ *
14
+ * This module reduces code duplication by providing reusable field definitions
15
+ * for common patterns like pagination (returnAll, limit), sorting, and filtering.
16
+ */
17
+ // ============================================================================
18
+ // Common Field Generators
19
+ // ============================================================================
20
+ /**
21
+ * Creates a 'Return All' toggle field for a resource
22
+ * @param resource - The resource name (e.g., 'product', 'order')
23
+ * @param operations - Operations where this field applies (default: ['getAll'])
24
+ */
25
+ function createReturnAllField(resource, operations = ['getAll']) {
26
+ return {
27
+ displayName: 'Return All',
28
+ name: 'returnAll',
29
+ type: 'boolean',
30
+ default: false,
31
+ description: 'Whether to return all results or only up to a given limit',
32
+ displayOptions: {
33
+ show: { resource: [resource], operation: operations },
34
+ },
35
+ };
36
+ }
37
+ /**
38
+ * Creates a 'Limit' number field for a resource
39
+ * @param resource - The resource name
40
+ * @param operations - Operations where this field applies
41
+ */
42
+ function createLimitField(resource, operations = ['getAll']) {
43
+ return {
44
+ displayName: 'Limit',
45
+ name: 'limit',
46
+ type: 'number',
47
+ default: 50,
48
+ description: 'Max number of results to return',
49
+ typeOptions: { minValue: 1, maxValue: 100 },
50
+ displayOptions: {
51
+ show: { resource: [resource], operation: operations, returnAll: [false] },
52
+ },
53
+ };
54
+ }
55
+ /**
56
+ * Creates a resource ID field
57
+ * @param resource - The resource name
58
+ * @param idName - The parameter name for the ID (e.g., 'productId')
59
+ * @param displayName - Display name shown in UI
60
+ * @param operations - Operations where this field applies
61
+ */
62
+ function createIdField(resource, idName, displayName, operations = ['get', 'delete']) {
63
+ return {
64
+ displayName,
65
+ name: idName,
66
+ type: 'string',
67
+ required: true,
68
+ default: '',
69
+ description: `The ID of the ${resource}`,
70
+ displayOptions: {
71
+ show: { resource: [resource], operation: operations },
72
+ },
73
+ };
74
+ }
75
+ // ============================================================================
76
+ // Sort Options
77
+ // ============================================================================
78
+ /**
79
+ * Sort direction options for API queries
80
+ */
81
+ exports.SORT_DIRECTIONS = [
82
+ { name: 'Ascending', value: 'asc' },
83
+ { name: 'Descending', value: 'desc' },
84
+ ];
85
+ /**
86
+ * Common sortable fields across resources
87
+ */
88
+ exports.COMMON_SORT_FIELDS = [
89
+ { name: 'Created At', value: 'created_at' },
90
+ { name: 'Updated At', value: 'updated_at' },
91
+ ];
92
+ /**
93
+ * Resource-specific includable relationships
94
+ */
95
+ exports.RESOURCE_INCLUDES = {
96
+ order: [
97
+ { name: 'Store', value: 'store' },
98
+ { name: 'Customer', value: 'customer' },
99
+ { name: 'Order Items', value: 'order-items' },
100
+ { name: 'Subscriptions', value: 'subscriptions' },
101
+ { name: 'License Keys', value: 'license-keys' },
102
+ { name: 'Discount Redemptions', value: 'discount-redemptions' },
103
+ ],
104
+ subscription: [
105
+ { name: 'Store', value: 'store' },
106
+ { name: 'Customer', value: 'customer' },
107
+ { name: 'Order', value: 'order' },
108
+ { name: 'Order Item', value: 'order-item' },
109
+ { name: 'Product', value: 'product' },
110
+ { name: 'Variant', value: 'variant' },
111
+ ],
112
+ customer: [
113
+ { name: 'Store', value: 'store' },
114
+ { name: 'Orders', value: 'orders' },
115
+ { name: 'Subscriptions', value: 'subscriptions' },
116
+ { name: 'License Keys', value: 'license-keys' },
117
+ ],
118
+ licenseKey: [
119
+ { name: 'Store', value: 'store' },
120
+ { name: 'Customer', value: 'customer' },
121
+ { name: 'Order', value: 'order' },
122
+ { name: 'Order Item', value: 'order-item' },
123
+ { name: 'Product', value: 'product' },
124
+ { name: 'License Key Instances', value: 'license-key-instances' },
125
+ ],
126
+ product: [
127
+ { name: 'Store', value: 'store' },
128
+ { name: 'Variants', value: 'variants' },
129
+ ],
130
+ variant: [
131
+ { name: 'Product', value: 'product' },
132
+ { name: 'Files', value: 'files' },
133
+ ],
134
+ checkout: [
135
+ { name: 'Store', value: 'store' },
136
+ { name: 'Variant', value: 'variant' },
137
+ ],
138
+ discount: [
139
+ { name: 'Store', value: 'store' },
140
+ { name: 'Discount Redemptions', value: 'discount-redemptions' },
141
+ ],
142
+ };
143
+ /**
144
+ * Creates a filters collection field for a resource
145
+ * @param resource - The resource name
146
+ * @param filterOptions - Array of filter field definitions
147
+ * @param operations - Operations where this field applies
148
+ */
149
+ function createFiltersField(resource, filterOptions, operations = ['getAll']) {
150
+ return {
151
+ displayName: 'Filters',
152
+ name: 'filters',
153
+ type: 'collection',
154
+ placeholder: 'Add Filter',
155
+ default: {},
156
+ displayOptions: {
157
+ show: { resource: [resource], operation: operations },
158
+ },
159
+ options: filterOptions,
160
+ };
161
+ }
162
+ /**
163
+ * Common filter field: Store ID
164
+ */
165
+ exports.storeIdFilter = {
166
+ displayName: 'Store ID',
167
+ name: 'storeId',
168
+ type: 'string',
169
+ default: '',
170
+ description: 'Filter by store ID',
171
+ };
172
+ /**
173
+ * Common filter field: Status (generic)
174
+ */
175
+ function createStatusFilter(statusOptions) {
176
+ return {
177
+ displayName: 'Status',
178
+ name: 'status',
179
+ type: 'options',
180
+ options: statusOptions,
181
+ default: '',
182
+ description: 'Filter by status',
183
+ };
184
+ }
185
+ /**
186
+ * Common filter field: Email
187
+ */
188
+ exports.emailFilter = {
189
+ displayName: 'Email',
190
+ name: 'email',
191
+ type: 'string',
192
+ default: '',
193
+ description: 'Filter by email address',
194
+ };
195
+ /**
196
+ * Common filter field: Product ID
197
+ */
198
+ exports.productIdFilter = {
199
+ displayName: 'Product ID',
200
+ name: 'productId',
201
+ type: 'string',
202
+ default: '',
203
+ description: 'Filter by product ID',
204
+ };
205
+ /**
206
+ * Common filter field: Variant ID
207
+ */
208
+ exports.variantIdFilter = {
209
+ displayName: 'Variant ID',
210
+ name: 'variantId',
211
+ type: 'string',
212
+ default: '',
213
+ description: 'Filter by variant ID',
214
+ };
215
+ /**
216
+ * Common filter field: Order ID
217
+ */
218
+ exports.orderIdFilter = {
219
+ displayName: 'Order ID',
220
+ name: 'orderId',
221
+ type: 'string',
222
+ default: '',
223
+ description: 'Filter by order ID',
224
+ };
225
+ /**
226
+ * Generate advanced options field for a specific resource
227
+ * Includes sorting, relationship expansion, and pagination timeout
228
+ */
229
+ function createAdvancedOptionsField(resource, operations = ['getAll']) {
230
+ const includes = exports.RESOURCE_INCLUDES[resource] || [];
231
+ const options = [
232
+ {
233
+ displayName: 'Sort Field',
234
+ name: 'sortField',
235
+ type: 'options',
236
+ options: exports.COMMON_SORT_FIELDS,
237
+ default: '',
238
+ description: 'Field to sort results by',
239
+ },
240
+ {
241
+ displayName: 'Sort Direction',
242
+ name: 'sortDirection',
243
+ type: 'options',
244
+ options: exports.SORT_DIRECTIONS,
245
+ default: 'desc',
246
+ description: 'Direction to sort results',
247
+ },
248
+ {
249
+ displayName: 'Pagination Timeout (Seconds)',
250
+ name: 'paginationTimeout',
251
+ type: 'number',
252
+ default: 300,
253
+ description: 'Maximum time in seconds to wait for paginated results when using Return All. Set to 0 for no timeout.',
254
+ typeOptions: { minValue: 0, maxValue: 600 },
255
+ },
256
+ ];
257
+ if (includes.length > 0) {
258
+ options.push({
259
+ displayName: 'Include Related',
260
+ name: 'include',
261
+ type: 'multiOptions',
262
+ options: includes,
263
+ default: [],
264
+ description: 'Related resources to include in the response',
265
+ });
266
+ }
267
+ return {
268
+ displayName: 'Advanced Options',
269
+ name: 'advancedOptions',
270
+ type: 'collection',
271
+ placeholder: 'Add Option',
272
+ default: {},
273
+ displayOptions: {
274
+ show: { resource: [resource], operation: operations },
275
+ },
276
+ options,
277
+ };
278
+ }
279
+ /**
280
+ * Pre-built advanced options fields for each resource
281
+ */
282
+ exports.orderAdvancedOptions = createAdvancedOptionsField('order');
283
+ exports.subscriptionAdvancedOptions = createAdvancedOptionsField('subscription');
284
+ exports.customerAdvancedOptions = createAdvancedOptionsField('customer');
285
+ exports.licenseKeyAdvancedOptions = createAdvancedOptionsField('licenseKey');
286
+ exports.productAdvancedOptions = createAdvancedOptionsField('product');
287
+ exports.variantAdvancedOptions = createAdvancedOptionsField('variant');
288
+ exports.checkoutAdvancedOptions = createAdvancedOptionsField('checkout');
289
+ exports.discountAdvancedOptions = createAdvancedOptionsField('discount');
@@ -344,15 +344,71 @@ export type LicenseKeyInstance = JsonApiResource<'license-key-instances', Licens
344
344
  */
345
345
  export type WebhookEventType = 'order_created' | 'order_refunded' | 'subscription_created' | 'subscription_updated' | 'subscription_cancelled' | 'subscription_resumed' | 'subscription_expired' | 'subscription_paused' | 'subscription_unpaused' | 'subscription_payment_success' | 'subscription_payment_failed' | 'subscription_payment_recovered' | 'subscription_payment_refunded' | 'license_key_created' | 'license_key_updated';
346
346
  /**
347
- * Webhook payload
347
+ * Webhook payload received from Lemon Squeezy
348
348
  */
349
- export interface WebhookPayload {
350
- meta: {
351
- event_name: WebhookEventType;
352
- custom_data?: IDataObject;
353
- test_mode: boolean;
349
+ export interface WebhookPayload<T = IDataObject> {
350
+ meta: WebhookMeta;
351
+ data: T;
352
+ }
353
+ /**
354
+ * Webhook metadata
355
+ */
356
+ export interface WebhookMeta {
357
+ event_name: WebhookEventType;
358
+ custom_data?: IDataObject;
359
+ test_mode: boolean;
360
+ webhook_id?: string;
361
+ }
362
+ /**
363
+ * API Error response structure
364
+ */
365
+ export interface ApiError {
366
+ errors: ApiErrorDetail[];
367
+ }
368
+ /**
369
+ * Individual API error detail
370
+ */
371
+ export interface ApiErrorDetail {
372
+ detail: string;
373
+ title?: string;
374
+ status?: string;
375
+ source?: {
376
+ pointer?: string;
377
+ parameter?: string;
354
378
  };
355
- data: IDataObject;
379
+ }
380
+ /**
381
+ * Pagination metadata from API responses
382
+ */
383
+ export interface PaginationMeta {
384
+ page: {
385
+ currentPage: number;
386
+ from: number;
387
+ lastPage: number;
388
+ perPage: number;
389
+ to: number;
390
+ total: number;
391
+ };
392
+ }
393
+ /**
394
+ * Pagination links from API responses
395
+ */
396
+ export interface PaginationLinks {
397
+ first?: string;
398
+ last?: string;
399
+ next?: string;
400
+ prev?: string;
401
+ }
402
+ /**
403
+ * Options for paginated requests
404
+ */
405
+ export interface PaginationOptions {
406
+ /** Maximum number of items to fetch (default: no limit) */
407
+ maxItems?: number;
408
+ /** Request timeout in milliseconds (default: 30000) */
409
+ timeout?: number;
410
+ /** Page size for each request (default: 100) */
411
+ pageSize?: number;
356
412
  }
357
413
  /**
358
414
  * Resource name to endpoint mapping
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-lemonsqueezy",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "n8n community node for Lemon Squeezy - digital products and subscriptions platform",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",