-
Notifications
You must be signed in to change notification settings - Fork 393
Add functionality to accept a JSON template string when initializing a RC server template #2520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
43e0f2e
dac5893
de597ee
0608aaf
e926fcd
48fe8a2
295636b
9ae7d96
c7d4c6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ import { | |
GetServerTemplateOptions, | ||
InitServerTemplateOptions, | ||
} from './remote-config-api'; | ||
import { isString } from 'lodash'; | ||
|
||
/** | ||
* The Firebase `RemoteConfig` service interface. | ||
|
@@ -198,7 +199,19 @@ export class RemoteConfig { | |
const template = new ServerTemplateImpl( | ||
this.client, new ConditionEvaluator(), options?.defaultConfig); | ||
if (options?.template) { | ||
template.cache = options?.template; | ||
// Check and instantiates the template via a json string | ||
if (isString(options?.template)) { | ||
try { | ||
template.cache = new ServerTemplateDataImpl(JSON.parse(options?.template)); | ||
} catch (e) { | ||
throw new FirebaseRemoteConfigError( | ||
'invalid-argument', | ||
`Failed to parse the JSON string: ${options?.template}. ` + e | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the other errors we throw, we don't include the raw error ( Nit: If we do include the error, it might be more readable to differentiate it from the other error message, something like "... Raw error: ${e}". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't include it for most errors, but we do have it for the createTemplateFromJSON: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah. I overlooked that. Makes sense. Shipit 🚢 |
||
); | ||
} | ||
} else { | ||
template.cache = options?.template; | ||
} | ||
} | ||
return template; | ||
} | ||
|
@@ -430,7 +443,6 @@ class ServerTemplateDataImpl implements ServerTemplateData { | |
} | ||
|
||
this.etag = template.etag; | ||
|
||
if (typeof template.parameters !== 'undefined') { | ||
if (!validator.isNonNullObject(template.parameters)) { | ||
throw new FirebaseRemoteConfigError( | ||
|
Uh oh!
There was an error while loading. Please reload this page.