naystack 1.1.7 → 1.1.9

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.
@@ -25,6 +25,7 @@ __export(socials_exports, {
25
25
  getInstagramConversation: () => getInstagramConversation,
26
26
  getInstagramConversationByUser: () => getInstagramConversationByUser,
27
27
  getInstagramConversations: () => getInstagramConversations,
28
+ getInstagramConversationsByUser: () => getInstagramConversationsByUser,
28
29
  getInstagramMedia: () => getInstagramMedia,
29
30
  getInstagramMessage: () => getInstagramMessage,
30
31
  getInstagramUser: () => getInstagramUser,
@@ -79,7 +80,7 @@ var getInstagramConversations = async (token, limit = 25, cursor) => {
79
80
  fetchMore: result?.paging?.cursors?.after ? () => getInstagramConversations(token, limit, result.paging.cursors?.after) : void 0
80
81
  };
81
82
  };
82
- var getInstagramConversationByUser = (token, userID) => {
83
+ var getInstagramConversationsByUser = (token, userID) => {
83
84
  return getInstagramData(
84
85
  token,
85
86
  "me/conversations",
@@ -89,6 +90,10 @@ var getInstagramConversationByUser = (token, userID) => {
89
90
  }
90
91
  );
91
92
  };
93
+ var getInstagramConversationByUser = async (token, userID) => {
94
+ const res = await getInstagramConversationsByUser(token, userID);
95
+ return res?.data.find((item) => item.participants?.data.length === 2);
96
+ };
92
97
  var getInstagramConversation = async (token, id, cursor) => {
93
98
  const result = await getInstagramData(token, id + "", {
94
99
  fields: "participants,messages,updated_time",
@@ -136,8 +141,11 @@ var setupInstagramWebhook = (options) => {
136
141
  POST: async (req) => {
137
142
  const payload = await req.json();
138
143
  for (const entry of payload.entry) {
139
- for (const change of entry.changes) {
140
- await options.callback(change.field, change.value);
144
+ for (const type of Object.keys(entry)) {
145
+ if (!(entry[type] instanceof Array)) continue;
146
+ for (const change of entry[type]) {
147
+ await options.callback(type, change, entry.id);
148
+ }
141
149
  }
142
150
  }
143
151
  return new Response("OK");
@@ -219,6 +227,7 @@ var createThread = async (token, threads) => {
219
227
  getInstagramConversation,
220
228
  getInstagramConversationByUser,
221
229
  getInstagramConversations,
230
+ getInstagramConversationsByUser,
222
231
  getInstagramMedia,
223
232
  getInstagramMessage,
224
233
  getInstagramUser,
@@ -76,9 +76,10 @@ declare const getInstagramConversations: (token: string, limit?: number, cursor?
76
76
  }[] | undefined;
77
77
  fetchMore: (() => Promise</*elided*/ any>) | undefined;
78
78
  }>;
79
- declare const getInstagramConversationByUser: (token: string, userID: string) => Promise<({
79
+ declare const getInstagramConversationsByUser: (token: string, userID: string) => Promise<({
80
80
  data: InstagramConversation[];
81
81
  } & InstagramError) | null>;
82
+ declare const getInstagramConversationByUser: (token: string, userID: string) => Promise<InstagramConversation | undefined>;
82
83
  declare const getInstagramConversation: (token: string, id: string, cursor?: string) => Promise<{
83
84
  messages: {
84
85
  id: string;
@@ -99,7 +100,7 @@ declare const sendInstagramMessage: (token: string, to: string, text: string) =>
99
100
 
100
101
  declare const setupInstagramWebhook: (options: {
101
102
  secret: string;
102
- callback: (type: string, value: any) => Promise<void>;
103
+ callback: (type: string, value: any, id: string) => Promise<void>;
103
104
  }) => {
104
105
  GET: (req: NextRequest) => next_server.NextResponse<unknown> | undefined;
105
106
  POST: (req: NextRequest) => Promise<Response>;
@@ -118,4 +119,4 @@ declare const getThreadsReplies: <T = ThreadsPost>(token: string, id: string, fi
118
119
  declare const createThreadsPost: (token: string, text: string, reply_to_id?: string) => Promise<string | void | null>;
119
120
  declare const createThread: (token: string, threads: string[]) => Promise<string | undefined>;
120
121
 
121
- export { createThread, createThreadsPost, getInstagramConversation, getInstagramConversationByUser, getInstagramConversations, getInstagramMedia, getInstagramMessage, getInstagramUser, getThread, getThreads, getThreadsReplies, sendInstagramMessage, setupInstagramWebhook };
122
+ export { createThread, createThreadsPost, getInstagramConversation, getInstagramConversationByUser, getInstagramConversations, getInstagramConversationsByUser, getInstagramMedia, getInstagramMessage, getInstagramUser, getThread, getThreads, getThreadsReplies, sendInstagramMessage, setupInstagramWebhook };
@@ -76,9 +76,10 @@ declare const getInstagramConversations: (token: string, limit?: number, cursor?
76
76
  }[] | undefined;
77
77
  fetchMore: (() => Promise</*elided*/ any>) | undefined;
78
78
  }>;
79
- declare const getInstagramConversationByUser: (token: string, userID: string) => Promise<({
79
+ declare const getInstagramConversationsByUser: (token: string, userID: string) => Promise<({
80
80
  data: InstagramConversation[];
81
81
  } & InstagramError) | null>;
82
+ declare const getInstagramConversationByUser: (token: string, userID: string) => Promise<InstagramConversation | undefined>;
82
83
  declare const getInstagramConversation: (token: string, id: string, cursor?: string) => Promise<{
83
84
  messages: {
84
85
  id: string;
@@ -99,7 +100,7 @@ declare const sendInstagramMessage: (token: string, to: string, text: string) =>
99
100
 
100
101
  declare const setupInstagramWebhook: (options: {
101
102
  secret: string;
102
- callback: (type: string, value: any) => Promise<void>;
103
+ callback: (type: string, value: any, id: string) => Promise<void>;
103
104
  }) => {
104
105
  GET: (req: NextRequest) => next_server.NextResponse<unknown> | undefined;
105
106
  POST: (req: NextRequest) => Promise<Response>;
@@ -118,4 +119,4 @@ declare const getThreadsReplies: <T = ThreadsPost>(token: string, id: string, fi
118
119
  declare const createThreadsPost: (token: string, text: string, reply_to_id?: string) => Promise<string | void | null>;
119
120
  declare const createThread: (token: string, threads: string[]) => Promise<string | undefined>;
120
121
 
121
- export { createThread, createThreadsPost, getInstagramConversation, getInstagramConversationByUser, getInstagramConversations, getInstagramMedia, getInstagramMessage, getInstagramUser, getThread, getThreads, getThreadsReplies, sendInstagramMessage, setupInstagramWebhook };
122
+ export { createThread, createThreadsPost, getInstagramConversation, getInstagramConversationByUser, getInstagramConversations, getInstagramConversationsByUser, getInstagramMedia, getInstagramMessage, getInstagramUser, getThread, getThreads, getThreadsReplies, sendInstagramMessage, setupInstagramWebhook };
@@ -41,7 +41,7 @@ var getInstagramConversations = async (token, limit = 25, cursor) => {
41
41
  fetchMore: result?.paging?.cursors?.after ? () => getInstagramConversations(token, limit, result.paging.cursors?.after) : void 0
42
42
  };
43
43
  };
44
- var getInstagramConversationByUser = (token, userID) => {
44
+ var getInstagramConversationsByUser = (token, userID) => {
45
45
  return getInstagramData(
46
46
  token,
47
47
  "me/conversations",
@@ -51,6 +51,10 @@ var getInstagramConversationByUser = (token, userID) => {
51
51
  }
52
52
  );
53
53
  };
54
+ var getInstagramConversationByUser = async (token, userID) => {
55
+ const res = await getInstagramConversationsByUser(token, userID);
56
+ return res?.data.find((item) => item.participants?.data.length === 2);
57
+ };
54
58
  var getInstagramConversation = async (token, id, cursor) => {
55
59
  const result = await getInstagramData(token, id + "", {
56
60
  fields: "participants,messages,updated_time",
@@ -98,8 +102,11 @@ var setupInstagramWebhook = (options) => {
98
102
  POST: async (req) => {
99
103
  const payload = await req.json();
100
104
  for (const entry of payload.entry) {
101
- for (const change of entry.changes) {
102
- await options.callback(change.field, change.value);
105
+ for (const type of Object.keys(entry)) {
106
+ if (!(entry[type] instanceof Array)) continue;
107
+ for (const change of entry[type]) {
108
+ await options.callback(type, change, entry.id);
109
+ }
103
110
  }
104
111
  }
105
112
  return new Response("OK");
@@ -180,6 +187,7 @@ export {
180
187
  getInstagramConversation,
181
188
  getInstagramConversationByUser,
182
189
  getInstagramConversations,
190
+ getInstagramConversationsByUser,
183
191
  getInstagramMedia,
184
192
  getInstagramMessage,
185
193
  getInstagramUser,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "naystack",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "description": "A stack built with tight Next + Drizzle + GraphQL",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",