@rezamirzapour/pod-sdk 1.0.8 → 1.0.10

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