iii-sdk 0.8.3 → 0.9.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 (48) hide show
  1. package/README.md +15 -11
  2. package/dist/index.cjs +234 -105
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +182 -3
  5. package/dist/index.d.cts.map +1 -1
  6. package/dist/index.d.mts +182 -3
  7. package/dist/index.d.mts.map +1 -1
  8. package/dist/index.mjs +234 -106
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/state.cjs +1 -0
  11. package/dist/state.cjs.map +1 -1
  12. package/dist/state.d.cts +43 -1
  13. package/dist/state.d.cts.map +1 -1
  14. package/dist/state.d.mts +43 -1
  15. package/dist/state.d.mts.map +1 -1
  16. package/dist/state.mjs +1 -0
  17. package/dist/state.mjs.map +1 -1
  18. package/dist/stream-BAjVneSg.d.mts +176 -0
  19. package/dist/stream-BAjVneSg.d.mts.map +1 -0
  20. package/dist/stream-DUNsytJU.d.cts +176 -0
  21. package/dist/stream-DUNsytJU.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 +1 -1
  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-coGqiBHT.mjs → utils-5jD8F3OE.mjs} +241 -212
  31. package/dist/utils-5jD8F3OE.mjs.map +1 -0
  32. package/dist/{utils-CMrMD5Ij.d.mts → utils-BRn3Iff5.d.mts} +586 -210
  33. package/dist/utils-BRn3Iff5.d.mts.map +1 -0
  34. package/dist/{utils-BaGgUfjl.d.cts → utils-D6RPYBhs.d.cts} +586 -210
  35. package/dist/utils-D6RPYBhs.d.cts.map +1 -0
  36. package/dist/{utils-BJTjoUdq.cjs → utils-bsZVduQi.cjs} +240 -211
  37. package/dist/utils-bsZVduQi.cjs.map +1 -0
  38. package/package.json +4 -2
  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.map +0 -1
  47. package/dist/utils-CMrMD5Ij.d.mts.map +0 -1
  48. package/dist/utils-coGqiBHT.mjs.map +0 -1
package/dist/index.d.mts CHANGED
@@ -1,7 +1,134 @@
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-BRn3Iff5.mjs";
2
2
 
3
- //#region src/logger.d.ts
3
+ //#region src/iii.d.ts
4
4
 
5
+ /** @internal */
6
+ type TelemetryOptions = {
7
+ language?: string;
8
+ project_name?: string;
9
+ framework?: string;
10
+ amplitude_api_key?: string;
11
+ };
12
+ /**
13
+ * Configuration options passed to {@link registerWorker}.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const iii = registerWorker('ws://localhost:49134', {
18
+ * workerName: 'my-worker',
19
+ * invocationTimeoutMs: 10000,
20
+ * reconnectionConfig: { maxRetries: 5 },
21
+ * })
22
+ * ```
23
+ */
24
+ type InitOptions = {
25
+ /** Display name for this worker. Defaults to `hostname:pid`. */
26
+ workerName?: string;
27
+ /** Enable worker metrics via OpenTelemetry. Defaults to `true`. */
28
+ enableMetricsReporting?: boolean;
29
+ /** Default timeout for `trigger()` in milliseconds. Defaults to `30000`. */
30
+ invocationTimeoutMs?: number;
31
+ /**
32
+ * WebSocket reconnection behavior.
33
+ *
34
+ * @see {@link IIIReconnectionConfig} for available fields and defaults.
35
+ */
36
+ reconnectionConfig?: Partial<IIIReconnectionConfig>;
37
+ /**
38
+ * OpenTelemetry configuration. OTel is initialized automatically by default.
39
+ * Set `{ enabled: false }` or env `OTEL_ENABLED=false/0/no/off` to disable.
40
+ * The `engineWsUrl` is set automatically from the III address.
41
+ */
42
+ otel?: Omit<OtelConfig, 'engineWsUrl'>;
43
+ /** @internal */
44
+ telemetry?: TelemetryOptions;
45
+ };
46
+ /**
47
+ * Factory object that constructs routing actions for {@link ISdk.trigger}.
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * import { TriggerAction } from 'iii-sdk'
52
+ *
53
+ * // Enqueue to a named queue
54
+ * iii.trigger({
55
+ * function_id: 'process',
56
+ * payload: { data: 'hello' },
57
+ * action: TriggerAction.Enqueue({ queue: 'jobs' }),
58
+ * })
59
+ *
60
+ * // Fire-and-forget
61
+ * iii.trigger({
62
+ * function_id: 'notify',
63
+ * payload: {},
64
+ * action: TriggerAction.Void(),
65
+ * })
66
+ * ```
67
+ */
68
+ declare const TriggerAction: {
69
+ /**
70
+ * Routes the invocation through a named queue. The engine enqueues the job,
71
+ * acknowledges the caller with `{ messageReceiptId }`, and processes it
72
+ * asynchronously.
73
+ *
74
+ * @param opts - Queue routing options.
75
+ * @param opts.queue - Name of the target queue.
76
+ */
77
+ readonly Enqueue: (opts: {
78
+ queue: string;
79
+ }) => TriggerAction$1;
80
+ /**
81
+ * Fire-and-forget routing. The engine forwards the invocation without
82
+ * waiting for a response or queuing the job.
83
+ */
84
+ readonly Void: () => TriggerAction$1;
85
+ };
86
+ /**
87
+ * Creates and returns a connected SDK instance. The WebSocket connection is
88
+ * established automatically -- there is no separate `connect()` call.
89
+ *
90
+ * @param address - WebSocket URL of the III engine (e.g. `ws://localhost:49134`).
91
+ * @param options - Optional {@link InitOptions} for worker name, timeouts, reconnection, and OTel.
92
+ * @returns A connected {@link ISdk} instance.
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * import { registerWorker } from 'iii-sdk'
97
+ *
98
+ * const iii = registerWorker(process.env.III_URL ?? 'ws://localhost:49134', {
99
+ * workerName: 'my-worker',
100
+ * })
101
+ * ```
102
+ */
103
+ declare const registerWorker: (address: string, options?: InitOptions) => ISdk;
104
+ //#endregion
105
+ //#region src/logger.d.ts
106
+ /**
107
+ * Structured logger that emits logs as OpenTelemetry LogRecords.
108
+ *
109
+ * Every log call automatically captures the active trace and span context,
110
+ * correlating your logs with distributed traces without any manual wiring.
111
+ * When OTel is not initialized, Logger gracefully falls back to `console.*`.
112
+ *
113
+ * Pass structured data as the second argument to any log method. Using an
114
+ * object of key-value pairs (instead of string interpolation) lets you
115
+ * filter, aggregate, and build dashboards in your observability backend.
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * import { Logger } from 'iii-sdk'
120
+ *
121
+ * const logger = new Logger()
122
+ *
123
+ * // Basic logging — trace context is injected automatically
124
+ * logger.info('Worker connected')
125
+ *
126
+ * // Structured context for dashboards and alerting
127
+ * logger.info('Order processed', { orderId: 'ord_123', amount: 49.99, currency: 'USD' })
128
+ * logger.warn('Retry attempt', { attempt: 3, maxRetries: 5, endpoint: '/api/charge' })
129
+ * logger.error('Payment failed', { orderId: 'ord_123', gateway: 'stripe', errorCode: 'card_declined' })
130
+ * ```
131
+ */
5
132
  declare class Logger {
6
133
  private readonly traceId?;
7
134
  private readonly serviceName?;
@@ -10,11 +137,63 @@ declare class Logger {
10
137
  private get otelLogger();
11
138
  constructor(traceId?: string | undefined, serviceName?: string | undefined, spanId?: string | undefined);
12
139
  private emit;
140
+ /**
141
+ * Log an info-level message.
142
+ *
143
+ * @param message - Human-readable log message.
144
+ * @param data - Structured context attached as OTel log attributes.
145
+ * Use key-value objects to enable filtering and aggregation in your
146
+ * observability backend (e.g. Grafana, Datadog, New Relic).
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * logger.info('Order processed', { orderId: 'ord_123', status: 'completed' })
151
+ * ```
152
+ */
13
153
  info(message: string, data?: unknown): void;
154
+ /**
155
+ * Log a warning-level message.
156
+ *
157
+ * @param message - Human-readable log message.
158
+ * @param data - Structured context attached as OTel log attributes.
159
+ * Use key-value objects to enable filtering and aggregation in your
160
+ * observability backend (e.g. Grafana, Datadog, New Relic).
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * logger.warn('Retry attempt', { attempt: 3, maxRetries: 5, endpoint: '/api/charge' })
165
+ * ```
166
+ */
14
167
  warn(message: string, data?: unknown): void;
168
+ /**
169
+ * Log an error-level message.
170
+ *
171
+ * @param message - Human-readable log message.
172
+ * @param data - Structured context attached as OTel log attributes.
173
+ * Use key-value objects to enable filtering and aggregation in your
174
+ * observability backend (e.g. Grafana, Datadog, New Relic).
175
+ *
176
+ * @example
177
+ * ```typescript
178
+ * logger.error('Payment failed', { orderId: 'ord_123', gateway: 'stripe', errorCode: 'card_declined' })
179
+ * ```
180
+ */
15
181
  error(message: string, data?: unknown): void;
182
+ /**
183
+ * Log a debug-level message.
184
+ *
185
+ * @param message - Human-readable log message.
186
+ * @param data - Structured context attached as OTel log attributes.
187
+ * Use key-value objects to enable filtering and aggregation in your
188
+ * observability backend (e.g. Grafana, Datadog, New Relic).
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * logger.debug('Cache lookup', { key: 'user:42', hit: false })
193
+ * ```
194
+ */
16
195
  debug(message: string, data?: unknown): void;
17
196
  }
18
197
  //#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 };
198
+ 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
199
  //# 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"],"sourcesContent":[],"mappings":";;;;AA4FA;AAY+B,KA/BnB,gBAAA,GA+BmB;EAAR,QAAA,CAAA,EAAA,MAAA;EAMT,YAAA,CAAA,EAAA,MAAA;EAAL,SAAA,CAAA,EAAA,MAAA;EAEK,iBAAA,CAAA,EAAA,MAAA;CAAgB;AAy3B9B;AAkCA;;;;AC/9BA;;;;;;;KDgDY,WAAA;;;;;;;;;;;;uBAYW,QAAQ;;;;;;SAMtB,KAAK;;cAEA;;;;;;;;;;;;;;;;;;;;;;;;cAy3BD;;;;;;;;;;;QASyB;;;;;uBAK1B;;;;;;;;;;;;;;;;;;;cAoBC,4CAA6C,gBAAc;;;;AAlCxE;AAkCA;;;;AC/9BA;;;;;;;;;;;;;;;;;;;;cAAa,MAAA"}