diff --git a/README.md b/README.md index 984a1872..b9f1cd04 100644 --- a/README.md +++ b/README.md @@ -74,9 +74,18 @@ modules: [ } }, // The following options are optional: - useOnly: ['auth','firestore','functions','storage','realtimeDb', 'messaging', 'performance', 'analytics'], + useOnly: ['auth','firestore','functions','storage','realtimeDb', 'messaging', 'performance', 'analytics', 'remoteConfig'], customEnv: false, functionsLocation: 'us-central1', + remoteConfig: { + settings: { + fetchTimeoutMillis: 60000, + minimumFetchIntervalMillis: 43200000, + }, + defaultConfig: { + 'welcome_message': 'Welcome' + } + } } ] ], @@ -108,21 +117,23 @@ Firebase products supported by nuxt-fire so far: | Messaging | \$fireMess | | Performance | \$firePerf | | Analytics | \$fireAnalytics | +| Remote Config | \$fireConfig | See [Firebase's official docs](https://firebase.google.com/docs/) for more usage information. You can further access the objects like so: -| Firebase Obj | Shortcut | -| -------------------- | ------------------ | -| firebase.auth | \$fireAuthObj | -| firebase.database | \$fireDbObj | -| firebase.firestore | \$fireStoreObj | -| firebase.storage | \$fireStorageObj | -| firebase.functions | \$fireFuncObj | -| firebase.messaging | \$fireMessObj | -| firebase.performance | \$firePerfObj | -| firebase.analytics | \$fireAnalyticsObj | +| Firebase Obj | Shortcut | +| ---------------------- | ------------------ | +| firebase.auth | \$fireAuthObj | +| firebase.database | \$fireDbObj | +| firebase.firestore | \$fireStoreObj | +| firebase.storage | \$fireStorageObj | +| firebase.functions | \$fireFuncObj | +| firebase.messaging | \$fireMessObj | +| firebase.performance | \$firePerfObj | +| firebase.analytics | \$fireAnalyticsObj | +| firebase.remoteConfig | \$fireConfigObj | ## Options @@ -131,7 +142,7 @@ You can further access the objects like so: By default, all supported Firebase products are loaded. If you only wish to load certain products (recommended!), add the `useOnly` option. - type: `Array` -- default: `['auth','firestore','functions','storage','realtimeDb', 'messaging', 'performance', 'analytics']` +- default: `['auth','firestore','functions','storage','realtimeDb', 'messaging', 'performance', 'analytics', 'remoteConfig']` - required: `false` #### config[environment] @@ -215,6 +226,20 @@ You can change the location with this option. More information [here](https://firebase.google.com/docs/functions/locations). +#### remoteConfig +You can custom the settings and default config. +```js +{ + settings: { + fetchTimeoutMillis: 60000, + minimumFetchIntervalMillis: 43200000, + }, + defaultConfig: { + 'welcome_message': 'Welcome' // you can add another default config here + } +} +``` + ## Examples Check out our [Demo](https://nuxt-fire-demo.firebaseapp.com/) or its [GitHub Repo](https://github.com/lupas/nuxt-fire-demo) for example code. diff --git a/index.d.ts b/index.d.ts index 889ee328..d1d2b1ee 100644 --- a/index.d.ts +++ b/index.d.ts @@ -12,5 +12,6 @@ declare module 'vue/types/vue' { $fireMess: firebase.messaging.Messaging $fireAnalytics: firebase.analytics.Analytics $firePerf: firebase.performance.Performance + $fireConfig: firebase.remoteConfig.RemoteConfig } } diff --git a/plugin.js b/plugin.js index a2431f78..7d5f6bc1 100644 --- a/plugin.js +++ b/plugin.js @@ -10,7 +10,7 @@ export default async (ctx, inject) => { } if (options.useOnly.includes('auth')) { - <%= options.useOnly.includes('auth') ? "await import('firebase/auth')" : "" %> + await import('firebase/auth') const fireAuth = firebase.auth() const fireAuthObj = firebase.auth @@ -19,7 +19,7 @@ export default async (ctx, inject) => { } if (options.useOnly.includes('realtimeDb')) { - <%= options.useOnly.includes('realtimeDb') ? "await import('firebase/database')" : "" %> + await import('firebase/database') const fireDb = firebase.database() const fireDbObj = firebase.database @@ -28,7 +28,7 @@ export default async (ctx, inject) => { } if (options.useOnly.includes('firestore')) { - <%= options.useOnly.includes('firestore') ? "await import('firebase/firestore')" : "" %> + await import('firebase/firestore') const fireStore = firebase.firestore() const fireStoreObj = firebase.firestore @@ -37,7 +37,7 @@ export default async (ctx, inject) => { } if (options.useOnly.includes('storage')) { - <%= options.useOnly.includes('storage') ? "await import('firebase/storage')" : "" %> + await import('firebase/storage') const fireStorage = firebase.storage() const fireStorageObj = firebase.storage @@ -46,7 +46,7 @@ export default async (ctx, inject) => { } if (options.useOnly.includes('functions')) { - <%= options.useOnly.includes('functions') ? "await import('firebase/functions')" : "" %> + await import('firebase/functions') const fireFunc = firebase.app().functions(options.functionsLocation) const fireFuncObj = firebase.functions @@ -56,7 +56,7 @@ export default async (ctx, inject) => { // Firebase Messaging can only be initiated on client side if (process.browser && options.useOnly.includes('messaging')) { - <%= options.useOnly.includes('messaging') ? "await import('firebase/messaging')" : "" %> + await import('firebase/messaging') if (firebase.messaging.isSupported()) { const fireMess = firebase.messaging() @@ -68,7 +68,7 @@ export default async (ctx, inject) => { // Firebase Performance can only be initiated on client side if(process.browser && options.useOnly.includes('performance')){ - <%= options.useOnly.includes('performance') ? "await import('firebase/performance')" : "" %> + await import('firebase/performance') const firePerf = firebase.performance() const firePerfObj = firebase.performance @@ -78,11 +78,34 @@ export default async (ctx, inject) => { // Firebase Analytics can only be initiated on the client side if(process.browser && options.useOnly.includes('analytics')) { - <%= options.useOnly.includes('analytics') ? "await import('firebase/analytics')" : "" %> + await import('firebase/analytics') const fireAnalytics = firebase.analytics() const fireAnalyticsObj = firebase.analytics inject('fireAnalytics', fireAnalytics) inject('fireAnalyticsObj', fireAnalyticsObj) } + + // Firebase Remote Config can only be initiated on the client side + if(process.browser && options.useOnly.includes('remoteConfig')) { + await import('firebase/remote-config') + + const fireConfig = firebase.remoteConfig() + const fireConfigObj = firebase.remoteConfig + + if (options.remoteConfig) { + const { settings: remoteSettings, defaultConfig: remoteDefaultConfig } = options.remoteConfig + if (remoteSettings) { + const { minimumFetchIntervalMillis, fetchTimeoutMillis } = remoteSettings + fireConfig.settings = { + fetchTimeoutMillis: fetchTimeoutMillis ? fetchTimeoutMillis : 60000, + minimumFetchIntervalMillis: minimumFetchIntervalMillis ? minimumFetchIntervalMillis : 43200000 + } + } + fireConfig.defaultConfig = (remoteDefaultConfig) + } + + inject('fireConfig', fireConfig) + inject('fireConfigObj', fireConfigObj) + } }