@venturekit-pro/social 0.0.0-dev.20260602192622

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.
Files changed (53) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +134 -0
  3. package/dist/adapter.d.ts +46 -0
  4. package/dist/adapter.d.ts.map +1 -0
  5. package/dist/adapter.js +15 -0
  6. package/dist/adapter.js.map +1 -0
  7. package/dist/adapters/facebook.d.ts +25 -0
  8. package/dist/adapters/facebook.d.ts.map +1 -0
  9. package/dist/adapters/facebook.js +95 -0
  10. package/dist/adapters/facebook.js.map +1 -0
  11. package/dist/adapters/index.d.ts +23 -0
  12. package/dist/adapters/index.d.ts.map +1 -0
  13. package/dist/adapters/index.js +19 -0
  14. package/dist/adapters/index.js.map +1 -0
  15. package/dist/adapters/instagram.d.ts +25 -0
  16. package/dist/adapters/instagram.d.ts.map +1 -0
  17. package/dist/adapters/instagram.js +113 -0
  18. package/dist/adapters/instagram.js.map +1 -0
  19. package/dist/adapters/linkedin.d.ts +28 -0
  20. package/dist/adapters/linkedin.d.ts.map +1 -0
  21. package/dist/adapters/linkedin.js +121 -0
  22. package/dist/adapters/linkedin.js.map +1 -0
  23. package/dist/adapters/x.d.ts +21 -0
  24. package/dist/adapters/x.d.ts.map +1 -0
  25. package/dist/adapters/x.js +80 -0
  26. package/dist/adapters/x.js.map +1 -0
  27. package/dist/http.d.ts +40 -0
  28. package/dist/http.d.ts.map +1 -0
  29. package/dist/http.js +127 -0
  30. package/dist/http.js.map +1 -0
  31. package/dist/index.d.ts +28 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +27 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/migrations/vk_social_0001_init.sql +121 -0
  36. package/dist/path.d.ts +9 -0
  37. package/dist/path.d.ts.map +1 -0
  38. package/dist/path.js +17 -0
  39. package/dist/path.js.map +1 -0
  40. package/dist/registry.d.ts +32 -0
  41. package/dist/registry.d.ts.map +1 -0
  42. package/dist/registry.js +42 -0
  43. package/dist/registry.js.map +1 -0
  44. package/dist/types.d.ts +229 -0
  45. package/dist/types.d.ts.map +1 -0
  46. package/dist/types.js +57 -0
  47. package/dist/types.js.map +1 -0
  48. package/dist/validation.d.ts +17 -0
  49. package/dist/validation.d.ts.map +1 -0
  50. package/dist/validation.js +157 -0
  51. package/dist/validation.js.map +1 -0
  52. package/package.json +78 -0
  53. package/src/migrations/vk_social_0001_init.sql +121 -0
package/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to the Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by the Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding any notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2025 VentureKit Contributors
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,134 @@
1
+ # @venturekit-pro/social
2
+
3
+ Generic social-platform publishing adapters + tenant catalog for VentureKit
4
+ applications.
5
+
6
+ **Domain-neutral.** This package knows about platforms, posts, media,
7
+ OAuth credentials, validation, and publishing. It does **not** know about
8
+ cadence, fan-out, AI generation, angles, blog↔social linkage, or any other
9
+ calling-app concept. Apps compose those on top.
10
+
11
+ ## What it gives you
12
+
13
+ - **One canonical adapter contract** — `SocialAdapter` with `validate()` +
14
+ `publish()` and optional `verify()` + `parseWebhook()`.
15
+ - **Four v1 adapters** — LinkedIn (UGC Posts), X (v2 Tweets), Facebook
16
+ (Pages Graph), Instagram (Content Publishing). All factory-constructed,
17
+ stateless, served from one instance per process.
18
+ - **`social_platforms` catalog** — a database row per supported platform
19
+ (seeded by the package's migration), plus a thin per-tenant
20
+ `tenant_social_platforms` table for enable/disable + author-ref pairing.
21
+ - **Typed errors** — `SocialAuthError` / `SocialRateLimitError` /
22
+ `SocialValidationError` / `SocialPublishError` so callers can build
23
+ retry policies that match the failure mode.
24
+ - **Pre-publish validation** — `validatePost()` enforces per-platform
25
+ body / hashtag / media constraints and surfaces both errors and warnings.
26
+
27
+ ## Wire-up
28
+
29
+ ```ts
30
+ // In your project's vk.config.ts:
31
+ import { getSocialMigrationsDir } from '@venturekit-pro/social';
32
+
33
+ export default defineVenture({
34
+ extraMigrationsDirs: [getSocialMigrationsDir()],
35
+ });
36
+ ```
37
+
38
+ `vk migrate` runs `vk_social_0001_init.sql` alongside your project's own
39
+ migrations.
40
+
41
+ ## Building the registry
42
+
43
+ ```ts
44
+ import {
45
+ createAdapterRegistry,
46
+ createLinkedInAdapter,
47
+ createXAdapter,
48
+ createFacebookAdapter,
49
+ createInstagramAdapter,
50
+ } from '@venturekit-pro/social';
51
+
52
+ export const socialRegistry = createAdapterRegistry([
53
+ createLinkedInAdapter(),
54
+ createXAdapter(),
55
+ createFacebookAdapter(),
56
+ createInstagramAdapter(),
57
+ ]);
58
+ ```
59
+
60
+ ## Validate + publish
61
+
62
+ ```ts
63
+ import { socialRegistry } from './social';
64
+
65
+ const adapter = socialRegistry.resolve('linkedin');
66
+
67
+ const validation = adapter.validate(post);
68
+ if (!validation.ok) {
69
+ throw new Error(validation.issues.map(i => i.message).join('; '));
70
+ }
71
+
72
+ try {
73
+ const result = await adapter.publish(post, credentials);
74
+ // result.externalRef, result.publishedUrl, result.publishedAt
75
+ } catch (err) {
76
+ if (err instanceof SocialRateLimitError) {
77
+ // back off using err.retryAfterSeconds
78
+ } else if (err instanceof SocialAuthError) {
79
+ // refresh credentials and retry
80
+ } else if (err instanceof SocialValidationError) {
81
+ // platform rejected the body — show err.message to the editor
82
+ } else if (err instanceof SocialPublishError) {
83
+ // transient or unexpected — retry with backoff
84
+ }
85
+ }
86
+ ```
87
+
88
+ ## OAuth credentials
89
+
90
+ The package never reads or writes credentials — the caller fetches the
91
+ `{accessToken, refreshToken?, expiresAt?, authorRef}` pair from its own
92
+ secret store (the CMS uses KMS-encrypted-in-DB jsonb on `tenants.secrets`)
93
+ and passes it per call.
94
+
95
+ `authorRef` carries the platform-side target id:
96
+
97
+ | Platform | `authorRef` example |
98
+ |------------|--------------------------------------|
99
+ | LinkedIn | `urn:li:organization:12345` |
100
+ | X | the user/page handle |
101
+ | Facebook | `page_12345` |
102
+ | Instagram | `ig_user_17841412345` |
103
+
104
+ ## Media staging
105
+
106
+ Image upload is **caller-side**: the package treats `SocialMedia.url` as
107
+ an opaque platform reference. For LinkedIn / X the caller stages the
108
+ upload via the platform's pre-upload endpoint and passes the resulting
109
+ URN / `media_id_string` as `url`. For Facebook / Instagram the package
110
+ calls Meta's `/photos` or `/media` endpoint with a public image URL
111
+ directly.
112
+
113
+ The CMS handles staging in its own pre-publish workflow.
114
+
115
+ ## Extending with a custom platform
116
+
117
+ Add a row to `social_platforms` (any tenant-admin-owned migration of yours)
118
+ and register a custom adapter:
119
+
120
+ ```ts
121
+ const mastodonAdapter: SocialAdapter = {
122
+ key: 'mastodon',
123
+ displayName: 'Mastodon',
124
+ constraints: { /* … */ },
125
+ validate(post) { /* … */ },
126
+ async publish(post, credentials) { /* … */ },
127
+ };
128
+
129
+ const registry = createAdapterRegistry([
130
+ createLinkedInAdapter(),
131
+ // …
132
+ mastodonAdapter,
133
+ ]);
134
+ ```
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Adapter contract.
3
+ *
4
+ * One adapter implementation per supported `SocialPlatformKey`. The
5
+ * package ships four (linkedin, x, facebook, instagram); apps with
6
+ * a custom platform register their own.
7
+ *
8
+ * **Pure functional contract**: an adapter is a stateless object
9
+ * holding only constants (constraints + endpoint base URLs). All
10
+ * per-call state lives in the `OAuthCredentials` + `SocialPost`
11
+ * arguments. This lets one adapter instance serve every tenant in
12
+ * the process — no per-tenant client pool needed.
13
+ */
14
+ import type { OAuthCredentials, PublishResult, SocialPlatformConstraints, SocialPlatformKey, SocialPost, SocialValidationResult, VerifyResult, WebhookEvent } from './types.js';
15
+ export interface SocialAdapter {
16
+ /** Platform key matching the `social_platforms.key` column. */
17
+ readonly key: SocialPlatformKey;
18
+ /** Human-readable platform name used in error messages + logs. */
19
+ readonly displayName: string;
20
+ /** Default per-post constraints; the adapter exposes them so the UI can render hints + counters. */
21
+ readonly constraints: SocialPlatformConstraints;
22
+ /**
23
+ * Pre-publish validation. Pure, no network. Returns errors AND
24
+ * warnings; callers MUST block on `severity === 'error'`.
25
+ */
26
+ validate(post: SocialPost): SocialValidationResult;
27
+ /**
28
+ * Publish to the platform. Throws `SocialAuthError` on 401/403,
29
+ * `SocialRateLimitError` on 429 (with retry-after), and
30
+ * `SocialPublishError` for everything else.
31
+ */
32
+ publish(post: SocialPost, credentials: OAuthCredentials): Promise<PublishResult>;
33
+ /**
34
+ * Optional status check. Most platforms don't expose this; the
35
+ * caller treats `undefined` as "verification not available, assume
36
+ * status from publish response".
37
+ */
38
+ verify?(externalRef: string, credentials: OAuthCredentials): Promise<VerifyResult>;
39
+ /**
40
+ * Optional webhook payload classifier. Used by apps that wire a
41
+ * platform's webhooks into their own job queue. Returns `null`
42
+ * when the payload isn't recognized.
43
+ */
44
+ parseWebhook?(payload: unknown, headers: Record<string, string>): WebhookEvent | null;
45
+ }
46
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EACb,yBAAyB,EACzB,iBAAiB,EACjB,UAAU,EACV,sBAAsB,EACtB,YAAY,EACZ,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,aAAa;IAC5B,+DAA+D;IAC/D,QAAQ,CAAC,GAAG,EAAE,iBAAiB,CAAC;IAEhC,kEAAkE;IAClE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B,oGAAoG;IACpG,QAAQ,CAAC,WAAW,EAAE,yBAAyB,CAAC;IAEhD;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,sBAAsB,CAAC;IAEnD;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAEjF;;;;OAIG;IACH,MAAM,CAAC,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAEnF;;;;OAIG;IACH,YAAY,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,GAAG,IAAI,CAAC;CACvF"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Adapter contract.
3
+ *
4
+ * One adapter implementation per supported `SocialPlatformKey`. The
5
+ * package ships four (linkedin, x, facebook, instagram); apps with
6
+ * a custom platform register their own.
7
+ *
8
+ * **Pure functional contract**: an adapter is a stateless object
9
+ * holding only constants (constraints + endpoint base URLs). All
10
+ * per-call state lives in the `OAuthCredentials` + `SocialPost`
11
+ * arguments. This lets one adapter instance serve every tenant in
12
+ * the process — no per-tenant client pool needed.
13
+ */
14
+ export {};
15
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Facebook (Pages) adapter — Meta Graph API.
3
+ *
4
+ * Endpoints:
5
+ * - Text post: `POST /v18.0/<page-id>/feed`
6
+ * - Photo post: `POST /v18.0/<page-id>/photos`
7
+ *
8
+ * Auth: Page access token via `?access_token=…` OR
9
+ * `Authorization: Bearer …`. We use the header form so the
10
+ * token never appears in URLs / logs.
11
+ *
12
+ * `credentials.authorRef` carries the Page id (e.g. `'page_12345'`).
13
+ * We strip the `'page_'` prefix when forming URLs — same convention
14
+ * the Instagram adapter uses.
15
+ */
16
+ import type { SocialAdapter } from '../adapter.js';
17
+ import type { SocialPlatformConstraints } from '../types.js';
18
+ export declare const FACEBOOK_CONSTRAINTS: SocialPlatformConstraints;
19
+ export interface FacebookAdapterConfig {
20
+ baseUrl?: string;
21
+ graphVersion?: string;
22
+ constraints?: Partial<SocialPlatformConstraints>;
23
+ }
24
+ export declare function createFacebookAdapter(config?: FacebookAdapterConfig): SocialAdapter;
25
+ //# sourceMappingURL=facebook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facebook.d.ts","sourceRoot":"","sources":["../../src/adapters/facebook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAIV,yBAAyB,EAE1B,MAAM,aAAa,CAAC;AAOrB,eAAO,MAAM,oBAAoB,EAAE,yBAUlC,CAAC;AAEF,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAC;CAClD;AAED,wBAAgB,qBAAqB,CACnC,MAAM,GAAE,qBAA0B,GACjC,aAAa,CAwDf"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Facebook (Pages) adapter — Meta Graph API.
3
+ *
4
+ * Endpoints:
5
+ * - Text post: `POST /v18.0/<page-id>/feed`
6
+ * - Photo post: `POST /v18.0/<page-id>/photos`
7
+ *
8
+ * Auth: Page access token via `?access_token=…` OR
9
+ * `Authorization: Bearer …`. We use the header form so the
10
+ * token never appears in URLs / logs.
11
+ *
12
+ * `credentials.authorRef` carries the Page id (e.g. `'page_12345'`).
13
+ * We strip the `'page_'` prefix when forming URLs — same convention
14
+ * the Instagram adapter uses.
15
+ */
16
+ import { vendorFetch } from '../http.js';
17
+ import { validatePost } from '../validation.js';
18
+ const META_GRAPH_BASE = 'https://graph.facebook.com';
19
+ const META_GRAPH_VERSION = 'v18.0';
20
+ export const FACEBOOK_CONSTRAINTS = {
21
+ maxBodyChars: 63206, // Meta's published max; 2000 is the recommended ceiling
22
+ minBodyChars: 1,
23
+ minHashtags: 0,
24
+ maxHashtags: 30,
25
+ allowedMimeTypes: ['image/jpeg', 'image/png'],
26
+ maxMediaCount: 1,
27
+ allowedAspectRatios: ['1:1', '4:3', '16:9', '4:5'],
28
+ maxMediaSizeBytes: 10 * 1024 * 1024,
29
+ supportsFirstComment: false,
30
+ };
31
+ export function createFacebookAdapter(config = {}) {
32
+ const baseUrl = (config.baseUrl ?? META_GRAPH_BASE).replace(/\/+$/, '');
33
+ const version = config.graphVersion ?? META_GRAPH_VERSION;
34
+ const constraints = {
35
+ ...FACEBOOK_CONSTRAINTS,
36
+ ...config.constraints,
37
+ };
38
+ return {
39
+ key: 'facebook',
40
+ displayName: 'Facebook',
41
+ constraints,
42
+ validate(post) {
43
+ return validatePost(post, constraints);
44
+ },
45
+ async publish(post, credentials) {
46
+ const pageId = stripPagePrefix(credentials.authorRef);
47
+ const hasMedia = (post.media?.length ?? 0) > 0;
48
+ const endpoint = hasMedia
49
+ ? `/${version}/${encodeURIComponent(pageId)}/photos`
50
+ : `/${version}/${encodeURIComponent(pageId)}/feed`;
51
+ const body = buildFeedBody(post, hasMedia);
52
+ const res = await vendorFetch('facebook', `${baseUrl}${endpoint}`, {
53
+ method: 'POST',
54
+ headers: {
55
+ Authorization: `Bearer ${credentials.accessToken}`,
56
+ 'Content-Type': 'application/json',
57
+ },
58
+ body: JSON.stringify(body),
59
+ });
60
+ const json = res.body;
61
+ const externalRef = json?.post_id ?? json?.id;
62
+ if (!externalRef) {
63
+ throw new Error('[social/facebook] Publish returned no id; vendor body: ' + res.bodyText.slice(0, 200));
64
+ }
65
+ // Public URL form: facebook.com/<pageId>/posts/<postRef> (Meta
66
+ // composes a more user-friendly canonical URL behind the
67
+ // scenes, but the raw form always works).
68
+ return {
69
+ externalRef,
70
+ publishedUrl: `https://www.facebook.com/${encodeURIComponent(externalRef)}`,
71
+ publishedAt: new Date().toISOString(),
72
+ idempotencyKey: post.idempotencyKey,
73
+ correlationId: post.correlationId,
74
+ raw: json,
75
+ };
76
+ },
77
+ };
78
+ }
79
+ function stripPagePrefix(authorRef) {
80
+ return authorRef.startsWith('page_') ? authorRef.slice(5) : authorRef;
81
+ }
82
+ function buildFeedBody(post, hasMedia) {
83
+ const body = { message: post.body };
84
+ if (post.link && !hasMedia) {
85
+ body.link = post.link;
86
+ }
87
+ if (hasMedia && post.media?.[0]) {
88
+ // For /<page-id>/photos, the `url` field carries the public
89
+ // image URL. Meta fetches it server-side. We pass through the
90
+ // post's first media URL verbatim.
91
+ body.url = post.media[0].url;
92
+ }
93
+ return body;
94
+ }
95
+ //# sourceMappingURL=facebook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facebook.js","sourceRoot":"","sources":["../../src/adapters/facebook.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * V1 adapters — one factory function per supported platform.
3
+ *
4
+ * Apps construct what they need and feed the array to
5
+ * `createAdapterRegistry()`. The factories are deliberately
6
+ * argument-less for the default case so a CMS can do:
7
+ *
8
+ * const registry = createAdapterRegistry([
9
+ * createLinkedInAdapter(),
10
+ * createXAdapter(),
11
+ * createFacebookAdapter(),
12
+ * createInstagramAdapter(),
13
+ * ]);
14
+ */
15
+ export { createLinkedInAdapter, LINKEDIN_CONSTRAINTS } from './linkedin.js';
16
+ export type { LinkedInAdapterConfig } from './linkedin.js';
17
+ export { createXAdapter, X_CONSTRAINTS } from './x.js';
18
+ export type { XAdapterConfig } from './x.js';
19
+ export { createFacebookAdapter, FACEBOOK_CONSTRAINTS } from './facebook.js';
20
+ export type { FacebookAdapterConfig } from './facebook.js';
21
+ export { createInstagramAdapter, INSTAGRAM_CONSTRAINTS } from './instagram.js';
22
+ export type { InstagramAdapterConfig } from './instagram.js';
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC5E,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvD,YAAY,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC5E,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC/E,YAAY,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * V1 adapters — one factory function per supported platform.
3
+ *
4
+ * Apps construct what they need and feed the array to
5
+ * `createAdapterRegistry()`. The factories are deliberately
6
+ * argument-less for the default case so a CMS can do:
7
+ *
8
+ * const registry = createAdapterRegistry([
9
+ * createLinkedInAdapter(),
10
+ * createXAdapter(),
11
+ * createFacebookAdapter(),
12
+ * createInstagramAdapter(),
13
+ * ]);
14
+ */
15
+ export { createLinkedInAdapter, LINKEDIN_CONSTRAINTS } from './linkedin.js';
16
+ export { createXAdapter, X_CONSTRAINTS } from './x.js';
17
+ export { createFacebookAdapter, FACEBOOK_CONSTRAINTS } from './facebook.js';
18
+ export { createInstagramAdapter, INSTAGRAM_CONSTRAINTS } from './instagram.js';
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAE5E,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvD,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAE5E,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Instagram (Business / Creator) adapter — Meta Graph Content
3
+ * Publishing API.
4
+ *
5
+ * Two-step protocol — the only one in this package:
6
+ * 1. `POST /v18.0/<ig-user-id>/media` → returns `creation_id`
7
+ * 2. `POST /v18.0/<ig-user-id>/media_publish` → publishes the container
8
+ *
9
+ * Auth: Page-linked IG user access token via
10
+ * `Authorization: Bearer …`.
11
+ *
12
+ * `credentials.authorRef` carries the IG user id (e.g.
13
+ * `'ig_user_12345'`). Caption is required; media is required —
14
+ * Instagram doesn't allow text-only posts.
15
+ */
16
+ import type { SocialAdapter } from '../adapter.js';
17
+ import type { SocialPlatformConstraints } from '../types.js';
18
+ export declare const INSTAGRAM_CONSTRAINTS: SocialPlatformConstraints;
19
+ export interface InstagramAdapterConfig {
20
+ baseUrl?: string;
21
+ graphVersion?: string;
22
+ constraints?: Partial<SocialPlatformConstraints>;
23
+ }
24
+ export declare function createInstagramAdapter(config?: InstagramAdapterConfig): SocialAdapter;
25
+ //# sourceMappingURL=instagram.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instagram.d.ts","sourceRoot":"","sources":["../../src/adapters/instagram.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAIV,yBAAyB,EAE1B,MAAM,aAAa,CAAC;AAOrB,eAAO,MAAM,qBAAqB,EAAE,yBAiBnC,CAAC;AAEF,MAAM,WAAW,sBAAsB;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAC;CAClD;AAED,wBAAgB,sBAAsB,CACpC,MAAM,GAAE,sBAA2B,GAClC,aAAa,CA2Ff"}