@timeback/core 0.1.3 → 0.1.4

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.
@@ -7,6 +7,10 @@ import type { ResolveEnvVars } from '@timeback/internal-client-infra';
7
7
  import type { Environment, EnvServiceUrls, Platform } from './types';
8
8
  /**
9
9
  * Environment variable names for Timeback client configuration.
10
+ *
11
+ * Supports fallback chains - tries each env var in order until one is defined:
12
+ * - `TIMEBACK_API_*` (canonical/preferred)
13
+ * - `TIMEBACK_*` (legacy shorthand)
10
14
  */
11
15
  export declare const TIMEBACK_ENV_VARS: ResolveEnvVars;
12
16
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAMpE;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,cAM/B,CAAA;AAMD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CACnC,GAAG,EAAE,WAAW,EAChB,QAAQ,GAAE,QAA2B,GACnC,cAAc,CAShB"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAMpE;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,EAAE,cAM/B,CAAA;AAMD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CACnC,GAAG,EAAE,WAAW,EAChB,QAAQ,GAAE,QAA2B,GACnC,cAAc,CAShB"}
package/dist/errors.js CHANGED
@@ -704,7 +704,17 @@ class TimebackProvider {
704
704
  // ../../internal/client-infra/src/utils/utils.ts
705
705
  function getEnv(key) {
706
706
  try {
707
- return typeof process === "undefined" ? undefined : process.env[key];
707
+ if (typeof process === "undefined")
708
+ return;
709
+ if (typeof key === "string") {
710
+ return process.env[key];
711
+ }
712
+ for (const k of key) {
713
+ const value = process.env[k];
714
+ if (value !== undefined)
715
+ return value;
716
+ }
717
+ return;
708
718
  } catch {
709
719
  return;
710
720
  }
@@ -725,6 +735,18 @@ var DEFAULT_PROVIDER_REGISTRY = {
725
735
  };
726
736
 
727
737
  // ../../internal/client-infra/src/config/resolve.ts
738
+ function primaryEnvVar(key) {
739
+ if (typeof key === "string") {
740
+ return key;
741
+ }
742
+ if (key.length === 0) {
743
+ throw new Error(`Missing env var key: ${key}`);
744
+ }
745
+ return key[0];
746
+ }
747
+ function formatEnvVarKey(key) {
748
+ return primaryEnvVar(key);
749
+ }
728
750
  function validateEnv(env) {
729
751
  if (env !== "staging" && env !== "production") {
730
752
  throw new Error(`Invalid env "${env}": must be "staging" or "production"`);
@@ -735,10 +757,10 @@ function validateAuth(auth, envVars) {
735
757
  const clientId = auth?.clientId ?? getEnv(envVars.clientId);
736
758
  const clientSecret = auth?.clientSecret ?? getEnv(envVars.clientSecret);
737
759
  if (!clientId) {
738
- throw new Error(`Missing clientId: provide in config or set ${envVars.clientId}`);
760
+ throw new Error(`Missing clientId: provide in config or set ${formatEnvVarKey(envVars.clientId)}`);
739
761
  }
740
762
  if (!clientSecret) {
741
- throw new Error(`Missing clientSecret: provide in config or set ${envVars.clientSecret}`);
763
+ throw new Error(`Missing clientSecret: provide in config or set ${formatEnvVarKey(envVars.clientSecret)}`);
742
764
  }
743
765
  return { clientId, clientSecret };
744
766
  }
@@ -754,21 +776,21 @@ function buildMissingEnvError(envVars) {
754
776
  const clientId = getEnv(envVars.clientId);
755
777
  const clientSecret = getEnv(envVars.clientSecret);
756
778
  if (baseUrl === undefined && clientId === undefined) {
757
- const hint = envVars.env ?? envVars.baseUrl;
779
+ const hint = formatEnvVarKey(envVars.env ?? envVars.baseUrl);
758
780
  return `Missing env: provide in config or set ${hint}`;
759
781
  }
760
782
  const missing = [];
761
783
  if (baseUrl === undefined) {
762
- missing.push(envVars.env ?? envVars.baseUrl);
784
+ missing.push(formatEnvVarKey(envVars.env ?? envVars.baseUrl));
763
785
  }
764
786
  if (baseUrl !== undefined && authUrl === undefined) {
765
- missing.push(envVars.authUrl);
787
+ missing.push(formatEnvVarKey(envVars.authUrl));
766
788
  }
767
789
  if (clientId === undefined) {
768
- missing.push(envVars.clientId);
790
+ missing.push(formatEnvVarKey(envVars.clientId));
769
791
  }
770
792
  if (clientSecret === undefined) {
771
- missing.push(envVars.clientSecret);
793
+ missing.push(formatEnvVarKey(envVars.clientSecret));
772
794
  }
773
795
  return `Missing environment variables: ${missing.join(", ")}`;
774
796
  }
package/dist/index.d.ts CHANGED
@@ -24,6 +24,7 @@ export type { BroadcastResult, BroadcastResultMethods, BroadcastResults } from '
24
24
  export { ApiError, ForbiddenError, isApiError, NotFoundError, UnauthorizedError, ValidationError, } from '@timeback/internal-client-infra';
25
25
  export { whereToFilter } from '@timeback/internal-client-infra';
26
26
  export type { FieldCondition, FieldOperators, FilterValue, OrCondition, WhereClause, } from '@timeback/internal-client-infra';
27
- export type { Environment, TimebackClientConfig } from './types/index';
27
+ export { getServiceUrlsForEnv } from './constants';
28
+ export type { Environment, EnvServiceUrls, TimebackClientConfig } from './types/index';
28
29
  export type { AuthCheckResult } from '@timeback/internal-client-infra';
29
30
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAMH,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3C,YAAY,EAAE,eAAe,EAAE,sBAAsB,EAAE,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