@postrun/react 0.1.0 → 0.2.0
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/index.cjs +49 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +304 -95
- package/dist/index.d.ts +304 -95
- package/dist/index.js +49 -11
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { createContext, memo, useMemo, useState, useEffect, Fragment as Fragment$1, useRef, createElement, useContext, useCallback } from 'react';
|
|
3
3
|
import { useInfiniteQuery, useQuery, useMutation, QueryClient } from '@tanstack/react-query';
|
|
4
|
-
import { createPostrunClient, profilesList, profilesGet, profilesCreate, profilesUpdate, profilesDelete, connectionsConnect, connectionsListByProfile, connectionsGet, connectionsListAccounts, connectionsSelect, connectionsDelete, mediaCreate, mediaGet, mediaUpdate, mediaDelete, postsList, postsGet, postsCreate, buildCreatePost, isPostPlatform, postsUpdate, postsDelete } from '@postrun/js';
|
|
4
|
+
import { createPostrunClient, profilesList, profilesGet, profilesCreate, profilesUpdate, profilesDelete, connectionsConnect, connectionsListByProfile, connectionsGet, connectionsListAccounts, connectionsSelect, connectionsDelete, mediaCreate, mediaGet, mediaList, mediaUpdate, mediaDelete, postsList, postsGet, postsCreate, buildCreatePost, isPostPlatform, postsUpdate, postsDelete } from '@postrun/js';
|
|
5
5
|
import pRetry, { AbortError } from 'p-retry';
|
|
6
6
|
import pWaitFor from 'p-wait-for';
|
|
7
7
|
import axios, { isAxiosError } from 'axios';
|
|
@@ -89,7 +89,8 @@ var profileKeys = {
|
|
|
89
89
|
list: (query) => [...profileKeys.lists(), query ?? {}],
|
|
90
90
|
// Nested under lists() so a create/update/delete invalidating lists() also
|
|
91
91
|
// refreshes the infinite cache; distinct tail so the two cache shapes (a
|
|
92
|
-
// single Page vs accumulated pages) never collide on one key.
|
|
92
|
+
// single Page vs accumulated pages) never collide on one key. The filter omits
|
|
93
|
+
// limit/offset — the infinite hook owns pagination, so they never key the cache.
|
|
93
94
|
infinite: (query) => [...profileKeys.lists(), "infinite", query ?? {}],
|
|
94
95
|
details: () => [...profileKeys.all, "detail"],
|
|
95
96
|
detail: (id) => [...profileKeys.details(), id]
|
|
@@ -100,20 +101,28 @@ var postKeys = {
|
|
|
100
101
|
list: (query) => [...postKeys.lists(), query ?? {}],
|
|
101
102
|
// Nested under lists() so a create/update/delete invalidating lists() also
|
|
102
103
|
// refreshes the infinite cache; distinct tail so the two cache shapes (a
|
|
103
|
-
// single Page vs accumulated pages) never collide on one key.
|
|
104
|
+
// single Page vs accumulated pages) never collide on one key. The filter omits
|
|
105
|
+
// limit/offset — the infinite hook owns pagination, so they never key the cache.
|
|
104
106
|
infinite: (query) => [...postKeys.lists(), "infinite", query ?? {}],
|
|
105
107
|
details: () => [...postKeys.all, "detail"],
|
|
106
108
|
detail: (id) => [...postKeys.details(), id]
|
|
107
109
|
};
|
|
108
110
|
var mediaKeys = {
|
|
109
111
|
all: [ROOT, "media"],
|
|
112
|
+
lists: () => [...mediaKeys.all, "list"],
|
|
113
|
+
list: (query) => [...mediaKeys.lists(), query ?? {}],
|
|
114
|
+
// Nested under lists() so an upload/update/delete invalidating lists() also
|
|
115
|
+
// refreshes the infinite cache; distinct tail so the two cache shapes (a
|
|
116
|
+
// single Page vs accumulated pages) never collide on one key. The filter omits
|
|
117
|
+
// limit/offset — the infinite hook owns pagination, so they never key the cache.
|
|
118
|
+
infinite: (query) => [...mediaKeys.lists(), "infinite", query ?? {}],
|
|
110
119
|
details: () => [...mediaKeys.all, "detail"],
|
|
111
120
|
detail: (id) => [...mediaKeys.details(), id]
|
|
112
121
|
};
|
|
113
122
|
var connectionKeys = {
|
|
114
123
|
all: [ROOT, "connections"],
|
|
115
124
|
lists: () => [...connectionKeys.all, "list"],
|
|
116
|
-
list: (profileId) => [...connectionKeys.lists(), profileId],
|
|
125
|
+
list: (profileId, filter) => [...connectionKeys.lists(), profileId, filter ?? {}],
|
|
117
126
|
details: () => [...connectionKeys.all, "detail"],
|
|
118
127
|
detail: (id) => [...connectionKeys.details(), id],
|
|
119
128
|
accounts: (id) => [...connectionKeys.all, "accounts", id]
|
|
@@ -202,19 +211,23 @@ function useConnect() {
|
|
|
202
211
|
path: { id: profileId },
|
|
203
212
|
body: { platform }
|
|
204
213
|
})).data;
|
|
205
|
-
navigate(session.
|
|
214
|
+
navigate(session.hosted_connect_url);
|
|
206
215
|
return session;
|
|
207
216
|
}
|
|
208
217
|
},
|
|
209
218
|
queryClient
|
|
210
219
|
);
|
|
211
220
|
}
|
|
212
|
-
function useConnections(profileId) {
|
|
221
|
+
function useConnections(profileId, filter) {
|
|
213
222
|
const { client, queryClient } = usePostrun();
|
|
214
223
|
return useQuery(
|
|
215
224
|
{
|
|
216
|
-
queryKey: connectionKeys.list(profileId),
|
|
217
|
-
queryFn: async () => (await connectionsListByProfile({
|
|
225
|
+
queryKey: connectionKeys.list(profileId, filter),
|
|
226
|
+
queryFn: async () => (await connectionsListByProfile({
|
|
227
|
+
client,
|
|
228
|
+
path: { id: profileId },
|
|
229
|
+
query: filter
|
|
230
|
+
})).data,
|
|
218
231
|
enabled: Boolean(profileId)
|
|
219
232
|
},
|
|
220
233
|
queryClient
|
|
@@ -399,6 +412,7 @@ function useMediaUpload() {
|
|
|
399
412
|
controller.signal
|
|
400
413
|
);
|
|
401
414
|
queryClient.setQueryData(mediaKeys.detail(created.id), settled);
|
|
415
|
+
void queryClient.invalidateQueries({ queryKey: mediaKeys.lists() });
|
|
402
416
|
setMedia(settled);
|
|
403
417
|
setStatus(settled.status === "failed" ? "failed" : "ready");
|
|
404
418
|
return settled;
|
|
@@ -438,12 +452,33 @@ function useMedia(id) {
|
|
|
438
452
|
queryClient
|
|
439
453
|
);
|
|
440
454
|
}
|
|
455
|
+
function useMediaList(query) {
|
|
456
|
+
const { client, queryClient } = usePostrun();
|
|
457
|
+
return useQuery(
|
|
458
|
+
{
|
|
459
|
+
queryKey: mediaKeys.list(query),
|
|
460
|
+
queryFn: async () => (await mediaList({ client, query })).data
|
|
461
|
+
},
|
|
462
|
+
queryClient
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
function useMediaInfinite(filters, options) {
|
|
466
|
+
const { client } = usePostrun();
|
|
467
|
+
return useInfiniteList({
|
|
468
|
+
queryKey: mediaKeys.infinite(filters),
|
|
469
|
+
limit: options?.pageSize,
|
|
470
|
+
fetchPage: async ({ limit, offset }) => (await mediaList({ client, query: { ...filters, limit, offset } })).data
|
|
471
|
+
});
|
|
472
|
+
}
|
|
441
473
|
function useUpdateMedia() {
|
|
442
474
|
const { client, queryClient } = usePostrun();
|
|
443
475
|
return useMutation(
|
|
444
476
|
{
|
|
445
477
|
mutationFn: async ({ id, ...body }) => (await mediaUpdate({ client, path: { id }, body })).data,
|
|
446
|
-
onSuccess: (result, { id }) =>
|
|
478
|
+
onSuccess: (result, { id }) => {
|
|
479
|
+
queryClient.setQueryData(mediaKeys.detail(id), result);
|
|
480
|
+
void queryClient.invalidateQueries({ queryKey: mediaKeys.lists() });
|
|
481
|
+
}
|
|
447
482
|
},
|
|
448
483
|
queryClient
|
|
449
484
|
);
|
|
@@ -453,7 +488,10 @@ function useDeleteMedia() {
|
|
|
453
488
|
return useMutation(
|
|
454
489
|
{
|
|
455
490
|
mutationFn: async (id) => (await mediaDelete({ client, path: { id } })).data,
|
|
456
|
-
onSuccess: (_result, id) =>
|
|
491
|
+
onSuccess: (_result, id) => {
|
|
492
|
+
queryClient.removeQueries({ queryKey: mediaKeys.detail(id) });
|
|
493
|
+
void queryClient.invalidateQueries({ queryKey: mediaKeys.lists() });
|
|
494
|
+
}
|
|
457
495
|
},
|
|
458
496
|
queryClient
|
|
459
497
|
);
|
|
@@ -1279,6 +1317,6 @@ function LinkedInPostPreviewImpl({
|
|
|
1279
1317
|
}
|
|
1280
1318
|
var LinkedInPostPreview = memo(LinkedInPostPreviewImpl);
|
|
1281
1319
|
|
|
1282
|
-
export { LinkedInPostPreview, PostrunProvider, UploadError, XPostPreview, connectionKeys, mediaKeys, postKeys, profileKeys, useCalendar, useConnect, useConnection, useConnections, useCreatePost, useCreateProfile, useDeleteMedia, useDeletePost, useDeleteProfile, useDisconnect, useDiscoverableAccounts, useInfiniteList, useMedia, useMediaUpload, usePost, usePostrun, usePosts, usePostsInfinite, useProfile, useProfiles, useProfilesInfinite, useSelectAccount, useUpdateMedia, useUpdatePost, useUpdateProfile };
|
|
1320
|
+
export { LinkedInPostPreview, PostrunProvider, UploadError, XPostPreview, connectionKeys, mediaKeys, postKeys, profileKeys, useCalendar, useConnect, useConnection, useConnections, useCreatePost, useCreateProfile, useDeleteMedia, useDeletePost, useDeleteProfile, useDisconnect, useDiscoverableAccounts, useInfiniteList, useMedia, useMediaInfinite, useMediaList, useMediaUpload, usePost, usePostrun, usePosts, usePostsInfinite, useProfile, useProfiles, useProfilesInfinite, useSelectAccount, useUpdateMedia, useUpdatePost, useUpdateProfile };
|
|
1283
1321
|
//# sourceMappingURL=index.js.map
|
|
1284
1322
|
//# sourceMappingURL=index.js.map
|