@gapi/onesignal-notifications 1.8.122

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ export const Constants = {
2
+ API_ROOT: 'https://onesignal.com/api/v1',
3
+
4
+ /** PATHS **/
5
+ NOTIFICATIONS_PATH: '/notifications',
6
+ APPS_PATH: '/apps',
7
+ DEVICES_PATH: '/players',
8
+ };
package/src/index.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { Container, Module, ModuleWithServices } from '@rxdi/core';
2
+
3
+ import { OneSignalClientService } from './client';
4
+ import { OneSignalConfig } from './onesignal.config';
5
+
6
+ @Module()
7
+ export class OneSignalModule {
8
+ static forRoot(config: OneSignalConfig): ModuleWithServices {
9
+ Container.set(OneSignalClientService, new OneSignalClientService(config));
10
+ return {
11
+ module: OneSignalModule,
12
+ };
13
+ }
14
+ }
15
+
16
+ export * from './notification';
17
+ export * from './client';
18
+ export * from './interfaces/index';
@@ -0,0 +1,21 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { SendNotificationResponse } from './notificationResponse';
3
+
4
+ export interface OneSignalClient {
5
+ setRootUrl(rootUrl: string): void;
6
+ setApp(app): void;
7
+ sendNotification(notification, callback?): Promise<SendNotificationResponse>;
8
+ cancelNotification(notificationId, callback): Promise<any>;
9
+ viewNotification(notificationId, callback): Promise<any>;
10
+ viewNotifications(query, callback): Promise<any>;
11
+ viewApps(callback): Promise<any>;
12
+ viewApp(appId, callback): Promise<any>;
13
+ createApp(body, callback): Promise<any>;
14
+ updateApp(body, callback): Promise<any>;
15
+ viewDevices(query, callback): Promise<any>;
16
+ viewDevice(deviceId, callback): Promise<any>;
17
+ addDevice(body, callback): Promise<any>;
18
+ editDevice(deviceId, body, callback): Promise<any>;
19
+ trackOpen(notificationId, body, callback): Promise<any>;
20
+ csvExport(body, callback): Promise<any>;
21
+ }
@@ -0,0 +1,4 @@
1
+ export * from './client';
2
+ export * from './notificationDataResponse';
3
+ export * from './notificationHttpResponse';
4
+ export * from './notificationResponse';
@@ -0,0 +1,4 @@
1
+ export interface SendNotificationDataResponse {
2
+ id: string;
3
+ recipients: number;
4
+ }
@@ -0,0 +1,40 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { Domain } from 'domain';
3
+ import { ClientRequest } from 'http';
4
+ import { TLSSocket } from 'tls';
5
+
6
+ import { SendNotificationDataResponse } from './notificationDataResponse';
7
+
8
+ export interface SendNotificationHttpResponse {
9
+ _consuming: boolean;
10
+ _dumped: boolean;
11
+ _events: any;
12
+ _eventsCount: number;
13
+ _maxListeners: number;
14
+ _readableState: any;
15
+ body: SendNotificationDataResponse;
16
+ caseless: { dict: Record<string, any> };
17
+ client: TLSSocket;
18
+ complete: true;
19
+ connection: TLSSocket;
20
+ destroyed: boolean;
21
+ domain: Domain;
22
+ headers: Record<string, any>;
23
+ httpVersion: string;
24
+ httpVersionMajor: number;
25
+ httpVersionMinor: number;
26
+ method: any;
27
+ rawHeaders: Array<{ [key: string]: string }>;
28
+ rawTrailers: Array<any>;
29
+ read: Function;
30
+ readable: boolean;
31
+ req: ClientRequest;
32
+ request: Request;
33
+ socket: TLSSocket;
34
+ statusCode: number;
35
+ statusMessage: string;
36
+ toJSON: Function;
37
+ trailers: Record<string, any>;
38
+ upgrade: boolean;
39
+ url: string;
40
+ }
@@ -0,0 +1,7 @@
1
+ import { SendNotificationDataResponse } from './notificationDataResponse';
2
+ import { SendNotificationHttpResponse } from './notificationHttpResponse';
3
+
4
+ export interface SendNotificationResponse {
5
+ data: SendNotificationDataResponse;
6
+ httpResponse: SendNotificationHttpResponse;
7
+ }
@@ -0,0 +1,171 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ const ALLOWED_FIELDS = [
3
+ 'contents',
4
+ 'included_segments',
5
+ 'excluded_segments',
6
+ 'filters',
7
+ 'include_player_ids',
8
+ 'app_id',
9
+ 'app_ids',
10
+ 'headings',
11
+ 'subtitle',
12
+ 'template_id',
13
+ 'content_available',
14
+ 'mutable_content',
15
+ 'data',
16
+ 'url',
17
+ 'ios_attachments',
18
+ 'big_picture',
19
+ 'adm_big_picture',
20
+ 'chrome_big_picture',
21
+ 'buttons',
22
+ 'web_buttons',
23
+ 'ios_category',
24
+ 'android_background_layout',
25
+ 'small_icon',
26
+ 'large_icon',
27
+ 'adm_small_icon',
28
+ 'adm_large_icon',
29
+ 'chrome_web_icon',
30
+ 'chrome_web_image',
31
+ 'firefox_icon',
32
+ 'chrome_icon',
33
+ 'ios_sound',
34
+ 'android_sound',
35
+ 'android_led_color',
36
+ 'android_accent_color',
37
+ 'android_visibility',
38
+ 'adm_sound',
39
+ 'ios_badgeType',
40
+ 'ios_badgeCount',
41
+ 'collapse_id',
42
+ 'send_after',
43
+ 'delayed_option',
44
+ 'delivery_time_of_day',
45
+ 'ttl',
46
+ 'priority',
47
+ 'android_group',
48
+ 'android_group_message',
49
+ 'adm_group',
50
+ 'adm_group_message',
51
+ 'isIos',
52
+ 'isAndroid',
53
+ 'isAnyWeb',
54
+ 'isChromeWeb',
55
+ 'isFirefox',
56
+ 'isSafari',
57
+ 'isWP',
58
+ 'isWP_WNS',
59
+ 'isAdm',
60
+ 'isChrome',
61
+ 'android_channel_id',
62
+ 'existing_android_channel_id',
63
+ ];
64
+
65
+ export interface PostBody {
66
+ contents: {
67
+ [key: string]: string;
68
+ };
69
+ data: any;
70
+ content_available: any;
71
+ template_id: any;
72
+ included_segments: any;
73
+ excluded_segments: any;
74
+ filters: any;
75
+ app_ids;
76
+ app_id;
77
+ include_player_ids: string[];
78
+ }
79
+
80
+ interface ClientNotification {
81
+ postBody: PostBody;
82
+ setContent(contents): void;
83
+ setExcludedSegments(excludedSegments: string[]): void;
84
+ setFilters(filters: string): void;
85
+ setIncludedSegments(includedSegments: string[]): void;
86
+ setParameter(name: string, value: any): void;
87
+ setTargetDevices(include_player_ids: string[]): void;
88
+ }
89
+
90
+ export class Notification {
91
+ public initialBody: {
92
+ contents?: any;
93
+ content_available?: any;
94
+ template_id?: any;
95
+ };
96
+ public postBody: PostBody;
97
+ public allowed_fields: string[] = ALLOWED_FIELDS;
98
+
99
+ constructor(initialBody: {
100
+ contents?: any;
101
+ content_available?: any;
102
+ template_id?: any;
103
+ }) {
104
+ this.initialBody = initialBody;
105
+ this.postBody = {} as never;
106
+
107
+ if (initialBody.constructor !== Object) {
108
+ throw new Error('Body must be a JSON object');
109
+ }
110
+
111
+ if ('contents' in initialBody) {
112
+ this.postBody.contents = this.initialBody.contents;
113
+ return;
114
+ }
115
+
116
+ if ('content_available' in initialBody) {
117
+ this.postBody.content_available = this.initialBody.content_available;
118
+ return;
119
+ }
120
+
121
+ if ('template_id' in initialBody) {
122
+ this.postBody.template_id = this.initialBody.template_id;
123
+ return;
124
+ }
125
+
126
+ throw new Error(
127
+ 'Body must include one of the following fields: contents, content_available, template_id'
128
+ );
129
+ }
130
+
131
+ setParameter(name: string, value) {
132
+ if (name && name[0] === '!') {
133
+ name = name.substring(1);
134
+ } else if (ALLOWED_FIELDS.indexOf(name) === -1) {
135
+ throw new Error(
136
+ '"' +
137
+ name +
138
+ '" is not present in documentation. You should add a ' +
139
+ 'exclamation mark to the begging of the name, if you want to set it : !' +
140
+ name
141
+ );
142
+ }
143
+ this.postBody[name] = value;
144
+ return this;
145
+ }
146
+
147
+ setContent(contents) {
148
+ this.postBody.contents = contents;
149
+ return this;
150
+ }
151
+
152
+ setIncludedSegments<T>(included_segments: T[]) {
153
+ this.postBody.included_segments = included_segments;
154
+ return this;
155
+ }
156
+
157
+ setExcludedSegments<T>(excluded_segments: T[]) {
158
+ this.postBody.excluded_segments = excluded_segments;
159
+ return this;
160
+ }
161
+
162
+ setFilters(filters: any) {
163
+ this.postBody.filters = filters;
164
+ return this;
165
+ }
166
+
167
+ setTargetDevices(include_player_ids: string[]) {
168
+ this.postBody.include_player_ids = include_player_ids;
169
+ return this;
170
+ }
171
+ }
@@ -0,0 +1,7 @@
1
+ export class OneSignalConfig {
2
+ userAuthKey: string;
3
+ app: {
4
+ appAuthKey: string;
5
+ appId: string;
6
+ };
7
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "module": "commonjs",
5
+ "target": "es6",
6
+ "baseUrl": ".",
7
+ "stripInternal": true,
8
+ "emitDecoratorMetadata": true,
9
+ "experimentalDecorators": true,
10
+ "moduleResolution": "node",
11
+ "outDir": "dist",
12
+ "rootDir": "./src",
13
+ "lib": [
14
+ "es2017",
15
+ "es2016",
16
+ "es2015",
17
+ "es6",
18
+ "dom",
19
+ "esnext.asynciterable"
20
+ ],
21
+ "skipLibCheck": true,
22
+ "types": [
23
+ "node"
24
+ ],
25
+ "typeRoots": [
26
+ "node_modules/"
27
+ ]
28
+ },
29
+ "angularCompilerOptions": {
30
+ "annotateForClosureCompiler": true,
31
+ "strictMetadataEmit": true,
32
+ "skipTemplateCodegen": true,
33
+ "flatModuleOutFile": "gapi-amqp.js",
34
+ "flatModuleId": "gapi-amqp"
35
+ },
36
+ "files": [
37
+ "./src/index.ts"
38
+ ]
39
+ }