New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@nhost/nhost-js

Package Overview
Dependencies
Maintainers
3
Versions
173
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nhost/nhost-js - npm Package Compare versions

Comparing version 1.5.0 to 1.5.1

2

dist/index.cjs.js

@@ -1,2 +0,2 @@

"use strict";var E=Object.defineProperty,$=Object.defineProperties;var _=Object.getOwnPropertyDescriptors;var d=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,m=Object.prototype.propertyIsEnumerable;var p=(t,e,s)=>e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,h=(t,e)=>{for(var s in e||(e={}))A.call(e,s)&&p(t,s,e[s]);if(d)for(var s of d(e))m.call(e,s)&&p(t,s,e[s]);return t},T=(t,e)=>$(t,_(e));var b=(t,e)=>{var s={};for(var r in t)A.call(t,r)&&e.indexOf(r)<0&&(s[r]=t[r]);if(t!=null&&d)for(var r of d(t))e.indexOf(r)<0&&m.call(t,r)&&(s[r]=t[r]);return s};Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var N=require("@nhost/hasura-auth-js"),U=require("@nhost/hasura-storage-js"),L=require("axios"),H=require("graphql");function G(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var S=G(L);class q{constructor(e){const{url:s,adminSecret:r}=e;this.accessToken=null,this.adminSecret=r,this.instance=S.default.create({baseURL:s})}async call(e,s,r){const c=h(h({},this.generateAccessTokenHeaders()),r==null?void 0:r.headers);let n;try{n=await this.instance.post(e,s,T(h({},r),{headers:c}))}catch(i){if(i instanceof Error)return{res:null,error:i}}return n?{res:n,error:null}:{res:null,error:new Error("Unable to make post request to funtion")}}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:this.accessToken?{Authorization:`Bearer ${this.accessToken}`}:{}}}class w{constructor(e){const{url:s,adminSecret:r}=e;this.url=s,this.accessToken=null,this.adminSecret=r,this.instance=S.default.create({baseURL:s})}async request(e,s,r){const c=h(h({},this.generateAccessTokenHeaders()),r==null?void 0:r.headers);try{const n="",u=(await this.instance.post("",{operationName:n||void 0,query:typeof e=="string"?e:H.print(e),variables:s},T(h({},r),{headers:c}))).data,{data:o}=u;return u.errors?{data:null,error:u.errors}:typeof o!="object"||Array.isArray(o)||o===null?{data:null,error:new Error("incorrect response data from GraphQL server")}:{data:o,error:null}}catch(n){return n instanceof Error?{data:null,error:n}:(console.error(n),{data:null,error:new Error("Unable to get do GraphQL request")})}}getUrl(){return this.url}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:this.accessToken?{Authorization:`Bearer ${this.accessToken}`}:{}}}const j=/^localhost(:\d+)*$/g;function k(t,e){const{backendUrl:s,subdomain:r,region:c}=t;if(!s&&!r)throw new Error("Either `backendUrl` or `subdomain` must be set.");if(s)return`${s}/v1/${e}`;if(!r)throw new Error("`subdomain` must be set if `backendUrl` is not set.");const n=r.match(j);if(n&&n.length>0){const i=n[0];return i==="localhost"?`http://localhost:1337/v1/${e}`:`http://${i}/v1/${e}`}if(!c)throw new Error('`region` must be set when using a `subdomain` other than "localhost".');return`https://${r}.${e}.${c}.nhost.run/v1`}class v{constructor(F){var f=F,{refreshIntervalTime:e,clientStorageGetter:s,clientStorageSetter:r,clientStorage:c,clientStorageType:n,autoRefreshToken:i,autoSignIn:u,adminSecret:o,devTools:C,start:y=!0}=f,l=b(f,["refreshIntervalTime","clientStorageGetter","clientStorageSetter","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","adminSecret","devTools","start"]);var g;this.auth=new N.HasuraAuthClient({url:k(l,"auth"),refreshIntervalTime:e,clientStorageGetter:s,clientStorageSetter:r,clientStorage:c,clientStorageType:n,autoRefreshToken:i,autoSignIn:u,start:y}),this.storage=new U.HasuraStorageClient({url:k(l,"storage"),adminSecret:o}),this.functions=new q({url:k(l,"functions"),adminSecret:o}),this.graphql=new w({url:k(l,"graphql"),adminSecret:o}),this.storage.setAccessToken(this.auth.getAccessToken()),this.functions.setAccessToken(this.auth.getAccessToken()),this.graphql.setAccessToken(this.auth.getAccessToken()),(g=this.auth.client)==null||g.onStart(()=>{this.auth.onAuthStateChanged((a,O)=>{a==="SIGNED_OUT"&&(this.storage.setAccessToken(void 0),this.functions.setAccessToken(void 0),this.graphql.setAccessToken(void 0))}),this.auth.onTokenChanged(a=>{this.storage.setAccessToken(a==null?void 0:a.accessToken),this.functions.setAccessToken(a==null?void 0:a.accessToken),this.graphql.setAccessToken(a==null?void 0:a.accessToken)})}),this._adminSecret=o,this.devTools=C}get adminSecret(){return this._adminSecret}set adminSecret(e){this._adminSecret=e,this.storage.setAdminSecret(e)}}const x=t=>new v(t);exports.NhostClient=v;exports.NhostFunctionsClient=q;exports.NhostGraphqlClient=w;exports.createClient=x;
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var m=require("@nhost/hasura-auth-js"),b=require("@nhost/hasura-storage-js"),S=require("axios"),q=require("graphql");function w(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}var k=w(S);class T{constructor(e){const{url:s,adminSecret:t}=e;this.accessToken=null,this.adminSecret=t,this.instance=k.default.create({baseURL:s})}async call(e,s,t){const c={...this.generateAccessTokenHeaders(),...t==null?void 0:t.headers};let r;try{r=await this.instance.post(e,s,{...t,headers:c})}catch(i){if(i instanceof Error)return{res:null,error:i}}return r?{res:r,error:null}:{res:null,error:new Error("Unable to make post request to funtion")}}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:this.accessToken?{Authorization:`Bearer ${this.accessToken}`}:{}}}class f{constructor(e){const{url:s,adminSecret:t}=e;this.url=s,this.accessToken=null,this.adminSecret=t,this.instance=k.default.create({baseURL:s})}async request(e,s,t){const c={...this.generateAccessTokenHeaders(),...t==null?void 0:t.headers};try{const r="",h=(await this.instance.post("",{operationName:r||void 0,query:typeof e=="string"?e:q.print(e),variables:s},{...t,headers:c})).data,{data:o}=h;return h.errors?{data:null,error:h.errors}:typeof o!="object"||Array.isArray(o)||o===null?{data:null,error:new Error("incorrect response data from GraphQL server")}:{data:o,error:null}}catch(r){return r instanceof Error?{data:null,error:r}:(console.error(r),{data:null,error:new Error("Unable to get do GraphQL request")})}}getUrl(){return this.url}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:this.accessToken?{Authorization:`Bearer ${this.accessToken}`}:{}}}const v=/^localhost(:\d+)*$/g;function l(n,e){const{backendUrl:s,subdomain:t,region:c}=n;if(!s&&!t)throw new Error("Either `backendUrl` or `subdomain` must be set.");if(s)return`${s}/v1/${e}`;if(!t)throw new Error("`subdomain` must be set if `backendUrl` is not set.");const r=t.match(v);if(r&&r.length>0){const i=r[0];return i==="localhost"?`http://localhost:1337/v1/${e}`:`http://${i}/v1/${e}`}if(!c)throw new Error('`region` must be set when using a `subdomain` other than "localhost".');return`https://${t}.${e}.${c}.nhost.run/v1`}class g{constructor({refreshIntervalTime:e,clientStorageGetter:s,clientStorageSetter:t,clientStorage:c,clientStorageType:r,autoRefreshToken:i,autoSignIn:h,adminSecret:o,devTools:p,start:A=!0,...u}){var d;this.auth=new m.HasuraAuthClient({url:l(u,"auth"),refreshIntervalTime:e,clientStorageGetter:s,clientStorageSetter:t,clientStorage:c,clientStorageType:r,autoRefreshToken:i,autoSignIn:h,start:A}),this.storage=new b.HasuraStorageClient({url:l(u,"storage"),adminSecret:o}),this.functions=new T({url:l(u,"functions"),adminSecret:o}),this.graphql=new f({url:l(u,"graphql"),adminSecret:o}),this.storage.setAccessToken(this.auth.getAccessToken()),this.functions.setAccessToken(this.auth.getAccessToken()),this.graphql.setAccessToken(this.auth.getAccessToken()),(d=this.auth.client)==null||d.onStart(()=>{this.auth.onAuthStateChanged((a,y)=>{a==="SIGNED_OUT"&&(this.storage.setAccessToken(void 0),this.functions.setAccessToken(void 0),this.graphql.setAccessToken(void 0))}),this.auth.onTokenChanged(a=>{this.storage.setAccessToken(a==null?void 0:a.accessToken),this.functions.setAccessToken(a==null?void 0:a.accessToken),this.graphql.setAccessToken(a==null?void 0:a.accessToken)})}),this._adminSecret=o,this.devTools=p}get adminSecret(){return this._adminSecret}set adminSecret(e){this._adminSecret=e,this.storage.setAdminSecret(e)}}const C=n=>new g(n);exports.NhostClient=g;exports.NhostFunctionsClient=T;exports.NhostGraphqlClient=f;exports.createClient=C;
//# sourceMappingURL=index.cjs.js.map

@@ -1,32 +0,1 @@

var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
var target = {};
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop];
if (source != null && __getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(source)) {
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
target[prop] = source[prop];
}
return target;
};
import { HasuraAuthClient } from "@nhost/hasura-auth-js";

@@ -46,6 +15,9 @@ import { HasuraStorageClient } from "@nhost/hasura-storage-js";

async call(url, data, config) {
const headers = __spreadValues(__spreadValues({}, this.generateAccessTokenHeaders()), config == null ? void 0 : config.headers);
const headers = {
...this.generateAccessTokenHeaders(),
...config == null ? void 0 : config.headers
};
let res;
try {
res = await this.instance.post(url, data, __spreadProps(__spreadValues({}, config), { headers }));
res = await this.instance.post(url, data, { ...config, headers });
} catch (error) {

@@ -96,10 +68,17 @@ if (error instanceof Error) {

async request(document, variables, config) {
const headers = __spreadValues(__spreadValues({}, this.generateAccessTokenHeaders()), config == null ? void 0 : config.headers);
const headers = {
...this.generateAccessTokenHeaders(),
...config == null ? void 0 : config.headers
};
try {
const operationName = "";
const res = await this.instance.post("", {
operationName: operationName || void 0,
query: typeof document === "string" ? document : print(document),
variables
}, __spreadProps(__spreadValues({}, config), { headers }));
const res = await this.instance.post(
"",
{
operationName: operationName || void 0,
query: typeof document === "string" ? document : print(document),
variables
},
{ ...config, headers }
);
const responseData = res.data;

@@ -181,27 +160,16 @@ const { data } = responseData;

class NhostClient {
constructor(_a) {
var _b = _a, {
refreshIntervalTime,
clientStorageGetter,
clientStorageSetter,
clientStorage,
clientStorageType,
autoRefreshToken,
autoSignIn,
adminSecret,
devTools,
start = true
} = _b, urlParams = __objRest(_b, [
"refreshIntervalTime",
"clientStorageGetter",
"clientStorageSetter",
"clientStorage",
"clientStorageType",
"autoRefreshToken",
"autoSignIn",
"adminSecret",
"devTools",
"start"
]);
var _a2;
constructor({
refreshIntervalTime,
clientStorageGetter,
clientStorageSetter,
clientStorage,
clientStorageType,
autoRefreshToken,
autoSignIn,
adminSecret,
devTools,
start = true,
...urlParams
}) {
var _a;
this.auth = new HasuraAuthClient({

@@ -233,3 +201,3 @@ url: urlFromParams(urlParams, "auth"),

this.graphql.setAccessToken(this.auth.getAccessToken());
(_a2 = this.auth.client) == null ? void 0 : _a2.onStart(() => {
(_a = this.auth.client) == null ? void 0 : _a.onStart(() => {
this.auth.onAuthStateChanged((_event, session) => {

@@ -236,0 +204,0 @@ if (_event === "SIGNED_OUT") {

{
"name": "@nhost/nhost-js",
"version": "1.5.0",
"version": "1.5.1",
"description": "Nhost JavaScript SDK",

@@ -46,4 +46,4 @@ "license": "MIT",

"dependencies": {
"@nhost/hasura-auth-js": "1.5.0",
"@nhost/hasura-storage-js": "0.6.2",
"@nhost/hasura-auth-js": "1.6.0",
"@nhost/hasura-storage-js": "0.7.0",
"axios": "^0.27.2",

@@ -54,4 +54,4 @@ "jwt-decode": "^3.1.2",

"devDependencies": {
"@nhost/docgen": "0.1.2",
"graphql": "16",
"@nhost/docgen": "0.1.3",
"graphql": "15.7.2",
"start-server-and-test": "^1.14.0"

@@ -80,4 +80,3 @@ },

"docgen": "pnpm typedoc && docgen --config ./nhost-js.docgen.json"
},
"readme": "<h1 align=\"center\">@nhost/nhost-js</h1>\n<h2 align=\"center\">Nhost JavaScript SDK</h2>\n\n<p align=\"center\">\n <img alt=\"npm\" src=\"https://img.shields.io/npm/v/@nhost/nhost-js\">\n <img alt=\"npm\" src=\"https://img.shields.io/npm/dm/@nhost/nhost-js\">\n <a href=\"LICENSE\">\n <img src=\"https://img.shields.io/badge/license-MIT-yellow.svg\" alt=\"license: MIT\" />\n </a>\n</p>\n\n## Documentation\n\n[Reference documentation](https://docs.nhost.io/reference/javascript)\n\n## Install\n\n```\nnpm install @nhost/nhost-js\n\n# or yarn\nyarn add @nhost/nhost-js\n```\n\n### Initialise\n\n```js\nimport { NhostClient } from '@nhost/nhost-js'\n\nconst nhost = new NhostClient({\n subdomain: '<Your Nhost project subdomain>',\n region: '<Your Nhost project region>'\n})\n```\n\n## Features\n\n### GraphQL\n\nAccess Nhost GraphQL methods using `nhost.graphql`.\n\n### Authentication\n\nAccess Nhost Auth methods using `nhost.auth`.\n\n### Storage\n\nAccess Nhost Storage methods using `nhost.storage`.\n\n### Functions\n\nAccess Nhost Functions methods via `nhost.functions`.\n"
}
}

Sorry, the diff of this file is not supported yet

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

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