Skip to content

Commit 3d65727

Browse files
authored
Merge pull request #90 from OneSignal/fg/export-types
Export Type Declarations
2 parents 8630781 + 36adb83 commit 3d65727

File tree

15 files changed

+924
-446
lines changed

15 files changed

+924
-446
lines changed

.vscode/settings.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
2+
"editor.codeActionsOnSave": {
3+
"source.fixAll.eslint": "explicit",
4+
"source.organizeImports": "always"
5+
},
26
"files.exclude": {
3-
"**/.git": true,
4-
"**/.DS_Store": true,
5-
"**/*.map": true
7+
"**/.git": true,
8+
"**/.DS_Store": true,
9+
"**/*.map": true
610
}
711
}

src/managers/TypingsWriterManager.ts

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { CodeWriter } from "@yellicode/core";
2-
import { IFunctionSignature } from "../models/FunctionSignature";
3-
import IOneSignalApi from "../models/OneSignalApi";
1+
import { CodeWriter } from '@yellicode/core';
2+
import { IFunctionSignature } from '../models/FunctionSignature';
3+
import IOneSignalApi from '../models/OneSignalApi';
44
import {
55
AUTO_PROMPT_OPTIONS,
66
CATEGORY_OPTIONS,
@@ -17,41 +17,48 @@ import {
1717
SLIDEDOWN_EVENT_NAME,
1818
SLIDEDOWN_OPTIONS,
1919
SUBSCRIPTION_CHANGE_EVENT,
20-
TAG_CATEGORY,
20+
TAG_CATEGORY,
2121
USER_CHANGE_EVENT,
22-
USER_NAMESPACE_PROPERTIES} from "../snippets/types";
23-
import { INTERFACE_PREFIX } from "../support/constants";
24-
import { ReaderManager } from "./ReaderManager";
22+
USER_NAMESPACE_PROPERTIES,
23+
} from '../snippets/types';
24+
import { INTERFACE_PREFIX } from '../support/constants';
25+
import { ReaderManager } from './ReaderManager';
2526

2627
export class TypingsWriterManager extends CodeWriter {
2728
public getFunctionSignatureString(sig: IFunctionSignature): string {
28-
let argumentsString = "";
29+
let argumentsString = '';
2930

3031
if (sig.args) {
31-
sig.args.forEach(arg => {
32-
const optionalValue = arg.optional ? "?" : "";
33-
argumentsString = argumentsString + arg.name + optionalValue + ": "+arg.type+", ";
32+
sig.args.forEach((arg) => {
33+
const optionalValue = arg.optional ? '?' : '';
34+
argumentsString =
35+
argumentsString + arg.name + optionalValue + ': ' + arg.type + ', ';
3436
});
3537
argumentsString = argumentsString.trim();
3638
}
37-
return `${sig.name}${sig.genericTypeParameter ?? ''}(${argumentsString.slice(0, -1)}): ${sig.returnType}`;
39+
return `${sig.name}${
40+
sig.genericTypeParameter ?? ''
41+
}(${argumentsString.slice(0, -1)}): ${sig.returnType}`;
3842
}
3943

40-
public writeFunctionTypes(functions: IFunctionSignature[], tabs?: number): void {
44+
public writeFunctionTypes(
45+
functions: IFunctionSignature[],
46+
tabs?: number,
47+
): void {
4148
const prefix = '\t'.repeat(tabs || 1);
42-
[...functions].forEach(func => {
49+
[...functions].forEach((func) => {
4350
this.writeLine(`${prefix}${this.getFunctionSignatureString(func)};`);
4451
});
4552
}
4653

4754
public writeOneSignalInterfaces(api: IOneSignalApi): void {
48-
Object.keys(api).forEach(key => {
55+
Object.keys(api).forEach((key) => {
4956
const namespace = api[key];
5057
const { functions, namespaces, properties } = namespace;
51-
this.writeLine(`interface ${INTERFACE_PREFIX}${key} {`);
58+
this.writeLine(`export interface ${INTERFACE_PREFIX}${key} {`);
5259

5360
if (properties) {
54-
properties.forEach(prop => {
61+
properties.forEach((prop) => {
5562
this.writeLine(`\t${prop.name}: ${prop.type};`);
5663
});
5764
}
@@ -69,7 +76,7 @@ export class TypingsWriterManager extends CodeWriter {
6976

7077
private _writeNamespaces(namespaces: string[], tabs?: number): void {
7178
const prefix = '\t'.repeat(tabs || 1);
72-
namespaces.forEach(namespace => {
79+
namespaces.forEach((namespace) => {
7380
this.writeLine(`${prefix}${namespace}: ${INTERFACE_PREFIX}${namespace};`);
7481
});
7582
}
@@ -79,27 +86,29 @@ export class TypingsWriterManager extends CodeWriter {
7986
* @returns void
8087
*/
8188
public async writeInterfaces(tabs: number): Promise<void> {
82-
const initObjectInterfaceContents = await ReaderManager.readFile(__dirname.replace('ts-to-es6/', '') + `/../snippets/InitObject.ts`);
89+
const initObjectInterfaceContents = await ReaderManager.readFile(
90+
__dirname.replace('ts-to-es6/', '') + `/../snippets/InitObject.ts`,
91+
);
8392

84-
const prefix = "\t".repeat(tabs);
85-
this.writeLine(prefix+AUTO_PROMPT_OPTIONS);
86-
this.writeLine(prefix+SLIDEDOWN_OPTIONS);
87-
this.writeLine(prefix+CATEGORY_OPTIONS);
88-
this.writeLine(prefix+TAG_CATEGORY);
89-
this.writeLine(prefix+PUSH_SUBSCRIPTION_NAMESPACE_PROPERTIES);
90-
this.writeLine(prefix+SUBSCRIPTION_CHANGE_EVENT);
91-
this.writeLine(prefix+NOTIFICATION_EVENT_NAME);
92-
this.writeLine(prefix+SLIDEDOWN_EVENT_NAME);
93-
this.writeLine(prefix+ONESIGNAL_DEFERRED_CALLBACK);
94-
this.writeLine(prefix+OS_NOTIFICATION);
95-
this.writeLine(prefix+NOTIFICATION_BUTTON_ACTION_BUTTON);
96-
this.writeLine(prefix+NOTIFICATION_CLICK_RESULT);
97-
this.writeLine(prefix+NOTIFICATION_EVENT_TYPE_MAP);
98-
this.writeLine(prefix+NOTIFICATION_FOREGROUND_WILL_DISPLAY_EVENT);
99-
this.writeLine(prefix+NOTIFICATION_DISMISS_EVENT);
100-
this.writeLine(prefix+NOTIFICATION_CLICK_EVENT);
101-
this.writeLine(prefix+USER_CHANGE_EVENT);
102-
this.writeLine(prefix+USER_NAMESPACE_PROPERTIES);
93+
const prefix = '\t'.repeat(tabs);
94+
this.writeLine(prefix + AUTO_PROMPT_OPTIONS);
95+
this.writeLine(prefix + SLIDEDOWN_OPTIONS);
96+
this.writeLine(prefix + CATEGORY_OPTIONS);
97+
this.writeLine(prefix + TAG_CATEGORY);
98+
this.writeLine(prefix + PUSH_SUBSCRIPTION_NAMESPACE_PROPERTIES);
99+
this.writeLine(prefix + SUBSCRIPTION_CHANGE_EVENT);
100+
this.writeLine(prefix + NOTIFICATION_EVENT_NAME);
101+
this.writeLine(prefix + SLIDEDOWN_EVENT_NAME);
102+
this.writeLine(prefix + ONESIGNAL_DEFERRED_CALLBACK);
103+
this.writeLine(prefix + OS_NOTIFICATION);
104+
this.writeLine(prefix + NOTIFICATION_BUTTON_ACTION_BUTTON);
105+
this.writeLine(prefix + NOTIFICATION_CLICK_RESULT);
106+
this.writeLine(prefix + NOTIFICATION_EVENT_TYPE_MAP);
107+
this.writeLine(prefix + NOTIFICATION_FOREGROUND_WILL_DISPLAY_EVENT);
108+
this.writeLine(prefix + NOTIFICATION_DISMISS_EVENT);
109+
this.writeLine(prefix + NOTIFICATION_CLICK_EVENT);
110+
this.writeLine(prefix + USER_CHANGE_EVENT);
111+
this.writeLine(prefix + USER_NAMESPACE_PROPERTIES);
103112
this.writeLine();
104113
this.writeLine(initObjectInterfaceContents);
105114
}

src/scaffolds/angular-workspace/projects/onesignal-ngx/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "onesignal-ngx",
33
"version": "2.1.0",
44
"description": "This is a JavaScript module that can be used to easily include OneSignal code in a website or app that uses Angular for its front-end codebase.",
5-
"author": "rgomezp",
65
"contributors": [
76
{
87
"name": "Rodrigo Gomez-Palacio"

src/scaffolds/angular-workspace/projects/onesignal-ngx/src/lib/onesignal-ngx.service.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
interface AutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; slidedownPromptOptions?: IOneSignalAutoPromptOptions; }
2-
interface IOneSignalAutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; isInUpdateMode?: boolean; categoryOptions?: IOneSignalCategories; }
3-
interface IOneSignalCategories { positiveUpdateButton: string; negativeUpdateButton: string; savingButtonText: string; errorButtonText: string; updateMessage: string; tags: IOneSignalTagCategory[]; }
4-
interface IOneSignalTagCategory { tag: string; label: string; checked?: boolean; }
5-
type PushSubscriptionNamespaceProperties = { id: string | null | undefined; token: string | null | undefined; optedIn: boolean; };
6-
type SubscriptionChangeEvent = { previous: PushSubscriptionNamespaceProperties; current: PushSubscriptionNamespaceProperties; };
7-
type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay';
8-
type SlidedownEventName = 'slidedownShown';
9-
type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void;
10-
interface IOSNotification {
1+
export interface AutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; slidedownPromptOptions?: IOneSignalAutoPromptOptions; }
2+
export interface IOneSignalAutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; isInUpdateMode?: boolean; categoryOptions?: IOneSignalCategories; }
3+
export interface IOneSignalCategories { positiveUpdateButton: string; negativeUpdateButton: string; savingButtonText: string; errorButtonText: string; updateMessage: string; tags: IOneSignalTagCategory[]; }
4+
export interface IOneSignalTagCategory { tag: string; label: string; checked?: boolean; }
5+
export type PushSubscriptionNamespaceProperties = { id: string | null | undefined; token: string | null | undefined; optedIn: boolean; };
6+
export type SubscriptionChangeEvent = { previous: PushSubscriptionNamespaceProperties; current: PushSubscriptionNamespaceProperties; };
7+
export type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay';
8+
export type SlidedownEventName = 'slidedownShown';
9+
export type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void;
10+
export interface IOSNotification {
1111
/**
1212
* The OneSignal notification id;
1313
* - Primary id on OneSignal's REST API and dashboard
@@ -69,7 +69,7 @@ interface IOSNotification {
6969
readonly confirmDelivery: boolean;
7070
}
7171

72-
interface IOSNotificationActionButton {
72+
export interface IOSNotificationActionButton {
7373
/**
7474
* Any unique identifier to represent which button was clicked. This is typically passed back to the service worker
7575
* and host page through events to identify which button was clicked.
@@ -90,42 +90,42 @@ interface IOSNotificationActionButton {
9090
readonly launchURL?: string;
9191
}
9292

93-
interface NotificationClickResult {
93+
export interface NotificationClickResult {
9494
readonly actionId?: string;
9595
readonly url?: string;
9696
}
9797

98-
type NotificationEventTypeMap = {
98+
export type NotificationEventTypeMap = {
9999
'click': NotificationClickEvent;
100100
'foregroundWillDisplay': NotificationForegroundWillDisplayEvent;
101101
'dismiss': NotificationDismissEvent;
102102
'permissionChange': boolean;
103103
'permissionPromptDisplay': void;
104104
};
105105

106-
interface NotificationForegroundWillDisplayEvent {
106+
export interface NotificationForegroundWillDisplayEvent {
107107
readonly notification: IOSNotification;
108108
preventDefault(): void;
109109
}
110110

111-
interface NotificationDismissEvent {
111+
export interface NotificationDismissEvent {
112112
notification: IOSNotification;
113113
}
114114

115-
interface NotificationClickEvent {
115+
export interface NotificationClickEvent {
116116
readonly notification: IOSNotification;
117117
readonly result: NotificationClickResult;
118118
}
119119

120-
type UserChangeEvent = {
120+
export type UserChangeEvent = {
121121
current: UserNamespaceProperties;
122122
};
123-
type UserNamespaceProperties = {
123+
export type UserNamespaceProperties = {
124124
onesignalId: string | undefined;
125125
externalId: string | undefined;
126126
};
127127

128-
interface IInitObject {
128+
export interface IInitObject {
129129
appId: string;
130130
subdomainName?: string;
131131
requiresUserPrivacyConsent?: boolean;
@@ -147,7 +147,7 @@ interface IInitObject {
147147
[key: string]: any;
148148
}
149149

150-
interface IOneSignalOneSignal {
150+
export interface IOneSignalOneSignal {
151151
Slidedown: IOneSignalSlidedown;
152152
Notifications: IOneSignalNotifications;
153153
Session: IOneSignalSession;
@@ -159,7 +159,7 @@ interface IOneSignalOneSignal {
159159
setConsentGiven(consent: boolean): Promise<void>;
160160
setConsentRequired(requiresConsent: boolean): Promise<void>;
161161
}
162-
interface IOneSignalNotifications {
162+
export interface IOneSignalNotifications {
163163
permissionNative: NotificationPermission;
164164
permission: boolean;
165165
setDefaultUrl(url: string): Promise<void>;
@@ -169,7 +169,7 @@ interface IOneSignalNotifications {
169169
addEventListener<K extends NotificationEventName>(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void;
170170
removeEventListener<K extends NotificationEventName>(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void;
171171
}
172-
interface IOneSignalSlidedown {
172+
export interface IOneSignalSlidedown {
173173
promptPush(options?: AutoPromptOptions): Promise<void>;
174174
promptPushCategories(options?: AutoPromptOptions): Promise<void>;
175175
promptSms(options?: AutoPromptOptions): Promise<void>;
@@ -178,14 +178,14 @@ interface IOneSignalSlidedown {
178178
addEventListener(event: SlidedownEventName, listener: (wasShown: boolean) => void): void;
179179
removeEventListener(event: SlidedownEventName, listener: (wasShown: boolean) => void): void;
180180
}
181-
interface IOneSignalDebug {
181+
export interface IOneSignalDebug {
182182
setLogLevel(logLevel: string): void;
183183
}
184-
interface IOneSignalSession {
184+
export interface IOneSignalSession {
185185
sendOutcome(outcomeName: string, outcomeWeight?: number): Promise<void>;
186186
sendUniqueOutcome(outcomeName: string): Promise<void>;
187187
}
188-
interface IOneSignalUser {
188+
export interface IOneSignalUser {
189189
onesignalId: string | undefined;
190190
externalId: string | undefined;
191191
PushSubscription: IOneSignalPushSubscription;
@@ -207,7 +207,7 @@ interface IOneSignalUser {
207207
setLanguage(language: string): void;
208208
getLanguage(): string;
209209
}
210-
interface IOneSignalPushSubscription {
210+
export interface IOneSignalPushSubscription {
211211
id: string | null | undefined;
212212
token: string | null | undefined;
213213
optedIn: boolean | undefined;
@@ -705,7 +705,7 @@ declare global {
705705
}
706706
}
707707

708-
interface IOneSignalOneSignal {
708+
export interface IOneSignalOneSignal {
709709
[key: string]: any;
710710
}
711711

src/snippets/InitObject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
interface IInitObject {
1+
export interface IInitObject {
22
appId: string;
33
subdomainName?: string;
44
requiresUserPrivacyConsent?: boolean;

src/snippets/angular/support.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ declare global {
8181
}
8282
}
8383

84-
interface IOneSignalOneSignal {
84+
export interface IOneSignalOneSignal {
8585
[key: string]: any;
8686
}
8787

src/snippets/types.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
export const AUTO_PROMPT_OPTIONS = `interface AutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; slidedownPromptOptions?: IOneSignalAutoPromptOptions; }`;
2-
export const SLIDEDOWN_OPTIONS = `interface IOneSignalAutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; isInUpdateMode?: boolean; categoryOptions?: IOneSignalCategories; }`;
3-
export const CATEGORY_OPTIONS = `interface IOneSignalCategories { positiveUpdateButton: string; negativeUpdateButton: string; savingButtonText: string; errorButtonText: string; updateMessage: string; tags: IOneSignalTagCategory[]; }`;
4-
export const TAG_CATEGORY = `interface IOneSignalTagCategory { tag: string; label: string; checked?: boolean; }`;
5-
export const PUSH_SUBSCRIPTION_NAMESPACE_PROPERTIES = `type PushSubscriptionNamespaceProperties = { id: string | null | undefined; token: string | null | undefined; optedIn: boolean; };`;
6-
export const SUBSCRIPTION_CHANGE_EVENT = `type SubscriptionChangeEvent = { previous: PushSubscriptionNamespaceProperties; current: PushSubscriptionNamespaceProperties; };`;
7-
export const NOTIFICATION_EVENT_NAME = `type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay';`
8-
export const NOTIFICATION_BUTTON_ACTION_BUTTON = `interface IOSNotificationActionButton {
1+
export const AUTO_PROMPT_OPTIONS = `export interface AutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; slidedownPromptOptions?: IOneSignalAutoPromptOptions; }`;
2+
export const SLIDEDOWN_OPTIONS = `export interface IOneSignalAutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; isInUpdateMode?: boolean; categoryOptions?: IOneSignalCategories; }`;
3+
export const CATEGORY_OPTIONS = `export interface IOneSignalCategories { positiveUpdateButton: string; negativeUpdateButton: string; savingButtonText: string; errorButtonText: string; updateMessage: string; tags: IOneSignalTagCategory[]; }`;
4+
export const TAG_CATEGORY = `export interface IOneSignalTagCategory { tag: string; label: string; checked?: boolean; }`;
5+
export const PUSH_SUBSCRIPTION_NAMESPACE_PROPERTIES = `export type PushSubscriptionNamespaceProperties = { id: string | null | undefined; token: string | null | undefined; optedIn: boolean; };`;
6+
export const SUBSCRIPTION_CHANGE_EVENT = `export type SubscriptionChangeEvent = { previous: PushSubscriptionNamespaceProperties; current: PushSubscriptionNamespaceProperties; };`;
7+
export const NOTIFICATION_EVENT_NAME = `export type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay';`;
8+
export const NOTIFICATION_BUTTON_ACTION_BUTTON = `export interface IOSNotificationActionButton {
99
/**
1010
* Any unique identifier to represent which button was clicked. This is typically passed back to the service worker
1111
* and host page through events to identify which button was clicked.
@@ -25,10 +25,10 @@ export const NOTIFICATION_BUTTON_ACTION_BUTTON = `interface IOSNotificationActio
2525
*/
2626
readonly launchURL?: string;
2727
}
28-
`
29-
export const SLIDEDOWN_EVENT_NAME = `type SlidedownEventName = 'slidedownShown';`;
30-
export const ONESIGNAL_DEFERRED_CALLBACK = `type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void;`;
31-
export const OS_NOTIFICATION = `interface IOSNotification {
28+
`;
29+
export const SLIDEDOWN_EVENT_NAME = `export type SlidedownEventName = 'slidedownShown';`;
30+
export const ONESIGNAL_DEFERRED_CALLBACK = `export type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void;`;
31+
export const OS_NOTIFICATION = `export interface IOSNotification {
3232
/**
3333
* The OneSignal notification id;
3434
* - Primary id on OneSignal's REST API and dashboard
@@ -90,37 +90,37 @@ export const OS_NOTIFICATION = `interface IOSNotification {
9090
readonly confirmDelivery: boolean;
9191
}
9292
`;
93-
export const NOTIFICATION_CLICK_RESULT = `interface NotificationClickResult {
93+
export const NOTIFICATION_CLICK_RESULT = `export interface NotificationClickResult {
9494
readonly actionId?: string;
9595
readonly url?: string;
9696
}
9797
`;
98-
export const NOTIFICATION_FOREGROUND_WILL_DISPLAY_EVENT = `interface NotificationForegroundWillDisplayEvent {
98+
export const NOTIFICATION_FOREGROUND_WILL_DISPLAY_EVENT = `export interface NotificationForegroundWillDisplayEvent {
9999
readonly notification: IOSNotification;
100100
preventDefault(): void;
101101
}
102102
`;
103-
export const NOTIFICATION_EVENT_TYPE_MAP = `type NotificationEventTypeMap = {
103+
export const NOTIFICATION_EVENT_TYPE_MAP = `export type NotificationEventTypeMap = {
104104
'click': NotificationClickEvent;
105105
'foregroundWillDisplay': NotificationForegroundWillDisplayEvent;
106106
'dismiss': NotificationDismissEvent;
107107
'permissionChange': boolean;
108108
'permissionPromptDisplay': void;
109109
};
110110
`;
111-
export const NOTIFICATION_DISMISS_EVENT = `interface NotificationDismissEvent {
111+
export const NOTIFICATION_DISMISS_EVENT = `export interface NotificationDismissEvent {
112112
notification: IOSNotification;
113113
}
114114
`;
115-
export const NOTIFICATION_CLICK_EVENT = `interface NotificationClickEvent {
115+
export const NOTIFICATION_CLICK_EVENT = `export interface NotificationClickEvent {
116116
readonly notification: IOSNotification;
117117
readonly result: NotificationClickResult;
118118
}
119119
`;
120-
export const USER_CHANGE_EVENT = `type UserChangeEvent = {
120+
export const USER_CHANGE_EVENT = `export type UserChangeEvent = {
121121
current: UserNamespaceProperties;
122122
};`;
123-
export const USER_NAMESPACE_PROPERTIES = `type UserNamespaceProperties = {
123+
export const USER_NAMESPACE_PROPERTIES = `export type UserNamespaceProperties = {
124124
onesignalId: string | undefined;
125125
externalId: string | undefined;
126126
};`;
File renamed without changes.

0 commit comments

Comments
 (0)