@useflagly/sdk-javascript 0.1.1 → 0.2.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.
package/README.md CHANGED
@@ -1,63 +1,54 @@
1
1
  # @useflagly/sdk-javascript
2
2
 
3
- SDK JavaScript para interagir com as rotas expostas pelo `SystemModule` (FeatureFlag API).
3
+ SDK JavaScript para a API de feature flags da Flagly.
4
4
 
5
5
  ## Instalação
6
6
 
7
- Configurar publicação/registro para o GitHub Packages (ex.: `useflagly`):
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 '@featureflag/sdk-system';
14
+ import { SystemSDK } from '@useflagly/sdk-javascript';
26
15
 
27
- const sdk = new SystemSDK({ baseUrl: 'https://api.example.com', token: process.env.API_TOKEN });
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('my-flag-slug', { cpf: '00000000000', context: { userId: '123' } }, 'PRD');
20
+ await sdk.validateFlag('minha-flag', { identifier: '00000000000' }, 'PRD');
31
21
 
32
22
  // Ler cache de flag
33
- await sdk.getFlagCache('my-flag-slug', '00000000000');
34
-
35
- // Inicializar (producer)
36
- await sdk.initializeFlags({ pattern: '...' });
37
- ```
23
+ await sdk.getFlagCache('minha-flag', '00000000000');
38
24
 
39
- ## Métodos principais
25
+ // Validar flow
26
+ await sdk.validateFlow('meu-flow', { identifier: '00000000000' }, 'PRD');
40
27
 
41
- - `validateFlag(slug, body, environment?)`
42
- - `getFlagCache(slug, cpf?)`
43
- - `validateFlow(slug, body, environment?)`
44
- - `getFlowCache(slug, cpf?)`
45
- - `validateFlowPart(...)`
46
- - `getFlowPartCache(...)`
47
- - `validateScenario(...)`
48
- - `getScenarioCache(...)`
49
- - `initializeFlags(payload, environment?)`
50
- - `getResult(cpf)`
28
+ // Validar flow-part
29
+ await sdk.validateFlowPart('meu-flow-part', { identifier: '00000000000' }, 'PRD');
51
30
 
52
- ## Publicação no GitHub Packages
31
+ // Validar scenario
32
+ await sdk.validateScenario('meu-scenario', { identifier: '00000000000' }, 'PRD');
53
33
 
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:
34
+ // Inicializar (producer)
35
+ await sdk.initializeFlags({ identifier: '...', slug: '...', companyId: 1 });
58
36
 
59
- ```bash
60
- npm publish --access=restricted
37
+ // Buscar resultado
38
+ await sdk.getResult('00000000000');
61
39
  ```
62
40
 
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`.
41
+ ## Métodos
42
+
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 |
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: string;
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: SDKOptions);
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
- this.baseUrl = opts.baseUrl.replace(/\/+$/, '');
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@useflagly/sdk-javascript",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "JavaScript SDK para SystemModule (FeatureFlag API)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",