Skip to content

Commit fa455b9

Browse files
n0nickviambot
andauthored
APP-14421 TypeScript SDK support for CreateBinaryDataSignedURL (#690)
Co-authored-by: viambot <[email protected]>
1 parent 1e22fa1 commit fa455b9

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

src/app/data-client.spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import {
2323
CaptureInterval,
2424
ConfigureDatabaseUserRequest,
2525
ConfigureDatabaseUserResponse,
26+
CreateBinaryDataSignedURLRequest,
27+
CreateBinaryDataSignedURLResponse,
2628
CreateIndexRequest,
2729
CreateIndexResponse,
2830
DataRequest,
@@ -554,6 +556,50 @@ describe('DataClient tests', () => {
554556
});
555557
});
556558

559+
describe('createBinaryDataSignedURL tests', () => {
560+
let capReq: CreateBinaryDataSignedURLRequest;
561+
const signedUrl = 'https://example.com/signed-url?token=abc123';
562+
const binaryDataId = 'test-binary-data-id';
563+
564+
beforeEach(() => {
565+
mockTransport = createRouterTransport(({ service }) => {
566+
service(DataService, {
567+
createBinaryDataSignedURL: (req) => {
568+
capReq = req;
569+
return new CreateBinaryDataSignedURLResponse({
570+
signedUrl,
571+
});
572+
},
573+
});
574+
});
575+
});
576+
577+
it('create signed URL for binary data', async () => {
578+
const expectedRequest = new CreateBinaryDataSignedURLRequest({
579+
binaryDataId,
580+
});
581+
582+
const response = await subject().createBinaryDataSignedURL(binaryDataId);
583+
expect(capReq).toStrictEqual(expectedRequest);
584+
expect(response).toEqual(signedUrl);
585+
});
586+
587+
it('create signed URL with expiration minutes', async () => {
588+
const expirationMinutes = 30;
589+
const expectedRequest = new CreateBinaryDataSignedURLRequest({
590+
binaryDataId,
591+
expirationMinutes,
592+
});
593+
594+
const response = await subject().createBinaryDataSignedURL(
595+
binaryDataId,
596+
expirationMinutes
597+
);
598+
expect(capReq).toStrictEqual(expectedRequest);
599+
expect(response).toEqual(signedUrl);
600+
});
601+
});
602+
557603
describe('deleteTabularData tests', () => {
558604
beforeEach(() => {
559605
mockTransport = createRouterTransport(({ service }) => {

src/app/data-client.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,34 @@ export class DataClient {
496496
return resp.data;
497497
}
498498

499+
/**
500+
* Create a signed URL for binary data.
501+
*
502+
* @example
503+
*
504+
* ```ts
505+
* const signedUrl = await dataClient.createBinaryDataSignedURL(
506+
* 'ccb74b53-1235-4328-a4b9-91dff1915a50/x5vur1fmps/YAEzj5I1kTwtYsDdf4a7ctaJpGgKRHmnM9bJNVyblk52UpqmrnMVTITaBKZctKEh'
507+
* );
508+
* ```
509+
*
510+
* For more information, see [Data
511+
* API](https://docs.viam.com/dev/reference/apis/data-client/#createbinarydatasignedurl).
512+
*
513+
* @param binaryDataId The ID of the binary data
514+
* @returns A signed URL string for accessing the binary data
515+
*/
516+
async createBinaryDataSignedURL(
517+
binaryDataId: string,
518+
expirationMinutes?: number
519+
): Promise<string> {
520+
const response = await this.dataClient.createBinaryDataSignedURL({
521+
binaryDataId,
522+
expirationMinutes,
523+
});
524+
return response.signedUrl;
525+
}
526+
499527
/**
500528
* Delete tabular data older than a specified number of days.
501529
*

0 commit comments

Comments
 (0)