Skip to content

Commit

Permalink
feat: Add new App Installation Parameter value type 'Secret' [EXT-483…
Browse files Browse the repository at this point in the history
…6] (#2286)
  • Loading branch information
jjolton-contentful committed May 22, 2024
1 parent b86267f commit c14280f
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/entities/app-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { wrapCollection } from '../common-utils'
import createAppDefinitionApi, { ContentfulAppDefinitionAPI } from '../create-app-definition-api'
import { SetOptional, Except } from 'type-fest'
import { FieldType } from './field-type'
import { ParameterDefinition } from './widget-parameters'
import { InstallationParameterType, ParameterDefinition } from './widget-parameters'
import { AppInstallationProps } from './app-installation'
import { EnvironmentProps } from './environment'

Expand Down Expand Up @@ -62,7 +62,7 @@ export type AppDefinitionProps = {
*/
parameters?: {
instance?: ParameterDefinition[]
installation?: ParameterDefinition[]
installation?: ParameterDefinition<InstallationParameterType>[]
}
}

Expand Down
8 changes: 6 additions & 2 deletions lib/entities/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import copy from 'fast-copy'
import { freezeSys, toPlainObject } from 'contentful-sdk-core'
import enhanceWithMethods from '../enhance-with-methods'
import { FieldType } from './field-type'
import { DefinedParameters, ParameterDefinition } from './widget-parameters'
import {
DefinedParameters,
InstallationParameterType,
ParameterDefinition,
} from './widget-parameters'
import { wrapCollection } from '../common-utils'
import { DefaultElements, BasicMetaSysProps, SysLink, MakeRequest } from '../common-types'
import { SetRequired, RequireExactlyOne } from 'type-fest'
Expand Down Expand Up @@ -37,7 +41,7 @@ export type ExtensionProps = {
*/
parameters?: {
instance?: ParameterDefinition[]
installation?: ParameterDefinition[]
installation?: ParameterDefinition<InstallationParameterType>[]
}
/**
* Controls the location of the extension. If true it will be rendered on the sidebar instead of replacing the field's editing control
Expand Down
5 changes: 3 additions & 2 deletions lib/entities/widget-parameters.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
type ParameterType = 'Boolean' | 'Symbol' | 'Number' | 'Enum'
export type InstallationParameterType = ParameterType | 'Secret'
type ParameterOption = string | { [key: string]: string }

export interface ParameterDefinition {
export interface ParameterDefinition<T = ParameterType> {
name: string
id: string
description?: string
type: ParameterType
type: T
required?: boolean
default?: boolean | string | number
options?: ParameterOption[]
Expand Down
1 change: 1 addition & 0 deletions lib/export-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export type {
DefinedParameters,
FreeFormParameters,
ParameterDefinition,
InstallationParameterType,
} from './entities/widget-parameters'
export type {
CreateWorkflowProps,
Expand Down
28 changes: 28 additions & 0 deletions test/integration/app-definition-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,34 @@ describe('AppDefinition api', function () {
expect(appDefinition.name).equals('Test App', 'name')
})

test('createAppDefinition with secret installation param', async () => {
const appDefinition = await organization.createAppDefinition({
name: 'Test App',
src: 'http://localhost:3000',
locations: [
{
location: 'app-config',
},
],
parameters: {
installation: [
{
name: 'my-secret-param',
id: 'secret',
type: 'Secret',
},
],
},
})

expect(appDefinition.sys.type).equals('AppDefinition', 'type')
expect(appDefinition.name).equals('Test App', 'name')
expect(appDefinition.parameters.installation[0].id).equals(
'secret',
'installation parameter id'
)
})

test('getAppDefintion', async () => {
const appDefinition = await organization.createAppDefinition({
name: 'Test App',
Expand Down
16 changes: 16 additions & 0 deletions test/unit/mocks/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,22 @@ const appDefinitionMock = {
fieldTypes: [{ type: 'Symbol' }],
},
],
parameters: {
instance: [
{
name: 'my-bool-param',
id: 'param',
type: 'Boolean',
},
],
installation: [
{
name: 'my-secret-param',
id: 'param',
type: 'Secret',
},
],
},
}

const appUploadMock = {
Expand Down

0 comments on commit c14280f

Please sign in to comment.