@netlify/zip-it-and-ship-it 9.35.1 → 9.37.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/main.d.ts CHANGED
@@ -5,6 +5,8 @@ import { RuntimeName } from './runtimes/runtime.js';
5
5
  export { Config, FunctionConfig } from './config.js';
6
6
  export { zipFunction, zipFunctions, ZipFunctionOptions, ZipFunctionsOptions } from './zip.js';
7
7
  export { ArchiveFormat, ARCHIVE_FORMAT } from './archive.js';
8
+ export type { TrafficRules } from './rate_limit.js';
9
+ export type { ExtendedRoute, Route } from './utils/routes.js';
8
10
  export { NodeBundlerName, NODE_BUNDLER } from './runtimes/node/bundlers/types.js';
9
11
  export { RuntimeName, RUNTIME } from './runtimes/runtime.js';
10
12
  export { ModuleFormat, MODULE_FORMAT } from './runtimes/node/utils/module_format.js';
@@ -1,14 +1,15 @@
1
1
  import type { InvocationMode } from './function.js';
2
2
  import type { TrafficRules } from './rate_limit.js';
3
3
  import type { FunctionResult } from './utils/format_result.js';
4
- import type { Route } from './utils/routes.js';
4
+ import type { ExtendedRoute, Route } from './utils/routes.js';
5
5
  interface ManifestFunction {
6
6
  buildData?: Record<string, unknown>;
7
7
  invocationMode?: InvocationMode;
8
8
  mainFile: string;
9
9
  name: string;
10
10
  path: string;
11
- routes?: Route[];
11
+ routes?: ExtendedRoute[];
12
+ excludedRoutes?: Route[];
12
13
  runtime: string;
13
14
  runtimeVersion?: string;
14
15
  schedule?: string;
@@ -2,19 +2,24 @@ import type { ArgumentPlaceholder, Expression, SpreadElement, JSXNamespacedName
2
2
  import { z } from 'zod';
3
3
  import { FunctionConfig } from '../../../config.js';
4
4
  import { InvocationMode } from '../../../function.js';
5
- import { Route } from '../../../utils/routes.js';
5
+ import { ExtendedRoute, Route } from '../../../utils/routes.js';
6
6
  import type { ModuleFormat } from '../utils/module_format.js';
7
7
  export declare const IN_SOURCE_CONFIG_MODULE = "@netlify/functions";
8
8
  export interface StaticAnalysisResult {
9
9
  config: InSourceConfig;
10
+ excludedRoutes?: Route[];
10
11
  inputModuleFormat?: ModuleFormat;
11
12
  invocationMode?: InvocationMode;
12
- routes?: Route[];
13
+ routes?: ExtendedRoute[];
13
14
  runtimeAPIVersion?: number;
14
15
  }
15
16
  interface FindISCDeclarationsOptions {
16
17
  functionName: string;
17
18
  }
19
+ declare const httpMethod: z.ZodEnum<["GET", "POST", "PUT", "PATCH", "OPTIONS", "DELETE", "HEAD"]>;
20
+ declare const httpMethods: z.ZodEffects<z.ZodEnum<["GET", "POST", "PUT", "PATCH", "OPTIONS", "DELETE", "HEAD"]>, "GET" | "POST" | "PUT" | "PATCH" | "OPTIONS" | "DELETE" | "HEAD", unknown>;
21
+ export type HttpMethod = z.infer<typeof httpMethod>;
22
+ export type HttpMethods = z.infer<typeof httpMethods>;
18
23
  export declare const inSourceConfig: z.ZodObject<z.objectUtil.extendShape<Pick<{
19
24
  externalNodeModules: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
20
25
  generator: z.ZodCatch<z.ZodOptional<z.ZodString>>;
@@ -40,8 +45,9 @@ export declare const inSourceConfig: z.ZodObject<z.objectUtil.extendShape<Pick<{
40
45
  readonly ESM: "esm";
41
46
  }>>>;
42
47
  }, "name" | "externalNodeModules" | "generator" | "includedFiles" | "ignoredNodeModules" | "nodeBundler" | "nodeVersion" | "schedule" | "timeout">, {
43
- 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>>;
44
- path: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, any[], string | string[]>>;
48
+ 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>>;
49
+ path: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, string[], string | string[]>>;
50
+ excludedPath: z.ZodOptional<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, string[], string | string[]>>;
45
51
  preferStatic: z.ZodCatch<z.ZodOptional<z.ZodBoolean>>;
46
52
  rateLimit: z.ZodCatch<z.ZodOptional<z.ZodObject<z.objectUtil.extendShape<z.objectUtil.extendShape<{
47
53
  action: z.ZodOptional<z.ZodEnum<["rate_limit", "rewrite"]>>;
@@ -69,7 +75,7 @@ export declare const inSourceConfig: z.ZodObject<z.objectUtil.extendShape<Pick<{
69
75
  }>>>;
70
76
  }>, "strip", z.ZodTypeAny, {
71
77
  name?: string | undefined;
72
- path?: any[] | undefined;
78
+ path?: string[] | undefined;
73
79
  externalNodeModules?: string[] | undefined;
74
80
  generator?: string | undefined;
75
81
  includedFiles?: string[] | undefined;
@@ -78,8 +84,9 @@ export declare const inSourceConfig: z.ZodObject<z.objectUtil.extendShape<Pick<{
78
84
  nodeVersion?: string | undefined;
79
85
  schedule?: string | undefined;
80
86
  timeout?: number | undefined;
87
+ method?: ("GET" | "POST" | "PUT" | "PATCH" | "OPTIONS" | "DELETE" | "HEAD")[] | undefined;
88
+ excludedPath?: string[] | undefined;
81
89
  preferStatic?: boolean | undefined;
82
- method?: any[] | undefined;
83
90
  rateLimit?: {
84
91
  windowLimit: number;
85
92
  windowSize: number;
@@ -99,8 +106,9 @@ export declare const inSourceConfig: z.ZodObject<z.objectUtil.extendShape<Pick<{
99
106
  nodeVersion?: unknown;
100
107
  schedule?: unknown;
101
108
  timeout?: unknown;
102
- preferStatic?: unknown;
103
109
  method?: unknown;
110
+ excludedPath?: string | string[] | undefined;
111
+ preferStatic?: unknown;
104
112
  rateLimit?: unknown;
105
113
  }>;
106
114
  export type InSourceConfig = z.infer<typeof inSourceConfig>;
@@ -132,7 +140,7 @@ export declare const augmentFunctionConfig: (mainFile: string, tomlConfig: Funct
132
140
  nodeModuleFormat?: "cjs" | "esm" | undefined;
133
141
  } & {
134
142
  name?: string | undefined;
135
- path?: any[] | undefined;
143
+ path?: string[] | undefined;
136
144
  externalNodeModules?: string[] | undefined;
137
145
  generator?: string | undefined;
138
146
  includedFiles?: string[] | undefined;
@@ -141,8 +149,9 @@ export declare const augmentFunctionConfig: (mainFile: string, tomlConfig: Funct
141
149
  nodeVersion?: string | undefined;
142
150
  schedule?: string | undefined;
143
151
  timeout?: number | undefined;
152
+ method?: ("GET" | "POST" | "PUT" | "PATCH" | "OPTIONS" | "DELETE" | "HEAD")[] | undefined;
153
+ excludedPath?: string[] | undefined;
144
154
  preferStatic?: boolean | undefined;
145
- method?: any[] | undefined;
146
155
  rateLimit?: {
147
156
  windowLimit: number;
148
157
  windowSize: number;
@@ -4,6 +4,7 @@ import { z } from 'zod';
4
4
  import { functionConfig } from '../../../config.js';
5
5
  import { INVOCATION_MODE } from '../../../function.js';
6
6
  import { rateLimit } from '../../../rate_limit.js';
7
+ import { ensureArray } from '../../../utils/ensure_array.js';
7
8
  import { FunctionBundlingUserError } from '../../../utils/error.js';
8
9
  import { getRoutes } from '../../../utils/routes.js';
9
10
  import { RUNTIME } from '../../runtime.js';
@@ -13,8 +14,8 @@ import { getImports } from '../parser/imports.js';
13
14
  import { safelyParseSource, safelyReadSource } from '../parser/index.js';
14
15
  import { parse as parseSchedule } from './properties/schedule.js';
15
16
  export const IN_SOURCE_CONFIG_MODULE = '@netlify/functions';
16
- const ensureArray = (input) => (Array.isArray(input) ? input : [input]);
17
- const httpMethods = z.preprocess((input) => (typeof input === 'string' ? input.toUpperCase() : input), z.enum(['GET', 'POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE', 'HEAD']));
17
+ const httpMethod = z.enum(['GET', 'POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE', 'HEAD']);
18
+ const httpMethods = z.preprocess((input) => (typeof input === 'string' ? input.toUpperCase() : input), httpMethod);
18
19
  const path = z.string().startsWith('/', { message: "Must start with a '/'" });
19
20
  export const inSourceConfig = functionConfig
20
21
  .pick({
@@ -39,6 +40,10 @@ export const inSourceConfig = functionConfig
39
40
  .union([path, z.array(path)], { errorMap: () => ({ message: 'Must be a string or array of strings' }) })
40
41
  .transform(ensureArray)
41
42
  .optional(),
43
+ excludedPath: z
44
+ .union([path, z.array(path)], { errorMap: () => ({ message: 'Must be a string or array of strings' }) })
45
+ .transform(ensureArray)
46
+ .optional(),
42
47
  preferStatic: z.boolean().optional().catch(undefined),
43
48
  rateLimit: rateLimit.optional().catch(undefined),
44
49
  });
@@ -91,12 +96,12 @@ export const parseSource = (source, { functionName }) => {
91
96
  const { data, error, success } = inSourceConfig.safeParse(configExport);
92
97
  if (success) {
93
98
  result.config = data;
94
- result.routes = getRoutes({
95
- functionName,
99
+ result.excludedRoutes = getRoutes(functionName, data.excludedPath);
100
+ result.routes = getRoutes(functionName, data.path).map((route) => ({
101
+ ...route,
96
102
  methods: data.method ?? [],
97
- path: data.path,
98
- preferStatic: data.preferStatic,
99
- });
103
+ prefer_static: data.preferStatic || undefined,
104
+ }));
100
105
  }
101
106
  else {
102
107
  // TODO: Handle multiple errors.
@@ -0,0 +1 @@
1
+ export declare const ensureArray: <T>(input: T | T[]) => T[];
@@ -0,0 +1 @@
1
+ export const ensureArray = (input) => (Array.isArray(input) ? input : [input]);
@@ -1,8 +1,9 @@
1
1
  import { FunctionArchive } from '../function.js';
2
2
  import { RuntimeName } from '../runtimes/runtime.js';
3
- import type { Route } from './routes.js';
3
+ import type { ExtendedRoute, Route } from './routes.js';
4
4
  export type FunctionResult = Omit<FunctionArchive, 'runtime'> & {
5
- routes?: Route[];
5
+ routes?: ExtendedRoute[];
6
+ excludedRoutes?: Route[];
6
7
  runtime: RuntimeName;
7
8
  schedule?: string;
8
9
  runtimeAPIVersion?: number;
@@ -5,6 +5,7 @@ export const formatZipResult = (archive) => {
5
5
  ...archive,
6
6
  staticAnalysisResult: undefined,
7
7
  routes: archive.staticAnalysisResult?.routes,
8
+ excludedRoutes: archive.staticAnalysisResult?.excludedRoutes,
8
9
  runtime: archive.runtime.name,
9
10
  schedule: archive.staticAnalysisResult?.config?.schedule ?? archive?.config?.schedule,
10
11
  runtimeAPIVersion: archive.staticAnalysisResult?.runtimeAPIVersion,
@@ -1,21 +1,16 @@
1
1
  export type Route = {
2
2
  pattern: string;
3
- methods: string[];
4
- prefer_static?: boolean;
5
3
  } & ({
6
4
  literal: string;
7
5
  } | {
8
6
  expression: string;
9
7
  });
10
- interface GetRoutesOptions {
11
- functionName: string;
12
- methods: string[];
13
- path: unknown;
14
- preferStatic?: boolean;
15
- }
8
+ export type ExtendedRoute = Route & {
9
+ methods?: string[];
10
+ prefer_static?: boolean;
11
+ };
16
12
  /**
17
13
  * Takes a `path` declaration, normalizes it into an array, and processes the
18
14
  * individual elements to obtain an array of `Route` expressions.
19
15
  */
20
- export declare const getRoutes: ({ functionName, methods, path: pathOrPaths, preferStatic, }: GetRoutesOptions) => Route[];
21
- export {};
16
+ export declare const getRoutes: (functionName: string, pathOrPaths: unknown) => ExtendedRoute[];
@@ -14,7 +14,7 @@ const isPathLiteral = (path) => {
14
14
  * Takes an element from a `path` declaration and returns a Route element that
15
15
  * represents it.
16
16
  */
17
- const getRoute = ({ functionName, methods, path, preferStatic }) => {
17
+ const getRoute = (functionName, path) => {
18
18
  if (typeof path !== 'string') {
19
19
  throw new FunctionBundlingUserError(`'path' property must be a string, found '${JSON.stringify(path)}'`, {
20
20
  functionName,
@@ -28,7 +28,7 @@ const getRoute = ({ functionName, methods, path, preferStatic }) => {
28
28
  });
29
29
  }
30
30
  if (isPathLiteral(path)) {
31
- return { pattern: path, literal: path, methods, prefer_static: preferStatic || undefined };
31
+ return { pattern: path, literal: path };
32
32
  }
33
33
  try {
34
34
  const pattern = new ExtendedURLPattern({ pathname: path });
@@ -39,7 +39,7 @@ const getRoute = ({ functionName, methods, path, preferStatic }) => {
39
39
  // trailing slash, so that a declaration of `path: "/foo"` matches requests
40
40
  // for both `/foo` and `/foo/`.
41
41
  const normalizedRegex = `^${regex}\\/?$`;
42
- return { pattern: path, expression: normalizedRegex, methods, prefer_static: preferStatic || undefined };
42
+ return { pattern: path, expression: normalizedRegex };
43
43
  }
44
44
  catch {
45
45
  throw new FunctionBundlingUserError(`'${path}' is not a valid path according to the URLPattern specification`, {
@@ -52,18 +52,11 @@ const getRoute = ({ functionName, methods, path, preferStatic }) => {
52
52
  * Takes a `path` declaration, normalizes it into an array, and processes the
53
53
  * individual elements to obtain an array of `Route` expressions.
54
54
  */
55
- export const getRoutes = ({ functionName, methods, path: pathOrPaths, preferStatic = false, }) => {
55
+ export const getRoutes = (functionName, pathOrPaths) => {
56
56
  if (!pathOrPaths) {
57
57
  return [];
58
58
  }
59
59
  const paths = [...new Set(Array.isArray(pathOrPaths) ? pathOrPaths : [pathOrPaths])];
60
- const routes = paths
61
- .map((path) => getRoute({
62
- functionName,
63
- methods,
64
- path,
65
- preferStatic,
66
- }))
67
- .filter(nonNullable);
60
+ const routes = paths.map((path) => getRoute(functionName, path)).filter(nonNullable);
68
61
  return routes;
69
62
  };
package/dist/zip.d.ts CHANGED
@@ -20,7 +20,8 @@ export type ZipFunctionsOptions = ZipFunctionOptions & {
20
20
  internalSrcFolder?: string;
21
21
  };
22
22
  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"> & {
23
- routes?: import("./utils/routes.js").Route[] | undefined;
23
+ routes?: import("./main.js").ExtendedRoute[] | undefined;
24
+ excludedRoutes?: import("./main.js").Route[] | undefined;
24
25
  runtime: import("./main.js").RuntimeName;
25
26
  schedule?: string | undefined;
26
27
  runtimeAPIVersion?: number | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/zip-it-and-ship-it",
3
- "version": "9.35.1",
3
+ "version": "9.37.0",
4
4
  "description": "Zip it and ship it",
5
5
  "main": "./dist/main.js",
6
6
  "type": "module",
@@ -105,5 +105,5 @@
105
105
  "engines": {
106
106
  "node": "^14.18.0 || >=16.0.0"
107
107
  },
108
- "gitHead": "e4464a74add778cb61ff06702ef3a43367a930c3"
108
+ "gitHead": "10e722ebad2755434933ef205672e290d810259b"
109
109
  }