@obelism/improve-sdk-next 1.1.1 → 1.1.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-2026 Obelism
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sources":["../src/index.ts"],"mappings":";;;;;AAKA,KAAK,YAAY;AACjB;AACA;AACA;AACA,KAAK,kBAAkB;AACvB;AACA;AACA,uBAAuB,OAAO,kBAAkB,YAAY,KAAK,OAAO;AACxE,aAAa,YAAY;AACzB;AACA,KAAK,iCAAiC;AACtC,gBAAgB,gBAAgB;AAChC,mBAAmB,kBAAkB;AACrC;AACA,oBAAoB,cAAc;AAClC,oBAAoB,cAAc;AAClC;AACA;AACA,cAAc,6BAA6B,SAAS,iCAAiC,eAAe,WAAW,KAAK,YAAY;;;;","names":[]}
1
+ {"version":3,"file":"index.d.mts","sources":["../src/index.ts"],"mappings":";;;;;AAKA,KAAK,YAAY;AACjB;AACA;AACA;AACA,KAAK,kBAAkB;AACvB;AACA;AACA,uBAAuB,OAAO,kBAAkB,YAAY,KAAK,OAAO;AACxE,aAAa,YAAY;AACzB;AACA,KAAK,iCAAiC;AACtC,gBAAgB,gBAAgB;AAChC,mBAAmB,kBAAkB;AACrC;AACA,oBAAoB,cAAc;AAClC,oBAAoB,cAAc;AAClC;AACA;AACA,cAAc,6BAA6B,SAAS,iCAAiC,eAAe,WAAW,KAAK,YAAY;;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sources":["../src/index.ts"],"mappings":";;;;;AAKA,KAAK,YAAY;AACjB;AACA;AACA;AACA,KAAK,kBAAkB;AACvB;AACA;AACA,uBAAuB,OAAO,kBAAkB,YAAY,KAAK,OAAO;AACxE,aAAa,YAAY;AACzB;AACA,KAAK,iCAAiC;AACtC,gBAAgB,gBAAgB;AAChC,mBAAmB,kBAAkB;AACrC;AACA,oBAAoB,cAAc;AAClC,oBAAoB,cAAc;AAClC;AACA;AACA,cAAc,6BAA6B,SAAS,iCAAiC,eAAe,WAAW,KAAK,YAAY;;;;","names":[]}
1
+ {"version":3,"file":"index.d.ts","sources":["../src/index.ts"],"mappings":";;;;;AAKA,KAAK,YAAY;AACjB;AACA;AACA;AACA,KAAK,kBAAkB;AACvB;AACA;AACA,uBAAuB,OAAO,kBAAkB,YAAY,KAAK,OAAO;AACxE,aAAa,YAAY;AACzB;AACA,KAAK,iCAAiC;AACtC,gBAAgB,gBAAgB;AAChC,mBAAmB,kBAAkB;AACrC;AACA,oBAAoB,cAAc;AAClC,oBAAoB,cAAc;AAClC;AACA;AACA,cAAc,6BAA6B,SAAS,iCAAiC,eAAe,WAAW,KAAK,YAAY;;","names":[]}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/server");let t=RegExp(["Vercelbot","DotBot","Yeti","AhrefsBot","SeznamBot","YandexBot","UptimeRobot","Bytespider","Baiduspider","fidget-spinner-bot","AASA-Bot","FullStoryBot","SemrushBot","PetalBot","RyteBot","Pinterestbot","AntBot","Monsidobot","blowra","JobRoboter","Qwantify","YisouSpider"].map(e=>e.toLowerCase()).join("|"),"i"),o=/(\[[a-zA-Z0-9-]+\])+/g,r=/\[\[\.\.\.[a-zA-Z0-9-]+\]\]/g,s=/\[\.\.\.[a-zA-Z0-9-]+\]/g,n=e=>e.endsWith("/")?e.substring(0,e.length-1):e,i=new Map;exports.generateImproveNextMiddleware=a=>l=>{try{let p,{ua:u="",isBot:g=!1}=e.userAgent(l);if(g||u&&t.test(u.toLowerCase()))return e.NextResponse.next();let d=a.serverABtests.find(e=>((e,t)=>{let a=n(t.split("?")[0]),l=n(e.split("?")[0]);if(a===l)return!0;let p=i.get(l);return p||(p=new RegExp(`^${l.replace(o,"[a-zA-Z0-9-]+")}$`.replace(r,"?.*").replace(s,".*")),i.set(l,p)),p.test(a)})(e.routeHandler,l.nextUrl.pathname));if(!d)return e.NextResponse.next();let x=d.options.at(0)?.value;if(!x)return e.NextResponse.next();let v=a.improveSdk.getVisitorCookieName(),m=l.cookies.get(v)?.value,c=m&&a.improveSdk.validateVisitorId(m)?m:a.improveSdk.generateVisitorId(),f=e=>e&&a.improveSdk.validateTestValue(d.slug,e)?e:null,A={country:l.headers.get("x-vercel-ip-country")??l.headers.get("cf-ipcountry")??void 0},B=f(l.nextUrl.searchParams.get(d.slug))||f(l.cookies.get(d.slug)?.value)||a.improveSdk.getTestValue(d.slug,c,u,A),S=d.options.find(e=>e.value===B);if(!S)return e.NextResponse.next();if(S.value!==x){let t=l.nextUrl.clone();t.pathname=d?.formatSlug?d?.formatSlug(t,S)?.pathname:S.slug,p=e.NextResponse.rewrite(t)}else p=e.NextResponse.next();return p.cookies.set(v,c,{maxAge:604800,...a.options?.visitorId}),p.cookies.set(d.slug,B,{maxAge:604800,...a.options?.testValue}),p}catch(t){return console.error("[Improve SDK]",t),e.NextResponse.next()}};
1
+ Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/server");let t=RegExp(["Vercelbot","DotBot","Yeti","AhrefsBot","SeznamBot","YandexBot","UptimeRobot","Bytespider","Baiduspider","fidget-spinner-bot","AASA-Bot","FullStoryBot","SemrushBot","PetalBot","RyteBot","Pinterestbot","AntBot","Monsidobot","blowra","JobRoboter","Qwantify","YisouSpider"].map(e=>e.toLowerCase()).join("|"),"i"),o=/(\[[a-zA-Z0-9-]+\])+/g,r=/\[\[\.\.\.[a-zA-Z0-9-]+\]\]/g,s=/\[\.\.\.[a-zA-Z0-9-]+\]/g,i=e=>e.endsWith("/")?e.substring(0,e.length-1):e,n=new Map;exports.generateImproveNextMiddleware=a=>l=>{try{let p,{ua:u="",isBot:g=!1}=e.userAgent(l);if(g||u&&t.test(u.toLowerCase()))return e.NextResponse.next();let d=a.serverABtests.find(e=>((e,t)=>{let a=i(t.split("?")[0]),l=i(e.split("?")[0]);if(a===l)return!0;let p=n.get(l);return p||(p=new RegExp(`^${l.replace(o,"[a-zA-Z0-9-]+")}$`.replace(r,"?.*").replace(s,".*")),n.set(l,p)),p.test(a)})(e.routeHandler,l.nextUrl.pathname));if(!d)return e.NextResponse.next();let x=d.options.at(0)?.value;if(!x)return e.NextResponse.next();let v=a.improveSdk.getVisitorCookieName(),c=l.cookies.get(v)?.value??l.cookies.get("visitorId")?.value,m=c&&a.improveSdk.validateVisitorId(c)?c:a.improveSdk.generateVisitorId(),f=e=>e&&a.improveSdk.validateTestValue(d.slug,e)?e:null,A={country:l.headers.get("x-vercel-ip-country")??l.headers.get("cf-ipcountry")??void 0},B=f(l.nextUrl.searchParams.get(d.slug))||f(l.cookies.get(d.slug)?.value)||a.improveSdk.getTestValue(d.slug,m,u,A),S=d.options.find(e=>e.value===B);if(null==B||!S)return e.NextResponse.next();if(S.value!==x){let t=l.nextUrl.clone();t.pathname=d?.formatSlug?d?.formatSlug(t,S)?.pathname:S.slug,p=e.NextResponse.rewrite(t)}else p=e.NextResponse.next();return p.cookies.set(v,m,{maxAge:604800,...a.options?.visitorId}),p.cookies.set(d.slug,B,{maxAge:604800,...a.options?.testValue}),p}catch(t){return console.error("[Improve SDK]",t),e.NextResponse.next()}};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/extendedBotCheck.ts","../src/matchesRoute.ts","../src/index.ts"],"sourcesContent":["const EXTENDED_BOT_REGEX = new RegExp(\n\t[\n\t\t'Vercelbot',\n\t\t'DotBot',\n\t\t'Yeti',\n\t\t'AhrefsBot',\n\t\t'SeznamBot',\n\t\t'YandexBot',\n\t\t'UptimeRobot',\n\t\t'Bytespider',\n\t\t'Baiduspider',\n\t\t'fidget-spinner-bot',\n\t\t'AASA-Bot',\n\t\t'FullStoryBot',\n\t\t'SemrushBot',\n\t\t'PetalBot',\n\t\t'RyteBot',\n\t\t'Pinterestbot',\n\t\t'AntBot',\n\t\t'Monsidobot',\n\t\t'blowra',\n\t\t'JobRoboter',\n\t\t'Qwantify',\n\t\t'YisouSpider',\n\t]\n\t\t.map((name) => name.toLowerCase())\n\t\t.join('|'),\n\t'i',\n)\n\nexport const extendedBotCheck = (userAgent: string): boolean => {\n\tif (!userAgent) return false\n\treturn EXTENDED_BOT_REGEX.test(userAgent.toLowerCase())\n}\n","const BASE_REGEX = /(\\[[a-zA-Z0-9-]+\\])+/g\n\nconst SECONDARY_REGEX = /\\[\\[\\.\\.\\.[a-zA-Z0-9-]+\\]\\]/g\n\nconst TERTIARY_REGEX = /\\[\\.\\.\\.[a-zA-Z0-9-]+\\]/g\n\nexport const removeTrailingSlash = (val: string) =>\n\tval.endsWith('/') ? val.substring(0, val.length - 1) : val\n\nconst regexCache = new Map<string, RegExp>()\n\nexport const matchesRoute = (route: string, pathname: string) => {\n\tconst basePathname = removeTrailingSlash(pathname.split('?')[0] as string)\n\tconst baseRoute = removeTrailingSlash(route.split('?')[0] as string)\n\n\tif (basePathname === baseRoute) return true\n\n\tlet routeRegex = regexCache.get(baseRoute)\n\tif (!routeRegex) {\n\t\trouteRegex = new RegExp(\n\t\t\t`^${baseRoute.replace(BASE_REGEX, '[a-zA-Z0-9-]+')}$`\n\t\t\t\t.replace(SECONDARY_REGEX, '?.*')\n\t\t\t\t.replace(TERTIARY_REGEX, '.*'),\n\t\t)\n\t\tregexCache.set(baseRoute, routeRegex)\n\t}\n\n\treturn routeRegex.test(basePathname)\n}\n","import { ImproveServerSDK } from '@obelism/improve-sdk/server'\nimport type { NextURL } from 'next/dist/server/web/next-url'\nimport type { NextRequest } from 'next/server'\nimport { NextResponse, userAgent } from 'next/server'\n\nimport { extendedBotCheck } from './extendedBotCheck'\nimport { matchesRoute } from './matchesRoute'\nimport type { ResponseCookie } from 'next/dist/compiled/@edge-runtime/cookies'\n\nconst DEFAULT_COOKIE_TTL = 60 * 60 * 24 * 7\n\nexport type OptionConfig = { value: string; slug: string }\n\nexport type ServerABTestConfig = {\n\tslug: string\n\trouteHandler: string\n\tformatSlug?: (url: NextURL, matchingOption: OptionConfig) => NextURL\n\toptions: OptionConfig[]\n}\n\nexport type GenerateImproveNextMiddlewareArgs = {\n\timproveSdk: ImproveServerSDK\n\tserverABtests: ServerABTestConfig[]\n\toptions?: {\n\t\tvisitorId?: ResponseCookie\n\t\ttestValue?: ResponseCookie\n\t}\n}\n\nexport const generateImproveNextMiddleware = (\n\targs: GenerateImproveNextMiddlewareArgs,\n) => {\n\treturn (request: NextRequest) => {\n\t\ttry {\n\t\t\t// Early esacape for bots that shouldn't be getting AB tested\n\t\t\tconst { ua = '', isBot = false } = userAgent(request)\n\t\t\tif (isBot || extendedBotCheck(ua)) return NextResponse.next()\n\n\t\t\t// When there is no (valid) server AB config escape\n\t\t\tconst serverABTestConfig = args.serverABtests.find((route) =>\n\t\t\t\tmatchesRoute(route.routeHandler, request.nextUrl.pathname),\n\t\t\t)\n\t\t\tif (!serverABTestConfig) return NextResponse.next()\n\n\t\t\tconst basePath = serverABTestConfig.options.at(0)?.value\n\n\t\t\tif (!basePath) return NextResponse.next()\n\n\t\t\tconst visitorCookieName = args.improveSdk.getVisitorCookieName()\n\t\t\tconst cookieVisitorId = request.cookies.get(visitorCookieName)?.value\n\t\t\tconst validCookieVisitorId =\n\t\t\t\tcookieVisitorId && args.improveSdk.validateVisitorId(cookieVisitorId)\n\t\t\tconst visitorId = validCookieVisitorId\n\t\t\t\t? cookieVisitorId\n\t\t\t\t: args.improveSdk.generateVisitorId()\n\n\t\t\tconst validateValue = (value: string | null | undefined) => {\n\t\t\t\treturn value &&\n\t\t\t\t\targs.improveSdk.validateTestValue(serverABTestConfig.slug, value)\n\t\t\t\t\t? value\n\t\t\t\t\t: null\n\t\t\t}\n\n\t\t\t// Coarse geo from the edge, so country-targeted audiences resolve\n\t\t\t// server-side (the browser can't determine country). Vercel sets\n\t\t\t// x-vercel-ip-country; Cloudflare sets cf-ipcountry.\n\t\t\tconst geo = {\n\t\t\t\tcountry:\n\t\t\t\t\trequest.headers.get('x-vercel-ip-country') ??\n\t\t\t\t\trequest.headers.get('cf-ipcountry') ??\n\t\t\t\t\tundefined,\n\t\t\t}\n\n\t\t\t// Get AB test value from: searchParam, cookies or get generate a new value\n\t\t\tconst testValue =\n\t\t\t\tvalidateValue(\n\t\t\t\t\trequest.nextUrl.searchParams.get(serverABTestConfig.slug),\n\t\t\t\t) ||\n\t\t\t\tvalidateValue(request.cookies.get(serverABTestConfig.slug)?.value) ||\n\t\t\t\targs.improveSdk.getTestValue(\n\t\t\t\t\tserverABTestConfig.slug,\n\t\t\t\t\tvisitorId,\n\t\t\t\t\tua,\n\t\t\t\t\tgeo,\n\t\t\t\t)\n\n\t\t\tconst testMatchOption = serverABTestConfig.options.find(\n\t\t\t\t(option) => option.value === testValue,\n\t\t\t)\n\n\t\t\tif (!testMatchOption) return NextResponse.next()\n\n\t\t\t// Update the response with cookies response\n\t\t\tlet response: undefined | NextResponse<unknown>\n\n\t\t\tif (testMatchOption.value !== basePath) {\n\t\t\t\tconst url = request.nextUrl.clone()\n\n\t\t\t\turl.pathname = serverABTestConfig?.formatSlug\n\t\t\t\t\t? serverABTestConfig?.formatSlug(url, testMatchOption)?.pathname\n\t\t\t\t\t: testMatchOption.slug\n\n\t\t\t\tresponse = NextResponse.rewrite(url)\n\t\t\t} else {\n\t\t\t\tresponse = NextResponse.next()\n\t\t\t}\n\n\t\t\tresponse.cookies.set(visitorCookieName, visitorId, {\n\t\t\t\tmaxAge: DEFAULT_COOKIE_TTL,\n\t\t\t\t...args.options?.visitorId,\n\t\t\t})\n\t\t\tresponse.cookies.set(serverABTestConfig.slug, testValue, {\n\t\t\t\tmaxAge: DEFAULT_COOKIE_TTL,\n\t\t\t\t...args.options?.testValue,\n\t\t\t})\n\n\t\t\treturn response\n\t\t} catch (e) {\n\t\t\tconsole.error('[Improve SDK]', e)\n\t\t\treturn NextResponse.next()\n\t\t}\n\t}\n}\n"],"names":["EXTENDED_BOT_REGEX","RegExp","map","name","toLowerCase","join","BASE_REGEX","SECONDARY_REGEX","TERTIARY_REGEX","removeTrailingSlash","val","endsWith","substring","length","regexCache","Map","args","request","response","ua","isBot","userAgent","test","NextResponse","next","serverABTestConfig","serverABtests","find","route","matchesRoute","pathname","basePathname","split","baseRoute","routeRegex","get","replace","set","routeHandler","nextUrl","basePath","options","at","value","visitorCookieName","improveSdk","getVisitorCookieName","cookieVisitorId","cookies","visitorId","validCookieVisitorId","validateVisitorId","generateVisitorId","validateValue","validateTestValue","slug","geo","country","headers","undefined","testValue","searchParams","getTestValue","testMatchOption","option","url","clone","formatSlug","rewrite","maxAge","e","console","error"],"mappings":"oFAAA,IAAMA,EAAqB,AAAIC,OAC9B,CACC,YACA,SACA,OACA,YACA,YACA,YACA,cACA,aACA,cACA,qBACA,WACA,eACA,aACA,WACA,UACA,eACA,SACA,aACA,SACA,aACA,WACA,cACA,CACCC,GAAG,CAAC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EAAS8B,OAAO,CAACX,GAAG,CAACO,EAAmBK,EAAW,CAClDoB,OAnGuB,OAoGvB,GAAGrD,EAAKyB,OAAO,EAAEQ,SAAAA,AAClB,GACA/B,EAAS8B,OAAO,CAACX,GAAG,CAACZ,EAAmB8B,IAAI,CAAEK,EAAW,CACxDS,OAvGuB,OAwGvB,GAAGrD,EAAKyB,OAAO,EAAEmB,SAAAA,AAClB,GAEO1C,CACR,CAAE,MAAOoD,EAAG,CAEX,OADAC,QAAQC,KAAK,CAAC,gBAAiBF,GACxB/C,EAAAA,aAAaC,IAAI,EACzB,CACD"}
1
+ {"version":3,"file":"index.js","sources":["../src/extendedBotCheck.ts","../src/matchesRoute.ts","../src/index.ts"],"sourcesContent":["const EXTENDED_BOT_REGEX = new RegExp(\n\t[\n\t\t'Vercelbot',\n\t\t'DotBot',\n\t\t'Yeti',\n\t\t'AhrefsBot',\n\t\t'SeznamBot',\n\t\t'YandexBot',\n\t\t'UptimeRobot',\n\t\t'Bytespider',\n\t\t'Baiduspider',\n\t\t'fidget-spinner-bot',\n\t\t'AASA-Bot',\n\t\t'FullStoryBot',\n\t\t'SemrushBot',\n\t\t'PetalBot',\n\t\t'RyteBot',\n\t\t'Pinterestbot',\n\t\t'AntBot',\n\t\t'Monsidobot',\n\t\t'blowra',\n\t\t'JobRoboter',\n\t\t'Qwantify',\n\t\t'YisouSpider',\n\t]\n\t\t.map((name) => name.toLowerCase())\n\t\t.join('|'),\n\t'i',\n)\n\nexport const extendedBotCheck = (userAgent: string): boolean => {\n\tif (!userAgent) return false\n\treturn EXTENDED_BOT_REGEX.test(userAgent.toLowerCase())\n}\n","const BASE_REGEX = /(\\[[a-zA-Z0-9-]+\\])+/g\n\nconst SECONDARY_REGEX = /\\[\\[\\.\\.\\.[a-zA-Z0-9-]+\\]\\]/g\n\nconst TERTIARY_REGEX = /\\[\\.\\.\\.[a-zA-Z0-9-]+\\]/g\n\nexport const removeTrailingSlash = (val: string) =>\n\tval.endsWith('/') ? val.substring(0, val.length - 1) : val\n\nconst regexCache = new Map<string, RegExp>()\n\nexport const matchesRoute = (route: string, pathname: string) => {\n\tconst basePathname = removeTrailingSlash(pathname.split('?')[0] as string)\n\tconst baseRoute = removeTrailingSlash(route.split('?')[0] as string)\n\n\tif (basePathname === baseRoute) return true\n\n\tlet routeRegex = regexCache.get(baseRoute)\n\tif (!routeRegex) {\n\t\trouteRegex = new RegExp(\n\t\t\t`^${baseRoute.replace(BASE_REGEX, '[a-zA-Z0-9-]+')}$`\n\t\t\t\t.replace(SECONDARY_REGEX, '?.*')\n\t\t\t\t.replace(TERTIARY_REGEX, '.*'),\n\t\t)\n\t\tregexCache.set(baseRoute, routeRegex)\n\t}\n\n\treturn routeRegex.test(basePathname)\n}\n","import { ImproveServerSDK } from '@obelism/improve-sdk/server'\nimport type { NextURL } from 'next/dist/server/web/next-url'\nimport type { NextRequest } from 'next/server'\nimport { NextResponse, userAgent } from 'next/server'\n\nimport { extendedBotCheck } from './extendedBotCheck'\nimport { matchesRoute } from './matchesRoute'\nimport type { ResponseCookie } from 'next/dist/compiled/@edge-runtime/cookies'\n\nconst DEFAULT_COOKIE_TTL = 60 * 60 * 24 * 7\n\nexport type OptionConfig = { value: string; slug: string }\n\nexport type ServerABTestConfig = {\n\tslug: string\n\trouteHandler: string\n\tformatSlug?: (url: NextURL, matchingOption: OptionConfig) => NextURL\n\toptions: OptionConfig[]\n}\n\nexport type GenerateImproveNextMiddlewareArgs = {\n\timproveSdk: ImproveServerSDK\n\tserverABtests: ServerABTestConfig[]\n\toptions?: {\n\t\tvisitorId?: ResponseCookie\n\t\ttestValue?: ResponseCookie\n\t}\n}\n\nexport const generateImproveNextMiddleware = (\n\targs: GenerateImproveNextMiddlewareArgs,\n) => {\n\treturn (request: NextRequest) => {\n\t\ttry {\n\t\t\t// Early esacape for bots that shouldn't be getting AB tested\n\t\t\tconst { ua = '', isBot = false } = userAgent(request)\n\t\t\tif (isBot || extendedBotCheck(ua)) return NextResponse.next()\n\n\t\t\t// When there is no (valid) server AB config escape\n\t\t\tconst serverABTestConfig = args.serverABtests.find((route) =>\n\t\t\t\tmatchesRoute(route.routeHandler, request.nextUrl.pathname),\n\t\t\t)\n\t\t\tif (!serverABTestConfig) return NextResponse.next()\n\n\t\t\tconst basePath = serverABTestConfig.options.at(0)?.value\n\n\t\t\tif (!basePath) return NextResponse.next()\n\n\t\t\tconst visitorCookieName = args.improveSdk.getVisitorCookieName()\n\t\t\t// The name before it was namespaced: keep an existing visitor.\n\t\t\tconst cookieVisitorId =\n\t\t\t\trequest.cookies.get(visitorCookieName)?.value ??\n\t\t\t\trequest.cookies.get('visitorId')?.value\n\t\t\tconst validCookieVisitorId =\n\t\t\t\tcookieVisitorId && args.improveSdk.validateVisitorId(cookieVisitorId)\n\t\t\tconst visitorId = validCookieVisitorId\n\t\t\t\t? cookieVisitorId\n\t\t\t\t: args.improveSdk.generateVisitorId()\n\n\t\t\tconst validateValue = (value: string | null | undefined) => {\n\t\t\t\treturn value &&\n\t\t\t\t\targs.improveSdk.validateTestValue(serverABTestConfig.slug, value)\n\t\t\t\t\t? value\n\t\t\t\t\t: null\n\t\t\t}\n\n\t\t\t// Coarse geo from the edge, so country-targeted audiences resolve\n\t\t\t// server-side (the browser can't determine country). Vercel sets\n\t\t\t// x-vercel-ip-country; Cloudflare sets cf-ipcountry.\n\t\t\tconst geo = {\n\t\t\t\tcountry:\n\t\t\t\t\trequest.headers.get('x-vercel-ip-country') ??\n\t\t\t\t\trequest.headers.get('cf-ipcountry') ??\n\t\t\t\t\tundefined,\n\t\t\t}\n\n\t\t\t// Get AB test value from: searchParam, cookies or get generate a new value\n\t\t\tconst testValue =\n\t\t\t\tvalidateValue(\n\t\t\t\t\trequest.nextUrl.searchParams.get(serverABTestConfig.slug),\n\t\t\t\t) ||\n\t\t\t\tvalidateValue(request.cookies.get(serverABTestConfig.slug)?.value) ||\n\t\t\t\targs.improveSdk.getTestValue(\n\t\t\t\t\tserverABTestConfig.slug,\n\t\t\t\t\tvisitorId,\n\t\t\t\t\tua,\n\t\t\t\t\tgeo,\n\t\t\t\t)\n\n\t\t\tconst testMatchOption = serverABTestConfig.options.find(\n\t\t\t\t(option) => option.value === testValue,\n\t\t\t)\n\n\t\t\tif (testValue == null || !testMatchOption) return NextResponse.next()\n\n\t\t\t// Update the response with cookies response\n\t\t\tlet response: undefined | NextResponse<unknown>\n\n\t\t\tif (testMatchOption.value !== basePath) {\n\t\t\t\tconst url = request.nextUrl.clone()\n\n\t\t\t\turl.pathname = serverABTestConfig?.formatSlug\n\t\t\t\t\t? serverABTestConfig?.formatSlug(url, testMatchOption)?.pathname\n\t\t\t\t\t: testMatchOption.slug\n\n\t\t\t\tresponse = NextResponse.rewrite(url)\n\t\t\t} else {\n\t\t\t\tresponse = NextResponse.next()\n\t\t\t}\n\n\t\t\tresponse.cookies.set(visitorCookieName, visitorId, {\n\t\t\t\tmaxAge: DEFAULT_COOKIE_TTL,\n\t\t\t\t...args.options?.visitorId,\n\t\t\t})\n\t\t\tresponse.cookies.set(serverABTestConfig.slug, testValue, {\n\t\t\t\tmaxAge: DEFAULT_COOKIE_TTL,\n\t\t\t\t...args.options?.testValue,\n\t\t\t})\n\n\t\t\treturn response\n\t\t} catch (e) {\n\t\t\tconsole.error('[Improve SDK]', e)\n\t\t\treturn NextResponse.next()\n\t\t}\n\t}\n}\n"],"names":["EXTENDED_BOT_REGEX","RegExp","map","name","toLowerCase","join","BASE_REGEX","SECONDARY_REGEX","TERTIARY_REGEX","removeTrailingSlash","val","endsWith","substring","length","regexCache","Map","args","request","response","ua","isBot","userAgent","test","NextResponse","next","serverABTestConfig","serverABtests","find","route","matchesRoute","pathname","basePathname","split","baseRoute","routeRegex","get","replace","set","routeHandler","nextUrl","basePath","options","at","value","visitorCookieName","improveSdk","getVisitorCookieName","cookieVisitorId","cookies","visitorId","validCookieVisitorId","validateVisitorId","generateVisitorId","validateValue","validateTestValue","slug","geo","country","headers","undefined","testValue","searchParams","getTestValue","testMatchOption","option","url","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C,IAAMyB,EAAMhD,EAAQsB,OAAO,CAAC2B,KAAK,EAEjCD,CAAAA,EAAInC,QAAQ,CAAGL,GAAoB0C,WAChC1C,GAAoB0C,WAAWF,EAAKF,IAAkBjC,SACtDiC,EAAgBR,IAAI,CAEvBrC,EAAWK,EAAAA,YAAAA,CAAa6C,OAAO,CAACH,EACjC,MACC/C,EAAWK,EAAAA,aAAaC,IAAI,GAY7B,OATAN,EAAS8B,OAAO,CAACX,GAAG,CAACO,EAAmBK,EAAW,CAClDoB,OAtGuB,OAuGvB,GAAGrD,EAAKyB,OAAO,EAAEQ,SAAAA,AAClB,GACA/B,EAAS8B,OAAO,CAACX,GAAG,CAACZ,EAAmB8B,IAAI,CAAEK,EAAW,CACxDS,OA1GuB,OA2GvB,GAAGrD,EAAKyB,OAAO,EAAEmB,SAAAA,AAClB,GAEO1C,CACR,CAAE,MAAOoD,EAAG,CAEX,OADAC,QAAQC,KAAK,CAAC,gBAAiBF,GACxB/C,EAAAA,aAAaC,IAAI,EACzB,CACD"}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{userAgent as e,NextResponse as t}from"next/server";let r=RegExp(["Vercelbot","DotBot","Yeti","AhrefsBot","SeznamBot","YandexBot","UptimeRobot","Bytespider","Baiduspider","fidget-spinner-bot","AASA-Bot","FullStoryBot","SemrushBot","PetalBot","RyteBot","Pinterestbot","AntBot","Monsidobot","blowra","JobRoboter","Qwantify","YisouSpider"].map(e=>e.toLowerCase()).join("|"),"i"),o=/(\[[a-zA-Z0-9-]+\])+/g,i=/\[\[\.\.\.[a-zA-Z0-9-]+\]\]/g,a=/\[\.\.\.[a-zA-Z0-9-]+\]/g,s=e=>e.endsWith("/")?e.substring(0,e.length-1):e,n=new Map,l=l=>u=>{try{let p,{ua:g="",isBot:d=!1}=e(u);if(d||g&&r.test(g.toLowerCase()))return t.next();let m=l.serverABtests.find(e=>((e,t)=>{let r=s(t.split("?")[0]),l=s(e.split("?")[0]);if(r===l)return!0;let u=n.get(l);return u||(u=new RegExp(`^${l.replace(o,"[a-zA-Z0-9-]+")}$`.replace(i,"?.*").replace(a,".*")),n.set(l,u)),u.test(r)})(e.routeHandler,u.nextUrl.pathname));if(!m)return t.next();let v=m.options.at(0)?.value;if(!v)return t.next();let c=l.improveSdk.getVisitorCookieName(),x=u.cookies.get(c)?.value,f=x&&l.improveSdk.validateVisitorId(x)?x:l.improveSdk.generateVisitorId(),B=e=>e&&l.improveSdk.validateTestValue(m.slug,e)?e:null,S={country:u.headers.get("x-vercel-ip-country")??u.headers.get("cf-ipcountry")??void 0},A=B(u.nextUrl.searchParams.get(m.slug))||B(u.cookies.get(m.slug)?.value)||l.improveSdk.getTestValue(m.slug,f,g,S),h=m.options.find(e=>e.value===A);if(!h)return t.next();if(h.value!==v){let e=u.nextUrl.clone();e.pathname=m?.formatSlug?m?.formatSlug(e,h)?.pathname:h.slug,p=t.rewrite(e)}else p=t.next();return p.cookies.set(c,f,{maxAge:604800,...l.options?.visitorId}),p.cookies.set(m.slug,A,{maxAge:604800,...l.options?.testValue}),p}catch(e){return console.error("[Improve SDK]",e),t.next()}};export{l as generateImproveNextMiddleware};
1
+ import{userAgent as e,NextResponse as t}from"next/server";let o=RegExp(["Vercelbot","DotBot","Yeti","AhrefsBot","SeznamBot","YandexBot","UptimeRobot","Bytespider","Baiduspider","fidget-spinner-bot","AASA-Bot","FullStoryBot","SemrushBot","PetalBot","RyteBot","Pinterestbot","AntBot","Monsidobot","blowra","JobRoboter","Qwantify","YisouSpider"].map(e=>e.toLowerCase()).join("|"),"i"),r=/(\[[a-zA-Z0-9-]+\])+/g,i=/\[\[\.\.\.[a-zA-Z0-9-]+\]\]/g,s=/\[\.\.\.[a-zA-Z0-9-]+\]/g,a=e=>e.endsWith("/")?e.substring(0,e.length-1):e,l=new Map,n=n=>u=>{try{let p,{ua:g="",isBot:d=!1}=e(u);if(d||g&&o.test(g.toLowerCase()))return t.next();let m=n.serverABtests.find(e=>((e,t)=>{let o=a(t.split("?")[0]),n=a(e.split("?")[0]);if(o===n)return!0;let u=l.get(n);return u||(u=new RegExp(`^${n.replace(r,"[a-zA-Z0-9-]+")}$`.replace(i,"?.*").replace(s,".*")),l.set(n,u)),u.test(o)})(e.routeHandler,u.nextUrl.pathname));if(!m)return t.next();let v=m.options.at(0)?.value;if(!v)return t.next();let c=n.improveSdk.getVisitorCookieName(),x=u.cookies.get(c)?.value??u.cookies.get("visitorId")?.value,f=x&&n.improveSdk.validateVisitorId(x)?x:n.improveSdk.generateVisitorId(),B=e=>e&&n.improveSdk.validateTestValue(m.slug,e)?e:null,S={country:u.headers.get("x-vercel-ip-country")??u.headers.get("cf-ipcountry")??void 0},A=B(u.nextUrl.searchParams.get(m.slug))||B(u.cookies.get(m.slug)?.value)||n.improveSdk.getTestValue(m.slug,f,g,S),h=m.options.find(e=>e.value===A);if(null==A||!h)return t.next();if(h.value!==v){let e=u.nextUrl.clone();e.pathname=m?.formatSlug?m?.formatSlug(e,h)?.pathname:h.slug,p=t.rewrite(e)}else p=t.next();return p.cookies.set(c,f,{maxAge:604800,...n.options?.visitorId}),p.cookies.set(m.slug,A,{maxAge:604800,...n.options?.testValue}),p}catch(e){return console.error("[Improve SDK]",e),t.next()}};export{n as generateImproveNextMiddleware};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/extendedBotCheck.ts","../src/matchesRoute.ts","../src/index.ts"],"sourcesContent":["const EXTENDED_BOT_REGEX = new RegExp(\n\t[\n\t\t'Vercelbot',\n\t\t'DotBot',\n\t\t'Yeti',\n\t\t'AhrefsBot',\n\t\t'SeznamBot',\n\t\t'YandexBot',\n\t\t'UptimeRobot',\n\t\t'Bytespider',\n\t\t'Baiduspider',\n\t\t'fidget-spinner-bot',\n\t\t'AASA-Bot',\n\t\t'FullStoryBot',\n\t\t'SemrushBot',\n\t\t'PetalBot',\n\t\t'RyteBot',\n\t\t'Pinterestbot',\n\t\t'AntBot',\n\t\t'Monsidobot',\n\t\t'blowra',\n\t\t'JobRoboter',\n\t\t'Qwantify',\n\t\t'YisouSpider',\n\t]\n\t\t.map((name) => name.toLowerCase())\n\t\t.join('|'),\n\t'i',\n)\n\nexport const extendedBotCheck = (userAgent: string): boolean => {\n\tif (!userAgent) return false\n\treturn EXTENDED_BOT_REGEX.test(userAgent.toLowerCase())\n}\n","const BASE_REGEX = /(\\[[a-zA-Z0-9-]+\\])+/g\n\nconst SECONDARY_REGEX = /\\[\\[\\.\\.\\.[a-zA-Z0-9-]+\\]\\]/g\n\nconst TERTIARY_REGEX = /\\[\\.\\.\\.[a-zA-Z0-9-]+\\]/g\n\nexport const removeTrailingSlash = (val: string) =>\n\tval.endsWith('/') ? val.substring(0, val.length - 1) : val\n\nconst regexCache = new Map<string, RegExp>()\n\nexport const matchesRoute = (route: string, pathname: string) => {\n\tconst basePathname = removeTrailingSlash(pathname.split('?')[0] as string)\n\tconst baseRoute = removeTrailingSlash(route.split('?')[0] as string)\n\n\tif (basePathname === baseRoute) return true\n\n\tlet routeRegex = regexCache.get(baseRoute)\n\tif (!routeRegex) {\n\t\trouteRegex = new RegExp(\n\t\t\t`^${baseRoute.replace(BASE_REGEX, '[a-zA-Z0-9-]+')}$`\n\t\t\t\t.replace(SECONDARY_REGEX, '?.*')\n\t\t\t\t.replace(TERTIARY_REGEX, '.*'),\n\t\t)\n\t\tregexCache.set(baseRoute, routeRegex)\n\t}\n\n\treturn routeRegex.test(basePathname)\n}\n","import { ImproveServerSDK } from '@obelism/improve-sdk/server'\nimport type { NextURL } from 'next/dist/server/web/next-url'\nimport type { NextRequest } from 'next/server'\nimport { NextResponse, userAgent } from 'next/server'\n\nimport { extendedBotCheck } from './extendedBotCheck'\nimport { matchesRoute } from './matchesRoute'\nimport type { ResponseCookie } from 'next/dist/compiled/@edge-runtime/cookies'\n\nconst DEFAULT_COOKIE_TTL = 60 * 60 * 24 * 7\n\nexport type OptionConfig = { value: string; slug: string }\n\nexport type ServerABTestConfig = {\n\tslug: string\n\trouteHandler: string\n\tformatSlug?: (url: NextURL, matchingOption: OptionConfig) => NextURL\n\toptions: OptionConfig[]\n}\n\nexport type GenerateImproveNextMiddlewareArgs = {\n\timproveSdk: ImproveServerSDK\n\tserverABtests: ServerABTestConfig[]\n\toptions?: {\n\t\tvisitorId?: ResponseCookie\n\t\ttestValue?: ResponseCookie\n\t}\n}\n\nexport const generateImproveNextMiddleware = (\n\targs: GenerateImproveNextMiddlewareArgs,\n) => {\n\treturn (request: NextRequest) => {\n\t\ttry {\n\t\t\t// Early esacape for bots that shouldn't be getting AB tested\n\t\t\tconst { ua = '', isBot = false } = userAgent(request)\n\t\t\tif (isBot || extendedBotCheck(ua)) return NextResponse.next()\n\n\t\t\t// When there is no (valid) server AB config escape\n\t\t\tconst serverABTestConfig = args.serverABtests.find((route) =>\n\t\t\t\tmatchesRoute(route.routeHandler, request.nextUrl.pathname),\n\t\t\t)\n\t\t\tif (!serverABTestConfig) return NextResponse.next()\n\n\t\t\tconst basePath = serverABTestConfig.options.at(0)?.value\n\n\t\t\tif (!basePath) return NextResponse.next()\n\n\t\t\tconst visitorCookieName = args.improveSdk.getVisitorCookieName()\n\t\t\tconst cookieVisitorId = request.cookies.get(visitorCookieName)?.value\n\t\t\tconst validCookieVisitorId =\n\t\t\t\tcookieVisitorId && args.improveSdk.validateVisitorId(cookieVisitorId)\n\t\t\tconst visitorId = validCookieVisitorId\n\t\t\t\t? cookieVisitorId\n\t\t\t\t: args.improveSdk.generateVisitorId()\n\n\t\t\tconst validateValue = (value: string | null | undefined) => {\n\t\t\t\treturn value &&\n\t\t\t\t\targs.improveSdk.validateTestValue(serverABTestConfig.slug, value)\n\t\t\t\t\t? value\n\t\t\t\t\t: null\n\t\t\t}\n\n\t\t\t// Coarse geo from the edge, so country-targeted audiences resolve\n\t\t\t// server-side (the browser can't determine country). Vercel sets\n\t\t\t// x-vercel-ip-country; Cloudflare sets cf-ipcountry.\n\t\t\tconst geo = {\n\t\t\t\tcountry:\n\t\t\t\t\trequest.headers.get('x-vercel-ip-country') ??\n\t\t\t\t\trequest.headers.get('cf-ipcountry') ??\n\t\t\t\t\tundefined,\n\t\t\t}\n\n\t\t\t// Get AB test value from: searchParam, cookies or get generate a new value\n\t\t\tconst testValue =\n\t\t\t\tvalidateValue(\n\t\t\t\t\trequest.nextUrl.searchParams.get(serverABTestConfig.slug),\n\t\t\t\t) ||\n\t\t\t\tvalidateValue(request.cookies.get(serverABTestConfig.slug)?.value) ||\n\t\t\t\targs.improveSdk.getTestValue(\n\t\t\t\t\tserverABTestConfig.slug,\n\t\t\t\t\tvisitorId,\n\t\t\t\t\tua,\n\t\t\t\t\tgeo,\n\t\t\t\t)\n\n\t\t\tconst testMatchOption = serverABTestConfig.options.find(\n\t\t\t\t(option) => option.value === testValue,\n\t\t\t)\n\n\t\t\tif (!testMatchOption) return NextResponse.next()\n\n\t\t\t// Update the response with cookies response\n\t\t\tlet response: undefined | NextResponse<unknown>\n\n\t\t\tif (testMatchOption.value !== basePath) {\n\t\t\t\tconst url = request.nextUrl.clone()\n\n\t\t\t\turl.pathname = serverABTestConfig?.formatSlug\n\t\t\t\t\t? serverABTestConfig?.formatSlug(url, testMatchOption)?.pathname\n\t\t\t\t\t: testMatchOption.slug\n\n\t\t\t\tresponse = NextResponse.rewrite(url)\n\t\t\t} else {\n\t\t\t\tresponse = NextResponse.next()\n\t\t\t}\n\n\t\t\tresponse.cookies.set(visitorCookieName, visitorId, {\n\t\t\t\tmaxAge: DEFAULT_COOKIE_TTL,\n\t\t\t\t...args.options?.visitorId,\n\t\t\t})\n\t\t\tresponse.cookies.set(serverABTestConfig.slug, testValue, {\n\t\t\t\tmaxAge: DEFAULT_COOKIE_TTL,\n\t\t\t\t...args.options?.testValue,\n\t\t\t})\n\n\t\t\treturn response\n\t\t} catch (e) {\n\t\t\tconsole.error('[Improve SDK]', e)\n\t\t\treturn NextResponse.next()\n\t\t}\n\t}\n}\n"],"names":["EXTENDED_BOT_REGEX","RegExp","map","name","toLowerCase","join","BASE_REGEX","SECONDARY_REGEX","TERTIARY_REGEX","removeTrailingSlash","val","endsWith","substring","length","regexCache","Map","generateImproveNextMiddleware","args","request","response","ua","isBot","userAgent","test","NextResponse","next","serverABTestConfig","serverABtests","find","route","matchesRoute","pathname","basePathname","split","baseRoute","routeRegex","get","replace","set","routeHandler","nextUrl","basePath","options","at","value","visitorCookieName","improveSdk","getVisitorCookieName","cookieVisitorId","cookies","visitorId","validCookieVisitorId","validateVisitorId","generateVisitorId","validateValue","validateTestValue","slug","geo","country","headers","undefined","testValue","searchParams","getTestValue","testMatchOption","option","url","clone","formatSlug","rewrite","maxAge","e","console","error"],"mappings":"0DAAA,IAAMA,EAAqB,AAAIC,OAC9B,CACC,YACA,SACA,OACA,YACA,YACA,YACA,cACA,aACA,cACA,qBACA,WACA,eACA,aACA,WACA,UACA,eACA,SACA,aACA,SACA,aACA,WACA,cACA,CACCC,GAAG,CAAC,AAACC,GAASA,EAAKC,WAAW,IAC9BC,IAAI,CAAC,KACP,KC3BKC,EAAa,wBAEbC,EAAkB,+BAElBC,EAAiB,2BAEVC,EAAsB,AAACC,GACnCA,EAAIC,QAAQ,CAAC,KAAOD,EAAIE,SAAS,CAAC,EAAGF,EAAIG,MAAM,CAAG,GAAKH,EAElDI,EAAa,IAAIC,ICoBVC,EAAgC,AAC5CC,GAEO,AAACC,IACP,GAAI,CAEH,IA0DIC,EA1DE,CAAEC,GAAAA,EAAK,EAAE,CAAEC,MAAAA,EAAQ,CAAA,CAAK,CAAE,CAAGC,EAAUJ,GAC7C,GAAIG,GFLN,AEKgCD,GFJzBpB,EAAmBuB,IAAI,CAACD,AEICF,EFJShB,WAAW,IEIf,OAAOoB,EAAaC,IAAI,GAG3D,IAAMC,EAAqBT,EAAKU,aAAa,CAACC,IAAI,CAAC,AAACC,GACnDC,AD7BwB,CAAA,CAACD,EAAeE,KAC3C,IAAMC,EAAevB,EAAoBsB,EAASE,KAAK,CAAC,IAAI,CAAC,EAAE,EACzD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K6B,UAAU,CAACiB,YAAY,CAC3BrC,EAAmB8B,IAAI,CACvBN,EACA9B,EACAqC,GAGIO,EAAkBtC,EAAmBgB,OAAO,CAACd,IAAI,CACtD,AAACqC,GAAWA,EAAOrB,KAAK,GAAKiB,GAG9B,GAAI,CAACG,EAAiB,OAAOxC,EAAaC,IAAI,GAK9C,GAAIuC,EAAgBpB,KAAK,GAAKH,EAAU,CACvC,IAAMyB,EAAMhD,EAAQsB,OAAO,CAAC2B,KAAK,EAEjCD,CAAAA,EAAInC,QAAQ,CAAGL,GAAoB0C,WAChC1C,GAAoB0C,WAAWF,EAAKF,IAAkBjC,SACtDiC,EAAgBR,IAAI,CAEvBrC,EAAWK,EAAa6C,OAAO,CAACH,EACjC,MACC/C,EAAWK,EAAaC,IAAI,GAY7B,OATAN,EAAS8B,OAAO,CAACX,GAAG,CAACO,EAAmBK,EAAW,CAClDoB,OAnGuB,OAoGvB,GAAGrD,EAAKyB,OAAO,EAAEQ,SAAAA,AAClB,GACA/B,EAAS8B,OAAO,CAACX,GAAG,CAACZ,EAAmB8B,IAAI,CAAEK,EAAW,CACxDS,OAvGuB,OAwGvB,GAAGrD,EAAKyB,OAAO,EAAEmB,SAAAA,AAClB,GAEO1C,CACR,CAAE,MAAOoD,EAAG,CAEX,OADAC,QAAQC,KAAK,CAAC,gBAAiBF,GACxB/C,EAAaC,IAAI,EACzB,CACD"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/extendedBotCheck.ts","../src/matchesRoute.ts","../src/index.ts"],"sourcesContent":["const EXTENDED_BOT_REGEX = new RegExp(\n\t[\n\t\t'Vercelbot',\n\t\t'DotBot',\n\t\t'Yeti',\n\t\t'AhrefsBot',\n\t\t'SeznamBot',\n\t\t'YandexBot',\n\t\t'UptimeRobot',\n\t\t'Bytespider',\n\t\t'Baiduspider',\n\t\t'fidget-spinner-bot',\n\t\t'AASA-Bot',\n\t\t'FullStoryBot',\n\t\t'SemrushBot',\n\t\t'PetalBot',\n\t\t'RyteBot',\n\t\t'Pinterestbot',\n\t\t'AntBot',\n\t\t'Monsidobot',\n\t\t'blowra',\n\t\t'JobRoboter',\n\t\t'Qwantify',\n\t\t'YisouSpider',\n\t]\n\t\t.map((name) => name.toLowerCase())\n\t\t.join('|'),\n\t'i',\n)\n\nexport const extendedBotCheck = (userAgent: string): boolean => {\n\tif (!userAgent) return false\n\treturn EXTENDED_BOT_REGEX.test(userAgent.toLowerCase())\n}\n","const BASE_REGEX = /(\\[[a-zA-Z0-9-]+\\])+/g\n\nconst SECONDARY_REGEX = /\\[\\[\\.\\.\\.[a-zA-Z0-9-]+\\]\\]/g\n\nconst TERTIARY_REGEX = /\\[\\.\\.\\.[a-zA-Z0-9-]+\\]/g\n\nexport const removeTrailingSlash = (val: string) =>\n\tval.endsWith('/') ? val.substring(0, val.length - 1) : val\n\nconst regexCache = new Map<string, RegExp>()\n\nexport const matchesRoute = (route: string, pathname: string) => {\n\tconst basePathname = removeTrailingSlash(pathname.split('?')[0] as string)\n\tconst baseRoute = removeTrailingSlash(route.split('?')[0] as string)\n\n\tif (basePathname === baseRoute) return true\n\n\tlet routeRegex = regexCache.get(baseRoute)\n\tif (!routeRegex) {\n\t\trouteRegex = new RegExp(\n\t\t\t`^${baseRoute.replace(BASE_REGEX, '[a-zA-Z0-9-]+')}$`\n\t\t\t\t.replace(SECONDARY_REGEX, '?.*')\n\t\t\t\t.replace(TERTIARY_REGEX, '.*'),\n\t\t)\n\t\tregexCache.set(baseRoute, routeRegex)\n\t}\n\n\treturn routeRegex.test(basePathname)\n}\n","import { ImproveServerSDK } from '@obelism/improve-sdk/server'\nimport type { NextURL } from 'next/dist/server/web/next-url'\nimport type { NextRequest } from 'next/server'\nimport { NextResponse, userAgent } from 'next/server'\n\nimport { extendedBotCheck } from './extendedBotCheck'\nimport { matchesRoute } from './matchesRoute'\nimport type { ResponseCookie } from 'next/dist/compiled/@edge-runtime/cookies'\n\nconst DEFAULT_COOKIE_TTL = 60 * 60 * 24 * 7\n\nexport type OptionConfig = { value: string; slug: string }\n\nexport type ServerABTestConfig = {\n\tslug: string\n\trouteHandler: string\n\tformatSlug?: (url: NextURL, matchingOption: OptionConfig) => NextURL\n\toptions: OptionConfig[]\n}\n\nexport type GenerateImproveNextMiddlewareArgs = {\n\timproveSdk: ImproveServerSDK\n\tserverABtests: ServerABTestConfig[]\n\toptions?: {\n\t\tvisitorId?: ResponseCookie\n\t\ttestValue?: ResponseCookie\n\t}\n}\n\nexport const generateImproveNextMiddleware = (\n\targs: GenerateImproveNextMiddlewareArgs,\n) => {\n\treturn (request: NextRequest) => {\n\t\ttry {\n\t\t\t// Early esacape for bots that shouldn't be getting AB tested\n\t\t\tconst { ua = '', isBot = false } = userAgent(request)\n\t\t\tif (isBot || extendedBotCheck(ua)) return NextResponse.next()\n\n\t\t\t// When there is no (valid) server AB config escape\n\t\t\tconst serverABTestConfig = args.serverABtests.find((route) =>\n\t\t\t\tmatchesRoute(route.routeHandler, request.nextUrl.pathname),\n\t\t\t)\n\t\t\tif (!serverABTestConfig) return NextResponse.next()\n\n\t\t\tconst basePath = serverABTestConfig.options.at(0)?.value\n\n\t\t\tif (!basePath) return NextResponse.next()\n\n\t\t\tconst visitorCookieName = args.improveSdk.getVisitorCookieName()\n\t\t\t// The name before it was namespaced: keep an existing visitor.\n\t\t\tconst cookieVisitorId =\n\t\t\t\trequest.cookies.get(visitorCookieName)?.value ??\n\t\t\t\trequest.cookies.get('visitorId')?.value\n\t\t\tconst validCookieVisitorId =\n\t\t\t\tcookieVisitorId && args.improveSdk.validateVisitorId(cookieVisitorId)\n\t\t\tconst visitorId = validCookieVisitorId\n\t\t\t\t? cookieVisitorId\n\t\t\t\t: args.improveSdk.generateVisitorId()\n\n\t\t\tconst validateValue = (value: string | null | undefined) => {\n\t\t\t\treturn value &&\n\t\t\t\t\targs.improveSdk.validateTestValue(serverABTestConfig.slug, value)\n\t\t\t\t\t? value\n\t\t\t\t\t: null\n\t\t\t}\n\n\t\t\t// Coarse geo from the edge, so country-targeted audiences resolve\n\t\t\t// server-side (the browser can't determine country). Vercel sets\n\t\t\t// x-vercel-ip-country; Cloudflare sets cf-ipcountry.\n\t\t\tconst geo = {\n\t\t\t\tcountry:\n\t\t\t\t\trequest.headers.get('x-vercel-ip-country') ??\n\t\t\t\t\trequest.headers.get('cf-ipcountry') ??\n\t\t\t\t\tundefined,\n\t\t\t}\n\n\t\t\t// Get AB test value from: searchParam, cookies or get generate a new value\n\t\t\tconst testValue =\n\t\t\t\tvalidateValue(\n\t\t\t\t\trequest.nextUrl.searchParams.get(serverABTestConfig.slug),\n\t\t\t\t) ||\n\t\t\t\tvalidateValue(request.cookies.get(serverABTestConfig.slug)?.value) ||\n\t\t\t\targs.improveSdk.getTestValue(\n\t\t\t\t\tserverABTestConfig.slug,\n\t\t\t\t\tvisitorId,\n\t\t\t\t\tua,\n\t\t\t\t\tgeo,\n\t\t\t\t)\n\n\t\t\tconst testMatchOption = serverABTestConfig.options.find(\n\t\t\t\t(option) => option.value === testValue,\n\t\t\t)\n\n\t\t\tif (testValue == null || !testMatchOption) return NextResponse.next()\n\n\t\t\t// Update the response with cookies response\n\t\t\tlet response: undefined | NextResponse<unknown>\n\n\t\t\tif (testMatchOption.value !== basePath) {\n\t\t\t\tconst url = request.nextUrl.clone()\n\n\t\t\t\turl.pathname = serverABTestConfig?.formatSlug\n\t\t\t\t\t? serverABTestConfig?.formatSlug(url, testMatchOption)?.pathname\n\t\t\t\t\t: testMatchOption.slug\n\n\t\t\t\tresponse = NextResponse.rewrite(url)\n\t\t\t} else {\n\t\t\t\tresponse = NextResponse.next()\n\t\t\t}\n\n\t\t\tresponse.cookies.set(visitorCookieName, visitorId, {\n\t\t\t\tmaxAge: DEFAULT_COOKIE_TTL,\n\t\t\t\t...args.options?.visitorId,\n\t\t\t})\n\t\t\tresponse.cookies.set(serverABTestConfig.slug, testValue, {\n\t\t\t\tmaxAge: DEFAULT_COOKIE_TTL,\n\t\t\t\t...args.options?.testValue,\n\t\t\t})\n\n\t\t\treturn response\n\t\t} catch (e) {\n\t\t\tconsole.error('[Improve SDK]', e)\n\t\t\treturn NextResponse.next()\n\t\t}\n\t}\n}\n"],"names":["EXTENDED_BOT_REGEX","RegExp","map","name","toLowerCase","join","BASE_REGEX","SECONDARY_REGEX","TERTIARY_REGEX","removeTrailingSlash","val","endsWith","substring","length","regexCache","Map","generateImproveNextMiddleware","args","request","response","ua","isBot","userAgent","test","NextResponse","next","serverABTestConfig","serverABtests","find","route","matchesRoute","pathname","basePathname","split","baseRoute","routeRegex","get","replace","set","routeHandler","nextUrl","basePath","options","at","value","visitorCookieName","improveSdk","getVisitorCookieName","cookieVisitorId","cookies","visitorId","validCookieVisitorId","validateVisitorId","generateVisitorId","validateValue","validateTestValue","slug","geo","country","headers","undefined","testValue","searchParams","getTestValue","testMatchOption","option","url","clone","formatSlug","rewrite","maxAge","e","console","error"],"mappings":"0DAAA,IAAMA,EAAqB,AAAIC,OAC9B,CACC,YACA,SACA,OACA,YACA,YACA,YACA,cACA,aACA,cACA,qBACA,WACA,eACA,aACA,WACA,UACA,eACA,SACA,aACA,SACA,aACA,WACA,cACA,CACCC,GAAG,CAAC,AAACC,GAASA,EAAKC,WAAW,IAC9BC,IAAI,CAAC,KACP,KC3BKC,EAAa,wBAEbC,EAAkB,+BAElBC,EAAiB,2BAEVC,EAAsB,AAACC,GACnCA,EAAIC,QAAQ,CAAC,KAAOD,EAAIE,SAAS,CAAC,EAAGF,EAAIG,MAAM,CAAG,GAAKH,EAElDI,EAAa,IAAIC,ICoBVC,EAAgC,AAC5CC,GAEO,AAACC,IACP,GAAI,CAEH,IA6DIC,EA7DE,CAAEC,GAAAA,EAAK,EAAE,CAAEC,MAAAA,EAAQ,CAAA,CAAK,CAAE,CAAGC,EAAUJ,GAC7C,GAAIG,GFLN,AEKgCD,GFJzBpB,EAAmBuB,IAAI,CAACD,AEICF,EFJShB,WAAW,IEIf,OAAOoB,EAAaC,IAAI,GAG3D,IAAMC,EAAqBT,EAAKU,aAA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AAA,CACF,EAGMC,EACLP,EACCpC,EAAQsB,OAAO,CAACsB,YAAY,CAAC1B,GAAG,CAACV,EAAmB8B,IAAI,IAEzDF,EAAcpC,EAAQ+B,OAAO,CAACb,GAAG,CAACV,EAAmB8B,IAAI,GAAGZ,QAC5D3B,EAAK6B,UAAU,CAACiB,YAAY,CAC3BrC,EAAmB8B,IAAI,CACvBN,EACA9B,EACAqC,GAGIO,EAAkBtC,EAAmBgB,OAAO,CAACd,IAAI,CACtD,AAACqC,GAAWA,EAAOrB,KAAK,GAAKiB,GAG9B,GAAIA,AAAa,MAAbA,GAAqB,CAACG,EAAiB,OAAOxC,EAAaC,IAAI,GAKnE,GAAIuC,EAAgBpB,KAAK,GAAKH,EAAU,CACvC,IAAMyB,EAAMhD,EAAQsB,OAAO,CAAC2B,KAAK,EAEjCD,CAAAA,EAAInC,QAAQ,CAAGL,GAAoB0C,WAChC1C,GAAoB0C,WAAWF,EAAKF,IAAkBjC,SACtDiC,EAAgBR,IAAI,CAEvBrC,EAAWK,EAAa6C,OAAO,CAACH,EACjC,MACC/C,EAAWK,EAAaC,IAAI,GAY7B,OATAN,EAAS8B,OAAO,CAACX,GAAG,CAACO,EAAmBK,EAAW,CAClDoB,OAtGuB,OAuGvB,GAAGrD,EAAKyB,OAAO,EAAEQ,SAAAA,AAClB,GACA/B,EAAS8B,OAAO,CAACX,GAAG,CAACZ,EAAmB8B,IAAI,CAAEK,EAAW,CACxDS,OA1GuB,OA2GvB,GAAGrD,EAAKyB,OAAO,EAAEmB,SAAAA,AAClB,GAEO1C,CACR,CAAE,MAAOoD,EAAG,CAEX,OADAC,QAAQC,KAAK,CAAC,gBAAiBF,GACxB/C,EAAaC,IAAI,EACzB,CACD"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@obelism/improve-sdk-next",
3
3
  "description": "Obelism Improve NextJS SDK",
4
- "version": "1.1.1",
4
+ "version": "1.1.3",
5
5
  "keywords": [
6
6
  "ab-tests",
7
7
  "feature-flags",
@@ -14,8 +14,8 @@
14
14
  "author": "Obelism <hello@obelism.studio> (https://www.obelism.studio)",
15
15
  "repository": {
16
16
  "type": "git",
17
- "url": "https://github.com/Obelism/improve-sdk",
18
- "directory": "packages/next-sdk"
17
+ "url": "https://github.com/Obelism/sdk",
18
+ "directory": "packages/improve-next"
19
19
  },
20
20
  "sideEffects": false,
21
21
  "files": [
@@ -38,7 +38,7 @@
38
38
  "test:coverage": "vitest run --coverage",
39
39
  "test:ci": "vitest run",
40
40
  "lint": "npm-run-all --parallel lint:*",
41
- "lint:fix": "eslint --fix",
41
+ "lint:oxlint": "oxlint",
42
42
  "lint:types": "tsc --noEmit",
43
43
  "clean": "rm -rf ./node_modules && rm -rf ./dist && rm -rf ./.turbo"
44
44
  },
@@ -47,15 +47,16 @@
47
47
  "react": ">=18.0.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@obelism/improve-sdk-eslint-config": "^0.0.0",
51
- "@obelism/improve-sdk-typescript-config": "^0.0.0",
52
- "@types/react": "^19.2.17",
53
- "bunchee": "^6.11.0",
54
- "eslint": "^10.6.0",
55
- "typescript": "^6.0.3",
56
- "vitest": "^4.1.9"
50
+ "@obelism/sdk-typescript-config": "^0.0.0",
51
+ "@types/react": "^19.3.0",
52
+ "@typescript/typescript6": "^6.0.2",
53
+ "bunchee": "^7.0.2",
54
+ "npm-run-all2": "^9.0.4",
55
+ "oxlint": "^1.90.0",
56
+ "typescript": "^7.0.2",
57
+ "vitest": "^5.0.5"
57
58
  },
58
59
  "dependencies": {
59
- "@obelism/improve-sdk": "^3.0.0"
60
+ "@obelism/improve-sdk": "^3.4.0"
60
61
  }
61
62
  }