@azure/eventgrid 4.12.0-alpha.20230517.3 → 4.13.0-beta.1

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.
Files changed (45) hide show
  1. package/dist/index.js +430 -4
  2. package/dist/index.js.map +1 -1
  3. package/dist-esm/src/cadl-generated/EventGridClient.js +28 -0
  4. package/dist-esm/src/cadl-generated/EventGridClient.js.map +1 -0
  5. package/dist-esm/src/cadl-generated/api/EventGridContext.js +11 -0
  6. package/dist-esm/src/cadl-generated/api/EventGridContext.js.map +1 -0
  7. package/dist-esm/src/cadl-generated/api/index.js +5 -0
  8. package/dist-esm/src/cadl-generated/api/index.js.map +1 -0
  9. package/dist-esm/src/cadl-generated/api/models.js +2 -0
  10. package/dist-esm/src/cadl-generated/api/models.js.map +1 -0
  11. package/dist-esm/src/cadl-generated/api/operations.js +162 -0
  12. package/dist-esm/src/cadl-generated/api/operations.js.map +1 -0
  13. package/dist-esm/src/cadl-generated/common/interfaces.js +4 -0
  14. package/dist-esm/src/cadl-generated/common/interfaces.js.map +1 -0
  15. package/dist-esm/src/cadl-generated/index.js +4 -0
  16. package/dist-esm/src/cadl-generated/index.js.map +1 -0
  17. package/dist-esm/src/cadl-generated/logger.js +5 -0
  18. package/dist-esm/src/cadl-generated/logger.js.map +1 -0
  19. package/dist-esm/src/cadl-generated/rest/clientDefinitions.js +4 -0
  20. package/dist-esm/src/cadl-generated/rest/clientDefinitions.js.map +1 -0
  21. package/dist-esm/src/cadl-generated/rest/eventGridClient.js +30 -0
  22. package/dist-esm/src/cadl-generated/rest/eventGridClient.js.map +1 -0
  23. package/dist-esm/src/cadl-generated/rest/index.js +12 -0
  24. package/dist-esm/src/cadl-generated/rest/index.js.map +1 -0
  25. package/dist-esm/src/cadl-generated/rest/isUnexpected.js +74 -0
  26. package/dist-esm/src/cadl-generated/rest/isUnexpected.js.map +1 -0
  27. package/dist-esm/src/cadl-generated/rest/models.js +4 -0
  28. package/dist-esm/src/cadl-generated/rest/models.js.map +1 -0
  29. package/dist-esm/src/cadl-generated/rest/outputModels.js +4 -0
  30. package/dist-esm/src/cadl-generated/rest/outputModels.js.map +1 -0
  31. package/dist-esm/src/cadl-generated/rest/parameters.js +4 -0
  32. package/dist-esm/src/cadl-generated/rest/parameters.js.map +1 -0
  33. package/dist-esm/src/cadl-generated/rest/responses.js +4 -0
  34. package/dist-esm/src/cadl-generated/rest/responses.js.map +1 -0
  35. package/dist-esm/src/eventGridClientV2.js +128 -0
  36. package/dist-esm/src/eventGridClientV2.js.map +1 -0
  37. package/dist-esm/src/generated/generatedClientContext.js +1 -1
  38. package/dist-esm/src/generated/generatedClientContext.js.map +1 -1
  39. package/dist-esm/src/index.js +1 -0
  40. package/dist-esm/src/index.js.map +1 -1
  41. package/dist-esm/src/models.js.map +1 -1
  42. package/dist-esm/src/tracing.js +1 -1
  43. package/dist-esm/src/tracing.js.map +1 -1
  44. package/package.json +6 -5
  45. package/types/eventgrid.d.ts +216 -0
package/dist/index.js CHANGED
@@ -9,6 +9,8 @@ var coreTracing = require('@azure/core-tracing');
9
9
  var uuid = require('uuid');
10
10
  var coreRestPipeline = require('@azure/core-rest-pipeline');
11
11
  var crypto = require('crypto');
12
+ var coreClient$1 = require('@azure-rest/core-client');
13
+ var logger$1 = require('@azure/logger');
12
14
 
13
15
  function _interopNamespace(e) {
14
16
  if (e && e.__esModule) return e;
@@ -8422,7 +8424,7 @@ class GeneratedClientContext extends coreClient__namespace.ServiceClient {
8422
8424
  const defaults = {
8423
8425
  requestContentType: "application/json; charset=utf-8"
8424
8426
  };
8425
- const packageDetails = `azsdk-js-eventgrid/4.12.0`;
8427
+ const packageDetails = `azsdk-js-eventgrid/4.13.0-beta.1`;
8426
8428
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
8427
8429
  ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
8428
8430
  : `${packageDetails}`;
@@ -8576,7 +8578,7 @@ function cloudEventDistributedTracingEnricherPolicy() {
8576
8578
  const tracingClient = coreTracing.createTracingClient({
8577
8579
  namespace: "Microsoft.Messaging.EventGrid",
8578
8580
  packageName: "@azure/event-grid",
8579
- packageVersion: "4.12.0",
8581
+ packageVersion: "4.13.0-beta.1",
8580
8582
  });
8581
8583
 
8582
8584
  // Copyright (c) Microsoft Corporation.
@@ -8636,7 +8638,7 @@ class EventGridPublisherClient {
8636
8638
  if (channelName) {
8637
8639
  sendOptions.aegChannelName = channelName;
8638
8640
  }
8639
- return this.client.publishCloudEventEvents(this.endpointUrl, events.map(convertCloudEventToModelType), sendOptions);
8641
+ return this.client.publishCloudEventEvents(this.endpointUrl, events.map(convertCloudEventToModelType$1), sendOptions);
8640
8642
  }
8641
8643
  case "Custom": {
8642
8644
  return this.client.publishCustomEventEvents(this.endpointUrl, events, updatedOptions);
@@ -8666,7 +8668,7 @@ function convertEventGridEventToModelType(event) {
8666
8668
  /**
8667
8669
  * @internal
8668
8670
  */
8669
- function convertCloudEventToModelType(event) {
8671
+ function convertCloudEventToModelType$1(event) {
8670
8672
  var _a, _b, _c, _d;
8671
8673
  if (event.extensionAttributes) {
8672
8674
  for (const propName in event.extensionAttributes) {
@@ -8816,6 +8818,429 @@ function isSystemEvent(eventType, event) {
8816
8818
  }
8817
8819
  }
8818
8820
 
8821
+ // Copyright (c) Microsoft Corporation.
8822
+ const logger = logger$1.createClientLogger("event-grid-modular");
8823
+
8824
+ // Copyright (c) Microsoft Corporation.
8825
+ /**
8826
+ * Initialize a new instance of `EventGridContext`
8827
+ * @param endpoint - The host name of the namespace, e.g. namespaceName1.westus-1.eventgrid.azure.net
8828
+ * @param credentials - Uniquely identify client credential
8829
+ * @param options - optional parameters
8830
+ */
8831
+ function createClient(endpoint, credentials, options = {}) {
8832
+ var _a, _b, _c, _d;
8833
+ const baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : `${endpoint}`;
8834
+ options.apiVersion = (_b = options.apiVersion) !== null && _b !== void 0 ? _b : "2023-06-01-preview";
8835
+ options = Object.assign(Object.assign({}, options), { credentials: {
8836
+ apiKeyHeaderName: "Authorization",
8837
+ } });
8838
+ const userAgentInfo = `azsdk-js-event-grid-modular-rest/1.0.0-beta.1`;
8839
+ const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
8840
+ ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
8841
+ : `${userAgentInfo}`;
8842
+ options = Object.assign(Object.assign({}, options), { userAgentOptions: {
8843
+ userAgentPrefix,
8844
+ }, loggingOptions: {
8845
+ logger: (_d = (_c = options.loggingOptions) === null || _c === void 0 ? void 0 : _c.logger) !== null && _d !== void 0 ? _d : logger.info,
8846
+ } });
8847
+ const client = coreClient$1.getClient(baseUrl, credentials, options);
8848
+ return client;
8849
+ }
8850
+
8851
+ // Copyright (c) Microsoft Corporation.
8852
+ // Licensed under the MIT license.
8853
+ const responseMap = {
8854
+ "POST /topics/{topicName}:publish": ["200"],
8855
+ "POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:receive": ["200"],
8856
+ "POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:acknowledge": ["200"],
8857
+ "POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:release": ["200"],
8858
+ "POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:reject": ["200"],
8859
+ };
8860
+ function isUnexpected(response) {
8861
+ const lroOriginal = response.headers["x-ms-original-url"];
8862
+ const url = new URL(lroOriginal !== null && lroOriginal !== void 0 ? lroOriginal : response.request.url);
8863
+ const method = response.request.method;
8864
+ let pathDetails = responseMap[`${method} ${url.pathname}`];
8865
+ if (!pathDetails) {
8866
+ pathDetails = getParametrizedPathSuccess(method, url.pathname);
8867
+ }
8868
+ return !pathDetails.includes(response.status);
8869
+ }
8870
+ function getParametrizedPathSuccess(method, path) {
8871
+ var _a, _b, _c, _d;
8872
+ const pathParts = path.split("/");
8873
+ // Traverse list to match the longest candidate
8874
+ // matchedLen: the length of candidate path
8875
+ // matchedValue: the matched status code array
8876
+ let matchedLen = -1, matchedValue = [];
8877
+ // Iterate the responseMap to find a match
8878
+ for (const [key, value] of Object.entries(responseMap)) {
8879
+ // Extracting the path from the map key which is in format
8880
+ // GET /path/foo
8881
+ if (!key.startsWith(method)) {
8882
+ continue;
8883
+ }
8884
+ const candidatePath = getPathFromMapKey(key);
8885
+ // Get each part of the url path
8886
+ const candidateParts = candidatePath.split("/");
8887
+ // track if we have found a match to return the values found.
8888
+ let found = true;
8889
+ for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
8890
+ if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) && ((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.indexOf("}")) !== -1) {
8891
+ const start = candidateParts[i].indexOf("}") + 1, end = (_c = candidateParts[i]) === null || _c === void 0 ? void 0 : _c.length;
8892
+ // If the current part of the candidate is a "template" part
8893
+ // Try to use the suffix of pattern to match the path
8894
+ // {guid} ==> $
8895
+ // {guid}:export ==> :export$
8896
+ const isMatched = new RegExp(`${(_d = candidateParts[i]) === null || _d === void 0 ? void 0 : _d.slice(start, end)}`).test(pathParts[j] || "");
8897
+ if (!isMatched) {
8898
+ found = false;
8899
+ break;
8900
+ }
8901
+ continue;
8902
+ }
8903
+ // If the candidate part is not a template and
8904
+ // the parts don't match mark the candidate as not found
8905
+ // to move on with the next candidate path.
8906
+ if (candidateParts[i] !== pathParts[j]) {
8907
+ found = false;
8908
+ break;
8909
+ }
8910
+ }
8911
+ // We finished evaluating the current candidate parts
8912
+ // Update the matched value if and only if we found the longer pattern
8913
+ if (found && candidatePath.length > matchedLen) {
8914
+ matchedLen = candidatePath.length;
8915
+ matchedValue = value;
8916
+ }
8917
+ }
8918
+ return matchedValue;
8919
+ }
8920
+ function getPathFromMapKey(mapKey) {
8921
+ const pathStart = mapKey.indexOf("/");
8922
+ return mapKey.slice(pathStart);
8923
+ }
8924
+
8925
+ // Copyright (c) Microsoft Corporation.
8926
+ /** Azure Messaging EventGrid Client */
8927
+ function createEventGrid(endpoint, credential, options = {}) {
8928
+ const baseUrl = endpoint;
8929
+ options.credentials = Object.assign(Object.assign({}, options.credentials), { apiKeyHeaderName: "Authorization" });
8930
+ const clientContext = createClient(baseUrl, credential, options);
8931
+ return clientContext;
8932
+ }
8933
+
8934
+ // Copyright (c) Microsoft Corporation.
8935
+ /** Publish Single Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200 status code with an empty JSON object in response. Otherwise, the server can return various error codes. For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for internal server error. */
8936
+ async function publishCloudEvent(context, event, topicName, options = { requestOptions: {} }) {
8937
+ var _a, _b, _c, _d, _e;
8938
+ const result = await context.path("/topics/{topicName}:publish", topicName).post({
8939
+ allowInsecureConnection: (_a = options.requestOptions) === null || _a === void 0 ? void 0 : _a.allowInsecureConnection,
8940
+ skipUrlEncoding: (_b = options.requestOptions) === null || _b === void 0 ? void 0 : _b.skipUrlEncoding,
8941
+ contentType: (_c = options.contentType) !== null && _c !== void 0 ? _c : "application/cloudevents+json; charset=utf-8",
8942
+ headers: Object.assign({}, (_d = options.requestOptions) === null || _d === void 0 ? void 0 : _d.headers),
8943
+ body: Object.assign({}, event),
8944
+ });
8945
+ if (typeof ((_e = options.requestOptions) === null || _e === void 0 ? void 0 : _e.onResponse) === "function") {
8946
+ options.requestOptions.onResponse(result);
8947
+ }
8948
+ if (isUnexpected(result)) {
8949
+ throw result.body;
8950
+ }
8951
+ return result.body;
8952
+ }
8953
+ /** Publish Batch Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200 status code with an empty JSON object in response. Otherwise, the server can return various error codes. For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for internal server error. */
8954
+ async function publishCloudEvents(context, events, topicName, options = { requestOptions: {} }) {
8955
+ var _a, _b, _c, _d, _e;
8956
+ const result = await context.path("/topics/{topicName}:publish", topicName).post({
8957
+ allowInsecureConnection: (_a = options.requestOptions) === null || _a === void 0 ? void 0 : _a.allowInsecureConnection,
8958
+ skipUrlEncoding: (_b = options.requestOptions) === null || _b === void 0 ? void 0 : _b.skipUrlEncoding,
8959
+ contentType: (_c = options.contentType) !== null && _c !== void 0 ? _c : "application/cloudevents-batch+json; charset=utf-8",
8960
+ headers: Object.assign({}, (_d = options.requestOptions) === null || _d === void 0 ? void 0 : _d.headers),
8961
+ body: events,
8962
+ });
8963
+ if (typeof ((_e = options.requestOptions) === null || _e === void 0 ? void 0 : _e.onResponse) === "function") {
8964
+ options.requestOptions.onResponse(result);
8965
+ }
8966
+ if (isUnexpected(result)) {
8967
+ throw result.body;
8968
+ }
8969
+ return result.body;
8970
+ }
8971
+ /** Receive Batch of Cloud Events from the Event Subscription. */
8972
+ async function receiveCloudEvents(context, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
8973
+ var _a, _b, _c, _d, _e;
8974
+ const result = await context
8975
+ .path("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:receive", topicName, eventSubscriptionName)
8976
+ .post({
8977
+ allowInsecureConnection: (_a = options.requestOptions) === null || _a === void 0 ? void 0 : _a.allowInsecureConnection,
8978
+ skipUrlEncoding: (_b = options.requestOptions) === null || _b === void 0 ? void 0 : _b.skipUrlEncoding,
8979
+ headers: Object.assign({}, (_c = options.requestOptions) === null || _c === void 0 ? void 0 : _c.headers),
8980
+ queryParameters: Object.assign(Object.assign({}, (options.maxEvents && { maxEvents: options.maxEvents })), (options.maxWaitTime && { maxWaitTime: options.maxWaitTime })),
8981
+ });
8982
+ if (typeof ((_d = options.requestOptions) === null || _d === void 0 ? void 0 : _d.onResponse) === "function") {
8983
+ options.requestOptions.onResponse(result);
8984
+ }
8985
+ if (isUnexpected(result)) {
8986
+ throw result.body;
8987
+ }
8988
+ return {
8989
+ value: ((_e = result.body["value"]) !== null && _e !== void 0 ? _e : []).map((p) => {
8990
+ var _a;
8991
+ return ({
8992
+ brokerProperties: {
8993
+ lockToken: p.brokerProperties["lockToken"],
8994
+ deliveryCount: p.brokerProperties["deliveryCount"],
8995
+ },
8996
+ event: {
8997
+ id: p.event["id"],
8998
+ source: p.event["source"],
8999
+ data: p.event["data"],
9000
+ dataBase64: p.event["data_base64"],
9001
+ type: p.event["type"],
9002
+ time: new Date((_a = p.event["time"]) !== null && _a !== void 0 ? _a : ""),
9003
+ specversion: p.event["specversion"],
9004
+ dataschema: p.event["dataschema"],
9005
+ datacontenttype: p.event["datacontenttype"],
9006
+ subject: p.event["subject"],
9007
+ },
9008
+ });
9009
+ }),
9010
+ };
9011
+ }
9012
+ /** Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if at least one event is successfully acknowledged. The response body will include the set of successfully acknowledged lockTokens, along with other failed lockTokens with their corresponding error information. Successfully acknowledged events will no longer be available to any consumer. */
9013
+ async function acknowledgeCloudEvents(context, lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
9014
+ var _a, _b, _c, _d, _e, _f;
9015
+ const result = await context
9016
+ .path("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:acknowledge", topicName, eventSubscriptionName)
9017
+ .post({
9018
+ allowInsecureConnection: (_a = options.requestOptions) === null || _a === void 0 ? void 0 : _a.allowInsecureConnection,
9019
+ skipUrlEncoding: (_b = options.requestOptions) === null || _b === void 0 ? void 0 : _b.skipUrlEncoding,
9020
+ contentType: (_c = options.contentType) !== null && _c !== void 0 ? _c : "application/json; charset=utf-8",
9021
+ headers: Object.assign({}, (_d = options.requestOptions) === null || _d === void 0 ? void 0 : _d.headers),
9022
+ body: { lockTokens: lockTokens },
9023
+ });
9024
+ if (typeof ((_e = options.requestOptions) === null || _e === void 0 ? void 0 : _e.onResponse) === "function") {
9025
+ options.requestOptions.onResponse(result);
9026
+ }
9027
+ if (isUnexpected(result)) {
9028
+ throw result.body;
9029
+ }
9030
+ return {
9031
+ failedLockTokens: ((_f = result.body["failedLockTokens"]) !== null && _f !== void 0 ? _f : []).map((p) => ({
9032
+ lockToken: p["lockToken"],
9033
+ errorCode: p["errorCode"],
9034
+ errorDescription: p["errorDescription"],
9035
+ })),
9036
+ succeededLockTokens: result.body["succeededLockTokens"],
9037
+ };
9038
+ }
9039
+ /** Release batch of Cloud Events. The server responds with an HTTP 200 status code if at least one event is successfully released. The response body will include the set of successfully released lockTokens, along with other failed lockTokens with their corresponding error information. */
9040
+ async function releaseCloudEvents(context, lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
9041
+ var _a, _b, _c, _d, _e, _f;
9042
+ const result = await context
9043
+ .path("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:release", topicName, eventSubscriptionName)
9044
+ .post({
9045
+ allowInsecureConnection: (_a = options.requestOptions) === null || _a === void 0 ? void 0 : _a.allowInsecureConnection,
9046
+ skipUrlEncoding: (_b = options.requestOptions) === null || _b === void 0 ? void 0 : _b.skipUrlEncoding,
9047
+ contentType: (_c = options.contentType) !== null && _c !== void 0 ? _c : "application/json; charset=utf-8",
9048
+ headers: Object.assign({}, (_d = options.requestOptions) === null || _d === void 0 ? void 0 : _d.headers),
9049
+ body: { lockTokens: lockTokens },
9050
+ });
9051
+ if (typeof ((_e = options.requestOptions) === null || _e === void 0 ? void 0 : _e.onResponse) === "function") {
9052
+ options.requestOptions.onResponse(result);
9053
+ }
9054
+ if (isUnexpected(result)) {
9055
+ throw result.body;
9056
+ }
9057
+ return {
9058
+ failedLockTokens: ((_f = result.body["failedLockTokens"]) !== null && _f !== void 0 ? _f : []).map((p) => ({
9059
+ lockToken: p["lockToken"],
9060
+ errorCode: p["errorCode"],
9061
+ errorDescription: p["errorDescription"],
9062
+ })),
9063
+ succeededLockTokens: result.body["succeededLockTokens"],
9064
+ };
9065
+ }
9066
+ /** Reject batch of Cloud Events. */
9067
+ async function rejectCloudEvents(context, lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
9068
+ var _a, _b, _c, _d, _e, _f;
9069
+ const result = await context
9070
+ .path("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:reject", topicName, eventSubscriptionName)
9071
+ .post({
9072
+ allowInsecureConnection: (_a = options.requestOptions) === null || _a === void 0 ? void 0 : _a.allowInsecureConnection,
9073
+ skipUrlEncoding: (_b = options.requestOptions) === null || _b === void 0 ? void 0 : _b.skipUrlEncoding,
9074
+ contentType: (_c = options.contentType) !== null && _c !== void 0 ? _c : "application/json; charset=utf-8",
9075
+ headers: Object.assign({}, (_d = options.requestOptions) === null || _d === void 0 ? void 0 : _d.headers),
9076
+ body: { lockTokens: lockTokens },
9077
+ });
9078
+ if (typeof ((_e = options.requestOptions) === null || _e === void 0 ? void 0 : _e.onResponse) === "function") {
9079
+ options.requestOptions.onResponse(result);
9080
+ }
9081
+ if (isUnexpected(result)) {
9082
+ throw result.body;
9083
+ }
9084
+ return {
9085
+ failedLockTokens: ((_f = result.body["failedLockTokens"]) !== null && _f !== void 0 ? _f : []).map((p) => ({
9086
+ lockToken: p["lockToken"],
9087
+ errorCode: p["errorCode"],
9088
+ errorDescription: p["errorDescription"],
9089
+ })),
9090
+ succeededLockTokens: result.body["succeededLockTokens"],
9091
+ };
9092
+ }
9093
+
9094
+ // Copyright (c) Microsoft Corporation.
9095
+ class EventGridClient$1 {
9096
+ /** Azure Messaging EventGrid Client */
9097
+ constructor(endpoint, credential, options = {}) {
9098
+ this._client = createEventGrid(endpoint, credential, options);
9099
+ }
9100
+ publishCloudEvent(event, topicName, options = { requestOptions: {} }) {
9101
+ return publishCloudEvent(this._client, event, topicName, options);
9102
+ }
9103
+ publishCloudEvents(events, topicName, options = { requestOptions: {} }) {
9104
+ return publishCloudEvents(this._client, events, topicName, options);
9105
+ }
9106
+ receiveCloudEvents(topicName, eventSubscriptionName, options = { requestOptions: {} }) {
9107
+ return receiveCloudEvents(this._client, topicName, eventSubscriptionName, options);
9108
+ }
9109
+ acknowledgeCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
9110
+ return acknowledgeCloudEvents(this._client, lockTokens, topicName, eventSubscriptionName, options);
9111
+ }
9112
+ releaseCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
9113
+ return releaseCloudEvents(this._client, lockTokens, topicName, eventSubscriptionName, options);
9114
+ }
9115
+ rejectCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
9116
+ return rejectCloudEvents(this._client, lockTokens, topicName, eventSubscriptionName, options);
9117
+ }
9118
+ }
9119
+
9120
+ // Copyright (c) Microsoft Corporation.
9121
+ /**
9122
+ * Event Grid Client
9123
+ */
9124
+ class EventGridClient {
9125
+ /** Azure Messaging EventGrid Client */
9126
+ constructor(endpoint, credential, options = {}) {
9127
+ credential.update(`SharedAccessKey ${credential.key}`);
9128
+ this._client = new EventGridClient$1(endpoint, credential, options);
9129
+ }
9130
+ /**
9131
+ * Publish Single Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200
9132
+ * status code with an empty JSON object in response. Otherwise, the server can return various error codes.
9133
+ * For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
9134
+ * is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
9135
+ * internal server error.
9136
+ *
9137
+ * @param event - Event to publish
9138
+ * @param topicName - Topic to publish the event
9139
+ * @param options - Options to publish
9140
+ *
9141
+ */
9142
+ publishCloudEvent(event, topicName, options = { requestOptions: {} }) {
9143
+ return this._client.publishCloudEvent(convertCloudEventToModelType(event), topicName, options);
9144
+ }
9145
+ /**
9146
+ * Publish Batch Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200
9147
+ * status code with an empty JSON object in response. Otherwise, the server can return various error codes.
9148
+ * For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
9149
+ * is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
9150
+ * internal server error.
9151
+ *
9152
+ * @param events - Events to publish
9153
+ * @param topicName - Topic to publish the event
9154
+ * @param options - Options to publish
9155
+ *
9156
+ */
9157
+ publishCloudEvents(events, topicName, options = { requestOptions: {} }) {
9158
+ const eventsWireModel = [];
9159
+ for (const individualevent of events) {
9160
+ eventsWireModel.concat(convertCloudEventToModelType(individualevent));
9161
+ }
9162
+ return this._client.publishCloudEvents(eventsWireModel, topicName, options);
9163
+ }
9164
+ /**
9165
+ * Receive Batch of Cloud Events from the Event Subscription.
9166
+ *
9167
+ * @param topicName - Topic to receive
9168
+ * @param eventSubscriptionName - Name of the Event Subscription
9169
+ * @param options - Options to receive
9170
+ *
9171
+ */
9172
+ receiveCloudEvents(topicName, eventSubscriptionName, options = { requestOptions: {} }) {
9173
+ return this._client.receiveCloudEvents(topicName, eventSubscriptionName, options);
9174
+ }
9175
+ /**
9176
+ * Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if at least one
9177
+ * event is successfully acknowledged. The response body will include the set of successfully acknowledged
9178
+ * lockTokens, along with other failed lockTokens with their corresponding error information. Successfully
9179
+ * acknowledged events will no longer be available to any consumer.
9180
+ *
9181
+ * @param lockTokens - Lock Tokens
9182
+ * @param topicName - Topic Name
9183
+ * @param eventSubscriptionName - Name of the Event Subscription
9184
+ * @param options - Options to Acknowledge
9185
+ *
9186
+ */
9187
+ acknowledgeCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
9188
+ return this._client.acknowledgeCloudEvents(lockTokens, topicName, eventSubscriptionName, options);
9189
+ }
9190
+ /**
9191
+ * Release batch of Cloud Events. The server responds with an HTTP 200 status code if at least one event is
9192
+ * successfully released. The response body will include the set of successfully released lockTokens, along
9193
+ * with other failed lockTokens with their corresponding error information.
9194
+ *
9195
+ * @param lockTokens - Lock Tokens
9196
+ * @param topicName - Topic Name
9197
+ * @param eventSubscriptionName - Name of the Event Subscription
9198
+ * @param options - Options to release
9199
+ *
9200
+ */
9201
+ releaseCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
9202
+ return this._client.releaseCloudEvents(lockTokens, topicName, eventSubscriptionName, options);
9203
+ }
9204
+ /**
9205
+ * Reject batch of Cloud Events.
9206
+ *
9207
+ * @param lockTokens - Lock Tokens
9208
+ * @param topicName - Topic Name
9209
+ * @param eventSubscriptionName - Name of the Event Subscription
9210
+ * @param options - Options to reject
9211
+ *
9212
+ */
9213
+ rejectCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
9214
+ return this._client.rejectCloudEvents(lockTokens, topicName, eventSubscriptionName, options);
9215
+ }
9216
+ }
9217
+ function convertCloudEventToModelType(event) {
9218
+ var _a, _b, _c, _d, _e;
9219
+ if (event.extensionAttributes) {
9220
+ for (const propName in event.extensionAttributes) {
9221
+ // Per the cloud events spec: "CloudEvents attribute names MUST consist of lower-case letters ('a' to 'z') or digits ('0' to '9') from the ASCII character set"
9222
+ // they also can not match an existing defined property name.
9223
+ if (!/^[a-z0-9]*$/.test(propName) ||
9224
+ cloudEventReservedPropertyNames.indexOf(propName) !== -1) {
9225
+ throw new Error(`invalid extension attribute name: ${propName}`);
9226
+ }
9227
+ }
9228
+ }
9229
+ const converted = Object.assign({ specversion: (_a = event.specversion) !== null && _a !== void 0 ? _a : "1.0", type: event.type, source: event.source, id: (_b = event.id) !== null && _b !== void 0 ? _b : uuid.v4(), time: (_c = event.time) !== null && _c !== void 0 ? _c : new Date(), subject: event.subject, dataschema: event.dataschema }, ((_d = event.extensionAttributes) !== null && _d !== void 0 ? _d : []));
9230
+ if (event.data instanceof Uint8Array) {
9231
+ if (!event.datacontenttype) {
9232
+ throw new Error("a data content type must be provided when sending an event with binary data");
9233
+ }
9234
+ converted.datacontenttype = event.datacontenttype;
9235
+ converted.data_base64 = event.data;
9236
+ }
9237
+ else {
9238
+ converted.datacontenttype = (_e = event.datacontenttype) !== null && _e !== void 0 ? _e : "application/json";
9239
+ converted.data = event.data;
9240
+ }
9241
+ return converted;
9242
+ }
9243
+
8819
9244
  Object.defineProperty(exports, 'AzureKeyCredential', {
8820
9245
  enumerable: true,
8821
9246
  get: function () { return coreAuth.AzureKeyCredential; }
@@ -8824,6 +9249,7 @@ Object.defineProperty(exports, 'AzureSASCredential', {
8824
9249
  enumerable: true,
8825
9250
  get: function () { return coreAuth.AzureSASCredential; }
8826
9251
  });
9252
+ exports.EventGridClient = EventGridClient;
8827
9253
  exports.EventGridDeserializer = EventGridDeserializer;
8828
9254
  exports.EventGridPublisherClient = EventGridPublisherClient;
8829
9255
  exports.generateSharedAccessSignature = generateSharedAccessSignature;