Skip to content

Commit 1d032bd

Browse files
committed
feat(fcm): Rename apns.live_activity_token to lowerCamelCase
1 parent 6b5079e commit 1d032bd

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

etc/firebase-admin.messaging.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export interface ApnsConfig {
6161
headers?: {
6262
[key: string]: string;
6363
};
64-
live_activity_token?: string;
64+
liveActivityToken?: string;
6565
payload?: ApnsPayload;
6666
}
6767

src/messaging/messaging-api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,9 @@ export interface WebpushNotification {
242242
*/
243243
export interface ApnsConfig {
244244
/**
245-
* APN `live_activity_push_to_start_token` or `live_activity_push_token` to start or update live activities.
245+
* APN `pushToStartToken` or `pushToken` to start or update live activities.
246246
*/
247-
live_activity_token?: string;
247+
liveActivityToken?: string;
248248
/**
249249
* A collection of APNs headers. Header values must be strings.
250250
*/

src/messaging/messaging-internal.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,24 +123,30 @@ function validateApnsConfig(config: ApnsConfig | undefined): void {
123123
throw new FirebaseMessagingError(
124124
MessagingClientErrorCode.INVALID_PAYLOAD, 'apns must be a non-null object');
125125
}
126-
validateApnsLiveActivityToken(config.live_activity_token);
126+
validateApnsLiveActivityToken(config.liveActivityToken);
127127
validateStringMap(config.headers, 'apns.headers');
128128
validateApnsPayload(config.payload);
129129
validateApnsFcmOptions(config.fcmOptions);
130+
131+
const propertyMappings = {
132+
liveActivityToken: 'live_activity_token'
133+
}
134+
135+
renameProperties(config, propertyMappings)
130136
}
131137

132-
function validateApnsLiveActivityToken(liveActivityToken: ApnsConfig['live_activity_token']): void {
138+
function validateApnsLiveActivityToken(liveActivityToken: ApnsConfig['liveActivityToken']): void {
133139
if (typeof liveActivityToken === 'undefined') {
134140
return;
135141
} else if (!validator.isString(liveActivityToken)) {
136142
throw new FirebaseMessagingError(
137143
MessagingClientErrorCode.INVALID_PAYLOAD,
138-
'apns.live_activity_token must be a string value',
144+
'apns.liveActivityToken must be a string value',
139145
);
140146
} else if (!validator.isNonEmptyString(liveActivityToken)) {
141147
throw new FirebaseMessagingError(
142148
MessagingClientErrorCode.INVALID_PAYLOAD,
143-
'apns.live_activity_token must be a non-empty string',
149+
'apns.liveActivityToken must be a non-empty string',
144150
);
145151
}
146152
}

test/unit/messaging/messaging.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,15 +1729,15 @@ describe('Messaging', () => {
17291729
invalidApnsLiveActivityTokens.forEach((arg) => {
17301730
it(`should throw given invalid apns live activity token: ${JSON.stringify(arg)}`, () => {
17311731
expect(() => {
1732-
messaging.send({ apns: { live_activity_token: arg }, topic: 'test' });
1733-
}).to.throw('apns.live_activity_token must be a string value');
1732+
messaging.send({ apns: { liveActivityToken: arg }, topic: 'test' });
1733+
}).to.throw('apns.liveActivityToken must be a string value');
17341734
});
17351735
})
17361736

17371737
it('should throw given empty apns live activity token', () => {
17381738
expect(() => {
1739-
messaging.send({ apns: { live_activity_token: '' }, topic: 'test' });
1740-
}).to.throw('apns.live_activity_token must be a non-empty string');
1739+
messaging.send({ apns: { liveActivityToken: '' }, topic: 'test' });
1740+
}).to.throw('apns.liveActivityToken must be a non-empty string');
17411741
});
17421742

17431743
const invalidApnsPayloads: any[] = [null, '', 'payload', true, 1.23];
@@ -2407,7 +2407,7 @@ describe('Messaging', () => {
24072407
label: 'APNS Start LiveActivity',
24082408
req: {
24092409
apns: {
2410-
live_activity_token: 'live-activity-token',
2410+
liveActivityToken: 'live-activity-token',
24112411
headers:{
24122412
'apns-priority': '10'
24132413
},
@@ -2432,7 +2432,7 @@ describe('Messaging', () => {
24322432
},
24332433
expectedReq: {
24342434
apns: {
2435-
live_activity_token: 'live-activity-token',
2435+
liveActivityToken: 'live-activity-token',
24362436
headers:{
24372437
'apns-priority': '10'
24382438
},
@@ -2460,7 +2460,7 @@ describe('Messaging', () => {
24602460
label: 'APNS Update LiveActivity',
24612461
req: {
24622462
apns: {
2463-
live_activity_token: 'live-activity-token',
2463+
liveActivityToken: 'live-activity-token',
24642464
headers:{
24652465
'apns-priority': '10'
24662466
},
@@ -2482,7 +2482,7 @@ describe('Messaging', () => {
24822482
},
24832483
expectedReq: {
24842484
apns: {
2485-
live_activity_token: 'live-activity-token',
2485+
liveActivityToken: 'live-activity-token',
24862486
headers:{
24872487
'apns-priority': '10'
24882488
},
@@ -2507,7 +2507,7 @@ describe('Messaging', () => {
25072507
label: 'APNS End LiveActivity',
25082508
req: {
25092509
apns: {
2510-
live_activity_token: 'live-activity-token',
2510+
liveActivityToken: 'live-activity-token',
25112511
'headers':{
25122512
'apns-priority': '10'
25132513
},
@@ -2530,7 +2530,7 @@ describe('Messaging', () => {
25302530
},
25312531
expectedReq: {
25322532
apns: {
2533-
live_activity_token: 'live-activity-token',
2533+
liveActivityToken: 'live-activity-token',
25342534
'headers':{
25352535
'apns-priority': '10'
25362536
},

0 commit comments

Comments
 (0)