freelancer-kit 1.0.0 → 1.0.1

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.
Files changed (3) hide show
  1. package/README.md +219 -0
  2. package/package.json +2 -1
  3. package/src/index.js +0 -2
package/README.md ADDED
@@ -0,0 +1,219 @@
1
+ # Freelancer Kit 🚀
2
+
3
+ [![MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
4
+ [![JavaScript](https://img.shields.io/badge/Language-JavaScript-yellow.svg)](https://www.javascript.com/)
5
+
6
+ This repository provides a comprehensive JavaScript toolkit for interacting with the Freelancer API. Designed for Node.js environments, it simplifies common tasks such as authentication, profile management, and project searching.
7
+
8
+ ## Features ✨
9
+
10
+ * **Authentication:** Securely authenticate with the Freelancer API using OAuth 2.0.
11
+ * **Token Management:** Easily handle access and refresh tokens for persistent API access.
12
+ * **Profile Retrieval:** Fetch and manage your Freelancer profile information.
13
+ * **Project Searching:** Efficiently search for projects based on various criteria.
14
+
15
+ ## Installation 📥
16
+
17
+ You can install `freelancer-kit` directly from npm:
18
+
19
+ ```bash
20
+ npm install freelancer-kit
21
+ ```
22
+
23
+ Alternatively, if you are developing locally or wish to contribute, you can clone the repository and install dependencies:
24
+
25
+ ```bash
26
+ git clone https://github.com/Murtesa-developer/freelancer-kit.git
27
+ cd freelancer-kit
28
+ npm install
29
+ ```
30
+
31
+ ## Usage Examples 💡
32
+
33
+ ### Authentication Example
34
+
35
+ ```javascript
36
+ const FreelancerAuth = require('freelancer-kit').FreelancerAuth;
37
+
38
+ const auth = new FreelancerAuth({
39
+ clientId: 'YOUR_CLIENT_ID',
40
+ clientSecret: 'YOUR_CLIENT_SECRET',
41
+ redirectUri: 'YOUR_REDIRECT_URI'
42
+ });
43
+
44
+ // Get authorization URL
45
+ const authorizationUrl = auth.getAuthorizationUrl(['email', 'profile']);
46
+ console.log('Please visit this URL to authorize:', authorizationUrl);
47
+
48
+ // After user authorizes, you'll receive a code. Exchange it for tokens.
49
+ // Assuming you have the authorization code:
50
+ async function exchangeCodeForToken(code) {
51
+ try {
52
+ const tokens = await auth.exchangeCodeForToken(code);
53
+ console.log('Access Token:', tokens.access_token);
54
+ console.log('Refresh Token:', tokens.refresh_token);
55
+ // Store tokens securely
56
+ } catch (error) {
57
+ console.error('Error exchanging code for token:', error);
58
+ }
59
+ }
60
+
61
+ // Example of refreshing a token
62
+ async function refreshTokenExample(refreshToken) {
63
+ try {
64
+ const newTokens = await auth.refreshToken(refreshToken);
65
+ console.log('New Access Token:', newTokens.access_token);
66
+ // Update stored tokens
67
+ } catch (error) {
68
+ console.error('Error refreshing token:', error);
69
+ }
70
+ }
71
+ ```
72
+
73
+ ### Self Profile Example
74
+
75
+ ```javascript
76
+ const SelfProfile = require('freelancer-kit').SelfProfile;
77
+ const FreelancerAuth = require('freelancer-kit').FreelancerAuth; // Needed for token management
78
+
79
+ // Assuming you have obtained and stored your access token
80
+ const accessToken = 'YOUR_STORED_ACCESS_TOKEN';
81
+
82
+ async function getProfile() {
83
+ try {
84
+ const profile = new SelfProfile(accessToken);
85
+ const userProfile = await profile.getProfile();
86
+ console.log('User Profile:', userProfile);
87
+ } catch (error) {
88
+ console.error('Error fetching profile:', error);
89
+ }
90
+ }
91
+
92
+ getProfile();
93
+ ```
94
+
95
+ ### Search Projects Example
96
+
97
+ ```javascript
98
+ const SearchProjects = require('freelancer-kit').SearchProjects;
99
+ const FreelancerAuth = require('freelancer-kit').FreelancerAuth; // Needed for token management
100
+
101
+ // Assuming you have obtained and stored your access token
102
+ const accessToken = 'YOUR_STORED_ACCESS_TOKEN';
103
+
104
+ async function searchProjects() {
105
+ try {
106
+ const searcher = new SearchProjects(accessToken);
107
+ const projects = await searcher.search({
108
+ limit: 10,
109
+ full_description: 1,
110
+ query: 'web development'
111
+ });
112
+ console.log('Found Projects:', projects);
113
+ } catch (error) {
114
+ console.error('Error searching projects:', error);
115
+ }
116
+ }
117
+
118
+ searchProjects();
119
+ ```
120
+
121
+ ## Contributing 🤝
122
+
123
+ We welcome contributions to `freelancer-kit`! Please follow these guidelines:
124
+
125
+ 1. **Fork the repository.**
126
+ 2. **Create a new branch** for your feature or bug fix.
127
+ 3. **Make your changes** and ensure they are well-documented.
128
+ 4. **Add tests** for your new functionality.
129
+ 5. **Submit a Pull Request** with a clear description of your changes.
130
+
131
+ Please ensure your code adheres to the existing style and formatting.
132
+
133
+ ## License 📜
134
+
135
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
136
+
137
+ ## API Documentation 📚
138
+
139
+ The `freelancer-kit` library exposes several classes to interact with the Freelancer API.
140
+
141
+ ### `FreelancerAuth` 🔐
142
+
143
+ Handles authentication and token management.
144
+
145
+ **Constructor:**
146
+
147
+ ```javascript
148
+ new FreelancerAuth(options: {
149
+ clientId: string;
150
+ clientSecret: string;
151
+ redirectUri: string;
152
+ })
153
+ ```
154
+
155
+ **Methods:**
156
+
157
+ * `getAuthorizationUrl(scopes: string[]): string`
158
+ * Generates the OAuth 2.0 authorization URL.
159
+ * `exchangeCodeForToken(code: string): Promise<TokenResponse>`
160
+ * Exchanges an authorization code for an access token and refresh token.
161
+ * `refreshToken(refreshToken: string): Promise<TokenResponse>`
162
+ * Refreshes an expired access token using a refresh token.
163
+
164
+ ### `SearchProjects` 🔍
165
+
166
+ Facilitates searching for projects.
167
+
168
+ **Constructor:**
169
+
170
+ ```javascript
171
+ new SearchProjects(accessToken: string)
172
+ ```
173
+
174
+ **Methods:**
175
+
176
+ * `search(params: SearchParams): Promise<Project[]>`
177
+ * Searches for projects.
178
+ * `SearchParams` can include:
179
+ * `limit`: Maximum number of results.
180
+ * `full_description`: Whether to include full project descriptions (1 for yes, 0 for no).
181
+ * `query`: Search term.
182
+ * `page`: Page number for results.
183
+ * `sort_field`: Field to sort by (e.g., 'time_left', 'budget').
184
+ * `sort_order`: Sort order ('asc' or 'desc').
185
+ * `min_budget`: Minimum budget for projects.
186
+ * `max_budget`: Maximum budget for projects.
187
+ * `category_id`: Filter by category ID.
188
+
189
+ ### `SelfProfile` 👤
190
+
191
+ Provides access to the authenticated user's profile.
192
+
193
+ **Constructor:**
194
+
195
+ ```javascript
196
+ new SelfProfile(accessToken: string)
197
+ ```
198
+
199
+ **Methods:**
200
+
201
+ * `getProfile(): Promise<UserProfile>`
202
+ * Fetches the authenticated user's profile information.
203
+
204
+ ## Configuration Options & Environment Variables ⚙️
205
+
206
+ While the library can be configured directly via constructor options, it's recommended to use environment variables for sensitive information like API keys and secrets.
207
+
208
+ * `FREELANCER_CLIENT_ID`: Your Freelancer API Client ID.
209
+ * `FREELANCER_CLIENT_SECRET`: Your Freelancer API Client Secret.
210
+ * `FREELANCER_REDIRECT_URI`: Your registered Redirect URI.
211
+
212
+ When using these environment variables, you can instantiate classes without passing explicit options:
213
+
214
+ ```javascript
215
+ // Example using environment variables for FreelancerAuth
216
+ const auth = new FreelancerAuth(); // Reads from process.env.FREELANCER_CLIENT_ID, etc.
217
+ ```
218
+
219
+ ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "freelancer-kit",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Unofficial Node.js toolkit for integrating with the Freelancer.com API",
5
5
  "author": "MURTESA",
6
6
  "license": "MIT",
@@ -18,6 +18,7 @@
18
18
  "node": ">=14"
19
19
  },
20
20
  "dependencies": {
21
+ "freelancer-kit": "^1.0.0",
21
22
  "node-fetch": "^2.7.0"
22
23
  }
23
24
  }
package/src/index.js CHANGED
@@ -2,7 +2,6 @@ const SelfProfile = require("./classes/SelfProfile");
2
2
  const Token = require("./classes/Token");
3
3
  const SearchProjects = require("./classes/SearchProjects");
4
4
  const FreelancerAuth = require("./classes/FreelancerAuth");
5
- const Bid = require("./classes/Bid")
6
5
 
7
6
 
8
7
  module.exports = {
@@ -10,5 +9,4 @@ module.exports = {
10
9
  Token,
11
10
  SearchProjects,
12
11
  FreelancerAuth,
13
- Bid,
14
12
  };