@sinch/functions-runtime 0.6.2 → 0.7.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.
package/dist/index.d.ts CHANGED
@@ -4638,7 +4638,8 @@ export interface AgentStreamEndpointOptions {
4638
4638
  export declare function buildAgentStreamEndpoint(options: AgentStreamEndpointOptions): AgentStreamEndpoint;
4639
4639
  /**
4640
4640
  * Install `context.voice` on a context object, in place — and the `UniversalConfig` methods on
4641
- * `context.config` (see `attachConfigAccessors`).
4641
+ * `context.config` (see `attachConfigAccessors`). First hides the context's credentials from
4642
+ * serialisation and logging (see `protectContext`).
4642
4643
  *
4643
4644
  * @param context - Context under construction, without its `voice` member
4644
4645
  * @param v1 - The v1 SDK client to expose as `context.voice.v1`, if credentials produced one
@@ -5624,6 +5625,62 @@ export declare function sessionCookieHeader(user: string, password: string): str
5624
5625
  export declare function clearedSessionCookieHeader(): string;
5625
5626
  /** Whether the `Cookie` header carries a valid session for this credential pair. */
5626
5627
  export declare function hasValidSessionCookie(cookieHeader: string | undefined, user: string, password: string): boolean;
5628
+ /**
5629
+ * Set the credential values to redact, from `env`. Call it once the environment is final, and
5630
+ * again whenever a credential in it changes. Calling it with no credentials (`{}`) turns
5631
+ * redaction off.
5632
+ *
5633
+ * Has no other effect: stdout and stderr are redacted only after {@link installStdioRedaction}.
5634
+ *
5635
+ * @param env - The environment, normally `process.env`
5636
+ */
5637
+ export declare function configureSecretRedaction(env: Record<string, string | undefined>): void;
5638
+ /**
5639
+ * Replace every credential value in `text` with {@link REDACTED}. Overlapping or adjacent values
5640
+ * become one marker, so no fragment of either is left.
5641
+ *
5642
+ * Returns `text` itself when nothing matched, or before {@link configureSecretRedaction}.
5643
+ *
5644
+ * @param text - Any text about to leave the process
5645
+ */
5646
+ export declare function redactSecrets(text: string): string;
5647
+ /**
5648
+ * Redact a value the runtime writes out as text, whatever its type. A string goes through
5649
+ * {@link redactSecrets}. Anything else, such as an object a handler threw as an error's message,
5650
+ * is redacted as its JSON, or as `String(value)` when it has none (circular, a symbol), so it
5651
+ * cannot pass through unredacted. `undefined` and `null` hold nothing and are returned as given.
5652
+ *
5653
+ * @param value - Any value about to be written into a response body or a log record
5654
+ * @returns The redacted text, or `value` when it is `undefined` or `null`
5655
+ */
5656
+ export declare function redactAsText(value: unknown): string | null | undefined;
5657
+ /**
5658
+ * How many bytes past a cut point {@link safeCut} needs to see. 0 before
5659
+ * {@link configureSecretRedaction}.
5660
+ */
5661
+ export declare function secretLookaheadBytes(): number;
5662
+ /**
5663
+ * Shorten `prefix` so that no credential value is cut in half at its end.
5664
+ *
5665
+ * Text cut to a size limit can end partway through a value, and the half left behind no longer
5666
+ * matches it, so {@link redactSecrets} would let it through. This moves the cut back to the start
5667
+ * of the value that crosses it, or of the run of overlapping values it belongs to. A value that
5668
+ * ends exactly at the cut is left for {@link redactSecrets}.
5669
+ *
5670
+ * @param prefix - The text up to the cut
5671
+ * @param continuation - The text right after the cut, at least {@link secretLookaheadBytes} long
5672
+ * when that much exists
5673
+ * @returns `prefix`, or a shorter start of it
5674
+ */
5675
+ export declare function safeCut(prefix: string, continuation: string): string;
5676
+ /**
5677
+ * Redact the process's stdout and stderr. `console` writes through them, so this covers every
5678
+ * console method, `%o`, stack traces and the runtime's own debug output.
5679
+ *
5680
+ * Not covered: writes that bypass `stream.write` (`fs.writeSync(1, ...)`, a child process with
5681
+ * inherited stdio, Node's own print of an uncaught exception), and a value split across two writes.
5682
+ */
5683
+ export declare function installStdioRedaction(): void;
5627
5684
  /**
5628
5685
  * Converts a phone number to local/national format.
5629
5686
  *
@@ -5851,6 +5908,10 @@ export declare class TunnelClient {
5851
5908
  private webhookConfig;
5852
5909
  private welcomeResolver;
5853
5910
  private streams;
5911
+ /** Set by disconnect(). A reconnect after it would repoint the webhooks cleanup restored. */
5912
+ private shuttingDown;
5913
+ /** The in-flight configureWebhooks(), so disconnect() can wait for it before restoring. */
5914
+ private configuring;
5854
5915
  constructor(localPort?: number);
5855
5916
  /** Sends one JSON message up the tunnel channel, if it is still connected. */
5856
5917
  private sendMessage;
@@ -5861,7 +5922,8 @@ export declare class TunnelClient {
5861
5922
  /**
5862
5923
  * Build a full tunnel URL with optional sub-path and tunnel query param.
5863
5924
  * e.g. buildTunnelUrl('/webhook/conversation') →
5864
- * https://tunnel.fn.sinch.com/ingress/webhook/conversation?tunnel=01KKT...
5925
+ * https://tunnel.fn.sinch.io/ingress/webhook/conversation?tunnel=01KKT...
5926
+ * See ./url.ts for why the welcome URL's own query string is dropped.
5865
5927
  */
5866
5928
  private buildTunnelUrl;
5867
5929
  private handleWelcomeMessage;
@@ -5874,11 +5936,21 @@ export declare class TunnelClient {
5874
5936
  */
5875
5937
  private configureWebhooks;
5876
5938
  /**
5877
- * Cleanup webhooks on disconnect
5939
+ * Restore every webhook the tunnel repointed. Run in parallel: this happens during
5940
+ * shutdown, under a timeout, and the two restores are independent.
5941
+ * The v1 application callback is still not restored (it was never saved).
5878
5942
  */
5879
5943
  private cleanupWebhooks;
5880
5944
  private configureVoiceWebhooks;
5881
5945
  private scheduleReconnect;
5946
+ /**
5947
+ * Stop the tunnel and restore every webhook it repointed.
5948
+ *
5949
+ * Order matters (#102 review): stop reconnects and close the socket first, so no new
5950
+ * welcome can start another configure; then wait for any configure already in flight, so
5951
+ * a PATCH that lands late (Ctrl+C between its GET and its PATCH) cannot overwrite the
5952
+ * restore; only then restore.
5953
+ */
5882
5954
  disconnect(): Promise<void>;
5883
5955
  getTunnelUrl(): string | null;
5884
5956
  getIsConnected(): boolean;
package/dist/index.js CHANGED
@@ -43,6 +43,7 @@ import {
43
43
  clearedSessionCookieHeader,
44
44
  collectCredentials,
45
45
  commands,
46
+ configureSecretRedaction,
46
47
  connectAgent,
47
48
  createAceBuilder,
48
49
  createApp,
@@ -101,6 +102,7 @@ import {
101
102
  handleVoiceV1Callback,
102
103
  handleVoiceWebhook,
103
104
  hasValidSessionCookie,
105
+ installStdioRedaction,
104
106
  installWebSocketHandlers,
105
107
  isBrowserNavigation,
106
108
  isGated,
@@ -115,10 +117,14 @@ import {
115
117
  onCall,
116
118
  parseJson,
117
119
  realtimeAgent,
120
+ redactAsText,
121
+ redactSecrets,
118
122
  renderLoginPage,
119
123
  resetSinchClients,
120
124
  resetVoiceSignatureWarning,
121
125
  resolveAgentStreamUrl,
126
+ safeCut,
127
+ secretLookaheadBytes,
122
128
  secretsLoader,
123
129
  sendAuthChallenge,
124
130
  sessionCookieHeader,
@@ -137,7 +143,7 @@ import {
137
143
  validateVoiceV1Request,
138
144
  verifyVoiceWebhook,
139
145
  voiceRelay
140
- } from "./chunk-W3R4GR3E.js";
146
+ } from "./chunk-DLBCKZ6X.js";
141
147
  export {
142
148
  AGENT_HEADER_TOKEN,
143
149
  AGENT_STREAM_PATH,
@@ -179,6 +185,7 @@ export {
179
185
  clearedSessionCookieHeader,
180
186
  collectCredentials,
181
187
  commands,
188
+ configureSecretRedaction,
182
189
  connectAgent,
183
190
  toCamelCase as convertToCamelCase,
184
191
  createAceBuilder,
@@ -239,6 +246,7 @@ export {
239
246
  handleVoiceV1Callback,
240
247
  handleVoiceWebhook,
241
248
  hasValidSessionCookie,
249
+ installStdioRedaction,
242
250
  installWebSocketHandlers,
243
251
  isBrowserNavigation,
244
252
  isGated,
@@ -254,10 +262,14 @@ export {
254
262
  parseJson,
255
263
  parseJson as parseJsonLenient,
256
264
  realtimeAgent,
265
+ redactAsText,
266
+ redactSecrets,
257
267
  renderLoginPage,
258
268
  resetSinchClients,
259
269
  resetVoiceSignatureWarning,
260
270
  resolveAgentStreamUrl,
271
+ safeCut,
272
+ secretLookaheadBytes,
261
273
  secretsLoader,
262
274
  sendAuthChallenge,
263
275
  sessionCookieHeader,
package/dist/voice/v2.js CHANGED
@@ -40,7 +40,7 @@ import {
40
40
  toWebhookRequest,
41
41
  tool,
42
42
  voiceRelay
43
- } from "../chunk-W3R4GR3E.js";
43
+ } from "../chunk-DLBCKZ6X.js";
44
44
  export {
45
45
  Client,
46
46
  CommandBuilder,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinch/functions-runtime",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
4
4
  "description": "Node.js SDK and local development runtime for Sinch Functions: voice, messaging and HTTP serverless functions",
5
5
  "type": "module",
6
6
  "exports": {