remote-config-api.d.ts 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. /*! firebase-admin v12.1.1 */
  2. /*!
  3. * Copyright 2021 Google Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /**
  18. * Colors that are associated with conditions for display purposes.
  19. */
  20. export type TagColor = 'BLUE' | 'BROWN' | 'CYAN' | 'DEEP_ORANGE' | 'GREEN' | 'INDIGO' | 'LIME' | 'ORANGE' | 'PINK' | 'PURPLE' | 'TEAL';
  21. /**
  22. * Type representing a Remote Config parameter value data type.
  23. * Defaults to `STRING` if unspecified.
  24. */
  25. export type ParameterValueType = 'STRING' | 'BOOLEAN' | 'NUMBER' | 'JSON';
  26. /**
  27. * Interface representing a Remote Config condition.
  28. * A condition targets a specific group of users. A list of these conditions make up
  29. * part of a Remote Config template.
  30. */
  31. export interface RemoteConfigCondition {
  32. /**
  33. * A non-empty and unique name of this condition.
  34. */
  35. name: string;
  36. /**
  37. * The logic of this condition.
  38. * See the documentation on
  39. * {@link https://firebase.google.com/docs/remote-config/condition-reference | condition expressions}
  40. * for the expected syntax of this field.
  41. */
  42. expression: string;
  43. /**
  44. * The color associated with this condition for display purposes in the Firebase Console.
  45. * Not specifying this value results in the console picking an arbitrary color to associate
  46. * with the condition.
  47. */
  48. tagColor?: TagColor;
  49. }
  50. /**
  51. * Represents a Remote Config condition in the dataplane.
  52. * A condition targets a specific group of users. A list of these conditions
  53. * comprise part of a Remote Config template.
  54. */
  55. export interface NamedCondition {
  56. /**
  57. * A non-empty and unique name of this condition.
  58. */
  59. name: string;
  60. /**
  61. * The logic of this condition.
  62. * See the documentation on
  63. * {@link https://firebase.google.com/docs/remote-config/condition-reference | condition expressions}
  64. * for the expected syntax of this field.
  65. */
  66. condition: OneOfCondition;
  67. }
  68. /**
  69. * Represents a condition that may be one of several types.
  70. * Only the first defined field will be processed.
  71. */
  72. export interface OneOfCondition {
  73. /**
  74. * Makes this condition an OR condition.
  75. */
  76. orCondition?: OrCondition;
  77. /**
  78. * Makes this condition an AND condition.
  79. */
  80. andCondition?: AndCondition;
  81. /**
  82. * Makes this condition a constant true.
  83. */
  84. true?: Record<string, never>;
  85. /**
  86. * Makes this condition a constant false.
  87. */
  88. false?: Record<string, never>;
  89. /**
  90. * Makes this condition a percent condition.
  91. */
  92. percent?: PercentCondition;
  93. }
  94. /**
  95. * Represents a collection of conditions that evaluate to true if all are true.
  96. */
  97. export interface AndCondition {
  98. /**
  99. * The collection of conditions.
  100. */
  101. conditions?: Array<OneOfCondition>;
  102. }
  103. /**
  104. * Represents a collection of conditions that evaluate to true if any are true.
  105. */
  106. export interface OrCondition {
  107. /**
  108. * The collection of conditions.
  109. */
  110. conditions?: Array<OneOfCondition>;
  111. }
  112. /**
  113. * Defines supported operators for percent conditions.
  114. */
  115. export declare enum PercentConditionOperator {
  116. /**
  117. * A catchall error case.
  118. */
  119. UNKNOWN = "UNKNOWN",
  120. /**
  121. * Target percentiles less than or equal to the target percent.
  122. * A condition using this operator must specify microPercent.
  123. */
  124. LESS_OR_EQUAL = "LESS_OR_EQUAL",
  125. /**
  126. * Target percentiles greater than the target percent.
  127. * A condition using this operator must specify microPercent.
  128. */
  129. GREATER_THAN = "GREATER_THAN",
  130. /**
  131. * Target percentiles within an interval defined by a lower bound and an
  132. * upper bound. The lower bound is an exclusive (open) bound and the
  133. * micro_percent_range_upper_bound is an inclusive (closed) bound.
  134. * A condition using this operator must specify microPercentRange.
  135. */
  136. BETWEEN = "BETWEEN"
  137. }
  138. /**
  139. * Represents the limit of percentiles to target in micro-percents.
  140. * The value must be in the range [0 and 100000000]
  141. */
  142. export interface MicroPercentRange {
  143. /**
  144. * The lower limit of percentiles to target in micro-percents.
  145. * The value must be in the range [0 and 100000000].
  146. */
  147. microPercentLowerBound?: number;
  148. /**
  149. * The upper limit of percentiles to target in micro-percents.
  150. * The value must be in the range [0 and 100000000].
  151. */
  152. microPercentUpperBound?: number;
  153. }
  154. /**
  155. * Represents a condition that compares the instance pseudo-random
  156. * percentile to a given limit.
  157. */
  158. export interface PercentCondition {
  159. /**
  160. * The choice of percent operator to determine how to compare targets
  161. * to percent(s).
  162. */
  163. percentOperator?: PercentConditionOperator;
  164. /**
  165. * The limit of percentiles to target in micro-percents when
  166. * using the LESS_OR_EQUAL and GREATER_THAN operators. The value must
  167. * be in the range [0 and 100000000].
  168. */
  169. microPercent?: number;
  170. /**
  171. * The seed used when evaluating the hash function to map an instance to
  172. * a value in the hash space. This is a string which can have 0 - 32
  173. * characters and can contain ASCII characters [-_.0-9a-zA-Z].The string
  174. * is case-sensitive.
  175. */
  176. seed?: string;
  177. /**
  178. * The micro-percent interval to be used with the
  179. * BETWEEN operator.
  180. */
  181. microPercentRange?: MicroPercentRange;
  182. }
  183. /**
  184. * Interface representing an explicit parameter value.
  185. */
  186. export interface ExplicitParameterValue {
  187. /**
  188. * The `string` value that the parameter is set to.
  189. */
  190. value: string;
  191. }
  192. /**
  193. * Interface representing an in-app-default value.
  194. */
  195. export interface InAppDefaultValue {
  196. /**
  197. * If `true`, the parameter is omitted from the parameter values returned to a client.
  198. */
  199. useInAppDefault: boolean;
  200. }
  201. /**
  202. * Type representing a Remote Config parameter value.
  203. * A `RemoteConfigParameterValue` could be either an `ExplicitParameterValue` or
  204. * an `InAppDefaultValue`.
  205. */
  206. export type RemoteConfigParameterValue = ExplicitParameterValue | InAppDefaultValue;
  207. /**
  208. * Interface representing a Remote Config parameter.
  209. * At minimum, a `defaultValue` or a `conditionalValues` entry must be present for the
  210. * parameter to have any effect.
  211. */
  212. export interface RemoteConfigParameter {
  213. /**
  214. * The value to set the parameter to, when none of the named conditions evaluate to `true`.
  215. */
  216. defaultValue?: RemoteConfigParameterValue;
  217. /**
  218. * A `(condition name, value)` map. The condition name of the highest priority
  219. * (the one listed first in the Remote Config template's conditions list) determines the value of
  220. * this parameter.
  221. */
  222. conditionalValues?: {
  223. [key: string]: RemoteConfigParameterValue;
  224. };
  225. /**
  226. * A description for this parameter. Should not be over 100 characters and may contain any
  227. * Unicode characters.
  228. */
  229. description?: string;
  230. /**
  231. * The data type for all values of this parameter in the current version of the template.
  232. * Defaults to `ParameterValueType.STRING` if unspecified.
  233. */
  234. valueType?: ParameterValueType;
  235. }
  236. /**
  237. * Interface representing a Remote Config parameter group.
  238. * Grouping parameters is only for management purposes and does not affect client-side
  239. * fetching of parameter values.
  240. */
  241. export interface RemoteConfigParameterGroup {
  242. /**
  243. * A description for the group. Its length must be less than or equal to 256 characters.
  244. * A description may contain any Unicode characters.
  245. */
  246. description?: string;
  247. /**
  248. * Map of parameter keys to their optional default values and optional conditional values for
  249. * parameters that belong to this group. A parameter only appears once per
  250. * Remote Config template. An ungrouped parameter appears at the top level, whereas a
  251. * parameter organized within a group appears within its group's map of parameters.
  252. */
  253. parameters: {
  254. [key: string]: RemoteConfigParameter;
  255. };
  256. }
  257. /**
  258. * Represents a Remote Config client template.
  259. */
  260. export interface RemoteConfigTemplate {
  261. /**
  262. * A list of conditions in descending order by priority.
  263. */
  264. conditions: RemoteConfigCondition[];
  265. /**
  266. * Map of parameter keys to their optional default values and optional conditional values.
  267. */
  268. parameters: {
  269. [key: string]: RemoteConfigParameter;
  270. };
  271. /**
  272. * Map of parameter group names to their parameter group objects.
  273. * A group's name is mutable but must be unique among groups in the Remote Config template.
  274. * The name is limited to 256 characters and intended to be human-readable. Any Unicode
  275. * characters are allowed.
  276. */
  277. parameterGroups: {
  278. [key: string]: RemoteConfigParameterGroup;
  279. };
  280. /**
  281. * ETag of the current Remote Config template (readonly).
  282. */
  283. readonly etag: string;
  284. /**
  285. * Version information for the current Remote Config template.
  286. */
  287. version?: Version;
  288. }
  289. /**
  290. * Represents the data in a Remote Config server template.
  291. */
  292. export interface ServerTemplateData {
  293. /**
  294. * A list of conditions in descending order by priority.
  295. */
  296. conditions: NamedCondition[];
  297. /**
  298. * Map of parameter keys to their optional default values and optional conditional values.
  299. */
  300. parameters: {
  301. [key: string]: RemoteConfigParameter;
  302. };
  303. /**
  304. * Current Remote Config template ETag (read-only).
  305. */
  306. readonly etag: string;
  307. /**
  308. * Version information for the current Remote Config template.
  309. */
  310. version?: Version;
  311. }
  312. /**
  313. * Represents optional arguments that can be used when instantiating {@link ServerTemplate}.
  314. */
  315. export interface GetServerTemplateOptions {
  316. /**
  317. * Defines in-app default parameter values, so that your app behaves as
  318. * intended before it connects to the Remote Config backend, and so that
  319. * default values are available if none are set on the backend.
  320. */
  321. defaultConfig?: DefaultConfig;
  322. }
  323. /**
  324. * Represents the type of a Remote Config server template that can be set on
  325. * {@link ServerTemplate}. This can either be a {@link ServerTemplateData} object
  326. * or a template JSON string.
  327. */
  328. export type ServerTemplateDataType = ServerTemplateData | string;
  329. /**
  330. * Represents optional arguments that can be used when instantiating
  331. * {@link ServerTemplate} synchronously.
  332. */
  333. export interface InitServerTemplateOptions extends GetServerTemplateOptions {
  334. /**
  335. * Enables integrations to use template data loaded independently. For
  336. * example, customers can reduce initialization latency by pre-fetching and
  337. * caching template data and then using this option to initialize the SDK with
  338. * that data.
  339. */
  340. template?: ServerTemplateDataType;
  341. }
  342. /**
  343. * Represents a stateful abstraction for a Remote Config server template.
  344. */
  345. export interface ServerTemplate {
  346. /**
  347. * Evaluates the current template to produce a {@link ServerConfig}.
  348. */
  349. evaluate(context?: EvaluationContext): ServerConfig;
  350. /**
  351. * Fetches and caches the current active version of the
  352. * project's {@link ServerTemplate}.
  353. */
  354. load(): Promise<void>;
  355. /**
  356. * Sets and caches a {@link ServerTemplateData} or a JSON string representing
  357. * the server template
  358. */
  359. set(template: ServerTemplateDataType): void;
  360. /**
  361. * Returns a JSON representation of {@link ServerTemplateData}
  362. */
  363. toJSON(): ServerTemplateData;
  364. }
  365. /**
  366. * Represents template evaluation input signals.
  367. */
  368. export type EvaluationContext = {
  369. /**
  370. * Defines the identifier to use when splitting a group. For example,
  371. * this is used by the percent condition.
  372. */
  373. randomizationId?: string;
  374. };
  375. /**
  376. * Interface representing a Remote Config user.
  377. */
  378. export interface RemoteConfigUser {
  379. /**
  380. * Email address. Output only.
  381. */
  382. email: string;
  383. /**
  384. * Display name. Output only.
  385. */
  386. name?: string;
  387. /**
  388. * Image URL. Output only.
  389. */
  390. imageUrl?: string;
  391. }
  392. /**
  393. * Interface representing a Remote Config template version.
  394. * Output only, except for the version description. Contains metadata about a particular
  395. * version of the Remote Config template. All fields are set at the time the specified Remote
  396. * Config template is published. A version's description field may be specified in
  397. * `publishTemplate` calls.
  398. */
  399. export interface Version {
  400. /**
  401. * The version number of a Remote Config template.
  402. */
  403. versionNumber?: string;
  404. /**
  405. * The timestamp of when this version of the Remote Config template was written to the
  406. * Remote Config backend.
  407. */
  408. updateTime?: string;
  409. /**
  410. * The origin of the template update action.
  411. */
  412. updateOrigin?: ('REMOTE_CONFIG_UPDATE_ORIGIN_UNSPECIFIED' | 'CONSOLE' | 'REST_API' | 'ADMIN_SDK_NODE');
  413. /**
  414. * The type of the template update action.
  415. */
  416. updateType?: ('REMOTE_CONFIG_UPDATE_TYPE_UNSPECIFIED' | 'INCREMENTAL_UPDATE' | 'FORCED_UPDATE' | 'ROLLBACK');
  417. /**
  418. * Aggregation of all metadata fields about the account that performed the update.
  419. */
  420. updateUser?: RemoteConfigUser;
  421. /**
  422. * The user-provided description of the corresponding Remote Config template.
  423. */
  424. description?: string;
  425. /**
  426. * The version number of the Remote Config template that has become the current version
  427. * due to a rollback. Only present if this version is the result of a rollback.
  428. */
  429. rollbackSource?: string;
  430. /**
  431. * Indicates whether this Remote Config template was published before version history was
  432. * supported.
  433. */
  434. isLegacy?: boolean;
  435. }
  436. /**
  437. * Interface representing a list of Remote Config template versions.
  438. */
  439. export interface ListVersionsResult {
  440. /**
  441. * A list of version metadata objects, sorted in reverse chronological order.
  442. */
  443. versions: Version[];
  444. /**
  445. * Token to retrieve the next page of results, or empty if there are no more results
  446. * in the list.
  447. */
  448. nextPageToken?: string;
  449. }
  450. /**
  451. * Interface representing options for Remote Config list versions operation.
  452. */
  453. export interface ListVersionsOptions {
  454. /**
  455. * The maximum number of items to return per page.
  456. */
  457. pageSize?: number;
  458. /**
  459. * The `nextPageToken` value returned from a previous list versions request, if any.
  460. */
  461. pageToken?: string;
  462. /**
  463. * Specifies the newest version number to include in the results.
  464. * If specified, must be greater than zero. Defaults to the newest version.
  465. */
  466. endVersionNumber?: string | number;
  467. /**
  468. * Specifies the earliest update time to include in the results. Any entries updated before this
  469. * time are omitted.
  470. */
  471. startTime?: Date | string;
  472. /**
  473. * Specifies the latest update time to include in the results. Any entries updated on or after
  474. * this time are omitted.
  475. */
  476. endTime?: Date | string;
  477. }
  478. /**
  479. * Represents the configuration produced by evaluating a server template.
  480. */
  481. export interface ServerConfig {
  482. /**
  483. * Gets the value for the given key as a boolean.
  484. *
  485. * Convenience method for calling <code>serverConfig.getValue(key).asBoolean()</code>.
  486. *
  487. * @param key - The name of the parameter.
  488. *
  489. * @returns The value for the given key as a boolean.
  490. */
  491. getBoolean(key: string): boolean;
  492. /**
  493. * Gets the value for the given key as a number.
  494. *
  495. * Convenience method for calling <code>serverConfig.getValue(key).asNumber()</code>.
  496. *
  497. * @param key - The name of the parameter.
  498. *
  499. * @returns The value for the given key as a number.
  500. */
  501. getNumber(key: string): number;
  502. /**
  503. * Gets the value for the given key as a string.
  504. * Convenience method for calling <code>serverConfig.getValue(key).asString()</code>.
  505. *
  506. * @param key - The name of the parameter.
  507. *
  508. * @returns The value for the given key as a string.
  509. */
  510. getString(key: string): string;
  511. /**
  512. * Gets the {@link Value} for the given key.
  513. *
  514. * Ensures application logic will always have a type-safe reference,
  515. * even if the parameter is removed remotely.
  516. *
  517. * @param key - The name of the parameter.
  518. *
  519. * @returns The value for the given key.
  520. */
  521. getValue(key: string): Value;
  522. }
  523. /**
  524. * Wraps a parameter value with metadata and type-safe getters.
  525. *
  526. * Type-safe getters insulate application logic from remote
  527. * changes to parameter names and types.
  528. */
  529. export interface Value {
  530. /**
  531. * Gets the value as a boolean.
  532. *
  533. * The following values (case insensitive) are interpreted as true:
  534. * "1", "true", "t", "yes", "y", "on". Other values are interpreted as false.
  535. */
  536. asBoolean(): boolean;
  537. /**
  538. * Gets the value as a number. Comparable to calling <code>Number(value) || 0</code>.
  539. */
  540. asNumber(): number;
  541. /**
  542. * Gets the value as a string.
  543. */
  544. asString(): string;
  545. /**
  546. * Gets the {@link ValueSource} for the given key.
  547. */
  548. getSource(): ValueSource;
  549. }
  550. /**
  551. * Indicates the source of a value.
  552. *
  553. * <ul>
  554. * <li>"static" indicates the value was defined by a static constant.</li>
  555. * <li>"default" indicates the value was defined by default config.</li>
  556. * <li>"remote" indicates the value was defined by config produced by
  557. * evaluating a template.</li>
  558. * </ul>
  559. */
  560. export type ValueSource = 'static' | 'default' | 'remote';
  561. /**
  562. * Defines the format for in-app default parameter values.
  563. */
  564. export type DefaultConfig = {
  565. [key: string]: string | number | boolean;
  566. };