@productcraft/social 0.1.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/LICENSE +21 -0
- package/README.md +199 -0
- package/dist/index.cjs +16 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +11122 -0
- package/dist/index.d.ts +11122 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ProductCraft
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# @productcraft/social
|
|
2
|
+
|
|
3
|
+
Typed Node.js SDK for [ProductCraft Social](https://productcraft.co) — social-as-a-service backend: communities, posts, ranked feeds, stories (with polls + close-friends), direct conversations, notifications, moderation, flags. Generic actor / object / edge primitives.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @productcraft/social
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Server-side only. Customer-facing apps integrate via a backend (BFF pattern) that holds the workspace PAK (`pcft_live_…`).
|
|
10
|
+
|
|
11
|
+
## Two caller contexts
|
|
12
|
+
|
|
13
|
+
Social's surface splits two ways — both reach the same data but differ in auth + URL shape:
|
|
14
|
+
|
|
15
|
+
| Caller | URL prefix | Auth | What you do |
|
|
16
|
+
|---|---|---|---|
|
|
17
|
+
| **PlatformUser admin** | `/v1/workspaces/{workspaceId}/...` | cookie or PAK | Create communities, run moderation, read analytics. |
|
|
18
|
+
| **Customer backend** | `/v1/communities/{communityId}/...` | PAK + `X-Acting-As: <actor_id>` header | Day-to-day reads/writes on behalf of an EndUser. |
|
|
19
|
+
|
|
20
|
+
The customer backend acts on behalf of one of its EndUsers via the `X-Acting-As` header — the SDK passes whatever you put in headers straight through, so a per-request wrapper that injects the acting actor id is idiomatic.
|
|
21
|
+
|
|
22
|
+
## Quick start — create a community (admin)
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { Social } from "@productcraft/social";
|
|
26
|
+
|
|
27
|
+
const social = new Social({
|
|
28
|
+
auth: { type: "apiKey", key: process.env.PCFT_KEY! },
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const { data, error } = await social.client.POST(
|
|
32
|
+
"/v1/workspaces/{workspaceId}/communities",
|
|
33
|
+
{
|
|
34
|
+
params: { path: { workspaceId: "<workspace-uuid>" } },
|
|
35
|
+
body: { display_name: "Founders Club", slug: "founders" },
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quick start — post on behalf of an EndUser (customer backend)
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
const actor_id = "<actor-uuid>"; // the EndUser's Social actor id
|
|
44
|
+
|
|
45
|
+
const { data, error } = await social.client.POST(
|
|
46
|
+
"/v1/communities/{communityId}/posts",
|
|
47
|
+
{
|
|
48
|
+
params: {
|
|
49
|
+
path: { communityId: "<community-uuid>" },
|
|
50
|
+
header: { "X-Acting-As": actor_id },
|
|
51
|
+
},
|
|
52
|
+
body: {
|
|
53
|
+
// `actor_id` is required in the body too — the header sets caller
|
|
54
|
+
// identity; the body field is the author of the post (typically
|
|
55
|
+
// the same UUID, but allowed to differ on admin-impersonation flows).
|
|
56
|
+
actor_id,
|
|
57
|
+
text: "Hello, world!",
|
|
58
|
+
visibility: "public",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Social's wire is snake_case both at the DTO level and in TS types — there's no name translation layer for this surface. Use snake_case keys in `body` to match what the API actually accepts.
|
|
65
|
+
|
|
66
|
+
## Configuration
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
new Social({
|
|
70
|
+
auth: { type: "apiKey", key: "pcft_live_..." }
|
|
71
|
+
| { type: "bearer", token: "eyJ..." }
|
|
72
|
+
| { type: "cookie", value: "auth_token=..." },
|
|
73
|
+
baseUrl: "https://social.example.test", // optional override
|
|
74
|
+
fetch: customFetch, // optional
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Common operations
|
|
79
|
+
|
|
80
|
+
### Posts + feeds
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
// Create a post
|
|
84
|
+
await social.client.POST(
|
|
85
|
+
"/v1/communities/{communityId}/posts",
|
|
86
|
+
{ params: { path: { communityId } }, body: { text: "..." } },
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
// Get the actor's ranked home feed
|
|
90
|
+
await social.client.GET(
|
|
91
|
+
"/v1/communities/{communityId}/actors/{actorId}/feed",
|
|
92
|
+
{ params: { path: { communityId, actorId } } },
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
// Discover (community-wide ranked feed, not personalised to follows)
|
|
96
|
+
await social.client.GET(
|
|
97
|
+
"/v1/communities/{communityId}/discover-feed",
|
|
98
|
+
{ params: { path: { communityId } } },
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
// React / unreact / bookmark / quote / repost — same shape, different paths
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Stories
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
// Post a story (24h TTL)
|
|
108
|
+
await social.client.POST(
|
|
109
|
+
"/v1/communities/{communityId}/stories",
|
|
110
|
+
{ params: { ... }, body: { media_url: "...", visibility: "close_friends" } },
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
// Story tray (the bubble row at the top of the home screen)
|
|
114
|
+
await social.client.GET(
|
|
115
|
+
"/v1/communities/{communityId}/actors/{actorId}/story-tray",
|
|
116
|
+
{ ... },
|
|
117
|
+
);
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Social graph
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
// Follow / unfollow
|
|
124
|
+
await social.client.PUT(
|
|
125
|
+
"/v1/communities/{communityId}/follows/{srcActorId}/{dstActorId}",
|
|
126
|
+
{ ... },
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
// Block / mute / restrict — same shape, different paths
|
|
130
|
+
// Close friends, hashtag follows, muted terms — all under /actors/{actorId}/...
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Notifications
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
// List
|
|
137
|
+
await social.client.GET(
|
|
138
|
+
"/v1/communities/{communityId}/actors/{actorId}/notifications",
|
|
139
|
+
{ ... },
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
// Unread count for the bell badge
|
|
143
|
+
await social.client.GET(
|
|
144
|
+
"/v1/communities/{communityId}/actors/{actorId}/notifications/unread-count",
|
|
145
|
+
{ ... },
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
// Mark all read
|
|
149
|
+
await social.client.POST(
|
|
150
|
+
"/v1/communities/{communityId}/actors/{actorId}/notifications/read-all",
|
|
151
|
+
{ ... },
|
|
152
|
+
);
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Direct conversations
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
// Start / open a conversation
|
|
159
|
+
await social.client.POST(
|
|
160
|
+
"/v1/communities/{communityId}/conversations",
|
|
161
|
+
{ params: { ... }, body: { members: ["act_a", "act_b"] } },
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
// Send a message
|
|
165
|
+
await social.client.POST(
|
|
166
|
+
"/v1/communities/{communityId}/conversations/{conversationId}/messages",
|
|
167
|
+
{ ... },
|
|
168
|
+
);
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Moderation (workspace admin)
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
// List flags
|
|
175
|
+
await social.client.GET(
|
|
176
|
+
"/v1/workspaces/{workspaceId}/communities/{communityId}/moderation/flags",
|
|
177
|
+
{ ... },
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
// Act on a flag (resolve / dismiss / take action on the target)
|
|
181
|
+
await social.client.POST(
|
|
182
|
+
"/v1/workspaces/{workspaceId}/communities/{communityId}/moderation/flags/{flagId}/actions",
|
|
183
|
+
{ params: { ... }, body: { action: "remove_content", note: "..." } },
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
// Shadow-ban an actor
|
|
187
|
+
await social.client.PUT(
|
|
188
|
+
"/v1/workspaces/{workspaceId}/communities/{communityId}/moderation/actors/{actorId}/shadow-ban",
|
|
189
|
+
{ ... },
|
|
190
|
+
);
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## How this SDK is built
|
|
194
|
+
|
|
195
|
+
Generated from the live OpenAPI spec at `https://social.productcraft.co/docs-json` via [`openapi-typescript`](https://openapi-ts.dev/) + [`openapi-fetch`](https://openapi-ts.dev/openapi-fetch/). The nightly `spec-refresh` workflow opens a PR whenever the spec changes.
|
|
196
|
+
|
|
197
|
+
## License
|
|
198
|
+
|
|
199
|
+
[MIT](https://github.com/clauderanelagh/productcraft-node/blob/main/LICENSE).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@productcraft/core');
|
|
4
|
+
|
|
5
|
+
// src/index.ts
|
|
6
|
+
var Social = class {
|
|
7
|
+
/** The underlying typed client. v0 surface — every endpoint reachable. */
|
|
8
|
+
client;
|
|
9
|
+
constructor(config = {}) {
|
|
10
|
+
this.client = core.makeClient(core.PC_BASE_URL.social, config);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
exports.Social = Social;
|
|
15
|
+
//# sourceMappingURL=index.cjs.map
|
|
16
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["makeClient","PC_BASE_URL"],"mappings":";;;;;AASO,IAAM,SAAN,MAAa;AAAA;AAAA,EAEF,MAAA;AAAA,EAEhB,WAAA,CAAY,MAAA,GAAyB,EAAC,EAAG;AACvC,IAAA,IAAA,CAAK,MAAA,GAASA,eAAA,CAAkBC,gBAAA,CAAY,MAAA,EAAQ,MAAM,CAAA;AAAA,EAC5D;AACF","file":"index.cjs","sourcesContent":["import type { paths } from \"./_generated.js\";\nimport { makeClient, PC_BASE_URL, type PCClientConfig } from \"@productcraft/core\";\n\n/**\n * Social — typed `openapi-fetch` client for every endpoint in\n * `Specs/social.json`. Reach for `client.GET(\"/v1/...\")` or\n * `client.POST(...)`; request / response types come from the\n * generated `paths` interface.\n */\nexport class Social {\n /** The underlying typed client. v0 surface — every endpoint reachable. */\n public readonly client: ReturnType<typeof makeClient<paths>>;\n\n constructor(config: PCClientConfig = {}) {\n this.client = makeClient<paths>(PC_BASE_URL.social, config);\n }\n}\n\nexport type { paths } from \"./_generated.js\";\n"]}
|