@lightsparkdev/core 0.3.3 → 0.3.5

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @lightsparkdev/core
2
2
 
3
+ ## 0.3.5
4
+
5
+ ### Patch Changes
6
+
7
+ - c92f1d8: Force patch to sync with npm versions
8
+
9
+ ## 0.3.4
10
+
11
+ ### Patch Changes
12
+
13
+ - 1528704: Allow setting a protocol manually in the js sdk
14
+ - 44be15f: Add the LNURL docs for JS
15
+
3
16
  ## 0.3.3
4
17
 
5
18
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -143,7 +143,22 @@ var getCrypto = () => {
143
143
  cryptoImplPromise = Promise.resolve(crypto);
144
144
  } else {
145
145
  cryptoImplPromise = import("crypto").then((nodeCrypto) => {
146
- return nodeCrypto;
146
+ let cryptoModule = nodeCrypto;
147
+ if (!nodeCrypto.subtle) {
148
+ cryptoModule = Object.assign({}, cryptoModule, {
149
+ subtle: nodeCrypto.webcrypto.subtle
150
+ });
151
+ }
152
+ if (!nodeCrypto.getRandomValues) {
153
+ cryptoModule = Object.assign({}, cryptoModule, {
154
+ getRandomValues: (array) => {
155
+ const buffer = Buffer.from(array.buffer);
156
+ nodeCrypto.randomFillSync(buffer);
157
+ return array;
158
+ }
159
+ });
160
+ }
161
+ return cryptoModule;
147
162
  });
148
163
  }
149
164
  return cryptoImplPromise;
@@ -395,7 +410,7 @@ var Requester = class {
395
410
  websocketImpl = import_ws.default;
396
411
  }
397
412
  this.wsClient = (0, import_graphql_ws.createClient)({
398
- url: `wss://${this.baseUrl}/${this.schemaEndpoint}`,
413
+ url: `wss://${this.stripProtocol(this.baseUrl)}/${this.schemaEndpoint}`,
399
414
  connectionParams: () => authProvider.addWsConnectionParams({}),
400
415
  webSocketImpl: websocketImpl
401
416
  });
@@ -481,14 +496,15 @@ var Requester = class {
481
496
  headers,
482
497
  signingNodeId
483
498
  );
484
- const response = await fetch(
485
- `https://${this.baseUrl}/${this.schemaEndpoint}`,
486
- {
487
- method: "POST",
488
- headers,
489
- body: JSON.stringify(bodyData)
490
- }
491
- );
499
+ let urlWithProtocol = this.baseUrl;
500
+ if (!urlWithProtocol.startsWith("https://") && !urlWithProtocol.startsWith("http://")) {
501
+ urlWithProtocol = `https://${urlWithProtocol}`;
502
+ }
503
+ const response = await fetch(`${urlWithProtocol}/${this.schemaEndpoint}`, {
504
+ method: "POST",
505
+ headers,
506
+ body: JSON.stringify(bodyData)
507
+ });
492
508
  if (!response.ok) {
493
509
  throw new LightsparkException_default(
494
510
  "RequestFailed",
@@ -510,6 +526,9 @@ var Requester = class {
510
526
  const platformVersion = isNode ? process.version : "";
511
527
  return `${this.sdkUserAgent} ${platform}/${platformVersion}`;
512
528
  }
529
+ stripProtocol(url) {
530
+ return url.replace(/.*?:\/\//g, "");
531
+ }
513
532
  async addSigningDataIfNeeded(queryPayload, headers, signingNodeId) {
514
533
  if (!signingNodeId) {
515
534
  return queryPayload;
package/dist/index.d.ts CHANGED
@@ -106,6 +106,7 @@ declare class Requester {
106
106
  [key: string]: any;
107
107
  }, signingNodeId?: string | undefined, skipAuth?: boolean): Promise<any | null>;
108
108
  private getSdkUserAgent;
109
+ private stripProtocol;
109
110
  private addSigningDataIfNeeded;
110
111
  }
111
112
 
package/dist/index.js CHANGED
@@ -91,7 +91,22 @@ var getCrypto = () => {
91
91
  cryptoImplPromise = Promise.resolve(crypto);
92
92
  } else {
93
93
  cryptoImplPromise = import("crypto").then((nodeCrypto) => {
94
- return nodeCrypto;
94
+ let cryptoModule = nodeCrypto;
95
+ if (!nodeCrypto.subtle) {
96
+ cryptoModule = Object.assign({}, cryptoModule, {
97
+ subtle: nodeCrypto.webcrypto.subtle
98
+ });
99
+ }
100
+ if (!nodeCrypto.getRandomValues) {
101
+ cryptoModule = Object.assign({}, cryptoModule, {
102
+ getRandomValues: (array) => {
103
+ const buffer = Buffer.from(array.buffer);
104
+ nodeCrypto.randomFillSync(buffer);
105
+ return array;
106
+ }
107
+ });
108
+ }
109
+ return cryptoModule;
95
110
  });
96
111
  }
97
112
  return cryptoImplPromise;
@@ -343,7 +358,7 @@ var Requester = class {
343
358
  websocketImpl = NodeWebSocket;
344
359
  }
345
360
  this.wsClient = createClient({
346
- url: `wss://${this.baseUrl}/${this.schemaEndpoint}`,
361
+ url: `wss://${this.stripProtocol(this.baseUrl)}/${this.schemaEndpoint}`,
347
362
  connectionParams: () => authProvider.addWsConnectionParams({}),
348
363
  webSocketImpl: websocketImpl
349
364
  });
@@ -429,14 +444,15 @@ var Requester = class {
429
444
  headers,
430
445
  signingNodeId
431
446
  );
432
- const response = await fetch(
433
- `https://${this.baseUrl}/${this.schemaEndpoint}`,
434
- {
435
- method: "POST",
436
- headers,
437
- body: JSON.stringify(bodyData)
438
- }
439
- );
447
+ let urlWithProtocol = this.baseUrl;
448
+ if (!urlWithProtocol.startsWith("https://") && !urlWithProtocol.startsWith("http://")) {
449
+ urlWithProtocol = `https://${urlWithProtocol}`;
450
+ }
451
+ const response = await fetch(`${urlWithProtocol}/${this.schemaEndpoint}`, {
452
+ method: "POST",
453
+ headers,
454
+ body: JSON.stringify(bodyData)
455
+ });
440
456
  if (!response.ok) {
441
457
  throw new LightsparkException_default(
442
458
  "RequestFailed",
@@ -458,6 +474,9 @@ var Requester = class {
458
474
  const platformVersion = isNode ? process.version : "";
459
475
  return `${this.sdkUserAgent} ${platform}/${platformVersion}`;
460
476
  }
477
+ stripProtocol(url) {
478
+ return url.replace(/.*?:\/\//g, "");
479
+ }
461
480
  async addSigningDataIfNeeded(queryPayload, headers, signingNodeId) {
462
481
  if (!signingNodeId) {
463
482
  return queryPayload;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightsparkdev/core",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "Lightspark JS SDK",
5
5
  "author": "Lightspark Inc.",
6
6
  "keywords": [
@@ -40,7 +40,23 @@ const getCrypto = () => {
40
40
  cryptoImplPromise = Promise.resolve(crypto);
41
41
  } else {
42
42
  cryptoImplPromise = import("crypto").then((nodeCrypto) => {
43
- return nodeCrypto as typeof crypto;
43
+ let cryptoModule = nodeCrypto as typeof crypto;
44
+ if (!nodeCrypto.subtle) {
45
+ cryptoModule = Object.assign({}, cryptoModule, {
46
+ subtle: nodeCrypto.webcrypto.subtle,
47
+ }) as typeof crypto;
48
+ }
49
+ if (!nodeCrypto.getRandomValues) {
50
+ cryptoModule = Object.assign({}, cryptoModule, {
51
+ getRandomValues: (array) => {
52
+ const buffer = Buffer.from(array.buffer);
53
+ nodeCrypto.randomFillSync(buffer);
54
+ return array;
55
+ },
56
+ }) as typeof crypto;
57
+ }
58
+
59
+ return cryptoModule;
44
60
  });
45
61
  }
46
62
  return cryptoImplPromise;
@@ -42,7 +42,7 @@ class Requester {
42
42
  websocketImpl = NodeWebSocket;
43
43
  }
44
44
  this.wsClient = createClient({
45
- url: `wss://${this.baseUrl}/${this.schemaEndpoint}`,
45
+ url: `wss://${this.stripProtocol(this.baseUrl)}/${this.schemaEndpoint}`,
46
46
  connectionParams: () => authProvider.addWsConnectionParams({}),
47
47
  webSocketImpl: websocketImpl,
48
48
  });
@@ -145,14 +145,18 @@ class Requester {
145
145
  signingNodeId
146
146
  );
147
147
 
148
- const response = await fetch(
149
- `https://${this.baseUrl}/${this.schemaEndpoint}`,
150
- {
151
- method: "POST",
152
- headers: headers,
153
- body: JSON.stringify(bodyData),
154
- }
155
- );
148
+ let urlWithProtocol = this.baseUrl;
149
+ if (
150
+ !urlWithProtocol.startsWith("https://") &&
151
+ !urlWithProtocol.startsWith("http://")
152
+ ) {
153
+ urlWithProtocol = `https://${urlWithProtocol}`;
154
+ }
155
+ const response = await fetch(`${urlWithProtocol}/${this.schemaEndpoint}`, {
156
+ method: "POST",
157
+ headers: headers,
158
+ body: JSON.stringify(bodyData),
159
+ });
156
160
  if (!response.ok) {
157
161
  throw new LightsparkException(
158
162
  "RequestFailed",
@@ -176,6 +180,10 @@ class Requester {
176
180
  return `${this.sdkUserAgent} ${platform}/${platformVersion}`;
177
181
  }
178
182
 
183
+ private stripProtocol(url: string): string {
184
+ return url.replace(/.*?:\/\//g, "");
185
+ }
186
+
179
187
  private async addSigningDataIfNeeded(
180
188
  queryPayload: { query: string; variables: any; operationName: string },
181
189
  headers: { [key: string]: string },