Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@contential/api

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contential/api - npm Package Compare versions

Comparing version 0.0.1-test to 0.0.1

CHANGELOG.md

12

dist/index.d.ts
interface ContentialApiOptions {
secretKey?: string;
key?: string;
url?: string;

@@ -13,3 +13,3 @@ }

url: string;
secretKey: string;
key: string;
constructor(options?: ContentialApiOptions);

@@ -20,2 +20,8 @@ stream<ResponseData>({ path, data, onUpdate, }: ContentialApiStreamOptions<ResponseData>): Promise<{} | undefined>;

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}`
},

@@ -120,3 +150,8 @@ body: JSON.stringify(data)

ContentialApi,
getClient
getApiUrl,
getClient,
getKey,
isClient,
isSecretKey,
isServer
});
{
"name": "@contential/api",
"version": "0.0.1-test",
"version": "0.0.1",
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc