diff --git a/app/gen-server/lib/HomeDBManager.ts b/app/gen-server/lib/HomeDBManager.ts index 9c276e5b..63778743 100644 --- a/app/gen-server/lib/HomeDBManager.ts +++ b/app/gen-server/lib/HomeDBManager.ts @@ -35,6 +35,7 @@ import {makeId} from 'app/server/lib/idUtils'; import * as log from 'app/server/lib/log'; import {Permit} from 'app/server/lib/Permit'; import {WebHookSecret} from "app/server/lib/Triggers"; +import {StringUnion} from 'app/common/StringUnion'; import {EventEmitter} from 'events'; import flatten = require('lodash/flatten'); import pick = require('lodash/pick'); @@ -48,6 +49,17 @@ import * as uuidv4 from "uuid/v4"; // fixed. See https://github.com/typeorm/typeorm/issues/1884#issuecomment-380767213 applyPatch(); +export const NotifierEvents = StringUnion( + 'addUser', + 'userChange', + 'firstLogin', + 'addBillingManager', + 'teamCreator', + 'trialPeriodEndingSoon', +); + +export type NotifierEvent = typeof NotifierEvents.type; + // Nominal email address of a user who can view anything (for thumbnails). export const PREVIEWER_EMAIL = 'thumbnail@getgrist.com'; @@ -190,6 +202,10 @@ export class HomeDBManager extends EventEmitter { private _docAuthCache = new MapWithTTL>(DOC_AUTH_CACHE_TTL); + public emit(event: NotifierEvent, ...args: any[]): boolean { + return super.emit(event, ...args); + } + /** * Five aclRules, each with one group (with the names 'owners', 'editors', 'viewers', * 'guests', and 'members') are created by default on every new entity (Organization, diff --git a/app/server/lib/FlexServer.ts b/app/server/lib/FlexServer.ts index 3099d328..ee95f0d1 100644 --- a/app/server/lib/FlexServer.ts +++ b/app/server/lib/FlexServer.ts @@ -99,7 +99,6 @@ export class FlexServer implements GristServer { public host: string; public tag: string; public info = new Array<[string, any]>(); - public notifier: INotifier; public usage: Usage; public housekeeper: Housekeeper; public server: http.Server; @@ -123,6 +122,7 @@ export class FlexServer implements GristServer { private _storageManager: IDocStorageManager; private _docWorkerMap: IDocWorkerMap; private _widgetRepository: IWidgetRepository; + private _notifier: INotifier; private _internalPermitStore: IPermitStore; // store for permits that stay within our servers private _externalPermitStore: IPermitStore; // store for permits that pass through outside servers private _disabled: boolean = false; @@ -286,6 +286,11 @@ export class FlexServer implements GristServer { return this._widgetRepository; } + public getNotifier(): INotifier { + if (!this._notifier) { throw new Error('no notifier available'); } + return this._notifier; + } + public addLogging() { if (this._check('logging')) { return; } if (process.env.GRIST_LOG_SKIP_HTTP) { return; } @@ -1254,7 +1259,7 @@ export class FlexServer implements GristServer { // and all that is needed is a refactor to pass that info along. But there is also the // case of notification(s) from stripe. May need to associate a preferred base domain // with org/user and persist that? - this.notifier = this.create.Notifier(this._dbManager, this); + this._notifier = this.create.Notifier(this._dbManager, this); } public getGristConfig(): GristLoadConfig { diff --git a/app/server/lib/GristServer.ts b/app/server/lib/GristServer.ts index 075a8927..54dacb46 100644 --- a/app/server/lib/GristServer.ts +++ b/app/server/lib/GristServer.ts @@ -9,6 +9,7 @@ import * as Comm from 'app/server/lib/Comm'; import { Hosts } from 'app/server/lib/extractOrg'; import { ICreate } from 'app/server/lib/ICreate'; import { IDocStorageManager } from 'app/server/lib/IDocStorageManager'; +import { INotifier } from 'app/server/lib/INotifier'; import { IPermitStore } from 'app/server/lib/Permit'; import { Sessions } from 'app/server/lib/Sessions'; import * as express from 'express'; @@ -34,6 +35,7 @@ export interface GristServer { getHosts(): Hosts; getHomeDBManager(): HomeDBManager; getStorageManager(): IDocStorageManager; + getNotifier(): INotifier; } export interface GristLoginSystem {