Skip to content
This repository was archived by the owner on Oct 25, 2023. It is now read-only.

Commit 44bf629

Browse files
authored
replace StorageApi global var with a make fn (#394)
1 parent 93c359e commit 44bf629

File tree

16 files changed

+93
-85
lines changed

16 files changed

+93
-85
lines changed

archaeologist/src/background.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
NodeUtil,
2828
TotalUserActivity,
2929
ResourceVisit,
30-
smuggler,
30+
makeDatacenterStorageApi,
3131
UserExternalPipelineId,
3232
NodeCreatedVia,
3333
UserExternalPipelineIngestionProgress,
@@ -877,7 +877,7 @@ browser.contextMenus.onClicked.addListener(
877877
}
878878
)
879879

880-
const storage: StorageApi = smuggler
880+
const storage: StorageApi = makeDatacenterStorageApi()
881881

882882
auth.register()
883883
browserBookmarks.register(storage)

archaeologist/src/content/App.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import browser from 'webextension-polyfill'
55
import { PostHog } from 'posthog-js'
66
import { v4 as uuidv4 } from 'uuid'
77

8-
import { NodeUtil, NodeType, smuggler } from 'smuggler-api'
8+
import { NodeUtil, NodeType, makeDatacenterStorageApi } from 'smuggler-api'
99
import type { TNode, TNodeJson } from 'smuggler-api'
1010
import { genOriginId, OriginIdentity, log, productanalytics } from 'armoury'
1111
import * as truthsayer_archaeologist_communication from 'truthsayer-archaeologist-communication'
@@ -390,7 +390,10 @@ const App = () => {
390390
return (
391391
<AppErrorBoundary>
392392
<ContentContext.Provider
393-
value={{ analytics: state.analytics, storage: smuggler }}
393+
value={{
394+
analytics: state.analytics,
395+
storage: makeDatacenterStorageApi(),
396+
}}
394397
>
395398
<BrowserHistoryImportControlPortal
396399
progress={state.browserHistoryUploadProgress}

archaeologist/src/popup/PopUpApp.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { mazed } from '../util/mazed'
1515
import { MdiLaunch } from 'elementary'
1616
import { productanalytics } from 'armoury'
1717
import { PopUpContext } from './context'
18-
import { smuggler } from 'smuggler-api'
18+
import { makeDatacenterStorageApi } from 'smuggler-api'
1919

2020
const AppContainer = styled.div`
2121
width: 340px;
@@ -74,7 +74,7 @@ export const PopUpApp = () => {
7474

7575
return (
7676
<AppContainer>
77-
<PopUpContext.Provider value={{ storage: smuggler }}>
77+
<PopUpContext.Provider value={{ storage: makeDatacenterStorageApi() }}>
7878
{state.userUid == null ? <LoginPage /> : <ViewActiveTabStatus />}
7979
</PopUpContext.Provider>
8080
</AppContainer>

smuggler-api/src/api_cloud.ts renamed to smuggler-api/src/api_datacenter.ts

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* Implementation of smuggler APIs like @see StorageApi which interact with a
3-
* cloud-hosted infrastructure to perform their job.
2+
* Implementation of smuggler APIs like @see StorageApi which, to perform their job,
3+
* interact with an infrastructure hosted in Mazed's datacenter.
44
*/
55

66
import {
@@ -233,7 +233,7 @@ async function lookupNodes(key: NodeLookupKey, signal?: AbortSignal) {
233233
} else if ('webBookmark' in key) {
234234
const { id, stableUrl } = genOriginId(key.webBookmark.url)
235235
const query = { ...SLICE_ALL, origin: { id } }
236-
const iter = smuggler.node.slice(query)
236+
const iter = _getNodesSliceIter(query)
237237

238238
for (let node = await iter.next(); node != null; node = await iter.next()) {
239239
const nodeUrl = node.extattrs?.web?.url
@@ -245,7 +245,7 @@ async function lookupNodes(key: NodeLookupKey, signal?: AbortSignal) {
245245
} else if ('webQuote' in key) {
246246
const { id, stableUrl } = genOriginId(key.webQuote.url)
247247
const query = { ...SLICE_ALL, origin: { id } }
248-
const iter = smuggler.node.slice(query)
248+
const iter = _getNodesSliceIter(query)
249249

250250
const nodes: TNode[] = []
251251
for (let node = await iter.next(); node != null; node = await iter.next()) {
@@ -261,7 +261,7 @@ async function lookupNodes(key: NodeLookupKey, signal?: AbortSignal) {
261261
} else if ('url' in key) {
262262
const { id, stableUrl } = genOriginId(key.url)
263263
const query = { ...SLICE_ALL, origin: { id } }
264-
const iter = smuggler.node.slice(query)
264+
const iter = _getNodesSliceIter(query)
265265

266266
const nodes: TNode[] = []
267267
for (let node = await iter.next(); node != null; node = await iter.next()) {
@@ -957,62 +957,67 @@ function _makeResponseError(response: Response, message?: string): Error {
957957
})
958958
}
959959

960-
export const smuggler: StorageApi & AuthenticationApi = {
961-
getAuth,
962-
node: {
963-
get: getNode,
964-
update: updateNode,
965-
create: createNode,
966-
createOrUpdate: createOrUpdateNode,
967-
slice: _getNodesSliceIter,
968-
lookup: lookupNodes,
969-
delete: deleteNode,
970-
bulkDelete: bulkDeleteNodes,
971-
batch: {
972-
/**
973-
* Caution: these methods are not cached
974-
*/
975-
get: getNodeBatch,
960+
export function makeDatacenterStorageApi(): StorageApi {
961+
return {
962+
node: {
963+
get: getNode,
964+
update: updateNode,
965+
create: createNode,
966+
createOrUpdate: createOrUpdateNode,
967+
slice: _getNodesSliceIter,
968+
lookup: lookupNodes,
969+
delete: deleteNode,
970+
bulkDelete: bulkDeleteNodes,
971+
batch: {
972+
/**
973+
* Caution: these methods are not cached
974+
*/
975+
get: getNodeBatch,
976+
},
977+
url: makeDirectUrl,
976978
},
977-
url: makeDirectUrl,
978-
},
979-
blob: {
980-
upload: uploadFiles,
981-
sourceUrl: makeBlobSourceUrl,
982-
},
983-
blob_index: {
984-
build: buildFilesSearchIndex,
985-
cfg: {
986-
supportsMime: mimeTypeIsSupportedByBuildIndex,
979+
blob: {
980+
upload: uploadFiles,
981+
sourceUrl: makeBlobSourceUrl,
987982
},
988-
},
989-
edge: {
990-
create: createEdge,
991-
get: getNodeAllEdges,
992-
sticky: switchEdgeStickiness,
993-
delete: deleteEdge,
994-
},
983+
blob_index: {
984+
build: buildFilesSearchIndex,
985+
cfg: {
986+
supportsMime: mimeTypeIsSupportedByBuildIndex,
987+
},
988+
},
989+
edge: {
990+
create: createEdge,
991+
get: getNodeAllEdges,
992+
sticky: switchEdgeStickiness,
993+
delete: deleteEdge,
994+
},
995+
activity: {
996+
external: {
997+
add: addExternalUserActivity,
998+
get: getExternalUserActivity,
999+
},
1000+
association: {
1001+
record: recordExternalAssociation,
1002+
get: getExternalAssociation,
1003+
},
1004+
},
1005+
external: {
1006+
ingestion: {
1007+
get: getUserIngestionProgress,
1008+
advance: advanceUserIngestionProgress,
1009+
},
1010+
},
1011+
}
1012+
}
1013+
1014+
export const authentication: AuthenticationApi = {
1015+
getAuth,
9951016
session: {
9961017
create: createSession,
9971018
delete: deleteSession,
9981019
update: updateSession,
9991020
},
1000-
activity: {
1001-
external: {
1002-
add: addExternalUserActivity,
1003-
get: getExternalUserActivity,
1004-
},
1005-
association: {
1006-
record: recordExternalAssociation,
1007-
get: getExternalAssociation,
1008-
},
1009-
},
1010-
external: {
1011-
ingestion: {
1012-
get: getUserIngestionProgress,
1013-
advance: advanceUserIngestionProgress,
1014-
},
1015-
},
10161021
user: {
10171022
password: {
10181023
recover: passwordRecoverRequest,

smuggler-api/src/auth/account.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { smuggler } from './../api_cloud'
1+
import { authentication } from '../api_datacenter'
22
import { authCookie } from './cookie'
33
import { AccountInterface } from './account_interface'
44
import type { LocalCrypto } from './account_interface'
@@ -40,7 +40,7 @@ export class UserAccount extends AnonymousAccount {
4040
}
4141

4242
static async create(signal?: AbortSignal): Promise<AccountInterface> {
43-
const user = await smuggler.getAuth({ signal }).catch(() => {
43+
const user = await authentication.getAuth({ signal }).catch(() => {
4444
return null
4545
})
4646
if (!user) {

smuggler-api/src/auth/knocker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { smuggler, SmugglerError } from '../api_cloud'
1+
import { authentication, SmugglerError } from '../api_datacenter'
22
import { StatusCode } from './../status_codes'
33
import { authCookie } from './cookie'
44

@@ -106,7 +106,7 @@ export class Knocker {
106106
const now = unixtime.now()
107107
if (this.#knockingPeriodSeconds < now - lastUpdateTime) {
108108
log.debug('Knock-knock smuggler', now, lastUpdateTime)
109-
await smuggler.session.update(this.#abortController.signal)
109+
await authentication.session.update(this.#abortController.signal)
110110
this.setLastUpdate({ time: now })
111111

112112
try {

smuggler-api/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export * from './node_slice_iterator'
88
export * from './storage_api'
99
export * from './storage_api_throwing'
1010
export * from './authentication_api'
11-
export { smuggler } from './api_cloud'
11+
export { authentication, makeDatacenterStorageApi } from './api_datacenter'
1212
export { steroid } from './steroid/steroid'

smuggler-api/src/steroid/node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export type CreateNodeFromLocalBinaryArgs = {
3434

3535
/**
3636
* Upload a local binary file as a *fully featured* Mazed node
37-
* (as opposed to, for example, @see smuggler.blob.upload that
37+
* (as opposed to, for example, @see StorageApi.blob.upload that
3838
* at the time of this writing creates a node that *doesn't support some
3939
* Mazed features* like search index).
4040
*/

truthsayer/src/account/create/Signup.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { goto, History, routes } from '../../lib/route'
1111

1212
import { log } from 'armoury'
1313

14-
import { smuggler } from 'smuggler-api'
14+
import { authentication } from 'smuggler-api'
1515
import { Link } from 'react-router-dom'
1616

1717
type SignupProps = {
@@ -92,7 +92,7 @@ class SignupImpl extends React.Component<SignupProps, SignupState> {
9292
this.setState({
9393
errorMsg: undefined,
9494
})
95-
smuggler.user
95+
authentication.user
9696
.register({
9797
name: this.state.name,
9898
email: this.state.email,

truthsayer/src/auth/Login.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import PropTypes from 'prop-types'
88
import { css } from '@emotion/react'
99
import { withRouter, Link } from 'react-router-dom'
1010

11-
import { smuggler } from 'smuggler-api'
11+
import { authentication } from 'smuggler-api'
1212
import { goto } from '../lib/route'
1313

1414
class Login extends React.Component {
@@ -54,7 +54,7 @@ class Login extends React.Component {
5454
})
5555
const { email, password } = this.state
5656
const permissions = null
57-
smuggler.session
57+
authentication.session
5858
.create(
5959
email,
6060
password,

0 commit comments

Comments
 (0)