|  | 
|  | 1 | +import { axios } from "@pipedream/platform"; | 
|  | 2 | +import { DOCUMENT_MODE_OPTIONS } from "./common/constants.mjs"; | 
|  | 3 | + | 
| 1 | 4 | export default { | 
| 2 | 5 |   type: "app", | 
| 3 | 6 |   app: "ragie", | 
| 4 |  | -  propDefinitions: {}, | 
|  | 7 | +  propDefinitions: { | 
|  | 8 | +    documentFile: { | 
|  | 9 | +      type: "string", | 
|  | 10 | +      label: "File", | 
|  | 11 | +      description: "The path to the file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#the-tmp-directory).", | 
|  | 12 | +    }, | 
|  | 13 | +    documentMode: { | 
|  | 14 | +      type: "string", | 
|  | 15 | +      label: "Mode", | 
|  | 16 | +      description: "Partition strategy for the document. Options are 'hi_res' or 'fast'.", | 
|  | 17 | +      optional: true, | 
|  | 18 | +      options: DOCUMENT_MODE_OPTIONS, | 
|  | 19 | +    }, | 
|  | 20 | +    partition: { | 
|  | 21 | +      type: "string", | 
|  | 22 | +      label: "Partition", | 
|  | 23 | +      description: "An optional partition identifier. Partitions must be lowercase alphanumeric and may only include the special characters '_' and '-'.", | 
|  | 24 | +    }, | 
|  | 25 | +    documentId: { | 
|  | 26 | +      type: "string", | 
|  | 27 | +      label: "Document ID", | 
|  | 28 | +      description: "The ID of the document to update.", | 
|  | 29 | +      async options({ prevContext }) { | 
|  | 30 | +        const { | 
|  | 31 | +          documents, pagination, | 
|  | 32 | +        } = await this.listDocuments({ | 
|  | 33 | +          params: { | 
|  | 34 | +            cursor: prevContext.cursor, | 
|  | 35 | +          }, | 
|  | 36 | +        }); | 
|  | 37 | +        return { | 
|  | 38 | +          options: documents.map(({ | 
|  | 39 | +            id: value, name: label, | 
|  | 40 | +          }) => ({ | 
|  | 41 | +            label, | 
|  | 42 | +            value, | 
|  | 43 | +          })), | 
|  | 44 | +          context: { | 
|  | 45 | +            cursor: pagination.next_cursor, | 
|  | 46 | +          }, | 
|  | 47 | +        }; | 
|  | 48 | +      }, | 
|  | 49 | +    }, | 
|  | 50 | +  }, | 
| 5 | 51 |   methods: { | 
| 6 |  | -    // this.$auth contains connected account data | 
| 7 |  | -    authKeys() { | 
| 8 |  | -      console.log(Object.keys(this.$auth)); | 
|  | 52 | +    _baseUrl() { | 
|  | 53 | +      return "https://api.ragie.ai"; | 
|  | 54 | +    }, | 
|  | 55 | +    _headers(headers = {}) { | 
|  | 56 | +      return { | 
|  | 57 | +        ...headers, | 
|  | 58 | +        "Authorization": `Bearer ${this.$auth.api_key}`, | 
|  | 59 | +      }; | 
|  | 60 | +    }, | 
|  | 61 | +    _makeRequest({ | 
|  | 62 | +      $ = this, path, headers, ...opts | 
|  | 63 | +    }) { | 
|  | 64 | +      return axios($, { | 
|  | 65 | +        url: this._baseUrl() + path, | 
|  | 66 | +        headers: this._headers(headers), | 
|  | 67 | +        ...opts, | 
|  | 68 | +      }); | 
|  | 69 | +    }, | 
|  | 70 | +    createDocument(opts = {}) { | 
|  | 71 | +      return this._makeRequest({ | 
|  | 72 | +        method: "POST", | 
|  | 73 | +        path: "/documents", | 
|  | 74 | +        ...opts, | 
|  | 75 | +      }); | 
|  | 76 | +    }, | 
|  | 77 | +    listDocuments(opts = {}) { | 
|  | 78 | +      return this._makeRequest({ | 
|  | 79 | +        path: "/documents", | 
|  | 80 | +        params: opts, | 
|  | 81 | +      }); | 
|  | 82 | +    }, | 
|  | 83 | +    updateDocumentFile({ | 
|  | 84 | +      documentId, ...opts | 
|  | 85 | +    }) { | 
|  | 86 | +      return this._makeRequest({ | 
|  | 87 | +        method: "PUT", | 
|  | 88 | +        path: `/documents/${documentId}/file`, | 
|  | 89 | +        ...opts, | 
|  | 90 | +      }); | 
|  | 91 | +    }, | 
|  | 92 | +    listConnections(opts = {}) { | 
|  | 93 | +      return this._makeRequest({ | 
|  | 94 | +        path: "/connections", | 
|  | 95 | +        params: opts, | 
|  | 96 | +      }); | 
|  | 97 | +    }, | 
|  | 98 | +    async *paginate({ | 
|  | 99 | +      fn, params = {}, fieldName, maxResults = null, ...opts | 
|  | 100 | +    }) { | 
|  | 101 | +      let count = 0; | 
|  | 102 | +      let nextCursor; | 
|  | 103 | + | 
|  | 104 | +      do { | 
|  | 105 | +        params.cursor = nextCursor; | 
|  | 106 | +        const { | 
|  | 107 | +          pagination, | 
|  | 108 | +          ...data | 
|  | 109 | +        } = await fn({ | 
|  | 110 | +          params, | 
|  | 111 | +          ...opts, | 
|  | 112 | +        }); | 
|  | 113 | +        const items = data[fieldName]; | 
|  | 114 | + | 
|  | 115 | +        for (const d of items) { | 
|  | 116 | +          yield d; | 
|  | 117 | + | 
|  | 118 | +          if (maxResults && ++count === maxResults) { | 
|  | 119 | +            return count; | 
|  | 120 | +          } | 
|  | 121 | +        } | 
|  | 122 | + | 
|  | 123 | +        nextCursor = pagination?.next_cursor; | 
|  | 124 | +      } while (nextCursor); | 
| 9 | 125 |     }, | 
| 10 | 126 |   }, | 
| 11 | 127 | }; | 
0 commit comments