@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.
@@ -7,13 +7,13 @@ export const authHeaders = (token) => {
7
7
  }
8
8
  : undefined;
9
9
  };
10
- export const authenticatedCoreApiClient = (token) => { var _a; return fetchClient(Object.assign(Object.assign({}, apiClientConfig), { headers: (_a = authHeaders(token)) !== null && _a !== void 0 ? _a : {} })); };
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 Object.assign(Object.assign({}, (await r.json())), { status: r.status });
16
+ throw { ...(await r.json()), status: r.status };
17
17
  }
18
18
  };
19
19
  export const transformResponse = (r) => r.json();
@@ -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 Object.assign(Object.assign({}, (await response.json())), { status: response.status });
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 Object.assign(Object.assign({}, (await response.json())), { status: response.status });
80
+ throw { ...(await response.json()), status: response.status };
81
81
  }
82
82
  return response.text();
83
83
  },
@@ -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 Object.assign(Object.assign({}, (await response.json())), { status: response.status });
21
+ throw { ...(await response.json()), status: response.status };
22
22
  }
23
23
  return response.text();
24
24
  },
@@ -47,7 +47,11 @@ const postFeeds = (rawClient) => ({
47
47
  local: allpeepNoPayloadEndpoint(rawClient, '/posts/feeds/local'),
48
48
  });
49
49
  const feeds = (rawClient) => ({
50
- feeds: Object.assign(Object.assign(Object.assign({}, postFeeds(rawClient)), eventFeeds(rawClient)), jamFeeds(rawClient)),
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) => (Object.assign(Object.assign(Object.assign({}, finders(rawClient)), mutators(rawClient)), feeds(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
- var _a;
25
- return ({
26
- baseUrl: ((_a = options === null || options === void 0 ? void 0 : options.baseUrl) !== null && _a !== void 0 ? _a : '') + '/api/openpeeps/core/v1',
27
- headers: (options === null || options === void 0 ? void 0 : options.token)
28
- ? {
29
- Authorization: `Bearer ${options.token}`,
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.1.38",
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
- "zod": "^4.4.3",
9
- "@openpeepshq/common": "^0.1.46",
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
- ".": "./dist/index.js",
16
- "./*": "./dist/*/index.js"
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
- "/dist"
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
+ });