Skip to content

Commit b183e0c

Browse files
authored
Fix TLS Credential Options (#23)
* bumping to v0.3.3 with some minor updates to the package.json Signed-off-by: Daan Gerits <daan@synadia.com> * TLS credentials options added Signed-off-by: Daan Gerits <daan@synadia.com> * Formatted the codebase Signed-off-by: Daan Gerits <daan@synadia.com> --------- Signed-off-by: Daan Gerits <daan@synadia.com>
1 parent 6fc037b commit b183e0c

30 files changed

+401
-206
lines changed

credentials/NatsApi/NatsApi.credentials.ts

Lines changed: 55 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -111,73 +111,64 @@ SUACSSL3UAHUDXKFSNVUZRF5UHPMWZ6BFDTJ7M6USDXIEDNPPQYYYCU3VY
111111
required: true,
112112
},
113113
{
114-
displayName: 'Options',
115-
name: 'options',
116-
type: 'collection',
117-
placeholder: 'Add Option',
118-
default: {},
119-
options: [
120-
{
121-
displayName: 'Client Name',
122-
name: 'name',
123-
type: 'string',
124-
default: '',
125-
description: 'Client name for connection identification',
126-
},
127-
{
128-
displayName: 'Enable TLS',
129-
name: 'tlsEnabled',
130-
type: 'boolean',
131-
default: false,
132-
description: 'Whether to enable TLS encryption',
133-
},
134-
{
135-
displayName: 'TLS CA Certificate',
136-
name: 'ca',
137-
type: 'string',
138-
typeOptions: {
139-
rows: 4,
140-
},
141-
displayOptions: {
142-
show: {
143-
tlsEnabled: [true],
144-
},
145-
},
146-
default: '',
147-
description: 'CA certificate for TLS verification',
114+
displayName: 'Client Name',
115+
name: 'name',
116+
type: 'string',
117+
default: '',
118+
description: 'Client name for connection identification',
119+
},
120+
{
121+
displayName: 'Enable TLS',
122+
name: 'tlsEnabled',
123+
type: 'boolean',
124+
default: false,
125+
description: 'Whether to enable TLS encryption',
126+
},
127+
{
128+
displayName: 'TLS CA Certificate',
129+
name: 'ca',
130+
type: 'string',
131+
typeOptions: {
132+
rows: 4,
133+
},
134+
displayOptions: {
135+
show: {
136+
tlsEnabled: [true],
148137
},
149-
{
150-
displayName: 'TLS Client Certificate',
151-
name: 'cert',
152-
type: 'string',
153-
typeOptions: {
154-
rows: 4,
155-
},
156-
displayOptions: {
157-
show: {
158-
tlsEnabled: [true],
159-
},
160-
},
161-
default: '',
162-
description: 'Client certificate for TLS authentication',
138+
},
139+
default: '',
140+
description: 'CA certificate for TLS verification',
141+
},
142+
{
143+
displayName: 'TLS Client Certificate',
144+
name: 'cert',
145+
type: 'string',
146+
typeOptions: {
147+
rows: 4,
148+
},
149+
displayOptions: {
150+
show: {
151+
tlsEnabled: [true],
163152
},
164-
{
165-
displayName: 'TLS Client Key',
166-
name: 'key',
167-
type: 'string',
168-
typeOptions: {
169-
rows: 4,
170-
password: true,
171-
},
172-
displayOptions: {
173-
show: {
174-
tlsEnabled: [true],
175-
},
176-
},
177-
default: '',
178-
description: 'Client key for TLS authentication',
153+
},
154+
default: '',
155+
description: 'Client certificate for TLS authentication',
156+
},
157+
{
158+
displayName: 'TLS Client Key',
159+
name: 'key',
160+
type: 'string',
161+
typeOptions: {
162+
rows: 4,
163+
password: true,
164+
},
165+
displayOptions: {
166+
show: {
167+
tlsEnabled: [true],
179168
},
180-
],
169+
},
170+
default: '',
171+
description: 'Client key for TLS authentication',
181172
},
182173
];
183174

nodes/Nats/Nats.node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,4 @@ export class Nats implements INodeType {
174174

175175
return [returnData];
176176
}
177-
}
177+
}

nodes/Nats/NatsTrigger.node.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,26 +102,25 @@ export class NatsTrigger implements INodeType {
102102
user: {
103103
id: 'user-12345',
104104
email: 'user@example.com',
105-
name: 'John Doe'
105+
name: 'John Doe',
106106
},
107107
metadata: {
108108
source: 'web-app',
109109
version: '1.0.0',
110-
environment: 'production'
110+
environment: 'production',
111111
},
112112
timestamp: Date.now(),
113113
},
114114
headers: {
115115
'Content-Type': 'application/json',
116116
'X-Request-ID': 'req-' + Math.random().toString(36).substr(2, 9),
117117
'X-Source': 'manual-trigger',
118-
'X-Version': '1.0'
118+
'X-Version': '1.0',
119119
},
120120
replyTo: `_INBOX.${Math.random().toString(36).substr(2, 12)}`,
121121
timestamp: new Date().toISOString(),
122122
};
123123

124-
125124
this.emit([this.helpers.returnJsonArray([sampleData])]);
126125
};
127126

@@ -164,4 +163,4 @@ export class NatsTrigger implements INodeType {
164163
throw new ApplicationError(`Failed to setup NATS subscriber: ${error.message}`);
165164
}
166165
}
167-
}
166+
}

nodes/NatsJetstream/ConsumersDescription.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,4 @@ export const consumersDescription: INodeProperties[] = [
242242
},
243243
],
244244
},
245-
];
245+
];

nodes/NatsJetstream/MessageOperationHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ export class PublishMessageOperationHandler implements MessageOperationHandler {
6161
timestamp: new Date().toISOString(),
6262
};
6363
}
64-
}
64+
}

nodes/NatsJetstream/MessagesDescription.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,4 @@ export const messagesDescription: INodeProperties[] = [
139139
},
140140
],
141141
},
142-
];
142+
];

nodes/NatsJetstream/NatsJetstream.node.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ export class NatsJetstream implements INodeType {
184184
// Flush any pending messages for message operations
185185
await nc.flush();
186186
} catch (error: any) {
187-
throw new NodeOperationError(this.getNode(), `NATS JetStream operation failed: ${error.message}`);
187+
throw new NodeOperationError(
188+
this.getNode(),
189+
`NATS JetStream operation failed: ${error.message}`,
190+
);
188191
} finally {
189192
if (nc!) {
190193
await closeNatsConnection(nc, nodeLogger);
@@ -193,4 +196,4 @@ export class NatsJetstream implements INodeType {
193196

194197
return [returnData];
195198
}
196-
}
199+
}

nodes/NatsJetstream/NatsJetstreamTrigger.node.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import {
88
} from 'n8n-workflow';
99
import { NatsConnection, jetstream, jetstreamManager } from '../../bundled/nats-bundled';
1010
import { createNatsConnection, closeNatsConnection } from '../../utils/NatsConnection';
11-
import { parseNatsMessage, validateStreamName, validateConsumerName } from '../../utils/NatsHelpers';
11+
import {
12+
parseNatsMessage,
13+
validateStreamName,
14+
validateConsumerName,
15+
} from '../../utils/NatsHelpers';
1216
import { NodeLogger } from '../../utils/NodeLogger';
1317

1418
export class NatsJetstreamTrigger implements INodeType {
@@ -72,7 +76,8 @@ export class NatsJetstreamTrigger implements INodeType {
7276
name: 'maxBytes',
7377
type: 'number',
7478
default: 0,
75-
description: 'Maximum bytes to fetch in each pull. If set, takes priority over Max Messages.',
79+
description:
80+
'Maximum bytes to fetch in each pull. If set, takes priority over Max Messages.',
7681
hint: 'Set to 0 to use Max Messages instead. These options are mutually exclusive',
7782
},
7883
{
@@ -135,18 +140,18 @@ export class NatsJetstreamTrigger implements INodeType {
135140
sku: 'WIDGET-001',
136141
name: 'Premium Widget',
137142
quantity: 2,
138-
price: 49.99
139-
}
143+
price: 49.99,
144+
},
140145
],
141146
shipping: {
142147
address: '123 Main St, Anytown, NY 12345',
143148
method: 'standard',
144-
cost: 9.99
149+
cost: 9.99,
145150
},
146151
payment: {
147152
method: 'credit_card',
148153
last4: '4242',
149-
status: 'authorized'
154+
status: 'authorized',
150155
},
151156
status: 'confirmed',
152157
timestamp: Date.now(),
@@ -156,7 +161,7 @@ export class NatsJetstreamTrigger implements INodeType {
156161
'X-Order-Source': 'web-app',
157162
'X-User-Agent': 'Mozilla/5.0 (example)',
158163
'X-Request-ID': 'req-' + Math.random().toString(36).substr(2, 12),
159-
'X-Correlation-ID': 'corr-' + Math.random().toString(36).substr(2, 12)
164+
'X-Correlation-ID': 'corr-' + Math.random().toString(36).substr(2, 12),
160165
},
161166
// JetStream specific metadata
162167
seq: Math.floor(Math.random() * 10000) + 1000,
@@ -198,7 +203,9 @@ export class NatsJetstreamTrigger implements INodeType {
198203
await jsm.streams.info(streamName);
199204
} catch (error: any) {
200205
if (error.code === 'STREAM_NOT_FOUND') {
201-
throw new ApplicationError(`JetStream stream '${streamName}' not found. Please create the stream first.`);
206+
throw new ApplicationError(
207+
`JetStream stream '${streamName}' not found. Please create the stream first.`,
208+
);
202209
}
203210
throw error;
204211
}
@@ -208,7 +215,9 @@ export class NatsJetstreamTrigger implements INodeType {
208215
consumer = await js.consumers.get(streamName, consumerName);
209216
} catch (error: any) {
210217
if (error.code === 'CONSUMER_NOT_FOUND') {
211-
throw new ApplicationError(`JetStream consumer '${consumerName}' not found in stream '${streamName}'. Please create the consumer first.`);
218+
throw new ApplicationError(
219+
`JetStream consumer '${consumerName}' not found in stream '${streamName}'. Please create the consumer first.`,
220+
);
212221
}
213222
throw error;
214223
}
@@ -236,7 +245,7 @@ export class NatsJetstreamTrigger implements INodeType {
236245
for await (const msg of messageIterator) {
237246
try {
238247
const parsedMessage = parseNatsMessage(msg);
239-
248+
240249
// Add JetStream-specific metadata
241250
const jetstreamMessage = {
242251
...parsedMessage,
@@ -252,9 +261,9 @@ export class NatsJetstreamTrigger implements INodeType {
252261
// Acknowledge the message
253262
msg.ack();
254263
} catch (messageError: any) {
255-
nodeLogger.error('Error processing JetStream message:', {
264+
nodeLogger.error('Error processing JetStream message:', {
256265
error: messageError,
257-
seq: msg.seq
266+
seq: msg.seq,
258267
});
259268
// NAK the message for redelivery
260269
msg.nak();
@@ -273,4 +282,4 @@ export class NatsJetstreamTrigger implements INodeType {
273282
throw new ApplicationError(`Failed to setup JetStream consumer: ${error.message}`);
274283
}
275284
}
276-
}
285+
}

nodes/NatsJetstream/StreamDescription.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,4 @@ export const streamDescription: INodeProperties[] = [
243243
},
244244
],
245245
},
246-
];
246+
];

0 commit comments

Comments
 (0)