Skip to content

Commit

Permalink
feat: add webhook signing secrets to legacy client interface
Browse files Browse the repository at this point in the history
  • Loading branch information
t-col committed Nov 2, 2023
1 parent 1ecd72b commit 3f8dae8
Showing 1 changed file with 73 additions and 1 deletion.
74 changes: 73 additions & 1 deletion lib/create-space-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ScheduledActionProps, ScheduledActionQueryOptions } from './entities/sc
import { SpaceProps } from './entities/space'
import { CreateSpaceMembershipProps } from './entities/space-membership'
import { CreateTeamSpaceMembershipProps } from './entities/team-space-membership'
import { CreateWebhooksProps } from './entities/webhook'
import { CreateWebhooksProps, UpsertWebhookSigningSecretPayload } from './entities/webhook'

/**
* @private
Expand Down Expand Up @@ -266,6 +266,31 @@ export default function createSpaceApi(makeRequest: MakeRequest) {
}).then((data) => wrapWebhookCollection(makeRequest, data))
},

/**
* Fetch a webhook signing secret
* @returns Promise for the redacted webhook signing secret in this space
* @example ```javascript
* const contentful = require('contentful-management')
*
* const client = contentful.createClient({
* accessToken: '<content_management_api_key>'
* })
*
* client.getSpace('<space_id>')
* .then((space) => space.getWebhookSigningSecret())
* .then((response) => console.log(response.redactedValue))
* .catch(console.error)
* ```
*/
getWebhookSigningSecret: function getSigningSecret() {
const raw = this.toPlainObject() as SpaceProps
return makeRequest({
entityType: 'Webhook',
action: 'getSigningSecret',
params: { spaceId: raw.sys.id },
})
},

/**
* Creates a Webhook
* @param data - Object representation of the Webhook to be created
Expand Down Expand Up @@ -330,6 +355,53 @@ export default function createSpaceApi(makeRequest: MakeRequest) {
payload: data,
}).then((data) => wrapWebhook(makeRequest, data))
},

/**
* Create or update the webhook signing secret for this space
* @param data 64 character string that will be used to sign the webhook calls
* @returns Promise for the redacted webhook signing secret that was created or updated
* @example ```javascript
* const contentful = require('contentful-management')
* const crypto = require('crypto')
*
* const client = contentful.createClient({
* .then((space) => space.upsertWebhookSigningSecret({
* value: crypto.randomBytes(32).toString('hex')
* })
* .then((response) => console.log(response.redactedValue))
* .catch(console.error)
* ```
*/
upsertWebhookSigningSecret: function getSigningSecret(data: UpsertWebhookSigningSecretPayload) {
const raw = this.toPlainObject() as SpaceProps
return makeRequest({
entityType: 'Webhook',
action: 'upsertSigningSecret',
params: { spaceId: raw.sys.id },
payload: data,
})
},

/**
* Delete the webhook signing secret for this space
* @returns Promise<void>
* @example ```javascript
* const contentful = require('contentful-management')
*
* const client = contentful.createClient({
* .then((space) => space.deleteWebhookSigningSecret()
* .then((response) => console.log(response.redactedValue))
* .catch(console.error)
* ```
*/
deleteWebhookSigningSecret: function getSigningSecret() {
const raw = this.toPlainObject() as SpaceProps
return makeRequest({
entityType: 'Webhook',
action: 'deleteSigningSecret',
params: { spaceId: raw.sys.id },
})
},
/**
* Gets a Role
* @param id - Role ID
Expand Down

0 comments on commit 3f8dae8

Please sign in to comment.