Skip to content

Commit 2fe441f

Browse files
committed
refactor(plugin): remove deprecated subscription properties
1 parent 25eedba commit 2fe441f

5 files changed

Lines changed: 2 additions & 141 deletions

File tree

src/OneSignalPlugin.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ export class OneSignalPlugin implements OneSignalAPI {
4444
initialize(appId: string): Promise<void> {
4545
this._appID = appId;
4646

47-
return this._plugin.initialize({ appId: this._appID }).then(() => {
48-
this.User.pushSubscription._setPropertiesAndObserver();
49-
});
47+
return this._plugin.initialize({ appId: this._appID });
5048
}
5149

5250
/**

src/PushSubscriptionNamespace.test.ts

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -22,73 +22,6 @@ describe('PushSubscription', () => {
2222
expect(pushSubscription).toBeInstanceOf(PushSubscription);
2323
});
2424

25-
describe('id (deprecated)', () => {
26-
test('should set id via getPushSubscriptionId', async () => {
27-
mockPlugin.getPushSubscriptionId.mockResolvedValue({ id: SUB_ID });
28-
pushSubscription._setPropertiesAndObserver();
29-
30-
await vi.waitFor(() => {
31-
expect(pushSubscription.id).toBe(SUB_ID);
32-
});
33-
});
34-
35-
test('should set id via addEventListener', () => {
36-
pushSubscription._setPropertiesAndObserver();
37-
38-
const listener = mockPlugin.addListener.mock.calls.find(
39-
(call) => call[0] === 'pushSubscriptionChange',
40-
)?.[1];
41-
listener?.({ current: { id: SUB_ID, token: SUB_TOKEN, optedIn: true } });
42-
expect(pushSubscription.id).toBe(SUB_ID);
43-
});
44-
});
45-
46-
describe('token (deprecated)', () => {
47-
test('should set token via getPushSubscriptionToken', async () => {
48-
mockPlugin.getPushSubscriptionToken.mockResolvedValue({
49-
token: SUB_TOKEN,
50-
});
51-
pushSubscription._setPropertiesAndObserver();
52-
53-
await vi.waitFor(() => {
54-
expect(pushSubscription.token).toBe(SUB_TOKEN);
55-
});
56-
});
57-
58-
test('should set token via addEventListener', () => {
59-
pushSubscription._setPropertiesAndObserver();
60-
61-
const listener = mockPlugin.addListener.mock.calls.find(
62-
(call) => call[0] === 'pushSubscriptionChange',
63-
)?.[1];
64-
listener?.({ current: { id: SUB_ID, token: SUB_TOKEN, optedIn: true } });
65-
expect(pushSubscription.token).toBe(SUB_TOKEN);
66-
});
67-
});
68-
69-
describe('optedIn (deprecated)', () => {
70-
test('should set optedIn via getPushSubscriptionOptedIn', async () => {
71-
mockPlugin.getPushSubscriptionOptedIn.mockResolvedValue({
72-
optedIn: true,
73-
});
74-
pushSubscription._setPropertiesAndObserver();
75-
76-
await vi.waitFor(() => {
77-
expect(pushSubscription.optedIn).toBe(true);
78-
});
79-
});
80-
81-
test('should set optedIn via addEventListener', () => {
82-
pushSubscription._setPropertiesAndObserver();
83-
84-
const listener = mockPlugin.addListener.mock.calls.find(
85-
(call) => call[0] === 'pushSubscriptionChange',
86-
)?.[1];
87-
listener?.({ current: { id: SUB_ID, token: SUB_TOKEN, optedIn: true } });
88-
expect(pushSubscription.optedIn).toBe(true);
89-
});
90-
});
91-
9225
describe('getIdAsync', () => {
9326
test('should return a Promise', () => {
9427
const promise = pushSubscription.getIdAsync();

src/PushSubscriptionNamespace.ts

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ export interface PushSubscriptionChangedState {
1515

1616
export default class PushSubscription implements OneSignalPushSubscriptionAPI {
1717
private _plugin: OneSignalCapacitorPlugin;
18-
private _id?: string | null;
19-
private _token?: string | null;
20-
private _optedIn?: boolean;
2118

2219
private _subscriptionObserverList: ((event: PushSubscriptionChangedState) => void)[] = [];
2320

@@ -34,60 +31,6 @@ export default class PushSubscription implements OneSignalPushSubscriptionAPI {
3431
}
3532
}
3633

37-
/**
38-
* Sets initial Push Subscription properties and adds observer for changes.
39-
* This internal method is kept to support the deprecated methods {@link id}, {@link token}, {@link optedIn}.
40-
*/
41-
_setPropertiesAndObserver(): void {
42-
void this._plugin.getPushSubscriptionId().then((result) => {
43-
this._id = result.id;
44-
});
45-
46-
void this._plugin.getPushSubscriptionToken().then((result) => {
47-
this._token = result.token;
48-
});
49-
50-
void this._plugin.getPushSubscriptionOptedIn().then((result) => {
51-
this._optedIn = result.optedIn;
52-
});
53-
54-
this.addEventListener('change', (subscriptionChange) => {
55-
this._id = subscriptionChange.current.id;
56-
this._token = subscriptionChange.current.token;
57-
this._optedIn = subscriptionChange.current.optedIn;
58-
});
59-
}
60-
61-
/**
62-
* @deprecated This method is deprecated. It has been replaced by {@link getIdAsync}.
63-
*/
64-
get id(): string | null | undefined {
65-
console.warn(
66-
'OneSignal: This method has been deprecated. Use getIdAsync instead for getting push subscription id.',
67-
);
68-
return this._id;
69-
}
70-
71-
/**
72-
* @deprecated This method is deprecated. It has been replaced by {@link getTokenAsync}.
73-
*/
74-
get token(): string | null | undefined {
75-
console.warn(
76-
'OneSignal: This method has been deprecated. Use getTokenAsync instead for getting push subscription token.',
77-
);
78-
return this._token;
79-
}
80-
81-
/**
82-
* @deprecated This method is deprecated. It has been replaced by {@link getOptedInAsync}.
83-
*/
84-
get optedIn(): boolean {
85-
console.warn(
86-
'OneSignal: This method has been deprecated. Use getOptedInAsync instead for getting push subscription opted in status.',
87-
);
88-
return this._optedIn || false;
89-
}
90-
9134
/**
9235
* The readonly push subscription ID.
9336
* @returns {Promise<string | null>}

src/api.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ export interface OneSignalDebugAPI {
2121
* Push subscription state and controls exposed via `OneSignal.User.pushSubscription`.
2222
*/
2323
export interface OneSignalPushSubscriptionAPI {
24-
/** @deprecated Use {@link getIdAsync} instead. */
25-
readonly id: string | null | undefined;
26-
27-
/** @deprecated Use {@link getTokenAsync} instead. */
28-
readonly token: string | null | undefined;
29-
30-
/** @deprecated Use {@link getOptedInAsync} instead. */
31-
readonly optedIn: boolean;
32-
3324
/** Get the current device's push subscription ID, or null if not yet assigned. */
3425
getIdAsync(): Promise<string | null>;
3526

src/index.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, test, expect, vi, beforeEach } from 'vitest';
1+
import { describe, test, expect, beforeEach } from 'vitest';
22

33
import { createMockPlugin } from '../mocks/capacitor';
44
import { APP_ID } from '../mocks/constants';
@@ -31,10 +31,6 @@ describe('OneSignalPlugin', () => {
3131
await plugin.initialize(APP_ID);
3232

3333
expect(mockPlugin.initialize).toHaveBeenCalledWith({ appId: APP_ID });
34-
35-
await vi.waitFor(() => {
36-
expect(mockPlugin.getPushSubscriptionId).toHaveBeenCalled();
37-
});
3834
});
3935

4036
test('should call plugin for login', async () => {

0 commit comments

Comments
 (0)