core-services-sdk 1.3.9 → 1.3.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-services-sdk",
3
- "version": "1.3.9",
3
+ "version": "1.3.10",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -23,7 +23,6 @@
23
23
  "@aws-sdk/credential-provider-node": "^3.862.0",
24
24
  "@sendgrid/mail": "^8.1.5",
25
25
  "amqplib": "^0.10.8",
26
- "crypto": "^1.0.1",
27
26
  "dot": "^1.1.3",
28
27
  "fastify": "^5.4.0",
29
28
  "http-status": "^2.1.0",
@@ -40,4 +39,4 @@
40
39
  "url": "^0.11.4",
41
40
  "vitest": "^3.2.4"
42
41
  }
43
- }
42
+ }
@@ -1,9 +1,7 @@
1
+ // @ts-nocheck
1
2
  import nodemailer from 'nodemailer'
2
- import { describe, it, expect, vi, beforeEach } from 'vitest'
3
3
 
4
- // ===================
5
- // SAFELY MOCK MODULES
6
- // ===================
4
+ import { describe, it, expect, vi, beforeEach } from 'vitest'
7
5
 
8
6
  vi.mock('nodemailer', () => {
9
7
  const createTransport = vi.fn((options) => ({
@@ -17,23 +15,24 @@ vi.mock('nodemailer', () => {
17
15
  }
18
16
  })
19
17
 
20
- vi.mock('nodemailer-sendgrid-transport', () => ({
21
- __esModule: true,
22
- default: vi.fn((opts) => ({
23
- sendgrid: true,
24
- options: opts,
25
- })),
26
- }))
18
+ vi.mock('@sendgrid/mail', () => {
19
+ const setApiKey = vi.fn()
20
+ const send = vi.fn()
21
+ const sgMail = { setApiKey, send }
22
+ globalThis.__mockedSgMail__ = sgMail
23
+ return {
24
+ __esModule: true,
25
+ default: sgMail,
26
+ }
27
+ })
27
28
 
28
29
  vi.mock('@aws-sdk/client-ses', () => {
29
- const mockSesInstance = { mocked: true } // consistent reference
30
- const sesClient = vi.fn(() => mockSesInstance)
31
-
32
- globalThis.__mockedSesClient__ = sesClient
30
+ const mockSesInstance = { mocked: true }
31
+ const SESClient = vi.fn(() => mockSesInstance)
32
+ globalThis.__mockedSesClient__ = SESClient
33
33
  globalThis.__mockedSesInstance__ = mockSesInstance
34
-
35
34
  return {
36
- SESClient: sesClient,
35
+ SESClient,
37
36
  SendRawEmailCommand: 'mocked-command',
38
37
  }
39
38
  })
@@ -41,15 +40,9 @@ vi.mock('@aws-sdk/client-ses', () => {
41
40
  vi.mock('@aws-sdk/credential-provider-node', () => {
42
41
  const defaultProvider = vi.fn(() => 'mocked-default-provider')
43
42
  globalThis.__mockedDefaultProvider__ = defaultProvider
44
- return {
45
- defaultProvider,
46
- }
43
+ return { defaultProvider }
47
44
  })
48
45
 
49
- // ==========================
50
- // NOW IMPORT MODULE UNDER TEST
51
- // ==========================
52
-
53
46
  import { TransportFactory } from '../../src/mailer/transport.factory.js'
54
47
 
55
48
  describe('TransportFactory', () => {
@@ -66,7 +59,6 @@ describe('TransportFactory', () => {
66
59
  auth: { user: 'user', pass: 'pass' },
67
60
  }
68
61
 
69
- // @ts-ignore
70
62
  const transport = TransportFactory.create(config)
71
63
 
72
64
  expect(nodemailer.createTransport).toHaveBeenCalledWith({
@@ -75,8 +67,6 @@ describe('TransportFactory', () => {
75
67
  secure: config.secure,
76
68
  auth: config.auth,
77
69
  })
78
-
79
- // @ts-ignore
80
70
  expect(transport.type).toBe('mock-transport')
81
71
  })
82
72
 
@@ -86,46 +76,33 @@ describe('TransportFactory', () => {
86
76
  auth: { user: 'user@gmail.com', pass: 'pass' },
87
77
  }
88
78
 
89
- // @ts-ignore
90
79
  const transport = TransportFactory.create(config)
91
80
 
92
81
  expect(nodemailer.createTransport).toHaveBeenCalledWith({
93
82
  service: 'gmail',
94
83
  auth: config.auth,
95
84
  })
96
-
97
- // @ts-ignore
98
85
  expect(transport.type).toBe('mock-transport')
99
86
  })
100
87
 
101
88
  it('should create sendgrid transport', () => {
102
89
  const config = {
103
90
  type: 'sendgrid',
104
- apiKey: 'SG.xxxx',
91
+ apiKey: 'SG.key',
105
92
  }
106
93
 
107
- // @ts-ignore
108
94
  const transport = TransportFactory.create(config)
109
95
 
110
- // @ts-ignore
111
- const args = nodemailer.createTransport.mock.calls[0][0]
112
-
113
- expect(args).toEqual({
114
- sendgrid: true,
115
- options: {
116
- auth: { api_key: config.apiKey },
117
- },
118
- })
96
+ expect(globalThis.__mockedSgMail__.setApiKey).toHaveBeenCalledWith(
97
+ config.apiKey,
98
+ )
99
+ expect(transport).toEqual(globalThis.__mockedSgMail__)
100
+ })
119
101
 
120
- expect(transport).toEqual({
121
- type: 'mock-transport',
122
- options: {
123
- sendgrid: true,
124
- options: {
125
- auth: { api_key: config.apiKey },
126
- },
127
- },
128
- })
102
+ it('should throw if sendgrid API key is missing', () => {
103
+ expect(() => {
104
+ TransportFactory.create({ type: 'sendgrid' })
105
+ }).toThrow('Missing SendGrid API key')
129
106
  })
130
107
 
131
108
  it('should create ses transport with credentials', () => {
@@ -136,7 +113,6 @@ describe('TransportFactory', () => {
136
113
  region: 'us-west-2',
137
114
  }
138
115
 
139
- // @ts-ignore
140
116
  const transport = TransportFactory.create(config)
141
117
 
142
118
  expect(globalThis.__mockedSesClient__).toHaveBeenCalledWith({
@@ -147,19 +123,14 @@ describe('TransportFactory', () => {
147
123
  },
148
124
  })
149
125
 
150
- // @ts-ignore
151
126
  const args = nodemailer.createTransport.mock.calls[0][0]
152
-
153
127
  expect(args).toEqual({
154
128
  SES: {
155
129
  ses: globalThis.__mockedSesInstance__,
156
- aws: {
157
- SendRawEmailCommand: 'mocked-command',
158
- },
130
+ aws: { SendRawEmailCommand: 'mocked-command' },
159
131
  },
160
132
  })
161
133
 
162
- // @ts-ignore
163
134
  expect(transport.type).toBe('mock-transport')
164
135
  })
165
136
 
@@ -169,35 +140,27 @@ describe('TransportFactory', () => {
169
140
  region: 'us-east-1',
170
141
  }
171
142
 
172
- // @ts-ignore
173
143
  const transport = TransportFactory.create(config)
174
144
 
175
145
  expect(globalThis.__mockedDefaultProvider__).toHaveBeenCalled()
176
-
177
146
  expect(globalThis.__mockedSesClient__).toHaveBeenCalledWith({
178
147
  region: config.region,
179
148
  credentials: 'mocked-default-provider',
180
149
  })
181
150
 
182
- // @ts-ignore
183
151
  const args = nodemailer.createTransport.mock.calls[0][0]
184
-
185
152
  expect(args).toEqual({
186
153
  SES: {
187
154
  ses: globalThis.__mockedSesInstance__,
188
- aws: {
189
- SendRawEmailCommand: 'mocked-command',
190
- },
155
+ aws: { SendRawEmailCommand: 'mocked-command' },
191
156
  },
192
157
  })
193
158
 
194
- // @ts-ignore
195
159
  expect(transport.type).toBe('mock-transport')
196
160
  })
197
161
 
198
162
  it('should throw error for unsupported type', () => {
199
163
  expect(() => {
200
- // @ts-ignore
201
164
  TransportFactory.create({ type: 'invalid' })
202
165
  }).toThrow('Unsupported transport type: invalid')
203
166
  })