ad2app-lib 1.0.4 → 1.0.5

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.
@@ -0,0 +1,10 @@
1
+ {
2
+ "folders": [
3
+ {
4
+ "path": "."
5
+ }
6
+ ],
7
+ "settings": {
8
+ "workbench.colorTheme": "Kimbie Dark"
9
+ }
10
+ }
@@ -0,0 +1,11 @@
1
+ export declare enum SocialProvider {
2
+ TIKTOK = 'tiktok',
3
+ }
4
+ export declare class I_SocialSignInDTO {
5
+ userId: string;
6
+ provider: SocialProvider;
7
+ provider_user_id: string;
8
+ access_token: string;
9
+ refresh_token?: string;
10
+ expires_at?: string;
11
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.I_SocialSignInDTO = exports.SocialProvider = void 0;
13
+ const class_validator_1 = require("class-validator");
14
+ var SocialProvider;
15
+ (function (SocialProvider) {
16
+ SocialProvider["TIKTOK"] = "tiktok";
17
+ })(SocialProvider || (exports.SocialProvider = SocialProvider = {}));
18
+ class I_SocialSignInDTO {
19
+ }
20
+ exports.I_SocialSignInDTO = I_SocialSignInDTO;
21
+ __decorate([
22
+ (0, class_validator_1.IsNotEmpty)(),
23
+ __metadata("design:type", String)
24
+ ], I_SocialSignInDTO.prototype, "userId", void 0);
25
+ __decorate([
26
+ (0, class_validator_1.IsEnum)(SocialProvider),
27
+ __metadata("design:type", String)
28
+ ], I_SocialSignInDTO.prototype, "provider", void 0);
29
+ __decorate([
30
+ (0, class_validator_1.IsNotEmpty)(),
31
+ (0, class_validator_1.IsString)(),
32
+ __metadata("design:type", String)
33
+ ], I_SocialSignInDTO.prototype, "provider_user_id", void 0);
34
+ __decorate([
35
+ (0, class_validator_1.IsNotEmpty)(),
36
+ (0, class_validator_1.IsString)(),
37
+ __metadata("design:type", String)
38
+ ], I_SocialSignInDTO.prototype, "access_token", void 0);
39
+ __decorate([
40
+ (0, class_validator_1.IsOptional)(),
41
+ (0, class_validator_1.IsString)(),
42
+ __metadata("design:type", String)
43
+ ], I_SocialSignInDTO.prototype, "refresh_token", void 0);
44
+ __decorate([
45
+ (0, class_validator_1.IsOptional)(),
46
+ (0, class_validator_1.IsISO8601)(),
47
+ __metadata("design:type", String)
48
+ ], I_SocialSignInDTO.prototype, "expires_at", void 0);
@@ -1,8 +1,8 @@
1
- import { I_Influencer } from "./I_Influencer";
1
+ import { I_Influencer } from './I_Influencer';
2
2
  export declare class I_User {
3
3
  id: string;
4
- email: string;
5
- password: string;
4
+ email?: string;
5
+ password?: string;
6
6
  role: UserRoles;
7
7
  influencer?: I_Influencer;
8
8
  }
@@ -30,4 +30,5 @@ 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_SocialAccount';
33
34
  export * from './I_Collaboration';
@@ -46,4 +46,5 @@ __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_SocialAccount"), exports);
49
50
  __exportStar(require("./I_Collaboration"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ad2app-lib",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "commonjs",
@@ -1,7 +1,7 @@
1
- import { FetchParams } from '../types';
2
- import { concatApiPaths, createQueryString, insertParams } from './utils';
1
+ import { FetchParams } from "../types";
2
+ import { concatApiPaths, createQueryString, insertParams } from "./utils";
3
3
 
4
- type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
4
+ type HttpMethod = "get" | "post" | "put" | "patch" | "delete";
5
5
 
6
6
  interface DriverConfig {
7
7
  apiUrl: string;
@@ -14,33 +14,36 @@ export function configureApiDriver(config: DriverConfig) {
14
14
  CONFIG = config;
15
15
  }
16
16
 
17
- type FetchCallArgs<Q> = [
18
- path: string,
19
- params?: FetchParams<Q>,
20
- method?: HttpMethod,
21
- headers?: HeadersInit,
17
+ type FetchCallArgs<Q> = {
18
+ path?: string;
19
+ params?: FetchParams<Q>;
20
+ method?: HttpMethod;
21
+ headers?: HeadersInit;
22
22
  transformers?: {
23
23
  body?: (body: any) => BodyInit;
24
- }
25
- ];
24
+ };
25
+ baseUrl?: string;
26
+ };
26
27
 
27
- export async function fetchCall<T, Q>(...args: FetchCallArgs<Q>): Promise<T> {
28
- let [path, fetchParams, method, headers, transformers] = args;
28
+ export async function fetchCall<T, Q>(args: FetchCallArgs<Q>): Promise<T> {
29
+ let { path, params, method, headers, baseUrl, transformers } = args;
29
30
 
30
31
  headers = {
31
- ...CONFIG.getHeaders?.(),
32
+ ...CONFIG?.getHeaders?.(),
32
33
  ...headers,
33
34
  };
34
35
 
35
36
  const query: Q = {} as Q;
36
- Object.entries(fetchParams?.query || {}).forEach(([key, val]) => {
37
+ Object.entries(params?.query || {}).forEach(([key, val]) => {
37
38
  query[key] = Array.isArray(val) ? JSON.stringify(val) : val;
38
39
  });
39
40
 
40
- const queryString = createQueryString({ ...fetchParams, query });
41
+ const apiUrl = baseUrl ?? CONFIG.apiUrl;
42
+
43
+ const queryString = createQueryString({ ...params, query });
41
44
  const fullPath = insertParams(
42
- concatApiPaths(CONFIG.apiUrl, path) + queryString,
43
- fetchParams?.params
45
+ concatApiPaths(apiUrl, path) + queryString,
46
+ params?.params
44
47
  );
45
48
 
46
49
  const init: RequestInit = {
@@ -48,34 +51,69 @@ export async function fetchCall<T, Q>(...args: FetchCallArgs<Q>): Promise<T> {
48
51
  headers,
49
52
  };
50
53
 
51
- if (fetchParams?.body) {
52
- // if (transformers?.body) {
53
- // init.body = transformers.body(fetchParams.body);
54
- // } else {
55
- init.body = JSON.stringify(fetchParams.body);
56
- // }
54
+ if (params?.body) {
55
+ if (transformers?.body) {
56
+ init.body = transformers.body(params.body);
57
+ } else {
58
+ init.body = JSON.stringify(params.body);
59
+ }
57
60
 
58
- headers['Content-Type'] = 'application/json';
61
+ if (!headers["Content-Type"]) {
62
+ headers["Content-Type"] = "application/json";
63
+ }
59
64
  }
60
65
 
61
66
  const res = await fetch(fullPath, init);
62
67
 
63
68
  if (!res.ok) throw new Error(JSON.stringify(await res.json()));
64
69
 
65
- return res.json() as Promise<T>;
70
+ try {
71
+ return res.json() as Promise<T>;
72
+ } catch {
73
+ return res.text() as Promise<T>;
74
+ }
66
75
  }
67
76
 
68
- export function apiDriver() {
77
+ type MethodCallArgs<Q> = [
78
+ path: string,
79
+ options: Omit<FetchCallArgs<Q>, "path" | "method">
80
+ ];
81
+
82
+ export function apiDriver(baseUrl?: string) {
69
83
  return {
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]),
84
+ get: <T, Q>(...args: MethodCallArgs<Q>) =>
85
+ fetchCall<T, Q>({
86
+ ...args[1],
87
+ path: args[0],
88
+ method: "get",
89
+ baseUrl,
90
+ }),
91
+ post: <T, Q>(...args: MethodCallArgs<Q>) =>
92
+ fetchCall<T, Q>({
93
+ ...args[1],
94
+ path: args[0],
95
+ method: "post",
96
+ baseUrl,
97
+ }),
98
+ put: <T, Q>(...args: MethodCallArgs<Q>) =>
99
+ fetchCall<T, Q>({
100
+ ...args[1],
101
+ path: args[0],
102
+ method: "put",
103
+ }),
104
+ patch: <T, Q>(...args: MethodCallArgs<Q>) =>
105
+ fetchCall<T, Q>({
106
+ ...args[1],
107
+ path: args[0],
108
+ method: "patch",
109
+ baseUrl,
110
+ }),
111
+ delete: <T, Q>(...args: MethodCallArgs<Q>) =>
112
+ fetchCall<T, Q>({
113
+ ...args[1],
114
+ path: args[0],
115
+ method: "delete",
116
+ baseUrl,
117
+ }),
80
118
  };
81
119
  }
@@ -1,5 +1,5 @@
1
- import { I_ResponseMessage } from './I_ResponseMessage';
2
- import { T_FetchStatus } from './T_FetchStatus';
1
+ import { I_ResponseMessage } from "./I_ResponseMessage";
2
+ import { T_FetchStatus } from "./T_FetchStatus";
3
3
 
4
4
  export class I_Item<T> implements I_ResponseMessage {
5
5
  data: T;
@@ -8,12 +8,12 @@ export class I_Item<T> implements I_ResponseMessage {
8
8
 
9
9
  constructor(data?: Partial<I_Item<T>>) {
10
10
  this.data = data?.data || null;
11
- this.status = data?.status || 'succeeded';
12
- this.message = data?.message || '';
11
+ this.status = data?.status || "succeeded";
12
+ this.message = data?.message || "";
13
13
  }
14
14
 
15
15
  succeed?(data: T, message?: string): this {
16
- this.status = 'succeeded';
16
+ this.status = "succeeded";
17
17
  this.data = data;
18
18
  this.message = message;
19
19
 
@@ -21,14 +21,14 @@ export class I_Item<T> implements I_ResponseMessage {
21
21
  }
22
22
 
23
23
  fail?(message: string): this {
24
- this.status = 'failed';
24
+ this.status = "failed";
25
25
  this.message = message;
26
26
 
27
27
  return this;
28
28
  }
29
29
  }
30
30
 
31
- export const itemIsLoading = (item: I_Item<any>) => item.status === 'loading';
31
+ export const itemIsLoading = (item: I_Item<any>) => item.status === "loading";
32
32
  export const itemIsResolving = (item: I_Item<any>) =>
33
- item.status === 'initial' || item.status === 'loading';
34
- export const itemFailed = (item: I_Item<any>) => item.status === 'failed';
33
+ item.status === "initial" || item.status === "loading";
34
+ export const itemFailed = (item: I_Item<any>) => item.status === "failed";
@@ -0,0 +1,14 @@
1
+ export type I_CrossPostContentDTO = {
2
+ file: File;
3
+ description: string;
4
+ refreshToken: string;
5
+ };
6
+
7
+ export type I_GetPublishStatusDTO = {
8
+ publishId: string;
9
+ refreshToken: string;
10
+ };
11
+
12
+ export type I_PublishStatus = {
13
+ status: string;
14
+ };
@@ -1,11 +1,11 @@
1
- import { T_FetchStatus } from './T_FetchStatus';
1
+ import { T_FetchStatus } from "./T_FetchStatus";
2
2
 
3
3
  export class I_ResponseMessage {
4
4
  status: T_FetchStatus;
5
5
  message?: string;
6
6
 
7
7
  constructor(data?: Partial<I_ResponseMessage>) {
8
- this.status = data?.status || 'initial';
9
- this.message = data?.message || '';
8
+ this.status = data?.status || "initial";
9
+ this.message = data?.message || "";
10
10
  }
11
11
  }
@@ -0,0 +1,52 @@
1
+ import {
2
+ IsNotEmpty,
3
+ IsOptional,
4
+ IsEnum,
5
+ IsISO8601,
6
+ IsString,
7
+ } from 'class-validator';
8
+
9
+ export enum SocialProvider {
10
+ TIKTOK = 'tiktok',
11
+ }
12
+
13
+ export class I_SocialSignInDTO {
14
+ // @IsNotEmpty()
15
+ // userId: string;
16
+
17
+ @IsEnum(SocialProvider)
18
+ provider: SocialProvider;
19
+
20
+ @IsNotEmpty()
21
+ @IsString()
22
+ provider_user_id: string;
23
+
24
+ @IsNotEmpty()
25
+ @IsString()
26
+ access_token: string;
27
+
28
+ @IsOptional()
29
+ @IsString()
30
+ refresh_token?: string;
31
+
32
+ @IsOptional()
33
+ @IsISO8601()
34
+ expires_at?: string;
35
+ }
36
+
37
+ export class I_TikTokUserPayload {
38
+ id: string;
39
+ role: string;
40
+ email?: string | null;
41
+ accessToken: string;
42
+ refreshToken: string;
43
+ influencer?: { handle_tt: string };
44
+
45
+ constructor(data: I_TikTokUserPayload) {
46
+ this.id = data.id;
47
+ this.role = data.role;
48
+ this.email = data.email; this.accessToken = data.accessToken;
49
+ this.refreshToken = data.refreshToken;
50
+ this.influencer = data.influencer;
51
+ }
52
+ };
@@ -1,10 +1,10 @@
1
- import { IsNotEmpty } from "class-validator";
2
- import { I_Influencer } from "./I_Influencer";
1
+ import { IsNotEmpty } from 'class-validator';
2
+ import { I_Influencer } from './I_Influencer';
3
3
 
4
4
  export class I_User {
5
5
  id: string;
6
- email: string;
7
- password: string;
6
+ email?: string;
7
+ password?: string;
8
8
  role: UserRoles;
9
9
  influencer?: I_Influencer;
10
10
  }
@@ -14,9 +14,9 @@ export class I_SignedUser extends I_User {
14
14
  }
15
15
 
16
16
  export enum UserRoles {
17
- ADMIN = "ADMIN",
18
- INFLUENCER = "INFLUENCER",
19
- AGENT = "AGENT",
17
+ ADMIN = 'ADMIN',
18
+ INFLUENCER = 'INFLUENCER',
19
+ AGENT = 'AGENT',
20
20
  }
21
21
 
22
22
  export class I_UserCreateDTO {
@@ -1,33 +1,35 @@
1
- export * from './I_TikTokUser';
2
- export * from './I_Queue';
3
- export * from './I_Campaign';
4
- export * from './I_Influencer';
5
- export * from './I_InfluencersLists';
6
- export * from './I_InfluencersCategories';
7
- export * from './I_InfluencersProperties';
8
- export * from './I_Item';
9
- export * from './I_List';
10
- export * from './I_PaginatedList';
11
- export * from './I_Pagination';
12
- export * from './I_TIkTokRaports';
13
- export * from './I_Tag';
14
- export * from './I_TikTokPost';
15
- export * from './I_User';
16
- export * from './I_UserTikTokStatistic';
17
- export * from './I_ScrappingAccount';
18
- export * from './global';
19
- export * from './I_Scrappers';
20
- export * from './I_ScrappingServiceMessages';
21
- export * from './I_ScrappingMachine';
22
- export * from './I_ScrappingMachineProcess';
23
- export * from './T_FetchStatus';
24
- export * from './I_ResponseMessage';
25
- export * from './I_ScrapperLog';
26
- export * from './I_CampaignGoal';
27
- export * from './I_CampaignCollaborationMethod';
28
- export * from './I_TikTokReport';
29
- export * from './I_Offer';
30
- export * from './I_CampaignDeadline';
31
- export * from './I_Agency';
32
- export * from './I_Media';
33
- export * from './I_Collaboration';
1
+ export * from "./I_TikTokUser";
2
+ export * from "./I_Queue";
3
+ export * from "./I_Campaign";
4
+ export * from "./I_Influencer";
5
+ export * from "./I_InfluencersLists";
6
+ export * from "./I_InfluencersCategories";
7
+ export * from "./I_InfluencersProperties";
8
+ export * from "./I_Item";
9
+ export * from "./I_List";
10
+ export * from "./I_PaginatedList";
11
+ export * from "./I_Pagination";
12
+ export * from "./I_TIkTokRaports";
13
+ export * from "./I_Tag";
14
+ export * from "./I_TikTokPost";
15
+ export * from "./I_User";
16
+ export * from "./I_UserTikTokStatistic";
17
+ export * from "./I_ScrappingAccount";
18
+ export * from "./global";
19
+ export * from "./I_Scrappers";
20
+ export * from "./I_ScrappingServiceMessages";
21
+ export * from "./I_ScrappingMachine";
22
+ export * from "./I_ScrappingMachineProcess";
23
+ export * from "./T_FetchStatus";
24
+ export * from "./I_ResponseMessage";
25
+ export * from "./I_ScrapperLog";
26
+ export * from "./I_CampaignGoal";
27
+ export * from "./I_CampaignCollaborationMethod";
28
+ export * from "./I_TikTokReport";
29
+ export * from "./I_Offer";
30
+ export * from "./I_CampaignDeadline";
31
+ export * from "./I_Agency";
32
+ export * from "./I_Media";
33
+ export * from "./I_SocialAccount";
34
+ export * from "./I_Collaboration";
35
+ export * from "./I_Publish";