@factorialco/api-client 1.0.3 → 1.1.1

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/cjs/sdk.js CHANGED
@@ -5511,8 +5511,22 @@ class FactorialClient {
5511
5511
  workSchedule;
5512
5512
  constructor(config = {}) {
5513
5513
  const { apiKey, token, baseUrl, ...rest } = config;
5514
- if (!apiKey && !token) {
5515
- throw new Error("FactorialClient: provide either apiKey or token");
5514
+ // Fall back to environment variables when options are omitted. Guarded so
5515
+ // the SDK keeps working in non-Node runtimes (e.g. browsers) where
5516
+ // `process` is undefined.
5517
+ const env = typeof globalThis !== "undefined" &&
5518
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5519
+ globalThis.process &&
5520
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5521
+ globalThis.process.env
5522
+ ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
5523
+ globalThis.process.env
5524
+ : {};
5525
+ const resolvedApiKey = apiKey ?? env.FACTORIAL_API_KEY;
5526
+ const resolvedToken = token ?? env.FACTORIAL_TOKEN;
5527
+ const resolvedBaseUrl = baseUrl ?? env.FACTORIAL_BASE_URL ?? "https://api.factorialhr.com";
5528
+ if (!resolvedApiKey && !resolvedToken) {
5529
+ throw new Error("FactorialClient: provide either apiKey or token (or set FACTORIAL_API_KEY / FACTORIAL_TOKEN)");
5516
5530
  }
5517
5531
  // hey-api calls the auth callback once per security scheme in spec order:
5518
5532
  // 1. { type: 'http', scheme: 'bearer' } → Authorization: Bearer <token>
@@ -5520,13 +5534,14 @@ class FactorialClient {
5520
5534
  // Return a value only for the matching scheme so the other is skipped.
5521
5535
  const auth = (scheme) => {
5522
5536
  if (scheme.type === "http")
5523
- return token; // OAuth bearer
5537
+ return resolvedToken; // OAuth bearer
5524
5538
  if (scheme.type === "apiKey")
5525
- return apiKey; // API key
5539
+ return resolvedApiKey; // API key
5526
5540
  return undefined;
5527
5541
  };
5528
5542
  const client = (0, index_js_1.createClient)((0, index_js_1.createConfig)({
5529
- baseUrl: baseUrl ?? "https://api.factorialhr.com",
5543
+ baseUrl: resolvedBaseUrl,
5544
+ throwOnError: true,
5530
5545
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5531
5546
  auth: auth,
5532
5547
  ...rest,