@cohostvip/cohost-node 0.1.3 → 0.1.5

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
@@ -88,6 +88,40 @@ type PaginatedResponse<T> = {
88
88
  /** Pagination metadata. */
89
89
  pagination: PaginationResponse;
90
90
  };
91
+ /**
92
+ * A pre-parsed human-friendly representation of a date and time.
93
+ */
94
+ interface StructuredDate {
95
+ /** Formatted date strings. */
96
+ date: {
97
+ /** Full format, e.g., "Tuesday, October 3". */
98
+ EEEEMMMMd: string;
99
+ /** Short weekday/month/day, e.g., "Tue, Oct. 3". */
100
+ EEEMMMd: string;
101
+ /** Long date format, e.g., "Tuesday, October 3, 2023". */
102
+ long: string;
103
+ /** Short numeric format, e.g., "10/03/2023". */
104
+ short: string;
105
+ };
106
+ /** Time string (e.g., "3:00 PM"). */
107
+ time: string;
108
+ /** UTC timestamp (e.g., "2006-10-25T12:00:00Z"). */
109
+ utc: string;
110
+ /** IANA timezone (e.g., "America/New_York"). */
111
+ timezone: string;
112
+ /** Local timestamp (e.g., "2006-10-25T12:00:00-04:00"). */
113
+ local: string;
114
+ /** Whether this date is in the future. */
115
+ upcoming: boolean;
116
+ /** Duration details from now to the date. */
117
+ duration: {
118
+ days: number;
119
+ hours: number;
120
+ minutes: number;
121
+ weeks: number;
122
+ months: number;
123
+ };
124
+ }
91
125
  /**
92
126
  * Base metadata for any record stored in the system.
93
127
  * Includes an ID and timestamps for creation and optional updates.
@@ -314,6 +348,12 @@ interface OfferingCosts extends CostBase {
314
348
  */
315
349
  total: CurrencyAmount;
316
350
  }
351
+ interface StructuredCost {
352
+ currency: string;
353
+ formatted: string;
354
+ value: number;
355
+ majorValue: number;
356
+ }
317
357
  type CostBucket = "item" | "fee" | "tax" | "delivery";
318
358
  interface CostComponent {
319
359
  id: string;
@@ -917,7 +957,7 @@ interface OrderItem {
917
957
  options: any | null;
918
958
  offering: OrderItemOffering;
919
959
  }
920
- interface OrderItemOffering extends Pick<Offering, "id" | "name" | "type" | "includes" | "sorting" | "maximumQuantity" | "minimumQuantity"> {
960
+ interface OrderItemOffering extends Pick<Offering, "id" | "name" | "type" | "includes" | "status" | "description" | "options" | "maximumQuantity" | "minimumQuantity" | "sorting"> {
921
961
  costs?: OfferingCosts;
922
962
  /**
923
963
  * doc assicated with this offering in the DB.
@@ -980,6 +1020,7 @@ interface ResolvedCartContext {
980
1020
  * }
981
1021
  */
982
1022
  offerings?: Record<string, ResolvedCartContextOffering>;
1023
+ config: any;
983
1024
  }
984
1025
  interface ResolvedCartContextOffering {
985
1026
  path: string;
@@ -1176,8 +1217,9 @@ interface OrderContext$1 {
1176
1217
  */
1177
1218
  [custom: string]: unknown;
1178
1219
  }
1179
- type CartSessionItem = Pick<OrderItem, "id" | "details" | "offeringId" | "quantity" | "options" | "offering" | "tableCommitmentId"> & {
1220
+ type CartSessionItem = Pick<OrderItem, "id" | "details" | "offeringId" | "quantity" | "options" | "tableCommitmentId"> & {
1180
1221
  costs?: OrderItemCosts;
1222
+ offering: OrderItemOffering;
1181
1223
  };
1182
1224
  /**
1183
1225
  * Represents a temporary or persisted cart before order placement.
@@ -1236,9 +1278,13 @@ interface CartSession extends DataRecord, Pick<Order, "currency" | "contextId" |
1236
1278
  * Partner-forwarded data (e.g. utm, session metadata).
1237
1279
  */
1238
1280
  forwarded?: any;
1281
+ /**
1282
+ * Customer answers
1283
+ */
1284
+ customerAnswers?: any;
1239
1285
  status: "started" | "completed" | "abandoned" | "cancelled";
1240
1286
  }
1241
- type UpdatableCartSession = Pick<CartSession, "customer" | "items">;
1287
+ type UpdatableCartSession = Pick<CartSession, "customer" | "items" | "customerAnswers" | "forwarded">;
1242
1288
 
1243
1289
  /**
1244
1290
  * Pagination parameters for a paginated API request.
@@ -1568,4 +1614,4 @@ declare class CohostClient {
1568
1614
  */
1569
1615
  declare function createCohostClient(options: CohostClientOptions): CohostClient;
1570
1616
 
1571
- export { type ActiveOfferingStatus, type Address, type ApiVersion, type Attendee3, type AttendeeStatus, type BuzzBuilder, type CalculatedCostComponent, type CartSession, type CartSessionItem, CohostClient, type CohostClientSettings, type ContextId, type CostBase, type CostBucket, type CostComponent, type CostComponentCap, type CostComponentRule, type CostComponentRuleCondition, type CostOp, type Coupon, type CouponSummary, type CurrencyAmount, type Customer, type DataRecord, type EqualOperator, type EventBase, type EventFeature, type EventProfile, type EventStatus, type GeometryPoint, type Location, type LocationGeometry, type MultipartText, type Offering, type OfferingCosts, type OfferingOption, type OfferingOptionsGroup, type OfferingStatus, type OfferingType, type Order, type OrderContext, type OrderCosts, type OrderItem, type OrderItemCosts, type OrderItemOffering, type OrderStatus, type PackageInclude, type PaginatedRequest, type PaginatedResponse, type Pagination$1 as Pagination, type PaginationResponse, type Person, type PersonContact, type Photo, type PriceCategory, type ResolvedCartContext, type ResolvedCartContextOffering, type Schedule, type Ticket, type TimeOrOffset, type UpdatableCartSession, type VCDataRecord, type Venue, type VenueBase, type VersionedDataRecord, createCohostClient };
1617
+ export { type ActiveOfferingStatus, type Address, type ApiVersion, type Attendee3, type AttendeeStatus, type BuzzBuilder, type CalculatedCostComponent, type CartSession, type CartSessionItem, CohostClient, type CohostClientSettings, type ContextId, type CostBase, type CostBucket, type CostComponent, type CostComponentCap, type CostComponentRule, type CostComponentRuleCondition, type CostOp, type Coupon, type CouponSummary, type CurrencyAmount, type Customer, type DataRecord, type EqualOperator, type EventBase, type EventFeature, type EventProfile, type EventStatus, type GeometryPoint, type Location, type LocationGeometry, type MultipartText, type Offering, type OfferingCosts, type OfferingOption, type OfferingOptionsGroup, type OfferingStatus, type OfferingType, type Order, type OrderContext, type OrderCosts, type OrderItem, type OrderItemCosts, type OrderItemOffering, type OrderStatus, type PackageInclude, type PaginatedRequest, type PaginatedResponse, type Pagination$1 as Pagination, type PaginationResponse, type Person, type PersonContact, type Photo, type PriceCategory, type ResolvedCartContext, type ResolvedCartContextOffering, type Schedule, type StructuredCost, type StructuredDate, type Ticket, type TimeOrOffset, type UpdatableCartSession, type VCDataRecord, type Venue, type VenueBase, type VersionedDataRecord, createCohostClient };
package/dist/index.d.ts CHANGED
@@ -88,6 +88,40 @@ type PaginatedResponse<T> = {
88
88
  /** Pagination metadata. */
89
89
  pagination: PaginationResponse;
90
90
  };
91
+ /**
92
+ * A pre-parsed human-friendly representation of a date and time.
93
+ */
94
+ interface StructuredDate {
95
+ /** Formatted date strings. */
96
+ date: {
97
+ /** Full format, e.g., "Tuesday, October 3". */
98
+ EEEEMMMMd: string;
99
+ /** Short weekday/month/day, e.g., "Tue, Oct. 3". */
100
+ EEEMMMd: string;
101
+ /** Long date format, e.g., "Tuesday, October 3, 2023". */
102
+ long: string;
103
+ /** Short numeric format, e.g., "10/03/2023". */
104
+ short: string;
105
+ };
106
+ /** Time string (e.g., "3:00 PM"). */
107
+ time: string;
108
+ /** UTC timestamp (e.g., "2006-10-25T12:00:00Z"). */
109
+ utc: string;
110
+ /** IANA timezone (e.g., "America/New_York"). */
111
+ timezone: string;
112
+ /** Local timestamp (e.g., "2006-10-25T12:00:00-04:00"). */
113
+ local: string;
114
+ /** Whether this date is in the future. */
115
+ upcoming: boolean;
116
+ /** Duration details from now to the date. */
117
+ duration: {
118
+ days: number;
119
+ hours: number;
120
+ minutes: number;
121
+ weeks: number;
122
+ months: number;
123
+ };
124
+ }
91
125
  /**
92
126
  * Base metadata for any record stored in the system.
93
127
  * Includes an ID and timestamps for creation and optional updates.
@@ -314,6 +348,12 @@ interface OfferingCosts extends CostBase {
314
348
  */
315
349
  total: CurrencyAmount;
316
350
  }
351
+ interface StructuredCost {
352
+ currency: string;
353
+ formatted: string;
354
+ value: number;
355
+ majorValue: number;
356
+ }
317
357
  type CostBucket = "item" | "fee" | "tax" | "delivery";
318
358
  interface CostComponent {
319
359
  id: string;
@@ -917,7 +957,7 @@ interface OrderItem {
917
957
  options: any | null;
918
958
  offering: OrderItemOffering;
919
959
  }
920
- interface OrderItemOffering extends Pick<Offering, "id" | "name" | "type" | "includes" | "sorting" | "maximumQuantity" | "minimumQuantity"> {
960
+ interface OrderItemOffering extends Pick<Offering, "id" | "name" | "type" | "includes" | "status" | "description" | "options" | "maximumQuantity" | "minimumQuantity" | "sorting"> {
921
961
  costs?: OfferingCosts;
922
962
  /**
923
963
  * doc assicated with this offering in the DB.
@@ -980,6 +1020,7 @@ interface ResolvedCartContext {
980
1020
  * }
981
1021
  */
982
1022
  offerings?: Record<string, ResolvedCartContextOffering>;
1023
+ config: any;
983
1024
  }
984
1025
  interface ResolvedCartContextOffering {
985
1026
  path: string;
@@ -1176,8 +1217,9 @@ interface OrderContext$1 {
1176
1217
  */
1177
1218
  [custom: string]: unknown;
1178
1219
  }
1179
- type CartSessionItem = Pick<OrderItem, "id" | "details" | "offeringId" | "quantity" | "options" | "offering" | "tableCommitmentId"> & {
1220
+ type CartSessionItem = Pick<OrderItem, "id" | "details" | "offeringId" | "quantity" | "options" | "tableCommitmentId"> & {
1180
1221
  costs?: OrderItemCosts;
1222
+ offering: OrderItemOffering;
1181
1223
  };
1182
1224
  /**
1183
1225
  * Represents a temporary or persisted cart before order placement.
@@ -1236,9 +1278,13 @@ interface CartSession extends DataRecord, Pick<Order, "currency" | "contextId" |
1236
1278
  * Partner-forwarded data (e.g. utm, session metadata).
1237
1279
  */
1238
1280
  forwarded?: any;
1281
+ /**
1282
+ * Customer answers
1283
+ */
1284
+ customerAnswers?: any;
1239
1285
  status: "started" | "completed" | "abandoned" | "cancelled";
1240
1286
  }
1241
- type UpdatableCartSession = Pick<CartSession, "customer" | "items">;
1287
+ type UpdatableCartSession = Pick<CartSession, "customer" | "items" | "customerAnswers" | "forwarded">;
1242
1288
 
1243
1289
  /**
1244
1290
  * Pagination parameters for a paginated API request.
@@ -1568,4 +1614,4 @@ declare class CohostClient {
1568
1614
  */
1569
1615
  declare function createCohostClient(options: CohostClientOptions): CohostClient;
1570
1616
 
1571
- export { type ActiveOfferingStatus, type Address, type ApiVersion, type Attendee3, type AttendeeStatus, type BuzzBuilder, type CalculatedCostComponent, type CartSession, type CartSessionItem, CohostClient, type CohostClientSettings, type ContextId, type CostBase, type CostBucket, type CostComponent, type CostComponentCap, type CostComponentRule, type CostComponentRuleCondition, type CostOp, type Coupon, type CouponSummary, type CurrencyAmount, type Customer, type DataRecord, type EqualOperator, type EventBase, type EventFeature, type EventProfile, type EventStatus, type GeometryPoint, type Location, type LocationGeometry, type MultipartText, type Offering, type OfferingCosts, type OfferingOption, type OfferingOptionsGroup, type OfferingStatus, type OfferingType, type Order, type OrderContext, type OrderCosts, type OrderItem, type OrderItemCosts, type OrderItemOffering, type OrderStatus, type PackageInclude, type PaginatedRequest, type PaginatedResponse, type Pagination$1 as Pagination, type PaginationResponse, type Person, type PersonContact, type Photo, type PriceCategory, type ResolvedCartContext, type ResolvedCartContextOffering, type Schedule, type Ticket, type TimeOrOffset, type UpdatableCartSession, type VCDataRecord, type Venue, type VenueBase, type VersionedDataRecord, createCohostClient };
1617
+ export { type ActiveOfferingStatus, type Address, type ApiVersion, type Attendee3, type AttendeeStatus, type BuzzBuilder, type CalculatedCostComponent, type CartSession, type CartSessionItem, CohostClient, type CohostClientSettings, type ContextId, type CostBase, type CostBucket, type CostComponent, type CostComponentCap, type CostComponentRule, type CostComponentRuleCondition, type CostOp, type Coupon, type CouponSummary, type CurrencyAmount, type Customer, type DataRecord, type EqualOperator, type EventBase, type EventFeature, type EventProfile, type EventStatus, type GeometryPoint, type Location, type LocationGeometry, type MultipartText, type Offering, type OfferingCosts, type OfferingOption, type OfferingOptionsGroup, type OfferingStatus, type OfferingType, type Order, type OrderContext, type OrderCosts, type OrderItem, type OrderItemCosts, type OrderItemOffering, type OrderStatus, type PackageInclude, type PaginatedRequest, type PaginatedResponse, type Pagination$1 as Pagination, type PaginationResponse, type Person, type PersonContact, type Photo, type PriceCategory, type ResolvedCartContext, type ResolvedCartContextOffering, type Schedule, type StructuredCost, type StructuredDate, type Ticket, type TimeOrOffset, type UpdatableCartSession, type VCDataRecord, type Venue, type VenueBase, type VersionedDataRecord, createCohostClient };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var l=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var w=(n,e,t)=>e in n?l(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var B=(n,e)=>{for(var t in e)l(n,t,{get:e[t],enumerable:!0})},D=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of U(e))!$.call(n,s)&&s!==t&&l(n,s,{get:()=>e[s],enumerable:!(r=E(e,s))||r.enumerable});return n};var z=n=>D(l({},"__esModule",{value:!0}),n);var o=(n,e,t)=>w(n,typeof e!="symbol"?e+"":e,t);var L={};B(L,{CohostClient:()=>p,createCohostClient:()=>_});module.exports=z(L);var d=class{constructor(e,t){o(this,"request");o(this,"settings");this.request=e,this.settings=t}};var g="https://api.cohost.com/v1";var m=class n extends Error{constructor(t,r){super(t);o(this,"errorCode");o(this,"statusCode");this.name="CohostError",this.errorCode=r?.errorCode,this.statusCode=r?.statusCode}static fromError(t,r){return new n(t.message,{...r,errorCode:r?.errorCode||t.name})}};var v={baseUrl:"https://api.cohost.vip",headers:{"Content-Type":"application/json"}},O={};var R=(n,e)=>{let{pagination:t,...r}=n;return{query:r,pagination:t,...e}},V=n=>{if(!n)return"";let e=new URLSearchParams;for(let[t,r]of Object.entries(n))r!==void 0&&(Array.isArray(r)?r.forEach(s=>e.append(t,String(s))):e.set(t,String(r)));return e.toString()?`?${e.toString()}`:""},P=({token:n,baseUrl:e=g,debug:t=!1})=>async function(r,s={}){let{method:i="GET",data:c,query:q,pagination:I,headers:A={}}=s,T={...q,...I},k=V(T),x=`${O.baseUrl??e}${r}${k}`,h={...v.headers,...O.headers,...A};n&&(h.Authorization=`Bearer ${n}`);let b=c&&i!=="GET"?JSON.stringify(c):void 0;t&&(console.log(`[Cohost SDK] Request: ${i} ${x}`),b&&console.log("[Cohost SDK] Body:",b),console.log("[Cohost SDK] Headers:",h));let u=await fetch(x,{method:i,headers:h,body:b}),a=u.headers.get("content-type")?.includes("application/json")?await u.json():await u.text();if(!u.ok){let S=typeof a=="string"?a:JSON.stringify(a);throw console.error(`[Cohost SDK] Error: ${S}`,{url:x}),new m(S||u.statusText,{errorCode:u.statusText||"API_ERROR",statusCode:u.status})}return typeof a=="object"&&a!==null&&a.status==="ok"&&"data"in a?a.data:a};var f=class extends d{async list(){return this.request("/events")}async fetch(e){return this.request(`/events/${e}`)}async tickets(e){return this.request(`/events/${e}/tickets`)}async attendees(e,t){return this.request(`/events/${e}/attendees`,R(t))}};var y=class extends d{async fetch(e,t){return this.request(`/orders/${e}?uid=${t}`)}async list(e){let t=new URLSearchParams(e).toString();return this.request(`/orders${t?`?${t}`:""}`)}};var C=class extends d{async start(e){return this.request("/cart/sessions",{method:"POST",data:e})}async get(e){return this.request(`/cart/sessions/${e}`)}async update(e,t){return this.request(`/cart/sessions/${e}`,{method:"PATCH",data:t})}async cancel(e){return this.request(`/cart/sessions/${e}`,{method:"DELETE"})}async updateItem(e,t){return this.request(`/cart/sessions/${e}/item`,{method:"POST",data:t})}async preValidate(e,t){return this.request(`/cart/sessions/${e}/payment/pre-validate`,{method:"POST",data:t})}async processPayment(e,t){return this.request(`/cart/sessions/${e}/payment/process`,{method:"POST",data:t})}async placeOrder(e,t){return this.request(`/cart/sessions/${e}/place-order`,{method:"POST",data:t})}async deleteItem(e,t){return this.updateItem(e,{itemId:t,quantity:0})}async findTables(e,t){return this.request(`/cart/tables/find-tables/${e}`,{query:{...t}})}async joinTableCommitment(e,t){return this.request(`/cart/sessions/${e}/join-table`,{method:"POST",data:{tableCommitmentId:t}})}};var p=class n{constructor(e,t){o(this,"events");o(this,"orders");o(this,"cart");o(this,"baseOptions");this.baseOptions=e;let{token:r,settings:s={}}=e,i=t??P({token:r,baseUrl:s.apiUrl||g,debug:s.debug});this.events=new f(i,s),this.orders=new y(i,s),this.cart=new C(i,s)}requestWithOverrides(e){let{token:t,settings:r={}}=this.baseOptions,s=(i,c={})=>P({token:e.token??t,baseUrl:e.baseUrl??r.apiUrl??g,debug:r.debug})(i,{...c,headers:{...e.headers||{},...c.headers||{}}});return new n({token:e.token??t,settings:{...r,apiUrl:e.baseUrl??r.apiUrl}},s)}};function _(n){return new p(n)}0&&(module.exports={CohostClient,createCohostClient});
1
+ "use strict";var l=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var D=(n,e,t)=>e in n?l(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var $=(n,e)=>{for(var t in e)l(n,t,{get:e[t],enumerable:!0})},z=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of w(e))!U.call(n,s)&&s!==t&&l(n,s,{get:()=>e[s],enumerable:!(r=E(e,s))||r.enumerable});return n};var B=n=>z(l({},"__esModule",{value:!0}),n);var o=(n,e,t)=>D(n,typeof e!="symbol"?e+"":e,t);var L={};$(L,{CohostClient:()=>p,createCohostClient:()=>_});module.exports=B(L);var d=class{constructor(e,t){o(this,"request");o(this,"settings");this.request=e,this.settings=t}};var g="https://api.cohost.com/v1";var m=class n extends Error{constructor(t,r){super(t);o(this,"errorCode");o(this,"statusCode");this.name="CohostError",this.errorCode=r?.errorCode,this.statusCode=r?.statusCode}static fromError(t,r){return new n(t.message,{...r,errorCode:r?.errorCode||t.name})}};var v={baseUrl:"https://api.cohost.vip",headers:{"Content-Type":"application/json"}},O={};var R=(n,e)=>{let{pagination:t,...r}=n;return{query:r,pagination:t,...e}},V=n=>{if(!n)return"";let e=new URLSearchParams;for(let[t,r]of Object.entries(n))r!==void 0&&(Array.isArray(r)?r.forEach(s=>e.append(t,String(s))):e.set(t,String(r)));return e.toString()?`?${e.toString()}`:""},P=({token:n,baseUrl:e=g,debug:t=!1})=>async function(r,s={}){let{method:i="GET",data:c,query:q,pagination:I,headers:A={}}=s,T={...q,...I},k=V(T),x=`${O.baseUrl??e}${r}${k}`,h={...v.headers,...O.headers,...A};n&&(h.Authorization=`Bearer ${n}`);let b=c&&i!=="GET"?JSON.stringify(c):void 0;t&&(console.log(`[Cohost SDK] Request: ${i} ${x}`),b&&console.log("[Cohost SDK] Body:",b),console.log("[Cohost SDK] Headers:",h));let u=await fetch(x,{method:i,headers:h,body:b}),a=u.headers.get("content-type")?.includes("application/json")?await u.json():await u.text();if(!u.ok){let S=typeof a=="string"?a:JSON.stringify(a);throw console.error(`[Cohost SDK] Error: ${S}`,{url:x}),new m(S||u.statusText,{errorCode:u.statusText||"API_ERROR",statusCode:u.status})}return typeof a=="object"&&a!==null&&a.status==="ok"&&"data"in a?a.data:a};var f=class extends d{async list(){return this.request("/events")}async fetch(e){return this.request(`/events/${e}`)}async tickets(e){return this.request(`/events/${e}/tickets`)}async attendees(e,t){return this.request(`/events/${e}/attendees`,R(t))}};var y=class extends d{async fetch(e,t){return this.request(`/orders/${e}?uid=${t}`)}async list(e){let t=new URLSearchParams(e).toString();return this.request(`/orders${t?`?${t}`:""}`)}};var C=class extends d{async start(e){return this.request("/cart/sessions",{method:"POST",data:e})}async get(e){return this.request(`/cart/sessions/${e}`)}async update(e,t){return this.request(`/cart/sessions/${e}`,{method:"PATCH",data:t})}async cancel(e){return this.request(`/cart/sessions/${e}`,{method:"DELETE"})}async updateItem(e,t){return this.request(`/cart/sessions/${e}/item`,{method:"POST",data:t})}async preValidate(e,t){return this.request(`/cart/sessions/${e}/payment/pre-validate`,{method:"POST",data:t})}async processPayment(e,t){return this.request(`/cart/sessions/${e}/payment/process`,{method:"POST",data:t})}async placeOrder(e,t){return this.request(`/cart/sessions/${e}/place-order`,{method:"POST",data:t})}async deleteItem(e,t){return this.updateItem(e,{itemId:t,quantity:0})}async findTables(e,t){return this.request(`/cart/tables/find-tables/${e}`,{query:{...t}})}async joinTableCommitment(e,t){return this.request(`/cart/sessions/${e}/join-table`,{method:"POST",data:{tableCommitmentId:t}})}};var p=class n{constructor(e,t){o(this,"events");o(this,"orders");o(this,"cart");o(this,"baseOptions");this.baseOptions=e;let{token:r,settings:s={}}=e,i=t??P({token:r,baseUrl:s.apiUrl||g,debug:s.debug});this.events=new f(i,s),this.orders=new y(i,s),this.cart=new C(i,s)}requestWithOverrides(e){let{token:t,settings:r={}}=this.baseOptions,s=(i,c={})=>P({token:e.token??t,baseUrl:e.baseUrl??r.apiUrl??g,debug:r.debug})(i,{...c,headers:{...e.headers||{},...c.headers||{}}});return new n({token:e.token??t,settings:{...r,apiUrl:e.baseUrl??r.apiUrl}},s)}};function _(n){return new p(n)}0&&(module.exports={CohostClient,createCohostClient});
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- var k=Object.defineProperty;var E=(n,e,t)=>e in n?k(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var o=(n,e,t)=>E(n,typeof e!="symbol"?e+"":e,t);var d=class{constructor(e,t){o(this,"request");o(this,"settings");this.request=e,this.settings=t}};var g="https://api.cohost.com/v1";var p=class n extends Error{constructor(t,r){super(t);o(this,"errorCode");o(this,"statusCode");this.name="CohostError",this.errorCode=r?.errorCode,this.statusCode=r?.statusCode}static fromError(t,r){return new n(t.message,{...r,errorCode:r?.errorCode||t.name})}};var S={baseUrl:"https://api.cohost.vip",headers:{"Content-Type":"application/json"}},b={};var v=(n,e)=>{let{pagination:t,...r}=n;return{query:r,pagination:t,...e}},U=n=>{if(!n)return"";let e=new URLSearchParams;for(let[t,r]of Object.entries(n))r!==void 0&&(Array.isArray(r)?r.forEach(s=>e.append(t,String(s))):e.set(t,String(r)));return e.toString()?`?${e.toString()}`:""},O=({token:n,baseUrl:e=g,debug:t=!1})=>async function(r,s={}){let{method:i="GET",data:c,query:R,pagination:q,headers:I={}}=s,A={...R,...q},T=U(A),C=`${b.baseUrl??e}${r}${T}`,x={...S.headers,...b.headers,...I};n&&(x.Authorization=`Bearer ${n}`);let h=c&&i!=="GET"?JSON.stringify(c):void 0;t&&(console.log(`[Cohost SDK] Request: ${i} ${C}`),h&&console.log("[Cohost SDK] Body:",h),console.log("[Cohost SDK] Headers:",x));let u=await fetch(C,{method:i,headers:x,body:h}),a=u.headers.get("content-type")?.includes("application/json")?await u.json():await u.text();if(!u.ok){let P=typeof a=="string"?a:JSON.stringify(a);throw console.error(`[Cohost SDK] Error: ${P}`,{url:C}),new p(P||u.statusText,{errorCode:u.statusText||"API_ERROR",statusCode:u.status})}return typeof a=="object"&&a!==null&&a.status==="ok"&&"data"in a?a.data:a};var l=class extends d{async list(){return this.request("/events")}async fetch(e){return this.request(`/events/${e}`)}async tickets(e){return this.request(`/events/${e}/tickets`)}async attendees(e,t){return this.request(`/events/${e}/attendees`,v(t))}};var m=class extends d{async fetch(e,t){return this.request(`/orders/${e}?uid=${t}`)}async list(e){let t=new URLSearchParams(e).toString();return this.request(`/orders${t?`?${t}`:""}`)}};var f=class extends d{async start(e){return this.request("/cart/sessions",{method:"POST",data:e})}async get(e){return this.request(`/cart/sessions/${e}`)}async update(e,t){return this.request(`/cart/sessions/${e}`,{method:"PATCH",data:t})}async cancel(e){return this.request(`/cart/sessions/${e}`,{method:"DELETE"})}async updateItem(e,t){return this.request(`/cart/sessions/${e}/item`,{method:"POST",data:t})}async preValidate(e,t){return this.request(`/cart/sessions/${e}/payment/pre-validate`,{method:"POST",data:t})}async processPayment(e,t){return this.request(`/cart/sessions/${e}/payment/process`,{method:"POST",data:t})}async placeOrder(e,t){return this.request(`/cart/sessions/${e}/place-order`,{method:"POST",data:t})}async deleteItem(e,t){return this.updateItem(e,{itemId:t,quantity:0})}async findTables(e,t){return this.request(`/cart/tables/find-tables/${e}`,{query:{...t}})}async joinTableCommitment(e,t){return this.request(`/cart/sessions/${e}/join-table`,{method:"POST",data:{tableCommitmentId:t}})}};var y=class n{constructor(e,t){o(this,"events");o(this,"orders");o(this,"cart");o(this,"baseOptions");this.baseOptions=e;let{token:r,settings:s={}}=e,i=t??O({token:r,baseUrl:s.apiUrl||g,debug:s.debug});this.events=new l(i,s),this.orders=new m(i,s),this.cart=new f(i,s)}requestWithOverrides(e){let{token:t,settings:r={}}=this.baseOptions,s=(i,c={})=>O({token:e.token??t,baseUrl:e.baseUrl??r.apiUrl??g,debug:r.debug})(i,{...c,headers:{...e.headers||{},...c.headers||{}}});return new n({token:e.token??t,settings:{...r,apiUrl:e.baseUrl??r.apiUrl}},s)}};function ue(n){return new y(n)}export{y as CohostClient,ue as createCohostClient};
1
+ var k=Object.defineProperty;var E=(n,e,t)=>e in n?k(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var o=(n,e,t)=>E(n,typeof e!="symbol"?e+"":e,t);var d=class{constructor(e,t){o(this,"request");o(this,"settings");this.request=e,this.settings=t}};var g="https://api.cohost.com/v1";var p=class n extends Error{constructor(t,r){super(t);o(this,"errorCode");o(this,"statusCode");this.name="CohostError",this.errorCode=r?.errorCode,this.statusCode=r?.statusCode}static fromError(t,r){return new n(t.message,{...r,errorCode:r?.errorCode||t.name})}};var S={baseUrl:"https://api.cohost.vip",headers:{"Content-Type":"application/json"}},b={};var v=(n,e)=>{let{pagination:t,...r}=n;return{query:r,pagination:t,...e}},w=n=>{if(!n)return"";let e=new URLSearchParams;for(let[t,r]of Object.entries(n))r!==void 0&&(Array.isArray(r)?r.forEach(s=>e.append(t,String(s))):e.set(t,String(r)));return e.toString()?`?${e.toString()}`:""},O=({token:n,baseUrl:e=g,debug:t=!1})=>async function(r,s={}){let{method:i="GET",data:c,query:R,pagination:q,headers:I={}}=s,A={...R,...q},T=w(A),C=`${b.baseUrl??e}${r}${T}`,x={...S.headers,...b.headers,...I};n&&(x.Authorization=`Bearer ${n}`);let h=c&&i!=="GET"?JSON.stringify(c):void 0;t&&(console.log(`[Cohost SDK] Request: ${i} ${C}`),h&&console.log("[Cohost SDK] Body:",h),console.log("[Cohost SDK] Headers:",x));let u=await fetch(C,{method:i,headers:x,body:h}),a=u.headers.get("content-type")?.includes("application/json")?await u.json():await u.text();if(!u.ok){let P=typeof a=="string"?a:JSON.stringify(a);throw console.error(`[Cohost SDK] Error: ${P}`,{url:C}),new p(P||u.statusText,{errorCode:u.statusText||"API_ERROR",statusCode:u.status})}return typeof a=="object"&&a!==null&&a.status==="ok"&&"data"in a?a.data:a};var l=class extends d{async list(){return this.request("/events")}async fetch(e){return this.request(`/events/${e}`)}async tickets(e){return this.request(`/events/${e}/tickets`)}async attendees(e,t){return this.request(`/events/${e}/attendees`,v(t))}};var m=class extends d{async fetch(e,t){return this.request(`/orders/${e}?uid=${t}`)}async list(e){let t=new URLSearchParams(e).toString();return this.request(`/orders${t?`?${t}`:""}`)}};var f=class extends d{async start(e){return this.request("/cart/sessions",{method:"POST",data:e})}async get(e){return this.request(`/cart/sessions/${e}`)}async update(e,t){return this.request(`/cart/sessions/${e}`,{method:"PATCH",data:t})}async cancel(e){return this.request(`/cart/sessions/${e}`,{method:"DELETE"})}async updateItem(e,t){return this.request(`/cart/sessions/${e}/item`,{method:"POST",data:t})}async preValidate(e,t){return this.request(`/cart/sessions/${e}/payment/pre-validate`,{method:"POST",data:t})}async processPayment(e,t){return this.request(`/cart/sessions/${e}/payment/process`,{method:"POST",data:t})}async placeOrder(e,t){return this.request(`/cart/sessions/${e}/place-order`,{method:"POST",data:t})}async deleteItem(e,t){return this.updateItem(e,{itemId:t,quantity:0})}async findTables(e,t){return this.request(`/cart/tables/find-tables/${e}`,{query:{...t}})}async joinTableCommitment(e,t){return this.request(`/cart/sessions/${e}/join-table`,{method:"POST",data:{tableCommitmentId:t}})}};var y=class n{constructor(e,t){o(this,"events");o(this,"orders");o(this,"cart");o(this,"baseOptions");this.baseOptions=e;let{token:r,settings:s={}}=e,i=t??O({token:r,baseUrl:s.apiUrl||g,debug:s.debug});this.events=new l(i,s),this.orders=new m(i,s),this.cart=new f(i,s)}requestWithOverrides(e){let{token:t,settings:r={}}=this.baseOptions,s=(i,c={})=>O({token:e.token??t,baseUrl:e.baseUrl??r.apiUrl??g,debug:r.debug})(i,{...c,headers:{...e.headers||{},...c.headers||{}}});return new n({token:e.token??t,settings:{...r,apiUrl:e.baseUrl??r.apiUrl}},s)}};function ue(n){return new y(n)}export{y as CohostClient,ue as createCohostClient};
2
2
  //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cohostvip/cohost-node",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Cohost API wrapper",
5
5
  "main": "dist/index.mjs",
6
6
  "module": "dist/index.mjs",