Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 13 additions & 11 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,13 @@ jobs:
- run:
name: Deploy apps to staging
command: |
STATIC_S3_BASE="s3://cf-apps-static-dev/apps-test-$CIRCLE_SHA1" \
STATIC_JIRA_S3_BASE="s3://cf-apps-static-dev/apps-test-$CIRCLE_SHA1/jira" \
STATIC_KLAVIYO_S3_BASE="s3://cf-apps-klaviyo/apps" \
REACT_APP_BACKEND_BASE_URL=$BACKEND_BASE_URL_TEST \
REACT_APP_SLACK_CLIENT_ID=$SLACK_CLIENT_ID_TEST \
STAGE='test' npm run deploy:test
STATIC_S3_BASE="s3://cf-apps-static-dev/apps" \
STATIC_TEST_S3_BASE="s3://cf-apps-static-dev/apps/apps-test-$CIRCLE_SHA1" \
STATIC_KLAVIYO_S3_BASE="s3://cf-apps-klaviyo/apps" \
REACT_APP_BACKEND_BASE_URL=$BACKEND_BASE_URL_TEST \
REACT_APP_SLACK_CLIENT_ID=$SLACK_CLIENT_ID_TEST \
STAGE='test' npm run deploy:test
GOOGLE_DOCS_TEST_CLOUDFRONT_DIST_ID=$GOOGLE_DOCS_TEST_CLOUDFRONT_DIST_ID \
- run:
name: Invalidate Slack staging cloudfront distribution
command: aws cloudfront create-invalidation --distribution-id $SLACK_TEST_CLOUDFRONT_DIST_ID --paths "/*"
Expand Down Expand Up @@ -154,11 +155,12 @@ jobs:
name: Deploy apps to prod
command: |
STATIC_S3_BASE="s3://cf-apps-static/apps" \
STATIC_JIRA_S3_BASE="s3://cf-apps-jira" \
STATIC_KLAVIYO_S3_BASE="s3://cf-apps-klaviyo/apps" \
REACT_APP_BACKEND_BASE_URL=$APP_SLACK_BACKEND_BASE_URL_PROD \
REACT_APP_SLACK_CLIENT_ID=$SLACK_CLIENT_ID_PROD \
STAGE='prd' npm run deploy
STATIC_JIRA_S3_BASE="s3://cf-apps-jira" \
STATIC_KLAVIYO_S3_BASE="s3://cf-apps-klaviyo/apps" \
REACT_APP_BACKEND_BASE_URL=$APP_SLACK_BACKEND_BASE_URL_PROD \
REACT_APP_SLACK_CLIENT_ID=$SLACK_CLIENT_ID_PROD \
STAGE='prd' npm run deploy
GOOGLE_DOCS_PROD_CLOUDFRONT_DIST_ID=$GOOGLE_DOCS_PROD_CLOUDFRONT_DIST_ID \
- run:
name: Post Deploy
command: npm run post-deploy
Expand Down
2 changes: 1 addition & 1 deletion apps/google-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"start": "cross-env BROWSER=none react-scripts --openssl-legacy-provider start",
"build": "react-scripts --openssl-legacy-provider build",
"deploy": "aws s3 sync ./build ${STATIC_S3_BASE}/google-analytics --acl public-read",
"deploy:test": "npm run deploy"
"deploy:test": "aws s3 sync ./build ${STATIC_TEST_S3_BASE}/google-analytics --acl public-read"
},
"eslintConfig": {
"extends": "react-app"
Expand Down
41 changes: 27 additions & 14 deletions apps/google-docs/contentful-app-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
},
"functions": [
{
"id": "createEntriesFromDocumentFunction",
"name": "Create content entries from document function",
"description": "Function to create content blocks from App Action.",
"path": "functions/createEntriesFromDocument.js",
"entryFile": "functions/createEntriesFromDocument.ts",
"id": "createPreview",
"name": "Create Preview",
"description": "Parses the Google Doc and creates preview entries",
"path": "functions/handlers/createPreview/createPreviewHandler.js",
"entryFile": "functions/handlers/createPreview/createPreviewHandler.ts",
"allowNetworks": [
"https://api.openai.com",
"*.googleapis.com",
Expand All @@ -37,12 +37,25 @@
"appaction.call"
]
},
{
"id": "analyzeContentTypes",
"name": "Analyze Content Types",
"description": "Analyzes content type structure and relationships using AI.",
"path": "functions/handlers/createPreview/createContentTypesAnalysisHandler.js",
"entryFile": "functions/handlers/createPreview/createContentTypesAnalysisHandler.ts",
"allowNetworks": [
"https://api.openai.com"
],
"accepts": [
"appaction.call"
]
},
{
"id": "initiateGdocOauth",
"name": "Initiate Gdoc OAuth Flow",
"description": "Initiates the OAuth flow for Google Docs",
"path": "functions/initiateOauth.js",
"entryFile": "functions/initiateOauth.ts",
"path": "functions/oauth/initiateOauth.js",
"entryFile": "functions/oauth/initiateOauth.ts",
"allowNetworks": [
"oauth2.googleapis.com"
],
Expand All @@ -54,8 +67,8 @@
"id": "completeGdocOauth",
"name": "Complete Gdoc OAuth Flow",
"description": "Completes the OAuth flow for Google Docs",
"path": "functions/completeOauth.js",
"entryFile": "functions/completeOauth.ts",
"path": "functions/oauth/completeOauth.js",
"entryFile": "functions/oauth/completeOauth.ts",
"allowNetworks": [
"oauth2.googleapis.com"
],
Expand All @@ -67,8 +80,8 @@
"id": "revokeGdocOauthToken",
"name": "Revoke Gdoc OAuth Token",
"description": "Revoke token for the Google Docs app to disconnect from the app",
"path": "functions/disconnect.js",
"entryFile": "functions/disconnect.ts",
"path": "functions/oauth/disconnect.js",
"entryFile": "functions/oauth/disconnect.ts",
"allowNetworks": [
"oauth2.googleapis.com"
],
Expand All @@ -80,8 +93,8 @@
"id": "checkGdocOauthTokenStatus",
"name": "Check Gdoc OAuth Token Status",
"description": "Checks the status of the Google Docs OAuth token to see if it is valid",
"path": "functions/checkStatus.js",
"entryFile": "functions/checkStatus.ts",
"path": "functions/oauth/checkStatus.js",
"entryFile": "functions/oauth/checkStatus.ts",
"allowNetworks": [
"oauth2.googleapis.com"
],
Expand All @@ -91,4 +104,4 @@
}
],
"actions": []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface ContentTypeParserConfig {
* @returns Promise resolving to structured parse result with summaries
*
*/
export async function analyzeContentTypes({
export async function createContentTypeAnalysisWithAgent({
contentTypes,
openAiApiKey,
}: ContentTypeParserConfig): Promise<FinalContentTypesResultSummary> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface DocumentParserConfig {
* @param config - Parser configuration including API key, document JSON, and content types
* @returns Promise resolving to entries ready for CMA client
*/
export async function analyzeDocumentWithAgent(
export async function createPreviewWithAgent(
config: DocumentParserConfig
): Promise<FinalEntriesResult> {
// TODO: Double check these values and make sure they are compatible because not every user will have a key
Expand Down
90 changes: 0 additions & 90 deletions apps/google-docs/functions/createEntriesFromDocument.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type {
FunctionEventContext,
FunctionEventHandler,
FunctionTypeEnum,
AppActionRequest,
} from '@contentful/node-apps-toolkit';
import { createContentTypeAnalysisWithAgent as analyzeContentTypesAgent } from '../../agents/contentTypeParserAgent/contentTypeParser.agent';
import { fetchContentTypes } from '../../service/contentTypeService';
import { initContentfulManagementClient } from '../../service/initCMAClient';

export type AnalyzeContentTypesParameters = {
contentTypeIds: string[];
};

interface AppInstallationParameters {
openAiApiKey: string;
}

export const handler: FunctionEventHandler<
FunctionTypeEnum.AppActionCall,
AnalyzeContentTypesParameters
> = async (
event: AppActionRequest<'Custom', AnalyzeContentTypesParameters>,
context: FunctionEventContext
) => {
const { contentTypeIds } = event.body;
const { openAiApiKey } = context.appInstallationParameters as AppInstallationParameters;

if (!contentTypeIds || contentTypeIds.length === 0) {
throw new Error('At least one content type ID is required');
}

const cma = initContentfulManagementClient(context);
const contentTypes = await fetchContentTypes(cma, new Set<string>(contentTypeIds));

const contentTypeParserAgentResult = await analyzeContentTypesAgent({
contentTypes,
openAiApiKey,
});

console.log('Content type analysis completed', contentTypeParserAgentResult);
return {
success: true,
analysis: contentTypeParserAgentResult,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import type {
FunctionEventContext,
FunctionEventHandler,
FunctionTypeEnum,
AppActionRequest,
} from '@contentful/node-apps-toolkit';
import { createPreviewWithAgent } from '../../agents/documentParserAgent/documentParser.agent';
import { fetchContentTypes } from '../../service/contentTypeService';
import { initContentfulManagementClient } from '../../service/initCMAClient';

export type CreatePreviewParameters = {
contentTypeIds: string[];
documentId: string;
oauthToken: string;
};

interface AppInstallationParameters {
openAiApiKey: string;
}

/**
* Create Preview
*
* Processes a Google Doc and creates preview entries based on the document structure
* and the provided content types.
*
*/
export const handler: FunctionEventHandler<
FunctionTypeEnum.AppActionCall,
CreatePreviewParameters
> = async (
event: AppActionRequest<'Custom', CreatePreviewParameters>,
context: FunctionEventContext
) => {
const { contentTypeIds, documentId, oauthToken } = event.body;
const { openAiApiKey } = context.appInstallationParameters as AppInstallationParameters;

if (!contentTypeIds || contentTypeIds.length === 0) {
throw new Error('At least one content type ID is required');
}

const cma = initContentfulManagementClient(context);

const contentTypes = await fetchContentTypes(cma, new Set<string>(contentTypeIds));

// Process the document and create preview entries
const aiDocumentResponse = await createPreviewWithAgent({
documentId,
oauthToken,
openAiApiKey,
contentTypes,
});

return {
success: true,
summary: aiDocumentResponse.summary,
totalEntriesExtracted: aiDocumentResponse.totalEntries,
entries: aiDocumentResponse.entries,
};
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
AppEventHandlerRequest,
AppEventHandlerResponse,
AppEventContext,
} from './types/oauth.types';
import { AppEventHandlerRequest, AppEventHandlerResponse, AppEventContext } from './oauth.types';

export const handler = async (
event: AppEventHandlerRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
AppEventHandlerRequest,
AppEventContext,
AppEventHandlerResponse,
} from './types/oauth.types';
} from './oauth.types';

export type OAuthSDK = {
init: () => Promise<OAuthInitResponse>;
Expand Down
16 changes: 0 additions & 16 deletions apps/google-docs/functions/observer/observer.ts

This file was deleted.

Loading