2.1.7 • Published 1 month ago

@zapehr/sdk v2.1.7

Weekly downloads
-
License
MIT
Repository
-
Last release
1 month ago

Version Compatible Node Versions Install Size Minified Size Downloads / Month License

ZapEHR SDK

The ZapEHR SDK is a TypeScript library for interacting with ZapEHR's FHIR and Project APIs.

While you can always make raw HTTP requests to ZapEHR's APIs from any language, this SDK provides several advantages for developers:

  • TypeScript types The SDK provides complete typing for requests and responses across all of ZapEHR's APIs. This gives you helpful autocomplete and build-time type checking.
  • Convenience functions The SDK provides convenience functions for doing common tasks like uploading and downloading files with Z3.

Installation

npm install @zapehr/sdk

Usage

  1. Import the SDK.
  2. Initialize the SDK with a ZapEHR access token. (Learn how to get an access token).
  3. Invoke any of ZapEHR's APIs with a function call.
import zapehr from '@zapehr/sdk'

zapehr.init({
  ZAPEHR_ACCESS_TOKEN: 'your_access_token',
});

// Create a Patient FHIR resource
const patient = await zapehr.fhir.create({
  resourceType: 'Patient',
});

// Upload a zambda
try {
  const zambda = await zapehr.project.zambda.create({ name: 'new zambda', triggerMethod: 'http_open' });
  const fileHandle = await fs.open('./path/to/my/zambda.zip')
  const file = new Blob([await fileHandle.readFile()]);
  await zapehr.project.zambda.uploadFile({ id: createZambda.data.id, file, })
} catch (err) {
  // Handle error thrown by ZapEHR or JS in some way
}

Convenience Functions

Z3

Under the hood, uploading and downloading files with Z3 is a two-step process:

  1. Create a presigned URL to upload or download the file (API Reference).
  2. Upload or download the file using the presigned URL.

The SDK provides convenience functions which combine these steps into a single function call to make it a one-liner:

    await zapehr.project.z3.uploadFile(
      { bucketName: 'your-bucket-name', 'objectPath+': 'path/to/your-filename', file: someFileBlob }
    );

In the example, someFileBlob is a Blob.

    const downloadedBuffer = await zapehr.project.z3.downloadFile(
      { bucketName: 'your-bucket-name', 'objectPath+': 'path/to/your-filename' }
    );

Zambda

Uploading code for your Zambda Functions is very similar to uploading a file with Z3. After creating your .zip archive, use the uploadFile() function to deploy your code.

  const zambdaFile = fs.readFileSync('build/your-zambda-code.zip');
  await zapehr.project.zambda.uploadFile({
    id: yourZambdaId,
    file: new Blob([zambdaFile]),
  });
2.1.7

1 month ago

2.1.4

2 months ago

2.1.3

2 months ago

2.1.6

2 months ago

2.1.5

2 months ago

2.1.2

2 months ago

2.1.1

3 months ago

2.1.0

3 months ago

2.0.7

4 months ago

2.0.6

4 months ago

2.0.5

4 months ago

2.0.4

4 months ago

2.0.3

4 months ago

2.0.2

4 months ago

2.0.1

4 months ago

2.0.0

5 months ago

1.0.17

6 months ago

1.0.16

6 months ago

1.0.9

7 months ago

1.0.8

8 months ago

1.0.7

9 months ago

1.0.11

7 months ago

1.0.10

7 months ago

1.0.15

6 months ago

1.0.14

7 months ago

1.0.13

7 months ago

1.0.12

7 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago