operand-meta-sdk 1.2.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/.eslintrc.js +25 -0
- package/.prettierrc +4 -0
- package/README.md +435 -0
- package/dist/jest.config.d.ts +3 -0
- package/dist/jest.config.js +14 -0
- package/dist/jest.config.js.map +1 -0
- package/dist/src/__test__/mocks/index.d.ts +2 -0
- package/dist/src/__test__/mocks/index.js +6 -0
- package/dist/src/__test__/mocks/index.js.map +1 -0
- package/dist/src/error/operand-error.d.ts +8 -0
- package/dist/src/error/operand-error.js +196 -0
- package/dist/src/error/operand-error.js.map +1 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.js +22 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/interfaces/ing-publish.d.ts +53 -0
- package/dist/src/interfaces/ing-publish.js +3 -0
- package/dist/src/interfaces/ing-publish.js.map +1 -0
- package/dist/src/interfaces/meta-auth.d.ts +14 -0
- package/dist/src/interfaces/meta-auth.js +3 -0
- package/dist/src/interfaces/meta-auth.js.map +1 -0
- package/dist/src/interfaces/meta-mkt.d.ts +4 -0
- package/dist/src/interfaces/meta-mkt.js +3 -0
- package/dist/src/interfaces/meta-mkt.js.map +1 -0
- package/dist/src/interfaces/meta-response.d.ts +285 -0
- package/dist/src/interfaces/meta-response.js +3 -0
- package/dist/src/interfaces/meta-response.js.map +1 -0
- package/dist/src/interfaces/meta.d.ts +6 -0
- package/dist/src/interfaces/meta.js +3 -0
- package/dist/src/interfaces/meta.js.map +1 -0
- package/dist/src/interfaces/page-publish.d.ts +66 -0
- package/dist/src/interfaces/page-publish.js +3 -0
- package/dist/src/interfaces/page-publish.js.map +1 -0
- package/dist/src/modules/auth/meta-auth.d.ts +35 -0
- package/dist/src/modules/auth/meta-auth.js +131 -0
- package/dist/src/modules/auth/meta-auth.js.map +1 -0
- package/dist/src/modules/auth/meta-auth.spec.d.ts +1 -0
- package/dist/src/modules/auth/meta-auth.spec.js +76 -0
- package/dist/src/modules/auth/meta-auth.spec.js.map +1 -0
- package/dist/src/modules/comments/ing-comments.d.ts +7 -0
- package/dist/src/modules/comments/ing-comments.js +27 -0
- package/dist/src/modules/comments/ing-comments.js.map +1 -0
- package/dist/src/modules/comments/page-comments.d.ts +6 -0
- package/dist/src/modules/comments/page-comments.js +18 -0
- package/dist/src/modules/comments/page-comments.js.map +1 -0
- package/dist/src/modules/insights/ing-insights.d.ts +42 -0
- package/dist/src/modules/insights/ing-insights.js +150 -0
- package/dist/src/modules/insights/ing-insights.js.map +1 -0
- package/dist/src/modules/insights/mkt-insights.d.ts +10 -0
- package/dist/src/modules/insights/mkt-insights.js +46 -0
- package/dist/src/modules/insights/mkt-insights.js.map +1 -0
- package/dist/src/modules/insights/page-insights.d.ts +34 -0
- package/dist/src/modules/insights/page-insights.js +146 -0
- package/dist/src/modules/insights/page-insights.js.map +1 -0
- package/dist/src/modules/meta-ing.d.ts +5 -0
- package/dist/src/modules/meta-ing.js +11 -0
- package/dist/src/modules/meta-ing.js.map +1 -0
- package/dist/src/modules/meta-mkt.d.ts +5 -0
- package/dist/src/modules/meta-mkt.js +11 -0
- package/dist/src/modules/meta-mkt.js.map +1 -0
- package/dist/src/modules/meta-page.d.ts +5 -0
- package/dist/src/modules/meta-page.js +11 -0
- package/dist/src/modules/meta-page.js.map +1 -0
- package/dist/src/modules/meta.d.ts +10 -0
- package/dist/src/modules/meta.js +23 -0
- package/dist/src/modules/meta.js.map +1 -0
- package/dist/src/modules/publish/ing-publish.d.ts +39 -0
- package/dist/src/modules/publish/ing-publish.js +464 -0
- package/dist/src/modules/publish/ing-publish.js.map +1 -0
- package/dist/src/modules/publish/page-publish.d.ts +51 -0
- package/dist/src/modules/publish/page-publish.js +560 -0
- package/dist/src/modules/publish/page-publish.js.map +1 -0
- package/dist/src/modules/publish/page-publish.spec.d.ts +1 -0
- package/dist/src/modules/publish/page-publish.spec.js +280 -0
- package/dist/src/modules/publish/page-publish.spec.js.map +1 -0
- package/dist/src/modules/utils/meta-utils.d.ts +8 -0
- package/dist/src/modules/utils/meta-utils.js +28 -0
- package/dist/src/modules/utils/meta-utils.js.map +1 -0
- package/dist/src/utils/api.d.ts +8 -0
- package/dist/src/utils/api.js +36 -0
- package/dist/src/utils/api.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/jest.config.ts +198 -0
- package/package.json +39 -0
- package/src/__test__/mocks/image.jpeg +0 -0
- package/src/__test__/mocks/index.ts +5 -0
- package/src/__test__/mocks/video-to-post.mp4 +0 -0
- package/src/__test__/mocks/video-to-stories.mp4 +0 -0
- package/src/error/operand-error.ts +217 -0
- package/src/index.ts +21 -0
- package/src/interfaces/ing-publish.ts +58 -0
- package/src/interfaces/meta-auth.ts +52 -0
- package/src/interfaces/meta-mkt.ts +5 -0
- package/src/interfaces/meta-response.ts +319 -0
- package/src/interfaces/meta.ts +7 -0
- package/src/interfaces/page-publish.ts +72 -0
- package/src/modules/auth/meta-auth.spec.ts +93 -0
- package/src/modules/auth/meta-auth.ts +227 -0
- package/src/modules/comments/ing-comments.ts +38 -0
- package/src/modules/comments/page-comments.ts +20 -0
- package/src/modules/insights/ing-insights.ts +275 -0
- package/src/modules/insights/mkt-insights.ts +68 -0
- package/src/modules/insights/page-insights.ts +267 -0
- package/src/modules/meta-ing.ts +8 -0
- package/src/modules/meta-mkt.ts +8 -0
- package/src/modules/meta-page.ts +8 -0
- package/src/modules/meta.ts +31 -0
- package/src/modules/publish/ing-publish.ts +754 -0
- package/src/modules/publish/page-publish.spec.ts +386 -0
- package/src/modules/publish/page-publish.ts +881 -0
- package/src/modules/utils/meta-utils.ts +37 -0
- package/src/utils/api.ts +45 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ConstructorMain } from "./meta";
|
|
2
|
+
import { PagePost } from "./meta-response";
|
|
3
|
+
|
|
4
|
+
export type PhotoMediaItem = {
|
|
5
|
+
source: "url" | "path";
|
|
6
|
+
value: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type VideoMediaItem = {
|
|
10
|
+
source: "url" | "path";
|
|
11
|
+
value: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type CreatePost = {
|
|
15
|
+
mediaType?: "photo" | "video";
|
|
16
|
+
message?: string;
|
|
17
|
+
publishNow: boolean;
|
|
18
|
+
datePublish?: Date;
|
|
19
|
+
photos?: PhotoMediaItem[];
|
|
20
|
+
video?: VideoMediaItem;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type CreateStoriesPath = {
|
|
24
|
+
source: "path";
|
|
25
|
+
mediaType: "photo" | "video";
|
|
26
|
+
path: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type CreateStoriesUrl = {
|
|
30
|
+
source: "url";
|
|
31
|
+
mediaType: "photo" | "video";
|
|
32
|
+
url: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type CreateStories = CreateStoriesPath | CreateStoriesUrl;
|
|
36
|
+
|
|
37
|
+
type CreateReelsPath = {
|
|
38
|
+
source: "path";
|
|
39
|
+
path: string;
|
|
40
|
+
title?: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
type CreateReelsUrl = {
|
|
45
|
+
source: "url";
|
|
46
|
+
url: string;
|
|
47
|
+
title?: string;
|
|
48
|
+
description?: string;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type CreateReels = CreateReelsPath | CreateReelsUrl;
|
|
52
|
+
|
|
53
|
+
export type SetThumbnailToReels = {
|
|
54
|
+
source: "url" | "path";
|
|
55
|
+
value: string;
|
|
56
|
+
videoId: string;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export interface ConstructorPage extends ConstructorMain {
|
|
60
|
+
pageId: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface IPagePublish {
|
|
64
|
+
getAllPosts(): Promise<PagePost[]>;
|
|
65
|
+
getPostUrlById(postId: string): string;
|
|
66
|
+
createPost(data: CreatePost): Promise<string>;
|
|
67
|
+
updatePost(postId: string, message: string): Promise<boolean>;
|
|
68
|
+
deletePost(postId: string): Promise<boolean>;
|
|
69
|
+
createStories(data: CreateStories): Promise<string>;
|
|
70
|
+
createReels(data: CreateReels): Promise<{ postId: string; videoId: string }>;
|
|
71
|
+
setThumbnailToReels(data: SetThumbnailToReels): Promise<{ success: boolean }>;
|
|
72
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { MetaAuth } from "./meta-auth";
|
|
3
|
+
import { ApiVersion, CreateMetaAuth } from "@/interfaces/meta-auth";
|
|
4
|
+
|
|
5
|
+
jest.mock("axios");
|
|
6
|
+
const mockedAxios = axios as jest.Mocked<typeof axios>;
|
|
7
|
+
|
|
8
|
+
describe("Module MetaAuth", () => {
|
|
9
|
+
describe("createAccessToken", () => {
|
|
10
|
+
it("should make a request to /oauth/access_token and return the access token", async () => {
|
|
11
|
+
const requestData: CreateMetaAuth = {
|
|
12
|
+
client_id: "test-client-id",
|
|
13
|
+
client_secret: "test-client-secret",
|
|
14
|
+
redirect_uri: "https://example.com/callback",
|
|
15
|
+
apiVersion: "v21.0",
|
|
16
|
+
code: "test-code",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const mockAccessTokenResponse = {
|
|
20
|
+
data: {
|
|
21
|
+
access_token: "mocked-access-token",
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
mockedAxios.create.mockReturnValue(mockedAxios);
|
|
26
|
+
const mockPost = mockedAxios.post.mockResolvedValue(
|
|
27
|
+
mockAccessTokenResponse,
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const accessToken = await MetaAuth.createAccessTokenFb(requestData);
|
|
31
|
+
|
|
32
|
+
expect(accessToken).toEqual({
|
|
33
|
+
accessToken: "mocked-access-token",
|
|
34
|
+
getAccounts: expect.any(Function),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
expect(mockedAxios.post).toHaveBeenCalledWith("/oauth/access_token", {
|
|
38
|
+
client_id: requestData.client_id,
|
|
39
|
+
client_secret: requestData.client_secret,
|
|
40
|
+
code: requestData.code,
|
|
41
|
+
redirect_uri: requestData.redirect_uri,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
expect(mockPost).toHaveBeenCalled();
|
|
45
|
+
expect(mockPost).toHaveBeenCalledTimes(1);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("getAccounts", () => {
|
|
50
|
+
it("should make a request to /me/accounts and return the accounts", async () => {
|
|
51
|
+
const requestData = {
|
|
52
|
+
fields: ["id", "name"],
|
|
53
|
+
accessToken: "test-access-token",
|
|
54
|
+
apiVersion: "v21.0" as ApiVersion,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const mockGetPageAccountsResponse = {
|
|
58
|
+
data: {
|
|
59
|
+
data: [
|
|
60
|
+
{
|
|
61
|
+
id: "test-page-id",
|
|
62
|
+
name: "Test Page",
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
mockedAxios.create.mockReturnValue(mockedAxios);
|
|
69
|
+
const mockGet = mockedAxios.get.mockResolvedValue(
|
|
70
|
+
mockGetPageAccountsResponse,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const accounts = await MetaAuth.getAccountsWithFbToken(requestData);
|
|
74
|
+
|
|
75
|
+
expect(accounts).toEqual([
|
|
76
|
+
{
|
|
77
|
+
id: "test-page-id",
|
|
78
|
+
name: "Test Page",
|
|
79
|
+
},
|
|
80
|
+
]);
|
|
81
|
+
|
|
82
|
+
expect(mockedAxios.get).toHaveBeenCalledWith("/me/accounts", {
|
|
83
|
+
params: {
|
|
84
|
+
access_token: requestData.accessToken,
|
|
85
|
+
fields: requestData.fields.join(","),
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
expect(mockGet).toHaveBeenCalled();
|
|
90
|
+
expect(mockGet).toHaveBeenCalledTimes(1);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApiVersion,
|
|
3
|
+
CreateMetaAuth,
|
|
4
|
+
FieldsPage,
|
|
5
|
+
GetAccounts,
|
|
6
|
+
} from "../../interfaces/meta-auth";
|
|
7
|
+
import {
|
|
8
|
+
CreateAccessTokenResponse,
|
|
9
|
+
FacebookAdAccount,
|
|
10
|
+
FacebookPage,
|
|
11
|
+
GetAlongTokenMetaResponse,
|
|
12
|
+
GetPageAccountsResponse,
|
|
13
|
+
InstagramAccount,
|
|
14
|
+
} from "../../interfaces/meta-response";
|
|
15
|
+
import { generateAxiosInstance } from "../../utils/api";
|
|
16
|
+
|
|
17
|
+
export class MetaAuth {
|
|
18
|
+
public static async createAccessTokenIg({
|
|
19
|
+
client_id,
|
|
20
|
+
client_secret,
|
|
21
|
+
redirect_uri,
|
|
22
|
+
apiVersion,
|
|
23
|
+
code,
|
|
24
|
+
}: CreateMetaAuth) {
|
|
25
|
+
const api = generateAxiosInstance({
|
|
26
|
+
apiVersion: "v21.0",
|
|
27
|
+
isInstagramAccessToken: true,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const data = new URLSearchParams();
|
|
31
|
+
|
|
32
|
+
data.append("client_id", client_id);
|
|
33
|
+
data.append("client_secret", client_secret);
|
|
34
|
+
data.append("grant_type", "authorization_code");
|
|
35
|
+
data.append("redirect_uri", redirect_uri);
|
|
36
|
+
data.append("code", code);
|
|
37
|
+
|
|
38
|
+
const accessToken = (
|
|
39
|
+
await api.post<CreateAccessTokenResponse>(`/oauth/access_token`, data)
|
|
40
|
+
).data;
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
accessToken: accessToken.access_token,
|
|
44
|
+
getAccounts: ({ fields }: { fields: FieldsPage }) => {
|
|
45
|
+
return MetaAuth.getAccountsWithIgToken({
|
|
46
|
+
fields,
|
|
47
|
+
accessToken: accessToken.access_token,
|
|
48
|
+
apiVersion,
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public static async createAccessTokenFb({
|
|
55
|
+
client_id,
|
|
56
|
+
client_secret,
|
|
57
|
+
redirect_uri,
|
|
58
|
+
apiVersion,
|
|
59
|
+
code,
|
|
60
|
+
}: CreateMetaAuth) {
|
|
61
|
+
const api = generateAxiosInstance({ apiVersion });
|
|
62
|
+
|
|
63
|
+
const shortAccessToken = (
|
|
64
|
+
await api.post<CreateAccessTokenResponse>(`/oauth/access_token`, {
|
|
65
|
+
client_id,
|
|
66
|
+
client_secret,
|
|
67
|
+
code,
|
|
68
|
+
redirect_uri,
|
|
69
|
+
})
|
|
70
|
+
).data.access_token;
|
|
71
|
+
|
|
72
|
+
const longAccessToken = await this.extendUserAccessToken({
|
|
73
|
+
client_id,
|
|
74
|
+
client_secret,
|
|
75
|
+
accessToken: shortAccessToken,
|
|
76
|
+
apiVersion,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
accessToken: longAccessToken,
|
|
81
|
+
getAccounts: ({ fields }: { fields: FieldsPage }) => {
|
|
82
|
+
return MetaAuth.getAccountsWithFbToken({
|
|
83
|
+
fields,
|
|
84
|
+
accessToken: longAccessToken,
|
|
85
|
+
apiVersion,
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
getAdAccounts: () => {
|
|
89
|
+
return MetaAuth.getAdAccounts({
|
|
90
|
+
accessToken: longAccessToken,
|
|
91
|
+
apiVersion,
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public static async extendUserAccessToken({
|
|
98
|
+
client_id,
|
|
99
|
+
client_secret,
|
|
100
|
+
accessToken,
|
|
101
|
+
apiVersion,
|
|
102
|
+
}: {
|
|
103
|
+
client_id: string;
|
|
104
|
+
client_secret: string;
|
|
105
|
+
accessToken: string;
|
|
106
|
+
apiVersion: ApiVersion;
|
|
107
|
+
}) {
|
|
108
|
+
const api = generateAxiosInstance({ apiVersion });
|
|
109
|
+
|
|
110
|
+
const response = await api.get<GetAlongTokenMetaResponse>(
|
|
111
|
+
"/oauth/access_token",
|
|
112
|
+
{
|
|
113
|
+
params: {
|
|
114
|
+
grant_type: "fb_exchange_token",
|
|
115
|
+
client_id,
|
|
116
|
+
client_secret,
|
|
117
|
+
fb_exchange_token: accessToken,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
return response.data.access_token;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public static async getAccountsWithFbToken({
|
|
126
|
+
fields,
|
|
127
|
+
accessToken,
|
|
128
|
+
apiVersion,
|
|
129
|
+
}: GetAccounts): Promise<FacebookPage[]> {
|
|
130
|
+
const api = generateAxiosInstance({ apiVersion });
|
|
131
|
+
|
|
132
|
+
const allAccounts: FacebookPage[] = [];
|
|
133
|
+
let afterCursor: string | undefined = undefined;
|
|
134
|
+
let hasNextPage = true;
|
|
135
|
+
|
|
136
|
+
while (hasNextPage) {
|
|
137
|
+
const response = await api.get<GetPageAccountsResponse>(`/me/accounts`, {
|
|
138
|
+
params: {
|
|
139
|
+
access_token: accessToken,
|
|
140
|
+
fields: fields.join(","),
|
|
141
|
+
after: afterCursor,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const { data, paging } = response.data;
|
|
146
|
+
allAccounts.push(...data);
|
|
147
|
+
|
|
148
|
+
afterCursor = paging?.cursors?.after;
|
|
149
|
+
hasNextPage = Boolean(afterCursor);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return allAccounts;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
public static async getAccountsWithIgToken({
|
|
156
|
+
fields,
|
|
157
|
+
accessToken,
|
|
158
|
+
apiVersion,
|
|
159
|
+
}: GetAccounts): Promise<InstagramAccount> {
|
|
160
|
+
const api = generateAxiosInstance({ apiVersion, isInstagramApi: true });
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
await api.get<InstagramAccount>(`/me`, {
|
|
164
|
+
params: {
|
|
165
|
+
access_token: accessToken,
|
|
166
|
+
fields: fields.join(","),
|
|
167
|
+
},
|
|
168
|
+
})
|
|
169
|
+
).data;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
public static async getAdAccounts({
|
|
173
|
+
accessToken,
|
|
174
|
+
apiVersion,
|
|
175
|
+
}: Omit<GetAccounts, "fields">): Promise<FacebookPage[]> {
|
|
176
|
+
const api = generateAxiosInstance({ apiVersion });
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
await api.get<FacebookAdAccount>(`/me/adaccounts`, {
|
|
180
|
+
params: {
|
|
181
|
+
access_token: accessToken,
|
|
182
|
+
},
|
|
183
|
+
})
|
|
184
|
+
).data.data;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
public static async generateIgLongToken({
|
|
188
|
+
accessToken,
|
|
189
|
+
apiVersion,
|
|
190
|
+
clientSecret,
|
|
191
|
+
}: {
|
|
192
|
+
accessToken: string;
|
|
193
|
+
apiVersion: ApiVersion;
|
|
194
|
+
clientSecret: string;
|
|
195
|
+
}): Promise<string> {
|
|
196
|
+
const api = generateAxiosInstance({ apiVersion, isInstagramApi: true });
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
await api.get<GetAlongTokenMetaResponse>("/access_token", {
|
|
200
|
+
params: {
|
|
201
|
+
client_secret: clientSecret,
|
|
202
|
+
access_token: accessToken,
|
|
203
|
+
grant_type: "ig_exchange_token",
|
|
204
|
+
},
|
|
205
|
+
})
|
|
206
|
+
).data.access_token;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
public static async generateIgRefreshToken({
|
|
210
|
+
accessToken,
|
|
211
|
+
apiVersion,
|
|
212
|
+
}: {
|
|
213
|
+
accessToken: string;
|
|
214
|
+
apiVersion: ApiVersion;
|
|
215
|
+
}): Promise<string> {
|
|
216
|
+
const api = generateAxiosInstance({ apiVersion, isInstagramApi: true });
|
|
217
|
+
|
|
218
|
+
return (
|
|
219
|
+
await api.get<GetAlongTokenMetaResponse>("/refresh_access_token", {
|
|
220
|
+
params: {
|
|
221
|
+
access_token: accessToken,
|
|
222
|
+
grant_type: "ig_refresh_token",
|
|
223
|
+
},
|
|
224
|
+
})
|
|
225
|
+
).data.access_token;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ConstructorIng } from "../../interfaces/ing-publish";
|
|
2
|
+
import { IngPublish } from "../publish/ing-publish";
|
|
3
|
+
|
|
4
|
+
export class IngComments extends IngPublish {
|
|
5
|
+
constructor(constructorIng: ConstructorIng) {
|
|
6
|
+
super({ ...constructorIng, isInstagramApi: true });
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
public async createComment(postId: string, message: string): Promise<string> {
|
|
10
|
+
const response = await this.api.post<{ id: string }>(
|
|
11
|
+
`/${postId}/comments`,
|
|
12
|
+
{
|
|
13
|
+
message,
|
|
14
|
+
access_token: this.pageAccessToken,
|
|
15
|
+
},
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
return response.data.id;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public async updateCommentStatus(
|
|
22
|
+
postId: string,
|
|
23
|
+
enabled: boolean,
|
|
24
|
+
): Promise<boolean> {
|
|
25
|
+
await this.api.post(
|
|
26
|
+
`/${postId}`,
|
|
27
|
+
{},
|
|
28
|
+
{
|
|
29
|
+
params: {
|
|
30
|
+
comment_enabled: enabled,
|
|
31
|
+
access_token: this.pageAccessToken,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ConstructorPage } from "../../interfaces/page-publish";
|
|
2
|
+
import { PagePublish } from "../publish/page-publish";
|
|
3
|
+
|
|
4
|
+
export class PageComments extends PagePublish {
|
|
5
|
+
constructor(constructorPage: ConstructorPage) {
|
|
6
|
+
super(constructorPage);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
public async createComment(postId: string, message: string): Promise<string> {
|
|
10
|
+
const response = await this.api.post<{ id: string }>(
|
|
11
|
+
`/${postId}/comments`,
|
|
12
|
+
{
|
|
13
|
+
message,
|
|
14
|
+
access_token: this.pageAccessToken,
|
|
15
|
+
},
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
return response.data.id;
|
|
19
|
+
}
|
|
20
|
+
}
|