@azure/eventgrid 4.13.0-beta.1 → 4.13.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/dist/index.js +76 -430
- package/dist/index.js.map +1 -1
- package/dist-esm/src/generated/generatedClientContext.js +1 -1
- package/dist-esm/src/generated/generatedClientContext.js.map +1 -1
- package/dist-esm/src/generated/models/index.js.map +1 -1
- package/dist-esm/src/generated/models/mappers.js +65 -0
- package/dist-esm/src/generated/models/mappers.js.map +1 -1
- package/dist-esm/src/index.js +0 -1
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/models.js.map +1 -1
- package/dist-esm/src/predicates.js.map +1 -1
- package/dist-esm/src/tracing.js +1 -1
- package/dist-esm/src/tracing.js.map +1 -1
- package/package.json +2 -3
- package/types/eventgrid.d.ts +37 -216
- package/dist-esm/src/cadl-generated/EventGridClient.js +0 -28
- package/dist-esm/src/cadl-generated/EventGridClient.js.map +0 -1
- package/dist-esm/src/cadl-generated/api/EventGridContext.js +0 -11
- package/dist-esm/src/cadl-generated/api/EventGridContext.js.map +0 -1
- package/dist-esm/src/cadl-generated/api/index.js +0 -5
- package/dist-esm/src/cadl-generated/api/index.js.map +0 -1
- package/dist-esm/src/cadl-generated/api/models.js +0 -2
- package/dist-esm/src/cadl-generated/api/models.js.map +0 -1
- package/dist-esm/src/cadl-generated/api/operations.js +0 -162
- package/dist-esm/src/cadl-generated/api/operations.js.map +0 -1
- package/dist-esm/src/cadl-generated/common/interfaces.js +0 -4
- package/dist-esm/src/cadl-generated/common/interfaces.js.map +0 -1
- package/dist-esm/src/cadl-generated/index.js +0 -4
- package/dist-esm/src/cadl-generated/index.js.map +0 -1
- package/dist-esm/src/cadl-generated/logger.js +0 -5
- package/dist-esm/src/cadl-generated/logger.js.map +0 -1
- package/dist-esm/src/cadl-generated/rest/clientDefinitions.js +0 -4
- package/dist-esm/src/cadl-generated/rest/clientDefinitions.js.map +0 -1
- package/dist-esm/src/cadl-generated/rest/eventGridClient.js +0 -30
- package/dist-esm/src/cadl-generated/rest/eventGridClient.js.map +0 -1
- package/dist-esm/src/cadl-generated/rest/index.js +0 -12
- package/dist-esm/src/cadl-generated/rest/index.js.map +0 -1
- package/dist-esm/src/cadl-generated/rest/isUnexpected.js +0 -74
- package/dist-esm/src/cadl-generated/rest/isUnexpected.js.map +0 -1
- package/dist-esm/src/cadl-generated/rest/models.js +0 -4
- package/dist-esm/src/cadl-generated/rest/models.js.map +0 -1
- package/dist-esm/src/cadl-generated/rest/outputModels.js +0 -4
- package/dist-esm/src/cadl-generated/rest/outputModels.js.map +0 -1
- package/dist-esm/src/cadl-generated/rest/parameters.js +0 -4
- package/dist-esm/src/cadl-generated/rest/parameters.js.map +0 -1
- package/dist-esm/src/cadl-generated/rest/responses.js +0 -4
- package/dist-esm/src/cadl-generated/rest/responses.js.map +0 -1
- package/dist-esm/src/eventGridClientV2.js +0 -128
- package/dist-esm/src/eventGridClientV2.js.map +0 -1
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/cadl-generated/logger.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,MAAM,CAAC,MAAM,MAAM,GAAG,kBAAkB,CAAC,oBAAoB,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { createClientLogger } from \"@azure/logger\";\nexport const logger = createClientLogger(\"event-grid-modular\");\n"]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"clientDefinitions.js","sourceRoot":"","sources":["../../../../src/cadl-generated/rest/clientDefinitions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n PublishCloudEventParameters,\n PublishCloudEventsParameters,\n ReceiveCloudEventsParameters,\n AcknowledgeCloudEventsParameters,\n ReleaseCloudEventsParameters,\n RejectCloudEventsParameters,\n} from \"./parameters\";\nimport {\n PublishCloudEvent200Response,\n PublishCloudEventDefaultResponse,\n PublishCloudEvents200Response,\n PublishCloudEventsDefaultResponse,\n ReceiveCloudEvents200Response,\n ReceiveCloudEventsDefaultResponse,\n AcknowledgeCloudEvents200Response,\n AcknowledgeCloudEventsDefaultResponse,\n ReleaseCloudEvents200Response,\n ReleaseCloudEventsDefaultResponse,\n RejectCloudEvents200Response,\n RejectCloudEventsDefaultResponse,\n} from \"./responses\";\nimport { Client, StreamableMethod } from \"@azure-rest/core-client\";\n\nexport interface PublishCloudEvent {\n /** 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. */\n post(\n options: PublishCloudEventParameters\n ): StreamableMethod<PublishCloudEvent200Response | PublishCloudEventDefaultResponse>;\n /** 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. */\n post(\n options: PublishCloudEventsParameters\n ): StreamableMethod<PublishCloudEvents200Response | PublishCloudEventsDefaultResponse>;\n}\n\nexport interface ReceiveCloudEvents {\n /** Receive Batch of Cloud Events from the Event Subscription. */\n post(\n options?: ReceiveCloudEventsParameters\n ): StreamableMethod<ReceiveCloudEvents200Response | ReceiveCloudEventsDefaultResponse>;\n}\n\nexport interface AcknowledgeCloudEvents {\n /** Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if at least one event is successfully acknowledged. 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. */\n post(\n options: AcknowledgeCloudEventsParameters\n ): StreamableMethod<AcknowledgeCloudEvents200Response | AcknowledgeCloudEventsDefaultResponse>;\n}\n\nexport interface ReleaseCloudEvents {\n /** Release batch of Cloud Events. The server responds with an HTTP 200 status code if at least one event is successfully released. The response body will include the set of successfully released lockTokens, along with other failed lockTokens with their corresponding error information. */\n post(\n options: ReleaseCloudEventsParameters\n ): StreamableMethod<ReleaseCloudEvents200Response | ReleaseCloudEventsDefaultResponse>;\n}\n\nexport interface RejectCloudEvents {\n /** Reject batch of Cloud Events. */\n post(\n options: RejectCloudEventsParameters\n ): StreamableMethod<RejectCloudEvents200Response | RejectCloudEventsDefaultResponse>;\n}\n\nexport interface Routes {\n /** Resource for '/topics/\\{topicName\\}:publish' has methods for the following verbs: post */\n (path: \"/topics/{topicName}:publish\", topicName: string): PublishCloudEvent;\n /** Resource for '/topics/\\{topicName\\}/eventsubscriptions/\\{eventSubscriptionName\\}:receive' has methods for the following verbs: post */\n (\n path: \"/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:receive\",\n topicName: string,\n eventSubscriptionName: string\n ): ReceiveCloudEvents;\n /** Resource for '/topics/\\{topicName\\}/eventsubscriptions/\\{eventSubscriptionName\\}:acknowledge' has methods for the following verbs: post */\n (\n path: \"/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:acknowledge\",\n topicName: string,\n eventSubscriptionName: string\n ): AcknowledgeCloudEvents;\n /** Resource for '/topics/\\{topicName\\}/eventsubscriptions/\\{eventSubscriptionName\\}:release' has methods for the following verbs: post */\n (\n path: \"/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:release\",\n topicName: string,\n eventSubscriptionName: string\n ): ReleaseCloudEvents;\n /** Resource for '/topics/\\{topicName\\}/eventsubscriptions/\\{eventSubscriptionName\\}:reject' has methods for the following verbs: post */\n (\n path: \"/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:reject\",\n topicName: string,\n eventSubscriptionName: string\n ): RejectCloudEvents;\n}\n\nexport type EventGridContext = Client & {\n path: Routes;\n};\n"]}
|
@@ -1,30 +0,0 @@
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
2
|
-
// Licensed under the MIT license.
|
3
|
-
import { getClient } from "@azure-rest/core-client";
|
4
|
-
import { logger } from "../logger";
|
5
|
-
/**
|
6
|
-
* Initialize a new instance of `EventGridContext`
|
7
|
-
* @param endpoint - The host name of the namespace, e.g. namespaceName1.westus-1.eventgrid.azure.net
|
8
|
-
* @param credentials - Uniquely identify client credential
|
9
|
-
* @param options - optional parameters
|
10
|
-
*/
|
11
|
-
export default function createClient(endpoint, credentials, options = {}) {
|
12
|
-
var _a, _b, _c, _d;
|
13
|
-
const baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : `${endpoint}`;
|
14
|
-
options.apiVersion = (_b = options.apiVersion) !== null && _b !== void 0 ? _b : "2023-06-01-preview";
|
15
|
-
options = Object.assign(Object.assign({}, options), { credentials: {
|
16
|
-
apiKeyHeaderName: "Authorization",
|
17
|
-
} });
|
18
|
-
const userAgentInfo = `azsdk-js-event-grid-modular-rest/1.0.0-beta.1`;
|
19
|
-
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
20
|
-
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
|
21
|
-
: `${userAgentInfo}`;
|
22
|
-
options = Object.assign(Object.assign({}, options), { userAgentOptions: {
|
23
|
-
userAgentPrefix,
|
24
|
-
}, loggingOptions: {
|
25
|
-
logger: (_d = (_c = options.loggingOptions) === null || _c === void 0 ? void 0 : _c.logger) !== null && _d !== void 0 ? _d : logger.info,
|
26
|
-
} });
|
27
|
-
const client = getClient(baseUrl, credentials, options);
|
28
|
-
return client;
|
29
|
-
}
|
30
|
-
//# sourceMappingURL=eventGridClient.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"eventGridClient.js","sourceRoot":"","sources":["../../../../src/cadl-generated/rest/eventGridClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,SAAS,EAAiB,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAInC;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,QAAgB,EAChB,WAA0B,EAC1B,UAAyB,EAAE;;IAE3B,MAAM,OAAO,GAAG,MAAA,OAAO,CAAC,OAAO,mCAAI,GAAG,QAAQ,EAAE,CAAC;IACjD,OAAO,CAAC,UAAU,GAAG,MAAA,OAAO,CAAC,UAAU,mCAAI,oBAAoB,CAAC;IAChE,OAAO,mCACF,OAAO,KACV,WAAW,EAAE;YACX,gBAAgB,EAAE,eAAe;SAClC,GACF,CAAC;IAEF,MAAM,aAAa,GAAG,+CAA+C,CAAC;IACtE,MAAM,eAAe,GACnB,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC,eAAe;QAClE,CAAC,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,eAAe,IAAI,aAAa,EAAE;QAChE,CAAC,CAAC,GAAG,aAAa,EAAE,CAAC;IACzB,OAAO,mCACF,OAAO,KACV,gBAAgB,EAAE;YAChB,eAAe;SAChB,EACD,cAAc,EAAE;YACd,MAAM,EAAE,MAAA,MAAA,OAAO,CAAC,cAAc,0CAAE,MAAM,mCAAI,MAAM,CAAC,IAAI;SACtD,GACF,CAAC;IAEF,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAqB,CAAC;IAE5E,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { getClient, ClientOptions } from \"@azure-rest/core-client\";\nimport { logger } from \"../logger\";\nimport { KeyCredential } from \"@azure/core-auth\";\nimport { EventGridContext } from \"./clientDefinitions\";\n\n/**\n * Initialize a new instance of `EventGridContext`\n * @param endpoint - The host name of the namespace, e.g. namespaceName1.westus-1.eventgrid.azure.net\n * @param credentials - Uniquely identify client credential\n * @param options - optional parameters\n */\nexport default function createClient(\n endpoint: string,\n credentials: KeyCredential,\n options: ClientOptions = {}\n): EventGridContext {\n const baseUrl = options.baseUrl ?? `${endpoint}`;\n options.apiVersion = options.apiVersion ?? \"2023-06-01-preview\";\n options = {\n ...options,\n credentials: {\n apiKeyHeaderName: \"Authorization\",\n },\n };\n\n const userAgentInfo = `azsdk-js-event-grid-modular-rest/1.0.0-beta.1`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`\n : `${userAgentInfo}`;\n options = {\n ...options,\n userAgentOptions: {\n userAgentPrefix,\n },\n loggingOptions: {\n logger: options.loggingOptions?.logger ?? logger.info,\n },\n };\n\n const client = getClient(baseUrl, credentials, options) as EventGridContext;\n\n return client;\n}\n"]}
|
@@ -1,12 +0,0 @@
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
2
|
-
// Licensed under the MIT license.
|
3
|
-
import EventGridClient from "./eventGridClient";
|
4
|
-
export * from "./eventGridClient";
|
5
|
-
export * from "./parameters";
|
6
|
-
export * from "./responses";
|
7
|
-
export * from "./clientDefinitions";
|
8
|
-
export * from "./isUnexpected";
|
9
|
-
export * from "./models";
|
10
|
-
export * from "./outputModels";
|
11
|
-
export default EventGridClient;
|
12
|
-
//# sourceMappingURL=index.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/cadl-generated/rest/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAEhD,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAE/B,eAAe,eAAe,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport EventGridClient from \"./eventGridClient\";\n\nexport * from \"./eventGridClient\";\nexport * from \"./parameters\";\nexport * from \"./responses\";\nexport * from \"./clientDefinitions\";\nexport * from \"./isUnexpected\";\nexport * from \"./models\";\nexport * from \"./outputModels\";\n\nexport default EventGridClient;\n"]}
|
@@ -1,74 +0,0 @@
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
2
|
-
// Licensed under the MIT license.
|
3
|
-
const responseMap = {
|
4
|
-
"POST /topics/{topicName}:publish": ["200"],
|
5
|
-
"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:receive": ["200"],
|
6
|
-
"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:acknowledge": ["200"],
|
7
|
-
"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:release": ["200"],
|
8
|
-
"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:reject": ["200"],
|
9
|
-
};
|
10
|
-
export function isUnexpected(response) {
|
11
|
-
const lroOriginal = response.headers["x-ms-original-url"];
|
12
|
-
const url = new URL(lroOriginal !== null && lroOriginal !== void 0 ? lroOriginal : response.request.url);
|
13
|
-
const method = response.request.method;
|
14
|
-
let pathDetails = responseMap[`${method} ${url.pathname}`];
|
15
|
-
if (!pathDetails) {
|
16
|
-
pathDetails = getParametrizedPathSuccess(method, url.pathname);
|
17
|
-
}
|
18
|
-
return !pathDetails.includes(response.status);
|
19
|
-
}
|
20
|
-
function getParametrizedPathSuccess(method, path) {
|
21
|
-
var _a, _b, _c, _d;
|
22
|
-
const pathParts = path.split("/");
|
23
|
-
// Traverse list to match the longest candidate
|
24
|
-
// matchedLen: the length of candidate path
|
25
|
-
// matchedValue: the matched status code array
|
26
|
-
let matchedLen = -1, matchedValue = [];
|
27
|
-
// Iterate the responseMap to find a match
|
28
|
-
for (const [key, value] of Object.entries(responseMap)) {
|
29
|
-
// Extracting the path from the map key which is in format
|
30
|
-
// GET /path/foo
|
31
|
-
if (!key.startsWith(method)) {
|
32
|
-
continue;
|
33
|
-
}
|
34
|
-
const candidatePath = getPathFromMapKey(key);
|
35
|
-
// Get each part of the url path
|
36
|
-
const candidateParts = candidatePath.split("/");
|
37
|
-
// track if we have found a match to return the values found.
|
38
|
-
let found = true;
|
39
|
-
for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
|
40
|
-
if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) && ((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.indexOf("}")) !== -1) {
|
41
|
-
const start = candidateParts[i].indexOf("}") + 1, end = (_c = candidateParts[i]) === null || _c === void 0 ? void 0 : _c.length;
|
42
|
-
// If the current part of the candidate is a "template" part
|
43
|
-
// Try to use the suffix of pattern to match the path
|
44
|
-
// {guid} ==> $
|
45
|
-
// {guid}:export ==> :export$
|
46
|
-
const isMatched = new RegExp(`${(_d = candidateParts[i]) === null || _d === void 0 ? void 0 : _d.slice(start, end)}`).test(pathParts[j] || "");
|
47
|
-
if (!isMatched) {
|
48
|
-
found = false;
|
49
|
-
break;
|
50
|
-
}
|
51
|
-
continue;
|
52
|
-
}
|
53
|
-
// If the candidate part is not a template and
|
54
|
-
// the parts don't match mark the candidate as not found
|
55
|
-
// to move on with the next candidate path.
|
56
|
-
if (candidateParts[i] !== pathParts[j]) {
|
57
|
-
found = false;
|
58
|
-
break;
|
59
|
-
}
|
60
|
-
}
|
61
|
-
// We finished evaluating the current candidate parts
|
62
|
-
// Update the matched value if and only if we found the longer pattern
|
63
|
-
if (found && candidatePath.length > matchedLen) {
|
64
|
-
matchedLen = candidatePath.length;
|
65
|
-
matchedValue = value;
|
66
|
-
}
|
67
|
-
}
|
68
|
-
return matchedValue;
|
69
|
-
}
|
70
|
-
function getPathFromMapKey(mapKey) {
|
71
|
-
const pathStart = mapKey.indexOf("/");
|
72
|
-
return mapKey.slice(pathStart);
|
73
|
-
}
|
74
|
-
//# sourceMappingURL=isUnexpected.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"isUnexpected.js","sourceRoot":"","sources":["../../../../src/cadl-generated/rest/isUnexpected.ts"],"names":[],"mappings":"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","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n PublishCloudEvent200Response,\n PublishCloudEventDefaultResponse,\n ReceiveCloudEvents200Response,\n ReceiveCloudEventsDefaultResponse,\n AcknowledgeCloudEvents200Response,\n AcknowledgeCloudEventsDefaultResponse,\n ReleaseCloudEvents200Response,\n ReleaseCloudEventsDefaultResponse,\n RejectCloudEvents200Response,\n RejectCloudEventsDefaultResponse,\n} from \"./responses\";\n\nconst responseMap: Record<string, string[]> = {\n \"POST /topics/{topicName}:publish\": [\"200\"],\n \"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:receive\": [\"200\"],\n \"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:acknowledge\": [\"200\"],\n \"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:release\": [\"200\"],\n \"POST /topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:reject\": [\"200\"],\n};\n\nexport function isUnexpected(\n response: PublishCloudEvent200Response | PublishCloudEventDefaultResponse\n): response is PublishCloudEventDefaultResponse;\nexport function isUnexpected(\n response: ReceiveCloudEvents200Response | ReceiveCloudEventsDefaultResponse\n): response is ReceiveCloudEventsDefaultResponse;\nexport function isUnexpected(\n response: AcknowledgeCloudEvents200Response | AcknowledgeCloudEventsDefaultResponse\n): response is AcknowledgeCloudEventsDefaultResponse;\nexport function isUnexpected(\n response: ReleaseCloudEvents200Response | ReleaseCloudEventsDefaultResponse\n): response is ReleaseCloudEventsDefaultResponse;\nexport function isUnexpected(\n response: RejectCloudEvents200Response | RejectCloudEventsDefaultResponse\n): response is RejectCloudEventsDefaultResponse;\nexport function isUnexpected(\n response:\n | PublishCloudEvent200Response\n | PublishCloudEventDefaultResponse\n | ReceiveCloudEvents200Response\n | ReceiveCloudEventsDefaultResponse\n | AcknowledgeCloudEvents200Response\n | AcknowledgeCloudEventsDefaultResponse\n | ReleaseCloudEvents200Response\n | ReleaseCloudEventsDefaultResponse\n | RejectCloudEvents200Response\n | RejectCloudEventsDefaultResponse\n): response is\n | PublishCloudEventDefaultResponse\n | ReceiveCloudEventsDefaultResponse\n | AcknowledgeCloudEventsDefaultResponse\n | ReleaseCloudEventsDefaultResponse\n | RejectCloudEventsDefaultResponse {\n const lroOriginal = response.headers[\"x-ms-original-url\"];\n const url = new URL(lroOriginal ?? response.request.url);\n const method = response.request.method;\n let pathDetails = responseMap[`${method} ${url.pathname}`];\n if (!pathDetails) {\n pathDetails = getParametrizedPathSuccess(method, url.pathname);\n }\n return !pathDetails.includes(response.status);\n}\n\nfunction getParametrizedPathSuccess(method: string, path: string): string[] {\n const pathParts = path.split(\"/\");\n\n // Traverse list to match the longest candidate\n // matchedLen: the length of candidate path\n // matchedValue: the matched status code array\n let matchedLen = -1,\n matchedValue: string[] = [];\n\n // Iterate the responseMap to find a match\n for (const [key, value] of Object.entries(responseMap)) {\n // Extracting the path from the map key which is in format\n // GET /path/foo\n if (!key.startsWith(method)) {\n continue;\n }\n const candidatePath = getPathFromMapKey(key);\n // Get each part of the url path\n const candidateParts = candidatePath.split(\"/\");\n\n // track if we have found a match to return the values found.\n let found = true;\n for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {\n if (candidateParts[i]?.startsWith(\"{\") && candidateParts[i]?.indexOf(\"}\") !== -1) {\n const start = candidateParts[i]!.indexOf(\"}\") + 1,\n end = candidateParts[i]?.length;\n // If the current part of the candidate is a \"template\" part\n // Try to use the suffix of pattern to match the path\n // {guid} ==> $\n // {guid}:export ==> :export$\n const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(\n pathParts[j] || \"\"\n );\n\n if (!isMatched) {\n found = false;\n break;\n }\n continue;\n }\n\n // If the candidate part is not a template and\n // the parts don't match mark the candidate as not found\n // to move on with the next candidate path.\n if (candidateParts[i] !== pathParts[j]) {\n found = false;\n break;\n }\n }\n\n // We finished evaluating the current candidate parts\n // Update the matched value if and only if we found the longer pattern\n if (found && candidatePath.length > matchedLen) {\n matchedLen = candidatePath.length;\n matchedValue = value;\n }\n }\n\n return matchedValue;\n}\n\nfunction getPathFromMapKey(mapKey: string): string {\n const pathStart = mapKey.indexOf(\"/\");\n return mapKey.slice(pathStart);\n}\n"]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../src/cadl-generated/rest/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/** Properties of an event published to an Azure Messaging EventGrid Namespace topic using the CloudEvent 1.0 Schema. */\nexport interface CloudEvent extends Record<string, unknown> {\n /** An identifier for the event. The combination of id and source must be unique for each distinct event. */\n id: string;\n /** Identifies the context in which an event happened. The combination of id and source must be unique for each distinct event. */\n source: string;\n /** Event data specific to the event type. */\n data?: unknown;\n /** Event data specific to the event type, encoded as a base64 string. */\n data_base64?: Uint8Array;\n /** Type of event related to the originating occurrence. */\n type: string;\n /** The time (in UTC) the event was generated, in RFC3339 format. */\n time?: Date | string;\n /** The version of the CloudEvents specification which the event uses. */\n specversion: string;\n /** Identifies the schema that data adheres to. */\n dataschema?: string;\n /** Content type of data value. */\n datacontenttype?: string;\n /** This describes the subject of the event in the context of the event producer (identified by source). */\n subject?: string;\n}\n\n/** Array of lock token strings for the corresponding received Cloud Events to be acknowledged. */\nexport interface AcknowledgeOptions {\n /** String array of lock tokens. */\n lockTokens: string[];\n}\n\n/** Array of lock token strings for the corresponding received Cloud Events to be released. */\nexport interface ReleaseOptions {\n /** String array of lock tokens. */\n lockTokens: string[];\n}\n\n/** Array of lock token strings for the corresponding received Cloud Events to be rejected. */\nexport interface RejectOptions {\n /** String array of lock tokens. */\n lockTokens: string[];\n}\n"]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"outputModels.js","sourceRoot":"","sources":["../../../../src/cadl-generated/rest/outputModels.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/** Properties of an event published to an Azure Messaging EventGrid Namespace topic using the CloudEvent 1.0 Schema. */\nexport interface CloudEventOutput extends Record<string, unknown> {\n /** An identifier for the event. The combination of id and source must be unique for each distinct event. */\n id: string;\n /** Identifies the context in which an event happened. The combination of id and source must be unique for each distinct event. */\n source: string;\n /** Event data specific to the event type. */\n data?: any;\n /** Event data specific to the event type, encoded as a base64 string. */\n data_base64?: string;\n /** Type of event related to the originating occurrence. */\n type: string;\n /** The time (in UTC) the event was generated, in RFC3339 format. */\n time?: string;\n /** The version of the CloudEvents specification which the event uses. */\n specversion: string;\n /** Identifies the schema that data adheres to. */\n dataschema?: string;\n /** Content type of data value. */\n datacontenttype?: string;\n /** This describes the subject of the event in the context of the event producer (identified by source). */\n subject?: string;\n}\n\n/** The result of the Publish operation. */\nexport interface PublishResultOutput {}\n\n/** Details of the Receive operation response. */\nexport interface ReceiveResultOutput {\n /** Array of receive responses, one per cloud event. */\n value: Array<ReceiveDetailsOutput>;\n}\n\n/** Receive operation details per Cloud Event. */\nexport interface ReceiveDetailsOutput {\n /** The Event Broker details. */\n brokerProperties: BrokerPropertiesOutput;\n /** Cloud Event details. */\n event: CloudEventOutput;\n}\n\n/** Properties of the Event Broker operation. */\nexport interface BrokerPropertiesOutput {\n /** The token used to lock the event. */\n lockToken: string;\n /** The attempt count for delivering the event. */\n deliveryCount: number;\n}\n\n/** The result of the Acknowledge operation. */\nexport interface AcknowledgeResultOutput {\n /** Array of LockToken values for failed cloud events. Each LockToken includes the lock token value along with the related error information (namely, the error code and description). */\n failedLockTokens: Array<FailedLockTokenOutput>;\n /** Array of lock tokens values for the successfully acknowledged cloud events. */\n succeededLockTokens: string[];\n}\n\n/** Failed LockToken information. */\nexport interface FailedLockTokenOutput {\n /** LockToken value */\n lockToken: string;\n /** Error code related to the token. Example of such error codes are BadToken: which indicates the Token is not formatted correctly, TokenLost: which indicates that token is not found, and InternalServerError: For any internal server errors. */\n errorCode: string;\n /** Description of the token error. */\n errorDescription: string;\n}\n\n/** The result of the Release operation. */\nexport interface ReleaseResultOutput {\n /** Array of LockToken values for failed cloud events. Each LockToken includes the lock token value along with the related error information (namely, the error code and description). */\n failedLockTokens: Array<FailedLockTokenOutput>;\n /** Array of lock tokens values for the successfully released cloud events. */\n succeededLockTokens: string[];\n}\n\n/** The result of the Reject operation. */\nexport interface RejectResultOutput {\n /** Array of LockToken values for failed cloud events. Each LockToken includes the lock token value along with the related error information (namely, the error code and description). */\n failedLockTokens: Array<FailedLockTokenOutput>;\n /** Array of lock tokens values for the successfully rejected cloud events. */\n succeededLockTokens: string[];\n}\n"]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"parameters.js","sourceRoot":"","sources":["../../../../src/cadl-generated/rest/parameters.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { RequestParameters } from \"@azure-rest/core-client\";\nimport { CloudEvent, AcknowledgeOptions, ReleaseOptions, RejectOptions } from \"./models\";\n\nexport interface PublishCloudEventBodyParam {\n /** Single Cloud Event being published. */\n body: CloudEvent;\n}\n\nexport interface PublishCloudEventMediaTypesParam {\n /** content type */\n contentType: \"application/cloudevents+json; charset=utf-8\";\n}\n\nexport type PublishCloudEventParameters = PublishCloudEventMediaTypesParam &\n PublishCloudEventBodyParam &\n RequestParameters;\n\nexport interface PublishCloudEventsBodyParam {\n /** Array of Cloud Events being published. */\n body: Array<CloudEvent>;\n}\n\nexport interface PublishCloudEventsMediaTypesParam {\n /** content type */\n contentType: \"application/cloudevents-batch+json; charset=utf-8\";\n}\n\nexport type PublishCloudEventsParameters = PublishCloudEventsMediaTypesParam &\n PublishCloudEventsBodyParam &\n RequestParameters;\n\nexport interface ReceiveCloudEventsQueryParamProperties {\n /** Max Events count to be received. Minimum value is 1, while maximum value is 100 events. If not specified, the default value is 1. */\n maxEvents?: number;\n /** 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. */\n maxWaitTime?: number;\n}\n\nexport interface ReceiveCloudEventsQueryParam {\n queryParameters?: ReceiveCloudEventsQueryParamProperties;\n}\n\nexport type ReceiveCloudEventsParameters = ReceiveCloudEventsQueryParam & RequestParameters;\n\nexport interface AcknowledgeCloudEventsBodyParam {\n /** AcknowledgeOptions. */\n body: AcknowledgeOptions;\n}\n\nexport interface AcknowledgeCloudEventsMediaTypesParam {\n /** content type */\n contentType: \"application/json; charset=utf-8\";\n}\n\nexport type AcknowledgeCloudEventsParameters = AcknowledgeCloudEventsMediaTypesParam &\n AcknowledgeCloudEventsBodyParam &\n RequestParameters;\n\nexport interface ReleaseCloudEventsBodyParam {\n /** ReleaseOptions */\n body: ReleaseOptions;\n}\n\nexport interface ReleaseCloudEventsMediaTypesParam {\n /** content type */\n contentType: \"application/json; charset=utf-8\";\n}\n\nexport type ReleaseCloudEventsParameters = ReleaseCloudEventsMediaTypesParam &\n ReleaseCloudEventsBodyParam &\n RequestParameters;\n\nexport interface RejectCloudEventsBodyParam {\n /** RejectOptions */\n body: RejectOptions;\n}\n\nexport interface RejectCloudEventsMediaTypesParam {\n /** content type */\n contentType: \"application/json; charset=utf-8\";\n}\n\nexport type RejectCloudEventsParameters = RejectCloudEventsMediaTypesParam &\n RejectCloudEventsBodyParam &\n RequestParameters;\n"]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../../../../src/cadl-generated/rest/responses.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { RawHttpHeaders } from \"@azure/core-rest-pipeline\";\nimport { HttpResponse, ErrorResponse } from \"@azure-rest/core-client\";\nimport {\n PublishResultOutput,\n ReceiveResultOutput,\n AcknowledgeResultOutput,\n ReleaseResultOutput,\n RejectResultOutput,\n} from \"./outputModels\";\n\n/** The request has succeeded. */\nexport interface PublishCloudEvent200Response extends HttpResponse {\n status: \"200\";\n body: PublishResultOutput;\n}\n\nexport interface PublishCloudEventDefaultHeaders {\n /** String error code indicating what went wrong. */\n \"x-ms-error-code\"?: string;\n}\n\nexport interface PublishCloudEventDefaultResponse extends HttpResponse {\n status: string;\n body: ErrorResponse;\n headers: RawHttpHeaders & PublishCloudEventDefaultHeaders;\n}\n\n/** The request has succeeded. */\nexport interface PublishCloudEvents200Response extends HttpResponse {\n status: \"200\";\n body: PublishResultOutput;\n}\n\nexport interface PublishCloudEventsDefaultHeaders {\n /** String error code indicating what went wrong. */\n \"x-ms-error-code\"?: string;\n}\n\nexport interface PublishCloudEventsDefaultResponse extends HttpResponse {\n status: string;\n body: ErrorResponse;\n headers: RawHttpHeaders & PublishCloudEventsDefaultHeaders;\n}\n\n/** The request has succeeded. */\nexport interface ReceiveCloudEvents200Response extends HttpResponse {\n status: \"200\";\n body: ReceiveResultOutput;\n}\n\nexport interface ReceiveCloudEventsDefaultHeaders {\n /** String error code indicating what went wrong. */\n \"x-ms-error-code\"?: string;\n}\n\nexport interface ReceiveCloudEventsDefaultResponse extends HttpResponse {\n status: string;\n body: ErrorResponse;\n headers: RawHttpHeaders & ReceiveCloudEventsDefaultHeaders;\n}\n\n/** The request has succeeded. */\nexport interface AcknowledgeCloudEvents200Response extends HttpResponse {\n status: \"200\";\n body: AcknowledgeResultOutput;\n}\n\nexport interface AcknowledgeCloudEventsDefaultHeaders {\n /** String error code indicating what went wrong. */\n \"x-ms-error-code\"?: string;\n}\n\nexport interface AcknowledgeCloudEventsDefaultResponse extends HttpResponse {\n status: string;\n body: ErrorResponse;\n headers: RawHttpHeaders & AcknowledgeCloudEventsDefaultHeaders;\n}\n\n/** The request has succeeded. */\nexport interface ReleaseCloudEvents200Response extends HttpResponse {\n status: \"200\";\n body: ReleaseResultOutput;\n}\n\nexport interface ReleaseCloudEventsDefaultHeaders {\n /** String error code indicating what went wrong. */\n \"x-ms-error-code\"?: string;\n}\n\nexport interface ReleaseCloudEventsDefaultResponse extends HttpResponse {\n status: string;\n body: ErrorResponse;\n headers: RawHttpHeaders & ReleaseCloudEventsDefaultHeaders;\n}\n\n/** The request has succeeded. */\nexport interface RejectCloudEvents200Response extends HttpResponse {\n status: \"200\";\n body: RejectResultOutput;\n}\n\nexport interface RejectCloudEventsDefaultHeaders {\n /** String error code indicating what went wrong. */\n \"x-ms-error-code\"?: string;\n}\n\nexport interface RejectCloudEventsDefaultResponse extends HttpResponse {\n status: string;\n body: ErrorResponse;\n headers: RawHttpHeaders & RejectCloudEventsDefaultHeaders;\n}\n"]}
|
@@ -1,128 +0,0 @@
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
2
|
-
// Licensed under the MIT license.
|
3
|
-
import { cloudEventReservedPropertyNames } from "./models";
|
4
|
-
import { v4 as uuidv4 } from "uuid";
|
5
|
-
import { EventGridClient as EventGridClientGenerated } from "./cadl-generated/EventGridClient";
|
6
|
-
/**
|
7
|
-
* Event Grid Client
|
8
|
-
*/
|
9
|
-
export class EventGridClient {
|
10
|
-
/** Azure Messaging EventGrid Client */
|
11
|
-
constructor(endpoint, credential, options = {}) {
|
12
|
-
credential.update(`SharedAccessKey ${credential.key}`);
|
13
|
-
this._client = new EventGridClientGenerated(endpoint, credential, options);
|
14
|
-
}
|
15
|
-
/**
|
16
|
-
* Publish Single Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200
|
17
|
-
* status code with an empty JSON object in response. Otherwise, the server can return various error codes.
|
18
|
-
* For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
|
19
|
-
* is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
|
20
|
-
* internal server error.
|
21
|
-
*
|
22
|
-
* @param event - Event to publish
|
23
|
-
* @param topicName - Topic to publish the event
|
24
|
-
* @param options - Options to publish
|
25
|
-
*
|
26
|
-
*/
|
27
|
-
publishCloudEvent(event, topicName, options = { requestOptions: {} }) {
|
28
|
-
return this._client.publishCloudEvent(convertCloudEventToModelType(event), topicName, options);
|
29
|
-
}
|
30
|
-
/**
|
31
|
-
* Publish Batch Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200
|
32
|
-
* status code with an empty JSON object in response. Otherwise, the server can return various error codes.
|
33
|
-
* For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message
|
34
|
-
* is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for
|
35
|
-
* internal server error.
|
36
|
-
*
|
37
|
-
* @param events - Events to publish
|
38
|
-
* @param topicName - Topic to publish the event
|
39
|
-
* @param options - Options to publish
|
40
|
-
*
|
41
|
-
*/
|
42
|
-
publishCloudEvents(events, topicName, options = { requestOptions: {} }) {
|
43
|
-
const eventsWireModel = [];
|
44
|
-
for (const individualevent of events) {
|
45
|
-
eventsWireModel.concat(convertCloudEventToModelType(individualevent));
|
46
|
-
}
|
47
|
-
return this._client.publishCloudEvents(eventsWireModel, topicName, options);
|
48
|
-
}
|
49
|
-
/**
|
50
|
-
* Receive Batch of Cloud Events from the Event Subscription.
|
51
|
-
*
|
52
|
-
* @param topicName - Topic to receive
|
53
|
-
* @param eventSubscriptionName - Name of the Event Subscription
|
54
|
-
* @param options - Options to receive
|
55
|
-
*
|
56
|
-
*/
|
57
|
-
receiveCloudEvents(topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
58
|
-
return this._client.receiveCloudEvents(topicName, eventSubscriptionName, options);
|
59
|
-
}
|
60
|
-
/**
|
61
|
-
* Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if at least one
|
62
|
-
* event is successfully acknowledged. The response body will include the set of successfully acknowledged
|
63
|
-
* lockTokens, along with other failed lockTokens with their corresponding error information. Successfully
|
64
|
-
* acknowledged events will no longer be available to any consumer.
|
65
|
-
*
|
66
|
-
* @param lockTokens - Lock Tokens
|
67
|
-
* @param topicName - Topic Name
|
68
|
-
* @param eventSubscriptionName - Name of the Event Subscription
|
69
|
-
* @param options - Options to Acknowledge
|
70
|
-
*
|
71
|
-
*/
|
72
|
-
acknowledgeCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
73
|
-
return this._client.acknowledgeCloudEvents(lockTokens, topicName, eventSubscriptionName, options);
|
74
|
-
}
|
75
|
-
/**
|
76
|
-
* Release batch of Cloud Events. The server responds with an HTTP 200 status code if at least one event is
|
77
|
-
* successfully released. The response body will include the set of successfully released lockTokens, along
|
78
|
-
* with other failed lockTokens with their corresponding error information.
|
79
|
-
*
|
80
|
-
* @param lockTokens - Lock Tokens
|
81
|
-
* @param topicName - Topic Name
|
82
|
-
* @param eventSubscriptionName - Name of the Event Subscription
|
83
|
-
* @param options - Options to release
|
84
|
-
*
|
85
|
-
*/
|
86
|
-
releaseCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
87
|
-
return this._client.releaseCloudEvents(lockTokens, topicName, eventSubscriptionName, options);
|
88
|
-
}
|
89
|
-
/**
|
90
|
-
* Reject batch of Cloud Events.
|
91
|
-
*
|
92
|
-
* @param lockTokens - Lock Tokens
|
93
|
-
* @param topicName - Topic Name
|
94
|
-
* @param eventSubscriptionName - Name of the Event Subscription
|
95
|
-
* @param options - Options to reject
|
96
|
-
*
|
97
|
-
*/
|
98
|
-
rejectCloudEvents(lockTokens, topicName, eventSubscriptionName, options = { requestOptions: {} }) {
|
99
|
-
return this._client.rejectCloudEvents(lockTokens, topicName, eventSubscriptionName, options);
|
100
|
-
}
|
101
|
-
}
|
102
|
-
export function convertCloudEventToModelType(event) {
|
103
|
-
var _a, _b, _c, _d, _e;
|
104
|
-
if (event.extensionAttributes) {
|
105
|
-
for (const propName in event.extensionAttributes) {
|
106
|
-
// 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"
|
107
|
-
// they also can not match an existing defined property name.
|
108
|
-
if (!/^[a-z0-9]*$/.test(propName) ||
|
109
|
-
cloudEventReservedPropertyNames.indexOf(propName) !== -1) {
|
110
|
-
throw new Error(`invalid extension attribute name: ${propName}`);
|
111
|
-
}
|
112
|
-
}
|
113
|
-
}
|
114
|
-
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 : uuidv4(), 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 : []));
|
115
|
-
if (event.data instanceof Uint8Array) {
|
116
|
-
if (!event.datacontenttype) {
|
117
|
-
throw new Error("a data content type must be provided when sending an event with binary data");
|
118
|
-
}
|
119
|
-
converted.datacontenttype = event.datacontenttype;
|
120
|
-
converted.data_base64 = event.data;
|
121
|
-
}
|
122
|
-
else {
|
123
|
-
converted.datacontenttype = (_e = event.datacontenttype) !== null && _e !== void 0 ? _e : "application/json";
|
124
|
-
converted.data = event.data;
|
125
|
-
}
|
126
|
-
return converted;
|
127
|
-
}
|
128
|
-
//# sourceMappingURL=eventGridClientV2.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"eventGridClientV2.js","sourceRoot":"","sources":["../../src/eventGridClientV2.ts"],"names":[],"mappings":"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","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AzureKeyCredential } from \"@azure/core-auth\";\nimport { ClientOptions } from \"./cadl-generated/common/interfaces\";\nimport {\n ReceiveResult,\n AcknowledgeResult,\n ReleaseResult,\n RejectResult,\n PublishCloudEventOptions,\n PublishCloudEventsOptions,\n ReceiveCloudEventsOptions,\n AcknowledgeCloudEventsOptions,\n ReleaseCloudEventsOptions,\n RejectCloudEventsOptions,\n PublishResultOutput,\n} from \"./cadl-generated/api/index\";\nimport { CloudEvent, cloudEventReservedPropertyNames } from \"./models\";\nimport { v4 as uuidv4 } from \"uuid\";\nimport { CloudEvent as CloudEventWireModel } from \"./cadl-generated/rest/index\";\nimport { EventGridClient as EventGridClientGenerated } from \"./cadl-generated/EventGridClient\";\n\n/**\n * Event Grid Client\n */\nexport class EventGridClient {\n private _client: EventGridClientGenerated;\n\n /** Azure Messaging EventGrid Client */\n constructor(endpoint: string, credential: AzureKeyCredential, options: ClientOptions = {}) {\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 publishCloudEvent<T>(\n event: CloudEvent<T>,\n topicName: string,\n options: PublishCloudEventOptions = { requestOptions: {} }\n ): Promise<PublishResultOutput> {\n return this._client.publishCloudEvent(convertCloudEventToModelType(event), topicName, options);\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 publishCloudEvents<T>(\n events: CloudEvent<T>[],\n topicName: string,\n options: PublishCloudEventsOptions = { requestOptions: {} }\n ): Promise<PublishResultOutput> {\n const eventsWireModel: Array<CloudEventWireModel> = [];\n for (const individualevent of events) {\n eventsWireModel.concat(convertCloudEventToModelType(individualevent));\n }\n return this._client.publishCloudEvents(eventsWireModel, topicName, 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<T>(\n topicName: string,\n eventSubscriptionName: string,\n options: ReceiveCloudEventsOptions = { requestOptions: {} }\n ): Promise<ReceiveResult<T>> {\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 lockTokens,\n topicName,\n eventSubscriptionName,\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(lockTokens, topicName, eventSubscriptionName, options);\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(lockTokens, topicName, eventSubscriptionName, options);\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 ?? uuidv4(),\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.data_base64 = event.data;\n } else {\n converted.datacontenttype = event.datacontenttype ?? \"application/json\";\n converted.data = event.data;\n }\n\n return converted;\n}\n"]}
|