Connect your app to the company database

Paste one block, change one word. No request, no key, no account, no waiting.

<script>
(function(){
  var APP    = 'my-app';        /* <-- CHANGE THIS: short, unique, lowercase */
  var PREFIX = null;            /* optional: only share keys starting with these, e.g. ['myapp:'] */

  var DOOR='https://mera.shapeshifter.me', TABLE='app_state', ROW=APP+':shared',
      HY='ss_hy_'+APP, SKIP=/(theme|:view$|_view$|active_user|token|secret)/i;
  function shared(k){
    if(SKIP.test(k)) return false;
    return PREFIX ? PREFIX.some(function(p){return k.indexOf(p)===0}) : true;
  }
  var _set=localStorage.setItem.bind(localStorage), _rem=localStorage.removeItem.bind(localStorage), t=null, pip=null;

  function paint(state, detail){
    if(!pip){
      var host=document.querySelector('aside.sidebar')||document.getElementById('sidebar');
      pip=document.createElement('div'); pip.id='ss-sync-pip';
      pip.style.cssText='margin-top:auto;padding:10px 12px;font:11.5px/1.45 system-ui;border-top:1px solid rgba(255,255,255,.08);color:#8ea6bd;display:flex;align-items:center;gap:7px';
      if(host){ host.style.display='flex'; host.style.flexDirection='column'; host.appendChild(pip); }
      else { pip.style.cssText+=';position:fixed;left:12px;bottom:10px;z-index:9998;background:rgba(12,18,24,.9);border-radius:12px'; document.body.appendChild(pip); }
    }
    var c={ok:'#5ad19b',sync:'#e5c76b',err:'#f08a72'}[state]||'#7b8b9a';
    var label={ok:'Synced',sync:'Saving…',err:'Not saving'}[state]||'Local only';
    pip.innerHTML='<span style="width:8px;height:8px;border-radius:50%;background:'+c+';flex:none"></span>'+
      '<span><b style="color:#cfe0ee;font-weight:600">'+label+'</b>'+(detail?'<br><span style="color:#7b8b9a">'+detail+'</span>':'')+'</span>';
  }
  function push(){
    paint('sync');
    var payload={};
    for(var i=0;i<localStorage.length;i++){ var k=localStorage.key(i);
      if(shared(k)){ try{ payload[k]=localStorage.getItem(k); }catch(e){} } }
    fetch(DOOR+'/pm-write/upsert',{method:'POST',credentials:'include',
      headers:{'Content-Type':'application/json'},
      body:JSON.stringify({table:TABLE,rows:[{id:ROW,data:payload}]})})
      .then(function(r){ paint(r&&r.ok?'ok':'err', r&&r.ok?'saved '+new Date().toLocaleTimeString([], {hour:'numeric',minute:'2-digit'}):'server refused the save'); })
      .catch(function(){ paint('err','no connection — kept on this device'); });
  }
  localStorage.setItem=function(k,v){ _set(k,v); if(shared(k)){ clearTimeout(t); t=setTimeout(push,900);} };
  localStorage.removeItem=function(k){ _rem(k); if(shared(k)){ clearTimeout(t); t=setTimeout(push,900);} };

  if(!sessionStorage.getItem(HY)){
    sessionStorage.setItem(HY,'1');
    fetch(DOOR+'/data/'+TABLE+'?id=eq.'+encodeURIComponent(ROW)+'&select=data',{credentials:'include'})
      .then(function(r){ return r.ok?r.json():[] })
      .then(function(rows){
        var d=(rows&&rows[0]&&rows[0].data)||{}, changed=false;
        Object.keys(d).forEach(function(k){ if(d[k]!=null && d[k]!==localStorage.getItem(k)){ _set(k,d[k]); changed=true; } });
        paint('ok','loaded from company database');
        if(changed) location.reload(); else push();
      }).catch(function(){ paint('err','could not reach the company database'); });
  } else { paint('ok'); }

  function gate(){
    fetch(DOOR+'/data/products?select=id&limit=1',{credentials:'include'}).then(function(r){
      if(r.ok) return;
      var d=document.createElement('div');
      d.style.cssText='position:fixed;inset:0;z-index:2147483647;background:#0b0f14;color:#e6edf3;display:flex;align-items:center;justify-content:center;font:15px system-ui';
      d.innerHTML='<div style="max-width:440px;padding:32px;text-align:center"><div style="font-size:20px;font-weight:600;margin-bottom:10px">One-time sign-in needed</div><div style="color:#9aa7b4;margin-bottom:22px">This app loads live company data. Your browser needs a session with the company data service — one click, once per browser.</div><button id="ssgo" style="padding:11px 22px;border-radius:8px;border:0;background:#2f81f7;color:#fff;font-weight:600;cursor:pointer">Connect &amp; open app</button></div>';
      document.body.appendChild(d);
      d.querySelector('#ssgo').onclick=function(){ window.open(DOOR+'/','ss-connect');
        var n=0,iv=setInterval(function(){ n++; fetch(DOOR+'/data/products?select=id&limit=1',{credentials:'include'})
          .then(function(r2){ if(r2.ok){ clearInterval(iv); location.reload(); } else if(n>150) clearInterval(iv); }); },2000); };
    }).catch(function(){});
  }
  if(document.readyState==='loading') document.addEventListener('DOMContentLoaded',gate); else gate();
})();
</script>

What to do

  1. Paste the block into your app's HTML, immediately before </head>.
  2. Change APP = 'my-app' to a short unique name for your app — 'jim-inventory', 'harwill-schedule'.
  3. Publish as usual.

Your app now shares its data across the whole team, shows a Synced / Saving indicator, and handles first-time sign-in on its own.

Three rules that matter

  1. It must go in <head>. Apps fetch on load, so a script before </body> runs too late.
  2. Keep it on every rebuild. If a redesign strips it out, the app silently goes back to saving only in that one browser — no error, no warning.
  3. Theme, current view, tokens and secrets stay local and are never shared.

Read-only feeds — no setup at all

Any signed-in colleague can read these right now, from an app or the browser console:

fetch('https://mera.shapeshifter.me/data/<feed>', {credentials:'include'})

Filters: ?select= ?order= ?limit= ?column=eq.value. Responses cap at 1,000 rows — page with &offset= or results truncate with no error.

Certificates of analysis

FeedWhat it holdsRows
coasevery certificate record, all sources8387
coa_librarythe portal's combined library8385
coa_lotslots with parsed potency / microbial3176
coa_pdf_indexwhich lots have a certificate file on record5679
coa_smartsheetraw submission-tracker rows5209
coa_sync_statuslast sync outcome20

Sales & operations

FeedWhat it holdsRows
sop_shipmentsshipment lines, all channels2924
sop_liverecreational actuals by month & category100
sop_live_b2bB2B actuals by month & category110
sop_actuals_by_monthunits by category & ship month193
sop_b2b_reconcileB2B sliced for reconciliation31
sop_sync_statuslast sync outcome20

Regulatory

FeedWhat it holdsRows
reg_newsregulatory feed, refreshed hourly850
reg_countriescountry register51
reg_country_sourcessources behind each country12

Procurement & finance

FeedWhat it holdsRows
procurement_lotsflower procurement lots40
fp_lotssame, portal shape40
erp_rowsERP records524

Project management

FeedWhat it holdsRows
pm_taskstasks76
pm_projectsprojects4
pm_peoplepeople directory33
pm_automationsautomation rules1
pm_email_outboxoutbound notification queue0

Shared app storage (your app writes here)

FeedWhat it holdsRows
app_stateuniversal store — the block below uses this0
crm_rec_stateRecreational CRM1
crm_b2b_stateB2B CRM0
crm_intl_stateInternational CRM0
sellthru_stateSell-Through1
sop_stateS&OP shared inputs1
qms_stateQMS1

Thin today — present but barely populated

FeedWhat it holdsRows
productsproduct master1
companiescompany master6
inventory_on_handon-hand inventory1
lotslots1

Worth knowing

Every app shares one store, separated by the name you choose. Any signed-in colleague could in principle read or write another app's space — the boundary is the company sign-in, not a wall between apps. If your app will hold something sensitive, ask for its own isolated area instead.

When to ask

Self-serve covers everything above. You still need a hand for: an app that must hold sensitive data in its own isolated area, a new automatic import from SharePoint or Smartsheet, or file and PDF storage.