// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../core/resource'; import { APIPromise } from '../../core/api-promise'; import { buildHeaders } from '../../internal/headers'; import { RequestOptions } from '../../internal/request-options'; import { path } from '../../internal/utils/path'; export class Devices extends APIResource { /** * Register the phone or browser the user is signed in on to receive push * notifications, or refresh a device registered before. Call once after login -- * not per organization; the device receives push from every organization the user * belongs to -- and again whenever the push provider rotates the token. A token * registered earlier by another user moves to this user, so the previous owner * stops receiving push on it. */ create(params: DeviceCreateParams, options?: RequestOptions): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat, ...body } = params; return this._client.post('/notifications/devices', { body, ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Stop sending push notifications to one of the user's devices. Call on logout, * together with the push SDK's own token deletion. Repeating the call for an * already unregistered device succeeds. */ delete( deviceID: string, params: DeviceDeleteParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat } = params ?? {}; return this._client.delete(path`/notifications/devices/${deviceID}`, { ...options, headers: buildHeaders([ { Accept: '*/*', ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } } /** * The registered device. * * Attributes: device_id (str): ID to send to * `DELETE /notifications/devices/{device_id}` on logout. */ export interface DeviceCreateResponse { /** * ID to send when unregistering the device on logout. */ device_id: string; } export interface DeviceCreateParams { /** * Body param: Push token issued by the provider. */ token: string; /** * Body param: Where the device runs. */ platform: 'ios' | 'android' | 'web'; /** * Body param: App the device registered from, e.g. `glchat` or `catapa`. */ app_id?: string; /** * Body param: App version, e.g. `2.4.0 (231)`. */ app_version?: string | null; /** * Body param: BCP-47 language tag, e.g. `id-ID`. */ locale?: string | null; /** * Body param: Who issued the token. */ provider?: 'fcm'; /** * Body param: IANA time zone, e.g. `Asia/Jakarta`. */ timezone?: string | null; /** * Header param */ 'Accept-Language'?: string; /** * Header param: Set to `structured` to receive errors in the structured envelope. * Omit it to keep the legacy error body. */ 'X-Error-Format'?: string; } export interface DeviceDeleteParams { 'Accept-Language'?: string; /** * Set to `structured` to receive errors in the structured envelope. Omit it to * keep the legacy error body. */ 'X-Error-Format'?: string; } export declare namespace Devices { export { type DeviceCreateResponse as DeviceCreateResponse, type DeviceCreateParams as DeviceCreateParams, type DeviceDeleteParams as DeviceDeleteParams, }; }