import type { IdempotencyKeyOptions, IdempotencyKeyScope } from "./idempotency-key-catalog/catalog.js"; import type { IdempotencyKey } from "./types/idempotencyKeys.js"; import type { ZodFetchOptions } from "./apiClient/core.js"; export type { IdempotencyKeyScope, IdempotencyKeyOptions, } from "./idempotency-key-catalog/catalog.js"; /** * Extracts the user-provided key and scope from an idempotency key created with `idempotencyKeys.create()`. * * @param idempotencyKey The idempotency key to extract options from * @returns The original key and scope, or undefined if the key doesn't have attached options * * @example * ```typescript * const key = await idempotencyKeys.create("my-key", { scope: "global" }); * const options = getIdempotencyKeyOptions(key); * // options = { key: "my-key", scope: "global" } * ``` */ export declare function getIdempotencyKeyOptions(idempotencyKey: IdempotencyKey | string): IdempotencyKeyOptions | undefined; /** * Clears the in-process idempotency key catalog. * * The catalog maps an idempotency-key hash back to its original key and scope so * the SDK can attach that metadata when triggering. The worker calls this at each * run boundary so the mapping does not accumulate across warm-start runs. */ export declare function resetIdempotencyKeyCatalog(): void; export declare function isIdempotencyKey(value: string | string[] | IdempotencyKey): value is IdempotencyKey; export declare function flattenIdempotencyKey(idempotencyKey?: IdempotencyKey | string | string[] | (undefined | IdempotencyKey | string | string[])[]): IdempotencyKey | string | string[] | undefined; export declare function makeIdempotencyKey(idempotencyKey?: IdempotencyKey | string | string[]): Promise; /** * Creates a deterministic idempotency key based on the provided key material. * * If running inside a task, the task run ID is automatically included in the key material, giving you a unique key per task run. * This ensures that a given child task is only triggered once per task run, even if the parent task is retried. * * @param {string | string[]} key The key material to create the idempotency key from. * @param {object} [options] Additional options. * @param {"run" | "attempt" | "global"} [options.scope="run"] The scope of the idempotency key. * * @returns {Promise} The idempotency key as a branded string. * * @example * * ```typescript * import { idempotencyKeys, task } from "@trigger.dev/sdk/v3"; * * export const myTask = task({ * id: "my-task", * run: async (payload: any) => { * const idempotencyKey = await idempotencyKeys.create("my-task-key"); * * // Use the idempotency key when triggering child tasks * await childTask.triggerAndWait(payload, { idempotencyKey }); * } * }); * ``` * * You can also use the `scope` parameter to create a key that is unique per task run, task run attempts (retries of the same run), or globally: * * ```typescript * await idempotencyKeys.create("my-task-key", { scope: "attempt" }); // Creates a key that is unique per task run attempt * await idempotencyKeys.create("my-task-key", { scope: "global" }); // Skips including the task run ID * ``` */ export declare function createIdempotencyKey(key: string | string[], options?: { scope?: IdempotencyKeyScope; }): Promise; type AttemptKeyMaterial = { run: { id: string; }; attempt: { number: number; }; }; /** Creates a unique key for each attempt. */ export declare function attemptKey(ctx: AttemptKeyMaterial): string; export type ResetIdempotencyKeyOptions = { scope?: IdempotencyKeyScope; /** Required if scope is "run" or "attempt" to reconstruct the hash */ parentRunId?: string; /** Required if scope is "attempt" to reconstruct the hash */ attemptNumber?: number; }; /** * Resets an idempotency key, effectively deleting it from the associated task. * * @param taskIdentifier The task identifier (e.g., "my-task") * @param idempotencyKey The idempotency key to reset. Can be: * - An `IdempotencyKey` created with `idempotencyKeys.create()` (options are extracted automatically) * - A string or string array (requires `options.scope` and potentially `options.parentRunId`) * @param options Options for reconstructing the hash if needed * @param requestOptions Optional fetch options * * @example * ```typescript * // Using a key created with idempotencyKeys.create() - options are extracted automatically * const key = await idempotencyKeys.create("my-key", { scope: "global" }); * await idempotencyKeys.reset("my-task", key); * * // Using a raw string with global scope * await idempotencyKeys.reset("my-task", "my-key", { scope: "global" }); * * // Using a raw string with run scope (requires parentRunId) * await idempotencyKeys.reset("my-task", "my-key", { * scope: "run", * parentRunId: "run_abc123" * }); * ``` */ export declare function resetIdempotencyKey(taskIdentifier: string, idempotencyKey: IdempotencyKey | string | string[], options?: ResetIdempotencyKeyOptions, requestOptions?: ZodFetchOptions): Promise<{ id: string; }>;