naystack 1.1.0 → 1.1.2
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/.tsbuildinfo +1 -0
- package/dist/auth/index.cjs.js +200 -11
- package/dist/auth/index.d.mts +45 -4
- package/dist/auth/index.d.ts +45 -4
- package/dist/auth/index.esm.js +173 -11
- package/dist/index.cjs.js +29 -5
- package/dist/index.esm.js +0 -1
- package/dist/socials/index.cjs.js +173 -33
- package/dist/socials/index.d.mts +68 -3
- package/dist/socials/index.d.ts +68 -3
- package/dist/socials/index.esm.js +123 -20
- package/package.json +14 -8
- package/dist/auth/email/index.cjs.js +0 -14
- package/dist/auth/email/index.cjs.js.map +0 -1
- package/dist/auth/email/index.d.mts +0 -18
- package/dist/auth/email/index.d.ts +0 -18
- package/dist/auth/email/index.esm.js +0 -14
- package/dist/auth/email/index.esm.js.map +0 -1
- package/dist/auth/email/routes/delete.cjs.js +0 -8
- package/dist/auth/email/routes/delete.cjs.js.map +0 -1
- package/dist/auth/email/routes/delete.d.mts +0 -8
- package/dist/auth/email/routes/delete.d.ts +0 -8
- package/dist/auth/email/routes/delete.esm.js +0 -8
- package/dist/auth/email/routes/delete.esm.js.map +0 -1
- package/dist/auth/email/routes/get.cjs.js +0 -8
- package/dist/auth/email/routes/get.cjs.js.map +0 -1
- package/dist/auth/email/routes/get.d.mts +0 -11
- package/dist/auth/email/routes/get.d.ts +0 -11
- package/dist/auth/email/routes/get.esm.js +0 -8
- package/dist/auth/email/routes/get.esm.js.map +0 -1
- package/dist/auth/email/routes/post.cjs.js +0 -10
- package/dist/auth/email/routes/post.cjs.js.map +0 -1
- package/dist/auth/email/routes/post.d.mts +0 -8
- package/dist/auth/email/routes/post.d.ts +0 -8
- package/dist/auth/email/routes/post.esm.js +0 -10
- package/dist/auth/email/routes/post.esm.js.map +0 -1
- package/dist/auth/email/routes/put.cjs.js +0 -10
- package/dist/auth/email/routes/put.cjs.js.map +0 -1
- package/dist/auth/email/routes/put.d.mts +0 -8
- package/dist/auth/email/routes/put.d.ts +0 -8
- package/dist/auth/email/routes/put.esm.js +0 -10
- package/dist/auth/email/routes/put.esm.js.map +0 -1
- package/dist/auth/email/token.cjs.js +0 -15
- package/dist/auth/email/token.cjs.js.map +0 -1
- package/dist/auth/email/token.d.mts +0 -13
- package/dist/auth/email/token.d.ts +0 -13
- package/dist/auth/email/token.esm.js +0 -15
- package/dist/auth/email/token.esm.js.map +0 -1
- package/dist/auth/email/types.cjs.js +0 -1
- package/dist/auth/email/types.cjs.js.map +0 -1
- package/dist/auth/email/types.d.mts +0 -14
- package/dist/auth/email/types.d.ts +0 -14
- package/dist/auth/email/types.esm.js +0 -1
- package/dist/auth/email/types.esm.js.map +0 -1
- package/dist/auth/email/utils.cjs.js +0 -10
- package/dist/auth/email/utils.cjs.js.map +0 -1
- package/dist/auth/email/utils.d.mts +0 -16
- package/dist/auth/email/utils.d.ts +0 -16
- package/dist/auth/email/utils.esm.js +0 -10
- package/dist/auth/email/utils.esm.js.map +0 -1
- package/dist/auth/index.cjs.js.map +0 -1
- package/dist/auth/index.esm.js.map +0 -1
- package/dist/auth/types.cjs.js +0 -1
- package/dist/auth/types.cjs.js.map +0 -1
- package/dist/auth/types.d.mts +0 -21
- package/dist/auth/types.d.ts +0 -21
- package/dist/auth/types.esm.js +0 -1
- package/dist/auth/types.esm.js.map +0 -1
- package/dist/auth/utils/errors.cjs.js +0 -7
- package/dist/auth/utils/errors.cjs.js.map +0 -1
- package/dist/auth/utils/errors.d.mts +0 -6
- package/dist/auth/utils/errors.d.ts +0 -6
- package/dist/auth/utils/errors.esm.js +0 -7
- package/dist/auth/utils/errors.esm.js.map +0 -1
- package/dist/chunk-37UVEZCA.esm.js +0 -11
- package/dist/chunk-37UVEZCA.esm.js.map +0 -1
- package/dist/chunk-6ZBFLB55.cjs.js +0 -47
- package/dist/chunk-6ZBFLB55.cjs.js.map +0 -1
- package/dist/chunk-7QIJ7FHA.cjs.js +0 -54
- package/dist/chunk-7QIJ7FHA.cjs.js.map +0 -1
- package/dist/chunk-AMP7DBFP.cjs.js +0 -12
- package/dist/chunk-AMP7DBFP.cjs.js.map +0 -1
- package/dist/chunk-AYIXZ7XQ.esm.js +0 -27
- package/dist/chunk-AYIXZ7XQ.esm.js.map +0 -1
- package/dist/chunk-CGRSCX3T.cjs.js +0 -53
- package/dist/chunk-CGRSCX3T.cjs.js.map +0 -1
- package/dist/chunk-E4A5ZSZU.esm.js +0 -33
- package/dist/chunk-E4A5ZSZU.esm.js.map +0 -1
- package/dist/chunk-ERHCUBHW.cjs.js +0 -27
- package/dist/chunk-ERHCUBHW.cjs.js.map +0 -1
- package/dist/chunk-FUZFHRDV.cjs.js +0 -21
- package/dist/chunk-FUZFHRDV.cjs.js.map +0 -1
- package/dist/chunk-HWKI3FIU.cjs.js +0 -33
- package/dist/chunk-HWKI3FIU.cjs.js.map +0 -1
- package/dist/chunk-IKQIDAZS.esm.js +0 -54
- package/dist/chunk-IKQIDAZS.esm.js.map +0 -1
- package/dist/chunk-J3TSW2Y3.esm.js +0 -58
- package/dist/chunk-J3TSW2Y3.esm.js.map +0 -1
- package/dist/chunk-JGNQS6S2.esm.js +0 -52
- package/dist/chunk-JGNQS6S2.esm.js.map +0 -1
- package/dist/chunk-JJXQ5JOS.esm.js +0 -12
- package/dist/chunk-JJXQ5JOS.esm.js.map +0 -1
- package/dist/chunk-L4I7NYLN.cjs.js +0 -15
- package/dist/chunk-L4I7NYLN.cjs.js.map +0 -1
- package/dist/chunk-LK3HK7R4.cjs.js +0 -11
- package/dist/chunk-LK3HK7R4.cjs.js.map +0 -1
- package/dist/chunk-MIXJIQ5O.esm.js +0 -15
- package/dist/chunk-MIXJIQ5O.esm.js.map +0 -1
- package/dist/chunk-N3XXF6VF.cjs.js +0 -27
- package/dist/chunk-N3XXF6VF.cjs.js.map +0 -1
- package/dist/chunk-Q7PSM2YD.esm.js +0 -47
- package/dist/chunk-Q7PSM2YD.esm.js.map +0 -1
- package/dist/chunk-SHMULRN5.cjs.js +0 -15
- package/dist/chunk-SHMULRN5.cjs.js.map +0 -1
- package/dist/chunk-TBMSHEBW.cjs.js +0 -58
- package/dist/chunk-TBMSHEBW.cjs.js.map +0 -1
- package/dist/chunk-UU7YFJ3G.esm.js +0 -15
- package/dist/chunk-UU7YFJ3G.esm.js.map +0 -1
- package/dist/chunk-WII2K6A5.esm.js +0 -27
- package/dist/chunk-WII2K6A5.esm.js.map +0 -1
- package/dist/chunk-Y7CO6FEH.esm.js +0 -21
- package/dist/chunk-Y7CO6FEH.esm.js.map +0 -1
- package/dist/chunk-YDL4WCOP.cjs.js +0 -52
- package/dist/chunk-YDL4WCOP.cjs.js.map +0 -1
- package/dist/chunk-ZRKBAPNJ.esm.js +0 -53
- package/dist/chunk-ZRKBAPNJ.esm.js.map +0 -1
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.esm.js.map +0 -1
- package/dist/socials/index.cjs.js.map +0 -1
- package/dist/socials/index.esm.js.map +0 -1
- package/dist/socials/instagram/getters.cjs.js +0 -18
- package/dist/socials/instagram/getters.cjs.js.map +0 -1
- package/dist/socials/instagram/getters.d.mts +0 -38
- package/dist/socials/instagram/getters.d.ts +0 -38
- package/dist/socials/instagram/getters.esm.js +0 -18
- package/dist/socials/instagram/getters.esm.js.map +0 -1
- package/dist/socials/instagram/utils.cjs.js +0 -9
- package/dist/socials/instagram/utils.cjs.js.map +0 -1
- package/dist/socials/instagram/utils.d.mts +0 -4
- package/dist/socials/instagram/utils.d.ts +0 -4
- package/dist/socials/instagram/utils.esm.js +0 -9
- package/dist/socials/instagram/utils.esm.js.map +0 -1
- package/dist/socials/threads/getters.cjs.js +0 -12
- package/dist/socials/threads/getters.cjs.js.map +0 -1
- package/dist/socials/threads/getters.d.mts +0 -5
- package/dist/socials/threads/getters.d.ts +0 -5
- package/dist/socials/threads/getters.esm.js +0 -12
- package/dist/socials/threads/getters.esm.js.map +0 -1
- package/dist/socials/threads/setters.cjs.js +0 -14
- package/dist/socials/threads/setters.cjs.js.map +0 -1
- package/dist/socials/threads/setters.d.mts +0 -6
- package/dist/socials/threads/setters.d.ts +0 -6
- package/dist/socials/threads/setters.esm.js +0 -14
- package/dist/socials/threads/setters.esm.js.map +0 -1
- package/dist/socials/threads/types.cjs.js +0 -1
- package/dist/socials/threads/types.cjs.js.map +0 -1
- package/dist/socials/threads/types.d.mts +0 -18
- package/dist/socials/threads/types.d.ts +0 -18
- package/dist/socials/threads/types.esm.js +0 -1
- package/dist/socials/threads/types.esm.js.map +0 -1
- package/dist/socials/threads/utils.cjs.js +0 -9
- package/dist/socials/threads/utils.cjs.js.map +0 -1
- package/dist/socials/threads/utils.d.mts +0 -4
- package/dist/socials/threads/utils.d.ts +0 -4
- package/dist/socials/threads/utils.esm.js +0 -9
- package/dist/socials/threads/utils.esm.js.map +0 -1
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,4 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
import 'next/server';
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import * as next_server from 'next/server';
|
|
2
|
+
import { NextResponse } from 'next/server';
|
|
3
|
+
|
|
4
|
+
type ErrorHandler = (error: {
|
|
5
|
+
status: number;
|
|
6
|
+
message: string;
|
|
7
|
+
}) => NextResponse;
|
|
8
|
+
type UserInput = {
|
|
9
|
+
email: string;
|
|
10
|
+
password: string;
|
|
11
|
+
} & {
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
};
|
|
14
|
+
type UserOutput = {
|
|
15
|
+
id: number;
|
|
16
|
+
email: string;
|
|
17
|
+
password: string | null;
|
|
18
|
+
} & {
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type InitRoutesOptions = {
|
|
23
|
+
getUser: (email: string) => Promise<UserOutput | undefined>;
|
|
24
|
+
createUser: (user: UserInput) => Promise<UserOutput | undefined>;
|
|
25
|
+
onError?: ErrorHandler;
|
|
26
|
+
signingKey: string;
|
|
27
|
+
refreshKey: string;
|
|
28
|
+
turnstileKey?: string;
|
|
29
|
+
onSignUp: (user: UserOutput) => void;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
declare function getEmailAuthRoutes(options: InitRoutesOptions): {
|
|
33
|
+
GET: (req: next_server.NextRequest) => next_server.NextResponse<{
|
|
34
|
+
accessToken: string | undefined;
|
|
35
|
+
refreshToken: string | undefined;
|
|
36
|
+
}>;
|
|
37
|
+
POST: (req: next_server.NextRequest) => Promise<next_server.NextResponse<unknown> | undefined>;
|
|
38
|
+
PUT: (req: next_server.NextRequest) => Promise<next_server.NextResponse<unknown> | undefined>;
|
|
39
|
+
DELETE: () => next_server.NextResponse<{
|
|
40
|
+
accessToken: string | undefined;
|
|
41
|
+
refreshToken: string | undefined;
|
|
42
|
+
}>;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { getEmailAuthRoutes };
|
package/dist/auth/index.esm.js
CHANGED
|
@@ -1,14 +1,176 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
} from "
|
|
4
|
-
import "
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
// src/auth/email/token.ts
|
|
2
|
+
import { compare } from "bcryptjs";
|
|
3
|
+
import { JsonWebTokenError, sign, verify } from "jsonwebtoken";
|
|
4
|
+
import { NextResponse } from "next/server";
|
|
5
|
+
function generateAccessToken(id, signingKey) {
|
|
6
|
+
return sign({ id }, signingKey, {
|
|
7
|
+
expiresIn: "2h"
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function generateRefreshToken(id, refreshKey) {
|
|
11
|
+
return sign({ id }, refreshKey);
|
|
12
|
+
}
|
|
13
|
+
function getTokenizedResponse(accessToken, refreshToken) {
|
|
14
|
+
const body = { accessToken, refreshToken };
|
|
15
|
+
const response = NextResponse.json(body, {
|
|
16
|
+
status: 200
|
|
17
|
+
});
|
|
18
|
+
if (!accessToken) {
|
|
19
|
+
response.cookies.set("refresh", "", {
|
|
20
|
+
secure: false,
|
|
21
|
+
httpOnly: true,
|
|
22
|
+
expires: 0
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (refreshToken !== void 0) {
|
|
26
|
+
response.cookies.set("refresh", refreshToken, {
|
|
27
|
+
secure: false,
|
|
28
|
+
httpOnly: true,
|
|
29
|
+
expires: refreshToken === "" ? 0 : new Date(Date.now() + 60 * 60 * 24 * 365 * 1e3)
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return response;
|
|
33
|
+
}
|
|
34
|
+
function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
35
|
+
if (refreshToken)
|
|
36
|
+
try {
|
|
37
|
+
const decoded = verify(refreshToken, refreshKey);
|
|
38
|
+
if (typeof decoded !== "string" && typeof decoded.id === "number")
|
|
39
|
+
return decoded.id;
|
|
40
|
+
} catch (e) {
|
|
41
|
+
if (!(e instanceof JsonWebTokenError)) console.error(e, "errors");
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
function verifyUser(user, password) {
|
|
47
|
+
if (!user.password) return false;
|
|
48
|
+
return compare(password, user.password);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/auth/email/routes/delete.ts
|
|
52
|
+
var getDeleteRoute = () => () => getTokenizedResponse(void 0, "");
|
|
53
|
+
|
|
54
|
+
// src/auth/email/routes/get.ts
|
|
55
|
+
var getGetRoute = (options) => (req) => {
|
|
56
|
+
const refresh = req.cookies.get("refresh")?.value;
|
|
57
|
+
const userID = getUserIdFromRefreshToken(options.refreshKey, refresh);
|
|
58
|
+
if (userID)
|
|
59
|
+
return getTokenizedResponse(
|
|
60
|
+
generateAccessToken(userID, options.signingKey)
|
|
61
|
+
);
|
|
62
|
+
return getTokenizedResponse();
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// src/auth/email/routes/post.ts
|
|
66
|
+
import { hash } from "bcryptjs";
|
|
67
|
+
|
|
68
|
+
// src/auth/utils/errors.ts
|
|
69
|
+
import { NextResponse as NextResponse2 } from "next/server";
|
|
70
|
+
function handleError(status, message, onError) {
|
|
71
|
+
const res = onError?.({ status, message });
|
|
72
|
+
if (res) return res;
|
|
73
|
+
return new NextResponse2(message, { status });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/auth/email/utils.ts
|
|
77
|
+
async function massageRequest(req, options) {
|
|
78
|
+
const data = await req.json();
|
|
79
|
+
if (!data.email || !data.password)
|
|
80
|
+
return {
|
|
81
|
+
error: handleError(400, "Missing email or password", options.onError)
|
|
82
|
+
};
|
|
83
|
+
if (options.turnstileKey) {
|
|
84
|
+
if (!data.captchaToken)
|
|
85
|
+
return { error: handleError(400, "Missing captcha", options.onError) };
|
|
86
|
+
if (!await verifyCaptcha(data.captchaToken, options.turnstileKey))
|
|
87
|
+
return {
|
|
88
|
+
error: handleError(400, "Invalid captcha", options.onError)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
data: {
|
|
93
|
+
email: data.email,
|
|
94
|
+
password: data.password,
|
|
95
|
+
...data
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
async function verifyCaptcha(token, secret) {
|
|
100
|
+
const res = await fetch(
|
|
101
|
+
"https://challenges.cloudflare.com/turnstile/v0/siteverify",
|
|
102
|
+
{
|
|
103
|
+
method: "POST",
|
|
104
|
+
headers: {
|
|
105
|
+
"Content-Type": "application/json"
|
|
106
|
+
},
|
|
107
|
+
body: JSON.stringify({
|
|
108
|
+
secret,
|
|
109
|
+
response: token
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
if (res.ok) {
|
|
114
|
+
const data = await res.json();
|
|
115
|
+
return data.success;
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/auth/email/routes/post.ts
|
|
121
|
+
var getPostRoute = (options) => async (req) => {
|
|
122
|
+
const { data, error } = await massageRequest(req, options);
|
|
123
|
+
if (error || !data) return error;
|
|
124
|
+
const existingUser = await options.getUser(data.email);
|
|
125
|
+
if (existingUser) {
|
|
126
|
+
if (await verifyUser(existingUser, data.password)) {
|
|
127
|
+
return getTokenizedResponse(
|
|
128
|
+
generateAccessToken(existingUser.id, options.signingKey),
|
|
129
|
+
generateRefreshToken(existingUser.id, options.refreshKey)
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
return handleError(400, "A user already exists", options.onError);
|
|
133
|
+
}
|
|
134
|
+
const encryptedPassword = await hash(data.password, 10);
|
|
135
|
+
const newUser = await options.createUser({
|
|
136
|
+
...data,
|
|
137
|
+
password: encryptedPassword
|
|
138
|
+
});
|
|
139
|
+
if (newUser) {
|
|
140
|
+
options.onSignUp?.(newUser);
|
|
141
|
+
return getTokenizedResponse(
|
|
142
|
+
generateAccessToken(newUser.id, options.signingKey),
|
|
143
|
+
generateRefreshToken(newUser.id, options.refreshKey)
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
return getTokenizedResponse();
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// src/auth/email/routes/put.ts
|
|
150
|
+
var getPutRoute = (options) => async (req) => {
|
|
151
|
+
const { data, error } = await massageRequest(req, options);
|
|
152
|
+
if (error || !data) return error;
|
|
153
|
+
const user = await options.getUser(data.email);
|
|
154
|
+
if (!user)
|
|
155
|
+
return handleError(400, "A user does not exist", options.onError);
|
|
156
|
+
if (await verifyUser(user, data.password)) {
|
|
157
|
+
return getTokenizedResponse(
|
|
158
|
+
generateAccessToken(user.id, options.signingKey),
|
|
159
|
+
generateRefreshToken(user.id, options.refreshKey)
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
return handleError(403, "Invalid password", options.onError);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// src/auth/email/index.ts
|
|
166
|
+
function getEmailAuthRoutes(options) {
|
|
167
|
+
return {
|
|
168
|
+
GET: getGetRoute(options),
|
|
169
|
+
POST: getPostRoute(options),
|
|
170
|
+
PUT: getPutRoute(options),
|
|
171
|
+
DELETE: getDeleteRoute()
|
|
172
|
+
};
|
|
173
|
+
}
|
|
11
174
|
export {
|
|
12
175
|
getEmailAuthRoutes
|
|
13
176
|
};
|
|
14
|
-
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
4
19
|
|
|
5
|
-
|
|
6
|
-
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
hello: () => hello
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var hello = "world";
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
hello
|
|
30
|
+
});
|
package/dist/index.esm.js
CHANGED
|
@@ -1,33 +1,173 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/socials/index.ts
|
|
21
|
+
var socials_exports = {};
|
|
22
|
+
__export(socials_exports, {
|
|
23
|
+
createThread: () => createThread,
|
|
24
|
+
createThreadsPost: () => createThreadsPost,
|
|
25
|
+
getInstagramConversation: () => getInstagramConversation,
|
|
26
|
+
getInstagramConversationByUser: () => getInstagramConversationByUser,
|
|
27
|
+
getInstagramConversations: () => getInstagramConversations,
|
|
28
|
+
getInstagramMedia: () => getInstagramMedia,
|
|
29
|
+
getInstagramMessage: () => getInstagramMessage,
|
|
30
|
+
getInstagramUser: () => getInstagramUser,
|
|
31
|
+
getThread: () => getThread,
|
|
32
|
+
getThreads: () => getThreads,
|
|
33
|
+
getThreadsReplies: () => getThreadsReplies
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(socials_exports);
|
|
36
|
+
|
|
37
|
+
// src/socials/instagram/utils.ts
|
|
38
|
+
function getInstagramURL(token, path, params) {
|
|
39
|
+
return `https://graph.instagram.com/v23.0/${path}?${Object.keys(params).map((key) => `${key}=${params[key]}`).join("&")}&access_token=${token}`;
|
|
40
|
+
}
|
|
41
|
+
function getInstagramData(token, path, params, method) {
|
|
42
|
+
return fetch(getInstagramURL(token, path, params), {
|
|
43
|
+
method: method || "GET"
|
|
44
|
+
}).then((res) => res.json());
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/socials/instagram/getters.ts
|
|
48
|
+
var getInstagramUser = (token, fields) => {
|
|
49
|
+
return getInstagramData(token, "me", {
|
|
50
|
+
fields: fields ? fields.join(",") : "username,followers_count,media_count"
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
var getInstagramMedia = (token, fields, limit) => {
|
|
54
|
+
return getInstagramData(token, "me/media", {
|
|
55
|
+
fields: fields ? fields.join(",") : "like_count,comments_count,permalink",
|
|
56
|
+
limit: limit?.toString() || "12"
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
var getInstagramConversations = async (token, cursor) => {
|
|
60
|
+
const result = await getInstagramData(token, "me/conversations", {
|
|
61
|
+
platform: "instagram",
|
|
62
|
+
...cursor ? { after: cursor } : {}
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
data: result?.data,
|
|
66
|
+
fetchMore: result?.paging?.cursors?.after ? () => getInstagramConversations(token, result.paging.cursors?.after) : void 0
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
var getInstagramConversationByUser = (token, userID) => {
|
|
70
|
+
return getInstagramData(
|
|
71
|
+
token,
|
|
72
|
+
"me/conversations",
|
|
73
|
+
{
|
|
74
|
+
user_id: userID
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
var getInstagramConversation = async (token, id, cursor) => {
|
|
79
|
+
const result = await getInstagramData(token, id + "/messages", {
|
|
80
|
+
...cursor ? { after: cursor } : {}
|
|
81
|
+
});
|
|
82
|
+
return {
|
|
83
|
+
data: result?.data,
|
|
84
|
+
fetchMore: result?.paging?.cursors?.after ? () => getInstagramConversation(token, id, result?.paging.cursors?.after) : void 0
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
var getInstagramMessage = (token, id, fields) => {
|
|
88
|
+
return getInstagramData(token, id, {
|
|
89
|
+
fields: fields ? fields.join(",") : "id,created_time,from,to,message"
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// src/socials/threads/utils.ts
|
|
94
|
+
function getThreadsURL(token, path, params) {
|
|
95
|
+
return `https://graph.threads.net/v1.0/${path}?${Object.keys(params).map((key) => `${key}=${params[key]}`).join("&")}&access_token=${token}`;
|
|
96
|
+
}
|
|
97
|
+
function getThreadsData(token, path, params, method) {
|
|
98
|
+
return fetch(getThreadsURL(token, path, params), {
|
|
99
|
+
method: method || "GET"
|
|
100
|
+
}).then((res) => res.json());
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/socials/threads/getters.ts
|
|
104
|
+
var getThread = (token, id, fields) => {
|
|
105
|
+
return getThreadsData(token, id, {
|
|
106
|
+
fields: fields ? fields.join(",") : "text,permalink,username"
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
var getThreads = (token, fields) => {
|
|
110
|
+
return getThreadsData(token, "me/threads", {
|
|
111
|
+
fields: fields ? fields.join(",") : "text,permalink,username"
|
|
112
|
+
}).then((res) => res?.data);
|
|
113
|
+
};
|
|
114
|
+
var getThreadsReplies = (token, id, fields) => {
|
|
115
|
+
return getThreadsData(token, `${id}/replies`, {
|
|
116
|
+
fields: fields ? fields.join(",") : "text,username,permalink"
|
|
117
|
+
}).then((res) => res?.data);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// src/socials/threads/setters.ts
|
|
121
|
+
function createContainer(token, text, reply_to_id) {
|
|
122
|
+
return getThreadsData(
|
|
123
|
+
token,
|
|
124
|
+
"me/threads",
|
|
125
|
+
{
|
|
126
|
+
media_type: "TEXT",
|
|
127
|
+
text,
|
|
128
|
+
...reply_to_id ? { reply_to_id } : {}
|
|
129
|
+
},
|
|
130
|
+
"POST"
|
|
131
|
+
).then((res) => res?.id).catch(console.error);
|
|
132
|
+
}
|
|
133
|
+
function publishContainer(token, creation_id) {
|
|
134
|
+
return getThreadsData(
|
|
135
|
+
token,
|
|
136
|
+
"me/threads_publish",
|
|
137
|
+
{
|
|
138
|
+
creation_id
|
|
139
|
+
},
|
|
140
|
+
"POST"
|
|
141
|
+
).then((res) => res?.id).catch(console.error);
|
|
142
|
+
}
|
|
143
|
+
var createThreadsPost = async (token, text, reply_to_id) => {
|
|
144
|
+
const containerID = await createContainer(token, text, reply_to_id);
|
|
145
|
+
if (!containerID) return null;
|
|
146
|
+
return publishContainer(token, containerID);
|
|
147
|
+
};
|
|
148
|
+
var createThread = async (token, threads) => {
|
|
149
|
+
const publishedIDs = [];
|
|
150
|
+
for (const thread of threads) {
|
|
151
|
+
const postID = await createThreadsPost(
|
|
152
|
+
token,
|
|
153
|
+
thread.split("\n").join("%0A"),
|
|
154
|
+
publishedIDs.at(-1)
|
|
155
|
+
);
|
|
156
|
+
if (postID) publishedIDs.push(postID);
|
|
157
|
+
}
|
|
158
|
+
return publishedIDs[0];
|
|
159
|
+
};
|
|
160
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
161
|
+
0 && (module.exports = {
|
|
162
|
+
createThread,
|
|
163
|
+
createThreadsPost,
|
|
164
|
+
getInstagramConversation,
|
|
165
|
+
getInstagramConversationByUser,
|
|
166
|
+
getInstagramConversations,
|
|
167
|
+
getInstagramMedia,
|
|
168
|
+
getInstagramMessage,
|
|
169
|
+
getInstagramUser,
|
|
170
|
+
getThread,
|
|
171
|
+
getThreads,
|
|
172
|
+
getThreadsReplies
|
|
173
|
+
});
|
package/dist/socials/index.d.mts
CHANGED
|
@@ -1,3 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
type InstagramMessage = {
|
|
2
|
+
id: string;
|
|
3
|
+
created_time: string;
|
|
4
|
+
from: {
|
|
5
|
+
id: string;
|
|
6
|
+
username: string;
|
|
7
|
+
};
|
|
8
|
+
to: {
|
|
9
|
+
data: {
|
|
10
|
+
username: string;
|
|
11
|
+
id: string;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
message: string;
|
|
15
|
+
};
|
|
16
|
+
type InstagramUser = {
|
|
17
|
+
username: string;
|
|
18
|
+
followers_count: number;
|
|
19
|
+
media_count: number;
|
|
20
|
+
};
|
|
21
|
+
type InstagramMedia = {
|
|
22
|
+
like_count?: number;
|
|
23
|
+
comments_count: number;
|
|
24
|
+
permalink: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
declare const getInstagramUser: <T = InstagramUser>(token: string, fields?: string[]) => Promise<(T & {
|
|
28
|
+
error?: object;
|
|
29
|
+
}) | null>;
|
|
30
|
+
declare const getInstagramMedia: <T = InstagramMedia>(token: string, fields?: string[], limit?: number) => Promise<{
|
|
31
|
+
data: T[];
|
|
32
|
+
error?: object;
|
|
33
|
+
} | null>;
|
|
34
|
+
declare const getInstagramConversations: (token: string, cursor?: string) => Promise<{
|
|
35
|
+
data: {
|
|
36
|
+
id: string;
|
|
37
|
+
updated_time: string;
|
|
38
|
+
}[] | undefined;
|
|
39
|
+
fetchMore: (() => Promise</*elided*/ any>) | undefined;
|
|
40
|
+
}>;
|
|
41
|
+
declare const getInstagramConversationByUser: (token: string, userID: string) => Promise<{
|
|
42
|
+
data: {
|
|
43
|
+
id: string;
|
|
44
|
+
}[];
|
|
45
|
+
} | null>;
|
|
46
|
+
declare const getInstagramConversation: (token: string, id: string, cursor?: string) => Promise<{
|
|
47
|
+
data: {
|
|
48
|
+
id: string;
|
|
49
|
+
updated_time: string;
|
|
50
|
+
}[] | undefined;
|
|
51
|
+
fetchMore: (() => Promise</*elided*/ any>) | undefined;
|
|
52
|
+
}>;
|
|
53
|
+
declare const getInstagramMessage: <T = InstagramMessage>(token: string, id: string, fields?: string[]) => Promise<T | null>;
|
|
54
|
+
|
|
55
|
+
type ThreadsPost = {
|
|
56
|
+
text: string;
|
|
57
|
+
permalink: string;
|
|
58
|
+
username: string;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
declare const getThread: <T = ThreadsPost>(token: string, id: string, fields?: string[]) => Promise<T | null>;
|
|
62
|
+
declare const getThreads: <T = ThreadsPost>(token: string, fields?: string[]) => Promise<T[] | undefined>;
|
|
63
|
+
declare const getThreadsReplies: <T = ThreadsPost>(token: string, id: string, fields?: string[]) => Promise<T[] | undefined>;
|
|
64
|
+
|
|
65
|
+
declare const createThreadsPost: (token: string, text: string, reply_to_id?: string) => Promise<string | void | null>;
|
|
66
|
+
declare const createThread: (token: string, threads: string[]) => Promise<string | undefined>;
|
|
67
|
+
|
|
68
|
+
export { createThread, createThreadsPost, getInstagramConversation, getInstagramConversationByUser, getInstagramConversations, getInstagramMedia, getInstagramMessage, getInstagramUser, getThread, getThreads, getThreadsReplies };
|
package/dist/socials/index.d.ts
CHANGED
|
@@ -1,3 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
type InstagramMessage = {
|
|
2
|
+
id: string;
|
|
3
|
+
created_time: string;
|
|
4
|
+
from: {
|
|
5
|
+
id: string;
|
|
6
|
+
username: string;
|
|
7
|
+
};
|
|
8
|
+
to: {
|
|
9
|
+
data: {
|
|
10
|
+
username: string;
|
|
11
|
+
id: string;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
message: string;
|
|
15
|
+
};
|
|
16
|
+
type InstagramUser = {
|
|
17
|
+
username: string;
|
|
18
|
+
followers_count: number;
|
|
19
|
+
media_count: number;
|
|
20
|
+
};
|
|
21
|
+
type InstagramMedia = {
|
|
22
|
+
like_count?: number;
|
|
23
|
+
comments_count: number;
|
|
24
|
+
permalink: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
declare const getInstagramUser: <T = InstagramUser>(token: string, fields?: string[]) => Promise<(T & {
|
|
28
|
+
error?: object;
|
|
29
|
+
}) | null>;
|
|
30
|
+
declare const getInstagramMedia: <T = InstagramMedia>(token: string, fields?: string[], limit?: number) => Promise<{
|
|
31
|
+
data: T[];
|
|
32
|
+
error?: object;
|
|
33
|
+
} | null>;
|
|
34
|
+
declare const getInstagramConversations: (token: string, cursor?: string) => Promise<{
|
|
35
|
+
data: {
|
|
36
|
+
id: string;
|
|
37
|
+
updated_time: string;
|
|
38
|
+
}[] | undefined;
|
|
39
|
+
fetchMore: (() => Promise</*elided*/ any>) | undefined;
|
|
40
|
+
}>;
|
|
41
|
+
declare const getInstagramConversationByUser: (token: string, userID: string) => Promise<{
|
|
42
|
+
data: {
|
|
43
|
+
id: string;
|
|
44
|
+
}[];
|
|
45
|
+
} | null>;
|
|
46
|
+
declare const getInstagramConversation: (token: string, id: string, cursor?: string) => Promise<{
|
|
47
|
+
data: {
|
|
48
|
+
id: string;
|
|
49
|
+
updated_time: string;
|
|
50
|
+
}[] | undefined;
|
|
51
|
+
fetchMore: (() => Promise</*elided*/ any>) | undefined;
|
|
52
|
+
}>;
|
|
53
|
+
declare const getInstagramMessage: <T = InstagramMessage>(token: string, id: string, fields?: string[]) => Promise<T | null>;
|
|
54
|
+
|
|
55
|
+
type ThreadsPost = {
|
|
56
|
+
text: string;
|
|
57
|
+
permalink: string;
|
|
58
|
+
username: string;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
declare const getThread: <T = ThreadsPost>(token: string, id: string, fields?: string[]) => Promise<T | null>;
|
|
62
|
+
declare const getThreads: <T = ThreadsPost>(token: string, fields?: string[]) => Promise<T[] | undefined>;
|
|
63
|
+
declare const getThreadsReplies: <T = ThreadsPost>(token: string, id: string, fields?: string[]) => Promise<T[] | undefined>;
|
|
64
|
+
|
|
65
|
+
declare const createThreadsPost: (token: string, text: string, reply_to_id?: string) => Promise<string | void | null>;
|
|
66
|
+
declare const createThread: (token: string, threads: string[]) => Promise<string | undefined>;
|
|
67
|
+
|
|
68
|
+
export { createThread, createThreadsPost, getInstagramConversation, getInstagramConversationByUser, getInstagramConversations, getInstagramMedia, getInstagramMessage, getInstagramUser, getThread, getThreads, getThreadsReplies };
|