@gugananuvem/aws-local-simulator 1.0.25 → 1.0.27

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.
@@ -49,7 +49,7 @@ class SQSSimulator {
49
49
  }
50
50
  }
51
51
 
52
- createQueue(queueName) {
52
+ createQueue(queueName, attributes = {}) {
53
53
  if (this.queues.has(queueName)) {
54
54
  return { error: { code: 'QueueAlreadyExists', message: 'Queue already exists' }, status: 409 };
55
55
  }
@@ -60,12 +60,18 @@ class SQSSimulator {
60
60
  arn: `arn:aws:sqs:local:000000000000:${queueName}`,
61
61
  messages: [],
62
62
  handler: null,
63
- batchSize: 10,
64
- visibilityTimeout: 30,
63
+ batchSize: parseInt(attributes.BatchSize || 10),
64
+ visibilityTimeout: parseInt(attributes.VisibilityTimeout || 30),
65
+ delaySeconds: parseInt(attributes.DelaySeconds || 0),
66
+ messageRetentionPeriod: parseInt(attributes.MessageRetentionPeriod || 345600),
65
67
  createdAt: new Date().toISOString(),
66
68
  messageCount: 0
67
69
  };
68
70
 
71
+ if (attributes.LambdaName) {
72
+ this.attachLambdaToQueue(queueName, attributes.LambdaName, { batchSize: queue.batchSize });
73
+ }
74
+
69
75
  this.queues.set(queueName, queue);
70
76
  this.persistQueues();
71
77
  // Only initialize message store if it doesn't already exist
@@ -73,7 +79,7 @@ class SQSSimulator {
73
79
  this.store.write(queueName, []);
74
80
  }
75
81
 
76
- logger.debug(`✅ Fila SQS criada: ${queueName}`);
82
+ logger.debug(`✅ Fila SQS criada: ${queueName} com atributos: ${JSON.stringify(attributes)}`);
77
83
 
78
84
  return { queue };
79
85
  }
@@ -82,6 +88,8 @@ class SQSSimulator {
82
88
  switch(action) {
83
89
  case 'CreateQueue':
84
90
  return this.createQueueAction(req);
91
+ case 'SetQueueAttributes':
92
+ return this.setQueueAttributesAction(req);
85
93
  case 'SendMessage':
86
94
  return this.sendMessageAction(req);
87
95
  case 'SendMessageBatch':
@@ -108,9 +116,26 @@ class SQSSimulator {
108
116
  return undefined;
109
117
  }
110
118
 
119
+ // Parses Attribute.N.Name and Attribute.N.Value from request body/query
120
+ extractAttributes(req) {
121
+ const attributes = {};
122
+ const source = req.body.Action ? req.body : req.query;
123
+
124
+ Object.keys(source).forEach(key => {
125
+ if (key.startsWith('Attribute.') && key.endsWith('.Name')) {
126
+ const index = key.split('.')[1];
127
+ const name = source[key];
128
+ const value = source[`Attribute.${index}.Value`];
129
+ attributes[name] = value;
130
+ }
131
+ });
132
+ return attributes;
133
+ }
134
+
111
135
  createQueueAction(req) {
112
136
  const queueName = req.query.QueueName || req.body.QueueName;
113
- const result = this.createQueue(queueName);
137
+ const attributes = this.extractAttributes(req);
138
+ const result = this.createQueue(queueName, attributes);
114
139
 
115
140
  if (result.error) {
116
141
  return result;
@@ -119,6 +144,39 @@ class SQSSimulator {
119
144
  return { queueUrl: result.queue.url };
120
145
  }
121
146
 
147
+ setQueueAttributesAction(req) {
148
+ const queueName = this.resolveQueueName(req);
149
+ const queue = this.queues.get(queueName);
150
+
151
+ if (!queue) {
152
+ return { error: { code: 'QueueDoesNotExist', message: 'Queue does not exist' }, status: 400 };
153
+ }
154
+
155
+ const attributes = this.extractAttributes(req);
156
+
157
+ if (attributes.DelaySeconds !== undefined) queue.delaySeconds = parseInt(attributes.DelaySeconds);
158
+ if (attributes.VisibilityTimeout !== undefined) queue.visibilityTimeout = parseInt(attributes.VisibilityTimeout);
159
+ if (attributes.MessageRetentionPeriod !== undefined) queue.messageRetentionPeriod = parseInt(attributes.MessageRetentionPeriod);
160
+
161
+ if (attributes.LambdaName !== undefined) {
162
+ queue.lambdaName = attributes.LambdaName;
163
+ if (attributes.LambdaName) {
164
+ // Here we'd normally re-attach if we had a direct reference to the lambda service function
165
+ // For now, we store the name and the server/index.js will handle re-attachment or we use the name to look it up
166
+ this.attachLambdaToQueue(queueName, attributes.LambdaName, { batchSize: queue.batchSize });
167
+ } else {
168
+ queue.handler = null;
169
+ }
170
+ }
171
+
172
+ if (attributes.BatchSize !== undefined) {
173
+ queue.batchSize = parseInt(attributes.BatchSize);
174
+ }
175
+
176
+ this.persistQueues();
177
+ return { success: true };
178
+ }
179
+
122
180
  sendMessageAction(req) {
123
181
  const queueName = this.resolveQueueName(req);
124
182
  const queue = this.queues.get(queueName);
@@ -334,9 +392,13 @@ class SQSSimulator {
334
392
  arn: queue.arn,
335
393
  batchSize: queue.batchSize,
336
394
  visibilityTimeout: queue.visibilityTimeout,
395
+ delaySeconds: queue.delaySeconds,
396
+ messageRetentionPeriod: queue.messageRetentionPeriod,
397
+ lambdaName: queue.lambdaName,
337
398
  createdAt: queue.createdAt,
338
399
  messageCount: queue.messageCount
339
400
  };
401
+
340
402
  }
341
403
  this.store.write('__queues__', queuesObj);
342
404
  }
@@ -372,10 +434,16 @@ class SQSSimulator {
372
434
  name: q.name,
373
435
  url: q.url,
374
436
  messagesCount: q.messageCount,
375
- createdAt: q.createdAt
437
+ createdAt: q.createdAt,
438
+ delaySeconds: q.delaySeconds,
439
+ visibilityTimeout: q.visibilityTimeout,
440
+ messageRetentionPeriod: q.messageRetentionPeriod,
441
+ lambdaName: q.lambdaName,
442
+ batchSize: q.batchSize
376
443
  }));
377
444
  }
378
445
 
446
+
379
447
  getQueue(queueName) {
380
448
  const queue = this.queues.get(queueName);
381
449
  if (!queue) return null;