@loadstrike/loadstrike-sdk 1.0.26901 → 1.0.27301

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.
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.__loadstrikeTestExports = exports.EndpointAdapterFactory = exports.KafkaSaslOptions = exports.HttpAuthOptions = exports.HttpOAuth2ClientCredentialsOptions = exports.PushDiffusionEndpointDefinition = exports.DelegateStreamEndpointDefinition = exports.SqsEndpointDefinition = exports.AzureEventHubsEndpointDefinition = exports.RedisStreamsEndpointDefinition = exports.NatsEndpointDefinition = exports.RabbitMqEndpointDefinition = exports.KafkaEndpointDefinition = exports.HttpEndpointDefinition = exports.TrafficEndpointDefinition = exports.LOADSTRIKE_TRACE_ID_TRACKING_FIELD = exports.LOADSTRIKE_TRACE_ID_HEADER = void 0;
36
+ exports.__loadstrikeTestExports = exports.EndpointAdapterFactory = exports.KafkaSaslOptions = exports.HttpAuthOptions = exports.HttpOAuth2ClientCredentialsOptions = exports.WebSocketEndpointDefinition = exports.GrpcEndpointDefinition = exports.PushDiffusionEndpointDefinition = exports.DelegateStreamEndpointDefinition = exports.SqsEndpointDefinition = exports.AzureEventHubsEndpointDefinition = exports.RedisStreamsEndpointDefinition = exports.NatsEndpointDefinition = exports.RabbitMqEndpointDefinition = exports.KafkaEndpointDefinition = exports.HttpEndpointDefinition = exports.TrafficEndpointDefinition = exports.WebSocketNativeClientOptions = exports.WebSocketExpectedMessage = exports.WebSocketMessageSpec = exports.WebSocketReconnectPolicy = exports.ProtocolMetricSnapshot = exports.GrpcStatusMapper = exports.GrpcNativeClientOptions = exports.GrpcMethodTypes = exports.LOADSTRIKE_TRACE_ID_TRACKING_FIELD = exports.LOADSTRIKE_TRACE_ID_HEADER = void 0;
37
37
  const node_crypto_1 = require("node:crypto");
38
38
  const correlation_js_1 = require("./correlation.js");
39
39
  exports.LOADSTRIKE_TRACE_ID_HEADER = "loadstrike-trace-id";
@@ -321,6 +321,343 @@ class PushDiffusionEndpointDefinitionModel extends TrafficEndpointDefinitionMode
321
321
  }
322
322
  }
323
323
  }
324
+ exports.GrpcMethodTypes = {
325
+ Unary: "Unary",
326
+ ServerStreaming: "ServerStreaming",
327
+ ClientStreaming: "ClientStreaming",
328
+ BidirectionalStreaming: "BidirectionalStreaming"
329
+ };
330
+ class GrpcNativeClientOptions {
331
+ constructor(initial = {}) {
332
+ this.UseReflection = false;
333
+ this.UseTls = true;
334
+ this.AllowUntrustedCertificates = false;
335
+ this.DeadlineSeconds = 30;
336
+ this.Metadata = {};
337
+ this.RequestPayloadJsonStream = [];
338
+ const raw = asRecordOrEmpty(initial);
339
+ this.ProtoFilePath = pickOptionalEndpointString(raw, "ProtoFilePath", "protoFilePath");
340
+ this.DescriptorSetPath = pickOptionalEndpointString(raw, "DescriptorSetPath", "descriptorSetPath");
341
+ this.UseReflection = pickEndpointBoolean(raw, "UseReflection", "useReflection") ?? false;
342
+ this.UseTls = pickEndpointBoolean(raw, "UseTls", "useTls") ?? true;
343
+ this.AllowUntrustedCertificates = pickEndpointBoolean(raw, "AllowUntrustedCertificates", "allowUntrustedCertificates") ?? false;
344
+ const deadlineMs = pickOptionalEndpointNumber(raw, "DeadlineMs", "deadlineMs");
345
+ const deadlineSeconds = pickOptionalEndpointNumber(raw, "DeadlineSeconds", "deadlineSeconds", "Deadline", "deadline");
346
+ this.DeadlineSeconds = deadlineMs != null ? deadlineMs / 1000 : (deadlineSeconds ?? 30);
347
+ this.Metadata = pickEndpointStringRecord(raw, "Metadata", "metadata");
348
+ this.RequestPayloadJson = pickOptionalEndpointString(raw, "RequestPayloadJson", "requestPayloadJson");
349
+ this.RequestPayloadJsonStream = pickEndpointStringArray(raw, "RequestPayloadJsonStream", "requestPayloadJsonStream") ?? [];
350
+ }
351
+ Validate() {
352
+ this.validate();
353
+ }
354
+ validate() {
355
+ if (this.DeadlineSeconds <= 0) {
356
+ throw new RangeError("Deadline must be greater than zero.");
357
+ }
358
+ }
359
+ }
360
+ exports.GrpcNativeClientOptions = GrpcNativeClientOptions;
361
+ exports.GrpcStatusMapper = {
362
+ fromStatusCode(statusCode) {
363
+ const names = {
364
+ 0: "OK",
365
+ 1: "CANCELLED",
366
+ 2: "UNKNOWN",
367
+ 3: "INVALID_ARGUMENT",
368
+ 4: "DEADLINE_EXCEEDED",
369
+ 5: "NOT_FOUND",
370
+ 6: "ALREADY_EXISTS",
371
+ 7: "PERMISSION_DENIED",
372
+ 8: "RESOURCE_EXHAUSTED",
373
+ 9: "FAILED_PRECONDITION",
374
+ 10: "ABORTED",
375
+ 11: "OUT_OF_RANGE",
376
+ 12: "UNIMPLEMENTED",
377
+ 13: "INTERNAL",
378
+ 14: "UNAVAILABLE",
379
+ 15: "DATA_LOSS",
380
+ 16: "UNAUTHENTICATED"
381
+ };
382
+ const normalized = Number.isFinite(statusCode) ? Math.trunc(statusCode) : 2;
383
+ const statusName = names[normalized] ?? "UNKNOWN";
384
+ return {
385
+ statusCode: normalized,
386
+ StatusCode: normalized,
387
+ statusName,
388
+ StatusName: statusName,
389
+ isSuccess: normalized === 0,
390
+ IsSuccess: normalized === 0
391
+ };
392
+ },
393
+ FromStatusCode(statusCode) {
394
+ return this.fromStatusCode(statusCode);
395
+ }
396
+ };
397
+ class ProtocolMetricSnapshot {
398
+ constructor(initial = {}) {
399
+ this.protocol = "";
400
+ this.Protocol = "";
401
+ this.requests = 0;
402
+ this.Requests = 0;
403
+ this.messagesSent = 0;
404
+ this.MessagesSent = 0;
405
+ this.messagesReceived = 0;
406
+ this.MessagesReceived = 0;
407
+ this.latencyMs = 0;
408
+ this.LatencyMs = 0;
409
+ this.streamDurationMs = 0;
410
+ this.StreamDurationMs = 0;
411
+ this.bytesSent = 0;
412
+ this.BytesSent = 0;
413
+ this.bytesReceived = 0;
414
+ this.BytesReceived = 0;
415
+ this.reconnects = 0;
416
+ this.Reconnects = 0;
417
+ this.errors = 0;
418
+ this.Errors = 0;
419
+ this.status = "";
420
+ this.Status = "";
421
+ const raw = asRecordOrEmpty(initial);
422
+ this.protocol = pickOptionalEndpointString(raw, "protocol", "Protocol") ?? "";
423
+ this.Protocol = this.protocol;
424
+ this.requests = pickOptionalEndpointNumber(raw, "requests", "Requests") ?? 0;
425
+ this.Requests = this.requests;
426
+ this.messagesSent = pickOptionalEndpointNumber(raw, "messagesSent", "MessagesSent") ?? 0;
427
+ this.MessagesSent = this.messagesSent;
428
+ this.messagesReceived = pickOptionalEndpointNumber(raw, "messagesReceived", "MessagesReceived") ?? 0;
429
+ this.MessagesReceived = this.messagesReceived;
430
+ this.latencyMs = pickOptionalEndpointNumber(raw, "latencyMs", "LatencyMs") ?? 0;
431
+ this.LatencyMs = this.latencyMs;
432
+ this.streamDurationMs = pickOptionalEndpointNumber(raw, "streamDurationMs", "StreamDurationMs") ?? 0;
433
+ this.StreamDurationMs = this.streamDurationMs;
434
+ this.bytesSent = pickOptionalEndpointNumber(raw, "bytesSent", "BytesSent") ?? 0;
435
+ this.BytesSent = this.bytesSent;
436
+ this.bytesReceived = pickOptionalEndpointNumber(raw, "bytesReceived", "BytesReceived") ?? 0;
437
+ this.BytesReceived = this.bytesReceived;
438
+ this.reconnects = pickOptionalEndpointNumber(raw, "reconnects", "Reconnects") ?? 0;
439
+ this.Reconnects = this.reconnects;
440
+ this.errors = pickOptionalEndpointNumber(raw, "errors", "Errors") ?? 0;
441
+ this.Errors = this.errors;
442
+ this.status = pickOptionalEndpointString(raw, "status", "Status") ?? "";
443
+ this.Status = this.status;
444
+ }
445
+ }
446
+ exports.ProtocolMetricSnapshot = ProtocolMetricSnapshot;
447
+ class GrpcEndpointDefinitionModel extends TrafficEndpointDefinitionModel {
448
+ constructor(initial) {
449
+ super(initial);
450
+ this.Kind = "Grpc";
451
+ this.Target = "";
452
+ this.ServiceName = "";
453
+ this.MethodName = "";
454
+ this.MethodType = "Unary";
455
+ this.DeadlineSeconds = 30;
456
+ this.ConnectionMetadata = {};
457
+ this.Metadata = {};
458
+ initializeGrpcEndpointDefinitionModel(this, initial);
459
+ }
460
+ Validate() {
461
+ super.Validate();
462
+ requireNonEmptyString(this.Target, "Target must be provided for gRPC endpoint definitions.");
463
+ requireNonEmptyString(this.ServiceName, "ServiceName must be provided for gRPC endpoint definitions.");
464
+ requireNonEmptyString(this.MethodName, "MethodName must be provided for gRPC endpoint definitions.");
465
+ requireNonEmptyString(this.MethodType, "MethodType must be provided for gRPC endpoint definitions.");
466
+ if (this.DeadlineSeconds <= 0) {
467
+ throw new RangeError("Deadline must be greater than zero.");
468
+ }
469
+ this.NativeClient?.validate();
470
+ if (this.Mode === "Produce" && typeof this.ProduceAsync !== "function" && !this.NativeClient) {
471
+ throw new Error("ProduceAsync delegate must be provided when endpoint mode is Produce.");
472
+ }
473
+ if (this.Mode === "Consume" && typeof this.ConsumeAsync !== "function" && !this.NativeClient) {
474
+ throw new Error("ConsumeAsync delegate must be provided when endpoint mode is Consume.");
475
+ }
476
+ }
477
+ }
478
+ class WebSocketReconnectPolicy {
479
+ constructor(initial = {}) {
480
+ this.MaxAttempts = 0;
481
+ this.maxAttempts = 0;
482
+ this.DelaySeconds = 1;
483
+ this.delaySeconds = 1;
484
+ const raw = asRecordOrEmpty(initial);
485
+ this.MaxAttempts = Math.trunc(pickOptionalEndpointNumber(raw, "MaxAttempts", "maxAttempts") ?? 0);
486
+ this.maxAttempts = this.MaxAttempts;
487
+ const delayMs = pickOptionalEndpointNumber(raw, "DelayMs", "delayMs");
488
+ this.DelaySeconds = delayMs != null
489
+ ? delayMs / 1000
490
+ : (pickOptionalEndpointNumber(raw, "DelaySeconds", "delaySeconds", "Delay", "delay") ?? 1);
491
+ this.delaySeconds = this.DelaySeconds;
492
+ }
493
+ Validate() {
494
+ this.validate();
495
+ }
496
+ validate() {
497
+ if (this.MaxAttempts < 0) {
498
+ throw new RangeError("MaxAttempts cannot be negative.");
499
+ }
500
+ if (this.DelaySeconds < 0) {
501
+ throw new RangeError("Delay cannot be negative.");
502
+ }
503
+ }
504
+ }
505
+ exports.WebSocketReconnectPolicy = WebSocketReconnectPolicy;
506
+ class WebSocketMessageSpec {
507
+ constructor(initial = {}) {
508
+ this.Kind = "Text";
509
+ this.kind = "Text";
510
+ const raw = asRecordOrEmpty(initial);
511
+ this.Kind = pickOptionalEndpointString(raw, "Kind", "kind") ?? "Text";
512
+ this.kind = this.Kind;
513
+ this.TextPayload = pickOptionalEndpointString(raw, "TextPayload", "textPayload");
514
+ this.textPayload = this.TextPayload;
515
+ const binary = pickEndpointValue(raw, "BinaryPayload", "binaryPayload");
516
+ if (binary instanceof Uint8Array) {
517
+ this.BinaryPayload = binary;
518
+ }
519
+ else if (Array.isArray(binary)) {
520
+ this.BinaryPayload = Uint8Array.from(binary.map((value) => Number(value) & 0xff));
521
+ }
522
+ this.binaryPayload = this.BinaryPayload;
523
+ }
524
+ static Text(payload) {
525
+ return new WebSocketMessageSpec({ Kind: "Text", TextPayload: payload });
526
+ }
527
+ static Binary(payload) {
528
+ return new WebSocketMessageSpec({ Kind: "Binary", BinaryPayload: payload });
529
+ }
530
+ Validate() {
531
+ this.validate();
532
+ }
533
+ validate() {
534
+ if (this.Kind.toLowerCase() === "text" && this.TextPayload == null) {
535
+ throw new Error("Text WebSocket messages require TextPayload.");
536
+ }
537
+ if (this.Kind.toLowerCase() === "binary" && this.BinaryPayload == null) {
538
+ throw new Error("Binary WebSocket messages require BinaryPayload.");
539
+ }
540
+ }
541
+ }
542
+ exports.WebSocketMessageSpec = WebSocketMessageSpec;
543
+ class WebSocketExpectedMessage {
544
+ constructor(initial = {}) {
545
+ this.TimeoutSeconds = 30;
546
+ this.timeoutSeconds = 30;
547
+ const raw = asRecordOrEmpty(initial);
548
+ this.ContainsText = pickOptionalEndpointString(raw, "ContainsText", "containsText");
549
+ this.containsText = this.ContainsText;
550
+ const bytes = pickEndpointValue(raw, "ContainsBytes", "containsBytes");
551
+ if (bytes instanceof Uint8Array) {
552
+ this.ContainsBytes = bytes;
553
+ }
554
+ else if (Array.isArray(bytes)) {
555
+ this.ContainsBytes = Uint8Array.from(bytes.map((value) => Number(value) & 0xff));
556
+ }
557
+ this.containsBytes = this.ContainsBytes;
558
+ const timeoutMs = pickOptionalEndpointNumber(raw, "TimeoutMs", "timeoutMs");
559
+ this.TimeoutSeconds = timeoutMs != null
560
+ ? timeoutMs / 1000
561
+ : (pickOptionalEndpointNumber(raw, "TimeoutSeconds", "timeoutSeconds", "Timeout", "timeout") ?? 30);
562
+ this.timeoutSeconds = this.TimeoutSeconds;
563
+ }
564
+ Validate() {
565
+ this.validate();
566
+ }
567
+ validate() {
568
+ if (this.TimeoutSeconds <= 0) {
569
+ throw new RangeError("Timeout must be greater than zero.");
570
+ }
571
+ }
572
+ }
573
+ exports.WebSocketExpectedMessage = WebSocketExpectedMessage;
574
+ class WebSocketNativeClientOptions {
575
+ constructor(initial = {}) {
576
+ this.Headers = {};
577
+ this.headers = {};
578
+ this.Cookies = [];
579
+ this.cookies = [];
580
+ this.Reconnect = new WebSocketReconnectPolicy();
581
+ this.reconnect = this.Reconnect;
582
+ this.Messages = [];
583
+ this.messages = [];
584
+ this.ExpectedMessages = [];
585
+ this.expectedMessages = [];
586
+ const raw = asRecordOrEmpty(initial);
587
+ this.Headers = pickEndpointStringRecord(raw, "Headers", "headers");
588
+ this.headers = this.Headers;
589
+ this.Cookies = pickEndpointStringArray(raw, "Cookies", "cookies") ?? [];
590
+ this.cookies = this.Cookies;
591
+ const pingMs = pickOptionalEndpointNumber(raw, "PingIntervalMs", "pingIntervalMs");
592
+ const pingSeconds = pickOptionalEndpointNumber(raw, "PingIntervalSeconds", "pingIntervalSeconds", "PingInterval", "pingInterval");
593
+ this.PingIntervalSeconds = pingMs != null ? pingMs / 1000 : pingSeconds;
594
+ this.pingIntervalSeconds = this.PingIntervalSeconds;
595
+ const reconnect = pickEndpointValue(raw, "Reconnect", "reconnect");
596
+ this.Reconnect = reconnect instanceof WebSocketReconnectPolicy
597
+ ? reconnect
598
+ : new WebSocketReconnectPolicy(asRecordOrEmpty(reconnect));
599
+ this.reconnect = this.Reconnect;
600
+ this.Messages = normalizeWebSocketMessages(pickEndpointValue(raw, "Messages", "messages"));
601
+ this.messages = this.Messages;
602
+ this.ExpectedMessages = normalizeWebSocketExpectedMessages(pickEndpointValue(raw, "ExpectedMessages", "expectedMessages"));
603
+ this.expectedMessages = this.ExpectedMessages;
604
+ }
605
+ Validate() {
606
+ this.validate();
607
+ }
608
+ validate() {
609
+ if (this.PingIntervalSeconds != null && this.PingIntervalSeconds <= 0) {
610
+ throw new RangeError("PingInterval must be greater than zero.");
611
+ }
612
+ this.Reconnect.validate();
613
+ for (const message of this.Messages) {
614
+ message.validate();
615
+ }
616
+ for (const expected of this.ExpectedMessages) {
617
+ expected.validate();
618
+ }
619
+ }
620
+ }
621
+ exports.WebSocketNativeClientOptions = WebSocketNativeClientOptions;
622
+ class WebSocketEndpointDefinitionModel extends TrafficEndpointDefinitionModel {
623
+ constructor(initial) {
624
+ super(initial);
625
+ this.Kind = "WebSocket";
626
+ this.Url = "";
627
+ this.Subprotocols = [];
628
+ this.ConnectTimeoutSeconds = 30;
629
+ this.CloseTimeoutSeconds = 5;
630
+ this.ConnectionMetadata = {};
631
+ initializeWebSocketEndpointDefinitionModel(this, initial);
632
+ }
633
+ Validate() {
634
+ super.Validate();
635
+ const url = requireNonEmptyString(this.Url, "Url must be provided for WebSocket endpoint definitions.");
636
+ let parsed;
637
+ try {
638
+ parsed = new URL(url);
639
+ }
640
+ catch {
641
+ throw new Error("Url must be an absolute ws:// or wss:// URI.");
642
+ }
643
+ if (parsed.protocol !== "ws:" && parsed.protocol !== "wss:") {
644
+ throw new Error("Url must be an absolute ws:// or wss:// URI.");
645
+ }
646
+ if (this.ConnectTimeoutSeconds <= 0) {
647
+ throw new RangeError("ConnectTimeout must be greater than zero.");
648
+ }
649
+ if (this.CloseTimeoutSeconds <= 0) {
650
+ throw new RangeError("CloseTimeout must be greater than zero.");
651
+ }
652
+ this.NativeClient?.validate();
653
+ if (this.Mode === "Produce" && typeof this.ProduceAsync !== "function" && !this.NativeClient) {
654
+ throw new Error("ProduceAsync delegate must be provided when endpoint mode is Produce.");
655
+ }
656
+ if (this.Mode === "Consume" && typeof this.ConsumeAsync !== "function" && !this.NativeClient) {
657
+ throw new Error("ConsumeAsync delegate must be provided when endpoint mode is Consume.");
658
+ }
659
+ }
660
+ }
324
661
  exports.TrafficEndpointDefinition = TrafficEndpointDefinitionModel;
325
662
  exports.HttpEndpointDefinition = HttpEndpointDefinitionModel;
326
663
  exports.KafkaEndpointDefinition = KafkaEndpointDefinitionModel;
@@ -331,6 +668,8 @@ exports.AzureEventHubsEndpointDefinition = AzureEventHubsEndpointDefinitionModel
331
668
  exports.SqsEndpointDefinition = SqsEndpointDefinitionModel;
332
669
  exports.DelegateStreamEndpointDefinition = DelegateStreamEndpointDefinitionModel;
333
670
  exports.PushDiffusionEndpointDefinition = PushDiffusionEndpointDefinitionModel;
671
+ exports.GrpcEndpointDefinition = GrpcEndpointDefinitionModel;
672
+ exports.WebSocketEndpointDefinition = WebSocketEndpointDefinitionModel;
334
673
  exports.HttpOAuth2ClientCredentialsOptions = HttpOAuth2ClientCredentialsOptionsModel;
335
674
  exports.HttpAuthOptions = HttpAuthOptionsModel;
336
675
  exports.KafkaSaslOptions = KafkaSaslOptionsModel;
@@ -780,6 +1119,113 @@ function initializePushDiffusionEndpointDefinitionModel(target, initial) {
780
1119
  target.SubscribeAsync = subscribeAsync;
781
1120
  }
782
1121
  }
1122
+ function initializeGrpcEndpointDefinitionModel(target, initial) {
1123
+ const raw = asRecordOrEmpty(initial);
1124
+ const targetUrl = pickOptionalEndpointString(raw, "Target", "target");
1125
+ if (targetUrl) {
1126
+ target.Target = targetUrl;
1127
+ }
1128
+ const serviceName = pickOptionalEndpointString(raw, "ServiceName", "serviceName");
1129
+ if (serviceName) {
1130
+ target.ServiceName = serviceName;
1131
+ }
1132
+ const methodName = pickOptionalEndpointString(raw, "MethodName", "methodName");
1133
+ if (methodName) {
1134
+ target.MethodName = methodName;
1135
+ }
1136
+ const methodType = pickOptionalEndpointString(raw, "MethodType", "methodType");
1137
+ if (methodType) {
1138
+ target.MethodType = methodType;
1139
+ }
1140
+ const deadlineMs = pickOptionalEndpointNumber(raw, "DeadlineMs", "deadlineMs");
1141
+ const deadlineSeconds = pickOptionalEndpointNumber(raw, "DeadlineSeconds", "deadlineSeconds", "Deadline", "deadline");
1142
+ if (deadlineMs != null) {
1143
+ target.DeadlineSeconds = deadlineMs / 1000;
1144
+ }
1145
+ else if (deadlineSeconds != null) {
1146
+ target.DeadlineSeconds = deadlineSeconds;
1147
+ }
1148
+ const produce = pickEndpointFunction(raw, "Produce", "produce");
1149
+ if (produce) {
1150
+ target.Produce = produce;
1151
+ }
1152
+ const consume = pickEndpointFunction(raw, "Consume", "consume");
1153
+ if (consume) {
1154
+ target.Consume = consume;
1155
+ }
1156
+ const produceAsync = pickEndpointFunction(raw, "ProduceAsync", "produceAsync");
1157
+ if (produceAsync) {
1158
+ target.ProduceAsync = produceAsync;
1159
+ }
1160
+ const consumeAsync = pickEndpointFunction(raw, "ConsumeAsync", "consumeAsync");
1161
+ if (consumeAsync) {
1162
+ target.ConsumeAsync = consumeAsync;
1163
+ }
1164
+ if (hasAnyEndpointField(raw, ["ConnectionMetadata", "connectionMetadata"])) {
1165
+ target.ConnectionMetadata = pickEndpointStringRecord(raw, "ConnectionMetadata", "connectionMetadata");
1166
+ }
1167
+ if (hasAnyEndpointField(raw, ["Metadata", "metadata"])) {
1168
+ target.Metadata = pickEndpointStringRecord(raw, "Metadata", "metadata");
1169
+ }
1170
+ if (hasAnyEndpointField(raw, ["NativeClient", "nativeClient"])) {
1171
+ const nativeClient = pickEndpointValue(raw, "NativeClient", "nativeClient");
1172
+ target.NativeClient = nativeClient instanceof GrpcNativeClientOptions
1173
+ ? nativeClient
1174
+ : new GrpcNativeClientOptions(asRecordOrEmpty(nativeClient));
1175
+ }
1176
+ }
1177
+ function initializeWebSocketEndpointDefinitionModel(target, initial) {
1178
+ const raw = asRecordOrEmpty(initial);
1179
+ const url = pickOptionalEndpointString(raw, "Url", "url");
1180
+ if (url) {
1181
+ target.Url = url;
1182
+ }
1183
+ const subprotocols = pickEndpointStringArray(raw, "Subprotocols", "subprotocols");
1184
+ if (subprotocols) {
1185
+ target.Subprotocols = subprotocols;
1186
+ }
1187
+ const connectMs = pickOptionalEndpointNumber(raw, "ConnectTimeoutMs", "connectTimeoutMs");
1188
+ const connectSeconds = pickOptionalEndpointNumber(raw, "ConnectTimeoutSeconds", "connectTimeoutSeconds", "ConnectTimeout", "connectTimeout");
1189
+ if (connectMs != null) {
1190
+ target.ConnectTimeoutSeconds = connectMs / 1000;
1191
+ }
1192
+ else if (connectSeconds != null) {
1193
+ target.ConnectTimeoutSeconds = connectSeconds;
1194
+ }
1195
+ const closeMs = pickOptionalEndpointNumber(raw, "CloseTimeoutMs", "closeTimeoutMs");
1196
+ const closeSeconds = pickOptionalEndpointNumber(raw, "CloseTimeoutSeconds", "closeTimeoutSeconds", "CloseTimeout", "closeTimeout");
1197
+ if (closeMs != null) {
1198
+ target.CloseTimeoutSeconds = closeMs / 1000;
1199
+ }
1200
+ else if (closeSeconds != null) {
1201
+ target.CloseTimeoutSeconds = closeSeconds;
1202
+ }
1203
+ const produce = pickEndpointFunction(raw, "Produce", "produce");
1204
+ if (produce) {
1205
+ target.Produce = produce;
1206
+ }
1207
+ const consume = pickEndpointFunction(raw, "Consume", "consume");
1208
+ if (consume) {
1209
+ target.Consume = consume;
1210
+ }
1211
+ const produceAsync = pickEndpointFunction(raw, "ProduceAsync", "produceAsync");
1212
+ if (produceAsync) {
1213
+ target.ProduceAsync = produceAsync;
1214
+ }
1215
+ const consumeAsync = pickEndpointFunction(raw, "ConsumeAsync", "consumeAsync");
1216
+ if (consumeAsync) {
1217
+ target.ConsumeAsync = consumeAsync;
1218
+ }
1219
+ if (hasAnyEndpointField(raw, ["ConnectionMetadata", "connectionMetadata"])) {
1220
+ target.ConnectionMetadata = pickEndpointStringRecord(raw, "ConnectionMetadata", "connectionMetadata");
1221
+ }
1222
+ if (hasAnyEndpointField(raw, ["NativeClient", "nativeClient"])) {
1223
+ const nativeClient = pickEndpointValue(raw, "NativeClient", "nativeClient");
1224
+ target.NativeClient = nativeClient instanceof WebSocketNativeClientOptions
1225
+ ? nativeClient
1226
+ : new WebSocketNativeClientOptions(asRecordOrEmpty(nativeClient));
1227
+ }
1228
+ }
783
1229
  function validateTrafficEndpointDefinitionModel(target) {
784
1230
  requireNonEmptyString(target.Name, "Endpoint name must be provided.");
785
1231
  if (target.Mode !== "Produce" && target.Mode !== "Consume") {
@@ -1914,6 +2360,10 @@ class PushDiffusionEndpointAdapter extends CallbackAdapter {
1914
2360
  }
1915
2361
  class DelegateStreamEndpointAdapter extends CallbackAdapter {
1916
2362
  }
2363
+ class GrpcEndpointAdapter extends CallbackAdapter {
2364
+ }
2365
+ class WebSocketEndpointAdapter extends CallbackAdapter {
2366
+ }
1917
2367
  class EndpointAdapterFactory {
1918
2368
  static create(endpoint) {
1919
2369
  if (endpoint instanceof TrafficEndpointDefinitionModel) {
@@ -1940,6 +2390,10 @@ class EndpointAdapterFactory {
1940
2390
  return new PushDiffusionEndpointAdapter(normalized);
1941
2391
  case "DelegateStream":
1942
2392
  return new DelegateStreamEndpointAdapter(normalized);
2393
+ case "Grpc":
2394
+ return new GrpcEndpointAdapter(normalized);
2395
+ case "WebSocket":
2396
+ return new WebSocketEndpointAdapter(normalized);
1943
2397
  default:
1944
2398
  throw new Error(`Unsupported endpoint kind: ${String(normalized?.kind ?? "")}.`);
1945
2399
  }
@@ -2103,6 +2557,66 @@ const PUSH_DIFFUSION_ENDPOINT_FLAT_KEYS = [
2103
2557
  "subscribeAsync"
2104
2558
  ];
2105
2559
  const DELEGATE_STREAM_ENDPOINT_FLAT_KEYS = [
2560
+ "Produce",
2561
+ "produce",
2562
+ "Consume",
2563
+ "consume",
2564
+ "ProduceAsync",
2565
+ "produceAsync",
2566
+ "ConsumeAsync",
2567
+ "consumeAsync",
2568
+ "ConnectionMetadata",
2569
+ "connectionMetadata",
2570
+ "NativeClient",
2571
+ "nativeClient"
2572
+ ];
2573
+ const GRPC_ENDPOINT_FLAT_KEYS = [
2574
+ "Target",
2575
+ "target",
2576
+ "ServiceName",
2577
+ "serviceName",
2578
+ "MethodName",
2579
+ "methodName",
2580
+ "MethodType",
2581
+ "methodType",
2582
+ "Deadline",
2583
+ "deadline",
2584
+ "DeadlineSeconds",
2585
+ "deadlineSeconds",
2586
+ "DeadlineMs",
2587
+ "deadlineMs",
2588
+ "Metadata",
2589
+ "metadata",
2590
+ "Produce",
2591
+ "produce",
2592
+ "Consume",
2593
+ "consume",
2594
+ "ProduceAsync",
2595
+ "produceAsync",
2596
+ "ConsumeAsync",
2597
+ "consumeAsync",
2598
+ "ConnectionMetadata",
2599
+ "connectionMetadata",
2600
+ "NativeClient",
2601
+ "nativeClient"
2602
+ ];
2603
+ const WEB_SOCKET_ENDPOINT_FLAT_KEYS = [
2604
+ "Url",
2605
+ "url",
2606
+ "Subprotocols",
2607
+ "subprotocols",
2608
+ "ConnectTimeout",
2609
+ "connectTimeout",
2610
+ "ConnectTimeoutSeconds",
2611
+ "connectTimeoutSeconds",
2612
+ "ConnectTimeoutMs",
2613
+ "connectTimeoutMs",
2614
+ "CloseTimeout",
2615
+ "closeTimeout",
2616
+ "CloseTimeoutSeconds",
2617
+ "closeTimeoutSeconds",
2618
+ "CloseTimeoutMs",
2619
+ "closeTimeoutMs",
2106
2620
  "Produce",
2107
2621
  "produce",
2108
2622
  "Consume",
@@ -2148,7 +2662,9 @@ function normalizeEndpointDefinition(endpoint) {
2148
2662
  azureEventHubs: normalizeProtocolOptions(pickEndpointTransportRecord(raw, kind, "AzureEventHubs", ["azureEventHubs", "AzureEventHubs"], AZURE_EVENT_HUBS_ENDPOINT_FLAT_KEYS)),
2149
2663
  sqs: normalizeProtocolOptions(pickEndpointTransportRecord(raw, kind, "Sqs", ["sqs", "Sqs"], SQS_ENDPOINT_FLAT_KEYS)),
2150
2664
  pushDiffusion: normalizeProtocolOptions(pickEndpointTransportRecord(raw, kind, "PushDiffusion", ["pushDiffusion", "PushDiffusion"], PUSH_DIFFUSION_ENDPOINT_FLAT_KEYS)),
2151
- delegate: normalizeDelegateEndpointOptions(pickEndpointTransportRecord(raw, kind, "DelegateStream", ["delegate", "Delegate", "DelegateStream"], DELEGATE_STREAM_ENDPOINT_FLAT_KEYS))
2665
+ delegate: normalizeDelegateEndpointOptions(pickEndpointTransportRecord(raw, kind, "DelegateStream", ["delegate", "Delegate", "DelegateStream"], DELEGATE_STREAM_ENDPOINT_FLAT_KEYS)),
2666
+ grpc: normalizeProtocolOptions(pickEndpointTransportRecord(raw, kind, "Grpc", ["grpc", "Grpc"], GRPC_ENDPOINT_FLAT_KEYS)),
2667
+ webSocket: normalizeProtocolOptions(pickEndpointTransportRecord(raw, kind, "WebSocket", ["webSocket", "WebSocket"], WEB_SOCKET_ENDPOINT_FLAT_KEYS))
2152
2668
  };
2153
2669
  }
2154
2670
  function resolveEndpointKind(raw) {
@@ -2234,6 +2750,32 @@ function resolveEndpointKind(raw) {
2234
2750
  ])) {
2235
2751
  return "PushDiffusion";
2236
2752
  }
2753
+ if (Object.keys(pickEndpointRecord(raw, "grpc", "Grpc")).length || hasAnyEndpointField(raw, [
2754
+ "Target",
2755
+ "target",
2756
+ "ServiceName",
2757
+ "serviceName",
2758
+ "MethodName",
2759
+ "methodName",
2760
+ "MethodType",
2761
+ "methodType",
2762
+ "NativeClient",
2763
+ "nativeClient"
2764
+ ])) {
2765
+ return "Grpc";
2766
+ }
2767
+ if (Object.keys(pickEndpointRecord(raw, "webSocket", "WebSocket")).length || hasAnyEndpointField(raw, [
2768
+ "Subprotocols",
2769
+ "subprotocols",
2770
+ "ConnectTimeoutSeconds",
2771
+ "connectTimeoutSeconds",
2772
+ "CloseTimeoutSeconds",
2773
+ "closeTimeoutSeconds",
2774
+ "NativeClient",
2775
+ "nativeClient"
2776
+ ])) {
2777
+ return "WebSocket";
2778
+ }
2237
2779
  if (Object.keys(pickEndpointRecord(raw, "delegate", "Delegate", "DelegateStream")).length || hasAnyEndpointField(raw, [
2238
2780
  "Produce",
2239
2781
  "produce",
@@ -2364,6 +2906,22 @@ function normalizeDelegateEndpointOptions(options) {
2364
2906
  function normalizeProtocolOptions(options) {
2365
2907
  return Object.keys(options).length ? options : undefined;
2366
2908
  }
2909
+ function normalizeWebSocketMessages(value) {
2910
+ if (!Array.isArray(value)) {
2911
+ return [];
2912
+ }
2913
+ return value.map((entry) => entry instanceof WebSocketMessageSpec
2914
+ ? entry
2915
+ : new WebSocketMessageSpec(asRecordOrEmpty(entry)));
2916
+ }
2917
+ function normalizeWebSocketExpectedMessages(value) {
2918
+ if (!Array.isArray(value)) {
2919
+ return [];
2920
+ }
2921
+ return value.map((entry) => entry instanceof WebSocketExpectedMessage
2922
+ ? entry
2923
+ : new WebSocketExpectedMessage(asRecordOrEmpty(entry)));
2924
+ }
2367
2925
  function pickEndpointValue(record, ...keys) {
2368
2926
  return pickProtocolValue(record, ...keys);
2369
2927
  }
@@ -2477,10 +3035,8 @@ function validateEndpointDefinition(endpoint) {
2477
3035
  if (mode !== "Produce" && mode !== "Consume") {
2478
3036
  throw new Error(`Unsupported endpoint mode: ${mode}.`);
2479
3037
  }
2480
- const hasProduceDelegate = typeof endpoint.delegate?.produce === "function"
2481
- || typeof endpoint.delegate?.produceAsync === "function";
2482
- const hasConsumeDelegate = typeof endpoint.delegate?.consume === "function"
2483
- || typeof endpoint.delegate?.consumeAsync === "function";
3038
+ const hasProduceDelegate = Boolean(resolveProduceDelegate(endpoint) || resolveStructuredProduceDelegate(endpoint));
3039
+ const hasConsumeDelegate = Boolean(resolveConsumeDelegate(endpoint) || resolveStructuredConsumeDelegate(endpoint) || resolveStructuredConsumeStreamDelegate(endpoint));
2484
3040
  const hasModeDelegate = mode === "Produce" ? hasProduceDelegate : hasConsumeDelegate;
2485
3041
  switch (kind) {
2486
3042
  case "Http":
@@ -2510,6 +3066,12 @@ function validateEndpointDefinition(endpoint) {
2510
3066
  case "DelegateStream":
2511
3067
  validateDelegateStreamEndpoint(endpoint, mode);
2512
3068
  return;
3069
+ case "Grpc":
3070
+ validateGrpcEndpoint(endpoint, mode);
3071
+ return;
3072
+ case "WebSocket":
3073
+ validateWebSocketEndpoint(endpoint, mode);
3074
+ return;
2513
3075
  default:
2514
3076
  throw new Error(`Unsupported endpoint kind: ${kind}.`);
2515
3077
  }
@@ -2585,6 +3147,65 @@ function validateDelegateStreamEndpoint(endpoint, mode) {
2585
3147
  throw new Error("ConsumeAsync delegate must be provided when endpoint mode is Consume.");
2586
3148
  }
2587
3149
  }
3150
+ function validateGrpcEndpoint(endpoint, mode) {
3151
+ const options = asRecordOrEmpty(endpoint.grpc);
3152
+ requireNonEmptyString(optionString(options, "Target", "target"), "Target must be provided for gRPC endpoint definitions.");
3153
+ requireNonEmptyString(optionString(options, "ServiceName", "serviceName"), "ServiceName must be provided for gRPC endpoint definitions.");
3154
+ requireNonEmptyString(optionString(options, "MethodName", "methodName"), "MethodName must be provided for gRPC endpoint definitions.");
3155
+ requireNonEmptyString(optionString(options, "MethodType", "methodType") || "Unary", "MethodType must be provided for gRPC endpoint definitions.");
3156
+ const deadlineMs = optionNumber(options, "DeadlineMs", "deadlineMs");
3157
+ const deadlineSeconds = optionNumber(options, "DeadlineSeconds", "deadlineSeconds", "Deadline", "deadline");
3158
+ if ((hasOptionValue(options, "DeadlineMs", "deadlineMs") && deadlineMs <= 0)
3159
+ || (hasOptionValue(options, "DeadlineSeconds", "deadlineSeconds", "Deadline", "deadline") && deadlineSeconds <= 0)) {
3160
+ throw new RangeError("Deadline must be greater than zero.");
3161
+ }
3162
+ const nativeClient = pickEndpointValue(options, "NativeClient", "nativeClient");
3163
+ if (nativeClient != null) {
3164
+ new GrpcNativeClientOptions(asRecordOrEmpty(nativeClient)).validate();
3165
+ }
3166
+ if (mode === "Produce" && !resolveStructuredProduceDelegate(endpoint) && !resolveProduceDelegate(endpoint) && nativeClient == null) {
3167
+ throw new Error("ProduceAsync delegate must be provided when endpoint mode is Produce.");
3168
+ }
3169
+ if (mode === "Consume" && !resolveStructuredConsumeDelegate(endpoint) && !resolveStructuredConsumeStreamDelegate(endpoint) && !resolveConsumeDelegate(endpoint) && nativeClient == null) {
3170
+ throw new Error("ConsumeAsync delegate must be provided when endpoint mode is Consume.");
3171
+ }
3172
+ }
3173
+ function validateWebSocketEndpoint(endpoint, mode) {
3174
+ const options = asRecordOrEmpty(endpoint.webSocket);
3175
+ const url = requireNonEmptyString(optionString(options, "Url", "url"), "Url must be provided for WebSocket endpoint definitions.");
3176
+ let parsed;
3177
+ try {
3178
+ parsed = new URL(url);
3179
+ }
3180
+ catch {
3181
+ throw new Error("Url must be an absolute ws:// or wss:// URI.");
3182
+ }
3183
+ if (parsed.protocol !== "ws:" && parsed.protocol !== "wss:") {
3184
+ throw new Error("Url must be an absolute ws:// or wss:// URI.");
3185
+ }
3186
+ const connectMs = optionNumber(options, "ConnectTimeoutMs", "connectTimeoutMs");
3187
+ const connectSeconds = optionNumber(options, "ConnectTimeoutSeconds", "connectTimeoutSeconds", "ConnectTimeout", "connectTimeout");
3188
+ const closeMs = optionNumber(options, "CloseTimeoutMs", "closeTimeoutMs");
3189
+ const closeSeconds = optionNumber(options, "CloseTimeoutSeconds", "closeTimeoutSeconds", "CloseTimeout", "closeTimeout");
3190
+ if ((hasOptionValue(options, "ConnectTimeoutMs", "connectTimeoutMs") && connectMs <= 0)
3191
+ || (hasOptionValue(options, "ConnectTimeoutSeconds", "connectTimeoutSeconds", "ConnectTimeout", "connectTimeout") && connectSeconds <= 0)) {
3192
+ throw new RangeError("ConnectTimeout must be greater than zero.");
3193
+ }
3194
+ if ((hasOptionValue(options, "CloseTimeoutMs", "closeTimeoutMs") && closeMs <= 0)
3195
+ || (hasOptionValue(options, "CloseTimeoutSeconds", "closeTimeoutSeconds", "CloseTimeout", "closeTimeout") && closeSeconds <= 0)) {
3196
+ throw new RangeError("CloseTimeout must be greater than zero.");
3197
+ }
3198
+ const nativeClient = pickEndpointValue(options, "NativeClient", "nativeClient");
3199
+ if (nativeClient != null) {
3200
+ new WebSocketNativeClientOptions(asRecordOrEmpty(nativeClient)).validate();
3201
+ }
3202
+ if (mode === "Produce" && !resolveStructuredProduceDelegate(endpoint) && !resolveProduceDelegate(endpoint) && nativeClient == null) {
3203
+ throw new Error("ProduceAsync delegate must be provided when endpoint mode is Produce.");
3204
+ }
3205
+ if (mode === "Consume" && !resolveStructuredConsumeDelegate(endpoint) && !resolveStructuredConsumeStreamDelegate(endpoint) && !resolveConsumeDelegate(endpoint) && nativeClient == null) {
3206
+ throw new Error("ConsumeAsync delegate must be provided when endpoint mode is Consume.");
3207
+ }
3208
+ }
2588
3209
  function validateHttpAuthOptions(options) {
2589
3210
  const auth = options.auth;
2590
3211
  if (!auth) {
@@ -3227,6 +3848,10 @@ function createDelegateRequestEndpointView(endpoint) {
3227
3848
  return new exports.AzureEventHubsEndpointDefinition(endpoint);
3228
3849
  case "PushDiffusion":
3229
3850
  return new exports.PushDiffusionEndpointDefinition(endpoint);
3851
+ case "Grpc":
3852
+ return new exports.GrpcEndpointDefinition(endpoint);
3853
+ case "WebSocket":
3854
+ return new exports.WebSocketEndpointDefinition(endpoint);
3230
3855
  default:
3231
3856
  return new exports.DelegateStreamEndpointDefinition(endpoint);
3232
3857
  }
@@ -3445,12 +4070,20 @@ function parseBodyObject(body) {
3445
4070
  function resolveStructuredProduceDelegate(endpoint) {
3446
4071
  return endpoint.delegate?.produceAsync
3447
4072
  ?? endpoint.pushDiffusion?.PublishAsync
3448
- ?? endpoint.pushDiffusion?.publishAsync;
4073
+ ?? endpoint.pushDiffusion?.publishAsync
4074
+ ?? endpoint.grpc?.ProduceAsync
4075
+ ?? endpoint.grpc?.produceAsync
4076
+ ?? endpoint.webSocket?.ProduceAsync
4077
+ ?? endpoint.webSocket?.produceAsync;
3449
4078
  }
3450
4079
  function resolveStructuredConsumeDelegate(endpoint) {
3451
4080
  const delegate = endpoint.delegate?.consumeAsync
3452
4081
  ?? endpoint.pushDiffusion?.SubscribeAsync
3453
- ?? endpoint.pushDiffusion?.subscribeAsync;
4082
+ ?? endpoint.pushDiffusion?.subscribeAsync
4083
+ ?? endpoint.grpc?.ConsumeAsync
4084
+ ?? endpoint.grpc?.consumeAsync
4085
+ ?? endpoint.webSocket?.ConsumeAsync
4086
+ ?? endpoint.webSocket?.consumeAsync;
3454
4087
  return typeof delegate === "function" && delegate.length === 0
3455
4088
  ? delegate
3456
4089
  : undefined;
@@ -3458,22 +4091,36 @@ function resolveStructuredConsumeDelegate(endpoint) {
3458
4091
  function resolveStructuredConsumeStreamDelegate(endpoint) {
3459
4092
  const delegate = endpoint.delegate?.consumeAsync
3460
4093
  ?? endpoint.pushDiffusion?.SubscribeAsync
3461
- ?? endpoint.pushDiffusion?.subscribeAsync;
4094
+ ?? endpoint.pushDiffusion?.subscribeAsync
4095
+ ?? endpoint.grpc?.ConsumeAsync
4096
+ ?? endpoint.grpc?.consumeAsync
4097
+ ?? endpoint.webSocket?.ConsumeAsync
4098
+ ?? endpoint.webSocket?.consumeAsync;
3462
4099
  return typeof delegate === "function" && delegate.length > 0
3463
4100
  ? delegate
3464
4101
  : undefined;
3465
4102
  }
3466
4103
  function resolveProduceDelegate(endpoint) {
3467
- return endpoint.delegate?.produce;
4104
+ return endpoint.delegate?.produce
4105
+ ?? endpoint.grpc?.Produce
4106
+ ?? endpoint.grpc?.produce
4107
+ ?? endpoint.webSocket?.Produce
4108
+ ?? endpoint.webSocket?.produce;
3468
4109
  }
3469
4110
  function resolveConsumeDelegate(endpoint) {
3470
- return endpoint.delegate?.consume;
4111
+ return endpoint.delegate?.consume
4112
+ ?? endpoint.grpc?.Consume
4113
+ ?? endpoint.grpc?.consume
4114
+ ?? endpoint.webSocket?.Consume
4115
+ ?? endpoint.webSocket?.consume;
3471
4116
  }
3472
4117
  function resolveConnectionMetadata(endpoint) {
3473
4118
  return {
3474
4119
  ...(endpoint.connectionMetadata ?? {}),
3475
4120
  ...(endpoint.delegate?.connectionMetadata ?? {}),
3476
- ...toStringRecord(endpoint.pushDiffusion?.ConnectionProperties ?? endpoint.pushDiffusion?.connectionProperties)
4121
+ ...toStringRecord(endpoint.pushDiffusion?.ConnectionProperties ?? endpoint.pushDiffusion?.connectionProperties),
4122
+ ...toStringRecord(endpoint.grpc?.ConnectionMetadata ?? endpoint.grpc?.connectionMetadata),
4123
+ ...toStringRecord(endpoint.webSocket?.ConnectionMetadata ?? endpoint.webSocket?.connectionMetadata)
3477
4124
  };
3478
4125
  }
3479
4126
  function isStructuredProduceResult(value) {