@examplary/sdk 2.2.0 → 2.3.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/dist/index.mjs CHANGED
@@ -88,6 +88,36 @@ var request = async (ctx, method, pathTemplate, pathKeys, queryKeys, hasBody, ar
88
88
  return response.data;
89
89
  };
90
90
 
91
+ // src/overrides/media.upload.ts
92
+ var override = async (ctx, args, options) => {
93
+ const contentType = args.contentType ?? "application/octet-stream";
94
+ const { data } = await ctx.axios.request({
95
+ ...options,
96
+ method: "GET",
97
+ url: "/media/upload",
98
+ params: {
99
+ contentType,
100
+ ...args.filename ? { filename: args.filename } : {},
101
+ ...args.type ? { type: args.type } : {}
102
+ }
103
+ });
104
+ if (args.content) {
105
+ const body = typeof Buffer !== "undefined" && !Buffer.isBuffer(args.content) ? Buffer.from(args.content) : args.content;
106
+ const uploadRes = await fetch(data.uploadUrl, {
107
+ method: "PUT",
108
+ headers: { "Content-Type": contentType },
109
+ body
110
+ });
111
+ if (!uploadRes.ok) {
112
+ throw new ExamplaryError(
113
+ `Upload failed: ${await uploadRes.text()}`,
114
+ "UploadError"
115
+ );
116
+ }
117
+ }
118
+ return data;
119
+ };
120
+
91
121
  // generated/sdk.ts
92
122
  var QuestionTypes = class {
93
123
  constructor(ctx) {
@@ -240,9 +270,15 @@ var Media = class {
240
270
  constructor(ctx) {
241
271
  this.ctx = ctx;
242
272
  }
243
- upload(arg, options) {
244
- const args = arg;
245
- return request(this.ctx, "GET", "/media/upload", [], ["filename", "type", "contentType"], false, args, options);
273
+ /**
274
+ * Get file upload URL
275
+ *
276
+ * Returns a signed URL for uploading a file, and a public URL for accessing it afterwards.
277
+ *
278
+ * API endpoint: `GET /media/upload`
279
+ */
280
+ upload(args, options) {
281
+ return override(this.ctx, args, options);
246
282
  }
247
283
  };
248
284
  var OrgCustomDomain = class {