@rezamirzapour/pod-sdk 1.0.7 → 1.0.9

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.js CHANGED
@@ -256,6 +256,90 @@ var SsoService = class {
256
256
  }
257
257
  }
258
258
  };
259
+ var CaptchaService = class {
260
+ http;
261
+ clientId;
262
+ accessToken;
263
+ constructor(options) {
264
+ this.clientId = options.clientId;
265
+ this.accessToken = options.accessToken;
266
+ this.http = http.createNextHttp({
267
+ baseUrl: options.baseUrl,
268
+ serviceName: "POD-CAPTCHA"
269
+ });
270
+ }
271
+ /**
272
+ * Get a new captcha image
273
+ */
274
+ async get(options) {
275
+ const params = {};
276
+ if (options?.width) params.width = options.width;
277
+ if (options?.height) params.height = options.height;
278
+ if (options?.length) params.length = options.length;
279
+ if (options?.type) params.type = options.type;
280
+ if (options?.format) params.format = options.format;
281
+ if (options?.noise !== void 0) params.noise = options.noise;
282
+ if (options?.bgColor) params.bgColor = options.bgColor;
283
+ if (options?.fontColor) params.fontColor = options.fontColor;
284
+ if (options?.fontSize) params.fontSize = options.fontSize;
285
+ try {
286
+ const result = await this.http.post(
287
+ "/api/core/captchas/generate",
288
+ void 0,
289
+ {
290
+ params,
291
+ headers: {
292
+ "Content-Type": "application/json",
293
+ Accept: "application/json",
294
+ "Client-Id": this.clientId,
295
+ "Access-Token": this.accessToken
296
+ }
297
+ }
298
+ );
299
+ return {
300
+ hasError: false,
301
+ result
302
+ };
303
+ } catch (err) {
304
+ return {
305
+ hasError: true,
306
+ message: err.data?.message || err.message,
307
+ errorCode: err.status
308
+ };
309
+ }
310
+ }
311
+ /**
312
+ * Check if the entered captcha value is valid
313
+ */
314
+ async check(captchaId, options) {
315
+ try {
316
+ const result = await this.http.post(
317
+ `/api/core/captchas/check/${captchaId}`,
318
+ {
319
+ captchaValue: options.captchaValue
320
+ },
321
+ {
322
+ headers: {
323
+ "Content-Type": "application/json",
324
+ Accept: "application/json",
325
+ "Client-Id": this.clientId,
326
+ "Access-Token": this.accessToken
327
+ }
328
+ }
329
+ );
330
+ return {
331
+ hasError: false,
332
+ result
333
+ };
334
+ } catch (err) {
335
+ return {
336
+ hasError: true,
337
+ message: err.data?.message || err.message,
338
+ errorCode: err.status
339
+ };
340
+ }
341
+ }
342
+ };
259
343
 
260
344
  // src/services/customPost/crud.ts
261
345
  var CustomPostCrudService = class {
@@ -2171,41 +2255,260 @@ var PodspaceService = class {
2171
2255
  };
2172
2256
  var PodFormService = class {
2173
2257
  http;
2174
- apiToken;
2175
2258
  revalidate;
2176
2259
  constructor(options) {
2177
- this.apiToken = options.apiToken || "";
2178
2260
  this.revalidate = Number(options.revalidate) || 0;
2179
- this.http = http.createNextHttp({
2261
+ this.http = options.http || http.createNextHttp({
2180
2262
  baseUrl: options.baseUrl,
2181
2263
  serviceName: "POD-PodForm",
2182
2264
  headers: {
2183
- token: this.apiToken,
2265
+ ...options.apiToken ? { token: options.apiToken } : {},
2184
2266
  accept: "*/*"
2185
2267
  }
2186
2268
  });
2187
2269
  }
2270
+ requestOptions(options = {}, headers = {}) {
2271
+ const next = this.revalidate ? { revalidate: this.revalidate, ...options.next || {} } : options.next;
2272
+ return {
2273
+ ...options,
2274
+ headers: { ...headers, ...options.headers },
2275
+ ...next ? { next } : {}
2276
+ };
2277
+ }
2278
+ languageHeaders(language = "fa") {
2279
+ return { "Accept-Language": language, "Content-Type": "application/json" };
2280
+ }
2281
+ /** Retrieves a form by its numeric ID. Swagger: GET `/forms/{formId}`. */
2282
+ async getForm(formId, params = {}, options = {}) {
2283
+ return this.http.get(`/forms/${formId}`, this.requestOptions({
2284
+ ...options,
2285
+ params: { ...options.params || {}, lockForEdit: params.lockForEdit ?? false }
2286
+ }, { "Content-Type": "application/json" }));
2287
+ }
2288
+ /** Backward-compatible alias for `getForm`. */
2289
+ async getPodformById(id, options = {}) {
2290
+ return this.getForm(id, { lockForEdit: false }, options);
2291
+ }
2292
+ /** Lists forms with the filters supported by Swagger. */
2293
+ async getForms(params = {}, options = {}) {
2294
+ return this.http.get("/forms/all", this.requestOptions({ ...options, params }, {
2295
+ "Content-Type": "application/json"
2296
+ }));
2297
+ }
2298
+ /** Creates a form. Swagger: POST `/forms`. */
2299
+ async createForm(data, language = "fa", options = {}) {
2300
+ return this.http.post("/forms", data, this.requestOptions(options, this.languageHeaders(language)));
2301
+ }
2302
+ /** Updates a form. Swagger: PATCH `/forms/{formId}`. */
2303
+ async updateForm(formId, data, options = {}) {
2304
+ return this.http.patch(`/forms/${formId}`, data, this.requestOptions(options, {
2305
+ "Content-Type": "application/json"
2306
+ }));
2307
+ }
2308
+ /** Deletes a form (or moves it to trash). */
2309
+ async deleteForm(formId, params = {}, options = {}) {
2310
+ return this.http.delete(`/forms/${formId}`, this.requestOptions({ ...options, params }, {
2311
+ "Content-Type": "application/json"
2312
+ }));
2313
+ }
2314
+ /** Gets form settings. Swagger: GET `/forms/{formId}/settings`. */
2315
+ async getFormSettings(formId, lockForEdit = false, options = {}) {
2316
+ return this.http.get(`/forms/${formId}/settings`, this.requestOptions({
2317
+ ...options,
2318
+ params: { ...options.params || {}, lockForEdit }
2319
+ }, { "Content-Type": "application/json" }));
2320
+ }
2321
+ /** Updates form settings. */
2322
+ async updateFormSettings(formId, data, params = {}, options = {}) {
2323
+ return this.http.patch(`/forms/${formId}/settings`, data, this.requestOptions({ ...options, params }, {
2324
+ "Content-Type": "application/json"
2325
+ }));
2326
+ }
2327
+ /** Adds a field to a form. */
2328
+ async addField(formId, field, language = "fa", options = {}) {
2329
+ return this.http.post(`/forms/${formId}/fields`, field, this.requestOptions(options, this.languageHeaders(language)));
2330
+ }
2331
+ /** Adds multiple fields to a form. */
2332
+ async addFields(formId, fields, language = "fa", options = {}) {
2333
+ return this.http.post(`/forms/${formId}/fields/batch`, fields, this.requestOptions(options, this.languageHeaders(language)));
2334
+ }
2335
+ /** Updates one or more fields. */
2336
+ async updateFields(formId, fields, options = {}) {
2337
+ return this.http.patch(`/forms/${formId}/fields`, fields, this.requestOptions(options, {
2338
+ "Content-Type": "application/json"
2339
+ }));
2340
+ }
2341
+ /** Deletes selected fields from a form. */
2342
+ async deleteFields(formId, fieldIds, options = {}) {
2343
+ return this.http.delete(`/forms/${formId}/fields`, this.requestOptions({
2344
+ ...options,
2345
+ params: { ...options.params || {}, fieldIds }
2346
+ }, { "Content-Type": "application/json" }));
2347
+ }
2348
+ /** Gets a form preview by ID. */
2349
+ async getFormPreview(formId, params = {}, options = {}) {
2350
+ return this.http.get(`/forms/${formId}/preview`, this.requestOptions({ ...options, params }, {
2351
+ "Content-Type": "application/json"
2352
+ }));
2353
+ }
2354
+ /** Gets a public form preview by hash. */
2355
+ async getFormPreviewByHash(formHash, params = {}, options = {}) {
2356
+ return this.http.get(`/forms/${formHash}/previewByHash`, this.requestOptions({ ...options, params }, {
2357
+ "Content-Type": "application/json"
2358
+ }));
2359
+ }
2360
+ /** Generates the captcha associated with a public form. */
2361
+ async generateCaptcha(formHash, options = {}) {
2362
+ return this.http.get(`/forms/${formHash}/generateCaptcha`, this.requestOptions(options, {
2363
+ "Content-Type": "application/json"
2364
+ }));
2365
+ }
2366
+ /** Saves a response using the Swagger JSON contract. */
2367
+ async saveResponse(formHash, data, params = {}, language = "fa", options = {}) {
2368
+ return this.http.post(`/responses/${formHash}`, data, this.requestOptions({ ...options, params }, this.languageHeaders(language)));
2369
+ }
2188
2370
  /**
2189
- * Submits responses/answers to a POD Form.
2371
+ * Backward-compatible response helper. The form identifier can be numeric
2372
+ * or a hash; the payload is now sent as JSON per the official API.
2190
2373
  */
2191
- async sendForm(formId, data) {
2192
- const payload = new URLSearchParams({
2193
- ...data,
2194
- userResponseTimeMilliSeconds: "230000"
2195
- });
2196
- return this.http.post(`/responses/${formId}`, payload, {
2197
- headers: {
2198
- "Content-Type": "application/x-www-form-urlencoded"
2199
- }
2200
- });
2374
+ async sendForm(formHash, data, options = {}) {
2375
+ const payload = { ...data };
2376
+ if (payload.userResponseTimeMilliSeconds === void 0) {
2377
+ payload.userResponseTimeMilliSeconds = 23e4;
2378
+ }
2379
+ return this.saveResponse(String(formHash), payload, {}, "fa", options);
2380
+ }
2381
+ /** Initiates a response before collecting field values. */
2382
+ async initiateResponse(formId, data, language = "fa", options = {}) {
2383
+ return this.http.post(`/responses/${formId}/initiate`, data, this.requestOptions(options, this.languageHeaders(language)));
2384
+ }
2385
+ /** Retrieves responses for a form with filtering and pagination. */
2386
+ async getAllFormResponses(formId, params = {}, options = {}) {
2387
+ return this.http.get(`/responses/all/${formId}`, this.requestOptions({ ...options, params }, {
2388
+ "Content-Type": "application/json"
2389
+ }));
2390
+ }
2391
+ /** Retrieves responses by a public form hash. */
2392
+ async getAllFormResponsesByHash(formHash, params = {}, options = {}) {
2393
+ return this.http.get(`/responses/all/byFormHash/${formHash}`, this.requestOptions({ ...options, params }, {
2394
+ "Content-Type": "application/json"
2395
+ }));
2396
+ }
2397
+ /** Gets an individual response. */
2398
+ async getResponse(responseId, containsNonInputFields = false, options = {}) {
2399
+ return this.http.get(`/responses/${responseId}`, this.requestOptions({
2400
+ ...options,
2401
+ params: { ...options.params || {}, containsNonInputFields }
2402
+ }, { "Content-Type": "application/json" }));
2403
+ }
2404
+ /** Updates fields of an existing response. */
2405
+ async updateResponseFields(responseId, fields, options = {}) {
2406
+ return this.http.patch(`/responses/${responseId}`, fields, this.requestOptions(options, {
2407
+ "Content-Type": "application/json"
2408
+ }));
2409
+ }
2410
+ /** Deletes selected/all responses for a form. */
2411
+ async deleteResponses(formId, data, options = {}) {
2412
+ if (Array.isArray(data)) {
2413
+ return this.http.delete(`/responses/${formId}`, this.requestOptions({ ...options, params: { responseIds: data } }, {
2414
+ "Content-Type": "application/json"
2415
+ }));
2416
+ }
2417
+ return this.http.put(`/responses/${formId}`, data, this.requestOptions(options, {
2418
+ "Content-Type": "application/json"
2419
+ }));
2420
+ }
2421
+ /** Lists templates available to the current user. */
2422
+ async getTemplates(params = {}, options = {}) {
2423
+ return this.http.get("/templates", this.requestOptions({ ...options, params }, {
2424
+ "Content-Type": "application/json"
2425
+ }));
2426
+ }
2427
+ /** Creates a template. */
2428
+ async createTemplate(data, templateOwnership, options = {}) {
2429
+ return this.http.post("/templates", data, this.requestOptions({ ...options, params: { templateOwnership } }, {
2430
+ "Content-Type": "application/json"
2431
+ }));
2432
+ }
2433
+ /** Updates or deletes a template. */
2434
+ async updateTemplate(templateId, data, options = {}) {
2435
+ return this.http.patch(`/templates/${templateId}`, data, this.requestOptions(options, {
2436
+ "Content-Type": "application/json"
2437
+ }));
2438
+ }
2439
+ async deleteTemplate(templateId, options = {}) {
2440
+ return this.http.delete(`/templates/${templateId}`, this.requestOptions(options, {
2441
+ "Content-Type": "application/json"
2442
+ }));
2443
+ }
2444
+ /** Lists or creates folders. */
2445
+ async getFolders(params = {}, options = {}) {
2446
+ return this.http.get("/folders", this.requestOptions({ ...options, params }, {
2447
+ "Content-Type": "application/json"
2448
+ }));
2449
+ }
2450
+ async createFolder(data, options = {}) {
2451
+ return this.http.post("/folders", data, this.requestOptions(options, {
2452
+ "Content-Type": "application/json"
2453
+ }));
2454
+ }
2455
+ async updateFolder(folderId, data, options = {}) {
2456
+ return this.http.patch(`/folders/${folderId}`, data, this.requestOptions(options, {
2457
+ "Content-Type": "application/json"
2458
+ }));
2459
+ }
2460
+ async deleteFolder(folderId, removeFromTrash = false, options = {}) {
2461
+ return this.http.delete(`/folders/${folderId}`, this.requestOptions({ ...options, params: { removeFromTrash } }, {
2462
+ "Content-Type": "application/json"
2463
+ }));
2464
+ }
2465
+ /** Sends or validates a form OTP. */
2466
+ async sendOtp(formHash, params, options = {}) {
2467
+ return this.http.get(`/otp/${formHash}/send`, this.requestOptions({ ...options, params }, {
2468
+ "Content-Type": "application/json"
2469
+ }));
2470
+ }
2471
+ async validateOtp(formHash, params, options = {}) {
2472
+ return this.http.get(`/otp/${formHash}/validate`, this.requestOptions({ ...options, params }, {
2473
+ "Content-Type": "application/json"
2474
+ }));
2475
+ }
2476
+ /** Retrieves the authenticated PodForm user. */
2477
+ async getUser(options = {}) {
2478
+ return this.http.get("/user", this.requestOptions(options, { "Content-Type": "application/json" }));
2479
+ }
2480
+ async getUploadLink(options = {}) {
2481
+ return this.http.get("/user/getUploadLink", this.requestOptions(options, { "Content-Type": "application/json" }));
2482
+ }
2483
+ async getDownloadLink(params, options = {}) {
2484
+ return this.http.get("/user/getDownloadLink", this.requestOptions({ ...options, params }, { "Content-Type": "application/json" }));
2485
+ }
2486
+ /** Gets plans and the current user's plan. */
2487
+ async getPlans(params = {}, options = {}) {
2488
+ return this.http.get("/plans/all", this.requestOptions({ ...options, params }, { "Content-Type": "application/json" }));
2489
+ }
2490
+ async getUserPlan(options = {}) {
2491
+ return this.http.get("/plans", this.requestOptions(options, { "Content-Type": "application/json" }));
2492
+ }
2493
+ /** Exports form responses using the official export endpoint. */
2494
+ async exportResponses(formId, params = {}, options = {}) {
2495
+ return this.http.get(`/responses/${formId}/export`, this.requestOptions({ ...options, params }, { "Content-Type": "application/json" }));
2496
+ }
2497
+ /** Retrieves the statistical report for a form. */
2498
+ async getFormReport(formId, options = {}) {
2499
+ return this.http.get(`/forms/${formId}/reports`, this.requestOptions(options, { "Content-Type": "application/json" }));
2201
2500
  }
2202
2501
  /**
2203
- * Retrieves a form and its questions by ID.
2502
+ * Escape hatch for any newly-added Swagger operation not yet represented by
2503
+ * a convenience method. Authentication and base URL are still applied.
2204
2504
  */
2205
- async getPodformById(id, options) {
2206
- return this.http.get(`/responses/all/${id}`, {
2207
- ...options,
2208
- next: this.revalidate ? { revalidate: this.revalidate, ...options?.next || {} } : options?.next
2505
+ async request(method, path, options = {}) {
2506
+ const { body, ...requestOptions } = options;
2507
+ return this.http.request({
2508
+ ...this.requestOptions(requestOptions),
2509
+ url: path,
2510
+ method,
2511
+ body
2209
2512
  });
2210
2513
  }
2211
2514
  };
@@ -3864,7 +4167,7 @@ var DEFAULT_POD_URLS = {
3864
4167
  notification: "https://api.pod.ir/srv/notification",
3865
4168
  podreport: "https://reporting.pod.ir",
3866
4169
  podspace: "https://podspace.pod.ir",
3867
- podform: "https://podform.pod.ir",
4170
+ podform: "https://podformapi.pod.ir",
3868
4171
  sandboxCms: "http://api.sandpod.ir/srv/cms-sandbox",
3869
4172
  sandboxCmsClient: "https://api.sandpod.ir/srv/cms-sandbox",
3870
4173
  sandboxPodspace: "http://podspace.sandpod.ir",
@@ -3881,7 +4184,7 @@ var SANDBOX_POD_URLS = {
3881
4184
  notification: "https://api.pod.ir/srv/notification",
3882
4185
  podreport: "https://reporting.pod.ir",
3883
4186
  podspace: "http://podspace.sandpod.ir",
3884
- podform: "https://podform.pod.ir",
4187
+ podform: "https://podformapi.sandpod.ir",
3885
4188
  sandboxCms: "http://api.sandpod.ir/srv/cms-sandbox",
3886
4189
  sandboxCmsClient: "https://api.sandpod.ir/srv/cms-sandbox",
3887
4190
  sandboxPodspace: "http://podspace.sandpod.ir",
@@ -3922,6 +4225,7 @@ function resolvePodUrls(urls, sandbox = false) {
3922
4225
  // src/client.ts
3923
4226
  var PodSdk = class {
3924
4227
  sso;
4228
+ captcha;
3925
4229
  customPost;
3926
4230
  podspace;
3927
4231
  podform;
@@ -3949,6 +4253,11 @@ var PodSdk = class {
3949
4253
  websiteUrl: urls.website,
3950
4254
  revalidate
3951
4255
  });
4256
+ this.captcha = new CaptchaService({
4257
+ baseUrl: urls.apiPod,
4258
+ clientId,
4259
+ accessToken: apiToken
4260
+ });
3952
4261
  this.customPost = new CustomPostService({
3953
4262
  baseUrl: urls.apiPod,
3954
4263
  apiToken,
@@ -4000,6 +4309,7 @@ function createPodSdk(config) {
4000
4309
  }
4001
4310
  var client_default = PodSdk;
4002
4311
 
4312
+ exports.CaptchaService = CaptchaService;
4003
4313
  exports.CmsDataFormatter = CmsDataFormatter;
4004
4314
  exports.CmsProductService = CmsProductService;
4005
4315
  exports.CmsService = CmsService;