@netlify/zip-it-and-ship-it
Advanced tools
Comparing version 9.35.1 to 9.36.0
import type { InvocationMode } from './function.js'; | ||
import type { TrafficRules } from './rate_limit.js'; | ||
import type { FunctionResult } from './utils/format_result.js'; | ||
import type { Route } from './utils/routes.js'; | ||
import type { ExtendedRoute, Route } from './utils/routes.js'; | ||
interface ManifestFunction { | ||
@@ -11,3 +11,4 @@ buildData?: Record<string, unknown>; | ||
path: string; | ||
routes?: Route[]; | ||
routes?: ExtendedRoute[]; | ||
excludedRoutes?: Route[]; | ||
runtime: string; | ||
@@ -14,0 +15,0 @@ runtimeVersion?: string; |
@@ -5,3 +5,3 @@ import type { ArgumentPlaceholder, Expression, SpreadElement, JSXNamespacedName } from '@babel/types'; | ||
import { InvocationMode } from '../../../function.js'; | ||
import { Route } from '../../../utils/routes.js'; | ||
import { ExtendedRoute, Route } from '../../../utils/routes.js'; | ||
import type { ModuleFormat } from '../utils/module_format.js'; | ||
@@ -11,5 +11,6 @@ export declare const IN_SOURCE_CONFIG_MODULE = "@netlify/functions"; | ||
config: InSourceConfig; | ||
excludedRoutes?: Route[]; | ||
inputModuleFormat?: ModuleFormat; | ||
invocationMode?: InvocationMode; | ||
routes?: Route[]; | ||
routes?: ExtendedRoute[]; | ||
runtimeAPIVersion?: number; | ||
@@ -20,2 +21,6 @@ } | ||
} | ||
declare const httpMethod: z.ZodEnum<["GET", "POST", "PUT", "PATCH", "OPTIONS", "DELETE", "HEAD"]>; | ||
declare const httpMethods: z.ZodEffects<z.ZodEnum<["GET", "POST", "PUT", "PATCH", "OPTIONS", "DELETE", "HEAD"]>, "GET" | "POST" | "PUT" | "PATCH" | "OPTIONS" | "DELETE" | "HEAD", unknown>; | ||
export type HttpMethod = z.infer<typeof httpMethod>; | ||
export type HttpMethods = z.infer<typeof httpMethods>; | ||
export declare const inSourceConfig: z.ZodObject<z.objectUtil.extendShape<Pick<{ | ||
@@ -46,4 +51,5 @@ externalNodeModules: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>; | ||
}, "name" | "externalNodeModules" | "generator" | "includedFiles" | "ignoredNodeModules" | "nodeBundler" | "nodeVersion" | "schedule" | "timeout">, { | ||
method: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodEffects<z.ZodEnum<["GET", "POST", "PUT", "PATCH", "OPTIONS", "DELETE", "HEAD"]>, "GET" | "POST" | "PUT" | "PATCH" | "OPTIONS" | "DELETE" | "HEAD", unknown>, z.ZodArray<z.ZodEffects<z.ZodEnum<["GET", "POST", "PUT", "PATCH", "OPTIONS", "DELETE", "HEAD"]>, "GET" | "POST" | "PUT" | "PATCH" | "OPTIONS" | "DELETE" | "HEAD", unknown>, "many">]>, any[], unknown>>; | ||
path: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, any[], string | string[]>>; | ||
method: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodEffects<z.ZodEnum<["GET", "POST", "PUT", "PATCH", "OPTIONS", "DELETE", "HEAD"]>, "GET" | "POST" | "PUT" | "PATCH" | "OPTIONS" | "DELETE" | "HEAD", unknown>, z.ZodArray<z.ZodEffects<z.ZodEnum<["GET", "POST", "PUT", "PATCH", "OPTIONS", "DELETE", "HEAD"]>, "GET" | "POST" | "PUT" | "PATCH" | "OPTIONS" | "DELETE" | "HEAD", unknown>, "many">]>, ("GET" | "POST" | "PUT" | "PATCH" | "OPTIONS" | "DELETE" | "HEAD")[], unknown>>; | ||
path: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, string[], string | string[]>>; | ||
excludedPath: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, string[], string | string[]>>; | ||
preferStatic: z.ZodCatch<z.ZodOptional<z.ZodBoolean>>; | ||
@@ -76,3 +82,3 @@ rateLimit: z.ZodCatch<z.ZodOptional<z.ZodObject<z.objectUtil.extendShape<z.objectUtil.extendShape<{ | ||
name?: string | undefined; | ||
path?: any[] | undefined; | ||
path?: string[] | undefined; | ||
externalNodeModules?: string[] | undefined; | ||
@@ -86,4 +92,5 @@ generator?: string | undefined; | ||
timeout?: number | undefined; | ||
method?: ("GET" | "POST" | "PUT" | "PATCH" | "OPTIONS" | "DELETE" | "HEAD")[] | undefined; | ||
excludedPath?: string[] | undefined; | ||
preferStatic?: boolean | undefined; | ||
method?: any[] | undefined; | ||
rateLimit?: { | ||
@@ -108,4 +115,5 @@ windowLimit: number; | ||
timeout?: unknown; | ||
method?: unknown; | ||
excludedPath?: string | string[] | undefined; | ||
preferStatic?: unknown; | ||
method?: unknown; | ||
rateLimit?: unknown; | ||
@@ -142,3 +150,3 @@ }>; | ||
name?: string | undefined; | ||
path?: any[] | undefined; | ||
path?: string[] | undefined; | ||
externalNodeModules?: string[] | undefined; | ||
@@ -152,4 +160,5 @@ generator?: string | undefined; | ||
timeout?: number | undefined; | ||
method?: ("GET" | "POST" | "PUT" | "PATCH" | "OPTIONS" | "DELETE" | "HEAD")[] | undefined; | ||
excludedPath?: string[] | undefined; | ||
preferStatic?: boolean | undefined; | ||
method?: any[] | undefined; | ||
rateLimit?: { | ||
@@ -156,0 +165,0 @@ windowLimit: number; |
@@ -7,2 +7,3 @@ import { dirname } from 'path'; | ||
import { rateLimit } from '../../../rate_limit.js'; | ||
import { ensureArray } from '../../../utils/ensure_array.js'; | ||
import { FunctionBundlingUserError } from '../../../utils/error.js'; | ||
@@ -17,4 +18,4 @@ import { getRoutes } from '../../../utils/routes.js'; | ||
export const IN_SOURCE_CONFIG_MODULE = '@netlify/functions'; | ||
const ensureArray = (input) => (Array.isArray(input) ? input : [input]); | ||
const httpMethods = z.preprocess((input) => (typeof input === 'string' ? input.toUpperCase() : input), z.enum(['GET', 'POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE', 'HEAD'])); | ||
const httpMethod = z.enum(['GET', 'POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE', 'HEAD']); | ||
const httpMethods = z.preprocess((input) => (typeof input === 'string' ? input.toUpperCase() : input), httpMethod); | ||
const path = z.string().startsWith('/', { message: "Must start with a '/'" }); | ||
@@ -44,2 +45,6 @@ export const inSourceConfig = functionConfig | ||
.optional(), | ||
excludedPath: z | ||
.union([path, z.array(path)], { errorMap: () => ({ message: 'Must be a string or array of strings' }) }) | ||
.transform(ensureArray) | ||
.optional(), | ||
preferStatic: z.boolean().optional().catch(undefined), | ||
@@ -97,8 +102,8 @@ rateLimit: rateLimit.optional().catch(undefined), | ||
result.config = data; | ||
result.routes = getRoutes({ | ||
functionName, | ||
result.excludedRoutes = getRoutes(functionName, data.excludedPath); | ||
result.routes = getRoutes(functionName, data.path).map((route) => ({ | ||
...route, | ||
methods: data.method ?? [], | ||
path: data.path, | ||
preferStatic: data.preferStatic, | ||
}); | ||
prefer_static: data.preferStatic || undefined, | ||
})); | ||
} | ||
@@ -105,0 +110,0 @@ else { |
import { FunctionArchive } from '../function.js'; | ||
import { RuntimeName } from '../runtimes/runtime.js'; | ||
import type { Route } from './routes.js'; | ||
import type { ExtendedRoute, Route } from './routes.js'; | ||
export type FunctionResult = Omit<FunctionArchive, 'runtime'> & { | ||
routes?: Route[]; | ||
routes?: ExtendedRoute[]; | ||
excludedRoutes?: Route[]; | ||
runtime: RuntimeName; | ||
@@ -7,0 +8,0 @@ schedule?: string; |
@@ -8,2 +8,3 @@ import { removeUndefined } from './remove_undefined.js'; | ||
routes: archive.staticAnalysisResult?.routes, | ||
excludedRoutes: archive.staticAnalysisResult?.excludedRoutes, | ||
runtime: archive.runtime.name, | ||
@@ -10,0 +11,0 @@ schedule: archive.staticAnalysisResult?.config?.schedule ?? archive?.config?.schedule, |
export type Route = { | ||
pattern: string; | ||
methods: string[]; | ||
prefer_static?: boolean; | ||
} & ({ | ||
@@ -10,8 +8,6 @@ literal: string; | ||
}); | ||
interface GetRoutesOptions { | ||
functionName: string; | ||
methods: string[]; | ||
path: unknown; | ||
preferStatic?: boolean; | ||
} | ||
export type ExtendedRoute = Route & { | ||
methods?: string[]; | ||
prefer_static?: boolean; | ||
}; | ||
/** | ||
@@ -21,3 +17,2 @@ * Takes a `path` declaration, normalizes it into an array, and processes the | ||
*/ | ||
export declare const getRoutes: ({ functionName, methods, path: pathOrPaths, preferStatic, }: GetRoutesOptions) => Route[]; | ||
export {}; | ||
export declare const getRoutes: (functionName: string, pathOrPaths: unknown) => ExtendedRoute[]; |
@@ -17,3 +17,3 @@ import { RUNTIME } from '../runtimes/runtime.js'; | ||
*/ | ||
const getRoute = ({ functionName, methods, path, preferStatic }) => { | ||
const getRoute = (functionName, path) => { | ||
if (typeof path !== 'string') { | ||
@@ -32,3 +32,3 @@ throw new FunctionBundlingUserError(`'path' property must be a string, found '${JSON.stringify(path)}'`, { | ||
if (isPathLiteral(path)) { | ||
return { pattern: path, literal: path, methods, prefer_static: preferStatic || undefined }; | ||
return { pattern: path, literal: path }; | ||
} | ||
@@ -44,3 +44,3 @@ try { | ||
const normalizedRegex = `^${regex}\\/?$`; | ||
return { pattern: path, expression: normalizedRegex, methods, prefer_static: preferStatic || undefined }; | ||
return { pattern: path, expression: normalizedRegex }; | ||
} | ||
@@ -58,3 +58,3 @@ catch { | ||
*/ | ||
export const getRoutes = ({ functionName, methods, path: pathOrPaths, preferStatic = false, }) => { | ||
export const getRoutes = (functionName, pathOrPaths) => { | ||
if (!pathOrPaths) { | ||
@@ -64,11 +64,4 @@ return []; | ||
const paths = [...new Set(Array.isArray(pathOrPaths) ? pathOrPaths : [pathOrPaths])]; | ||
const routes = paths | ||
.map((path) => getRoute({ | ||
functionName, | ||
methods, | ||
path, | ||
preferStatic, | ||
})) | ||
.filter(nonNullable); | ||
const routes = paths.map((path) => getRoute(functionName, path)).filter(nonNullable); | ||
return routes; | ||
}; |
@@ -23,3 +23,4 @@ import { ArchiveFormat } from './archive.js'; | ||
export declare const zipFunctions: (relativeSrcFolders: string | string[], destFolder: string, { archiveFormat, basePath, config, configFileDirectories, featureFlags: inputFeatureFlags, manifest, parallelLimit, repositoryRoot, systemLog, debug, internalSrcFolder, }?: ZipFunctionsOptions) => Promise<(Omit<import("./function.js").FunctionArchive, "runtime"> & { | ||
routes?: import("./utils/routes.js").Route[] | undefined; | ||
routes?: import("./utils/routes.js").ExtendedRoute[] | undefined; | ||
excludedRoutes?: import("./utils/routes.js").Route[] | undefined; | ||
runtime: import("./main.js").RuntimeName; | ||
@@ -26,0 +27,0 @@ schedule?: string | undefined; |
{ | ||
"name": "@netlify/zip-it-and-ship-it", | ||
"version": "9.35.1", | ||
"version": "9.36.0", | ||
"description": "Zip it and ship it", | ||
@@ -108,3 +108,3 @@ "main": "./dist/main.js", | ||
}, | ||
"gitHead": "e4464a74add778cb61ff06702ef3a43367a930c3" | ||
"gitHead": "4a5a503555b806ef711031834f563aa06773817e" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
260637
175
5688