Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@flatfile/listener

Package Overview
Dependencies
Maintainers
26
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@flatfile/listener - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

dist/index.cjs

6

CHANGELOG.md
# @flatfile/listener
## 0.0.9
### Patch Changes
- 46357d9: flatfile deploy and develop
## 0.0.8

@@ -4,0 +10,0 @@

21

dist/index.d.ts
import { FetchAPI, DefaultApi, Event } from '@flatfile/api';
declare class AuthenticatedClient {
private _accessToken?;
private _apiUrl?;
private _api?;
private _fetchApi?;
_accessToken?: string;
_apiUrl?: string;
fetchApi: FetchAPI;
constructor(accessToken?: string, apiUrl?: string);
get api(): DefaultApi;

@@ -48,3 +50,3 @@ fetch(url: string): any;

readonly cache: EventCache;
constructor(src: Event);
constructor(src: Event, accessToken?: string, apiUrl?: string);
/**

@@ -75,3 +77,3 @@ * Should return either event body if expanded already or fetch data from the

private listeners;
constructor(filter?: EventFilter);
constructor(filter?: EventFilter, accessToken?: string, apiUrl?: string);
/**

@@ -236,6 +238,9 @@ * Cache of registered child nodes for this listener. These nodes will

declare class PollingEventDriver extends EventDriver {
private options;
constructor(options: {
interval: number;
environmentId: string;
environmentId?: string;
apiUrl: string;
accessToken: string;
constructor({ environmentId, apiUrl, accessToken, }: {
environmentId?: string;
apiUrl?: string;
accessToken?: string;
});

@@ -242,0 +247,0 @@ start(): void;

{
"name": "@flatfile/listener",
"version": "0.0.8",
"version": "0.0.9",
"description": "A PubSub Listener for configuring and using Flatfile",

@@ -8,3 +8,5 @@ "main": "dist/index.js",

"types": "dist/index.d.ts",
"type": "module",
"scripts": {
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
"build": "tsup src/index.ts --format esm,cjs --dts",

@@ -37,4 +39,5 @@ "dev": "tsup src/index.ts --format esm,cjs --dts --watch",

"date-fns": "^2.29.1",
"node-fetch": "^2.6.7",
"xlsx": "^0.18.5"
}
}

@@ -16,2 +16,3 @@ import { EventDriver } from './_EventDriver'

*/
handle(event: FlatfileEvent) {

@@ -22,16 +23,2 @@ this.dispatchEvent(event)

mountEventHandler(handler: EventHandler): this {
const IS_NODE =
typeof global === 'object' &&
'[object global]' === global.toString.call(global)
const IS_BROWSER =
// @ts-ignore - ts says window is undefined here, but when mounted it is not
typeof window === 'object' &&
// @ts-ignore - ts says window is undefined here, but when mounted it is not
'[object Window]' === window.toString.call(window)
if (IS_NODE && !IS_BROWSER)
handler.setVariables({
fetchApi: require('node-fetch')
})
this._handler = handler

@@ -38,0 +25,0 @@ return this

@@ -0,10 +1,44 @@

import c from 'ansi-colors'
import { EventDriver } from './_EventDriver'
/**
* Todo: this should just be using the version from listener
*/
const events = new Map()
export class PollingEventDriver extends EventDriver {
constructor(private options: { interval: number; environmentId: string }) {
environmentId?: string
apiUrl: string
accessToken: string
constructor({
environmentId,
apiUrl,
accessToken,
}: {
environmentId?: string
apiUrl?: string
accessToken?: string
}) {
super()
this.apiUrl =
apiUrl ||
process.env.AGENT_INTERNAL_URL ||
'https://platform.flatfile.com/api/'
this.accessToken =
accessToken ||
process.env.FLATFILE_API_KEY ||
process.env.FLATFILE_BEARER_TOKEN ||
'...'
this.environmentId = environmentId || process.env.FLATFILE_ENVIRONMENT_ID
}
start() {
this.handler.setVariables({
accessToken: this.accessToken,
apiUrl: this.apiUrl,
})
let lastTimestamp = new Date()
if (!this.environmentId) {
throw new Error('environmentId is required')
}
setInterval(() => {

@@ -14,3 +48,4 @@ this.handler.api

since: lastTimestamp,
environmentId: this.options.environmentId,
includeAcknowledged: false,
environmentId: this.environmentId,
})

@@ -20,9 +55,21 @@ .then((res) => {

process.stdout.clearLine(1)
process.stdout.write(
`→ checked events at ${lastTimestamp.toISOString()} — ${
res.data?.length || 0
} found\n`
)
if (!res.data?.length) {
process.stdout.write(
`${c.white.bgMagentaBright(
'listening for events'
)} at ${lastTimestamp.toLocaleString()}`
)
}
res.data?.forEach((e) => {
this.dispatchEvent(e)
if (!events.get(e.id)) {
process.stdout.write(
`${c.white.bgBlue(e.topic)} ${c.white.bgYellow(
e.id
)} ${e.createdAt?.toLocaleString()}\n`
)
events.set(e.id, true)
this.dispatchEvent(e)
}
})

@@ -33,3 +80,3 @@ })

lastTimestamp = new Date()
}, this.options.interval)
}, 500)
}

@@ -36,0 +83,0 @@

import { Configuration, DefaultApi, FetchAPI } from '@flatfile/api'
import fetch from 'node-fetch'

@@ -7,8 +8,14 @@ const FLATFILE_API_URL =

export class AuthenticatedClient {
private _accessToken?: string
private _apiUrl?: string
private _api?: DefaultApi
private _fetchApi?: FetchAPI
private _api?: DefaultApi
public _accessToken?: string
public _apiUrl?: string
public fetchApi: FetchAPI
constructor(accessToken?: string, apiUrl?: string) {
this._accessToken =
accessToken || process.env.FLATFILE_BEARER_TOKEN || '...'
this._apiUrl = apiUrl || FLATFILE_API_URL
}
get api(): DefaultApi {

@@ -20,6 +27,7 @@ if (this._api) {

const accessToken = this._accessToken
const apiUrl = this._apiUrl ?? FLATFILE_API_URL
const apiUrl = this._apiUrl
const ClientConfig = new Configuration({
basePath: `${apiUrl}/v1`,
fetchApi: this.fetchApi,
fetchApi: fetch,
accessToken,

@@ -31,17 +39,17 @@ headers: {

})
return new DefaultApi(ClientConfig)
this._api = new DefaultApi(ClientConfig)
return this._api
}
fetch(url: string) {
if (this.fetchApi) {
return this.fetchApi
if (this._fetchApi) {
return this._fetchApi
}
const headers = {
Authorization:
`Bearer ${process.env.FLATFILE_BEARER_TOKEN}` ?? `Bearer ...`,
Authorization: `Bearer ${this._accessToken}`,
}
const fetchUrl = FLATFILE_API_URL + '/' + url
const fetchUrl = this._apiUrl + '/' + url
return this.fetchApi(fetchUrl, {
this._fetchApi = fetch(fetchUrl, {
headers,

@@ -51,2 +59,4 @@ })

.then((resp: any) => resp.data)
return this._fetchApi
}

@@ -53,0 +63,0 @@

@@ -21,4 +21,4 @@ import { AuthenticatedClient } from './authenticated.client'

constructor(filter?: EventFilter) {
super()
constructor(filter?: EventFilter, accessToken?: string, apiUrl?: string) {
super(accessToken, apiUrl)
if (filter) {

@@ -83,8 +83,7 @@ this.filterQuery = filter

if (!(event instanceof FlatfileEvent)) {
const { _apiUrl, _accessToken } = event
event = new FlatfileEvent(event)
if (_apiUrl && _accessToken) {
event = new FlatfileEvent(event, this._accessToken, this._apiUrl)
if (this._apiUrl && this._accessToken) {
event.setVariables({
apiUrl: _apiUrl,
accessToken: _accessToken,
apiUrl: this._apiUrl,
accessToken: this._accessToken,
})

@@ -91,0 +90,0 @@ }

import { AuthenticatedClient } from './authenticated.client'
import { Event } from '@flatfile/api'
import fetch from 'node-fetch'
import { EventCache } from './cache'

@@ -29,4 +28,8 @@ export class FlatfileEvent extends AuthenticatedClient {

constructor(private readonly src: Event) {
super()
constructor(
private readonly src: Event,
accessToken?: string,
apiUrl?: string
) {
super(accessToken, apiUrl)
this.cache = new EventCache()

@@ -33,0 +36,0 @@ this.domain = src.domain

@@ -8,4 +8,4 @@ {

"module": "ESNext",
"target": "ES6"
"target": "es2020"
},
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc