diff --git a/archaeologist/src/background.ts b/archaeologist/src/background.ts index 927cae32..55456592 100644 --- a/archaeologist/src/background.ts +++ b/archaeologist/src/background.ts @@ -27,7 +27,7 @@ import { NodeUtil, TotalUserActivity, ResourceVisit, - smuggler, + makeDatacenterStorageApi, UserExternalPipelineId, NodeCreatedVia, UserExternalPipelineIngestionProgress, @@ -877,7 +877,7 @@ browser.contextMenus.onClicked.addListener( } ) -const storage: StorageApi = smuggler +const storage: StorageApi = makeDatacenterStorageApi() auth.register() browserBookmarks.register(storage) diff --git a/archaeologist/src/content/App.tsx b/archaeologist/src/content/App.tsx index b7213ed6..e8698f6f 100644 --- a/archaeologist/src/content/App.tsx +++ b/archaeologist/src/content/App.tsx @@ -5,7 +5,7 @@ import browser from 'webextension-polyfill' import { PostHog } from 'posthog-js' import { v4 as uuidv4 } from 'uuid' -import { NodeUtil, NodeType, smuggler } from 'smuggler-api' +import { NodeUtil, NodeType, makeDatacenterStorageApi } from 'smuggler-api' import type { TNode, TNodeJson } from 'smuggler-api' import { genOriginId, OriginIdentity, log, productanalytics } from 'armoury' import * as truthsayer_archaeologist_communication from 'truthsayer-archaeologist-communication' @@ -390,7 +390,10 @@ const App = () => { return ( { return ( - + {state.userUid == null ? : } diff --git a/smuggler-api/src/api_cloud.ts b/smuggler-api/src/api_datacenter.ts similarity index 94% rename from smuggler-api/src/api_cloud.ts rename to smuggler-api/src/api_datacenter.ts index 172f51b0..a27fe9ff 100644 --- a/smuggler-api/src/api_cloud.ts +++ b/smuggler-api/src/api_datacenter.ts @@ -1,6 +1,6 @@ /** - * Implementation of smuggler APIs like @see StorageApi which interact with a - * cloud-hosted infrastructure to perform their job. + * Implementation of smuggler APIs like @see StorageApi which, to perform their job, + * interact with an infrastructure hosted in Mazed's datacenter. */ import { @@ -233,7 +233,7 @@ async function lookupNodes(key: NodeLookupKey, signal?: AbortSignal) { } else if ('webBookmark' in key) { const { id, stableUrl } = genOriginId(key.webBookmark.url) const query = { ...SLICE_ALL, origin: { id } } - const iter = smuggler.node.slice(query) + const iter = _getNodesSliceIter(query) for (let node = await iter.next(); node != null; node = await iter.next()) { const nodeUrl = node.extattrs?.web?.url @@ -245,7 +245,7 @@ async function lookupNodes(key: NodeLookupKey, signal?: AbortSignal) { } else if ('webQuote' in key) { const { id, stableUrl } = genOriginId(key.webQuote.url) const query = { ...SLICE_ALL, origin: { id } } - const iter = smuggler.node.slice(query) + const iter = _getNodesSliceIter(query) const nodes: TNode[] = [] for (let node = await iter.next(); node != null; node = await iter.next()) { @@ -261,7 +261,7 @@ async function lookupNodes(key: NodeLookupKey, signal?: AbortSignal) { } else if ('url' in key) { const { id, stableUrl } = genOriginId(key.url) const query = { ...SLICE_ALL, origin: { id } } - const iter = smuggler.node.slice(query) + const iter = _getNodesSliceIter(query) const nodes: TNode[] = [] for (let node = await iter.next(); node != null; node = await iter.next()) { @@ -957,62 +957,67 @@ function _makeResponseError(response: Response, message?: string): Error { }) } -export const smuggler: StorageApi & AuthenticationApi = { - getAuth, - node: { - get: getNode, - update: updateNode, - create: createNode, - createOrUpdate: createOrUpdateNode, - slice: _getNodesSliceIter, - lookup: lookupNodes, - delete: deleteNode, - bulkDelete: bulkDeleteNodes, - batch: { - /** - * Caution: these methods are not cached - */ - get: getNodeBatch, +export function makeDatacenterStorageApi(): StorageApi { + return { + node: { + get: getNode, + update: updateNode, + create: createNode, + createOrUpdate: createOrUpdateNode, + slice: _getNodesSliceIter, + lookup: lookupNodes, + delete: deleteNode, + bulkDelete: bulkDeleteNodes, + batch: { + /** + * Caution: these methods are not cached + */ + get: getNodeBatch, + }, + url: makeDirectUrl, }, - url: makeDirectUrl, - }, - blob: { - upload: uploadFiles, - sourceUrl: makeBlobSourceUrl, - }, - blob_index: { - build: buildFilesSearchIndex, - cfg: { - supportsMime: mimeTypeIsSupportedByBuildIndex, + blob: { + upload: uploadFiles, + sourceUrl: makeBlobSourceUrl, }, - }, - edge: { - create: createEdge, - get: getNodeAllEdges, - sticky: switchEdgeStickiness, - delete: deleteEdge, - }, + blob_index: { + build: buildFilesSearchIndex, + cfg: { + supportsMime: mimeTypeIsSupportedByBuildIndex, + }, + }, + edge: { + create: createEdge, + get: getNodeAllEdges, + sticky: switchEdgeStickiness, + delete: deleteEdge, + }, + activity: { + external: { + add: addExternalUserActivity, + get: getExternalUserActivity, + }, + association: { + record: recordExternalAssociation, + get: getExternalAssociation, + }, + }, + external: { + ingestion: { + get: getUserIngestionProgress, + advance: advanceUserIngestionProgress, + }, + }, + } +} + +export const authentication: AuthenticationApi = { + getAuth, session: { create: createSession, delete: deleteSession, update: updateSession, }, - activity: { - external: { - add: addExternalUserActivity, - get: getExternalUserActivity, - }, - association: { - record: recordExternalAssociation, - get: getExternalAssociation, - }, - }, - external: { - ingestion: { - get: getUserIngestionProgress, - advance: advanceUserIngestionProgress, - }, - }, user: { password: { recover: passwordRecoverRequest, diff --git a/smuggler-api/src/auth/account.ts b/smuggler-api/src/auth/account.ts index ca26ca85..222ebf3f 100644 --- a/smuggler-api/src/auth/account.ts +++ b/smuggler-api/src/auth/account.ts @@ -1,4 +1,4 @@ -import { smuggler } from './../api_cloud' +import { authentication } from '../api_datacenter' import { authCookie } from './cookie' import { AccountInterface } from './account_interface' import type { LocalCrypto } from './account_interface' @@ -40,7 +40,7 @@ export class UserAccount extends AnonymousAccount { } static async create(signal?: AbortSignal): Promise { - const user = await smuggler.getAuth({ signal }).catch(() => { + const user = await authentication.getAuth({ signal }).catch(() => { return null }) if (!user) { diff --git a/smuggler-api/src/auth/knocker.ts b/smuggler-api/src/auth/knocker.ts index 7ef12ab8..c794244d 100644 --- a/smuggler-api/src/auth/knocker.ts +++ b/smuggler-api/src/auth/knocker.ts @@ -1,4 +1,4 @@ -import { smuggler, SmugglerError } from '../api_cloud' +import { authentication, SmugglerError } from '../api_datacenter' import { StatusCode } from './../status_codes' import { authCookie } from './cookie' @@ -106,7 +106,7 @@ export class Knocker { const now = unixtime.now() if (this.#knockingPeriodSeconds < now - lastUpdateTime) { log.debug('Knock-knock smuggler', now, lastUpdateTime) - await smuggler.session.update(this.#abortController.signal) + await authentication.session.update(this.#abortController.signal) this.setLastUpdate({ time: now }) try { diff --git a/smuggler-api/src/index.ts b/smuggler-api/src/index.ts index 3d45f328..a4f6ea59 100644 --- a/smuggler-api/src/index.ts +++ b/smuggler-api/src/index.ts @@ -8,5 +8,5 @@ export * from './node_slice_iterator' export * from './storage_api' export * from './storage_api_throwing' export * from './authentication_api' -export { smuggler } from './api_cloud' +export { authentication, makeDatacenterStorageApi } from './api_datacenter' export { steroid } from './steroid/steroid' diff --git a/smuggler-api/src/steroid/node.ts b/smuggler-api/src/steroid/node.ts index d58a2607..30f1bb09 100644 --- a/smuggler-api/src/steroid/node.ts +++ b/smuggler-api/src/steroid/node.ts @@ -34,7 +34,7 @@ export type CreateNodeFromLocalBinaryArgs = { /** * Upload a local binary file as a *fully featured* Mazed node - * (as opposed to, for example, @see smuggler.blob.upload that + * (as opposed to, for example, @see StorageApi.blob.upload that * at the time of this writing creates a node that *doesn't support some * Mazed features* like search index). */ diff --git a/truthsayer/src/account/create/Signup.tsx b/truthsayer/src/account/create/Signup.tsx index 4bf163b8..5d57c46f 100644 --- a/truthsayer/src/account/create/Signup.tsx +++ b/truthsayer/src/account/create/Signup.tsx @@ -11,7 +11,7 @@ import { goto, History, routes } from '../../lib/route' import { log } from 'armoury' -import { smuggler } from 'smuggler-api' +import { authentication } from 'smuggler-api' import { Link } from 'react-router-dom' type SignupProps = { @@ -92,7 +92,7 @@ class SignupImpl extends React.Component { this.setState({ errorMsg: undefined, }) - smuggler.user + authentication.user .register({ name: this.state.name, email: this.state.email, diff --git a/truthsayer/src/auth/Login.js b/truthsayer/src/auth/Login.js index 6ff66847..66a570c0 100644 --- a/truthsayer/src/auth/Login.js +++ b/truthsayer/src/auth/Login.js @@ -8,7 +8,7 @@ import PropTypes from 'prop-types' import { css } from '@emotion/react' import { withRouter, Link } from 'react-router-dom' -import { smuggler } from 'smuggler-api' +import { authentication } from 'smuggler-api' import { goto } from '../lib/route' class Login extends React.Component { @@ -54,7 +54,7 @@ class Login extends React.Component { }) const { email, password } = this.state const permissions = null - smuggler.session + authentication.session .create( email, password, diff --git a/truthsayer/src/auth/Logout.js b/truthsayer/src/auth/Logout.js index e864f14e..656c8024 100644 --- a/truthsayer/src/auth/Logout.js +++ b/truthsayer/src/auth/Logout.js @@ -4,7 +4,7 @@ import PropTypes from 'prop-types' import { withRouter } from 'react-router-dom' import { goto } from '../lib/route' -import { smuggler } from 'smuggler-api' +import { authentication } from 'smuggler-api' import { MzdGlobalContext } from './../lib/global' @@ -26,7 +26,7 @@ class Logout extends React.Component { const account = this.context.account const isAuthenticated = account != null && account.isAuthenticated() if (isAuthenticated) { - smuggler.session + authentication.session .delete({ signal: this.fetchAbortController.signal, }) diff --git a/truthsayer/src/auth/PasswordChange.js b/truthsayer/src/auth/PasswordChange.js index f1aa9d2d..75184eef 100644 --- a/truthsayer/src/auth/PasswordChange.js +++ b/truthsayer/src/auth/PasswordChange.js @@ -3,7 +3,7 @@ import React from 'react' import { Badge, Button, Card, Col, Container, Form, Row } from 'react-bootstrap' import PropTypes from 'prop-types' -import { smuggler } from 'smuggler-api' +import { authentication } from 'smuggler-api' import { withRouter } from 'react-router-dom' class PasswordChange extends React.Component { @@ -54,7 +54,7 @@ class PasswordChange extends React.Component { onSubmit = (event) => { event.preventDefault() - smuggler.user.password + authentication.user.password .change({ old_password: this.state.password, new_password: this.state.new_password, diff --git a/truthsayer/src/auth/PasswordRecoverForm.js b/truthsayer/src/auth/PasswordRecoverForm.js index 3379a17a..ba93f414 100644 --- a/truthsayer/src/auth/PasswordRecoverForm.js +++ b/truthsayer/src/auth/PasswordRecoverForm.js @@ -5,7 +5,7 @@ import { Card, Button, Form, Container, Row, Col } from 'react-bootstrap' import PropTypes from 'prop-types' import { withRouter } from 'react-router-dom' -import { smuggler } from 'smuggler-api' +import { authentication } from 'smuggler-api' class PasswordRecoverForm extends React.Component { constructor(props) { @@ -36,7 +36,7 @@ class PasswordRecoverForm extends React.Component { onSubmit = (event) => { event.preventDefault() - smuggler.user.password + authentication.user.password .reset({ token: this.props.token, new_password: this.state.password, diff --git a/truthsayer/src/auth/PasswordRecoverRequest.js b/truthsayer/src/auth/PasswordRecoverRequest.js index b07eec1a..d056d2db 100644 --- a/truthsayer/src/auth/PasswordRecoverRequest.js +++ b/truthsayer/src/auth/PasswordRecoverRequest.js @@ -12,7 +12,7 @@ import { import { Emoji } from './../lib/Emoji' import PropTypes from 'prop-types' -import { smuggler } from 'smuggler-api' +import { authentication } from 'smuggler-api' import { withRouter } from 'react-router-dom' class PasswordRecoverRequest extends React.Component { @@ -67,7 +67,7 @@ class PasswordRecoverRequest extends React.Component { onSubmit = (event) => { event.preventDefault() - smuggler.user.password + authentication.user.password .recover({ email: this.state.email, signal: this.abortControler.signal, diff --git a/truthsayer/src/crypto/local.ts b/truthsayer/src/crypto/local.ts index 6b5db12a..7d0c9a67 100644 --- a/truthsayer/src/crypto/local.ts +++ b/truthsayer/src/crypto/local.ts @@ -9,7 +9,7 @@ import { sha1, } from './wrapper' -import { smuggler } from 'smuggler-api' +import { authentication } from 'smuggler-api' import { base64 } from 'armoury' @@ -32,7 +32,7 @@ export class LocalCrypto { _uid: string = '' _storage: TStorage _lastSecret: TSecret | null = null - _smuggler: any + _authentication: any constructor( uid: string, @@ -42,7 +42,7 @@ export class LocalCrypto { ) { this._uid = uid this._storage = storage || ls - this._smuggler = remote || smuggler + this._authentication = remote || authentication this._lastSecret = lastSecret || null } @@ -164,7 +164,7 @@ export class LocalCrypto { return null } const secretEnc: TEncrypted = base64.toObject(secretBase64) - const secondKeyData = await this._smuggler.getSecondKey({ + const secondKeyData = await this._authentication.getSecondKey({ id: secretEnc.secret_id, }) const secondKey: TSecret = { @@ -177,7 +177,7 @@ export class LocalCrypto { } async _storeSecretToLocalStorage(secretPhrase: string): Promise { - const secondKeyData = await this._smuggler.getAnySecondKey() + const secondKeyData = await this._authentication.getAnySecondKey() // { // key: String, // length: u32, diff --git a/truthsayer/src/lib/global.tsx b/truthsayer/src/lib/global.tsx index 051be916..75f89245 100644 --- a/truthsayer/src/lib/global.tsx +++ b/truthsayer/src/lib/global.tsx @@ -9,7 +9,7 @@ import { jcss } from 'elementary' import { createUserAccount, AccountInterface, - smuggler, + makeDatacenterStorageApi, makeAlwaysThrowingStorageApi, } from 'smuggler-api' import type { StorageApi } from 'smuggler-api' @@ -116,7 +116,7 @@ export class MzdGlobal extends React.Component { }, account: null, analytics: props.analytics, - storage: smuggler, + storage: makeDatacenterStorageApi(), } }