feat: add PackageLink.request for auth org trust link (W-23970567) - #918
Conversation
Add the PackageLink library class that creates a Public Secure trust relationship (PkgVrfyAuthOrgTrustRela) from a connected authoring org to a Verified Partner Business Org via the Tooling API. Includes the PackageLinkRequestOptions/Result types, an Organization Id (00D) entry in the ID registry, messages, and unit tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
btrn11
left a comment
There was a problem hiding this comment.
A few functional issues on the duplicate-guard / create path.
| } | ||
|
|
||
| function getLinkRequestQuery(): string { | ||
| return "SELECT Id, VerifiedOrg, Status FROM PkgVrfyAuthOrgTrustRela WHERE VerifiedOrg = '%s'"; |
There was a problem hiding this comment.
VerifiedOrg is TEXT and core stores it as 15-char. An 18-char --verified-org will miss existing rows (SOQL won’t coerce). trimTo15 before query/create, same as PackageLink.list.
| const LINK_REQUEST_SOBJECT = 'PkgVrfyAuthOrgTrustRela'; | ||
|
|
||
| // Statuses that mean a trust relationship already exists and must be revoked (via unlink) before requesting again. | ||
| const ACTIVE_LINK_STATUSES = ['Pending', 'Accepted', 'Linked']; |
There was a problem hiding this comment.
No Linked status — enum is Pending/Accepted/Declined/Revoked/Failed. Declined/Revoked/Failed rows still occupy the unique key, so a re-request skips this guard and fails on insert. Treat any existing row as blocking until deleted.
| options: PackageLinkRequestOptions | ||
| ): Promise<PackageLinkRequestResult> { | ||
| try { | ||
| validateId(BY_LABEL.ORGANIZATION_ID, options.verifiedOrgId); |
There was a problem hiding this comment.
invalidVerifiedOrgId is unused; validateId throws pkg_utils invalidIdOrAlias. Throw the package_link message (or drop it).
| }); | ||
|
|
||
| if (!createResult.success) { | ||
| throw messages.createError('linkRequestFailed', [options.verifiedOrgId]); |
There was a problem hiding this comment.
This drops createResult.errors (duplicate value, validation, etc.). Prefer connection.tooling.create(...) and include the save errors in the thrown SfError.
Rename PackageLink -> PackageTrustLink for the "sf package trust link request" command and address PR #918 review feedback: - normalize verified org ID with trimTo15 before lookup and insert - block any existing trust relationship regardless of status - validate the verified org ID in the library (invalidVerifiedOrgId) - create via tooling.create and surface errors with combineSaveErrors Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… t/packaging-distribution/w-23970567/auth-link-request
An authoring org can hold only one trust relationship at a time. The Tooling API query runs against the connected authoring org and only returns that org's own rows, so the duplicate check must not filter by VerifiedOrg. Drop the WHERE clause and report the existing link's verified org in the error. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Keep PackageTrustLink.request from #918 and add PBO list on that class.
What
Adds the
PackageLinklibrary class that creates a Public Secure trust relationship (PkgVrfyAuthOrgTrustRela) from a connected authoring org to a Verified Partner Business Org (PBO) via the Tooling API.Details
PackageLink.request(connection, { verifiedOrgId })— POSTs{ VerifiedOrg, Status: 'Pending' }to the Tooling APIPkgVrfyAuthOrgTrustRelaSObject, with a duplicate-guard that fails if an active (Pending/Accepted/Linked) relationship already exists.PackageLinkRequestOptions/PackageLinkRequestResulttypes.Organization Id(00D) entry to the ID registry for validation.Testing
yarn buildand fullyarn testpass.sf package link request, beta/hidden).W-23970567
🤖 Generated with Claude Code