@cerios/salesforce-sobjectly 1.1.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.
@@ -1,47 +1,85 @@
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
- /** Client credentials read from environment variables (defaults shown). */
4
- interface EnvClientCredentialsAuth {
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` (your My Domain 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
- /** Defaults to `SF_CLIENT_ID`. */
21
+ /** @deprecated Use `clientId: process.env.NAME` (or `"${NAME}"` in JSON). Removed in 2.0. */
9
22
  clientIdEnv?: string;
10
- /** Defaults to `SF_CLIENT_SECRET`. */
23
+ /** @deprecated Use `clientSecret: process.env.NAME` (or `"${NAME}"` in JSON). Removed in 2.0. */
11
24
  clientSecretEnv?: string;
12
25
  }
13
- /** An access token read from environment variables (defaults shown), e.g. from `sf org display`. */
14
- interface EnvAccessTokenAuth {
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
- /** Defaults to `SF_INSTANCE_URL`. */
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 with values read from environment variables (defaults shown). */
22
- interface EnvJwtBearerAuth {
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
- /** Defaults to `SF_CLIENT_ID`. */
53
+ /** @deprecated Use `clientId: process.env.NAME` (or `"${NAME}"` in JSON). Removed in 2.0. */
27
54
  clientIdEnv?: string;
28
- /** Defaults to `SF_USERNAME`. */
55
+ /** @deprecated Use `username: process.env.NAME` (or `"${NAME}"` in JSON). Removed in 2.0. */
29
56
  usernameEnv?: string;
30
- /** The PEM key itself. Defaults to `SF_PRIVATE_KEY`. */
57
+ /** @deprecated Use `privateKey: process.env.NAME` (or `"${NAME}"` in JSON). Removed in 2.0. */
31
58
  privateKeyEnv?: string;
32
- /** A path to the PEM key file, used when the key variable is empty. Defaults to `SF_PRIVATE_KEY_PATH`. */
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
- /** The org alias or username. Defaults to the CLI's default org. */
40
- targetOrg?: string;
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
- type EnvAuth = EnvClientCredentialsAuth | EnvAccessTokenAuth | EnvJwtBearerAuth | SfCliAuth;
43
- /** Env-based auth, or any auth provider (TypeScript configs only). */
44
- type CodegenAuth = EnvAuth | AuthProvider;
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" |
@@ -77,7 +115,10 @@ interface CodegenConfig<S extends string = string> {
77
115
  sobjects?: readonly S[];
78
116
  /** sObjects to skip (applied after `sobjects`). */
79
117
  exclude?: readonly string[];
80
- /** How to authenticate. Defaults to client credentials from `SF_LOGIN_URL`, `SF_CLIENT_ID` and `SF_CLIENT_SECRET`. */
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
+ */
81
122
  auth?: CodegenAuth;
82
123
  /** Fields to leave out of the create input per sObject (e.g. fields describe marks createable but REST rejects). */
83
124
  excludeCreateFields?: Partial<Record<NoInfer<S>, readonly string[]>>;
@@ -104,7 +145,7 @@ interface CodegenConfig<S extends string = string> {
104
145
  */
105
146
  type JsonCodegenConfig = Omit<CodegenConfig, "auth" | "format" | "transport"> & {
106
147
  $schema?: string;
107
- auth?: EnvAuth;
148
+ auth?: AuthSetting;
108
149
  };
109
150
  /**
110
151
  * Type-checks a `sobjectly.config.ts`. The listed `sobjects` become a literal union, so a typo in
@@ -192,8 +233,10 @@ export declare class CodegenConfigError extends Error {
192
233
  readonly name: string;
193
234
  constructor(source: string, problems: string[]);
194
235
  }
195
- /** The env-variable options each env-based auth type accepts. */
196
- export declare const AUTH_OPTIONS: Record<EnvAuth["type"], readonly string[]>;
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>>;
197
240
  /** The options a config may contain. */
198
241
  export declare const CONFIG_OPTIONS: readonly string[];
199
242
  /**
@@ -261,7 +304,7 @@ interface InitResult {
261
304
  envExampleUpdated?: boolean;
262
305
  scriptAdded?: boolean;
263
306
  }
264
- /** The environment variables each auth type reads by default. */
307
+ /** The environment variables the config written by `init` reads, per auth type. */
265
308
  export declare const AUTH_ENV_VARS: Record<InitAuthType, string[]>;
266
309
  /**
267
310
  * Creates a `sobjectly.config` file by asking for the API version, output path, sObjects, auth
@@ -283,7 +326,7 @@ export interface GenerateOptions {
283
326
  /** Directory that `output` is resolved against. Defaults to `process.cwd()`. */
284
327
  cwd?: string;
285
328
  logger?: CodegenLogger;
286
- /** Environment to read credentials from. Defaults to `process.env`. */
329
+ /** Where `"${NAME}"` placeholders and the default `SF_*` variables are read from. Defaults to `process.env`. */
287
330
  env?: Record<string, string | undefined>;
288
331
  /** Write the file. Defaults to `true`; with `false` the source is only returned. */
289
332
  write?: boolean;
@@ -320,8 +363,32 @@ export declare function generate(input: CodegenConfig, options?: GenerateOptions
320
363
  * Only content counts: a file reformatted by Prettier, oxfmt or the `format` hook is up to date.
321
364
  */
322
365
  export declare function checkGenerated(input: CodegenConfig, options?: GenerateOptions): Promise<CheckResult>;
323
- /** Turns the config's auth setting into an auth provider, reading env-based credentials. */
324
- export declare function resolveAuth(auth: CodegenAuth | undefined, env: Record<string, string | undefined>): AuthProvider;
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>;
325
392
  //#endregion
326
- 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 };
327
394
  //# sourceMappingURL=codegen.d.mts.map
package/dist/codegen.mjs CHANGED
@@ -1,10 +1,10 @@
1
- import { A as mapFieldType, C as init_validate_config, D as readGeneratedHashes, E as init_generator, O as FIELD_TYPE_MAP, T as generateSource, _ as defineConfig, a as init_prompter, b as CONFIG_OPTIONS, c as init_init, d as runInit, f as CONFIG_FILE_NAMES, g as loadConfig, h as init_load_config, i as resolveAuth, k as init_type_mapper, l as parseSObjects, m as findConfigFiles, n as generate, o as readlinePrompter, p as findConfigFile, r as init_codegen, s as AUTH_ENV_VARS, t as checkGenerated, u as renderConfig, v as init_config, w as validateConfig, x as CodegenConfigError, y as AUTH_OPTIONS } from "./codegen-C6MEYiWo.mjs";
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-R6LHwqoo.cjs");
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
- /** Observability hooks, e.g. for logging in test reports. Tokens are never passed to hooks. */
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
- /** Observability hooks, e.g. for logging in test reports. Tokens are never passed to hooks. */
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-_Ua-M_Zi.mjs";
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
- /** Runs an observability hook; a throwing hook must never change the outcome of a request. */
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.status, response.headers);
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
- afterResponse(event, status, headers) {
709
- this.trackApiUsage(headers);
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) return response;
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
- const response = await stream(prepared.transportRequest);
784
- this.afterResponse(prepared.event, response.status, response.headers);
785
- return response;
802
+ return {
803
+ event: prepared.event,
804
+ response: await stream(prepared.transportRequest)
805
+ };
786
806
  } finally {
787
807
  clearTimeout(timer);
788
808
  }
@@ -3986,4 +4006,4 @@ var init_sf_cli = __esmMin((() => {
3986
4006
  //#endregion
3987
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 };
3988
4008
 
3989
- //# sourceMappingURL=sf-cli-_Ua-M_Zi.mjs.map
4009
+ //# sourceMappingURL=sf-cli-D2PgjErx.mjs.map