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

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 +30 -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 +108 -0
  8. package/lib/deployers/arm.service.d.ts.map +1 -0
  9. package/lib/deployers/arm.service.js +280 -0
  10. package/lib/deployers/arm.service.js.map +1 -0
  11. package/lib/deployers/containerapps.service.d.ts +156 -0
  12. package/lib/deployers/containerapps.service.d.ts.map +1 -0
  13. package/lib/deployers/containerapps.service.js +455 -0
  14. package/lib/deployers/containerapps.service.js.map +1 -0
  15. package/lib/deployers/functions-entrypoint.d.ts +48 -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 +66 -0
  20. package/lib/deployers/functions.service.d.ts.map +1 -0
  21. package/lib/deployers/functions.service.js +322 -0
  22. package/lib/deployers/functions.service.js.map +1 -0
  23. package/lib/deployers/functionspackager.service.d.ts +43 -0
  24. package/lib/deployers/functionspackager.service.d.ts.map +1 -0
  25. package/lib/deployers/functionspackager.service.js +151 -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 +41 -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 +157 -0
  36. package/lib/services/blob.service.d.ts.map +1 -0
  37. package/lib/services/blob.service.js +428 -0
  38. package/lib/services/blob.service.js.map +1 -0
  39. package/lib/services/contributors.d.ts +47 -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 +211 -0
  44. package/lib/services/cosmos.service.d.ts.map +1 -0
  45. package/lib/services/cosmos.service.js +554 -0
  46. package/lib/services/cosmos.service.js.map +1 -0
  47. package/lib/services/functionserver.service.d.ts +42 -0
  48. package/lib/services/functionserver.service.d.ts.map +1 -0
  49. package/lib/services/functionserver.service.js +223 -0
  50. package/lib/services/functionserver.service.js.map +1 -0
  51. package/lib/services/keyvault.service.d.ts +91 -0
  52. package/lib/services/keyvault.service.d.ts.map +1 -0
  53. package/lib/services/keyvault.service.js +225 -0
  54. package/lib/services/keyvault.service.js.map +1 -0
  55. package/lib/services/monitorlogger.service.d.ts +66 -0
  56. package/lib/services/monitorlogger.service.d.ts.map +1 -0
  57. package/lib/services/monitorlogger.service.js +131 -0
  58. package/lib/services/monitorlogger.service.js.map +1 -0
  59. package/lib/services/servicebus.service.d.ts +128 -0
  60. package/lib/services/servicebus.service.d.ts.map +1 -0
  61. package/lib/services/servicebus.service.js +324 -0
  62. package/lib/services/servicebus.service.js.map +1 -0
  63. package/lib/template.d.ts +53 -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 +1817 -0
@@ -0,0 +1,131 @@
1
+ import { LogsIngestionClient } from "@azure/monitor-ingestion";
2
+ import { Service, useCoreEvents, WebdaError } from "@webda/core";
3
+ import { LogFilter, useWorkerOutput } from "@webda/workout";
4
+ import { format } from "node:util";
5
+ import { AzureParameters, getAzureCredential } from "./azure-parameters.js";
6
+ /** Azure Monitor Logs Ingestion settings. */
7
+ export class AzureMonitorLoggerParameters extends AzureParameters {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.logLevel = "INFO";
11
+ this.batchSize = 100;
12
+ this.flushInterval = 5000;
13
+ this.maxBufferedLogs = 10000;
14
+ }
15
+ }
16
+ /** Forward Webda logs to a custom Azure Monitor table.
17
+ * @WebdaModda
18
+ */
19
+ export class AzureMonitorLogger extends Service {
20
+ constructor() {
21
+ super(...arguments);
22
+ this.buffer = [];
23
+ /** Number of records dropped because the bounded buffer was full. */
24
+ this.droppedLogs = 0;
25
+ /** Last delivery error, available to health checks without recursively logging it. */
26
+ this.lastDeliveryFailed = false;
27
+ }
28
+ /**
29
+ * Perform init.
30
+ * @override
31
+ */
32
+ async init() {
33
+ await super.init();
34
+ const p = this.parameters;
35
+ if (!p.endpoint ||
36
+ !p.ruleId ||
37
+ !p.streamName ||
38
+ !Number.isInteger(p.batchSize) ||
39
+ p.batchSize < 1 ||
40
+ !Number.isInteger(p.maxBufferedLogs) ||
41
+ p.maxBufferedLogs < p.batchSize ||
42
+ p.flushInterval < 1) {
43
+ throw new WebdaError.BadRequest("Azure Monitor requires endpoint, ruleId, streamName and positive buffer settings");
44
+ }
45
+ this.removeListeners();
46
+ this.client = new LogsIngestionClient(p.endpoint, getAzureCredential(p));
47
+ this.messageListener = message => {
48
+ if (message.type === "log" && message.log && LogFilter(message.log.level, p.logLevel)) {
49
+ this._log(message.log.level, ...message.log.args);
50
+ }
51
+ };
52
+ useWorkerOutput().on("message", this.messageListener);
53
+ this.resultListenerOff = useCoreEvents("Webda.Result", () => this.sendLogs());
54
+ this.timer = setInterval(() => {
55
+ void this.sendLogs();
56
+ }, p.flushInterval);
57
+ this.timer.unref();
58
+ return this;
59
+ }
60
+ /**
61
+ * Buffer one record. SecretString values retain their masked representation.
62
+ * @param level - Worker log level
63
+ * @param args - Log arguments
64
+ */
65
+ _log(level, ...args) {
66
+ if (this.buffer.length >= this.parameters.maxBufferedLogs) {
67
+ this.droppedLogs++;
68
+ return;
69
+ }
70
+ this.buffer.push({ TimeGenerated: new Date().toISOString(), Level: level, Message: format(...args) });
71
+ if (this.buffer.length >= this.parameters.batchSize)
72
+ void this.sendLogs();
73
+ }
74
+ /**
75
+ * Serialize flushes; failed records stay at the front for the next scheduled retry.
76
+ * @returns Completion of the current flush attempt
77
+ */
78
+ sendLogs() {
79
+ if (this.sending)
80
+ return this.sending;
81
+ this.sending = this.flush().finally(() => {
82
+ this.sending = undefined;
83
+ });
84
+ return this.sending;
85
+ }
86
+ /**
87
+ * Deliver buffered records in bounded batches.
88
+ */
89
+ async flush() {
90
+ while (this.buffer.length) {
91
+ const records = this.buffer.splice(0, this.parameters.batchSize);
92
+ try {
93
+ await this.client.upload(this.parameters.ruleId, this.parameters.streamName, records);
94
+ this.lastDeliveryFailed = false;
95
+ }
96
+ catch {
97
+ this.lastDeliveryFailed = true;
98
+ this.buffer.unshift(...records);
99
+ const overflow = Math.max(0, this.buffer.length - this.parameters.maxBufferedLogs);
100
+ this.buffer.splice(this.parameters.maxBufferedLogs, overflow);
101
+ this.droppedLogs += overflow;
102
+ return;
103
+ }
104
+ }
105
+ }
106
+ /**
107
+ * Detach log forwarding and stop scheduled flushing.
108
+ */
109
+ removeListeners() {
110
+ if (this.messageListener)
111
+ useWorkerOutput().off("message", this.messageListener);
112
+ this.messageListener = undefined;
113
+ this.resultListenerOff?.();
114
+ this.resultListenerOff = undefined;
115
+ clearInterval(this.timer);
116
+ this.timer = undefined;
117
+ }
118
+ /**
119
+ * Perform stop.
120
+ * @override
121
+ */
122
+ async stop() {
123
+ this.removeListeners();
124
+ await this.sendLogs();
125
+ await super.stop();
126
+ if (this.buffer.length)
127
+ throw new WebdaError.ServiceUnavailable("Unable to flush remaining Azure Monitor logs");
128
+ }
129
+ }
130
+ AzureMonitorLogger.Parameters = AzureMonitorLoggerParameters;
131
+ //# sourceMappingURL=monitorlogger.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monitorlogger.service.js","sources":["../../src/services/monitorlogger.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,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CAAC,IAAI,CAAC,UAAU,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;gBAC9D,IAAI,CAAC,WAAW,IAAI,QAAQ,CAAC;gBAC7B,OAAO;YACT,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACO,eAAe;QACvB,IAAI,IAAI,CAAC,eAAe;YAAE,eAAe,EAAE,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QACjF,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QACjC,IAAI,CAAC,iBAAiB,EAAE,EAAE,CAAC;QAC3B,IAAI,CAAC,iBAAiB,GAAG,SAAS,CAAC;QACnC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,eAAe,EAAE,CAAC;QACvB,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACtB,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM;YAAE,MAAM,IAAI,UAAU,CAAC,kBAAkB,CAAC,8CAA8C,CAAC,CAAC;IAClH,CAAC;CACF;AArHQ,6BAAU,GAAG,4BAA4B,AAA/B,CAAgC"}
@@ -0,0 +1,128 @@
1
+ import { ServiceBusAdministrationClient, ServiceBusClient, ServiceBusReceivedMessage, ServiceBusReceiver, ServiceBusSender } from "@azure/service-bus";
2
+ import { MessageReceipt, PubSubService, Queue, QueueParameters, SecretString } from "@webda/core";
3
+ import { CancelablePromise } from "@webda/utils";
4
+ import { AzureParameters, AzureServiceParameters } from "./azure-parameters.js";
5
+ import { AzureContributor, AzureDeployerInfo, AzureResourceContribution } from "./contributors.js";
6
+ interface ServiceBusSettings extends AzureServiceParameters {
7
+ namespace: string;
8
+ connectionString?: string | SecretString;
9
+ createIfNotExists?: boolean;
10
+ }
11
+ /** Service Bus work queue settings. */
12
+ export declare class ServiceBusQueueParameters extends QueueParameters implements ServiceBusSettings {
13
+ namespace: string;
14
+ connectionString?: string | SecretString;
15
+ createIfNotExists: boolean;
16
+ queue: string;
17
+ tenantId?: string;
18
+ clientId?: string;
19
+ clientSecret?: string | SecretString;
20
+ subscriptionId?: string;
21
+ endpoint?: string;
22
+ maxMessages: number;
23
+ maxWaitTimeInMs: number;
24
+ maxPendingMessages: number;
25
+ /**
26
+ * Perform load.
27
+ * @override
28
+ */
29
+ load(params?: any): this;
30
+ }
31
+ /** Service Bus peek-lock queue. Receipts retain their exact SDK message until completion or expiry.
32
+ * @WebdaModda
33
+ */
34
+ export declare class ServiceBusQueue<T = any> extends Queue<T, ServiceBusQueueParameters> implements AzureContributor {
35
+ static Parameters: typeof ServiceBusQueueParameters;
36
+ protected client: ServiceBusClient;
37
+ protected admin: ServiceBusAdministrationClient;
38
+ protected sender: ServiceBusSender;
39
+ protected receiver: ServiceBusReceiver;
40
+ protected pending: Map<string, ServiceBusReceivedMessage>;
41
+ /**
42
+ * Perform init.
43
+ * @override
44
+ */
45
+ init(): Promise<this>;
46
+ /**
47
+ * Perform send message.
48
+ * @override
49
+ */
50
+ sendMessage(event: T): Promise<void>;
51
+ /**
52
+ * Perform receive message.
53
+ * @override
54
+ */
55
+ receiveMessage<L>(proto?: new () => L): Promise<MessageReceipt<L>[]>;
56
+ /**
57
+ * Perform delete message.
58
+ * @override
59
+ */
60
+ deleteMessage(handle: string): Promise<void>;
61
+ /**
62
+ * Perform size.
63
+ * @override
64
+ */
65
+ size(): Promise<number>;
66
+ /**
67
+ * Perform stop.
68
+ * @override
69
+ */
70
+ stop(): Promise<void>;
71
+ /**
72
+ * Describe the Azure resources and identity permissions required by this service.
73
+ * @param deployer - Deployment scope and identity helpers
74
+ * @returns The azure resources result
75
+ */
76
+ getAzureResources(deployer: AzureDeployerInfo): AzureResourceContribution;
77
+ }
78
+ /** Service Bus pub/sub settings. Omit subscription to create one temporary subscription per consumer. */
79
+ export declare class ServiceBusPubSubParameters extends AzureParameters implements ServiceBusSettings {
80
+ namespace: string;
81
+ connectionString?: string | SecretString;
82
+ createIfNotExists: boolean;
83
+ topic: string;
84
+ subscription?: string;
85
+ }
86
+ /** Service Bus topic with explicit completion after successful processing.
87
+ * @WebdaModda
88
+ */
89
+ export declare class ServiceBusPubSub<T = any> extends PubSubService<T, ServiceBusPubSubParameters> implements AzureContributor {
90
+ static Parameters: typeof ServiceBusPubSubParameters;
91
+ protected client: ServiceBusClient;
92
+ protected admin: ServiceBusAdministrationClient;
93
+ protected sender: ServiceBusSender;
94
+ protected consumers: Set<CancelablePromise<void>>;
95
+ /**
96
+ * Perform init.
97
+ * @override
98
+ */
99
+ init(): Promise<this>;
100
+ /**
101
+ * Perform send message.
102
+ * @override
103
+ */
104
+ sendMessage(event: T): Promise<void>;
105
+ /**
106
+ * Perform size.
107
+ * @override
108
+ */
109
+ size(): Promise<number>;
110
+ /**
111
+ * Perform consume.
112
+ * @override
113
+ */
114
+ consume(callback: (event: T) => Promise<void>, proto?: new () => T, onBind?: () => void): CancelablePromise;
115
+ /**
116
+ * Perform stop.
117
+ * @override
118
+ */
119
+ stop(): Promise<void>;
120
+ /**
121
+ * Describe the Azure resources and identity permissions required by this service.
122
+ * @param deployer - Deployment scope and identity helpers
123
+ * @returns The azure resources result
124
+ */
125
+ getAzureResources(deployer: AzureDeployerInfo): AzureResourceContribution;
126
+ }
127
+ export {};
128
+ //# sourceMappingURL=servicebus.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"servicebus.service.d.ts","sources":["../../src/services/servicebus.service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,gBAAgB,EAChB,yBAAyB,EACzB,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,KAAK,EAAE,eAAe,EAAE,YAAY,EAAc,MAAM,aAAa,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;IAED;;;OAGG;IACG,WAAW,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAGzC;IAED;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAK5B;IAED;;;OAGG;IACH,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,IAAI,GAAG,iBAAiB,CAoE1G;IAED;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAW1B;IAED;;;;OAIG;IACH,iBAAiB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,yBAAyB,CAExE;CACF"}
@@ -0,0 +1,324 @@
1
+ import { ServiceBusAdministrationClient, ServiceBusClient } from "@azure/service-bus";
2
+ import { PubSubService, Queue, QueueParameters, SecretString, WebdaError } from "@webda/core";
3
+ import { CancelablePromise, JSONUtils } from "@webda/utils";
4
+ import { randomUUID } from "node:crypto";
5
+ import { AzureParameters, getAzureCredential, loadAzureParameters } from "./azure-parameters.js";
6
+ /**
7
+ * Construct SDK clients without performing network I/O.
8
+ * @param params - Raw configuration parameters
9
+ * @returns The clients result
10
+ */
11
+ function createClients(params) {
12
+ if (params.connectionString !== undefined) {
13
+ const connection = SecretString.from(params.connectionString, "connectionString");
14
+ return { client: new ServiceBusClient(connection), admin: new ServiceBusAdministrationClient(connection) };
15
+ }
16
+ const credential = getAzureCredential(params);
17
+ return {
18
+ client: new ServiceBusClient(params.namespace, credential),
19
+ admin: new ServiceBusAdministrationClient(params.namespace, credential)
20
+ };
21
+ }
22
+ /**
23
+ * Describe an existing namespace's messaging entities and managed identity permissions.
24
+ * @param params - Raw configuration parameters
25
+ * @param deployer - Deployment scope and identity helpers
26
+ * @param entity - Queue or topic name
27
+ * @param topic - Whether the entity is a topic
28
+ * @param subscription - Configured subscription name, if any
29
+ * @returns The contribute result
30
+ */
31
+ function contribute(params, deployer, entity, topic, subscription) {
32
+ const namespace = params.namespace.split(".")[0];
33
+ const entityType = topic ? "topics" : "queues";
34
+ const name = `${namespace}/${entity}`;
35
+ const scope = `/subscriptions/${deployer.resources.subscriptionId}/resourceGroups/${deployer.resources.resourceGroup}/providers/Microsoft.ServiceBus/namespaces/${name.replace("/", `/${entityType}/`)}`;
36
+ const resources = [
37
+ { type: `Microsoft.ServiceBus/namespaces/${entityType}`, apiVersion: "2024-01-01", name, properties: {} }
38
+ ];
39
+ if (topic && subscription)
40
+ resources.push({
41
+ type: "Microsoft.ServiceBus/namespaces/topics/subscriptions",
42
+ apiVersion: "2024-01-01",
43
+ name: `${name}/${subscription}`,
44
+ dependsOn: [scope],
45
+ properties: {}
46
+ });
47
+ const roles = ["69a216fc-b8fb-44d8-bc22-1f3c2cd27a39", "4f6d3b9b-027b-4f4c-9142-0e5a2a2247e0"];
48
+ // Temporary subscriptions need management rights on the topic, in addition to data-plane access.
49
+ if (topic && !subscription)
50
+ roles.push("090c5cfd-751d-490a-894a-3ce6f1109419");
51
+ return {
52
+ resources,
53
+ roleAssignments: roles.map(role => ({
54
+ scope,
55
+ roleDefinitionId: `/subscriptions/${deployer.resources.subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/${role}`
56
+ }))
57
+ };
58
+ }
59
+ /** Service Bus work queue settings. */
60
+ export class ServiceBusQueueParameters extends QueueParameters {
61
+ constructor() {
62
+ super(...arguments);
63
+ this.createIfNotExists = false;
64
+ this.maxMessages = 10;
65
+ this.maxWaitTimeInMs = 1000;
66
+ this.maxPendingMessages = 1000;
67
+ }
68
+ /**
69
+ * Perform load.
70
+ * @override
71
+ */
72
+ load(params = {}) {
73
+ super.load(params);
74
+ return loadAzureParameters(this);
75
+ }
76
+ }
77
+ /** Service Bus peek-lock queue. Receipts retain their exact SDK message until completion or expiry.
78
+ * @WebdaModda
79
+ */
80
+ export class ServiceBusQueue extends Queue {
81
+ constructor() {
82
+ super(...arguments);
83
+ this.pending = new Map();
84
+ }
85
+ /**
86
+ * Perform init.
87
+ * @override
88
+ */
89
+ async init() {
90
+ await super.init();
91
+ const p = this.parameters;
92
+ if (!Number.isInteger(p.maxMessages) ||
93
+ p.maxMessages < 1 ||
94
+ !Number.isInteger(p.maxPendingMessages) ||
95
+ p.maxPendingMessages < p.maxMessages) {
96
+ throw new WebdaError.BadRequest("Service Bus requires positive message limits");
97
+ }
98
+ ({ client: this.client, admin: this.admin } = createClients(p));
99
+ if (p.createIfNotExists && !(await this.admin.queueExists(p.queue)))
100
+ await this.admin.createQueue(p.queue);
101
+ this.sender = this.client.createSender(p.queue);
102
+ this.receiver = this.client.createReceiver(p.queue, { receiveMode: "peekLock" });
103
+ return this;
104
+ }
105
+ /**
106
+ * Perform send message.
107
+ * @override
108
+ */
109
+ async sendMessage(event) {
110
+ await this.sender.sendMessages({ body: JSONUtils.stringify(event), contentType: "application/json" });
111
+ this.metrics.messages_sent.inc();
112
+ }
113
+ /**
114
+ * Perform receive message.
115
+ * @override
116
+ */
117
+ async receiveMessage(proto) {
118
+ for (const [handle, message] of this.pending) {
119
+ if (!message.lockedUntilUtc || message.lockedUntilUtc.getTime() <= Date.now())
120
+ this.pending.delete(handle);
121
+ }
122
+ const count = Math.min(this.parameters.maxMessages, this.parameters.maxPendingMessages - this.pending.size);
123
+ if (!count)
124
+ return [];
125
+ const messages = await this.receiver.receiveMessages(count, { maxWaitTimeInMs: this.parameters.maxWaitTimeInMs });
126
+ const receipts = [];
127
+ for (const message of messages) {
128
+ try {
129
+ const value = this.unserialize(typeof message.body === "string" ? message.body : JSONUtils.stringify(message.body), proto);
130
+ const handle = randomUUID();
131
+ this.pending.set(handle, message);
132
+ receipts.push({ Message: value, ReceiptHandle: handle });
133
+ }
134
+ catch {
135
+ this.metrics.errors.inc();
136
+ await this.receiver.abandonMessage(message);
137
+ }
138
+ }
139
+ return receipts;
140
+ }
141
+ /**
142
+ * Perform delete message.
143
+ * @override
144
+ */
145
+ async deleteMessage(handle) {
146
+ const message = this.pending.get(handle);
147
+ if (!message)
148
+ throw new WebdaError.NotFound("Service Bus receipt is unknown or expired");
149
+ await this.receiver.completeMessage(message);
150
+ this.pending.delete(handle);
151
+ }
152
+ /**
153
+ * Perform size.
154
+ * @override
155
+ */
156
+ async size() {
157
+ return (await this.admin.getQueueRuntimeProperties(this.parameters.queue)).activeMessageCount;
158
+ }
159
+ /**
160
+ * Perform stop.
161
+ * @override
162
+ */
163
+ async stop() {
164
+ try {
165
+ await this.receiver?.close();
166
+ }
167
+ finally {
168
+ this.pending.clear();
169
+ try {
170
+ await this.sender?.close();
171
+ }
172
+ finally {
173
+ await this.client?.close();
174
+ }
175
+ }
176
+ await super.stop();
177
+ }
178
+ /**
179
+ * Describe the Azure resources and identity permissions required by this service.
180
+ * @param deployer - Deployment scope and identity helpers
181
+ * @returns The azure resources result
182
+ */
183
+ getAzureResources(deployer) {
184
+ return contribute(this.parameters, deployer, this.parameters.queue, false);
185
+ }
186
+ }
187
+ ServiceBusQueue.Parameters = ServiceBusQueueParameters;
188
+ /** Service Bus pub/sub settings. Omit subscription to create one temporary subscription per consumer. */
189
+ export class ServiceBusPubSubParameters extends AzureParameters {
190
+ constructor() {
191
+ super(...arguments);
192
+ this.createIfNotExists = false;
193
+ }
194
+ }
195
+ /** Service Bus topic with explicit completion after successful processing.
196
+ * @WebdaModda
197
+ */
198
+ export class ServiceBusPubSub extends PubSubService {
199
+ constructor() {
200
+ super(...arguments);
201
+ this.consumers = new Set();
202
+ }
203
+ /**
204
+ * Perform init.
205
+ * @override
206
+ */
207
+ async init() {
208
+ await super.init();
209
+ ({ client: this.client, admin: this.admin } = createClients(this.parameters));
210
+ if (this.parameters.createIfNotExists && !(await this.admin.topicExists(this.parameters.topic)))
211
+ await this.admin.createTopic(this.parameters.topic);
212
+ this.sender = this.client.createSender(this.parameters.topic);
213
+ return this;
214
+ }
215
+ /**
216
+ * Perform send message.
217
+ * @override
218
+ */
219
+ async sendMessage(event) {
220
+ await this.sender.sendMessages({ body: JSONUtils.stringify(event), contentType: "application/json" });
221
+ this.metrics.messages_sent.inc();
222
+ }
223
+ /**
224
+ * Perform size.
225
+ * @override
226
+ */
227
+ async size() {
228
+ return this.parameters.subscription
229
+ ? (await this.admin.getSubscriptionRuntimeProperties(this.parameters.topic, this.parameters.subscription))
230
+ .activeMessageCount
231
+ : 0;
232
+ }
233
+ /**
234
+ * Perform consume.
235
+ * @override
236
+ */
237
+ consume(callback, proto, onBind) {
238
+ const topic = this.parameters.topic;
239
+ const temporary = !this.parameters.subscription;
240
+ const subscription = this.parameters.subscription ?? `webda-${randomUUID()}`;
241
+ let receiver;
242
+ let created = false;
243
+ let closing;
244
+ const cleanup = () => (closing ?? (closing = (async () => {
245
+ try {
246
+ await receiver?.close();
247
+ }
248
+ finally {
249
+ if (created)
250
+ await this.admin.deleteSubscription(topic, subscription);
251
+ }
252
+ })()));
253
+ const binding = (async () => {
254
+ if (temporary ||
255
+ (this.parameters.createIfNotExists && !(await this.admin.subscriptionExists(topic, subscription)))) {
256
+ await this.admin.createSubscription(topic, subscription, temporary ? { autoDeleteOnIdle: "PT5M" } : {});
257
+ created = temporary;
258
+ }
259
+ receiver = this.client.createReceiver(topic, subscription, { receiveMode: "peekLock" });
260
+ receiver.subscribe({
261
+ processMessage: async (message) => {
262
+ this.metrics.messages_received.inc();
263
+ const end = this.metrics.processing_duration.startTimer();
264
+ try {
265
+ await callback(this.unserialize(typeof message.body === "string" ? message.body : JSONUtils.stringify(message.body), proto));
266
+ await receiver.completeMessage(message);
267
+ }
268
+ catch {
269
+ this.metrics.errors.inc();
270
+ await receiver.abandonMessage(message);
271
+ }
272
+ finally {
273
+ end();
274
+ }
275
+ },
276
+ processError: async () => {
277
+ this.metrics.errors.inc();
278
+ }
279
+ }, { autoCompleteMessages: false });
280
+ onBind?.();
281
+ })();
282
+ const consumer = new CancelablePromise((_resolve, reject) => {
283
+ void binding.catch(async (error) => {
284
+ await cleanup().catch(() => { });
285
+ reject(error);
286
+ });
287
+ }, async () => {
288
+ await binding.catch(() => { });
289
+ await cleanup();
290
+ });
291
+ this.consumers.add(consumer);
292
+ // The consumer remains pending until cancellation or failure; observe its rejection during shutdown.
293
+ void consumer.catch(() => this.consumers.delete(consumer));
294
+ return consumer;
295
+ }
296
+ /**
297
+ * Perform stop.
298
+ * @override
299
+ */
300
+ async stop() {
301
+ try {
302
+ await Promise.all([...this.consumers].map(consumer => consumer.cancel()));
303
+ }
304
+ finally {
305
+ try {
306
+ await this.sender?.close();
307
+ }
308
+ finally {
309
+ await this.client?.close();
310
+ }
311
+ }
312
+ await super.stop();
313
+ }
314
+ /**
315
+ * Describe the Azure resources and identity permissions required by this service.
316
+ * @param deployer - Deployment scope and identity helpers
317
+ * @returns The azure resources result
318
+ */
319
+ getAzureResources(deployer) {
320
+ return contribute(this.parameters, deployer, this.parameters.topic, true, this.parameters.subscription);
321
+ }
322
+ }
323
+ ServiceBusPubSub.Parameters = ServiceBusPubSubParameters;
324
+ //# sourceMappingURL=servicebus.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"servicebus.service.js","sources":["../../src/services/servicebus.service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,gBAAgB,EAIjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAkB,aAAa,EAAE,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9G,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,eAAe,EAEf,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,uBAAuB,CAAC;AAS/B;;;;GAIG;AACH,SAAS,aAAa,CAAC,MAA0B;IAC/C,IAAI,MAAM,CAAC,gBAAgB,KAAK,SAAS,EAAE,CAAC;QAC1C,MAAM,UAAU,GAAG,YAAY,CAAC,IAA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AG,0BAA0B,AAA7B,CAA8B"}
@@ -0,0 +1,53 @@
1
+ /** ARM template shape shared by Azure deployers and contributors. */
2
+ export interface AzureTemplate {
3
+ $schema: string;
4
+ contentVersion: string;
5
+ parameters: Record<string, {
6
+ type: string;
7
+ }>;
8
+ resources: Record<string, any>[];
9
+ outputs: Record<string, any>;
10
+ }
11
+ /**
12
+ * Create an empty ARM deployment template.
13
+ * @returns The azure template result
14
+ */
15
+ export declare function createAzureTemplate(): AzureTemplate;
16
+ /**
17
+ * Quote a literal embedded inside an ARM expression.
18
+ * @param value - Value to convert or protect
19
+ * @returns The arm literal result
20
+ */
21
+ export declare function armLiteral(value: string): string;
22
+ /**
23
+ * Strip the brackets of an expression, or quote a literal for a larger expression.
24
+ * @param value - Value to convert or protect
25
+ * @returns The arm value result
26
+ */
27
+ export declare function armValue(value: string): string;
28
+ /**
29
+ * Construct a resource identifier without interpolating unescaped names.
30
+ * @param type - ARM resource type
31
+ * @param names - Resource name segments
32
+ * @returns The resource id result
33
+ */
34
+ export declare function resourceId(type: string, ...names: string[]): string;
35
+ /**
36
+ * Resource identifier for a role assignment at a resource scope.
37
+ * @param resource - ARM resource declaration
38
+ * @returns The role assignment id result
39
+ */
40
+ export declare function roleAssignmentId(resource: Record<string, any>): string;
41
+ /**
42
+ * Azure Container Apps uses five cron fields; sub-minute schedules cannot be represented.
43
+ * @param cron - Cron expression
44
+ * @returns The container apps schedule result
45
+ */
46
+ export declare function containerAppsSchedule(cron: string): string;
47
+ /**
48
+ * Functions timers use six-field NCRONTAB with seconds first.
49
+ * @param cron - Cron expression
50
+ * @returns The functions schedule result
51
+ */
52
+ export declare function functionsSchedule(cron: string): string;
53
+ //# sourceMappingURL=template.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template.d.ts","sources":["../src/template.ts"],"names":[],"mappings":"AAEA,qEAAqE;AACrE,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7C,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,aAAa,CAQnD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AACD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE9C;AACD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAEnE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAEtE;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM1D;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKtD"}