@lightsparkdev/core 0.3.4 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -1
- package/dist/index.cjs +17 -9
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -9
- package/package.json +1 -1
- package/src/requester/Requester.ts +23 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
# @lightsparkdev/core
|
|
2
2
|
|
|
3
|
+
## 0.3.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a09f51f: Allow websockets without ssl for local testing.
|
|
8
|
+
|
|
9
|
+
## 0.3.5
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- c92f1d8: Force patch to sync with npm versions
|
|
14
|
+
|
|
3
15
|
## 0.3.4
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
6
18
|
|
|
7
|
-
-
|
|
19
|
+
- 1528704: Allow setting a protocol manually in the js sdk
|
|
20
|
+
- 44be15f: Add the LNURL docs for JS
|
|
8
21
|
|
|
9
22
|
## 0.3.3
|
|
10
23
|
|
package/dist/index.cjs
CHANGED
|
@@ -409,8 +409,12 @@ var Requester = class {
|
|
|
409
409
|
if (typeof WebSocket === "undefined" && typeof window === "undefined") {
|
|
410
410
|
websocketImpl = import_ws.default;
|
|
411
411
|
}
|
|
412
|
+
let websocketProtocol = "wss";
|
|
413
|
+
if (baseUrl.startsWith("http://")) {
|
|
414
|
+
websocketProtocol = "ws";
|
|
415
|
+
}
|
|
412
416
|
this.wsClient = (0, import_graphql_ws.createClient)({
|
|
413
|
-
url:
|
|
417
|
+
url: `${websocketProtocol}://${this.stripProtocol(this.baseUrl)}/${this.schemaEndpoint}`,
|
|
414
418
|
connectionParams: () => authProvider.addWsConnectionParams({}),
|
|
415
419
|
webSocketImpl: websocketImpl
|
|
416
420
|
});
|
|
@@ -496,14 +500,15 @@ var Requester = class {
|
|
|
496
500
|
headers,
|
|
497
501
|
signingNodeId
|
|
498
502
|
);
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
{
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
503
|
+
let urlWithProtocol = this.baseUrl;
|
|
504
|
+
if (!urlWithProtocol.startsWith("https://") && !urlWithProtocol.startsWith("http://")) {
|
|
505
|
+
urlWithProtocol = `https://${urlWithProtocol}`;
|
|
506
|
+
}
|
|
507
|
+
const response = await fetch(`${urlWithProtocol}/${this.schemaEndpoint}`, {
|
|
508
|
+
method: "POST",
|
|
509
|
+
headers,
|
|
510
|
+
body: JSON.stringify(bodyData)
|
|
511
|
+
});
|
|
507
512
|
if (!response.ok) {
|
|
508
513
|
throw new LightsparkException_default(
|
|
509
514
|
"RequestFailed",
|
|
@@ -525,6 +530,9 @@ var Requester = class {
|
|
|
525
530
|
const platformVersion = isNode ? process.version : "";
|
|
526
531
|
return `${this.sdkUserAgent} ${platform}/${platformVersion}`;
|
|
527
532
|
}
|
|
533
|
+
stripProtocol(url) {
|
|
534
|
+
return url.replace(/.*?:\/\//g, "");
|
|
535
|
+
}
|
|
528
536
|
async addSigningDataIfNeeded(queryPayload, headers, signingNodeId) {
|
|
529
537
|
if (!signingNodeId) {
|
|
530
538
|
return queryPayload;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -357,8 +357,12 @@ var Requester = class {
|
|
|
357
357
|
if (typeof WebSocket === "undefined" && typeof window === "undefined") {
|
|
358
358
|
websocketImpl = NodeWebSocket;
|
|
359
359
|
}
|
|
360
|
+
let websocketProtocol = "wss";
|
|
361
|
+
if (baseUrl.startsWith("http://")) {
|
|
362
|
+
websocketProtocol = "ws";
|
|
363
|
+
}
|
|
360
364
|
this.wsClient = createClient({
|
|
361
|
-
url:
|
|
365
|
+
url: `${websocketProtocol}://${this.stripProtocol(this.baseUrl)}/${this.schemaEndpoint}`,
|
|
362
366
|
connectionParams: () => authProvider.addWsConnectionParams({}),
|
|
363
367
|
webSocketImpl: websocketImpl
|
|
364
368
|
});
|
|
@@ -444,14 +448,15 @@ var Requester = class {
|
|
|
444
448
|
headers,
|
|
445
449
|
signingNodeId
|
|
446
450
|
);
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
{
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
451
|
+
let urlWithProtocol = this.baseUrl;
|
|
452
|
+
if (!urlWithProtocol.startsWith("https://") && !urlWithProtocol.startsWith("http://")) {
|
|
453
|
+
urlWithProtocol = `https://${urlWithProtocol}`;
|
|
454
|
+
}
|
|
455
|
+
const response = await fetch(`${urlWithProtocol}/${this.schemaEndpoint}`, {
|
|
456
|
+
method: "POST",
|
|
457
|
+
headers,
|
|
458
|
+
body: JSON.stringify(bodyData)
|
|
459
|
+
});
|
|
455
460
|
if (!response.ok) {
|
|
456
461
|
throw new LightsparkException_default(
|
|
457
462
|
"RequestFailed",
|
|
@@ -473,6 +478,9 @@ var Requester = class {
|
|
|
473
478
|
const platformVersion = isNode ? process.version : "";
|
|
474
479
|
return `${this.sdkUserAgent} ${platform}/${platformVersion}`;
|
|
475
480
|
}
|
|
481
|
+
stripProtocol(url) {
|
|
482
|
+
return url.replace(/.*?:\/\//g, "");
|
|
483
|
+
}
|
|
476
484
|
async addSigningDataIfNeeded(queryPayload, headers, signingNodeId) {
|
|
477
485
|
if (!signingNodeId) {
|
|
478
486
|
return queryPayload;
|
package/package.json
CHANGED
|
@@ -41,8 +41,14 @@ class Requester {
|
|
|
41
41
|
if (typeof WebSocket === "undefined" && typeof window === "undefined") {
|
|
42
42
|
websocketImpl = NodeWebSocket;
|
|
43
43
|
}
|
|
44
|
+
let websocketProtocol = "wss";
|
|
45
|
+
if (baseUrl.startsWith("http://")) {
|
|
46
|
+
websocketProtocol = "ws";
|
|
47
|
+
}
|
|
44
48
|
this.wsClient = createClient({
|
|
45
|
-
url:
|
|
49
|
+
url: `${websocketProtocol}://${this.stripProtocol(this.baseUrl)}/${
|
|
50
|
+
this.schemaEndpoint
|
|
51
|
+
}`,
|
|
46
52
|
connectionParams: () => authProvider.addWsConnectionParams({}),
|
|
47
53
|
webSocketImpl: websocketImpl,
|
|
48
54
|
});
|
|
@@ -145,14 +151,18 @@ class Requester {
|
|
|
145
151
|
signingNodeId
|
|
146
152
|
);
|
|
147
153
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
let urlWithProtocol = this.baseUrl;
|
|
155
|
+
if (
|
|
156
|
+
!urlWithProtocol.startsWith("https://") &&
|
|
157
|
+
!urlWithProtocol.startsWith("http://")
|
|
158
|
+
) {
|
|
159
|
+
urlWithProtocol = `https://${urlWithProtocol}`;
|
|
160
|
+
}
|
|
161
|
+
const response = await fetch(`${urlWithProtocol}/${this.schemaEndpoint}`, {
|
|
162
|
+
method: "POST",
|
|
163
|
+
headers: headers,
|
|
164
|
+
body: JSON.stringify(bodyData),
|
|
165
|
+
});
|
|
156
166
|
if (!response.ok) {
|
|
157
167
|
throw new LightsparkException(
|
|
158
168
|
"RequestFailed",
|
|
@@ -176,6 +186,10 @@ class Requester {
|
|
|
176
186
|
return `${this.sdkUserAgent} ${platform}/${platformVersion}`;
|
|
177
187
|
}
|
|
178
188
|
|
|
189
|
+
private stripProtocol(url: string): string {
|
|
190
|
+
return url.replace(/.*?:\/\//g, "");
|
|
191
|
+
}
|
|
192
|
+
|
|
179
193
|
private async addSigningDataIfNeeded(
|
|
180
194
|
queryPayload: { query: string; variables: any; operationName: string },
|
|
181
195
|
headers: { [key: string]: string },
|