@useflagly/sdk-javascript 0.2.2 → 0.2.4

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/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 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
+ }
16
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<T = unknown>(slug: string, body: ValidateBody, environment?: string): Promise<string | T | null>;
23
- getFlagCache<T = unknown>(slug: string, identifier?: string): Promise<string | T | null>;
24
- validateFlow<T = unknown>(slug: string, body: ValidateBody, environment?: string): Promise<string | T | null>;
25
- getFlowCache<T = unknown>(slug: string, identifier?: string): Promise<string | T | null>;
26
- validateFlowPart<T = unknown>(slug: string, body: ValidateBody, environment?: string): Promise<string | T | null>;
27
- getFlowPartCache<T = unknown>(slug: string, identifier?: string): Promise<string | T | null>;
28
- validateScenario<T = unknown>(slug: string, body: ValidateBody, environment?: string): Promise<string | T | null>;
29
- getScenarioCache<T = unknown>(slug: string, identifier?: string): Promise<string | T | null>;
30
- initializeFlags<T = unknown>(payload: ReceiveMessage, environment?: string): Promise<string | T | null>;
31
- getResult<T = unknown>(cpf: string): Promise<string | T | null>;
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,8 +3,23 @@ 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.UseFlaglyClient = 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
24
  class UseFlaglyClient {
10
25
  constructor(opts = {}) {
@@ -31,6 +46,9 @@ class UseFlaglyClient {
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useflagly/sdk-javascript",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "JavaScript SDK para UseFlagly API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",