@nhost/nhost-js
Advanced tools
Comparing version 0.1.1 to 0.1.2
import { AxiosRequestConfig } from 'axios'; | ||
import { FunctionCallResponse } from '../types'; | ||
export declare type NhostFunctionsConstructorParams = { | ||
@@ -9,6 +10,5 @@ url: string; | ||
constructor(params: NhostFunctionsConstructorParams); | ||
private post; | ||
call(url: string, data: any, config?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<unknown, any>>; | ||
call(url: string, data: any, config?: AxiosRequestConfig): Promise<FunctionCallResponse>; | ||
setAccessToken(accessToken: string | undefined): void; | ||
private generateAccessTokenHeaders; | ||
} |
@@ -13,2 +13,38 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -29,8 +65,33 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
NhostFunctionsClient.prototype.post = function (url, data, config) { | ||
var headers = __assign(__assign({}, config === null || config === void 0 ? void 0 : config.headers), this.generateAccessTokenHeaders()); | ||
return this.instance.post(url, data, __assign(__assign({}, config), { headers: headers })); | ||
}; | ||
NhostFunctionsClient.prototype.call = function (url, data, config) { | ||
return this.post(url, data, config); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var headers, res, error_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
headers = __assign(__assign({}, config === null || config === void 0 ? void 0 : config.headers), this.generateAccessTokenHeaders()); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.instance.post(url, data, __assign(__assign({}, config), { headers: headers }))]; | ||
case 2: | ||
res = _a.sent(); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
error_1 = _a.sent(); | ||
if (error_1 instanceof Error) { | ||
return [2 /*return*/, { res: null, error: error_1 }]; | ||
} | ||
return [3 /*break*/, 4]; | ||
case 4: | ||
if (!res) { | ||
return [2 /*return*/, { | ||
res: null, | ||
error: Error('Unable to make post request to funtion'), | ||
}]; | ||
} | ||
return [2 /*return*/, { res: res, error: null }]; | ||
} | ||
}); | ||
}); | ||
}; | ||
@@ -37,0 +98,0 @@ NhostFunctionsClient.prototype.setAccessToken = function (accessToken) { |
import { AxiosRequestConfig } from 'axios'; | ||
import { GraphqlRequestResponse } from '../types'; | ||
export declare type NhostGraphqlConstructorParams = { | ||
@@ -10,3 +11,3 @@ url: string; | ||
constructor(params: NhostGraphqlConstructorParams); | ||
request(document: string, variables?: any, config?: AxiosRequestConfig): Promise<unknown>; | ||
request(document: string, variables?: any, config?: AxiosRequestConfig): Promise<GraphqlRequestResponse>; | ||
getUrl(): string; | ||
@@ -13,0 +14,0 @@ setAccessToken(accessToken: string | undefined): void; |
@@ -67,3 +67,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var headers, operationName, data; | ||
var headers, operationName, responseData, res, error_1; | ||
return __generator(this, function (_a) { | ||
@@ -74,2 +74,5 @@ switch (_a.label) { | ||
operationName = ''; | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.instance.post('', { | ||
@@ -80,5 +83,30 @@ operationName: operationName ? operationName : undefined, | ||
}, __assign(__assign({}, config), { headers: headers }))]; | ||
case 1: | ||
data = (_a.sent()).data; | ||
return [2 /*return*/, data]; | ||
case 2: | ||
res = _a.sent(); | ||
responseData = res.data; | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
error_1 = _a.sent(); | ||
if (error_1 instanceof Error) { | ||
return [2 /*return*/, { data: null, error: error_1 }]; | ||
} | ||
console.error(error_1); | ||
return [2 /*return*/, { data: null, error: Error('Unable to get do GraphQL request') }]; | ||
case 4: | ||
if (typeof responseData !== 'object' || | ||
Array.isArray(responseData) || | ||
responseData === null) { | ||
return [2 /*return*/, { | ||
data: null, | ||
error: Error('incorrect response data from GraphQL server'), | ||
}]; | ||
} | ||
responseData = responseData; | ||
if (responseData.errors) { | ||
return [2 /*return*/, { | ||
data: null, | ||
error: responseData.errors, | ||
}]; | ||
} | ||
return [2 /*return*/, { data: responseData.data, error: null }]; | ||
} | ||
@@ -85,0 +113,0 @@ }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=types.js.map |
import { AxiosRequestConfig } from 'axios'; | ||
import { FunctionCallResponse } from '../types'; | ||
export declare type NhostFunctionsConstructorParams = { | ||
@@ -9,6 +10,5 @@ url: string; | ||
constructor(params: NhostFunctionsConstructorParams); | ||
private post; | ||
call(url: string, data: any, config?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<unknown, any>>; | ||
call(url: string, data: any, config?: AxiosRequestConfig): Promise<FunctionCallResponse>; | ||
setAccessToken(accessToken: string | undefined): void; | ||
private generateAccessTokenHeaders; | ||
} |
@@ -12,2 +12,38 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
import axios from 'axios'; | ||
@@ -23,8 +59,33 @@ var NhostFunctionsClient = /** @class */ (function () { | ||
} | ||
NhostFunctionsClient.prototype.post = function (url, data, config) { | ||
var headers = __assign(__assign({}, config === null || config === void 0 ? void 0 : config.headers), this.generateAccessTokenHeaders()); | ||
return this.instance.post(url, data, __assign(__assign({}, config), { headers: headers })); | ||
}; | ||
NhostFunctionsClient.prototype.call = function (url, data, config) { | ||
return this.post(url, data, config); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var headers, res, error_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
headers = __assign(__assign({}, config === null || config === void 0 ? void 0 : config.headers), this.generateAccessTokenHeaders()); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.instance.post(url, data, __assign(__assign({}, config), { headers: headers }))]; | ||
case 2: | ||
res = _a.sent(); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
error_1 = _a.sent(); | ||
if (error_1 instanceof Error) { | ||
return [2 /*return*/, { res: null, error: error_1 }]; | ||
} | ||
return [3 /*break*/, 4]; | ||
case 4: | ||
if (!res) { | ||
return [2 /*return*/, { | ||
res: null, | ||
error: Error('Unable to make post request to funtion'), | ||
}]; | ||
} | ||
return [2 /*return*/, { res: res, error: null }]; | ||
} | ||
}); | ||
}); | ||
}; | ||
@@ -31,0 +92,0 @@ NhostFunctionsClient.prototype.setAccessToken = function (accessToken) { |
import { AxiosRequestConfig } from 'axios'; | ||
import { GraphqlRequestResponse } from '../types'; | ||
export declare type NhostGraphqlConstructorParams = { | ||
@@ -10,3 +11,3 @@ url: string; | ||
constructor(params: NhostGraphqlConstructorParams); | ||
request(document: string, variables?: any, config?: AxiosRequestConfig): Promise<unknown>; | ||
request(document: string, variables?: any, config?: AxiosRequestConfig): Promise<GraphqlRequestResponse>; | ||
getUrl(): string; | ||
@@ -13,0 +14,0 @@ setAccessToken(accessToken: string | undefined): void; |
@@ -61,3 +61,3 @@ var __assign = (this && this.__assign) || function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var headers, operationName, data; | ||
var headers, operationName, responseData, res, error_1; | ||
return __generator(this, function (_a) { | ||
@@ -68,2 +68,5 @@ switch (_a.label) { | ||
operationName = ''; | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.instance.post('', { | ||
@@ -74,5 +77,30 @@ operationName: operationName ? operationName : undefined, | ||
}, __assign(__assign({}, config), { headers: headers }))]; | ||
case 1: | ||
data = (_a.sent()).data; | ||
return [2 /*return*/, data]; | ||
case 2: | ||
res = _a.sent(); | ||
responseData = res.data; | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
error_1 = _a.sent(); | ||
if (error_1 instanceof Error) { | ||
return [2 /*return*/, { data: null, error: error_1 }]; | ||
} | ||
console.error(error_1); | ||
return [2 /*return*/, { data: null, error: Error('Unable to get do GraphQL request') }]; | ||
case 4: | ||
if (typeof responseData !== 'object' || | ||
Array.isArray(responseData) || | ||
responseData === null) { | ||
return [2 /*return*/, { | ||
data: null, | ||
error: Error('incorrect response data from GraphQL server'), | ||
}]; | ||
} | ||
responseData = responseData; | ||
if (responseData.errors) { | ||
return [2 /*return*/, { | ||
data: null, | ||
error: responseData.errors, | ||
}]; | ||
} | ||
return [2 /*return*/, { data: responseData.data, error: null }]; | ||
} | ||
@@ -79,0 +107,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
"use strict"; | ||
export {}; | ||
//# sourceMappingURL=types.js.map |
{ | ||
"name": "@nhost/nhost-js", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Nhost JavaScript SDK", | ||
@@ -18,4 +18,3 @@ "main": "./lib/cjs/index.js", | ||
"build:cjs": "tsc --module commonjs --outDir lib/cjs", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"release": "yarn build && np" | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
@@ -41,2 +40,3 @@ "repository": { | ||
"np": "^7.5.0", | ||
"typedoc": "^0.22.6", | ||
"typescript": "^4.4.2" | ||
@@ -43,0 +43,0 @@ }, |
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 not supported yet
Sorry, the diff of this file is not supported yet
114240
1768
3