hanzio 1.0.7 → 1.0.9

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.
@@ -0,0 +1,108 @@
1
+ import { z } from 'zod'
2
+ import { createApiClient } from '../api-wrapper'
3
+ import type { SecretSetLoaderContext } from '.'
4
+
5
+ const defaultFetch = globalThis.fetch
6
+
7
+ const infisicalAuthResponseSchema = z.object({
8
+ accessToken: z.string()
9
+ })
10
+
11
+ const infisicalSecretSchema = z.object({
12
+ secretKey: z.string(),
13
+ secretValue: z.string()
14
+ })
15
+
16
+ const infisicalSecretsResponseSchema = z.object({
17
+ secrets: z.array(infisicalSecretSchema)
18
+ })
19
+
20
+ export async function loadInfisicalSecrets<SecretKey extends string>({
21
+ keys,
22
+ projectId,
23
+ environment,
24
+ siteUrl,
25
+ clientIdEnvKey,
26
+ clientSecretEnvKey
27
+ }: SecretSetLoaderContext<SecretKey>): Promise<
28
+ Partial<Record<SecretKey, string>>
29
+ > {
30
+ const clientId = process.env[clientIdEnvKey]
31
+ const clientSecret = process.env[clientSecretEnvKey]
32
+
33
+ if (!clientId || !clientSecret) {
34
+ throw new Error('Missing Infisical credentials')
35
+ }
36
+
37
+ const infisical = createInfisicalApiClient(siteUrl)
38
+ const { data: auth } = await infisical.request('login', {
39
+ reqBody: {
40
+ clientId,
41
+ clientSecret
42
+ }
43
+ })
44
+ const { data } = await infisical.request('listSecrets', {
45
+ reqHeaders: {
46
+ Authorization: `Bearer ${auth.accessToken}`
47
+ },
48
+ reqQuery: {
49
+ environment,
50
+ projectId,
51
+ secretPath: '/',
52
+ viewSecretValue: true,
53
+ expandSecretReferences: true,
54
+ includeImports: true
55
+ }
56
+ })
57
+
58
+ const wantedKeys = new Set<string>(keys)
59
+ return Object.fromEntries(
60
+ data.secrets
61
+ .filter((secret) => wantedKeys.has(secret.secretKey))
62
+ .map((secret) => [secret.secretKey, secret.secretValue])
63
+ ) as Partial<Record<SecretKey, string>>
64
+ }
65
+
66
+ function createInfisicalApiClient(siteUrl: string) {
67
+ return createApiClient({
68
+ name: 'infisical',
69
+ baseApiUrls: {
70
+ infisical: siteUrl
71
+ },
72
+ defaultBaseApiUrl: 'infisical',
73
+ fetch: getFetch(),
74
+ retries: 1,
75
+ endpoints: {
76
+ login: {
77
+ method: 'POST',
78
+ path: '/api/v1/auth/universal-auth/login',
79
+ reqBodySchema: z.object({
80
+ clientId: z.string(),
81
+ clientSecret: z.string()
82
+ }),
83
+ resSchema: infisicalAuthResponseSchema,
84
+ reqBodyFormat: 'json'
85
+ },
86
+ listSecrets: {
87
+ method: 'GET',
88
+ path: '/api/v4/secrets',
89
+ reqHeadersSchema: z.object({
90
+ Authorization: z.string()
91
+ }),
92
+ reqQuerySchema: z.object({
93
+ projectId: z.string(),
94
+ environment: z.string(),
95
+ secretPath: z.string(),
96
+ viewSecretValue: z.boolean(),
97
+ expandSecretReferences: z.boolean(),
98
+ includeImports: z.boolean()
99
+ }),
100
+ resSchema: infisicalSecretsResponseSchema
101
+ }
102
+ }
103
+ })
104
+ }
105
+
106
+ function getFetch(): typeof fetch {
107
+ return globalThis.fetch ?? defaultFetch
108
+ }
package/src/gzip/index.ts DELETED
@@ -1,29 +0,0 @@
1
- import pako from 'pako'
2
-
3
- export function compressString(input: string): string {
4
- // Convert string to Uint8Array
5
- const uint8Array = new TextEncoder().encode(input)
6
-
7
- // Compress the Uint8Array
8
- const compressed = pako.deflate(uint8Array)
9
-
10
- // Convert compressed Uint8Array to base64 string for storage
11
- return btoa(
12
- String.fromCharCode.apply(null, compressed as unknown as number[])
13
- )
14
- }
15
-
16
- export function decompressString(compressedString: string): string {
17
- // Convert base64 string back to Uint8Array
18
- const compressedData = new Uint8Array(
19
- atob(compressedString)
20
- .split('')
21
- .map((char) => char.charCodeAt(0))
22
- )
23
-
24
- // Decompress the Uint8Array
25
- const decompressed = pako.inflate(compressedData)
26
-
27
- // Convert Uint8Array back to string
28
- return new TextDecoder().decode(decompressed)
29
- }