@flatfile/listener
Advanced tools
Comparing version 0.3.15 to 0.3.16
@@ -1,296 +0,11 @@ | ||
import { Event, RecordsWithLinks } from '@flatfile/api/api'; | ||
import { Flatfile } from '@flatfile/api'; | ||
declare class AuthenticatedClient { | ||
_accessToken?: string; | ||
_apiUrl?: string; | ||
constructor(accessToken?: string, apiUrl?: string); | ||
fetch(url: string, options?: any): Promise<any>; | ||
/** | ||
* | ||
* @deprecated use @flatfile/cross-env-config instead | ||
*/ | ||
setVariables({ accessToken, apiUrl, }: { | ||
accessToken?: string; | ||
apiUrl?: string; | ||
}): void; | ||
} | ||
declare class EventCache { | ||
private eventCache; | ||
init<T>(key: string, callback: () => Promise<T>): Promise<T>; | ||
set<T>(key: string, callback: () => Promise<T>): Promise<T>; | ||
get<T>(key: string): T; | ||
delete(key?: string | string[]): void; | ||
} | ||
type GetDataOptions = { | ||
[key: string]: any; | ||
}; | ||
interface GetData extends Function { | ||
(options?: GetDataOptions): Promise<any>; | ||
then<TResult1 = any, TResult2 = any>(onfulfilled?: ((value: any) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>; | ||
} | ||
declare class FlatfileEvent extends AuthenticatedClient { | ||
readonly src: Event; | ||
/** | ||
* Event ID from the API | ||
* | ||
* @example us0_ev_82hgidh9skd | ||
* @readonly | ||
* | ||
*/ | ||
readonly id?: string; | ||
/** | ||
* Topic the event was produced on | ||
* | ||
* @example workbook:created | ||
* @readonly | ||
*/ | ||
readonly topic: string; | ||
readonly domain: string; | ||
readonly target: string; | ||
readonly origin: object; | ||
readonly action: string; | ||
readonly context: any; | ||
readonly payload: any; | ||
readonly cache: EventCache; | ||
readonly namespace: string[]; | ||
readonly createdAt?: Date; | ||
/** | ||
* Fetch record data from Flatfile API via the event's dataUrl | ||
* | ||
* @async | ||
* @param {object} options | ||
* @returns {Promise<any>} JSON | ||
*/ | ||
data: GetData; | ||
constructor(src: Event, accessToken?: string, apiUrl?: string); | ||
/** | ||
* Should return either event body if expanded already or fetch data from the | ||
* signed dataURL | ||
*/ | ||
private fetchData; | ||
private afterAllCallbacks; | ||
afterAll<T>(callback: () => T, cacheKey?: string): void; | ||
update(records: RecordsWithLinks): Promise<void>; | ||
/** | ||
* Fetch the Secrets as indicated by this event context | ||
* | ||
* @param key - The name of the secret to fetch | ||
* @param options - (Optional) environmentId and spaceId to override event context | ||
* | ||
* @returns The value of the secret (usually a credential or token) | ||
*/ | ||
secrets(key: string, options?: { | ||
environmentId?: string; | ||
spaceId?: string; | ||
}): Promise<string>; | ||
} | ||
type EventCallback = (evt: FlatfileEvent) => void; | ||
import { FlatfileListener } from './flatfile.listener'; | ||
export * from './flatfile.listener'; | ||
export * from './event-drivers'; | ||
export * from './events'; | ||
/** | ||
* EventHandler is a Flatfile flavored implementation of EventTarget | ||
*/ | ||
declare class EventHandler extends AuthenticatedClient { | ||
/** | ||
* Apply a filter to the values of an event | ||
*/ | ||
readonly filterQuery?: EventFilter; | ||
/** | ||
* Cache of registered listeners on this instance | ||
* @private | ||
*/ | ||
protected listeners: [string | string[], EventFilter, EventCallback][]; | ||
constructor(filter?: EventFilter, accessToken?: string, apiUrl?: string); | ||
/** | ||
* Cache of registered child nodes for this listener. These nodes will | ||
* only receive events that pass the parent filter. | ||
* | ||
* @private | ||
*/ | ||
protected nodes: EventHandler[]; | ||
/** | ||
* Register a subscriber for events that match this path | ||
*/ | ||
on(query: Arrayable<string>, callback: EventCallback): this; | ||
on(query: Arrayable<string>, filter: EventFilter, callback: EventCallback): this; | ||
/** | ||
* Add child nodes to send this event to as well | ||
* | ||
* @param node | ||
*/ | ||
addNode(node: EventHandler): this; | ||
/** | ||
* Dispatch an event and resolve the promise once it has completed (or | ||
* errored | ||
* | ||
* @todo - is there a right order in which to resolve event listeners? | ||
* Should it matter? | ||
* | ||
* @param event | ||
*/ | ||
dispatchEvent(event: FlatfileEvent | Flatfile.Event | any): Promise<void>; | ||
/** | ||
* @deprecated legacy shim for receiving events from the VM layer | ||
* @alias dispatchEvent | ||
* @param event | ||
*/ | ||
routeEvent(event: Flatfile.Event): Promise<void>; | ||
/** | ||
* Actually trigger the event listeners on this particular target | ||
* | ||
* @note It is safer for now to run this in series to avoid IO locks and | ||
* potential race conditions and uncaught errors | ||
* | ||
* @param event | ||
* @param recursive | ||
*/ | ||
trigger(event: FlatfileEvent, recursive?: boolean): Promise<void>; | ||
/** | ||
* Get any listeners from this target subscribing to this event | ||
* | ||
* @param event | ||
* @param recursive | ||
*/ | ||
getListeners(event: FlatfileEvent, recursive?: boolean): Listener[]; | ||
/** | ||
* Attach more event listeners using a callback function. Used most | ||
* frequently for plugins. | ||
* | ||
* @param fn | ||
*/ | ||
use(fn: (handler: this) => void): this; | ||
/** | ||
* Filter an event out based on glob filter object | ||
* | ||
* @param event | ||
* @param filter | ||
*/ | ||
matchEvent(event: FlatfileEvent, filter: EventFilter | undefined): boolean; | ||
} | ||
type EventFilter = Record<string, any>; | ||
type Arrayable<T> = T | Array<T>; | ||
type Listener = { | ||
query: string | string[]; | ||
filter: any; | ||
callback: EventCallback; | ||
}; | ||
declare abstract class EventDriver { | ||
_handler?: EventHandler; | ||
get handler(): EventHandler; | ||
/** | ||
* Mount an event handler | ||
* | ||
* @param handler | ||
*/ | ||
mountEventHandler(handler: EventHandler): this; | ||
/** | ||
* Dispatch an event | ||
* | ||
* @param e | ||
*/ | ||
dispatchEvent(e: any): this; | ||
} | ||
declare class Browser extends EventDriver { | ||
_accessToken?: string; | ||
_apiUrl?: string; | ||
_environmentId?: string; | ||
constructor({ apiUrl, accessToken, environmentId, }: { | ||
apiUrl: string; | ||
accessToken: string; | ||
environmentId?: string; | ||
/** | ||
* @deprecated | ||
*/ | ||
fetchApi: any; | ||
}); | ||
mountEventHandler(handler: EventHandler): this; | ||
} | ||
/** | ||
* Flatfile's Virtual Machine is stateless / serverless. So when a new event | ||
* is handled, it will just call `handle(event)`. | ||
*/ | ||
declare class FlatfileVirtualMachine extends EventDriver { | ||
/** | ||
* This method is triggered from within the Flatfile Core VM Runner. This | ||
* EventDriver does not have to listen for events because this method will | ||
* be invoked as necessary. | ||
* | ||
* @param event | ||
*/ | ||
handle(event: FlatfileEvent): void; | ||
mountEventHandler(handler: EventHandler): this; | ||
} | ||
/** | ||
* The Flatfile Listener | ||
* | ||
* The Flatfile PubSub Client is just a simple event subscriber. It can | ||
* receive events from any PubSub driver. The default drivers are: | ||
* | ||
* - Webhook (for simply processing events sent to URL) | ||
* - Websocket (for subscribing real time on an HTTP2 connection) | ||
* - Serverless (for stateless invocations via AWS Lambda or similar) | ||
* | ||
* Once an event is received, it is routed to any awaiting listeners which | ||
* are added with `addEventListener()` or its alias `on()`. | ||
* | ||
* Flatfile events follow a standard structure and event listeners can use | ||
* any of the following syntaxes to react to events within Flatfile. | ||
* | ||
* // listen to an event | ||
* addEventListener('entity:topic') | ||
* | ||
* // listen to an event on a specific namespace | ||
* addEventListener('entity:topic@namespace') | ||
* | ||
* // listen to a specific context on a namespace | ||
* addEventListener('entity:topic@namespace?context=us_sp_89234oihsdo') | ||
* | ||
* // filter by any | ||
* addEventListener('entity:topic@namespace?') | ||
* | ||
*/ | ||
declare class FlatfileListener extends EventHandler { | ||
/** | ||
* Subscribe to events only within a certain namespace. | ||
* | ||
* @param namespace | ||
* @param cb | ||
*/ | ||
namespace(namespaces: string | string[], cb?: SubFn<this>): this; | ||
/** | ||
* Filter by namespace | ||
* | ||
* @param filter | ||
* @param cb | ||
*/ | ||
filter(filter: EventFilter, cb?: SubFn<this>): this; | ||
/** | ||
* Start subscribing to events | ||
* | ||
* @param cb | ||
*/ | ||
static create<T extends FlatfileListener>(this: Constructor<T>, cb: SubFn<T>): T; | ||
/** | ||
* Mount this client using an acceptable Event Driver | ||
*/ | ||
mount(driver: EventDriver): this; | ||
} | ||
type SubFn<T extends FlatfileListener> = (client: T) => void; | ||
type Constructor<T> = { | ||
new (): T; | ||
}; | ||
/** | ||
* Backwards compatibility | ||
*/ | ||
declare class Client extends FlatfileListener { | ||
export declare class Client extends FlatfileListener { | ||
} | ||
export { Arrayable, AuthenticatedClient, Browser, Client, EventCallback, EventDriver, EventFilter, EventHandler, FlatfileEvent, FlatfileListener, FlatfileVirtualMachine, Listener }; | ||
export default FlatfileListener; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@flatfile/listener", | ||
"version": "0.3.15", | ||
"version": "0.3.16", | ||
"description": "A PubSub Listener for configuring and using Flatfile", | ||
"main": "dist/index.js", | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.mjs", | ||
@@ -10,5 +10,4 @@ "types": "dist/index.d.ts", | ||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist", | ||
"build": "tsup src/index.ts --format esm,cjs --dts", | ||
"dev": "tsup src/index.ts --format esm,cjs --dts --watch", | ||
"poll": "tsup src/dev.ts --format esm,cjs --watch --dts --onSuccess \"node dist/dev.js\"", | ||
"build": "rollup -c", | ||
"dev": "rollup -c --watch", | ||
"test": "jest --passWithNoTests" | ||
@@ -24,3 +23,4 @@ }, | ||
"@flatfile/ts-config-platform-sdk": "*", | ||
"@flatfile/cross-env-config": "*", | ||
"@rollup/plugin-commonjs": "^25.0.7", | ||
"@rollup/plugin-typescript": "^11.1.5", | ||
"@types/flat": "^5.0.2", | ||
@@ -30,10 +30,14 @@ "@types/jest": "^29.5.1", | ||
"jest": "^29.5.0", | ||
"rollup": "^2.79.1", | ||
"ts-jest": "^29.1.0", | ||
"tslib": "^2.4.1", | ||
"tsup": "^6.1.3", | ||
"typescript": "^5.0.4" | ||
}, | ||
"dependencies": { | ||
"@flatfile/cross-env-config": "^0.0.5", | ||
"@rollup/plugin-json": "^6.0.1", | ||
"@rollup/plugin-node-resolve": "^15.2.3", | ||
"ansi-colors": "^4.1.3", | ||
"flat": "^5.0.2" | ||
"flat": "^5.0.2", | ||
"wildcard-match": "^5.1.2" | ||
}, | ||
@@ -40,0 +44,0 @@ "peerDependencies": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
369417
43
11347
1
8
13
1
+ Added@rollup/plugin-json@^6.0.1
+ Addedwildcard-match@^5.1.2
+ Added@flatfile/cross-env-config@0.0.5(transitive)
+ Added@rollup/plugin-json@6.1.0(transitive)
+ Added@rollup/plugin-node-resolve@15.3.0(transitive)
+ Added@rollup/pluginutils@5.1.3(transitive)
+ Added@types/estree@1.0.6(transitive)
+ Added@types/resolve@1.20.2(transitive)
+ Addeddeepmerge@4.3.1(transitive)
+ Addedestree-walker@2.0.2(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-module@1.0.0(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpicomatch@4.0.2(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedwildcard-match@5.1.3(transitive)