Files
medusa-store/docs/content/references/services/classes/IdempotencyKeyService.md
Shahed Nasser a8293af8e1 fix: overlapping branch names for generated PRs of references (#2097)
* fix overlapping branch names of generated references

* regenerate references
2022-08-25 17:47:58 +03:00

9.1 KiB

Class: IdempotencyKeyService

Hierarchy

  • TransactionBaseService

    IdempotencyKeyService

Constructors

constructor

new IdempotencyKeyService(__namedParameters)

Parameters

Name Type
__namedParameters InjectedDependencies

Overrides

TransactionBaseService.constructor

Defined in

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

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


idempotencyKeyRepository_

Protected Readonly idempotencyKeyRepository_: typeof IdempotencyKeyRepository

Defined in

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


manager_

Protected manager_: EntityManager

Overrides

TransactionBaseService.manager_

Defined in

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


transactionManager_

Protected transactionManager_: undefined | EntityManager

Overrides

TransactionBaseService.transactionManager_

Defined in

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

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

Name Type Description
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

Name Type Description
payload CreateIdempotencyKeyInput payload of request to create idempotency key for

Returns

Promise<IdempotencyKey>

the created idempotency key

Defined in

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


initializeRequest

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

Execute the initial steps in a idempotent request.

Parameters

Name Type Description
headerKey string potential idempotency key from header
reqMethod string method of request
reqParams Record<string, unknown> params of request
reqPath string path of request

Returns

Promise<IdempotencyKey>

the existing or created idempotency key

Defined in

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


lock

lock(idempotencyKey): Promise<IdempotencyKey>

Locks an idempotency.

Parameters

Name Type Description
idempotencyKey string key to lock

Returns

Promise<IdempotencyKey>

result of the update operation

Defined in

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


retrieve

retrieve(idempotencyKey): Promise<IdempotencyKey>

Retrieves an idempotency key

Parameters

Name Type Description
idempotencyKey string key to retrieve

Returns

Promise<IdempotencyKey>

idempotency key

Defined in

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


shouldRetryTransaction_

Protected shouldRetryTransaction_(err): boolean

Parameters

Name Type
err Record<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

Name Type Description
idempotencyKey string key to update
update Object update 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:134


withTransaction

withTransaction(transactionManager?): IdempotencyKeyService

Parameters

Name Type
transactionManager? EntityManager

Returns

IdempotencyKeyService

Inherited from

TransactionBaseService.withTransaction

Defined in

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


workStage

workStage(idempotencyKey, callback): Promise<{ error?: unknown ; key?: 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

Name Type Description
idempotencyKey string current idempotency key
callback (transactionManager: EntityManager) => Promise<{ recovery_point?: string ; response_body?: Record<string, unknown> ; response_code?: number }> functionality to execute within the phase

Returns

Promise<{ error?: unknown ; key?: IdempotencyKey }>

new updated idempotency key

Defined in

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