diff --git a/.prettierrc b/.prettierrc
new file mode 100644
index 0000000..f0db82f
--- /dev/null
+++ b/.prettierrc
@@ -0,0 +1,7 @@
+{
+ "trailingComma": "es5",
+ "tabWidth": 4,
+ "semi": false,
+ "singleQuote": true,
+ "printWidth": 120
+}
diff --git a/src/types.ts b/src/types.ts
index c7a4607..d84c2dc 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -1,7 +1,7 @@
import { City } from '@maxmind/geoip2-node'
/** A PostHog plugin. */
-export interface Plugin {
+export interface Plugin {
/** Ran when the plugin is loaded by the PostHog plugin server. */
setupPlugin?: (meta: Meta) => void
/** Ran when the plugin is unloaded by the PostHog plugin server. */
@@ -47,12 +47,46 @@ export interface PluginAttachment {
contents: any
}
-export interface PluginMeta {
+interface BasePluginMeta {
cache: CacheExtension
storage: StorageExtension
geoip: GeoIPExtension
config: Record
global: Record
+ attachments: Record
+ jobs: Record JobControls>
+}
+
+type JobOptions = Record | undefined
+
+type MetaInput = {
+ config?: Record
+ attachments?: Record
+ global?: Record
+ jobs?: Record
+}
+
+type JobControls = {
+ runNow: () => Promise
+ runIn: (duration: number, unit: string) => Promise
+ runAt: (date: Date) => Promise
+}
+
+type MetaJobsFromJobOptions> = {
+ [K in keyof J]: (opts: J[K]) => JobControls
+}
+
+export interface PluginMeta extends BasePluginMeta {
+ config: Input['config']
+ attachments: Input['attachments']
+ global: Input['global']
+ jobs: Input['jobs'] extends Record
+ ? MetaJobsFromJobOptions
+ : Record JobControls>
+}
+
+export type PluginJobs = {
+ [K in keyof M['jobs']]: (opts: Parameters[0], meta: M) => void | Promise
}
export interface PluginConfigStructure {
@@ -68,7 +102,7 @@ export interface PluginConfigStructure {
export interface PluginConfigDefault extends PluginConfigStructure {
type?: 'string' | 'attachment'
-}
+}
export interface PluginConfigChoice extends PluginConfigStructure {
type: 'choice'