@neuralinnovations/dataisland-sdk 0.6.12 → 0.6.13
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/package.json +1 -1
- package/dist/src/dto/instaResponse.d.ts +9 -3
- package/dist/src/dto/instaResponse.d.ts.map +1 -1
- package/dist/src/dto/instaResponse.js +6 -0
- package/dist/src/dto/instaResponse.js.map +1 -1
- package/dist/src/storages/insta/instaAccounts.d.ts +4 -3
- package/dist/src/storages/insta/instaAccounts.d.ts.map +1 -1
- package/dist/src/storages/insta/instaAccounts.impl.d.ts +9 -4
- package/dist/src/storages/insta/instaAccounts.impl.d.ts.map +1 -1
- package/dist/src/storages/insta/instaAccounts.impl.js +44 -7
- package/dist/src/storages/insta/instaAccounts.impl.js.map +1 -1
- package/dist/src/storages/insta/instaAccounts.js.map +1 -1
- package/dist/src/storages/insta/instaPost.d.ts +10 -0
- package/dist/src/storages/insta/instaPost.d.ts.map +1 -0
- package/dist/src/storages/insta/instaPost.impl.d.ts +15 -0
- package/dist/src/storages/insta/instaPost.impl.d.ts.map +1 -0
- package/dist/src/storages/insta/instaPost.impl.js +55 -0
- package/dist/src/storages/insta/instaPost.impl.js.map +1 -0
- package/dist/src/storages/insta/instaPost.js +7 -0
- package/dist/src/storages/insta/instaPost.js.map +1 -0
- package/package.json +1 -1
- package/src/dto/instaResponse.ts +10 -3
- package/src/storages/insta/instaAccounts.impl.ts +68 -9
- package/src/storages/insta/instaAccounts.ts +6 -5
- package/src/storages/insta/instaPost.impl.ts +68 -0
- package/src/storages/insta/instaPost.ts +17 -0
package/dist/package.json
CHANGED
@@ -11,8 +11,14 @@ export interface InstaCutAccountDto {
|
|
11
11
|
id: string;
|
12
12
|
name: string;
|
13
13
|
}
|
14
|
-
export interface
|
15
|
-
|
16
|
-
|
14
|
+
export interface InstaPostDto {
|
15
|
+
id: string;
|
16
|
+
status: PostStatus;
|
17
|
+
message: string;
|
18
|
+
postLeft: number;
|
19
|
+
}
|
20
|
+
export declare enum PostStatus {
|
21
|
+
Generation = 0,
|
22
|
+
Finished = 1
|
17
23
|
}
|
18
24
|
//# sourceMappingURL=instaResponse.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"instaResponse.d.ts","sourceRoot":"","sources":["../../../src/dto/instaResponse.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,MAAM,CAAA;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,iBAAiB,EAAE,MAAM,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,
|
1
|
+
{"version":3,"file":"instaResponse.d.ts","sourceRoot":"","sources":["../../../src/dto/instaResponse.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,MAAM,CAAA;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,iBAAiB,EAAE,MAAM,CAAA;IACzB,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,UAAU,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,oBAAY,UAAU;IACpB,UAAU,IAAI;IACd,QAAQ,IAAI;CACb"}
|
@@ -1,3 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.PostStatus = void 0;
|
4
|
+
var PostStatus;
|
5
|
+
(function (PostStatus) {
|
6
|
+
PostStatus[PostStatus["Generation"] = 0] = "Generation";
|
7
|
+
PostStatus[PostStatus["Finished"] = 1] = "Finished";
|
8
|
+
})(PostStatus || (exports.PostStatus = PostStatus = {}));
|
3
9
|
//# sourceMappingURL=instaResponse.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"instaResponse.js","sourceRoot":"","sources":["../../../src/dto/instaResponse.ts"],"names":[],"mappings":""}
|
1
|
+
{"version":3,"file":"instaResponse.js","sourceRoot":"","sources":["../../../src/dto/instaResponse.ts"],"names":[],"mappings":";;;AAyBA,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,uDAAc,CAAA;IACd,mDAAY,CAAA;AACd,CAAC,EAHW,UAAU,0BAAV,UAAU,QAGrB"}
|
@@ -1,10 +1,11 @@
|
|
1
|
-
import { InstaPostResult } from "../../dto/instaResponse";
|
2
1
|
import { InstaAccount } from "./instaAccount";
|
2
|
+
import { InstaPost } from "./instaPost";
|
3
3
|
export declare abstract class InstaAccounts {
|
4
|
-
abstract get
|
4
|
+
abstract get accounts(): InstaAccount[];
|
5
|
+
abstract get posts(): InstaPost[];
|
5
6
|
abstract update(): Promise<void>;
|
6
7
|
abstract add(name: string, token: string, accountId: string, additionalContext: string, folderId: string): Promise<void>;
|
7
8
|
abstract delete(id: string): Promise<void>;
|
8
|
-
abstract post(message: string): Promise<
|
9
|
+
abstract post(message: string): Promise<void>;
|
9
10
|
}
|
10
11
|
//# sourceMappingURL=instaAccounts.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"instaAccounts.d.ts","sourceRoot":"","sources":["../../../../src/storages/insta/instaAccounts.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"instaAccounts.d.ts","sourceRoot":"","sources":["../../../../src/storages/insta/instaAccounts.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAA;AAGrC,8BAAsB,aAAa;IAEjC,QAAQ,KAAK,QAAQ,IAAI,YAAY,EAAE,CAAA;IAEvC,QAAQ,KAAK,KAAK,IAAI,SAAS,EAAE,CAAA;IAEjC,QAAQ,CAAC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAEhC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAExH,QAAQ,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAE1C,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAE9C"}
|
@@ -1,17 +1,22 @@
|
|
1
1
|
import { InstaAccounts } from "./instaAccounts";
|
2
|
-
import { InstaPostResult } from "../../dto/instaResponse";
|
3
2
|
import { OrganizationImpl } from "../organizations/organization.impl";
|
4
3
|
import { Context } from "../../context";
|
5
4
|
import { InstaAccount } from "./instaAccount";
|
5
|
+
import { InstaPost } from "./instaPost";
|
6
6
|
export declare class InstaAccountsImpl extends InstaAccounts {
|
7
7
|
readonly organization: OrganizationImpl;
|
8
8
|
readonly context: Context;
|
9
|
-
private
|
9
|
+
private _accounts?;
|
10
|
+
private _posts?;
|
11
|
+
private _inProgress;
|
12
|
+
private _fetchTimeout?;
|
10
13
|
constructor(organization: OrganizationImpl, context: Context);
|
11
|
-
get
|
14
|
+
get accounts(): InstaAccount[];
|
15
|
+
get posts(): InstaPost[];
|
16
|
+
internalFetchPosts(): Promise<void>;
|
12
17
|
update(): Promise<void>;
|
13
18
|
add(name: string, token: string, accountId: string, additionalContext: string, folderId: string): Promise<void>;
|
14
19
|
delete(id: string): Promise<void>;
|
15
|
-
post(message: string): Promise<
|
20
|
+
post(message: string): Promise<void>;
|
16
21
|
}
|
17
22
|
//# sourceMappingURL=instaAccounts.impl.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"instaAccounts.impl.d.ts","sourceRoot":"","sources":["../../../../src/storages/insta/instaAccounts.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAA;
|
1
|
+
{"version":3,"file":"instaAccounts.impl.d.ts","sourceRoot":"","sources":["../../../../src/storages/insta/instaAccounts.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAA;AAQ7C,OAAO,EAAC,gBAAgB,EAAC,MAAM,oCAAoC,CAAA;AACnE,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAA;AAErC,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAA;AAE3C,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAA;AAGrC,qBAAa,iBAAkB,SAAQ,aAAa;aAUhC,YAAY,EAAE,gBAAgB;aAC9B,OAAO,EAAE,OAAO;IAVlC,OAAO,CAAC,SAAS,CAAC,CAAoB;IACtC,OAAO,CAAC,MAAM,CAAC,CAAiB;IAGhC,OAAO,CAAC,WAAW,CAAsB;IAEzC,OAAO,CAAC,aAAa,CAAC,CAAgB;gBAGpB,YAAY,EAAE,gBAAgB,EAC9B,OAAO,EAAE,OAAO;IAKlC,IAAI,QAAQ,IAAI,YAAY,EAAE,CAM7B;IAED,IAAI,KAAK,IAAI,SAAS,EAAE,CAMvB;IAEK,kBAAkB;IAelB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IA6CvB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAwC/G,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BjC,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAwB3C"}
|
@@ -2,25 +2,48 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.InstaAccountsImpl = void 0;
|
4
4
|
const instaAccounts_1 = require("./instaAccounts");
|
5
|
+
const instaResponse_1 = require("../../dto/instaResponse");
|
5
6
|
const rpcService_1 = require("../../services/rpcService");
|
6
7
|
const responseUtils_1 = require("../../services/responseUtils");
|
7
8
|
const instaAccount_impl_1 = require("./instaAccount.impl");
|
9
|
+
const instaPost_impl_1 = require("./instaPost.impl");
|
8
10
|
class InstaAccountsImpl extends instaAccounts_1.InstaAccounts {
|
9
11
|
constructor(organization, context) {
|
10
12
|
super();
|
11
13
|
this.organization = organization;
|
12
14
|
this.context = context;
|
15
|
+
this._inProgress = [];
|
13
16
|
}
|
14
|
-
get
|
15
|
-
if (this.
|
16
|
-
return this.
|
17
|
+
get accounts() {
|
18
|
+
if (this._accounts !== undefined) {
|
19
|
+
return this._accounts;
|
17
20
|
}
|
18
21
|
else {
|
19
22
|
throw new Error("Insta accounts collection is not loaded, please update it first");
|
20
23
|
}
|
21
24
|
}
|
25
|
+
get posts() {
|
26
|
+
if (this._posts !== undefined) {
|
27
|
+
return this._posts;
|
28
|
+
}
|
29
|
+
else {
|
30
|
+
throw new Error("Insta posts collection is not loaded, please update it first");
|
31
|
+
}
|
32
|
+
}
|
33
|
+
async internalFetchPosts() {
|
34
|
+
for (const post of this._inProgress) {
|
35
|
+
await post.update();
|
36
|
+
}
|
37
|
+
this._inProgress = this._inProgress.filter(post => post.status == instaResponse_1.PostStatus.Generation);
|
38
|
+
if (this._inProgress.length > 0) {
|
39
|
+
this._fetchTimeout = setTimeout(async () => await this.internalFetchPosts(), 2000);
|
40
|
+
}
|
41
|
+
else {
|
42
|
+
clearTimeout(this._fetchTimeout);
|
43
|
+
}
|
44
|
+
}
|
22
45
|
async update() {
|
23
|
-
var _a;
|
46
|
+
var _a, _b;
|
24
47
|
const response = await ((_a = this.context
|
25
48
|
.resolve(rpcService_1.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Insta/list").searchParam("organizationId", this.organization.id).sendGet());
|
26
49
|
// check response status
|
@@ -28,7 +51,21 @@ class InstaAccountsImpl extends instaAccounts_1.InstaAccounts {
|
|
28
51
|
await responseUtils_1.ResponseUtils.throwError(`Insta accounts list for organization ${this.organization.id} failed`, response);
|
29
52
|
}
|
30
53
|
const accounts = (await response.json()).instaAccounts;
|
31
|
-
this.
|
54
|
+
this._accounts = accounts.map(acc => new instaAccount_impl_1.InstaAccountImpl(this.context, acc.id));
|
55
|
+
const postsResponse = await ((_b = this.context
|
56
|
+
.resolve(rpcService_1.RpcService)) === null || _b === void 0 ? void 0 : _b.requestBuilder("api/v1/Insta/post/list").searchParam("organizationId", this.organization.id).sendGet());
|
57
|
+
// check response status
|
58
|
+
if (responseUtils_1.ResponseUtils.isFail(postsResponse)) {
|
59
|
+
await responseUtils_1.ResponseUtils.throwError(`Insta posts list for organization ${this.organization.id} failed`, postsResponse);
|
60
|
+
}
|
61
|
+
const posts = (await postsResponse.json()).posts;
|
62
|
+
this._posts = posts.map(acc => new instaPost_impl_1.InstaPostImpl(this.context, acc.id));
|
63
|
+
this._inProgress = [];
|
64
|
+
clearTimeout(this._fetchTimeout);
|
65
|
+
this._inProgress = this._posts.filter(post => post.status == instaResponse_1.PostStatus.Generation);
|
66
|
+
if (this._inProgress.length > 0) {
|
67
|
+
this._fetchTimeout = setTimeout(async () => await this.internalFetchPosts(), 2000);
|
68
|
+
}
|
32
69
|
}
|
33
70
|
async add(name, token, accountId, additionalContext, folderId) {
|
34
71
|
var _a;
|
@@ -65,7 +102,7 @@ class InstaAccountsImpl extends instaAccounts_1.InstaAccounts {
|
|
65
102
|
}
|
66
103
|
async delete(id) {
|
67
104
|
var _a, _b;
|
68
|
-
const account = (_a = this.
|
105
|
+
const account = (_a = this._accounts) === null || _a === void 0 ? void 0 : _a.find(acc => acc.id === id);
|
69
106
|
// check if account is found
|
70
107
|
if (!account) {
|
71
108
|
throw new Error(`Insta account ${id} is not found, organization: ${this.organization.id}`);
|
@@ -94,7 +131,7 @@ class InstaAccountsImpl extends instaAccounts_1.InstaAccounts {
|
|
94
131
|
if (responseUtils_1.ResponseUtils.isFail(response)) {
|
95
132
|
await responseUtils_1.ResponseUtils.throwError(`Failed to add post for insta accounts in organization ${this.organization.id}`, response);
|
96
133
|
}
|
97
|
-
|
134
|
+
await this.update();
|
98
135
|
}
|
99
136
|
}
|
100
137
|
exports.InstaAccountsImpl = InstaAccountsImpl;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"instaAccounts.impl.js","sourceRoot":"","sources":["../../../../src/storages/insta/instaAccounts.impl.ts"],"names":[],"mappings":";;;AAAA,mDAA6C;
|
1
|
+
{"version":3,"file":"instaAccounts.impl.js","sourceRoot":"","sources":["../../../../src/storages/insta/instaAccounts.impl.ts"],"names":[],"mappings":";;;AAAA,mDAA6C;AAC7C,2DAIgC;AAChC,0DAAoD;AACpD,gEAA0D;AAG1D,2DAAoD;AAEpD,qDAA8C;AAI9C,MAAa,iBAAkB,SAAQ,6BAAa;IASlD,YACkB,YAA8B,EAC9B,OAAgB;QAChC,KAAK,EAAE,CAAA;QAFS,iBAAY,GAAZ,YAAY,CAAkB;QAC9B,YAAO,GAAP,OAAO,CAAS;QAN1B,gBAAW,GAAoB,EAAE,CAAA;IAQzC,CAAC;IAGD,IAAI,QAAQ;QACV,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC,SAAS,CAAA;QACvB,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,iEAAiE,C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ACxB,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACvE,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAA;QACrE,CAAC;QAED,oCAAoC;QACpC,MAAM,QAAQ,GAAG,MAAM,CAAA,MAAA,IAAI,CAAC,OAAO;aAChC,OAAO,CAAC,uBAAU,CAAC,0CAClB,cAAc,CAAC,mBAAmB,EACnC,YAAY,CAAC;YACZ,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,EAAE;YACpC,OAAO,EAAE,OAAO;SACjB,CAAC,CAAA,CAAA;QAEJ,wBAAwB;QACxB,IAAI,6BAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YACnC,MAAM,6BAAa,CAAC,UAAU,CAAC,yDAAyD,IAAI,CAAC,YAAY,CAAC,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAA;QAC3H,CAAC;QAGD,MAAM,IAAI,CAAC,MAAM,EAAE,CAAA;IACrB,CAAC;CAGF;AAtLD,8CAsLC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"instaAccounts.js","sourceRoot":"","sources":["../../../../src/storages/insta/instaAccounts.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"instaAccounts.js","sourceRoot":"","sources":["../../../../src/storages/insta/instaAccounts.ts"],"names":[],"mappings":";;;AAKA,MAAsB,aAAa;CAclC;AAdD,sCAcC"}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { PostStatus } from "../../dto/instaResponse";
|
2
|
+
export type InstaPostId = string;
|
3
|
+
export declare abstract class InstaPost {
|
4
|
+
abstract get id(): InstaPostId;
|
5
|
+
abstract get message(): string;
|
6
|
+
abstract get status(): PostStatus;
|
7
|
+
abstract get postsLeft(): number;
|
8
|
+
abstract update(): Promise<void>;
|
9
|
+
}
|
10
|
+
//# sourceMappingURL=instaPost.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"instaPost.d.ts","sourceRoot":"","sources":["../../../../src/storages/insta/instaPost.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAGlD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AAEjC,8BAAsB,SAAS;IAE7B,QAAQ,KAAK,EAAE,IAAI,WAAW,CAAA;IAE9B,QAAQ,KAAK,OAAO,IAAI,MAAM,CAAA;IAE9B,QAAQ,KAAK,MAAM,IAAI,UAAU,CAAA;IAEjC,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAA;IAEhC,QAAQ,CAAC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CACjC"}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { InstaPost, InstaPostId } from "./instaPost";
|
2
|
+
import { Context } from "../../context";
|
3
|
+
import { PostStatus } from "../../dto/instaResponse";
|
4
|
+
export declare class InstaPostImpl extends InstaPost {
|
5
|
+
private readonly context;
|
6
|
+
private readonly _id;
|
7
|
+
private _data?;
|
8
|
+
constructor(context: Context, id: string);
|
9
|
+
get id(): InstaPostId;
|
10
|
+
get message(): string;
|
11
|
+
get status(): PostStatus;
|
12
|
+
get postsLeft(): number;
|
13
|
+
update(): Promise<void>;
|
14
|
+
}
|
15
|
+
//# sourceMappingURL=instaPost.impl.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"instaPost.impl.d.ts","sourceRoot":"","sources":["../../../../src/storages/insta/instaPost.impl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,WAAW,EAAC,MAAM,aAAa,CAAA;AAClD,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAA;AACrC,OAAO,EAEL,UAAU,EACX,MAAM,yBAAyB,CAAA;AAKhC,qBAAa,aAAc,SAAQ,SAAS;IAK9B,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJpC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAE5B,OAAO,CAAC,KAAK,CAAC,CAAc;gBAEC,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM;IAMzD,IAAI,EAAE,IAAI,WAAW,CAEpB;IAED,IAAI,OAAO,IAAI,MAAM,CAMpB;IAED,IAAI,MAAM,IAAI,UAAU,CAMvB;IAED,IAAI,SAAS,IAAI,MAAM,CAMtB;IAEK,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAkB9B"}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.InstaPostImpl = void 0;
|
4
|
+
const instaPost_1 = require("./instaPost");
|
5
|
+
const rpcService_1 = require("../../services/rpcService");
|
6
|
+
const responseUtils_1 = require("../../services/responseUtils");
|
7
|
+
class InstaPostImpl extends instaPost_1.InstaPost {
|
8
|
+
constructor(context, id) {
|
9
|
+
super();
|
10
|
+
this.context = context;
|
11
|
+
this._id = id;
|
12
|
+
}
|
13
|
+
get id() {
|
14
|
+
return this._id;
|
15
|
+
}
|
16
|
+
get message() {
|
17
|
+
var _a;
|
18
|
+
if (this._data) {
|
19
|
+
return (_a = this._data) === null || _a === void 0 ? void 0 : _a.message;
|
20
|
+
}
|
21
|
+
else {
|
22
|
+
throw new Error("Insta post data not loaded, please call update first");
|
23
|
+
}
|
24
|
+
}
|
25
|
+
get status() {
|
26
|
+
var _a;
|
27
|
+
if (this._data) {
|
28
|
+
return (_a = this._data) === null || _a === void 0 ? void 0 : _a.status;
|
29
|
+
}
|
30
|
+
else {
|
31
|
+
throw new Error("Insta post data not loaded, please call update first");
|
32
|
+
}
|
33
|
+
}
|
34
|
+
get postsLeft() {
|
35
|
+
var _a;
|
36
|
+
if (this._data) {
|
37
|
+
return (_a = this._data) === null || _a === void 0 ? void 0 : _a.postLeft;
|
38
|
+
}
|
39
|
+
else {
|
40
|
+
throw new Error("Insta post data not loaded, please call update first");
|
41
|
+
}
|
42
|
+
}
|
43
|
+
async update() {
|
44
|
+
var _a;
|
45
|
+
const response = await ((_a = this.context
|
46
|
+
.resolve(rpcService_1.RpcService)) === null || _a === void 0 ? void 0 : _a.requestBuilder("api/v1/Insta/post/status").searchParam("postId", this._id).sendGet());
|
47
|
+
// check response status
|
48
|
+
if (responseUtils_1.ResponseUtils.isFail(response)) {
|
49
|
+
await responseUtils_1.ResponseUtils.throwError(`Insta post status get for post ${this._id} failes`, response);
|
50
|
+
}
|
51
|
+
this._data = (await response.json()).post;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
exports.InstaPostImpl = InstaPostImpl;
|
55
|
+
//# sourceMappingURL=instaPost.impl.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"instaPost.impl.js","sourceRoot":"","sources":["../../../../src/storages/insta/instaPost.impl.ts"],"names":[],"mappings":";;;AAAA,2CAAkD;AAMlD,0DAAoD;AACpD,gEAA0D;AAG1D,MAAa,aAAc,SAAQ,qBAAS;IAK1C,YAA6B,OAAgB,EAAE,EAAU;QACvD,KAAK,EAAE,CAAA;QADoB,YAAO,GAAP,OAAO,CAAS;QAG3C,IAAI,CAAC,GAAG,GAAG,EAAE,CAAA;IACf,CAAC;IAED,IAAI,EAAE;QACJ,OAAoB,IAAI,CAAC,GAAG,CAAA;IAC9B,CAAC;IAED,IAAI,OAAO;;QACT,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,OAAO,MAAA,IAAI,CAAC,KAAK,0CAAE,OAAO,CAAA;QAC5B,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;QACzE,CAAC;IACH,CAAC;IAED,IAAI,MAAM;;QACR,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,OAAO,MAAA,IAAI,CAAC,KAAK,0CAAE,MAAM,CAAA;QAC3B,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;QACzE,CAAC;IACH,CAAC;IAED,IAAI,SAAS;;QACX,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,OAAO,MAAA,IAAI,CAAC,KAAK,0CAAE,QAAQ,CAAA;QAC7B,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;QACzE,CAAC;IACH,CAAC;IAED,KAAK,CAAC,MAAM;;QACV,MAAM,QAAQ,GAAG,MAAM,CAAA,MAAA,IAAI,CAAC,OAAO;aAChC,OAAO,CAAC,uBAAU,CAAC,0CAClB,cAAc,CAAC,0BAA0B,EAC1C,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,EAC9B,OAAO,EAAE,CAAA,CAAA;QAEZ,wBAAwB;QACxB,IAAI,6BAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YACnC,MAAM,6BAAa,CAAC,UAAU,CAC5B,kCAAkC,IAAI,CAAC,GAAG,SAAS,EACnD,QAAQ,CACT,CAAA;QACH,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,CAAC,MAAM,QAAS,CAAC,IAAI,EAA2B,CAAA,CAAC,IAAI,CAAA;IACpE,CAAC;CAEF;AAzDD,sCAyDC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"instaPost.js","sourceRoot":"","sources":["../../../../src/storages/insta/instaPost.ts"],"names":[],"mappings":";;;AAKA,MAAsB,SAAS;CAW9B;AAXD,8BAWC"}
|
package/package.json
CHANGED
package/src/dto/instaResponse.ts
CHANGED
@@ -16,7 +16,14 @@ export interface InstaCutAccountDto {
|
|
16
16
|
name: string
|
17
17
|
}
|
18
18
|
|
19
|
-
export interface
|
20
|
-
|
21
|
-
|
19
|
+
export interface InstaPostDto {
|
20
|
+
id: string
|
21
|
+
status: PostStatus
|
22
|
+
message: string
|
23
|
+
postLeft: number
|
24
|
+
}
|
25
|
+
|
26
|
+
export enum PostStatus {
|
27
|
+
Generation = 0,
|
28
|
+
Finished = 1
|
22
29
|
}
|
@@ -1,15 +1,27 @@
|
|
1
1
|
import {InstaAccounts} from "./instaAccounts"
|
2
|
-
import {
|
2
|
+
import {
|
3
|
+
InstaCutAccountDto,
|
4
|
+
InstaPostDto,
|
5
|
+
PostStatus,
|
6
|
+
} from "../../dto/instaResponse"
|
3
7
|
import {RpcService} from "../../services/rpcService"
|
4
8
|
import {ResponseUtils} from "../../services/responseUtils"
|
5
9
|
import {OrganizationImpl} from "../organizations/organization.impl"
|
6
10
|
import {Context} from "../../context"
|
7
11
|
import {InstaAccountImpl} from "./instaAccount.impl"
|
8
12
|
import {InstaAccount} from "./instaAccount"
|
13
|
+
import {InstaPostImpl} from "./instaPost.impl"
|
14
|
+
import {InstaPost} from "./instaPost"
|
9
15
|
|
10
16
|
|
11
17
|
export class InstaAccountsImpl extends InstaAccounts {
|
12
|
-
private
|
18
|
+
private _accounts?: InstaAccountImpl[]
|
19
|
+
private _posts?: InstaPostImpl[]
|
20
|
+
|
21
|
+
|
22
|
+
private _inProgress: InstaPostImpl[] = []
|
23
|
+
|
24
|
+
private _fetchTimeout?: NodeJS.Timeout
|
13
25
|
|
14
26
|
constructor(
|
15
27
|
public readonly organization: OrganizationImpl,
|
@@ -18,14 +30,36 @@ export class InstaAccountsImpl extends InstaAccounts {
|
|
18
30
|
}
|
19
31
|
|
20
32
|
|
21
|
-
get
|
22
|
-
if (this.
|
23
|
-
return this.
|
33
|
+
get accounts(): InstaAccount[] {
|
34
|
+
if (this._accounts !== undefined) {
|
35
|
+
return this._accounts
|
24
36
|
} else {
|
25
37
|
throw new Error("Insta accounts collection is not loaded, please update it first")
|
26
38
|
}
|
27
39
|
}
|
28
40
|
|
41
|
+
get posts(): InstaPost[] {
|
42
|
+
if (this._posts !== undefined) {
|
43
|
+
return this._posts
|
44
|
+
} else {
|
45
|
+
throw new Error("Insta posts collection is not loaded, please update it first")
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
async internalFetchPosts() {
|
50
|
+
for (const post of this._inProgress){
|
51
|
+
await post.update()
|
52
|
+
}
|
53
|
+
|
54
|
+
this._inProgress = this._inProgress.filter(post => post.status == PostStatus.Generation)
|
55
|
+
|
56
|
+
if (this._inProgress.length > 0) {
|
57
|
+
this._fetchTimeout = setTimeout(async () => await this.internalFetchPosts(), 2000)
|
58
|
+
} else {
|
59
|
+
clearTimeout(this._fetchTimeout)
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
29
63
|
|
30
64
|
async update(): Promise<void> {
|
31
65
|
const response = await this.context
|
@@ -43,8 +77,33 @@ export class InstaAccountsImpl extends InstaAccounts {
|
|
43
77
|
}
|
44
78
|
|
45
79
|
const accounts = (await response!.json() as {instaAccounts: InstaCutAccountDto[]}).instaAccounts
|
80
|
+
this._accounts = accounts.map(acc => new InstaAccountImpl(this.context, acc.id))
|
46
81
|
|
47
|
-
|
82
|
+
const postsResponse = await this.context
|
83
|
+
.resolve(RpcService)
|
84
|
+
?.requestBuilder("api/v1/Insta/post/list")
|
85
|
+
.searchParam("organizationId", this.organization.id)
|
86
|
+
.sendGet()
|
87
|
+
|
88
|
+
// check response status
|
89
|
+
if (ResponseUtils.isFail(postsResponse)) {
|
90
|
+
await ResponseUtils.throwError(
|
91
|
+
`Insta posts list for organization ${this.organization.id} failed`,
|
92
|
+
postsResponse
|
93
|
+
)
|
94
|
+
}
|
95
|
+
|
96
|
+
const posts = (await postsResponse!.json() as {posts: InstaPostDto[]}).posts
|
97
|
+
this._posts = posts.map(acc => new InstaPostImpl(this.context, acc.id))
|
98
|
+
|
99
|
+
this._inProgress = []
|
100
|
+
clearTimeout(this._fetchTimeout)
|
101
|
+
|
102
|
+
this._inProgress = this._posts.filter(post => post.status == PostStatus.Generation)
|
103
|
+
|
104
|
+
if (this._inProgress.length > 0) {
|
105
|
+
this._fetchTimeout = setTimeout(async () => await this.internalFetchPosts(), 2000)
|
106
|
+
}
|
48
107
|
}
|
49
108
|
|
50
109
|
async add(name: string, token: string, accountId: string, additionalContext: string, folderId: string): Promise<void> {
|
@@ -88,7 +147,7 @@ export class InstaAccountsImpl extends InstaAccounts {
|
|
88
147
|
|
89
148
|
|
90
149
|
async delete(id: string): Promise<void> {
|
91
|
-
const account = this.
|
150
|
+
const account = this._accounts?.find(acc => acc.id === id)
|
92
151
|
|
93
152
|
// check if account is found
|
94
153
|
if (!account) {
|
@@ -113,7 +172,7 @@ export class InstaAccountsImpl extends InstaAccounts {
|
|
113
172
|
await this.update()
|
114
173
|
}
|
115
174
|
|
116
|
-
async post(message: string): Promise<
|
175
|
+
async post(message: string): Promise<void> {
|
117
176
|
if (message === undefined || message === null || message.trim() === "") {
|
118
177
|
throw new Error("Add insta post, message can not be null or empty")
|
119
178
|
}
|
@@ -133,7 +192,7 @@ export class InstaAccountsImpl extends InstaAccounts {
|
|
133
192
|
}
|
134
193
|
|
135
194
|
|
136
|
-
|
195
|
+
await this.update()
|
137
196
|
}
|
138
197
|
|
139
198
|
|
@@ -1,12 +1,13 @@
|
|
1
|
-
|
2
|
-
InstaPostResult
|
3
|
-
} from "../../dto/instaResponse"
|
1
|
+
|
4
2
|
import {InstaAccount} from "./instaAccount"
|
3
|
+
import {InstaPost} from "./instaPost"
|
5
4
|
|
6
5
|
|
7
6
|
export abstract class InstaAccounts {
|
8
7
|
|
9
|
-
abstract get
|
8
|
+
abstract get accounts(): InstaAccount[]
|
9
|
+
|
10
|
+
abstract get posts(): InstaPost[]
|
10
11
|
|
11
12
|
abstract update(): Promise<void>
|
12
13
|
|
@@ -14,6 +15,6 @@ export abstract class InstaAccounts {
|
|
14
15
|
|
15
16
|
abstract delete(id: string): Promise<void>
|
16
17
|
|
17
|
-
abstract post(message: string): Promise<
|
18
|
+
abstract post(message: string): Promise<void>
|
18
19
|
|
19
20
|
}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
import {InstaPost, InstaPostId} from "./instaPost"
|
2
|
+
import {Context} from "../../context"
|
3
|
+
import {
|
4
|
+
InstaPostDto,
|
5
|
+
PostStatus
|
6
|
+
} from "../../dto/instaResponse"
|
7
|
+
import {RpcService} from "../../services/rpcService"
|
8
|
+
import {ResponseUtils} from "../../services/responseUtils"
|
9
|
+
|
10
|
+
|
11
|
+
export class InstaPostImpl extends InstaPost {
|
12
|
+
private readonly _id: string
|
13
|
+
|
14
|
+
private _data?: InstaPostDto
|
15
|
+
|
16
|
+
constructor(private readonly context: Context, id: string) {
|
17
|
+
super()
|
18
|
+
|
19
|
+
this._id = id
|
20
|
+
}
|
21
|
+
|
22
|
+
get id(): InstaPostId {
|
23
|
+
return <InstaPostId>this._id
|
24
|
+
}
|
25
|
+
|
26
|
+
get message(): string {
|
27
|
+
if (this._data) {
|
28
|
+
return this._data?.message
|
29
|
+
} else {
|
30
|
+
throw new Error("Insta post data not loaded, please call update first")
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
get status(): PostStatus {
|
35
|
+
if (this._data) {
|
36
|
+
return this._data?.status
|
37
|
+
} else {
|
38
|
+
throw new Error("Insta post data not loaded, please call update first")
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
get postsLeft(): number {
|
43
|
+
if (this._data) {
|
44
|
+
return this._data?.postLeft
|
45
|
+
} else {
|
46
|
+
throw new Error("Insta post data not loaded, please call update first")
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
async update(): Promise<void> {
|
51
|
+
const response = await this.context
|
52
|
+
.resolve(RpcService)
|
53
|
+
?.requestBuilder("api/v1/Insta/post/status")
|
54
|
+
.searchParam("postId", this._id)
|
55
|
+
.sendGet()
|
56
|
+
|
57
|
+
// check response status
|
58
|
+
if (ResponseUtils.isFail(response)) {
|
59
|
+
await ResponseUtils.throwError(
|
60
|
+
`Insta post status get for post ${this._id} failes`,
|
61
|
+
response
|
62
|
+
)
|
63
|
+
}
|
64
|
+
|
65
|
+
this._data = (await response!.json() as {post: InstaPostDto}).post
|
66
|
+
}
|
67
|
+
|
68
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import {PostStatus} from "../../dto/instaResponse"
|
2
|
+
|
3
|
+
|
4
|
+
export type InstaPostId = string;
|
5
|
+
|
6
|
+
export abstract class InstaPost {
|
7
|
+
|
8
|
+
abstract get id(): InstaPostId
|
9
|
+
|
10
|
+
abstract get message(): string
|
11
|
+
|
12
|
+
abstract get status(): PostStatus
|
13
|
+
|
14
|
+
abstract get postsLeft(): number
|
15
|
+
|
16
|
+
abstract update(): Promise<void>
|
17
|
+
}
|