@friggframework/serverless-plugin 2.0.0--canary.398.a314355.0 → 2.0.0--canary.397.4957a89.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 (3) hide show
  1. package/index.js +2 -38
  2. package/package.json +2 -2
  3. package/index.test.js +0 -183
package/index.js CHANGED
@@ -1,30 +1,16 @@
1
1
  const { spawn } = require("child_process");
2
2
 
3
- /**
4
- * Frigg Serverless Plugin - Handles AWS discovery and local development setup
5
- */
6
3
  class FriggServerlessPlugin {
7
- /**
8
- * Creates an instance of FriggServerlessPlugin
9
- * @param {Object} serverless - Serverless framework instance
10
- * @param {Object} options - Plugin options
11
- */
12
4
  constructor(serverless, options) {
13
5
  this.serverless = serverless;
14
6
  this.options = options;
15
7
  this.provider = serverless.getProvider("aws");
16
8
  this.hooks = {
17
9
  initialize: () => this.init(),
18
- "before:package:initialize": () => this.beforePackageInitialize(),
19
10
  "after:package:package": () => this.afterPackage(),
20
11
  "before:deploy:deploy": () => this.beforeDeploy(),
21
12
  };
22
13
  }
23
- /**
24
- * Asynchronous initialization for offline mode
25
- * Creates SQS queues in localstack for local development
26
- * @returns {Promise<void>}
27
- */
28
14
  async asyncInit() {
29
15
  this.serverless.cli.log("Initializing Frigg Serverless Plugin...");
30
16
  console.log("Hello from Frigg Serverless Plugin!");
@@ -52,7 +38,7 @@ class FriggServerlessPlugin {
52
38
  });
53
39
 
54
40
  const sqs = new AWS.SQS();
55
- // Find the environment variables that we need to override and create an easy map
41
+ // Find the environment variables that we need to override and create an easy map
56
42
  const environmentMap = {};
57
43
  const environment = this.serverless.service.provider.environment;
58
44
 
@@ -97,26 +83,7 @@ class FriggServerlessPlugin {
97
83
  console.log("Running in online mode, doing nothing");
98
84
  }
99
85
  }
100
-
101
- /**
102
- * Hook that runs before serverless package initialization
103
- * AWS discovery is now handled in serverless-template.js
104
- * @returns {Promise<void>}
105
- */
106
- async beforePackageInitialize() {
107
- // AWS discovery is now handled directly in serverless-template.js
108
- // This hook remains for potential future use or other pre-package tasks
109
- this.serverless.cli.log("Frigg Serverless Plugin: Pre-package hook");
110
- }
111
-
112
-
113
- /**
114
- * Initialization hook (currently empty)
115
- */
116
- init() { }
117
- /**
118
- * Hook that runs after serverless package
119
- */
86
+ init() {}
120
87
  afterPackage() {
121
88
  console.log("After package hook called");
122
89
  // // const queues = Object.keys(infrastructure.custom)
@@ -156,9 +123,6 @@ class FriggServerlessPlugin {
156
123
  // // });
157
124
  // });
158
125
  }
159
- /**
160
- * Hook that runs before serverless deploy
161
- */
162
126
  beforeDeploy() {
163
127
  console.log("Before deploy hook called");
164
128
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@friggframework/serverless-plugin",
3
- "version": "2.0.0--canary.398.a314355.0",
3
+ "version": "2.0.0--canary.397.4957a89.0",
4
4
  "description": "Plugin to help dynamically load frigg resources",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,5 +11,5 @@
11
11
  "publishConfig": {
12
12
  "access": "public"
13
13
  },
14
- "gitHead": "a31435596361f047f54cfbcc03c9863b129d0d1c"
14
+ "gitHead": "4957a89e2a8ebcc2698dbae047858120ef1725fc"
15
15
  }
package/index.test.js DELETED
@@ -1,183 +0,0 @@
1
- const FriggServerlessPlugin = require('./index');
2
-
3
- // Mock dependencies
4
- jest.mock('aws-sdk');
5
-
6
- describe('FriggServerlessPlugin', () => {
7
- let plugin;
8
- let mockServerless;
9
- let mockOptions;
10
- const originalEnv = process.env;
11
-
12
- beforeEach(() => {
13
-
14
- // Mock serverless object
15
- mockServerless = {
16
- cli: {
17
- log: jest.fn()
18
- },
19
- service: {
20
- provider: {
21
- name: 'aws',
22
- region: 'us-east-1'
23
- },
24
- plugins: [],
25
- custom: {},
26
- functions: {}
27
- },
28
- processedInput: {
29
- commands: []
30
- },
31
- getProvider: jest.fn(() => ({})),
32
- extendConfiguration: jest.fn()
33
- };
34
-
35
- mockOptions = {
36
- stage: 'test'
37
- };
38
-
39
- // Reset environment
40
- process.env = { ...originalEnv };
41
-
42
- jest.clearAllMocks();
43
-
44
- plugin = new FriggServerlessPlugin(mockServerless, mockOptions);
45
- });
46
-
47
- afterEach(() => {
48
- process.env = originalEnv;
49
- });
50
-
51
- describe('constructor', () => {
52
- it('should initialize plugin with correct hooks', () => {
53
- expect(plugin.serverless).toBe(mockServerless);
54
- expect(plugin.options).toBe(mockOptions);
55
- expect(plugin.hooks).toEqual({
56
- initialize: expect.any(Function),
57
- 'before:package:initialize': expect.any(Function),
58
- 'after:package:package': expect.any(Function),
59
- 'before:deploy:deploy': expect.any(Function)
60
- });
61
- });
62
-
63
- it('should get AWS provider from serverless', () => {
64
- expect(mockServerless.getProvider).toHaveBeenCalledWith('aws');
65
- });
66
- });
67
-
68
- describe('beforePackageInitialize', () => {
69
- it('should log pre-package hook message', async () => {
70
- await plugin.beforePackageInitialize();
71
-
72
- expect(mockServerless.cli.log).toHaveBeenCalledWith('Frigg Serverless Plugin: Pre-package hook');
73
- });
74
- });
75
-
76
-
77
- describe('asyncInit (offline mode)', () => {
78
- beforeEach(() => {
79
- // Mock AWS SDK
80
- const mockSQS = {
81
- createQueue: jest.fn()
82
- };
83
-
84
- jest.doMock('aws-sdk', () => ({
85
- SQS: jest.fn(() => mockSQS),
86
- config: {
87
- update: jest.fn()
88
- }
89
- }));
90
-
91
- mockServerless.service.custom = {
92
- TestQueue: 'test-queue-name',
93
- AnotherQueue: 'another-queue-name'
94
- };
95
-
96
- mockServerless.service.provider.environment = {
97
- TEST_QUEUE_URL: { Ref: 'TestQueue' },
98
- ANOTHER_QUEUE_URL: { Ref: 'AnotherQueue' },
99
- NORMAL_VAR: 'normal-value'
100
- };
101
- });
102
-
103
- it('should create queues in offline mode', async () => {
104
- mockServerless.processedInput.commands = ['offline'];
105
-
106
- const AWS = require('aws-sdk');
107
- const mockSQS = new AWS.SQS();
108
- mockSQS.createQueue.mockImplementation((params, callback) => {
109
- callback(null, { QueueUrl: `http://localhost:4566/000000000000/${params.QueueName}` });
110
- });
111
-
112
- await plugin.asyncInit();
113
-
114
- expect(AWS.config.update).toHaveBeenCalledWith({
115
- region: 'us-east-1',
116
- endpoint: 'localhost:4566'
117
- });
118
-
119
- expect(mockSQS.createQueue).toHaveBeenCalledWith(
120
- { QueueName: 'test-queue-name' },
121
- expect.any(Function)
122
- );
123
-
124
- expect(mockSQS.createQueue).toHaveBeenCalledWith(
125
- { QueueName: 'another-queue-name' },
126
- expect.any(Function)
127
- );
128
-
129
- expect(mockServerless.extendConfiguration).toHaveBeenCalled();
130
- });
131
-
132
- it('should skip queue creation in online mode', async () => {
133
- mockServerless.processedInput.commands = ['deploy'];
134
-
135
- await plugin.asyncInit();
136
-
137
- const AWS = require('aws-sdk');
138
- expect(AWS.config.update).not.toHaveBeenCalled();
139
- });
140
-
141
- it('should handle queue creation errors', async () => {
142
- mockServerless.processedInput.commands = ['offline'];
143
-
144
- const AWS = require('aws-sdk');
145
- const mockSQS = new AWS.SQS();
146
- mockSQS.createQueue.mockImplementation((params, callback) => {
147
- callback(new Error('Queue creation failed'));
148
- });
149
-
150
- await expect(plugin.asyncInit()).rejects.toThrow('Queue creation failed');
151
- });
152
- });
153
-
154
- describe('hook methods', () => {
155
- it('should have init method', () => {
156
- expect(plugin.init).toBeDefined();
157
- expect(typeof plugin.init).toBe('function');
158
- });
159
-
160
- it('should have afterPackage method', () => {
161
- expect(plugin.afterPackage).toBeDefined();
162
- expect(typeof plugin.afterPackage).toBe('function');
163
-
164
- // Test that it logs correctly
165
- const consoleSpy = jest.spyOn(console, 'log');
166
- plugin.afterPackage();
167
- expect(consoleSpy).toHaveBeenCalledWith('After package hook called');
168
- consoleSpy.mockRestore();
169
- });
170
-
171
- it('should have beforeDeploy method', () => {
172
- expect(plugin.beforeDeploy).toBeDefined();
173
- expect(typeof plugin.beforeDeploy).toBe('function');
174
-
175
- // Test that it logs correctly
176
- const consoleSpy = jest.spyOn(console, 'log');
177
- plugin.beforeDeploy();
178
- expect(consoleSpy).toHaveBeenCalledWith('Before deploy hook called');
179
- consoleSpy.mockRestore();
180
- });
181
- });
182
-
183
- });