assembly-kit 0.0.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/CLAUDE.md +205 -0
- package/LICENSE +21 -0
- package/README.md +516 -0
- package/dist/bridge-ui/index.d.mts +4 -0
- package/dist/bridge-ui/index.mjs +5 -0
- package/dist/bridge-ui/use-actions-menu.d.mts +16 -0
- package/dist/bridge-ui/use-actions-menu.mjs +33 -0
- package/dist/bridge-ui/use-actions-menu.mjs.map +1 -0
- package/dist/bridge-ui/use-primary-cta.d.mts +16 -0
- package/dist/bridge-ui/use-primary-cta.mjs +34 -0
- package/dist/bridge-ui/use-primary-cta.mjs.map +1 -0
- package/dist/bridge-ui/use-secondary-cta.d.mts +16 -0
- package/dist/bridge-ui/use-secondary-cta.mjs +34 -0
- package/dist/bridge-ui/use-secondary-cta.mjs.map +1 -0
- package/dist/client/index.d.mts +108 -0
- package/dist/client/index.mjs +168 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/client/options.d.mts +40 -0
- package/dist/constants/kit-mode.d.mts +15 -0
- package/dist/constants/kit-mode.mjs +15 -0
- package/dist/constants/kit-mode.mjs.map +1 -0
- package/dist/errors/base.d.mts +29 -0
- package/dist/errors/base.mjs +16 -0
- package/dist/errors/base.mjs.map +1 -0
- package/dist/errors/connection.d.mts +12 -0
- package/dist/errors/connection.mjs +16 -0
- package/dist/errors/connection.mjs.map +1 -0
- package/dist/errors/forbidden.d.mts +12 -0
- package/dist/errors/forbidden.mjs +16 -0
- package/dist/errors/forbidden.mjs.map +1 -0
- package/dist/errors/index.d.mts +13 -0
- package/dist/errors/index.mjs +13 -0
- package/dist/errors/invalid-token.d.mts +12 -0
- package/dist/errors/invalid-token.mjs +16 -0
- package/dist/errors/invalid-token.mjs.map +1 -0
- package/dist/errors/missing-api-key.d.mts +12 -0
- package/dist/errors/missing-api-key.mjs +16 -0
- package/dist/errors/missing-api-key.mjs.map +1 -0
- package/dist/errors/no-token.d.mts +12 -0
- package/dist/errors/no-token.mjs +16 -0
- package/dist/errors/no-token.mjs.map +1 -0
- package/dist/errors/not-found.d.mts +12 -0
- package/dist/errors/not-found.mjs +16 -0
- package/dist/errors/not-found.mjs.map +1 -0
- package/dist/errors/rate-limit.d.mts +17 -0
- package/dist/errors/rate-limit.mjs +18 -0
- package/dist/errors/rate-limit.mjs.map +1 -0
- package/dist/errors/response-parse.d.mts +19 -0
- package/dist/errors/response-parse.mjs +23 -0
- package/dist/errors/response-parse.mjs.map +1 -0
- package/dist/errors/server.d.mts +12 -0
- package/dist/errors/server.mjs +16 -0
- package/dist/errors/server.mjs.map +1 -0
- package/dist/errors/unauthorized.d.mts +12 -0
- package/dist/errors/unauthorized.mjs +16 -0
- package/dist/errors/unauthorized.mjs.map +1 -0
- package/dist/errors/validation.d.mts +12 -0
- package/dist/errors/validation.mjs +16 -0
- package/dist/errors/validation.mjs.map +1 -0
- package/dist/index.d.mts +49 -0
- package/dist/index.mjs +51 -0
- package/dist/lib/modules/app-connections/resource.d.mts +28 -0
- package/dist/lib/modules/app-connections/resource.mjs +33 -0
- package/dist/lib/modules/app-connections/resource.mjs.map +1 -0
- package/dist/lib/modules/app-connections/schema.d.mts +37 -0
- package/dist/lib/modules/app-connections/schema.mjs +30 -0
- package/dist/lib/modules/app-connections/schema.mjs.map +1 -0
- package/dist/lib/modules/app-installs/resource.d.mts +21 -0
- package/dist/lib/modules/app-installs/resource.mjs +31 -0
- package/dist/lib/modules/app-installs/resource.mjs.map +1 -0
- package/dist/lib/modules/app-installs/schema.d.mts +22 -0
- package/dist/lib/modules/app-installs/schema.mjs +23 -0
- package/dist/lib/modules/app-installs/schema.mjs.map +1 -0
- package/dist/lib/modules/clients/resource.d.mts +43 -0
- package/dist/lib/modules/clients/resource.mjs +62 -0
- package/dist/lib/modules/clients/resource.mjs.map +1 -0
- package/dist/lib/modules/clients/schema.d.mts +50 -0
- package/dist/lib/modules/clients/schema.mjs +52 -0
- package/dist/lib/modules/clients/schema.mjs.map +1 -0
- package/dist/lib/modules/companies/resource.d.mts +37 -0
- package/dist/lib/modules/companies/resource.mjs +60 -0
- package/dist/lib/modules/companies/resource.mjs.map +1 -0
- package/dist/lib/modules/companies/schema.d.mts +39 -0
- package/dist/lib/modules/companies/schema.mjs +34 -0
- package/dist/lib/modules/companies/schema.mjs.map +1 -0
- package/dist/lib/modules/contract-templates/resource.d.mts +27 -0
- package/dist/lib/modules/contract-templates/resource.mjs +40 -0
- package/dist/lib/modules/contract-templates/resource.mjs.map +1 -0
- package/dist/lib/modules/contract-templates/schema.d.mts +21 -0
- package/dist/lib/modules/contract-templates/schema.mjs +18 -0
- package/dist/lib/modules/contract-templates/schema.mjs.map +1 -0
- package/dist/lib/modules/contracts/resource.d.mts +29 -0
- package/dist/lib/modules/contracts/resource.mjs +40 -0
- package/dist/lib/modules/contracts/resource.mjs.map +1 -0
- package/dist/lib/modules/contracts/schema.d.mts +50 -0
- package/dist/lib/modules/contracts/schema.mjs +45 -0
- package/dist/lib/modules/contracts/schema.mjs.map +1 -0
- package/dist/lib/modules/custom-field-options/index.d.mts +1 -0
- package/dist/lib/modules/custom-field-options/index.mjs +2 -0
- package/dist/lib/modules/custom-field-options/resource.d.mts +22 -0
- package/dist/lib/modules/custom-field-options/resource.mjs +25 -0
- package/dist/lib/modules/custom-field-options/resource.mjs.map +1 -0
- package/dist/lib/modules/custom-field-options/schema.d.mts +18 -0
- package/dist/lib/modules/custom-field-options/schema.mjs +13 -0
- package/dist/lib/modules/custom-field-options/schema.mjs.map +1 -0
- package/dist/lib/modules/custom-fields/resource.d.mts +21 -0
- package/dist/lib/modules/custom-fields/resource.mjs +24 -0
- package/dist/lib/modules/custom-fields/resource.mjs.map +1 -0
- package/dist/lib/modules/custom-fields/schema.d.mts +43 -0
- package/dist/lib/modules/custom-fields/schema.mjs +44 -0
- package/dist/lib/modules/custom-fields/schema.mjs.map +1 -0
- package/dist/lib/modules/events/resource.d.mts +33 -0
- package/dist/lib/modules/events/resource.mjs +49 -0
- package/dist/lib/modules/events/resource.mjs.map +1 -0
- package/dist/lib/modules/events/schema.d.mts +52 -0
- package/dist/lib/modules/events/schema.mjs +49 -0
- package/dist/lib/modules/events/schema.mjs.map +1 -0
- package/dist/lib/modules/file-channels/resource.d.mts +26 -0
- package/dist/lib/modules/file-channels/resource.mjs +48 -0
- package/dist/lib/modules/file-channels/resource.mjs.map +1 -0
- package/dist/lib/modules/file-channels/schema.d.mts +33 -0
- package/dist/lib/modules/file-channels/schema.mjs +28 -0
- package/dist/lib/modules/file-channels/schema.mjs.map +1 -0
- package/dist/lib/modules/files/resource.d.mts +40 -0
- package/dist/lib/modules/files/resource.mjs +52 -0
- package/dist/lib/modules/files/resource.mjs.map +1 -0
- package/dist/lib/modules/files/schema.d.mts +27 -0
- package/dist/lib/modules/files/schema.mjs +27 -0
- package/dist/lib/modules/files/schema.mjs.map +1 -0
- package/dist/lib/modules/form-responses/resource.d.mts +24 -0
- package/dist/lib/modules/form-responses/resource.mjs +34 -0
- package/dist/lib/modules/form-responses/resource.mjs.map +1 -0
- package/dist/lib/modules/form-responses/schema.d.mts +29 -0
- package/dist/lib/modules/form-responses/schema.mjs +23 -0
- package/dist/lib/modules/form-responses/schema.mjs.map +1 -0
- package/dist/lib/modules/forms/resource.d.mts +24 -0
- package/dist/lib/modules/forms/resource.mjs +40 -0
- package/dist/lib/modules/forms/resource.mjs.map +1 -0
- package/dist/lib/modules/forms/schema.d.mts +22 -0
- package/dist/lib/modules/forms/schema.mjs +19 -0
- package/dist/lib/modules/forms/schema.mjs.map +1 -0
- package/dist/lib/modules/index.d.mts +28 -0
- package/dist/lib/modules/index.mjs +29 -0
- package/dist/lib/modules/internal-users/resource.d.mts +24 -0
- package/dist/lib/modules/internal-users/resource.mjs +37 -0
- package/dist/lib/modules/internal-users/resource.mjs.map +1 -0
- package/dist/lib/modules/internal-users/schema.d.mts +27 -0
- package/dist/lib/modules/internal-users/schema.mjs +24 -0
- package/dist/lib/modules/internal-users/schema.mjs.map +1 -0
- package/dist/lib/modules/invoice-templates/resource.d.mts +22 -0
- package/dist/lib/modules/invoice-templates/resource.mjs +32 -0
- package/dist/lib/modules/invoice-templates/resource.mjs.map +1 -0
- package/dist/lib/modules/invoice-templates/schema.d.mts +21 -0
- package/dist/lib/modules/invoice-templates/schema.mjs +18 -0
- package/dist/lib/modules/invoice-templates/schema.mjs.map +1 -0
- package/dist/lib/modules/invoices/resource.d.mts +30 -0
- package/dist/lib/modules/invoices/resource.mjs +48 -0
- package/dist/lib/modules/invoices/resource.mjs.map +1 -0
- package/dist/lib/modules/invoices/schema.d.mts +81 -0
- package/dist/lib/modules/invoices/schema.mjs +75 -0
- package/dist/lib/modules/invoices/schema.mjs.map +1 -0
- package/dist/lib/modules/message-channels/resource.d.mts +26 -0
- package/dist/lib/modules/message-channels/resource.mjs +48 -0
- package/dist/lib/modules/message-channels/resource.mjs.map +1 -0
- package/dist/lib/modules/message-channels/schema.d.mts +35 -0
- package/dist/lib/modules/message-channels/schema.mjs +30 -0
- package/dist/lib/modules/message-channels/schema.mjs.map +1 -0
- package/dist/lib/modules/messages/resource.d.mts +27 -0
- package/dist/lib/modules/messages/resource.mjs +40 -0
- package/dist/lib/modules/messages/resource.mjs.map +1 -0
- package/dist/lib/modules/messages/schema.d.mts +30 -0
- package/dist/lib/modules/messages/schema.mjs +26 -0
- package/dist/lib/modules/messages/schema.mjs.map +1 -0
- package/dist/lib/modules/notes/resource.d.mts +37 -0
- package/dist/lib/modules/notes/resource.mjs +60 -0
- package/dist/lib/modules/notes/resource.mjs.map +1 -0
- package/dist/lib/modules/notes/schema.d.mts +34 -0
- package/dist/lib/modules/notes/schema.mjs +27 -0
- package/dist/lib/modules/notes/schema.mjs.map +1 -0
- package/dist/lib/modules/notifications/resource.d.mts +27 -0
- package/dist/lib/modules/notifications/resource.mjs +52 -0
- package/dist/lib/modules/notifications/resource.mjs.map +1 -0
- package/dist/lib/modules/notifications/schema.d.mts +52 -0
- package/dist/lib/modules/notifications/schema.mjs +43 -0
- package/dist/lib/modules/notifications/schema.mjs.map +1 -0
- package/dist/lib/modules/payments/resource.d.mts +26 -0
- package/dist/lib/modules/payments/resource.mjs +32 -0
- package/dist/lib/modules/payments/resource.mjs.map +1 -0
- package/dist/lib/modules/payments/schema.d.mts +23 -0
- package/dist/lib/modules/payments/schema.mjs +20 -0
- package/dist/lib/modules/payments/schema.mjs.map +1 -0
- package/dist/lib/modules/prices/resource.d.mts +27 -0
- package/dist/lib/modules/prices/resource.mjs +40 -0
- package/dist/lib/modules/prices/resource.mjs.map +1 -0
- package/dist/lib/modules/prices/schema.d.mts +22 -0
- package/dist/lib/modules/prices/schema.mjs +19 -0
- package/dist/lib/modules/prices/schema.mjs.map +1 -0
- package/dist/lib/modules/products/resource.d.mts +24 -0
- package/dist/lib/modules/products/resource.mjs +40 -0
- package/dist/lib/modules/products/resource.mjs.map +1 -0
- package/dist/lib/modules/products/schema.d.mts +22 -0
- package/dist/lib/modules/products/schema.mjs +19 -0
- package/dist/lib/modules/products/schema.mjs.map +1 -0
- package/dist/lib/modules/subscription-templates/resource.d.mts +22 -0
- package/dist/lib/modules/subscription-templates/resource.mjs +32 -0
- package/dist/lib/modules/subscription-templates/resource.mjs.map +1 -0
- package/dist/lib/modules/subscription-templates/schema.d.mts +21 -0
- package/dist/lib/modules/subscription-templates/schema.mjs +18 -0
- package/dist/lib/modules/subscription-templates/schema.mjs.map +1 -0
- package/dist/lib/modules/subscriptions/resource.d.mts +32 -0
- package/dist/lib/modules/subscriptions/resource.mjs +56 -0
- package/dist/lib/modules/subscriptions/resource.mjs.map +1 -0
- package/dist/lib/modules/subscriptions/schema.d.mts +31 -0
- package/dist/lib/modules/subscriptions/schema.mjs +26 -0
- package/dist/lib/modules/subscriptions/schema.mjs.map +1 -0
- package/dist/lib/modules/task-templates/resource.d.mts +24 -0
- package/dist/lib/modules/task-templates/resource.mjs +40 -0
- package/dist/lib/modules/task-templates/resource.mjs.map +1 -0
- package/dist/lib/modules/task-templates/schema.d.mts +22 -0
- package/dist/lib/modules/task-templates/schema.mjs +19 -0
- package/dist/lib/modules/task-templates/schema.mjs.map +1 -0
- package/dist/lib/modules/tasks/resource.d.mts +38 -0
- package/dist/lib/modules/tasks/resource.mjs +60 -0
- package/dist/lib/modules/tasks/resource.mjs.map +1 -0
- package/dist/lib/modules/tasks/schema.d.mts +45 -0
- package/dist/lib/modules/tasks/schema.mjs +43 -0
- package/dist/lib/modules/tasks/schema.mjs.map +1 -0
- package/dist/lib/modules/workspace/resource.d.mts +19 -0
- package/dist/lib/modules/workspace/resource.mjs +23 -0
- package/dist/lib/modules/workspace/resource.mjs.map +1 -0
- package/dist/lib/modules/workspace/schema.d.mts +23 -0
- package/dist/lib/modules/workspace/schema.mjs +21 -0
- package/dist/lib/modules/workspace/schema.mjs.map +1 -0
- package/dist/lib/pagination/paginate.d.mts +8 -0
- package/dist/lib/pagination/paginate.mjs +24 -0
- package/dist/lib/pagination/paginate.mjs.map +1 -0
- package/dist/logger/index.d.mts +26 -0
- package/dist/logger/index.mjs +45 -0
- package/dist/logger/index.mjs.map +1 -0
- package/dist/schemas/index.d.mts +32 -0
- package/dist/schemas/index.mjs +34 -0
- package/dist/schemas/shared/hex-color.d.mts +8 -0
- package/dist/schemas/shared/hex-color.mjs +7 -0
- package/dist/schemas/shared/hex-color.mjs.map +1 -0
- package/dist/schemas/shared/index.d.mts +3 -0
- package/dist/schemas/shared/index.mjs +4 -0
- package/dist/schemas/shared/membership-type.d.mts +9 -0
- package/dist/schemas/shared/membership-type.mjs +11 -0
- package/dist/schemas/shared/membership-type.mjs.map +1 -0
- package/dist/schemas/shared/token.d.mts +22 -0
- package/dist/schemas/shared/token.mjs +21 -0
- package/dist/schemas/shared/token.mjs.map +1 -0
- package/dist/token/assembly-token.d.mts +96 -0
- package/dist/token/assembly-token.mjs +117 -0
- package/dist/token/assembly-token.mjs.map +1 -0
- package/dist/token/crypto.mjs +98 -0
- package/dist/token/crypto.mjs.map +1 -0
- package/dist/token/index.d.mts +3 -0
- package/dist/token/index.mjs +3 -0
- package/dist/token/parse.d.mts +24 -0
- package/dist/token/parse.mjs +62 -0
- package/dist/token/parse.mjs.map +1 -0
- package/dist/transport/build-search-params.mjs +16 -0
- package/dist/transport/build-search-params.mjs.map +1 -0
- package/dist/transport/http.d.mts +14 -0
- package/dist/transport/http.mjs +142 -0
- package/dist/transport/http.mjs.map +1 -0
- package/dist/transport/parse-response.mjs +17 -0
- package/dist/transport/parse-response.mjs.map +1 -0
- package/dist/version.mjs +7 -0
- package/dist/version.mjs.map +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/transport/http.d.ts
|
|
2
|
+
interface RequestOpts {
|
|
3
|
+
searchParams?: Record<string, string | number | boolean>;
|
|
4
|
+
}
|
|
5
|
+
interface Transport {
|
|
6
|
+
get<T>(path: string, opts?: RequestOpts): Promise<T>;
|
|
7
|
+
post<T>(path: string, body?: unknown, opts?: RequestOpts): Promise<T>;
|
|
8
|
+
put<T>(path: string, body?: unknown, opts?: RequestOpts): Promise<T>;
|
|
9
|
+
patch<T>(path: string, body?: unknown, opts?: RequestOpts): Promise<T>;
|
|
10
|
+
delete(path: string, opts?: RequestOpts): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { Transport };
|
|
14
|
+
//# sourceMappingURL=http.d.mts.map
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { AssemblyUnauthorizedError } from "../errors/unauthorized.mjs";
|
|
2
|
+
import { AssemblyConnectionError } from "../errors/connection.mjs";
|
|
3
|
+
import { AssemblyForbiddenError } from "../errors/forbidden.mjs";
|
|
4
|
+
import { AssemblyNotFoundError } from "../errors/not-found.mjs";
|
|
5
|
+
import { AssemblyRateLimitError } from "../errors/rate-limit.mjs";
|
|
6
|
+
import { AssemblyServerError } from "../errors/server.mjs";
|
|
7
|
+
import { AssemblyValidationError } from "../errors/validation.mjs";
|
|
8
|
+
import ky, { HTTPError } from "ky";
|
|
9
|
+
import pThrottle from "p-throttle";
|
|
10
|
+
//#region src/transport/http.ts
|
|
11
|
+
const DEFAULT_BASE_URL = "https://api.assembly.com";
|
|
12
|
+
const DEFAULT_REQUESTS_PER_SECOND = 20;
|
|
13
|
+
/**
|
|
14
|
+
* Parses a `Retry-After` header value into seconds.
|
|
15
|
+
* Supports both integer seconds and HTTP-date formats (RFC 7231).
|
|
16
|
+
*/
|
|
17
|
+
const parseRetryAfter = (header) => {
|
|
18
|
+
if (!header) return void 0;
|
|
19
|
+
const seconds = Number(header);
|
|
20
|
+
if (!Number.isNaN(seconds)) return seconds >= 0 ? seconds : void 0;
|
|
21
|
+
const dateMs = Date.parse(header);
|
|
22
|
+
if (!Number.isNaN(dateMs)) {
|
|
23
|
+
const delayMs = dateMs - Date.now();
|
|
24
|
+
return delayMs > 0 ? Math.ceil(delayMs / 1e3) : 0;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const tryParseBody = async (response) => {
|
|
28
|
+
try {
|
|
29
|
+
return await response.clone().json();
|
|
30
|
+
} catch {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const createErrorForStatus = (status, cause, details, retryAfterHeader) => {
|
|
35
|
+
switch (status) {
|
|
36
|
+
case 400:
|
|
37
|
+
case 422: return new AssemblyValidationError({
|
|
38
|
+
cause,
|
|
39
|
+
details
|
|
40
|
+
});
|
|
41
|
+
case 401: return new AssemblyUnauthorizedError({
|
|
42
|
+
cause,
|
|
43
|
+
details
|
|
44
|
+
});
|
|
45
|
+
case 403: return new AssemblyForbiddenError({
|
|
46
|
+
cause,
|
|
47
|
+
details
|
|
48
|
+
});
|
|
49
|
+
case 404: return new AssemblyNotFoundError({
|
|
50
|
+
cause,
|
|
51
|
+
details
|
|
52
|
+
});
|
|
53
|
+
case 429: return new AssemblyRateLimitError({
|
|
54
|
+
cause,
|
|
55
|
+
details,
|
|
56
|
+
retryAfter: parseRetryAfter(retryAfterHeader)
|
|
57
|
+
});
|
|
58
|
+
default:
|
|
59
|
+
if (status >= 500) return new AssemblyServerError({
|
|
60
|
+
cause,
|
|
61
|
+
details
|
|
62
|
+
});
|
|
63
|
+
return new AssemblyConnectionError({
|
|
64
|
+
cause,
|
|
65
|
+
details,
|
|
66
|
+
message: `Unexpected HTTP ${status}`
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const mapHttpError = async (error) => {
|
|
71
|
+
const { response } = error;
|
|
72
|
+
const details = await tryParseBody(response);
|
|
73
|
+
return createErrorForStatus(response.status, error, details, response.headers.get("Retry-After"));
|
|
74
|
+
};
|
|
75
|
+
const stripLeadingSlash = (path) => path.startsWith("/") ? path.slice(1) : path;
|
|
76
|
+
const withErrorMapping = async (request) => {
|
|
77
|
+
try {
|
|
78
|
+
return await request;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (error instanceof HTTPError) throw await mapHttpError(error);
|
|
81
|
+
throw new AssemblyConnectionError({ cause: error });
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Creates an HTTP transport backed by `ky` with rate limiting, retry,
|
|
86
|
+
* auth headers, and structured error mapping. Each call produces a fully
|
|
87
|
+
* independent instance (safe for serverless / multi-tenant).
|
|
88
|
+
*/
|
|
89
|
+
const createTransport = (options) => {
|
|
90
|
+
const acquireSlot = pThrottle({
|
|
91
|
+
interval: 1e3,
|
|
92
|
+
limit: options.requestsPerSecond ?? DEFAULT_REQUESTS_PER_SECOND
|
|
93
|
+
})(async () => {});
|
|
94
|
+
const api = ky.create({
|
|
95
|
+
headers: {
|
|
96
|
+
"X-API-Key": options.compoundKey,
|
|
97
|
+
"X-Assembly-SDK-Version": options.sdkVersion
|
|
98
|
+
},
|
|
99
|
+
hooks: { beforeRequest: [async () => {
|
|
100
|
+
await acquireSlot();
|
|
101
|
+
}] },
|
|
102
|
+
prefix: options.baseUrl ?? DEFAULT_BASE_URL,
|
|
103
|
+
retry: {
|
|
104
|
+
limit: options.retryCount ?? 2,
|
|
105
|
+
methods: [
|
|
106
|
+
"get",
|
|
107
|
+
"post",
|
|
108
|
+
"put",
|
|
109
|
+
"patch",
|
|
110
|
+
"delete"
|
|
111
|
+
]
|
|
112
|
+
},
|
|
113
|
+
...options.fetch ? { fetch: options.fetch } : {}
|
|
114
|
+
});
|
|
115
|
+
return {
|
|
116
|
+
get: (path, opts) => withErrorMapping(api.get(stripLeadingSlash(path), { searchParams: opts?.searchParams }).json()),
|
|
117
|
+
post: (path, body, opts) => withErrorMapping(api.post(stripLeadingSlash(path), {
|
|
118
|
+
json: body,
|
|
119
|
+
searchParams: opts?.searchParams
|
|
120
|
+
}).json()),
|
|
121
|
+
put: (path, body, opts) => withErrorMapping(api.put(stripLeadingSlash(path), {
|
|
122
|
+
json: body,
|
|
123
|
+
searchParams: opts?.searchParams
|
|
124
|
+
}).json()),
|
|
125
|
+
patch: (path, body, opts) => withErrorMapping(api.patch(stripLeadingSlash(path), {
|
|
126
|
+
json: body,
|
|
127
|
+
searchParams: opts?.searchParams
|
|
128
|
+
}).json()),
|
|
129
|
+
delete: async (path, opts) => {
|
|
130
|
+
try {
|
|
131
|
+
await api.delete(stripLeadingSlash(path), { searchParams: opts?.searchParams });
|
|
132
|
+
} catch (error) {
|
|
133
|
+
if (error instanceof HTTPError) throw await mapHttpError(error);
|
|
134
|
+
throw new AssemblyConnectionError({ cause: error });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
//#endregion
|
|
140
|
+
export { createTransport };
|
|
141
|
+
|
|
142
|
+
//# sourceMappingURL=http.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.mjs","names":[],"sources":["../../src/transport/http.ts"],"sourcesContent":["import ky, { HTTPError } from \"ky\";\nimport pThrottle from \"p-throttle\";\nimport type { AssemblyError } from \"src/errors/base\";\nimport { AssemblyConnectionError } from \"src/errors/connection\";\nimport { AssemblyForbiddenError } from \"src/errors/forbidden\";\nimport { AssemblyNotFoundError } from \"src/errors/not-found\";\nimport { AssemblyRateLimitError } from \"src/errors/rate-limit\";\nimport { AssemblyServerError } from \"src/errors/server\";\nimport { AssemblyUnauthorizedError } from \"src/errors/unauthorized\";\nimport { AssemblyValidationError } from \"src/errors/validation\";\n\nconst DEFAULT_BASE_URL: string = \"https://api.assembly.com\";\nconst DEFAULT_REQUESTS_PER_SECOND: number = 20;\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\nexport interface TransportOptions {\n /** Pre-built compound key value for the `X-API-Key` header. */\n compoundKey: string;\n /** SDK version string for the `X-Assembly-SDK-Version` header. */\n sdkVersion: string;\n /** Base URL for all API requests. Defaults to the Assembly API. */\n baseUrl?: string;\n /** Maximum number of retry attempts for retryable errors (ky default: 2). */\n retryCount?: number;\n /** Maximum requests per second for the sliding-window rate limiter. */\n requestsPerSecond?: number;\n /** Injectable fetch function for testing. Defaults to global `fetch`. */\n fetch?: typeof globalThis.fetch;\n}\n\nexport interface RequestOpts {\n searchParams?: Record<string, string | number | boolean>;\n}\n\nexport interface Transport {\n get<T>(path: string, opts?: RequestOpts): Promise<T>;\n post<T>(path: string, body?: unknown, opts?: RequestOpts): Promise<T>;\n put<T>(path: string, body?: unknown, opts?: RequestOpts): Promise<T>;\n patch<T>(path: string, body?: unknown, opts?: RequestOpts): Promise<T>;\n delete(path: string, opts?: RequestOpts): Promise<void>;\n}\n\n// ---------------------------------------------------------------------------\n// Retry-After parsing\n// ---------------------------------------------------------------------------\n\n/**\n * Parses a `Retry-After` header value into seconds.\n * Supports both integer seconds and HTTP-date formats (RFC 7231).\n */\nexport const parseRetryAfter = (header: string | null): number | undefined => {\n if (!header) return undefined;\n\n const seconds = Number(header);\n if (!Number.isNaN(seconds)) return seconds >= 0 ? seconds : undefined;\n\n const dateMs = Date.parse(header);\n if (!Number.isNaN(dateMs)) {\n const delayMs = dateMs - Date.now();\n return delayMs > 0 ? Math.ceil(delayMs / 1000) : 0;\n }\n\n return undefined;\n};\n\n// ---------------------------------------------------------------------------\n// Error mapping\n// ---------------------------------------------------------------------------\n\nconst tryParseBody = async (response: Response): Promise<unknown> => {\n try {\n return await response.clone().json();\n } catch {\n return undefined;\n }\n};\n\nconst createErrorForStatus = (\n status: number,\n cause: HTTPError,\n details: unknown,\n retryAfterHeader: string | null,\n): AssemblyError => {\n switch (status) {\n case 400:\n case 422:\n return new AssemblyValidationError({ cause, details });\n case 401:\n return new AssemblyUnauthorizedError({ cause, details });\n case 403:\n return new AssemblyForbiddenError({ cause, details });\n case 404:\n return new AssemblyNotFoundError({ cause, details });\n case 429:\n return new AssemblyRateLimitError({\n cause,\n details,\n retryAfter: parseRetryAfter(retryAfterHeader),\n });\n default:\n if (status >= 500) {\n return new AssemblyServerError({ cause, details });\n }\n return new AssemblyConnectionError({\n cause,\n details,\n message: `Unexpected HTTP ${status}`,\n });\n }\n};\n\nconst mapHttpError = async (error: HTTPError): Promise<AssemblyError> => {\n const { response } = error;\n const details = await tryParseBody(response);\n return createErrorForStatus(response.status, error, details, response.headers.get(\"Retry-After\"));\n};\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nconst stripLeadingSlash = (path: string): string => (path.startsWith(\"/\") ? path.slice(1) : path);\n\nconst withErrorMapping = async <T>(request: Promise<T>): Promise<T> => {\n try {\n return await request;\n } catch (error) {\n if (error instanceof HTTPError) {\n throw await mapHttpError(error);\n }\n throw new AssemblyConnectionError({ cause: error });\n }\n};\n\n// ---------------------------------------------------------------------------\n// Transport factory\n// ---------------------------------------------------------------------------\n\n/**\n * Creates an HTTP transport backed by `ky` with rate limiting, retry,\n * auth headers, and structured error mapping. Each call produces a fully\n * independent instance (safe for serverless / multi-tenant).\n */\nexport const createTransport = (options: TransportOptions): Transport => {\n const acquireSlot = pThrottle({\n interval: 1000,\n limit: options.requestsPerSecond ?? DEFAULT_REQUESTS_PER_SECOND,\n })(async (): Promise<void> => {});\n\n const api = ky.create({\n headers: {\n \"X-API-Key\": options.compoundKey,\n \"X-Assembly-SDK-Version\": options.sdkVersion,\n },\n hooks: {\n beforeRequest: [\n async (): Promise<void> => {\n await acquireSlot();\n },\n ],\n },\n prefix: options.baseUrl ?? DEFAULT_BASE_URL,\n retry: {\n limit: options.retryCount ?? 2,\n methods: [\"get\", \"post\", \"put\", \"patch\", \"delete\"],\n },\n ...(options.fetch ? { fetch: options.fetch } : {}),\n });\n\n return {\n get: <T>(path: string, opts?: RequestOpts): Promise<T> =>\n withErrorMapping(\n api\n .get(stripLeadingSlash(path), {\n searchParams: opts?.searchParams,\n })\n .json<T>(),\n ),\n\n post: <T>(path: string, body?: unknown, opts?: RequestOpts): Promise<T> =>\n withErrorMapping(\n api\n .post(stripLeadingSlash(path), {\n json: body,\n searchParams: opts?.searchParams,\n })\n .json<T>(),\n ),\n\n put: <T>(path: string, body?: unknown, opts?: RequestOpts): Promise<T> =>\n withErrorMapping(\n api\n .put(stripLeadingSlash(path), {\n json: body,\n searchParams: opts?.searchParams,\n })\n .json<T>(),\n ),\n\n patch: <T>(path: string, body?: unknown, opts?: RequestOpts): Promise<T> =>\n withErrorMapping(\n api\n .patch(stripLeadingSlash(path), {\n json: body,\n searchParams: opts?.searchParams,\n })\n .json<T>(),\n ),\n\n delete: async (path: string, opts?: RequestOpts): Promise<void> => {\n try {\n await api.delete(stripLeadingSlash(path), {\n searchParams: opts?.searchParams,\n });\n } catch (error) {\n if (error instanceof HTTPError) {\n throw await mapHttpError(error);\n }\n throw new AssemblyConnectionError({ cause: error });\n }\n },\n };\n};\n"],"mappings":";;;;;;;;;;AAWA,MAAM,mBAA2B;AACjC,MAAM,8BAAsC;;;;;AAyC5C,MAAa,mBAAmB,WAA8C;AAC5E,KAAI,CAAC,OAAQ,QAAO,KAAA;CAEpB,MAAM,UAAU,OAAO,OAAO;AAC9B,KAAI,CAAC,OAAO,MAAM,QAAQ,CAAE,QAAO,WAAW,IAAI,UAAU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EAGxD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AssemblyResponseParseError } from "../errors/response-parse.mjs";
|
|
2
|
+
//#region src/transport/parse-response.ts
|
|
3
|
+
/**
|
|
4
|
+
* Optionally validates `data` against a Zod schema.
|
|
5
|
+
* When `validate` is false, returns `data` as-is (cast to `T`).
|
|
6
|
+
* When `validate` is true and parsing fails, throws `AssemblyResponseParseError`.
|
|
7
|
+
*/
|
|
8
|
+
const parseResponse = ({ schema, data, validate }) => {
|
|
9
|
+
if (!validate) return data;
|
|
10
|
+
const result = schema.safeParse(data);
|
|
11
|
+
if (!result.success) throw new AssemblyResponseParseError({ cause: result.error });
|
|
12
|
+
return result.data;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
export { parseResponse };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=parse-response.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-response.mjs","names":[],"sources":["../../src/transport/parse-response.ts"],"sourcesContent":["import { AssemblyResponseParseError } from \"src/errors/response-parse\";\nimport type { z } from \"zod\";\n\n/**\n * Optionally validates `data` against a Zod schema.\n * When `validate` is false, returns `data` as-is (cast to `T`).\n * When `validate` is true and parsing fails, throws `AssemblyResponseParseError`.\n */\nexport const parseResponse = <T>({\n schema,\n data,\n validate,\n}: {\n schema: z.ZodType<T>;\n data: unknown;\n validate: boolean;\n}): T => {\n if (!validate) return data as T;\n\n const result = schema.safeParse(data);\n if (!result.success) {\n throw new AssemblyResponseParseError({ cause: result.error });\n }\n return result.data;\n};\n"],"mappings":";;;;;;;AAQA,MAAa,iBAAoB,EAC/B,QACA,MACA,eAKO;AACP,KAAI,CAAC,SAAU,QAAO;CAEtB,MAAM,SAAS,OAAO,UAAU,KAAK;AACrC,KAAI,CAAC,OAAO,QACV,OAAM,IAAI,2BAA2B,EAAE,OAAO,OAAO,OAAO,CAAC;AAE/D,QAAO,OAAO"}
|
package/dist/version.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["/** SDK version string sent with every API request. */\nexport const SDK_VERSION: string = \"2.0.8\";\n"],"mappings":";;AACA,MAAa,cAAsB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "assembly-kit",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "TypeScript SDK for the Assembly platform",
|
|
5
|
+
"homepage": "https://github.com/outsidestudio/assembly-kit#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/outsidestudio/assembly-kit/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/outsidestudio/assembly-kit.git"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"CLAUDE.md"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./dist/index.mjs",
|
|
21
|
+
"./bridge-ui": "./dist/bridge-ui/index.mjs",
|
|
22
|
+
"./client": "./dist/client/index.mjs",
|
|
23
|
+
"./errors": "./dist/errors/index.mjs",
|
|
24
|
+
"./logger": "./dist/logger/index.mjs",
|
|
25
|
+
"./schemas": "./dist/schemas/index.mjs",
|
|
26
|
+
"./token": "./dist/token/index.mjs",
|
|
27
|
+
"./package.json": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "vp pack",
|
|
34
|
+
"dev": "vp pack --watch",
|
|
35
|
+
"test": "vp test",
|
|
36
|
+
"check": "vp check",
|
|
37
|
+
"release": "bumpp --commit --push --tag",
|
|
38
|
+
"prepublishOnly": "vp run build",
|
|
39
|
+
"prepare": "vp config"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"ky": "^2.0.2",
|
|
43
|
+
"p-throttle": "^8.1.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@assembly-js/app-bridge": "^1.1.1",
|
|
47
|
+
"@types/node": "^25.6.0",
|
|
48
|
+
"@types/react": "^19.2.14",
|
|
49
|
+
"@typescript/native-preview": "7.0.0-dev.20260505.1",
|
|
50
|
+
"bumpp": "^11.0.1",
|
|
51
|
+
"pino": "^10.3.1",
|
|
52
|
+
"pino-pretty": "^13.1.3",
|
|
53
|
+
"react": "^19.2.5",
|
|
54
|
+
"typescript": "^6.0.3",
|
|
55
|
+
"vite-plus": "^0.1.20",
|
|
56
|
+
"zod": "^4.4.3"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@assembly-js/app-bridge": "^1.1.1",
|
|
60
|
+
"pino": ">=9",
|
|
61
|
+
"pino-pretty": ">=10",
|
|
62
|
+
"react": ">=18",
|
|
63
|
+
"typescript": ">=5",
|
|
64
|
+
"zod": ">=4"
|
|
65
|
+
},
|
|
66
|
+
"peerDependenciesMeta": {
|
|
67
|
+
"@assembly-js/app-bridge": {
|
|
68
|
+
"optional": true
|
|
69
|
+
},
|
|
70
|
+
"pino": {
|
|
71
|
+
"optional": true
|
|
72
|
+
},
|
|
73
|
+
"pino-pretty": {
|
|
74
|
+
"optional": true
|
|
75
|
+
},
|
|
76
|
+
"react": {
|
|
77
|
+
"optional": true
|
|
78
|
+
},
|
|
79
|
+
"typescript": {
|
|
80
|
+
"optional": true
|
|
81
|
+
},
|
|
82
|
+
"zod": {
|
|
83
|
+
"optional": true
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"packageManager": "bun@1.3.12",
|
|
87
|
+
"pnpm": {
|
|
88
|
+
"overrides": {
|
|
89
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
|
|
90
|
+
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|