@itm-studio/partner-sdk 0.4.1 → 0.5.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.
package/README.md CHANGED
@@ -2177,14 +2177,19 @@ There are two ways to run it:
2177
2177
  | How it runs | Browser redirect to ITM, then a standard authorization-code exchange | `startPartnerAppLogin` and `verifyPartnerAppLogin`, from your server |
2178
2178
  | What you receive | An ID token and an access token issued by ITM (1 hour, no refresh) | `customerUid` and a profile. **No token**: you keep your own session |
2179
2179
  | Partner key used | Only to register the app | On every call |
2180
- | Marketing opt-in | Not offered. Use `createPartnerBrandSubscription` separately | One optional checkbox, recorded with the sign-in |
2180
+ | Marketing opt-in | One optional checkbox on ITM's code and "Continue" screens | One optional checkbox, recorded with the sign-in |
2181
2181
  | Person identifier | The ID token's `sub` claim (equal to the customer UID) | `customerUid` |
2182
2182
 
2183
2183
  Use the hosted sign-in unless you need the form inside your own UI. Both start with an app.
2184
2184
 
2185
2185
  ### Register an app
2186
2186
 
2187
- An app is a public OpenID Connect client for one of your sites. Register it once, from your server:
2187
+ An app is an OpenID Connect client for one of your sites. There are two kinds:
2188
+
2189
+ - **Browser app:** a public client with no secret. `createPartnerBrandApp` registers this kind, and it is all the custom sign-in form needs.
2190
+ - **Server website:** a confidential client whose server keeps a client secret, so tokens never reach the browser. Create it in Backstage under **Manage › Advanced settings › Login with ITM**. Backstage shows the client secret once and can rotate it.
2191
+
2192
+ Register a Browser app once, from your server:
2188
2193
 
2189
2194
  ```typescript
2190
2195
  const { createPartnerBrandApp: app } = await itm.mutation({
@@ -2220,14 +2225,14 @@ Hosted sign-in is standard OpenID Connect, so you do not need this SDK for it, a
2220
2225
 
2221
2226
  - **Discovery:** `${issuer}/.well-known/openid-configuration`. Read the endpoints from it rather than hard-coding paths.
2222
2227
  - **Flow:** authorization code with PKCE. `response_type=code` and `code_challenge_method=S256` are the only values accepted, and PKCE is required.
2223
- - **Client authentication:** none. The app is a public client (`token_endpoint_auth_method: none`) with no secret.
2228
+ - **Client authentication:** a Browser app is a public client with no secret (`token_endpoint_auth_method: none`). A Server website app authenticates with its client secret using `client_secret_basic`.
2224
2229
  - **Scopes:** `openid profile email phone`. Every app gets this fixed set.
2225
2230
  - **ID token:** verify it against the issuer's `jwks_uri`, with `aud` equal to your client ID and the `nonce` you sent. Its `sub` is pairwise: it equals the person's customer UID for your brand.
2226
2231
  - **Profile claims:** read them from the userinfo endpoint with the access token. It returns `name`, `email`, `email_verified`, `phone_number` and `phone_number_verified`, and leaves out any the person does not have. The access token is opaque.
2227
2232
  - **Lifetimes:** authorization codes last 60 seconds; access and ID tokens last 1 hour. There are no refresh tokens (`offline_access` is not supported). When you need new tokens, send the person through the flow again. While their ITM session on the issuer lasts (up to 30 days), a person who already approved your app comes straight back without a prompt.
2228
2233
  - **Revocation** is available. There is no logout endpoint: end your own session.
2229
2234
 
2230
- The person sees your brand's name and logo, gets a code by SMS or email, and approves sharing their name, email address and phone number the first time. They become a contact and are **not** subscribed to marketing.
2235
+ The person sees your brand's name and logo, gets a code by SMS or email, and approves sharing their name, email address and phone number the first time. They become a contact. They are subscribed to your brand's marketing only if they tick the optional, unticked checkbox on ITM's page.
2231
2236
 
2232
2237
  Run the token exchange on your server and keep tokens out of the browser, following the Backend for Frontend pattern ([RFC 10017 §6.1](https://www.rfc-editor.org/rfc/rfc10017.html)). Prefer an OpenID Connect client library that performs the protocol validation. This framework-neutral sketch with `fetch` and [`jose`](https://github.com/panva/jose) shows the main steps; `rotateSession()` represents your framework's session regeneration API and must invalidate the old session ID and return the new session.
2233
2238
 
@@ -2313,6 +2318,8 @@ const authenticatedSession = await rotateSession();
2313
2318
  authenticatedSession.customerUid = payload.sub;
2314
2319
  ```
2315
2320
 
2321
+ The sketch uses a Browser app. With a Server website app, also authenticate the token request with `client_secret_basic` (an `authorization: Basic …` header built from the client ID and client secret) and keep the secret on your server. For a complete server example using `openid-client`, see [`examples/login-with-itm`](https://github.com/itm-studio/demo-events-sdk-integration/tree/main/examples/login-with-itm).
2322
+
2316
2323
  A redirect that comes back with `error=access_denied` means the person cancelled.
2317
2324
  Never use UserInfo claims until its `sub` matches the validated ID token's `sub` ([OpenID Connect Core §5.3.2](https://openid.net/specs/openid-connect-core-1_0.html#UserInfoResponse)). Persist the pending login before redirecting, expire it after a short interval, and consume it once on callback using your session store's concurrency controls.
2318
2325
 
@@ -2461,7 +2468,7 @@ When the visitor ticks the checkbox from step 2 and you send `marketingConsent:
2461
2468
  - Each opt-in is recorded as new evidence, including repeat opt-ins. Leaving the box unticked records nothing and never unsubscribes anyone.
2462
2469
  - People your brand has blacklisted can still sign in, but an opt-in never subscribes them.
2463
2470
 
2464
- Hosted sign-in does not offer an opt-in. To subscribe someone outside the custom sign-in form, collect consent on your own page and call `createPartnerBrandSubscription`; see the [Partner Brand Subscription Guide](#partner-brand-subscription-guide).
2471
+ Hosted sign-in offers the same optional checkbox on ITM's code and "Continue to {Brand}" screens, and ITM records a ticked box as an opt-in. To subscribe someone outside sign-in, collect consent on your own page and call `createPartnerBrandSubscription`; see the [Partner Brand Subscription Guide](#partner-brand-subscription-guide).
2465
2472
 
2466
2473
  ### What ITM handles
2467
2474
 
@@ -2511,7 +2518,7 @@ For staging or local development:
2511
2518
  ```typescript
2512
2519
  const itm = createITMPartnerClient({
2513
2520
  token: process.env.ITM_PARTNER_TOKEN!,
2514
- baseUrl: "https://staging-api.itm.studio/graphql",
2521
+ baseUrl: "https://staging.itm-api.com/graphql",
2515
2522
  });
2516
2523
  ```
2517
2524
 
@@ -2706,3 +2713,22 @@ receipt eligibility. Omit it for no receipt. `userUid` is populated when entered
2706
2713
  email or phone matches a current verified ITM identity; unmatched contacts do not
2707
2714
  create an account, and conflicting matches are rejected. `source` distinguishes
2708
2715
  `STRIPE`, `OFF_SITE`, and in-person `POS` independently of payment status.
2716
+
2717
+ ### Delegated integration credentials (MCP)
2718
+
2719
+ The integration authentication mode accepts a backend-issued, short-lived **API** credential. It sends `x-itm-integration-access-token`; external MCP access tokens cannot authenticate to the business API.
2720
+
2721
+ ```ts
2722
+ const client = createITMPartnerClient({
2723
+ baseUrl: process.env.ITM_PARTNER_API_ORIGIN,
2724
+ integration: { accessToken: async () => requestScopedApiCredential },
2725
+ signal: request.signal,
2726
+ });
2727
+ const { getPartnerBrand } = await client.query({
2728
+ getPartnerBrand: { uid: true, name: true, slug: true, publicUrl: true },
2729
+ });
2730
+ ```
2731
+
2732
+ Provide exactly one of `token`, `agentSession`, `agentAccess`, or `integration`. Extra headers cannot override credential headers, regardless of casing. Create a client per inbound request; asynchronous token getters run per API request. `signal` cancels requests in every authentication mode. `ITMPartnerTransportError` exposes the HTTP status without copying a possibly sensitive response body; GraphQL failures remain `GenqlError`.
2733
+
2734
+ This SDK does not log in operators, choose brands, retain OAuth refresh tokens, or decide permissions. The MCP caller handles OAuth and supplies the delegated API credential.
package/dist/index.d.mts CHANGED
@@ -3621,6 +3621,8 @@ interface ITMPartnerTokenConfig {
3621
3621
  * @default DEFAULT_API_URL
3622
3622
  */
3623
3623
  baseUrl?: string;
3624
+ /** Cancellation for this request-scoped client. */
3625
+ signal?: AbortSignal;
3624
3626
  /**
3625
3627
  * Additional headers to include on every request.
3626
3628
  * A function is useful for request-scoped values like `x-forwarded-for`
@@ -3659,6 +3661,8 @@ interface ITMPartnerAgentSessionConfig {
3659
3661
  * @default DEFAULT_API_URL
3660
3662
  */
3661
3663
  baseUrl?: string;
3664
+ /** Cancellation for this request-scoped client. */
3665
+ signal?: AbortSignal;
3662
3666
  /**
3663
3667
  * Additional headers to include on every request. Credential headers
3664
3668
  * always take precedence and cannot be overridden.
@@ -3692,13 +3696,25 @@ interface ITMPartnerAgentAccessConfig {
3692
3696
  * @default DEFAULT_API_URL
3693
3697
  */
3694
3698
  baseUrl?: string;
3699
+ /** Cancellation for this request-scoped client. */
3700
+ signal?: AbortSignal;
3695
3701
  /**
3696
3702
  * Additional headers to include on every request. Credential headers
3697
3703
  * always take precedence and cannot be overridden.
3698
3704
  */
3699
3705
  headers?: ITMPartnerHeaders;
3700
3706
  }
3701
- type ITMPartnerClientConfig = ITMPartnerTokenConfig | ITMPartnerAgentSessionConfig | ITMPartnerAgentAccessConfig;
3707
+ interface ITMPartnerIntegrationCredentials {
3708
+ /** Short-lived API credential supplied by the caller, resolved afresh per request. */
3709
+ accessToken: string | (() => MaybePromise<string>);
3710
+ }
3711
+ interface ITMPartnerIntegrationConfig {
3712
+ integration: ITMPartnerIntegrationCredentials;
3713
+ baseUrl?: string;
3714
+ headers?: ITMPartnerHeaders;
3715
+ signal?: AbortSignal;
3716
+ }
3717
+ type ITMPartnerClientConfig = ITMPartnerIntegrationConfig | ITMPartnerTokenConfig | ITMPartnerAgentSessionConfig | ITMPartnerAgentAccessConfig;
3702
3718
  type ITMPartnerClient = Client;
3703
3719
  /**
3704
3720
  * Create a typed ITM Partner API client.
@@ -3730,5 +3746,12 @@ type ITMPartnerClient = Client;
3730
3746
  * ```
3731
3747
  */
3732
3748
  declare function createITMPartnerClient(config: ITMPartnerClientConfig): ITMPartnerClient;
3749
+ /** HTTP errors retain status without copying response bodies or credentials. */
3750
+ declare class ITMPartnerTransportError extends Error {
3751
+ readonly status: number | undefined;
3752
+ readonly requestId?: string | undefined;
3753
+ readonly name = "ITMPartnerTransportError";
3754
+ constructor(status: number | undefined, requestId?: string | undefined);
3755
+ }
3733
3756
 
3734
- export { type AgentThreadSeedContext, type ApplyDynamicPricingInput, type BrandAgentEmailMessageInput, type BrandAgentEmailSendBatch, type BrandAgentEmailSendBatchStatus, type BrandAgentEmailSendMessage, type BrandAgentEmailSendMessageStatus, type BrandApp, type BrandAppStatus, type BrandDrop, type BrandDropCtaType, type BrandDropMusicLink, type BrandSubscription, type CheckoutMarketingConsentInput, type CheckoutMarketingConsentPrompt, type ConsentChannel, type ConsentPromptCategory, type ConsentStatus, type ContributionAdmin, type ContributionPageAdmin, type ContributionPageStatusFilter, type ContributionPagesResponse, type ContributionSource, type ContributionStatus, type ContributionsResponse, type CreateBrandAppInput, type CreateManualContributionInput, type CreateMomentOnlineConfigInput, type CreatePartnerBrandDropInput, type CreatePartnerBrandSubscriptionInput, type CreatePartnerBrandSubscriptionResponse, type CreatePartnerMomentInput, type CreatePartnerTicketTierInput, type CreatePlanBudgetInput, type CreatePlanInput, type Currency, DEFAULT_API_URL, type Dimensions, type DimensionsInput, type DynamicPricingActorType, type DynamicPricingAdmissionWindow, type DynamicPricingBatch, type DynamicPricingBatchEvent, type DynamicPricingBatchEventType, type DynamicPricingBatchItem, type DynamicPricingBatchItemStatus, type DynamicPricingBatchStatus, type DynamicPricingContext, type DynamicPricingExecutionMode, type DynamicPricingInventoryGuardInput, type DynamicPricingInventoryGuardMode, type DynamicPricingInventoryMetric, type DynamicPricingMomentInput, type DynamicPricingTierContext, type DynamicPricingTierUpdateInput, type Echo, type EchoMediaAsset, type EchoType, type EditPartnerTicketTiersForMomentInput, type EventImportPlatform, GenqlError, type GetBrandEchoesForUserResponse, type GetMomentLineupsResponse, type GetMomentTagAssignmentsResponse, type GetPartnerAudienceInput, type GetPartnerAudienceResponse, type GetPartnerCustomersResponse, type GetPartnerDropsResponse, type GetPartnerMediaAssetsInput, type GetPartnerMediaAssetsResponse, type GetPartnerMembersInput, type GetPartnerMembersResponse, type GetPartnerMembershipTiersInput, type GetPartnerMembershipTiersResponse, type GetPartnerTicketTiersForMomentInput, type GetPartnerTicketTiersForMomentResponse, type GetPlansInput, type GetPlansResponse, type GetPublicMomentsResponse, type GetTicketsResponse, type ITMPartnerAgentAccessConfig, type ITMPartnerAgentAccessCredentials, type ITMPartnerAgentSessionConfig, type ITMPartnerAgentSessionCredentials, type ITMPartnerClient, type ITMPartnerClientConfig, type ITMPartnerHeaders, type ITMPartnerHeadersObject, type ITMPartnerTokenConfig, type LoginCodeChannel, type ManualContributionReceiptType, type MediaAsset, type MediaAssetUploadUrl, type MembershipBillingInterval, type MembershipExpiryType, type MembershipPassType, type MembershipPurchaseType, type MembershipSource, type MembershipStatus, type MerchPurchase, type Moment, type MomentCategory, type MomentCollection, type MomentCollectionLink, type MomentDiscountCodeUsage, type MomentDynamicPricingPolicy, type MomentDynamicPricingTierRule, type MomentLineup, type MomentLineupDisplayLabel, type MomentLineupResponseResult, type MomentLineupStatus, type MomentLineupType, type MomentOccurrenceScheduleFrequency, type MomentOnlineProvider, type MomentPublicVenuePreview, type MomentSortOrder, type MomentStatus, type MomentSubcategory, type MomentTagAssignment, type MomentType, type MusicReleaseType, type Mutation, type PaginationInput, type PartnerAppLogin, type PartnerAppLoginChallenge, type PartnerAppLoginProfile, type PartnerAudienceCustomer, type PartnerAudienceFiltersInput, type PartnerAudienceSortField, type PartnerAudienceSortInput, type PartnerBrand, type PartnerCustomer, type PartnerMember, type PartnerMemberCustomer, type PartnerMemberTier, type PartnerMembershipTier, type PartnerMomentAttendanceCount, type PartnerMomentAttendanceLookupInput, type PartnerMomentAttendanceStats, type PartnerMomentGuestlistAttendance, type PartnerMomentGuestlistLabelAttendance, type PartnerMomentStats, type PartnerMomentTicketAttendance, type PartnerMomentTicketTierAttendance, type PartnerMomentsFiltersInput, type PartnerTicketStatus, type PartnerTicketTier, type PartnerTicketTierUpdateInput, type PartnerTicketUserLookupInput, type PartnerTicketsForUserInput, type Payment, type PaymentStatus, type Plan, type PlanBudget, type PlanBudgetAllocationType, type PlanBudgetArtistDealBasis, type PlanBudgetArtistDealInput, type PlanBudgetArtistDealType, type PlanBudgetCapacityAllocationInput, type PlanBudgetCategoryInput, type PlanBudgetCategoryKind, type PlanBudgetChargeCalculation, type PlanBudgetChargeKind, type PlanBudgetChargeTreatment, type PlanBudgetExternalTicketingChannelInput, type PlanBudgetFeeAssessment, type PlanBudgetFeeComponentKind, type PlanBudgetFeePercentageBasis, type PlanBudgetGuaranteeBasis, type PlanBudgetLineBasis, type PlanBudgetLineInput, type PlanBudgetPaymentStatus, type PlanBudgetPricingMode, type PlanBudgetSummary, type PlanBudgetTicketChargeRuleInput, type PlanBudgetTicketTierInput, type PlanBudgetTicketingChannelType, type PlanBudgetTicketingFeeComponentInput, type PlanKind, type PlanLinkMetadataStatus, type PlanMoodboard, type PlanMoodboardItem, type PlanMoodboardItemType, type PlanSchedule, type PlanScheduleInput, type PlanScheduleTime, type PlanScheduleTimeInput, type PlanScheduleType, type PlanStatus, type PlanSummary, type PlanningProposal, type PlanningSource, type PlanningSourceDispositionInput, type PlanningSourceSection, type PostSubscriptionEmailInput, type PostSubscriptionMessageInput, type PostSubscriptionPushInput, type PostSubscriptionSmsInput, type PreparePlanningProposalInput, type PublicMomentLineupInfo, type Query, type ReplacePlanBudgetDraftInput, type RespondToMomentLineupInput, type SendPartnerAgentEmailInput, type SortDirection, type StartPartnerAppLoginInput, type SubscriptionComplianceInput, type Tag, type TagSource, type ThirdPartyEchoType, type Ticket, type TicketAdmissionWindowSource, type TicketAttendanceMode, type TicketExtension, type TicketExtensionStatus, type TicketTier, type Transforms, type UpdatePlanInput, type User, type UserSource, type Venue, type VenueInput, type VerifyPartnerAppLoginInput, type VerifyPartnerBrandSubscriptionInput, createITMPartnerClient, everything, generateMutationOp, generateQueryOp };
3757
+ export { type AgentThreadSeedContext, type ApplyDynamicPricingInput, type BrandAgentEmailMessageInput, type BrandAgentEmailSendBatch, type BrandAgentEmailSendBatchStatus, type BrandAgentEmailSendMessage, type BrandAgentEmailSendMessageStatus, type BrandApp, type BrandAppStatus, type BrandDrop, type BrandDropCtaType, type BrandDropMusicLink, type BrandSubscription, type CheckoutMarketingConsentInput, type CheckoutMarketingConsentPrompt, type ConsentChannel, type ConsentPromptCategory, type ConsentStatus, type ContributionAdmin, type ContributionPageAdmin, type ContributionPageStatusFilter, type ContributionPagesResponse, type ContributionSource, type ContributionStatus, type ContributionsResponse, type CreateBrandAppInput, type CreateManualContributionInput, type CreateMomentOnlineConfigInput, type CreatePartnerBrandDropInput, type CreatePartnerBrandSubscriptionInput, type CreatePartnerBrandSubscriptionResponse, type CreatePartnerMomentInput, type CreatePartnerTicketTierInput, type CreatePlanBudgetInput, type CreatePlanInput, type Currency, DEFAULT_API_URL, type Dimensions, type DimensionsInput, type DynamicPricingActorType, type DynamicPricingAdmissionWindow, type DynamicPricingBatch, type DynamicPricingBatchEvent, type DynamicPricingBatchEventType, type DynamicPricingBatchItem, type DynamicPricingBatchItemStatus, type DynamicPricingBatchStatus, type DynamicPricingContext, type DynamicPricingExecutionMode, type DynamicPricingInventoryGuardInput, type DynamicPricingInventoryGuardMode, type DynamicPricingInventoryMetric, type DynamicPricingMomentInput, type DynamicPricingTierContext, type DynamicPricingTierUpdateInput, type Echo, type EchoMediaAsset, type EchoType, type EditPartnerTicketTiersForMomentInput, type EventImportPlatform, GenqlError, type GetBrandEchoesForUserResponse, type GetMomentLineupsResponse, type GetMomentTagAssignmentsResponse, type GetPartnerAudienceInput, type GetPartnerAudienceResponse, type GetPartnerCustomersResponse, type GetPartnerDropsResponse, type GetPartnerMediaAssetsInput, type GetPartnerMediaAssetsResponse, type GetPartnerMembersInput, type GetPartnerMembersResponse, type GetPartnerMembershipTiersInput, type GetPartnerMembershipTiersResponse, type GetPartnerTicketTiersForMomentInput, type GetPartnerTicketTiersForMomentResponse, type GetPlansInput, type GetPlansResponse, type GetPublicMomentsResponse, type GetTicketsResponse, type ITMPartnerAgentAccessConfig, type ITMPartnerAgentAccessCredentials, type ITMPartnerAgentSessionConfig, type ITMPartnerAgentSessionCredentials, type ITMPartnerClient, type ITMPartnerClientConfig, type ITMPartnerHeaders, type ITMPartnerHeadersObject, type ITMPartnerIntegrationConfig, type ITMPartnerIntegrationCredentials, type ITMPartnerTokenConfig, ITMPartnerTransportError, type LoginCodeChannel, type ManualContributionReceiptType, type MediaAsset, type MediaAssetUploadUrl, type MembershipBillingInterval, type MembershipExpiryType, type MembershipPassType, type MembershipPurchaseType, type MembershipSource, type MembershipStatus, type MerchPurchase, type Moment, type MomentCategory, type MomentCollection, type MomentCollectionLink, type MomentDiscountCodeUsage, type MomentDynamicPricingPolicy, type MomentDynamicPricingTierRule, type MomentLineup, type MomentLineupDisplayLabel, type MomentLineupResponseResult, type MomentLineupStatus, type MomentLineupType, type MomentOccurrenceScheduleFrequency, type MomentOnlineProvider, type MomentPublicVenuePreview, type MomentSortOrder, type MomentStatus, type MomentSubcategory, type MomentTagAssignment, type MomentType, type MusicReleaseType, type Mutation, type PaginationInput, type PartnerAppLogin, type PartnerAppLoginChallenge, type PartnerAppLoginProfile, type PartnerAudienceCustomer, type PartnerAudienceFiltersInput, type PartnerAudienceSortField, type PartnerAudienceSortInput, type PartnerBrand, type PartnerCustomer, type PartnerMember, type PartnerMemberCustomer, type PartnerMemberTier, type PartnerMembershipTier, type PartnerMomentAttendanceCount, type PartnerMomentAttendanceLookupInput, type PartnerMomentAttendanceStats, type PartnerMomentGuestlistAttendance, type PartnerMomentGuestlistLabelAttendance, type PartnerMomentStats, type PartnerMomentTicketAttendance, type PartnerMomentTicketTierAttendance, type PartnerMomentsFiltersInput, type PartnerTicketStatus, type PartnerTicketTier, type PartnerTicketTierUpdateInput, type PartnerTicketUserLookupInput, type PartnerTicketsForUserInput, type Payment, type PaymentStatus, type Plan, type PlanBudget, type PlanBudgetAllocationType, type PlanBudgetArtistDealBasis, type PlanBudgetArtistDealInput, type PlanBudgetArtistDealType, type PlanBudgetCapacityAllocationInput, type PlanBudgetCategoryInput, type PlanBudgetCategoryKind, type PlanBudgetChargeCalculation, type PlanBudgetChargeKind, type PlanBudgetChargeTreatment, type PlanBudgetExternalTicketingChannelInput, type PlanBudgetFeeAssessment, type PlanBudgetFeeComponentKind, type PlanBudgetFeePercentageBasis, type PlanBudgetGuaranteeBasis, type PlanBudgetLineBasis, type PlanBudgetLineInput, type PlanBudgetPaymentStatus, type PlanBudgetPricingMode, type PlanBudgetSummary, type PlanBudgetTicketChargeRuleInput, type PlanBudgetTicketTierInput, type PlanBudgetTicketingChannelType, type PlanBudgetTicketingFeeComponentInput, type PlanKind, type PlanLinkMetadataStatus, type PlanMoodboard, type PlanMoodboardItem, type PlanMoodboardItemType, type PlanSchedule, type PlanScheduleInput, type PlanScheduleTime, type PlanScheduleTimeInput, type PlanScheduleType, type PlanStatus, type PlanSummary, type PlanningProposal, type PlanningSource, type PlanningSourceDispositionInput, type PlanningSourceSection, type PostSubscriptionEmailInput, type PostSubscriptionMessageInput, type PostSubscriptionPushInput, type PostSubscriptionSmsInput, type PreparePlanningProposalInput, type PublicMomentLineupInfo, type Query, type ReplacePlanBudgetDraftInput, type RespondToMomentLineupInput, type SendPartnerAgentEmailInput, type SortDirection, type StartPartnerAppLoginInput, type SubscriptionComplianceInput, type Tag, type TagSource, type ThirdPartyEchoType, type Ticket, type TicketAdmissionWindowSource, type TicketAttendanceMode, type TicketExtension, type TicketExtensionStatus, type TicketTier, type Transforms, type UpdatePlanInput, type User, type UserSource, type Venue, type VenueInput, type VerifyPartnerAppLoginInput, type VerifyPartnerBrandSubscriptionInput, createITMPartnerClient, everything, generateMutationOp, generateQueryOp };
package/dist/index.d.ts CHANGED
@@ -3621,6 +3621,8 @@ interface ITMPartnerTokenConfig {
3621
3621
  * @default DEFAULT_API_URL
3622
3622
  */
3623
3623
  baseUrl?: string;
3624
+ /** Cancellation for this request-scoped client. */
3625
+ signal?: AbortSignal;
3624
3626
  /**
3625
3627
  * Additional headers to include on every request.
3626
3628
  * A function is useful for request-scoped values like `x-forwarded-for`
@@ -3659,6 +3661,8 @@ interface ITMPartnerAgentSessionConfig {
3659
3661
  * @default DEFAULT_API_URL
3660
3662
  */
3661
3663
  baseUrl?: string;
3664
+ /** Cancellation for this request-scoped client. */
3665
+ signal?: AbortSignal;
3662
3666
  /**
3663
3667
  * Additional headers to include on every request. Credential headers
3664
3668
  * always take precedence and cannot be overridden.
@@ -3692,13 +3696,25 @@ interface ITMPartnerAgentAccessConfig {
3692
3696
  * @default DEFAULT_API_URL
3693
3697
  */
3694
3698
  baseUrl?: string;
3699
+ /** Cancellation for this request-scoped client. */
3700
+ signal?: AbortSignal;
3695
3701
  /**
3696
3702
  * Additional headers to include on every request. Credential headers
3697
3703
  * always take precedence and cannot be overridden.
3698
3704
  */
3699
3705
  headers?: ITMPartnerHeaders;
3700
3706
  }
3701
- type ITMPartnerClientConfig = ITMPartnerTokenConfig | ITMPartnerAgentSessionConfig | ITMPartnerAgentAccessConfig;
3707
+ interface ITMPartnerIntegrationCredentials {
3708
+ /** Short-lived API credential supplied by the caller, resolved afresh per request. */
3709
+ accessToken: string | (() => MaybePromise<string>);
3710
+ }
3711
+ interface ITMPartnerIntegrationConfig {
3712
+ integration: ITMPartnerIntegrationCredentials;
3713
+ baseUrl?: string;
3714
+ headers?: ITMPartnerHeaders;
3715
+ signal?: AbortSignal;
3716
+ }
3717
+ type ITMPartnerClientConfig = ITMPartnerIntegrationConfig | ITMPartnerTokenConfig | ITMPartnerAgentSessionConfig | ITMPartnerAgentAccessConfig;
3702
3718
  type ITMPartnerClient = Client;
3703
3719
  /**
3704
3720
  * Create a typed ITM Partner API client.
@@ -3730,5 +3746,12 @@ type ITMPartnerClient = Client;
3730
3746
  * ```
3731
3747
  */
3732
3748
  declare function createITMPartnerClient(config: ITMPartnerClientConfig): ITMPartnerClient;
3749
+ /** HTTP errors retain status without copying response bodies or credentials. */
3750
+ declare class ITMPartnerTransportError extends Error {
3751
+ readonly status: number | undefined;
3752
+ readonly requestId?: string | undefined;
3753
+ readonly name = "ITMPartnerTransportError";
3754
+ constructor(status: number | undefined, requestId?: string | undefined);
3755
+ }
3733
3756
 
3734
- export { type AgentThreadSeedContext, type ApplyDynamicPricingInput, type BrandAgentEmailMessageInput, type BrandAgentEmailSendBatch, type BrandAgentEmailSendBatchStatus, type BrandAgentEmailSendMessage, type BrandAgentEmailSendMessageStatus, type BrandApp, type BrandAppStatus, type BrandDrop, type BrandDropCtaType, type BrandDropMusicLink, type BrandSubscription, type CheckoutMarketingConsentInput, type CheckoutMarketingConsentPrompt, type ConsentChannel, type ConsentPromptCategory, type ConsentStatus, type ContributionAdmin, type ContributionPageAdmin, type ContributionPageStatusFilter, type ContributionPagesResponse, type ContributionSource, type ContributionStatus, type ContributionsResponse, type CreateBrandAppInput, type CreateManualContributionInput, type CreateMomentOnlineConfigInput, type CreatePartnerBrandDropInput, type CreatePartnerBrandSubscriptionInput, type CreatePartnerBrandSubscriptionResponse, type CreatePartnerMomentInput, type CreatePartnerTicketTierInput, type CreatePlanBudgetInput, type CreatePlanInput, type Currency, DEFAULT_API_URL, type Dimensions, type DimensionsInput, type DynamicPricingActorType, type DynamicPricingAdmissionWindow, type DynamicPricingBatch, type DynamicPricingBatchEvent, type DynamicPricingBatchEventType, type DynamicPricingBatchItem, type DynamicPricingBatchItemStatus, type DynamicPricingBatchStatus, type DynamicPricingContext, type DynamicPricingExecutionMode, type DynamicPricingInventoryGuardInput, type DynamicPricingInventoryGuardMode, type DynamicPricingInventoryMetric, type DynamicPricingMomentInput, type DynamicPricingTierContext, type DynamicPricingTierUpdateInput, type Echo, type EchoMediaAsset, type EchoType, type EditPartnerTicketTiersForMomentInput, type EventImportPlatform, GenqlError, type GetBrandEchoesForUserResponse, type GetMomentLineupsResponse, type GetMomentTagAssignmentsResponse, type GetPartnerAudienceInput, type GetPartnerAudienceResponse, type GetPartnerCustomersResponse, type GetPartnerDropsResponse, type GetPartnerMediaAssetsInput, type GetPartnerMediaAssetsResponse, type GetPartnerMembersInput, type GetPartnerMembersResponse, type GetPartnerMembershipTiersInput, type GetPartnerMembershipTiersResponse, type GetPartnerTicketTiersForMomentInput, type GetPartnerTicketTiersForMomentResponse, type GetPlansInput, type GetPlansResponse, type GetPublicMomentsResponse, type GetTicketsResponse, type ITMPartnerAgentAccessConfig, type ITMPartnerAgentAccessCredentials, type ITMPartnerAgentSessionConfig, type ITMPartnerAgentSessionCredentials, type ITMPartnerClient, type ITMPartnerClientConfig, type ITMPartnerHeaders, type ITMPartnerHeadersObject, type ITMPartnerTokenConfig, type LoginCodeChannel, type ManualContributionReceiptType, type MediaAsset, type MediaAssetUploadUrl, type MembershipBillingInterval, type MembershipExpiryType, type MembershipPassType, type MembershipPurchaseType, type MembershipSource, type MembershipStatus, type MerchPurchase, type Moment, type MomentCategory, type MomentCollection, type MomentCollectionLink, type MomentDiscountCodeUsage, type MomentDynamicPricingPolicy, type MomentDynamicPricingTierRule, type MomentLineup, type MomentLineupDisplayLabel, type MomentLineupResponseResult, type MomentLineupStatus, type MomentLineupType, type MomentOccurrenceScheduleFrequency, type MomentOnlineProvider, type MomentPublicVenuePreview, type MomentSortOrder, type MomentStatus, type MomentSubcategory, type MomentTagAssignment, type MomentType, type MusicReleaseType, type Mutation, type PaginationInput, type PartnerAppLogin, type PartnerAppLoginChallenge, type PartnerAppLoginProfile, type PartnerAudienceCustomer, type PartnerAudienceFiltersInput, type PartnerAudienceSortField, type PartnerAudienceSortInput, type PartnerBrand, type PartnerCustomer, type PartnerMember, type PartnerMemberCustomer, type PartnerMemberTier, type PartnerMembershipTier, type PartnerMomentAttendanceCount, type PartnerMomentAttendanceLookupInput, type PartnerMomentAttendanceStats, type PartnerMomentGuestlistAttendance, type PartnerMomentGuestlistLabelAttendance, type PartnerMomentStats, type PartnerMomentTicketAttendance, type PartnerMomentTicketTierAttendance, type PartnerMomentsFiltersInput, type PartnerTicketStatus, type PartnerTicketTier, type PartnerTicketTierUpdateInput, type PartnerTicketUserLookupInput, type PartnerTicketsForUserInput, type Payment, type PaymentStatus, type Plan, type PlanBudget, type PlanBudgetAllocationType, type PlanBudgetArtistDealBasis, type PlanBudgetArtistDealInput, type PlanBudgetArtistDealType, type PlanBudgetCapacityAllocationInput, type PlanBudgetCategoryInput, type PlanBudgetCategoryKind, type PlanBudgetChargeCalculation, type PlanBudgetChargeKind, type PlanBudgetChargeTreatment, type PlanBudgetExternalTicketingChannelInput, type PlanBudgetFeeAssessment, type PlanBudgetFeeComponentKind, type PlanBudgetFeePercentageBasis, type PlanBudgetGuaranteeBasis, type PlanBudgetLineBasis, type PlanBudgetLineInput, type PlanBudgetPaymentStatus, type PlanBudgetPricingMode, type PlanBudgetSummary, type PlanBudgetTicketChargeRuleInput, type PlanBudgetTicketTierInput, type PlanBudgetTicketingChannelType, type PlanBudgetTicketingFeeComponentInput, type PlanKind, type PlanLinkMetadataStatus, type PlanMoodboard, type PlanMoodboardItem, type PlanMoodboardItemType, type PlanSchedule, type PlanScheduleInput, type PlanScheduleTime, type PlanScheduleTimeInput, type PlanScheduleType, type PlanStatus, type PlanSummary, type PlanningProposal, type PlanningSource, type PlanningSourceDispositionInput, type PlanningSourceSection, type PostSubscriptionEmailInput, type PostSubscriptionMessageInput, type PostSubscriptionPushInput, type PostSubscriptionSmsInput, type PreparePlanningProposalInput, type PublicMomentLineupInfo, type Query, type ReplacePlanBudgetDraftInput, type RespondToMomentLineupInput, type SendPartnerAgentEmailInput, type SortDirection, type StartPartnerAppLoginInput, type SubscriptionComplianceInput, type Tag, type TagSource, type ThirdPartyEchoType, type Ticket, type TicketAdmissionWindowSource, type TicketAttendanceMode, type TicketExtension, type TicketExtensionStatus, type TicketTier, type Transforms, type UpdatePlanInput, type User, type UserSource, type Venue, type VenueInput, type VerifyPartnerAppLoginInput, type VerifyPartnerBrandSubscriptionInput, createITMPartnerClient, everything, generateMutationOp, generateQueryOp };
3757
+ export { type AgentThreadSeedContext, type ApplyDynamicPricingInput, type BrandAgentEmailMessageInput, type BrandAgentEmailSendBatch, type BrandAgentEmailSendBatchStatus, type BrandAgentEmailSendMessage, type BrandAgentEmailSendMessageStatus, type BrandApp, type BrandAppStatus, type BrandDrop, type BrandDropCtaType, type BrandDropMusicLink, type BrandSubscription, type CheckoutMarketingConsentInput, type CheckoutMarketingConsentPrompt, type ConsentChannel, type ConsentPromptCategory, type ConsentStatus, type ContributionAdmin, type ContributionPageAdmin, type ContributionPageStatusFilter, type ContributionPagesResponse, type ContributionSource, type ContributionStatus, type ContributionsResponse, type CreateBrandAppInput, type CreateManualContributionInput, type CreateMomentOnlineConfigInput, type CreatePartnerBrandDropInput, type CreatePartnerBrandSubscriptionInput, type CreatePartnerBrandSubscriptionResponse, type CreatePartnerMomentInput, type CreatePartnerTicketTierInput, type CreatePlanBudgetInput, type CreatePlanInput, type Currency, DEFAULT_API_URL, type Dimensions, type DimensionsInput, type DynamicPricingActorType, type DynamicPricingAdmissionWindow, type DynamicPricingBatch, type DynamicPricingBatchEvent, type DynamicPricingBatchEventType, type DynamicPricingBatchItem, type DynamicPricingBatchItemStatus, type DynamicPricingBatchStatus, type DynamicPricingContext, type DynamicPricingExecutionMode, type DynamicPricingInventoryGuardInput, type DynamicPricingInventoryGuardMode, type DynamicPricingInventoryMetric, type DynamicPricingMomentInput, type DynamicPricingTierContext, type DynamicPricingTierUpdateInput, type Echo, type EchoMediaAsset, type EchoType, type EditPartnerTicketTiersForMomentInput, type EventImportPlatform, GenqlError, type GetBrandEchoesForUserResponse, type GetMomentLineupsResponse, type GetMomentTagAssignmentsResponse, type GetPartnerAudienceInput, type GetPartnerAudienceResponse, type GetPartnerCustomersResponse, type GetPartnerDropsResponse, type GetPartnerMediaAssetsInput, type GetPartnerMediaAssetsResponse, type GetPartnerMembersInput, type GetPartnerMembersResponse, type GetPartnerMembershipTiersInput, type GetPartnerMembershipTiersResponse, type GetPartnerTicketTiersForMomentInput, type GetPartnerTicketTiersForMomentResponse, type GetPlansInput, type GetPlansResponse, type GetPublicMomentsResponse, type GetTicketsResponse, type ITMPartnerAgentAccessConfig, type ITMPartnerAgentAccessCredentials, type ITMPartnerAgentSessionConfig, type ITMPartnerAgentSessionCredentials, type ITMPartnerClient, type ITMPartnerClientConfig, type ITMPartnerHeaders, type ITMPartnerHeadersObject, type ITMPartnerIntegrationConfig, type ITMPartnerIntegrationCredentials, type ITMPartnerTokenConfig, ITMPartnerTransportError, type LoginCodeChannel, type ManualContributionReceiptType, type MediaAsset, type MediaAssetUploadUrl, type MembershipBillingInterval, type MembershipExpiryType, type MembershipPassType, type MembershipPurchaseType, type MembershipSource, type MembershipStatus, type MerchPurchase, type Moment, type MomentCategory, type MomentCollection, type MomentCollectionLink, type MomentDiscountCodeUsage, type MomentDynamicPricingPolicy, type MomentDynamicPricingTierRule, type MomentLineup, type MomentLineupDisplayLabel, type MomentLineupResponseResult, type MomentLineupStatus, type MomentLineupType, type MomentOccurrenceScheduleFrequency, type MomentOnlineProvider, type MomentPublicVenuePreview, type MomentSortOrder, type MomentStatus, type MomentSubcategory, type MomentTagAssignment, type MomentType, type MusicReleaseType, type Mutation, type PaginationInput, type PartnerAppLogin, type PartnerAppLoginChallenge, type PartnerAppLoginProfile, type PartnerAudienceCustomer, type PartnerAudienceFiltersInput, type PartnerAudienceSortField, type PartnerAudienceSortInput, type PartnerBrand, type PartnerCustomer, type PartnerMember, type PartnerMemberCustomer, type PartnerMemberTier, type PartnerMembershipTier, type PartnerMomentAttendanceCount, type PartnerMomentAttendanceLookupInput, type PartnerMomentAttendanceStats, type PartnerMomentGuestlistAttendance, type PartnerMomentGuestlistLabelAttendance, type PartnerMomentStats, type PartnerMomentTicketAttendance, type PartnerMomentTicketTierAttendance, type PartnerMomentsFiltersInput, type PartnerTicketStatus, type PartnerTicketTier, type PartnerTicketTierUpdateInput, type PartnerTicketUserLookupInput, type PartnerTicketsForUserInput, type Payment, type PaymentStatus, type Plan, type PlanBudget, type PlanBudgetAllocationType, type PlanBudgetArtistDealBasis, type PlanBudgetArtistDealInput, type PlanBudgetArtistDealType, type PlanBudgetCapacityAllocationInput, type PlanBudgetCategoryInput, type PlanBudgetCategoryKind, type PlanBudgetChargeCalculation, type PlanBudgetChargeKind, type PlanBudgetChargeTreatment, type PlanBudgetExternalTicketingChannelInput, type PlanBudgetFeeAssessment, type PlanBudgetFeeComponentKind, type PlanBudgetFeePercentageBasis, type PlanBudgetGuaranteeBasis, type PlanBudgetLineBasis, type PlanBudgetLineInput, type PlanBudgetPaymentStatus, type PlanBudgetPricingMode, type PlanBudgetSummary, type PlanBudgetTicketChargeRuleInput, type PlanBudgetTicketTierInput, type PlanBudgetTicketingChannelType, type PlanBudgetTicketingFeeComponentInput, type PlanKind, type PlanLinkMetadataStatus, type PlanMoodboard, type PlanMoodboardItem, type PlanMoodboardItemType, type PlanSchedule, type PlanScheduleInput, type PlanScheduleTime, type PlanScheduleTimeInput, type PlanScheduleType, type PlanStatus, type PlanSummary, type PlanningProposal, type PlanningSource, type PlanningSourceDispositionInput, type PlanningSourceSection, type PostSubscriptionEmailInput, type PostSubscriptionMessageInput, type PostSubscriptionPushInput, type PostSubscriptionSmsInput, type PreparePlanningProposalInput, type PublicMomentLineupInfo, type Query, type ReplacePlanBudgetDraftInput, type RespondToMomentLineupInput, type SendPartnerAgentEmailInput, type SortDirection, type StartPartnerAppLoginInput, type SubscriptionComplianceInput, type Tag, type TagSource, type ThirdPartyEchoType, type Ticket, type TicketAdmissionWindowSource, type TicketAttendanceMode, type TicketExtension, type TicketExtensionStatus, type TicketTier, type Transforms, type UpdatePlanInput, type User, type UserSource, type Venue, type VenueInput, type VerifyPartnerAppLoginInput, type VerifyPartnerBrandSubscriptionInput, createITMPartnerClient, everything, generateMutationOp, generateQueryOp };
package/dist/index.js CHANGED
@@ -5382,24 +5382,46 @@ assertNodeServerRuntime();
5382
5382
  var DEFAULT_API_URL = "https://itm-backend-production.up.railway.app/graphql";
5383
5383
  var RESERVED_AGENT_HEADERS = /* @__PURE__ */ new Set([
5384
5384
  "authorization",
5385
+ "x-itm-integration-access-token",
5385
5386
  "x-itm-agent-session-id",
5386
5387
  "x-itm-agent-bootstrap-token",
5387
5388
  "x-itm-agent-access-token",
5388
5389
  "x-partner-api-key"
5389
5390
  ]);
5390
5391
  function createITMPartnerClient(config) {
5391
- const { baseUrl, headers: extraHeaders } = config;
5392
+ const { baseUrl, headers: extraHeaders, signal } = config;
5392
5393
  const token = "token" in config ? config.token : void 0;
5393
5394
  const agentSession = "agentSession" in config ? config.agentSession : void 0;
5394
5395
  const agentAccess = "agentAccess" in config ? config.agentAccess : void 0;
5395
- const providedModes = [token, agentSession, agentAccess].filter(
5396
+ const integration = "integration" in config ? config.integration : void 0;
5397
+ const providedModes = [token, agentSession, agentAccess, integration].filter(
5396
5398
  (mode) => mode !== void 0
5397
5399
  );
5398
5400
  if (providedModes.length > 1) {
5399
5401
  throw new Error(
5400
- "ITM Partner SDK: provide exactly one of token, agentSession, or agentAccess authentication."
5402
+ "ITM Partner SDK: provide exactly one of token, agentSession, agentAccess, or integration authentication."
5401
5403
  );
5402
5404
  }
5405
+ if (integration !== void 0) {
5406
+ if (typeof integration.accessToken !== "function" && (typeof integration.accessToken !== "string" || !integration.accessToken.trim())) {
5407
+ throw new Error("ITM Partner SDK: integration.accessToken is required.");
5408
+ }
5409
+ return createSafeClient({
5410
+ url: baseUrl ?? DEFAULT_API_URL,
5411
+ signal,
5412
+ headers: async () => {
5413
+ const extra = typeof extraHeaders === "function" ? await extraHeaders() : extraHeaders;
5414
+ let credential;
5415
+ try {
5416
+ credential = typeof integration.accessToken === "function" ? await integration.accessToken() : integration.accessToken;
5417
+ } catch {
5418
+ throw new Error("ITM Partner SDK: integration credential is unavailable.");
5419
+ }
5420
+ if (typeof credential !== "string" || !credential.trim()) throw new Error("ITM Partner SDK: integration credential is unavailable.");
5421
+ return { ...sanitizeHeaders(extra), "x-itm-integration-access-token": credential, "Content-Type": "application/json" };
5422
+ }
5423
+ });
5424
+ }
5403
5425
  if (agentAccess !== void 0) {
5404
5426
  if (typeof agentAccess.workloadToken !== "function") {
5405
5427
  throw new Error(
@@ -5409,8 +5431,9 @@ function createITMPartnerClient(config) {
5409
5431
  if (!agentAccess.accessToken) {
5410
5432
  throw new Error("ITM Partner SDK: agentAccess.accessToken is required.");
5411
5433
  }
5412
- return createClient2({
5434
+ return createSafeClient({
5413
5435
  url: baseUrl ?? DEFAULT_API_URL,
5436
+ signal,
5414
5437
  headers: async () => {
5415
5438
  const resolvedExtraHeaders = typeof extraHeaders === "function" ? await extraHeaders() : extraHeaders;
5416
5439
  const sanitizedExtraHeaders = Object.fromEntries(
@@ -5442,8 +5465,9 @@ function createITMPartnerClient(config) {
5442
5465
  if (!agentSession.sessionUid) {
5443
5466
  throw new Error("ITM Partner SDK: agentSession.sessionUid is required.");
5444
5467
  }
5445
- return createClient2({
5468
+ return createSafeClient({
5446
5469
  url: baseUrl ?? DEFAULT_API_URL,
5470
+ signal,
5447
5471
  headers: async () => {
5448
5472
  const resolvedExtraHeaders = typeof extraHeaders === "function" ? await extraHeaders() : extraHeaders;
5449
5473
  const sanitizedExtraHeaders = Object.fromEntries(
@@ -5472,21 +5496,80 @@ function createITMPartnerClient(config) {
5472
5496
  "ITM Partner SDK: token is required. Get one from backstage: Settings > Partner API."
5473
5497
  );
5474
5498
  }
5475
- return createClient2({
5499
+ return createSafeClient({
5476
5500
  url: baseUrl ?? DEFAULT_API_URL,
5501
+ signal,
5477
5502
  headers: async () => {
5478
5503
  const resolvedExtraHeaders = typeof extraHeaders === "function" ? await extraHeaders() : extraHeaders;
5479
5504
  return {
5480
- ...resolvedExtraHeaders ?? {},
5505
+ ...sanitizeHeaders(resolvedExtraHeaders),
5481
5506
  "x-partner-api-key": token,
5482
5507
  "Content-Type": "application/json"
5483
5508
  };
5484
5509
  }
5485
5510
  });
5486
5511
  }
5512
+ function sanitizeHeaders(headers) {
5513
+ return Object.fromEntries(Object.entries(headers ?? {}).filter(([name]) => !RESERVED_AGENT_HEADERS.has(name.toLowerCase())));
5514
+ }
5515
+ var ITMPartnerTransportError = class extends Error {
5516
+ constructor(status, requestId) {
5517
+ super(status ? `ITM Partner API request failed (HTTP ${status}).` : "ITM Partner API request failed.");
5518
+ this.status = status;
5519
+ this.requestId = requestId;
5520
+ }
5521
+ name = "ITMPartnerTransportError";
5522
+ };
5523
+ function createSafeClient(options) {
5524
+ return createClient2({ fetcher: async (operation) => {
5525
+ options.signal?.throwIfAborted();
5526
+ const headers = await withCancellation(options.headers, options.signal);
5527
+ options.signal?.throwIfAborted();
5528
+ let response;
5529
+ try {
5530
+ response = await fetch(options.url, { method: "POST", headers, body: JSON.stringify(operation), signal: options.signal, redirect: "error" });
5531
+ } catch {
5532
+ options.signal?.throwIfAborted();
5533
+ throw new ITMPartnerTransportError(void 0);
5534
+ }
5535
+ if (!response.ok) throw new ITMPartnerTransportError(response.status, response.headers.get("x-request-id") ?? void 0);
5536
+ let value;
5537
+ try {
5538
+ value = await response.json();
5539
+ } catch {
5540
+ options.signal?.throwIfAborted();
5541
+ throw new ITMPartnerTransportError(response.status);
5542
+ }
5543
+ if (!value || typeof value !== "object" || !("data" in value || "errors" in value)) throw new ITMPartnerTransportError(response.status);
5544
+ const result = value;
5545
+ const secrets = Object.entries(headers).filter(([key]) => RESERVED_AGENT_HEADERS.has(key.toLowerCase())).flatMap(([, v]) => [v, v.replace(/^Bearer /i, "")]).filter(Boolean);
5546
+ const redact = (message) => secrets.reduce((text, secret) => text.split(secret).join("[redacted]"), message);
5547
+ if (result.errors) result.errors = result.errors.map((error) => ({ name: "GraphQLError", message: redact(typeof error.message === "string" ? error.message : "GraphQL request failed"), extensions: typeof error.extensions?.code === "string" ? { code: redact(error.extensions.code) } : void 0 }));
5548
+ return result;
5549
+ } });
5550
+ }
5551
+ async function withCancellation(operation, signal) {
5552
+ signal?.throwIfAborted();
5553
+ if (!signal) return operation();
5554
+ let abort = () => {
5555
+ };
5556
+ try {
5557
+ return await Promise.race([
5558
+ operation(),
5559
+ new Promise((_resolve, reject) => {
5560
+ abort = () => reject(signal.reason);
5561
+ signal.addEventListener("abort", abort, { once: true });
5562
+ if (signal.aborted) abort();
5563
+ })
5564
+ ]);
5565
+ } finally {
5566
+ signal.removeEventListener("abort", abort);
5567
+ }
5568
+ }
5487
5569
 
5488
5570
  exports.DEFAULT_API_URL = DEFAULT_API_URL;
5489
5571
  exports.GenqlError = GenqlError;
5572
+ exports.ITMPartnerTransportError = ITMPartnerTransportError;
5490
5573
  exports.createITMPartnerClient = createITMPartnerClient;
5491
5574
  exports.everything = everything;
5492
5575
  exports.generateMutationOp = generateMutationOp;