@alt-javascript/scanner-darkly
Version:
A Pluggable Scanner For Launch Darkly Feature Flag Variations
81 lines (61 loc) • 3.95 kB
Markdown
A Pluggable Scanner For Launch Darkly Feature Flag Variations
=============================================================
[](https://nodei.co/npm/@alt-javascript/scanner-darkly/)
<br/>

 <br/>
[release notes](https://github.com/alt-javascript/scanner-darkly/blob/main/History.md)
<a name="intro">Introduction</a>
--------------------------------
A pluggable scanner for listening and acting on Launch Darkly feature flag variations in
server-side node.js.
<a name="usage">Usage</a>
-------------------------
To use the module, follow the example in the included `scan.js` file, which plays nicely with all the other
-javascript modules.
The Scanner, takes an `Arctor` (or array of `Arctors`) that will act on flagged LaunchDarkly variations with
the implemented `see(clearly)` function, in this case the provided `LogArctor` outputs the changed flag value.
`scan.js`
```javascript
const LaunchDarkly = require('launchdarkly-node-server-sdk');
const ScannerDarkly = require('-javascript/scanner-darkly');
const {config} = require ("@alt-javascript/config");
const {boot} = require ("@alt-javascript/boot");
const {LoggerFactory} = require ('-javascript/logger');
boot({ config });
const LogArctor = require('-javascript/scanner-darkly'); // this uses booted logging config, so is required after boot().
const logger = LoggerFactory.getLogger('-javascript/scanner-darkly/scan');
const ldlogger = LoggerFactory.getLogger('LaunchDarkly');
const SDK_KEY = config.get('scanner.darkly.sdk-key');
const scannerDarkly = new ScannerDarkly(
new LogArctor('logging-levels', {"key": "user@test.com"},null),
SDK_KEY,
{logger : ldlogger});
scannerDarkly.init();
// ... later, on process exit.
scannerDarkly.destroy();
```
When your LaunchDarkly product, environment, sdk-key and feature flag are configured, you should see output like:
```shell
Wed Jul 28 2021 10:57:03 GMT+1000 (GMT+10:00):LaunchDarkly:info:Initializing stream processor to receive feature flag updates
Wed Jul 28 2021 10:57:04 GMT+1000 (GMT+10:00):LaunchDarkly:info:Opened LaunchDarkly stream connection
Wed Jul 28 2021 10:57:04 GMT+1000 (GMT+10:00):LaunchDarkly:debug:Received put event
Wed Jul 28 2021 10:57:15 GMT+1000 (GMT+10:00):LaunchDarkly:debug:Received patch event
Wed Jul 28 2021 10:57:15 GMT+1000 (GMT+10:00):LaunchDarkly:debug:Updating logging-levels in features
Wed Jul 28 2021 10:57:15 GMT+1000 (GMT+10:00):-javascript/scanner-darkly/LogArctor:info:Variation seen clearly as {"crew_prestart/src/services":"debug"}
Wed Jul 28 2021 10:57:18 GMT+1000 (GMT+10:00):LaunchDarkly:debug:Flushing %d events2
```
<a name="arctor">Yes, its Arctor, not Actor</a>
----------------------------------------
Yes, the class is called `Arctor` _by design_, and in homage to one of my very favourite novels,
> What does a scanner see? he asked himself. I mean, really see? Into the head?
> Down into the heart? Does a passive infrared scanner like they used to use or a cube-type holo-scanner
> like they use these days, the latest thing, see into me - into us - clearly or darkly?
> I hope it does, he thought, see clearly, because I can't any longer these days see into myself.
> I see only murk. Murk outside; murk inside. I hope, for everyone's sake, the scanners do better.
> Because, he thought, if the scanner sees only darkly, the way I myself do, then we are cursed,
> cursed again and like we have been continually, and we'll wind up dead this way,
> knowing very little and getting that little fragment wrong too.
>
>― [A Scanner Darkly - Philip. K. Dick, 1977](https://en.wikipedia.org/wiki/A_Scanner_Darkly)
The movie is pretty good too, _weird good_.