@azure/eventgrid-namespaces 1.0.0-alpha.20240513.1 → 1.0.0-alpha.20240606.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/index.js +454 -200
  2. package/dist/index.js.map +1 -1
  3. package/dist-esm/src/cadl-generated/EventGridClient.js +20 -28
  4. package/dist-esm/src/cadl-generated/EventGridClient.js.map +1 -1
  5. package/dist-esm/src/cadl-generated/api/EventGridContext.js +2 -2
  6. package/dist-esm/src/cadl-generated/api/EventGridContext.js.map +1 -1
  7. package/dist-esm/src/cadl-generated/api/operations.js +25 -29
  8. package/dist-esm/src/cadl-generated/api/operations.js.map +1 -1
  9. package/dist-esm/src/cadl-generated/index.js.map +1 -1
  10. package/dist-esm/src/cadl-generated/models/index.js.map +1 -1
  11. package/dist-esm/src/cadl-generated/models/models.js.map +1 -1
  12. package/dist-esm/src/cadl-generated/models/options.js.map +1 -1
  13. package/dist-esm/src/cadl-generated/rest/clientDefinitions.js.map +1 -1
  14. package/dist-esm/src/cadl-generated/rest/eventGridClient.js +9 -9
  15. package/dist-esm/src/cadl-generated/rest/eventGridClient.js.map +1 -1
  16. package/dist-esm/src/cadl-generated/rest/isUnexpected.js.map +1 -1
  17. package/dist-esm/src/cadl-generated/rest/models.js.map +1 -1
  18. package/dist-esm/src/cadl-generated/rest/parameters.js.map +1 -1
  19. package/dist-esm/src/cloudEventDistrubtedTracingEnricherPolicy.js +53 -0
  20. package/dist-esm/src/cloudEventDistrubtedTracingEnricherPolicy.js.map +1 -0
  21. package/dist-esm/src/consumer.js +73 -0
  22. package/dist-esm/src/consumer.js.map +1 -0
  23. package/dist-esm/src/eventGridNamespacesPublishBinaryMode.js.map +1 -1
  24. package/dist-esm/src/eventGridReceiverClient.js +144 -0
  25. package/dist-esm/src/eventGridReceiverClient.js.map +1 -0
  26. package/dist-esm/src/eventGridSenderClient.js +78 -0
  27. package/dist-esm/src/eventGridSenderClient.js.map +1 -0
  28. package/dist-esm/src/index.js +3 -2
  29. package/dist-esm/src/index.js.map +1 -1
  30. package/dist-esm/src/models.js +3 -3
  31. package/dist-esm/src/models.js.map +1 -1
  32. package/dist-esm/src/util.js +155 -0
  33. package/dist-esm/src/util.js.map +1 -0
  34. package/package.json +3 -3
  35. package/types/eventgrid-namespaces.d.ts +154 -99
  36. package/dist-esm/src/eventGridNamespacesClient.js +0 -147
  37. 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,131 @@ 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
441
  constructor(endpoint, credential, options = {}) {
461
- // credential.update(`SharedAccessKey ${credential.key}`);
442
+ var _a;
462
443
  this._client = new EventGridClient(endpoint, credential, options);
444
+ this._topicName = (_a = options === null || options === void 0 ? void 0 : options.topicName) !== null && _a !== void 0 ? _a : undefined;
445
+ this._client.pipeline.addPolicy(cloudEventDistributedTracingEnricherPolicy(), {
446
+ afterPolicies: [coreRestPipeline.tracingPolicyName],
447
+ });
463
448
  }
464
449
  /**
465
- * Publish Single Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200
450
+ * Publish Cloud Events to namespace topic. In case of success, the server responds with an HTTP 200
466
451
  * status code with an empty JSON object in response. Otherwise, the server can return various error codes.
467
452
  * For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
468
453
  * is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
469
454
  * internal server error.
470
455
  *
471
- * @param event - Event to publish
472
- * @param topicName - Topic to publish the event
456
+ * @param events - Events to publish
473
457
  * @param options - Options to publish
474
458
  *
475
459
  */
476
- async publishCloudEvent(event, topicName, options = { requestOptions: {} }) {
477
- const cloudEventWireModel = convertCloudEventToModelType(event);
478
- if (!options.binaryMode) {
479
- await this._client.publishCloudEvent(topicName, cloudEventWireModel, options);
460
+ async sendEvents(events, options = { requestOptions: {} }) {
461
+ var _a;
462
+ const topicName = (_a = options === null || options === void 0 ? void 0 : options.topicName) !== null && _a !== void 0 ? _a : this._topicName;
463
+ if (!topicName) {
464
+ throw new Error("Topic name is required");
465
+ }
466
+ if (Array.isArray(events)) {
467
+ const eventsWireModel = [];
468
+ for (const individualevent of events) {
469
+ eventsWireModel.push(convertCloudEventToModelType(individualevent));
470
+ }
471
+ await this._client.publishCloudEvents(topicName, eventsWireModel, options);
480
472
  }
481
473
  else {
482
- await publishCloudEventInBinaryMode(this._client.getClient(), topicName, cloudEventWireModel, Object.assign({ contentType: options.contentType }, options));
474
+ const cloudEventWireModel = convertCloudEventToModelType(events);
475
+ await this._client.publishCloudEvent(topicName, cloudEventWireModel, options);
483
476
  }
484
477
  }
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));
478
+ }
479
+ function convertCloudEventToModelType(event) {
480
+ var _a, _b, _c, _d, _e;
481
+ if (event.extensionAttributes) {
482
+ for (const propName in event.extensionAttributes) {
483
+ // 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"
484
+ // they also can not match an existing defined property name.
485
+ if (!/^[a-z0-9]*$/.test(propName) ||
486
+ cloudEventReservedPropertyNames.indexOf(propName) !== -1) {
487
+ throw new Error(`invalid extension attribute name: ${propName}`);
488
+ }
501
489
  }
502
- await this._client.publishCloudEvents(topicName, eventsWireModel, options);
490
+ }
491
+ 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 : []));
492
+ if (event.data instanceof Uint8Array) {
493
+ if (!event.dataContentType) {
494
+ throw new Error("a data content type must be provided when sending an event with binary data");
495
+ }
496
+ converted.datacontenttype = event.dataContentType;
497
+ converted.dataBase64 = event.data;
498
+ }
499
+ else {
500
+ converted.datacontenttype =
501
+ (_e = event.dataContentType) !== null && _e !== void 0 ? _e : "application/cloudevents+json; charset=utf-8";
502
+ converted.data = event.data;
503
+ }
504
+ return converted;
505
+ }
506
+
507
+ // Copyright (c) Microsoft Corporation.
508
+ // Licensed under the MIT license.
509
+ /**
510
+ * Event Grid Namespaces Client
511
+ */
512
+ class EventGridReceiverClient {
513
+ /** Azure Messaging EventGrid Client */
514
+ constructor(endpoint, credential, options = {}) {
515
+ var _a, _b;
516
+ this._client = new EventGridClient(endpoint, credential, options);
517
+ this._topicName = (_a = options === null || options === void 0 ? void 0 : options.topicName) !== null && _a !== void 0 ? _a : undefined;
518
+ this._eventSubscriptionName = (_b = options === null || options === void 0 ? void 0 : options.eventSubscriptionName) !== null && _b !== void 0 ? _b : undefined;
519
+ this._client.pipeline.addPolicy(cloudEventDistributedTracingEnricherPolicy(), {
520
+ afterPolicies: [coreRestPipeline.tracingPolicyName],
521
+ });
503
522
  }
504
523
  /**
505
524
  * Receive Batch of Cloud Events from the Event Subscription.
506
525
  *
507
- * @param topicName - Topic to receive
508
- * @param eventSubscriptionName - Name of the Event Subscription
509
526
  * @param options - Options to receive
510
527
  *
511
528
  */
512
- receiveCloudEvents(topicName, eventSubscriptionName, options = { requestOptions: {} }) {
513
- return this._client.receiveCloudEvents(topicName, eventSubscriptionName, options);
529
+ async receiveEvents(options = { requestOptions: {} }) {
530
+ var _a, _b;
531
+ const topicName = (_a = options === null || options === void 0 ? void 0 : options.topicName) !== null && _a !== void 0 ? _a : this._topicName;
532
+ if (!topicName) {
533
+ throw new Error("Topic name is required");
534
+ }
535
+ const eventSubscriptionName = (_b = options === null || options === void 0 ? void 0 : options.eventSubscriptionName) !== null && _b !== void 0 ? _b : this._eventSubscriptionName;
536
+ if (!eventSubscriptionName) {
537
+ throw new Error("Event Subscription name is required");
538
+ }
539
+ const result = await this._client.receiveCloudEvents(topicName, eventSubscriptionName, options);
540
+ const modifiedResult = {
541
+ details: result.details.map((receiveDetails) => {
542
+ const cloudEvent = {
543
+ type: receiveDetails.event.type,
544
+ source: receiveDetails.event.source,
545
+ id: receiveDetails.event.id,
546
+ time: receiveDetails.event.time,
547
+ dataSchema: receiveDetails.event.dataschema,
548
+ dataContentType: receiveDetails.event.datacontenttype,
549
+ subject: receiveDetails.event.subject,
550
+ specVersion: receiveDetails.event.specversion,
551
+ data: receiveDetails.event.data
552
+ ? receiveDetails.event.data
553
+ : receiveDetails.event.dataBase64
554
+ ? coreUtil.uint8ArrayToString(receiveDetails.event.dataBase64, "base64")
555
+ : undefined,
556
+ };
557
+ return {
558
+ brokerProperties: receiveDetails.brokerProperties,
559
+ event: cloudEvent,
560
+ };
561
+ }),
562
+ };
563
+ return modifiedResult;
514
564
  }
515
565
  /**
516
566
  * Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if at least one
@@ -519,13 +569,20 @@ class EventGridNamespacesClient {
519
569
  * acknowledged events will no longer be available to any consumer.
520
570
  *
521
571
  * @param lockTokens - Lock Tokens
522
- * @param topicName - Topic Name
523
- * @param eventSubscriptionName - Name of the Event Subscription
524
572
  * @param options - Options to Acknowledge
525
573
  *
526
574
  */
527
- acknowledgeCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
528
- return this._client.acknowledgeCloudEvents(topicName, eventSubscriptionName, { lockTokens }, options);
575
+ acknowledgeEvents(lockTokens, options = { requestOptions: {} }) {
576
+ var _a, _b;
577
+ const topicName = (_a = options === null || options === void 0 ? void 0 : options.topicName) !== null && _a !== void 0 ? _a : this._topicName;
578
+ if (!topicName) {
579
+ throw new Error("Topic name is required");
580
+ }
581
+ const eventSubscriptionName = (_b = options === null || options === void 0 ? void 0 : options.eventSubscriptionName) !== null && _b !== void 0 ? _b : this._eventSubscriptionName;
582
+ if (!eventSubscriptionName) {
583
+ throw new Error("Event Subscription name is required");
584
+ }
585
+ return this._client.acknowledgeCloudEvents(topicName, eventSubscriptionName, lockTokens, options);
529
586
  }
530
587
  /**
531
588
  * Release batch of Cloud Events. The server responds with an HTTP 200 status code if at least one event is
@@ -533,73 +590,270 @@ class EventGridNamespacesClient {
533
590
  * with other failed lockTokens with their corresponding error information.
534
591
  *
535
592
  * @param lockTokens - Lock Tokens
536
- * @param topicName - Topic Name
537
- * @param eventSubscriptionName - Name of the Event Subscription
538
593
  * @param options - Options to release
539
594
  *
540
595
  */
541
- releaseCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
542
- return this._client.releaseCloudEvents(topicName, eventSubscriptionName, { lockTokens }, options);
596
+ releaseEvents(lockTokens, options = { requestOptions: {} }) {
597
+ var _a, _b;
598
+ const topicName = (_a = options === null || options === void 0 ? void 0 : options.topicName) !== null && _a !== void 0 ? _a : this._topicName;
599
+ if (!topicName) {
600
+ throw new Error("Topic name is required");
601
+ }
602
+ const eventSubscriptionName = (_b = options === null || options === void 0 ? void 0 : options.eventSubscriptionName) !== null && _b !== void 0 ? _b : this._eventSubscriptionName;
603
+ if (!eventSubscriptionName) {
604
+ throw new Error("Event Subscription name is required");
605
+ }
606
+ return this._client.releaseCloudEvents(topicName, eventSubscriptionName, lockTokens, Object.assign(Object.assign({}, options), { releaseDelayInSeconds: options.releaseDelay }));
543
607
  }
544
608
  /**
545
609
  * Reject batch of Cloud Events.
546
610
  *
547
611
  * @param lockTokens - Lock Tokens
548
- * @param topicName - Topic Name
549
- * @param eventSubscriptionName - Name of the Event Subscription
550
612
  * @param options - Options to reject
551
613
  *
552
614
  */
553
- rejectCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
554
- return this._client.rejectCloudEvents(topicName, eventSubscriptionName, { lockTokens }, options);
615
+ rejectEvents(lockTokens, options = { requestOptions: {} }) {
616
+ var _a, _b;
617
+ const topicName = (_a = options === null || options === void 0 ? void 0 : options.topicName) !== null && _a !== void 0 ? _a : this._topicName;
618
+ if (!topicName) {
619
+ throw new Error("Topic name is required");
620
+ }
621
+ const eventSubscriptionName = (_b = options === null || options === void 0 ? void 0 : options.eventSubscriptionName) !== null && _b !== void 0 ? _b : this._eventSubscriptionName;
622
+ if (!eventSubscriptionName) {
623
+ throw new Error("Event Subscription name is required");
624
+ }
625
+ return this._client.rejectCloudEvents(topicName, eventSubscriptionName, lockTokens, options);
555
626
  }
556
627
  /**
557
628
  * Renew lock for batch of Cloud Events.
558
629
  *
559
630
  * @param lockTokens - Lock Tokens
560
- * @param topicName - Topic Name
561
- * @param eventSubscriptionName - Name of the Event Subscription
562
631
  * @param options - Options to renew
563
632
  */
564
- renewCloudEventLocks(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
565
- return this._client.renewCloudEventLocks(topicName, eventSubscriptionName, { lockTokens }, options);
633
+ renewEventLocks(lockTokens, options = { requestOptions: {} }) {
634
+ var _a, _b;
635
+ const topicName = (_a = options === null || options === void 0 ? void 0 : options.topicName) !== null && _a !== void 0 ? _a : this._topicName;
636
+ if (!topicName) {
637
+ throw new Error("Topic name is required");
638
+ }
639
+ const eventSubscriptionName = (_b = options === null || options === void 0 ? void 0 : options.eventSubscriptionName) !== null && _b !== void 0 ? _b : this._eventSubscriptionName;
640
+ if (!eventSubscriptionName) {
641
+ throw new Error("Event Subscription name is required");
642
+ }
643
+ return this._client.renewCloudEventLocks(topicName, eventSubscriptionName, lockTokens, options);
566
644
  }
567
645
  }
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
- }
646
+
647
+ // Copyright (c) Microsoft Corporation.
648
+ // Licensed under the MIT license.
649
+ /**
650
+ * Stringifies a Date object in the format expected by the Event Grid service, for use in a Shared Access Signiture.
651
+ *
652
+ * The service expects this time string to be in the same format as what is returned by the .NET DateTime.ToString
653
+ * method, using the "en-US" culture.
654
+ *
655
+ * 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"
656
+ * is represented as the string "6/5/2020 12:09:03 PM"
657
+ *
658
+ * The service expects a UTC time, so this method returns a string based on the UTC time of the provided Date.
659
+ *
660
+ * @param d - The Date object to convert to a string.
661
+ */
662
+ function parseAndWrap(jsonStringOrObject) {
663
+ if (typeof jsonStringOrObject === "string") {
664
+ const o = JSON.parse(jsonStringOrObject);
665
+ if (Array.isArray(o)) {
666
+ return o;
578
667
  }
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");
668
+ else {
669
+ return [o];
584
670
  }
585
- converted.datacontenttype = event.datacontenttype;
586
- converted.dataBase64 = event.data;
671
+ }
672
+ if (Array.isArray(jsonStringOrObject)) {
673
+ return jsonStringOrObject;
587
674
  }
588
675
  else {
589
- converted.datacontenttype =
590
- (_e = event.datacontenttype) !== null && _e !== void 0 ? _e : "application/cloudevents+json; charset=utf-8";
591
- converted.data = event.data;
676
+ return [jsonStringOrObject];
677
+ }
678
+ }
679
+ const CLOUD_EVENT_1_0_SPEC_VERSION = "1.0";
680
+ function validateCloudEventEvent(o) {
681
+ validateRequiredStringProperties(o, ["type", "source", "id", "specVersion"]);
682
+ validateOptionalStringProperties(o, ["time", "dataSchema", "dataContentType", "subject"]);
683
+ if (typeof o !== "object") {
684
+ throw new TypeError("event is not an object");
685
+ }
686
+ const castO = o;
687
+ if (castO.specVersion !== CLOUD_EVENT_1_0_SPEC_VERSION) {
688
+ throw new Error("event is not in the Cloud Event 1.0 schema");
689
+ }
690
+ }
691
+ function validateRequiredStringProperties(o, propertyNames) {
692
+ for (const propertyName of propertyNames) {
693
+ if (typeof o[propertyName] === "undefined") {
694
+ throw new Error(`event is missing required property '${propertyName}'`);
695
+ }
696
+ if (typeof o[propertyName] !== "string") {
697
+ throw new TypeError(`event property '${propertyName} should be a 'string', but is '${typeof o[propertyName]}'`);
698
+ }
699
+ }
700
+ }
701
+ function validateOptionalStringProperties(o, propertyNames) {
702
+ for (const propertyName of propertyNames) {
703
+ if (typeof o[propertyName] !== "undefined" && typeof o[propertyName] !== "string") {
704
+ throw new TypeError(`event property '${propertyName}' should be a 'string' but it is a '${typeof o[propertyName]}'`);
705
+ }
706
+ }
707
+ }
708
+ const CloudEvent = {
709
+ type: {
710
+ name: "Composite",
711
+ className: "CloudEvent",
712
+ additionalProperties: { type: { name: "Object" } },
713
+ modelProperties: {
714
+ id: {
715
+ serializedName: "id",
716
+ required: true,
717
+ type: {
718
+ name: "String",
719
+ },
720
+ },
721
+ source: {
722
+ serializedName: "source",
723
+ required: true,
724
+ type: {
725
+ name: "String",
726
+ },
727
+ },
728
+ data: {
729
+ serializedName: "data",
730
+ type: {
731
+ name: "any",
732
+ },
733
+ },
734
+ dataBase64: {
735
+ serializedName: "data_base64",
736
+ type: {
737
+ name: "ByteArray",
738
+ },
739
+ },
740
+ type: {
741
+ serializedName: "type",
742
+ required: true,
743
+ type: {
744
+ name: "String",
745
+ },
746
+ },
747
+ time: {
748
+ serializedName: "time",
749
+ type: {
750
+ name: "DateTime",
751
+ },
752
+ },
753
+ specversion: {
754
+ serializedName: "specversion",
755
+ required: true,
756
+ type: {
757
+ name: "String",
758
+ },
759
+ },
760
+ dataschema: {
761
+ serializedName: "dataschema",
762
+ type: {
763
+ name: "String",
764
+ },
765
+ },
766
+ datacontenttype: {
767
+ serializedName: "datacontenttype",
768
+ type: {
769
+ name: "String",
770
+ },
771
+ },
772
+ subject: {
773
+ serializedName: "subject",
774
+ type: {
775
+ name: "String",
776
+ },
777
+ },
778
+ },
779
+ },
780
+ };
781
+
782
+ // Copyright (c) Microsoft Corporation.
783
+ // Licensed under the MIT license.
784
+ const serializer = coreClient$1.createSerializer();
785
+ /**
786
+ * EventGridDeserializer is used to aid in processing events delivered by EventGrid. It can deserialize a JSON encoded payload
787
+ * of either a single event or batch of events as well as be used to convert the result of `JSON.parse` into an
788
+ * `EventGridEvent` or `CloudEvent` like object.
789
+ *
790
+ * Unlike normal JSON deseralization, EventGridDeserializer does some additional conversions:
791
+ *
792
+ * - The consumer parses the event time property into a `Date` object, for ease of use.
793
+ * - When deserializing an event in the CloudEvent schema, if the event contains binary data, it is base64 decoded
794
+ * and returned as an instance of the `Uint8Array` type.
795
+ */
796
+ class EventGridDeserializer {
797
+ async deserializeCloudEvents(encodedEvents) {
798
+ const decodedArray = parseAndWrap(encodedEvents);
799
+ const events = [];
800
+ for (const o of decodedArray) {
801
+ validateCloudEventEvent(o);
802
+ // Check that the required fields are present and of the correct type and the optional fields are missing
803
+ // or of the correct type.
804
+ const deserialized = serializer.deserialize(CloudEvent, o, "");
805
+ const modelEvent = {
806
+ specversion: deserialized.specversion,
807
+ id: deserialized.id,
808
+ source: deserialized.source,
809
+ type: deserialized.type,
810
+ };
811
+ if (deserialized.datacontenttype !== undefined) {
812
+ modelEvent.datacontenttype = deserialized.datacontenttype;
813
+ }
814
+ if (deserialized.dataschema !== undefined) {
815
+ modelEvent.dataschema = deserialized.dataschema;
816
+ }
817
+ if (deserialized.subject !== undefined) {
818
+ modelEvent.subject = deserialized.subject;
819
+ }
820
+ if (deserialized.time !== undefined) {
821
+ modelEvent.time = deserialized.time;
822
+ }
823
+ if (deserialized.data !== undefined) {
824
+ modelEvent.data = deserialized.data;
825
+ }
826
+ // 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.
827
+ if (deserialized.dataBase64 !== undefined) {
828
+ if (deserialized.data !== undefined) {
829
+ throw new TypeError("event contains both a data and data_base64 field");
830
+ }
831
+ if (!(deserialized.dataBase64 instanceof Uint8Array)) {
832
+ throw new TypeError("event data_base64 property is not an instance of Uint8Array");
833
+ }
834
+ modelEvent.data = deserialized.dataBase64;
835
+ }
836
+ // Build the "extensionsAttributes" property bag by removing all known top level properties.
837
+ const extensionAttributes = Object.assign({}, deserialized);
838
+ for (const propName of cloudEventReservedPropertyNames) {
839
+ delete extensionAttributes[propName];
840
+ }
841
+ delete extensionAttributes.dataBase64;
842
+ // If any properties remain, copy them to the model.
843
+ if (Object.keys(extensionAttributes).length > 0) {
844
+ modelEvent.extensionAttributes = extensionAttributes;
845
+ }
846
+ events.push(modelEvent);
847
+ }
848
+ return events;
592
849
  }
593
- return converted;
594
850
  }
595
851
 
596
852
  Object.defineProperty(exports, "AzureKeyCredential", {
597
853
  enumerable: true,
598
854
  get: function () { return coreAuth.AzureKeyCredential; }
599
855
  });
600
- Object.defineProperty(exports, "EventGridDeserializer", {
601
- enumerable: true,
602
- get: function () { return eventgrid.EventGridDeserializer; }
603
- });
604
- exports.EventGridClient = EventGridNamespacesClient;
856
+ exports.EventGridDeserializer = EventGridDeserializer;
857
+ exports.EventGridReceiverClient = EventGridReceiverClient;
858
+ exports.EventGridSenderClient = EventGridSenderClient;
605
859
  //# sourceMappingURL=index.js.map