@useflagly/sdk-javascript 0.2.1 → 0.2.3

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
@@ -11,9 +11,9 @@ npm install @useflagly/sdk-javascript
11
11
  ## Uso
12
12
 
13
13
  ```js
14
- import { SystemSDK } from '@useflagly/sdk-javascript';
14
+ import { UseFlaglyClient } from '@useflagly/sdk-javascript';
15
15
 
16
- const sdk = new SystemSDK({ token: 'seu-api-token' });
16
+ const sdk = new UseFlaglyClient({ token: 'seu-api-token' });
17
17
  // A URL padrão é https://api.useflagly.com.br — pode ser sobrescrita com { baseUrl: '...' }
18
18
 
19
19
  // Validar flag
package/dist/index.d.ts CHANGED
@@ -13,20 +13,27 @@ export type SDKOptions = {
13
13
  token?: string;
14
14
  timeoutMs?: number;
15
15
  };
16
- export declare class SystemSDK {
16
+ export declare class FlaglyError extends Error {
17
+ readonly statusCode: number;
18
+ readonly body: string;
19
+ constructor(statusCode: number, body: string);
20
+ get isSubscriptionError(): boolean;
21
+ get isUnauthorized(): boolean;
22
+ }
23
+ export declare class UseFlaglyClient {
17
24
  private baseUrl;
18
25
  private token?;
19
26
  constructor(opts?: SDKOptions);
20
27
  private headers;
21
28
  private request;
22
- validateFlag(slug: string, body: ValidateBody, environment?: string): Promise<any>;
23
- getFlagCache(slug: string, identifier?: string): Promise<any>;
24
- validateFlow(slug: string, body: ValidateBody, environment?: string): Promise<any>;
25
- getFlowCache(slug: string, identifier?: string): Promise<any>;
26
- validateFlowPart(slug: string, body: ValidateBody, environment?: string): Promise<any>;
27
- getFlowPartCache(slug: string, identifier?: string): Promise<any>;
28
- validateScenario(slug: string, body: ValidateBody, environment?: string): Promise<any>;
29
- getScenarioCache(slug: string, identifier?: string): Promise<any>;
30
- initializeFlags(payload: ReceiveMessage, environment?: string): Promise<any>;
31
- getResult(cpf: string): Promise<any>;
29
+ validateFlag<T = unknown>(slug: string, body: ValidateBody, environment?: string): Promise<T | null>;
30
+ getFlagCache<T = unknown>(slug: string, identifier?: string): Promise<T | null>;
31
+ validateFlow<T = unknown>(slug: string, body: ValidateBody, environment?: string): Promise<T | null>;
32
+ getFlowCache<T = unknown>(slug: string, identifier?: string): Promise<T | null>;
33
+ validateFlowPart<T = unknown>(slug: string, body: ValidateBody, environment?: string): Promise<T | null>;
34
+ getFlowPartCache<T = unknown>(slug: string, identifier?: string): Promise<T | null>;
35
+ validateScenario<T = unknown>(slug: string, body: ValidateBody, environment?: string): Promise<T | null>;
36
+ getScenarioCache<T = unknown>(slug: string, identifier?: string): Promise<T | null>;
37
+ initializeFlags<T = unknown>(payload: ReceiveMessage, environment?: string): Promise<T | null>;
38
+ getResult<T = unknown>(cpf: string): Promise<T | null>;
32
39
  }
package/dist/index.js CHANGED
@@ -3,10 +3,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SystemSDK = void 0;
6
+ exports.UseFlaglyClient = exports.FlaglyError = void 0;
7
7
  const cross_fetch_1 = __importDefault(require("cross-fetch"));
8
+ class FlaglyError extends Error {
9
+ constructor(statusCode, body) {
10
+ super(`UseFlagly error ${statusCode}: ${body}`);
11
+ this.statusCode = statusCode;
12
+ this.body = body;
13
+ this.name = 'FlaglyError';
14
+ }
15
+ get isSubscriptionError() {
16
+ return this.statusCode === 403;
17
+ }
18
+ get isUnauthorized() {
19
+ return this.statusCode === 401;
20
+ }
21
+ }
22
+ exports.FlaglyError = FlaglyError;
8
23
  const DEFAULT_BASE_URL = 'https://api.useflagly.com.br';
9
- class SystemSDK {
24
+ class UseFlaglyClient {
10
25
  constructor(opts = {}) {
11
26
  var _a;
12
27
  this.baseUrl = ((_a = opts.baseUrl) !== null && _a !== void 0 ? _a : DEFAULT_BASE_URL).replace(/\/+$/, '');
@@ -31,6 +46,9 @@ class SystemSDK {
31
46
  if (res.status === 204)
32
47
  return null;
33
48
  const text = await res.text();
49
+ if (res.status >= 400) {
50
+ throw new FlaglyError(res.status, text);
51
+ }
34
52
  try {
35
53
  return JSON.parse(text);
36
54
  }
@@ -79,4 +97,4 @@ class SystemSDK {
79
97
  return this.request(`/validate/result/${encodeURIComponent(cpf)}`, 'GET');
80
98
  }
81
99
  }
82
- exports.SystemSDK = SystemSDK;
100
+ exports.UseFlaglyClient = UseFlaglyClient;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@useflagly/sdk-javascript",
3
- "version": "0.2.1",
4
- "description": "JavaScript SDK para SystemModule (FeatureFlag API)",
3
+ "version": "0.2.3",
4
+ "description": "JavaScript SDK para UseFlagly API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
@@ -23,7 +23,8 @@
23
23
  "author": "",
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
- "cross-fetch": "^3.1.8"
26
+ "cross-fetch": "^3.1.8",
27
+ "express-basic-auth": "^1.2.1"
27
28
  },
28
29
  "devDependencies": {
29
30
  "typescript": "^5.9.3"