@neurosity/sdk 6.2.1-next.2 → 6.2.2

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.
Files changed (305) hide show
  1. package/dist/browser/neurosity.iife.js +48717 -0
  2. package/dist/browser/neurosity.js +666 -0
  3. package/dist/browser/neurosity.js.map +1 -0
  4. package/dist/{Neurosity.d.ts → cjs/Neurosity.d.ts} +2 -116
  5. package/dist/cjs/Neurosity.js +1244 -0
  6. package/dist/{api → cjs/api}/bluetooth/BluetoothClient.d.ts +6 -6
  7. package/dist/cjs/api/bluetooth/BluetoothClient.js +310 -0
  8. package/dist/cjs/api/bluetooth/BluetoothTransport.d.ts +33 -0
  9. package/dist/cjs/api/bluetooth/BluetoothTransport.js +2 -0
  10. package/dist/{api → cjs/api}/bluetooth/constants.d.ts +0 -0
  11. package/dist/cjs/api/bluetooth/constants.js +9 -0
  12. package/dist/{api → cjs/api}/bluetooth/index.d.ts +0 -0
  13. package/dist/cjs/api/bluetooth/index.js +21 -0
  14. package/dist/{api → cjs/api}/bluetooth/react-native/ReactNativeTransport.d.ts +4 -4
  15. package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.js +411 -0
  16. package/dist/cjs/api/bluetooth/react-native/types/BleManagerTypes.d.ts +63 -0
  17. package/dist/cjs/api/bluetooth/react-native/types/BleManagerTypes.js +11 -0
  18. package/dist/cjs/api/bluetooth/react-native/types/ReactNativeTypes.d.ts +180 -0
  19. package/dist/cjs/api/bluetooth/react-native/types/ReactNativeTypes.js +10 -0
  20. package/dist/{api → cjs/api}/bluetooth/types/index.d.ts +2 -2
  21. package/dist/cjs/api/bluetooth/types/index.js +22 -0
  22. package/dist/{api → cjs/api}/bluetooth/utils/create6DigitPin.d.ts +0 -0
  23. package/dist/cjs/api/bluetooth/utils/create6DigitPin.js +8 -0
  24. package/dist/{api → cjs/api}/bluetooth/utils/csvBufferToEpoch.d.ts +0 -0
  25. package/dist/cjs/api/bluetooth/utils/csvBufferToEpoch.js +36 -0
  26. package/dist/{api → cjs/api}/bluetooth/utils/encoding.d.ts +0 -0
  27. package/dist/cjs/api/bluetooth/utils/encoding.js +22 -0
  28. package/dist/{api → cjs/api}/bluetooth/utils/osHasBluetoothSupport.d.ts +0 -0
  29. package/dist/cjs/api/bluetooth/utils/osHasBluetoothSupport.js +23 -0
  30. package/dist/{api → cjs/api}/bluetooth/utils/stitch.d.ts +1 -1
  31. package/dist/cjs/api/bluetooth/utils/stitch.js +22 -0
  32. package/dist/{api → cjs/api}/bluetooth/web/WebBluetoothTransport.d.ts +1 -1
  33. package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.js +430 -0
  34. package/dist/{api → cjs/api}/bluetooth/web/isMaybeWebWorkerContext.d.ts +0 -0
  35. package/dist/cjs/api/bluetooth/web/isMaybeWebWorkerContext.js +8 -0
  36. package/dist/{api → cjs/api}/bluetooth/web/isWebBluetoothSupported.d.ts +0 -0
  37. package/dist/cjs/api/bluetooth/web/isWebBluetoothSupported.js +11 -0
  38. package/dist/{api → cjs/api}/firebase/FirebaseApp.d.ts +0 -0
  39. package/dist/cjs/api/firebase/FirebaseApp.js +70 -0
  40. package/dist/{api → cjs/api}/firebase/FirebaseDevice.d.ts +1 -1
  41. package/dist/cjs/api/firebase/FirebaseDevice.js +146 -0
  42. package/dist/{api → cjs/api}/firebase/FirebaseUser.d.ts +0 -0
  43. package/dist/cjs/api/firebase/FirebaseUser.js +434 -0
  44. package/dist/{api → cjs/api}/firebase/config.d.ts +0 -0
  45. package/dist/cjs/api/firebase/config.js +11 -0
  46. package/dist/{api → cjs/api}/firebase/deviceStore.d.ts +0 -0
  47. package/dist/cjs/api/firebase/deviceStore.js +191 -0
  48. package/dist/{api → cjs/api}/firebase/index.d.ts +0 -0
  49. package/dist/cjs/api/firebase/index.js +19 -0
  50. package/dist/{api → cjs/api}/https/config.d.ts +0 -0
  51. package/dist/cjs/api/https/config.js +4 -0
  52. package/dist/{api → cjs/api}/https/createOAuthURL.d.ts +0 -0
  53. package/dist/cjs/api/https/createOAuthURL.js +18 -0
  54. package/dist/{api → cjs/api}/https/getOAuthToken.d.ts +0 -0
  55. package/dist/cjs/api/https/getOAuthToken.js +34 -0
  56. package/dist/{api → cjs/api}/https/utils.d.ts +0 -0
  57. package/dist/cjs/api/https/utils.js +13 -0
  58. package/dist/{api → cjs/api}/index.d.ts +0 -8
  59. package/dist/cjs/api/index.js +307 -0
  60. package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
  61. package/dist/cjs/index.js +18 -0
  62. package/dist/{subscriptions → cjs/subscriptions}/SubscriptionManager.d.ts +0 -0
  63. package/dist/cjs/subscriptions/SubscriptionManager.js +27 -0
  64. package/dist/{timesync → cjs/timesync}/Timesync.d.ts +1 -1
  65. package/dist/cjs/timesync/Timesync.js +78 -0
  66. package/dist/{timesync → cjs/timesync}/index.d.ts +0 -0
  67. package/dist/cjs/timesync/index.js +17 -0
  68. package/dist/cjs/types/accelerometer.d.ts +10 -0
  69. package/dist/cjs/types/accelerometer.js +2 -0
  70. package/dist/cjs/types/actions.d.ts +16 -0
  71. package/dist/cjs/types/actions.js +2 -0
  72. package/dist/cjs/types/awareness.d.ts +1 -0
  73. package/dist/cjs/types/awareness.js +2 -0
  74. package/dist/cjs/types/brainwaves.d.ts +26 -0
  75. package/dist/cjs/types/brainwaves.js +2 -0
  76. package/dist/cjs/types/calm.d.ts +6 -0
  77. package/dist/cjs/types/calm.js +2 -0
  78. package/dist/cjs/types/client.d.ts +22 -0
  79. package/dist/cjs/types/client.js +2 -0
  80. package/dist/cjs/types/credentials.d.ts +12 -0
  81. package/dist/cjs/types/credentials.js +2 -0
  82. package/dist/cjs/types/deviceInfo.d.ts +18 -0
  83. package/dist/cjs/types/deviceInfo.js +2 -0
  84. package/dist/cjs/types/epoch.d.ts +12 -0
  85. package/dist/cjs/types/epoch.js +2 -0
  86. package/dist/cjs/types/experiment.d.ts +9 -0
  87. package/dist/cjs/types/experiment.js +2 -0
  88. package/dist/cjs/types/focus.d.ts +6 -0
  89. package/dist/cjs/types/focus.js +2 -0
  90. package/dist/cjs/types/hapticEffects.d.ts +125 -0
  91. package/dist/cjs/types/hapticEffects.js +2 -0
  92. package/dist/cjs/types/kinesis.d.ts +6 -0
  93. package/dist/cjs/types/kinesis.js +2 -0
  94. package/dist/cjs/types/marker.d.ts +7 -0
  95. package/dist/cjs/types/marker.js +2 -0
  96. package/dist/cjs/types/metrics.d.ts +21 -0
  97. package/dist/cjs/types/metrics.js +2 -0
  98. package/dist/cjs/types/oauth.d.ts +20 -0
  99. package/dist/cjs/types/oauth.js +2 -0
  100. package/dist/cjs/types/options.d.ts +51 -0
  101. package/dist/cjs/types/options.js +2 -0
  102. package/dist/cjs/types/sample.d.ts +15 -0
  103. package/dist/cjs/types/sample.js +2 -0
  104. package/dist/cjs/types/settings.d.ts +13 -0
  105. package/dist/cjs/types/settings.js +2 -0
  106. package/dist/cjs/types/signalQuality.d.ts +13 -0
  107. package/dist/cjs/types/signalQuality.js +2 -0
  108. package/dist/cjs/types/skill.d.ts +68 -0
  109. package/dist/cjs/types/skill.js +2 -0
  110. package/dist/{types → cjs/types}/status.d.ts +0 -0
  111. package/dist/cjs/types/status.js +22 -0
  112. package/dist/{types → cjs/types}/streaming.d.ts +0 -0
  113. package/dist/cjs/types/streaming.js +20 -0
  114. package/dist/cjs/types/subscriptions.d.ts +23 -0
  115. package/dist/cjs/types/subscriptions.js +2 -0
  116. package/dist/cjs/types/training.d.ts +19 -0
  117. package/dist/cjs/types/training.js +2 -0
  118. package/dist/cjs/types/user.d.ts +12 -0
  119. package/dist/cjs/types/user.js +2 -0
  120. package/dist/{utils → cjs/utils}/errors.d.ts +0 -0
  121. package/dist/cjs/utils/errors.js +17 -0
  122. package/dist/{utils → cjs/utils}/filterInternalKeys.d.ts +0 -0
  123. package/dist/cjs/utils/filterInternalKeys.js +21 -0
  124. package/dist/{utils → cjs/utils}/hapticEffects.d.ts +0 -0
  125. package/dist/cjs/utils/hapticEffects.js +130 -0
  126. package/dist/{utils → cjs/utils}/heartbeat.d.ts +0 -0
  127. package/dist/cjs/utils/heartbeat.js +41 -0
  128. package/dist/{utils → cjs/utils}/is-node.d.ts +0 -0
  129. package/dist/cjs/utils/is-node.js +9 -0
  130. package/dist/cjs/utils/metrics.d.ts +1 -0
  131. package/dist/cjs/utils/metrics.js +56 -0
  132. package/dist/{utils → cjs/utils}/oauth.d.ts +1 -1
  133. package/dist/cjs/utils/oauth.js +92 -0
  134. package/dist/cjs/utils/pick.d.ts +1 -0
  135. package/dist/cjs/utils/pick.js +5 -0
  136. package/dist/{utils → cjs/utils}/pipes.d.ts +0 -0
  137. package/dist/cjs/utils/pipes.js +71 -0
  138. package/dist/{utils → cjs/utils}/platform.d.ts +0 -0
  139. package/dist/cjs/utils/platform.js +47 -0
  140. package/dist/{utils → cjs/utils}/subscription.d.ts +0 -0
  141. package/dist/cjs/utils/subscription.js +55 -0
  142. package/dist/cjs/utils/transferDevice.d.ts +9 -0
  143. package/dist/cjs/utils/transferDevice.js +2 -0
  144. package/dist/{utils → cjs/utils}/whileOnline.d.ts +1 -1
  145. package/dist/cjs/utils/whileOnline.js +15 -0
  146. package/dist/electron/index.js +86 -0
  147. package/dist/electron/index.js.map +1 -0
  148. package/dist/esm/Neurosity.d.ts +619 -0
  149. package/dist/esm/Neurosity.js +1213 -0
  150. package/dist/esm/api/bluetooth/BluetoothClient.d.ts +72 -0
  151. package/dist/esm/api/bluetooth/BluetoothClient.js +306 -0
  152. package/dist/esm/api/bluetooth/BluetoothTransport.d.ts +33 -0
  153. package/dist/esm/api/bluetooth/BluetoothTransport.js +1 -0
  154. package/dist/esm/api/bluetooth/constants.d.ts +4 -0
  155. package/dist/esm/api/bluetooth/constants.js +6 -0
  156. package/dist/esm/api/bluetooth/index.d.ts +5 -0
  157. package/dist/esm/api/bluetooth/index.js +5 -0
  158. package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.d.ts +70 -0
  159. package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.js +407 -0
  160. package/dist/esm/api/bluetooth/react-native/types/BleManagerTypes.d.ts +63 -0
  161. package/dist/esm/api/bluetooth/react-native/types/BleManagerTypes.js +8 -0
  162. package/dist/esm/api/bluetooth/react-native/types/ReactNativeTypes.d.ts +180 -0
  163. package/dist/esm/api/bluetooth/react-native/types/ReactNativeTypes.js +9 -0
  164. package/dist/esm/api/bluetooth/types/index.d.ts +31 -0
  165. package/dist/esm/api/bluetooth/types/index.js +19 -0
  166. package/dist/esm/api/bluetooth/utils/create6DigitPin.d.ts +1 -0
  167. package/dist/esm/api/bluetooth/utils/create6DigitPin.js +4 -0
  168. package/dist/esm/api/bluetooth/utils/csvBufferToEpoch.d.ts +11 -0
  169. package/dist/esm/api/bluetooth/utils/csvBufferToEpoch.js +31 -0
  170. package/dist/esm/api/bluetooth/utils/encoding.d.ts +3 -0
  171. package/dist/esm/api/bluetooth/utils/encoding.js +17 -0
  172. package/dist/esm/api/bluetooth/utils/osHasBluetoothSupport.d.ts +2 -0
  173. package/dist/esm/api/bluetooth/utils/osHasBluetoothSupport.js +16 -0
  174. package/dist/esm/api/bluetooth/utils/stitch.d.ts +5 -0
  175. package/dist/esm/api/bluetooth/utils/stitch.js +18 -0
  176. package/dist/esm/api/bluetooth/web/WebBluetoothTransport.d.ts +54 -0
  177. package/dist/esm/api/bluetooth/web/WebBluetoothTransport.js +426 -0
  178. package/dist/esm/api/bluetooth/web/isMaybeWebWorkerContext.d.ts +1 -0
  179. package/dist/esm/api/bluetooth/web/isMaybeWebWorkerContext.js +4 -0
  180. package/dist/esm/api/bluetooth/web/isWebBluetoothSupported.d.ts +1 -0
  181. package/dist/esm/api/bluetooth/web/isWebBluetoothSupported.js +7 -0
  182. package/dist/esm/api/firebase/FirebaseApp.d.ts +20 -0
  183. package/dist/esm/api/firebase/FirebaseApp.js +63 -0
  184. package/dist/esm/api/firebase/FirebaseDevice.d.ts +68 -0
  185. package/dist/esm/api/firebase/FirebaseDevice.js +139 -0
  186. package/dist/esm/api/firebase/FirebaseUser.d.ts +53 -0
  187. package/dist/esm/api/firebase/FirebaseUser.js +426 -0
  188. package/dist/esm/api/firebase/config.d.ts +8 -0
  189. package/dist/esm/api/firebase/config.js +8 -0
  190. package/dist/esm/api/firebase/deviceStore.d.ts +26 -0
  191. package/dist/esm/api/firebase/deviceStore.js +184 -0
  192. package/dist/esm/api/firebase/index.d.ts +3 -0
  193. package/dist/esm/api/firebase/index.js +3 -0
  194. package/dist/esm/api/https/config.d.ts +1 -0
  195. package/dist/esm/api/https/config.js +1 -0
  196. package/dist/esm/api/https/createOAuthURL.d.ts +3 -0
  197. package/dist/esm/api/https/createOAuthURL.js +11 -0
  198. package/dist/esm/api/https/getOAuthToken.d.ts +3 -0
  199. package/dist/esm/api/https/getOAuthToken.js +27 -0
  200. package/dist/esm/api/https/utils.d.ts +2 -0
  201. package/dist/esm/api/https/utils.js +9 -0
  202. package/dist/esm/api/index.d.ts +109 -0
  203. package/dist/esm/api/index.js +300 -0
  204. package/dist/esm/index.d.ts +2 -0
  205. package/dist/esm/index.js +2 -0
  206. package/dist/esm/neurosity.mjs +48705 -0
  207. package/dist/esm/subscriptions/SubscriptionManager.d.ts +11 -0
  208. package/dist/esm/subscriptions/SubscriptionManager.js +23 -0
  209. package/dist/esm/timesync/Timesync.d.ts +20 -0
  210. package/dist/esm/timesync/Timesync.js +71 -0
  211. package/dist/esm/timesync/index.d.ts +1 -0
  212. package/dist/esm/timesync/index.js +1 -0
  213. package/dist/esm/types/accelerometer.d.ts +10 -0
  214. package/dist/esm/types/accelerometer.js +1 -0
  215. package/dist/esm/types/actions.d.ts +16 -0
  216. package/dist/esm/types/actions.js +1 -0
  217. package/dist/esm/types/awareness.d.ts +1 -0
  218. package/dist/esm/types/awareness.js +1 -0
  219. package/dist/esm/types/brainwaves.d.ts +26 -0
  220. package/dist/esm/types/brainwaves.js +1 -0
  221. package/dist/esm/types/calm.d.ts +6 -0
  222. package/dist/esm/types/calm.js +1 -0
  223. package/dist/esm/types/client.d.ts +22 -0
  224. package/dist/esm/types/client.js +1 -0
  225. package/dist/esm/types/credentials.d.ts +12 -0
  226. package/dist/esm/types/credentials.js +1 -0
  227. package/dist/esm/types/deviceInfo.d.ts +18 -0
  228. package/dist/esm/types/deviceInfo.js +1 -0
  229. package/dist/esm/types/epoch.d.ts +12 -0
  230. package/dist/esm/types/epoch.js +1 -0
  231. package/dist/esm/types/experiment.d.ts +9 -0
  232. package/dist/esm/types/experiment.js +1 -0
  233. package/dist/esm/types/focus.d.ts +6 -0
  234. package/dist/esm/types/focus.js +1 -0
  235. package/dist/esm/types/hapticEffects.d.ts +125 -0
  236. package/dist/esm/types/hapticEffects.js +1 -0
  237. package/dist/esm/types/kinesis.d.ts +6 -0
  238. package/dist/esm/types/kinesis.js +1 -0
  239. package/dist/esm/types/marker.d.ts +7 -0
  240. package/dist/esm/types/marker.js +1 -0
  241. package/dist/esm/types/metrics.d.ts +21 -0
  242. package/dist/esm/types/metrics.js +1 -0
  243. package/dist/esm/types/oauth.d.ts +20 -0
  244. package/dist/esm/types/oauth.js +1 -0
  245. package/dist/esm/types/options.d.ts +51 -0
  246. package/dist/esm/types/options.js +1 -0
  247. package/dist/esm/types/sample.d.ts +15 -0
  248. package/dist/esm/types/sample.js +1 -0
  249. package/dist/esm/types/settings.d.ts +13 -0
  250. package/dist/esm/types/settings.js +1 -0
  251. package/dist/esm/types/signalQuality.d.ts +13 -0
  252. package/dist/esm/types/signalQuality.js +1 -0
  253. package/dist/esm/types/skill.d.ts +68 -0
  254. package/dist/esm/types/skill.js +1 -0
  255. package/dist/esm/types/status.d.ts +26 -0
  256. package/dist/esm/types/status.js +19 -0
  257. package/dist/esm/types/streaming.d.ts +15 -0
  258. package/dist/esm/types/streaming.js +17 -0
  259. package/dist/esm/types/subscriptions.d.ts +23 -0
  260. package/dist/esm/types/subscriptions.js +1 -0
  261. package/dist/esm/types/training.d.ts +19 -0
  262. package/dist/esm/types/training.js +1 -0
  263. package/dist/esm/types/user.d.ts +12 -0
  264. package/dist/esm/types/user.js +1 -0
  265. package/dist/esm/utils/errors.d.ts +5 -0
  266. package/dist/esm/utils/errors.js +11 -0
  267. package/dist/esm/utils/filterInternalKeys.d.ts +3 -0
  268. package/dist/esm/utils/filterInternalKeys.js +17 -0
  269. package/dist/esm/utils/hapticEffects.d.ts +123 -0
  270. package/dist/esm/utils/hapticEffects.js +125 -0
  271. package/dist/esm/utils/heartbeat.d.ts +4 -0
  272. package/dist/esm/utils/heartbeat.js +33 -0
  273. package/dist/esm/utils/is-node.d.ts +1 -0
  274. package/dist/esm/utils/is-node.js +5 -0
  275. package/dist/esm/utils/metrics.d.ts +1 -0
  276. package/dist/esm/utils/metrics.js +52 -0
  277. package/dist/esm/utils/oauth.d.ts +9 -0
  278. package/dist/esm/utils/oauth.js +64 -0
  279. package/dist/esm/utils/pick.d.ts +1 -0
  280. package/dist/esm/utils/pick.js +1 -0
  281. package/dist/esm/utils/pipes.d.ts +46 -0
  282. package/dist/esm/utils/pipes.js +65 -0
  283. package/dist/esm/utils/platform.d.ts +30 -0
  284. package/dist/esm/utils/platform.js +41 -0
  285. package/dist/esm/utils/subscription.d.ts +6 -0
  286. package/dist/esm/utils/subscription.js +24 -0
  287. package/dist/esm/utils/transferDevice.d.ts +9 -0
  288. package/dist/esm/utils/transferDevice.js +1 -0
  289. package/dist/esm/utils/whileOnline.d.ts +8 -0
  290. package/dist/esm/utils/whileOnline.js +11 -0
  291. package/dist/examples/auth.html +32 -0
  292. package/dist/examples/cloud.html +17 -0
  293. package/dist/examples/index.html +1 -0
  294. package/dist/examples/neurosity.iife.js +48717 -0
  295. package/dist/examples/neurosity.js +666 -0
  296. package/dist/examples/neurosity.mjs +48705 -0
  297. package/dist/examples/training.html +49 -0
  298. package/package.json +23 -18
  299. package/dist/index.cjs +0 -2
  300. package/dist/index.cjs.map +0 -1
  301. package/dist/index.m.js +0 -2
  302. package/dist/index.m.js.map +0 -1
  303. package/dist/index.umd.js +0 -2
  304. package/dist/index.umd.js.map +0 -1
  305. package/dist/utils/metrics.d.ts +0 -6
@@ -0,0 +1,1244 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.Notion = exports.Neurosity = void 0;
39
+ const rxjs_1 = require("rxjs");
40
+ const rxjs_2 = require("rxjs");
41
+ const operators_1 = require("rxjs/operators");
42
+ const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
43
+ const index_1 = require("./api/index");
44
+ const index_2 = require("./api/index");
45
+ const streaming_1 = require("./types/streaming");
46
+ const subscription_1 = require("./utils/subscription");
47
+ const status_1 = require("./types/status");
48
+ const errors = __importStar(require("./utils/errors"));
49
+ const platform = __importStar(require("./utils/platform"));
50
+ const hapticEffects = __importStar(require("./utils/hapticEffects"));
51
+ const oauth_1 = require("./utils/oauth");
52
+ const oauth_2 = require("./utils/oauth");
53
+ const createOAuthURL_1 = require("./api/https/createOAuthURL");
54
+ const getOAuthToken_1 = require("./api/https/getOAuthToken");
55
+ const is_node_1 = require("./utils/is-node");
56
+ const metrics_1 = require("./utils/metrics");
57
+ const bluetooth_1 = require("./api/bluetooth");
58
+ const types_1 = require("./api/bluetooth/types");
59
+ const defaultOptions = {
60
+ timesync: false,
61
+ autoSelectDevice: true,
62
+ streamingMode: streaming_1.STREAMING_MODE.WIFI_ONLY,
63
+ emulator: false,
64
+ emulatorHost: "localhost",
65
+ emulatorAuthPort: 9099,
66
+ emulatorDatabasePort: 9000,
67
+ emulatorFunctionsPort: 5001,
68
+ emulatorFirestorePort: 8080,
69
+ emulatorOptions: {}
70
+ };
71
+ /**
72
+ * import StreamingModes from "@site/src/components/StreamingModes";
73
+ *
74
+ * Example
75
+ * ```typescript
76
+ * import { Neurosity } from "@neurosity/sdk";
77
+ *
78
+ * const neurosity = new Neurosity();
79
+ * ```
80
+ */
81
+ class Neurosity {
82
+ /**
83
+ * Creates new instance of the Neurosity SDK
84
+ *
85
+ * ```typescript
86
+ * const neurosity = new Neurosity();
87
+ * ```
88
+
89
+ * @param options
90
+ */
91
+ constructor(options = {}) {
92
+ /**
93
+ * @hidden
94
+ */
95
+ this.streamingMode$ = new rxjs_2.ReplaySubject(1);
96
+ const { streamingMode, bluetoothTransport } = options;
97
+ this.options = Object.freeze(Object.assign(Object.assign({}, defaultOptions), options));
98
+ this.cloudClient = new index_1.CloudClient(this.options);
99
+ if (!!bluetoothTransport) {
100
+ this.bluetoothClient = new bluetooth_1.BluetoothClient({
101
+ selectedDevice$: this.onDeviceChange(),
102
+ createBluetoothToken: this.createBluetoothToken.bind(this),
103
+ transport: bluetoothTransport
104
+ });
105
+ }
106
+ this._initStreamingMode(streamingMode, !!bluetoothTransport);
107
+ }
108
+ /**
109
+ *
110
+ * @hidden
111
+ */
112
+ _initStreamingMode(streamingMode, hasBluetoothTransport) {
113
+ const streamingModeFeaturesBluetooth = [
114
+ streaming_1.STREAMING_MODE.BLUETOOTH_WITH_WIFI_FALLBACK,
115
+ streaming_1.STREAMING_MODE.WIFI_WITH_BLUETOOTH_FALLBACK
116
+ ].includes(streamingMode);
117
+ const isInvalidStreamingMode = !Object.values(streaming_1.STREAMING_MODE).includes(streamingMode);
118
+ const isMissingBluetoothTransport = streamingModeFeaturesBluetooth && !hasBluetoothTransport;
119
+ this.isMissingBluetoothTransport = isMissingBluetoothTransport;
120
+ const shouldDefaultToCloud = !streamingMode || isInvalidStreamingMode || isMissingBluetoothTransport;
121
+ // Default to backwards compatible cloud streaming mode if:
122
+ // 1. No streaming mode is provided
123
+ // 2. An invalid streaming mode is provided
124
+ // 3. A streaming mode containing bluetooth is provided, but without a bluetooth transport
125
+ if (shouldDefaultToCloud) {
126
+ this.streamingMode$.next(streaming_1.STREAMING_MODE.WIFI_ONLY);
127
+ }
128
+ else {
129
+ this.streamingMode$.next(streamingMode);
130
+ }
131
+ }
132
+ /**
133
+ * Subscribe to the device's streaming state changes and the current strategy
134
+ *
135
+ * Streams the current mode of streaming (wifi or bluetooth).
136
+ *
137
+ * ```typescript
138
+ * neurosity.streamingState().subscribe((streamingState) => {
139
+ * console.log(streamingState);
140
+ * // { streamingMode: "wifi-only", activeMode: "wifi", connected: true }
141
+ * });
142
+ * ```
143
+ */
144
+ streamingState() {
145
+ const isWifiOnline = (state) => [status_1.STATUS.ONLINE, status_1.STATUS.UPDATING].includes(state);
146
+ return this.streamingMode$.pipe((0, operators_1.switchMap)((streamingMode) => {
147
+ if (this.isMissingBluetoothTransport) {
148
+ return this.cloudClient.status().pipe((0, operators_1.map)(({ state }) => ({
149
+ connected: isWifiOnline(state),
150
+ streamingMode,
151
+ activeMode: streaming_1.STREAMING_TYPE.WIFI
152
+ })));
153
+ }
154
+ return this.onDeviceChange().pipe((0, operators_1.switchMap)((selectDevice) => !selectDevice
155
+ ? rxjs_2.EMPTY
156
+ : (0, rxjs_1.combineLatest)({
157
+ wifiStatus: this.cloudClient.status(),
158
+ bluetoothConnection: !!(this === null || this === void 0 ? void 0 : this.bluetoothClient)
159
+ ? this.bluetoothClient.connection()
160
+ : (0, rxjs_1.of)(types_1.BLUETOOTH_CONNECTION.DISCONNECTED)
161
+ }).pipe((0, operators_1.map)(({ wifiStatus, bluetoothConnection }) => {
162
+ const isBluetoothConnected = bluetoothConnection === types_1.BLUETOOTH_CONNECTION.CONNECTED;
163
+ switch (streamingMode) {
164
+ default:
165
+ case streaming_1.STREAMING_MODE.WIFI_ONLY:
166
+ return {
167
+ connected: isWifiOnline(wifiStatus.state),
168
+ streamingMode,
169
+ activeMode: streaming_1.STREAMING_TYPE.WIFI
170
+ };
171
+ case streaming_1.STREAMING_MODE.WIFI_WITH_BLUETOOTH_FALLBACK:
172
+ return {
173
+ connected: isWifiOnline(wifiStatus.state) ||
174
+ !isBluetoothConnected
175
+ ? isWifiOnline(wifiStatus.state)
176
+ : isBluetoothConnected,
177
+ streamingMode,
178
+ activeMode: isWifiOnline(wifiStatus.state) ||
179
+ !isBluetoothConnected
180
+ ? streaming_1.STREAMING_TYPE.WIFI
181
+ : streaming_1.STREAMING_TYPE.BLUETOOTH
182
+ };
183
+ case streaming_1.STREAMING_MODE.BLUETOOTH_WITH_WIFI_FALLBACK:
184
+ return {
185
+ connected: isBluetoothConnected
186
+ ? true
187
+ : isWifiOnline(wifiStatus.state),
188
+ streamingMode,
189
+ activeMode: isBluetoothConnected
190
+ ? streaming_1.STREAMING_TYPE.BLUETOOTH
191
+ : streaming_1.STREAMING_TYPE.WIFI
192
+ };
193
+ }
194
+ }), (0, operators_1.distinctUntilChanged)((a, b) => (0, fast_deep_equal_1.default)(a, b)))));
195
+ }));
196
+ }
197
+ /**
198
+ *
199
+ * @hidden
200
+ */
201
+ _withStreamingModeObservable(streams) {
202
+ const { wifi, bluetooth } = streams;
203
+ return this.streamingState().pipe((0, operators_1.switchMap)(({ activeMode }) => {
204
+ switch (activeMode) {
205
+ case streaming_1.STREAMING_TYPE.WIFI:
206
+ return wifi();
207
+ case streaming_1.STREAMING_TYPE.BLUETOOTH:
208
+ return bluetooth();
209
+ default:
210
+ return wifi();
211
+ }
212
+ }));
213
+ }
214
+ /**
215
+ *
216
+ * @hidden
217
+ */
218
+ _withStreamingModePromise(promises) {
219
+ return __awaiter(this, void 0, void 0, function* () {
220
+ const { wifi, bluetooth } = promises;
221
+ const { activeMode } = yield (0, rxjs_2.firstValueFrom)(this.streamingState());
222
+ switch (activeMode) {
223
+ case streaming_1.STREAMING_TYPE.WIFI:
224
+ return yield wifi();
225
+ case streaming_1.STREAMING_TYPE.BLUETOOTH:
226
+ return yield bluetooth();
227
+ default:
228
+ return yield wifi();
229
+ }
230
+ });
231
+ }
232
+ /**
233
+ *
234
+ * @hidden
235
+ */
236
+ get bluetooth() {
237
+ return this === null || this === void 0 ? void 0 : this.bluetoothClient;
238
+ }
239
+ /**
240
+ *
241
+ * @hidden
242
+ */
243
+ _getCloudMetricDependencies() {
244
+ return {
245
+ options: this.options,
246
+ cloudClient: this.cloudClient,
247
+ onDeviceChange: this.onDeviceChange.bind(this),
248
+ status: this.status.bind(this)
249
+ };
250
+ }
251
+ /**
252
+ * Starts user session
253
+ *
254
+ * ```typescript
255
+ * await neurosity.login({
256
+ * email: "...",
257
+ * password: "..."
258
+ * });
259
+ * ```
260
+ *
261
+ * @param credentials
262
+ */
263
+ login(credentials) {
264
+ return __awaiter(this, void 0, void 0, function* () {
265
+ return yield this.cloudClient.login(credentials);
266
+ });
267
+ }
268
+ /**
269
+ * Ends user session
270
+ *
271
+ * ```typescript
272
+ * await neurosity.logout();
273
+ * // session has ended
274
+ * ```
275
+ *
276
+ */
277
+ logout() {
278
+ return __awaiter(this, void 0, void 0, function* () {
279
+ return yield this.cloudClient.logout();
280
+ });
281
+ }
282
+ /**
283
+ * @internal
284
+ * Not user facing.
285
+ */
286
+ __getApp() {
287
+ return this.cloudClient.__getApp();
288
+ }
289
+ /**
290
+ * Subscribe to auth state changes
291
+ *
292
+ * Streams the state of the auth session. If user has logged in, the user object will be set. When logged out, the user object will be null.
293
+ *
294
+ * ```typescript
295
+ * neurosity.onAuthStateChanged().subscribe((user) => {
296
+ * console.log(user);
297
+ * });
298
+ * ```
299
+ */
300
+ onAuthStateChanged() {
301
+ return this.cloudClient.onAuthStateChanged();
302
+ }
303
+ /**
304
+ * @internal
305
+ * Not user facing yet
306
+ */
307
+ addDevice(deviceId) {
308
+ const [hasOAuthError, OAuthError] = (0, oauth_1.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims, "addDevice");
309
+ if (hasOAuthError) {
310
+ return Promise.reject(OAuthError);
311
+ }
312
+ return this.cloudClient.addDevice(deviceId);
313
+ }
314
+ /**
315
+ * @internal
316
+ * Not user facing yet
317
+ */
318
+ removeDevice(deviceId) {
319
+ const [hasOAuthError, OAuthError] = (0, oauth_1.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims, "removeDevice");
320
+ if (hasOAuthError) {
321
+ return Promise.reject(OAuthError);
322
+ }
323
+ return this.cloudClient.removeDevice(deviceId);
324
+ }
325
+ /**
326
+ * @internal
327
+ * Not user facing yet
328
+ */
329
+ transferDevice(options) {
330
+ const [hasOAuthError, OAuthError] = (0, oauth_1.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims, "transferDevice");
331
+ if (hasOAuthError) {
332
+ return Promise.reject(OAuthError);
333
+ }
334
+ return this.cloudClient.transferDevice(options);
335
+ }
336
+ /**
337
+ * @internal
338
+ * Not user facing yet
339
+ */
340
+ onUserDevicesChange() {
341
+ const [hasOAuthError, OAuthError] = (0, oauth_1.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims, "onUserDevicesChange");
342
+ if (hasOAuthError) {
343
+ return (0, rxjs_1.throwError)(() => OAuthError);
344
+ }
345
+ return this.cloudClient.onUserDevicesChange();
346
+ }
347
+ /**
348
+ * @internal
349
+ * Not user facing yet
350
+ */
351
+ onUserClaimsChange() {
352
+ return this.cloudClient.onUserClaimsChange();
353
+ }
354
+ /**
355
+ * Get user devices
356
+ *
357
+ * Returns a list of devices claimed by the user authenticated.
358
+ *
359
+ * ```typescript
360
+ * const devices = await neurosity.getDevices();
361
+ * console.log(devices);
362
+ * ```
363
+ */
364
+ getDevices() {
365
+ return __awaiter(this, void 0, void 0, function* () {
366
+ return yield this.cloudClient.getDevices();
367
+ });
368
+ }
369
+ /**
370
+ * Select Device
371
+ *
372
+ * Rarely necessary, but useful when the user owns multiple devices.
373
+ *
374
+ * A common use case for manually selecting a device is when you wish to build a device dropdown a user can select from, instead of collecting the Device Id from the user ahead of time.
375
+ *
376
+ * The 3 steps to manually selecting a device are:
377
+ *
378
+ * - Set `autoSelectDevice` to false when instantiating the `Neurosity` class.
379
+ * - Authenticate with your Neurosity account to access your devices by calling the `neurosity.login(...)` function.
380
+ * - Call the `neurosity.selectDevice(...)` function with a device selector function.
381
+ *
382
+ * ```typescript
383
+ * const devices = await neurosity.selectDevice((devices) =>
384
+ * devices.find((device) => device.deviceNickname === "Crown-A1B")
385
+ * );
386
+ *
387
+ * console.log(devices);
388
+ * ```
389
+ *
390
+ * > If you own multiple devices, and don't pass `autoSelectDevice`, then the first device on the list will be automatically selected.
391
+ *
392
+ * For more info, check out the "Device Selection" guide.
393
+ */
394
+ selectDevice(deviceSelector) {
395
+ return __awaiter(this, void 0, void 0, function* () {
396
+ const [hasOAuthError, OAuthError] = (0, oauth_1.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims, "selectDevice");
397
+ if (hasOAuthError) {
398
+ return Promise.reject(OAuthError);
399
+ }
400
+ return yield this.cloudClient.selectDevice(deviceSelector);
401
+ });
402
+ }
403
+ /**
404
+ * Get selected device
405
+ *
406
+ * ```typescript
407
+ * const selectedDevice = await neurosity.getSelectedDevice();
408
+ * console.log(selectedDevice);
409
+ * ```
410
+ */
411
+ getSelectedDevice() {
412
+ return __awaiter(this, void 0, void 0, function* () {
413
+ const [hasOAuthError, OAuthError] = (0, oauth_1.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims, "getSelectedDevice");
414
+ if (hasOAuthError) {
415
+ return Promise.reject(OAuthError);
416
+ }
417
+ return yield this.cloudClient.getSelectedDevice();
418
+ });
419
+ }
420
+ /**
421
+ * ```typescript
422
+ * const info = await neurosity.getInfo();
423
+ * ```
424
+ */
425
+ getInfo() {
426
+ return __awaiter(this, void 0, void 0, function* () {
427
+ if (!(yield this.cloudClient.didSelectDevice())) {
428
+ return Promise.reject(errors.mustSelectDevice);
429
+ }
430
+ const [hasOAuthError, OAuthError] = (0, oauth_1.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims, "getInfo");
431
+ if (hasOAuthError) {
432
+ return Promise.reject(OAuthError);
433
+ }
434
+ return yield this._withStreamingModePromise({
435
+ wifi: () => this.cloudClient.getInfo(),
436
+ bluetooth: () => this.bluetoothClient.getInfo()
437
+ });
438
+ });
439
+ }
440
+ /**
441
+ * Observes selected device
442
+ *
443
+ * ```typescript
444
+ * neurosity.onDeviceChange().subscribe(device => {
445
+ * console.log(device);
446
+ * });
447
+ * ```
448
+ */
449
+ onDeviceChange() {
450
+ const [hasOAuthError, OAuthError] = (0, oauth_1.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims, "onDeviceChange");
451
+ if (hasOAuthError) {
452
+ return (0, rxjs_1.throwError)(() => OAuthError);
453
+ }
454
+ return this.cloudClient.onDeviceChange();
455
+ }
456
+ /**
457
+ * <StreamingModes wifi={true} bluetooth={true} />
458
+ *
459
+ * Ends database connection
460
+ *
461
+ * ```typescript
462
+ * await neurosity.disconnect();
463
+ * ```
464
+ */
465
+ disconnect() {
466
+ return __awaiter(this, void 0, void 0, function* () {
467
+ return yield this._withStreamingModePromise({
468
+ wifi: () => this.cloudClient.disconnect(),
469
+ bluetooth: () => this.bluetoothClient.disconnect()
470
+ });
471
+ });
472
+ }
473
+ /**
474
+ * <StreamingModes wifi={true} bluetooth={true} />
475
+ *
476
+ * @internal
477
+ * Not user facing
478
+ */
479
+ dispatchAction(action) {
480
+ return __awaiter(this, void 0, void 0, function* () {
481
+ if (!(yield this.cloudClient.didSelectDevice())) {
482
+ return Promise.reject(errors.mustSelectDevice);
483
+ }
484
+ const [hasOAuthError, OAuthError] = (0, oauth_2.validateOAuthScopeForAction)(this.cloudClient.userClaims, action);
485
+ if (hasOAuthError) {
486
+ return Promise.reject(OAuthError);
487
+ }
488
+ return yield this._withStreamingModePromise({
489
+ wifi: () => this.cloudClient.dispatchAction(action),
490
+ bluetooth: () => this.bluetoothClient.dispatchAction(action)
491
+ });
492
+ });
493
+ }
494
+ /**
495
+ * <StreamingModes wifi={true} bluetooth={true} />
496
+ *
497
+ * Injects an EEG marker to data stream
498
+ *
499
+ * ```typescript
500
+ * neurosity.addMarker("eyes-closed");
501
+ *
502
+ * // later...
503
+ *
504
+ * neurosity.addMarker("eyes-open");
505
+ * ```
506
+ *
507
+ * @param label Name the label to inject
508
+ */
509
+ addMarker(label) {
510
+ return __awaiter(this, void 0, void 0, function* () {
511
+ if (!(yield this.cloudClient.didSelectDevice())) {
512
+ throw errors.mustSelectDevice;
513
+ }
514
+ if (!label) {
515
+ throw new Error(`${errors.prefix}A label is required for addMarker`);
516
+ }
517
+ return yield this._withStreamingModePromise({
518
+ wifi: () => this.cloudClient.dispatchAction({
519
+ command: "marker",
520
+ action: "add",
521
+ message: {
522
+ label,
523
+ timestamp: this.cloudClient.timestamp
524
+ }
525
+ }),
526
+ bluetooth: () => this.bluetoothClient.addMarker(label)
527
+ });
528
+ });
529
+ }
530
+ /**
531
+ * <StreamingModes wifi={true} bluetooth={true} />
532
+ *
533
+ * Queue haptic motor commands
534
+ *
535
+ * To queue haptic P7 only,
536
+ * ```typescript
537
+ * await neurosity.haptics({
538
+ * P7: ["tripleClick100"]
539
+ * });
540
+ * ```
541
+ *
542
+ * To queue both motors at the same time
543
+ * ```typescript
544
+ * await neurosity.haptics({
545
+ * P7: [neurosity.getHapticEffects().strongClick100],
546
+ * P8: [neurosity.getHapticEffects().strongClick100]
547
+ * });
548
+ * ```
549
+ *
550
+ * You can queue different commands to the motors too
551
+ * ```typescript
552
+ * const effects = neurosity.getHapticEffects();
553
+ * await neurosity.haptics({
554
+ * P7: [effects.transitionRampUpLongSmooth1_0_to_100,
555
+ * effects.transitionRampDownLongSmooth1_100_to_0],
556
+ * P8: [effects.strongClick100]
557
+ * });
558
+ * ```
559
+ *
560
+ * @param effects Effects to queue. The key of the object passed should be the location of the motor
561
+ * to queue. Each key can be an array of up to 7 commands. There is no haptic support for model
562
+ * version 1, Notion DK1. The Haptic motor's location is positioned in reference to the 10-10 EEG
563
+ * system used to label the channels of the Crown's EEG sensors. Notion 2 and Crown have haptics
564
+ * at P7 and P8. A list of haptic commands can be found on ./utils/hapticCodes.ts - there
565
+ * are about 127 of them!
566
+ */
567
+ haptics(effects) {
568
+ var _a;
569
+ return __awaiter(this, void 0, void 0, function* () {
570
+ const metric = "haptics";
571
+ if (!(yield this.cloudClient.didSelectDevice())) {
572
+ return Promise.reject(errors.mustSelectDevice);
573
+ }
574
+ const modelVersion = (_a = (yield this.getSelectedDevice())) === null || _a === void 0 ? void 0 : _a.modelVersion;
575
+ const supportsHaptics = platform.supportsHaptics(modelVersion);
576
+ if (!supportsHaptics) {
577
+ return Promise.reject(errors.metricNotSupportedByModel(metric, modelVersion));
578
+ }
579
+ const newPlatformHapticRequest = platform.getPlatformHapticMotors(modelVersion);
580
+ for (const key in effects) {
581
+ if (!Object.keys(newPlatformHapticRequest).includes(key)) {
582
+ return Promise.reject(errors.locationNotFound(key, modelVersion));
583
+ }
584
+ const singleMotorEffects = effects[key];
585
+ const maxItems = 7;
586
+ if (singleMotorEffects.length > maxItems) {
587
+ return Promise.reject(errors.exceededMaxItems(maxItems));
588
+ }
589
+ newPlatformHapticRequest[key] = singleMotorEffects;
590
+ }
591
+ const payload = {
592
+ command: metric,
593
+ action: "queue",
594
+ responseRequired: true,
595
+ responseTimeout: 1000,
596
+ message: { effects: newPlatformHapticRequest }
597
+ };
598
+ return yield this._withStreamingModePromise({
599
+ wifi: () => this.cloudClient.dispatchAction(payload),
600
+ bluetooth: () => this.bluetoothClient.dispatchAction(payload)
601
+ });
602
+ });
603
+ }
604
+ /**
605
+ * ```typescript
606
+ * const effects = neurosity.getHapticEffects();
607
+ * ```
608
+ */
609
+ getHapticEffects() {
610
+ return hapticEffects;
611
+ }
612
+ /**
613
+ * <StreamingModes wifi={true} bluetooth={true} />
614
+ *
615
+ * Observes accelerometer data
616
+ * Supported by the Crown and Notion 2 devices.
617
+ *
618
+ * ```typescript
619
+ * neurosity.accelerometer().subscribe(accelerometer => {
620
+ * console.log(accelerometer);
621
+ * });
622
+ *
623
+ * // { acceleration: ..., inclination: ..., orientation: ..., pitch: ..., roll: ..., x: ..., y: ..., z: ... }
624
+ * ```
625
+ *
626
+ * @returns Observable of accelerometer metric events
627
+ */
628
+ accelerometer() {
629
+ const metric = "accelerometer";
630
+ const [hasOAuthError, OAuthError] = (0, oauth_1.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims, metric);
631
+ if (hasOAuthError) {
632
+ return (0, rxjs_1.throwError)(() => OAuthError);
633
+ }
634
+ return this.onDeviceChange().pipe((0, operators_1.switchMap)((selectedDevice) => {
635
+ const modelVersion = (selectedDevice === null || selectedDevice === void 0 ? void 0 : selectedDevice.modelVersion) || platform.MODEL_VERSION_1;
636
+ const supportsAccel = platform.supportsAccel(modelVersion);
637
+ if (!supportsAccel) {
638
+ return (0, rxjs_1.throwError)(() => errors.metricNotSupportedByModel(metric, modelVersion));
639
+ }
640
+ return this._withStreamingModeObservable({
641
+ wifi: () => (0, metrics_1.getCloudMetric)(this._getCloudMetricDependencies(), {
642
+ metric,
643
+ labels: (0, subscription_1.getLabels)(metric),
644
+ atomic: true
645
+ }),
646
+ bluetooth: () => this.bluetoothClient.accelerometer()
647
+ });
648
+ }));
649
+ }
650
+ /**
651
+ * <StreamingModes wifi={true} bluetooth={true} />
652
+ *
653
+ * The `raw` brainwaves parameter emits epochs of 16 samples for Crown and 25 for Notion 1 and 2.
654
+ *
655
+ * Example
656
+ * ```typescript
657
+ * neurosity.brainwaves("raw").subscribe(brainwaves => {
658
+ * console.log(brainwaves);
659
+ * });
660
+ * ```
661
+ *
662
+ * Raw Unfiltered - The `rawUnfiltered` brainwaves parameter emits epochs of 16 samples for Crown and 25 for Notion 1 and 2.
663
+
664
+ * Example
665
+ * ```typescript
666
+ * neurosity.brainwaves("rawUnfiltered").subscribe(brainwaves => {
667
+ * console.log(brainwaves);
668
+ * });
669
+ * ```
670
+ *
671
+ * Power By Band - The `powerByBand` brainwaves parameter emits epochs 4 times a second. Every frequency label (e.g. beta) contains an average power value per channel.
672
+ *
673
+ * Example
674
+ * ```typescript
675
+ * neurosity.brainwaves("powerByBand").subscribe(brainwaves => {
676
+ * console.log(brainwaves);
677
+ * });
678
+ * ```
679
+ *
680
+ * Power Spectral Density (PSD) - The `psd` brainwaves parameter emits epochs 4 times a second. Every frequency label (e.g. alpha) contains the computed FFT (Fast Fourier transform) value per channel (see the `psd` property), as well as the frequency ranges (see the `freqs` property).
681
+ *
682
+ * Example
683
+ * ```typescript
684
+ * neurosity.brainwaves("psd").subscribe(brainwaves => {
685
+ * console.log(brainwaves);
686
+ * });
687
+ * ```
688
+ *
689
+ * @param label Name of metric properties to filter by
690
+ * @returns Observable of brainwaves metric events
691
+ */
692
+ brainwaves(label) {
693
+ const [hasOAuthError, OAuthError] = (0, oauth_1.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims, "brainwaves");
694
+ if (hasOAuthError) {
695
+ return (0, rxjs_1.throwError)(() => OAuthError);
696
+ }
697
+ return this._withStreamingModeObservable({
698
+ wifi: () => (0, metrics_1.getCloudMetric)(this._getCloudMetricDependencies(), {
699
+ metric: "brainwaves",
700
+ labels: label ? [label] : [],
701
+ atomic: false
702
+ }),
703
+ // @TODO: doesn't support multiple labels, we should make the higher
704
+ // order function only support one label
705
+ bluetooth: () => this.bluetoothClient.brainwaves(label)
706
+ });
707
+ }
708
+ /**
709
+ * <StreamingModes wifi={true} bluetooth={true} />
710
+ *
711
+ * Example
712
+ * ```typescript
713
+ * neurosity.calm().subscribe(calm => {
714
+ * console.log(calm.probability);
715
+ * });
716
+ *
717
+ * // 0.45
718
+ * // 0.47
719
+ * // 0.53
720
+ * // 0.51
721
+ * // ...
722
+ * ```
723
+ *
724
+ * @returns Observable of calm events - awareness/calm alias
725
+ */
726
+ calm() {
727
+ const [hasOAuthError, OAuthError] = (0, oauth_1.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims, "calm");
728
+ if (hasOAuthError) {
729
+ return (0, rxjs_1.throwError)(() => OAuthError);
730
+ }
731
+ return this._withStreamingModeObservable({
732
+ wifi: () => (0, metrics_1.getCloudMetric)(this._getCloudMetricDependencies(), {
733
+ metric: "awareness",
734
+ labels: ["calm"],
735
+ atomic: false
736
+ }),
737
+ bluetooth: () => this.bluetoothClient.calm()
738
+ });
739
+ }
740
+ /**
741
+ * <StreamingModes wifi={true} bluetooth={true} />
742
+ *
743
+ * Observes signal quality data where each property is the name
744
+ * of the channel and the value includes the standard deviation and
745
+ * a status set by the device
746
+ *
747
+ * ```typescript
748
+ * neurosity.signalQuality().subscribe(signalQuality => {
749
+ * console.log(signalQuality);
750
+ * });
751
+ *
752
+ * // { FC6: { standardDeviation: 3.5, status: "good" }, C3: {...}, ... }
753
+ * ```
754
+ *
755
+ * @returns Observable of signalQuality metric events
756
+ */
757
+ signalQuality() {
758
+ const metric = "signalQuality";
759
+ const [hasOAuthError, OAuthError] = (0, oauth_1.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims, metric);
760
+ if (hasOAuthError) {
761
+ return (0, rxjs_1.throwError)(() => OAuthError);
762
+ }
763
+ return this._withStreamingModeObservable({
764
+ wifi: () => (0, metrics_1.getCloudMetric)(this._getCloudMetricDependencies(), {
765
+ metric,
766
+ labels: (0, subscription_1.getLabels)(metric),
767
+ atomic: true
768
+ }),
769
+ bluetooth: () => this.bluetoothClient.signalQuality()
770
+ });
771
+ }
772
+ /**
773
+ * <StreamingModes wifi={true} />
774
+ *
775
+ * Observes last state of `settings` and all subsequent `settings` changes
776
+ *
777
+ * ```typescript
778
+ * neurosity.settings().subscribe(settings => {
779
+ * console.log(settings.lsl);
780
+ * });
781
+ *
782
+ * // true
783
+ * // ...
784
+ * ```
785
+ *
786
+ * @returns Observable of `settings` metric events
787
+ */
788
+ settings() {
789
+ const [hasOAuthError, OAuthError] = (0, oauth_1.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims, "settings");
790
+ if (hasOAuthError) {
791
+ return (0, rxjs_1.throwError)(() => OAuthError);
792
+ }
793
+ return this.cloudClient.observeNamespace("settings");
794
+ }
795
+ /**
796
+ * <StreamingModes wifi={true} bluetooth={true} />
797
+ *
798
+ * Example
799
+ * ```typescript
800
+ * neurosity.focus().subscribe(focus => {
801
+ * console.log(focus.probability);
802
+ * });
803
+ *
804
+ * // 0.56
805
+ * // 0.46
806
+ * // 0.31
807
+ * // 0.39
808
+ * // ...
809
+ * ```
810
+ *
811
+ * @returns Observable of focus events - awareness/focus alias
812
+ */
813
+ focus() {
814
+ const [hasOAuthError, OAuthError] = (0, oauth_1.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims, "focus");
815
+ if (hasOAuthError) {
816
+ return (0, rxjs_1.throwError)(() => OAuthError);
817
+ }
818
+ return this._withStreamingModeObservable({
819
+ wifi: () => (0, metrics_1.getCloudMetric)(this._getCloudMetricDependencies(), {
820
+ metric: "awareness",
821
+ labels: ["focus"],
822
+ atomic: false
823
+ }),
824
+ bluetooth: () => this.bluetoothClient.focus()
825
+ });
826
+ }
827
+ /**
828
+ * <StreamingModes wifi={true} />
829
+ *
830
+ * @param label Name of metric properties to filter by
831
+ * @returns Observable of kinesis metric events
832
+ */
833
+ kinesis(label) {
834
+ const metric = "kinesis";
835
+ const [hasOAuthError, OAuthError] = (0, oauth_1.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims, metric);
836
+ if (hasOAuthError) {
837
+ return (0, rxjs_1.throwError)(() => OAuthError);
838
+ }
839
+ return (0, metrics_1.getCloudMetric)(this._getCloudMetricDependencies(), {
840
+ metric,
841
+ labels: label ? [label] : [],
842
+ atomic: false
843
+ });
844
+ }
845
+ /**
846
+ * <StreamingModes wifi={true} />
847
+ *
848
+ * @param label Name of metric properties to filter by
849
+ * @returns Observable of predictions metric events
850
+ */
851
+ predictions(label) {
852
+ const metric = "predictions";
853
+ const [hasOAuthError, OAuthError] = (0, oauth_1.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims, metric);
854
+ if (hasOAuthError) {
855
+ return (0, rxjs_1.throwError)(() => OAuthError);
856
+ }
857
+ return (0, metrics_1.getCloudMetric)(this._getCloudMetricDependencies(), {
858
+ metric,
859
+ labels: label ? [label] : [],
860
+ atomic: false
861
+ });
862
+ }
863
+ /**
864
+ * <StreamingModes wifi={true} bluetooth={true} />
865
+ *
866
+ * Observes last state of `status` and all subsequent `status` changes
867
+ *
868
+ * ```typescript
869
+ * neurosity.status().subscribe(status => {
870
+ * console.log(status.state);
871
+ * });
872
+ *
873
+ * // "online"
874
+ * // ...
875
+ * ```
876
+ *
877
+ * @returns Observable of `status` metric events
878
+ */
879
+ status() {
880
+ const [hasOAuthError, OAuthError] = (0, oauth_1.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims, "status");
881
+ if (hasOAuthError) {
882
+ return (0, rxjs_1.throwError)(() => OAuthError);
883
+ }
884
+ return this._withStreamingModeObservable({
885
+ wifi: () => this.cloudClient.status(),
886
+ bluetooth: () => this.bluetoothClient.status()
887
+ });
888
+ }
889
+ /**
890
+ * @internal
891
+ * Not user facing yet
892
+ *
893
+ * <StreamingModes wifi={true} />
894
+ *
895
+ * Changes device settings programmatically. These settings can be
896
+ * also changed from the developer console under device settings.
897
+ *
898
+ * Available settings [[ChangeSettings]]
899
+ *
900
+ * Example
901
+ * ```typescript
902
+ * neurosity.changeSettings({
903
+ * lsl: true
904
+ * });
905
+ * ```
906
+ */
907
+ changeSettings(settings) {
908
+ return __awaiter(this, void 0, void 0, function* () {
909
+ if (!(yield this.cloudClient.didSelectDevice())) {
910
+ return Promise.reject(errors.mustSelectDevice);
911
+ }
912
+ const [hasOAuthError, OAuthError] = (0, oauth_1.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims, "changeSettings");
913
+ if (hasOAuthError) {
914
+ return Promise.reject(OAuthError);
915
+ }
916
+ return yield this.cloudClient.changeSettings(settings);
917
+ });
918
+ }
919
+ /**
920
+ * <StreamingModes wifi={true} />
921
+ *
922
+ * ```typescript
923
+ * neurosity.training.record({
924
+ * metric: "kinesis",
925
+ * label: "push"
926
+ * });
927
+ *
928
+ * neurosity.training.stop({
929
+ * metric: "kinesis",
930
+ * label: "push"
931
+ * });
932
+ * ```
933
+ *
934
+ * @returns Training methods
935
+ */
936
+ get training() {
937
+ return {
938
+ /**
939
+ * <StreamingModes wifi={true} />
940
+ *
941
+ * Records a training for a metric/label pair
942
+ * @category Training
943
+ */
944
+ record: (training) => __awaiter(this, void 0, void 0, function* () {
945
+ if (!(yield this.cloudClient.didSelectDevice())) {
946
+ throw errors.mustSelectDevice;
947
+ }
948
+ const userId = this.cloudClient.user && "uid" in this.cloudClient.user
949
+ ? this.cloudClient.user.uid
950
+ : null;
951
+ const message = Object.assign(Object.assign({ fit: false, baseline: false, timestamp: this.cloudClient.timestamp }, training), { userId });
952
+ yield this.cloudClient.actions.dispatch({
953
+ command: "training",
954
+ action: "record",
955
+ message
956
+ });
957
+ }),
958
+ /**
959
+ * <StreamingModes wifi={true} />
960
+ *
961
+ * Stops the training for a metric/label pair
962
+ * @category Training
963
+ */
964
+ stop: (training) => __awaiter(this, void 0, void 0, function* () {
965
+ if (!(yield this.cloudClient.didSelectDevice())) {
966
+ throw errors.mustSelectDevice;
967
+ }
968
+ yield this.cloudClient.actions.dispatch({
969
+ command: "training",
970
+ action: "stop",
971
+ message: Object.assign({}, training)
972
+ });
973
+ }),
974
+ /**
975
+ * <StreamingModes wifi={true} />
976
+ *
977
+ * Stops all trainings
978
+ * @category Training
979
+ */
980
+ stopAll: () => __awaiter(this, void 0, void 0, function* () {
981
+ if (!(yield this.cloudClient.didSelectDevice())) {
982
+ throw errors.mustSelectDevice;
983
+ }
984
+ yield this.cloudClient.actions.dispatch({
985
+ command: "training",
986
+ action: "stopAll",
987
+ message: {}
988
+ });
989
+ })
990
+ };
991
+ }
992
+ /**
993
+ * @internal
994
+ * Proof of Concept for disconnecting db
995
+ */
996
+ goOffline() {
997
+ this.cloudClient.goOffline();
998
+ }
999
+ /**
1000
+ * @internal
1001
+ * Proof of Concept for resuming db connection
1002
+ */
1003
+ goOnline() {
1004
+ this.cloudClient.goOnline();
1005
+ }
1006
+ /**
1007
+ * @internal
1008
+ * Not user facing yet
1009
+ *
1010
+ * Creates user account and automatically signs in with same credentials
1011
+ *
1012
+ * @param emailAndPasswordObject
1013
+ * @returns user credential
1014
+ */
1015
+ createAccount(credentials) {
1016
+ return this.cloudClient.createAccount(credentials);
1017
+ }
1018
+ /**
1019
+ * @internal
1020
+ * Not user facing yet
1021
+ *
1022
+ * Removes all devices from an account and then deletes the account
1023
+ */
1024
+ deleteAccount() {
1025
+ return this.cloudClient.deleteAccount();
1026
+ }
1027
+ /**
1028
+ * @internal
1029
+ * Not user facing
1030
+ *
1031
+ * Creates token (JWT) designed to authenticate and authorize Bluetooth clients/centrals.
1032
+ *
1033
+ * @returns token
1034
+ */
1035
+ createBluetoothToken() {
1036
+ return this.cloudClient.createBluetoothToken();
1037
+ }
1038
+ /**
1039
+ * @internal
1040
+ * Not user facing yet
1041
+ *
1042
+ * Creates custom token (JWT) to use to login with `{ customToken }`.
1043
+ *
1044
+ * @returns custom token
1045
+ */
1046
+ createCustomToken() {
1047
+ return this.cloudClient.createCustomToken();
1048
+ }
1049
+ /**
1050
+ * @internal
1051
+ * Not user facing yet
1052
+ *
1053
+ * Gets the offset between the device's clock and the client's clock
1054
+ * Requires option.timesync to be true
1055
+ *
1056
+ * @returns timesyncOffset
1057
+ */
1058
+ getTimesyncOffset() {
1059
+ if (!this.options.timesync) {
1060
+ console.warn(`getTimesyncOffset() requires options.timesync to be true.`);
1061
+ }
1062
+ return this.options.timesync ? this.cloudClient.getTimesyncOffset() : 0;
1063
+ }
1064
+ /**
1065
+ * Create OAuth URL
1066
+ * 💡 OAuth requires developers to register their apps with Neurosity
1067
+ * [Read full OAuth guide](/docs/oauth)
1068
+ *
1069
+ * Creates client-specific OAuth URL. This is the first step of the OAuth workflow. Use this function to create a URL you can use to redirect users to the Neurosity sign-in page.
1070
+ * 💡 This function is designed to only run on the server side for security reasons, as it requires your client secret.
1071
+ *
1072
+ * ```typescript
1073
+ * const { Neurosity } = require("@neurosity/sdk");
1074
+ *
1075
+ * const neurosity = new Neurosity({
1076
+ * autoSelectDevice: false
1077
+ * });
1078
+ *
1079
+ * exports.handler = async function (event) {
1080
+ * return neurosity
1081
+ * .createOAuthURL({
1082
+ * clientId: process.env.NEUROSITY_OAUTH_CLIENT_ID,
1083
+ * clientSecret: process.env.NEUROSITY_OAUTH_CLIENT_SECRET,
1084
+ * redirectUri: process.env.NEUROSITY_OAUTH_CLIENT_REDIRECT_URI,
1085
+ * responseType: "token",
1086
+ * state: Math.random().toString().split(".")[1],
1087
+ * scope: [
1088
+ * "read:devices-info",
1089
+ * "read:devices-status",
1090
+ * "read:signal-quality",
1091
+ * "read:brainwaves"
1092
+ * ]
1093
+ * })
1094
+ * .then((url) => ({
1095
+ * statusCode: 200,
1096
+ * body: JSON.stringify({ url })
1097
+ * }))
1098
+ * .catch((error) => ({
1099
+ * statusCode: 400,
1100
+ * body: JSON.stringify(error.response.data)
1101
+ * }));
1102
+ * };
1103
+ * ```
1104
+ * @returns custom token
1105
+ */
1106
+ createOAuthURL(config) {
1107
+ if (!is_node_1.isNode) {
1108
+ return Promise.reject(new Error(`${errors.prefix}the createOAuthURL method must be used on the server side (node.js) for security reasons.`));
1109
+ }
1110
+ return (0, createOAuthURL_1.createOAuthURL)(config, this.options);
1111
+ }
1112
+ /**
1113
+ * Get OAuth Token
1114
+ * 💡 OAuth requires developers to register their apps with Neurosity
1115
+ * [Read full OAuth guide](/docs/oauth)
1116
+ *
1117
+ * Gets client-specific OAuth token for a given userId.
1118
+ *
1119
+ * 💡 This function is designed to only run on the server side for security reasons, as it requires your client secret.
1120
+ * Here's an example of a cloud function that receives a `userId` via query params and loads the client id and client secret securely via environment variables.
1121
+ *
1122
+ *
1123
+ * ```typescript
1124
+ * const { Neurosity } = require("@neurosity/sdk");
1125
+ *
1126
+ * const neurosity = new Neurosity({
1127
+ * autoSelectDevice: false
1128
+ * });
1129
+ *
1130
+ * exports.handler = async function (event) {
1131
+ * const userId = event.queryStringParameters?.userId;
1132
+ *
1133
+ * return neurosity
1134
+ * .getOAuthToken({
1135
+ * clientId: process.env.NEUROSITY_OAUTH_CLIENT_ID,
1136
+ * clientSecret: process.env.NEUROSITY_OAUTH_CLIENT_SECRET,
1137
+ * userId
1138
+ * })
1139
+ * .then((token) => ({
1140
+ * statusCode: 200,
1141
+ * body: JSON.stringify(token)
1142
+ * }))
1143
+ * .catch((error) => ({
1144
+ * statusCode: 200,
1145
+ * body: JSON.stringify(error.response.data)
1146
+ * }));
1147
+ * };
1148
+ * ```
1149
+ * @returns custom token
1150
+ */
1151
+ getOAuthToken(query) {
1152
+ if (!is_node_1.isNode) {
1153
+ return Promise.reject(new Error(`${errors.prefix}the getOAuthToken method must be used on the server side (node.js) for security reasons.`));
1154
+ }
1155
+ return (0, getOAuthToken_1.getOAuthToken)(query, this.options);
1156
+ }
1157
+ /**
1158
+ * Remove OAuth Access
1159
+ * 💡 OAuth requires developers to register their apps with Neurosity
1160
+ * [Read full OAuth guide](/docs/oauth)
1161
+ *
1162
+ * Removes client-specific OAuth token for a given userId. Requires SDK to be signed in with OAuth custom token.
1163
+ *
1164
+ * ```typescript
1165
+ * await neurosity.removeOAuthAccess().catch((error) => {
1166
+ * // handle error here...
1167
+ * });
1168
+ * ```
1169
+ * @returns custom token
1170
+ */
1171
+ removeOAuthAccess() {
1172
+ return this.cloudClient.removeOAuthAccess();
1173
+ }
1174
+ /**
1175
+ * <StreamingModes wifi={true} />
1176
+ *
1177
+ * Observes and returns a list of all Kinesis `experiments` and all subsequent experiment changes.
1178
+ * Here's an example of how to get a list of all Kinesis labels that have been trained:
1179
+ *
1180
+ * ```typescript
1181
+ *
1182
+ * const getUniqueLabels = (experiments) => {
1183
+ * const labels = experiments.flatMap((experiment) => experiment.labels);
1184
+ * // only return unique labels
1185
+ * return [...new Set(labels)];
1186
+ * }
1187
+ *
1188
+ * neurosity.onUserExperiments().subscribe((experiments) => {
1189
+ * console.log(experiments);
1190
+ * console.log("labels", getUniqueLabels(experiments));
1191
+ * });
1192
+ *
1193
+ * // [{ id: '...', deviceId: '...', labels: [ 'drop' ], name: 'Lightgray cheetah', timestamp: 1577908381552, totalTrials: 16, userId: '...' }]
1194
+ * // ["drop", "lift", "push"]
1195
+ * ```
1196
+ *
1197
+ * @returns Observable of `experiments` events
1198
+ */
1199
+ onUserExperiments() {
1200
+ return this.cloudClient.onUserExperiments();
1201
+ }
1202
+ /**
1203
+ * <StreamingModes wifi={true} />
1204
+ *
1205
+ * Deletes a specific experiment provided an experiment ID
1206
+ *
1207
+ * ```typescript
1208
+ * await neurosity.deleteUserExperiment(experiment.id);
1209
+ * ```
1210
+ *
1211
+ * @param experimentId The ID of the Experiment
1212
+ * @returns void
1213
+ */
1214
+ deleteUserExperiment(experimentId) {
1215
+ return this.cloudClient.deleteUserExperiment(experimentId);
1216
+ }
1217
+ }
1218
+ exports.Neurosity = Neurosity;
1219
+ /**
1220
+ *
1221
+ * @hidden
1222
+ */
1223
+ Neurosity.credentialWithLink = index_2.credentialWithLink;
1224
+ /**
1225
+ *
1226
+ * @hidden
1227
+ */
1228
+ Neurosity.createUser = index_1.createUser;
1229
+ /**
1230
+ *
1231
+ * @hidden
1232
+ */
1233
+ Neurosity.SERVER_TIMESTAMP = index_2.SERVER_TIMESTAMP;
1234
+ /**
1235
+ * @hidden
1236
+ * Deprecated class kept for backwards compatibility purposes.
1237
+ */
1238
+ class Notion extends Neurosity {
1239
+ constructor(options = {}) {
1240
+ super(options);
1241
+ console.log(`The Notion class is deprecated and will be removed in the next version of the SDK. Please use the Neurosity class instead. e.g. new Notion() => new Neurosity()`);
1242
+ }
1243
+ }
1244
+ exports.Notion = Notion;