conjure-lite
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -1,2 +0,20 @@ | ||
export { conjureFetch } from "./conjureFetch.js"; | ||
export type { ConjureContext } from "./ConjureContext.js"; | ||
interface ConjureContext { | ||
fetchFn?: typeof fetch; | ||
tokenProvider?: () => Promise<string>; | ||
baseUrl: string; | ||
servicePath: string; | ||
} | ||
declare function conjureFetch<T>( | ||
{ fetchFn, baseUrl, servicePath, tokenProvider }: ConjureContext, | ||
url: string, | ||
method: string, | ||
body?: ArrayBuffer | Blob | FormData | URLSearchParams | null | string | {}, | ||
params?: { | ||
[key: string]: string | number | boolean | any[] | undefined | null; | ||
}, | ||
contentType?: "application/json" | "application/octet-stream", | ||
accept?: "application/json" | "application/octet-stream", | ||
): Promise<T>; | ||
export { type ConjureContext, conjureFetch }; |
"use strict"; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
conjureFetch: () => conjureFetch | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
// src/conjureFetch.ts | ||
async function conjureFetch({ fetchFn, baseUrl, servicePath, tokenProvider }, url, method, body, params, contentType, accept) { | ||
async function conjureFetch( | ||
{ fetchFn, baseUrl, servicePath, tokenProvider }, | ||
url, | ||
method, | ||
body, | ||
params, | ||
contentType, | ||
accept, | ||
) { | ||
if (body) { | ||
if (body instanceof URLSearchParams || body instanceof Blob || body instanceof FormData || typeof body === "string" || body instanceof ArrayBuffer) { | ||
} else { | ||
if ( | ||
body instanceof URLSearchParams || body instanceof Blob || body instanceof FormData | ||
|| typeof body === "string" || body instanceof ArrayBuffer | ||
); | ||
else { | ||
body = JSON.stringify(body); | ||
@@ -45,5 +31,7 @@ } | ||
return stringValue.length === 0 ? [] : [[key, stringValue]]; | ||
} | ||
}, | ||
); | ||
const query = Object.keys(queryParams).length === 0 ? "" : `?${new URLSearchParams(queryParams).toString()}`; | ||
const query = Object.keys(queryParams).length === 0 | ||
? "" | ||
: `?${new URLSearchParams(queryParams).toString()}`; | ||
const response = await (fetchFn ?? fetch)(`${baseUrl}${servicePath}${url}${query}`, { | ||
@@ -56,9 +44,10 @@ method, | ||
accept: accept ?? "application/json", | ||
...tokenProvider ? { "Authorization": `Bearer ${await tokenProvider()}` } : {} | ||
...tokenProvider ? { "Authorization": `Bearer ${await tokenProvider()}` } : {}, | ||
}, | ||
...body ? { body } : {} | ||
...body ? { body } : {}, | ||
}); | ||
try { | ||
if (response.status === 204) | ||
if (response.status === 204) { | ||
return void 0; | ||
} | ||
const body2 = await readBody(response); | ||
@@ -80,3 +69,5 @@ if (!response.ok) { | ||
async function readBody(response) { | ||
const contentType = response.headers.get("Content-Type") != null ? response.headers.get("Content-Type") : ""; | ||
const contentType = response.headers.get("Content-Type") != null | ||
? response.headers.get("Content-Type") | ||
: ""; | ||
try { | ||
@@ -94,3 +85,3 @@ if (contentType.includes("application/json")) { | ||
} | ||
var ConjureError = class { | ||
class ConjureError { | ||
type; | ||
@@ -112,13 +103,10 @@ originalError; | ||
status: this.status, | ||
type: this.type | ||
type: this.type, | ||
}, | ||
null, | ||
" " | ||
" ", | ||
); | ||
} | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
conjureFetch | ||
}); | ||
//# sourceMappingURL=index.js.map | ||
} | ||
exports.conjureFetch = conjureFetch; |
{ | ||
"name": "conjure-lite", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"license": "Apache-2.0", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.js" | ||
"import": { | ||
"types": "./dist/index.d.mts", | ||
"default": "./dist/index.mjs" | ||
}, | ||
"require": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
} | ||
} | ||
@@ -16,14 +21,8 @@ }, | ||
"bin": { | ||
"conjure-lite": "bin/conjure-lite.mjs" | ||
"conjure-lite": "./dist/conjure-lite.mjs" | ||
}, | ||
"files": [ | ||
"package.json", | ||
"dist", | ||
"bin" | ||
"dist" | ||
], | ||
"scripts": { | ||
"prepack": "npm run clean && tsup && tsc", | ||
"clean": "rm -rf lib tsconfig.tsbuildinfo dist", | ||
"generateExamples": "npm run prepack && rm -rf examples/widget/src/generated examples/widget/lib examples/widget/tsconfig.tsbuildinfo && ./bin/conjure-lite.mjs generate --ir examples/widget/ir.json --outDir examples/widget/src/generated && tsc --build examples/widget" | ||
}, | ||
"devDependencies": { | ||
@@ -39,3 +38,6 @@ "@microsoft/api-extractor": "^7.38.4", | ||
"tsup": "^8.0.1", | ||
"typescript": "^5.2.2" | ||
"typescript": "^5.2.2", | ||
"@changesets/cli": "^2.27.1", | ||
"@arethetypeswrong/cli": "^0.15.2", | ||
"pkgroll": "^2.0.2" | ||
}, | ||
@@ -45,3 +47,10 @@ "dependencies": { | ||
"yargs": "^17.7.2" | ||
}, | ||
"scripts": { | ||
"clean": "rm -rf lib tsconfig.tsbuildinfo dist", | ||
"build": "pkgroll --target=es2020", | ||
"format": "dprint fmt", | ||
"generateExamples": "rm -rf examples/widget/src/generated examples/widget/lib examples/widget/tsconfig.tsbuildinfo && ./dist/conjure-lite.mjs generate --ir examples/widget/ir.json --outDir examples/widget/src/generated && tsc --build examples/widget", | ||
"check": "pnpm run prepack && attw --pack" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
1
41058
13
11
1307
4