@aptly-as/types 2.7.15 → 2.8.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/enums/index.d.ts CHANGED
@@ -83,11 +83,6 @@ export declare enum AptlySignageSignerRef {
83
83
  Customer = "customer",
84
84
  Admin = "admin"
85
85
  }
86
- export declare enum AptlyErrorCode {
87
- Default = "default",
88
- InvalidFields = "invalid-fields",
89
- SessionExpired = "session-expired"
90
- }
91
86
  export declare enum AptlyQueueDownloadType {
92
87
  Document = "document",
93
88
  Image = "image"
package/enums/index.js CHANGED
@@ -95,12 +95,6 @@ export var AptlySignageSignerRef;
95
95
  AptlySignageSignerRef["Customer"] = "customer";
96
96
  AptlySignageSignerRef["Admin"] = "admin";
97
97
  })(AptlySignageSignerRef || (AptlySignageSignerRef = {}));
98
- export var AptlyErrorCode;
99
- (function (AptlyErrorCode) {
100
- AptlyErrorCode["Default"] = "default";
101
- AptlyErrorCode["InvalidFields"] = "invalid-fields";
102
- AptlyErrorCode["SessionExpired"] = "session-expired";
103
- })(AptlyErrorCode || (AptlyErrorCode = {}));
104
98
  export var AptlyQueueDownloadType;
105
99
  (function (AptlyQueueDownloadType) {
106
100
  AptlyQueueDownloadType["Document"] = "document";
package/error/error.d.ts CHANGED
@@ -1,25 +1,29 @@
1
+ import { AptlyErrorCode } from './error.utils.js';
1
2
  export interface AptlyErrorBody {
2
3
  name: 'AptlyError';
3
4
  status: number;
4
- title: string;
5
+ message: string;
5
6
  id?: string;
6
- code?: number;
7
+ code?: AptlyErrorCode;
7
8
  detail?: string;
8
9
  errors?: AptlyErrorBodySimple[];
9
10
  link?: string;
11
+ title?: string;
10
12
  error?: string;
11
13
  }
12
- export type AptlyErrorBodySimple = Pick<AptlyErrorBody, 'status' | 'title' | 'detail' | 'link'>;
14
+ export type AptlyErrorBodySimple = Pick<AptlyErrorBody, 'status' | 'message' | 'detail' | 'link'>;
13
15
  export declare class AptlyError extends Error {
14
16
  readonly data: Omit<AptlyErrorBody, 'name'>;
15
17
  readonly error?: Error | undefined;
16
18
  readonly name = "AptlyError";
17
- id: string;
18
- constructor(data: Omit<AptlyErrorBody, 'name'>, error?: Error | undefined);
19
+ readonly _status: number;
20
+ readonly id: string;
19
21
  static fromFetchResponse(response: Response): Promise<AptlyError>;
22
+ static fromResponse(response: Response): Promise<AptlyError>;
23
+ constructor(data: Omit<AptlyErrorBody, 'name'>, error?: Error | undefined);
20
24
  get status(): number;
21
25
  get title(): string;
22
- get code(): number | undefined;
26
+ get code(): AptlyErrorCode | undefined;
23
27
  get detail(): string | undefined;
24
28
  get link(): string | undefined;
25
29
  get errors(): AptlyErrorBodySimple[];
package/error/error.js CHANGED
@@ -1,14 +1,14 @@
1
1
  export class AptlyError extends Error {
2
- constructor(data, error) {
3
- super(data.title);
4
- this.data = data;
5
- this.error = error;
6
- this.name = 'AptlyError';
7
- this.id = data.id || '';
2
+ static fromFetchResponse(response) {
3
+ return AptlyError.fromResponse(response);
8
4
  }
9
- static async fromFetchResponse(response) {
10
- if (response.headers.get('content-type') !== 'application/json') {
5
+ static async fromResponse(response) {
6
+ const contentType = response.headers.get('content-type');
7
+ if (contentType?.includes('application/json')) {
11
8
  const body = await response.json();
9
+ if (!body.link) {
10
+ body.link = response.url;
11
+ }
12
12
  if (body.name === AptlyError.name) {
13
13
  return new AptlyError(body);
14
14
  }
@@ -16,15 +16,24 @@ export class AptlyError extends Error {
16
16
  throw new AptlyError({
17
17
  id: 'unknown',
18
18
  status: response.status,
19
- title: response.statusText,
19
+ message: response.statusText,
20
20
  detail: `Failed to fetch from url: ${response.url}`,
21
21
  });
22
22
  }
23
+ constructor(data, error) {
24
+ super(data.title || data.message);
25
+ this.data = data;
26
+ this.error = error;
27
+ this.name = 'AptlyError';
28
+ this._status = 500;
29
+ this._status = data.status;
30
+ this.id = data.id || '';
31
+ }
23
32
  get status() {
24
- return this.data.status;
33
+ return this._status;
25
34
  }
26
35
  get title() {
27
- return this.data.title;
36
+ return this.data.message;
28
37
  }
29
38
  get code() {
30
39
  return this.data.code;
@@ -0,0 +1,5 @@
1
+ export declare enum AptlyErrorCode {
2
+ NotFound = 4040,
3
+ Duplicate = 4090,
4
+ Error = 5000
5
+ }
@@ -0,0 +1,6 @@
1
+ export var AptlyErrorCode;
2
+ (function (AptlyErrorCode) {
3
+ AptlyErrorCode[AptlyErrorCode["NotFound"] = 4040] = "NotFound";
4
+ AptlyErrorCode[AptlyErrorCode["Duplicate"] = 4090] = "Duplicate";
5
+ AptlyErrorCode[AptlyErrorCode["Error"] = 5000] = "Error";
6
+ })(AptlyErrorCode || (AptlyErrorCode = {}));
package/error/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './error.js';
2
+ export * from './error.utils.js';
package/error/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export * from './error.js';
2
+ export * from './error.utils.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aptly-as/types",
3
- "version": "2.7.15",
3
+ "version": "2.8.1",
4
4
  "description": "Aptly types and enums",
5
5
  "type": "module",
6
6
  "main": "./index.js",