Skip to content

Commit d81760a

Browse files
authored
Fix: [AEA-0000] - remove uuid (#2244)
## Summary - Routine Change ### Details - remove uuid
1 parent 2cbe4f7 commit d81760a

File tree

9 files changed

+132
-661
lines changed

9 files changed

+132
-661
lines changed

package-lock.json

Lines changed: 120 additions & 629 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/nhsNotifyLambda/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
"axios": "^1.12.2",
2525
"axios-retry": "^4.5.0",
2626
"jose": "^6.1.0",
27-
"nock": "^14.0.10",
28-
"uuid": "^13.0.0"
27+
"nock": "^14.0.10"
2928
},
3029
"devDependencies": {
3130
"@PrescriptionStatusUpdate_common/testing": "^1.0.0",

packages/nhsNotifyLambda/src/utils/auth.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {getSecret} from "@aws-lambda-powertools/parameters/secrets"
33
import {AxiosInstance} from "axios"
44

55
import {SignJWT, importPKCS8} from "jose"
6-
import {v4 as uuidv4} from "uuid"
76

87
/**
98
* Exchange API key + JWT for a bearer token from NHS Notify.
@@ -30,7 +29,7 @@ export async function tokenExchange(
3029
// create and sign the JWT
3130
const alg = "RS512"
3231
const now = Math.floor(Date.now() / 1000)
33-
const jti = uuidv4()
32+
const jti = crypto.randomUUID()
3433

3534
const key = await importPKCS8(PRIVATE_KEY, alg)
3635

packages/nhsNotifyLambda/src/utils/notify.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {Logger} from "@aws-lambda-powertools/logger"
22

33
import axios from "axios"
4-
import {v4} from "uuid"
54

65
import {setupAxios} from "./axios"
76
import {
@@ -95,7 +94,7 @@ async function makeFakeNotifyRequest(
9594
await new Promise(f => setTimeout(f, DUMMY_NOTIFY_DELAY_MS))
9695

9796
const messageStatus = "silent running"
98-
const messageBatchReference = v4()
97+
const messageBatchReference = crypto.randomUUID()
9998

10099
logger.info("Requested notifications OK!", {
101100
messageBatchReference,
@@ -113,7 +112,7 @@ async function makeFakeNotifyRequest(
113112
...item,
114113
messageBatchReference,
115114
messageStatus,
116-
notifyMessageId: v4() // Create a dummy UUID
115+
notifyMessageId: crypto.randomUUID() // Create a dummy UUID
117116
}
118117
})
119118
}
@@ -137,7 +136,7 @@ export async function makeRealNotifyRequest(
137136
): Promise<Array<NotifyDataItemMessage>> {
138137

139138
// Shared between all messages in this batch
140-
const messageBatchReference = v4()
139+
const messageBatchReference = crypto.randomUUID()
141140

142141
const body: CreateMessageBatchRequest = {
143142
data: {

packages/nhsNotifyLambda/src/utils/sqs.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import {
77
} from "@aws-sdk/client-sqs"
88
import {Logger} from "@aws-lambda-powertools/logger"
99

10-
import {v4} from "uuid"
11-
1210
import {NotifyDataItem} from "@PrescriptionStatusUpdate_common/commonTypes"
1311

1412
import {NotifyDataItemMessage} from "./types"
@@ -122,7 +120,7 @@ export async function drainQueue(
122120
...m,
123121
PSUDataItem: parsedBody,
124122
messageBatchReference: undefined, // Only populated when notify request is made
125-
messageReference: v4()
123+
messageReference: crypto.randomUUID()
126124
}
127125
]
128126
} catch (error) {

packages/nhsNotifyLambda/tests/testAuth.test.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ jest.unstable_mockModule("jose", async () => ({
2121
SignJWT: mockSignJWTConstructor
2222
}))
2323

24-
const mockUuidv4 = jest.fn()
25-
jest.unstable_mockModule("uuid", async () => ({
26-
__esModule: true,
27-
v4: mockUuidv4
28-
}))
29-
3024
let tokenExchange: (logger: Logger, axiosInstance: AxiosInstance, host: string) => Promise<string>
3125
beforeAll(async () => {
3226
({tokenExchange} = await import("../src/utils/auth"))
@@ -69,9 +63,6 @@ describe("tokenExchange", () => {
6963
}
7064
mockSignJWTConstructor.mockImplementation(() => fakeJwtInstance)
7165

72-
// Mock uuid
73-
mockUuidv4.mockReturnValue("uuid-1234")
74-
7566
// Mock the HTTP call
7667
nock(`${host}`)
7768
.post("/oauth2/token", (body) => {
@@ -123,7 +114,6 @@ describe("tokenExchange", () => {
123114
},
124115
sign: jest.fn().mockImplementation(() => Promise.resolve("jwt-tkn"))
125116
}))
126-
mockUuidv4.mockReturnValue("uid")
127117

128118
nock(`${host}`)
129119
.post("/oauth2/token")
@@ -149,7 +139,6 @@ describe("tokenExchange", () => {
149139
},
150140
sign: jest.fn().mockImplementation(() => Promise.resolve("jwt-tkn"))
151141
}))
152-
mockUuidv4.mockReturnValue("uid")
153142

154143
nock(`${host}`)
155144
.post("/oauth2/token")

packages/nhsNotifyLambda/tests/testHelpers.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import {jest} from "@jest/globals"
22

33
import * as sqs from "@aws-sdk/client-sqs"
44

5-
import {v4} from "uuid"
6-
75
import {PSUDataItem} from "@PrescriptionStatusUpdate_common/commonTypes"
86
import {NotifyDataItemMessage} from "../src/utils"
97

@@ -25,7 +23,7 @@ export function constructMessage(overrides: Partial<sqs.Message> = {}): sqs.Mess
2523
return {
2624
MessageId: "messageId",
2725
Attributes: {
28-
MessageDeduplicationId: v4()
26+
MessageDeduplicationId: crypto.randomUUID()
2927
},
3028
Body: JSON.stringify(constructPSUDataItem()),
3129
...overrides
@@ -36,9 +34,9 @@ export function constructPSUDataItemMessage(overrides: Partial<NotifyDataItemMes
3634
return {
3735
...constructMessage(),
3836
PSUDataItem: constructPSUDataItem(),
39-
messageBatchReference: v4(),
40-
messageReference: v4(),
41-
notifyMessageId: v4(),
37+
messageBatchReference: crypto.randomUUID(),
38+
messageReference: crypto.randomUUID(),
39+
notifyMessageId: crypto.randomUUID(),
4240
...overrides
4341
}
4442
}

packages/updatePrescriptionStatus/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
"@middy/core": "^6.4.5",
2323
"@middy/http-header-normalizer": "^6.4.5",
2424
"@middy/input-output-logger": "^6.4.5",
25-
"@nhs/fhir-middy-error-handler": "^2.1.51",
26-
"uuid": "^13.0.0"
25+
"@nhs/fhir-middy-error-handler": "^2.1.51"
2726
},
2827
"devDependencies": {
2928
"@faker-js/faker": "^10.0.0",

packages/updatePrescriptionStatus/tests/testUpdatePrescriptionStatus.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
} from "@jest/globals"
88

99
import {BundleEntry} from "fhir/r4"
10-
import {v4} from "uuid"
1110

1211
import {badRequest, conflictDuplicate} from "../src/utils/responses"
1312
import {
@@ -210,7 +209,7 @@ describe("handleTransactionCancelledException", () => {
210209
describe("buildDataItems", () => {
211210
it("should uppercase LineItemId, PharmacyODSCode and PrescriptionID", () => {
212211
const task = validTask()
213-
const lineItemID = v4().toUpperCase()
212+
const lineItemID = crypto.randomUUID().toUpperCase()
214213
const pharmacyODSCode = "X26"
215214
const prescriptionID = "4F00A8-A83008-2EB4D"
216215

0 commit comments

Comments
 (0)