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

feat: add function support #2512

Closed
wants to merge 7 commits into from
Closed
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
11 changes: 11 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
steps:
- with-workspace
- run: npm run build
- persist-workspace

lint:
executor: docker-with-node
Expand All @@ -81,6 +82,12 @@ jobs:
- store_artifacts:
path: ./reports/unit-results.xml

size:
executor: docker-with-node
steps:
- with-workspace
- run: npm run test:size

integration:
executor: docker-with-node
steps:
Expand Down Expand Up @@ -122,6 +129,10 @@ workflows:
- build
- unit
- lint
- size:
requires:
- prepare
- build

- release:
context: vault
Expand Down
41 changes: 41 additions & 0 deletions lib/adapters/REST/endpoints/function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { AxiosInstance } from 'contentful-sdk-core'
import * as raw from './raw'
import { normalizeSelect } from './utils'
import type {
CollectionProp,
GetFunctionForEnvParams,
GetFunctionParams,
} from '../../../common-types'
import type { RestEndpoint } from '../types'
import type { FunctionProps } from '../../../entities/function'

const getBaseUrl = (params: GetFunctionParams) =>
`/organizations/${params.organizationId}/app_definitions/${params.appDefinitionId}/functions`

const getFunctionUrl = (params: GetFunctionParams) =>
`${getBaseUrl(params)}/${params.functionId}`

const getFunctionsEnvURL = (params: GetFunctionForEnvParams) => {
return `/spaces/${params.spaceId}/environments/${params.environmentId}/app_installations/${params.appInstallationId}/functions`
}

export const get: RestEndpoint<'Function', 'get'> = (
http: AxiosInstance,
params: GetFunctionParams
) => {
return raw.get<FunctionProps>(http, getFunctionUrl(params))
}

export const getMany: RestEndpoint<'Function', 'getMany'> = (
http: AxiosInstance,
params: GetFunctionParams
) => {
return raw.get<CollectionProp<FunctionProps>>(http, getBaseUrl(params))
}

export const getManyForEnvironment: RestEndpoint<'Function', 'getManyForEnvironment'> = (
http: AxiosInstance,
params: GetFunctionForEnvParams
) => {
return raw.get<CollectionProp<FunctionProps>>(http, getFunctionsEnvURL(params))
}
17 changes: 11 additions & 6 deletions lib/common-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,10 @@ type MRInternal<UA extends boolean> = {
(opts: MROpts<'Extension', 'update', UA>): MRReturn<'Extension', 'update'>
(opts: MROpts<'Extension', 'delete', UA>): MRReturn<'Extension', 'delete'>

(opts: MROpts<'Function', 'get', UA>): MRReturn<'Function', 'get'>
(opts: MROpts<'Function', 'getMany', UA>): MRReturn<'Function', 'getMany'>
(opts: MROpts<'Function', 'getManyForEnvironment', UA>): MRReturn<'Function', 'getManyForEnvironment'>

(opts: MROpts<'Locale', 'get', UA>): MRReturn<'Locale', 'get'>
(opts: MROpts<'Locale', 'getMany', UA>): MRReturn<'Locale', 'getMany'>
(opts: MROpts<'Locale', 'delete', UA>): MRReturn<'Locale', 'delete'>
Expand Down Expand Up @@ -1276,12 +1280,6 @@ export type MRActions = {
return: EditorInterfaceProps
}
}
Function: {
getMany: {
params: GetAppDefinitionParams & QueryParams
return: CollectionProp<FunctionProps>
}
}
Environment: {
get: { params: GetSpaceEnvironmentParams; return: EnvironmentProps }
getMany: {
Expand Down Expand Up @@ -1494,6 +1492,11 @@ export type MRActions = {
}
delete: { params: GetExtensionParams; return: any }
}
Function: {
get: { params: GetFunctionParams; return: FunctionProps }
getMany: { params: GetFunctionParams; return: CollectionProp<FunctionProps> }
getManyForEnvironment: { params: GetFunctionForEnvParams; return: CollectionProp<FunctionProps> }
}
Locale: {
get: { params: GetSpaceEnvironmentParams & { localeId: string }; return: LocaleProps }
getMany: {
Expand Down Expand Up @@ -2076,6 +2079,8 @@ export type GetEditorInterfaceParams = GetSpaceEnvironmentParams & { contentType
export type GetEntryParams = GetSpaceEnvironmentParams & { entryId: string }
export type GetExtensionParams = GetSpaceEnvironmentParams & { extensionId: string }
export type GetEnvironmentTemplateParams = GetOrganizationParams & { environmentTemplateId: string }
export type GetFunctionParams = GetAppDefinitionParams & { functionId?: string}
export type GetFunctionForEnvParams = GetSpaceParams & { environmentId: string } & { appInstallationId: string }
export type GetOrganizationParams = { organizationId: string }
export type GetReleaseParams = GetSpaceEnvironmentParams & { releaseId: string }
export type GetSnapshotForContentTypeParams = GetSpaceEnvironmentParams & { contentTypeId: string }
Expand Down
19 changes: 7 additions & 12 deletions lib/plain/common-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
CollectionProp,
CursorPaginatedCollectionProp,
EnvironmentTemplateParams,
GetAppDefinitionParams,
GetBulkActionParams,
GetContentTypeParams,
GetEnvironmentTemplateParams,
Expand Down Expand Up @@ -87,19 +86,19 @@ import type { AppInstallationPlainClientAPI } from './entities/app-installation'
import type { WebhookPlainClientAPI } from './entities/webhook'
import type { AppSignedRequestPlainClientAPI } from './entities/app-signed-request'
import type { AppSigningSecretPlainClientAPI } from './entities/app-signing-secret'
import type { ExtensionPlainClientAPI } from './entities/extension'
import type { AppEventSubscriptionPlainClientAPI } from './entities/app-event-subscription'
import type { AppKeyPlainClientAPI } from './entities/app-key'
import type { UserPlainClientAPI } from './entities/user'
import type { UploadPlainClientAPI } from './entities/upload'
import type { OrganizationPlainClientAPI } from './entities/organization'
import type { EnvironmentPlainClientAPI } from './entities/environment'
import type { EnvironmentAliasPlainClientAPI } from './entities/environment-alias'
import type { ExtensionPlainClientAPI } from './entities/extension'
import type { FunctionPlainClientAPI } from './entities/function'
import type { LocalePlainClientAPI } from './entities/locale'
import type { OrganizationPlainClientAPI } from './entities/organization'
import type { SpacePlainClientAPI } from './entities/space'
import type { SpaceMembershipPlainClientAPI } from './entities/space-membership'
import type { SpaceMemberPlainClientAPI } from './entities/space-member'
import type { EnvironmentPlainClientAPI } from './entities/environment'
import type { EnvironmentAliasPlainClientAPI } from './entities/environment-alias'
import type { CommentPlainClientAPI } from './entities/comment'
import type { SpaceMembershipPlainClientAPI } from './entities/space-membership'
import type { TaskPlainClientAPI } from './entities/task'
import type { WorkflowPlainClientAPI } from './entities/workflow'
import type { WorkflowsChangelogPlainClientAPI } from './entities/workflows-changelog'
Expand Down Expand Up @@ -136,11 +135,7 @@ export type PlainClientAPI = {
appSignedRequest: AppSignedRequestPlainClientAPI
appSigningSecret: AppSigningSecretPlainClientAPI
appAccessToken: AppAccessTokenPlainClientAPI
function: {
getMany(
params: OptionalDefaults<GetAppDefinitionParams & QueryParams>
): Promise<CollectionProp<FunctionProps>>
}
function: FunctionPlainClientAPI
editorInterface: EditorInterfacePlainClientAPI
space: SpacePlainClientAPI
environment: EnvironmentPlainClientAPI
Expand Down
61 changes: 61 additions & 0 deletions lib/plain/entities/function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import type {
CollectionProp,
GetFunctionParams,
GetFunctionForEnvParams,
QueryParams,
} from '../../common-types'
import type { FunctionProps } from '../../entities/function'
import type { OptionalDefaults } from '../wrappers/wrap'

export type FunctionPlainClientAPI = {
/**
* Fetches the specified function
* @param params organization ID, app definition ID, entity ID to identify the function
* @returns the function
* @throws if the request fails, or the Function is not found
* @example
* ```javascript
* const func = await client.function.get({
* organizationId: "<org_id>",
* appDefinitionId: "<app_definition_id>",
* functionId: "<function_id>",
* });
* ```
*/
get(params: OptionalDefaults<GetFunctionParams>): Promise<FunctionProps>

/**
* Fetches all functions for the given app
* @param params organization ID, app definition ID to identify the functions
* @returns an object containing an array of Functions
* @throws if the request fails, or the App is not found
* @example
* ```javascript
* const functions = await client.function.getMany({
* organizationId: "<org_id>",
* appDefinitionId: "<app_definition_id>",
* });
* ```
*/
getMany(
params: OptionalDefaults<GetFunctionParams & QueryParams>
): Promise<CollectionProp<FunctionProps>>

/**
* Fetches all functions for the given environment
* @param params space ID, environment ID, app installation ID to identify the functions
* @returns an object containing an array of Functions
* @throws if the request fails, or the Environment is not found
* @example
* ```javascript
* const functions = await client.function.getManyForEnvironment({
* spaceId: "<space_id>",
* environmentId: "<environment_id>",
* appInstallationId: "<app_installation_id>",
* });
* ```
*/
getManyForEnvironment(
params: OptionalDefaults<GetFunctionForEnvParams & QueryParams>
): Promise<CollectionProp<FunctionProps>>
}
2 changes: 2 additions & 0 deletions lib/plain/plain-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ export const createPlainClient = (
update: wrap(wrapParams, 'ConceptScheme', 'update'),
},
function: {
get: wrap(wrapParams, 'Function', 'get'),
getMany: wrap(wrapParams, 'Function', 'getMany'),
getManyForEnvironment: wrap(wrapParams, 'Function', 'getManyForEnvironment')
},
editorInterface: {
get: wrap(wrapParams, 'EditorInterface', 'get'),
Expand Down
Loading