Skip to content

Commit 6b20b88

Browse files
20644: Implement Camera API (#3597)
Co-authored-by: andy-chhuon <andy.chhuon@shopify.com>
1 parent ba6a8ee commit 6b20b88

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-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: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 (1 to 1920) 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 (1 to 1920) 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.
21+
* Percentile value between 0 (lowest quality/highest compression) and 1 (highest quality/lowest compression).
22+
* @defaultValue 0.9
23+
*/
24+
quality?: number;
25+
}
26+
27+
export interface CameraMediaResponse {
28+
/** The image data as base64 string. */
29+
base64: string;
30+
/** The width of the image in pixels. */
31+
width: number;
32+
/** The height of the image in pixels. */
33+
height: number;
34+
/** The file size of the image in bytes. */
35+
fileSize: number;
36+
/** The MIME type of the image. */
37+
type: string;
38+
}
39+
40+
export interface CameraApiContent {
41+
/**
42+
* Launch the device's camera to take a photo.
43+
*
44+
* @param options the options for the camera media
45+
* @returns a promise that resolves with the captured image and metadata
46+
* @throws {Error} when camera permission is denied by the user
47+
* @throws {Error} when the user cancels the photo capture
48+
* @throws {Error} when the device has no available camera
49+
* @throws {Error} when the camera API is already in use
50+
*/
51+
takePhoto: (options?: CameraMediaOptions) => Promise<CameraMediaResponse>;
52+
}
53+
54+
export interface CameraApi {
55+
camera: CameraApiContent;
56+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {CameraApi} from '../camera-api/camera-api';
12
import {ConnectivityApi} from '../connectivity-api/connectivity-api';
23
import {DeviceApi} from '../device-api/device-api';
34
import {LocaleApi} from '../locale-api/locale-api';
@@ -20,4 +21,5 @@ export type StandardApi<T> = {[key: string]: any} & {
2021
DeviceApi &
2122
ConnectivityApi &
2223
StorageApi &
23-
PinPadApi;
24+
PinPadApi &
25+
CameraApi;

0 commit comments

Comments
 (0)