@wtfalch/agreements 0.1.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/LICENSE +21 -0
- package/README.md +34 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.js +9 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/transport.d.ts +16 -0
- package/dist/transport.js +63 -0
- package/dist/types.d.ts +33 -0
- package/dist/types.js +1 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 William Tallis Falch
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @wtfalch/agreements
|
|
2
|
+
|
|
3
|
+
Public client SDK and API types for the Agreements service. Requires Node 22+ or a
|
|
4
|
+
browser with Fetch support. The client has no runtime package dependencies.
|
|
5
|
+
|
|
6
|
+
## Status
|
|
7
|
+
|
|
8
|
+
Published: no.
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm install @wtfalch/agreements
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { createAgreementsClient } from '@wtfalch/agreements';
|
|
16
|
+
|
|
17
|
+
const agreements = createAgreementsClient({
|
|
18
|
+
baseUrl: serviceOrigin,
|
|
19
|
+
credential: () => serviceKey,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const agreements = await agreements.createAgreements({ organisationId, name: 'Widget' });
|
|
23
|
+
const { agreements: list } = await agreements.listAgreements(organisationId);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The credential callback runs for every request, so rotation does not require a
|
|
27
|
+
new client. API failures reject with `AgreementsApiError`, which carries `status`
|
|
28
|
+
and a typed `code` (see `AgreementsError`); the SDK never throws a bare `Error`
|
|
29
|
+
for a service failure.
|
|
30
|
+
|
|
31
|
+
The root export provides the client and public request/response types.
|
|
32
|
+
`@wtfalch/agreements/client` is also supported. There are no server, database,
|
|
33
|
+
migration or authorization exports. The service implementation is a private
|
|
34
|
+
package.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ClientOptions } from './transport.js';
|
|
2
|
+
import type { Agreements, CreateAgreementsRequest, ListAgreementsResponse } from './types.js';
|
|
3
|
+
export { AgreementsApiError, type ClientOptions } from './transport.js';
|
|
4
|
+
export declare function createAgreementsClient(options: ClientOptions): {
|
|
5
|
+
createAgreements: (input: CreateAgreementsRequest) => Promise<Agreements>;
|
|
6
|
+
listAgreements: (organisationId: string) => Promise<ListAgreementsResponse>;
|
|
7
|
+
};
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createTransport } from './transport.js';
|
|
2
|
+
export { AgreementsApiError } from './transport.js';
|
|
3
|
+
export function createAgreementsClient(options) {
|
|
4
|
+
const call = createTransport(options);
|
|
5
|
+
return {
|
|
6
|
+
createAgreements: (input) => call('POST', '/v1/agreements', input),
|
|
7
|
+
listAgreements: (organisationId) => call('GET', `/v1/agreements?${new URLSearchParams({ organisationId })}`),
|
|
8
|
+
};
|
|
9
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './client.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AgreementsErrorCode } from './types.js';
|
|
2
|
+
export interface ClientOptions {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
credential: () => string | Promise<string>;
|
|
5
|
+
fetch?: typeof fetch;
|
|
6
|
+
}
|
|
7
|
+
/** A typed failure, never a bare `Error`. `status` is the HTTP status; `code`
|
|
8
|
+
* and `message` are the service's own wire error (see `AgreementsError`). */
|
|
9
|
+
export declare class AgreementsApiError extends Error {
|
|
10
|
+
readonly status: number;
|
|
11
|
+
readonly code: AgreementsErrorCode;
|
|
12
|
+
constructor(status: number, code: AgreementsErrorCode, message: string);
|
|
13
|
+
}
|
|
14
|
+
/** Minimal fetch-based transport: JSON in, JSON out, a bearer credential on
|
|
15
|
+
* every request. No Node-only imports -- this runs in a browser too. */
|
|
16
|
+
export declare function createTransport(options: ClientOptions): <T>(method: string, path: string, input?: unknown) => Promise<T>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const KNOWN_CODES = [
|
|
2
|
+
'invalid_request',
|
|
3
|
+
'unauthorized',
|
|
4
|
+
'forbidden',
|
|
5
|
+
'not_found',
|
|
6
|
+
'unavailable',
|
|
7
|
+
];
|
|
8
|
+
/** A typed failure, never a bare `Error`. `status` is the HTTP status; `code`
|
|
9
|
+
* and `message` are the service's own wire error (see `AgreementsError`). */
|
|
10
|
+
export class AgreementsApiError extends Error {
|
|
11
|
+
status;
|
|
12
|
+
code;
|
|
13
|
+
constructor(status, code, message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.status = status;
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.name = 'AgreementsApiError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function errorFrom(value) {
|
|
21
|
+
const error = typeof value === 'object' && value !== null && 'error' in value
|
|
22
|
+
? value.error
|
|
23
|
+
: null;
|
|
24
|
+
const rawCode = typeof error === 'object' && error !== null && 'code' in error && typeof error.code === 'string'
|
|
25
|
+
? error.code
|
|
26
|
+
: undefined;
|
|
27
|
+
const rawMessage = typeof error === 'object' &&
|
|
28
|
+
error !== null &&
|
|
29
|
+
'message' in error &&
|
|
30
|
+
typeof error.message === 'string'
|
|
31
|
+
? error.message
|
|
32
|
+
: undefined;
|
|
33
|
+
const code = KNOWN_CODES.includes(rawCode ?? '')
|
|
34
|
+
? rawCode
|
|
35
|
+
: 'unavailable';
|
|
36
|
+
return { code, message: rawMessage ?? 'Request failed' };
|
|
37
|
+
}
|
|
38
|
+
/** Minimal fetch-based transport: JSON in, JSON out, a bearer credential on
|
|
39
|
+
* every request. No Node-only imports -- this runs in a browser too. */
|
|
40
|
+
export function createTransport(options) {
|
|
41
|
+
return async (method, path, input) => {
|
|
42
|
+
const response = await (options.fetch ?? fetch)(new URL(path, options.baseUrl), {
|
|
43
|
+
method,
|
|
44
|
+
headers: {
|
|
45
|
+
authorization: `Bearer ${await options.credential()}`,
|
|
46
|
+
...(input === undefined ? {} : { 'content-type': 'application/json' }),
|
|
47
|
+
},
|
|
48
|
+
body: input === undefined ? undefined : JSON.stringify(input),
|
|
49
|
+
});
|
|
50
|
+
let value;
|
|
51
|
+
try {
|
|
52
|
+
value = response.status === 204 ? undefined : await response.json();
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
throw new AgreementsApiError(response.status, 'unavailable', 'Invalid response body');
|
|
56
|
+
}
|
|
57
|
+
if (!response.ok) {
|
|
58
|
+
const { code, message } = errorFrom(value);
|
|
59
|
+
throw new AgreementsApiError(response.status, code, message);
|
|
60
|
+
}
|
|
61
|
+
return value;
|
|
62
|
+
};
|
|
63
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Public HTTP contracts for the Agreements service. Internal storage rows are never returned. */
|
|
2
|
+
export interface Agreements {
|
|
3
|
+
id: string;
|
|
4
|
+
organisationId: string;
|
|
5
|
+
name: string;
|
|
6
|
+
createdAt: string;
|
|
7
|
+
}
|
|
8
|
+
export interface CreateAgreementsRequest {
|
|
9
|
+
organisationId: string;
|
|
10
|
+
name: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ListAgreementsResponse {
|
|
13
|
+
agreements: Agreements[];
|
|
14
|
+
}
|
|
15
|
+
/** The wire shape of a failed request, discriminated on `code` so a caller can
|
|
16
|
+
* narrow on it. Every non-2xx response body has this shape. */
|
|
17
|
+
export type AgreementsError = {
|
|
18
|
+
code: 'invalid_request';
|
|
19
|
+
message: string;
|
|
20
|
+
} | {
|
|
21
|
+
code: 'unauthorized';
|
|
22
|
+
message: string;
|
|
23
|
+
} | {
|
|
24
|
+
code: 'forbidden';
|
|
25
|
+
message: string;
|
|
26
|
+
} | {
|
|
27
|
+
code: 'not_found';
|
|
28
|
+
message: string;
|
|
29
|
+
} | {
|
|
30
|
+
code: 'unavailable';
|
|
31
|
+
message: string;
|
|
32
|
+
};
|
|
33
|
+
export type AgreementsErrorCode = AgreementsError['code'];
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wtfalch/agreements",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"description": "Public client SDK and API types for the Agreements service.",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/wtfalch/agreements",
|
|
10
|
+
"directory": "packages/sdk"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"LICENSE",
|
|
14
|
+
"README.md",
|
|
15
|
+
"dist/client.d.ts",
|
|
16
|
+
"dist/client.js",
|
|
17
|
+
"dist/index.d.ts",
|
|
18
|
+
"dist/index.js",
|
|
19
|
+
"dist/transport.d.ts",
|
|
20
|
+
"dist/transport.js",
|
|
21
|
+
"dist/types.d.ts",
|
|
22
|
+
"dist/types.js"
|
|
23
|
+
],
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./client": {
|
|
30
|
+
"types": "./dist/client.d.ts",
|
|
31
|
+
"default": "./dist/client.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=22.0.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc -p tsconfig.build.json",
|
|
43
|
+
"typecheck": "tsc --noEmit",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"prepublishOnly": "pnpm build && node ../../scripts/check-package.mjs"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "^22",
|
|
49
|
+
"typescript": "^5.9.0",
|
|
50
|
+
"vitest": "^4.1.6"
|
|
51
|
+
}
|
|
52
|
+
}
|