feat(medusa): add if statement to idempotency-key initialize (#3555)

* add if statement to idempotency-key initialize

* add changeset
This commit is contained in:
Philip Korsholm authored and GitHub committed 2023-03-22 21:34:50 +01:00
1 parent 74bc4b16a0
commit 3171b0e518
2 files changed
+15 -7

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
fix(medusa): if no headerkey is provided when initilizing idempotency key, no attempt is made at fetching the key
@@ -1,16 +1,17 @@
import { isDefined, MedusaError } from "medusa-core-utils"
import { v4 } from "uuid"
import { TransactionBaseService } from "../interfaces"
import { DeepPartial, EntityManager } from "typeorm"
import { IdempotencyKeyRepository } from "../repositories/idempotency-key"
import { IdempotencyKey } from "../models"
import { import {
CreateIdempotencyKeyInput, CreateIdempotencyKeyInput,
IdempotencyCallbackResult, IdempotencyCallbackResult,
} from "../types/idempotency-key" } from "../types/idempotency-key"
import { Selector } from "../types/common" import { DeepPartial, EntityManager } from "typeorm"
import { MedusaError, isDefined } from "medusa-core-utils"
import { buildQuery, isString } from "../utils" import { buildQuery, isString } from "../utils"
import { IdempotencyKey } from "../models"
import { IdempotencyKeyRepository } from "../repositories/idempotency-key"
import { Selector } from "../types/common"
import { TransactionBaseService } from "../interfaces"
import { v4 } from "uuid"
const KEY_LOCKED_TIMEOUT = 1000 const KEY_LOCKED_TIMEOUT = 1000
type InjectedDependencies = { type InjectedDependencies = {
@@ -43,10 +44,12 @@ class IdempotencyKeyService extends TransactionBaseService {
reqPath: string reqPath: string
): Promise<IdempotencyKey> { ): Promise<IdempotencyKey> {
return await this.atomicPhase_(async () => { return await this.atomicPhase_(async () => {
if (headerKey) {
const key = await this.retrieve(headerKey).catch(() => void 0) const key = await this.retrieve(headerKey).catch(() => void 0)
if (key) { if (key) {
return key return key
} }
}
return await this.create({ return await this.create({
request_method: reqMethod, request_method: reqMethod,
request_params: reqParams, request_params: reqParams,