@lightsparkdev/lightspark-sdk 0.3.2 → 0.3.4

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,24 @@
1
1
  # @lightsparkdev/lightspark-sdk
2
2
 
3
+ ## 0.3.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 55f31db: Add walletID to relevant webhook events.
8
+
9
+ ## 0.3.3
10
+
11
+ ### Patch Changes
12
+
13
+ - cf73a38: Upgrade yarn to latest
14
+ - 9c0a2fe: Move typedoc into dev deps for sdks
15
+ - 9c0a2fe: Declare shared deps in workspaces that require them
16
+ - 9c0a2fe: Fix importing TextDecoder when not available
17
+ - 9c0a2fe: Fix webhook JS docs and function names
18
+ - Updated dependencies [cf73a38]
19
+ - Updated dependencies [9c0a2fe]
20
+ - @lightsparkdev/core@0.3.2
21
+
3
22
  ## 0.3.2
4
23
 
5
24
  ### Patch Changes
package/README.md CHANGED
@@ -123,15 +123,14 @@ $ ts-node createInvoice.ts -a "100" -m "Whasssupppp"
123
123
 
124
124
  ### Streaming Wallet Extension
125
125
 
126
- This example is meant to be used in conjunction with the [Lightspark streaming sats demo](https://app.lightspark.com/demos/streaming). It can be built and installed as a Chrome extension by running:
126
+ This example is meant to be used in conjunction with the [Lightspark streaming sats demo](https://app.lightspark.com/demos/streaming). It can be built and installed as a Chrome extension by running (from root js-sdk directory):
127
127
 
128
128
  ```bash
129
- $ cd examples/streaming-wallet-extension
130
- $ npm install
131
- $ npm run build
129
+ $ yarn
130
+ $ yarn build
132
131
  ```
133
132
 
134
- Then, go to `chrome://extensions` and click "Load unpacked" and select the `streaming-wallet-extension/build` directory.
133
+ Then, go to `chrome://extensions` and click "Load unpacked" and select the `apps/examples/streaming-wallet-extension/build` directory.
135
134
 
136
135
  When the extension is installed, it will automatically open the streaming sats demo page. You can then click extension icon to open the extension popup, which will give you the ability to create a test account with 2 nodes - a viewer node (which acts as your wallet for the demo), and a creator node, which simulates the wallet of the creator of the streaming content. The page will reload and you'll be able to start streaming sats as the video plays!
137
136
 
package/dist/index.cjs CHANGED
@@ -35,7 +35,7 @@ var require_package = __commonJS({
35
35
  "package.json"(exports, module2) {
36
36
  module2.exports = {
37
37
  name: "@lightsparkdev/lightspark-sdk",
38
- version: "0.3.2",
38
+ version: "0.3.4",
39
39
  description: "Lightspark JS SDK",
40
40
  author: "Lightspark Inc.",
41
41
  keywords: [
@@ -92,25 +92,25 @@ var require_package = __commonJS({
92
92
  ],
93
93
  scripts: {
94
94
  build: "tsup --entry src/index.ts --entry src/objects/index.ts --format cjs,esm --dts",
95
- clean: "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
95
+ clean: "rm -rf .turbo && rm -rf dist",
96
96
  dev: "yarn build -- --watch",
97
97
  docs: "typedoc src",
98
- format: "npx prettier --write ./src",
99
- lint: "npx prettier --check ./src",
98
+ format: "prettier src --check",
99
+ "format:fix": "prettier src --write",
100
+ lint: "prettier --check ./src",
100
101
  postversion: "yarn build",
101
102
  test: "jest --no-cache --runInBand --bail",
102
- "type-check": "tsc --noEmit"
103
+ types: "tsc"
103
104
  },
104
105
  license: "Apache-2.0",
105
106
  dependencies: {
106
- "@lightsparkdev/core": "0.3.1",
107
+ "@lightsparkdev/core": "0.3.2",
107
108
  "auto-bind": "^5.0.1",
108
109
  crypto: "^1.0.1",
109
110
  "crypto-browserify": "^3.12.0",
110
111
  dayjs: "^1.11.7",
111
112
  graphql: "^16.6.0",
112
113
  "graphql-ws": "^5.11.3",
113
- typedoc: "^0.24.7",
114
114
  ws: "^8.12.1",
115
115
  "zen-observable-ts": "^1.1.0"
116
116
  },
@@ -118,12 +118,13 @@ var require_package = __commonJS({
118
118
  "@types/crypto-js": "^4.1.1",
119
119
  "@types/jest": "^29.5.2",
120
120
  "@types/ws": "^8.5.4",
121
- jest: "^29.5.0",
122
- prettier: "^2.8.4",
123
- "prettier-plugin-organize-imports": "^3.2.2",
124
- "ts-jest": "^29.1.0",
121
+ jest: "^29.4.1",
122
+ prettier: "2.8.7",
123
+ "ts-jest": "^29.0.5",
125
124
  "ts-node": "^10.9.1",
126
125
  tsconfig: "*",
126
+ tsup: "^6.7.0",
127
+ typedoc: "^0.24.7",
127
128
  typescript: "^4.9.5"
128
129
  }
129
130
  };
@@ -1983,8 +1984,7 @@ __export(src_exports, {
1983
1984
  getRoutingTransactionQuery: () => getRoutingTransactionQuery,
1984
1985
  getTransactionQuery: () => getTransactionQuery,
1985
1986
  getWithdrawalQuery: () => getWithdrawalQuery,
1986
- parse_webhook: () => parse_webhook,
1987
- verify_and_parse_webhook: () => verify_and_parse_webhook
1987
+ verifyAndParseWebhook: () => verifyAndParseWebhook
1988
1988
  });
1989
1989
  module.exports = __toCommonJS(src_exports);
1990
1990
 
@@ -8855,24 +8855,27 @@ ${FRAGMENT28}
8855
8855
  // src/webhooks.ts
8856
8856
  var import_crypto = require("crypto");
8857
8857
  var WEBHOOKS_SIGNATURE_HEADER = "lightspark-signature";
8858
- var verify_and_parse_webhook = (data, hexdigest, webhook_secret) => {
8858
+ var verifyAndParseWebhook = (data, hexdigest, webhook_secret) => {
8859
8859
  const sig = (0, import_crypto.createHmac)("sha256", webhook_secret).update(data).digest("hex");
8860
8860
  if (sig.toLowerCase() !== hexdigest.toLowerCase()) {
8861
8861
  throw new Error("Webhook message hash does not match signature");
8862
8862
  }
8863
- return parse_webhook(data);
8863
+ return parseWebhook(data);
8864
8864
  };
8865
- var parse_webhook = async (data) => {
8866
- if (typeof TextDecoder === "undefined") {
8867
- const TextDecoder2 = (await Promise.resolve().then(() => __toESM(require_text_encoding(), 1))).TextDecoder;
8865
+ var parseWebhook = async (data) => {
8866
+ let td = TextDecoder;
8867
+ if (typeof td === "undefined") {
8868
+ const tdModule = await Promise.resolve().then(() => __toESM(require_text_encoding(), 1));
8869
+ td = tdModule.TextDecoder;
8868
8870
  }
8869
- const dataStr = new TextDecoder().decode(data);
8871
+ const dataStr = new td().decode(data);
8870
8872
  const event = JSON.parse(dataStr);
8871
8873
  return {
8872
8874
  event_type: WebhookEventType[event.event_type],
8873
8875
  event_id: event.event_id,
8874
8876
  timestamp: new Date(event.timestamp),
8875
- entity_id: event.entity_id
8877
+ entity_id: event.entity_id,
8878
+ wallet_id: event.wallet_id
8876
8879
  };
8877
8880
  };
8878
8881
  // Annotate the CommonJS export names for ESM import in node:
@@ -8923,6 +8926,5 @@ var parse_webhook = async (data) => {
8923
8926
  getRoutingTransactionQuery,
8924
8927
  getTransactionQuery,
8925
8928
  getWithdrawalQuery,
8926
- parse_webhook,
8927
- verify_and_parse_webhook
8929
+ verifyAndParseWebhook
8928
8930
  });
package/dist/index.d.ts CHANGED
@@ -19,8 +19,8 @@ interface WebhookEvent {
19
19
  event_id: string;
20
20
  timestamp: Date;
21
21
  entity_id: string;
22
+ wallet_id?: string;
22
23
  }
23
- declare const verify_and_parse_webhook: (data: Uint8Array, hexdigest: string, webhook_secret: string) => Promise<WebhookEvent>;
24
- declare const parse_webhook: (data: Uint8Array) => Promise<WebhookEvent>;
24
+ declare const verifyAndParseWebhook: (data: Uint8Array, hexdigest: string, webhook_secret: string) => Promise<WebhookEvent>;
25
25
 
26
- export { AccountTokenAuthProvider, WEBHOOKS_SIGNATURE_HEADER, WebhookEvent, WebhookEventType, parse_webhook, verify_and_parse_webhook };
26
+ export { AccountTokenAuthProvider, WEBHOOKS_SIGNATURE_HEADER, WebhookEvent, WebhookEventType, verifyAndParseWebhook };
package/dist/index.js CHANGED
@@ -70,7 +70,7 @@ var require_package = __commonJS({
70
70
  "package.json"(exports, module) {
71
71
  module.exports = {
72
72
  name: "@lightsparkdev/lightspark-sdk",
73
- version: "0.3.2",
73
+ version: "0.3.4",
74
74
  description: "Lightspark JS SDK",
75
75
  author: "Lightspark Inc.",
76
76
  keywords: [
@@ -127,25 +127,25 @@ var require_package = __commonJS({
127
127
  ],
128
128
  scripts: {
129
129
  build: "tsup --entry src/index.ts --entry src/objects/index.ts --format cjs,esm --dts",
130
- clean: "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
130
+ clean: "rm -rf .turbo && rm -rf dist",
131
131
  dev: "yarn build -- --watch",
132
132
  docs: "typedoc src",
133
- format: "npx prettier --write ./src",
134
- lint: "npx prettier --check ./src",
133
+ format: "prettier src --check",
134
+ "format:fix": "prettier src --write",
135
+ lint: "prettier --check ./src",
135
136
  postversion: "yarn build",
136
137
  test: "jest --no-cache --runInBand --bail",
137
- "type-check": "tsc --noEmit"
138
+ types: "tsc"
138
139
  },
139
140
  license: "Apache-2.0",
140
141
  dependencies: {
141
- "@lightsparkdev/core": "0.3.1",
142
+ "@lightsparkdev/core": "0.3.2",
142
143
  "auto-bind": "^5.0.1",
143
144
  crypto: "^1.0.1",
144
145
  "crypto-browserify": "^3.12.0",
145
146
  dayjs: "^1.11.7",
146
147
  graphql: "^16.6.0",
147
148
  "graphql-ws": "^5.11.3",
148
- typedoc: "^0.24.7",
149
149
  ws: "^8.12.1",
150
150
  "zen-observable-ts": "^1.1.0"
151
151
  },
@@ -153,12 +153,13 @@ var require_package = __commonJS({
153
153
  "@types/crypto-js": "^4.1.1",
154
154
  "@types/jest": "^29.5.2",
155
155
  "@types/ws": "^8.5.4",
156
- jest: "^29.5.0",
157
- prettier: "^2.8.4",
158
- "prettier-plugin-organize-imports": "^3.2.2",
159
- "ts-jest": "^29.1.0",
156
+ jest: "^29.4.1",
157
+ prettier: "2.8.7",
158
+ "ts-jest": "^29.0.5",
160
159
  "ts-node": "^10.9.1",
161
160
  tsconfig: "*",
161
+ tsup: "^6.7.0",
162
+ typedoc: "^0.24.7",
162
163
  typescript: "^4.9.5"
163
164
  }
164
165
  };
@@ -1352,24 +1353,27 @@ var client_default = LightsparkClient;
1352
1353
  // src/webhooks.ts
1353
1354
  import { createHmac } from "crypto";
1354
1355
  var WEBHOOKS_SIGNATURE_HEADER = "lightspark-signature";
1355
- var verify_and_parse_webhook = (data, hexdigest, webhook_secret) => {
1356
+ var verifyAndParseWebhook = (data, hexdigest, webhook_secret) => {
1356
1357
  const sig = createHmac("sha256", webhook_secret).update(data).digest("hex");
1357
1358
  if (sig.toLowerCase() !== hexdigest.toLowerCase()) {
1358
1359
  throw new Error("Webhook message hash does not match signature");
1359
1360
  }
1360
- return parse_webhook(data);
1361
+ return parseWebhook(data);
1361
1362
  };
1362
- var parse_webhook = async (data) => {
1363
- if (typeof TextDecoder === "undefined") {
1364
- const TextDecoder2 = (await import("./text-encoding-MDIPJAHL.js")).TextDecoder;
1363
+ var parseWebhook = async (data) => {
1364
+ let td = TextDecoder;
1365
+ if (typeof td === "undefined") {
1366
+ const tdModule = await import("./text-encoding-MDIPJAHL.js");
1367
+ td = tdModule.TextDecoder;
1365
1368
  }
1366
- const dataStr = new TextDecoder().decode(data);
1369
+ const dataStr = new td().decode(data);
1367
1370
  const event = JSON.parse(dataStr);
1368
1371
  return {
1369
1372
  event_type: WebhookEventType[event.event_type],
1370
1373
  event_id: event.event_id,
1371
1374
  timestamp: new Date(event.timestamp),
1372
- entity_id: event.entity_id
1375
+ entity_id: event.entity_id,
1376
+ wallet_id: event.wallet_id
1373
1377
  };
1374
1378
  };
1375
1379
  export {
@@ -1419,6 +1423,5 @@ export {
1419
1423
  getRoutingTransactionQuery,
1420
1424
  getTransactionQuery,
1421
1425
  getWithdrawalQuery,
1422
- parse_webhook,
1423
- verify_and_parse_webhook
1426
+ verifyAndParseWebhook
1424
1427
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightsparkdev/lightspark-sdk",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "Lightspark JS SDK",
5
5
  "author": "Lightspark Inc.",
6
6
  "keywords": [
@@ -57,25 +57,25 @@
57
57
  ],
58
58
  "scripts": {
59
59
  "build": "tsup --entry src/index.ts --entry src/objects/index.ts --format cjs,esm --dts",
60
- "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
60
+ "clean": "rm -rf .turbo && rm -rf dist",
61
61
  "dev": "yarn build -- --watch",
62
62
  "docs": "typedoc src",
63
- "format": "npx prettier --write ./src",
64
- "lint": "npx prettier --check ./src",
63
+ "format": "prettier src --check",
64
+ "format:fix": "prettier src --write",
65
+ "lint": "prettier --check ./src",
65
66
  "postversion": "yarn build",
66
67
  "test": "jest --no-cache --runInBand --bail",
67
- "type-check": "tsc --noEmit"
68
+ "types": "tsc"
68
69
  },
69
70
  "license": "Apache-2.0",
70
71
  "dependencies": {
71
- "@lightsparkdev/core": "0.3.1",
72
+ "@lightsparkdev/core": "0.3.2",
72
73
  "auto-bind": "^5.0.1",
73
74
  "crypto": "^1.0.1",
74
75
  "crypto-browserify": "^3.12.0",
75
76
  "dayjs": "^1.11.7",
76
77
  "graphql": "^16.6.0",
77
78
  "graphql-ws": "^5.11.3",
78
- "typedoc": "^0.24.7",
79
79
  "ws": "^8.12.1",
80
80
  "zen-observable-ts": "^1.1.0"
81
81
  },
@@ -83,12 +83,13 @@
83
83
  "@types/crypto-js": "^4.1.1",
84
84
  "@types/jest": "^29.5.2",
85
85
  "@types/ws": "^8.5.4",
86
- "jest": "^29.5.0",
87
- "prettier": "^2.8.4",
88
- "prettier-plugin-organize-imports": "^3.2.2",
89
- "ts-jest": "^29.1.0",
86
+ "jest": "^29.4.1",
87
+ "prettier": "2.8.7",
88
+ "ts-jest": "^29.0.5",
90
89
  "ts-node": "^10.9.1",
91
90
  "tsconfig": "*",
91
+ "tsup": "^6.7.0",
92
+ "typedoc": "^0.24.7",
92
93
  "typescript": "^4.9.5"
93
94
  }
94
95
  }
@@ -1,5 +1,5 @@
1
1
  import WebhookEventType from "../objects/WebhookEventType.js";
2
- import { verify_and_parse_webhook } from "../webhooks.js";
2
+ import { verifyAndParseWebhook } from "../webhooks.js";
3
3
 
4
4
  describe("Webhooks", () => {
5
5
  test("should verify and parse webhook data", async () => {
@@ -12,8 +12,8 @@ describe("Webhooks", () => {
12
12
  "62a8829aeb48b4142533520b1f7f86cdb1ee7d718bf3ea15bc1c662d4c453b74";
13
13
  const webhookSecret = "3gZ5oQQUASYmqQNuEk0KambNMVkOADDItIJjzUlAWjX";
14
14
 
15
- const webhook = await verify_and_parse_webhook(
16
- new TextEncoder().encode(data),
15
+ const webhook = await verifyAndParseWebhook(
16
+ Buffer.from(data, "utf-8"),
17
17
  hexdigest,
18
18
  webhookSecret
19
19
  );
package/src/webhooks.ts CHANGED
@@ -8,9 +8,10 @@ export interface WebhookEvent {
8
8
  event_id: string;
9
9
  timestamp: Date;
10
10
  entity_id: string;
11
+ wallet_id?: string;
11
12
  }
12
13
 
13
- export const verify_and_parse_webhook = (
14
+ export const verifyAndParseWebhook = (
14
15
  data: Uint8Array,
15
16
  hexdigest: string,
16
17
  webhook_secret: string
@@ -21,16 +22,16 @@ export const verify_and_parse_webhook = (
21
22
  throw new Error("Webhook message hash does not match signature");
22
23
  }
23
24
 
24
- return parse_webhook(data);
25
+ return parseWebhook(data);
25
26
  };
26
27
 
27
- export const parse_webhook = async (
28
- data: Uint8Array
29
- ): Promise<WebhookEvent> => {
30
- if (typeof TextDecoder === "undefined") {
31
- const TextDecoder = (await import("text-encoding")).TextDecoder;
28
+ const parseWebhook = async (data: Uint8Array): Promise<WebhookEvent> => {
29
+ let td = TextDecoder;
30
+ if (typeof td === "undefined") {
31
+ const tdModule = await import("text-encoding");
32
+ td = tdModule.TextDecoder;
32
33
  }
33
- const dataStr = new TextDecoder().decode(data);
34
+ const dataStr = new td().decode(data);
34
35
  const event = JSON.parse(dataStr);
35
36
 
36
37
  return {
@@ -38,5 +39,6 @@ export const parse_webhook = async (
38
39
  event_id: event.event_id,
39
40
  timestamp: new Date(event.timestamp),
40
41
  entity_id: event.entity_id,
42
+ wallet_id: event.wallet_id,
41
43
  };
42
44
  };