import * as Promise from 'bluebird'; import { EventEmitter } from 'events'; import * as ResinErrors from 'resin-errors'; import { Readable } from 'stream'; import * as Pine from './pinejs-client-core'; import * as ResinPine from './resin-pine'; import { ResinRequest } from './resin-request'; declare namespace ResinSdk { type WithId = Pine.WithId; type PineDeferred = Pine.PineDeferred; type NavigationResource = Pine.NavigationResource; type ReverseNavigationResource = Pine.ReverseNavigationResource< T >; type PineFilterFor = Pine.Filter; type PineExpandFor = Pine.Expand; type PineOptions = Pine.PineOptions; type PineOptionsFor = Pine.PineOptionsFor; type PineParams = Pine.PineParams; type PineParamsFor = Pine.PineParamsFor; type PineParamsWithIdFor = Pine.PineParamsWithIdFor; interface Interceptor { request?(response: any): Promise; response?(response: any): Promise; requestError?(error: Error): Promise; responseError?(error: Error): Promise; } interface Config { deployment: string | null; deviceUrlsBase: string; adminUrl: string; apiUrl: string; actionsUrl: string; gitServerUrl: string; pubnub: { subscribe_key: string; publish_key: string; }; ga?: GaConfig; mixpanelToken?: string; intercomAppId?: string; recurlyPublicKey?: string; deviceTypes: DeviceType[]; DEVICE_ONLINE_ICON: string; DEVICE_OFFLINE_ICON: string; signupCodeRequired: boolean; supportedSocialProviders: string[]; } interface CurrentService { id: number; image_id: number; service_id: number; commit: string; download_progress: number; install_date: string; status: string; } interface CurrentGatewayDownload { id: number; image_id: number; service_id: number; download_progress: number; status: string; } interface DeviceWithServiceDetails extends Device { current_services: { [serviceName: string]: CurrentService[]; }; current_gateway_downloads: CurrentGatewayDownload[]; } interface GaConfig { site: string; id: string; } interface DeviceType { slug: string; name: string; arch: string; state?: string; isDependent?: boolean; instructions?: string[] | DeviceTypeInstructions; gettingStartedLink?: string | DeviceTypeGettingStartedLink; stateInstructions?: { [key: string]: string[] }; options?: DeviceTypeOptions[]; initialization?: { options?: DeviceInitializationOptions[]; operations: Array<{ command: string; }>; }; supportsBlink?: boolean; yocto: { fstype?: string; deployArtifact: string; }; /** Holds the latest resinOS version */ buildId?: string; } interface DeviceTypeInstructions { linux: string[]; osx: string[]; windows: string[]; } interface DeviceTypeGettingStartedLink { linux: string; osx: string; windows: string; [key: string]: string; } interface DeviceTypeOptions { options: DeviceTypeOptionsGroup[]; collapsed: boolean; isCollapsible: boolean; isGroup: boolean; message: string; name: string; } interface DeviceInitializationOptions { message: string; type: string; name: string; } interface DeviceTypeOptionsGroup { default: number | string; message: string; name: string; type: string; min?: number; choices?: string[] | number[]; choicesLabels?: { [key: string]: string }; } interface SocialServiceAccount { provider: string; display_name: string; created_at: string; id: number; remote_id: string; belongs_to__user: NavigationResource; } interface User { account_type?: string; actualUser?: number; company?: string; created_at: string; email?: string; features?: string[]; first_name?: string; hasPasswordSet?: boolean; has_disabled_newsletter?: boolean; id: number; intercomUserName?: string; intercomUserHash?: string; jwt_secret: string; last_name?: string; loginAs?: boolean; needsPasswordReset?: boolean; permissions?: string[]; public_key?: boolean; twoFactorRequired?: boolean; username: string; application: ReverseNavigationResource; creates__release: ReverseNavigationResource; owns__device: ReverseNavigationResource; user__is_member_of__application: ReverseNavigationResource< ApplicationMember >; // this is what the api route returns social_service_account: ReverseNavigationResource; } interface ApiKey { id: number; created_at: string; name: string; description: string | null; } interface Application { app_name: string; device_type: string; git_repository: string; commit: string; id: number; device_type_info?: DeviceType; has_dependent?: boolean; is_accessible_by_support_until__date: string; should_track_latest_release: boolean; application_type: NavigationResource; user: NavigationResource; depends_on__application: NavigationResource; application_config_variable: ReverseNavigationResource; application_environment_variable: ReverseNavigationResource< ApplicationVariable >; application_tag: ReverseNavigationResource; owns__device: ReverseNavigationResource; owns__release: ReverseNavigationResource; is_depended_on_by__application: ReverseNavigationResource; user__is_member_of__application: ReverseNavigationResource< ApplicationMember >; } interface ApplicationMember { id: number; role_title: string; is_member_of__application: NavigationResource; user: NavigationResource; } interface ApplicationType { id: number; name: string; slug: string; description: string | null; supports_gateway_mode: boolean; supports_multicontainer: boolean; supports_web_url: boolean; is_legacy: boolean; requires_payment: boolean; needs__os_version_range: string | null; maximum_device_count: number | null; } type ReleaseStatus = | 'cancelled' | 'error' | 'failed' | 'interrupted' | 'local' | 'running' | 'success' | 'timeout' | null; interface Release { log: string; commit: string; created_at: string; id: number; composition: string | null; source: string; end_timestamp: string; push_timestamp: string | null; start_timestamp: string; status: ReleaseStatus; update_timestamp: string | null; contains__image: null | Array<{ id: number; image: NavigationResource; }>; is_created_by__user: NavigationResource; belongs_to__application: NavigationResource; release_tag: ReverseNavigationResource; } interface BillingAccountAddressInfo { address1: string; address2: string; city: string; state: string; zip: string; country: string; phone: string; } interface BillingAccountInfo { account_state: string; first_name: string; last_name: string; company_name: string; cc_emails: string; vat_number: string; address: BillingAccountAddressInfo; } type BillingInfoType = 'bank_account' | 'credit_card' | 'paypal'; interface BillingInfo { full_name: string; first_name: string; last_name: string; company: string; vat_number: string; address1: string; address2: string; city: string; state: string; zip: string; country: string; phone: string; type?: BillingInfoType; } interface CardBillingInfo extends BillingInfo { card_type: string; year: string; month: string; first_one: string; last_four: string; } interface BankAccountBillingInfo extends BillingInfo { account_type: string; last_four: string; name_on_account: string; routing_number: string; } interface TokenBillingSubmitInfo { token_id: string; } interface BillingPlanInfo { name: string; tier: string; billing: BillingPlanBillingInfo; intervalUnit?: string; intervalLength?: string; addonPlan?: BillingAddonPlanInfo; } interface BillingAddonPlanInfo { code: string; currentPeriodEndDate?: string; billing: BillingPlanBillingInfo; addOns: Array<{ code: string; unitCostCents?: string; quantity?: string; }>; } interface BillingPlanBillingInfo { currency: string; currencySymbol?: string; totalCostCents: string; charges: Array<{ itemType: string; name: string; code: string; unitCostCents: string; quantity: string; }>; } interface InvoiceInfo { closed_at: string; created_at: string; due_on: string; currency: string; invoice_number: string; subtotal_in_cents: string; total_in_cents: string; uuid: string; state: 'pending' | 'paid' | 'failed' | 'past_due'; } interface Device { app_name: string; created_at: string; custom_latitude?: string; custom_longitude?: string; device_name: string; device_type: string; download_progress?: number; has_dependent: boolean; id: number; ip_address: string | null; is_accessible_by_support_until__date: string; is_connected_to_vpn: boolean; is_in_local_mode?: boolean; is_locked_until__date: string; is_on__commit: string; is_web_accessible: boolean; is_active: boolean; is_online: boolean; last_connectivity_event: string; latitude?: string; local_id?: string; location: string; longitude?: string; note: string; os_variant?: string; os_version: string; provisioning_progress?: number; provisioning_state: string; state?: { key: string; name: string }; status: string; status_sort_index?: number; supervisor_version: string; uuid: string; vpn_address: string | null; should_be_managed_by__supervisor_release: number; belongs_to__application: NavigationResource; belongs_to__user: NavigationResource; should_be_running__release: NavigationResource; is_managed_by__service__instance: NavigationResource; is_managed_by__device: NavigationResource; device_config_variable: ReverseNavigationResource; device_environment_variable: ReverseNavigationResource; device_tag: ReverseNavigationResource; manages__device: ReverseNavigationResource; } interface SupervisorRelease { created_at: string; id: number; supervisor_version: string; device_type: string; image_name: string; is_public: boolean; note?: string; } interface ServiceInstance { created_at: string; id: number; service_type: string; ip_address: string; last_heartbeat: string; } interface Service { id: number; service_name: string; application: NavigationResource; } interface Image { id: number; build_log: string; is_a_build_of__service: NavigationResource; start_timestamp?: string | null; end_timestamp?: string | null; image_size?: number | null; dockerfile: string; error_message?: string | null; } interface LogMessage { message: string; isSystem: boolean; createdAt: number; timestamp: number; serviceId?: number; isStdErr: boolean; } interface LogsSubscription extends EventEmitter { unsubscribe(): void; } interface LogsOptions { count?: number | 'all'; } interface SSHKey { title: string; public_key: string; id: number; created_at: string; } type ImgConfigOptions = { network?: 'ethernet' | 'wifi'; appUpdatePollInterval?: number; wifiKey?: string; wifiSsid?: string; ip?: string; gateway?: string; netmask?: string; version: string; }; type OsVersions = { latest: string; recommended: string; default: string; versions: string[]; }; interface ServiceInstall { id: number; should_be_running: boolean; device: NavigationResource; installs__service: NavigationResource; service: Service[]; application: NavigationResource; } interface EnvironmentVariableBase { id: number; name: string; value: string; } interface DeviceServiceEnvironmentVariable extends EnvironmentVariableBase { service_install: NavigationResource; } interface ServiceEnvironmentVariable extends EnvironmentVariableBase { service: NavigationResource; } interface DeviceVariable extends EnvironmentVariableBase { device: NavigationResource; } interface ApplicationVariable extends EnvironmentVariableBase { application: NavigationResource; } interface ResourceTagBase { id: number; tag_key: string; value: string; } interface ApplicationTag extends ResourceTagBase { application: NavigationResource; } interface DeviceTag extends ResourceTagBase { device: NavigationResource; } interface ReleaseTag extends ResourceTagBase { release: NavigationResource; } interface ResinSDK { auth: { register: ( credentials: { email: string; password: string }, ) => Promise; authenticate: ( credentials: { email: string; password: string }, ) => Promise; login: ( credentials: { email: string; password: string }, ) => Promise; loginWithToken: (authToken: string) => Promise; logout: () => Promise; getToken: () => Promise; whoami: () => Promise; isLoggedIn: () => Promise; getUserId: () => Promise; getEmail: () => Promise; twoFactor: { isEnabled: () => Promise; isPassed: () => Promise; challenge: (code: string) => Promise; }; }; settings: { get(key: string): Promise; getAll(): Promise<{ [key: string]: string }>; }; request: ResinRequest; errors: typeof ResinErrors; models: { application: { create(options: { name: string; applicationType?: string; deviceType: string; parent?: number | string; }): Promise; get( nameOrId: string | number, options?: PineOptionsFor, ): Promise; getWithDeviceServiceDetails( nameOrId: string | number, options?: PineOptionsFor, ): Promise< Application & { owns__device: DeviceWithServiceDetails[]; } >; getAppByOwner( appName: string, owner: string, options?: PineOptionsFor, ): Promise; getAll(options?: PineOptionsFor): Promise; has(nameOrId: string | number): Promise; hasAny(): Promise; remove(nameOrId: string | number): Promise; restart(nameOrId: string | number): Promise; enableDeviceUrls(nameOrId: string | number): Promise; disableDeviceUrls(nameOrId: string | number): Promise; grantSupportAccess( nameOrId: string | number, expiryTimestamp: number, ): Promise; revokeSupportAccess(nameOrId: string | number): Promise; reboot(appId: number, { force }: { force?: boolean }): Promise; shutdown(appId: number, { force }: { force?: boolean }): Promise; purge(appId: number): Promise; generateApiKey(nameOrId: string | number): Promise; generateProvisioningKey(nameOrId: string | number): Promise; tags: { getAllByApplication( nameOrId: string | number, options?: PineOptionsFor, ): Promise; getAll( options?: PineOptionsFor, ): Promise; set( nameOrId: string | number, tagKey: string, value: string, ): Promise; remove(nameOrId: string | number, tagKey: string): Promise; }; configVar: { getAllByApplication( nameOrId: string | number, options?: PineOptionsFor, ): Promise; set( nameOrId: string | number, key: string, value: string, ): Promise; get( nameOrId: string | number, key: string, ): Promise; remove(nameOrId: string | number, key: string): Promise; }; envVar: { getAllByApplication( nameOrId: string | number, options?: PineOptionsFor, ): Promise; set( nameOrId: string | number, key: string, value: string, ): Promise; get( nameOrId: string | number, key: string, ): Promise; remove(nameOrId: string | number, key: string): Promise; }; }; apiKey: { create: (name: string, description?: string | null) => Promise; getAll: (options?: PineOptionsFor) => Promise; update: ( id: number, apiKeyInfo: { name?: string; description?: string | null }, ) => Promise; revoke: (id: number) => Promise; }; release: { get(id: number, options?: PineOptionsFor): Promise; getAllByApplication( nameOrId: string | number, options?: PineOptionsFor, ): Promise; getWithImageDetails( nameOrId: string | number, options?: { release?: PineOptionsFor; image?: PineOptionsFor; }, ): Promise< Array< Release & { images: Array<{ id: number; service_name: string; }>; user: User; } > >; tags: { getAllByApplication( nameOrId: string | number, options?: PineOptionsFor, ): Promise; getAllByRelease( id: number, options?: PineOptionsFor, ): Promise; getAll(options?: PineOptionsFor): Promise; set(releaseId: number, tagKey: string, value: string): Promise; remove(releaseId: number, tagKey: string): Promise; }; }; billing: { getAccount(): Promise; getPlan(): Promise; getBillingInfo(): Promise; updateBillingInfo( billingInfo: TokenBillingSubmitInfo, ): Promise; getInvoices(): Promise; downloadInvoice(invoiceNumber: string): Promise; }; device: { get( uuidOrId: string | number, options?: PineOptionsFor, ): Promise; getByName( nameOrId: string | number, options?: PineOptionsFor, ): Promise; getWithServiceDetails( nameOrId: string | number, options?: PineOptionsFor, ): Promise; getAll(options?: PineOptionsFor): Promise; getAllByApplication( nameOrId: string | number, options?: PineOptionsFor, ): Promise; getAllByParentDevice( parentUuidOrId: string | number, options?: PineOptionsFor, ): Promise; getName(uuidOrId: string | number): Promise; getApplicationName(uuidOrId: string | number): Promise; getApplicationInfo( uuidOrId: string | number, ): Promise<{ appId: string; commit: string; containerId: string; env: { [key: string]: string | number }; imageId: string; }>; has(uuidOrId: string | number): Promise; isOnline(uuidOrId: string | number): Promise; getLocalIPAddressess(uuidOrId: string | number): Promise; getDashboardUrl(uuid: string): string; getSupportedDeviceTypes(): Promise; getManifestBySlug(slugOrName: string): Promise; getManifestByApplication( nameOrId: string | number, ): Promise; move( uuidOrId: string | number, applicationNameOrId: string | number, ): Promise; note(uuidOrId: string | number, note: string): Promise; remove(uuidOrId: string | number): Promise; rename(uuidOrId: string | number, newName: string): Promise; setCustomLocation( uuidOrId: string | number, location: { latitude: number; longitude: number }, ): Promise; unsetCustomLocation(uuidOrId: string | number): Promise; identify(uuidOrId: string | number): Promise; startApplication(uuidOrId: string | number): Promise; stopApplication(uuidOrId: string | number): Promise; restartApplication(uuidOrId: string | number): Promise; grantSupportAccess( uuidOrId: string | number, expiryTimestamp: number, ): Promise; revokeSupportAccess(uuidOrId: string | number): Promise; reboot( uuidOrId: string | number, { force }: { force?: boolean }, ): Promise; shutdown( uuidOrId: string | number, { force }: { force?: boolean }, ): Promise; purge(uuidOrId: string | number): Promise; update( uuidOrId: string | number, { force }: { force?: boolean }, ): Promise; getDisplayName(deviceTypeName: string): string; getDeviceSlug(deviceTypeName: string): string; generateUniqueKey(): string; register( applicationNameOrId: string | number, uuid: string, ): Promise<{ id: number; uuid: string; api_key: string; }>; generateDeviceKey(uuidOrId: string | number): Promise; enableDeviceUrl(uuidOrId: string | number): Promise; disableDeviceUrl(uuidOrId: string | number): Promise; hasDeviceUrl(uuidOrId: string | number): Promise; getDeviceUrl(uuidOrId: string | number): Promise; enableTcpPing(uuidOrId: string | number): Promise; disableTcpPing(uuidOrId: string | number): Promise; ping(uuidOrId: string | number): Promise; getStatus(device: object): string; lastOnline(device: Device): string; tags: { getAllByApplication( nameOrId: string | number, options?: PineOptionsFor, ): Promise; getAllByDevice( uuidOrId: string | number, options?: PineOptionsFor, ): Promise; getAll(options?: PineOptionsFor): Promise; set( uuidOrId: string | number, tagKey: string, value: string, ): Promise; remove(uuidOrId: string | number, tagKey: string): Promise; }; configVar: { getAllByDevice( uuidOrId: string | number, options?: PineOptionsFor, ): Promise; getAllByApplication( nameOrId: string | number, options?: PineOptionsFor, ): Promise; set( uuidOrId: string | number, key: string, value: string, ): Promise; get( uuidOrId: string | number, key: string, ): Promise; remove(uuidOrId: string | number, key: string): Promise; }; envVar: { getAllByDevice( uuidOrId: string | number, options?: PineOptionsFor, ): Promise; getAllByApplication( nameOrId: string | number, options?: PineOptionsFor, ): Promise; set( uuidOrId: string | number, key: string, value: string, ): Promise; get( uuidOrId: string | number, key: string, ): Promise; remove(uuidOrId: string | number, key: string): Promise; }; serviceVar: { getAllByDevice( uuidOrId: string | number, options?: PineOptionsFor, ): Promise; getAllByApplication( nameOrId: string | number, options?: PineOptionsFor, ): Promise; set( uuidOrId: string | number, serviceId: number, key: string, value: string, ): Promise; get( uuidOrId: string | number, serviceId: number, key: string, ): Promise; remove( uuidOrId: string | number, serviceId: number, key: string, ): Promise; }; }; service: { getAllByApplication( nameOrId: string | number, options?: PineOptionsFor, ): Promise; var: { getAllByService( id: number, options?: PineOptionsFor, ): Promise; getAllByApplication( nameOrId: string | number, options?: PineOptionsFor, ): Promise; set(id: number, key: string, value: string): Promise; get(id: number, key: string): Promise; remove(id: number, key: string): Promise; }; }; config: { getAll: () => Promise; getDeviceTypes: () => Promise; getDeviceOptions( deviceType: string, ): Promise>; }; image: { get(id: number, options?: PineOptionsFor): Promise; getLogs(id: number): Promise; }; key: { getAll(options?: PineOptionsFor): Promise; get(id: string | number): Promise; remove(id: string | number): Promise; create(title: string, key: string): Promise; }; os: { getConfig( nameOrId: string | number, options: ImgConfigOptions, ): Promise; getDownloadSize(slug: string, version?: string): Promise; getSupportedVersions(slug: string): Promise; getMaxSatisfyingVersion( deviceType: string, versionOrRange: string, ): string; getLastModified(deviceType: string, version?: string): Promise; download(deviceType: string, version?: string): Promise; }; }; logs: { history(uuid: string, options?: LogsOptions): Promise; subscribe(uuid: string, options?: LogsOptions): Promise; }; pine: ResinPine.Pine; interceptors: Interceptor[]; } interface SdkOptions { apiUrl?: string; /** * @deprecated Use resin.auth.loginWithToken(apiKey) instead */ apiKey?: string; imageMakerUrl?: string; dataDirectory?: string; isBrowser?: boolean; debug?: boolean; } interface SdkConstructor { (options?: SdkOptions): ResinSdk.ResinSDK; setSharedOptions(options: SdkOptions): void; fromSharedOptions: () => ResinSdk.ResinSDK; } } declare const ResinSdk: ResinSdk.SdkConstructor; export = ResinSdk;