diff --git a/package-lock.json b/package-lock.json index ef9ceb65..74e05cb9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,8 +11,7 @@ "dependencies": { "@azure/core-auth": "^1.9.0", "@azure/functions": "^4.11.2", - "@azure/functions-old": "npm:@azure/functions@3.5.1", - "@azure/identity": "^4.6.0", + "@azure/identity": "^4.13.1", "@azure/monitor-opentelemetry": "^1.18.0", "@azure/monitor-opentelemetry-exporter": "^1.0.0-beta.41", "@azure/opentelemetry-instrumentation-azure-sdk": "^1.0.0-beta.7", @@ -182,22 +181,10 @@ "node": ">=18.0" } }, - "node_modules/@azure/functions-old": { - "name": "@azure/functions", - "version": "3.5.1", - "resolved": "https://registry.npmjs.org/@azure/functions/-/functions-3.5.1.tgz", - "integrity": "sha512-6UltvJiuVpvHSwLcK/Zc6NfUwlkDLOFFx97BHCJzlWNsfiWwzwmTsxJXg4kE/LemKTHxPpfoPE+kOJ8hAdiKFQ==", - "license": "MIT", - "dependencies": { - "iconv-lite": "^0.6.3", - "long": "^4.0.0", - "uuid": "^8.3.0" - } - }, "node_modules/@azure/identity": { - "version": "4.12.0", - "resolved": "https://registry.npmjs.org/@azure/identity/-/identity-4.12.0.tgz", - "integrity": "sha512-6vuh2R3Cte6SD6azNalLCjIDoryGdcvDVEV7IDRPtm5lHX5ffkDlIalaoOp5YJU08e4ipjJENel20kSMDLAcug==", + "version": "4.13.1", + "resolved": "https://registry.npmjs.org/@azure/identity/-/identity-4.13.1.tgz", + "integrity": "sha512-5C/2WD5Vb1lHnZS16dNQRPMjN6oV/Upba+C9nBIs15PmOi6A3ZGs4Lr2u60zw4S04gi+u3cEXiqTVP7M4Pz3kw==", "license": "MIT", "dependencies": { "@azure/abort-controller": "^2.0.0", @@ -207,8 +194,8 @@ "@azure/core-tracing": "^1.0.0", "@azure/core-util": "^1.11.0", "@azure/logger": "^1.0.0", - "@azure/msal-browser": "^4.2.0", - "@azure/msal-node": "^3.5.0", + "@azure/msal-browser": "^5.5.0", + "@azure/msal-node": "^5.1.0", "open": "^10.1.0", "tslib": "^2.2.0" }, @@ -294,38 +281,37 @@ } }, "node_modules/@azure/msal-browser": { - "version": "4.22.1", - "resolved": "https://registry.npmjs.org/@azure/msal-browser/-/msal-browser-4.22.1.tgz", - "integrity": "sha512-/I76rBJpt5ZVfFXk+GkKxD4w1DZEbVpNn0aQjvRgnDnTYo3L/f8Oeo3R1O9eL/ccg5j1537iRLr7UwVhwnHtyg==", + "version": "5.11.0", + "resolved": "https://registry.npmjs.org/@azure/msal-browser/-/msal-browser-5.11.0.tgz", + "integrity": "sha512-zkGNYS3TwY8lUpPIafAmsFCYZbgFixY9y/LZB9GUg0IILoHTqpN26j5OrkL1AQThh/YdZsawe4iWXfp85lFVxg==", "license": "MIT", "dependencies": { - "@azure/msal-common": "15.12.0" + "@azure/msal-common": "16.6.2" }, "engines": { "node": ">=0.8.0" } }, "node_modules/@azure/msal-common": { - "version": "15.12.0", - "resolved": "https://registry.npmjs.org/@azure/msal-common/-/msal-common-15.12.0.tgz", - "integrity": "sha512-4ucXbjVw8KJ5QBgnGJUeA07c8iznwlk5ioHIhI4ASXcXgcf2yRFhWzYOyWg/cI49LC9ekpFJeQtO3zjDTbl6TQ==", + "version": "16.6.2", + "resolved": "https://registry.npmjs.org/@azure/msal-common/-/msal-common-16.6.2.tgz", + "integrity": "sha512-hQjjsekAjB00cM1EmatWJlzhEoK2Qhz7Rj5gvM6tYf8iL7RM3tkxlpU9fG0+ofkulzg9AEEA6dIEnSmDr5ZqUA==", "license": "MIT", "engines": { "node": ">=0.8.0" } }, "node_modules/@azure/msal-node": { - "version": "3.7.3", - "resolved": "https://registry.npmjs.org/@azure/msal-node/-/msal-node-3.7.3.tgz", - "integrity": "sha512-MoJxkKM/YpChfq4g2o36tElyzNUMG8mfD6u8NbuaPAsqfGpaw249khAcJYNoIOigUzRw45OjXCOrexE6ImdUxg==", + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/@azure/msal-node/-/msal-node-5.2.2.tgz", + "integrity": "sha512-toS+2AePxqyzb0YOKttDOOiSl3jrkK9aiqIvpurpis0O34QcIS5gToqrgT39p04Dpxw3YoUU0lxJKTpSFFfA6Q==", "license": "MIT", "dependencies": { - "@azure/msal-common": "15.12.0", - "jsonwebtoken": "^9.0.0", - "uuid": "^8.3.0" + "@azure/msal-common": "16.6.2", + "jsonwebtoken": "^9.0.0" }, "engines": { - "node": ">=16" + "node": ">=20" } }, "node_modules/@azure/opentelemetry-instrumentation-azure-sdk": { @@ -715,9 +701,9 @@ } }, "node_modules/@grpc/grpc-js": { - "version": "1.14.3", - "resolved": "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.14.3.tgz", - "integrity": "sha512-Iq8QQQ/7X3Sac15oB6p0FmUg/klxQvXLeileoqrTRGJYLV+/9tubbr9ipz0GKHjmXVsgFPo/+W+2cA8eNcR+XA==", + "version": "1.14.4", + "resolved": "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.14.4.tgz", + "integrity": "sha512-k9Dj3DV/itK9D06Y8f190Qgop7/Ui+D0njFV3LHMPwPT75DpXLQohE9Wmz0QElrJnzsjB7KPWiKJbOl7IPDArQ==", "license": "Apache-2.0", "dependencies": { "@grpc/proto-loader": "^0.8.0", @@ -3556,18 +3542,6 @@ "node": ">= 14" } }, - "node_modules/iconv-lite": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", - "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", - "license": "MIT", - "dependencies": { - "safer-buffer": ">= 2.1.2 < 3.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/ignore": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", @@ -4043,12 +4017,12 @@ } }, "node_modules/jsonwebtoken": { - "version": "9.0.2", - "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.2.tgz", - "integrity": "sha512-PRp66vJ865SSqOlgqS8hujT5U4AOgMfhrwYIuIhfKaoSCZcirrmASQr8CX7cUg+RMih+hgznrjp99o+W4pJLHQ==", + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.3.tgz", + "integrity": "sha512-MT/xP0CrubFRNLNKvxJ2BYfy53Zkm++5bX9dtuPbqAeQpTVe0MQTFhao8+Cp//EmJp244xt6Drw/GVEGCUj40g==", "license": "MIT", "dependencies": { - "jws": "^4.0.0", + "jws": "^4.0.1", "lodash.includes": "^4.3.0", "lodash.isboolean": "^3.0.3", "lodash.isinteger": "^4.0.4", @@ -4243,12 +4217,6 @@ "node": ">= 12.0.0" } }, - "node_modules/long": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz", - "integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==", - "license": "Apache-2.0" - }, "node_modules/lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", @@ -4912,9 +4880,9 @@ } }, "node_modules/pg-protocol": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.13.0.tgz", - "integrity": "sha512-zzdvXfS6v89r6v7OcFCHfHlyG/wvry1ALxZo4LqgUoy7W9xhBDMaqOuMiF3qEV45VqsN6rdlcehHrfDtlCPc8w==", + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.14.0.tgz", + "integrity": "sha512-n5taZ1kO3s9ngDTVxsEznOqCyToTgz0FLuPq0B33COy5pPpuWJpY3/2oRBVETuOgzdqRXfWpM9HIhp2LBBT1BA==", "license": "MIT" }, "node_modules/pg-types": { @@ -5111,14 +5079,13 @@ } }, "node_modules/protobufjs": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-8.2.0.tgz", - "integrity": "sha512-oI+GC9iPxrQEr6wragljFKH46/r3rNsm6eg7F2fp6kBUMnf6/mesDRdBuF4gK+OyaKJ8N4C1B9s9cCeYdqFikg==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-8.4.0.tgz", + "integrity": "sha512-iriNhQ57SYA5Jbdi+41AyPdx6jPPkFO7DODzkOBmqFhgYn/JzX2HxgxYPY18eQAs3CP/AWqtPvkWn8rclRAxdQ==", "hasInstallScript": true, "license": "BSD-3-Clause", "dependencies": { - "@types/node": ">=13.7.0", - "long": "^5.0.0" + "long": "^5.3.2" }, "engines": { "node": ">=12.0.0" @@ -5389,12 +5356,6 @@ "node": ">=10" } }, - "node_modules/safer-buffer": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", - "license": "MIT" - }, "node_modules/semver": { "version": "7.7.2", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", @@ -5825,6 +5786,7 @@ "version": "8.3.2", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "dev": true, "license": "MIT", "bin": { "uuid": "dist/bin/uuid" diff --git a/package.json b/package.json index c1a743fe..02ec5208 100644 --- a/package.json +++ b/package.json @@ -66,8 +66,7 @@ "dependencies": { "@azure/core-auth": "^1.9.0", "@azure/functions": "^4.11.2", - "@azure/functions-old": "npm:@azure/functions@3.5.1", - "@azure/identity": "^4.6.0", + "@azure/identity": "^4.13.1", "@azure/monitor-opentelemetry": "^1.18.0", "@azure/monitor-opentelemetry-exporter": "^1.0.0-beta.41", "@azure/opentelemetry-instrumentation-azure-sdk": "^1.0.0-beta.7", diff --git a/src/shim/azureFunctionsV3Types.ts b/src/shim/azureFunctionsV3Types.ts new file mode 100644 index 00000000..2d81e6d1 --- /dev/null +++ b/src/shim/azureFunctionsV3Types.ts @@ -0,0 +1,185 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +// +// Inlined type definitions for the Azure Functions v3 (programming model v3) +// public surface. These mirror the interfaces previously imported from +// `@azure/functions` v3.x (aliased as `@azure/functions-old`) so this SDK can +// keep accepting v3-model Context/HttpRequest objects without taking a runtime +// dependency on that package. Removing the dependency eliminates the +// transitive `uuid@8.x` chain that security scanners flag (MSRC 115880 / +// GHSA-w5hq-g745-h8pq). +// +// Source of truth: @azure/functions@3.5.1 type declarations +// (https://github.com/Azure/azure-functions-nodejs-library, MIT). + +/** + * HTTP request headers. + */ +export interface HttpRequestHeaders { + [name: string]: string; +} + +/** + * HTTP response headers. + */ +export interface HttpResponseHeaders { + [name: string]: string; +} + +/** + * Query string parameter keys and values from the URL. + */ +export interface HttpRequestQuery { + [name: string]: string; +} + +/** + * Route parameter keys and values. + */ +export interface HttpRequestParams { + [name: string]: string; +} + +/** + * Possible values for an HTTP request method. + */ +export type HttpMethod = + | "GET" + | "POST" + | "DELETE" + | "HEAD" + | "PATCH" + | "PUT" + | "OPTIONS" + | "TRACE" + | "CONNECT"; + +/** + * Possible values for an HTTP Request user type. + */ +export type HttpRequestUserType = "AppService" | "StaticWebApps"; + +/** + * Object representing a logged-in user, either through + * AppService/Functions authentication or SWA Authentication. + */ +export interface HttpRequestUser { + type: HttpRequestUserType; + id: string; + username: string; + identityProvider: string; + claimsPrincipalData: { + [key: string]: any; + }; +} + +export interface FormPart { + value: Buffer; + fileName?: string; + contentType?: string; +} + +export interface Form extends Iterable<[string, FormPart]> { + get(name: string): FormPart | null; + getAll(name: string): FormPart[]; + has(name: string): boolean; + length: number; +} + +/** + * HTTP request object. Provided to your function when using HTTP Bindings. + */ +export interface HttpRequest { + method: HttpMethod | null; + url: string; + headers: HttpRequestHeaders; + query: HttpRequestQuery; + params: HttpRequestParams; + user: HttpRequestUser | null; + body?: any; + rawBody?: any; + bufferBody?: Buffer; + get(field: string): string | undefined; + parseFormBody(): Form; +} + +/** + * TraceContext information to enable distributed tracing scenarios. + */ +export interface TraceContext { + traceparent: string | null | undefined; + tracestate: string | null | undefined; + attributes: + | { + [k: string]: string; + } + | null + | undefined; +} + +export interface Exception { + source?: string | null; + stackTrace?: string | null; + message?: string | null; +} + +export interface RetryContext { + retryCount: number; + maxRetryCount: number; + exception?: Exception; +} + +export interface ExecutionContext { + invocationId: string; + functionName: string; + functionDirectory: string; + retryContext: RetryContext | null; +} + +export interface ContextBindings { + [name: string]: any; +} + +export interface ContextBindingData { + invocationId: string; + [name: string]: any; +} + +export interface BindingDefinition { + name: string; + type: string; + direction: "in" | "out" | "inout" | undefined; +} + +/** + * Allows you to write streaming function logs. + */ +export interface Logger { + (...args: any[]): void; + error(...args: any[]): void; + warn(...args: any[]): void; + info(...args: any[]): void; + verbose(...args: any[]): void; +} + +/** + * The context object can be used for writing logs, reading data from bindings, + * setting outputs and using the context.done callback when your exported + * function is synchronous. A context object is passed to your function from the + * Azure Functions runtime on function invocation. + */ +export interface Context { + invocationId: string; + executionContext: ExecutionContext; + bindings: ContextBindings; + bindingData: ContextBindingData; + traceContext: TraceContext; + bindingDefinitions: BindingDefinition[]; + log: Logger; + done(err?: Error | string | null, result?: any): void; + req?: HttpRequest; + res?: { + [key: string]: any; + }; + suppressAsyncDoneError?: boolean; +} diff --git a/src/shim/correlationContextManager.ts b/src/shim/correlationContextManager.ts index f9ca2668..37047be8 100644 --- a/src/shim/correlationContextManager.ts +++ b/src/shim/correlationContextManager.ts @@ -8,7 +8,7 @@ import { TraceState } from "@opentelemetry/core"; import { Span } from "@opentelemetry/sdk-trace-base"; import { ICorrelationContext, ITraceparent, ITracestate, ICustomProperties, AzureFnContext, AzureFnRequest, AzureFnTraceContext, HttpRequest } from "./types"; import { Util } from "../shared/util"; -import { HttpRequestHeaders } from "@azure/functions-old"; +import type { HttpRequestHeaders } from "./azureFunctionsV3Types"; import { HttpRequest as AzureFnHttpRequest } from "@azure/functions"; diff --git a/src/shim/types.ts b/src/shim/types.ts index b92f323b..7b8834b0 100644 --- a/src/shim/types.ts +++ b/src/shim/types.ts @@ -4,7 +4,7 @@ import { TokenCredential } from "@azure/core-auth"; import * as http from "http"; import https = require("https"); -import { Context as AzureFnV3Context, HttpRequest as AzureFnV3Request, TraceContext as AzureFnV3TraceContext } from "@azure/functions-old"; +import type { Context as AzureFnV3Context, HttpRequest as AzureFnV3Request, TraceContext as AzureFnV3TraceContext } from "./azureFunctionsV3Types"; import { InvocationContext as AzureFnV4Context, HttpRequest as AzureFnV4Request } from "@azure/functions"; export const UNSUPPORTED_MSG = "Please reference the Azure Monitor OpenTelemetry Migration Doc for more information. If this functionality is required, please revert to Application Insights 2.X SDK."; diff --git a/test/unitTests/shim/correlationContextManger.tests.ts b/test/unitTests/shim/correlationContextManger.tests.ts index f64d5237..8ed5d856 100644 --- a/test/unitTests/shim/correlationContextManger.tests.ts +++ b/test/unitTests/shim/correlationContextManger.tests.ts @@ -6,7 +6,7 @@ import * as events from "events"; import { SpanContext, context, trace, diag, DiagLogger } from "@opentelemetry/api"; import { TraceState } from "@opentelemetry/core"; import { Span } from "@opentelemetry/sdk-trace-base"; -import * as azureFunctionTypes from "@azure/functions-old"; +import type * as azureFunctionTypes from "../../../src/shim/azureFunctionsV3Types"; import { CorrelationContextManager } from '../../../src/shim/correlationContextManager'; import { ICorrelationContext, ITraceparent, ITracestate } from "../../../src/shim/types"; import { HttpRequest, InvocationContext, TraceContext } from "@azure/functions"; diff --git a/tsconfig.json b/tsconfig.json index 4cb99e75..128f6968 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,7 @@ "sourceMap": true, "declaration": true, "noImplicitAny": true, + "skipLibCheck": true, "outDir": "./out", "typeRoots": [ "./node_modules/@types",