@pierre/storage 0.0.3 → 0.0.6

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/dist/index.d.ts CHANGED
@@ -1,15 +1,17 @@
1
- /**
2
- * Pierre Git Storage SDK
3
- *
4
- * A TypeScript SDK for interacting with Pierre's git storage system
5
- */
6
1
  /**
7
2
  * Type definitions for Pierre Git Storage SDK
8
3
  */
9
- interface GitStorageOptions {
4
+ interface OverrideableGitStorageOptions {
5
+ apiBaseUrl?: string;
6
+ storageBaseUrl?: string;
7
+ apiVersion?: ValidAPIVersion;
8
+ }
9
+ interface GitStorageOptions extends OverrideableGitStorageOptions {
10
10
  key: string;
11
11
  name: string;
12
+ defaultTTL?: number;
12
13
  }
14
+ type ValidAPIVersion = 1;
13
15
  interface GetRemoteURLOptions {
14
16
  permissions?: ('git:write' | 'git:read' | 'repo:write')[];
15
17
  ttl?: number;
@@ -17,20 +19,281 @@ interface GetRemoteURLOptions {
17
19
  interface Repo {
18
20
  id: string;
19
21
  getRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
22
+ getFile(options: GetFileOptions): Promise<GetFileResponse>;
23
+ listFiles(options?: ListFilesOptions): Promise<ListFilesResponse>;
24
+ listBranches(options?: ListBranchesOptions): Promise<ListBranchesResponse>;
25
+ listCommits(options?: ListCommitsOptions): Promise<ListCommitsResponse>;
26
+ getBranchDiff(options: GetBranchDiffOptions): Promise<GetBranchDiffResponse>;
27
+ getCommitDiff(options: GetCommitDiffOptions): Promise<GetCommitDiffResponse>;
28
+ getCommit(options: GetCommitOptions): Promise<GetCommitResponse>;
29
+ }
30
+ type ValidMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
31
+ type SimplePath = string;
32
+ type ComplexPath = {
33
+ path: string;
34
+ params?: Record<string, string>;
35
+ body?: Record<string, any>;
36
+ };
37
+ type ValidPath = SimplePath | ComplexPath;
38
+ interface GitStorageInvocationOptions {
39
+ ttl?: number;
20
40
  }
21
41
  interface FindOneOptions {
22
42
  id: string;
23
43
  }
24
- interface CreateRepoOptions {
44
+ type SupportedRepoProvider = 'github';
45
+ interface BaseRepo {
46
+ /**
47
+ * @default github
48
+ */
49
+ provider?: SupportedRepoProvider;
50
+ owner: string;
51
+ name: string;
52
+ defaultBranch?: string;
53
+ }
54
+ interface CreateRepoOptions extends GitStorageInvocationOptions {
25
55
  id?: string;
56
+ baseRepo?: BaseRepo;
26
57
  }
27
58
  interface CreateRepoResponse {
28
59
  repo_id: string;
29
60
  url: string;
30
61
  }
62
+ interface GetFileOptions extends GitStorageInvocationOptions {
63
+ path: string;
64
+ ref?: string;
65
+ }
66
+ interface GetFileResponse {
67
+ path: string;
68
+ ref: string;
69
+ content: string;
70
+ size: number;
71
+ is_binary: boolean;
72
+ }
73
+ interface RepullOptions extends GitStorageInvocationOptions {
74
+ ref?: string;
75
+ }
76
+ interface ListFilesOptions extends GitStorageInvocationOptions {
77
+ ref?: string;
78
+ }
79
+ interface ListFilesResponse {
80
+ paths: string[];
81
+ ref: string;
82
+ }
83
+ interface ListBranchesOptions extends GitStorageInvocationOptions {
84
+ cursor?: string;
85
+ limit?: number;
86
+ }
87
+ interface BranchInfo {
88
+ cursor: string;
89
+ name: string;
90
+ head_sha: string;
91
+ created_at: string;
92
+ }
93
+ interface ListBranchesResponse {
94
+ branches: BranchInfo[];
95
+ next_cursor?: string;
96
+ has_more: boolean;
97
+ }
98
+ interface ListCommitsOptions extends GitStorageInvocationOptions {
99
+ branch?: string;
100
+ cursor?: string;
101
+ limit?: number;
102
+ }
103
+ interface CommitInfo {
104
+ sha: string;
105
+ message: string;
106
+ author_name: string;
107
+ author_email: string;
108
+ committer_name: string;
109
+ committer_email: string;
110
+ date: string;
111
+ }
112
+ interface ListCommitsResponse {
113
+ commits: CommitInfo[];
114
+ next_cursor?: string;
115
+ has_more: boolean;
116
+ }
117
+ interface GetBranchDiffOptions extends GitStorageInvocationOptions {
118
+ branch: string;
119
+ base?: string;
120
+ }
121
+ interface GetBranchDiffResponse {
122
+ branch: string;
123
+ base: string;
124
+ stats: DiffStats;
125
+ files: FileDiff[];
126
+ filtered_files: FilteredFile[];
127
+ }
128
+ interface GetCommitDiffOptions extends GitStorageInvocationOptions {
129
+ sha: string;
130
+ }
131
+ interface GetCommitDiffResponse {
132
+ sha: string;
133
+ stats: DiffStats;
134
+ files: FileDiff[];
135
+ filtered_files: FilteredFile[];
136
+ }
137
+ interface DiffStats {
138
+ files: number;
139
+ additions: number;
140
+ deletions: number;
141
+ changes: number;
142
+ }
143
+ interface FileDiff {
144
+ path: string;
145
+ state: string;
146
+ old_path?: string;
147
+ bytes: number;
148
+ is_eof: boolean;
149
+ diff: string;
150
+ }
151
+ interface FilteredFile {
152
+ path: string;
153
+ state: string;
154
+ old_path?: string;
155
+ bytes: number;
156
+ is_eof: boolean;
157
+ }
158
+ interface GetCommitOptions extends GitStorageInvocationOptions {
159
+ sha: string;
160
+ }
161
+ interface GetCommitResponse {
162
+ sha: string;
163
+ message: string;
164
+ author: {
165
+ name: string;
166
+ email: string;
167
+ };
168
+ committer: {
169
+ name: string;
170
+ email: string;
171
+ };
172
+ date: string;
173
+ stats: {
174
+ additions: number;
175
+ deletions: number;
176
+ total: number;
177
+ };
178
+ }
179
+ interface WebhookValidationOptions {
180
+ /**
181
+ * Maximum age of webhook in seconds (default: 300 seconds / 5 minutes)
182
+ * Set to 0 to disable timestamp validation
183
+ */
184
+ maxAgeSeconds?: number;
185
+ }
186
+ interface WebhookValidationResult {
187
+ /**
188
+ * Whether the webhook signature and timestamp are valid
189
+ */
190
+ valid: boolean;
191
+ /**
192
+ * Error message if validation failed
193
+ */
194
+ error?: string;
195
+ /**
196
+ * The parsed webhook event type (e.g., "push")
197
+ */
198
+ eventType?: string;
199
+ /**
200
+ * The timestamp from the signature (Unix seconds)
201
+ */
202
+ timestamp?: number;
203
+ }
204
+ interface WebhookPushEvent {
205
+ repository: {
206
+ id: string;
207
+ url: string;
208
+ };
209
+ ref: string;
210
+ before: string;
211
+ after: string;
212
+ customer_id: string;
213
+ pushed_at: string;
214
+ }
215
+ type WebhookEventPayload = WebhookPushEvent;
216
+ interface ParsedWebhookSignature {
217
+ timestamp: string;
218
+ signature: string;
219
+ }
220
+
221
+ /**
222
+ * Webhook validation utilities for Pierre Git Storage
223
+ */
224
+
225
+ /**
226
+ * Parse the X-Pierre-Signature header
227
+ * Format: t=<timestamp>,sha256=<signature>
228
+ */
229
+ declare function parseSignatureHeader(header: string): ParsedWebhookSignature | null;
230
+ /**
231
+ * Validate a webhook signature and timestamp
232
+ *
233
+ * @param payload - The raw webhook payload (request body)
234
+ * @param signatureHeader - The X-Pierre-Signature header value
235
+ * @param secret - The webhook secret for HMAC verification
236
+ * @param options - Validation options
237
+ * @returns Validation result with details
238
+ *
239
+ * @example
240
+ * ```typescript
241
+ * const result = await validateWebhookSignature(
242
+ * requestBody,
243
+ * request.headers['x-pierre-signature'],
244
+ * webhookSecret
245
+ * );
246
+ *
247
+ * if (!result.valid) {
248
+ * console.error('Invalid webhook:', result.error);
249
+ * return;
250
+ * }
251
+ * ```
252
+ */
253
+ declare function validateWebhookSignature(payload: string | Buffer, signatureHeader: string, secret: string, options?: WebhookValidationOptions): Promise<WebhookValidationResult>;
254
+ /**
255
+ * Validate a webhook request
256
+ *
257
+ * This is a convenience function that validates the signature and parses the payload.
258
+ *
259
+ * @param payload - The raw webhook payload (request body)
260
+ * @param headers - The request headers (must include x-pierre-signature and x-pierre-event)
261
+ * @param secret - The webhook secret for HMAC verification
262
+ * @param options - Validation options
263
+ * @returns The parsed webhook payload if valid, or validation error
264
+ *
265
+ * @example
266
+ * ```typescript
267
+ * const result = await validateWebhook(
268
+ * request.body,
269
+ * request.headers,
270
+ * process.env.WEBHOOK_SECRET
271
+ * );
272
+ *
273
+ * if (!result.valid) {
274
+ * return new Response('Invalid webhook', { status: 401 });
275
+ * }
276
+ *
277
+ * // Type-safe access to the webhook payload
278
+ * console.log('Push event:', result.payload);
279
+ * ```
280
+ */
281
+ declare function validateWebhook(payload: string | Buffer, headers: Record<string, string | string[] | undefined>, secret: string, options?: WebhookValidationOptions): Promise<WebhookValidationResult & {
282
+ payload?: WebhookEventPayload;
283
+ }>;
284
+
285
+ /**
286
+ * Pierre Git Storage SDK
287
+ *
288
+ * A TypeScript SDK for interacting with Pierre's git storage system
289
+ */
290
+
31
291
  declare class GitStorage {
292
+ private static overrides;
32
293
  private options;
294
+ private api;
33
295
  constructor(options: GitStorageOptions);
296
+ static override(options: OverrideableGitStorageOptions): void;
34
297
  /**
35
298
  * Create a new repository
36
299
  * @returns The created repository
@@ -56,4 +319,4 @@ declare class GitStorage {
56
319
  declare function createClient(options: GitStorageOptions): GitStorage;
57
320
  type StorageOptions = GitStorageOptions;
58
321
 
59
- export { type CreateRepoOptions, type CreateRepoResponse, type FindOneOptions, type GetRemoteURLOptions, GitStorage, type GitStorageOptions, type Repo, type StorageOptions, createClient };
322
+ export { type BaseRepo, type BranchInfo, type CommitInfo, type CreateRepoOptions, type CreateRepoResponse, type DiffStats, type FileDiff, type FilteredFile, type FindOneOptions, type GetBranchDiffOptions, type GetBranchDiffResponse, type GetCommitDiffOptions, type GetCommitDiffResponse, type GetCommitOptions, type GetCommitResponse, type GetFileOptions, type GetFileResponse, type GetRemoteURLOptions, GitStorage, type GitStorageOptions, type ListBranchesOptions, type ListBranchesResponse, type ListCommitsOptions, type ListCommitsResponse, type ListFilesOptions, type ListFilesResponse, type OverrideableGitStorageOptions, type ParsedWebhookSignature, type Repo, type RepullOptions, type StorageOptions, type SupportedRepoProvider, type ValidAPIVersion, type ValidMethod, type ValidPath, type WebhookEventPayload, type WebhookPushEvent, type WebhookValidationOptions, type WebhookValidationResult, createClient, parseSignatureHeader, validateWebhook, validateWebhookSignature };