naystack 1.5.8 → 1.5.10

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.
Files changed (114) hide show
  1. package/README.md +646 -91
  2. package/dist/auth/constants.d.mts +4 -0
  3. package/dist/auth/constants.d.ts +4 -0
  4. package/dist/auth/email/client.d.mts +149 -0
  5. package/dist/auth/email/client.d.ts +149 -0
  6. package/dist/auth/email/index.cjs.js +2 -14
  7. package/dist/auth/email/index.d.mts +41 -1
  8. package/dist/auth/email/index.d.ts +41 -1
  9. package/dist/auth/email/index.esm.js +1 -12
  10. package/dist/auth/email/routes/delete.cjs.js +0 -1
  11. package/dist/auth/email/routes/delete.d.mts +5 -0
  12. package/dist/auth/email/routes/delete.d.ts +5 -0
  13. package/dist/auth/email/routes/delete.esm.js +0 -1
  14. package/dist/auth/email/routes/get.d.mts +5 -0
  15. package/dist/auth/email/routes/get.d.ts +5 -0
  16. package/dist/auth/email/routes/post.cjs.js +0 -1
  17. package/dist/auth/email/routes/post.d.mts +5 -0
  18. package/dist/auth/email/routes/post.d.ts +5 -0
  19. package/dist/auth/email/routes/post.esm.js +0 -1
  20. package/dist/auth/email/routes/put.cjs.js +0 -1
  21. package/dist/auth/email/routes/put.d.mts +5 -0
  22. package/dist/auth/email/routes/put.d.ts +5 -0
  23. package/dist/auth/email/routes/put.esm.js +0 -1
  24. package/dist/auth/email/token.d.mts +62 -0
  25. package/dist/auth/email/token.d.ts +62 -0
  26. package/dist/auth/email/types.d.mts +22 -0
  27. package/dist/auth/email/types.d.ts +22 -0
  28. package/dist/auth/email/utils.cjs.js +0 -12
  29. package/dist/auth/email/utils.d.mts +41 -2
  30. package/dist/auth/email/utils.d.ts +41 -2
  31. package/dist/auth/email/utils.esm.js +0 -11
  32. package/dist/auth/google/get.d.mts +5 -0
  33. package/dist/auth/google/get.d.ts +5 -0
  34. package/dist/auth/google/index.d.mts +39 -0
  35. package/dist/auth/google/index.d.ts +39 -0
  36. package/dist/auth/index.cjs.js +4 -16
  37. package/dist/auth/index.d.mts +1 -1
  38. package/dist/auth/index.d.ts +1 -1
  39. package/dist/auth/index.esm.js +3 -14
  40. package/dist/auth/instagram/client.d.mts +19 -0
  41. package/dist/auth/instagram/client.d.ts +19 -0
  42. package/dist/auth/instagram/index.d.mts +37 -0
  43. package/dist/auth/instagram/index.d.ts +37 -0
  44. package/dist/auth/instagram/route.d.mts +5 -0
  45. package/dist/auth/instagram/route.d.ts +5 -0
  46. package/dist/auth/instagram/utils.d.mts +13 -0
  47. package/dist/auth/instagram/utils.d.ts +13 -0
  48. package/dist/auth/types.d.mts +24 -0
  49. package/dist/auth/types.d.ts +24 -0
  50. package/dist/auth/utils/errors.d.mts +10 -0
  51. package/dist/auth/utils/errors.d.ts +10 -0
  52. package/dist/auth/utils/token.d.mts +20 -0
  53. package/dist/auth/utils/token.d.ts +20 -0
  54. package/dist/client/hooks.d.mts +59 -0
  55. package/dist/client/hooks.d.ts +59 -0
  56. package/dist/client/seo.d.mts +46 -0
  57. package/dist/client/seo.d.ts +46 -0
  58. package/dist/env.d.mts +61 -0
  59. package/dist/env.d.ts +61 -0
  60. package/dist/file/client.d.mts +53 -1
  61. package/dist/file/client.d.ts +53 -1
  62. package/dist/file/index.cjs.js +0 -1
  63. package/dist/file/index.esm.js +0 -1
  64. package/dist/file/put.cjs.js +0 -1
  65. package/dist/file/put.d.mts +11 -0
  66. package/dist/file/put.d.ts +11 -0
  67. package/dist/file/put.esm.js +0 -1
  68. package/dist/file/setup.cjs.js +0 -1
  69. package/dist/file/setup.d.mts +48 -0
  70. package/dist/file/setup.d.ts +48 -0
  71. package/dist/file/setup.esm.js +0 -1
  72. package/dist/file/utils.d.mts +41 -0
  73. package/dist/file/utils.d.ts +41 -0
  74. package/dist/graphql/client.d.mts +113 -0
  75. package/dist/graphql/client.d.ts +113 -0
  76. package/dist/graphql/errors.d.mts +26 -0
  77. package/dist/graphql/errors.d.ts +26 -0
  78. package/dist/graphql/index.cjs.js +2 -3
  79. package/dist/graphql/index.esm.js +2 -3
  80. package/dist/graphql/init.cjs.js +0 -1
  81. package/dist/graphql/init.d.mts +33 -0
  82. package/dist/graphql/init.d.ts +33 -0
  83. package/dist/graphql/init.esm.js +0 -1
  84. package/dist/graphql/server.d.mts +88 -0
  85. package/dist/graphql/server.d.ts +88 -0
  86. package/dist/graphql/types.d.mts +21 -0
  87. package/dist/graphql/types.d.ts +21 -0
  88. package/dist/graphql/utils.d.mts +217 -0
  89. package/dist/graphql/utils.d.ts +217 -0
  90. package/dist/index.d.mts +16 -0
  91. package/dist/index.d.ts +16 -0
  92. package/dist/socials/instagram/getters.d.mts +115 -0
  93. package/dist/socials/instagram/getters.d.ts +115 -0
  94. package/dist/socials/instagram/setters.d.mts +18 -0
  95. package/dist/socials/instagram/setters.d.ts +18 -0
  96. package/dist/socials/instagram/types.d.mts +46 -0
  97. package/dist/socials/instagram/types.d.ts +46 -0
  98. package/dist/socials/instagram/utils.d.mts +19 -0
  99. package/dist/socials/instagram/utils.d.ts +19 -0
  100. package/dist/socials/instagram/webhook.d.mts +31 -0
  101. package/dist/socials/instagram/webhook.d.ts +31 -0
  102. package/dist/socials/meta-webhook.d.mts +11 -0
  103. package/dist/socials/meta-webhook.d.ts +11 -0
  104. package/dist/socials/threads/getters.d.mts +57 -0
  105. package/dist/socials/threads/getters.d.ts +57 -0
  106. package/dist/socials/threads/setters.d.mts +59 -0
  107. package/dist/socials/threads/setters.d.ts +59 -0
  108. package/dist/socials/threads/types.d.mts +9 -0
  109. package/dist/socials/threads/types.d.ts +9 -0
  110. package/dist/socials/threads/utils.d.mts +19 -0
  111. package/dist/socials/threads/utils.d.ts +19 -0
  112. package/dist/socials/threads/webhook.d.mts +30 -0
  113. package/dist/socials/threads/webhook.d.ts +30 -0
  114. package/package.json +4 -2
@@ -1,9 +1,71 @@
1
1
  import { InstagramConversation, InstagramError, InstagramMedia, InstagramMessage, InstagramUser } from './types.mjs';
2
2
 
3
+ /**
4
+ * Fetches an Instagram user's profile. Defaults to the authenticated user (`"me"`).
5
+ *
6
+ * @param token - Instagram access token.
7
+ * @param id - User id to fetch. Defaults to `"me"` (the token owner).
8
+ * @param fields - Optional array of field names to request. Default: `["username", "followers_count", "media_count"]`.
9
+ * @returns Promise of user data (typed as `T`, defaults to {@link InstagramUser}).
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { getInstagramUser } from "naystack/socials";
14
+ *
15
+ * const user = await getInstagramUser(accessToken);
16
+ * console.log(user?.username, user?.followers_count);
17
+ * ```
18
+ *
19
+ * @category Socials
20
+ */
3
21
  declare const getInstagramUser: <T = InstagramUser>(token: string, id?: string, fields?: string[]) => Promise<(T & InstagramError) | null>;
22
+ /**
23
+ * Fetches the authenticated user's recent Instagram media.
24
+ *
25
+ * @param token - Instagram access token.
26
+ * @param fields - Optional array of field names. Default: `["like_count", "comments_count", "permalink"]`.
27
+ * @param limit - Maximum number of items to return. Default: `12`.
28
+ * @returns Promise of `{ data: T[] }` where T defaults to {@link InstagramMedia}.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { getInstagramMedia } from "naystack/socials";
33
+ *
34
+ * const media = await getInstagramMedia(accessToken, undefined, 10);
35
+ * for (const item of media?.data ?? []) {
36
+ * console.log(item.permalink, item.like_count);
37
+ * }
38
+ * ```
39
+ *
40
+ * @category Socials
41
+ */
4
42
  declare const getInstagramMedia: <T = InstagramMedia>(token: string, fields?: string[], limit?: number) => Promise<({
5
43
  data: T[];
6
44
  } & InstagramError) | null>;
45
+ /**
46
+ * Fetches Instagram conversations (DM threads) with pagination support.
47
+ *
48
+ * @param token - Instagram access token.
49
+ * @param limit - Page size. Default: `25`.
50
+ * @param cursor - Optional pagination cursor (from a previous `fetchMore`).
51
+ * @returns Promise of `{ data: InstagramConversation[], fetchMore?: () => Promise<...> }`.
52
+ * Call `fetchMore()` to load the next page.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * import { getInstagramConversations } from "naystack/socials";
57
+ *
58
+ * const convos = await getInstagramConversations(accessToken, 25);
59
+ * for (const convo of convos.data ?? []) {
60
+ * console.log(convo.participants, convo.messages);
61
+ * }
62
+ * if (convos.fetchMore) {
63
+ * const nextPage = await convos.fetchMore();
64
+ * }
65
+ * ```
66
+ *
67
+ * @category Socials
68
+ */
7
69
  declare const getInstagramConversations: (token: string, limit?: number, cursor?: string) => Promise<{
8
70
  data: {
9
71
  messages: {
@@ -19,10 +81,53 @@ declare const getInstagramConversations: (token: string, limit?: number, cursor?
19
81
  }[] | undefined;
20
82
  fetchMore: (() => Promise</*elided*/ any>) | undefined;
21
83
  }>;
84
+ /**
85
+ * Fetches conversations filtered by a specific Instagram user id.
86
+ *
87
+ * @param token - Instagram access token.
88
+ * @param userID - The Instagram user id to filter conversations by.
89
+ * @returns Promise of `{ data: InstagramConversation[] }`.
90
+ *
91
+ * @category Socials
92
+ */
22
93
  declare const getInstagramConversationsByUser: (token: string, userID: string) => Promise<({
23
94
  data: InstagramConversation[];
24
95
  } & InstagramError) | null>;
96
+ /**
97
+ * Fetches the single conversation between the authenticated user and the given user.
98
+ * Filters for conversations with exactly 2 participants.
99
+ *
100
+ * @param token - Instagram access token.
101
+ * @param userID - The other participant's Instagram user id.
102
+ * @returns Promise of a single `InstagramConversation` or `undefined` if not found.
103
+ *
104
+ * @category Socials
105
+ */
25
106
  declare const getInstagramConversationByUser: (token: string, userID: string) => Promise<InstagramConversation | undefined>;
107
+ /**
108
+ * Fetches a single Instagram conversation by id with messages and participants.
109
+ * Supports pagination for messages via `fetchMore`.
110
+ *
111
+ * @param token - Instagram access token.
112
+ * @param id - Conversation id.
113
+ * @param cursor - Optional pagination cursor for messages.
114
+ * @returns Promise of `{ messages, participants, fetchMore? }`.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * import { getInstagramConversation } from "naystack/socials";
119
+ *
120
+ * const convo = await getInstagramConversation(accessToken, conversationId);
121
+ * for (const msg of convo.messages ?? []) {
122
+ * console.log(msg.id, msg.created_time);
123
+ * }
124
+ * if (convo.fetchMore) {
125
+ * const older = await convo.fetchMore();
126
+ * }
127
+ * ```
128
+ *
129
+ * @category Socials
130
+ */
26
131
  declare const getInstagramConversation: (token: string, id: string, cursor?: string) => Promise<{
27
132
  messages: {
28
133
  id: string;
@@ -34,6 +139,16 @@ declare const getInstagramConversation: (token: string, id: string, cursor?: str
34
139
  }[] | undefined;
35
140
  fetchMore: (() => Promise</*elided*/ any>) | undefined;
36
141
  }>;
142
+ /**
143
+ * Fetches a single Instagram message by id.
144
+ *
145
+ * @param token - Instagram access token.
146
+ * @param id - Message id.
147
+ * @param fields - Optional array of field names. Default: `["id", "created_time", "from", "to", "message"]`.
148
+ * @returns Promise of message data (typed as `T`, defaults to {@link InstagramMessage}).
149
+ *
150
+ * @category Socials
151
+ */
37
152
  declare const getInstagramMessage: <T = InstagramMessage>(token: string, id: string, fields?: string[]) => Promise<(T & InstagramError) | null>;
38
153
 
39
154
  export { getInstagramConversation, getInstagramConversationByUser, getInstagramConversations, getInstagramConversationsByUser, getInstagramMedia, getInstagramMessage, getInstagramUser };
@@ -1,9 +1,71 @@
1
1
  import { InstagramConversation, InstagramError, InstagramMedia, InstagramMessage, InstagramUser } from './types.js';
2
2
 
3
+ /**
4
+ * Fetches an Instagram user's profile. Defaults to the authenticated user (`"me"`).
5
+ *
6
+ * @param token - Instagram access token.
7
+ * @param id - User id to fetch. Defaults to `"me"` (the token owner).
8
+ * @param fields - Optional array of field names to request. Default: `["username", "followers_count", "media_count"]`.
9
+ * @returns Promise of user data (typed as `T`, defaults to {@link InstagramUser}).
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { getInstagramUser } from "naystack/socials";
14
+ *
15
+ * const user = await getInstagramUser(accessToken);
16
+ * console.log(user?.username, user?.followers_count);
17
+ * ```
18
+ *
19
+ * @category Socials
20
+ */
3
21
  declare const getInstagramUser: <T = InstagramUser>(token: string, id?: string, fields?: string[]) => Promise<(T & InstagramError) | null>;
22
+ /**
23
+ * Fetches the authenticated user's recent Instagram media.
24
+ *
25
+ * @param token - Instagram access token.
26
+ * @param fields - Optional array of field names. Default: `["like_count", "comments_count", "permalink"]`.
27
+ * @param limit - Maximum number of items to return. Default: `12`.
28
+ * @returns Promise of `{ data: T[] }` where T defaults to {@link InstagramMedia}.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { getInstagramMedia } from "naystack/socials";
33
+ *
34
+ * const media = await getInstagramMedia(accessToken, undefined, 10);
35
+ * for (const item of media?.data ?? []) {
36
+ * console.log(item.permalink, item.like_count);
37
+ * }
38
+ * ```
39
+ *
40
+ * @category Socials
41
+ */
4
42
  declare const getInstagramMedia: <T = InstagramMedia>(token: string, fields?: string[], limit?: number) => Promise<({
5
43
  data: T[];
6
44
  } & InstagramError) | null>;
45
+ /**
46
+ * Fetches Instagram conversations (DM threads) with pagination support.
47
+ *
48
+ * @param token - Instagram access token.
49
+ * @param limit - Page size. Default: `25`.
50
+ * @param cursor - Optional pagination cursor (from a previous `fetchMore`).
51
+ * @returns Promise of `{ data: InstagramConversation[], fetchMore?: () => Promise<...> }`.
52
+ * Call `fetchMore()` to load the next page.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * import { getInstagramConversations } from "naystack/socials";
57
+ *
58
+ * const convos = await getInstagramConversations(accessToken, 25);
59
+ * for (const convo of convos.data ?? []) {
60
+ * console.log(convo.participants, convo.messages);
61
+ * }
62
+ * if (convos.fetchMore) {
63
+ * const nextPage = await convos.fetchMore();
64
+ * }
65
+ * ```
66
+ *
67
+ * @category Socials
68
+ */
7
69
  declare const getInstagramConversations: (token: string, limit?: number, cursor?: string) => Promise<{
8
70
  data: {
9
71
  messages: {
@@ -19,10 +81,53 @@ declare const getInstagramConversations: (token: string, limit?: number, cursor?
19
81
  }[] | undefined;
20
82
  fetchMore: (() => Promise</*elided*/ any>) | undefined;
21
83
  }>;
84
+ /**
85
+ * Fetches conversations filtered by a specific Instagram user id.
86
+ *
87
+ * @param token - Instagram access token.
88
+ * @param userID - The Instagram user id to filter conversations by.
89
+ * @returns Promise of `{ data: InstagramConversation[] }`.
90
+ *
91
+ * @category Socials
92
+ */
22
93
  declare const getInstagramConversationsByUser: (token: string, userID: string) => Promise<({
23
94
  data: InstagramConversation[];
24
95
  } & InstagramError) | null>;
96
+ /**
97
+ * Fetches the single conversation between the authenticated user and the given user.
98
+ * Filters for conversations with exactly 2 participants.
99
+ *
100
+ * @param token - Instagram access token.
101
+ * @param userID - The other participant's Instagram user id.
102
+ * @returns Promise of a single `InstagramConversation` or `undefined` if not found.
103
+ *
104
+ * @category Socials
105
+ */
25
106
  declare const getInstagramConversationByUser: (token: string, userID: string) => Promise<InstagramConversation | undefined>;
107
+ /**
108
+ * Fetches a single Instagram conversation by id with messages and participants.
109
+ * Supports pagination for messages via `fetchMore`.
110
+ *
111
+ * @param token - Instagram access token.
112
+ * @param id - Conversation id.
113
+ * @param cursor - Optional pagination cursor for messages.
114
+ * @returns Promise of `{ messages, participants, fetchMore? }`.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * import { getInstagramConversation } from "naystack/socials";
119
+ *
120
+ * const convo = await getInstagramConversation(accessToken, conversationId);
121
+ * for (const msg of convo.messages ?? []) {
122
+ * console.log(msg.id, msg.created_time);
123
+ * }
124
+ * if (convo.fetchMore) {
125
+ * const older = await convo.fetchMore();
126
+ * }
127
+ * ```
128
+ *
129
+ * @category Socials
130
+ */
26
131
  declare const getInstagramConversation: (token: string, id: string, cursor?: string) => Promise<{
27
132
  messages: {
28
133
  id: string;
@@ -34,6 +139,16 @@ declare const getInstagramConversation: (token: string, id: string, cursor?: str
34
139
  }[] | undefined;
35
140
  fetchMore: (() => Promise</*elided*/ any>) | undefined;
36
141
  }>;
142
+ /**
143
+ * Fetches a single Instagram message by id.
144
+ *
145
+ * @param token - Instagram access token.
146
+ * @param id - Message id.
147
+ * @param fields - Optional array of field names. Default: `["id", "created_time", "from", "to", "message"]`.
148
+ * @returns Promise of message data (typed as `T`, defaults to {@link InstagramMessage}).
149
+ *
150
+ * @category Socials
151
+ */
37
152
  declare const getInstagramMessage: <T = InstagramMessage>(token: string, id: string, fields?: string[]) => Promise<(T & InstagramError) | null>;
38
153
 
39
154
  export { getInstagramConversation, getInstagramConversationByUser, getInstagramConversations, getInstagramConversationsByUser, getInstagramMedia, getInstagramMessage, getInstagramUser };
@@ -1,5 +1,23 @@
1
1
  import { InstagramError } from './types.mjs';
2
2
 
3
+ /**
4
+ * Sends a text message to an Instagram user via the Instagram Messaging API.
5
+ *
6
+ * @param token - Instagram access token.
7
+ * @param to - Recipient's Instagram user id.
8
+ * @param text - Message text to send.
9
+ * @returns Promise of `{ recipient_id, message_id }` on success.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { sendInstagramMessage } from "naystack/socials";
14
+ *
15
+ * const result = await sendInstagramMessage(accessToken, recipientId, "Hello!");
16
+ * console.log("Sent message:", result?.message_id);
17
+ * ```
18
+ *
19
+ * @category Socials
20
+ */
3
21
  declare const sendInstagramMessage: (token: string, to: string, text: string) => Promise<({
4
22
  recipient_id?: string;
5
23
  message_id?: string;
@@ -1,5 +1,23 @@
1
1
  import { InstagramError } from './types.js';
2
2
 
3
+ /**
4
+ * Sends a text message to an Instagram user via the Instagram Messaging API.
5
+ *
6
+ * @param token - Instagram access token.
7
+ * @param to - Recipient's Instagram user id.
8
+ * @param text - Message text to send.
9
+ * @returns Promise of `{ recipient_id, message_id }` on success.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { sendInstagramMessage } from "naystack/socials";
14
+ *
15
+ * const result = await sendInstagramMessage(accessToken, recipientId, "Hello!");
16
+ * console.log("Sent message:", result?.message_id);
17
+ * ```
18
+ *
19
+ * @category Socials
20
+ */
3
21
  declare const sendInstagramMessage: (token: string, to: string, text: string) => Promise<({
4
22
  recipient_id?: string;
5
23
  message_id?: string;
@@ -1,3 +1,14 @@
1
+ /**
2
+ * Instagram Messaging API message shape.
3
+ *
4
+ * @property id - Message id.
5
+ * @property created_time - ISO timestamp of when the message was sent.
6
+ * @property from - Sender's id and username.
7
+ * @property to - Array of recipient ids and usernames.
8
+ * @property message - Text content of the message.
9
+ *
10
+ * @category Socials
11
+ */
1
12
  type InstagramMessage = {
2
13
  id: string;
3
14
  created_time: string;
@@ -13,16 +24,44 @@ type InstagramMessage = {
13
24
  };
14
25
  message: string;
15
26
  };
27
+ /**
28
+ * Instagram user/profile data (e.g. from the `"me"` endpoint).
29
+ *
30
+ * @property username - Instagram handle.
31
+ * @property followers_count - Number of followers.
32
+ * @property media_count - Number of media posts.
33
+ *
34
+ * @category Socials
35
+ */
16
36
  type InstagramUser = {
17
37
  username: string;
18
38
  followers_count: number;
19
39
  media_count: number;
20
40
  };
41
+ /**
42
+ * Instagram media item (e.g. from the `me/media` endpoint).
43
+ *
44
+ * @property like_count - Number of likes (may be undefined if not requested).
45
+ * @property comments_count - Number of comments.
46
+ * @property permalink - Permanent URL to the post on Instagram.
47
+ *
48
+ * @category Socials
49
+ */
21
50
  type InstagramMedia = {
22
51
  like_count?: number;
23
52
  comments_count: number;
24
53
  permalink: string;
25
54
  };
55
+ /**
56
+ * Instagram conversation (DM thread) from the Messaging API.
57
+ *
58
+ * @property id - Conversation id.
59
+ * @property updated_time - ISO timestamp of the last update.
60
+ * @property messages - Optional nested messages with pagination cursors.
61
+ * @property participants - Optional array of participant ids and usernames.
62
+ *
63
+ * @category Socials
64
+ */
26
65
  type InstagramConversation = {
27
66
  id: string;
28
67
  updated_time: string;
@@ -44,6 +83,13 @@ type InstagramConversation = {
44
83
  }[];
45
84
  };
46
85
  };
86
+ /**
87
+ * Instagram Graph API error response shape.
88
+ *
89
+ * @property error - Error details from the API (message, type, code, subcode, trace id).
90
+ *
91
+ * @category Socials
92
+ */
47
93
  type InstagramError = {
48
94
  error?: {
49
95
  message: string;
@@ -1,3 +1,14 @@
1
+ /**
2
+ * Instagram Messaging API message shape.
3
+ *
4
+ * @property id - Message id.
5
+ * @property created_time - ISO timestamp of when the message was sent.
6
+ * @property from - Sender's id and username.
7
+ * @property to - Array of recipient ids and usernames.
8
+ * @property message - Text content of the message.
9
+ *
10
+ * @category Socials
11
+ */
1
12
  type InstagramMessage = {
2
13
  id: string;
3
14
  created_time: string;
@@ -13,16 +24,44 @@ type InstagramMessage = {
13
24
  };
14
25
  message: string;
15
26
  };
27
+ /**
28
+ * Instagram user/profile data (e.g. from the `"me"` endpoint).
29
+ *
30
+ * @property username - Instagram handle.
31
+ * @property followers_count - Number of followers.
32
+ * @property media_count - Number of media posts.
33
+ *
34
+ * @category Socials
35
+ */
16
36
  type InstagramUser = {
17
37
  username: string;
18
38
  followers_count: number;
19
39
  media_count: number;
20
40
  };
41
+ /**
42
+ * Instagram media item (e.g. from the `me/media` endpoint).
43
+ *
44
+ * @property like_count - Number of likes (may be undefined if not requested).
45
+ * @property comments_count - Number of comments.
46
+ * @property permalink - Permanent URL to the post on Instagram.
47
+ *
48
+ * @category Socials
49
+ */
21
50
  type InstagramMedia = {
22
51
  like_count?: number;
23
52
  comments_count: number;
24
53
  permalink: string;
25
54
  };
55
+ /**
56
+ * Instagram conversation (DM thread) from the Messaging API.
57
+ *
58
+ * @property id - Conversation id.
59
+ * @property updated_time - ISO timestamp of the last update.
60
+ * @property messages - Optional nested messages with pagination cursors.
61
+ * @property participants - Optional array of participant ids and usernames.
62
+ *
63
+ * @category Socials
64
+ */
26
65
  type InstagramConversation = {
27
66
  id: string;
28
67
  updated_time: string;
@@ -44,6 +83,13 @@ type InstagramConversation = {
44
83
  }[];
45
84
  };
46
85
  };
86
+ /**
87
+ * Instagram Graph API error response shape.
88
+ *
89
+ * @property error - Error details from the API (message, type, code, subcode, trace id).
90
+ *
91
+ * @category Socials
92
+ */
47
93
  type InstagramError = {
48
94
  error?: {
49
95
  message: string;
@@ -1,6 +1,25 @@
1
1
  import { InstagramError } from './types.mjs';
2
2
 
3
+ /**
4
+ * Builds an Instagram Graph API URL with the given path and query parameters (includes `access_token`).
5
+ *
6
+ * @param token - Instagram access token.
7
+ * @param path - API path (e.g. `"me"`, `"me/media"`, `"me/conversations"`).
8
+ * @param params - Additional query parameters.
9
+ * @returns Full URL string.
10
+ * @category Socials
11
+ */
3
12
  declare function getInstagramURL(token: string, path: string, params: Record<string, string>): string;
13
+ /**
14
+ * Fetches JSON from the Instagram Graph API (GET or POST depending on whether `postData` is provided).
15
+ *
16
+ * @param token - Instagram access token.
17
+ * @param path - API path.
18
+ * @param params - Query parameters (default: `{}`).
19
+ * @param postData - Optional POST body (if provided, the request becomes a POST).
20
+ * @returns Promise of `(T & InstagramError) | null`.
21
+ * @category Socials
22
+ */
4
23
  declare function getInstagramData<T>(token: string, path: string, params?: Record<string, string>, postData?: object): Promise<(T & InstagramError) | null>;
5
24
 
6
25
  export { getInstagramData, getInstagramURL };
@@ -1,6 +1,25 @@
1
1
  import { InstagramError } from './types.js';
2
2
 
3
+ /**
4
+ * Builds an Instagram Graph API URL with the given path and query parameters (includes `access_token`).
5
+ *
6
+ * @param token - Instagram access token.
7
+ * @param path - API path (e.g. `"me"`, `"me/media"`, `"me/conversations"`).
8
+ * @param params - Additional query parameters.
9
+ * @returns Full URL string.
10
+ * @category Socials
11
+ */
3
12
  declare function getInstagramURL(token: string, path: string, params: Record<string, string>): string;
13
+ /**
14
+ * Fetches JSON from the Instagram Graph API (GET or POST depending on whether `postData` is provided).
15
+ *
16
+ * @param token - Instagram access token.
17
+ * @param path - API path.
18
+ * @param params - Query parameters (default: `{}`).
19
+ * @param postData - Optional POST body (if provided, the request becomes a POST).
20
+ * @returns Promise of `(T & InstagramError) | null`.
21
+ * @category Socials
22
+ */
4
23
  declare function getInstagramData<T>(token: string, path: string, params?: Record<string, string>, postData?: object): Promise<(T & InstagramError) | null>;
5
24
 
6
25
  export { getInstagramData, getInstagramURL };
@@ -1,6 +1,37 @@
1
1
  import * as next_server from 'next/server';
2
2
  import { NextRequest } from 'next/server';
3
3
 
4
+ /**
5
+ * Sets up GET (verification) and POST (event handling) route handlers for the Instagram webhook.
6
+ *
7
+ * - **GET**: Responds to Meta's webhook verification challenge (checks `hub.verify_token` against `secret`).
8
+ * - **POST**: Parses incoming webhook events and calls your `callback` for each event in the payload.
9
+ *
10
+ * @param options - Configuration object.
11
+ * @param options.secret - The verify token you configured in the Meta Developer Portal.
12
+ * @param options.callback - Called for each webhook event: `(type, value, pageId) => Promise<void>`.
13
+ * - `type` — Event type (e.g. `"messaging"`, `"changes"`).
14
+ * - `value` — Event payload.
15
+ * - `id` — The page/account id from the entry.
16
+ * @returns Object with `GET` and `POST` — export as your route's handlers.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * // app/api/webhooks/instagram/route.ts
21
+ * import { setupInstagramWebhook } from "naystack/socials";
22
+ *
23
+ * export const { GET, POST } = setupInstagramWebhook({
24
+ * secret: process.env.WEBHOOK_SECRET!,
25
+ * callback: async (type, value, id) => {
26
+ * if (type === "messaging") {
27
+ * console.log("New message from page", id, value);
28
+ * }
29
+ * },
30
+ * });
31
+ * ```
32
+ *
33
+ * @category Socials
34
+ */
4
35
  declare const setupInstagramWebhook: (options: {
5
36
  secret: string;
6
37
  callback: (type: string, value: any, id: string) => Promise<void>;
@@ -1,6 +1,37 @@
1
1
  import * as next_server from 'next/server';
2
2
  import { NextRequest } from 'next/server';
3
3
 
4
+ /**
5
+ * Sets up GET (verification) and POST (event handling) route handlers for the Instagram webhook.
6
+ *
7
+ * - **GET**: Responds to Meta's webhook verification challenge (checks `hub.verify_token` against `secret`).
8
+ * - **POST**: Parses incoming webhook events and calls your `callback` for each event in the payload.
9
+ *
10
+ * @param options - Configuration object.
11
+ * @param options.secret - The verify token you configured in the Meta Developer Portal.
12
+ * @param options.callback - Called for each webhook event: `(type, value, pageId) => Promise<void>`.
13
+ * - `type` — Event type (e.g. `"messaging"`, `"changes"`).
14
+ * - `value` — Event payload.
15
+ * - `id` — The page/account id from the entry.
16
+ * @returns Object with `GET` and `POST` — export as your route's handlers.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * // app/api/webhooks/instagram/route.ts
21
+ * import { setupInstagramWebhook } from "naystack/socials";
22
+ *
23
+ * export const { GET, POST } = setupInstagramWebhook({
24
+ * secret: process.env.WEBHOOK_SECRET!,
25
+ * callback: async (type, value, id) => {
26
+ * if (type === "messaging") {
27
+ * console.log("New message from page", id, value);
28
+ * }
29
+ * },
30
+ * });
31
+ * ```
32
+ *
33
+ * @category Socials
34
+ */
4
35
  declare const setupInstagramWebhook: (options: {
5
36
  secret: string;
6
37
  callback: (type: string, value: any, id: string) => Promise<void>;
@@ -1,5 +1,16 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
2
 
3
+ /**
4
+ * Returns a GET handler that verifies a Meta (Instagram/Threads) webhook subscription.
5
+ * Responds with `hub.challenge` when `hub.verify_token` matches the provided secret.
6
+ *
7
+ * Used internally by `setupInstagramWebhook` and `setupThreadsWebhook`.
8
+ *
9
+ * @param secret - Expected `hub.verify_token` value (configured in the Meta Developer Portal).
10
+ * @returns GET route handler that responds to Meta's verification request.
11
+ *
12
+ * @category Socials
13
+ */
3
14
  declare const verifyWebhook: (secret: string) => (req: NextRequest) => NextResponse<unknown> | undefined;
4
15
 
5
16
  export { verifyWebhook };
@@ -1,5 +1,16 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
2
 
3
+ /**
4
+ * Returns a GET handler that verifies a Meta (Instagram/Threads) webhook subscription.
5
+ * Responds with `hub.challenge` when `hub.verify_token` matches the provided secret.
6
+ *
7
+ * Used internally by `setupInstagramWebhook` and `setupThreadsWebhook`.
8
+ *
9
+ * @param secret - Expected `hub.verify_token` value (configured in the Meta Developer Portal).
10
+ * @returns GET route handler that responds to Meta's verification request.
11
+ *
12
+ * @category Socials
13
+ */
3
14
  declare const verifyWebhook: (secret: string) => (req: NextRequest) => NextResponse<unknown> | undefined;
4
15
 
5
16
  export { verifyWebhook };