@oystehr/sdk 3.0.2 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/client.d.ts +2 -1
- package/dist/cjs/index.cjs +61 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.min.cjs +1 -1
- package/dist/cjs/index.min.cjs.map +1 -1
- package/dist/cjs/resources/classes/z3-ext.d.ts +22 -0
- package/dist/cjs/resources/classes/z3.d.ts +15 -0
- package/dist/esm/client/client.d.ts +2 -1
- package/dist/esm/client/client.js +1 -1
- package/dist/esm/client/client.js.map +1 -1
- package/dist/esm/index.min.js +1 -1
- package/dist/esm/index.min.js.map +1 -1
- package/dist/esm/resources/classes/z3-ext.d.ts +22 -0
- package/dist/esm/resources/classes/z3-ext.js +49 -1
- package/dist/esm/resources/classes/z3-ext.js.map +1 -1
- package/dist/esm/resources/classes/z3.d.ts +15 -0
- package/dist/esm/resources/classes/z3.js +16 -1
- package/dist/esm/resources/classes/z3.js.map +1 -1
- package/package.json +1 -1
- package/src/client/client.ts +2 -2
- package/src/resources/classes/z3-ext.ts +48 -1
- package/src/resources/classes/z3.ts +15 -0
|
@@ -1,10 +1,32 @@
|
|
|
1
1
|
import { SDKResource } from '../../client/client';
|
|
2
|
+
import { Z3GetPresignedUrlParams, Z3GetPresignedUrlResponse } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Uploads a file to the bucket and key. Files should be Blobs.
|
|
5
|
+
*
|
|
6
|
+
* @param params upload file params
|
|
7
|
+
*/
|
|
2
8
|
export declare function uploadFile(this: SDKResource, { bucketName, 'objectPath+': key, file, }: {
|
|
3
9
|
bucketName: string;
|
|
4
10
|
'objectPath+': string;
|
|
5
11
|
file: Blob;
|
|
6
12
|
}): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Downloads an object matching the bucket and key. File content is returned as an ArrayBuffer.
|
|
15
|
+
*
|
|
16
|
+
* @param params download file params
|
|
17
|
+
*/
|
|
7
18
|
export declare function downloadFile(this: SDKResource, { bucketName, 'objectPath+': key, }: {
|
|
8
19
|
bucketName: string;
|
|
9
20
|
'objectPath+': string;
|
|
10
21
|
}): Promise<ArrayBuffer>;
|
|
22
|
+
/**
|
|
23
|
+
* This helper performs a `getPresignedUrl` request for Z3 URLs of the forms
|
|
24
|
+
* `https://projects-api.oystehr.com/v1/z3/<bucket>/<key>` or `z3://<bucket>/<key>`
|
|
25
|
+
* instead of the standard SDK `Z3GetPresignedUrlParams`.
|
|
26
|
+
*
|
|
27
|
+
* @param params url and action
|
|
28
|
+
*/
|
|
29
|
+
export declare function getPresignedUrlForZ3Url(this: SDKResource, params: {
|
|
30
|
+
url: string;
|
|
31
|
+
action: Z3GetPresignedUrlParams['action'];
|
|
32
|
+
}): Promise<Z3GetPresignedUrlResponse>;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { __awaiter } from '../../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { defaultProjectApiUrl } from '../../client/client.js';
|
|
3
|
+
import { OystehrSdkError } from '../../errors/index.js';
|
|
2
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Uploads a file to the bucket and key. Files should be Blobs.
|
|
7
|
+
*
|
|
8
|
+
* @param params upload file params
|
|
9
|
+
*/
|
|
3
10
|
function uploadFile({ bucketName, 'objectPath+': key, file, }) {
|
|
4
11
|
return __awaiter(this, void 0, void 0, function* () {
|
|
5
12
|
const uploadUrl = yield this.request('/z3/{bucketName}/{objectPath+}', 'post')({
|
|
@@ -13,6 +20,11 @@ function uploadFile({ bucketName, 'objectPath+': key, file, }) {
|
|
|
13
20
|
});
|
|
14
21
|
});
|
|
15
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Downloads an object matching the bucket and key. File content is returned as an ArrayBuffer.
|
|
25
|
+
*
|
|
26
|
+
* @param params download file params
|
|
27
|
+
*/
|
|
16
28
|
function downloadFile({ bucketName, 'objectPath+': key, }) {
|
|
17
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
30
|
const uploadUrl = yield this.request('/z3/{bucketName}/{objectPath+}', 'post')({
|
|
@@ -29,6 +41,42 @@ function downloadFile({ bucketName, 'objectPath+': key, }) {
|
|
|
29
41
|
return resp.arrayBuffer();
|
|
30
42
|
});
|
|
31
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* This helper performs a `getPresignedUrl` request for Z3 URLs of the forms
|
|
46
|
+
* `https://projects-api.oystehr.com/v1/z3/<bucket>/<key>` or `z3://<bucket>/<key>`
|
|
47
|
+
* instead of the standard SDK `Z3GetPresignedUrlParams`.
|
|
48
|
+
*
|
|
49
|
+
* @param params url and action
|
|
50
|
+
*/
|
|
51
|
+
function getPresignedUrlForZ3Url(params) {
|
|
52
|
+
var _a;
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
let bucket;
|
|
55
|
+
let key;
|
|
56
|
+
const url = new URL(params.url);
|
|
57
|
+
if (url.protocol === 'z3:') {
|
|
58
|
+
// remove leading forward slash
|
|
59
|
+
const z3PathParts = url.pathname.split('/').slice(1);
|
|
60
|
+
bucket = url.hostname;
|
|
61
|
+
key = z3PathParts.join('/');
|
|
62
|
+
}
|
|
63
|
+
else if (url.href.startsWith((_a = this.config.projectApiUrl) !== null && _a !== void 0 ? _a : defaultProjectApiUrl)) {
|
|
64
|
+
// remove leading `/v1/z3`
|
|
65
|
+
const httpsPathParts = url.pathname.split('/').slice(3);
|
|
66
|
+
bucket = httpsPathParts[0];
|
|
67
|
+
key = httpsPathParts.slice(1).join('/');
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
throw new OystehrSdkError({ message: 'Invalid Z3 URL', code: 400 });
|
|
71
|
+
}
|
|
72
|
+
const requestParams = {
|
|
73
|
+
action: 'upload',
|
|
74
|
+
bucketName: bucket,
|
|
75
|
+
'objectPath+': key,
|
|
76
|
+
};
|
|
77
|
+
return this.request('/z3/{bucketName}/{objectPath+}', 'post')(requestParams);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
32
80
|
|
|
33
|
-
export { downloadFile, uploadFile };
|
|
81
|
+
export { downloadFile, getPresignedUrlForZ3Url, uploadFile };
|
|
34
82
|
//# sourceMappingURL=z3-ext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"z3-ext.js","sources":["../../../../src/resources/classes/z3-ext.ts"],"sourcesContent":["import { SDKResource } from '../../client/client';\n\nexport async function uploadFile(\n this: SDKResource,\n {\n bucketName,\n 'objectPath+': key,\n file,\n }: {\n bucketName: string;\n 'objectPath+': string;\n file: Blob;\n }\n): Promise<void> {\n const uploadUrl = await this.request(\n '/z3/{bucketName}/{objectPath+}',\n 'post'\n )({\n action: 'upload',\n bucketName,\n 'objectPath+': key,\n });\n await fetch(uploadUrl.signedUrl, {\n method: 'PUT',\n body: file,\n });\n}\n\nexport async function downloadFile(\n this: SDKResource,\n {\n bucketName,\n 'objectPath+': key,\n }: {\n bucketName: string;\n 'objectPath+': string;\n }\n): Promise<ArrayBuffer> {\n const uploadUrl = await this.request(\n '/z3/{bucketName}/{objectPath+}',\n 'post'\n )({\n action: 'download',\n bucketName,\n 'objectPath+': key,\n });\n const resp = await fetch(uploadUrl.signedUrl, {\n method: 'GET',\n });\n if (!resp.ok) {\n throw new Error('Failed to download file');\n }\n return resp.arrayBuffer();\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"z3-ext.js","sources":["../../../../src/resources/classes/z3-ext.ts"],"sourcesContent":["import { defaultProjectApiUrl, SDKResource } from '../../client/client';\nimport { OystehrSdkError } from '../../errors';\nimport { Z3GetPresignedUrlParams, Z3GetPresignedUrlResponse } from '../types';\n\n/**\n * Uploads a file to the bucket and key. Files should be Blobs.\n *\n * @param params upload file params\n */\nexport async function uploadFile(\n this: SDKResource,\n {\n bucketName,\n 'objectPath+': key,\n file,\n }: {\n bucketName: string;\n 'objectPath+': string;\n file: Blob;\n }\n): Promise<void> {\n const uploadUrl = await this.request(\n '/z3/{bucketName}/{objectPath+}',\n 'post'\n )({\n action: 'upload',\n bucketName,\n 'objectPath+': key,\n });\n await fetch(uploadUrl.signedUrl, {\n method: 'PUT',\n body: file,\n });\n}\n\n/**\n * Downloads an object matching the bucket and key. File content is returned as an ArrayBuffer.\n *\n * @param params download file params\n */\nexport async function downloadFile(\n this: SDKResource,\n {\n bucketName,\n 'objectPath+': key,\n }: {\n bucketName: string;\n 'objectPath+': string;\n }\n): Promise<ArrayBuffer> {\n const uploadUrl = await this.request(\n '/z3/{bucketName}/{objectPath+}',\n 'post'\n )({\n action: 'download',\n bucketName,\n 'objectPath+': key,\n });\n const resp = await fetch(uploadUrl.signedUrl, {\n method: 'GET',\n });\n if (!resp.ok) {\n throw new Error('Failed to download file');\n }\n return resp.arrayBuffer();\n}\n\n/**\n * This helper performs a `getPresignedUrl` request for Z3 URLs of the forms\n * `https://projects-api.oystehr.com/v1/z3/<bucket>/<key>` or `z3://<bucket>/<key>`\n * instead of the standard SDK `Z3GetPresignedUrlParams`.\n *\n * @param params url and action\n */\nexport async function getPresignedUrlForZ3Url(\n this: SDKResource,\n params: { url: string; action: Z3GetPresignedUrlParams['action'] }\n): Promise<Z3GetPresignedUrlResponse> {\n let bucket: string;\n let key: string;\n const url = new URL(params.url);\n if (url.protocol === 'z3:') {\n // remove leading forward slash\n const z3PathParts = url.pathname.split('/').slice(1);\n bucket = url.hostname;\n key = z3PathParts.join('/');\n } else if (url.href.startsWith(this.config.projectApiUrl ?? defaultProjectApiUrl)) {\n // remove leading `/v1/z3`\n const httpsPathParts = url.pathname.split('/').slice(3);\n bucket = httpsPathParts[0];\n key = httpsPathParts.slice(1).join('/');\n } else {\n throw new OystehrSdkError({ message: 'Invalid Z3 URL', code: 400 });\n }\n const requestParams: Z3GetPresignedUrlParams = {\n action: 'upload',\n bucketName: bucket,\n 'objectPath+': key,\n };\n return this.request('/z3/{bucketName}/{objectPath+}', 'post')(requestParams);\n}\n"],"names":[],"mappings":";;;;AAIA;;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config: OystehrConfig);
|
|
7
|
+
/**
|
|
8
|
+
* Uploads a file to the bucket and key. Files should be Blobs.
|
|
9
|
+
* @param params upload file params
|
|
10
|
+
*/
|
|
7
11
|
uploadFile: typeof ext.uploadFile;
|
|
12
|
+
/**
|
|
13
|
+
* Downloads an object matching the bucket and key. File content is returned as an ArrayBuffer.
|
|
14
|
+
* @param params download file params
|
|
15
|
+
*/
|
|
8
16
|
downloadFile: typeof ext.downloadFile;
|
|
17
|
+
/**
|
|
18
|
+
* This helper performs a `getPresignedUrl` request for Z3 URLs of the forms
|
|
19
|
+
* `https://projects-api.oystehr.com/v1/z3/<bucket>/<key>` * or `z3://<bucket>/<key>`
|
|
20
|
+
* instead of the standard SDK `Z3GetPresignedUrlParams`.
|
|
21
|
+
* @param params url and action
|
|
22
|
+
*/
|
|
23
|
+
getPresignedUrlForZ3Url: typeof ext.getPresignedUrlForZ3Url;
|
|
9
24
|
/**
|
|
10
25
|
* List all Z3 Buckets. [Z3](https://docs.oystehr.com/services/z3/) is Oystehr's built-in and fully integrated solution for file storage.
|
|
11
26
|
*
|
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
import { SDKResource } from '../../client/client.js';
|
|
2
|
-
import { uploadFile, downloadFile } from './z3-ext.js';
|
|
2
|
+
import { uploadFile, downloadFile, getPresignedUrlForZ3Url } from './z3-ext.js';
|
|
3
3
|
|
|
4
4
|
// AUTOGENERATED -- DO NOT EDIT
|
|
5
5
|
class Z3 extends SDKResource {
|
|
6
6
|
constructor(config) {
|
|
7
7
|
super(config);
|
|
8
|
+
/**
|
|
9
|
+
* Uploads a file to the bucket and key. Files should be Blobs.
|
|
10
|
+
* @param params upload file params
|
|
11
|
+
*/
|
|
8
12
|
this.uploadFile = uploadFile;
|
|
13
|
+
/**
|
|
14
|
+
* Downloads an object matching the bucket and key. File content is returned as an ArrayBuffer.
|
|
15
|
+
* @param params download file params
|
|
16
|
+
*/
|
|
9
17
|
this.downloadFile = downloadFile;
|
|
18
|
+
/**
|
|
19
|
+
* This helper performs a `getPresignedUrl` request for Z3 URLs of the forms
|
|
20
|
+
* `https://projects-api.oystehr.com/v1/z3/<bucket>/<key>` * or `z3://<bucket>/<key>`
|
|
21
|
+
* instead of the standard SDK `Z3GetPresignedUrlParams`.
|
|
22
|
+
* @param params url and action
|
|
23
|
+
*/
|
|
24
|
+
this.getPresignedUrlForZ3Url = getPresignedUrlForZ3Url;
|
|
10
25
|
/**
|
|
11
26
|
* List all Z3 Buckets. [Z3](https://docs.oystehr.com/services/z3/) is Oystehr's built-in and fully integrated solution for file storage.
|
|
12
27
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"z3.js","sources":["../../../../src/resources/classes/z3.ts"],"sourcesContent":["// AUTOGENERATED -- DO NOT EDIT\n\nimport {\n OystehrClientRequest,\n Z3CreateBucketParams,\n Z3CreateBucketResponse,\n Z3DeleteBucketParams,\n Z3DeleteObjectParams,\n Z3GetPresignedUrlParams,\n Z3GetPresignedUrlResponse,\n Z3ListBucketsResponse,\n Z3ListObjectsParams,\n Z3ListObjectsResponse,\n} from '../..';\nimport { SDKResource } from '../../client/client';\nimport { OystehrConfig } from '../../config';\nimport * as ext from './z3-ext';\n\nexport class Z3 extends SDKResource {\n constructor(config: OystehrConfig) {\n super(config);\n }\n uploadFile = ext.uploadFile;\n downloadFile = ext.downloadFile;\n /**\n * List all Z3 Buckets. [Z3](https://docs.oystehr.com/services/z3/) is Oystehr's built-in and fully integrated solution for file storage.\n *\n * Access Policy Action: `Z3:ListBuckets`\n * Access Policy Resource: `Z3:BucketName`\n */\n listBuckets = (request?: OystehrClientRequest): Promise<Z3ListBucketsResponse> => this.request('/z3', 'get')(request);\n /**\n * Create a Z3 Bucket with the provided name. [Z3](https://docs.oystehr.com/services/z3/) is Oystehr's built-in and fully integrated solution for file storage.\n *\n * Access Policy Action: `Z3:CreateBucket`\n * Access Policy Resource: `Z3:BucketName`\n */\n createBucket = (params: Z3CreateBucketParams, request?: OystehrClientRequest): Promise<Z3CreateBucketResponse> =>\n this.request('/z3/{bucketName}', 'put')(params, request);\n /**\n * Delete the Z3 Bucket with the provided name. [Z3](https://docs.oystehr.com/services/z3/) is Oystehr's built-in and fully integrated solution for file storage.\n *\n * Access Policy Action: `Z3:DeleteBucket`\n * Access Policy Resource: `Z3:BucketName`\n */\n deleteBucket = (params: Z3DeleteBucketParams, request?: OystehrClientRequest): Promise<void> =>\n this.request('/z3/{bucketName}', 'delete')(params, request);\n /**\n * List all Z3 Objects at the provided path in the Bucket with the provided name [Z3](https://docs.oystehr.com/services/z3/) is Oystehr's built-in and fully integrated solution for file storage.\n *\n * Access Policy Action: `Z3:ListObjects`\n * Access Policy Resource: `Z3:BucketName:ObjectPath`\n */\n listObjects = (params: Z3ListObjectsParams, request?: OystehrClientRequest): Promise<Z3ListObjectsResponse> =>\n this.request('/z3/{bucketName}/{objectPath+}', 'get')(params, request);\n /**\n * Get a link for downloading or uploading a Z3 Object to the provided path in the Bucket with the provided name. [Z3](https://docs.oystehr.com/services/z3/) is Oystehr's built-in and fully integrated solution for file storage.\n *\n * Access Policy Action: `Z3:PutObject` or `Z3:GetObject`\n * Access Policy Resource: `Z3:BucketName:ObjectPath`\n */\n getPresignedUrl = (\n params: Z3GetPresignedUrlParams,\n request?: OystehrClientRequest\n ): Promise<Z3GetPresignedUrlResponse> => this.request('/z3/{bucketName}/{objectPath+}', 'post')(params, request);\n /**\n * Delete the Z3 Object at the provided path in the Bucket with the provided name. [Z3](https://docs.oystehr.com/services/z3/) is Oystehr's built-in and fully integrated solution for file storage.\n *\n * Access Policy Action: `Z3:DeleteObject`\n * Access Policy Resource: `Z3:BucketName:ObjectPath`\n */\n deleteObject = (params: Z3DeleteObjectParams, request?: OystehrClientRequest): Promise<void> =>\n this.request('/z3/{bucketName}/{objectPath+}', 'delete')(params, request);\n}\n"],"names":["ext.uploadFile","ext.downloadFile"],"mappings":";;;AAAA;AAkBM,MAAO,EAAG,SAAQ,WAAW,CAAA;AACjC,IA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NOT EDIT\n\nimport {\n OystehrClientRequest,\n Z3CreateBucketParams,\n Z3CreateBucketResponse,\n Z3DeleteBucketParams,\n Z3DeleteObjectParams,\n Z3GetPresignedUrlParams,\n Z3GetPresignedUrlResponse,\n Z3ListBucketsResponse,\n Z3ListObjectsParams,\n Z3ListObjectsResponse,\n} from '../..';\nimport { SDKResource } from '../../client/client';\nimport { OystehrConfig } from '../../config';\nimport * as ext from './z3-ext';\n\nexport class Z3 extends SDKResource {\n constructor(config: OystehrConfig) {\n super(config);\n }\n /**\n * Uploads a file to the bucket and key. Files should be Blobs.\n * @param params upload file params\n */\n uploadFile = ext.uploadFile;\n /**\n * Downloads an object matching the bucket and key. File content is returned as an ArrayBuffer.\n * @param params download file params\n */\n downloadFile = ext.downloadFile;\n /**\n * This helper performs a `getPresignedUrl` request for Z3 URLs of the forms\n * `https://projects-api.oystehr.com/v1/z3/<bucket>/<key>` * or `z3://<bucket>/<key>`\n * instead of the standard SDK `Z3GetPresignedUrlParams`.\n * @param params url and action\n */\n getPresignedUrlForZ3Url = ext.getPresignedUrlForZ3Url;\n /**\n * List all Z3 Buckets. [Z3](https://docs.oystehr.com/services/z3/) is Oystehr's built-in and fully integrated solution for file storage.\n *\n * Access Policy Action: `Z3:ListBuckets`\n * Access Policy Resource: `Z3:BucketName`\n */\n listBuckets = (request?: OystehrClientRequest): Promise<Z3ListBucketsResponse> => this.request('/z3', 'get')(request);\n /**\n * Create a Z3 Bucket with the provided name. [Z3](https://docs.oystehr.com/services/z3/) is Oystehr's built-in and fully integrated solution for file storage.\n *\n * Access Policy Action: `Z3:CreateBucket`\n * Access Policy Resource: `Z3:BucketName`\n */\n createBucket = (params: Z3CreateBucketParams, request?: OystehrClientRequest): Promise<Z3CreateBucketResponse> =>\n this.request('/z3/{bucketName}', 'put')(params, request);\n /**\n * Delete the Z3 Bucket with the provided name. [Z3](https://docs.oystehr.com/services/z3/) is Oystehr's built-in and fully integrated solution for file storage.\n *\n * Access Policy Action: `Z3:DeleteBucket`\n * Access Policy Resource: `Z3:BucketName`\n */\n deleteBucket = (params: Z3DeleteBucketParams, request?: OystehrClientRequest): Promise<void> =>\n this.request('/z3/{bucketName}', 'delete')(params, request);\n /**\n * List all Z3 Objects at the provided path in the Bucket with the provided name [Z3](https://docs.oystehr.com/services/z3/) is Oystehr's built-in and fully integrated solution for file storage.\n *\n * Access Policy Action: `Z3:ListObjects`\n * Access Policy Resource: `Z3:BucketName:ObjectPath`\n */\n listObjects = (params: Z3ListObjectsParams, request?: OystehrClientRequest): Promise<Z3ListObjectsResponse> =>\n this.request('/z3/{bucketName}/{objectPath+}', 'get')(params, request);\n /**\n * Get a link for downloading or uploading a Z3 Object to the provided path in the Bucket with the provided name. [Z3](https://docs.oystehr.com/services/z3/) is Oystehr's built-in and fully integrated solution for file storage.\n *\n * Access Policy Action: `Z3:PutObject` or `Z3:GetObject`\n * Access Policy Resource: `Z3:BucketName:ObjectPath`\n */\n getPresignedUrl = (\n params: Z3GetPresignedUrlParams,\n request?: OystehrClientRequest\n ): Promise<Z3GetPresignedUrlResponse> => this.request('/z3/{bucketName}/{objectPath+}', 'post')(params, request);\n /**\n * Delete the Z3 Object at the provided path in the Bucket with the provided name. [Z3](https://docs.oystehr.com/services/z3/) is Oystehr's built-in and fully integrated solution for file storage.\n *\n * Access Policy Action: `Z3:DeleteObject`\n * Access Policy Resource: `Z3:BucketName:ObjectPath`\n */\n deleteObject = (params: Z3DeleteObjectParams, request?: OystehrClientRequest): Promise<void> =>\n this.request('/z3/{bucketName}/{objectPath+}', 'delete')(params, request);\n}\n"],"names":["ext.uploadFile","ext.downloadFile","ext.getPresignedUrlForZ3Url"],"mappings":";;;AAAA;AAkBM,MAAO,EAAG,SAAQ,WAAW,CAAA;AACjC,IAAA,WAAA,CAAY,MAAqB,EAAA;QAC/B,KAAK,CAAC,MAAM,CAAC,CAAC;AAEhB;;;AAGG;AACH,QAAA,IAAA,CAAA,UAAU,GAAGA,UAAc,CAAC;AAC5B;;;AAGG;A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undle, FhirResource, OperationOutcome } from '../resources/types';
|
|
5
5
|
|
|
6
6
|
type HttpMethod = 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace';
|
|
7
|
-
const defaultProjectApiUrl = 'https://project-api.zapehr.com/v1';
|
|
7
|
+
export const defaultProjectApiUrl = 'https://project-api.zapehr.com/v1';
|
|
8
8
|
const defaultFhirApiUrl = 'https://fhir-api.zapehr.com';
|
|
9
9
|
const STATUS_CODES_TO_RETRY = [408, 429, 500, 502, 503, 504];
|
|
10
10
|
const ERROR_CODES_TO_RETRY = [
|
|
@@ -50,7 +50,7 @@ type FhirData<T extends FhirResource> = T | T[] | FhirBundle<T>;
|
|
|
50
50
|
export type FhirFetcherResponse<T extends FhirData<FhirResource> = any> = T;
|
|
51
51
|
|
|
52
52
|
export class SDKResource {
|
|
53
|
-
|
|
53
|
+
protected readonly config: OystehrConfig;
|
|
54
54
|
constructor(config: OystehrConfig) {
|
|
55
55
|
this.config = config;
|
|
56
56
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import { SDKResource } from '../../client/client';
|
|
1
|
+
import { defaultProjectApiUrl, SDKResource } from '../../client/client';
|
|
2
|
+
import { OystehrSdkError } from '../../errors';
|
|
3
|
+
import { Z3GetPresignedUrlParams, Z3GetPresignedUrlResponse } from '../types';
|
|
2
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Uploads a file to the bucket and key. Files should be Blobs.
|
|
7
|
+
*
|
|
8
|
+
* @param params upload file params
|
|
9
|
+
*/
|
|
3
10
|
export async function uploadFile(
|
|
4
11
|
this: SDKResource,
|
|
5
12
|
{
|
|
@@ -26,6 +33,11 @@ export async function uploadFile(
|
|
|
26
33
|
});
|
|
27
34
|
}
|
|
28
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Downloads an object matching the bucket and key. File content is returned as an ArrayBuffer.
|
|
38
|
+
*
|
|
39
|
+
* @param params download file params
|
|
40
|
+
*/
|
|
29
41
|
export async function downloadFile(
|
|
30
42
|
this: SDKResource,
|
|
31
43
|
{
|
|
@@ -52,3 +64,38 @@ export async function downloadFile(
|
|
|
52
64
|
}
|
|
53
65
|
return resp.arrayBuffer();
|
|
54
66
|
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* This helper performs a `getPresignedUrl` request for Z3 URLs of the forms
|
|
70
|
+
* `https://projects-api.oystehr.com/v1/z3/<bucket>/<key>` or `z3://<bucket>/<key>`
|
|
71
|
+
* instead of the standard SDK `Z3GetPresignedUrlParams`.
|
|
72
|
+
*
|
|
73
|
+
* @param params url and action
|
|
74
|
+
*/
|
|
75
|
+
export async function getPresignedUrlForZ3Url(
|
|
76
|
+
this: SDKResource,
|
|
77
|
+
params: { url: string; action: Z3GetPresignedUrlParams['action'] }
|
|
78
|
+
): Promise<Z3GetPresignedUrlResponse> {
|
|
79
|
+
let bucket: string;
|
|
80
|
+
let key: string;
|
|
81
|
+
const url = new URL(params.url);
|
|
82
|
+
if (url.protocol === 'z3:') {
|
|
83
|
+
// remove leading forward slash
|
|
84
|
+
const z3PathParts = url.pathname.split('/').slice(1);
|
|
85
|
+
bucket = url.hostname;
|
|
86
|
+
key = z3PathParts.join('/');
|
|
87
|
+
} else if (url.href.startsWith(this.config.projectApiUrl ?? defaultProjectApiUrl)) {
|
|
88
|
+
// remove leading `/v1/z3`
|
|
89
|
+
const httpsPathParts = url.pathname.split('/').slice(3);
|
|
90
|
+
bucket = httpsPathParts[0];
|
|
91
|
+
key = httpsPathParts.slice(1).join('/');
|
|
92
|
+
} else {
|
|
93
|
+
throw new OystehrSdkError({ message: 'Invalid Z3 URL', code: 400 });
|
|
94
|
+
}
|
|
95
|
+
const requestParams: Z3GetPresignedUrlParams = {
|
|
96
|
+
action: 'upload',
|
|
97
|
+
bucketName: bucket,
|
|
98
|
+
'objectPath+': key,
|
|
99
|
+
};
|
|
100
|
+
return this.request('/z3/{bucketName}/{objectPath+}', 'post')(requestParams);
|
|
101
|
+
}
|
|
@@ -20,8 +20,23 @@ export class Z3 extends SDKResource {
|
|
|
20
20
|
constructor(config: OystehrConfig) {
|
|
21
21
|
super(config);
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Uploads a file to the bucket and key. Files should be Blobs.
|
|
25
|
+
* @param params upload file params
|
|
26
|
+
*/
|
|
23
27
|
uploadFile = ext.uploadFile;
|
|
28
|
+
/**
|
|
29
|
+
* Downloads an object matching the bucket and key. File content is returned as an ArrayBuffer.
|
|
30
|
+
* @param params download file params
|
|
31
|
+
*/
|
|
24
32
|
downloadFile = ext.downloadFile;
|
|
33
|
+
/**
|
|
34
|
+
* This helper performs a `getPresignedUrl` request for Z3 URLs of the forms
|
|
35
|
+
* `https://projects-api.oystehr.com/v1/z3/<bucket>/<key>` * or `z3://<bucket>/<key>`
|
|
36
|
+
* instead of the standard SDK `Z3GetPresignedUrlParams`.
|
|
37
|
+
* @param params url and action
|
|
38
|
+
*/
|
|
39
|
+
getPresignedUrlForZ3Url = ext.getPresignedUrlForZ3Url;
|
|
25
40
|
/**
|
|
26
41
|
* List all Z3 Buckets. [Z3](https://docs.oystehr.com/services/z3/) is Oystehr's built-in and fully integrated solution for file storage.
|
|
27
42
|
*
|