@azure/eventgrid-namespaces 1.0.0-alpha.20240412.4
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/LICENSE +21 -0
- package/README.md +181 -0
- package/dist/index.js +600 -0
- package/dist/index.js.map +1 -0
- package/dist-esm/src/cadl-generated/EventGridClient.js +50 -0
- package/dist-esm/src/cadl-generated/EventGridClient.js.map +1 -0
- package/dist-esm/src/cadl-generated/api/EventGridContext.js +9 -0
- package/dist-esm/src/cadl-generated/api/EventGridContext.js.map +1 -0
- package/dist-esm/src/cadl-generated/api/index.js +5 -0
- package/dist-esm/src/cadl-generated/api/index.js.map +1 -0
- package/dist-esm/src/cadl-generated/api/operations.js +197 -0
- package/dist-esm/src/cadl-generated/api/operations.js.map +1 -0
- package/dist-esm/src/cadl-generated/index.js +4 -0
- package/dist-esm/src/cadl-generated/index.js.map +1 -0
- package/dist-esm/src/cadl-generated/logger.js +5 -0
- package/dist-esm/src/cadl-generated/logger.js.map +1 -0
- package/dist-esm/src/cadl-generated/models/index.js +4 -0
- package/dist-esm/src/cadl-generated/models/index.js.map +1 -0
- package/dist-esm/src/cadl-generated/models/models.js +4 -0
- package/dist-esm/src/cadl-generated/models/models.js.map +1 -0
- package/dist-esm/src/cadl-generated/models/options.js +4 -0
- package/dist-esm/src/cadl-generated/models/options.js.map +1 -0
- package/dist-esm/src/cadl-generated/rest/clientDefinitions.js +4 -0
- package/dist-esm/src/cadl-generated/rest/clientDefinitions.js.map +1 -0
- package/dist-esm/src/cadl-generated/rest/eventGridClient.js +40 -0
- package/dist-esm/src/cadl-generated/rest/eventGridClient.js.map +1 -0
- package/dist-esm/src/cadl-generated/rest/index.js +12 -0
- package/dist-esm/src/cadl-generated/rest/index.js.map +1 -0
- package/dist-esm/src/cadl-generated/rest/isUnexpected.js +75 -0
- package/dist-esm/src/cadl-generated/rest/isUnexpected.js.map +1 -0
- package/dist-esm/src/cadl-generated/rest/models.js +4 -0
- package/dist-esm/src/cadl-generated/rest/models.js.map +1 -0
- package/dist-esm/src/cadl-generated/rest/outputModels.js +4 -0
- package/dist-esm/src/cadl-generated/rest/outputModels.js.map +1 -0
- package/dist-esm/src/cadl-generated/rest/parameters.js +4 -0
- package/dist-esm/src/cadl-generated/rest/parameters.js.map +1 -0
- package/dist-esm/src/cadl-generated/rest/responses.js +4 -0
- package/dist-esm/src/cadl-generated/rest/responses.js.map +1 -0
- package/dist-esm/src/constants.js +5 -0
- package/dist-esm/src/constants.js.map +1 -0
- package/dist-esm/src/eventGridNamespacesClient.js +147 -0
- package/dist-esm/src/eventGridNamespacesClient.js.map +1 -0
- package/dist-esm/src/eventGridNamespacesPublishBinaryMode.js +63 -0
- package/dist-esm/src/eventGridNamespacesPublishBinaryMode.js.map +1 -0
- package/dist-esm/src/index.js +5 -0
- package/dist-esm/src/index.js.map +1 -0
- package/dist-esm/src/models.js +14 -0
- package/dist-esm/src/models.js.map +1 -0
- package/package.json +120 -0
- package/types/eventgrid-namespaces.d.ts +275 -0
package/dist/index.js
ADDED
@@ -0,0 +1,600 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
4
|
+
|
5
|
+
var coreAuth = require('@azure/core-auth');
|
6
|
+
var coreUtil = require('@azure/core-util');
|
7
|
+
var coreClient = require('@azure-rest/core-client');
|
8
|
+
var logger$1 = require('@azure/logger');
|
9
|
+
var buffer = require('buffer');
|
10
|
+
|
11
|
+
// Copyright (c) Microsoft Corporation.
|
12
|
+
// Licensed under the MIT license.
|
13
|
+
const logger = logger$1.createClientLogger("eventgrid-namespaces");
|
14
|
+
|
15
|
+
// Copyright (c) Microsoft Corporation.
|
16
|
+
// Licensed under the MIT license.
|
17
|
+
/**
|
18
|
+
* Initialize a new instance of `EventGridContext`
|
19
|
+
* @param endpoint - The host name of the namespace, e.g. namespaceName1.westus-1.eventgrid.azure.net
|
20
|
+
* @param credentials - uniquely identify client credential
|
21
|
+
* @param options - the parameter for all optional parameters
|
22
|
+
*/
|
23
|
+
function createClient(endpoint, credentials, options = {}) {
|
24
|
+
var _a, _b, _c, _d, _e, _f;
|
25
|
+
const baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : `${endpoint}`;
|
26
|
+
options.apiVersion = (_b = options.apiVersion) !== null && _b !== void 0 ? _b : "2023-10-01-preview";
|
27
|
+
const userAgentInfo = `azsdk-js-eventgrid-namespaces-rest/1.0.0-beta.1`;
|
28
|
+
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
29
|
+
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
|
30
|
+
: `${userAgentInfo}`;
|
31
|
+
options = Object.assign(Object.assign({}, options), { userAgentOptions: {
|
32
|
+
userAgentPrefix,
|
33
|
+
}, loggingOptions: {
|
34
|
+
logger: (_d = (_c = options.loggingOptions) === null || _c === void 0 ? void 0 : _c.logger) !== null && _d !== void 0 ? _d : logger.info,
|
35
|
+
}, credentials: {
|
36
|
+
scopes: (_f = (_e = options.credentials) === null || _e === void 0 ? void 0 : _e.scopes) !== null && _f !== void 0 ? _f : ["https://eventgrid.azure.net/.default"],
|
37
|
+
apiKeyHeaderName: "Authorization",
|
38
|
+
} });
|
39
|
+
const client = coreClient.getClient(baseUrl, credentials, options);
|
40
|
+
if (coreAuth.isKeyCredential(credentials)) {
|
41
|
+
client.pipeline.addPolicy({
|
42
|
+
name: "customKeyCredentialPolicy",
|
43
|
+
async sendRequest(request, next) {
|
44
|
+
request.headers.set("Authorization", "SharedAccessKey " + credentials.key);
|
45
|
+
return next(request);
|
46
|
+
},
|
47
|
+
});
|
48
|
+
}
|
49
|
+
return client;
|
50
|
+
}
|
51
|
+
|
52
|
+
// Copyright (c) Microsoft Corporation.
|
53
|
+
// Licensed under the MIT license.
|
54
|
+
const responseMap = {
|
55
|
+
"POST /topics/{topicName}:publish": ["200"],
|
56
|
+
"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:receive": ["200"],
|
57
|
+
"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:acknowledge": ["200"],
|
58
|
+
"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:release": ["200"],
|
59
|
+
"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:reject": ["200"],
|
60
|
+
"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:renewLock": ["200"],
|
61
|
+
};
|
62
|
+
function isUnexpected(response) {
|
63
|
+
const lroOriginal = response.headers["x-ms-original-url"];
|
64
|
+
const url = new URL(lroOriginal !== null && lroOriginal !== void 0 ? lroOriginal : response.request.url);
|
65
|
+
const method = response.request.method;
|
66
|
+
let pathDetails = responseMap[`${method} ${url.pathname}`];
|
67
|
+
if (!pathDetails) {
|
68
|
+
pathDetails = getParametrizedPathSuccess(method, url.pathname);
|
69
|
+
}
|
70
|
+
return !pathDetails.includes(response.status);
|
71
|
+
}
|
72
|
+
function getParametrizedPathSuccess(method, path) {
|
73
|
+
var _a, _b, _c, _d;
|
74
|
+
const pathParts = path.split("/");
|
75
|
+
// Traverse list to match the longest candidate
|
76
|
+
// matchedLen: the length of candidate path
|
77
|
+
// matchedValue: the matched status code array
|
78
|
+
let matchedLen = -1, matchedValue = [];
|
79
|
+
// Iterate the responseMap to find a match
|
80
|
+
for (const [key, value] of Object.entries(responseMap)) {
|
81
|
+
// Extracting the path from the map key which is in format
|
82
|
+
// GET /path/foo
|
83
|
+
if (!key.startsWith(method)) {
|
84
|
+
continue;
|
85
|
+
}
|
86
|
+
const candidatePath = getPathFromMapKey(key);
|
87
|
+
// Get each part of the url path
|
88
|
+
const candidateParts = candidatePath.split("/");
|
89
|
+
// track if we have found a match to return the values found.
|
90
|
+
let found = true;
|
91
|
+
for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
|
92
|
+
if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) && ((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.indexOf("}")) !== -1) {
|
93
|
+
const start = candidateParts[i].indexOf("}") + 1, end = (_c = candidateParts[i]) === null || _c === void 0 ? void 0 : _c.length;
|
94
|
+
// If the current part of the candidate is a "template" part
|
95
|
+
// Try to use the suffix of pattern to match the path
|
96
|
+
// {guid} ==> $
|
97
|
+
// {guid}:export ==> :export$
|
98
|
+
const isMatched = new RegExp(`${(_d = candidateParts[i]) === null || _d === void 0 ? void 0 : _d.slice(start, end)}`).test(pathParts[j] || "");
|
99
|
+
if (!isMatched) {
|
100
|
+
found = false;
|
101
|
+
break;
|
102
|
+
}
|
103
|
+
continue;
|
104
|
+
}
|
105
|
+
// If the candidate part is not a template and
|
106
|
+
// the parts don't match mark the candidate as not found
|
107
|
+
// to move on with the next candidate path.
|
108
|
+
if (candidateParts[i] !== pathParts[j]) {
|
109
|
+
found = false;
|
110
|
+
break;
|
111
|
+
}
|
112
|
+
}
|
113
|
+
// We finished evaluating the current candidate parts
|
114
|
+
// Update the matched value if and only if we found the longer pattern
|
115
|
+
if (found && candidatePath.length > matchedLen) {
|
116
|
+
matchedLen = candidatePath.length;
|
117
|
+
matchedValue = value;
|
118
|
+
}
|
119
|
+
}
|
120
|
+
return matchedValue;
|
121
|
+
}
|
122
|
+
function getPathFromMapKey(mapKey) {
|
123
|
+
const pathStart = mapKey.indexOf("/");
|
124
|
+
return mapKey.slice(pathStart);
|
125
|
+
}
|
126
|
+
|
127
|
+
// Copyright (c) Microsoft Corporation.
|
128
|
+
// Licensed under the MIT license.
|
129
|
+
/** Azure Messaging EventGrid Client */
|
130
|
+
function createEventGrid(endpoint, credential, options = {}) {
|
131
|
+
const clientContext = createClient(endpoint, credential, options);
|
132
|
+
return clientContext;
|
133
|
+
}
|
134
|
+
|
135
|
+
// Copyright (c) Microsoft Corporation.
|
136
|
+
// Licensed under the MIT license.
|
137
|
+
function _publishCloudEventSend(context, topicName, event, options = { requestOptions: {} }) {
|
138
|
+
var _a, _b;
|
139
|
+
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", body: {
|
140
|
+
id: event["id"],
|
141
|
+
source: event["source"],
|
142
|
+
data: event["data"],
|
143
|
+
data_base64: event["dataBase64"] !== undefined
|
144
|
+
? coreUtil.uint8ArrayToString(event["dataBase64"], "base64")
|
145
|
+
: undefined,
|
146
|
+
type: event["type"],
|
147
|
+
time: (_b = event["time"]) === null || _b === void 0 ? void 0 : _b.toISOString(),
|
148
|
+
specversion: event["specversion"],
|
149
|
+
dataschema: event["dataschema"],
|
150
|
+
datacontenttype: event["datacontenttype"],
|
151
|
+
subject: event["subject"],
|
152
|
+
} }));
|
153
|
+
}
|
154
|
+
async function _publishCloudEventDeserialize$1(result) {
|
155
|
+
if (isUnexpected(result)) {
|
156
|
+
throw coreClient.createRestError(result);
|
157
|
+
}
|
158
|
+
return result.body;
|
159
|
+
}
|
160
|
+
/** Publish Single Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200 status code with an empty JSON object in response. Otherwise, the server can return various error codes. For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for internal server error. */
|
161
|
+
async function publishCloudEvent(context, topicName, event, options = { requestOptions: {} }) {
|
162
|
+
const result = await _publishCloudEventSend(context, topicName, event, options);
|
163
|
+
return _publishCloudEventDeserialize$1(result);
|
164
|
+
}
|
165
|
+
function _publishCloudEventsSend(context, topicName, events, options = { requestOptions: {} }) {
|
166
|
+
var _a;
|
167
|
+
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-batch+json; charset=utf-8", body: (events !== null && events !== void 0 ? events : []).map((p) => {
|
168
|
+
var _a;
|
169
|
+
return {
|
170
|
+
id: p["id"],
|
171
|
+
source: p["source"],
|
172
|
+
data: p["data"],
|
173
|
+
data_base64: p["dataBase64"] !== undefined ? coreUtil.uint8ArrayToString(p["dataBase64"], "base64") : undefined,
|
174
|
+
type: p["type"],
|
175
|
+
time: (_a = p["time"]) === null || _a === void 0 ? void 0 : _a.toISOString(),
|
176
|
+
specversion: p["specversion"],
|
177
|
+
dataschema: p["dataschema"],
|
178
|
+
datacontenttype: p["datacontenttype"],
|
179
|
+
subject: p["subject"],
|
180
|
+
};
|
181
|
+
}) }));
|
182
|
+
}
|
183
|
+
async function _publishCloudEventsDeserialize(result) {
|
184
|
+
if (isUnexpected(result)) {
|
185
|
+
throw coreClient.createRestError(result);
|
186
|
+
}
|
187
|
+
return result.body;
|
188
|
+
}
|
189
|
+
/** Publish Batch Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200 status code with an empty JSON object in response. Otherwise, the server can return various error codes. For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for internal server error. */
|
190
|
+
async function publishCloudEvents(context, topicName, events, options = { requestOptions: {} }) {
|
191
|
+
const result = await _publishCloudEventsSend(context, topicName, events, options);
|
192
|
+
return _publishCloudEventsDeserialize(result);
|
193
|
+
}
|
194
|
+
function _receiveCloudEventsSend(context, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
195
|
+
return context
|
196
|
+
.path("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:receive", topicName, eventSubscriptionName)
|
197
|
+
.post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { queryParameters: {
|
198
|
+
maxEvents: options === null || options === void 0 ? void 0 : options.maxEvents,
|
199
|
+
maxWaitTime: options === null || options === void 0 ? void 0 : options.maxWaitTime,
|
200
|
+
} }));
|
201
|
+
}
|
202
|
+
async function _receiveCloudEventsDeserialize(result) {
|
203
|
+
if (isUnexpected(result)) {
|
204
|
+
throw coreClient.createRestError(result);
|
205
|
+
}
|
206
|
+
return {
|
207
|
+
value: result.body["value"].map((p) => ({
|
208
|
+
brokerProperties: {
|
209
|
+
lockToken: p.brokerProperties["lockToken"],
|
210
|
+
deliveryCount: p.brokerProperties["deliveryCount"],
|
211
|
+
},
|
212
|
+
event: {
|
213
|
+
id: p.event["id"],
|
214
|
+
source: p.event["source"],
|
215
|
+
data: p.event["data"],
|
216
|
+
dataBase64: typeof p.event["data_base64"] === "string"
|
217
|
+
? coreUtil.stringToUint8Array(p.event["data_base64"], "base64")
|
218
|
+
: p.event["data_base64"],
|
219
|
+
type: p.event["type"],
|
220
|
+
time: p.event["time"] !== undefined ? new Date(p.event["time"]) : undefined,
|
221
|
+
specversion: p.event["specversion"],
|
222
|
+
dataschema: p.event["dataschema"],
|
223
|
+
datacontenttype: p.event["datacontenttype"],
|
224
|
+
subject: p.event["subject"],
|
225
|
+
},
|
226
|
+
})),
|
227
|
+
};
|
228
|
+
}
|
229
|
+
/** Receive Batch of Cloud Events from the Event Subscription. */
|
230
|
+
async function receiveCloudEvents(context, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
231
|
+
const result = await _receiveCloudEventsSend(context, topicName, eventSubscriptionName, options);
|
232
|
+
return _receiveCloudEventsDeserialize(result);
|
233
|
+
}
|
234
|
+
function _acknowledgeCloudEventsSend(context, topicName, eventSubscriptionName, acknowledgeOptions, options = { requestOptions: {} }) {
|
235
|
+
return context
|
236
|
+
.path("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:acknowledge", topicName, eventSubscriptionName)
|
237
|
+
.post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { body: { lockTokens: acknowledgeOptions["lockTokens"] } }));
|
238
|
+
}
|
239
|
+
async function _acknowledgeCloudEventsDeserialize(result) {
|
240
|
+
if (isUnexpected(result)) {
|
241
|
+
throw coreClient.createRestError(result);
|
242
|
+
}
|
243
|
+
return {
|
244
|
+
failedLockTokens: result.body["failedLockTokens"].map((p) => ({
|
245
|
+
lockToken: p["lockToken"],
|
246
|
+
error: p.error,
|
247
|
+
})),
|
248
|
+
succeededLockTokens: result.body["succeededLockTokens"],
|
249
|
+
};
|
250
|
+
}
|
251
|
+
/** Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if the request is successfully accepted. The response body will include the set of successfully acknowledged lockTokens, along with other failed lockTokens with their corresponding error information. Successfully acknowledged events will no longer be available to any consumer. */
|
252
|
+
async function acknowledgeCloudEvents(context, topicName, eventSubscriptionName, acknowledgeOptions, options = { requestOptions: {} }) {
|
253
|
+
const result = await _acknowledgeCloudEventsSend(context, topicName, eventSubscriptionName, acknowledgeOptions, options);
|
254
|
+
return _acknowledgeCloudEventsDeserialize(result);
|
255
|
+
}
|
256
|
+
function _releaseCloudEventsSend(context, topicName, eventSubscriptionName, releaseOptions, options = { requestOptions: {} }) {
|
257
|
+
let releaseDelayInSeconds = undefined;
|
258
|
+
if (options === null || options === void 0 ? void 0 : options.releaseDelayInSeconds) {
|
259
|
+
releaseDelayInSeconds = parseInt(options.releaseDelayInSeconds);
|
260
|
+
}
|
261
|
+
return context
|
262
|
+
.path("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:release", topicName, eventSubscriptionName)
|
263
|
+
.post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { queryParameters: {
|
264
|
+
releaseDelayInSeconds,
|
265
|
+
}, body: { lockTokens: releaseOptions["lockTokens"] } }));
|
266
|
+
}
|
267
|
+
async function _releaseCloudEventsDeserialize(result) {
|
268
|
+
if (isUnexpected(result)) {
|
269
|
+
throw coreClient.createRestError(result);
|
270
|
+
}
|
271
|
+
return {
|
272
|
+
failedLockTokens: result.body["failedLockTokens"].map((p) => ({
|
273
|
+
lockToken: p["lockToken"],
|
274
|
+
error: p.error,
|
275
|
+
})),
|
276
|
+
succeededLockTokens: result.body["succeededLockTokens"],
|
277
|
+
};
|
278
|
+
}
|
279
|
+
/** Release batch of Cloud Events. The server responds with an HTTP 200 status code if the request is successfully accepted. The response body will include the set of successfully released lockTokens, along with other failed lockTokens with their corresponding error information. */
|
280
|
+
async function releaseCloudEvents(context, topicName, eventSubscriptionName, releaseOptions, options = { requestOptions: {} }) {
|
281
|
+
const result = await _releaseCloudEventsSend(context, topicName, eventSubscriptionName, releaseOptions, options);
|
282
|
+
return _releaseCloudEventsDeserialize(result);
|
283
|
+
}
|
284
|
+
function _rejectCloudEventsSend(context, topicName, eventSubscriptionName, rejectOptions, options = { requestOptions: {} }) {
|
285
|
+
return context
|
286
|
+
.path("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:reject", topicName, eventSubscriptionName)
|
287
|
+
.post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { body: { lockTokens: rejectOptions["lockTokens"] } }));
|
288
|
+
}
|
289
|
+
async function _rejectCloudEventsDeserialize(result) {
|
290
|
+
if (isUnexpected(result)) {
|
291
|
+
throw coreClient.createRestError(result);
|
292
|
+
}
|
293
|
+
return {
|
294
|
+
failedLockTokens: result.body["failedLockTokens"].map((p) => ({
|
295
|
+
lockToken: p["lockToken"],
|
296
|
+
error: p.error,
|
297
|
+
})),
|
298
|
+
succeededLockTokens: result.body["succeededLockTokens"],
|
299
|
+
};
|
300
|
+
}
|
301
|
+
/** Reject batch of Cloud Events. The server responds with an HTTP 200 status code if the request is successfully accepted. The response body will include the set of successfully rejected lockTokens, along with other failed lockTokens with their corresponding error information. */
|
302
|
+
async function rejectCloudEvents(context, topicName, eventSubscriptionName, rejectOptions, options = { requestOptions: {} }) {
|
303
|
+
const result = await _rejectCloudEventsSend(context, topicName, eventSubscriptionName, rejectOptions, options);
|
304
|
+
return _rejectCloudEventsDeserialize(result);
|
305
|
+
}
|
306
|
+
function _renewCloudEventLocksSend(context, topicName, eventSubscriptionName, renewLockOptions, options = { requestOptions: {} }) {
|
307
|
+
return context
|
308
|
+
.path("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:renewLock", topicName, eventSubscriptionName)
|
309
|
+
.post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { body: { lockTokens: renewLockOptions["lockTokens"] } }));
|
310
|
+
}
|
311
|
+
async function _renewCloudEventLocksDeserialize(result) {
|
312
|
+
if (isUnexpected(result)) {
|
313
|
+
throw coreClient.createRestError(result);
|
314
|
+
}
|
315
|
+
return {
|
316
|
+
failedLockTokens: result.body["failedLockTokens"].map((p) => ({
|
317
|
+
lockToken: p["lockToken"],
|
318
|
+
error: p.error,
|
319
|
+
})),
|
320
|
+
succeededLockTokens: result.body["succeededLockTokens"],
|
321
|
+
};
|
322
|
+
}
|
323
|
+
/** Renew lock for batch of Cloud Events. The server responds with an HTTP 200 status code if the request is successfully accepted. The response body will include the set of successfully renewed lockTokens, along with other failed lockTokens with their corresponding error information. */
|
324
|
+
async function renewCloudEventLocks(context, topicName, eventSubscriptionName, renewLockOptions, options = { requestOptions: {} }) {
|
325
|
+
const result = await _renewCloudEventLocksSend(context, topicName, eventSubscriptionName, renewLockOptions, options);
|
326
|
+
return _renewCloudEventLocksDeserialize(result);
|
327
|
+
}
|
328
|
+
|
329
|
+
// Copyright (c) Microsoft Corporation.
|
330
|
+
// Licensed under the MIT license.
|
331
|
+
class EventGridClient {
|
332
|
+
getClient() {
|
333
|
+
return this._client;
|
334
|
+
}
|
335
|
+
/** Azure Messaging EventGrid Client */
|
336
|
+
constructor(endpoint, credential, options = {}) {
|
337
|
+
this._client = createEventGrid(endpoint, credential, options);
|
338
|
+
this.pipeline = this._client.pipeline;
|
339
|
+
}
|
340
|
+
/** Publish Single Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200 status code with an empty JSON object in response. Otherwise, the server can return various error codes. For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for internal server error. */
|
341
|
+
publishCloudEvent(topicName, event, options = { requestOptions: {} }) {
|
342
|
+
return publishCloudEvent(this._client, topicName, event, options);
|
343
|
+
}
|
344
|
+
/** Publish Batch Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200 status code with an empty JSON object in response. Otherwise, the server can return various error codes. For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for internal server error. */
|
345
|
+
publishCloudEvents(topicName, events, options = { requestOptions: {} }) {
|
346
|
+
return publishCloudEvents(this._client, topicName, events, options);
|
347
|
+
}
|
348
|
+
/** Receive Batch of Cloud Events from the Event Subscription. */
|
349
|
+
receiveCloudEvents(topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
350
|
+
return receiveCloudEvents(this._client, topicName, eventSubscriptionName, options);
|
351
|
+
}
|
352
|
+
/** Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if the request is successfully accepted. The response body will include the set of successfully acknowledged lockTokens, along with other failed lockTokens with their corresponding error information. Successfully acknowledged events will no longer be available to any consumer. */
|
353
|
+
acknowledgeCloudEvents(topicName, eventSubscriptionName,
|
354
|
+
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
|
355
|
+
acknowledgeOptions, options = { requestOptions: {} }) {
|
356
|
+
return acknowledgeCloudEvents(this._client, topicName, eventSubscriptionName, acknowledgeOptions, options);
|
357
|
+
}
|
358
|
+
/** Release batch of Cloud Events. The server responds with an HTTP 200 status code if the request is successfully accepted. The response body will include the set of successfully released lockTokens, along with other failed lockTokens with their corresponding error information. */
|
359
|
+
releaseCloudEvents(topicName, eventSubscriptionName,
|
360
|
+
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
|
361
|
+
releaseOptions, options = { requestOptions: {} }) {
|
362
|
+
return releaseCloudEvents(this._client, topicName, eventSubscriptionName, releaseOptions, options);
|
363
|
+
}
|
364
|
+
/** Reject batch of Cloud Events. The server responds with an HTTP 200 status code if the request is successfully accepted. The response body will include the set of successfully rejected lockTokens, along with other failed lockTokens with their corresponding error information. */
|
365
|
+
rejectCloudEvents(topicName, eventSubscriptionName,
|
366
|
+
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
|
367
|
+
rejectOptions, options = { requestOptions: {} }) {
|
368
|
+
return rejectCloudEvents(this._client, topicName, eventSubscriptionName, rejectOptions, options);
|
369
|
+
}
|
370
|
+
/** Renew lock for batch of Cloud Events. The server responds with an HTTP 200 status code if the request is successfully accepted. The response body will include the set of successfully renewed lockTokens, along with other failed lockTokens with their corresponding error information. */
|
371
|
+
renewCloudEventLocks(topicName, eventSubscriptionName,
|
372
|
+
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
|
373
|
+
renewLockOptions, options = { requestOptions: {} }) {
|
374
|
+
return renewCloudEventLocks(this._client, topicName, eventSubscriptionName, renewLockOptions, options);
|
375
|
+
}
|
376
|
+
}
|
377
|
+
|
378
|
+
// Copyright (c) Microsoft Corporation.
|
379
|
+
// Licensed under the MIT license.
|
380
|
+
const cloudEventReservedPropertyNames = [
|
381
|
+
"specversion",
|
382
|
+
"id",
|
383
|
+
"source",
|
384
|
+
"type",
|
385
|
+
"datacontenttype",
|
386
|
+
"dataschema",
|
387
|
+
"subject",
|
388
|
+
"time",
|
389
|
+
"data",
|
390
|
+
];
|
391
|
+
|
392
|
+
// Copyright (c) Microsoft Corporation.
|
393
|
+
// Licensed under the MIT license.
|
394
|
+
async function publishCloudEventInBinaryMode(context, topicName, event, options = { requestOptions: {} }) {
|
395
|
+
const result = await _publishCloudEventSendBinaryMode(context, topicName, event, options);
|
396
|
+
return _publishCloudEventDeserialize(result);
|
397
|
+
}
|
398
|
+
async function _publishCloudEventDeserialize(result) {
|
399
|
+
if (isUnexpected(result)) {
|
400
|
+
throw result.body;
|
401
|
+
}
|
402
|
+
return result.body;
|
403
|
+
}
|
404
|
+
function _publishCloudEventSendBinaryMode(context, topicName, event, options = { requestOptions: {} }) {
|
405
|
+
var _a, _b;
|
406
|
+
const headers = {
|
407
|
+
"ce-id": event.id,
|
408
|
+
"ce-source": event.source,
|
409
|
+
"ce-type": event.type,
|
410
|
+
"ce-specversion": event.specversion,
|
411
|
+
};
|
412
|
+
if (event.time) {
|
413
|
+
headers["ce-time"] = event.time.toISOString();
|
414
|
+
}
|
415
|
+
if (event.dataschema) {
|
416
|
+
headers["ce-dataschema"] = event.dataschema;
|
417
|
+
}
|
418
|
+
if (event.datacontenttype) {
|
419
|
+
headers["ce-datacontenttype"] = event.datacontenttype;
|
420
|
+
}
|
421
|
+
if (event.subject) {
|
422
|
+
headers["ce-subject"] = event.subject;
|
423
|
+
}
|
424
|
+
let data;
|
425
|
+
if (event.data) {
|
426
|
+
// If data is already encoded
|
427
|
+
if (buffer.Buffer.isBuffer(event.data)) {
|
428
|
+
data = event.data;
|
429
|
+
}
|
430
|
+
else {
|
431
|
+
throw new Error(`CloudEvent data must be binary when in binary mode.`);
|
432
|
+
}
|
433
|
+
}
|
434
|
+
else {
|
435
|
+
if (event.dataBase64) {
|
436
|
+
data = event.dataBase64;
|
437
|
+
}
|
438
|
+
}
|
439
|
+
return context.path("/topics/{topicName}:publish", topicName).post(Object.assign(Object.assign({}, coreClient.operationOptionsToRequestParameters(options)), { contentType: (_a = options.contentType) !== null && _a !== void 0 ? _a : "application/cloudevents+json; charset=utf-8", headers, body: {
|
440
|
+
id: event.id,
|
441
|
+
source: event.source,
|
442
|
+
data,
|
443
|
+
type: event.type,
|
444
|
+
time: (_b = event.time) === null || _b === void 0 ? void 0 : _b.toISOString(),
|
445
|
+
specversion: event.specversion,
|
446
|
+
dataschema: event.dataschema,
|
447
|
+
datacontenttype: event.datacontenttype,
|
448
|
+
subject: event.subject,
|
449
|
+
} }));
|
450
|
+
}
|
451
|
+
|
452
|
+
// Copyright (c) Microsoft Corporation.
|
453
|
+
// Licensed under the MIT license.
|
454
|
+
/**
|
455
|
+
* Event Grid Namespaces Client
|
456
|
+
*/
|
457
|
+
class EventGridNamespacesClient {
|
458
|
+
/** Azure Messaging EventGrid Client */
|
459
|
+
constructor(endpoint, credential, options = {}) {
|
460
|
+
// credential.update(`SharedAccessKey ${credential.key}`);
|
461
|
+
this._client = new EventGridClient(endpoint, credential, options);
|
462
|
+
}
|
463
|
+
/**
|
464
|
+
* Publish Single Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200
|
465
|
+
* status code with an empty JSON object in response. Otherwise, the server can return various error codes.
|
466
|
+
* For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
|
467
|
+
* is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
|
468
|
+
* internal server error.
|
469
|
+
*
|
470
|
+
* @param event - Event to publish
|
471
|
+
* @param topicName - Topic to publish the event
|
472
|
+
* @param options - Options to publish
|
473
|
+
*
|
474
|
+
*/
|
475
|
+
async publishCloudEvent(event, topicName, options = { requestOptions: {} }) {
|
476
|
+
const cloudEventWireModel = convertCloudEventToModelType(event);
|
477
|
+
if (!options.binaryMode) {
|
478
|
+
await this._client.publishCloudEvent(topicName, cloudEventWireModel, options);
|
479
|
+
}
|
480
|
+
else {
|
481
|
+
await publishCloudEventInBinaryMode(this._client.getClient(), topicName, cloudEventWireModel, Object.assign({ contentType: options.contentType }, options));
|
482
|
+
}
|
483
|
+
}
|
484
|
+
/**
|
485
|
+
* Publish Batch Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200
|
486
|
+
* status code with an empty JSON object in response. Otherwise, the server can return various error codes.
|
487
|
+
* For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
|
488
|
+
* is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
|
489
|
+
* internal server error.
|
490
|
+
*
|
491
|
+
* @param events - Events to publish
|
492
|
+
* @param topicName - Topic to publish the event
|
493
|
+
* @param options - Options to publish
|
494
|
+
*
|
495
|
+
*/
|
496
|
+
async publishCloudEvents(events, topicName, options = { requestOptions: {} }) {
|
497
|
+
const eventsWireModel = [];
|
498
|
+
for (const individualevent of events) {
|
499
|
+
eventsWireModel.push(convertCloudEventToModelType(individualevent));
|
500
|
+
}
|
501
|
+
await this._client.publishCloudEvents(topicName, eventsWireModel, options);
|
502
|
+
}
|
503
|
+
/**
|
504
|
+
* Receive Batch of Cloud Events from the Event Subscription.
|
505
|
+
*
|
506
|
+
* @param topicName - Topic to receive
|
507
|
+
* @param eventSubscriptionName - Name of the Event Subscription
|
508
|
+
* @param options - Options to receive
|
509
|
+
*
|
510
|
+
*/
|
511
|
+
receiveCloudEvents(topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
512
|
+
return this._client.receiveCloudEvents(topicName, eventSubscriptionName, options);
|
513
|
+
}
|
514
|
+
/**
|
515
|
+
* Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if at least one
|
516
|
+
* event is successfully acknowledged. The response body will include the set of successfully acknowledged
|
517
|
+
* lockTokens, along with other failed lockTokens with their corresponding error information. Successfully
|
518
|
+
* acknowledged events will no longer be available to any consumer.
|
519
|
+
*
|
520
|
+
* @param lockTokens - Lock Tokens
|
521
|
+
* @param topicName - Topic Name
|
522
|
+
* @param eventSubscriptionName - Name of the Event Subscription
|
523
|
+
* @param options - Options to Acknowledge
|
524
|
+
*
|
525
|
+
*/
|
526
|
+
acknowledgeCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
527
|
+
return this._client.acknowledgeCloudEvents(topicName, eventSubscriptionName, { lockTokens }, options);
|
528
|
+
}
|
529
|
+
/**
|
530
|
+
* Release batch of Cloud Events. The server responds with an HTTP 200 status code if at least one event is
|
531
|
+
* successfully released. The response body will include the set of successfully released lockTokens, along
|
532
|
+
* with other failed lockTokens with their corresponding error information.
|
533
|
+
*
|
534
|
+
* @param lockTokens - Lock Tokens
|
535
|
+
* @param topicName - Topic Name
|
536
|
+
* @param eventSubscriptionName - Name of the Event Subscription
|
537
|
+
* @param options - Options to release
|
538
|
+
*
|
539
|
+
*/
|
540
|
+
releaseCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
541
|
+
return this._client.releaseCloudEvents(topicName, eventSubscriptionName, { lockTokens }, options);
|
542
|
+
}
|
543
|
+
/**
|
544
|
+
* Reject batch of Cloud Events.
|
545
|
+
*
|
546
|
+
* @param lockTokens - Lock Tokens
|
547
|
+
* @param topicName - Topic Name
|
548
|
+
* @param eventSubscriptionName - Name of the Event Subscription
|
549
|
+
* @param options - Options to reject
|
550
|
+
*
|
551
|
+
*/
|
552
|
+
rejectCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
553
|
+
return this._client.rejectCloudEvents(topicName, eventSubscriptionName, { lockTokens }, options);
|
554
|
+
}
|
555
|
+
/**
|
556
|
+
* Renew lock for batch of Cloud Events.
|
557
|
+
*
|
558
|
+
* @param lockTokens - Lock Tokens
|
559
|
+
* @param topicName - Topic Name
|
560
|
+
* @param eventSubscriptionName - Name of the Event Subscription
|
561
|
+
* @param options - Options to renew
|
562
|
+
*/
|
563
|
+
renewCloudEventLocks(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
564
|
+
return this._client.renewCloudEventLocks(topicName, eventSubscriptionName, { lockTokens }, options);
|
565
|
+
}
|
566
|
+
}
|
567
|
+
function convertCloudEventToModelType(event) {
|
568
|
+
var _a, _b, _c, _d, _e;
|
569
|
+
if (event.extensionAttributes) {
|
570
|
+
for (const propName in event.extensionAttributes) {
|
571
|
+
// Per the cloud events spec: "CloudEvents attribute names MUST consist of lower-case letters ('a' to 'z') or digits ('0' to '9') from the ASCII character set"
|
572
|
+
// they also can not match an existing defined property name.
|
573
|
+
if (!/^[a-z0-9]*$/.test(propName) ||
|
574
|
+
cloudEventReservedPropertyNames.indexOf(propName) !== -1) {
|
575
|
+
throw new Error(`invalid extension attribute name: ${propName}`);
|
576
|
+
}
|
577
|
+
}
|
578
|
+
}
|
579
|
+
const converted = Object.assign({ specversion: (_a = event.specversion) !== null && _a !== void 0 ? _a : "1.0", type: event.type, source: event.source, id: (_b = event.id) !== null && _b !== void 0 ? _b : coreUtil.randomUUID(), time: (_c = event.time) !== null && _c !== void 0 ? _c : new Date(), subject: event.subject, dataschema: event.dataschema }, ((_d = event.extensionAttributes) !== null && _d !== void 0 ? _d : []));
|
580
|
+
if (event.data instanceof Uint8Array) {
|
581
|
+
if (!event.datacontenttype) {
|
582
|
+
throw new Error("a data content type must be provided when sending an event with binary data");
|
583
|
+
}
|
584
|
+
converted.datacontenttype = event.datacontenttype;
|
585
|
+
converted.dataBase64 = event.data;
|
586
|
+
}
|
587
|
+
else {
|
588
|
+
converted.datacontenttype =
|
589
|
+
(_e = event.datacontenttype) !== null && _e !== void 0 ? _e : "application/cloudevents+json; charset=utf-8";
|
590
|
+
converted.data = event.data;
|
591
|
+
}
|
592
|
+
return converted;
|
593
|
+
}
|
594
|
+
|
595
|
+
Object.defineProperty(exports, "AzureKeyCredential", {
|
596
|
+
enumerable: true,
|
597
|
+
get: function () { return coreAuth.AzureKeyCredential; }
|
598
|
+
});
|
599
|
+
exports.EventGridClient = EventGridNamespacesClient;
|
600
|
+
//# sourceMappingURL=index.js.map
|