@openpeepshq/client 0.2.0 → 0.3.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.
@@ -1,56 +1,53 @@
1
1
  import type {
2
- FetchClient,
3
- noPayloadEventSource,
2
+ FetchClient,
3
+ noPayloadEventSource,
4
4
  } from '@openpeepshq/fetch-client';
5
5
  import type {
6
- MediaAttachment,
7
- MediaProgressEvent,
8
- MediaStorageRequestInput,
9
- SuccessResponse,
6
+ MediaAttachment,
7
+ MediaProgressEvent,
8
+ MediaStorageRequestInput,
9
+ SuccessResponse,
10
10
  } from '@openpeepshq/common';
11
11
  import {
12
- allpeepNoPayloadEndpoint,
13
- allpeepPayloadEndpoint,
14
- allpeepPayloadProgressObserverEndpoint,
12
+ allpeepNoPayloadEndpoint,
13
+ allpeepPayloadEndpoint,
14
+ allpeepPayloadProgressObserverEndpoint,
15
15
  } from './helpers';
16
16
 
17
17
  export const media = (
18
- rawClient: FetchClient,
19
- eventSource: ReturnType<typeof noPayloadEventSource>,
18
+ rawClient: FetchClient,
19
+ eventSource: ReturnType<typeof noPayloadEventSource>,
20
20
  ) => ({
21
- list: allpeepNoPayloadEndpoint<MediaAttachment[]>(
22
- rawClient,
23
- '/media',
24
- ),
25
- findById: allpeepNoPayloadEndpoint<MediaAttachment, { id: string }>(
26
- rawClient,
27
- '/media/:id',
28
- ),
29
- create: allpeepPayloadEndpoint<MediaAttachment, MediaStorageRequestInput>(
30
- rawClient,
31
- '/media',
32
- 'post',
33
- true,
34
- ),
35
- /**
36
- * Same as `create` but routes through XHR so callers can pass
37
- * `onUploadProgress` to receive byte-level upload events. Returns either a
38
- * fully-processed `MediaAttachment` (small files, sync path) or a partial
39
- * one with `status: 'processing'` (large files, async path) — pair with
40
- * `progress.listen` to track the background processing phase.
41
- */
42
- createWithProgress: allpeepPayloadProgressObserverEndpoint<
43
- MediaAttachment,
44
- MediaStorageRequestInput
45
- >(rawClient, '/media', 'post', true),
46
- delete: allpeepNoPayloadEndpoint<SuccessResponse, { id: string }>(
47
- rawClient,
48
- '/media/:id',
49
- 'delete',
21
+ list: allpeepNoPayloadEndpoint<MediaAttachment[]>(rawClient, '/media'),
22
+ findById: allpeepNoPayloadEndpoint<MediaAttachment, { id: string }>(
23
+ rawClient,
24
+ '/media/:id',
25
+ ),
26
+ create: allpeepPayloadEndpoint<MediaAttachment, MediaStorageRequestInput>(
27
+ rawClient,
28
+ '/media',
29
+ 'post',
30
+ true,
31
+ ),
32
+ /**
33
+ * Same as `create` but routes through XHR so callers can pass
34
+ * `onUploadProgress` to receive byte-level upload events. Returns either a
35
+ * fully-processed `MediaAttachment` (small files, sync path) or a partial
36
+ * one with `status: 'processing'` (large files, async path) — pair with
37
+ * `progress.listen` to track the background processing phase.
38
+ */
39
+ createWithProgress: allpeepPayloadProgressObserverEndpoint<
40
+ MediaAttachment,
41
+ MediaStorageRequestInput
42
+ >(rawClient, '/media', 'post', true),
43
+ delete: allpeepNoPayloadEndpoint<SuccessResponse, { id: string }>(
44
+ rawClient,
45
+ '/media/:id',
46
+ 'delete',
47
+ ),
48
+ progress: {
49
+ listen: eventSource<MediaProgressEvent, { id: string }>(
50
+ '/media/:id/progress',
50
51
  ),
51
- progress: {
52
- listen: eventSource<MediaProgressEvent, { id: string }>(
53
- '/media/:id/progress',
54
- ),
55
- },
52
+ },
56
53
  });
@@ -77,6 +77,7 @@ type Finders = {
77
77
  { id: string; recordingId: string }
78
78
  >;
79
79
  unseenCounts: OpenpeepsNoPayloadEndpoint<UnseenPostCounts>;
80
+ exportRsvps: (args: { id: string; occurrence?: string }) => Promise<string>;
80
81
  };
81
82
 
82
83
  // Explicit return types keep `tsc` from serializing the expanded PublicPost
@@ -140,6 +141,18 @@ const finders = (rawClient: FetchClient): Finders => ({
140
141
  rawClient,
141
142
  '/posts/unseen/counts',
142
143
  ),
144
+ exportRsvps: async ({ id, occurrence }) => {
145
+ const query = occurrence
146
+ ? `?occurrence=${encodeURIComponent(occurrence)}`
147
+ : '';
148
+ const response = await rawClient.get(`/posts/${id}/rsvp/export${query}`);
149
+
150
+ if (!response.ok) {
151
+ throw { ...(await response.json()), status: response.status };
152
+ }
153
+
154
+ return response.text();
155
+ },
143
156
  });
144
157
 
145
158
  const eventFeeds = (rawClient: FetchClient): EventFeeds => ({
@@ -1,10 +1,9 @@
1
1
  import type { FetchClient } from '@openpeepshq/fetch-client';
2
- import type {
3
- FetchUrlResponse,
4
- } from '@openpeepshq/common';
2
+ import type { FetchUrlResponse } from '@openpeepshq/common';
5
3
  import { allpeepNoPayloadEndpoint } from './helpers';
6
4
 
7
- export const previewLink = (rawClient: FetchClient) => allpeepNoPayloadEndpoint<FetchUrlResponse, { url: string }>(
5
+ export const previewLink = (rawClient: FetchClient) =>
6
+ allpeepNoPayloadEndpoint<FetchUrlResponse, { url: string }>(
8
7
  rawClient,
9
8
  '/fetch-url/:url',
10
- );
9
+ );
@@ -1,32 +1,29 @@
1
1
  import type { FetchClient } from '@openpeepshq/fetch-client';
2
2
  import type {
3
- ReportCreationData,
4
- PublicReport,
5
- SuccessResponse,
3
+ ReportCreationData,
4
+ PublicReport,
5
+ SuccessResponse,
6
6
  } from '@openpeepshq/common';
7
7
  import { allpeepNoPayloadEndpoint, allpeepPayloadEndpoint } from './helpers';
8
8
 
9
9
  export const reports = (rawClient: FetchClient) => ({
10
- list: allpeepNoPayloadEndpoint<PublicReport[]>(
11
- rawClient,
12
- '/reports',
13
- ),
14
- findById: allpeepNoPayloadEndpoint<PublicReport, { reportId: string }>(
15
- rawClient,
16
- '/reports/:reportId',
17
- ),
18
- create: allpeepPayloadEndpoint<PublicReport, ReportCreationData>(
19
- rawClient,
20
- '/reports',
21
- ),
22
- update: allpeepPayloadEndpoint<PublicReport, Partial<ReportCreationData>, { id: string }>(
23
- rawClient,
24
- '/reports/:id',
25
- 'patch',
26
- ),
27
- delete: allpeepNoPayloadEndpoint<SuccessResponse, { id: string }>(
28
- rawClient,
29
- '/reports/:id',
30
- 'delete',
31
- ),
32
- });
10
+ list: allpeepNoPayloadEndpoint<PublicReport[]>(rawClient, '/reports'),
11
+ findById: allpeepNoPayloadEndpoint<PublicReport, { reportId: string }>(
12
+ rawClient,
13
+ '/reports/:reportId',
14
+ ),
15
+ create: allpeepPayloadEndpoint<PublicReport, ReportCreationData>(
16
+ rawClient,
17
+ '/reports',
18
+ ),
19
+ update: allpeepPayloadEndpoint<
20
+ PublicReport,
21
+ Partial<ReportCreationData>,
22
+ { id: string }
23
+ >(rawClient, '/reports/:id', 'patch'),
24
+ delete: allpeepNoPayloadEndpoint<SuccessResponse, { id: string }>(
25
+ rawClient,
26
+ '/reports/:id',
27
+ 'delete',
28
+ ),
29
+ });
@@ -1,34 +1,47 @@
1
- import { FetchClient } from "@openpeepshq/fetch-client";
2
- import { allpeepNoPayloadEndpoint } from "./helpers";
3
- import { GroupWithMeta, PublicPost, OffsetInfiniteQueryParams, PublicProfile, SearchResult, SearchResultCounts } from "@openpeepshq/common";
1
+ import { FetchClient } from '@openpeepshq/fetch-client';
2
+ import { allpeepNoPayloadEndpoint } from './helpers';
3
+ import {
4
+ GroupWithMeta,
5
+ PublicPost,
6
+ OffsetInfiniteQueryParams,
7
+ PublicProfile,
8
+ SearchResult,
9
+ SearchResultCounts,
10
+ } from '@openpeepshq/common';
4
11
 
5
12
  type SearchQueryParams = OffsetInfiniteQueryParams & {
6
- q: string;
7
- }
13
+ q: string;
14
+ };
8
15
 
9
16
  export const search = (rawClient: FetchClient) => ({
10
- posts: allpeepNoPayloadEndpoint<SearchResult<PublicPost>, undefined, SearchQueryParams>(
11
- rawClient,
12
- '/search/posts',
13
- ),
14
- profiles: allpeepNoPayloadEndpoint<SearchResult<PublicProfile>, undefined, SearchQueryParams>(
15
- rawClient,
16
- '/search/profiles',
17
- ),
18
- events: allpeepNoPayloadEndpoint<SearchResult<PublicPost>, undefined, SearchQueryParams>(
19
- rawClient,
20
- '/search/events',
21
- ),
22
- jams: allpeepNoPayloadEndpoint<SearchResult<PublicPost>, undefined, SearchQueryParams>(
23
- rawClient,
24
- '/search/jams',
25
- ),
26
- groups: allpeepNoPayloadEndpoint<SearchResult<GroupWithMeta>, undefined, SearchQueryParams>(
27
- rawClient,
28
- '/search/groups',
29
- ),
30
- counts: allpeepNoPayloadEndpoint<SearchResultCounts, undefined, SearchQueryParams>(
31
- rawClient,
32
- '/search/counts',
33
- ),
34
- })
17
+ posts: allpeepNoPayloadEndpoint<
18
+ SearchResult<PublicPost>,
19
+ undefined,
20
+ SearchQueryParams
21
+ >(rawClient, '/search/posts'),
22
+ profiles: allpeepNoPayloadEndpoint<
23
+ SearchResult<PublicProfile>,
24
+ undefined,
25
+ SearchQueryParams
26
+ >(rawClient, '/search/profiles'),
27
+ events: allpeepNoPayloadEndpoint<
28
+ SearchResult<PublicPost>,
29
+ undefined,
30
+ SearchQueryParams
31
+ >(rawClient, '/search/events'),
32
+ jams: allpeepNoPayloadEndpoint<
33
+ SearchResult<PublicPost>,
34
+ undefined,
35
+ SearchQueryParams
36
+ >(rawClient, '/search/jams'),
37
+ groups: allpeepNoPayloadEndpoint<
38
+ SearchResult<GroupWithMeta>,
39
+ undefined,
40
+ SearchQueryParams
41
+ >(rawClient, '/search/groups'),
42
+ counts: allpeepNoPayloadEndpoint<
43
+ SearchResultCounts,
44
+ undefined,
45
+ SearchQueryParams
46
+ >(rawClient, '/search/counts'),
47
+ });
@@ -1,38 +1,31 @@
1
1
  import type { FetchClient } from '@openpeepshq/fetch-client';
2
2
  import type {
3
- CapabilitiesConfig,
4
- ServerInfo,
5
- WebhookKeyResponse,
6
- WebhookVerifyRequest,
7
- WebhookVerifyResponse,
3
+ CapabilitiesConfig,
4
+ ServerInfo,
5
+ WebhookKeyResponse,
6
+ WebhookVerifyRequest,
7
+ WebhookVerifyResponse,
8
8
  } from '@openpeepshq/common';
9
9
  import { allpeepNoPayloadEndpoint, allpeepPayloadEndpoint } from './helpers';
10
10
 
11
11
  export const server = (rawClient: FetchClient) => ({
12
- info: allpeepNoPayloadEndpoint<ServerInfo>(
13
- rawClient,
14
- '/server/info',
12
+ info: allpeepNoPayloadEndpoint<ServerInfo>(rawClient, '/server/info'),
13
+ config: {
14
+ capabilities: allpeepNoPayloadEndpoint<CapabilitiesConfig>(
15
+ rawClient,
16
+ '/server/config/capabilities',
15
17
  ),
16
- config: {
17
- capabilities: allpeepNoPayloadEndpoint<CapabilitiesConfig>(
18
- rawClient,
19
- '/server/config/capabilities',
20
- ),
21
- },
22
- keys: {
23
- webhooks: {
24
- public: allpeepNoPayloadEndpoint<WebhookKeyResponse>(
25
- rawClient,
26
- '/server/keys/webhooks',
27
- ),
28
- verify: allpeepPayloadEndpoint<
29
- WebhookVerifyResponse,
30
- WebhookVerifyRequest
31
- >(
32
- rawClient,
33
- '/server/keys/webhooks/verify',
34
- 'post',
35
- ),
36
- },
18
+ },
19
+ keys: {
20
+ webhooks: {
21
+ public: allpeepNoPayloadEndpoint<WebhookKeyResponse>(
22
+ rawClient,
23
+ '/server/keys/webhooks',
24
+ ),
25
+ verify: allpeepPayloadEndpoint<
26
+ WebhookVerifyResponse,
27
+ WebhookVerifyRequest
28
+ >(rawClient, '/server/keys/webhooks/verify', 'post'),
37
29
  },
38
- });
30
+ },
31
+ });
@@ -3,33 +3,21 @@ import type { TokenResponse } from '@openpeepshq/common';
3
3
  import { allpeepPayloadEndpoint, allpeepNoPayloadEndpoint } from './helpers';
4
4
 
5
5
  export const sso = (rawClient: FetchClient) => ({
6
- generic: {
7
- authenticate: allpeepPayloadEndpoint<
8
- TokenResponse,
9
- { data: Record<string, string> }
10
- >(
11
- rawClient,
12
- '/sso/generic',
13
- ),
14
- },
15
- oidc: {
16
- authorize: allpeepNoPayloadEndpoint<
17
- { data: { redirectUrl: string } },
18
- { id: string }
19
- >(
20
- rawClient,
21
- '/sso/oidc/{id}/authorize',
22
- 'get',
23
- ),
24
- callback: allpeepNoPayloadEndpoint<
25
- TokenResponse,
26
- { id: string },
27
- Record<string, string>
28
- >(
29
- rawClient,
30
- '/sso/oidc/{id}/callback',
31
- 'get',
32
- ),
33
- },
34
- }
35
- );
6
+ generic: {
7
+ authenticate: allpeepPayloadEndpoint<
8
+ TokenResponse,
9
+ { data: Record<string, string> }
10
+ >(rawClient, '/sso/generic'),
11
+ },
12
+ oidc: {
13
+ authorize: allpeepNoPayloadEndpoint<
14
+ { data: { redirectUrl: string } },
15
+ { id: string }
16
+ >(rawClient, '/sso/oidc/{id}/authorize', 'get'),
17
+ callback: allpeepNoPayloadEndpoint<
18
+ TokenResponse,
19
+ { id: string },
20
+ Record<string, string>
21
+ >(rawClient, '/sso/oidc/{id}/callback', 'get'),
22
+ },
23
+ });
@@ -1,29 +1,23 @@
1
1
  import type { FetchClient } from '@openpeepshq/fetch-client';
2
- import type {
3
- MediaStream,
4
- MediaStreamRequest,
5
- } from '@openpeepshq/common';
6
- import {
7
- allpeepNoPayloadEndpoint,
8
- allpeepPayloadEndpoint,
9
- } from './helpers';
2
+ import type { MediaStream, MediaStreamRequest } from '@openpeepshq/common';
3
+ import { allpeepNoPayloadEndpoint, allpeepPayloadEndpoint } from './helpers';
10
4
 
11
5
  export const streaming = (rawClient: FetchClient) => ({
12
- vod: {
13
- /**
14
- * Request that an HLS VOD stream be produced for a media URL hosted on
15
- * this server. Idempotent: returns the existing stream's status when
16
- * called again with the same source URL.
17
- */
18
- create: allpeepPayloadEndpoint<MediaStream, MediaStreamRequest>(
19
- rawClient,
20
- '/streaming/vod',
21
- 'post',
22
- ),
23
- /** Polls the current status of a previously-created VOD stream. */
24
- status: allpeepNoPayloadEndpoint<MediaStream, { storageId: string }>(
25
- rawClient,
26
- '/streaming/vod/:storageId/status',
27
- ),
28
- },
6
+ vod: {
7
+ /**
8
+ * Request that an HLS VOD stream be produced for a media URL hosted on
9
+ * this server. Idempotent: returns the existing stream's status when
10
+ * called again with the same source URL.
11
+ */
12
+ create: allpeepPayloadEndpoint<MediaStream, MediaStreamRequest>(
13
+ rawClient,
14
+ '/streaming/vod',
15
+ 'post',
16
+ ),
17
+ /** Polls the current status of a previously-created VOD stream. */
18
+ status: allpeepNoPayloadEndpoint<MediaStream, { storageId: string }>(
19
+ rawClient,
20
+ '/streaming/vod/:storageId/status',
21
+ ),
22
+ },
29
23
  });
@@ -7,18 +7,14 @@ import {
7
7
  import { parseJwtKeyId, verifyJwt } from '@openpeepshq/common/lib';
8
8
  import type { OpenpeepsNoPayloadEndpoint } from '../types';
9
9
 
10
- export type WebhookHandler = ((
11
- input: string,
12
- ) => Promise<WebhookData>);
10
+ export type WebhookHandler = (input: string) => Promise<WebhookData>;
13
11
 
14
12
  export const webhookHandler = (
15
13
  publicKeyEndpoint: OpenpeepsNoPayloadEndpoint<WebhookKeyResponse>,
16
14
  ): WebhookHandler => {
17
-
18
- let publicKey: string | undefined = undefined;
15
+ const publicKey: string | undefined = undefined;
19
16
 
20
17
  const getPublicKey = async (kid?: string) => {
21
-
22
18
  if (!kid) {
23
19
  throw new Error('Kid is required');
24
20
  }
@@ -34,8 +30,7 @@ export const webhookHandler = (
34
30
  return result.data.publicKey;
35
31
  };
36
32
 
37
-
38
- return (async (input: string | WebhookVerifyRequest) => {
33
+ return async (input: string | WebhookVerifyRequest) => {
39
34
  const token = typeof input === 'string' ? input : input.token;
40
35
  const tokenKeyId = parseJwtKeyId(token);
41
36
 
@@ -45,6 +40,5 @@ export const webhookHandler = (
45
40
  }
46
41
 
47
42
  return webhookDataSchema.parse(verification.payload);
48
-
49
- });
43
+ };
50
44
  };