hanzio 1.1.0 → 2.0.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.
Files changed (172) hide show
  1. package/README.md +832 -219
  2. package/dist/api-wrapper/builders.d.ts +15 -3
  3. package/dist/api-wrapper/create-client.d.ts +1 -1
  4. package/dist/api-wrapper/describe.d.ts +16 -0
  5. package/dist/api-wrapper/endpoint.d.ts +18 -0
  6. package/dist/api-wrapper/errors.d.ts +40 -2
  7. package/dist/api-wrapper/headers.d.ts +2 -1
  8. package/dist/api-wrapper/index.d.ts +5 -0
  9. package/dist/api-wrapper/otel.d.ts +44 -0
  10. package/dist/api-wrapper/paginate.d.ts +12 -0
  11. package/dist/api-wrapper/redaction.d.ts +2 -0
  12. package/dist/api-wrapper/shared.d.ts +16 -2
  13. package/dist/api-wrapper/testing.d.ts +23 -0
  14. package/dist/api-wrapper/transport.d.ts +12 -10
  15. package/dist/api-wrapper/types.d.ts +104 -18
  16. package/dist/array/index.d.ts +50 -4
  17. package/dist/cache/createCache.d.ts +31 -0
  18. package/dist/cache/index.d.ts +45 -2
  19. package/dist/color/contrast.d.ts +40 -0
  20. package/dist/color/index.d.ts +2 -0
  21. package/dist/{math → color}/metricsSeriesColors.d.ts +14 -7
  22. package/dist/cool-console-log/index.d.ts +34 -5
  23. package/dist/crypto/encoding.d.ts +18 -0
  24. package/dist/crypto/hash.d.ts +33 -0
  25. package/dist/crypto/index.d.ts +4 -0
  26. package/dist/crypto/sealer.d.ts +25 -0
  27. package/dist/crypto/webhook.d.ts +20 -0
  28. package/dist/date/index.d.ts +46 -2
  29. package/dist/emitter/index.d.ts +21 -0
  30. package/dist/error/index.d.ts +12 -0
  31. package/dist/format/index.d.ts +102 -0
  32. package/dist/function/index.d.ts +60 -0
  33. package/dist/guard/index.d.ts +20 -0
  34. package/dist/i18n/index.d.ts +37 -0
  35. package/dist/index-0zvtcbzy.js +224 -0
  36. package/dist/index-181e6vfw.js +29 -0
  37. package/dist/index-8r2vdzjg.js +87 -0
  38. package/dist/index-hy7kbb99.js +157 -0
  39. package/dist/{src/secrets/loaders.js → index-j1ybktbr.js} +608 -405
  40. package/dist/index-k9yx6bne.js +89 -0
  41. package/dist/index-kj1phgrx.js +169 -0
  42. package/dist/index-mnkcfyx8.js +78 -0
  43. package/dist/{p-queue/index.js → index-pwt0dz63.js} +7 -11
  44. package/dist/index-rp5pqghz.js +157 -0
  45. package/dist/index-srt06xd2.js +15 -0
  46. package/dist/index-wjyb9bsd.js +263 -0
  47. package/dist/index.d.ts +7 -7
  48. package/dist/jwt/index.d.ts +50 -2
  49. package/dist/math/index.d.ts +2 -2
  50. package/dist/math/linearRegressionTrend.d.ts +14 -1
  51. package/dist/math/scale.d.ts +8 -0
  52. package/dist/object/index.d.ts +19 -0
  53. package/dist/p-queue/index.d.ts +1 -1
  54. package/dist/promise/index.d.ts +97 -2
  55. package/dist/secrets/core.d.ts +47 -0
  56. package/dist/secrets/deadline.d.ts +6 -0
  57. package/dist/secrets/environment.d.ts +9 -0
  58. package/dist/secrets/errors.d.ts +11 -0
  59. package/dist/secrets/index.d.ts +13 -25
  60. package/dist/secrets/infisical-cli.d.ts +6 -0
  61. package/dist/secrets/infisical-config.d.ts +17 -0
  62. package/dist/secrets/infisical-session.d.ts +4 -0
  63. package/dist/secrets/infisical.d.ts +8 -13
  64. package/dist/secrets/loaders.d.ts +5 -12
  65. package/dist/secrets/vite.d.ts +7 -3
  66. package/dist/secrets/worker-loader.d.ts +9 -0
  67. package/dist/secrets/worker.d.ts +3 -0
  68. package/dist/sitemap/index.d.ts +48 -6
  69. package/dist/src/api-wrapper/index.js +60 -1100
  70. package/dist/src/api-wrapper/testing.js +20 -0
  71. package/dist/{cool-console-log → src/cool-console-log}/index.js +80 -33
  72. package/dist/src/crypto/index.js +195 -0
  73. package/dist/src/format/index.js +211 -0
  74. package/dist/src/i18n/index.js +36 -0
  75. package/dist/src/index.js +863 -2809
  76. package/dist/src/jwt/index.js +138 -92
  77. package/dist/src/p-queue/index.js +9 -437
  78. package/dist/src/secrets/index.js +261 -1377
  79. package/dist/src/secrets/vite.js +6 -17
  80. package/dist/src/secrets/worker.js +12 -0
  81. package/dist/src/sitemap/index.js +183 -511
  82. package/dist/src/storage/index.js +119 -0
  83. package/dist/src/zod/index.js +347 -174
  84. package/dist/state/index.d.ts +21 -0
  85. package/dist/storage/index.d.ts +58 -0
  86. package/dist/string/index.d.ts +75 -2
  87. package/dist/typedswitch/index.d.ts +37 -26
  88. package/dist/types/index.d.ts +11 -0
  89. package/dist/url/index.d.ts +50 -1
  90. package/dist/zod/index.d.ts +32 -3
  91. package/dist/zod/introspect.d.ts +19 -0
  92. package/dist/zod/jsonToZodSchemaMapper.d.ts +3 -1
  93. package/dist/zod/zodMinMaxFilter.d.ts +22 -3
  94. package/dist/zod/zodToTypeString.d.ts +8 -3
  95. package/package.json +87 -7
  96. package/src/api-wrapper/actions-impl.ts +11 -72
  97. package/src/api-wrapper/builders.ts +84 -52
  98. package/src/api-wrapper/create-client.ts +246 -96
  99. package/src/api-wrapper/describe.ts +157 -0
  100. package/src/api-wrapper/endpoint.ts +26 -0
  101. package/src/api-wrapper/error-reporting.ts +7 -1
  102. package/src/api-wrapper/errors.ts +117 -2
  103. package/src/api-wrapper/headers.ts +19 -1
  104. package/src/api-wrapper/index.ts +5 -0
  105. package/src/api-wrapper/otel.ts +139 -0
  106. package/src/api-wrapper/paginate.ts +28 -0
  107. package/src/api-wrapper/redaction.ts +43 -0
  108. package/src/api-wrapper/shared.ts +21 -2
  109. package/src/api-wrapper/testing.ts +48 -0
  110. package/src/api-wrapper/transport.ts +68 -74
  111. package/src/api-wrapper/types.ts +186 -18
  112. package/src/array/index.ts +195 -42
  113. package/src/cache/createCache.ts +157 -0
  114. package/src/cache/index.ts +235 -83
  115. package/src/color/contrast.ts +163 -0
  116. package/src/color/index.ts +22 -0
  117. package/src/{math → color}/metricsSeriesColors.ts +47 -49
  118. package/src/cool-console-log/index.ts +128 -41
  119. package/src/crypto/encoding.ts +83 -0
  120. package/src/crypto/hash.ts +170 -0
  121. package/src/crypto/index.ts +26 -0
  122. package/src/crypto/sealer.ts +168 -0
  123. package/src/crypto/webhook.ts +86 -0
  124. package/src/date/index.ts +109 -34
  125. package/src/emitter/index.ts +82 -0
  126. package/src/error/index.ts +63 -0
  127. package/src/format/index.ts +389 -0
  128. package/src/function/index.ts +201 -0
  129. package/src/guard/index.ts +80 -0
  130. package/src/i18n/index.ts +125 -0
  131. package/src/index.ts +11 -7
  132. package/src/jwt/index.ts +199 -125
  133. package/src/math/index.ts +5 -10
  134. package/src/math/linearRegressionTrend.ts +33 -8
  135. package/src/math/scale.ts +17 -0
  136. package/src/object/index.ts +99 -0
  137. package/src/p-queue/index.ts +2 -0
  138. package/src/promise/index.ts +304 -9
  139. package/src/secrets/core.ts +348 -0
  140. package/src/secrets/deadline.ts +69 -0
  141. package/src/secrets/environment.ts +69 -0
  142. package/src/secrets/errors.ts +29 -0
  143. package/src/secrets/index.ts +79 -210
  144. package/src/secrets/infisical-cli.ts +99 -0
  145. package/src/secrets/infisical-config.ts +70 -0
  146. package/src/secrets/infisical-session.ts +42 -0
  147. package/src/secrets/infisical.ts +214 -66
  148. package/src/secrets/loaders.ts +24 -48
  149. package/src/secrets/vite.ts +44 -15
  150. package/src/secrets/worker-loader.ts +56 -0
  151. package/src/secrets/worker.ts +4 -0
  152. package/src/sitemap/index.ts +293 -130
  153. package/src/state/index.ts +133 -81
  154. package/src/storage/index.ts +187 -0
  155. package/src/string/index.ts +261 -23
  156. package/src/typedswitch/index.ts +134 -103
  157. package/src/types/index.ts +14 -0
  158. package/src/url/index.ts +146 -1
  159. package/src/zod/index.ts +105 -9
  160. package/src/zod/introspect.ts +103 -0
  161. package/src/zod/jsonToZodSchemaMapper.ts +44 -21
  162. package/src/zod/zodMinMaxFilter.ts +37 -13
  163. package/src/zod/zodToTypeString.ts +184 -181
  164. package/dist/api-wrapper/index.js +0 -250
  165. package/dist/gzip/index.d.ts +0 -2
  166. package/dist/gzip/index.js +0 -16
  167. package/dist/index.js +0 -1823
  168. package/dist/jwt/index.js +0 -19
  169. package/dist/sitemap/index.js +0 -552
  170. package/dist/src/gzip/index.js +0 -16
  171. package/dist/src/secrets/infisical.js +0 -1194
  172. package/dist/zod/index.js +0 -210
@@ -0,0 +1,17 @@
1
+ import type { SecretRequestOptions } from './deadline';
2
+ /** Project scope shared by the public Infisical loaders. */
3
+ export type InfisicalProjectOptions = {
4
+ readonly projectId: string;
5
+ /** Scope CLI user authentication; machine identities already have an organization. */
6
+ readonly organizationId: string;
7
+ readonly siteUrl?: string;
8
+ readonly secretPath?: string;
9
+ };
10
+ export type InfisicalScope<K extends string> = InfisicalProjectOptions & SecretRequestOptions & {
11
+ readonly keys: readonly K[];
12
+ readonly environment: string;
13
+ readonly siteUrl: string;
14
+ };
15
+ export declare function validateInfisicalScope(options: InfisicalScope<string>): void;
16
+ /** Validate at configuration time, including for JavaScript callers and local-only loads. */
17
+ export declare function validateInfisicalOrganizationId(organizationId: unknown): void;
@@ -0,0 +1,4 @@
1
+ /** Read routing metadata only. JWT signature and permissions are verified by Infisical. */
2
+ export declare function parseInfisicalSessionToken(token: string): {
3
+ organizationId?: string;
4
+ };
@@ -1,19 +1,14 @@
1
- import type { SecretEnvironment } from '.';
1
+ import { type InfisicalScope } from './infisical-config';
2
2
  export declare const DEFAULT_INFISICAL_SITE_URL = "https://eu.infisical.com";
3
- export declare function fetchInfisicalSecrets<SecretKey extends string>({ keys, projectId, environment, siteUrl, clientId, clientSecret }: {
4
- readonly keys: readonly SecretKey[];
5
- readonly projectId: string;
6
- readonly environment: SecretEnvironment;
7
- readonly siteUrl: string;
3
+ export type InfisicalAuthMode = 'auto' | 'http' | 'cli';
4
+ export declare function fetchInfisicalSecrets<K extends string>(options: InfisicalScope<K> & {
8
5
  readonly clientId: string;
9
6
  readonly clientSecret: string;
10
- }): Promise<Partial<Record<SecretKey, string>>>;
11
- export type LoadInfisicalSecretsFromEnvOptions<SecretKey extends string> = {
12
- readonly keys: readonly SecretKey[];
13
- readonly projectId: string;
14
- readonly environment: SecretEnvironment;
15
- readonly siteUrl: string;
7
+ }): Promise<Partial<Record<K, string>>>;
8
+ export type LoadInfisicalSecretsFromEnvOptions<K extends string> = InfisicalScope<K> & {
16
9
  readonly clientIdEnvKey: string;
17
10
  readonly clientSecretEnvKey: string;
11
+ readonly auth?: InfisicalAuthMode;
12
+ readonly reportSource?: (source: string) => void;
18
13
  };
19
- export declare function loadInfisicalSecrets<SecretKey extends string>({ keys, projectId, environment, siteUrl, clientIdEnvKey, clientSecretEnvKey }: LoadInfisicalSecretsFromEnvOptions<SecretKey>): Promise<Partial<Record<SecretKey, string>>>;
14
+ export declare function loadInfisicalSecrets<K extends string>(options: LoadInfisicalSecretsFromEnvOptions<K>): Promise<Partial<Record<K, string>>>;
@@ -1,16 +1,9 @@
1
- import type { SecretSetLoader, SecretSetLoaderContext } from './index';
2
- /**
3
- * Reads secrets from a Cloudflare Worker `env` bindings object (or any similar
4
- * `Record`), for Workers where `process.env` is not populated. Pass the same
5
- * object you get as `env` in your fetch handler, or values you’d read from
6
- * `import { env } from "cloudflare:workers"` in your Worker bundle — this
7
- * package does not import that module.
8
- */
9
- export declare function cloudflareWorkerEnvLoader<SecretKey extends string>(workerEnv: Record<string, unknown>): SecretSetLoader<SecretKey>;
10
- export declare function infisicalLoader<SecretKey extends string>(config: {
11
- readonly projectId: string;
1
+ import { type InfisicalProjectOptions } from './infisical-config';
2
+ import type { SecretSetLoader, SecretSetLoaderContext } from './core';
3
+ export { cloudflareWorkerEnvLoader } from './worker-loader';
4
+ export declare function infisicalLoader<SecretKey extends string>(config: InfisicalProjectOptions & {
12
5
  readonly clientId: string;
13
6
  readonly clientSecret: string;
14
- readonly siteUrl?: string;
7
+ readonly timeoutMs?: number;
15
8
  }): SecretSetLoader<SecretKey>;
16
9
  export declare function processEnvLoader<SecretKey extends string>(_ctx: SecretSetLoaderContext<SecretKey>): Promise<Partial<Record<SecretKey, string>>>;
@@ -1,9 +1,13 @@
1
- import type { SecretSet } from '.';
1
+ import type { SecretSet } from './core';
2
2
  export type ViteSecretSetPlugin = {
3
3
  name: string;
4
4
  config: () => {
5
5
  define: Record<string, string>;
6
6
  };
7
7
  };
8
- export declare function getViteDefine<SecretKey extends string>(secretSet: SecretSet<SecretKey>): Record<string, string>;
9
- export declare function viteSecretSetPlugin<SecretKey extends string>(secretSet: SecretSet<SecretKey>): ViteSecretSetPlugin;
8
+ export type ViteSecretSetOptions<K extends string> = {
9
+ /** Explicit acknowledgement that these values may be shipped to browsers. */
10
+ readonly publicKeys?: readonly K[];
11
+ };
12
+ export declare function getViteDefine<K extends string>(secretSet: Pick<SecretSet<K, unknown>, 'secrets'>, options?: ViteSecretSetOptions<K>): Record<string, string>;
13
+ export declare function viteSecretSetPlugin<K extends string>(secretSet: Pick<SecretSet<K, unknown>, 'secrets'>, options?: ViteSecretSetOptions<K>): ViteSecretSetPlugin;
@@ -0,0 +1,9 @@
1
+ import type { SecretSetLoader } from './core';
2
+ /**
3
+ * Reads secrets from a Cloudflare Worker `env` bindings object (or any similar
4
+ * `Record`), for Workers where `process.env` is not populated. Pass the same
5
+ * object you get as `env` in your fetch handler, or values you’d read from
6
+ * `import { env } from "cloudflare:workers"` in your Worker bundle — this
7
+ * package does not import that module.
8
+ */
9
+ export declare function cloudflareWorkerEnvLoader<SecretKey extends string>(workerEnv: Record<string, unknown>): SecretSetLoader<SecretKey>;
@@ -0,0 +1,3 @@
1
+ export * from './core';
2
+ export { cloudflareWorkerEnvLoader } from './worker-loader';
3
+ export type { SecretRequestOptions } from './deadline';
@@ -1,14 +1,56 @@
1
- interface SitemapOptions {
2
- filterIndexes?: string;
1
+ /** Substring, RegExp, or predicate. */
2
+ export type SitemapUrlFilter = string | RegExp | ((url: string) => boolean);
3
+ export interface SitemapOptions {
4
+ /** Only follow nested sitemaps (from a `<sitemapindex>`) that match. */
5
+ filterIndexes?: SitemapUrlFilter;
6
+ /** Only keep page URLs (from a `<urlset>`) that match. */
7
+ filterUrls?: SitemapUrlFilter;
3
8
  concurrency?: number;
4
9
  maxDepth?: number;
10
+ /** Stop once this many URLs have been collected. */
11
+ maxUrls?: number;
12
+ /** Per-request timeout in ms. */
5
13
  timeout?: number;
14
+ userAgent?: string;
15
+ fetch?: typeof fetch;
16
+ /** Called for failed robots.txt/sitemap requests. Defaults to `console.warn`. */
17
+ onError?: (url: string, error: unknown) => void;
18
+ /** Drop page URLs that robots.txt disallows for `userAgent`. Defaults to `false`. */
19
+ respectRobots?: boolean;
6
20
  }
21
+ /** The robots.txt rules that apply to one user agent. */
22
+ export interface RobotsRules {
23
+ allow: string[];
24
+ disallow: string[];
25
+ /** Every `Sitemap:` line, whatever group it is in. */
26
+ sitemaps: string[];
27
+ crawlDelaySec?: number;
28
+ }
29
+ export interface SitemapEntry {
30
+ loc: string;
31
+ lastmod?: string;
32
+ }
33
+ /**
34
+ * Parses robots.txt for one user agent (RFC 9309): the groups naming its
35
+ * product token (case-insensitive, versions ignored), else the `*` groups.
36
+ * Several matching groups are merged. Empty `Allow`/`Disallow` values are dropped.
37
+ */
38
+ export declare function parseRobotsTxt(body: string, userAgent?: string): RobotsRules;
39
+ /**
40
+ * Whether `url` (absolute, or a path) may be crawled under `rules` (RFC 9309):
41
+ * the longest matching pattern wins and `Allow` wins a tie. Patterns support
42
+ * `*` and a trailing `$`, and match the path plus query string.
43
+ */
44
+ export declare function isAllowedByRobots(rules: Pick<RobotsRules, 'allow' | 'disallow'>, url: string): boolean;
45
+ /**
46
+ * Gets all entries (`loc` + optional `lastmod`) from a domain by discovering and crawling its sitemaps
47
+ * @param domain - The root domain (e.g., 'example.com' or 'https://example.com')
48
+ * @throws When no sitemap can be discovered
49
+ */
50
+ export declare const getDomainSitemapEntries: (domain: string, options?: SitemapOptions) => Promise<SitemapEntry[]>;
7
51
  /**
8
52
  * Gets all URLs from a domain by discovering and crawling its sitemaps
9
- * @param domain - The root domain (e.g., 'https://example.com')
10
- * @param options - Configuration options for the crawler
11
- * @returns Promise<string[]> - Array of unique URLs found in the sitemap
53
+ * @param domain - The root domain (e.g., 'example.com' or 'https://example.com')
54
+ * @returns Array of unique URLs found in the sitemap
12
55
  */
13
56
  export declare const getDomainSitemap: (domain: string, options?: SitemapOptions) => Promise<string[]>;
14
- export {};