@opengeni/api-router 3.1.2 → 3.2.2

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/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import {
3
3
  SlackBotProviderError,
4
4
  apiRequestBindingsForTransportPeer,
5
5
  cleanupScheduledTaskConnectorAuthorization,
6
+ closeNativeExternalVaultProviders,
6
7
  createAppComposition,
7
8
  createAutomaticAgentUpdater,
8
9
  createLocalBrowserBoundary,
@@ -14,7 +15,7 @@ import {
14
15
  startSlackInteractionPump,
15
16
  startTemporalScheduleCleanupPump,
16
17
  withAccessGrantSessionRlsContext
17
- } from "./chunk-OT56OY4V.js";
18
+ } from "./chunk-PQBHZ2YH.js";
18
19
  import "./chunk-OGQDXVXY.js";
19
20
 
20
21
  // src/index.ts
@@ -3794,6 +3795,44 @@ function defaultProcessBoundary() {
3794
3795
  };
3795
3796
  }
3796
3797
 
3798
+ // src/shutdown.ts
3799
+ function installApiShutdownHandlers(input) {
3800
+ const runtime = input.process ?? process;
3801
+ let started = false;
3802
+ let finished = false;
3803
+ let deadline;
3804
+ const dispose = () => {
3805
+ runtime.off("SIGINT", shutdown);
3806
+ runtime.off("SIGTERM", shutdown);
3807
+ };
3808
+ const finish = (code) => {
3809
+ if (finished) return;
3810
+ finished = true;
3811
+ clearTimeout(deadline);
3812
+ dispose();
3813
+ if (code !== 0) {
3814
+ try {
3815
+ input.onFailure?.();
3816
+ } catch {
3817
+ }
3818
+ }
3819
+ runtime.exit(code);
3820
+ };
3821
+ function shutdown() {
3822
+ if (started) return;
3823
+ started = true;
3824
+ deadline = setTimeout(() => finish(1), input.timeoutMs ?? 3e4);
3825
+ deadline.unref?.();
3826
+ void Promise.resolve().then(input.close).then(
3827
+ () => finish(0),
3828
+ () => finish(1)
3829
+ );
3830
+ }
3831
+ runtime.on("SIGINT", shutdown);
3832
+ runtime.on("SIGTERM", shutdown);
3833
+ return dispose;
3834
+ }
3835
+
3797
3836
  // src/index.ts
3798
3837
  function isWorkflowAlreadyStarted(error) {
3799
3838
  return error instanceof WorkflowExecutionAlreadyStartedError;
@@ -4239,6 +4278,7 @@ async function startApi(options = {}) {
4239
4278
  server,
4240
4279
  close: async () => {
4241
4280
  server.stop(true);
4281
+ const vaultProvidersClosed = closeNativeExternalVaultProviders().catch(() => void 0);
4242
4282
  metricsServer?.stop(true);
4243
4283
  stopSlackInteractionPump?.();
4244
4284
  await stopMemorySlackPublicationPump();
@@ -4250,6 +4290,7 @@ async function startApi(options = {}) {
4250
4290
  await stopNativePushDispatchPump();
4251
4291
  await routeDeps.userPresence?.close().catch(() => void 0);
4252
4292
  await Promise.allSettled([
4293
+ vaultProvidersClosed,
4253
4294
  Promise.resolve(editableArtifactComposition?.close()),
4254
4295
  authCalloutResponder?.close(),
4255
4296
  bus.close(),
@@ -4265,7 +4306,13 @@ if (import.meta.main) {
4265
4306
  const settings = getSettings();
4266
4307
  const observability = createObservability(settings, { component: "api" });
4267
4308
  fatalBoundary.attachObservability(observability);
4268
- await startApi({ settings, observability });
4309
+ const api = await startApi({ settings, observability });
4310
+ installApiShutdownHandlers({
4311
+ close: api.close,
4312
+ onFailure: () => observability.warn("Opengeni API shutdown did not finish cleanly", {
4313
+ errorCode: "api_shutdown_failed"
4314
+ })
4315
+ });
4269
4316
  fatalBoundary.markRunning();
4270
4317
  } catch (error) {
4271
4318
  await fatalBoundary.reportStartupFailure(error);