Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCC-1623: Initial implementation of metadata groups in SDK + starter kit #316

Merged
merged 20 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
572fb97
Initial implementation of metadata groups in SDK + starter kit (1/3rd…
kevinstubbs Oct 8, 2024
35f2547
Fix typing for metadata field.
kevinstubbs Oct 14, 2024
15e29cd
Merge branch 'main' of https://github.com/pantheon-systems/pantheon-c…
kevinstubbs Oct 14, 2024
347b2a4
Version beta as 3.10.0-beta.0
kevinstubbs Oct 14, 2024
30ede71
Allow caller to retrieve all groups and possible values in a single c…
kevinstubbs Oct 14, 2024
400fc48
Add changeset
kevinstubbs Oct 14, 2024
477792d
Pre-release update for retrieving hydrated metadata groups.
kevinstubbs Oct 14, 2024
6edc5cf
Starter kits all support custom metadata groups.
kevinstubbs Oct 17, 2024
45d8f50
Merge branch 'main' of https://github.com/pantheon-systems/pantheon-c…
kevinstubbs Oct 17, 2024
9c864b5
Fix starters build.
kevinstubbs Oct 17, 2024
bfe715a
Merge branch 'main' into PCC-1623-sdk-needs-to-support-metadata-group
kevinstubbs Dec 3, 2024
408ac40
Merge branch 'main' of https://github.com/pantheon-systems/pantheon-c…
kevinstubbs Dec 17, 2024
c136c8f
Use 'label' as the primary identifier for both group and its records.
kevinstubbs Dec 17, 2024
67bc79b
Update changeset for name => label change.
kevinstubbs Dec 17, 2024
2b90051
Bump beta version.
kevinstubbs Dec 17, 2024
a5639f8
Undo changes to vue package & starter kits.
kevinstubbs Dec 17, 2024
9ffdc92
Automated markdown changes.
kevinstubbs Dec 17, 2024
2281581
Fix unnecessary block codacy error.
kevinstubbs Dec 24, 2024
d3d8035
Merge branch 'main' into PCC-1623-sdk-needs-to-support-metadata-group
a11rew Dec 30, 2024
8550068
Merge branch 'main' into PCC-1623-sdk-needs-to-support-metadata-group
kevinstubbs Jan 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/good-weeks-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@pantheon-systems/next-approuter-pcc-starter-ts": patch
"@pantheon-systems/pcc-react-sample-library": patch
"@pantheon-systems/pcc-react-sdk": patch
"@pantheon-systems/pcc-browser-sdk": patch
"@pantheon-systems/pcc-sdk-core": patch
"@pantheon-systems/pcc-cli": patch
---

Use 'label' for metadata group record identifiers instead of 'name'
29 changes: 29 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"mode": "pre",
"tag": "beta",
"initialVersions": {
"eslint-config-pcc-custom": "1.0.0",
"testpages": "0.1.0",
"@pantheon-systems/pcc-browser-sdk": "3.9.0",
"@pantheon-systems/pcc-cli": "3.9.0",
"@pantheon-systems/pcc-sdk-core": "3.9.0",
"@pantheon-systems/pcc-react-sample-library": "3.9.0",
"@pantheon-systems/pcc-react-sdk": "3.9.0",
"@pantheon-systems/pcc-vue-sdk": "3.9.0",
"gatsby-pcc-starter": "1.0.0",
"gatsby-pcc-starter-ts": "1.0.0",
"@pantheon-systems/next-pcc-starter": "1.0.0",
"@pantheon-systems/next-approuter-pcc-starter-ts": "1.1.8",
"@pantheon-systems/next-pcc-starter-ts": "1.0.0",
"@pantheon-systems/vue-pcc-starter": "1.1.3",
"@pantheon-systems/vue-pcc-starter-ts": "1.1.3"
},
"changesets": [
"good-weeks-agree",
"plenty-rice-cheer",
"proud-socks-cry",
"seven-owls-poke",
"sixty-moose-act",
"ten-cats-swim"
]
}
5 changes: 5 additions & 0 deletions .changeset/seven-owls-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pantheon-systems/pcc-sdk-core": patch
---

Allow caller to retrieve all metadata groups, optionally hydrated.
5 changes: 5 additions & 0 deletions .changeset/sixty-moose-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pantheon-systems/pcc-sdk-core": minor
---

Add support for metadata groups (like authors).
22 changes: 22 additions & 0 deletions packages/browser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# @pantheon-systems/pcc-browser-sdk

## 3.10.0-beta.2

### Patch Changes

- 67bc79b: Use 'label' for metadata group record identifiers instead of 'name'
- Updated dependencies [67bc79b]
- @pantheon-systems/[email protected]

## 3.10.0-beta.1

### Patch Changes

- Updated dependencies [400fc48]
- @pantheon-systems/[email protected]

## 3.10.0-beta.0

### Patch Changes

- Updated dependencies [572fb97]
- @pantheon-systems/[email protected]

## 3.9.0

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@pantheon-systems/pcc-browser-sdk",
"author": "@pantheon-systems",
"description": "Pantheon Content Cloud Browser SDK",
"version": "3.9.0",
"version": "3.10.0-beta.2",
"main": "dist/index.js",
"files": [
"dist",
Expand Down
29 changes: 29 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# @pantheon-systems/pcc-cli

## 3.10.0-beta.2

### Minor Changes

- 0b3ee7b: No longer download turbo.json when initializing a new project from
the starter kit.

### Patch Changes

- 67bc79b: Use 'label' for metadata group record identifiers instead of 'name'
- 39b7604: Added a warning message when CLI build is pointing to non-production
environment.
- Updated dependencies [67bc79b]
- @pantheon-systems/[email protected]

## 3.10.0-beta.1

### Patch Changes

- Updated dependencies [400fc48]
- @pantheon-systems/[email protected]

## 3.10.0-beta.0

### Patch Changes

- Updated dependencies [572fb97]
- @pantheon-systems/[email protected]

## 3.9.0

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@pantheon-systems/pcc-cli",
"author": "@pantheon-systems",
"description": "Pantheon Content Cloud CLI",
"version": "3.9.0",
"version": "3.10.0-beta.2",
"type": "module",
"license": "MIT",
"keywords": [
Expand Down
18 changes: 18 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# @pantheon-systems/pcc-sdk-core

## 3.10.0-beta.2

### Patch Changes

- 67bc79b: Use 'label' for metadata group record identifiers instead of 'name'

## 3.10.0-beta.1

### Patch Changes

- 400fc48: Allow caller to retrieve all metadata groups, optionally hydrated.

## 3.10.0-beta.0

### Minor Changes

- 572fb97: Add support for metadata groups (like authors).

## 3.9.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@pantheon-systems/pcc-sdk-core",
"author": "@pantheon-systems",
"description": "Pantheon Content Cloud SDK Core",
"version": "3.9.0",
"version": "3.10.0-beta.2",
"license": "MIT",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
54 changes: 53 additions & 1 deletion packages/core/src/core/pantheon-api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import queryString from "query-string";
import { getArticleBySlugOrId, PCCConvenienceFunctions } from "../helpers";
import { parseJwt } from "../lib/jwt";
import { Article, SmartComponentMap } from "../types";
import { Article, MetadataGroup, SmartComponentMap } from "../types";
import { PantheonClient, PantheonClientConfig } from "./pantheon-client";

export interface ApiRequest {
Expand Down Expand Up @@ -85,6 +85,11 @@ export interface PantheonAPIOptions {
* Map of smart component names to their schemas.
*/
smartComponentMap?: SmartComponentMap;

/**
* Metadata groups, schemas, and how to retrieve their data.
*/
metadataGroups?: MetadataGroup[];
}

const defaultOptions = {
Expand Down Expand Up @@ -238,6 +243,53 @@ export const PantheonAPI = (givenOptions?: PantheonAPIOptions) => {
return await res.redirect(302, options.notFoundPath);
}

case "metadata_group": {
const groupIdentifier = command[1];
const objectId = command[2];

if (options.metadataGroups == null) {
return res.json({
error: "This collection has no metadata groups defined.",
});
}

if (groupIdentifier == null) {
return res.json({
rows: await Promise.all(
options.metadataGroups.map(
async ({ label, groupIdentifier, schema, list }) => ({
label,
groupIdentifier,
schema,
values:
restOfQuery.hydrate === "true" ? await list() : undefined,
}),
),
),
});
}

const group = await options.metadataGroups.find(
(x) => x.groupIdentifier === groupIdentifier,
);

if (!group) {
return res.json({
error: "Could not find matching group by given identifier.",
});
}

if (!objectId) {
return res.json({
rows: await group.list(),
});
}

return res.json({
row: await group.get(objectId),
});
}

default: {
return await res.redirect(302, options.notFoundPath);
}
Expand Down
26 changes: 26 additions & 0 deletions packages/core/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,37 @@ export interface PantheonTreeNode<T extends "component" | string = string> {
id?: string;
type?: string;
}

export interface PantheonTree {
version: string;
children: PantheonTreeNode[];
}

interface MetadataGroupRowEssentials {
label: string;
}

export interface MetadataGroup {
label: string;
groupIdentifier: string;
schema?: Record<
string,
"string" | "textarea" | "number" | "boolean" | "date" | "file"
>;
get: (
id: string,
) =>
| Promise<(unknown & MetadataGroupRowEssentials) | null | undefined>
| (unknown & MetadataGroupRowEssentials)
| null
| undefined;
list: () =>
| Promise<(unknown & MetadataGroupRowEssentials)[] | null | undefined>
| (unknown & MetadataGroupRowEssentials)[]
| null
| undefined;
}

const fieldTypes = z.enum([
"string",
"textarea",
Expand Down
26 changes: 26 additions & 0 deletions packages/react-sample-library/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# @pantheon-systems/pcc-vue-sdk

## 3.10.0-beta.2

### Patch Changes

- 67bc79b: Use 'label' for metadata group record identifiers instead of 'name'
- Updated dependencies [67bc79b]
- Updated dependencies [b89c5ee]
- @pantheon-systems/[email protected]
- @pantheon-systems/[email protected]

## 3.10.0-beta.1

### Patch Changes

- Updated dependencies [400fc48]
- @pantheon-systems/[email protected]
- @pantheon-systems/[email protected]

## 3.10.0-beta.0

### Patch Changes

- Updated dependencies [572fb97]
- @pantheon-systems/[email protected]
- @pantheon-systems/[email protected]

## 3.9.0

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/react-sample-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@pantheon-systems/pcc-react-sample-library",
"author": "@pantheon-systems",
"description": "Pantheon Content Cloud Sample Component Library for React",
"version": "3.9.0",
"version": "3.10.0-beta.2",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
Expand Down
27 changes: 27 additions & 0 deletions packages/react-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# @pantheon-systems/pcc-react-sdk

## 3.10.0-beta.2

### Minor Changes

- b89c5ee: The injected preview bar is deprecated in favor of the integrated
preview bar in the dashboard preview interface

### Patch Changes

- 67bc79b: Use 'label' for metadata group record identifiers instead of 'name'
- Updated dependencies [67bc79b]
- @pantheon-systems/[email protected]

## 3.10.0-beta.1

### Patch Changes

- Updated dependencies [400fc48]
- @pantheon-systems/[email protected]

## 3.10.0-beta.0

### Patch Changes

- Updated dependencies [572fb97]
- @pantheon-systems/[email protected]

## 3.9.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/react-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@pantheon-systems/pcc-react-sdk",
"author": "@pantheon-systems",
"description": "Pantheon Content Cloud React SDK",
"version": "3.9.0",
"version": "3.10.0-beta.2",
"license": "MIT",
"keywords": [
"pcc",
Expand Down
2 changes: 1 addition & 1 deletion starters/gatsby-starter-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"@mdx-js/react": "2.3.0",
"@pantheon-systems/pcc-react-sdk": "~3.9.0",
"@pantheon-systems/pcc-react-sdk": "~3.10.0-beta.2",
"@pantheon-systems/pds-toolkit-react": "1.0.0-dev.55",
"autoprefixer": "^10.4.17",
"gatsby": "5.13.5",
Expand Down
2 changes: 1 addition & 1 deletion starters/gatsby-starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"@mdx-js/react": "2.3.0",
"@pantheon-systems/pcc-react-sdk": "3.9.0",
"@pantheon-systems/pcc-react-sdk": "3.10.0-beta.2",
"@pantheon-systems/pds-toolkit-react": "1.0.0-dev.55",
"autoprefixer": "^10.4.17",
"gatsby": "5.13.5",
Expand Down
Loading
Loading