Bug 1458827 - Add more information about RemoteSettings for developers r?glasserc,Gijs draft
authorMathieu Leplatre <mathieu@mozilla.com>
Thu, 03 May 2018 18:54:40 +0200
changeset 791167 dd5b5e210d0e39908036b85c403583ca243ab189
parent 790505 87bd488c19f620d726b8363d47c8a320bae9bb7c
child 792081 5af8ff44b9a09820c944f767cdf7e9aad6f6d458
push id108717
push usermleplatre@mozilla.com
push dateThu, 03 May 2018 16:55:03 +0000
reviewersglasserc, Gijs
bugs1458827
milestone61.0a1
Bug 1458827 - Add more information about RemoteSettings for developers r?glasserc,Gijs MozReview-Commit-ID: 7LEZa6ICBB5
services/common/docs/RemoteSettings.rst
--- a/services/common/docs/RemoteSettings.rst
+++ b/services/common/docs/RemoteSettings.rst
@@ -38,17 +38,17 @@ Options
 -------
 
 The list can optionally be filtered or ordered:
 
 .. code-block:: js
 
     const subset = await RemoteSettings("a-key").get({
       filters: {
-        "enabled": true,
+        "property": "value"
       },
       order: "-weight"
     });
 
 Events
 ------
 
 The ``change`` event allows to be notified when the remote settings are changed. The event ``data`` attribute contains the whole new list of settings.
@@ -102,8 +102,109 @@ It basically consists in:
 #. Assigning collaborators to editors and reviewers groups
 #. (*optional*) Define a JSONSchema to validate entries
 #. (*optional*) Allow attachments on entries
 
 And once done:
 
 #. Create, modify or delete entries and let reviewers approve the changes
 #. Wait for Firefox to pick-up the changes for your settings key
+
+
+Debugging and testing
+=====================
+
+Trigger a synchronization manually
+----------------------------------
+
+The synchronization of every known remote settings clients can be triggered manually with ``pollChanges()``:
+
+.. code-block:: js
+
+    RemoteSettings.pollChanges()
+
+The synchronization of a single client can be forced with ``maybeSync()``:
+
+.. code-block:: js
+
+    const fakeTimestamp = Infinity;
+    const fakeServerTime = Date.now();
+
+    await RemoteSettings("a-key").maybeSync(fakeTimestamp, fakeServerTime)
+
+
+Manipulate local data
+---------------------
+
+A handle on the local collection can be obtained with ``openCollection()``.
+
+.. code-block:: js
+
+    const collection = await RemoteSettings("a-key").openCollection();
+
+And records can be created manually (as if they were synchronized from the server):
+
+.. code-block:: js
+
+    const record = await collection.create({
+      domain: "website.com",
+      usernameSelector: "#login-account",
+      passwordSelector: "#pass-signin",
+    }, { synced: true });
+
+In order to bypass the potential target filtering of ``RemoteSettings("key").get()``, the low-level listing of records can be obtained with ``.list()``:
+
+.. code-block:: js
+
+    const subset = await collection.list({
+      filters: {
+        "property": "value"
+      }
+    });
+
+The local data can be flushed with ``clear()``:
+
+.. code-block:: js
+
+    await collection.clear()
+
+For further documentation in collection API, checkout the `kinto.js library <https://kintojs.readthedocs.io/>`_, which is charge of the IndexedDB interaction behind-the-scenes.
+
+
+Inspect local data
+------------------
+
+The internal IndexedDBs of remote settings can be accessed via the Storage Inspector in the `browser toolbox <https://developer.mozilla.org/en-US/docs/Tools/Browser_Toolbox>`_.
+
+For example, the local data of the ``"key"`` collection can be accessed in the ``main/key`` IndexedDB store at *Browser Toolbox* > *Storage* > *IndexedDB* > *chrome* > *main/key*.
+
+
+about:remotesettings
+--------------------
+
+The ``about:remotesettings`` extension provides tool to inspect synchronization status, change the remote server or switch to *preview* in order to sign-off pending changes. `More information on the dedicated repository <https://github.com/leplatrem/aboutremotesettings>`_.
+
+.. note::
+
+    With `Bug 1406036 <https://bugzilla.mozilla.org/show_bug.cgi?id=1406036>`_, ``about:remotesettings`` will be available natively.
+
+
+About blocklists
+----------------
+
+Addons, certificates, plugins, and GFX blocklists were the first use-cases of remote settings, and thus have some specificities.
+
+For example, they leverage advanced customization options (bucket, content-signature certificate etc.), and in order to be able to inspect and manipulate their data, the client instances must first be explicitly initialized.
+
+.. code-block:: js
+
+    const BlocklistClients = ChromeUtils.import("resource://services-common/blocklist-clients.js", {});
+
+    BlocklistClients.initialize();
+
+Then, in order to access a specific client instance, the bucket must be specified:
+
+.. code-block:: js
+
+    const collection = await RemoteSettings("addons", { bucketName: "blocklists" }).openCollection();
+
+And in the storage inspector, the IndexedDB internal store will be prefixed with ``blocklists`` instead of ``main`` (eg. ``blocklists/addons``).
+