Skip to main content

Class: IdempotencyKeyService

Hierarchy

  • TransactionBaseService

    IdempotencyKeyService

Constructors

constructor

new IdempotencyKeyService(__namedParameters)

Parameters

NameType
__namedParametersInjectedDependencies

Overrides

TransactionBaseService.constructor

Defined in

packages/medusa/src/services/idempotency-key.ts:25

Properties

__configModule__

Protected Optional Readonly __configModule__: Record<string, unknown>

Inherited from

TransactionBaseService.__configModule__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:10


__container__

Protected Readonly __container__: any

Inherited from

TransactionBaseService.__container__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:9


__moduleDeclaration__

Protected Optional Readonly __moduleDeclaration__: Record<string, unknown>

Inherited from

TransactionBaseService.__moduleDeclaration__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:11


idempotencyKeyRepository_

Protected Readonly idempotencyKeyRepository_: typeof IdempotencyKeyRepository

Defined in

packages/medusa/src/services/idempotency-key.ts:23


manager_

Protected manager_: EntityManager

Overrides

TransactionBaseService.manager_

Defined in

packages/medusa/src/services/idempotency-key.ts:20


transactionManager_

Protected transactionManager_: undefined | EntityManager

Overrides

TransactionBaseService.transactionManager_

Defined in

packages/medusa/src/services/idempotency-key.ts:21

Methods

atomicPhase_

Protected atomicPhase_<TResult, TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise<TResult>

Wraps some work within a transactional block. If the service already has a transaction manager attached this will be reused, otherwise a new transaction manager is created.

Type parameters

Name
TResult
TError

Parameters

NameTypeDescription
work(transactionManager: EntityManager) => Promise<TResult>the transactional work to be done
isolationOrErrorHandler?IsolationLevel | (error: TError) => Promise<void | TResult>the isolation level to be used for the work.
maybeErrorHandlerOrDontFail?(error: TError) => Promise<void | TResult>Potential error handler

Returns

Promise<TResult>

the result of the transactional work

Inherited from

TransactionBaseService.atomicPhase_

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:50


create

create(payload): Promise<IdempotencyKey>

Creates an idempotency key for a request. If no idempotency key is provided in request, we will create a unique identifier.

Parameters

NameTypeDescription
payloadCreateIdempotencyKeyInputpayload of request to create idempotency key for

Returns

Promise<IdempotencyKey>

the created idempotency key

Defined in

packages/medusa/src/services/idempotency-key.ts:67


initializeRequest

initializeRequest(headerKey, reqMethod, reqParams, reqPath): Promise<IdempotencyKey>

Execute the initial steps in a idempotent request.

Parameters

NameTypeDescription
headerKeystringpotential idempotency key from header
reqMethodstringmethod of request
reqParamsRecord<string, unknown>params of request
reqPathstringpath of request

Returns

Promise<IdempotencyKey>

the existing or created idempotency key

Defined in

packages/medusa/src/services/idempotency-key.ts:41


lock

lock(idempotencyKey): Promise<IdempotencyKey>

Locks an idempotency.

Parameters

NameTypeDescription
idempotencyKeystringkey to lock

Returns

Promise<IdempotencyKey>

result of the update operation

Defined in

packages/medusa/src/services/idempotency-key.ts:116


retrieve

retrieve(idempotencyKey): Promise<IdempotencyKey>

Retrieves an idempotency key

Parameters

NameTypeDescription
idempotencyKeystringkey to retrieve

Returns

Promise<IdempotencyKey>

idempotency key

Defined in

packages/medusa/src/services/idempotency-key.ts:85


shouldRetryTransaction_

Protected shouldRetryTransaction_(err): boolean

Parameters

NameType
errRecord<string, unknown> | { code: string }

Returns

boolean

Inherited from

TransactionBaseService.shouldRetryTransaction_

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:31


update

update(idempotencyKey, update): Promise<IdempotencyKey>

Locks an idempotency.

Parameters

NameTypeDescription
idempotencyKeystringkey to update
updateObjectupdate object
update.created_at?{ toString?: {} | undefined; toDateString?: {} | undefined; toTimeString?: {} | undefined; toLocaleString?: {} | undefined; toLocaleDateString?: {} | undefined; toLocaleTimeString?: {} | undefined; ... 37 more ...; [Symbol.toPrimitive]?: {} | undefined; }-
update.id?string-
update.idempotency_key?string-
update.locked_at?{ toString?: {} | undefined; toDateString?: {} | undefined; toTimeString?: {} | undefined; toLocaleString?: {} | undefined; toLocaleDateString?: {} | undefined; toLocaleTimeString?: {} | undefined; ... 37 more ...; [Symbol.toPrimitive]?: {} | undefined; }-
update.recovery_point?string-
update.request_method?string-
update.request_params?{ [x: string]: unknown; }-
update.request_path?string-
update.response_body?{ [x: string]: unknown; }-
update.response_code?number-

Returns

Promise<IdempotencyKey>

result of the update operation

Defined in

packages/medusa/src/services/idempotency-key.ts:145


withTransaction

withTransaction(transactionManager?): IdempotencyKeyService

Parameters

NameType
transactionManager?EntityManager

Returns

IdempotencyKeyService

Inherited from

TransactionBaseService.withTransaction

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:14


workStage

workStage(idempotencyKey, callback): Promise<IdempotencyKey>

Performs an atomic work stage. An atomic work stage contains some related functionality, that needs to be transactionally executed in isolation. An idempotent request will always consist of 2 or more of these phases. The required phases are "started" and "finished".

Parameters

NameTypeDescription
idempotencyKeystringcurrent idempotency key
callback(transactionManager: EntityManager) => Promise<IdempotencyCallbackResult>functionality to execute within the phase

Returns

Promise<IdempotencyKey>

new updated idempotency key

Defined in

packages/medusa/src/services/idempotency-key.ts:174