Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/custom-token-exchange/v1/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ type CustomTokenExchangeV1Event = {
} & {
[additionalProperties: string]: any;
};
/** [Early Access] An object containing shared data across custom Actions for the duration of a transaction. */
metadata?: {
[additionalProperties: string]: string | number | boolean;
};
/** The scopes requested (if any) provided in the token exchange request. */
requested_scopes: string[];
/** The type of token to be generated by Auth0. For example: urn:ietf:params:oauth:token-type:access_token. */
Expand Down Expand Up @@ -287,6 +291,7 @@ type CustomTokenExchangeSetUserByConnectionUserAttributes = {
} & {
[additionalProperties: string]: any;
};
type TxMetadataValue = string | boolean | number;
/** Recursively defines nested actor levels, terminating when the depth tuple is exhausted. */
type NestedActor<D extends unknown[] = [1, 2, 3, 4]> = D extends [unknown, ...infer Rest]
? {
Expand Down Expand Up @@ -569,6 +574,34 @@ interface AuthenticationAPI {
*/
setActor(actor: ActorParams): void;
}
interface TransactionAPI {
/**
* [Early Access] Store or update the value in the transaction metadata for a specified key.
*
* Metadata modified using this method is updated in real-time in the
* `event.transaction.metadata` object.
*
* @param key The key of the property to be set.
* @param value The value of the property. This may be set to `null` to remove the
* metadata property.
*
* @example
* ```js
* exports.onExecuteCustomTokenExchange = async (event, api) => {
* // Store data to share across Actions for the duration of the transaction.
* api.transaction.setMetadata('subject_verified', true);
* api.transaction.setMetadata('risk_score', 42);
*
* // Read it back from the event in real-time.
* console.log(event.transaction.metadata.risk_score); // 42
*
* // Remove a previously set property by passing `null`.
* api.transaction.setMetadata('risk_score', null);
* };
* ```
*/
setMetadata(key: string, value: TxMetadataValue | null): void;
}
interface UserAPI {
/**
* Set application-specific metadata for the user corresponding to the subject token.
Expand Down Expand Up @@ -639,6 +672,10 @@ interface CustomTokenExchangeAPI {
* Store and retrieve data that persists across executions.
*/
readonly cache: CacheAPI;
/**
* [Early Access] Make changes to the transaction.
*/
readonly transaction: TransactionAPI;
}
interface CustomTokenExchangeAction {
(event: Event, api: CustomTokenExchangeAPI): Promise<void>;
Expand Down