@azure/eventgrid-namespaces 1.0.0-beta.1 → 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 (40) hide show
  1. package/README.md +45 -19
  2. package/dist/index.js +403 -196
  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 -1
  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 +10 -10
  36. package/types/eventgrid-namespaces.d.ts +127 -97
  37. package/dist-esm/src/constants.js +0 -5
  38. package/dist-esm/src/constants.js.map +0 -1
  39. package/dist-esm/src/eventGridNamespacesClient.js +0 -147
  40. package/dist-esm/src/eventGridNamespacesClient.js.map +0 -1
package/dist/index.js CHANGED
@@ -6,7 +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');
9
+ var coreRestPipeline = require('@azure/core-rest-pipeline');
10
+ var coreClient$1 = require('@azure/core-client');
10
11
 
11
12
  // Copyright (c) Microsoft Corporation.
12
13
  // Licensed under the MIT license.
@@ -16,27 +17,27 @@ const logger = logger$1.createClientLogger("eventgrid-namespaces");
16
17
  // Licensed under the MIT license.
17
18
  /**
18
19
  * Initialize a new instance of `EventGridContext`
19
- * @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
20
21
  * @param credentials - uniquely identify client credential
21
22
  * @param options - the parameter for all optional parameters
22
23
  */
23
- function createClient(endpoint, credentials, options = {}) {
24
- var _a, _b, _c, _d, _e, _f;
25
- const baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : `${endpoint}`;
26
- options.apiVersion = (_b = options.apiVersion) !== null && _b !== void 0 ? _b : "2023-10-01-preview";
27
- 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`;
28
29
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
29
30
  ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
30
31
  : `${userAgentInfo}`;
31
32
  options = Object.assign(Object.assign({}, options), { userAgentOptions: {
32
33
  userAgentPrefix,
33
34
  }, loggingOptions: {
34
- 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,
35
36
  }, credentials: {
36
- 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"],
37
38
  apiKeyHeaderName: "Authorization",
38
39
  } });
39
- const client = coreClient.getClient(baseUrl, credentials, options);
40
+ const client = coreClient.getClient(endpointUrl, credentials, options);
40
41
  if (coreAuth.isKeyCredential(credentials)) {
41
42
  client.pipeline.addPolicy({
42
43
  name: "customKeyCredentialPolicy",
@@ -127,8 +128,8 @@ function getPathFromMapKey(mapKey) {
127
128
  // Copyright (c) Microsoft Corporation.
128
129
  // Licensed under the MIT license.
129
130
  /** Azure Messaging EventGrid Client */
130
- function createEventGrid(endpoint, credential, options = {}) {
131
- const clientContext = createClient(endpoint, credential, options);
131
+ function createEventGrid(endpointParam, credential, options = {}) {
132
+ const clientContext = createClient(endpointParam, credential, options);
132
133
  return clientContext;
133
134
  }
134
135
 
@@ -151,16 +152,16 @@ function _publishCloudEventSend(context, topicName, event, options = { requestOp
151
152
  subject: event["subject"],
152
153
  } }));
153
154
  }
154
- async function _publishCloudEventDeserialize$1(result) {
155
+ async function _publishCloudEventDeserialize(result) {
155
156
  if (isUnexpected(result)) {
156
157
  throw coreClient.createRestError(result);
157
158
  }
158
159
  return result.body;
159
160
  }
160
- /** 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. */
161
162
  async function publishCloudEvent(context, topicName, event, options = { requestOptions: {} }) {
162
163
  const result = await _publishCloudEventSend(context, topicName, event, options);
163
- return _publishCloudEventDeserialize$1(result);
164
+ return _publishCloudEventDeserialize(result);
164
165
  }
165
166
  function _publishCloudEventsSend(context, topicName, events, options = { requestOptions: {} }) {
166
167
  var _a;
@@ -186,7 +187,7 @@ async function _publishCloudEventsDeserialize(result) {
186
187
  }
187
188
  return result.body;
188
189
  }
189
- /** 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. */
190
191
  async function publishCloudEvents(context, topicName, events, options = { requestOptions: {} }) {
191
192
  const result = await _publishCloudEventsSend(context, topicName, events, options);
192
193
  return _publishCloudEventsDeserialize(result);
@@ -204,7 +205,7 @@ async function _receiveCloudEventsDeserialize(result) {
204
205
  throw coreClient.createRestError(result);
205
206
  }
206
207
  return {
207
- value: result.body["value"].map((p) => ({
208
+ details: result.body["value"].map((p) => ({
208
209
  brokerProperties: {
209
210
  lockToken: p.brokerProperties["lockToken"],
210
211
  deliveryCount: p.brokerProperties["deliveryCount"],
@@ -226,15 +227,15 @@ async function _receiveCloudEventsDeserialize(result) {
226
227
  })),
227
228
  };
228
229
  }
229
- /** Receive Batch of Cloud Events from the Event Subscription. */
230
+ /** Receive a batch of Cloud Events from a subscription. */
230
231
  async function receiveCloudEvents(context, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
231
232
  const result = await _receiveCloudEventsSend(context, topicName, eventSubscriptionName, options);
232
233
  return _receiveCloudEventsDeserialize(result);
233
234
  }
234
- function _acknowledgeCloudEventsSend(context, topicName, eventSubscriptionName, acknowledgeOptions, options = { requestOptions: {} }) {
235
+ function _acknowledgeCloudEventsSend(context, topicName, eventSubscriptionName, lockTokens, options = { requestOptions: {} }) {
235
236
  return context
236
237
  .path("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:acknowledge", topicName, eventSubscriptionName)
237
- .post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { body: { lockTokens: acknowledgeOptions["lockTokens"] } }));
238
+ .post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { body: { lockTokens: lockTokens } }));
238
239
  }
239
240
  async function _acknowledgeCloudEventsDeserialize(result) {
240
241
  if (isUnexpected(result)) {
@@ -248,21 +249,17 @@ async function _acknowledgeCloudEventsDeserialize(result) {
248
249
  succeededLockTokens: result.body["succeededLockTokens"],
249
250
  };
250
251
  }
251
- /** 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. */
252
- async function acknowledgeCloudEvents(context, topicName, eventSubscriptionName, acknowledgeOptions, options = { requestOptions: {} }) {
253
- 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);
254
255
  return _acknowledgeCloudEventsDeserialize(result);
255
256
  }
256
- function _releaseCloudEventsSend(context, topicName, eventSubscriptionName, releaseOptions, options = { requestOptions: {} }) {
257
- let releaseDelayInSeconds = undefined;
258
- if (options === null || options === void 0 ? void 0 : options.releaseDelayInSeconds) {
259
- releaseDelayInSeconds = parseInt(options.releaseDelayInSeconds);
260
- }
257
+ function _releaseCloudEventsSend(context, topicName, eventSubscriptionName, lockTokens, options = { requestOptions: {} }) {
261
258
  return context
262
259
  .path("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:release", topicName, eventSubscriptionName)
263
260
  .post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { queryParameters: {
264
- releaseDelayInSeconds,
265
- }, body: { lockTokens: releaseOptions["lockTokens"] } }));
261
+ releaseDelayInSeconds: options === null || options === void 0 ? void 0 : options.releaseDelayInSeconds,
262
+ }, body: { lockTokens: lockTokens } }));
266
263
  }
267
264
  async function _releaseCloudEventsDeserialize(result) {
268
265
  if (isUnexpected(result)) {
@@ -276,15 +273,15 @@ async function _releaseCloudEventsDeserialize(result) {
276
273
  succeededLockTokens: result.body["succeededLockTokens"],
277
274
  };
278
275
  }
279
- /** 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. */
280
- async function releaseCloudEvents(context, topicName, eventSubscriptionName, releaseOptions, options = { requestOptions: {} }) {
281
- 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);
282
279
  return _releaseCloudEventsDeserialize(result);
283
280
  }
284
- function _rejectCloudEventsSend(context, topicName, eventSubscriptionName, rejectOptions, options = { requestOptions: {} }) {
281
+ function _rejectCloudEventsSend(context, topicName, eventSubscriptionName, lockTokens, options = { requestOptions: {} }) {
285
282
  return context
286
283
  .path("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:reject", topicName, eventSubscriptionName)
287
- .post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { body: { lockTokens: rejectOptions["lockTokens"] } }));
284
+ .post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { body: { lockTokens: lockTokens } }));
288
285
  }
289
286
  async function _rejectCloudEventsDeserialize(result) {
290
287
  if (isUnexpected(result)) {
@@ -298,15 +295,15 @@ async function _rejectCloudEventsDeserialize(result) {
298
295
  succeededLockTokens: result.body["succeededLockTokens"],
299
296
  };
300
297
  }
301
- /** 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. */
302
- async function rejectCloudEvents(context, topicName, eventSubscriptionName, rejectOptions, options = { requestOptions: {} }) {
303
- 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);
304
301
  return _rejectCloudEventsDeserialize(result);
305
302
  }
306
- function _renewCloudEventLocksSend(context, topicName, eventSubscriptionName, renewLockOptions, options = { requestOptions: {} }) {
303
+ function _renewCloudEventLocksSend(context, topicName, eventSubscriptionName, lockTokens, options = { requestOptions: {} }) {
307
304
  return context
308
305
  .path("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:renewLock", topicName, eventSubscriptionName)
309
- .post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { body: { lockTokens: renewLockOptions["lockTokens"] } }));
306
+ .post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { body: { lockTokens: lockTokens } }));
310
307
  }
311
308
  async function _renewCloudEventLocksDeserialize(result) {
312
309
  if (isUnexpected(result)) {
@@ -320,9 +317,9 @@ async function _renewCloudEventLocksDeserialize(result) {
320
317
  succeededLockTokens: result.body["succeededLockTokens"],
321
318
  };
322
319
  }
323
- /** 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. */
324
- async function renewCloudEventLocks(context, topicName, eventSubscriptionName, renewLockOptions, options = { requestOptions: {} }) {
325
- 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);
326
323
  return _renewCloudEventLocksDeserialize(result);
327
324
  }
328
325
 
@@ -333,57 +330,49 @@ class EventGridClient {
333
330
  return this._client;
334
331
  }
335
332
  /** Azure Messaging EventGrid Client */
336
- constructor(endpoint, credential, options = {}) {
337
- this._client = createEventGrid(endpoint, credential, options);
333
+ constructor(endpointParam, credential, options = {}) {
334
+ this._client = createEventGrid(endpointParam, credential, options);
338
335
  this.pipeline = this._client.pipeline;
339
336
  }
340
- /** 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. */
341
338
  publishCloudEvent(topicName, event, options = { requestOptions: {} }) {
342
339
  return publishCloudEvent(this._client, topicName, event, options);
343
340
  }
344
- /** 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. */
345
342
  publishCloudEvents(topicName, events, options = { requestOptions: {} }) {
346
343
  return publishCloudEvents(this._client, topicName, events, options);
347
344
  }
348
- /** Receive Batch of Cloud Events from the Event Subscription. */
345
+ /** Receive a batch of Cloud Events from a subscription. */
349
346
  receiveCloudEvents(topicName, eventSubscriptionName, options = { requestOptions: {} }) {
350
347
  return receiveCloudEvents(this._client, topicName, eventSubscriptionName, options);
351
348
  }
352
- /** 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. */
353
- acknowledgeCloudEvents(topicName, eventSubscriptionName,
354
- // eslint-disable-next-line @azure/azure-sdk/ts-naming-options
355
- acknowledgeOptions, options = { requestOptions: {} }) {
356
- 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);
357
352
  }
358
- /** 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. */
359
- releaseCloudEvents(topicName, eventSubscriptionName,
360
- // eslint-disable-next-line @azure/azure-sdk/ts-naming-options
361
- releaseOptions, options = { requestOptions: {} }) {
362
- 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);
363
356
  }
364
- /** 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. */
365
- rejectCloudEvents(topicName, eventSubscriptionName,
366
- // eslint-disable-next-line @azure/azure-sdk/ts-naming-options
367
- rejectOptions, options = { requestOptions: {} }) {
368
- 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);
369
360
  }
370
- /** 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. */
371
- renewCloudEventLocks(topicName, eventSubscriptionName,
372
- // eslint-disable-next-line @azure/azure-sdk/ts-naming-options
373
- renewLockOptions, options = { requestOptions: {} }) {
374
- 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);
375
364
  }
376
365
  }
377
366
 
378
367
  // Copyright (c) Microsoft Corporation.
379
368
  // Licensed under the MIT license.
380
369
  const cloudEventReservedPropertyNames = [
381
- "specversion",
370
+ "specVersion",
382
371
  "id",
383
372
  "source",
384
373
  "type",
385
- "datacontenttype",
386
- "dataschema",
374
+ "dataContentType",
375
+ "dataSchema",
387
376
  "subject",
388
377
  "time",
389
378
  "data",
@@ -391,62 +380,55 @@ const cloudEventReservedPropertyNames = [
391
380
 
392
381
  // Copyright (c) Microsoft Corporation.
393
382
  // Licensed under the MIT license.
394
- async function publishCloudEventInBinaryMode(context, topicName, event, options = { requestOptions: {} }) {
395
- const result = await _publishCloudEventSendBinaryMode(context, topicName, event, options);
396
- return _publishCloudEventDeserialize(result);
397
- }
398
- async function _publishCloudEventDeserialize(result) {
399
- if (isUnexpected(result)) {
400
- throw result.body;
401
- }
402
- return result.body;
403
- }
404
- function _publishCloudEventSendBinaryMode(context, topicName, event, options = { requestOptions: {} }) {
405
- var _a, _b;
406
- const headers = {
407
- "ce-id": event.id,
408
- "ce-source": event.source,
409
- "ce-type": event.type,
410
- "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
+ },
411
431
  };
412
- if (event.time) {
413
- headers["ce-time"] = event.time.toISOString();
414
- }
415
- if (event.dataschema) {
416
- headers["ce-dataschema"] = event.dataschema;
417
- }
418
- if (event.datacontenttype) {
419
- headers["ce-datacontenttype"] = event.datacontenttype;
420
- }
421
- if (event.subject) {
422
- headers["ce-subject"] = event.subject;
423
- }
424
- let data;
425
- if (event.data) {
426
- // If data is already encoded
427
- if (buffer.Buffer.isBuffer(event.data)) {
428
- data = event.data;
429
- }
430
- else {
431
- throw new Error(`CloudEvent data must be binary when in binary mode.`);
432
- }
433
- }
434
- else {
435
- if (event.dataBase64) {
436
- data = event.dataBase64;
437
- }
438
- }
439
- 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: {
440
- id: event.id,
441
- source: event.source,
442
- data,
443
- type: event.type,
444
- time: (_b = event.time) === null || _b === void 0 ? void 0 : _b.toISOString(),
445
- specversion: event.specversion,
446
- dataschema: event.dataschema,
447
- datacontenttype: event.datacontenttype,
448
- subject: event.subject,
449
- } }));
450
432
  }
451
433
 
452
434
  // Copyright (c) Microsoft Corporation.
@@ -454,62 +436,115 @@ function _publishCloudEventSendBinaryMode(context, topicName, event, options = {
454
436
  /**
455
437
  * Event Grid Namespaces Client
456
438
  */
457
- class EventGridNamespacesClient {
439
+ class EventGridSenderClient {
458
440
  /** Azure Messaging EventGrid Client */
459
- constructor(endpoint, credential, options = {}) {
460
- // credential.update(`SharedAccessKey ${credential.key}`);
441
+ constructor(endpoint, credential, topicName, options = {}) {
461
442
  this._client = new EventGridClient(endpoint, credential, options);
443
+ this._topicName = topicName;
444
+ this._client.pipeline.addPolicy(cloudEventDistributedTracingEnricherPolicy(), {
445
+ afterPolicies: [coreRestPipeline.tracingPolicyName],
446
+ });
462
447
  }
463
448
  /**
464
- * 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
465
450
  * status code with an empty JSON object in response. Otherwise, the server can return various error codes.
466
451
  * For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
467
452
  * is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
468
453
  * internal server error.
469
454
  *
470
- * @param event - Event to publish
471
- * @param topicName - Topic to publish the event
455
+ * @param events - Events to publish
472
456
  * @param options - Options to publish
473
457
  *
474
458
  */
475
- async publishCloudEvent(event, topicName, options = { requestOptions: {} }) {
476
- const cloudEventWireModel = convertCloudEventToModelType(event);
477
- if (!options.binaryMode) {
478
- 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);
479
466
  }
480
467
  else {
481
- 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);
482
470
  }
483
471
  }
484
- /**
485
- * Publish Batch Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200
486
- * status code with an empty JSON object in response. Otherwise, the server can return various error codes.
487
- * For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
488
- * is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
489
- * internal server error.
490
- *
491
- * @param events - Events to publish
492
- * @param topicName - Topic to publish the event
493
- * @param options - Options to publish
494
- *
495
- */
496
- async publishCloudEvents(events, topicName, options = { requestOptions: {} }) {
497
- const eventsWireModel = [];
498
- for (const individualevent of events) {
499
- 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
+ }
483
+ }
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");
500
489
  }
501
- await this._client.publishCloudEvents(topicName, eventsWireModel, options);
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
+ });
502
515
  }
503
516
  /**
504
517
  * Receive Batch of Cloud Events from the Event Subscription.
505
518
  *
506
- * @param topicName - Topic to receive
507
- * @param eventSubscriptionName - Name of the Event Subscription
508
519
  * @param options - Options to receive
509
520
  *
510
521
  */
511
- receiveCloudEvents(topicName, eventSubscriptionName, options = { requestOptions: {} }) {
512
- 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;
513
548
  }
514
549
  /**
515
550
  * Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if at least one
@@ -518,13 +553,11 @@ class EventGridNamespacesClient {
518
553
  * acknowledged events will no longer be available to any consumer.
519
554
  *
520
555
  * @param lockTokens - Lock Tokens
521
- * @param topicName - Topic Name
522
- * @param eventSubscriptionName - Name of the Event Subscription
523
556
  * @param options - Options to Acknowledge
524
557
  *
525
558
  */
526
- acknowledgeCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
527
- return this._client.acknowledgeCloudEvents(topicName, eventSubscriptionName, { lockTokens }, options);
559
+ acknowledgeEvents(lockTokens, options = { requestOptions: {} }) {
560
+ return this._client.acknowledgeCloudEvents(this._topicName, this._subscriptionName, lockTokens, options);
528
561
  }
529
562
  /**
530
563
  * Release batch of Cloud Events. The server responds with an HTTP 200 status code if at least one event is
@@ -532,69 +565,243 @@ class EventGridNamespacesClient {
532
565
  * with other failed lockTokens with their corresponding error information.
533
566
  *
534
567
  * @param lockTokens - Lock Tokens
535
- * @param topicName - Topic Name
536
- * @param eventSubscriptionName - Name of the Event Subscription
537
568
  * @param options - Options to release
538
569
  *
539
570
  */
540
- releaseCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
541
- 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 }));
542
573
  }
543
574
  /**
544
575
  * Reject batch of Cloud Events.
545
576
  *
546
577
  * @param lockTokens - Lock Tokens
547
- * @param topicName - Topic Name
548
- * @param eventSubscriptionName - Name of the Event Subscription
549
578
  * @param options - Options to reject
550
579
  *
551
580
  */
552
- rejectCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
553
- return this._client.rejectCloudEvents(topicName, eventSubscriptionName, { lockTokens }, options);
581
+ rejectEvents(lockTokens, options = { requestOptions: {} }) {
582
+ return this._client.rejectCloudEvents(this._topicName, this._subscriptionName, lockTokens, options);
554
583
  }
555
584
  /**
556
585
  * Renew lock for batch of Cloud Events.
557
586
  *
558
587
  * @param lockTokens - Lock Tokens
559
- * @param topicName - Topic Name
560
- * @param eventSubscriptionName - Name of the Event Subscription
561
588
  * @param options - Options to renew
562
589
  */
563
- renewCloudEventLocks(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
564
- return this._client.renewCloudEventLocks(topicName, eventSubscriptionName, { lockTokens }, options);
590
+ renewEventLocks(lockTokens, options = { requestOptions: {} }) {
591
+ return this._client.renewCloudEventLocks(this._topicName, this._subscriptionName, lockTokens, options);
565
592
  }
566
593
  }
567
- function convertCloudEventToModelType(event) {
568
- var _a, _b, _c, _d, _e;
569
- if (event.extensionAttributes) {
570
- for (const propName in event.extensionAttributes) {
571
- // 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"
572
- // they also can not match an existing defined property name.
573
- if (!/^[a-z0-9]*$/.test(propName) ||
574
- cloudEventReservedPropertyNames.indexOf(propName) !== -1) {
575
- throw new Error(`invalid extension attribute name: ${propName}`);
576
- }
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;
577
615
  }
578
- }
579
- 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 : []));
580
- if (event.data instanceof Uint8Array) {
581
- if (!event.datacontenttype) {
582
- throw new Error("a data content type must be provided when sending an event with binary data");
616
+ else {
617
+ return [o];
583
618
  }
584
- converted.datacontenttype = event.datacontenttype;
585
- converted.dataBase64 = event.data;
619
+ }
620
+ if (Array.isArray(jsonStringOrObject)) {
621
+ return jsonStringOrObject;
586
622
  }
587
623
  else {
588
- converted.datacontenttype =
589
- (_e = event.datacontenttype) !== null && _e !== void 0 ? _e : "application/cloudevents+json; charset=utf-8";
590
- 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;
591
797
  }
592
- return converted;
593
798
  }
594
799
 
595
800
  Object.defineProperty(exports, "AzureKeyCredential", {
596
801
  enumerable: true,
597
802
  get: function () { return coreAuth.AzureKeyCredential; }
598
803
  });
599
- exports.EventGridClient = EventGridNamespacesClient;
804
+ exports.EventGridDeserializer = EventGridDeserializer;
805
+ exports.EventGridReceiverClient = EventGridReceiverClient;
806
+ exports.EventGridSenderClient = EventGridSenderClient;
600
807
  //# sourceMappingURL=index.js.map