Skip to content
Merged
Show file tree
Hide file tree
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
44 changes: 44 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,50 @@
"types": "./src/credentials-exchange/v2/index.d.ts",
"default": null
},
"./credentials-exchange/v2/test": {
"types": "./src/credentials-exchange/v2/test/index.d.ts",
"default": "./src/credentials-exchange/v2/test/index.js"
},
"./custom-email-provider/v1": {
"types": "./src/custom-email-provider/v1/index.d.ts",
"default": null
},
"./custom-email-provider/v1/test": {
"types": "./src/custom-email-provider/v1/test/index.d.ts",
"default": "./src/custom-email-provider/v1/test/index.js"
},
"./custom-phone-provider/v1": {
"types": "./src/custom-phone-provider/v1/index.d.ts",
"default": null
},
"./custom-phone-provider/v1/test": {
"types": "./src/custom-phone-provider/v1/test/index.d.ts",
"default": "./src/custom-phone-provider/v1/test/index.js"
},
"./custom-token-exchange/v1": {
"types": "./src/custom-token-exchange/v1/index.d.ts",
"default": null
},
"./custom-token-exchange/v1/test": {
"types": "./src/custom-token-exchange/v1/test/index.d.ts",
"default": "./src/custom-token-exchange/v1/test/index.js"
},
"./event-stream/v1": {
"types": "./src/event-stream/v1/index.d.ts",
"default": null
},
"./event-stream/v1/test": {
"types": "./src/event-stream/v1/test/index.d.ts",
"default": "./src/event-stream/v1/test/index.js"
},
"./password-reset-post-challenge/v1": {
"types": "./src/password-reset-post-challenge/v1/index.d.ts",
"default": null
},
"./password-reset-post-challenge/v1/test": {
"types": "./src/password-reset-post-challenge/v1/test/index.d.ts",
"default": "./src/password-reset-post-challenge/v1/test/index.js"
},
"./post-change-password/v1": {
"types": "./src/post-change-password/v1/index.d.ts",
"default": null
Expand All @@ -64,6 +88,10 @@
"types": "./src/post-change-password/v2/index.d.ts",
"default": null
},
"./post-change-password/v2/test": {
"types": "./src/post-change-password/v2/test/index.d.ts",
"default": "./src/post-change-password/v2/test/index.js"
},
"./post-login/v1": {
"types": "./src/post-login/v1/index.d.ts",
"default": null
Expand All @@ -76,6 +104,10 @@
"types": "./src/post-login/v3/index.d.ts",
"default": null
},
"./post-login/v3/test": {
"types": "./src/post-login/v3/test/index.d.ts",
"default": "./src/post-login/v3/test/index.js"
},
"./post-user-registration/v1": {
"types": "./src/post-user-registration/v1/index.d.ts",
"default": null
Expand All @@ -84,6 +116,10 @@
"types": "./src/post-user-registration/v2/index.d.ts",
"default": null
},
"./post-user-registration/v2/test": {
"types": "./src/post-user-registration/v2/test/index.d.ts",
"default": "./src/post-user-registration/v2/test/index.js"
},
"./pre-user-registration/v1": {
"types": "./src/pre-user-registration/v1/index.d.ts",
"default": null
Expand All @@ -92,13 +128,21 @@
"types": "./src/pre-user-registration/v2/index.d.ts",
"default": null
},
"./pre-user-registration/v2/test": {
"types": "./src/pre-user-registration/v2/test/index.d.ts",
"default": "./src/pre-user-registration/v2/test/index.js"
},
"./send-phone-message/v1": {
"types": "./src/send-phone-message/v1/index.d.ts",
"default": null
},
"./send-phone-message/v2": {
"types": "./src/send-phone-message/v2/index.d.ts",
"default": null
},
"./send-phone-message/v2/test": {
"types": "./src/send-phone-message/v2/test/index.d.ts",
"default": "./src/send-phone-message/v2/test/index.js"
}
}
}
93 changes: 93 additions & 0 deletions src/_shared/Bi7NRjgy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
'use strict';

var index = require('./DvTaCl9e.js');

const { assertValidScope, MAX_SCOPE_COUNT_LIMIT } = index.helpers.accessToken;
/**
* Implements the {@link TargetScopesAPI} for managing target scopes: validates
* arguments, tracks the scope set, and delegates to a
* {@link TargetScopesWriterAPI} to record the resulting command.
*
* Note: commands are recorded before the local scope set is updated, so a
* writer failure leaves the scope set unchanged.
*/
class TargetScopesAPIImpl {
#scopesWriter;
#targetScopes;
constructor(scopesWriter, initialTargetScopes) {
this.#scopesWriter = scopesWriter;
this.#targetScopes = new Set(initialTargetScopes);
}
addTargetScope(scope) {
if (typeof scope !== 'string') {
throw new TypeError('The value for the scope must be a string.');
}
const trimmedScope = scope.trim();
assertValidScope(trimmedScope);
if (!this.#targetScopes.has(trimmedScope) && this.#targetScopes.size >= MAX_SCOPE_COUNT_LIMIT) {
throw new Error(`The number of scopes exceeds the allowed maximum of ${MAX_SCOPE_COUNT_LIMIT}.`);
}
this.#scopesWriter.addTargetScope(trimmedScope);
this.#targetScopes.add(trimmedScope);
}
removeTargetScope(scope) {
if (typeof scope !== 'string') {
throw new TypeError('The value for the scope must be a string.');
}
const trimmedScope = scope.trim();
assertValidScope(trimmedScope);
this.#scopesWriter.removeTargetScope(trimmedScope);
this.#targetScopes.delete(trimmedScope);
}
setTargetScopes(scopes) {
if (!Array.isArray(scopes)) {
throw new TypeError('The value for scopes must be an array.');
}
// Empty array is a valid input and should clear all target scopes
if (scopes.length === 0) {
return this.clearTargetScopes();
}
for (const scope of scopes) {
if (typeof scope !== 'string') {
throw new TypeError('The value for the scope must be a string.');
}
assertValidScope(scope.trim());
}
const uniqueScopes = [...new Set(scopes.map((s) => s.trim()))];
if (uniqueScopes.length > MAX_SCOPE_COUNT_LIMIT) {
throw new Error(`The number of scopes exceeds the allowed maximum of ${MAX_SCOPE_COUNT_LIMIT}.`);
}
this.#scopesWriter.setTargetScopes(uniqueScopes);
this.#targetScopes.clear();
for (const s of uniqueScopes) {
this.#targetScopes.add(s);
}
}
clearTargetScopes() {
this.#scopesWriter.clearTargetScopes();
this.#targetScopes.clear();
}
getTargetScopes() {
// Return a copy to prevent external mutation of the scope set
return [...this.#targetScopes];
}
}
/**
* A no-op {@link TargetScopesWriterAPI}. Backs stub trigger APIs so the target
* scope methods still validate and reads still reflect prior writes.
*/
class NoopTargetScopesWriterAPI {
addTargetScope(_scope) { }
removeTargetScope(_scope) { }
setTargetScopes(_scopes) { }
clearTargetScopes() { }
}
/**
* Creates a {@link TargetScopesAPI} backed by {@link NoopTargetScopesWriterAPI}
* for use in stub trigger API implementations.
*/
function createNoopTargetScopesAPI(initialTargetScopes = []) {
return new TargetScopesAPIImpl(new NoopTargetScopesWriterAPI(), initialTargetScopes);
}

exports.createNoopTargetScopesAPI = createNoopTargetScopesAPI;
118 changes: 118 additions & 0 deletions src/_shared/BquXyhu2.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
interface Handler {
(...args: any[]): Promise<void>;
}
interface Execution {
/** Returns all stdout/stderr output written by the action via console. */
getLogs(): string;
}
/** An actions: module to register up front, so the action can require('actions:<name>'). */
interface ModuleRegistration {
name: string;
filename: string;
secrets?: Record<string, string>;
}
interface LoadedAction<TModule extends Record<string, Handler>> {
/** Invokes the loaded action's export named `entrypoint`, e.g. `action.execute('onExecutePostLogin', event, api)`. */
execute<K extends keyof TModule & string>(
entrypoint: K,
...args: Parameters<TModule[K]>
): Promise<Execution>;
}
type CacheWriteErrorCode =
| 'MaxSideEffectsExceeded'
| 'CacheKeySizeExceeded'
| 'CacheValueSizeExceeded'
| 'CacheSizeExceeded'
| 'ItemAlreadyExpired'
| 'InvalidExpiry'
| 'FailedToSetCacheRecord'
| 'FailedToDeleteCacheRecord'
| 'CacheKeyDoesNotExist';
/**
* Details about a cached value.
*/
interface CacheRecord {
/**
* The cached value itself.
*/
value: string;
/**
* Expiry time in milliseconds since the unix epoch.
*/
expires_at: number;
}
interface CacheWriteSuccess {
type: 'success';
record: CacheRecord;
}
interface CacheWriteError {
type: 'error';
code: CacheWriteErrorCode;
}
type CacheWriteResult = CacheWriteSuccess | CacheWriteError;
interface CacheDeleteSuccess {
type: 'success';
}
type CacheDeleteResult = CacheDeleteSuccess | CacheWriteError;
interface CacheSetOptions {
/**
* The absolute expiry time in milliseconds since the unix epoch.
* While cached records may be evicted earlier, they will
* never remain beyond the supplied `expires_at`.
*
* *Note*: This value should not be supplied if a value was also
* provided for `ttl`. If both options are supplied, the
* earlier expiry of the two will be used.
*/
expires_at?: number;
/**
* The time-to-live value of this cache entry in milliseconds.
* While cached values may be evicted earlier, they will
* never remain beyond the supplied `ttl`.
*
* *Note*: This value should not be supplied if a value was also
* provided for `expires_at`. If both options are supplied, the
* earlier expiry of the two will be used.
*/
ttl?: number;
}
/**
* Methods and utilities to manage the Actions cache.
*/
interface CacheAPI {
/**
* Delete a record describing a cached value at the supplied
* key if it exists.
*
* @param key The key of the cache record to delete.
*/
delete(key: string): CacheDeleteResult;
/**
* Retrieve a record describing a cached value at the supplied key,
* if it exists. If a record is found, the cached value can be found
* at the `value` property of the returned object.
*
* @param key The key of the record stored in the cache.
*/
get(key: string): CacheRecord | undefined;
/**
* Store or update a string value in the cache at the specified key.
*
* Values stored in this cache are scoped to the Trigger in which they
* are set. They are subject to the {@link https://auth0.com/docs/customize/actions/limitations Actions Cache Limits}.
*
* Values stored in this way will have lifetimes of _up to_ the specified
* `ttl` or `expires_at` values. If no lifetime is specified, a default of
* lifetime of 15 minutes will be used. Lifetimes may not exceed the maximum
* duration listed at {@link https://auth0.com/docs/customize/actions/limitations Actions Cache Limits}.
*
* **Important**: This cache is designed for short-lived, ephemeral data. Items may not be
* available in later transactions even if they are within their supplied their lifetime.
*
* @param key The key of the record to be stored.
* @param value The value of the record to be stored.
* @param options Options for adjusting cache behavior.
*/
set(key: string, value: string, options?: CacheSetOptions): CacheWriteResult;
}
export type { CacheAPI as C, LoadedAction as L, ModuleRegistration as M };
Loading