@cohostvip/cohost-node 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -123,4 +123,14 @@ declare class CohostClient {
123
123
  constructor({ token, settings }: CohostClientOptions);
124
124
  }
125
125
 
126
- export { CohostClient };
126
+ /**
127
+ * Factory method for creating a CohostClient instance.
128
+ *
129
+ * Example:
130
+ * ```ts
131
+ * const client = createCohostClient({ token: 'your-token' });
132
+ * ```
133
+ */
134
+ declare function createCohostClient(options: CohostClientOptions): CohostClient;
135
+
136
+ export { CohostClient, createCohostClient };
package/dist/index.d.ts CHANGED
@@ -123,4 +123,14 @@ declare class CohostClient {
123
123
  constructor({ token, settings }: CohostClientOptions);
124
124
  }
125
125
 
126
- export { CohostClient };
126
+ /**
127
+ * Factory method for creating a CohostClient instance.
128
+ *
129
+ * Example:
130
+ * ```ts
131
+ * const client = createCohostClient({ token: 'your-token' });
132
+ * ```
133
+ */
134
+ declare function createCohostClient(options: CohostClientOptions): CohostClient;
135
+
136
+ export { CohostClient, createCohostClient };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var u=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var w=(e,t,s)=>t in e?u(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var F=(e,t)=>{for(var s in t)u(e,s,{get:t[s],enumerable:!0})},U=(e,t,s,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of E(t))!T.call(e,o)&&o!==s&&u(e,o,{get:()=>t[o],enumerable:!(n=P(t,o))||n.enumerable});return e};var O=e=>U(u({},"__esModule",{value:!0}),e);var a=(e,t,s)=>w(e,typeof t!="symbol"?t+"":t,s);var B={};F(B,{CohostClient:()=>h});module.exports=O(B);var p=class{constructor(t,s){a(this,"request");a(this,"settings");this.request=t,this.settings=s}};var d=class extends p{async fetch(t){return this.request(`/events/${t}`)}async tickets(t){return this.request(`/events/${t}/tickets`)}};var g=class extends p{async fetch(t,s){return this.request(`/orders/${t}`)}};var l="https://api.cohost.com/v1";var S=({token:e,baseUrl:t=l,debug:s=!1})=>async(n,{method:o="GET",data:m,query:q,headers:x={}}={})=>{let $=q?"?"+new URLSearchParams(Object.entries(q).reduce((c,[b,R])=>(R!==void 0&&(c[b]=String(R)),c),{})).toString():"",y=`${t}${n}${$}`,C={"Content-Type":"application/json",...x};e&&(C.Authorization=`Bearer ${e}`);let f=m&&o!=="GET"?JSON.stringify(m):void 0;s&&(console.log(`[Cohost SDK] Request: ${o} ${y}`),f&&console.log("[Cohost SDK] Body:",f));let i=await fetch(y,{method:o,headers:C,body:f}),r=i.headers.get("content-type")?.includes("application/json")?await i.json():await i.text();if(!i.ok){let c=typeof r=="string"?r:JSON.stringify(r);throw new Error(`[Cohost SDK] ${i.status} ${i.statusText}: ${c}`)}return typeof r=="object"&&r!==null&&r.status==="ok"&&"data"in r?r.data:r};var h=class{constructor({token:t,settings:s={}}){a(this,"events");a(this,"orders");let n=S({token:t,baseUrl:s.apiUrl||l,debug:s.debug});this.events=new d(n,s),this.orders=new g(n,s)}};0&&(module.exports={CohostClient});
1
+ "use strict";var d=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var O=(e,t,s)=>t in e?d(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var T=(e,t)=>{for(var s in t)d(e,s,{get:t[s],enumerable:!0})},F=(e,t,s,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of w(t))!E.call(e,o)&&o!==s&&d(e,o,{get:()=>t[o],enumerable:!(n=P(t,o))||n.enumerable});return e};var U=e=>F(d({},"__esModule",{value:!0}),e);var a=(e,t,s)=>O(e,typeof t!="symbol"?t+"":t,s);var j={};T(j,{CohostClient:()=>c,createCohostClient:()=>B});module.exports=U(j);var p=class{constructor(t,s){a(this,"request");a(this,"settings");this.request=t,this.settings=s}};var l=class extends p{async fetch(t){return this.request(`/events/${t}`)}async tickets(t){return this.request(`/events/${t}/tickets`)}};var h=class extends p{async fetch(t,s){return this.request(`/orders/${t}`)}};var g="https://api.cohost.com/v1";var x=({token:e,baseUrl:t=g,debug:s=!1})=>async(n,{method:o="GET",data:C,query:m,headers:S={}}={})=>{let $=m?"?"+new URLSearchParams(Object.entries(m).reduce((u,[b,R])=>(R!==void 0&&(u[b]=String(R)),u),{})).toString():"",q=`${t}${n}${$}`,y={"Content-Type":"application/json",...S};e&&(y.Authorization=`Bearer ${e}`);let f=C&&o!=="GET"?JSON.stringify(C):void 0;s&&(console.log(`[Cohost SDK] Request: ${o} ${q}`),f&&console.log("[Cohost SDK] Body:",f));let i=await fetch(q,{method:o,headers:y,body:f}),r=i.headers.get("content-type")?.includes("application/json")?await i.json():await i.text();if(!i.ok){let u=typeof r=="string"?r:JSON.stringify(r);throw new Error(`[Cohost SDK] ${i.status} ${i.statusText}: ${u}`)}return typeof r=="object"&&r!==null&&r.status==="ok"&&"data"in r?r.data:r};var c=class{constructor({token:t,settings:s={}}){a(this,"events");a(this,"orders");let n=x({token:t,baseUrl:s.apiUrl||g,debug:s.debug});this.events=new l(n,s),this.orders=new h(n,s)}};function B(e){return new c(e)}0&&(module.exports={CohostClient,createCohostClient});
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/endpoint.ts","../src/api/events.ts","../src/api/orders.ts","../src/apiVersion.ts","../src/http/request.ts","../src/client.ts"],"sourcesContent":["export {\n CohostClient } from './client';","import { RequestFn } from \"./http/request\";\nimport { CohostClientSettings } from \"./settings\";\n\n/**\n * Base class for all API endpoint groups within the Cohost SDK.\n * Provides shared access to the configured request function and settings.\n */\nexport class CohostEndpoint {\n /** Shared request function injected from the client */\n protected request: RequestFn;\n\n /** Client settings passed during instantiation */\n protected settings: CohostClientSettings;\n\n /**\n * Constructs a new endpoint group.\n *\n * @param request - The shared request function for performing API calls\n * @param settings - The client-wide settings passed from the parent client\n */\n constructor(request: RequestFn, settings: CohostClientSettings) {\n this.request = request;\n this.settings = settings;\n }\n}\n","// src/api/EventsAPI.ts\n\nimport { CohostEndpoint } from '../endpoint';\n\n/**\n * Provides methods to interact with the Cohost Events API.\n * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const event = await client.events.fetch('event-id');\n * const tickets = await client.events.tickets('event-id');\n * ```\n */\nexport class EventsAPI extends CohostEndpoint {\n /**\n * Fetch a single event by ID.\n * \n * @param id - The unique identifier of the event\n * @returns A Promise resolving to the event object\n * @throws Will throw an error if the request fails or the event is not found\n */\n async fetch(id: string) {\n return this.request(`/events/${id}`);\n }\n\n /**\n * List all tickets associated with a specific event.\n * \n * @param id - The unique identifier of the event\n * @returns A Promise resolving to an array of ticket objects\n * @throws Will throw an error if the request fails or the event does not exist\n */\n async tickets(id: string) {\n return this.request(`/events/${id}/tickets`);\n }\n}\n","// src/api/OrdersAPI.ts\n\nimport { CohostEndpoint } from '../endpoint';\n\n/**\n * Provides methods to interact with the Cohost Orders API.\n * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const order = await client.orders.fetch('order-id', 'user-id');\n * ```\n */\nexport class OrdersAPI extends CohostEndpoint {\n /**\n * Fetch a single order by ID.\n * \n * @param id - The unique identifier of the order\n * @param uid - The unique user ID associated with the order (currently unused but reserved for future auth context)\n * @returns A Promise resolving to the order object\n * @throws Will throw an error if the request fails or the order is not found\n */\n async fetch(id: string, uid: string) {\n // uid is reserved for future scoped access/auth features\n return this.request(`/orders/${id}`);\n }\n}\n","export const apiVersion = '0.1.0';\nexport const apiVersionDate = '2025-04-15';\nexport const apiBaseUrl = 'https://api.cohost.com/v1'","import { apiBaseUrl } from \"../apiVersion\";\n\n/**\n * Options for configuring the request handler.\n */\ninterface RequestProps {\n /** API token for authentication (Bearer token). */\n token: string | null;\n\n /** Base URL of the API (defaults to versioned `apiBaseUrl`). */\n baseUrl?: string;\n\n /** Enable debug logging of requests/responses. */\n debug?: boolean;\n}\n\n/**\n * Supported HTTP methods.\n */\ntype RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n\n/**\n * A function that performs a request to the Cohost API.\n */\ntype RequestFn = (\n /** Path of the request relative to baseUrl */\n path: string,\n options?: {\n /** HTTP method (defaults to 'GET') */\n method?: RequestMethod;\n\n /** Request body data (auto-serialized as JSON) */\n data?: any;\n\n /** Query parameters to be appended to the URL */\n query?: Record<string, string | number | boolean | undefined>;\n\n /** Additional headers to merge into the request */\n headers?: Record<string, string>;\n }\n) => Promise<any>;\n\n/**\n * Creates a request function configured with authentication and defaults.\n */\nconst request = ({ token, baseUrl = apiBaseUrl, debug = false }: RequestProps): RequestFn => {\n return async (path, { method = 'GET', data, query, headers = {} } = {}) => {\n const queryString = query\n ? '?' + new URLSearchParams(\n Object.entries(query).reduce((acc, [key, value]) => {\n if (value !== undefined) acc[key] = String(value);\n return acc;\n }, {} as Record<string, string>)\n ).toString()\n : '';\n\n const url = `${baseUrl}${path}${queryString}`;\n\n const reqHeaders: Record<string, string> = {\n 'Content-Type': 'application/json',\n ...headers,\n };\n\n if (token) {\n reqHeaders['Authorization'] = `Bearer ${token}`;\n }\n\n const body = data && method !== 'GET' ? JSON.stringify(data) : undefined;\n\n if (debug) {\n console.log(`[Cohost SDK] Request: ${method} ${url}`);\n if (body) console.log(`[Cohost SDK] Body:`, body);\n }\n\n const res = await fetch(url, {\n method,\n headers: reqHeaders,\n body,\n });\n\n const isJson = res.headers.get('content-type')?.includes('application/json');\n const responseBody = isJson ? await res.json() : await res.text();\n\n if (!res.ok) {\n const message = typeof responseBody === 'string' ? responseBody : JSON.stringify(responseBody);\n throw new Error(`[Cohost SDK] ${res.status} ${res.statusText}: ${message}`);\n }\n\n if (typeof responseBody === 'object' && responseBody !== null && responseBody.status === 'ok' && 'data' in responseBody) {\n return responseBody.data;\n }\n\n return responseBody;\n };\n};\n\nexport { request, RequestProps, RequestFn };\n","import { EventsAPI } from './api/events';\nimport { OrdersAPI } from './api/orders';\nimport { apiBaseUrl } from './apiVersion';\nimport { request, RequestFn } from './http/request';\nimport { CohostClientSettings } from './settings';\n\n/**\n * Configuration options for instantiating a CohostClient.\n */\nexport interface CohostClientOptions {\n /** API token used for authenticated requests. */\n token: string;\n\n /** Optional client settings such as debug mode or custom API URL. */\n settings?: CohostClientSettings;\n}\n\n/**\n * CohostClient provides grouped access to various API modules such as Events and Orders.\n * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const event = await client.events.fetch('event-id');\n * const order = await client.orders.fetch('order-id', 'user-id');\n * ```\n */\nexport class CohostClient {\n /** Access to Event-related endpoints */\n readonly events: EventsAPI;\n\n /** Access to Order-related endpoints */\n readonly orders: OrdersAPI;\n\n constructor({ token, settings = {} }: CohostClientOptions) {\n const sharedRequest: RequestFn = request({\n token,\n baseUrl: settings.apiUrl || apiBaseUrl,\n debug: settings.debug,\n });\n\n this.events = new EventsAPI(sharedRequest, settings);\n this.orders = new OrdersAPI(sharedRequest, settings);\n }\n}\n"],"mappings":"ijBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,IAAA,eAAAC,EAAAH,GCOO,IAAMI,EAAN,KAAqB,CAa1B,YAAYC,EAAoBC,EAAgC,CAXhEC,EAAA,KAAU,WAGVA,EAAA,KAAU,YASR,KAAK,QAAUF,EACf,KAAK,SAAWC,CAClB,CACF,ECVO,IAAME,EAAN,cAAwBC,CAAe,CAQ5C,MAAM,MAAMC,EAAY,CACtB,OAAO,KAAK,QAAQ,WAAWA,CAAE,EAAE,CACrC,CASA,MAAM,QAAQA,EAAY,CACxB,OAAO,KAAK,QAAQ,WAAWA,CAAE,UAAU,CAC7C,CACF,ECvBO,IAAMC,EAAN,cAAwBC,CAAe,CAS5C,MAAM,MAAMC,EAAYC,EAAa,CAE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Aa,SAAW,MAAQ,SAAUA,EAChGA,EAAa,KAGjBA,CACX,EClEG,IAAME,EAAN,KAAmB,CAOxB,YAAY,CAAE,MAAAC,EAAO,SAAAC,EAAW,CAAC,CAAE,EAAwB,CAL3DC,EAAA,KAAS,UAGTA,EAAA,KAAS,UAGP,IAAMC,EAA2BC,EAAQ,CACvC,MAAAJ,EACA,QAASC,EAAS,QAAUI,EAC5B,MAAOJ,EAAS,KAClB,CAAC,EAED,KAAK,OAAS,IAAIK,EAAUH,EAAeF,CAAQ,EACnD,KAAK,OAAS,IAAIM,EAAUJ,EAAeF,CAAQ,CACrD,CACF","names":["index_exports","__export","CohostClient","__toCommonJS","CohostEndpoint","request","settings","__publicField","EventsAPI","CohostEndpoint","id","OrdersAPI","CohostEndpoint","id","uid","apiBaseUrl","request","token","baseUrl","apiBaseUrl","debug","path","method","data","query","headers","queryString","acc","key","value","url","reqHeaders","body","res","responseBody","message","CohostClient","token","settings","__publicField","sharedRequest","request","apiBaseUrl","EventsAPI","OrdersAPI"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/endpoint.ts","../src/api/events.ts","../src/api/orders.ts","../src/apiVersion.ts","../src/http/request.ts","../src/client.ts"],"sourcesContent":["import { CohostClient, CohostClientOptions } from './client';\n\n/**\n * Factory method for creating a CohostClient instance.\n * \n * Example:\n * ```ts\n * const client = createCohostClient({ token: 'your-token' });\n * ```\n */\nexport function createCohostClient(options: CohostClientOptions): CohostClient {\n return new CohostClient(options);\n}\n\n\nexport { CohostClient }","import { RequestFn } from \"./http/request\";\nimport { CohostClientSettings } from \"./settings\";\n\n/**\n * Base class for all API endpoint groups within the Cohost SDK.\n * Provides shared access to the configured request function and settings.\n */\nexport class CohostEndpoint {\n /** Shared request function injected from the client */\n protected request: RequestFn;\n\n /** Client settings passed during instantiation */\n protected settings: CohostClientSettings;\n\n /**\n * Constructs a new endpoint group.\n *\n * @param request - The shared request function for performing API calls\n * @param settings - The client-wide settings passed from the parent client\n */\n constructor(request: RequestFn, settings: CohostClientSettings) {\n this.request = request;\n this.settings = settings;\n }\n}\n","// src/api/EventsAPI.ts\n\nimport { CohostEndpoint } from '../endpoint';\n\n/**\n * Provides methods to interact with the Cohost Events API.\n * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const event = await client.events.fetch('event-id');\n * const tickets = await client.events.tickets('event-id');\n * ```\n */\nexport class EventsAPI extends CohostEndpoint {\n /**\n * Fetch a single event by ID.\n * \n * @param id - The unique identifier of the event\n * @returns A Promise resolving to the event object\n * @throws Will throw an error if the request fails or the event is not found\n */\n async fetch(id: string) {\n return this.request(`/events/${id}`);\n }\n\n /**\n * List all tickets associated with a specific event.\n * \n * @param id - The unique identifier of the event\n * @returns A Promise resolving to an array of ticket objects\n * @throws Will throw an error if the request fails or the event does not exist\n */\n async tickets(id: string) {\n return this.request(`/events/${id}/tickets`);\n }\n}\n","// src/api/OrdersAPI.ts\n\nimport { CohostEndpoint } from '../endpoint';\n\n/**\n * Provides methods to interact with the Cohost Orders API.\n * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const order = await client.orders.fetch('order-id', 'user-id');\n * ```\n */\nexport class OrdersAPI extends CohostEndpoint {\n /**\n * Fetch a single order by ID.\n * \n * @param id - The unique identifier of the order\n * @param uid - The unique user ID associated with the order (currently unused but reserved for future auth context)\n * @returns A Promise resolving to the order object\n * @throws Will throw an error if the request fails or the order is not found\n */\n async fetch(id: string, uid: string) {\n // uid is reserved for future scoped access/auth features\n return this.request(`/orders/${id}`);\n }\n}\n","export const apiVersion = '0.1.0';\nexport const apiVersionDate = '2025-04-15';\nexport const apiBaseUrl = 'https://api.cohost.com/v1'","import { apiBaseUrl } from \"../apiVersion\";\n\n/**\n * Options for configuring the request handler.\n */\ninterface RequestProps {\n /** API token for authentication (Bearer token). */\n token: string | null;\n\n /** Base URL of the API (defaults to versioned `apiBaseUrl`). */\n baseUrl?: string;\n\n /** Enable debug logging of requests/responses. */\n debug?: boolean;\n}\n\n/**\n * Supported HTTP methods.\n */\ntype RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n\n/**\n * A function that performs a request to the Cohost API.\n */\ntype RequestFn = (\n /** Path of the request relative to baseUrl */\n path: string,\n options?: {\n /** HTTP method (defaults to 'GET') */\n method?: RequestMethod;\n\n /** Request body data (auto-serialized as JSON) */\n data?: any;\n\n /** Query parameters to be appended to the URL */\n query?: Record<string, string | number | boolean | undefined>;\n\n /** Additional headers to merge into the request */\n headers?: Record<string, string>;\n }\n) => Promise<any>;\n\n/**\n * Creates a request function configured with authentication and defaults.\n */\nconst request = ({ token, baseUrl = apiBaseUrl, debug = false }: RequestProps): RequestFn => {\n return async (path, { method = 'GET', data, query, headers = {} } = {}) => {\n const queryString = query\n ? '?' + new URLSearchParams(\n Object.entries(query).reduce((acc, [key, value]) => {\n if (value !== undefined) acc[key] = String(value);\n return acc;\n }, {} as Record<string, string>)\n ).toString()\n : '';\n\n const url = `${baseUrl}${path}${queryString}`;\n\n const reqHeaders: Record<string, string> = {\n 'Content-Type': 'application/json',\n ...headers,\n };\n\n if (token) {\n reqHeaders['Authorization'] = `Bearer ${token}`;\n }\n\n const body = data && method !== 'GET' ? JSON.stringify(data) : undefined;\n\n if (debug) {\n console.log(`[Cohost SDK] Request: ${method} ${url}`);\n if (body) console.log(`[Cohost SDK] Body:`, body);\n }\n\n const res = await fetch(url, {\n method,\n headers: reqHeaders,\n body,\n });\n\n const isJson = res.headers.get('content-type')?.includes('application/json');\n const responseBody = isJson ? await res.json() : await res.text();\n\n if (!res.ok) {\n const message = typeof responseBody === 'string' ? responseBody : JSON.stringify(responseBody);\n throw new Error(`[Cohost SDK] ${res.status} ${res.statusText}: ${message}`);\n }\n\n if (typeof responseBody === 'object' && responseBody !== null && responseBody.status === 'ok' && 'data' in responseBody) {\n return responseBody.data;\n }\n\n return responseBody;\n };\n};\n\nexport { request, RequestProps, RequestFn };\n","import { EventsAPI } from './api/events';\nimport { OrdersAPI } from './api/orders';\nimport { apiBaseUrl } from './apiVersion';\nimport { request, RequestFn } from './http/request';\nimport { CohostClientSettings } from './settings';\n\n/**\n * Configuration options for instantiating a CohostClient.\n */\nexport interface CohostClientOptions {\n /** API token used for authenticated requests. */\n token: string;\n\n /** Optional client settings such as debug mode or custom API URL. */\n settings?: CohostClientSettings;\n}\n\n/**\n * CohostClient provides grouped access to various API modules such as Events and Orders.\n * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const event = await client.events.fetch('event-id');\n * const order = await client.orders.fetch('order-id', 'user-id');\n * ```\n */\nexport class CohostClient {\n /** Access to Event-related endpoints */\n readonly events: EventsAPI;\n\n /** Access to Order-related endpoints */\n readonly orders: OrdersAPI;\n\n constructor({ token, settings = {} }: CohostClientOptions) {\n const sharedRequest: RequestFn = request({\n token,\n baseUrl: settings.apiUrl || apiBaseUrl,\n debug: settings.debug,\n });\n\n this.events = new EventsAPI(sharedRequest, settings);\n this.orders = new OrdersAPI(sharedRequest, settings);\n }\n}\n"],"mappings":"ijBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,EAAA,uBAAAC,IAAA,eAAAC,EAAAJ,GCOO,IAAMK,EAAN,KAAqB,CAa1B,YAAYC,EAAoBC,EAAgC,CAXhEC,EAAA,KAAU,WAGVA,EAAA,KAAU,YASR,KAAK,QAAUF,EACf,KAAK,SAAWC,CAClB,CACF,ECVO,IAAME,EAAN,cAAwBC,CAAe,CAQ5C,MAAM,MAAMC,EAAY,CACtB,OAAO,KAAK,QAAQ,WAAWA,CAAE,EAAE,CACrC,CASA,MAAM,QAAQA,EAAY,CACxB,OAAO,KAAK,QAAQ,WAAWA,CAAE,UAAU,CAC7C,CACF,ECvBO,IAAMC,EAAN,cAAwBC,CAAe,CAS5C,MAAM,MAAMC,EAAYC,EAAa,CAEnC,OAAO,KAAK,QAAQ,WAAWD,CAAE,EAAE,CACrC,CACF,ECxBO,IAAME,EAAa,4BC2C1B,IAAMC,EA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AE,MAAAC,EAAO,SAAAC,EAAW,CAAC,CAAE,EAAwB,CAL3DC,EAAA,KAAS,UAGTA,EAAA,KAAS,UAGP,IAAMC,EAA2BC,EAAQ,CACvC,MAAAJ,EACA,QAASC,EAAS,QAAUI,EAC5B,MAAOJ,EAAS,KAClB,CAAC,EAED,KAAK,OAAS,IAAIK,EAAUH,EAAeF,CAAQ,EACnD,KAAK,OAAS,IAAIM,EAAUJ,EAAeF,CAAQ,CACrD,CACF,ENlCO,SAASO,EAAmBC,EAA4C,CAC3E,OAAO,IAAIC,EAAaD,CAAO,CACnC","names":["index_exports","__export","CohostClient","createCohostClient","__toCommonJS","CohostEndpoint","request","settings","__publicField","EventsAPI","CohostEndpoint","id","OrdersAPI","CohostEndpoint","id","uid","apiBaseUrl","request","token","baseUrl","apiBaseUrl","debug","path","method","data","query","headers","queryString","acc","key","value","url","reqHeaders","body","res","responseBody","message","CohostClient","token","settings","__publicField","sharedRequest","request","apiBaseUrl","EventsAPI","OrdersAPI","createCohostClient","options","CohostClient"]}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- var b=Object.defineProperty;var P=(s,t,e)=>t in s?b(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var n=(s,t,e)=>P(s,typeof t!="symbol"?t+"":t,e);var i=class{constructor(t,e){n(this,"request");n(this,"settings");this.request=t,this.settings=e}};var c=class extends i{async fetch(t){return this.request(`/events/${t}`)}async tickets(t){return this.request(`/events/${t}/tickets`)}};var u=class extends i{async fetch(t,e){return this.request(`/orders/${t}`)}};var d="https://api.cohost.com/v1";var R=({token:s,baseUrl:t=d,debug:e=!1})=>async(a,{method:g="GET",data:f,query:m,headers:S={}}={})=>{let x=m?"?"+new URLSearchParams(Object.entries(m).reduce((p,[$,C])=>(C!==void 0&&(p[$]=String(C)),p),{})).toString():"",q=`${t}${a}${x}`,y={"Content-Type":"application/json",...S};s&&(y.Authorization=`Bearer ${s}`);let l=f&&g!=="GET"?JSON.stringify(f):void 0;e&&(console.log(`[Cohost SDK] Request: ${g} ${q}`),l&&console.log("[Cohost SDK] Body:",l));let r=await fetch(q,{method:g,headers:y,body:l}),o=r.headers.get("content-type")?.includes("application/json")?await r.json():await r.text();if(!r.ok){let p=typeof o=="string"?o:JSON.stringify(o);throw new Error(`[Cohost SDK] ${r.status} ${r.statusText}: ${p}`)}return typeof o=="object"&&o!==null&&o.status==="ok"&&"data"in o?o.data:o};var h=class{constructor({token:t,settings:e={}}){n(this,"events");n(this,"orders");let a=R({token:t,baseUrl:e.apiUrl||d,debug:e.debug});this.events=new c(a,e),this.orders=new u(a,e)}};export{h as CohostClient};
1
+ var b=Object.defineProperty;var P=(e,t,s)=>t in e?b(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var n=(e,t,s)=>P(e,typeof t!="symbol"?t+"":t,s);var i=class{constructor(t,s){n(this,"request");n(this,"settings");this.request=t,this.settings=s}};var c=class extends i{async fetch(t){return this.request(`/events/${t}`)}async tickets(t){return this.request(`/events/${t}/tickets`)}};var u=class extends i{async fetch(t,s){return this.request(`/orders/${t}`)}};var d="https://api.cohost.com/v1";var R=({token:e,baseUrl:t=d,debug:s=!1})=>async(a,{method:h="GET",data:f,query:C,headers:x={}}={})=>{let S=C?"?"+new URLSearchParams(Object.entries(C).reduce((p,[$,y])=>(y!==void 0&&(p[$]=String(y)),p),{})).toString():"",m=`${t}${a}${S}`,q={"Content-Type":"application/json",...x};e&&(q.Authorization=`Bearer ${e}`);let g=f&&h!=="GET"?JSON.stringify(f):void 0;s&&(console.log(`[Cohost SDK] Request: ${h} ${m}`),g&&console.log("[Cohost SDK] Body:",g));let r=await fetch(m,{method:h,headers:q,body:g}),o=r.headers.get("content-type")?.includes("application/json")?await r.json():await r.text();if(!r.ok){let p=typeof o=="string"?o:JSON.stringify(o);throw new Error(`[Cohost SDK] ${r.status} ${r.statusText}: ${p}`)}return typeof o=="object"&&o!==null&&o.status==="ok"&&"data"in o?o.data:o};var l=class{constructor({token:t,settings:s={}}){n(this,"events");n(this,"orders");let a=R({token:t,baseUrl:s.apiUrl||d,debug:s.debug});this.events=new c(a,s),this.orders=new u(a,s)}};function V(e){return new l(e)}export{l as CohostClient,V as createCohostClient};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/endpoint.ts","../src/api/events.ts","../src/api/orders.ts","../src/apiVersion.ts","../src/http/request.ts","../src/client.ts"],"sourcesContent":["import { RequestFn } from \"./http/request\";\nimport { CohostClientSettings } from \"./settings\";\n\n/**\n * Base class for all API endpoint groups within the Cohost SDK.\n * Provides shared access to the configured request function and settings.\n */\nexport class CohostEndpoint {\n /** Shared request function injected from the client */\n protected request: RequestFn;\n\n /** Client settings passed during instantiation */\n protected settings: CohostClientSettings;\n\n /**\n * Constructs a new endpoint group.\n *\n * @param request - The shared request function for performing API calls\n * @param settings - The client-wide settings passed from the parent client\n */\n constructor(request: RequestFn, settings: CohostClientSettings) {\n this.request = request;\n this.settings = settings;\n }\n}\n","// src/api/EventsAPI.ts\n\nimport { CohostEndpoint } from '../endpoint';\n\n/**\n * Provides methods to interact with the Cohost Events API.\n * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const event = await client.events.fetch('event-id');\n * const tickets = await client.events.tickets('event-id');\n * ```\n */\nexport class EventsAPI extends CohostEndpoint {\n /**\n * Fetch a single event by ID.\n * \n * @param id - The unique identifier of the event\n * @returns A Promise resolving to the event object\n * @throws Will throw an error if the request fails or the event is not found\n */\n async fetch(id: string) {\n return this.request(`/events/${id}`);\n }\n\n /**\n * List all tickets associated with a specific event.\n * \n * @param id - The unique identifier of the event\n * @returns A Promise resolving to an array of ticket objects\n * @throws Will throw an error if the request fails or the event does not exist\n */\n async tickets(id: string) {\n return this.request(`/events/${id}/tickets`);\n }\n}\n","// src/api/OrdersAPI.ts\n\nimport { CohostEndpoint } from '../endpoint';\n\n/**\n * Provides methods to interact with the Cohost Orders API.\n * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const order = await client.orders.fetch('order-id', 'user-id');\n * ```\n */\nexport class OrdersAPI extends CohostEndpoint {\n /**\n * Fetch a single order by ID.\n * \n * @param id - The unique identifier of the order\n * @param uid - The unique user ID associated with the order (currently unused but reserved for future auth context)\n * @returns A Promise resolving to the order object\n * @throws Will throw an error if the request fails or the order is not found\n */\n async fetch(id: string, uid: string) {\n // uid is reserved for future scoped access/auth features\n return this.request(`/orders/${id}`);\n }\n}\n","export const apiVersion = '0.1.0';\nexport const apiVersionDate = '2025-04-15';\nexport const apiBaseUrl = 'https://api.cohost.com/v1'","import { apiBaseUrl } from \"../apiVersion\";\n\n/**\n * Options for configuring the request handler.\n */\ninterface RequestProps {\n /** API token for authentication (Bearer token). */\n token: string | null;\n\n /** Base URL of the API (defaults to versioned `apiBaseUrl`). */\n baseUrl?: string;\n\n /** Enable debug logging of requests/responses. */\n debug?: boolean;\n}\n\n/**\n * Supported HTTP methods.\n */\ntype RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n\n/**\n * A function that performs a request to the Cohost API.\n */\ntype RequestFn = (\n /** Path of the request relative to baseUrl */\n path: string,\n options?: {\n /** HTTP method (defaults to 'GET') */\n method?: RequestMethod;\n\n /** Request body data (auto-serialized as JSON) */\n data?: any;\n\n /** Query parameters to be appended to the URL */\n query?: Record<string, string | number | boolean | undefined>;\n\n /** Additional headers to merge into the request */\n headers?: Record<string, string>;\n }\n) => Promise<any>;\n\n/**\n * Creates a request function configured with authentication and defaults.\n */\nconst request = ({ token, baseUrl = apiBaseUrl, debug = false }: RequestProps): RequestFn => {\n return async (path, { method = 'GET', data, query, headers = {} } = {}) => {\n const queryString = query\n ? '?' + new URLSearchParams(\n Object.entries(query).reduce((acc, [key, value]) => {\n if (value !== undefined) acc[key] = String(value);\n return acc;\n }, {} as Record<string, string>)\n ).toString()\n : '';\n\n const url = `${baseUrl}${path}${queryString}`;\n\n const reqHeaders: Record<string, string> = {\n 'Content-Type': 'application/json',\n ...headers,\n };\n\n if (token) {\n reqHeaders['Authorization'] = `Bearer ${token}`;\n }\n\n const body = data && method !== 'GET' ? JSON.stringify(data) : undefined;\n\n if (debug) {\n console.log(`[Cohost SDK] Request: ${method} ${url}`);\n if (body) console.log(`[Cohost SDK] Body:`, body);\n }\n\n const res = await fetch(url, {\n method,\n headers: reqHeaders,\n body,\n });\n\n const isJson = res.headers.get('content-type')?.includes('application/json');\n const responseBody = isJson ? await res.json() : await res.text();\n\n if (!res.ok) {\n const message = typeof responseBody === 'string' ? responseBody : JSON.stringify(responseBody);\n throw new Error(`[Cohost SDK] ${res.status} ${res.statusText}: ${message}`);\n }\n\n if (typeof responseBody === 'object' && responseBody !== null && responseBody.status === 'ok' && 'data' in responseBody) {\n return responseBody.data;\n }\n\n return responseBody;\n };\n};\n\nexport { request, RequestProps, RequestFn };\n","import { EventsAPI } from './api/events';\nimport { OrdersAPI } from './api/orders';\nimport { apiBaseUrl } from './apiVersion';\nimport { request, RequestFn } from './http/request';\nimport { CohostClientSettings } from './settings';\n\n/**\n * Configuration options for instantiating a CohostClient.\n */\nexport interface CohostClientOptions {\n /** API token used for authenticated requests. */\n token: string;\n\n /** Optional client settings such as debug mode or custom API URL. */\n settings?: CohostClientSettings;\n}\n\n/**\n * CohostClient provides grouped access to various API modules such as Events and Orders.\n * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const event = await client.events.fetch('event-id');\n * const order = await client.orders.fetch('order-id', 'user-id');\n * ```\n */\nexport class CohostClient {\n /** Access to Event-related endpoints */\n readonly events: EventsAPI;\n\n /** Access to Order-related endpoints */\n readonly orders: OrdersAPI;\n\n constructor({ token, settings = {} }: CohostClientOptions) {\n const sharedRequest: RequestFn = request({\n token,\n baseUrl: settings.apiUrl || apiBaseUrl,\n debug: settings.debug,\n });\n\n this.events = new EventsAPI(sharedRequest, settings);\n this.orders = new OrdersAPI(sharedRequest, settings);\n }\n}\n"],"mappings":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AAMH,EAAK,CACzB,OAAAR,EACA,QAASS,EACT,KAAAC,CACJ,CAAC,EAGKE,EADSD,EAAI,QAAQ,IAAI,cAAc,GAAG,SAAS,kBAAkB,EAC7C,MAAMA,EAAI,KAAK,EAAI,MAAMA,EAAI,KAAK,EAEhE,GAAI,CAACA,EAAI,GAAI,CACT,IAAME,EAAU,OAAOD,GAAiB,SAAWA,EAAe,KAAK,UAAUA,CAAY,EAC7F,MAAM,IAAI,MAAM,gBAAgBD,EAAI,MAAM,IAAIA,EAAI,UAAU,KAAKE,CAAO,EAAE,CAC9E,CAEA,OAAI,OAAOD,GAAiB,UAAYA,IAAiB,MAAQA,EAAa,SAAW,MAAQ,SAAUA,EAChGA,EAAa,KAGjBA,CACX,EClEG,IAAME,EAAN,KAAmB,CAOxB,YAAY,CAAE,MAAAC,EAAO,SAAAC,EAAW,CAAC,CAAE,EAAwB,CAL3DC,EAAA,KAAS,UAGTA,EAAA,KAAS,UAGP,IAAMC,EAA2BC,EAAQ,CACvC,MAAAJ,EACA,QAASC,EAAS,QAAUI,EAC5B,MAAOJ,EAAS,KAClB,CAAC,EAED,KAAK,OAAS,IAAIK,EAAUH,EAAeF,CAAQ,EACnD,KAAK,OAAS,IAAIM,EAAUJ,EAAeF,CAAQ,CACrD,CACF","names":["CohostEndpoint","request","settings","__publicField","EventsAPI","CohostEndpoint","id","OrdersAPI","CohostEndpoint","id","uid","apiBaseUrl","request","token","baseUrl","apiBaseUrl","debug","path","method","data","query","headers","queryString","acc","key","value","url","reqHeaders","body","res","responseBody","message","CohostClient","token","settings","__publicField","sharedRequest","request","apiBaseUrl","EventsAPI","OrdersAPI"]}
1
+ {"version":3,"sources":["../src/endpoint.ts","../src/api/events.ts","../src/api/orders.ts","../src/apiVersion.ts","../src/http/request.ts","../src/client.ts","../src/index.ts"],"sourcesContent":["import { RequestFn } from \"./http/request\";\nimport { CohostClientSettings } from \"./settings\";\n\n/**\n * Base class for all API endpoint groups within the Cohost SDK.\n * Provides shared access to the configured request function and settings.\n */\nexport class CohostEndpoint {\n /** Shared request function injected from the client */\n protected request: RequestFn;\n\n /** Client settings passed during instantiation */\n protected settings: CohostClientSettings;\n\n /**\n * Constructs a new endpoint group.\n *\n * @param request - The shared request function for performing API calls\n * @param settings - The client-wide settings passed from the parent client\n */\n constructor(request: RequestFn, settings: CohostClientSettings) {\n this.request = request;\n this.settings = settings;\n }\n}\n","// src/api/EventsAPI.ts\n\nimport { CohostEndpoint } from '../endpoint';\n\n/**\n * Provides methods to interact with the Cohost Events API.\n * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const event = await client.events.fetch('event-id');\n * const tickets = await client.events.tickets('event-id');\n * ```\n */\nexport class EventsAPI extends CohostEndpoint {\n /**\n * Fetch a single event by ID.\n * \n * @param id - The unique identifier of the event\n * @returns A Promise resolving to the event object\n * @throws Will throw an error if the request fails or the event is not found\n */\n async fetch(id: string) {\n return this.request(`/events/${id}`);\n }\n\n /**\n * List all tickets associated with a specific event.\n * \n * @param id - The unique identifier of the event\n * @returns A Promise resolving to an array of ticket objects\n * @throws Will throw an error if the request fails or the event does not exist\n */\n async tickets(id: string) {\n return this.request(`/events/${id}/tickets`);\n }\n}\n","// src/api/OrdersAPI.ts\n\nimport { CohostEndpoint } from '../endpoint';\n\n/**\n * Provides methods to interact with the Cohost Orders API.\n * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const order = await client.orders.fetch('order-id', 'user-id');\n * ```\n */\nexport class OrdersAPI extends CohostEndpoint {\n /**\n * Fetch a single order by ID.\n * \n * @param id - The unique identifier of the order\n * @param uid - The unique user ID associated with the order (currently unused but reserved for future auth context)\n * @returns A Promise resolving to the order object\n * @throws Will throw an error if the request fails or the order is not found\n */\n async fetch(id: string, uid: string) {\n // uid is reserved for future scoped access/auth features\n return this.request(`/orders/${id}`);\n }\n}\n","export const apiVersion = '0.1.0';\nexport const apiVersionDate = '2025-04-15';\nexport const apiBaseUrl = 'https://api.cohost.com/v1'","import { apiBaseUrl } from \"../apiVersion\";\n\n/**\n * Options for configuring the request handler.\n */\ninterface RequestProps {\n /** API token for authentication (Bearer token). */\n token: string | null;\n\n /** Base URL of the API (defaults to versioned `apiBaseUrl`). */\n baseUrl?: string;\n\n /** Enable debug logging of requests/responses. */\n debug?: boolean;\n}\n\n/**\n * Supported HTTP methods.\n */\ntype RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';\n\n/**\n * A function that performs a request to the Cohost API.\n */\ntype RequestFn = (\n /** Path of the request relative to baseUrl */\n path: string,\n options?: {\n /** HTTP method (defaults to 'GET') */\n method?: RequestMethod;\n\n /** Request body data (auto-serialized as JSON) */\n data?: any;\n\n /** Query parameters to be appended to the URL */\n query?: Record<string, string | number | boolean | undefined>;\n\n /** Additional headers to merge into the request */\n headers?: Record<string, string>;\n }\n) => Promise<any>;\n\n/**\n * Creates a request function configured with authentication and defaults.\n */\nconst request = ({ token, baseUrl = apiBaseUrl, debug = false }: RequestProps): RequestFn => {\n return async (path, { method = 'GET', data, query, headers = {} } = {}) => {\n const queryString = query\n ? '?' + new URLSearchParams(\n Object.entries(query).reduce((acc, [key, value]) => {\n if (value !== undefined) acc[key] = String(value);\n return acc;\n }, {} as Record<string, string>)\n ).toString()\n : '';\n\n const url = `${baseUrl}${path}${queryString}`;\n\n const reqHeaders: Record<string, string> = {\n 'Content-Type': 'application/json',\n ...headers,\n };\n\n if (token) {\n reqHeaders['Authorization'] = `Bearer ${token}`;\n }\n\n const body = data && method !== 'GET' ? JSON.stringify(data) : undefined;\n\n if (debug) {\n console.log(`[Cohost SDK] Request: ${method} ${url}`);\n if (body) console.log(`[Cohost SDK] Body:`, body);\n }\n\n const res = await fetch(url, {\n method,\n headers: reqHeaders,\n body,\n });\n\n const isJson = res.headers.get('content-type')?.includes('application/json');\n const responseBody = isJson ? await res.json() : await res.text();\n\n if (!res.ok) {\n const message = typeof responseBody === 'string' ? responseBody : JSON.stringify(responseBody);\n throw new Error(`[Cohost SDK] ${res.status} ${res.statusText}: ${message}`);\n }\n\n if (typeof responseBody === 'object' && responseBody !== null && responseBody.status === 'ok' && 'data' in responseBody) {\n return responseBody.data;\n }\n\n return responseBody;\n };\n};\n\nexport { request, RequestProps, RequestFn };\n","import { EventsAPI } from './api/events';\nimport { OrdersAPI } from './api/orders';\nimport { apiBaseUrl } from './apiVersion';\nimport { request, RequestFn } from './http/request';\nimport { CohostClientSettings } from './settings';\n\n/**\n * Configuration options for instantiating a CohostClient.\n */\nexport interface CohostClientOptions {\n /** API token used for authenticated requests. */\n token: string;\n\n /** Optional client settings such as debug mode or custom API URL. */\n settings?: CohostClientSettings;\n}\n\n/**\n * CohostClient provides grouped access to various API modules such as Events and Orders.\n * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const event = await client.events.fetch('event-id');\n * const order = await client.orders.fetch('order-id', 'user-id');\n * ```\n */\nexport class CohostClient {\n /** Access to Event-related endpoints */\n readonly events: EventsAPI;\n\n /** Access to Order-related endpoints */\n readonly orders: OrdersAPI;\n\n constructor({ token, settings = {} }: CohostClientOptions) {\n const sharedRequest: RequestFn = request({\n token,\n baseUrl: settings.apiUrl || apiBaseUrl,\n debug: settings.debug,\n });\n\n this.events = new EventsAPI(sharedRequest, settings);\n this.orders = new OrdersAPI(sharedRequest, settings);\n }\n}\n","import { CohostClient, CohostClientOptions } from './client';\n\n/**\n * Factory method for creating a CohostClient instance.\n * \n * Example:\n * ```ts\n * const client = createCohostClient({ token: 'your-token' });\n * ```\n */\nexport function createCohostClient(options: CohostClientOptions): CohostClient {\n return new CohostClient(options);\n}\n\n\nexport { CohostClient }"],"mappings":"oKAOO,IAAMA,EAAN,KAAqB,CAa1B,YAAYC,EAAoBC,EAAgC,CAXhEC,EAAA,KAAU,WAGVA,EAAA,KAAU,YASR,KAAK,QAAUF,EACf,KAAK,SAAWC,CAClB,CACF,ECVO,IAAME,EAAN,cAAwBC,CAAe,CAQ5C,MAAM,MAAMC,EAA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ACT,IAAME,EAAU,OAAOD,GAAiB,SAAWA,EAAe,KAAK,UAAUA,CAAY,EAC7F,MAAM,IAAI,MAAM,gBAAgBD,EAAI,MAAM,IAAIA,EAAI,UAAU,KAAKE,CAAO,EAAE,CAC9E,CAEA,OAAI,OAAOD,GAAiB,UAAYA,IAAiB,MAAQA,EAAa,SAAW,MAAQ,SAAUA,EAChGA,EAAa,KAGjBA,CACX,EClEG,IAAME,EAAN,KAAmB,CAOxB,YAAY,CAAE,MAAAC,EAAO,SAAAC,EAAW,CAAC,CAAE,EAAwB,CAL3DC,EAAA,KAAS,UAGTA,EAAA,KAAS,UAGP,IAAMC,EAA2BC,EAAQ,CACvC,MAAAJ,EACA,QAASC,EAAS,QAAUI,EAC5B,MAAOJ,EAAS,KAClB,CAAC,EAED,KAAK,OAAS,IAAIK,EAAUH,EAAeF,CAAQ,EACnD,KAAK,OAAS,IAAIM,EAAUJ,EAAeF,CAAQ,CACrD,CACF,EClCO,SAASO,EAAmBC,EAA4C,CAC3E,OAAO,IAAIC,EAAaD,CAAO,CACnC","names":["CohostEndpoint","request","settings","__publicField","EventsAPI","CohostEndpoint","id","OrdersAPI","CohostEndpoint","id","uid","apiBaseUrl","request","token","baseUrl","apiBaseUrl","debug","path","method","data","query","headers","queryString","acc","key","value","url","reqHeaders","body","res","responseBody","message","CohostClient","token","settings","__publicField","sharedRequest","request","apiBaseUrl","EventsAPI","OrdersAPI","createCohostClient","options","CohostClient"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cohostvip/cohost-node",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Cohost API wrapper",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -8,8 +8,7 @@
8
8
  "exports": {
9
9
  ".": {
10
10
  "require": "./dist/index.cjs",
11
- "import": "./dist/index.mjs",
12
- "types": "./dist/index.d.ts"
11
+ "import": "./dist/index.mjs"
13
12
  }
14
13
  },
15
14
  "files": [