@cohostvip/cohost-node 0.0.4 → 0.0.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 +40 -123
- package/dist/index.d.ts +40 -123
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -470,92 +470,6 @@ declare namespace CartSession {
|
|
|
470
470
|
}
|
|
471
471
|
}
|
|
472
472
|
|
|
473
|
-
type CostComponentCap = {
|
|
474
|
-
op: string;
|
|
475
|
-
type: CostComponentCap.type;
|
|
476
|
-
/**
|
|
477
|
-
* The value of the cap. If type is percentage, it is a percentage of the base value.
|
|
478
|
-
* If type is absolute, it is an absolute value.
|
|
479
|
-
*
|
|
480
|
-
* Absolute value is represented in the same denomination as the cost.
|
|
481
|
-
* i.e. if the cost is in cents, the absolute value should be in cents.
|
|
482
|
-
*
|
|
483
|
-
* percentage value is represented as a decimal.
|
|
484
|
-
* For example, 10% is represented as 0.1.
|
|
485
|
-
*/
|
|
486
|
-
value: number;
|
|
487
|
-
};
|
|
488
|
-
declare namespace CostComponentCap {
|
|
489
|
-
enum type {
|
|
490
|
-
ABSOLUTE = "absolute",
|
|
491
|
-
PERCENTAGE = "percentage"
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
* A set of comparison operators used for evaluating conditional expressions.
|
|
497
|
-
*
|
|
498
|
-
* Supported operators:
|
|
499
|
-
* - '==' (equal to)
|
|
500
|
-
* - '!=' (not equal to)
|
|
501
|
-
* - '<' (less than)
|
|
502
|
-
* - '<=' (less than or equal to)
|
|
503
|
-
* - '>' (greater than)
|
|
504
|
-
* - '>=' (greater than or equal to)
|
|
505
|
-
*/
|
|
506
|
-
declare enum EqualOperator {
|
|
507
|
-
_ = "!="
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
type CostComponentRuleCondition = {
|
|
511
|
-
/**
|
|
512
|
-
* evaluator, will define a function or endpoint to evaluate the condition.
|
|
513
|
-
*/
|
|
514
|
-
eval?: string;
|
|
515
|
-
/**
|
|
516
|
-
* The field to evaluate the condition against.
|
|
517
|
-
* For example, "item.price" or "order.total".
|
|
518
|
-
* The field should be a valid path to the field in the cost component base.
|
|
519
|
-
*/
|
|
520
|
-
field: string;
|
|
521
|
-
operator: EqualOperator;
|
|
522
|
-
/**
|
|
523
|
-
* Can be a value such as number, currencyAmount, an ISO date string, etc...
|
|
524
|
-
*/
|
|
525
|
-
value: any;
|
|
526
|
-
};
|
|
527
|
-
|
|
528
|
-
type CostComponentRule = {
|
|
529
|
-
/**
|
|
530
|
-
* The rule will be applied to the cost component if the conditions are met.
|
|
531
|
-
*/
|
|
532
|
-
conditions: Array<CostComponentRuleCondition>;
|
|
533
|
-
/**
|
|
534
|
-
* Friendly name of the rule.
|
|
535
|
-
*/
|
|
536
|
-
name: string;
|
|
537
|
-
};
|
|
538
|
-
|
|
539
|
-
type CostComponent = {
|
|
540
|
-
base: string;
|
|
541
|
-
bucket: CostBucket;
|
|
542
|
-
cap?: CostComponentCap;
|
|
543
|
-
currency: string;
|
|
544
|
-
details?: any;
|
|
545
|
-
id: string;
|
|
546
|
-
name: string;
|
|
547
|
-
payer: CostComponent.payer;
|
|
548
|
-
recipient: string;
|
|
549
|
-
rules: Array<CostComponentRule>;
|
|
550
|
-
version: string;
|
|
551
|
-
};
|
|
552
|
-
declare namespace CostComponent {
|
|
553
|
-
enum payer {
|
|
554
|
-
ATTENDEE = "attendee",
|
|
555
|
-
ORGANIZER = "organizer"
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
|
|
559
473
|
/**
|
|
560
474
|
* Status of the event lifecycle.
|
|
561
475
|
*
|
|
@@ -761,46 +675,16 @@ declare enum PriceCategory {
|
|
|
761
675
|
PAID = "paid"
|
|
762
676
|
}
|
|
763
677
|
|
|
764
|
-
|
|
765
|
-
* A repeating or structured date schedule for an event or item.
|
|
766
|
-
*/
|
|
767
|
-
type Schedule = {
|
|
768
|
-
/**
|
|
769
|
-
* Days of the week (0 = Sunday, 6 = Saturday).
|
|
770
|
-
*/
|
|
771
|
-
daysOfWeek?: Array<number>;
|
|
772
|
-
/**
|
|
773
|
-
* ISO-formatted UTC end datetime.
|
|
774
|
-
*/
|
|
775
|
-
end: string;
|
|
776
|
-
/**
|
|
777
|
-
* Specific dates to exclude in "YYYY-MM-DD" format.
|
|
778
|
-
*/
|
|
779
|
-
excludeDates?: Array<string>;
|
|
780
|
-
/**
|
|
781
|
-
* Specific dates to include in "YYYY-MM-DD" format.
|
|
782
|
-
*/
|
|
783
|
-
includeDates?: Array<string>;
|
|
678
|
+
type Ticket = {
|
|
784
679
|
/**
|
|
785
|
-
*
|
|
680
|
+
* The maximum number of tickets that can be sold for this offering.
|
|
786
681
|
*/
|
|
787
|
-
start: string;
|
|
788
|
-
};
|
|
789
|
-
|
|
790
|
-
type Ticket = {
|
|
791
682
|
capacity: number;
|
|
792
683
|
category: string;
|
|
793
684
|
/**
|
|
794
685
|
* ISO 8601 timestamp indicating when the record was last updated, if applicable.
|
|
795
686
|
*/
|
|
796
687
|
changed?: string;
|
|
797
|
-
/**
|
|
798
|
-
* Describe fees and other costs associated with purchasing tickets
|
|
799
|
-
* to this offering
|
|
800
|
-
*
|
|
801
|
-
* --@schema array(z.any()).optional()
|
|
802
|
-
*/
|
|
803
|
-
costComponents?: Array<CostComponent>;
|
|
804
688
|
costs: OfferingCosts;
|
|
805
689
|
/**
|
|
806
690
|
* ISO 8601 timestamp indicating when the record was created.
|
|
@@ -812,9 +696,18 @@ type Ticket = {
|
|
|
812
696
|
* Unique identifier for the record.
|
|
813
697
|
*/
|
|
814
698
|
id: string;
|
|
699
|
+
/**
|
|
700
|
+
* Items, products ,and vouchers included in this offering.
|
|
701
|
+
*/
|
|
815
702
|
included?: Array<PackageInclude>;
|
|
816
703
|
instructions?: string;
|
|
704
|
+
/**
|
|
705
|
+
* Maximum number of tickets that can be purchased in a single order.
|
|
706
|
+
*/
|
|
817
707
|
maximumQuantity: number;
|
|
708
|
+
/**
|
|
709
|
+
* Minimum number of tickets that can be purchased in a single order.
|
|
710
|
+
*/
|
|
818
711
|
minimumQuantity: number;
|
|
819
712
|
/**
|
|
820
713
|
* Offering name, can be ticket name, vaucher name, etc...
|
|
@@ -828,7 +721,6 @@ type Ticket = {
|
|
|
828
721
|
refId?: string;
|
|
829
722
|
salesEnd: string;
|
|
830
723
|
salesStart: string;
|
|
831
|
-
schedule?: Schedule;
|
|
832
724
|
sorting: number;
|
|
833
725
|
source: string;
|
|
834
726
|
status: OfferingStatus;
|
|
@@ -932,7 +824,8 @@ declare class SessionsAPI extends CohostEndpoint {
|
|
|
932
824
|
* Start a new cart session.
|
|
933
825
|
*
|
|
934
826
|
* @param input - Data to start the session
|
|
935
|
-
* @returns The
|
|
827
|
+
* @returns {CartSession} The latest cart session
|
|
828
|
+
*
|
|
936
829
|
* @throws Will throw an error if the request fails
|
|
937
830
|
*/
|
|
938
831
|
start(input: StartCartSessionInput): Promise<CartSession>;
|
|
@@ -940,7 +833,8 @@ declare class SessionsAPI extends CohostEndpoint {
|
|
|
940
833
|
* Get a cart session by its ID.
|
|
941
834
|
*
|
|
942
835
|
* @param id - The unique session ID
|
|
943
|
-
* @returns The cart session
|
|
836
|
+
* @returns {CartSession} The latest cart session
|
|
837
|
+
*
|
|
944
838
|
* @throws Will throw an error if the session is not found or request fails
|
|
945
839
|
*/
|
|
946
840
|
get(id: string): Promise<CartSession>;
|
|
@@ -949,7 +843,8 @@ declare class SessionsAPI extends CohostEndpoint {
|
|
|
949
843
|
*
|
|
950
844
|
* @param id - The ID of the session to update
|
|
951
845
|
* @param input - Data to update the session
|
|
952
|
-
* @returns The
|
|
846
|
+
* @returns {CartSession} The latest cart session
|
|
847
|
+
*
|
|
953
848
|
* @throws Will throw an error if the update fails
|
|
954
849
|
*/
|
|
955
850
|
update(id: string, input: UpdatableCartSession): Promise<CartSession>;
|
|
@@ -961,6 +856,28 @@ declare class SessionsAPI extends CohostEndpoint {
|
|
|
961
856
|
* @throws Will throw an error if the cancel operation fails
|
|
962
857
|
*/
|
|
963
858
|
cancel(id: string): Promise<void>;
|
|
859
|
+
/**
|
|
860
|
+
* Update an item in the cart session.
|
|
861
|
+
*
|
|
862
|
+
* @param sessionId - The ID of the session
|
|
863
|
+
* @param props - Properties to update
|
|
864
|
+
* @returns {CartSession} The latest cart session
|
|
865
|
+
*
|
|
866
|
+
* @throws Will throw an error if the update fails
|
|
867
|
+
*/
|
|
868
|
+
updateItem(sessionId: string, props: {
|
|
869
|
+
offeringId: string;
|
|
870
|
+
quantity: number;
|
|
871
|
+
}): Promise<CartSession>;
|
|
872
|
+
/**
|
|
873
|
+
* Remove an item from the cart session.
|
|
874
|
+
* The same as setting the quantity to 0.
|
|
875
|
+
*
|
|
876
|
+
* @param sessionId
|
|
877
|
+
* @param offeringId
|
|
878
|
+
* @returns {CartSession} The latest cart session
|
|
879
|
+
*/
|
|
880
|
+
deleteItem(sessionId: string, offeringId: string): Promise<CartSession>;
|
|
964
881
|
}
|
|
965
882
|
|
|
966
883
|
/**
|
|
@@ -1001,4 +918,4 @@ declare class CohostClient {
|
|
|
1001
918
|
*/
|
|
1002
919
|
declare function createCohostClient(options: CohostClientOptions): CohostClient;
|
|
1003
920
|
|
|
1004
|
-
export { CohostClient, createCohostClient };
|
|
921
|
+
export { CohostClient, type CohostClientSettings, createCohostClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -470,92 +470,6 @@ declare namespace CartSession {
|
|
|
470
470
|
}
|
|
471
471
|
}
|
|
472
472
|
|
|
473
|
-
type CostComponentCap = {
|
|
474
|
-
op: string;
|
|
475
|
-
type: CostComponentCap.type;
|
|
476
|
-
/**
|
|
477
|
-
* The value of the cap. If type is percentage, it is a percentage of the base value.
|
|
478
|
-
* If type is absolute, it is an absolute value.
|
|
479
|
-
*
|
|
480
|
-
* Absolute value is represented in the same denomination as the cost.
|
|
481
|
-
* i.e. if the cost is in cents, the absolute value should be in cents.
|
|
482
|
-
*
|
|
483
|
-
* percentage value is represented as a decimal.
|
|
484
|
-
* For example, 10% is represented as 0.1.
|
|
485
|
-
*/
|
|
486
|
-
value: number;
|
|
487
|
-
};
|
|
488
|
-
declare namespace CostComponentCap {
|
|
489
|
-
enum type {
|
|
490
|
-
ABSOLUTE = "absolute",
|
|
491
|
-
PERCENTAGE = "percentage"
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
* A set of comparison operators used for evaluating conditional expressions.
|
|
497
|
-
*
|
|
498
|
-
* Supported operators:
|
|
499
|
-
* - '==' (equal to)
|
|
500
|
-
* - '!=' (not equal to)
|
|
501
|
-
* - '<' (less than)
|
|
502
|
-
* - '<=' (less than or equal to)
|
|
503
|
-
* - '>' (greater than)
|
|
504
|
-
* - '>=' (greater than or equal to)
|
|
505
|
-
*/
|
|
506
|
-
declare enum EqualOperator {
|
|
507
|
-
_ = "!="
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
type CostComponentRuleCondition = {
|
|
511
|
-
/**
|
|
512
|
-
* evaluator, will define a function or endpoint to evaluate the condition.
|
|
513
|
-
*/
|
|
514
|
-
eval?: string;
|
|
515
|
-
/**
|
|
516
|
-
* The field to evaluate the condition against.
|
|
517
|
-
* For example, "item.price" or "order.total".
|
|
518
|
-
* The field should be a valid path to the field in the cost component base.
|
|
519
|
-
*/
|
|
520
|
-
field: string;
|
|
521
|
-
operator: EqualOperator;
|
|
522
|
-
/**
|
|
523
|
-
* Can be a value such as number, currencyAmount, an ISO date string, etc...
|
|
524
|
-
*/
|
|
525
|
-
value: any;
|
|
526
|
-
};
|
|
527
|
-
|
|
528
|
-
type CostComponentRule = {
|
|
529
|
-
/**
|
|
530
|
-
* The rule will be applied to the cost component if the conditions are met.
|
|
531
|
-
*/
|
|
532
|
-
conditions: Array<CostComponentRuleCondition>;
|
|
533
|
-
/**
|
|
534
|
-
* Friendly name of the rule.
|
|
535
|
-
*/
|
|
536
|
-
name: string;
|
|
537
|
-
};
|
|
538
|
-
|
|
539
|
-
type CostComponent = {
|
|
540
|
-
base: string;
|
|
541
|
-
bucket: CostBucket;
|
|
542
|
-
cap?: CostComponentCap;
|
|
543
|
-
currency: string;
|
|
544
|
-
details?: any;
|
|
545
|
-
id: string;
|
|
546
|
-
name: string;
|
|
547
|
-
payer: CostComponent.payer;
|
|
548
|
-
recipient: string;
|
|
549
|
-
rules: Array<CostComponentRule>;
|
|
550
|
-
version: string;
|
|
551
|
-
};
|
|
552
|
-
declare namespace CostComponent {
|
|
553
|
-
enum payer {
|
|
554
|
-
ATTENDEE = "attendee",
|
|
555
|
-
ORGANIZER = "organizer"
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
|
|
559
473
|
/**
|
|
560
474
|
* Status of the event lifecycle.
|
|
561
475
|
*
|
|
@@ -761,46 +675,16 @@ declare enum PriceCategory {
|
|
|
761
675
|
PAID = "paid"
|
|
762
676
|
}
|
|
763
677
|
|
|
764
|
-
|
|
765
|
-
* A repeating or structured date schedule for an event or item.
|
|
766
|
-
*/
|
|
767
|
-
type Schedule = {
|
|
768
|
-
/**
|
|
769
|
-
* Days of the week (0 = Sunday, 6 = Saturday).
|
|
770
|
-
*/
|
|
771
|
-
daysOfWeek?: Array<number>;
|
|
772
|
-
/**
|
|
773
|
-
* ISO-formatted UTC end datetime.
|
|
774
|
-
*/
|
|
775
|
-
end: string;
|
|
776
|
-
/**
|
|
777
|
-
* Specific dates to exclude in "YYYY-MM-DD" format.
|
|
778
|
-
*/
|
|
779
|
-
excludeDates?: Array<string>;
|
|
780
|
-
/**
|
|
781
|
-
* Specific dates to include in "YYYY-MM-DD" format.
|
|
782
|
-
*/
|
|
783
|
-
includeDates?: Array<string>;
|
|
678
|
+
type Ticket = {
|
|
784
679
|
/**
|
|
785
|
-
*
|
|
680
|
+
* The maximum number of tickets that can be sold for this offering.
|
|
786
681
|
*/
|
|
787
|
-
start: string;
|
|
788
|
-
};
|
|
789
|
-
|
|
790
|
-
type Ticket = {
|
|
791
682
|
capacity: number;
|
|
792
683
|
category: string;
|
|
793
684
|
/**
|
|
794
685
|
* ISO 8601 timestamp indicating when the record was last updated, if applicable.
|
|
795
686
|
*/
|
|
796
687
|
changed?: string;
|
|
797
|
-
/**
|
|
798
|
-
* Describe fees and other costs associated with purchasing tickets
|
|
799
|
-
* to this offering
|
|
800
|
-
*
|
|
801
|
-
* --@schema array(z.any()).optional()
|
|
802
|
-
*/
|
|
803
|
-
costComponents?: Array<CostComponent>;
|
|
804
688
|
costs: OfferingCosts;
|
|
805
689
|
/**
|
|
806
690
|
* ISO 8601 timestamp indicating when the record was created.
|
|
@@ -812,9 +696,18 @@ type Ticket = {
|
|
|
812
696
|
* Unique identifier for the record.
|
|
813
697
|
*/
|
|
814
698
|
id: string;
|
|
699
|
+
/**
|
|
700
|
+
* Items, products ,and vouchers included in this offering.
|
|
701
|
+
*/
|
|
815
702
|
included?: Array<PackageInclude>;
|
|
816
703
|
instructions?: string;
|
|
704
|
+
/**
|
|
705
|
+
* Maximum number of tickets that can be purchased in a single order.
|
|
706
|
+
*/
|
|
817
707
|
maximumQuantity: number;
|
|
708
|
+
/**
|
|
709
|
+
* Minimum number of tickets that can be purchased in a single order.
|
|
710
|
+
*/
|
|
818
711
|
minimumQuantity: number;
|
|
819
712
|
/**
|
|
820
713
|
* Offering name, can be ticket name, vaucher name, etc...
|
|
@@ -828,7 +721,6 @@ type Ticket = {
|
|
|
828
721
|
refId?: string;
|
|
829
722
|
salesEnd: string;
|
|
830
723
|
salesStart: string;
|
|
831
|
-
schedule?: Schedule;
|
|
832
724
|
sorting: number;
|
|
833
725
|
source: string;
|
|
834
726
|
status: OfferingStatus;
|
|
@@ -932,7 +824,8 @@ declare class SessionsAPI extends CohostEndpoint {
|
|
|
932
824
|
* Start a new cart session.
|
|
933
825
|
*
|
|
934
826
|
* @param input - Data to start the session
|
|
935
|
-
* @returns The
|
|
827
|
+
* @returns {CartSession} The latest cart session
|
|
828
|
+
*
|
|
936
829
|
* @throws Will throw an error if the request fails
|
|
937
830
|
*/
|
|
938
831
|
start(input: StartCartSessionInput): Promise<CartSession>;
|
|
@@ -940,7 +833,8 @@ declare class SessionsAPI extends CohostEndpoint {
|
|
|
940
833
|
* Get a cart session by its ID.
|
|
941
834
|
*
|
|
942
835
|
* @param id - The unique session ID
|
|
943
|
-
* @returns The cart session
|
|
836
|
+
* @returns {CartSession} The latest cart session
|
|
837
|
+
*
|
|
944
838
|
* @throws Will throw an error if the session is not found or request fails
|
|
945
839
|
*/
|
|
946
840
|
get(id: string): Promise<CartSession>;
|
|
@@ -949,7 +843,8 @@ declare class SessionsAPI extends CohostEndpoint {
|
|
|
949
843
|
*
|
|
950
844
|
* @param id - The ID of the session to update
|
|
951
845
|
* @param input - Data to update the session
|
|
952
|
-
* @returns The
|
|
846
|
+
* @returns {CartSession} The latest cart session
|
|
847
|
+
*
|
|
953
848
|
* @throws Will throw an error if the update fails
|
|
954
849
|
*/
|
|
955
850
|
update(id: string, input: UpdatableCartSession): Promise<CartSession>;
|
|
@@ -961,6 +856,28 @@ declare class SessionsAPI extends CohostEndpoint {
|
|
|
961
856
|
* @throws Will throw an error if the cancel operation fails
|
|
962
857
|
*/
|
|
963
858
|
cancel(id: string): Promise<void>;
|
|
859
|
+
/**
|
|
860
|
+
* Update an item in the cart session.
|
|
861
|
+
*
|
|
862
|
+
* @param sessionId - The ID of the session
|
|
863
|
+
* @param props - Properties to update
|
|
864
|
+
* @returns {CartSession} The latest cart session
|
|
865
|
+
*
|
|
866
|
+
* @throws Will throw an error if the update fails
|
|
867
|
+
*/
|
|
868
|
+
updateItem(sessionId: string, props: {
|
|
869
|
+
offeringId: string;
|
|
870
|
+
quantity: number;
|
|
871
|
+
}): Promise<CartSession>;
|
|
872
|
+
/**
|
|
873
|
+
* Remove an item from the cart session.
|
|
874
|
+
* The same as setting the quantity to 0.
|
|
875
|
+
*
|
|
876
|
+
* @param sessionId
|
|
877
|
+
* @param offeringId
|
|
878
|
+
* @returns {CartSession} The latest cart session
|
|
879
|
+
*/
|
|
880
|
+
deleteItem(sessionId: string, offeringId: string): Promise<CartSession>;
|
|
964
881
|
}
|
|
965
882
|
|
|
966
883
|
/**
|
|
@@ -1001,4 +918,4 @@ declare class CohostClient {
|
|
|
1001
918
|
*/
|
|
1002
919
|
declare function createCohostClient(options: CohostClientOptions): CohostClient;
|
|
1003
920
|
|
|
1004
|
-
export { CohostClient, createCohostClient };
|
|
921
|
+
export { CohostClient, type CohostClientSettings, createCohostClient };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var g=Object.defineProperty;var
|
|
1
|
+
"use strict";var g=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var w=(e,t,s)=>t in e?g(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var F=(e,t)=>{for(var s in t)g(e,s,{get:t[s],enumerable:!0})},I=(e,t,s,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of k(t))!v.call(e,r)&&r!==s&&g(e,r,{get:()=>t[r],enumerable:!(n=$(t,r))||n.enumerable});return e};var B=e=>I(g({},"__esModule",{value:!0}),e);var a=(e,t,s)=>w(e,typeof t!="symbol"?t+"":t,s);var A={};F(A,{CohostClient:()=>h,createCohostClient:()=>D});module.exports=B(A);var u=class{constructor(t,s){a(this,"request");a(this,"settings");this.request=t,this.settings=s}};var m=class extends u{async list(){return this.request("/events")}async fetch(t){return this.request(`/events/${t}`)}async tickets(t){return this.request(`/events/${t}/tickets`)}};var f=class extends u{async fetch(t,s){return this.request(`/orders/${t}`)}};var C=class extends u{async start(t){return this.request("/cart/sessions",{method:"POST",data:t})}async get(t){return this.request(`/cart/sessions/${t}`)}async update(t,s){return this.request(`/cart/sessions/${t}`,{method:"PATCH",data:s})}async cancel(t){return this.request(`/cart/sessions/${t}`,{method:"DELETE"})}async updateItem(t,s){return this.request(`/cart/sessions/${t}/item`,{method:"POST"})}async deleteItem(t,s){return this.updateItem(t,{offeringId:s,quantity:0})}};var l="https://api.cohost.com/v1";var T={baseUrl:"https://api.cohost.vip",headers:{"Content-Type":"application/json"}},b={};var R=({token:e,baseUrl:t=l,debug:s=!1})=>async function(n,r={}){let{method:o="GET",data:p,query:U,headers:O={}}=r,P=U?"?"+new URLSearchParams(Object.entries(U).reduce((c,[E,x])=>(x!==void 0&&(c[E]=String(x)),c),{})).toString():"",q=`${b.baseUrl??t}${n}${P}`,y={...T.headers,...b.headers,...O};e&&(y.Authorization=`Bearer ${e}`);let S=p&&o!=="GET"?JSON.stringify(p):void 0;s&&(console.log(`[Cohost SDK] Request: ${o} ${q}`),S&&console.log("[Cohost SDK] Body:",S),console.log("[Cohost SDK] Headers:",y));let d=await fetch(q,{method:o,headers:y,body:S}),i=d.headers.get("content-type")?.includes("application/json")?await d.json():await d.text();if(!d.ok){let c=typeof i=="string"?i:JSON.stringify(i);throw console.error(`[Cohost SDK] Error: ${c}`,{url:q}),new Error(`[Cohost SDK] ${d.status} ${d.statusText}: ${c}`)}return typeof i=="object"&&i!==null&&i.status==="ok"&&"data"in i?i.data:i};var h=class e{constructor(t,s){a(this,"events");a(this,"orders");a(this,"cart");a(this,"baseOptions");this.baseOptions=t;let{token:n,settings:r={}}=t,o=s??R({token:n,baseUrl:r.apiUrl||l,debug:r.debug});this.events=new m(o,r),this.orders=new f(o,r),this.cart=new C(o,r)}requestWithOverrides(t){let{token:s,settings:n={}}=this.baseOptions,r=(o,p={})=>R({token:t.token??s,baseUrl:t.baseUrl??n.apiUrl??l,debug:n.debug})(o,{...p,headers:{...t.headers||{},...p.headers||{}}});return new e({token:t.token??s,settings:{...n,apiUrl:t.baseUrl??n.apiUrl}},r)}};function D(e){return new h(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/api/sessions.ts","../src/apiVersion.ts","../src/settings.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';\nimport { EventProfile, Ticket } from '../../types/index';\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 list = await client.events.list();\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 /**\n * Fetch a list of all events.\n * \n * @returns A Promise resolving to an array of event objects\n * @throws Will throw an error if the request fails\n * \n * @todo Implement pagination and filtering options\n */\n async list() {\n return this.request<EventProfile[]>('/events');\n }\n\n\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<EventProfile>(`/events/${id}`);\n }\n\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<Ticket[]>(`/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","import { CohostEndpoint } from '../endpoint';\nimport {\n CartSession,\n UpdatableCartSession,\n} from '../../types/index';\nimport { StartCartSessionInput } from '../types/sessions';\n\n/**\n * Provides methods to interact with cart sessions in the Cohost API.\n *\n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const session = await client.sessions.start({ contextId: 'evt_abc123' });\n * ```\n */\nexport class SessionsAPI extends CohostEndpoint {\n /**\n * Start a new cart session.\n *\n * @param input - Data to start the session\n * @returns The newly created cart session\n * @throws Will throw an error if the request fails\n */\n async start(input: StartCartSessionInput) {\n return this.request<CartSession>('/cart/sessions', {\n method: 'POST',\n data: input,\n });\n }\n\n /**\n * Get a cart session by its ID.\n *\n * @param id - The unique session ID\n * @returns The cart session object\n * @throws Will throw an error if the session is not found or request fails\n */\n async get(id: string) {\n return this.request<CartSession>(`/cart/sessions/${id}`);\n }\n\n /**\n * Update a cart session.\n *\n * @param id - The ID of the session to update\n * @param input - Data to update the session\n * @returns The updated session\n * @throws Will throw an error if the update fails\n */\n async update(id: string, input: UpdatableCartSession) {\n return this.request<CartSession>(`/cart/sessions/${id}`, {\n method: 'PATCH',\n data: input,\n });\n }\n\n /**\n * Cancel (soft delete) a cart session.\n *\n * @param id - The ID of the session to cancel\n * @returns Nothing if successful\n * @throws Will throw an error if the cancel operation fails\n */\n async cancel(id: string) {\n return this.request<void>(`/cart/sessions/${id}`, {\n method: 'DELETE',\n });\n }\n\n}\n","export const apiVersion = '0.1.0';\nexport const apiVersionDate = '2025-04-15';\nexport const apiBaseUrl = 'https://api.cohost.com/v1'","/**\n * Optional settings for customizing the behavior of the CohostClient.\n */\nexport interface CohostClientSettings {\n /** Enable verbose debug output for all API requests. */\n debug?: boolean;\n\n /** Override the default API base URL (defaults to apiBaseUrl). */\n apiUrl?: string;\n}\n\n// settings.ts\nexport const defaultSettings = {\n baseUrl: 'https://api.cohost.vip',\n headers: {\n 'Content-Type': 'application/json',\n },\n};\n\n// In dev or testing, you can override this in the browser or Node\nexport let runtimeOverrides: {\n baseUrl?: string;\n headers?: Record<string, string>;\n} = {};\n\nexport function setSdkOverrides(overrides: typeof runtimeOverrides) {\n runtimeOverrides = overrides;\n}\n\n","import { apiBaseUrl } from \"../apiVersion\";\nimport { defaultSettings, runtimeOverrides } from \"../settings\";\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 * The generic <T> allows you to specify the expected response type.\n */\ntype RequestFn = <T = any>(\n path: string,\n options?: {\n method?: RequestMethod;\n data?: any;\n query?: Record<string, string | number | boolean | undefined>;\n headers?: Record<string, string>;\n }\n) => Promise<T>;\n\n/**\n * Creates a request function configured with authentication and client defaults.\n * The returned function supports generic return typing via <T>.\n */\nconst request = ({ token, baseUrl = apiBaseUrl, debug = false }: RequestProps): RequestFn => {\n return async function <T = any>(\n path: string,\n options: {\n method?: RequestMethod;\n data?: any;\n query?: Record<string, string | number | boolean | undefined>;\n headers?: Record<string, string>;\n } = {}\n ): Promise<T> {\n const { method = \"GET\", data, query, headers = {} } = options;\n\n // Construct query string from `query` object\n const queryString = query\n ? \"?\" +\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 finalBaseUrl = runtimeOverrides.baseUrl ?? baseUrl;\n const url = `${finalBaseUrl}${path}${queryString}`;\n\n // Merge default, runtime, and per-request headers\n const reqHeaders: Record<string, string> = {\n ...defaultSettings.headers,\n ...runtimeOverrides.headers,\n ...headers,\n };\n\n // Add Authorization header if token is present\n if (token) {\n reqHeaders[\"Authorization\"] = `Bearer ${token}`;\n }\n\n // Only send body if method allows it\n const body = data && method !== \"GET\" ? JSON.stringify(data) : undefined;\n\n // Optional debug logging\n if (debug) {\n console.log(`[Cohost SDK] Request: ${method} ${url}`);\n if (body) console.log(`[Cohost SDK] Body:`, body);\n console.log(`[Cohost SDK] Headers:`, reqHeaders);\n }\n\n const res = await fetch(url, {\n method,\n headers: reqHeaders,\n body,\n });\n\n // Parse the response based on content type\n const isJson = res.headers.get(\"content-type\")?.includes(\"application/json\");\n const responseBody = isJson ? await res.json() : await res.text();\n\n // Handle error responses\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 wrapped response structure with { status: 'ok', data }, return `data`\n if (\n typeof responseBody === \"object\" &&\n responseBody !== null &&\n (responseBody as any).status === \"ok\" &&\n \"data\" in responseBody\n ) {\n return (responseBody as { data: T }).data;\n }\n\n // Fallback for raw/unwrapped responses\n return responseBody as T;\n };\n};\n\nexport { request, RequestProps, RequestFn };\n","import { EventsAPI } from './api/events';\nimport { OrdersAPI } from './api/orders';\nimport { SessionsAPI } from './api/sessions';\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 */\nexport class CohostClient {\n public readonly events: EventsAPI;\n public readonly orders: OrdersAPI;\n public readonly cart: SessionsAPI;\n\n private readonly baseOptions: CohostClientOptions;\n\n constructor(options: CohostClientOptions, customRequestFn?: RequestFn) {\n this.baseOptions = options;\n\n const { token, settings = {} } = options;\n\n const sharedRequest = customRequestFn ?? 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 this.cart = new SessionsAPI(sharedRequest, settings);\n }\n\n /**\n * Returns a new CohostClient instance with overridden request behavior\n */\n public requestWithOverrides(overrides: {\n token?: string;\n baseUrl?: string;\n headers?: Record<string, string>;\n }): CohostClient {\n const { token, settings = {} } = this.baseOptions;\n\n const overriddenRequest: RequestFn = (path, options = {}) =>\n request({\n token: overrides.token ?? token,\n baseUrl: overrides.baseUrl ?? settings.apiUrl ?? apiBaseUrl,\n debug: settings.debug,\n })(path, {\n ...options,\n headers: {\n ...(overrides.headers || {}),\n ...(options.headers || {}),\n },\n });\n\n return new CohostClient(\n {\n token: overrides.token ?? token,\n settings: {\n ...settings,\n apiUrl: overrides.baseUrl ?? settings.apiUrl,\n },\n },\n overriddenRequest\n );\n }\n}\n"],"mappings":"ijBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,EAAA,u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ANvEC,EAAA,KAAgB,UAChBA,EAAA,KAAgB,UAChBA,EAAA,KAAgB,QAEhBA,EAAA,KAAiB,eAGf,KAAK,YAAcF,EAEnB,GAAM,CAAE,MAAAG,EAAO,SAAAC,EAAW,CAAC,CAAE,EAAIJ,EAE3BK,EAAgBJ,GAAmBK,EAAQ,CAC/C,MAAAH,EACA,QAASC,EAAS,QAAUG,EAC5B,MAAOH,EAAS,KAClB,CAAC,EAED,KAAK,OAAS,IAAII,EAAUH,EAAeD,CAAQ,EACnD,KAAK,OAAS,IAAIK,EAAUJ,EAAeD,CAAQ,EACnD,KAAK,KAAO,IAAIM,EAAYL,EAAeD,CAAQ,CACrD,CAKO,qBAAqBO,EAIX,CACf,GAAM,CAAE,MAAAR,EAAO,SAAAC,EAAW,CAAC,CAAE,EAAI,KAAK,YAEhCQ,EAA+B,CAACC,EAAMb,EAAU,CAAC,IACrDM,EAAQ,CACN,MAAOK,EAAU,OAASR,EAC1B,QAASQ,EAAU,SAAWP,EAAS,QAAUG,EACjD,MAAOH,EAAS,KAClB,CAAC,EAAES,EAAM,CACP,GAAGb,EACH,QAAS,CACP,GAAIW,EAAU,SAAW,CAAC,EAC1B,GAAIX,EAAQ,SAAW,CAAC,CAC1B,CACF,CAAC,EAEH,OAAO,IAAID,EACT,CACE,MAAOY,EAAU,OAASR,EAC1B,SAAU,CACR,GAAGC,EACH,OAAQO,EAAU,SAAWP,EAAS,MACxC,CACF,EACAQ,CACF,CACF,CACF,ERpEO,SAASE,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","SessionsAPI","CohostEndpoint","input","id","apiBaseUrl","defaultSettings","runtimeOverrides","request","token","baseUrl","apiBaseUrl","debug","path","options","method","data","query","headers","queryString","acc","key","value","url","runtimeOverrides","reqHeaders","defaultSettings","body","res","responseBody","message","CohostClient","_CohostClient","options","customRequestFn","__publicField","token","settings","sharedRequest","request","apiBaseUrl","EventsAPI","OrdersAPI","SessionsAPI","overrides","overriddenRequest","path","createCohostClient","options","CohostClient"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/endpoint.ts","../src/api/events.ts","../src/api/orders.ts","../src/api/sessions.ts","../src/apiVersion.ts","../src/settings.ts","../src/http/request.ts","../src/client.ts"],"sourcesContent":["import { CohostClient, CohostClientOptions } from './client';\nexport { CohostClientSettings } from './settings';\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';\nimport { EventProfile, Ticket } from '../../types/index';\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 list = await client.events.list();\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 /**\n * Fetch a list of all events.\n * \n * @returns A Promise resolving to an array of event objects\n * @throws Will throw an error if the request fails\n * \n * @todo Implement pagination and filtering options\n */\n async list() {\n return this.request<EventProfile[]>('/events');\n }\n\n\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<EventProfile>(`/events/${id}`);\n }\n\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<Ticket[]>(`/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","import { CohostEndpoint } from '../endpoint';\nimport {\n CartSession,\n UpdatableCartSession,\n} from '../../types/index';\nimport { StartCartSessionInput } from '../types/sessions';\n\n/**\n * Provides methods to interact with cart sessions in the Cohost API.\n *\n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const session = await client.sessions.start({ contextId: 'evt_abc123' });\n * ```\n */\nexport class SessionsAPI extends CohostEndpoint {\n\n\n /**\n * Start a new cart session.\n *\n * @param input - Data to start the session\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the request fails\n */\n async start(input: StartCartSessionInput) {\n return this.request<CartSession>('/cart/sessions', {\n method: 'POST',\n data: input,\n });\n }\n\n /**\n * Get a cart session by its ID.\n *\n * @param id - The unique session ID\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the session is not found or request fails\n */\n async get(id: string) {\n return this.request<CartSession>(`/cart/sessions/${id}`);\n }\n\n /**\n * Update a cart session.\n *\n * @param id - The ID of the session to update\n * @param input - Data to update the session\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the update fails\n */\n async update(id: string, input: UpdatableCartSession) {\n return this.request<CartSession>(`/cart/sessions/${id}`, {\n method: 'PATCH',\n data: input,\n });\n }\n\n /**\n * Cancel (soft delete) a cart session.\n *\n * @param id - The ID of the session to cancel\n * @returns Nothing if successful\n * @throws Will throw an error if the cancel operation fails\n */\n async cancel(id: string) {\n return this.request<void>(`/cart/sessions/${id}`, {\n method: 'DELETE',\n });\n }\n\n\n\n /**\n * Update an item in the cart session.\n *\n * @param sessionId - The ID of the session\n * @param props - Properties to update\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the update fails\n */\n async updateItem(sessionId: string, props: {\n offeringId: string;\n quantity: number;\n }) {\n return this.request<CartSession>(`/cart/sessions/${sessionId}/item`, {\n method: 'POST',\n });\n }\n\n /**\n * Remove an item from the cart session.\n * The same as setting the quantity to 0.\n * \n * @param sessionId \n * @param offeringId \n * @returns {CartSession} The latest cart session\n */\n async deleteItem(sessionId: string, offeringId: string) {\n return this.updateItem(sessionId, {\n offeringId,\n quantity: 0,\n });\n }\n\n}\n","export const apiVersion = '0.1.0';\nexport const apiVersionDate = '2025-04-15';\nexport const apiBaseUrl = 'https://api.cohost.com/v1'","/**\n * Optional settings for customizing the behavior of the CohostClient.\n */\nexport interface CohostClientSettings {\n /** Enable verbose debug output for all API requests. */\n debug?: boolean;\n\n /** Override the default API base URL (defaults to apiBaseUrl). */\n apiUrl?: string;\n}\n\n// settings.ts\nexport const defaultSettings = {\n baseUrl: 'https://api.cohost.vip',\n headers: {\n 'Content-Type': 'application/json',\n },\n};\n\n// In dev or testing, you can override this in the browser or Node\nexport let runtimeOverrides: {\n baseUrl?: string;\n headers?: Record<string, string>;\n} = {};\n\nexport function setSdkOverrides(overrides: typeof runtimeOverrides) {\n runtimeOverrides = overrides;\n}\n\n","import { apiBaseUrl } from \"../apiVersion\";\nimport { defaultSettings, runtimeOverrides } from \"../settings\";\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 * The generic <T> allows you to specify the expected response type.\n */\ntype RequestFn = <T = any>(\n path: string,\n options?: {\n method?: RequestMethod;\n data?: any;\n query?: Record<string, string | number | boolean | undefined>;\n headers?: Record<string, string>;\n }\n) => Promise<T>;\n\n/**\n * Creates a request function configured with authentication and client defaults.\n * The returned function supports generic return typing via <T>.\n */\nconst request = ({ token, baseUrl = apiBaseUrl, debug = false }: RequestProps): RequestFn => {\n return async function <T = any>(\n path: string,\n options: {\n method?: RequestMethod;\n data?: any;\n query?: Record<string, string | number | boolean | undefined>;\n headers?: Record<string, string>;\n } = {}\n ): Promise<T> {\n const { method = \"GET\", data, query, headers = {} } = options;\n\n // Construct query string from `query` object\n const queryString = query\n ? \"?\" +\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 finalBaseUrl = runtimeOverrides.baseUrl ?? baseUrl;\n const url = `${finalBaseUrl}${path}${queryString}`;\n\n // Merge default, runtime, and per-request headers\n const reqHeaders: Record<string, string> = {\n ...defaultSettings.headers,\n ...runtimeOverrides.headers,\n ...headers,\n };\n\n // Add Authorization header if token is present\n if (token) {\n reqHeaders[\"Authorization\"] = `Bearer ${token}`;\n }\n\n // Only send body if method allows it\n const body = data && method !== \"GET\" ? JSON.stringify(data) : undefined;\n\n // Optional debug logging\n if (debug) {\n console.log(`[Cohost SDK] Request: ${method} ${url}`);\n if (body) console.log(`[Cohost SDK] Body:`, body);\n console.log(`[Cohost SDK] Headers:`, reqHeaders);\n }\n\n const res = await fetch(url, {\n method,\n headers: reqHeaders,\n body,\n });\n\n // Parse the response based on content type\n const isJson = res.headers.get(\"content-type\")?.includes(\"application/json\");\n const responseBody = isJson ? await res.json() : await res.text();\n\n // Handle error responses\n if (!res.ok) {\n const message = typeof responseBody === \"string\" ? responseBody : JSON.stringify(responseBody);\n console.error(`[Cohost SDK] Error: ${message}`, {\n url\n });\n throw new Error(`[Cohost SDK] ${res.status} ${res.statusText}: ${message}`);\n }\n\n // If wrapped response structure with { status: 'ok', data }, return `data`\n if (\n typeof responseBody === \"object\" &&\n responseBody !== null &&\n (responseBody as any).status === \"ok\" &&\n \"data\" in responseBody\n ) {\n return (responseBody as { data: T }).data;\n }\n\n // Fallback for raw/unwrapped responses\n return responseBody as T;\n };\n};\n\nexport { request, RequestProps, RequestFn };\n","import { EventsAPI } from './api/events';\nimport { OrdersAPI } from './api/orders';\nimport { SessionsAPI } from './api/sessions';\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 */\nexport class CohostClient {\n public readonly events: EventsAPI;\n public readonly orders: OrdersAPI;\n public readonly cart: SessionsAPI;\n\n private readonly baseOptions: CohostClientOptions;\n\n constructor(options: CohostClientOptions, customRequestFn?: RequestFn) {\n this.baseOptions = options;\n\n const { token, settings = {} } = options;\n\n const sharedRequest = customRequestFn ?? 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 this.cart = new SessionsAPI(sharedRequest, settings);\n }\n\n /**\n * Returns a new CohostClient instance with overridden request behavior\n */\n public requestWithOverrides(overrides: {\n token?: string;\n baseUrl?: string;\n headers?: Record<string, string>;\n }): CohostClient {\n const { token, settings = {} } = this.baseOptions;\n\n const overriddenRequest: RequestFn = (path, options = {}) =>\n request({\n token: overrides.token ?? token,\n baseUrl: overrides.baseUrl ?? settings.apiUrl ?? apiBaseUrl,\n debug: settings.debug,\n })(path, {\n ...options,\n headers: {\n ...(overrides.headers || {}),\n ...(options.headers || {}),\n },\n });\n\n return new CohostClient(\n {\n token: overrides.token ?? token,\n settings: {\n ...settings,\n apiUrl: overrides.baseUrl ?? settings.apiUrl,\n },\n },\n overriddenRequest\n );\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,ECRO,IAAME,EAAN,cAAwBC,CAAe,CAU5C,MAAM,MAAO,CACX,OAAO,KAAK,QAAwB,SAAS,CAC/C,CAUA,MAAM,MAAMC,EAAY,CACtB,OAAO,KAAK,QAAsB,WAAWA,CAAE,EAAE,CACnD,CAWA,MAAM,QAAQA,EAAY,CACxB,OAAO,KAAK,QAAkB,WAAWA,CAAE,UAAU,CACvD,CACF,ECzCO,IAAMC,EAAN,cAAwBC,CAAe,CAS5C,MAAM,MAAMC,EAAYC,EAAa,CAEnC,OAAO,KAAK,QAAQ,WAAWD,CAAE,EAAE,CACrC,CACF,ECVO,IAAME,EAAN,cAA0BC,CAAe,CAW5C,MAAM,MAAMC,EAA8B,CACtC,OAAO,KAAK,QAAqB,iBAAkB,CAC/C,OAAQ,OACR,KAAMA,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M,EAAYL,EAAeD,CAAQ,CACrD,CAKO,qBAAqBO,EAIX,CACf,GAAM,CAAE,MAAAR,EAAO,SAAAC,EAAW,CAAC,CAAE,EAAI,KAAK,YAEhCQ,EAA+B,CAACC,EAAMb,EAAU,CAAC,IACrDM,EAAQ,CACN,MAAOK,EAAU,OAASR,EAC1B,QAASQ,EAAU,SAAWP,EAAS,QAAUG,EACjD,MAAOH,EAAS,KAClB,CAAC,EAAES,EAAM,CACP,GAAGb,EACH,QAAS,CACP,GAAIW,EAAU,SAAW,CAAC,EAC1B,GAAIX,EAAQ,SAAW,CAAC,CAC1B,CACF,CAAC,EAEH,OAAO,IAAID,EACT,CACE,MAAOY,EAAU,OAASR,EAC1B,SAAU,CACR,GAAGC,EACH,OAAQO,EAAU,SAAWP,EAAS,MACxC,CACF,EACAQ,CACF,CACF,CACF,ERnEO,SAASE,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","SessionsAPI","CohostEndpoint","input","id","sessionId","props","offeringId","apiBaseUrl","defaultSettings","runtimeOverrides","request","token","baseUrl","apiBaseUrl","debug","path","options","method","data","query","headers","queryString","acc","key","value","url","runtimeOverrides","reqHeaders","defaultSettings","body","res","responseBody","message","CohostClient","_CohostClient","options","customRequestFn","__publicField","token","settings","sharedRequest","request","apiBaseUrl","EventsAPI","OrdersAPI","SessionsAPI","overrides","overriddenRequest","path","createCohostClient","options","CohostClient"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var E=Object.defineProperty;var
|
|
1
|
+
var E=Object.defineProperty;var $=(s,t,e)=>t in s?E(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var a=(s,t,e)=>$(s,typeof t!="symbol"?t+"":t,e);var u=class{constructor(t,e){a(this,"request");a(this,"settings");this.request=t,this.settings=e}};var h=class extends u{async list(){return this.request("/events")}async fetch(t){return this.request(`/events/${t}`)}async tickets(t){return this.request(`/events/${t}/tickets`)}};var g=class extends u{async fetch(t,e){return this.request(`/orders/${t}`)}};var m=class extends u{async start(t){return this.request("/cart/sessions",{method:"POST",data:t})}async get(t){return this.request(`/cart/sessions/${t}`)}async update(t,e){return this.request(`/cart/sessions/${t}`,{method:"PATCH",data:e})}async cancel(t){return this.request(`/cart/sessions/${t}`,{method:"DELETE"})}async updateItem(t,e){return this.request(`/cart/sessions/${t}/item`,{method:"POST"})}async deleteItem(t,e){return this.updateItem(t,{offeringId:e,quantity:0})}};var l="https://api.cohost.com/v1";var x={baseUrl:"https://api.cohost.vip",headers:{"Content-Type":"application/json"}},S={};var b=({token:s,baseUrl:t=l,debug:e=!1})=>async function(i,r={}){let{method:n="GET",data:p,query:R,headers:T={}}=r,O=R?"?"+new URLSearchParams(Object.entries(R).reduce((c,[P,U])=>(U!==void 0&&(c[P]=String(U)),c),{})).toString():"",C=`${S.baseUrl??t}${i}${O}`,q={...x.headers,...S.headers,...T};s&&(q.Authorization=`Bearer ${s}`);let y=p&&n!=="GET"?JSON.stringify(p):void 0;e&&(console.log(`[Cohost SDK] Request: ${n} ${C}`),y&&console.log("[Cohost SDK] Body:",y),console.log("[Cohost SDK] Headers:",q));let d=await fetch(C,{method:n,headers:q,body:y}),o=d.headers.get("content-type")?.includes("application/json")?await d.json():await d.text();if(!d.ok){let c=typeof o=="string"?o:JSON.stringify(o);throw console.error(`[Cohost SDK] Error: ${c}`,{url:C}),new Error(`[Cohost SDK] ${d.status} ${d.statusText}: ${c}`)}return typeof o=="object"&&o!==null&&o.status==="ok"&&"data"in o?o.data:o};var f=class s{constructor(t,e){a(this,"events");a(this,"orders");a(this,"cart");a(this,"baseOptions");this.baseOptions=t;let{token:i,settings:r={}}=t,n=e??b({token:i,baseUrl:r.apiUrl||l,debug:r.debug});this.events=new h(n,r),this.orders=new g(n,r),this.cart=new m(n,r)}requestWithOverrides(t){let{token:e,settings:i={}}=this.baseOptions,r=(n,p={})=>b({token:t.token??e,baseUrl:t.baseUrl??i.apiUrl??l,debug:i.debug})(n,{...p,headers:{...t.headers||{},...p.headers||{}}});return new s({token:t.token??e,settings:{...i,apiUrl:t.baseUrl??i.apiUrl}},r)}};function st(s){return new f(s)}export{f as CohostClient,st as createCohostClient};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/endpoint.ts","../src/api/events.ts","../src/api/orders.ts","../src/api/sessions.ts","../src/apiVersion.ts","../src/settings.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';\nimport { EventProfile, Ticket } from '../../types/index';\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 list = await client.events.list();\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 /**\n * Fetch a list of all events.\n * \n * @returns A Promise resolving to an array of event objects\n * @throws Will throw an error if the request fails\n * \n * @todo Implement pagination and filtering options\n */\n async list() {\n return this.request<EventProfile[]>('/events');\n }\n\n\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<EventProfile>(`/events/${id}`);\n }\n\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<Ticket[]>(`/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","import { CohostEndpoint } from '../endpoint';\nimport {\n CartSession,\n UpdatableCartSession,\n} from '../../types/index';\nimport { StartCartSessionInput } from '../types/sessions';\n\n/**\n * Provides methods to interact with cart sessions in the Cohost API.\n *\n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const session = await client.sessions.start({ contextId: 'evt_abc123' });\n * ```\n */\nexport class SessionsAPI extends CohostEndpoint {\n /**\n * Start a new cart session.\n *\n * @param input - Data to start the session\n * @returns The newly created cart session\n * @throws Will throw an error if the request fails\n */\n async start(input: StartCartSessionInput) {\n return this.request<CartSession>('/cart/sessions', {\n method: 'POST',\n data: input,\n });\n }\n\n /**\n * Get a cart session by its ID.\n *\n * @param id - The unique session ID\n * @returns The cart session object\n * @throws Will throw an error if the session is not found or request fails\n */\n async get(id: string) {\n return this.request<CartSession>(`/cart/sessions/${id}`);\n }\n\n /**\n * Update a cart session.\n *\n * @param id - The ID of the session to update\n * @param input - Data to update the session\n * @returns The updated session\n * @throws Will throw an error if the update fails\n */\n async update(id: string, input: UpdatableCartSession) {\n return this.request<CartSession>(`/cart/sessions/${id}`, {\n method: 'PATCH',\n data: input,\n });\n }\n\n /**\n * Cancel (soft delete) a cart session.\n *\n * @param id - The ID of the session to cancel\n * @returns Nothing if successful\n * @throws Will throw an error if the cancel operation fails\n */\n async cancel(id: string) {\n return this.request<void>(`/cart/sessions/${id}`, {\n method: 'DELETE',\n });\n }\n\n}\n","export const apiVersion = '0.1.0';\nexport const apiVersionDate = '2025-04-15';\nexport const apiBaseUrl = 'https://api.cohost.com/v1'","/**\n * Optional settings for customizing the behavior of the CohostClient.\n */\nexport interface CohostClientSettings {\n /** Enable verbose debug output for all API requests. */\n debug?: boolean;\n\n /** Override the default API base URL (defaults to apiBaseUrl). */\n apiUrl?: string;\n}\n\n// settings.ts\nexport const defaultSettings = {\n baseUrl: 'https://api.cohost.vip',\n headers: {\n 'Content-Type': 'application/json',\n },\n};\n\n// In dev or testing, you can override this in the browser or Node\nexport let runtimeOverrides: {\n baseUrl?: string;\n headers?: Record<string, string>;\n} = {};\n\nexport function setSdkOverrides(overrides: typeof runtimeOverrides) {\n runtimeOverrides = overrides;\n}\n\n","import { apiBaseUrl } from \"../apiVersion\";\nimport { defaultSettings, runtimeOverrides } from \"../settings\";\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 * The generic <T> allows you to specify the expected response type.\n */\ntype RequestFn = <T = any>(\n path: string,\n options?: {\n method?: RequestMethod;\n data?: any;\n query?: Record<string, string | number | boolean | undefined>;\n headers?: Record<string, string>;\n }\n) => Promise<T>;\n\n/**\n * Creates a request function configured with authentication and client defaults.\n * The returned function supports generic return typing via <T>.\n */\nconst request = ({ token, baseUrl = apiBaseUrl, debug = false }: RequestProps): RequestFn => {\n return async function <T = any>(\n path: string,\n options: {\n method?: RequestMethod;\n data?: any;\n query?: Record<string, string | number | boolean | undefined>;\n headers?: Record<string, string>;\n } = {}\n ): Promise<T> {\n const { method = \"GET\", data, query, headers = {} } = options;\n\n // Construct query string from `query` object\n const queryString = query\n ? \"?\" +\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 finalBaseUrl = runtimeOverrides.baseUrl ?? baseUrl;\n const url = `${finalBaseUrl}${path}${queryString}`;\n\n // Merge default, runtime, and per-request headers\n const reqHeaders: Record<string, string> = {\n ...defaultSettings.headers,\n ...runtimeOverrides.headers,\n ...headers,\n };\n\n // Add Authorization header if token is present\n if (token) {\n reqHeaders[\"Authorization\"] = `Bearer ${token}`;\n }\n\n // Only send body if method allows it\n const body = data && method !== \"GET\" ? JSON.stringify(data) : undefined;\n\n // Optional debug logging\n if (debug) {\n console.log(`[Cohost SDK] Request: ${method} ${url}`);\n if (body) console.log(`[Cohost SDK] Body:`, body);\n console.log(`[Cohost SDK] Headers:`, reqHeaders);\n }\n\n const res = await fetch(url, {\n method,\n headers: reqHeaders,\n body,\n });\n\n // Parse the response based on content type\n const isJson = res.headers.get(\"content-type\")?.includes(\"application/json\");\n const responseBody = isJson ? await res.json() : await res.text();\n\n // Handle error responses\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 wrapped response structure with { status: 'ok', data }, return `data`\n if (\n typeof responseBody === \"object\" &&\n responseBody !== null &&\n (responseBody as any).status === \"ok\" &&\n \"data\" in responseBody\n ) {\n return (responseBody as { data: T }).data;\n }\n\n // Fallback for raw/unwrapped responses\n return responseBody as T;\n };\n};\n\nexport { request, RequestProps, RequestFn };\n","import { EventsAPI } from './api/events';\nimport { OrdersAPI } from './api/orders';\nimport { SessionsAPI } from './api/sessions';\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 */\nexport class CohostClient {\n public readonly events: EventsAPI;\n public readonly orders: OrdersAPI;\n public readonly cart: SessionsAPI;\n\n private readonly baseOptions: CohostClientOptions;\n\n constructor(options: CohostClientOptions, customRequestFn?: RequestFn) {\n this.baseOptions = options;\n\n const { token, settings = {} } = options;\n\n const sharedRequest = customRequestFn ?? 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 this.cart = new SessionsAPI(sharedRequest, settings);\n }\n\n /**\n * Returns a new CohostClient instance with overridden request behavior\n */\n public requestWithOverrides(overrides: {\n token?: string;\n baseUrl?: string;\n headers?: Record<string, string>;\n }): CohostClient {\n const { token, settings = {} } = this.baseOptions;\n\n const overriddenRequest: RequestFn = (path, options = {}) =>\n request({\n token: overrides.token ?? token,\n baseUrl: overrides.baseUrl ?? settings.apiUrl ?? apiBaseUrl,\n debug: settings.debug,\n })(path, {\n ...options,\n headers: {\n ...(overrides.headers || {}),\n ...(options.headers || {}),\n },\n });\n\n return new CohostClient(\n {\n token: overrides.token ?? token,\n settings: {\n ...settings,\n apiUrl: overrides.baseUrl ?? settings.apiUrl,\n },\n },\n overriddenRequest\n );\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,ECRO,IAAME,EAAN,cAAwBC,CAAe,CAU5C,MAAM,MAAO,CACX,OAAO,KAAK,QAAwB,SAAS,CAC/C,CAUA,MAAM,MAAMC,EAAY,CACtB,OAAO,KAAK,QAAsB,WAAWA,CAAE,EAAE,CACnD,CAWA,MAAM,QAAQA,EAAY,CACxB,OAAO,KAAK,QAAkB,WAAWA,CAAE,UAAU,CACvD,CACF,ECzCO,IAAMC,EAAN,cAAwBC,CAAe,CAS5C,MAAM,MAAMC,EAAYC,EAAa,CAEnC,OAAO,KAAK,QAAQ,WAAWD,CAAE,EAAE,CACrC,CACF,ECVO,IAAME,EAAN,cAA0BC,CAAe,CAQ5C,MAAM,MAAMC,EAA8B,CACtC,OAAO,KAAK,QAAqB,iBAAkB,CAC/C,OAAQ,OACR,KAAMA,CACV,CAAC,CACL,CASA,MAAM,IAAIC,EAAY,CAClB,OAAO,KAAK,QAAqB,kBAAkBA,CAAE,EAAE,CAC3D,CAUA,MAAM,OAAOA,EAAYD,EAA6B,CAClD,OAAO,KAAK,QAAqB,kBAAkBC,CAAE,GAAI,CACrD,OAAQ,QACR,KAAMD,CACV,CAAC,CACL,CASA,MAAM,OAAOC,EAAY,CACrB,OAAO,KAAK,QAAc,kBAAkBA,CAAE,GAAI,CAC9C,OAAQ,QACZ,CAAC,CACL,CAEJ,ECpEO,IAAMC,EAAa,4BCUnB,IAAMC,EAAkB,CAC3B,QAAS,yBACT,Q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O,EAAE,CAC5E,CAGA,OACE,OAAOD,GAAiB,UACxBA,IAAiB,MAChBA,EAAqB,SAAW,MACjC,SAAUA,EAEFA,EAA6B,KAIhCA,CACT,EC/FK,IAAME,EAAN,MAAMC,CAAa,CAOxB,YAAYC,EAA8BC,EAA6B,CANvEC,EAAA,KAAgB,UAChBA,EAAA,KAAgB,UAChBA,EAAA,KAAgB,QAEhBA,EAAA,KAAiB,eAGf,KAAK,YAAcF,EAEnB,GAAM,CAAE,MAAAG,EAAO,SAAAC,EAAW,CAAC,CAAE,EAAIJ,EAE3BK,EAAgBJ,GAAmBK,EAAQ,CAC/C,MAAAH,EACA,QAASC,EAAS,QAAUG,EAC5B,MAAOH,EAAS,KAClB,CAAC,EAED,KAAK,OAAS,IAAII,EAAUH,EAAeD,CAAQ,EACnD,KAAK,OAAS,IAAIK,EAAUJ,EAAeD,CAAQ,EACnD,KAAK,KAAO,IAAIM,EAAYL,EAAeD,CAAQ,CACrD,CAKO,qBAAqBO,EAIX,CACf,GAAM,CAAE,MAAAR,EAAO,SAAAC,EAAW,CAAC,CAAE,EAAI,KAAK,YAEhCQ,EAA+B,CAACC,EAAMb,EAAU,CAAC,IACrDM,EAAQ,CACN,MAAOK,EAAU,OAASR,EAC1B,QAASQ,EAAU,SAAWP,EAAS,QAAUG,EACjD,MAAOH,EAAS,KAClB,CAAC,EAAES,EAAM,CACP,GAAGb,EACH,QAAS,CACP,GAAIW,EAAU,SAAW,CAAC,EAC1B,GAAIX,EAAQ,SAAW,CAAC,CAC1B,CACF,CAAC,EAEH,OAAO,IAAID,EACT,CACE,MAAOY,EAAU,OAASR,EAC1B,SAAU,CACR,GAAGC,EACH,OAAQO,EAAU,SAAWP,EAAS,MACxC,CACF,EACAQ,CACF,CACF,CACF,ECpEO,SAASE,GAAmBC,EAA4C,CAC3E,OAAO,IAAIC,EAAaD,CAAO,CACnC","names":["CohostEndpoint","request","settings","__publicField","EventsAPI","CohostEndpoint","id","OrdersAPI","CohostEndpoint","id","uid","SessionsAPI","CohostEndpoint","input","id","apiBaseUrl","defaultSettings","runtimeOverrides","request","token","baseUrl","apiBaseUrl","debug","path","options","method","data","query","headers","queryString","acc","key","value","url","runtimeOverrides","reqHeaders","defaultSettings","body","res","responseBody","message","CohostClient","_CohostClient","options","customRequestFn","__publicField","token","settings","sharedRequest","request","apiBaseUrl","EventsAPI","OrdersAPI","SessionsAPI","overrides","overriddenRequest","path","createCohostClient","options","CohostClient"]}
|
|
1
|
+
{"version":3,"sources":["../src/endpoint.ts","../src/api/events.ts","../src/api/orders.ts","../src/api/sessions.ts","../src/apiVersion.ts","../src/settings.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';\nimport { EventProfile, Ticket } from '../../types/index';\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 list = await client.events.list();\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 /**\n * Fetch a list of all events.\n * \n * @returns A Promise resolving to an array of event objects\n * @throws Will throw an error if the request fails\n * \n * @todo Implement pagination and filtering options\n */\n async list() {\n return this.request<EventProfile[]>('/events');\n }\n\n\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<EventProfile>(`/events/${id}`);\n }\n\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<Ticket[]>(`/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","import { CohostEndpoint } from '../endpoint';\nimport {\n CartSession,\n UpdatableCartSession,\n} from '../../types/index';\nimport { StartCartSessionInput } from '../types/sessions';\n\n/**\n * Provides methods to interact with cart sessions in the Cohost API.\n *\n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const session = await client.sessions.start({ contextId: 'evt_abc123' });\n * ```\n */\nexport class SessionsAPI extends CohostEndpoint {\n\n\n /**\n * Start a new cart session.\n *\n * @param input - Data to start the session\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the request fails\n */\n async start(input: StartCartSessionInput) {\n return this.request<CartSession>('/cart/sessions', {\n method: 'POST',\n data: input,\n });\n }\n\n /**\n * Get a cart session by its ID.\n *\n * @param id - The unique session ID\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the session is not found or request fails\n */\n async get(id: string) {\n return this.request<CartSession>(`/cart/sessions/${id}`);\n }\n\n /**\n * Update a cart session.\n *\n * @param id - The ID of the session to update\n * @param input - Data to update the session\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the update fails\n */\n async update(id: string, input: UpdatableCartSession) {\n return this.request<CartSession>(`/cart/sessions/${id}`, {\n method: 'PATCH',\n data: input,\n });\n }\n\n /**\n * Cancel (soft delete) a cart session.\n *\n * @param id - The ID of the session to cancel\n * @returns Nothing if successful\n * @throws Will throw an error if the cancel operation fails\n */\n async cancel(id: string) {\n return this.request<void>(`/cart/sessions/${id}`, {\n method: 'DELETE',\n });\n }\n\n\n\n /**\n * Update an item in the cart session.\n *\n * @param sessionId - The ID of the session\n * @param props - Properties to update\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the update fails\n */\n async updateItem(sessionId: string, props: {\n offeringId: string;\n quantity: number;\n }) {\n return this.request<CartSession>(`/cart/sessions/${sessionId}/item`, {\n method: 'POST',\n });\n }\n\n /**\n * Remove an item from the cart session.\n * The same as setting the quantity to 0.\n * \n * @param sessionId \n * @param offeringId \n * @returns {CartSession} The latest cart session\n */\n async deleteItem(sessionId: string, offeringId: string) {\n return this.updateItem(sessionId, {\n offeringId,\n quantity: 0,\n });\n }\n\n}\n","export const apiVersion = '0.1.0';\nexport const apiVersionDate = '2025-04-15';\nexport const apiBaseUrl = 'https://api.cohost.com/v1'","/**\n * Optional settings for customizing the behavior of the CohostClient.\n */\nexport interface CohostClientSettings {\n /** Enable verbose debug output for all API requests. */\n debug?: boolean;\n\n /** Override the default API base URL (defaults to apiBaseUrl). */\n apiUrl?: string;\n}\n\n// settings.ts\nexport const defaultSettings = {\n baseUrl: 'https://api.cohost.vip',\n headers: {\n 'Content-Type': 'application/json',\n },\n};\n\n// In dev or testing, you can override this in the browser or Node\nexport let runtimeOverrides: {\n baseUrl?: string;\n headers?: Record<string, string>;\n} = {};\n\nexport function setSdkOverrides(overrides: typeof runtimeOverrides) {\n runtimeOverrides = overrides;\n}\n\n","import { apiBaseUrl } from \"../apiVersion\";\nimport { defaultSettings, runtimeOverrides } from \"../settings\";\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 * The generic <T> allows you to specify the expected response type.\n */\ntype RequestFn = <T = any>(\n path: string,\n options?: {\n method?: RequestMethod;\n data?: any;\n query?: Record<string, string | number | boolean | undefined>;\n headers?: Record<string, string>;\n }\n) => Promise<T>;\n\n/**\n * Creates a request function configured with authentication and client defaults.\n * The returned function supports generic return typing via <T>.\n */\nconst request = ({ token, baseUrl = apiBaseUrl, debug = false }: RequestProps): RequestFn => {\n return async function <T = any>(\n path: string,\n options: {\n method?: RequestMethod;\n data?: any;\n query?: Record<string, string | number | boolean | undefined>;\n headers?: Record<string, string>;\n } = {}\n ): Promise<T> {\n const { method = \"GET\", data, query, headers = {} } = options;\n\n // Construct query string from `query` object\n const queryString = query\n ? \"?\" +\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 finalBaseUrl = runtimeOverrides.baseUrl ?? baseUrl;\n const url = `${finalBaseUrl}${path}${queryString}`;\n\n // Merge default, runtime, and per-request headers\n const reqHeaders: Record<string, string> = {\n ...defaultSettings.headers,\n ...runtimeOverrides.headers,\n ...headers,\n };\n\n // Add Authorization header if token is present\n if (token) {\n reqHeaders[\"Authorization\"] = `Bearer ${token}`;\n }\n\n // Only send body if method allows it\n const body = data && method !== \"GET\" ? JSON.stringify(data) : undefined;\n\n // Optional debug logging\n if (debug) {\n console.log(`[Cohost SDK] Request: ${method} ${url}`);\n if (body) console.log(`[Cohost SDK] Body:`, body);\n console.log(`[Cohost SDK] Headers:`, reqHeaders);\n }\n\n const res = await fetch(url, {\n method,\n headers: reqHeaders,\n body,\n });\n\n // Parse the response based on content type\n const isJson = res.headers.get(\"content-type\")?.includes(\"application/json\");\n const responseBody = isJson ? await res.json() : await res.text();\n\n // Handle error responses\n if (!res.ok) {\n const message = typeof responseBody === \"string\" ? responseBody : JSON.stringify(responseBody);\n console.error(`[Cohost SDK] Error: ${message}`, {\n url\n });\n throw new Error(`[Cohost SDK] ${res.status} ${res.statusText}: ${message}`);\n }\n\n // If wrapped response structure with { status: 'ok', data }, return `data`\n if (\n typeof responseBody === \"object\" &&\n responseBody !== null &&\n (responseBody as any).status === \"ok\" &&\n \"data\" in responseBody\n ) {\n return (responseBody as { data: T }).data;\n }\n\n // Fallback for raw/unwrapped responses\n return responseBody as T;\n };\n};\n\nexport { request, RequestProps, RequestFn };\n","import { EventsAPI } from './api/events';\nimport { OrdersAPI } from './api/orders';\nimport { SessionsAPI } from './api/sessions';\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 */\nexport class CohostClient {\n public readonly events: EventsAPI;\n public readonly orders: OrdersAPI;\n public readonly cart: SessionsAPI;\n\n private readonly baseOptions: CohostClientOptions;\n\n constructor(options: CohostClientOptions, customRequestFn?: RequestFn) {\n this.baseOptions = options;\n\n const { token, settings = {} } = options;\n\n const sharedRequest = customRequestFn ?? 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 this.cart = new SessionsAPI(sharedRequest, settings);\n }\n\n /**\n * Returns a new CohostClient instance with overridden request behavior\n */\n public requestWithOverrides(overrides: {\n token?: string;\n baseUrl?: string;\n headers?: Record<string, string>;\n }): CohostClient {\n const { token, settings = {} } = this.baseOptions;\n\n const overriddenRequest: RequestFn = (path, options = {}) =>\n request({\n token: overrides.token ?? token,\n baseUrl: overrides.baseUrl ?? settings.apiUrl ?? apiBaseUrl,\n debug: settings.debug,\n })(path, {\n ...options,\n headers: {\n ...(overrides.headers || {}),\n ...(options.headers || {}),\n },\n });\n\n return new CohostClient(\n {\n token: overrides.token ?? token,\n settings: {\n ...settings,\n apiUrl: overrides.baseUrl ?? settings.apiUrl,\n },\n },\n overriddenRequest\n );\n }\n}\n","import { CohostClient, CohostClientOptions } from './client';\nexport { CohostClientSettings } from './settings';\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,ECRO,IAAME,EAAN,cAAwBC,CAAe,CAU5C,MAAM,MAAO,CACX,OAAO,KAAK,QAAwB,SAAS,CAC/C,CAUA,MAAM,MAAMC,EAAY,CACtB,OAAO,KAAK,QAAsB,WAAWA,CAAE,EAAE,CACnD,CAWA,MAAM,QAAQA,EAAY,CACxB,OAAO,KAAK,QAAkB,WAAWA,CAAE,UAAU,CACvD,CACF,ECzCO,IAAMC,EAAN,cAAwBC,CAAe,CAS5C,MAAM,MAAMC,EAAYC,EAAa,CAEnC,OAAO,KAAK,QAAQ,WAAWD,CAAE,EAAE,CACrC,CACF,ECVO,IAAME,EAAN,cAA0BC,CAAe,CAW5C,MAAM,MAAMC,EAA8B,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,OAAS,IAAIK,EAAUJ,EAAeD,CAAQ,EACnD,KAAK,KAAO,IAAIM,EAAYL,EAAeD,CAAQ,CACrD,CAKO,qBAAqBO,EAIX,CACf,GAAM,CAAE,MAAAR,EAAO,SAAAC,EAAW,CAAC,CAAE,EAAI,KAAK,YAEhCQ,EAA+B,CAACC,EAAMb,EAAU,CAAC,IACrDM,EAAQ,CACN,MAAOK,EAAU,OAASR,EAC1B,QAASQ,EAAU,SAAWP,EAAS,QAAUG,EACjD,MAAOH,EAAS,KAClB,CAAC,EAAES,EAAM,CACP,GAAGb,EACH,QAAS,CACP,GAAIW,EAAU,SAAW,CAAC,EAC1B,GAAIX,EAAQ,SAAW,CAAC,CAC1B,CACF,CAAC,EAEH,OAAO,IAAID,EACT,CACE,MAAOY,EAAU,OAASR,EAC1B,SAAU,CACR,GAAGC,EACH,OAAQO,EAAU,SAAWP,EAAS,MACxC,CACF,EACAQ,CACF,CACF,CACF,ECnEO,SAASE,GAAmBC,EAA4C,CAC3E,OAAO,IAAIC,EAAaD,CAAO,CACnC","names":["CohostEndpoint","request","settings","__publicField","EventsAPI","CohostEndpoint","id","OrdersAPI","CohostEndpoint","id","uid","SessionsAPI","CohostEndpoint","input","id","sessionId","props","offeringId","apiBaseUrl","defaultSettings","runtimeOverrides","request","token","baseUrl","apiBaseUrl","debug","path","options","method","data","query","headers","queryString","acc","key","value","url","runtimeOverrides","reqHeaders","defaultSettings","body","res","responseBody","message","CohostClient","_CohostClient","options","customRequestFn","__publicField","token","settings","sharedRequest","request","apiBaseUrl","EventsAPI","OrdersAPI","SessionsAPI","overrides","overriddenRequest","path","createCohostClient","options","CohostClient"]}
|