-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
175 lines (172 loc) · 4.73 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import {
pullHydratedConfigurations,
pullFlattenedConfigurations,
} from './src/configurations.js';
import {DEFAULT_PROFILE, DEFAULT_ENDPOINT} from './src/constants.js';
/**
* This is used if you have a specific
* node that you want to pull, and
* you don't care about pulling different configurations
* @function getHydratedConfigurations
* @param {string} apiKey - The api key for the api
* @param {string} nodeId - The id of the node to be pulled from Konfigs
* @param {string} applicationId - Id of the application which contains
* the requested node
* @param {string} profile - Profile of published configs
* @param {string} endpoint - Endpoint of the konfigs api
* @return {Promise<*|null|undefined>}
* @example
* const configs = await pullHydratedConfigurations(
* "myApiKey",
* "myNodeId",
* "myApplicationId")
* console.log(configs)
* // {
* // "configurations": [
* // {
* // "nodeId": "5e9f8f8f-f8f8-f8f8-f8f8-f8f8f8f8f8f8",
* // "data": [
* // {
* // "key": "key1",
* // "value": {
* // "value": "value1"
* // "datatype:"ARRAY |
* // OBJECT | STRING | NUMBER | BOOLEAN"
* // }
* // },
* //}
* //]
* // }
* //
*/
export function getHydratedConfigs(
apiKey,
nodeId,
applicationId,
profile = DEFAULT_PROFILE,
endpoint = DEFAULT_ENDPOINT,
) {
return pullHydratedConfigurations(
apiKey,
endpoint,
nodeId,
applicationId,
profile,
);
}
/**
* Use class if you intend to initialize once and use it for multiple nodes
* @class KonfigsSdk
* @public
* @property {string} apiKey - Konfigs API key
* @property {string} nodeId - Konfigs node id
* @property {string} applicationId - Konfigs application id
* @property {string} profile - Konfigs profile
* @property {string} endpoint - Konfigs endpoint
* @return {KonfigsSdk} - Konfigs SDK instance
* @example
* const konfigs = new KonfigsSdk(apiKey, nodeId, applicationId, profile, endpoint)
* const configs = await konfigs.getHydratedConfigs()
* console.log(configs)
* // {
* // "configurations": [
* // {
* // "nodeId": "5e9f8f8f-f8f8-f8f8-f8f8-f8f8f8f8f8f8",
* // "data": [
* // {
* // "key": "key1",
* // "value": {
* // "value": "value1"
* // "datatype:"ARRAY |
* // OBJECT | STRING | NUMBER | BOOLEAN"
* // }
* // },
* //}
* //]
* // }
* //
*/
export default class KonfigsSdk {
/**
* @param {string} applicationId
*/
set ApplicationId(applicationId) {
this.applicationId = applicationId;
}
/**
* @param {string} endpoint
*/
set Endpoint(endpoint) {
this.endpoint = endpoint;
}
/**
* @param {string} profile
*/
set Profile(profile) {
this.profile = profile;
}
/**
* @param {string} apiKey
*/
set ApiKey(apiKey) {
this.apiKey = apiKey;
}
/**
* @param {string} nodeId
*/
set NodeId(nodeId) {
this.nodeId = nodeId;
}
/**
* Initializes Konfigs SDK instance
* @function KonfigsSdk#constructor
* @param {string} apiKey - API Key which is generated for your organization
* @param {string} applicationId - Application
* id where the node is part of
* @param {string} profile - Publish Profile of the node item
* @param {string} endpoint - Endpoint of the Konfigs service
*/
constructor(
apiKey,
applicationId,
profile = DEFAULT_PROFILE,
endpoint = DEFAULT_ENDPOINT,
) {
this.apiKey = apiKey;
this.applicationId = applicationId;
this.profile = profile;
this.endpoint = endpoint;
}
/**
* This function is called to retrieve your published configurations
* @function KonfigsSdk#getHydratedConfigs
* @param {string} nodeId - Konfigs node id
* @return {Promise} - Promise containing hydrated configurations
*/
getHydratedConfigs(nodeId) {
return pullHydratedConfigurations(
this.apiKey,
this.endpoint,
nodeId,
this.applicationId,
this.profile,
);
}
/**
* This function is called to retrieve your flattened
* published configurations
* @function KonfigsSdk#getFlattenedConfigs
* @param {string} nodeId - Konfigs node id
* @return {Promise} - Promise containing
* flattened configurations
*/
getFlattenedConfigs(nodeId) {
return pullFlattenedConfigurations(
this.apiKey,
this.endpoint,
nodeId,
this.applicationId,
this.profile,
);
}
}