expo-server 0.0.0 → 0.0.1

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 (158) hide show
  1. package/README.md +1 -0
  2. package/build/cjs/ImmutableRequest.d.ts +60 -0
  3. package/build/cjs/ImmutableRequest.js +160 -0
  4. package/build/cjs/ImmutableRequest.js.map +1 -0
  5. package/build/cjs/global.types.d.ts +13 -0
  6. package/build/cjs/global.types.js +3 -0
  7. package/build/cjs/global.types.js.map +1 -0
  8. package/build/cjs/index.d.ts +2 -0
  9. package/build/cjs/index.js +18 -0
  10. package/build/cjs/index.js.map +1 -0
  11. package/build/cjs/manifest.d.ts +27 -0
  12. package/build/cjs/manifest.js +3 -0
  13. package/build/cjs/manifest.js.map +1 -0
  14. package/build/cjs/middleware/rsc.d.ts +36 -0
  15. package/build/cjs/middleware/rsc.js +124 -0
  16. package/build/cjs/middleware/rsc.js.map +1 -0
  17. package/build/cjs/private.d.ts +2 -0
  18. package/build/cjs/private.js +6 -0
  19. package/build/cjs/private.js.map +1 -0
  20. package/build/cjs/runtime/api.d.ts +36 -0
  21. package/build/cjs/runtime/api.js +64 -0
  22. package/build/cjs/runtime/api.js.map +1 -0
  23. package/build/cjs/runtime/error.d.ts +19 -0
  24. package/build/cjs/runtime/error.js +69 -0
  25. package/build/cjs/runtime/error.js.map +1 -0
  26. package/build/cjs/runtime/index.d.ts +11 -0
  27. package/build/cjs/runtime/index.js +77 -0
  28. package/build/cjs/runtime/index.js.map +1 -0
  29. package/build/cjs/runtime/scope.d.ts +10 -0
  30. package/build/cjs/runtime/scope.js +12 -0
  31. package/build/cjs/runtime/scope.js.map +1 -0
  32. package/build/cjs/types.d.ts +43 -0
  33. package/build/cjs/types.js +3 -0
  34. package/build/cjs/types.js.map +1 -0
  35. package/build/cjs/utils/createReadableStreamFromReadable.d.ts +15 -0
  36. package/build/cjs/utils/createReadableStreamFromReadable.js +97 -0
  37. package/build/cjs/utils/createReadableStreamFromReadable.js.map +1 -0
  38. package/build/cjs/utils/importMetaRegistry.d.ts +3 -0
  39. package/build/cjs/utils/importMetaRegistry.js +30 -0
  40. package/build/cjs/utils/importMetaRegistry.js.map +1 -0
  41. package/build/cjs/utils/matchers.d.ts +12 -0
  42. package/build/cjs/utils/matchers.js +76 -0
  43. package/build/cjs/utils/matchers.js.map +1 -0
  44. package/build/cjs/utils/middleware.d.ts +9 -0
  45. package/build/cjs/utils/middleware.js +82 -0
  46. package/build/cjs/utils/middleware.js.map +1 -0
  47. package/build/cjs/vendor/abstract.d.ts +40 -0
  48. package/build/cjs/vendor/abstract.js +245 -0
  49. package/build/cjs/vendor/abstract.js.map +1 -0
  50. package/build/cjs/vendor/bun.d.ts +10 -0
  51. package/build/cjs/vendor/bun.js +22 -0
  52. package/build/cjs/vendor/bun.js.map +1 -0
  53. package/build/cjs/vendor/eas.d.ts +10 -0
  54. package/build/cjs/vendor/eas.js +28 -0
  55. package/build/cjs/vendor/eas.js.map +1 -0
  56. package/build/cjs/vendor/environment/common.d.ts +14 -0
  57. package/build/cjs/vendor/environment/common.js +66 -0
  58. package/build/cjs/vendor/environment/common.js.map +1 -0
  59. package/build/cjs/vendor/environment/node.d.ts +14 -0
  60. package/build/cjs/vendor/environment/node.js +55 -0
  61. package/build/cjs/vendor/environment/node.js.map +1 -0
  62. package/build/cjs/vendor/environment/workerd.d.ts +18 -0
  63. package/build/cjs/vendor/environment/workerd.js +72 -0
  64. package/build/cjs/vendor/environment/workerd.js.map +1 -0
  65. package/build/cjs/vendor/express.d.ts +14 -0
  66. package/build/cjs/vendor/express.js +100 -0
  67. package/build/cjs/vendor/express.js.map +1 -0
  68. package/build/cjs/vendor/http.d.ts +15 -0
  69. package/build/cjs/vendor/http.js +103 -0
  70. package/build/cjs/vendor/http.js.map +1 -0
  71. package/build/cjs/vendor/netlify.d.ts +15 -0
  72. package/build/cjs/vendor/netlify.js +46 -0
  73. package/build/cjs/vendor/netlify.js.map +1 -0
  74. package/build/cjs/vendor/vercel.d.ts +13 -0
  75. package/build/cjs/vendor/vercel.js +109 -0
  76. package/build/cjs/vendor/vercel.js.map +1 -0
  77. package/build/cjs/vendor/workerd.d.ts +11 -0
  78. package/build/cjs/vendor/workerd.js +22 -0
  79. package/build/cjs/vendor/workerd.js.map +1 -0
  80. package/build/mjs/ImmutableRequest.d.ts +60 -0
  81. package/build/mjs/ImmutableRequest.js +155 -0
  82. package/build/mjs/ImmutableRequest.js.map +1 -0
  83. package/build/mjs/global.types.d.ts +13 -0
  84. package/build/mjs/global.types.js +2 -0
  85. package/build/mjs/global.types.js.map +1 -0
  86. package/build/mjs/index.d.ts +2 -0
  87. package/build/mjs/index.js +2 -0
  88. package/build/mjs/index.js.map +1 -0
  89. package/build/mjs/manifest.d.ts +27 -0
  90. package/build/mjs/manifest.js +2 -0
  91. package/build/mjs/manifest.js.map +1 -0
  92. package/build/mjs/middleware/rsc.d.ts +36 -0
  93. package/build/mjs/middleware/rsc.js +119 -0
  94. package/build/mjs/middleware/rsc.js.map +1 -0
  95. package/build/mjs/private.d.ts +2 -0
  96. package/build/mjs/private.js +2 -0
  97. package/build/mjs/private.js.map +1 -0
  98. package/build/mjs/runtime/api.d.ts +36 -0
  99. package/build/mjs/runtime/api.js +56 -0
  100. package/build/mjs/runtime/api.js.map +1 -0
  101. package/build/mjs/runtime/error.d.ts +19 -0
  102. package/build/mjs/runtime/error.js +64 -0
  103. package/build/mjs/runtime/error.js.map +1 -0
  104. package/build/mjs/runtime/index.d.ts +11 -0
  105. package/build/mjs/runtime/index.js +74 -0
  106. package/build/mjs/runtime/index.js.map +1 -0
  107. package/build/mjs/runtime/scope.d.ts +10 -0
  108. package/build/mjs/runtime/scope.js +9 -0
  109. package/build/mjs/runtime/scope.js.map +1 -0
  110. package/build/mjs/types.d.ts +43 -0
  111. package/build/mjs/types.js +2 -0
  112. package/build/mjs/types.js.map +1 -0
  113. package/build/mjs/utils/createReadableStreamFromReadable.d.ts +15 -0
  114. package/build/mjs/utils/createReadableStreamFromReadable.js +93 -0
  115. package/build/mjs/utils/createReadableStreamFromReadable.js.map +1 -0
  116. package/build/mjs/utils/importMetaRegistry.d.ts +3 -0
  117. package/build/mjs/utils/importMetaRegistry.js +27 -0
  118. package/build/mjs/utils/importMetaRegistry.js.map +1 -0
  119. package/build/mjs/utils/matchers.d.ts +12 -0
  120. package/build/mjs/utils/matchers.js +69 -0
  121. package/build/mjs/utils/matchers.js.map +1 -0
  122. package/build/mjs/utils/middleware.d.ts +9 -0
  123. package/build/mjs/utils/middleware.js +79 -0
  124. package/build/mjs/utils/middleware.js.map +1 -0
  125. package/build/mjs/vendor/abstract.d.ts +40 -0
  126. package/build/mjs/vendor/abstract.js +240 -0
  127. package/build/mjs/vendor/abstract.js.map +1 -0
  128. package/build/mjs/vendor/bun.d.ts +10 -0
  129. package/build/mjs/vendor/bun.js +17 -0
  130. package/build/mjs/vendor/bun.js.map +1 -0
  131. package/build/mjs/vendor/eas.d.ts +10 -0
  132. package/build/mjs/vendor/eas.js +23 -0
  133. package/build/mjs/vendor/eas.js.map +1 -0
  134. package/build/mjs/vendor/environment/common.d.ts +14 -0
  135. package/build/mjs/vendor/environment/common.js +63 -0
  136. package/build/mjs/vendor/environment/common.js.map +1 -0
  137. package/build/mjs/vendor/environment/node.d.ts +14 -0
  138. package/build/mjs/vendor/environment/node.js +48 -0
  139. package/build/mjs/vendor/environment/node.js.map +1 -0
  140. package/build/mjs/vendor/environment/workerd.d.ts +18 -0
  141. package/build/mjs/vendor/environment/workerd.js +68 -0
  142. package/build/mjs/vendor/environment/workerd.js.map +1 -0
  143. package/build/mjs/vendor/express.d.ts +14 -0
  144. package/build/mjs/vendor/express.js +92 -0
  145. package/build/mjs/vendor/express.js.map +1 -0
  146. package/build/mjs/vendor/http.d.ts +15 -0
  147. package/build/mjs/vendor/http.js +95 -0
  148. package/build/mjs/vendor/http.js.map +1 -0
  149. package/build/mjs/vendor/netlify.d.ts +15 -0
  150. package/build/mjs/vendor/netlify.js +41 -0
  151. package/build/mjs/vendor/netlify.js.map +1 -0
  152. package/build/mjs/vendor/vercel.d.ts +13 -0
  153. package/build/mjs/vendor/vercel.js +101 -0
  154. package/build/mjs/vendor/vercel.js.map +1 -0
  155. package/build/mjs/vendor/workerd.d.ts +11 -0
  156. package/build/mjs/vendor/workerd.js +17 -0
  157. package/build/mjs/vendor/workerd.js.map +1 -0
  158. package/package.json +58 -7
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Copyright © 2025 650 Industries.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ const getHeadersConstructor = () => {
8
+ if (typeof Headers !== 'undefined') {
9
+ return Headers;
10
+ }
11
+ else {
12
+ // NOTE(@kitten): The `assertRuntimeFetchAPISupport` helper will catch this. Currently only an issue in Jest
13
+ return (globalThis.Headers ??
14
+ class _MockHeaders {
15
+ constructor() {
16
+ throw new Error('Runtime built-in Headers API is not available.');
17
+ }
18
+ });
19
+ }
20
+ };
21
+ /**
22
+ * An immutable version of the Fetch API's [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) object which prevents mutations.
23
+ */
24
+ class ImmutableHeaders extends getHeadersConstructor() {
25
+ // TODO(@hassankhan): Merge with `ReadonlyHeaders` from `expo-router`
26
+ #throwImmutableError() {
27
+ throw new Error('This operation is not allowed on immutable headers.');
28
+ }
29
+ set() {
30
+ this.#throwImmutableError();
31
+ }
32
+ append() {
33
+ this.#throwImmutableError();
34
+ }
35
+ delete() {
36
+ this.#throwImmutableError();
37
+ }
38
+ }
39
+ /**
40
+ * An immutable version of the Fetch API's [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) object which prevents mutations to the request body and headers.
41
+ */
42
+ export class ImmutableRequest {
43
+ #headers;
44
+ #request;
45
+ constructor(request) {
46
+ this.#headers = new ImmutableHeaders(request.headers);
47
+ this.#request = request;
48
+ }
49
+ get cache() {
50
+ return this.#request.cache;
51
+ }
52
+ get credentials() {
53
+ return this.#request.credentials;
54
+ }
55
+ get destination() {
56
+ return this.#request.destination;
57
+ }
58
+ get integrity() {
59
+ return this.#request.integrity;
60
+ }
61
+ get keepalive() {
62
+ return this.#request.keepalive;
63
+ }
64
+ get method() {
65
+ return this.#request.method;
66
+ }
67
+ get mode() {
68
+ return this.#request.mode;
69
+ }
70
+ get redirect() {
71
+ return this.#request.redirect;
72
+ }
73
+ get referrer() {
74
+ return this.#request.referrer;
75
+ }
76
+ get referrerPolicy() {
77
+ return this.#request.referrerPolicy;
78
+ }
79
+ get signal() {
80
+ return this.#request.signal;
81
+ }
82
+ get url() {
83
+ return this.#request.url;
84
+ }
85
+ get bodyUsed() {
86
+ return this.#request.bodyUsed;
87
+ }
88
+ get duplex() {
89
+ return this.#request.duplex;
90
+ }
91
+ get headers() {
92
+ return this.#headers;
93
+ }
94
+ #throwImmutableBodyError() {
95
+ throw new Error('This operation is not allowed on immutable requests.');
96
+ }
97
+ /**
98
+ * The request body is not accessible in immutable requests.
99
+ */
100
+ // @ts-expect-error This ensures JavaScript users cannot mutate the request body
101
+ // eslint-disable-next-line getter-return
102
+ get body() {
103
+ this.#throwImmutableBodyError();
104
+ }
105
+ async arrayBuffer() {
106
+ this.#throwImmutableBodyError();
107
+ }
108
+ async blob() {
109
+ this.#throwImmutableBodyError();
110
+ }
111
+ async bytes() {
112
+ this.#throwImmutableBodyError();
113
+ }
114
+ async formData() {
115
+ this.#throwImmutableBodyError();
116
+ }
117
+ async json() {
118
+ this.#throwImmutableBodyError();
119
+ }
120
+ async text() {
121
+ this.#throwImmutableBodyError();
122
+ }
123
+ /**
124
+ * Creates a mutable clone of the original request. This is provided as an escape hatch.
125
+ */
126
+ clone() {
127
+ return this.#request.clone();
128
+ }
129
+ }
130
+ // Add assertions to improve usage in non-standard environments.
131
+ export function assertRuntimeFetchAPISupport({ Request, Response, Headers, process, } = globalThis) {
132
+ // Check if Request and Response are available.
133
+ if (typeof Request === 'undefined' ||
134
+ typeof Response === 'undefined' ||
135
+ typeof Headers === 'undefined') {
136
+ // Detect if `--no-experimental-fetch` flag is enabled and warn that it must be disabled.
137
+ if (typeof process !== 'undefined' && process.env && process.env.NODE_OPTIONS) {
138
+ const nodeOptions = process.env.NODE_OPTIONS;
139
+ if (nodeOptions.includes('--no-experimental-fetch')) {
140
+ throw new Error('NODE_OPTIONS="--no-experimental-fetch" is not supported with Expo server. Node.js built-in Request/Response APIs are required to continue.');
141
+ }
142
+ }
143
+ // If Node.js is <18, throw an error.
144
+ if (typeof process !== 'undefined' && process.version) {
145
+ const version = process.version;
146
+ const majorVersion = parseInt(version.replace(/v/g, '').split('.')[0], 10);
147
+ if (majorVersion < 18) {
148
+ throw new Error(`Node.js version ${majorVersion} is not supported. Upgrade to Node.js 20 or newer.`);
149
+ }
150
+ }
151
+ // Default error event for missing APIs.
152
+ throw new Error('Runtime built-in Request/Response/Headers APIs are not available. If running Node ensure that Node Fetch API, first available in Node.js 18, is enabled.');
153
+ }
154
+ }
155
+ //# sourceMappingURL=ImmutableRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImmutableRequest.js","sourceRoot":"","sources":["../../src/ImmutableRequest.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,qBAAqB,GAAG,GAAmB,EAAE;IACjD,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE,CAAC;QACnC,OAAO,OAAO,CAAC;IACjB,CAAC;SAAM,CAAC;QACN,4GAA4G;QAC5G,OAAO,CACL,UAAU,CAAC,OAAO;YAClB,MAAM,YAAY;gBAChB;oBACE,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;gBACpE,CAAC;aACF,CACF,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,gBAAiB,SAAQ,qBAAqB,EAAE;IACpD,qEAAqE;IACrE,oBAAoB;QAClB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAED,GAAG;QACD,IAAI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AAW;QAC/B,OAAO,OAAO,KAAK,WAAW,EAC9B,CAAC;QACD,yFAAyF;QACzF,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC;YAC9E,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;YAC7C,IAAI,WAAW,CAAC,QAAQ,CAAC,yBAAyB,CAAC,EAAE,CAAC;gBACpD,MAAM,IAAI,KAAK,CACb,4IAA4I,CAC7I,CAAC;YACJ,CAAC;QACH,CAAC;QACD,qCAAqC;QACrC,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACtD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;YAChC,MAAM,YAAY,GAAG,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC3E,IAAI,YAAY,GAAG,EAAE,EAAE,CAAC;gBACtB,MAAM,IAAI,KAAK,CACb,mBAAmB,YAAY,oDAAoD,CACpF,CAAC;YACJ,CAAC;QACH,CAAC;QAED,wCAAwC;QACxC,MAAM,IAAI,KAAK,CACb,0JAA0J,CAC3J,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,13 @@
1
+ declare global {
2
+ interface RequestInit {
3
+ duplex?: 'half';
4
+ }
5
+ interface Request {
6
+ duplex?: 'half';
7
+ }
8
+ interface Response {
9
+ cf?: unknown;
10
+ webSocket?: unknown;
11
+ }
12
+ }
13
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=global.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global.types.js","sourceRoot":"","sources":["../../src/global.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export * from './runtime/api';
2
+ export type * from './types';
@@ -0,0 +1,2 @@
1
+ export * from './runtime/api';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
@@ -0,0 +1,27 @@
1
+ export interface MiddlewareInfo {
2
+ /**
3
+ * Path to the module that contains the middleware function as a default export.
4
+ *
5
+ * @example _expo/functions/+middleware.js
6
+ */
7
+ file: string;
8
+ }
9
+ export interface RouteInfo<TRegex = RegExp | string> {
10
+ file: string;
11
+ page: string;
12
+ namedRegex: TRegex;
13
+ routeKeys: Record<string, string>;
14
+ permanent?: boolean;
15
+ methods?: string[];
16
+ }
17
+ export interface RoutesManifest<TRegex = RegExp | string> {
18
+ middleware?: MiddlewareInfo;
19
+ apiRoutes: RouteInfo<TRegex>[];
20
+ htmlRoutes: RouteInfo<TRegex>[];
21
+ notFoundRoutes: RouteInfo<TRegex>[];
22
+ redirects: RouteInfo<TRegex>[];
23
+ rewrites: RouteInfo<TRegex>[];
24
+ }
25
+ export type RawManifest = RoutesManifest<string>;
26
+ export type Manifest = RoutesManifest<RegExp>;
27
+ export type Route = RouteInfo<RegExp>;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../src/manifest.ts"],"names":[],"mappings":""}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Copyright © 2024 650 Industries.
3
+ * Copyright © 2024 dai-shi.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ *
8
+ * https://github.com/dai-shi/waku/blob/f9111ed7d96c95d7e128b37e8f7ae2d80122218e/packages/waku/src/lib/middleware/rsc.ts#L1
9
+ */
10
+ type ResolvedConfig = any;
11
+ export type RenderRscArgs = {
12
+ config: ResolvedConfig;
13
+ input: string;
14
+ searchParams: URLSearchParams;
15
+ platform: string;
16
+ engine?: 'hermes' | null;
17
+ method: 'GET' | 'POST';
18
+ body?: ReadableStream | null;
19
+ contentType?: string | undefined;
20
+ decodedBody?: unknown;
21
+ moduleIdCallback?: ((id: string) => void) | undefined;
22
+ onError?: (err: unknown) => void;
23
+ headers: Record<string, string>;
24
+ };
25
+ export declare const decodeInput: (encodedInput: string) => string;
26
+ export declare function getRscMiddleware(options: {
27
+ config: ResolvedConfig;
28
+ baseUrl: string;
29
+ rscPath: string;
30
+ renderRsc: (args: RenderRscArgs) => Promise<ReadableStream<any>>;
31
+ onError?: (err: unknown) => void;
32
+ }): {
33
+ GET: (req: Request) => Promise<Response>;
34
+ POST: (req: Request) => Promise<Response>;
35
+ };
36
+ export {};
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Copyright © 2024 650 Industries.
3
+ * Copyright © 2024 dai-shi.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ *
8
+ * https://github.com/dai-shi/waku/blob/f9111ed7d96c95d7e128b37e8f7ae2d80122218e/packages/waku/src/lib/middleware/rsc.ts#L1
9
+ */
10
+ export const decodeInput = (encodedInput) => {
11
+ if (encodedInput === 'index.txt') {
12
+ return '';
13
+ }
14
+ if (encodedInput?.endsWith('.txt')) {
15
+ return encodedInput.slice(0, -'.txt'.length);
16
+ }
17
+ const err = new Error('Invalid encoded input');
18
+ err.statusCode = 400;
19
+ throw err;
20
+ };
21
+ // Production / Development API Route for handling RSC. Must be applied to the RSC paths, e.g. `/_flight/[...slug]+api.tsx`
22
+ export function getRscMiddleware(options) {
23
+ let rscPathPrefix = options.rscPath;
24
+ if (rscPathPrefix !== '/' && !rscPathPrefix.endsWith('/')) {
25
+ rscPathPrefix += '/';
26
+ }
27
+ async function getOrPostAsync(req) {
28
+ const url = new URL(req.url);
29
+ const { method } = req;
30
+ if (method !== 'GET' && method !== 'POST') {
31
+ throw new Error(`Unsupported method '${method}'`);
32
+ }
33
+ const platform = url.searchParams.get('platform') ?? req.headers.get('expo-platform');
34
+ if (typeof platform !== 'string' || !platform) {
35
+ return new Response('Missing expo-platform header or platform query parameter', {
36
+ status: 500,
37
+ headers: {
38
+ 'Content-Type': 'text/plain',
39
+ },
40
+ });
41
+ }
42
+ const engine = url.searchParams.get('transform.engine');
43
+ // TODO: Will the hermes flag apply in production later?
44
+ if (engine && !['hermes'].includes(engine)) {
45
+ return new Response(`Query parameter "transform.engine" is an unsupported value: ${engine}`, {
46
+ status: 500,
47
+ headers: {
48
+ 'Content-Type': 'text/plain',
49
+ },
50
+ });
51
+ }
52
+ let encodedInput = url.pathname.replace(
53
+ // TODO: baseUrl support
54
+ rscPathPrefix, '');
55
+ // First segment should be the target platform.
56
+ // This is used for aligning with production exports which are statically exported to a single location at build-time.
57
+ encodedInput = encodedInput.replace(new RegExp(`^${platform}/`), '');
58
+ try {
59
+ encodedInput = decodeInput(encodedInput);
60
+ }
61
+ catch {
62
+ return new Response(`Invalid encoded input: "${encodedInput}"`, {
63
+ status: 400,
64
+ headers: {
65
+ 'Content-Type': 'text/plain',
66
+ },
67
+ });
68
+ }
69
+ try {
70
+ const args = {
71
+ config: options.config,
72
+ platform,
73
+ engine: engine,
74
+ input: encodedInput,
75
+ searchParams: url.searchParams,
76
+ method,
77
+ body: req.body,
78
+ contentType: req.headers.get('Content-Type') ?? '',
79
+ decodedBody: req.headers.get('X-Expo-Params'),
80
+ onError: options.onError,
81
+ headers: headersToRecord(req.headers),
82
+ };
83
+ const readable = await options.renderRsc(args);
84
+ return new Response(readable, {
85
+ headers: {
86
+ // The response is a streamed text file
87
+ 'Content-Type': 'text/plain',
88
+ },
89
+ });
90
+ }
91
+ catch (err) {
92
+ if (err instanceof Response) {
93
+ return err;
94
+ }
95
+ if (process.env.NODE_ENV !== 'development') {
96
+ throw err;
97
+ }
98
+ console.error(err);
99
+ return new Response(`Unexpected server error rendering RSC: ` + err.message, {
100
+ status: 'statusCode' in err ? err.statusCode : 500,
101
+ headers: {
102
+ 'Content-Type': 'text/plain',
103
+ },
104
+ });
105
+ }
106
+ }
107
+ return {
108
+ GET: getOrPostAsync,
109
+ POST: getOrPostAsync,
110
+ };
111
+ }
112
+ function headersToRecord(headers) {
113
+ const record = {};
114
+ for (const [key, value] of headers.entries()) {
115
+ record[key] = value;
116
+ }
117
+ return record;
118
+ }
119
+ //# sourceMappingURL=rsc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rsc.js","sourceRoot":"","sources":["../../../src/middleware/rsc.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAmBH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,YAAoB,EAAE,EAAE;IAClD,IAAI,YAAY,KAAK,WAAW,EAAE,CAAC;QACjC,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACnC,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC/C,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC9C,GAAW,CAAC,UAAU,GAAG,GAAG,CAAC;IAC9B,MAAM,GAAG,CAAC;AACZ,CAAC,CAAC;AAEF,2HAA2H;AAC3H,MAAM,UAAU,gBAAgB,CAAC,OAMhC;IAIC,IAAI,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC;IACpC,IAAI,aAAa,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1D,aAAa,IAAI,GAAG,CAAC;IACvB,CAAC;IAED,KAAK,UAAU,cAAc,CAAC,GAAY;QACxC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC7B,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;QACvB,IAAI,MAAM,KAA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AO,EAAE;oBACP,cAAc,EAAE,YAAY;iBAC7B;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO;QACL,GAAG,EAAE,cAAc;QACnB,IAAI,EAAE,cAAc;KACrB,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,OAAgB;IACvC,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;QAC7C,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACtB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { type RenderRscArgs, getRscMiddleware } from './middleware/rsc';
2
+ export type * from './manifest';
@@ -0,0 +1,2 @@
1
+ export { getRscMiddleware } from './middleware/rsc';
2
+ //# sourceMappingURL=private.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"private.js","sourceRoot":"","sources":["../../src/private.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,gBAAgB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,36 @@
1
+ export { StatusError } from './error';
2
+ export interface RequestAPI {
3
+ origin?: string;
4
+ environment?: string | null;
5
+ waitUntil?(promise: Promise<unknown>): void;
6
+ deferTask?(fn: () => Promise<unknown>): void;
7
+ }
8
+ /** Returns the current request's origin URL
9
+ * @remarks
10
+ * This returns the request's Origin header, which contains the
11
+ * request origin URL or defaults to `null`.
12
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Origin
13
+ */
14
+ export declare function origin(): string | null;
15
+ /** Returns the currently specified "environment", if any is set up.
16
+ * @remarks
17
+ * The request's environment. When this is `null`, this by convention typically
18
+ * signifies the production environment. This is typically customized via the
19
+ * Expo server adapters, and will default to the current `alias` name in
20
+ * EAS Hosting.
21
+ */
22
+ export declare function environment(): string | null;
23
+ /** Runs a task immediately and instructs the runtime to complete the task.
24
+ * @remarks
25
+ * Running a promise concurrently to the request doesn't usually guarantee that your
26
+ * serverless function will continue executing the task. Passing the task to `runTask`
27
+ * will attempt to keep the current invocation running until the task is completed.
28
+ */
29
+ export declare function runTask(fn: () => Promise<unknown>): void;
30
+ /** Defers a task until after a response has been sent.
31
+ * @remarks
32
+ * After a response has been sent, if no error occurred, the tasks passed to `deferTask`
33
+ * will be executed and the serverless function will be instructed to continue executing
34
+ * the task until it has completed.
35
+ */
36
+ export declare function deferTask(fn: () => Promise<unknown>): void;
@@ -0,0 +1,56 @@
1
+ import { scopeRef } from './scope';
2
+ function enforcedRequestScope() {
3
+ const scope = scopeRef.current?.getStore();
4
+ if (scope === undefined) {
5
+ throw new Error('Invalid server runtime API call. Runtime APIs can only be called during ongoing requests.\n' +
6
+ '- You may be calling this API in the global scope.\n' +
7
+ '- You might be calling this API outside of a promise scoped to a request.\n' +
8
+ '- You might have more than one copy of this API installed.');
9
+ }
10
+ return scope;
11
+ }
12
+ function assertSupport(name, v) {
13
+ if (v === undefined) {
14
+ throw new Error(`Unsupported server runtime API call: ${name}. This API is not supported in your current environment.`);
15
+ }
16
+ return v;
17
+ }
18
+ export { StatusError } from './error';
19
+ /** Returns the current request's origin URL
20
+ * @remarks
21
+ * This returns the request's Origin header, which contains the
22
+ * request origin URL or defaults to `null`.
23
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Origin
24
+ */
25
+ export function origin() {
26
+ return assertSupport('origin()', enforcedRequestScope().origin);
27
+ }
28
+ /** Returns the currently specified "environment", if any is set up.
29
+ * @remarks
30
+ * The request's environment. When this is `null`, this by convention typically
31
+ * signifies the production environment. This is typically customized via the
32
+ * Expo server adapters, and will default to the current `alias` name in
33
+ * EAS Hosting.
34
+ */
35
+ export function environment() {
36
+ return assertSupport('environment()', enforcedRequestScope().environment);
37
+ }
38
+ /** Runs a task immediately and instructs the runtime to complete the task.
39
+ * @remarks
40
+ * Running a promise concurrently to the request doesn't usually guarantee that your
41
+ * serverless function will continue executing the task. Passing the task to `runTask`
42
+ * will attempt to keep the current invocation running until the task is completed.
43
+ */
44
+ export function runTask(fn) {
45
+ assertSupport('runTask()', enforcedRequestScope().waitUntil)(fn());
46
+ }
47
+ /** Defers a task until after a response has been sent.
48
+ * @remarks
49
+ * After a response has been sent, if no error occurred, the tasks passed to `deferTask`
50
+ * will be executed and the serverless function will be instructed to continue executing
51
+ * the task until it has completed.
52
+ */
53
+ export function deferTask(fn) {
54
+ assertSupport('deferTask()', enforcedRequestScope().deferTask)(fn);
55
+ }
56
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/runtime/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,SAAS,oBAAoB;IAC3B,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC;IAC3C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,6FAA6F;YAC3F,sDAAsD;YACtD,6EAA6E;YAC7E,4DAA4D,CAC/D,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,aAAa,CAAI,IAAY,EAAE,CAAgB;IACtD,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,wCAAwC,IAAI,0DAA0D,CACvG,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAStC;;;;;GAKG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,aAAa,CAAC,UAAU,EAAE,oBAAoB,EAAE,CAAC,MAAM,CAAC,CAAC;AAClE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,aAAa,CAAC,eAAe,EAAE,oBAAoB,EAAE,CAAC,WAAW,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,EAA0B;IAChD,aAAa,CAAC,WAAW,EAAE,oBAAoB,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACrE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,EAA0B;IAClD,aAAa,CAAC,aAAa,EAAE,oBAAoB,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC;AACrE,CAAC"}
@@ -0,0 +1,19 @@
1
+ export declare class StatusError extends Error {
2
+ status: number;
3
+ body: string;
4
+ constructor(status?: number, body?: {
5
+ error?: string;
6
+ [key: string]: any;
7
+ } | Error | string);
8
+ constructor(status?: number, errorOptions?: {
9
+ cause: unknown;
10
+ error?: string;
11
+ });
12
+ constructor(status?: number, body?: {
13
+ error?: string;
14
+ [key: string]: any;
15
+ } | Error | string, errorOptions?: {
16
+ cause?: unknown;
17
+ });
18
+ }
19
+ export declare function errorToResponse(error: Error): Response;
@@ -0,0 +1,64 @@
1
+ export class StatusError extends Error {
2
+ status;
3
+ body;
4
+ constructor(status = 500, body, errorOptions) {
5
+ const cause = (errorOptions != null && errorOptions.cause) ??
6
+ (body != null && typeof body === 'object' && body.cause != null ? body.cause : undefined);
7
+ let message = typeof body === 'object' ? (body instanceof Error ? body.message : body.error) : body;
8
+ if (message == null) {
9
+ switch (status) {
10
+ case 400:
11
+ message = 'Bad Request';
12
+ break;
13
+ case 401:
14
+ message = 'Unauthorized';
15
+ break;
16
+ case 403:
17
+ message = 'Forbidden';
18
+ break;
19
+ case 404:
20
+ message = 'Not Found';
21
+ break;
22
+ case 500:
23
+ message = 'Internal Server Error';
24
+ break;
25
+ default:
26
+ message = 'Unknown Error';
27
+ }
28
+ }
29
+ super(message, cause ? { cause } : undefined);
30
+ this.name = 'StatusError';
31
+ this.status = status;
32
+ if (body instanceof Error) {
33
+ this.body = JSON.stringify({ error: body.message }, null, 2);
34
+ }
35
+ else {
36
+ this.body =
37
+ typeof body === 'object'
38
+ ? JSON.stringify(body, null, 2)
39
+ : (body ?? JSON.stringify({ error: message }, null, 2));
40
+ }
41
+ }
42
+ }
43
+ export function errorToResponse(error) {
44
+ if (error instanceof StatusError) {
45
+ return new Response(error.body, {
46
+ status: error.status,
47
+ headers: {
48
+ 'Content-Type': 'application/json; charset=utf-8',
49
+ },
50
+ });
51
+ }
52
+ else if ('status' in error && typeof error.status === 'number') {
53
+ const body = 'body' in error && typeof error.body === 'string'
54
+ ? error.body
55
+ : JSON.stringify({ error: error.message }, null, 2);
56
+ return new Response(body, {
57
+ status: error.status,
58
+ });
59
+ }
60
+ else {
61
+ return new Response(`${error}`, { status: 500 });
62
+ }
63
+ }
64
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/runtime/error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,MAAM,CAAS;IACf,IAAI,CAAS;IASb,YACE,MAAM,GAAG,GAAG,EACZ,IAA+E,EAC/E,YAAkC;QAElC,MAAM,KAAK,GACT,CAAC,YAAY,IAAI,IAAI,IAAI,YAAY,CAAC,KAAK,CAAC;YAC5C,CAAC,IAAI,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAC5F,IAAI,OAAO,GACT,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,YAAY,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACxF,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;YACpB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M,EAAE,KAAK,CAAC,MAAM;YACpB,OAAO,EAAE;gBACP,cAAc,EAAE,iCAAiC;aAClD;SACF,CAAC,CAAC;IACL,CAAC;SAAM,IAAI,QAAQ,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QACjE,MAAM,IAAI,GACR,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;YAC/C,CAAC,CAAC,KAAK,CAAC,IAAI;YACZ,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACxD,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE;YACxB,MAAM,EAAE,KAAK,CAAC,MAAM;SACrB,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,QAAQ,CAAC,GAAG,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IACnD,CAAC;AACH,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { RequestAPI } from './api';
2
+ import { type ScopeDefinition } from './scope';
3
+ export interface RequestAPISetup extends RequestAPI {
4
+ origin?: string;
5
+ environment?: string | null;
6
+ waitUntil?(promise: Promise<unknown>): void;
7
+ }
8
+ type RequestContextFactory = (...args: any[]) => Partial<RequestAPISetup>;
9
+ type RequestScopeRunner<F extends RequestContextFactory> = (fn: (...args: Parameters<F>) => Promise<Response>, ...args: Parameters<F>) => Promise<Response>;
10
+ export declare function createRequestScope<F extends RequestContextFactory>(scopeDefinition: ScopeDefinition, makeRequestAPISetup: F): RequestScopeRunner<F>;
11
+ export {};