@junobuild/functions 0.7.2-next-2026-03-22 → 0.7.2-next-2026-03-29
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 +166 -0
- package/global.d.ts +1 -0
- package/ic-cdk/http-request.ic-cdk.d.ts +10 -0
- package/ic-cdk/schemas/http-request.d.ts +142 -0
- package/ic-cdk.d.ts +2 -0
- package/ic-cdk.js +1 -1
- package/ic-cdk.js.map +4 -4
- package/package.json +1 -1
- package/src/global.d.ts +1 -0
package/README.md
CHANGED
|
@@ -76,6 +76,7 @@ JavaScript and TypeScript utilities for [Juno] Serverless Functions.
|
|
|
76
76
|
- [call](#gear-call)
|
|
77
77
|
- [msgCaller](#gear-msgcaller)
|
|
78
78
|
- [caller](#gear-caller)
|
|
79
|
+
- [httpRequest](#gear-httprequest)
|
|
79
80
|
- [canisterSelf](#gear-canisterself)
|
|
80
81
|
- [id](#gear-id)
|
|
81
82
|
- [satelliteSelf](#gear-satelliteself)
|
|
@@ -900,6 +901,24 @@ The Principal ID of the caller.
|
|
|
900
901
|
|
|
901
902
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/caller.ic-cdk.ts#L21)
|
|
902
903
|
|
|
904
|
+
#### :gear: httpRequest
|
|
905
|
+
|
|
906
|
+
Performs an HTTP request from a Juno serverless function.
|
|
907
|
+
|
|
908
|
+
| Function | Type |
|
|
909
|
+
| ------------- | ------------------------------------------------------- |
|
|
910
|
+
| `httpRequest` | `(args: HttpRequestArgs) => Promise<HttpRequestResult>` |
|
|
911
|
+
|
|
912
|
+
Parameters:
|
|
913
|
+
|
|
914
|
+
- `args`: - The HTTP request parameters
|
|
915
|
+
|
|
916
|
+
Returns:
|
|
917
|
+
|
|
918
|
+
A promise resolving to the HTTP response.
|
|
919
|
+
|
|
920
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/http-request.ic-cdk.ts#L16)
|
|
921
|
+
|
|
903
922
|
#### :gear: canisterSelf
|
|
904
923
|
|
|
905
924
|
Retrieves the Satellite's Principal ID.
|
|
@@ -1066,6 +1085,10 @@ The current timestamp.
|
|
|
1066
1085
|
- [CallArgsSchema](#gear-callargsschema)
|
|
1067
1086
|
- [CallResultSchema](#gear-callresultschema)
|
|
1068
1087
|
- [CallParamsSchema](#gear-callparamsschema)
|
|
1088
|
+
- [HttpHeaderSchema](#gear-httpheaderschema)
|
|
1089
|
+
- [HttpMethodSchema](#gear-httpmethodschema)
|
|
1090
|
+
- [HttpRequestArgsSchema](#gear-httprequestargsschema)
|
|
1091
|
+
- [HttpRequestResultSchema](#gear-httprequestresultschema)
|
|
1069
1092
|
|
|
1070
1093
|
#### :gear: SatelliteEnvSchema
|
|
1071
1094
|
|
|
@@ -2336,6 +2359,54 @@ References:
|
|
|
2336
2359
|
|
|
2337
2360
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/call.ts#L60)
|
|
2338
2361
|
|
|
2362
|
+
#### :gear: HttpHeaderSchema
|
|
2363
|
+
|
|
2364
|
+
| Constant | Type |
|
|
2365
|
+
| ------------------ | ----------------------------------------------------------- |
|
|
2366
|
+
| `HttpHeaderSchema` | `ZodObject<{ name: ZodString; value: ZodString; }, $strip>` |
|
|
2367
|
+
|
|
2368
|
+
References:
|
|
2369
|
+
|
|
2370
|
+
- HttpHeader
|
|
2371
|
+
|
|
2372
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/http-request.ts#L6)
|
|
2373
|
+
|
|
2374
|
+
#### :gear: HttpMethodSchema
|
|
2375
|
+
|
|
2376
|
+
| Constant | Type |
|
|
2377
|
+
| ------------------ | ------------------------------------------------------ |
|
|
2378
|
+
| `HttpMethodSchema` | `ZodEnum<{ GET: "GET"; POST: "POST"; HEAD: "HEAD"; }>` |
|
|
2379
|
+
|
|
2380
|
+
References:
|
|
2381
|
+
|
|
2382
|
+
- HttpMethod
|
|
2383
|
+
|
|
2384
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/http-request.ts#L14)
|
|
2385
|
+
|
|
2386
|
+
#### :gear: HttpRequestArgsSchema
|
|
2387
|
+
|
|
2388
|
+
| Constant | Type |
|
|
2389
|
+
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
2390
|
+
| `HttpRequestArgsSchema` | `ZodObject<{ url: ZodURL; method: ZodEnum<{ GET: "GET"; POST: "POST"; HEAD: "HEAD"; }>; headers: ZodArray<ZodObject<{ name: ZodString; value: ZodString; }, $strip>>; body: ZodOptional<...>; maxResponseBytes: ZodOptional<...>; transform: ZodOptional<...>; isReplicated: ZodOptional<...>; }, $strip>` |
|
|
2391
|
+
|
|
2392
|
+
References:
|
|
2393
|
+
|
|
2394
|
+
- HttpRequestArgs
|
|
2395
|
+
|
|
2396
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/http-request.ts#L19)
|
|
2397
|
+
|
|
2398
|
+
#### :gear: HttpRequestResultSchema
|
|
2399
|
+
|
|
2400
|
+
| Constant | Type |
|
|
2401
|
+
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
2402
|
+
| `HttpRequestResultSchema` | `ZodObject<{ status: ZodBigInt; headers: ZodArray<ZodObject<{ name: ZodString; value: ZodString; }, $strip>>; body: ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<...>>; }, $strip>` |
|
|
2403
|
+
|
|
2404
|
+
References:
|
|
2405
|
+
|
|
2406
|
+
- HttpRequestResult
|
|
2407
|
+
|
|
2408
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/http-request.ts#L32)
|
|
2409
|
+
|
|
2339
2410
|
### :factory: CallResponseLengthError
|
|
2340
2411
|
|
|
2341
2412
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/types/errors.ts#L1)
|
|
@@ -2372,6 +2443,12 @@ References:
|
|
|
2372
2443
|
- [SetAssetHandlerParams](#gear-setassethandlerparams)
|
|
2373
2444
|
- [GetContentChunksStoreParams](#gear-getcontentchunksstoreparams)
|
|
2374
2445
|
- [CallParams](#gear-callparams)
|
|
2446
|
+
- [HttpHeader](#gear-httpheader)
|
|
2447
|
+
- [HttpRequestArgs](#gear-httprequestargs)
|
|
2448
|
+
- [HttpRequestResult](#gear-httprequestresult)
|
|
2449
|
+
- [HttpHeader](#gear-httpheader)
|
|
2450
|
+
- [HttpRequestArgs](#gear-httprequestargs)
|
|
2451
|
+
- [HttpRequestResult](#gear-httprequestresult)
|
|
2375
2452
|
|
|
2376
2453
|
#### :gear: CustomFunctionWithArgsAndResult
|
|
2377
2454
|
|
|
@@ -2745,6 +2822,84 @@ Type representing the parameters required to make a canister call.
|
|
|
2745
2822
|
|
|
2746
2823
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/call.ts#L70)
|
|
2747
2824
|
|
|
2825
|
+
#### :gear: HttpHeader
|
|
2826
|
+
|
|
2827
|
+
An HTTP header consisting of a name and value.
|
|
2828
|
+
|
|
2829
|
+
| Property | Type | Description |
|
|
2830
|
+
| -------- | -------- | ----------------- |
|
|
2831
|
+
| `name` | `string` | The header name. |
|
|
2832
|
+
| `value` | `string` | The header value. |
|
|
2833
|
+
|
|
2834
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/http-request.ts#L41)
|
|
2835
|
+
|
|
2836
|
+
#### :gear: HttpRequestArgs
|
|
2837
|
+
|
|
2838
|
+
The arguments for an HTTP request.
|
|
2839
|
+
|
|
2840
|
+
| Property | Type | Description |
|
|
2841
|
+
| ------------------ | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
2842
|
+
| `url` | `string` | The requested URL. |
|
|
2843
|
+
| `method` | `HttpMethod` | The HTTP method. |
|
|
2844
|
+
| `headers` | `HttpHeader[]` | List of HTTP request headers and their corresponding values. |
|
|
2845
|
+
| `body` | `Uint8Array<ArrayBufferLike> or undefined` | Optionally provide request body. |
|
|
2846
|
+
| `maxResponseBytes` | `bigint or undefined` | The maximal size of the response in bytes. |
|
|
2847
|
+
| `transform` | `string or undefined` | The name of a query function used to transform the response before consensus - for example, to trim headers. If provided, a corresponding query must be declared using {@link defineQuery }. |
|
|
2848
|
+
| `isReplicated` | `boolean or undefined` | Whether all nodes should perform the request and agree on the response, or just one node. Using a single node is cheaper but the response is not verified by others - suitable when you trust the data source or consistency is not critical. Defaults to all nodes if not specified. |
|
|
2849
|
+
|
|
2850
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/http-request.ts#L54)
|
|
2851
|
+
|
|
2852
|
+
#### :gear: HttpRequestResult
|
|
2853
|
+
|
|
2854
|
+
The result of an HTTP request.
|
|
2855
|
+
|
|
2856
|
+
| Property | Type | Description |
|
|
2857
|
+
| --------- | ----------------------------- | ------------------------------------------------------------- |
|
|
2858
|
+
| `status` | `bigint` | The response status (e.g. 200, 404). |
|
|
2859
|
+
| `headers` | `HttpHeader[]` | List of HTTP response headers and their corresponding values. |
|
|
2860
|
+
| `body` | `Uint8Array<ArrayBufferLike>` | The response's body. |
|
|
2861
|
+
|
|
2862
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/http-request.ts#L67)
|
|
2863
|
+
|
|
2864
|
+
#### :gear: HttpHeader
|
|
2865
|
+
|
|
2866
|
+
An HTTP header consisting of a name and value.
|
|
2867
|
+
|
|
2868
|
+
| Property | Type | Description |
|
|
2869
|
+
| -------- | -------- | ----------------- |
|
|
2870
|
+
| `name` | `string` | The header name. |
|
|
2871
|
+
| `value` | `string` | The header value. |
|
|
2872
|
+
|
|
2873
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/http-request.ts#L76)
|
|
2874
|
+
|
|
2875
|
+
#### :gear: HttpRequestArgs
|
|
2876
|
+
|
|
2877
|
+
The arguments for an HTTP request.
|
|
2878
|
+
|
|
2879
|
+
| Property | Type | Description |
|
|
2880
|
+
| ------------------ | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
2881
|
+
| `url` | `string` | The requested URL. |
|
|
2882
|
+
| `method` | `HttpMethod` | The HTTP method. |
|
|
2883
|
+
| `headers` | `HttpHeader[]` | List of HTTP request headers and their corresponding values. |
|
|
2884
|
+
| `body` | `Uint8Array<ArrayBufferLike> or undefined` | Optionally provide request body. |
|
|
2885
|
+
| `maxResponseBytes` | `bigint or undefined` | The maximal size of the response in bytes. |
|
|
2886
|
+
| `transform` | `string or undefined` | The name of a query function used to transform the response before consensus - for example, to trim headers. If provided, a corresponding query must be declared using {@link defineQuery }. |
|
|
2887
|
+
| `isReplicated` | `boolean or undefined` | Whether all nodes should perform the request and agree on the response, or just one node. Using a single node is cheaper but the response is not verified by others - suitable when you trust the data source or consistency is not critical. Defaults to all nodes if not specified. |
|
|
2888
|
+
|
|
2889
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/http-request.ts#L91)
|
|
2890
|
+
|
|
2891
|
+
#### :gear: HttpRequestResult
|
|
2892
|
+
|
|
2893
|
+
The result of an HTTP request.
|
|
2894
|
+
|
|
2895
|
+
| Property | Type | Description |
|
|
2896
|
+
| --------- | ----------------------------- | ------------------------------------------------------------- |
|
|
2897
|
+
| `status` | `bigint` | The response status (e.g. 200, 404). |
|
|
2898
|
+
| `headers` | `HttpHeader[]` | List of HTTP response headers and their corresponding values. |
|
|
2899
|
+
| `body` | `Uint8Array<ArrayBufferLike>` | The response's body. |
|
|
2900
|
+
|
|
2901
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/http-request.ts#L134)
|
|
2902
|
+
|
|
2748
2903
|
### :cocktail: Types
|
|
2749
2904
|
|
|
2750
2905
|
- [SatelliteEnv](#gear-satelliteenv)
|
|
@@ -2847,6 +3002,7 @@ Type representing the parameters required to make a canister call.
|
|
|
2847
3002
|
- [CallArg](#gear-callarg)
|
|
2848
3003
|
- [CallArgs](#gear-callargs)
|
|
2849
3004
|
- [CallResult](#gear-callresult)
|
|
3005
|
+
- [HttpMethod](#gear-httpmethod)
|
|
2850
3006
|
|
|
2851
3007
|
#### :gear: SatelliteEnv
|
|
2852
3008
|
|
|
@@ -3919,6 +4075,16 @@ Defines the type used to decode the result of a canister call.
|
|
|
3919
4075
|
|
|
3920
4076
|
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/call.ts#L55)
|
|
3921
4077
|
|
|
4078
|
+
#### :gear: HttpMethod
|
|
4079
|
+
|
|
4080
|
+
The HTTP method for the request.
|
|
4081
|
+
|
|
4082
|
+
| Type | Type |
|
|
4083
|
+
| ------------ | --------------------------- |
|
|
4084
|
+
| `HttpMethod` | `'GET' or 'POST' or 'HEAD'` |
|
|
4085
|
+
|
|
4086
|
+
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions/src/ic-cdk/schemas/http-request.ts#L49)
|
|
4087
|
+
|
|
3922
4088
|
<!-- TSDOC_END -->
|
|
3923
4089
|
|
|
3924
4090
|
## License
|
package/global.d.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type HttpRequestArgs, type HttpRequestResult } from './schemas/http-request';
|
|
2
|
+
/**
|
|
3
|
+
* Performs an HTTP request from a Juno serverless function.
|
|
4
|
+
*
|
|
5
|
+
* @param {HttpRequestArgs} args - The HTTP request parameters
|
|
6
|
+
* @returns {Promise<HttpRequestResult>} A promise resolving to the HTTP response.
|
|
7
|
+
* @throws {ZodError} If the provided arguments do not match the expected schema.
|
|
8
|
+
* @throws {Error} If the HTTP request fails.
|
|
9
|
+
*/
|
|
10
|
+
export declare const httpRequest: (args: HttpRequestArgs) => Promise<HttpRequestResult>;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @see HttpHeader
|
|
3
|
+
*/
|
|
4
|
+
export declare const HttpHeaderSchema: import("zod").ZodObject<{
|
|
5
|
+
name: import("zod").ZodString;
|
|
6
|
+
value: import("zod").ZodString;
|
|
7
|
+
}, import("zod/v4/core").$strip>;
|
|
8
|
+
/**
|
|
9
|
+
* @see HttpMethod
|
|
10
|
+
*/
|
|
11
|
+
export declare const HttpMethodSchema: import("zod").ZodEnum<{
|
|
12
|
+
GET: "GET";
|
|
13
|
+
POST: "POST";
|
|
14
|
+
HEAD: "HEAD";
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* @see HttpRequestArgs
|
|
18
|
+
*/
|
|
19
|
+
export declare const HttpRequestArgsSchema: import("zod").ZodObject<{
|
|
20
|
+
url: import("zod").ZodURL;
|
|
21
|
+
method: import("zod").ZodEnum<{
|
|
22
|
+
GET: "GET";
|
|
23
|
+
POST: "POST";
|
|
24
|
+
HEAD: "HEAD";
|
|
25
|
+
}>;
|
|
26
|
+
headers: import("zod").ZodArray<import("zod").ZodObject<{
|
|
27
|
+
name: import("zod").ZodString;
|
|
28
|
+
value: import("zod").ZodString;
|
|
29
|
+
}, import("zod/v4/core").$strip>>;
|
|
30
|
+
body: import("zod").ZodOptional<import("zod").ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
|
|
31
|
+
maxResponseBytes: import("zod").ZodOptional<import("zod").ZodBigInt>;
|
|
32
|
+
transform: import("zod").ZodOptional<import("zod").ZodString>;
|
|
33
|
+
isReplicated: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
34
|
+
}, import("zod/v4/core").$strip>;
|
|
35
|
+
/**
|
|
36
|
+
* @see HttpRequestResult
|
|
37
|
+
*/
|
|
38
|
+
export declare const HttpRequestResultSchema: import("zod").ZodObject<{
|
|
39
|
+
status: import("zod").ZodBigInt;
|
|
40
|
+
headers: import("zod").ZodArray<import("zod").ZodObject<{
|
|
41
|
+
name: import("zod").ZodString;
|
|
42
|
+
value: import("zod").ZodString;
|
|
43
|
+
}, import("zod/v4/core").$strip>>;
|
|
44
|
+
body: import("zod").ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
45
|
+
}, import("zod/v4/core").$strip>;
|
|
46
|
+
/**
|
|
47
|
+
* An HTTP header consisting of a name and value.
|
|
48
|
+
*/
|
|
49
|
+
export interface HttpHeader {
|
|
50
|
+
name: string;
|
|
51
|
+
value: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The HTTP method for the request.
|
|
55
|
+
*/
|
|
56
|
+
export type HttpMethod = 'GET' | 'POST' | 'HEAD';
|
|
57
|
+
/**
|
|
58
|
+
* The arguments for an HTTP request.
|
|
59
|
+
*/
|
|
60
|
+
export interface HttpRequestArgs {
|
|
61
|
+
url: string;
|
|
62
|
+
method: HttpMethod;
|
|
63
|
+
headers: HttpHeader[];
|
|
64
|
+
body?: Uint8Array;
|
|
65
|
+
maxResponseBytes?: bigint;
|
|
66
|
+
transform?: string;
|
|
67
|
+
isReplicated?: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The result of an HTTP request.
|
|
71
|
+
*/
|
|
72
|
+
export interface HttpRequestResult {
|
|
73
|
+
status: bigint;
|
|
74
|
+
headers: HttpHeader[];
|
|
75
|
+
body: Uint8Array;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* An HTTP header consisting of a name and value.
|
|
79
|
+
*/
|
|
80
|
+
export interface HttpHeader {
|
|
81
|
+
/**
|
|
82
|
+
* The header name.
|
|
83
|
+
*/
|
|
84
|
+
name: string;
|
|
85
|
+
/**
|
|
86
|
+
* The header value.
|
|
87
|
+
*/
|
|
88
|
+
value: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The arguments for an HTTP request.
|
|
92
|
+
*/
|
|
93
|
+
export interface HttpRequestArgs {
|
|
94
|
+
/**
|
|
95
|
+
* The requested URL.
|
|
96
|
+
*/
|
|
97
|
+
url: string;
|
|
98
|
+
/**
|
|
99
|
+
* The HTTP method.
|
|
100
|
+
*/
|
|
101
|
+
method: HttpMethod;
|
|
102
|
+
/**
|
|
103
|
+
* List of HTTP request headers and their corresponding values.
|
|
104
|
+
*/
|
|
105
|
+
headers: HttpHeader[];
|
|
106
|
+
/**
|
|
107
|
+
* Optionally provide request body.
|
|
108
|
+
*/
|
|
109
|
+
body?: Uint8Array;
|
|
110
|
+
/**
|
|
111
|
+
* The maximal size of the response in bytes.
|
|
112
|
+
*/
|
|
113
|
+
maxResponseBytes?: bigint;
|
|
114
|
+
/**
|
|
115
|
+
* The name of a query function used to transform the response before consensus - for example, to trim headers.
|
|
116
|
+
* If provided, a corresponding query must be declared using {@link defineQuery}.
|
|
117
|
+
*/
|
|
118
|
+
transform?: string;
|
|
119
|
+
/**
|
|
120
|
+
* Whether all nodes should perform the request and agree on the response, or just one node.
|
|
121
|
+
* Using a single node is cheaper but the response is not verified by others - suitable when you trust the data source or consistency is not critical.
|
|
122
|
+
* Defaults to all nodes if not specified.
|
|
123
|
+
*/
|
|
124
|
+
isReplicated?: boolean;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The result of an HTTP request.
|
|
128
|
+
*/
|
|
129
|
+
export interface HttpRequestResult {
|
|
130
|
+
/**
|
|
131
|
+
* The response status (e.g. 200, 404).
|
|
132
|
+
*/
|
|
133
|
+
status: bigint;
|
|
134
|
+
/**
|
|
135
|
+
* List of HTTP response headers and their corresponding values.
|
|
136
|
+
*/
|
|
137
|
+
headers: HttpHeader[];
|
|
138
|
+
/**
|
|
139
|
+
* The response's body.
|
|
140
|
+
*/
|
|
141
|
+
body: Uint8Array;
|
|
142
|
+
}
|
package/ic-cdk.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from './ic-cdk/call.ic-cdk';
|
|
2
2
|
export * from './ic-cdk/caller.ic-cdk';
|
|
3
|
+
export * from './ic-cdk/http-request.ic-cdk';
|
|
3
4
|
export * from './ic-cdk/id.ic-cdk';
|
|
4
5
|
export * from './ic-cdk/schemas/call';
|
|
6
|
+
export * from './ic-cdk/schemas/http-request';
|
|
5
7
|
export * from './ic-cdk/time.ic-cdk';
|
|
6
8
|
export * from './ic-cdk/types/errors';
|
package/ic-cdk.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as m,b as u,c as d,d as H,e as x,f,g as R}from"./chunk-PEKVE4RM.js";import"./chunk-JU5CZHLY.js";import"./chunk-4C666HHU.js";import{Principal as a}from"@icp-sdk/core/principal";var n=()=>a.fromUint8Array(__ic_cdk_caller()),y=()=>n();import{j as t}from"@junobuild/schema";var r=t.object({name:t.string(),value:t.string()}),c=t.enum(["GET","POST","HEAD"]),o=t.object({url:t.url(),method:c,headers:t.array(r),body:t.uint8Array().optional(),maxResponseBytes:t.bigint().optional(),transform:t.string().optional(),isReplicated:t.boolean().optional()}),i=t.object({status:t.bigint(),headers:t.array(r),body:t.uint8Array()});var q=async e=>{o.parse(e);let s=await __ic_cdk_http_request(e);return i.parse(s)};import{Principal as l}from"@icp-sdk/core/principal";var p=()=>l.fromUint8Array(__ic_cdk_id()),U=()=>p(),j=()=>p();var E=()=>__ic_cdk_time();export{u as CallArgSchema,d as CallArgsSchema,x as CallParamsSchema,f as CallResponseLengthError,H as CallResultSchema,r as HttpHeaderSchema,c as HttpMethodSchema,o as HttpRequestArgsSchema,i as HttpRequestResultSchema,m as IDLTypeSchema,R as call,y as caller,p as canisterSelf,q as httpRequest,U as id,n as msgCaller,j as satelliteSelf,E as time};
|
|
2
2
|
//# sourceMappingURL=ic-cdk.js.map
|
package/ic-cdk.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["src/ic-cdk/caller.ic-cdk.ts", "src/ic-cdk/id.ic-cdk.ts", "src/ic-cdk/time.ic-cdk.ts"],
|
|
4
|
-
"sourcesContent": ["import {Principal} from '@icp-sdk/core/principal';\n\n/**\n * Retrieves the caller's Principal ID.\n *\n * This function is a JavaScript binding for the Rust function\n * [`ic_cdk::api::msg_caller()`](https://docs.rs/ic-cdk/latest/ic_cdk/api/fn.msg_caller.html), which returns\n * the Principal of the caller of the current call.\n *\n * @returns {Principal} The Principal ID of the caller.\n */\nexport const msgCaller = (): Principal => {\n const principal = Principal.fromUint8Array(__ic_cdk_caller());\n\n return principal;\n};\n\n/**\n * @deprecated Use {@link msgCaller} instead.\n */\nexport const caller = (): Principal => msgCaller();\n", "import {Principal} from '@icp-sdk/core/principal';\n\n/**\n * Retrieves the Satellite's Principal ID.\n *\n * This function is a JavaScript binding for the Rust function\n * [`ic_cdk::api::canister_self()`](https://docs.rs/ic-cdk/latest/ic_cdk/api/fn.canister_self.html), which returns\n * the Principal of the executing canister.\n *\n * @returns {Principal} The Principal ID of the Satellite.\n */\nexport const canisterSelf = (): Principal => {\n const principal = Principal.fromUint8Array(__ic_cdk_id());\n\n // We assume the Principal is always built using the global function and is therefore always valid.\n // In other words, we do not validate it to conserve resources and optimize performance.\n\n return principal;\n};\n\n/**\n * @deprecated Use {@link canisterSelf} instead.\n */\nexport const id = (): Principal => canisterSelf();\n\n/**\n * Retrieves the Satellite's Principal ID.\n *\n * @returns {Principal} The Principal ID of the Satellite.\n */\nexport const satelliteSelf = (): Principal => canisterSelf();\n", "/**\n * Gets current timestamp, in nanoseconds since the epoch (1970-01-01)\n *\n * This function is a JavaScript binding for the Rust function\n * [`ic_cdk::time()`](https://docs.rs/ic-cdk/latest/ic_cdk/api/fn.time.html), which returns\n * the system time publicly exposed and verified part of the IC state tree\n *\n * @returns {bigint} The current timestamp.\n */\nexport const time = (): bigint => __ic_cdk_time();\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["Principal", "msgCaller", "caller", "Principal", "canisterSelf", "id", "satelliteSelf", "time"]
|
|
3
|
+
"sources": ["src/ic-cdk/caller.ic-cdk.ts", "src/ic-cdk/schemas/http-request.ts", "src/ic-cdk/http-request.ic-cdk.ts", "src/ic-cdk/id.ic-cdk.ts", "src/ic-cdk/time.ic-cdk.ts"],
|
|
4
|
+
"sourcesContent": ["import {Principal} from '@icp-sdk/core/principal';\n\n/**\n * Retrieves the caller's Principal ID.\n *\n * This function is a JavaScript binding for the Rust function\n * [`ic_cdk::api::msg_caller()`](https://docs.rs/ic-cdk/latest/ic_cdk/api/fn.msg_caller.html), which returns\n * the Principal of the caller of the current call.\n *\n * @returns {Principal} The Principal ID of the caller.\n */\nexport const msgCaller = (): Principal => {\n const principal = Principal.fromUint8Array(__ic_cdk_caller());\n\n return principal;\n};\n\n/**\n * @deprecated Use {@link msgCaller} instead.\n */\nexport const caller = (): Principal => msgCaller();\n", "import {j} from '@junobuild/schema';\n\n/**\n * @see HttpHeader\n */\nexport const HttpHeaderSchema = j.object({\n name: j.string(),\n value: j.string()\n});\n\n/**\n * @see HttpMethod\n */\nexport const HttpMethodSchema = j.enum(['GET', 'POST', 'HEAD']);\n\n/**\n * @see HttpRequestArgs\n */\nexport const HttpRequestArgsSchema = j.object({\n url: j.url(),\n method: HttpMethodSchema,\n headers: j.array(HttpHeaderSchema),\n body: j.uint8Array().optional(),\n maxResponseBytes: j.bigint().optional(),\n transform: j.string().optional(),\n isReplicated: j.boolean().optional()\n});\n\n/**\n * @see HttpRequestResult\n */\nexport const HttpRequestResultSchema = j.object({\n status: j.bigint(),\n headers: j.array(HttpHeaderSchema),\n body: j.uint8Array()\n});\n\n/**\n * An HTTP header consisting of a name and value.\n */\nexport interface HttpHeader {\n name: string;\n value: string;\n}\n\n/**\n * The HTTP method for the request.\n */\nexport type HttpMethod = 'GET' | 'POST' | 'HEAD';\n\n/**\n * The arguments for an HTTP request.\n */\nexport interface HttpRequestArgs {\n url: string;\n method: HttpMethod;\n headers: HttpHeader[];\n body?: Uint8Array;\n maxResponseBytes?: bigint;\n transform?: string;\n isReplicated?: boolean;\n}\n\n/**\n * The result of an HTTP request.\n */\nexport interface HttpRequestResult {\n status: bigint;\n headers: HttpHeader[];\n body: Uint8Array;\n}\n\n/**\n * An HTTP header consisting of a name and value.\n */\nexport interface HttpHeader {\n /**\n * The header name.\n */\n name: string;\n\n /**\n * The header value.\n */\n value: string;\n}\n\n/**\n * The arguments for an HTTP request.\n */\nexport interface HttpRequestArgs {\n /**\n * The requested URL.\n */\n url: string;\n\n /**\n * The HTTP method.\n */\n method: HttpMethod;\n\n /**\n * List of HTTP request headers and their corresponding values.\n */\n headers: HttpHeader[];\n\n /**\n * Optionally provide request body.\n */\n body?: Uint8Array;\n\n /**\n * The maximal size of the response in bytes.\n */\n maxResponseBytes?: bigint;\n\n /**\n * The name of a query function used to transform the response before consensus - for example, to trim headers.\n * If provided, a corresponding query must be declared using {@link defineQuery}.\n */\n transform?: string;\n\n /**\n * Whether all nodes should perform the request and agree on the response, or just one node.\n * Using a single node is cheaper but the response is not verified by others - suitable when you trust the data source or consistency is not critical.\n * Defaults to all nodes if not specified.\n */\n isReplicated?: boolean;\n}\n\n/**\n * The result of an HTTP request.\n */\nexport interface HttpRequestResult {\n /**\n * The response status (e.g. 200, 404).\n */\n status: bigint;\n\n /**\n * List of HTTP response headers and their corresponding values.\n */\n headers: HttpHeader[];\n\n /**\n * The response's body.\n */\n body: Uint8Array;\n}\n", "import {\n type HttpRequestArgs,\n type HttpRequestResult,\n HttpRequestArgsSchema,\n HttpRequestResultSchema\n} from './schemas/http-request';\n\n/**\n * Performs an HTTP request from a Juno serverless function.\n *\n * @param {HttpRequestArgs} args - The HTTP request parameters\n * @returns {Promise<HttpRequestResult>} A promise resolving to the HTTP response.\n * @throws {ZodError} If the provided arguments do not match the expected schema.\n * @throws {Error} If the HTTP request fails.\n */\nexport const httpRequest = async (args: HttpRequestArgs): Promise<HttpRequestResult> => {\n HttpRequestArgsSchema.parse(args);\n\n const result = await __ic_cdk_http_request(args);\n\n return HttpRequestResultSchema.parse(result);\n};\n", "import {Principal} from '@icp-sdk/core/principal';\n\n/**\n * Retrieves the Satellite's Principal ID.\n *\n * This function is a JavaScript binding for the Rust function\n * [`ic_cdk::api::canister_self()`](https://docs.rs/ic-cdk/latest/ic_cdk/api/fn.canister_self.html), which returns\n * the Principal of the executing canister.\n *\n * @returns {Principal} The Principal ID of the Satellite.\n */\nexport const canisterSelf = (): Principal => {\n const principal = Principal.fromUint8Array(__ic_cdk_id());\n\n // We assume the Principal is always built using the global function and is therefore always valid.\n // In other words, we do not validate it to conserve resources and optimize performance.\n\n return principal;\n};\n\n/**\n * @deprecated Use {@link canisterSelf} instead.\n */\nexport const id = (): Principal => canisterSelf();\n\n/**\n * Retrieves the Satellite's Principal ID.\n *\n * @returns {Principal} The Principal ID of the Satellite.\n */\nexport const satelliteSelf = (): Principal => canisterSelf();\n", "/**\n * Gets current timestamp, in nanoseconds since the epoch (1970-01-01)\n *\n * This function is a JavaScript binding for the Rust function\n * [`ic_cdk::time()`](https://docs.rs/ic-cdk/latest/ic_cdk/api/fn.time.html), which returns\n * the system time publicly exposed and verified part of the IC state tree\n *\n * @returns {bigint} The current timestamp.\n */\nexport const time = (): bigint => __ic_cdk_time();\n"],
|
|
5
|
+
"mappings": "qIAAA,OAAQ,aAAAA,MAAgB,0BAWjB,IAAMC,EAAY,IACLD,EAAU,eAAe,gBAAgB,CAAC,EAQjDE,EAAS,IAAiBD,EAAU,ECpBjD,OAAQ,KAAAE,MAAQ,oBAKT,IAAMC,EAAmBD,EAAE,OAAO,CACvC,KAAMA,EAAE,OAAO,EACf,MAAOA,EAAE,OAAO,CAClB,CAAC,EAKYE,EAAmBF,EAAE,KAAK,CAAC,MAAO,OAAQ,MAAM,CAAC,EAKjDG,EAAwBH,EAAE,OAAO,CAC5C,IAAKA,EAAE,IAAI,EACX,OAAQE,EACR,QAASF,EAAE,MAAMC,CAAgB,EACjC,KAAMD,EAAE,WAAW,EAAE,SAAS,EAC9B,iBAAkBA,EAAE,OAAO,EAAE,SAAS,EACtC,UAAWA,EAAE,OAAO,EAAE,SAAS,EAC/B,aAAcA,EAAE,QAAQ,EAAE,SAAS,CACrC,CAAC,EAKYI,EAA0BJ,EAAE,OAAO,CAC9C,OAAQA,EAAE,OAAO,EACjB,QAASA,EAAE,MAAMC,CAAgB,EACjC,KAAMD,EAAE,WAAW,CACrB,CAAC,ECpBM,IAAMK,EAAc,MAAOC,GAAsD,CACtFC,EAAsB,MAAMD,CAAI,EAEhC,IAAME,EAAS,MAAM,sBAAsBF,CAAI,EAE/C,OAAOG,EAAwB,MAAMD,CAAM,CAC7C,ECrBA,OAAQ,aAAAE,MAAgB,0BAWjB,IAAMC,EAAe,IACRD,EAAU,eAAe,YAAY,CAAC,EAW7CE,EAAK,IAAiBD,EAAa,EAOnCE,EAAgB,IAAiBF,EAAa,ECrBpD,IAAMG,EAAO,IAAc,cAAc",
|
|
6
|
+
"names": ["Principal", "msgCaller", "caller", "j", "HttpHeaderSchema", "HttpMethodSchema", "HttpRequestArgsSchema", "HttpRequestResultSchema", "httpRequest", "args", "HttpRequestArgsSchema", "result", "HttpRequestResultSchema", "Principal", "canisterSelf", "id", "satelliteSelf", "time"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@junobuild/functions",
|
|
3
|
-
"version": "0.7.2-next-2026-03-
|
|
3
|
+
"version": "0.7.2-next-2026-03-29",
|
|
4
4
|
"description": "JavaScript and TypeScript utilities for Juno Serverless Functions",
|
|
5
5
|
"author": "David Dal Busco (https://daviddalbusco.com)",
|
|
6
6
|
"license": "MIT",
|