@webda/azure 0.0.0-stage → 4.0.0-beta.14

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.
Files changed (68) hide show
  1. package/LICENSE +166 -0
  2. package/README.md +248 -2
  3. package/lib/auth.d.ts +36 -0
  4. package/lib/auth.d.ts.map +1 -0
  5. package/lib/auth.js +70 -0
  6. package/lib/auth.js.map +1 -0
  7. package/lib/deployers/arm.service.d.ts +177 -0
  8. package/lib/deployers/arm.service.d.ts.map +1 -0
  9. package/lib/deployers/arm.service.js +307 -0
  10. package/lib/deployers/arm.service.js.map +1 -0
  11. package/lib/deployers/containerapps.service.d.ts +186 -0
  12. package/lib/deployers/containerapps.service.d.ts.map +1 -0
  13. package/lib/deployers/containerapps.service.js +482 -0
  14. package/lib/deployers/containerapps.service.js.map +1 -0
  15. package/lib/deployers/functions-entrypoint.d.ts +60 -0
  16. package/lib/deployers/functions-entrypoint.d.ts.map +1 -0
  17. package/lib/deployers/functions-entrypoint.js +78 -0
  18. package/lib/deployers/functions-entrypoint.js.map +1 -0
  19. package/lib/deployers/functions.service.d.ts +96 -0
  20. package/lib/deployers/functions.service.d.ts.map +1 -0
  21. package/lib/deployers/functions.service.js +340 -0
  22. package/lib/deployers/functions.service.js.map +1 -0
  23. package/lib/deployers/functionspackager.service.d.ts +82 -0
  24. package/lib/deployers/functionspackager.service.d.ts.map +1 -0
  25. package/lib/deployers/functionspackager.service.js +157 -0
  26. package/lib/deployers/functionspackager.service.js.map +1 -0
  27. package/lib/index.d.ts +15 -0
  28. package/lib/index.d.ts.map +1 -0
  29. package/lib/index.js +18 -0
  30. package/lib/index.js.map +1 -0
  31. package/lib/services/azure-parameters.d.ts +56 -0
  32. package/lib/services/azure-parameters.d.ts.map +1 -0
  33. package/lib/services/azure-parameters.js +43 -0
  34. package/lib/services/azure-parameters.js.map +1 -0
  35. package/lib/services/blob.service.d.ts +196 -0
  36. package/lib/services/blob.service.d.ts.map +1 -0
  37. package/lib/services/blob.service.js +450 -0
  38. package/lib/services/blob.service.js.map +1 -0
  39. package/lib/services/contributors.d.ts +50 -0
  40. package/lib/services/contributors.d.ts.map +1 -0
  41. package/lib/services/contributors.js +2 -0
  42. package/lib/services/contributors.js.map +1 -0
  43. package/lib/services/cosmos.service.d.ts +253 -0
  44. package/lib/services/cosmos.service.d.ts.map +1 -0
  45. package/lib/services/cosmos.service.js +566 -0
  46. package/lib/services/cosmos.service.js.map +1 -0
  47. package/lib/services/functionserver.service.d.ts +51 -0
  48. package/lib/services/functionserver.service.d.ts.map +1 -0
  49. package/lib/services/functionserver.service.js +232 -0
  50. package/lib/services/functionserver.service.js.map +1 -0
  51. package/lib/services/keyvault.service.d.ts +106 -0
  52. package/lib/services/keyvault.service.d.ts.map +1 -0
  53. package/lib/services/keyvault.service.js +228 -0
  54. package/lib/services/keyvault.service.js.map +1 -0
  55. package/lib/services/monitorlogger.service.d.ts +117 -0
  56. package/lib/services/monitorlogger.service.d.ts.map +1 -0
  57. package/lib/services/monitorlogger.service.js +149 -0
  58. package/lib/services/monitorlogger.service.js.map +1 -0
  59. package/lib/services/servicebus.service.d.ts +224 -0
  60. package/lib/services/servicebus.service.d.ts.map +1 -0
  61. package/lib/services/servicebus.service.js +351 -0
  62. package/lib/services/servicebus.service.js.map +1 -0
  63. package/lib/template.d.ts +68 -0
  64. package/lib/template.d.ts.map +1 -0
  65. package/lib/template.js +74 -0
  66. package/lib/template.js.map +1 -0
  67. package/package.json +77 -3
  68. package/webda.module.json +1891 -0
package/LICENSE ADDED
@@ -0,0 +1,166 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
166
+
package/README.md CHANGED
@@ -1,3 +1,249 @@
1
- # Temporary Holding Version
1
+ # @webda/azure module
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ This module is part of Webda Application Framework that allows you to quickly develop applications with all modern prerequisites: Security, Extensibility, GraphQL, REST, CloudNative [https://webda.io](https://webda.io)
4
+
5
+ <img src="https://webda.io/img/webda.svg" width="128" />
6
+
7
+ ![CI](https://github.com/loopingz/webda.io/workflows/CI/badge.svg)
8
+
9
+ [![Join the chat at https://gitter.im/loopingz/webda](https://badges.gitter.im/loopingz/webda.svg)](https://gitter.im/loopingz/webda?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
10
+ [![codecov](https://codecov.io/gh/loopingz/webda.io/branch/main/graph/badge.svg?token=8N9DNM3K3O)](https://codecov.io/gh/loopingz/webda.io)
11
+ [![SonarCloud.io](https://sonarcloud.io/api/project_badges/measure?project=loopingz_webda.io&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=loopingz_webda.io)
12
+ ![CodeQL](https://github.com/loopingz/webda.io/workflows/CodeQL/badge.svg)
13
+
14
+ <!-- README_HEADER -->
15
+
16
+ Azure Blob storage, Cosmos DB, Service Bus, Key Vault, Monitor logging, Container Apps and Functions integrations for Webda.
17
+
18
+ ## Install
19
+
20
+ ```sh
21
+ pnpm add @webda/azure
22
+ ```
23
+
24
+ ## Credentials
25
+
26
+ `getAzureCredential(params)` returns an Azure SDK `TokenCredential`. Complete service-principal parameters select `ClientSecretCredential`; other configurations use `DefaultAzureCredential`, including Azure CLI, managed identity and workload identity authentication.
27
+
28
+ ```typescript
29
+ import { getAzureCredential, loadAzureParameters } from "@webda/azure";
30
+
31
+ const params = loadAzureParameters({ endpoint: "http://127.0.0.1:10000/devstoreaccount1" });
32
+ const credential = getAzureCredential(params);
33
+ // Pass credential to your Azure SDK client. Use params.endpoint for the service's emulator endpoint.
34
+ ```
35
+
36
+ | Parameter | Environment fallback | Purpose |
37
+ | ---------------- | ----------------------- | ----------------------------------------------------- |
38
+ | `tenantId` | `AZURE_TENANT_ID` | Microsoft Entra tenant |
39
+ | `clientId` | `AZURE_CLIENT_ID` | Service principal or user-assigned identity client |
40
+ | `clientSecret` | `AZURE_CLIENT_SECRET` | Service principal secret (`string` or `SecretString`) |
41
+ | `subscriptionId` | `AZURE_SUBSCRIPTION_ID` | Resource subscription |
42
+ | `endpoint` | — | Service-specific endpoint, such as Azurite |
43
+
44
+ Service parameter classes implementing `AzureServiceParameters` can call `loadAzureParameters(this)` from `load()`. It fills absent fields and returns the same object, preserving explicit values and encrypted `SecretString` instances. `getAzureCredential` resolves defaults in a copy, so it preserves its input. It forwards the configured tenant/client to the default chain's managed and workload identity options; the SDK also honors its standard authentication environment variables.
45
+
46
+ Use managed or workload identity for deployed applications, or `az login` for development. To configure a service principal, supply all three of `tenantId`, `clientId` and `clientSecret`. Secrets decrypted by Webda remain wrapped until the SDK constructor needs their plain value. Clear-text secrets emit the existing `SecretString.from` warning, which names the field and never logs its value. Creating a credential performs no token request; the SDK acquires a token when a client needs one.
47
+
48
+ See Microsoft's [Azure Identity documentation](https://learn.microsoft.com/en-us/javascript/api/overview/azure/identity-readme?view=azure-node-latest) for the SDK's credential chain and environment variables.
49
+
50
+ ## Resource contributions
51
+
52
+ Services implement `AzureContributor` to describe their ARM resources, container environment, outputs and managed-identity roles. Deployers merge the returned contribution and grant its roles to the application's managed identity.
53
+
54
+ ```typescript
55
+ import type { AzureContributor, AzureDeployerInfo, AzureResourceContribution } from "@webda/azure";
56
+
57
+ class StorageContribution implements AzureContributor {
58
+ getAzureResources(deployer: AzureDeployerInfo): AzureResourceContribution {
59
+ const account = "myappstorage";
60
+ const scope = `[resourceId('Microsoft.Storage/storageAccounts', '${account}')]`;
61
+ return {
62
+ resources: [
63
+ {
64
+ type: "Microsoft.Storage/storageAccounts",
65
+ apiVersion: "2023-05-01",
66
+ name: account,
67
+ location: deployer.resources.location,
68
+ tags: deployer.getDefaultTags(),
69
+ sku: { name: "Standard_LRS" },
70
+ kind: "StorageV2"
71
+ }
72
+ ],
73
+ env: { STORAGE_ACCOUNT: account, STORAGE_KEY: { secretRef: "storage-key" } },
74
+ outputs: { storageAccountId: { type: "string", value: scope } },
75
+ roleAssignments: [
76
+ {
77
+ roleDefinitionId:
78
+ "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'ba92f5b4-2d11-453d-a403-e96b0029c9fe')]",
79
+ scope
80
+ }
81
+ ]
82
+ };
83
+ }
84
+ }
85
+ ```
86
+
87
+ `AzureDeployerInfo` exposes `resources.resourceGroup`, `resources.location`, `resources.subscriptionId`, `getDefaultTags(tags?)` and `getAppPrincipalId()`. Contributors describe resources synchronously; the deployer performs Azure operations. Environment secrets use `{ secretRef }` references to secrets supplied by the deployer.
88
+
89
+ ## Runtime services
90
+
91
+ Declare these services in `webda.config.jsonc`. All use the credentials above and create SDK clients during initialization.
92
+
93
+ ```jsonc
94
+ {
95
+ "services": {
96
+ "Files": {
97
+ "type": "Webda/AzureBlobBinary",
98
+ "account": "myappstorage",
99
+ "container": "files",
100
+ "models": { "MyApp/Document": ["attachments"] }
101
+ },
102
+ "Database": {
103
+ "type": "Webda/CosmosStore",
104
+ "endpoint": "https://myapp.documents.azure.com",
105
+ "database": "webda",
106
+ "container": "models",
107
+ "models": ["MyApp/Document"]
108
+ },
109
+ "Work": { "type": "Webda/ServiceBusQueue", "namespace": "myapp.servicebus.windows.net", "queue": "work" },
110
+ "Events": {
111
+ "type": "Webda/ServiceBusPubSub",
112
+ "namespace": "myapp.servicebus.windows.net",
113
+ "topic": "events",
114
+ "subscription": "api"
115
+ },
116
+ "Vault": { "type": "Webda/AzureKeyVault", "vaultUrl": "https://myapp.vault.azure.net" }
117
+ }
118
+ }
119
+ ```
120
+
121
+ ### Blob binaries and content
122
+
123
+ `AzureBlobBinary` implements `CloudBinary` and registers `azure://container/key` and `azblob://container/key` content URLs. `getContent`, `putContent`, `headContent` and `deleteContent` support streaming, byte ranges, metadata and conditional creation. `prefix` scopes binary keys. `connectionString` accepts a `SecretString`; `endpoint` overrides the configured storage endpoint. `createContainer` defaults to `false`.
124
+
125
+ Files use `<prefix>/<md5>/data` and exact model/attribute/owner markers. A direct upload has three steps:
126
+
127
+ 1. Send the normal binary challenge (`hash`, `challenge`, `size`, name and MIME type). A verified matching proof attaches an existing file immediately.
128
+ 2. PUT bytes to the returned SAS URL with **all returned headers**, including `x-ms-blob-type: BlockBlob` and `Content-MD5`. This SAS only creates an isolated staging blob; it cannot replace shared content.
129
+ 3. POST the binary's `complete/{hash}` action. Webda checks the staged bytes, size and proof before publishing and attaching the file. An unfinished or invalid upload never grants access to existing data.
130
+
131
+ SAS URLs use a shared key when the connection string contains one, or an Entra user delegation key otherwise. The contributor grants Blob Data Contributor on the container and Blob Delegator on the account for signing. Signed URLs and proof values are never logged. `urlExpiry` controls SAS lifetime; `pendingTimeout` limits completion time. Configure a storage lifecycle policy to expire `_staging/` and `_pending/` objects older than that timeout, allowing for the SAS lifetime.
132
+
133
+ For Azurite, use `connectionString: "UseDevelopmentStorage=true"`, `createContainer: true`, and `serviceVersion: "2023-11-03"` when its supported API version predates the SDK. Development connection strings may also provide a `BlobEndpoint`. Keep the container private.
134
+
135
+ ### Cosmos DB
136
+
137
+ `CosmosStore` uses the NoSQL API and a serializer envelope to preserve dates, behaviors and concrete model types. `key` accepts a `SecretString`; without it the SDK uses Entra authentication. `createIfNotExists` defaults to `false`; `throughput` optionally configures container RU/s when creating it.
138
+
139
+ The default partition key is `/id`, with the model primary key encoded as a Cosmos-safe identifier. A custom partition such as `/tenant` must be a top-level field included in the model's primary key. It is immutable with that key. A container's partition definition must match the service setting.
140
+
141
+ Replace, delete and patches use ETags; stale conditions raise `UpdateConditionFailError`, and missing records raise `StoreNotFoundError`. Patch, increment and remove operations use atomic Cosmos Patch. A change requiring more than ten patch operations fails before writing; use `update()` for larger replacements. Concurrent writes can surface an ETag conflict for the caller to retry.
142
+
143
+ Supported WebdaQL filters are `=`, `!=`, `<`, `<=`, `>`, `>=`, `IN`, array `CONTAINS`, `LIKE`, `IS NULL`, `IS NOT NULL`, and nested `AND`/`OR`, plus `ORDER BY`, parameters, page limits and opaque continuation tokens. Query values are bound parameters. Cosmos composite indexes may be required for multi-field ordering. Aggregation uses the repository fallback policy; bulk UPDATE and DELETE are explicitly unsupported.
144
+
145
+ The resource contributor creates the SQL database/container under the account named by `endpoint` and assigns the **Cosmos data-plane** Built-in Data Contributor role. Provision the account itself separately or through the deployer's `customResources`.
146
+
147
+ ### Service Bus
148
+
149
+ Both services accept `namespace`, optional `connectionString` (`SecretString`), and `createIfNotExists` (default `false`). Queue settings include `queue`, `maxMessages` (10), `maxWaitTimeInMs` (1000), and `maxPendingMessages` (1000).
150
+
151
+ `ServiceBusQueue` receives in peek-lock mode. Each opaque receipt retains the exact SDK message; `deleteMessage(receipt)` completes it. Failed processing leaves the message available after lock expiry. The pending receipt map is bounded and expired receipts are removed on subsequent receives. Size reports active messages. Long-running manual consumers must finish within the configured Service Bus lock duration.
152
+
153
+ `ServiceBusPubSub` publishes JSON to `topic`. A configured `subscription` is shared and is never deleted by shutdown. Omitting it creates a unique temporary subscription per consumer with five-minute idle expiry. Successful callbacks complete messages; failed callbacks abandon them. Cancellation waits for receiver creation and closes it, then deletes only its own temporary subscription.
154
+
155
+ Contributors create messaging entities in an existing namespace and grant Data Sender/Data Receiver. Temporary subscriptions also need topic-scoped Data Owner for their management operations. Runtime `createIfNotExists` needs management privileges; production deployments normally create entities through ARM instead.
156
+
157
+ ### Key Vault configuration and encryption
158
+
159
+ `AzureKeyVault.getSecret(name)` returns a masked `SecretString`. To load a JSON configuration document, configure `ConfigurationService.sources` as `["Vault:configuration-secret"]`. Within that document, a whole value such as `"${keyvault:database-password}"` resolves to the named secret. Embedded string interpolation is deliberately not supported, so secret wrappers remain intact. ConfigurationService polls for changes.
160
+
161
+ The module registers the `azure` configuration encrypter before services are created:
162
+
163
+ ```jsonc
164
+ {
165
+ "parameters": {
166
+ "configurationEncryption": {
167
+ "default": "azure",
168
+ "encrypters": { "azure": { "keyId": "https://myapp.vault.azure.net/keys/configuration" } }
169
+ }
170
+ },
171
+ "services": { "Database": { "key": "encrypt:azure:replace-this" } }
172
+ }
173
+ ```
174
+
175
+ Run `webda config encrypt` to replace the marker with an `crypt:azure:` value. `WEBDA_AZURE_KEY_ID` is the fallback key URL. A random AES-256-GCM key encrypts the value locally and Key Vault wraps that key with RSA-OAEP-256. The envelope pins the vault key version, and tampered values fail authentication. Keep previous key versions enabled while their envelopes remain in use. Decrypted service values stay wrapped until the SDK needs them. The contributor grants Key Vault Secrets User and Crypto User on an existing vault.
176
+
177
+ ### Monitor logs and OpenTelemetry
178
+
179
+ Container Apps already forwards stdout to Log Analytics. `AzureMonitorLogger` is optional when a custom table is needed:
180
+
181
+ ```json
182
+ {
183
+ "type": "Webda/AzureMonitorLogger",
184
+ "endpoint": "https://my-dce.ingest.monitor.azure.com",
185
+ "ruleId": "dcr-immutable-id",
186
+ "streamName": "Custom-Webda",
187
+ "logLevel": "INFO",
188
+ "batchSize": 100,
189
+ "flushInterval": 5000,
190
+ "maxBufferedLogs": 10000
191
+ }
192
+ ```
193
+
194
+ Follow Microsoft's [Logs ingestion setup](https://learn.microsoft.com/en-us/azure/azure-monitor/logs/tutorial-logs-ingestion-portal) to create a Log Analytics custom table, a DCR and (when needed) a DCE. Use the DCR's **immutable** ID, its ingestion stream name, and the DCE or direct DCR ingestion endpoint. Grant the application identity **Monitoring Metrics Publisher** on the DCR. The stream and target table need these columns:
195
+
196
+ ```json
197
+ [
198
+ { "name": "TimeGenerated", "type": "datetime" },
199
+ { "name": "Level", "type": "string" },
200
+ { "name": "Message", "type": "string" }
201
+ ]
202
+ ```
203
+
204
+ The logger filters levels, sends serial batches, retains failed records for retry and flushes on stop. Its bounded buffer drops new records when full (`droppedLogs` records the count). Delivery is at least once; retries can duplicate records. `lastDeliveryFailed` is available for health checks, and a failed final flush raises an error after listeners are detached.
205
+
206
+ For traces and metrics, reuse `@webda/otel` and an OTLP collector with Azure Monitor ingestion. The current Webda OTEL service selects console or OTLP exporters; it does not accept an Azure exporter instance in its configuration. A separately configured Azure Monitor OpenTelemetry SDK/exporter is another option, but avoid initializing competing global SDKs. See Microsoft's [Azure Monitor OpenTelemetry options](https://learn.microsoft.com/en-us/azure/azure-monitor/containers/opentelemetry-options). This package adds no second tracing or metrics implementation.
207
+
208
+ ## Deployers
209
+
210
+ `Webda/AzureContainerAppsDeployer` builds an OCI image and deploys its digest with ARM. `Webda/AzureFunctionsPackager` creates a deterministic Functions archive, and `Webda/AzureFunctionsDeployer` deploys it to Node 22 Flex Consumption through OneDeploy. See the [Azure deployment guide](https://webda.io/docs/Deployments/Azure).
211
+
212
+ ## Emulator tests
213
+
214
+ The `Azure emulators` workflow runs Blob uploads against Azurite and Cosmos repository conformance against the Linux emulator. Unit tests use SDK mocks and need no cloud credentials. To run the emulator tests locally, start their containers, trust the Cosmos emulator certificate with `NODE_EXTRA_CA_CERTS`, then run:
215
+
216
+ ```sh
217
+ AZURE_EMULATOR_TESTS=true pnpm --filter @webda/azure exec vitest run src/services/emulators.spec.ts --coverage.enabled=false
218
+ ```
219
+
220
+ Only that test process trusts the emulator certificate; TLS verification remains enabled. The documented emulator account keys are development credentials only.
221
+
222
+ ## Validation
223
+
224
+ ```sh
225
+ pnpm --filter @webda/azure build
226
+ pnpm --filter @webda/azure test
227
+ pnpm --filter @webda/azure lint
228
+ pnpm --filter @webda/azure format
229
+ ```
230
+
231
+ <!-- README_FOOTER -->
232
+
233
+ ## Sponsors
234
+
235
+ <!--
236
+ Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor](mailto:sponsor@webda.io)
237
+ -->
238
+
239
+ Arize AI is a machine learning observability and model monitoring platform. It helps you visualize, monitor, and explain your machine learning models. [Learn more](https://arize.com)
240
+
241
+ [<img src="https://webda.io/img/sponsors/arize.svg" width="200">](https://arize.com)
242
+
243
+ Loopingz is a software development company that provides consulting and development services. [Learn more](https://loopingz.com)
244
+
245
+ [<img src="https://webda.io/img/sponsors/loopingz.png" width="200">](https://loopingz.com)
246
+
247
+ Tellae is an innovative consulting firm specialized in cities transportation issues. We provide our clients, both public and private, with solutions to support your strategic and operational decisions. [Learn more](https://tellae.fr)
248
+
249
+ [<img src="https://webda.io/img/sponsors/tellae.svg" width="200">](https://tellae.fr)
package/lib/auth.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ import type { AccessToken, TokenCredential } from "@azure/core-auth";
2
+ import { AzureServiceParameters } from "./services/azure-parameters.js";
3
+ /** Azure authentication shared by ARM deployment, ACR publishing and OneDeploy. */
4
+ export declare class AzureAuth {
5
+ protected parameters: AzureServiceParameters;
6
+ /**
7
+ * Credential
8
+ */
9
+ protected credential?: TokenCredential;
10
+ /**
11
+ * Arm token
12
+ */
13
+ protected armToken?: AccessToken;
14
+ /**
15
+ * Initialize the Azure integration.
16
+ * @param parameters - Azure authentication or integration parameters
17
+ */
18
+ constructor(parameters: AzureServiceParameters);
19
+ /**
20
+ * Return the shared Azure SDK credential.
21
+ * @returns Credential shared by Azure SDK clients
22
+ */
23
+ getCredential(): TokenCredential;
24
+ /**
25
+ * Acquire or reuse an ARM access token.
26
+ * @returns Access token for ARM requests
27
+ */
28
+ getArmToken(): Promise<string>;
29
+ /**
30
+ * Exchange an ARM token for an ACR refresh token.
31
+ * @param loginServer - ACR login server hostname
32
+ * @returns ACR refresh token
33
+ */
34
+ getAcrRefreshToken(loginServer: string): Promise<string>;
35
+ }
36
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAErE,OAAO,EAAE,sBAAsB,EAAsB,MAAM,gCAAgC,CAAC;AAE5F,mFAAmF;AACnF,qBAAa,SAAS;IAaR,SAAS,CAAC,UAAU,EAAE,sBAAsB;IAZxD;;OAEG;IACH,SAAS,CAAC,UAAU,CAAC,EAAE,eAAe,CAAC;IACvC;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC;IACjC;;;OAGG;IACH,YAAsB,UAAU,EAAE,sBAAsB,EAAI;IAE5D;;;OAGG;IACH,aAAa,IAAI,eAAe,CAE/B;IAED;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC,CAanC;IAED;;;;OAIG;IACG,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA0B7D;CACF"}
package/lib/auth.js ADDED
@@ -0,0 +1,70 @@
1
+ import { WebdaError } from "@webda/core";
2
+ import { getAzureCredential } from "./services/azure-parameters.js";
3
+ /** Azure authentication shared by ARM deployment, ACR publishing and OneDeploy. */
4
+ export class AzureAuth {
5
+ /**
6
+ * Initialize the Azure integration.
7
+ * @param parameters - Azure authentication or integration parameters
8
+ */
9
+ constructor(parameters) {
10
+ this.parameters = parameters;
11
+ }
12
+ /**
13
+ * Return the shared Azure SDK credential.
14
+ * @returns Credential shared by Azure SDK clients
15
+ */
16
+ getCredential() {
17
+ return (this.credential ?? (this.credential = getAzureCredential(this.parameters)));
18
+ }
19
+ /**
20
+ * Acquire or reuse an ARM access token.
21
+ * @returns Access token for ARM requests
22
+ */
23
+ async getArmToken() {
24
+ try {
25
+ if (!this.armToken || this.armToken.expiresOnTimestamp < Date.now() + 60000) {
26
+ this.armToken = (await this.getCredential().getToken("https://management.azure.com/.default")) ?? undefined;
27
+ }
28
+ if (!this.armToken)
29
+ throw new Error();
30
+ return this.armToken.token;
31
+ }
32
+ catch {
33
+ throw new WebdaError.CodeError("AZURE_AUTH", "Azure authentication failed: run az login or configure AZURE_CLIENT_ID, AZURE_TENANT_ID and AZURE_CLIENT_SECRET");
34
+ }
35
+ }
36
+ /**
37
+ * Exchange an ARM token for an ACR refresh token.
38
+ * @param loginServer - ACR login server hostname
39
+ * @returns ACR refresh token
40
+ */
41
+ async getAcrRefreshToken(loginServer) {
42
+ if (!/^[a-zA-Z0-9-]+\.azurecr\.(?:io|cn|us)$/.test(loginServer))
43
+ throw new WebdaError.BadRequest("ACR token exchange requires an Azure Container Registry login server");
44
+ const body = new URLSearchParams({
45
+ grant_type: "access_token",
46
+ service: loginServer,
47
+ access_token: await this.getArmToken()
48
+ });
49
+ if (this.parameters.tenantId)
50
+ body.set("tenant", this.parameters.tenantId);
51
+ try {
52
+ const response = await fetch(`https://${loginServer}/oauth2/exchange`, {
53
+ method: "POST",
54
+ body,
55
+ redirect: "error",
56
+ signal: AbortSignal.timeout(30000)
57
+ });
58
+ if (!response.ok)
59
+ throw new Error();
60
+ const result = (await response.json());
61
+ if (!result.refresh_token)
62
+ throw new Error();
63
+ return result.refresh_token;
64
+ }
65
+ catch {
66
+ throw new WebdaError.CodeError("AZURE_ACR_AUTH", "ACR token exchange failed; check the identity's registry push permissions");
67
+ }
68
+ }
69
+ }
70
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sources":["../src/auth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAA0B,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAE5F,mFAAmF;AACnF,MAAM,OAAO,SAAS;IASpB;;;OAGG;IACH,YAAsB,UAAkC;0BAAlC,UAAU;IAA2B,CAAC;IAE5D;;;OAGG;IACH,aAAa;QACX,OAAO,CAAC,IAAI,CAAC,UAAU,KAAf,IAAI,CAAC,UAAU,GAAK,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,EAAC,CAAC;IACnE,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,WAAW;QACf,IAAI,CAAC;YACH,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,kBAAkB,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;gBAC5E,IAAI,CAAC,QAAQ,GAAG,CAAC,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC,QAAQ,CAAC,uCAAuC,CAAC,CAAC,IAAI,SAAS,CAAC;YAC9G,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,QAAQ;gBAAE,MAAM,IAAI,KAAK,EAAE,CAAC;YACtC,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,UAAU,CAAC,SAAS,CAC5B,YAAY,EACZ,iHAAiH,CAClH,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,kBAAkB,CAAC,WAAmB;QAC1C,IAAI,CAAC,wCAAwC,CAAC,IAAI,CAAC,WAAW,CAAC;YAC7D,MAAM,IAAI,UAAU,CAAC,UAAU,CAAC,sEAAsE,CAAC,CAAC;QAC1G,MAAM,IAAI,GAAG,IAAI,eAAe,CAAC;YAC/B,UAAU,EAAE,cAAc;YAC1B,OAAO,EAAE,WAAW;YACpB,YAAY,EAAE,MAAM,IAAI,CAAC,WAAW,EAAE;SACvC,CAAC,CAAC;QACH,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ;YAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAC3E,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,WAAW,WAAW,kBAAkB,EAAE;gBACrE,MAAM,EAAE,MAAM;gBACd,IAAI;gBACJ,QAAQ,EAAE,OAAO;gBACjB,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC;aACnC,CAAC,CAAC;YACH,IAAI,CAAC,QAAQ,CAAC,EAAE;gBAAE,MAAM,IAAI,KAAK,EAAE,CAAC;YACpC,MAAM,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAA+B,CAAC;YACrE,IAAI,CAAC,MAAM,CAAC,aAAa;gBAAE,MAAM,IAAI,KAAK,EAAE,CAAC;YAC7C,OAAO,MAAM,CAAC,aAAa,CAAC;QAC9B,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,UAAU,CAAC,SAAS,CAC5B,gBAAgB,EAChB,2EAA2E,CAC5E,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}