@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.
Files changed (125) hide show
  1. package/dist/api/AssetClient.d.ts +53 -0
  2. package/dist/api/AssetClient.js +2 -0
  3. package/dist/api/AssetUploadClient.d.ts +17 -0
  4. package/dist/api/AssetUploadClient.js +26 -0
  5. package/dist/api/AuthClient.d.ts +29 -0
  6. package/dist/api/AuthClient.js +2 -0
  7. package/dist/api/ChangeSetClient.d.ts +84 -0
  8. package/dist/api/ChangeSetClient.js +31 -0
  9. package/dist/api/CollectionClient.d.ts +187 -0
  10. package/dist/api/CollectionClient.js +2 -0
  11. package/dist/api/ContentClient.d.ts +43 -0
  12. package/dist/api/ContentClient.js +34 -0
  13. package/dist/api/IAssetApiClient.d.ts +9 -0
  14. package/dist/api/IAssetApiClient.js +2 -0
  15. package/dist/api/PageClient.d.ts +264 -0
  16. package/dist/api/PageClient.js +2 -0
  17. package/dist/api/SiteClient.d.ts +23 -0
  18. package/dist/api/SiteClient.js +2 -0
  19. package/dist/api/SiteConfigClient.d.ts +26 -0
  20. package/dist/api/SiteConfigClient.js +2 -0
  21. package/dist/api/UpgradeClient.d.ts +16 -0
  22. package/dist/api/UpgradeClient.js +2 -0
  23. package/dist/api/UserClient.d.ts +46 -0
  24. package/dist/api/UserClient.js +2 -0
  25. package/dist/api/index.d.ts +11 -0
  26. package/dist/api/index.js +27 -0
  27. package/dist/errors/CMSError.d.ts +8 -0
  28. package/dist/errors/CMSError.js +17 -0
  29. package/dist/errors/CMSErrors.d.ts +5 -0
  30. package/dist/errors/CMSErrors.js +36 -0
  31. package/dist/errors/LinkedDependantsError.d.ts +21 -0
  32. package/dist/errors/LinkedDependantsError.js +31 -0
  33. package/dist/errors/LockdownError.d.ts +4 -0
  34. package/dist/errors/LockdownError.js +12 -0
  35. package/dist/errors/SlugValidationError.d.ts +21 -0
  36. package/dist/errors/SlugValidationError.js +23 -0
  37. package/dist/errors/TranslateReferencesError.d.ts +21 -0
  38. package/dist/errors/TranslateReferencesError.js +22 -0
  39. package/dist/errors/index.d.ts +4 -0
  40. package/dist/errors/index.js +25 -0
  41. package/dist/index.d.ts +3 -0
  42. package/dist/index.js +19 -0
  43. package/dist/models/Entity.d.ts +14 -0
  44. package/dist/models/Entity.js +2 -0
  45. package/dist/models/Environment.d.ts +1 -0
  46. package/dist/models/Environment.js +2 -0
  47. package/dist/models/Pagination.d.ts +20 -0
  48. package/dist/models/Pagination.js +21 -0
  49. package/dist/models/Privilege.d.ts +57 -0
  50. package/dist/models/Privilege.js +163 -0
  51. package/dist/models/Role.d.ts +33 -0
  52. package/dist/models/Role.js +118 -0
  53. package/dist/models/SiteConfig.d.ts +14 -0
  54. package/dist/models/SiteConfig.js +2 -0
  55. package/dist/models/Upgrade.d.ts +40 -0
  56. package/dist/models/Upgrade.js +19 -0
  57. package/dist/models/User.d.ts +41 -0
  58. package/dist/models/User.js +71 -0
  59. package/dist/models/Versioned.d.ts +22 -0
  60. package/dist/models/Versioned.js +45 -0
  61. package/dist/models/index.d.ts +9 -0
  62. package/dist/models/index.js +25 -0
  63. package/dist/strapi/IStrapiContentClient.d.ts +39 -0
  64. package/dist/strapi/IStrapiContentClient.js +2 -0
  65. package/dist/strapi/Strapi.d.ts +37 -0
  66. package/dist/strapi/Strapi.js +156 -0
  67. package/dist/strapi/StrapiAssetClient.d.ts +11 -0
  68. package/dist/strapi/StrapiAssetClient.js +143 -0
  69. package/dist/strapi/StrapiAssetUploadClient.d.ts +6 -0
  70. package/dist/strapi/StrapiAssetUploadClient.js +109 -0
  71. package/dist/strapi/StrapiAuthClient.d.ts +9 -0
  72. package/dist/strapi/StrapiAuthClient.js +64 -0
  73. package/dist/strapi/StrapiChangeSetClient.d.ts +22 -0
  74. package/dist/strapi/StrapiChangeSetClient.js +218 -0
  75. package/dist/strapi/StrapiCollectionClient.d.ts +18 -0
  76. package/dist/strapi/StrapiCollectionClient.js +610 -0
  77. package/dist/strapi/StrapiContentClient.d.ts +38 -0
  78. package/dist/strapi/StrapiContentClient.js +105 -0
  79. package/dist/strapi/StrapiContentClientFactory.d.ts +13 -0
  80. package/dist/strapi/StrapiContentClientFactory.js +19 -0
  81. package/dist/strapi/StrapiPageClient.d.ts +23 -0
  82. package/dist/strapi/StrapiPageClient.js +882 -0
  83. package/dist/strapi/StrapiSiteConfigClient.d.ts +8 -0
  84. package/dist/strapi/StrapiSiteConfigClient.js +50 -0
  85. package/dist/strapi/StrapiUpgradeClient.d.ts +13 -0
  86. package/dist/strapi/StrapiUpgradeClient.js +118 -0
  87. package/dist/strapi/StrapiUserClient.d.ts +17 -0
  88. package/dist/strapi/StrapiUserClient.js +199 -0
  89. package/dist/strapi/client.d.ts +1 -0
  90. package/dist/strapi/client.js +17 -0
  91. package/dist/strapi/index.d.ts +3 -0
  92. package/dist/strapi/index.js +19 -0
  93. package/dist/strapi/models/StrapiAsset.d.ts +10 -0
  94. package/dist/strapi/models/StrapiAsset.js +16 -0
  95. package/dist/strapi/models/StrapiData.d.ts +13 -0
  96. package/dist/strapi/models/StrapiData.js +16 -0
  97. package/dist/strapi/models/StrapiFile.d.ts +18 -0
  98. package/dist/strapi/models/StrapiFile.js +2 -0
  99. package/dist/strapi/models/index.d.ts +3 -0
  100. package/dist/strapi/models/index.js +19 -0
  101. package/dist/strapi/serialization/ChangeSetData.d.ts +15 -0
  102. package/dist/strapi/serialization/ChangeSetData.js +76 -0
  103. package/dist/strapi/serialization/CollectionData.d.ts +57 -0
  104. package/dist/strapi/serialization/CollectionData.js +258 -0
  105. package/dist/strapi/serialization/CollectionSnapshotData.d.ts +16 -0
  106. package/dist/strapi/serialization/CollectionSnapshotData.js +66 -0
  107. package/dist/strapi/serialization/PageData.d.ts +126 -0
  108. package/dist/strapi/serialization/PageData.js +335 -0
  109. package/dist/strapi/serialization/PageSnapshotData.d.ts +20 -0
  110. package/dist/strapi/serialization/PageSnapshotData.js +69 -0
  111. package/dist/strapi/serialization/RoleData.d.ts +5 -0
  112. package/dist/strapi/serialization/RoleData.js +2 -0
  113. package/dist/strapi/serialization/SiteConfigData.d.ts +11 -0
  114. package/dist/strapi/serialization/SiteConfigData.js +23 -0
  115. package/dist/strapi/serialization/StrapiAssetData.d.ts +17 -0
  116. package/dist/strapi/serialization/StrapiAssetData.js +39 -0
  117. package/dist/strapi/serialization/UserData.d.ts +18 -0
  118. package/dist/strapi/serialization/UserData.js +42 -0
  119. package/dist/strapi/serialization/VersionData.d.ts +26 -0
  120. package/dist/strapi/serialization/VersionData.js +88 -0
  121. package/dist/strapi/serialization/index.d.ts +10 -0
  122. package/dist/strapi/serialization/index.js +26 -0
  123. package/dist/strapi/test.d.ts +563 -0
  124. package/dist/strapi/test.js +1131 -0
  125. package/package.json +42 -0
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.StrapiContentClient = void 0;
7
+ const funnel_core_1 = require("@nascentdigital/funnel-core");
8
+ const webhook_1 = require("@slack/webhook");
9
+ const client_1 = require("@strapi/client");
10
+ const qs_1 = __importDefault(require("qs"));
11
+ const StrapiAssetClient_1 = require("./StrapiAssetClient");
12
+ const StrapiAuthClient_1 = require("./StrapiAuthClient");
13
+ const StrapiChangeSetClient_1 = require("./StrapiChangeSetClient");
14
+ const StrapiCollectionClient_1 = require("./StrapiCollectionClient");
15
+ const StrapiPageClient_1 = require("./StrapiPageClient");
16
+ const StrapiSiteConfigClient_1 = require("./StrapiSiteConfigClient");
17
+ const StrapiUpgradeClient_1 = require("./StrapiUpgradeClient");
18
+ const StrapiUserClient_1 = require("./StrapiUserClient");
19
+ // class
20
+ class StrapiContentClient {
21
+ constructor({ baseUrl, token, slackUrl }) {
22
+ // initialize instance variables
23
+ const slack = slackUrl
24
+ ? new webhook_1.IncomingWebhook(slackUrl)
25
+ : undefined;
26
+ this._baseUrl = baseUrl;
27
+ this._token = token;
28
+ this._client = (0, client_1.strapi)({
29
+ baseURL: baseUrl,
30
+ auth: token
31
+ });
32
+ this.auth = new StrapiAuthClient_1.StrapiAuthClient(this);
33
+ this.changeSets = new StrapiChangeSetClient_1.StrapiChangeSetClient(this);
34
+ this.files = new StrapiAssetClient_1.StrapiAssetClient(this);
35
+ this.pages = new StrapiPageClient_1.StrapiPageClient(this);
36
+ this.collections = new StrapiCollectionClient_1.StrapiCollectionClient(this);
37
+ this.upgrade = new StrapiUpgradeClient_1.StrapiUpgradeClient(this);
38
+ this.users = new StrapiUserClient_1.StrapiUserClient(this, slack);
39
+ this.siteConfig = new StrapiSiteConfigClient_1.StrapiSiteConfigClient(this);
40
+ }
41
+ get client() {
42
+ return this._client;
43
+ }
44
+ get token() {
45
+ // throw if token isn't set
46
+ const { _token } = this;
47
+ if (!_token) {
48
+ throw new funnel_core_1.InvalidOperationError('Cannot access token before authentication');
49
+ }
50
+ // return token
51
+ return _token;
52
+ }
53
+ set token(token) {
54
+ // change client if token changes
55
+ if (this._token !== token) {
56
+ // capture new token
57
+ this._token = token;
58
+ // create new client
59
+ this._client = (0, client_1.strapi)({
60
+ baseURL: this._baseUrl,
61
+ auth: token
62
+ });
63
+ }
64
+ }
65
+ clearToken() {
66
+ // change client if token changes
67
+ if (this._token) {
68
+ // clear token
69
+ delete this._token;
70
+ // create new client
71
+ this._client = (0, client_1.strapi)({
72
+ baseURL: this._baseUrl
73
+ });
74
+ }
75
+ }
76
+ async customRequest({ command, method = 'GET', params = {}, data, onError }) {
77
+ // create full query
78
+ const { client, token } = this;
79
+ const url = new URL(`/api/funnel/${command}`, client.baseURL);
80
+ url.search = qs_1.default.stringify(params, { addQueryPrefix: true });
81
+ // send request
82
+ const response = await fetch(url.href, {
83
+ method,
84
+ headers: {
85
+ Authorization: `Bearer ${token}`,
86
+ 'Content-Type': 'application/json'
87
+ },
88
+ body: data
89
+ });
90
+ // handle errors (never return)
91
+ if (!response.ok) {
92
+ // process error if expected
93
+ if (onError) {
94
+ onError(await response.json());
95
+ }
96
+ // or throw generic error
97
+ else {
98
+ throw new funnel_core_1.ServerError(`Failed to invoke "${command}" command:` + response.statusText);
99
+ }
100
+ }
101
+ // return response
102
+ return response.json();
103
+ }
104
+ }
105
+ exports.StrapiContentClient = StrapiContentClient;
@@ -0,0 +1,13 @@
1
+ import { RequiredBy } from '@nascentdigital/funnel-core';
2
+ import { ContentClient } from '../api';
3
+ import { StrapiContentClient } from './StrapiContentClient';
4
+ export declare class StrapiContentClientFactory implements ContentClient.Factory {
5
+ private readonly _baseUrl;
6
+ private readonly _serverClient;
7
+ constructor(args: StrapiContentClientFactory.ConstructorArgs);
8
+ forServer(): StrapiContentClient;
9
+ forEditor(): StrapiContentClient;
10
+ }
11
+ export declare namespace StrapiContentClientFactory {
12
+ type ConstructorArgs = RequiredBy<StrapiContentClient.ConstructorArgs, 'token'>;
13
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StrapiContentClientFactory = void 0;
4
+ const StrapiContentClient_1 = require("./StrapiContentClient");
5
+ // factory
6
+ class StrapiContentClientFactory {
7
+ constructor(args) {
8
+ // initialize instance variables
9
+ this._baseUrl = args.baseUrl;
10
+ this._serverClient = new StrapiContentClient_1.StrapiContentClient(args);
11
+ }
12
+ forServer() {
13
+ return this._serverClient;
14
+ }
15
+ forEditor() {
16
+ return new StrapiContentClient_1.StrapiContentClient({ baseUrl: this._baseUrl });
17
+ }
18
+ }
19
+ exports.StrapiContentClientFactory = StrapiContentClientFactory;
@@ -0,0 +1,23 @@
1
+ import { PageClient } from '../api';
2
+ import type { IStrapiContentClient } from './IStrapiContentClient';
3
+ export declare class StrapiPageClient implements PageClient {
4
+ private readonly provider;
5
+ constructor(provider: IStrapiContentClient);
6
+ getOverview({ brand, region, version }: PageClient.GetOverview.Args): Promise<PageClient.GetOverview.Result>;
7
+ getSummaries(args: PageClient.GetSummaries.Args): Promise<PageClient.GetSummaries.Result>;
8
+ getPreviews({ pagination, ...args }: PageClient.GetPreviews.Args): Promise<PageClient.GetPreviews.Result>;
9
+ search({ pagination, ...args }: PageClient.Search.Args): Promise<PageClient.Search.Result>;
10
+ query({ pagination, ...args }: PageClient.Query.Args): Promise<PageClient.Query.Result>;
11
+ find({ pagination, ...args }: PageClient.Find.Args): Promise<PageClient.Find.Result>;
12
+ getGroup({ brand, groupId, type, slug, region, language, version }: PageClient.GetGroup.Args): Promise<PageClient.GetGroup.Result>;
13
+ get(args: PageClient.Get.Args): Promise<PageClient.Get.Result>;
14
+ create(args: PageClient.Create.Args): Promise<PageClient.Create.Result>;
15
+ duplicate({ source: pageId, targetPage, targetLanguage, targetSlug }: PageClient.Duplicate.Args): Promise<PageClient.Duplicate.Result>;
16
+ touch({ id: pageId, version: status }: PageClient.Touch.Args): Promise<PageClient.Touch.Result>;
17
+ update({ id: pageId, slug: pageSlug, publication: pagePublication, errors, updates }: PageClient.Update.Args): Promise<PageClient.Update.Result>;
18
+ replace({ page, version, skipSync }: PageClient.Replace.Args): Promise<PageClient.Replace.Result>;
19
+ unpublish(pageId: PageClient.Unpublish.Args): Promise<PageClient.Unpublish.Result>;
20
+ getDependants({ id: pageId, version }: PageClient.GetDependants.Args): Promise<PageClient.GetDependants.Result>;
21
+ getDependencies({ id: pageId, version }: PageClient.GetDependencies.Args): Promise<PageClient.GetDependencies.Result>;
22
+ validateSlug({ brand, type, region, slug, groupId }: PageClient.ValidateSlug.Args): Promise<PageClient.ValidateSlug.Result>;
23
+ }