@microsoft/rayfin-functions 1.31.0 → 1.33.0-beta.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @fileoverview Per-function typed client.
2
+ * @packageDocumentation Per-function typed client.
3
3
  *
4
4
  * Each property on the proxy returned by `createFunctionsApi` is a
5
5
  * `FunctionClient` whose `invoke()` signature is derived from the schema
@@ -35,33 +35,48 @@ export interface InvokeOptions {
35
35
  /**
36
36
  * A strongly-typed client for a single function.
37
37
  *
38
- * @template TInput - The parameter object the function expects (`void` when none).
39
- * @template TOutput - The type returned by the function.
38
+ * @typeParam TInput - The parameter object the function expects (`void` when none).
39
+ * @typeParam TOutput - The type returned by the function.
40
40
  */
41
41
  export declare class FunctionClient<TInput = any, TOutput = any> {
42
42
  private apiClient;
43
43
  private functionName;
44
44
  constructor(apiClient: ApiClient, functionName: string);
45
45
  /**
46
- * Invoke the function.
46
+ * Invoke the function and return its typed output.
47
47
  *
48
- * @param params - Input parameters (omit when the function takes no input).
49
- * @param options - Optional per-call settings (extra headers, etc.).
50
- * @returns A response whose `output` field is typed as `TOutput`.
48
+ * @param args - When the function accepts input, pass
49
+ * `[params, options?]` `params` are the input parameters declared
50
+ * by the function schema, `options` are optional per-call settings
51
+ * (extra headers, etc.). When the function takes no input, pass
52
+ * `[options?]` instead.
53
+ * @returns The function's success-path output, typed as `TOutput`.
51
54
  *
52
- * @throws {FunctionsError} If the function invocation fails.
53
- * @throws {NetworkError} For network-related issues.
54
- * @throws {SdkError} For any other unexpected SDK errors.
55
+ * Failure modes throw a non-empty `errors` array or a non-success
56
+ * status on the wire response is surfaced as {@link FunctionsError}.
57
+ * Network and unknown errors are wrapped in {@link NetworkError} and
58
+ * {@link FunctionsError} respectively. By the time this method
59
+ * resolves, the caller can use the value without defending against
60
+ * `undefined`.
61
+ *
62
+ * The server-side `invocationId` from the underlying envelope is
63
+ * emitted via `console.debug` (along with the function name) so the
64
+ * value is available in the browser/Node console for correlation
65
+ * without polluting the public return type.
66
+ *
67
+ * @throws {@link FunctionsError} - If the function invocation fails.
68
+ * @throws `NetworkError` - For network-related issues.
69
+ * @throws `SdkError` - For any other unexpected SDK errors.
55
70
  *
56
71
  * @example
57
72
  * ```typescript
58
- * const res = await client.functions.helloWorld.invoke({
73
+ * const greeting = await client.functions.helloWorld.invoke({
59
74
  * firstName: 'Ada',
60
75
  * lastName: 'Lovelace',
61
76
  * });
62
- * console.log(res.output); // typed as string
77
+ * console.log(greeting); // typed as string
63
78
  * ```
64
79
  */
65
- invoke(...args: TInput extends void ? [options?: InvokeOptions] : [params: TInput, options?: InvokeOptions]): Promise<FunctionInvocationResponse<TOutput>>;
80
+ invoke(...args: TInput extends void ? [options?: InvokeOptions] : [params: TInput, options?: InvokeOptions]): Promise<TOutput>;
66
81
  }
67
82
  //# sourceMappingURL=FunctionClient.d.ts.map
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @fileoverview Per-function typed client.
2
+ * @packageDocumentation Per-function typed client.
3
3
  *
4
4
  * Each property on the proxy returned by `createFunctionsApi` is a
5
5
  * `FunctionClient` whose `invoke()` signature is derived from the schema
@@ -7,12 +7,12 @@
7
7
  */
8
8
  import { SdkError, NetworkError } from '@microsoft/rayfin-lib';
9
9
  import { FUNCTIONS_BASE_PATH } from '@microsoft/rayfin-lib';
10
- import { FunctionsError } from './Functions';
10
+ import { FunctionsError } from './Functions.js';
11
11
  /**
12
12
  * A strongly-typed client for a single function.
13
13
  *
14
- * @template TInput - The parameter object the function expects (`void` when none).
15
- * @template TOutput - The type returned by the function.
14
+ * @typeParam TInput - The parameter object the function expects (`void` when none).
15
+ * @typeParam TOutput - The type returned by the function.
16
16
  */
17
17
  export class FunctionClient {
18
18
  apiClient;
@@ -22,23 +22,38 @@ export class FunctionClient {
22
22
  this.functionName = functionName;
23
23
  }
24
24
  /**
25
- * Invoke the function.
25
+ * Invoke the function and return its typed output.
26
26
  *
27
- * @param params - Input parameters (omit when the function takes no input).
28
- * @param options - Optional per-call settings (extra headers, etc.).
29
- * @returns A response whose `output` field is typed as `TOutput`.
27
+ * @param args - When the function accepts input, pass
28
+ * `[params, options?]` `params` are the input parameters declared
29
+ * by the function schema, `options` are optional per-call settings
30
+ * (extra headers, etc.). When the function takes no input, pass
31
+ * `[options?]` instead.
32
+ * @returns The function's success-path output, typed as `TOutput`.
30
33
  *
31
- * @throws {FunctionsError} If the function invocation fails.
32
- * @throws {NetworkError} For network-related issues.
33
- * @throws {SdkError} For any other unexpected SDK errors.
34
+ * Failure modes throw a non-empty `errors` array or a non-success
35
+ * status on the wire response is surfaced as {@link FunctionsError}.
36
+ * Network and unknown errors are wrapped in {@link NetworkError} and
37
+ * {@link FunctionsError} respectively. By the time this method
38
+ * resolves, the caller can use the value without defending against
39
+ * `undefined`.
40
+ *
41
+ * The server-side `invocationId` from the underlying envelope is
42
+ * emitted via `console.debug` (along with the function name) so the
43
+ * value is available in the browser/Node console for correlation
44
+ * without polluting the public return type.
45
+ *
46
+ * @throws {@link FunctionsError} - If the function invocation fails.
47
+ * @throws `NetworkError` - For network-related issues.
48
+ * @throws `SdkError` - For any other unexpected SDK errors.
34
49
  *
35
50
  * @example
36
51
  * ```typescript
37
- * const res = await client.functions.helloWorld.invoke({
52
+ * const greeting = await client.functions.helloWorld.invoke({
38
53
  * firstName: 'Ada',
39
54
  * lastName: 'Lovelace',
40
55
  * });
41
- * console.log(res.output); // typed as string
56
+ * console.log(greeting); // typed as string
42
57
  * ```
43
58
  */
44
59
  async invoke(...args) {
@@ -66,7 +81,16 @@ export class FunctionClient {
66
81
  parameters = args[0];
67
82
  options = args[1];
68
83
  }
69
- const url = `${FUNCTIONS_BASE_PATH}/${this.functionName}/invoke`;
84
+ // When a `functionsBaseUrl` is configured on the ApiClient (e.g. by
85
+ // local-debug flows that point at a `func start` process), invoke the
86
+ // function directly against `${functionsBaseUrl}/api/<name>` using the
87
+ // Azure Functions Core Tools routing convention. Otherwise fall back to
88
+ // the production path `${baseUrl}/functions/<name>/invoke` handled by
89
+ // the Fabric `InvokeController`.
90
+ const functionsBaseUrl = this.apiClient.getFunctionsBaseUrl();
91
+ const url = functionsBaseUrl
92
+ ? `${functionsBaseUrl}/api/${this.functionName}`
93
+ : `${FUNCTIONS_BASE_PATH}/${this.functionName}/invoke`;
70
94
  const response = await this.apiClient.post(url, parameters ?? {}, { headers: options?.headers });
71
95
  // Check for errors in the response body
72
96
  if (response.errors && response.errors.length > 0) {
@@ -80,23 +104,39 @@ export class FunctionClient {
80
104
  if (status !== 'success' && status !== 'succeeded') {
81
105
  throw new FunctionsError(`Function invocation failed with status: ${response.status}`, 'FUNCTION_EXECUTION_ERROR');
82
106
  }
83
- // Auto-parse JSON-encoded output strings
107
+ // Auto-parse JSON-encoded output strings. The Fabric runtime
108
+ // sometimes wraps the user's return value in an inner envelope
109
+ // (a stringified `{ output: <value> }`); peel that off so the
110
+ // caller always sees the original `TOutput`.
111
+ // To-Do Investigate why the double JSON encoding is necessary on the runtime side and whether it can be eliminated.
112
+ let output;
84
113
  if (typeof response.output === 'string') {
85
114
  try {
86
115
  const parsed = JSON.parse(response.output);
87
- // If the parsed envelope has its own `output` field, unwrap it
88
116
  if (parsed && typeof parsed === 'object' && 'output' in parsed) {
89
- response.output = parsed.output;
117
+ output = parsed.output;
90
118
  }
91
119
  else {
92
- response.output = parsed;
120
+ output = parsed;
93
121
  }
94
122
  }
95
123
  catch {
96
- // Not JSON — leave as-is (TOutput may be `string`)
124
+ // Not JSON — pass through (TOutput may be `string`)
125
+ output = response.output;
97
126
  }
98
127
  }
99
- return response;
128
+ else {
129
+ output = response.output;
130
+ }
131
+ // Surface invocationId via console.debug so callers can correlate
132
+ // a UI action with server-side telemetry without us having to
133
+ // bake the envelope into the return type. This is opt-in noise
134
+ // that DevTools / Node consoles hide unless the verbose level is
135
+ // turned on.
136
+ if (response.invocationId) {
137
+ console.debug(`[rayfin-functions] ${this.functionName} invocationId=${response.invocationId}`);
138
+ }
139
+ return output;
100
140
  }
101
141
  catch (error) {
102
142
  if (error instanceof FunctionsError ||
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @fileoverview Functions API for invoking serverless functions.
2
+ * @packageDocumentation Functions API for invoking serverless functions.
3
3
  *
4
4
  * The single public surface is `client.functions.<name>.invoke(...)` where
5
5
  * `<name>` is constrained by the `FunctionsSchema` type parameter passed to
@@ -10,10 +10,10 @@
10
10
  * ```
11
11
  */
12
12
  import { ApiClient, SdkError } from '@microsoft/rayfin-lib';
13
- import { FunctionClient } from './FunctionClient';
14
- import type { FunctionsSchema } from './FunctionsSchema';
15
- export { FunctionClient } from './FunctionClient';
16
- export type { FunctionInvocationResponse, InvokeOptions, } from './FunctionClient';
13
+ import { FunctionClient } from './FunctionClient.js';
14
+ import type { FunctionsSchema } from './FunctionsSchema.js';
15
+ export { FunctionClient } from './FunctionClient.js';
16
+ export type { FunctionInvocationResponse, InvokeOptions, } from './FunctionClient.js';
17
17
  /**
18
18
  * Functions error specific to the Rayfin SDK.
19
19
  */
package/dist/Functions.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @fileoverview Functions API for invoking serverless functions.
2
+ * @packageDocumentation Functions API for invoking serverless functions.
3
3
  *
4
4
  * The single public surface is `client.functions.<name>.invoke(...)` where
5
5
  * `<name>` is constrained by the `FunctionsSchema` type parameter passed to
@@ -10,8 +10,8 @@
10
10
  * ```
11
11
  */
12
12
  import { SdkError } from '@microsoft/rayfin-lib';
13
- import { FunctionClient } from './FunctionClient';
14
- export { FunctionClient } from './FunctionClient';
13
+ import { FunctionClient } from './FunctionClient.js';
14
+ export { FunctionClient } from './FunctionClient.js';
15
15
  /**
16
16
  * Functions error specific to the Rayfin SDK.
17
17
  */
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { FunctionsError, createFunctionsApi, FunctionClient, } from './Functions';
2
- export type { FunctionInvocationResponse, InvokeOptions, TypedFunctionClients, } from './Functions';
3
- export type { FunctionsSchema } from './FunctionsSchema';
1
+ export { FunctionsError, createFunctionsApi, FunctionClient, } from './Functions.js';
2
+ export type { FunctionInvocationResponse, InvokeOptions, TypedFunctionClients, } from './Functions.js';
3
+ export type { FunctionsSchema } from './FunctionsSchema.js';
4
4
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { FunctionsError, createFunctionsApi, FunctionClient, } from './Functions';
1
+ export { FunctionsError, createFunctionsApi, FunctionClient, } from './Functions.js';
2
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/rayfin-functions",
3
- "version": "1.31.0",
3
+ "version": "1.33.0-beta.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,7 +19,7 @@
19
19
  "rimraf": "~6.0.1"
20
20
  },
21
21
  "dependencies": {
22
- "@microsoft/rayfin-lib": "1.31.0"
22
+ "@microsoft/rayfin-lib": "1.33.0-beta.0"
23
23
  },
24
24
  "publishConfig": {
25
25
  "registry": "https://npm.pkg.github.com",
@@ -35,7 +35,7 @@
35
35
  "license": "MIT",
36
36
  "type": "module",
37
37
  "scripts": {
38
- "build": "tsc",
38
+ "build": "tsc && node ../scripts/fix-esm-extensions.mjs ./dist",
39
39
  "build:watch": "tsc --watch",
40
40
  "clean": "rimraf dist && rimraf .tsbuildinfo",
41
41
  "test": "vitest run"