@useflagly/sdk-javascript 0.1.1 → 0.2.1
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.
- package/README.md +33 -38
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -2
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,63 +1,58 @@
|
|
|
1
1
|
# @useflagly/sdk-javascript
|
|
2
2
|
|
|
3
|
-
SDK JavaScript para
|
|
3
|
+
SDK JavaScript para a API de feature flags da Flagly.
|
|
4
4
|
|
|
5
5
|
## Instalação
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
.npmrc (no repositório ou no CI):
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
@useflagly:registry=https://npm.pkg.github.com
|
|
13
|
-
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
Para instalar em outro projeto (após publicar):
|
|
17
|
-
|
|
18
|
-
```
|
|
7
|
+
```bash
|
|
19
8
|
npm install @useflagly/sdk-javascript
|
|
20
9
|
```
|
|
21
10
|
|
|
22
11
|
## Uso
|
|
23
12
|
|
|
24
13
|
```js
|
|
25
|
-
import { SystemSDK } from '@
|
|
14
|
+
import { SystemSDK } from '@useflagly/sdk-javascript';
|
|
26
15
|
|
|
27
|
-
const sdk = new SystemSDK({
|
|
16
|
+
const sdk = new SystemSDK({ token: 'seu-api-token' });
|
|
17
|
+
// A URL padrão é https://api.useflagly.com.br — pode ser sobrescrita com { baseUrl: '...' }
|
|
28
18
|
|
|
29
19
|
// Validar flag
|
|
30
|
-
await sdk.validateFlag('
|
|
20
|
+
await sdk.validateFlag('minha-flag', { identifier: '00000000000' }, 'PRD');
|
|
31
21
|
|
|
32
22
|
// Ler cache de flag
|
|
33
|
-
await sdk.getFlagCache('
|
|
23
|
+
await sdk.getFlagCache('minha-flag', '00000000000');
|
|
24
|
+
|
|
25
|
+
// Validar flow
|
|
26
|
+
await sdk.validateFlow('meu-flow', { identifier: '00000000000' }, 'PRD');
|
|
27
|
+
|
|
28
|
+
// Validar flow-part
|
|
29
|
+
await sdk.validateFlowPart('meu-flow-part', { identifier: '00000000000' }, 'PRD');
|
|
30
|
+
|
|
31
|
+
// Validar scenario
|
|
32
|
+
await sdk.validateScenario('meu-scenario', { identifier: '00000000000' }, 'PRD');
|
|
34
33
|
|
|
35
34
|
// Inicializar (producer)
|
|
36
|
-
await sdk.initializeFlags({
|
|
35
|
+
await sdk.initializeFlags({ identifier: '...', slug: '...', companyId: 1 });
|
|
36
|
+
|
|
37
|
+
// Buscar resultado
|
|
38
|
+
await sdk.getResult('00000000000');
|
|
37
39
|
```
|
|
38
40
|
|
|
39
|
-
## Métodos
|
|
41
|
+
## Métodos
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
| Método | Descrição |
|
|
44
|
+
|---|---|
|
|
45
|
+
| `validateFlag(slug, body, environment?)` | Valida uma feature flag |
|
|
46
|
+
| `getFlagCache(slug, identifier?)` | Lê o cache de uma flag |
|
|
47
|
+
| `validateFlow(slug, body, environment?)` | Valida um flow |
|
|
48
|
+
| `getFlowCache(slug, identifier?)` | Lê o cache de um flow |
|
|
49
|
+
| `validateFlowPart(slug, body, environment?)` | Valida um flow-part |
|
|
50
|
+
| `getFlowPartCache(slug, identifier?)` | Lê o cache de um flow-part |
|
|
51
|
+
| `validateScenario(slug, body, environment?)` | Valida um scenario |
|
|
52
|
+
| `getScenarioCache(slug, identifier?)` | Lê o cache de um scenario |
|
|
53
|
+
| `initializeFlags(payload, environment?)` | Inicializa flags (producer) |
|
|
54
|
+
| `getResult(identifier)` | Busca resultado por identifier |
|
|
51
55
|
|
|
52
|
-
## Publicação no GitHub Packages
|
|
53
56
|
|
|
54
|
-
1. Crie um Personal Access Token com `write:packages` e `read:packages` (scope).
|
|
55
|
-
2. Adicione o token como `GITHUB_TOKEN` no CI ou no `~/.npmrc` local.
|
|
56
|
-
3. Ajuste `package.json` `name` e `repository.url` se necessário (já configurado para `useflagly`).
|
|
57
|
-
4. Rodar:
|
|
58
57
|
|
|
59
|
-
```bash
|
|
60
|
-
npm publish --access=restricted
|
|
61
|
-
```
|
|
62
58
|
|
|
63
|
-
> Observação: para pacotes sob escopo de organização, garanta que o registro do escopo está apontado para `https://npm.pkg.github.com` no `.npmrc`.
|
package/dist/index.d.ts
CHANGED
|
@@ -9,14 +9,14 @@ export type ReceiveMessage = {
|
|
|
9
9
|
context?: Record<string, any>;
|
|
10
10
|
};
|
|
11
11
|
export type SDKOptions = {
|
|
12
|
-
baseUrl
|
|
12
|
+
baseUrl?: string;
|
|
13
13
|
token?: string;
|
|
14
14
|
timeoutMs?: number;
|
|
15
15
|
};
|
|
16
16
|
export declare class SystemSDK {
|
|
17
17
|
private baseUrl;
|
|
18
18
|
private token?;
|
|
19
|
-
constructor(opts
|
|
19
|
+
constructor(opts?: SDKOptions);
|
|
20
20
|
private headers;
|
|
21
21
|
private request;
|
|
22
22
|
validateFlag(slug: string, body: ValidateBody, environment?: string): Promise<any>;
|
package/dist/index.js
CHANGED
|
@@ -5,9 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.SystemSDK = void 0;
|
|
7
7
|
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
8
|
+
const DEFAULT_BASE_URL = 'https://api.useflagly.com.br';
|
|
8
9
|
class SystemSDK {
|
|
9
|
-
constructor(opts) {
|
|
10
|
-
|
|
10
|
+
constructor(opts = {}) {
|
|
11
|
+
var _a;
|
|
12
|
+
this.baseUrl = ((_a = opts.baseUrl) !== null && _a !== void 0 ? _a : DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
11
13
|
this.token = opts.token;
|
|
12
14
|
}
|
|
13
15
|
headers(env) {
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useflagly/sdk-javascript",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "JavaScript SDK para SystemModule (FeatureFlag API)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
8
10
|
"publishConfig": {
|
|
9
11
|
"registry": "https://registry.npmjs.org",
|
|
10
12
|
"access": "public"
|