@roarkanalytics/sdk 0.1.0-alpha.1 → 0.1.0-alpha.2
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +8 -0
- package/LICENSE +1 -1
- package/README.md +48 -85
- package/_shims/MultipartBody.d.ts +9 -0
- package/_shims/MultipartBody.d.ts.map +1 -0
- package/_shims/MultipartBody.js +16 -0
- package/_shims/MultipartBody.js.map +1 -0
- package/_shims/MultipartBody.mjs +12 -0
- package/_shims/MultipartBody.mjs.map +1 -0
- package/_shims/README.md +46 -0
- package/_shims/auto/runtime-bun.d.ts +5 -0
- package/_shims/auto/runtime-bun.d.ts.map +1 -0
- package/{internal/utils.js → _shims/auto/runtime-bun.js} +5 -8
- package/_shims/auto/runtime-bun.js.map +1 -0
- package/_shims/auto/runtime-bun.mjs +2 -0
- package/_shims/auto/runtime-bun.mjs.map +1 -0
- package/_shims/auto/runtime-node.d.ts +5 -0
- package/_shims/auto/runtime-node.d.ts.map +1 -0
- package/_shims/auto/runtime-node.js +21 -0
- package/_shims/auto/runtime-node.js.map +1 -0
- package/_shims/auto/runtime-node.mjs +2 -0
- package/_shims/auto/runtime-node.mjs.map +1 -0
- package/_shims/auto/runtime.d.ts +5 -0
- package/_shims/auto/runtime.d.ts.map +1 -0
- package/_shims/auto/runtime.js +21 -0
- package/_shims/auto/runtime.js.map +1 -0
- package/_shims/auto/runtime.mjs +2 -0
- package/_shims/auto/runtime.mjs.map +1 -0
- package/_shims/auto/types-node.d.ts +5 -0
- package/_shims/auto/types-node.d.ts.map +1 -0
- package/_shims/auto/types-node.js +21 -0
- package/_shims/auto/types-node.js.map +1 -0
- package/_shims/auto/types-node.mjs +2 -0
- package/_shims/auto/types-node.mjs.map +1 -0
- package/_shims/auto/types.d.ts +101 -0
- package/_shims/auto/types.js +3 -0
- package/_shims/auto/types.mjs +3 -0
- package/_shims/bun-runtime.d.ts +6 -0
- package/_shims/bun-runtime.d.ts.map +1 -0
- package/_shims/bun-runtime.js +14 -0
- package/_shims/bun-runtime.js.map +1 -0
- package/_shims/bun-runtime.mjs +10 -0
- package/_shims/bun-runtime.mjs.map +1 -0
- package/_shims/index.d.ts +81 -0
- package/_shims/index.js +13 -0
- package/_shims/index.mjs +7 -0
- package/_shims/manual-types.d.ts +12 -0
- package/_shims/manual-types.js +3 -0
- package/_shims/manual-types.mjs +3 -0
- package/_shims/node-runtime.d.ts +3 -0
- package/_shims/node-runtime.d.ts.map +1 -0
- package/_shims/node-runtime.js +89 -0
- package/_shims/node-runtime.js.map +1 -0
- package/_shims/node-runtime.mjs +56 -0
- package/_shims/node-runtime.mjs.map +1 -0
- package/_shims/node-types.d.ts +42 -0
- package/_shims/node-types.js +3 -0
- package/_shims/node-types.mjs +3 -0
- package/_shims/registry.d.ts +37 -0
- package/_shims/registry.d.ts.map +1 -0
- package/_shims/registry.js +41 -0
- package/_shims/registry.js.map +1 -0
- package/_shims/registry.mjs +37 -0
- package/_shims/registry.mjs.map +1 -0
- package/_shims/web-runtime.d.ts +5 -0
- package/_shims/web-runtime.d.ts.map +1 -0
- package/_shims/web-runtime.js +78 -0
- package/_shims/web-runtime.js.map +1 -0
- package/_shims/web-runtime.mjs +71 -0
- package/_shims/web-runtime.mjs.map +1 -0
- package/_shims/web-types.d.ts +83 -0
- package/_shims/web-types.js +3 -0
- package/_shims/web-types.mjs +3 -0
- package/core.d.ts +241 -0
- package/core.d.ts.map +1 -0
- package/core.js +908 -0
- package/core.js.map +1 -0
- package/core.mjs +876 -0
- package/core.mjs.map +1 -0
- package/error.d.ts +3 -3
- package/error.d.ts.map +1 -1
- package/error.js +6 -6
- package/error.js.map +1 -1
- package/error.mjs +3 -3
- package/error.mjs.map +1 -1
- package/index.d.mts +109 -5
- package/index.d.ts +109 -5
- package/index.d.ts.map +1 -1
- package/index.js +103 -11
- package/index.js.map +1 -1
- package/index.mjs +77 -5
- package/index.mjs.map +1 -1
- package/package.json +66 -82
- package/resource.d.ts +3 -3
- package/resource.d.ts.map +1 -1
- package/resource.js.map +1 -1
- package/resource.mjs.map +1 -1
- package/resources/calls.d.ts +2 -3
- package/resources/calls.d.ts.map +1 -1
- package/resources/calls.js.map +1 -1
- package/resources/calls.mjs.map +1 -1
- package/resources/index.d.ts.map +1 -1
- package/shims/node.d.ts +30 -0
- package/shims/node.d.ts.map +1 -0
- package/shims/node.js +31 -0
- package/shims/node.js.map +1 -0
- package/shims/node.mjs +5 -0
- package/shims/node.mjs.map +1 -0
- package/shims/web.d.ts +26 -0
- package/shims/web.d.ts.map +1 -0
- package/shims/web.js +31 -0
- package/shims/web.js.map +1 -0
- package/shims/web.mjs +5 -0
- package/shims/web.mjs.map +1 -0
- package/src/_shims/MultipartBody.ts +9 -0
- package/src/_shims/README.md +46 -0
- package/src/_shims/auto/runtime-bun.ts +4 -0
- package/src/_shims/auto/runtime-node.ts +4 -0
- package/src/_shims/auto/runtime.ts +4 -0
- package/src/_shims/auto/types-node.ts +4 -0
- package/src/_shims/auto/types.d.ts +101 -0
- package/src/_shims/auto/types.js +3 -0
- package/src/_shims/auto/types.mjs +3 -0
- package/src/_shims/bun-runtime.ts +14 -0
- package/src/_shims/index.d.ts +81 -0
- package/src/_shims/index.js +13 -0
- package/src/_shims/index.mjs +7 -0
- package/src/_shims/manual-types.d.ts +12 -0
- package/src/_shims/manual-types.js +3 -0
- package/src/_shims/manual-types.mjs +3 -0
- package/src/_shims/node-runtime.ts +81 -0
- package/src/_shims/node-types.d.ts +42 -0
- package/src/_shims/node-types.js +3 -0
- package/src/_shims/node-types.mjs +3 -0
- package/src/_shims/registry.ts +67 -0
- package/src/_shims/web-runtime.ts +103 -0
- package/src/_shims/web-types.d.ts +83 -0
- package/src/_shims/web-types.js +3 -0
- package/src/_shims/web-types.mjs +3 -0
- package/src/core.ts +1200 -0
- package/src/error.ts +3 -3
- package/src/index.ts +172 -5
- package/src/resource.ts +3 -3
- package/src/resources/calls.ts +2 -3
- package/src/shims/node.ts +50 -0
- package/src/shims/web.ts +50 -0
- package/src/tsconfig.json +2 -2
- package/src/uploads.ts +255 -1
- package/src/version.ts +1 -1
- package/uploads.d.ts +74 -1
- package/uploads.d.ts.map +1 -1
- package/uploads.js +168 -3
- package/uploads.js.map +1 -1
- package/uploads.mjs +157 -1
- package/uploads.mjs.map +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
- package/api-promise.d.mts +0 -47
- package/api-promise.d.mts.map +0 -1
- package/api-promise.d.ts +0 -47
- package/api-promise.d.ts.map +0 -1
- package/api-promise.js +0 -84
- package/api-promise.js.map +0 -1
- package/api-promise.mjs +0 -80
- package/api-promise.mjs.map +0 -1
- package/client.d.mts +0 -186
- package/client.d.mts.map +0 -1
- package/client.d.ts +0 -186
- package/client.d.ts.map +0 -1
- package/client.js +0 -449
- package/client.js.map +0 -1
- package/client.mjs +0 -422
- package/client.mjs.map +0 -1
- package/error.d.mts +0 -47
- package/error.d.mts.map +0 -1
- package/index.d.mts.map +0 -1
- package/internal/builtin-types.d.mts +0 -65
- package/internal/builtin-types.d.mts.map +0 -1
- package/internal/builtin-types.d.ts +0 -65
- package/internal/builtin-types.d.ts.map +0 -1
- package/internal/builtin-types.js +0 -4
- package/internal/builtin-types.js.map +0 -1
- package/internal/builtin-types.mjs +0 -3
- package/internal/builtin-types.mjs.map +0 -1
- package/internal/detect-platform.d.mts +0 -15
- package/internal/detect-platform.d.mts.map +0 -1
- package/internal/detect-platform.d.ts +0 -15
- package/internal/detect-platform.d.ts.map +0 -1
- package/internal/detect-platform.js +0 -162
- package/internal/detect-platform.js.map +0 -1
- package/internal/detect-platform.mjs +0 -157
- package/internal/detect-platform.mjs.map +0 -1
- package/internal/errors.d.mts +0 -3
- package/internal/errors.d.mts.map +0 -1
- package/internal/errors.d.ts +0 -3
- package/internal/errors.d.ts.map +0 -1
- package/internal/errors.js +0 -26
- package/internal/errors.js.map +0 -1
- package/internal/errors.mjs +0 -21
- package/internal/errors.mjs.map +0 -1
- package/internal/headers.d.mts +0 -21
- package/internal/headers.d.mts.map +0 -1
- package/internal/headers.d.ts +0 -21
- package/internal/headers.d.ts.map +0 -1
- package/internal/headers.js +0 -77
- package/internal/headers.js.map +0 -1
- package/internal/headers.mjs +0 -72
- package/internal/headers.mjs.map +0 -1
- package/internal/parse.d.mts +0 -10
- package/internal/parse.d.mts.map +0 -1
- package/internal/parse.d.ts +0 -10
- package/internal/parse.d.ts.map +0 -1
- package/internal/parse.js +0 -28
- package/internal/parse.js.map +0 -1
- package/internal/parse.mjs +0 -24
- package/internal/parse.mjs.map +0 -1
- package/internal/polyfill/crypto.node.d.ts +0 -10
- package/internal/polyfill/crypto.node.js +0 -11
- package/internal/polyfill/crypto.node.mjs +0 -2
- package/internal/polyfill/file.node.d.ts +0 -9
- package/internal/polyfill/file.node.js +0 -17
- package/internal/polyfill/file.node.mjs +0 -9
- package/internal/request-options.d.mts +0 -34
- package/internal/request-options.d.mts.map +0 -1
- package/internal/request-options.d.ts +0 -34
- package/internal/request-options.d.ts.map +0 -1
- package/internal/request-options.js +0 -39
- package/internal/request-options.js.map +0 -1
- package/internal/request-options.mjs +0 -34
- package/internal/request-options.mjs.map +0 -1
- package/internal/shim-types.d.mts +0 -28
- package/internal/shim-types.d.ts +0 -28
- package/internal/shims.d.mts +0 -61
- package/internal/shims.d.mts.map +0 -1
- package/internal/shims.d.ts +0 -61
- package/internal/shims.d.ts.map +0 -1
- package/internal/shims.js +0 -101
- package/internal/shims.js.map +0 -1
- package/internal/shims.mjs +0 -92
- package/internal/shims.mjs.map +0 -1
- package/internal/types.d.mts +0 -68
- package/internal/types.d.mts.map +0 -1
- package/internal/types.d.ts +0 -68
- package/internal/types.d.ts.map +0 -1
- package/internal/types.js +0 -4
- package/internal/types.js.map +0 -1
- package/internal/types.mjs +0 -3
- package/internal/types.mjs.map +0 -1
- package/internal/uploads.d.mts +0 -73
- package/internal/uploads.d.mts.map +0 -1
- package/internal/uploads.d.ts +0 -73
- package/internal/uploads.d.ts.map +0 -1
- package/internal/uploads.js +0 -208
- package/internal/uploads.js.map +0 -1
- package/internal/uploads.mjs +0 -200
- package/internal/uploads.mjs.map +0 -1
- package/internal/utils/base64.d.mts +0 -3
- package/internal/utils/base64.d.mts.map +0 -1
- package/internal/utils/base64.d.ts +0 -3
- package/internal/utils/base64.d.ts.map +0 -1
- package/internal/utils/base64.js +0 -33
- package/internal/utils/base64.js.map +0 -1
- package/internal/utils/base64.mjs +0 -28
- package/internal/utils/base64.mjs.map +0 -1
- package/internal/utils/env.d.mts +0 -9
- package/internal/utils/env.d.mts.map +0 -1
- package/internal/utils/env.d.ts +0 -9
- package/internal/utils/env.d.ts.map +0 -1
- package/internal/utils/env.js +0 -22
- package/internal/utils/env.js.map +0 -1
- package/internal/utils/env.mjs +0 -18
- package/internal/utils/env.mjs.map +0 -1
- package/internal/utils/log.d.mts +0 -4
- package/internal/utils/log.d.mts.map +0 -1
- package/internal/utils/log.d.ts +0 -4
- package/internal/utils/log.d.ts.map +0 -1
- package/internal/utils/log.js +0 -47
- package/internal/utils/log.js.map +0 -1
- package/internal/utils/log.mjs +0 -43
- package/internal/utils/log.mjs.map +0 -1
- package/internal/utils/sleep.d.mts +0 -2
- package/internal/utils/sleep.d.mts.map +0 -1
- package/internal/utils/sleep.d.ts +0 -2
- package/internal/utils/sleep.d.ts.map +0 -1
- package/internal/utils/sleep.js +0 -7
- package/internal/utils/sleep.js.map +0 -1
- package/internal/utils/sleep.mjs +0 -3
- package/internal/utils/sleep.mjs.map +0 -1
- package/internal/utils/uuid.d.mts +0 -5
- package/internal/utils/uuid.d.mts.map +0 -1
- package/internal/utils/uuid.d.ts +0 -5
- package/internal/utils/uuid.d.ts.map +0 -1
- package/internal/utils/uuid.js +0 -15
- package/internal/utils/uuid.js.map +0 -1
- package/internal/utils/uuid.mjs +0 -11
- package/internal/utils/uuid.mjs.map +0 -1
- package/internal/utils/values.d.mts +0 -15
- package/internal/utils/values.d.mts.map +0 -1
- package/internal/utils/values.d.ts +0 -15
- package/internal/utils/values.d.ts.map +0 -1
- package/internal/utils/values.js +0 -100
- package/internal/utils/values.js.map +0 -1
- package/internal/utils/values.mjs +0 -84
- package/internal/utils/values.mjs.map +0 -1
- package/internal/utils.d.mts +0 -7
- package/internal/utils.d.mts.map +0 -1
- package/internal/utils.d.ts +0 -7
- package/internal/utils.d.ts.map +0 -1
- package/internal/utils.js.map +0 -1
- package/internal/utils.mjs +0 -8
- package/internal/utils.mjs.map +0 -1
- package/resource.d.mts +0 -6
- package/resource.d.mts.map +0 -1
- package/resources/calls.d.mts +0 -85
- package/resources/calls.d.mts.map +0 -1
- package/resources/index.d.mts +0 -2
- package/resources/index.d.mts.map +0 -1
- package/src/api-promise.ts +0 -92
- package/src/client.ts +0 -646
- package/src/internal/builtin-types.ts +0 -79
- package/src/internal/detect-platform.ts +0 -196
- package/src/internal/errors.ts +0 -22
- package/src/internal/headers.ts +0 -96
- package/src/internal/parse.ts +0 -41
- package/src/internal/polyfill/crypto.node.d.ts +0 -10
- package/src/internal/polyfill/crypto.node.js +0 -11
- package/src/internal/polyfill/crypto.node.mjs +0 -2
- package/src/internal/polyfill/file.node.d.ts +0 -9
- package/src/internal/polyfill/file.node.js +0 -17
- package/src/internal/polyfill/file.node.mjs +0 -9
- package/src/internal/request-options.ts +0 -67
- package/src/internal/shim-types.d.ts +0 -28
- package/src/internal/shims.ts +0 -145
- package/src/internal/types.ts +0 -98
- package/src/internal/uploads.ts +0 -307
- package/src/internal/utils/base64.ts +0 -37
- package/src/internal/utils/env.ts +0 -18
- package/src/internal/utils/log.ts +0 -49
- package/src/internal/utils/sleep.ts +0 -3
- package/src/internal/utils/uuid.ts +0 -13
- package/src/internal/utils/values.ts +0 -94
- package/src/internal/utils.ts +0 -8
- package/uploads.d.mts +0 -2
- package/uploads.d.mts.map +0 -1
- package/version.d.mts +0 -2
- package/version.d.mts.map +0 -1
@@ -0,0 +1,81 @@
|
|
1
|
+
/**
|
2
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
3
|
+
*/
|
4
|
+
import { manual } from './manual-types';
|
5
|
+
import * as auto from "./auto/types";
|
6
|
+
import { type RequestOptions } from '../core';
|
7
|
+
|
8
|
+
type SelectType<Manual, Auto> = unknown extends Manual ? Auto : Manual;
|
9
|
+
|
10
|
+
export const kind: string;
|
11
|
+
|
12
|
+
// @ts-ignore
|
13
|
+
export type Agent = SelectType<manual.Agent, auto.Agent>;
|
14
|
+
|
15
|
+
// @ts-ignore
|
16
|
+
export const fetch: SelectType<typeof manual.fetch, typeof auto.fetch>;
|
17
|
+
|
18
|
+
// @ts-ignore
|
19
|
+
export type Request = SelectType<manual.Request, auto.Request>;
|
20
|
+
// @ts-ignore
|
21
|
+
export type RequestInfo = SelectType<manual.RequestInfo, auto.RequestInfo>;
|
22
|
+
// @ts-ignore
|
23
|
+
export type RequestInit = SelectType<manual.RequestInit, auto.RequestInit>;
|
24
|
+
|
25
|
+
// @ts-ignore
|
26
|
+
export type Response = SelectType<manual.Response, auto.Response>;
|
27
|
+
// @ts-ignore
|
28
|
+
export type ResponseInit = SelectType<manual.ResponseInit, auto.ResponseInit>;
|
29
|
+
// @ts-ignore
|
30
|
+
export type ResponseType = SelectType<manual.ResponseType, auto.ResponseType>;
|
31
|
+
// @ts-ignore
|
32
|
+
export type BodyInit = SelectType<manual.BodyInit, auto.BodyInit>;
|
33
|
+
// @ts-ignore
|
34
|
+
export type Headers = SelectType<manual.Headers, auto.Headers>;
|
35
|
+
// @ts-ignore
|
36
|
+
export const Headers: SelectType<typeof manual.Headers, typeof auto.Headers>;
|
37
|
+
// @ts-ignore
|
38
|
+
export type HeadersInit = SelectType<manual.HeadersInit, auto.HeadersInit>;
|
39
|
+
|
40
|
+
// @ts-ignore
|
41
|
+
export type BlobPropertyBag = SelectType<manual.BlobPropertyBag, auto.BlobPropertyBag>;
|
42
|
+
// @ts-ignore
|
43
|
+
export type FilePropertyBag = SelectType<manual.FilePropertyBag, auto.FilePropertyBag>;
|
44
|
+
// @ts-ignore
|
45
|
+
export type FileFromPathOptions = SelectType<manual.FileFromPathOptions, auto.FileFromPathOptions>;
|
46
|
+
// @ts-ignore
|
47
|
+
export type FormData = SelectType<manual.FormData, auto.FormData>;
|
48
|
+
// @ts-ignore
|
49
|
+
export const FormData: SelectType<typeof manual.FormData, typeof auto.FormData>;
|
50
|
+
// @ts-ignore
|
51
|
+
export type File = SelectType<manual.File, auto.File>;
|
52
|
+
// @ts-ignore
|
53
|
+
export const File: SelectType<typeof manual.File, typeof auto.File>;
|
54
|
+
// @ts-ignore
|
55
|
+
export type Blob = SelectType<manual.Blob, auto.Blob>;
|
56
|
+
// @ts-ignore
|
57
|
+
export const Blob: SelectType<typeof manual.Blob, typeof auto.Blob>;
|
58
|
+
|
59
|
+
// @ts-ignore
|
60
|
+
export type Readable = SelectType<manual.Readable, auto.Readable>;
|
61
|
+
// @ts-ignore
|
62
|
+
export type FsReadStream = SelectType<manual.FsReadStream, auto.FsReadStream>;
|
63
|
+
// @ts-ignore
|
64
|
+
export type ReadableStream = SelectType<manual.ReadableStream, auto.ReadableStream>;
|
65
|
+
// @ts-ignore
|
66
|
+
export const ReadableStream: SelectType<typeof manual.ReadableStream, typeof auto.ReadableStream>;
|
67
|
+
|
68
|
+
export function getMultipartRequestOptions<T = Record<string, unknown>>(
|
69
|
+
form: FormData,
|
70
|
+
opts: RequestOptions<T>,
|
71
|
+
): Promise<RequestOptions<T>>;
|
72
|
+
|
73
|
+
export function getDefaultAgent(url: string): any;
|
74
|
+
|
75
|
+
// @ts-ignore
|
76
|
+
export type FileFromPathOptions = SelectType<manual.FileFromPathOptions, auto.FileFromPathOptions>;
|
77
|
+
|
78
|
+
export function fileFromPath(path: string, options?: FileFromPathOptions): Promise<File>;
|
79
|
+
export function fileFromPath(path: string, filename?: string, options?: FileFromPathOptions): Promise<File>;
|
80
|
+
|
81
|
+
export function isFsReadStream(value: any): value is FsReadStream;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/**
|
2
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
3
|
+
*/
|
4
|
+
const shims = require('./registry');
|
5
|
+
const auto = require('@roarkanalytics/sdk/_shims/auto/runtime');
|
6
|
+
if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
|
7
|
+
for (const property of Object.keys(shims)) {
|
8
|
+
Object.defineProperty(exports, property, {
|
9
|
+
get() {
|
10
|
+
return shims[property];
|
11
|
+
},
|
12
|
+
});
|
13
|
+
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/**
|
2
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
3
|
+
*/
|
4
|
+
import * as shims from './registry.mjs';
|
5
|
+
import * as auto from "./auto/runtime";
|
6
|
+
if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
|
7
|
+
export * from './registry.mjs';
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/**
|
2
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
3
|
+
*/
|
4
|
+
/**
|
5
|
+
* Types will get added to this namespace when you import one of the following:
|
6
|
+
*
|
7
|
+
* import '@roarkanalytics/sdk/shims/node'
|
8
|
+
* import '@roarkanalytics/sdk/shims/web'
|
9
|
+
*
|
10
|
+
* Importing more than one will cause type and runtime errors.
|
11
|
+
*/
|
12
|
+
export namespace manual {}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
/**
|
2
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
3
|
+
*/
|
4
|
+
import * as nf from 'node-fetch';
|
5
|
+
import * as fd from 'formdata-node';
|
6
|
+
import { type File, type FilePropertyBag } from 'formdata-node';
|
7
|
+
import KeepAliveAgent from 'agentkeepalive';
|
8
|
+
import { AbortController as AbortControllerPolyfill } from 'abort-controller';
|
9
|
+
import { ReadStream as FsReadStream } from 'node:fs';
|
10
|
+
import { type Agent } from 'node:http';
|
11
|
+
import { FormDataEncoder } from 'form-data-encoder';
|
12
|
+
import { Readable } from 'node:stream';
|
13
|
+
import { type RequestOptions } from '../core';
|
14
|
+
import { MultipartBody } from './MultipartBody';
|
15
|
+
import { type Shims } from './registry';
|
16
|
+
import { ReadableStream } from 'node:stream/web';
|
17
|
+
|
18
|
+
type FileFromPathOptions = Omit<FilePropertyBag, 'lastModified'>;
|
19
|
+
|
20
|
+
let fileFromPathWarned = false;
|
21
|
+
|
22
|
+
/**
|
23
|
+
* @deprecated use fs.createReadStream('./my/file.txt') instead
|
24
|
+
*/
|
25
|
+
async function fileFromPath(path: string): Promise<File>;
|
26
|
+
async function fileFromPath(path: string, filename?: string): Promise<File>;
|
27
|
+
async function fileFromPath(path: string, options?: FileFromPathOptions): Promise<File>;
|
28
|
+
async function fileFromPath(path: string, filename?: string, options?: FileFromPathOptions): Promise<File>;
|
29
|
+
async function fileFromPath(path: string, ...args: any[]): Promise<File> {
|
30
|
+
// this import fails in environments that don't handle export maps correctly, like old versions of Jest
|
31
|
+
const { fileFromPath: _fileFromPath } = await import('formdata-node/file-from-path');
|
32
|
+
|
33
|
+
if (!fileFromPathWarned) {
|
34
|
+
console.warn(`fileFromPath is deprecated; use fs.createReadStream(${JSON.stringify(path)}) instead`);
|
35
|
+
fileFromPathWarned = true;
|
36
|
+
}
|
37
|
+
// @ts-ignore
|
38
|
+
return await _fileFromPath(path, ...args);
|
39
|
+
}
|
40
|
+
|
41
|
+
const defaultHttpAgent: Agent = new KeepAliveAgent({ keepAlive: true, timeout: 5 * 60 * 1000 });
|
42
|
+
const defaultHttpsAgent: Agent = new KeepAliveAgent.HttpsAgent({ keepAlive: true, timeout: 5 * 60 * 1000 });
|
43
|
+
|
44
|
+
async function getMultipartRequestOptions<T = Record<string, unknown>>(
|
45
|
+
form: fd.FormData,
|
46
|
+
opts: RequestOptions<T>,
|
47
|
+
): Promise<RequestOptions<T>> {
|
48
|
+
const encoder = new FormDataEncoder(form);
|
49
|
+
const readable = Readable.from(encoder);
|
50
|
+
const body = new MultipartBody(readable);
|
51
|
+
const headers = {
|
52
|
+
...opts.headers,
|
53
|
+
...encoder.headers,
|
54
|
+
'Content-Length': encoder.contentLength,
|
55
|
+
};
|
56
|
+
|
57
|
+
return { ...opts, body: body as any, headers };
|
58
|
+
}
|
59
|
+
|
60
|
+
export function getRuntime(): Shims {
|
61
|
+
// Polyfill global object if needed.
|
62
|
+
if (typeof AbortController === 'undefined') {
|
63
|
+
// @ts-expect-error (the types are subtly different, but compatible in practice)
|
64
|
+
globalThis.AbortController = AbortControllerPolyfill;
|
65
|
+
}
|
66
|
+
return {
|
67
|
+
kind: 'node',
|
68
|
+
fetch: nf.default,
|
69
|
+
Request: nf.Request,
|
70
|
+
Response: nf.Response,
|
71
|
+
Headers: nf.Headers,
|
72
|
+
FormData: fd.FormData,
|
73
|
+
Blob: fd.Blob,
|
74
|
+
File: fd.File,
|
75
|
+
ReadableStream,
|
76
|
+
getMultipartRequestOptions,
|
77
|
+
getDefaultAgent: (url: string): Agent => (url.startsWith('https') ? defaultHttpsAgent : defaultHttpAgent),
|
78
|
+
fileFromPath,
|
79
|
+
isFsReadStream: (value: any): value is FsReadStream => value instanceof FsReadStream,
|
80
|
+
};
|
81
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
/**
|
2
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
3
|
+
*/
|
4
|
+
import * as nf from 'node-fetch';
|
5
|
+
import * as fd from 'formdata-node';
|
6
|
+
|
7
|
+
export { type Agent } from 'node:http';
|
8
|
+
export { type Readable } from 'node:stream';
|
9
|
+
export { type ReadStream as FsReadStream } from 'node:fs';
|
10
|
+
export { ReadableStream } from 'node:stream/web';
|
11
|
+
|
12
|
+
export const fetch: typeof nf.default;
|
13
|
+
|
14
|
+
export type Request = nf.Request;
|
15
|
+
export type RequestInfo = nf.RequestInfo;
|
16
|
+
export type RequestInit = nf.RequestInit;
|
17
|
+
|
18
|
+
export type Response = nf.Response;
|
19
|
+
export type ResponseInit = nf.ResponseInit;
|
20
|
+
export type ResponseType = nf.ResponseType;
|
21
|
+
export type BodyInit = nf.BodyInit;
|
22
|
+
export type Headers = nf.Headers;
|
23
|
+
export type HeadersInit = nf.HeadersInit;
|
24
|
+
|
25
|
+
type EndingType = 'native' | 'transparent';
|
26
|
+
export interface BlobPropertyBag {
|
27
|
+
endings?: EndingType;
|
28
|
+
type?: string;
|
29
|
+
}
|
30
|
+
|
31
|
+
export interface FilePropertyBag extends BlobPropertyBag {
|
32
|
+
lastModified?: number;
|
33
|
+
}
|
34
|
+
|
35
|
+
export type FileFromPathOptions = Omit<FilePropertyBag, 'lastModified'>;
|
36
|
+
|
37
|
+
export type FormData = fd.FormData;
|
38
|
+
export const FormData: typeof fd.FormData;
|
39
|
+
export type File = fd.File;
|
40
|
+
export const File: typeof fd.File;
|
41
|
+
export type Blob = fd.Blob;
|
42
|
+
export const Blob: typeof fd.Blob;
|
@@ -0,0 +1,67 @@
|
|
1
|
+
/**
|
2
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
3
|
+
*/
|
4
|
+
import { type RequestOptions } from '../core';
|
5
|
+
|
6
|
+
export interface Shims {
|
7
|
+
kind: string;
|
8
|
+
fetch: any;
|
9
|
+
Request: any;
|
10
|
+
Response: any;
|
11
|
+
Headers: any;
|
12
|
+
FormData: any;
|
13
|
+
Blob: any;
|
14
|
+
File: any;
|
15
|
+
ReadableStream: any;
|
16
|
+
getMultipartRequestOptions: <T = Record<string, unknown>>(
|
17
|
+
form: Shims['FormData'],
|
18
|
+
opts: RequestOptions<T>,
|
19
|
+
) => Promise<RequestOptions<T>>;
|
20
|
+
getDefaultAgent: (url: string) => any;
|
21
|
+
fileFromPath:
|
22
|
+
| ((path: string, filename?: string, options?: {}) => Promise<Shims['File']>)
|
23
|
+
| ((path: string, options?: {}) => Promise<Shims['File']>);
|
24
|
+
isFsReadStream: (value: any) => boolean;
|
25
|
+
}
|
26
|
+
|
27
|
+
export let auto = false;
|
28
|
+
export let kind: Shims['kind'] | undefined = undefined;
|
29
|
+
export let fetch: Shims['fetch'] | undefined = undefined;
|
30
|
+
export let Request: Shims['Request'] | undefined = undefined;
|
31
|
+
export let Response: Shims['Response'] | undefined = undefined;
|
32
|
+
export let Headers: Shims['Headers'] | undefined = undefined;
|
33
|
+
export let FormData: Shims['FormData'] | undefined = undefined;
|
34
|
+
export let Blob: Shims['Blob'] | undefined = undefined;
|
35
|
+
export let File: Shims['File'] | undefined = undefined;
|
36
|
+
export let ReadableStream: Shims['ReadableStream'] | undefined = undefined;
|
37
|
+
export let getMultipartRequestOptions: Shims['getMultipartRequestOptions'] | undefined = undefined;
|
38
|
+
export let getDefaultAgent: Shims['getDefaultAgent'] | undefined = undefined;
|
39
|
+
export let fileFromPath: Shims['fileFromPath'] | undefined = undefined;
|
40
|
+
export let isFsReadStream: Shims['isFsReadStream'] | undefined = undefined;
|
41
|
+
|
42
|
+
export function setShims(shims: Shims, options: { auto: boolean } = { auto: false }) {
|
43
|
+
if (auto) {
|
44
|
+
throw new Error(
|
45
|
+
`you must \`import '@roarkanalytics/sdk/shims/${shims.kind}'\` before importing anything else from @roarkanalytics/sdk`,
|
46
|
+
);
|
47
|
+
}
|
48
|
+
if (kind) {
|
49
|
+
throw new Error(
|
50
|
+
`can't \`import '@roarkanalytics/sdk/shims/${shims.kind}'\` after \`import '@roarkanalytics/sdk/shims/${kind}'\``,
|
51
|
+
);
|
52
|
+
}
|
53
|
+
auto = options.auto;
|
54
|
+
kind = shims.kind;
|
55
|
+
fetch = shims.fetch;
|
56
|
+
Request = shims.Request;
|
57
|
+
Response = shims.Response;
|
58
|
+
Headers = shims.Headers;
|
59
|
+
FormData = shims.FormData;
|
60
|
+
Blob = shims.Blob;
|
61
|
+
File = shims.File;
|
62
|
+
ReadableStream = shims.ReadableStream;
|
63
|
+
getMultipartRequestOptions = shims.getMultipartRequestOptions;
|
64
|
+
getDefaultAgent = shims.getDefaultAgent;
|
65
|
+
fileFromPath = shims.fileFromPath;
|
66
|
+
isFsReadStream = shims.isFsReadStream;
|
67
|
+
}
|
@@ -0,0 +1,103 @@
|
|
1
|
+
/**
|
2
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
3
|
+
*/
|
4
|
+
import { MultipartBody } from './MultipartBody';
|
5
|
+
import { type RequestOptions } from '../core';
|
6
|
+
import { type Shims } from './registry';
|
7
|
+
|
8
|
+
export function getRuntime({ manuallyImported }: { manuallyImported?: boolean } = {}): Shims {
|
9
|
+
const recommendation =
|
10
|
+
manuallyImported ?
|
11
|
+
`You may need to use polyfills`
|
12
|
+
: `Add one of these imports before your first \`import … from '@roarkanalytics/sdk'\`:
|
13
|
+
- \`import '@roarkanalytics/sdk/shims/node'\` (if you're running on Node)
|
14
|
+
- \`import '@roarkanalytics/sdk/shims/web'\` (otherwise)
|
15
|
+
`;
|
16
|
+
|
17
|
+
let _fetch, _Request, _Response, _Headers;
|
18
|
+
try {
|
19
|
+
// @ts-ignore
|
20
|
+
_fetch = fetch;
|
21
|
+
// @ts-ignore
|
22
|
+
_Request = Request;
|
23
|
+
// @ts-ignore
|
24
|
+
_Response = Response;
|
25
|
+
// @ts-ignore
|
26
|
+
_Headers = Headers;
|
27
|
+
} catch (error) {
|
28
|
+
throw new Error(
|
29
|
+
`this environment is missing the following Web Fetch API type: ${
|
30
|
+
(error as any).message
|
31
|
+
}. ${recommendation}`,
|
32
|
+
);
|
33
|
+
}
|
34
|
+
|
35
|
+
return {
|
36
|
+
kind: 'web',
|
37
|
+
fetch: _fetch,
|
38
|
+
Request: _Request,
|
39
|
+
Response: _Response,
|
40
|
+
Headers: _Headers,
|
41
|
+
FormData:
|
42
|
+
// @ts-ignore
|
43
|
+
typeof FormData !== 'undefined' ? FormData : (
|
44
|
+
class FormData {
|
45
|
+
// @ts-ignore
|
46
|
+
constructor() {
|
47
|
+
throw new Error(
|
48
|
+
`file uploads aren't supported in this environment yet as 'FormData' is undefined. ${recommendation}`,
|
49
|
+
);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
),
|
53
|
+
Blob:
|
54
|
+
typeof Blob !== 'undefined' ? Blob : (
|
55
|
+
class Blob {
|
56
|
+
constructor() {
|
57
|
+
throw new Error(
|
58
|
+
`file uploads aren't supported in this environment yet as 'Blob' is undefined. ${recommendation}`,
|
59
|
+
);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
),
|
63
|
+
File:
|
64
|
+
// @ts-ignore
|
65
|
+
typeof File !== 'undefined' ? File : (
|
66
|
+
class File {
|
67
|
+
// @ts-ignore
|
68
|
+
constructor() {
|
69
|
+
throw new Error(
|
70
|
+
`file uploads aren't supported in this environment yet as 'File' is undefined. ${recommendation}`,
|
71
|
+
);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
),
|
75
|
+
ReadableStream:
|
76
|
+
// @ts-ignore
|
77
|
+
typeof ReadableStream !== 'undefined' ? ReadableStream : (
|
78
|
+
class ReadableStream {
|
79
|
+
// @ts-ignore
|
80
|
+
constructor() {
|
81
|
+
throw new Error(
|
82
|
+
`streaming isn't supported in this environment yet as 'ReadableStream' is undefined. ${recommendation}`,
|
83
|
+
);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
),
|
87
|
+
getMultipartRequestOptions: async <T = Record<string, unknown>>(
|
88
|
+
// @ts-ignore
|
89
|
+
form: FormData,
|
90
|
+
opts: RequestOptions<T>,
|
91
|
+
): Promise<RequestOptions<T>> => ({
|
92
|
+
...opts,
|
93
|
+
body: new MultipartBody(form) as any,
|
94
|
+
}),
|
95
|
+
getDefaultAgent: (url: string) => undefined,
|
96
|
+
fileFromPath: () => {
|
97
|
+
throw new Error(
|
98
|
+
'The `fileFromPath` function is only supported in Node. See the README for more details: https://www.github.com/roarkhq/sdk-roark-analytics-node#file-uploads',
|
99
|
+
);
|
100
|
+
},
|
101
|
+
isFsReadStream: (value: any) => false,
|
102
|
+
};
|
103
|
+
}
|
@@ -0,0 +1,83 @@
|
|
1
|
+
/**
|
2
|
+
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
3
|
+
*/
|
4
|
+
export type Agent = any;
|
5
|
+
|
6
|
+
declare const _fetch: typeof fetch;
|
7
|
+
export { _fetch as fetch };
|
8
|
+
|
9
|
+
type _Request = Request;
|
10
|
+
export { _Request as Request };
|
11
|
+
|
12
|
+
type _RequestInfo = RequestInfo;
|
13
|
+
export { type _RequestInfo as RequestInfo };
|
14
|
+
|
15
|
+
type _RequestInit = RequestInit;
|
16
|
+
export { type _RequestInit as RequestInit };
|
17
|
+
|
18
|
+
type _Response = Response;
|
19
|
+
export { _Response as Response };
|
20
|
+
|
21
|
+
type _ResponseInit = ResponseInit;
|
22
|
+
export { type _ResponseInit as ResponseInit };
|
23
|
+
|
24
|
+
type _ResponseType = ResponseType;
|
25
|
+
export { type _ResponseType as ResponseType };
|
26
|
+
|
27
|
+
type _BodyInit = BodyInit;
|
28
|
+
export { type _BodyInit as BodyInit };
|
29
|
+
|
30
|
+
type _Headers = Headers;
|
31
|
+
export { _Headers as Headers };
|
32
|
+
|
33
|
+
type _HeadersInit = HeadersInit;
|
34
|
+
export { type _HeadersInit as HeadersInit };
|
35
|
+
|
36
|
+
type EndingType = 'native' | 'transparent';
|
37
|
+
|
38
|
+
export interface BlobPropertyBag {
|
39
|
+
endings?: EndingType;
|
40
|
+
type?: string;
|
41
|
+
}
|
42
|
+
|
43
|
+
export interface FilePropertyBag extends BlobPropertyBag {
|
44
|
+
lastModified?: number;
|
45
|
+
}
|
46
|
+
|
47
|
+
export type FileFromPathOptions = Omit<FilePropertyBag, 'lastModified'>;
|
48
|
+
|
49
|
+
type _FormData = FormData;
|
50
|
+
declare const _FormData: typeof FormData;
|
51
|
+
export { _FormData as FormData };
|
52
|
+
|
53
|
+
type _File = File;
|
54
|
+
declare const _File: typeof File;
|
55
|
+
export { _File as File };
|
56
|
+
|
57
|
+
type _Blob = Blob;
|
58
|
+
declare const _Blob: typeof Blob;
|
59
|
+
export { _Blob as Blob };
|
60
|
+
|
61
|
+
export declare class Readable {
|
62
|
+
readable: boolean;
|
63
|
+
readonly readableEnded: boolean;
|
64
|
+
readonly readableFlowing: boolean | null;
|
65
|
+
readonly readableHighWaterMark: number;
|
66
|
+
readonly readableLength: number;
|
67
|
+
readonly readableObjectMode: boolean;
|
68
|
+
destroyed: boolean;
|
69
|
+
read(size?: number): any;
|
70
|
+
pause(): this;
|
71
|
+
resume(): this;
|
72
|
+
isPaused(): boolean;
|
73
|
+
destroy(error?: Error): this;
|
74
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<any>;
|
75
|
+
}
|
76
|
+
|
77
|
+
export declare class FsReadStream extends Readable {
|
78
|
+
path: {}; // node type is string | Buffer
|
79
|
+
}
|
80
|
+
|
81
|
+
type _ReadableStream<R = any> = ReadableStream<R>;
|
82
|
+
declare const _ReadableStream: typeof ReadableStream;
|
83
|
+
export { _ReadableStream as ReadableStream };
|