@exodus/headless 2.0.0-alpha.6 → 2.0.0-alpha.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +433 -0
- package/README.md +133 -4
- package/package.json +54 -17
- package/src/api.js +11 -31
- package/src/application.js +54 -39
- package/src/atoms/attach.js +31 -0
- package/src/atoms/base-asset-names-to-monitor.js +37 -0
- package/src/constants.js +37 -0
- package/src/dependencies/atoms.js +2 -21
- package/src/dependencies/index.js +8 -1
- package/src/dependencies/modules.js +2 -16
- package/src/dependencies/plugins.js +7 -0
- package/src/dependencies/utils.js +0 -4
- package/src/features/available-assets/index.js +15 -0
- package/src/features/balances/index.js +14 -0
- package/src/features/blockchain-metadata/api.js +22 -0
- package/src/features/blockchain-metadata/index.js +20 -0
- package/src/features/blockchain-metadata/plugin.js +30 -0
- package/src/features/blockchain-metadata/utils.js +11 -0
- package/src/features/enabled-assets/api.js +18 -0
- package/src/features/enabled-assets/index.js +26 -0
- package/src/features/enabled-assets/plugin.js +18 -0
- package/src/features/feature-flags/api.js +14 -0
- package/src/features/feature-flags/index.js +37 -0
- package/src/features/feature-flags/plugin.js +18 -0
- package/src/features/fees/index.js +16 -0
- package/src/features/fees/plugin.js +17 -0
- package/src/features/fiat-balances/index.js +10 -0
- package/src/features/fiat-balances/non-dust-balance-asset-names-atom.js +10 -0
- package/src/features/geolocation/index.js +20 -0
- package/src/features/geolocation/plugin.js +14 -0
- package/src/features/locale/api.js +13 -0
- package/src/features/locale/index.js +50 -0
- package/src/features/locale/plugin.js +14 -0
- package/src/features/market-history/index.js +69 -0
- package/src/features/market-history/plugin.js +21 -0
- package/src/features/nfts/api.js +13 -0
- package/src/features/nfts/index.js +33 -0
- package/src/features/nfts/plugin.js +23 -0
- package/src/features/pricing/api.js +14 -0
- package/src/features/pricing/index.js +35 -0
- package/src/features/rates/api.js +12 -0
- package/src/features/rates/index.js +22 -0
- package/src/features/rates/plugin.js +17 -0
- package/src/features/remote-config/api.js +13 -0
- package/src/features/remote-config/index.js +28 -0
- package/src/features/remote-config/plugin.js +20 -0
- package/src/features/wallet/api.js +34 -0
- package/src/features/wallet/index.js +24 -0
- package/src/features/wallet/locked-atom.js +10 -0
- package/src/features/wallet/restore-atom.js +10 -0
- package/src/features/wallet/restore-plugin.js +17 -0
- package/src/features/wallet-accounts/api.js +16 -0
- package/src/features/wallet-accounts/index.js +29 -0
- package/src/features/wallet-accounts/plugin.js +18 -0
- package/src/index.js +102 -18
- package/src/ioc.js +40 -7
- package/src/plugins/attach.js +25 -0
- package/src/plugins/index.js +5 -0
- package/src/plugins/log-lifecycle.js +26 -0
- package/src/unlock-encrypted-storage.js +1 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import createRemoteConfig from '@exodus/config/remote'
|
|
2
|
+
import EventEmitter from 'events/'
|
|
3
|
+
|
|
4
|
+
import remoteConfigApiDefinition from './api'
|
|
5
|
+
import remoteConfigPluginDefinition from './plugin'
|
|
6
|
+
|
|
7
|
+
const remoteConfig = () => {
|
|
8
|
+
return {
|
|
9
|
+
id: 'remoteConfig',
|
|
10
|
+
definitions: [
|
|
11
|
+
{
|
|
12
|
+
definition: {
|
|
13
|
+
id: 'remoteConfig',
|
|
14
|
+
type: 'module',
|
|
15
|
+
factory: (deps) => {
|
|
16
|
+
const eventEmitter = new EventEmitter().setMaxListeners(Number.POSITIVE_INFINITY)
|
|
17
|
+
return createRemoteConfig({ eventEmitter, ...deps })
|
|
18
|
+
},
|
|
19
|
+
dependencies: ['fetch', 'freeze', 'config', 'logger'],
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
{ definition: remoteConfigPluginDefinition },
|
|
23
|
+
{ definition: remoteConfigApiDefinition },
|
|
24
|
+
],
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default remoteConfig
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const remoteConfigLifecyclePlugin = ({ remoteConfig, port }) => {
|
|
2
|
+
remoteConfig.on('sync', ({ current }) => port.emit('remote-config', current))
|
|
3
|
+
|
|
4
|
+
const onStart = () => {
|
|
5
|
+
remoteConfig.load()
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const onUnlock = () => {
|
|
9
|
+
remoteConfig.sync()
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return { onUnlock, onStart }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
id: 'remoteConfigLifecyclePlugin',
|
|
17
|
+
type: 'plugin',
|
|
18
|
+
factory: remoteConfigLifecyclePlugin,
|
|
19
|
+
dependencies: ['remoteConfig', 'port'],
|
|
20
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const createWalletApi = ({ wallet, application, passphraseCache }) => {
|
|
2
|
+
const restoreFromCurrentPhrase = async ({ passphrase } = {}) => {
|
|
3
|
+
if (!passphrase) passphrase = await passphraseCache.get()
|
|
4
|
+
const mnemonic = await application.getMnemonic({ passphrase })
|
|
5
|
+
await application.import({ passphrase, mnemonic })
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
wallet: {
|
|
10
|
+
exists: () => wallet.exists(),
|
|
11
|
+
start: application.start,
|
|
12
|
+
load: application.load,
|
|
13
|
+
unload: application.unload,
|
|
14
|
+
create: application.create,
|
|
15
|
+
lock: application.lock,
|
|
16
|
+
unlock: application.unlock,
|
|
17
|
+
import: application.import,
|
|
18
|
+
delete: application.delete,
|
|
19
|
+
getMnemonic: application.getMnemonic,
|
|
20
|
+
setBackedUp: application.setBackedUp,
|
|
21
|
+
changePassphrase: application.changePassphrase,
|
|
22
|
+
changeLockTimer: application.changeLockTimer,
|
|
23
|
+
restoreFromCurrentPhrase,
|
|
24
|
+
isLocked: () => wallet.isLocked(),
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default {
|
|
30
|
+
id: 'walletApi',
|
|
31
|
+
type: 'api',
|
|
32
|
+
factory: createWalletApi,
|
|
33
|
+
dependencies: ['wallet', 'application', 'passphraseCache'],
|
|
34
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import walletDefinition from '@exodus/wallet/module'
|
|
2
|
+
|
|
3
|
+
import walletApi from './api'
|
|
4
|
+
import lockedAtomDefinition from './locked-atom'
|
|
5
|
+
import restoreAtomDefinition from './restore-atom'
|
|
6
|
+
import restorePluginDefinition from './restore-plugin'
|
|
7
|
+
|
|
8
|
+
const wallet = () => {
|
|
9
|
+
return {
|
|
10
|
+
id: 'wallet',
|
|
11
|
+
definitions: [
|
|
12
|
+
{
|
|
13
|
+
definition: { type: 'module', ...walletDefinition },
|
|
14
|
+
writesAtoms: ['lockedAtom'],
|
|
15
|
+
},
|
|
16
|
+
{ definition: lockedAtomDefinition },
|
|
17
|
+
{ definition: restoreAtomDefinition },
|
|
18
|
+
{ definition: restorePluginDefinition, writesAtoms: ['restoreAtom'] },
|
|
19
|
+
{ definition: walletApi },
|
|
20
|
+
],
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default wallet
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const restorePlugin = ({ restoreAtom }) => {
|
|
2
|
+
return {
|
|
3
|
+
onStart: async ({ isRestoring }) => {
|
|
4
|
+
await restoreAtom.set(!!isRestoring)
|
|
5
|
+
},
|
|
6
|
+
onAssetsSynced: async () => {
|
|
7
|
+
await restoreAtom.set(false)
|
|
8
|
+
},
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
id: 'restorePlugin',
|
|
14
|
+
type: 'plugin',
|
|
15
|
+
factory: restorePlugin,
|
|
16
|
+
dependencies: ['restoreAtom'],
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const walletAccountsApi = ({ walletAccounts, enabledWalletAccountsAtom }) => ({
|
|
2
|
+
walletAccounts: {
|
|
3
|
+
create: walletAccounts.create,
|
|
4
|
+
update: walletAccounts.update,
|
|
5
|
+
disable: walletAccounts.disable,
|
|
6
|
+
enable: walletAccounts.enable,
|
|
7
|
+
getEnabled: enabledWalletAccountsAtom.get,
|
|
8
|
+
},
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
id: 'walletAccountsApi',
|
|
13
|
+
type: 'api',
|
|
14
|
+
factory: walletAccountsApi,
|
|
15
|
+
dependencies: ['walletAccounts', 'enabledWalletAccountsAtom'],
|
|
16
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
enabledWalletAccountsAtomDefinition,
|
|
3
|
+
walletAccountsAtomDefinition,
|
|
4
|
+
} from '@exodus/wallet-accounts/atoms'
|
|
5
|
+
import walletAccountsDefinition from '@exodus/wallet-accounts/module'
|
|
6
|
+
|
|
7
|
+
import walletAccountsApiDefinition from './api'
|
|
8
|
+
import walletAccountsPluginDefinition from './plugin'
|
|
9
|
+
|
|
10
|
+
const walletAccounts = () => {
|
|
11
|
+
return {
|
|
12
|
+
id: 'walletAccounts',
|
|
13
|
+
definitions: [
|
|
14
|
+
{
|
|
15
|
+
definition: walletAccountsDefinition,
|
|
16
|
+
writesAtoms: ['walletAccountsAtom'],
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
definition: walletAccountsAtomDefinition,
|
|
20
|
+
storage: { namespace: 'walletAccounts' },
|
|
21
|
+
},
|
|
22
|
+
{ definition: enabledWalletAccountsAtomDefinition },
|
|
23
|
+
{ definition: walletAccountsApiDefinition },
|
|
24
|
+
{ definition: walletAccountsPluginDefinition },
|
|
25
|
+
],
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default walletAccounts
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const walletAccountsPlugin = ({ walletAccounts }) => {
|
|
2
|
+
const onUnlock = async () => {
|
|
3
|
+
await walletAccounts.load()
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const onClear = async () => {
|
|
7
|
+
await walletAccounts.clear()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return { onUnlock, onClear }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
id: 'walletAccountsLifecyclePlugin',
|
|
15
|
+
type: 'plugin',
|
|
16
|
+
factory: walletAccountsPlugin,
|
|
17
|
+
dependencies: ['walletAccounts'],
|
|
18
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,46 +1,130 @@
|
|
|
1
|
-
import
|
|
1
|
+
import abTesting from '@exodus/ab-testing'
|
|
2
|
+
import addressProvider from '@exodus/address-provider'
|
|
3
|
+
import apyRates from '@exodus/apy-rates'
|
|
4
|
+
import { pick } from '@exodus/basic-utils'
|
|
5
|
+
import connectedOrigins from '@exodus/connected-origins'
|
|
6
|
+
import cryptoNews from '@exodus/crypto-news-monitor'
|
|
7
|
+
import keychain from '@exodus/keychain'
|
|
8
|
+
import kyc from '@exodus/kyc'
|
|
9
|
+
import topMovers from '@exodus/top-movers-monitor'
|
|
10
|
+
|
|
2
11
|
import createApi from './api'
|
|
12
|
+
import attachAtoms from './atoms/attach'
|
|
13
|
+
import { atomsToAttach } from './constants'
|
|
14
|
+
import availableAssets from './features/available-assets'
|
|
15
|
+
import balances from './features/balances'
|
|
16
|
+
import blockchainMetadata from './features/blockchain-metadata'
|
|
17
|
+
import enabledAssets from './features/enabled-assets'
|
|
18
|
+
import featureFlags from './features/feature-flags'
|
|
19
|
+
import fees from './features/fees'
|
|
20
|
+
import fiatBalances from './features/fiat-balances'
|
|
21
|
+
import geolocation from './features/geolocation'
|
|
22
|
+
import locale from './features/locale'
|
|
23
|
+
import marketHistory from './features/market-history'
|
|
24
|
+
import nfts from './features/nfts'
|
|
25
|
+
import pricing from './features/pricing'
|
|
26
|
+
import rates from './features/rates'
|
|
27
|
+
import remoteConfig from './features/remote-config'
|
|
28
|
+
import wallet from './features/wallet'
|
|
29
|
+
import walletAccounts from './features/wallet-accounts'
|
|
30
|
+
import createIOC from './ioc'
|
|
31
|
+
import attachPlugins from './plugins/attach'
|
|
3
32
|
|
|
4
33
|
const createExodus = ({ adapters, config, port }) => {
|
|
5
34
|
const ioc = createIOC({ adapters, config })
|
|
35
|
+
const { headless: headlessConfig, topMoversMonitor } = config
|
|
36
|
+
|
|
37
|
+
ioc.use(wallet())
|
|
38
|
+
ioc.use(keychain(config.keychain))
|
|
39
|
+
ioc.use(walletAccounts())
|
|
40
|
+
ioc.use(blockchainMetadata())
|
|
41
|
+
ioc.use(availableAssets())
|
|
42
|
+
ioc.use(enabledAssets())
|
|
43
|
+
ioc.use(balances())
|
|
44
|
+
ioc.use(fiatBalances())
|
|
45
|
+
ioc.use(remoteConfig())
|
|
46
|
+
ioc.use(geolocation())
|
|
47
|
+
ioc.use(marketHistory())
|
|
48
|
+
ioc.use(pricing())
|
|
49
|
+
ioc.use(fees())
|
|
50
|
+
ioc.use(rates())
|
|
51
|
+
ioc.use(apyRates())
|
|
52
|
+
ioc.use(featureFlags())
|
|
53
|
+
ioc.use(locale())
|
|
54
|
+
ioc.use(nfts())
|
|
55
|
+
ioc.use(kyc())
|
|
56
|
+
ioc.use(connectedOrigins())
|
|
57
|
+
ioc.use(abTesting())
|
|
58
|
+
ioc.use(cryptoNews())
|
|
59
|
+
ioc.use(topMovers({ config: topMoversMonitor }))
|
|
60
|
+
ioc.use(addressProvider({ config: config.addressProvider }))
|
|
61
|
+
|
|
62
|
+
ioc.register({ definition: { id: 'port', type: 'port', factory: () => port } })
|
|
6
63
|
|
|
7
64
|
const resolve = () => {
|
|
8
65
|
ioc.resolve()
|
|
9
66
|
|
|
10
67
|
const { assetsModule, storage } = ioc.getByType('adapter')
|
|
11
68
|
|
|
12
|
-
const { application,
|
|
69
|
+
const { application, wallet, unlockEncryptedStorage } = ioc.getByType('module')
|
|
13
70
|
|
|
14
|
-
application.hook('start', () =>
|
|
15
|
-
|
|
71
|
+
application.hook('start', (payload) => port.emit('start', payload))
|
|
72
|
+
|
|
73
|
+
application.on('load', (args) => port.emit('load', args))
|
|
74
|
+
|
|
75
|
+
application.on('create', async ({ hasPassphraseSet }) => {
|
|
76
|
+
const isLocked = await wallet.isLocked()
|
|
77
|
+
|
|
78
|
+
port.emit('create', {
|
|
79
|
+
walletExists: true,
|
|
80
|
+
hasPassphraseSet,
|
|
81
|
+
isLocked,
|
|
82
|
+
isBackedUp: false,
|
|
83
|
+
isRestoring: false,
|
|
84
|
+
})
|
|
16
85
|
})
|
|
17
86
|
|
|
87
|
+
application.on('unlock', () => port.emit('unlock'))
|
|
88
|
+
|
|
89
|
+
application.on('lock', () => port.emit('lock'))
|
|
90
|
+
|
|
91
|
+
application.on('backup', () => port.emit('backup'))
|
|
92
|
+
|
|
93
|
+
application.on('restore', () => port.emit('restore'))
|
|
94
|
+
|
|
95
|
+
application.on('restore-completed', () => port.emit('restore-completed'))
|
|
96
|
+
|
|
97
|
+
application.on('change-passphrase', () => port.emit('passphrase-changed'))
|
|
98
|
+
|
|
99
|
+
application.on('import', () => port.emit('import', { walletExists: true }))
|
|
100
|
+
|
|
18
101
|
application.hook('unlock', async () => {
|
|
19
102
|
if (typeof storage.unlock === 'function') unlockEncryptedStorage(storage)
|
|
20
103
|
|
|
21
104
|
await assetsModule.load()
|
|
22
|
-
await walletAccounts.load()
|
|
23
105
|
})
|
|
24
106
|
|
|
25
|
-
application.
|
|
26
|
-
|
|
107
|
+
application.hook('clear', async () => {
|
|
108
|
+
await assetsModule.clear()
|
|
27
109
|
})
|
|
28
110
|
|
|
29
|
-
application.
|
|
30
|
-
await Promise.all([
|
|
31
|
-
//
|
|
32
|
-
assetsModule.clear(),
|
|
33
|
-
walletAccounts.clear(),
|
|
34
|
-
])
|
|
111
|
+
application.on('clear', () => port.emit('clear'))
|
|
35
112
|
|
|
36
|
-
|
|
37
|
-
})
|
|
113
|
+
application.on('restart', (payload) => port.emit('restart', payload))
|
|
38
114
|
|
|
39
|
-
|
|
40
|
-
port
|
|
115
|
+
attachAtoms({
|
|
116
|
+
port,
|
|
117
|
+
application,
|
|
118
|
+
logger: ioc.get('createLogger')('attachAtoms'),
|
|
119
|
+
atoms: pick(ioc.getByType('atom'), atomsToAttach),
|
|
120
|
+
lifecycleEvents: headlessConfig?.attachAtomsLifecycleEvents,
|
|
41
121
|
})
|
|
42
122
|
|
|
43
|
-
|
|
123
|
+
attachPlugins({
|
|
124
|
+
application,
|
|
125
|
+
plugins: ioc.getByType('plugin'),
|
|
126
|
+
logger: ioc.get('createLogger')('attachPlugins'),
|
|
127
|
+
})
|
|
44
128
|
|
|
45
129
|
return createApi({ ioc, port })
|
|
46
130
|
}
|
package/src/ioc.js
CHANGED
|
@@ -1,23 +1,56 @@
|
|
|
1
1
|
import createIocContainer from '@exodus/dependency-injection'
|
|
2
2
|
import preprocess from '@exodus/dependency-preprocessors'
|
|
3
3
|
import alias from '@exodus/dependency-preprocessors/src/preprocessors/alias'
|
|
4
|
+
import devModeAtoms from '@exodus/dependency-preprocessors/src/preprocessors/dev-mode-atoms'
|
|
4
5
|
import logify from '@exodus/dependency-preprocessors/src/preprocessors/logify'
|
|
5
6
|
import namespaceConfig from '@exodus/dependency-preprocessors/src/preprocessors/namespace-config'
|
|
7
|
+
import namespaceStorage from '@exodus/dependency-preprocessors/src/preprocessors/namespace-storage'
|
|
8
|
+
import optional from '@exodus/dependency-preprocessors/src/preprocessors/optional'
|
|
9
|
+
import readOnlyAtoms from '@exodus/dependency-preprocessors/src/preprocessors/read-only-atoms'
|
|
10
|
+
import assert from 'minimalistic-assert'
|
|
6
11
|
|
|
7
12
|
import createDependencies from './dependencies'
|
|
8
13
|
|
|
9
14
|
const createIOC = ({ adapters, config }) => {
|
|
10
15
|
const { createLogger } = adapters
|
|
16
|
+
const { readOnlyAtoms: readOnlyAtomsConfig, devModeAtoms: devModeAtomsConfig } = config.ioc ?? {}
|
|
11
17
|
|
|
12
|
-
const
|
|
13
|
-
const dependencies = createDependencies({ adapters, config })
|
|
14
|
-
const preprocessors = [logify({ createLogger }), namespaceConfig(), alias()]
|
|
15
|
-
const definitions = preprocess({ dependencies, preprocessors })
|
|
16
|
-
const ioc = createIocContainer({ logger })
|
|
18
|
+
const ioc = createIocContainer({ logger: createLogger('exodus:ioc') })
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
const preprocessors = [
|
|
21
|
+
logify({ createLogger }),
|
|
22
|
+
namespaceConfig(),
|
|
23
|
+
alias(),
|
|
24
|
+
// NOTE: order matters, this should come after `alias`
|
|
25
|
+
namespaceStorage(),
|
|
26
|
+
readOnlyAtoms({
|
|
27
|
+
logger: createLogger('exodus:read-only-atoms'),
|
|
28
|
+
warn: true,
|
|
29
|
+
...readOnlyAtomsConfig,
|
|
30
|
+
}),
|
|
31
|
+
optional(),
|
|
32
|
+
...(devModeAtomsConfig ? [devModeAtoms(devModeAtomsConfig)] : []),
|
|
33
|
+
]
|
|
19
34
|
|
|
20
|
-
|
|
35
|
+
const registerMultiple = (dependencies) => {
|
|
36
|
+
ioc.registerMultiple(preprocess({ dependencies, preprocessors }))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const register = (dependency) => {
|
|
40
|
+
registerMultiple([dependency])
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const use = (module) => {
|
|
44
|
+
for (const { definition } of module.definitions) {
|
|
45
|
+
assert(definition.type, `ioc.use: "${definition.id}" is missing type field`)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
registerMultiple(module.definitions)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
registerMultiple(createDependencies({ adapters, config }))
|
|
52
|
+
|
|
53
|
+
return { ...ioc, register, registerMultiple, use }
|
|
21
54
|
}
|
|
22
55
|
|
|
23
56
|
export default createIOC
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { LifecycleHook } from '../constants'
|
|
2
|
+
|
|
3
|
+
const LIFECYCLE_METHOD_TO_HOOK_NAME = Object.fromEntries(
|
|
4
|
+
Object.entries(LifecycleHook).map(([pascalCaseName, hookName]) => [
|
|
5
|
+
`on${pascalCaseName}`,
|
|
6
|
+
hookName,
|
|
7
|
+
])
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
const attachPlugins = ({ plugins, application, logger }) => {
|
|
11
|
+
Object.entries(plugins).forEach(([name, lifecycleMethods]) => {
|
|
12
|
+
const entries = Object.entries(lifecycleMethods || {})
|
|
13
|
+
|
|
14
|
+
for (const [lifecycleMethod, fn] of entries) {
|
|
15
|
+
const hookName = LIFECYCLE_METHOD_TO_HOOK_NAME[lifecycleMethod]
|
|
16
|
+
if (hookName) {
|
|
17
|
+
application.hook(hookName, fn)
|
|
18
|
+
} else {
|
|
19
|
+
logger.error(`plugin "${name}" declares unsupported lifecycle method "${lifecycleMethod}"`)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default attachPlugins
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const logLifecycle = {
|
|
2
|
+
id: 'logLifecyclePlugin',
|
|
3
|
+
type: 'plugin',
|
|
4
|
+
factory: ({ logger }) => {
|
|
5
|
+
return {
|
|
6
|
+
onLock: () => logger.debug('onLock'),
|
|
7
|
+
onUnlock: () => logger.debug('onUnlock'),
|
|
8
|
+
onClear: () => logger.debug('onClear'),
|
|
9
|
+
onImport: () => logger.debug('onImport'),
|
|
10
|
+
onMigrate: () => logger.debug('onMigrate'),
|
|
11
|
+
onStart: () => logger.debug('onStart'),
|
|
12
|
+
onRestart: () => logger.debug('onRestart'),
|
|
13
|
+
onLoad: () => logger.debug('onLoad'),
|
|
14
|
+
onUnload: () => logger.debug('onUnload'),
|
|
15
|
+
onCreate: () => logger.debug('onCreate'),
|
|
16
|
+
onBackup: () => logger.debug('onBackup'),
|
|
17
|
+
onRestore: () => logger.debug('onRestore'),
|
|
18
|
+
onRestoreCompleted: () => logger.debug('onRestoreCompleted'),
|
|
19
|
+
onAssetsSynced: () => logger.debug('onAssetsSynced'),
|
|
20
|
+
onChangePassphrase: () => logger.debug('onChangePassphrase'),
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
dependencies: ['logger'],
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default logLifecycle
|