@azure/eventgrid-namespaces 1.0.0-alpha.20240605.3 → 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.
- package/dist/index.js +454 -200
- package/dist/index.js.map +1 -1
- package/dist-esm/src/cadl-generated/EventGridClient.js +20 -28
- package/dist-esm/src/cadl-generated/EventGridClient.js.map +1 -1
- package/dist-esm/src/cadl-generated/api/EventGridContext.js +2 -2
- package/dist-esm/src/cadl-generated/api/EventGridContext.js.map +1 -1
- package/dist-esm/src/cadl-generated/api/operations.js +25 -29
- package/dist-esm/src/cadl-generated/api/operations.js.map +1 -1
- package/dist-esm/src/cadl-generated/index.js.map +1 -1
- package/dist-esm/src/cadl-generated/models/index.js.map +1 -1
- package/dist-esm/src/cadl-generated/models/models.js.map +1 -1
- package/dist-esm/src/cadl-generated/models/options.js.map +1 -1
- package/dist-esm/src/cadl-generated/rest/clientDefinitions.js.map +1 -1
- package/dist-esm/src/cadl-generated/rest/eventGridClient.js +9 -9
- package/dist-esm/src/cadl-generated/rest/eventGridClient.js.map +1 -1
- package/dist-esm/src/cadl-generated/rest/isUnexpected.js.map +1 -1
- package/dist-esm/src/cadl-generated/rest/models.js.map +1 -1
- package/dist-esm/src/cadl-generated/rest/parameters.js.map +1 -1
- package/dist-esm/src/cloudEventDistrubtedTracingEnricherPolicy.js +53 -0
- package/dist-esm/src/cloudEventDistrubtedTracingEnricherPolicy.js.map +1 -0
- package/dist-esm/src/consumer.js +73 -0
- package/dist-esm/src/consumer.js.map +1 -0
- package/dist-esm/src/eventGridNamespacesPublishBinaryMode.js.map +1 -1
- package/dist-esm/src/eventGridReceiverClient.js +144 -0
- package/dist-esm/src/eventGridReceiverClient.js.map +1 -0
- package/dist-esm/src/eventGridSenderClient.js +78 -0
- package/dist-esm/src/eventGridSenderClient.js.map +1 -0
- package/dist-esm/src/index.js +3 -2
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/models.js +3 -3
- package/dist-esm/src/models.js.map +1 -1
- package/dist-esm/src/util.js +155 -0
- package/dist-esm/src/util.js.map +1 -0
- package/package.json +1 -1
- package/types/eventgrid-namespaces.d.ts +154 -99
- package/dist-esm/src/eventGridNamespacesClient.js +0 -147
- package/dist-esm/src/eventGridNamespacesClient.js.map +0 -1
@@ -1,11 +1,18 @@
|
|
1
1
|
import { AzureKeyCredential } from '@azure/core-auth';
|
2
2
|
import { ClientOptions } from '@azure-rest/core-client';
|
3
3
|
import { ErrorModel } from '@azure-rest/core-client';
|
4
|
-
import { EventGridDeserializer } from '@azure/eventgrid';
|
5
4
|
import { OperationOptions } from '@azure-rest/core-client';
|
6
5
|
import { TokenCredential } from '@azure/core-auth';
|
7
6
|
|
8
|
-
export declare interface
|
7
|
+
export declare interface AcknowledgeEventsOptionalParams extends OperationOptions {
|
8
|
+
}
|
9
|
+
|
10
|
+
/** Acknowledge Events Options */
|
11
|
+
export declare interface AcknowledgeEventsOptions extends AcknowledgeEventsOptionalParams {
|
12
|
+
/** Topic name */
|
13
|
+
topicName?: string;
|
14
|
+
/** Event Subscription name */
|
15
|
+
eventSubscriptionName?: string;
|
9
16
|
}
|
10
17
|
|
11
18
|
/** The result of the Acknowledge operation. */
|
@@ -49,11 +56,11 @@ export declare interface CloudEvent<T> {
|
|
49
56
|
/**
|
50
57
|
* Identifies the schema that data adheres to.
|
51
58
|
*/
|
52
|
-
|
59
|
+
dataSchema?: string;
|
53
60
|
/**
|
54
61
|
* Content type of data value.
|
55
62
|
*/
|
56
|
-
|
63
|
+
dataContentType?: string;
|
57
64
|
/**
|
58
65
|
* Event data specific to the event type.
|
59
66
|
*/
|
@@ -69,75 +76,57 @@ export declare interface CloudEvent<T> {
|
|
69
76
|
/**
|
70
77
|
* The version of the CloudEvents specification which the event uses.
|
71
78
|
*/
|
72
|
-
|
79
|
+
specVersion?: string | "1.0";
|
73
80
|
}
|
74
81
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
id: string;
|
79
|
-
/** Identifies the context in which an event happened. The combination of id and source must be unique for each distinct event. */
|
80
|
-
source: string;
|
81
|
-
/** Event data specific to the event type. */
|
82
|
-
data?: unknown;
|
83
|
-
/** Event data specific to the event type, encoded as a base64 string. */
|
84
|
-
dataBase64?: Uint8Array;
|
85
|
-
/** Type of event related to the originating occurrence. */
|
86
|
-
type: string;
|
87
|
-
/** The time (in UTC) the event was generated, in RFC3339 format. */
|
88
|
-
time?: Date;
|
89
|
-
/** The version of the CloudEvents specification which the event uses. */
|
90
|
-
specversion: string;
|
91
|
-
/** Identifies the schema that data adheres to. */
|
92
|
-
dataschema?: string;
|
93
|
-
/** Content type of data value. */
|
94
|
-
datacontenttype?: string;
|
95
|
-
/** This describes the subject of the event in the context of the event producer (identified by source). */
|
96
|
-
subject?: string;
|
82
|
+
export declare interface EventGridClientOptions extends ClientOptions {
|
83
|
+
/** The API version to use for this operation. */
|
84
|
+
apiVersion?: string;
|
97
85
|
}
|
98
86
|
|
99
87
|
/**
|
100
|
-
*
|
88
|
+
* EventGridDeserializer is used to aid in processing events delivered by EventGrid. It can deserialize a JSON encoded payload
|
89
|
+
* of either a single event or batch of events as well as be used to convert the result of `JSON.parse` into an
|
90
|
+
* `EventGridEvent` or `CloudEvent` like object.
|
91
|
+
*
|
92
|
+
* Unlike normal JSON deseralization, EventGridDeserializer does some additional conversions:
|
93
|
+
*
|
94
|
+
* - The consumer parses the event time property into a `Date` object, for ease of use.
|
95
|
+
* - When deserializing an event in the CloudEvent schema, if the event contains binary data, it is base64 decoded
|
96
|
+
* and returned as an instance of the `Uint8Array` type.
|
101
97
|
*/
|
102
|
-
export declare class
|
103
|
-
private _client;
|
104
|
-
/** Azure Messaging EventGrid Client */
|
105
|
-
constructor(endpoint: string, credential: AzureKeyCredential | TokenCredential, options?: EventGridClientOptions);
|
98
|
+
export declare class EventGridDeserializer {
|
106
99
|
/**
|
107
|
-
*
|
108
|
-
* status code with an empty JSON object in response. Otherwise, the server can return various error codes.
|
109
|
-
* For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
|
110
|
-
* is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
|
111
|
-
* internal server error.
|
112
|
-
*
|
113
|
-
* @param event - Event to publish
|
114
|
-
* @param topicName - Topic to publish the event
|
115
|
-
* @param options - Options to publish
|
100
|
+
* Deserializes events encoded in the Cloud Events 1.0 schema.
|
116
101
|
*
|
102
|
+
* @param encodedEvents - the JSON encoded representation of either a single event or an array of
|
103
|
+
* events, encoded in the Cloud Events 1.0 Schema.
|
117
104
|
*/
|
118
|
-
|
105
|
+
deserializeCloudEvents(encodedEvents: string): Promise<CloudEvent<unknown>[]>;
|
119
106
|
/**
|
120
|
-
*
|
121
|
-
* status code with an empty JSON object in response. Otherwise, the server can return various error codes.
|
122
|
-
* For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
|
123
|
-
* is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
|
124
|
-
* internal server error.
|
125
|
-
*
|
126
|
-
* @param events - Events to publish
|
127
|
-
* @param topicName - Topic to publish the event
|
128
|
-
* @param options - Options to publish
|
107
|
+
* Deserializes events encoded in the Cloud Events 1.0 schema.
|
129
108
|
*
|
109
|
+
* @param encodedEvents - an object representing a single event, encoded in the Cloud Events 1.0 schema.
|
130
110
|
*/
|
131
|
-
|
111
|
+
deserializeCloudEvents(encodedEvents: Record<string, unknown>): Promise<CloudEvent<unknown>[]>;
|
112
|
+
}
|
113
|
+
|
114
|
+
/**
|
115
|
+
* Event Grid Namespaces Client
|
116
|
+
*/
|
117
|
+
export declare class EventGridReceiverClient {
|
118
|
+
private _client;
|
119
|
+
private _topicName;
|
120
|
+
private _eventSubscriptionName;
|
121
|
+
/** Azure Messaging EventGrid Client */
|
122
|
+
constructor(endpoint: string, credential: AzureKeyCredential | TokenCredential, options?: EventGridReceiverClientOptions);
|
132
123
|
/**
|
133
124
|
* Receive Batch of Cloud Events from the Event Subscription.
|
134
125
|
*
|
135
|
-
* @param topicName - Topic to receive
|
136
|
-
* @param eventSubscriptionName - Name of the Event Subscription
|
137
126
|
* @param options - Options to receive
|
138
127
|
*
|
139
128
|
*/
|
140
|
-
|
129
|
+
receiveEvents<T>(options?: ReceiveEventsOptions): Promise<ReceiveResult<T>>;
|
141
130
|
/**
|
142
131
|
* Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if at least one
|
143
132
|
* event is successfully acknowledged. The response body will include the set of successfully acknowledged
|
@@ -145,49 +134,72 @@ export declare class EventGridClient {
|
|
145
134
|
* acknowledged events will no longer be available to any consumer.
|
146
135
|
*
|
147
136
|
* @param lockTokens - Lock Tokens
|
148
|
-
* @param topicName - Topic Name
|
149
|
-
* @param eventSubscriptionName - Name of the Event Subscription
|
150
137
|
* @param options - Options to Acknowledge
|
151
138
|
*
|
152
139
|
*/
|
153
|
-
|
140
|
+
acknowledgeEvents(lockTokens: string[], options?: AcknowledgeEventsOptions): Promise<AcknowledgeResult>;
|
154
141
|
/**
|
155
142
|
* Release batch of Cloud Events. The server responds with an HTTP 200 status code if at least one event is
|
156
143
|
* successfully released. The response body will include the set of successfully released lockTokens, along
|
157
144
|
* with other failed lockTokens with their corresponding error information.
|
158
145
|
*
|
159
146
|
* @param lockTokens - Lock Tokens
|
160
|
-
* @param topicName - Topic Name
|
161
|
-
* @param eventSubscriptionName - Name of the Event Subscription
|
162
147
|
* @param options - Options to release
|
163
148
|
*
|
164
149
|
*/
|
165
|
-
|
150
|
+
releaseEvents(lockTokens: string[], options?: ReleaseEventsOptions): Promise<ReleaseResult>;
|
166
151
|
/**
|
167
152
|
* Reject batch of Cloud Events.
|
168
153
|
*
|
169
154
|
* @param lockTokens - Lock Tokens
|
170
|
-
* @param topicName - Topic Name
|
171
|
-
* @param eventSubscriptionName - Name of the Event Subscription
|
172
155
|
* @param options - Options to reject
|
173
156
|
*
|
174
157
|
*/
|
175
|
-
|
158
|
+
rejectEvents(lockTokens: string[], options?: RejectEventsOptions): Promise<RejectResult>;
|
176
159
|
/**
|
177
160
|
* Renew lock for batch of Cloud Events.
|
178
161
|
*
|
179
162
|
* @param lockTokens - Lock Tokens
|
180
|
-
* @param topicName - Topic Name
|
181
|
-
* @param eventSubscriptionName - Name of the Event Subscription
|
182
163
|
* @param options - Options to renew
|
183
164
|
*/
|
184
|
-
|
165
|
+
renewEventLocks(lockTokens: string[], options?: RenewEventLocksOptions): Promise<RenewLocksResult>;
|
185
166
|
}
|
186
167
|
|
187
|
-
|
168
|
+
/** Event Grid Receiver Client Options */
|
169
|
+
export declare interface EventGridReceiverClientOptions extends EventGridClientOptions {
|
170
|
+
/** Topic name */
|
171
|
+
topicName?: string;
|
172
|
+
/** Event Subscription name */
|
173
|
+
eventSubscriptionName?: string;
|
174
|
+
}
|
175
|
+
|
176
|
+
/**
|
177
|
+
* Event Grid Namespaces Client
|
178
|
+
*/
|
179
|
+
export declare class EventGridSenderClient {
|
180
|
+
private _client;
|
181
|
+
private _topicName;
|
182
|
+
/** Azure Messaging EventGrid Client */
|
183
|
+
constructor(endpoint: string, credential: AzureKeyCredential | TokenCredential, options?: EventGridSenderClientOptions);
|
184
|
+
/**
|
185
|
+
* Publish Cloud Events to namespace topic. In case of success, the server responds with an HTTP 200
|
186
|
+
* status code with an empty JSON object in response. Otherwise, the server can return various error codes.
|
187
|
+
* For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
|
188
|
+
* is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
|
189
|
+
* internal server error.
|
190
|
+
*
|
191
|
+
* @param events - Events to publish
|
192
|
+
* @param options - Options to publish
|
193
|
+
*
|
194
|
+
*/
|
195
|
+
sendEvents<T>(events: CloudEvent<T>[] | CloudEvent<T>, options?: SendEventsOptions): Promise<void>;
|
188
196
|
}
|
189
197
|
|
190
|
-
|
198
|
+
/** Event Grid Sender Client Options */
|
199
|
+
export declare interface EventGridSenderClientOptions extends EventGridClientOptions {
|
200
|
+
/** Topic name */
|
201
|
+
topicName?: string;
|
202
|
+
}
|
191
203
|
|
192
204
|
/** Failed LockToken information. */
|
193
205
|
export declare interface FailedLockToken {
|
@@ -197,46 +209,60 @@ export declare interface FailedLockToken {
|
|
197
209
|
error: ErrorModel;
|
198
210
|
}
|
199
211
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
212
|
+
/** Known values of {@link ReleaseDelay} that the service accepts. */
|
213
|
+
export declare const enum KnownReleaseDelay {
|
214
|
+
/** Ten Minutes */
|
215
|
+
TenMinutes = "600",
|
216
|
+
/** One Minute */
|
217
|
+
OneMinute = "60",
|
218
|
+
/** Ten Seconds */
|
219
|
+
TenSeconds = "10",
|
220
|
+
/** One Hour */
|
221
|
+
OneHour = "3600",
|
222
|
+
/** No Delay */
|
223
|
+
NoDelay = "0"
|
207
224
|
}
|
208
225
|
|
209
|
-
export
|
210
|
-
/** content type */
|
211
|
-
contentType?: string;
|
212
|
-
}
|
226
|
+
export { OperationOptions }
|
213
227
|
|
214
|
-
/**
|
215
|
-
export declare interface
|
228
|
+
/** Receive operation details per Cloud Event. */
|
229
|
+
export declare interface ReceiveDetails<T> {
|
230
|
+
/** The Event Broker details. */
|
231
|
+
brokerProperties: BrokerProperties;
|
232
|
+
/** Cloud Event details. */
|
233
|
+
event: CloudEvent<T>;
|
216
234
|
}
|
217
235
|
|
218
|
-
export declare interface
|
236
|
+
export declare interface ReceiveEventsOptionalParams extends OperationOptions {
|
219
237
|
/** Max Events count to be received. Minimum value is 1, while maximum value is 100 events. If not specified, the default value is 1. */
|
220
238
|
maxEvents?: number;
|
221
239
|
/** Max wait time value for receive operation in Seconds. It is the time in seconds that the server approximately waits for the availability of an event and responds to the request. If an event is available, the broker responds immediately to the client. Minimum value is 10 seconds, while maximum value is 120 seconds. If not specified, the default value is 60 seconds. */
|
222
240
|
maxWaitTime?: number;
|
223
241
|
}
|
224
242
|
|
225
|
-
/** Receive
|
226
|
-
export declare interface
|
227
|
-
/**
|
228
|
-
|
229
|
-
/**
|
230
|
-
|
243
|
+
/** Receive Events Options */
|
244
|
+
export declare interface ReceiveEventsOptions extends ReceiveEventsOptionalParams {
|
245
|
+
/** Topic name */
|
246
|
+
topicName?: string;
|
247
|
+
/** Event Subscription name */
|
248
|
+
eventSubscriptionName?: string;
|
231
249
|
}
|
232
250
|
|
233
251
|
/** Details of the Receive operation response. */
|
234
|
-
export declare interface ReceiveResult {
|
252
|
+
export declare interface ReceiveResult<T> {
|
235
253
|
/** Array of receive responses, one per cloud event. */
|
236
|
-
|
254
|
+
details: ReceiveDetails<T>[];
|
237
255
|
}
|
238
256
|
|
239
|
-
export declare interface
|
257
|
+
export declare interface RejectEventsOptionalParams extends OperationOptions {
|
258
|
+
}
|
259
|
+
|
260
|
+
/** Reject Events Options */
|
261
|
+
export declare interface RejectEventsOptions extends RejectEventsOptionalParams {
|
262
|
+
/** Topic name */
|
263
|
+
topicName?: string;
|
264
|
+
/** Event Subscription name */
|
265
|
+
eventSubscriptionName?: string;
|
240
266
|
}
|
241
267
|
|
242
268
|
/** The result of the Reject operation. */
|
@@ -247,15 +273,20 @@ export declare interface RejectResult {
|
|
247
273
|
succeededLockTokens: string[];
|
248
274
|
}
|
249
275
|
|
250
|
-
export declare interface ReleaseCloudEventsOptions extends OperationOptions {
|
251
|
-
/** Release cloud events with the specified delay in seconds. */
|
252
|
-
releaseDelayInSeconds?: ReleaseDelay;
|
253
|
-
}
|
254
|
-
|
255
276
|
/** Supported delays for release operation. */
|
256
277
|
/** "0", "10", "60", "600", "3600" */
|
257
278
|
export declare type ReleaseDelay = string;
|
258
279
|
|
280
|
+
/** Release Events Options */
|
281
|
+
export declare interface ReleaseEventsOptions extends OperationOptions {
|
282
|
+
/** Topic name */
|
283
|
+
topicName?: string;
|
284
|
+
/** Event Subscription name */
|
285
|
+
eventSubscriptionName?: string;
|
286
|
+
/** Release events with the specified delay in seconds. */
|
287
|
+
releaseDelay?: ReleaseDelay;
|
288
|
+
}
|
289
|
+
|
259
290
|
/** The result of the Release operation. */
|
260
291
|
export declare interface ReleaseResult {
|
261
292
|
/** Array of FailedLockToken for failed cloud events. Each FailedLockToken includes the lock token along with the related error information (namely, the error code and description). */
|
@@ -264,15 +295,39 @@ export declare interface ReleaseResult {
|
|
264
295
|
succeededLockTokens: string[];
|
265
296
|
}
|
266
297
|
|
267
|
-
export declare interface
|
298
|
+
export declare interface RenewEventLocksOptionalParams extends OperationOptions {
|
299
|
+
}
|
300
|
+
|
301
|
+
/** Renew Event Locks Options */
|
302
|
+
export declare interface RenewEventLocksOptions extends RenewEventLocksOptionalParams {
|
303
|
+
/** Topic name */
|
304
|
+
topicName?: string;
|
305
|
+
/** Event Subscription name */
|
306
|
+
eventSubscriptionName?: string;
|
268
307
|
}
|
269
308
|
|
270
309
|
/** The result of the RenewLock operation. */
|
271
|
-
export declare interface
|
310
|
+
export declare interface RenewLocksResult {
|
272
311
|
/** Array of FailedLockToken for failed cloud events. Each FailedLockToken includes the lock token along with the related error information (namely, the error code and description). */
|
273
312
|
failedLockTokens: FailedLockToken[];
|
274
313
|
/** Array of lock tokens for the successfully renewed locks. */
|
275
314
|
succeededLockTokens: string[];
|
276
315
|
}
|
277
316
|
|
317
|
+
export declare interface SendEventOptionalParams extends OperationOptions {
|
318
|
+
/** content type */
|
319
|
+
contentType?: string;
|
320
|
+
}
|
321
|
+
|
322
|
+
export declare interface SendEventsOptionalParams extends OperationOptions {
|
323
|
+
/** content type */
|
324
|
+
contentType?: string;
|
325
|
+
}
|
326
|
+
|
327
|
+
/** Send Events Options */
|
328
|
+
export declare interface SendEventsOptions extends SendEventOptionalParams {
|
329
|
+
/** Topic name */
|
330
|
+
topicName?: string;
|
331
|
+
}
|
332
|
+
|
278
333
|
export { }
|
@@ -1,147 +0,0 @@
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
2
|
-
// Licensed under the MIT license.
|
3
|
-
import { randomUUID } from "@azure/core-util";
|
4
|
-
import { EventGridClient as EventGridClientGenerated } from "./cadl-generated/EventGridClient";
|
5
|
-
import { cloudEventReservedPropertyNames } from "./models";
|
6
|
-
import { publishCloudEventInBinaryMode } from "./eventGridNamespacesPublishBinaryMode";
|
7
|
-
/**
|
8
|
-
* Event Grid Namespaces Client
|
9
|
-
*/
|
10
|
-
export class EventGridNamespacesClient {
|
11
|
-
/** Azure Messaging EventGrid Client */
|
12
|
-
constructor(endpoint, credential, options = {}) {
|
13
|
-
// credential.update(`SharedAccessKey ${credential.key}`);
|
14
|
-
this._client = new EventGridClientGenerated(endpoint, credential, options);
|
15
|
-
}
|
16
|
-
/**
|
17
|
-
* Publish Single Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200
|
18
|
-
* status code with an empty JSON object in response. Otherwise, the server can return various error codes.
|
19
|
-
* For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
|
20
|
-
* is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
|
21
|
-
* internal server error.
|
22
|
-
*
|
23
|
-
* @param event - Event to publish
|
24
|
-
* @param topicName - Topic to publish the event
|
25
|
-
* @param options - Options to publish
|
26
|
-
*
|
27
|
-
*/
|
28
|
-
async publishCloudEvent(event, topicName, options = { requestOptions: {} }) {
|
29
|
-
const cloudEventWireModel = convertCloudEventToModelType(event);
|
30
|
-
if (!options.binaryMode) {
|
31
|
-
await this._client.publishCloudEvent(topicName, cloudEventWireModel, options);
|
32
|
-
}
|
33
|
-
else {
|
34
|
-
await publishCloudEventInBinaryMode(this._client.getClient(), topicName, cloudEventWireModel, Object.assign({ contentType: options.contentType }, options));
|
35
|
-
}
|
36
|
-
}
|
37
|
-
/**
|
38
|
-
* Publish Batch Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200
|
39
|
-
* status code with an empty JSON object in response. Otherwise, the server can return various error codes.
|
40
|
-
* For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
|
41
|
-
* is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
|
42
|
-
* internal server error.
|
43
|
-
*
|
44
|
-
* @param events - Events to publish
|
45
|
-
* @param topicName - Topic to publish the event
|
46
|
-
* @param options - Options to publish
|
47
|
-
*
|
48
|
-
*/
|
49
|
-
async publishCloudEvents(events, topicName, options = { requestOptions: {} }) {
|
50
|
-
const eventsWireModel = [];
|
51
|
-
for (const individualevent of events) {
|
52
|
-
eventsWireModel.push(convertCloudEventToModelType(individualevent));
|
53
|
-
}
|
54
|
-
await this._client.publishCloudEvents(topicName, eventsWireModel, options);
|
55
|
-
}
|
56
|
-
/**
|
57
|
-
* Receive Batch of Cloud Events from the Event Subscription.
|
58
|
-
*
|
59
|
-
* @param topicName - Topic to receive
|
60
|
-
* @param eventSubscriptionName - Name of the Event Subscription
|
61
|
-
* @param options - Options to receive
|
62
|
-
*
|
63
|
-
*/
|
64
|
-
receiveCloudEvents(topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
65
|
-
return this._client.receiveCloudEvents(topicName, eventSubscriptionName, options);
|
66
|
-
}
|
67
|
-
/**
|
68
|
-
* Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if at least one
|
69
|
-
* event is successfully acknowledged. The response body will include the set of successfully acknowledged
|
70
|
-
* lockTokens, along with other failed lockTokens with their corresponding error information. Successfully
|
71
|
-
* acknowledged events will no longer be available to any consumer.
|
72
|
-
*
|
73
|
-
* @param lockTokens - Lock Tokens
|
74
|
-
* @param topicName - Topic Name
|
75
|
-
* @param eventSubscriptionName - Name of the Event Subscription
|
76
|
-
* @param options - Options to Acknowledge
|
77
|
-
*
|
78
|
-
*/
|
79
|
-
acknowledgeCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
80
|
-
return this._client.acknowledgeCloudEvents(topicName, eventSubscriptionName, { lockTokens }, options);
|
81
|
-
}
|
82
|
-
/**
|
83
|
-
* Release batch of Cloud Events. The server responds with an HTTP 200 status code if at least one event is
|
84
|
-
* successfully released. The response body will include the set of successfully released lockTokens, along
|
85
|
-
* with other failed lockTokens with their corresponding error information.
|
86
|
-
*
|
87
|
-
* @param lockTokens - Lock Tokens
|
88
|
-
* @param topicName - Topic Name
|
89
|
-
* @param eventSubscriptionName - Name of the Event Subscription
|
90
|
-
* @param options - Options to release
|
91
|
-
*
|
92
|
-
*/
|
93
|
-
releaseCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
94
|
-
return this._client.releaseCloudEvents(topicName, eventSubscriptionName, { lockTokens }, options);
|
95
|
-
}
|
96
|
-
/**
|
97
|
-
* Reject batch of Cloud Events.
|
98
|
-
*
|
99
|
-
* @param lockTokens - Lock Tokens
|
100
|
-
* @param topicName - Topic Name
|
101
|
-
* @param eventSubscriptionName - Name of the Event Subscription
|
102
|
-
* @param options - Options to reject
|
103
|
-
*
|
104
|
-
*/
|
105
|
-
rejectCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
106
|
-
return this._client.rejectCloudEvents(topicName, eventSubscriptionName, { lockTokens }, options);
|
107
|
-
}
|
108
|
-
/**
|
109
|
-
* Renew lock for batch of Cloud Events.
|
110
|
-
*
|
111
|
-
* @param lockTokens - Lock Tokens
|
112
|
-
* @param topicName - Topic Name
|
113
|
-
* @param eventSubscriptionName - Name of the Event Subscription
|
114
|
-
* @param options - Options to renew
|
115
|
-
*/
|
116
|
-
renewCloudEventLocks(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
117
|
-
return this._client.renewCloudEventLocks(topicName, eventSubscriptionName, { lockTokens }, options);
|
118
|
-
}
|
119
|
-
}
|
120
|
-
export function convertCloudEventToModelType(event) {
|
121
|
-
var _a, _b, _c, _d, _e;
|
122
|
-
if (event.extensionAttributes) {
|
123
|
-
for (const propName in event.extensionAttributes) {
|
124
|
-
// 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"
|
125
|
-
// they also can not match an existing defined property name.
|
126
|
-
if (!/^[a-z0-9]*$/.test(propName) ||
|
127
|
-
cloudEventReservedPropertyNames.indexOf(propName) !== -1) {
|
128
|
-
throw new Error(`invalid extension attribute name: ${propName}`);
|
129
|
-
}
|
130
|
-
}
|
131
|
-
}
|
132
|
-
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 : 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 : []));
|
133
|
-
if (event.data instanceof Uint8Array) {
|
134
|
-
if (!event.datacontenttype) {
|
135
|
-
throw new Error("a data content type must be provided when sending an event with binary data");
|
136
|
-
}
|
137
|
-
converted.datacontenttype = event.datacontenttype;
|
138
|
-
converted.dataBase64 = event.data;
|
139
|
-
}
|
140
|
-
else {
|
141
|
-
converted.datacontenttype =
|
142
|
-
(_e = event.datacontenttype) !== null && _e !== void 0 ? _e : "application/cloudevents+json; charset=utf-8";
|
143
|
-
converted.data = event.data;
|
144
|
-
}
|
145
|
-
return converted;
|
146
|
-
}
|
147
|
-
//# sourceMappingURL=eventGridNamespacesClient.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"eventGridNamespacesClient.js","sourceRoot":"","sources":["../../src/eventGridNamespacesClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAiBlC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,eAAe,IAAI,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAE/F,OAAO,EAAwC,+BAA+B,EAAE,MAAM,UAAU,CAAC;AACjG,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AAEvF;;GAEG;AACH,MAAM,OAAO,yBAAyB;IAGpC,uCAAuC;IACvC,YACE,QAAgB,EAChB,UAAgD,EAChD,UAAkC,EAAE;QAEpC,0DAA0D;QAC1D,IAAI,CAAC,OAAO,GAAG,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AAQ,CAAC,KAAK,CAAC,CAAC,EACxD,CAAC;gBACD,MAAM,IAAI,KAAK,CAAC,qCAAqC,QAAQ,EAAE,CAAC,CAAC;YACnE,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,SAAS,mBACb,WAAW,EAAE,MAAA,KAAK,CAAC,WAAW,mCAAI,KAAK,EACvC,IAAI,EAAE,KAAK,CAAC,IAAI,EAChB,MAAM,EAAE,KAAK,CAAC,MAAM,EACpB,EAAE,EAAE,MAAA,KAAK,CAAC,EAAE,mCAAI,UAAU,EAAE,EAC5B,IAAI,EAAE,MAAA,KAAK,CAAC,IAAI,mCAAI,IAAI,IAAI,EAAE,EAC9B,OAAO,EAAE,KAAK,CAAC,OAAO,EACtB,UAAU,EAAE,KAAK,CAAC,UAAU,IACzB,CAAC,MAAA,KAAK,CAAC,mBAAmB,mCAAI,EAAE,CAAC,CACrC,CAAC;IAEF,IAAI,KAAK,CAAC,IAAI,YAAY,UAAU,EAAE,CAAC;QACrC,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CACb,6EAA6E,CAC9E,CAAC;QACJ,CAAC;QAED,SAAS,CAAC,eAAe,GAAG,KAAK,CAAC,eAAe,CAAC;QAClD,SAAS,CAAC,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC;IACpC,CAAC;SAAM,CAAC;QACN,SAAS,CAAC,eAAe;YACvB,MAAA,KAAK,CAAC,eAAe,mCAAI,6CAA6C,CAAC;QACzE,SAAS,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;IAC9B,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AzureKeyCredential, TokenCredential } from \"@azure/core-auth\";\nimport {\n ReceiveResult,\n AcknowledgeResult,\n ReleaseResult,\n RejectResult,\n PublishCloudEventsOptions,\n ReceiveCloudEventsOptions,\n AcknowledgeCloudEventsOptions,\n ReleaseCloudEventsOptions,\n RejectCloudEventsOptions,\n RenewCloudEventLocksOptions,\n RenewCloudEventLocksResult,\n CloudEvent as CloudEventWireModel,\n} from \"./cadl-generated/models\";\nimport { randomUUID } from \"@azure/core-util\";\nimport { EventGridClient as EventGridClientGenerated } from \"./cadl-generated/EventGridClient\";\nimport { EventGridClientOptions } from \"./cadl-generated/api\";\nimport { PublishCloudEventOptions, CloudEvent, cloudEventReservedPropertyNames } from \"./models\";\nimport { publishCloudEventInBinaryMode } from \"./eventGridNamespacesPublishBinaryMode\";\n\n/**\n * Event Grid Namespaces Client\n */\nexport class EventGridNamespacesClient {\n private _client: EventGridClientGenerated;\n\n /** Azure Messaging EventGrid Client */\n constructor(\n endpoint: string,\n credential: AzureKeyCredential | TokenCredential,\n options: EventGridClientOptions = {},\n ) {\n // credential.update(`SharedAccessKey ${credential.key}`);\n this._client = new EventGridClientGenerated(endpoint, credential, options);\n }\n\n /**\n * Publish Single Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200\n * status code with an empty JSON object in response. Otherwise, the server can return various error codes.\n * For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message\n * is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for\n * internal server error.\n *\n * @param event - Event to publish\n * @param topicName - Topic to publish the event\n * @param options - Options to publish\n *\n */\n async publishCloudEvent<T>(\n event: CloudEvent<T>,\n topicName: string,\n options: PublishCloudEventOptions = { requestOptions: {} },\n ): Promise<void> {\n const cloudEventWireModel: CloudEventWireModel = convertCloudEventToModelType(event);\n\n if (!options.binaryMode) {\n await this._client.publishCloudEvent(topicName, cloudEventWireModel, options);\n } else {\n await publishCloudEventInBinaryMode(\n this._client.getClient(),\n topicName,\n cloudEventWireModel,\n {\n contentType: options.contentType,\n ...options,\n },\n );\n }\n }\n\n /**\n * Publish Batch Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200\n * status code with an empty JSON object in response. Otherwise, the server can return various error codes.\n * For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message\n * is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for\n * internal server error.\n *\n * @param events - Events to publish\n * @param topicName - Topic to publish the event\n * @param options - Options to publish\n *\n */\n async publishCloudEvents<T>(\n events: CloudEvent<T>[],\n topicName: string,\n options: PublishCloudEventsOptions = { requestOptions: {} },\n ): Promise<void> {\n const eventsWireModel: Array<CloudEventWireModel> = [];\n for (const individualevent of events) {\n eventsWireModel.push(convertCloudEventToModelType(individualevent));\n }\n await this._client.publishCloudEvents(topicName, eventsWireModel, options);\n }\n\n /**\n * Receive Batch of Cloud Events from the Event Subscription.\n *\n * @param topicName - Topic to receive\n * @param eventSubscriptionName - Name of the Event Subscription\n * @param options - Options to receive\n *\n */\n receiveCloudEvents(\n topicName: string,\n eventSubscriptionName: string,\n options: ReceiveCloudEventsOptions = { requestOptions: {} },\n ): Promise<ReceiveResult> {\n return this._client.receiveCloudEvents(topicName, eventSubscriptionName, options);\n }\n\n /**\n * Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if at least one\n * event is successfully acknowledged. The response body will include the set of successfully acknowledged\n * lockTokens, along with other failed lockTokens with their corresponding error information. Successfully\n * acknowledged events will no longer be available to any consumer.\n *\n * @param lockTokens - Lock Tokens\n * @param topicName - Topic Name\n * @param eventSubscriptionName - Name of the Event Subscription\n * @param options - Options to Acknowledge\n *\n */\n acknowledgeCloudEvents(\n lockTokens: string[],\n topicName: string,\n eventSubscriptionName: string,\n options: AcknowledgeCloudEventsOptions = { requestOptions: {} },\n ): Promise<AcknowledgeResult> {\n return this._client.acknowledgeCloudEvents(\n topicName,\n eventSubscriptionName,\n { lockTokens },\n options,\n );\n }\n\n /**\n * Release batch of Cloud Events. The server responds with an HTTP 200 status code if at least one event is\n * successfully released. The response body will include the set of successfully released lockTokens, along\n * with other failed lockTokens with their corresponding error information.\n *\n * @param lockTokens - Lock Tokens\n * @param topicName - Topic Name\n * @param eventSubscriptionName - Name of the Event Subscription\n * @param options - Options to release\n *\n */\n releaseCloudEvents(\n lockTokens: string[],\n topicName: string,\n eventSubscriptionName: string,\n options: ReleaseCloudEventsOptions = { requestOptions: {} },\n ): Promise<ReleaseResult> {\n return this._client.releaseCloudEvents(\n topicName,\n eventSubscriptionName,\n { lockTokens },\n options,\n );\n }\n\n /**\n * Reject batch of Cloud Events.\n *\n * @param lockTokens - Lock Tokens\n * @param topicName - Topic Name\n * @param eventSubscriptionName - Name of the Event Subscription\n * @param options - Options to reject\n *\n */\n rejectCloudEvents(\n lockTokens: string[],\n topicName: string,\n eventSubscriptionName: string,\n options: RejectCloudEventsOptions = { requestOptions: {} },\n ): Promise<RejectResult> {\n return this._client.rejectCloudEvents(\n topicName,\n eventSubscriptionName,\n { lockTokens },\n options,\n );\n }\n\n /**\n * Renew lock for batch of Cloud Events.\n *\n * @param lockTokens - Lock Tokens\n * @param topicName - Topic Name\n * @param eventSubscriptionName - Name of the Event Subscription\n * @param options - Options to renew\n */\n renewCloudEventLocks(\n lockTokens: string[],\n topicName: string,\n eventSubscriptionName: string,\n options: RenewCloudEventLocksOptions = { requestOptions: {} },\n ): Promise<RenewCloudEventLocksResult> {\n return this._client.renewCloudEventLocks(\n topicName,\n eventSubscriptionName,\n { lockTokens },\n options,\n );\n }\n}\n\nexport function convertCloudEventToModelType<T>(event: CloudEvent<T>): CloudEventWireModel {\n if (event.extensionAttributes) {\n for (const propName in event.extensionAttributes) {\n // 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\"\n // they also can not match an existing defined property name.\n\n if (\n !/^[a-z0-9]*$/.test(propName) ||\n cloudEventReservedPropertyNames.indexOf(propName) !== -1\n ) {\n throw new Error(`invalid extension attribute name: ${propName}`);\n }\n }\n }\n\n const converted: CloudEventWireModel = {\n specversion: event.specversion ?? \"1.0\",\n type: event.type,\n source: event.source,\n id: event.id ?? randomUUID(),\n time: event.time ?? new Date(),\n subject: event.subject,\n dataschema: event.dataschema,\n ...(event.extensionAttributes ?? []),\n };\n\n if (event.data instanceof Uint8Array) {\n if (!event.datacontenttype) {\n throw new Error(\n \"a data content type must be provided when sending an event with binary data\",\n );\n }\n\n converted.datacontenttype = event.datacontenttype;\n converted.dataBase64 = event.data;\n } else {\n converted.datacontenttype =\n event.datacontenttype ?? \"application/cloudevents+json; charset=utf-8\";\n converted.data = event.data;\n }\n\n return converted;\n}\n"]}
|