Skip to content

Commit 8658d3d

Browse files
committed
20644: Implement Camera API
1 parent 591de24 commit 8658d3d

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: 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+
* - `'front'`: The front-facing camera
5+
* - `'back'`: The rear-facing camera
6+
*
7+
* @defaultValue 'back'
8+
*/
9+
cameraType?: 'front' | 'back';
10+
/**
11+
* The maximum width (0 to 5000) of the image in pixels. Resizes the image to this width if it is larger.
12+
* @defaultValue 5000
13+
*/
14+
maxWidth?: number;
15+
/**
16+
* The maximum height (0 to 5000) of the image in pixels. Resizes the image to this height if it is larger.
17+
* @defaultValue 5000
18+
*/
19+
maxHeight?: number;
20+
}
21+
22+
export interface CameraMediaResponse {
23+
/** The base64 string of the image */
24+
base64: string;
25+
/** The file uri in the temporary cache directory, do not expect this to persist. Only use this for previewing the image. */
26+
previewUri: string;
27+
/** The width of the image in pixels. */
28+
width: number;
29+
/** The height of the image in pixels. */
30+
height: number;
31+
/** The file size of the image in bytes. */
32+
fileSize: number;
33+
/** The mime type of the image. */
34+
type: string;
35+
}
36+
37+
export interface CameraApiContent {
38+
/**
39+
* Get a media snapshot from the camera.
40+
*
41+
* @param options the options for the camera media.
42+
* @returns Promise<CameraMediaResponse> that resolves when the POS has necessary permissions to access the camera and the media is captured.
43+
*/
44+
getCameraMedia: (
45+
options?: CameraMediaOptions,
46+
) => Promise<CameraMediaResponse>;
47+
}
48+
49+
export interface CameraApi {
50+
camera: CameraApiContent;
51+
}

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
@@ -7,6 +7,7 @@ import {ProductSearchApi} from '../product-search-api/product-search-api';
77
import {PrintApi} from '../print-api/print-api';
88
import {StorageApi} from '../storage-api/storage-api';
99
import {PinPadApi} from '../pin-pad-api';
10+
import {CameraApi} from '../camera-api/camera-api';
1011

1112
export type StandardApi<T> = {[key: string]: any} & {
1213
extensionPoint: T;
@@ -18,4 +19,5 @@ export type StandardApi<T> = {[key: string]: any} & {
1819
DeviceApi &
1920
ConnectivityApi &
2021
StorageApi &
21-
PinPadApi;
22+
PinPadApi &
23+
CameraApi;

0 commit comments

Comments
 (0)