@openfn/language-common 2.0.0-rc2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/ast.json +1602 -0
- package/dist/index.cjs +690 -4941
- package/dist/index.js +611 -4921
- package/dist/metadata.cjs +59 -0
- package/dist/metadata.js +35 -0
- package/dist/util.cjs +322 -0
- package/dist/util.js +276 -0
- package/package.json +51 -57
- package/types/Adaptor.d.ts +429 -0
- package/types/beta.d.ts +21 -0
- package/types/dateFns.d.ts +1 -0
- package/types/http.d.ts +129 -0
- package/types/index.d.ts +8 -0
- package/types/metadata.d.ts +11 -0
- package/types/util/http.d.ts +76 -0
- package/types/util/index.d.ts +4 -0
- package/types/util/parse-date.d.ts +2 -0
- package/types/util/references.d.ts +2 -0
- package/dist/language-common.d.ts +0 -685
package/types/http.d.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builder function to create request options. Returns an object with helpers to
|
|
3
|
+
* easily add commonly used options. The return object is chainable so you can set
|
|
4
|
+
* as many options as you want.
|
|
5
|
+
* Pass an object to set your own options.
|
|
6
|
+
* @param {CommonRequestOptions} options - options to pass to the request
|
|
7
|
+
* @returns {OptionsHelpers}
|
|
8
|
+
* @function
|
|
9
|
+
* @public
|
|
10
|
+
* @example <caption>Get with a query an oath token</caption>
|
|
11
|
+
* get($.data.url, http.options({ query: $.query }).oath($.configuration.access_token)
|
|
12
|
+
*/
|
|
13
|
+
export function options(opts?: {}): any;
|
|
14
|
+
/**
|
|
15
|
+
* Make a GET request.
|
|
16
|
+
* @public
|
|
17
|
+
* @function
|
|
18
|
+
* @example <caption>Request a resource</caption>
|
|
19
|
+
* http.get('https://jsonplaceholder.typicode.com/todos')
|
|
20
|
+
* @example <caption>Request a resource with basic auth</caption>
|
|
21
|
+
* http.get(
|
|
22
|
+
* 'https://jsonplaceholder.typicode.com/todos',
|
|
23
|
+
* http.options().basic('user', 'pass')
|
|
24
|
+
* )
|
|
25
|
+
* @example <caption>Request a resource with oauth</caption>
|
|
26
|
+
* http.get(
|
|
27
|
+
* 'https://jsonplaceholder.typicode.com/todos',
|
|
28
|
+
* http.options().oauth($.configuration.access_token)
|
|
29
|
+
* )
|
|
30
|
+
* @param {string} url - URL to access
|
|
31
|
+
* @param {CommonRequestOptions} options - Request options
|
|
32
|
+
* @state {CommonHttpState}
|
|
33
|
+
* @returns {Operation}
|
|
34
|
+
*/
|
|
35
|
+
export function get(url: string, options: CommonRequestOptions): Operation;
|
|
36
|
+
/**
|
|
37
|
+
* Make a POST request.
|
|
38
|
+
* @public
|
|
39
|
+
* @function
|
|
40
|
+
* @example <caption>Post a JSON object (setting the content-type header)</caption>
|
|
41
|
+
* http.post(
|
|
42
|
+
* 'https://jsonplaceholder.typicode.com/todos',
|
|
43
|
+
* $.data,
|
|
44
|
+
* options().json(),
|
|
45
|
+
* })
|
|
46
|
+
* @param {string} url - URL to access
|
|
47
|
+
* @param {CommonRequestOptions} options - Request options
|
|
48
|
+
* @state {CommonHttpState}
|
|
49
|
+
* @returns {Operation}
|
|
50
|
+
*/
|
|
51
|
+
export function post(path: any, data: any, options: CommonRequestOptions): Operation;
|
|
52
|
+
export { req as request };
|
|
53
|
+
/**
|
|
54
|
+
* Helper functions provided by `http.options`.
|
|
55
|
+
*/
|
|
56
|
+
export type OptionsHelpers = any;
|
|
57
|
+
/**
|
|
58
|
+
* Options provided to the HTTP request
|
|
59
|
+
*/
|
|
60
|
+
export type CommonRequestOptions = {
|
|
61
|
+
/**
|
|
62
|
+
* - Map of errorCodes -> error messages, ie, `{ 404: 'Resource not found;' }`. Pass `false` to suppress errors.
|
|
63
|
+
*/
|
|
64
|
+
errors: object;
|
|
65
|
+
/**
|
|
66
|
+
* - Pass a JSON object to be serialised into a multipart HTML form (as FormData) in the body.
|
|
67
|
+
*/
|
|
68
|
+
form: object;
|
|
69
|
+
/**
|
|
70
|
+
* - An object of query parameters to be encoded into the URL.
|
|
71
|
+
*/
|
|
72
|
+
query: object;
|
|
73
|
+
/**
|
|
74
|
+
* - An object of headers to append to the request.
|
|
75
|
+
*/
|
|
76
|
+
headers: object;
|
|
77
|
+
/**
|
|
78
|
+
* - Parse the response body as json, text or stream. By default will use the response headers.
|
|
79
|
+
*/
|
|
80
|
+
parseAs: string;
|
|
81
|
+
/**
|
|
82
|
+
* - Request timeout in ms. Default: 300 seconds.
|
|
83
|
+
*/
|
|
84
|
+
timeout: number;
|
|
85
|
+
/**
|
|
86
|
+
* - TLS/SSL authentication options. See https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions
|
|
87
|
+
*/
|
|
88
|
+
tls: object;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* State object
|
|
92
|
+
*/
|
|
93
|
+
export type CommonHttpState = any;
|
|
94
|
+
/**
|
|
95
|
+
* Options provided to the HTTP request
|
|
96
|
+
* @typedef {Object} CommonRequestOptions
|
|
97
|
+
* @property {object} errors - Map of errorCodes -> error messages, ie, `{ 404: 'Resource not found;' }`. Pass `false` to suppress errors.
|
|
98
|
+
* @property {object} form - Pass a JSON object to be serialised into a multipart HTML form (as FormData) in the body.
|
|
99
|
+
* @property {object} query - An object of query parameters to be encoded into the URL.
|
|
100
|
+
* @property {object} headers - An object of headers to append to the request.
|
|
101
|
+
* @property {string} parseAs - Parse the response body as json, text or stream. By default will use the response headers.
|
|
102
|
+
* @property {number} timeout - Request timeout in ms. Default: 300 seconds.
|
|
103
|
+
* @property {object} tls - TLS/SSL authentication options. See https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions
|
|
104
|
+
*/
|
|
105
|
+
/**
|
|
106
|
+
* State object
|
|
107
|
+
* @typedef {Object} CommonHttpState
|
|
108
|
+
* @private
|
|
109
|
+
* @property data - the parsed response body
|
|
110
|
+
* @property response - the response from the HTTP server, including headers, statusCode, body, etc
|
|
111
|
+
* @property references - an array of all previous data objects used in the Job
|
|
112
|
+
**/
|
|
113
|
+
/**
|
|
114
|
+
* Make a HTTP request.
|
|
115
|
+
* @public
|
|
116
|
+
* @function
|
|
117
|
+
* @example
|
|
118
|
+
* http.request(
|
|
119
|
+
* 'GET',
|
|
120
|
+
* 'https://jsonplaceholder.typicode.com/todos'
|
|
121
|
+
* )
|
|
122
|
+
* @name request
|
|
123
|
+
* @param {string} method - The HTTP method to use.
|
|
124
|
+
* @param {string} url - URL to resource.
|
|
125
|
+
* @param {CommonRequestOptions} options - Request options
|
|
126
|
+
* @state {CommonHttpState}
|
|
127
|
+
* @returns {Operation}
|
|
128
|
+
*/
|
|
129
|
+
declare function req(method: string, url: string, options: CommonRequestOptions): Operation;
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare type Entity = {
|
|
2
|
+
name: string;
|
|
3
|
+
type: string;
|
|
4
|
+
label?: string;
|
|
5
|
+
datatype?: string;
|
|
6
|
+
desc?: string;
|
|
7
|
+
children?: Entity[] | Record<string, Entity>;
|
|
8
|
+
meta?: Record<string, any>;
|
|
9
|
+
addChild: (e: Entity, name?: string) => void;
|
|
10
|
+
};
|
|
11
|
+
declare type DataType = 'string' | 'boolean' | 'date';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `request` is a helper function that sends HTTP requests and returns the response
|
|
3
|
+
* body, headers, and status code.
|
|
4
|
+
* Use the error map to provide custom error messages or get hold of the response in case of errors.
|
|
5
|
+
* @param method - The HTTP method to use for the request (e.g., "GET", "POST", "PUT", "DELETE", etc.).
|
|
6
|
+
* @param fullUrlOrPath - The full or partial URL for the request.
|
|
7
|
+
* @param [options] - The `options` parameter is an object that contains additional configuration
|
|
8
|
+
* options for the request.
|
|
9
|
+
* @returns an object with the following properties:
|
|
10
|
+
* - method: the request method
|
|
11
|
+
* - url: the request url
|
|
12
|
+
* - code: the status code of the response
|
|
13
|
+
* - headers: the headers of the response
|
|
14
|
+
* - body: the body of the response
|
|
15
|
+
* - message: the status text of the response
|
|
16
|
+
* - duration: the response time
|
|
17
|
+
*/
|
|
18
|
+
export function request(method: any, fullUrlOrPath: any, options?: {}): Promise<{
|
|
19
|
+
url: string;
|
|
20
|
+
method: any;
|
|
21
|
+
statusCode: any;
|
|
22
|
+
statusMessage: string;
|
|
23
|
+
headers: any;
|
|
24
|
+
body: any;
|
|
25
|
+
duration: number;
|
|
26
|
+
}>;
|
|
27
|
+
export function makeBasicAuthHeader(username: any, password: any): {
|
|
28
|
+
Authorization: string;
|
|
29
|
+
};
|
|
30
|
+
export function logResponse(response: any): any;
|
|
31
|
+
export function enableMockClient(baseUrl: any): import("undici/types/mock-interceptor").Interceptable;
|
|
32
|
+
export const ERROR_ABSOLUTE_URL: "Absolute URLs not suppored";
|
|
33
|
+
export function assertRelativeUrl(path: any): void;
|
|
34
|
+
export const ERROR_URL_MISMATCH: "Target origin does not match baseUrl origin";
|
|
35
|
+
export function parseUrl(pathOrUrl: string, baseUrl: any): {
|
|
36
|
+
url: string;
|
|
37
|
+
baseUrl: string;
|
|
38
|
+
path: string;
|
|
39
|
+
query: any;
|
|
40
|
+
};
|
|
41
|
+
export function get(url: any, options: any): Promise<{
|
|
42
|
+
url: string;
|
|
43
|
+
method: any;
|
|
44
|
+
statusCode: any;
|
|
45
|
+
statusMessage: string;
|
|
46
|
+
headers: any;
|
|
47
|
+
body: any;
|
|
48
|
+
duration: number;
|
|
49
|
+
}>;
|
|
50
|
+
export function post(url: any, body: any, options: any): Promise<{
|
|
51
|
+
url: string;
|
|
52
|
+
method: any;
|
|
53
|
+
statusCode: any;
|
|
54
|
+
statusMessage: string;
|
|
55
|
+
headers: any;
|
|
56
|
+
body: any;
|
|
57
|
+
duration: number;
|
|
58
|
+
}>;
|
|
59
|
+
export function put(url: any, body: any, options: any): Promise<{
|
|
60
|
+
url: string;
|
|
61
|
+
method: any;
|
|
62
|
+
statusCode: any;
|
|
63
|
+
statusMessage: string;
|
|
64
|
+
headers: any;
|
|
65
|
+
body: any;
|
|
66
|
+
duration: number;
|
|
67
|
+
}>;
|
|
68
|
+
export function del(url: any, body: any, options: any): Promise<{
|
|
69
|
+
url: string;
|
|
70
|
+
method: any;
|
|
71
|
+
statusCode: any;
|
|
72
|
+
statusMessage: string;
|
|
73
|
+
headers: any;
|
|
74
|
+
body: any;
|
|
75
|
+
duration: number;
|
|
76
|
+
}>;
|