@nascentdigital/funnel-cms 4.4.4
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/api/AssetClient.d.ts +53 -0
- package/dist/api/AssetClient.js +2 -0
- package/dist/api/AssetUploadClient.d.ts +17 -0
- package/dist/api/AssetUploadClient.js +26 -0
- package/dist/api/AuthClient.d.ts +29 -0
- package/dist/api/AuthClient.js +2 -0
- package/dist/api/ChangeSetClient.d.ts +84 -0
- package/dist/api/ChangeSetClient.js +31 -0
- package/dist/api/CollectionClient.d.ts +187 -0
- package/dist/api/CollectionClient.js +2 -0
- package/dist/api/ContentClient.d.ts +43 -0
- package/dist/api/ContentClient.js +34 -0
- package/dist/api/IAssetApiClient.d.ts +9 -0
- package/dist/api/IAssetApiClient.js +2 -0
- package/dist/api/PageClient.d.ts +264 -0
- package/dist/api/PageClient.js +2 -0
- package/dist/api/SiteClient.d.ts +23 -0
- package/dist/api/SiteClient.js +2 -0
- package/dist/api/SiteConfigClient.d.ts +26 -0
- package/dist/api/SiteConfigClient.js +2 -0
- package/dist/api/UpgradeClient.d.ts +16 -0
- package/dist/api/UpgradeClient.js +2 -0
- package/dist/api/UserClient.d.ts +46 -0
- package/dist/api/UserClient.js +2 -0
- package/dist/api/index.d.ts +11 -0
- package/dist/api/index.js +27 -0
- package/dist/errors/CMSError.d.ts +8 -0
- package/dist/errors/CMSError.js +17 -0
- package/dist/errors/CMSErrors.d.ts +5 -0
- package/dist/errors/CMSErrors.js +36 -0
- package/dist/errors/LinkedDependantsError.d.ts +21 -0
- package/dist/errors/LinkedDependantsError.js +31 -0
- package/dist/errors/LockdownError.d.ts +4 -0
- package/dist/errors/LockdownError.js +12 -0
- package/dist/errors/SlugValidationError.d.ts +21 -0
- package/dist/errors/SlugValidationError.js +23 -0
- package/dist/errors/TranslateReferencesError.d.ts +21 -0
- package/dist/errors/TranslateReferencesError.js +22 -0
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.js +25 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +19 -0
- package/dist/models/Entity.d.ts +14 -0
- package/dist/models/Entity.js +2 -0
- package/dist/models/Environment.d.ts +1 -0
- package/dist/models/Environment.js +2 -0
- package/dist/models/Pagination.d.ts +20 -0
- package/dist/models/Pagination.js +21 -0
- package/dist/models/Privilege.d.ts +57 -0
- package/dist/models/Privilege.js +163 -0
- package/dist/models/Role.d.ts +33 -0
- package/dist/models/Role.js +118 -0
- package/dist/models/SiteConfig.d.ts +14 -0
- package/dist/models/SiteConfig.js +2 -0
- package/dist/models/Upgrade.d.ts +40 -0
- package/dist/models/Upgrade.js +19 -0
- package/dist/models/User.d.ts +41 -0
- package/dist/models/User.js +71 -0
- package/dist/models/Versioned.d.ts +22 -0
- package/dist/models/Versioned.js +45 -0
- package/dist/models/index.d.ts +9 -0
- package/dist/models/index.js +25 -0
- package/dist/strapi/IStrapiContentClient.d.ts +39 -0
- package/dist/strapi/IStrapiContentClient.js +2 -0
- package/dist/strapi/Strapi.d.ts +37 -0
- package/dist/strapi/Strapi.js +156 -0
- package/dist/strapi/StrapiAssetClient.d.ts +11 -0
- package/dist/strapi/StrapiAssetClient.js +143 -0
- package/dist/strapi/StrapiAssetUploadClient.d.ts +6 -0
- package/dist/strapi/StrapiAssetUploadClient.js +109 -0
- package/dist/strapi/StrapiAuthClient.d.ts +9 -0
- package/dist/strapi/StrapiAuthClient.js +64 -0
- package/dist/strapi/StrapiChangeSetClient.d.ts +22 -0
- package/dist/strapi/StrapiChangeSetClient.js +218 -0
- package/dist/strapi/StrapiCollectionClient.d.ts +18 -0
- package/dist/strapi/StrapiCollectionClient.js +610 -0
- package/dist/strapi/StrapiContentClient.d.ts +38 -0
- package/dist/strapi/StrapiContentClient.js +105 -0
- package/dist/strapi/StrapiContentClientFactory.d.ts +13 -0
- package/dist/strapi/StrapiContentClientFactory.js +19 -0
- package/dist/strapi/StrapiPageClient.d.ts +23 -0
- package/dist/strapi/StrapiPageClient.js +882 -0
- package/dist/strapi/StrapiSiteConfigClient.d.ts +8 -0
- package/dist/strapi/StrapiSiteConfigClient.js +50 -0
- package/dist/strapi/StrapiUpgradeClient.d.ts +13 -0
- package/dist/strapi/StrapiUpgradeClient.js +118 -0
- package/dist/strapi/StrapiUserClient.d.ts +17 -0
- package/dist/strapi/StrapiUserClient.js +199 -0
- package/dist/strapi/client.d.ts +1 -0
- package/dist/strapi/client.js +17 -0
- package/dist/strapi/index.d.ts +3 -0
- package/dist/strapi/index.js +19 -0
- package/dist/strapi/models/StrapiAsset.d.ts +10 -0
- package/dist/strapi/models/StrapiAsset.js +16 -0
- package/dist/strapi/models/StrapiData.d.ts +13 -0
- package/dist/strapi/models/StrapiData.js +16 -0
- package/dist/strapi/models/StrapiFile.d.ts +18 -0
- package/dist/strapi/models/StrapiFile.js +2 -0
- package/dist/strapi/models/index.d.ts +3 -0
- package/dist/strapi/models/index.js +19 -0
- package/dist/strapi/serialization/ChangeSetData.d.ts +15 -0
- package/dist/strapi/serialization/ChangeSetData.js +76 -0
- package/dist/strapi/serialization/CollectionData.d.ts +57 -0
- package/dist/strapi/serialization/CollectionData.js +258 -0
- package/dist/strapi/serialization/CollectionSnapshotData.d.ts +16 -0
- package/dist/strapi/serialization/CollectionSnapshotData.js +66 -0
- package/dist/strapi/serialization/PageData.d.ts +126 -0
- package/dist/strapi/serialization/PageData.js +335 -0
- package/dist/strapi/serialization/PageSnapshotData.d.ts +20 -0
- package/dist/strapi/serialization/PageSnapshotData.js +69 -0
- package/dist/strapi/serialization/RoleData.d.ts +5 -0
- package/dist/strapi/serialization/RoleData.js +2 -0
- package/dist/strapi/serialization/SiteConfigData.d.ts +11 -0
- package/dist/strapi/serialization/SiteConfigData.js +23 -0
- package/dist/strapi/serialization/StrapiAssetData.d.ts +17 -0
- package/dist/strapi/serialization/StrapiAssetData.js +39 -0
- package/dist/strapi/serialization/UserData.d.ts +18 -0
- package/dist/strapi/serialization/UserData.js +42 -0
- package/dist/strapi/serialization/VersionData.d.ts +26 -0
- package/dist/strapi/serialization/VersionData.js +88 -0
- package/dist/strapi/serialization/index.d.ts +10 -0
- package/dist/strapi/serialization/index.js +26 -0
- package/dist/strapi/test.d.ts +563 -0
- package/dist/strapi/test.js +1131 -0
- package/package.json +42 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StrapiAssetUploadClient = void 0;
|
|
4
|
+
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
5
|
+
const api_1 = require("../api");
|
|
6
|
+
const models_1 = require("./models");
|
|
7
|
+
// class
|
|
8
|
+
class StrapiAssetUploadClient extends api_1.AssetUploadClient {
|
|
9
|
+
constructor(strapiUrl) {
|
|
10
|
+
// construct base
|
|
11
|
+
super();
|
|
12
|
+
this.strapiUrl = strapiUrl;
|
|
13
|
+
}
|
|
14
|
+
async onUpload({ api, file: blob, brand, type, size, name, description, scope, tags, metadata }) {
|
|
15
|
+
var _a, _b, _c;
|
|
16
|
+
console.debug(`[StrapiAssetUploadClient] creating initial asset for "${name}"`, { type, size, scope, tags, metadata });
|
|
17
|
+
// get existing asset if we're replacing the asset
|
|
18
|
+
let assetRef = await api.createAsset({
|
|
19
|
+
brand,
|
|
20
|
+
type,
|
|
21
|
+
size,
|
|
22
|
+
name,
|
|
23
|
+
description,
|
|
24
|
+
scope,
|
|
25
|
+
tags,
|
|
26
|
+
metadata
|
|
27
|
+
});
|
|
28
|
+
if (!assetRef) {
|
|
29
|
+
throw new funnel_core_1.IllegalStateError(`Unable to create new Asset for "${name}"`);
|
|
30
|
+
}
|
|
31
|
+
console.debug('[StrapiAssetUploadClient] created new asset', assetRef);
|
|
32
|
+
// throw if we don't have a strapi asset
|
|
33
|
+
const { value: partialAsset } = assetRef;
|
|
34
|
+
if (!models_1.StrapiAsset.filter(partialAsset)) {
|
|
35
|
+
console.error('[StrapiAssetUploadClient] invalid asset', assetRef);
|
|
36
|
+
throw new funnel_core_1.IllegalStateError('Asset is missing strapi internals');
|
|
37
|
+
}
|
|
38
|
+
// upload + link asset
|
|
39
|
+
const assetId = assetRef.value.id;
|
|
40
|
+
try {
|
|
41
|
+
// create file submission
|
|
42
|
+
const formData = new FormData();
|
|
43
|
+
formData.append('files', blob);
|
|
44
|
+
formData.append('ref', 'api::asset.asset');
|
|
45
|
+
formData.append('refId', `${partialAsset.__internal.assetId}`);
|
|
46
|
+
formData.append('field', 'file');
|
|
47
|
+
console.debug('[StrapiAssetUploadClient] uploading file', Array.from(formData.entries()));
|
|
48
|
+
// upload file
|
|
49
|
+
const url = new URL('/api/upload', this.strapiUrl);
|
|
50
|
+
url.searchParams.set('funnel_token', (_a = api.token) !== null && _a !== void 0 ? _a : '');
|
|
51
|
+
const response = await fetch(url.href, {
|
|
52
|
+
method: 'POST',
|
|
53
|
+
body: formData
|
|
54
|
+
});
|
|
55
|
+
// handle upload errors (remember we're on the client-side)
|
|
56
|
+
const json = await response.json();
|
|
57
|
+
if (!response.ok || json.error) {
|
|
58
|
+
throw new funnel_core_1.DependencyError('Failed to upload file: ' + ((_c = (_b = json.error) === null || _b === void 0 ? void 0 : _b.message) !== null && _c !== void 0 ? _c : json.statusText));
|
|
59
|
+
}
|
|
60
|
+
const file = json[0];
|
|
61
|
+
console.debug('[StrapiAssetUploadClient] uploaded asset file', file);
|
|
62
|
+
// update asset with missing details
|
|
63
|
+
assetRef = await api.updateAsset(getAssetUpdate({ asset: assetRef.value, file }));
|
|
64
|
+
// return asset
|
|
65
|
+
return assetRef;
|
|
66
|
+
}
|
|
67
|
+
// cleanup on error
|
|
68
|
+
catch (e) {
|
|
69
|
+
console.error('[StrapiAssetUpload] failed to upload asset - deleting file', e);
|
|
70
|
+
// delete zombie
|
|
71
|
+
await api.deleteAsset(assetId);
|
|
72
|
+
// rethrow
|
|
73
|
+
if (e instanceof funnel_core_1.IsometricError) {
|
|
74
|
+
console.error('[StrapiAssetUploadClient] file upload failed', e.message);
|
|
75
|
+
throw e;
|
|
76
|
+
}
|
|
77
|
+
// or create new error
|
|
78
|
+
else {
|
|
79
|
+
console.error('[StrapiAssetUploadClient] asset upload failed for unknown reason', e);
|
|
80
|
+
throw new funnel_core_1.DependencyError('Asset upload failed');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.StrapiAssetUploadClient = StrapiAssetUploadClient;
|
|
86
|
+
function getAssetUpdate({ asset, file }) {
|
|
87
|
+
var _a, _b, _c;
|
|
88
|
+
// create base
|
|
89
|
+
const update = {
|
|
90
|
+
id: asset.id,
|
|
91
|
+
url: file.url,
|
|
92
|
+
};
|
|
93
|
+
// add metadata based on type
|
|
94
|
+
const metadata = Object.assign({}, ((_a = asset.metadata) !== null && _a !== void 0 ? _a : {}));
|
|
95
|
+
const fileType = funnel_core_1.FileType.coerce(asset.type);
|
|
96
|
+
console.debug('[StrapiAssetUploadClient/getAssetUpdate] getting update', { fileType, metadata });
|
|
97
|
+
switch (fileType) {
|
|
98
|
+
case 'image': {
|
|
99
|
+
metadata.thumbUrl = (_c = (_b = file.formats) === null || _b === void 0 ? void 0 : _b.thumbnail) === null || _c === void 0 ? void 0 : _c.url;
|
|
100
|
+
update.metadata = metadata;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
default:
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
console.debug('[StrapiAssetUploadClient/getAssetUpdate] getting update', update);
|
|
107
|
+
// return update
|
|
108
|
+
return update;
|
|
109
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AuthClient } from '../api';
|
|
2
|
+
import type { IStrapiContentClient } from './IStrapiContentClient';
|
|
3
|
+
export declare class StrapiAuthClient implements AuthClient {
|
|
4
|
+
private readonly provider;
|
|
5
|
+
constructor(provider: IStrapiContentClient);
|
|
6
|
+
identify(token: AuthClient.Identify.Args): Promise<AuthClient.Identify.Result>;
|
|
7
|
+
login({ email, password }: AuthClient.Login.Args): Promise<AuthClient.Login.Result>;
|
|
8
|
+
authorize(token: AuthClient.Authorize.Args): Promise<AuthClient.Authorize.Result>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StrapiAuthClient = void 0;
|
|
4
|
+
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
5
|
+
const serialization_1 = require("./serialization");
|
|
6
|
+
// class
|
|
7
|
+
class StrapiAuthClient {
|
|
8
|
+
constructor(provider) {
|
|
9
|
+
this.provider = provider;
|
|
10
|
+
}
|
|
11
|
+
async identify(token) {
|
|
12
|
+
// fetch me
|
|
13
|
+
const { client } = this.provider;
|
|
14
|
+
const response = await client.fetch('/users/me?populate=*', {
|
|
15
|
+
method: 'GET',
|
|
16
|
+
headers: {
|
|
17
|
+
Authorization: `Bearer ${token}`
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
// return undefined if auth failed
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
// create user from response
|
|
25
|
+
const data = await response.json();
|
|
26
|
+
return serialization_1.UserData.deserialize(data);
|
|
27
|
+
}
|
|
28
|
+
async login({ email, password }) {
|
|
29
|
+
// make google authentication request
|
|
30
|
+
const { client } = this.provider;
|
|
31
|
+
const url = new URL('/api/auth/local', client.baseURL);
|
|
32
|
+
const response = await fetch(url.href, {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: { 'Content-Type': 'application/json' },
|
|
35
|
+
body: JSON.stringify({ identifier: email, password })
|
|
36
|
+
});
|
|
37
|
+
// return undefined if auth failed
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
throw new funnel_core_1.NotAuthenticatedError('Invalid email or password');
|
|
40
|
+
}
|
|
41
|
+
// fetch jwt from response
|
|
42
|
+
const { jwt } = await response.json();
|
|
43
|
+
// return jwt
|
|
44
|
+
return jwt;
|
|
45
|
+
}
|
|
46
|
+
async authorize(token) {
|
|
47
|
+
// make google authentication request
|
|
48
|
+
const { client } = this.provider;
|
|
49
|
+
const url = new URL('/api/funnel/google/authenticate', client.baseURL);
|
|
50
|
+
url.searchParams.append('token', token);
|
|
51
|
+
const response = await fetch(url.href, {
|
|
52
|
+
headers: { 'Content-Type': 'application/json' }
|
|
53
|
+
});
|
|
54
|
+
// return undefined if auth failed
|
|
55
|
+
if (!response.ok) {
|
|
56
|
+
throw new funnel_core_1.ArgumentError('Invalid google token');
|
|
57
|
+
}
|
|
58
|
+
// fetch jwt from response
|
|
59
|
+
const { jwt } = await response.json();
|
|
60
|
+
// return jwt
|
|
61
|
+
return jwt;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.StrapiAuthClient = StrapiAuthClient;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Schema } from '@nascentdigital/funnel-core';
|
|
2
|
+
import { ChangeSetClient } from '../api';
|
|
3
|
+
import type { IStrapiContentClient } from './IStrapiContentClient';
|
|
4
|
+
export declare class StrapiChangeSetClient implements ChangeSetClient {
|
|
5
|
+
private readonly provider;
|
|
6
|
+
constructor(provider: IStrapiContentClient);
|
|
7
|
+
resolve({ id, fallbackToGlobal }?: StrapiChangeSetClient.ResolveArgs): Promise<Schema.ChangeSet>;
|
|
8
|
+
current({ brand, groupId }: ChangeSetClient.Current.Args): Promise<ChangeSetClient.Current.Result>;
|
|
9
|
+
listGroups({ brand }: ChangeSetClient.ListGroups.Args): Promise<ChangeSetClient.ListGroups.Result>;
|
|
10
|
+
list({ brand, groupId, scope, pagination }: ChangeSetClient.List.Args): Promise<ChangeSetClient.List.Result>;
|
|
11
|
+
get(changeSetId: ChangeSetClient.Get.Args): Promise<ChangeSetClient.Get.Result>;
|
|
12
|
+
update({ id, name, changes, publishedOn }: ChangeSetClient.Update.Args): Promise<ChangeSetClient.Update.Result>;
|
|
13
|
+
delete(args: ChangeSetClient.Delete.Args): Promise<ChangeSetClient.Delete.Result>;
|
|
14
|
+
commit(changeSetId: ChangeSetClient.Commit.Args): Promise<ChangeSetClient.Commit.Result>;
|
|
15
|
+
revert({ changeSetId, changeIds }: ChangeSetClient.Revert.Args): Promise<ChangeSetClient.Revert.Result>;
|
|
16
|
+
}
|
|
17
|
+
export declare namespace StrapiChangeSetClient {
|
|
18
|
+
type ResolveArgs = {
|
|
19
|
+
id?: Schema.ChangeSet.Id;
|
|
20
|
+
fallbackToGlobal?: boolean;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.StrapiChangeSetClient = void 0;
|
|
15
|
+
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
16
|
+
const serialization_1 = require("./serialization");
|
|
17
|
+
const Strapi_1 = require("./Strapi");
|
|
18
|
+
// class
|
|
19
|
+
class StrapiChangeSetClient {
|
|
20
|
+
constructor(provider) {
|
|
21
|
+
this.provider = provider;
|
|
22
|
+
}
|
|
23
|
+
async resolve({ id, fallbackToGlobal = false } = {}) {
|
|
24
|
+
// get specific changeset
|
|
25
|
+
let changeSetData;
|
|
26
|
+
if (id) {
|
|
27
|
+
try {
|
|
28
|
+
changeSetData = await this.get(id);
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
// fallback if allowed
|
|
32
|
+
if (fallbackToGlobal) {
|
|
33
|
+
changeSetData = await this.current({ brand: funnel_core_1.AppConfig.brand() });
|
|
34
|
+
}
|
|
35
|
+
// or throw
|
|
36
|
+
else {
|
|
37
|
+
throw funnel_core_1.IsometricErrorUtils.coerceError(e);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// or resolve current changeset (might create one)
|
|
42
|
+
else {
|
|
43
|
+
changeSetData = await this.current({ brand: funnel_core_1.AppConfig.brand() });
|
|
44
|
+
}
|
|
45
|
+
// convert to change set instance
|
|
46
|
+
return new funnel_core_1.Schema.ChangeSet(changeSetData);
|
|
47
|
+
}
|
|
48
|
+
async current({ brand, groupId = funnel_core_1.Schema.ChangeSet.GroupId.global }) {
|
|
49
|
+
// get latest changeset
|
|
50
|
+
const client = this.provider.client;
|
|
51
|
+
const collection = client.collection('change-sets');
|
|
52
|
+
let { data: [changeSetData] } = await collection.find({
|
|
53
|
+
filters: {
|
|
54
|
+
$and: [
|
|
55
|
+
{ brand: { $eq: brand } },
|
|
56
|
+
{ groupId: { $eq: groupId } },
|
|
57
|
+
{ publishedOn: { $null: true } }
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
sort: ['updatedAt:desc'],
|
|
61
|
+
pagination: {
|
|
62
|
+
start: 0,
|
|
63
|
+
limit: 1
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
// create change set if it doesn't exist
|
|
67
|
+
if (!changeSetData) {
|
|
68
|
+
// create new changeset
|
|
69
|
+
const { data } = await collection.create(Object.assign({}, (serialization_1.ChangeSetData.serialize({
|
|
70
|
+
brand: funnel_core_1.AppConfig.brand(),
|
|
71
|
+
name: groupId === '__global' ? 'Global' : funnel_core_1.StringUtils.capitalize(groupId),
|
|
72
|
+
groupId
|
|
73
|
+
}))));
|
|
74
|
+
// capture new changeset
|
|
75
|
+
changeSetData = data;
|
|
76
|
+
}
|
|
77
|
+
// return new changeset
|
|
78
|
+
return serialization_1.ChangeSetData.deserialize(changeSetData);
|
|
79
|
+
}
|
|
80
|
+
async listGroups({ brand }) {
|
|
81
|
+
// fetch data
|
|
82
|
+
const data = await this.provider.customRequest({
|
|
83
|
+
command: 'changeset/query',
|
|
84
|
+
params: { brand }
|
|
85
|
+
});
|
|
86
|
+
console.debug('[StrapiChangeSetClient] listing groups', data);
|
|
87
|
+
// return deserialized
|
|
88
|
+
return data.map((_a) => {
|
|
89
|
+
var { latest } = _a, data = __rest(_a, ["latest"]);
|
|
90
|
+
return (Object.assign(Object.assign({}, data), { latest: serialization_1.ChangeSetData.deserialize(latest) }));
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async list({ brand, groupId, scope = 'all', pagination }) {
|
|
94
|
+
// create filters
|
|
95
|
+
const filters = [
|
|
96
|
+
{ brand: { $eq: brand } }
|
|
97
|
+
];
|
|
98
|
+
if (groupId) {
|
|
99
|
+
filters.push({ groupId: { $eq: groupId } });
|
|
100
|
+
}
|
|
101
|
+
if (scope !== 'all') {
|
|
102
|
+
filters.push(scope === 'published'
|
|
103
|
+
? { publishedOn: { $notNull: true } }
|
|
104
|
+
: { publishedOn: { $null: true } });
|
|
105
|
+
}
|
|
106
|
+
// fetch items
|
|
107
|
+
const { client } = this.provider;
|
|
108
|
+
const collection = client.collection('change-sets');
|
|
109
|
+
const _a = await Strapi_1.Strapi.paginate({
|
|
110
|
+
collection,
|
|
111
|
+
pagination,
|
|
112
|
+
filters: filters.length === 1
|
|
113
|
+
? filters[0]
|
|
114
|
+
: { $and: filters },
|
|
115
|
+
sort: ['updatedAt:desc']
|
|
116
|
+
}), { items } = _a, paginated = __rest(_a, ["items"]);
|
|
117
|
+
// transform and return them
|
|
118
|
+
return Object.assign({ items: items
|
|
119
|
+
.map(data => serialization_1.ChangeSetData.deserialize(data)) }, paginated);
|
|
120
|
+
}
|
|
121
|
+
async get(changeSetId) {
|
|
122
|
+
// fetch changeset
|
|
123
|
+
const client = this.provider.client;
|
|
124
|
+
const collection = client.collection('change-sets');
|
|
125
|
+
const { data } = await collection.findOne(changeSetId);
|
|
126
|
+
// throw if it isn't found
|
|
127
|
+
if (!data) {
|
|
128
|
+
throw new funnel_core_1.NotFoundError();
|
|
129
|
+
}
|
|
130
|
+
// or return changeset
|
|
131
|
+
return serialization_1.ChangeSetData.deserialize(data);
|
|
132
|
+
}
|
|
133
|
+
async update({ id, name, changes, publishedOn }) {
|
|
134
|
+
// fetch changeset
|
|
135
|
+
const client = this.provider.client;
|
|
136
|
+
const collection = client.collection('change-sets');
|
|
137
|
+
const { data } = await collection.update(id, {
|
|
138
|
+
name,
|
|
139
|
+
changes,
|
|
140
|
+
errors: changes === null || changes === void 0 ? void 0 : changes.some(change => change.errors),
|
|
141
|
+
publishedOn: publishedOn === null || publishedOn === void 0 ? void 0 : publishedOn.toString()
|
|
142
|
+
});
|
|
143
|
+
// return update
|
|
144
|
+
return serialization_1.ChangeSetData.deserialize(data);
|
|
145
|
+
}
|
|
146
|
+
async delete(args) {
|
|
147
|
+
throw new funnel_core_1.NotImplementedError();
|
|
148
|
+
}
|
|
149
|
+
async commit(changeSetId) {
|
|
150
|
+
// fetch changeset
|
|
151
|
+
const changeSet = await this.resolve({ id: changeSetId });
|
|
152
|
+
const { pageChanges, collectionChanges, assetChanges, errors, publishedOn } = changeSet;
|
|
153
|
+
// throw if changeset is already published
|
|
154
|
+
if (publishedOn) {
|
|
155
|
+
throw new funnel_core_1.ConflictError('ChangeSet already published');
|
|
156
|
+
}
|
|
157
|
+
// throw if changeset is empty (shouldn't happen)
|
|
158
|
+
else if (pageChanges.length === 0 && collectionChanges.length === 0) {
|
|
159
|
+
throw new funnel_core_1.NotFoundError('No changes to publish in ChangeSet');
|
|
160
|
+
}
|
|
161
|
+
// or throw if changeset has errors
|
|
162
|
+
else if (errors) {
|
|
163
|
+
throw new funnel_core_1.DependencyError('Cannot publish ChangeSet with errors');
|
|
164
|
+
}
|
|
165
|
+
// try to publish
|
|
166
|
+
try {
|
|
167
|
+
// publish changeset (transactional)
|
|
168
|
+
const data = await this.provider.customRequest({
|
|
169
|
+
command: 'changeset/commit',
|
|
170
|
+
method: 'POST',
|
|
171
|
+
params: { changeSetId }
|
|
172
|
+
});
|
|
173
|
+
console.debug('[StrapiChangeSetClient] publish complete:', data);
|
|
174
|
+
// update changeset
|
|
175
|
+
return serialization_1.ChangeSetData.deserialize(data);
|
|
176
|
+
}
|
|
177
|
+
// handle errors
|
|
178
|
+
catch (e) {
|
|
179
|
+
throw funnel_core_1.IsometricErrorUtils.coerceError(e);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async revert({ changeSetId, changeIds = [] }) {
|
|
183
|
+
// fetch changeset
|
|
184
|
+
const changeSet = await this.resolve({ id: changeSetId });
|
|
185
|
+
const { pageChanges, collectionChanges, publishedOn } = changeSet;
|
|
186
|
+
// throw if changeset is already published
|
|
187
|
+
if (publishedOn) {
|
|
188
|
+
throw new funnel_core_1.InvalidOperationError('Cannot revert changes of published ChangeSet');
|
|
189
|
+
}
|
|
190
|
+
// throw if changeset is empty (shouldn't happen)
|
|
191
|
+
else if (pageChanges.length === 0 && collectionChanges.length === 0) {
|
|
192
|
+
throw new funnel_core_1.NotFoundError('No changes to in ChangeSet to revert');
|
|
193
|
+
}
|
|
194
|
+
// or throw if a change isn't found in the set
|
|
195
|
+
else if (changeIds.length > 0
|
|
196
|
+
&& !changeIds.some(changeId => pageChanges.some(change => change.id === changeId)
|
|
197
|
+
|| collectionChanges.some(change => change.id === changeId))) {
|
|
198
|
+
throw new RangeError('Some changes don\'t exist in the ChangeSet');
|
|
199
|
+
}
|
|
200
|
+
// try to revert
|
|
201
|
+
try {
|
|
202
|
+
// revert changeset (transactional)
|
|
203
|
+
const data = await this.provider.customRequest({
|
|
204
|
+
command: 'changeset/revert',
|
|
205
|
+
method: 'POST',
|
|
206
|
+
params: { changeSetId },
|
|
207
|
+
data: JSON.stringify(changeIds)
|
|
208
|
+
});
|
|
209
|
+
// update changeset
|
|
210
|
+
return data ? serialization_1.ChangeSetData.deserialize(data) : false;
|
|
211
|
+
}
|
|
212
|
+
// handle errors
|
|
213
|
+
catch (e) {
|
|
214
|
+
throw funnel_core_1.IsometricErrorUtils.coerceError(e);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.StrapiChangeSetClient = StrapiChangeSetClient;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CollectionClient } from '../api';
|
|
2
|
+
import type { IStrapiContentClient } from './IStrapiContentClient';
|
|
3
|
+
export declare class StrapiCollectionClient implements CollectionClient {
|
|
4
|
+
private readonly provider;
|
|
5
|
+
constructor(provider: IStrapiContentClient);
|
|
6
|
+
getOverview({ brand, version }: CollectionClient.GetOverview.Args): Promise<CollectionClient.GetOverview.Result>;
|
|
7
|
+
getItems({ brand, type, language, tags, version }: CollectionClient.GetItems.Args): Promise<CollectionClient.GetItems.Result>;
|
|
8
|
+
find({ pagination, ...args }: CollectionClient.Find.Args): Promise<CollectionClient.Find.Result>;
|
|
9
|
+
getGroup({ version, type, brand, groupId, language }: CollectionClient.GetGroup.Args): Promise<CollectionClient.GetGroup.Result>;
|
|
10
|
+
get({ version, id }: CollectionClient.Get.Args): Promise<CollectionClient.Get.Result>;
|
|
11
|
+
create(args: CollectionClient.Create.Args): Promise<CollectionClient.Create.Result>;
|
|
12
|
+
duplicate({ source: collectionId, targetCollection, targetLanguage }: CollectionClient.Duplicate.Args): Promise<CollectionClient.Duplicate.Result>;
|
|
13
|
+
update({ id: collectionId, errors, updates }: CollectionClient.Update.Args): Promise<CollectionClient.Update.Result>;
|
|
14
|
+
replace({ updatedCollection, version, skipSync }: CollectionClient.Replace.Args): Promise<CollectionClient.Replace.Result>;
|
|
15
|
+
unpublish(collectionId: CollectionClient.Unpublish.Args): Promise<CollectionClient.Unpublish.Result>;
|
|
16
|
+
getDependants({ id: collectionId, version }: CollectionClient.GetDependants.Args): Promise<CollectionClient.GetDependants.Result>;
|
|
17
|
+
getDependencies({ id: collectionId, version }: CollectionClient.GetDependencies.Args): Promise<CollectionClient.GetDependencies.Result>;
|
|
18
|
+
}
|