@awell-health/awell-sdk
Advanced tools
Comparing version 0.1.8 to 0.1.9
@@ -0,1 +1,4 @@ | ||
export * from './types'; | ||
export * from './genql/generated/schema'; | ||
export * from './webhooks/types'; | ||
export { AwellSdk } from './AwellSdk'; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AwellSdk = void 0; | ||
__exportStar(require("./types"), exports); | ||
__exportStar(require("./genql/generated/schema"), exports); | ||
__exportStar(require("./webhooks/types"), exports); | ||
var AwellSdk_1 = require("./AwellSdk"); | ||
Object.defineProperty(exports, "AwellSdk", { enumerable: true, get: function () { return AwellSdk_1.AwellSdk; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -1,3 +0,1 @@ | ||
export * from './genql/generated/schema'; | ||
export * from './webhooks/types'; | ||
export type Environment = 'development' | 'staging' | 'sandbox' | 'production-eu' | 'production-us' | 'production-uk'; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./genql/generated/schema"), exports); | ||
__exportStar(require("./webhooks/types"), exports); | ||
//# sourceMappingURL=types.js.map |
@@ -13,1 +13,15 @@ export declare enum WebhookEvent { | ||
} | ||
export type WebhookPayload = { | ||
event_type: string; | ||
date?: string; | ||
complete_date?: string; | ||
start_date?: string; | ||
activity_id?: string; | ||
activity?: any; | ||
session?: any; | ||
pathway?: any; | ||
data_point?: any; | ||
reminder?: any; | ||
form?: any; | ||
response?: any; | ||
}; |
{ | ||
"name": "@awell-health/awell-sdk", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"packageManager": "yarn@4.2.1", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
# Awell SDK | ||
The Awell SDK provides convenient access to Awell's APIs from applications written in server-side JavaScript. The SDK also exports all of our GraphQL types. | ||
The Awell SDK provides convenient access to Awell's APIs and webhooks from applications written in server-side JavaScript. The SDK also exports all of our GraphQL types. | ||
## Powered by GenQL | ||
The SDK is built using [GenQL](https://genql.dev/), making it easier to call Awell's API if you're using a JavaScript stack. The SDK translates JavaScript code into GraphQL queries, providing auto-completion and validation for your queries. | ||
## Installation | ||
@@ -21,3 +17,3 @@ | ||
Learn more about GenQL and its syntax [here](https://genql.dev/docs). | ||
Learn more about the syntax of the SDK [here](https://genql.dev/docs). | ||
@@ -51,3 +47,2 @@ Remember to **always call the SDK on the server** to keep your API key secure. | ||
### Types | ||
@@ -63,4 +58,60 @@ | ||
### Webhooks | ||
```javascript | ||
import { | ||
AwellSdk, | ||
type WebhookEvent, | ||
type WebhookBodyPayload | ||
} from '@awell-health/awell-sdk' | ||
const PUBLIC_KEY = 'your_public_key' // Available in Awell Studio | ||
app.post( | ||
'/awell-webhook-listener', | ||
express.json({ type: 'application/json' }), | ||
(request, response) => { | ||
// Needed if you want to verify the incoming webhook | ||
const signature = req.headers['x-awell-signature'] as string; | ||
const requestBody = request.body as WebhookPayload | ||
const sdk = new AwellSdk({ | ||
environment: 'production-eu', | ||
apiKey: 'YOUR_API_KEY', | ||
}) | ||
/** | ||
* Verify that the incoming webhook has been sent | ||
* by Awell and has not been tampered with | ||
*/ | ||
const isValid = sdk.webhooks.verify( | ||
requestBody, | ||
signature, | ||
PUBLIC_KEY, | ||
) | ||
// If webhook you received is legitimate, you can process it | ||
if (isValid) { | ||
const { event } = requestBody | ||
// Handle the event | ||
switch (event.event_type) { | ||
case WebhookEvent.PATHWAY_STARTED: { | ||
const pathway = event?.pathway | ||
console.log(pathway) | ||
// Your code | ||
break | ||
} | ||
default: | ||
console.log(`Unhandled event type ${event.event_type}`) | ||
} | ||
} | ||
// Return a response to acknowledge receipt of the event | ||
response.json({ received: true }) | ||
}, | ||
) | ||
``` | ||
## Configuration | ||
@@ -78,7 +129,7 @@ | ||
| Option | Required | Description | | ||
|-------------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| environment | No* | The Awell environment to use for the SDK. The SDK will automatically target the correct endpoint for the environment you specified. Following options are allowed: `development` \| `staging` \| `sandbox` \| `production-eu` \| `production-us` \| `production-uk`| | ||
| apiUrl | No* | The API URL. Takes presedence over the "environment" when both are specified. | | ||
| apiKey | Yes | The API key to use for authentication. | | ||
| Option | Required | Description | | ||
| ----------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| environment | No\* | The Awell environment to use for the SDK. The SDK will automatically target the correct endpoint for the environment you specified. Following options are allowed: `development` \| `staging` \| `sandbox` \| `production-eu` \| `production-us` \| `production-uk` | | ||
| apiUrl | No\* | The API URL. Takes presedence over the "environment" when both are specified. | | ||
| apiKey | Yes | The API key to use for authentication. | | ||
@@ -85,0 +136,0 @@ \* The SDK will throw an error if neither environment nor apiUrl is provided. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
544835
13083
167