@plattar/sdk-core
Advanced tools
Comparing version
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CoreQuery = void 0; | ||
const util_1 = require("../../generator/generators/util"); | ||
const global_object_pool_1 = require("../global-object-pool"); | ||
@@ -133,2 +134,6 @@ const service_1 = require("../service"); | ||
const results = new Array(); | ||
const headers = { | ||
'Content-Type': 'application/json', | ||
'Accept': 'application/json' | ||
}; | ||
// init our request type | ||
@@ -139,10 +144,36 @@ const request = { | ||
cache: 'no-cache', | ||
credentials: 'include', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Accept': 'application/json' | ||
}, | ||
redirect: 'follow', | ||
referrerPolicy: 'origin' | ||
}; | ||
if (util_1.Util.isNode()) { | ||
switch (service.config.auth.type) { | ||
// for NodeJS we need to set the cookie header directly so we'll use the | ||
// token as the actual cookies to send over to the server | ||
case 'cookie': | ||
if (service.config.auth.token) { | ||
headers['cookie'] = service.config.auth.token; | ||
} | ||
break; | ||
case 'token': | ||
if (service.config.auth.token) { | ||
headers['Authorization'] = `Bearer ${service.config.auth.token}`; | ||
} | ||
break; | ||
} | ||
} | ||
else { | ||
switch (service.config.auth.type) { | ||
// in brwoser mode (non NodeJS) we send all cookies via `include` credentials | ||
// which will instruct browser to send all current cookies to the server | ||
case 'cookie': | ||
request.credentials = 'include'; | ||
break; | ||
case 'token': | ||
if (service.config.auth.token) { | ||
headers['Authorization'] = `Bearer ${service.config.auth.token}`; | ||
} | ||
break; | ||
} | ||
} | ||
request.headers = headers; | ||
// send the payload if performing POST/PUT/PATCH requests | ||
@@ -149,0 +180,0 @@ switch (type) { |
@@ -1,2 +0,2 @@ | ||
export type ServiceAuthType = 'cookie' | 'token'; | ||
export type ServiceAuthType = 'cookie' | 'token' | 'none'; | ||
export type ServiceErrorHandler = 'silent' | 'console.error' | 'console.warn' | 'throw'; | ||
@@ -3,0 +3,0 @@ export type ServiceErrorListener = (err: Error) => void; |
@@ -24,3 +24,3 @@ "use strict"; | ||
auth: { | ||
type: (config.auth && config.auth.type) ? config.auth.type : 'cookie', | ||
type: (config.auth && config.auth.type) ? config.auth.type : 'none', | ||
token: (config.auth && config.auth.token) ? config.auth.token : null | ||
@@ -27,0 +27,0 @@ } |
@@ -1,2 +0,2 @@ | ||
declare const _default: "1.164.8"; | ||
declare const _default: "1.164.9"; | ||
export default _default; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = "1.164.8"; | ||
exports.default = "1.164.9"; |
{ | ||
"name": "@plattar/sdk-core", | ||
"version": "1.164.8", | ||
"version": "1.164.9", | ||
"description": "Core SDK Module for Generative SDK using API Core", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
78760
1.75%1978
1.59%