Skip to content

feat: add PackageLink.request for auth org trust link (W-23970567) - #918

Merged
sshyamala-sfdc merged 4 commits into
packaging-distribution/spifrom
t/packaging-distribution/w-23970567/auth-link-request
Aug 26, 2026
Merged

feat: add PackageLink.request for auth org trust link (W-23970567)#918
sshyamala-sfdc merged 4 commits into
packaging-distribution/spifrom
t/packaging-distribution/w-23970567/auth-link-request

Conversation

@sshyamala-sfdc

Copy link
Copy Markdown
Collaborator

What

Adds the PackageLink library 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 API PkgVrfyAuthOrgTrustRela SObject, with a duplicate-guard that fails if an active (Pending/Accepted/Linked) relationship already exists.
  • New PackageLinkRequestOptions / PackageLinkRequestResult types.
  • Adds an Organization Id (00D) entry to the ID registry for validation.
  • Messages + unit tests.

Testing

  • yarn build and full yarn test pass.
  • Companion plugin PR: salesforcecli/plugin-packaging (sf package link request, beta/hidden).

W-23970567

🤖 Generated with Claude Code

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 btrn11 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few functional issues on the duplicate-guard / create path.

Comment thread src/package/packageLink.ts Outdated
}

function getLinkRequestQuery(): string {
return "SELECT Id, VerifiedOrg, Status FROM PkgVrfyAuthOrgTrustRela WHERE VerifiedOrg = '%s'";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/package/packageLink.ts Outdated
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'];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/package/packageLink.ts Outdated
options: PackageLinkRequestOptions
): Promise<PackageLinkRequestResult> {
try {
validateId(BY_LABEL.ORGANIZATION_ID, options.verifiedOrgId);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalidVerifiedOrgId is unused; validateId throws pkg_utils invalidIdOrAlias. Throw the package_link message (or drop it).

Comment thread src/package/packageLink.ts Outdated
});

if (!createResult.success) {
throw messages.createError('linkRequestFailed', [options.verifiedOrgId]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This drops createResult.errors (duplicate value, validation, etc.). Prefer connection.tooling.create(...) and include the save errors in the thrown SfError.

sshyamala-sfdc and others added 3 commits August 26, 2026 16:45
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>
@sshyamala-sfdc
sshyamala-sfdc merged commit 7cccbb0 into packaging-distribution/spi Aug 26, 2026
15 checks passed
@sshyamala-sfdc
sshyamala-sfdc deleted the t/packaging-distribution/w-23970567/auth-link-request branch August 26, 2026 19:00
btrn11 added a commit that referenced this pull request Aug 26, 2026
Keep PackageTrustLink.request from #918 and add PBO list on that class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants