@tracken/sdk 0.0.0-stage → 0.2.1
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 +75 -2
- package/SOURCE.json +10 -0
- package/dist/client.d.ts +94 -0
- package/dist/client.js +258 -0
- package/dist/credentials.d.ts +60 -0
- package/dist/credentials.js +122 -0
- package/dist/decimal.d.ts +20 -0
- package/dist/decimal.js +67 -0
- package/dist/environments.d.ts +14 -0
- package/dist/environments.js +16 -0
- package/dist/errors.d.ts +150 -0
- package/dist/errors.js +190 -0
- package/dist/generated/operations.d.ts +1955 -0
- package/dist/generated/operations.js +2746 -0
- package/dist/generated/schema.d.ts +17988 -0
- package/dist/generated/schema.js +5 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +24 -0
- package/dist/jobs.d.ts +23 -0
- package/dist/jobs.js +80 -0
- package/dist/operations.d.ts +23 -0
- package/dist/operations.js +2 -0
- package/dist/pagination.d.ts +19 -0
- package/dist/pagination.js +49 -0
- package/dist/request.d.ts +27 -0
- package/dist/request.js +10 -0
- package/dist/runtime.d.ts +22 -0
- package/dist/runtime.js +33 -0
- package/dist/tracken.d.ts +74 -0
- package/dist/tracken.js +203 -0
- package/dist/types.d.ts +130 -0
- package/dist/types.js +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/package.json +40 -4
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The type of every operation's inputs and answer, read from openapi-typescript's `operations`
|
|
3
|
+
* (generated from the public document) by operation id. Nothing here exists at run time.
|
|
4
|
+
*/
|
|
5
|
+
import type { OPERATIONS } from "./generated/operations.js";
|
|
6
|
+
import type { operations } from "./generated/schema.js";
|
|
7
|
+
type Table = typeof OPERATIONS;
|
|
8
|
+
/** Every v1 operation the SDK can call, by the document's operation id. */
|
|
9
|
+
export type OperationId = keyof Table & keyof operations;
|
|
10
|
+
type Operation<Id extends OperationId> = operations[Id];
|
|
11
|
+
type Params<Id extends OperationId> = Operation<Id>["parameters"];
|
|
12
|
+
type MediaOf<R> = R extends {
|
|
13
|
+
content: infer C;
|
|
14
|
+
} ? C : never;
|
|
15
|
+
/** A multipart field is text, or a file (`Blob`/`File`). */
|
|
16
|
+
type FormFields<M> = {
|
|
17
|
+
[K in keyof M]: string | Blob;
|
|
18
|
+
};
|
|
19
|
+
type BodyOfContent<C> = "application/json" extends keyof C ? C["application/json"] : "multipart/form-data" extends keyof C ? FormData | FormFields<C["multipart/form-data"]> : never;
|
|
20
|
+
/** The request body: the `{data}` envelope with operation options beside it, or a form for an upload. */
|
|
21
|
+
export type RequestBody<Id extends OperationId> = BodyOfContent<MediaOf<NonNullable<Operation<Id>["requestBody"]>>>;
|
|
22
|
+
type BodyInput<Id extends OperationId> = [RequestBody<Id>] extends [never] ? {
|
|
23
|
+
body?: never;
|
|
24
|
+
} : {} extends Pick<Operation<Id>, "requestBody"> ? {
|
|
25
|
+
body?: RequestBody<Id>;
|
|
26
|
+
} : {
|
|
27
|
+
body: RequestBody<Id>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* One call's inputs: `path` and `query` parameters by their wire names, and the `body`. Each is
|
|
31
|
+
* required exactly when the document requires it.
|
|
32
|
+
*/
|
|
33
|
+
export type OperationInput<Id extends OperationId> = Pick<Params<Id>, "path" | "query"> & BodyInput<Id>;
|
|
34
|
+
type Responses<Id extends OperationId> = Operation<Id>["responses"];
|
|
35
|
+
/** A JSON answer is parsed; any other content (a PDF, a KMD file) arrives as bytes. */
|
|
36
|
+
type AnswerOf<R> = R extends {
|
|
37
|
+
content: infer C;
|
|
38
|
+
} ? {
|
|
39
|
+
[K in keyof C]: K extends "application/json" ? C[K] : Uint8Array;
|
|
40
|
+
}[keyof C] : undefined;
|
|
41
|
+
/**
|
|
42
|
+
* The parsed body of a success: the JSON of a 200/201/202, `undefined` for a 204, and the file's
|
|
43
|
+
* bytes for a rendition the API answers with a 303 to a pre-signed link (the client follows it).
|
|
44
|
+
*/
|
|
45
|
+
export type ResponseBody<Id extends OperationId> = {
|
|
46
|
+
[S in keyof Responses<Id>]: S extends 303 ? Uint8Array : S extends 200 | 201 | 202 | 203 | 204 | 206 ? AnswerOf<Responses<Id>[S]> : never;
|
|
47
|
+
}[keyof Responses<Id>];
|
|
48
|
+
/** A success, with what the headers say about it. */
|
|
49
|
+
export interface TrackenResponse<B = unknown> {
|
|
50
|
+
body: B;
|
|
51
|
+
status: number;
|
|
52
|
+
headers: Headers;
|
|
53
|
+
contentType: string;
|
|
54
|
+
/** The `X-Request-Id` to quote to support. */
|
|
55
|
+
requestId: string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* The record's version, from a read or from the 201 of a create (every create of a record whose
|
|
58
|
+
* read answers one); pass the response (or this) as `ifMatch` to update it safely.
|
|
59
|
+
*/
|
|
60
|
+
etag: string | undefined;
|
|
61
|
+
/** Where a created record or a started job lives. */
|
|
62
|
+
location: string | undefined;
|
|
63
|
+
/** The API confirmed nothing was stored (`dry_run=true`, answered with `Tracken-Dry-Run: true`). */
|
|
64
|
+
dryRun: boolean;
|
|
65
|
+
/** On a list read with `updated_since`: where the next incremental pass starts (`meta.sync.next_since`). */
|
|
66
|
+
nextSince: string | undefined;
|
|
67
|
+
}
|
|
68
|
+
/** Per-call options: the request headers the conventions name, and cancellation. */
|
|
69
|
+
export interface RequestOptions {
|
|
70
|
+
/**
|
|
71
|
+
* The POST's replay guard. The client sends a fresh one on every POST anyway and reuses it on its
|
|
72
|
+
* own retries; pass your own (stable per business action, such as your order id) to make a retry
|
|
73
|
+
* of yours safe too. A key reused with a different body answers `IDEMPOTENCY_KEY_REUSED`.
|
|
74
|
+
*/
|
|
75
|
+
idempotencyKey?: string;
|
|
76
|
+
/** The `ETag` of the version you read (or that read's response): the write fails with 412 if it changed since. */
|
|
77
|
+
ifMatch?: string | {
|
|
78
|
+
etag: string | undefined;
|
|
79
|
+
};
|
|
80
|
+
/** For an app's installation token: the person the app acts for (`Tracken-On-Behalf-Of`). */
|
|
81
|
+
onBehalfOf?: string;
|
|
82
|
+
/** Overrides the client's organization for this call (a person's token only). */
|
|
83
|
+
organizationId?: string;
|
|
84
|
+
signal?: AbortSignal;
|
|
85
|
+
}
|
|
86
|
+
type ArgsFor<I> = {} extends I ? [input?: I, options?: RequestOptions] : [input: I, options?: RequestOptions];
|
|
87
|
+
type Args<Id extends OperationId> = ArgsFor<OperationInput<Id>>;
|
|
88
|
+
type QueryOf<Id extends OperationId> = NonNullable<Params<Id>["query"]>;
|
|
89
|
+
/** The renditions an operation's `format` parameter offers (`"pdf"`, `"kmd"`), when it has one. */
|
|
90
|
+
type FormatOf<Id extends OperationId> = "format" extends keyof QueryOf<Id> ? NonNullable<QueryOf<Id>[keyof QueryOf<Id> & "format"]> : never;
|
|
91
|
+
type JsonAnswer<Id extends OperationId> = Exclude<ResponseBody<Id>, Uint8Array>;
|
|
92
|
+
/**
|
|
93
|
+
* An operation with a `format` parameter answers the file's bytes for a rendition (`format: "pdf"`)
|
|
94
|
+
* and the JSON record otherwise, so each call is typed by the format it asks for.
|
|
95
|
+
*/
|
|
96
|
+
export interface RenditionMethod<Id extends OperationId> {
|
|
97
|
+
(input: OperationInput<Id> & {
|
|
98
|
+
query: {
|
|
99
|
+
format: Exclude<FormatOf<Id>, "json">;
|
|
100
|
+
};
|
|
101
|
+
}, options?: RequestOptions): Promise<TrackenResponse<Uint8Array>>;
|
|
102
|
+
(...args: ArgsFor<OperationInput<Id> & {
|
|
103
|
+
query?: {
|
|
104
|
+
format?: "json";
|
|
105
|
+
};
|
|
106
|
+
}>): Promise<TrackenResponse<JsonAnswer<Id>>>;
|
|
107
|
+
(...args: Args<Id>): Promise<TrackenResponse<ResponseBody<Id>>>;
|
|
108
|
+
}
|
|
109
|
+
export type OperationMethod<Id extends OperationId> = [FormatOf<Id>] extends [never] ? (...args: Args<Id>) => Promise<TrackenResponse<ResponseBody<Id>>> : RenditionMethod<Id>;
|
|
110
|
+
export type CallArgs<Id extends OperationId> = Args<Id>;
|
|
111
|
+
/** Operations that answer one page of a cursor-paginated list. */
|
|
112
|
+
export type PaginatedOperationId = {
|
|
113
|
+
[Id in OperationId]: Table[Id]["paginated"] extends true ? Id : never;
|
|
114
|
+
}[OperationId];
|
|
115
|
+
/** One record of a list page: an element of `data`, or of a paginated report's `data.rows`. */
|
|
116
|
+
export type ItemOf<B> = B extends {
|
|
117
|
+
data: ReadonlyArray<infer T>;
|
|
118
|
+
} ? T : B extends {
|
|
119
|
+
data: {
|
|
120
|
+
rows: ReadonlyArray<infer T>;
|
|
121
|
+
};
|
|
122
|
+
} ? T : unknown;
|
|
123
|
+
export type ResourceName = Table[OperationId]["resource"];
|
|
124
|
+
/** `tracken.salesInvoices.issue(…)`: each resource's operations, the colon actions among them, as methods. */
|
|
125
|
+
export type Resources = {
|
|
126
|
+
[R in ResourceName]: {
|
|
127
|
+
[Id in OperationId as Table[Id]["resource"] extends R ? Table[Id]["name"] : never]: OperationMethod<Id>;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
export {};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/version.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tracken/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "A typed TypeScript client for Tracken Accounts' public API.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Tracken-Technologies/tracken-cli.git",
|
|
9
|
+
"directory": "packages/sdk"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"tracken-source": "./src/index.ts",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"!dist/**/*.map",
|
|
28
|
+
"SOURCE.json"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json && cp ../../openapi/SOURCE.json SOURCE.json",
|
|
32
|
+
"typecheck": "tsc --noEmit",
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"prepack": "npm run build"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=22"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"openapi-fetch": "^0.17.0"
|
|
41
|
+
}
|
|
42
|
+
}
|