@meistrari/vault-sdk 0.0.2 → 0.0.4

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.
@@ -0,0 +1,47 @@
1
+ interface AuthStrategy {
2
+ getHeaders: () => Headers;
3
+ }
4
+ declare class DataTokenAuthStrategy implements AuthStrategy {
5
+ dataToken: string;
6
+ getHeaders(): Headers;
7
+ constructor(dataToken: string);
8
+ }
9
+ declare class APIKeyAuthStrategy implements AuthStrategy {
10
+ apiKey: string;
11
+ getHeaders(): Headers;
12
+ constructor(apiKey: string);
13
+ }
14
+
15
+ type FetchParams = {
16
+ method: 'GET' | 'POST' | 'PUT';
17
+ path: string;
18
+ body?: any;
19
+ ignoreHeaders?: boolean;
20
+ };
21
+ type VaultParams = {
22
+ name: string;
23
+ authStrategy: AuthStrategy;
24
+ vaultUrl: string;
25
+ };
26
+ declare class VaultFile {
27
+ readonly name: string;
28
+ readonly vaultUrl: string;
29
+ readonly headers: Headers;
30
+ constructor(params: VaultParams);
31
+ getUploadUrl(): Promise<any>;
32
+ getDownloadUrl(): Promise<URL>;
33
+ _fetch(params: FetchParams): Promise<any>;
34
+ upload(file: Blob): Promise<void>;
35
+ download(): Promise<Blob>;
36
+ }
37
+
38
+ declare class FetchError extends Error {
39
+ readonly response: Response;
40
+ constructor(message: string, response: Response);
41
+ }
42
+
43
+ declare function useVault(vaultUrl: string, authStrategy: AuthStrategy): {
44
+ createVaultFile: (name: string) => VaultFile;
45
+ };
46
+
47
+ export { APIKeyAuthStrategy, type AuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile, useVault };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,47 @@
1
- import type { AuthStrategy } from './authStrategies';
2
- import { VaultFile } from './vault-file';
3
- import { DataTokenAuthStrategy, APIKeyAuthStrategy } from './authStrategies';
4
- import { FetchError } from './errors/fetchError';
5
- export declare function useVault(vaultUrl: string, authStrategy: AuthStrategy): {
1
+ interface AuthStrategy {
2
+ getHeaders: () => Headers;
3
+ }
4
+ declare class DataTokenAuthStrategy implements AuthStrategy {
5
+ dataToken: string;
6
+ getHeaders(): Headers;
7
+ constructor(dataToken: string);
8
+ }
9
+ declare class APIKeyAuthStrategy implements AuthStrategy {
10
+ apiKey: string;
11
+ getHeaders(): Headers;
12
+ constructor(apiKey: string);
13
+ }
14
+
15
+ type FetchParams = {
16
+ method: 'GET' | 'POST' | 'PUT';
17
+ path: string;
18
+ body?: any;
19
+ ignoreHeaders?: boolean;
20
+ };
21
+ type VaultParams = {
22
+ name: string;
23
+ authStrategy: AuthStrategy;
24
+ vaultUrl: string;
25
+ };
26
+ declare class VaultFile {
27
+ readonly name: string;
28
+ readonly vaultUrl: string;
29
+ readonly headers: Headers;
30
+ constructor(params: VaultParams);
31
+ getUploadUrl(): Promise<any>;
32
+ getDownloadUrl(): Promise<URL>;
33
+ _fetch(params: FetchParams): Promise<any>;
34
+ upload(file: Blob): Promise<void>;
35
+ download(): Promise<Blob>;
36
+ }
37
+
38
+ declare class FetchError extends Error {
39
+ readonly response: Response;
40
+ constructor(message: string, response: Response);
41
+ }
42
+
43
+ declare function useVault(vaultUrl: string, authStrategy: AuthStrategy): {
6
44
  createVaultFile: (name: string) => VaultFile;
7
45
  };
8
- export type { AuthStrategy };
9
- export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile };
46
+
47
+ export { APIKeyAuthStrategy, type AuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile, useVault };
package/dist/index.mjs ADDED
@@ -0,0 +1,116 @@
1
+ class FetchError extends Error {
2
+ constructor(message, response) {
3
+ super(message);
4
+ this.response = response;
5
+ this.name = "FetchError";
6
+ }
7
+ }
8
+
9
+ var __defProp$1 = Object.defineProperty;
10
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __publicField$1 = (obj, key, value) => {
12
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
13
+ return value;
14
+ };
15
+ class VaultFile {
16
+ constructor(params) {
17
+ __publicField$1(this, "name");
18
+ __publicField$1(this, "vaultUrl");
19
+ __publicField$1(this, "headers");
20
+ this.name = params.name;
21
+ this.vaultUrl = params.vaultUrl;
22
+ this.headers = params.authStrategy.getHeaders();
23
+ }
24
+ async getUploadUrl() {
25
+ const response = await this._fetch({
26
+ method: "POST",
27
+ path: `/files/${this.name}`
28
+ });
29
+ return response.url;
30
+ }
31
+ async getDownloadUrl() {
32
+ const response = await this._fetch({
33
+ method: "GET",
34
+ path: `/files/${this.name}`
35
+ });
36
+ return new URL(response.url);
37
+ }
38
+ async _fetch(params) {
39
+ const { method, path, body, ignoreHeaders } = params;
40
+ const url = new URL(this.vaultUrl + path).toString();
41
+ const response = await fetch(url, {
42
+ method,
43
+ body,
44
+ headers: ignoreHeaders ? void 0 : this.headers
45
+ });
46
+ if (!response.ok) {
47
+ throw new FetchError(`Failed to ${method} ${url}: ${response.status} ${response.statusText}`, response);
48
+ }
49
+ const content = await response.json();
50
+ return content;
51
+ }
52
+ async upload(file) {
53
+ const uploadUrl = await this.getUploadUrl();
54
+ const response = await fetch(uploadUrl, {
55
+ method: "PUT",
56
+ body: file,
57
+ headers: this.headers
58
+ });
59
+ if (!response.ok) {
60
+ throw new FetchError(`Error uploading file ${this.name}: ${response.status} ${response.statusText}`, response);
61
+ }
62
+ }
63
+ async download() {
64
+ const downloadUrl = await this.getDownloadUrl();
65
+ const response = await fetch(downloadUrl, {
66
+ method: "GET",
67
+ headers: this.headers
68
+ });
69
+ if (!response.ok) {
70
+ throw new FetchError(`Error downloading file ${this.name}: ${response.status} ${response.statusText}`, response);
71
+ }
72
+ return response.blob();
73
+ }
74
+ }
75
+
76
+ var __defProp = Object.defineProperty;
77
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
78
+ var __publicField = (obj, key, value) => {
79
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
80
+ return value;
81
+ };
82
+ class DataTokenAuthStrategy {
83
+ constructor(dataToken) {
84
+ __publicField(this, "dataToken");
85
+ this.dataToken = dataToken;
86
+ }
87
+ getHeaders() {
88
+ return new Headers({
89
+ "x-data-token": this.dataToken
90
+ });
91
+ }
92
+ }
93
+ class APIKeyAuthStrategy {
94
+ constructor(apiKey) {
95
+ __publicField(this, "apiKey");
96
+ this.apiKey = apiKey;
97
+ }
98
+ getHeaders() {
99
+ return new Headers({
100
+ Authorization: this.apiKey
101
+ });
102
+ }
103
+ }
104
+
105
+ function useVault(vaultUrl, authStrategy) {
106
+ function createVaultFile(name) {
107
+ return new VaultFile({
108
+ name,
109
+ authStrategy,
110
+ vaultUrl
111
+ });
112
+ }
113
+ return { createVaultFile };
114
+ }
115
+
116
+ export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile, useVault };
package/package.json CHANGED
@@ -1,25 +1,30 @@
1
1
  {
2
2
  "name": "@meistrari/vault-sdk",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
+ "license": "UNLICENSED",
4
5
  "repository": {
5
6
  "type": "git",
6
7
  "url": "https://github.com/meistrari/vault.git"
7
8
  },
8
9
  "exports": {
9
- ".": "./dist/index.js"
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.mjs"
13
+ }
10
14
  },
11
- "main": "dist/index.js",
15
+ "main": "dist/index.mjs",
12
16
  "types": "dist/index.d.ts",
13
17
  "files": [
14
18
  "dist"
15
19
  ],
16
20
  "dependencies": {
17
21
  "ofetch": "1.4.1",
18
- "vitest": "^2.1.8"
22
+ "vitest": "2.1.8"
19
23
  },
20
24
  "devDependencies": {
21
25
  "@types/bun": "latest",
22
- "msw": "2.6.8"
26
+ "msw": "2.6.8",
27
+ "unbuild": "2.0.0"
23
28
  },
24
29
  "peerDependencies": {
25
30
  "typescript": "^5.0.0"
@@ -29,7 +34,9 @@
29
34
  },
30
35
  "scripts": {
31
36
  "test": "vitest",
32
- "build": "tsc",
33
- "lint:ts": "tsc --noEmit"
37
+ "build": "unbuild",
38
+ "lint": "eslint .",
39
+ "lint:fix": "eslint . --fix",
40
+ "check": "bun run lint && bun tsc --noEmit"
34
41
  }
35
42
  }
@@ -1,13 +0,0 @@
1
- export interface AuthStrategy {
2
- getHeaders: () => Headers;
3
- }
4
- export declare class DataTokenAuthStrategy implements AuthStrategy {
5
- dataToken: string;
6
- getHeaders(): Headers;
7
- constructor(dataToken: string);
8
- }
9
- export declare class APIKeyAuthStrategy implements AuthStrategy {
10
- apiKey: string;
11
- getHeaders(): Headers;
12
- constructor(apiKey: string);
13
- }
@@ -1,23 +0,0 @@
1
- export class DataTokenAuthStrategy {
2
- dataToken;
3
- getHeaders() {
4
- return new Headers({
5
- 'x-data-token': this.dataToken,
6
- });
7
- }
8
- constructor(dataToken) {
9
- this.dataToken = dataToken;
10
- }
11
- }
12
- export class APIKeyAuthStrategy {
13
- apiKey;
14
- getHeaders() {
15
- return new Headers({
16
- Authorization: this.apiKey,
17
- });
18
- }
19
- constructor(apiKey) {
20
- this.apiKey = apiKey;
21
- }
22
- }
23
- //# sourceMappingURL=authStrategies.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authStrategies.js","sourceRoot":"","sources":["../src/authStrategies.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,qBAAqB;IAC9B,SAAS,CAAQ;IAEjB,UAAU;QACN,OAAO,IAAI,OAAO,CAAC;YACf,cAAc,EAAE,IAAI,CAAC,SAAS;SACjC,CAAC,CAAA;IACN,CAAC;IAED,YAAY,SAAiB;QACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC9B,CAAC;CACJ;AAED,MAAM,OAAO,kBAAkB;IAC3B,MAAM,CAAQ;IAEd,UAAU;QACN,OAAO,IAAI,OAAO,CAAC;YACf,aAAa,EAAE,IAAI,CAAC,MAAM;SAC7B,CAAC,CAAA;IACN,CAAC;IAED,YAAY,MAAc;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;CACJ"}
@@ -1,4 +0,0 @@
1
- export declare class FetchError extends Error {
2
- readonly response: Response;
3
- constructor(message: string, response: Response);
4
- }
@@ -1,9 +0,0 @@
1
- export class FetchError extends Error {
2
- response;
3
- constructor(message, response) {
4
- super(message);
5
- this.response = response;
6
- this.name = 'FetchError';
7
- }
8
- }
9
- //# sourceMappingURL=fetchError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetchError.js","sourceRoot":"","sources":["../../src/errors/fetchError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAW,SAAQ,KAAK;IACY;IAA7C,YAAY,OAAe,EAAkB,QAAkB;QAC3D,KAAK,CAAC,OAAO,CAAC,CAAA;QAD2B,aAAQ,GAAR,QAAQ,CAAU;QAE3D,IAAI,CAAC,IAAI,GAAG,YAAY,CAAA;IAC5B,CAAC;CACJ"}
package/dist/index.js DELETED
@@ -1,15 +0,0 @@
1
- import { VaultFile } from './vault-file';
2
- import { DataTokenAuthStrategy, APIKeyAuthStrategy } from './authStrategies';
3
- import { FetchError } from './errors/fetchError';
4
- export function useVault(vaultUrl, authStrategy) {
5
- function createVaultFile(name) {
6
- return new VaultFile({
7
- name,
8
- authStrategy,
9
- vaultUrl,
10
- });
11
- }
12
- return { createVaultFile };
13
- }
14
- export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile };
15
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAEhD,MAAM,UAAU,QAAQ,CAAC,QAAgB,EAAE,YAA0B;IACjE,SAAS,eAAe,CAAC,IAAY;QACjC,OAAO,IAAI,SAAS,CAAC;YACjB,IAAI;YACJ,YAAY;YACZ,QAAQ;SACX,CAAC,CAAA;IACN,CAAC;IAED,OAAO,EAAE,eAAe,EAAE,CAAA;AAC9B,CAAC;AAGD,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,UAAU,EAAE,SAAS,EAAE,CAAA"}
@@ -1,24 +0,0 @@
1
- import type { AuthStrategy } from './authStrategies';
2
- type FetchParams = {
3
- method: 'GET' | 'POST' | 'PUT';
4
- path: string | URL;
5
- body?: any;
6
- ignoreHeaders?: boolean;
7
- };
8
- type VaultParams = {
9
- name: string;
10
- authStrategy: AuthStrategy;
11
- vaultUrl: string;
12
- };
13
- export declare class VaultFile {
14
- readonly name: string;
15
- readonly vaultUrl: string;
16
- readonly headers: Headers;
17
- constructor(params: VaultParams);
18
- getUploadUrl(): Promise<any>;
19
- getDownloadUrl(): Promise<URL>;
20
- _fetch(params: FetchParams): Promise<any>;
21
- upload(file: Blob): Promise<void>;
22
- download(): Promise<Blob>;
23
- }
24
- export {};
@@ -1,62 +0,0 @@
1
- import { FetchError } from './errors/fetchError';
2
- export class VaultFile {
3
- name;
4
- vaultUrl;
5
- headers;
6
- constructor(params) {
7
- this.name = params.name;
8
- this.vaultUrl = params.vaultUrl;
9
- this.headers = params.authStrategy.getHeaders();
10
- }
11
- async getUploadUrl() {
12
- const response = await this._fetch({
13
- method: 'POST',
14
- path: `/files/${this.name}`,
15
- });
16
- return response.url;
17
- }
18
- async getDownloadUrl() {
19
- const response = await this._fetch({
20
- method: 'GET',
21
- path: `/files/${this.name}`,
22
- });
23
- return new URL(response.url);
24
- }
25
- async _fetch(params) {
26
- const { method, path, body, ignoreHeaders } = params;
27
- const url = path instanceof URL ? path.toString() : new URL(path, this.vaultUrl).toString();
28
- const response = await fetch(url, {
29
- method,
30
- body,
31
- headers: ignoreHeaders ? undefined : this.headers,
32
- });
33
- if (!response.ok) {
34
- throw new FetchError(`Failed to ${method} ${url}: ${response.status} ${response.statusText}`, response);
35
- }
36
- const content = await response.json();
37
- return content;
38
- }
39
- async upload(file) {
40
- const uploadUrl = await this.getUploadUrl();
41
- const response = await fetch(uploadUrl, {
42
- method: 'PUT',
43
- body: file,
44
- headers: this.headers,
45
- });
46
- if (!response.ok) {
47
- throw new FetchError(`Error uploading file ${this.name}: ${response.status} ${response.statusText}`, response);
48
- }
49
- }
50
- async download() {
51
- const downloadUrl = await this.getDownloadUrl();
52
- const response = await fetch(downloadUrl, {
53
- method: 'GET',
54
- headers: this.headers,
55
- });
56
- if (!response.ok) {
57
- throw new FetchError(`Error downloading file ${this.name}: ${response.status} ${response.statusText}`, response);
58
- }
59
- return response.blob();
60
- }
61
- }
62
- //# sourceMappingURL=vault-file.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vault-file.js","sourceRoot":"","sources":["../src/vault-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAgBhD,MAAM,OAAO,SAAS;IACT,IAAI,CAAQ;IACZ,QAAQ,CAAQ;IAChB,OAAO,CAAS;IAEzB,YAAY,MAAmB;QAC3B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAA;QACvB,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAA;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,YAAY,CAAC,UAAU,EAAE,CAAA;IACnD,CAAC;IAED,KAAK,CAAC,YAAY;QACd,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC;YAC/B,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,UAAU,IAAI,CAAC,IAAI,EAAE;SAC9B,CAAC,CAAA;QAEF,OAAO,QAAQ,CAAC,GAAG,CAAA;IACvB,CAAC;IAED,KAAK,CAAC,cAAc;QAChB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC;Y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