@azure/web-pubsub 1.1.4-alpha.20241119.1 → 1.1.4-alpha.20241120.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. package/dist/commonjs/generated/generatedClient.d.ts +19 -0
  2. package/dist/commonjs/generated/generatedClient.d.ts.map +1 -0
  3. package/dist/commonjs/generated/generatedClient.js +76 -0
  4. package/dist/commonjs/generated/generatedClient.js.map +1 -0
  5. package/dist/commonjs/generated/generatedClientContext.d.ts +14 -0
  6. package/dist/commonjs/generated/generatedClientContext.d.ts.map +1 -0
  7. package/dist/commonjs/generated/generatedClientContext.js +46 -0
  8. package/dist/commonjs/generated/generatedClientContext.js.map +1 -0
  9. package/dist/commonjs/generated/index.d.ts +4 -0
  10. package/dist/commonjs/generated/index.d.ts.map +1 -0
  11. package/dist/commonjs/generated/index.js +16 -0
  12. package/dist/commonjs/generated/index.js.map +1 -0
  13. package/dist/commonjs/generated/models/index.d.ts +323 -0
  14. package/dist/commonjs/generated/models/index.d.ts.map +1 -0
  15. package/dist/commonjs/generated/models/index.js +27 -0
  16. package/dist/commonjs/generated/models/index.js.map +1 -0
  17. package/dist/commonjs/generated/models/mappers.d.ts +30 -0
  18. package/dist/commonjs/generated/models/mappers.d.ts.map +1 -0
  19. package/dist/commonjs/generated/models/mappers.js +463 -0
  20. package/dist/commonjs/generated/models/mappers.js.map +1 -0
  21. package/dist/commonjs/generated/models/parameters.d.ts +31 -0
  22. package/dist/commonjs/generated/models/parameters.d.ts.map +1 -0
  23. package/dist/commonjs/generated/models/parameters.js +335 -0
  24. package/dist/commonjs/generated/models/parameters.js.map +1 -0
  25. package/dist/commonjs/generated/operations/healthApi.d.ts +18 -0
  26. package/dist/commonjs/generated/operations/healthApi.d.ts.map +1 -0
  27. package/dist/commonjs/generated/operations/healthApi.js +43 -0
  28. package/dist/commonjs/generated/operations/healthApi.js.map +1 -0
  29. package/dist/commonjs/generated/operations/index.d.ts +3 -0
  30. package/dist/commonjs/generated/operations/index.d.ts.map +1 -0
  31. package/dist/commonjs/generated/operations/index.js +13 -0
  32. package/dist/commonjs/generated/operations/index.js.map +1 -0
  33. package/dist/commonjs/generated/operations/webPubSub.d.ts +249 -0
  34. package/dist/commonjs/generated/operations/webPubSub.d.ts.map +1 -0
  35. package/dist/commonjs/generated/operations/webPubSub.js +874 -0
  36. package/dist/commonjs/generated/operations/webPubSub.js.map +1 -0
  37. package/dist/commonjs/generated/operationsInterfaces/healthApi.d.ts +10 -0
  38. package/dist/commonjs/generated/operationsInterfaces/healthApi.d.ts.map +1 -0
  39. package/dist/commonjs/generated/operationsInterfaces/healthApi.js +10 -0
  40. package/dist/commonjs/generated/operationsInterfaces/healthApi.js.map +1 -0
  41. package/dist/commonjs/generated/operationsInterfaces/index.d.ts +3 -0
  42. package/dist/commonjs/generated/operationsInterfaces/index.d.ts.map +1 -0
  43. package/dist/commonjs/generated/operationsInterfaces/index.js +13 -0
  44. package/dist/commonjs/generated/operationsInterfaces/index.js.map +1 -0
  45. package/dist/commonjs/generated/operationsInterfaces/webPubSub.d.ts +224 -0
  46. package/dist/commonjs/generated/operationsInterfaces/webPubSub.d.ts.map +1 -0
  47. package/dist/commonjs/generated/operationsInterfaces/webPubSub.js +10 -0
  48. package/dist/commonjs/generated/operationsInterfaces/webPubSub.js.map +1 -0
  49. package/dist/commonjs/groupClient.d.ts +232 -0
  50. package/dist/commonjs/groupClient.d.ts.map +1 -0
  51. package/dist/commonjs/groupClient.js +101 -0
  52. package/dist/commonjs/groupClient.js.map +1 -0
  53. package/dist/commonjs/hubClient.d.ts +478 -0
  54. package/dist/commonjs/hubClient.d.ts.map +1 -0
  55. package/dist/commonjs/hubClient.js +372 -0
  56. package/dist/commonjs/hubClient.js.map +1 -0
  57. package/dist/commonjs/index.d.ts +5 -0
  58. package/dist/commonjs/index.d.ts.map +1 -0
  59. package/dist/commonjs/index.js +12 -0
  60. package/dist/commonjs/index.js.map +1 -0
  61. package/dist/commonjs/logger.d.ts +5 -0
  62. package/dist/commonjs/logger.d.ts.map +1 -0
  63. package/dist/commonjs/logger.js +11 -0
  64. package/dist/commonjs/logger.js.map +1 -0
  65. package/dist/commonjs/package.json +3 -0
  66. package/dist/commonjs/parseConnectionString.d.ts +8 -0
  67. package/dist/commonjs/parseConnectionString.d.ts.map +1 -0
  68. package/dist/commonjs/parseConnectionString.js +34 -0
  69. package/dist/commonjs/parseConnectionString.js.map +1 -0
  70. package/dist/commonjs/reverseProxyPolicy.d.ts +9 -0
  71. package/dist/commonjs/reverseProxyPolicy.d.ts.map +1 -0
  72. package/dist/commonjs/reverseProxyPolicy.js +25 -0
  73. package/dist/commonjs/reverseProxyPolicy.js.map +1 -0
  74. package/dist/commonjs/tracing.d.ts +3 -0
  75. package/dist/commonjs/tracing.d.ts.map +1 -0
  76. package/dist/commonjs/tracing.js +12 -0
  77. package/dist/commonjs/tracing.js.map +1 -0
  78. package/dist/commonjs/tsdoc-metadata.json +11 -0
  79. package/dist/commonjs/utils.d.ts +29 -0
  80. package/dist/commonjs/utils.d.ts.map +1 -0
  81. package/dist/commonjs/utils.js +73 -0
  82. package/dist/commonjs/utils.js.map +1 -0
  83. package/dist/commonjs/webPubSubCredentialPolicy.d.ts +13 -0
  84. package/dist/commonjs/webPubSubCredentialPolicy.d.ts.map +1 -0
  85. package/dist/commonjs/webPubSubCredentialPolicy.js +32 -0
  86. package/dist/commonjs/webPubSubCredentialPolicy.js.map +1 -0
  87. package/dist/esm/generated/generatedClient.d.ts +19 -0
  88. package/dist/esm/generated/generatedClient.d.ts.map +1 -0
  89. package/{dist-esm/src → dist/esm}/generated/generatedClient.js +1 -1
  90. package/dist/esm/generated/generatedClient.js.map +1 -0
  91. package/dist/esm/generated/generatedClientContext.d.ts +14 -0
  92. package/dist/esm/generated/generatedClientContext.d.ts.map +1 -0
  93. package/dist/esm/generated/generatedClientContext.js.map +1 -0
  94. package/dist/esm/generated/index.d.ts +4 -0
  95. package/dist/esm/generated/index.d.ts.map +1 -0
  96. package/{dist-esm/src → dist/esm}/generated/index.js +3 -3
  97. package/dist/esm/generated/index.js.map +1 -0
  98. package/dist/esm/generated/models/index.d.ts +323 -0
  99. package/dist/esm/generated/models/index.d.ts.map +1 -0
  100. package/dist/esm/generated/models/mappers.d.ts +30 -0
  101. package/dist/esm/generated/models/mappers.d.ts.map +1 -0
  102. package/dist/esm/generated/models/parameters.d.ts +31 -0
  103. package/dist/esm/generated/models/parameters.d.ts.map +1 -0
  104. package/{dist-esm/src → dist/esm}/generated/models/parameters.js +1 -1
  105. package/dist/esm/generated/models/parameters.js.map +1 -0
  106. package/dist/esm/generated/operations/healthApi.d.ts +18 -0
  107. package/dist/esm/generated/operations/healthApi.d.ts.map +1 -0
  108. package/{dist-esm/src → dist/esm}/generated/operations/healthApi.js +2 -2
  109. package/dist/esm/generated/operations/healthApi.js.map +1 -0
  110. package/dist/esm/generated/operations/index.d.ts +3 -0
  111. package/dist/esm/generated/operations/index.d.ts.map +1 -0
  112. package/{dist-esm/src/generated/operationsInterfaces → dist/esm/generated/operations}/index.js +2 -2
  113. package/dist/esm/generated/operations/index.js.map +1 -0
  114. package/dist/esm/generated/operations/webPubSub.d.ts +249 -0
  115. package/dist/esm/generated/operations/webPubSub.d.ts.map +1 -0
  116. package/{dist-esm/src → dist/esm}/generated/operations/webPubSub.js +2 -2
  117. package/dist/esm/generated/operations/webPubSub.js.map +1 -0
  118. package/dist/esm/generated/operationsInterfaces/healthApi.d.ts +10 -0
  119. package/dist/esm/generated/operationsInterfaces/healthApi.d.ts.map +1 -0
  120. package/{dist-esm/src → dist/esm}/generated/operationsInterfaces/healthApi.js.map +1 -1
  121. package/dist/esm/generated/operationsInterfaces/index.d.ts +3 -0
  122. package/dist/esm/generated/operationsInterfaces/index.d.ts.map +1 -0
  123. package/{dist-esm/src/generated/operations → dist/esm/generated/operationsInterfaces}/index.js +2 -2
  124. package/dist/esm/generated/operationsInterfaces/index.js.map +1 -0
  125. package/dist/esm/generated/operationsInterfaces/webPubSub.d.ts +224 -0
  126. package/dist/esm/generated/operationsInterfaces/webPubSub.d.ts.map +1 -0
  127. package/dist/esm/generated/operationsInterfaces/webPubSub.js.map +1 -0
  128. package/dist/esm/groupClient.d.ts +232 -0
  129. package/dist/esm/groupClient.d.ts.map +1 -0
  130. package/{dist-esm/src → dist/esm}/groupClient.js +2 -2
  131. package/dist/esm/groupClient.js.map +1 -0
  132. package/dist/esm/hubClient.d.ts +478 -0
  133. package/dist/esm/hubClient.d.ts.map +1 -0
  134. package/{dist-esm/src → dist/esm}/hubClient.js +9 -9
  135. package/dist/esm/hubClient.js.map +1 -0
  136. package/dist/esm/index.d.ts +5 -0
  137. package/dist/esm/index.d.ts.map +1 -0
  138. package/{dist-esm/src → dist/esm}/index.js +2 -2
  139. package/dist/esm/index.js.map +1 -0
  140. package/dist/esm/logger.d.ts +5 -0
  141. package/dist/esm/logger.d.ts.map +1 -0
  142. package/dist/esm/package.json +3 -0
  143. package/dist/esm/parseConnectionString.d.ts +8 -0
  144. package/dist/esm/parseConnectionString.d.ts.map +1 -0
  145. package/dist/esm/reverseProxyPolicy.d.ts +9 -0
  146. package/dist/esm/reverseProxyPolicy.d.ts.map +1 -0
  147. package/dist/esm/tracing.d.ts +3 -0
  148. package/dist/esm/tracing.d.ts.map +1 -0
  149. package/dist/esm/utils.d.ts +29 -0
  150. package/dist/esm/utils.d.ts.map +1 -0
  151. package/dist/esm/webPubSubCredentialPolicy.d.ts +13 -0
  152. package/dist/esm/webPubSubCredentialPolicy.d.ts.map +1 -0
  153. package/package.json +56 -52
  154. package/dist/index.js +0 -2441
  155. package/dist/index.js.map +0 -1
  156. package/dist-esm/samples-dev/broadcasting.js +0 -27
  157. package/dist-esm/samples-dev/broadcasting.js.map +0 -1
  158. package/dist-esm/samples-dev/directMessage.js +0 -20
  159. package/dist-esm/samples-dev/directMessage.js.map +0 -1
  160. package/dist-esm/samples-dev/managingGroups.js +0 -23
  161. package/dist-esm/samples-dev/managingGroups.js.map +0 -1
  162. package/dist-esm/src/generated/generatedClient.js.map +0 -1
  163. package/dist-esm/src/generated/generatedClientContext.js.map +0 -1
  164. package/dist-esm/src/generated/index.js.map +0 -1
  165. package/dist-esm/src/generated/models/parameters.js.map +0 -1
  166. package/dist-esm/src/generated/operations/healthApi.js.map +0 -1
  167. package/dist-esm/src/generated/operations/index.js.map +0 -1
  168. package/dist-esm/src/generated/operations/webPubSub.js.map +0 -1
  169. package/dist-esm/src/generated/operationsInterfaces/index.js.map +0 -1
  170. package/dist-esm/src/generated/operationsInterfaces/webPubSub.js.map +0 -1
  171. package/dist-esm/src/groupClient.js.map +0 -1
  172. package/dist-esm/src/hubClient.js.map +0 -1
  173. package/dist-esm/src/index.js.map +0 -1
  174. package/dist-esm/test/conn.spec.js +0 -23
  175. package/dist-esm/test/conn.spec.js.map +0 -1
  176. package/dist-esm/test/groups.spec.js +0 -138
  177. package/dist-esm/test/groups.spec.js.map +0 -1
  178. package/dist-esm/test/hubs.spec.js +0 -270
  179. package/dist-esm/test/hubs.spec.js.map +0 -1
  180. package/dist-esm/test/integration.spec.js +0 -299
  181. package/dist-esm/test/integration.spec.js.map +0 -1
  182. package/dist-esm/test/odata.spec.js +0 -15
  183. package/dist-esm/test/odata.spec.js.map +0 -1
  184. package/dist-esm/test/testEnv.js +0 -23
  185. package/dist-esm/test/testEnv.js.map +0 -1
  186. /package/{dist-esm/src → dist/esm}/generated/generatedClientContext.js +0 -0
  187. /package/{dist-esm/src → dist/esm}/generated/models/index.js +0 -0
  188. /package/{dist-esm/src → dist/esm}/generated/models/index.js.map +0 -0
  189. /package/{dist-esm/src → dist/esm}/generated/models/mappers.js +0 -0
  190. /package/{dist-esm/src → dist/esm}/generated/models/mappers.js.map +0 -0
  191. /package/{dist-esm/src → dist/esm}/generated/operationsInterfaces/healthApi.js +0 -0
  192. /package/{dist-esm/src → dist/esm}/generated/operationsInterfaces/webPubSub.js +0 -0
  193. /package/{dist-esm/src → dist/esm}/logger.js +0 -0
  194. /package/{dist-esm/src → dist/esm}/logger.js.map +0 -0
  195. /package/{dist-esm/src → dist/esm}/parseConnectionString.js +0 -0
  196. /package/{dist-esm/src → dist/esm}/parseConnectionString.js.map +0 -0
  197. /package/{dist-esm/src → dist/esm}/reverseProxyPolicy.js +0 -0
  198. /package/{dist-esm/src → dist/esm}/reverseProxyPolicy.js.map +0 -0
  199. /package/{dist-esm/src → dist/esm}/tracing.js +0 -0
  200. /package/{dist-esm/src → dist/esm}/tracing.js.map +0 -0
  201. /package/{dist-esm/src → dist/esm}/utils.js +0 -0
  202. /package/{dist-esm/src → dist/esm}/utils.js.map +0 -0
  203. /package/{dist-esm/src → dist/esm}/webPubSubCredentialPolicy.js +0 -0
  204. /package/{dist-esm/src → dist/esm}/webPubSubCredentialPolicy.js.map +0 -0
  205. /package/{types → dist}/web-pubsub.d.ts +0 -0
@@ -0,0 +1,372 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.WebPubSubServiceClient = void 0;
6
+ const tslib_1 = require("tslib");
7
+ const core_rest_pipeline_1 = require("@azure/core-rest-pipeline");
8
+ const generatedClient_js_1 = require("./generated/generatedClient.js");
9
+ const groupClient_js_1 = require("./groupClient.js");
10
+ const core_auth_1 = require("@azure/core-auth");
11
+ const webPubSubCredentialPolicy_js_1 = require("./webPubSubCredentialPolicy.js");
12
+ const tracing_js_1 = require("./tracing.js");
13
+ const logger_js_1 = require("./logger.js");
14
+ const parseConnectionString_js_1 = require("./parseConnectionString.js");
15
+ const jsonwebtoken_1 = tslib_1.__importDefault(require("jsonwebtoken"));
16
+ const utils_js_1 = require("./utils.js");
17
+ const reverseProxyPolicy_js_1 = require("./reverseProxyPolicy.js");
18
+ /**
19
+ * Client for connecting to a Web PubSub hub
20
+ */
21
+ class WebPubSubServiceClient {
22
+ constructor(endpointOrConnectionString, credsOrHubName, hubNameOrOpts, opts) {
23
+ var _a, _b, _c, _d, _e, _f;
24
+ /**
25
+ * The Web PubSub API version being used by this client
26
+ */
27
+ this.apiVersion = "2024-01-01";
28
+ // unpack constructor arguments
29
+ if (typeof credsOrHubName === "object") {
30
+ this.endpoint = endpointOrConnectionString;
31
+ this.hubName = hubNameOrOpts;
32
+ this.clientOptions = opts;
33
+ this.credential = credsOrHubName;
34
+ }
35
+ else {
36
+ const parsedCs = (0, parseConnectionString_js_1.parseConnectionString)(endpointOrConnectionString);
37
+ this.endpoint = parsedCs.endpoint;
38
+ this.credential = parsedCs.credential;
39
+ this.hubName = credsOrHubName;
40
+ this.clientOptions = hubNameOrOpts;
41
+ }
42
+ const internalPipelineOptions = Object.assign(Object.assign(Object.assign({}, this.clientOptions), {
43
+ apiVersion: this.apiVersion,
44
+ loggingOptions: {
45
+ additionalAllowedHeaderNames: (_b = (_a = this.clientOptions) === null || _a === void 0 ? void 0 : _a.loggingOptions) === null || _b === void 0 ? void 0 : _b.additionalAllowedHeaderNames,
46
+ additionalAllowedQueryParameters: (_d = (_c = this.clientOptions) === null || _c === void 0 ? void 0 : _c.loggingOptions) === null || _d === void 0 ? void 0 : _d.additionalAllowedQueryParameters,
47
+ logger: logger_js_1.logger.info,
48
+ },
49
+ }), ((0, core_auth_1.isTokenCredential)(this.credential)
50
+ ? {
51
+ credential: this.credential,
52
+ credentialScopes: ["https://webpubsub.azure.com/.default"],
53
+ }
54
+ : {}));
55
+ this.client = new generatedClient_js_1.GeneratedClient(this.endpoint, internalPipelineOptions);
56
+ if (!(0, core_auth_1.isTokenCredential)(this.credential)) {
57
+ this.client.pipeline.addPolicy((0, webPubSubCredentialPolicy_js_1.webPubSubKeyCredentialPolicy)(this.credential));
58
+ }
59
+ if ((_e = this.clientOptions) === null || _e === void 0 ? void 0 : _e.reverseProxyEndpoint) {
60
+ this.client.pipeline.addPolicy((0, reverseProxyPolicy_js_1.webPubSubReverseProxyPolicy)((_f = this.clientOptions) === null || _f === void 0 ? void 0 : _f.reverseProxyEndpoint));
61
+ }
62
+ }
63
+ /**
64
+ * Get a client for a group
65
+ * @param groupName - The name of the group to connect to.
66
+ */
67
+ group(groupName) {
68
+ return new groupClient_js_1.WebPubSubGroupImpl(this.client, this.hubName, groupName);
69
+ }
70
+ async sendToAll(message, options = {}) {
71
+ return tracing_js_1.tracingClient.withSpan("WebPubSubServiceClient.sendToAll", options, (updatedOptions) => {
72
+ const { contentType, payload } = (0, utils_js_1.getPayloadForMessage)(message, updatedOptions);
73
+ return this.client.webPubSub.sendToAll(this.hubName, contentType, payload, updatedOptions);
74
+ });
75
+ }
76
+ async sendToUser(username, message, options = {}) {
77
+ return tracing_js_1.tracingClient.withSpan("WebPubSubServiceClient.sendToUser", options, (updatedOptions) => {
78
+ const { contentType, payload } = (0, utils_js_1.getPayloadForMessage)(message, updatedOptions);
79
+ return this.client.webPubSub.sendToUser(this.hubName, username, contentType, payload, updatedOptions);
80
+ });
81
+ }
82
+ async sendToConnection(connectionId, message, options = {}) {
83
+ return tracing_js_1.tracingClient.withSpan("WebPubSubServiceClient.sendToConnection", options, (updatedOptions) => {
84
+ const { contentType, payload } = (0, utils_js_1.getPayloadForMessage)(message, updatedOptions);
85
+ return this.client.webPubSub.sendToConnection(this.hubName, connectionId, contentType, payload, updatedOptions);
86
+ });
87
+ }
88
+ /**
89
+ * Check if a specific connection is connected to this hub
90
+ *
91
+ * @param connectionId - Connection id to check
92
+ * @param options - Additional options
93
+ */
94
+ async connectionExists(connectionId, options = {}) {
95
+ let response;
96
+ function onResponse(rawResponse, flatResponse) {
97
+ response = rawResponse;
98
+ if (options.onResponse) {
99
+ options.onResponse(rawResponse, flatResponse);
100
+ }
101
+ }
102
+ return tracing_js_1.tracingClient.withSpan("WebPubSubServiceClient.connectionExists", options, async (updatedOptions) => {
103
+ await this.client.webPubSub.connectionExists(this.hubName, connectionId, Object.assign(Object.assign({}, updatedOptions), { onResponse }));
104
+ if (response.status === 200) {
105
+ return true;
106
+ }
107
+ else if (response.status === 404) {
108
+ return false;
109
+ }
110
+ else {
111
+ // this is sad - wish this was handled by autorest.
112
+ throw new core_rest_pipeline_1.RestError(response.bodyAsText, {
113
+ statusCode: response === null || response === void 0 ? void 0 : response.status,
114
+ request: response === null || response === void 0 ? void 0 : response.request,
115
+ response: response,
116
+ });
117
+ }
118
+ });
119
+ }
120
+ /**
121
+ * Close a specific connection to this hub
122
+ *
123
+ * @param connectionId - Connection id to close
124
+ * @param options - Additional options
125
+ */
126
+ async closeConnection(connectionId, options = {}) {
127
+ return tracing_js_1.tracingClient.withSpan("WebPubSubServiceClient.closeConnection", options, (updatedOptions) => {
128
+ return this.client.webPubSub.closeConnection(this.hubName, connectionId, updatedOptions);
129
+ });
130
+ }
131
+ /**
132
+ * Close all connections to this hub
133
+ *
134
+ * @param options - Additional options
135
+ */
136
+ async closeAllConnections(options = {}) {
137
+ return tracing_js_1.tracingClient.withSpan("WebPubSubServiceClient.closeAllConnections", options, (updatedOptions) => {
138
+ return this.client.webPubSub.closeAllConnections(this.hubName, updatedOptions);
139
+ });
140
+ }
141
+ /**
142
+ * Close all connections with the given user id
143
+ *
144
+ * @param user - User id to close
145
+ * @param options - Additional options
146
+ */
147
+ async closeUserConnections(userId, options = {}) {
148
+ return tracing_js_1.tracingClient.withSpan("WebPubSubServiceClient.closeUserConnections", options, (updatedOptions) => {
149
+ return this.client.webPubSub.closeUserConnections(this.hubName, userId, updatedOptions);
150
+ });
151
+ }
152
+ /**
153
+ * Remove a specific user from all groups they are joined to
154
+ * @param userId - The user id to remove from all groups
155
+ * @param options - Additional options
156
+ */
157
+ async removeUserFromAllGroups(userId, options = {}) {
158
+ return tracing_js_1.tracingClient.withSpan("WebPubSubServiceClient.removeUserFromAllGroups", options, (updatedOptions) => {
159
+ return this.client.webPubSub.removeUserFromAllGroups(this.hubName, userId, updatedOptions);
160
+ });
161
+ }
162
+ /**
163
+ * Remove a specific connection from all groups they are joined to
164
+ * @param connectionId - The connection id to remove from all groups
165
+ * @param options - Additional options
166
+ */
167
+ async removeConnectionFromAllGroups(connectionId, options = {}) {
168
+ return tracing_js_1.tracingClient.withSpan("WebPubSubServiceClient.removeConnectionFromAllGroups", options, (updatedOptions) => {
169
+ return this.client.webPubSub.removeConnectionFromAllGroups(this.hubName, connectionId, updatedOptions);
170
+ });
171
+ }
172
+ /**
173
+ * Add filtered connections to multiple groups
174
+ * @param groups - A list of groups which target connections will be added into
175
+ * @param filter - An OData filter which target connections satisfy
176
+ * @param options - Additional options
177
+ */
178
+ async addConnectionsToGroups(groups, filter, options = {}) {
179
+ return tracing_js_1.tracingClient.withSpan("WebPubSubServiceClient.addConnectionsToGroups", options, (updatedOptions) => {
180
+ return this.client.webPubSub.addConnectionsToGroups(this.hubName, {
181
+ groups: groups,
182
+ filter: filter,
183
+ }, updatedOptions);
184
+ });
185
+ }
186
+ /**
187
+ * Remove filtered connections from multiple groups
188
+ * @param groups - A list of groups which target connections will be removed from
189
+ * @param filter - An OData filter which target connections satisfy
190
+ * @param options - Additional options
191
+ */
192
+ async removeConnectionsFromGroups(groups, filter, options = {}) {
193
+ return tracing_js_1.tracingClient.withSpan("WebPubSubServiceClient.removeConnectionsFromGroups", options, (updatedOptions) => {
194
+ return this.client.webPubSub.removeConnectionsFromGroups(this.hubName, {
195
+ groups: groups,
196
+ filter: filter,
197
+ }, updatedOptions);
198
+ });
199
+ }
200
+ /**
201
+ * Check if a particular group exists (i.e. has active connections).
202
+ *
203
+ * @param groupName - The group name to check for
204
+ * @param options - Additional options
205
+ */
206
+ async groupExists(groupName, options = {}) {
207
+ let response;
208
+ function onResponse(rawResponse, flatResponse) {
209
+ response = rawResponse;
210
+ if (options.onResponse) {
211
+ options.onResponse(rawResponse, flatResponse);
212
+ }
213
+ }
214
+ return tracing_js_1.tracingClient.withSpan("WebPubSubServiceClient.groupExists", options, async (updatedOptions) => {
215
+ await this.client.webPubSub.groupExists(this.hubName, groupName, Object.assign(Object.assign({}, updatedOptions), { onResponse }));
216
+ if (response.status === 200) {
217
+ return true;
218
+ }
219
+ else if (response.status === 404) {
220
+ return false;
221
+ }
222
+ else {
223
+ throw new core_rest_pipeline_1.RestError(response.bodyAsText, {
224
+ statusCode: response === null || response === void 0 ? void 0 : response.status,
225
+ request: response === null || response === void 0 ? void 0 : response.request,
226
+ response: response,
227
+ });
228
+ }
229
+ });
230
+ }
231
+ /**
232
+ * Check if a particular user is connected to this hub.
233
+ *
234
+ * @param username - The user name to check for
235
+ * @param options - Additional options
236
+ */
237
+ async userExists(username, options = {}) {
238
+ let response;
239
+ function onResponse(rawResponse, flatResponse) {
240
+ response = rawResponse;
241
+ if (options.onResponse) {
242
+ options.onResponse(rawResponse, flatResponse);
243
+ }
244
+ }
245
+ return tracing_js_1.tracingClient.withSpan("WebPubSubServiceClient.userExists", options, async (updatedOptions) => {
246
+ await this.client.webPubSub.userExists(this.hubName, username, Object.assign(Object.assign({}, updatedOptions), { onResponse }));
247
+ if (response.status === 200) {
248
+ return true;
249
+ }
250
+ else if (response.status === 404) {
251
+ return false;
252
+ }
253
+ else {
254
+ // this is sad - wish this was handled by autorest.
255
+ throw new core_rest_pipeline_1.RestError(response.bodyAsText, {
256
+ statusCode: response === null || response === void 0 ? void 0 : response.status,
257
+ request: response === null || response === void 0 ? void 0 : response.request,
258
+ response: response,
259
+ });
260
+ }
261
+ });
262
+ }
263
+ /**
264
+ * Grant permissions to a connection
265
+ *
266
+ * @param connectionId - The connection id to grant permissions to
267
+ * @param Permission - The permission to grant
268
+ * @param options - Additional options
269
+ */
270
+ async grantPermission(connectionId, permission, options = {}) {
271
+ return tracing_js_1.tracingClient.withSpan("WebPubSubServiceClient.grantPermission", options, (updatedOptions) => {
272
+ return this.client.webPubSub.grantPermission(this.hubName, permission, connectionId, updatedOptions);
273
+ });
274
+ }
275
+ /**
276
+ * Revoke permissions from a connection
277
+ *
278
+ * @param connectionId - The connection id to revoke permissions from
279
+ * @param Permission - The permission to revoke
280
+ * @param options - Additional options
281
+ */
282
+ async revokePermission(connectionId, permission, options = {}) {
283
+ return tracing_js_1.tracingClient.withSpan("WebPubSubServiceClient.revokePermission", options, (updatedOptions) => {
284
+ return this.client.webPubSub.revokePermission(this.hubName, permission, connectionId, updatedOptions);
285
+ });
286
+ }
287
+ /**
288
+ * Check if the connection has the specified permission
289
+ *
290
+ * @param connectionId - The connection id to check permission
291
+ * @param Permission - The permission to check
292
+ * @param options - Additional options
293
+ */
294
+ async hasPermission(connectionId, permission, options = {}) {
295
+ let response;
296
+ function onResponse(rawResponse, flatResponse) {
297
+ response = rawResponse;
298
+ if (options.onResponse) {
299
+ options.onResponse(rawResponse, flatResponse);
300
+ }
301
+ }
302
+ return tracing_js_1.tracingClient.withSpan("WebPubSubServiceClient.hasPermission", options, async (updatedOptions) => {
303
+ await this.client.webPubSub.checkPermission(this.hubName, permission, connectionId, Object.assign(Object.assign({}, updatedOptions), { onResponse }));
304
+ if (response.status === 200) {
305
+ return true;
306
+ }
307
+ else if (response.status === 404) {
308
+ return false;
309
+ }
310
+ else {
311
+ // this is sad - wish this was handled by autorest.
312
+ throw new core_rest_pipeline_1.RestError(response.bodyAsText, {
313
+ statusCode: response === null || response === void 0 ? void 0 : response.status,
314
+ request: response === null || response === void 0 ? void 0 : response.request,
315
+ response: response,
316
+ });
317
+ }
318
+ });
319
+ }
320
+ /**
321
+ * Generate a token for a client to connect to the Azure Web PubSub service.
322
+ *
323
+ * @param options - Additional options
324
+ */
325
+ async getClientAccessToken(options = {}) {
326
+ return tracing_js_1.tracingClient.withSpan("WebPubSubServiceClient.getClientAccessToken", options, async (updatedOptions) => {
327
+ const endpoint = this.endpoint.endsWith("/") ? this.endpoint : this.endpoint + "/";
328
+ const clientEndpoint = endpoint.replace(/(http)(s?:\/\/)/gi, "ws$2");
329
+ const clientProtocol = updatedOptions.clientProtocol;
330
+ let clientPath = `client/hubs/${this.hubName}`;
331
+ switch (clientProtocol) {
332
+ case "mqtt":
333
+ clientPath = `clients/mqtt/hubs/${this.hubName}`;
334
+ break;
335
+ case "socketio":
336
+ clientPath = `clients/socketio/hubs/${this.hubName}`;
337
+ }
338
+ const baseUrl = clientEndpoint + clientPath;
339
+ let token;
340
+ if ((0, core_auth_1.isTokenCredential)(this.credential)) {
341
+ const response = await this.client.webPubSub.generateClientToken(this.hubName, Object.assign(Object.assign({}, updatedOptions), { clientType: clientProtocol }));
342
+ token = response.token;
343
+ }
344
+ else {
345
+ const key = this.credential.key;
346
+ const audience = endpoint + clientPath;
347
+ const payload = {
348
+ role: updatedOptions === null || updatedOptions === void 0 ? void 0 : updatedOptions.roles,
349
+ "webpubsub.group": updatedOptions === null || updatedOptions === void 0 ? void 0 : updatedOptions.groups,
350
+ };
351
+ const signOptions = {
352
+ audience: audience,
353
+ expiresIn: (updatedOptions === null || updatedOptions === void 0 ? void 0 : updatedOptions.expirationTimeInMinutes) === undefined
354
+ ? "1h"
355
+ : `${updatedOptions.expirationTimeInMinutes}m`,
356
+ algorithm: "HS256",
357
+ };
358
+ if (updatedOptions === null || updatedOptions === void 0 ? void 0 : updatedOptions.userId) {
359
+ signOptions.subject = updatedOptions === null || updatedOptions === void 0 ? void 0 : updatedOptions.userId;
360
+ }
361
+ token = jsonwebtoken_1.default.sign(payload, key, signOptions);
362
+ }
363
+ return {
364
+ token,
365
+ baseUrl,
366
+ url: `${baseUrl}?access_token=${token}`,
367
+ };
368
+ });
369
+ }
370
+ }
371
+ exports.WebPubSubServiceClient = WebPubSubServiceClient;
372
+ //# sourceMappingURL=hubClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hubClient.js","sourceRoot":"","sources":["../../src/hubClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAQlC,kEAAsD;AACtD,uEAAiE;AAMjE,qDAAsD;AAEtD,gDAAqD;AACrD,iFAA8E;AAC9E,6CAA6C;AAC7C,2CAAqC;AACrC,yEAAmE;AACnE,wEAA+B;AAC/B,yCAAkD;AAMlD,mEAAsE;AAmRtE;;GAEG;AACH,MAAa,sBAAsB;IAyDjC,YACE,0BAAkC,EAClC,cAA8D,EAC9D,aAAsD,EACtD,IAAoC;;QApDtC;;W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;gBACH,KAAK,GAAG,QAAQ,CAAC,KAAM,CAAC;YAC1B,CAAC;iBAAM,CAAC;gBACN,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;gBAChC,MAAM,QAAQ,GAAG,QAAQ,GAAG,UAAU,CAAC;gBACvC,MAAM,OAAO,GAAG;oBACd,IAAI,EAAE,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,KAAK;oBAC3B,iBAAiB,EAAE,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,MAAM;iBAC1C,CAAC;gBACF,MAAM,WAAW,GAAoB;oBACnC,QAAQ,EAAE,QAAQ;oBAClB,SAAS,EACP,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,uBAAuB,MAAK,SAAS;wBACnD,CAAC,CAAC,IAAI;wBACN,CAAC,CAAC,GAAG,cAAc,CAAC,uBAAuB,GAAG;oBAClD,SAAS,EAAE,OAAO;iBACnB,CAAC;gBACF,IAAI,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,MAAM,EAAE,CAAC;oBAC3B,WAAW,CAAC,OAAO,GAAG,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,MAAM,CAAC;gBAC/C,CAAC;gBACD,KAAK,GAAG,sBAAG,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;YAC9C,CAAC;YAED,OAAO;gBACL,KAAK;gBACL,OAAO;gBACP,GAAG,EAAE,GAAG,OAAO,iBAAiB,KAAK,EAAE;aACxC,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAhsBD,wDAgsBC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n CommonClientOptions,\n FullOperationResponse,\n OperationOptions,\n} from \"@azure/core-client\";\nimport type { RequestBodyType } from \"@azure/core-rest-pipeline\";\nimport { RestError } from \"@azure/core-rest-pipeline\";\nimport { GeneratedClient } from \"./generated/generatedClient.js\";\nimport type {\n WebPubSubGroup,\n GroupAddConnectionOptions,\n GroupRemoveConnectionOptions,\n} from \"./groupClient.js\";\nimport { WebPubSubGroupImpl } from \"./groupClient.js\";\nimport type { AzureKeyCredential, TokenCredential } from \"@azure/core-auth\";\nimport { isTokenCredential } from \"@azure/core-auth\";\nimport { webPubSubKeyCredentialPolicy } from \"./webPubSubCredentialPolicy.js\";\nimport { tracingClient } from \"./tracing.js\";\nimport { logger } from \"./logger.js\";\nimport { parseConnectionString } from \"./parseConnectionString.js\";\nimport jwt from \"jsonwebtoken\";\nimport { getPayloadForMessage } from \"./utils.js\";\nimport type {\n GeneratedClientOptionalParams,\n AddToGroupsRequest,\n RemoveFromGroupsRequest,\n} from \"./generated/index.js\";\nimport { webPubSubReverseProxyPolicy } from \"./reverseProxyPolicy.js\";\n\n/**\n * Options for closing a connection to a hub.\n */\nexport interface HubCloseConnectionOptions extends OperationOptions {\n /**\n * Reason the connection is being closed.\n */\n reason?: string;\n}\n\n/**\n * Options for closing all connections to a hub.\n */\nexport interface HubCloseAllConnectionsOptions extends OperationOptions {\n /**\n * Reason the connection is being closed.\n */\n reason?: string;\n}\n\n/**\n * Options for closing all of a user's connections to a hub.\n */\nexport interface HubCloseUserConnectionsOptions extends OperationOptions {\n /**\n * Reason the connection is being closed.\n */\n reason?: string;\n}\n\n/**\n * Options for sending messages to hubs.\n */\nexport interface HubSendToAllOptions extends OperationOptions {\n /**\n * Connection ids to exclude from receiving this message.\n */\n excludedConnections?: string[];\n /**\n * The filter syntax to filter out the connections to send the messages to following OData filter syntax.\n * Examples:\n * * Exclude connections from `user1` and `user2`: `userId ne 'user1' and userId ne 'user2'`\n * * Exclude connections in `group1`: `not('group1' in groups)`\n * Details about `filter` syntax please see [OData filter syntax for Azure Web PubSub](https://aka.ms/awps/filter-syntax).\n */\n filter?: string;\n /**\n * The time-to-live (TTL) value in seconds for messages sent to the service.\n * 0 is the default value, which means the message never expires.\n * 300 is the maximum value.\n * If this parameter is non-zero, messages that are not consumed by the client within the specified TTL will be dropped by the service.\n * This parameter can help when the client's bandwidth is limited.\n */\n messageTtlSeconds?: number;\n}\n\n/**\n * Options for sending text messages to hubs.\n */\nexport interface HubSendTextToAllOptions extends HubSendToAllOptions {\n /**\n * The content will be sent to the clients in plain text.\n */\n contentType: \"text/plain\";\n}\n\n/**\n * Types which can be serialized and sent as JSON.\n */\nexport type JSONTypes = string | number | boolean | object;\n\n/**\n * Options for constructing a HubAdmin client.\n */\nexport interface WebPubSubServiceClientOptions extends CommonClientOptions {\n /**\n * Reverse proxy endpoint (for example, your Azure API management endpoint)\n */\n reverseProxyEndpoint?: string;\n /**\n * Options to configure the logging options.\n */\n loggingOptions?: WebPubSubServiceClientLogOptions;\n}\n\n/**\n * Options to configure the logging options.\n */\nexport declare interface WebPubSubServiceClientLogOptions {\n /**\n * Header names whose values will be logged when logging is enabled.\n * Defaults include a list of well-known safe headers. Any headers\n * specified in this field will be added to that list. Any other values will\n * be written to logs as \"REDACTED\".\n */\n additionalAllowedHeaderNames?: string[];\n /**\n * Query string names whose values will be logged when logging is enabled. By default no\n * query string values are logged.\n */\n additionalAllowedQueryParameters?: string[];\n}\n\n/**\n * Options for checking if a connection exists.\n */\nexport interface HasConnectionOptions extends OperationOptions {}\n\n/**\n * Options for checking if a group exists.\n */\nexport interface HubHasGroupOptions extends OperationOptions {}\n\n/**\n * Options for checking if a user exists.\n */\nexport interface HubHasUserOptions extends OperationOptions {}\n\n/**\n * Options for removing a user from all groups.\n */\nexport interface HubRemoveUserFromAllGroupsOptions extends HubCloseConnectionOptions {}\n\n/**\n * Options for sending a message to a specific connection.\n */\nexport interface HubSendToConnectionOptions extends OperationOptions {\n /**\n * The time-to-live (TTL) value in seconds for messages sent to the service.\n * 0 is the default value, which means the message never expires.\n * 300 is the maximum value.\n * If this parameter is non-zero, messages that are not consumed by the client within the specified TTL will be dropped by the service.\n * This parameter can help when the client's bandwidth is limited.\n */\n messageTtlSeconds?: number;\n}\n\n/**\n * Options for sending a text message to a connection.\n */\nexport interface HubSendTextToConnectionOptions extends HubSendToConnectionOptions {\n contentType: \"text/plain\";\n}\n\n/**\n * Options for sending a message to a user.\n */\nexport interface HubSendToUserOptions extends OperationOptions {\n /**\n * The filter syntax to filter out the connections to send the messages to following OData filter syntax.\n * Examples:\n * * Exclude connections in `group1`: `not('group1' in groups)`\n * * Send to connections in `group1` or `group2`: `'group1' in groups or `group2` in groups`\n * Details about `filter` syntax please see [OData filter syntax for Azure Web PubSub](https://aka.ms/awps/filter-syntax).\n */\n filter?: string;\n /**\n * The time-to-live (TTL) value in seconds for messages sent to the service.\n * 0 is the default value, which means the message never expires.\n * 300 is the maximum value.\n * If this parameter is non-zero, messages that are not consumed by the client within the specified TTL will be dropped by the service.\n * This parameter can help when the client's bandwidth is limited.\n */\n messageTtlSeconds?: number;\n}\n\n/**\n * Options for sending a text message to a user.\n */\nexport interface HubSendTextToUserOptions extends HubSendToUserOptions {\n /**\n * The content will be sent to the clients in plain text.\n */\n contentType: \"text/plain\";\n}\n\nexport type Permission = \"joinLeaveGroup\" | \"sendToGroup\";\n\n/**\n * Options for grant permissions to a connection\n */\nexport interface HubGrantPermissionOptions extends OperationOptions {\n /**\n * The meaning of the target depends on the specific permission.\n * For joinLeaveGroup and sendToGroup, targetName is a required parameter standing for the group name.\n */\n targetName?: string;\n}\n\n/**\n * Options for revoke permissions from a connection\n */\nexport interface HubRevokePermissionOptions extends OperationOptions {\n /**\n * The meaning of the target depends on the specific permission.\n * For joinLeaveGroup and sendToGroup, targetName is a required parameter standing for the group name.\n */\n targetName?: string;\n}\n\n/**\n * Options for checking if a connection has the specified permission\n */\nexport interface HubHasPermissionOptions extends OperationOptions {\n /**\n * The meaning of the target depends on the specific permission.\n * For joinLeaveGroup and sendToGroup, targetName is a required parameter standing for the group name.\n */\n targetName?: string;\n}\n\n/**\n * The type of client endpoint that is being requested.\n */\nexport type WebPubSubClientProtocol = \"default\" | \"mqtt\" | \"socketio\";\n\n/**\n * Options for generating a token to connect a client to the Azure Web Pubsub service.\n */\nexport interface GenerateClientTokenOptions extends OperationOptions {\n /**\n * The userId for the client.\n */\n userId?: string;\n\n /**\n * The roles that the connection with the generated token will have.\n * Roles give the client initial permissions to leave, join, or publish to groups when using PubSub subprotocol\n * * `webpubsub.joinLeaveGroup`: the client can join or leave any group\n * * `webpubsub.sendToGroup`: the client can send messages to any group\n * * `webpubsub.joinLeaveGroup.<group>`: the client can join or leave group `<group>`\n * * `webpubsub.sendToGroup.<group>`: the client can send messages to group `<group>`\n *\n * {@link https://azure.github.io/azure-webpubsub/references/pubsub-websocket-subprotocol#permissions}\n */\n roles?: string[];\n\n /**\n * Minutes until the token expires.\n */\n expirationTimeInMinutes?: number;\n\n /**\n * The groups to join when the client connects\n */\n groups?: string[];\n\n /**\n * The protocol type of the client\n * * `default`: Default WebPubSub Client. Example Client Connection URL: _wss://exampleHost.com/client/hubs/exampleHub_\n * * `mqtt`: MQTT Client. Example Client Connection URL: _wss://exampleHost.com/client/mqtt/hubs/exampleHub_\n */\n clientProtocol?: WebPubSubClientProtocol;\n}\n\n/**\n * A response containing the client token.\n */\nexport interface ClientTokenResponse {\n /**\n * The client token.\n */\n token: string;\n /**\n * The URL client connects to\n */\n baseUrl: string;\n /**\n * The URL client connects to with access_token query string\n */\n url: string;\n}\n\n/**\n * Client for connecting to a Web PubSub hub\n */\nexport class WebPubSubServiceClient {\n private readonly client: GeneratedClient;\n private credential!: AzureKeyCredential | TokenCredential;\n private readonly clientOptions?: WebPubSubServiceClientOptions;\n\n /**\n * The name of the hub this client is connected to\n */\n public readonly hubName: string;\n /**\n * The Web PubSub API version being used by this client\n */\n public readonly apiVersion: string = \"2024-01-01\";\n\n /**\n * The Web PubSub endpoint this client is connected to\n */\n public endpoint!: string;\n\n /**\n * Creates an instance of a WebPubSubServiceClient for sending messages and managing groups, connections, and users.\n *\n * Example usage:\n * ```ts\n * import { WebPubSubServiceClient } from \"@azure/web-pubsub\";\n * const connectionString = process.env['WEB_PUBSUB_CONNECTION_STRING'];\n * const client = new WebPubSubServiceClient(connectionString, 'chat');\n * ```\n *\n * @param connectionString - The connection string\n * @param hubName - The name of the hub to connect to. If omitted, '_default' is used.\n * @param options - Options to configure the http pipeline\n */\n constructor(connectionString: string, hubName: string, options?: WebPubSubServiceClientOptions);\n\n /**\n * Creates an instance of a WebPubSubServiceClient for sending messages and managing groups, connections, and users.\n *\n * Example usage:\n * ```ts\n * import { WebPubSubServiceClient, AzureKeyCredential } from \"@azure/web-pubsub\";\n * const cred = new AzureKeyCredential(\"<your web pubsub api key>\");\n * const endpoint = \"https://xxxx.webpubsubdev.azure.com\"\n * const client = new WebPubSubServiceClient(endpoint, cred, 'chat');\n * ```\n *\n * @param endpoint - The endpoint to connect to\n * @param credential - An AzureKeyCredential holding your service key\n * @param hubName - The name of the hub to connect to.\n * @param options - Options to configure the http pipeline\n */\n constructor(\n endpoint: string,\n credential: AzureKeyCredential | TokenCredential,\n hubName: string,\n options?: WebPubSubServiceClientOptions,\n );\n constructor(\n endpointOrConnectionString: string,\n credsOrHubName?: AzureKeyCredential | TokenCredential | string,\n hubNameOrOpts?: string | WebPubSubServiceClientOptions,\n opts?: WebPubSubServiceClientOptions,\n ) {\n // unpack constructor arguments\n if (typeof credsOrHubName === \"object\") {\n this.endpoint = endpointOrConnectionString;\n this.hubName = hubNameOrOpts as string;\n this.clientOptions = opts;\n this.credential = credsOrHubName;\n } else {\n const parsedCs = parseConnectionString(endpointOrConnectionString);\n this.endpoint = parsedCs.endpoint;\n this.credential = parsedCs.credential;\n this.hubName = credsOrHubName as string;\n this.clientOptions = hubNameOrOpts as WebPubSubServiceClientOptions;\n }\n\n const internalPipelineOptions: GeneratedClientOptionalParams = {\n ...this.clientOptions,\n ...{\n apiVersion: this.apiVersion,\n loggingOptions: {\n additionalAllowedHeaderNames:\n this.clientOptions?.loggingOptions?.additionalAllowedHeaderNames,\n additionalAllowedQueryParameters:\n this.clientOptions?.loggingOptions?.additionalAllowedQueryParameters,\n logger: logger.info,\n },\n },\n ...(isTokenCredential(this.credential)\n ? {\n credential: this.credential,\n credentialScopes: [\"https://webpubsub.azure.com/.default\"],\n }\n : {}),\n };\n\n this.client = new GeneratedClient(this.endpoint, internalPipelineOptions);\n\n if (!isTokenCredential(this.credential)) {\n this.client.pipeline.addPolicy(webPubSubKeyCredentialPolicy(this.credential));\n }\n\n if (this.clientOptions?.reverseProxyEndpoint) {\n this.client.pipeline.addPolicy(\n webPubSubReverseProxyPolicy(this.clientOptions?.reverseProxyEndpoint),\n );\n }\n }\n\n /**\n * Get a client for a group\n * @param groupName - The name of the group to connect to.\n */\n public group(groupName: string): WebPubSubGroup {\n return new WebPubSubGroupImpl(this.client, this.hubName, groupName);\n }\n\n /**\n * Broadcast a text message to all connections on this hub.\n *\n * @param message - The text message to send\n * @param options - Additional options\n */\n // eslint-disable-next-line @azure/azure-sdk/ts-naming-options\n public async sendToAll(message: string, options: HubSendTextToAllOptions): Promise<void>;\n /**\n * Broadcast a JSON message to all connections on this hub.\n *\n * @param message - The JSON message to send\n * @param options - Additional options\n */\n public async sendToAll(message: JSONTypes, options?: HubSendToAllOptions): Promise<void>;\n /**\n * Broadcast a binary message to all connections on this hub.\n *\n * @param message - The message to send\n * @param options - Additional options\n */\n public async sendToAll(message: RequestBodyType, options?: HubSendToAllOptions): Promise<void>;\n\n public async sendToAll(\n message: RequestBodyType | JSONTypes,\n options: HubSendToAllOptions | HubSendTextToAllOptions = {},\n ): Promise<void> {\n return tracingClient.withSpan(\"WebPubSubServiceClient.sendToAll\", options, (updatedOptions) => {\n const { contentType, payload } = getPayloadForMessage(message, updatedOptions);\n return this.client.webPubSub.sendToAll(\n this.hubName,\n contentType,\n payload as any,\n updatedOptions,\n );\n });\n }\n\n /**\n * Send a text message to a specific user\n *\n * @param username - User name to send to\n * @param message - The text message to send\n * @param options - Additional options\n */\n public async sendToUser(\n username: string,\n message: string,\n // eslint-disable-next-line @azure/azure-sdk/ts-naming-options\n options: HubSendTextToUserOptions,\n ): Promise<void>;\n\n /**\n * Send a JSON message to a specific user\n *\n * @param username - User name to send to\n * @param message - The josn message to send\n * @param options - Additional options\n */\n public async sendToUser(\n username: string,\n message: JSONTypes,\n options?: HubSendToUserOptions,\n ): Promise<void>;\n\n /**\n * Send a binary message to a specific user\n *\n * @param username - The user name to send to\n * @param message - The binary message to send\n * @param options - Additional options\n */\n public async sendToUser(\n username: string,\n message: RequestBodyType,\n options?: HubSendToUserOptions | HubSendTextToUserOptions,\n ): Promise<void>;\n public async sendToUser(\n username: string,\n message: RequestBodyType | JSONTypes,\n options: HubSendToUserOptions = {},\n ): Promise<void> {\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.sendToUser\",\n options,\n (updatedOptions) => {\n const { contentType, payload } = getPayloadForMessage(message, updatedOptions);\n return this.client.webPubSub.sendToUser(\n this.hubName,\n username,\n contentType,\n payload as any,\n updatedOptions,\n );\n },\n );\n }\n\n /**\n * Send a text message to a specific connection\n *\n * @param connectionId - Connection id to send to\n * @param message - The text message\n * @param options - Additional options\n */\n public async sendToConnection(\n connectionId: string,\n message: string,\n // eslint-disable-next-line @azure/azure-sdk/ts-naming-options\n options: HubSendTextToConnectionOptions,\n ): Promise<void>;\n\n /**\n * Send a binary message to a specific connection\n *\n * @param connectionId - Connection id to send to\n * @param message - The JSON message\n * @param options - Additional options\n */\n public async sendToConnection(\n connectionId: string,\n message: JSONTypes,\n options?: HubSendToConnectionOptions,\n ): Promise<void>;\n\n /**\n * Send a binary message to a specific connection\n *\n * @param connectionId - Connection id to send to\n * @param message - The binary message\n * @param options - Additional options\n */\n public async sendToConnection(\n connectionId: string,\n message: RequestBodyType,\n options?: HubSendToConnectionOptions | HubSendTextToConnectionOptions,\n ): Promise<void>;\n public async sendToConnection(\n connectionId: string,\n message: RequestBodyType | JSONTypes,\n options: HubSendToConnectionOptions = {},\n ): Promise<void> {\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.sendToConnection\",\n options,\n (updatedOptions) => {\n const { contentType, payload } = getPayloadForMessage(message, updatedOptions);\n\n return this.client.webPubSub.sendToConnection(\n this.hubName,\n connectionId,\n contentType,\n payload as any,\n updatedOptions,\n );\n },\n );\n }\n\n /**\n * Check if a specific connection is connected to this hub\n *\n * @param connectionId - Connection id to check\n * @param options - Additional options\n */\n public async connectionExists(\n connectionId: string,\n options: HasConnectionOptions = {},\n ): Promise<boolean> {\n let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (options.onResponse) {\n options.onResponse(rawResponse, flatResponse);\n }\n }\n\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.connectionExists\",\n options,\n async (updatedOptions) => {\n await this.client.webPubSub.connectionExists(this.hubName, connectionId, {\n ...updatedOptions,\n onResponse,\n });\n\n if (response!.status === 200) {\n return true;\n } else if (response!.status === 404) {\n return false;\n } else {\n // this is sad - wish this was handled by autorest.\n throw new RestError(response!.bodyAsText!, {\n statusCode: response?.status,\n request: response?.request,\n response: response,\n });\n }\n },\n );\n }\n\n /**\n * Close a specific connection to this hub\n *\n * @param connectionId - Connection id to close\n * @param options - Additional options\n */\n public async closeConnection(\n connectionId: string,\n options: HubCloseConnectionOptions = {},\n ): Promise<void> {\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.closeConnection\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.closeConnection(this.hubName, connectionId, updatedOptions);\n },\n );\n }\n\n /**\n * Close all connections to this hub\n *\n * @param options - Additional options\n */\n public async closeAllConnections(options: HubCloseAllConnectionsOptions = {}): Promise<void> {\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.closeAllConnections\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.closeAllConnections(this.hubName, updatedOptions);\n },\n );\n }\n\n /**\n * Close all connections with the given user id\n *\n * @param user - User id to close\n * @param options - Additional options\n */\n public async closeUserConnections(\n userId: string,\n options: HubCloseUserConnectionsOptions = {},\n ): Promise<void> {\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.closeUserConnections\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.closeUserConnections(this.hubName, userId, updatedOptions);\n },\n );\n }\n\n /**\n * Remove a specific user from all groups they are joined to\n * @param userId - The user id to remove from all groups\n * @param options - Additional options\n */\n public async removeUserFromAllGroups(\n userId: string,\n options: HubCloseConnectionOptions = {},\n ): Promise<void> {\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.removeUserFromAllGroups\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.removeUserFromAllGroups(this.hubName, userId, updatedOptions);\n },\n );\n }\n\n /**\n * Remove a specific connection from all groups they are joined to\n * @param connectionId - The connection id to remove from all groups\n * @param options - Additional options\n */\n public async removeConnectionFromAllGroups(\n connectionId: string,\n options: HubCloseConnectionOptions = {},\n ): Promise<void> {\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.removeConnectionFromAllGroups\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.removeConnectionFromAllGroups(\n this.hubName,\n connectionId,\n updatedOptions,\n );\n },\n );\n }\n\n /**\n * Add filtered connections to multiple groups\n * @param groups - A list of groups which target connections will be added into\n * @param filter - An OData filter which target connections satisfy\n * @param options - Additional options\n */\n public async addConnectionsToGroups(\n groups: string[],\n filter: string,\n options: GroupAddConnectionOptions = {},\n ): Promise<void> {\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.addConnectionsToGroups\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.addConnectionsToGroups(\n this.hubName,\n {\n groups: groups,\n filter: filter,\n } as AddToGroupsRequest,\n updatedOptions,\n );\n },\n );\n }\n\n /**\n * Remove filtered connections from multiple groups\n * @param groups - A list of groups which target connections will be removed from\n * @param filter - An OData filter which target connections satisfy\n * @param options - Additional options\n */\n public async removeConnectionsFromGroups(\n groups: string[],\n filter: string,\n options: GroupRemoveConnectionOptions = {},\n ): Promise<void> {\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.removeConnectionsFromGroups\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.removeConnectionsFromGroups(\n this.hubName,\n {\n groups: groups,\n filter: filter,\n } as RemoveFromGroupsRequest,\n updatedOptions,\n );\n },\n );\n }\n\n /**\n * Check if a particular group exists (i.e. has active connections).\n *\n * @param groupName - The group name to check for\n * @param options - Additional options\n */\n public async groupExists(groupName: string, options: HubHasGroupOptions = {}): Promise<boolean> {\n let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (options.onResponse) {\n options.onResponse(rawResponse, flatResponse);\n }\n }\n\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.groupExists\",\n options,\n async (updatedOptions) => {\n await this.client.webPubSub.groupExists(this.hubName, groupName, {\n ...updatedOptions,\n onResponse,\n });\n\n if (response!.status === 200) {\n return true;\n } else if (response!.status === 404) {\n return false;\n } else {\n throw new RestError(response!.bodyAsText!, {\n statusCode: response?.status,\n request: response?.request,\n response: response,\n });\n }\n },\n );\n }\n\n /**\n * Check if a particular user is connected to this hub.\n *\n * @param username - The user name to check for\n * @param options - Additional options\n */\n public async userExists(username: string, options: HubHasUserOptions = {}): Promise<boolean> {\n let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (options.onResponse) {\n options.onResponse(rawResponse, flatResponse);\n }\n }\n\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.userExists\",\n options,\n async (updatedOptions) => {\n await this.client.webPubSub.userExists(this.hubName, username, {\n ...updatedOptions,\n onResponse,\n });\n\n if (response!.status === 200) {\n return true;\n } else if (response!.status === 404) {\n return false;\n } else {\n // this is sad - wish this was handled by autorest.\n throw new RestError(response!.bodyAsText!, {\n statusCode: response?.status,\n request: response?.request,\n response: response,\n });\n }\n },\n );\n }\n\n /**\n * Grant permissions to a connection\n *\n * @param connectionId - The connection id to grant permissions to\n * @param Permission - The permission to grant\n * @param options - Additional options\n */\n public async grantPermission(\n connectionId: string,\n permission: Permission,\n options: HubGrantPermissionOptions = {},\n ): Promise<void> {\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.grantPermission\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.grantPermission(\n this.hubName,\n permission,\n connectionId,\n updatedOptions,\n );\n },\n );\n }\n\n /**\n * Revoke permissions from a connection\n *\n * @param connectionId - The connection id to revoke permissions from\n * @param Permission - The permission to revoke\n * @param options - Additional options\n */\n public async revokePermission(\n connectionId: string,\n permission: Permission,\n options: HubRevokePermissionOptions = {},\n ): Promise<void> {\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.revokePermission\",\n options,\n (updatedOptions) => {\n return this.client.webPubSub.revokePermission(\n this.hubName,\n permission,\n connectionId,\n updatedOptions,\n );\n },\n );\n }\n\n /**\n * Check if the connection has the specified permission\n *\n * @param connectionId - The connection id to check permission\n * @param Permission - The permission to check\n * @param options - Additional options\n */\n public async hasPermission(\n connectionId: string,\n permission: Permission,\n options: HubHasPermissionOptions = {},\n ): Promise<boolean> {\n let response: FullOperationResponse | undefined;\n function onResponse(rawResponse: FullOperationResponse, flatResponse: unknown): void {\n response = rawResponse;\n if (options.onResponse) {\n options.onResponse(rawResponse, flatResponse);\n }\n }\n\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.hasPermission\",\n options,\n async (updatedOptions) => {\n await this.client.webPubSub.checkPermission(this.hubName, permission, connectionId, {\n ...updatedOptions,\n onResponse,\n });\n\n if (response!.status === 200) {\n return true;\n } else if (response!.status === 404) {\n return false;\n } else {\n // this is sad - wish this was handled by autorest.\n throw new RestError(response!.bodyAsText!, {\n statusCode: response?.status,\n request: response?.request,\n response: response,\n });\n }\n },\n );\n }\n\n /**\n * Generate a token for a client to connect to the Azure Web PubSub service.\n *\n * @param options - Additional options\n */\n public async getClientAccessToken(\n options: GenerateClientTokenOptions = {},\n ): Promise<ClientTokenResponse> {\n return tracingClient.withSpan(\n \"WebPubSubServiceClient.getClientAccessToken\",\n options,\n async (updatedOptions) => {\n const endpoint = this.endpoint.endsWith(\"/\") ? this.endpoint : this.endpoint + \"/\";\n const clientEndpoint = endpoint.replace(/(http)(s?:\\/\\/)/gi, \"ws$2\");\n const clientProtocol = updatedOptions.clientProtocol;\n let clientPath = `client/hubs/${this.hubName}`;\n switch (clientProtocol) {\n case \"mqtt\":\n clientPath = `clients/mqtt/hubs/${this.hubName}`;\n break;\n case \"socketio\":\n clientPath = `clients/socketio/hubs/${this.hubName}`;\n }\n const baseUrl = clientEndpoint + clientPath;\n\n let token: string;\n if (isTokenCredential(this.credential)) {\n const response = await this.client.webPubSub.generateClientToken(this.hubName, {\n ...updatedOptions,\n clientType: clientProtocol,\n });\n token = response.token!;\n } else {\n const key = this.credential.key;\n const audience = endpoint + clientPath;\n const payload = {\n role: updatedOptions?.roles,\n \"webpubsub.group\": updatedOptions?.groups,\n };\n const signOptions: jwt.SignOptions = {\n audience: audience,\n expiresIn:\n updatedOptions?.expirationTimeInMinutes === undefined\n ? \"1h\"\n : `${updatedOptions.expirationTimeInMinutes}m`,\n algorithm: \"HS256\",\n };\n if (updatedOptions?.userId) {\n signOptions.subject = updatedOptions?.userId;\n }\n token = jwt.sign(payload, key, signOptions);\n }\n\n return {\n token,\n baseUrl,\n url: `${baseUrl}?access_token=${token}`,\n };\n },\n );\n }\n}\n"]}
@@ -0,0 +1,5 @@
1
+ export { AzureKeyCredential } from "@azure/core-auth";
2
+ export { WebPubSubServiceClient, HubSendToAllOptions, ClientTokenResponse, HubCloseConnectionOptions, HubCloseAllConnectionsOptions, HubCloseUserConnectionsOptions, GenerateClientTokenOptions, HasConnectionOptions, HubHasGroupOptions, HubHasUserOptions, WebPubSubServiceClientOptions, WebPubSubServiceClientLogOptions, HubRemoveUserFromAllGroupsOptions, HubSendToConnectionOptions, HubSendToUserOptions, HubGrantPermissionOptions, HubRevokePermissionOptions, HubHasPermissionOptions, HubSendTextToAllOptions, HubSendTextToConnectionOptions, HubSendTextToUserOptions, JSONTypes, Permission, WebPubSubClientProtocol, } from "./hubClient.js";
3
+ export { WebPubSubGroup, GroupAddConnectionOptions, GroupCloseAllConnectionsOptions, GroupAddUserOptions, GroupAdminClientOptions, GroupHasUserOptions, GroupRemoveConnectionOptions, GroupRemoveUserOptions, GroupSendTextToAllOptions, GroupSendToAllOptions, } from "./groupClient.js";
4
+ export { odata } from "./utils.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,yBAAyB,EACzB,6BAA6B,EAC7B,8BAA8B,EAC9B,0BAA0B,EAC1B,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,EACjB,6BAA6B,EAC7B,gCAAgC,EAChC,iCAAiC,EACjC,0BAA0B,EAC1B,oBAAoB,EACpB,yBAAyB,EACzB,0BAA0B,EAC1B,uBAAuB,EACvB,uBAAuB,EACvB,8BAA8B,EAC9B,wBAAwB,EACxB,SAAS,EACT,UAAU,EACV,uBAAuB,GACxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,cAAc,EACd,yBAAyB,EACzB,+BAA+B,EAC/B,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,4BAA4B,EAC5B,sBAAsB,EACtB,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.odata = exports.WebPubSubServiceClient = exports.AzureKeyCredential = void 0;
4
+ // Copyright (c) Microsoft Corporation.
5
+ // Licensed under the MIT License.
6
+ var core_auth_1 = require("@azure/core-auth");
7
+ Object.defineProperty(exports, "AzureKeyCredential", { enumerable: true, get: function () { return core_auth_1.AzureKeyCredential; } });
8
+ var hubClient_js_1 = require("./hubClient.js");
9
+ Object.defineProperty(exports, "WebPubSubServiceClient", { enumerable: true, get: function () { return hubClient_js_1.WebPubSubServiceClient; } });
10
+ var utils_js_1 = require("./utils.js");
11
+ Object.defineProperty(exports, "odata", { enumerable: true, get: function () { return utils_js_1.odata; } });
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AACvC,kCAAkC;AAClC,8CAAsD;AAA7C,+GAAA,kBAAkB,OAAA;AAC3B,+CAyBwB;AAxBtB,sHAAA,sBAAsB,OAAA;AAqCxB,uCAAmC;AAA1B,iGAAA,KAAK,OAAA","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\nexport { AzureKeyCredential } from \"@azure/core-auth\";\nexport {\n WebPubSubServiceClient,\n HubSendToAllOptions,\n ClientTokenResponse,\n HubCloseConnectionOptions,\n HubCloseAllConnectionsOptions,\n HubCloseUserConnectionsOptions,\n GenerateClientTokenOptions,\n HasConnectionOptions,\n HubHasGroupOptions,\n HubHasUserOptions,\n WebPubSubServiceClientOptions,\n WebPubSubServiceClientLogOptions,\n HubRemoveUserFromAllGroupsOptions,\n HubSendToConnectionOptions,\n HubSendToUserOptions,\n HubGrantPermissionOptions,\n HubRevokePermissionOptions,\n HubHasPermissionOptions,\n HubSendTextToAllOptions,\n HubSendTextToConnectionOptions,\n HubSendTextToUserOptions,\n JSONTypes,\n Permission,\n WebPubSubClientProtocol,\n} from \"./hubClient.js\";\nexport {\n WebPubSubGroup,\n GroupAddConnectionOptions,\n GroupCloseAllConnectionsOptions,\n GroupAddUserOptions,\n GroupAdminClientOptions,\n GroupHasUserOptions,\n GroupRemoveConnectionOptions,\n GroupRemoveUserOptions,\n GroupSendTextToAllOptions,\n GroupSendToAllOptions,\n} from \"./groupClient.js\";\nexport { odata } from \"./utils.js\";\n"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The `@azure/logger` configuration for this package.
3
+ */
4
+ export declare const logger: import("@azure/logger").AzureLogger;
5
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,eAAO,MAAM,MAAM,qCAAmC,CAAC"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.logger = void 0;
6
+ const logger_1 = require("@azure/logger");
7
+ /**
8
+ * The `@azure/logger` configuration for this package.
9
+ */
10
+ exports.logger = (0, logger_1.createClientLogger)("web-pubsub");
11
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,0CAAmD;AAEnD;;GAEG;AACU,QAAA,MAAM,GAAG,IAAA,2BAAkB,EAAC,YAAY,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { createClientLogger } from \"@azure/logger\";\n\n/**\n * The `@azure/logger` configuration for this package.\n */\nexport const logger = createClientLogger(\"web-pubsub\");\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,8 @@
1
+ import { AzureKeyCredential } from "@azure/core-auth";
2
+ interface ParsedConnectionString {
3
+ credential: AzureKeyCredential;
4
+ endpoint: string;
5
+ }
6
+ export declare function parseConnectionString(conn: string): ParsedConnectionString;
7
+ export {};
8
+ //# sourceMappingURL=parseConnectionString.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseConnectionString.d.ts","sourceRoot":"","sources":["../../src/parseConnectionString.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,UAAU,sBAAsB;IAC9B,UAAU,EAAE,kBAAkB,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,sBAAsB,CA0B1E"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.parseConnectionString = parseConnectionString;
6
+ const core_auth_1 = require("@azure/core-auth");
7
+ function parseConnectionString(conn) {
8
+ const parsed = {};
9
+ conn.split(";").forEach((i) => {
10
+ const assignmentPos = i.indexOf("=");
11
+ if (assignmentPos === -1)
12
+ return;
13
+ const key = i.substring(0, assignmentPos).toLowerCase();
14
+ const value = i.substring(assignmentPos + 1);
15
+ parsed[key] = value;
16
+ });
17
+ let endpointPart = parsed["endpoint"];
18
+ if (!endpointPart)
19
+ throw new TypeError("connection string missing endpoint");
20
+ if (!endpointPart.startsWith("http")) {
21
+ endpointPart = `https://${endpointPart}`;
22
+ }
23
+ const key = parsed["accesskey"];
24
+ if (!key)
25
+ throw new TypeError("connection string missing access key");
26
+ const credential = new core_auth_1.AzureKeyCredential(key);
27
+ const port = parsed["port"];
28
+ const url = new URL(endpointPart);
29
+ url.port = port;
30
+ const endpoint = url.toString();
31
+ url.port = "";
32
+ return { credential, endpoint };
33
+ }
34
+ //# sourceMappingURL=parseConnectionString.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseConnectionString.js","sourceRoot":"","sources":["../../src/parseConnectionString.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AASlC,sDA0BC;AAjCD,gDAAsD;AAOtD,SAAgB,qBAAqB,CAAC,IAAY;IAChD,MAAM,MAAM,GAA6B,EAAE,CAAC;IAE5C,IAAI,CAAC,KAA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License.\n\nimport { AzureKeyCredential } from \"@azure/core-auth\";\n\ninterface ParsedConnectionString {\n credential: AzureKeyCredential;\n endpoint: string;\n}\n\nexport function parseConnectionString(conn: string): ParsedConnectionString {\n const parsed: { [id: string]: string } = {};\n\n conn.split(\";\").forEach((i) => {\n const assignmentPos = i.indexOf(\"=\");\n if (assignmentPos === -1) return;\n const key = i.substring(0, assignmentPos).toLowerCase();\n const value = i.substring(assignmentPos + 1);\n parsed[key] = value;\n });\n\n let endpointPart = parsed[\"endpoint\"];\n if (!endpointPart) throw new TypeError(\"connection string missing endpoint\");\n if (!endpointPart.startsWith(\"http\")) {\n endpointPart = `https://${endpointPart}`;\n }\n const key = parsed[\"accesskey\"];\n if (!key) throw new TypeError(\"connection string missing access key\");\n const credential = new AzureKeyCredential(key);\n const port = parsed[\"port\"];\n const url = new URL(endpointPart);\n url.port = port;\n const endpoint = url.toString();\n url.port = \"\";\n\n return { credential, endpoint };\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import type { PipelinePolicy } from "@azure/core-rest-pipeline";
2
+ export declare const webPubSubReverseProxyPolicyName = "webPubSubReverseProxyPolicy";
3
+ /**
4
+ * Create an HTTP pipeline policy to use a reverse proxy.
5
+ * This is generally going to be an Azure APIM endpoint.
6
+ * @internal
7
+ */
8
+ export declare function webPubSubReverseProxyPolicy(endpoint: string): PipelinePolicy;
9
+ //# sourceMappingURL=reverseProxyPolicy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reverseProxyPolicy.d.ts","sourceRoot":"","sources":["../../src/reverseProxyPolicy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAIV,cAAc,EACf,MAAM,2BAA2B,CAAC;AAEnC,eAAO,MAAM,+BAA+B,gCAAgC,CAAC;AAE7E;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CAW5E"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.webPubSubReverseProxyPolicyName = void 0;
6
+ exports.webPubSubReverseProxyPolicy = webPubSubReverseProxyPolicy;
7
+ exports.webPubSubReverseProxyPolicyName = "webPubSubReverseProxyPolicy";
8
+ /**
9
+ * Create an HTTP pipeline policy to use a reverse proxy.
10
+ * This is generally going to be an Azure APIM endpoint.
11
+ * @internal
12
+ */
13
+ function webPubSubReverseProxyPolicy(endpoint) {
14
+ const rpEndpointUrl = new URL(endpoint);
15
+ return {
16
+ name: exports.webPubSubReverseProxyPolicyName,
17
+ sendRequest(request, next) {
18
+ const parsedUrl = new URL(request.url);
19
+ parsedUrl.host = rpEndpointUrl.host;
20
+ request.url = parsedUrl.toString();
21
+ return next(request);
22
+ },
23
+ };
24
+ }
25
+ //# sourceMappingURL=reverseProxyPolicy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reverseProxyPolicy.js","sourceRoot":"","sources":["../../src/reverseProxyPolicy.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAgBlC,kEAWC;AAlBY,QAAA,+BAA+B,GAAG,6BAA6B,CAAC;AAE7E;;;;GAIG;AACH,SAAgB,2BAA2B,CAAC,QAAgB;IAC1D,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;IACxC,OAAO;QACL,IAAI,EAAE,uCAA+B;QACrC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YACrD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACvC,SAAS,CAAC,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC;YACpC,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;YACnC,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n PipelineResponse,\n PipelineRequest,\n SendRequest,\n PipelinePolicy,\n} from \"@azure/core-rest-pipeline\";\n\nexport const webPubSubReverseProxyPolicyName = \"webPubSubReverseProxyPolicy\";\n\n/**\n * Create an HTTP pipeline policy to use a reverse proxy.\n * This is generally going to be an Azure APIM endpoint.\n * @internal\n */\nexport function webPubSubReverseProxyPolicy(endpoint: string): PipelinePolicy {\n const rpEndpointUrl = new URL(endpoint);\n return {\n name: webPubSubReverseProxyPolicyName,\n sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n const parsedUrl = new URL(request.url);\n parsedUrl.host = rpEndpointUrl.host;\n request.url = parsedUrl.toString();\n return next(request);\n },\n };\n}\n"]}