@cord-sdk/server
Advanced tools
Comparing version 1.36.2-canary.1 to 1.36.2-canary.2
@@ -111,2 +111,22 @@ 'use strict'; | ||
} | ||
/** | ||
* Takes a request payload, and returns a typed object for handling | ||
* Cord webhook notifications. | ||
* @param requestPayload Request payload from a webhook request. Should have | ||
* a similar structure to express style request object. | ||
* @returns A typed object to support handling webhook events. See: | ||
* https://docs.cord.com/reference/events-webhook | ||
*/ | ||
function parseEventPayload(requestPayload) { | ||
switch (requestPayload.body.type) { | ||
case 'thread-message-added': | ||
return requestPayload.body; | ||
case 'notification-created': | ||
return requestPayload.body; | ||
case 'url-verification': | ||
return requestPayload.body; | ||
default: | ||
throw 'unknown webhook request type.'; | ||
} | ||
} | ||
@@ -117,4 +137,5 @@ exports.getApplicationManagementAuthToken = getApplicationManagementAuthToken; | ||
exports.getServerAuthToken = getServerAuthToken; | ||
exports.parseEventPayload = parseEventPayload; | ||
exports.tryValidateWebhookSignature = tryValidateWebhookSignature; | ||
exports.validateWebhookSignature = validateWebhookSignature; | ||
//# sourceMappingURL=index.js.map |
@@ -87,4 +87,24 @@ import { createHmac } from 'crypto'; | ||
} | ||
/** | ||
* Takes a request payload, and returns a typed object for handling | ||
* Cord webhook notifications. | ||
* @param requestPayload Request payload from a webhook request. Should have | ||
* a similar structure to express style request object. | ||
* @returns A typed object to support handling webhook events. See: | ||
* https://docs.cord.com/reference/events-webhook | ||
*/ | ||
function parseEventPayload(requestPayload) { | ||
switch (requestPayload.body.type) { | ||
case 'thread-message-added': | ||
return requestPayload.body; | ||
case 'notification-created': | ||
return requestPayload.body; | ||
case 'url-verification': | ||
return requestPayload.body; | ||
default: | ||
throw 'unknown webhook request type.'; | ||
} | ||
} | ||
export { getApplicationManagementAuthToken, getClientAuthToken, getProjectManagementAuthToken, getServerAuthToken, tryValidateWebhookSignature, validateWebhookSignature }; | ||
export { getApplicationManagementAuthToken, getClientAuthToken, getProjectManagementAuthToken, getServerAuthToken, parseEventPayload, tryValidateWebhookSignature, validateWebhookSignature }; | ||
//# sourceMappingURL=index.js.map |
import * as jwt from 'jsonwebtoken'; | ||
import type { ClientAuthTokenData } from '@cord-sdk/types'; | ||
import type { ClientAuthTokenData, ThreadMessageAddedWebhookPayload, NotificationCreatedWebhookPayload, URLVerificationWebhookPayload } from '@cord-sdk/types'; | ||
export type { ClientAuthTokenData }; | ||
@@ -13,5 +13,8 @@ export type CommonAuthTokenOptions = { | ||
export type GetApplicationManagementAuthTokenOptions = CommonAuthTokenOptions; | ||
export type WebhookPayload = ThreadMessageAddedWebhookPayload | NotificationCreatedWebhookPayload | URLVerificationWebhookPayload; | ||
export type WebhookRequest = { | ||
header(name: string): string; | ||
body: string; | ||
body: { | ||
type: string; | ||
}; | ||
}; | ||
@@ -50,1 +53,10 @@ export declare function getClientAuthToken(project_id: string, project_secret: string, payload: Omit<ClientAuthTokenData, 'app_id' | 'project_id'>, options?: GetClientAuthTokenOptions): string; | ||
export declare function tryValidateWebhookSignature(requestPayload: WebhookRequest, clientSecret: string): boolean; | ||
/** | ||
* Takes a request payload, and returns a typed object for handling | ||
* Cord webhook notifications. | ||
* @param requestPayload Request payload from a webhook request. Should have | ||
* a similar structure to express style request object. | ||
* @returns A typed object to support handling webhook events. See: | ||
* https://docs.cord.com/reference/events-webhook | ||
*/ | ||
export declare function parseEventPayload(requestPayload: WebhookRequest): WebhookPayload; |
{ | ||
"name": "@cord-sdk/server", | ||
"description": "Server-side portion of the Cord SDK", | ||
"version": "1.36.2-canary.1", | ||
"version": "1.36.2-canary.2", | ||
"homepage": "https://docs.cord.com/", | ||
@@ -25,3 +25,3 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@cord-sdk/types": "1.36.2-canary.1", | ||
"@cord-sdk/types": "1.36.2-canary.2", | ||
"@types/jsonwebtoken": "^8.5.9", | ||
@@ -28,0 +28,0 @@ "typescript": "~5.1.6" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22284
300