@salesforce/plugin-devops-center 1.2.28 → 1.3.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.
@@ -0,0 +1,92 @@
1
+ import { Connection } from '@salesforce/core';
2
+ export type OrgType = 'Production' | 'Sandbox';
3
+ export declare const POLL_INTERVAL_MS = 3000;
4
+ export declare const POLL_TIMEOUT_MS: number;
5
+ export type AddStageEnvironmentParams = {
6
+ connection: Connection;
7
+ pipelineId: string;
8
+ stageId: string;
9
+ environmentName: string;
10
+ orgType: OrgType;
11
+ };
12
+ export type AddStageEnvironmentResult = {
13
+ success: boolean;
14
+ stageId: string;
15
+ environmentId?: string;
16
+ environmentName?: string;
17
+ orgType?: OrgType;
18
+ pipelineId?: string;
19
+ redirectUrl?: string;
20
+ namedCredential?: string;
21
+ organizationId?: string;
22
+ error?: string;
23
+ };
24
+ type EnvironmentCreateResponse = {
25
+ id: string;
26
+ name: string;
27
+ redirectUrl: string;
28
+ namedCredential: string;
29
+ externalCredential: string;
30
+ pipelineId?: string;
31
+ };
32
+ export type EnvironmentGetResponse = {
33
+ id: string;
34
+ name: string;
35
+ organizationId?: string;
36
+ orgType?: string;
37
+ namedCredential?: string;
38
+ redirectUrl?: string;
39
+ };
40
+ type EnvironmentValidateResponse = {
41
+ id: string;
42
+ name: string;
43
+ organizationId?: string;
44
+ orgType?: string;
45
+ namedCredential?: string;
46
+ };
47
+ /**
48
+ * Creates an environment and associates it with a pipeline stage via the Connect API.
49
+ * POST /services/data/v{version}/connect/devops/environment
50
+ */
51
+ export declare function createEnvironment(connection: Connection, params: {
52
+ pipelineId: string;
53
+ stageId: string;
54
+ environmentName: string;
55
+ orgType: OrgType;
56
+ }): Promise<EnvironmentCreateResponse>;
57
+ /**
58
+ * Fetches the current state of an environment.
59
+ * GET /services/data/v{version}/connect/devops/environment/{environmentId}
60
+ */
61
+ export declare function getEnvironment(connection: Connection, environmentId: string): Promise<EnvironmentGetResponse>;
62
+ /**
63
+ * Validates an authenticated environment by triggering server-side org extraction.
64
+ * PATCH /services/data/v{version}/connect/devops/environment/{environmentId}
65
+ */
66
+ export declare function validateEnvironment(connection: Connection, environmentId: string): Promise<EnvironmentValidateResponse>;
67
+ /**
68
+ * Polls until authentication is complete by attempting PATCH validation.
69
+ * The PATCH call triggers server-side org extraction; if the user has
70
+ * completed OAuth, it returns a response with organizationId populated.
71
+ * If auth isn't done yet, the PATCH throws — we catch and retry.
72
+ * Falls back to GET polling as a secondary check.
73
+ * Throws on timeout.
74
+ */
75
+ export declare function pollForAuthentication(connection: Connection, environmentId: string, timeoutMs?: number, intervalMs?: number): Promise<EnvironmentValidateResponse>;
76
+ /**
77
+ * Full orchestration: create environment -> poll for auth -> validate.
78
+ * Returns the final result including organizationId.
79
+ *
80
+ * The caller is responsible for opening the browser at the returned redirectUrl
81
+ * and displaying progress to the user. Use `onCreated` to receive the redirect URL
82
+ * before polling begins.
83
+ */
84
+ export declare function addStageEnvironment(params: AddStageEnvironmentParams & {
85
+ onCreated?: (data: {
86
+ environmentId: string;
87
+ redirectUrl: string;
88
+ }) => void;
89
+ pollTimeoutMs?: number;
90
+ pollIntervalMs?: number;
91
+ }): Promise<AddStageEnvironmentResult>;
92
+ export {};
@@ -0,0 +1,120 @@
1
+ /*
2
+ * Copyright 2026, Salesforce, Inc.
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
+ const ORG_TYPE_API_MAP = {
17
+ Production: 'PRODUCTION',
18
+ Sandbox: 'SANDBOX',
19
+ };
20
+ export const POLL_INTERVAL_MS = 3000;
21
+ export const POLL_TIMEOUT_MS = 5 * 60 * 1000;
22
+ /**
23
+ * Creates an environment and associates it with a pipeline stage via the Connect API.
24
+ * POST /services/data/v{version}/connect/devops/environment
25
+ */
26
+ export async function createEnvironment(connection, params) {
27
+ const path = `/services/data/v${connection.getApiVersion()}/connect/devops/environment`;
28
+ return connection.request({
29
+ method: 'POST',
30
+ url: path,
31
+ body: JSON.stringify({
32
+ envName: params.environmentName,
33
+ orgType: ORG_TYPE_API_MAP[params.orgType],
34
+ pipelineStageId: params.stageId,
35
+ pipelineId: params.pipelineId,
36
+ }),
37
+ headers: { 'Content-Type': 'application/json' },
38
+ });
39
+ }
40
+ /**
41
+ * Fetches the current state of an environment.
42
+ * GET /services/data/v{version}/connect/devops/environment/{environmentId}
43
+ */
44
+ export async function getEnvironment(connection, environmentId) {
45
+ const path = `/services/data/v${connection.getApiVersion()}/connect/devops/environment/${environmentId}`;
46
+ return connection.request({ method: 'GET', url: path });
47
+ }
48
+ /**
49
+ * Validates an authenticated environment by triggering server-side org extraction.
50
+ * PATCH /services/data/v{version}/connect/devops/environment/{environmentId}
51
+ */
52
+ export async function validateEnvironment(connection, environmentId) {
53
+ const path = `/services/data/v${connection.getApiVersion()}/connect/devops/environment/${environmentId}`;
54
+ return connection.request({
55
+ method: 'PATCH',
56
+ url: path,
57
+ body: JSON.stringify({}),
58
+ headers: { 'Content-Type': 'application/json' },
59
+ });
60
+ }
61
+ function sleep(ms) {
62
+ return new Promise((resolve) => {
63
+ setTimeout(resolve, ms);
64
+ });
65
+ }
66
+ /**
67
+ * Polls until authentication is complete by attempting PATCH validation.
68
+ * The PATCH call triggers server-side org extraction; if the user has
69
+ * completed OAuth, it returns a response with organizationId populated.
70
+ * If auth isn't done yet, the PATCH throws — we catch and retry.
71
+ * Falls back to GET polling as a secondary check.
72
+ * Throws on timeout.
73
+ */
74
+ // eslint-disable-next-line no-await-in-loop -- polling requires sequential awaits by design
75
+ export async function pollForAuthentication(connection, environmentId, timeoutMs = POLL_TIMEOUT_MS, intervalMs = POLL_INTERVAL_MS) {
76
+ const deadline = Date.now() + timeoutMs;
77
+ while (Date.now() < deadline) {
78
+ try {
79
+ // eslint-disable-next-line no-await-in-loop
80
+ const validated = await validateEnvironment(connection, environmentId);
81
+ if (validated.organizationId) {
82
+ return validated;
83
+ }
84
+ }
85
+ catch {
86
+ // PATCH failed — auth likely not yet complete, continue polling
87
+ }
88
+ // eslint-disable-next-line no-await-in-loop
89
+ await sleep(intervalMs);
90
+ }
91
+ throw new Error(`Authentication timed out after ${timeoutMs / 1000} seconds. Re-run the command or authenticate manually.`);
92
+ }
93
+ /**
94
+ * Full orchestration: create environment -> poll for auth -> validate.
95
+ * Returns the final result including organizationId.
96
+ *
97
+ * The caller is responsible for opening the browser at the returned redirectUrl
98
+ * and displaying progress to the user. Use `onCreated` to receive the redirect URL
99
+ * before polling begins.
100
+ */
101
+ export async function addStageEnvironment(params) {
102
+ const { connection, pipelineId, stageId, environmentName, orgType, onCreated, pollTimeoutMs, pollIntervalMs } = params;
103
+ const createData = await createEnvironment(connection, { pipelineId, stageId, environmentName, orgType });
104
+ if (onCreated) {
105
+ onCreated({ environmentId: createData.id, redirectUrl: createData.redirectUrl });
106
+ }
107
+ const validated = await pollForAuthentication(connection, createData.id, pollTimeoutMs, pollIntervalMs);
108
+ return {
109
+ success: true,
110
+ stageId,
111
+ environmentId: createData.id,
112
+ environmentName: createData.name,
113
+ orgType,
114
+ pipelineId,
115
+ redirectUrl: createData.redirectUrl,
116
+ namedCredential: createData.namedCredential ?? validated.namedCredential,
117
+ organizationId: validated.organizationId,
118
+ };
119
+ }
120
+ //# sourceMappingURL=addStageEnvironment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addStageEnvironment.js","sourceRoot":"","sources":["../../src/utils/addStageEnvironment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,MAAM,gBAAgB,GAA4B;IAChD,UAAU,EAAE,YAAY;IACxB,OAAO,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E,OAAO,EAAE,CAAC,CAAC;IAE1G,IAAI,SAAS,EAAE,CAAC;QACd,SAAS,CAAC,EAAE,aAAa,EAAE,UAAU,CAAC,EAAE,EAAE,WAAW,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;IACnF,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,qBAAqB,CAAC,UAAU,EAAE,UAAU,CAAC,EAAE,EAAE,aAAa,EAAE,cAAc,CAAC,CAAC;IAExG,OAAO;QACL,OAAO,EAAE,IAAI;QACb,OAAO;QACP,aAAa,EAAE,UAAU,CAAC,EAAE;QAC5B,eAAe,EAAE,UAAU,CAAC,IAAI;QAChC,OAAO;QACP,UAAU;QACV,WAAW,EAAE,UAAU,CAAC,WAAW;QACnC,eAAe,EAAE,UAAU,CAAC,eAAe,IAAI,SAAS,CAAC,eAAe;QACxE,cAAc,EAAE,SAAS,CAAC,cAAc;KACzC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,46 @@
1
+ # summary
2
+
3
+ Add a source code repository branch to a pipeline stage.
4
+
5
+ # description
6
+
7
+ By default, the branch must exist in the repository. Use --create-vcs-branch to create a branch if it doesn't exist.
8
+ Each pipeline stage supports only one branch. Adding a branch replaces any existing branch linked to the pipeline stage.
9
+
10
+ # flags.pipeline-id.summary
11
+
12
+ ID of the pipeline that contains the stage.
13
+
14
+ # flags.stage-id.summary
15
+
16
+ ID of the pipeline stage to associate the branch with.
17
+
18
+ # flags.branch-name.summary
19
+
20
+ Name of the repository branch to assign to the stage.
21
+
22
+ # flags.create-vcs-branch.summary
23
+
24
+ Create the branch in the remote repository if it doesn't already exist.
25
+
26
+ # examples
27
+
28
+ - Add an existing branch to a stage:
29
+
30
+ <%= config.bin %> <%= command.id %> --target-org my-devops-org --pipeline-id 0Xo000000000001 --stage-id 0Xp000000000001 --branch-name main
31
+
32
+ - Create and add a branch to a pipeline stage:
33
+
34
+ <%= config.bin %> <%= command.id %> --target-org my-devops-org --pipeline-id 0Xo000000000001 --stage-id 0Xp000000000002 --branch-name integration --create-vcs-branch
35
+
36
+ # error.StageNotFound
37
+
38
+ Pipeline stage "%s" doesn't exist in pipeline "%s". Check the stage ID and try again.
39
+
40
+ # error.NextStageNoBranch
41
+
42
+ You must set up a branch on stage "%s" before configuring stage "%s". Branches must be configured from right to left (starting from the last stage in the pipeline).
43
+
44
+ # error.BranchAttachFailed
45
+
46
+ Failed to associate branch with stage: %s
@@ -0,0 +1,61 @@
1
+ # summary
2
+
3
+ Add a Salesforce environment to a pipeline stage.
4
+
5
+ # description
6
+
7
+ This command triggers an OAuth flow to authenticate the environment. A browser window opens automatically for you to log in.
8
+
9
+ # flags.pipeline-id.summary
10
+
11
+ ID of the pipeline that contains the stage.
12
+
13
+ # flags.stage-id.summary
14
+
15
+ ID of the pipeline stage.
16
+
17
+ # flags.environment-name.summary
18
+
19
+ Name of the environment.
20
+
21
+ # flags.org-type.summary
22
+
23
+ Type of the Salesforce org. Valid values: Production, Sandbox.
24
+
25
+ # flags.no-browser.summary
26
+
27
+ Don't auto-open the browser for OAuth authentication. The redirect URL is printed for manual use.
28
+
29
+ # examples
30
+
31
+ - Add a production environment to a stage using its ID:
32
+
33
+ <%= config.bin %> <%= command.id %> --target-org my-devops-org --stage-id 0Xp000000000001 --environment-name Production_Org --org-type Production
34
+
35
+ # info.BrowserOpened
36
+
37
+ A browser window has been opened for authentication. Log in to the target org to complete the setup.
38
+
39
+ # info.ManualAuth
40
+
41
+ Open the following URL in your browser to authenticate the environment:\n%s
42
+
43
+ # info.WaitingForAuth
44
+
45
+ Waiting for authentication to complete...
46
+
47
+ # info.Success
48
+
49
+ Successfully added environment to the stage.
50
+
51
+ # error.StageNotFound
52
+
53
+ Pipeline stage "%s" doesn't exist in pipeline "%s". Check the stage ID and try again.
54
+
55
+ # error.EnvironmentAttachFailed
56
+
57
+ Failed to create environment for stage: %s
58
+
59
+ # error.AuthTimeout
60
+
61
+ Authentication timed out. The environment was created but not yet authenticated. Re-run the command or authenticate manually via the org's DevOps Center setup.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@salesforce/plugin-devops-center",
3
- "version": "1.2.28",
3
+ "version": "1.3.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@salesforce/plugin-devops-center",
9
- "version": "1.2.28",
9
+ "version": "1.3.0",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "@jsforce/jsforce-node": "^3",