Skip to content

Commit 216d774

Browse files
committed
20644: Implement Camera API
1 parent e362d1f commit 216d774

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
export interface CameraMediaOptions {
2+
/**
3+
* The camera that will be active when the camera interface first opens.
4+
* - `'user'`: The user-facing camera
5+
* - `'environment'`: The environment-facing camera
6+
*
7+
* @defaultValue 'environment'
8+
*/
9+
facingMode?: 'user' | 'environment';
10+
/**
11+
* The maximum width (0 to 1080) of the image in pixels. Resizes the image to this width if it is larger.
12+
* @defaultValue 1080
13+
*/
14+
maxWidth?: number;
15+
/**
16+
* The maximum height (0 to 1080) of the image in pixels. Resizes the image to this height if it is larger.
17+
* @defaultValue 1080
18+
*/
19+
maxHeight?: number;
20+
21+
/**
22+
* The quality of the image. (0.0 to 1.0)
23+
* @defaultValue '0.9'
24+
*/
25+
quality?: number;
26+
}
27+
28+
export interface CameraMediaResponse {
29+
/** The base64 string of the image */
30+
base64: string;
31+
/** The width of the image in pixels. */
32+
width: number;
33+
/** The height of the image in pixels. */
34+
height: number;
35+
/** The file size of the image in bytes. */
36+
fileSize: number;
37+
/** The mime type of the image. */
38+
type: string;
39+
}
40+
41+
export interface CameraApiContent {
42+
/**
43+
* Get a media snapshot from the camera.
44+
*
45+
* @param options the options for the camera media.
46+
* @returns Promise<CameraMediaResponse> that resolves when the POS has necessary permissions to access the camera and the media is captured.
47+
*/
48+
takePhoto: (options?: CameraMediaOptions) => Promise<CameraMediaResponse>;
49+
}
50+
51+
export interface CameraApi {
52+
camera: CameraApiContent;
53+
}

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
@@ -8,6 +8,7 @@ import {PrintApi} from '../print-api/print-api';
88
import {StorageApi} from '../storage-api/storage-api';
99
import {PinPadApi} from '../pin-pad-api';
1010
import type {I18n} from '../../../../api';
11+
import {CameraApi} from '../camera-api/camera-api';
1112

1213
export type StandardApi<T> = {[key: string]: any} & {
1314
extensionPoint: T;
@@ -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)