Skip to content

Commit

Permalink
Merge branch 'main' of github.com:pantheon-systems/pantheon-content-c…
Browse files Browse the repository at this point in the history
…loud-sdk into od/graphql/update-pagination-format
  • Loading branch information
aumkar committed Jul 17, 2024
2 parents ffb566d + 8208018 commit 9425781
Show file tree
Hide file tree
Showing 42 changed files with 1,858 additions and 80 deletions.
6 changes: 6 additions & 0 deletions .changeset/chatty-suns-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pantheon-systems/pcc-sdk-core": patch
---

Fixed issue where some GQL parameters would not be passed to the API in
`getAllArticles`
5 changes: 5 additions & 0 deletions .changeset/ninety-ladybugs-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pantheon-systems/pcc-react-sdk": patch
---

Gracefully handle implementation edge case where a smart component map was provided to the ArticlerRenderer but without defining the react components that should be used.
5 changes: 5 additions & 0 deletions .changeset/tough-melons-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pantheon-systems/pcc-cli": patch
---

Don't notify the user that an update is available, if it is only a pre-release.
5 changes: 5 additions & 0 deletions .changeset/tough-zebras-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pantheon-systems/pcc-cli": minor
---

New command: site delete.
5 changes: 5 additions & 0 deletions .changeset/young-maps-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pantheon-systems/pcc-sdk-core": patch
---

PCC-GRANT (preview token) cookie now set with most relaxed security so that preview-pages can be shown in iframes.
2 changes: 1 addition & 1 deletion .github/workflows/changeset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout code repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: setup node.js
Expand Down
1,546 changes: 1,493 additions & 53 deletions configs/eslint/yarn.lock

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions packages/browser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @pantheon-systems/pcc-browser-sdk

## 3.6.1

### Patch Changes

- Updated dependencies [183ad17]
- @pantheon-systems/pcc-sdk-core@3.6.1

## 3.6.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.6.0",
"version": "3.6.1",
"main": "dist/index.js",
"files": [
"dist",
Expand Down
13 changes: 12 additions & 1 deletion packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
# @pantheon-systems/pcc-cli

## 3.6.1

### Patch Changes

- 0c75736: CLI replaces "--version" command with "version"
- 1fd7c4d: Added support for setting preferred webhook events. Webhook
notifications will only be sent on events matching preferred events
- Updated dependencies [183ad17]
- @pantheon-systems/pcc-sdk-core@3.6.1

## 3.6.0

### Patch Changes

- 3651708: Fix how protocols are being forwarded by API handler.
- 61363af: Removes inline sourcemaps. Sourcemaps are still provided, just linked in separate files instead.
- 61363af: Removes inline sourcemaps. Sourcemaps are still provided, just linked
in separate files instead.
- Updated dependencies [61363af]
- Updated dependencies [3651708]
- Updated dependencies [61363af]
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.6.0",
"version": "3.6.1",
"type": "module",
"license": "MIT",
"keywords": [
Expand Down
15 changes: 15 additions & 0 deletions packages/cli/src/cli/commands/sites/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ export const createSite = errorHandler<string>(async (url: string) => {
}
});

export const deleteSite = errorHandler<{
id: string;
transferToSiteId: string | null | undefined;
force: boolean;
}>(async ({ id, transferToSiteId, force }) => {
const spinner = ora("Deleting site...").start();
try {
await AddOnApiHelper.deleteSite(id, transferToSiteId, force);
spinner.succeed(`Successfully deleted the site with id "${id}"`);
} catch (e) {
spinner.fail();
throw e;
}
});

export const listSites = errorHandler<{
withStatus?: boolean;
}>(async ({ withStatus }) => {
Expand Down
38 changes: 38 additions & 0 deletions packages/cli/src/cli/commands/sites/webhooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import inquirer from "inquirer";
import ora from "ora";
import AddOnApiHelper from "../../../lib/addonApiHelper";
import { errorHandler } from "../../exceptions";

async function configurePreferredWebhookEvents(siteId: string) {
// Fetch available events
const availableEventsSpinner = ora("Fetching available events...").start();
const availableEvents =
await AddOnApiHelper.fetchAvailableWebhookEvents(siteId);
availableEventsSpinner.succeed("Fetched available events");

// Prompt user to select events
const { selectedEvents } = await inquirer.prompt([
{
type: "checkbox",
name: "selectedEvents",
message:
"Select events to receive notifications for. Select none to receive notifications for all events.",
choices: availableEvents,
},
]);

if (selectedEvents.length === 0) {
console.info(
"No events selected. Your webhook will receive notifications for all events.",
);
}

// Update events for the site
const updateEventsSpinner = ora("Updating preferred events...").start();
await AddOnApiHelper.updateSiteConfig(siteId, {
preferredEvents: selectedEvents,
});
updateEventsSpinner.succeed("Updated preferred events");
}

export default errorHandler(configurePreferredWebhookEvents);
12 changes: 7 additions & 5 deletions packages/cli/src/cli/exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,26 @@ export function errorHandler<T>(
if (cleanup) cleanup(arg);

if (e instanceof UserNotLoggedIn) {
console.log(chalk.red("Error: User is not logged in."));
console.log(chalk.yellow('Please run "pcc login" to login.'));
console.log(chalk.red("\nError: User is not logged in."));
console.log(chalk.yellow('\nPlease run "pcc login" to login.'));
} else {
if (
axios.isAxiosError(e) &&
(e.response?.status ?? 500) < 500 && // Treat internal server errors as unhandled errors
e.response?.data?.message
e.response?.data
) {
// Operational error
console.log(chalk.red(`Error: ${e.response.data.message}`));
console.log(
chalk.red(`\nError: ${e.response.data.message || e.response.data}`),
);
} else {
// Unhandled error
console.log(
chalk.yellow("\nStack trace:", (e as { stack: string }).stack),
);
console.log(
chalk.red(
"Error: Something went wrong. Please contact Pantheon support team.",
"\nError: Something went wrong. Please contact Pantheon support team.",
),
);
}
Expand Down
53 changes: 52 additions & 1 deletion packages/cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import ora from "ora";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import checkUpdate from "../lib/checkUpdate";
import checkUpdate, { getPackageDetails } from "../lib/checkUpdate";
import { isProgramInstalled } from "../lib/utils";
import {
printConfigurationData,
Expand Down Expand Up @@ -30,10 +30,12 @@ import {
import {
configurableSiteProperties,
createSite,
deleteSite,
listSites,
SITE_EXAMPLES,
updateSiteConfig,
} from "./commands/sites/site";
import configurePreferredWebhookEvents from "./commands/sites/webhooks";
import {
createToken,
listTokens,
Expand All @@ -59,6 +61,13 @@ yargs(hideBin(process.argv))
.middleware(configureMiddleware(checkUpdate))
.strictCommands()
.demandCommand()
.version(false)
.command(
"version",
"Prints the version of this CLI",
() => void 0,
() => console.log(getPackageDetails().version),
)
.command(
"init <project_directory> [options]",
"Sets up project with required files.",
Expand Down Expand Up @@ -371,6 +380,35 @@ yargs(hideBin(process.argv))
},
async (args) => await createSite(args.url as string),
)
.command(
"delete [options]",
"Delete site.",
(yargs) => {
yargs.option("id", {
describe: "Site id",
type: "string",
demandOption: true,
});
yargs.option("transferToSiteId", {
describe:
"Id of site to transfer connected documents to. Required if force is not used.",
type: "string",
demandOption: false,
});
yargs.option("force", {
describe:
"If true, delete even if documents are connected to it.",
type: "string",
demandOption: false,
});
},
async (args) =>
await deleteSite({
id: args.id as string,
transferToSiteId: args.transferToSiteId as string,
force: args.force === "true",
}),
)
.command(
"componentschema [command] [options]",
"Make changes & inspect the component schema for a site",
Expand Down Expand Up @@ -545,6 +583,19 @@ yargs(hideBin(process.argv))
id: args.id as string,
limit: args.limit as number,
}),
)
.command(
"preferred-events <id>",
"Set preferred webhook events for a given site. Your webhook will only receive notifications for events that you specify.",
(yargs) => {
yargs.strictCommands().positional("<id>", {
describe: "ID of the site for which you want to configure.",
demandOption: true,
type: "string",
});
},
async (args) =>
configurePreferredWebhookEvents(String(args.id)),
);
},
)
Expand Down
45 changes: 44 additions & 1 deletion packages/cli/src/lib/addonApiHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SmartComponentMapZod } from "@pantheon-systems/pcc-sdk-core/types";
import axios, { AxiosError, HttpStatusCode } from "axios";
import { Credentials } from "google-auth-library";
import ora from "ora";
import queryString from "query-string";
import login from "../cli/commands/login";
import { HTTPNotFound, UserNotLoggedIn } from "../cli/exceptions";
import { getApiConfig } from "./apiConfig";
Expand Down Expand Up @@ -290,6 +291,30 @@ class AddOnApiHelper {
return resp.data.id as string;
}

static async deleteSite(
id: string,
transferToSiteId: string | null | undefined,
force: boolean,
): Promise<string> {
const idToken = await this.getIdToken();

const resp = await axios.delete(
queryString.stringifyUrl({
url: `${(await getApiConfig()).SITE_ENDPOINT}/${id}`,
query: {
transferToSiteId,
force,
},
}),
{
headers: {
Authorization: `Bearer ${idToken}`,
},
},
);
return resp.data.id as string;
}

static async listSites({
withConnectionStatus,
}: {
Expand Down Expand Up @@ -430,15 +455,17 @@ class AddOnApiHelper {
url,
webhookUrl,
webhookSecret,
preferredEvents,
}: {
url?: string;
webhookUrl?: string;
webhookSecret?: string;
preferredEvents?: string[];
},
): Promise<void> {
const idToken = await this.getIdToken();

const configuredWebhook = webhookUrl || webhookSecret;
const configuredWebhook = webhookUrl || webhookSecret || preferredEvents;

await axios.patch(
`${(await getApiConfig()).SITE_ENDPOINT}/${id}`,
Expand All @@ -448,6 +475,7 @@ class AddOnApiHelper {
webhookConfig: {
...(webhookUrl && { webhookUrl: webhookUrl }),
...(webhookSecret && { webhookSecret: webhookSecret }),
...(preferredEvents && { preferredEvents }),
},
}),
},
Expand Down Expand Up @@ -486,6 +514,21 @@ class AddOnApiHelper {

return resp.data as WebhookDeliveryLog[];
}

static async fetchAvailableWebhookEvents(siteId: string) {
const idToken = await this.getIdToken();

const resp = await axios.get(
`${(await getApiConfig()).SITE_ENDPOINT}/${siteId}/availableWebhookEvents`,
{
headers: {
Authorization: `Bearer ${idToken}`,
},
},
);

return resp.data as string[];
}
}

export default AddOnApiHelper;
Loading

0 comments on commit 9425781

Please sign in to comment.