@retainer/extension 0.1.0 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retainer/extension",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Build-time contracts for reviewed Retainer extensions",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/Tamloot-cc/Retainer/tree/main/packages/extension#readme",
@@ -21,9 +21,13 @@
21
21
  "types": "./dist/index.d.ts",
22
22
  "default": "./dist/index.js"
23
23
  },
24
- "./nango-gmail": {
25
- "types": "./dist/nango-gmail.d.ts",
26
- "default": "./dist/nango-gmail.js"
24
+ "./gmail-provider": {
25
+ "types": "./dist/gmail-provider.d.ts",
26
+ "default": "./dist/gmail-provider.js"
27
+ },
28
+ "./model": {
29
+ "types": "./dist/model.d.ts",
30
+ "default": "./dist/model.js"
27
31
  }
28
32
  },
29
33
  "files": [
@@ -34,10 +38,20 @@
34
38
  "provenance": true
35
39
  },
36
40
  "dependencies": {
37
- "@anthropic-ai/sdk": "^1.8.0",
38
- "@retainer/shared": "0.1.0",
41
+ "@retainer/shared": "0.2.0",
39
42
  "zod": "^4.6.7"
40
43
  },
44
+ "peerDependencies": {
45
+ "@anthropic-ai/sdk": "^1.12.0"
46
+ },
47
+ "peerDependenciesMeta": {
48
+ "@anthropic-ai/sdk": {
49
+ "optional": true
50
+ }
51
+ },
52
+ "devDependencies": {
53
+ "@anthropic-ai/sdk": "^1.14.0"
54
+ },
41
55
  "scripts": {
42
56
  "build": "tsc -p tsconfig.json",
43
57
  "typecheck": "tsc -p tsconfig.json --noEmit",
@@ -1,56 +0,0 @@
1
- import { z } from 'zod';
2
- export declare const gmailRegistrationId = "4c60fc8e-45f9-49c8-919e-5c05c947a9aa";
3
- export declare const nangoOrigin = "https://api.nango.dev";
4
- export declare const nangoId: z.ZodString;
5
- /**
6
- * The Nango integration Gmail connects through. It belongs to the operator's Nango
7
- * environment, like the keys, so it comes from the server environment, not a
8
- * workspace setting.
9
- */
10
- export declare function nangoGmailIntegrationId(env?: NodeJS.ProcessEnv): string | null;
11
- export declare class GmailProviderError extends Error {
12
- readonly code: 'provider_unauthorized' | 'provider_forbidden' | 'provider_rate_limited' | 'provider_unavailable' | 'provider_invalid_request' | 'provider_invalid_response' | 'provider_content_too_large' | 'provider_identity_mismatch' | 'provider_connection_unavailable' | 'provider_scope_missing' | 'provider_scope_excessive';
13
- readonly retry: boolean;
14
- constructor(code: 'provider_unauthorized' | 'provider_forbidden' | 'provider_rate_limited' | 'provider_unavailable' | 'provider_invalid_request' | 'provider_invalid_response' | 'provider_content_too_large' | 'provider_identity_mismatch' | 'provider_connection_unavailable' | 'provider_scope_missing' | 'provider_scope_excessive', retry?: boolean);
15
- }
16
- export declare function readResponse<T>(response: Response, schema: z.ZodType<T>, signal: AbortSignal, limit?: number): Promise<T>;
17
- export type NangoGmailConfig = {
18
- apiKey: string;
19
- integrationId: string;
20
- };
21
- export type NangoGmailConnection = NangoGmailConfig & {
22
- connectionId: string;
23
- };
24
- export type ConnectAttempt = {
25
- workspaceId: string;
26
- memberId: string;
27
- attemptId: string;
28
- };
29
- export declare function nangoGmailAttemptTags(attempt: ConnectAttempt): {
30
- organization_id: string;
31
- end_user_id: string;
32
- retainer_attempt_id: string;
33
- };
34
- export declare function assertConnectionConfig(connection: NangoGmailConnection): void;
35
- export declare function nangoRequest(url: URL, headers: Record<string, string>, signal: AbortSignal, transport: typeof fetch, body?: Record<string, unknown>): Promise<Response>;
36
- export declare function nangoFailure(response: Response, signal: AbortSignal, mailboxRequest?: boolean): Promise<string>;
37
- /** Start authorization for a pending attempt created by the Retainer backend. */
38
- export declare function createNangoGmailConnectSession(config: NangoGmailConfig, attempt: ConnectAttempt, signal: AbortSignal, transport?: typeof fetch): Promise<{
39
- connectLink: string;
40
- sessionToken: string;
41
- integrationId: string;
42
- expiresAt: string;
43
- }>;
44
- /** Check Google's granted scopes and, at enrollment, the pending attempt's owner tags.
45
- * With no attempt, the caller must supply a connection already bound to its Retainer owner.
46
- * Use a trusted control key here. The runtime key needs no credential-read scope.
47
- */
48
- export declare function verifyNangoGmailGrant(connection: NangoGmailConnection & {
49
- attempt?: ConnectAttempt;
50
- }, signal: AbortSignal, transport?: typeof fetch): Promise<void>;
51
- /** Return only connections with the exact integration and attempt tags. */
52
- export declare function listNangoGmailAttemptConnections(config: NangoGmailConfig, tags: ReturnType<typeof nangoGmailAttemptTags>, signal: AbortSignal, transport?: typeof fetch): Promise<string[]>;
53
- /** Only consider connections created by this pending attempt. Verify their grant separately. */
54
- export declare function findNangoGmailConnection(config: NangoGmailConfig, attempt: ConnectAttempt, signal: AbortSignal, transport?: typeof fetch): Promise<string | null>;
55
- /** Delete this dedicated connection. A prior successful deletion can be retried. */
56
- export declare function deleteNangoGmailConnection(connection: NangoGmailConnection, signal: AbortSignal, transport?: typeof fetch): Promise<void>;
@@ -1,244 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import { z } from 'zod';
3
- export const gmailRegistrationId = '4c60fc8e-45f9-49c8-919e-5c05c947a9aa';
4
- export const nangoOrigin = 'https://api.nango.dev';
5
- const readOnlyScope = 'https://www.googleapis.com/auth/gmail.readonly';
6
- const identityScopes = new Set(['openid', 'https://www.googleapis.com/auth/userinfo.email']);
7
- export const nangoId = z.string().regex(/^[A-Za-z0-9_-]{1,255}$/);
8
- /**
9
- * The Nango integration Gmail connects through. It belongs to the operator's Nango
10
- * environment, like the keys, so it comes from the server environment, not a
11
- * workspace setting.
12
- */
13
- export function nangoGmailIntegrationId(env = process.env) {
14
- const parsed = nangoId.safeParse(env.RETAINER_GMAIL_NANGO_INTEGRATION_ID || 'google-mail');
15
- return parsed.success ? parsed.data : null;
16
- }
17
- const maxResponseBytes = 4 * 1024 * 1024;
18
- const nangoGrant = z.object({
19
- connection_id: nangoId,
20
- provider_config_key: nangoId,
21
- provider: z.literal('google-mail'),
22
- tags: z.record(z.string(), z.string()).optional(),
23
- credentials: z.object({
24
- type: z.literal('OAUTH2'),
25
- raw: z.object({ scope: z.string().optional() }).optional(),
26
- }),
27
- });
28
- const apiError = z.object({
29
- error: z.object({
30
- code: z.union([z.number().int(), z.string()]).optional(),
31
- errors: z.array(z.object({ reason: z.string() })).default([]),
32
- }),
33
- });
34
- export class GmailProviderError extends Error {
35
- code;
36
- retry;
37
- constructor(code, retry = false) {
38
- super(code);
39
- this.code = code;
40
- this.retry = retry;
41
- }
42
- }
43
- export async function readResponse(response, schema, signal, limit = maxResponseBytes) {
44
- const reader = response.body?.getReader();
45
- if (!reader)
46
- throw new GmailProviderError('provider_invalid_response');
47
- const chunks = [];
48
- let bytes = 0;
49
- try {
50
- for (;;) {
51
- const chunk = await reader.read();
52
- if (chunk.done)
53
- break;
54
- bytes += chunk.value.length;
55
- if (bytes > limit)
56
- throw new GmailProviderError('provider_content_too_large');
57
- chunks.push(chunk.value);
58
- }
59
- return schema.parse(JSON.parse(Buffer.concat(chunks).toString('utf8')));
60
- }
61
- catch (error) {
62
- if (error instanceof GmailProviderError)
63
- throw error;
64
- if (signal.aborted)
65
- throw new GmailProviderError('provider_unavailable', true);
66
- // Provider bodies, URLs, and schema errors may carry mailbox data.
67
- throw new GmailProviderError('provider_invalid_response');
68
- }
69
- finally {
70
- await reader.cancel().catch(() => { });
71
- reader.releaseLock();
72
- }
73
- }
74
- export function nangoGmailAttemptTags(attempt) {
75
- const tags = {
76
- organization_id: attempt.workspaceId,
77
- end_user_id: createHash('sha256')
78
- .update(JSON.stringify([attempt.workspaceId, attempt.memberId]))
79
- .digest('hex'),
80
- retainer_attempt_id: attempt.attemptId,
81
- };
82
- if (!Object.values(tags).every((value) => nangoId.safeParse(value).success))
83
- throw new GmailProviderError('provider_invalid_request');
84
- return tags;
85
- }
86
- export function assertConnectionConfig(connection) {
87
- if (!connection.apiKey ||
88
- !nangoId.safeParse(connection.integrationId).success ||
89
- !nangoId.safeParse(connection.connectionId).success)
90
- throw new GmailProviderError('provider_invalid_request');
91
- }
92
- export async function nangoRequest(url, headers, signal, transport, body) {
93
- try {
94
- return await transport(url, {
95
- method: body ? 'POST' : 'GET',
96
- headers: body ? { ...headers, 'content-type': 'application/json' } : headers,
97
- body: body ? JSON.stringify(body) : undefined,
98
- redirect: 'error',
99
- signal,
100
- });
101
- }
102
- catch {
103
- throw new GmailProviderError('provider_unavailable', true);
104
- }
105
- }
106
- export async function nangoFailure(response, signal, mailboxRequest = false) {
107
- const body = await readResponse(response, apiError, signal, 64 * 1024).catch(() => undefined);
108
- if (signal.aborted)
109
- throw new GmailProviderError('provider_unavailable', true);
110
- const code = body?.error.code;
111
- if (response.status === 404 && mailboxRequest && code === 404)
112
- return 'gmail_not_found';
113
- if (response.status === 404 || response.status === 424 || code === 'invalid_credentials')
114
- throw new GmailProviderError('provider_connection_unavailable');
115
- if (response.status === 401 ||
116
- (mailboxRequest &&
117
- response.status === 403 &&
118
- body?.error.errors.some(({ reason }) => reason === 'insufficientPermissions')))
119
- throw new GmailProviderError('provider_unauthorized');
120
- if (response.status === 429 ||
121
- body?.error.errors.some(({ reason }) => ['rateLimitExceeded', 'userRateLimitExceeded'].includes(reason)))
122
- throw new GmailProviderError('provider_rate_limited', true);
123
- if (response.status === 403)
124
- throw new GmailProviderError('provider_forbidden');
125
- if (response.status >= 500)
126
- throw new GmailProviderError('provider_unavailable', true);
127
- throw new GmailProviderError('provider_invalid_request');
128
- }
129
- const connectSession = z.object({
130
- data: z.object({
131
- token: z.string().min(1),
132
- connect_link: z.url().refine((value) => {
133
- const url = new URL(value);
134
- return (url.protocol === 'https:' &&
135
- ['connect.nango.dev', 'app.nango.dev'].includes(url.hostname) &&
136
- !url.username &&
137
- !url.password &&
138
- !url.port);
139
- }),
140
- expires_at: z.iso.datetime({ offset: true }),
141
- }),
142
- });
143
- /** Start authorization for a pending attempt created by the Retainer backend. */
144
- export async function createNangoGmailConnectSession(config, attempt, signal, transport = fetch) {
145
- if (!config.apiKey || !nangoId.safeParse(config.integrationId).success)
146
- throw new GmailProviderError('provider_invalid_request');
147
- const timeout = AbortSignal.any([signal, AbortSignal.timeout(20000)]);
148
- const response = await nangoRequest(new URL('/connect/sessions', nangoOrigin), { authorization: `Bearer ${config.apiKey}` }, timeout, transport, {
149
- allowed_integrations: [config.integrationId],
150
- integrations_config_defaults: {
151
- [config.integrationId]: { connection_config: { oauth_scopes_override: readOnlyScope } },
152
- },
153
- tags: nangoGmailAttemptTags(attempt),
154
- });
155
- if (!response.ok)
156
- await nangoFailure(response, timeout);
157
- const { data } = await readResponse(response, connectSession, timeout, 64 * 1024);
158
- return {
159
- connectLink: data.connect_link,
160
- sessionToken: data.token,
161
- integrationId: config.integrationId,
162
- expiresAt: data.expires_at,
163
- };
164
- }
165
- /** Check Google's granted scopes and, at enrollment, the pending attempt's owner tags.
166
- * With no attempt, the caller must supply a connection already bound to its Retainer owner.
167
- * Use a trusted control key here. The runtime key needs no credential-read scope.
168
- */
169
- export async function verifyNangoGmailGrant(connection, signal, transport = fetch) {
170
- assertConnectionConfig(connection);
171
- const expectedTags = connection.attempt && nangoGmailAttemptTags(connection.attempt);
172
- const url = new URL(`/connections/${connection.connectionId}`, nangoOrigin);
173
- url.searchParams.set('provider_config_key', connection.integrationId);
174
- const timeout = AbortSignal.any([signal, AbortSignal.timeout(20000)]);
175
- const response = await nangoRequest(url, { authorization: `Bearer ${connection.apiKey}` }, timeout, transport);
176
- if (!response.ok)
177
- await nangoFailure(response, timeout);
178
- const grant = await readResponse(response, nangoGrant, timeout, 64 * 1024);
179
- if (grant.connection_id !== connection.connectionId ||
180
- grant.provider_config_key !== connection.integrationId ||
181
- (expectedTags &&
182
- Object.entries(expectedTags).some(([name, value]) => grant.tags?.[name] !== value)))
183
- throw new GmailProviderError('provider_identity_mismatch');
184
- const scopes = new Set(grant.credentials.raw?.scope?.split(/\s+/).filter(Boolean));
185
- if (!scopes.delete(readOnlyScope))
186
- throw new GmailProviderError('provider_scope_missing');
187
- if ([...scopes].some((scope) => !identityScopes.has(scope)))
188
- throw new GmailProviderError('provider_scope_excessive');
189
- }
190
- const connectionsPage = z.object({
191
- connections: z.array(z.object({
192
- connection_id: nangoId,
193
- provider_config_key: nangoId,
194
- provider: z.string(),
195
- tags: z.record(z.string(), z.string()).nullable().optional(),
196
- })),
197
- });
198
- /** Return only connections with the exact integration and attempt tags. */
199
- export async function listNangoGmailAttemptConnections(config, tags, signal, transport = fetch) {
200
- const url = new URL('/connections', nangoOrigin);
201
- url.searchParams.set('limit', '3');
202
- for (const [name, value] of Object.entries(tags))
203
- url.searchParams.set(`tags[${name}]`, value);
204
- const timeout = AbortSignal.any([signal, AbortSignal.timeout(20000)]);
205
- const response = await nangoRequest(url, { authorization: `Bearer ${config.apiKey}` }, timeout, transport);
206
- if (!response.ok)
207
- await nangoFailure(response, timeout);
208
- const result = await readResponse(response, connectionsPage, timeout, 128 * 1024);
209
- return result.connections
210
- .filter((row) => row.provider === 'google-mail' &&
211
- row.provider_config_key === config.integrationId &&
212
- Object.entries(tags).every(([name, value]) => row.tags?.[name] === value))
213
- .map((row) => row.connection_id);
214
- }
215
- /** Only consider connections created by this pending attempt. Verify their grant separately. */
216
- export async function findNangoGmailConnection(config, attempt, signal, transport = fetch) {
217
- const matches = await listNangoGmailAttemptConnections(config, nangoGmailAttemptTags(attempt), signal, transport);
218
- if (matches.length > 1)
219
- throw new GmailProviderError('provider_identity_mismatch');
220
- return matches[0] ?? null;
221
- }
222
- /** Delete this dedicated connection. A prior successful deletion can be retried. */
223
- export async function deleteNangoGmailConnection(connection, signal, transport = fetch) {
224
- assertConnectionConfig(connection);
225
- const url = new URL(`/connections/${connection.connectionId}`, nangoOrigin);
226
- url.searchParams.set('provider_config_key', connection.integrationId);
227
- const timeout = AbortSignal.any([signal, AbortSignal.timeout(20000)]);
228
- let response;
229
- try {
230
- response = await transport(url, {
231
- method: 'DELETE',
232
- redirect: 'error',
233
- signal: timeout,
234
- headers: { authorization: `Bearer ${connection.apiKey}` },
235
- });
236
- }
237
- catch {
238
- throw new GmailProviderError('provider_unavailable', true);
239
- }
240
- if (!response.ok && response.status !== 404)
241
- await nangoFailure(response, timeout);
242
- await response.body?.cancel().catch(() => { });
243
- }
244
- //# sourceMappingURL=nango-gmail.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nango-gmail.js","sourceRoot":"","sources":["../src/nango-gmail.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,mBAAmB,GAAG,sCAAsC,CAAC;AAC1E,MAAM,CAAC,MAAM,WAAW,GAAG,uBAAuB,CAAC;AACnD,MAAM,aAAa,GAAG,gDAAgD,CAAC;AACvE,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,gDAAgD,CAAC,CAAC,CAAC;AAC7F,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;AAElE;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,GAAG,GAAsB,OAAO,CAAC,GAAG;IAC1E,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,mCAAmC,IAAI,aAAa,CAAC,CAAC;IAC3F,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7C,CAAC;AACD,MAAM,gBAAgB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AACzC,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1B,aAAa,EAAE,OAAO;IACtB,mBAAmB,EAAE,OAAO;IAC5B,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC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