@contential/api
Advanced tools
Comparing version 0.0.3-test to 0.0.3
interface ContentialApiOptions { | ||
secretKey?: string; | ||
key?: string; | ||
url?: string; | ||
@@ -13,8 +13,14 @@ } | ||
url: string; | ||
secretKey: string; | ||
key: string; | ||
constructor(options?: ContentialApiOptions); | ||
stream<ResponseData>({ path, data, onUpdate, }: ContentialApiStreamOptions<ResponseData>): Promise<{} | undefined>; | ||
stream<ResponseData>({ path, data, onUpdate, }: ContentialApiStreamOptions<ResponseData>): Promise<void>; | ||
} | ||
declare const getClient: (options?: ContentialApiOptions) => ContentialApi; | ||
export { ContentialApi, ContentialApiOptions, ContentialApiStreamOptions, getClient }; | ||
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 { ContentialApi, ContentialApiOptions, ContentialApiStreamOptions, getApiUrl, getClient, getKey, isClient, isSecretKey, isServer }; |
@@ -44,15 +44,45 @@ "use strict"; | ||
ContentialApi: () => ContentialApi, | ||
getClient: () => getClient | ||
getApiUrl: () => getApiUrl, | ||
getClient: () => getClient, | ||
getKey: () => getKey, | ||
isClient: () => isClient, | ||
isSecretKey: () => isSecretKey, | ||
isServer: () => isServer | ||
}); | ||
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_undici = require("undici"); | ||
var ContentialApi = class { | ||
constructor(options) { | ||
this.url = (options == null ? void 0 : options.url) || process.env.CONTENTIAL_API_URL || "https://api.contential.ai"; | ||
this.secretKey = (options == null ? void 0 : options.secretKey) || process.env.CONTENTIAL_SECRET_KEY || ""; | ||
if (!this.secretKey) { | ||
throw new Error("Missing: secretKey"); | ||
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_...)." | ||
); | ||
} | ||
} | ||
@@ -67,7 +97,7 @@ stream(_0) { | ||
const url = `${this.url}${path}`; | ||
const response = yield (0, import_undici.fetch)(url, { | ||
const response = yield fetch(url, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${this.secretKey}` | ||
Authorization: `Bearer ${this.key}` | ||
}, | ||
@@ -107,3 +137,2 @@ body: JSON.stringify(data) | ||
} | ||
return {}; | ||
} catch (error) { | ||
@@ -121,3 +150,8 @@ console.log(error); | ||
ContentialApi, | ||
getClient | ||
getApiUrl, | ||
getClient, | ||
getKey, | ||
isClient, | ||
isSecretKey, | ||
isServer | ||
}); |
{ | ||
"name": "@contential/api", | ||
"version": "0.0.3-test", | ||
"version": "0.0.3", | ||
"license": "MIT", | ||
@@ -10,4 +10,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"axios": "^1.4.0", | ||
"undici": "^5.22.1" | ||
"axios": "^1.4.0" | ||
}, | ||
@@ -14,0 +13,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
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 2 instances in 1 package
10707
1
1
2
1
7
293
2
- Removedundici@^5.22.1
- Removed@fastify/busboy@2.1.1(transitive)
- Removedundici@5.28.5(transitive)