@cooperco/cooper-component-library 0.1.129 → 0.1.131

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 (21) hide show
  1. package/dist/cms/{migrations/scripts/0098-delete-body-copy-content-type.cjs → 0096-delete-body-copy-content-type.cjs} +70 -4
  2. package/dist/cms/{contentful/migrations/scripts/0096-update-container-collection-filtered-table.cjs → 0098-update-container-collection-filtered-table.cjs} +0 -3
  3. package/dist/cms/{scripts/0098-delete-body-copy-content-type.cjs → contentful/migrations/scripts/0096-delete-body-copy-content-type.cjs} +70 -4
  4. package/dist/cms/{0096-update-container-collection-filtered-table.cjs → contentful/migrations/scripts/0098-update-container-collection-filtered-table.cjs} +0 -3
  5. package/dist/cms/{contentful/migrations/scripts/0098-delete-body-copy-content-type.cjs → migrations/scripts/0096-delete-body-copy-content-type.cjs} +70 -4
  6. package/dist/cms/migrations/scripts/{0096-update-container-collection-filtered-table.cjs → 0098-update-container-collection-filtered-table.cjs} +0 -3
  7. package/dist/cms/{0098-delete-body-copy-content-type.cjs → scripts/0096-delete-body-copy-content-type.cjs} +70 -4
  8. package/dist/cms/scripts/{0096-update-container-collection-filtered-table.cjs → 0098-update-container-collection-filtered-table.cjs} +0 -3
  9. package/dist/lib/component-lib.js +1748 -1735
  10. package/dist/lib/component-lib.umd.cjs +15 -15
  11. package/dist/lib/css/main.css +5 -5
  12. package/dist/lib/style.css +1 -1
  13. package/package.json +1 -1
  14. /package/dist/cms/{0097-tabmodule-inline-body-copy.cjs → 0095-tabmodule-inline-body-copy.cjs} +0 -0
  15. /package/dist/cms/{0095-create-table-module.cjs → 0097-create-table-module.cjs} +0 -0
  16. /package/dist/cms/contentful/migrations/scripts/{0097-tabmodule-inline-body-copy.cjs → 0095-tabmodule-inline-body-copy.cjs} +0 -0
  17. /package/dist/cms/contentful/migrations/scripts/{0095-create-table-module.cjs → 0097-create-table-module.cjs} +0 -0
  18. /package/dist/cms/migrations/scripts/{0097-tabmodule-inline-body-copy.cjs → 0095-tabmodule-inline-body-copy.cjs} +0 -0
  19. /package/dist/cms/migrations/scripts/{0095-create-table-module.cjs → 0097-create-table-module.cjs} +0 -0
  20. /package/dist/cms/scripts/{0097-tabmodule-inline-body-copy.cjs → 0095-tabmodule-inline-body-copy.cjs} +0 -0
  21. /package/dist/cms/scripts/{0095-create-table-module.cjs → 0097-create-table-module.cjs} +0 -0
@@ -95,8 +95,46 @@ async function deleteEntry(makeRequest, entryId) {
95
95
  }
96
96
  }
97
97
 
98
+ /**
99
+ * Check whether a content type exists on the current environment.
100
+ *
101
+ * @param {Function} makeRequest
102
+ * @param {string} contentTypeId
103
+ * @returns {Promise<boolean>}
104
+ */
105
+ async function contentTypeExists(makeRequest, contentTypeId) {
106
+ try {
107
+ await makeRequest({
108
+ method: 'GET',
109
+ url: `/content_types/${contentTypeId}`,
110
+ })
111
+ return true
112
+ } catch (error) {
113
+ if (
114
+ error?.status === 404 ||
115
+ error?.response?.status === 404 ||
116
+ error?.name === 'NotFound'
117
+ ) {
118
+ return false
119
+ }
120
+ // contentful-sdk-core packs status into error.message JSON
121
+ if (typeof error?.message === 'string') {
122
+ try {
123
+ const parsed = JSON.parse(error.message)
124
+ if (parsed?.status === 404) {
125
+ return false
126
+ }
127
+ } catch {
128
+ // message is not JSON — ignore
129
+ }
130
+ }
131
+ throw error
132
+ }
133
+ }
134
+
98
135
  /**
99
136
  * Delete every entry of the given content type (paginated).
137
+ * Returns early if the content type does not exist (nothing to delete).
100
138
  *
101
139
  * @param {Function} makeRequest
102
140
  * @param {string} contentTypeId
@@ -107,10 +145,30 @@ async function deleteAllEntriesOfContentType(makeRequest, contentTypeId) {
107
145
  // Re-query from skip 0 after each page of deletes — indexes shift as
108
146
  // entries drop, so a single ascending skip walk would miss rows.
109
147
  for (;;) {
110
- const page = await makeRequest({
111
- method: 'GET',
112
- url: `/entries?content_type=${contentTypeId}&limit=${limit}&skip=0&sys.archivedAt[exists]=false`,
113
- })
148
+ let page
149
+ try {
150
+ page = await makeRequest({
151
+ method: 'GET',
152
+ url: `/entries?content_type=${contentTypeId}&limit=${limit}&skip=0&sys.archivedAt[exists]=false`,
153
+ })
154
+ } catch (error) {
155
+ // Contentful returns 400 with unknownContentType when the content
156
+ // type doesn't exist — treat it the same as "no entries".
157
+ const errorMessage =
158
+ typeof error?.message === 'string' ? error.message : ''
159
+ if (
160
+ error?.status === 400 ||
161
+ error?.response?.status === 400 ||
162
+ errorMessage.includes('unknownContentType')
163
+ ) {
164
+ process.stdout.write(
165
+ `[0096] Content type "${contentTypeId}" does not exist ` +
166
+ `or is not queryable — skipping entry deletion.\n`
167
+ )
168
+ return
169
+ }
170
+ throw error
171
+ }
114
172
 
115
173
  const items = page.items ?? []
116
174
  if (items.length === 0) {
@@ -127,6 +185,14 @@ module.exports = {
127
185
  // @ts-check
128
186
  /** @type { import('contentful-migration').MigrationFunction } */
129
187
  up: async function (migration, { makeRequest }) {
188
+ const exists = await contentTypeExists(makeRequest, 'bodyCopy')
189
+ if (!exists) {
190
+ process.stdout.write(
191
+ '[0096] bodyCopy content type does not exist — nothing to delete.\n'
192
+ )
193
+ return
194
+ }
195
+
130
196
  await deleteAllEntriesOfContentType(makeRequest, 'bodyCopy')
131
197
  migration.deleteContentType('bodyCopy')
132
198
  },
@@ -4,9 +4,6 @@ module.exports = {
4
4
  up: function (migration) {
5
5
  const collection = migration.editContentType('containerCollectionModule')
6
6
 
7
- // Delete the variant field from Contentful
8
- collection.deleteField('variant')
9
-
10
7
  // Subheadline field
11
8
  collection.createField('subheadline', {
12
9
  name: 'Subheadline',
@@ -95,8 +95,46 @@ async function deleteEntry(makeRequest, entryId) {
95
95
  }
96
96
  }
97
97
 
98
+ /**
99
+ * Check whether a content type exists on the current environment.
100
+ *
101
+ * @param {Function} makeRequest
102
+ * @param {string} contentTypeId
103
+ * @returns {Promise<boolean>}
104
+ */
105
+ async function contentTypeExists(makeRequest, contentTypeId) {
106
+ try {
107
+ await makeRequest({
108
+ method: 'GET',
109
+ url: `/content_types/${contentTypeId}`,
110
+ })
111
+ return true
112
+ } catch (error) {
113
+ if (
114
+ error?.status === 404 ||
115
+ error?.response?.status === 404 ||
116
+ error?.name === 'NotFound'
117
+ ) {
118
+ return false
119
+ }
120
+ // contentful-sdk-core packs status into error.message JSON
121
+ if (typeof error?.message === 'string') {
122
+ try {
123
+ const parsed = JSON.parse(error.message)
124
+ if (parsed?.status === 404) {
125
+ return false
126
+ }
127
+ } catch {
128
+ // message is not JSON — ignore
129
+ }
130
+ }
131
+ throw error
132
+ }
133
+ }
134
+
98
135
  /**
99
136
  * Delete every entry of the given content type (paginated).
137
+ * Returns early if the content type does not exist (nothing to delete).
100
138
  *
101
139
  * @param {Function} makeRequest
102
140
  * @param {string} contentTypeId
@@ -107,10 +145,30 @@ async function deleteAllEntriesOfContentType(makeRequest, contentTypeId) {
107
145
  // Re-query from skip 0 after each page of deletes — indexes shift as
108
146
  // entries drop, so a single ascending skip walk would miss rows.
109
147
  for (;;) {
110
- const page = await makeRequest({
111
- method: 'GET',
112
- url: `/entries?content_type=${contentTypeId}&limit=${limit}&skip=0&sys.archivedAt[exists]=false`,
113
- })
148
+ let page
149
+ try {
150
+ page = await makeRequest({
151
+ method: 'GET',
152
+ url: `/entries?content_type=${contentTypeId}&limit=${limit}&skip=0&sys.archivedAt[exists]=false`,
153
+ })
154
+ } catch (error) {
155
+ // Contentful returns 400 with unknownContentType when the content
156
+ // type doesn't exist — treat it the same as "no entries".
157
+ const errorMessage =
158
+ typeof error?.message === 'string' ? error.message : ''
159
+ if (
160
+ error?.status === 400 ||
161
+ error?.response?.status === 400 ||
162
+ errorMessage.includes('unknownContentType')
163
+ ) {
164
+ process.stdout.write(
165
+ `[0096] Content type "${contentTypeId}" does not exist ` +
166
+ `or is not queryable — skipping entry deletion.\n`
167
+ )
168
+ return
169
+ }
170
+ throw error
171
+ }
114
172
 
115
173
  const items = page.items ?? []
116
174
  if (items.length === 0) {
@@ -127,6 +185,14 @@ module.exports = {
127
185
  // @ts-check
128
186
  /** @type { import('contentful-migration').MigrationFunction } */
129
187
  up: async function (migration, { makeRequest }) {
188
+ const exists = await contentTypeExists(makeRequest, 'bodyCopy')
189
+ if (!exists) {
190
+ process.stdout.write(
191
+ '[0096] bodyCopy content type does not exist — nothing to delete.\n'
192
+ )
193
+ return
194
+ }
195
+
130
196
  await deleteAllEntriesOfContentType(makeRequest, 'bodyCopy')
131
197
  migration.deleteContentType('bodyCopy')
132
198
  },
@@ -4,9 +4,6 @@ module.exports = {
4
4
  up: function (migration) {
5
5
  const collection = migration.editContentType('containerCollectionModule')
6
6
 
7
- // Delete the variant field from Contentful
8
- collection.deleteField('variant')
9
-
10
7
  // Subheadline field
11
8
  collection.createField('subheadline', {
12
9
  name: 'Subheadline',
@@ -95,8 +95,46 @@ async function deleteEntry(makeRequest, entryId) {
95
95
  }
96
96
  }
97
97
 
98
+ /**
99
+ * Check whether a content type exists on the current environment.
100
+ *
101
+ * @param {Function} makeRequest
102
+ * @param {string} contentTypeId
103
+ * @returns {Promise<boolean>}
104
+ */
105
+ async function contentTypeExists(makeRequest, contentTypeId) {
106
+ try {
107
+ await makeRequest({
108
+ method: 'GET',
109
+ url: `/content_types/${contentTypeId}`,
110
+ })
111
+ return true
112
+ } catch (error) {
113
+ if (
114
+ error?.status === 404 ||
115
+ error?.response?.status === 404 ||
116
+ error?.name === 'NotFound'
117
+ ) {
118
+ return false
119
+ }
120
+ // contentful-sdk-core packs status into error.message JSON
121
+ if (typeof error?.message === 'string') {
122
+ try {
123
+ const parsed = JSON.parse(error.message)
124
+ if (parsed?.status === 404) {
125
+ return false
126
+ }
127
+ } catch {
128
+ // message is not JSON — ignore
129
+ }
130
+ }
131
+ throw error
132
+ }
133
+ }
134
+
98
135
  /**
99
136
  * Delete every entry of the given content type (paginated).
137
+ * Returns early if the content type does not exist (nothing to delete).
100
138
  *
101
139
  * @param {Function} makeRequest
102
140
  * @param {string} contentTypeId
@@ -107,10 +145,30 @@ async function deleteAllEntriesOfContentType(makeRequest, contentTypeId) {
107
145
  // Re-query from skip 0 after each page of deletes — indexes shift as
108
146
  // entries drop, so a single ascending skip walk would miss rows.
109
147
  for (;;) {
110
- const page = await makeRequest({
111
- method: 'GET',
112
- url: `/entries?content_type=${contentTypeId}&limit=${limit}&skip=0&sys.archivedAt[exists]=false`,
113
- })
148
+ let page
149
+ try {
150
+ page = await makeRequest({
151
+ method: 'GET',
152
+ url: `/entries?content_type=${contentTypeId}&limit=${limit}&skip=0&sys.archivedAt[exists]=false`,
153
+ })
154
+ } catch (error) {
155
+ // Contentful returns 400 with unknownContentType when the content
156
+ // type doesn't exist — treat it the same as "no entries".
157
+ const errorMessage =
158
+ typeof error?.message === 'string' ? error.message : ''
159
+ if (
160
+ error?.status === 400 ||
161
+ error?.response?.status === 400 ||
162
+ errorMessage.includes('unknownContentType')
163
+ ) {
164
+ process.stdout.write(
165
+ `[0096] Content type "${contentTypeId}" does not exist ` +
166
+ `or is not queryable — skipping entry deletion.\n`
167
+ )
168
+ return
169
+ }
170
+ throw error
171
+ }
114
172
 
115
173
  const items = page.items ?? []
116
174
  if (items.length === 0) {
@@ -127,6 +185,14 @@ module.exports = {
127
185
  // @ts-check
128
186
  /** @type { import('contentful-migration').MigrationFunction } */
129
187
  up: async function (migration, { makeRequest }) {
188
+ const exists = await contentTypeExists(makeRequest, 'bodyCopy')
189
+ if (!exists) {
190
+ process.stdout.write(
191
+ '[0096] bodyCopy content type does not exist — nothing to delete.\n'
192
+ )
193
+ return
194
+ }
195
+
130
196
  await deleteAllEntriesOfContentType(makeRequest, 'bodyCopy')
131
197
  migration.deleteContentType('bodyCopy')
132
198
  },
@@ -4,9 +4,6 @@ module.exports = {
4
4
  up: function (migration) {
5
5
  const collection = migration.editContentType('containerCollectionModule')
6
6
 
7
- // Delete the variant field from Contentful
8
- collection.deleteField('variant')
9
-
10
7
  // Subheadline field
11
8
  collection.createField('subheadline', {
12
9
  name: 'Subheadline',
@@ -95,8 +95,46 @@ async function deleteEntry(makeRequest, entryId) {
95
95
  }
96
96
  }
97
97
 
98
+ /**
99
+ * Check whether a content type exists on the current environment.
100
+ *
101
+ * @param {Function} makeRequest
102
+ * @param {string} contentTypeId
103
+ * @returns {Promise<boolean>}
104
+ */
105
+ async function contentTypeExists(makeRequest, contentTypeId) {
106
+ try {
107
+ await makeRequest({
108
+ method: 'GET',
109
+ url: `/content_types/${contentTypeId}`,
110
+ })
111
+ return true
112
+ } catch (error) {
113
+ if (
114
+ error?.status === 404 ||
115
+ error?.response?.status === 404 ||
116
+ error?.name === 'NotFound'
117
+ ) {
118
+ return false
119
+ }
120
+ // contentful-sdk-core packs status into error.message JSON
121
+ if (typeof error?.message === 'string') {
122
+ try {
123
+ const parsed = JSON.parse(error.message)
124
+ if (parsed?.status === 404) {
125
+ return false
126
+ }
127
+ } catch {
128
+ // message is not JSON — ignore
129
+ }
130
+ }
131
+ throw error
132
+ }
133
+ }
134
+
98
135
  /**
99
136
  * Delete every entry of the given content type (paginated).
137
+ * Returns early if the content type does not exist (nothing to delete).
100
138
  *
101
139
  * @param {Function} makeRequest
102
140
  * @param {string} contentTypeId
@@ -107,10 +145,30 @@ async function deleteAllEntriesOfContentType(makeRequest, contentTypeId) {
107
145
  // Re-query from skip 0 after each page of deletes — indexes shift as
108
146
  // entries drop, so a single ascending skip walk would miss rows.
109
147
  for (;;) {
110
- const page = await makeRequest({
111
- method: 'GET',
112
- url: `/entries?content_type=${contentTypeId}&limit=${limit}&skip=0&sys.archivedAt[exists]=false`,
113
- })
148
+ let page
149
+ try {
150
+ page = await makeRequest({
151
+ method: 'GET',
152
+ url: `/entries?content_type=${contentTypeId}&limit=${limit}&skip=0&sys.archivedAt[exists]=false`,
153
+ })
154
+ } catch (error) {
155
+ // Contentful returns 400 with unknownContentType when the content
156
+ // type doesn't exist — treat it the same as "no entries".
157
+ const errorMessage =
158
+ typeof error?.message === 'string' ? error.message : ''
159
+ if (
160
+ error?.status === 400 ||
161
+ error?.response?.status === 400 ||
162
+ errorMessage.includes('unknownContentType')
163
+ ) {
164
+ process.stdout.write(
165
+ `[0096] Content type "${contentTypeId}" does not exist ` +
166
+ `or is not queryable — skipping entry deletion.\n`
167
+ )
168
+ return
169
+ }
170
+ throw error
171
+ }
114
172
 
115
173
  const items = page.items ?? []
116
174
  if (items.length === 0) {
@@ -127,6 +185,14 @@ module.exports = {
127
185
  // @ts-check
128
186
  /** @type { import('contentful-migration').MigrationFunction } */
129
187
  up: async function (migration, { makeRequest }) {
188
+ const exists = await contentTypeExists(makeRequest, 'bodyCopy')
189
+ if (!exists) {
190
+ process.stdout.write(
191
+ '[0096] bodyCopy content type does not exist — nothing to delete.\n'
192
+ )
193
+ return
194
+ }
195
+
130
196
  await deleteAllEntriesOfContentType(makeRequest, 'bodyCopy')
131
197
  migration.deleteContentType('bodyCopy')
132
198
  },
@@ -4,9 +4,6 @@ module.exports = {
4
4
  up: function (migration) {
5
5
  const collection = migration.editContentType('containerCollectionModule')
6
6
 
7
- // Delete the variant field from Contentful
8
- collection.deleteField('variant')
9
-
10
7
  // Subheadline field
11
8
  collection.createField('subheadline', {
12
9
  name: 'Subheadline',