@cerios/salesforce-sobjectly 1.0.0 → 1.2.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 +21 -13
- package/dist/cli.cjs +4 -4
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +5 -4
- package/dist/cli.mjs.map +1 -1
- package/dist/{codegen-CSx0WAtK.mjs → codegen-0L2ebG9j.mjs} +410 -117
- package/dist/codegen-0L2ebG9j.mjs.map +1 -0
- package/dist/{codegen-BgDgU2RR.cjs → codegen-Daud-Grz.cjs} +419 -112
- package/dist/codegen-Daud-Grz.cjs.map +1 -0
- package/dist/codegen.cjs +3 -1
- package/dist/codegen.d.cts +117 -35
- package/dist/codegen.d.mts +117 -35
- package/dist/codegen.mjs +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +15 -4
- package/dist/index.d.mts +15 -4
- package/dist/index.mjs +1 -1
- package/dist/{sf-cli-CtWtdkJ0.mjs → sf-cli-D2PgjErx.mjs} +40 -17
- package/dist/sf-cli-D2PgjErx.mjs.map +1 -0
- package/dist/{sf-cli-DEVZQTR7.cjs → sf-cli-S2BrCbik.cjs} +40 -17
- package/dist/sf-cli-S2BrCbik.cjs.map +1 -0
- package/package.json +1 -1
- package/sobjectly.config.schema.json +94 -18
- package/dist/codegen-BgDgU2RR.cjs.map +0 -1
- package/dist/codegen-CSx0WAtK.mjs.map +0 -1
- package/dist/sf-cli-CtWtdkJ0.mjs.map +0 -1
- package/dist/sf-cli-DEVZQTR7.cjs.map +0 -1
package/dist/codegen.d.mts
CHANGED
|
@@ -1,52 +1,101 @@
|
|
|
1
1
|
import { E as AuthProvider, O as HttpTransport, a as FieldDescribe, c as RecordTypeInfo, t as ChildRelationship, u as ApiVersion } from "./describe-Dj3J8o-x.mjs";
|
|
2
2
|
//#region src/codegen/config.d.ts
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* A credential value in the config: usually `process.env.ANY_NAME` (so `undefined` type-checks),
|
|
5
|
+
* a `"${ANY_NAME}"` placeholder that is read from the environment (the way to do it in JSON), or
|
|
6
|
+
* a literal. A key that is set but ends up empty is an error; a key that is left out falls back
|
|
7
|
+
* to its default `SF_*` environment variable.
|
|
8
|
+
*/
|
|
9
|
+
type ConfigValue = string | undefined;
|
|
10
|
+
/** OAuth 2.0 client credentials. Keys you leave out are read from the default variables shown. */
|
|
11
|
+
interface ClientCredentialsAuth {
|
|
5
12
|
type: "clientCredentials";
|
|
6
|
-
/** Defaults to `SF_LOGIN_URL`
|
|
13
|
+
/** Your My Domain URL. Defaults to the `SF_LOGIN_URL` variable. */
|
|
14
|
+
loginUrl?: ConfigValue;
|
|
15
|
+
/** Defaults to the `SF_CLIENT_ID` variable. */
|
|
16
|
+
clientId?: ConfigValue;
|
|
17
|
+
/** Defaults to the `SF_CLIENT_SECRET` variable. */
|
|
18
|
+
clientSecret?: ConfigValue;
|
|
19
|
+
/** @deprecated Use `loginUrl: process.env.NAME` (or `"${NAME}"` in JSON). Removed in 2.0. */
|
|
7
20
|
loginUrlEnv?: string;
|
|
8
|
-
/**
|
|
21
|
+
/** @deprecated Use `clientId: process.env.NAME` (or `"${NAME}"` in JSON). Removed in 2.0. */
|
|
9
22
|
clientIdEnv?: string;
|
|
10
|
-
/**
|
|
23
|
+
/** @deprecated Use `clientSecret: process.env.NAME` (or `"${NAME}"` in JSON). Removed in 2.0. */
|
|
11
24
|
clientSecretEnv?: string;
|
|
12
25
|
}
|
|
13
|
-
/**
|
|
14
|
-
interface
|
|
26
|
+
/** A fixed access token, e.g. from `sf org display`. Keys you leave out are read from the default variables shown. */
|
|
27
|
+
interface AccessTokenAuth {
|
|
15
28
|
type: "accessToken";
|
|
16
|
-
/** Defaults to `SF_ACCESS_TOKEN
|
|
29
|
+
/** Defaults to the `SF_ACCESS_TOKEN` variable. */
|
|
30
|
+
accessToken?: ConfigValue;
|
|
31
|
+
/** Defaults to the `SF_INSTANCE_URL` variable. */
|
|
32
|
+
instanceUrl?: ConfigValue;
|
|
33
|
+
/** @deprecated Use `accessToken: process.env.NAME` (or `"${NAME}"` in JSON). Removed in 2.0. */
|
|
17
34
|
accessTokenEnv?: string;
|
|
18
|
-
/**
|
|
35
|
+
/** @deprecated Use `instanceUrl: process.env.NAME` (or `"${NAME}"` in JSON). Removed in 2.0. */
|
|
19
36
|
instanceUrlEnv?: string;
|
|
20
37
|
}
|
|
21
|
-
/** JWT bearer flow
|
|
22
|
-
interface
|
|
38
|
+
/** OAuth 2.0 JWT bearer flow. Keys you leave out are read from the default variables shown. */
|
|
39
|
+
interface JwtBearerAuth {
|
|
23
40
|
type: "jwtBearer";
|
|
24
|
-
/** Defaults to `SF_LOGIN_URL
|
|
41
|
+
/** Defaults to the `SF_LOGIN_URL` variable. */
|
|
42
|
+
loginUrl?: ConfigValue;
|
|
43
|
+
/** Defaults to the `SF_CLIENT_ID` variable. */
|
|
44
|
+
clientId?: ConfigValue;
|
|
45
|
+
/** Defaults to the `SF_USERNAME` variable. */
|
|
46
|
+
username?: ConfigValue;
|
|
47
|
+
/** The PEM key itself. Defaults to the `SF_PRIVATE_KEY` variable. */
|
|
48
|
+
privateKey?: ConfigValue;
|
|
49
|
+
/** A path to the PEM key file, used when `privateKey` is empty. Defaults to the `SF_PRIVATE_KEY_PATH` variable. */
|
|
50
|
+
privateKeyPath?: ConfigValue;
|
|
51
|
+
/** @deprecated Use `loginUrl: process.env.NAME` (or `"${NAME}"` in JSON). Removed in 2.0. */
|
|
25
52
|
loginUrlEnv?: string;
|
|
26
|
-
/**
|
|
53
|
+
/** @deprecated Use `clientId: process.env.NAME` (or `"${NAME}"` in JSON). Removed in 2.0. */
|
|
27
54
|
clientIdEnv?: string;
|
|
28
|
-
/**
|
|
55
|
+
/** @deprecated Use `username: process.env.NAME` (or `"${NAME}"` in JSON). Removed in 2.0. */
|
|
29
56
|
usernameEnv?: string;
|
|
30
|
-
/**
|
|
57
|
+
/** @deprecated Use `privateKey: process.env.NAME` (or `"${NAME}"` in JSON). Removed in 2.0. */
|
|
31
58
|
privateKeyEnv?: string;
|
|
32
|
-
/**
|
|
59
|
+
/** @deprecated Use `privateKeyPath: process.env.NAME` (or `"${NAME}"` in JSON). Removed in 2.0. */
|
|
33
60
|
privateKeyPathEnv?: string;
|
|
34
61
|
}
|
|
35
|
-
/** An auth setting that reads credentials from environment variables. The only kind a JSON config can use. */
|
|
36
62
|
/** An org you are logged into with the Salesforce CLI (`sf org login web --alias my-org`). */
|
|
37
63
|
interface SfCliAuth {
|
|
38
64
|
type: "sfCli";
|
|
39
|
-
/**
|
|
40
|
-
|
|
65
|
+
/**
|
|
66
|
+
* The org alias or username, e.g. `process.env.NAME` or a `"${NAME}"` placeholder. Left out, the
|
|
67
|
+
* CLI's default org is used (the CLI's own `SF_TARGET_ORG` variable can set it). Set but empty is an error.
|
|
68
|
+
*/
|
|
69
|
+
targetOrg?: ConfigValue;
|
|
41
70
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
71
|
+
/** An auth setting that can be written as data. The only kind a JSON config can use. */
|
|
72
|
+
type AuthSetting = ClientCredentialsAuth | AccessTokenAuth | JwtBearerAuth | SfCliAuth;
|
|
73
|
+
/** @deprecated Use `ClientCredentialsAuth`. */
|
|
74
|
+
type EnvClientCredentialsAuth = ClientCredentialsAuth;
|
|
75
|
+
/** @deprecated Use `AccessTokenAuth`. */
|
|
76
|
+
type EnvAccessTokenAuth = AccessTokenAuth;
|
|
77
|
+
/** @deprecated Use `JwtBearerAuth`. */
|
|
78
|
+
type EnvJwtBearerAuth = JwtBearerAuth;
|
|
79
|
+
/** @deprecated Use `AuthSetting`. */
|
|
80
|
+
type EnvAuth = AuthSetting;
|
|
81
|
+
/** An auth setting, or any auth provider (TypeScript configs only). */
|
|
82
|
+
type CodegenAuth = AuthSetting | AuthProvider;
|
|
45
83
|
type PicklistMode =
|
|
46
84
|
/** Every picklist is `string`. */
|
|
47
85
|
"string" |
|
|
48
86
|
/** Restricted picklists become a union of their values; unrestricted ones `"A" | "B" | (string & {})`. */
|
|
49
|
-
"union"
|
|
87
|
+
"union" |
|
|
88
|
+
/**
|
|
89
|
+
* Like `"union"`, plus a named `as const` object and type per picklist: `CaseStatus.Working`,
|
|
90
|
+
* `Status: CaseStatus`. Plain strings such as `"Working"` are still accepted.
|
|
91
|
+
*/
|
|
92
|
+
"const" |
|
|
93
|
+
/**
|
|
94
|
+
* A TypeScript `enum` per picklist: `CaseStatus.Working`, `Status: CaseStatus`. Enums are nominal,
|
|
95
|
+
* so restricted picklists only accept enum members, not plain strings. Not usable with
|
|
96
|
+
* `erasableSyntaxOnly` or Node's type stripping.
|
|
97
|
+
*/
|
|
98
|
+
"enum";
|
|
50
99
|
/**
|
|
51
100
|
* The codegen config. `S` is the union of the listed sObject names; `defineConfig` infers it, so
|
|
52
101
|
* per-sObject options such as `excludeCreateFields` only accept listed names.
|
|
@@ -66,7 +115,10 @@ interface CodegenConfig<S extends string = string> {
|
|
|
66
115
|
sobjects?: readonly S[];
|
|
67
116
|
/** sObjects to skip (applied after `sobjects`). */
|
|
68
117
|
exclude?: readonly string[];
|
|
69
|
-
/**
|
|
118
|
+
/**
|
|
119
|
+
* How to authenticate, e.g. `{ type: "clientCredentials", clientId: process.env.MY_CLIENT_ID, ... }`.
|
|
120
|
+
* Defaults to client credentials from `SF_LOGIN_URL`, `SF_CLIENT_ID` and `SF_CLIENT_SECRET`.
|
|
121
|
+
*/
|
|
70
122
|
auth?: CodegenAuth;
|
|
71
123
|
/** Fields to leave out of the create input per sObject (e.g. fields describe marks createable but REST rejects). */
|
|
72
124
|
excludeCreateFields?: Partial<Record<NoInfer<S>, readonly string[]>>;
|
|
@@ -93,7 +145,7 @@ interface CodegenConfig<S extends string = string> {
|
|
|
93
145
|
*/
|
|
94
146
|
type JsonCodegenConfig = Omit<CodegenConfig, "auth" | "format" | "transport"> & {
|
|
95
147
|
$schema?: string;
|
|
96
|
-
auth?:
|
|
148
|
+
auth?: AuthSetting;
|
|
97
149
|
};
|
|
98
150
|
/**
|
|
99
151
|
* Type-checks a `sobjectly.config.ts`. The listed `sobjects` become a literal union, so a typo in
|
|
@@ -115,8 +167,11 @@ export declare function defineConfig<const S extends string = string>(config: Co
|
|
|
115
167
|
type CodegenField = Pick<FieldDescribe, "name" | "label" | "type" | "nillable" | "createable" | "updateable" | "defaultedOnCreate" | "referenceTo" | "relationshipName"> & Partial<Pick<FieldDescribe, "picklistValues" | "restrictedPicklist" | "externalId" | "idLookup">>;
|
|
116
168
|
/** Maps each Salesforce field type to a TypeScript type. Types not listed become `unknown`. */
|
|
117
169
|
export declare const FIELD_TYPE_MAP: Readonly<Record<string, string>>;
|
|
118
|
-
/**
|
|
119
|
-
|
|
170
|
+
/**
|
|
171
|
+
* Returns the TypeScript type for a field, including `| null` for nillable fields. With picklist
|
|
172
|
+
* mode `"const"` or `"enum"`, `typeName` is the field's named picklist type; it replaces the union.
|
|
173
|
+
*/
|
|
174
|
+
export declare function mapFieldType(field: CodegenField, picklists?: PicklistMode, typeName?: string): string;
|
|
120
175
|
//#endregion
|
|
121
176
|
//#region src/codegen/generator.d.ts
|
|
122
177
|
/** The subset of an sObject describe the generator needs. */
|
|
@@ -139,7 +194,8 @@ interface GenerateSourceOptions {
|
|
|
139
194
|
}
|
|
140
195
|
/**
|
|
141
196
|
* Generates the TypeScript source for a set of sObject describes: a read interface, create
|
|
142
|
-
* and update input types per sObject, and the `SObjectRegistry` that ties them together.
|
|
197
|
+
* and update input types per sObject, and the `SObjectRegistry` that ties them together. With
|
|
198
|
+
* picklist mode `"const"` or `"enum"`, each picklist also gets a named type before its sObject.
|
|
143
199
|
* The output is deterministic: sObjects are sorted by name and fields by name (`Id` first).
|
|
144
200
|
*/
|
|
145
201
|
export declare function generateSource(describes: readonly CodegenDescribe[], options?: GenerateSourceOptions): string;
|
|
@@ -177,8 +233,10 @@ export declare class CodegenConfigError extends Error {
|
|
|
177
233
|
readonly name: string;
|
|
178
234
|
constructor(source: string, problems: string[]);
|
|
179
235
|
}
|
|
180
|
-
/** The
|
|
181
|
-
export declare const AUTH_OPTIONS: Record<
|
|
236
|
+
/** The options each auth type accepts: its credential keys, then the deprecated `*Env` keys. */
|
|
237
|
+
export declare const AUTH_OPTIONS: Record<AuthSetting["type"], readonly string[]>;
|
|
238
|
+
/** The deprecated `*Env` auth options, each mapped to the credential key that replaces it. */
|
|
239
|
+
export declare const DEPRECATED_AUTH_OPTIONS: Readonly<Record<string, string>>;
|
|
182
240
|
/** The options a config may contain. */
|
|
183
241
|
export declare const CONFIG_OPTIONS: readonly string[];
|
|
184
242
|
/**
|
|
@@ -246,7 +304,7 @@ interface InitResult {
|
|
|
246
304
|
envExampleUpdated?: boolean;
|
|
247
305
|
scriptAdded?: boolean;
|
|
248
306
|
}
|
|
249
|
-
/** The environment variables
|
|
307
|
+
/** The environment variables the config written by `init` reads, per auth type. */
|
|
250
308
|
export declare const AUTH_ENV_VARS: Record<InitAuthType, string[]>;
|
|
251
309
|
/**
|
|
252
310
|
* Creates a `sobjectly.config` file by asking for the API version, output path, sObjects, auth
|
|
@@ -268,7 +326,7 @@ export interface GenerateOptions {
|
|
|
268
326
|
/** Directory that `output` is resolved against. Defaults to `process.cwd()`. */
|
|
269
327
|
cwd?: string;
|
|
270
328
|
logger?: CodegenLogger;
|
|
271
|
-
/**
|
|
329
|
+
/** Where `"${NAME}"` placeholders and the default `SF_*` variables are read from. Defaults to `process.env`. */
|
|
272
330
|
env?: Record<string, string | undefined>;
|
|
273
331
|
/** Write the file. Defaults to `true`; with `false` the source is only returned. */
|
|
274
332
|
write?: boolean;
|
|
@@ -305,8 +363,32 @@ export declare function generate(input: CodegenConfig, options?: GenerateOptions
|
|
|
305
363
|
* Only content counts: a file reformatted by Prettier, oxfmt or the `format` hook is up to date.
|
|
306
364
|
*/
|
|
307
365
|
export declare function checkGenerated(input: CodegenConfig, options?: GenerateOptions): Promise<CheckResult>;
|
|
308
|
-
|
|
309
|
-
|
|
366
|
+
export interface ResolveAuthOptions {
|
|
367
|
+
/** Receives deprecation warnings, e.g. for the `*Env` keys. */
|
|
368
|
+
warn?: (message: string) => void;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Turns the config's auth setting into an auth provider. Each credential comes from its key in
|
|
372
|
+
* the setting (a `"${NAME}"` placeholder is read from `env`), else from the variable a deprecated
|
|
373
|
+
* `*Env` key names, else from its default `SF_*` variable. Throws one error listing every
|
|
374
|
+
* missing credential.
|
|
375
|
+
*/
|
|
376
|
+
export declare function resolveAuth(auth: CodegenAuth | undefined, env: Record<string, string | undefined>, options?: ResolveAuthOptions): AuthProvider;
|
|
377
|
+
export interface LoadAuthOptions extends ResolveAuthOptions {
|
|
378
|
+
/** The config file. Defaults to the first `sobjectly.config.{ts,mts,cts,json}` in `cwd`. */
|
|
379
|
+
configPath?: string;
|
|
380
|
+
/** Where to look for the config file. Defaults to `process.cwd()`. */
|
|
381
|
+
cwd?: string;
|
|
382
|
+
/** Where `"${NAME}"` placeholders and the default `SF_*` variables are read from. Defaults to `process.env`. */
|
|
383
|
+
env?: Record<string, string | undefined>;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Loads the sobjectly config and returns an auth provider for its `auth` setting, so the client
|
|
387
|
+
* logs in the same way as `sobjectly generate`:
|
|
388
|
+
* `new SalesforceClient({ apiVersion: API_VERSION, auth: await loadAuth() })`.
|
|
389
|
+
* Throws when no config file is found, or one error listing every missing credential.
|
|
390
|
+
*/
|
|
391
|
+
export declare function loadAuth(options?: LoadAuthOptions): Promise<AuthProvider>;
|
|
310
392
|
//#endregion
|
|
311
|
-
export type { Choice, CodegenAuth, CodegenConfig, CodegenDescribe, CodegenField, EnvAccessTokenAuth, EnvAuth, EnvClientCredentialsAuth, EnvJwtBearerAuth, GenerateSourceOptions, GeneratedFileHashes, InitAnswers, InitAuthType, InitConfigFormat, InitOptions, InitResult, JsonCodegenConfig, PicklistMode, Prompter, SfCliAuth };
|
|
393
|
+
export type { AccessTokenAuth, AuthSetting, Choice, ClientCredentialsAuth, CodegenAuth, CodegenConfig, CodegenDescribe, CodegenField, ConfigValue, EnvAccessTokenAuth, EnvAuth, EnvClientCredentialsAuth, EnvJwtBearerAuth, GenerateSourceOptions, GeneratedFileHashes, InitAnswers, InitAuthType, InitConfigFormat, InitOptions, InitResult, JsonCodegenConfig, JwtBearerAuth, PicklistMode, Prompter, SfCliAuth };
|
|
312
394
|
//# sourceMappingURL=codegen.d.mts.map
|
package/dist/codegen.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { A as FIELD_TYPE_MAP, C as DEPRECATED_AUTH_OPTIONS, D as generateSource, E as validateConfig, M as mapFieldType, O as init_generator, S as CodegenConfigError, T as init_validate_config, _ as findConfigFiles, a as resolveAuth, b as AUTH_OPTIONS, c as AUTH_ENV_VARS, d as renderConfig, f as runInit, g as findConfigFile, h as CONFIG_FILE_NAMES, i as loadAuth, j as init_type_mapper, k as readGeneratedHashes, l as init_init, m as init_config, n as generate, o as init_prompter, p as defineConfig, r as init_codegen, s as readlinePrompter, t as checkGenerated, u as parseSObjects, v as init_load_config, x as CONFIG_OPTIONS, y as loadConfig } from "./codegen-0L2ebG9j.mjs";
|
|
2
2
|
init_type_mapper();
|
|
3
3
|
init_generator();
|
|
4
4
|
init_validate_config();
|
|
5
|
-
init_config();
|
|
6
5
|
init_load_config();
|
|
6
|
+
init_config();
|
|
7
7
|
init_init();
|
|
8
8
|
init_prompter();
|
|
9
9
|
init_codegen();
|
|
10
|
-
export { AUTH_ENV_VARS, AUTH_OPTIONS, CONFIG_FILE_NAMES, CONFIG_OPTIONS, CodegenConfigError, FIELD_TYPE_MAP, checkGenerated, defineConfig, findConfigFile, findConfigFiles, generate, generateSource, loadConfig, mapFieldType, parseSObjects, readGeneratedHashes, readlinePrompter, renderConfig, resolveAuth, runInit, validateConfig };
|
|
10
|
+
export { AUTH_ENV_VARS, AUTH_OPTIONS, CONFIG_FILE_NAMES, CONFIG_OPTIONS, CodegenConfigError, DEPRECATED_AUTH_OPTIONS, FIELD_TYPE_MAP, checkGenerated, defineConfig, findConfigFile, findConfigFiles, generate, generateSource, loadAuth, loadConfig, mapFieldType, parseSObjects, readGeneratedHashes, readlinePrompter, renderConfig, resolveAuth, runInit, validateConfig };
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_sf_cli = require("./sf-cli-
|
|
2
|
+
const require_sf_cli = require("./sf-cli-S2BrCbik.cjs");
|
|
3
3
|
exports.ActionsApi = require_sf_cli.ActionsApi;
|
|
4
4
|
exports.ApexExecutionError = require_sf_cli.ApexExecutionError;
|
|
5
5
|
exports.ApprovalsApi = require_sf_cli.ApprovalsApi;
|
package/dist/index.d.cts
CHANGED
|
@@ -51,6 +51,8 @@ interface RequestEvent {
|
|
|
51
51
|
url: string;
|
|
52
52
|
/** Request headers with `Authorization` redacted. */
|
|
53
53
|
headers: Record<string, string>;
|
|
54
|
+
/** The body as sent: JSON or form text, or bytes for binary uploads. `undefined` without a body. */
|
|
55
|
+
body?: string | Uint8Array;
|
|
54
56
|
attempt: number;
|
|
55
57
|
}
|
|
56
58
|
interface ResponseEvent extends RequestEvent {
|
|
@@ -58,11 +60,19 @@ interface ResponseEvent extends RequestEvent {
|
|
|
58
60
|
durationMs: number;
|
|
59
61
|
/** Response headers without `set-cookie`. */
|
|
60
62
|
responseHeaders: Record<string, string>;
|
|
63
|
+
/**
|
|
64
|
+
* The response body: text for JSON, XML, CSV and `text/*`, bytes otherwise. `undefined` when
|
|
65
|
+
* empty, and for successful streamed responses (Bulk API query results), which aren't read yet.
|
|
66
|
+
*/
|
|
67
|
+
responseBody?: string | Uint8Array;
|
|
61
68
|
}
|
|
62
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Observability hooks, e.g. for logging requests and responses in test reports. Tokens are never
|
|
71
|
+
* passed to hooks. A hook may return a promise; it is not awaited, and a rejection is ignored.
|
|
72
|
+
*/
|
|
63
73
|
interface RequestHooks {
|
|
64
|
-
onRequest?(event: RequestEvent): void
|
|
65
|
-
onResponse?(event: ResponseEvent): void
|
|
74
|
+
onRequest?(event: RequestEvent): void | Promise<void>;
|
|
75
|
+
onResponse?(event: ResponseEvent): void | Promise<void>;
|
|
66
76
|
}
|
|
67
77
|
interface ApiUsage {
|
|
68
78
|
used: number;
|
|
@@ -111,6 +121,7 @@ export declare class SalesforceConnection {
|
|
|
111
121
|
resolveUrl(path: string, instanceUrl: string, query?: Record<string, QueryParamValue>): URL;
|
|
112
122
|
private sendOnce;
|
|
113
123
|
private prepare;
|
|
124
|
+
/** `body` is left out for a streamed response that hasn't been read yet. */
|
|
114
125
|
private afterResponse;
|
|
115
126
|
private toResult;
|
|
116
127
|
private errorFor;
|
|
@@ -2078,7 +2089,7 @@ interface SalesforceClientOptions {
|
|
|
2078
2089
|
allowedOrigins?: string[];
|
|
2079
2090
|
/** Headers sent with every request, e.g. `{ "Sforce-Call-Options": "client=my-app" }`. */
|
|
2080
2091
|
headers?: Record<string, string>;
|
|
2081
|
-
/** Observability hooks. Tokens are redacted. */
|
|
2092
|
+
/** Observability hooks, e.g. for logging request and response bodies. Tokens are redacted. */
|
|
2082
2093
|
hooks?: RequestHooks;
|
|
2083
2094
|
/**
|
|
2084
2095
|
* Cache metadata (describe, UI API object info, record type ids) in memory for the lifetime of
|
package/dist/index.d.mts
CHANGED
|
@@ -51,6 +51,8 @@ interface RequestEvent {
|
|
|
51
51
|
url: string;
|
|
52
52
|
/** Request headers with `Authorization` redacted. */
|
|
53
53
|
headers: Record<string, string>;
|
|
54
|
+
/** The body as sent: JSON or form text, or bytes for binary uploads. `undefined` without a body. */
|
|
55
|
+
body?: string | Uint8Array;
|
|
54
56
|
attempt: number;
|
|
55
57
|
}
|
|
56
58
|
interface ResponseEvent extends RequestEvent {
|
|
@@ -58,11 +60,19 @@ interface ResponseEvent extends RequestEvent {
|
|
|
58
60
|
durationMs: number;
|
|
59
61
|
/** Response headers without `set-cookie`. */
|
|
60
62
|
responseHeaders: Record<string, string>;
|
|
63
|
+
/**
|
|
64
|
+
* The response body: text for JSON, XML, CSV and `text/*`, bytes otherwise. `undefined` when
|
|
65
|
+
* empty, and for successful streamed responses (Bulk API query results), which aren't read yet.
|
|
66
|
+
*/
|
|
67
|
+
responseBody?: string | Uint8Array;
|
|
61
68
|
}
|
|
62
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Observability hooks, e.g. for logging requests and responses in test reports. Tokens are never
|
|
71
|
+
* passed to hooks. A hook may return a promise; it is not awaited, and a rejection is ignored.
|
|
72
|
+
*/
|
|
63
73
|
interface RequestHooks {
|
|
64
|
-
onRequest?(event: RequestEvent): void
|
|
65
|
-
onResponse?(event: ResponseEvent): void
|
|
74
|
+
onRequest?(event: RequestEvent): void | Promise<void>;
|
|
75
|
+
onResponse?(event: ResponseEvent): void | Promise<void>;
|
|
66
76
|
}
|
|
67
77
|
interface ApiUsage {
|
|
68
78
|
used: number;
|
|
@@ -111,6 +121,7 @@ export declare class SalesforceConnection {
|
|
|
111
121
|
resolveUrl(path: string, instanceUrl: string, query?: Record<string, QueryParamValue>): URL;
|
|
112
122
|
private sendOnce;
|
|
113
123
|
private prepare;
|
|
124
|
+
/** `body` is left out for a streamed response that hasn't been read yet. */
|
|
114
125
|
private afterResponse;
|
|
115
126
|
private toResult;
|
|
116
127
|
private errorFor;
|
|
@@ -2078,7 +2089,7 @@ interface SalesforceClientOptions {
|
|
|
2078
2089
|
allowedOrigins?: string[];
|
|
2079
2090
|
/** Headers sent with every request, e.g. `{ "Sforce-Call-Options": "client=my-app" }`. */
|
|
2080
2091
|
headers?: Record<string, string>;
|
|
2081
|
-
/** Observability hooks. Tokens are redacted. */
|
|
2092
|
+
/** Observability hooks, e.g. for logging request and response bodies. Tokens are redacted. */
|
|
2082
2093
|
hooks?: RequestHooks;
|
|
2083
2094
|
/**
|
|
2084
2095
|
* Cache metadata (describe, UI API object info, record type ids) in memory for the lifetime of
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as BulkApi, A as init_search, At as init_errors, B as MAX_UPLOAD_BYTES, C as init_ui_api, Ct as soslEscape, D as isSObjectType, Dt as SalesforcePartialFailureError, E as init_query_builder, Et as SalesforceError, F as init_quick_actions, Ft as MetadataCache, G as init_events, H as buildMultipart, I as QueryApi, It as init_cache, J as CompositeRequestBuilder, K as toPublishResult, L as init_query, M as init_reports, Mt as init_api_version, N as reportRows, Nt as isApiVersion, O as soqlFor, Ot as SalesforceSaveError, P as QuickActionsApi, Pt as normalizeApiVersion, Q as init_collections, R as FilesApi, S as UiApi, St as soqlLiteral, T as TypeOfBuilder, Tt as SalesforceBulkJobError, U as init_multipart, V as init_files, W as EventsApi, X as init_composite, Y as CompositeResponse, Z as CollectionsApi, _ as DebugLogCaptureError, _t as init_escape, a as createJwtAssertion, at as parseCsv, b as SObjectResource, bt as soqlEscape, c as refreshToken, ct as toCsv, d as init_client, dt as ActionsApi, et as BulkIngestJob, f as ApexExecutionError, ft as init_actions, g as DEFAULT_DEBUG_LEVELS, gt as init_connection, h as DEBUG_LEVEL_NAME, ht as SalesforceConnection, i as clientCredentials, it as init_csv, j as ReportsApi, jt as isSalesforceError, k as SearchApi, kt as hasErrorCode, l as tokenProvider, lt as ApprovalsApi, m as init_tooling, mt as init_fetch_transport, n as sfCli, nt as init_bulk, o as init_providers, ot as parseCsvRows, p as ToolingApi, pt as fetchTransport, q as CompositeApi, r as accessToken, rt as CsvRowParser, s as jwtBearer, st as parseCsvStream, t as init_sf_cli, tt as BulkQueryJob, u as SalesforceClient, ut as init_approvals, v as DebugLogsApi, vt as soqlDate, w as SoqlQueryBuilder, wt as SalesforceAuthError, x as init_sobject, xt as soqlEscapeDateOnly, y as init_debug_logs, yt as soqlDateLiteral, z as MAX_JSON_UPLOAD_BYTES } from "./sf-cli-
|
|
1
|
+
import { $ as BulkApi, A as init_search, At as init_errors, B as MAX_UPLOAD_BYTES, C as init_ui_api, Ct as soslEscape, D as isSObjectType, Dt as SalesforcePartialFailureError, E as init_query_builder, Et as SalesforceError, F as init_quick_actions, Ft as MetadataCache, G as init_events, H as buildMultipart, I as QueryApi, It as init_cache, J as CompositeRequestBuilder, K as toPublishResult, L as init_query, M as init_reports, Mt as init_api_version, N as reportRows, Nt as isApiVersion, O as soqlFor, Ot as SalesforceSaveError, P as QuickActionsApi, Pt as normalizeApiVersion, Q as init_collections, R as FilesApi, S as UiApi, St as soqlLiteral, T as TypeOfBuilder, Tt as SalesforceBulkJobError, U as init_multipart, V as init_files, W as EventsApi, X as init_composite, Y as CompositeResponse, Z as CollectionsApi, _ as DebugLogCaptureError, _t as init_escape, a as createJwtAssertion, at as parseCsv, b as SObjectResource, bt as soqlEscape, c as refreshToken, ct as toCsv, d as init_client, dt as ActionsApi, et as BulkIngestJob, f as ApexExecutionError, ft as init_actions, g as DEFAULT_DEBUG_LEVELS, gt as init_connection, h as DEBUG_LEVEL_NAME, ht as SalesforceConnection, i as clientCredentials, it as init_csv, j as ReportsApi, jt as isSalesforceError, k as SearchApi, kt as hasErrorCode, l as tokenProvider, lt as ApprovalsApi, m as init_tooling, mt as init_fetch_transport, n as sfCli, nt as init_bulk, o as init_providers, ot as parseCsvRows, p as ToolingApi, pt as fetchTransport, q as CompositeApi, r as accessToken, rt as CsvRowParser, s as jwtBearer, st as parseCsvStream, t as init_sf_cli, tt as BulkQueryJob, u as SalesforceClient, ut as init_approvals, v as DebugLogsApi, vt as soqlDate, w as SoqlQueryBuilder, wt as SalesforceAuthError, x as init_sobject, xt as soqlEscapeDateOnly, y as init_debug_logs, yt as soqlDateLiteral, z as MAX_JSON_UPLOAD_BYTES } from "./sf-cli-D2PgjErx.mjs";
|
|
2
2
|
//#region src/index.ts
|
|
3
3
|
init_client();
|
|
4
4
|
init_providers();
|
|
@@ -478,10 +478,14 @@ function toBytes(body) {
|
|
|
478
478
|
function assertSerializable(body) {
|
|
479
479
|
if (typeof Blob !== "undefined" && body instanceof Blob || typeof FormData !== "undefined" && body instanceof FormData || typeof ReadableStream !== "undefined" && body instanceof ReadableStream) throw new TypeError("Unsupported request body: Blob, FormData and streams can't be sent. Pass a Uint8Array (see buildMultipart for multipart).");
|
|
480
480
|
}
|
|
481
|
-
/**
|
|
481
|
+
/**
|
|
482
|
+
* Runs an observability hook; a throwing hook must never change the outcome of a request. A
|
|
483
|
+
* returned promise is not awaited, and its rejection is swallowed so it can't go unhandled.
|
|
484
|
+
*/
|
|
482
485
|
function callHook(hook) {
|
|
483
486
|
try {
|
|
484
|
-
hook();
|
|
487
|
+
const result = hook();
|
|
488
|
+
if (result && typeof result.catch === "function") result.catch(() => void 0);
|
|
485
489
|
} catch {}
|
|
486
490
|
}
|
|
487
491
|
function setDefault(headers, name, value) {
|
|
@@ -506,6 +510,11 @@ function parseBody(response, responseType, strict = false) {
|
|
|
506
510
|
}
|
|
507
511
|
return text;
|
|
508
512
|
}
|
|
513
|
+
/** A response body for hooks: decoded text for text content types, bytes otherwise. */
|
|
514
|
+
function eventBody(body, headers) {
|
|
515
|
+
if (body.byteLength === 0) return;
|
|
516
|
+
return isTextContentType((headers.get("content-type") ?? "").toLowerCase()) ? decoder$1.decode(body) : body;
|
|
517
|
+
}
|
|
509
518
|
function isTextContentType(contentType) {
|
|
510
519
|
return contentType === "" || contentType.includes("json") || contentType.startsWith("text/") || contentType.includes("xml") || contentType.includes("csv");
|
|
511
520
|
}
|
|
@@ -675,7 +684,7 @@ var init_connection = __esmMin((() => {
|
|
|
675
684
|
const signal = combineSignals(request.signal, timeoutMs);
|
|
676
685
|
const prepared = this.prepare(request, method, token, attempt, signal, timeoutMs);
|
|
677
686
|
const response = await this._transport.send(prepared.transportRequest);
|
|
678
|
-
this.afterResponse(prepared.event, response
|
|
687
|
+
this.afterResponse(prepared.event, response);
|
|
679
688
|
return response;
|
|
680
689
|
}
|
|
681
690
|
prepare(request, method, token, attempt, signal, timeoutMs) {
|
|
@@ -687,6 +696,7 @@ var init_connection = __esmMin((() => {
|
|
|
687
696
|
method,
|
|
688
697
|
url: url.toString(),
|
|
689
698
|
headers: redactHeaders(headers),
|
|
699
|
+
body,
|
|
690
700
|
attempt
|
|
691
701
|
};
|
|
692
702
|
callHook(() => this._hooks.onRequest?.(event));
|
|
@@ -705,14 +715,16 @@ var init_connection = __esmMin((() => {
|
|
|
705
715
|
}
|
|
706
716
|
};
|
|
707
717
|
}
|
|
708
|
-
|
|
709
|
-
|
|
718
|
+
/** `body` is left out for a streamed response that hasn't been read yet. */
|
|
719
|
+
afterResponse(event, response) {
|
|
720
|
+
this.trackApiUsage(response.headers);
|
|
710
721
|
const { started, ...requestEvent } = event;
|
|
711
722
|
callHook(() => this._hooks.onResponse?.({
|
|
712
723
|
...requestEvent,
|
|
713
|
-
status,
|
|
724
|
+
status: response.status,
|
|
714
725
|
durationMs: Date.now() - started,
|
|
715
|
-
responseHeaders: headersToObject(headers)
|
|
726
|
+
responseHeaders: headersToObject(response.headers),
|
|
727
|
+
responseBody: response.body && eventBody(response.body, response.headers)
|
|
716
728
|
}));
|
|
717
729
|
}
|
|
718
730
|
toResult(request, method, response) {
|
|
@@ -747,13 +759,20 @@ var init_connection = __esmMin((() => {
|
|
|
747
759
|
let reauthenticated = false;
|
|
748
760
|
let retries = 0;
|
|
749
761
|
for (let attempt = 1;; attempt++) {
|
|
750
|
-
const response = await this.openStream(stream, request, method, token, attempt, timeoutMs);
|
|
751
|
-
if (response.status >= 200 && response.status < 300)
|
|
762
|
+
const { event, response } = await this.openStream(stream, request, method, token, attempt, timeoutMs);
|
|
763
|
+
if (response.status >= 200 && response.status < 300) {
|
|
764
|
+
this.afterResponse(event, {
|
|
765
|
+
status: response.status,
|
|
766
|
+
headers: response.headers
|
|
767
|
+
});
|
|
768
|
+
return response;
|
|
769
|
+
}
|
|
752
770
|
const buffered = {
|
|
753
771
|
status: response.status,
|
|
754
772
|
headers: response.headers,
|
|
755
773
|
body: await collect(response.body)
|
|
756
774
|
};
|
|
775
|
+
this.afterResponse(event, buffered);
|
|
757
776
|
if (response.status === 401 && !reauthenticated && this._auth.invalidate) {
|
|
758
777
|
reauthenticated = true;
|
|
759
778
|
const next = await this.reauthenticate(token, request.signal, timeoutMs);
|
|
@@ -780,9 +799,10 @@ var init_connection = __esmMin((() => {
|
|
|
780
799
|
const signal = request.signal ? AbortSignal.any([request.signal, headerTimeout.signal]) : headerTimeout.signal;
|
|
781
800
|
try {
|
|
782
801
|
const prepared = this.prepare(request, method, token, attempt, signal, 0);
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
802
|
+
return {
|
|
803
|
+
event: prepared.event,
|
|
804
|
+
response: await stream(prepared.transportRequest)
|
|
805
|
+
};
|
|
786
806
|
} finally {
|
|
787
807
|
clearTimeout(timer);
|
|
788
808
|
}
|
|
@@ -3965,14 +3985,17 @@ var init_sf_cli = __esmMin((() => {
|
|
|
3965
3985
|
"/c",
|
|
3966
3986
|
`"${[command, ...args].map(quoteForCmd).join(" ")}"`
|
|
3967
3987
|
]] : [command, [...args]];
|
|
3988
|
+
const env = {
|
|
3989
|
+
...process.env,
|
|
3990
|
+
SF_JSON_TO_STDOUT: "true",
|
|
3991
|
+
NO_COLOR: "1"
|
|
3992
|
+
};
|
|
3993
|
+
delete env.FORCE_COLOR;
|
|
3968
3994
|
execFile(file, fileArgs, {
|
|
3969
3995
|
windowsHide: true,
|
|
3970
3996
|
windowsVerbatimArguments: windows,
|
|
3971
3997
|
maxBuffer: 10485760,
|
|
3972
|
-
env
|
|
3973
|
-
...process.env,
|
|
3974
|
-
SF_JSON_TO_STDOUT: "true"
|
|
3975
|
-
}
|
|
3998
|
+
env
|
|
3976
3999
|
}, (error, stdout, stderr) => {
|
|
3977
4000
|
if (error && (error.code === "ENOENT" || windows && (error.code === CMD_NOT_FOUND || /is not recognized/i.test(stderr)))) reject(Object.assign(/* @__PURE__ */ new Error(`${command} was not found`), { code: "ENOENT" }));
|
|
3978
4001
|
else if (error && !stdout.includes("{")) reject(/* @__PURE__ */ new Error(`${error.message}${stderr ? `\n${stderr.trim()}` : ""}`));
|
|
@@ -3983,4 +4006,4 @@ var init_sf_cli = __esmMin((() => {
|
|
|
3983
4006
|
//#endregion
|
|
3984
4007
|
export { BulkApi as $, init_search as A, init_errors as At, MAX_UPLOAD_BYTES as B, init_ui_api as C, soslEscape as Ct, isSObjectType as D, SalesforcePartialFailureError as Dt, init_query_builder as E, SalesforceError as Et, init_quick_actions as F, MetadataCache as Ft, init_events as G, buildMultipart as H, QueryApi as I, init_cache as It, CompositeRequestBuilder as J, toPublishResult as K, init_query as L, __commonJSMin as Lt, init_reports as M, init_api_version as Mt, reportRows as N, isApiVersion as Nt, soqlFor as O, SalesforceSaveError as Ot, QuickActionsApi as P, normalizeApiVersion as Pt, init_collections as Q, FilesApi as R, __esmMin as Rt, UiApi as S, soqlLiteral as St, TypeOfBuilder as T, SalesforceBulkJobError as Tt, init_multipart as U, init_files as V, EventsApi as W, init_composite as X, CompositeResponse as Y, CollectionsApi as Z, DebugLogCaptureError as _, init_escape as _t, createJwtAssertion as a, parseCsv as at, SObjectResource as b, soqlEscape as bt, refreshToken as c, toCsv as ct, init_client as d, ActionsApi as dt, BulkIngestJob as et, ApexExecutionError as f, init_actions as ft, DEFAULT_DEBUG_LEVELS as g, init_connection as gt, DEBUG_LEVEL_NAME as h, SalesforceConnection as ht, clientCredentials as i, init_csv as it, ReportsApi as j, isSalesforceError as jt, SearchApi as k, hasErrorCode as kt, tokenProvider as l, ApprovalsApi as lt, init_tooling as m, init_fetch_transport as mt, sfCli as n, init_bulk as nt, init_providers as o, parseCsvRows as ot, ToolingApi as p, fetchTransport as pt, CompositeApi as q, accessToken as r, CsvRowParser as rt, jwtBearer as s, parseCsvStream as st, init_sf_cli as t, BulkQueryJob as tt, SalesforceClient as u, init_approvals as ut, DebugLogsApi as v, soqlDate as vt, SoqlQueryBuilder as w, SalesforceAuthError as wt, init_sobject as x, soqlEscapeDateOnly as xt, init_debug_logs as y, soqlDateLiteral as yt, MAX_JSON_UPLOAD_BYTES as z };
|
|
3985
4008
|
|
|
3986
|
-
//# sourceMappingURL=sf-cli-
|
|
4009
|
+
//# sourceMappingURL=sf-cli-D2PgjErx.mjs.map
|