Skip to content
Closed
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
4 changes: 4 additions & 0 deletions dist/helpers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ export interface CreateNotificationWithRetryResult {
wasReplayed: boolean;
}
export declare function createNotificationWithRetry(configuration: Configuration, notification: Notification, options?: CreateNotificationWithRetryOptions): Promise<CreateNotificationWithRetryResult>;
export type MessageSent = CreateNotificationSuccessResponse;
export type MessageNotSent = CreateNotificationSuccessResponse;
export declare function isMessageSent(response: CreateNotificationSuccessResponse): response is MessageSent;
export declare function isMessageNotSent(response: CreateNotificationSuccessResponse): response is MessageNotSent;
10 changes: 9 additions & 1 deletion dist/helpers.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/helpers.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,35 @@ function generateUuidV4(): string {
function sleep(ms: number): Promise<void> {
return new Promise<void>((resolve) => setTimeout(resolve, ms));
}

/**
* POST /notifications returns 200 in two distinct cases that share the
* `CreateNotificationSuccessResponse` shape. `MessageSent` is the branch where a
* notification was actually created — `id` is a non-empty UUID. Prefer the
* `isMessageSent` guard over inspecting `id` directly.
*/
export type MessageSent = CreateNotificationSuccessResponse;

/**
* The branch of a POST /notifications 200 where NO notification was created:
* `id` is the empty string and `errors` carries the reason (for example
* `["All included players are not subscribed"]`). Prefer the `isMessageNotSent`
* guard over inspecting `id` directly.
*/
export type MessageNotSent = CreateNotificationSuccessResponse;

/**
* Narrows a POST /notifications 200 response to the `MessageSent` branch — a
* notification was created (`id` is a non-empty string).
*/
export function isMessageSent(response: CreateNotificationSuccessResponse): response is MessageSent {
return typeof response.id === 'string' && response.id.length > 0;
}

/**
* Narrows a POST /notifications 200 response to the `MessageNotSent` branch — no
* notification was created (`id` is absent or empty); inspect `errors` for why.
*/
export function isMessageNotSent(response: CreateNotificationSuccessResponse): response is MessageNotSent {
return !isMessageSent(response);
}
2 changes: 1 addition & 1 deletion models/CreateNotificationSuccessResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { HttpFile } from '../http/http';

export class CreateNotificationSuccessResponse {
/**
* Notification identifier when the request created a notification. An empty string means no notification was created; read `errors` for details (HTTP may still be 200).
* Notification identifier when the request created a notification. An empty string means no notification was created; read `errors` for details (HTTP may still be 200). All OneSignal server SDKs expose message-sent / message-not-sent narrowing helpers (named idiomatically per language — e.g. `isMessageSent`, `is_message_sent`, `message_sent?`); prefer them over comparing `id` directly.
*/
'id'?: string;
/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onesignal/node-onesignal",
"version": "5.9.0",
"version": "5.8.0",
"description": "OpenAPI client for @onesignal/node-onesignal",
"author": "OpenAPI-Generator Contributors",
"keywords": [
Expand Down