@replohq/canopy-sdk 2.2.0 → 2.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@replohq/canopy-sdk",
3
- "version": "2.2.0",
3
+ "version": "2.4.0",
4
4
  "description": "Replo Canopy SDK — cart, analytics, data loaders, and editor runtime for agent-built Next.js sites.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -93,6 +93,14 @@
93
93
  "types": "./loaders/levanta-product-loader.d.ts",
94
94
  "default": "./loaders/levanta-product-loader.js"
95
95
  },
96
+ "./loaders/metaobject-loader": {
97
+ "types": "./loaders/metaobject-loader.d.ts",
98
+ "default": "./loaders/metaobject-loader.js"
99
+ },
100
+ "./loaders/metaobjects-loader": {
101
+ "types": "./loaders/metaobjects-loader.d.ts",
102
+ "default": "./loaders/metaobjects-loader.js"
103
+ },
96
104
  "./loaders/okendo-review-aggregate-loader": {
97
105
  "types": "./loaders/okendo-review-aggregate-loader.d.ts",
98
106
  "default": "./loaders/okendo-review-aggregate-loader.js"
@@ -177,6 +185,14 @@
177
185
  "types": "./next/open-next.d.ts",
178
186
  "default": "./next/open-next.js"
179
187
  },
188
+ "./routing/evaluate": {
189
+ "types": "./routing/evaluate.d.ts",
190
+ "default": "./routing/evaluate.js"
191
+ },
192
+ "./routing/rules": {
193
+ "types": "./routing/rules.d.ts",
194
+ "default": "./routing/rules.js"
195
+ },
180
196
  "./_vendor/schemas/loaderKeys": {
181
197
  "types": "./_vendor/schemas/loaderKeys.d.ts",
182
198
  "default": "./_vendor/schemas/loaderKeys.mjs"
@@ -0,0 +1,7 @@
1
+ import type { NextRequest } from "next/server";
2
+ import type { RedirectRule } from "../_vendor/schemas/routing/rules";
3
+ import { NextResponse } from "next/server";
4
+ export declare function evaluateRouting({ request, rules, }: {
5
+ request: NextRequest;
6
+ rules: readonly RedirectRule[];
7
+ }): NextResponse;
@@ -0,0 +1,46 @@
1
+ import { NextResponse } from "next/server";
2
+ import { applyParams, matchSource } from "../_vendor/schemas/routing/match.mjs";
3
+ function evaluateRouting({
4
+ request,
5
+ rules
6
+ }) {
7
+ for (const rule of rules) {
8
+ const response = evaluateRedirect({ request, rule });
9
+ if (response) {
10
+ return response;
11
+ }
12
+ }
13
+ return NextResponse.next();
14
+ }
15
+ function evaluateRedirect({
16
+ request,
17
+ rule
18
+ }) {
19
+ const params = matchSource({
20
+ source: rule.source,
21
+ pathname: request.nextUrl.pathname
22
+ });
23
+ if (!params) {
24
+ return null;
25
+ }
26
+ const url = new URL(
27
+ applyParams({ value: rule.destination, params }),
28
+ request.nextUrl.origin
29
+ );
30
+ if (url.origin === request.nextUrl.origin && !url.search) {
31
+ url.search = request.nextUrl.search;
32
+ }
33
+ const redirectsToCurrentRequest = url.origin === request.nextUrl.origin && normalizePath(url.pathname) === normalizePath(request.nextUrl.pathname) && url.search === request.nextUrl.search;
34
+ if (redirectsToCurrentRequest) {
35
+ return NextResponse.next();
36
+ }
37
+ return NextResponse.redirect(url, rule.status);
38
+ }
39
+ function normalizePath(pathname) {
40
+ const trimmed = pathname.replace(/\/+$/, "");
41
+ return trimmed === "" ? "/" : trimmed;
42
+ }
43
+ export {
44
+ evaluateRouting
45
+ };
46
+ //# sourceMappingURL=evaluate.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../routing/evaluate.ts"],
4
+ "sourcesContent": ["import type { NextRequest } from \"next/server\";\nimport type { RedirectRule } from \"schemas/routing/rules\";\n\nimport { NextResponse } from \"next/server\";\n\nimport { applyParams, matchSource } from \"schemas/routing/match\";\n\nexport function evaluateRouting({\n request,\n rules,\n}: {\n request: NextRequest;\n rules: readonly RedirectRule[];\n}): NextResponse {\n for (const rule of rules) {\n const response = evaluateRedirect({ request, rule });\n if (response) {\n return response;\n }\n }\n return NextResponse.next();\n}\n\nfunction evaluateRedirect({\n request,\n rule,\n}: {\n request: NextRequest;\n rule: RedirectRule;\n}): NextResponse | null {\n const params = matchSource({\n source: rule.source,\n pathname: request.nextUrl.pathname,\n });\n if (!params) {\n return null;\n }\n const url = new URL(\n applyParams({ value: rule.destination, params }),\n request.nextUrl.origin,\n );\n if (url.origin === request.nextUrl.origin && !url.search) {\n url.search = request.nextUrl.search;\n }\n // A destination that lands back on the current request would loop. The rule\n // still consumes the request \u2014 later rules were authored as alternatives to\n // it, not fallbacks for it \u2014 so the page renders normally instead.\n const redirectsToCurrentRequest =\n url.origin === request.nextUrl.origin &&\n normalizePath(url.pathname) === normalizePath(request.nextUrl.pathname) &&\n url.search === request.nextUrl.search;\n if (redirectsToCurrentRequest) {\n return NextResponse.next();\n }\n return NextResponse.redirect(url, rule.status);\n}\n\n/** Trailing slashes carry no meaning, so `/blogs` and `/blogs/` are the same. */\nfunction normalizePath(pathname: string): string {\n const trimmed = pathname.replace(/\\/+$/, \"\");\n return trimmed === \"\" ? \"/\" : trimmed;\n}\n"],
5
+ "mappings": "AAGA,SAAS,oBAAoB;AAE7B,SAAS,aAAa,mBAAmB;AAElC,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AACF,GAGiB;AACf,aAAW,QAAQ,OAAO;AACxB,UAAM,WAAW,iBAAiB,EAAE,SAAS,KAAK,CAAC;AACnD,QAAI,UAAU;AACZ,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO,aAAa,KAAK;AAC3B;AAEA,SAAS,iBAAiB;AAAA,EACxB;AAAA,EACA;AACF,GAGwB;AACtB,QAAM,SAAS,YAAY;AAAA,IACzB,QAAQ,KAAK;AAAA,IACb,UAAU,QAAQ,QAAQ;AAAA,EAC5B,CAAC;AACD,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AACA,QAAM,MAAM,IAAI;AAAA,IACd,YAAY,EAAE,OAAO,KAAK,aAAa,OAAO,CAAC;AAAA,IAC/C,QAAQ,QAAQ;AAAA,EAClB;AACA,MAAI,IAAI,WAAW,QAAQ,QAAQ,UAAU,CAAC,IAAI,QAAQ;AACxD,QAAI,SAAS,QAAQ,QAAQ;AAAA,EAC/B;AAIA,QAAM,4BACJ,IAAI,WAAW,QAAQ,QAAQ,UAC/B,cAAc,IAAI,QAAQ,MAAM,cAAc,QAAQ,QAAQ,QAAQ,KACtE,IAAI,WAAW,QAAQ,QAAQ;AACjC,MAAI,2BAA2B;AAC7B,WAAO,aAAa,KAAK;AAAA,EAC3B;AACA,SAAO,aAAa,SAAS,KAAK,KAAK,MAAM;AAC/C;AAGA,SAAS,cAAc,UAA0B;AAC/C,QAAM,UAAU,SAAS,QAAQ,QAAQ,EAAE;AAC3C,SAAO,YAAY,KAAK,MAAM;AAChC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Site-facing entrypoint for redirect rule authoring.
3
+ *
4
+ * The schema, validators, and matcher live in `schemas/routing` so the Website
5
+ * Builder can import them without depending on canopy (a published package,
6
+ * whose release cycle shouldn't gate editor-only changes). Sites can't import
7
+ * `schemas` directly — it is workspace-only and reaches generated sites through
8
+ * canopy's vendoring step — so `middleware.ts` keeps importing `reploRedirect`
9
+ * from here.
10
+ */
11
+ export type { RedirectRule, RedirectStatus, } from "../_vendor/schemas/routing/rules";
12
+ export { reploRedirect } from "../_vendor/schemas/routing/rules";
@@ -0,0 +1,5 @@
1
+ import { reploRedirect } from "../_vendor/schemas/routing/rules.mjs";
2
+ export {
3
+ reploRedirect
4
+ };
5
+ //# sourceMappingURL=rules.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../routing/rules.ts"],
4
+ "sourcesContent": ["/**\n * Site-facing entrypoint for redirect rule authoring.\n *\n * The schema, validators, and matcher live in `schemas/routing` so the Website\n * Builder can import them without depending on canopy (a published package,\n * whose release cycle shouldn't gate editor-only changes). Sites can't import\n * `schemas` directly \u2014 it is workspace-only and reaches generated sites through\n * canopy's vendoring step \u2014 so `middleware.ts` keeps importing `reploRedirect`\n * from here.\n */\nexport type {\n RedirectRule,\n RedirectStatus,\n} from \"schemas/routing/rules\"; /* eslint-disable-line replo/no-export-from -- site-facing entrypoint intentionally re-exports the authoring API. */\nexport { reploRedirect } from \"schemas/routing/rules\"; /* eslint-disable-line replo/no-export-from -- site-facing entrypoint intentionally re-exports the authoring API. */\n"],
5
+ "mappings": "AAcA,SAAS,qBAAqB;",
6
+ "names": []
7
+ }