Skip to content

Latest commit

 

History

History
487 lines (317 loc) · 16.9 KB

README.md

File metadata and controls

487 lines (317 loc) · 16.9 KB

snack-sdk

snack-sdk

Index

Classes

Interfaces

Type aliases

Functions

Type aliases

SDKFeature

Ƭ SDKFeature: "MULTIPLE_FILES" | "PROJECT_DEPENDENCIES" | "TYPESCRIPT" | "UNIMODULE_IMPORTS" | "POSTMESSAGE_TRANSPORT" | "VERSIONED_SNACKAGER"

Feature that is supported by the SDK (e.g. "TYPESCRIPT").


SDKVersion

Ƭ SDKVersion: "37.0.0" | "38.0.0" | "39.0.0" | "40.0.0"

Version of the sdk to use (e.g. "37.0.0").


SnackAssetFile

Ƭ SnackAssetFile: { contents: string | File | Blob | FormData ; error?: Error ; type: "ASSET" }

An asset file that refers to externaly available content such as an image or font.

When resolved, the contents field is an URL to the uploaded asset. A File, Blob or FormData object may also be provided after which it is automatically uploaded and converted into an URL.

Type declaration:

Name Type
contents string | File | Blob | FormData
error? Error
type "ASSET"

SnackCodeFile

Ƭ SnackCodeFile: { contents: string ; error?: Error ; type: "CODE" }

A non asset file that is included with the project. This can be either a code file (.js/.tsx) or a support file such as a markdown or json file.

Type declaration:

Name Type
contents string
error? Error
type "CODE"

SnackConnectedClient

Ƭ SnackConnectedClient: { error?: SnackError ; id: string ; name: string ; platform: string ; previewTimestamp?: undefined | number ; previewURL?: undefined | string ; status: SnackConnectedClientStatus ; transport: string }

Client which connected to the Snack.

Clients are only able to connect when the Snack is online.

Type declaration:

Name Type
error? SnackError
id string
name string
platform string
previewTimestamp? undefined | number
previewURL? undefined | string
status SnackConnectedClientStatus
transport string

SnackConnectedClientStatus

Ƭ SnackConnectedClientStatus: "ok" | "error" | "reloading"


SnackConnectedClients

Ƭ SnackConnectedClients: { [key:string]: SnackConnectedClient; }

Collection of connected clients.


SnackDependencies

Ƭ SnackDependencies: { [name:string]: SnackDependency; }

Dictionary of dependency names and their (resolved) versions.


SnackDependency

Ƭ SnackDependency: { error?: Error ; handle?: undefined | string ; peerDependencies?: SnackDependencyVersions ; version: string ; wantedVersion?: undefined | string }

The version, resolved handle, peer-dependencies and optional error of a dependency.

Type declaration:

Name Type
error? Error
handle? undefined | string
peerDependencies? SnackDependencyVersions
version string
wantedVersion? undefined | string

SnackDependencyVersions

Ƭ SnackDependencyVersions: { [name:string]: string; }

Dictionary of dependencies and their version.


SnackFile

Ƭ SnackFile: SnackCodeFile | SnackAssetFile

The content of a Snack code or asset file.


SnackFiles

Ƭ SnackFiles: { [path:string]: SnackFile; }

Dictionary of file-names and their content that make up the files of the Snack.


SnackListenerSubscription

Ƭ SnackListenerSubscription: () => any


SnackLogEvent

Ƭ SnackLogEvent: { connectedClient?: SnackConnectedClient ; error?: SnackError ; message: string ; type: "error" | "warn" | "log" | "info" }

Log data for when a connected client calls one of the console.[log,info,warn,error] to log information to the console.

Type declaration:

Name Type
connectedClient? SnackConnectedClient
error? SnackError
message string
type "error" | "warn" | "log" | "info"

SnackLogListener

Ƭ SnackLogListener: (log: SnackLogEvent) => any


SnackMissingDependencies

Ƭ SnackMissingDependencies: { [name:string]: SnackMissingDependency; }

Dictionary of dependencies that are missing.


SnackMissingDependency

Ƭ SnackMissingDependency: { dependents: string[] ; wantedVersion?: undefined | string }

Wanted version of the dependency that is missing, including the dependents which have this dependency as a peer-dependency.

Type declaration:

Name Type
dependents string[]
wantedVersion? undefined | string

SnackOptions

Ƭ SnackOptions: { accountSnackId?: undefined | string ; apiURL?: undefined | string ; channel?: undefined | string ; codeChangesDelay?: undefined | number ; createTransport?: undefined | (options: SnackTransportOptions) => SnackTransport ; dependencies?: SnackDependencies ; description?: undefined | string ; deviceId?: undefined | string ; disabled?: undefined | false | true ; files?: SnackFiles ; host?: undefined | string ; id?: undefined | string ; name?: undefined | string ; online?: undefined | false | true ; previewTimeout?: undefined | number ; reloadTimeout?: undefined | number ; sdkVersion?: SDKVersion ; snackagerURL?: undefined | string ; snackId?: undefined | string ; transports?: undefined | { [id:string]: SnackTransport; } ; user?: SnackUser ; verbose?: undefined | false | true ; webPlayerURL?: undefined | string ; webPreviewRef?: SnackWindowRef }

Type declaration:

Name Type
accountSnackId? undefined | string
apiURL? undefined | string
channel? undefined | string
codeChangesDelay? undefined | number
createTransport? undefined | (options: SnackTransportOptions) => SnackTransport
dependencies? SnackDependencies
description? undefined | string
deviceId? undefined | string
disabled? undefined | false | true
files? SnackFiles
host? undefined | string
id? undefined | string
name? undefined | string
online? undefined | false | true
previewTimeout? undefined | number
reloadTimeout? undefined | number
sdkVersion? SDKVersion
snackagerURL? undefined | string
snackId? undefined | string
transports? undefined | { [id:string]: SnackTransport; }
user? SnackUser
verbose? undefined | false | true
webPlayerURL? undefined | string
webPreviewRef? SnackWindowRef

SnackSaveOptions

Ƭ SnackSaveOptions: { ignoreUser?: undefined | false | true ; isDraft?: undefined | false | true }

Type declaration:

Name Type
ignoreUser? undefined | false | true
isDraft? undefined | false | true

SnackSendBeaconRequest

Ƭ SnackSendBeaconRequest: { data: any ; url: string }

Request data to be used with the sendBeacon API.

Type declaration:

Name Type
data any
url string

SnackState

Ƭ SnackState: { accountSnackId: undefined |string ; channel: string ; connectedClients: SnackConnectedClients ; dependencies: SnackDependencies ; description: string ; deviceId?: undefined | string ; disabled: boolean ; files: SnackFiles ; id?: undefined | string ; missingDependencies: SnackMissingDependencies ; name: string ; online: boolean ; onlineName?: undefined | string ; saveURL?: undefined | string ; savedSDKVersion?: undefined | string ; sdkVersion: SDKVersion ; sendBeaconCloseRequest?: SnackSendBeaconRequest ; snackId: undefined |string ; unsaved: boolean ; url: string ; user?: SnackUser ; wantedDependencyVersions?: SnackDependencyVersions ; webPreviewURL?: undefined | string }

Type declaration:

Name Type Description
accountSnackId undefined | string Id of the saved Snack if it belongs to an account.
channel string Communication channel ("pubnub") through which live updates are transferred. The communication channel is only used when the Snack is "online".
connectedClients SnackConnectedClients Clients that are currently connected.
dependencies SnackDependencies Packages that can be used in the code files. Packages that are pre-loaded by the sdk may be ommited, but it is recommended to add them anyway.
description string Additional description of the Snack. The description is used when saving the Snack and may also be used for searching purposes.
deviceId? undefined | string Device-id of the Expo client. When set causes the Snack to be visible in the "Recently in Development" section of the Expo client with that device-id. The device-id is only used when the Snack is "online".
disabled boolean Disabled state. When the Snack is disabled it will not resolve any dependencies or upload any asset files. It also disables the ability to go online.
files SnackFiles Files that make up the content (code & assets) of the Snack. There should always be a file called "App.js" or "App.tsx" as the main entry point.
id? undefined | string Full name of the saved Snack.
missingDependencies SnackMissingDependencies Collection of dependencies that are missing but are required by one or more of the dependencies.
name string Optional name. The name is used when saving or downloading the Snack; and is used for the onlineName property.
online boolean When online is true, Expo clients can connect to the Snack and receive live updates when code or dependencies are changed. It also makes the Snack visible in the "Recently in Development" section of the Expo client.
onlineName? undefined | string Name of the Snack as shown in the "Recently in Development" section in the Expo client. The online-name will be empty when the Snack is not "online".
saveURL? undefined | string URL of the saved Snack. The URL is empty when no save "id" is available.
savedSDKVersion? undefined | string Last saved (non-draft) Expo SDK version.
sdkVersion SDKVersion Expo SDK version.
sendBeaconCloseRequest? SnackSendBeaconRequest A close request that should be send using the browser sendBeacon API whenever the browser session is unloaded. This gives the Snack a last opportunity to gracefully close its connections so that the "Recently in Development" section in the Expo client no longer shows the Snack.
snackId undefined | string Id of this version of the saved Snack.
unsaved boolean Unsaved status of the Snack. Becomes true when the Snack code is changed and false whenever the Snack is saved.
url string Unique experience url which can be used to open the Expo client and connect to the Snack (e.g. "exp://exp.host/@snack/sdk.38.0.0-78173941").
user? SnackUser
wantedDependencyVersions? SnackDependencyVersions Collection of packages and versions that are compatible with the selected SDK version. This is similar to using expo install, which ensures the latest compatible version is installed.
webPreviewURL? undefined | string URL to use to when loading the web-preview in an iframe. Web-preview is supported from SDK 40 and higher. To enable it, set the webPreviewRef to the contentWindow of the iframe.

SnackStateListener

Ƭ SnackStateListener: (state: SnackState, prevState: SnackState) => any


SnackUser

Ƭ SnackUser: { sessionSecret?: undefined | string }

User that is used for communicating with the Expo servers.

Type declaration:

Name Type
sessionSecret? undefined | string

SnackWindowRef

Ƭ SnackWindowRef: { current: Window | null }

Type declaration:

Name Type
current Window | null

Functions

getPreloadedModules

getPreloadedModules(sdkVersion: SDKVersion, coreModulesOnly?: undefined | false | true): object

Returns the list of pre-loaded modules for the given SDK version.

Parameters:

Name Type
sdkVersion SDKVersion
coreModulesOnly? undefined | false | true

Returns: object


getSupportedSDKVersions

getSupportedSDKVersions(): SDKVersion[]

Returns the list of supported SDK versions.

Returns: SDKVersion[]


isFeatureSupported

isFeatureSupported(feature: SDKFeature, sdkVersion: string): boolean

Checks whether a feature is supported by the given SDK version.

Parameters:

Name Type
feature SDKFeature
sdkVersion string

Returns: boolean


isModulePreloaded

isModulePreloaded(name: string, sdkVersion: SDKVersion, coreModulesOnly?: undefined | false | true): boolean

Checks whether a specific module/dependency is preloaded for the given SDK version.

Parameters:

Name Type
name string
sdkVersion SDKVersion
coreModulesOnly? undefined | false | true

Returns: boolean


isValidSemver

isValidSemver(version: string): boolean

Verifies whether a string is a valid semver.

Parameters:

Name Type
version string

Returns: boolean


standardizeDependencies

standardizeDependencies(dependencies: any): SnackDependencies

Converts older dependency formats into the SnackDependencies type.

Parameters:

Name Type
dependencies any

Returns: SnackDependencies


validateSDKVersion

validateSDKVersion(sdkVersion: SDKVersion): SDKVersion

Parameters:

Name Type
sdkVersion SDKVersion

Returns: SDKVersion