ad2app-lib 1.0.2 → 1.0.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.
@@ -5,12 +5,31 @@ interface DriverConfig {
5
5
  getHeaders?: () => HeadersInit;
6
6
  }
7
7
  export declare function configureApiDriver(config: DriverConfig): void;
8
- export declare function fetchCall<T, Q>(path: string, fetchParams?: FetchParams<Q>, method?: HttpMethod): Promise<T>;
8
+ type FetchCallArgs<Q> = [
9
+ path: string,
10
+ params?: FetchParams<Q>,
11
+ method?: HttpMethod,
12
+ headers?: HeadersInit,
13
+ transformers?: {
14
+ body?: (body: any) => BodyInit;
15
+ }
16
+ ];
17
+ export declare function fetchCall<T, Q>(...args: FetchCallArgs<Q>): Promise<T>;
9
18
  export declare function apiDriver(): {
10
- get: <T, Q>(path: string, params?: FetchParams<Q>) => Promise<T>;
11
- post: <T, Q>(path: string, params?: FetchParams<Q>) => Promise<T>;
12
- put: <T, Q>(path: string, params?: FetchParams<Q>) => Promise<T>;
13
- patch: <T, Q>(path: string, params?: FetchParams<Q>) => Promise<T>;
14
- delete: <T, Q>(path: string, params?: FetchParams<Q>) => Promise<T>;
19
+ get: <T, Q>(path: string, params?: FetchParams<Q>, method?: HttpMethod, headers?: HeadersInit, transformers?: {
20
+ body?: (body: any) => BodyInit;
21
+ }) => Promise<T>;
22
+ post: <T, Q>(path: string, params?: FetchParams<Q>, method?: HttpMethod, headers?: HeadersInit, transformers?: {
23
+ body?: (body: any) => BodyInit;
24
+ }) => Promise<T>;
25
+ put: <T, Q>(path: string, params?: FetchParams<Q>, method?: HttpMethod, headers?: HeadersInit, transformers?: {
26
+ body?: (body: any) => BodyInit;
27
+ }) => Promise<T>;
28
+ patch: <T, Q>(path: string, params?: FetchParams<Q>, method?: HttpMethod, headers?: HeadersInit, transformers?: {
29
+ body?: (body: any) => BodyInit;
30
+ }) => Promise<T>;
31
+ delete: <T, Q>(path: string, params?: FetchParams<Q>, method?: HttpMethod, headers?: HeadersInit, transformers?: {
32
+ body?: (body: any) => BodyInit;
33
+ }) => Promise<T>;
15
34
  };
16
35
  export {};
@@ -8,8 +8,12 @@ let CONFIG;
8
8
  function configureApiDriver(config) {
9
9
  CONFIG = config;
10
10
  }
11
- async function fetchCall(path, fetchParams, method = 'get') {
12
- const headers = CONFIG.getHeaders?.() || {};
11
+ async function fetchCall(...args) {
12
+ let [path, fetchParams, method, headers, transformers] = args;
13
+ headers = {
14
+ ...CONFIG.getHeaders?.(),
15
+ ...headers,
16
+ };
13
17
  const query = {};
14
18
  Object.entries(fetchParams?.query || {}).forEach(([key, val]) => {
15
19
  query[key] = Array.isArray(val) ? JSON.stringify(val) : val;
@@ -21,7 +25,11 @@ async function fetchCall(path, fetchParams, method = 'get') {
21
25
  headers,
22
26
  };
23
27
  if (fetchParams?.body) {
28
+ // if (transformers?.body) {
29
+ // init.body = transformers.body(fetchParams.body);
30
+ // } else {
24
31
  init.body = JSON.stringify(fetchParams.body);
32
+ // }
25
33
  headers['Content-Type'] = 'application/json';
26
34
  }
27
35
  const res = await fetch(fullPath, init);
@@ -31,10 +39,10 @@ async function fetchCall(path, fetchParams, method = 'get') {
31
39
  }
32
40
  function apiDriver() {
33
41
  return {
34
- get: (path, params) => fetchCall(path, params, 'get'),
35
- post: (path, params) => fetchCall(path, params, 'post'),
36
- put: (path, params) => fetchCall(path, params, 'put'),
37
- patch: (path, params) => fetchCall(path, params, 'patch'),
38
- delete: (path, params) => fetchCall(path, params, 'delete'),
42
+ get: (...args) => fetchCall(args[0], args[1], 'get', args[3], args[4]),
43
+ post: (...args) => fetchCall(args[0], args[1], 'post', args[3], args[4]),
44
+ put: (...args) => fetchCall(args[0], args[1], 'put', args[3], args[4]),
45
+ patch: (...args) => fetchCall(args[0], args[1], 'patch', args[3], args[4]),
46
+ delete: (...args) => fetchCall(args[0], args[1], 'delete', args[3], args[4]),
39
47
  };
40
48
  }
@@ -1,5 +1,5 @@
1
- import { I_Offer } from "./I_Offer";
2
- import { I_User } from "./I_User";
1
+ import { I_Offer } from './I_Offer';
2
+ import { I_User } from './I_User';
3
3
  export declare class I_Agency {
4
4
  id: string;
5
5
  name: string;
@@ -0,0 +1,35 @@
1
+ import { I_Offer } from './I_Offer';
2
+ export declare class I_Collaboration {
3
+ id: string;
4
+ offer: I_Offer;
5
+ media: [];
6
+ }
7
+ export declare class I_GetCampaignCollaborationsDTO {
8
+ campaignId: string;
9
+ constructor(data?: Partial<I_GetCampaignCollaborationsDTO>);
10
+ }
11
+ export declare class I_GetCollaborationDTO {
12
+ collaborationId: string;
13
+ constructor(data?: Partial<I_GetCollaborationDTO>);
14
+ }
15
+ export declare class I_GetCollaborationByOfferDTO {
16
+ offerId: string;
17
+ constructor(data?: Partial<I_GetCollaborationByOfferDTO>);
18
+ }
19
+ export declare class I_GetCollaborationsDTO {
20
+ userId: string;
21
+ constructor(data?: Partial<I_GetCollaborationsDTO>);
22
+ }
23
+ export declare class I_FindUserCollaborationsDTO {
24
+ userId: string;
25
+ constructor(data?: Partial<I_FindUserCollaborationsDTO>);
26
+ }
27
+ export declare class I_CreateCollaborationDTO {
28
+ offerId: string;
29
+ constructor(data?: Partial<I_CreateCollaborationDTO>);
30
+ }
31
+ export declare class I_UploadFirstMediaVersionDTO {
32
+ collaborationId: string;
33
+ file: string;
34
+ fileName: string;
35
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.I_UploadFirstMediaVersionDTO = exports.I_CreateCollaborationDTO = exports.I_Collaboration = void 0;
4
+ class I_Collaboration {
5
+ }
6
+ exports.I_Collaboration = I_Collaboration;
7
+ class I_CreateCollaborationDTO {
8
+ constructor(data) {
9
+ this.offerId = data?.offerId ?? null;
10
+ }
11
+ }
12
+ exports.I_CreateCollaborationDTO = I_CreateCollaborationDTO;
13
+ class I_UploadFirstMediaVersionDTO {
14
+ }
15
+ exports.I_UploadFirstMediaVersionDTO = I_UploadFirstMediaVersionDTO;
@@ -1,6 +1,21 @@
1
- export declare enum I_MediaStatus {
1
+ export declare enum I_MediaStage {
2
2
  UPLOADED = "uploaded",
3
3
  ADJUSTMENT_REQUIRED = "adjustmentRequired",
4
4
  REJECTED = "rejected",
5
5
  ACCEPTED = "accepted"
6
6
  }
7
+ export declare class I_Media {
8
+ id: string;
9
+ url: string;
10
+ fileName: string;
11
+ type: I_MediaStage;
12
+ }
13
+ export declare class I_GetCollaborationMediaDTO {
14
+ collaborationId: string;
15
+ }
16
+ export declare class I_CreateMediaDTO {
17
+ collaborationId: string;
18
+ fileName: string;
19
+ type: I_MediaStage;
20
+ file: string;
21
+ }
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.I_MediaStatus = void 0;
4
- var I_MediaStatus;
5
- (function (I_MediaStatus) {
6
- I_MediaStatus["UPLOADED"] = "uploaded";
7
- I_MediaStatus["ADJUSTMENT_REQUIRED"] = "adjustmentRequired";
8
- I_MediaStatus["REJECTED"] = "rejected";
9
- I_MediaStatus["ACCEPTED"] = "accepted";
10
- })(I_MediaStatus || (exports.I_MediaStatus = I_MediaStatus = {}));
3
+ exports.I_Media = exports.I_MediaStage = void 0;
4
+ var I_MediaStage;
5
+ (function (I_MediaStage) {
6
+ I_MediaStage["UPLOADED"] = "uploaded";
7
+ I_MediaStage["ADJUSTMENT_REQUIRED"] = "adjustmentRequired";
8
+ I_MediaStage["REJECTED"] = "rejected";
9
+ I_MediaStage["ACCEPTED"] = "accepted";
10
+ })(I_MediaStage || (exports.I_MediaStage = I_MediaStage = {}));
11
+ class I_Media {
12
+ }
13
+ exports.I_Media = I_Media;
@@ -8,6 +8,7 @@ export declare class I_Offer {
8
8
  price?: number;
9
9
  status?: I_OfferStatus;
10
10
  action?: OfferActions;
11
+ campaign: I_Campaign;
11
12
  constructor(data?: I_Offer);
12
13
  }
13
14
  export type OfferActions = 'create' | 'delete' | 'confirm' | 'reject' | 'negotiate' | 'accept';
@@ -19,6 +19,7 @@ class I_Offer {
19
19
  this.price = data?.price ?? null;
20
20
  this.status = data?.status ?? null;
21
21
  this.action = data?.action ?? null;
22
+ this.campaign = data?.campaign ?? null;
22
23
  }
23
24
  }
24
25
  exports.I_Offer = I_Offer;
@@ -30,3 +30,4 @@ export * from './I_Offer';
30
30
  export * from './I_CampaignDeadline';
31
31
  export * from './I_Agency';
32
32
  export * from './I_Media';
33
+ export * from './I_Collaboration';
@@ -46,3 +46,4 @@ __exportStar(require("./I_Offer"), exports);
46
46
  __exportStar(require("./I_CampaignDeadline"), exports);
47
47
  __exportStar(require("./I_Agency"), exports);
48
48
  __exportStar(require("./I_Media"), exports);
49
+ __exportStar(require("./I_Collaboration"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ad2app-lib",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "commonjs",
@@ -14,12 +14,23 @@ export function configureApiDriver(config: DriverConfig) {
14
14
  CONFIG = config;
15
15
  }
16
16
 
17
- export async function fetchCall<T, Q>(
17
+ type FetchCallArgs<Q> = [
18
18
  path: string,
19
- fetchParams?: FetchParams<Q>,
20
- method: HttpMethod = 'get'
21
- ): Promise<T> {
22
- const headers: HeadersInit = CONFIG.getHeaders?.() || {};
19
+ params?: FetchParams<Q>,
20
+ method?: HttpMethod,
21
+ headers?: HeadersInit,
22
+ transformers?: {
23
+ body?: (body: any) => BodyInit;
24
+ }
25
+ ];
26
+
27
+ export async function fetchCall<T, Q>(...args: FetchCallArgs<Q>): Promise<T> {
28
+ let [path, fetchParams, method, headers, transformers] = args;
29
+
30
+ headers = {
31
+ ...CONFIG.getHeaders?.(),
32
+ ...headers,
33
+ };
23
34
 
24
35
  const query: Q = {} as Q;
25
36
  Object.entries(fetchParams?.query || {}).forEach(([key, val]) => {
@@ -38,7 +49,12 @@ export async function fetchCall<T, Q>(
38
49
  };
39
50
 
40
51
  if (fetchParams?.body) {
52
+ // if (transformers?.body) {
53
+ // init.body = transformers.body(fetchParams.body);
54
+ // } else {
41
55
  init.body = JSON.stringify(fetchParams.body);
56
+ // }
57
+
42
58
  headers['Content-Type'] = 'application/json';
43
59
  }
44
60
 
@@ -51,15 +67,15 @@ export async function fetchCall<T, Q>(
51
67
 
52
68
  export function apiDriver() {
53
69
  return {
54
- get: <T, Q>(path: string, params?: FetchParams<Q>) =>
55
- fetchCall<T, Q>(path, params, 'get'),
56
- post: <T, Q>(path: string, params?: FetchParams<Q>) =>
57
- fetchCall<T, Q>(path, params, 'post'),
58
- put: <T, Q>(path: string, params?: FetchParams<Q>) =>
59
- fetchCall<T, Q>(path, params, 'put'),
60
- patch: <T, Q>(path: string, params?: FetchParams<Q>) =>
61
- fetchCall<T, Q>(path, params, 'patch'),
62
- delete: <T, Q>(path: string, params?: FetchParams<Q>) =>
63
- fetchCall<T, Q>(path, params, 'delete'),
70
+ get: <T, Q>(...args: FetchCallArgs<Q>) =>
71
+ fetchCall<T, Q>(args[0], args[1], 'get', args[3], args[4]),
72
+ post: <T, Q>(...args: FetchCallArgs<Q>) =>
73
+ fetchCall<T, Q>(args[0], args[1], 'post', args[3], args[4]),
74
+ put: <T, Q>(...args: FetchCallArgs<Q>) =>
75
+ fetchCall<T, Q>(args[0], args[1], 'put', args[3], args[4]),
76
+ patch: <T, Q>(...args: FetchCallArgs<Q>) =>
77
+ fetchCall<T, Q>(args[0], args[1], 'patch', args[3], args[4]),
78
+ delete: <T, Q>(...args: FetchCallArgs<Q>) =>
79
+ fetchCall<T, Q>(args[0], args[1], 'delete', args[3], args[4]),
64
80
  };
65
81
  }
@@ -1,5 +1,5 @@
1
- import { I_Offer } from "./I_Offer";
2
- import { I_User } from "./I_User";
1
+ import { I_Offer } from './I_Offer';
2
+ import { I_User } from './I_User';
3
3
 
4
4
  export class I_Agency {
5
5
  id: string;
@@ -0,0 +1,47 @@
1
+ import { I_Media } from './I_Media';
2
+ import { I_Offer } from './I_Offer';
3
+
4
+ export class I_Collaboration {
5
+ id: string;
6
+ offer: I_Offer;
7
+ media: [];
8
+ }
9
+
10
+ export declare class I_GetCampaignCollaborationsDTO {
11
+ campaignId: string;
12
+ constructor(data?: Partial<I_GetCampaignCollaborationsDTO>);
13
+ }
14
+
15
+ export declare class I_GetCollaborationDTO {
16
+ collaborationId: string;
17
+ constructor(data?: Partial<I_GetCollaborationDTO>);
18
+ }
19
+
20
+ export declare class I_GetCollaborationByOfferDTO {
21
+ offerId: string;
22
+ constructor(data?: Partial<I_GetCollaborationByOfferDTO>);
23
+ }
24
+
25
+ export declare class I_GetCollaborationsDTO {
26
+ userId: string;
27
+ constructor(data?: Partial<I_GetCollaborationsDTO>);
28
+ }
29
+
30
+ export declare class I_FindUserCollaborationsDTO {
31
+ userId: string;
32
+ constructor(data?: Partial<I_FindUserCollaborationsDTO>);
33
+ }
34
+
35
+ export class I_CreateCollaborationDTO {
36
+ offerId: string;
37
+
38
+ constructor(data?: Partial<I_CreateCollaborationDTO>) {
39
+ this.offerId = data?.offerId ?? null;
40
+ }
41
+ }
42
+
43
+ export class I_UploadFirstMediaVersionDTO {
44
+ collaborationId: string;
45
+ file: string;
46
+ fileName: string;
47
+ }
@@ -1,6 +1,24 @@
1
- export enum I_MediaStatus {
1
+ export enum I_MediaStage {
2
2
  UPLOADED = 'uploaded',
3
3
  ADJUSTMENT_REQUIRED = 'adjustmentRequired',
4
4
  REJECTED = 'rejected',
5
5
  ACCEPTED = 'accepted',
6
6
  }
7
+
8
+ export class I_Media {
9
+ id: string;
10
+ url: string;
11
+ fileName: string;
12
+ type: I_MediaStage;
13
+ }
14
+
15
+ export declare class I_GetCollaborationMediaDTO {
16
+ collaborationId: string;
17
+ }
18
+
19
+ export declare class I_CreateMediaDTO {
20
+ collaborationId: string;
21
+ fileName: string;
22
+ type: I_MediaStage;
23
+ file: string;
24
+ }
@@ -10,6 +10,7 @@ export class I_Offer {
10
10
  price?: number;
11
11
  status?: I_OfferStatus;
12
12
  action?: OfferActions;
13
+ campaign: I_Campaign;
13
14
 
14
15
  constructor(data?: I_Offer) {
15
16
  this.agency = data?.agency ?? null;
@@ -18,6 +19,7 @@ export class I_Offer {
18
19
  this.price = data?.price ?? null;
19
20
  this.status = data?.status ?? null;
20
21
  this.action = data?.action ?? null;
22
+ this.campaign = data?.campaign ?? null;
21
23
  }
22
24
  }
23
25
 
@@ -30,3 +30,4 @@ export * from './I_Offer';
30
30
  export * from './I_CampaignDeadline';
31
31
  export * from './I_Agency';
32
32
  export * from './I_Media';
33
+ export * from './I_Collaboration';