modifywithai 1.7.1 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AGENTS.md CHANGED
@@ -77,6 +77,7 @@ export { generateStaticParams } from "modifywithai/nextjs/api"
77
77
  export const dynamicParams = false
78
78
 
79
79
  export const { GET, POST, PUT, PATCH, DELETE } = createNextjsHandler({
80
+ appId: "{{MWAI_APP_ID}}", // Your MWAI app ID from the dashboard
80
81
  getEndUserId: async (request) => {
81
82
  // TODO: Implement user ID retrieval based on the project's auth system
82
83
  // Return the current user's ID as a string
@@ -97,6 +98,7 @@ export { generateStaticParams } from "modifywithai/nextjs/api"
97
98
  export const dynamicParams = false
98
99
 
99
100
  export const { GET, POST, PUT, PATCH, DELETE } = createNextjsHandler({
101
+ appId: "{{MWAI_APP_ID}}", // Your MWAI app ID from the dashboard
100
102
  getEndUserId: async (request) => {
101
103
  const session = await auth.api.getSession({
102
104
  headers: request.headers,
@@ -2,6 +2,11 @@ import { NextRequest } from "next/server";
2
2
 
3
3
  //#region src/nextjs/api.d.ts
4
4
  type CreateApiProxyHandlerOptions = {
5
+ /**
6
+ * The app ID for this MWAI application
7
+ * This identifies your app in the modifywithai system
8
+ */
9
+ appId: string;
5
10
  /**
6
11
  * Base URL of the modifywithai service
7
12
  * @default "https://modifywithai.com"
@@ -1 +1 @@
1
- import{NextResponse as e}from"next/server";const t=[`list`,`enable`,`disable`,`modify`,`status`],n={modify:{method:`POST`,inBody:!0},disable:{method:`POST`,inBody:!0},enable:{method:`POST`,inBody:!0},list:{method:`GET`,inBody:!1}};async function r(){return t.map(e=>({path:e}))}function i(r){let{baseUrl:i=`https://modifywithai.com`,apiKey:a=process.env.MWAI_API_KEY,getEndUserId:o}=r;if(!a)throw Error(`MWAI API key is required. Provide it via the apiKey option or set the MWAI_API_KEY environment variable.`);async function s(r,{params:s}){let c=(await s).path;if(!t.includes(c))return e.json({error:`Not found`},{status:404});let l=c,u=await o(r),d=n[l];if(d&&!u)return e.json({error:`Unauthorized - end user ID required`},{status:401});let f=new URL(`/api/${c}`,i);r.nextUrl.searchParams.forEach((e,t)=>{f.searchParams.set(t,e)});let p=new Headers({"Content-Type":`application/json`,"x-api-key":a}),m;if(r.method===`POST`||r.method===`PUT`||r.method===`PATCH`)try{let e=await r.json();d?.inBody&&u&&(e.endUserId=u),m=JSON.stringify(e)}catch{}r.method===`GET`&&d&&!d.inBody&&u&&f.searchParams.set(`endUserId`,u);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:s,POST:s,PUT:s,PATCH:s,DELETE:s}}export{i as createNextjsHandler,r as generateStaticParams};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "modifywithai",
3
- "version": "1.7.1",
3
+ "version": "1.8.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",