@onkernel/sdk 0.0.1-alpha.1 → 0.1.0-alpha.10
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/CHANGELOG.md +92 -0
- package/LICENSE +201 -0
- package/README.md +416 -8
- package/api-promise.d.mts +2 -0
- package/api-promise.d.mts.map +1 -0
- package/api-promise.d.ts +2 -0
- package/api-promise.d.ts.map +1 -0
- package/api-promise.js +6 -0
- package/api-promise.js.map +1 -0
- package/api-promise.mjs +2 -0
- package/api-promise.mjs.map +1 -0
- package/client.d.mts +203 -0
- package/client.d.mts.map +1 -0
- package/client.d.ts +203 -0
- package/client.d.ts.map +1 -0
- package/client.js +477 -0
- package/client.js.map +1 -0
- package/client.mjs +473 -0
- package/client.mjs.map +1 -0
- package/core/api-promise.d.mts +46 -0
- package/core/api-promise.d.mts.map +1 -0
- package/core/api-promise.d.ts +46 -0
- package/core/api-promise.d.ts.map +1 -0
- package/core/api-promise.js +74 -0
- package/core/api-promise.js.map +1 -0
- package/core/api-promise.mjs +70 -0
- package/core/api-promise.mjs.map +1 -0
- package/core/app-framework.d.mts +49 -0
- package/core/app-framework.d.mts.map +1 -0
- package/core/app-framework.d.ts +49 -0
- package/core/app-framework.d.ts.map +1 -0
- package/core/app-framework.js +105 -0
- package/core/app-framework.js.map +1 -0
- package/core/app-framework.mjs +101 -0
- package/core/app-framework.mjs.map +1 -0
- package/core/error.d.mts +46 -0
- package/core/error.d.mts.map +1 -0
- package/core/error.d.ts +46 -0
- package/core/error.d.ts.map +1 -0
- package/core/error.js +113 -0
- package/core/error.js.map +1 -0
- package/core/error.mjs +97 -0
- package/core/error.mjs.map +1 -0
- package/core/resource.d.mts +6 -0
- package/core/resource.d.mts.map +1 -0
- package/core/resource.d.ts +6 -0
- package/core/resource.d.ts.map +1 -0
- package/core/resource.js +11 -0
- package/core/resource.js.map +1 -0
- package/core/resource.mjs +7 -0
- package/core/resource.mjs.map +1 -0
- package/core/uploads.d.mts +3 -0
- package/core/uploads.d.mts.map +1 -0
- package/core/uploads.d.ts +3 -0
- package/core/uploads.d.ts.map +1 -0
- package/core/uploads.js +6 -0
- package/core/uploads.js.map +1 -0
- package/core/uploads.mjs +2 -0
- package/core/uploads.mjs.map +1 -0
- package/error.d.mts +2 -0
- package/error.d.mts.map +1 -0
- package/error.d.ts +2 -0
- package/error.d.ts.map +1 -0
- package/error.js +6 -0
- package/error.js.map +1 -0
- package/error.mjs +2 -0
- package/error.mjs.map +1 -0
- package/index.d.mts +7 -0
- package/index.d.mts.map +1 -0
- package/index.d.ts +7 -0
- package/index.d.ts.map +1 -0
- package/index.js +32 -0
- package/index.js.map +1 -0
- package/index.mjs +8 -0
- package/index.mjs.map +1 -0
- package/internal/builtin-types.d.mts +73 -0
- package/internal/builtin-types.d.mts.map +1 -0
- package/internal/builtin-types.d.ts +73 -0
- package/internal/builtin-types.d.ts.map +1 -0
- package/internal/builtin-types.js +4 -0
- package/internal/builtin-types.js.map +1 -0
- package/internal/builtin-types.mjs +3 -0
- package/internal/builtin-types.mjs.map +1 -0
- package/internal/detect-platform.d.mts +15 -0
- package/internal/detect-platform.d.mts.map +1 -0
- package/internal/detect-platform.d.ts +15 -0
- package/internal/detect-platform.d.ts.map +1 -0
- package/internal/detect-platform.js +162 -0
- package/internal/detect-platform.js.map +1 -0
- package/internal/detect-platform.mjs +157 -0
- package/internal/detect-platform.mjs.map +1 -0
- package/internal/errors.d.mts +3 -0
- package/internal/errors.d.mts.map +1 -0
- package/internal/errors.d.ts +3 -0
- package/internal/errors.d.ts.map +1 -0
- package/internal/errors.js +41 -0
- package/internal/errors.js.map +1 -0
- package/internal/errors.mjs +36 -0
- package/internal/errors.mjs.map +1 -0
- package/internal/headers.d.mts +20 -0
- package/internal/headers.d.mts.map +1 -0
- package/internal/headers.d.ts +20 -0
- package/internal/headers.d.ts.map +1 -0
- package/internal/headers.js +79 -0
- package/internal/headers.js.map +1 -0
- package/internal/headers.mjs +74 -0
- package/internal/headers.mjs.map +1 -0
- package/internal/parse.d.mts +12 -0
- package/internal/parse.d.mts.map +1 -0
- package/internal/parse.d.ts +12 -0
- package/internal/parse.d.ts.map +1 -0
- package/internal/parse.js +35 -0
- package/internal/parse.js.map +1 -0
- package/internal/parse.mjs +32 -0
- package/internal/parse.mjs.map +1 -0
- package/internal/request-options.d.mts +32 -0
- package/internal/request-options.d.mts.map +1 -0
- package/internal/request-options.d.ts +32 -0
- package/internal/request-options.d.ts.map +1 -0
- package/internal/request-options.js +14 -0
- package/internal/request-options.js.map +1 -0
- package/internal/request-options.mjs +10 -0
- package/internal/request-options.mjs.map +1 -0
- package/internal/shim-types.d.mts +28 -0
- package/internal/shim-types.d.ts +28 -0
- package/internal/shims.d.mts +20 -0
- package/internal/shims.d.mts.map +1 -0
- package/internal/shims.d.ts +20 -0
- package/internal/shims.d.ts.map +1 -0
- package/internal/shims.js +92 -0
- package/internal/shims.js.map +1 -0
- package/internal/shims.mjs +85 -0
- package/internal/shims.mjs.map +1 -0
- package/internal/to-file.d.mts +45 -0
- package/internal/to-file.d.mts.map +1 -0
- package/internal/to-file.d.ts +45 -0
- package/internal/to-file.d.ts.map +1 -0
- package/internal/to-file.js +91 -0
- package/internal/to-file.js.map +1 -0
- package/internal/to-file.mjs +88 -0
- package/internal/to-file.mjs.map +1 -0
- package/internal/tslib.js +81 -0
- package/internal/tslib.mjs +17 -0
- package/internal/types.d.mts +67 -0
- package/internal/types.d.mts.map +1 -0
- package/internal/types.d.ts +67 -0
- package/internal/types.d.ts.map +1 -0
- package/internal/types.js +4 -0
- package/internal/types.js.map +1 -0
- package/internal/types.mjs +3 -0
- package/internal/types.mjs.map +1 -0
- package/internal/uploads.d.mts +42 -0
- package/internal/uploads.d.mts.map +1 -0
- package/internal/uploads.d.ts +42 -0
- package/internal/uploads.d.ts.map +1 -0
- package/internal/uploads.js +141 -0
- package/internal/uploads.js.map +1 -0
- package/internal/uploads.mjs +131 -0
- package/internal/uploads.mjs.map +1 -0
- package/internal/utils/base64.d.mts +3 -0
- package/internal/utils/base64.d.mts.map +1 -0
- package/internal/utils/base64.d.ts +3 -0
- package/internal/utils/base64.d.ts.map +1 -0
- package/internal/utils/base64.js +38 -0
- package/internal/utils/base64.js.map +1 -0
- package/internal/utils/base64.mjs +33 -0
- package/internal/utils/base64.mjs.map +1 -0
- package/internal/utils/bytes.d.mts +4 -0
- package/internal/utils/bytes.d.mts.map +1 -0
- package/internal/utils/bytes.d.ts +4 -0
- package/internal/utils/bytes.d.ts.map +1 -0
- package/internal/utils/bytes.js +31 -0
- package/internal/utils/bytes.js.map +1 -0
- package/internal/utils/bytes.mjs +26 -0
- package/internal/utils/bytes.mjs.map +1 -0
- package/internal/utils/env.d.mts +9 -0
- package/internal/utils/env.d.mts.map +1 -0
- package/internal/utils/env.d.ts +9 -0
- package/internal/utils/env.d.ts.map +1 -0
- package/internal/utils/env.js +22 -0
- package/internal/utils/env.js.map +1 -0
- package/internal/utils/env.mjs +18 -0
- package/internal/utils/env.mjs.map +1 -0
- package/internal/utils/log.d.mts +37 -0
- package/internal/utils/log.d.mts.map +1 -0
- package/internal/utils/log.d.ts +37 -0
- package/internal/utils/log.d.ts.map +1 -0
- package/internal/utils/log.js +85 -0
- package/internal/utils/log.js.map +1 -0
- package/internal/utils/log.mjs +79 -0
- package/internal/utils/log.mjs.map +1 -0
- package/internal/utils/path.d.mts +15 -0
- package/internal/utils/path.d.mts.map +1 -0
- package/internal/utils/path.d.ts +15 -0
- package/internal/utils/path.d.ts.map +1 -0
- package/internal/utils/path.js +58 -0
- package/internal/utils/path.js.map +1 -0
- package/internal/utils/path.mjs +53 -0
- package/internal/utils/path.mjs.map +1 -0
- package/internal/utils/sleep.d.mts +2 -0
- package/internal/utils/sleep.d.mts.map +1 -0
- package/internal/utils/sleep.d.ts +2 -0
- package/internal/utils/sleep.d.ts.map +1 -0
- package/internal/utils/sleep.js +7 -0
- package/internal/utils/sleep.js.map +1 -0
- package/internal/utils/sleep.mjs +3 -0
- package/internal/utils/sleep.mjs.map +1 -0
- package/internal/utils/uuid.d.mts +5 -0
- package/internal/utils/uuid.d.mts.map +1 -0
- package/internal/utils/uuid.d.ts +5 -0
- package/internal/utils/uuid.d.ts.map +1 -0
- package/internal/utils/uuid.js +19 -0
- package/internal/utils/uuid.js.map +1 -0
- package/internal/utils/uuid.mjs +15 -0
- package/internal/utils/uuid.mjs.map +1 -0
- package/internal/utils/values.d.mts +16 -0
- package/internal/utils/values.d.mts.map +1 -0
- package/internal/utils/values.d.ts +16 -0
- package/internal/utils/values.d.ts.map +1 -0
- package/internal/utils/values.js +109 -0
- package/internal/utils/values.js.map +1 -0
- package/internal/utils/values.mjs +92 -0
- package/internal/utils/values.mjs.map +1 -0
- package/internal/utils.d.mts +7 -0
- package/internal/utils.d.mts.map +1 -0
- package/internal/utils.d.ts +7 -0
- package/internal/utils.d.ts.map +1 -0
- package/internal/utils.js +11 -0
- package/internal/utils.js.map +1 -0
- package/internal/utils.mjs +8 -0
- package/internal/utils.mjs.map +1 -0
- package/package.json +133 -42
- package/resource.d.mts +2 -0
- package/resource.d.mts.map +1 -0
- package/resource.d.ts +2 -0
- package/resource.d.ts.map +1 -0
- package/resource.js +6 -0
- package/resource.js.map +1 -0
- package/resource.mjs +2 -0
- package/resource.mjs.map +1 -0
- package/resources/apps.d.mts +142 -0
- package/resources/apps.d.mts.map +1 -0
- package/resources/apps.d.ts +142 -0
- package/resources/apps.d.ts.map +1 -0
- package/resources/apps.js +54 -0
- package/resources/apps.js.map +1 -0
- package/resources/apps.mjs +50 -0
- package/resources/apps.mjs.map +1 -0
- package/resources/browser.d.mts +33 -0
- package/resources/browser.d.mts.map +1 -0
- package/resources/browser.d.ts +33 -0
- package/resources/browser.d.ts.map +1 -0
- package/resources/browser.js +15 -0
- package/resources/browser.js.map +1 -0
- package/resources/browser.mjs +11 -0
- package/resources/browser.mjs.map +1 -0
- package/resources/index.d.mts +3 -0
- package/resources/index.d.mts.map +1 -0
- package/resources/index.d.ts +3 -0
- package/resources/index.d.ts.map +1 -0
- package/resources/index.js +9 -0
- package/resources/index.js.map +1 -0
- package/resources/index.mjs +4 -0
- package/resources/index.mjs.map +1 -0
- package/resources.d.mts +2 -0
- package/resources.d.mts.map +1 -0
- package/resources.d.ts +2 -0
- package/resources.d.ts.map +1 -0
- package/resources.js +5 -0
- package/resources.js.map +1 -0
- package/resources.mjs +2 -0
- package/resources.mjs.map +1 -0
- package/src/api-promise.ts +2 -0
- package/src/client.ts +759 -0
- package/src/core/README.md +3 -0
- package/src/core/api-promise.ts +92 -0
- package/src/core/app-framework.ts +137 -0
- package/src/core/error.ts +130 -0
- package/src/core/resource.ts +11 -0
- package/src/core/uploads.ts +2 -0
- package/src/error.ts +2 -0
- package/src/index.ts +24 -0
- package/src/internal/README.md +3 -0
- package/src/internal/builtin-types.ts +93 -0
- package/src/internal/detect-platform.ts +196 -0
- package/src/internal/errors.ts +33 -0
- package/src/internal/headers.ts +97 -0
- package/src/internal/parse.ts +50 -0
- package/src/internal/request-options.ts +37 -0
- package/src/internal/shim-types.d.ts +28 -0
- package/src/internal/shims.ts +107 -0
- package/src/internal/to-file.ts +154 -0
- package/src/internal/types.ts +92 -0
- package/src/internal/uploads.ts +187 -0
- package/src/internal/utils/base64.ts +40 -0
- package/src/internal/utils/bytes.ts +32 -0
- package/src/internal/utils/env.ts +18 -0
- package/src/internal/utils/log.ts +126 -0
- package/src/internal/utils/path.ts +63 -0
- package/src/internal/utils/sleep.ts +3 -0
- package/src/internal/utils/uuid.ts +17 -0
- package/src/internal/utils/values.ts +102 -0
- package/src/internal/utils.ts +8 -0
- package/src/lib/.keep +4 -0
- package/src/resource.ts +2 -0
- package/src/resources/apps.ts +187 -0
- package/src/resources/browser.ts +48 -0
- package/src/resources/index.ts +11 -0
- package/src/resources.ts +1 -0
- package/src/tsconfig.json +11 -0
- package/src/uploads.ts +2 -0
- package/src/version.ts +1 -0
- package/uploads.d.mts +2 -0
- package/uploads.d.mts.map +1 -0
- package/uploads.d.ts +2 -0
- package/uploads.d.ts.map +1 -0
- package/uploads.js +6 -0
- package/uploads.js.map +1 -0
- package/uploads.mjs +2 -0
- package/uploads.mjs.map +1 -0
- package/version.d.mts +2 -0
- package/version.d.mts.map +1 -0
- package/version.d.ts +2 -0
- package/version.d.ts.map +1 -0
- package/version.js +5 -0
- package/version.js.map +1 -0
- package/version.mjs +2 -0
- package/version.mjs.map +1 -0
- package/dist/index.cjs +0 -71
- package/dist/index.d.cts +0 -59
- package/dist/index.d.ts +0 -59
- package/dist/index.js +0 -68
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { KernelError } from '../../core/error';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Percent-encode everything that isn't safe to have in a path without encoding safe chars.
|
|
5
|
+
*
|
|
6
|
+
* Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:
|
|
7
|
+
* > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
|
8
|
+
* > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
|
|
9
|
+
* > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
|
10
|
+
*/
|
|
11
|
+
export function encodeURIPath(str: string) {
|
|
12
|
+
return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
|
|
16
|
+
function path(statics: readonly string[], ...params: readonly unknown[]): string {
|
|
17
|
+
// If there are no params, no processing is needed.
|
|
18
|
+
if (statics.length === 1) return statics[0]!;
|
|
19
|
+
|
|
20
|
+
let postPath = false;
|
|
21
|
+
const path = statics.reduce((previousValue, currentValue, index) => {
|
|
22
|
+
if (/[?#]/.test(currentValue)) {
|
|
23
|
+
postPath = true;
|
|
24
|
+
}
|
|
25
|
+
return (
|
|
26
|
+
previousValue +
|
|
27
|
+
currentValue +
|
|
28
|
+
(index === params.length ? '' : (postPath ? encodeURIComponent : pathEncoder)(String(params[index])))
|
|
29
|
+
);
|
|
30
|
+
}, '');
|
|
31
|
+
|
|
32
|
+
const pathOnly = path.split(/[?#]/, 1)[0]!;
|
|
33
|
+
const invalidSegments = [];
|
|
34
|
+
const invalidSegmentPattern = /(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
|
|
35
|
+
let match;
|
|
36
|
+
|
|
37
|
+
// Find all invalid segments
|
|
38
|
+
while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
|
|
39
|
+
invalidSegments.push({
|
|
40
|
+
start: match.index,
|
|
41
|
+
length: match[0].length,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (invalidSegments.length > 0) {
|
|
46
|
+
let lastEnd = 0;
|
|
47
|
+
const underline = invalidSegments.reduce((acc, segment) => {
|
|
48
|
+
const spaces = ' '.repeat(segment.start - lastEnd);
|
|
49
|
+
const arrows = '^'.repeat(segment.length);
|
|
50
|
+
lastEnd = segment.start + segment.length;
|
|
51
|
+
return acc + spaces + arrows;
|
|
52
|
+
}, '');
|
|
53
|
+
|
|
54
|
+
throw new KernelError(`Path parameters result in path with invalid segments:\n${path}\n${underline}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return path;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
|
|
62
|
+
*/
|
|
63
|
+
export const path = createPathTagFunction(encodeURIPath);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* https://stackoverflow.com/a/2117523
|
|
5
|
+
*/
|
|
6
|
+
export let uuid4 = function () {
|
|
7
|
+
const { crypto } = globalThis as any;
|
|
8
|
+
if (crypto?.randomUUID) {
|
|
9
|
+
uuid4 = crypto.randomUUID.bind(crypto);
|
|
10
|
+
return crypto.randomUUID();
|
|
11
|
+
}
|
|
12
|
+
const u8 = new Uint8Array(1);
|
|
13
|
+
const randomByte = crypto ? () => crypto.getRandomValues(u8)[0]! : () => (Math.random() * 0xff) & 0xff;
|
|
14
|
+
return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, (c) =>
|
|
15
|
+
(+c ^ (randomByte() & (15 >> (+c / 4)))).toString(16),
|
|
16
|
+
);
|
|
17
|
+
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { KernelError } from '../../core/error';
|
|
4
|
+
|
|
5
|
+
// https://url.spec.whatwg.org/#url-scheme-string
|
|
6
|
+
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
|
|
7
|
+
|
|
8
|
+
export const isAbsoluteURL = (url: string): boolean => {
|
|
9
|
+
return startsWithSchemeRegexp.test(url);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/** Returns an object if the given value isn't an object, otherwise returns as-is */
|
|
13
|
+
export function maybeObj(x: unknown): object {
|
|
14
|
+
if (typeof x !== 'object') {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return x ?? {};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// https://stackoverflow.com/a/34491287
|
|
22
|
+
export function isEmptyObj(obj: Object | null | undefined): boolean {
|
|
23
|
+
if (!obj) return true;
|
|
24
|
+
for (const _k in obj) return false;
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// https://eslint.org/docs/latest/rules/no-prototype-builtins
|
|
29
|
+
export function hasOwn<T extends object = object>(obj: T, key: PropertyKey): key is keyof T {
|
|
30
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function isObj(obj: unknown): obj is Record<string, unknown> {
|
|
34
|
+
return obj != null && typeof obj === 'object' && !Array.isArray(obj);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const ensurePresent = <T>(value: T | null | undefined): T => {
|
|
38
|
+
if (value == null) {
|
|
39
|
+
throw new KernelError(`Expected a value to be given but received ${value} instead.`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return value;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const validatePositiveInteger = (name: string, n: unknown): number => {
|
|
46
|
+
if (typeof n !== 'number' || !Number.isInteger(n)) {
|
|
47
|
+
throw new KernelError(`${name} must be an integer`);
|
|
48
|
+
}
|
|
49
|
+
if (n < 0) {
|
|
50
|
+
throw new KernelError(`${name} must be a positive integer`);
|
|
51
|
+
}
|
|
52
|
+
return n;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const coerceInteger = (value: unknown): number => {
|
|
56
|
+
if (typeof value === 'number') return Math.round(value);
|
|
57
|
+
if (typeof value === 'string') return parseInt(value, 10);
|
|
58
|
+
|
|
59
|
+
throw new KernelError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const coerceFloat = (value: unknown): number => {
|
|
63
|
+
if (typeof value === 'number') return value;
|
|
64
|
+
if (typeof value === 'string') return parseFloat(value);
|
|
65
|
+
|
|
66
|
+
throw new KernelError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const coerceBoolean = (value: unknown): boolean => {
|
|
70
|
+
if (typeof value === 'boolean') return value;
|
|
71
|
+
if (typeof value === 'string') return value === 'true';
|
|
72
|
+
return Boolean(value);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const maybeCoerceInteger = (value: unknown): number | undefined => {
|
|
76
|
+
if (value === undefined) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
return coerceInteger(value);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const maybeCoerceFloat = (value: unknown): number | undefined => {
|
|
83
|
+
if (value === undefined) {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
return coerceFloat(value);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const maybeCoerceBoolean = (value: unknown): boolean | undefined => {
|
|
90
|
+
if (value === undefined) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
return coerceBoolean(value);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const safeJSON = (text: string) => {
|
|
97
|
+
try {
|
|
98
|
+
return JSON.parse(text);
|
|
99
|
+
} catch (err) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
export * from './utils/values';
|
|
4
|
+
export * from './utils/base64';
|
|
5
|
+
export * from './utils/env';
|
|
6
|
+
export * from './utils/log';
|
|
7
|
+
export * from './utils/uuid';
|
|
8
|
+
export * from './utils/sleep';
|
package/src/lib/.keep
ADDED
package/src/resource.ts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { APIResource } from '../core/resource';
|
|
4
|
+
import { APIPromise } from '../core/api-promise';
|
|
5
|
+
import { type Uploadable } from '../core/uploads';
|
|
6
|
+
import { RequestOptions } from '../internal/request-options';
|
|
7
|
+
import { multipartFormRequestOptions } from '../internal/uploads';
|
|
8
|
+
import { path } from '../internal/utils/path';
|
|
9
|
+
|
|
10
|
+
export class Apps extends APIResource {
|
|
11
|
+
/**
|
|
12
|
+
* Deploy a new application
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const response = await client.apps.deploy({
|
|
17
|
+
* entrypointRelPath: 'app.py',
|
|
18
|
+
* file: fs.createReadStream('path/to/file'),
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
deploy(body: AppDeployParams, options?: RequestOptions): APIPromise<AppDeployResponse> {
|
|
23
|
+
return this._client.post('/apps/deploy', multipartFormRequestOptions({ body, ...options }, this._client));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Invoke an application
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const response = await client.apps.invoke({
|
|
32
|
+
* actionName: 'analyze',
|
|
33
|
+
* appName: 'my-awesome-app',
|
|
34
|
+
* payload: { data: 'example input' },
|
|
35
|
+
* version: '1.0.0',
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
invoke(body: AppInvokeParams, options?: RequestOptions): APIPromise<AppInvokeResponse> {
|
|
40
|
+
return this._client.post('/apps/invoke', { body, ...options });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Get an app invocation by id
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const response = await client.apps.retrieveInvocation(
|
|
49
|
+
* 'ckqwer3o20000jb9s7abcdef',
|
|
50
|
+
* );
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
retrieveInvocation(id: string, options?: RequestOptions): APIPromise<AppRetrieveInvocationResponse> {
|
|
54
|
+
return this._client.get(path`/apps/invocations/${id}`, options);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface AppDeployResponse {
|
|
59
|
+
apps: Array<AppDeployResponse.App>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Success message
|
|
63
|
+
*/
|
|
64
|
+
message: string;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Status of the deployment
|
|
68
|
+
*/
|
|
69
|
+
success: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export namespace AppDeployResponse {
|
|
73
|
+
export interface App {
|
|
74
|
+
/**
|
|
75
|
+
* ID for the app version deployed
|
|
76
|
+
*/
|
|
77
|
+
id: string;
|
|
78
|
+
|
|
79
|
+
actions: Array<App.Action>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Name of the app
|
|
83
|
+
*/
|
|
84
|
+
name: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export namespace App {
|
|
88
|
+
export interface Action {
|
|
89
|
+
/**
|
|
90
|
+
* Name of the action
|
|
91
|
+
*/
|
|
92
|
+
name: string;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface AppInvokeResponse {
|
|
98
|
+
/**
|
|
99
|
+
* ID of the invocation
|
|
100
|
+
*/
|
|
101
|
+
id: string;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Status of the invocation
|
|
105
|
+
*/
|
|
106
|
+
status: 'QUEUED' | 'RUNNING' | 'SUCCEEDED' | 'FAILED';
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Output from the invocation (if available)
|
|
110
|
+
*/
|
|
111
|
+
output?: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface AppRetrieveInvocationResponse {
|
|
115
|
+
id: string;
|
|
116
|
+
|
|
117
|
+
appName: string;
|
|
118
|
+
|
|
119
|
+
finishedAt: string | null;
|
|
120
|
+
|
|
121
|
+
input: string;
|
|
122
|
+
|
|
123
|
+
output: string;
|
|
124
|
+
|
|
125
|
+
startedAt: string;
|
|
126
|
+
|
|
127
|
+
status: string;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface AppDeployParams {
|
|
131
|
+
/**
|
|
132
|
+
* Relative path to the entrypoint of the application
|
|
133
|
+
*/
|
|
134
|
+
entrypointRelPath: string;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* ZIP file containing the application source directory
|
|
138
|
+
*/
|
|
139
|
+
file: Uploadable;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Allow overwriting an existing app version
|
|
143
|
+
*/
|
|
144
|
+
force?: 'true' | 'false';
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Region for deployment. Currently we only support "aws.us-east-1a"
|
|
148
|
+
*/
|
|
149
|
+
region?: 'aws.us-east-1a';
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Version of the application. Can be any string.
|
|
153
|
+
*/
|
|
154
|
+
version?: string;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface AppInvokeParams {
|
|
158
|
+
/**
|
|
159
|
+
* Name of the action to invoke
|
|
160
|
+
*/
|
|
161
|
+
actionName: string;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Name of the application
|
|
165
|
+
*/
|
|
166
|
+
appName: string;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Input data for the application
|
|
170
|
+
*/
|
|
171
|
+
payload: unknown;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Version of the application
|
|
175
|
+
*/
|
|
176
|
+
version: string;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export declare namespace Apps {
|
|
180
|
+
export {
|
|
181
|
+
type AppDeployResponse as AppDeployResponse,
|
|
182
|
+
type AppInvokeResponse as AppInvokeResponse,
|
|
183
|
+
type AppRetrieveInvocationResponse as AppRetrieveInvocationResponse,
|
|
184
|
+
type AppDeployParams as AppDeployParams,
|
|
185
|
+
type AppInvokeParams as AppInvokeParams,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { APIResource } from '../core/resource';
|
|
4
|
+
import { APIPromise } from '../core/api-promise';
|
|
5
|
+
import { RequestOptions } from '../internal/request-options';
|
|
6
|
+
|
|
7
|
+
export class Browser extends APIResource {
|
|
8
|
+
/**
|
|
9
|
+
* Create Browser Session
|
|
10
|
+
*/
|
|
11
|
+
createSession(
|
|
12
|
+
body: BrowserCreateSessionParams,
|
|
13
|
+
options?: RequestOptions,
|
|
14
|
+
): APIPromise<BrowserCreateSessionResponse> {
|
|
15
|
+
return this._client.post('/browser', { body, ...options });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface BrowserCreateSessionResponse {
|
|
20
|
+
/**
|
|
21
|
+
* Websocket URL for Chrome DevTools Protocol connections to the browser session
|
|
22
|
+
*/
|
|
23
|
+
cdp_ws_url: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Remote URL for live viewing the browser session
|
|
27
|
+
*/
|
|
28
|
+
remote_url: string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Unique identifier for the browser session
|
|
32
|
+
*/
|
|
33
|
+
sessionId: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface BrowserCreateSessionParams {
|
|
37
|
+
/**
|
|
38
|
+
* Kernel App invocation ID
|
|
39
|
+
*/
|
|
40
|
+
invocationId: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export declare namespace Browser {
|
|
44
|
+
export {
|
|
45
|
+
type BrowserCreateSessionResponse as BrowserCreateSessionResponse,
|
|
46
|
+
type BrowserCreateSessionParams as BrowserCreateSessionParams,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
Apps,
|
|
5
|
+
type AppDeployResponse,
|
|
6
|
+
type AppInvokeResponse,
|
|
7
|
+
type AppRetrieveInvocationResponse,
|
|
8
|
+
type AppDeployParams,
|
|
9
|
+
type AppInvokeParams,
|
|
10
|
+
} from './apps';
|
|
11
|
+
export { Browser, type BrowserCreateSessionResponse, type BrowserCreateSessionParams } from './browser';
|
package/src/resources.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './resources/index';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
// this config is included in the published src directory to prevent TS errors
|
|
3
|
+
// from appearing when users go to source, and VSCode opens the source .ts file
|
|
4
|
+
// via declaration maps
|
|
5
|
+
"include": ["index.ts"],
|
|
6
|
+
"compilerOptions": {
|
|
7
|
+
"target": "ES2015",
|
|
8
|
+
"lib": ["DOM", "DOM.Iterable", "ES2018"],
|
|
9
|
+
"moduleResolution": "node"
|
|
10
|
+
}
|
|
11
|
+
}
|
package/src/uploads.ts
ADDED
package/src/version.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const VERSION = '0.1.0-alpha.10'; // x-release-please-version
|
package/uploads.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploads.d.mts","sourceRoot":"","sources":["src/uploads.ts"],"names":[],"mappings":""}
|
package/uploads.d.ts
ADDED
package/uploads.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploads.d.ts","sourceRoot":"","sources":["src/uploads.ts"],"names":[],"mappings":""}
|
package/uploads.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("./internal/tslib.js");
|
|
4
|
+
/** @deprecated Import from ./core/uploads instead */
|
|
5
|
+
tslib_1.__exportStar(require("./core/uploads.js"), exports);
|
|
6
|
+
//# sourceMappingURL=uploads.js.map
|
package/uploads.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploads.js","sourceRoot":"","sources":["src/uploads.ts"],"names":[],"mappings":";;;AAAA,qDAAqD;AACrD,4DAA+B"}
|
package/uploads.mjs
ADDED
package/uploads.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uploads.mjs","sourceRoot":"","sources":["src/uploads.ts"],"names":[],"mappings":""}
|
package/version.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.mts","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,mBAAmB,CAAC"}
|
package/version.d.ts
ADDED
package/version.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,mBAAmB,CAAC"}
|
package/version.js
ADDED
package/version.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,gBAAgB,CAAC,CAAC,2BAA2B"}
|
package/version.mjs
ADDED
package/version.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.mjs","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC,CAAC,2BAA2B"}
|
package/dist/index.cjs
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// src/index.ts
|
|
4
|
-
var KernelRegistry = class {
|
|
5
|
-
registry = /* @__PURE__ */ new Map();
|
|
6
|
-
register(item) {
|
|
7
|
-
this.registry.set(item.name, item);
|
|
8
|
-
}
|
|
9
|
-
getAll() {
|
|
10
|
-
return Array.from(this.registry.values());
|
|
11
|
-
}
|
|
12
|
-
getByName(name) {
|
|
13
|
-
return this.registry.get(name);
|
|
14
|
-
}
|
|
15
|
-
getByType(type) {
|
|
16
|
-
return this.getAll().filter((item) => item.type === type);
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
var registry = new KernelRegistry();
|
|
20
|
-
var Kernel = {
|
|
21
|
-
/**
|
|
22
|
-
* Define a scheduled function
|
|
23
|
-
*/
|
|
24
|
-
schedule: (cronExpression, fn) => {
|
|
25
|
-
registry.register({
|
|
26
|
-
type: "schedule",
|
|
27
|
-
name: fn.name || `schedule_${cronExpression.replace(/\s+/g, "_")}`,
|
|
28
|
-
cron: cronExpression,
|
|
29
|
-
handler: fn
|
|
30
|
-
});
|
|
31
|
-
return fn;
|
|
32
|
-
},
|
|
33
|
-
/**
|
|
34
|
-
* Define an HTTP endpoint
|
|
35
|
-
*/
|
|
36
|
-
endpoint: (options, handler) => {
|
|
37
|
-
registry.register({
|
|
38
|
-
type: "http",
|
|
39
|
-
name: handler.name || `endpoint_${options.method.toLowerCase()}_${options.path.replace(/\//g, "_")}`,
|
|
40
|
-
path: options.path,
|
|
41
|
-
method: options.method,
|
|
42
|
-
handler
|
|
43
|
-
});
|
|
44
|
-
return handler;
|
|
45
|
-
},
|
|
46
|
-
/**
|
|
47
|
-
* Use a browser for automation
|
|
48
|
-
* The returned browser object contains cdp_ws_url which should be used with playwright:
|
|
49
|
-
* const browser = await chromium.connectOverCDP(cdp_ws_url);
|
|
50
|
-
*/
|
|
51
|
-
useBrowser: (fn) => {
|
|
52
|
-
return fn({
|
|
53
|
-
cdp_ws_url: "ws://localhost:9222"
|
|
54
|
-
});
|
|
55
|
-
},
|
|
56
|
-
/**
|
|
57
|
-
* Define a function
|
|
58
|
-
*/
|
|
59
|
-
func: (fn) => {
|
|
60
|
-
const name = fn.name || "default";
|
|
61
|
-
registry.register({
|
|
62
|
-
type: "function",
|
|
63
|
-
name,
|
|
64
|
-
handler: fn
|
|
65
|
-
});
|
|
66
|
-
return fn;
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
exports.Kernel = Kernel;
|
|
71
|
-
exports.registry = registry;
|
package/dist/index.d.cts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
interface Request {
|
|
2
|
-
query: Record<string, string>;
|
|
3
|
-
body?: any;
|
|
4
|
-
}
|
|
5
|
-
interface Browser {
|
|
6
|
-
cdp_ws_url: string;
|
|
7
|
-
}
|
|
8
|
-
interface KernelFunction {
|
|
9
|
-
type: 'function';
|
|
10
|
-
name: string;
|
|
11
|
-
handler: (...args: any[]) => Promise<any>;
|
|
12
|
-
}
|
|
13
|
-
interface KernelSchedule {
|
|
14
|
-
type: 'schedule';
|
|
15
|
-
name: string;
|
|
16
|
-
cron: string;
|
|
17
|
-
handler: () => Promise<void>;
|
|
18
|
-
}
|
|
19
|
-
interface KernelEndpoint {
|
|
20
|
-
type: 'http';
|
|
21
|
-
name: string;
|
|
22
|
-
path: string;
|
|
23
|
-
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
24
|
-
handler: (req: Request) => Promise<any>;
|
|
25
|
-
}
|
|
26
|
-
type KernelRegistryItem = KernelFunction | KernelSchedule | KernelEndpoint;
|
|
27
|
-
declare class KernelRegistry {
|
|
28
|
-
private registry;
|
|
29
|
-
register(item: KernelRegistryItem): void;
|
|
30
|
-
getAll(): KernelRegistryItem[];
|
|
31
|
-
getByName(name: string): KernelRegistryItem | undefined;
|
|
32
|
-
getByType(type: 'function' | 'schedule' | 'http'): KernelRegistryItem[];
|
|
33
|
-
}
|
|
34
|
-
declare const registry: KernelRegistry;
|
|
35
|
-
declare const Kernel: {
|
|
36
|
-
/**
|
|
37
|
-
* Define a scheduled function
|
|
38
|
-
*/
|
|
39
|
-
schedule: (cronExpression: string, fn: () => Promise<void>) => () => Promise<void>;
|
|
40
|
-
/**
|
|
41
|
-
* Define an HTTP endpoint
|
|
42
|
-
*/
|
|
43
|
-
endpoint: <T>(options: {
|
|
44
|
-
path: string;
|
|
45
|
-
method: string;
|
|
46
|
-
}, handler: (req: Request) => Promise<T>) => (req: Request) => Promise<T>;
|
|
47
|
-
/**
|
|
48
|
-
* Use a browser for automation
|
|
49
|
-
* The returned browser object contains cdp_ws_url which should be used with playwright:
|
|
50
|
-
* const browser = await chromium.connectOverCDP(cdp_ws_url);
|
|
51
|
-
*/
|
|
52
|
-
useBrowser: <T>(fn: (browser: Browser) => Promise<T>) => Promise<T>;
|
|
53
|
-
/**
|
|
54
|
-
* Define a function
|
|
55
|
-
*/
|
|
56
|
-
func: <T, R>(fn: (input: T) => Promise<R>) => (input: T) => Promise<R>;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export { type Browser, Kernel, type KernelEndpoint, type KernelFunction, type KernelRegistryItem, type KernelSchedule, type Request, registry };
|