@pierre/storage 0.2.2 → 0.3.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,39 +1,40 @@
1
1
  {
2
- "name": "@pierre/storage",
3
- "version": "0.2.2",
4
- "description": "Pierre Git Storage SDK",
5
- "license": "MIT",
6
- "type": "module",
7
- "main": "./dist/index.cjs",
8
- "module": "./dist/index.js",
9
- "types": "./dist/index.d.ts",
10
- "exports": {
11
- ".": {
12
- "types": "./dist/index.d.ts",
13
- "import": "./dist/index.js",
14
- "require": "./dist/index.cjs",
15
- "default": "./dist/index.js"
16
- }
17
- },
18
- "files": [
19
- "dist",
20
- "src"
21
- ],
22
- "dependencies": {
23
- "jose": "^5.10.0",
24
- "snakecase-keys": "^9.0.2",
25
- "zod": "^3.23.8"
26
- },
27
- "devDependencies": {
28
- "tsup": "8.5.0",
29
- "typescript": "5.8.3",
30
- "vitest": "3.2.4"
31
- },
32
- "publishConfig": {
33
- "access": "public"
34
- },
35
- "scripts": {
36
- "build": "tsup",
37
- "dev": "tsup --watch"
38
- }
39
- }
2
+ "name": "@pierre/storage",
3
+ "version": "0.3.0",
4
+ "description": "Pierre Git Storage SDK",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.cjs",
15
+ "default": "./dist/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "src"
21
+ ],
22
+ "scripts": {
23
+ "build": "tsup",
24
+ "dev": "tsup --watch",
25
+ "prepublishOnly": "pnpm build"
26
+ },
27
+ "dependencies": {
28
+ "jose": "^5.10.0",
29
+ "snakecase-keys": "^9.0.2",
30
+ "zod": "^3.23.8"
31
+ },
32
+ "devDependencies": {
33
+ "tsup": "8.5.0",
34
+ "typescript": "5.8.3",
35
+ "vitest": "3.2.4"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ }
40
+ }
package/src/commit.ts CHANGED
@@ -20,6 +20,7 @@ import type {
20
20
  CreateCommitOptions,
21
21
  LegacyCreateCommitOptions,
22
22
  } from './types';
23
+ import { getUserAgent } from './version';
23
24
 
24
25
  const DEFAULT_TTL_SECONDS = 60 * 60;
25
26
  const HEADS_REF_PREFIX = 'refs/heads/';
@@ -294,6 +295,7 @@ export class FetchCommitTransport implements CommitTransport {
294
295
  Authorization: `Bearer ${request.authorization}`,
295
296
  'Content-Type': 'application/x-ndjson',
296
297
  Accept: 'application/json',
298
+ 'Code-Storage-Agent': getUserAgent(),
297
299
  },
298
300
  body: body as any,
299
301
  signal: request.signal,
@@ -16,6 +16,7 @@ import type {
16
16
  CreateCommitFromDiffOptions,
17
17
  DiffSource,
18
18
  } from './types';
19
+ import { getUserAgent } from './version';
19
20
 
20
21
  interface DiffCommitMetadataPayload {
21
22
  target_branch: string;
@@ -190,6 +191,7 @@ export class FetchDiffCommitTransport implements DiffCommitTransport {
190
191
  Authorization: `Bearer ${request.authorization}`,
191
192
  'Content-Type': 'application/x-ndjson',
192
193
  Accept: 'application/json',
194
+ 'Code-Storage-Agent': getUserAgent(),
193
195
  },
194
196
  body: body as any,
195
197
  signal: request.signal,
package/src/fetch.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { errorEnvelopeSchema } from './schemas';
2
2
  import type { ValidAPIVersion, ValidMethod, ValidPath } from './types';
3
+ import { getUserAgent } from './version';
3
4
 
4
5
  interface RequestOptions {
5
6
  allowedStatus?: number[];
@@ -59,6 +60,7 @@ export class ApiFetcher {
59
60
  headers: {
60
61
  Authorization: `Bearer ${jwt}`,
61
62
  'Content-Type': 'application/json',
63
+ 'Code-Storage-Agent': getUserAgent(),
62
64
  },
63
65
  };
64
66
 
package/src/index.ts CHANGED
@@ -53,7 +53,6 @@ import type {
53
53
  ListCommitsResult,
54
54
  ListFilesOptions,
55
55
  ListFilesResult,
56
- OverrideableGitStorageOptions,
57
56
  PullUpstreamOptions,
58
57
  RawBranchInfo,
59
58
  RawCommitInfo,
@@ -346,14 +345,20 @@ class RepoImpl implements Repo {
346
345
  ) => Promise<string>,
347
346
  ) {
348
347
  this.api = getApiInstance(
349
- this.options.apiBaseUrl ?? API_BASE_URL,
348
+ this.options.apiBaseUrl ?? GitStorage.getDefaultAPIBaseUrl(options.name),
350
349
  this.options.apiVersion ?? API_VERSION,
351
350
  );
352
351
  }
353
352
 
354
353
  async getRemoteURL(urlOptions?: GetRemoteURLOptions): Promise<string> {
355
- const storageBaseUrl = this.options.storageBaseUrl ?? STORAGE_BASE_URL;
356
- const url = new URL(`https://${this.options.name}.${storageBaseUrl}/${this.id}.git`);
354
+ const url = new URL(`https://${this.options.storageBaseUrl}/${this.id}.git`);
355
+ url.username = `t`;
356
+ url.password = await this.generateJWT(this.id, urlOptions);
357
+ return url.toString();
358
+ }
359
+
360
+ async getEphemeralRemoteURL(urlOptions?: GetRemoteURLOptions): Promise<string> {
361
+ const url = new URL(`https://${this.options.storageBaseUrl}/${this.id}+ephemeral.git`);
357
362
  url.username = `t`;
358
363
  url.password = await this.generateJWT(this.id, urlOptions);
359
364
  return url.toString();
@@ -376,6 +381,9 @@ class RepoImpl implements Repo {
376
381
  if (typeof options.ephemeral === 'boolean') {
377
382
  params.ephemeral = String(options.ephemeral);
378
383
  }
384
+ if (typeof options.ephemeralBase === 'boolean') {
385
+ params.ephemeral_base = String(options.ephemeralBase);
386
+ }
379
387
 
380
388
  // Return the raw fetch Response for streaming
381
389
  return this.api.get({ path: 'repos/file', params }, jwt);
@@ -480,6 +488,12 @@ class RepoImpl implements Repo {
480
488
  if (options.base) {
481
489
  params.base = options.base;
482
490
  }
491
+ if (typeof options.ephemeral === 'boolean') {
492
+ params.ephemeral = String(options.ephemeral);
493
+ }
494
+ if (typeof options.ephemeralBase === 'boolean') {
495
+ params.ephemeral_base = String(options.ephemeralBase);
496
+ }
483
497
 
484
498
  const response = await this.api.get({ path: 'repos/branches/diff', params }, jwt);
485
499
 
@@ -498,6 +512,10 @@ class RepoImpl implements Repo {
498
512
  sha: options.sha,
499
513
  };
500
514
 
515
+ if (options.baseSha) {
516
+ params.baseSha = options.baseSha;
517
+ }
518
+
501
519
  const response = await this.api.get({ path: 'repos/diff', params }, jwt);
502
520
 
503
521
  const raw = commitDiffResponseSchema.parse(await response.json());
@@ -645,7 +663,7 @@ class RepoImpl implements Repo {
645
663
 
646
664
  createCommit(options: CreateCommitOptions): CommitBuilder {
647
665
  const version = this.options.apiVersion ?? API_VERSION;
648
- const baseUrl = this.options.apiBaseUrl ?? API_BASE_URL;
666
+ const baseUrl = this.options.apiBaseUrl ?? GitStorage.getDefaultAPIBaseUrl(this.options.name);
649
667
  const transport = new FetchCommitTransport({ baseUrl, version });
650
668
  const ttl = resolveCommitTtlSeconds(options);
651
669
  const builderOptions: CreateCommitOptions = {
@@ -667,7 +685,7 @@ class RepoImpl implements Repo {
667
685
 
668
686
  async createCommitFromDiff(options: CreateCommitFromDiffOptions): Promise<CommitResult> {
669
687
  const version = this.options.apiVersion ?? API_VERSION;
670
- const baseUrl = this.options.apiBaseUrl ?? API_BASE_URL;
688
+ const baseUrl = this.options.apiBaseUrl ?? GitStorage.getDefaultAPIBaseUrl(this.options.name);
671
689
  const transport = new FetchDiffCommitTransport({ baseUrl, version });
672
690
  const ttl = resolveCommitTtlSeconds(options);
673
691
  const requestOptions: CreateCommitFromDiffOptions = {
@@ -689,7 +707,6 @@ class RepoImpl implements Repo {
689
707
  }
690
708
 
691
709
  export class GitStorage {
692
- private static overrides: OverrideableGitStorageOptions = {};
693
710
  private options: GitStorageOptions;
694
711
  private api: ApiFetcher;
695
712
 
@@ -714,12 +731,11 @@ export class GitStorage {
714
731
  throw new Error('GitStorage key must be a non-empty string.');
715
732
  }
716
733
 
717
- const resolvedApiBaseUrl =
718
- options.apiBaseUrl ?? GitStorage.overrides.apiBaseUrl ?? API_BASE_URL;
719
- const resolvedApiVersion = options.apiVersion ?? GitStorage.overrides.apiVersion ?? API_VERSION;
734
+ const resolvedApiBaseUrl = options.apiBaseUrl ?? GitStorage.getDefaultAPIBaseUrl(options.name);
735
+ const resolvedApiVersion = options.apiVersion ?? API_VERSION;
720
736
  const resolvedStorageBaseUrl =
721
- options.storageBaseUrl ?? GitStorage.overrides.storageBaseUrl ?? STORAGE_BASE_URL;
722
- const resolvedDefaultTtl = options.defaultTTL ?? GitStorage.overrides.defaultTTL;
737
+ options.storageBaseUrl ?? GitStorage.getDefaultStorageBaseUrl(options.name);
738
+ const resolvedDefaultTtl = options.defaultTTL;
723
739
 
724
740
  this.api = getApiInstance(resolvedApiBaseUrl, resolvedApiVersion);
725
741
 
@@ -733,8 +749,12 @@ export class GitStorage {
733
749
  };
734
750
  }
735
751
 
736
- static override(options: OverrideableGitStorageOptions): void {
737
- this.overrides = Object.assign({}, this.overrides, options);
752
+ static getDefaultAPIBaseUrl(name: string): string {
753
+ return API_BASE_URL.replace('{{org}}', name);
754
+ }
755
+
756
+ static getDefaultStorageBaseUrl(name: string): string {
757
+ return STORAGE_BASE_URL.replace('{{org}}', name);
738
758
  }
739
759
 
740
760
  /**
@@ -845,5 +865,8 @@ export function createClient(options: GitStorageOptions): GitStorage {
845
865
  return new GitStorage(options);
846
866
  }
847
867
 
868
+ // Export CodeStorage as an alias for GitStorage
869
+ export { GitStorage as CodeStorage };
870
+
848
871
  // Type alias for backward compatibility
849
872
  export type StorageOptions = GitStorageOptions;
package/src/types.ts CHANGED
@@ -38,6 +38,7 @@ export interface GetRemoteURLOptions {
38
38
  export interface Repo {
39
39
  id: string;
40
40
  getRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
41
+ getEphemeralRemoteURL(options?: GetRemoteURLOptions): Promise<string>;
41
42
 
42
43
  getFileStream(options: GetFileOptions): Promise<Response>;
43
44
  listFiles(options?: ListFilesOptions): Promise<ListFilesResult>;
@@ -92,6 +93,7 @@ export interface GetFileOptions extends GitStorageInvocationOptions {
92
93
  path: string;
93
94
  ref?: string;
94
95
  ephemeral?: boolean;
96
+ ephemeralBase?: boolean;
95
97
  }
96
98
 
97
99
  export interface PullUpstreamOptions extends GitStorageInvocationOptions {
@@ -183,6 +185,8 @@ export interface ListCommitsResult {
183
185
  export interface GetBranchDiffOptions extends GitStorageInvocationOptions {
184
186
  branch: string;
185
187
  base?: string;
188
+ ephemeral?: boolean;
189
+ ephemeralBase?: boolean;
186
190
  }
187
191
 
188
192
  export type GetBranchDiffResponse = GetBranchDiffResponseRaw;
@@ -198,6 +202,7 @@ export interface GetBranchDiffResult {
198
202
  // Commit Diff API types
199
203
  export interface GetCommitDiffOptions extends GitStorageInvocationOptions {
200
204
  sha: string;
205
+ baseSha?: string;
201
206
  }
202
207
 
203
208
  export type GetCommitDiffResponse = GetCommitDiffResponseRaw;
package/src/version.ts ADDED
@@ -0,0 +1,8 @@
1
+ import packageJson from '../package.json';
2
+
3
+ export const PACKAGE_NAME = 'code-storage-sdk';
4
+ export const PACKAGE_VERSION = packageJson.version;
5
+
6
+ export function getUserAgent(): string {
7
+ return `${PACKAGE_NAME}/${PACKAGE_VERSION}`;
8
+ }