@canvas-digital/blog-sdk 2.0.0 → 2.0.1
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/README.md +24 -9
- package/dist/BlogPlatform.d.ts +2 -3
- package/dist/BlogPlatform.d.ts.map +1 -1
- package/dist/BlogPlatform.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/utils/env.d.ts +11 -7
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/utils/env.js +13 -11
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,20 +43,23 @@ apiKey: bp_public_... # or admin key
|
|
|
43
43
|
domain: example.com # optional
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
## Host app
|
|
46
|
+
## Host app `.env` (API base URL)
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
Use **one key** in every host app (Vite React, Next.js, or anything else):
|
|
49
49
|
|
|
50
50
|
```bash
|
|
51
|
-
|
|
51
|
+
BLOG_API_URL=https://blog-platform-backend-omega.vercel.app/api/v1
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
| Host | How `BLOG_API_URL` is exposed |
|
|
55
|
+
|------|-------------------------------|
|
|
56
|
+
| **Vite** | Set `envPrefix: ["VITE_", "BLOG_"]` in `vite.config` (see examples) |
|
|
57
|
+
| **Next.js** | Map it in `next.config` `env: { BLOG_API_URL: process.env.BLOG_API_URL }` |
|
|
58
|
+
| **Prop** | `<BlogPlatform apiUrl={...} />` overrides env |
|
|
59
|
+
|
|
60
|
+
Restart the dev server after changing `.env`. If unset, the SDK defaults to the production URL above. Legacy `VITE_BLOG_API_URL` / `NEXT_PUBLIC_BLOG_API_URL` still work.
|
|
58
61
|
|
|
59
|
-
`email`, `apiKey`, and optional `domain` are **props** on `BlogPlatform`, not env vars
|
|
62
|
+
`email`, `apiKey`, and optional `domain` are **props** on `BlogPlatform`, not env vars.
|
|
60
63
|
|
|
61
64
|
## Usage in your React app
|
|
62
65
|
|
|
@@ -95,7 +98,7 @@ import { BlogPlatform } from "@canvas-digital/blog-sdk";
|
|
|
95
98
|
| `theme` | user UI layout/colors |
|
|
96
99
|
| `adminTheme` | admin UI theme |
|
|
97
100
|
| `timeoutMs` | request timeout |
|
|
98
|
-
| `apiUrl` | override
|
|
101
|
+
| `apiUrl` | override `BLOG_API_URL` (usually omit) |
|
|
99
102
|
| `className` | wrapper class |
|
|
100
103
|
|
|
101
104
|
## Develop this package
|
|
@@ -108,3 +111,15 @@ npm test
|
|
|
108
111
|
npm run build
|
|
109
112
|
npm run dev # playground reads root .env
|
|
110
113
|
```
|
|
114
|
+
|
|
115
|
+
## Publish to npm
|
|
116
|
+
|
|
117
|
+
Create a granular access token on [npmjs.com](https://www.npmjs.com) (publish permission for `@canvas-digital/blog-sdk`). Do not commit the token.
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
npm config set //registry.npmjs.org/:_authToken=YOUR_NEW_TOKEN
|
|
121
|
+
npm whoami
|
|
122
|
+
npm publish --access public
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Bump `"version"` in `package.json` before each new release (npm rejects republishing the same version).
|
package/dist/BlogPlatform.d.ts
CHANGED
|
@@ -20,8 +20,7 @@ export type BlogPlatformProps = {
|
|
|
20
20
|
email: string;
|
|
21
21
|
/**
|
|
22
22
|
* Optional override for the platform API base URL.
|
|
23
|
-
* Prefer
|
|
24
|
-
* `VITE_BLOG_API_URL` or `NEXT_PUBLIC_BLOG_API_URL`
|
|
23
|
+
* Prefer `BLOG_API_URL` in the host app `.env` (works for Vite, Next, etc.).
|
|
25
24
|
*/
|
|
26
25
|
apiUrl?: string;
|
|
27
26
|
timeoutMs?: number;
|
|
@@ -34,7 +33,7 @@ export type BlogPlatformProps = {
|
|
|
34
33
|
* Drop into any React / Next.js app after `npm install @canvas-digital/blog-sdk`.
|
|
35
34
|
*
|
|
36
35
|
* - `email` + `apiKey` (+ optional `domain`) are sent as request headers
|
|
37
|
-
* - API base URL
|
|
36
|
+
* - API base URL from host `.env` key `BLOG_API_URL` (or prop `apiUrl`)
|
|
38
37
|
*/
|
|
39
38
|
export declare function BlogPlatform({ mode, domain, apiKey: apiKeyProp, email: emailProp, apiUrl: apiUrlOverride, timeoutMs, theme, branding, adminTheme, className, }: BlogPlatformProps): import("react").JSX.Element;
|
|
40
39
|
//# sourceMappingURL=BlogPlatform.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlogPlatform.d.ts","sourceRoot":"","sources":["../app/BlogPlatform.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGxD,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,OAAO,CAAC;AAEhD,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;OAGG;IACH,IAAI,EAAE,gBAAgB,CAAC;IACvB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd
|
|
1
|
+
{"version":3,"file":"BlogPlatform.d.ts","sourceRoot":"","sources":["../app/BlogPlatform.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGxD,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,OAAO,CAAC;AAEhD,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;OAGG;IACH,IAAI,EAAE,gBAAgB,CAAC;IACvB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,QAAQ,CAAC,EAAE,QAAQ,GAAG,aAAa,CAAC;IACpC,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,EAC3B,IAAI,EACJ,MAAM,EACN,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,cAAc,EACtB,SAAS,EACT,KAAK,EACL,QAAQ,EACR,UAAU,EACV,SAAS,GACV,EAAE,iBAAiB,+BAuDnB"}
|
package/dist/BlogPlatform.js
CHANGED
|
@@ -6,7 +6,7 @@ import { normalizeDomain, resolveBlogApiUrl } from "./utils/env";
|
|
|
6
6
|
* Drop into any React / Next.js app after `npm install @canvas-digital/blog-sdk`.
|
|
7
7
|
*
|
|
8
8
|
* - `email` + `apiKey` (+ optional `domain`) are sent as request headers
|
|
9
|
-
* - API base URL
|
|
9
|
+
* - API base URL from host `.env` key `BLOG_API_URL` (or prop `apiUrl`)
|
|
10
10
|
*/
|
|
11
11
|
export function BlogPlatform({ mode, domain, apiKey: apiKeyProp, email: emailProp, apiUrl: apiUrlOverride, timeoutMs, theme, branding, adminTheme, className, }) {
|
|
12
12
|
const clientDomain = normalizeDomain(domain);
|
|
@@ -17,7 +17,7 @@ export function BlogPlatform({ mode, domain, apiKey: apiKeyProp, email: emailPro
|
|
|
17
17
|
return (_jsxs("div", { className: className, role: "alert", children: ["Provide ", _jsx("code", { children: "mode" }), ", ", _jsx("code", { children: "email" }), ", and ", _jsx("code", { children: "apiKey" }), " ", "(sent as request headers). ", _jsx("code", { children: "domain" }), " is optional."] }));
|
|
18
18
|
}
|
|
19
19
|
if (!apiUrl) {
|
|
20
|
-
return (_jsxs("div", { className: className, role: "alert", children: ["Set
|
|
20
|
+
return (_jsxs("div", { className: className, role: "alert", children: ["Set ", _jsx("code", { children: "BLOG_API_URL" }), " in your app ", _jsx("code", { children: ".env" }), " ", "(e.g. ", _jsx("code", { children: "https://blog-platform-backend-omega.vercel.app/api/v1" }), ")."] }));
|
|
21
21
|
}
|
|
22
22
|
if (mode === "admin") {
|
|
23
23
|
return (_jsx(BlogAdmin, { className: className, config: {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from "./services";
|
|
2
2
|
export { BlogList, BlogDetail, BlogSearch, BlogCategories, BlogTags, FeaturedBlogs, RelatedBlogs, } from "./components/user";
|
|
3
|
-
export { sanitizeHtml, normalizeDomain, resolveBlogApiUrl, } from "./utils";
|
|
3
|
+
export { sanitizeHtml, normalizeDomain, resolveBlogApiUrl, DEFAULT_BLOG_API_URL, } from "./utils";
|
|
4
4
|
export { DEFAULT_THEME, formatDate, cardStyle, } from "./styles/userTheme";
|
|
5
5
|
export type { BlogTheme, ThemeColors, ThemeFonts, BlogComponentProps, Branding, } from "./types/user";
|
|
6
6
|
export { BlogAdmin } from "./pages/admin";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../app/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,OAAO,EACL,QAAQ,EACR,UAAU,EACV,UAAU,EACV,cAAc,EACd,QAAQ,EACR,aAAa,EACb,YAAY,GACb,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,YAAY,EACZ,eAAe,EACf,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../app/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAE3B,OAAO,EACL,QAAQ,EACR,UAAU,EACV,UAAU,EACV,cAAc,EACd,QAAQ,EACR,aAAa,EACb,YAAY,GACb,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,aAAa,EACb,UAAU,EACV,SAAS,GACV,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,QAAQ,GACT,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EACL,QAAQ,EACR,UAAU,EACV,eAAe,EACf,UAAU,EACV,YAAY,GACb,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,YAAY,EAAE,UAAU,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from "./services";
|
|
2
2
|
export { BlogList, BlogDetail, BlogSearch, BlogCategories, BlogTags, FeaturedBlogs, RelatedBlogs, } from "./components/user";
|
|
3
|
-
export { sanitizeHtml, normalizeDomain, resolveBlogApiUrl, } from "./utils";
|
|
3
|
+
export { sanitizeHtml, normalizeDomain, resolveBlogApiUrl, DEFAULT_BLOG_API_URL, } from "./utils";
|
|
4
4
|
export { DEFAULT_THEME, formatDate, cardStyle, } from "./styles/userTheme";
|
|
5
5
|
export { BlogAdmin } from "./pages/admin";
|
|
6
6
|
export { PostList, PostEditor, CategoryManager, TagManager, MediaManager, } from "./components/admin";
|
package/dist/utils/env.d.ts
CHANGED
|
@@ -3,14 +3,18 @@
|
|
|
3
3
|
* `https://example.com/blog` → `example.com`
|
|
4
4
|
*/
|
|
5
5
|
export declare function normalizeDomain(input?: string | null): string;
|
|
6
|
+
/** Deployed platform API — used when `BLOG_API_URL` is unset. */
|
|
7
|
+
export declare const DEFAULT_BLOG_API_URL = "https://blog-platform-backend-omega.vercel.app/api/v1";
|
|
6
8
|
/**
|
|
7
|
-
* Blog
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* -
|
|
12
|
-
*
|
|
13
|
-
*
|
|
9
|
+
* Resolve the Blog Platform API base URL.
|
|
10
|
+
*
|
|
11
|
+
* One key for every host (Vite, Next, CRA, Node):
|
|
12
|
+
* ```bash
|
|
13
|
+
* BLOG_API_URL=https://blog-platform-backend-omega.vercel.app/api/v1
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Legacy aliases still work: `VITE_BLOG_API_URL`, `NEXT_PUBLIC_BLOG_API_URL`.
|
|
17
|
+
* Or pass `apiUrl` on `<BlogPlatform />`.
|
|
14
18
|
*/
|
|
15
19
|
export declare function resolveBlogApiUrl(override?: string): string;
|
|
16
20
|
//# sourceMappingURL=env.d.ts.map
|
package/dist/utils/env.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../app/utils/env.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAY7D;AAuBD
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../app/utils/env.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAY7D;AAuBD,iEAAiE;AACjE,eAAO,MAAM,oBAAoB,0DACwB,CAAC;AAE1D;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAY3D"}
|
package/dist/utils/env.js
CHANGED
|
@@ -34,14 +34,18 @@ function readEnv(name) {
|
|
|
34
34
|
}
|
|
35
35
|
return undefined;
|
|
36
36
|
}
|
|
37
|
+
/** Deployed platform API — used when `BLOG_API_URL` is unset. */
|
|
38
|
+
export const DEFAULT_BLOG_API_URL = "https://blog-platform-backend-omega.vercel.app/api/v1";
|
|
37
39
|
/**
|
|
38
|
-
* Blog
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* -
|
|
43
|
-
*
|
|
44
|
-
*
|
|
40
|
+
* Resolve the Blog Platform API base URL.
|
|
41
|
+
*
|
|
42
|
+
* One key for every host (Vite, Next, CRA, Node):
|
|
43
|
+
* ```bash
|
|
44
|
+
* BLOG_API_URL=https://blog-platform-backend-omega.vercel.app/api/v1
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* Legacy aliases still work: `VITE_BLOG_API_URL`, `NEXT_PUBLIC_BLOG_API_URL`.
|
|
48
|
+
* Or pass `apiUrl` on `<BlogPlatform />`.
|
|
45
49
|
*/
|
|
46
50
|
export function resolveBlogApiUrl(override) {
|
|
47
51
|
const explicit = override?.trim();
|
|
@@ -50,8 +54,6 @@ export function resolveBlogApiUrl(override) {
|
|
|
50
54
|
}
|
|
51
55
|
const fromEnv = readEnv("BLOG_API_URL") ??
|
|
52
56
|
readEnv("VITE_BLOG_API_URL") ??
|
|
53
|
-
readEnv("NEXT_PUBLIC_BLOG_API_URL")
|
|
54
|
-
|
|
55
|
-
readEnv("NEXT_PUBLIC_API_URL");
|
|
56
|
-
return (fromEnv ?? "").replace(/\/+$/, "");
|
|
57
|
+
readEnv("NEXT_PUBLIC_BLOG_API_URL");
|
|
58
|
+
return (fromEnv ?? DEFAULT_BLOG_API_URL).replace(/\/+$/, "");
|
|
57
59
|
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../app/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../app/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { sanitizeHtml } from "./sanitize";
|
|
2
|
-
export { normalizeDomain, resolveBlogApiUrl } from "./env";
|
|
2
|
+
export { normalizeDomain, resolveBlogApiUrl, DEFAULT_BLOG_API_URL } from "./env";
|