@lead-routing/cli 0.1.1 → 0.1.2

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.js CHANGED
@@ -1050,18 +1050,26 @@ async function sfdcDeployInline(params) {
1050
1050
  { reject: false }
1051
1051
  );
1052
1052
  const alreadyAuthed = authCheck === 0;
1053
+ let sfCredEnv = {};
1054
+ let targetOrgArgs = ["--target-org", orgAlias];
1053
1055
  if (alreadyAuthed) {
1054
1056
  log6.success("Using existing Salesforce authentication");
1055
1057
  } else {
1056
- await loginViaAppBridge(appUrl, orgAlias);
1058
+ const { accessToken, instanceUrl, aliasStored } = await loginViaAppBridge(appUrl, orgAlias);
1059
+ sfCredEnv = { SF_ACCESS_TOKEN: accessToken, SF_ORG_INSTANCE_URL: instanceUrl };
1060
+ if (!aliasStored) {
1061
+ targetOrgArgs = [];
1062
+ }
1057
1063
  }
1058
1064
  s.start("Copying Salesforce package\u2026");
1059
- const bundledPkg = join5(__dirname2, "..", "sfdc-package");
1065
+ const inDist = join5(__dirname2, "sfdc-package");
1066
+ const nextToDist = join5(__dirname2, "..", "sfdc-package");
1067
+ const bundledPkg = existsSync4(inDist) ? inDist : nextToDist;
1060
1068
  const destPkg = join5(installDir ?? tmpdir(), "lead-routing-sfdc-package");
1061
1069
  if (!existsSync4(bundledPkg)) {
1062
1070
  s.stop("sfdc-package not found in CLI bundle");
1063
1071
  throw new Error(
1064
- `Expected bundle at: ${bundledPkg}
1072
+ `Expected bundle at: ${inDist}
1065
1073
  The CLI may need to be reinstalled: npm i -g @lead-routing/cli`
1066
1074
  );
1067
1075
  }
@@ -1111,8 +1119,8 @@ The CLI may need to be reinstalled: npm i -g @lead-routing/cli`
1111
1119
  try {
1112
1120
  await execa3(
1113
1121
  "sf",
1114
- ["project", "deploy", "start", "--target-org", orgAlias, "--source-dir", "force-app"],
1115
- { cwd: destPkg, stdio: "inherit" }
1122
+ ["project", "deploy", "start", ...targetOrgArgs, "--source-dir", "force-app"],
1123
+ { cwd: destPkg, stdio: "inherit", env: { ...process.env, ...sfCredEnv } }
1116
1124
  );
1117
1125
  s.stop("Package deployed");
1118
1126
  } catch (err) {
@@ -1129,8 +1137,8 @@ The CLI may need to be reinstalled: npm i -g @lead-routing/cli`
1129
1137
  try {
1130
1138
  await execa3(
1131
1139
  "sf",
1132
- ["org", "assign", "permset", "--name", "LeadRouterAdmin", "--target-org", orgAlias],
1133
- { stdio: "inherit" }
1140
+ ["org", "assign", "permset", "--name", "LeadRouterAdmin", ...targetOrgArgs],
1141
+ { stdio: "inherit", env: { ...process.env, ...sfCredEnv } }
1134
1142
  );
1135
1143
  s.stop("Permission set assigned \u2014 Lead Router Setup will appear in the App Launcher");
1136
1144
  } catch (err) {
@@ -1152,12 +1160,11 @@ The CLI may need to be reinstalled: npm i -g @lead-routing/cli`
1152
1160
  const qr = await execa3("sf", [
1153
1161
  "data",
1154
1162
  "query",
1155
- "--target-org",
1156
- orgAlias,
1163
+ ...targetOrgArgs,
1157
1164
  "--query",
1158
1165
  "SELECT Id FROM Routing_Settings__c LIMIT 1",
1159
1166
  "--json"
1160
- ]);
1167
+ ], { env: { ...process.env, ...sfCredEnv } });
1161
1168
  const parsed = JSON.parse(qr.stdout);
1162
1169
  existingId = parsed?.result?.records?.[0]?.Id;
1163
1170
  } catch {
@@ -1167,27 +1174,25 @@ The CLI may need to be reinstalled: npm i -g @lead-routing/cli`
1167
1174
  "data",
1168
1175
  "update",
1169
1176
  "record",
1170
- "--target-org",
1171
- orgAlias,
1177
+ ...targetOrgArgs,
1172
1178
  "--sobject",
1173
1179
  "Routing_Settings__c",
1174
1180
  "--record-id",
1175
1181
  existingId,
1176
1182
  "--values",
1177
1183
  `App_Url__c='${appUrl}' Engine_Endpoint__c='${engineUrl}'`
1178
- ], { stdio: "inherit" });
1184
+ ], { stdio: "inherit", env: { ...process.env, ...sfCredEnv } });
1179
1185
  } else {
1180
1186
  await execa3("sf", [
1181
1187
  "data",
1182
1188
  "create",
1183
1189
  "record",
1184
- "--target-org",
1185
- orgAlias,
1190
+ ...targetOrgArgs,
1186
1191
  "--sobject",
1187
1192
  "Routing_Settings__c",
1188
1193
  "--values",
1189
1194
  `App_Url__c='${appUrl}' Engine_Endpoint__c='${engineUrl}'`
1190
- ], { stdio: "inherit" });
1195
+ ], { stdio: "inherit", env: { ...process.env, ...sfCredEnv } });
1191
1196
  }
1192
1197
  s.stop("Org settings written");
1193
1198
  } catch (err) {
@@ -1259,17 +1264,20 @@ Ensure the app is running and the URL is correct.`
1259
1264
  );
1260
1265
  }
1261
1266
  s.stop("Authenticated with Salesforce");
1267
+ let aliasStored = false;
1262
1268
  try {
1263
1269
  await execa3(
1264
1270
  "sf",
1265
1271
  ["org", "login", "access-token", "--instance-url", instanceUrl, "--alias", orgAlias, "--no-prompt"],
1266
- { input: accessToken + "\n" }
1272
+ { env: { ...process.env, SFDX_ACCESS_TOKEN: accessToken } }
1267
1273
  );
1268
1274
  log6.success(`Salesforce org saved as "${orgAlias}"`);
1275
+ aliasStored = true;
1269
1276
  } catch (err) {
1270
- log6.warn(`Could not store sf CLI credentials: ${String(err)}`);
1271
- log6.info("Re-authenticate manually if deploy commands fail: sf org login web");
1277
+ log6.warn(`Could not persist sf CLI credentials: ${String(err)}`);
1278
+ log6.info("Continuing with direct token auth for this session.");
1272
1279
  }
1280
+ return { accessToken, instanceUrl, aliasStored };
1273
1281
  }
1274
1282
 
1275
1283
  // src/steps/app-launcher-guide.ts
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <RemoteSiteSetting xmlns="http://soap.sforce.com/2006/04/metadata">
3
+ <description>Lead Router App URL — patched by lead-routing sfdc deploy</description>
4
+ <disableProtocolSecurity>false</disableProtocolSecurity>
5
+ <isActive>true</isActive>
6
+ <url>https://app.example.com</url>
7
+ </RemoteSiteSetting>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lead-routing/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Self-hosted deployment CLI for Lead Routing",
5
5
  "homepage": "https://github.com/lead-routing/lead-routing",
6
6
  "keywords": ["salesforce", "lead-routing", "self-hosted", "deployment", "cli"],