New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.5-test to 0.0.5

CHANGELOG.md

44

dist/index.d.ts

@@ -1,8 +0,26 @@

interface ContentialApiOptions {
secretKey?: string;
interface ApiOptions {
key?: string;
url?: string;
}
interface ContentialApiStreamOptions<ResponseData> {
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;

@@ -13,8 +31,18 @@ }

url: string;
secretKey: string;
constructor(options?: ContentialApiOptions);
stream<ResponseData>({ path, data, onUpdate, }: ContentialApiStreamOptions<ResponseData>): Promise<{} | undefined>;
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?: ContentialApiOptions) => ContentialApi;
declare const getClient: (options?: ApiOptions) => 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 { ApiDeleteOptions, ApiGetOptions, ApiOptions, ApiPatchOptions, ApiPostOptions, ApiPutOptions, ApiStreamOptions, ContentialApi, getApiUrl, getClient, getKey, isClient, isSecretKey, isServer };
"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;

@@ -18,2 +20,10 @@ 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);

@@ -45,16 +55,102 @@ var __async = (__this, __arguments, generator) => {

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 import_axios = __toESM(require("axios"));
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_...)."
);
}
}
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) {

@@ -68,7 +164,7 @@ return __async(this, arguments, function* ({

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

@@ -108,3 +204,2 @@ body: JSON.stringify(data)

}
return {};
} catch (error) {

@@ -122,3 +217,8 @@ console.log(error);

ContentialApi,
getClient
getApiUrl,
getClient,
getKey,
isClient,
isSecretKey,
isServer
});

8

package.json
{
"name": "@contential/api",
"version": "0.0.5-test",
"version": "0.0.5",
"license": "MIT",

@@ -10,4 +10,3 @@ "main": "dist/index.js",

"dependencies": {
"axios": "^1.4.0",
"undici": "^5.22.1"
"axios": "^1.4.0"
},

@@ -19,5 +18,4 @@ "scripts": {

"build:main": "tsup src/index.ts --format cjs,esm --dts",
"lint": "eslint \"**/*.ts*\"",
"publish:prod": "changeset version && changeset publish"
"lint": "eslint \"**/*.ts*\""
}
}

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