@topsort/sdk
Advanced tools
+20
-1
@@ -9,2 +9,22 @@ # Changelog | ||
| ## Version 0.3.5 (2025-10-23) | ||
| - fix: install browsers in npm publish job by @jbergstroem in https://github.com/Topsort/topsort.js/pull/174 | ||
| - feat: run e2e tests in PRs by @jbergstroem in https://github.com/Topsort/topsort.js/pull/167 | ||
| - chore(deps): actions/setup-node v6 by @renovate[bot] in https://github.com/Topsort/topsort.js/pull/163 | ||
| - chore(deps): actionlint v1.7.8 by @renovate[bot] in https://github.com/Topsort/topsort.js/pull/161 | ||
| - fix(ci): use correct checkout version by @jbergstroem in https://github.com/Topsort/topsort.js/pull/169 | ||
| - chore(deps): @biomejs/biome v2.2.7 by @renovate[bot] in https://github.com/Topsort/topsort.js/pull/162 | ||
| - chore(deps): @playwright/test v1.56.1 by @renovate[bot] in https://github.com/Topsort/topsort.js/pull/151 | ||
| - chore(deps): typos v1.38.1 by @renovate[bot] in https://github.com/Topsort/topsort.js/pull/141 | ||
| - chore(deps): lefthook v2 by @renovate[bot] in https://github.com/Topsort/topsort.js/pull/171 | ||
| - feat(ci): send test metadata to codecov by @jbergstroem in https://github.com/Topsort/topsort.js/pull/173 | ||
| - feat: pass `fetchOptions` to fetch client by @jbergstroem in https://github.com/Topsort/topsort.js/pull/170 | ||
| - chore: v0.3.5 by @jbergstroem in https://github.com/Topsort/topsort.js/pull/172 | ||
| ## Version 0.3.3 (2025-10-22) | ||
| - Add optional keepalive support for analytics events ([#164](https://github.com/Topsort/topsort.js/pull/164)) | ||
| ## Version 0.3.2 (2024-09-19) | ||
@@ -124,2 +144,1 @@ | ||
| - Add function `createAuction` | ||
+2
-0
@@ -138,2 +138,4 @@ type AuctionType = "banners" | "listings"; | ||
| userAgent?: string; | ||
| /// Optional fetch options to pass to the fetch call. Defaults to { keepalive: true }. | ||
| fetchOptions?: RequestInit; | ||
| } | ||
@@ -140,0 +142,0 @@ |
+1
-1
@@ -1,1 +0,1 @@ | ||
| "use strict";var a=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var s=(r,t)=>a(r,"name",{value:t,configurable:!0});var R=(r,t)=>{for(var e in t)a(r,e,{get:t[e],enumerable:!0})},T=(r,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of C(t))!E.call(r,i)&&i!==e&&a(r,i,{get:()=>t[i],enumerable:!(o=k(t,i))||o.enumerable});return r};var U=r=>T(a({},"__esModule",{value:!0}),r);var $={};R($,{TopsortClient:()=>A});module.exports=U($);var v="https://api.topsort.com",p={auctions:"v2/auctions",events:"v2/events"};var m="0.3.2";var l=class l{constructor(t,e,o,i=!1){this.status=t,this.statusText=e,this.body=o,this.retry=i}};s(l,"AppError");var d=l,n=d;var y=class y{async handleResponse(t){let e;if(t.status!==204&&(e=await t.json()),!t.ok){let o=t.status===429||t.status>=500;throw new n(t.status,t.statusText,e,o)}return e}async request(t,e){try{let o=this.sanitizeUrl(t),i=await fetch(o,e);return this.handleResponse(i)}catch(o){let i=o instanceof Error?o.message:"Unknown error";throw new n(500,"Internal Server Error",i)}}setupTimeoutSignal(t){if(t.timeout!=null){let e=new AbortController;return setTimeout(()=>e.abort(),t.timeout),e.signal}}async post(t,e,o){let i=this.setupTimeoutSignal(o);return this.request(t,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","X-UA":o.userAgent?`@topsort/sdk ${m} ${o.userAgent}`:`@topsort/sdk ${m}`,Authorization:`Bearer ${o.apiKey}`},body:JSON.stringify(e),signal:i})}sanitizeUrl(t){try{return new URL(t).href.replace(/\/+$/,"")}catch(e){throw new n(400,"Invalid URL",{error:`Invalid URL: ${e}`})}}};s(y,"APIClient");var f=y,u=new f;function b(r){if(!r?.apiKey?.length)throw new n(401,"API Key is required.",{})}s(b,"validateConfig");function c(r){return async(...t)=>{let e=t[t.length-1];return b(e),r(...t)}}s(c,"withValidation");async function P(r,t){let e=`${t.host}/${p.auctions}`;return await u.post(e.toString(),r,t)}s(P,"handler");var w=c(P);async function S(r,t){try{let e=`${t.host}/${p.events}`;return await u.post(e,r,t),{ok:!0,retry:!1}}catch(e){if(e instanceof n&&e.retry)return{ok:!1,retry:!0};throw e}}s(S,"handler");var x=c(S);var g=class g{constructor(t){this.config=t,this.config.host=this.config.host??v}async reportEvent(t){return x(t,this.config)}async createAuction(t){return w(t,this.config)}};s(g,"TopsortClient");var h=g,A=h;0&&(module.exports={TopsortClient}); | ||
| var A=Object.defineProperty;var o=(s,t)=>A(s,"name",{value:t,configurable:!0});var g="https://api.topsort.com",a={auctions:"v2/auctions",events:"v2/events"};var c="0.3.5";var d=class d{constructor(t,e,r,n=!1){this.status=t,this.statusText=e,this.body=r,this.retry=n}};o(d,"AppError");var m=d,i=m;var f=class f{async handleResponse(t){let e;if(t.status!==204&&(e=await t.json()),!t.ok){let r=t.status===429||t.status>=500;throw new i(t.status,t.statusText,e,r)}return e}async request(t,e){try{let r=this.sanitizeUrl(t),n=await fetch(r,e);return this.handleResponse(n)}catch(r){let n=r instanceof Error?r.message:"Unknown error";throw new i(500,"Internal Server Error",n)}}setupTimeoutSignal(t){if(t.timeout!=null){let e=new AbortController;return setTimeout(()=>e.abort(),t.timeout),e.signal}}async post(t,e,r){let n=this.setupTimeoutSignal(r),x=r.fetchOptions??{keepalive:!0};return this.request(t,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","X-UA":r.userAgent?`@topsort/sdk ${c} ${r.userAgent}`:`@topsort/sdk ${c}`,Authorization:`Bearer ${r.apiKey}`},body:JSON.stringify(e),signal:n,...x})}sanitizeUrl(t){try{return new URL(t).href.replace(/\/+$/,"")}catch(e){throw new i(400,"Invalid URL",{error:`Invalid URL: ${e}`})}}};o(f,"APIClient");var l=f,p=new l;function v(s){if(!s?.apiKey?.length)throw new i(401,"API Key is required.",{})}o(v,"validateConfig");function u(s){return async(...t)=>{let e=t[t.length-1];return v(e),s(...t)}}o(u,"withValidation");async function C(s,t){let e=`${t.host}/${a.auctions}`;return await p.post(e.toString(),s,t)}o(C,"handler");var b=u(C);async function E(s,t){try{let e=`${t.host}/${a.events}`;return await p.post(e,s,t),{ok:!0,retry:!1}}catch(e){if(e instanceof i&&e.retry)return{ok:!1,retry:!0};throw e}}o(E,"handler");var w=u(E);var y=class y{constructor(t){this.config=t,this.config.host=this.config.host??g}async reportEvent(t){return w(t,this.config)}async createAuction(t){return b(t,this.config)}};o(y,"TopsortClient");var h=y,R=h;export{R as TopsortClient}; |
+20
-14
| { | ||
| "name": "@topsort/sdk", | ||
| "version": "0.3.2", | ||
| "version": "0.3.5", | ||
| "description": "The official Topsort SDK for TypeScript and JavaScript", | ||
| "packageManager": "bun@1.1.28", | ||
| "packageManager": "bun@1.3.1", | ||
| "main": "dist/index.js", | ||
| "module": "dist/index.mjs", | ||
| "author": "Márcio Barbosa <marcio@topsort.com>", | ||
| "type": "module", | ||
| "license": "MIT", | ||
@@ -20,8 +21,8 @@ "repository": { | ||
| "import": { | ||
| "default": "./dist/index.mjs", | ||
| "types": "./dist/index.d.mts" | ||
| "types": "./dist/index.d.mts", | ||
| "default": "./dist/index.mjs" | ||
| }, | ||
| "require": { | ||
| "default": "./dist/index.js", | ||
| "types": "./dist/index.d.ts" | ||
| "types": "./dist/index.d.ts", | ||
| "default": "./dist/index.js" | ||
| } | ||
@@ -50,11 +51,16 @@ } | ||
| "devDependencies": { | ||
| "@biomejs/biome": "1.9.1", | ||
| "@playwright/test": "1.47.1", | ||
| "@types/bun": "1.1.6", | ||
| "lefthook": "1.7.15", | ||
| "msw": "2.4.3", | ||
| "tsup": "8.2.4", | ||
| "typescript": "5.6.2" | ||
| "@biomejs/biome": "2.2.7", | ||
| "@playwright/test": "1.56.1", | ||
| "@types/bun": "1.3.0", | ||
| "lefthook": "2.0.0", | ||
| "msw": "2.11.2", | ||
| "tsup": "8.5.0", | ||
| "typescript": "5.9.3" | ||
| }, | ||
| "keywords": ["topsort", "sdk", "javascript", "typescript"] | ||
| "keywords": [ | ||
| "topsort", | ||
| "sdk", | ||
| "javascript", | ||
| "typescript" | ||
| ] | ||
| } |
+27
-7
@@ -10,9 +10,17 @@ # Topsort SDK | ||
| - [Installation](#installation) | ||
| - [Usage](#usage) | ||
| - [Creating an Auction](#auctions) | ||
| - [Reporting an Event](#events) | ||
| - [Retryable Errors](#retryable-errors) | ||
| - [Contributing](#contributing) | ||
| - [License](#license) | ||
| - [Topsort SDK](#topsort-sdk) | ||
| - [Table of Contents](#table-of-contents) | ||
| - [Installation](#installation) | ||
| - [Usage](#usage) | ||
| - [Auctions](#auctions) | ||
| - [Parameters](#parameters) | ||
| - [Config Parameters](#config-parameters) | ||
| - [Sample response](#sample-response) | ||
| - [Events](#events) | ||
| - [Parameters](#parameters-1) | ||
| - [Config Parameters](#config-parameters-1) | ||
| - [Sample response](#sample-response-1) | ||
| - [Retryable Errors](#retryable-errors) | ||
| - [Contributing](#contributing) | ||
| - [License](#license) | ||
@@ -80,5 +88,11 @@ ## Installation | ||
| - `timeout`: Optional timeout in milliseconds. Default is 30 seconds. If timeout is reached, the call will be rejected with an [AbortError](https://developer.mozilla.org/en-US/docs/Web/API/DOMException#aborterror). | ||
| - `fetchOptions`: Optional fetch options to pass to the fetch call. Defaults to `{ keepalive: true }`. | ||
| `auctionDetails`: An object containing the details of the auction to be created, please refer to [Topsort's Auction API doc](https://docs.topsort.com/reference/createauctions) for body specification. | ||
| ##### Overriding fetch options | ||
| By default, we pass `{ keepalive: true }` to fetch while making requests to our APIs. If you want to pass other options | ||
| or disable fetch due to the browser/engine version required, you can do so by overriding the `fetchOptions` object. | ||
| #### Sample response | ||
@@ -159,2 +173,8 @@ | ||
| ##### Config Parameters | ||
| - `apiKey`: Your Topsort API Key | ||
| - `userAgent`: Optional user agent to be added as part of the request. Example: `Mozilla/5.0` | ||
| - `timeout`: Optional timeout in milliseconds. Default is 30 seconds. If timeout is reached, the call will be rejected with an [AbortError](https://developer.mozilla.org/en-US/docs/Web/API/DOMException#aborterror). | ||
| - `fetchOptions`: Optional fetch options to pass to the fetch call. Defaults to `{ keepalive: true }`. When keepalive is enabled, requests will continue even if the page is being unloaded, which is useful for analytics and event tracking. | ||
| `event`: An object containing the details of the event to be reported, please refer to [Topsort's Event API doc](https://docs.topsort.com/reference/reportevents) for body specification. | ||
@@ -161,0 +181,0 @@ |
-147
| type AuctionType = "banners" | "listings"; | ||
| type DeviceType = "desktop" | "mobile"; | ||
| interface GeoTargeting { | ||
| location: string; | ||
| } | ||
| interface AuctionSingleCategory { | ||
| id: string; | ||
| } | ||
| interface AuctionMultipleCategories { | ||
| ids: string[]; | ||
| } | ||
| interface AuctionDisjunctiveCategories { | ||
| disjunctions: string[][]; | ||
| } | ||
| interface AuctionProduct { | ||
| ids: string[]; | ||
| qualityScores?: number[]; | ||
| } | ||
| interface AuctionBase { | ||
| category?: AuctionSingleCategory | AuctionMultipleCategories | AuctionDisjunctiveCategories; | ||
| geoTargeting?: GeoTargeting; | ||
| products?: AuctionProduct; | ||
| searchQuery?: string; | ||
| slots: number; | ||
| type: AuctionType; | ||
| } | ||
| interface SponsoredListingAuction extends AuctionBase { | ||
| type: "listings"; | ||
| } | ||
| interface BannerAuction extends AuctionBase { | ||
| device?: DeviceType; | ||
| slotId: string; | ||
| type: "banners"; | ||
| } | ||
| interface Auction { | ||
| auctions: (SponsoredListingAuction | BannerAuction)[]; | ||
| } | ||
| interface Asset { | ||
| url: string; | ||
| } | ||
| interface Winner { | ||
| asset: Asset[]; | ||
| id: string; | ||
| rank: number; | ||
| resolvedBidId: string; | ||
| type: string; | ||
| } | ||
| interface Result { | ||
| error: boolean; | ||
| resultType: AuctionType; | ||
| winners: Winner[]; | ||
| } | ||
| interface AuctionResult { | ||
| results: Result[]; | ||
| } | ||
| interface Placement { | ||
| categoryIds?: string[]; | ||
| page?: number; | ||
| pageSize?: number; | ||
| path: string; | ||
| position?: number; | ||
| productId?: string; | ||
| searchQuery?: string; | ||
| } | ||
| interface Entity { | ||
| id: string; | ||
| type: "product" | "vendor"; | ||
| } | ||
| interface Impression { | ||
| additionalAttribution?: Entity; | ||
| entity?: Entity; | ||
| id: string; | ||
| occurredAt: string; | ||
| opaqueUserId: string; | ||
| placement?: Placement; | ||
| resolvedBidId?: string; | ||
| } | ||
| interface Click { | ||
| additionalAttribution?: Entity; | ||
| entity?: Entity; | ||
| id: string; | ||
| occurredAt: string; | ||
| opaqueUserId: string; | ||
| placement?: Placement; | ||
| resolvedBidId?: string; | ||
| } | ||
| interface Item { | ||
| productId: string; | ||
| quantity: number; | ||
| unitPrice: number; | ||
| vendorId?: string; | ||
| } | ||
| interface Purchase { | ||
| id: string; | ||
| items: Item[]; | ||
| occurredAt: string; | ||
| opaqueUserId: string; | ||
| } | ||
| interface Event { | ||
| clicks?: Click[]; | ||
| impressions?: Impression[]; | ||
| purchases?: Purchase[]; | ||
| } | ||
| interface EventResult { | ||
| ok: boolean; | ||
| retry: boolean; | ||
| } | ||
| interface Config { | ||
| /// The API key to use for requests. | ||
| apiKey: string; | ||
| /// An optional alternative host to use for requests. | ||
| host?: string; | ||
| /// An optional timeout for requests in milliseconds. | ||
| timeout?: number; | ||
| userAgent?: string; | ||
| } | ||
| declare class TopsortClient { | ||
| private config; | ||
| constructor(config: Config); | ||
| reportEvent(event: Event): Promise<EventResult>; | ||
| createAuction(auction: Auction): Promise<AuctionResult>; | ||
| } | ||
| export { type Auction, type AuctionResult, type Click, type Config, type Entity, type Event, type EventResult, type Impression, type Item, type Placement, type Purchase, TopsortClient }; |
| var x=Object.defineProperty;var o=(s,t)=>x(s,"name",{value:t,configurable:!0});var g="https://api.topsort.com",a={auctions:"v2/auctions",events:"v2/events"};var c="0.3.2";var d=class d{constructor(t,e,r,n=!1){this.status=t,this.statusText=e,this.body=r,this.retry=n}};o(d,"AppError");var m=d,i=m;var f=class f{async handleResponse(t){let e;if(t.status!==204&&(e=await t.json()),!t.ok){let r=t.status===429||t.status>=500;throw new i(t.status,t.statusText,e,r)}return e}async request(t,e){try{let r=this.sanitizeUrl(t),n=await fetch(r,e);return this.handleResponse(n)}catch(r){let n=r instanceof Error?r.message:"Unknown error";throw new i(500,"Internal Server Error",n)}}setupTimeoutSignal(t){if(t.timeout!=null){let e=new AbortController;return setTimeout(()=>e.abort(),t.timeout),e.signal}}async post(t,e,r){let n=this.setupTimeoutSignal(r);return this.request(t,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","X-UA":r.userAgent?`@topsort/sdk ${c} ${r.userAgent}`:`@topsort/sdk ${c}`,Authorization:`Bearer ${r.apiKey}`},body:JSON.stringify(e),signal:n})}sanitizeUrl(t){try{return new URL(t).href.replace(/\/+$/,"")}catch(e){throw new i(400,"Invalid URL",{error:`Invalid URL: ${e}`})}}};o(f,"APIClient");var l=f,p=new l;function v(s){if(!s?.apiKey?.length)throw new i(401,"API Key is required.",{})}o(v,"validateConfig");function u(s){return async(...t)=>{let e=t[t.length-1];return v(e),s(...t)}}o(u,"withValidation");async function k(s,t){let e=`${t.host}/${a.auctions}`;return await p.post(e.toString(),s,t)}o(k,"handler");var b=u(k);async function C(s,t){try{let e=`${t.host}/${a.events}`;return await p.post(e,s,t),{ok:!0,retry:!1}}catch(e){if(e instanceof i&&e.retry)return{ok:!1,retry:!0};throw e}}o(C,"handler");var w=u(C);var h=class h{constructor(t){this.config=t,this.config.host=this.config.host??g}async reportEvent(t){return w(t,this.config)}async createAuction(t){return b(t,this.config)}};o(h,"TopsortClient");var y=h,E=y;export{E as TopsortClient}; |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
3
-25%221
9.95%Yes
NaN19621
-10.76%6
-25%133
-5.67%3
50%