import { isVersionCompatible } from './discoverServices';

function Stripes(properties) {
  const logger = properties.logger;

  Object.assign(this, properties);
  this.hasPerm = (perm) => {
    if (this.config && this.config.hasAllPerms) {
      logger.log('perm', `assuming perm '${perm}': hasAllPerms is true`);
      return true;
    }
    if (!this.user.perms) {
      logger.log('perm', `not checking perm '${perm}': no user permissions yet`);
      return undefined;
    }
    logger.log('perm', `checking perm '${perm}': `, !!this.user.perms[perm]);
    return this.user.perms[perm] || false;
  };
  this.hasInterface = (name, versionWanted) => {
    if (!this.discovery || !this.discovery.interfaces) {
      logger.log('interface', `not checking interface '${name}': no discovery yet`);
      return undefined;
    }
    const version = this.discovery.interfaces[name];
    if (!version) {
      logger.log('interface', `interface '${name}' is missing`);
      return undefined;
    }
    if (!versionWanted) {
      logger.log('interface', `interface '${name}' exists`);
      return true;
    }
    const ok = isVersionCompatible(version, versionWanted);
    const cond = ok ? 'is' : 'is not';
    logger.log('interface', `interface '${name}' v${versionWanted} ${cond} compatible with available v${version}`);
    return ok ? version : 0;
  };
}

export default Stripes;

@@ -56,24 +56,37 @@
 ';%0A%0A
-function Stripes
+class Stripes %7B%0A  constructor
 (pro
@@ -96,16 +96,18 @@
 ties) %7B%0A
+  
   const 
@@ -135,16 +135,18 @@
 ogger;%0A%0A
+  
   Object
@@ -172,16 +172,18 @@
 rties);%0A
+  
   this.h
@@ -199,24 +199,26 @@
 (perm) =%3E %7B%0A
+  
     if (this
@@ -247,32 +247,34 @@
 .hasAllPerms) %7B%0A
+  
       logger.log
@@ -329,32 +329,34 @@
 s true%60);%0A      
+  
 return true;%0A   
@@ -352,26 +352,30 @@
 n true;%0A    
-%7D%0A
+  %7D%0A  
     if (!thi
@@ -386,24 +386,26 @@
 er.perms) %7B%0A
+  
       logger
@@ -472,32 +472,34 @@
 ns yet%60);%0A      
+  
 return undefined
@@ -492,32 +492,34 @@
 turn undefined;%0A
+  
     %7D%0A    logger
@@ -508,24 +508,26 @@
       %7D%0A    
+  
 logger.log('
@@ -588,24 +588,26 @@
 perm%5D);%0A    
+  
 return this.
@@ -633,21 +633,25 @@
  false;%0A
+  
   %7D;%0A
+  
   this.h
@@ -687,24 +687,26 @@
 anted) =%3E %7B%0A
+  
     if (!thi
@@ -746,24 +746,26 @@
 terfaces) %7B%0A
+  
       logger
@@ -835,32 +835,34 @@
 ry yet%60);%0A      
+  
 return undefined
@@ -863,26 +863,30 @@
 efined;%0A    
-%7D%0A
+  %7D%0A  
     const ve
@@ -926,24 +926,26 @@
 %5Bname%5D;%0A    
+  
 if (!version
@@ -944,24 +944,26 @@
 !version) %7B%0A
+  
       logger
@@ -1011,24 +1011,26 @@
  missing%60);%0A
+  
       return
@@ -1041,26 +1041,30 @@
 efined;%0A    
-%7D%0A
+  %7D%0A  
     if (!ver
@@ -1073,24 +1073,26 @@
 onWanted) %7B%0A
+  
       logger
@@ -1138,32 +1138,34 @@
 exists%60);%0A      
+  
 return true;%0A   
@@ -1161,26 +1161,30 @@
 n true;%0A    
-%7D%0A
+  %7D%0A  
     const ok
@@ -1231,24 +1231,26 @@
 anted);%0A    
+  
 const cond =
@@ -1272,16 +1272,18 @@
 s not';%0A
+  
     logg
@@ -1390,24 +1390,26 @@
 ion%7D%60);%0A    
+  
 return ok ? 
@@ -1423,18 +1423,24 @@
  : 0;%0A  
+  %7D;%0A  
 %7D
-;
 %0A%7D%0A%0Aexpo

Convert Stripes to a regular class rather than a function