@geekmidas/constructs 9.1.0 → 9.2.1

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.
Files changed (123) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/dist/{AWSScheduledFunction-C42adp8A.cjs → AWSScheduledFunction-CKhVurOa.cjs} +3 -3
  3. package/dist/{AWSScheduledFunction-C42adp8A.cjs.map → AWSScheduledFunction-CKhVurOa.cjs.map} +1 -1
  4. package/dist/{AWSScheduledFunction-KP6lqbsW.mjs → AWSScheduledFunction-CU7mMGFA.mjs} +2 -2
  5. package/dist/{AWSScheduledFunction-KP6lqbsW.mjs.map → AWSScheduledFunction-CU7mMGFA.mjs.map} +1 -1
  6. package/dist/{AWSScheduledFunction-BHHlWlfV.d.cts → AWSScheduledFunction-DPMzOjZP.d.cts} +2 -2
  7. package/dist/{AWSScheduledFunction-BHHlWlfV.d.cts.map → AWSScheduledFunction-DPMzOjZP.d.cts.map} +1 -1
  8. package/dist/{AWSScheduledFunction-BzGCUbkk.d.mts → AWSScheduledFunction-a6hRp3nk.d.mts} +2 -2
  9. package/dist/{AWSScheduledFunction-BzGCUbkk.d.mts.map → AWSScheduledFunction-a6hRp3nk.d.mts.map} +1 -1
  10. package/dist/{Construct-TGIM_E4o.cjs → Construct-D09WUUOf.cjs} +9 -1
  11. package/dist/Construct-D09WUUOf.cjs.map +1 -0
  12. package/dist/{Construct-BWF5HxaM.mjs → Construct-D0uZvbr3.mjs} +9 -1
  13. package/dist/Construct-D0uZvbr3.mjs.map +1 -0
  14. package/dist/{Construct-JlyQkBkv.d.cts → Construct-D_3yZ9m5.d.cts} +23 -3
  15. package/dist/Construct-D_3yZ9m5.d.cts.map +1 -0
  16. package/dist/{Construct-pxwC6fDD.d.mts → Construct-DsqpiAym.d.mts} +23 -3
  17. package/dist/Construct-DsqpiAym.d.mts.map +1 -0
  18. package/dist/{Endpoint-B0P_pEMr.d.mts → Endpoint-DEydLuBs.d.mts} +2 -2
  19. package/dist/{Endpoint-B0P_pEMr.d.mts.map → Endpoint-DEydLuBs.d.mts.map} +1 -1
  20. package/dist/{Endpoint-Cwjhc1Hl.d.cts → Endpoint-nhjtdDL3.d.cts} +2 -2
  21. package/dist/{Endpoint-Cwjhc1Hl.d.cts.map → Endpoint-nhjtdDL3.d.cts.map} +1 -1
  22. package/dist/{HonoEndpointAdaptor-BMVwx2cz.mjs → HonoEndpointAdaptor-CJfFQ5KR.mjs} +3 -3
  23. package/dist/{HonoEndpointAdaptor-BMVwx2cz.mjs.map → HonoEndpointAdaptor-CJfFQ5KR.mjs.map} +1 -1
  24. package/dist/{HonoEndpointAdaptor-DPDsDi-D.cjs → HonoEndpointAdaptor-DCD0rhFg.cjs} +5 -5
  25. package/dist/{HonoEndpointAdaptor-DPDsDi-D.cjs.map → HonoEndpointAdaptor-DCD0rhFg.cjs.map} +1 -1
  26. package/dist/{Queue-BL68oDJ-.d.mts → Queue-Brw--scg.d.cts} +3 -3
  27. package/dist/{Queue-BL68oDJ-.d.mts.map → Queue-Brw--scg.d.cts.map} +1 -1
  28. package/dist/{Queue-DxJ6btRE.d.cts → Queue-D5z1bwFu.d.mts} +3 -3
  29. package/dist/{Queue-DxJ6btRE.d.cts.map → Queue-D5z1bwFu.d.mts.map} +1 -1
  30. package/dist/{Subscriber-DF6xsBAJ.d.mts → Subscriber-CJ22tp8r.d.mts} +2 -2
  31. package/dist/{Subscriber-DF6xsBAJ.d.mts.map → Subscriber-CJ22tp8r.d.mts.map} +1 -1
  32. package/dist/{Subscriber-BpVhcGhX.d.cts → Subscriber-DvKSp0N4.d.cts} +2 -2
  33. package/dist/{Subscriber-BpVhcGhX.d.cts.map → Subscriber-DvKSp0N4.d.cts.map} +1 -1
  34. package/dist/{Topic-DJXoDeMP.d.cts → Topic-B-fxOsR2.d.mts} +3 -3
  35. package/dist/{Topic-DJXoDeMP.d.cts.map → Topic-B-fxOsR2.d.mts.map} +1 -1
  36. package/dist/{Topic-DxWQBgMN.d.mts → Topic-BMfrIFdX.d.cts} +3 -3
  37. package/dist/{Topic-DxWQBgMN.d.mts.map → Topic-BMfrIFdX.d.cts.map} +1 -1
  38. package/dist/adaptors/aws.cjs +12 -11
  39. package/dist/adaptors/aws.cjs.map +1 -1
  40. package/dist/adaptors/aws.d.cts +6 -6
  41. package/dist/adaptors/aws.d.cts.map +1 -1
  42. package/dist/adaptors/aws.d.mts +6 -6
  43. package/dist/adaptors/aws.d.mts.map +1 -1
  44. package/dist/adaptors/aws.mjs +11 -10
  45. package/dist/adaptors/aws.mjs.map +1 -1
  46. package/dist/adaptors/hono.cjs +5 -5
  47. package/dist/adaptors/hono.d.cts +3 -3
  48. package/dist/adaptors/hono.d.mts +3 -3
  49. package/dist/adaptors/hono.mjs +4 -4
  50. package/dist/adaptors/testing.cjs +5 -5
  51. package/dist/adaptors/testing.d.cts +5 -5
  52. package/dist/adaptors/testing.d.mts +5 -5
  53. package/dist/adaptors/testing.mjs +4 -4
  54. package/dist/crons/index.cjs +3 -3
  55. package/dist/crons/index.d.cts +7 -7
  56. package/dist/crons/index.d.cts.map +1 -1
  57. package/dist/crons/index.d.mts +3 -3
  58. package/dist/crons/index.mjs +3 -3
  59. package/dist/endpoints/index.cjs +3 -3
  60. package/dist/endpoints/index.d.cts +5 -5
  61. package/dist/endpoints/index.d.mts +3 -3
  62. package/dist/endpoints/index.mjs +3 -3
  63. package/dist/functions/index.cjs +2 -2
  64. package/dist/functions/index.d.cts +2 -2
  65. package/dist/functions/index.d.mts +2 -2
  66. package/dist/functions/index.mjs +2 -2
  67. package/dist/{functions-SqtCDc9c.cjs → functions-B3OFv3QV.cjs} +2 -2
  68. package/dist/functions-B3OFv3QV.cjs.map +1 -0
  69. package/dist/{functions-EqTloHjo.mjs → functions-DhkDodl0.mjs} +2 -2
  70. package/dist/functions-DhkDodl0.mjs.map +1 -0
  71. package/dist/{index-C7iynzLI.d.mts → index-B8LNLQXD.d.mts} +2 -2
  72. package/dist/{index-C7iynzLI.d.mts.map → index-B8LNLQXD.d.mts.map} +1 -1
  73. package/dist/{index-DdgJRm4q.d.cts → index-CXpim5mV.d.cts} +6 -6
  74. package/dist/{index-DdgJRm4q.d.cts.map → index-CXpim5mV.d.cts.map} +1 -1
  75. package/dist/index.cjs +1 -1
  76. package/dist/index.d.cts +2 -2
  77. package/dist/index.d.mts +2 -2
  78. package/dist/index.mjs +1 -1
  79. package/dist/lazyAccessors-C1n1QfEj.cjs +653 -0
  80. package/dist/lazyAccessors-C1n1QfEj.cjs.map +1 -0
  81. package/dist/lazyAccessors-fFIQrblM.mjs +594 -0
  82. package/dist/lazyAccessors-fFIQrblM.mjs.map +1 -0
  83. package/dist/monitors/index.cjs +9 -2
  84. package/dist/monitors/index.cjs.map +1 -1
  85. package/dist/monitors/index.d.cts +19 -6
  86. package/dist/monitors/index.d.cts.map +1 -1
  87. package/dist/monitors/index.d.mts +15 -6
  88. package/dist/monitors/index.d.mts.map +1 -1
  89. package/dist/monitors/index.mjs +9 -2
  90. package/dist/monitors/index.mjs.map +1 -1
  91. package/dist/{processAudits-BJZT5gmy.cjs → processAudits-94Ar_EJF.cjs} +2 -2
  92. package/dist/{processAudits-BJZT5gmy.cjs.map → processAudits-94Ar_EJF.cjs.map} +1 -1
  93. package/dist/queue/index.cjs +1 -1
  94. package/dist/queue/index.d.cts +4 -4
  95. package/dist/queue/index.d.mts +2 -2
  96. package/dist/queue/index.mjs +1 -1
  97. package/dist/subscribers/index.cjs +1 -1
  98. package/dist/subscribers/index.d.cts +5 -5
  99. package/dist/subscribers/index.d.mts +3 -3
  100. package/dist/subscribers/index.mjs +1 -1
  101. package/dist/topic/index.cjs +1 -1
  102. package/dist/topic/index.d.cts +2 -2
  103. package/dist/topic/index.d.mts +2 -2
  104. package/dist/topic/index.mjs +1 -1
  105. package/package.json +23 -27
  106. package/src/Construct.ts +12 -1
  107. package/src/__tests__/monitor.spec.ts +67 -7
  108. package/src/endpoints/AmazonApiGatewayEndpointAdaptor.ts +7 -15
  109. package/src/endpoints/Endpoint.ts +12 -15
  110. package/src/index.ts +1 -0
  111. package/src/monitor.ts +17 -1
  112. package/src/monitors/heartbeat.ts +16 -6
  113. package/tsdown.config.ts +1 -7
  114. package/dist/Construct-BWF5HxaM.mjs.map +0 -1
  115. package/dist/Construct-JlyQkBkv.d.cts.map +0 -1
  116. package/dist/Construct-TGIM_E4o.cjs.map +0 -1
  117. package/dist/Construct-pxwC6fDD.d.mts.map +0 -1
  118. package/dist/functions-EqTloHjo.mjs.map +0 -1
  119. package/dist/functions-SqtCDc9c.cjs.map +0 -1
  120. package/dist/lazyAccessors-CCTK19xj.mjs +0 -1855
  121. package/dist/lazyAccessors-CCTK19xj.mjs.map +0 -1
  122. package/dist/lazyAccessors-D04oftGw.cjs +0 -1920
  123. package/dist/lazyAccessors-D04oftGw.cjs.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/constructs",
3
- "version": "9.1.0",
3
+ "version": "9.2.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -137,8 +137,6 @@
137
137
  "fast-glob": "~3.3.3",
138
138
  "lodash.compact": "~3.0.1",
139
139
  "lodash.get": "~4.4.2",
140
- "lodash.pick": "~4.4.0",
141
- "lodash.set": "~4.3.2",
142
140
  "lodash.uniqby": "~4.7.0",
143
141
  "openapi-types": "~12.1.3",
144
142
  "qs": "~6.15.0"
@@ -146,8 +144,6 @@
146
144
  "devDependencies": {
147
145
  "@types/lodash.compact": "~3.0.9",
148
146
  "@types/lodash.get": "~4.4.9",
149
- "@types/lodash.pick": "~4.4.9",
150
- "@types/lodash.set": "~4.3.9",
151
147
  "@types/lodash.uniqby": "~4.7.9",
152
148
  "@types/pg": "~8.15.6",
153
149
  "@types/qs": "~6.15.0",
@@ -155,34 +151,34 @@
155
151
  "kysely": "~0.29.4",
156
152
  "pg": "~8.16.3",
157
153
  "msw": "~2.10.3",
158
- "zod": "~4.1.13",
159
- "@geekmidas/cache": "^9.1.0",
160
- "@geekmidas/audit": "^9.1.0",
161
- "@geekmidas/db": "^9.1.0",
162
- "@geekmidas/envkit": "^9.1.0",
163
- "@geekmidas/errors": "^9.1.0",
164
- "@geekmidas/events": "^9.1.0",
165
- "@geekmidas/rate-limit": "^9.1.0",
166
- "@geekmidas/schema": "^9.1.0",
167
- "@geekmidas/logger": "^9.1.0",
168
- "@geekmidas/services": "^9.1.0",
169
- "@geekmidas/testkit": "^9.1.0"
154
+ "zod": "~4.6.6",
155
+ "@geekmidas/audit": "^9.2.1",
156
+ "@geekmidas/cache": "^9.2.1",
157
+ "@geekmidas/db": "^9.2.1",
158
+ "@geekmidas/envkit": "^9.2.1",
159
+ "@geekmidas/errors": "^9.2.1",
160
+ "@geekmidas/events": "^9.2.1",
161
+ "@geekmidas/logger": "^9.2.1",
162
+ "@geekmidas/rate-limit": "^9.2.1",
163
+ "@geekmidas/schema": "^9.2.1",
164
+ "@geekmidas/services": "^9.2.1",
165
+ "@geekmidas/testkit": "^9.2.1"
170
166
  },
171
167
  "peerDependencies": {
172
168
  "@middy/core": ">=6.3.1",
173
169
  "@types/aws-lambda": ">=8.10.92",
174
170
  "hono": ">=4.8.2",
175
171
  "msw": ">=2.0.0",
176
- "@geekmidas/audit": "^9.1.0",
177
- "@geekmidas/cache": "^9.1.0",
178
- "@geekmidas/db": "^9.1.0",
179
- "@geekmidas/envkit": "^9.1.0",
180
- "@geekmidas/errors": "^9.1.0",
181
- "@geekmidas/events": "^9.1.0",
182
- "@geekmidas/logger": "^9.1.0",
183
- "@geekmidas/rate-limit": "^9.1.0",
184
- "@geekmidas/schema": "^9.1.0",
185
- "@geekmidas/services": "^9.1.0"
172
+ "@geekmidas/audit": "^9.2.1",
173
+ "@geekmidas/cache": "^9.2.1",
174
+ "@geekmidas/db": "^9.2.1",
175
+ "@geekmidas/envkit": "^9.2.1",
176
+ "@geekmidas/errors": "^9.2.1",
177
+ "@geekmidas/events": "^9.2.1",
178
+ "@geekmidas/logger": "^9.2.1",
179
+ "@geekmidas/rate-limit": "^9.2.1",
180
+ "@geekmidas/schema": "^9.2.1",
181
+ "@geekmidas/services": "^9.2.1"
186
182
  },
187
183
  "peerDependenciesMeta": {
188
184
  "@geekmidas/audit": {
package/src/Construct.ts CHANGED
@@ -9,7 +9,7 @@ import type { Logger } from '@geekmidas/logger';
9
9
  import type { Service, ServiceContext } from '@geekmidas/services';
10
10
  import type { StandardSchemaV1 } from '@standard-schema/spec';
11
11
  import compact from 'lodash.compact';
12
- import type { MonitorService } from './monitor';
12
+ import type { MonitorInfo, MonitorService } from './monitor';
13
13
 
14
14
  // Cache for service environment variables to handle singleton services
15
15
  // Stores both the full list and the optional subset so the same sniff result
@@ -80,6 +80,17 @@ export abstract class Construct<
80
80
  >,
81
81
  ) {}
82
82
 
83
+ /**
84
+ * This construct's monitors as the build manifest records them, or nothing
85
+ * when it has none.
86
+ */
87
+ getMonitoring(): MonitorInfo[] | undefined {
88
+ if (!this.monitors.length) return undefined;
89
+ return this.monitors.map(
90
+ (monitor) => monitor.monitor ?? { type: monitor.serviceName },
91
+ );
92
+ }
93
+
83
94
  /**
84
95
  * Returns an array of environment variable names required by this construct's services.
85
96
  * This is determined by running a "sniffer" EnvironmentParser through each service's
@@ -145,18 +145,20 @@ describe('heartbeat', () => {
145
145
  expect(pings).toEqual(['/abc/start', '/abc']);
146
146
  });
147
147
 
148
- it('does nothing when its env var is unset', async () => {
148
+ it('skips the heartbeat but still runs when its env var is missing', async () => {
149
149
  const cron = new CronBuilder()
150
150
  .input(z.object({}))
151
151
  .schedule('rate(1 day)')
152
152
  .monitor(heartbeat.betterStack())
153
- .handle(async () => ({}));
153
+ .output(z.object({ ok: z.boolean() }))
154
+ .handle(async () => ({ ok: true }));
154
155
 
155
- await new TestFunctionAdaptor(cron, discovery()).invoke({
156
+ const output = await new TestFunctionAdaptor(cron, discovery()).invoke({
156
157
  input: {},
157
158
  services: {},
158
159
  });
159
160
 
161
+ expect(output).toEqual({ ok: true });
160
162
  expect(pings).toEqual([]);
161
163
  });
162
164
 
@@ -196,16 +198,17 @@ describe('heartbeat', () => {
196
198
  expect(output).toEqual({ ok: true });
197
199
  });
198
200
 
199
- it('declares its env var as optional', async () => {
201
+ it('declares its env var as required', async () => {
200
202
  const cron = new CronBuilder()
201
203
  .input(z.object({}))
202
204
  .schedule('rate(1 day)')
203
205
  .monitor(heartbeat.betterStack('NIGHTLY_HEARTBEAT_URL'))
204
206
  .handle(async () => ({}));
205
207
 
206
- expect(await cron.getEnvironment({ markOptional: true })).toContain(
207
- 'NIGHTLY_HEARTBEAT_URL?',
208
- );
208
+ const environment = await cron.getEnvironment({ markOptional: true });
209
+
210
+ expect(environment).toContain('NIGHTLY_HEARTBEAT_URL');
211
+ expect(environment).not.toContain('NIGHTLY_HEARTBEAT_URL?');
209
212
  });
210
213
  });
211
214
 
@@ -634,3 +637,60 @@ describe('heartbeat requests, per construct', () => {
634
637
  });
635
638
  });
636
639
  });
640
+
641
+ describe('getMonitoring', () => {
642
+ it('records each monitor for the manifest', () => {
643
+ const cron = new CronBuilder()
644
+ .schedule('rate(1 day)')
645
+ .monitor(heartbeat.betterStack('MONITORING_URL'))
646
+ .monitor(heartbeat.healthchecks('HEALTHCHECKS_URL'))
647
+ .handle(async () => ({}));
648
+
649
+ expect(cron.getMonitoring()).toEqual([
650
+ { type: 'heartbeat', provider: 'betterStack', env: 'MONITORING_URL' },
651
+ { type: 'heartbeat', provider: 'healthchecks', env: 'HEALTHCHECKS_URL' },
652
+ ]);
653
+ });
654
+
655
+ it('records a custom heartbeat without a provider, on its default env var', () => {
656
+ const fn = new FunctionBuilder()
657
+ .monitor(heartbeat())
658
+ .handle(async () => ({}));
659
+
660
+ expect(fn.getMonitoring()).toEqual([
661
+ { type: 'heartbeat', env: 'HEARTBEAT_URL' },
662
+ ]);
663
+ });
664
+
665
+ it('records a hand-written monitor by its service name', () => {
666
+ const fn = new FunctionBuilder()
667
+ .monitor({
668
+ serviceName: 'errors',
669
+ async register() {
670
+ return { async success() {}, async failure() {} };
671
+ },
672
+ })
673
+ .handle(async () => ({}));
674
+
675
+ expect(fn.getMonitoring()).toEqual([{ type: 'errors' }]);
676
+ });
677
+
678
+ it('records an endpoint’s monitors inherited from its factory', () => {
679
+ const endpoint = new EndpointFactory()
680
+ .monitor(heartbeat.betterStack())
681
+ .get('/health')
682
+ .handle(async () => ({}));
683
+
684
+ expect(endpoint.getMonitoring()).toEqual([
685
+ { type: 'heartbeat', provider: 'betterStack', env: 'HEARTBEAT_URL' },
686
+ ]);
687
+ });
688
+
689
+ it('records nothing for a construct without monitors', () => {
690
+ const cron = new CronBuilder()
691
+ .schedule('rate(1 day)')
692
+ .handle(async () => ({}));
693
+
694
+ expect(cron.getMonitoring()).toBeUndefined();
695
+ });
696
+ });
@@ -9,7 +9,6 @@ import type {
9
9
  APIGatewayProxyEventV2,
10
10
  Context,
11
11
  } from 'aws-lambda';
12
- import set from 'lodash.set';
13
12
  import type { Telemetry } from '../telemetry';
14
13
  import type { HttpMethod } from '../types';
15
14
  import { Endpoint, type EndpointSchemas, ResponseBuilder } from './Endpoint';
@@ -190,20 +189,13 @@ export abstract class AmazonApiGatewayEndpoint<
190
189
  const header = Endpoint.createHeaders(headers);
191
190
  const cookie = this.getCookies(req.event);
192
191
 
193
- set(req.event, 'body', await this.endpoint.parseInput(body, 'body'));
194
-
195
- set(
196
- req.event,
197
- 'query',
198
- await this.endpoint.parseInput(query, 'query'),
199
- );
200
- set(
201
- req.event,
202
- 'params',
203
- await this.endpoint.parseInput(params, 'params'),
204
- );
205
- set(req.event, 'header', header);
206
- set(req.event, 'cookie', cookie);
192
+ Object.assign(req.event, {
193
+ body: await this.endpoint.parseInput(body, 'body'),
194
+ query: await this.endpoint.parseInput(query, 'query'),
195
+ params: await this.endpoint.parseInput(params, 'params'),
196
+ header,
197
+ cookie,
198
+ });
207
199
  } catch (error) {
208
200
  // Convert validation errors to 422 Unprocessable Entity
209
201
  if (error && typeof error === 'object' && Array.isArray(error)) {
@@ -22,8 +22,6 @@ import {
22
22
  } from '@geekmidas/schema/openapi';
23
23
  import type { Service, ServiceRecord } from '@geekmidas/services';
24
24
  import type { StandardSchemaV1 } from '@standard-schema/spec';
25
- import pick from 'lodash.pick';
26
- import set from 'lodash.set';
27
25
  import type { OpenAPIV3_1 } from 'openapi-types';
28
26
  import { ConstructType } from '../Construct';
29
27
  import { Function, type FunctionHandler } from '../functions';
@@ -347,13 +345,14 @@ export class Endpoint<
347
345
  refineInput(
348
346
  ctx: EndpointContext<TInput, TServices, TLogger, TSession>,
349
347
  ): InferComposableStandardSchema<TInput> {
350
- const input = pick(ctx, [
351
- 'body',
352
- 'query',
353
- 'params',
354
- ]) as InferComposableStandardSchema<TInput>;
348
+ const input: Record<string, unknown> = {};
349
+ for (const key of ['body', 'query', 'params'] as const) {
350
+ if (key in ctx) {
351
+ input[key] = (ctx as Record<string, unknown>)[key];
352
+ }
353
+ }
355
354
 
356
- return input;
355
+ return input as InferComposableStandardSchema<TInput>;
357
356
  }
358
357
 
359
358
  handler = (
@@ -471,11 +470,9 @@ export class Endpoint<
471
470
  componentCollector,
472
471
  );
473
472
  if (responseSchema) {
474
- set(
475
- operation,
476
- ['responses', '200', 'content', this.responseType, 'schema'],
477
- responseSchema,
478
- );
473
+ (operation.responses!['200'] as OpenAPIV3_1.ResponseObject).content = {
474
+ [this.responseType]: { schema: responseSchema },
475
+ };
479
476
  }
480
477
  }
481
478
 
@@ -498,14 +495,14 @@ export class Endpoint<
498
495
  componentCollector,
499
496
  );
500
497
  if (bodySchema) {
501
- set(operation, ['requestBody'], {
498
+ operation.requestBody = {
502
499
  required: true,
503
500
  content: {
504
501
  'application/json': {
505
502
  schema: bodySchema,
506
503
  },
507
504
  },
508
- });
505
+ };
509
506
  }
510
507
  }
511
508
 
package/src/index.ts CHANGED
@@ -12,6 +12,7 @@ export {
12
12
  export type {
13
13
  ConstructMonitor,
14
14
  MonitorContext,
15
+ MonitorInfo,
15
16
  MonitorService,
16
17
  } from './monitor';
17
18
  // Telemetry interface
package/src/monitor.ts CHANGED
@@ -30,7 +30,23 @@ export interface ConstructMonitor<TRun = unknown> {
30
30
  ): Promise<void>;
31
31
  }
32
32
 
33
- export type MonitorService = Service<string, ConstructMonitor<any>>;
33
+ /**
34
+ * A monitor as the build manifest records it, so infrastructure can provision
35
+ * what it reports to: a heartbeat's URL, set in the variable it reads.
36
+ */
37
+ export interface MonitorInfo {
38
+ /** The kind of monitor, e.g. `heartbeat`. */
39
+ type: string;
40
+ /** The service it reports to, e.g. `betterStack`. Absent for a custom one. */
41
+ provider?: string;
42
+ /** The environment variable it reads its target from. */
43
+ env?: string;
44
+ }
45
+
46
+ export type MonitorService = Service<string, ConstructMonitor<any>> & {
47
+ /** How the manifest records this monitor. Defaults to its service name. */
48
+ monitor?: MonitorInfo;
49
+ };
34
50
 
35
51
  /** A run in progress, closed by exactly one of its two methods. */
36
52
  export interface MonitoredRun {
@@ -1,10 +1,12 @@
1
1
  import type { Service } from '@geekmidas/services';
2
- import type { ConstructMonitor } from '../monitor';
2
+ import type { ConstructMonitor, MonitorInfo } from '../monitor';
3
3
 
4
4
  export interface HeartbeatOptions {
5
5
  /**
6
- * The environment variable holding the heartbeat URL. When it is unset the
7
- * monitor does nothing, so only the stages that set it are monitored.
6
+ * The environment variable holding the heartbeat URL. Required: the manifest
7
+ * lists it so infrastructure sets it wherever the construct is deployed. If
8
+ * it is missing at runtime the monitor is skipped with a warning, and the
9
+ * run goes on.
8
10
  * @default 'HEARTBEAT_URL'
9
11
  */
10
12
  env?: string;
@@ -19,6 +21,11 @@ export interface HeartbeatOptions {
19
21
  failure?: (url: string) => string;
20
22
  /** Milliseconds to wait for the provider. @default 3000 */
21
23
  timeout?: number;
24
+ /**
25
+ * The service the URL belongs to, recorded in the manifest so infrastructure
26
+ * knows which kind of heartbeat to create. Set by the presets.
27
+ */
28
+ provider?: string;
22
29
  }
23
30
 
24
31
  /**
@@ -36,20 +43,22 @@ export interface HeartbeatOptions {
36
43
  */
37
44
  export function heartbeat(
38
45
  options: HeartbeatOptions = {},
39
- ): Service<`heartbeat:${string}`, ConstructMonitor> {
46
+ ): Service<`heartbeat:${string}`, ConstructMonitor> & { monitor: MonitorInfo } {
40
47
  const {
41
48
  env = 'HEARTBEAT_URL',
42
49
  start,
43
50
  success = (url) => url,
44
51
  failure,
45
52
  timeout = 3000,
53
+ provider,
46
54
  } = options;
47
55
 
48
56
  return {
49
57
  serviceName: `heartbeat:${env}`,
58
+ monitor: { type: 'heartbeat', ...(provider ? { provider } : {}), env },
50
59
  async register({ envParser }) {
51
60
  const { url } = envParser
52
- .create((get) => ({ url: get(env).string().optional() }))
61
+ .create((get) => ({ url: get(env).string() }))
53
62
  .parse();
54
63
 
55
64
  const ping = async (target?: (url: string) => string) => {
@@ -75,12 +84,13 @@ export function heartbeat(
75
84
 
76
85
  /** Better Stack heartbeats: `{url}` on success, `{url}/fail` on failure. */
77
86
  heartbeat.betterStack = (env?: string) =>
78
- heartbeat({ env, failure: (url) => `${url}/fail` });
87
+ heartbeat({ env, provider: 'betterStack', failure: (url) => `${url}/fail` });
79
88
 
80
89
  /** Healthchecks.io: `{url}/start`, `{url}` and `{url}/fail`. */
81
90
  heartbeat.healthchecks = (env?: string) =>
82
91
  heartbeat({
83
92
  env,
93
+ provider: 'healthchecks',
84
94
  start: (url) => `${url}/start`,
85
95
  failure: (url) => `${url}/fail`,
86
96
  });
package/tsdown.config.ts CHANGED
@@ -25,11 +25,5 @@ export default defineConfig({
25
25
  }),
26
26
  // Bundle lodash utilities — they are not hoisted to the workspace root
27
27
  // and would fail to resolve when consumers load the dist from the root context.
28
- noExternal: [
29
- 'lodash.compact',
30
- 'lodash.get',
31
- 'lodash.pick',
32
- 'lodash.set',
33
- 'lodash.uniqby',
34
- ],
28
+ noExternal: ['lodash.compact', 'lodash.get', 'lodash.uniqby'],
35
29
  });
@@ -1 +0,0 @@
1
- {"version":3,"file":"Construct-BWF5HxaM.mjs","names":["compact","snifferContext: ServiceContext","type: ConstructType","logger: TLogger","services: TServices","events: MappedEvent<T, any>[]","publisherService?: Service<TServiceName, T>","outputSchema?: OutSchema","timeout?: number","memorySize?: number","auditorStorageService?: Service<\n\t\t\tTAuditStorageServiceName,\n\t\t\tTAuditStorage\n\t\t>","opts: { markOptional?: boolean }","services: Service[]","service: Service"],"sources":["../../../node_modules/.pnpm/lodash.compact@3.0.1/node_modules/lodash.compact/index.js","../src/Construct.ts"],"sourcesContent":["/**\n * lodash 3.0.1 (Custom Build) <https://lodash.com/>\n * Build: `lodash modularize exports=\"npm\" -o ./`\n * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>\n * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>\n * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors\n * Available under MIT license <https://lodash.com/license>\n */\n\n/**\n * Creates an array with all falsey values removed. The values `false`, `null`,\n * `0`, `\"\"`, `undefined`, and `NaN` are falsey.\n *\n * @static\n * @memberOf _\n * @category Array\n * @param {Array} array The array to compact.\n * @returns {Array} Returns the new array of filtered values.\n * @example\n *\n * _.compact([0, 1, false, 2, '', 3]);\n * // => [1, 2, 3]\n */\nfunction compact(array) {\n var index = -1,\n length = array ? array.length : 0,\n resIndex = 0,\n result = [];\n\n while (++index < length) {\n var value = array[index];\n if (value) {\n result[resIndex++] = value;\n }\n }\n return result;\n}\n\nmodule.exports = compact;\n","import type { AuditStorage } from '@geekmidas/audit';\nimport {\n\tSnifferEnvironmentParser,\n\ttype SniffResult,\n\tsniffWithFireAndForget,\n} from '@geekmidas/envkit/sniffer';\nimport type { EventPublisher, MappedEvent } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type { Service, ServiceContext } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport compact from 'lodash.compact';\nimport type { MonitorService } from './monitor';\n\n// Cache for service environment variables to handle singleton services\n// Stores both the full list and the optional subset so the same sniff result\n// can satisfy both getEnvironment() and getEnvironment({ markOptional: true }).\nconst serviceEnvCache = new Map<\n\tService,\n\t{ envVars: string[]; optionalEnvVars: string[] }\n>();\n\n/**\n * Noop context for environment sniffing.\n * Used when calling service.register() to detect env vars without a real request.\n * Returns dummy values since services should only use context in instance methods,\n * not during registration.\n */\nconst snifferContext: ServiceContext = {\n\tgetLogger() {\n\t\t// Return a noop logger for sniffing - services shouldn't log during registration\n\t\treturn {\n\t\t\tdebug: () => {},\n\t\t\tinfo: () => {},\n\t\t\twarn: () => {},\n\t\t\terror: () => {},\n\t\t\tchild: () => snifferContext.getLogger(),\n\t\t} as unknown as Logger;\n\t},\n\tgetRequestId() {\n\t\treturn 'sniffer-context';\n\t},\n\tgetRequestStartTime() {\n\t\treturn Date.now();\n\t},\n\thasContext() {\n\t\treturn false;\n\t},\n};\n\nexport abstract class Construct<\n\tTLogger extends Logger = Logger,\n\tTServiceName extends string = string,\n\tT extends EventPublisher<any> | undefined = undefined,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTAuditStorageServiceName extends string = string,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTDatabaseServiceName extends string = string,\n\tTDatabase = unknown,\n> {\n\t/** Database service for this construct (used by Endpoint for RLS/audit context) */\n\tpublic databaseService?: Service<TDatabaseServiceName, TDatabase>;\n\n\t/** Monitors told about each run of this construct (see `.monitor()`). */\n\tpublic monitors: MonitorService[] = [];\n\n\tconstructor(\n\t\tpublic readonly type: ConstructType,\n\t\tpublic readonly logger: TLogger,\n\t\tpublic readonly services: TServices,\n\t\tpublic readonly events: MappedEvent<T, any>[] = [],\n\n\t\tpublic readonly publisherService?: Service<TServiceName, T>,\n\t\tpublic outputSchema?: OutSchema,\n\t\tpublic readonly timeout?: number,\n\t\tpublic readonly memorySize?: number,\n\t\tpublic readonly auditorStorageService?: Service<\n\t\t\tTAuditStorageServiceName,\n\t\t\tTAuditStorage\n\t\t>,\n\t) {}\n\n\t/**\n\t * Returns an array of environment variable names required by this construct's services.\n\t * This is determined by running a \"sniffer\" EnvironmentParser through each service's\n\t * register method to track which environment variables are accessed.\n\t *\n\t * Results are cached per service class to handle singleton patterns where\n\t * subsequent register() calls may short-circuit and not access env vars.\n\t *\n\t * @param markOptional - When true, optional vars (those accessed via `.optional()` or\n\t * `.default()`) are suffixed with `?` in the returned array (e.g. `'PORT?'`).\n\t * @returns Promise that resolves to array of environment variable names, sorted alphabetically\n\t *\n\t * @example\n\t * ```typescript\n\t * const endpoint = e\n\t * .services([databaseService, authService])\n\t * .get('/users')\n\t * .handle(async () => []);\n\t *\n\t * await endpoint.getEnvironment(); // ['AUTH_SECRET', 'DATABASE_URL']\n\t * await endpoint.getEnvironment({ markOptional: true }); // ['AUTH_SECRET', 'DATABASE_URL', 'PORT?']\n\t * ```\n\t */\n\tasync getEnvironment(\n\t\topts: { markOptional?: boolean } = {},\n\t): Promise<string[]> {\n\t\tconst { markOptional = false } = opts;\n\t\tconst envVars = new Set<string>();\n\t\tconst optionalVars = new Set<string>();\n\t\tconst services: Service[] = compact([\n\t\t\t...this.services,\n\t\t\tthis.publisherService,\n\t\t\tthis.publisherService,\n\t\t\tthis.auditorStorageService,\n\t\t\tthis.databaseService,\n\t\t\t...this.monitors,\n\t\t]);\n\n\t\ttry {\n\t\t\tfor (const service of services) {\n\t\t\t\t// Check cache first - handles singleton services that short-circuit\n\t\t\t\tif (serviceEnvCache.has(service)) {\n\t\t\t\t\tconst cached = serviceEnvCache.get(service)!;\n\t\t\t\t\tcached.envVars.forEach((v) => envVars.add(v));\n\t\t\t\t\tcached.optionalEnvVars.forEach((v) => optionalVars.add(v));\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Use sniffService to properly handle all error scenarios\n\t\t\t\tconst result = await sniffService(service);\n\n\t\t\t\t// Log any issues for debugging\n\t\t\t\tif (result.error) {\n\t\t\t\t\tthis.logger.warn(\n\t\t\t\t\t\t{ error: result.error.message, service: service.serviceName },\n\t\t\t\t\t\t'Service threw error during env sniffing (env vars still captured)',\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (result.unhandledRejections.length > 0) {\n\t\t\t\t\tthis.logger.warn(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\terrors: result.unhandledRejections.map((e) => e.message),\n\t\t\t\t\t\t\tservice: service.serviceName,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t'Fire-and-forget rejections during env sniffing (suppressed)',\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Cache and collect env vars (both required and optional)\n\t\t\t\tserviceEnvCache.set(service, {\n\t\t\t\t\tenvVars: result.envVars,\n\t\t\t\t\toptionalEnvVars: result.optionalEnvVars,\n\t\t\t\t});\n\t\t\t\tresult.envVars.forEach((v) => envVars.add(v));\n\t\t\t\tresult.optionalEnvVars.forEach((v) => optionalVars.add(v));\n\t\t\t}\n\n\t\t\tconst sorted = Array.from(envVars).sort();\n\t\t\tif (!markOptional || optionalVars.size === 0) return sorted;\n\t\t\treturn sorted.map((v) => (optionalVars.has(v) ? `${v}?` : v));\n\t\t} catch (error) {\n\t\t\tthis.logger.error(\n\t\t\t\t{ error },\n\t\t\t\t'Error determining environment variables for construct',\n\t\t\t);\n\n\t\t\treturn [];\n\t\t}\n\t}\n}\n\nexport enum ConstructType {\n\tCron = 'dev.geekmidas.function.cron',\n\tEndpoint = 'dev.geekmidas.function.endpoint',\n\tFunction = 'dev.geekmidas.function.function',\n\tSubscriber = 'dev.geekmidas.function.subscriber',\n\tQueue = 'dev.geekmidas.function.queue',\n\tTopic = 'dev.geekmidas.resource.topic',\n}\n\n/**\n * Utility to test sniffing a service for environment variables.\n * Useful for debugging services that throw errors during sniffing.\n *\n * @example\n * ```typescript\n * import { sniffService } from '@geekmidas/constructs';\n * import { authService } from './services/AuthService';\n *\n * const result = await sniffService(authService);\n * console.log('Env vars:', result.envVars);\n * console.log('Error:', result.error);\n * ```\n */\nexport async function sniffService(service: Service): Promise<SniffResult> {\n\tconst sniffer = new SnifferEnvironmentParser();\n\n\treturn sniffWithFireAndForget(sniffer, () =>\n\t\tservice.register({\n\t\t\tenvParser: sniffer as any,\n\t\t\tcontext: snifferContext,\n\t\t}),\n\t);\n}\n\n// Export for testing\nexport { snifferContext };\n"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuBA,SAASA,UAAQ,OAAO;EACtB,IAAI,QAAQ,IACR,SAAS,QAAQ,MAAM,SAAS,GAChC,WAAW,GACX,SAAS,CAAE;AAEf,SAAO,EAAE,QAAQ,QAAQ;GACvB,IAAI,QAAQ,MAAM;AAClB,OAAI,MACF,QAAO,cAAc;EAExB;AACD,SAAO;CACR;AAED,QAAO,UAAUA;;;;;;ACtBjB,MAAM,kCAAkB,IAAI;;;;;;;AAW5B,MAAMC,iBAAiC;CACtC,YAAY;AAEX,SAAO;GACN,OAAO,MAAM,CAAE;GACf,MAAM,MAAM,CAAE;GACd,MAAM,MAAM,CAAE;GACd,OAAO,MAAM,CAAE;GACf,OAAO,MAAM,eAAe,WAAW;EACvC;CACD;CACD,eAAe;AACd,SAAO;CACP;CACD,sBAAsB;AACrB,SAAO,KAAK,KAAK;CACjB;CACD,aAAa;AACZ,SAAO;CACP;AACD;AAED,IAAsB,YAAtB,MAUE;;CAED,AAAO;;CAGP,AAAO,WAA6B,CAAE;CAEtC,YACiBC,MACAC,QACAC,UACAC,SAAgC,CAAE,GAElCC,kBACTC,cACSC,SACAC,YACAC,uBAIf;EAbe;EACA;EACA;EACA;EAEA;EACT;EACS;EACA;EACA;CAIb;;;;;;;;;;;;;;;;;;;;;;;;CAyBJ,MAAM,eACLC,OAAmC,CAAE,GACjB;EACpB,MAAM,EAAE,eAAe,OAAO,GAAG;EACjC,MAAM,0BAAU,IAAI;EACpB,MAAM,+BAAe,IAAI;EACzB,MAAMC,WAAsB,2BAAQ;GACnC,GAAG,KAAK;GACR,KAAK;GACL,KAAK;GAC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AAA,EAAA,CAAA;;AAAR,aAgHd,aAAA;EAhHqB,IAGf,GAAA,6BAAA;EAAc,QAGR,GAAA,iCAAA;EAAa,QACX,GAAA,iCAAA;EAAO,UACL,GAAA,mCAAA;EAAS,KACC,GAAA,8BAAA;EAAC,KAAb,GAAA,8BAAA;;;;;;;;;AAqCf;AAkEX;AAuBA;;;;;AAA6D,iBAAvC,YAAA,CAAuC,OAAA,EAAjB,OAAiB,CAAA,EAAP,OAAO,CAAC,WAAD,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Construct-TGIM_E4o.cjs","names":["compact","snifferContext: ServiceContext","type: ConstructType","logger: TLogger","services: TServices","events: MappedEvent<T, any>[]","publisherService?: Service<TServiceName, T>","outputSchema?: OutSchema","timeout?: number","memorySize?: number","auditorStorageService?: Service<\n\t\t\tTAuditStorageServiceName,\n\t\t\tTAuditStorage\n\t\t>","opts: { markOptional?: boolean }","services: Service[]","service: Service","SnifferEnvironmentParser"],"sources":["../../../node_modules/.pnpm/lodash.compact@3.0.1/node_modules/lodash.compact/index.js","../src/Construct.ts"],"sourcesContent":["/**\n * lodash 3.0.1 (Custom Build) <https://lodash.com/>\n * Build: `lodash modularize exports=\"npm\" -o ./`\n * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>\n * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>\n * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors\n * Available under MIT license <https://lodash.com/license>\n */\n\n/**\n * Creates an array with all falsey values removed. The values `false`, `null`,\n * `0`, `\"\"`, `undefined`, and `NaN` are falsey.\n *\n * @static\n * @memberOf _\n * @category Array\n * @param {Array} array The array to compact.\n * @returns {Array} Returns the new array of filtered values.\n * @example\n *\n * _.compact([0, 1, false, 2, '', 3]);\n * // => [1, 2, 3]\n */\nfunction compact(array) {\n var index = -1,\n length = array ? array.length : 0,\n resIndex = 0,\n result = [];\n\n while (++index < length) {\n var value = array[index];\n if (value) {\n result[resIndex++] = value;\n }\n }\n return result;\n}\n\nmodule.exports = compact;\n","import type { AuditStorage } from '@geekmidas/audit';\nimport {\n\tSnifferEnvironmentParser,\n\ttype SniffResult,\n\tsniffWithFireAndForget,\n} from '@geekmidas/envkit/sniffer';\nimport type { EventPublisher, MappedEvent } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type { Service, ServiceContext } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport compact from 'lodash.compact';\nimport type { MonitorService } from './monitor';\n\n// Cache for service environment variables to handle singleton services\n// Stores both the full list and the optional subset so the same sniff result\n// can satisfy both getEnvironment() and getEnvironment({ markOptional: true }).\nconst serviceEnvCache = new Map<\n\tService,\n\t{ envVars: string[]; optionalEnvVars: string[] }\n>();\n\n/**\n * Noop context for environment sniffing.\n * Used when calling service.register() to detect env vars without a real request.\n * Returns dummy values since services should only use context in instance methods,\n * not during registration.\n */\nconst snifferContext: ServiceContext = {\n\tgetLogger() {\n\t\t// Return a noop logger for sniffing - services shouldn't log during registration\n\t\treturn {\n\t\t\tdebug: () => {},\n\t\t\tinfo: () => {},\n\t\t\twarn: () => {},\n\t\t\terror: () => {},\n\t\t\tchild: () => snifferContext.getLogger(),\n\t\t} as unknown as Logger;\n\t},\n\tgetRequestId() {\n\t\treturn 'sniffer-context';\n\t},\n\tgetRequestStartTime() {\n\t\treturn Date.now();\n\t},\n\thasContext() {\n\t\treturn false;\n\t},\n};\n\nexport abstract class Construct<\n\tTLogger extends Logger = Logger,\n\tTServiceName extends string = string,\n\tT extends EventPublisher<any> | undefined = undefined,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTAuditStorageServiceName extends string = string,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTDatabaseServiceName extends string = string,\n\tTDatabase = unknown,\n> {\n\t/** Database service for this construct (used by Endpoint for RLS/audit context) */\n\tpublic databaseService?: Service<TDatabaseServiceName, TDatabase>;\n\n\t/** Monitors told about each run of this construct (see `.monitor()`). */\n\tpublic monitors: MonitorService[] = [];\n\n\tconstructor(\n\t\tpublic readonly type: ConstructType,\n\t\tpublic readonly logger: TLogger,\n\t\tpublic readonly services: TServices,\n\t\tpublic readonly events: MappedEvent<T, any>[] = [],\n\n\t\tpublic readonly publisherService?: Service<TServiceName, T>,\n\t\tpublic outputSchema?: OutSchema,\n\t\tpublic readonly timeout?: number,\n\t\tpublic readonly memorySize?: number,\n\t\tpublic readonly auditorStorageService?: Service<\n\t\t\tTAuditStorageServiceName,\n\t\t\tTAuditStorage\n\t\t>,\n\t) {}\n\n\t/**\n\t * Returns an array of environment variable names required by this construct's services.\n\t * This is determined by running a \"sniffer\" EnvironmentParser through each service's\n\t * register method to track which environment variables are accessed.\n\t *\n\t * Results are cached per service class to handle singleton patterns where\n\t * subsequent register() calls may short-circuit and not access env vars.\n\t *\n\t * @param markOptional - When true, optional vars (those accessed via `.optional()` or\n\t * `.default()`) are suffixed with `?` in the returned array (e.g. `'PORT?'`).\n\t * @returns Promise that resolves to array of environment variable names, sorted alphabetically\n\t *\n\t * @example\n\t * ```typescript\n\t * const endpoint = e\n\t * .services([databaseService, authService])\n\t * .get('/users')\n\t * .handle(async () => []);\n\t *\n\t * await endpoint.getEnvironment(); // ['AUTH_SECRET', 'DATABASE_URL']\n\t * await endpoint.getEnvironment({ markOptional: true }); // ['AUTH_SECRET', 'DATABASE_URL', 'PORT?']\n\t * ```\n\t */\n\tasync getEnvironment(\n\t\topts: { markOptional?: boolean } = {},\n\t): Promise<string[]> {\n\t\tconst { markOptional = false } = opts;\n\t\tconst envVars = new Set<string>();\n\t\tconst optionalVars = new Set<string>();\n\t\tconst services: Service[] = compact([\n\t\t\t...this.services,\n\t\t\tthis.publisherService,\n\t\t\tthis.publisherService,\n\t\t\tthis.auditorStorageService,\n\t\t\tthis.databaseService,\n\t\t\t...this.monitors,\n\t\t]);\n\n\t\ttry {\n\t\t\tfor (const service of services) {\n\t\t\t\t// Check cache first - handles singleton services that short-circuit\n\t\t\t\tif (serviceEnvCache.has(service)) {\n\t\t\t\t\tconst cached = serviceEnvCache.get(service)!;\n\t\t\t\t\tcached.envVars.forEach((v) => envVars.add(v));\n\t\t\t\t\tcached.optionalEnvVars.forEach((v) => optionalVars.add(v));\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Use sniffService to properly handle all error scenarios\n\t\t\t\tconst result = await sniffService(service);\n\n\t\t\t\t// Log any issues for debugging\n\t\t\t\tif (result.error) {\n\t\t\t\t\tthis.logger.warn(\n\t\t\t\t\t\t{ error: result.error.message, service: service.serviceName },\n\t\t\t\t\t\t'Service threw error during env sniffing (env vars still captured)',\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (result.unhandledRejections.length > 0) {\n\t\t\t\t\tthis.logger.warn(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\terrors: result.unhandledRejections.map((e) => e.message),\n\t\t\t\t\t\t\tservice: service.serviceName,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t'Fire-and-forget rejections during env sniffing (suppressed)',\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Cache and collect env vars (both required and optional)\n\t\t\t\tserviceEnvCache.set(service, {\n\t\t\t\t\tenvVars: result.envVars,\n\t\t\t\t\toptionalEnvVars: result.optionalEnvVars,\n\t\t\t\t});\n\t\t\t\tresult.envVars.forEach((v) => envVars.add(v));\n\t\t\t\tresult.optionalEnvVars.forEach((v) => optionalVars.add(v));\n\t\t\t}\n\n\t\t\tconst sorted = Array.from(envVars).sort();\n\t\t\tif (!markOptional || optionalVars.size === 0) return sorted;\n\t\t\treturn sorted.map((v) => (optionalVars.has(v) ? `${v}?` : v));\n\t\t} catch (error) {\n\t\t\tthis.logger.error(\n\t\t\t\t{ error },\n\t\t\t\t'Error determining environment variables for construct',\n\t\t\t);\n\n\t\t\treturn [];\n\t\t}\n\t}\n}\n\nexport enum ConstructType {\n\tCron = 'dev.geekmidas.function.cron',\n\tEndpoint = 'dev.geekmidas.function.endpoint',\n\tFunction = 'dev.geekmidas.function.function',\n\tSubscriber = 'dev.geekmidas.function.subscriber',\n\tQueue = 'dev.geekmidas.function.queue',\n\tTopic = 'dev.geekmidas.resource.topic',\n}\n\n/**\n * Utility to test sniffing a service for environment variables.\n * Useful for debugging services that throw errors during sniffing.\n *\n * @example\n * ```typescript\n * import { sniffService } from '@geekmidas/constructs';\n * import { authService } from './services/AuthService';\n *\n * const result = await sniffService(authService);\n * console.log('Env vars:', result.envVars);\n * console.log('Error:', result.error);\n * ```\n */\nexport async function sniffService(service: Service): Promise<SniffResult> {\n\tconst sniffer = new SnifferEnvironmentParser();\n\n\treturn sniffWithFireAndForget(sniffer, () =>\n\t\tservice.register({\n\t\t\tenvParser: sniffer as any,\n\t\t\tcontext: snifferContext,\n\t\t}),\n\t);\n}\n\n// Export for testing\nexport { snifferContext };\n"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuBA,SAASA,UAAQ,OAAO;EACtB,IAAI,QAAQ,IACR,SAAS,QAAQ,MAAM,SAAS,GAChC,WAAW,GACX,SAAS,CAAE;AAEf,SAAO,EAAE,QAAQ,QAAQ;GACvB,IAAI,QAAQ,MAAM;AAClB,OAAI,MACF,QAAO,cAAc;EAExB;AACD,SAAO;CACR;AAED,QAAO,UAAUA;;;;;;ACtBjB,MAAM,kCAAkB,IAAI;;;;;;;AAW5B,MAAMC,iBAAiC;CACtC,YAAY;AAEX,SAAO;GACN,OAAO,MAAM,CAAE;GACf,MAAM,MAAM,CAAE;GACd,MAAM,MAAM,CAAE;GACd,OAAO,MAAM,CAAE;GACf,OAAO,MAAM,eAAe,WAAW;EACvC;CACD;CACD,eAAe;AACd,SAAO;CACP;CACD,sBAAsB;AACrB,SAAO,KAAK,KAAK;CACjB;CACD,aAAa;AACZ,SAAO;CACP;AACD;AAED,IAAsB,YAAtB,MA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