Skip to content

Commit

Permalink
PCC-1882: Fixed minor issues and added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aumkar committed Jan 29, 2025
1 parent e80cc96 commit 748ffcc
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 37 deletions.
1 change: 1 addition & 0 deletions packages/cli/src/cli/commands/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const generatePreviewLink = errorHandler<GeneratePreviewParam>(

let previewLink: string;
try {
// TODO: Check if we can derive domain from the document
previewLink = await AddOnApiHelper.previewFile(cleanedId, domain, {
baseUrl,
});
Expand Down
17 changes: 4 additions & 13 deletions packages/cli/src/cli/commands/login.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
import nunjucks from "nunjucks";
import { getAuthProvider } from "../../lib/auth";
import { Auth0Provider } from "../../lib/auth";
import { errorHandler } from "../exceptions";

nunjucks.configure({ autoescape: true });

async function login({
authType,
scopes,
}: {
authType: "auth0" | "google";
scopes?: string[];
}): Promise<void> {
const provider = getAuthProvider(authType, scopes);
async function login(): Promise<void> {
const provider = new Auth0Provider();
await provider.login();
}
export default errorHandler<{
authType: "auth0" | "google";
scopes?: string[];
}>(login);
export default errorHandler<void>(login);
export const LOGIN_EXAMPLES = [
{ description: "Login the user", command: "$0 login" },
];
2 changes: 1 addition & 1 deletion packages/cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ yargs(hideBin(process.argv))
() => {
// noop
},
async () => await login({ authType: "auth0" }),
async () => await login(),
)
.command(
"logout",
Expand Down
18 changes: 7 additions & 11 deletions packages/cli/src/lib/addonApiHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,20 @@ class AddOnApiHelper {
}

static async publishDocument(documentId: string, domain: string) {
const { id_token: idToken, access_token: oauthToken } =
await this.getGoogleTokens({
scopes: ["https://www.googleapis.com/auth/drive.file"],
domain,
});

if (!idToken || !oauthToken) {
throw new UserNotLoggedIn();
}
const { access_token: auth0AccessToken } = await this.getAuth0Tokens();
const { access_token: googleAccessToken } = await this.getGoogleTokens({
scopes: ["https://www.googleapis.com/auth/drive.file"],
domain,
});

const resp = await axios.post<{ url: string }>(
`${(await getApiConfig()).DOCUMENT_ENDPOINT}/${documentId}/publish`,
{},
{
headers: {
Authorization: `Bearer ${idToken}`,
Authorization: `Bearer ${auth0AccessToken}`,
"Content-Type": "application/json",
"oauth-token": oauthToken,
"oauth-token": googleAccessToken,
},

Check warning

Code scanning / CodeQL

File data in outbound network request Medium

Outbound network request depends on
file data
.
},
);
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/lib/apiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const apiConfigMap: { [key in TargetEnvironment]: ApiConfig } = {
[TargetEnvironment.production]: {
addOnApiEndpoint:
"https://us-central1-pantheon-content-cloud.cloudfunctions.net/addOnApi",
// TODO: Update with the Auth0 prod tenant
auth0ClientId:
"432998952749-6eurouamlt7mvacb6u4e913m3kg4774c.apps.googleusercontent.com",
auth0RedirectUri: "http://localhost:3030/oauth-redirect",
Expand All @@ -32,9 +33,11 @@ const apiConfigMap: { [key in TargetEnvironment]: ApiConfig } = {
playgroundUrl: "https://live-collabcms-fe-demo.appa.pantheon.site",
},
[TargetEnvironment.staging]: {
// TODO: Uncomment the correct one
// addOnApiEndpoint:
// "https://us-central1-pantheon-content-cloud-staging.cloudfunctions.net/addOnApi",
addOnApiEndpoint: "http://localhost:8080",
// TODO: Update with the Auth0 staging tenant
auth0ClientId: "RAHxEbc251zD529hByapcv6Dcp3pmv4P",
auth0RedirectUri: "http://localhost:3030/oauth-redirect",
auth0Audience: "https://addonapi-cxog5ytt4a-uc.a.run.app",
Expand Down
21 changes: 9 additions & 12 deletions packages/cli/src/lib/localStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,30 @@ const readFile = async <T>(path: string): Promise<T | null> => {
export const getConfigDetails = async (): Promise<Config | null> => {
return readFile<Config>(CONFIG_FILE_PATH);
};
export const getAuthDetails = async (): Promise<PersistedTokens | null> => {
return readFile<PersistedTokens>(AUTH_FILE_PATH);
};
export const getGoogleAuthDetails = async (): Promise<
PersistedTokens[] | null
> => {
return readFile<PersistedTokens[]>(GOOGLE_AUTH_FILE_PATH);
};

export const persistConfigDetails = async (payload: Config): Promise<void> => {
await persistDetailsToFile(payload, CONFIG_FILE_PATH);
};

export const deleteConfigDetails = async () => remove(CONFIG_FILE_PATH);

export const getAuthDetails = async (): Promise<PersistedTokens | null> => {
return readFile<PersistedTokens>(AUTH_FILE_PATH);
};
export const persistAuthDetails = async (
payload: PersistedTokens,
): Promise<void> => {
await persistDetailsToFile(payload, AUTH_FILE_PATH);
};

export const getGoogleAuthDetails = async (): Promise<
PersistedTokens[] | null
> => {
return readFile<PersistedTokens[]>(GOOGLE_AUTH_FILE_PATH);
};
export const persistGoogleAuthDetails = async (
payload: PersistedTokens[],
): Promise<void> => {
await persistDetailsToFile(payload, GOOGLE_AUTH_FILE_PATH);
};

export const deleteConfigDetails = async () => remove(CONFIG_FILE_PATH);
export const deleteAuthDetails = async () => remove(AUTH_FILE_PATH);
export const deleteGoogleAuthDetails = async () =>
remove(GOOGLE_AUTH_FILE_PATH);

0 comments on commit 748ffcc

Please sign in to comment.