@opencoredev/social-sdk 0.3.0 → 0.4.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.
Files changed (63) hide show
  1. package/dist/cli-request.d.ts +15 -0
  2. package/dist/cli-request.js +193 -0
  3. package/dist/cli.d.ts +4 -3
  4. package/dist/cli.js +19 -21
  5. package/dist/cloud/common.d.ts +7 -6
  6. package/dist/cloud/common.js +35 -54
  7. package/dist/cloud/lifecycle.js +31 -35
  8. package/dist/cloud/media.d.ts +2 -2
  9. package/dist/cloud/media.js +13 -3
  10. package/dist/cloud/outcomes.d.ts +4 -3
  11. package/dist/cloud/outcomes.js +8 -15
  12. package/dist/cloud/post-for-me.js +41 -49
  13. package/dist/cloud/zernio.js +58 -98
  14. package/dist/core/client.js +79 -99
  15. package/dist/core/fields.d.ts +14 -0
  16. package/dist/core/fields.js +14 -0
  17. package/dist/core/idempotency.d.ts +7 -2
  18. package/dist/core/idempotency.js +37 -20
  19. package/dist/core/pagination.js +8 -7
  20. package/dist/core/types.d.ts +3 -2
  21. package/dist/platforms/bluesky.d.ts +65 -1
  22. package/dist/platforms/bluesky.js +675 -276
  23. package/dist/platforms/instagram.d.ts +2 -0
  24. package/dist/platforms/instagram.js +130 -105
  25. package/dist/platforms/linkedin.d.ts +58 -1
  26. package/dist/platforms/linkedin.js +877 -107
  27. package/dist/platforms/threads.d.ts +13 -1
  28. package/dist/platforms/threads.js +204 -302
  29. package/dist/platforms/tiktok.d.ts +4 -0
  30. package/dist/platforms/tiktok.js +140 -124
  31. package/dist/platforms/webhook-adapter.d.ts +9 -0
  32. package/dist/platforms/webhook-adapter.js +24 -0
  33. package/dist/platforms/x-engagement.js +7 -12
  34. package/dist/platforms/x-stream.d.ts +83 -0
  35. package/dist/platforms/x-stream.js +350 -0
  36. package/dist/platforms/x.d.ts +72 -0
  37. package/dist/platforms/x.js +328 -119
  38. package/dist/platforms/youtube-upload.d.ts +1 -1
  39. package/dist/platforms/youtube-upload.js +6 -2
  40. package/dist/platforms/youtube.d.ts +28 -4
  41. package/dist/platforms/youtube.js +291 -133
  42. package/dist/server/bluesky-oauth.d.ts +177 -0
  43. package/dist/server/bluesky-oauth.js +1229 -0
  44. package/dist/server/connections.d.ts +14 -0
  45. package/dist/server/connections.js +10 -2
  46. package/dist/server/egress.d.ts +14 -0
  47. package/dist/server/egress.js +115 -0
  48. package/dist/server/oauth-internal.d.ts +6 -0
  49. package/dist/server/oauth-internal.js +66 -0
  50. package/dist/server/oauth.d.ts +1 -1
  51. package/dist/server/oauth.js +46 -99
  52. package/dist/server/webhooks.d.ts +136 -3
  53. package/dist/server/webhooks.js +639 -25
  54. package/dist/testing/index.js +14 -28
  55. package/dist/transport/http.d.ts +1 -1
  56. package/dist/transport/http.js +0 -1
  57. package/dist/transport/json.d.ts +7 -0
  58. package/dist/transport/json.js +32 -4
  59. package/dist/transport/upload.d.ts +1 -1
  60. package/dist/transport/upload.js +46 -38
  61. package/dist/transport/validation.d.ts +16 -5
  62. package/dist/transport/validation.js +29 -7
  63. package/package.json +2 -2
@@ -0,0 +1,177 @@
1
+ import { type JsonValue } from "../core/types.js";
2
+ import type { ConnectionAccount, ConnectionAttempt, ConnectionProvider } from "./connections.js";
3
+ /** ES256 client signing key for confidential clients (`private_key_jwt`). */
4
+ export interface BlueskyOAuthSigningKey {
5
+ /** Key ID published in the client metadata `jwks` or `jwks_uri`. */
6
+ readonly kid: string;
7
+ /** Private P-256 JWK. Keep it in a server-side secret store. */
8
+ readonly privateJwk: JsonWebKey;
9
+ }
10
+ export interface BlueskyOAuthRequestOptions {
11
+ readonly fetch?: typeof globalThis.fetch;
12
+ /** Maximum time for one HTTP request or DNS lookup. Defaults to ten seconds. */
13
+ readonly timeoutMs?: number;
14
+ /** Maximum response body size. Defaults to one MiB. */
15
+ readonly maxResponseBytes?: number;
16
+ /**
17
+ * DNS TXT lookup used for `_atproto.<handle>`. Defaults to `resolveTxt` from
18
+ * `node:dns/promises`, loaded on first use.
19
+ */
20
+ readonly resolveTxt?: (hostname: string) => Promise<readonly (readonly string[])[]>;
21
+ /** PLC directory used for `did:plc` documents. Defaults to https://plc.directory. */
22
+ readonly plcDirectoryUrl?: string;
23
+ /**
24
+ * Extra check run before every outgoing request and every redirect hop, after
25
+ * the built-in checks. The built-in checks allow only HTTPS, reject `localhost`
26
+ * names, and reject IP-literal hosts in loopback, private, link-local, CGNAT,
27
+ * multicast, and reserved ranges. They cannot see where a hostname resolves.
28
+ * Throw to block the request. For DNS-level protection, also pass a `fetch`
29
+ * that pins resolved addresses, since a lookup here can differ from the one
30
+ * `fetch` makes.
31
+ */
32
+ readonly assertEgressAllowed?: (url: URL) => void | Promise<void>;
33
+ }
34
+ export interface BlueskyOAuthClientOptions extends BlueskyOAuthRequestOptions {
35
+ /** URL of the client metadata document, or a `http://localhost` development client ID. */
36
+ readonly clientId: string;
37
+ /** Present for confidential clients. Public clients omit it. */
38
+ readonly clientKey?: BlueskyOAuthSigningKey;
39
+ }
40
+ /** A DPoP-bound AT Protocol OAuth session. Contains secrets; store it encrypted. */
41
+ export interface BlueskyOAuthSession {
42
+ readonly version: 1;
43
+ readonly did: string;
44
+ readonly handle?: string;
45
+ /** Verified PDS origin. XRPC requests go here. */
46
+ readonly pdsUrl: string;
47
+ readonly issuer: string;
48
+ readonly clientId: string;
49
+ readonly authMethod: "none" | "private_key_jwt";
50
+ readonly clientKeyId?: string;
51
+ readonly accessToken: string;
52
+ readonly refreshToken?: string;
53
+ readonly expiresAt?: string;
54
+ readonly scopes: readonly string[];
55
+ /** Private P-256 DPoP key bound to this session's tokens. */
56
+ readonly dpopKey: JsonWebKey;
57
+ }
58
+ export interface BlueskyOAuthSessionSink {
59
+ save(input: {
60
+ readonly account: ConnectionAccount;
61
+ readonly session: BlueskyOAuthSession;
62
+ readonly attempt: ConnectionAttempt;
63
+ }): Promise<void>;
64
+ }
65
+ export interface BlueskyOAuthOptions extends BlueskyOAuthClientOptions {
66
+ readonly redirectUri?: string;
67
+ /** Space-separated scopes. Must include `atproto`. Defaults to `atproto transition:generic`. */
68
+ readonly scope?: string;
69
+ /**
70
+ * Handle, DID, or HTTPS server URL used when `ConnectionManager.begin` has no
71
+ * `loginHint`. For example `https://bsky.social`.
72
+ */
73
+ readonly defaultServer?: string;
74
+ /** Receives the verified session. Without a sink the session is discarded. */
75
+ readonly sessionSink?: BlueskyOAuthSessionSink;
76
+ }
77
+ export interface BlueskyOAuthTransport {
78
+ readonly did: string;
79
+ /** Verified PDS origin, suitable for the adapter's `auth.service`. */
80
+ readonly service: string;
81
+ fetchHandler(pathname: string, init?: RequestInit): Promise<Response>;
82
+ }
83
+ export interface BlueskyOAuthClientMetadataInput {
84
+ /** HTTPS URL where this document is served. */
85
+ readonly clientId: string;
86
+ readonly redirectUris: readonly string[];
87
+ /** Every scope the client may request. Must include `atproto`. */
88
+ readonly scope: string;
89
+ readonly applicationType?: "web" | "native";
90
+ readonly clientName?: string;
91
+ readonly clientUri?: string;
92
+ readonly logoUri?: string;
93
+ readonly tosUri?: string;
94
+ readonly policyUri?: string;
95
+ /** Confidential clients publish exactly one of `jwksUri` or `jwks`. */
96
+ readonly jwksUri?: string;
97
+ readonly jwks?: {
98
+ readonly keys: readonly BlueskyOAuthPublishedJwk[];
99
+ };
100
+ }
101
+ /** A public signing key in the client metadata `jwks` document. */
102
+ export type BlueskyOAuthPublishedJwk = JsonWebKey & {
103
+ readonly kid?: string;
104
+ };
105
+ export interface BlueskyOAuthClientMetadata {
106
+ readonly client_id: string;
107
+ readonly application_type: "web" | "native";
108
+ readonly grant_types: readonly ["authorization_code", "refresh_token"];
109
+ readonly response_types: readonly ["code"];
110
+ readonly scope: string;
111
+ readonly redirect_uris: readonly string[];
112
+ readonly dpop_bound_access_tokens: true;
113
+ readonly token_endpoint_auth_method: "none" | "private_key_jwt";
114
+ readonly token_endpoint_auth_signing_alg?: "ES256";
115
+ readonly jwks_uri?: string;
116
+ readonly jwks?: {
117
+ readonly keys: readonly JsonWebKey[];
118
+ };
119
+ readonly client_name?: string;
120
+ readonly client_uri?: string;
121
+ readonly logo_uri?: string;
122
+ readonly tos_uri?: string;
123
+ readonly policy_uri?: string;
124
+ }
125
+ /** Public JWK for the client metadata `jwks` document. Never publish the private key. */
126
+ export declare function blueskyOAuthPublicJwk(key: BlueskyOAuthSigningKey): JsonWebKey & {
127
+ readonly kid: string;
128
+ readonly alg: "ES256";
129
+ readonly use: "sig";
130
+ };
131
+ /**
132
+ * AT Protocol OAuth for Bluesky accounts, driven by `ConnectionManager`.
133
+ *
134
+ * `start` resolves the login hint to an authorization server, generates a DPoP
135
+ * key, and sends a pushed authorization request with the manager's PKCE
136
+ * challenge and state. `complete` checks `iss`, exchanges the code with DPoP,
137
+ * and verifies that the returned DID's PDS names the same issuer before the
138
+ * account is returned or the session reaches `sessionSink`.
139
+ */
140
+ export declare function blueskyOAuth(options: BlueskyOAuthOptions): ConnectionProvider;
141
+ /**
142
+ * Validate a session loaded from storage before using it. Pass the decoded JSON
143
+ * document, for example the result of `JSON.parse` on the decrypted session.
144
+ */
145
+ export declare function parseBlueskyOAuthSession(value: BlueskyOAuthSession | JsonValue): BlueskyOAuthSession;
146
+ /**
147
+ * DPoP transport for the Bluesky adapter's `session` option. Every request gets
148
+ * `Authorization: DPoP <token>` and a fresh proof with `ath`. When the PDS
149
+ * answers 401 with `use_dpop_nonce`, a replayable request is sent once more with
150
+ * the new nonce (RFC 9449 section 9). It never refreshes tokens; call
151
+ * `refreshBlueskyOAuthSession` before `expiresAt`.
152
+ *
153
+ * A PDS response without a `DPoP-Nonce` header is returned rather than rejected:
154
+ * by then the PDS has already processed the request, and turning a completed
155
+ * write into an error would hide its outcome.
156
+ */
157
+ export declare function blueskyOAuthTransport(session: BlueskyOAuthSession, options?: Pick<BlueskyOAuthRequestOptions, "fetch" | "assertEgressAllowed">): BlueskyOAuthTransport;
158
+ /**
159
+ * Refresh a session with its own DPoP key and client authentication. The
160
+ * account's PDS is resolved again first, and the refresh fails unless it still
161
+ * names the session issuer. Refresh tokens rotate, so store the result with a
162
+ * compare-and-set write (for example `CredentialManager.rotate`).
163
+ */
164
+ export declare function refreshBlueskyOAuthSession(session: BlueskyOAuthSession, options: BlueskyOAuthClientOptions): Promise<BlueskyOAuthSession>;
165
+ /**
166
+ * Build and validate the client metadata document to serve at `clientId`.
167
+ * Adding `jwks` or `jwksUri` makes the client confidential (`private_key_jwt`).
168
+ */
169
+ export declare function blueskyOAuthClientMetadata(input: BlueskyOAuthClientMetadataInput): BlueskyOAuthClientMetadata;
170
+ /**
171
+ * Development client ID for a public client running on a loopback address. The
172
+ * authorization server derives its metadata from these query parameters.
173
+ */
174
+ export declare function blueskyLoopbackClientId(input?: {
175
+ readonly redirectUris?: readonly string[];
176
+ readonly scope?: string;
177
+ }): string;