@contential/api
Advanced tools
Comparing version 0.0.6 to 0.0.7
# @contential/api | ||
## 0.0.6 | ||
## 0.0.7 | ||
### Patch Changes | ||
- 58e0d1b: Updated description | ||
## 0.0.5 | ||
### Patch Changes | ||
- 6ab087e: Test 1 | ||
## 0.0.4 | ||
### Patch Changes | ||
- 4c55e13: Updated api | ||
- daa1c7a: Updated api description |
@@ -1,47 +0,3 @@ | ||
interface ApiOptions { | ||
key?: string; | ||
url?: string; | ||
} | ||
interface ApiGetOptions { | ||
path: string; | ||
} | ||
interface ApiPostOptions { | ||
path: string; | ||
data?: unknown; | ||
} | ||
interface ApiPutOptions { | ||
path: string; | ||
data?: unknown; | ||
} | ||
interface ApiPatchOptions { | ||
path: string; | ||
data?: unknown; | ||
} | ||
interface ApiDeleteOptions { | ||
path: string; | ||
} | ||
interface ApiStreamOptions<ResponseData> { | ||
path: string; | ||
data?: unknown; | ||
onUpdate: (data: ResponseData) => void; | ||
} | ||
declare function api(): string; | ||
declare class ContentialApi { | ||
url: string; | ||
key: string; | ||
constructor(options?: ApiOptions); | ||
get<ResponseData>({ path }: ApiGetOptions): Promise<ResponseData>; | ||
post<ResponseData>({ path, data }: ApiPostOptions): Promise<ResponseData>; | ||
put<ResponseData>({ path, data }: ApiPutOptions): Promise<ResponseData>; | ||
patch<ResponseData>({ path, data }: ApiPatchOptions): Promise<ResponseData>; | ||
stream<ResponseData>({ path, data, onUpdate, }: ApiStreamOptions<ResponseData>): Promise<void>; | ||
} | ||
declare const getClient: (options?: ApiOptions) => ContentialApi; | ||
declare const isServer: () => boolean; | ||
declare const isClient: () => boolean; | ||
declare const isSecretKey: (key: string) => boolean; | ||
declare const getApiUrl: (url: string | undefined) => string; | ||
declare const getKey: (key: string | undefined) => string; | ||
export { ApiDeleteOptions, ApiGetOptions, ApiOptions, ApiPatchOptions, ApiPostOptions, ApiPutOptions, ApiStreamOptions, ContentialApi, getApiUrl, getClient, getKey, isClient, isSecretKey, isServer }; | ||
export { api }; |
"use strict"; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
@@ -20,31 +18,3 @@ var __export = (target, all) => { | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
var __async = (__this, __arguments, generator) => { | ||
return new Promise((resolve, reject) => { | ||
var fulfilled = (value) => { | ||
try { | ||
step(generator.next(value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}; | ||
var rejected = (value) => { | ||
try { | ||
step(generator.throw(value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}; | ||
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); | ||
step((generator = generator.apply(__this, __arguments)).next()); | ||
}); | ||
}; | ||
@@ -54,168 +24,13 @@ // src/index.ts | ||
__export(src_exports, { | ||
ContentialApi: () => ContentialApi, | ||
getApiUrl: () => getApiUrl, | ||
getClient: () => getClient, | ||
getKey: () => getKey, | ||
isClient: () => isClient, | ||
isSecretKey: () => isSecretKey, | ||
isServer: () => isServer | ||
api: () => api | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
// src/utils.ts | ||
var isServer = () => { | ||
return !(typeof window != "undefined" && window.document); | ||
}; | ||
var isClient = () => { | ||
return !isServer(); | ||
}; | ||
var isSecretKey = (key) => { | ||
return key.startsWith("sk_"); | ||
}; | ||
var getApiUrl = (url) => { | ||
if (url) | ||
return url; | ||
return process.env.CONTENTIAL_API_URL || process.env.NEXT_PUBLIC_CONTENTIAL_API_URL || process.env.VITE_CONTENTIAL_API_URL || process.env.REACT_APP_CONTENTIAL_API_URL || process.env.GATSBY_CONTENTIAL_API_URL || "https://api.contential.ai"; | ||
}; | ||
var getKey = (key) => { | ||
if (key) | ||
return key; | ||
return process.env.CONTENTIAL_SECRET_KEY || process.env.CONTENTIAL_PUBLISHABLE_KEY || process.env.NEXT_PUBLIC_CONTENTIAL_PUBLISHABLE_KEY || process.env.VITE_CONTENTIAL_PUBLISHABLE_KEY || process.env.REACT_APP_CONTENTIAL_PUBLISHABLE_KEY || process.env.GATSBY_CONTENTIAL_PUBLISHABLE_KEY || ""; | ||
}; | ||
// src/api.ts | ||
var import_axios = __toESM(require("axios")); | ||
var ContentialApi = class { | ||
constructor(options) { | ||
this.url = getApiUrl(options == null ? void 0 : options.url); | ||
this.key = getKey(options == null ? void 0 : options.key); | ||
if (!this.key) { | ||
throw new Error("Missing: key"); | ||
} | ||
if (isClient() && isSecretKey(this.key)) { | ||
throw new Error( | ||
"Using secret key on client is not allowed. Please use publishable key instead (pk_...)." | ||
); | ||
} | ||
} | ||
get(_0) { | ||
return __async(this, arguments, function* ({ path }) { | ||
const url = `${this.url}${path}`; | ||
const response = yield (0, import_axios.default)({ | ||
url, | ||
method: "GET", | ||
headers: { | ||
Authorization: `Bearer ${this.key}` | ||
} | ||
}); | ||
return response.data; | ||
}); | ||
} | ||
post(_0) { | ||
return __async(this, arguments, function* ({ path, data }) { | ||
const url = `${this.url}${path}`; | ||
const response = yield (0, import_axios.default)({ | ||
url, | ||
method: "POST", | ||
headers: { | ||
Authorization: `Bearer ${this.key}` | ||
}, | ||
data | ||
}); | ||
return response.data; | ||
}); | ||
} | ||
put(_0) { | ||
return __async(this, arguments, function* ({ path, data }) { | ||
const url = `${this.url}${path}`; | ||
const response = yield (0, import_axios.default)({ | ||
url, | ||
method: "PUT", | ||
headers: { | ||
Authorization: `Bearer ${this.key}` | ||
}, | ||
data | ||
}); | ||
return response.data; | ||
}); | ||
} | ||
patch(_0) { | ||
return __async(this, arguments, function* ({ path, data }) { | ||
const url = `${this.url}${path}`; | ||
const response = yield (0, import_axios.default)({ | ||
url, | ||
method: "PATCH", | ||
headers: { | ||
Authorization: `Bearer ${this.key}` | ||
}, | ||
data | ||
}); | ||
return response.data; | ||
}); | ||
} | ||
stream(_0) { | ||
return __async(this, arguments, function* ({ | ||
path, | ||
data, | ||
onUpdate | ||
}) { | ||
try { | ||
const url = `${this.url}${path}`; | ||
const response = yield fetch(url, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${this.key}` | ||
}, | ||
body: JSON.stringify(data) | ||
}); | ||
if (!response.ok) { | ||
throw new Error(response.statusText); | ||
} | ||
const body = response.body; | ||
if (!body) { | ||
return; | ||
} | ||
const start = Date.now(); | ||
const reader = body.getReader(); | ||
const decoder = new TextDecoder(); | ||
let isDone = false; | ||
while (!isDone) { | ||
try { | ||
const { value, done } = yield reader.read(); | ||
const chunkValue = decoder.decode(value); | ||
const dataString = chunkValue.split("data: ")[1] || chunkValue; | ||
try { | ||
const data2 = JSON.parse(dataString); | ||
onUpdate(data2); | ||
} catch (error) { | ||
} | ||
if (chunkValue.includes("[DONE]")) { | ||
const end = Date.now(); | ||
const totalTime = end - start; | ||
} | ||
isDone = done; | ||
} catch (error) { | ||
isDone = true; | ||
console.log(error); | ||
} | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}); | ||
} | ||
}; | ||
var getClient = (options) => { | ||
return new ContentialApi(options); | ||
}; | ||
// src/lib/api.ts | ||
function api() { | ||
return "api"; | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
ContentialApi, | ||
getApiUrl, | ||
getClient, | ||
getKey, | ||
isClient, | ||
isSecretKey, | ||
isServer | ||
api | ||
}); |
{ | ||
"name": "@contential/api", | ||
"description": "A simple API wrapper for Contential", | ||
"version": "0.0.6", | ||
"license": "MIT", | ||
"description": "Contential API Client", | ||
"version": "0.0.7", | ||
"main": "dist/index.js", | ||
@@ -10,12 +9,5 @@ "module": "dist/index.mjs", | ||
"private": false, | ||
"dependencies": { | ||
"axios": "^1.4.0" | ||
}, | ||
"scripts": { | ||
"dev": "tsup src/index.ts --format cjs,esm --dts --watch", | ||
"clean": "rimraf dist", | ||
"build": "npm-run-all clean build:main", | ||
"build:main": "tsup src/index.ts --format cjs,esm --dts", | ||
"lint": "eslint \"**/*.ts*\"" | ||
"build": "tsup" | ||
} | ||
} |
@@ -1,1 +0,11 @@ | ||
# Contential - API Client | ||
# api | ||
This library was generated with [Nx](https://nx.dev). | ||
## Building | ||
Run `nx build api` to build the library. | ||
## Running unit tests | ||
Run `nx test api` to execute the unit tests via [Jest](https://jestjs.io). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 11 instances in 1 package
0
17
12
1
1
5107
1
190
- Removedaxios@^1.4.0
- Removedasynckit@0.4.0(transitive)
- Removedaxios@1.7.9(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedfollow-redirects@1.15.9(transitive)
- Removedform-data@4.0.1(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedproxy-from-env@1.1.0(transitive)