Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 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
14 changes: 12 additions & 2 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions sdk/notificationhubs/notification-hubs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Release History

## 1.2.4 (Unreleased)
## 2.0.0 (Unreleased)

### Features Added

- Moved to `@azure/core-lro` v3 for long running operations.
- Added `beginGetNotificationDetails` to get the details of a notification as a long running operation.

### Breaking Changes

### Bugs Fixed
- Moving from `@azure/core-lro` v2 to v3 for long running operations. For APIs such as `beginSubmitNotificationHubJob`, this is a breaking change as it uses the new `PollerLike` interface instead of the old `SimplePollerLike` interface. See the [Polling API](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-lro/docs/MIGRATION.md#poller-api) migration guide for more information.

### Other Changes

## 1.2.3 (2024-05-21)

Expand Down
2 changes: 1 addition & 1 deletion sdk/notificationhubs/notification-hubs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"dependencies": {
"@azure/core-auth": "^1.7.2",
"@azure/abort-controller": "^2.1.2",
"@azure/core-lro": "^2.7.2",
"@azure/core-lro": "3.0.0-beta.2",
"@azure/core-paging": "^1.6.2",
"@azure/core-rest-pipeline": "^1.15.2",
"@azure/core-tracing": "^1.1.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import { OperationState } from '@azure/core-lro';
import { PagedAsyncIterableIterator } from '@azure/core-paging';
import { PipelineRequest } from '@azure/core-rest-pipeline';
import { PipelineResponse } from '@azure/core-rest-pipeline';
import { SimplePollerLike } from '@azure/core-lro';
import { PollerLike } from '@azure/core-lro';

// @public
export function beginGetNotificationDetails(context: NotificationHubsClientContext, notificationId: string, polledOperationOptions?: PolledOperationOptions): Promise<NotificationDetailsPoller>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the operation that will only be available to some SKUs but not to all correct? I was thinking, it may be a good idea to expose these operations in a separate subExport that makes it clear they are meant to be used for "non-basic" skus.

If we do this, I think it would be a good idea, instead of exposing an LRO for getting the notification details. Exposing a submitNotification that returns a PollerLike so that customers that have these Skus only need to call one operation instead of submit + check.


// @public
export function beginSubmitNotificationHubJob(context: NotificationHubsClientContext, notificationHubJob: NotificationHubJob, polledOperationOptions?: PolledOperationOptions): Promise<NotificationHubJobPoller>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { ClientOptions } from '@azure-rest/core-client';
import { OperationOptions } from '@azure-rest/core-client';
import { OperationState } from '@azure/core-lro';
import { SimplePollerLike } from '@azure/core-lro';
import { PollerLike } from '@azure/core-lro';

// @public
export interface AdmInstallation extends DeviceTokenInstallation {
Expand Down Expand Up @@ -815,6 +815,9 @@ export interface NotificationDetails {
xiaomiOutcomeCounts?: NotificationOutcome[];
}

// @public
export type NotificationDetailsPoller = PollerLike<OperationState<NotificationDetails>, NotificationDetails>;

// @public
export interface NotificationHubJob {
createdAt?: Date;
Expand All @@ -833,7 +836,7 @@ export interface NotificationHubJob {
}

// @public
export type NotificationHubJobPoller = SimplePollerLike<OperationState<NotificationHubJob>, NotificationHubJob>;
export type NotificationHubJobPoller = PollerLike<OperationState<NotificationHubJob>, NotificationHubJob>;

// @public
export type NotificationHubJobStatus =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import { ClientOptions } from '@azure-rest/core-client';
import { OperationOptions } from '@azure-rest/core-client';
import { OperationState } from '@azure/core-lro';
import { PagedAsyncIterableIterator } from '@azure/core-paging';
import { SimplePollerLike } from '@azure/core-lro';
import type { PagedAsyncIterableIterator } from '@azure/core-paging';
import { PollerLike } from '@azure/core-lro';

// @public
export interface AdmInstallation extends DeviceTokenInstallation {
Expand Down Expand Up @@ -816,6 +816,9 @@ export interface NotificationDetails {
xiaomiOutcomeCounts?: NotificationOutcome[];
}

// @public
export type NotificationDetailsPoller = PollerLike<OperationState<NotificationDetails>, NotificationDetails>;

// @public
export interface NotificationHubJob {
createdAt?: Date;
Expand All @@ -834,7 +837,7 @@ export interface NotificationHubJob {
}

// @public
export type NotificationHubJobPoller = SimplePollerLike<OperationState<NotificationHubJob>, NotificationHubJob>;
export type NotificationHubJobPoller = PollerLike<OperationState<NotificationHubJob>, NotificationHubJob>;

// @public
export type NotificationHubJobStatus =
Expand Down Expand Up @@ -883,6 +886,7 @@ export type NotificationHubJobType =
// @public
export class NotificationHubsClient {
constructor(connectionString: string, hubName: string, options?: NotificationHubsClientOptions);
beginGetNotificationDetails(notificationId: string, polledOperationOptions?: PolledOperationOptions): Promise<NotificationDetailsPoller>;
beginSubmitNotificationHubJob(notificationHubJob: NotificationHubJob, options?: PolledOperationOptions): Promise<NotificationHubJobPoller>;
cancelScheduledNotification(notificationId: string, options?: OperationOptions): Promise<NotificationHubsResponse>;
createOrUpdateInstallation(installation: Installation, options?: OperationOptions): Promise<NotificationHubsResponse>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@

import * as dotenv from "dotenv";
import {
NotificationHubsClientContext,
beginGetNotificationDetails,
createClientContext,
getNotificationOutcomeDetails,
sendNotification,
} from "@azure/notification-hubs/api";
import {
createAppleNotification,
NotificationDetails,
NotificationOutcomeState,
} from "@azure/notification-hubs/models";
import { delay } from "@azure/core-util";
import { createAppleNotification } from "@azure/notification-hubs/models";

// Load the .env file if it exists
dotenv.config();
Expand Down Expand Up @@ -58,34 +52,14 @@ async function main(): Promise<void> {
if (result.notificationId) {
console.log(`Tag List send Notification ID: ${result.notificationId}`);

const results = await getNotificationDetails(context, result.notificationId);
const poller = await beginGetNotificationDetails(context, result.notificationId);
const results = await poller.pollUntilDone();
if (results) {
console.log(JSON.stringify(results, null, 2));
}
}
}

async function getNotificationDetails(
context: NotificationHubsClientContext,
notificationId: string,
): Promise<NotificationDetails | undefined> {
let state: NotificationOutcomeState = "Enqueued";
let count = 0;
let result: NotificationDetails | undefined;
while ((state === "Enqueued" || state === "Processing") && count++ < 10) {
try {
result = await getNotificationOutcomeDetails(context, notificationId);
state = result.state!;
} catch (e) {
// Possible to get 404 for when it doesn't exist yet.
}

await delay(1000);
}

return result;
}

main().catch((err) => {
console.log("sendTagsList Sample: Error occurred: ", err);
process.exit(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,12 @@
*/

import * as dotenv from "dotenv";
import { createFcmLegacyNotification } from "@azure/notification-hubs/models";
import {
NotificationDetails,
NotificationOutcomeState,
createFcmLegacyNotification,
} from "@azure/notification-hubs/models";
import {
NotificationHubsClientContext,
beginGetNotificationDetails,
createClientContext,
getNotificationOutcomeDetails,
sendNotification,
} from "@azure/notification-hubs/api";
import { delay } from "@azure/core-util";
import { isRestError } from "@azure/core-rest-pipeline";

// Load the .env file if it exists
dotenv.config();
Expand Down Expand Up @@ -67,39 +60,14 @@ async function main(): Promise<void> {
if (result.notificationId) {
console.log(`Direct send Notification ID: ${result.notificationId}`);

const results = await getNotificationDetails(context, result.notificationId);
const poller = await beginGetNotificationDetails(context, result.notificationId);
const results = await poller.pollUntilDone();
if (results) {
console.log(JSON.stringify(results, null, 2));
}
}
}

async function getNotificationDetails(
context: NotificationHubsClientContext,
notificationId: string,
): Promise<NotificationDetails | undefined> {
let state: NotificationOutcomeState = "Enqueued";
let count = 0;
let result: NotificationDetails | undefined;
while ((state === "Enqueued" || state === "Processing") && count++ < 10) {
try {
result = await getNotificationOutcomeDetails(context, notificationId);
state = result.state!;
} catch (e) {
// Possible to get 404 for when it doesn't exist yet.
if (isRestError(e) && e.statusCode === 404) {
continue;
} else {
throw e;
}
}

await delay(1000);
}

return result;
}

main().catch((err) => {
console.log("sendDirectNotification Sample: Error occurred: ", err);
process.exit(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,12 @@
*/

import * as dotenv from "dotenv";
import { createFcmV1Notification } from "@azure/notification-hubs/models";
import {
NotificationDetails,
NotificationOutcomeState,
createFcmV1Notification,
} from "@azure/notification-hubs/models";
import {
NotificationHubsClientContext,
beginGetNotificationDetails,
createClientContext,
getNotificationOutcomeDetails,
sendNotification,
} from "@azure/notification-hubs/api";
import { delay } from "@azure/core-util";
import { isRestError } from "@azure/core-rest-pipeline";

// Load the .env file if it exists
dotenv.config();
Expand Down Expand Up @@ -71,39 +64,14 @@ async function main(): Promise<void> {
if (result.notificationId) {
console.log(`Direct send Notification ID: ${result.notificationId}`);

const results = await getNotificationDetails(context, result.notificationId);
const poller = await beginGetNotificationDetails(context, result.notificationId);
const results = await poller.pollUntilDone();
if (results) {
console.log(JSON.stringify(results, null, 2));
}
}
}

async function getNotificationDetails(
context: NotificationHubsClientContext,
notificationId: string,
): Promise<NotificationDetails | undefined> {
let state: NotificationOutcomeState = "Enqueued";
let count = 0;
let result: NotificationDetails | undefined;
while ((state === "Enqueued" || state === "Processing") && count++ < 10) {
try {
result = await getNotificationOutcomeDetails(context, notificationId);
state = result.state!;
} catch (e) {
// Possible to get 404 for when it doesn't exist yet.
if (isRestError(e) && e.statusCode === 404) {
continue;
} else {
throw e;
}
}

await delay(1000);
}

return result;
}

main().catch((err) => {
console.log("sendDirectNotification Sample: Error occurred: ", err);
process.exit(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,12 @@
*/

import * as dotenv from "dotenv";
import { createAppleNotification } from "@azure/notification-hubs/models";
import {
NotificationDetails,
NotificationOutcomeState,
createAppleNotification,
} from "@azure/notification-hubs/models";
import {
NotificationHubsClientContext,
beginGetNotificationDetails,
createClientContext,
getNotificationOutcomeDetails,
sendNotification,
} from "@azure/notification-hubs/api";
import { delay } from "@azure/core-util";
import { isRestError } from "@azure/core-rest-pipeline";

// Load the .env file if it exists
dotenv.config();
Expand Down Expand Up @@ -71,39 +64,14 @@ async function main(): Promise<void> {
if (result.notificationId) {
console.log(`Direct send Notification ID: ${result.notificationId}`);

const results = await getNotificationDetails(context, result.notificationId);
const poller = await beginGetNotificationDetails(context, result.notificationId);
const results = await poller.pollUntilDone();
if (results) {
console.log(JSON.stringify(results, null, 2));
}
}
}

async function getNotificationDetails(
context: NotificationHubsClientContext,
notificationId: string,
): Promise<NotificationDetails | undefined> {
let state: NotificationOutcomeState = "Enqueued";
let count = 0;
let result: NotificationDetails | undefined;
while ((state === "Enqueued" || state === "Processing") && count++ < 10) {
try {
result = await getNotificationOutcomeDetails(context, notificationId);
state = result.state!;
} catch (e) {
// Possible to get 404 for when it doesn't exist yet.
if (isRestError(e) && e.statusCode === 404) {
continue;
} else {
throw e;
}
}

await delay(1000);
}

return result;
}

main().catch((err) => {
console.log("sendDirectNotification Sample: Error occurred: ", err);
process.exit(1);
Expand Down
Loading