modifywithai 1.8.1 → 1.10.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.
@@ -0,0 +1,391 @@
1
+ import { f as ModificationToggleOptions, w as UseRouterOptions, x as RouterResponse } from "./types-D83LZSks.js";
2
+ import * as react0 from "react";
3
+ import { ReactNode } from "react";
4
+ import * as jsxRuntime from "react/jsx-runtime";
5
+ import * as _tanstack_react_query0 from "@tanstack/react-query";
6
+
7
+ //#region src/react/components.d.ts
8
+ declare const useComponents: () => jsxRuntime.JSX.Element | null;
9
+ declare const MWAIComponents: () => jsxRuntime.JSX.Element | null;
10
+ //#endregion
11
+ //#region src/react/head.d.ts
12
+ declare const MWAIHead: ({
13
+ basePath
14
+ }?: {
15
+ basePath?: string;
16
+ }) => jsxRuntime.JSX.Element;
17
+ //#endregion
18
+ //#region src/react/hooks.d.ts
19
+ /**
20
+ * React hook for fetching the list of modifications
21
+ * Polls every 10 seconds for updates
22
+ * Automatically reloads the page when enabled modifications change
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * const { data, isLoading, error } = useList()
27
+ * ```
28
+ */
29
+ declare function useList(): _tanstack_react_query0.UseQueryResult<{
30
+ id: string;
31
+ title: string | null;
32
+ description: string | null;
33
+ status: "error" | "pending" | "success";
34
+ createdAt: number;
35
+ updatedAt: number;
36
+ enabled: boolean | null;
37
+ }[], Error>;
38
+ /**
39
+ * React hook for routing modification requests to ModifyWithAI
40
+ * Returns the router response, pending state, and a `submit` function
41
+ *
42
+ * @example
43
+ * ```tsx
44
+ * const { submit, routerResponse, reply, isPending } = useRouter()
45
+ *
46
+ * const handleSubmit = () => {
47
+ * submit("Change the button color to blue")
48
+ * }
49
+ *
50
+ * // Display the response
51
+ * if (routerResponse?.route === "matched") {
52
+ * console.log("Matched:", routerResponse.title)
53
+ * }
54
+ * ```
55
+ */
56
+ declare function useRouter(options?: UseRouterOptions): {
57
+ variables: undefined;
58
+ error: null;
59
+ isError: false;
60
+ isIdle: true;
61
+ isSuccess: false;
62
+ status: "idle";
63
+ context: unknown;
64
+ failureCount: number;
65
+ failureReason: Error | null;
66
+ isPaused: boolean;
67
+ submittedAt: number;
68
+ mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<RouterResponse, Error, string, unknown>; /** Submit a prompt to the router */
69
+ submit: _tanstack_react_query0.UseMutateFunction<RouterResponse, Error, string, unknown>; /** Reset the router state */
70
+ reset: () => void; /** The parsed router response */
71
+ routerResponse: RouterResponse | null; /** The text message from the router (friendly explanation) */
72
+ reply: string | null; /** Whether the router request is pending */
73
+ isPending: boolean;
74
+ } | {
75
+ variables: string;
76
+ error: null;
77
+ isError: false;
78
+ isIdle: false;
79
+ isSuccess: false;
80
+ status: "pending";
81
+ context: unknown;
82
+ failureCount: number;
83
+ failureReason: Error | null;
84
+ isPaused: boolean;
85
+ submittedAt: number;
86
+ mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<RouterResponse, Error, string, unknown>; /** Submit a prompt to the router */
87
+ submit: _tanstack_react_query0.UseMutateFunction<RouterResponse, Error, string, unknown>; /** Reset the router state */
88
+ reset: () => void; /** The parsed router response */
89
+ routerResponse: RouterResponse | null; /** The text message from the router (friendly explanation) */
90
+ reply: string | null; /** Whether the router request is pending */
91
+ isPending: boolean;
92
+ } | {
93
+ error: Error;
94
+ variables: string;
95
+ isError: true;
96
+ isIdle: false;
97
+ isSuccess: false;
98
+ status: "error";
99
+ context: unknown;
100
+ failureCount: number;
101
+ failureReason: Error | null;
102
+ isPaused: boolean;
103
+ submittedAt: number;
104
+ mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<RouterResponse, Error, string, unknown>; /** Submit a prompt to the router */
105
+ submit: _tanstack_react_query0.UseMutateFunction<RouterResponse, Error, string, unknown>; /** Reset the router state */
106
+ reset: () => void; /** The parsed router response */
107
+ routerResponse: RouterResponse | null; /** The text message from the router (friendly explanation) */
108
+ reply: string | null; /** Whether the router request is pending */
109
+ isPending: boolean;
110
+ } | {
111
+ error: null;
112
+ variables: string;
113
+ isError: false;
114
+ isIdle: false;
115
+ isSuccess: true;
116
+ status: "success";
117
+ context: unknown;
118
+ failureCount: number;
119
+ failureReason: Error | null;
120
+ isPaused: boolean;
121
+ submittedAt: number;
122
+ mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<RouterResponse, Error, string, unknown>; /** Submit a prompt to the router */
123
+ submit: _tanstack_react_query0.UseMutateFunction<RouterResponse, Error, string, unknown>; /** Reset the router state */
124
+ reset: () => void; /** The parsed router response */
125
+ routerResponse: RouterResponse | null; /** The text message from the router (friendly explanation) */
126
+ reply: string | null; /** Whether the router request is pending */
127
+ isPending: boolean;
128
+ };
129
+ /**
130
+ * React hook for enabling a modification
131
+ * Returns mutation state and an `enable` function for enabling modifications
132
+ *
133
+ * @example
134
+ * ```tsx
135
+ * const { enable, isPending, isError, error } = useEnable()
136
+ *
137
+ * const handleEnable = () => {
138
+ * enable("modification-id", {
139
+ * onSuccess: () => console.log("Enabled!"),
140
+ * onError: (err) => console.error(err),
141
+ * })
142
+ * }
143
+ * ```
144
+ */
145
+ declare function useEnable(options?: ModificationToggleOptions): {
146
+ data: undefined;
147
+ variables: undefined;
148
+ error: null;
149
+ isError: false;
150
+ isIdle: true;
151
+ isPending: false;
152
+ isSuccess: false;
153
+ status: "idle";
154
+ reset: () => void;
155
+ context: unknown;
156
+ failureCount: number;
157
+ failureReason: Error | null;
158
+ isPaused: boolean;
159
+ submittedAt: number;
160
+ mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<{
161
+ message: string;
162
+ modificationId: string;
163
+ endUserId: string;
164
+ }, Error, string, unknown>;
165
+ enable: _tanstack_react_query0.UseMutateFunction<{
166
+ message: string;
167
+ modificationId: string;
168
+ endUserId: string;
169
+ }, Error, string, unknown>;
170
+ } | {
171
+ data: undefined;
172
+ variables: string;
173
+ error: null;
174
+ isError: false;
175
+ isIdle: false;
176
+ isPending: true;
177
+ isSuccess: false;
178
+ status: "pending";
179
+ reset: () => void;
180
+ context: unknown;
181
+ failureCount: number;
182
+ failureReason: Error | null;
183
+ isPaused: boolean;
184
+ submittedAt: number;
185
+ mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<{
186
+ message: string;
187
+ modificationId: string;
188
+ endUserId: string;
189
+ }, Error, string, unknown>;
190
+ enable: _tanstack_react_query0.UseMutateFunction<{
191
+ message: string;
192
+ modificationId: string;
193
+ endUserId: string;
194
+ }, Error, string, unknown>;
195
+ } | {
196
+ data: undefined;
197
+ error: Error;
198
+ variables: string;
199
+ isError: true;
200
+ isIdle: false;
201
+ isPending: false;
202
+ isSuccess: false;
203
+ status: "error";
204
+ reset: () => void;
205
+ context: unknown;
206
+ failureCount: number;
207
+ failureReason: Error | null;
208
+ isPaused: boolean;
209
+ submittedAt: number;
210
+ mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<{
211
+ message: string;
212
+ modificationId: string;
213
+ endUserId: string;
214
+ }, Error, string, unknown>;
215
+ enable: _tanstack_react_query0.UseMutateFunction<{
216
+ message: string;
217
+ modificationId: string;
218
+ endUserId: string;
219
+ }, Error, string, unknown>;
220
+ } | {
221
+ data: {
222
+ message: string;
223
+ modificationId: string;
224
+ endUserId: string;
225
+ };
226
+ error: null;
227
+ variables: string;
228
+ isError: false;
229
+ isIdle: false;
230
+ isPending: false;
231
+ isSuccess: true;
232
+ status: "success";
233
+ reset: () => void;
234
+ context: unknown;
235
+ failureCount: number;
236
+ failureReason: Error | null;
237
+ isPaused: boolean;
238
+ submittedAt: number;
239
+ mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<{
240
+ message: string;
241
+ modificationId: string;
242
+ endUserId: string;
243
+ }, Error, string, unknown>;
244
+ enable: _tanstack_react_query0.UseMutateFunction<{
245
+ message: string;
246
+ modificationId: string;
247
+ endUserId: string;
248
+ }, Error, string, unknown>;
249
+ };
250
+ /**
251
+ * React hook for disabling a modification
252
+ * Returns mutation state and a `disable` function for disabling modifications
253
+ *
254
+ * @example
255
+ * ```tsx
256
+ * const { disable, isPending, isError, error } = useDisable()
257
+ *
258
+ * const handleDisable = () => {
259
+ * disable("modification-id", {
260
+ * onSuccess: () => console.log("Disabled!"),
261
+ * onError: (err) => console.error(err),
262
+ * })
263
+ * }
264
+ * ```
265
+ */
266
+ declare function useDisable(options?: ModificationToggleOptions): {
267
+ data: undefined;
268
+ variables: undefined;
269
+ error: null;
270
+ isError: false;
271
+ isIdle: true;
272
+ isPending: false;
273
+ isSuccess: false;
274
+ status: "idle";
275
+ reset: () => void;
276
+ context: unknown;
277
+ failureCount: number;
278
+ failureReason: Error | null;
279
+ isPaused: boolean;
280
+ submittedAt: number;
281
+ mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<{
282
+ message: string;
283
+ modificationId: string;
284
+ endUserId: string;
285
+ }, Error, string, unknown>;
286
+ disable: _tanstack_react_query0.UseMutateFunction<{
287
+ message: string;
288
+ modificationId: string;
289
+ endUserId: string;
290
+ }, Error, string, unknown>;
291
+ } | {
292
+ data: undefined;
293
+ variables: string;
294
+ error: null;
295
+ isError: false;
296
+ isIdle: false;
297
+ isPending: true;
298
+ isSuccess: false;
299
+ status: "pending";
300
+ reset: () => void;
301
+ context: unknown;
302
+ failureCount: number;
303
+ failureReason: Error | null;
304
+ isPaused: boolean;
305
+ submittedAt: number;
306
+ mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<{
307
+ message: string;
308
+ modificationId: string;
309
+ endUserId: string;
310
+ }, Error, string, unknown>;
311
+ disable: _tanstack_react_query0.UseMutateFunction<{
312
+ message: string;
313
+ modificationId: string;
314
+ endUserId: string;
315
+ }, Error, string, unknown>;
316
+ } | {
317
+ data: undefined;
318
+ error: Error;
319
+ variables: string;
320
+ isError: true;
321
+ isIdle: false;
322
+ isPending: false;
323
+ isSuccess: false;
324
+ status: "error";
325
+ reset: () => void;
326
+ context: unknown;
327
+ failureCount: number;
328
+ failureReason: Error | null;
329
+ isPaused: boolean;
330
+ submittedAt: number;
331
+ mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<{
332
+ message: string;
333
+ modificationId: string;
334
+ endUserId: string;
335
+ }, Error, string, unknown>;
336
+ disable: _tanstack_react_query0.UseMutateFunction<{
337
+ message: string;
338
+ modificationId: string;
339
+ endUserId: string;
340
+ }, Error, string, unknown>;
341
+ } | {
342
+ data: {
343
+ message: string;
344
+ modificationId: string;
345
+ endUserId: string;
346
+ };
347
+ error: null;
348
+ variables: string;
349
+ isError: false;
350
+ isIdle: false;
351
+ isPending: false;
352
+ isSuccess: true;
353
+ status: "success";
354
+ reset: () => void;
355
+ context: unknown;
356
+ failureCount: number;
357
+ failureReason: Error | null;
358
+ isPaused: boolean;
359
+ submittedAt: number;
360
+ mutateAsync: _tanstack_react_query0.UseMutateAsyncFunction<{
361
+ message: string;
362
+ modificationId: string;
363
+ endUserId: string;
364
+ }, Error, string, unknown>;
365
+ disable: _tanstack_react_query0.UseMutateFunction<{
366
+ message: string;
367
+ modificationId: string;
368
+ endUserId: string;
369
+ }, Error, string, unknown>;
370
+ };
371
+ //#endregion
372
+ //#region src/react/provider.d.ts
373
+ declare const MWAIContext: react0.Context<string | null>;
374
+ declare const MWAIProvider: ({
375
+ appId,
376
+ children
377
+ }: {
378
+ appId: string;
379
+ children: ReactNode;
380
+ }) => jsxRuntime.JSX.Element;
381
+ //#endregion
382
+ //#region src/react/query-keys.d.ts
383
+ /**
384
+ * Centralized query key factory for type-safe, consistent cache management
385
+ */
386
+ declare const mwaiQueryKeys: {
387
+ readonly all: readonly ["mwai"];
388
+ readonly modifications: () => readonly ["mwai", "modifications"];
389
+ };
390
+ //#endregion
391
+ export { useEnable as a, MWAIHead as c, useDisable as i, MWAIComponents as l, MWAIContext as n, useList as o, MWAIProvider as r, useRouter as s, mwaiQueryKeys as t, useComponents as u };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { _ as ModifyWithAIOptions, a as DisableResponseSchema, c as EnableResponseSchema, d as ModificationSchema, f as ModificationToggleOptions, g as ModifyWithAIArgs, h as ModifyResponseSchema, i as DisableResponse, l as ListModificationsArgs, m as ModifyResponse, n as ApiErrorSchema, o as EnableModificationArgs, p as ModificationsListSchema, r as DisableModificationArgs, s as EnableResponse, t as ApiError, u as Modification } from "./types-DP2zKGqL.js";
1
+ import { _ as ModifyWithAIOptions, a as DisableResponseSchema, c as EnableResponseSchema, d as ModificationSchema, f as ModificationToggleOptions, g as ModifyWithAIArgs, h as ModifyResponseSchema, i as DisableResponse, l as ListModificationsArgs, m as ModifyResponse, n as ApiErrorSchema, o as EnableModificationArgs, p as ModificationsListSchema, r as DisableModificationArgs, s as EnableResponse, t as ApiError, u as Modification } from "./types-D83LZSks.js";
2
2
 
3
3
  //#region src/core.d.ts
4
-
5
4
  /**
6
5
  * Fetch the list of modifications for a given MWAI instance
7
6
  *
@@ -29,7 +28,7 @@ declare function modifyWithAI({
29
28
  id,
30
29
  prompt
31
30
  }: ModifyWithAIArgs, options?: ModifyWithAIOptions): Promise<{
32
- success: boolean;
31
+ modificationId?: string;
33
32
  error?: Error;
34
33
  }>;
35
34
  /**
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as e,i as t,n,o as r,r as i,t as a}from"./types-B-V0OtIq.js";async function o({id:t}){let n=await fetch(`/api/mwai/api/list`);if(!n.ok)throw Error(`Failed to fetch modifications`);let r=await n.json();return e.parse(r)}async function s({id:e,prompt:t},n){let i=t.trim();if(!i){let e=Error(`Prompt cannot be empty`);return n?.onError?.(e),{success:!1,error:e}}try{let e=await fetch(`/api/mwai/api/modify`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prompt:i})});if(!e.ok){let t=await e.json().catch(()=>({})),n=a.safeParse(t),r=n.success&&(n.data.message||n.data.error)||`Failed to submit modification`;throw Error(r)}let t=await e.json(),o=r.parse(t);return n?.onSuccess?.(),typeof window<`u`&&window.location.reload(),{success:o.success}}catch(e){let t=e instanceof Error?e:Error(`Unknown error`);return n?.onError?.(t),{success:!1,error:t}}}async function c({modificationId:e},t){try{let n=await fetch(`/api/mwai/api/enable`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({modificationId:e})});if(!n.ok){let e=await n.json().catch(()=>({})),t=a.safeParse(e),r=t.success&&(t.data.message||t.data.error)||`Failed to enable modification`;throw Error(r)}let r=await n.json(),o=i.parse(r);return t?.onSuccess?.(),typeof window<`u`&&window.location.reload(),{success:!0,data:o}}catch(e){let n=e instanceof Error?e:Error(`Unknown error`);return t?.onError?.(n),{success:!1,error:n}}}async function l({modificationId:e},t){try{let r=await fetch(`/api/mwai/api/disable`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({modificationId:e})});if(!r.ok){let e=await r.json().catch(()=>({})),t=a.safeParse(e),n=t.success&&(t.data.message||t.data.error)||`Failed to disable modification`;throw Error(n)}let i=await r.json(),o=n.parse(i);return t?.onSuccess?.(),typeof window<`u`&&window.location.reload(),{success:!0,data:o}}catch(e){let n=e instanceof Error?e:Error(`Unknown error`);return t?.onError?.(n),{success:!1,error:n}}}export{a as ApiErrorSchema,n as DisableResponseSchema,i as EnableResponseSchema,t as ModificationSchema,e as ModificationsListSchema,r as ModifyResponseSchema,l as disableModification,c as enableModification,o as listModifications,s as modifyWithAI};
1
+ import{a as e,i as t,n,o as r,r as i,t as a}from"./types-V6wytIkL.js";async function o({id:t}){let n=await fetch(`/api/mwai/api/list`);if(!n.ok)throw Error(`Failed to fetch modifications`);let r=await n.json();return e.parse(r)}async function s({id:e,prompt:t},n){let i=t.trim();if(!i){let e=Error(`Prompt cannot be empty`);return n?.onError?.(e),{error:e}}try{let e=await fetch(`/api/mwai/api/modify`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({prompt:i})});if(!e.ok){let t=await e.json().catch(()=>({})),n=a.safeParse(t),r=n.success&&(n.data.message||n.data.error)||`Failed to submit modification`;throw Error(r)}let t=await e.json(),o=r.parse(t);return n?.onSuccess?.(),{modificationId:o.modificationId}}catch(e){let t=e instanceof Error?e:Error(`Unknown error`);return n?.onError?.(t),{error:t}}}async function c({modificationId:e},t){try{let n=await fetch(`/api/mwai/api/enable`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({modificationId:e})});if(!n.ok){let e=await n.json().catch(()=>({})),t=a.safeParse(e),r=t.success&&(t.data.message||t.data.error)||`Failed to enable modification`;throw Error(r)}let r=await n.json(),o=i.parse(r);return t?.onSuccess?.(),{success:!0,data:o}}catch(e){let n=e instanceof Error?e:Error(`Unknown error`);return t?.onError?.(n),{success:!1,error:n}}}async function l({modificationId:e},t){try{let r=await fetch(`/api/mwai/api/disable`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({modificationId:e})});if(!r.ok){let e=await r.json().catch(()=>({})),t=a.safeParse(e),n=t.success&&(t.data.message||t.data.error)||`Failed to disable modification`;throw Error(n)}let i=await r.json(),o=n.parse(i);return t?.onSuccess?.(),{success:!0,data:o}}catch(e){let n=e instanceof Error?e:Error(`Unknown error`);return t?.onError?.(n),{success:!1,error:n}}}export{a as ApiErrorSchema,n as DisableResponseSchema,i as EnableResponseSchema,t as ModificationSchema,e as ModificationsListSchema,r as ModifyResponseSchema,l as disableModification,c as enableModification,o as listModifications,s as modifyWithAI};
@@ -3,28 +3,28 @@ import { NextRequest } from "next/server";
3
3
  //#region src/nextjs/api.d.ts
4
4
  type CreateApiProxyHandlerOptions = {
5
5
  /**
6
- * The app ID for this MWAI application
7
- * This identifies your app in the modifywithai system
8
- */
6
+ * The app ID for this MWAI application
7
+ * This identifies your app in the modifywithai system
8
+ */
9
9
  appId: string;
10
10
  /**
11
- * Base URL of the modifywithai service
12
- * @default "https://modifywithai.com"
13
- */
11
+ * Base URL of the modifywithai service
12
+ * @default "https://modifywithai.com"
13
+ */
14
14
  baseUrl?: string;
15
15
  /**
16
- * API key for authenticating with the modifywithai service
17
- * @default process.env.MWAI_API_KEY
18
- */
16
+ * API key for authenticating with the modifywithai service
17
+ * @default process.env.MWAI_API_KEY
18
+ */
19
19
  apiKey?: string;
20
20
  /**
21
- * Function to get the end user's ID from the request
22
- * This will be injected into API calls that require endUserId
23
- */
21
+ * Function to get the end user's ID from the request
22
+ * This will be injected into API calls that require endUserId
23
+ */
24
24
  getEndUserId: (request: NextRequest) => Promise<string | null>;
25
25
  };
26
26
  declare function generateStaticParams(): Promise<{
27
- path: "list" | "enable" | "disable" | "modify" | "status";
27
+ path: "status" | "list" | "enable" | "disable" | "router";
28
28
  }[]>;
29
29
  declare function createNextjsHandler(options: CreateApiProxyHandlerOptions): {
30
30
  GET: (request: NextRequest, {
@@ -1 +1 @@
1
- import{NextResponse as e}from"next/server";const t=[`list`,`enable`,`disable`,`modify`,`status`],n={modify:{method:`POST`,inBody:!0,needsEndUserId:!0},disable:{method:`POST`,inBody:!0,needsEndUserId:!0},enable:{method:`POST`,inBody:!0,needsEndUserId:!0},list:{method:`GET`,inBody:!1,needsEndUserId:!1},status:{method:`GET`,inBody:!1,needsEndUserId:!1}};async function r(){return t.map(e=>({path:e}))}function i(r){let{appId:i,baseUrl:a=`https://modifywithai.com`,apiKey:o=process.env.MWAI_API_KEY,getEndUserId:s}=r;if(!o)throw Error(`MWAI API key is required. Provide it via the apiKey option or set the MWAI_API_KEY environment variable.`);async function c(r,{params:c}){let l=(await c).path;if(!t.includes(l))return e.json({error:`Not found`},{status:404});let u=n[l],d=await s(r);if(u.needsEndUserId&&!d)return e.json({error:`Unauthorized - end user ID required`},{status:401});let f=new URL(`/api/${l}`,a);r.nextUrl.searchParams.forEach((e,t)=>{f.searchParams.set(t,e)});let p=new Headers({"Content-Type":`application/json`,"x-api-key":o}),m;if(r.method===`POST`||r.method===`PUT`||r.method===`PATCH`)try{let e=await r.json();e.appId=i,u.needsEndUserId&&d&&(e.endUserId=d),m=JSON.stringify(e)}catch{let e={appId:i};u.needsEndUserId&&d&&(e.endUserId=d),m=JSON.stringify(e)}r.method===`GET`&&(f.searchParams.set(`appId`,i),d&&f.searchParams.set(`endUserId`,d));let h=await fetch(f.toString(),{method:r.method,headers:p,body:m}),g=await h.text();return new Response(g,{status:h.status,statusText:h.statusText,headers:{"Content-Type":h.headers.get(`Content-Type`)||`application/json`}})}return{GET:c,POST:c,PUT:c,PATCH:c,DELETE:c}}export{i as createNextjsHandler,r as generateStaticParams};
1
+ import{NextResponse as e}from"next/server";const t=[`list`,`enable`,`disable`,`router`,`status`],n={router:{method:`POST`,inBody:!0,needsEndUserId:!0},disable:{method:`POST`,inBody:!0,needsEndUserId:!0},enable:{method:`POST`,inBody:!0,needsEndUserId:!0},list:{method:`GET`,inBody:!1,needsEndUserId:!1},status:{method:`GET`,inBody:!1,needsEndUserId:!1}};async function r(){return t.map(e=>({path:e}))}function i(r){let{appId:i,baseUrl:a=`https://modifywithai.com`,apiKey:o=process.env.MWAI_API_KEY,getEndUserId:s}=r;if(!o)throw Error(`MWAI API key is required. Provide it via the apiKey option or set the MWAI_API_KEY environment variable.`);async function c(r,{params:c}){let l=(await c).path;if(!t.includes(l))return e.json({error:`Not found`},{status:404});let u=n[l],d=await s(r);if(u.needsEndUserId&&!d)return e.json({error:`Unauthorized - end user ID required`},{status:401});let f=new URL(`/api/${l}`,a);r.nextUrl.searchParams.forEach((e,t)=>{f.searchParams.set(t,e)});let p=new Headers({"Content-Type":`application/json`,"x-api-key":o}),m;if(r.method===`POST`||r.method===`PUT`||r.method===`PATCH`)try{let e=await r.json();e.appId=i,u.needsEndUserId&&d&&(e.endUserId=d),m=JSON.stringify(e)}catch{let e={appId:i};u.needsEndUserId&&d&&(e.endUserId=d),m=JSON.stringify(e)}r.method===`GET`&&(f.searchParams.set(`appId`,i),d&&f.searchParams.set(`endUserId`,d));let h=await fetch(f.toString(),{method:r.method,headers:p,body:m}),g=await h.text();return new Response(g,{status:h.status,statusText:h.statusText,headers:{"Content-Type":h.headers.get(`Content-Type`)||`application/json`}})}return{GET:c,POST:c,PUT:c,PATCH:c,DELETE:c}}export{i as createNextjsHandler,r as generateStaticParams};
@@ -1,78 +1 @@
1
- const e={"react-shim.js":`// Re-export React from the window object (set by the app)
2
- const React = window.__REACT__;
3
- export default React;
4
- export const {
5
- useState,
6
- useEffect,
7
- useLayoutEffect,
8
- useRef,
9
- useCallback,
10
- useMemo,
11
- useContext,
12
- useReducer,
13
- useId,
14
- useTransition,
15
- useDeferredValue,
16
- useImperativeHandle,
17
- useDebugValue,
18
- useSyncExternalStore,
19
- useInsertionEffect,
20
- createElement,
21
- createContext,
22
- createRef,
23
- forwardRef,
24
- memo,
25
- lazy,
26
- Suspense,
27
- Fragment,
28
- Children,
29
- cloneElement,
30
- isValidElement,
31
- Component,
32
- PureComponent,
33
- StrictMode,
34
- startTransition,
35
- use,
36
- } = React;
37
- `,"react-jsx-shim.js":`// Re-export jsx-runtime from the window object (set by the app)
38
- const jsxRuntime = window.__REACT_JSX_RUNTIME__;
39
- export const jsx = jsxRuntime?.jsx;
40
- export const jsxs = jsxRuntime?.jsxs;
41
- export const Fragment = jsxRuntime?.Fragment;
42
- `,"react-dom-shim.js":`// Re-export ReactDOM from the window object (set by the app)
43
- const ReactDOM = window.__REACT_DOM__
44
- export default ReactDOM
45
- export const {
46
- createPortal,
47
- flushSync,
48
- findDOMNode,
49
- hydrate,
50
- render,
51
- unmountComponentAtNode,
52
- unstable_batchedUpdates,
53
- version,
54
- } = ReactDOM || {}
55
- `,"react-dom-client-shim.js":`// Re-export ReactDOM/client from the window object (set by the app)
56
- const ReactDOMClient = window.__REACT_DOM_CLIENT__;
57
- export const createRoot = ReactDOMClient?.createRoot;
58
- export const hydrateRoot = ReactDOMClient?.hydrateRoot;
59
- export default ReactDOMClient;
60
- `,"next-link-shim.js":`// Re-export next/link from the window object (set by the app)
61
- const NextLink = window.__NEXT_LINK__;
62
- export default NextLink;
63
- `,"next-image-shim.js":`// Re-export next/image from the window object (set by the app)
64
- const NextImage = window.__NEXT_IMAGE__;
65
- export default NextImage;
66
- `,"next-navigation-shim.js":`// Re-export next/navigation from the window object (set by the app)
67
- const NextNavigation = window.__NEXT_NAVIGATION__;
68
- export const useRouter = NextNavigation?.useRouter;
69
- export const usePathname = NextNavigation?.usePathname;
70
- export const useSearchParams = NextNavigation?.useSearchParams;
71
- export const useParams = NextNavigation?.useParams;
72
- export const useSelectedLayoutSegment = NextNavigation?.useSelectedLayoutSegment;
73
- export const useSelectedLayoutSegments = NextNavigation?.useSelectedLayoutSegments;
74
- export const redirect = NextNavigation?.redirect;
75
- export const notFound = NextNavigation?.notFound;
76
- export const permanentRedirect = NextNavigation?.permanentRedirect;
77
- export default NextNavigation;
78
- `};async function t(){return Object.keys(e).map(e=>({path:e}))}const n=async(t,{params:n})=>{let r=(await n).path;return new Response(e[r],{headers:{"Content-Type":`application/javascript`,"Cache-Control":`public, max-age=31536000, immutable`}})};export{n as GET,t as generateStaticParams};
1
+ import{t as e}from"../shims-C5D8K0uz.js";async function t(){return Object.keys(e).map(e=>({path:e}))}const n=async(t,{params:n})=>{let r=(await n).path;return new Response(e[r],{headers:{"Content-Type":`application/javascript`,"Cache-Control":`public, max-age=31536000, immutable`}})};export{n as GET,t as generateStaticParams};