@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,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.User = void 0;
|
|
4
|
+
const Role_1 = require("./Role");
|
|
5
|
+
// class
|
|
6
|
+
class User {
|
|
7
|
+
constructor(data) {
|
|
8
|
+
this.data = data;
|
|
9
|
+
// get a role instance from the role id
|
|
10
|
+
this.role = Role_1.Role.fromId(data.role);
|
|
11
|
+
}
|
|
12
|
+
get isOwner() {
|
|
13
|
+
const { role } = this;
|
|
14
|
+
return role.id === 'owner';
|
|
15
|
+
}
|
|
16
|
+
get isAdmin() {
|
|
17
|
+
const { role } = this;
|
|
18
|
+
return role.id === 'owner' || role.id === 'admin';
|
|
19
|
+
}
|
|
20
|
+
get isEditor() {
|
|
21
|
+
return this.role.id === 'editor';
|
|
22
|
+
}
|
|
23
|
+
get isViewer() {
|
|
24
|
+
return this.role.id === 'viewer';
|
|
25
|
+
}
|
|
26
|
+
get id() {
|
|
27
|
+
return this.data.id;
|
|
28
|
+
}
|
|
29
|
+
get brands() {
|
|
30
|
+
return this.data.brands;
|
|
31
|
+
}
|
|
32
|
+
get username() {
|
|
33
|
+
return this.data.username;
|
|
34
|
+
}
|
|
35
|
+
get email() {
|
|
36
|
+
return this.data.email;
|
|
37
|
+
}
|
|
38
|
+
get blocked() {
|
|
39
|
+
return this.data.blocked;
|
|
40
|
+
}
|
|
41
|
+
has(...privileges) {
|
|
42
|
+
return this.role.has(...privileges);
|
|
43
|
+
}
|
|
44
|
+
hasAny(...privileges) {
|
|
45
|
+
return this.role.hasAny(...privileges);
|
|
46
|
+
}
|
|
47
|
+
compareTo(that) {
|
|
48
|
+
// same if equivalent
|
|
49
|
+
if (this.id === that.id) {
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
// or compare role
|
|
53
|
+
const roleComparison = this.role.compareTo(that.role);
|
|
54
|
+
return roleComparison === 0
|
|
55
|
+
? this.username.localeCompare(that.username)
|
|
56
|
+
: roleComparison;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.User = User;
|
|
60
|
+
// extension
|
|
61
|
+
(function (User) {
|
|
62
|
+
// constant for unauthenticated user
|
|
63
|
+
User.UNAUTHENTICATED = new User({
|
|
64
|
+
id: 'unauthenticated',
|
|
65
|
+
username: 'unauthenticated',
|
|
66
|
+
email: 'unauthenticated',
|
|
67
|
+
blocked: true,
|
|
68
|
+
brands: [],
|
|
69
|
+
role: 'public'
|
|
70
|
+
});
|
|
71
|
+
})(User || (exports.User = User = {}));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Entity } from './Entity';
|
|
2
|
+
export declare class Versioned<TEntity extends Entity<unknown>> {
|
|
3
|
+
readonly published: TEntity | undefined;
|
|
4
|
+
readonly draft: TEntity;
|
|
5
|
+
constructor({ published, draft }: Versioned.ConstructorArgs<TEntity>);
|
|
6
|
+
get state(): Versioned.State;
|
|
7
|
+
/**
|
|
8
|
+
* Returns draft/modified version if new/changed, otherwise this return the last published version.
|
|
9
|
+
*/
|
|
10
|
+
get current(): TEntity;
|
|
11
|
+
get id(): TEntity['id'];
|
|
12
|
+
toData(): Versioned.Data<TEntity>;
|
|
13
|
+
}
|
|
14
|
+
export declare namespace Versioned {
|
|
15
|
+
type Target = 'published' | 'draft' | 'all';
|
|
16
|
+
type State = 'draft' | 'published' | 'modified';
|
|
17
|
+
type ConstructorArgs<TEntity extends Entity<unknown>> = Data<TEntity>;
|
|
18
|
+
type Data<TEntity extends Entity<unknown>> = {
|
|
19
|
+
published?: TEntity;
|
|
20
|
+
draft: TEntity;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Versioned = void 0;
|
|
4
|
+
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
5
|
+
// class
|
|
6
|
+
class Versioned {
|
|
7
|
+
constructor({ published, draft }) {
|
|
8
|
+
// initialize instance variables
|
|
9
|
+
this.published = published;
|
|
10
|
+
this.draft = draft;
|
|
11
|
+
// verify the args
|
|
12
|
+
if (!published && !draft) {
|
|
13
|
+
throw new funnel_core_1.IllegalStateError('Versioned entity must have either published or draft value');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
get state() {
|
|
17
|
+
const { published, draft } = this;
|
|
18
|
+
return published
|
|
19
|
+
? draft
|
|
20
|
+
? 'modified'
|
|
21
|
+
: 'published'
|
|
22
|
+
: 'draft';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns draft/modified version if new/changed, otherwise this return the last published version.
|
|
26
|
+
*/
|
|
27
|
+
get current() {
|
|
28
|
+
// get id (or throw)
|
|
29
|
+
const { published, draft } = this;
|
|
30
|
+
const current = draft !== null && draft !== void 0 ? draft : published;
|
|
31
|
+
if (!current) {
|
|
32
|
+
throw new funnel_core_1.IllegalStateError('Versioned entity must have either published or draft value');
|
|
33
|
+
}
|
|
34
|
+
// return latest
|
|
35
|
+
return current;
|
|
36
|
+
}
|
|
37
|
+
get id() {
|
|
38
|
+
return this.current.id;
|
|
39
|
+
}
|
|
40
|
+
toData() {
|
|
41
|
+
const { published, draft } = this;
|
|
42
|
+
return { published, draft };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.Versioned = Versioned;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './Entity';
|
|
2
|
+
export * from './Environment';
|
|
3
|
+
export * from './Pagination';
|
|
4
|
+
export * from './Privilege';
|
|
5
|
+
export * from './Role';
|
|
6
|
+
export * from './SiteConfig';
|
|
7
|
+
export * from './Upgrade';
|
|
8
|
+
export * from './User';
|
|
9
|
+
export * from './Versioned';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Entity"), exports);
|
|
18
|
+
__exportStar(require("./Environment"), exports);
|
|
19
|
+
__exportStar(require("./Pagination"), exports);
|
|
20
|
+
__exportStar(require("./Privilege"), exports);
|
|
21
|
+
__exportStar(require("./Role"), exports);
|
|
22
|
+
__exportStar(require("./SiteConfig"), exports);
|
|
23
|
+
__exportStar(require("./Upgrade"), exports);
|
|
24
|
+
__exportStar(require("./User"), exports);
|
|
25
|
+
__exportStar(require("./Versioned"), exports);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Callback } from '@nascentdigital/funnel-core';
|
|
2
|
+
import { StrapiClient } from '@strapi/client';
|
|
3
|
+
import { Jsonify, JsonValue } from 'type-fest';
|
|
4
|
+
import { AuthClient } from '../api';
|
|
5
|
+
import { CollectionData, PageData } from './serialization';
|
|
6
|
+
import type { StrapiAssetClient } from './StrapiAssetClient';
|
|
7
|
+
import type { StrapiAuthClient } from './StrapiAuthClient';
|
|
8
|
+
import type { StrapiChangeSetClient } from './StrapiChangeSetClient';
|
|
9
|
+
import type { StrapiCollectionClient } from './StrapiCollectionClient';
|
|
10
|
+
import type { StrapiPageClient } from './StrapiPageClient';
|
|
11
|
+
import type { StrapiSiteConfigClient } from './StrapiSiteConfigClient';
|
|
12
|
+
import type { StrapiUserClient } from './StrapiUserClient';
|
|
13
|
+
export interface IStrapiContentClient {
|
|
14
|
+
readonly token: AuthClient.AccessToken;
|
|
15
|
+
readonly client: StrapiClient;
|
|
16
|
+
readonly auth: StrapiAuthClient;
|
|
17
|
+
readonly changeSets: StrapiChangeSetClient;
|
|
18
|
+
readonly files: StrapiAssetClient;
|
|
19
|
+
readonly pages: StrapiPageClient;
|
|
20
|
+
readonly collections: StrapiCollectionClient;
|
|
21
|
+
readonly users: StrapiUserClient;
|
|
22
|
+
readonly siteConfig: StrapiSiteConfigClient;
|
|
23
|
+
customRequest<TResult extends JsonValue = JsonValue, TError extends JsonValue = JsonValue>(args: IStrapiContentClient.CustomRequestArgs<TError>): Promise<TResult>;
|
|
24
|
+
}
|
|
25
|
+
export declare namespace IStrapiContentClient {
|
|
26
|
+
type CustomRequestArgs<TError extends JsonValue = JsonValue> = {
|
|
27
|
+
command: CustomCommand;
|
|
28
|
+
params?: Record<string, unknown>;
|
|
29
|
+
data?: string;
|
|
30
|
+
method?: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
|
|
31
|
+
onError?: Callback<TError>;
|
|
32
|
+
};
|
|
33
|
+
type CustomCommand = 'changeset/query' | 'changeset/commit' | 'changeset/revert' | 'query/pages' | 'query/rank-pages' | 'query/collections' | 'query/collection' | 'publish' | 'unpublish' | 'version';
|
|
34
|
+
type UnpublishErrorData = Jsonify<{
|
|
35
|
+
error: true;
|
|
36
|
+
pageRefs: PageData.Ref[];
|
|
37
|
+
collectionRefs: CollectionData.Ref[];
|
|
38
|
+
}>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Language, Schema } from '@nascentdigital/funnel-core';
|
|
2
|
+
import { API as StrapiApi, CollectionTypeManager, StrapiClient } from '@strapi/client';
|
|
3
|
+
import { StringKeyOf } from 'type-fest';
|
|
4
|
+
import { Pagination } from '../models';
|
|
5
|
+
import { StrapiData } from './models';
|
|
6
|
+
import { CollectionData, PageData } from './serialization';
|
|
7
|
+
export declare namespace Strapi {
|
|
8
|
+
type PaginateArgs<TCollection extends StrapiData> = Omit<StrapiApi.BaseQueryParams, 'fields' | 'locale' | 'pagination'> & {
|
|
9
|
+
collection: CollectionTypeManager;
|
|
10
|
+
pagination: Pagination;
|
|
11
|
+
fields?: Array<StringKeyOf<TCollection>>;
|
|
12
|
+
};
|
|
13
|
+
function paginate<TCollection extends StrapiData>({ collection, pagination, status, fields, ...query }: PaginateArgs<TCollection>): Promise<Pagination.Paginated<TCollection>>;
|
|
14
|
+
namespace TranslateReferences {
|
|
15
|
+
type Args = {
|
|
16
|
+
client: StrapiClient;
|
|
17
|
+
targetLanguage: Language;
|
|
18
|
+
pageRefs?: PageData.Ref[];
|
|
19
|
+
collectionRefs?: CollectionData.Ref[];
|
|
20
|
+
};
|
|
21
|
+
type Result = {
|
|
22
|
+
pageIdMappings: IdMapping<Schema.Page.Id>[];
|
|
23
|
+
collectionIdMappings: IdMapping<Schema.Collection.Id>[];
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function translateReferences({ client, targetLanguage, pageRefs, collectionRefs }: TranslateReferences.Args): Promise<TranslateReferences.Result>;
|
|
27
|
+
type UpdateRefsArgs<T> = {
|
|
28
|
+
value: T;
|
|
29
|
+
pageIdMappings?: IdMapping<Schema.Page.Id>[];
|
|
30
|
+
collectionIdMappings?: IdMapping<Schema.Collection.Id>[];
|
|
31
|
+
};
|
|
32
|
+
function updateRefs<T>({ value, pageIdMappings, collectionIdMappings }: UpdateRefsArgs<T>): T;
|
|
33
|
+
type IdMapping<T extends string> = {
|
|
34
|
+
sourceId: T;
|
|
35
|
+
targetId: T;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
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.Strapi = void 0;
|
|
15
|
+
const errors_1 = require("../errors");
|
|
16
|
+
const serialization_1 = require("./serialization");
|
|
17
|
+
// extension
|
|
18
|
+
var Strapi;
|
|
19
|
+
(function (Strapi) {
|
|
20
|
+
async function paginate(_a) {
|
|
21
|
+
var _b, _c, _d, _e;
|
|
22
|
+
var { collection, pagination, status = 'published', fields } = _a, query = __rest(_a, ["collection", "pagination", "status", "fields"]);
|
|
23
|
+
// drain all pages while there are more pages
|
|
24
|
+
const items = [];
|
|
25
|
+
let hasMorePages = true;
|
|
26
|
+
let page = pagination === 'all' ? 1 : pagination.page;
|
|
27
|
+
const pageSize = pagination === 'all' ? 100 : pagination.pageSize;
|
|
28
|
+
let totalItemCount = 0;
|
|
29
|
+
let pageCount = 1;
|
|
30
|
+
do {
|
|
31
|
+
// get next page
|
|
32
|
+
const { data, meta } = await collection.find(Object.assign(Object.assign({}, query), { fields,
|
|
33
|
+
status, pagination: {
|
|
34
|
+
page,
|
|
35
|
+
pageSize
|
|
36
|
+
} }));
|
|
37
|
+
// merge results
|
|
38
|
+
items.push(...data);
|
|
39
|
+
// update paging info
|
|
40
|
+
pageCount = (_c = (_b = meta === null || meta === void 0 ? void 0 : meta.pagination) === null || _b === void 0 ? void 0 : _b.pageCount) !== null && _c !== void 0 ? _c : 0;
|
|
41
|
+
totalItemCount = (_e = (_d = meta === null || meta === void 0 ? void 0 : meta.pagination) === null || _d === void 0 ? void 0 : _d.total) !== null && _e !== void 0 ? _e : 0;
|
|
42
|
+
hasMorePages = pagination === 'all'
|
|
43
|
+
? ++page <= pageCount
|
|
44
|
+
: false;
|
|
45
|
+
} while (hasMorePages);
|
|
46
|
+
// return results
|
|
47
|
+
return {
|
|
48
|
+
items,
|
|
49
|
+
page: pagination === 'all' ? 1 : page,
|
|
50
|
+
pageCount: pagination === 'all' ? 1 : pageCount,
|
|
51
|
+
totalItemCount
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
Strapi.paginate = paginate;
|
|
55
|
+
async function translateReferences({ client, targetLanguage, pageRefs = [], collectionRefs = [] }) {
|
|
56
|
+
// setup return values
|
|
57
|
+
const pageIdMappings = [];
|
|
58
|
+
const collectionIdMappings = [];
|
|
59
|
+
// bail if no refs
|
|
60
|
+
if (pageRefs.length === 0 && collectionRefs.length === 0) {
|
|
61
|
+
return { pageIdMappings, collectionIdMappings };
|
|
62
|
+
}
|
|
63
|
+
// setup collections
|
|
64
|
+
const pageCollection = client.collection('pages');
|
|
65
|
+
const collectionCollection = client.collection('collections');
|
|
66
|
+
// try to find each item in target language
|
|
67
|
+
const [{ items: pagesInTargetLang }, { items: collectionsInTargetLang }] = await Promise.all([
|
|
68
|
+
Strapi.paginate({
|
|
69
|
+
collection: pageCollection,
|
|
70
|
+
pagination: 'all',
|
|
71
|
+
filters: {
|
|
72
|
+
groupId: { $in: pageRefs.map(ref => ref.groupId) },
|
|
73
|
+
lang: targetLanguage
|
|
74
|
+
},
|
|
75
|
+
status: 'draft'
|
|
76
|
+
}),
|
|
77
|
+
Strapi.paginate({
|
|
78
|
+
collection: collectionCollection,
|
|
79
|
+
pagination: 'all',
|
|
80
|
+
filters: {
|
|
81
|
+
groupId: { $in: collectionRefs.map(ref => ref.groupId) },
|
|
82
|
+
lang: targetLanguage
|
|
83
|
+
},
|
|
84
|
+
status: 'draft'
|
|
85
|
+
})
|
|
86
|
+
]);
|
|
87
|
+
// go through each item to map ref to target language ref
|
|
88
|
+
const pageRefsMap = pageRefs.map(pageRef => {
|
|
89
|
+
const pageInTargetLang = pagesInTargetLang
|
|
90
|
+
.find(page => page.groupId === pageRef.groupId);
|
|
91
|
+
return { sourceRef: pageRef, targetRef: pageInTargetLang };
|
|
92
|
+
});
|
|
93
|
+
const collectionRefsMap = collectionRefs.map(collectionRef => {
|
|
94
|
+
const collectionInTargetLang = collectionsInTargetLang
|
|
95
|
+
.find(collection => collection.groupId === collectionRef.groupId);
|
|
96
|
+
return { sourceRef: collectionRef, targetRef: collectionInTargetLang };
|
|
97
|
+
});
|
|
98
|
+
console.debug('[TargetLanguageRefs] fetched ref groups', { pageRefsMap, collectionRefsMap });
|
|
99
|
+
// find refs with missing target language
|
|
100
|
+
const missingPageRefs = pageRefsMap
|
|
101
|
+
.filter(map => map.targetRef === undefined)
|
|
102
|
+
.map(map => map.sourceRef);
|
|
103
|
+
const missingCollectionRefs = collectionRefsMap
|
|
104
|
+
.filter(map => map.targetRef === undefined)
|
|
105
|
+
.map(map => map.sourceRef);
|
|
106
|
+
console.debug('[TargetLanguageRefs] missing refs', { missingPageRefs, missingCollectionRefs });
|
|
107
|
+
// throw if there are any missing refs in target language
|
|
108
|
+
if (missingPageRefs.length > 0 || missingCollectionRefs.length > 0) {
|
|
109
|
+
console.error('[TargetLanguageRefs] missing target refs', { missingPageRefs, missingCollectionRefs });
|
|
110
|
+
throw new errors_1.TranslateReferencesError({
|
|
111
|
+
message: 'Missing references in target language',
|
|
112
|
+
untranslatedPages: missingPageRefs.map(ref => serialization_1.PageData.deserializeRef(ref)),
|
|
113
|
+
untranslatedCollections: missingCollectionRefs.map(ref => serialization_1.CollectionData.deserializeRef(ref)),
|
|
114
|
+
targetLanguage,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
// build mappings
|
|
118
|
+
for (const { sourceRef, targetRef } of pageRefsMap) {
|
|
119
|
+
// shouldn't happen because of check above
|
|
120
|
+
if (!targetRef) {
|
|
121
|
+
throw new Error('something went wrong');
|
|
122
|
+
}
|
|
123
|
+
pageIdMappings.push({
|
|
124
|
+
sourceId: sourceRef.documentId,
|
|
125
|
+
targetId: targetRef.documentId
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
for (const { sourceRef, targetRef } of collectionRefsMap) {
|
|
129
|
+
// shouldn't happen because of check above
|
|
130
|
+
if (!targetRef) {
|
|
131
|
+
throw new Error('something went wrong');
|
|
132
|
+
}
|
|
133
|
+
collectionIdMappings.push({
|
|
134
|
+
sourceId: sourceRef.documentId,
|
|
135
|
+
targetId: targetRef.documentId
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
// return results
|
|
139
|
+
return { pageIdMappings, collectionIdMappings };
|
|
140
|
+
}
|
|
141
|
+
Strapi.translateReferences = translateReferences;
|
|
142
|
+
function updateRefs({ value, pageIdMappings = [], collectionIdMappings = [] }) {
|
|
143
|
+
// return original value if there is no mappings
|
|
144
|
+
if (pageIdMappings.length === 0 && collectionIdMappings.length === 0) {
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
// TODO: recurse through object instead of using string replaceAll
|
|
148
|
+
// otherwise find/replace ids
|
|
149
|
+
let serialized = JSON.stringify(value);
|
|
150
|
+
for (const { sourceId, targetId } of [...pageIdMappings, ...collectionIdMappings]) {
|
|
151
|
+
serialized = serialized.replaceAll(sourceId, targetId);
|
|
152
|
+
}
|
|
153
|
+
return JSON.parse(serialized);
|
|
154
|
+
}
|
|
155
|
+
Strapi.updateRefs = updateRefs;
|
|
156
|
+
})(Strapi || (exports.Strapi = Strapi = {}));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AssetClient } from '../api';
|
|
2
|
+
import type { IStrapiContentClient } from './IStrapiContentClient';
|
|
3
|
+
export declare class StrapiAssetClient implements AssetClient {
|
|
4
|
+
private readonly provider;
|
|
5
|
+
constructor(provider: IStrapiContentClient);
|
|
6
|
+
getAssets({ brand, fileType, scope, tags, pagination }: AssetClient.GetAssets.Args): Promise<AssetClient.GetAssets.Result>;
|
|
7
|
+
getAsset(id: AssetClient.GetAsset.Args): Promise<AssetClient.GetAsset.Result>;
|
|
8
|
+
createAsset({ tags, ...asset }: AssetClient.CreateAsset.Args): Promise<AssetClient.CreateAsset.Result>;
|
|
9
|
+
updateAsset({ id, tags, ...update }: AssetClient.UpdateAsset.Args): Promise<AssetClient.UpdateAsset.Result>;
|
|
10
|
+
deleteAsset(id: AssetClient.DeleteAsset.Args): Promise<AssetClient.DeleteAsset.Result>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
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.StrapiAssetClient = void 0;
|
|
15
|
+
const funnel_core_1 = require("@nascentdigital/funnel-core");
|
|
16
|
+
const models_1 = require("./models");
|
|
17
|
+
const serialization_1 = require("./serialization");
|
|
18
|
+
const Strapi_1 = require("./Strapi");
|
|
19
|
+
// class
|
|
20
|
+
class StrapiAssetClient {
|
|
21
|
+
constructor(provider) {
|
|
22
|
+
this.provider = provider;
|
|
23
|
+
}
|
|
24
|
+
async getAssets({ brand, fileType = [], scope, tags = [], pagination }) {
|
|
25
|
+
// build filters
|
|
26
|
+
const filters = [
|
|
27
|
+
{
|
|
28
|
+
$or: [
|
|
29
|
+
{ brand: { $eq: brand } },
|
|
30
|
+
{ brand: { $null: true } }
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
];
|
|
34
|
+
// filter mime types (if any)
|
|
35
|
+
const fileTypes = Array.isArray(fileType)
|
|
36
|
+
? fileType
|
|
37
|
+
: [fileType];
|
|
38
|
+
if (fileTypes.length > 0) {
|
|
39
|
+
filters.push({
|
|
40
|
+
file: { mime: {
|
|
41
|
+
$in: new Set(fileTypes.flatMap(fileType => funnel_core_1.MimeType.forFileType(fileType))).values().toArray()
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
// filter scope (if any)
|
|
47
|
+
if ((scope === null || scope === void 0 ? void 0 : scope.target) === 'page') {
|
|
48
|
+
filters.push({
|
|
49
|
+
$or: [
|
|
50
|
+
{ scope: { $eq: funnel_core_1.Schema.AssetScope.global.data } },
|
|
51
|
+
{ scope: { $eq: new funnel_core_1.Schema.PageTypeAssetScope(scope.type).data } },
|
|
52
|
+
{ scope: { $eq: new funnel_core_1.Schema.PageInstanceAssetScope(scope.groupId).data } }
|
|
53
|
+
]
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
else if ((scope === null || scope === void 0 ? void 0 : scope.target) === 'collection') {
|
|
57
|
+
filters.push({
|
|
58
|
+
$or: [
|
|
59
|
+
{ scope: { $eq: funnel_core_1.Schema.AssetScope.global.data } },
|
|
60
|
+
{ scope: { $eq: new funnel_core_1.Schema.CollectionTypeAssetScope(scope.type).data } },
|
|
61
|
+
{ scope: { $eq: new funnel_core_1.Schema.CollectionInstanceAssetScope(scope.groupId).data } }
|
|
62
|
+
]
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
// filter tags (if any)
|
|
66
|
+
if (tags.length === 1) {
|
|
67
|
+
filters.push({ tags: { $contains: `"${tags[0]}"` } });
|
|
68
|
+
}
|
|
69
|
+
else if (tags.length > 1) {
|
|
70
|
+
filters.push({
|
|
71
|
+
$or: tags
|
|
72
|
+
.filter((tag) => !!tag)
|
|
73
|
+
.map((tag) => ({ tags: { $contains: `"${tag}"` } }))
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
// fetch all assets
|
|
77
|
+
const { client } = this.provider;
|
|
78
|
+
const collection = client.collection('assets');
|
|
79
|
+
const _a = await Strapi_1.Strapi.paginate({
|
|
80
|
+
collection,
|
|
81
|
+
pagination,
|
|
82
|
+
filters: filters.length > 1 ? { $and: filters } : filters[0],
|
|
83
|
+
populate: '*',
|
|
84
|
+
sort: ['updatedAt:desc']
|
|
85
|
+
}), { items } = _a, paginated = __rest(_a, ["items"]);
|
|
86
|
+
// transform to dtos
|
|
87
|
+
return Object.assign({ items: items
|
|
88
|
+
.map(data => serialization_1.StrapiAssetData.deserialize(data, client.baseURL))
|
|
89
|
+
.filter(funnel_core_1.Value.isDefined) }, paginated);
|
|
90
|
+
}
|
|
91
|
+
async getAsset(id) {
|
|
92
|
+
// fetch asset
|
|
93
|
+
const { client } = this.provider;
|
|
94
|
+
const collection = client.collection('assets');
|
|
95
|
+
const { data } = await collection.findOne(id, { populate: '*' });
|
|
96
|
+
console.debug('[StrapiAssetClient] found asset', data);
|
|
97
|
+
// return it (transformed)
|
|
98
|
+
return data
|
|
99
|
+
? serialization_1.StrapiAssetData.deserialize(data, client.baseURL)
|
|
100
|
+
: undefined;
|
|
101
|
+
}
|
|
102
|
+
async createAsset(_a) {
|
|
103
|
+
var { tags } = _a, asset = __rest(_a, ["tags"]);
|
|
104
|
+
console.debug('[StrapiAssetClient/createAsset] creating file', Object.assign(Object.assign({}, asset), { tags }));
|
|
105
|
+
// create asset
|
|
106
|
+
const { client } = this.provider;
|
|
107
|
+
const collection = client.collection('assets');
|
|
108
|
+
const { data } = await collection.create(Object.assign(Object.assign({}, asset), { brand: funnel_core_1.AppConfig.brand(), tags: JSON.stringify(tags) }));
|
|
109
|
+
// return asset partial
|
|
110
|
+
return serialization_1.StrapiAssetData.deserialize(data, client.baseURL);
|
|
111
|
+
}
|
|
112
|
+
async updateAsset(_a) {
|
|
113
|
+
var { id, tags } = _a, update = __rest(_a, ["id", "tags"]);
|
|
114
|
+
console.debug('[StrapiAssetClient/updateAsset] updating file', Object.assign({ id }, update));
|
|
115
|
+
// create asset
|
|
116
|
+
const { client } = this.provider;
|
|
117
|
+
const collection = client.collection('assets');
|
|
118
|
+
const { data } = await collection.update(id, Object.assign(Object.assign({}, update), { tags: tags ? JSON.stringify(tags) : undefined }), { status: 'draft', populate: '*' });
|
|
119
|
+
// return asset
|
|
120
|
+
return serialization_1.StrapiAssetData.deserialize(data, client.baseURL);
|
|
121
|
+
}
|
|
122
|
+
async deleteAsset(id) {
|
|
123
|
+
var _a;
|
|
124
|
+
console.debug('[StrapiAssetClient/deleteAsset] deleting asset:', id);
|
|
125
|
+
// get asset (skip if it doesn't exist)
|
|
126
|
+
const { client } = this.provider;
|
|
127
|
+
const collection = client.collection('assets');
|
|
128
|
+
const asset = await this.getAsset(id);
|
|
129
|
+
if (!asset) {
|
|
130
|
+
console.debug('[StrapiAssetClient/deleteAsset] no asset to delete:', id);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
// delete asset
|
|
134
|
+
await collection.delete(id);
|
|
135
|
+
// delete underlying media file (if we have any - might be a zombie)
|
|
136
|
+
const { value } = asset;
|
|
137
|
+
if (models_1.StrapiAsset.filter(value) && ((_a = value.__internal) === null || _a === void 0 ? void 0 : _a.fileId)) {
|
|
138
|
+
console.debug('[StrapiAssetClient/deleteAsset] deleting associated file:', value.__internal.fileId);
|
|
139
|
+
await client.files.delete(value.__internal.fileId);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.StrapiAssetClient = StrapiAssetClient;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AssetUploadClient } from '../api';
|
|
2
|
+
export declare class StrapiAssetUploadClient extends AssetUploadClient {
|
|
3
|
+
private readonly strapiUrl;
|
|
4
|
+
constructor(strapiUrl: string);
|
|
5
|
+
onUpload({ api, file: blob, brand, type, size, name, description, scope, tags, metadata }: AssetUploadClient.OnUpload.Args): Promise<AssetUploadClient.OnUpload.Result>;
|
|
6
|
+
}
|