@opencoredev/social-sdk 0.1.0 → 0.1.2

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 (154) hide show
  1. package/README.md +4 -2
  2. package/package.json +1 -1
  3. package/dist/cli.d.ts +0 -14
  4. package/dist/cli.d.ts.map +0 -1
  5. package/dist/cli.js +0 -223
  6. package/dist/cli.js.map +0 -1
  7. package/dist/cloud/common.d.ts +0 -26
  8. package/dist/cloud/common.d.ts.map +0 -1
  9. package/dist/cloud/common.js +0 -307
  10. package/dist/cloud/common.js.map +0 -1
  11. package/dist/cloud/lifecycle.d.ts +0 -11
  12. package/dist/cloud/lifecycle.d.ts.map +0 -1
  13. package/dist/cloud/lifecycle.js +0 -108
  14. package/dist/cloud/lifecycle.js.map +0 -1
  15. package/dist/cloud/media.d.ts +0 -24
  16. package/dist/cloud/media.d.ts.map +0 -1
  17. package/dist/cloud/media.js +0 -97
  18. package/dist/cloud/media.js.map +0 -1
  19. package/dist/cloud/outcomes.d.ts +0 -10
  20. package/dist/cloud/outcomes.d.ts.map +0 -1
  21. package/dist/cloud/outcomes.js +0 -188
  22. package/dist/cloud/outcomes.js.map +0 -1
  23. package/dist/cloud/post-for-me.d.ts +0 -70
  24. package/dist/cloud/post-for-me.d.ts.map +0 -1
  25. package/dist/cloud/post-for-me.js +0 -326
  26. package/dist/cloud/post-for-me.js.map +0 -1
  27. package/dist/cloud/zernio.d.ts +0 -112
  28. package/dist/cloud/zernio.d.ts.map +0 -1
  29. package/dist/cloud/zernio.js +0 -542
  30. package/dist/cloud/zernio.js.map +0 -1
  31. package/dist/core/adapter.d.ts +0 -118
  32. package/dist/core/adapter.d.ts.map +0 -1
  33. package/dist/core/adapter.js +0 -4
  34. package/dist/core/adapter.js.map +0 -1
  35. package/dist/core/client.d.ts +0 -108
  36. package/dist/core/client.d.ts.map +0 -1
  37. package/dist/core/client.js +0 -893
  38. package/dist/core/client.js.map +0 -1
  39. package/dist/core/concurrency.d.ts +0 -10
  40. package/dist/core/concurrency.d.ts.map +0 -1
  41. package/dist/core/concurrency.js +0 -78
  42. package/dist/core/concurrency.js.map +0 -1
  43. package/dist/core/errors.d.ts +0 -45
  44. package/dist/core/errors.d.ts.map +0 -1
  45. package/dist/core/errors.js +0 -44
  46. package/dist/core/errors.js.map +0 -1
  47. package/dist/core/idempotency.d.ts +0 -34
  48. package/dist/core/idempotency.d.ts.map +0 -1
  49. package/dist/core/idempotency.js +0 -59
  50. package/dist/core/idempotency.js.map +0 -1
  51. package/dist/core/index.d.ts +0 -7
  52. package/dist/core/index.d.ts.map +0 -1
  53. package/dist/core/index.js +0 -7
  54. package/dist/core/index.js.map +0 -1
  55. package/dist/core/pagination.d.ts +0 -12
  56. package/dist/core/pagination.d.ts.map +0 -1
  57. package/dist/core/pagination.js +0 -81
  58. package/dist/core/pagination.js.map +0 -1
  59. package/dist/core/types.d.ts +0 -329
  60. package/dist/core/types.d.ts.map +0 -1
  61. package/dist/core/types.js +0 -7
  62. package/dist/core/types.js.map +0 -1
  63. package/dist/index.d.ts +0 -2
  64. package/dist/index.d.ts.map +0 -1
  65. package/dist/index.js +0 -2
  66. package/dist/index.js.map +0 -1
  67. package/dist/platforms/bluesky.d.ts +0 -132
  68. package/dist/platforms/bluesky.d.ts.map +0 -1
  69. package/dist/platforms/bluesky.js +0 -1049
  70. package/dist/platforms/bluesky.js.map +0 -1
  71. package/dist/platforms/instagram.d.ts +0 -63
  72. package/dist/platforms/instagram.d.ts.map +0 -1
  73. package/dist/platforms/instagram.js +0 -676
  74. package/dist/platforms/instagram.js.map +0 -1
  75. package/dist/platforms/linkedin.d.ts +0 -54
  76. package/dist/platforms/linkedin.d.ts.map +0 -1
  77. package/dist/platforms/linkedin.js +0 -580
  78. package/dist/platforms/linkedin.js.map +0 -1
  79. package/dist/platforms/threads.d.ts +0 -102
  80. package/dist/platforms/threads.d.ts.map +0 -1
  81. package/dist/platforms/threads.js +0 -571
  82. package/dist/platforms/threads.js.map +0 -1
  83. package/dist/platforms/tiktok.d.ts +0 -32
  84. package/dist/platforms/tiktok.d.ts.map +0 -1
  85. package/dist/platforms/tiktok.js +0 -511
  86. package/dist/platforms/tiktok.js.map +0 -1
  87. package/dist/platforms/x-engagement.d.ts +0 -17
  88. package/dist/platforms/x-engagement.d.ts.map +0 -1
  89. package/dist/platforms/x-engagement.js +0 -47
  90. package/dist/platforms/x-engagement.js.map +0 -1
  91. package/dist/platforms/x.d.ts +0 -82
  92. package/dist/platforms/x.d.ts.map +0 -1
  93. package/dist/platforms/x.js +0 -511
  94. package/dist/platforms/x.js.map +0 -1
  95. package/dist/platforms/youtube-upload.d.ts +0 -33
  96. package/dist/platforms/youtube-upload.d.ts.map +0 -1
  97. package/dist/platforms/youtube-upload.js +0 -281
  98. package/dist/platforms/youtube-upload.js.map +0 -1
  99. package/dist/platforms/youtube.d.ts +0 -55
  100. package/dist/platforms/youtube.d.ts.map +0 -1
  101. package/dist/platforms/youtube.js +0 -561
  102. package/dist/platforms/youtube.js.map +0 -1
  103. package/dist/server/connections.d.ts +0 -124
  104. package/dist/server/connections.d.ts.map +0 -1
  105. package/dist/server/connections.js +0 -334
  106. package/dist/server/connections.js.map +0 -1
  107. package/dist/server/credentials.d.ts +0 -52
  108. package/dist/server/credentials.d.ts.map +0 -1
  109. package/dist/server/credentials.js +0 -115
  110. package/dist/server/credentials.js.map +0 -1
  111. package/dist/server/index.d.ts +0 -5
  112. package/dist/server/index.d.ts.map +0 -1
  113. package/dist/server/index.js +0 -5
  114. package/dist/server/index.js.map +0 -1
  115. package/dist/server/oauth.d.ts +0 -48
  116. package/dist/server/oauth.d.ts.map +0 -1
  117. package/dist/server/oauth.js +0 -483
  118. package/dist/server/oauth.js.map +0 -1
  119. package/dist/server/webhooks.d.ts +0 -58
  120. package/dist/server/webhooks.d.ts.map +0 -1
  121. package/dist/server/webhooks.js +0 -198
  122. package/dist/server/webhooks.js.map +0 -1
  123. package/dist/testing/index.d.ts +0 -47
  124. package/dist/testing/index.d.ts.map +0 -1
  125. package/dist/testing/index.js +0 -413
  126. package/dist/testing/index.js.map +0 -1
  127. package/dist/testing.d.ts +0 -2
  128. package/dist/testing.d.ts.map +0 -1
  129. package/dist/testing.js +0 -2
  130. package/dist/testing.js.map +0 -1
  131. package/dist/transport/binary.d.ts +0 -3
  132. package/dist/transport/binary.d.ts.map +0 -1
  133. package/dist/transport/binary.js +0 -30
  134. package/dist/transport/binary.js.map +0 -1
  135. package/dist/transport/budget.d.ts +0 -4
  136. package/dist/transport/budget.d.ts.map +0 -1
  137. package/dist/transport/budget.js +0 -27
  138. package/dist/transport/budget.js.map +0 -1
  139. package/dist/transport/http.d.ts +0 -44
  140. package/dist/transport/http.d.ts.map +0 -1
  141. package/dist/transport/http.js +0 -230
  142. package/dist/transport/http.js.map +0 -1
  143. package/dist/transport/json.d.ts +0 -3
  144. package/dist/transport/json.d.ts.map +0 -1
  145. package/dist/transport/json.js +0 -11
  146. package/dist/transport/json.js.map +0 -1
  147. package/dist/transport/upload.d.ts +0 -25
  148. package/dist/transport/upload.d.ts.map +0 -1
  149. package/dist/transport/upload.js +0 -133
  150. package/dist/transport/upload.js.map +0 -1
  151. package/dist/transport/validation.d.ts +0 -6
  152. package/dist/transport/validation.d.ts.map +0 -1
  153. package/dist/transport/validation.js +0 -24
  154. package/dist/transport/validation.js.map +0 -1
@@ -1,124 +0,0 @@
1
- import type { ConnectedAccountRef, Platform } from "../core/types.js";
2
- export interface ConnectionAttempt {
3
- readonly id: string;
4
- readonly backend: string;
5
- readonly tenantId: string;
6
- readonly principalId: string;
7
- readonly platforms: readonly Platform[];
8
- readonly capabilities: readonly string[];
9
- readonly redirectUri: string;
10
- readonly state: string;
11
- readonly codeVerifier: string;
12
- readonly providerState?: string;
13
- readonly createdAt: string;
14
- readonly expiresAt: string;
15
- }
16
- export interface ConnectionStart {
17
- readonly authorizationUrl: string;
18
- readonly attempt: Omit<ConnectionAttempt, "state" | "codeVerifier"> & {
19
- readonly state: string;
20
- };
21
- }
22
- export interface ConnectionAccount {
23
- readonly ref: ConnectedAccountRef;
24
- readonly displayName: string;
25
- }
26
- export interface ConnectionProvider {
27
- start(input: {
28
- readonly platforms: readonly Platform[];
29
- readonly capabilities: readonly string[];
30
- readonly redirectUri: string;
31
- readonly state: string;
32
- readonly codeChallenge: string;
33
- }): Promise<{
34
- readonly authorizationUrl: string;
35
- readonly providerState?: string;
36
- }>;
37
- complete(input: {
38
- readonly callbackUrl: string;
39
- readonly attempt: ConnectionAttempt;
40
- }): Promise<readonly ConnectionAccount[]>;
41
- }
42
- export interface ConnectionStore {
43
- save(attempt: ConnectionAttempt): Promise<void>;
44
- get(attemptId: string): Promise<ConnectionAttempt | undefined>;
45
- /** Atomically claim a one-use code exchange. Never expire or release this claim automatically. */
46
- claimDiscovery(attemptId: string): Promise<boolean>;
47
- /** Persist discovered accounts before presenting the account picker. */
48
- saveDiscoveredAccounts(attemptId: string, accounts: readonly ConnectionAccount[]): Promise<void>;
49
- getDiscoveredAccounts(attemptId: string): Promise<readonly ConnectionAccount[] | undefined>;
50
- /**
51
- * Implementations must consume an attempt and insert all selected grants in
52
- * one durable transaction. If the transaction fails, the attempt must remain
53
- * retryable (or expose an explicit recovery marker); never commit a consumed
54
- * attempt with only a subset of its grants.
55
- */
56
- complete(input: {
57
- readonly attemptId: string;
58
- readonly state: string;
59
- readonly accounts: readonly ConnectionAccount[];
60
- readonly selectedAccountIds: readonly string[];
61
- }): Promise<readonly ConnectionGrant[]>;
62
- }
63
- export interface ConnectionGrant {
64
- readonly grantId: string;
65
- readonly tenantId: string;
66
- readonly principalId: string;
67
- readonly account: ConnectedAccountRef;
68
- readonly capabilities: readonly string[];
69
- }
70
- export interface ConnectionManagerOptions {
71
- readonly store: ConnectionStore;
72
- readonly now?: () => Date;
73
- readonly randomBytes?: (length: number) => Uint8Array;
74
- readonly ttlMs?: number;
75
- }
76
- export declare class ConnectionManager {
77
- #private;
78
- constructor(options: ConnectionManagerOptions);
79
- begin(input: {
80
- readonly backend: string;
81
- readonly tenantId: string;
82
- readonly principalId: string;
83
- readonly platforms: readonly Platform[];
84
- readonly capabilities?: readonly string[];
85
- readonly redirectUri: string;
86
- readonly allowedRedirectUris: readonly string[];
87
- readonly provider: ConnectionProvider;
88
- }): Promise<ConnectionStart>;
89
- discover(input: {
90
- readonly attemptId: string;
91
- readonly tenantId: string;
92
- readonly principalId: string;
93
- readonly callbackUrl: string;
94
- readonly returnedState: string;
95
- readonly allowedRedirectUris: readonly string[];
96
- readonly provider: ConnectionProvider;
97
- }): Promise<readonly ConnectionAccount[]>;
98
- select(input: {
99
- readonly attemptId: string;
100
- readonly tenantId: string;
101
- readonly principalId: string;
102
- readonly selectedAccountIds: readonly string[];
103
- }): Promise<readonly ConnectionGrant[]>;
104
- /** Convenience for callers that already know which discovered accounts to select. */
105
- complete(input: Parameters<ConnectionManager["discover"]>[0] & {
106
- readonly selectedAccountIds: readonly string[];
107
- }): Promise<readonly ConnectionGrant[]>;
108
- }
109
- export declare class MemoryConnectionStore implements ConnectionStore {
110
- #private;
111
- save(attempt: ConnectionAttempt): Promise<void>;
112
- get(attemptId: string): Promise<ConnectionAttempt | undefined>;
113
- claimDiscovery(attemptId: string): Promise<boolean>;
114
- saveDiscoveredAccounts(attemptId: string, accounts: readonly ConnectionAccount[]): Promise<void>;
115
- getDiscoveredAccounts(attemptId: string): Promise<readonly ConnectionAccount[] | undefined>;
116
- complete(input: {
117
- readonly attemptId: string;
118
- readonly state: string;
119
- readonly accounts: readonly ConnectionAccount[];
120
- readonly selectedAccountIds: readonly string[];
121
- }): Promise<readonly ConnectionGrant[]>;
122
- grants(): readonly ConnectionGrant[];
123
- }
124
- //# sourceMappingURL=connections.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connections.d.ts","sourceRoot":"","sources":["../../src/server/connections.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEtE,MAA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,SAAS,iBAAiB,EAAE,CAAC;QAChD,QAAQ,CAAC,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;KAChD,GAAG,OAAO,CAAC,SAAS,eAAe,EAAE,CAAC;IA6BvC,MAAM,IAAI,SAAS,eAAe,EAAE;CAGrC"}
@@ -1,334 +0,0 @@
1
- import { SocialError } from "../core/errors.js";
2
- function randomBytes(length) {
3
- const result = new Uint8Array(length);
4
- crypto.getRandomValues(result);
5
- return result;
6
- }
7
- function base64Url(bytes) {
8
- let binary = "";
9
- for (const byte of bytes)
10
- binary += String.fromCharCode(byte);
11
- return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
12
- }
13
- async function challenge(verifier) {
14
- const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(verifier));
15
- return base64Url(new Uint8Array(digest));
16
- }
17
- function allowedRedirect(value, allowlist, callback = false) {
18
- let candidate;
19
- try {
20
- candidate = new URL(value);
21
- }
22
- catch {
23
- return false;
24
- }
25
- if (candidate.username ||
26
- candidate.password ||
27
- candidate.hash ||
28
- (candidate.protocol !== "https:" &&
29
- !(candidate.protocol === "http:" &&
30
- ["localhost", "127.0.0.1", "[::1]"].includes(candidate.hostname))))
31
- return false;
32
- return allowlist.some((entry) => {
33
- try {
34
- const allowed = new URL(entry);
35
- if (!callback)
36
- return candidate.href === allowed.href;
37
- if (candidate.origin !== allowed.origin || candidate.pathname !== allowed.pathname)
38
- return false;
39
- for (const [key, value] of allowed.searchParams)
40
- if (candidate.searchParams.getAll(key).length !== 1 ||
41
- candidate.searchParams.get(key) !== value)
42
- return false;
43
- return true;
44
- }
45
- catch {
46
- return false;
47
- }
48
- });
49
- }
50
- function ensureState(expected, actual) {
51
- const expectedBytes = new TextEncoder().encode(expected);
52
- const actualBytes = new TextEncoder().encode(actual);
53
- let difference = expectedBytes.length ^ actualBytes.length;
54
- const length = Math.max(expectedBytes.length, actualBytes.length);
55
- for (let index = 0; index < length; index++)
56
- difference |= (expectedBytes[index] ?? 0) ^ (actualBytes[index] ?? 0);
57
- if (difference !== 0) {
58
- throw new SocialError({
59
- code: "unauthorized",
60
- operation: "connections.complete",
61
- message: "Connection state did not match this authenticated attempt",
62
- });
63
- }
64
- }
65
- export class ConnectionManager {
66
- #options;
67
- constructor(options) {
68
- const ttlMs = options.ttlMs ?? 10 * 60 * 1000;
69
- if (!Number.isSafeInteger(ttlMs) || ttlMs < 1)
70
- throw new SocialError({
71
- code: "invalid_config",
72
- operation: "connections.constructor",
73
- message: "ttlMs must be a positive safe integer",
74
- });
75
- this.#options = {
76
- store: options.store,
77
- now: options.now ?? (() => new Date()),
78
- randomBytes: options.randomBytes ?? randomBytes,
79
- ttlMs,
80
- };
81
- }
82
- async begin(input) {
83
- if (!input.tenantId || !input.principalId)
84
- throw new SocialError({
85
- code: "unauthorized",
86
- operation: "connections.begin",
87
- message: "An authenticated tenant and principal are required",
88
- });
89
- if (!allowedRedirect(input.redirectUri, input.allowedRedirectUris))
90
- throw new SocialError({
91
- code: "invalid_input",
92
- operation: "connections.begin",
93
- message: "redirectUri is not on the exact callback allowlist",
94
- });
95
- if (input.platforms.length === 0)
96
- throw new SocialError({
97
- code: "invalid_input",
98
- operation: "connections.begin",
99
- message: "At least one platform is required",
100
- });
101
- const now = this.#options.now();
102
- const state = base64Url(this.#options.randomBytes(32));
103
- const codeVerifier = base64Url(this.#options.randomBytes(48));
104
- const attemptId = base64Url(this.#options.randomBytes(18));
105
- const expiresAt = new Date(now.getTime() + this.#options.ttlMs).toISOString();
106
- const started = await input.provider.start({
107
- platforms: input.platforms,
108
- capabilities: input.capabilities ?? [],
109
- redirectUri: input.redirectUri,
110
- state,
111
- codeChallenge: await challenge(codeVerifier),
112
- });
113
- const attempt = {
114
- id: attemptId,
115
- backend: input.backend,
116
- tenantId: input.tenantId,
117
- principalId: input.principalId,
118
- platforms: [...input.platforms],
119
- capabilities: [...(input.capabilities ?? [])],
120
- redirectUri: input.redirectUri,
121
- state,
122
- codeVerifier,
123
- ...(started.providerState === undefined ? {} : { providerState: started.providerState }),
124
- createdAt: now.toISOString(),
125
- expiresAt,
126
- };
127
- await this.#options.store.save(attempt);
128
- const { state: publicState, codeVerifier: _privateVerifier, ...publicAttempt } = attempt;
129
- return {
130
- authorizationUrl: started.authorizationUrl,
131
- attempt: { ...publicAttempt, state: publicState },
132
- };
133
- }
134
- async discover(input) {
135
- const attempt = await this.#options.store.get(input.attemptId);
136
- if (attempt === undefined)
137
- throw new SocialError({
138
- code: "invalid_input",
139
- operation: "connections.complete",
140
- message: "Connection attempt was not found",
141
- });
142
- if (attempt.tenantId !== input.tenantId || attempt.principalId !== input.principalId)
143
- throw new SocialError({
144
- code: "unauthorized",
145
- operation: "connections.complete",
146
- message: "Connection attempt belongs to a different authenticated principal",
147
- });
148
- if (!allowedRedirect(input.callbackUrl, input.allowedRedirectUris, true) ||
149
- !allowedRedirect(input.callbackUrl, [attempt.redirectUri], true))
150
- throw new SocialError({
151
- code: "invalid_input",
152
- operation: "connections.complete",
153
- message: "Callback URL is not the exact registered redirect",
154
- });
155
- ensureState(attempt.state, input.returnedState);
156
- const states = new URL(input.callbackUrl).searchParams.getAll("state");
157
- // Callers may pass a callback URL after extracting its state parameter; when
158
- // present, reject duplicates or a value that differs from the authenticated state.
159
- if (states.length > 1 || (states.length === 1 && states[0] !== input.returnedState))
160
- throw new SocialError({
161
- code: "unauthorized",
162
- operation: "connections.complete",
163
- message: "Callback state differs from the authenticated callback parameter",
164
- });
165
- if (this.#options.now().getTime() >= Date.parse(attempt.expiresAt))
166
- throw new SocialError({
167
- code: "timeout",
168
- operation: "connections.complete",
169
- message: "Connection attempt expired",
170
- });
171
- const saved = await this.#options.store.getDiscoveredAccounts(attempt.id);
172
- if (saved)
173
- return saved;
174
- if (!(await this.#options.store.claimDiscovery(attempt.id))) {
175
- const completed = await this.#options.store.getDiscoveredAccounts(attempt.id);
176
- if (completed)
177
- return completed;
178
- throw new SocialError({
179
- code: "reconnect_required",
180
- operation: "connections.discover",
181
- message: "Code exchange is already in progress or its result was lost. Wait for discovery or begin a new connection; the code will not be exchanged again.",
182
- });
183
- }
184
- const accounts = await input.provider.complete({ callbackUrl: input.callbackUrl, attempt });
185
- this.#validateAccounts(attempt, accounts);
186
- await this.#options.store.saveDiscoveredAccounts(attempt.id, accounts);
187
- return structuredClone(accounts);
188
- }
189
- #validateAccounts(attempt, accounts) {
190
- if (accounts.length === 0)
191
- throw new SocialError({
192
- code: "invalid_input",
193
- operation: "connections.discover",
194
- message: "The provider returned no connected accounts",
195
- });
196
- const known = new Set(accounts.map((account) => account.ref.accountId));
197
- if (known.size !== accounts.length ||
198
- accounts.some(({ ref }) => ref.kind !== "connected-account" ||
199
- ref.version !== 1 ||
200
- ref.backend !== attempt.backend ||
201
- !attempt.platforms.includes(ref.platform) ||
202
- !ref.accountId))
203
- throw new SocialError({
204
- code: "unauthorized",
205
- operation: "connections.discover",
206
- message: "Provider returned ambiguous accounts or references outside this connection attempt",
207
- });
208
- }
209
- async select(input) {
210
- const attempt = await this.#options.store.get(input.attemptId);
211
- if (!attempt ||
212
- attempt.tenantId !== input.tenantId ||
213
- attempt.principalId !== input.principalId)
214
- throw new SocialError({
215
- code: "unauthorized",
216
- operation: "connections.select",
217
- message: "Connection attempt was not found for this authenticated principal",
218
- });
219
- if (this.#options.now().getTime() >= Date.parse(attempt.expiresAt))
220
- throw new SocialError({
221
- code: "timeout",
222
- operation: "connections.select",
223
- message: "Connection attempt expired",
224
- });
225
- const accounts = await this.#options.store.getDiscoveredAccounts(attempt.id);
226
- if (!accounts)
227
- throw new SocialError({
228
- code: "invalid_input",
229
- operation: "connections.select",
230
- message: "Complete account discovery before selecting accounts",
231
- });
232
- this.#validateAccounts(attempt, accounts);
233
- const selected = new Set(input.selectedAccountIds);
234
- if (!selected.size || selected.size !== input.selectedAccountIds.length)
235
- throw new SocialError({
236
- code: "invalid_input",
237
- operation: "connections.select",
238
- message: "Select one or more distinct discovered accounts",
239
- });
240
- const known = new Set(accounts.map(({ ref }) => ref.accountId));
241
- if ([...selected].some((id) => !known.has(id)))
242
- throw new SocialError({
243
- code: "unauthorized",
244
- operation: "connections.select",
245
- message: "Selected account was not returned by the provider",
246
- });
247
- return this.#options.store.complete({
248
- attemptId: attempt.id,
249
- state: attempt.state,
250
- accounts,
251
- selectedAccountIds: input.selectedAccountIds,
252
- });
253
- }
254
- /** Convenience for callers that already know which discovered accounts to select. */
255
- async complete(input) {
256
- await this.discover(input);
257
- return this.select(input);
258
- }
259
- }
260
- export class MemoryConnectionStore {
261
- #attempts = new Map();
262
- #grants = [];
263
- #sequence = 0;
264
- async save(attempt) {
265
- if (this.#attempts.has(attempt.id))
266
- throw new SocialError({
267
- code: "upstream_failure",
268
- operation: "connections.begin",
269
- message: "Connection attempt ID collision",
270
- });
271
- this.#attempts.set(attempt.id, {
272
- attempt: structuredClone(attempt),
273
- consumed: false,
274
- discoveryClaimed: false,
275
- });
276
- }
277
- async get(attemptId) {
278
- const stored = this.#attempts.get(attemptId);
279
- return stored && !stored.consumed ? structuredClone(stored.attempt) : undefined;
280
- }
281
- async claimDiscovery(attemptId) {
282
- const stored = this.#attempts.get(attemptId);
283
- if (!stored || stored.consumed || stored.discoveryClaimed)
284
- return false;
285
- stored.discoveryClaimed = true;
286
- return true;
287
- }
288
- async saveDiscoveredAccounts(attemptId, accounts) {
289
- const stored = this.#attempts.get(attemptId);
290
- if (!stored || stored.consumed || !stored.discoveryClaimed || stored.accounts)
291
- throw new SocialError({
292
- code: "unauthorized",
293
- operation: "connections.discover",
294
- message: "Discovery cannot be saved for this attempt",
295
- });
296
- stored.accounts = structuredClone(accounts);
297
- }
298
- async getDiscoveredAccounts(attemptId) {
299
- const stored = this.#attempts.get(attemptId);
300
- return stored?.accounts && !stored.consumed ? structuredClone(stored.accounts) : undefined;
301
- }
302
- async complete(input) {
303
- const stored = this.#attempts.get(input.attemptId);
304
- if (stored === undefined || stored.consumed || stored.attempt.state !== input.state)
305
- throw new SocialError({
306
- code: "unauthorized",
307
- operation: "connections.complete",
308
- message: "Connection callback is invalid or already consumed",
309
- });
310
- if (!stored.accounts || JSON.stringify(stored.accounts) !== JSON.stringify(input.accounts))
311
- throw new SocialError({
312
- code: "unauthorized",
313
- operation: "connections.select",
314
- message: "Grants must match persisted discovery",
315
- });
316
- const selected = new Set(input.selectedAccountIds);
317
- const grants = input.accounts
318
- .filter((account) => selected.has(account.ref.accountId))
319
- .map((account) => ({
320
- grantId: `grant-${++this.#sequence}`,
321
- tenantId: stored.attempt.tenantId,
322
- principalId: stored.attempt.principalId,
323
- account: account.ref,
324
- capabilities: stored.attempt.capabilities,
325
- }));
326
- this.#grants.push(...structuredClone(grants));
327
- stored.consumed = true;
328
- return structuredClone(grants);
329
- }
330
- grants() {
331
- return structuredClone(this.#grants);
332
- }
333
- }
334
- //# sourceMappingURL=connections.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connections.js","sourceRoot":"","sources":["../../src/server/connections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA+EhD,SAAS,WAAW,CAAC,MAAc;IACjC,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IAC/B,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,SAAS,CAAC,KAAiB;IAClC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC9D,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AACpF,CAAC;AAED,KAAK,UAAU,SAAS,CAAC,QAAgB;IACvC,MAAM,MAAM,GA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YAAY,EAAE,MAAM,CAAC,OAAO,CAAC,YAAY;SAC1C,CAAC,CAAC,CAAC;QACN,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;QAC9C,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC;QACvB,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAED,MAAM;QACJ,OAAO,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;CACF"}
@@ -1,52 +0,0 @@
1
- import type { CredentialStore } from "../core/adapter.js";
2
- export interface CredentialLease {
3
- readonly key: string;
4
- readonly token: string;
5
- readonly expiresAt: string;
6
- }
7
- export interface CredentialLock {
8
- acquire(key: string, ttlMs: number): Promise<CredentialLease | undefined>;
9
- release(lease: CredentialLease): Promise<void>;
10
- }
11
- export interface StoredCredential {
12
- readonly accessToken: string;
13
- readonly refreshToken?: string;
14
- readonly expiresAt?: string;
15
- readonly scopes?: readonly string[];
16
- readonly metadata?: Readonly<Record<string, string>>;
17
- }
18
- export declare class MemoryCredentialStore implements CredentialStore<StoredCredential> {
19
- #private;
20
- get(key: string): Promise<{
21
- readonly value: StoredCredential;
22
- readonly revision: string;
23
- } | undefined>;
24
- compareAndSet(input: {
25
- readonly key: string;
26
- readonly expectedRevision: string | undefined;
27
- readonly value: StoredCredential;
28
- }): Promise<{
29
- readonly updated: boolean;
30
- readonly revision?: string;
31
- }>;
32
- delete(key: string): Promise<void>;
33
- }
34
- export declare class MemoryCredentialLock implements CredentialLock {
35
- #private;
36
- acquire(key: string, ttlMs: number): Promise<CredentialLease | undefined>;
37
- release(lease: CredentialLease): Promise<void>;
38
- }
39
- export declare class CredentialManager {
40
- private readonly store;
41
- private readonly lock;
42
- private readonly lockTtlMs;
43
- constructor(store: CredentialStore<StoredCredential>, lock: CredentialLock, lockTtlMs?: number);
44
- get(key: string): Promise<{
45
- readonly value: StoredCredential;
46
- readonly revision: string;
47
- } | undefined>;
48
- save(key: string, value: StoredCredential, expectedRevision?: string): Promise<string>;
49
- rotate(key: string, refresh: (current: StoredCredential) => Promise<StoredCredential>): Promise<StoredCredential>;
50
- delete(key: string): Promise<void>;
51
- }
52
- //# sourceMappingURL=credentials.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../src/server/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG1D,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAAC;IAC1E,OAAO,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACtD;AAED,qBAAa,qBAAsB,YAAW,eAAe,CAAC,gBAAgB,CAAC;;IAIvE,GAAG,CACP,GAAG,EAAE,MAAM,GACV,OAAO,CAAC;QAAE,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;QAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAA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BAAgB,CAAC,GAChE,OAAO,CAAC,gBAAgB,CAAC;IAmC5B,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGnC"}
@@ -1,115 +0,0 @@
1
- import { SocialError } from "../core/errors.js";
2
- export class MemoryCredentialStore {
3
- #values = new Map();
4
- #sequence = 0;
5
- async get(key) {
6
- const found = this.#values.get(key);
7
- return found === undefined
8
- ? undefined
9
- : {
10
- value: {
11
- ...found.value,
12
- ...(found.value.scopes === undefined ? {} : { scopes: [...found.value.scopes] }),
13
- },
14
- revision: found.revision,
15
- };
16
- }
17
- async compareAndSet(input) {
18
- const current = this.#values.get(input.key);
19
- if ((current?.revision ?? undefined) !== input.expectedRevision)
20
- return { updated: false };
21
- const revision = `credential-${++this.#sequence}`;
22
- this.#values.set(input.key, {
23
- value: {
24
- ...input.value,
25
- ...(input.value.scopes === undefined ? {} : { scopes: [...input.value.scopes] }),
26
- },
27
- revision,
28
- });
29
- return { updated: true, revision };
30
- }
31
- async delete(key) {
32
- this.#values.delete(key);
33
- }
34
- }
35
- export class MemoryCredentialLock {
36
- #leases = new Map();
37
- #sequence = 0;
38
- async acquire(key, ttlMs) {
39
- const current = this.#leases.get(key);
40
- if (current !== undefined && Date.parse(current.expiresAt) > Date.now())
41
- return undefined;
42
- const lease = {
43
- key,
44
- token: `lease-${++this.#sequence}`,
45
- expiresAt: new Date(Date.now() + ttlMs).toISOString(),
46
- };
47
- this.#leases.set(key, lease);
48
- return lease;
49
- }
50
- async release(lease) {
51
- if (this.#leases.get(lease.key)?.token === lease.token)
52
- this.#leases.delete(lease.key);
53
- }
54
- }
55
- export class CredentialManager {
56
- store;
57
- lock;
58
- lockTtlMs;
59
- constructor(store, lock, lockTtlMs = 30_000) {
60
- this.store = store;
61
- this.lock = lock;
62
- this.lockTtlMs = lockTtlMs;
63
- }
64
- get(key) {
65
- return this.store.get(key);
66
- }
67
- async save(key, value, expectedRevision) {
68
- const result = await this.store.compareAndSet({ key, expectedRevision, value });
69
- if (!result.updated || result.revision === undefined)
70
- throw new SocialError({
71
- code: "upstream_failure",
72
- operation: "credentials.save",
73
- message: "Credential revision changed; reload before saving",
74
- });
75
- return result.revision;
76
- }
77
- async rotate(key, refresh) {
78
- const lease = await this.lock.acquire(key, this.lockTtlMs);
79
- if (lease === undefined)
80
- throw new SocialError({
81
- code: "upstream_failure",
82
- operation: "credentials.rotate",
83
- message: "Another worker is already refreshing this credential",
84
- });
85
- try {
86
- const current = await this.store.get(key);
87
- if (current === undefined)
88
- throw new SocialError({
89
- code: "reconnect_required",
90
- operation: "credentials.rotate",
91
- message: "No credential is stored for this account",
92
- });
93
- const next = await refresh(current.value);
94
- const saved = await this.store.compareAndSet({
95
- key,
96
- expectedRevision: current.revision,
97
- value: next,
98
- });
99
- if (!saved.updated)
100
- throw new SocialError({
101
- code: "upstream_failure",
102
- operation: "credentials.rotate",
103
- message: "Credential changed while refreshing; do not repeat the provider request blindly",
104
- });
105
- return next;
106
- }
107
- finally {
108
- await this.lock.release(lease);
109
- }
110
- }
111
- delete(key) {
112
- return this.store.delete(key);
113
- }
114
- }
115
- //# sourceMappingURL=credentials.js.map