@friggframework/serverless-plugin 2.0.0--canary.663.9683f8b.0 → 2.0.0--canary.639.4058469.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/index.js +12 -8
- package/index.test.js +53 -0
- package/package.json +5 -2
package/index.js
CHANGED
|
@@ -99,19 +99,23 @@ class FriggServerlessPlugin {
|
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
/**
|
|
103
|
+
* SQS client for LocalStack, used by `serverless offline` (`frigg start`)
|
|
104
|
+
* to create the app's queues locally. The aggregated AWS SDK v3 `SQS`
|
|
105
|
+
* client also accepts Node-style callbacks, which LocalStackQueueService
|
|
106
|
+
* uses.
|
|
107
|
+
*/
|
|
102
108
|
createLocalStackSQSClient() {
|
|
103
|
-
const
|
|
109
|
+
const { SQS } = require('@aws-sdk/client-sqs');
|
|
104
110
|
|
|
105
|
-
|
|
111
|
+
return new SQS({
|
|
106
112
|
region: process.env.AWS_REGION || 'us-east-1',
|
|
107
113
|
endpoint: process.env.AWS_ENDPOINT || 'http://localhost:4566',
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
114
|
+
credentials: {
|
|
115
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID || 'root',
|
|
116
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || 'root',
|
|
117
|
+
},
|
|
112
118
|
});
|
|
113
|
-
|
|
114
|
-
return new AWS.SQS({ sslEnabled: false });
|
|
115
119
|
}
|
|
116
120
|
|
|
117
121
|
async beforePackageInitialize() {
|
package/index.test.js
CHANGED
|
@@ -3,10 +3,12 @@ const FriggServerlessPlugin = require('./index');
|
|
|
3
3
|
jest.mock('./lib/queue-environment-mapper');
|
|
4
4
|
jest.mock('./lib/localstack-queue-service');
|
|
5
5
|
jest.mock('./lib/esbuild-directory-manager');
|
|
6
|
+
jest.mock('@aws-sdk/client-sqs', () => ({ SQS: jest.fn() }));
|
|
6
7
|
|
|
7
8
|
const { QueueEnvironmentMapper } = require('./lib/queue-environment-mapper');
|
|
8
9
|
const { LocalStackQueueService } = require('./lib/localstack-queue-service');
|
|
9
10
|
const { EsbuildDirectoryManager } = require('./lib/esbuild-directory-manager');
|
|
11
|
+
const { SQS } = require('@aws-sdk/client-sqs');
|
|
10
12
|
|
|
11
13
|
describe('FriggServerlessPlugin', () => {
|
|
12
14
|
let plugin;
|
|
@@ -158,6 +160,57 @@ describe('FriggServerlessPlugin', () => {
|
|
|
158
160
|
});
|
|
159
161
|
});
|
|
160
162
|
|
|
163
|
+
describe('createLocalStackSQSClient', () => {
|
|
164
|
+
const ENV_KEYS = [
|
|
165
|
+
'AWS_REGION',
|
|
166
|
+
'AWS_ENDPOINT',
|
|
167
|
+
'AWS_ACCESS_KEY_ID',
|
|
168
|
+
'AWS_SECRET_ACCESS_KEY',
|
|
169
|
+
];
|
|
170
|
+
let savedEnv;
|
|
171
|
+
|
|
172
|
+
beforeEach(() => {
|
|
173
|
+
savedEnv = Object.fromEntries(ENV_KEYS.map((k) => [k, process.env[k]]));
|
|
174
|
+
ENV_KEYS.forEach((k) => delete process.env[k]);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
afterEach(() => {
|
|
178
|
+
ENV_KEYS.forEach((k) => {
|
|
179
|
+
if (savedEnv[k] === undefined) delete process.env[k];
|
|
180
|
+
else process.env[k] = savedEnv[k];
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('creates an AWS SDK v3 SQS client pointed at LocalStack by default', () => {
|
|
185
|
+
plugin = new FriggServerlessPlugin(mockServerless, mockOptions);
|
|
186
|
+
|
|
187
|
+
const client = plugin.createLocalStackSQSClient();
|
|
188
|
+
|
|
189
|
+
expect(SQS).toHaveBeenCalledWith({
|
|
190
|
+
region: 'us-east-1',
|
|
191
|
+
endpoint: 'http://localhost:4566',
|
|
192
|
+
credentials: { accessKeyId: 'root', secretAccessKey: 'root' },
|
|
193
|
+
});
|
|
194
|
+
expect(client).toBeInstanceOf(SQS);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('honours AWS_* overrides from the environment', () => {
|
|
198
|
+
process.env.AWS_REGION = 'eu-west-1';
|
|
199
|
+
process.env.AWS_ENDPOINT = 'http://localstack:4566';
|
|
200
|
+
process.env.AWS_ACCESS_KEY_ID = 'key';
|
|
201
|
+
process.env.AWS_SECRET_ACCESS_KEY = 'secret';
|
|
202
|
+
plugin = new FriggServerlessPlugin(mockServerless, mockOptions);
|
|
203
|
+
|
|
204
|
+
plugin.createLocalStackSQSClient();
|
|
205
|
+
|
|
206
|
+
expect(SQS).toHaveBeenCalledWith({
|
|
207
|
+
region: 'eu-west-1',
|
|
208
|
+
endpoint: 'http://localstack:4566',
|
|
209
|
+
credentials: { accessKeyId: 'key', secretAccessKey: 'secret' },
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
161
214
|
describe('extractQueueDefinitions', () => {
|
|
162
215
|
it('should extract queue definitions from custom config', () => {
|
|
163
216
|
plugin = new FriggServerlessPlugin(mockServerless, mockOptions);
|
package/package.json
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@friggframework/serverless-plugin",
|
|
3
|
-
"version": "2.0.0--canary.
|
|
3
|
+
"version": "2.0.0--canary.639.4058469.0",
|
|
4
4
|
"description": "Plugin to help dynamically load frigg resources",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "jest"
|
|
8
8
|
},
|
|
9
9
|
"author": "Left Hook, Inc.",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@aws-sdk/client-sqs": "^3.588.0"
|
|
12
|
+
},
|
|
10
13
|
"license": "MIT",
|
|
11
14
|
"publishConfig": {
|
|
12
15
|
"access": "public"
|
|
13
16
|
},
|
|
14
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "4058469d1cf369ff715559377522175a046ba52f"
|
|
15
18
|
}
|