@openpeepshq/client 0.1.38 → 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/common/authenticated.js +2 -2
- package/dist/endpoints/admin.js +2 -2
- package/dist/endpoints/jams.js +1 -1
- package/dist/endpoints/posts.js +10 -2
- package/dist/endpoints/server.d.ts +1 -0
- package/dist/index.js +8 -11
- package/package.json +30 -9
- package/src/common/authenticated.ts +28 -0
- package/src/common/base.ts +11 -0
- package/src/endpoints/accounts.ts +52 -0
- package/src/endpoints/admin.ts +616 -0
- package/src/endpoints/analytics.ts +13 -0
- package/src/endpoints/auth.ts +43 -0
- package/src/endpoints/conversations.ts +28 -0
- package/src/endpoints/groups.ts +69 -0
- package/src/endpoints/helpers.ts +91 -0
- package/src/endpoints/i18n.ts +14 -0
- package/src/endpoints/jams.ts +126 -0
- package/src/endpoints/location.ts +10 -0
- package/src/endpoints/media.ts +56 -0
- package/src/endpoints/payments.ts +34 -0
- package/src/endpoints/plugins.ts +25 -0
- package/src/endpoints/posts.ts +377 -0
- package/src/endpoints/previewLink.ts +10 -0
- package/src/endpoints/profiles.ts +167 -0
- package/src/endpoints/reports.ts +32 -0
- package/src/endpoints/search.ts +34 -0
- package/src/endpoints/server.ts +38 -0
- package/src/endpoints/sso.ts +35 -0
- package/src/endpoints/streaming.ts +29 -0
- package/src/endpoints/types.ts +66 -0
- package/src/index.ts +88 -0
- package/src/types/index.ts +20 -0
- package/src/webhooks/index.ts +50 -0
|
@@ -7,13 +7,13 @@ export const authHeaders = (token) => {
|
|
|
7
7
|
}
|
|
8
8
|
: undefined;
|
|
9
9
|
};
|
|
10
|
-
export const authenticatedCoreApiClient = (token) =>
|
|
10
|
+
export const authenticatedCoreApiClient = (token) => fetchClient({ ...apiClientConfig, headers: authHeaders(token) ?? {} });
|
|
11
11
|
export const handleError = async (r) => {
|
|
12
12
|
if (r.ok) {
|
|
13
13
|
return r;
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
16
|
-
throw
|
|
16
|
+
throw { ...(await r.json()), status: r.status };
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
export const transformResponse = (r) => r.json();
|
package/dist/endpoints/admin.js
CHANGED
|
@@ -49,7 +49,7 @@ export const admin = (rawClient) => ({
|
|
|
49
49
|
const path = `/admin/db/tables/${encodeURIComponent(table)}/export${qs ? `?${qs}` : ''}`;
|
|
50
50
|
const response = await rawClient.get(path);
|
|
51
51
|
if (!response.ok) {
|
|
52
|
-
throw
|
|
52
|
+
throw { ...(await response.json()), status: response.status };
|
|
53
53
|
}
|
|
54
54
|
return response.text();
|
|
55
55
|
},
|
|
@@ -77,7 +77,7 @@ export const admin = (rawClient) => ({
|
|
|
77
77
|
exportCsv: async () => {
|
|
78
78
|
const response = await rawClient.get('/admin/profiles/export');
|
|
79
79
|
if (!response.ok) {
|
|
80
|
-
throw
|
|
80
|
+
throw { ...(await response.json()), status: response.status };
|
|
81
81
|
}
|
|
82
82
|
return response.text();
|
|
83
83
|
},
|
package/dist/endpoints/jams.js
CHANGED
|
@@ -18,7 +18,7 @@ export const jams = (rawClient, eventSource) => {
|
|
|
18
18
|
exportAttendance: async ({ id }) => {
|
|
19
19
|
const response = await rawClient.get(`/jams/${id}/events/attendance/export`);
|
|
20
20
|
if (!response.ok) {
|
|
21
|
-
throw
|
|
21
|
+
throw { ...(await response.json()), status: response.status };
|
|
22
22
|
}
|
|
23
23
|
return response.text();
|
|
24
24
|
},
|
package/dist/endpoints/posts.js
CHANGED
|
@@ -47,7 +47,11 @@ const postFeeds = (rawClient) => ({
|
|
|
47
47
|
local: allpeepNoPayloadEndpoint(rawClient, '/posts/feeds/local'),
|
|
48
48
|
});
|
|
49
49
|
const feeds = (rawClient) => ({
|
|
50
|
-
feeds:
|
|
50
|
+
feeds: {
|
|
51
|
+
...postFeeds(rawClient),
|
|
52
|
+
...eventFeeds(rawClient),
|
|
53
|
+
...jamFeeds(rawClient),
|
|
54
|
+
},
|
|
51
55
|
});
|
|
52
56
|
const mutators = (rawClient) => ({
|
|
53
57
|
create: allpeepPayloadEndpoint(rawClient, '/posts'),
|
|
@@ -64,4 +68,8 @@ const mutators = (rawClient) => ({
|
|
|
64
68
|
rsvp: allpeepPayloadEndpoint(rawClient, '/posts/:id/rsvp', 'post'),
|
|
65
69
|
rsvpManage: allpeepPayloadEndpoint(rawClient, '/posts/:id/rsvp/:profileId', 'post'),
|
|
66
70
|
});
|
|
67
|
-
export const posts = (rawClient) => (
|
|
71
|
+
export const posts = (rawClient) => ({
|
|
72
|
+
...finders(rawClient),
|
|
73
|
+
...mutators(rawClient),
|
|
74
|
+
...feeds(rawClient),
|
|
75
|
+
});
|
|
@@ -68,6 +68,7 @@ export declare const server: (rawClient: FetchClient) => {
|
|
|
68
68
|
defaultLanguage?: string | undefined;
|
|
69
69
|
defaultTimeZone?: string | undefined;
|
|
70
70
|
defaultFeedFormat?: "threaded" | "linear" | undefined;
|
|
71
|
+
indexProfiles?: boolean | undefined;
|
|
71
72
|
};
|
|
72
73
|
roles: {
|
|
73
74
|
onRegistration: {
|
package/dist/index.js
CHANGED
|
@@ -20,17 +20,14 @@ import { previewLink } from './endpoints/previewLink.js';
|
|
|
20
20
|
import { payments } from './endpoints/payments.js';
|
|
21
21
|
import { streaming } from './endpoints/streaming.js';
|
|
22
22
|
import { webhookHandler } from './webhooks/index.js';
|
|
23
|
-
const allPeepClientOptionsToClientConfig = (options) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
: undefined,
|
|
32
|
-
});
|
|
33
|
-
};
|
|
23
|
+
const allPeepClientOptionsToClientConfig = (options) => ({
|
|
24
|
+
baseUrl: (options?.baseUrl ?? '') + '/api/openpeeps/core/v1',
|
|
25
|
+
headers: options?.token
|
|
26
|
+
? {
|
|
27
|
+
Authorization: `Bearer ${options.token}`,
|
|
28
|
+
}
|
|
29
|
+
: undefined,
|
|
30
|
+
});
|
|
34
31
|
export const openpeepsClient = (options) => {
|
|
35
32
|
const config = typeof options === 'function'
|
|
36
33
|
? async () => allPeepClientOptionsToClientConfig(await options())
|
package/package.json
CHANGED
|
@@ -1,24 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
6
7
|
"dependencies": {
|
|
7
8
|
"validator": "^13.11.0",
|
|
8
|
-
"
|
|
9
|
-
"@openpeepshq/
|
|
10
|
-
"@openpeepshq/fetch-client": "^0.1.7"
|
|
9
|
+
"@openpeepshq/common": "^0.2.0",
|
|
10
|
+
"@openpeepshq/fetch-client": "^0.2.0"
|
|
11
11
|
},
|
|
12
|
-
"main": "dist/index.js",
|
|
13
|
-
"types": "dist/index.d.ts",
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
14
|
"exports": {
|
|
15
|
-
".":
|
|
16
|
-
|
|
15
|
+
".": {
|
|
16
|
+
"react-native": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./src/index.ts"
|
|
19
|
+
},
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"node": "./dist/index.js",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./*": {
|
|
25
|
+
"react-native": {
|
|
26
|
+
"types": "./dist/*/index.d.ts",
|
|
27
|
+
"default": "./src/*/index.ts"
|
|
28
|
+
},
|
|
29
|
+
"types": "./dist/*/index.d.ts",
|
|
30
|
+
"node": "./dist/*/index.js",
|
|
31
|
+
"default": "./dist/*/index.js"
|
|
32
|
+
}
|
|
17
33
|
},
|
|
18
34
|
"files": [
|
|
19
|
-
"
|
|
35
|
+
"src",
|
|
36
|
+
"dist",
|
|
37
|
+
"!**/__tests__",
|
|
38
|
+
"!**/*.test.ts"
|
|
20
39
|
],
|
|
21
40
|
"devDependencies": {
|
|
41
|
+
"@types/node": "^22.14.1",
|
|
22
42
|
"@types/validator": "^13.11.9",
|
|
23
43
|
"@typescript-eslint/eslint-plugin": "^8.19.0",
|
|
24
44
|
"@typescript-eslint/parser": "^8.19.0",
|
|
@@ -34,6 +54,7 @@
|
|
|
34
54
|
"lint": "prettier --check . && ESLINT_USE_FLAT_CONFIG=false eslint .",
|
|
35
55
|
"format": "prettier --write .",
|
|
36
56
|
"clean": "rm -rf tsconfig.tsbuildinfo dist",
|
|
57
|
+
"typecheck": "tsc --noEmit",
|
|
37
58
|
"build": "tsc && tsc-alias",
|
|
38
59
|
"build:watch": "tsc && tsc-alias && (concurrently \"tsc -w\" \"tsc-alias -w\")"
|
|
39
60
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { fetchClient, type FetchClient } from '@openpeepshq/fetch-client';
|
|
2
|
+
import { apiClientConfig } from './base';
|
|
3
|
+
|
|
4
|
+
export const authHeaders = (token: string) => {
|
|
5
|
+
return token
|
|
6
|
+
? {
|
|
7
|
+
Authorization: `Bearer ${token}`,
|
|
8
|
+
}
|
|
9
|
+
: undefined;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const authenticatedCoreApiClient = (token: string): FetchClient =>
|
|
13
|
+
fetchClient({ ...apiClientConfig, headers: authHeaders(token) ?? {} });
|
|
14
|
+
|
|
15
|
+
export const handleError = async (r: Response) => {
|
|
16
|
+
if (r.ok) {
|
|
17
|
+
return r;
|
|
18
|
+
} else {
|
|
19
|
+
throw { ...(await r.json()), status: r.status };
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const transformResponse = (r: Response) => r.json();
|
|
24
|
+
|
|
25
|
+
export const handleFetchResult = async (r: Response) => {
|
|
26
|
+
await handleError(r);
|
|
27
|
+
return transformResponse(r);
|
|
28
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ClientConfig,
|
|
3
|
+
fetchClient,
|
|
4
|
+
type FetchClient,
|
|
5
|
+
} from '@openpeepshq/fetch-client';
|
|
6
|
+
|
|
7
|
+
export const apiClientConfig: ClientConfig = {
|
|
8
|
+
baseUrl: '/api/openpeeps/core/v1',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const coreApiClient = (): FetchClient => fetchClient(apiClientConfig);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { FetchClient } from '@openpeepshq/fetch-client';
|
|
2
|
+
import type {
|
|
3
|
+
AccountExport,
|
|
4
|
+
PublicAccount,
|
|
5
|
+
PushSubscription,
|
|
6
|
+
PushSubscriptionData,
|
|
7
|
+
SuccessResponse,
|
|
8
|
+
UpdateAccountPasswordRequest,
|
|
9
|
+
} from '@openpeepshq/common';
|
|
10
|
+
import { allpeepNoPayloadEndpoint, allpeepPayloadEndpoint } from './helpers';
|
|
11
|
+
|
|
12
|
+
export const accounts = (rawClient: FetchClient) => ({
|
|
13
|
+
current: {
|
|
14
|
+
update: allpeepPayloadEndpoint<
|
|
15
|
+
SuccessResponse,
|
|
16
|
+
UpdateAccountPasswordRequest
|
|
17
|
+
>(rawClient, '/accounts/current', 'patch'),
|
|
18
|
+
read: allpeepNoPayloadEndpoint<PublicAccount>(
|
|
19
|
+
rawClient,
|
|
20
|
+
'/accounts/current',
|
|
21
|
+
),
|
|
22
|
+
export: allpeepNoPayloadEndpoint<AccountExport>(
|
|
23
|
+
rawClient,
|
|
24
|
+
'/accounts/current/export',
|
|
25
|
+
),
|
|
26
|
+
createPushSubscription: allpeepPayloadEndpoint<
|
|
27
|
+
PushSubscription,
|
|
28
|
+
PushSubscriptionData
|
|
29
|
+
>(rawClient, '/accounts/current/push-subscriptions'),
|
|
30
|
+
listPushSubscriptions: allpeepNoPayloadEndpoint<PushSubscription[]>(
|
|
31
|
+
rawClient,
|
|
32
|
+
'/accounts/current/push-subscriptions',
|
|
33
|
+
),
|
|
34
|
+
testPushSubscription: allpeepPayloadEndpoint<
|
|
35
|
+
SuccessResponse,
|
|
36
|
+
{ subscriptionKey: string }
|
|
37
|
+
>(rawClient, '/accounts/current/push-subscriptions/test'),
|
|
38
|
+
validationEmail: allpeepNoPayloadEndpoint<SuccessResponse>(
|
|
39
|
+
rawClient,
|
|
40
|
+
'/accounts/current/validation-email',
|
|
41
|
+
'post',
|
|
42
|
+
),
|
|
43
|
+
deletePushSubcription: allpeepNoPayloadEndpoint<
|
|
44
|
+
SuccessResponse,
|
|
45
|
+
{ pushSubscriptionId: string }
|
|
46
|
+
>(
|
|
47
|
+
rawClient,
|
|
48
|
+
'/accounts/current/push-subscriptions/:pushSubscriptionId',
|
|
49
|
+
'delete',
|
|
50
|
+
),
|
|
51
|
+
},
|
|
52
|
+
});
|