Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"oxc.oxc-vscode",
"esbenp.prettier-vscode",
"redhat.vscode-yaml"
]
}
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[yaml]": {
"editor.defaultFormatter": "redhat.vscode-yaml"
}
}
932 changes: 910 additions & 22 deletions bun.lock

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
"types": "dist/index.d.ts",
"scripts": {
"prepare": "bun run build",
"build": "tsc",
"build": "tsc --noEmit && vite build",
"lint": "oxlint src examples && prettier --check src examples",
"lint:fix": "oxlint src examples --fix && prettier --write src examples"
},
"dependencies": {
"invariant": "^2.2.2"
"invariant": "^2.2.4"
},
"devDependencies": {
"@types/invariant": "^2.2.2",
"@types/react-native": "^0.66.8",
"oxlint": "^1.24.0",
"prettier": "^2.7.1",
"typescript": "^3.8.3"
"@types/invariant": "^2.2.37",
"@types/react-native": "^0.73.0",
"oxlint": "^1.26.0",
"prettier": "^3.6.2",
"typescript": "^5.9.3",
"vite": "^7.2.0",
"vite-plugin-dts": "^4.5.4"
},
"keywords": [
"react-component",
Expand Down
4 changes: 2 additions & 2 deletions src/events/EventManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
EmitterSubscription,
type EmitterSubscription,
NativeEventEmitter,
NativeModule,
type NativeModule,
} from 'react-native';
import OSNotification from '../OSNotification';
import NotificationWillDisplayEvent from './NotificationWillDisplayEvent';
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import invariant from 'invariant';
import { NativeModule } from 'react-native';
import type { NativeModule } from 'react-native';

export function isValidCallback(handler: Function) {
invariant(typeof handler === 'function', 'Must provide a valid callback');
Expand Down
70 changes: 35 additions & 35 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ import {
SUBSCRIPTION_CHANGED,
USER_STATE_CHANGED,
} from './events/events';
import {
NotificationEventName,
NotificationEventTypeMap,
NotificationClickEvent,
} from './models/NotificationEvents';
import {
PushSubscriptionState,
OSNotificationPermission,
PushSubscriptionChangedState,
} from './models/Subscription';
import { UserState, UserChangedState } from './models/User';
import NotificationWillDisplayEvent from './events/NotificationWillDisplayEvent';
import { LiveActivitySetupOptions } from './models/LiveActivities';
import {
import { isNativeModuleLoaded, isValidCallback } from './helpers';
import type {
InAppMessage,
InAppMessageEventTypeMap,
InAppMessageEventName,
InAppMessageClickEvent,
InAppMessageWillDisplayEvent,
InAppMessageDidDismissEvent,
InAppMessageDidDisplayEvent,
InAppMessageEventName,
InAppMessageEventTypeMap,
InAppMessageWillDismissEvent,
InAppMessageDidDismissEvent,
InAppMessageWillDisplayEvent,
} from './models/InAppMessage';
import { isValidCallback, isNativeModuleLoaded } from './helpers';
import type { LiveActivitySetupOptions } from './models/LiveActivities';
import type {
NotificationClickEvent,
NotificationEventName,
NotificationEventTypeMap,
} from './models/NotificationEvents';
import {
OSNotificationPermission,
type PushSubscriptionChangedState,
type PushSubscriptionState,
} from './models/Subscription';
import type { UserChangedState, UserState } from './models/User';

const RNOneSignal = NativeModules.OneSignal;
const eventManager = new EventManager(RNOneSignal);
Expand Down Expand Up @@ -288,7 +288,7 @@ export namespace OneSignal {
export namespace pushSubscription {
/** Add a callback that fires when the OneSignal subscription state changes. */
export function addEventListener(
event: 'change',
_event: 'change',
listener: (event: PushSubscriptionChangedState) => void,
) {
if (!isNativeModuleLoaded(RNOneSignal)) return;
Expand All @@ -303,7 +303,7 @@ export namespace OneSignal {

/** Clears current subscription observers. */
export function removeEventListener(
event: 'change',
_event: 'change',
listener: (event: PushSubscriptionChangedState) => void,
) {
if (!isNativeModuleLoaded(RNOneSignal)) return;
Expand Down Expand Up @@ -410,7 +410,7 @@ export namespace OneSignal {
* Important: When using the observer to retrieve the onesignalId, check the externalId as well to confirm the values are associated with the expected user.
*/
export function addEventListener(
event: 'change',
_event: 'change',
listener: (event: UserChangedState) => void,
) {
if (!isNativeModuleLoaded(RNOneSignal)) return;
Expand All @@ -425,7 +425,7 @@ export namespace OneSignal {

/** Clears current user state observers. */
export function removeEventListener(
event: 'change',
_event: 'change',
listener: (event: UserChangedState) => void,
) {
if (!isNativeModuleLoaded(RNOneSignal)) return;
Expand Down Expand Up @@ -1002,20 +1002,20 @@ export namespace OneSignal {

export {
NotificationWillDisplayEvent,
NotificationClickEvent,
InAppMessage,
InAppMessageClickEvent,
InAppMessageWillDisplayEvent,
InAppMessageDidDisplayEvent,
InAppMessageWillDismissEvent,
InAppMessageDidDismissEvent,
PushSubscriptionState,
PushSubscriptionChangedState,
UserState,
UserChangedState,
OSNotificationPermission,
type InAppMessage,
type InAppMessageClickEvent,
type InAppMessageDidDismissEvent,
type InAppMessageDidDisplayEvent,
type InAppMessageWillDismissEvent,
type InAppMessageWillDisplayEvent,
type NotificationClickEvent,
type PushSubscriptionChangedState,
type PushSubscriptionState,
type UserChangedState,
type UserState,
};

export type { InAppMessageClickResult } from './models/InAppMessage';
export type { NotificationClickResult } from './models/NotificationEvents';
export { default as OSNotification } from './OSNotification';
export { NotificationClickResult } from './models/NotificationEvents';
export { InAppMessageClickResult } from './models/InAppMessage';
19 changes: 12 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
{
"compilerOptions": {
"outDir": "dist",
"target": "es5",
"moduleResolution": "node",
"target": "es2020",
"module": "esnext",
"moduleResolution": "bundler",
"noImplicitAny": true,
"lib": ["es6"],
"rootDir": "src",
"declaration": true,
"allowSyntheticDefaultImports": true,
"lib": ["es2020"],
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"strict": true,
"noUnusedLocals": true
"noUnusedLocals": true,
"noUnusedParameters": true,

/**
* Should use import type syntax instead of regular import when getting types/interfaces from a module
*/
"verbatimModuleSyntax": true
},
"exclude": ["node_modules", "dist", "android", "examples", "ios"]
}
18 changes: 18 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';

export default defineConfig({
plugins: [dts({ exclude: ['**/*.test.ts'], rollupTypes: true })],
build: {
outDir: 'dist',
emptyOutDir: true,
lib: {
entry: 'src/index.ts',
formats: ['es'],
fileName: () => 'index.js',
},
rollupOptions: {
external: ['react-native'],
},
},
});
Loading