Skip to content

Commit d40e1f6

Browse files
committed
feat: change name to fetchAllConfigs
1 parent a84cdd4 commit d40e1f6

4 files changed

Lines changed: 50 additions & 13 deletions

File tree

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Cloud Config
2+
3+
Manage your cloud configuration with ease.
4+
5+
## Installation
6+
7+
```bash
8+
npm install cloud-configuration
9+
```
10+
11+
or
12+
13+
```bash
14+
yarn add cloud-configuration
15+
```
16+
17+
## Basic Usage
18+
19+
```typescript
20+
import { fetchAllConfigs, getCloudConfig } from "cloud-configuration";
21+
22+
const configs = await fetchAllConfigs({
23+
orgId: "U2FsdGVkX1/1dETBp2nec8Xe2KtA/V8ndJo/uDqXrpc=",
24+
});
25+
26+
const auFlagUrl = getCloudConfig({ configs, featureKey: "au_flag_url" });
27+
```
28+
29+
## License
30+
31+
MIT

cloud-config.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export const CLOUD_CONFIG_API_ENDPOINT =
2121
process.env.NEXT_PUBLIC_CLOUD_CONFIG_API_ENDPOINT ||
2222
"http://localhost:3001/api";
2323

24+
export const CLOUD_CONFIG_ORG_ID =
25+
process.env.NEXT_PUBLIC_CLOUD_CONFIG_ORG_ID ||
26+
"Missing NEXT_PUBLIC_CLOUD_CONFIG_ORG_ID in .env";
27+
2428
const couldConfigSecretClient =
2529
process.env.NEXT_PUBLIC_CLOUD_CONFIG_CLIENT_ENCRYPT_SECRET;
2630

@@ -135,14 +139,14 @@ export const getCloudConfig = <T>({
135139
return config.value as T;
136140
};
137141

138-
export const fetchCloudConfig = async ({
139-
orgId,
142+
export const fetchAllConfigs = async ({
143+
orgId = CLOUD_CONFIG_ORG_ID,
140144
serverSide = false,
141145
accessToken,
142146
cache = "default",
143147
apiPrefix = CLOUD_CONFIG_API_ENDPOINT,
144148
}: {
145-
orgId: string;
149+
orgId?: string;
146150
serverSide?: boolean;
147151
accessToken?: string;
148152
cache?: RequestCache;
@@ -167,26 +171,28 @@ export const fetchCloudConfig = async ({
167171
cache: cache,
168172
});
169173
if (!response.ok) {
170-
console.log("🚀 Debug fetchCloudConfig requestData:", requestData);
174+
console.log("🚀 Debug fetchAllConfigs requestData:", requestData);
171175

172176
throw new Error(
173-
`😢 fetchCloudConfig failed: ${response.status}/${response.statusText} - ${apiEndpoint}`
177+
`😢 fetchAllConfigs failed: ${response.status}/${response.statusText} - ${apiEndpoint}`
174178
);
175179
}
176180
const duration = Date.now() - startTime;
177181

178182
console.log(
179-
`fetchCloudConfig in ${(duration / 1000).toFixed(2)} seconds ${
183+
`fetchAllConfigs in ${(duration / 1000).toFixed(2)} seconds ${
180184
duration > 2000 ? "💔" : "-"
181185
} ${apiEndpoint}`
182186
);
183187

184-
return (await response.json()) as CloudConfigData[];
188+
const configs = ((await response.json()) || []) as CloudConfigData[];
189+
190+
return parseAllConfigs(configs, serverSide);
185191
} catch (error) {
186-
console.log("💔💔💔 fetchCloudConfig error:", error);
192+
console.log("💔💔💔 fetchAllConfigs error:", error);
187193
}
188194

189-
return null;
195+
return [];
190196
};
191197

192198
export default {
@@ -198,5 +204,5 @@ export default {
198204
parseSingleConfig,
199205
parseAllConfigs,
200206
getCloudConfig,
201-
fetchCloudConfig,
207+
fetchAllConfigs,
202208
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cloud-configuration",
3-
"version": "0.1.0",
3+
"version": "0.1.3",
44
"description": "This package allows you to use CloudConfig easily.",
55
"author": "Alex Zeng",
66
"license": "MIT",

test/test-config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { fetchCloudConfig } from "../cloud-config";
1+
import { fetchAllConfigs } from "../cloud-config";
22

33
console.log(
44
"test-config.ts",
5-
fetchCloudConfig({
5+
fetchAllConfigs({
66
orgId: "U2FsdGVkX1/1dETBp2nec8Xe2KtA/V8ndJo/uDqXrpc=",
77
})
88
);

0 commit comments

Comments
 (0)