@planqk/planqk-api-sdk 1.3.6 → 1.6.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.
Files changed (126) hide show
  1. package/.fossa.yml +1 -0
  2. package/.gitlab-ci.yml +21 -14
  3. package/.releaserc.json +2 -1
  4. package/dist/sdk/Client.d.ts +8 -0
  5. package/dist/sdk/Client.js +12 -2
  6. package/dist/sdk/api/resources/dataPools/client/Client.d.ts +4 -1
  7. package/dist/sdk/api/resources/dataPools/client/Client.js +57 -39
  8. package/dist/sdk/api/resources/dataPools/client/requests/AddDataPoolFileRequest.d.ts +1 -1
  9. package/dist/sdk/api/resources/dataPools/client/requests/CreateDataPoolRequest.d.ts +1 -0
  10. package/dist/sdk/api/resources/dataPools/client/requests/UpdateDataPoolRequest.d.ts +3 -0
  11. package/dist/sdk/api/resources/index.d.ts +3 -0
  12. package/dist/sdk/api/resources/index.js +4 -1
  13. package/dist/sdk/api/resources/serviceExecutions/client/Client.d.ts +90 -0
  14. package/dist/sdk/api/resources/serviceExecutions/client/Client.js +271 -0
  15. package/dist/sdk/api/resources/serviceExecutions/client/index.d.ts +1 -0
  16. package/dist/sdk/api/resources/serviceExecutions/index.d.ts +1 -0
  17. package/dist/sdk/api/resources/serviceExecutions/index.js +17 -0
  18. package/dist/sdk/api/resources/serviceJobs/client/Client.d.ts +138 -0
  19. package/dist/sdk/api/resources/serviceJobs/client/Client.js +489 -0
  20. package/dist/sdk/api/resources/serviceJobs/client/index.d.ts +2 -0
  21. package/dist/sdk/api/resources/serviceJobs/client/index.js +17 -0
  22. package/dist/sdk/api/resources/serviceJobs/client/requests/CreateServiceJobRequest.d.ts +15 -0
  23. package/dist/sdk/api/resources/serviceJobs/client/requests/CreateServiceJobRequest.js +5 -0
  24. package/dist/sdk/api/resources/serviceJobs/client/requests/index.d.ts +1 -0
  25. package/dist/sdk/api/resources/serviceJobs/client/requests/index.js +2 -0
  26. package/dist/sdk/api/resources/serviceJobs/index.d.ts +1 -0
  27. package/dist/sdk/api/resources/serviceJobs/index.js +17 -0
  28. package/dist/sdk/api/types/ActivityInstance.d.ts +20 -0
  29. package/dist/sdk/api/types/ActivityInstance.js +14 -0
  30. package/dist/sdk/api/types/DataPoolDto.d.ts +5 -0
  31. package/dist/sdk/api/types/DataPoolFileDto.d.ts +7 -0
  32. package/dist/sdk/api/types/LogEntry.d.ts +24 -0
  33. package/dist/sdk/api/types/LogEntry.js +16 -0
  34. package/dist/sdk/api/types/MetricDataPoint.d.ts +12 -0
  35. package/dist/sdk/api/types/MetricDataPoint.js +5 -0
  36. package/dist/sdk/api/types/ServiceExecutionDto.d.ts +21 -0
  37. package/dist/sdk/api/types/ServiceExecutionDto.js +17 -0
  38. package/dist/sdk/api/types/ServiceExecutionLogs.d.ts +5 -0
  39. package/dist/sdk/api/types/ServiceExecutionLogs.js +5 -0
  40. package/dist/sdk/api/types/ServiceExecutionMetrics.d.ts +23 -0
  41. package/dist/sdk/api/types/ServiceExecutionMetrics.js +5 -0
  42. package/dist/sdk/api/types/ServiceJobDto.d.ts +46 -0
  43. package/dist/sdk/api/types/ServiceJobDto.js +22 -0
  44. package/dist/sdk/api/types/VariableInstance.d.ts +9 -0
  45. package/dist/sdk/api/types/VariableInstance.js +5 -0
  46. package/dist/sdk/api/types/WorkflowInstance.d.ts +23 -0
  47. package/dist/sdk/api/types/WorkflowInstance.js +17 -0
  48. package/dist/sdk/api/types/WorkflowServiceExecutionDto.d.ts +8 -0
  49. package/dist/sdk/api/types/WorkflowServiceExecutionDto.js +5 -0
  50. package/dist/sdk/api/types/index.d.ts +10 -0
  51. package/dist/sdk/api/types/index.js +10 -0
  52. package/dist/sdk/core/exports.d.ts +1 -0
  53. package/dist/sdk/core/exports.js +17 -0
  54. package/dist/sdk/core/fetcher/Fetcher.d.ts +1 -1
  55. package/dist/sdk/core/fetcher/Fetcher.js +2 -2
  56. package/dist/sdk/core/fetcher/index.d.ts +5 -5
  57. package/dist/sdk/core/fetcher/index.js +5 -5
  58. package/dist/sdk/core/file/exports.d.ts +1 -0
  59. package/dist/sdk/core/file/exports.js +2 -0
  60. package/dist/sdk/core/file/file.d.ts +5 -0
  61. package/dist/sdk/core/file/file.js +185 -0
  62. package/dist/sdk/core/file/index.d.ts +2 -0
  63. package/dist/sdk/core/file/index.js +18 -0
  64. package/dist/sdk/core/file/types.d.ts +66 -0
  65. package/dist/sdk/core/file/types.js +2 -0
  66. package/dist/sdk/core/form-data-utils/FormDataWrapper.js +12 -3
  67. package/dist/sdk/core/index.d.ts +1 -1
  68. package/dist/sdk/core/index.js +2 -2
  69. package/dist/sdk/core/url/join.js +23 -3
  70. package/dist/sdk/exports.d.ts +1 -0
  71. package/dist/sdk/exports.js +17 -0
  72. package/dist/sdk/index.d.ts +1 -0
  73. package/dist/sdk/index.js +4 -0
  74. package/fern/fern.config.json +1 -1
  75. package/fern/generators.yml +9 -3
  76. package/fern/openapi/openapi.json +950 -54
  77. package/package.json +1 -1
  78. package/planqk/api/_version.py +1 -1
  79. package/pyproject.toml +1 -1
  80. package/requirements.txt +319 -0
  81. package/scripts/update-version.sh +2 -0
  82. package/src/index.test.ts +11 -0
  83. package/src/sdk/Client.ts +14 -0
  84. package/src/sdk/api/resources/dataPools/client/Client.ts +95 -75
  85. package/src/sdk/api/resources/dataPools/client/requests/AddDataPoolFileRequest.ts +1 -1
  86. package/src/sdk/api/resources/dataPools/client/requests/CreateDataPoolRequest.ts +1 -0
  87. package/src/sdk/api/resources/dataPools/client/requests/UpdateDataPoolRequest.ts +3 -0
  88. package/src/sdk/api/resources/index.ts +3 -0
  89. package/src/sdk/api/resources/serviceExecutions/client/Client.ts +323 -0
  90. package/src/sdk/api/resources/serviceExecutions/client/index.ts +1 -0
  91. package/src/sdk/api/resources/serviceExecutions/index.ts +1 -0
  92. package/src/sdk/api/resources/serviceJobs/client/Client.ts +581 -0
  93. package/src/sdk/api/resources/serviceJobs/client/index.ts +2 -0
  94. package/src/sdk/api/resources/serviceJobs/client/requests/CreateServiceJobRequest.ts +16 -0
  95. package/src/sdk/api/resources/serviceJobs/client/requests/index.ts +1 -0
  96. package/src/sdk/api/resources/serviceJobs/index.ts +1 -0
  97. package/src/sdk/api/types/ActivityInstance.ts +22 -0
  98. package/src/sdk/api/types/DataPoolDto.ts +5 -0
  99. package/src/sdk/api/types/DataPoolFileDto.ts +7 -0
  100. package/src/sdk/api/types/LogEntry.ts +26 -0
  101. package/src/sdk/api/types/MetricDataPoint.ts +13 -0
  102. package/src/sdk/api/types/ServiceExecutionDto.ts +23 -0
  103. package/src/sdk/api/types/ServiceExecutionLogs.ts +7 -0
  104. package/src/sdk/api/types/ServiceExecutionMetrics.ts +25 -0
  105. package/src/sdk/api/types/ServiceJobDto.ts +48 -0
  106. package/src/sdk/api/types/VariableInstance.ts +10 -0
  107. package/src/sdk/api/types/WorkflowInstance.ts +26 -0
  108. package/src/sdk/api/types/WorkflowServiceExecutionDto.ts +10 -0
  109. package/src/sdk/api/types/index.ts +10 -0
  110. package/src/sdk/core/exports.ts +1 -0
  111. package/src/sdk/core/fetcher/Fetcher.ts +3 -3
  112. package/src/sdk/core/fetcher/index.ts +5 -5
  113. package/src/sdk/core/file/exports.ts +1 -0
  114. package/src/sdk/core/file/file.ts +186 -0
  115. package/src/sdk/core/file/index.ts +2 -0
  116. package/src/sdk/core/file/types.ts +81 -0
  117. package/src/sdk/core/form-data-utils/FormDataWrapper.ts +12 -3
  118. package/src/sdk/core/index.ts +1 -1
  119. package/src/sdk/core/url/join.ts +28 -3
  120. package/src/sdk/exports.ts +1 -0
  121. package/src/sdk/index.ts +1 -0
  122. package/uv.lock +245 -228
  123. package/dist/sdk/core/file.d.ts +0 -1
  124. package/planqk/__init__.py +0 -0
  125. package/src/sdk/core/file.ts +0 -11
  126. /package/dist/sdk/{core/file.js → api/resources/serviceExecutions/client/index.js} +0 -0
@@ -0,0 +1,26 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+
5
+ export interface LogEntry {
6
+ /** Log message content. */
7
+ message?: string;
8
+ /** Severity of the log entry. */
9
+ severity?: LogEntry.Severity;
10
+ /** Timestamp when the entry was logged. */
11
+ timestamp?: string;
12
+ }
13
+
14
+ export namespace LogEntry {
15
+ /**
16
+ * Severity of the log entry.
17
+ */
18
+ export type Severity = "DEBUG" | "NOTICE" | "INFO" | "WARNING" | "ERROR";
19
+ export const Severity = {
20
+ Debug: "DEBUG",
21
+ Notice: "NOTICE",
22
+ Info: "INFO",
23
+ Warning: "WARNING",
24
+ Error: "ERROR",
25
+ } as const;
26
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+
5
+ /**
6
+ * A single data point in a time series metric
7
+ */
8
+ export interface MetricDataPoint {
9
+ /** Timestamp of the data point in milliseconds since Unix epoch (UTC) */
10
+ timestamp?: number;
11
+ /** The metric value */
12
+ value?: number;
13
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+
5
+ export interface ServiceExecutionDto {
6
+ id?: string;
7
+ createdAt?: string;
8
+ startedAt?: string;
9
+ endedAt?: string;
10
+ status?: ServiceExecutionDto.Status;
11
+ }
12
+
13
+ export namespace ServiceExecutionDto {
14
+ export type Status = "UNKNOWN" | "PENDING" | "RUNNING" | "SUCCEEDED" | "FAILED" | "CANCELLED";
15
+ export const Status = {
16
+ Unknown: "UNKNOWN",
17
+ Pending: "PENDING",
18
+ Running: "RUNNING",
19
+ Succeeded: "SUCCEEDED",
20
+ Failed: "FAILED",
21
+ Cancelled: "CANCELLED",
22
+ } as const;
23
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+
5
+ import * as PlanqkApi from "../index.js";
6
+
7
+ export type ServiceExecutionLogs = PlanqkApi.LogEntry[];
@@ -0,0 +1,25 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+
5
+ import * as PlanqkApi from "../index.js";
6
+
7
+ /**
8
+ * Resource usage metrics for a service execution
9
+ */
10
+ export interface ServiceExecutionMetrics {
11
+ /** Service execution ID */
12
+ serviceExecutionId?: string;
13
+ /** CPU usage metrics time series */
14
+ cpuUsage?: PlanqkApi.MetricDataPoint[];
15
+ /** CPU limit metrics time series */
16
+ cpuLimit?: PlanqkApi.MetricDataPoint[];
17
+ /** Memory usage metrics time series */
18
+ memoryUsage?: PlanqkApi.MetricDataPoint[];
19
+ /** Memory limit metrics time series */
20
+ memoryLimit?: PlanqkApi.MetricDataPoint[];
21
+ /** Time range start */
22
+ startTime?: string;
23
+ /** Time range end */
24
+ endTime?: string;
25
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+
5
+ export interface ServiceJobDto {
6
+ /** The ID of the service job. */
7
+ id?: string;
8
+ /** The ID of the service for which this job was created. */
9
+ serviceId?: string;
10
+ /** The ID of the service definition for which this job was created. */
11
+ serviceDefinitionId?: string;
12
+ /** Status of the service job. */
13
+ status?: ServiceJobDto.Status;
14
+ /** Timestamp when the service job was created. */
15
+ createdAt?: string;
16
+ /** Timestamp when the service job started. */
17
+ startedAt?: string;
18
+ /** Timestamp when the service job ended. */
19
+ endedAt?: string;
20
+ /** Type identifier for the service job, indicating whether the underlying service is a 'managed' or 'workflow' service. */
21
+ type?: ServiceJobDto.Type;
22
+ /** List of tags associated with the service job. Tags are saved in lowercase and can be used for filtering and searching. */
23
+ tags?: string[];
24
+ }
25
+
26
+ export namespace ServiceJobDto {
27
+ /**
28
+ * Status of the service job.
29
+ */
30
+ export type Status = "UNKNOWN" | "PENDING" | "RUNNING" | "SUCCEEDED" | "FAILED" | "CANCELLED";
31
+ export const Status = {
32
+ Unknown: "UNKNOWN",
33
+ Pending: "PENDING",
34
+ Running: "RUNNING",
35
+ Succeeded: "SUCCEEDED",
36
+ Failed: "FAILED",
37
+ Cancelled: "CANCELLED",
38
+ } as const;
39
+ /**
40
+ * Type identifier for the service job, indicating whether the underlying service is a 'managed' or 'workflow' service.
41
+ */
42
+ export type Type = "MANAGED" | "EXTERNAL" | "WORKFLOW";
43
+ export const Type = {
44
+ Managed: "MANAGED",
45
+ External: "EXTERNAL",
46
+ Workflow: "WORKFLOW",
47
+ } as const;
48
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+
5
+ export interface VariableInstance {
6
+ id?: string;
7
+ name?: string;
8
+ type?: string;
9
+ value?: any;
10
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+
5
+ import * as PlanqkApi from "../index.js";
6
+
7
+ export interface WorkflowInstance {
8
+ id?: string;
9
+ state?: WorkflowInstance.State;
10
+ startedAt?: string;
11
+ endedAt?: string;
12
+ activities?: PlanqkApi.ActivityInstance[];
13
+ variables?: PlanqkApi.VariableInstance[];
14
+ }
15
+
16
+ export namespace WorkflowInstance {
17
+ export type State = "UNKNOWN" | "PENDING" | "RUNNING" | "SUCCEEDED" | "FAILED" | "CANCELLED";
18
+ export const State = {
19
+ Unknown: "UNKNOWN",
20
+ Pending: "PENDING",
21
+ Running: "RUNNING",
22
+ Succeeded: "SUCCEEDED",
23
+ Failed: "FAILED",
24
+ Cancelled: "CANCELLED",
25
+ } as const;
26
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file was auto-generated by Fern from our API Definition.
3
+ */
4
+
5
+ import * as PlanqkApi from "../index.js";
6
+
7
+ export interface WorkflowServiceExecutionDto {
8
+ workflowInstance?: PlanqkApi.WorkflowInstance;
9
+ workflowModel?: string;
10
+ }
@@ -1,3 +1,13 @@
1
1
  export * from "./OauthScope.js";
2
2
  export * from "./DataPoolDto.js";
3
+ export * from "./ServiceJobDto.js";
3
4
  export * from "./DataPoolFileDto.js";
5
+ export * from "./LogEntry.js";
6
+ export * from "./ServiceExecutionLogs.js";
7
+ export * from "./ServiceExecutionDto.js";
8
+ export * from "./ActivityInstance.js";
9
+ export * from "./VariableInstance.js";
10
+ export * from "./WorkflowInstance.js";
11
+ export * from "./WorkflowServiceExecutionDto.js";
12
+ export * from "./MetricDataPoint.js";
13
+ export * from "./ServiceExecutionMetrics.js";
@@ -0,0 +1 @@
1
+ export * from "./file/exports.js";
@@ -1,14 +1,14 @@
1
1
  import { toJson } from "../json.js";
2
2
  import { APIResponse } from "./APIResponse.js";
3
- import { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.js";
4
- import { Supplier } from "./Supplier.js";
5
3
  import { createRequestUrl } from "./createRequestUrl.js";
6
4
  import { getErrorResponseBody } from "./getErrorResponseBody.js";
7
5
  import { getFetchFn } from "./getFetchFn.js";
8
6
  import { getRequestBody } from "./getRequestBody.js";
9
7
  import { getResponseBody } from "./getResponseBody.js";
10
8
  import { makeRequest } from "./makeRequest.js";
9
+ import { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.js";
11
10
  import { requestWithRetries } from "./requestWithRetries.js";
11
+ import { Supplier } from "./Supplier.js";
12
12
 
13
13
  export type FetchFunction = <R = unknown>(args: Fetcher.Args) => Promise<APIResponse<R, Fetcher.Error>>;
14
14
 
@@ -18,7 +18,7 @@ export declare namespace Fetcher {
18
18
  method: string;
19
19
  contentType?: string;
20
20
  headers?: Record<string, string | Supplier<string | undefined> | undefined>;
21
- queryParameters?: Record<string, string | string[] | object | object[] | null>;
21
+ queryParameters?: Record<string, unknown>;
22
22
  body?: unknown;
23
23
  timeoutMs?: number;
24
24
  maxRetries?: number;
@@ -1,9 +1,9 @@
1
1
  export type { APIResponse } from "./APIResponse.js";
2
- export { fetcher } from "./Fetcher.js";
2
+ export type { BinaryResponse } from "./BinaryResponse.js";
3
3
  export type { Fetcher, FetchFunction } from "./Fetcher.js";
4
+ export { fetcher } from "./Fetcher.js";
4
5
  export { getHeader } from "./getHeader.js";
5
- export { Supplier } from "./Supplier.js";
6
- export { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.js";
7
- export type { RawResponse, WithRawResponse } from "./RawResponse.js";
8
6
  export { HttpResponsePromise } from "./HttpResponsePromise.js";
9
- export { BinaryResponse } from "./BinaryResponse.js";
7
+ export type { RawResponse, WithRawResponse } from "./RawResponse.js";
8
+ export { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.js";
9
+ export { Supplier } from "./Supplier.js";
@@ -0,0 +1 @@
1
+ export { Uploadable } from "./types.js";
@@ -0,0 +1,186 @@
1
+ import { Uploadable } from "./types.js";
2
+
3
+ export async function toBinaryUploadRequest(
4
+ file: Uploadable,
5
+ ): Promise<{ body: Uploadable.FileLike; headers?: Record<string, string> }> {
6
+ const { data, filename, contentLength, contentType } = await getFileWithMetadata(file);
7
+ const request = {
8
+ body: data,
9
+ headers: {} as Record<string, string>,
10
+ };
11
+ if (filename) {
12
+ request.headers["Content-Disposition"] = `attachment; filename="${filename}"`;
13
+ }
14
+ if (contentType) {
15
+ request.headers["Content-Type"] = contentType;
16
+ }
17
+ if (contentLength != null) {
18
+ request.headers["Content-Length"] = contentLength.toString();
19
+ }
20
+ return request;
21
+ }
22
+
23
+ async function getFileWithMetadata(file: Uploadable): Promise<Uploadable.WithMetadata> {
24
+ if (isFileLike(file)) {
25
+ return getFileWithMetadata({
26
+ data: file,
27
+ });
28
+ }
29
+ if ("path" in file) {
30
+ const fs = await import("fs");
31
+ if (!fs || !fs.createReadStream) {
32
+ throw new Error("File path uploads are not supported in this environment.");
33
+ }
34
+ const data = fs.createReadStream(file.path);
35
+ const contentLength = file.contentLength ?? (await tryGetFileSizeFromPath(file.path));
36
+ const filename = file.filename ?? getNameFromPath(file.path);
37
+ return {
38
+ data,
39
+ filename,
40
+ contentType: file.contentType,
41
+ contentLength,
42
+ };
43
+ }
44
+ if ("data" in file) {
45
+ const data = file.data;
46
+ const contentLength = file.contentLength ?? (await tryGetContentLengthFromFileLike(data));
47
+ const filename = file.filename ?? tryGetNameFromFileLike(data);
48
+ return {
49
+ data,
50
+ filename,
51
+ contentType: file.contentType ?? tryGetContentTypeFromFileLike(data),
52
+ contentLength,
53
+ };
54
+ }
55
+
56
+ throw new Error(`Invalid FileUpload of type ${typeof file}: ${JSON.stringify(file)}`);
57
+ }
58
+
59
+ function isFileLike(value: unknown): value is Uploadable.FileLike {
60
+ return (
61
+ isBuffer(value) ||
62
+ isArrayBufferView(value) ||
63
+ isArrayBuffer(value) ||
64
+ isUint8Array(value) ||
65
+ isBlob(value) ||
66
+ isFile(value) ||
67
+ isStreamLike(value) ||
68
+ isReadableStream(value)
69
+ );
70
+ }
71
+
72
+ async function tryGetFileSizeFromPath(path: string): Promise<number | undefined> {
73
+ try {
74
+ const fs = await import("fs");
75
+ if (!fs || !fs.promises || !fs.promises.stat) {
76
+ return undefined;
77
+ }
78
+ const fileStat = await fs.promises.stat(path);
79
+ return fileStat.size;
80
+ } catch (fallbackError) {
81
+ return undefined;
82
+ }
83
+ }
84
+
85
+ function tryGetNameFromFileLike(data: Uploadable.FileLike): string | undefined {
86
+ if (isNamedValue(data)) {
87
+ return data.name;
88
+ }
89
+ if (isPathedValue(data)) {
90
+ return getNameFromPath(data.path.toString());
91
+ }
92
+ return undefined;
93
+ }
94
+
95
+ async function tryGetContentLengthFromFileLike(data: Uploadable.FileLike): Promise<number | undefined> {
96
+ if (isBuffer(data)) {
97
+ return data.length;
98
+ }
99
+ if (isArrayBufferView(data)) {
100
+ return data.byteLength;
101
+ }
102
+ if (isArrayBuffer(data)) {
103
+ return data.byteLength;
104
+ }
105
+ if (isBlob(data)) {
106
+ return data.size;
107
+ }
108
+ if (isFile(data)) {
109
+ return data.size;
110
+ }
111
+ if (isPathedValue(data)) {
112
+ return await tryGetFileSizeFromPath(data.path.toString());
113
+ }
114
+ return undefined;
115
+ }
116
+
117
+ function tryGetContentTypeFromFileLike(data: Uploadable.FileLike): string | undefined {
118
+ if (isBlob(data)) {
119
+ return data.type;
120
+ }
121
+ if (isFile(data)) {
122
+ return data.type;
123
+ }
124
+
125
+ return undefined;
126
+ }
127
+
128
+ function getNameFromPath(path: string): string | undefined {
129
+ const lastForwardSlash = path.lastIndexOf("/");
130
+ const lastBackSlash = path.lastIndexOf("\\");
131
+ const lastSlashIndex = Math.max(lastForwardSlash, lastBackSlash);
132
+ return lastSlashIndex >= 0 ? path.substring(lastSlashIndex + 1) : path;
133
+ }
134
+
135
+ type NamedValue = {
136
+ name: string;
137
+ } & unknown;
138
+
139
+ type PathedValue = {
140
+ path: string | { toString(): string };
141
+ } & unknown;
142
+
143
+ type StreamLike = {
144
+ read?: () => unknown;
145
+ pipe?: (dest: unknown) => unknown;
146
+ } & unknown;
147
+
148
+ function isNamedValue(value: unknown): value is NamedValue {
149
+ return typeof value === "object" && value != null && "name" in value;
150
+ }
151
+
152
+ function isPathedValue(value: unknown): value is PathedValue {
153
+ return typeof value === "object" && value != null && "path" in value;
154
+ }
155
+
156
+ function isStreamLike(value: unknown): value is StreamLike {
157
+ return typeof value === "object" && value != null && ("read" in value || "pipe" in value);
158
+ }
159
+
160
+ function isReadableStream(value: unknown): value is ReadableStream {
161
+ return typeof value === "object" && value != null && "getReader" in value;
162
+ }
163
+
164
+ function isBuffer(value: unknown): value is Buffer {
165
+ return typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(value);
166
+ }
167
+
168
+ function isArrayBufferView(value: unknown): value is ArrayBufferView {
169
+ return typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView(value);
170
+ }
171
+
172
+ function isArrayBuffer(value: unknown): value is ArrayBuffer {
173
+ return typeof ArrayBuffer !== "undefined" && value instanceof ArrayBuffer;
174
+ }
175
+
176
+ function isUint8Array(value: unknown): value is Uint8Array {
177
+ return typeof Uint8Array !== "undefined" && value instanceof Uint8Array;
178
+ }
179
+
180
+ function isBlob(value: unknown): value is Blob {
181
+ return typeof Blob !== "undefined" && value instanceof Blob;
182
+ }
183
+
184
+ function isFile(value: unknown): value is File {
185
+ return typeof File !== "undefined" && value instanceof File;
186
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./file.js";
2
+ export * from "./types.js";
@@ -0,0 +1,81 @@
1
+ /**
2
+ * A file that can be uploaded. Can be a file-like object (stream, buffer, blob, etc.),
3
+ * a path to a file, or an object with a file-like object and metadata.
4
+ */
5
+ export type Uploadable = Uploadable.FileLike | Uploadable.FromPath | Uploadable.WithMetadata;
6
+
7
+ export namespace Uploadable {
8
+ /**
9
+ * Various file-like objects that can be used to upload a file.
10
+ */
11
+ export type FileLike =
12
+ | ArrayBuffer
13
+ | ArrayBufferLike
14
+ | ArrayBufferView
15
+ | Uint8Array
16
+ | import("buffer").Buffer
17
+ | import("buffer").Blob
18
+ | import("buffer").File
19
+ | import("stream").Readable
20
+ | import("stream/web").ReadableStream
21
+ | globalThis.Blob
22
+ | globalThis.File
23
+ | ReadableStream;
24
+
25
+ /**
26
+ * A file path with optional metadata, used for uploading a file from the file system.
27
+ */
28
+ export type FromPath = {
29
+ /** The path to the file to upload */
30
+ path: string;
31
+ /**
32
+ * Optional override for the file name (defaults to basename of path).
33
+ * This is used to set the `Content-Disposition` header in upload requests.
34
+ */
35
+ filename?: string;
36
+ /**
37
+ * Optional MIME type of the file (e.g., 'image/jpeg', 'text/plain').
38
+ * This is used to set the `Content-Type` header in upload requests.
39
+ */
40
+ contentType?: string;
41
+ /**
42
+ * Optional file size in bytes.
43
+ * If not provided, the file size will be determined from the file system.
44
+ * The content length is used to set the `Content-Length` header in upload requests.
45
+ */
46
+ contentLength?: number;
47
+ };
48
+
49
+ /**
50
+ * A file-like object with metadata, used for uploading files.
51
+ */
52
+ export type WithMetadata = {
53
+ /** The file data */
54
+ data: FileLike;
55
+ /**
56
+ * Optional override for the file name (defaults to basename of path).
57
+ * This is used to set the `Content-Disposition` header in upload requests.
58
+ */
59
+ filename?: string;
60
+ /**
61
+ * Optional MIME type of the file (e.g., 'image/jpeg', 'text/plain').
62
+ * This is used to set the `Content-Type` header in upload requests.
63
+ *
64
+ * If not provided, the content type may be determined from the data itself.
65
+ * * If the data is a `File`, `Blob`, or similar, the content type will be determined from the file itself, if the type is set.
66
+ * * Any other data type will not have a content type set, and the upload request will use `Content-Type: application/octet-stream` instead.
67
+ */
68
+ contentType?: string;
69
+ /**
70
+ * Optional file size in bytes.
71
+ * The content length is used to set the `Content-Length` header in upload requests.
72
+ * If the content length is not provided and cannot be determined, the upload request will not include the `Content-Length` header, but will use `Transfer-Encoding: chunked` instead.
73
+ *
74
+ * If not provided, the file size will be determined depending on the data type.
75
+ * * If the data is of type `fs.ReadStream` (`createReadStream`), the size will be determined from the file system.
76
+ * * If the data is a `Buffer`, `ArrayBuffer`, `Uint8Array`, `Blob`, `File`, or similar, the size will be determined from the data itself.
77
+ * * If the data is a `Readable` or `ReadableStream`, the size will not be determined.
78
+ */
79
+ contentLength?: number;
80
+ };
81
+ }
@@ -125,7 +125,10 @@ export class FormDataWrapper {
125
125
  private async convertToBlob(value: unknown): Promise<Blob> {
126
126
  if (isStreamLike(value) || isReadableStream(value)) {
127
127
  const buffer = await streamToBuffer(value);
128
- return new Blob([buffer]);
128
+ // Create a new Uint8Array to ensure ArrayBuffer compatibility
129
+ const uint8Array = new Uint8Array(buffer.length);
130
+ uint8Array.set(buffer);
131
+ return new Blob([uint8Array]);
129
132
  }
130
133
 
131
134
  if (value instanceof Blob) {
@@ -133,7 +136,10 @@ export class FormDataWrapper {
133
136
  }
134
137
 
135
138
  if (isBuffer(value)) {
136
- return new Blob([value]);
139
+ // Create a new Uint8Array to ensure ArrayBuffer compatibility
140
+ const uint8Array = new Uint8Array(value.length);
141
+ uint8Array.set(value);
142
+ return new Blob([uint8Array]);
137
143
  }
138
144
 
139
145
  if (value instanceof ArrayBuffer) {
@@ -141,7 +147,10 @@ export class FormDataWrapper {
141
147
  }
142
148
 
143
149
  if (isArrayBufferView(value)) {
144
- return new Blob([value]);
150
+ // Create a new Uint8Array to ensure ArrayBuffer compatibility
151
+ const uint8Array = new Uint8Array(value.byteLength);
152
+ uint8Array.set(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
153
+ return new Blob([uint8Array]);
145
154
  }
146
155
 
147
156
  if (typeof value === "string") {
@@ -2,4 +2,4 @@ export * from "./fetcher/index.js";
2
2
  export * from "./runtime/index.js";
3
3
  export * as url from "./url/index.js";
4
4
  export * from "./form-data-utils/index.js";
5
- export * from "./file.js";
5
+ export * as file from "./file/index.js";
@@ -3,6 +3,10 @@ export function join(base: string, ...segments: string[]): string {
3
3
  return "";
4
4
  }
5
5
 
6
+ if (segments.length === 0) {
7
+ return base;
8
+ }
9
+
6
10
  if (base.includes("://")) {
7
11
  let url: URL;
8
12
  try {
@@ -12,6 +16,9 @@ export function join(base: string, ...segments: string[]): string {
12
16
  return joinPath(base, ...segments);
13
17
  }
14
18
 
19
+ const lastSegment = segments[segments.length - 1];
20
+ const shouldPreserveTrailingSlash = lastSegment && lastSegment.endsWith("/");
21
+
15
22
  for (const segment of segments) {
16
23
  const cleanSegment = trimSlashes(segment);
17
24
  if (cleanSegment) {
@@ -19,6 +26,10 @@ export function join(base: string, ...segments: string[]): string {
19
26
  }
20
27
  }
21
28
 
29
+ if (shouldPreserveTrailingSlash && !url.pathname.endsWith("/")) {
30
+ url.pathname += "/";
31
+ }
32
+
22
33
  return url.toString();
23
34
  }
24
35
 
@@ -26,8 +37,15 @@ export function join(base: string, ...segments: string[]): string {
26
37
  }
27
38
 
28
39
  function joinPath(base: string, ...segments: string[]): string {
40
+ if (segments.length === 0) {
41
+ return base;
42
+ }
43
+
29
44
  let result = base;
30
45
 
46
+ const lastSegment = segments[segments.length - 1];
47
+ const shouldPreserveTrailingSlash = lastSegment && lastSegment.endsWith("/");
48
+
31
49
  for (const segment of segments) {
32
50
  const cleanSegment = trimSlashes(segment);
33
51
  if (cleanSegment) {
@@ -35,6 +53,10 @@ function joinPath(base: string, ...segments: string[]): string {
35
53
  }
36
54
  }
37
55
 
56
+ if (shouldPreserveTrailingSlash && !result.endsWith("/")) {
57
+ result += "/";
58
+ }
59
+
38
60
  return result;
39
61
  }
40
62
 
@@ -48,8 +70,11 @@ function joinPathSegments(left: string, right: string): string {
48
70
  function trimSlashes(str: string): string {
49
71
  if (!str) return str;
50
72
 
51
- let start = str.startsWith("/") ? 1 : 0;
52
- let end = str.endsWith("/") ? str.length - 1 : str.length;
73
+ let start = 0;
74
+ let end = str.length;
75
+
76
+ if (str.startsWith("/")) start = 1;
77
+ if (str.endsWith("/")) end = str.length - 1;
53
78
 
54
- return str.slice(start, end);
79
+ return start === 0 && end === str.length ? str : str.slice(start, end);
55
80
  }
@@ -0,0 +1 @@
1
+ export * from "./core/exports.js";
package/src/sdk/index.ts CHANGED
@@ -2,3 +2,4 @@ export * as PlanqkApi from "./api/index.js";
2
2
  export { PlanqkApiError, PlanqkApiTimeoutError } from "./errors/index.js";
3
3
  export { PlanqkApiClient } from "./Client.js";
4
4
  export { PlanqkApiEnvironment } from "./environments.js";
5
+ export * from "./exports.js";