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