@sortlist/cli 0.56.0 → 0.57.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.
- package/README.md +2 -2
- package/dist/index.js +22 -41
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -67,7 +67,7 @@ When the token expires, renewing needs your own login again — so this is a loc
|
|
|
67
67
|
|
|
68
68
|
## Acting for a company
|
|
69
69
|
|
|
70
|
-
A person can belong to several companies, and a subgraph that counts usage — Atlas records which contact details it hands out — needs to know which one a call is for. Every authenticated request carries that company as an `X-Company-Id` header, taken from `--company` or from `sl config set company`. Both take the company's slug or its GraphQL `id`, as `sl hermes companies` lists them; a slug costs one lookup per command, and a raw uuid is refused. The subgraph checks it against the companies your token lists and refuses the request outright when it names one you do not belong to. Without either,
|
|
70
|
+
A person can belong to several companies, and a subgraph that counts usage — Atlas records which contact details it hands out — needs to know which one a call is for. Every authenticated request carries that company as an `X-Company-Id` header, taken from `--company` or from `sl config set company`. Both take the company's slug or its GraphQL `id`, as `sl hermes companies` lists them; a slug costs one lookup per command, and a raw uuid is refused. The subgraph checks it against the companies your token lists and refuses the request outright when it names one you do not belong to. Without either, the request names your personal company, looked up once per command, staff elevation included, so that is where Atlas, Signals and Outreach count what you use. An application belongs to exactly one company, so acting as one needs no header.
|
|
71
71
|
|
|
72
72
|
```bash
|
|
73
73
|
sl config set company acme # for every command from now on
|
|
@@ -76,7 +76,7 @@ sl atlas find-contacts --company acme … # for one call
|
|
|
76
76
|
|
|
77
77
|
## Revealing contact details
|
|
78
78
|
|
|
79
|
-
Finding a contact shows only the reach details your company already owns — a name, an email, a phone, a LinkedIn profile each come back empty until revealed — and Atlas says so beside every row. Revealing is explicit, in the same command, with `--reveal`: a comma-separated list of dimensions named after what they unlock (`contactIdentity`, `contactEmailAddress`, `contactPhoneNumber`, `contactLinkedinUrl`, and `organization…` for organizations). Finding and revealing need no scope, only a company to act for
|
|
79
|
+
Finding a contact shows only the reach details your company already owns — a name, an email, a phone, a LinkedIn profile each come back empty until revealed — and Atlas says so beside every row. Revealing is explicit, in the same command, with `--reveal`: a comma-separated list of dimensions named after what they unlock (`contactIdentity`, `contactEmailAddress`, `contactPhoneNumber`, `contactLinkedinUrl`, and `organization…` for organizations). Finding and revealing need no scope, only a company to act for, which is your personal company unless you name another. Each reveal is charged to the company's credits. When you name a company, Atlas checks with Hermes first: you must still be a member of it, or the application must belong to it, otherwise the whole command is refused with a 403 and nothing is recorded — the token's claim was stamped at login and can outlive a membership.
|
|
80
80
|
|
|
81
81
|
```bash
|
|
82
82
|
sl atlas find-contacts --page '{"first":5}' --wait \
|
package/dist/index.js
CHANGED
|
@@ -701,7 +701,6 @@ function codeOf(errors) {
|
|
|
701
701
|
}
|
|
702
702
|
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
703
703
|
var CALLBACK_STATUS_NOT_OK = "SUBGRAPH_HTTP_CALLBACK_STATUS_CODE_NOT_OK";
|
|
704
|
-
var FORBIDDEN_COMPANY = "FORBIDDEN_COMPANY";
|
|
705
704
|
function subrequestStatus(errors) {
|
|
706
705
|
for (const { message, extensions } of errors) {
|
|
707
706
|
const http = extensions?.http;
|
|
@@ -777,12 +776,6 @@ function serviceOf(errors) {
|
|
|
777
776
|
}
|
|
778
777
|
return null;
|
|
779
778
|
}
|
|
780
|
-
function refusedForNamingNoCompany(errors, namedNoCompany) {
|
|
781
|
-
if (!namedNoCompany) return false;
|
|
782
|
-
const status = subrequestStatus(errors);
|
|
783
|
-
const maskedCallbackRefusal = status === null && codeOf(errors) === CALLBACK_STATUS_NOT_OK;
|
|
784
|
-
return status === 403 || maskedCallbackRefusal || codeOf(errors) === FORBIDDEN_COMPANY;
|
|
785
|
-
}
|
|
786
779
|
function hasResolvedField(data) {
|
|
787
780
|
if (data === null || data === void 0) return false;
|
|
788
781
|
return Object.values(data).some((value) => value !== null);
|
|
@@ -831,7 +824,7 @@ function reportGraphqlErrors(errors, options, attempt) {
|
|
|
831
824
|
const company = options.company ?? getUserContext().company ?? options.companyId;
|
|
832
825
|
if (options.actingForPersonalCompany) {
|
|
833
826
|
error(`${where} refused to act for your personal company.`);
|
|
834
|
-
hint("
|
|
827
|
+
hint("A request that names no company acts for it, and your token does not list it as yours.");
|
|
835
828
|
hint("On a local stack the token comes from a shared tenant and lists that environment's companies.");
|
|
836
829
|
hint("Pass --company <slug|id>, or `sl config set company <slug|id>`; `sl hermes companies` lists them.");
|
|
837
830
|
} else if (company && UUID.test(company)) {
|
|
@@ -892,17 +885,27 @@ function startAttempt(query, variables, options) {
|
|
|
892
885
|
}
|
|
893
886
|
async function requestHeaders(options, attempt) {
|
|
894
887
|
const headers = baseRequestHeaders();
|
|
895
|
-
if (!(options.authenticated ?? true)) return { headers,
|
|
888
|
+
if (!(options.authenticated ?? true)) return { headers, options };
|
|
896
889
|
const { token, kind } = await resolveAccessToken(options, attempt);
|
|
897
890
|
headers["Authorization"] = `Bearer ${token}`;
|
|
898
|
-
const companyId
|
|
891
|
+
const { companyId, personal: personal2 } = await actingCompany(options, kind, {
|
|
892
|
+
named: async () => options.companyId ?? await resolveCompanyId({ ctx: getUserContext() }),
|
|
893
|
+
personal: personalCompanyId
|
|
894
|
+
});
|
|
899
895
|
if (companyId) headers["X-Company-Id"] = companyId;
|
|
900
896
|
if (attempt.verbose) info(`[debug] ${kind} token: ...${token.slice(-8)}`);
|
|
901
|
-
return { headers,
|
|
897
|
+
return { headers, options: { ...options, actingForPersonalCompany: personal2 } };
|
|
898
|
+
}
|
|
899
|
+
async function actingCompany(options, kind, lookup) {
|
|
900
|
+
if (options.withoutCompany) return { companyId: void 0, personal: false };
|
|
901
|
+
const named = await lookup.named();
|
|
902
|
+
if (named || kind !== "user") return { companyId: named, personal: false };
|
|
903
|
+
const personal2 = await lookup.personal();
|
|
904
|
+
return { companyId: personal2, personal: personal2 !== void 0 };
|
|
902
905
|
}
|
|
903
906
|
async function executeQuery(query, variables, options = {}) {
|
|
904
907
|
const attempt = startAttempt(query, variables, options);
|
|
905
|
-
const { headers,
|
|
908
|
+
const { headers, options: sent } = await requestHeaders(options, attempt);
|
|
906
909
|
let res;
|
|
907
910
|
try {
|
|
908
911
|
res = await fetch(attempt.endpoint, {
|
|
@@ -920,14 +923,7 @@ async function executeQuery(query, variables, options = {}) {
|
|
|
920
923
|
if (!res.ok) reportHttpFailure(res, await res.text(), attempt);
|
|
921
924
|
const json = await res.json();
|
|
922
925
|
if (json.errors?.length) {
|
|
923
|
-
|
|
924
|
-
if (refused && refusedForNamingNoCompany(json.errors, namedNoCompany)) {
|
|
925
|
-
const personal2 = await personalCompanyId();
|
|
926
|
-
if (personal2) {
|
|
927
|
-
return executeQuery(query, variables, { ...options, companyId: personal2, actingForPersonalCompany: true });
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
if (refused) reportGraphqlErrors(json.errors, options, attempt);
|
|
926
|
+
if (!hasResolvedField(json.data)) reportGraphqlErrors(json.errors, sent, attempt);
|
|
931
927
|
for (const gqlError of json.errors) warn(gqlError.message);
|
|
932
928
|
if (hasFieldError(json.errors)) {
|
|
933
929
|
hint("Use --fields to select specific fields, or --exclude to skip broken ones.");
|
|
@@ -979,7 +975,7 @@ function parseEventBlock(block) {
|
|
|
979
975
|
return data.length > 0 || event !== "message" ? { event, data: data.join("\n") } : null;
|
|
980
976
|
}
|
|
981
977
|
async function openEventStream(query, variables, options, attempt) {
|
|
982
|
-
const { headers,
|
|
978
|
+
const { headers, options: sent } = await requestHeaders(options, attempt);
|
|
983
979
|
headers["Accept"] = "text/event-stream";
|
|
984
980
|
let res;
|
|
985
981
|
try {
|
|
@@ -999,10 +995,10 @@ async function openEventStream(query, variables, options, attempt) {
|
|
|
999
995
|
if (!res.ok) {
|
|
1000
996
|
const body = await res.text();
|
|
1001
997
|
const errors = parseErrors(body);
|
|
1002
|
-
if (errors) reportGraphqlErrors(errors,
|
|
998
|
+
if (errors) reportGraphqlErrors(errors, sent, attempt);
|
|
1003
999
|
reportHttpFailure(res, body, attempt);
|
|
1004
1000
|
}
|
|
1005
|
-
return { res,
|
|
1001
|
+
return { res, sent };
|
|
1006
1002
|
}
|
|
1007
1003
|
function parseErrors(body) {
|
|
1008
1004
|
try {
|
|
@@ -1012,25 +1008,13 @@ function parseErrors(body) {
|
|
|
1012
1008
|
return null;
|
|
1013
1009
|
}
|
|
1014
1010
|
}
|
|
1015
|
-
async function* subscriptionEvents(res,
|
|
1011
|
+
async function* subscriptionEvents(res, options, attempt) {
|
|
1016
1012
|
if (!res.body) return;
|
|
1017
1013
|
for await (const { event, data } of parseEventStream(res.body)) {
|
|
1018
1014
|
if (event === "complete") return;
|
|
1019
1015
|
if (event !== "next" && event !== "message") continue;
|
|
1020
1016
|
const payload = JSON.parse(data);
|
|
1021
1017
|
if (payload.errors?.length && !hasResolvedField(payload.data)) {
|
|
1022
|
-
if (refusedForNamingNoCompany(payload.errors, namedNoCompany)) {
|
|
1023
|
-
const personal2 = await personalCompanyId();
|
|
1024
|
-
if (personal2) {
|
|
1025
|
-
const retry = await graphqlSubscribe(query, variables, {
|
|
1026
|
-
...options,
|
|
1027
|
-
companyId: personal2,
|
|
1028
|
-
actingForPersonalCompany: true
|
|
1029
|
-
});
|
|
1030
|
-
yield* retry.events;
|
|
1031
|
-
return;
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
1018
|
reportGraphqlErrors(payload.errors, options, attempt);
|
|
1035
1019
|
}
|
|
1036
1020
|
for (const gqlError of payload.errors ?? []) warn(gqlError.message);
|
|
@@ -1039,8 +1023,8 @@ async function* subscriptionEvents(res, query, variables, options, attempt, name
|
|
|
1039
1023
|
}
|
|
1040
1024
|
async function graphqlSubscribe(query, variables, options = {}) {
|
|
1041
1025
|
const attempt = startAttempt(query, variables, options);
|
|
1042
|
-
const { res,
|
|
1043
|
-
return { events: subscriptionEvents(res,
|
|
1026
|
+
const { res, sent } = await openEventStream(query, variables, options, attempt);
|
|
1027
|
+
return { events: subscriptionEvents(res, sent, attempt) };
|
|
1044
1028
|
}
|
|
1045
1029
|
async function graphql(document, variables, options = {}) {
|
|
1046
1030
|
return executeQuery(print(document), variables, options);
|
|
@@ -1966,9 +1950,6 @@ function buildCommand(schema, fieldName, kind, description, service, resultSubsc
|
|
|
1966
1950
|
}
|
|
1967
1951
|
if (waiting && resultSubscription) {
|
|
1968
1952
|
const seconds = secondsOption(opts.wait, DEFAULT_WAIT_SECONDS, "--wait");
|
|
1969
|
-
if (!requestOptions.companyId && !actingAsApplication()) {
|
|
1970
|
-
requestOptions.companyId = await personalCompanyId();
|
|
1971
|
-
}
|
|
1972
1953
|
const externalId = opts.externalId;
|
|
1973
1954
|
const subscriptionVariables = { externalId };
|
|
1974
1955
|
if (selection.fields && !selection.fields.includes(PAGE_STATUS_FIELD) && deliversFillingPages(schema, resultSubscription)) {
|