Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/slimy-foxes-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/ui-extensions': minor
---

Add Camera API types
7 changes: 7 additions & 0 deletions packages/ui-extensions/src/surfaces/point-of-sale/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ export type {ActionApi, ActionApiContent} from './api/action-api/action-api';
export type {StandardApi} from './api/standard/standard-api';
export type {ActionTargetApi} from './api/action-target-api/action-target-api';

export type {
CameraApi,
CameraApiContent,
CameraMediaOptions,
CameraMediaResponse,
} from './api/camera-api/camera-api';

export type {
ConnectivityStateSeverity,
ConnectivityState,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
export interface CameraMediaOptions {
/**
* The camera that will be active when the camera interface first opens.
* - `'user'`: The user-facing camera
* - `'environment'`: The environment-facing camera
*
* @defaultValue 'environment'
*/
facingMode?: 'user' | 'environment';
/**
* The maximum width (0 to 1080) of the image in pixels. Resizes the image to this width if it is larger.
* @defaultValue 1080
*/
maxWidth?: number;
/**
* The maximum height (0 to 1080) of the image in pixels. Resizes the image to this height if it is larger.
* @defaultValue 1080
*/
maxHeight?: number;

/**
* The quality of the image. (0.0 to 1.0)
* @defaultValue '0.9'
*/
quality?: number;
}

export interface CameraMediaResponse {
/** The base64 string of the image */
base64: string;
/** The width of the image in pixels. */
width: number;
/** The height of the image in pixels. */
height: number;
/** The file size of the image in bytes. */
fileSize: number;
/** The mime type of the image. */
type: string;
}

export interface CameraApiContent {
/**
* Get a media snapshot from the camera.
*
* @param options the options for the camera media.
* @returns Promise<CameraMediaResponse> that resolves when the POS has necessary permissions to access the camera and the media is captured.
*/
takePhoto: (options?: CameraMediaOptions) => Promise<CameraMediaResponse>;
}

export interface CameraApi {
camera: CameraApiContent;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {PrintApi} from '../print-api/print-api';
import {StorageApi} from '../storage-api/storage-api';
import {PinPadApi} from '../pin-pad-api';
import type {I18n} from '../../../../api';
import {CameraApi} from '../camera-api/camera-api';

export type StandardApi<T> = {[key: string]: any} & {
extensionPoint: T;
Expand All @@ -20,4 +21,5 @@ export type StandardApi<T> = {[key: string]: any} & {
DeviceApi &
ConnectivityApi &
StorageApi &
PinPadApi;
PinPadApi &
CameraApi;