@uniformdev/canvas-next 18.11.1-alpha.4 → 18.11.1-alpha.5

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,54 @@
1
+ // src/slug/withUniformGetStaticProps.ts
2
+ import { CANVAS_DRAFT_STATE, CANVAS_PUBLISHED_STATE, CanvasClient } from "@uniformdev/canvas";
3
+ var withUniformGetStaticProps = (callback, options) => {
4
+ return async function wrappedGetStaticProps(context) {
5
+ var _a;
6
+ if (!process.env.UNIFORM_API_KEY) {
7
+ throw new Error("UNIFORM_API_KEY is not defined.");
8
+ }
9
+ if (!process.env.UNIFORM_PROJECT_ID) {
10
+ throw new Error("UNIFORM_PROJECT_ID is not defined.");
11
+ }
12
+ const slugString = resolveSlugFromParams({
13
+ param: options == null ? void 0 : options.param,
14
+ params: context == null ? void 0 : context.params,
15
+ prefix: options == null ? void 0 : options.prefix
16
+ });
17
+ const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new CanvasClient({
18
+ apiKey: process.env.UNIFORM_API_KEY,
19
+ projectId: process.env.UNIFORM_PROJECT_ID,
20
+ apiHost: process.env.UNIFORM_CLI_BASE_URL
21
+ });
22
+ const { preview } = context;
23
+ const response = await canvasClient.getCompositionBySlug({
24
+ slug: slugString,
25
+ state: preview ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE
26
+ });
27
+ if (!response.composition) {
28
+ return {
29
+ notFound: true
30
+ };
31
+ }
32
+ const { composition } = response;
33
+ const ret = callback ? await callback(context, composition) : { props: {} };
34
+ if (Object.hasOwn(ret, "props")) {
35
+ const casted = ret;
36
+ casted.props["data"] = composition;
37
+ }
38
+ return ret;
39
+ };
40
+ };
41
+ var resolveSlugFromParams = ({
42
+ param = "slug",
43
+ params,
44
+ prefix
45
+ }) => {
46
+ const slug = (params == null ? void 0 : params[param]) || "";
47
+ const slugString = Array.isArray(slug) ? slug.join("/") : slug;
48
+ return `/${slugString}` || prefix || "/";
49
+ };
50
+
51
+ export {
52
+ withUniformGetStaticProps,
53
+ resolveSlugFromParams
54
+ };
@@ -0,0 +1,18 @@
1
+ import { RootComponentInstance } from '@uniformdev/canvas';
2
+ import { CompositionProps } from '@uniformdev/canvas-react';
3
+ import { NextPage, PreviewData, GetStaticPropsContext, GetStaticPropsResult, GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
4
+ import { ParsedUrlQuery } from 'querystring';
5
+
6
+ type UniformCompositionNextPage<TProps = unknown> = NextPage<TProps & CompositionProps>;
7
+ type UniformGetStaticProps<P extends {
8
+ [key: string]: any;
9
+ } = {
10
+ [key: string]: any;
11
+ }, Q extends ParsedUrlQuery = ParsedUrlQuery, D extends PreviewData = PreviewData> = (context: GetStaticPropsContext<Q, D>, composition: RootComponentInstance | undefined) => Promise<GetStaticPropsResult<P>> | GetStaticPropsResult<P>;
12
+ type UniformGetServerSideProps<P extends {
13
+ [key: string]: any;
14
+ } = {
15
+ [key: string]: any;
16
+ }, Q extends ParsedUrlQuery = ParsedUrlQuery, D extends PreviewData = PreviewData> = (context: GetServerSidePropsContext<Q, D>, composition: RootComponentInstance | undefined) => Promise<GetServerSidePropsResult<P>> | GetServerSidePropsResult<P>;
17
+
18
+ export { UniformCompositionNextPage as U, UniformGetStaticProps as a, UniformGetServerSideProps as b };
@@ -0,0 +1,18 @@
1
+ import { RootComponentInstance } from '@uniformdev/canvas';
2
+ import { CompositionProps } from '@uniformdev/canvas-react';
3
+ import { NextPage, PreviewData, GetStaticPropsContext, GetStaticPropsResult, GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
4
+ import { ParsedUrlQuery } from 'querystring';
5
+
6
+ declare type UniformCompositionNextPage<TProps = unknown> = NextPage<TProps & CompositionProps>;
7
+ declare type UniformGetStaticProps<P extends {
8
+ [key: string]: any;
9
+ } = {
10
+ [key: string]: any;
11
+ }, Q extends ParsedUrlQuery = ParsedUrlQuery, D extends PreviewData = PreviewData> = (context: GetStaticPropsContext<Q, D>, composition: RootComponentInstance | undefined) => Promise<GetStaticPropsResult<P>> | GetStaticPropsResult<P>;
12
+ declare type UniformGetServerSideProps<P extends {
13
+ [key: string]: any;
14
+ } = {
15
+ [key: string]: any;
16
+ }, Q extends ParsedUrlQuery = ParsedUrlQuery, D extends PreviewData = PreviewData> = (context: GetServerSidePropsContext<Q, D>, composition: RootComponentInstance | undefined) => Promise<GetServerSidePropsResult<P>> | GetServerSidePropsResult<P>;
17
+
18
+ export { UniformCompositionNextPage as U, UniformGetStaticProps as a, UniformGetServerSideProps as b };
@@ -0,0 +1,18 @@
1
+ import { RootComponentInstance } from '@uniformdev/canvas';
2
+ import { CompositionProps } from '@uniformdev/canvas-react';
3
+ import { NextPage, PreviewData, GetStaticPropsContext, GetStaticPropsResult, GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
4
+ import { ParsedUrlQuery } from 'querystring';
5
+
6
+ type UniformCompositionNextPage<TProps = unknown> = NextPage<TProps & CompositionProps>;
7
+ type UniformGetStaticProps<P extends {
8
+ [key: string]: any;
9
+ } = {
10
+ [key: string]: any;
11
+ }, Q extends ParsedUrlQuery = ParsedUrlQuery, D extends PreviewData = PreviewData> = (context: GetStaticPropsContext<Q, D>, composition: RootComponentInstance | undefined) => Promise<GetStaticPropsResult<P>> | GetStaticPropsResult<P>;
12
+ type UniformGetServerSideProps<P extends {
13
+ [key: string]: any;
14
+ } = {
15
+ [key: string]: any;
16
+ }, Q extends ParsedUrlQuery = ParsedUrlQuery, D extends PreviewData = PreviewData> = (context: GetServerSidePropsContext<Q, D>, composition: RootComponentInstance | undefined) => Promise<GetServerSidePropsResult<P>> | GetServerSidePropsResult<P>;
17
+
18
+ export { UniformCompositionNextPage as U, UniformGetStaticProps as a, UniformGetServerSideProps as b };
@@ -54,7 +54,7 @@ var withUniformGetServerSideProps = (options) => {
54
54
  const preview = context.preview || (options == null ? void 0 : options.preview);
55
55
  let composition = void 0;
56
56
  try {
57
- const response = await canvasClient.unstable_getCompositionByNodePath({
57
+ const response = await canvasClient.getCompositionByNodePath({
58
58
  ...options == null ? void 0 : options.requestOptions,
59
59
  projectMapId,
60
60
  projectMapNodePath: (options == null ? void 0 : options.prefix) ? context.resolvedUrl.replace(new RegExp(`^${options.prefix}`), "") : context.resolvedUrl,
@@ -160,7 +160,7 @@ var withUniformGetStaticProps = (options) => {
160
160
  const { preview, previewData } = context;
161
161
  let composition = void 0;
162
162
  try {
163
- const response = await canvasClient.unstable_getCompositionByNodePath({
163
+ const response = await canvasClient.getCompositionByNodePath({
164
164
  ...options == null ? void 0 : options.requestOptions,
165
165
  projectMapId,
166
166
  projectMapNodePath: pathString,
@@ -31,7 +31,7 @@ var withUniformGetServerSideProps = (options) => {
31
31
  const preview = context.preview || (options == null ? void 0 : options.preview);
32
32
  let composition = void 0;
33
33
  try {
34
- const response = await canvasClient.unstable_getCompositionByNodePath({
34
+ const response = await canvasClient.getCompositionByNodePath({
35
35
  ...options == null ? void 0 : options.requestOptions,
36
36
  projectMapId,
37
37
  projectMapNodePath: (options == null ? void 0 : options.prefix) ? context.resolvedUrl.replace(new RegExp(`^${options.prefix}`), "") : context.resolvedUrl,
@@ -130,7 +130,7 @@ var withUniformGetStaticProps = (options) => {
130
130
  const { preview, previewData } = context;
131
131
  let composition = void 0;
132
132
  try {
133
- const response = await canvasClient.unstable_getCompositionByNodePath({
133
+ const response = await canvasClient.getCompositionByNodePath({
134
134
  ...options == null ? void 0 : options.requestOptions,
135
135
  projectMapId,
136
136
  projectMapNodePath: pathString,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-next",
3
- "version": "18.11.1-alpha.4+66560ce33",
3
+ "version": "18.11.1-alpha.5+f9e0478f7",
4
4
  "description": "Next.js SDK for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -52,9 +52,9 @@
52
52
  "format": "prettier --write \"src/**/*.{js,ts,tsx}\""
53
53
  },
54
54
  "dependencies": {
55
- "@uniformdev/canvas": "18.11.1-alpha.4+66560ce33",
56
- "@uniformdev/canvas-react": "18.11.1-alpha.4+66560ce33",
57
- "@uniformdev/project-map": "18.11.1-alpha.4+66560ce33"
55
+ "@uniformdev/canvas": "18.11.1-alpha.5+f9e0478f7",
56
+ "@uniformdev/canvas-react": "18.11.1-alpha.5+f9e0478f7",
57
+ "@uniformdev/project-map": "18.11.1-alpha.5+f9e0478f7"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "next": ">= 12.0.0",
@@ -73,5 +73,5 @@
73
73
  "publishConfig": {
74
74
  "access": "public"
75
75
  },
76
- "gitHead": "66560ce3318690c0d27110357d13334a63e72d32"
76
+ "gitHead": "f9e0478f758622e7fe503b1490a13ef102f54566"
77
77
  }