|
| 1 | +import objectAssign from 'object-assign'; |
| 2 | +import { merge } from "../../../src/utils/lang/index.js"; |
| 3 | + |
| 4 | +const base = { |
| 5 | + core:{ |
| 6 | + sdkKey:'', |
| 7 | + host:'http://app.unlaunch.io/' |
| 8 | + }, |
| 9 | + intervals: { |
| 10 | + // fetch feature updates each 30 sec |
| 11 | + pollingInterval: 30, |
| 12 | + // publish metrics each 120 sec |
| 13 | + metricsFlushInterval: 120, |
| 14 | + // flush events every 60 seconds after the first flush |
| 15 | + eventsFlushInterval: 60, |
| 16 | + // http connection timeout |
| 17 | + httpConnectionTimeout: 10 |
| 18 | + }, |
| 19 | + mode: { |
| 20 | + offlineMode: false |
| 21 | + }, |
| 22 | + |
| 23 | + urls: { |
| 24 | + // CDN having all the information for your environment |
| 25 | + sdk: '/api/v1/flags', |
| 26 | + // Storage for your SDK events |
| 27 | + events: '/api/v1/events' |
| 28 | + }, |
| 29 | + |
| 30 | +}; |
| 31 | + |
| 32 | +function fromSecondsToMillis(n) { |
| 33 | + return Math.round(n * 1000); |
| 34 | +} |
| 35 | + |
| 36 | +function defaults(custom) { |
| 37 | + const withDefaults = merge(base, custom); |
| 38 | + |
| 39 | + // // Scheduler periods |
| 40 | + withDefaults.intervals.pollingInterval = fromSecondsToMillis(withDefaults.intervals.pollingInterval); |
| 41 | + withDefaults.intervals.metricsFlushInterval = fromSecondsToMillis(withDefaults.intervals.metricsFlushInterval); |
| 42 | + withDefaults.intervals.httpConnectionTimeout = fromSecondsToMillis(withDefaults.intervals.httpConnectionTimeout); |
| 43 | + withDefaults.intervals.eventsFlushInterval = fromSecondsToMillis(withDefaults.intervals.eventsFlushInterval); |
| 44 | + |
| 45 | + // // mode |
| 46 | + // withDefaults.mode.offlineMode = false; |
| 47 | + |
| 48 | + // Startup periods |
| 49 | + // withDefaults.startup.requestTimeoutBeforeReady = fromSecondsToMillis(withDefaults.startup.requestTimeoutBeforeReady); |
| 50 | + // withDefaults.startup.readyTimeout = fromSecondsToMillis(withDefaults.startup.readyTimeout); |
| 51 | + // withDefaults.startup.eventsFirstPushWindow = fromSecondsToMillis(withDefaults.startup.eventsFirstPushWindow); |
| 52 | + |
| 53 | + return withDefaults; |
| 54 | +} |
| 55 | + |
| 56 | +export const ConfigsFactory = (configurations) => objectAssign(Object.create({}), defaults(configurations)); |
0 commit comments