@opennextjs/aws 3.1.4

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.
Files changed (175) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +94 -0
  3. package/dist/adapters/binary.d.ts +1 -0
  4. package/dist/adapters/binary.js +63 -0
  5. package/dist/adapters/cache.d.ts +96 -0
  6. package/dist/adapters/cache.js +278 -0
  7. package/dist/adapters/config/index.d.ts +27 -0
  8. package/dist/adapters/config/index.js +21 -0
  9. package/dist/adapters/config/util.d.ts +28 -0
  10. package/dist/adapters/config/util.js +84 -0
  11. package/dist/adapters/dynamo-provider.d.ts +8 -0
  12. package/dist/adapters/dynamo-provider.js +42 -0
  13. package/dist/adapters/edge-adapter.d.ts +8 -0
  14. package/dist/adapters/edge-adapter.js +54 -0
  15. package/dist/adapters/image-optimization-adapter.d.ts +4 -0
  16. package/dist/adapters/image-optimization-adapter.js +193 -0
  17. package/dist/adapters/logger.d.ts +13 -0
  18. package/dist/adapters/logger.js +51 -0
  19. package/dist/adapters/middleware.d.ts +5 -0
  20. package/dist/adapters/middleware.js +84 -0
  21. package/dist/adapters/plugins/14.1/util.d.ts +1 -0
  22. package/dist/adapters/plugins/14.1/util.js +29 -0
  23. package/dist/adapters/plugins/image-optimization/image-optimization.d.ts +11 -0
  24. package/dist/adapters/plugins/image-optimization/image-optimization.js +14 -0
  25. package/dist/adapters/plugins/image-optimization/image-optimization.replacement.d.ts +11 -0
  26. package/dist/adapters/plugins/image-optimization/image-optimization.replacement.js +22 -0
  27. package/dist/adapters/plugins/without-routing/requestHandler.d.ts +2 -0
  28. package/dist/adapters/plugins/without-routing/requestHandler.js +10 -0
  29. package/dist/adapters/revalidate.d.ts +9 -0
  30. package/dist/adapters/revalidate.js +71 -0
  31. package/dist/adapters/server-adapter.d.ts +4 -0
  32. package/dist/adapters/server-adapter.js +27 -0
  33. package/dist/adapters/util.d.ts +10 -0
  34. package/dist/adapters/util.js +28 -0
  35. package/dist/adapters/warmer-function.d.ts +12 -0
  36. package/dist/adapters/warmer-function.js +80 -0
  37. package/dist/build/bundleNextServer.d.ts +1 -0
  38. package/dist/build/bundleNextServer.js +87 -0
  39. package/dist/build/compileConfig.d.ts +3 -0
  40. package/dist/build/compileConfig.js +64 -0
  41. package/dist/build/copyTracedFiles.d.ts +1 -0
  42. package/dist/build/copyTracedFiles.js +207 -0
  43. package/dist/build/createServerBundle.d.ts +3 -0
  44. package/dist/build/createServerBundle.js +228 -0
  45. package/dist/build/edge/createEdgeBundle.d.ts +20 -0
  46. package/dist/build/edge/createEdgeBundle.js +149 -0
  47. package/dist/build/generateOutput.d.ts +2 -0
  48. package/dist/build/generateOutput.js +239 -0
  49. package/dist/build/helper.d.ts +33 -0
  50. package/dist/build/helper.js +193 -0
  51. package/dist/build/patch/patchedAsyncStorage.d.ts +5 -0
  52. package/dist/build/patch/patchedAsyncStorage.js +16 -0
  53. package/dist/build/validateConfig.d.ts +2 -0
  54. package/dist/build/validateConfig.js +76 -0
  55. package/dist/build.d.ts +7 -0
  56. package/dist/build.js +533 -0
  57. package/dist/cache/incremental/s3-lite.d.ts +3 -0
  58. package/dist/cache/incremental/s3-lite.js +72 -0
  59. package/dist/cache/incremental/s3.d.ts +3 -0
  60. package/dist/cache/incremental/s3.js +44 -0
  61. package/dist/cache/incremental/types.d.ts +34 -0
  62. package/dist/cache/incremental/types.js +1 -0
  63. package/dist/cache/next-types.d.ts +62 -0
  64. package/dist/cache/next-types.js +1 -0
  65. package/dist/cache/tag/constants.d.ts +2 -0
  66. package/dist/cache/tag/constants.js +17 -0
  67. package/dist/cache/tag/dynamodb-lite.d.ts +3 -0
  68. package/dist/cache/tag/dynamodb-lite.js +174 -0
  69. package/dist/cache/tag/dynamodb.d.ts +3 -0
  70. package/dist/cache/tag/dynamodb.js +129 -0
  71. package/dist/cache/tag/types.d.ts +11 -0
  72. package/dist/cache/tag/types.js +1 -0
  73. package/dist/converters/aws-apigw-v1.d.ts +3 -0
  74. package/dist/converters/aws-apigw-v1.js +89 -0
  75. package/dist/converters/aws-apigw-v2.d.ts +3 -0
  76. package/dist/converters/aws-apigw-v2.js +99 -0
  77. package/dist/converters/aws-cloudfront.d.ts +3 -0
  78. package/dist/converters/aws-cloudfront.js +170 -0
  79. package/dist/converters/dummy.d.ts +7 -0
  80. package/dist/converters/dummy.js +16 -0
  81. package/dist/converters/edge.d.ts +6 -0
  82. package/dist/converters/edge.js +88 -0
  83. package/dist/converters/node.d.ts +3 -0
  84. package/dist/converters/node.js +45 -0
  85. package/dist/converters/sqs-revalidate.d.ts +4 -0
  86. package/dist/converters/sqs-revalidate.js +22 -0
  87. package/dist/converters/utils.d.ts +1 -0
  88. package/dist/converters/utils.js +9 -0
  89. package/dist/core/createGenericHandler.d.ts +11 -0
  90. package/dist/core/createGenericHandler.js +16 -0
  91. package/dist/core/createMainHandler.d.ts +18 -0
  92. package/dist/core/createMainHandler.js +24 -0
  93. package/dist/core/edgeFunctionHandler.d.ts +54 -0
  94. package/dist/core/edgeFunctionHandler.js +21 -0
  95. package/dist/core/patchAsyncStorage.d.ts +1 -0
  96. package/dist/core/patchAsyncStorage.js +16 -0
  97. package/dist/core/requestHandler.d.ts +3 -0
  98. package/dist/core/requestHandler.js +162 -0
  99. package/dist/core/require-hooks.d.ts +3 -0
  100. package/dist/core/require-hooks.js +102 -0
  101. package/dist/core/resolve.d.ts +31 -0
  102. package/dist/core/resolve.js +81 -0
  103. package/dist/core/routing/cacheInterceptor.d.ts +2 -0
  104. package/dist/core/routing/cacheInterceptor.js +162 -0
  105. package/dist/core/routing/i18n/accept-header.d.ts +1 -0
  106. package/dist/core/routing/i18n/accept-header.js +101 -0
  107. package/dist/core/routing/i18n/index.d.ts +2 -0
  108. package/dist/core/routing/i18n/index.js +36 -0
  109. package/dist/core/routing/matcher.d.ts +25 -0
  110. package/dist/core/routing/matcher.js +294 -0
  111. package/dist/core/routing/middleware.d.ts +7 -0
  112. package/dist/core/routing/middleware.js +167 -0
  113. package/dist/core/routing/util.d.ts +105 -0
  114. package/dist/core/routing/util.js +415 -0
  115. package/dist/core/routingHandler.d.ts +8 -0
  116. package/dist/core/routingHandler.js +127 -0
  117. package/dist/core/util.d.ts +5 -0
  118. package/dist/core/util.js +84 -0
  119. package/dist/helpers/withCloudflare.d.ts +65 -0
  120. package/dist/helpers/withCloudflare.js +58 -0
  121. package/dist/helpers/withSST.d.ts +54 -0
  122. package/dist/helpers/withSST.js +28 -0
  123. package/dist/http/index.d.ts +2 -0
  124. package/dist/http/index.js +4 -0
  125. package/dist/http/openNextResponse.d.ts +78 -0
  126. package/dist/http/openNextResponse.js +281 -0
  127. package/dist/http/request.d.ts +12 -0
  128. package/dist/http/request.js +35 -0
  129. package/dist/http/util.d.ts +4 -0
  130. package/dist/http/util.js +34 -0
  131. package/dist/index.d.ts +2 -0
  132. package/dist/index.js +37 -0
  133. package/dist/logger.d.ts +12 -0
  134. package/dist/logger.js +13 -0
  135. package/dist/minimize-js.d.ts +1 -0
  136. package/dist/minimize-js.js +101 -0
  137. package/dist/overrides/imageLoader/host.d.ts +3 -0
  138. package/dist/overrides/imageLoader/host.js +29 -0
  139. package/dist/overrides/imageLoader/s3.d.ts +3 -0
  140. package/dist/overrides/imageLoader/s3.js +33 -0
  141. package/dist/plugins/edge.d.ts +15 -0
  142. package/dist/plugins/edge.js +157 -0
  143. package/dist/plugins/replacement.d.ts +42 -0
  144. package/dist/plugins/replacement.js +74 -0
  145. package/dist/plugins/resolve.d.ts +18 -0
  146. package/dist/plugins/resolve.js +45 -0
  147. package/dist/queue/sqs-lite.d.ts +3 -0
  148. package/dist/queue/sqs-lite.js +52 -0
  149. package/dist/queue/sqs.d.ts +3 -0
  150. package/dist/queue/sqs.js +20 -0
  151. package/dist/queue/types.d.ts +12 -0
  152. package/dist/queue/types.js +1 -0
  153. package/dist/types/aws-lambda.d.ts +22 -0
  154. package/dist/types/aws-lambda.js +1 -0
  155. package/dist/types/next-types.d.ts +155 -0
  156. package/dist/types/next-types.js +2 -0
  157. package/dist/types/open-next.d.ts +303 -0
  158. package/dist/types/open-next.js +1 -0
  159. package/dist/utils/error.d.ts +23 -0
  160. package/dist/utils/error.js +32 -0
  161. package/dist/utils/fetch.d.ts +2 -0
  162. package/dist/utils/fetch.js +23 -0
  163. package/dist/utils/promise.d.ts +18 -0
  164. package/dist/utils/promise.js +48 -0
  165. package/dist/utils/stream.d.ts +5 -0
  166. package/dist/utils/stream.js +30 -0
  167. package/dist/wrappers/aws-lambda-streaming.d.ts +7 -0
  168. package/dist/wrappers/aws-lambda-streaming.js +88 -0
  169. package/dist/wrappers/aws-lambda.d.ts +7 -0
  170. package/dist/wrappers/aws-lambda.js +39 -0
  171. package/dist/wrappers/cloudflare.d.ts +11 -0
  172. package/dist/wrappers/cloudflare.js +20 -0
  173. package/dist/wrappers/node.d.ts +7 -0
  174. package/dist/wrappers/node.js +57 -0
  175. package/package.json +66 -0
@@ -0,0 +1,20 @@
1
+ import { SendMessageCommand, SQSClient } from "@aws-sdk/client-sqs";
2
+ import { awsLogger } from "../adapters/logger";
3
+ // Expected environment variables
4
+ const { REVALIDATION_QUEUE_REGION, REVALIDATION_QUEUE_URL } = process.env;
5
+ const sqsClient = new SQSClient({
6
+ region: REVALIDATION_QUEUE_REGION,
7
+ logger: awsLogger,
8
+ });
9
+ const queue = {
10
+ send: async ({ MessageBody, MessageDeduplicationId, MessageGroupId }) => {
11
+ await sqsClient.send(new SendMessageCommand({
12
+ QueueUrl: REVALIDATION_QUEUE_URL,
13
+ MessageBody: JSON.stringify(MessageBody),
14
+ MessageDeduplicationId,
15
+ MessageGroupId,
16
+ }));
17
+ },
18
+ name: "sqs",
19
+ };
20
+ export default queue;
@@ -0,0 +1,12 @@
1
+ export interface QueueMessage {
2
+ MessageDeduplicationId: string;
3
+ MessageBody: {
4
+ host: string;
5
+ url: string;
6
+ };
7
+ MessageGroupId: string;
8
+ }
9
+ export interface Queue {
10
+ send(message: QueueMessage): Promise<void>;
11
+ name: string;
12
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { APIGatewayProxyEventV2, Context } from "aws-lambda";
4
+ import { Writable } from "stream";
5
+ export interface ResponseStream extends Writable {
6
+ getBufferedData(): Buffer;
7
+ setContentType(contentType: string): void;
8
+ }
9
+ type Handler = (event: APIGatewayProxyEventV2, responseStream: ResponseStream, context: Context) => Promise<any>;
10
+ interface Metadata {
11
+ statusCode: number;
12
+ headers: Record<string, string>;
13
+ }
14
+ declare global {
15
+ namespace awslambda {
16
+ function streamifyResponse(handler: Handler): Handler;
17
+ module HttpResponseStream {
18
+ function from(res: Writable, metadata: Metadata): ResponseStream;
19
+ }
20
+ }
21
+ }
22
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,155 @@
1
+ import type { IncomingMessage, OpenNextNodeResponse } from "../http/index.js";
2
+ import { InternalEvent } from "./open-next";
3
+ type RemotePattern = {
4
+ protocol?: "http" | "https";
5
+ hostname: string;
6
+ port?: string;
7
+ pathname?: string;
8
+ };
9
+ declare type ImageFormat = "image/avif" | "image/webp";
10
+ type ImageConfigComplete = {
11
+ deviceSizes: number[];
12
+ imageSizes: number[];
13
+ path: string;
14
+ loaderFile: string;
15
+ domains: string[];
16
+ disableStaticImages: boolean;
17
+ minimumCacheTTL: number;
18
+ formats: ImageFormat[];
19
+ dangerouslyAllowSVG: boolean;
20
+ contentSecurityPolicy: string;
21
+ contentDispositionType: "inline" | "attachment";
22
+ remotePatterns: RemotePattern[];
23
+ unoptimized: boolean;
24
+ };
25
+ type ImageConfig = Partial<ImageConfigComplete>;
26
+ export type RouteHas = {
27
+ type: "header" | "query" | "cookie";
28
+ key: string;
29
+ value?: string;
30
+ } | {
31
+ type: "host";
32
+ key?: undefined;
33
+ value: string;
34
+ };
35
+ export type Rewrite = {
36
+ source: string;
37
+ destination: string;
38
+ basePath?: false;
39
+ locale?: false;
40
+ has?: RouteHas[];
41
+ missing?: RouteHas[];
42
+ };
43
+ export type Header = {
44
+ source: string;
45
+ regex: string;
46
+ basePath?: false;
47
+ locale?: false;
48
+ headers: Array<{
49
+ key: string;
50
+ value: string;
51
+ }>;
52
+ has?: RouteHas[];
53
+ missing?: RouteHas[];
54
+ };
55
+ export interface i18nConfig {
56
+ locales: string[];
57
+ defaultLocale: string;
58
+ }
59
+ export interface NextConfig {
60
+ basePath?: string;
61
+ trailingSlash?: boolean;
62
+ skipTrailingSlashRedirect?: boolean;
63
+ i18n?: i18nConfig;
64
+ experimental: {
65
+ serverActions?: boolean;
66
+ appDir?: boolean;
67
+ };
68
+ images: ImageConfig;
69
+ }
70
+ export interface RouteDefinition {
71
+ page: string;
72
+ regex: string;
73
+ }
74
+ export interface DataRouteDefinition {
75
+ page: string;
76
+ dataRouteRegex: string;
77
+ routeKeys?: string;
78
+ }
79
+ export interface RewriteDefinition {
80
+ source: string;
81
+ destination: string;
82
+ has?: RouteHas[];
83
+ missing?: RouteHas[];
84
+ regex: string;
85
+ locale?: false;
86
+ }
87
+ export interface RedirectDefinition extends RewriteDefinition {
88
+ internal?: boolean;
89
+ statusCode?: number;
90
+ }
91
+ export interface RoutesManifest {
92
+ basePath?: string;
93
+ dynamicRoutes: RouteDefinition[];
94
+ staticRoutes: RouteDefinition[];
95
+ dataRoutes: DataRouteDefinition[];
96
+ rewrites: {
97
+ beforeFiles: RewriteDefinition[];
98
+ afterFiles: RewriteDefinition[];
99
+ fallback: RewriteDefinition[];
100
+ } | RewriteDefinition[];
101
+ redirects: RedirectDefinition[];
102
+ headers?: Header[];
103
+ i18n?: {
104
+ locales: string[];
105
+ };
106
+ }
107
+ export interface MiddlewareInfo {
108
+ files: string[];
109
+ paths?: string[];
110
+ name: string;
111
+ page: string;
112
+ matchers: {
113
+ regexp: string;
114
+ originalSource: string;
115
+ }[];
116
+ wasm: {
117
+ filePath: string;
118
+ name: string;
119
+ }[];
120
+ assets: {
121
+ filePath: string;
122
+ name: string;
123
+ }[];
124
+ }
125
+ export interface MiddlewareManifest {
126
+ sortedMiddleware: string[];
127
+ middleware: {
128
+ [key: string]: MiddlewareInfo;
129
+ };
130
+ functions: {
131
+ [key: string]: MiddlewareInfo;
132
+ };
133
+ version: number;
134
+ }
135
+ export interface PrerenderManifest {
136
+ routes: Record<string, {
137
+ initialRevalidateSeconds: number | false;
138
+ }>;
139
+ dynamicRoutes: {
140
+ [route: string]: {
141
+ routeRegex: string;
142
+ fallback: string | false | null;
143
+ dataRouteRegex: string;
144
+ };
145
+ };
146
+ }
147
+ export type Options = {
148
+ internalEvent: InternalEvent;
149
+ buildId: string;
150
+ isExternalRewrite?: boolean;
151
+ };
152
+ export interface PluginHandler {
153
+ (req: IncomingMessage, res: OpenNextNodeResponse, options: Options): Promise<OpenNextNodeResponse | undefined>;
154
+ }
155
+ export {};
@@ -0,0 +1,2 @@
1
+ // NOTE: add more next config typings as they become relevant
2
+ export {};
@@ -0,0 +1,303 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import type { Readable } from "node:stream";
5
+ import type { ReadableStream } from "node:stream/web";
6
+ import type { StreamCreator } from "../http/index.js";
7
+ import type { WarmerEvent, WarmerResponse } from "../adapters/warmer-function";
8
+ import type { IncrementalCache } from "../cache/incremental/types";
9
+ import type { TagCache } from "../cache/tag/types";
10
+ import type { Queue } from "../queue/types";
11
+ export type BaseEventOrResult<T extends string = string> = {
12
+ type: T;
13
+ };
14
+ export type InternalEvent = {
15
+ readonly method: string;
16
+ readonly rawPath: string;
17
+ readonly url: string;
18
+ readonly body?: Buffer;
19
+ readonly headers: Record<string, string>;
20
+ readonly query: Record<string, string | string[]>;
21
+ readonly cookies: Record<string, string>;
22
+ readonly remoteAddress: string;
23
+ } & BaseEventOrResult<"core">;
24
+ export type InternalResult = {
25
+ statusCode: number;
26
+ headers: Record<string, string | string[]>;
27
+ body: ReadableStream;
28
+ isBase64Encoded: boolean;
29
+ } & BaseEventOrResult<"core">;
30
+ export interface DangerousOptions {
31
+ /**
32
+ * The tag cache is used for revalidateTags and revalidatePath.
33
+ * @default false
34
+ */
35
+ disableTagCache?: boolean;
36
+ /**
37
+ * The incremental cache is used for ISR and SSG.
38
+ * Disable this only if you use only SSR
39
+ * @default false
40
+ */
41
+ disableIncrementalCache?: boolean;
42
+ /**
43
+ * Enable the cache interception.
44
+ * Every request will go through the cache interceptor, if it is found in the cache, it will be returned without going through NextServer.
45
+ * Not every feature is covered by the cache interceptor and it should fallback to the NextServer if the cache is not found.
46
+ * @default false
47
+ */
48
+ enableCacheInterception?: boolean;
49
+ /**
50
+ * Function to determine which headers or cookies takes precedence.
51
+ * By default, the middleware headers and cookies will override the handler headers and cookies.
52
+ * This is executed for every request and after next config headers and middleware has executed.
53
+ */
54
+ headersAndCookiesPriority?: (event: InternalEvent) => "middleware" | "handler";
55
+ }
56
+ export type BaseOverride = {
57
+ name: string;
58
+ };
59
+ export type LazyLoadedOverride<T extends BaseOverride> = () => Promise<T>;
60
+ export type OpenNextHandler<E extends BaseEventOrResult = InternalEvent, R extends BaseEventOrResult = InternalResult> = (event: E, responseStream?: StreamCreator) => Promise<R>;
61
+ export type Converter<E extends BaseEventOrResult = InternalEvent, R extends BaseEventOrResult = InternalResult> = BaseOverride & {
62
+ convertFrom: (event: any) => Promise<E>;
63
+ convertTo: (result: R, originalRequest?: any) => Promise<any>;
64
+ };
65
+ export type WrapperHandler<E extends BaseEventOrResult = InternalEvent, R extends BaseEventOrResult = InternalResult> = (handler: OpenNextHandler<E, R>, converter: Converter<E, R>) => Promise<(...args: any[]) => any>;
66
+ export type Wrapper<E extends BaseEventOrResult = InternalEvent, R extends BaseEventOrResult = InternalResult> = BaseOverride & {
67
+ wrapper: WrapperHandler<E, R>;
68
+ supportStreaming: boolean;
69
+ edgeRuntime?: boolean;
70
+ };
71
+ export type Warmer = BaseOverride & {
72
+ invoke: (warmerId: string) => Promise<void>;
73
+ };
74
+ export type ImageLoader = BaseOverride & {
75
+ load: (url: string) => Promise<{
76
+ body?: Readable;
77
+ contentType?: string;
78
+ cacheControl?: string;
79
+ }>;
80
+ };
81
+ export interface Origin {
82
+ host: string;
83
+ protocol: "http" | "https";
84
+ port?: number;
85
+ customHeaders?: Record<string, string>;
86
+ }
87
+ export type OriginResolver = BaseOverride & {
88
+ resolve: (path: string) => Promise<Origin | false>;
89
+ };
90
+ export type IncludedWrapper = "aws-lambda" | "aws-lambda-streaming" | "node" | "cloudflare";
91
+ export type IncludedConverter = "aws-apigw-v2" | "aws-apigw-v1" | "aws-cloudfront" | "edge" | "node" | "sqs-revalidate" | "dummy";
92
+ export type IncludedQueue = "sqs" | "sqs-lite";
93
+ export type IncludedIncrementalCache = "s3" | "s3-lite";
94
+ export type IncludedTagCache = "dynamodb" | "dynamodb-lite";
95
+ export type IncludedImageLoader = "s3" | "host";
96
+ export interface DefaultOverrideOptions<E extends BaseEventOrResult = InternalEvent, R extends BaseEventOrResult = InternalResult> {
97
+ /**
98
+ * This is the main entrypoint of your app.
99
+ * @default "aws-lambda"
100
+ */
101
+ wrapper?: IncludedWrapper | LazyLoadedOverride<Wrapper<E, R>>;
102
+ /**
103
+ * This code convert the event to InternalEvent and InternalResult to the expected output.
104
+ * @default "aws-apigw-v2"
105
+ */
106
+ converter?: IncludedConverter | LazyLoadedOverride<Converter<E, R>>;
107
+ /**
108
+ * Generate a basic dockerfile to deploy the app.
109
+ * If a string is provided, it will be used as the base dockerfile.
110
+ * @default false
111
+ */
112
+ generateDockerfile?: boolean | string;
113
+ }
114
+ export interface OverrideOptions extends DefaultOverrideOptions {
115
+ /**
116
+ * Add possibility to override the default s3 cache. Used for fetch cache and html/rsc/json cache.
117
+ * @default "s3"
118
+ */
119
+ incrementalCache?: IncludedIncrementalCache | LazyLoadedOverride<IncrementalCache>;
120
+ /**
121
+ * Add possibility to override the default tag cache. Used for revalidateTags and revalidatePath.
122
+ * @default "dynamodb"
123
+ */
124
+ tagCache?: IncludedTagCache | LazyLoadedOverride<TagCache>;
125
+ /**
126
+ * Add possibility to override the default queue. Used for isr.
127
+ * @default "sqs"
128
+ */
129
+ queue?: IncludedQueue | LazyLoadedOverride<Queue>;
130
+ }
131
+ export interface DefaultFunctionOptions<E extends BaseEventOrResult = InternalEvent, R extends BaseEventOrResult = InternalResult> {
132
+ /**
133
+ * Minify the server bundle.
134
+ * @default false
135
+ */
136
+ minify?: boolean;
137
+ /**
138
+ * Print debug information.
139
+ * @default false
140
+ */
141
+ debug?: boolean;
142
+ /**
143
+ * Enable overriding the default lambda.
144
+ */
145
+ override?: DefaultOverrideOptions<E, R>;
146
+ }
147
+ export interface FunctionOptions extends DefaultFunctionOptions {
148
+ /**
149
+ * Runtime used
150
+ * @default "node"
151
+ */
152
+ runtime?: "node" | "edge" | "deno";
153
+ /**
154
+ * @default "regional"
155
+ */
156
+ placement?: "regional" | "global";
157
+ /**
158
+ * Enable overriding the default lambda.
159
+ */
160
+ override?: OverrideOptions;
161
+ /**
162
+ * Bundle Next server into a single file.
163
+ * This results in a way smaller bundle but it might break for some cases.
164
+ * This option will probably break on every new Next.js version.
165
+ * @default false
166
+ * @deprecated This is not supported in 14.2+
167
+ */
168
+ experimentalBundledNextServer?: boolean;
169
+ }
170
+ export type RouteTemplate = `app/${string}/route` | `app/${string}/page` | `app/page` | `app/route` | `pages/${string}`;
171
+ export interface SplittedFunctionOptions extends FunctionOptions {
172
+ /**
173
+ * Here you should specify all the routes you want to use.
174
+ * For app routes, you should use the `app/${name}/route` format or `app/${name}/page` for pages.
175
+ * For pages, you should use the `page/${name}` format.
176
+ * @example
177
+ * ```ts
178
+ * routes: ["app/api/test/route", "app/page", "pages/admin"]
179
+ * ```
180
+ */
181
+ routes: RouteTemplate[];
182
+ /**
183
+ * Cloudfront compatible patterns.
184
+ * i.e. /api/*
185
+ * @default []
186
+ */
187
+ patterns: string[];
188
+ }
189
+ export interface OpenNextConfig {
190
+ default: FunctionOptions;
191
+ functions?: Record<string, SplittedFunctionOptions>;
192
+ /**
193
+ * Override the default middleware
194
+ * If you set this options, the middleware need to be deployed separately.
195
+ * It supports both edge and node runtime.
196
+ * @default undefined
197
+ */
198
+ middleware?: DefaultFunctionOptions & {
199
+ external: true;
200
+ /**
201
+ * The override options for the middleware.
202
+ * By default the lite override are used (.i.e. s3-lite, dynamodb-lite, sqs-lite)
203
+ * @default undefined
204
+ */
205
+ override?: OverrideOptions;
206
+ /**
207
+ * Origin resolver is used to resolve the origin for internal rewrite.
208
+ * By default, it uses the pattern-env origin resolver.
209
+ * Pattern env uses pattern set in split function options and an env variable OPEN_NEXT_ORIGIN
210
+ * OPEN_NEXT_ORIGIN should be a json stringified object with the key of the splitted function as key and the origin as value
211
+ * @default "pattern-env"
212
+ */
213
+ originResolver?: "pattern-env" | LazyLoadedOverride<OriginResolver>;
214
+ };
215
+ /**
216
+ * Override the default warmer
217
+ * By default, works for lambda only.
218
+ * If you override this, you'll need to handle the warmer event in the wrapper
219
+ * @default undefined
220
+ */
221
+ warmer?: DefaultFunctionOptions<WarmerEvent, WarmerResponse> & {
222
+ invokeFunction: "aws-lambda" | LazyLoadedOverride<Warmer>;
223
+ };
224
+ /**
225
+ * Override the default revalidate function
226
+ * By default, works for lambda and on SQS event.
227
+ * Supports only node runtime
228
+ */
229
+ revalidate?: DefaultFunctionOptions<{
230
+ host: string;
231
+ url: string;
232
+ type: "revalidate";
233
+ }, {
234
+ type: "revalidate";
235
+ }>;
236
+ /**
237
+ * Override the default revalidate function
238
+ * By default, works on lambda and for S3 key.
239
+ * Supports only node runtime
240
+ */
241
+ imageOptimization?: DefaultFunctionOptions & {
242
+ /**
243
+ * The image loader is used to load the image from the source.
244
+ * @default "s3"
245
+ */
246
+ loader?: IncludedImageLoader | LazyLoadedOverride<ImageLoader>;
247
+ /**
248
+ * @default "arm64"
249
+ */
250
+ arch?: "x64" | "arm64";
251
+ /**
252
+ * @default "18"
253
+ */
254
+ nodeVersion?: "18" | "20";
255
+ };
256
+ /**
257
+ * Override the default initialization function
258
+ * By default, works for lambda and on SQS event.
259
+ * Supports only node runtime
260
+ */
261
+ initializationFunction?: DefaultFunctionOptions & {
262
+ tagCache?: "dynamodb" | LazyLoadedOverride<TagCache>;
263
+ };
264
+ /**
265
+ * Dangerous options. This break some functionnality but can be useful in some cases.
266
+ */
267
+ dangerous?: DangerousOptions;
268
+ /**
269
+ * The command to build the Next.js app.
270
+ * @default `npm run build`, `yarn build`, or `pnpm build` based on the lock file found in the app's directory or any of its parent directories.
271
+ * @example
272
+ * ```ts
273
+ * build({
274
+ * buildCommand: "pnpm custom:build",
275
+ * });
276
+ * ```
277
+ */
278
+ buildCommand?: string;
279
+ /**
280
+ * The path to the target folder of build output from the `buildCommand` option (the path which will contain the `.next` and `.open-next` folders). This path is relative from the current process.cwd().
281
+ * @default "."
282
+ */
283
+ buildOutputPath?: string;
284
+ /**
285
+ * The path to the root of the Next.js app's source code. This path is relative from the current process.cwd().
286
+ * @default "."
287
+ */
288
+ appPath?: string;
289
+ /**
290
+ * The path to the package.json file of the Next.js app. This path is relative from the current process.cwd().
291
+ * @default "."
292
+ */
293
+ packageJsonPath?: string;
294
+ /**
295
+ * **Advanced usage**
296
+ * If you use the edge runtime somewhere (either in the middleware or in the functions), we compile 2 versions of the open-next.config.ts file.
297
+ * One for the node runtime and one for the edge runtime.
298
+ * This option allows you to specify the externals for the edge runtime used in esbuild for the compilation of open-next.config.ts
299
+ * It is especially useful if you use some custom overrides only in node
300
+ * @default []
301
+ */
302
+ edgeExternals?: string[];
303
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ export interface BaseOpenNextError {
2
+ readonly __openNextInternal: true;
3
+ readonly canIgnore: boolean;
4
+ readonly logLevel: 0 | 1 | 2;
5
+ }
6
+ export declare class IgnorableError extends Error implements BaseOpenNextError {
7
+ readonly __openNextInternal = true;
8
+ readonly canIgnore = true;
9
+ readonly logLevel = 0;
10
+ constructor(message: string);
11
+ }
12
+ export declare class RecoverableError extends Error implements BaseOpenNextError {
13
+ readonly __openNextInternal = true;
14
+ readonly canIgnore = true;
15
+ readonly logLevel = 1;
16
+ constructor(message: string);
17
+ }
18
+ export declare class FatalError extends Error implements BaseOpenNextError {
19
+ readonly __openNextInternal = true;
20
+ readonly canIgnore = false;
21
+ readonly logLevel = 2;
22
+ constructor(message: string);
23
+ }
@@ -0,0 +1,32 @@
1
+ // This is an error that can be totally ignored
2
+ // It don't even need to be logged, or only in debug mode
3
+ export class IgnorableError extends Error {
4
+ __openNextInternal = true;
5
+ canIgnore = true;
6
+ logLevel = 0;
7
+ constructor(message) {
8
+ super(message);
9
+ this.name = "IgnorableError";
10
+ }
11
+ }
12
+ // This is an error that can be recovered from
13
+ // It should be logged but the process can continue
14
+ export class RecoverableError extends Error {
15
+ __openNextInternal = true;
16
+ canIgnore = true;
17
+ logLevel = 1;
18
+ constructor(message) {
19
+ super(message);
20
+ this.name = "RecoverableError";
21
+ }
22
+ }
23
+ // We should not continue the process if this error is thrown
24
+ export class FatalError extends Error {
25
+ __openNextInternal = true;
26
+ canIgnore = false;
27
+ logLevel = 2;
28
+ constructor(message) {
29
+ super(message);
30
+ this.name = "FatalError";
31
+ }
32
+ }
@@ -0,0 +1,2 @@
1
+ import type { AwsClient } from "aws4fetch";
2
+ export declare function customFetchClient(client: AwsClient): (input: RequestInfo, init: RequestInit) => Promise<Response>;
@@ -0,0 +1,23 @@
1
+ // Because of Next take on fetch, and until it's fixed in Next 15 we have to pass some internals stuff to next for every fetch we do with aws4fetch
2
+ // For some reason passing this directly to client.fetch doesn't work
3
+ export function customFetchClient(client) {
4
+ return async (input, init) => {
5
+ const signed = await client.sign(input, init);
6
+ const headers = {};
7
+ signed.headers.forEach((value, key) => {
8
+ headers[key] = value;
9
+ });
10
+ const response = await globalThis.internalFetch(signed.url, {
11
+ method: signed.method,
12
+ headers,
13
+ body: init.body,
14
+ });
15
+ /**
16
+ * Response body must be consumed to avoid socket error.
17
+ * This is necessary otherwise we get some error : SocketError: other side closed
18
+ * https://github.com/nodejs/undici/issues/583#issuecomment-855384858
19
+ */
20
+ const clonedResponse = response.clone();
21
+ return clonedResponse;
22
+ };
23
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * A `Promise.withResolvers` implementation that exposes the `resolve` and
3
+ * `reject` functions on a `Promise`.
4
+ * Copied from next https://github.com/vercel/next.js/blob/canary/packages/next/src/lib/detached-promise.ts
5
+ * @see https://tc39.es/proposal-promise-with-resolvers/
6
+ */
7
+ export declare class DetachedPromise<T = any> {
8
+ readonly resolve: (value: T | PromiseLike<T>) => void;
9
+ readonly reject: (reason: any) => void;
10
+ readonly promise: Promise<T>;
11
+ constructor();
12
+ }
13
+ export declare class DetachedPromiseRunner {
14
+ private promises;
15
+ withResolvers<T>(): DetachedPromise<T>;
16
+ add<T>(promise: Promise<T>): void;
17
+ await(): Promise<void>;
18
+ }
@@ -0,0 +1,48 @@
1
+ import { debug, error } from "../adapters/logger";
2
+ /**
3
+ * A `Promise.withResolvers` implementation that exposes the `resolve` and
4
+ * `reject` functions on a `Promise`.
5
+ * Copied from next https://github.com/vercel/next.js/blob/canary/packages/next/src/lib/detached-promise.ts
6
+ * @see https://tc39.es/proposal-promise-with-resolvers/
7
+ */
8
+ export class DetachedPromise {
9
+ resolve;
10
+ reject;
11
+ promise;
12
+ constructor() {
13
+ let resolve;
14
+ let reject;
15
+ // Create the promise and assign the resolvers to the object.
16
+ this.promise = new Promise((res, rej) => {
17
+ resolve = res;
18
+ reject = rej;
19
+ });
20
+ // We know that resolvers is defined because the Promise constructor runs
21
+ // synchronously.
22
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
23
+ this.resolve = resolve;
24
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
25
+ this.reject = reject;
26
+ }
27
+ }
28
+ export class DetachedPromiseRunner {
29
+ promises = [];
30
+ withResolvers() {
31
+ const detachedPromise = new DetachedPromise();
32
+ this.promises.push(detachedPromise);
33
+ return detachedPromise;
34
+ }
35
+ add(promise) {
36
+ const detachedPromise = new DetachedPromise();
37
+ this.promises.push(detachedPromise);
38
+ promise.then(detachedPromise.resolve, detachedPromise.reject);
39
+ }
40
+ async await() {
41
+ debug(`Awaiting ${this.promises.length} detached promises`);
42
+ const results = await Promise.allSettled(this.promises.map((p) => p.promise));
43
+ const rejectedPromises = results.filter((r) => r.status === "rejected");
44
+ rejectedPromises.forEach((r) => {
45
+ error(r.reason);
46
+ });
47
+ }
48
+ }
@@ -0,0 +1,5 @@
1
+ /// <reference types="node" />
2
+ import type { ReadableStream } from "node:stream/web";
3
+ export declare function fromReadableStream(stream: ReadableStream<Uint8Array>, base64?: boolean): Promise<string>;
4
+ export declare function toReadableStream(value: string, isBase64?: boolean): ReadableStream;
5
+ export declare function emptyReadableStream(): ReadableStream;