osuny-owl 2.2.0 → 2.4.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 +6 -3
- package/src/OsunyOwl.js +25 -1
- package/src/api/client.js +12 -5
- package/src/builders/blocks/embed.js +16 -0
- package/src/builders/blocks/index.js +2 -1
- package/src/builders/index.js +1 -0
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "osuny-owl",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.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
|
-
"keywords": [
|
|
5
|
+
"keywords": [
|
|
6
|
+
"osuny",
|
|
7
|
+
"api"
|
|
8
|
+
],
|
|
6
9
|
"license": "GPL-3.0",
|
|
7
10
|
"author": "Sacha André",
|
|
8
11
|
"type": "module",
|
|
@@ -14,4 +17,4 @@
|
|
|
14
17
|
"dotenv": "^16.5.0",
|
|
15
18
|
"node-fetch": "^3.3.2"
|
|
16
19
|
}
|
|
17
|
-
}
|
|
20
|
+
}
|
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
|
-
|
|
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
|
|
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
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function createEmbed(code, transcription, migration_identifier, position, title = "", transcription_title = "") {
|
|
2
|
+
return {
|
|
3
|
+
"id": null,
|
|
4
|
+
"migration_identifier": migration_identifier,
|
|
5
|
+
"template_kind": "embed",
|
|
6
|
+
"title": title,
|
|
7
|
+
"position": position,
|
|
8
|
+
"published": true,
|
|
9
|
+
"html_class": null,
|
|
10
|
+
"data": {
|
|
11
|
+
"code": code,
|
|
12
|
+
"transcription": transcription,
|
|
13
|
+
"transcription_title": transcription_title
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -3,4 +3,5 @@ export { createChapter } from './chapter.js';
|
|
|
3
3
|
export { createDatatable } from './datatable.js';
|
|
4
4
|
export { createVideo } from './video.js';
|
|
5
5
|
export { createImage } from './image.js';
|
|
6
|
-
export { createTimeline } from './timeline.js';
|
|
6
|
+
export { createTimeline } from './timeline.js';
|
|
7
|
+
export { createEmbed } from './embed.js';
|
package/src/builders/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export class OsunyUtility {
|
|
|
15
15
|
static createVideo = blocks.createVideo;
|
|
16
16
|
static createImage = blocks.createImage;
|
|
17
17
|
static createTimeline = blocks.createTimeline;
|
|
18
|
+
static createEmbed = blocks.createEmbed;
|
|
18
19
|
static createPost = createPost;
|
|
19
20
|
static createProject = createProject;
|
|
20
21
|
static composePost = composePost;
|