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