franchising 0.0.0-stage → 0.2.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.
Files changed (237) hide show
  1. package/LICENSE +61 -0
  2. package/README.md +96 -2
  3. package/dist/accounts-B4bnTXUd.js +242 -0
  4. package/dist/accounts-B4bnTXUd.js.map +1 -0
  5. package/dist/accounts-TyMPSHM0.cjs +313 -0
  6. package/dist/accounts-TyMPSHM0.cjs.map +1 -0
  7. package/dist/adapters-DM59AJfR.d.cts +216 -0
  8. package/dist/adapters-DM59AJfR.d.ts +216 -0
  9. package/dist/cli/template-assets/api/src/errors/codes.ts +17 -0
  10. package/dist/cli/template-assets/api/src/errors/index.ts +16 -0
  11. package/dist/cli/template-assets/api/src/filters/exception.ts +53 -0
  12. package/dist/cli/template-assets/api/src/main.ts +189 -0
  13. package/dist/cli/template-assets/api/src/modules/health/controller.ts +23 -0
  14. package/dist/cli/template-assets/api/src/modules/health/dto/response.dto.ts +23 -0
  15. package/dist/cli/template-assets/api/src/modules/health/module.ts +12 -0
  16. package/dist/cli/template-assets/api/src/modules/health/service.ts +54 -0
  17. package/dist/cli/template-assets/api/src/modules/messaging/module.ts +7 -0
  18. package/dist/cli/template-assets/api/src/modules/messaging/service.ts +74 -0
  19. package/dist/cli/template-assets/api/src/shared/exceptions.ts +40 -0
  20. package/dist/cli/template-assets/api/src/shared/response.ts +31 -0
  21. package/dist/cli/template-assets/api/src/telemetry.ts +59 -0
  22. package/dist/cli/template-assets/api/src/types.ts +8 -0
  23. package/dist/cli/template-assets/cloudflare/cache.service.ts +23 -0
  24. package/dist/cli/template-assets/cloudflare/queue.service.ts +22 -0
  25. package/dist/cli/template-assets/cloudflare/worker.ts +33 -0
  26. package/dist/cli/template-assets/packages/jobs/src/index.ts +49 -0
  27. package/dist/cli/template-assets/packages/queue-runtime/src/index.ts +54 -0
  28. package/dist/cli/template-assets/root/dot-dockerignore +11 -0
  29. package/dist/cli/template-assets/root/dot-editorconfig +13 -0
  30. package/dist/cli/template-assets/root/dot-oxfmtrc.json +9 -0
  31. package/dist/cli/template-assets/root/dot-oxlintrc.json +47 -0
  32. package/dist/cli/template-assets/root/lefthook.yml +18 -0
  33. package/dist/cli/template-assets/web/postcss.config.mjs +9 -0
  34. package/dist/cli/template-assets/web/src/app/(app)/dashboard/page.tsx +5 -0
  35. package/dist/cli/template-assets/web/src/app/(app)/layout.tsx +25 -0
  36. package/dist/cli/template-assets/web/src/app/(auth)/login/page.tsx +75 -0
  37. package/dist/cli/template-assets/web/src/app/globals.css +48 -0
  38. package/dist/cli/template-assets/web/src/app/layout.tsx +30 -0
  39. package/dist/cli/template-assets/web/src/app/page.tsx +20 -0
  40. package/dist/cli/template-assets/web/src/components/overview/overview-panel.tsx +27 -0
  41. package/dist/cli/template-assets/web/src/components/shell/app-shell.tsx +37 -0
  42. package/dist/cli/template-assets/web/src/components/shell/providers.tsx +22 -0
  43. package/dist/cli/template-assets/web/src/lib/api-client.ts +57 -0
  44. package/dist/cli/template-assets/web/src/lib/auth-client.ts +15 -0
  45. package/dist/cli/template-assets/web/src/lib/server-auth.ts +38 -0
  46. package/dist/cli/template-assets/web/src/types/api.ts +18 -0
  47. package/dist/cli/template-assets/worker/src/app.module.ts +5 -0
  48. package/dist/cli/template-assets/worker/src/env.ts +8 -0
  49. package/dist/cli/template-assets/worker/src/main.ts +25 -0
  50. package/dist/cli/template-assets/worker/src/modules/queue/config.ts +16 -0
  51. package/dist/cli/template-assets/worker/src/modules/queue/module.ts +11 -0
  52. package/dist/cli/template-assets/worker/src/modules/queue/processor.ts +105 -0
  53. package/dist/cli/template-assets/worker/src/modules/queue/repository.ts +16 -0
  54. package/dist/cli/template-assets/worker/src/modules/queue/retry.ts +17 -0
  55. package/dist/cli/template-assets/worker/test/retry.test.ts.tpl +12 -0
  56. package/dist/cli/template-assets/worker-messaging/jobs-messaging.ts +12 -0
  57. package/dist/cli/template-assets/worker-messaging/messaging-api-service.ts +39 -0
  58. package/dist/cli/template-assets/worker-messaging/src/env.ts +14 -0
  59. package/dist/cli/template-assets/worker-messaging/src/modules/messaging/service.ts +59 -0
  60. package/dist/cli/template-assets/worker-messaging/src/modules/queue/module.ts +8 -0
  61. package/dist/cli/template-assets/worker-messaging/src/modules/queue/processor.ts +113 -0
  62. package/dist/cli.js +1218 -0
  63. package/dist/cn-BVOnrSza.js +1 -0
  64. package/dist/constants-C4iP0--i.js +38 -0
  65. package/dist/constants-C4iP0--i.js.map +1 -0
  66. package/dist/constants-rCR-LNSN.cjs +91 -0
  67. package/dist/constants-rCR-LNSN.cjs.map +1 -0
  68. package/dist/core-BidJDmSN.cjs +759 -0
  69. package/dist/core-BidJDmSN.cjs.map +1 -0
  70. package/dist/core-C-EFrEd6.js +710 -0
  71. package/dist/core-C-EFrEd6.js.map +1 -0
  72. package/dist/decorate-BR5FVX5x.js +14 -0
  73. package/dist/decorate-R-oqksAh.cjs +25 -0
  74. package/dist/decorateParam-BFJPEGKJ.cjs +13 -0
  75. package/dist/decorateParam-CKE7_J1s.js +8 -0
  76. package/dist/define-adapter-Cc0QrfKt.cjs +16 -0
  77. package/dist/define-adapter-Cc0QrfKt.cjs.map +1 -0
  78. package/dist/define-adapter-DRcXno3j.js +11 -0
  79. package/dist/define-adapter-DRcXno3j.js.map +1 -0
  80. package/dist/dispatcher-BsD7cO2w.cjs +84 -0
  81. package/dist/dispatcher-BsD7cO2w.cjs.map +1 -0
  82. package/dist/dispatcher-DA_l1Vkv.js +73 -0
  83. package/dist/dispatcher-DA_l1Vkv.js.map +1 -0
  84. package/dist/errors-DxHoXrLd.d.cts +46 -0
  85. package/dist/errors-DxHoXrLd.d.ts +46 -0
  86. package/dist/http/index.cjs +440 -0
  87. package/dist/http/index.cjs.map +1 -0
  88. package/dist/http/index.d.cts +257 -0
  89. package/dist/http/index.d.ts +257 -0
  90. package/dist/http/index.js +400 -0
  91. package/dist/http/index.js.map +1 -0
  92. package/dist/http/swagger.cjs +122 -0
  93. package/dist/http/swagger.cjs.map +1 -0
  94. package/dist/http/swagger.d.cts +59 -0
  95. package/dist/http/swagger.d.ts +59 -0
  96. package/dist/http/swagger.js +117 -0
  97. package/dist/http/swagger.js.map +1 -0
  98. package/dist/index--EJQTnHy.d.cts +174 -0
  99. package/dist/index-B3aVdDMV.d.cts +51 -0
  100. package/dist/index-BDYdEWl2.d.cts +833 -0
  101. package/dist/index-BDYdEWl2.d.ts +833 -0
  102. package/dist/index-Bdl0AiNM.d.ts +1262 -0
  103. package/dist/index-By8b4ksT.d.ts +25 -0
  104. package/dist/index-ByS2IC02.d.ts +51 -0
  105. package/dist/index-DDSaLjXV.d.cts +25 -0
  106. package/dist/index-FTrYdHfq.d.cts +1262 -0
  107. package/dist/index-u3ArUXO0.d.ts +174 -0
  108. package/dist/index.cjs +1 -0
  109. package/dist/index.d.cts +4 -0
  110. package/dist/index.d.ts +4 -0
  111. package/dist/index.js +1 -0
  112. package/dist/label-BqmJoVE-.cjs +1 -0
  113. package/dist/label-XeChe1Bu.js +1 -0
  114. package/dist/messaging/index.cjs +1 -0
  115. package/dist/messaging/index.d.cts +1775 -0
  116. package/dist/messaging/index.d.ts +1775 -0
  117. package/dist/messaging/index.js +1 -0
  118. package/dist/misc-BpM_lMTx.js +1 -0
  119. package/dist/misc-DkqJOm1V.cjs +1 -0
  120. package/dist/operational-CnxdBwVG.d.cts +13 -0
  121. package/dist/operational-CnxdBwVG.d.ts +13 -0
  122. package/dist/redaction-DhuHTlHA.js +124 -0
  123. package/dist/redaction-DhuHTlHA.js.map +1 -0
  124. package/dist/redaction-uRIQbTwZ.cjs +171 -0
  125. package/dist/redaction-uRIQbTwZ.cjs.map +1 -0
  126. package/dist/rolldown-runtime-auK_WOaK.cjs +1 -0
  127. package/dist/rolldown-runtime-xuxB8TGW.cjs +32 -0
  128. package/dist/sdk-B2Lp3JCz.cjs +45 -0
  129. package/dist/sdk-B2Lp3JCz.cjs.map +1 -0
  130. package/dist/sdk-IGOHpAeG.js +22 -0
  131. package/dist/sdk-IGOHpAeG.js.map +1 -0
  132. package/dist/skills-C1uwr9Pp.js +4 -0
  133. package/dist/skills-DuE-XnBp.js +1 -0
  134. package/dist/sso/client.cjs +37 -0
  135. package/dist/sso/client.cjs.map +1 -0
  136. package/dist/sso/client.d.cts +89 -0
  137. package/dist/sso/client.d.ts +89 -0
  138. package/dist/sso/client.js +36 -0
  139. package/dist/sso/client.js.map +1 -0
  140. package/dist/sso/index.cjs +833 -0
  141. package/dist/sso/index.cjs.map +1 -0
  142. package/dist/sso/index.d.cts +2 -0
  143. package/dist/sso/index.d.ts +2 -0
  144. package/dist/sso/index.js +821 -0
  145. package/dist/sso/index.js.map +1 -0
  146. package/dist/sso/nestjs.cjs +169 -0
  147. package/dist/sso/nestjs.cjs.map +1 -0
  148. package/dist/sso/nestjs.d.cts +92 -0
  149. package/dist/sso/nestjs.d.ts +92 -0
  150. package/dist/sso/nestjs.js +151 -0
  151. package/dist/sso/nestjs.js.map +1 -0
  152. package/dist/sso/resource.cjs +124 -0
  153. package/dist/sso/resource.cjs.map +1 -0
  154. package/dist/sso/resource.d.cts +3 -0
  155. package/dist/sso/resource.d.ts +3 -0
  156. package/dist/sso/resource.js +114 -0
  157. package/dist/sso/resource.js.map +1 -0
  158. package/dist/status-CRvlFPIs.js +13 -0
  159. package/dist/status-CRvlFPIs.js.map +1 -0
  160. package/dist/status-DtK6OHtj.cjs +24 -0
  161. package/dist/status-DtK6OHtj.cjs.map +1 -0
  162. package/dist/telemetry/adapters.cjs +6 -0
  163. package/dist/telemetry/adapters.d.cts +3 -0
  164. package/dist/telemetry/adapters.d.ts +3 -0
  165. package/dist/telemetry/adapters.js +4 -0
  166. package/dist/telemetry/betterstack.cjs +74 -0
  167. package/dist/telemetry/betterstack.cjs.map +1 -0
  168. package/dist/telemetry/betterstack.d.cts +12 -0
  169. package/dist/telemetry/betterstack.d.ts +12 -0
  170. package/dist/telemetry/betterstack.js +71 -0
  171. package/dist/telemetry/betterstack.js.map +1 -0
  172. package/dist/telemetry/core.cjs +11 -0
  173. package/dist/telemetry/core.d.cts +4 -0
  174. package/dist/telemetry/core.d.ts +4 -0
  175. package/dist/telemetry/core.js +5 -0
  176. package/dist/telemetry/index.cjs +524 -0
  177. package/dist/telemetry/index.cjs.map +1 -0
  178. package/dist/telemetry/index.d.cts +68 -0
  179. package/dist/telemetry/index.d.ts +68 -0
  180. package/dist/telemetry/index.js +499 -0
  181. package/dist/telemetry/index.js.map +1 -0
  182. package/dist/telemetry/posthog.cjs +72 -0
  183. package/dist/telemetry/posthog.cjs.map +1 -0
  184. package/dist/telemetry/posthog.d.cts +10 -0
  185. package/dist/telemetry/posthog.d.ts +10 -0
  186. package/dist/telemetry/posthog.js +71 -0
  187. package/dist/telemetry/posthog.js.map +1 -0
  188. package/dist/telemetry/register.cjs +88 -0
  189. package/dist/telemetry/register.cjs.map +1 -0
  190. package/dist/telemetry/register.d.cts +14 -0
  191. package/dist/telemetry/register.d.ts +14 -0
  192. package/dist/telemetry/register.js +85 -0
  193. package/dist/telemetry/register.js.map +1 -0
  194. package/dist/telemetry/testing.cjs +54 -0
  195. package/dist/telemetry/testing.cjs.map +1 -0
  196. package/dist/telemetry/testing.d.cts +15 -0
  197. package/dist/telemetry/testing.d.ts +15 -0
  198. package/dist/telemetry/testing.js +52 -0
  199. package/dist/telemetry/testing.js.map +1 -0
  200. package/dist/telemetry.mock-BSsx7L6S.cjs +45 -0
  201. package/dist/telemetry.mock-BSsx7L6S.cjs.map +1 -0
  202. package/dist/telemetry.mock-BZRpy63c.js +40 -0
  203. package/dist/telemetry.mock-BZRpy63c.js.map +1 -0
  204. package/dist/telemetry.mock-C1wXuf-M.d.cts +4 -0
  205. package/dist/telemetry.mock-CdaxofJ7.d.ts +4 -0
  206. package/dist/ui/chart.cjs +6 -0
  207. package/dist/ui/chart.d.cts +34 -0
  208. package/dist/ui/chart.d.ts +34 -0
  209. package/dist/ui/chart.js +6 -0
  210. package/dist/ui/form.cjs +1 -0
  211. package/dist/ui/form.d.cts +23 -0
  212. package/dist/ui/form.d.ts +23 -0
  213. package/dist/ui/form.js +1 -0
  214. package/dist/ui/hooks.cjs +1 -0
  215. package/dist/ui/hooks.d.cts +66 -0
  216. package/dist/ui/hooks.d.ts +66 -0
  217. package/dist/ui/hooks.js +1 -0
  218. package/dist/ui/index.cjs +1 -0
  219. package/dist/ui/index.d.cts +3 -0
  220. package/dist/ui/index.d.ts +3 -0
  221. package/dist/ui/index.js +1 -0
  222. package/dist/ui/styles.css +2 -0
  223. package/dist/ui/utils.cjs +1 -0
  224. package/dist/ui/utils.d.cts +199 -0
  225. package/dist/ui/utils.d.ts +199 -0
  226. package/dist/ui/utils.js +1 -0
  227. package/dist/use-mobile-BbeIMRgE.cjs +1 -0
  228. package/dist/use-mobile-Cdd4Lp7p.js +1 -0
  229. package/dist/use-mobile-ecpyXWz3.d.cts +10 -0
  230. package/dist/use-mobile-ecpyXWz3.d.ts +10 -0
  231. package/dist/verifier-BIBtPCVi.cjs +119 -0
  232. package/dist/verifier-BIBtPCVi.cjs.map +1 -0
  233. package/dist/verifier-DNdy5Ynw.js +90 -0
  234. package/dist/verifier-DNdy5Ynw.js.map +1 -0
  235. package/dist/version-B0ADow60.js +1 -0
  236. package/dist/version-CMkha8JJ.cjs +1 -0
  237. package/package.json +539 -5
@@ -0,0 +1,759 @@
1
+ const require_rolldown_runtime = require("./rolldown-runtime-xuxB8TGW.cjs");
2
+ const require_dispatcher = require("./dispatcher-BsD7cO2w.cjs");
3
+ const require_sdk = require("./sdk-B2Lp3JCz.cjs");
4
+ const require_redaction = require("./redaction-uRIQbTwZ.cjs");
5
+ let pino = require("pino");
6
+ pino = require_rolldown_runtime.__toESM(pino, 1);
7
+ let node_async_hooks = require("node:async_hooks");
8
+ let _opentelemetry_api = require("@opentelemetry/api");
9
+ let _opentelemetry_api_logs = require("@opentelemetry/api-logs");
10
+
11
+ // src/modules/telemetry/shared/context/context.ts
12
+ const storage = new node_async_hooks.AsyncLocalStorage();
13
+ function baseContext() {
14
+ const span = _opentelemetry_api.trace.getActiveSpan()?.spanContext();
15
+ return {
16
+ service: require_sdk.readEnv("OTEL_SERVICE_NAME", "SERVICE_NAME") ?? "unknown-service",
17
+ product: require_sdk.readEnv("TELEMETRY_PRODUCT"),
18
+ environment: require_sdk.readEnv("NODE_ENV") ?? "development",
19
+ release: require_sdk.readEnv("OTEL_SERVICE_VERSION", "RELEASE", "RAILWAY_DEPLOYMENT_ID", "GIT_SHA"),
20
+ traceId: span?.traceId,
21
+ spanId: span?.spanId,
22
+ ...storage.getStore()
23
+ };
24
+ }
25
+ var TelemetryContext = class {
26
+ logger;
27
+ constructor(logger) {
28
+ this.logger = logger;
29
+ }
30
+ get() {
31
+ return baseContext();
32
+ }
33
+ assign(context) {
34
+ const current = storage.getStore();
35
+ if (current) Object.assign(current, context);
36
+ try {
37
+ this.logger?.assign({
38
+ actor_id: context.actorId,
39
+ organization_id: context.organizationId,
40
+ job_id: context.jobId,
41
+ correlation_id: context.correlationId
42
+ });
43
+ } catch {}
44
+ }
45
+ identify(actorId) {
46
+ this.assign({ actorId });
47
+ }
48
+ organization(organizationId) {
49
+ this.assign({ organizationId });
50
+ }
51
+ run(context, fn) {
52
+ return storage.run({
53
+ ...storage.getStore(),
54
+ ...context
55
+ }, fn);
56
+ }
57
+ };
58
+
59
+ // src/modules/telemetry/shared/logging/otel.ts
60
+ const otelLogger = _opentelemetry_api_logs.logs.getLogger("@rockdev/telemetry", void 0, { includeTraceContext: true });
61
+ function severity(level) {
62
+ if (level >= 60) return {
63
+ text: "fatal",
64
+ number: _opentelemetry_api_logs.SeverityNumber.FATAL
65
+ };
66
+ if (level >= 50) return {
67
+ text: "error",
68
+ number: _opentelemetry_api_logs.SeverityNumber.ERROR
69
+ };
70
+ if (level >= 40) return {
71
+ text: "warn",
72
+ number: _opentelemetry_api_logs.SeverityNumber.WARN
73
+ };
74
+ if (level >= 30) return {
75
+ text: "info",
76
+ number: _opentelemetry_api_logs.SeverityNumber.INFO
77
+ };
78
+ if (level >= 20) return {
79
+ text: "debug",
80
+ number: _opentelemetry_api_logs.SeverityNumber.DEBUG
81
+ };
82
+ return {
83
+ text: "trace",
84
+ number: _opentelemetry_api_logs.SeverityNumber.TRACE
85
+ };
86
+ }
87
+ function toAnyValue(value) {
88
+ if (value instanceof Error) {
89
+ const safeError = require_redaction.sanitizeError(value);
90
+ return toAnyValue({
91
+ name: safeError.name,
92
+ message: safeError.message,
93
+ ...safeError.stack ? { stack: safeError.stack } : {}
94
+ });
95
+ }
96
+ if (typeof value === "string") return require_redaction.sanitizeText(value);
97
+ if (Array.isArray(value)) return value.map(toAnyValue);
98
+ if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, require_redaction.isSensitiveKey(key) ? "[REDACTED]" : toAnyValue(child)]));
99
+ if (typeof value === "number" || typeof value === "boolean" || value === null || value === void 0) return value;
100
+ return String(value);
101
+ }
102
+ function toLogRecord(args, level) {
103
+ const [first, second, ...rest] = args;
104
+ const body = {};
105
+ if (first && typeof first === "object" && !Array.isArray(first)) {
106
+ const safe = toAnyValue(first);
107
+ if (safe && typeof safe === "object" && !Array.isArray(safe)) Object.assign(body, safe);
108
+ if (second !== void 0 && typeof second !== "string") body.arguments = toAnyValue(second);
109
+ } else if (first !== void 0) body.message = typeof first === "string" ? require_redaction.sanitizeText(first) : toAnyValue(first);
110
+ if (typeof second === "string") body.message = require_redaction.sanitizeText(second);
111
+ if (rest.length > 0) body.arguments = toAnyValue(rest);
112
+ const currentSeverity = severity(level);
113
+ return {
114
+ body,
115
+ severityNumber: currentSeverity.number,
116
+ severityText: currentSeverity.text,
117
+ ...typeof body.event === "string" ? { eventName: body.event } : {}
118
+ };
119
+ }
120
+ function emitPinoLog(args, level) {
121
+ if (process.env.TELEMETRY_ENABLED === "false" || process.env.TELEMETRY_LOGS_ENABLED === "false") return;
122
+ try {
123
+ otelLogger.emit(toLogRecord(args, level));
124
+ } catch {}
125
+ }
126
+ function createTelemetryPinoHooks() {
127
+ return { logMethod(args, method, level) {
128
+ emitPinoLog(args, level);
129
+ method.apply(this, args);
130
+ } };
131
+ }
132
+
133
+ // src/modules/telemetry/shared/state/operational.ts
134
+ var TelemetryOperationalState = class {
135
+ signals = new Map([
136
+ "errors",
137
+ "events",
138
+ "logs",
139
+ "metrics",
140
+ "tracing"
141
+ ].map((signal) => [signal, {
142
+ failed: false,
143
+ failureCount: 0
144
+ }]));
145
+ recordFailure(signal) {
146
+ const current = this.signals.get(signal);
147
+ if (!current) return;
148
+ current.failed = true;
149
+ current.failureCount += 1;
150
+ current.lastFailureAt = (/* @__PURE__ */ new Date()).toISOString();
151
+ }
152
+ status(signal) {
153
+ return { ...this.signals.get(signal) ?? {
154
+ failed: false,
155
+ failureCount: 0
156
+ } };
157
+ }
158
+ };
159
+
160
+ // src/modules/telemetry/types/telemetry.ts
161
+ var Telemetry = class {};
162
+
163
+ // src/modules/telemetry/core/checked-telemetry.ts
164
+ var CheckedTelemetry = class extends Telemetry {
165
+ target;
166
+ adapters;
167
+ options;
168
+ constructor(target, adapters, options = {}) {
169
+ super();
170
+ this.target = target;
171
+ this.adapters = adapters;
172
+ this.options = options;
173
+ }
174
+ debug(event, attributes) {
175
+ this.require("logs", "telemetry.debug()");
176
+ this.target.debug(event, attributes);
177
+ }
178
+ info(event, attributes) {
179
+ this.require("logs", "telemetry.info()");
180
+ this.target.info(event, attributes);
181
+ }
182
+ warn(event, attributes) {
183
+ this.require("logs", "telemetry.warn()");
184
+ this.target.warn(event, attributes);
185
+ }
186
+ error(event, error, attributes) {
187
+ this.require("logs", "telemetry.error()");
188
+ this.target.error(event, error, attributes);
189
+ }
190
+ event(event, attributes) {
191
+ this.require("events", "telemetry.event()");
192
+ this.target.event(event, attributes);
193
+ }
194
+ captureException(error, attributes, options) {
195
+ this.require("errors", "telemetry.captureException()");
196
+ this.target.captureException(error, attributes, options);
197
+ }
198
+ async span(name, fn, attributes) {
199
+ this.require("tracing", "telemetry.span()");
200
+ return this.target.span(name, fn, attributes);
201
+ }
202
+ increment(name, value, attributes) {
203
+ this.require("metrics", "telemetry.increment()");
204
+ this.target.increment(name, value, attributes);
205
+ }
206
+ histogram(name, value, attributes) {
207
+ this.require("metrics", "telemetry.histogram()");
208
+ this.target.histogram(name, value, attributes);
209
+ }
210
+ async trackDependency(options, fn) {
211
+ this.requireDependency("telemetry.trackDependency()");
212
+ return this.target.trackDependency(options, fn);
213
+ }
214
+ runJob(options, fn) {
215
+ try {
216
+ this.requireDependency("telemetry.runJob()");
217
+ } catch (error) {
218
+ return Promise.reject(error);
219
+ }
220
+ return this.target.runJob(options, fn);
221
+ }
222
+ async fetch(input, init, options) {
223
+ this.requireDependency("telemetry.fetch()");
224
+ return this.target.fetch(input, init, options);
225
+ }
226
+ traceparent() {
227
+ return this.target.traceparent();
228
+ }
229
+ getContext() {
230
+ return this.target.getContext();
231
+ }
232
+ shutdown() {
233
+ return this.target.shutdown();
234
+ }
235
+ disabled(capability) {
236
+ if (process.env.TELEMETRY_ENABLED === "false") return true;
237
+ if (capability === "metrics") return process.env.TELEMETRY_METRICS_ENABLED === "false";
238
+ if (capability === "tracing") return this.options.tracing === false || process.env.TELEMETRY_TRACING_ENABLED === "false";
239
+ if (capability === "errors") return this.options.errors === false;
240
+ return false;
241
+ }
242
+ require(capability, operation) {
243
+ if (this.disabled(capability)) return;
244
+ this.adapters.assertSupports(capability, operation);
245
+ }
246
+ requireDependency(operation) {
247
+ this.require("tracing", operation);
248
+ this.require("metrics", operation);
249
+ this.require("errors", operation);
250
+ }
251
+ };
252
+
253
+ // src/modules/telemetry/shared/context/adapter.ts
254
+ function adapterContext(context) {
255
+ return require_redaction.sanitizeAttributes({ ...context });
256
+ }
257
+
258
+ // src/modules/telemetry/shared/utils/case.ts
259
+ function snakeCase(value) {
260
+ return value.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[.-]/g, "_").toLowerCase();
261
+ }
262
+
263
+ // src/modules/telemetry/shared/logging/attributes.ts
264
+ function logAttributes(context, attributes) {
265
+ const record = {};
266
+ for (const [key, value] of Object.entries({
267
+ requestId: context.requestId,
268
+ traceId: context.traceId,
269
+ spanId: context.spanId,
270
+ service: context.service,
271
+ product: context.product,
272
+ environment: context.environment,
273
+ release: context.release,
274
+ actorId: context.actorId,
275
+ organizationId: context.organizationId,
276
+ jobId: context.jobId,
277
+ correlationId: context.correlationId,
278
+ ...attributes
279
+ })) if (value !== void 0) record[snakeCase(key)] = value;
280
+ return require_redaction.sanitizeAttributes(record);
281
+ }
282
+
283
+ // src/modules/telemetry/shared/metrics/instruments.ts
284
+ const meter = _opentelemetry_api.metrics.getMeter("@rockdev/telemetry");
285
+ const counters = /* @__PURE__ */ new Map();
286
+ const histograms = /* @__PURE__ */ new Map();
287
+
288
+ // src/modules/telemetry/shared/metrics/metrics.ts
289
+ const ALLOWED_METRIC_ATTRIBUTES = /* @__PURE__ */ new Set([
290
+ "service",
291
+ "route",
292
+ "method",
293
+ "status",
294
+ "statusCode",
295
+ "statusClass",
296
+ "result",
297
+ "dependency",
298
+ "operation",
299
+ "queue",
300
+ "job",
301
+ "product",
302
+ "channel",
303
+ "provider",
304
+ "priority",
305
+ "reason"
306
+ ]);
307
+ function validValue(key, value) {
308
+ if (typeof value !== "string" || value.length === 0 || value.length > 100) return false;
309
+ if (require_redaction.containsSensitiveText(value) || require_redaction.isLikelyIdentifier(value)) return false;
310
+ if (key === "route") return (value === "unmatched" || value.startsWith("/")) && !value.includes("?") && !value.includes("://") && !value.split("/").some((segment) => /^\d+$/.test(segment));
311
+ if (key === "method") return /^[A-Z]+$/.test(value);
312
+ if (key === "statusCode") return /^[1-5]\d\d$/.test(value);
313
+ if (key === "statusClass") return /^[1-5]xx$/.test(value);
314
+ if (key === "result") return value === "success" || value === "error";
315
+ return true;
316
+ }
317
+ function sanitizeMetricAttributes(attributes) {
318
+ if (!attributes) return {
319
+ attributes: void 0,
320
+ rejectedKeys: []
321
+ };
322
+ const valid = {};
323
+ const rejectedKeys = [];
324
+ for (const [rawKey, value] of Object.entries(attributes)) {
325
+ const key = rawKey;
326
+ if (!ALLOWED_METRIC_ATTRIBUTES.has(key) || require_redaction.isSensitiveKey(rawKey) || !validValue(key, value)) {
327
+ rejectedKeys.push(rawKey);
328
+ continue;
329
+ }
330
+ valid[key] = value;
331
+ }
332
+ return {
333
+ attributes: valid,
334
+ rejectedKeys
335
+ };
336
+ }
337
+
338
+ // src/modules/telemetry/core/telemetry.service.ts
339
+ var TelemetryService = class extends Telemetry {
340
+ logger;
341
+ context;
342
+ operationalState;
343
+ options;
344
+ adapters;
345
+ constructor(logger, context, operationalState, options = {}, adapters) {
346
+ super();
347
+ this.logger = logger;
348
+ this.context = context;
349
+ this.operationalState = operationalState;
350
+ this.options = options;
351
+ this.adapters = adapters;
352
+ }
353
+ debug(event, attributes) {
354
+ this.write("debug", event, attributes);
355
+ }
356
+ info(event, attributes) {
357
+ this.write("info", event, attributes);
358
+ }
359
+ warn(event, attributes) {
360
+ this.write("warn", event, attributes);
361
+ }
362
+ error(event, error, attributes) {
363
+ this.writeError(event, error, attributes);
364
+ }
365
+ event(event, attributes) {
366
+ try {
367
+ const context = this.getContext();
368
+ const safeAttributes = logAttributes(context, attributes);
369
+ this.logger.info({
370
+ event,
371
+ event_kind: "product",
372
+ ...safeAttributes
373
+ });
374
+ this.adapters?.captureEvent?.({
375
+ event,
376
+ attributes: safeAttributes,
377
+ context: adapterContext(context)
378
+ });
379
+ } catch {
380
+ this.operationalState.recordFailure("events");
381
+ }
382
+ }
383
+ captureException(error, attributes, options) {
384
+ this.error("exception.captured", error, attributes);
385
+ if (this.options.errors === false) return;
386
+ const reportError = require_redaction.sanitizeError(error, process.env.TELEMETRY_ERROR_STACK_ENABLED !== "false");
387
+ const reportContext = {
388
+ request: require_redaction.sanitizeAttributes({ ...this.getContext() }),
389
+ attributes: require_redaction.sanitizeAttributes(attributes)
390
+ };
391
+ this.adapters?.captureException?.({
392
+ error: reportError,
393
+ context: reportContext,
394
+ ...options?.fingerprint ? { fingerprint: options.fingerprint } : {}
395
+ });
396
+ }
397
+ async span(name, fn, attributes = {}) {
398
+ if (this.options.tracing === false || process.env.TELEMETRY_TRACING_ENABLED === "false") return fn({
399
+ setAttributes() {},
400
+ addEvent() {}
401
+ });
402
+ try {
403
+ return _opentelemetry_api.trace.getTracer(this.getContext().service).startActiveSpan(name, { attributes: require_redaction.sanitizeAttributes(attributes) }, async (span) => {
404
+ const startedAt = performance.now();
405
+ const events = [];
406
+ let spanError;
407
+ let spanAttributes = require_redaction.sanitizeAttributes(attributes);
408
+ const facade = {
409
+ setAttributes: (values) => {
410
+ const safe = require_redaction.sanitizeAttributes(values);
411
+ spanAttributes = {
412
+ ...spanAttributes,
413
+ ...safe
414
+ };
415
+ span.setAttributes(safe);
416
+ },
417
+ addEvent: (event, values) => {
418
+ const safe = require_redaction.sanitizeAttributes(values);
419
+ events.push({
420
+ name: event,
421
+ attributes: safe
422
+ });
423
+ span.addEvent(event, safe);
424
+ }
425
+ };
426
+ try {
427
+ return await fn(facade);
428
+ } catch (error) {
429
+ spanError = require_redaction.sanitizeError(error);
430
+ try {
431
+ span.recordException(require_redaction.sanitizeError(error));
432
+ span.setStatus({ code: _opentelemetry_api.SpanStatusCode.ERROR });
433
+ } catch {
434
+ this.operationalState.recordFailure("tracing");
435
+ }
436
+ throw error;
437
+ } finally {
438
+ this.adapters?.captureSpan?.({
439
+ name,
440
+ durationMs: performance.now() - startedAt,
441
+ attributes: spanAttributes,
442
+ events,
443
+ context: adapterContext(this.getContext()),
444
+ ...spanError ? { error: spanError } : {}
445
+ });
446
+ try {
447
+ span.end();
448
+ } catch {
449
+ this.operationalState.recordFailure("tracing");
450
+ }
451
+ }
452
+ });
453
+ } catch {
454
+ this.operationalState.recordFailure("tracing");
455
+ return fn({
456
+ setAttributes() {},
457
+ addEvent() {}
458
+ });
459
+ }
460
+ }
461
+ increment(name, value = 1, attributes) {
462
+ if (process.env.TELEMETRY_METRICS_ENABLED === "false") return;
463
+ const sanitized = sanitizeMetricAttributes(attributes);
464
+ this.warnRejectedMetricAttributes(name, sanitized.rejectedKeys);
465
+ try {
466
+ const instrument = counters.get(name) ?? meter.createCounter(name);
467
+ counters.set(name, instrument);
468
+ instrument.add(value, sanitized.attributes);
469
+ this.adapters?.captureMetric?.({
470
+ type: "counter",
471
+ name,
472
+ value,
473
+ attributes: sanitized.attributes ?? {},
474
+ context: adapterContext(this.getContext())
475
+ });
476
+ } catch {
477
+ this.operationalState.recordFailure("metrics");
478
+ }
479
+ }
480
+ histogram(name, value, attributes) {
481
+ if (process.env.TELEMETRY_METRICS_ENABLED === "false") return;
482
+ const sanitized = sanitizeMetricAttributes(attributes);
483
+ this.warnRejectedMetricAttributes(name, sanitized.rejectedKeys);
484
+ try {
485
+ const instrument = histograms.get(name) ?? meter.createHistogram(name, { unit: "ms" });
486
+ histograms.set(name, instrument);
487
+ instrument.record(value, sanitized.attributes);
488
+ this.adapters?.captureMetric?.({
489
+ type: "histogram",
490
+ name,
491
+ value,
492
+ attributes: sanitized.attributes ?? {},
493
+ context: adapterContext(this.getContext())
494
+ });
495
+ } catch {
496
+ this.operationalState.recordFailure("metrics");
497
+ }
498
+ }
499
+ async trackDependency(options, fn) {
500
+ const startedAt = performance.now();
501
+ try {
502
+ const result = await this.span(`dependency.${options.name}.${options.operation}`, async () => fn(), {
503
+ "dependency.name": options.name,
504
+ "operation.name": options.operation
505
+ });
506
+ this.increment("rock_dependency_requests_total", 1, {
507
+ dependency: options.name,
508
+ operation: options.operation,
509
+ result: "success"
510
+ });
511
+ return result;
512
+ } catch (error) {
513
+ this.increment("rock_dependency_requests_total", 1, {
514
+ dependency: options.name,
515
+ operation: options.operation,
516
+ result: "error"
517
+ });
518
+ this.captureException(error, {
519
+ dependency: options.name,
520
+ operation: options.operation
521
+ });
522
+ throw error;
523
+ } finally {
524
+ this.histogram("rock_dependency_request_duration_ms", performance.now() - startedAt, {
525
+ dependency: options.name,
526
+ operation: options.operation
527
+ });
528
+ }
529
+ }
530
+ runJob(options, fn) {
531
+ const run = () => this.context.run({
532
+ ...options.jobId ? { jobId: options.jobId } : {},
533
+ ...options.correlationId ? { correlationId: options.correlationId } : {}
534
+ }, () => this.trackDependency({
535
+ name: `queue.${options.queue}`,
536
+ operation: options.job
537
+ }, fn));
538
+ if (!options.traceparent) return run();
539
+ const parent = _opentelemetry_api.propagation.extract(_opentelemetry_api.context.active(), { traceparent: options.traceparent });
540
+ return _opentelemetry_api.context.with(parent, run);
541
+ }
542
+ async fetch(input, init, options) {
543
+ const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
544
+ let host = "unknown";
545
+ let path = url;
546
+ try {
547
+ const parsed = new URL(url);
548
+ host = parsed.host;
549
+ path = parsed.pathname;
550
+ } catch {}
551
+ const method = (init?.method ?? (input instanceof Request ? input.method : void 0) ?? "GET").toUpperCase();
552
+ const dependency = options?.dependency ?? host;
553
+ const operation = options?.operation ?? `${method} ${path}`;
554
+ const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : {}));
555
+ _opentelemetry_api.propagation.inject(_opentelemetry_api.context.active(), headers, { set: (carrier, key, value) => carrier.set(key, String(value)) });
556
+ return this.trackDependency({
557
+ name: dependency,
558
+ operation
559
+ }, () => this.span(`http.client.${dependency}`, async (span) => {
560
+ const response = await fetch(input, {
561
+ ...init,
562
+ headers
563
+ });
564
+ span.setAttributes({ "http.response.status_code": response.status });
565
+ return response;
566
+ }, {
567
+ "http.request.method": method,
568
+ "server.address": host,
569
+ "url.path": path,
570
+ ...options?.attributes
571
+ }));
572
+ }
573
+ traceparent() {
574
+ const carrier = {};
575
+ try {
576
+ _opentelemetry_api.propagation.inject(_opentelemetry_api.context.active(), carrier);
577
+ } catch {
578
+ this.operationalState.recordFailure("tracing");
579
+ return;
580
+ }
581
+ return carrier.traceparent;
582
+ }
583
+ getContext() {
584
+ return this.context.get();
585
+ }
586
+ async shutdown() {
587
+ await Promise.allSettled([this.adapters?.shutdown() ?? Promise.resolve(), require_sdk.shutdownTelemetry().catch(() => {
588
+ this.operationalState.recordFailure("logs");
589
+ this.operationalState.recordFailure("metrics");
590
+ this.operationalState.recordFailure("tracing");
591
+ })]);
592
+ }
593
+ write(level, event, attributes) {
594
+ try {
595
+ const context = this.getContext();
596
+ const safeAttributes = logAttributes(context, attributes);
597
+ this.logger[level]({
598
+ event,
599
+ ...safeAttributes
600
+ });
601
+ this.adapters?.captureLog?.({
602
+ level,
603
+ event,
604
+ attributes: safeAttributes,
605
+ context: adapterContext(context)
606
+ });
607
+ } catch {
608
+ this.operationalState.recordFailure("logs");
609
+ }
610
+ }
611
+ writeError(event, error, attributes) {
612
+ try {
613
+ const context = this.getContext();
614
+ const safeAttributes = logAttributes(context, attributes);
615
+ this.logger.error({
616
+ event,
617
+ err: require_redaction.sanitizeError(error),
618
+ ...safeAttributes
619
+ });
620
+ this.adapters?.captureLog?.({
621
+ level: "error",
622
+ event,
623
+ attributes: safeAttributes,
624
+ context: adapterContext(context)
625
+ });
626
+ } catch {
627
+ this.operationalState.recordFailure("logs");
628
+ }
629
+ }
630
+ warnRejectedMetricAttributes(metricName, rejectedKeys) {
631
+ if (rejectedKeys.length === 0) return;
632
+ this.write("warn", "telemetry.metric_attributes_rejected", {
633
+ metricName,
634
+ rejectedAttributeKeys: rejectedKeys
635
+ });
636
+ }
637
+ };
638
+
639
+ // src/modules/telemetry/core/create-telemetry.ts
640
+ function createTelemetry(options = {}) {
641
+ const context = new TelemetryContext();
642
+ const operationalState = new TelemetryOperationalState();
643
+ const logger = (0, pino.default)({
644
+ hooks: createTelemetryPinoHooks(),
645
+ level: process.env.LOG_LEVEL ?? "info",
646
+ redact: {
647
+ paths: require_redaction.DEFAULT_REDACT_PATHS,
648
+ censor: "[REDACTED]"
649
+ }
650
+ });
651
+ const adapters = new require_dispatcher.TelemetryAdapterDispatcher(options.adapters ?? [], operationalState);
652
+ return new CheckedTelemetry(new TelemetryService(logger, context, operationalState, options, adapters), adapters, options);
653
+ }
654
+
655
+ // src/modules/telemetry/shared/tracing/span.ts
656
+ function recordError(span, error) {
657
+ try {
658
+ span.recordException(require_redaction.sanitizeError(error));
659
+ span.setStatus({ code: _opentelemetry_api.SpanStatusCode.ERROR });
660
+ } catch {}
661
+ }
662
+ function endSpan(span) {
663
+ try {
664
+ span.end();
665
+ } catch {}
666
+ }
667
+
668
+ // src/modules/telemetry/shared/utils/promise.ts
669
+ function isPromiseLike(value) {
670
+ return typeof value === "object" && value !== null && typeof value.then === "function";
671
+ }
672
+
673
+ // src/modules/telemetry/core/trace.decorator.ts
674
+ function Trace(name, attributes = {}) {
675
+ return (_target, _propertyKey, descriptor) => {
676
+ const typedDescriptor = descriptor;
677
+ const original = typedDescriptor.value;
678
+ if (!original) return;
679
+ typedDescriptor.value = function traced(...args) {
680
+ const invoke = () => original.apply(this, args);
681
+ if (process.env.TELEMETRY_TRACING_ENABLED === "false") return invoke();
682
+ try {
683
+ return _opentelemetry_api.trace.getTracer(require_sdk.readEnv("OTEL_SERVICE_NAME") ?? "unknown-service").startActiveSpan(name, { attributes: require_redaction.sanitizeAttributes(attributes) }, (span) => {
684
+ try {
685
+ const result = invoke();
686
+ if (!isPromiseLike(result)) {
687
+ endSpan(span);
688
+ return result;
689
+ }
690
+ return result.then((value) => {
691
+ endSpan(span);
692
+ return value;
693
+ }, (error) => {
694
+ recordError(span, error);
695
+ endSpan(span);
696
+ throw error;
697
+ });
698
+ } catch (error) {
699
+ recordError(span, error);
700
+ endSpan(span);
701
+ throw error;
702
+ }
703
+ });
704
+ } catch {
705
+ return invoke();
706
+ }
707
+ };
708
+ };
709
+ }
710
+
711
+ Object.defineProperty(exports, "CheckedTelemetry", {
712
+ enumerable: true,
713
+ get: function () {
714
+ return CheckedTelemetry;
715
+ }
716
+ });
717
+ Object.defineProperty(exports, "Telemetry", {
718
+ enumerable: true,
719
+ get: function () {
720
+ return Telemetry;
721
+ }
722
+ });
723
+ Object.defineProperty(exports, "TelemetryContext", {
724
+ enumerable: true,
725
+ get: function () {
726
+ return TelemetryContext;
727
+ }
728
+ });
729
+ Object.defineProperty(exports, "TelemetryOperationalState", {
730
+ enumerable: true,
731
+ get: function () {
732
+ return TelemetryOperationalState;
733
+ }
734
+ });
735
+ Object.defineProperty(exports, "TelemetryService", {
736
+ enumerable: true,
737
+ get: function () {
738
+ return TelemetryService;
739
+ }
740
+ });
741
+ Object.defineProperty(exports, "Trace", {
742
+ enumerable: true,
743
+ get: function () {
744
+ return Trace;
745
+ }
746
+ });
747
+ Object.defineProperty(exports, "createTelemetry", {
748
+ enumerable: true,
749
+ get: function () {
750
+ return createTelemetry;
751
+ }
752
+ });
753
+ Object.defineProperty(exports, "createTelemetryPinoHooks", {
754
+ enumerable: true,
755
+ get: function () {
756
+ return createTelemetryPinoHooks;
757
+ }
758
+ });
759
+ //# sourceMappingURL=core-BidJDmSN.cjs.map