@medalsocial/sdk 1.6.0 → 1.7.0

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.
@@ -573,6 +573,24 @@ declare class BaseClient {
573
573
  get<T>(path: string, params?: Record<string, string | undefined>): Promise<T>;
574
574
  /** Execute an authenticated POST request with a JSON body. */
575
575
  post<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
576
+ /**
577
+ * Execute a POST that must never execute twice, guaranteeing an
578
+ * `Idempotency-Key`.
579
+ *
580
+ * {@link BaseClient.post} retries 429 and 5xx automatically, so a write
581
+ * whose transaction committed before the gateway failed would otherwise be
582
+ * submitted a second time — booking the same slot twice. A key turns that
583
+ * retry into a replay: the server keys on the key, the workspace, and the
584
+ * method+path, and answers a repeat with the stored response, or 409 while
585
+ * the first attempt is still in flight. Either way the write happens once.
586
+ *
587
+ * The key is minted ONCE here, outside the retry loop in `request`, so every
588
+ * attempt of the same logical call carries the same value — a key minted per
589
+ * attempt would deduplicate nothing. A caller-supplied key always wins, so
590
+ * callers keeping their own records stay in control. See
591
+ * {@link resolveIdempotencyKey} for what counts as supplied.
592
+ */
593
+ postOnce<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
576
594
  /** Execute an authenticated PATCH request with a JSON body. */
577
595
  patch<T>(path: string, body: unknown, options?: RequestOptions): Promise<T>;
578
596
  /** Execute an authenticated DELETE request. */
@@ -582,6 +600,425 @@ declare class BaseClient {
582
600
  private request;
583
601
  }
584
602
 
603
+ /**
604
+ * A timestamp on the way IN to the booking API: Unix milliseconds, or an
605
+ * ISO 8601 date-time string.
606
+ *
607
+ * Both are accepted so a caller can book by echoing back the `start_ts` of a
608
+ * slot it just fetched — responses render every timestamp as ISO, requests
609
+ * take either. The API normalises to milliseconds server-side.
610
+ */
611
+ type BookingTimestampInput = number | string;
612
+ /** Lifecycle state of a booking. */
613
+ type BookingStatus = "pending" | "confirmed" | "completed" | "cancelled" | "no_show";
614
+ /**
615
+ * Who cancelled a booking. `staff` is a cancel made through
616
+ * `bookings.cancel(id)`, `customer` one made through
617
+ * `bookings.manage.cancel(token)`, `system` an automated one.
618
+ */
619
+ type BookingCancelledBy = "customer" | "staff" | "system";
620
+ /** Payment state of a booking. */
621
+ type BookingPaymentStatus = "none" | "reserved" | "captured" | "refunded";
622
+ /** Surface a booking was created through. API-created bookings are `api`. */
623
+ type BookingCreatedVia = "web" | "dashboard" | "walk_in" | "api";
624
+ /** Kind of bookable resource a booking lands on. */
625
+ type BookingResourceType = "staff" | "room" | "equipment";
626
+ /**
627
+ * One appointment: a contact holding a service slot on a resource.
628
+ *
629
+ * Money is `amount_ore` — an INTEGER number of øre, never a float and never
630
+ * kroner. Timestamps are ISO 8601 strings.
631
+ */
632
+ interface Booking {
633
+ id: string;
634
+ contact_id: string | null;
635
+ service_id: string | null;
636
+ resource_id: string | null;
637
+ start_ts: string | null;
638
+ end_ts: string | null;
639
+ booked_for_name: string | null;
640
+ /** Birth year (not a birthdate) of whoever the appointment is for. */
641
+ booked_for_birth_year: number | null;
642
+ /** Shared by every booking created in the same party request. */
643
+ party_sequence_id: string | null;
644
+ status: BookingStatus;
645
+ cancelled_by: BookingCancelledBy | null;
646
+ cancel_reason: string | null;
647
+ /** Set on the booking a reschedule created, pointing at the one it replaced. */
648
+ rescheduled_from_id: string | null;
649
+ payment_status: BookingPaymentStatus;
650
+ /** Price in integer øre. */
651
+ amount_ore: number | null;
652
+ /** Customer-visible note. */
653
+ notes: string | null;
654
+ /** Staff-only note; never shown to the customer. */
655
+ internal_notes: string | null;
656
+ created_via: BookingCreatedVia | null;
657
+ created_at: string | null;
658
+ updated_at: string | null;
659
+ }
660
+ /** A bookable service in the workspace catalogue. */
661
+ interface BookingService {
662
+ id: string;
663
+ name: string | null;
664
+ description: string | null;
665
+ category: string | null;
666
+ duration_minutes: number | null;
667
+ buffer_before_minutes: number | null;
668
+ buffer_after_minutes: number | null;
669
+ /** Price in integer øre. */
670
+ price_ore: number | null;
671
+ weekend_surcharge_pct: number | null;
672
+ /** Resource types this service needs, e.g. `["staff"]`. */
673
+ resource_requirements: string[];
674
+ bookable_online: boolean;
675
+ max_per_booking: number | null;
676
+ color: string | null;
677
+ sort_order: number | null;
678
+ active: boolean;
679
+ created_at: string | null;
680
+ updated_at: string | null;
681
+ }
682
+ /** Who or what performs a service: a staff member, a room, or equipment. */
683
+ interface BookingResource {
684
+ id: string;
685
+ type: BookingResourceType | null;
686
+ name: string | null;
687
+ photo_url: string | null;
688
+ bio: string | null;
689
+ /** Services this resource can perform. */
690
+ service_ids: string[];
691
+ capacity: number | null;
692
+ sort_order: number | null;
693
+ active: boolean;
694
+ created_at: string | null;
695
+ updated_at: string | null;
696
+ }
697
+ /** One free slot returned by `bookings.availability(...)`. */
698
+ interface BookingSlot {
699
+ start_ts: string | null;
700
+ end_ts: string | null;
701
+ resource_id: string | null;
702
+ }
703
+ /**
704
+ * One date a service can be booked on, from `bookings.schedule(...)`.
705
+ *
706
+ * `date` is the workspace's own calendar date (`YYYY-MM-DD`), not a timestamp.
707
+ * `last_start_ts` is the last start this service could occupy on that date —
708
+ * not the closing time; a 30-minute service at a salon closing 17:00 has its
709
+ * last start at 16:30 — and is `null` for a date with posted hours that is
710
+ * shut outright (a public holiday). A date ABSENT from the list is closed.
711
+ */
712
+ interface BookingScheduleDay {
713
+ date: string | null;
714
+ opens_ts: string | null;
715
+ closes_ts: string | null;
716
+ last_start_ts: string | null;
717
+ }
718
+ /** One line of a party booking — a single service on a single slot. */
719
+ interface CreateBookingItemInput {
720
+ service_id: string;
721
+ /** Leave unset to let the engine pick a free resource. */
722
+ resource_id?: string;
723
+ start_ts: BookingTimestampInput;
724
+ booked_for_name?: string;
725
+ /** Birth year (not a birthdate) of whoever the appointment is for. */
726
+ booked_for_birth_year?: number;
727
+ }
728
+ /** The person the booking is made under. Phone is the CRM dedupe key. */
729
+ interface BookingContactInput {
730
+ phone: string;
731
+ email?: string;
732
+ name?: string;
733
+ }
734
+ /**
735
+ * Input for `bookings.create(...)`. `items` is a PARTY — one request books a
736
+ * whole family in one all-or-nothing transaction (max 50 items).
737
+ */
738
+ /** Provenance an API caller may claim. `dashboard` and `walk_in` are staff-only and rejected. */
739
+ type BookingClaimableCreatedVia = "web" | "api";
740
+ interface CreateBookingInput {
741
+ items: CreateBookingItemInput[];
742
+ contact: BookingContactInput;
743
+ notes?: string;
744
+ /**
745
+ * Defaults to `api`. A workspace's OWN website should send `web`, so "how
746
+ * many bookings did the site bring in" is answerable; integrations leave it
747
+ * unset. `dashboard` and `walk_in` are refused with 400 — a bearer token
748
+ * proves which workspace is calling, not that a member typed it in.
749
+ */
750
+ created_via?: BookingClaimableCreatedVia;
751
+ }
752
+ /** One entry of `BookingCreateResult.bookings`, in request order. */
753
+ interface CreatedBooking {
754
+ id: string;
755
+ /**
756
+ * Show-once secret for the customer's manage link.
757
+ *
758
+ * Only its SHA-256 hash is stored, so this response is the ONLY place it
759
+ * ever appears — persist it here or it is gone. It is **absent** (the key is
760
+ * dropped, not nulled) when the response is replayed from an
761
+ * `Idempotency-Key`, since tokens are redacted from replays.
762
+ *
763
+ * A lost token cannot be recovered: {@link Booking} carries no token field,
764
+ * so re-reading the booking will not produce it. Either reschedule the
765
+ * booking (which mints a fresh token) or have staff act on it by id.
766
+ */
767
+ manage_token?: string;
768
+ }
769
+ /** Result returned after creating a booking or party. */
770
+ interface BookingCreateResult {
771
+ bookings: CreatedBooking[];
772
+ contact_id: string;
773
+ }
774
+ /** Result of a cancel or no-show. */
775
+ interface BookingActionResult {
776
+ success: true;
777
+ }
778
+ /**
779
+ * Result of a reschedule. A reschedule cancels the old booking and inserts a
780
+ * new one, so `booking_id` is a NEW id — the one you passed in is now cancelled.
781
+ */
782
+ interface BookingRescheduleResult {
783
+ success: true;
784
+ booking_id: string;
785
+ /**
786
+ * Freshly minted manage token for the new booking. Same show-once rule as
787
+ * {@link CreatedBooking.manage_token}: absent on an idempotent replay.
788
+ */
789
+ manage_token?: string;
790
+ }
791
+ /**
792
+ * What the holder of a manage token may see and do — the payload behind a
793
+ * customer's "manage my booking" link.
794
+ *
795
+ * `can_cancel` / `can_reschedule` already account for the workspace's policy
796
+ * windows, so honour them rather than re-deriving from the window hours.
797
+ */
798
+ interface ManageSummary {
799
+ booking_id: string;
800
+ contact_id: string | null;
801
+ status: BookingStatus | null;
802
+ cancelled_by: BookingCancelledBy | null;
803
+ cancel_reason: string | null;
804
+ rescheduled_from_id: string | null;
805
+ start_ts: string | null;
806
+ end_ts: string | null;
807
+ service_id: string | null;
808
+ service_name: string | null;
809
+ resource_id: string | null;
810
+ resource_name: string | null;
811
+ booked_for_name: string | null;
812
+ party_sequence_id: string | null;
813
+ /** Price in integer øre. */
814
+ amount_ore: number | null;
815
+ payment_status: BookingPaymentStatus | null;
816
+ /** IANA zone the booking's local times should be rendered in. */
817
+ time_zone: string | null;
818
+ cancel_window_hours: number | null;
819
+ reschedule_window_hours: number | null;
820
+ can_cancel: boolean;
821
+ can_reschedule: boolean;
822
+ }
823
+ /** The annotation fields a booking accepts. */
824
+ interface BookingNoteFields {
825
+ /** Customer-visible note. Pass `""` to clear it. */
826
+ notes?: string;
827
+ /** Staff-only note; never shown to the customer. Pass `""` to clear it. */
828
+ internal_notes?: string;
829
+ }
830
+ /**
831
+ * Input for annotating a booking.
832
+ *
833
+ * At least one of `notes` or `internal_notes` must be present: the API's
834
+ * `updateBookingSchema` refuses a body carrying neither with a 400, so the
835
+ * union turns `update(id, {})` into a compile error rather than a wasted round
836
+ * trip. Note that `""` is a meaningful value — it clears the field — which is
837
+ * why the constraint is on presence, not on emptiness.
838
+ */
839
+ type UpdateBookingInput = (BookingNoteFields & {
840
+ notes: string;
841
+ }) | (BookingNoteFields & {
842
+ internal_notes: string;
843
+ });
844
+ /** Optional reason recorded against a cancellation. */
845
+ interface CancelBookingInput {
846
+ reason?: string;
847
+ }
848
+ /** Input for moving a booking to a new slot, and optionally a new resource. */
849
+ interface RescheduleBookingInput {
850
+ new_start_ts: BookingTimestampInput;
851
+ new_resource_id?: string;
852
+ }
853
+ /**
854
+ * Pagination for a bookings page.
855
+ *
856
+ * `truncated` is the extra statement this list carries: the underlying read is
857
+ * capped, and when the cap binds there are matching bookings that no cursor
858
+ * from this call reaches. Narrow `from_ts`/`to_ts` when you see it.
859
+ */
860
+ interface BookingsPagination {
861
+ has_more: boolean;
862
+ next_cursor: string | null;
863
+ truncated: boolean;
864
+ }
865
+ /** A page of bookings. Carries `truncated` on top of the usual pagination. */
866
+ interface BookingsPage {
867
+ data: Booking[];
868
+ pagination: BookingsPagination;
869
+ }
870
+ /** Options for listing bookings with pagination and filters. */
871
+ interface ListBookingsOptions extends PaginationOptions {
872
+ from_ts?: BookingTimestampInput;
873
+ to_ts?: BookingTimestampInput;
874
+ status?: BookingStatus;
875
+ resource_id?: string;
876
+ }
877
+ /** Options for listing the service catalogue. The endpoint is not paginated. */
878
+ interface ListBookingServicesOptions {
879
+ /** Include services with `active: false`. Defaults to active-only. */
880
+ include_inactive?: boolean;
881
+ }
882
+ /**
883
+ * Options for `bookings.schedule(...)`. Same shape as availability, and for
884
+ * the same reason: the last bookable start depends on the service's duration
885
+ * and buffers, so a 30-minute cut and a 90-minute colour run out at different
886
+ * hours of the same afternoon.
887
+ */
888
+ interface BookingScheduleOptions {
889
+ service_id: string;
890
+ from_ts: BookingTimestampInput;
891
+ /** Must be after `from_ts`. */
892
+ to_ts: BookingTimestampInput;
893
+ /** Restrict to one resource's hours. */
894
+ resource_id?: string;
895
+ }
896
+ /** Options for querying free slots. The window is required and half-open. */
897
+ interface BookingAvailabilityOptions {
898
+ service_id: string;
899
+ from_ts: BookingTimestampInput;
900
+ /** Must be after `from_ts`. */
901
+ to_ts: BookingTimestampInput;
902
+ /** Restrict slots to one resource. Defaults to every capable resource. */
903
+ resource_id?: string;
904
+ }
905
+
906
+ /**
907
+ * Customer-side booking management, addressed by the show-once manage token
908
+ * from `bookings.create(...)` rather than by booking id.
909
+ *
910
+ * These are NOT the staff routes with a different lookup key: possession of
911
+ * the token is the customer's own authorization, so the workspace's cancel and
912
+ * reschedule windows are ENFORCED here (they are bypassed on
913
+ * `bookings.cancel` / `bookings.reschedule`), and a cancel is attributed to
914
+ * the customer rather than to staff. Relay a customer's click on their
915
+ * confirmation-email link through these; act as the business through the
916
+ * id-addressed methods.
917
+ */
918
+ declare class BookingsManage {
919
+ private client;
920
+ constructor(client: BaseClient);
921
+ /**
922
+ * Read what the holder of a manage token may see and do. Honour
923
+ * `can_cancel` / `can_reschedule` — they already apply the policy windows.
924
+ */
925
+ get(token: string): Promise<ApiResponse<ManageSummary>>;
926
+ /** Cancel on the customer's behalf. Rejected outside the cancel window. */
927
+ cancel(token: string, input?: CancelBookingInput, options?: RequestOptions): Promise<ApiResponse<BookingActionResult>>;
928
+ /**
929
+ * Move the booking on the customer's behalf. Rejected outside the reschedule
930
+ * window. Returns a NEW booking id and a new manage token — the old token
931
+ * stops working, so relay the new one into whatever link you send next.
932
+ */
933
+ reschedule(token: string, input: RescheduleBookingInput, options?: RequestOptions): Promise<ApiResponse<BookingRescheduleResult>>;
934
+ }
935
+ /**
936
+ * Appointment bookings: the service catalogue, free slots, and the bookings
937
+ * themselves.
938
+ *
939
+ * Every method here acts as the BUSINESS — policy windows are bypassed and a
940
+ * cancel is recorded against staff. To relay a customer's own action on their
941
+ * confirmation-email link, use {@link Bookings.manage} instead.
942
+ *
943
+ * Money is always integer øre (`amount_ore`, `price_ore`). Timestamps come
944
+ * back as ISO 8601 strings; on the way in, either Unix milliseconds or an ISO
945
+ * string is accepted.
946
+ *
947
+ * @example
948
+ * ```ts
949
+ * const { data: slots } = await medal.bookings.availability({
950
+ * service_id: "svc_1",
951
+ * from_ts: Date.now(),
952
+ * to_ts: Date.now() + 7 * 86_400_000,
953
+ * });
954
+ * const { data } = await medal.bookings.create({
955
+ * items: [{ service_id: "svc_1", start_ts: slots[0].start_ts! }],
956
+ * contact: { phone: "+4790000000", name: "Ida" },
957
+ * });
958
+ * ```
959
+ */
960
+ declare class Bookings {
961
+ private client;
962
+ /** Customer-side actions addressed by manage token. */
963
+ readonly manage: BookingsManage;
964
+ constructor(client: BaseClient);
965
+ /** List the bookable service catalogue. Active-only unless asked otherwise. */
966
+ listServices(options?: ListBookingServicesOptions): Promise<ApiResponse<BookingService[]>>;
967
+ /** List the bookable resources — staff, rooms, and equipment. */
968
+ listResources(): Promise<ApiResponse<BookingResource[]>>;
969
+ /**
970
+ * List free slots for a service over a window. Slots reflect opening hours,
971
+ * time off, buffers, and existing bookings at the moment of the call — they
972
+ * are not held, so a slot can be taken before you book it.
973
+ */
974
+ availability(options: BookingAvailabilityOptions): Promise<ApiResponse<BookingSlot[]>>;
975
+ /**
976
+ * The dates a service can be booked on — the half `availability` cannot
977
+ * answer. Availability returns free slots and nothing else, so a closed day,
978
+ * an evening past closing and a fully booked day are all the same empty
979
+ * array. A date absent from this list is closed; on a listed date, compare
980
+ * `last_start_ts` against the clock to tell "too late today" from "full".
981
+ */
982
+ schedule(options: BookingScheduleOptions): Promise<ApiResponse<BookingScheduleDay[]>>;
983
+ /**
984
+ * List bookings with cursor-based pagination and optional filters.
985
+ *
986
+ * Check `pagination.truncated`: when true the read window was clipped and
987
+ * matching bookings exist that no cursor reaches — narrow `from_ts`/`to_ts`.
988
+ */
989
+ list(options?: ListBookingsOptions): Promise<BookingsPage>;
990
+ /**
991
+ * Book a party — every item succeeds or none do (max 50).
992
+ *
993
+ * Each created booking comes back with a `manage_token` exactly once; only
994
+ * its hash is stored, so persist it if you need the customer's manage link.
995
+ *
996
+ * Automatically idempotent: the SDK mints an `Idempotency-Key` so its own
997
+ * 5xx retries replay rather than book the slot twice. Supply
998
+ * `options.idempotencyKey` to deduplicate across your OWN retries too — the
999
+ * server keys on it for 24 hours, so re-sending the same key after a network
1000
+ * timeout returns the original bookings instead of a second set.
1001
+ */
1002
+ create(input: CreateBookingInput, options?: RequestOptions): Promise<ApiResponse<BookingCreateResult>>;
1003
+ /** Get a booking by ID. */
1004
+ get(id: string): Promise<ApiResponse<Booking>>;
1005
+ /**
1006
+ * Annotate a booking. At least one of `notes` (customer-visible) or
1007
+ * `internal_notes` (staff-only) is required; `""` clears a field.
1008
+ */
1009
+ update(id: string, input: UpdateBookingInput, options?: RequestOptions): Promise<ApiResponse<Booking>>;
1010
+ /** Cancel as the business — the cancel window is bypassed. */
1011
+ cancel(id: string, input?: CancelBookingInput, options?: RequestOptions): Promise<ApiResponse<BookingActionResult>>;
1012
+ /**
1013
+ * Move a booking as the business — the reschedule window is bypassed.
1014
+ * Returns a NEW booking id and a new manage token; the old booking is
1015
+ * cancelled and its token stops working.
1016
+ */
1017
+ reschedule(id: string, input: RescheduleBookingInput, options?: RequestOptions): Promise<ApiResponse<BookingRescheduleResult>>;
1018
+ /** Mark a booking as a no-show. */
1019
+ markNoShow(id: string, options?: RequestOptions): Promise<ApiResponse<BookingActionResult>>;
1020
+ }
1021
+
585
1022
  /**
586
1023
  * Mint short-lived capability confirmation tokens.
587
1024
  *
@@ -621,6 +1058,13 @@ declare class CapabilityConfirmations {
621
1058
  * Setting `user_approved: true` asserts that a human on your side approved
622
1059
  * this specific action. `preview_summary` is what they approved, and is
623
1060
  * retained for audit — write it for a human reader, not a log parser.
1061
+ *
1062
+ * Deliberately unkeyed, unlike the writes it authorizes. Minting is not the
1063
+ * state change the guarantee exists to protect: the write itself is already
1064
+ * bound to `idempotency_key`, so a retry that mints a second token cannot
1065
+ * produce a second write. Keying this call would instead park a credential
1066
+ * designed to expire in 15 minutes inside a replay cache that answers for 24
1067
+ * hours — a worse trade than the duplicate token it would avoid.
624
1068
  */
625
1069
  create(input: IssueCapabilityConfirmationInput): Promise<ApiResponse<CapabilityConfirmation>>;
626
1070
  }
@@ -665,6 +1109,13 @@ declare class ChannelConnectLinks {
665
1109
  *
666
1110
  * Requires the `channel.connect.manage` scope; OAuth callers additionally
667
1111
  * need the workspace `admin` role.
1112
+ *
1113
+ * Automatically idempotent: an unkeyed retry mints a SECOND live single-use
1114
+ * link for the same person, and only one of the two can ever be consumed —
1115
+ * the other stays outstanding until it is revoked or expires. The key the
1116
+ * confirmer chose is the key that goes out — a capability confirmation is
1117
+ * bound to its idempotency key, so minting a fresh one here would invalidate
1118
+ * the confirmation.
668
1119
  */
669
1120
  create(input: CreateConnectLinkInput, options?: RequestOptions): Promise<ApiResponse<ConnectLinkCreateResult>>;
670
1121
  /**
@@ -841,8 +1292,16 @@ declare class Contacts {
841
1292
  constructor(client: BaseClient);
842
1293
  /** List contacts with cursor-based pagination and optional filters. */
843
1294
  list(options?: ListContactsOptions): Promise<PaginatedResponse<Contact>>;
844
- /** Create a new contact. Email must be unique in the workspace. */
845
- create(input: CreateContactInput): Promise<ApiResponse<ContactCreateResult>>;
1295
+ /**
1296
+ * Create a new contact. Email must be unique in the workspace.
1297
+ *
1298
+ * Automatically idempotent: the SDK mints an `Idempotency-Key` so its own
1299
+ * 5xx retries replay rather than run the create a second time. Uniqueness
1300
+ * alone would not save you here — it turns the retry of a committed create
1301
+ * into a spurious conflict, which reads as "the contact was not created".
1302
+ * Supply `options.idempotencyKey` to deduplicate across your OWN retries too.
1303
+ */
1304
+ create(input: CreateContactInput, options?: RequestOptions): Promise<ApiResponse<ContactCreateResult>>;
846
1305
  /** Get a contact by ID. */
847
1306
  get(id: string): Promise<ApiResponse<Contact>>;
848
1307
  /** Update one or more fields on a contact. */
@@ -851,10 +1310,23 @@ declare class Contacts {
851
1310
  remove(id: string): Promise<ApiResponse<ContactRemoveResult>>;
852
1311
  /** Get the activity timeline for a contact. */
853
1312
  activities(id: string, options?: PaginationOptions): Promise<PaginatedResponse<Activity>>;
854
- /** Add a note to a contact's timeline. */
855
- addNote(id: string, input: AddNoteInput): Promise<ApiResponse<ContactNoteResult>>;
856
- /** Bulk import contacts (max 500). Duplicates are skipped. */
857
- import(contacts: ImportContactInput[]): Promise<ApiResponse<ImportContactsResult>>;
1313
+ /**
1314
+ * Add a note to a contact's timeline.
1315
+ *
1316
+ * Automatically idempotent: nothing about a note is unique, so an unkeyed
1317
+ * retry appends the same text to the timeline twice. Supply
1318
+ * `options.idempotencyKey` to deduplicate across your OWN retries too.
1319
+ */
1320
+ addNote(id: string, input: AddNoteInput, options?: RequestOptions): Promise<ApiResponse<ContactNoteResult>>;
1321
+ /**
1322
+ * Bulk import contacts (max 500). Duplicates are skipped.
1323
+ *
1324
+ * Automatically idempotent: the import is processed in chunks, so a retry
1325
+ * after a partial failure re-walks the whole batch and reports `added` /
1326
+ * `skipped` counts for a run that was not the first. Supply
1327
+ * `options.idempotencyKey` to deduplicate across your OWN retries too.
1328
+ */
1329
+ import(contacts: ImportContactInput[], options?: RequestOptions): Promise<ApiResponse<ImportContactsResult>>;
858
1330
  }
859
1331
 
860
1332
  /** A sponsorship or brand deal in the workspace. */
@@ -933,8 +1405,14 @@ declare class Deals {
933
1405
  constructor(client: BaseClient);
934
1406
  /** List deals with cursor-based pagination and optional filters. */
935
1407
  list(options?: ListDealsOptions): Promise<PaginatedResponse<Deal>>;
936
- /** Create a new deal. */
937
- create(input: CreateDealInput): Promise<ApiResponse<DealCreateResult>>;
1408
+ /**
1409
+ * Create a new deal.
1410
+ *
1411
+ * Automatically idempotent: nothing about a deal is unique, so an unkeyed
1412
+ * retry puts a second identical deal in the pipeline. Supply
1413
+ * `options.idempotencyKey` to deduplicate across your OWN retries too.
1414
+ */
1415
+ create(input: CreateDealInput, options?: RequestOptions): Promise<ApiResponse<DealCreateResult>>;
938
1416
  /** Get a deal by ID. */
939
1417
  get(id: string): Promise<ApiResponse<Deal>>;
940
1418
  /** Update one or more fields on a deal. Set contact_id to null to unlink. */
@@ -1076,15 +1554,29 @@ declare class Emails {
1076
1554
  /**
1077
1555
  * Send a transactional email using a template (HTTP 202). The returned `id`
1078
1556
  * is an email send id — poll `emails.get(id)` with it to track delivery.
1557
+ *
1558
+ * Automatically idempotent: the SDK mints an `Idempotency-Key` so its own
1559
+ * 5xx retries replay rather than queue a second copy into someone's inbox —
1560
+ * a send that already committed cannot be un-sent. Supply
1561
+ * `options.idempotencyKey` to deduplicate across your OWN retries too.
1562
+ *
1563
+ * `input.idempotency_key` is the older, body-level form of the same control
1564
+ * and still takes precedence server-side, so setting it keeps working
1565
+ * unchanged.
1079
1566
  */
1080
- send(input: SendEmailInput): Promise<ApiResponse<EmailSendResult>>;
1567
+ send(input: SendEmailInput, options?: RequestOptions): Promise<ApiResponse<EmailSendResult>>;
1081
1568
  /** Get the delivery status of a sent email. */
1082
1569
  get(id: string): Promise<ApiResponse<EmailSend>>;
1083
1570
  /**
1084
1571
  * Send the same template to multiple recipients (max 100, HTTP 202). Each
1085
1572
  * queued recipient gets its own send id in `results` for `emails.get(id)`.
1573
+ *
1574
+ * Automatically idempotent — and this is the call where it matters most: an
1575
+ * unkeyed retry of a batch that already committed sends up to 100 duplicate
1576
+ * emails. Supply `options.idempotencyKey` to deduplicate across your OWN
1577
+ * retries too.
1086
1578
  */
1087
- batch(input: BatchSendInput): Promise<ApiResponse<BatchSendSummary>>;
1579
+ batch(input: BatchSendInput, options?: RequestOptions): Promise<ApiResponse<BatchSendSummary>>;
1088
1580
  }
1089
1581
 
1090
1582
  /** A workspace data export request and its current status. */
@@ -1156,8 +1648,16 @@ interface CookieCategoryConsent {
1156
1648
  declare class Gdpr {
1157
1649
  private client;
1158
1650
  constructor(client: BaseClient);
1159
- /** Request a workspace data export. Runs asynchronously. */
1160
- requestExport(): Promise<ApiResponse<{
1651
+ /**
1652
+ * Request a workspace data export. Runs asynchronously.
1653
+ *
1654
+ * Automatically idempotent: the request is recorded and the export is
1655
+ * scheduled in one step with no de-duplication of its own, so an unkeyed
1656
+ * retry files a second subject-access request and runs a second full export
1657
+ * of the workspace. Supply `options.idempotencyKey` to deduplicate across
1658
+ * your OWN retries too.
1659
+ */
1660
+ requestExport(options?: RequestOptions): Promise<ApiResponse<{
1161
1661
  request_id: string;
1162
1662
  status: string;
1163
1663
  }>>;
@@ -1165,11 +1665,25 @@ declare class Gdpr {
1165
1665
  listExports(): Promise<ApiResponse<GdprExport[]>>;
1166
1666
  /** Get the status of a specific export. */
1167
1667
  getExport(id: string): Promise<ApiResponse<GdprExport>>;
1168
- /** Record a GDPR consent decision for a contact by email. */
1668
+ /**
1669
+ * Record a GDPR consent decision for a contact by email.
1670
+ *
1671
+ * Deliberately unkeyed: a decision is stored once per
1672
+ * (workspace, email, consent type) and overwritten in place, so re-sending
1673
+ * the same body reaches the same state and returns the same record id.
1674
+ */
1169
1675
  recordConsent(input: RecordConsentInput): Promise<ApiResponse<ConsentResult>>;
1170
1676
  /** Get all consent records for a contact by email. */
1171
1677
  getConsent(email: string): Promise<ApiResponse<ConsentRecord[]>>;
1172
- /** Record cookie consent from an external site (legacy endpoint). */
1678
+ /**
1679
+ * Record cookie consent from an external site (legacy endpoint).
1680
+ *
1681
+ * Deliberately unkeyed: this legacy route predates the versioned API and
1682
+ * does not run the `Idempotency-Key` machinery, so a key here would be a
1683
+ * header that changes nothing while implying a guarantee the endpoint cannot
1684
+ * make. Treat a failed call as "unknown" and re-send only if a missing
1685
+ * consent log matters more to you than a duplicate one.
1686
+ */
1173
1687
  cookieConsent(input: CookieConsentInput): Promise<{
1174
1688
  success: boolean;
1175
1689
  logId?: string;
@@ -1198,8 +1712,16 @@ declare class HelpdeskReplies {
1198
1712
  /**
1199
1713
  * Send an operator reply or internal note. Returns HTTP 201.
1200
1714
  *
1201
- * Pass an `idempotencyKey` so retried requests do not create duplicate
1202
- * messages it is REQUIRED for capability-scoped tokens.
1715
+ * Automatically idempotent: a reply is a message to a real person, and an
1716
+ * unkeyed retry sends it to them twice. The key the confirmer chose is the
1717
+ * key that goes out — a capability confirmation is bound to its idempotency
1718
+ * key, so minting a fresh one here would invalidate the confirmation.
1719
+ *
1720
+ * Pass `options.idempotencyKey` to deduplicate across your OWN retries too.
1721
+ * It is REQUIRED for capability-scoped tokens, which need it paired with a
1722
+ * `capabilityConfirmation` — a generated key satisfies the pairing's key
1723
+ * half only; the confirmation is still yours to supply (or to let
1724
+ * `autoConfirm` mint).
1203
1725
  */
1204
1726
  create(input: CreateReplyInput, options?: RequestOptions): Promise<ApiResponse<ReplyCreateResult>>;
1205
1727
  }
@@ -1294,8 +1816,14 @@ declare class Posts {
1294
1816
  constructor(client: BaseClient);
1295
1817
  /** List posts with cursor-based pagination and optional filters. */
1296
1818
  list(options?: ListPostsOptions): Promise<PaginatedResponse<Post>>;
1297
- /** Create a new post with content and target channels. */
1298
- create(input: CreatePostInput): Promise<ApiResponse<{
1819
+ /**
1820
+ * Create a new post with content and target channels.
1821
+ *
1822
+ * Automatically idempotent: the SDK mints an `Idempotency-Key` so its own
1823
+ * 5xx retries replay rather than draft the post twice. Supply
1824
+ * `options.idempotencyKey` to deduplicate across your OWN retries too.
1825
+ */
1826
+ create(input: CreatePostInput, options?: RequestOptions): Promise<ApiResponse<{
1299
1827
  id: string;
1300
1828
  }>>;
1301
1829
  /** Get a post by ID, including its per-channel variants. */
@@ -1308,9 +1836,24 @@ declare class Posts {
1308
1836
  remove(id: string): Promise<ApiResponse<{
1309
1837
  success: boolean;
1310
1838
  }>>;
1311
- /** Schedule a post for future publication. */
1839
+ /**
1840
+ * Schedule a post for future publication.
1841
+ *
1842
+ * Deliberately unkeyed: re-sending the same `scheduled_at` for an
1843
+ * already-scheduled post returns the original `workflow_id` rather than
1844
+ * starting a second one, so a retried schedule cannot double-publish. A
1845
+ * *different* time is rejected — unschedule first.
1846
+ */
1312
1847
  schedule(id: string, input: SchedulePostInput): Promise<ApiResponse<ScheduleResult>>;
1313
- /** Publish a post immediately to all target channels. */
1848
+ /**
1849
+ * Publish a post immediately to all target channels.
1850
+ *
1851
+ * Deliberately unkeyed: publishing moves the post out of the set of statuses
1852
+ * that may be published, so the retry of a publish that already committed is
1853
+ * refused rather than posting a second time. It is refused with a 400 though
1854
+ * — treat an error here as "check the post's status", not as "nothing
1855
+ * happened".
1856
+ */
1314
1857
  publish(id: string): Promise<ApiResponse<PublishResult>>;
1315
1858
  /** List connected publishing channels for this workspace. */
1316
1859
  channels(): Promise<ApiResponse<Channel[]>>;
@@ -1457,10 +2000,15 @@ declare class Scan {
1457
2000
  * Queue a scan. Provide exactly one of `url`, `orgnr`, or `name`.
1458
2001
  * Runs asynchronously — poll with `get()` or use `waitForResult()`.
1459
2002
  *
2003
+ * Automatically idempotent: a scan job is queued the moment it is created,
2004
+ * so an unkeyed retry starts a second crawl of the same site and returns an
2005
+ * id for a job that duplicates one already running. Supply
2006
+ * `options.idempotencyKey` to deduplicate across your OWN retries too.
2007
+ *
1460
2008
  * @throws Error before any request when zero or several selectors are set —
1461
2009
  * the server would reject the body anyway; failing locally is clearer.
1462
2010
  */
1463
- create(input: ScanCreateInput): Promise<ApiResponse<ScanCreateResult>>;
2011
+ create(input: ScanCreateInput, options?: RequestOptions): Promise<ApiResponse<ScanCreateResult>>;
1464
2012
  /** Get a scan job's status and, once done, its findings payload. */
1465
2013
  get(id: string): Promise<ApiResponse<ScanJob>>;
1466
2014
  /** Search the Norwegian company registry by name (typeahead, top 5 hits). */
@@ -1491,6 +2039,13 @@ declare class Webhooks {
1491
2039
  * `secret` is typed optional because an idempotent replay (retrying with the
1492
2040
  * same `Idempotency-Key`, `X-Idempotent-Replayed: true`) returns the existing
1493
2041
  * endpoint WITHOUT the secret — handle that case (rotate if you lost it).
2042
+ *
2043
+ * Automatically idempotent: a duplicate endpoint is not a stray row, it is a
2044
+ * second copy of every future delivery to the same URL, forever. The key the
2045
+ * confirmer chose is the key that goes out — a capability confirmation is
2046
+ * bound to its idempotency key, so minting a fresh one here would invalidate
2047
+ * the confirmation. That the SDK now always sends a key is also what makes
2048
+ * the replay-without-secret case above reachable on a plain 5xx retry.
1494
2049
  */
1495
2050
  create(input: CreateWebhookInput, options?: RequestOptions): Promise<ApiResponse<WebhookEndpoint>>;
1496
2051
  /** Get a webhook endpoint by ID. */
@@ -1506,7 +2061,14 @@ declare class Webhooks {
1506
2061
  delete(id: string, options?: RequestOptions): Promise<ApiResponse<WebhookDeleteResult>>;
1507
2062
  /** List recent deliveries for an endpoint (most recent first). */
1508
2063
  deliveries(id: string, options?: ListDeliveriesOptions): Promise<ApiResponse<WebhookDelivery[]>>;
1509
- /** Queue a signed `test.ping` delivery to the endpoint. Returns HTTP 202. */
2064
+ /**
2065
+ * Queue a signed `test.ping` delivery to the endpoint. Returns HTTP 202.
2066
+ *
2067
+ * Deliberately unkeyed: a duplicate ping is the one duplicate that costs
2068
+ * nothing. Real deliveries are retried too, so any endpoint worth pointing at
2069
+ * already tolerates receiving the same event twice — that is what this call
2070
+ * exists to prove.
2071
+ */
1510
2072
  test(id: string): Promise<ApiResponse<WebhookTestResult>>;
1511
2073
  }
1512
2074
 
@@ -1813,6 +2375,13 @@ interface MedalOptions {
1813
2375
  * variables: { name: 'John' },
1814
2376
  * });
1815
2377
  *
2378
+ * // Bookings — free slots, then book a party (money is integer øre)
2379
+ * const { data: slots } = await medal.bookings.availability({
2380
+ * service_id: 'svc_1',
2381
+ * from_ts: Date.now(),
2382
+ * to_ts: Date.now() + 7 * 86_400_000,
2383
+ * });
2384
+ *
1816
2385
  * // Contacts, Deals, GDPR, Workspaces
1817
2386
  * const contacts = await medal.contacts.list({ status: 'lead' });
1818
2387
  * const { data: deal } = await medal.deals.create({ title: 'Acme', value: 50000 });
@@ -1821,6 +2390,7 @@ interface MedalOptions {
1821
2390
  * ```
1822
2391
  */
1823
2392
  declare class Medal {
2393
+ readonly bookings: Bookings;
1824
2394
  readonly capabilityConfirmations: CapabilityConfirmations;
1825
2395
  readonly channels: Channels;
1826
2396
  readonly emails: Emails;
@@ -1838,4 +2408,4 @@ declare class Medal {
1838
2408
  /** Convenience factory — equivalent to `new Medal(apiKey, options)`. */
1839
2409
  declare function createMedalClient(apiKey: string, options?: MedalOptions): Medal;
1840
2410
 
1841
- export { type Activity, type AddNoteInput, type ApiResponse, type AutoConfirmContext, type AutoConfirmOptions, BaseClient, type BatchSendInput, type BatchSendResult, type BatchSendSummary, CAPABILITY_IDS, CAPABILITY_ROUTES, type CapabilityConfirmation, CapabilityConfirmations, CapabilityConfirmer, type CapabilityId, type CapabilityPathParamValue, type CapabilityRoute, type CapabilityWriteBodies, type CapabilityWriteRequest, type Channel, type ChannelConnectedEvent, type ChannelConnection, type ChannelConnectionDisconnectResult, type ChannelConnectionState, type ChannelDisconnectReason, type ChannelDisconnectedEvent, Channels, type ConnectLink, type ConnectLinkCreateResult, type ConnectLinkRevokeResult, type ConnectLinkStatus, type ConsentRecord, type ConsentResult, type ConsentType, type Contact, type ContactConsents, type ContactCreateResult, type ContactNoteResult, type ContactRemoveResult, type ContactStatus, type ContactUpdateResult, Contacts, type Conversation, type ConversationAssignedEvent, type ConversationCreatedEvent, type ConversationMessage, type ConversationStatus, type ConversationStatusChangedEvent, type ConversationUpdateResult, type CookieCategoryConsent, type CookieConsentInput, type CreateConnectLinkInput, type CreateContactInput, type CreateDealInput, type CreatePostInput, type CreateReplyInput, type CreateWebhookInput, DEFAULT_WEBHOOK_TOLERANCE_MS, type Deal, type DealCreateResult, type DealRemoveResult, type DealStatus, type DealUpdateResult, Deals, type EmailSend, type EmailSendResult, type EmailStatus, type EmailTemplate, type EmailTemplateDetail, Emails, Gdpr, type GdprExport, type GetTemplateOptions, Helpdesk, type HelpdeskMessageType, type ImportContactInput, type ImportContactsResult, type IssueCapabilityConfirmationInput, type ListConnectLinksOptions, type ListContactsOptions, type ListConversationsOptions, type ListDealsOptions, type ListDeliveriesOptions, type ListPostsOptions, Medal, MedalApiError, type MedalOptions, type MessageAuthorType, type MessageDeliveryStatus, type MessageDeliveryUpdatedEvent, type MessageReceivedEvent, type MessageSentEvent, type PaginatedResponse, type PaginationOptions, type Post, type PostDetail, type PostType, type PostVariant, Posts, type PublishResult, type RecordConsentInput, type ReplyCreateResult, type RequestOptions, Scan, type ScanCompany, type ScanCreateInput, type ScanCreateResult, type ScanJob, type ScanResultPayload, type ScanStatus, type ScanSubScores, type SchedulePostInput, type ScheduleResult, type SendEmailInput, type TestPingEvent, type UpdateContactInput, type UpdateConversationInput, type UpdateDealInput, type UpdatePostInput, type UpdateWebhookInput, type VerifyWebhookSignatureInput, type WaitForScanOptions, type WebhookChannelLifecycleData, type WebhookConversationSnapshot, type WebhookDeleteResult, type WebhookDelivery, type WebhookEndpoint, type WebhookEvent, type WebhookMessageSnapshot, type WebhookTestResult, WebhookVerificationError, type WebhookVerificationErrorCode, Webhooks, type Workspace, Workspaces, createMedalClient, Medal as default, verifyWebhookSignature };
2411
+ export { type Activity, type AddNoteInput, type ApiResponse, type AutoConfirmContext, type AutoConfirmOptions, BaseClient, type BatchSendInput, type BatchSendResult, type BatchSendSummary, type Booking, type BookingActionResult, type BookingAvailabilityOptions, type BookingCancelledBy, type BookingClaimableCreatedVia, type BookingContactInput, type BookingCreateResult, type BookingCreatedVia, type BookingPaymentStatus, type BookingRescheduleResult, type BookingResource, type BookingResourceType, type BookingScheduleDay, type BookingScheduleOptions, type BookingService, type BookingSlot, type BookingStatus, type BookingTimestampInput, Bookings, type BookingsPage, type BookingsPagination, CAPABILITY_IDS, CAPABILITY_ROUTES, type CancelBookingInput, type CapabilityConfirmation, CapabilityConfirmations, CapabilityConfirmer, type CapabilityId, type CapabilityPathParamValue, type CapabilityRoute, type CapabilityWriteBodies, type CapabilityWriteRequest, type Channel, type ChannelConnectedEvent, type ChannelConnection, type ChannelConnectionDisconnectResult, type ChannelConnectionState, type ChannelDisconnectReason, type ChannelDisconnectedEvent, Channels, type ConnectLink, type ConnectLinkCreateResult, type ConnectLinkRevokeResult, type ConnectLinkStatus, type ConsentRecord, type ConsentResult, type ConsentType, type Contact, type ContactConsents, type ContactCreateResult, type ContactNoteResult, type ContactRemoveResult, type ContactStatus, type ContactUpdateResult, Contacts, type Conversation, type ConversationAssignedEvent, type ConversationCreatedEvent, type ConversationMessage, type ConversationStatus, type ConversationStatusChangedEvent, type ConversationUpdateResult, type CookieCategoryConsent, type CookieConsentInput, type CreateBookingInput, type CreateBookingItemInput, type CreateConnectLinkInput, type CreateContactInput, type CreateDealInput, type CreatePostInput, type CreateReplyInput, type CreateWebhookInput, type CreatedBooking, DEFAULT_WEBHOOK_TOLERANCE_MS, type Deal, type DealCreateResult, type DealRemoveResult, type DealStatus, type DealUpdateResult, Deals, type EmailSend, type EmailSendResult, type EmailStatus, type EmailTemplate, type EmailTemplateDetail, Emails, Gdpr, type GdprExport, type GetTemplateOptions, Helpdesk, type HelpdeskMessageType, type ImportContactInput, type ImportContactsResult, type IssueCapabilityConfirmationInput, type ListBookingServicesOptions, type ListBookingsOptions, type ListConnectLinksOptions, type ListContactsOptions, type ListConversationsOptions, type ListDealsOptions, type ListDeliveriesOptions, type ListPostsOptions, type ManageSummary, Medal, MedalApiError, type MedalOptions, type MessageAuthorType, type MessageDeliveryStatus, type MessageDeliveryUpdatedEvent, type MessageReceivedEvent, type MessageSentEvent, type PaginatedResponse, type PaginationOptions, type Post, type PostDetail, type PostType, type PostVariant, Posts, type PublishResult, type RecordConsentInput, type ReplyCreateResult, type RequestOptions, type RescheduleBookingInput, Scan, type ScanCompany, type ScanCreateInput, type ScanCreateResult, type ScanJob, type ScanResultPayload, type ScanStatus, type ScanSubScores, type SchedulePostInput, type ScheduleResult, type SendEmailInput, type TestPingEvent, type UpdateBookingInput, type UpdateContactInput, type UpdateConversationInput, type UpdateDealInput, type UpdatePostInput, type UpdateWebhookInput, type VerifyWebhookSignatureInput, type WaitForScanOptions, type WebhookChannelLifecycleData, type WebhookConversationSnapshot, type WebhookDeleteResult, type WebhookDelivery, type WebhookEndpoint, type WebhookEvent, type WebhookMessageSnapshot, type WebhookTestResult, WebhookVerificationError, type WebhookVerificationErrorCode, Webhooks, type Workspace, Workspaces, createMedalClient, Medal as default, verifyWebhookSignature };