@azure/notification-hubs 2.0.1-alpha.20250619.1 → 2.0.1-alpha.20250718.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/api/beginSubmitNotificationHubJob.js +6 -7
- package/dist/browser/api/beginSubmitNotificationHubJob.js.map +1 -1
- package/dist/browser/api/clientContext.js +12 -5
- package/dist/browser/api/clientContext.js.map +1 -1
- package/dist/browser/api/internal/_client.js +21 -4
- package/dist/browser/api/internal/_client.js.map +1 -1
- package/dist/browser/api/internal/_listRegistrations.js +13 -31
- package/dist/browser/api/internal/_listRegistrations.js.map +1 -1
- package/dist/browser/api/listRegistrationsByChannel.js +4 -1
- package/dist/browser/api/listRegistrationsByChannel.js.map +1 -1
- package/dist/browser/api/listRegistrationsByTag.js +13 -31
- package/dist/browser/api/listRegistrationsByTag.js.map +1 -1
- package/dist/browser/auth/sasTokenCredential.js +4 -0
- package/dist/browser/auth/sasTokenCredential.js.map +1 -1
- package/dist/browser/models/installation.js +32 -8
- package/dist/browser/models/installation.js.map +1 -1
- package/dist/browser/models/notification.js +69 -13
- package/dist/browser/models/notification.js.map +1 -1
- package/dist/browser/models/registration.js +64 -16
- package/dist/browser/models/registration.js.map +1 -1
- package/dist/browser/notificationHubsClient.js +1 -0
- package/dist/browser/notificationHubsClient.js.map +1 -1
- package/dist/browser/serializers/notificationDetailsSerializer.js +6 -7
- package/dist/browser/serializers/notificationDetailsSerializer.js.map +1 -1
- package/dist/browser/serializers/notificationHubJobSerializer.js +4 -5
- package/dist/browser/serializers/notificationHubJobSerializer.js.map +1 -1
- package/dist/browser/serializers/registrationSerializer.js +185 -48
- package/dist/browser/serializers/registrationSerializer.js.map +1 -1
- package/dist/browser/utils/xmlUtils.js +1 -1
- package/dist/browser/utils/xmlUtils.js.map +1 -1
- package/dist/commonjs/api/beginSubmitNotificationHubJob.js +6 -7
- package/dist/commonjs/api/beginSubmitNotificationHubJob.js.map +1 -1
- package/dist/commonjs/api/clientContext.js +12 -5
- package/dist/commonjs/api/clientContext.js.map +1 -1
- package/dist/commonjs/api/internal/_client.js +21 -4
- package/dist/commonjs/api/internal/_client.js.map +1 -1
- package/dist/commonjs/api/internal/_listRegistrations.js +13 -31
- package/dist/commonjs/api/internal/_listRegistrations.js.map +1 -1
- package/dist/commonjs/api/listRegistrationsByChannel.js +4 -1
- package/dist/commonjs/api/listRegistrationsByChannel.js.map +1 -1
- package/dist/commonjs/api/listRegistrationsByTag.js +13 -31
- package/dist/commonjs/api/listRegistrationsByTag.js.map +1 -1
- package/dist/commonjs/auth/sasTokenCredential.js +4 -0
- package/dist/commonjs/auth/sasTokenCredential.js.map +1 -1
- package/dist/commonjs/models/installation.js +32 -8
- package/dist/commonjs/models/installation.js.map +1 -1
- package/dist/commonjs/models/notification.js +69 -13
- package/dist/commonjs/models/notification.js.map +1 -1
- package/dist/commonjs/models/registration.js +64 -16
- package/dist/commonjs/models/registration.js.map +1 -1
- package/dist/commonjs/notificationHubsClient.js +1 -0
- package/dist/commonjs/notificationHubsClient.js.map +1 -1
- package/dist/commonjs/serializers/notificationDetailsSerializer.js +6 -7
- package/dist/commonjs/serializers/notificationDetailsSerializer.js.map +1 -1
- package/dist/commonjs/serializers/notificationHubJobSerializer.js +4 -5
- package/dist/commonjs/serializers/notificationHubJobSerializer.js.map +1 -1
- package/dist/commonjs/serializers/registrationSerializer.js +185 -48
- package/dist/commonjs/serializers/registrationSerializer.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +11 -11
- package/dist/commonjs/utils/xmlUtils.js +1 -1
- package/dist/commonjs/utils/xmlUtils.js.map +1 -1
- package/dist/esm/api/beginSubmitNotificationHubJob.js +6 -7
- package/dist/esm/api/beginSubmitNotificationHubJob.js.map +1 -1
- package/dist/esm/api/clientContext.js +12 -5
- package/dist/esm/api/clientContext.js.map +1 -1
- package/dist/esm/api/internal/_client.js +21 -4
- package/dist/esm/api/internal/_client.js.map +1 -1
- package/dist/esm/api/internal/_listRegistrations.js +13 -31
- package/dist/esm/api/internal/_listRegistrations.js.map +1 -1
- package/dist/esm/api/listRegistrationsByChannel.js +4 -1
- package/dist/esm/api/listRegistrationsByChannel.js.map +1 -1
- package/dist/esm/api/listRegistrationsByTag.js +13 -31
- package/dist/esm/api/listRegistrationsByTag.js.map +1 -1
- package/dist/esm/auth/sasTokenCredential.js +4 -0
- package/dist/esm/auth/sasTokenCredential.js.map +1 -1
- package/dist/esm/models/installation.js +32 -8
- package/dist/esm/models/installation.js.map +1 -1
- package/dist/esm/models/notification.js +69 -13
- package/dist/esm/models/notification.js.map +1 -1
- package/dist/esm/models/registration.js +64 -16
- package/dist/esm/models/registration.js.map +1 -1
- package/dist/esm/notificationHubsClient.js +1 -0
- package/dist/esm/notificationHubsClient.js.map +1 -1
- package/dist/esm/serializers/notificationDetailsSerializer.js +6 -7
- package/dist/esm/serializers/notificationDetailsSerializer.js.map +1 -1
- package/dist/esm/serializers/notificationHubJobSerializer.js +4 -5
- package/dist/esm/serializers/notificationHubJobSerializer.js.map +1 -1
- package/dist/esm/serializers/registrationSerializer.js +185 -48
- package/dist/esm/serializers/registrationSerializer.js.map +1 -1
- package/dist/esm/utils/xmlUtils.js +1 -1
- package/dist/esm/utils/xmlUtils.js.map +1 -1
- package/dist/react-native/api/beginSubmitNotificationHubJob.js +6 -7
- package/dist/react-native/api/beginSubmitNotificationHubJob.js.map +1 -1
- package/dist/react-native/api/clientContext.js +12 -5
- package/dist/react-native/api/clientContext.js.map +1 -1
- package/dist/react-native/api/internal/_client.js +21 -4
- package/dist/react-native/api/internal/_client.js.map +1 -1
- package/dist/react-native/api/internal/_listRegistrations.js +13 -31
- package/dist/react-native/api/internal/_listRegistrations.js.map +1 -1
- package/dist/react-native/api/listRegistrationsByChannel.js +4 -1
- package/dist/react-native/api/listRegistrationsByChannel.js.map +1 -1
- package/dist/react-native/api/listRegistrationsByTag.js +13 -31
- package/dist/react-native/api/listRegistrationsByTag.js.map +1 -1
- package/dist/react-native/auth/sasTokenCredential.js +4 -0
- package/dist/react-native/auth/sasTokenCredential.js.map +1 -1
- package/dist/react-native/models/installation.js +32 -8
- package/dist/react-native/models/installation.js.map +1 -1
- package/dist/react-native/models/notification.js +69 -13
- package/dist/react-native/models/notification.js.map +1 -1
- package/dist/react-native/models/registration.js +64 -16
- package/dist/react-native/models/registration.js.map +1 -1
- package/dist/react-native/notificationHubsClient.js +1 -0
- package/dist/react-native/notificationHubsClient.js.map +1 -1
- package/dist/react-native/serializers/notificationDetailsSerializer.js +6 -7
- package/dist/react-native/serializers/notificationDetailsSerializer.js.map +1 -1
- package/dist/react-native/serializers/notificationHubJobSerializer.js +4 -5
- package/dist/react-native/serializers/notificationHubJobSerializer.js.map +1 -1
- package/dist/react-native/serializers/registrationSerializer.js +185 -48
- package/dist/react-native/serializers/registrationSerializer.js.map +1 -1
- package/dist/react-native/utils/xmlUtils.js +1 -1
- package/dist/react-native/utils/xmlUtils.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_listRegistrations.js","sourceRoot":"","sources":["../../../../src/api/internal/_listRegistrations.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC
|
|
1
|
+
{"version":3,"file":"_listRegistrations.js","sourceRoot":"","sources":["../../../../src/api/internal/_listRegistrations.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAK1D,OAAO,EAAE,6BAA6B,EAAE,MAAM,6CAA6C,CAAC;AAE5F,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,oBAAoB,CACzC,OAAsC,EACtC,OAAiC;IAEjC,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,0BAA0B,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC;QACtE,KAAK,CAAC,CAAC,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,CAA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O,EAAE,OAAO,CAAC,CAAC;IACjE,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IAE1D,MAAM,aAAa,GAAG,MAAM,6BAA6B,CAAC,qBAAqB,CAC7E,QAAQ,CAAC,UAAW,CACrB,CAAC;IACF,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IACjE,OAAO;QACL,aAAa;QACb,iBAAiB,EAAE,SAAS;KAC7B,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { createRequest, sendRequest } from \"./_client.js\";\nimport type { NotificationHubsClientContext } from \"../index.js\";\nimport type { RegistrationDescription } from \"../../models/registration.js\";\nimport type { RegistrationQueryOptions } from \"../../models/options.js\";\nimport type { RegistrationQueryResponse } from \"../../models/response.js\";\nimport { registrationDescriptionParser } from \"../../serializers/registrationSerializer.js\";\n\nexport async function* listRegistrationsAll(\n context: NotificationHubsClientContext,\n options: RegistrationQueryOptions,\n): AsyncIterableIterator<RegistrationDescription> {\n for await (const page of listRegistrationPagingPage(context, options)) {\n yield* page;\n }\n}\n\nexport async function* listRegistrationPagingPage(\n context: NotificationHubsClientContext,\n options: RegistrationQueryOptions,\n): AsyncIterableIterator<RegistrationDescription[]> {\n let result = await _listRegistrations(context, options);\n yield result.registrations || [];\n let continuationToken = result.continuationToken;\n while (continuationToken) {\n result = await _listRegistrations(context, options, continuationToken);\n continuationToken = result.continuationToken;\n yield result.registrations || [];\n }\n}\n\nasync function _listRegistrations(\n context: NotificationHubsClientContext,\n options: RegistrationQueryOptions,\n continuationToken?: string,\n): Promise<RegistrationQueryResponse> {\n const endpoint = context.requestUrl();\n endpoint.pathname += \"/registrations\";\n if (options.top !== undefined) {\n endpoint.searchParams.set(\"$top\", `${options.top}`);\n }\n\n if (options.filter !== undefined) {\n endpoint.searchParams.set(\"$filter\", options.filter);\n }\n\n if (continuationToken !== undefined) {\n endpoint.searchParams.set(\"continuationtoken\", continuationToken);\n }\n\n const headers = await context.createHeaders(\"listRegistrations\");\n const request = createRequest(endpoint, \"GET\", headers, options);\n const response = await sendRequest(context, request, 200);\n\n const registrations = await registrationDescriptionParser.parseRegistrationFeed(\n response.bodyAsText!,\n );\n const nextToken = response.headers.get(\"x-ms-continuationtoken\");\n return {\n registrations,\n continuationToken: nextToken,\n };\n}\n"]}
|
|
@@ -11,7 +11,10 @@ import { tracingClient } from "../utils/tracing.js";
|
|
|
11
11
|
* @returns A paged async iterable containing all of the registrations for the notification hub.
|
|
12
12
|
*/
|
|
13
13
|
export function listRegistrationsByChannel(context, channel, options = {}) {
|
|
14
|
-
const newOptions =
|
|
14
|
+
const newOptions = {
|
|
15
|
+
...options,
|
|
16
|
+
filter: getFilterByChannel(channel),
|
|
17
|
+
};
|
|
15
18
|
const { span, updatedOptions } = tracingClient.startSpan("NotificationHubsClientContext.listRegistrationsByDevice", newOptions);
|
|
16
19
|
try {
|
|
17
20
|
const iter = listRegistrationsAll(context, updatedOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listRegistrationsByChannel.js","sourceRoot":"","sources":["../../../src/api/listRegistrationsByChannel.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAIpG,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CACxC,OAAsC,EACtC,OAA4B,EAC5B,UAAyC,EAAE;IAE3C,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"listRegistrationsByChannel.js","sourceRoot":"","sources":["../../../src/api/listRegistrationsByChannel.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAIpG,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CACxC,OAAsC,EACtC,OAA4B,EAC5B,UAAyC,EAAE;IAE3C,MAAM,UAAU,GAAG;QACjB,GAAG,OAAO;QACV,MAAM,EAAE,kBAAkB,CAAC,OAAO,CAAC;KACpC,CAAC;IACF,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,aAAa,CAAC,SAAS,CACtD,yDAAyD,EACzD,UAAU,CACX,CAAC;IACF,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,oBAAoB,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QAC3D,OAAO;YACL,IAAI;gBACF,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;YACrB,CAAC;YACD,CAAC,MAAM,CAAC,aAAa,CAAC;gBACpB,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,EAAE,GAAG,EAAE;gBACX,OAAO,0BAA0B,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;YAC7D,CAAC;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;QAC9C,MAAM,CAAC,CAAC;IACV,CAAC;YAAS,CAAC;QACT,IAAI,CAAC,GAAG,EAAE,CAAC;IACb,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { RegistrationDescription, RegistrationChannel } from \"../models/registration.js\";\nimport { listRegistrationPagingPage, listRegistrationsAll } from \"./internal/_listRegistrations.js\";\nimport type { NotificationHubsClientContext } from \"./index.js\";\nimport type { PagedAsyncIterableIterator } from \"@azure/core-paging\";\nimport type { RegistrationQueryLimitOptions } from \"../models/options.js\";\nimport { getFilterByChannel } from \"../utils/registrationUtils.js\";\nimport { tracingClient } from \"../utils/tracing.js\";\n\n/**\n * Gets all registrations for the notification hub with the given device information and options.\n * @param context - The Notification Hubs client.\n * @param channel - The Registration channel information to query per PNS type.\n * @param options - The options for querying the registrations such as $top.\n * @returns A paged async iterable containing all of the registrations for the notification hub.\n */\nexport function listRegistrationsByChannel(\n context: NotificationHubsClientContext,\n channel: RegistrationChannel,\n options: RegistrationQueryLimitOptions = {},\n): PagedAsyncIterableIterator<RegistrationDescription> {\n const newOptions = {\n ...options,\n filter: getFilterByChannel(channel),\n };\n const { span, updatedOptions } = tracingClient.startSpan(\n \"NotificationHubsClientContext.listRegistrationsByDevice\",\n newOptions,\n );\n try {\n const iter = listRegistrationsAll(context, updatedOptions);\n return {\n next() {\n return iter.next();\n },\n [Symbol.asyncIterator]() {\n return this;\n },\n byPage: () => {\n return listRegistrationPagingPage(context, updatedOptions);\n },\n };\n } catch (e: any) {\n span.setStatus({ status: \"error\", error: e });\n throw e;\n } finally {\n span.end();\n }\n}\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
|
-
import { __asyncDelegator, __asyncGenerator, __asyncValues, __await } from "tslib";
|
|
4
3
|
import { createRequest, sendRequest } from "./internal/_client.js";
|
|
5
4
|
import { registrationDescriptionParser } from "../serializers/registrationSerializer.js";
|
|
6
5
|
import { tracingClient } from "../utils/tracing.js";
|
|
@@ -36,37 +35,20 @@ export function listRegistrationsByTag(context, tag, options = {}) {
|
|
|
36
35
|
span.end();
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
|
-
function listRegistrationsByTagAll(context, tag, options) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
for (var _d = true, _e = __asyncValues(listRegistrationsByTagPagingPage(context, tag, options)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
|
|
44
|
-
_c = _f.value;
|
|
45
|
-
_d = false;
|
|
46
|
-
const page = _c;
|
|
47
|
-
yield __await(yield* __asyncDelegator(__asyncValues(page)));
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
51
|
-
finally {
|
|
52
|
-
try {
|
|
53
|
-
if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
|
|
54
|
-
}
|
|
55
|
-
finally { if (e_1) throw e_1.error; }
|
|
56
|
-
}
|
|
57
|
-
});
|
|
38
|
+
async function* listRegistrationsByTagAll(context, tag, options) {
|
|
39
|
+
for await (const page of listRegistrationsByTagPagingPage(context, tag, options)) {
|
|
40
|
+
yield* page;
|
|
41
|
+
}
|
|
58
42
|
}
|
|
59
|
-
function listRegistrationsByTagPagingPage(context, tag, options) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
});
|
|
43
|
+
async function* listRegistrationsByTagPagingPage(context, tag, options) {
|
|
44
|
+
let result = await _listRegistrationsByTag(context, tag, options);
|
|
45
|
+
yield result.registrations || [];
|
|
46
|
+
let continuationToken = result.continuationToken;
|
|
47
|
+
while (continuationToken) {
|
|
48
|
+
result = await _listRegistrationsByTag(context, tag, options, continuationToken);
|
|
49
|
+
continuationToken = result.continuationToken;
|
|
50
|
+
yield result.registrations || [];
|
|
51
|
+
}
|
|
70
52
|
}
|
|
71
53
|
async function _listRegistrationsByTag(context, tag, options, continuationToken) {
|
|
72
54
|
const endpoint = context.requestUrl();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listRegistrationsByTag.js","sourceRoot":"","sources":["../../../src/api/listRegistrationsByTag.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC
|
|
1
|
+
{"version":3,"file":"listRegistrationsByTag.js","sourceRoot":"","sources":["../../../src/api/listRegistrationsByTag.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAMnE,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CACpC,OAAsC,EACtC,GAAW,EACX,UAAyC,EAAE;IAE3C,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,aAAa,CAAC,SAAS,CACtD,iCAAiC,cAAc,EAAE,EACjD,OAAO,CACR,CAAC;IACF,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,yBAAyB,CAAC,OAAO,EAAE,GAAG,EAAE,cAAc,CAAC,CAAC;QACrE,OAAO;YACL,IAAI;gBACF,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;YACrB,CAAC;YACD,CAAC,MAAM,CAAC,aAAa,CAAC;gBACpB,OAAO,IAAI,CAAC;YACd,CAAC;YACD,MAAM,EAAE,GAAG,EAAE;gBACX,OAAO,gCAAgC,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;YACjE,CAAC;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;QAC9C,MAAM,CAAC,CAAC;IACV,CAAC;YAAS,CAAC;QACT,IAAI,CAAC,GAAG,EAAE,CAAC;IACb,CAAC;AACH,CAAC;AAED,KAAK,SAAS,CAAC,CAAC,yBAAyB,CACvC,OAAsC,EACtC,GAAW,EACX,OAAs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,CAAC;IAC5D,MAAM,OAAO,GAAG,aAAa,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACjE,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IAE1D,MAAM,aAAa,GAAG,MAAM,6BAA6B,CAAC,qBAAqB,CAC7E,QAAQ,CAAC,UAAW,CACrB,CAAC;IACF,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IACjE,OAAO;QACL,aAAa;QACb,iBAAiB,EAAE,SAAS;KAC7B,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { createRequest, sendRequest } from \"./internal/_client.js\";\nimport type { NotificationHubsClientContext } from \"./index.js\";\nimport type { PagedAsyncIterableIterator } from \"@azure/core-paging\";\nimport type { RegistrationDescription } from \"../models/registration.js\";\nimport type { RegistrationQueryLimitOptions } from \"../models/options.js\";\nimport type { RegistrationQueryResponse } from \"../models/response.js\";\nimport { registrationDescriptionParser } from \"../serializers/registrationSerializer.js\";\nimport { tracingClient } from \"../utils/tracing.js\";\n\nconst OPERATION_NAME = \"listRegistrationsByTag\";\n\n/**\n * Lists all registrations with the matching tag.\n * @param context - The Notification Hubs client.\n * @param tag - The tag to query for matching registrations.\n * @param options - The query options such as $top.\n * @returns A paged async iterable containing the matching registrations for the notification hub.\n */\nexport function listRegistrationsByTag(\n context: NotificationHubsClientContext,\n tag: string,\n options: RegistrationQueryLimitOptions = {},\n): PagedAsyncIterableIterator<RegistrationDescription> {\n const { span, updatedOptions } = tracingClient.startSpan(\n `NotificationHubsClientContext.${OPERATION_NAME}`,\n options,\n );\n try {\n const iter = listRegistrationsByTagAll(context, tag, updatedOptions);\n return {\n next() {\n return iter.next();\n },\n [Symbol.asyncIterator]() {\n return this;\n },\n byPage: () => {\n return listRegistrationsByTagPagingPage(context, tag, options);\n },\n };\n } catch (e: any) {\n span.setStatus({ status: \"error\", error: e });\n throw e;\n } finally {\n span.end();\n }\n}\n\nasync function* listRegistrationsByTagAll(\n context: NotificationHubsClientContext,\n tag: string,\n options: RegistrationQueryLimitOptions,\n): AsyncIterableIterator<RegistrationDescription> {\n for await (const page of listRegistrationsByTagPagingPage(context, tag, options)) {\n yield* page;\n }\n}\n\nasync function* listRegistrationsByTagPagingPage(\n context: NotificationHubsClientContext,\n tag: string,\n options: RegistrationQueryLimitOptions,\n): AsyncIterableIterator<RegistrationDescription[]> {\n let result = await _listRegistrationsByTag(context, tag, options);\n yield result.registrations || [];\n let continuationToken = result.continuationToken;\n while (continuationToken) {\n result = await _listRegistrationsByTag(context, tag, options, continuationToken);\n continuationToken = result.continuationToken;\n yield result.registrations || [];\n }\n}\n\nasync function _listRegistrationsByTag(\n context: NotificationHubsClientContext,\n tag: string,\n options: RegistrationQueryLimitOptions,\n continuationToken?: string,\n): Promise<RegistrationQueryResponse> {\n const endpoint = context.requestUrl();\n endpoint.pathname += `/tags/${tag}/registrations`;\n if (options.top !== undefined) {\n endpoint.searchParams.set(\"$top\", `${options.top}`);\n }\n\n if (continuationToken !== undefined) {\n endpoint.searchParams.set(\"continuationtoken\", continuationToken);\n }\n\n const headers = await context.createHeaders(OPERATION_NAME);\n const request = createRequest(endpoint, \"GET\", headers, options);\n const response = await sendRequest(context, request, 200);\n\n const registrations = await registrationDescriptionParser.parseRegistrationFeed(\n response.bodyAsText!,\n );\n const nextToken = response.headers.get(\"x-ms-continuationtoken\");\n return {\n registrations,\n continuationToken: nextToken,\n };\n}\n"]}
|
|
@@ -8,6 +8,10 @@ import { signString } from "./hmacSha256.js";
|
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
10
|
export class SasTokenCredential {
|
|
11
|
+
/**
|
|
12
|
+
* The SASCredential containing the key name and secret key value.
|
|
13
|
+
*/
|
|
14
|
+
_credential;
|
|
11
15
|
/**
|
|
12
16
|
* Initializes a new instance of SasTokenProvider
|
|
13
17
|
* @param credential - The source `NamedKeyCredential` or `SASCredential`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sasTokenCredential.js","sourceRoot":"","sources":["../../../src/auth/sasTokenCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAiB7C;;;;;GAKG;AACH,MAAM,OAAO,kBAAkB;
|
|
1
|
+
{"version":3,"file":"sasTokenCredential.js","sourceRoot":"","sources":["../../../src/auth/sasTokenCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAiB7C;;;;;GAKG;AACH,MAAM,OAAO,kBAAkB;IAC7B;;OAEG;IACK,WAAW,CAAqB;IAExC;;;OAGG;IACH,YAAY,UAA8B;QACxC,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ,CAAC,MAAyB;QACtC,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAC5D,OAAO,WAAW,CAChB,IAAI,CAAC,WAAW,CAAC,mBAAmB,EACpC,IAAI,CAAC,WAAW,CAAC,eAAe,EAChC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,EACpC,QAAQ,CACT,CAAC;IACJ,CAAC;CACF;AAED;;;;;;;GAOG;AACH,KAAK,UAAU,WAAW,CACxB,OAAe,EACf,GAAW,EACX,MAAc,EACd,QAAgB;IAEhB,QAAQ,GAAG,kBAAkB,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;IACtD,OAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,YAAY,GAAG,QAAQ,GAAG,IAAI,GAAG,MAAM,CAAC;IAC9C,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;IAEhD,OAAO;QACL,KAAK,EAAE,4BAA4B,QAAQ,QAAQ,GAAG,OAAO,MAAM,QAAQ,OAAO,EAAE;QACpF,kBAAkB,EAAE,MAAM;KAC3B,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, TokenCredential } from \"@azure/core-auth\";\nimport { signString } from \"./hmacSha256.js\";\n\n/**\n * Represents a named key credential.\n */\nexport interface NamedKeyCredential {\n /**\n * The Shared Access Signature key name.\n */\n sharedAccessKeyName: string;\n\n /**\n * The Shared Access Signature key value.\n */\n sharedAccessKey: string;\n}\n\n/**\n * A TokenProvider that generates a Sas token:\n * `SharedAccessSignature sr=<resource>&sig=<signature>&se=<expiry>&skn=<keyname>`\n *\n * @internal\n */\nexport class SasTokenCredential implements TokenCredential {\n /**\n * The SASCredential containing the key name and secret key value.\n */\n private _credential: NamedKeyCredential;\n\n /**\n * Initializes a new instance of SasTokenProvider\n * @param credential - The source `NamedKeyCredential` or `SASCredential`.\n */\n constructor(credential: NamedKeyCredential) {\n this._credential = credential;\n }\n\n /**\n * Gets the sas token for the specified audience\n * @param scopes - The scope for which the token is desired.\n */\n async getToken(scopes: string | string[]): Promise<AccessToken | null> {\n const audience = Array.isArray(scopes) ? scopes[0] : scopes;\n return createToken(\n this._credential.sharedAccessKeyName,\n this._credential.sharedAccessKey,\n Math.floor(Date.now() / 1000) + 3600,\n audience,\n );\n }\n}\n\n/**\n * Creates the sas token based on the provided information.\n * @param keyName - The shared access key name.\n * @param key - The shared access key.\n * @param expiry - The time period in unix time after which the token will expire.\n * @param audience - The audience for which the token is desired.\n * @internal\n */\nasync function createToken(\n keyName: string,\n key: string,\n expiry: number,\n audience: string,\n): Promise<AccessToken> {\n audience = encodeURIComponent(audience.toLowerCase());\n keyName = encodeURIComponent(keyName);\n const stringToSign = audience + \"\\n\" + expiry;\n const sig = await signString(key, stringToSign);\n\n return {\n token: `SharedAccessSignature sr=${audience}&sig=${sig}&se=${expiry}&skn=${keyName}`,\n expiresOnTimestamp: expiry,\n };\n}\n"]}
|
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
* @returns The newly created Apple installation.
|
|
7
7
|
*/
|
|
8
8
|
export function createAppleInstallation(installation) {
|
|
9
|
-
return
|
|
9
|
+
return {
|
|
10
|
+
...installation,
|
|
11
|
+
platform: "apns",
|
|
12
|
+
};
|
|
10
13
|
}
|
|
11
14
|
/**
|
|
12
15
|
* Creates an Amazon Device Messaging (ADM) based installation.
|
|
@@ -14,7 +17,10 @@ export function createAppleInstallation(installation) {
|
|
|
14
17
|
* @returns The newly created ADM installation.
|
|
15
18
|
*/
|
|
16
19
|
export function createAdmInstallation(installation) {
|
|
17
|
-
return
|
|
20
|
+
return {
|
|
21
|
+
...installation,
|
|
22
|
+
platform: "adm",
|
|
23
|
+
};
|
|
18
24
|
}
|
|
19
25
|
/**
|
|
20
26
|
* Creates a Baidu based installation.
|
|
@@ -22,7 +28,10 @@ export function createAdmInstallation(installation) {
|
|
|
22
28
|
* @returns The newly created Baidu installation.
|
|
23
29
|
*/
|
|
24
30
|
export function createBaiduInstallation(installation) {
|
|
25
|
-
return
|
|
31
|
+
return {
|
|
32
|
+
...installation,
|
|
33
|
+
platform: "baidu",
|
|
34
|
+
};
|
|
26
35
|
}
|
|
27
36
|
/**
|
|
28
37
|
* Creates a Firebase legacy HTTP based installation.
|
|
@@ -30,7 +39,10 @@ export function createBaiduInstallation(installation) {
|
|
|
30
39
|
* @returns The newly created Baidu installation.
|
|
31
40
|
*/
|
|
32
41
|
export function createFcmLegacyInstallation(installation) {
|
|
33
|
-
return
|
|
42
|
+
return {
|
|
43
|
+
...installation,
|
|
44
|
+
platform: "gcm",
|
|
45
|
+
};
|
|
34
46
|
}
|
|
35
47
|
/**
|
|
36
48
|
* Creates an Firebase V1 Cloud Messaging based installation.
|
|
@@ -38,7 +50,10 @@ export function createFcmLegacyInstallation(installation) {
|
|
|
38
50
|
* @returns The newly created Firebase V1 Cloud Messaging installation.
|
|
39
51
|
*/
|
|
40
52
|
export function createFcmV1Installation(installation) {
|
|
41
|
-
return
|
|
53
|
+
return {
|
|
54
|
+
...installation,
|
|
55
|
+
platform: "fcmv1",
|
|
56
|
+
};
|
|
42
57
|
}
|
|
43
58
|
/**
|
|
44
59
|
* Creates a Xiaomi based installation.
|
|
@@ -46,7 +61,10 @@ export function createFcmV1Installation(installation) {
|
|
|
46
61
|
* @returns The newly created Xiaomi installation.
|
|
47
62
|
*/
|
|
48
63
|
export function createXiaomiInstallation(installation) {
|
|
49
|
-
return
|
|
64
|
+
return {
|
|
65
|
+
...installation,
|
|
66
|
+
platform: "xiaomi",
|
|
67
|
+
};
|
|
50
68
|
}
|
|
51
69
|
/**
|
|
52
70
|
* Creates a Windows Notification Services (WNS) based installation.
|
|
@@ -54,7 +72,10 @@ export function createXiaomiInstallation(installation) {
|
|
|
54
72
|
* @returns The newly created WNS installation.
|
|
55
73
|
*/
|
|
56
74
|
export function createWindowsInstallation(installation) {
|
|
57
|
-
return
|
|
75
|
+
return {
|
|
76
|
+
...installation,
|
|
77
|
+
platform: "wns",
|
|
78
|
+
};
|
|
58
79
|
}
|
|
59
80
|
/**
|
|
60
81
|
* Creates a Web Push based installation.
|
|
@@ -62,6 +83,9 @@ export function createWindowsInstallation(installation) {
|
|
|
62
83
|
* @returns The newly created Web Push installation.
|
|
63
84
|
*/
|
|
64
85
|
export function createBrowserInstallation(installation) {
|
|
65
|
-
return
|
|
86
|
+
return {
|
|
87
|
+
...installation,
|
|
88
|
+
platform: "browser",
|
|
89
|
+
};
|
|
66
90
|
}
|
|
67
91
|
//# sourceMappingURL=installation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installation.js","sourceRoot":"","sources":["../../../src/models/installation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAmElC;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,YAAqC;IAC3E,
|
|
1
|
+
{"version":3,"file":"installation.js","sourceRoot":"","sources":["../../../src/models/installation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAmElC;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,YAAqC;IAC3E,OAAO;QACL,GAAG,YAAY;QACf,QAAQ,EAAE,MAAM;KACjB,CAAC;AACJ,CAAC;AAYD;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,YAAqC;IACzE,OAAO;QACL,GAAG,YAAY;QACf,QAAQ,EAAE,KAAK;KAChB,CAAC;AACJ,CAAC;AAYD;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,YAAqC;IAC3E,OAAO;QACL,GAAG,YAAY;QACf,QAAQ,EAAE,OAAO;KAClB,CAAC;AACJ,CAAC;AAYD;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CACzC,YAAqC;IAErC,OAAO;QACL,GAAG,YAAY;QACf,QAAQ,EAAE,KAAK;KAChB,CAAC;AACJ,CAAC;AAYD;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,YAAqC;IAC3E,OAAO;QACL,GAAG,YAAY;QACf,QAAQ,EAAE,OAAO;KAClB,CAAC;AACJ,CAAC;AAYD;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CACtC,YAAqC;IAErC,OAAO;QACL,GAAG,YAAY;QACf,QAAQ,EAAE,QAAQ;KACnB,CAAC;AACJ,CAAC;AAYD;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACvC,YAAqC;IAErC,OAAO;QACL,GAAG,YAAY;QACf,QAAQ,EAAE,KAAK;KAChB,CAAC;AACJ,CAAC;AA0CD;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACvC,YAAuC;IAEvC,OAAO;QACL,GAAG,YAAY;QACf,QAAQ,EAAE,SAAS;KACpB,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Represents an installation for a device for Notification Hubs.\n */\nexport interface InstallationCommon {\n /**\n * The ID for the installation.\n */\n installationId: string;\n\n /**\n * The User ID for the installation used for targeting.\n */\n userId?: string;\n\n /**\n * The installation expiration time.\n */\n readonly expirationTime?: string;\n\n /**\n * The last update date of the installation.\n */\n readonly lastUpdate?: string;\n\n /**\n * The tags used for targeting this installation.\n */\n tags?: string[];\n\n /**\n * The templates for the installation.\n */\n templates?: Record<string, InstallationTemplate>;\n\n /**\n * This parameter is true if the PNS expired the channel.\n */\n readonly pushChannelExpired?: boolean;\n\n /**\n * The push variables for the installation.\n */\n pushVariables?: Record<string, string>;\n}\n\n/**\n * Represents an installation with a string based device token.\n */\nexport interface DeviceTokenInstallation extends InstallationCommon {\n /**\n * The push channel for a device.\n */\n pushChannel: string;\n}\n\n/**\n * Represents an Apple APNs based installation.\n */\nexport interface AppleInstallation extends DeviceTokenInstallation {\n /**\n * The platform for the installation.\n */\n platform: \"apns\";\n}\n\n/**\n * Creates an Apple based installation.\n * @param installation - A partial installation used to create the Apple installation.\n * @returns The newly created Apple installation.\n */\nexport function createAppleInstallation(installation: DeviceTokenInstallation): AppleInstallation {\n return {\n ...installation,\n platform: \"apns\",\n };\n}\n\n/**\n * Represents an Amazon Device Messaging (ADM) based installation.\n */\nexport interface AdmInstallation extends DeviceTokenInstallation {\n /**\n * The platform for the installation.\n */\n platform: \"adm\";\n}\n\n/**\n * Creates an Amazon Device Messaging (ADM) based installation.\n * @param installation - A partial installation used to create the ADM installation.\n * @returns The newly created ADM installation.\n */\nexport function createAdmInstallation(installation: DeviceTokenInstallation): AdmInstallation {\n return {\n ...installation,\n platform: \"adm\",\n };\n}\n\n/**\n * Represents a Baidu based installation.\n */\nexport interface BaiduInstallation extends DeviceTokenInstallation {\n /**\n * The platform for the installation.\n */\n platform: \"baidu\";\n}\n\n/**\n * Creates a Baidu based installation.\n * @param installation - A partial installation used to create the Baidu installation.\n * @returns The newly created Baidu installation.\n */\nexport function createBaiduInstallation(installation: DeviceTokenInstallation): BaiduInstallation {\n return {\n ...installation,\n platform: \"baidu\",\n };\n}\n\n/**\n * Represents a Firebase Legacy HTTP installation.\n */\nexport interface FcmLegacyInstallation extends DeviceTokenInstallation {\n /**\n * The platform for the installation.\n */\n platform: \"gcm\";\n}\n\n/**\n * Creates a Firebase legacy HTTP based installation.\n * @param installation - A partial installation used to create the Firebase Legacy HTTP installation.\n * @returns The newly created Baidu installation.\n */\nexport function createFcmLegacyInstallation(\n installation: DeviceTokenInstallation,\n): FcmLegacyInstallation {\n return {\n ...installation,\n platform: \"gcm\",\n };\n}\n\n/**\n * Represents an Firebase V1 Cloud Messaging based installation.\n */\nexport interface FcmV1Installation extends DeviceTokenInstallation {\n /**\n * The platform for the installation.\n */\n platform: \"fcmv1\";\n}\n\n/**\n * Creates an Firebase V1 Cloud Messaging based installation.\n * @param installation - A partial installation used to create the Firebase V1 Cloud Messaging installation.\n * @returns The newly created Firebase V1 Cloud Messaging installation.\n */\nexport function createFcmV1Installation(installation: DeviceTokenInstallation): FcmV1Installation {\n return {\n ...installation,\n platform: \"fcmv1\",\n };\n}\n\n/**\n * Represents a Xiaomi based installation.\n */\nexport interface XiaomiInstallation extends DeviceTokenInstallation {\n /**\n * The platform for the installation.\n */\n platform: \"xiaomi\";\n}\n\n/**\n * Creates a Xiaomi based installation.\n * @param installation - A partial installation used to create the Xiaomi installation.\n * @returns The newly created Xiaomi installation.\n */\nexport function createXiaomiInstallation(\n installation: DeviceTokenInstallation,\n): XiaomiInstallation {\n return {\n ...installation,\n platform: \"xiaomi\",\n };\n}\n\n/**\n * Represents a Windows Notification Services (WNS) based installation.\n */\nexport interface WindowsInstallation extends DeviceTokenInstallation {\n /**\n * The platform for the installation.\n */\n platform: \"wns\";\n}\n\n/**\n * Creates a Windows Notification Services (WNS) based installation.\n * @param installation - A partial installation used to create the WNS installation.\n * @returns The newly created WNS installation.\n */\nexport function createWindowsInstallation(\n installation: DeviceTokenInstallation,\n): WindowsInstallation {\n return {\n ...installation,\n platform: \"wns\",\n };\n}\n\n/**\n * Represents the push channel for a Browser Push installation.\n */\nexport interface BrowserPushChannel {\n /**\n * The P256DH for the browser push installation.\n */\n p256dh: string;\n\n /**\n * The auth secret for the browser push installation.\n */\n auth: string;\n\n /**\n * The endpoint URL for the browser push installation.\n */\n endpoint: string;\n}\n\n/**\n * Represents a Browser/Web Push based installation.\n */\nexport interface BrowserInstallationCommon extends InstallationCommon {\n /**\n * The push channel for the Web Push API.\n */\n pushChannel: BrowserPushChannel;\n}\n\n/**\n * Represents a Browser/Web Push based installation.\n */\nexport interface BrowserInstallation extends BrowserInstallationCommon {\n /**\n * The platform for the installation.\n */\n platform: \"browser\";\n}\n\n/**\n * Creates a Web Push based installation.\n * @param installation - A partial installation used to create the Web Push installation.\n * @returns The newly created Web Push installation.\n */\nexport function createBrowserInstallation(\n installation: BrowserInstallationCommon,\n): BrowserInstallation {\n return {\n ...installation,\n platform: \"browser\",\n };\n}\n\n/**\n * Represents the types of installations available in Notification Hubs.\n */\nexport type Installation =\n | AppleInstallation\n | AdmInstallation\n | BaiduInstallation\n | BrowserInstallation\n | FcmLegacyInstallation\n | FcmV1Installation\n | XiaomiInstallation\n | WindowsInstallation;\n\n/**\n * Represents an installation template.\n */\nexport interface InstallationTemplate {\n /**\n * The body for the installation template.\n */\n body: string;\n\n /**\n * Headers to include for the template send.\n */\n headers: Record<string, string>;\n\n /**\n * The tags to include for the template.\n */\n tags?: string[];\n}\n\n/**\n * Represents the JSON Patch types of add, remove and replace.\n */\nexport type JsonPatchOperation = \"add\" | \"remove\" | \"replace\";\n\n/**\n * Represents a patch operation.\n */\nexport interface JsonPatch {\n /**\n * The patch operation.\n */\n op: JsonPatchOperation;\n\n /**\n * The path for the patch operation.\n */\n path: string;\n\n /**\n * The value to add or replace for the operation.\n */\n value?: string;\n}\n\n/**\n * Represents the types of push channels available for Notification Hubs.\n */\nexport type PushHandle = BrowserPushChannel | string;\n"]}
|
|
@@ -11,7 +11,12 @@ function isString(value) {
|
|
|
11
11
|
*/
|
|
12
12
|
export function createAppleNotification(notification) {
|
|
13
13
|
const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);
|
|
14
|
-
return
|
|
14
|
+
return {
|
|
15
|
+
...notification,
|
|
16
|
+
body,
|
|
17
|
+
platform: "apple",
|
|
18
|
+
contentType: Constants.JSON_CONTENT_TYPE,
|
|
19
|
+
};
|
|
15
20
|
}
|
|
16
21
|
/**
|
|
17
22
|
* Creates a notification to send to an Amazon Device Messaging device.
|
|
@@ -20,7 +25,12 @@ export function createAppleNotification(notification) {
|
|
|
20
25
|
*/
|
|
21
26
|
export function createAdmNotification(notification) {
|
|
22
27
|
const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);
|
|
23
|
-
return
|
|
28
|
+
return {
|
|
29
|
+
...notification,
|
|
30
|
+
body,
|
|
31
|
+
platform: "adm",
|
|
32
|
+
contentType: Constants.JSON_CONTENT_TYPE,
|
|
33
|
+
};
|
|
24
34
|
}
|
|
25
35
|
/**
|
|
26
36
|
* Creates a notification to send to a Baidu registered device.
|
|
@@ -29,7 +39,12 @@ export function createAdmNotification(notification) {
|
|
|
29
39
|
*/
|
|
30
40
|
export function createBaiduNotification(notification) {
|
|
31
41
|
const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);
|
|
32
|
-
return
|
|
42
|
+
return {
|
|
43
|
+
...notification,
|
|
44
|
+
body,
|
|
45
|
+
platform: "baidu",
|
|
46
|
+
contentType: Constants.JSON_CONTENT_TYPE,
|
|
47
|
+
};
|
|
33
48
|
}
|
|
34
49
|
/**
|
|
35
50
|
* Creates a notification to send to a browser.
|
|
@@ -38,7 +53,12 @@ export function createBaiduNotification(notification) {
|
|
|
38
53
|
*/
|
|
39
54
|
export function createBrowserNotification(notification) {
|
|
40
55
|
const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);
|
|
41
|
-
return
|
|
56
|
+
return {
|
|
57
|
+
...notification,
|
|
58
|
+
body,
|
|
59
|
+
platform: "browser",
|
|
60
|
+
contentType: Constants.JSON_CONTENT_TYPE,
|
|
61
|
+
};
|
|
42
62
|
}
|
|
43
63
|
/**
|
|
44
64
|
* Creates a notification to send to Firebase.
|
|
@@ -47,7 +67,12 @@ export function createBrowserNotification(notification) {
|
|
|
47
67
|
*/
|
|
48
68
|
export function createFcmLegacyNotification(notification) {
|
|
49
69
|
const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);
|
|
50
|
-
return
|
|
70
|
+
return {
|
|
71
|
+
...notification,
|
|
72
|
+
body,
|
|
73
|
+
platform: "gcm",
|
|
74
|
+
contentType: Constants.JSON_CONTENT_TYPE,
|
|
75
|
+
};
|
|
51
76
|
}
|
|
52
77
|
/**
|
|
53
78
|
* Creates a notification to send to Firebase.
|
|
@@ -56,7 +81,12 @@ export function createFcmLegacyNotification(notification) {
|
|
|
56
81
|
*/
|
|
57
82
|
export function createFcmV1Notification(notification) {
|
|
58
83
|
const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);
|
|
59
|
-
return
|
|
84
|
+
return {
|
|
85
|
+
...notification,
|
|
86
|
+
body,
|
|
87
|
+
platform: "fcmv1",
|
|
88
|
+
contentType: Constants.JSON_CONTENT_TYPE,
|
|
89
|
+
};
|
|
60
90
|
}
|
|
61
91
|
/**
|
|
62
92
|
* Creates a notification to send to Xiaomi.
|
|
@@ -65,7 +95,12 @@ export function createFcmV1Notification(notification) {
|
|
|
65
95
|
*/
|
|
66
96
|
export function createXiaomiNotification(notification) {
|
|
67
97
|
const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);
|
|
68
|
-
return
|
|
98
|
+
return {
|
|
99
|
+
...notification,
|
|
100
|
+
body,
|
|
101
|
+
platform: "xiaomi",
|
|
102
|
+
contentType: Constants.JSON_CONTENT_TYPE,
|
|
103
|
+
};
|
|
69
104
|
}
|
|
70
105
|
/**
|
|
71
106
|
* Creates a template notification.
|
|
@@ -74,7 +109,12 @@ export function createXiaomiNotification(notification) {
|
|
|
74
109
|
*/
|
|
75
110
|
export function createTemplateNotification(notification) {
|
|
76
111
|
const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);
|
|
77
|
-
return
|
|
112
|
+
return {
|
|
113
|
+
...notification,
|
|
114
|
+
body,
|
|
115
|
+
platform: "template",
|
|
116
|
+
contentType: Constants.JSON_CONTENT_TYPE,
|
|
117
|
+
};
|
|
78
118
|
}
|
|
79
119
|
/**
|
|
80
120
|
* Creates a notification to send to WNS.
|
|
@@ -82,7 +122,7 @@ export function createTemplateNotification(notification) {
|
|
|
82
122
|
* @returns A newly created WNS message.
|
|
83
123
|
*/
|
|
84
124
|
export function createWindowsNotification(notification) {
|
|
85
|
-
if (
|
|
125
|
+
if (notification?.headers && notification.headers["X-WNS-Type"]) {
|
|
86
126
|
const wnsType = notification.headers["X-WNS-Type"];
|
|
87
127
|
switch (wnsType) {
|
|
88
128
|
case Constants.WNS_TOAST:
|
|
@@ -107,7 +147,11 @@ export function createWindowsNotification(notification) {
|
|
|
107
147
|
* @returns A newly created WNS badge.
|
|
108
148
|
*/
|
|
109
149
|
export function createWindowsBadgeNotification(notification) {
|
|
110
|
-
const result =
|
|
150
|
+
const result = {
|
|
151
|
+
...notification,
|
|
152
|
+
platform: "windows",
|
|
153
|
+
contentType: Constants.XML_CONTENT_TYPE,
|
|
154
|
+
};
|
|
111
155
|
if (!result.headers) {
|
|
112
156
|
result.headers = {};
|
|
113
157
|
}
|
|
@@ -122,7 +166,11 @@ export function createWindowsBadgeNotification(notification) {
|
|
|
122
166
|
* @returns A newly created WNS tile.
|
|
123
167
|
*/
|
|
124
168
|
export function createWindowsTileNotification(notification) {
|
|
125
|
-
const result =
|
|
169
|
+
const result = {
|
|
170
|
+
...notification,
|
|
171
|
+
platform: "windows",
|
|
172
|
+
contentType: Constants.XML_CONTENT_TYPE,
|
|
173
|
+
};
|
|
126
174
|
if (!result.headers) {
|
|
127
175
|
result.headers = {};
|
|
128
176
|
}
|
|
@@ -137,7 +185,11 @@ export function createWindowsTileNotification(notification) {
|
|
|
137
185
|
* @returns A newly created WNS toast.
|
|
138
186
|
*/
|
|
139
187
|
export function createWindowsToastNotification(notification) {
|
|
140
|
-
const result =
|
|
188
|
+
const result = {
|
|
189
|
+
...notification,
|
|
190
|
+
platform: "windows",
|
|
191
|
+
contentType: Constants.XML_CONTENT_TYPE,
|
|
192
|
+
};
|
|
141
193
|
if (!result.headers) {
|
|
142
194
|
result.headers = {};
|
|
143
195
|
}
|
|
@@ -152,7 +204,11 @@ export function createWindowsToastNotification(notification) {
|
|
|
152
204
|
* @returns A newly created WNS message using XML.
|
|
153
205
|
*/
|
|
154
206
|
export function createWindowsRawNotification(notification) {
|
|
155
|
-
const result =
|
|
207
|
+
const result = {
|
|
208
|
+
...notification,
|
|
209
|
+
platform: "windows",
|
|
210
|
+
contentType: Constants.STREAM_CONTENT_TYPE,
|
|
211
|
+
};
|
|
156
212
|
if (!result.headers) {
|
|
157
213
|
result.headers = {};
|
|
158
214
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification.js","sourceRoot":"","sources":["../../../src/models/notification.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AASnD,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,MAAM,CAAC;AAC9D,CAAC;AAmED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,YAAqC;IAC3E,MAAM,IAAI,GAAG,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,IA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AAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,aAAa,CAAC,EAAE,CAAC;QAC7C,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,aAAa,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC;IAC9D,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport * as Constants from \"../utils/constants.js\";\nimport type {\n AdmNativeMessage,\n AppleNativeMessage,\n FirebaseLegacyNativeMessage,\n FirebaseV1NativeMessage,\n} from \"./notificationBodyBuilder.js\";\nimport type { AppleHeaders, WindowsHeaders } from \"./notificationHeaderBuilder.js\";\n\nfunction isString(value: unknown): value is string {\n return typeof value === \"string\" || value instanceof String;\n}\n\n/**\n * Represents a notification that can be sent to a device.\n */\nexport interface NotificationCommon {\n /**\n * The body for the push notification.\n */\n body: string;\n\n /**\n * The headers to include for the push notification.\n */\n headers?: Record<string, unknown>;\n}\n\n/**\n * The common notification parameters to accept a string body or JSON body.\n */\nexport interface NotificationCommonParams {\n /**\n * The body for the push notification.\n */\n body: string | unknown;\n\n /**\n * The headers to include for the push notification.\n */\n headers?: Record<string, unknown>;\n}\n\n/**\n * Represents a JSON notification hub.\n */\nexport interface JsonNotification extends NotificationCommon {\n /**\n * The content type for the push notification.\n */\n contentType: \"application/json;charset=utf-8\";\n}\n\n/**\n * Represents an Apple APNs push notification.\n */\nexport interface AppleNotification extends JsonNotification {\n /**\n * The platform for the push notification.\n */\n platform: \"apple\";\n}\n\n/**\n * Represents an Apple notification that can be sent to a device.\n */\nexport interface AppleNotificationParams {\n /**\n * The body for the push notification.\n */\n body: string | AppleNativeMessage;\n\n /**\n * The headers to include for the push notification.\n */\n headers?: AppleHeaders;\n}\n\n/**\n * Creates a notification to send to an Apple device.\n * @param notification - A partial message used to create a message for Apple.\n * @returns A newly created Apple.\n */\nexport function createAppleNotification(notification: AppleNotificationParams): AppleNotification {\n const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);\n\n return {\n ...notification,\n body,\n platform: \"apple\",\n contentType: Constants.JSON_CONTENT_TYPE,\n };\n}\n\n/**\n * Represents an Amazon Device Messaging (ADM) push notification.\n */\nexport interface AdmNotification extends JsonNotification {\n /**\n * The platform for the push notification.\n */\n platform: \"adm\";\n}\n\n/**\n * Represents an ADM notification that can be sent to a device.\n */\nexport interface AdmNotificationParams {\n /**\n * The body for the push notification.\n */\n body: string | AdmNativeMessage;\n\n /**\n * The headers to include for the push notification.\n */\n headers?: Record<string, string>;\n}\n\n/**\n * Creates a notification to send to an Amazon Device Messaging device.\n * @param notification - A partial message used to create a message for Amazon Device Messaging.\n * @returns A newly created Amazon Device Messaging.\n */\nexport function createAdmNotification(notification: AdmNotificationParams): AdmNotification {\n const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);\n\n return {\n ...notification,\n body,\n platform: \"adm\",\n contentType: Constants.JSON_CONTENT_TYPE,\n };\n}\n\n/**\n * Represents a Baidu push notification.\n */\nexport interface BaiduNotification extends JsonNotification {\n /**\n * The platform for the push notification.\n */\n platform: \"baidu\";\n}\n\n/**\n * Creates a notification to send to a Baidu registered device.\n * @param notification - A partial message used to create a message for Baidu.\n * @returns A newly created Baidu.\n */\nexport function createBaiduNotification(notification: NotificationCommonParams): BaiduNotification {\n const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);\n\n return {\n ...notification,\n body,\n platform: \"baidu\",\n contentType: Constants.JSON_CONTENT_TYPE,\n };\n}\n\n/**\n * Represents a Browser push notification.\n */\nexport interface BrowserNotification extends JsonNotification {\n /**\n * The platform for the push notification.\n */\n platform: \"browser\";\n}\n\n/**\n * Creates a notification to send to a browser.\n * @param notification - A partial message used to create a message for a browser.\n * @returns A newly created Web Push browser.\n */\nexport function createBrowserNotification(\n notification: NotificationCommonParams,\n): BrowserNotification {\n const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);\n\n return {\n ...notification,\n body,\n platform: \"browser\",\n contentType: Constants.JSON_CONTENT_TYPE,\n };\n}\n\n/**\n * Represents a Firebase legacy HTTP push notification.\n */\nexport interface FcmLegacyNotification extends JsonNotification {\n /**\n * The platform for the push notification.\n */\n platform: \"gcm\";\n}\n\n/**\n * Represents an Firebase Legacy notification that can be sent to a device.\n */\nexport interface FcmLegacyNotificationParams {\n /**\n * The body for the push notification.\n */\n body: string | FirebaseLegacyNativeMessage;\n\n /**\n * The headers to include for the push notification.\n */\n headers?: Record<string, string>;\n}\n\n/**\n * Creates a notification to send to Firebase.\n * @param notification - A partial message used to create a message for Firebase.\n * @returns A newly created Firebase notification.\n */\nexport function createFcmLegacyNotification(\n notification: FcmLegacyNotificationParams,\n): FcmLegacyNotification {\n const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);\n\n return {\n ...notification,\n body,\n platform: \"gcm\",\n contentType: Constants.JSON_CONTENT_TYPE,\n };\n}\n\n/**\n * Represents an Firebase V1 API notification that can be sent to a device.\n */\nexport interface FcmV1Notification extends JsonNotification {\n /**\n * The platform for the push notification.\n */\n platform: \"fcmv1\";\n}\n\n/**\n * Represents an Firebase V1 notification that can be sent to a device.\n */\nexport interface FcmV1NotificationParams {\n /**\n * The body for the push notification.\n */\n body: string | FirebaseV1NativeMessage;\n\n /**\n * The headers to include for the push notification.\n */\n headers?: Record<string, string>;\n}\n\n/**\n * Creates a notification to send to Firebase.\n * @param notification - A partial message used to create a message for Firebase.\n * @returns A newly created Firebase notification.\n */\nexport function createFcmV1Notification(notification: FcmV1NotificationParams): FcmV1Notification {\n const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);\n\n return {\n ...notification,\n body,\n platform: \"fcmv1\",\n contentType: Constants.JSON_CONTENT_TYPE,\n };\n}\n\n/**\n * Represents a Xiaomi push notification.\n */\nexport interface XiaomiNotification extends JsonNotification {\n /**\n * The platform for the push notification.\n */\n platform: \"xiaomi\";\n}\n\n/**\n * Creates a notification to send to Xiaomi.\n * @param notification - A partial message used to create a message for Xiaomi.\n * @returns A newly created Xiaomi notification.\n */\nexport function createXiaomiNotification(\n notification: NotificationCommonParams,\n): XiaomiNotification {\n const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);\n\n return {\n ...notification,\n body,\n platform: \"xiaomi\",\n contentType: Constants.JSON_CONTENT_TYPE,\n };\n}\n\n/**\n * Represents a template based push notification.\n */\nexport interface TemplateNotification extends JsonNotification {\n /**\n * The platform for the push notification.\n */\n platform: \"template\";\n}\n\n/**\n * Creates a template notification.\n * @param notification - A partial message used to be used for a template notification.\n * @returns A newly created Firebase.\n */\nexport function createTemplateNotification(\n notification: NotificationCommonParams,\n): TemplateNotification {\n const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);\n\n return {\n ...notification,\n body,\n platform: \"template\",\n contentType: Constants.JSON_CONTENT_TYPE,\n };\n}\n\n/**\n * Represents the possible WNS content-types.\n */\nexport type WindowsContentType = \"application/xml\" | \"application/octet-stream\";\n\n/**\n * Represents a Windows Notification Services (WNS) push notification.\n */\nexport interface WindowsNotification extends NotificationCommon {\n /**\n * The platform for the push notification.\n */\n platform: \"windows\";\n\n /**\n * The content type for the push notification.\n */\n contentType: WindowsContentType;\n}\n\n/**\n * Represents a WNS notification that can be sent to a device.\n */\nexport interface WnsNotificationParams {\n /**\n * The body for the push notification.\n */\n body: string;\n\n /**\n * The headers to include for the push notification.\n */\n headers?: WindowsHeaders;\n}\n\n/**\n * Creates a notification to send to WNS.\n * @param notification - The WNS notification to send.\n * @returns A newly created WNS message.\n */\nexport function createWindowsNotification(\n notification: WnsNotificationParams,\n): WindowsNotification {\n if (notification?.headers && notification.headers[\"X-WNS-Type\"]) {\n const wnsType = notification.headers[\"X-WNS-Type\"];\n switch (wnsType) {\n case Constants.WNS_TOAST:\n return createWindowsToastNotification(notification);\n case Constants.WNS_TITLE:\n return createWindowsTileNotification(notification);\n case Constants.WNS_BADGE:\n return createWindowsBadgeNotification(notification);\n case Constants.WNS_RAW:\n return createWindowsRawNotification(notification);\n default:\n throw new Error(`Invalid WNS type: ${wnsType}`);\n }\n } else {\n throw new Error(`Missing WNS type in headers`);\n }\n}\n\n/**\n * Creates a badge message to send to WNS.\n * @param notification - A partial message used to create a badge message for WNS.\n * @returns A newly created WNS badge.\n */\nexport function createWindowsBadgeNotification(\n notification: WnsNotificationParams,\n): WindowsNotification {\n const result: WindowsNotification = {\n ...notification,\n platform: \"windows\",\n contentType: Constants.XML_CONTENT_TYPE,\n };\n\n if (!result.headers) {\n result.headers = {};\n }\n\n if (!result.headers[Constants.WNS_TYPE_NAME]) {\n result.headers[Constants.WNS_TYPE_NAME] = Constants.WNS_BADGE;\n }\n\n return result;\n}\n\n/**\n * Creates a tile message to send to WNS.\n * @param notification - A partial message used to create a tile message for WNS.\n * @returns A newly created WNS tile.\n */\nexport function createWindowsTileNotification(\n notification: WnsNotificationParams,\n): WindowsNotification {\n const result: WindowsNotification = {\n ...notification,\n platform: \"windows\",\n contentType: Constants.XML_CONTENT_TYPE,\n };\n\n if (!result.headers) {\n result.headers = {};\n }\n\n if (!result.headers[Constants.WNS_TYPE_NAME]) {\n result.headers[Constants.WNS_TYPE_NAME] = Constants.WNS_TITLE;\n }\n\n return result;\n}\n\n/**\n * Creates a toast message to send to WNS.\n * @param notification - A partial message used to create a toast message for WNS.\n * @returns A newly created WNS toast.\n */\nexport function createWindowsToastNotification(\n notification: WnsNotificationParams,\n): WindowsNotification {\n const result: WindowsNotification = {\n ...notification,\n platform: \"windows\",\n contentType: Constants.XML_CONTENT_TYPE,\n };\n\n if (!result.headers) {\n result.headers = {};\n }\n\n if (!result.headers[Constants.WNS_TYPE_NAME]) {\n result.headers[Constants.WNS_TYPE_NAME] = Constants.WNS_TOAST;\n }\n\n return result;\n}\n\n/**\n * Creates a notification to send to WNS in wns/raw format..\n * @param notification - A partial message used to create a message for WNS in XML format.\n * @returns A newly created WNS message using XML.\n */\nexport function createWindowsRawNotification(\n notification: WnsNotificationParams,\n): WindowsNotification {\n const result: WindowsNotification = {\n ...notification,\n platform: \"windows\",\n contentType: Constants.STREAM_CONTENT_TYPE,\n };\n\n if (!result.headers) {\n result.headers = {};\n }\n\n if (!result.headers[Constants.WNS_TYPE_NAME]) {\n result.headers[Constants.WNS_TYPE_NAME] = Constants.WNS_RAW;\n }\n\n return result;\n}\n\n/**\n * Represents the possible push notification messages types.\n */\nexport type Notification =\n | AppleNotification\n | AdmNotification\n | BaiduNotification\n | BrowserNotification\n | FcmLegacyNotification\n | FcmV1Notification\n | XiaomiNotification\n | WindowsNotification\n | TemplateNotification;\n"]}
|
|
1
|
+
{"version":3,"file":"notification.js","sourceRoot":"","sources":["../../../src/models/notification.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AASnD,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,MAAM,CAAC;AAC9D,CAAC;AAmED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,YAAqC;IAC3E,MAAM,IAAI,GAAG,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAEjG,OAAO;QACL,GAAG,YAAY;QACf,IAAI;QACJ,QAAQ,EAAE,OAAO;QACjB,WAAW,EAAE,SAAS,CAAC,iBAAiB;KACzC,CAAC;AACJ,CAAC;AA2BD;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,YAAmC;IACvE,MAAM,IAAI,GAAG,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAEjG,OAAO;QACL,GAAG,YAAY;QACf,IAAI;QACJ,QAAQ,EAAE,KAAK;QACf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AAC,SAAS,CAAC,aAAa,CAAC,EAAE,CAAC;QAC7C,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,aAAa,CAAC,GAAG,SAAS,CAAC,SAAS,CAAC;IAChE,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,8BAA8B,CAC5C,YAAmC;IAEnC,MAAM,MAAM,GAAwB;QAClC,GAAG,YAAY;QACf,QAAQ,EAAE,SAAS;QACnB,WAAW,EAAE,SAAS,CAAC,gBAAgB;KACxC,CAAC;IAEF,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,CAAC,OAAO,GAAG,EAAE,CAAC;IACtB,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,aAAa,CAAC,EAAE,CAAC;QAC7C,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,aAAa,CAAC,GAAG,SAAS,CAAC,SAAS,CAAC;IAChE,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAC1C,YAAmC;IAEnC,MAAM,MAAM,GAAwB;QAClC,GAAG,YAAY;QACf,QAAQ,EAAE,SAAS;QACnB,WAAW,EAAE,SAAS,CAAC,mBAAmB;KAC3C,CAAC;IAEF,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,CAAC,OAAO,GAAG,EAAE,CAAC;IACtB,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,aAAa,CAAC,EAAE,CAAC;QAC7C,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,aAAa,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC;IAC9D,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport * as Constants from \"../utils/constants.js\";\nimport type {\n AdmNativeMessage,\n AppleNativeMessage,\n FirebaseLegacyNativeMessage,\n FirebaseV1NativeMessage,\n} from \"./notificationBodyBuilder.js\";\nimport type { AppleHeaders, WindowsHeaders } from \"./notificationHeaderBuilder.js\";\n\nfunction isString(value: unknown): value is string {\n return typeof value === \"string\" || value instanceof String;\n}\n\n/**\n * Represents a notification that can be sent to a device.\n */\nexport interface NotificationCommon {\n /**\n * The body for the push notification.\n */\n body: string;\n\n /**\n * The headers to include for the push notification.\n */\n headers?: Record<string, unknown>;\n}\n\n/**\n * The common notification parameters to accept a string body or JSON body.\n */\nexport interface NotificationCommonParams {\n /**\n * The body for the push notification.\n */\n body: string | unknown;\n\n /**\n * The headers to include for the push notification.\n */\n headers?: Record<string, unknown>;\n}\n\n/**\n * Represents a JSON notification hub.\n */\nexport interface JsonNotification extends NotificationCommon {\n /**\n * The content type for the push notification.\n */\n contentType: \"application/json;charset=utf-8\";\n}\n\n/**\n * Represents an Apple APNs push notification.\n */\nexport interface AppleNotification extends JsonNotification {\n /**\n * The platform for the push notification.\n */\n platform: \"apple\";\n}\n\n/**\n * Represents an Apple notification that can be sent to a device.\n */\nexport interface AppleNotificationParams {\n /**\n * The body for the push notification.\n */\n body: string | AppleNativeMessage;\n\n /**\n * The headers to include for the push notification.\n */\n headers?: AppleHeaders;\n}\n\n/**\n * Creates a notification to send to an Apple device.\n * @param notification - A partial message used to create a message for Apple.\n * @returns A newly created Apple.\n */\nexport function createAppleNotification(notification: AppleNotificationParams): AppleNotification {\n const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);\n\n return {\n ...notification,\n body,\n platform: \"apple\",\n contentType: Constants.JSON_CONTENT_TYPE,\n };\n}\n\n/**\n * Represents an Amazon Device Messaging (ADM) push notification.\n */\nexport interface AdmNotification extends JsonNotification {\n /**\n * The platform for the push notification.\n */\n platform: \"adm\";\n}\n\n/**\n * Represents an ADM notification that can be sent to a device.\n */\nexport interface AdmNotificationParams {\n /**\n * The body for the push notification.\n */\n body: string | AdmNativeMessage;\n\n /**\n * The headers to include for the push notification.\n */\n headers?: Record<string, string>;\n}\n\n/**\n * Creates a notification to send to an Amazon Device Messaging device.\n * @param notification - A partial message used to create a message for Amazon Device Messaging.\n * @returns A newly created Amazon Device Messaging.\n */\nexport function createAdmNotification(notification: AdmNotificationParams): AdmNotification {\n const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);\n\n return {\n ...notification,\n body,\n platform: \"adm\",\n contentType: Constants.JSON_CONTENT_TYPE,\n };\n}\n\n/**\n * Represents a Baidu push notification.\n */\nexport interface BaiduNotification extends JsonNotification {\n /**\n * The platform for the push notification.\n */\n platform: \"baidu\";\n}\n\n/**\n * Creates a notification to send to a Baidu registered device.\n * @param notification - A partial message used to create a message for Baidu.\n * @returns A newly created Baidu.\n */\nexport function createBaiduNotification(notification: NotificationCommonParams): BaiduNotification {\n const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);\n\n return {\n ...notification,\n body,\n platform: \"baidu\",\n contentType: Constants.JSON_CONTENT_TYPE,\n };\n}\n\n/**\n * Represents a Browser push notification.\n */\nexport interface BrowserNotification extends JsonNotification {\n /**\n * The platform for the push notification.\n */\n platform: \"browser\";\n}\n\n/**\n * Creates a notification to send to a browser.\n * @param notification - A partial message used to create a message for a browser.\n * @returns A newly created Web Push browser.\n */\nexport function createBrowserNotification(\n notification: NotificationCommonParams,\n): BrowserNotification {\n const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);\n\n return {\n ...notification,\n body,\n platform: \"browser\",\n contentType: Constants.JSON_CONTENT_TYPE,\n };\n}\n\n/**\n * Represents a Firebase legacy HTTP push notification.\n */\nexport interface FcmLegacyNotification extends JsonNotification {\n /**\n * The platform for the push notification.\n */\n platform: \"gcm\";\n}\n\n/**\n * Represents an Firebase Legacy notification that can be sent to a device.\n */\nexport interface FcmLegacyNotificationParams {\n /**\n * The body for the push notification.\n */\n body: string | FirebaseLegacyNativeMessage;\n\n /**\n * The headers to include for the push notification.\n */\n headers?: Record<string, string>;\n}\n\n/**\n * Creates a notification to send to Firebase.\n * @param notification - A partial message used to create a message for Firebase.\n * @returns A newly created Firebase notification.\n */\nexport function createFcmLegacyNotification(\n notification: FcmLegacyNotificationParams,\n): FcmLegacyNotification {\n const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);\n\n return {\n ...notification,\n body,\n platform: \"gcm\",\n contentType: Constants.JSON_CONTENT_TYPE,\n };\n}\n\n/**\n * Represents an Firebase V1 API notification that can be sent to a device.\n */\nexport interface FcmV1Notification extends JsonNotification {\n /**\n * The platform for the push notification.\n */\n platform: \"fcmv1\";\n}\n\n/**\n * Represents an Firebase V1 notification that can be sent to a device.\n */\nexport interface FcmV1NotificationParams {\n /**\n * The body for the push notification.\n */\n body: string | FirebaseV1NativeMessage;\n\n /**\n * The headers to include for the push notification.\n */\n headers?: Record<string, string>;\n}\n\n/**\n * Creates a notification to send to Firebase.\n * @param notification - A partial message used to create a message for Firebase.\n * @returns A newly created Firebase notification.\n */\nexport function createFcmV1Notification(notification: FcmV1NotificationParams): FcmV1Notification {\n const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);\n\n return {\n ...notification,\n body,\n platform: \"fcmv1\",\n contentType: Constants.JSON_CONTENT_TYPE,\n };\n}\n\n/**\n * Represents a Xiaomi push notification.\n */\nexport interface XiaomiNotification extends JsonNotification {\n /**\n * The platform for the push notification.\n */\n platform: \"xiaomi\";\n}\n\n/**\n * Creates a notification to send to Xiaomi.\n * @param notification - A partial message used to create a message for Xiaomi.\n * @returns A newly created Xiaomi notification.\n */\nexport function createXiaomiNotification(\n notification: NotificationCommonParams,\n): XiaomiNotification {\n const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);\n\n return {\n ...notification,\n body,\n platform: \"xiaomi\",\n contentType: Constants.JSON_CONTENT_TYPE,\n };\n}\n\n/**\n * Represents a template based push notification.\n */\nexport interface TemplateNotification extends JsonNotification {\n /**\n * The platform for the push notification.\n */\n platform: \"template\";\n}\n\n/**\n * Creates a template notification.\n * @param notification - A partial message used to be used for a template notification.\n * @returns A newly created Firebase.\n */\nexport function createTemplateNotification(\n notification: NotificationCommonParams,\n): TemplateNotification {\n const body = isString(notification.body) ? notification.body : JSON.stringify(notification.body);\n\n return {\n ...notification,\n body,\n platform: \"template\",\n contentType: Constants.JSON_CONTENT_TYPE,\n };\n}\n\n/**\n * Represents the possible WNS content-types.\n */\nexport type WindowsContentType = \"application/xml\" | \"application/octet-stream\";\n\n/**\n * Represents a Windows Notification Services (WNS) push notification.\n */\nexport interface WindowsNotification extends NotificationCommon {\n /**\n * The platform for the push notification.\n */\n platform: \"windows\";\n\n /**\n * The content type for the push notification.\n */\n contentType: WindowsContentType;\n}\n\n/**\n * Represents a WNS notification that can be sent to a device.\n */\nexport interface WnsNotificationParams {\n /**\n * The body for the push notification.\n */\n body: string;\n\n /**\n * The headers to include for the push notification.\n */\n headers?: WindowsHeaders;\n}\n\n/**\n * Creates a notification to send to WNS.\n * @param notification - The WNS notification to send.\n * @returns A newly created WNS message.\n */\nexport function createWindowsNotification(\n notification: WnsNotificationParams,\n): WindowsNotification {\n if (notification?.headers && notification.headers[\"X-WNS-Type\"]) {\n const wnsType = notification.headers[\"X-WNS-Type\"];\n switch (wnsType) {\n case Constants.WNS_TOAST:\n return createWindowsToastNotification(notification);\n case Constants.WNS_TITLE:\n return createWindowsTileNotification(notification);\n case Constants.WNS_BADGE:\n return createWindowsBadgeNotification(notification);\n case Constants.WNS_RAW:\n return createWindowsRawNotification(notification);\n default:\n throw new Error(`Invalid WNS type: ${wnsType}`);\n }\n } else {\n throw new Error(`Missing WNS type in headers`);\n }\n}\n\n/**\n * Creates a badge message to send to WNS.\n * @param notification - A partial message used to create a badge message for WNS.\n * @returns A newly created WNS badge.\n */\nexport function createWindowsBadgeNotification(\n notification: WnsNotificationParams,\n): WindowsNotification {\n const result: WindowsNotification = {\n ...notification,\n platform: \"windows\",\n contentType: Constants.XML_CONTENT_TYPE,\n };\n\n if (!result.headers) {\n result.headers = {};\n }\n\n if (!result.headers[Constants.WNS_TYPE_NAME]) {\n result.headers[Constants.WNS_TYPE_NAME] = Constants.WNS_BADGE;\n }\n\n return result;\n}\n\n/**\n * Creates a tile message to send to WNS.\n * @param notification - A partial message used to create a tile message for WNS.\n * @returns A newly created WNS tile.\n */\nexport function createWindowsTileNotification(\n notification: WnsNotificationParams,\n): WindowsNotification {\n const result: WindowsNotification = {\n ...notification,\n platform: \"windows\",\n contentType: Constants.XML_CONTENT_TYPE,\n };\n\n if (!result.headers) {\n result.headers = {};\n }\n\n if (!result.headers[Constants.WNS_TYPE_NAME]) {\n result.headers[Constants.WNS_TYPE_NAME] = Constants.WNS_TITLE;\n }\n\n return result;\n}\n\n/**\n * Creates a toast message to send to WNS.\n * @param notification - A partial message used to create a toast message for WNS.\n * @returns A newly created WNS toast.\n */\nexport function createWindowsToastNotification(\n notification: WnsNotificationParams,\n): WindowsNotification {\n const result: WindowsNotification = {\n ...notification,\n platform: \"windows\",\n contentType: Constants.XML_CONTENT_TYPE,\n };\n\n if (!result.headers) {\n result.headers = {};\n }\n\n if (!result.headers[Constants.WNS_TYPE_NAME]) {\n result.headers[Constants.WNS_TYPE_NAME] = Constants.WNS_TOAST;\n }\n\n return result;\n}\n\n/**\n * Creates a notification to send to WNS in wns/raw format..\n * @param notification - A partial message used to create a message for WNS in XML format.\n * @returns A newly created WNS message using XML.\n */\nexport function createWindowsRawNotification(\n notification: WnsNotificationParams,\n): WindowsNotification {\n const result: WindowsNotification = {\n ...notification,\n platform: \"windows\",\n contentType: Constants.STREAM_CONTENT_TYPE,\n };\n\n if (!result.headers) {\n result.headers = {};\n }\n\n if (!result.headers[Constants.WNS_TYPE_NAME]) {\n result.headers[Constants.WNS_TYPE_NAME] = Constants.WNS_RAW;\n }\n\n return result;\n}\n\n/**\n * Represents the possible push notification messages types.\n */\nexport type Notification =\n | AppleNotification\n | AdmNotification\n | BaiduNotification\n | BrowserNotification\n | FcmLegacyNotification\n | FcmV1Notification\n | XiaomiNotification\n | WindowsNotification\n | TemplateNotification;\n"]}
|