@pymthouse/builder-sdk 0.4.5 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -2,7 +2,7 @@ export { NETWORK_USD_PER_MICRO, applyRetailRateToNetworkMicros, defaultRetailRat
2
2
  import { S as SignedTicketIngestInput, F as FetchLike, f as SignedTicketIngestResult, r as UsageByUserRow, s as UsageForExternalUser, e as UsageApiResponse, n as MeScopeUsagePayload, t as UsageByPipelineModelRow, u as UsageByPipelineModelFiatRow, O as OidcDiscoveryDocument, v as AppManifestResponse } from './types-CcP67AZm.cjs';
3
3
  export { w as AllowancePolicy, x as AppManifestCapability, A as AppUserRecord, q as ApproveDeviceLoginInput, B as BillingProduct, y as BillingSyncState, z as BillingSyncStatus, E as CapabilityPriceRule, C as ClientCredentialsTokenResponse, D as DeviceApprovalInput, o as GetAppManifestResult, G as GetDiscoveryOptions, l as GrantSource, L as ListBillingProductsResult, p as MintSignerSessionForExternalUserInput, M as MintUserAccessTokenInput, b as MintUserAccessTokenResponse, c as MintUserSignerSessionTokenInput, a as ParsedDeviceApprovalRedirect, h as PlanSyncResult, P as PmtHouseClientOptions, H as SignerRoutingConfig, g as SignerRoutingResponse, T as TokenExchangeResponse, U as UpsertAppUserInput, i as UsageBalanceResponse, I as UsageDailyPipelineRow, d as UsageQueryInput, J as UsageTotals, k as UserAllowanceGrantInput, j as UserAllowancesResponse, K as UserCreditGrantInput, N as UserCreditsResponse, m as UserSubscriptionResponse } from './types-CcP67AZm.cjs';
4
4
  import { S as SignerUsageSnapshot } from './proxy-CZLY0IfL.cjs';
5
- export { P as PmtHouseClient, b as buildDeviceCodeResource, n as normalizeUserCode } from './client-GP-mTEI7.cjs';
5
+ export { P as PmtHouseClient, b as buildDeviceCodeResource, n as normalizeUserCode } from './client-CEBVgCD7.cjs';
6
6
  export { P as PmtHouseError, t as toPmtHouseError } from './errors-C9-V_zSi.cjs';
7
7
  export { PYMTHOUSE_NOT_CONFIGURED_MESSAGE, getBuilderApiV1BaseFromIssuerUrl, getPymthouseIssuerOrigin, getPymthouseIssuerUrlFromEnv, getPymthousePublicClientIdFromEnv, isPymthouseConfigured, readPymthouseEnv } from './config.cjs';
8
8
  import { AuthorizationServer } from 'oauth4webapi';
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { NETWORK_USD_PER_MICRO, applyRetailRateToNetworkMicros, defaultRetailRat
2
2
  import { S as SignedTicketIngestInput, F as FetchLike, f as SignedTicketIngestResult, r as UsageByUserRow, s as UsageForExternalUser, e as UsageApiResponse, n as MeScopeUsagePayload, t as UsageByPipelineModelRow, u as UsageByPipelineModelFiatRow, O as OidcDiscoveryDocument, v as AppManifestResponse } from './types-CcP67AZm.js';
3
3
  export { w as AllowancePolicy, x as AppManifestCapability, A as AppUserRecord, q as ApproveDeviceLoginInput, B as BillingProduct, y as BillingSyncState, z as BillingSyncStatus, E as CapabilityPriceRule, C as ClientCredentialsTokenResponse, D as DeviceApprovalInput, o as GetAppManifestResult, G as GetDiscoveryOptions, l as GrantSource, L as ListBillingProductsResult, p as MintSignerSessionForExternalUserInput, M as MintUserAccessTokenInput, b as MintUserAccessTokenResponse, c as MintUserSignerSessionTokenInput, a as ParsedDeviceApprovalRedirect, h as PlanSyncResult, P as PmtHouseClientOptions, H as SignerRoutingConfig, g as SignerRoutingResponse, T as TokenExchangeResponse, U as UpsertAppUserInput, i as UsageBalanceResponse, I as UsageDailyPipelineRow, d as UsageQueryInput, J as UsageTotals, k as UserAllowanceGrantInput, j as UserAllowancesResponse, K as UserCreditGrantInput, N as UserCreditsResponse, m as UserSubscriptionResponse } from './types-CcP67AZm.js';
4
4
  import { S as SignerUsageSnapshot } from './proxy-D36SpZ6k.js';
5
- export { P as PmtHouseClient, b as buildDeviceCodeResource, n as normalizeUserCode } from './client-BhNz0ZAA.js';
5
+ export { P as PmtHouseClient, b as buildDeviceCodeResource, n as normalizeUserCode } from './client-D-p6v8ju.js';
6
6
  export { P as PmtHouseError, t as toPmtHouseError } from './errors-C9-V_zSi.js';
7
7
  export { PYMTHOUSE_NOT_CONFIGURED_MESSAGE, getBuilderApiV1BaseFromIssuerUrl, getPymthouseIssuerOrigin, getPymthouseIssuerUrlFromEnv, getPymthousePublicClientIdFromEnv, isPymthouseConfigured, readPymthouseEnv } from './config.js';
8
8
  import { AuthorizationServer } from 'oauth4webapi';
package/dist/index.js CHANGED
@@ -1467,8 +1467,13 @@ var PmtHouseClient = class {
1467
1467
  params.set("subject_token", input.userJwt);
1468
1468
  params.set("subject_token_type", SUBJECT_ACCESS_TOKEN_TYPE2);
1469
1469
  params.set("requested_token_type", REQUESTED_ACCESS_TOKEN_TYPE);
1470
- const resourceCandidate = typeof input.resource === "string" && input.resource.trim() !== "" ? input.resource.trim() : this.issuerUrl;
1471
- params.set("resource", stripTrailingSlashes(resourceCandidate));
1470
+ if (typeof input.scope === "string" && input.scope.trim() !== "") {
1471
+ params.set("scope", input.scope.trim());
1472
+ }
1473
+ if (!input.omitResource) {
1474
+ const resourceCandidate = typeof input.resource === "string" && input.resource.trim() !== "" ? input.resource.trim() : this.issuerUrl;
1475
+ params.set("resource", stripTrailingSlashes(resourceCandidate));
1476
+ }
1472
1477
  try {
1473
1478
  const response = await genericTokenEndpointRequest(
1474
1479
  as,
@@ -1754,18 +1759,31 @@ var PmtHouseClient = class {
1754
1759
  };
1755
1760
  }
1756
1761
  /**
1757
- * Upsert an external user, mint a short-lived JWT, and exchange for an opaque signer session.
1762
+ * Upsert an external user, mint a short-lived JWT, and exchange it for a
1763
+ * long-lived opaque (`pmth_*`) signer session.
1764
+ *
1765
+ * Performs the *documented* remote-signer-session exchange (see
1766
+ * `builder-api.md` → "Remote signer session exchange"): the RFC 8693 token
1767
+ * exchange is sent with `scope=sign:job` and **no `resource` indicator**,
1768
+ * which selects the PymtHouse gateway/opaque path. A prior implementation set
1769
+ * `resource = issuer`, which routed to the signer-JWT path and returned a JWT
1770
+ * that {@link parseSignerSessionExchange} then rejected as non-opaque.
1758
1771
  */
1759
1772
  async mintSignerSessionForExternalUser(input) {
1773
+ const scope = input.scope ?? SIGN_JOB_SCOPE;
1760
1774
  await this.upsertAppUser({
1761
1775
  externalUserId: input.externalUserId,
1762
1776
  email: input.email,
1763
1777
  status: "active"
1764
1778
  });
1765
- const exchange = await this.mintUserSignerSessionToken({
1779
+ const userToken = await this.mintUserAccessToken({
1766
1780
  externalUserId: input.externalUserId,
1767
- scope: input.scope ?? SIGN_JOB_SCOPE,
1768
- resource: this.issuerUrl
1781
+ scope
1782
+ });
1783
+ const exchange = await this.exchangeForSignerSession({
1784
+ userJwt: userToken.access_token,
1785
+ omitResource: true,
1786
+ scope
1769
1787
  });
1770
1788
  return parseSignerSessionExchange(exchange);
1771
1789
  }