osuny-owl 2.2.0 → 2.3.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "osuny-owl",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Osuny Owl is an object that can go talk to the Osuny API, to create post or other osuny components from a large amount of data",
5
5
  "keywords": ["osuny", "api"],
6
6
  "license": "GPL-3.0",
package/src/OsunyOwl.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import 'dotenv/config';
2
- import { apiPost } from './api/client.js';
2
+ import { apiPost, apiPatch } from './api/client.js';
3
3
 
4
4
  export class OsunyOwl {
5
5
  constructor(website_id, api_url) {
@@ -80,6 +80,30 @@ export class OsunyOwl {
80
80
  }
81
81
  }
82
82
 
83
+ // PATCH d'un projet portfolio existant.
84
+ // `id` peut être l'id numérique OU le migration_identifier du projet.
85
+ // `project` doit contenir le migration_identifier existant (vérifié côté API).
86
+ async patchProjectToOsuny(id, project) {
87
+ if (this.api_key_defined) {
88
+ const url = this.api_url + "/communication/websites/" + this.website_id + "/portfolio/projects/" + id;
89
+ return await apiPatch(url, project, process.env.OSUNY_API_KEY, false);
90
+ } else {
91
+ throw new Error("No API Key Defined");
92
+ }
93
+ }
94
+
95
+ // PATCH d'une actualité (post) existante.
96
+ // `id` peut être l'id numérique OU le migration_identifier du post.
97
+ // `post` doit contenir le migration_identifier existant (vérifié côté API).
98
+ async patchPostToOsuny(id, post) {
99
+ if (this.api_key_defined) {
100
+ const url = this.api_url + "/communication/websites/" + this.website_id + "/posts/" + id;
101
+ return await apiPatch(url, post, process.env.OSUNY_API_KEY, false);
102
+ } else {
103
+ throw new Error("No API Key Defined");
104
+ }
105
+ }
106
+
83
107
  async importImage(img_bdy) {
84
108
  if (this.api_key_defined) {
85
109
  const url = this.api_url + "/communication/medias";
package/src/api/client.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import fetch from 'node-fetch';
2
2
 
3
- export async function apiPost(url, data, apiKey, isFormData = false) {
3
+ async function apiRequest(method, url, data, apiKey, isFormData = false) {
4
4
  const headers = {
5
5
  'X-Osuny-Token': apiKey
6
6
  };
@@ -11,7 +11,7 @@ export async function apiPost(url, data, apiKey, isFormData = false) {
11
11
 
12
12
  try {
13
13
  const response = await fetch(url, {
14
- method: 'POST',
14
+ method,
15
15
  headers,
16
16
  body: isFormData ? data : JSON.stringify(data)
17
17
  });
@@ -24,18 +24,25 @@ export async function apiPost(url, data, apiKey, isFormData = false) {
24
24
  } catch {
25
25
  errorDetails = errorBody;
26
26
  }
27
-
27
+
28
28
  console.error('\x1b[31m=== Erreur API ===\x1b[0m');
29
29
  console.error('Status:', response.status, response.statusText);
30
30
  console.error('Détails:', JSON.stringify(errorDetails, null, 2));
31
-
31
+
32
32
  throw new Error(`Response status: ${response.status} - ${response.statusText}`);
33
33
  }
34
34
 
35
-
36
35
  return await response.json();
37
36
  } catch (error) {
38
37
  console.error(error.message);
39
38
  throw error;
40
39
  }
40
+ }
41
+
42
+ export async function apiPost(url, data, apiKey, isFormData = false) {
43
+ return apiRequest('POST', url, data, apiKey, isFormData);
44
+ }
45
+
46
+ export async function apiPatch(url, data, apiKey, isFormData = false) {
47
+ return apiRequest('PATCH', url, data, apiKey, isFormData);
41
48
  }