notification-services
Version:
Use email, sms and custom notification services for node.js application easily
242 lines (241 loc) • 7.07 kB
TypeScript
export interface FCMServiceAccountKey {
type: string;
project_id: string;
private_key_id: string;
private_key: string;
client_email: string;
client_id: string;
auth_uri: string;
token_uri: string;
auth_provider_x509_cert_url: string;
client_x509_cert_url: string;
}
export interface FCMData {
[key: string]: string;
}
export interface FCMNotification {
title?: string;
body?: string;
image?: string;
icon?: string;
}
export interface FCMAndroidConfig {
collapse_key?: string;
priority?: 'normal' | 'high';
ttl?: string;
restricted_package_name?: string;
data?: FCMData;
notification?: {
title?: string;
body?: string;
icon?: string;
color?: string;
sound?: string;
tag?: string;
click_action?: string;
body_loc_key?: string;
body_loc_args?: string[];
title_loc_key?: string;
title_loc_args?: string[];
channel_id?: string;
ticker?: string;
sticky?: boolean;
event_time?: string;
local_only?: boolean;
notification_priority?: 'PRIORITY_UNSPECIFIED' | 'PRIORITY_MIN' | 'PRIORITY_LOW' | 'PRIORITY_DEFAULT' | 'PRIORITY_HIGH' | 'PRIORITY_MAX';
default_sound?: boolean;
default_vibrate_timings?: boolean;
default_light_settings?: boolean;
vibrate_timings?: string[];
visibility?: 'VISIBILITY_UNSPECIFIED' | 'PRIVATE' | 'PUBLIC' | 'SECRET';
notification_count?: number;
image?: string;
};
fcm_options?: {
analytics_label?: string;
};
}
export interface FCMApnsConfig {
headers?: {
[key: string]: string;
};
payload?: {
aps?: {
alert?: {
title?: string;
subtitle?: string;
body?: string;
'launch-image'?: string;
'title-loc-key'?: string;
'title-loc-args'?: string[];
'action-loc-key'?: string;
'loc-key'?: string;
'loc-args'?: string[];
};
badge?: number;
sound?: string | {
critical?: number;
name?: string;
volume?: number;
};
'thread-id'?: string;
category?: string;
'content-available'?: number;
'mutable-content'?: number;
'target-content-id'?: string;
'interruption-level'?: 'passive' | 'active' | 'time-sensitive' | 'critical';
'relevance-score'?: number;
'filter-criteria'?: string;
'stale-date'?: number;
'content-state'?: {
[key: string]: any;
};
timestamp?: number;
event?: 'update' | 'end';
'dismissal-date'?: number;
attributes?: {
'attributes-type'?: number;
'display-name'?: string;
'machine-name'?: string;
};
'content-id'?: string;
};
[key: string]: any;
};
fcm_options?: {
analytics_label?: string;
image?: string;
};
}
export interface FCMWebpushConfig {
headers?: {
[key: string]: string;
};
data?: FCMData;
notification?: {
title?: string;
body?: string;
icon?: string;
image?: string;
badge?: string;
actions?: Array<{
action: string;
title: string;
icon?: string;
}>;
dir?: 'auto' | 'ltr' | 'rtl';
lang?: string;
renotify?: boolean;
requireInteraction?: boolean;
silent?: boolean;
tag?: string;
timestamp?: number;
vibrate?: number[];
[key: string]: any;
};
fcm_options?: {
link?: string;
analytics_label?: string;
};
}
export interface FCMMessage {
name?: string;
data?: FCMData;
notification?: FCMNotification;
android?: FCMAndroidConfig;
webpush?: FCMWebpushConfig;
apns?: FCMApnsConfig;
fcm_options?: {
analytics_label?: string;
};
token?: string;
topic?: string;
condition?: string;
}
export interface FCMConfig {
projectId: string;
serviceAccountKey: FCMServiceAccountKey | string;
}
export interface FCMResponse {
name?: string;
error?: {
code: number;
message: string;
status: string;
details?: Array<{
[key: string]: any;
}>;
};
}
export interface FCMSendOptions {
message: FCMMessage;
validateOnly?: boolean;
}
declare class FCMv1 {
private projectId;
private serviceAccountKey;
private googleAuth;
constructor(config: FCMConfig);
/**
* Initialize Google Auth client
*/
private initializeAuth;
/**
* Get OAuth2 access token with caching
*/
private getAccessToken;
/**
* Send FCM message
*/
send(options: FCMSendOptions): Promise<FCMResponse>;
/**
* Send message to single token
*/
sendToToken(token: string, messageOptions: Omit<FCMMessage, 'token' | 'topic' | 'condition'>): Promise<FCMResponse>;
/**
* Send message to topic
*/
sendToTopic(topic: string, messageOptions: Omit<FCMMessage, 'token' | 'topic' | 'condition'>): Promise<FCMResponse>;
/**
* Send message to condition
*/
sendToCondition(condition: string, messageOptions: Omit<FCMMessage, 'token' | 'topic' | 'condition'>): Promise<FCMResponse>;
/**
* Send to multiple tokens (sends individual messages)
*/
sendMulticast(tokens: string[], messageOptions: Omit<FCMMessage, 'token' | 'topic' | 'condition'>): Promise<{
responses: FCMResponse[];
successCount: number;
failureCount: number;
}>;
}
/**
* Configure FCM v1 client
*/
export declare const fcmConfig: (config: FCMConfig) => FCMv1;
/**
* Send FCM message using the configured instance
*/
export declare const fcmSend: (options: FCMSendOptions) => Promise<FCMResponse>;
/**
* Send to single token using the configured instance
*/
export declare const fcmSendToToken: (token: string, messageOptions: Omit<FCMMessage, 'token' | 'topic' | 'condition'>) => Promise<FCMResponse>;
/**
* Send to topic using the configured instance
*/
export declare const fcmSendToTopic: (topic: string, messageOptions: Omit<FCMMessage, 'token' | 'topic' | 'condition'>) => Promise<FCMResponse>;
/**
* Send to condition using the configured instance
*/
export declare const fcmSendToCondition: (condition: string, messageOptions: Omit<FCMMessage, 'token' | 'topic' | 'condition'>) => Promise<FCMResponse>;
/**
* Send to multiple tokens using the configured instance
*/
export declare const fcmSendMulticast: (tokens: string[], messageOptions: Omit<FCMMessage, 'token' | 'topic' | 'condition'>) => Promise<{
responses: FCMResponse[];
successCount: number;
failureCount: number;
}>;
export { FCMv1 };
export default FCMv1;