@emmett-community/emmett-google-services-bootstrap 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -1
- package/dist/ServiceBootstrap-Cn1LJQgC.d.cts +336 -0
- package/dist/ServiceBootstrap-Cn1LJQgC.d.ts +336 -0
- package/dist/chunk-G3V6OOZL.cjs +919 -0
- package/dist/chunk-G3V6OOZL.cjs.map +1 -0
- package/dist/chunk-XUV26TX4.js +919 -0
- package/dist/chunk-XUV26TX4.js.map +1 -0
- package/dist/index.cjs +52 -942
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -294
- package/dist/index.d.ts +19 -294
- package/dist/index.js +32 -883
- package/dist/index.js.map +1 -1
- package/dist/testing.cjs +49 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +31 -0
- package/dist/testing.d.ts +31 -0
- package/dist/testing.js +49 -0
- package/dist/testing.js.map +1 -0
- package/package.json +15 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,307 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
1
|
+
import { S as ServiceBootstrapContext, L as Logger, F as FirebaseAdminLike } from './ServiceBootstrap-Cn1LJQgC.js';
|
|
2
|
+
export { C as CreateAppOptions, e as DependencyCheck, k as DependencyCheckResult, l as DependencyCheckSummary, m as DependencyChecker, j as DependencyTimeoutError, D as DependencyUnavailableError, d as FirebaseConfig, r as GracefulShutdown, G as GracefulShutdownConfig, q as GracefulShutdownResult, c as LogLevel, M as MessageBusWithLifecycle, O as ObservabilityConfig, P as PubSubConfig, R as ResolvedFirebaseConfig, h as ResolvedPubSubConfig, i as ResolvedServiceBootstrapConfig, b as ServiceBootstrap, g as ServiceBootstrapConfig, f as ServiceBootstrapOverrides, o as ShutdownTask, p as ShutdownTaskResult, n as ShutdownTimeoutError, a as StartApiOptions, s as startDependency } from './ServiceBootstrap-Cn1LJQgC.js';
|
|
3
|
+
import * as express from 'express';
|
|
4
|
+
import * as qs from 'qs';
|
|
5
|
+
import * as express_serve_static_core from 'express-serve-static-core';
|
|
5
6
|
import { Firestore } from '@google-cloud/firestore';
|
|
6
|
-
import { PubSub } from '@google-cloud/pubsub';
|
|
7
7
|
import { Auth } from 'firebase-admin/auth';
|
|
8
8
|
import { app } from 'firebase-admin';
|
|
9
9
|
import { Database } from 'firebase-admin/database';
|
|
10
|
-
import {
|
|
10
|
+
import { PubSub } from '@google-cloud/pubsub';
|
|
11
|
+
import { FirestoreEventStoreOptions } from '@emmett-community/emmett-google-firestore';
|
|
11
12
|
import { RealtimeDBInlineProjectionDefinition } from '@emmett-community/emmett-google-realtime-db';
|
|
12
13
|
export { realtimeDBInlineProjection } from '@emmett-community/emmett-google-realtime-db';
|
|
14
|
+
import { EventStore } from '@event-driven-io/emmett';
|
|
15
|
+
export { ImportedHandlerModules, NoContent, OK, createFirebaseAuthSecurityHandlers, lazyApplication, on } from '@emmett-community/emmett-expressjs-with-openapi';
|
|
16
|
+
import '@emmett-community/emmett-google-pubsub';
|
|
13
17
|
|
|
14
|
-
type LogLevel = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'silent';
|
|
15
|
-
/**
|
|
16
|
-
* Canonical logger contract used across Emmett packages.
|
|
17
|
-
* Matches Pino style (context, message).
|
|
18
|
-
*/
|
|
19
|
-
interface Logger {
|
|
20
|
-
debug(context: Record<string, unknown>, message?: string): void;
|
|
21
|
-
info(context: Record<string, unknown>, message?: string): void;
|
|
22
|
-
warn(context: Record<string, unknown>, message?: string): void;
|
|
23
|
-
error(context: Record<string, unknown>, message?: string): void;
|
|
24
|
-
}
|
|
25
|
-
type ObservabilityConfig = {
|
|
26
|
-
logger?: Logger;
|
|
27
|
-
logLevel?: LogLevel;
|
|
28
|
-
environment?: string;
|
|
29
|
-
createLogger?: boolean;
|
|
30
|
-
};
|
|
31
|
-
type FirebaseConfig = {
|
|
32
|
-
projectId?: string;
|
|
33
|
-
databaseURL?: string;
|
|
34
|
-
firestoreEmulatorHost?: string;
|
|
35
|
-
databaseEmulatorHost?: string;
|
|
36
|
-
};
|
|
37
|
-
type PubSubConfig = {
|
|
38
|
-
projectId?: string;
|
|
39
|
-
emulatorHost?: string;
|
|
40
|
-
topicPrefix?: string;
|
|
41
|
-
subscriptionOptions?: SubscriptionOptions;
|
|
42
|
-
autoCreateResources?: boolean;
|
|
43
|
-
cleanupOnClose?: boolean;
|
|
44
|
-
closePubSubClient?: boolean;
|
|
45
|
-
};
|
|
46
|
-
type DependencyCheck = {
|
|
47
|
-
name: string;
|
|
48
|
-
check: () => Promise<void>;
|
|
49
|
-
successMessage?: string;
|
|
50
|
-
timeoutMs?: number;
|
|
51
|
-
required?: boolean;
|
|
52
|
-
};
|
|
53
|
-
type GracefulShutdownConfig = {
|
|
54
|
-
timeoutMs?: number;
|
|
55
|
-
exitOnComplete?: boolean;
|
|
56
|
-
exitFn?: (code: number) => void;
|
|
57
|
-
};
|
|
58
|
-
type MessageBusWithLifecycle = MessageBus & EventSubscription & CommandProcessor & ScheduledMessageProcessor & PubSubMessageBusLifecycle;
|
|
59
|
-
interface FirebaseAdminLike {
|
|
60
|
-
initializeApp(options: {
|
|
61
|
-
projectId: string;
|
|
62
|
-
databaseURL?: string;
|
|
63
|
-
}, name?: string): app.App;
|
|
64
|
-
app?: () => app.App;
|
|
65
|
-
apps?: Array<app.App | null>;
|
|
66
|
-
}
|
|
67
|
-
type ServiceBootstrapOverrides = {
|
|
68
|
-
firebaseAdmin?: FirebaseAdminLike;
|
|
69
|
-
firestore?: Firestore;
|
|
70
|
-
database?: Database;
|
|
71
|
-
auth?: Auth;
|
|
72
|
-
pubsub?: PubSub;
|
|
73
|
-
eventStore?: EventStore;
|
|
74
|
-
messageBus?: MessageBusWithLifecycle;
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Main configuration for ServiceBootstrap.
|
|
78
|
-
* Values can be provided explicitly or via environment variables.
|
|
79
|
-
*/
|
|
80
|
-
type ServiceBootstrapConfig = {
|
|
81
|
-
serviceName: string;
|
|
82
|
-
firebase?: FirebaseConfig;
|
|
83
|
-
pubsub?: PubSubConfig;
|
|
84
|
-
observability?: ObservabilityConfig;
|
|
85
|
-
projections?: RealtimeDBInlineProjectionDefinition[];
|
|
86
|
-
getCurrentTime?: () => Date;
|
|
87
|
-
dependencies?: DependencyCheck[];
|
|
88
|
-
includeDefaultDependencyChecks?: boolean;
|
|
89
|
-
autoStartMessageBus?: boolean;
|
|
90
|
-
shutdownOnDependencyFailure?: boolean;
|
|
91
|
-
shutdown?: GracefulShutdownConfig;
|
|
92
|
-
_testOverrides?: ServiceBootstrapOverrides;
|
|
93
|
-
};
|
|
94
|
-
type ResolvedFirebaseConfig = {
|
|
95
|
-
projectId: string;
|
|
96
|
-
databaseURL: string;
|
|
97
|
-
firestoreEmulatorHost?: string;
|
|
98
|
-
databaseEmulatorHost?: string;
|
|
99
|
-
};
|
|
100
|
-
type ResolvedPubSubConfig = {
|
|
101
|
-
projectId: string;
|
|
102
|
-
emulatorHost?: string;
|
|
103
|
-
topicPrefix: string;
|
|
104
|
-
subscriptionOptions?: SubscriptionOptions;
|
|
105
|
-
autoCreateResources: boolean;
|
|
106
|
-
cleanupOnClose: boolean;
|
|
107
|
-
closePubSubClient: boolean;
|
|
108
|
-
};
|
|
109
|
-
type ResolvedServiceBootstrapConfig = {
|
|
110
|
-
serviceName: string;
|
|
111
|
-
firebase: ResolvedFirebaseConfig;
|
|
112
|
-
pubsub: ResolvedPubSubConfig;
|
|
113
|
-
observability: ObservabilityConfig;
|
|
114
|
-
projections: RealtimeDBInlineProjectionDefinition[];
|
|
115
|
-
getCurrentTime: () => Date;
|
|
116
|
-
dependencies: DependencyCheck[];
|
|
117
|
-
includeDefaultDependencyChecks: boolean;
|
|
118
|
-
autoStartMessageBus: boolean;
|
|
119
|
-
shutdownOnDependencyFailure: boolean;
|
|
120
|
-
shutdown: GracefulShutdownConfig;
|
|
121
|
-
_testOverrides?: ServiceBootstrapOverrides;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
declare class DependencyTimeoutError extends Error {
|
|
125
|
-
constructor(timeoutMs: number);
|
|
126
|
-
}
|
|
127
|
-
type DependencyCheckResult = {
|
|
128
|
-
name: string;
|
|
129
|
-
ok: boolean;
|
|
130
|
-
required: boolean;
|
|
131
|
-
durationMs: number;
|
|
132
|
-
timedOut: boolean;
|
|
133
|
-
error?: unknown;
|
|
134
|
-
};
|
|
135
|
-
type DependencyCheckSummary = {
|
|
136
|
-
ok: boolean;
|
|
137
|
-
results: DependencyCheckResult[];
|
|
138
|
-
};
|
|
139
|
-
/**
|
|
140
|
-
* Helper for one-off dependency checks with optional logging.
|
|
141
|
-
*/
|
|
142
|
-
declare const startDependency: (dependency: string, startFn: () => Promise<void>, options?: {
|
|
143
|
-
logger?: Logger;
|
|
144
|
-
successMessage?: string;
|
|
145
|
-
timeoutMs?: number;
|
|
146
|
-
}) => Promise<boolean>;
|
|
147
|
-
/**
|
|
148
|
-
* Executes dependency checks with optional timeouts.
|
|
149
|
-
*/
|
|
150
|
-
declare class DependencyChecker {
|
|
151
|
-
private readonly logger?;
|
|
152
|
-
private readonly defaultTimeoutMs?;
|
|
153
|
-
constructor(options?: {
|
|
154
|
-
logger?: Logger;
|
|
155
|
-
defaultTimeoutMs?: number;
|
|
156
|
-
});
|
|
157
|
-
check(dependency: DependencyCheck): Promise<DependencyCheckResult>;
|
|
158
|
-
checkAll(dependencies: DependencyCheck[]): Promise<DependencyCheckSummary>;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
declare class ShutdownTimeoutError extends Error {
|
|
162
|
-
constructor(timeoutMs: number);
|
|
163
|
-
}
|
|
164
|
-
type ShutdownTask = {
|
|
165
|
-
name: string;
|
|
166
|
-
close: () => Promise<void>;
|
|
167
|
-
timeoutMs?: number;
|
|
168
|
-
};
|
|
169
|
-
type ShutdownTaskResult = {
|
|
170
|
-
name: string;
|
|
171
|
-
ok: boolean;
|
|
172
|
-
timedOut: boolean;
|
|
173
|
-
durationMs: number;
|
|
174
|
-
error?: unknown;
|
|
175
|
-
};
|
|
176
|
-
type GracefulShutdownResult = {
|
|
177
|
-
reason: string;
|
|
178
|
-
exitCode: number;
|
|
179
|
-
tasks: ShutdownTaskResult[];
|
|
180
|
-
};
|
|
181
|
-
/**
|
|
182
|
-
* Runs shutdown tasks with timeout handling and optional exit.
|
|
183
|
-
*/
|
|
184
|
-
declare class GracefulShutdown {
|
|
185
|
-
private readonly logger?;
|
|
186
|
-
private readonly timeoutMs?;
|
|
187
|
-
private readonly exitOnComplete;
|
|
188
|
-
private readonly exitFn;
|
|
189
|
-
private readonly tasks;
|
|
190
|
-
private shuttingDown;
|
|
191
|
-
private lastResult?;
|
|
192
|
-
constructor(options?: GracefulShutdownConfig & {
|
|
193
|
-
logger?: Logger;
|
|
194
|
-
});
|
|
195
|
-
/**
|
|
196
|
-
* Register a shutdown task.
|
|
197
|
-
*/
|
|
198
|
-
register(task: ShutdownTask): void;
|
|
199
|
-
/**
|
|
200
|
-
* Execute all shutdown tasks and return the aggregated result.
|
|
201
|
-
*/
|
|
202
|
-
shutdown(reason: string, exitCode?: number): Promise<GracefulShutdownResult>;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Runtime context produced by ServiceBootstrap.
|
|
207
|
-
*/
|
|
208
|
-
type ServiceBootstrapContext = {
|
|
209
|
-
serviceName: string;
|
|
210
|
-
firebase: {
|
|
211
|
-
app: app.App;
|
|
212
|
-
firestore: Firestore;
|
|
213
|
-
database: Database;
|
|
214
|
-
auth: Auth;
|
|
215
|
-
};
|
|
216
|
-
firestore: Firestore;
|
|
217
|
-
database: Database;
|
|
218
|
-
auth: Auth;
|
|
219
|
-
pubsub: PubSub;
|
|
220
|
-
eventStore: EventStore;
|
|
221
|
-
messageBus: MessageBusWithLifecycle;
|
|
222
|
-
logger?: Logger;
|
|
223
|
-
getCurrentTime: () => Date;
|
|
224
|
-
config: ResolvedServiceBootstrapConfig;
|
|
225
|
-
};
|
|
226
18
|
/**
|
|
227
|
-
*
|
|
19
|
+
* Handler for `GET /health` (liveness): the process is up and serving requests.
|
|
20
|
+
* Wire it to the `getHealth` operation of the service contract.
|
|
228
21
|
*/
|
|
229
|
-
declare
|
|
230
|
-
readonly summary: DependencyCheckSummary;
|
|
231
|
-
constructor(summary: DependencyCheckSummary);
|
|
232
|
-
}
|
|
233
|
-
type CreateAppOptions = {
|
|
234
|
-
openApiPath: string;
|
|
235
|
-
handlersPath: string;
|
|
236
|
-
initializeHandlers: (handlers?: ImportedHandlerModules) => void | Promise<void>;
|
|
237
|
-
openApiOptions?: Partial<Omit<OpenApiValidatorOptions, 'apiSpec' | 'operationHandlers' | 'initializeHandlers'>>;
|
|
238
|
-
appOptions?: Omit<ApplicationOptions, 'openApiValidator' | 'observability'>;
|
|
239
|
-
};
|
|
240
|
-
type StartApiOptions = Omit<CreateAppOptions, 'initializeHandlers'> & {
|
|
241
|
-
initializeHandlers: (handlers: ImportedHandlerModules | undefined, ctx: ServiceBootstrapContext) => void | Promise<void>;
|
|
242
|
-
port?: number;
|
|
243
|
-
registerSignalHandlers?: boolean;
|
|
244
|
-
beforeStart?: (ctx: ServiceBootstrapContext) => void | Promise<void>;
|
|
245
|
-
};
|
|
22
|
+
declare const getHealth: (request: express.Request<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>, response: express.Response, _next: express.NextFunction) => Promise<void>;
|
|
246
23
|
/**
|
|
247
|
-
*
|
|
24
|
+
* Handler for `GET /ready` (readiness): answers 200 when the stores, the message bus and the
|
|
25
|
+
* configured dependencies answer, and 503 with the failed checks otherwise.
|
|
26
|
+
* Wire it to the `getReady` operation of the service contract.
|
|
248
27
|
*/
|
|
249
|
-
declare
|
|
250
|
-
private readonly config;
|
|
251
|
-
private resolvedConfig?;
|
|
252
|
-
private logger?;
|
|
253
|
-
private context?;
|
|
254
|
-
private dependencyChecker?;
|
|
255
|
-
private shutdownManager?;
|
|
256
|
-
constructor(config: ServiceBootstrapConfig);
|
|
257
|
-
/**
|
|
258
|
-
* Resolve configuration with defaults and environment variables.
|
|
259
|
-
*/
|
|
260
|
-
getConfig(): ResolvedServiceBootstrapConfig;
|
|
261
|
-
/**
|
|
262
|
-
* Return the initialized context if available.
|
|
263
|
-
*/
|
|
264
|
-
getContext(): ServiceBootstrapContext | undefined;
|
|
265
|
-
/**
|
|
266
|
-
* Register process signal handlers that trigger shutdown.
|
|
267
|
-
*/
|
|
268
|
-
registerSignalHandlers(options?: {
|
|
269
|
-
signals?: NodeJS.Signals[];
|
|
270
|
-
exitCode?: number;
|
|
271
|
-
}): () => void;
|
|
272
|
-
/**
|
|
273
|
-
* Create an Express app using emmett-expressjs-with-openapi defaults.
|
|
274
|
-
*/
|
|
275
|
-
createApp(options: CreateAppOptions): Promise<Application>;
|
|
276
|
-
/**
|
|
277
|
-
* Initialize, run dependency checks, create the app, and start the HTTP server.
|
|
278
|
-
*/
|
|
279
|
-
startApi(options: StartApiOptions): Promise<{
|
|
280
|
-
app: Application;
|
|
281
|
-
server: ReturnType<typeof startAPI>;
|
|
282
|
-
context: ServiceBootstrapContext;
|
|
283
|
-
}>;
|
|
284
|
-
/**
|
|
285
|
-
* Initialize Firebase, PubSub, and event store wiring.
|
|
286
|
-
* Does not execute dependency checks.
|
|
287
|
-
*/
|
|
288
|
-
initialize(): Promise<ServiceBootstrapContext>;
|
|
289
|
-
/**
|
|
290
|
-
* Initialize and run dependency checks before returning context.
|
|
291
|
-
*/
|
|
292
|
-
start(): Promise<ServiceBootstrapContext>;
|
|
293
|
-
/**
|
|
294
|
-
* Execute graceful shutdown tasks and return the shutdown result.
|
|
295
|
-
*/
|
|
296
|
-
shutdown(reason: string, exitCode?: number): Promise<GracefulShutdownResult>;
|
|
297
|
-
private getLogger;
|
|
298
|
-
private resolveConfig;
|
|
299
|
-
private getDatabaseURL;
|
|
300
|
-
private getDependencyChecker;
|
|
301
|
-
private getShutdownManager;
|
|
302
|
-
private registerDefaultShutdownTasks;
|
|
303
|
-
private buildDefaultDependencyChecks;
|
|
304
|
-
}
|
|
28
|
+
declare const getReady: (ctx: Pick<ServiceBootstrapContext, "checkReadiness">) => (request: express.Request<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>, response: express.Response, _next: express.NextFunction) => Promise<void>;
|
|
305
29
|
|
|
306
30
|
type FirebaseInitializationOptions = {
|
|
307
31
|
projectId: string;
|
|
@@ -373,10 +97,11 @@ type EventStoreFactoryOptions = {
|
|
|
373
97
|
database: Database;
|
|
374
98
|
projections?: RealtimeDBInlineProjectionDefinition[];
|
|
375
99
|
logger?: Logger;
|
|
100
|
+
collections?: FirestoreEventStoreOptions['collections'];
|
|
376
101
|
};
|
|
377
102
|
/**
|
|
378
103
|
* Create a Firestore-backed event store and wire RealtimeDB projections if provided.
|
|
379
104
|
*/
|
|
380
105
|
declare const createEventStore: <T extends EventStore = EventStore>(options: EventStoreFactoryOptions) => T;
|
|
381
106
|
|
|
382
|
-
export { type
|
|
107
|
+
export { type EventStoreFactoryOptions, FirebaseAdminLike, type FirebaseInitResult, type FirebaseInitializationOptions, FirebaseInitializer, Logger, type PubSubInitializationOptions, PubSubInitializer, ServiceBootstrapContext, type SignalHandlerOptions, createEventStore, getHealth, getReady, registerSignalHandlers };
|