+23
-3
| /** | ||
| * `devices` resource client. | ||
| * | ||
| * Mounted on `Nitroping` as `np.devices`. Wraps `POST /api/v1/devices`, | ||
| * `PUT /api/v1/devices/:id`, and `DELETE /api/v1/devices/:id`. | ||
| * Mounted on `Nitroping` as `np.devices`. Wraps `GET /api/v1/devices`, | ||
| * `POST /api/v1/devices`, `PUT /api/v1/devices/:id`, `DELETE | ||
| * /api/v1/devices/:id`, and `DELETE /api/v1/devices` (by token). | ||
| */ | ||
| import type { HttpClient } from "./http.mjs"; | ||
| import type { RegisterDeviceRequest, RegisterDeviceResponse, UpdateDeviceRequest, UpdateDeviceResponse } from "./types.mjs"; | ||
| import type { ListDevicesQuery, ListDevicesResponse, RegisterDeviceRequest, RegisterDeviceResponse, UpdateDeviceRequest, UpdateDeviceResponse } from "./types.mjs"; | ||
| export declare class DevicesClient { | ||
@@ -24,2 +25,9 @@ private readonly http; | ||
| /** | ||
| * List devices (secret key only). Wraps `GET /api/v1/devices`. | ||
| * | ||
| * Pass `userId` to fetch one end-user's registered devices. The push | ||
| * token is never returned. Returns `{ data, total }`. | ||
| */ | ||
| list(query?: ListDevicesQuery): Promise<ListDevicesResponse>; | ||
| /** | ||
| * Update a device (e.g. replace its tags). Wraps `PUT /api/v1/devices/:id`. | ||
@@ -41,2 +49,14 @@ * | ||
| }>; | ||
| /** | ||
| * Deactivate a device by its provider token (logout flow — you know the | ||
| * token but not the device id). Wraps `DELETE /api/v1/devices` with a | ||
| * `{ token }` body. | ||
| * | ||
| * Returns `{ id, status: "inactive" }`. Throws a `NitropingError` with | ||
| * `code: "not_found"` when no device with that token belongs to your app. | ||
| */ | ||
| deactivateByToken(token: string): Promise<{ | ||
| id: string; | ||
| status: string; | ||
| }>; | ||
| } |
+29
-0
@@ -12,2 +12,27 @@ export class DevicesClient { | ||
| async list(query = {}) { | ||
| const wire = { | ||
| user_id: query.userId, | ||
| platform: query.platform, | ||
| status: query.status, | ||
| page: query.page, | ||
| page_size: query.pageSize | ||
| }; | ||
| const raw = await this.http.request("GET", "/api/v1/devices", { query: wire }); | ||
| return { | ||
| total: raw.total, | ||
| data: raw.data.map((d) => ({ | ||
| id: d.id, | ||
| userId: d.user_id, | ||
| platform: d.platform, | ||
| status: d.status, | ||
| tags: d.tags, | ||
| timezone: d.timezone, | ||
| apnsEnvironment: d.apns_environment, | ||
| lastSeenAt: d.last_seen_at, | ||
| insertedAt: d.inserted_at | ||
| })) | ||
| }; | ||
| } | ||
| async update(id, input) { | ||
@@ -22,2 +47,6 @@ const body = {}; | ||
| } | ||
| async deactivateByToken(token) { | ||
| return await this.http.request("DELETE", "/api/v1/devices", { body: { token } }); | ||
| } | ||
| } | ||
@@ -24,0 +53,0 @@ function toWire(input) { |
+1
-1
@@ -7,3 +7,3 @@ /** Default base URL pointing at the hosted nitroping service. */ | ||
| */ | ||
| export declare const SDK_VERSION = "0.2.12"; | ||
| export declare const SDK_VERSION = "0.2.13"; | ||
| /** | ||
@@ -10,0 +10,0 @@ * Constructor options shared between server and public-key clients. |
+1
-1
@@ -6,3 +6,3 @@ | ||
| export const SDK_VERSION = "0.2.12"; | ||
| export const SDK_VERSION = "0.2.13"; | ||
@@ -9,0 +9,0 @@ export class HttpClient { |
@@ -39,2 +39,3 @@ export class NotificationsClient { | ||
| if (input.actions !== undefined) wire["actions"] = input.actions; | ||
| if (input.apnsCategory !== undefined) wire["apns_category"] = input.apnsCategory; | ||
| if (input.scheduledAt !== undefined) wire["scheduled_at"] = input.scheduledAt; | ||
@@ -41,0 +42,0 @@ if (input.expiresAt !== undefined) wire["expires_at"] = input.expiresAt; |
+36
-0
@@ -73,2 +73,8 @@ /** | ||
| actions?: NotificationAction[]; | ||
| /** | ||
| * iOS only. Sets `aps.category` verbatim so an app that registered a | ||
| * matching `UNNotificationCategory` (e.g. `"order_refund"`) renders the | ||
| * action buttons. Overrides the server-minted category for this message. | ||
| */ | ||
| apnsCategory?: string; | ||
| /** ISO-8601 timestamp; the row is held until then by the cron worker. */ | ||
@@ -152,2 +158,32 @@ scheduledAt?: string; | ||
| } | ||
| /** Query filters for `GET /api/v1/devices` (list). All optional. */ | ||
| export interface ListDevicesQuery { | ||
| /** Only this tenant-side user's devices. */ | ||
| userId?: string; | ||
| /** Filter by platform. */ | ||
| platform?: Platform; | ||
| /** Filter by status. */ | ||
| status?: "active" | "inactive"; | ||
| /** 1-based page number. */ | ||
| page?: number; | ||
| /** Rows per page (server caps at 100). */ | ||
| pageSize?: number; | ||
| } | ||
| /** One device in a `GET /api/v1/devices` listing. The push token is never returned. */ | ||
| export interface DeviceSummary { | ||
| id: string; | ||
| userId: string | null; | ||
| platform: Platform; | ||
| status: "active" | "inactive"; | ||
| tags: string[]; | ||
| timezone: string | null; | ||
| apnsEnvironment: "sandbox" | "production" | null; | ||
| lastSeenAt: string | null; | ||
| insertedAt: string; | ||
| } | ||
| /** Response from `GET /api/v1/devices`. */ | ||
| export interface ListDevicesResponse { | ||
| data: DeviceSummary[]; | ||
| total: number; | ||
| } | ||
| /** Delivery-tracking event type for `POST /api/v1/track`. */ | ||
@@ -154,0 +190,0 @@ export type TrackEvent = "delivered" | "opened" | "clicked"; |
+1
-1
| { | ||
| "name": "nitroping", | ||
| "version": "0.2.12", | ||
| "version": "0.2.13", | ||
| "description": "Zero-dependency TypeScript SDK for nitroping push notifications. Send pushes, register devices, verify webhooks. Works in Node, Bun, Deno, Cloudflare Workers, browsers.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
83287
3.31%996
2.89%