Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@targomo/core

Package Overview
Dependencies
Maintainers
3
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@targomo/core - npm Package Compare versions

Comparing version 0.7.8 to 0.7.9

2

package.json

@@ -5,3 +5,3 @@ {

"author": "Targomo",
"version": "0.7.8",
"version": "0.7.9",
"license": "MIT",

@@ -8,0 +8,0 @@ "repository": "github:targomo/targomo-js",

/**
* @targomo/core "0.7.8" http://targomo.com
* @targomo/core "0.7.9" http://targomo.com
* The JavaScript (& TypeScript) API for Targomo's time-based access mapping services.

@@ -41,8 +41,8 @@ * (c) 2023 Targomo

const TARGOMO_ENVIRONMENT_HEADER="x-targomo-environment";exports.TargomoEnvironment = void 0;!function(n){n.REVIEW="review",n.STAGING="staging",n.PROD="";}(exports.TargomoEnvironment||(exports.TargomoEnvironment={}));
class SimpleLRUEntry{constructor(t,e,i,s){this.value=t,this.key=e,this.previous=i,this.next=s;}}class SimpleLRU{constructor(t=0){this.capacity=t,this.map={},this.size=0;}get(t,e){return __awaiter(this,void 0,void 0,(function*(){const i=this.map[t];if(void 0!==i){this.oldest==i&&i.next&&(this.oldest=i.next),i.next&&(i.next.previous=i.previous),i.previous&&(i.previous.next=i.next),i.previous=this.newest,i.next=null,this.newest=i;try{return yield i.value}catch(i){return this.map[t]=void 0,this.get(t,e)}}else if(e){const i=e(),s=this.map[t]=new SimpleLRUEntry(i,t,this.newest,null),n=yield i;if(this.newest&&(this.newest.next=s),this.newest=s,this.capacity)if(this.size>=this.capacity){const t=this.oldest;t&&(this.oldest=t.next,delete this.map[t.key]);}else this.size++;return this.oldest||(this.oldest=this.newest),n}}))}}class SimpleCache{constructor(){this.map={};}get(t,e){return __awaiter(this,void 0,void 0,(function*(){let i;if(i="string"==typeof t?t:JSON.stringify(t),null!=this.map[i])return this.map[i];{const t=yield e();return this.map[i]=t,t}}))}}
const TARGOMO_ENVIRONMENT_HEADER="x-targomo-environment";exports.TargomoEnvironment = void 0;!function(n){n.REVIEW="review",n.STAGING="staging",n.PROD="";}(exports.TargomoEnvironment||(exports.TargomoEnvironment={}));
const CACHE=new SimpleCache;function logBody(o){o instanceof String||"string"==typeof o?console.log(o):console.log(JSON.stringify(o,null,2));}class RequestsUtil{constructor(o){this.options=o;}fetch(o,t="GET",e,n={}){return __awaiter(this,void 0,void 0,(function*(){this.options.environment&&(n[TARGOMO_ENVIRONMENT_HEADER]=this.options.environment);let s=t;"JSONP"!==t?n.Accept=n.Accept?n.Accept:"application/json":s="GET","POST-RAW"===t&&(s="POST"),"PUT"!==s&&"POST"!==s||(n["Content-Type"]="application/json");const i=new Headers(n),l={method:s,headers:i};"POST-RAW"===t?l.body=e:"GET"!==t&&"JSONP"!==t&&(l.body=JSON.stringify(e));const r=yield fetch(o,l);if((this.options&&this.options.debug||r.status>=400)&&(console.log("[TargomoClient Begin]"),console.log("[ENVIRONMENT]"),console.log(this.options.environment),console.log("[Request]",l.method,o),console.log(" [Headers]"),i.forEach(((o,t)=>{console.log(` ${t} = ${o}`);})),l.body&&(console.log(" [Body]"),console.log(l.body)),console.log("[Response]"),console.log(" status = ",r.status),console.log(" statusText = ",r.statusText),console.log(" [Headers]"),r.headers.forEach(((o,t)=>{console.log(` ${t} = ${o}`);}))),r.status>=400){console.log(" [Body]");const o="application/json"===r.headers.get("content-type")?JSON.stringify(yield r.text(),null,2):yield r.text();throw logBody(o),console.log("[TargomoClient End]"),{status:r.status,error:r.statusText,body:o}}{let o=null;if("JSONP"===t){const t=yield r.text(),e=t.indexOf("("),n=t.lastIndexOf(")");o=e>-1&&n>-1?JSON.parse(t.substring(e+1,n)):JSON.parse(t);}else o="POST-RAW"===t?yield r.text():r.json();return this.options&&this.options.debug&&(console.log(" [Body]"),logBody(yield o),console.log("[TargomoClient End]")),o}}))}fetchData(o,t="GET",e,n){return __awaiter(this,void 0,void 0,(function*(){const s=yield this.fetch(o,t,e,n);return s.data?s.data:(console.warn("No data object was transmitted by "+o+" \nReturning raw response"),s)}))}fetchCached(o,t,e="GET",n,s){if(!1!==o){!0!==o&&o||(o=CACHE);const i=JSON.stringify({url:t,method:e,payload:n});return o.get(i,(()=>this.fetch(t,e,n,s)))}return this.fetch(t,e,n,s)}fetchCachedData(o,t,e="GET",n,s){if(!1!==o){!0!==o&&o||(o=CACHE);const i=JSON.stringify({url:t,method:e,payload:n});return o.get(i,(()=>this.fetchData(t,e,n,s)))}return this.fetchData(t,e,n,s)}}function requests(o,t){return new RequestsUtil({debug:o&&o.config&&o.config.debug,environment:o&&o.config&&o.config.environment?o.config.environment:exports.TargomoEnvironment.PROD})}
const CACHE=new SimpleCache;function logBody(o){o instanceof String||"string"==typeof o?console.log(o):console.log(JSON.stringify(o,null,2));}class RequestsUtil{constructor(o){this.options=o;}fetch(o,t="GET",e,n={}){return __awaiter(this,void 0,void 0,(function*(){this.options.environment&&(n[TARGOMO_ENVIRONMENT_HEADER]=this.options.environment);let s=t;"JSONP"!==t?n.Accept=n.Accept?n.Accept:"application/json":s="GET","POST-RAW"===t&&(s="POST"),"PUT"!==s&&"POST"!==s||(n["Content-Type"]="application/json");const i=new Headers(n),l={method:s,headers:i};"POST-RAW"===t?l.body=e:"GET"!==t&&"JSONP"!==t&&(l.body=JSON.stringify(e));const r=yield fetch(o,l);if((this.options&&this.options.debug||r.status>=400)&&(console.log("[TargomoClient Begin]"),console.log("[ENVIRONMENT]"),console.log(this.options.environment),console.log("[Request]",l.method,o),console.log(" [Headers]"),i.forEach(((o,t)=>{console.log(` ${t} = ${o}`);})),l.body&&(console.log(" [Body]"),console.log(l.body)),console.log("[Response]"),console.log(" status = ",r.status),console.log(" statusText = ",r.statusText),console.log(" [Headers]"),r.headers.forEach(((o,t)=>{console.log(` ${t} = ${o}`);}))),r.status>=400){console.log(" [Body]");const o="application/json"===r.headers.get("content-type")?JSON.stringify(yield r.text(),null,2):yield r.text();throw logBody(o),console.log("[TargomoClient End]"),new Error(o)}{let o=null;if("JSONP"===t){const t=yield r.text(),e=t.indexOf("("),n=t.lastIndexOf(")");o=e>-1&&n>-1?JSON.parse(t.substring(e+1,n)):JSON.parse(t);}else o="POST-RAW"===t?yield r.text():r.json();return this.options&&this.options.debug&&(console.log(" [Body]"),logBody(yield o),console.log("[TargomoClient End]")),o}}))}fetchData(o,t="GET",e,n){return __awaiter(this,void 0,void 0,(function*(){const s=yield this.fetch(o,t,e,n);return s.data?s.data:(console.warn("No data object was transmitted by "+o+" \nReturning raw response"),s)}))}fetchCached(o,t,e="GET",n,s){if(!1!==o){!0!==o&&o||(o=CACHE);const i=JSON.stringify({url:t,method:e,payload:n});return o.get(i,(()=>this.fetch(t,e,n,s)))}return this.fetch(t,e,n,s)}fetchCachedData(o,t,e="GET",n,s){if(!1!==o){!0!==o&&o||(o=CACHE);const i=JSON.stringify({url:t,method:e,payload:n});return o.get(i,(()=>this.fetchData(t,e,n,s)))}return this.fetchData(t,e,n,s)}}function requests(o,t){return new RequestsUtil({debug:o&&o.config&&o.config.debug,environment:o&&o.config&&o.config.environment?o.config.environment:exports.TargomoEnvironment.PROD})}
exports.UrlUtil = void 0;!function(t){t.TargomoUrl=class{constructor(t){this.client=t,this.url="",this.firstParamPlaced=!1;}host(t){return 0===this.url.length&&"/"!==t[t.length-1]&&(t+="/"),this.part(t)}part(t){return this.url+=t,this}version(){return null!==this.client.config.version&&void 0!==this.client.config.version?this.part("v"+this.client.config.version):"/"===this.url[this.url.length-1]&&(this.url=this.url.substr(0,this.url.length-1)),this}params(t){return Object.keys(t).forEach((r=>{t[r]instanceof Array?t[r].forEach((t=>{this.param(r,t);})):this.param(r,t[r]);})),this}param(t,r){void 0!==r&&(this.firstParamPlaced?this.url+="&"+t+"="+r:(this.firstParamPlaced=!0,this.url+="?"+t+"="+r));}key(t="key"){return this.params({[t]:this.client.serviceKey})}toString(){return this.url}};}(exports.UrlUtil||(exports.UrlUtil={}));

@@ -49,0 +49,0 @@

@@ -1,4 +0,4 @@

import { Cache } from '../util/cache';
import { TargomoClient } from '../api/index';
import { TargomoEnvironment } from '../constants';
import { Cache } from '../util/cache';
export declare class RequestsUtil {

@@ -5,0 +5,0 @@ private options?;

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc