Skip to content

Commit

Permalink
[notification hubs] Adding Xiaomi support (#25171)
Browse files Browse the repository at this point in the history
### Packages impacted by this PR

- @azure/notification-hubs

### Issues associated with this PR


### Describe the problem that is addressed by this PR

Adds Xiaomi support for Track 2 SDKs with registration, installation,
send and send outcome operations.

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?


### Are there test cases added in this PR? _(If not, why?)_

yes

### Provide a list of related PRs _(if any)_

- Azure/azure-notificationhubs-dotnet#261
- Azure/azure-notificationhubs-dotnet#260
- Azure/azure-notificationhubs-dotnet#259

### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [x] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [x] Added a changelog (if necessary)

---------

Co-authored-by: Jeremy Meng <[email protected]>
  • Loading branch information
mpodwysocki and jeremymeng authored Mar 9, 2023
1 parent 7d0df44 commit 6f3c076
Show file tree
Hide file tree
Showing 15 changed files with 414 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@
"Usuk",
"USUK",
"Vertica",
"westus"
"westus",
"Xiaomi"
],
"allowCompoundWords": true,
"overrides": [
Expand Down
9 changes: 8 additions & 1 deletion sdk/notificationhubs/notification-hubs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Release History

## 1.0.0 (2023-02-16)
## 1.0.0-beta.9 (Unreleased)

### Features Added

- Added Xiaomi support with the following:
- `XiaomiRegistrationDescription` and `XiaomiTemplateRegistrationDescription` for registrations with associated factory methods.
- `XiaomiInstallation` for installation operations and associated factory methods.
- `XiaomiNotification` for notification send support and associated factory methods.

### Bugs Fixed

Expand Down
2 changes: 1 addition & 1 deletion sdk/notificationhubs/notification-hubs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Azure Notification Hubs SDK for JavaScript

Azure Notification Hubs provide a scaled-out push engine that enables you to send notifications to any platform (Apple, Amazon Kindle, Android, Baidu, Web, Windows, etc.) from any back-end (cloud or on-premises). Notification Hubs works well for both enterprise and consumer scenarios. Here are a few example scenarios:
Azure Notification Hubs provide a scaled-out push engine that enables you to send notifications to any platform (Apple, Amazon Kindle, Android, Baidu, Xiaomi, Web, Windows, etc.) from any back-end (cloud or on-premises). Notification Hubs works well for both enterprise and consumer scenarios. Here are a few example scenarios:

- Send breaking news notifications to millions with low latency.
- Send location-based coupons to interested user segments.
Expand Down
2 changes: 1 addition & 1 deletion sdk/notificationhubs/notification-hubs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure/notification-hubs",
"version": "1.0.0",
"version": "1.0.0-beta.9",
"description": "Azure Notification Hubs SDK for JavaScript",
"sdk-type": "client",
"main": "dist/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,18 @@ export function createWindowsTileNotification(notification: NotificationCommon):
// @public
export function createWindowsToastNotification(notification: NotificationCommon): WindowsNotification;

// @public
export function createXiaomiInstallation(installation: DeviceTokenInstallation): XiaomiInstallation;

// @public
export function createXiaomiNotification(notification: NotificationCommon): XiaomiNotification;

// @public
export function createXiaomiRegistrationDescription(description: XiaomiRegistrationDescriptionCommon): XiaomiRegistrationDescription;

// @public
export function createXiaomiTemplateRegistrationDescription(description: XiaomiTemplateRegistrationDescriptionCommon): XiaomiTemplateRegistrationDescription;

// @public
export interface DeviceTokenInstallation extends InstallationCommon {
pushChannel: string;
Expand Down Expand Up @@ -472,7 +484,7 @@ export interface GcmTemplateRegistrationDescriptionCommon extends GcmRegistratio
}

// @public
export type Installation = AppleInstallation | AdmInstallation | BaiduInstallation | BrowserInstallation | FcmLegacyInstallation | WindowsInstallation;
export type Installation = AppleInstallation | AdmInstallation | BaiduInstallation | BrowserInstallation | FcmLegacyInstallation | XiaomiInstallation | WindowsInstallation;

// @public
export interface InstallationCommon {
Expand Down Expand Up @@ -533,7 +545,7 @@ export interface MpnsTemplateRegistrationDescriptionCommon extends MpnsRegistrat
}

// @public
export type Notification = AppleNotification | AdmNotification | BaiduNotification | BrowserNotification | FcmLegacyNotification | WindowsNotification | TemplateNotification;
export type Notification = AppleNotification | AdmNotification | BaiduNotification | BrowserNotification | FcmLegacyNotification | XiaomiNotification | WindowsNotification | TemplateNotification;

// @public
export interface NotificationCommon {
Expand All @@ -559,6 +571,7 @@ export interface NotificationDetails {
tags?: string;
targetPlatforms?: string;
wnsOutcomeCounts?: NotificationOutcome[];
xiaomiOutcomeCounts?: NotificationOutcome[];
}

// @public
Expand Down Expand Up @@ -690,10 +703,10 @@ export interface PolledOperationOptions extends OperationOptions {
export type PushHandle = BrowserPushChannel | string;

// @public
export type RegistrationChannel = AdmRegistrationChannel | AppleRegistrationChannel | BaiduRegistrationChannel | BrowserRegistrationChannel | FirebaseLegacyRegistrationChannel | WindowsRegistrationChannel;
export type RegistrationChannel = AdmRegistrationChannel | AppleRegistrationChannel | BaiduRegistrationChannel | BrowserRegistrationChannel | FirebaseLegacyRegistrationChannel | XiaomiRegistrationChannel | WindowsRegistrationChannel;

// @public
export type RegistrationDescription = AdmRegistrationDescription | AdmTemplateRegistrationDescription | AppleRegistrationDescription | AppleTemplateRegistrationDescription | BaiduRegistrationDescription | BaiduTemplateRegistrationDescription | BrowserRegistrationDescription | BrowserTemplateRegistrationDescription | GcmRegistrationDescription | GcmTemplateRegistrationDescription | MpnsRegistrationDescription | MpnsTemplateRegistrationDescription | WindowsRegistrationDescription | WindowsTemplateRegistrationDescription;
export type RegistrationDescription = AdmRegistrationDescription | AdmTemplateRegistrationDescription | AppleRegistrationDescription | AppleTemplateRegistrationDescription | BaiduRegistrationDescription | BaiduTemplateRegistrationDescription | BrowserRegistrationDescription | BrowserTemplateRegistrationDescription | GcmRegistrationDescription | GcmTemplateRegistrationDescription | MpnsRegistrationDescription | MpnsTemplateRegistrationDescription | XiaomiRegistrationDescription | XiaomiTemplateRegistrationDescription | WindowsRegistrationDescription | WindowsTemplateRegistrationDescription;

// @public
export interface RegistrationDescriptionCommon {
Expand Down Expand Up @@ -729,7 +742,7 @@ export interface RegistrationResult {
}

// @public
export type RegistrationType = "Adm" | "AdmTemplate" | "Apple" | "AppleTemplate" | "Baidu" | "BaiduTemplate" | "Browser" | "BrowserTemplate" | "Gcm" | "GcmTemplate" | "Mpns" | "MpnsTemplate" | "Windows" | "WindowsTemplate";
export type RegistrationType = "Adm" | "AdmTemplate" | "Apple" | "AppleTemplate" | "Baidu" | "BaiduTemplate" | "Browser" | "BrowserTemplate" | "Gcm" | "GcmTemplate" | "Mpns" | "MpnsTemplate" | "Xiaomi" | "XiaomiTemplate" | "Windows" | "WindowsTemplate";

// @public
export interface ScheduleNotificationOptions extends OperationOptions {
Expand Down Expand Up @@ -801,6 +814,41 @@ export interface WindowsTemplateRegistrationDescriptionCommon extends WindowsReg
wnsHeaders?: Record<string, string>;
}

// @public
export interface XiaomiInstallation extends DeviceTokenInstallation {
platform: "xiaomi";
}

// @public
export interface XiaomiNotification extends JsonNotification {
platform: "xiaomi";
}

// @public
export interface XiaomiRegistrationChannel {
kind: "xiaomi";
xiaomiRegistrationId: string;
}

// @public
export interface XiaomiRegistrationDescription extends XiaomiRegistrationDescriptionCommon {
kind: "Xiaomi";
}

// @public
export interface XiaomiRegistrationDescriptionCommon extends RegistrationDescriptionCommon {
xiaomiRegistrationId: string;
}

// @public
export interface XiaomiTemplateRegistrationDescription extends XiaomiTemplateRegistrationDescriptionCommon {
kind: "XiaomiTemplate";
}

// @public
export interface XiaomiTemplateRegistrationDescriptionCommon extends XiaomiRegistrationDescriptionCommon, TemplateRegistrationDescription {
}

// (No @packageDocumentation comment for this package)

```
25 changes: 25 additions & 0 deletions sdk/notificationhubs/notification-hubs/src/models/installation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,30 @@ export function createFcmLegacyInstallation(
};
}

/**
* Represents a Xiaomi based installation.
*/
export interface XiaomiInstallation extends DeviceTokenInstallation {
/**
* The platform for the installation.
*/
platform: "xiaomi";
}

/**
* Creates a Xiaomi based installation.
* @param installation - A partial installation used to create the Xiaomi installation.
* @returns The newly created Xiaomi installation.
*/
export function createXiaomiInstallation(
installation: DeviceTokenInstallation
): XiaomiInstallation {
return {
...installation,
platform: "xiaomi",
};
}

/**
* Represents a Windows Notification Services (WNS) based installation.
*/
Expand Down Expand Up @@ -223,6 +247,7 @@ export type Installation =
| BaiduInstallation
| BrowserInstallation
| FcmLegacyInstallation
| XiaomiInstallation
| WindowsInstallation;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export interface FcmLegacyNotification extends JsonNotification {
/**
* Creates a notification to send to Firebase.
* @param notification - A partial message used to create a message for Firebase.
* @returns A newly created Firebase.
* @returns A newly created Firebase notification.
*/
export function createFcmLegacyNotification(
notification: NotificationCommon
Expand All @@ -145,6 +145,29 @@ export function createFcmLegacyNotification(
};
}

/**
* Represents a Xiaomi push notification.
*/
export interface XiaomiNotification extends JsonNotification {
/**
* The platform for the push notification.
*/
platform: "xiaomi";
}

/**
* Creates a notification to send to Xiaomi.
* @param notification - A partial message used to create a message for Xiaomi.
* @returns A newly created Xiaomi notification.
*/
export function createXiaomiNotification(notification: NotificationCommon): XiaomiNotification {
return {
...notification,
platform: "xiaomi",
contentType: Constants.JSON_CONTENT_TYPE,
};
}

/**
* Represents a template based push notification.
*/
Expand Down Expand Up @@ -289,5 +312,6 @@ export type Notification =
| BaiduNotification
| BrowserNotification
| FcmLegacyNotification
| XiaomiNotification
| WindowsNotification
| TemplateNotification;
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ export interface NotificationDetails {
* Web Push outcome counts per state.
*/
browserOutcomeCounts?: NotificationOutcome[];

/**
* Xiaomi outcome counts per state.
*/
xiaomiOutcomeCounts?: NotificationOutcome[];
}

/**
Expand Down
85 changes: 85 additions & 0 deletions sdk/notificationhubs/notification-hubs/src/models/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export type RegistrationType =
| "GcmTemplate"
| "Mpns"
| "MpnsTemplate"
| "Xiaomi"
| "XiaomiTemplate"
| "Windows"
| "WindowsTemplate";

Expand Down Expand Up @@ -558,6 +560,72 @@ export function createWindowsTemplateRegistrationDescription(
};
}

/**
* Represents a Xiaomi registration description.
*/
export interface XiaomiRegistrationDescriptionCommon extends RegistrationDescriptionCommon {
/**
* The Xiaomi registration ID.
*/
xiaomiRegistrationId: string;
}

/**
* Represents a Xiaomi registration description.
*/
export interface XiaomiRegistrationDescription extends XiaomiRegistrationDescriptionCommon {
/**
* The kind of the registration.
*/
kind: "Xiaomi";
}

/**
* Creates a Xiaomi registration description.
* @param description - A partial Xiaomi registration description.
* @returns A created Xiaomi registration description.
*/
export function createXiaomiRegistrationDescription(
description: XiaomiRegistrationDescriptionCommon
): XiaomiRegistrationDescription {
return {
...description,
kind: "Xiaomi",
};
}

/**
* Represents a Xiaomi template registration.
*/
export interface XiaomiTemplateRegistrationDescriptionCommon
extends XiaomiRegistrationDescriptionCommon,
TemplateRegistrationDescription {}

/**
* Represents a Windows Notification Services (WNS) template registration.
*/
export interface XiaomiTemplateRegistrationDescription
extends XiaomiTemplateRegistrationDescriptionCommon {
/**
* The kind of the registration.
*/
kind: "XiaomiTemplate";
}

/**
* Creates a Xiaomi template registration description.
* @param description - A partial Xiaomi template registration description.
* @returns A created Xiaomi template registration description.
*/
export function createXiaomiTemplateRegistrationDescription(
description: XiaomiTemplateRegistrationDescriptionCommon
): XiaomiTemplateRegistrationDescription {
return {
...description,
kind: "XiaomiTemplate",
};
}

/**
* Describes the types of registration descriptions.
*/
Expand All @@ -574,6 +642,8 @@ export type RegistrationDescription =
| GcmTemplateRegistrationDescription
| MpnsRegistrationDescription
| MpnsTemplateRegistrationDescription
| XiaomiRegistrationDescription
| XiaomiTemplateRegistrationDescription
| WindowsRegistrationDescription
| WindowsTemplateRegistrationDescription;

Expand Down Expand Up @@ -673,6 +743,20 @@ export interface WindowsRegistrationChannel {
kind: "windows";
}

/**
* Describes an Xiaomi Registration channel query.
*/
export interface XiaomiRegistrationChannel {
/**
* The Xiaomi registration ID.
*/
xiaomiRegistrationId: string;
/**
* The kind of the registration channel.
*/
kind: "xiaomi";
}

/**
* Describes a Registration query.
*/
Expand All @@ -682,4 +766,5 @@ export type RegistrationChannel =
| BaiduRegistrationChannel
| BrowserRegistrationChannel
| FirebaseLegacyRegistrationChannel
| XiaomiRegistrationChannel
| WindowsRegistrationChannel;
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export async function parseNotificationDetails(bodyText: string): Promise<Notifi
fcmOutcomeCounts = parseOutcomeCounts(notificationDetails["GcmOutcomeCounts"]["Outcome"]);
}

let xiaomiOutcomeCounts: NotificationOutcome[] | undefined;
if (isDefined(notificationDetails["XiaomiOutcomeCounts"])) {
xiaomiOutcomeCounts = parseOutcomeCounts(notificationDetails["XiaomiOutcomeCounts"]["Outcome"]);
}

let wnsOutcomeCounts: NotificationOutcome[] | undefined;
if (isDefined(notificationDetails["WnsOutcomeCounts"])) {
wnsOutcomeCounts = parseOutcomeCounts(notificationDetails["WnsOutcomeCounts"]["Outcome"]);
Expand All @@ -58,6 +63,7 @@ export async function parseNotificationDetails(bodyText: string): Promise<Notifi
admOutcomeCounts,
baiduOutcomeCounts,
fcmOutcomeCounts,
xiaomiOutcomeCounts,
wnsOutcomeCounts,
};
}
Expand Down
Loading

0 comments on commit 6f3c076

Please sign in to comment.