@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.
- package/README.md +45 -19
- package/dist/index.js +403 -196
- 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 +98 -0
- package/dist-esm/src/eventGridReceiverClient.js.map +1 -0
- package/dist-esm/src/eventGridSenderClient.js +72 -0
- package/dist-esm/src/eventGridSenderClient.js.map +1 -0
- package/dist-esm/src/index.js +3 -1
- 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 +10 -10
- package/types/eventgrid-namespaces.d.ts +127 -97
- package/dist-esm/src/constants.js +0 -5
- package/dist-esm/src/constants.js.map +0 -1
- package/dist-esm/src/eventGridNamespacesClient.js +0 -147
- package/dist-esm/src/eventGridNamespacesClient.js.map +0 -1
@@ -4,7 +4,11 @@ import { ErrorModel } from '@azure-rest/core-client';
|
|
4
4
|
import { OperationOptions } from '@azure-rest/core-client';
|
5
5
|
import { TokenCredential } from '@azure/core-auth';
|
6
6
|
|
7
|
-
export declare interface
|
7
|
+
export declare interface AcknowledgeEventsOptionalParams extends OperationOptions {
|
8
|
+
}
|
9
|
+
|
10
|
+
/** Acknowledge Events Options */
|
11
|
+
export declare interface AcknowledgeEventsOptions extends AcknowledgeEventsOptionalParams {
|
8
12
|
}
|
9
13
|
|
10
14
|
/** The result of the Acknowledge operation. */
|
@@ -48,11 +52,11 @@ export declare interface CloudEvent<T> {
|
|
48
52
|
/**
|
49
53
|
* Identifies the schema that data adheres to.
|
50
54
|
*/
|
51
|
-
|
55
|
+
dataSchema?: string;
|
52
56
|
/**
|
53
57
|
* Content type of data value.
|
54
58
|
*/
|
55
|
-
|
59
|
+
dataContentType?: string;
|
56
60
|
/**
|
57
61
|
* Event data specific to the event type.
|
58
62
|
*/
|
@@ -68,75 +72,57 @@ export declare interface CloudEvent<T> {
|
|
68
72
|
/**
|
69
73
|
* The version of the CloudEvents specification which the event uses.
|
70
74
|
*/
|
71
|
-
|
75
|
+
specVersion?: string | "1.0";
|
72
76
|
}
|
73
77
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
id: string;
|
78
|
-
/** Identifies the context in which an event happened. The combination of id and source must be unique for each distinct event. */
|
79
|
-
source: string;
|
80
|
-
/** Event data specific to the event type. */
|
81
|
-
data?: unknown;
|
82
|
-
/** Event data specific to the event type, encoded as a base64 string. */
|
83
|
-
dataBase64?: Uint8Array;
|
84
|
-
/** Type of event related to the originating occurrence. */
|
85
|
-
type: string;
|
86
|
-
/** The time (in UTC) the event was generated, in RFC3339 format. */
|
87
|
-
time?: Date;
|
88
|
-
/** The version of the CloudEvents specification which the event uses. */
|
89
|
-
specversion: string;
|
90
|
-
/** Identifies the schema that data adheres to. */
|
91
|
-
dataschema?: string;
|
92
|
-
/** Content type of data value. */
|
93
|
-
datacontenttype?: string;
|
94
|
-
/** This describes the subject of the event in the context of the event producer (identified by source). */
|
95
|
-
subject?: string;
|
78
|
+
export declare interface EventGridClientOptions extends ClientOptions {
|
79
|
+
/** The API version to use for this operation. */
|
80
|
+
apiVersion?: string;
|
96
81
|
}
|
97
82
|
|
98
83
|
/**
|
99
|
-
*
|
84
|
+
* EventGridDeserializer is used to aid in processing events delivered by EventGrid. It can deserialize a JSON encoded payload
|
85
|
+
* of either a single event or batch of events as well as be used to convert the result of `JSON.parse` into an
|
86
|
+
* `EventGridEvent` or `CloudEvent` like object.
|
87
|
+
*
|
88
|
+
* Unlike normal JSON deseralization, EventGridDeserializer does some additional conversions:
|
89
|
+
*
|
90
|
+
* - The consumer parses the event time property into a `Date` object, for ease of use.
|
91
|
+
* - When deserializing an event in the CloudEvent schema, if the event contains binary data, it is base64 decoded
|
92
|
+
* and returned as an instance of the `Uint8Array` type.
|
100
93
|
*/
|
101
|
-
export declare class
|
102
|
-
private _client;
|
103
|
-
/** Azure Messaging EventGrid Client */
|
104
|
-
constructor(endpoint: string, credential: AzureKeyCredential | TokenCredential, options?: EventGridClientOptions);
|
94
|
+
export declare class EventGridDeserializer {
|
105
95
|
/**
|
106
|
-
*
|
107
|
-
* status code with an empty JSON object in response. Otherwise, the server can return various error codes.
|
108
|
-
* For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
|
109
|
-
* is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
|
110
|
-
* internal server error.
|
111
|
-
*
|
112
|
-
* @param event - Event to publish
|
113
|
-
* @param topicName - Topic to publish the event
|
114
|
-
* @param options - Options to publish
|
96
|
+
* Deserializes events encoded in the Cloud Events 1.0 schema.
|
115
97
|
*
|
98
|
+
* @param encodedEvents - the JSON encoded representation of either a single event or an array of
|
99
|
+
* events, encoded in the Cloud Events 1.0 Schema.
|
116
100
|
*/
|
117
|
-
|
101
|
+
deserializeCloudEvents(encodedEvents: string): Promise<CloudEvent<unknown>[]>;
|
118
102
|
/**
|
119
|
-
*
|
120
|
-
* status code with an empty JSON object in response. Otherwise, the server can return various error codes.
|
121
|
-
* For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
|
122
|
-
* is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
|
123
|
-
* internal server error.
|
124
|
-
*
|
125
|
-
* @param events - Events to publish
|
126
|
-
* @param topicName - Topic to publish the event
|
127
|
-
* @param options - Options to publish
|
103
|
+
* Deserializes events encoded in the Cloud Events 1.0 schema.
|
128
104
|
*
|
105
|
+
* @param encodedEvents - an object representing a single event, encoded in the Cloud Events 1.0 schema.
|
129
106
|
*/
|
130
|
-
|
107
|
+
deserializeCloudEvents(encodedEvents: Record<string, unknown>): Promise<CloudEvent<unknown>[]>;
|
108
|
+
}
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Event Grid Namespaces Client
|
112
|
+
*/
|
113
|
+
export declare class EventGridReceiverClient {
|
114
|
+
private _client;
|
115
|
+
private _topicName;
|
116
|
+
private _subscriptionName;
|
117
|
+
/** Azure Messaging EventGrid Client */
|
118
|
+
constructor(endpoint: string, credential: AzureKeyCredential | TokenCredential, topicName: string, subscriptionName: string, options?: EventGridReceiverClientOptions);
|
131
119
|
/**
|
132
120
|
* Receive Batch of Cloud Events from the Event Subscription.
|
133
121
|
*
|
134
|
-
* @param topicName - Topic to receive
|
135
|
-
* @param eventSubscriptionName - Name of the Event Subscription
|
136
122
|
* @param options - Options to receive
|
137
123
|
*
|
138
124
|
*/
|
139
|
-
|
125
|
+
receiveEvents<T>(options?: ReceiveEventsOptions): Promise<ReceiveResult<T>>;
|
140
126
|
/**
|
141
127
|
* Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if at least one
|
142
128
|
* event is successfully acknowledged. The response body will include the set of successfully acknowledged
|
@@ -144,46 +130,65 @@ export declare class EventGridClient {
|
|
144
130
|
* acknowledged events will no longer be available to any consumer.
|
145
131
|
*
|
146
132
|
* @param lockTokens - Lock Tokens
|
147
|
-
* @param topicName - Topic Name
|
148
|
-
* @param eventSubscriptionName - Name of the Event Subscription
|
149
133
|
* @param options - Options to Acknowledge
|
150
134
|
*
|
151
135
|
*/
|
152
|
-
|
136
|
+
acknowledgeEvents(lockTokens: string[], options?: AcknowledgeEventsOptions): Promise<AcknowledgeResult>;
|
153
137
|
/**
|
154
138
|
* Release batch of Cloud Events. The server responds with an HTTP 200 status code if at least one event is
|
155
139
|
* successfully released. The response body will include the set of successfully released lockTokens, along
|
156
140
|
* with other failed lockTokens with their corresponding error information.
|
157
141
|
*
|
158
142
|
* @param lockTokens - Lock Tokens
|
159
|
-
* @param topicName - Topic Name
|
160
|
-
* @param eventSubscriptionName - Name of the Event Subscription
|
161
143
|
* @param options - Options to release
|
162
144
|
*
|
163
145
|
*/
|
164
|
-
|
146
|
+
releaseEvents(lockTokens: string[], options?: ReleaseEventsOptions): Promise<ReleaseResult>;
|
165
147
|
/**
|
166
148
|
* Reject batch of Cloud Events.
|
167
149
|
*
|
168
150
|
* @param lockTokens - Lock Tokens
|
169
|
-
* @param topicName - Topic Name
|
170
|
-
* @param eventSubscriptionName - Name of the Event Subscription
|
171
151
|
* @param options - Options to reject
|
172
152
|
*
|
173
153
|
*/
|
174
|
-
|
154
|
+
rejectEvents(lockTokens: string[], options?: RejectEventsOptions): Promise<RejectResult>;
|
175
155
|
/**
|
176
156
|
* Renew lock for batch of Cloud Events.
|
177
157
|
*
|
178
158
|
* @param lockTokens - Lock Tokens
|
179
|
-
* @param topicName - Topic Name
|
180
|
-
* @param eventSubscriptionName - Name of the Event Subscription
|
181
159
|
* @param options - Options to renew
|
182
160
|
*/
|
183
|
-
|
161
|
+
renewEventLocks(lockTokens: string[], options?: RenewEventLocksOptions): Promise<RenewLocksResult>;
|
184
162
|
}
|
185
163
|
|
186
|
-
|
164
|
+
/** Event Grid Receiver Client Options */
|
165
|
+
export declare interface EventGridReceiverClientOptions extends EventGridClientOptions {
|
166
|
+
}
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Event Grid Namespaces Client
|
170
|
+
*/
|
171
|
+
export declare class EventGridSenderClient {
|
172
|
+
private _client;
|
173
|
+
private _topicName;
|
174
|
+
/** Azure Messaging EventGrid Client */
|
175
|
+
constructor(endpoint: string, credential: AzureKeyCredential | TokenCredential, topicName: string, options?: EventGridSenderClientOptions);
|
176
|
+
/**
|
177
|
+
* Publish Cloud Events to namespace topic. In case of success, the server responds with an HTTP 200
|
178
|
+
* status code with an empty JSON object in response. Otherwise, the server can return various error codes.
|
179
|
+
* For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
|
180
|
+
* is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
|
181
|
+
* internal server error.
|
182
|
+
*
|
183
|
+
* @param events - Events to publish
|
184
|
+
* @param options - Options to publish
|
185
|
+
*
|
186
|
+
*/
|
187
|
+
sendEvents<T>(events: CloudEvent<T>[] | CloudEvent<T>, options?: SendEventsOptions): Promise<void>;
|
188
|
+
}
|
189
|
+
|
190
|
+
/** Event Grid Sender Client Options */
|
191
|
+
export declare interface EventGridSenderClientOptions extends EventGridClientOptions {
|
187
192
|
}
|
188
193
|
|
189
194
|
/** Failed LockToken information. */
|
@@ -194,46 +199,52 @@ export declare interface FailedLockToken {
|
|
194
199
|
error: ErrorModel;
|
195
200
|
}
|
196
201
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
202
|
+
/** Known values of {@link ReleaseDelay} that the service accepts. */
|
203
|
+
export declare const enum KnownReleaseDelay {
|
204
|
+
/** Ten Minutes */
|
205
|
+
TenMinutes = "600",
|
206
|
+
/** One Minute */
|
207
|
+
OneMinute = "60",
|
208
|
+
/** Ten Seconds */
|
209
|
+
TenSeconds = "10",
|
210
|
+
/** One Hour */
|
211
|
+
OneHour = "3600",
|
212
|
+
/** No Delay */
|
213
|
+
NoDelay = "0"
|
204
214
|
}
|
205
215
|
|
206
|
-
export
|
207
|
-
/** content type */
|
208
|
-
contentType?: string;
|
209
|
-
}
|
216
|
+
export { OperationOptions }
|
210
217
|
|
211
|
-
/**
|
212
|
-
export declare interface
|
218
|
+
/** Receive operation details per Cloud Event. */
|
219
|
+
export declare interface ReceiveDetails<T> {
|
220
|
+
/** The Event Broker details. */
|
221
|
+
brokerProperties: BrokerProperties;
|
222
|
+
/** Cloud Event details. */
|
223
|
+
event: CloudEvent<T>;
|
213
224
|
}
|
214
225
|
|
215
|
-
export declare interface
|
226
|
+
export declare interface ReceiveEventsOptionalParams extends OperationOptions {
|
216
227
|
/** Max Events count to be received. Minimum value is 1, while maximum value is 100 events. If not specified, the default value is 1. */
|
217
228
|
maxEvents?: number;
|
218
229
|
/** 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. */
|
219
230
|
maxWaitTime?: number;
|
220
231
|
}
|
221
232
|
|
222
|
-
/** Receive
|
223
|
-
export declare interface
|
224
|
-
/** The Event Broker details. */
|
225
|
-
brokerProperties: BrokerProperties;
|
226
|
-
/** Cloud Event details. */
|
227
|
-
event: CloudEvent_2;
|
233
|
+
/** Receive Events Options */
|
234
|
+
export declare interface ReceiveEventsOptions extends ReceiveEventsOptionalParams {
|
228
235
|
}
|
229
236
|
|
230
237
|
/** Details of the Receive operation response. */
|
231
|
-
export declare interface ReceiveResult {
|
238
|
+
export declare interface ReceiveResult<T> {
|
232
239
|
/** Array of receive responses, one per cloud event. */
|
233
|
-
|
240
|
+
details: ReceiveDetails<T>[];
|
234
241
|
}
|
235
242
|
|
236
|
-
export declare interface
|
243
|
+
export declare interface RejectEventsOptionalParams extends OperationOptions {
|
244
|
+
}
|
245
|
+
|
246
|
+
/** Reject Events Options */
|
247
|
+
export declare interface RejectEventsOptions extends RejectEventsOptionalParams {
|
237
248
|
}
|
238
249
|
|
239
250
|
/** The result of the Reject operation. */
|
@@ -244,15 +255,16 @@ export declare interface RejectResult {
|
|
244
255
|
succeededLockTokens: string[];
|
245
256
|
}
|
246
257
|
|
247
|
-
export declare interface ReleaseCloudEventsOptions extends OperationOptions {
|
248
|
-
/** Release cloud events with the specified delay in seconds. */
|
249
|
-
releaseDelayInSeconds?: ReleaseDelay;
|
250
|
-
}
|
251
|
-
|
252
258
|
/** Supported delays for release operation. */
|
253
259
|
/** "0", "10", "60", "600", "3600" */
|
254
260
|
export declare type ReleaseDelay = string;
|
255
261
|
|
262
|
+
/** Release Events Options */
|
263
|
+
export declare interface ReleaseEventsOptions extends OperationOptions {
|
264
|
+
/** Release events with the specified delay in seconds. */
|
265
|
+
releaseDelay?: ReleaseDelay;
|
266
|
+
}
|
267
|
+
|
256
268
|
/** The result of the Release operation. */
|
257
269
|
export declare interface ReleaseResult {
|
258
270
|
/** 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). */
|
@@ -261,15 +273,33 @@ export declare interface ReleaseResult {
|
|
261
273
|
succeededLockTokens: string[];
|
262
274
|
}
|
263
275
|
|
264
|
-
export declare interface
|
276
|
+
export declare interface RenewEventLocksOptionalParams extends OperationOptions {
|
277
|
+
}
|
278
|
+
|
279
|
+
/** Renew Event Locks Options */
|
280
|
+
export declare interface RenewEventLocksOptions extends RenewEventLocksOptionalParams {
|
265
281
|
}
|
266
282
|
|
267
283
|
/** The result of the RenewLock operation. */
|
268
|
-
export declare interface
|
284
|
+
export declare interface RenewLocksResult {
|
269
285
|
/** 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). */
|
270
286
|
failedLockTokens: FailedLockToken[];
|
271
287
|
/** Array of lock tokens for the successfully renewed locks. */
|
272
288
|
succeededLockTokens: string[];
|
273
289
|
}
|
274
290
|
|
291
|
+
export declare interface SendEventOptionalParams extends OperationOptions {
|
292
|
+
/** content type */
|
293
|
+
contentType?: string;
|
294
|
+
}
|
295
|
+
|
296
|
+
export declare interface SendEventsOptionalParams extends OperationOptions {
|
297
|
+
/** content type */
|
298
|
+
contentType?: string;
|
299
|
+
}
|
300
|
+
|
301
|
+
/** Send Events Options */
|
302
|
+
export declare interface SendEventsOptions extends SendEventOptionalParams {
|
303
|
+
}
|
304
|
+
|
275
305
|
export { }
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,CAAC,MAAM,mBAAmB,GAAG,YAAY,CAAC;AAChD,MAAM,CAAC,MAAM,uBAAuB,GAAG,sCAAsC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport const DEFAULT_API_VERSION = \"2018-01-01\";\nexport const DEFAULT_EVENTGRID_SCOPE = \"https://eventgrid.azure.net/.default\";\n"]}
|
@@ -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,IAAI,wBAAwB,CAAC,QAAQ,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAC7E,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,iBAAiB,CACrB,KAAoB,EACpB,SAAiB,EACjB,UAAoC,EAAE,cAAc,EAAE,EAAE,EAAE;QAE1D,MAAM,mBAAmB,GAAwB,4BAA4B,CAAC,KAAK,CAAC,CAAC;QAErF,IAAI,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AK,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"]}
|