@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/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Microsoft
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
# Azure Event Grid Namespaces client library for JavaScript
|
2
|
+
|
3
|
+
[Azure Event Grid](https://azure.microsoft.com/services/event-grid/) is a cloud-based service that provides reliable event delivery at massive scale.
|
4
|
+
|
5
|
+
Use the client library to Send events to Event Grid Namespaces
|
6
|
+
|
7
|
+
Key links:
|
8
|
+
|
9
|
+
- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/eventgrid/eventgrid/)
|
10
|
+
- [Package (NPM)](https://www.npmjs.com/package/@azure/eventgrid-namespaces)
|
11
|
+
- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/eventgrid/)
|
12
|
+
- [Product documentation](https://docs.microsoft.com/azure/event-grid/)
|
13
|
+
- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/eventgrid/eventgrid/samples)
|
14
|
+
|
15
|
+
## Getting started
|
16
|
+
|
17
|
+
### Currently supported environments
|
18
|
+
|
19
|
+
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
|
20
|
+
- Latest versions of Safari, Chrome, Edge, and Firefox.
|
21
|
+
|
22
|
+
See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.
|
23
|
+
|
24
|
+
### Prerequisites
|
25
|
+
|
26
|
+
- An [Azure subscription][azure_sub].
|
27
|
+
- An existing [Event Grid][event_grid] Topic or Domain. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].
|
28
|
+
|
29
|
+
If you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:
|
30
|
+
|
31
|
+
#### Create an Event Grid Topic
|
32
|
+
|
33
|
+
```bash
|
34
|
+
az eventgrid topic create --location <location> --resource-group <your-resource-group-name> --name <your-resource-name>
|
35
|
+
```
|
36
|
+
|
37
|
+
#### Create an Event Grid Domain
|
38
|
+
|
39
|
+
```bash
|
40
|
+
az eventgrid domain create --location <location> --resource-group <your-resource-group-name> --name <your-resource-name>
|
41
|
+
```
|
42
|
+
|
43
|
+
### Install the `@azure/eventgrid-namespaces` package
|
44
|
+
|
45
|
+
Install the Azure Event Grid Namespaces client library for JavaScript with `npm`:
|
46
|
+
|
47
|
+
```bash
|
48
|
+
npm install @azure/eventgrid-namespaces
|
49
|
+
```
|
50
|
+
|
51
|
+
### Create and authenticate a `EventGridNamespacesClient`
|
52
|
+
|
53
|
+
To create a client object to access the Event Grid Namespaces API, you will need the `endpoint` of your Event Grid topic and a `credential`. The Event Grid client can use an Access Key.
|
54
|
+
|
55
|
+
You can find the endpoint for your Event Grid topic either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:
|
56
|
+
|
57
|
+
```bash
|
58
|
+
az eventgrid topic show --name <your-resource-name> --resource-group <your-resource-group-name> --query "endpoint"
|
59
|
+
```
|
60
|
+
|
61
|
+
#### Using an Access Key
|
62
|
+
|
63
|
+
Use the [Azure Portal][azure_portal] to browse to your Event Grid resource and retrieve an Access Key, or use the [Azure CLI][azure_cli] snippet below:
|
64
|
+
|
65
|
+
```bash
|
66
|
+
az eventgrid topic key list --resource-group <your-resource-group-name> --name <your-event-grid-topic-name>
|
67
|
+
```
|
68
|
+
|
69
|
+
Once you have an API key and endpoint, you can use the `AzureKeyCredential` class to authenticate the client as follows:
|
70
|
+
|
71
|
+
```js
|
72
|
+
const { EventGridNamespacesClient, AzureKeyCredential } = require("@azure/eventgrid-namespaces");
|
73
|
+
|
74
|
+
const client = new EventGridNamespacesClient(
|
75
|
+
"<endpoint>",
|
76
|
+
new AzureKeyCredential("<Access Key>")
|
77
|
+
);
|
78
|
+
```
|
79
|
+
|
80
|
+
Azure EventGrid provides integration with Azure Active Directory (Azure AD) for identity-based authentication of requests. With Azure AD, you can use role-based access control (RBAC) to grant access to your Azure Event Grid resources to users, groups, or applications.
|
81
|
+
|
82
|
+
To send events to a topic or domain with a `TokenCredential`, the authenticated identity should have the "EventGrid Data Sender" role assigned.
|
83
|
+
|
84
|
+
With the `@azure/identity` package, you can seamlessly authorize requests in both development and production environments. To learn more about Azure Active Directory, see the [`@azure/identity` README](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/identity/identity/README.md).
|
85
|
+
|
86
|
+
For example, use can use `DefaultAzureCredential` to construct a client which will authenticate using Azure Active Directory:
|
87
|
+
|
88
|
+
```js
|
89
|
+
const { EventGridNamespacesClient } = require("@azure/eventgrid-namespaces");
|
90
|
+
const { DefaultAzureCredential } = require("@azure/identity");
|
91
|
+
|
92
|
+
const client = new EventGridNamespacesClient(
|
93
|
+
"<endpoint>",
|
94
|
+
new DefaultAzureCredential()
|
95
|
+
);
|
96
|
+
```
|
97
|
+
|
98
|
+
## Key concepts
|
99
|
+
|
100
|
+
### EventGridNamespacesClient
|
101
|
+
|
102
|
+
`EventGridNamespacesClient` is used sending events to an Event Grid. You can initialize it as:
|
103
|
+
|
104
|
+
```js
|
105
|
+
const client = new EventGridNamespacesClient(
|
106
|
+
"<endpoint>",
|
107
|
+
new AzureKeyCredential("<API Key>")
|
108
|
+
);
|
109
|
+
```
|
110
|
+
|
111
|
+
### Distributed Tracing and Cloud Events
|
112
|
+
|
113
|
+
This library supports distributed tracing using [`@azure/core-tracing`][azure-core-tracing-github]. When using distributed tracing, this library will create a span during a `send` operation. In addition, when sending events using the Cloud Events 1.0 schema, the SDK will add distributed tracing metadata to the events using the [Distributed Tracing extension][cloud-events-distributed-tracing-spec]. The values for the `traceparent` and `tracestate` extension properties correspond to the `traceparent` and `tracestate` headers from the HTTP request which sends the events. If an event already has a `traceparent` extension property it is not updated.
|
114
|
+
|
115
|
+
### Event Grid on Kubernetes
|
116
|
+
|
117
|
+
This library has been tested and validated on [Kubernetes using Azure Arc][eventgrid-on-kubernetes-using-azure-arc].
|
118
|
+
|
119
|
+
## Examples
|
120
|
+
|
121
|
+
### Publish an Event to an Event Grid Topic
|
122
|
+
|
123
|
+
```js
|
124
|
+
const { EventGridNamespacesClient, AzureKeyCredential } = require("@azure/eventgrid-namespaces");
|
125
|
+
|
126
|
+
const client = new EventGridNamespacesClient(
|
127
|
+
"<endpoint>",
|
128
|
+
new AzureKeyCredential("<API key>")
|
129
|
+
);
|
130
|
+
|
131
|
+
const cloudEvent: CloudEvent = {
|
132
|
+
type: "example",
|
133
|
+
source: "https://example.com",
|
134
|
+
id: `singleEventIdV210001`,
|
135
|
+
time: new Date(),
|
136
|
+
data: {
|
137
|
+
resourceUri: "https://dummyurl.com",
|
138
|
+
},
|
139
|
+
specversion: "1.0",
|
140
|
+
};
|
141
|
+
// Publish the Cloud Event
|
142
|
+
await client.publishCloudEvent(cloudEvent, topicName);
|
143
|
+
```
|
144
|
+
|
145
|
+
## Troubleshooting
|
146
|
+
|
147
|
+
### Logging
|
148
|
+
|
149
|
+
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
|
150
|
+
|
151
|
+
```javascript
|
152
|
+
const { setLogLevel } = require("@azure/logger");
|
153
|
+
|
154
|
+
setLogLevel("info");
|
155
|
+
```
|
156
|
+
|
157
|
+
For more detailed instructions on how to enable the logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).
|
158
|
+
|
159
|
+
## Next steps
|
160
|
+
|
161
|
+
Please take a look at the
|
162
|
+
[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/eventgrid/eventgrid/samples)
|
163
|
+
directory for detailed examples on how to use this library.
|
164
|
+
|
165
|
+
## Contributing
|
166
|
+
|
167
|
+
If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test the code.
|
168
|
+
|
169
|
+
## Related projects
|
170
|
+
|
171
|
+
- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)
|
172
|
+
|
173
|
+

|
174
|
+
|
175
|
+
[azure_cli]: https://docs.microsoft.com/cli/azure
|
176
|
+
[azure_sub]: https://azure.microsoft.com/free/
|
177
|
+
[event_grid]: https://docs.microsoft.com/azure/event-grid
|
178
|
+
[azure_portal]: https://portal.azure.com
|
179
|
+
[azure-core-tracing-github]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/core-tracing
|
180
|
+
[cloud-events-distributed-tracing-spec]: https://github.com/cloudevents/spec/blob/v1.0.1/extensions/distributed-tracing.md
|
181
|
+
[eventgrid-on-kubernetes-using-azure-arc]: https://docs.microsoft.com/azure/event-grid/kubernetes/
|