@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.
- package/dist/browser/neurosity.iife.js +48717 -0
- package/dist/browser/neurosity.js +666 -0
- package/dist/browser/neurosity.js.map +1 -0
- package/dist/{Neurosity.d.ts → cjs/Neurosity.d.ts} +2 -116
- package/dist/cjs/Neurosity.js +1244 -0
- package/dist/{api → cjs/api}/bluetooth/BluetoothClient.d.ts +6 -6
- package/dist/cjs/api/bluetooth/BluetoothClient.js +310 -0
- package/dist/cjs/api/bluetooth/BluetoothTransport.d.ts +33 -0
- package/dist/cjs/api/bluetooth/BluetoothTransport.js +2 -0
- package/dist/{api → cjs/api}/bluetooth/constants.d.ts +0 -0
- package/dist/cjs/api/bluetooth/constants.js +9 -0
- package/dist/{api → cjs/api}/bluetooth/index.d.ts +0 -0
- package/dist/cjs/api/bluetooth/index.js +21 -0
- package/dist/{api → cjs/api}/bluetooth/react-native/ReactNativeTransport.d.ts +4 -4
- package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.js +411 -0
- package/dist/cjs/api/bluetooth/react-native/types/BleManagerTypes.d.ts +63 -0
- package/dist/cjs/api/bluetooth/react-native/types/BleManagerTypes.js +11 -0
- package/dist/cjs/api/bluetooth/react-native/types/ReactNativeTypes.d.ts +180 -0
- package/dist/cjs/api/bluetooth/react-native/types/ReactNativeTypes.js +10 -0
- package/dist/{api → cjs/api}/bluetooth/types/index.d.ts +2 -2
- package/dist/cjs/api/bluetooth/types/index.js +22 -0
- package/dist/{api → cjs/api}/bluetooth/utils/create6DigitPin.d.ts +0 -0
- package/dist/cjs/api/bluetooth/utils/create6DigitPin.js +8 -0
- package/dist/{api → cjs/api}/bluetooth/utils/csvBufferToEpoch.d.ts +0 -0
- package/dist/cjs/api/bluetooth/utils/csvBufferToEpoch.js +36 -0
- package/dist/{api → cjs/api}/bluetooth/utils/encoding.d.ts +0 -0
- package/dist/cjs/api/bluetooth/utils/encoding.js +22 -0
- package/dist/{api → cjs/api}/bluetooth/utils/osHasBluetoothSupport.d.ts +0 -0
- package/dist/cjs/api/bluetooth/utils/osHasBluetoothSupport.js +23 -0
- package/dist/{api → cjs/api}/bluetooth/utils/stitch.d.ts +1 -1
- package/dist/cjs/api/bluetooth/utils/stitch.js +22 -0
- package/dist/{api → cjs/api}/bluetooth/web/WebBluetoothTransport.d.ts +1 -1
- package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.js +430 -0
- package/dist/{api → cjs/api}/bluetooth/web/isMaybeWebWorkerContext.d.ts +0 -0
- package/dist/cjs/api/bluetooth/web/isMaybeWebWorkerContext.js +8 -0
- package/dist/{api → cjs/api}/bluetooth/web/isWebBluetoothSupported.d.ts +0 -0
- package/dist/cjs/api/bluetooth/web/isWebBluetoothSupported.js +11 -0
- package/dist/{api → cjs/api}/firebase/FirebaseApp.d.ts +0 -0
- package/dist/cjs/api/firebase/FirebaseApp.js +70 -0
- package/dist/{api → cjs/api}/firebase/FirebaseDevice.d.ts +1 -1
- package/dist/cjs/api/firebase/FirebaseDevice.js +146 -0
- package/dist/{api → cjs/api}/firebase/FirebaseUser.d.ts +0 -0
- package/dist/cjs/api/firebase/FirebaseUser.js +434 -0
- package/dist/{api → cjs/api}/firebase/config.d.ts +0 -0
- package/dist/cjs/api/firebase/config.js +11 -0
- package/dist/{api → cjs/api}/firebase/deviceStore.d.ts +0 -0
- package/dist/cjs/api/firebase/deviceStore.js +191 -0
- package/dist/{api → cjs/api}/firebase/index.d.ts +0 -0
- package/dist/cjs/api/firebase/index.js +19 -0
- package/dist/{api → cjs/api}/https/config.d.ts +0 -0
- package/dist/cjs/api/https/config.js +4 -0
- package/dist/{api → cjs/api}/https/createOAuthURL.d.ts +0 -0
- package/dist/cjs/api/https/createOAuthURL.js +18 -0
- package/dist/{api → cjs/api}/https/getOAuthToken.d.ts +0 -0
- package/dist/cjs/api/https/getOAuthToken.js +34 -0
- package/dist/{api → cjs/api}/https/utils.d.ts +0 -0
- package/dist/cjs/api/https/utils.js +13 -0
- package/dist/{api → cjs/api}/index.d.ts +0 -8
- package/dist/cjs/api/index.js +307 -0
- package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- package/dist/cjs/index.js +18 -0
- package/dist/{subscriptions → cjs/subscriptions}/SubscriptionManager.d.ts +0 -0
- package/dist/cjs/subscriptions/SubscriptionManager.js +27 -0
- package/dist/{timesync → cjs/timesync}/Timesync.d.ts +1 -1
- package/dist/cjs/timesync/Timesync.js +78 -0
- package/dist/{timesync → cjs/timesync}/index.d.ts +0 -0
- package/dist/cjs/timesync/index.js +17 -0
- package/dist/cjs/types/accelerometer.d.ts +10 -0
- package/dist/cjs/types/accelerometer.js +2 -0
- package/dist/cjs/types/actions.d.ts +16 -0
- package/dist/cjs/types/actions.js +2 -0
- package/dist/cjs/types/awareness.d.ts +1 -0
- package/dist/cjs/types/awareness.js +2 -0
- package/dist/cjs/types/brainwaves.d.ts +26 -0
- package/dist/cjs/types/brainwaves.js +2 -0
- package/dist/cjs/types/calm.d.ts +6 -0
- package/dist/cjs/types/calm.js +2 -0
- package/dist/cjs/types/client.d.ts +22 -0
- package/dist/cjs/types/client.js +2 -0
- package/dist/cjs/types/credentials.d.ts +12 -0
- package/dist/cjs/types/credentials.js +2 -0
- package/dist/cjs/types/deviceInfo.d.ts +18 -0
- package/dist/cjs/types/deviceInfo.js +2 -0
- package/dist/cjs/types/epoch.d.ts +12 -0
- package/dist/cjs/types/epoch.js +2 -0
- package/dist/cjs/types/experiment.d.ts +9 -0
- package/dist/cjs/types/experiment.js +2 -0
- package/dist/cjs/types/focus.d.ts +6 -0
- package/dist/cjs/types/focus.js +2 -0
- package/dist/cjs/types/hapticEffects.d.ts +125 -0
- package/dist/cjs/types/hapticEffects.js +2 -0
- package/dist/cjs/types/kinesis.d.ts +6 -0
- package/dist/cjs/types/kinesis.js +2 -0
- package/dist/cjs/types/marker.d.ts +7 -0
- package/dist/cjs/types/marker.js +2 -0
- package/dist/cjs/types/metrics.d.ts +21 -0
- package/dist/cjs/types/metrics.js +2 -0
- package/dist/cjs/types/oauth.d.ts +20 -0
- package/dist/cjs/types/oauth.js +2 -0
- package/dist/cjs/types/options.d.ts +51 -0
- package/dist/cjs/types/options.js +2 -0
- package/dist/cjs/types/sample.d.ts +15 -0
- package/dist/cjs/types/sample.js +2 -0
- package/dist/cjs/types/settings.d.ts +13 -0
- package/dist/cjs/types/settings.js +2 -0
- package/dist/cjs/types/signalQuality.d.ts +13 -0
- package/dist/cjs/types/signalQuality.js +2 -0
- package/dist/cjs/types/skill.d.ts +68 -0
- package/dist/cjs/types/skill.js +2 -0
- package/dist/{types → cjs/types}/status.d.ts +0 -0
- package/dist/cjs/types/status.js +22 -0
- package/dist/{types → cjs/types}/streaming.d.ts +0 -0
- package/dist/cjs/types/streaming.js +20 -0
- package/dist/cjs/types/subscriptions.d.ts +23 -0
- package/dist/cjs/types/subscriptions.js +2 -0
- package/dist/cjs/types/training.d.ts +19 -0
- package/dist/cjs/types/training.js +2 -0
- package/dist/cjs/types/user.d.ts +12 -0
- package/dist/cjs/types/user.js +2 -0
- package/dist/{utils → cjs/utils}/errors.d.ts +0 -0
- package/dist/cjs/utils/errors.js +17 -0
- package/dist/{utils → cjs/utils}/filterInternalKeys.d.ts +0 -0
- package/dist/cjs/utils/filterInternalKeys.js +21 -0
- package/dist/{utils → cjs/utils}/hapticEffects.d.ts +0 -0
- package/dist/cjs/utils/hapticEffects.js +130 -0
- package/dist/{utils → cjs/utils}/heartbeat.d.ts +0 -0
- package/dist/cjs/utils/heartbeat.js +41 -0
- package/dist/{utils → cjs/utils}/is-node.d.ts +0 -0
- package/dist/cjs/utils/is-node.js +9 -0
- package/dist/cjs/utils/metrics.d.ts +1 -0
- package/dist/cjs/utils/metrics.js +56 -0
- package/dist/{utils → cjs/utils}/oauth.d.ts +1 -1
- package/dist/cjs/utils/oauth.js +92 -0
- package/dist/cjs/utils/pick.d.ts +1 -0
- package/dist/cjs/utils/pick.js +5 -0
- package/dist/{utils → cjs/utils}/pipes.d.ts +0 -0
- package/dist/cjs/utils/pipes.js +71 -0
- package/dist/{utils → cjs/utils}/platform.d.ts +0 -0
- package/dist/cjs/utils/platform.js +47 -0
- package/dist/{utils → cjs/utils}/subscription.d.ts +0 -0
- package/dist/cjs/utils/subscription.js +55 -0
- package/dist/cjs/utils/transferDevice.d.ts +9 -0
- package/dist/cjs/utils/transferDevice.js +2 -0
- package/dist/{utils → cjs/utils}/whileOnline.d.ts +1 -1
- package/dist/cjs/utils/whileOnline.js +15 -0
- package/dist/electron/index.js +86 -0
- package/dist/electron/index.js.map +1 -0
- package/dist/esm/Neurosity.d.ts +619 -0
- package/dist/esm/Neurosity.js +1213 -0
- package/dist/esm/api/bluetooth/BluetoothClient.d.ts +72 -0
- package/dist/esm/api/bluetooth/BluetoothClient.js +306 -0
- package/dist/esm/api/bluetooth/BluetoothTransport.d.ts +33 -0
- package/dist/esm/api/bluetooth/BluetoothTransport.js +1 -0
- package/dist/esm/api/bluetooth/constants.d.ts +4 -0
- package/dist/esm/api/bluetooth/constants.js +6 -0
- package/dist/esm/api/bluetooth/index.d.ts +5 -0
- package/dist/esm/api/bluetooth/index.js +5 -0
- package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.d.ts +70 -0
- package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.js +407 -0
- package/dist/esm/api/bluetooth/react-native/types/BleManagerTypes.d.ts +63 -0
- package/dist/esm/api/bluetooth/react-native/types/BleManagerTypes.js +8 -0
- package/dist/esm/api/bluetooth/react-native/types/ReactNativeTypes.d.ts +180 -0
- package/dist/esm/api/bluetooth/react-native/types/ReactNativeTypes.js +9 -0
- package/dist/esm/api/bluetooth/types/index.d.ts +31 -0
- package/dist/esm/api/bluetooth/types/index.js +19 -0
- package/dist/esm/api/bluetooth/utils/create6DigitPin.d.ts +1 -0
- package/dist/esm/api/bluetooth/utils/create6DigitPin.js +4 -0
- package/dist/esm/api/bluetooth/utils/csvBufferToEpoch.d.ts +11 -0
- package/dist/esm/api/bluetooth/utils/csvBufferToEpoch.js +31 -0
- package/dist/esm/api/bluetooth/utils/encoding.d.ts +3 -0
- package/dist/esm/api/bluetooth/utils/encoding.js +17 -0
- package/dist/esm/api/bluetooth/utils/osHasBluetoothSupport.d.ts +2 -0
- package/dist/esm/api/bluetooth/utils/osHasBluetoothSupport.js +16 -0
- package/dist/esm/api/bluetooth/utils/stitch.d.ts +5 -0
- package/dist/esm/api/bluetooth/utils/stitch.js +18 -0
- package/dist/esm/api/bluetooth/web/WebBluetoothTransport.d.ts +54 -0
- package/dist/esm/api/bluetooth/web/WebBluetoothTransport.js +426 -0
- package/dist/esm/api/bluetooth/web/isMaybeWebWorkerContext.d.ts +1 -0
- package/dist/esm/api/bluetooth/web/isMaybeWebWorkerContext.js +4 -0
- package/dist/esm/api/bluetooth/web/isWebBluetoothSupported.d.ts +1 -0
- package/dist/esm/api/bluetooth/web/isWebBluetoothSupported.js +7 -0
- package/dist/esm/api/firebase/FirebaseApp.d.ts +20 -0
- package/dist/esm/api/firebase/FirebaseApp.js +63 -0
- package/dist/esm/api/firebase/FirebaseDevice.d.ts +68 -0
- package/dist/esm/api/firebase/FirebaseDevice.js +139 -0
- package/dist/esm/api/firebase/FirebaseUser.d.ts +53 -0
- package/dist/esm/api/firebase/FirebaseUser.js +426 -0
- package/dist/esm/api/firebase/config.d.ts +8 -0
- package/dist/esm/api/firebase/config.js +8 -0
- package/dist/esm/api/firebase/deviceStore.d.ts +26 -0
- package/dist/esm/api/firebase/deviceStore.js +184 -0
- package/dist/esm/api/firebase/index.d.ts +3 -0
- package/dist/esm/api/firebase/index.js +3 -0
- package/dist/esm/api/https/config.d.ts +1 -0
- package/dist/esm/api/https/config.js +1 -0
- package/dist/esm/api/https/createOAuthURL.d.ts +3 -0
- package/dist/esm/api/https/createOAuthURL.js +11 -0
- package/dist/esm/api/https/getOAuthToken.d.ts +3 -0
- package/dist/esm/api/https/getOAuthToken.js +27 -0
- package/dist/esm/api/https/utils.d.ts +2 -0
- package/dist/esm/api/https/utils.js +9 -0
- package/dist/esm/api/index.d.ts +109 -0
- package/dist/esm/api/index.js +300 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/neurosity.mjs +48705 -0
- package/dist/esm/subscriptions/SubscriptionManager.d.ts +11 -0
- package/dist/esm/subscriptions/SubscriptionManager.js +23 -0
- package/dist/esm/timesync/Timesync.d.ts +20 -0
- package/dist/esm/timesync/Timesync.js +71 -0
- package/dist/esm/timesync/index.d.ts +1 -0
- package/dist/esm/timesync/index.js +1 -0
- package/dist/esm/types/accelerometer.d.ts +10 -0
- package/dist/esm/types/accelerometer.js +1 -0
- package/dist/esm/types/actions.d.ts +16 -0
- package/dist/esm/types/actions.js +1 -0
- package/dist/esm/types/awareness.d.ts +1 -0
- package/dist/esm/types/awareness.js +1 -0
- package/dist/esm/types/brainwaves.d.ts +26 -0
- package/dist/esm/types/brainwaves.js +1 -0
- package/dist/esm/types/calm.d.ts +6 -0
- package/dist/esm/types/calm.js +1 -0
- package/dist/esm/types/client.d.ts +22 -0
- package/dist/esm/types/client.js +1 -0
- package/dist/esm/types/credentials.d.ts +12 -0
- package/dist/esm/types/credentials.js +1 -0
- package/dist/esm/types/deviceInfo.d.ts +18 -0
- package/dist/esm/types/deviceInfo.js +1 -0
- package/dist/esm/types/epoch.d.ts +12 -0
- package/dist/esm/types/epoch.js +1 -0
- package/dist/esm/types/experiment.d.ts +9 -0
- package/dist/esm/types/experiment.js +1 -0
- package/dist/esm/types/focus.d.ts +6 -0
- package/dist/esm/types/focus.js +1 -0
- package/dist/esm/types/hapticEffects.d.ts +125 -0
- package/dist/esm/types/hapticEffects.js +1 -0
- package/dist/esm/types/kinesis.d.ts +6 -0
- package/dist/esm/types/kinesis.js +1 -0
- package/dist/esm/types/marker.d.ts +7 -0
- package/dist/esm/types/marker.js +1 -0
- package/dist/esm/types/metrics.d.ts +21 -0
- package/dist/esm/types/metrics.js +1 -0
- package/dist/esm/types/oauth.d.ts +20 -0
- package/dist/esm/types/oauth.js +1 -0
- package/dist/esm/types/options.d.ts +51 -0
- package/dist/esm/types/options.js +1 -0
- package/dist/esm/types/sample.d.ts +15 -0
- package/dist/esm/types/sample.js +1 -0
- package/dist/esm/types/settings.d.ts +13 -0
- package/dist/esm/types/settings.js +1 -0
- package/dist/esm/types/signalQuality.d.ts +13 -0
- package/dist/esm/types/signalQuality.js +1 -0
- package/dist/esm/types/skill.d.ts +68 -0
- package/dist/esm/types/skill.js +1 -0
- package/dist/esm/types/status.d.ts +26 -0
- package/dist/esm/types/status.js +19 -0
- package/dist/esm/types/streaming.d.ts +15 -0
- package/dist/esm/types/streaming.js +17 -0
- package/dist/esm/types/subscriptions.d.ts +23 -0
- package/dist/esm/types/subscriptions.js +1 -0
- package/dist/esm/types/training.d.ts +19 -0
- package/dist/esm/types/training.js +1 -0
- package/dist/esm/types/user.d.ts +12 -0
- package/dist/esm/types/user.js +1 -0
- package/dist/esm/utils/errors.d.ts +5 -0
- package/dist/esm/utils/errors.js +11 -0
- package/dist/esm/utils/filterInternalKeys.d.ts +3 -0
- package/dist/esm/utils/filterInternalKeys.js +17 -0
- package/dist/esm/utils/hapticEffects.d.ts +123 -0
- package/dist/esm/utils/hapticEffects.js +125 -0
- package/dist/esm/utils/heartbeat.d.ts +4 -0
- package/dist/esm/utils/heartbeat.js +33 -0
- package/dist/esm/utils/is-node.d.ts +1 -0
- package/dist/esm/utils/is-node.js +5 -0
- package/dist/esm/utils/metrics.d.ts +1 -0
- package/dist/esm/utils/metrics.js +52 -0
- package/dist/esm/utils/oauth.d.ts +9 -0
- package/dist/esm/utils/oauth.js +64 -0
- package/dist/esm/utils/pick.d.ts +1 -0
- package/dist/esm/utils/pick.js +1 -0
- package/dist/esm/utils/pipes.d.ts +46 -0
- package/dist/esm/utils/pipes.js +65 -0
- package/dist/esm/utils/platform.d.ts +30 -0
- package/dist/esm/utils/platform.js +41 -0
- package/dist/esm/utils/subscription.d.ts +6 -0
- package/dist/esm/utils/subscription.js +24 -0
- package/dist/esm/utils/transferDevice.d.ts +9 -0
- package/dist/esm/utils/transferDevice.js +1 -0
- package/dist/esm/utils/whileOnline.d.ts +8 -0
- package/dist/esm/utils/whileOnline.js +11 -0
- package/dist/examples/auth.html +32 -0
- package/dist/examples/cloud.html +17 -0
- package/dist/examples/index.html +1 -0
- package/dist/examples/neurosity.iife.js +48717 -0
- package/dist/examples/neurosity.js +666 -0
- package/dist/examples/neurosity.mjs +48705 -0
- package/dist/examples/training.html +49 -0
- package/package.json +23 -18
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +0 -1
- package/dist/index.m.js +0 -2
- package/dist/index.m.js.map +0 -1
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.map +0 -1
- package/dist/utils/metrics.d.ts +0 -6
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import axios from "axios";
|
|
11
|
+
import { getFunctionsBaseURL } from "./utils";
|
|
12
|
+
export function getOAuthToken(query, sdkOptions) {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
const baseUrl = getFunctionsBaseURL(sdkOptions);
|
|
15
|
+
// Get refresh token
|
|
16
|
+
const refreshResponse = yield axios.post(`${baseUrl}/getOAuthRefreshToken`, query);
|
|
17
|
+
const refreshToken = refreshResponse.data;
|
|
18
|
+
return axios
|
|
19
|
+
.post(`${baseUrl}/token`, {
|
|
20
|
+
grant_type: "refresh_token",
|
|
21
|
+
refresh_token: refreshToken.data,
|
|
22
|
+
client_id: query.clientId,
|
|
23
|
+
client_secret: query.clientSecret
|
|
24
|
+
})
|
|
25
|
+
.then((response) => JSON.parse(response.data)["access_token"]);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { prodFunctionsBaseUrl } from "./config";
|
|
2
|
+
export function getFunctionsBaseURL(sdkOptions) {
|
|
3
|
+
if (!sdkOptions.emulator) {
|
|
4
|
+
return prodFunctionsBaseUrl;
|
|
5
|
+
}
|
|
6
|
+
const { emulatorHost, emulatorFunctionsPort } = sdkOptions;
|
|
7
|
+
const emulatorFunctionsBaseUrl = `http://${emulatorHost}:${emulatorFunctionsPort}/neurosity-device/us-central1`;
|
|
8
|
+
return emulatorFunctionsBaseUrl;
|
|
9
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Observable } from "rxjs";
|
|
2
|
+
import { FirebaseApp, FirebaseUser, FirebaseDevice } from "./firebase";
|
|
3
|
+
import { Timesync } from "../timesync";
|
|
4
|
+
import { SubscriptionManager } from "../subscriptions/SubscriptionManager";
|
|
5
|
+
import { Client } from "../types/client";
|
|
6
|
+
import { Action, Actions } from "../types/actions";
|
|
7
|
+
import { Metrics } from "../types/metrics";
|
|
8
|
+
import { SDKOptions } from "../types/options";
|
|
9
|
+
import { SkillsClient } from "../types/skill";
|
|
10
|
+
import { Credentials, CustomToken } from "../types/credentials";
|
|
11
|
+
import { EmailAndPassword } from "../types/credentials";
|
|
12
|
+
import { ChangeSettings } from "../types/settings";
|
|
13
|
+
import { DeviceStatus } from "../types/status";
|
|
14
|
+
import { DeviceInfo, DeviceSelector } from "../types/deviceInfo";
|
|
15
|
+
import { UserClaims } from "../types/user";
|
|
16
|
+
import { OAuthRemoveResponse } from "../types/oauth";
|
|
17
|
+
import { Experiment } from "../types/experiment";
|
|
18
|
+
import { TransferDeviceOptions } from "../utils/transferDevice";
|
|
19
|
+
export { credentialWithLink, createUser, SERVER_TIMESTAMP } from "./firebase";
|
|
20
|
+
/**
|
|
21
|
+
* @hidden
|
|
22
|
+
*/
|
|
23
|
+
export declare class CloudClient implements Client {
|
|
24
|
+
user: any;
|
|
25
|
+
userClaims: any;
|
|
26
|
+
protected options: SDKOptions;
|
|
27
|
+
protected firebaseApp: FirebaseApp;
|
|
28
|
+
protected firebaseUser: FirebaseUser;
|
|
29
|
+
protected firebaseDevice: FirebaseDevice;
|
|
30
|
+
protected timesync: Timesync;
|
|
31
|
+
protected subscriptionManager: SubscriptionManager;
|
|
32
|
+
protected status$: Observable<DeviceStatus>;
|
|
33
|
+
constructor(options: SDKOptions);
|
|
34
|
+
onDeviceChange(): Observable<DeviceInfo>;
|
|
35
|
+
private setAutoSelectedDevice;
|
|
36
|
+
get actions(): Actions;
|
|
37
|
+
dispatchAction(action: Action): Promise<any>;
|
|
38
|
+
disconnect(): Promise<any>;
|
|
39
|
+
getInfo(): Promise<any>;
|
|
40
|
+
login(credentials: Credentials): Promise<any>;
|
|
41
|
+
logout(): Promise<any>;
|
|
42
|
+
onAuthStateChanged(): Observable<{
|
|
43
|
+
selectedDevice: DeviceInfo;
|
|
44
|
+
delete(): Promise<void>;
|
|
45
|
+
emailVerified: boolean;
|
|
46
|
+
getIdTokenResult(forceRefresh?: boolean): Promise<import("@firebase/auth-types").IdTokenResult>;
|
|
47
|
+
getIdToken(forceRefresh?: boolean): Promise<string>;
|
|
48
|
+
isAnonymous: boolean;
|
|
49
|
+
linkAndRetrieveDataWithCredential(credential: import("@firebase/auth-types").AuthCredential): Promise<import("@firebase/auth-types").UserCredential>;
|
|
50
|
+
linkWithCredential(credential: import("@firebase/auth-types").AuthCredential): Promise<import("@firebase/auth-types").UserCredential>;
|
|
51
|
+
linkWithPhoneNumber(phoneNumber: string, applicationVerifier: import("@firebase/auth-types").ApplicationVerifier): Promise<import("@firebase/auth-types").ConfirmationResult>;
|
|
52
|
+
linkWithPopup(provider: import("@firebase/auth-types").AuthProvider): Promise<import("@firebase/auth-types").UserCredential>;
|
|
53
|
+
linkWithRedirect(provider: import("@firebase/auth-types").AuthProvider): Promise<void>;
|
|
54
|
+
metadata: import("@firebase/auth-types").UserMetadata;
|
|
55
|
+
multiFactor: import("@firebase/auth-types").MultiFactorUser;
|
|
56
|
+
phoneNumber: string;
|
|
57
|
+
providerData: import("@firebase/auth-types").UserInfo[];
|
|
58
|
+
reauthenticateAndRetrieveDataWithCredential(credential: import("@firebase/auth-types").AuthCredential): Promise<import("@firebase/auth-types").UserCredential>;
|
|
59
|
+
reauthenticateWithCredential(credential: import("@firebase/auth-types").AuthCredential): Promise<import("@firebase/auth-types").UserCredential>;
|
|
60
|
+
reauthenticateWithPhoneNumber(phoneNumber: string, applicationVerifier: import("@firebase/auth-types").ApplicationVerifier): Promise<import("@firebase/auth-types").ConfirmationResult>;
|
|
61
|
+
reauthenticateWithPopup(provider: import("@firebase/auth-types").AuthProvider): Promise<import("@firebase/auth-types").UserCredential>;
|
|
62
|
+
reauthenticateWithRedirect(provider: import("@firebase/auth-types").AuthProvider): Promise<void>;
|
|
63
|
+
refreshToken: string;
|
|
64
|
+
reload(): Promise<void>;
|
|
65
|
+
sendEmailVerification(actionCodeSettings?: import("@firebase/auth-types").ActionCodeSettings): Promise<void>;
|
|
66
|
+
tenantId: string;
|
|
67
|
+
toJSON(): Object;
|
|
68
|
+
unlink(providerId: string): Promise<import("@firebase/auth-types").User>;
|
|
69
|
+
updateEmail(newEmail: string): Promise<void>;
|
|
70
|
+
updatePassword(newPassword: string): Promise<void>;
|
|
71
|
+
updatePhoneNumber(phoneCredential: import("@firebase/auth-types").AuthCredential): Promise<void>;
|
|
72
|
+
updateProfile(profile: {
|
|
73
|
+
displayName?: string;
|
|
74
|
+
photoURL?: string;
|
|
75
|
+
}): Promise<void>;
|
|
76
|
+
verifyBeforeUpdateEmail(newEmail: string, actionCodeSettings?: import("@firebase/auth-types").ActionCodeSettings): Promise<void>;
|
|
77
|
+
displayName: string;
|
|
78
|
+
email: string;
|
|
79
|
+
photoURL: string;
|
|
80
|
+
providerId: string;
|
|
81
|
+
uid: string;
|
|
82
|
+
}>;
|
|
83
|
+
getDevices(): Promise<DeviceInfo[]>;
|
|
84
|
+
addDevice(deviceId: string): Promise<void>;
|
|
85
|
+
removeDevice(deviceId: string): Promise<void>;
|
|
86
|
+
transferDevice(options: TransferDeviceOptions): Promise<void>;
|
|
87
|
+
onUserDevicesChange(): Observable<DeviceInfo[]>;
|
|
88
|
+
onUserClaimsChange(): Observable<UserClaims>;
|
|
89
|
+
didSelectDevice(): Promise<boolean>;
|
|
90
|
+
selectDevice(deviceSelector: DeviceSelector): Promise<DeviceInfo>;
|
|
91
|
+
getSelectedDevice(): Promise<DeviceInfo | null>;
|
|
92
|
+
status(): Observable<DeviceStatus>;
|
|
93
|
+
observeNamespace(namespace: string): Observable<any>;
|
|
94
|
+
onceNamespace(namespace: string): Promise<any>;
|
|
95
|
+
get metrics(): Metrics;
|
|
96
|
+
createAccount(credentials: EmailAndPassword): Promise<any>;
|
|
97
|
+
deleteAccount(): Promise<void>;
|
|
98
|
+
createBluetoothToken(): Promise<string>;
|
|
99
|
+
createCustomToken(): Promise<CustomToken>;
|
|
100
|
+
removeOAuthAccess(): Promise<OAuthRemoveResponse>;
|
|
101
|
+
onUserExperiments(): Observable<Experiment[]>;
|
|
102
|
+
deleteUserExperiment(experimentId: string): Promise<void>;
|
|
103
|
+
get skills(): SkillsClient;
|
|
104
|
+
get timestamp(): number;
|
|
105
|
+
getTimesyncOffset(): number;
|
|
106
|
+
changeSettings(settings: ChangeSettings): Promise<void>;
|
|
107
|
+
goOffline(): void;
|
|
108
|
+
goOnline(): void;
|
|
109
|
+
}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { ReplaySubject, EMPTY } from "rxjs";
|
|
11
|
+
import { fromEventPattern, firstValueFrom } from "rxjs";
|
|
12
|
+
import { filter, shareReplay, share, switchMap } from "rxjs/operators";
|
|
13
|
+
import { FirebaseApp, FirebaseUser, FirebaseDevice } from "./firebase";
|
|
14
|
+
import { Timesync } from "../timesync";
|
|
15
|
+
import { SubscriptionManager } from "../subscriptions/SubscriptionManager";
|
|
16
|
+
import { heartbeatAwareStatus } from "../utils/heartbeat";
|
|
17
|
+
import { filterInternalKeys } from "../utils/filterInternalKeys";
|
|
18
|
+
export { credentialWithLink, createUser, SERVER_TIMESTAMP } from "./firebase";
|
|
19
|
+
/**
|
|
20
|
+
* @hidden
|
|
21
|
+
*/
|
|
22
|
+
export class CloudClient {
|
|
23
|
+
constructor(options) {
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
this._selectedDevice = new ReplaySubject(1);
|
|
28
|
+
this.options = options;
|
|
29
|
+
this.subscriptionManager = new SubscriptionManager();
|
|
30
|
+
this.firebaseApp = new FirebaseApp(options);
|
|
31
|
+
this.firebaseUser = new FirebaseUser(this.firebaseApp);
|
|
32
|
+
this._selectedDevice.next(undefined);
|
|
33
|
+
this.status$ = heartbeatAwareStatus(this.observeNamespace("status").pipe(share())).pipe(filterInternalKeys(), shareReplay(1));
|
|
34
|
+
this.firebaseUser.onAuthStateChanged().subscribe((user) => {
|
|
35
|
+
this.user = user;
|
|
36
|
+
});
|
|
37
|
+
this.firebaseUser.onUserClaimsChange().subscribe((userClaims) => {
|
|
38
|
+
this.userClaims = userClaims;
|
|
39
|
+
});
|
|
40
|
+
this.onDeviceChange().subscribe((device) => {
|
|
41
|
+
if (this.firebaseDevice) {
|
|
42
|
+
this.firebaseDevice.disconnect();
|
|
43
|
+
}
|
|
44
|
+
if (!device) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
this.firebaseDevice = new FirebaseDevice({
|
|
48
|
+
deviceId: device.deviceId,
|
|
49
|
+
firebaseApp: this.firebaseApp,
|
|
50
|
+
dependencies: {
|
|
51
|
+
subscriptionManager: this.subscriptionManager
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
if (this.options.timesync) {
|
|
55
|
+
this.timesync = new Timesync({
|
|
56
|
+
status$: this.status(),
|
|
57
|
+
getTimesync: this.firebaseDevice.getTimesync.bind(this.firebaseDevice)
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
onDeviceChange() {
|
|
63
|
+
return this._selectedDevice
|
|
64
|
+
.asObservable()
|
|
65
|
+
.pipe(filter((value) => value !== undefined));
|
|
66
|
+
}
|
|
67
|
+
// Automatically select device when user logs in
|
|
68
|
+
setAutoSelectedDevice() {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
// Select based on `deviceId` passed
|
|
71
|
+
if (this.options.deviceId) {
|
|
72
|
+
return yield this.selectDevice((devices) => {
|
|
73
|
+
return devices.find((device) => device.deviceId === this.options.deviceId);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
// Auto select first-claimed device
|
|
77
|
+
if (!this.options.deviceId && this.options.autoSelectDevice) {
|
|
78
|
+
return yield this.selectDevice((devices) => {
|
|
79
|
+
// Auto select first device
|
|
80
|
+
return devices[0];
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
get actions() {
|
|
87
|
+
return {
|
|
88
|
+
dispatch: (action) => {
|
|
89
|
+
return this.firebaseDevice.dispatchAction(action);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
dispatchAction(action) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
return yield this.firebaseDevice.dispatchAction(action);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
disconnect() {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
return this.firebaseApp.disconnect();
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
getInfo() {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
return yield this.firebaseDevice.getInfo();
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
login(credentials) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
if (this.user) {
|
|
111
|
+
return Promise.reject(`Already logged in.`);
|
|
112
|
+
}
|
|
113
|
+
const auth = yield this.firebaseUser.login(credentials);
|
|
114
|
+
const selectedDevice = yield this.setAutoSelectedDevice();
|
|
115
|
+
return Object.assign(Object.assign({}, auth), { selectedDevice });
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
logout() {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
if (this.firebaseDevice) {
|
|
121
|
+
this.firebaseDevice.disconnect();
|
|
122
|
+
}
|
|
123
|
+
return yield this.firebaseUser.logout();
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
onAuthStateChanged() {
|
|
127
|
+
return this.firebaseUser.onAuthStateChanged().pipe(switchMap((user) => __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
if (!user) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
const selectedDevice = this.didSelectDevice()
|
|
132
|
+
? yield this.getSelectedDevice()
|
|
133
|
+
: yield this.setAutoSelectedDevice();
|
|
134
|
+
return Object.assign(Object.assign({}, user), { selectedDevice });
|
|
135
|
+
})));
|
|
136
|
+
}
|
|
137
|
+
getDevices() {
|
|
138
|
+
return this.firebaseUser.getDevices();
|
|
139
|
+
}
|
|
140
|
+
addDevice(deviceId) {
|
|
141
|
+
return this.firebaseUser.addDevice(deviceId);
|
|
142
|
+
}
|
|
143
|
+
removeDevice(deviceId) {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
const [hasError, errorMessage] = yield this.firebaseUser
|
|
146
|
+
.removeDevice(deviceId)
|
|
147
|
+
.then(() => [false])
|
|
148
|
+
.catch((error) => [true, error]);
|
|
149
|
+
if (hasError) {
|
|
150
|
+
return Promise.reject(errorMessage);
|
|
151
|
+
}
|
|
152
|
+
const selectedDevice = yield this.getSelectedDevice();
|
|
153
|
+
if ((selectedDevice === null || selectedDevice === void 0 ? void 0 : selectedDevice.deviceId) === deviceId) {
|
|
154
|
+
this._selectedDevice.next(null);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
transferDevice(options) {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
const [hasError, error] = yield this.firebaseUser
|
|
161
|
+
.transferDevice(options)
|
|
162
|
+
.then(() => [false])
|
|
163
|
+
.catch((error) => [true, error]);
|
|
164
|
+
if (hasError) {
|
|
165
|
+
return Promise.reject(error);
|
|
166
|
+
}
|
|
167
|
+
const selectedDevice = yield this.getSelectedDevice();
|
|
168
|
+
if ((selectedDevice === null || selectedDevice === void 0 ? void 0 : selectedDevice.deviceId) === options.deviceId) {
|
|
169
|
+
this._selectedDevice.next(null);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
onUserDevicesChange() {
|
|
174
|
+
return this.firebaseUser.onUserDevicesChange();
|
|
175
|
+
}
|
|
176
|
+
onUserClaimsChange() {
|
|
177
|
+
return this.firebaseUser.onUserClaimsChange();
|
|
178
|
+
}
|
|
179
|
+
didSelectDevice() {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
const selectedDevice = yield this.getSelectedDevice();
|
|
182
|
+
return !!selectedDevice;
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
selectDevice(deviceSelector) {
|
|
186
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
+
const devices = yield this.getDevices();
|
|
188
|
+
if (!devices) {
|
|
189
|
+
return Promise.reject(`Did not find any devices for this user. Make sure your device is claimed by your Neurosity account.`);
|
|
190
|
+
}
|
|
191
|
+
const deviceTupleSelector = (devices) => devices.find((device) => {
|
|
192
|
+
if (!Array.isArray(deviceSelector)) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
const [deviceKey, deviceValue] = deviceSelector;
|
|
196
|
+
return (JSON.stringify(device === null || device === void 0 ? void 0 : device[deviceKey]) === JSON.stringify(deviceValue));
|
|
197
|
+
});
|
|
198
|
+
const device = typeof deviceSelector === "function"
|
|
199
|
+
? deviceSelector(devices)
|
|
200
|
+
: deviceTupleSelector(devices);
|
|
201
|
+
if (!device) {
|
|
202
|
+
return Promise.reject(`A device was not provided. Try returning a device from the devicesList provided in the callback.`);
|
|
203
|
+
}
|
|
204
|
+
const hasPermission = yield this.firebaseUser.hasDevicePermission(device.deviceId);
|
|
205
|
+
if (!hasPermission) {
|
|
206
|
+
return Promise.reject(`Rejected device access due to permissions.`);
|
|
207
|
+
}
|
|
208
|
+
this._selectedDevice.next(device);
|
|
209
|
+
return device;
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
getSelectedDevice() {
|
|
213
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
return yield firstValueFrom(this._selectedDevice);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
status() {
|
|
218
|
+
return this.status$;
|
|
219
|
+
}
|
|
220
|
+
observeNamespace(namespace) {
|
|
221
|
+
const getNamespaceValues = () => fromEventPattern((handler) => this.firebaseDevice.onNamespace(namespace, handler), (handler) => this.firebaseDevice.offNamespace(namespace, handler));
|
|
222
|
+
return this.onDeviceChange().pipe(switchMap((selectedDevice) => {
|
|
223
|
+
return selectedDevice ? getNamespaceValues() : EMPTY;
|
|
224
|
+
}));
|
|
225
|
+
}
|
|
226
|
+
onceNamespace(namespace) {
|
|
227
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
228
|
+
return yield this.firebaseDevice.onceNamespace(namespace);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
get metrics() {
|
|
232
|
+
return {
|
|
233
|
+
next: (metricName, metricValue) => {
|
|
234
|
+
this.firebaseDevice.nextMetric(metricName, metricValue);
|
|
235
|
+
},
|
|
236
|
+
on: (subscription, callback) => {
|
|
237
|
+
return this.firebaseDevice.onMetric(subscription, callback);
|
|
238
|
+
},
|
|
239
|
+
subscribe: (subscription) => {
|
|
240
|
+
const subscriptionCreated = this.firebaseDevice.subscribeToMetric(subscription);
|
|
241
|
+
this.subscriptionManager.add(subscriptionCreated);
|
|
242
|
+
return subscriptionCreated;
|
|
243
|
+
},
|
|
244
|
+
unsubscribe: (subscription, listener) => {
|
|
245
|
+
this.subscriptionManager.remove(subscription);
|
|
246
|
+
this.firebaseDevice.unsubscribeFromMetric(subscription);
|
|
247
|
+
this.firebaseDevice.removeMetricListener(subscription, listener);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
createAccount(credentials) {
|
|
252
|
+
return this.firebaseUser.createAccount(credentials);
|
|
253
|
+
}
|
|
254
|
+
deleteAccount() {
|
|
255
|
+
return this.firebaseUser.deleteAccount();
|
|
256
|
+
}
|
|
257
|
+
createBluetoothToken() {
|
|
258
|
+
return this.firebaseDevice.createBluetoothToken();
|
|
259
|
+
}
|
|
260
|
+
createCustomToken() {
|
|
261
|
+
return this.firebaseUser.createCustomToken();
|
|
262
|
+
}
|
|
263
|
+
removeOAuthAccess() {
|
|
264
|
+
return this.firebaseUser.removeOAuthAccess();
|
|
265
|
+
}
|
|
266
|
+
onUserExperiments() {
|
|
267
|
+
return this.firebaseUser.onUserExperiments();
|
|
268
|
+
}
|
|
269
|
+
deleteUserExperiment(experimentId) {
|
|
270
|
+
return this.firebaseUser.deleteUserExperiment(experimentId);
|
|
271
|
+
}
|
|
272
|
+
get skills() {
|
|
273
|
+
return {
|
|
274
|
+
get: (bundleId) => __awaiter(this, void 0, void 0, function* () {
|
|
275
|
+
return this.firebaseDevice.getSkill(bundleId);
|
|
276
|
+
})
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
get timestamp() {
|
|
280
|
+
return this.options.timesync ? this.timesync.timestamp : Date.now();
|
|
281
|
+
}
|
|
282
|
+
getTimesyncOffset() {
|
|
283
|
+
return this.timesync.offset;
|
|
284
|
+
}
|
|
285
|
+
changeSettings(settings) {
|
|
286
|
+
return this.firebaseDevice.changeSettings(settings);
|
|
287
|
+
}
|
|
288
|
+
goOffline() {
|
|
289
|
+
this.firebaseApp.goOffline();
|
|
290
|
+
}
|
|
291
|
+
goOnline() {
|
|
292
|
+
this.firebaseApp.goOnline();
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* @internal
|
|
296
|
+
*/
|
|
297
|
+
__getApp() {
|
|
298
|
+
return this.firebaseApp.app;
|
|
299
|
+
}
|
|
300
|
+
}
|