@cmssy/next 0.2.0 → 0.2.2
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/dist/index.cjs +31 -0
- package/dist/index.d.cts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.js +30 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1078,6 +1078,35 @@ function createCmssyAuthMiddleware(config) {
|
|
|
1078
1078
|
return refreshed;
|
|
1079
1079
|
};
|
|
1080
1080
|
}
|
|
1081
|
+
var PRODUCTS_QUERY = `query Products($workspaceId: String!, $modelSlug: String!, $filter: JSON, $limit: Int) {
|
|
1082
|
+
publicModelRecords(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, limit: $limit) {
|
|
1083
|
+
items { id data variants { id sku price inventory selectedOptions { name value } } }
|
|
1084
|
+
}
|
|
1085
|
+
}`;
|
|
1086
|
+
async function fetchProducts(config, options) {
|
|
1087
|
+
const workspaceId = await react.resolveWorkspaceId(config);
|
|
1088
|
+
const data = await react.graphqlRequest(
|
|
1089
|
+
config,
|
|
1090
|
+
PRODUCTS_QUERY,
|
|
1091
|
+
{
|
|
1092
|
+
workspaceId,
|
|
1093
|
+
modelSlug: options.modelSlug,
|
|
1094
|
+
filter: options.filter ?? {},
|
|
1095
|
+
limit: options.limit ?? 50
|
|
1096
|
+
},
|
|
1097
|
+
{ headers: { "x-workspace-id": workspaceId } },
|
|
1098
|
+
"products query"
|
|
1099
|
+
);
|
|
1100
|
+
return data.publicModelRecords.items;
|
|
1101
|
+
}
|
|
1102
|
+
async function fetchProduct(config, options) {
|
|
1103
|
+
const products = await fetchProducts(config, {
|
|
1104
|
+
modelSlug: options.modelSlug,
|
|
1105
|
+
filter: { [options.slugField ?? "slug"]: options.slug },
|
|
1106
|
+
limit: 1
|
|
1107
|
+
});
|
|
1108
|
+
return products[0] ?? null;
|
|
1109
|
+
}
|
|
1081
1110
|
|
|
1082
1111
|
exports.CMSSY_CART_COOKIE = CMSSY_CART_COOKIE;
|
|
1083
1112
|
exports.CMSSY_EDIT_HEADER = CMSSY_EDIT_HEADER;
|
|
@@ -1092,6 +1121,8 @@ exports.createCmssyAuthRoute = createCmssyAuthRoute;
|
|
|
1092
1121
|
exports.createCmssyCartRoute = createCmssyCartRoute;
|
|
1093
1122
|
exports.createCmssyPage = createCmssyPage;
|
|
1094
1123
|
exports.createDraftRoute = createDraftRoute;
|
|
1124
|
+
exports.fetchProduct = fetchProduct;
|
|
1125
|
+
exports.fetchProducts = fetchProducts;
|
|
1095
1126
|
exports.getCmssyAccessToken = getCmssyAccessToken;
|
|
1096
1127
|
exports.getCmssyLocale = getCmssyLocale;
|
|
1097
1128
|
exports.getCmssyUser = getCmssyUser;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ComponentType } from 'react';
|
|
3
|
-
import { CmssyPageData, CmssyFormDefinition, BlockDefinition, CmssyClientConfig } from '@cmssy/react';
|
|
3
|
+
import { CmssyPageData, CmssyFormDefinition, BlockDefinition, CmssyClientConfig, CmssyProduct } from '@cmssy/react';
|
|
4
4
|
import { EditBridgeConfig } from '@cmssy/react/client';
|
|
5
5
|
import { NextRequest, NextResponse } from 'next/server';
|
|
6
6
|
|
|
@@ -136,4 +136,17 @@ declare function getCmssyAccessToken(config: CmssyNextConfig): Promise<string |
|
|
|
136
136
|
type CmssyAuthMiddleware = (request: NextRequest) => Promise<NextResponse>;
|
|
137
137
|
declare function createCmssyAuthMiddleware(config: CmssyNextConfig): CmssyAuthMiddleware;
|
|
138
138
|
|
|
139
|
-
|
|
139
|
+
interface FetchProductsOptions {
|
|
140
|
+
modelSlug: string;
|
|
141
|
+
filter?: Record<string, unknown>;
|
|
142
|
+
limit?: number;
|
|
143
|
+
}
|
|
144
|
+
declare function fetchProducts(config: CmssyNextConfig, options: FetchProductsOptions): Promise<CmssyProduct[]>;
|
|
145
|
+
interface FetchProductOptions {
|
|
146
|
+
modelSlug: string;
|
|
147
|
+
slug: string;
|
|
148
|
+
slugField?: string;
|
|
149
|
+
}
|
|
150
|
+
declare function fetchProduct(config: CmssyNextConfig, options: FetchProductOptions): Promise<CmssyProduct | null>;
|
|
151
|
+
|
|
152
|
+
export { CMSSY_CART_COOKIE, CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, CMSSY_SESSION_COOKIE, type CmssyAuthConfig, type CmssyAuthMiddleware, type CmssyAuthRouteHandlers, type CmssyCartRouteHandlers, type CmssyCspOptions, type CmssyDraftRouteConfig, type CmssyEditorProps, type CmssyNextConfig, type CmssySessionPayload, type CmssySessionUser, type CreateCmssyPageOptions, type FetchProductOptions, type FetchProductsOptions, SESSION_MAX_AGE_SECONDS, type SessionCookieOptions, applyCmssyCsp, assertAuthConfig, cmssyCspHeaders, createCmssyAuthMiddleware, createCmssyAuthRoute, createCmssyCartRoute, createCmssyPage, createDraftRoute, fetchProduct, fetchProducts, getCmssyAccessToken, getCmssyLocale, getCmssyUser, isAccessExpired, isCmssyEditMode, isCmssyEditRequest, localeForPathname, openSession, sealSession, sessionCookieOptions, splitCmssyLocale };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ComponentType } from 'react';
|
|
3
|
-
import { CmssyPageData, CmssyFormDefinition, BlockDefinition, CmssyClientConfig } from '@cmssy/react';
|
|
3
|
+
import { CmssyPageData, CmssyFormDefinition, BlockDefinition, CmssyClientConfig, CmssyProduct } from '@cmssy/react';
|
|
4
4
|
import { EditBridgeConfig } from '@cmssy/react/client';
|
|
5
5
|
import { NextRequest, NextResponse } from 'next/server';
|
|
6
6
|
|
|
@@ -136,4 +136,17 @@ declare function getCmssyAccessToken(config: CmssyNextConfig): Promise<string |
|
|
|
136
136
|
type CmssyAuthMiddleware = (request: NextRequest) => Promise<NextResponse>;
|
|
137
137
|
declare function createCmssyAuthMiddleware(config: CmssyNextConfig): CmssyAuthMiddleware;
|
|
138
138
|
|
|
139
|
-
|
|
139
|
+
interface FetchProductsOptions {
|
|
140
|
+
modelSlug: string;
|
|
141
|
+
filter?: Record<string, unknown>;
|
|
142
|
+
limit?: number;
|
|
143
|
+
}
|
|
144
|
+
declare function fetchProducts(config: CmssyNextConfig, options: FetchProductsOptions): Promise<CmssyProduct[]>;
|
|
145
|
+
interface FetchProductOptions {
|
|
146
|
+
modelSlug: string;
|
|
147
|
+
slug: string;
|
|
148
|
+
slugField?: string;
|
|
149
|
+
}
|
|
150
|
+
declare function fetchProduct(config: CmssyNextConfig, options: FetchProductOptions): Promise<CmssyProduct | null>;
|
|
151
|
+
|
|
152
|
+
export { CMSSY_CART_COOKIE, CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, CMSSY_SESSION_COOKIE, type CmssyAuthConfig, type CmssyAuthMiddleware, type CmssyAuthRouteHandlers, type CmssyCartRouteHandlers, type CmssyCspOptions, type CmssyDraftRouteConfig, type CmssyEditorProps, type CmssyNextConfig, type CmssySessionPayload, type CmssySessionUser, type CreateCmssyPageOptions, type FetchProductOptions, type FetchProductsOptions, SESSION_MAX_AGE_SECONDS, type SessionCookieOptions, applyCmssyCsp, assertAuthConfig, cmssyCspHeaders, createCmssyAuthMiddleware, createCmssyAuthRoute, createCmssyCartRoute, createCmssyPage, createDraftRoute, fetchProduct, fetchProducts, getCmssyAccessToken, getCmssyLocale, getCmssyUser, isAccessExpired, isCmssyEditMode, isCmssyEditRequest, localeForPathname, openSession, sealSession, sessionCookieOptions, splitCmssyLocale };
|
package/dist/index.js
CHANGED
|
@@ -1076,5 +1076,34 @@ function createCmssyAuthMiddleware(config) {
|
|
|
1076
1076
|
return refreshed;
|
|
1077
1077
|
};
|
|
1078
1078
|
}
|
|
1079
|
+
var PRODUCTS_QUERY = `query Products($workspaceId: String!, $modelSlug: String!, $filter: JSON, $limit: Int) {
|
|
1080
|
+
publicModelRecords(workspaceId: $workspaceId, modelSlug: $modelSlug, filter: $filter, limit: $limit) {
|
|
1081
|
+
items { id data variants { id sku price inventory selectedOptions { name value } } }
|
|
1082
|
+
}
|
|
1083
|
+
}`;
|
|
1084
|
+
async function fetchProducts(config, options) {
|
|
1085
|
+
const workspaceId = await resolveWorkspaceId(config);
|
|
1086
|
+
const data = await graphqlRequest(
|
|
1087
|
+
config,
|
|
1088
|
+
PRODUCTS_QUERY,
|
|
1089
|
+
{
|
|
1090
|
+
workspaceId,
|
|
1091
|
+
modelSlug: options.modelSlug,
|
|
1092
|
+
filter: options.filter ?? {},
|
|
1093
|
+
limit: options.limit ?? 50
|
|
1094
|
+
},
|
|
1095
|
+
{ headers: { "x-workspace-id": workspaceId } },
|
|
1096
|
+
"products query"
|
|
1097
|
+
);
|
|
1098
|
+
return data.publicModelRecords.items;
|
|
1099
|
+
}
|
|
1100
|
+
async function fetchProduct(config, options) {
|
|
1101
|
+
const products = await fetchProducts(config, {
|
|
1102
|
+
modelSlug: options.modelSlug,
|
|
1103
|
+
filter: { [options.slugField ?? "slug"]: options.slug },
|
|
1104
|
+
limit: 1
|
|
1105
|
+
});
|
|
1106
|
+
return products[0] ?? null;
|
|
1107
|
+
}
|
|
1079
1108
|
|
|
1080
|
-
export { CMSSY_CART_COOKIE, CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, CMSSY_SESSION_COOKIE, SESSION_MAX_AGE_SECONDS, applyCmssyCsp, assertAuthConfig, cmssyCspHeaders, createCmssyAuthMiddleware, createCmssyAuthRoute, createCmssyCartRoute, createCmssyPage, createDraftRoute, getCmssyAccessToken, getCmssyLocale, getCmssyUser, isAccessExpired, isCmssyEditMode, isCmssyEditRequest, localeForPathname, openSession, sealSession, sessionCookieOptions, splitCmssyLocale };
|
|
1109
|
+
export { CMSSY_CART_COOKIE, CMSSY_EDIT_HEADER, CMSSY_LOCALE_HEADER, CMSSY_SESSION_COOKIE, SESSION_MAX_AGE_SECONDS, applyCmssyCsp, assertAuthConfig, cmssyCspHeaders, createCmssyAuthMiddleware, createCmssyAuthRoute, createCmssyCartRoute, createCmssyPage, createDraftRoute, fetchProduct, fetchProducts, getCmssyAccessToken, getCmssyLocale, getCmssyUser, isAccessExpired, isCmssyEditMode, isCmssyEditRequest, localeForPathname, openSession, sealSession, sessionCookieOptions, splitCmssyLocale };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmssy/next",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Next.js App Router bindings for cmssy headless sites (createCmssyPage + draft preview)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cmssy",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"dist"
|
|
37
37
|
],
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@cmssy/react": "^0.2.
|
|
39
|
+
"@cmssy/react": "^0.2.2",
|
|
40
40
|
"next": ">=15",
|
|
41
41
|
"react": "^18.2.0 || ^19.0.0",
|
|
42
42
|
"react-dom": "^18.2.0 || ^19.0.0"
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"tsup": "^8.3.0",
|
|
50
50
|
"typescript": "^5.6.0",
|
|
51
51
|
"vitest": "^2.1.0",
|
|
52
|
-
"@cmssy/react": "0.2.
|
|
52
|
+
"@cmssy/react": "0.2.2"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"jose": "^6.2.3"
|