iii-sdk 0.8.3 → 0.10.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 (50) hide show
  1. package/README.md +15 -11
  2. package/dist/index.cjs +278 -142
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +177 -3
  5. package/dist/index.d.cts.map +1 -1
  6. package/dist/index.d.mts +177 -3
  7. package/dist/index.d.mts.map +1 -1
  8. package/dist/index.mjs +259 -125
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/state.cjs +7 -5
  11. package/dist/state.cjs.map +1 -1
  12. package/dist/state.d.cts +38 -13
  13. package/dist/state.d.cts.map +1 -1
  14. package/dist/state.d.mts +38 -13
  15. package/dist/state.d.mts.map +1 -1
  16. package/dist/state.mjs +6 -5
  17. package/dist/state.mjs.map +1 -1
  18. package/dist/stream-C1zUjhzk.d.mts +145 -0
  19. package/dist/stream-C1zUjhzk.d.mts.map +1 -0
  20. package/dist/stream-lxenNA3s.d.cts +145 -0
  21. package/dist/stream-lxenNA3s.d.cts.map +1 -0
  22. package/dist/stream.d.cts +1 -1
  23. package/dist/stream.d.mts +1 -1
  24. package/dist/telemetry.cjs +6 -5
  25. package/dist/telemetry.d.cts +10 -11
  26. package/dist/telemetry.d.cts.map +1 -1
  27. package/dist/telemetry.d.mts +10 -11
  28. package/dist/telemetry.d.mts.map +1 -1
  29. package/dist/telemetry.mjs +1 -1
  30. package/dist/utils-BvWlFlLq.d.cts +839 -0
  31. package/dist/utils-BvWlFlLq.d.cts.map +1 -0
  32. package/dist/{utils-BJTjoUdq.cjs → utils-C6yTT4Js.cjs} +311 -282
  33. package/dist/utils-C6yTT4Js.cjs.map +1 -0
  34. package/dist/utils-_zSeatp1.d.mts +839 -0
  35. package/dist/utils-_zSeatp1.d.mts.map +1 -0
  36. package/dist/{utils-coGqiBHT.mjs → utils-xBUm8n1P.mjs} +246 -217
  37. package/dist/utils-xBUm8n1P.mjs.map +1 -0
  38. package/package.json +5 -3
  39. package/typedoc.json +8 -0
  40. package/vitest.config.ts +4 -4
  41. package/dist/stream-BEp3rjfm.d.cts +0 -97
  42. package/dist/stream-BEp3rjfm.d.cts.map +0 -1
  43. package/dist/stream-Bzpo5JNV.d.mts +0 -97
  44. package/dist/stream-Bzpo5JNV.d.mts.map +0 -1
  45. package/dist/utils-BJTjoUdq.cjs.map +0 -1
  46. package/dist/utils-BaGgUfjl.d.cts +0 -524
  47. package/dist/utils-BaGgUfjl.d.cts.map +0 -1
  48. package/dist/utils-CMrMD5Ij.d.mts +0 -524
  49. package/dist/utils-CMrMD5Ij.d.mts.map +0 -1
  50. package/dist/utils-coGqiBHT.mjs.map +0 -1
package/dist/index.d.mts CHANGED
@@ -1,7 +1,129 @@
1
- import { S as StreamChannelRef, _ as ChannelReader, a as registerWorker, b as HttpAuthConfig, c as Channel, d as HttpResponse, f as ISdk, i as InitOptions, o as ApiRequest, s as ApiResponse, t as http, u as HttpRequest, v as ChannelWriter, x as HttpInvocationConfig } from "./utils-CMrMD5Ij.mjs";
1
+ import { $ as ChannelWriter, Q as ChannelReader, U as OtelConfig, X as IIIReconnectionConfig, _ as RemoteFunctionHandler, a as Channel, b as TriggerHandler, c as HttpRequest, ct as RegisterTriggerTypeMessage, d as InternalHttpRequest, dt as TriggerInfo, et as EnqueueResult, ft as TriggerRequest, g as RegisterTriggerTypeInput, h as RegisterTriggerInput, i as ApiResponse, it as MessageType, l as HttpResponse, lt as StreamChannelRef, m as RegisterServiceInput, nt as HttpAuthConfig, o as FunctionRef, ot as RegisterFunctionMessage, p as RegisterFunctionInput, r as ApiRequest, rt as HttpInvocationConfig, st as RegisterTriggerMessage, t as http, u as ISdk, ut as TriggerAction$1, v as Trigger, y as TriggerConfig } from "./utils-_zSeatp1.mjs";
2
2
 
3
+ //#region src/iii.d.ts
4
+ /** @internal */
5
+ type TelemetryOptions = {
6
+ language?: string;
7
+ project_name?: string;
8
+ framework?: string;
9
+ amplitude_api_key?: string;
10
+ };
11
+ /**
12
+ * Configuration options passed to {@link registerWorker}.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const iii = registerWorker('ws://localhost:49134', {
17
+ * workerName: 'my-worker',
18
+ * invocationTimeoutMs: 10000,
19
+ * reconnectionConfig: { maxRetries: 5 },
20
+ * })
21
+ * ```
22
+ */
23
+ type InitOptions = {
24
+ /** Display name for this worker. Defaults to `hostname:pid`. */workerName?: string; /** Enable worker metrics via OpenTelemetry. Defaults to `true`. */
25
+ enableMetricsReporting?: boolean; /** Default timeout for `trigger()` in milliseconds. Defaults to `30000`. */
26
+ invocationTimeoutMs?: number;
27
+ /**
28
+ * WebSocket reconnection behavior.
29
+ *
30
+ * @see {@link IIIReconnectionConfig} for available fields and defaults.
31
+ */
32
+ reconnectionConfig?: Partial<IIIReconnectionConfig>;
33
+ /**
34
+ * OpenTelemetry configuration. OTel is initialized automatically by default.
35
+ * Set `{ enabled: false }` or env `OTEL_ENABLED=false/0/no/off` to disable.
36
+ * The `engineWsUrl` is set automatically from the III address.
37
+ */
38
+ otel?: Omit<OtelConfig, 'engineWsUrl'>; /** @internal */
39
+ telemetry?: TelemetryOptions;
40
+ };
41
+ /**
42
+ * Factory object that constructs routing actions for {@link ISdk.trigger}.
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * import { TriggerAction } from 'iii-sdk'
47
+ *
48
+ * // Enqueue to a named queue
49
+ * iii.trigger({
50
+ * function_id: 'process',
51
+ * payload: { data: 'hello' },
52
+ * action: TriggerAction.Enqueue({ queue: 'jobs' }),
53
+ * })
54
+ *
55
+ * // Fire-and-forget
56
+ * iii.trigger({
57
+ * function_id: 'notify',
58
+ * payload: {},
59
+ * action: TriggerAction.Void(),
60
+ * })
61
+ * ```
62
+ */
63
+ declare const TriggerAction: {
64
+ /**
65
+ * Routes the invocation through a named queue. The engine enqueues the job,
66
+ * acknowledges the caller with `{ messageReceiptId }`, and processes it
67
+ * asynchronously.
68
+ *
69
+ * @param opts - Queue routing options.
70
+ * @param opts.queue - Name of the target queue.
71
+ */
72
+ readonly Enqueue: (opts: {
73
+ queue: string;
74
+ }) => TriggerAction$1;
75
+ /**
76
+ * Fire-and-forget routing. The engine forwards the invocation without
77
+ * waiting for a response or queuing the job.
78
+ */
79
+ readonly Void: () => TriggerAction$1;
80
+ };
81
+ /**
82
+ * Creates and returns a connected SDK instance. The WebSocket connection is
83
+ * established automatically -- there is no separate `connect()` call.
84
+ *
85
+ * @param address - WebSocket URL of the III engine (e.g. `ws://localhost:49134`).
86
+ * @param options - Optional {@link InitOptions} for worker name, timeouts, reconnection, and OTel.
87
+ * @returns A connected {@link ISdk} instance.
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * import { registerWorker } from 'iii-sdk'
92
+ *
93
+ * const iii = registerWorker(process.env.III_URL ?? 'ws://localhost:49134', {
94
+ * workerName: 'my-worker',
95
+ * })
96
+ * ```
97
+ */
98
+ declare const registerWorker: (address: string, options?: InitOptions) => ISdk;
99
+ //#endregion
3
100
  //#region src/logger.d.ts
4
-
101
+ /**
102
+ * Structured logger that emits logs as OpenTelemetry LogRecords.
103
+ *
104
+ * Every log call automatically captures the active trace and span context,
105
+ * correlating your logs with distributed traces without any manual wiring.
106
+ * When OTel is not initialized, Logger gracefully falls back to `console.*`.
107
+ *
108
+ * Pass structured data as the second argument to any log method. Using an
109
+ * object of key-value pairs (instead of string interpolation) lets you
110
+ * filter, aggregate, and build dashboards in your observability backend.
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * import { Logger } from 'iii-sdk'
115
+ *
116
+ * const logger = new Logger()
117
+ *
118
+ * // Basic logging — trace context is injected automatically
119
+ * logger.info('Worker connected')
120
+ *
121
+ * // Structured context for dashboards and alerting
122
+ * logger.info('Order processed', { orderId: 'ord_123', amount: 49.99, currency: 'USD' })
123
+ * logger.warn('Retry attempt', { attempt: 3, maxRetries: 5, endpoint: '/api/charge' })
124
+ * logger.error('Payment failed', { orderId: 'ord_123', gateway: 'stripe', errorCode: 'card_declined' })
125
+ * ```
126
+ */
5
127
  declare class Logger {
6
128
  private readonly traceId?;
7
129
  private readonly serviceName?;
@@ -10,11 +132,63 @@ declare class Logger {
10
132
  private get otelLogger();
11
133
  constructor(traceId?: string | undefined, serviceName?: string | undefined, spanId?: string | undefined);
12
134
  private emit;
135
+ /**
136
+ * Log an info-level message.
137
+ *
138
+ * @param message - Human-readable log message.
139
+ * @param data - Structured context attached as OTel log attributes.
140
+ * Use key-value objects to enable filtering and aggregation in your
141
+ * observability backend (e.g. Grafana, Datadog, New Relic).
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * logger.info('Order processed', { orderId: 'ord_123', status: 'completed' })
146
+ * ```
147
+ */
13
148
  info(message: string, data?: unknown): void;
149
+ /**
150
+ * Log a warning-level message.
151
+ *
152
+ * @param message - Human-readable log message.
153
+ * @param data - Structured context attached as OTel log attributes.
154
+ * Use key-value objects to enable filtering and aggregation in your
155
+ * observability backend (e.g. Grafana, Datadog, New Relic).
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * logger.warn('Retry attempt', { attempt: 3, maxRetries: 5, endpoint: '/api/charge' })
160
+ * ```
161
+ */
14
162
  warn(message: string, data?: unknown): void;
163
+ /**
164
+ * Log an error-level message.
165
+ *
166
+ * @param message - Human-readable log message.
167
+ * @param data - Structured context attached as OTel log attributes.
168
+ * Use key-value objects to enable filtering and aggregation in your
169
+ * observability backend (e.g. Grafana, Datadog, New Relic).
170
+ *
171
+ * @example
172
+ * ```typescript
173
+ * logger.error('Payment failed', { orderId: 'ord_123', gateway: 'stripe', errorCode: 'card_declined' })
174
+ * ```
175
+ */
15
176
  error(message: string, data?: unknown): void;
177
+ /**
178
+ * Log a debug-level message.
179
+ *
180
+ * @param message - Human-readable log message.
181
+ * @param data - Structured context attached as OTel log attributes.
182
+ * Use key-value objects to enable filtering and aggregation in your
183
+ * observability backend (e.g. Grafana, Datadog, New Relic).
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * logger.debug('Cache lookup', { key: 'user:42', hit: false })
188
+ * ```
189
+ */
16
190
  debug(message: string, data?: unknown): void;
17
191
  }
18
192
  //#endregion
19
- export { type ApiRequest, type ApiResponse, type Channel, ChannelReader, ChannelWriter, type HttpAuthConfig, type HttpInvocationConfig, type HttpRequest, type HttpResponse, type ISdk, type InitOptions, Logger, type StreamChannelRef, http, registerWorker };
193
+ export { type ApiRequest, type ApiResponse, type Channel, ChannelReader, ChannelWriter, type EnqueueResult, type FunctionRef, type HttpAuthConfig, type HttpInvocationConfig, type HttpRequest, type HttpResponse, type ISdk, type InitOptions, type InternalHttpRequest, Logger, type MessageType, type RegisterFunctionInput, type RegisterFunctionMessage, type RegisterServiceInput, type RegisterTriggerInput, type RegisterTriggerMessage, type RegisterTriggerTypeInput, type RegisterTriggerTypeMessage, type RemoteFunctionHandler, type StreamChannelRef, type Trigger, TriggerAction, type TriggerAction$1 as TriggerActionType, type TriggerConfig, type TriggerHandler, type TriggerInfo, type TriggerRequest, http, registerWorker };
20
194
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/logger.ts"],"sourcesContent":[],"mappings":";;;;cAiBa,MAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/iii.ts","../src/logger.ts"],"mappings":";;;;KAyEY,gBAAA;EACV,QAAA;EACA,YAAA;EACA,SAAA;EACA,iBAAA;AAAA;;;AAeF;;;;;;;;;;KAAY,WAAA;EAIV,gEAFA,UAAA,WAUA;EARA,sBAAA,YAQ6B;EAN7B,mBAAA;EAYO;;;;;EANP,kBAAA,GAAqB,OAAA,CAAQ,qBAAA;EAi4BlB;;;;;EA33BX,IAAA,GAAO,IAAA,CAAK,UAAA;EAEZ,SAAA,GAAY,gBAAA;AAAA;;;;AA25Bd;;;;;;;;;;;;;AC/9BA;;;;;;cD67Ba,aAAA;EC57BH;;;;;;;;EAAA;IDq8BU,KAAA;EAAA,MAAkB,eAAA;EC12B/B;;;;EAAA,qBD+2BK,eAAA;AAAA;;;;;;;;;;;;;;;;;;cAoBC,cAAA,GAAkB,OAAA,UAAiB,OAAA,GAAU,WAAA,KAAc,IAAA;;;;;;AA/6BxE;;;;;;;;;;;;;;;;;;;;;;;cChDa,MAAA;EAAA,iBAYQ,OAAA;EAAA,iBACA,WAAA;EAAA,iBACA,MAAA;EAAA,QAbX,WAAA;EAAA,YAEI,UAAA,CAAA;cASO,OAAA,uBACA,WAAA,uBACA,MAAA;EAAA,QAGX,IAAA;;;;;AD88BV;;;;;;;;;ECp5BE,IAAA,CAAK,OAAA,UAAiB,IAAA;;;;AA3ExB;;;;;;;;;;EA4FE,IAAA,CAAK,OAAA,UAAiB,IAAA;EA/EH;;;;;;;;;;;;;EAgGnB,KAAA,CAAM,OAAA,UAAiB,IAAA;EAiBA;;;;;;;;;;;;;EAAvB,KAAA,CAAM,OAAA,UAAiB,IAAA;AAAA"}