@azure/eventgrid-namespaces 1.0.0-beta.2 → 1.0.0

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 (38) hide show
  1. package/README.md +42 -16
  2. package/dist/index.js +403 -201
  3. package/dist/index.js.map +1 -1
  4. package/dist-esm/src/cadl-generated/EventGridClient.js +20 -28
  5. package/dist-esm/src/cadl-generated/EventGridClient.js.map +1 -1
  6. package/dist-esm/src/cadl-generated/api/EventGridContext.js +2 -2
  7. package/dist-esm/src/cadl-generated/api/EventGridContext.js.map +1 -1
  8. package/dist-esm/src/cadl-generated/api/operations.js +25 -29
  9. package/dist-esm/src/cadl-generated/api/operations.js.map +1 -1
  10. package/dist-esm/src/cadl-generated/index.js.map +1 -1
  11. package/dist-esm/src/cadl-generated/models/index.js.map +1 -1
  12. package/dist-esm/src/cadl-generated/models/models.js.map +1 -1
  13. package/dist-esm/src/cadl-generated/models/options.js.map +1 -1
  14. package/dist-esm/src/cadl-generated/rest/clientDefinitions.js.map +1 -1
  15. package/dist-esm/src/cadl-generated/rest/eventGridClient.js +9 -9
  16. package/dist-esm/src/cadl-generated/rest/eventGridClient.js.map +1 -1
  17. package/dist-esm/src/cadl-generated/rest/isUnexpected.js.map +1 -1
  18. package/dist-esm/src/cadl-generated/rest/models.js.map +1 -1
  19. package/dist-esm/src/cadl-generated/rest/parameters.js.map +1 -1
  20. package/dist-esm/src/cloudEventDistrubtedTracingEnricherPolicy.js +53 -0
  21. package/dist-esm/src/cloudEventDistrubtedTracingEnricherPolicy.js.map +1 -0
  22. package/dist-esm/src/consumer.js +73 -0
  23. package/dist-esm/src/consumer.js.map +1 -0
  24. package/dist-esm/src/eventGridNamespacesPublishBinaryMode.js.map +1 -1
  25. package/dist-esm/src/eventGridReceiverClient.js +98 -0
  26. package/dist-esm/src/eventGridReceiverClient.js.map +1 -0
  27. package/dist-esm/src/eventGridSenderClient.js +72 -0
  28. package/dist-esm/src/eventGridSenderClient.js.map +1 -0
  29. package/dist-esm/src/index.js +3 -2
  30. package/dist-esm/src/index.js.map +1 -1
  31. package/dist-esm/src/models.js +3 -3
  32. package/dist-esm/src/models.js.map +1 -1
  33. package/dist-esm/src/util.js +155 -0
  34. package/dist-esm/src/util.js.map +1 -0
  35. package/package.json +9 -10
  36. package/types/eventgrid-namespaces.d.ts +126 -99
  37. package/dist-esm/src/eventGridNamespacesClient.js +0 -147
  38. package/dist-esm/src/eventGridNamespacesClient.js.map +0 -1
package/dist/index.js CHANGED
@@ -6,8 +6,8 @@ var coreAuth = require('@azure/core-auth');
6
6
  var coreUtil = require('@azure/core-util');
7
7
  var coreClient = require('@azure-rest/core-client');
8
8
  var logger$1 = require('@azure/logger');
9
- var buffer = require('buffer');
10
- var eventgrid = require('@azure/eventgrid');
9
+ var coreRestPipeline = require('@azure/core-rest-pipeline');
10
+ var coreClient$1 = require('@azure/core-client');
11
11
 
12
12
  // Copyright (c) Microsoft Corporation.
13
13
  // Licensed under the MIT license.
@@ -17,27 +17,27 @@ const logger = logger$1.createClientLogger("eventgrid-namespaces");
17
17
  // Licensed under the MIT license.
18
18
  /**
19
19
  * Initialize a new instance of `EventGridContext`
20
- * @param endpoint - The host name of the namespace, e.g. namespaceName1.westus-1.eventgrid.azure.net
20
+ * @param endpointParam - The host name of the namespace, e.g. namespaceName1.westus-1.eventgrid.azure.net
21
21
  * @param credentials - uniquely identify client credential
22
22
  * @param options - the parameter for all optional parameters
23
23
  */
24
- function createClient(endpoint, credentials, options = {}) {
25
- var _a, _b, _c, _d, _e, _f;
26
- const baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : `${endpoint}`;
27
- options.apiVersion = (_b = options.apiVersion) !== null && _b !== void 0 ? _b : "2023-10-01-preview";
28
- const userAgentInfo = `azsdk-js-eventgrid-namespaces-rest/1.0.0-beta.1`;
24
+ function createClient(endpointParam, credentials, options = {}) {
25
+ var _a, _b, _c, _d, _e, _f, _g;
26
+ const endpointUrl = (_b = (_a = options.endpoint) !== null && _a !== void 0 ? _a : options.baseUrl) !== null && _b !== void 0 ? _b : `${endpointParam}`;
27
+ options.apiVersion = (_c = options.apiVersion) !== null && _c !== void 0 ? _c : "2024-06-01";
28
+ const userAgentInfo = `azsdk-js-eventgrid-namespaces-rest/1.0.0`;
29
29
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
30
30
  ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
31
31
  : `${userAgentInfo}`;
32
32
  options = Object.assign(Object.assign({}, options), { userAgentOptions: {
33
33
  userAgentPrefix,
34
34
  }, loggingOptions: {
35
- logger: (_d = (_c = options.loggingOptions) === null || _c === void 0 ? void 0 : _c.logger) !== null && _d !== void 0 ? _d : logger.info,
35
+ logger: (_e = (_d = options.loggingOptions) === null || _d === void 0 ? void 0 : _d.logger) !== null && _e !== void 0 ? _e : logger.info,
36
36
  }, credentials: {
37
- scopes: (_f = (_e = options.credentials) === null || _e === void 0 ? void 0 : _e.scopes) !== null && _f !== void 0 ? _f : ["https://eventgrid.azure.net/.default"],
37
+ scopes: (_g = (_f = options.credentials) === null || _f === void 0 ? void 0 : _f.scopes) !== null && _g !== void 0 ? _g : ["https://eventgrid.azure.net/.default"],
38
38
  apiKeyHeaderName: "Authorization",
39
39
  } });
40
- const client = coreClient.getClient(baseUrl, credentials, options);
40
+ const client = coreClient.getClient(endpointUrl, credentials, options);
41
41
  if (coreAuth.isKeyCredential(credentials)) {
42
42
  client.pipeline.addPolicy({
43
43
  name: "customKeyCredentialPolicy",
@@ -128,8 +128,8 @@ function getPathFromMapKey(mapKey) {
128
128
  // Copyright (c) Microsoft Corporation.
129
129
  // Licensed under the MIT license.
130
130
  /** Azure Messaging EventGrid Client */
131
- function createEventGrid(endpoint, credential, options = {}) {
132
- const clientContext = createClient(endpoint, credential, options);
131
+ function createEventGrid(endpointParam, credential, options = {}) {
132
+ const clientContext = createClient(endpointParam, credential, options);
133
133
  return clientContext;
134
134
  }
135
135
 
@@ -152,16 +152,16 @@ function _publishCloudEventSend(context, topicName, event, options = { requestOp
152
152
  subject: event["subject"],
153
153
  } }));
154
154
  }
155
- async function _publishCloudEventDeserialize$1(result) {
155
+ async function _publishCloudEventDeserialize(result) {
156
156
  if (isUnexpected(result)) {
157
157
  throw coreClient.createRestError(result);
158
158
  }
159
159
  return result.body;
160
160
  }
161
- /** 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. */
161
+ /** Publish a single Cloud Event to a namespace topic. */
162
162
  async function publishCloudEvent(context, topicName, event, options = { requestOptions: {} }) {
163
163
  const result = await _publishCloudEventSend(context, topicName, event, options);
164
- return _publishCloudEventDeserialize$1(result);
164
+ return _publishCloudEventDeserialize(result);
165
165
  }
166
166
  function _publishCloudEventsSend(context, topicName, events, options = { requestOptions: {} }) {
167
167
  var _a;
@@ -187,7 +187,7 @@ async function _publishCloudEventsDeserialize(result) {
187
187
  }
188
188
  return result.body;
189
189
  }
190
- /** 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. */
190
+ /** Publish a batch of Cloud Events to a namespace topic. */
191
191
  async function publishCloudEvents(context, topicName, events, options = { requestOptions: {} }) {
192
192
  const result = await _publishCloudEventsSend(context, topicName, events, options);
193
193
  return _publishCloudEventsDeserialize(result);
@@ -205,7 +205,7 @@ async function _receiveCloudEventsDeserialize(result) {
205
205
  throw coreClient.createRestError(result);
206
206
  }
207
207
  return {
208
- value: result.body["value"].map((p) => ({
208
+ details: result.body["value"].map((p) => ({
209
209
  brokerProperties: {
210
210
  lockToken: p.brokerProperties["lockToken"],
211
211
  deliveryCount: p.brokerProperties["deliveryCount"],
@@ -227,15 +227,15 @@ async function _receiveCloudEventsDeserialize(result) {
227
227
  })),
228
228
  };
229
229
  }
230
- /** Receive Batch of Cloud Events from the Event Subscription. */
230
+ /** Receive a batch of Cloud Events from a subscription. */
231
231
  async function receiveCloudEvents(context, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
232
232
  const result = await _receiveCloudEventsSend(context, topicName, eventSubscriptionName, options);
233
233
  return _receiveCloudEventsDeserialize(result);
234
234
  }
235
- function _acknowledgeCloudEventsSend(context, topicName, eventSubscriptionName, acknowledgeOptions, options = { requestOptions: {} }) {
235
+ function _acknowledgeCloudEventsSend(context, topicName, eventSubscriptionName, lockTokens, options = { requestOptions: {} }) {
236
236
  return context
237
237
  .path("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:acknowledge", topicName, eventSubscriptionName)
238
- .post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { body: { lockTokens: acknowledgeOptions["lockTokens"] } }));
238
+ .post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { body: { lockTokens: lockTokens } }));
239
239
  }
240
240
  async function _acknowledgeCloudEventsDeserialize(result) {
241
241
  if (isUnexpected(result)) {
@@ -249,21 +249,17 @@ async function _acknowledgeCloudEventsDeserialize(result) {
249
249
  succeededLockTokens: result.body["succeededLockTokens"],
250
250
  };
251
251
  }
252
- /** Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if the request is successfully accepted. 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. */
253
- async function acknowledgeCloudEvents(context, topicName, eventSubscriptionName, acknowledgeOptions, options = { requestOptions: {} }) {
254
- const result = await _acknowledgeCloudEventsSend(context, topicName, eventSubscriptionName, acknowledgeOptions, options);
252
+ /** Acknowledge a batch of Cloud Events. The response will include the set of successfully acknowledged lock tokens, along with other failed lock tokens with their corresponding error information. Successfully acknowledged events will no longer be available to be received by any consumer. */
253
+ async function acknowledgeCloudEvents(context, topicName, eventSubscriptionName, lockTokens, options = { requestOptions: {} }) {
254
+ const result = await _acknowledgeCloudEventsSend(context, topicName, eventSubscriptionName, lockTokens, options);
255
255
  return _acknowledgeCloudEventsDeserialize(result);
256
256
  }
257
- function _releaseCloudEventsSend(context, topicName, eventSubscriptionName, releaseOptions, options = { requestOptions: {} }) {
258
- let releaseDelayInSeconds = undefined;
259
- if (options === null || options === void 0 ? void 0 : options.releaseDelayInSeconds) {
260
- releaseDelayInSeconds = parseInt(options.releaseDelayInSeconds);
261
- }
257
+ function _releaseCloudEventsSend(context, topicName, eventSubscriptionName, lockTokens, options = { requestOptions: {} }) {
262
258
  return context
263
259
  .path("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:release", topicName, eventSubscriptionName)
264
260
  .post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { queryParameters: {
265
- releaseDelayInSeconds,
266
- }, body: { lockTokens: releaseOptions["lockTokens"] } }));
261
+ releaseDelayInSeconds: options === null || options === void 0 ? void 0 : options.releaseDelayInSeconds,
262
+ }, body: { lockTokens: lockTokens } }));
267
263
  }
268
264
  async function _releaseCloudEventsDeserialize(result) {
269
265
  if (isUnexpected(result)) {
@@ -277,15 +273,15 @@ async function _releaseCloudEventsDeserialize(result) {
277
273
  succeededLockTokens: result.body["succeededLockTokens"],
278
274
  };
279
275
  }
280
- /** Release batch of Cloud Events. The server responds with an HTTP 200 status code if the request is successfully accepted. The response body will include the set of successfully released lockTokens, along with other failed lockTokens with their corresponding error information. */
281
- async function releaseCloudEvents(context, topicName, eventSubscriptionName, releaseOptions, options = { requestOptions: {} }) {
282
- const result = await _releaseCloudEventsSend(context, topicName, eventSubscriptionName, releaseOptions, options);
276
+ /** Release a batch of Cloud Events. The response will include the set of successfully released lock tokens, along with other failed lock tokens with their corresponding error information. Successfully released events can be received by consumers. */
277
+ async function releaseCloudEvents(context, topicName, eventSubscriptionName, lockTokens, options = { requestOptions: {} }) {
278
+ const result = await _releaseCloudEventsSend(context, topicName, eventSubscriptionName, lockTokens, options);
283
279
  return _releaseCloudEventsDeserialize(result);
284
280
  }
285
- function _rejectCloudEventsSend(context, topicName, eventSubscriptionName, rejectOptions, options = { requestOptions: {} }) {
281
+ function _rejectCloudEventsSend(context, topicName, eventSubscriptionName, lockTokens, options = { requestOptions: {} }) {
286
282
  return context
287
283
  .path("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:reject", topicName, eventSubscriptionName)
288
- .post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { body: { lockTokens: rejectOptions["lockTokens"] } }));
284
+ .post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { body: { lockTokens: lockTokens } }));
289
285
  }
290
286
  async function _rejectCloudEventsDeserialize(result) {
291
287
  if (isUnexpected(result)) {
@@ -299,15 +295,15 @@ async function _rejectCloudEventsDeserialize(result) {
299
295
  succeededLockTokens: result.body["succeededLockTokens"],
300
296
  };
301
297
  }
302
- /** Reject batch of Cloud Events. The server responds with an HTTP 200 status code if the request is successfully accepted. The response body will include the set of successfully rejected lockTokens, along with other failed lockTokens with their corresponding error information. */
303
- async function rejectCloudEvents(context, topicName, eventSubscriptionName, rejectOptions, options = { requestOptions: {} }) {
304
- const result = await _rejectCloudEventsSend(context, topicName, eventSubscriptionName, rejectOptions, options);
298
+ /** Reject a batch of Cloud Events. The response will include the set of successfully rejected lock tokens, along with other failed lock tokens with their corresponding error information. Successfully rejected events will be dead-lettered and can no longer be received by a consumer. */
299
+ async function rejectCloudEvents(context, topicName, eventSubscriptionName, lockTokens, options = { requestOptions: {} }) {
300
+ const result = await _rejectCloudEventsSend(context, topicName, eventSubscriptionName, lockTokens, options);
305
301
  return _rejectCloudEventsDeserialize(result);
306
302
  }
307
- function _renewCloudEventLocksSend(context, topicName, eventSubscriptionName, renewLockOptions, options = { requestOptions: {} }) {
303
+ function _renewCloudEventLocksSend(context, topicName, eventSubscriptionName, lockTokens, options = { requestOptions: {} }) {
308
304
  return context
309
305
  .path("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:renewLock", topicName, eventSubscriptionName)
310
- .post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { body: { lockTokens: renewLockOptions["lockTokens"] } }));
306
+ .post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { body: { lockTokens: lockTokens } }));
311
307
  }
312
308
  async function _renewCloudEventLocksDeserialize(result) {
313
309
  if (isUnexpected(result)) {
@@ -321,9 +317,9 @@ async function _renewCloudEventLocksDeserialize(result) {
321
317
  succeededLockTokens: result.body["succeededLockTokens"],
322
318
  };
323
319
  }
324
- /** Renew lock for batch of Cloud Events. The server responds with an HTTP 200 status code if the request is successfully accepted. The response body will include the set of successfully renewed lockTokens, along with other failed lockTokens with their corresponding error information. */
325
- async function renewCloudEventLocks(context, topicName, eventSubscriptionName, renewLockOptions, options = { requestOptions: {} }) {
326
- const result = await _renewCloudEventLocksSend(context, topicName, eventSubscriptionName, renewLockOptions, options);
320
+ /** Renew locks for a batch of Cloud Events. The response will include the set of successfully renewed lock tokens, along with other failed lock tokens with their corresponding error information. Successfully renewed locks will ensure that the associated event is only available to the consumer that holds the renewed lock. */
321
+ async function renewCloudEventLocks(context, topicName, eventSubscriptionName, lockTokens, options = { requestOptions: {} }) {
322
+ const result = await _renewCloudEventLocksSend(context, topicName, eventSubscriptionName, lockTokens, options);
327
323
  return _renewCloudEventLocksDeserialize(result);
328
324
  }
329
325
 
@@ -334,57 +330,49 @@ class EventGridClient {
334
330
  return this._client;
335
331
  }
336
332
  /** Azure Messaging EventGrid Client */
337
- constructor(endpoint, credential, options = {}) {
338
- this._client = createEventGrid(endpoint, credential, options);
333
+ constructor(endpointParam, credential, options = {}) {
334
+ this._client = createEventGrid(endpointParam, credential, options);
339
335
  this.pipeline = this._client.pipeline;
340
336
  }
341
- /** 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. */
337
+ /** Publish a single Cloud Event to a namespace topic. */
342
338
  publishCloudEvent(topicName, event, options = { requestOptions: {} }) {
343
339
  return publishCloudEvent(this._client, topicName, event, options);
344
340
  }
345
- /** 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. */
341
+ /** Publish a batch of Cloud Events to a namespace topic. */
346
342
  publishCloudEvents(topicName, events, options = { requestOptions: {} }) {
347
343
  return publishCloudEvents(this._client, topicName, events, options);
348
344
  }
349
- /** Receive Batch of Cloud Events from the Event Subscription. */
345
+ /** Receive a batch of Cloud Events from a subscription. */
350
346
  receiveCloudEvents(topicName, eventSubscriptionName, options = { requestOptions: {} }) {
351
347
  return receiveCloudEvents(this._client, topicName, eventSubscriptionName, options);
352
348
  }
353
- /** Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if the request is successfully accepted. 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. */
354
- acknowledgeCloudEvents(topicName, eventSubscriptionName,
355
- // eslint-disable-next-line @azure/azure-sdk/ts-naming-options
356
- acknowledgeOptions, options = { requestOptions: {} }) {
357
- return acknowledgeCloudEvents(this._client, topicName, eventSubscriptionName, acknowledgeOptions, options);
349
+ /** Acknowledge a batch of Cloud Events. The response will include the set of successfully acknowledged lock tokens, along with other failed lock tokens with their corresponding error information. Successfully acknowledged events will no longer be available to be received by any consumer. */
350
+ acknowledgeCloudEvents(topicName, eventSubscriptionName, lockTokens, options = { requestOptions: {} }) {
351
+ return acknowledgeCloudEvents(this._client, topicName, eventSubscriptionName, lockTokens, options);
358
352
  }
359
- /** Release batch of Cloud Events. The server responds with an HTTP 200 status code if the request is successfully accepted. The response body will include the set of successfully released lockTokens, along with other failed lockTokens with their corresponding error information. */
360
- releaseCloudEvents(topicName, eventSubscriptionName,
361
- // eslint-disable-next-line @azure/azure-sdk/ts-naming-options
362
- releaseOptions, options = { requestOptions: {} }) {
363
- return releaseCloudEvents(this._client, topicName, eventSubscriptionName, releaseOptions, options);
353
+ /** Release a batch of Cloud Events. The response will include the set of successfully released lock tokens, along with other failed lock tokens with their corresponding error information. Successfully released events can be received by consumers. */
354
+ releaseCloudEvents(topicName, eventSubscriptionName, lockTokens, options = { requestOptions: {} }) {
355
+ return releaseCloudEvents(this._client, topicName, eventSubscriptionName, lockTokens, options);
364
356
  }
365
- /** Reject batch of Cloud Events. The server responds with an HTTP 200 status code if the request is successfully accepted. The response body will include the set of successfully rejected lockTokens, along with other failed lockTokens with their corresponding error information. */
366
- rejectCloudEvents(topicName, eventSubscriptionName,
367
- // eslint-disable-next-line @azure/azure-sdk/ts-naming-options
368
- rejectOptions, options = { requestOptions: {} }) {
369
- return rejectCloudEvents(this._client, topicName, eventSubscriptionName, rejectOptions, options);
357
+ /** Reject a batch of Cloud Events. The response will include the set of successfully rejected lock tokens, along with other failed lock tokens with their corresponding error information. Successfully rejected events will be dead-lettered and can no longer be received by a consumer. */
358
+ rejectCloudEvents(topicName, eventSubscriptionName, lockTokens, options = { requestOptions: {} }) {
359
+ return rejectCloudEvents(this._client, topicName, eventSubscriptionName, lockTokens, options);
370
360
  }
371
- /** Renew lock for batch of Cloud Events. The server responds with an HTTP 200 status code if the request is successfully accepted. The response body will include the set of successfully renewed lockTokens, along with other failed lockTokens with their corresponding error information. */
372
- renewCloudEventLocks(topicName, eventSubscriptionName,
373
- // eslint-disable-next-line @azure/azure-sdk/ts-naming-options
374
- renewLockOptions, options = { requestOptions: {} }) {
375
- return renewCloudEventLocks(this._client, topicName, eventSubscriptionName, renewLockOptions, options);
361
+ /** Renew locks for a batch of Cloud Events. The response will include the set of successfully renewed lock tokens, along with other failed lock tokens with their corresponding error information. Successfully renewed locks will ensure that the associated event is only available to the consumer that holds the renewed lock. */
362
+ renewCloudEventLocks(topicName, eventSubscriptionName, lockTokens, options = { requestOptions: {} }) {
363
+ return renewCloudEventLocks(this._client, topicName, eventSubscriptionName, lockTokens, options);
376
364
  }
377
365
  }
378
366
 
379
367
  // Copyright (c) Microsoft Corporation.
380
368
  // Licensed under the MIT license.
381
369
  const cloudEventReservedPropertyNames = [
382
- "specversion",
370
+ "specVersion",
383
371
  "id",
384
372
  "source",
385
373
  "type",
386
- "datacontenttype",
387
- "dataschema",
374
+ "dataContentType",
375
+ "dataSchema",
388
376
  "subject",
389
377
  "time",
390
378
  "data",
@@ -392,62 +380,55 @@ const cloudEventReservedPropertyNames = [
392
380
 
393
381
  // Copyright (c) Microsoft Corporation.
394
382
  // Licensed under the MIT license.
395
- async function publishCloudEventInBinaryMode(context, topicName, event, options = { requestOptions: {} }) {
396
- const result = await _publishCloudEventSendBinaryMode(context, topicName, event, options);
397
- return _publishCloudEventDeserialize(result);
398
- }
399
- async function _publishCloudEventDeserialize(result) {
400
- if (isUnexpected(result)) {
401
- throw result.body;
402
- }
403
- return result.body;
404
- }
405
- function _publishCloudEventSendBinaryMode(context, topicName, event, options = { requestOptions: {} }) {
406
- var _a, _b;
407
- const headers = {
408
- "ce-id": event.id,
409
- "ce-source": event.source,
410
- "ce-type": event.type,
411
- "ce-specversion": event.specversion,
383
+ const CloudEventBatchContentType = "application/cloudevents-batch+json; charset=utf-8";
384
+ const TraceParentHeaderName = "traceparent";
385
+ const TraceStateHeaderName = "tracestate";
386
+ const ContentTypeHeaderName = "Content-Type";
387
+ /**
388
+ * The programmatic identifier of the cloudEventDistributedTracingEnricherPolicy.
389
+ */
390
+ const cloudEventDistributedTracingEnricherPolicyName = "cloudEventDistributedTracingEnricherPolicy";
391
+ /**
392
+ * cloudEventDistributedTracingEnricherPolicy is a policy which adds distributed tracing information
393
+ * to a batch of cloud events. It does so by copying the `traceparent` and `tracestate` properties
394
+ * from the HTTP request into the individual events as extension properties.
395
+ *
396
+ * This will only happen in the case where an event does not have a `traceparent` defined already. This
397
+ * allows events to explicitly set a traceparent and tracestate which would be respected during "multi-hop
398
+ * transmition".
399
+ *
400
+ * See https://github.com/cloudevents/spec/blob/master/extensions/distributed-tracing.md
401
+ * for more information on distributed tracing and cloud events.
402
+ */
403
+ function cloudEventDistributedTracingEnricherPolicy() {
404
+ return {
405
+ name: cloudEventDistributedTracingEnricherPolicyName,
406
+ async sendRequest(request, next) {
407
+ const traceparent = request.headers.get(TraceParentHeaderName);
408
+ const tracestate = request.headers.get(TraceStateHeaderName);
409
+ if (request.headers.get(ContentTypeHeaderName) === CloudEventBatchContentType &&
410
+ typeof request.body === "string" &&
411
+ traceparent) {
412
+ // per the cloud event batched content type we know the body is an array encoded in JSON.
413
+ const parsedBody = JSON.parse(request.body);
414
+ for (const item of parsedBody) {
415
+ // When using the distributed tracing extension, the "traceparent" is a required property
416
+ // and "tracestate" is optional. This means if an item already has a "traceparent" property
417
+ // we should not stomp over it. Well formed events will not have a "tracestate" without
418
+ // also having a "traceparent" so there's no need to guard against that case.
419
+ if (typeof item !== "object" || item.traceparent) {
420
+ continue;
421
+ }
422
+ item.traceparent = traceparent;
423
+ if (tracestate) {
424
+ item.tracestate = tracestate;
425
+ }
426
+ }
427
+ request.body = JSON.stringify(parsedBody);
428
+ }
429
+ return next(request);
430
+ },
412
431
  };
413
- if (event.time) {
414
- headers["ce-time"] = event.time.toISOString();
415
- }
416
- if (event.dataschema) {
417
- headers["ce-dataschema"] = event.dataschema;
418
- }
419
- if (event.datacontenttype) {
420
- headers["ce-datacontenttype"] = event.datacontenttype;
421
- }
422
- if (event.subject) {
423
- headers["ce-subject"] = event.subject;
424
- }
425
- let data;
426
- if (event.data) {
427
- // If data is already encoded
428
- if (buffer.Buffer.isBuffer(event.data)) {
429
- data = event.data;
430
- }
431
- else {
432
- throw new Error(`CloudEvent data must be binary when in binary mode.`);
433
- }
434
- }
435
- else {
436
- if (event.dataBase64) {
437
- data = event.dataBase64;
438
- }
439
- }
440
- return context.path("/topics/{topicName}:publish", topicName).post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { contentType: (_a = options.contentType) !== null && _a !== void 0 ? _a : "application/cloudevents+json; charset=utf-8", headers, body: {
441
- id: event.id,
442
- source: event.source,
443
- data,
444
- type: event.type,
445
- time: (_b = event.time) === null || _b === void 0 ? void 0 : _b.toISOString(),
446
- specversion: event.specversion,
447
- dataschema: event.dataschema,
448
- datacontenttype: event.datacontenttype,
449
- subject: event.subject,
450
- } }));
451
432
  }
452
433
 
453
434
  // Copyright (c) Microsoft Corporation.
@@ -455,62 +436,115 @@ function _publishCloudEventSendBinaryMode(context, topicName, event, options = {
455
436
  /**
456
437
  * Event Grid Namespaces Client
457
438
  */
458
- class EventGridNamespacesClient {
439
+ class EventGridSenderClient {
459
440
  /** Azure Messaging EventGrid Client */
460
- constructor(endpoint, credential, options = {}) {
461
- // credential.update(`SharedAccessKey ${credential.key}`);
441
+ constructor(endpoint, credential, topicName, options = {}) {
462
442
  this._client = new EventGridClient(endpoint, credential, options);
443
+ this._topicName = topicName;
444
+ this._client.pipeline.addPolicy(cloudEventDistributedTracingEnricherPolicy(), {
445
+ afterPolicies: [coreRestPipeline.tracingPolicyName],
446
+ });
463
447
  }
464
448
  /**
465
- * Publish Single Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200
449
+ * Publish Cloud Events to namespace topic. In case of success, the server responds with an HTTP 200
466
450
  * status code with an empty JSON object in response. Otherwise, the server can return various error codes.
467
451
  * For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
468
452
  * is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
469
453
  * internal server error.
470
454
  *
471
- * @param event - Event to publish
472
- * @param topicName - Topic to publish the event
455
+ * @param events - Events to publish
473
456
  * @param options - Options to publish
474
457
  *
475
458
  */
476
- async publishCloudEvent(event, topicName, options = { requestOptions: {} }) {
477
- const cloudEventWireModel = convertCloudEventToModelType(event);
478
- if (!options.binaryMode) {
479
- await this._client.publishCloudEvent(topicName, cloudEventWireModel, options);
459
+ async sendEvents(events, options = { requestOptions: {} }) {
460
+ if (Array.isArray(events)) {
461
+ const eventsWireModel = [];
462
+ for (const individualevent of events) {
463
+ eventsWireModel.push(convertCloudEventToModelType(individualevent));
464
+ }
465
+ await this._client.publishCloudEvents(this._topicName, eventsWireModel, options);
480
466
  }
481
467
  else {
482
- await publishCloudEventInBinaryMode(this._client.getClient(), topicName, cloudEventWireModel, Object.assign({ contentType: options.contentType }, options));
468
+ const cloudEventWireModel = convertCloudEventToModelType(events);
469
+ await this._client.publishCloudEvent(this._topicName, cloudEventWireModel, options);
483
470
  }
484
471
  }
485
- /**
486
- * Publish Batch Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200
487
- * status code with an empty JSON object in response. Otherwise, the server can return various error codes.
488
- * For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
489
- * is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
490
- * internal server error.
491
- *
492
- * @param events - Events to publish
493
- * @param topicName - Topic to publish the event
494
- * @param options - Options to publish
495
- *
496
- */
497
- async publishCloudEvents(events, topicName, options = { requestOptions: {} }) {
498
- const eventsWireModel = [];
499
- for (const individualevent of events) {
500
- eventsWireModel.push(convertCloudEventToModelType(individualevent));
472
+ }
473
+ function convertCloudEventToModelType(event) {
474
+ var _a, _b, _c, _d, _e;
475
+ if (event.extensionAttributes) {
476
+ for (const propName in event.extensionAttributes) {
477
+ // 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"
478
+ // they also can not match an existing defined property name.
479
+ if (!/^[a-z0-9]*$/.test(propName) ||
480
+ cloudEventReservedPropertyNames.indexOf(propName) !== -1) {
481
+ throw new Error(`invalid extension attribute name: ${propName}`);
482
+ }
501
483
  }
502
- await this._client.publishCloudEvents(topicName, eventsWireModel, options);
484
+ }
485
+ 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 : coreUtil.randomUUID(), time: (_c = event.time) !== null && _c !== void 0 ? _c : new Date(), subject: event.subject, dataschema: event.dataSchema, datacontenttype: event.dataContentType }, ((_d = event.extensionAttributes) !== null && _d !== void 0 ? _d : []));
486
+ if (event.data instanceof Uint8Array) {
487
+ if (!event.dataContentType) {
488
+ throw new Error("a data content type must be provided when sending an event with binary data");
489
+ }
490
+ converted.datacontenttype = event.dataContentType;
491
+ converted.dataBase64 = event.data;
492
+ }
493
+ else {
494
+ converted.datacontenttype =
495
+ (_e = event.dataContentType) !== null && _e !== void 0 ? _e : "application/cloudevents+json; charset=utf-8";
496
+ converted.data = event.data;
497
+ }
498
+ return converted;
499
+ }
500
+
501
+ // Copyright (c) Microsoft Corporation.
502
+ // Licensed under the MIT license.
503
+ /**
504
+ * Event Grid Namespaces Client
505
+ */
506
+ class EventGridReceiverClient {
507
+ /** Azure Messaging EventGrid Client */
508
+ constructor(endpoint, credential, topicName, subscriptionName, options = {}) {
509
+ this._client = new EventGridClient(endpoint, credential, options);
510
+ this._topicName = topicName;
511
+ this._subscriptionName = subscriptionName;
512
+ this._client.pipeline.addPolicy(cloudEventDistributedTracingEnricherPolicy(), {
513
+ afterPolicies: [coreRestPipeline.tracingPolicyName],
514
+ });
503
515
  }
504
516
  /**
505
517
  * Receive Batch of Cloud Events from the Event Subscription.
506
518
  *
507
- * @param topicName - Topic to receive
508
- * @param eventSubscriptionName - Name of the Event Subscription
509
519
  * @param options - Options to receive
510
520
  *
511
521
  */
512
- receiveCloudEvents(topicName, eventSubscriptionName, options = { requestOptions: {} }) {
513
- return this._client.receiveCloudEvents(topicName, eventSubscriptionName, options);
522
+ async receiveEvents(options = { requestOptions: {} }) {
523
+ const result = await this._client.receiveCloudEvents(this._topicName, this._subscriptionName, options);
524
+ const modifiedResult = {
525
+ details: result.details.map((receiveDetails) => {
526
+ const cloudEvent = {
527
+ type: receiveDetails.event.type,
528
+ source: receiveDetails.event.source,
529
+ id: receiveDetails.event.id,
530
+ time: receiveDetails.event.time,
531
+ dataSchema: receiveDetails.event.dataschema,
532
+ dataContentType: receiveDetails.event.datacontenttype,
533
+ subject: receiveDetails.event.subject,
534
+ specVersion: receiveDetails.event.specversion,
535
+ data: receiveDetails.event.data
536
+ ? receiveDetails.event.data
537
+ : receiveDetails.event.dataBase64
538
+ ? coreUtil.uint8ArrayToString(receiveDetails.event.dataBase64, "base64")
539
+ : undefined,
540
+ };
541
+ return {
542
+ brokerProperties: receiveDetails.brokerProperties,
543
+ event: cloudEvent,
544
+ };
545
+ }),
546
+ };
547
+ return modifiedResult;
514
548
  }
515
549
  /**
516
550
  * Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if at least one
@@ -519,13 +553,11 @@ class EventGridNamespacesClient {
519
553
  * acknowledged events will no longer be available to any consumer.
520
554
  *
521
555
  * @param lockTokens - Lock Tokens
522
- * @param topicName - Topic Name
523
- * @param eventSubscriptionName - Name of the Event Subscription
524
556
  * @param options - Options to Acknowledge
525
557
  *
526
558
  */
527
- acknowledgeCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
528
- return this._client.acknowledgeCloudEvents(topicName, eventSubscriptionName, { lockTokens }, options);
559
+ acknowledgeEvents(lockTokens, options = { requestOptions: {} }) {
560
+ return this._client.acknowledgeCloudEvents(this._topicName, this._subscriptionName, lockTokens, options);
529
561
  }
530
562
  /**
531
563
  * Release batch of Cloud Events. The server responds with an HTTP 200 status code if at least one event is
@@ -533,73 +565,243 @@ class EventGridNamespacesClient {
533
565
  * with other failed lockTokens with their corresponding error information.
534
566
  *
535
567
  * @param lockTokens - Lock Tokens
536
- * @param topicName - Topic Name
537
- * @param eventSubscriptionName - Name of the Event Subscription
538
568
  * @param options - Options to release
539
569
  *
540
570
  */
541
- releaseCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
542
- return this._client.releaseCloudEvents(topicName, eventSubscriptionName, { lockTokens }, options);
571
+ releaseEvents(lockTokens, options = { requestOptions: {} }) {
572
+ return this._client.releaseCloudEvents(this._topicName, this._subscriptionName, lockTokens, Object.assign(Object.assign({}, options), { releaseDelayInSeconds: options.releaseDelay }));
543
573
  }
544
574
  /**
545
575
  * Reject batch of Cloud Events.
546
576
  *
547
577
  * @param lockTokens - Lock Tokens
548
- * @param topicName - Topic Name
549
- * @param eventSubscriptionName - Name of the Event Subscription
550
578
  * @param options - Options to reject
551
579
  *
552
580
  */
553
- rejectCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
554
- return this._client.rejectCloudEvents(topicName, eventSubscriptionName, { lockTokens }, options);
581
+ rejectEvents(lockTokens, options = { requestOptions: {} }) {
582
+ return this._client.rejectCloudEvents(this._topicName, this._subscriptionName, lockTokens, options);
555
583
  }
556
584
  /**
557
585
  * Renew lock for batch of Cloud Events.
558
586
  *
559
587
  * @param lockTokens - Lock Tokens
560
- * @param topicName - Topic Name
561
- * @param eventSubscriptionName - Name of the Event Subscription
562
588
  * @param options - Options to renew
563
589
  */
564
- renewCloudEventLocks(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
565
- return this._client.renewCloudEventLocks(topicName, eventSubscriptionName, { lockTokens }, options);
590
+ renewEventLocks(lockTokens, options = { requestOptions: {} }) {
591
+ return this._client.renewCloudEventLocks(this._topicName, this._subscriptionName, lockTokens, options);
566
592
  }
567
593
  }
568
- function convertCloudEventToModelType(event) {
569
- var _a, _b, _c, _d, _e;
570
- if (event.extensionAttributes) {
571
- for (const propName in event.extensionAttributes) {
572
- // 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"
573
- // they also can not match an existing defined property name.
574
- if (!/^[a-z0-9]*$/.test(propName) ||
575
- cloudEventReservedPropertyNames.indexOf(propName) !== -1) {
576
- throw new Error(`invalid extension attribute name: ${propName}`);
577
- }
594
+
595
+ // Copyright (c) Microsoft Corporation.
596
+ // Licensed under the MIT license.
597
+ /**
598
+ * Stringifies a Date object in the format expected by the Event Grid service, for use in a Shared Access Signiture.
599
+ *
600
+ * The service expects this time string to be in the same format as what is returned by the .NET DateTime.ToString
601
+ * method, using the "en-US" culture.
602
+ *
603
+ * This corresponds to the .NET format string: "M/d/yyyy h:mm:ss tt". For example, the date "June 5th, 2020, 12:09:03 PM"
604
+ * is represented as the string "6/5/2020 12:09:03 PM"
605
+ *
606
+ * The service expects a UTC time, so this method returns a string based on the UTC time of the provided Date.
607
+ *
608
+ * @param d - The Date object to convert to a string.
609
+ */
610
+ function parseAndWrap(jsonStringOrObject) {
611
+ if (typeof jsonStringOrObject === "string") {
612
+ const o = JSON.parse(jsonStringOrObject);
613
+ if (Array.isArray(o)) {
614
+ return o;
578
615
  }
579
- }
580
- 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 : coreUtil.randomUUID(), 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 : []));
581
- if (event.data instanceof Uint8Array) {
582
- if (!event.datacontenttype) {
583
- throw new Error("a data content type must be provided when sending an event with binary data");
616
+ else {
617
+ return [o];
584
618
  }
585
- converted.datacontenttype = event.datacontenttype;
586
- converted.dataBase64 = event.data;
619
+ }
620
+ if (Array.isArray(jsonStringOrObject)) {
621
+ return jsonStringOrObject;
587
622
  }
588
623
  else {
589
- converted.datacontenttype =
590
- (_e = event.datacontenttype) !== null && _e !== void 0 ? _e : "application/cloudevents+json; charset=utf-8";
591
- converted.data = event.data;
624
+ return [jsonStringOrObject];
625
+ }
626
+ }
627
+ const CLOUD_EVENT_1_0_SPEC_VERSION = "1.0";
628
+ function validateCloudEventEvent(o) {
629
+ validateRequiredStringProperties(o, ["type", "source", "id", "specVersion"]);
630
+ validateOptionalStringProperties(o, ["time", "dataSchema", "dataContentType", "subject"]);
631
+ if (typeof o !== "object") {
632
+ throw new TypeError("event is not an object");
633
+ }
634
+ const castO = o;
635
+ if (castO.specVersion !== CLOUD_EVENT_1_0_SPEC_VERSION) {
636
+ throw new Error("event is not in the Cloud Event 1.0 schema");
637
+ }
638
+ }
639
+ function validateRequiredStringProperties(o, propertyNames) {
640
+ for (const propertyName of propertyNames) {
641
+ if (typeof o[propertyName] === "undefined") {
642
+ throw new Error(`event is missing required property '${propertyName}'`);
643
+ }
644
+ if (typeof o[propertyName] !== "string") {
645
+ throw new TypeError(`event property '${propertyName} should be a 'string', but is '${typeof o[propertyName]}'`);
646
+ }
647
+ }
648
+ }
649
+ function validateOptionalStringProperties(o, propertyNames) {
650
+ for (const propertyName of propertyNames) {
651
+ if (typeof o[propertyName] !== "undefined" && typeof o[propertyName] !== "string") {
652
+ throw new TypeError(`event property '${propertyName}' should be a 'string' but it is a '${typeof o[propertyName]}'`);
653
+ }
654
+ }
655
+ }
656
+ const CloudEvent = {
657
+ type: {
658
+ name: "Composite",
659
+ className: "CloudEvent",
660
+ additionalProperties: { type: { name: "Object" } },
661
+ modelProperties: {
662
+ id: {
663
+ serializedName: "id",
664
+ required: true,
665
+ type: {
666
+ name: "String",
667
+ },
668
+ },
669
+ source: {
670
+ serializedName: "source",
671
+ required: true,
672
+ type: {
673
+ name: "String",
674
+ },
675
+ },
676
+ data: {
677
+ serializedName: "data",
678
+ type: {
679
+ name: "any",
680
+ },
681
+ },
682
+ dataBase64: {
683
+ serializedName: "data_base64",
684
+ type: {
685
+ name: "ByteArray",
686
+ },
687
+ },
688
+ type: {
689
+ serializedName: "type",
690
+ required: true,
691
+ type: {
692
+ name: "String",
693
+ },
694
+ },
695
+ time: {
696
+ serializedName: "time",
697
+ type: {
698
+ name: "DateTime",
699
+ },
700
+ },
701
+ specversion: {
702
+ serializedName: "specversion",
703
+ required: true,
704
+ type: {
705
+ name: "String",
706
+ },
707
+ },
708
+ dataschema: {
709
+ serializedName: "dataschema",
710
+ type: {
711
+ name: "String",
712
+ },
713
+ },
714
+ datacontenttype: {
715
+ serializedName: "datacontenttype",
716
+ type: {
717
+ name: "String",
718
+ },
719
+ },
720
+ subject: {
721
+ serializedName: "subject",
722
+ type: {
723
+ name: "String",
724
+ },
725
+ },
726
+ },
727
+ },
728
+ };
729
+
730
+ // Copyright (c) Microsoft Corporation.
731
+ // Licensed under the MIT license.
732
+ const serializer = coreClient$1.createSerializer();
733
+ /**
734
+ * EventGridDeserializer is used to aid in processing events delivered by EventGrid. It can deserialize a JSON encoded payload
735
+ * of either a single event or batch of events as well as be used to convert the result of `JSON.parse` into an
736
+ * `EventGridEvent` or `CloudEvent` like object.
737
+ *
738
+ * Unlike normal JSON deseralization, EventGridDeserializer does some additional conversions:
739
+ *
740
+ * - The consumer parses the event time property into a `Date` object, for ease of use.
741
+ * - When deserializing an event in the CloudEvent schema, if the event contains binary data, it is base64 decoded
742
+ * and returned as an instance of the `Uint8Array` type.
743
+ */
744
+ class EventGridDeserializer {
745
+ async deserializeCloudEvents(encodedEvents) {
746
+ const decodedArray = parseAndWrap(encodedEvents);
747
+ const events = [];
748
+ for (const o of decodedArray) {
749
+ validateCloudEventEvent(o);
750
+ // Check that the required fields are present and of the correct type and the optional fields are missing
751
+ // or of the correct type.
752
+ const deserialized = serializer.deserialize(CloudEvent, o, "");
753
+ const modelEvent = {
754
+ specversion: deserialized.specversion,
755
+ id: deserialized.id,
756
+ source: deserialized.source,
757
+ type: deserialized.type,
758
+ };
759
+ if (deserialized.datacontenttype !== undefined) {
760
+ modelEvent.datacontenttype = deserialized.datacontenttype;
761
+ }
762
+ if (deserialized.dataschema !== undefined) {
763
+ modelEvent.dataschema = deserialized.dataschema;
764
+ }
765
+ if (deserialized.subject !== undefined) {
766
+ modelEvent.subject = deserialized.subject;
767
+ }
768
+ if (deserialized.time !== undefined) {
769
+ modelEvent.time = deserialized.time;
770
+ }
771
+ if (deserialized.data !== undefined) {
772
+ modelEvent.data = deserialized.data;
773
+ }
774
+ // If the data the event represents binary, it is encoded as base64 text in a different property on the event and we need to transform it.
775
+ if (deserialized.dataBase64 !== undefined) {
776
+ if (deserialized.data !== undefined) {
777
+ throw new TypeError("event contains both a data and data_base64 field");
778
+ }
779
+ if (!(deserialized.dataBase64 instanceof Uint8Array)) {
780
+ throw new TypeError("event data_base64 property is not an instance of Uint8Array");
781
+ }
782
+ modelEvent.data = deserialized.dataBase64;
783
+ }
784
+ // Build the "extensionsAttributes" property bag by removing all known top level properties.
785
+ const extensionAttributes = Object.assign({}, deserialized);
786
+ for (const propName of cloudEventReservedPropertyNames) {
787
+ delete extensionAttributes[propName];
788
+ }
789
+ delete extensionAttributes.dataBase64;
790
+ // If any properties remain, copy them to the model.
791
+ if (Object.keys(extensionAttributes).length > 0) {
792
+ modelEvent.extensionAttributes = extensionAttributes;
793
+ }
794
+ events.push(modelEvent);
795
+ }
796
+ return events;
592
797
  }
593
- return converted;
594
798
  }
595
799
 
596
800
  Object.defineProperty(exports, "AzureKeyCredential", {
597
801
  enumerable: true,
598
802
  get: function () { return coreAuth.AzureKeyCredential; }
599
803
  });
600
- Object.defineProperty(exports, "EventGridDeserializer", {
601
- enumerable: true,
602
- get: function () { return eventgrid.EventGridDeserializer; }
603
- });
604
- exports.EventGridClient = EventGridNamespacesClient;
804
+ exports.EventGridDeserializer = EventGridDeserializer;
805
+ exports.EventGridReceiverClient = EventGridReceiverClient;
806
+ exports.EventGridSenderClient = EventGridSenderClient;
605
807
  //# sourceMappingURL=index.js.map