Skip to content

Commit 808eb9f

Browse files
andy-chhuonfatbattk
andcommitted
20644: Implement Camera API
Co-authored-by: Han T. <[email protected]>
1 parent e362d1f commit 808eb9f

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

.changeset/slimy-foxes-hide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/ui-extensions': minor
3+
---
4+
5+
Add Camera API types

packages/ui-extensions/src/surfaces/point-of-sale/api.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ export type {ActionApi, ActionApiContent} from './api/action-api/action-api';
1414
export type {StandardApi} from './api/standard/standard-api';
1515
export type {ActionTargetApi} from './api/action-target-api/action-target-api';
1616

17+
export type {
18+
CameraApi,
19+
CameraApiContent,
20+
CameraMediaOptions,
21+
CameraMediaResponse,
22+
} from './api/camera-api/camera-api';
23+
1724
export type {
1825
ConnectivityStateSeverity,
1926
ConnectivityState,
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {ScannerApi} from '../scanner-api/scanner-api';
22
import {StandardApi} from '../standard/standard-api';
3+
import {CameraApi} from '../camera-api/camera-api';
34

45
export type ActionTargetApi<T> = {[key: string]: any} & {
56
extensionPoint: T;
67
} & StandardApi<T> &
7-
ScannerApi;
8+
ScannerApi &
9+
CameraApi;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
export interface CameraMediaOptions {
2+
/**
3+
* The camera that will be active when the camera interface first opens.
4+
* - `'user'`: The front-facing camera
5+
* - `'environment'`: The rear-facing camera
6+
* @defaultValue 'environment'
7+
*/
8+
facingMode?: 'user' | 'environment';
9+
/**
10+
* The maximum width (0 to 1080) of the image in pixels. Resizes the image to this width if it is larger.
11+
* @defaultValue 1080
12+
*/
13+
maxWidth?: number;
14+
/**
15+
* The maximum height (0 to 1080) of the image in pixels. Resizes the image to this height if it is larger.
16+
* @defaultValue 1080
17+
*/
18+
maxHeight?: number;
19+
/**
20+
* The quality of the image returned. Percentile value between 0 and 1.
21+
* @defaultValue 0.9
22+
*/
23+
quality?: number;
24+
}
25+
26+
export interface CameraMediaResponse {
27+
/** The image data as base64 string. */
28+
base64: string;
29+
/** The width of the image in pixels. */
30+
width: number;
31+
/** The height of the image in pixels. */
32+
height: number;
33+
/** The file size of the image in bytes. */
34+
fileSize: number;
35+
/** The MIME type of the image. */
36+
type: string;
37+
}
38+
39+
export interface CameraApiContent {
40+
/**
41+
* Launch the device's camera to take a photo.
42+
*
43+
* @param options the options for the camera media.
44+
* @returns Promise<CameraMediaResponse> that resolves when the POS has necessary permissions to access the camera and the media is captured.
45+
*/
46+
takePhoto: (options?: CameraMediaOptions) => Promise<CameraMediaResponse>;
47+
}
48+
49+
export interface CameraApi {
50+
camera: CameraApiContent;
51+
}

0 commit comments

Comments
 (0)