@simplysf/simply-community-core 0.2.12 → 0.2.13

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
@@ -16,21 +16,23 @@ Requires Node.js `>=22` and either `"type": "module"` or a dynamic `import()`
16
16
 
17
17
  Everything below is exported from the package root. Removing or renaming an export is a breaking change; see [`src/index.ts`](src/index.ts).
18
18
 
19
- | Export | Description |
20
- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
21
- | `publishCommunity(options)` | Triggers a community publish via the Connect REST API and polls until it completes. |
22
- | `checkPublishStatus(connection, jobId)` | Builds the `PollingClient`-compatible poll function `publishCommunity` uses. |
23
- | `deployChangedFiles(options)` | Deploys a specific file list and polls until the deploy reaches a terminal state. |
24
- | `retrieveCustomSite(connection, site, outputDirectory)` | Retrieves a single `CustomSite` component by name. |
25
- | `resolveSearchRoots(directory?, projectDir?)` | Resolves the root directories a site/network lookup should search under. |
26
- | `resolveRetrieveDestination(directory?, projectDir?)` | Resolves the single directory a retrieve should write into. |
27
- | `resolveSiteFile(site, roots)` | Finds the `sites/<site>.site-meta.xml` file for a CustomSite API name. |
28
- | `resolveNetworkFile(site, roots)` | Finds the `networks/*.network-meta.xml` file whose `<site>` element names a CustomSite. |
29
- | `patchCustomSiteXml(xml, options)` | Pure function: replaces a `CustomSite` metadata document's custom URLs with exactly one. |
30
- | `patchNetworkXml(xml, pathPrefix)` | Pure function: patches a `Network` metadata document's `urlPathPrefix`. |
31
- | `readNetworkSiteName(xml)` | Pure function: reads a `Network` metadata document's `<site>` element. |
32
- | `verifyDomain(connection, domain)` | Checks whether a custom domain is registered in the target org, and what it's already bound to. |
33
- | `PublishCommunityOptions`, `DeployChangedFilesOptions`, `DeployChangedFilesResult`, `DeployComponentFailure`, `PatchCustomSiteXmlOptions`, `PatchCustomSiteXmlResult`, `DomainCheckStatus`, `DomainCheckResult` | Option and result types for `publishCommunity`, `deployChangedFiles`, `patchCustomSiteXml`, and `verifyDomain`. |
19
+ | Export | Description |
20
+ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
21
+ | `publishCommunity(options)` | Triggers a community publish via the Connect REST API and polls until it completes. `options.onPollError` reports failed status checks. |
22
+ | `checkPublishStatus(connection, jobId, requestTimeout?, onPollError?)` | Builds the `PollingClient`-compatible poll function `publishCommunity` uses. |
23
+ | `queryNetworkByName(connection, name, requestTimeout?)` | Looks up a `Network` (Experience Cloud site) by name; throws the same errors as `singleRecordQuery`. |
24
+ | `DEFAULT_PUBLISH_REQUEST_TIMEOUT` | Bounds each Salesforce API call above (30s). A stalled request is cancelled, not abandoned. |
25
+ | `deployChangedFiles(options)` | Deploys a specific file list and polls until the deploy reaches a terminal state. |
26
+ | `retrieveCustomSite(connection, site, outputDirectory)` | Retrieves a single `CustomSite` component by name. |
27
+ | `resolveSearchRoots(directory?, projectDir?)` | Resolves the root directories a site/network lookup should search under. |
28
+ | `resolveRetrieveDestination(directory?, projectDir?)` | Resolves the single directory a retrieve should write into. |
29
+ | `resolveSiteFile(site, roots)` | Finds the `sites/<site>.site-meta.xml` file for a CustomSite API name. |
30
+ | `resolveNetworkFile(site, roots)` | Finds the `networks/*.network-meta.xml` file whose `<site>` element names a CustomSite. |
31
+ | `patchCustomSiteXml(xml, options)` | Pure function: replaces a `CustomSite` metadata document's custom URLs with exactly one. |
32
+ | `patchNetworkXml(xml, pathPrefix)` | Pure function: patches a `Network` metadata document's `urlPathPrefix`. |
33
+ | `readNetworkSiteName(xml)` | Pure function: reads a `Network` metadata document's `<site>` element. |
34
+ | `verifyDomain(connection, domain)` | Checks whether a custom domain is registered in the target org, and what it's already bound to. |
35
+ | `PublishCommunityOptions`, `NetworkRecord`, `DeployChangedFilesOptions`, `DeployChangedFilesResult`, `DeployComponentFailure`, `PatchCustomSiteXmlOptions`, `PatchCustomSiteXmlResult`, `DomainCheckStatus`, `DomainCheckResult` | Option and result types for `publishCommunity`, `queryNetworkByName`, `deployChangedFiles`, `patchCustomSiteXml`, and `verifyDomain`. |
34
36
 
35
37
  ```ts
36
38
  import { publishCommunity } from '@simplysf/simply-community-core';
@@ -0,0 +1,39 @@
1
+ import type { Duration } from '@salesforce/kit';
2
+ import type { Connection } from '@salesforce/core';
3
+ import { type RetryWithBackoffOptions } from '@simplysf/simply-core';
4
+ type HttpRequest = Parameters<Connection['request']>[0];
5
+ /** The response shape of `GET /query?q=…`. */
6
+ export type QueryResponse<T> = {
7
+ totalSize: number;
8
+ done: boolean;
9
+ records: T[];
10
+ };
11
+ /**
12
+ * `Connection.request()` bounded to `timeout`, with the request actually cancelled when it fires.
13
+ *
14
+ * jsforce aborts the underlying fetch (and releases its socket) once the per-request `timeout` option
15
+ * elapses; without it a stalled request stays open for jsforce's 30-minute default, keeping the
16
+ * process alive long after the caller has given up. Only `Connection.request()` forwards that option
17
+ * — `query()`/`singleRecordQuery()` don't — hence {@link boundedQuery}. `retryWithBackoff`'s
18
+ * `attemptTimeout` is set to the same value as a backstop, so the attempt still settles with a
19
+ * `RetryAttemptTimeoutError` even if jsforce ever stops honouring the option. See
20
+ * docs/design/0044-community-publish-cancel-stalled-requests.md.
21
+ *
22
+ * @param connection - The org connection.
23
+ * @param request - The request to make, as accepted by `Connection.request()`.
24
+ * @param timeout - Bounds each attempt.
25
+ * @param retry - Retry settings; defaults to a single attempt.
26
+ * @returns The parsed response body.
27
+ */
28
+ export declare function boundedRequest<T>(connection: Connection, request: HttpRequest, timeout: Duration, retry?: Pick<RetryWithBackoffOptions, 'retryAttempts' | 'backoffFactor'>): Promise<T>;
29
+ /**
30
+ * A SOQL query through {@link boundedRequest}, so it's cancelled rather than abandoned on timeout.
31
+ * Returns only the first batch of records — fine for the single-record lookups this package makes.
32
+ *
33
+ * @param connection - The org connection.
34
+ * @param soql - The query to run.
35
+ * @param timeout - Bounds the request.
36
+ * @returns The query response.
37
+ */
38
+ export declare function boundedQuery<T>(connection: Connection, soql: string, timeout: Duration): Promise<QueryResponse<T>>;
39
+ export {};
@@ -0,0 +1,55 @@
1
+ /*
2
+ * Copyright (c) 2026, SimplySF.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { retryWithBackoff } from '@simplysf/simply-core';
17
+ /**
18
+ * How long after `attemptTimeout` jsforce aborts the request. Small enough that the socket goes away
19
+ * promptly; non-zero so the attempt reliably fails with `RetryAttemptTimeoutError` first, rather than
20
+ * jsforce's `AbortError`, whose message wrongly claims a 30-minute timeout.
21
+ */
22
+ const JSFORCE_ABORT_GRACE_MS = 1000;
23
+ /**
24
+ * `Connection.request()` bounded to `timeout`, with the request actually cancelled when it fires.
25
+ *
26
+ * jsforce aborts the underlying fetch (and releases its socket) once the per-request `timeout` option
27
+ * elapses; without it a stalled request stays open for jsforce's 30-minute default, keeping the
28
+ * process alive long after the caller has given up. Only `Connection.request()` forwards that option
29
+ * — `query()`/`singleRecordQuery()` don't — hence {@link boundedQuery}. `retryWithBackoff`'s
30
+ * `attemptTimeout` is set to the same value as a backstop, so the attempt still settles with a
31
+ * `RetryAttemptTimeoutError` even if jsforce ever stops honouring the option. See
32
+ * docs/design/0044-community-publish-cancel-stalled-requests.md.
33
+ *
34
+ * @param connection - The org connection.
35
+ * @param request - The request to make, as accepted by `Connection.request()`.
36
+ * @param timeout - Bounds each attempt.
37
+ * @param retry - Retry settings; defaults to a single attempt.
38
+ * @returns The parsed response body.
39
+ */
40
+ export async function boundedRequest(connection, request, timeout, retry = { retryAttempts: 0, backoffFactor: 1 }) {
41
+ return retryWithBackoff(async () => connection.request(request, { timeout: timeout.milliseconds + JSFORCE_ABORT_GRACE_MS }), { ...retry, attemptTimeout: timeout });
42
+ }
43
+ /**
44
+ * A SOQL query through {@link boundedRequest}, so it's cancelled rather than abandoned on timeout.
45
+ * Returns only the first batch of records — fine for the single-record lookups this package makes.
46
+ *
47
+ * @param connection - The org connection.
48
+ * @param soql - The query to run.
49
+ * @param timeout - Bounds the request.
50
+ * @returns The query response.
51
+ */
52
+ export async function boundedQuery(connection, soql, timeout) {
53
+ return boundedRequest(connection, { method: 'GET', url: `/query?q=${encodeURIComponent(soql)}` }, timeout);
54
+ }
55
+ //# sourceMappingURL=boundedRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boundedRequest.js","sourceRoot":"","sources":["../src/boundedRequest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,gBAAgB,EAAgC,MAAM,uBAAuB,CAAC;AAIvF;;;;GAIG;AACH,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAKpC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,UAAsB,EACtB,OAAoB,EACpB,OAAiB,EACjB,QAA0E,EAAE,aAAa,EAAE,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE;IAEhH,OAAO,gBAAgB,CACrB,KAAK,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,CAAI,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,YAAY,GAAG,sBAAsB,EAAE,CAAC,EACtG,EAAE,GAAG,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,CACtC,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,UAAsB,EACtB,IAAY,EACZ,OAAiB;IAEjB,OAAO,cAAc,CACnB,UAAU,EACV,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,YAAY,kBAAkB,CAAC,IAAI,CAAC,EAAE,EAAE,EAC9D,OAAO,CACR,CAAC;AACJ,CAAC"}
@@ -11,7 +11,8 @@ import { type Connection, type StatusResult } from '@salesforce/core';
11
11
  * @param connection - The org connection to poll against.
12
12
  * @param jobId - The `jobId` returned by `POST /connect/communities/{id}/publish`.
13
13
  * @param requestTimeout - Bounds each status-check attempt. Defaults to `DEFAULT_PUBLISH_REQUEST_TIMEOUT`; overridable mainly so tests don't have to wait out the real default.
14
+ * @param onPollError - Called with the error whenever a status check fails, so the caller can surface it (the poll itself still reports "not finished yet").
14
15
  * @returns A `poll()` function for `PollingClient.create({ poll, ... })`.
15
16
  * @throws {SfError} `CommunityPublishFailedError` if the job reaches a terminal failure state.
16
17
  */
17
- export declare function checkPublishStatus(connection: Connection, jobId: string, requestTimeout?: Duration): () => Promise<StatusResult>;
18
+ export declare function checkPublishStatus(connection: Connection, jobId: string, requestTimeout?: Duration, onPollError?: (error: unknown) => void): () => Promise<StatusResult>;
@@ -13,8 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { SfError } from '@salesforce/core';
17
- import { retryWithBackoff } from '@simplysf/simply-core';
16
+ import { Logger, SfError } from '@salesforce/core';
17
+ import { boundedQuery } from './boundedRequest.js';
18
18
  import { DEFAULT_PUBLISH_REQUEST_TIMEOUT } from './requestTimeout.js';
19
19
  /**
20
20
  * Builds a `PollingClient`-compatible `poll()` function for a community publish job.
@@ -27,18 +27,23 @@ import { DEFAULT_PUBLISH_REQUEST_TIMEOUT } from './requestTimeout.js';
27
27
  * @param connection - The org connection to poll against.
28
28
  * @param jobId - The `jobId` returned by `POST /connect/communities/{id}/publish`.
29
29
  * @param requestTimeout - Bounds each status-check attempt. Defaults to `DEFAULT_PUBLISH_REQUEST_TIMEOUT`; overridable mainly so tests don't have to wait out the real default.
30
+ * @param onPollError - Called with the error whenever a status check fails, so the caller can surface it (the poll itself still reports "not finished yet").
30
31
  * @returns A `poll()` function for `PollingClient.create({ poll, ... })`.
31
32
  * @throws {SfError} `CommunityPublishFailedError` if the job reaches a terminal failure state.
32
33
  */
33
- export function checkPublishStatus(connection, jobId, requestTimeout = DEFAULT_PUBLISH_REQUEST_TIMEOUT) {
34
+ export function checkPublishStatus(connection, jobId, requestTimeout = DEFAULT_PUBLISH_REQUEST_TIMEOUT, onPollError) {
34
35
  return async () => {
35
36
  let result;
36
37
  try {
37
- result = await retryWithBackoff(() => Promise.resolve(connection.query(`SELECT Id, Status, FinishedAt, Error FROM BackgroundOperation WHERE Id = '${jobId}'`)), { retryAttempts: 0, backoffFactor: 1, attemptTimeout: requestTimeout });
38
+ result = await boundedQuery(connection, `SELECT Id, Status, FinishedAt, Error FROM BackgroundOperation WHERE Id = '${jobId}'`, requestTimeout);
38
39
  }
39
- catch {
40
+ catch (err) {
40
41
  // A stalled or failed status check isn't a publish failure — treat it the same as "not
41
42
  // finished yet" below and let PollingClient's own timeout/frequency decide when to give up.
43
+ // But don't swallow it: a failure that repeats every poll (e.g. the user can't query
44
+ // BackgroundOperation) would otherwise only show up as a timeout once --wait runs out.
45
+ Logger.childFromRoot('checkPublishStatus').debug(`Status check for publish job ${jobId} failed: ${String(err)}`);
46
+ onPollError?.(err);
42
47
  return { completed: false };
43
48
  }
44
49
  const operation = result.records[0];
@@ -1 +1 @@
1
- {"version":3,"file":"checkPublishStatus.js","sourceRoot":"","sources":["../src/checkPublishStatus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,OAAO,EAAsC,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,+BAA+B,EAAE,MAAM,qBAAqB,CAAC;AAUtE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB,CAChC,UAAsB,EACtB,KAAa,EACb,iBAA2B,+BAA+B;IAE1D,OAAO,KAAK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AACH,MAAM,UAAU,kBAAkB,CAChC,UAAsB,EACtB,KAAa,EACb,iBAA2B,+BAA+B,EAC1D,WAAsC;IAEtC,OAAO,KAAK,IAA2B,EAAE;QACvC,IAAI,MAAM,CAAC;QACX,IAAI,CAAC;YACH,MAAM,GAAG,MAAM,YAAY,CACzB,UAAU,EACV,6EAA6E,KAAK,GAAG,EACrF,cAAc,CACf,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,uFAAuF;YACvF,4FAA4F;YAC5F,qFAAqF;YACrF,uFAAuF;YACvF,MAAM,CAAC,aAAa,CAAC,oBAAoB,CAAC,CAAC,KAAK,CAAC,gCAAgC,KAAK,YAAY,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACjH,WAAW,EAAE,CAAC,GAAG,CAAC,CAAC;YACnB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;QAC9B,CAAC;QAED,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAA0C,CAAC;QAE7E,6FAA6F;QAC7F,8FAA8F;QAC9F,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,CAAC;YAC3B,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;QAC9B,CAAC;QAED,IAAI,SAAS,CAAC,KAAK,EAAE,CAAC;YACpB,MAAM,IAAI,OAAO,CACf,qCAAqC,SAAS,CAAC,MAAM,IAAI,SAAS,MAAM,SAAS,CAAC,KAAK,EAAE,EACzF,6BAA6B,CAC9B,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC;IACpE,CAAC,CAAC;AACJ,CAAC"}
package/lib/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export { checkPublishStatus } from './checkPublishStatus.js';
2
2
  export { deployChangedFiles, type DeployChangedFilesOptions, type DeployComponentFailure, type DeployChangedFilesResult, } from './deployChangedFiles.js';
3
3
  export { publishCommunity, DEFAULT_PUBLISH_REQUEST_TIMEOUT, type PublishCommunityOptions } from './publishCommunity.js';
4
4
  export { resolveSearchRoots, resolveRetrieveDestination, resolveSiteFile, resolveNetworkFile, } from './resolveSiteFiles.js';
5
+ export { queryNetworkByName, type NetworkRecord } from './queryNetworkByName.js';
5
6
  export { retrieveCustomSite } from './retrieveCustomSite.js';
6
7
  export { patchCustomSiteXml, type PatchCustomSiteXmlOptions, type PatchCustomSiteXmlResult, patchNetworkXml, readNetworkSiteName, } from './siteMetadataXml.js';
7
8
  export { verifyDomain, type DomainCheckStatus, type DomainCheckResult } from './verifyDomain.js';
package/lib/index.js CHANGED
@@ -23,6 +23,7 @@ export { checkPublishStatus } from './checkPublishStatus.js';
23
23
  export { deployChangedFiles, } from './deployChangedFiles.js';
24
24
  export { publishCommunity, DEFAULT_PUBLISH_REQUEST_TIMEOUT } from './publishCommunity.js';
25
25
  export { resolveSearchRoots, resolveRetrieveDestination, resolveSiteFile, resolveNetworkFile, } from './resolveSiteFiles.js';
26
+ export { queryNetworkByName } from './queryNetworkByName.js';
26
27
  export { retrieveCustomSite } from './retrieveCustomSite.js';
27
28
  export { patchCustomSiteXml, patchNetworkXml, readNetworkSiteName, } from './siteMetadataXml.js';
28
29
  export { verifyDomain } from './verifyDomain.js';
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,mGAAmG;AACnG,iGAAiG;AACjG,qGAAqG;AACrG,kGAAkG;AAClG,oGAAoG;AACpG,MAAM;AAEN,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EACL,kBAAkB,GAInB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,+BAA+B,EAAgC,MAAM,uBAAuB,CAAC;AACxH,OAAO,EACL,kBAAkB,EAClB,0BAA0B,EAC1B,eAAe,EACf,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EACL,kBAAkB,EAGlB,eAAe,EACf,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAkD,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,mGAAmG;AACnG,iGAAiG;AACjG,qGAAqG;AACrG,kGAAkG;AAClG,oGAAoG;AACpG,MAAM;AAEN,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EACL,kBAAkB,GAInB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,+BAA+B,EAAgC,MAAM,uBAAuB,CAAC;AACxH,OAAO,EACL,kBAAkB,EAClB,0BAA0B,EAC1B,eAAe,EACf,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAsB,MAAM,yBAAyB,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EACL,kBAAkB,EAGlB,eAAe,EACf,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAkD,MAAM,mBAAmB,CAAC"}
@@ -24,6 +24,11 @@ export type PublishCommunityOptions = {
24
24
  * real default.
25
25
  */
26
26
  requestTimeout?: Duration;
27
+ /**
28
+ * Called with the error whenever a status check fails while polling. Polling carries on regardless
29
+ * — a failed check counts as "not finished yet" — so this is how a caller surfaces it.
30
+ */
31
+ onPollError?: (error: unknown) => void;
27
32
  };
28
33
  /**
29
34
  * Trigger a community publish via the Connect REST API and poll until the job reaches a terminal
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import { Duration } from '@salesforce/kit';
17
17
  import { PollingClient } from '@salesforce/core';
18
- import { retryWithBackoff } from '@simplysf/simply-core';
18
+ import { boundedRequest } from './boundedRequest.js';
19
19
  import { checkPublishStatus } from './checkPublishStatus.js';
20
20
  import { DEFAULT_PUBLISH_REQUEST_TIMEOUT } from './requestTimeout.js';
21
21
  export { DEFAULT_PUBLISH_REQUEST_TIMEOUT } from './requestTimeout.js';
@@ -33,16 +33,13 @@ export { DEFAULT_PUBLISH_REQUEST_TIMEOUT } from './requestTimeout.js';
33
33
  */
34
34
  export async function publishCommunity(options) {
35
35
  const requestTimeout = options.requestTimeout ?? DEFAULT_PUBLISH_REQUEST_TIMEOUT;
36
- const publishResponse = await retryWithBackoff(async () => options.connection.request({
37
- method: 'POST',
38
- url: `/connect/communities/${options.networkId}/publish`,
39
- }), {
40
- retryAttempts: options.retryAttempts ?? 0,
41
- backoffFactor: options.retryBackoff ?? 2,
42
- attemptTimeout: requestTimeout,
43
- });
36
+ const publishResponse = await boundedRequest(options.connection,
37
+ // The endpoint takes no input, but the body must be set: jsforce streams a POST's body and only
38
+ // ends that stream when `body` is defined, so a bodyless POST is never actually sent — undici
39
+ // holds the request until the first body chunk. See docs/design/0044.
40
+ { method: 'POST', url: `/connect/communities/${options.networkId}/publish`, body: '{}' }, requestTimeout, { retryAttempts: options.retryAttempts ?? 0, backoffFactor: options.retryBackoff ?? 2 });
44
41
  const client = await PollingClient.create({
45
- poll: checkPublishStatus(options.connection, publishResponse.jobId, requestTimeout),
42
+ poll: checkPublishStatus(options.connection, publishResponse.jobId, requestTimeout, options.onPollError),
46
43
  frequency: Duration.seconds(15),
47
44
  timeout: Duration.minutes(options.wait),
48
45
  timeoutErrorName: 'CommunityPublishTimeoutError',
@@ -1 +1 @@
1
- {"version":3,"file":"publishCommunity.js","sourceRoot":"","sources":["../src/publishCommunity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAA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OAAO,eAAe,CAAC;AACzB,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { Duration } from '@salesforce/kit';
2
+ import { type Connection } from '@salesforce/core';
3
+ /** The `Network` fields needed to publish a community. */
4
+ export type NetworkRecord = {
5
+ Id: string;
6
+ Name: string;
7
+ };
8
+ /**
9
+ * Looks up a `Network` (Experience Cloud site) by name, bounded by `requestTimeout` with the request
10
+ * cancelled if it stalls. A drop-in for `connection.singleRecordQuery()`: it throws the same error
11
+ * names (`SingleRecordQuery_NoRecords`, `SingleRecordQuery_MultipleRecords`), which
12
+ * `@salesforce/core` doesn't export as values.
13
+ *
14
+ * @param connection - The org connection.
15
+ * @param name - The `Network.Name` to find.
16
+ * @param requestTimeout - Bounds the query. Defaults to {@link DEFAULT_PUBLISH_REQUEST_TIMEOUT}.
17
+ * @returns The matching record's `Id` and `Name`.
18
+ * @throws {SfError} `SingleRecordQuery_NoRecords` / `SingleRecordQuery_MultipleRecords` unless exactly one matches.
19
+ */
20
+ export declare function queryNetworkByName(connection: Connection, name: string, requestTimeout?: Duration): Promise<NetworkRecord>;
@@ -0,0 +1,44 @@
1
+ /*
2
+ * Copyright (c) 2026, SimplySF.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { SfError } from '@salesforce/core';
17
+ import { escapeSoqlLiteral } from '@simplysf/simply-core';
18
+ import { boundedQuery } from './boundedRequest.js';
19
+ import { DEFAULT_PUBLISH_REQUEST_TIMEOUT } from './requestTimeout.js';
20
+ /**
21
+ * Looks up a `Network` (Experience Cloud site) by name, bounded by `requestTimeout` with the request
22
+ * cancelled if it stalls. A drop-in for `connection.singleRecordQuery()`: it throws the same error
23
+ * names (`SingleRecordQuery_NoRecords`, `SingleRecordQuery_MultipleRecords`), which
24
+ * `@salesforce/core` doesn't export as values.
25
+ *
26
+ * @param connection - The org connection.
27
+ * @param name - The `Network.Name` to find.
28
+ * @param requestTimeout - Bounds the query. Defaults to {@link DEFAULT_PUBLISH_REQUEST_TIMEOUT}.
29
+ * @returns The matching record's `Id` and `Name`.
30
+ * @throws {SfError} `SingleRecordQuery_NoRecords` / `SingleRecordQuery_MultipleRecords` unless exactly one matches.
31
+ */
32
+ export async function queryNetworkByName(connection, name, requestTimeout = DEFAULT_PUBLISH_REQUEST_TIMEOUT) {
33
+ const soql = `SELECT Id, Name FROM Network WHERE Name = '${escapeSoqlLiteral(name)}'`;
34
+ const result = await boundedQuery(connection, soql, requestTimeout);
35
+ if (result.totalSize === 0) {
36
+ throw new SfError(`No record found for ${soql}`, 'SingleRecordQuery_NoRecords');
37
+ }
38
+ if (result.totalSize > 1) {
39
+ throw new SfError('The query returned more than 1 record', 'SingleRecordQuery_MultipleRecords');
40
+ }
41
+ const { Id, Name } = result.records[0];
42
+ return { Id, Name };
43
+ }
44
+ //# sourceMappingURL=queryNetworkByName.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryNetworkByName.js","sourceRoot":"","sources":["../src/queryNetworkByName.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,OAAO,EAAmB,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,+BAA+B,EAAE,MAAM,qBAAqB,CAAC;AAKtE;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,UAAsB,EACtB,IAAY,EACZ,iBAA2B,+BAA+B;IAE1D,MAAM,IAAI,GAAG,8CAA8C,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC;IACtF,MAAM,MAAM,GAAG,MAAM,YAAY,CAAgB,UAAU,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;IAEnF,IAAI,MAAM,CAAC,SAAS,KAAK,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,OAAO,CAAC,uBAAuB,IAAI,EAAE,EAAE,6BAA6B,CAAC,CAAC;IAClF,CAAC;IACD,IAAI,MAAM,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,OAAO,CAAC,uCAAuC,EAAE,mCAAmC,CAAC,CAAC;IAClG,CAAC;IAED,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACvC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AACtB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@simplysf/simply-community-core",
3
3
  "description": "Community publish/deploy/domain-verification logic and site-file discovery — the library layer behind @simplysf/simply-community, published separately for direct consumption (e.g. editor tooling, CI scripts) without the CLI framework",
4
- "version": "0.2.12",
4
+ "version": "0.2.13",
5
5
  "author": "@ClayChipps",
6
6
  "homepage": "https://github.com/SimplySF/simply-plugins-core",
7
7
  "bugs": "https://github.com/SimplySF/simply-plugins-core/issues",
@@ -135,5 +135,5 @@
135
135
  "output": []
136
136
  }
137
137
  },
138
- "gitHead": "e81556e7cf6efcc452b380848ff3cfd034f51d4c"
138
+ "gitHead": "b114a74df8e67d1ff3fa4b6ed07e85027f70eee9"
139
139
  }