-
Notifications
You must be signed in to change notification settings - Fork 384
feat: add Agility CMS plugin #928
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
84ec315
feat: add Agility CMS plugin
Rupak-25 e0da922
feat(agilitycms): implement 9 API operations, database entities, and …
Dhirenderchoudhary aec4cf5
fix(agilitycms): add page module filtering, apiBaseUrl option, and sc…
Dhirenderchoudhary b871e6f
Merge branch 'upstream/main' into feat/agility-cms-plugin-merge-fix
Dhirenderchoudhary File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import type { ApiRequestOptions, OpenAPIConfig } from 'corsair/http'; | ||
| import { request } from 'corsair/http'; | ||
|
|
||
| export async function makeAgilityCmsRequest<T>( | ||
| instanceGuid: string, | ||
| apiKey: string, | ||
| apiType: 'fetch' | 'preview' = 'fetch', | ||
| endpoint: string, | ||
| options: { | ||
| method?: 'GET' | 'POST'; | ||
| query?: Record<string, string | number | boolean | undefined>; | ||
| body?: Record<string, unknown>; | ||
| apiBaseUrl?: string; | ||
| } = {}, | ||
| ): Promise<T> { | ||
| const { | ||
| method = 'GET', | ||
| query, | ||
| body, | ||
| apiBaseUrl = 'https://api.aglty.io', | ||
| } = options; | ||
|
|
||
| const config: OpenAPIConfig = { | ||
| BASE: `${apiBaseUrl.replace(/\/$/, '')}/${instanceGuid}/${apiType}`, | ||
| VERSION: '1.0.0', | ||
| WITH_CREDENTIALS: false, | ||
| CREDENTIALS: 'omit', | ||
| TOKEN: undefined, | ||
| HEADERS: { | ||
| Accept: 'application/json', | ||
| APIKey: apiKey, | ||
| }, | ||
| }; | ||
|
|
||
| const requestOptions: ApiRequestOptions = { | ||
| method, | ||
| url: endpoint, | ||
| mediaType: 'application/json', | ||
| query, | ||
| body, | ||
| }; | ||
|
|
||
| return await request<T>(config, requestOptions); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,306 @@ | ||
| import { logEventFromContext } from 'corsair/core'; | ||
| import { makeAgilityCmsRequest } from '../client'; | ||
| import type { AgilityCmsContext } from '../index'; | ||
| import type { | ||
| GetApiTypesInput, | ||
| GetApiTypesResponse, | ||
| GetContentModelsInput, | ||
| GetContentModelsResponse, | ||
| GetItemInput, | ||
| GetItemResponse, | ||
| GetListInput, | ||
| GetListResponse, | ||
| GetLogsInput, | ||
| GetLogsResponse, | ||
| GetPageInput, | ||
| GetPageModulesInput, | ||
| GetPageModulesResponse, | ||
| GetPageResponse, | ||
| GetSitemapFlatInput, | ||
| GetSitemapFlatResponse, | ||
| PageModule, | ||
| SyncPagesInput, | ||
| SyncPagesResponse, | ||
| } from './types'; | ||
| import { | ||
| GetApiTypesResponseSchema, | ||
| GetContentModelsResponseSchema, | ||
| GetItemResponseSchema, | ||
| GetListResponseSchema, | ||
| GetLogsResponseSchema, | ||
| GetPageModulesResponseSchema, | ||
| GetPageResponseSchema, | ||
| GetSitemapFlatResponseSchema, | ||
| SyncPagesResponseSchema, | ||
| } from './types'; | ||
|
|
||
| function compactQuery( | ||
| query: Record<string, string | number | boolean | undefined>, | ||
| ): Record<string, string | number | boolean> { | ||
| return Object.fromEntries( | ||
| Object.entries(query).filter(([, value]) => value !== undefined), | ||
| ) as Record<string, string | number | boolean>; | ||
| } | ||
|
|
||
| export const getPage = async ( | ||
| ctx: AgilityCmsContext, | ||
| input: GetPageInput, | ||
| ): Promise<GetPageResponse> => { | ||
| const response = await makeAgilityCmsRequest<GetPageResponse>( | ||
| input.instanceGuid, | ||
| ctx.key, | ||
| input.apiType, | ||
| `${input.locale}/page/${input.pageId}`, | ||
| { | ||
| apiBaseUrl: ctx.options?.apiBaseUrl, | ||
| query: compactQuery({ | ||
| contentLinkDepth: input.contentLinkDepth, | ||
| expandAllContentLinks: input.expandAllContentLinks, | ||
| }), | ||
| }, | ||
| ); | ||
|
|
||
| const parsed = GetPageResponseSchema.parse(response); | ||
|
|
||
| await logEventFromContext( | ||
| ctx, | ||
| 'agilitycms.content.getPage', | ||
| { ...input }, | ||
| 'completed', | ||
| ); | ||
|
|
||
| return parsed; | ||
| }; | ||
|
|
||
| export const getItem = async ( | ||
| ctx: AgilityCmsContext, | ||
| input: GetItemInput, | ||
| ): Promise<GetItemResponse> => { | ||
| const response = await makeAgilityCmsRequest<GetItemResponse>( | ||
| input.instanceGuid, | ||
| ctx.key, | ||
| input.apiType, | ||
| `${input.locale}/item/${input.contentId}`, | ||
| { | ||
| apiBaseUrl: ctx.options?.apiBaseUrl, | ||
| query: compactQuery({ | ||
| contentLinkDepth: input.contentLinkDepth, | ||
| expandAllContentLinks: input.expandAllContentLinks, | ||
| }), | ||
| }, | ||
| ); | ||
|
|
||
| const parsed = GetItemResponseSchema.parse(response); | ||
|
|
||
| await logEventFromContext( | ||
| ctx, | ||
| 'agilitycms.content.getItem', | ||
| { ...input }, | ||
| 'completed', | ||
| ); | ||
|
|
||
| return parsed; | ||
| }; | ||
|
|
||
| export const getList = async ( | ||
| ctx: AgilityCmsContext, | ||
| input: GetListInput, | ||
| ): Promise<GetListResponse> => { | ||
| const response = await makeAgilityCmsRequest<GetListResponse>( | ||
| input.instanceGuid, | ||
| ctx.key, | ||
| input.apiType, | ||
| `${input.locale}/list/${input.referenceName}`, | ||
| { | ||
| apiBaseUrl: ctx.options?.apiBaseUrl, | ||
| query: compactQuery({ | ||
| contentLinkDepth: input.contentLinkDepth, | ||
| expandAllContentLinks: input.expandAllContentLinks, | ||
| take: input.take, | ||
| skip: input.skip, | ||
| sort: input.sort, | ||
| direction: input.direction, | ||
| filter: input.filter, | ||
| }), | ||
| }, | ||
| ); | ||
|
|
||
| const parsed = GetListResponseSchema.parse(response); | ||
|
|
||
| await logEventFromContext( | ||
| ctx, | ||
| 'agilitycms.content.getList', | ||
| { ...input }, | ||
| 'completed', | ||
| ); | ||
|
|
||
| return parsed; | ||
| }; | ||
|
|
||
| export const getContentModels = async ( | ||
| ctx: AgilityCmsContext, | ||
| input: GetContentModelsInput, | ||
| ): Promise<GetContentModelsResponse> => { | ||
| const response = await makeAgilityCmsRequest<GetContentModelsResponse>( | ||
| input.instanceGuid, | ||
| ctx.key, | ||
| input.apiType, | ||
| `${input.locale}/models`, | ||
| { | ||
| apiBaseUrl: ctx.options?.apiBaseUrl, | ||
| }, | ||
| ); | ||
|
|
||
| const parsed = GetContentModelsResponseSchema.parse(response); | ||
|
|
||
| await logEventFromContext( | ||
| ctx, | ||
| 'agilitycms.content.getContentModels', | ||
| { ...input }, | ||
| 'completed', | ||
| ); | ||
|
|
||
| return parsed; | ||
| }; | ||
|
|
||
| export const getPageModules = async ( | ||
| ctx: AgilityCmsContext, | ||
| input: GetPageModulesInput, | ||
| ): Promise<GetPageModulesResponse> => { | ||
| const response = await makeAgilityCmsRequest<PageModule[]>( | ||
| input.instanceGuid, | ||
| ctx.key, | ||
| input.apiType, | ||
| `${input.locale}/models`, | ||
| { | ||
| apiBaseUrl: ctx.options?.apiBaseUrl, | ||
| }, | ||
| ); | ||
|
|
||
| const filtered = (Array.isArray(response) ? response : []).filter( | ||
| (item) => !item.referenceName || item.referenceName.trim() === '', | ||
| ); | ||
|
|
||
| const parsed = GetPageModulesResponseSchema.parse(filtered); | ||
|
|
||
| await logEventFromContext( | ||
| ctx, | ||
| 'agilitycms.content.getPageModules', | ||
| { ...input }, | ||
| 'completed', | ||
| ); | ||
|
|
||
| return parsed; | ||
| }; | ||
|
|
||
| export const getSitemapFlat = async ( | ||
| ctx: AgilityCmsContext, | ||
| input: GetSitemapFlatInput, | ||
| ): Promise<GetSitemapFlatResponse> => { | ||
| const response = await makeAgilityCmsRequest<GetSitemapFlatResponse>( | ||
| input.instanceGuid, | ||
| ctx.key, | ||
| input.apiType, | ||
| `${input.locale}/sitemap/flat/${input.channelName}`, | ||
| { | ||
| apiBaseUrl: ctx.options?.apiBaseUrl, | ||
| }, | ||
| ); | ||
|
|
||
| const parsed = GetSitemapFlatResponseSchema.parse(response); | ||
|
|
||
| await logEventFromContext( | ||
| ctx, | ||
| 'agilitycms.content.getSitemapFlat', | ||
| { ...input }, | ||
| 'completed', | ||
| ); | ||
|
|
||
| return parsed; | ||
| }; | ||
|
|
||
| export const getLogs = async ( | ||
| ctx: AgilityCmsContext, | ||
| input: GetLogsInput, | ||
| ): Promise<GetLogsResponse> => { | ||
| const response = await makeAgilityCmsRequest<GetLogsResponse>( | ||
| input.instanceGuid, | ||
| ctx.key, | ||
| input.apiType, | ||
| `${input.locale}/sync/items`, | ||
| { | ||
| apiBaseUrl: ctx.options?.apiBaseUrl, | ||
| query: compactQuery({ | ||
| syncToken: input.syncToken ?? '0', | ||
| pageSize: input.pageSize, | ||
| }), | ||
| }, | ||
| ); | ||
|
|
||
| const parsed = GetLogsResponseSchema.parse(response); | ||
|
|
||
| await logEventFromContext( | ||
| ctx, | ||
| 'agilitycms.content.getLogs', | ||
| { ...input }, | ||
| 'completed', | ||
| ); | ||
|
|
||
| return parsed; | ||
| }; | ||
|
|
||
| export const syncPages = async ( | ||
| ctx: AgilityCmsContext, | ||
| input: SyncPagesInput, | ||
| ): Promise<SyncPagesResponse> => { | ||
| const response = await makeAgilityCmsRequest<SyncPagesResponse>( | ||
| input.instanceGuid, | ||
| ctx.key, | ||
| input.apiType, | ||
| `${input.locale}/sync/pages`, | ||
| { | ||
| apiBaseUrl: ctx.options?.apiBaseUrl, | ||
| query: compactQuery({ | ||
| syncToken: input.syncToken ?? '0', | ||
| pageSize: input.pageSize, | ||
| }), | ||
| }, | ||
| ); | ||
|
|
||
| const parsed = SyncPagesResponseSchema.parse(response); | ||
|
|
||
| await logEventFromContext( | ||
| ctx, | ||
| 'agilitycms.content.syncPages', | ||
| { ...input }, | ||
| 'completed', | ||
| ); | ||
|
|
||
| return parsed; | ||
| }; | ||
|
|
||
| export const getApiTypes = async ( | ||
| ctx: AgilityCmsContext, | ||
| input: GetApiTypesInput, | ||
| ): Promise<GetApiTypesResponse> => { | ||
| const response = await makeAgilityCmsRequest<GetApiTypesResponse>( | ||
| input.instanceGuid, | ||
| ctx.key, | ||
| input.apiType, | ||
| `${input.locale ?? 'en-us'}/types`, | ||
| { | ||
| apiBaseUrl: ctx.options?.apiBaseUrl, | ||
| }, | ||
| ); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| const parsed = GetApiTypesResponseSchema.parse(response); | ||
|
|
||
| await logEventFromContext( | ||
| ctx, | ||
| 'agilitycms.content.getApiTypes', | ||
| { ...input }, | ||
| 'completed', | ||
| ); | ||
|
|
||
| return parsed; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * as Content from './content'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.