@strapi/core 0.0.0-experimental.0e5c9562e7bee0ab55e14e247b87a12c3b0ecb40 → 0.0.0-experimental.0ef52256bbcb9fb8e0689f4b51a6e8356f520184
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.
Potentially problematic release.
This version of @strapi/core might be problematic. Click here for more details.
- package/dist/Strapi.d.ts +1 -0
- package/dist/Strapi.d.ts.map +1 -1
- package/dist/Strapi.js +16 -0
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +16 -0
- package/dist/Strapi.mjs.map +1 -1
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +6 -0
- package/dist/constants.js.map +1 -0
- package/dist/constants.mjs +4 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/core-api/routes/validation/mappers.d.ts.map +1 -1
- package/dist/core-api/routes/validation/mappers.js +35 -0
- package/dist/core-api/routes/validation/mappers.js.map +1 -1
- package/dist/core-api/routes/validation/mappers.mjs +35 -0
- package/dist/core-api/routes/validation/mappers.mjs.map +1 -1
- package/dist/loaders/plugins/index.js +1 -1
- package/dist/loaders/plugins/index.js.map +1 -1
- package/dist/loaders/plugins/index.mjs +1 -1
- package/dist/loaders/plugins/index.mjs.map +1 -1
- package/dist/package.json.js +12 -11
- package/dist/package.json.js.map +1 -1
- package/dist/package.json.mjs +12 -11
- package/dist/package.json.mjs.map +1 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +2 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/index.mjs +2 -0
- package/dist/providers/index.mjs.map +1 -1
- package/dist/providers/session-manager.d.ts +3 -0
- package/dist/providers/session-manager.d.ts.map +1 -0
- package/dist/providers/session-manager.js +23 -0
- package/dist/providers/session-manager.js.map +1 -0
- package/dist/providers/session-manager.mjs +21 -0
- package/dist/providers/session-manager.mjs.map +1 -0
- package/dist/services/content-source-maps.d.ts +2 -1
- package/dist/services/content-source-maps.d.ts.map +1 -1
- package/dist/services/content-source-maps.js +29 -7
- package/dist/services/content-source-maps.js.map +1 -1
- package/dist/services/content-source-maps.mjs +29 -7
- package/dist/services/content-source-maps.mjs.map +1 -1
- package/dist/services/document-service/components.d.ts +26 -1
- package/dist/services/document-service/components.d.ts.map +1 -1
- package/dist/services/document-service/components.js +16 -4
- package/dist/services/document-service/components.js.map +1 -1
- package/dist/services/document-service/components.mjs +15 -5
- package/dist/services/document-service/components.mjs.map +1 -1
- package/dist/services/document-service/utils/clean-component-join-table.d.ts +7 -0
- package/dist/services/document-service/utils/clean-component-join-table.d.ts.map +1 -0
- package/dist/services/document-service/utils/clean-component-join-table.js +138 -0
- package/dist/services/document-service/utils/clean-component-join-table.js.map +1 -0
- package/dist/services/document-service/utils/clean-component-join-table.mjs +136 -0
- package/dist/services/document-service/utils/clean-component-join-table.mjs.map +1 -0
- package/dist/services/metrics/index.js +2 -1
- package/dist/services/metrics/index.js.map +1 -1
- package/dist/services/metrics/index.mjs +2 -1
- package/dist/services/metrics/index.mjs.map +1 -1
- package/dist/services/metrics/middleware.d.ts +2 -1
- package/dist/services/metrics/middleware.d.ts.map +1 -1
- package/dist/services/metrics/middleware.js +2 -2
- package/dist/services/metrics/middleware.js.map +1 -1
- package/dist/services/metrics/middleware.mjs +2 -2
- package/dist/services/metrics/middleware.mjs.map +1 -1
- package/dist/services/session-manager.d.ts +160 -0
- package/dist/services/session-manager.d.ts.map +1 -0
- package/dist/services/session-manager.js +476 -0
- package/dist/services/session-manager.js.map +1 -0
- package/dist/services/session-manager.mjs +473 -0
- package/dist/services/session-manager.mjs.map +1 -0
- package/package.json +12 -11
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var components = require('../components.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Cleans ghost relations with publication state mismatches from a join table
|
|
7
|
+
* Uses schema-based draft/publish checking like prevention fix
|
|
8
|
+
*/ const cleanComponentJoinTable = async (db, joinTableName, relation, sourceModel)=>{
|
|
9
|
+
try {
|
|
10
|
+
// Get the target model metadata
|
|
11
|
+
const targetModel = db.metadata.get(relation.target);
|
|
12
|
+
if (!targetModel) {
|
|
13
|
+
db.logger.debug(`Target model ${relation.target} not found, skipping ${joinTableName}`);
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
// Check if target supports draft/publish using schema-based approach (like prevention fix)
|
|
17
|
+
const targetContentType = strapi.contentTypes[relation.target];
|
|
18
|
+
const targetSupportsDraftPublish = targetContentType?.options?.draftAndPublish || false;
|
|
19
|
+
if (!targetSupportsDraftPublish) {
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
// Find entries with publication state mismatches
|
|
23
|
+
const ghostEntries = await findPublicationStateMismatches(db, joinTableName, relation, targetModel, sourceModel);
|
|
24
|
+
if (ghostEntries.length === 0) {
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
// Remove ghost entries
|
|
28
|
+
await db.connection(joinTableName).whereIn('id', ghostEntries).del();
|
|
29
|
+
db.logger.debug(`Removed ${ghostEntries.length} ghost relations with publication state mismatches from ${joinTableName}`);
|
|
30
|
+
return ghostEntries.length;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
33
|
+
db.logger.error(`Failed to clean join table "${joinTableName}": ${errorMessage}`);
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const findContentTypeParentForComponentInstance = async (componentSchema, componentId)=>{
|
|
38
|
+
// Get the parent schemas that could contain this component
|
|
39
|
+
const parentSchemas = components.getParentSchemasForComponent(componentSchema);
|
|
40
|
+
if (parentSchemas.length === 0) {
|
|
41
|
+
// No potential parents
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
// Find the actual parent for THIS specific component instance
|
|
45
|
+
const parent = await components.findComponentParent(componentSchema, componentId, parentSchemas);
|
|
46
|
+
if (!parent) {
|
|
47
|
+
// No parent found for this component instance
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
if (strapi.components[parent.uid]) {
|
|
51
|
+
// If the parent is a component, we need to check its parents recursively
|
|
52
|
+
const parentComponentSchema = strapi.components[parent.uid];
|
|
53
|
+
return findContentTypeParentForComponentInstance(parentComponentSchema, parent.parentId);
|
|
54
|
+
}
|
|
55
|
+
if (strapi.contentTypes[parent.uid]) {
|
|
56
|
+
// Found a content type parent
|
|
57
|
+
return parent;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Finds join table entries with publication state mismatches
|
|
63
|
+
* Uses existing component parent detection from document service
|
|
64
|
+
*/ const findPublicationStateMismatches = async (db, joinTableName, relation, targetModel, sourceModel)=>{
|
|
65
|
+
try {
|
|
66
|
+
// Get join column names using proper functions (addressing PR feedback)
|
|
67
|
+
const sourceColumn = relation.joinTable.joinColumn.name;
|
|
68
|
+
const targetColumn = relation.joinTable.inverseJoinColumn.name;
|
|
69
|
+
// Get all join entries with their target entities
|
|
70
|
+
const query = db.connection(joinTableName).select(`${joinTableName}.id as join_id`, `${joinTableName}.${sourceColumn} as source_id`, `${joinTableName}.${targetColumn} as target_id`, `${targetModel.tableName}.published_at as target_published_at`).leftJoin(targetModel.tableName, `${joinTableName}.${targetColumn}`, `${targetModel.tableName}.id`);
|
|
71
|
+
const joinEntries = await query;
|
|
72
|
+
// Group by source_id to find duplicates pointing to draft/published versions of same entity
|
|
73
|
+
const entriesBySource = {};
|
|
74
|
+
for (const entry of joinEntries){
|
|
75
|
+
const sourceId = entry.source_id;
|
|
76
|
+
if (!entriesBySource[sourceId]) {
|
|
77
|
+
entriesBySource[sourceId] = [];
|
|
78
|
+
}
|
|
79
|
+
entriesBySource[sourceId].push(entry);
|
|
80
|
+
}
|
|
81
|
+
const ghostEntries = [];
|
|
82
|
+
// Check if this is a join table (ends with _lnk)
|
|
83
|
+
const isRelationJoinTable = joinTableName.endsWith('_lnk');
|
|
84
|
+
const isComponentModel = !sourceModel.uid?.startsWith('api::') && !sourceModel.uid?.startsWith('plugin::') && sourceModel.uid?.includes('.');
|
|
85
|
+
// Check for draft/publish inconsistencies
|
|
86
|
+
for (const [sourceId, entries] of Object.entries(entriesBySource)){
|
|
87
|
+
// Skip entries with single relations
|
|
88
|
+
if (entries.length <= 1) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
// For component join tables, check if THIS specific component instance's parent supports D&P
|
|
92
|
+
if (isRelationJoinTable && isComponentModel) {
|
|
93
|
+
try {
|
|
94
|
+
const componentSchema = strapi.components[sourceModel.uid];
|
|
95
|
+
if (!componentSchema) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const parent = await findContentTypeParentForComponentInstance(componentSchema, sourceId);
|
|
99
|
+
if (!parent) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
// Check if THIS component instance's parent supports draft/publish
|
|
103
|
+
const parentContentType = strapi.contentTypes[parent.uid];
|
|
104
|
+
if (!parentContentType?.options?.draftAndPublish) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
// If we reach here, this component instance's parent DOES support D&P
|
|
108
|
+
// Continue to process this component instance for ghost relations
|
|
109
|
+
} catch (error) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Find ghost relations (same logic as original but with improved parent checking)
|
|
114
|
+
for (const entry of entries){
|
|
115
|
+
if (entry.target_published_at === null) {
|
|
116
|
+
// This is a draft target - find its published version
|
|
117
|
+
const draftTarget = await db.connection(targetModel.tableName).select('document_id').where('id', entry.target_id).first();
|
|
118
|
+
if (draftTarget) {
|
|
119
|
+
const publishedVersion = await db.connection(targetModel.tableName).select('id', 'document_id').where('document_id', draftTarget.document_id).whereNotNull('published_at').first();
|
|
120
|
+
if (publishedVersion) {
|
|
121
|
+
// Check if we also have a relation to the published version
|
|
122
|
+
const publishedRelation = entries.find((e)=>e.target_id === publishedVersion.id);
|
|
123
|
+
if (publishedRelation) {
|
|
124
|
+
ghostEntries.push(publishedRelation.join_id);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return ghostEntries;
|
|
132
|
+
} catch (error) {
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
exports.cleanComponentJoinTable = cleanComponentJoinTable;
|
|
138
|
+
//# sourceMappingURL=clean-component-join-table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clean-component-join-table.js","sources":["../../../../src/services/document-service/utils/clean-component-join-table.ts"],"sourcesContent":["import type { Database } from '@strapi/database';\nimport type { Schema } from '@strapi/types';\nimport { findComponentParent, getParentSchemasForComponent } from '../components';\n\n/**\n * Cleans ghost relations with publication state mismatches from a join table\n * Uses schema-based draft/publish checking like prevention fix\n */\nexport const cleanComponentJoinTable = async (\n db: Database,\n joinTableName: string,\n relation: any,\n sourceModel: any\n): Promise<number> => {\n try {\n // Get the target model metadata\n const targetModel = db.metadata.get(relation.target);\n if (!targetModel) {\n db.logger.debug(`Target model ${relation.target} not found, skipping ${joinTableName}`);\n return 0;\n }\n\n // Check if target supports draft/publish using schema-based approach (like prevention fix)\n const targetContentType =\n strapi.contentTypes[relation.target as keyof typeof strapi.contentTypes];\n const targetSupportsDraftPublish = targetContentType?.options?.draftAndPublish || false;\n\n if (!targetSupportsDraftPublish) {\n return 0;\n }\n\n // Find entries with publication state mismatches\n const ghostEntries = await findPublicationStateMismatches(\n db,\n joinTableName,\n relation,\n targetModel,\n sourceModel\n );\n\n if (ghostEntries.length === 0) {\n return 0;\n }\n\n // Remove ghost entries\n await db.connection(joinTableName).whereIn('id', ghostEntries).del();\n db.logger.debug(\n `Removed ${ghostEntries.length} ghost relations with publication state mismatches from ${joinTableName}`\n );\n\n return ghostEntries.length;\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n db.logger.error(`Failed to clean join table \"${joinTableName}\": ${errorMessage}`);\n return 0;\n }\n};\n\nconst findContentTypeParentForComponentInstance = async (\n componentSchema: Schema.Component,\n componentId: number | string\n): Promise<{ uid: string; table: string; parentId: number | string } | null> => {\n // Get the parent schemas that could contain this component\n const parentSchemas = getParentSchemasForComponent(componentSchema);\n if (parentSchemas.length === 0) {\n // No potential parents\n return null;\n }\n\n // Find the actual parent for THIS specific component instance\n const parent = await findComponentParent(componentSchema, componentId, parentSchemas);\n if (!parent) {\n // No parent found for this component instance\n return null;\n }\n\n if (strapi.components[parent.uid as keyof typeof strapi.components]) {\n // If the parent is a component, we need to check its parents recursively\n const parentComponentSchema = strapi.components[parent.uid as keyof typeof strapi.components];\n return findContentTypeParentForComponentInstance(parentComponentSchema, parent.parentId);\n }\n\n if (strapi.contentTypes[parent.uid as keyof typeof strapi.contentTypes]) {\n // Found a content type parent\n return parent;\n }\n\n return null;\n};\n\n/**\n * Finds join table entries with publication state mismatches\n * Uses existing component parent detection from document service\n */\nconst findPublicationStateMismatches = async (\n db: Database,\n joinTableName: string,\n relation: any,\n targetModel: any,\n sourceModel: any\n): Promise<number[]> => {\n try {\n // Get join column names using proper functions (addressing PR feedback)\n const sourceColumn = relation.joinTable.joinColumn.name;\n const targetColumn = relation.joinTable.inverseJoinColumn.name;\n\n // Get all join entries with their target entities\n const query = db\n .connection(joinTableName)\n .select(\n `${joinTableName}.id as join_id`,\n `${joinTableName}.${sourceColumn} as source_id`,\n `${joinTableName}.${targetColumn} as target_id`,\n `${targetModel.tableName}.published_at as target_published_at`\n )\n .leftJoin(\n targetModel.tableName,\n `${joinTableName}.${targetColumn}`,\n `${targetModel.tableName}.id`\n );\n\n const joinEntries = await query;\n\n // Group by source_id to find duplicates pointing to draft/published versions of same entity\n const entriesBySource: { [key: string]: any[] } = {};\n for (const entry of joinEntries) {\n const sourceId = entry.source_id;\n if (!entriesBySource[sourceId]) {\n entriesBySource[sourceId] = [];\n }\n entriesBySource[sourceId].push(entry);\n }\n\n const ghostEntries: number[] = [];\n\n // Check if this is a join table (ends with _lnk)\n const isRelationJoinTable = joinTableName.endsWith('_lnk');\n const isComponentModel =\n !sourceModel.uid?.startsWith('api::') &&\n !sourceModel.uid?.startsWith('plugin::') &&\n sourceModel.uid?.includes('.');\n\n // Check for draft/publish inconsistencies\n for (const [sourceId, entries] of Object.entries(entriesBySource)) {\n // Skip entries with single relations\n if (entries.length <= 1) {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n // For component join tables, check if THIS specific component instance's parent supports D&P\n if (isRelationJoinTable && isComponentModel) {\n try {\n const componentSchema = strapi.components[sourceModel.uid] as Schema.Component;\n if (!componentSchema) {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n const parent = await findContentTypeParentForComponentInstance(componentSchema, sourceId);\n if (!parent) {\n continue;\n }\n\n // Check if THIS component instance's parent supports draft/publish\n const parentContentType =\n strapi.contentTypes[parent.uid as keyof typeof strapi.contentTypes];\n if (!parentContentType?.options?.draftAndPublish) {\n // This component instance's parent does NOT support D&P - skip cleanup\n // eslint-disable-next-line no-continue\n continue;\n }\n\n // If we reach here, this component instance's parent DOES support D&P\n // Continue to process this component instance for ghost relations\n } catch (error) {\n // Skip this component instance on error\n // eslint-disable-next-line no-continue\n continue;\n }\n }\n\n // Find ghost relations (same logic as original but with improved parent checking)\n for (const entry of entries) {\n if (entry.target_published_at === null) {\n // This is a draft target - find its published version\n const draftTarget = await db\n .connection(targetModel.tableName)\n .select('document_id')\n .where('id', entry.target_id)\n .first();\n\n if (draftTarget) {\n const publishedVersion = await db\n .connection(targetModel.tableName)\n .select('id', 'document_id')\n .where('document_id', draftTarget.document_id)\n .whereNotNull('published_at')\n .first();\n\n if (publishedVersion) {\n // Check if we also have a relation to the published version\n const publishedRelation = entries.find((e) => e.target_id === publishedVersion.id);\n if (publishedRelation) {\n ghostEntries.push(publishedRelation.join_id);\n }\n }\n }\n }\n }\n }\n\n return ghostEntries;\n } catch (error) {\n return [];\n }\n};\n"],"names":["cleanComponentJoinTable","db","joinTableName","relation","sourceModel","targetModel","metadata","get","target","logger","debug","targetContentType","strapi","contentTypes","targetSupportsDraftPublish","options","draftAndPublish","ghostEntries","findPublicationStateMismatches","length","connection","whereIn","del","error","errorMessage","Error","message","String","findContentTypeParentForComponentInstance","componentSchema","componentId","parentSchemas","getParentSchemasForComponent","parent","findComponentParent","components","uid","parentComponentSchema","parentId","sourceColumn","joinTable","joinColumn","name","targetColumn","inverseJoinColumn","query","select","tableName","leftJoin","joinEntries","entriesBySource","entry","sourceId","source_id","push","isRelationJoinTable","endsWith","isComponentModel","startsWith","includes","entries","Object","parentContentType","target_published_at","draftTarget","where","target_id","first","publishedVersion","document_id","whereNotNull","publishedRelation","find","e","id","join_id"],"mappings":";;;;AAIA;;;AAGC,IACYA,MAAAA,uBAAAA,GAA0B,OACrCC,EAAAA,EACAC,eACAC,QACAC,EAAAA,WAAAA,GAAAA;IAEA,IAAI;;AAEF,QAAA,MAAMC,cAAcJ,EAAGK,CAAAA,QAAQ,CAACC,GAAG,CAACJ,SAASK,MAAM,CAAA;AACnD,QAAA,IAAI,CAACH,WAAa,EAAA;AAChBJ,YAAAA,EAAAA,CAAGQ,MAAM,CAACC,KAAK,CAAC,CAAC,aAAa,EAAEP,QAAAA,CAASK,MAAM,CAAC,qBAAqB,EAAEN,cAAc,CAAC,CAAA;YACtF,OAAO,CAAA;AACT;;AAGA,QAAA,MAAMS,oBACJC,MAAOC,CAAAA,YAAY,CAACV,QAAAA,CAASK,MAAM,CAAqC;QAC1E,MAAMM,0BAAAA,GAA6BH,iBAAmBI,EAAAA,OAAAA,EAASC,eAAmB,IAAA,KAAA;AAElF,QAAA,IAAI,CAACF,0BAA4B,EAAA;YAC/B,OAAO,CAAA;AACT;;AAGA,QAAA,MAAMG,eAAe,MAAMC,8BAAAA,CACzBjB,EACAC,EAAAA,aAAAA,EACAC,UACAE,WAC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IT,KAAAA,CAAMY,mBAAmB,KAAK,IAAM,EAAA;;AAEtC,oBAAA,MAAMC,cAAc,MAAM/D,EAAAA,CACvBmB,UAAU,CAACf,YAAY0C,SAAS,CAAA,CAChCD,MAAM,CAAC,eACPmB,KAAK,CAAC,MAAMd,KAAMe,CAAAA,SAAS,EAC3BC,KAAK,EAAA;AAER,oBAAA,IAAIH,WAAa,EAAA;wBACf,MAAMI,gBAAAA,GAAmB,MAAMnE,EAC5BmB,CAAAA,UAAU,CAACf,WAAY0C,CAAAA,SAAS,EAChCD,MAAM,CAAC,MAAM,aACbmB,CAAAA,CAAAA,KAAK,CAAC,aAAeD,EAAAA,WAAAA,CAAYK,WAAW,CAC5CC,CAAAA,YAAY,CAAC,cAAA,CAAA,CACbH,KAAK,EAAA;AAER,wBAAA,IAAIC,gBAAkB,EAAA;;4BAEpB,MAAMG,iBAAAA,GAAoBX,OAAQY,CAAAA,IAAI,CAAC,CAACC,IAAMA,CAAEP,CAAAA,SAAS,KAAKE,gBAAAA,CAAiBM,EAAE,CAAA;AACjF,4BAAA,IAAIH,iBAAmB,EAAA;gCACrBtD,YAAaqC,CAAAA,IAAI,CAACiB,iBAAAA,CAAkBI,OAAO,CAAA;AAC7C;AACF;AACF;AACF;AACF;AACF;QAEA,OAAO1D,YAAAA;AACT,KAAA,CAAE,OAAOM,KAAO,EAAA;AACd,QAAA,OAAO,EAAE;AACX;AACF,CAAA;;;;"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { getParentSchemasForComponent, findComponentParent } from '../components.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cleans ghost relations with publication state mismatches from a join table
|
|
5
|
+
* Uses schema-based draft/publish checking like prevention fix
|
|
6
|
+
*/ const cleanComponentJoinTable = async (db, joinTableName, relation, sourceModel)=>{
|
|
7
|
+
try {
|
|
8
|
+
// Get the target model metadata
|
|
9
|
+
const targetModel = db.metadata.get(relation.target);
|
|
10
|
+
if (!targetModel) {
|
|
11
|
+
db.logger.debug(`Target model ${relation.target} not found, skipping ${joinTableName}`);
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
// Check if target supports draft/publish using schema-based approach (like prevention fix)
|
|
15
|
+
const targetContentType = strapi.contentTypes[relation.target];
|
|
16
|
+
const targetSupportsDraftPublish = targetContentType?.options?.draftAndPublish || false;
|
|
17
|
+
if (!targetSupportsDraftPublish) {
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
// Find entries with publication state mismatches
|
|
21
|
+
const ghostEntries = await findPublicationStateMismatches(db, joinTableName, relation, targetModel, sourceModel);
|
|
22
|
+
if (ghostEntries.length === 0) {
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
// Remove ghost entries
|
|
26
|
+
await db.connection(joinTableName).whereIn('id', ghostEntries).del();
|
|
27
|
+
db.logger.debug(`Removed ${ghostEntries.length} ghost relations with publication state mismatches from ${joinTableName}`);
|
|
28
|
+
return ghostEntries.length;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
31
|
+
db.logger.error(`Failed to clean join table "${joinTableName}": ${errorMessage}`);
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const findContentTypeParentForComponentInstance = async (componentSchema, componentId)=>{
|
|
36
|
+
// Get the parent schemas that could contain this component
|
|
37
|
+
const parentSchemas = getParentSchemasForComponent(componentSchema);
|
|
38
|
+
if (parentSchemas.length === 0) {
|
|
39
|
+
// No potential parents
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
// Find the actual parent for THIS specific component instance
|
|
43
|
+
const parent = await findComponentParent(componentSchema, componentId, parentSchemas);
|
|
44
|
+
if (!parent) {
|
|
45
|
+
// No parent found for this component instance
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
if (strapi.components[parent.uid]) {
|
|
49
|
+
// If the parent is a component, we need to check its parents recursively
|
|
50
|
+
const parentComponentSchema = strapi.components[parent.uid];
|
|
51
|
+
return findContentTypeParentForComponentInstance(parentComponentSchema, parent.parentId);
|
|
52
|
+
}
|
|
53
|
+
if (strapi.contentTypes[parent.uid]) {
|
|
54
|
+
// Found a content type parent
|
|
55
|
+
return parent;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Finds join table entries with publication state mismatches
|
|
61
|
+
* Uses existing component parent detection from document service
|
|
62
|
+
*/ const findPublicationStateMismatches = async (db, joinTableName, relation, targetModel, sourceModel)=>{
|
|
63
|
+
try {
|
|
64
|
+
// Get join column names using proper functions (addressing PR feedback)
|
|
65
|
+
const sourceColumn = relation.joinTable.joinColumn.name;
|
|
66
|
+
const targetColumn = relation.joinTable.inverseJoinColumn.name;
|
|
67
|
+
// Get all join entries with their target entities
|
|
68
|
+
const query = db.connection(joinTableName).select(`${joinTableName}.id as join_id`, `${joinTableName}.${sourceColumn} as source_id`, `${joinTableName}.${targetColumn} as target_id`, `${targetModel.tableName}.published_at as target_published_at`).leftJoin(targetModel.tableName, `${joinTableName}.${targetColumn}`, `${targetModel.tableName}.id`);
|
|
69
|
+
const joinEntries = await query;
|
|
70
|
+
// Group by source_id to find duplicates pointing to draft/published versions of same entity
|
|
71
|
+
const entriesBySource = {};
|
|
72
|
+
for (const entry of joinEntries){
|
|
73
|
+
const sourceId = entry.source_id;
|
|
74
|
+
if (!entriesBySource[sourceId]) {
|
|
75
|
+
entriesBySource[sourceId] = [];
|
|
76
|
+
}
|
|
77
|
+
entriesBySource[sourceId].push(entry);
|
|
78
|
+
}
|
|
79
|
+
const ghostEntries = [];
|
|
80
|
+
// Check if this is a join table (ends with _lnk)
|
|
81
|
+
const isRelationJoinTable = joinTableName.endsWith('_lnk');
|
|
82
|
+
const isComponentModel = !sourceModel.uid?.startsWith('api::') && !sourceModel.uid?.startsWith('plugin::') && sourceModel.uid?.includes('.');
|
|
83
|
+
// Check for draft/publish inconsistencies
|
|
84
|
+
for (const [sourceId, entries] of Object.entries(entriesBySource)){
|
|
85
|
+
// Skip entries with single relations
|
|
86
|
+
if (entries.length <= 1) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
// For component join tables, check if THIS specific component instance's parent supports D&P
|
|
90
|
+
if (isRelationJoinTable && isComponentModel) {
|
|
91
|
+
try {
|
|
92
|
+
const componentSchema = strapi.components[sourceModel.uid];
|
|
93
|
+
if (!componentSchema) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const parent = await findContentTypeParentForComponentInstance(componentSchema, sourceId);
|
|
97
|
+
if (!parent) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
// Check if THIS component instance's parent supports draft/publish
|
|
101
|
+
const parentContentType = strapi.contentTypes[parent.uid];
|
|
102
|
+
if (!parentContentType?.options?.draftAndPublish) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
// If we reach here, this component instance's parent DOES support D&P
|
|
106
|
+
// Continue to process this component instance for ghost relations
|
|
107
|
+
} catch (error) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Find ghost relations (same logic as original but with improved parent checking)
|
|
112
|
+
for (const entry of entries){
|
|
113
|
+
if (entry.target_published_at === null) {
|
|
114
|
+
// This is a draft target - find its published version
|
|
115
|
+
const draftTarget = await db.connection(targetModel.tableName).select('document_id').where('id', entry.target_id).first();
|
|
116
|
+
if (draftTarget) {
|
|
117
|
+
const publishedVersion = await db.connection(targetModel.tableName).select('id', 'document_id').where('document_id', draftTarget.document_id).whereNotNull('published_at').first();
|
|
118
|
+
if (publishedVersion) {
|
|
119
|
+
// Check if we also have a relation to the published version
|
|
120
|
+
const publishedRelation = entries.find((e)=>e.target_id === publishedVersion.id);
|
|
121
|
+
if (publishedRelation) {
|
|
122
|
+
ghostEntries.push(publishedRelation.join_id);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return ghostEntries;
|
|
130
|
+
} catch (error) {
|
|
131
|
+
return [];
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export { cleanComponentJoinTable };
|
|
136
|
+
//# sourceMappingURL=clean-component-join-table.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clean-component-join-table.mjs","sources":["../../../../src/services/document-service/utils/clean-component-join-table.ts"],"sourcesContent":["import type { Database } from '@strapi/database';\nimport type { Schema } from '@strapi/types';\nimport { findComponentParent, getParentSchemasForComponent } from '../components';\n\n/**\n * Cleans ghost relations with publication state mismatches from a join table\n * Uses schema-based draft/publish checking like prevention fix\n */\nexport const cleanComponentJoinTable = async (\n db: Database,\n joinTableName: string,\n relation: any,\n sourceModel: any\n): Promise<number> => {\n try {\n // Get the target model metadata\n const targetModel = db.metadata.get(relation.target);\n if (!targetModel) {\n db.logger.debug(`Target model ${relation.target} not found, skipping ${joinTableName}`);\n return 0;\n }\n\n // Check if target supports draft/publish using schema-based approach (like prevention fix)\n const targetContentType =\n strapi.contentTypes[relation.target as keyof typeof strapi.contentTypes];\n const targetSupportsDraftPublish = targetContentType?.options?.draftAndPublish || false;\n\n if (!targetSupportsDraftPublish) {\n return 0;\n }\n\n // Find entries with publication state mismatches\n const ghostEntries = await findPublicationStateMismatches(\n db,\n joinTableName,\n relation,\n targetModel,\n sourceModel\n );\n\n if (ghostEntries.length === 0) {\n return 0;\n }\n\n // Remove ghost entries\n await db.connection(joinTableName).whereIn('id', ghostEntries).del();\n db.logger.debug(\n `Removed ${ghostEntries.length} ghost relations with publication state mismatches from ${joinTableName}`\n );\n\n return ghostEntries.length;\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n db.logger.error(`Failed to clean join table \"${joinTableName}\": ${errorMessage}`);\n return 0;\n }\n};\n\nconst findContentTypeParentForComponentInstance = async (\n componentSchema: Schema.Component,\n componentId: number | string\n): Promise<{ uid: string; table: string; parentId: number | string } | null> => {\n // Get the parent schemas that could contain this component\n const parentSchemas = getParentSchemasForComponent(componentSchema);\n if (parentSchemas.length === 0) {\n // No potential parents\n return null;\n }\n\n // Find the actual parent for THIS specific component instance\n const parent = await findComponentParent(componentSchema, componentId, parentSchemas);\n if (!parent) {\n // No parent found for this component instance\n return null;\n }\n\n if (strapi.components[parent.uid as keyof typeof strapi.components]) {\n // If the parent is a component, we need to check its parents recursively\n const parentComponentSchema = strapi.components[parent.uid as keyof typeof strapi.components];\n return findContentTypeParentForComponentInstance(parentComponentSchema, parent.parentId);\n }\n\n if (strapi.contentTypes[parent.uid as keyof typeof strapi.contentTypes]) {\n // Found a content type parent\n return parent;\n }\n\n return null;\n};\n\n/**\n * Finds join table entries with publication state mismatches\n * Uses existing component parent detection from document service\n */\nconst findPublicationStateMismatches = async (\n db: Database,\n joinTableName: string,\n relation: any,\n targetModel: any,\n sourceModel: any\n): Promise<number[]> => {\n try {\n // Get join column names using proper functions (addressing PR feedback)\n const sourceColumn = relation.joinTable.joinColumn.name;\n const targetColumn = relation.joinTable.inverseJoinColumn.name;\n\n // Get all join entries with their target entities\n const query = db\n .connection(joinTableName)\n .select(\n `${joinTableName}.id as join_id`,\n `${joinTableName}.${sourceColumn} as source_id`,\n `${joinTableName}.${targetColumn} as target_id`,\n `${targetModel.tableName}.published_at as target_published_at`\n )\n .leftJoin(\n targetModel.tableName,\n `${joinTableName}.${targetColumn}`,\n `${targetModel.tableName}.id`\n );\n\n const joinEntries = await query;\n\n // Group by source_id to find duplicates pointing to draft/published versions of same entity\n const entriesBySource: { [key: string]: any[] } = {};\n for (const entry of joinEntries) {\n const sourceId = entry.source_id;\n if (!entriesBySource[sourceId]) {\n entriesBySource[sourceId] = [];\n }\n entriesBySource[sourceId].push(entry);\n }\n\n const ghostEntries: number[] = [];\n\n // Check if this is a join table (ends with _lnk)\n const isRelationJoinTable = joinTableName.endsWith('_lnk');\n const isComponentModel =\n !sourceModel.uid?.startsWith('api::') &&\n !sourceModel.uid?.startsWith('plugin::') &&\n sourceModel.uid?.includes('.');\n\n // Check for draft/publish inconsistencies\n for (const [sourceId, entries] of Object.entries(entriesBySource)) {\n // Skip entries with single relations\n if (entries.length <= 1) {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n // For component join tables, check if THIS specific component instance's parent supports D&P\n if (isRelationJoinTable && isComponentModel) {\n try {\n const componentSchema = strapi.components[sourceModel.uid] as Schema.Component;\n if (!componentSchema) {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n const parent = await findContentTypeParentForComponentInstance(componentSchema, sourceId);\n if (!parent) {\n continue;\n }\n\n // Check if THIS component instance's parent supports draft/publish\n const parentContentType =\n strapi.contentTypes[parent.uid as keyof typeof strapi.contentTypes];\n if (!parentContentType?.options?.draftAndPublish) {\n // This component instance's parent does NOT support D&P - skip cleanup\n // eslint-disable-next-line no-continue\n continue;\n }\n\n // If we reach here, this component instance's parent DOES support D&P\n // Continue to process this component instance for ghost relations\n } catch (error) {\n // Skip this component instance on error\n // eslint-disable-next-line no-continue\n continue;\n }\n }\n\n // Find ghost relations (same logic as original but with improved parent checking)\n for (const entry of entries) {\n if (entry.target_published_at === null) {\n // This is a draft target - find its published version\n const draftTarget = await db\n .connection(targetModel.tableName)\n .select('document_id')\n .where('id', entry.target_id)\n .first();\n\n if (draftTarget) {\n const publishedVersion = await db\n .connection(targetModel.tableName)\n .select('id', 'document_id')\n .where('document_id', draftTarget.document_id)\n .whereNotNull('published_at')\n .first();\n\n if (publishedVersion) {\n // Check if we also have a relation to the published version\n const publishedRelation = entries.find((e) => e.target_id === publishedVersion.id);\n if (publishedRelation) {\n ghostEntries.push(publishedRelation.join_id);\n }\n }\n }\n }\n }\n }\n\n return ghostEntries;\n } catch (error) {\n return [];\n }\n};\n"],"names":["cleanComponentJoinTable","db","joinTableName","relation","sourceModel","targetModel","metadata","get","target","logger","debug","targetContentType","strapi","contentTypes","targetSupportsDraftPublish","options","draftAndPublish","ghostEntries","findPublicationStateMismatches","length","connection","whereIn","del","error","errorMessage","Error","message","String","findContentTypeParentForComponentInstance","componentSchema","componentId","parentSchemas","getParentSchemasForComponent","parent","findComponentParent","components","uid","parentComponentSchema","parentId","sourceColumn","joinTable","joinColumn","name","targetColumn","inverseJoinColumn","query","select","tableName","leftJoin","joinEntries","entriesBySource","entry","sourceId","source_id","push","isRelationJoinTable","endsWith","isComponentModel","startsWith","includes","entries","Object","parentContentType","target_published_at","draftTarget","where","target_id","first","publishedVersion","document_id","whereNotNull","publishedRelation","find","e","id","join_id"],"mappings":";;AAIA;;;AAGC,IACYA,MAAAA,uBAAAA,GAA0B,OACrCC,EAAAA,EACAC,eACAC,QACAC,EAAAA,WAAAA,GAAAA;IAEA,IAAI;;AAEF,QAAA,MAAMC,cAAcJ,EAAGK,CAAAA,QAAQ,CAACC,GAAG,CAACJ,SAASK,MAAM,CAAA;AACnD,QAAA,IAAI,CAACH,WAAa,EAAA;AAChBJ,YAAAA,EAAAA,CAAGQ,MAAM,CAACC,KAAK,CAAC,CAAC,aAAa,EAAEP,QAAAA,CAASK,MAAM,CAAC,qBAAqB,EAAEN,cAAc,CAAC,CAAA;YACtF,OAAO,CAAA;AACT;;AAGA,QAAA,MAAMS,oBACJC,MAAOC,CAAAA,YAAY,CAACV,QAAAA,CAASK,MAAM,CAAqC;QAC1E,MAAMM,0BAAAA,GAA6BH,iBAAmBI,EAAAA,OAAAA,EAASC,eAAmB,IAAA,KAAA;AAElF,QAAA,IAAI,CAACF,0BAA4B,EAAA;YAC/B,OAAO,CAAA;AACT;;AAGA,QAAA,MAAMG,eAAe,MAAMC,8BAAAA,CACzBjB,EACAC,EAAAA,aAAAA,EACAC,UACAE,WACAD,EAAAA,WAAAA,CAAAA;QAGF,IAAIa,YAAAA,CAAaE,MAAM,KAAK,CAAG,EAAA;YAC7B,OAAO,CAAA;AACT;;QAGA,MAAMlB,EAAAA,CAAGmB,UAAU,CAAClB,aAAAA,CAAAA,CAAemB,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,MAAMd,KAAMe,CAAAA,SAAS,EAC3BC,KAAK,EAAA;AAER,oBAAA,IAAIH,WAAa,EAAA;wBACf,MAAMI,gBAAAA,GAAmB,MAAMnE,EAC5BmB,CAAAA,UAAU,CAACf,WAAY0C,CAAAA,SAAS,EAChCD,MAAM,CAAC,MAAM,aACbmB,CAAAA,CAAAA,KAAK,CAAC,aAAeD,EAAAA,WAAAA,CAAYK,WAAW,CAC5CC,CAAAA,YAAY,CAAC,cAAA,CAAA,CACbH,KAAK,EAAA;AAER,wBAAA,IAAIC,gBAAkB,EAAA;;4BAEpB,MAAMG,iBAAAA,GAAoBX,OAAQY,CAAAA,IAAI,CAAC,CAACC,IAAMA,CAAEP,CAAAA,SAAS,KAAKE,gBAAAA,CAAiBM,EAAE,CAAA;AACjF,4BAAA,IAAIH,iBAAmB,EAAA;gCACrBtD,YAAaqC,CAAAA,IAAI,CAACiB,iBAAAA,CAAkBI,OAAO,CAAA;AAC7C;AACF;AACF;AACF;AACF;AACF;QAEA,OAAO1D,YAAAA;AACT,KAAA,CAAE,OAAOM,KAAO,EAAA;AACd,QAAA,OAAO,EAAE;AACX;AACF,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/services/metrics/index.ts"],"sourcesContent":["/**\n * Strapi telemetry package.\n * You can learn more at https://docs.strapi.io/developer-docs/latest/getting-started/usage-information.html\n */\n\nimport type { Core } from '@strapi/types';\n\nimport wrapWithRateLimit from './rate-limiter';\nimport createSender from './sender';\nimport createMiddleware from './middleware';\nimport isTruthy from './is-truthy';\n\nconst LIMITED_EVENTS = [\n 'didSaveMediaWithAlternativeText',\n 'didSaveMediaWithCaption',\n 'didDisableResponsiveDimensions',\n 'didEnableResponsiveDimensions',\n 'didInitializePluginUpload',\n];\n\nconst createTelemetryInstance = (strapi: Core.Strapi) => {\n const uuid = strapi.config.get('uuid');\n const telemetryDisabled = strapi.config.get('packageJsonStrapi.telemetryDisabled');\n const isDisabled =\n !uuid || isTruthy(process.env.STRAPI_TELEMETRY_DISABLED) || isTruthy(telemetryDisabled);\n\n const sender = createSender(strapi);\n const sendEvent = wrapWithRateLimit(sender, { limitedEvents: LIMITED_EVENTS });\n\n return {\n get isDisabled() {\n return isDisabled;\n },\n\n register() {\n if (!isDisabled) {\n strapi.cron.add({\n sendPingEvent: {\n task: () => sendEvent('ping'),\n options: '0 0 12 * * *',\n },\n });\n\n strapi.server.use(createMiddleware({ sendEvent }));\n }\n },\n\n bootstrap() {},\n\n async send(event: string, payload: Record<string, unknown> = {}) {\n if (isDisabled) return true;\n return sendEvent(event, payload);\n },\n\n destroy() {\n // Clean up resources if needed\n },\n };\n};\n\nexport default createTelemetryInstance;\n"],"names":["LIMITED_EVENTS","createTelemetryInstance","strapi","uuid","config","get","telemetryDisabled","isDisabled","isTruthy","process","env","STRAPI_TELEMETRY_DISABLED","sender","createSender","sendEvent","wrapWithRateLimit","limitedEvents","register","cron","add","sendPingEvent","task","options","server","use","createMiddleware","bootstrap","send","event","payload","destroy"],"mappings":";;;;;;;AAYA,MAAMA,cAAiB,GAAA;AACrB,IAAA,iCAAA;AACA,IAAA,yBAAA;AACA,IAAA,gCAAA;AACA,IAAA,+BAAA;AACA,IAAA;AACD,CAAA;AAED,MAAMC,0BAA0B,CAACC,MAAAA,GAAAA;AAC/B,IAAA,MAAMC,IAAOD,GAAAA,MAAAA,CAAOE,MAAM,CAACC,GAAG,CAAC,MAAA,CAAA;AAC/B,IAAA,MAAMC,iBAAoBJ,GAAAA,MAAAA,CAAOE,MAAM,CAACC,GAAG,CAAC,qCAAA,CAAA;IAC5C,MAAME,UAAAA,GACJ,CAACJ,IAAQK,IAAAA,QAAAA,CAASC,QAAQC,GAAG,CAACC,yBAAyB,CAAA,IAAKH,QAASF,CAAAA,iBAAAA,CAAAA;AAEvE,IAAA,MAAMM,WAASC,MAAaX,CAAAA,MAAAA,CAAAA;IAC5B,MAAMY,SAAAA,GAAYC,YAAkBH,QAAQ,EAAA;QAAEI,aAAehB,EAAAA;AAAe,KAAA,CAAA;IAE5E,OAAO;AACL,QAAA,IAAIO,UAAa,CAAA,GAAA;YACf,OAAOA,UAAAA;AACT,SAAA;AAEAU,QAAAA,QAAAA,CAAAA,GAAAA;AACE,YAAA,IAAI,CAACV,UAAY,EAAA;gBACfL,MAAOgB,CAAAA,IAAI,CAACC,GAAG,CAAC;oBACdC,aAAe,EAAA;AACbC,wBAAAA,IAAAA,EAAM,IAAMP,SAAU,CAAA,MAAA,CAAA;wBACtBQ,OAAS,EAAA;AACX;AACF,iBAAA,CAAA;AAEApB,gBAAAA,MAAAA,CAAOqB,MAAM,CAACC,GAAG,CAACC,UAAiB,CAAA;AAAEX,oBAAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/services/metrics/index.ts"],"sourcesContent":["/**\n * Strapi telemetry package.\n * You can learn more at https://docs.strapi.io/developer-docs/latest/getting-started/usage-information.html\n */\n\nimport type { Core } from '@strapi/types';\n\nimport wrapWithRateLimit from './rate-limiter';\nimport createSender from './sender';\nimport createMiddleware from './middleware';\nimport isTruthy from './is-truthy';\n\nconst LIMITED_EVENTS = [\n 'didSaveMediaWithAlternativeText',\n 'didSaveMediaWithCaption',\n 'didDisableResponsiveDimensions',\n 'didEnableResponsiveDimensions',\n 'didInitializePluginUpload',\n];\n\nconst createTelemetryInstance = (strapi: Core.Strapi) => {\n const uuid = strapi.config.get('uuid');\n const telemetryDisabled = strapi.config.get('packageJsonStrapi.telemetryDisabled');\n const isDisabled =\n !uuid || isTruthy(process.env.STRAPI_TELEMETRY_DISABLED) || isTruthy(telemetryDisabled);\n\n const sender = createSender(strapi);\n const sendEvent = wrapWithRateLimit(sender, { limitedEvents: LIMITED_EVENTS });\n\n return {\n get isDisabled() {\n return isDisabled;\n },\n\n register() {\n if (!isDisabled) {\n strapi.cron.add({\n sendPingEvent: {\n task: () => sendEvent('ping'),\n options: '0 0 12 * * *',\n },\n });\n\n strapi.server.use(createMiddleware({ sendEvent, strapi }));\n }\n },\n\n bootstrap() {},\n\n async send(event: string, payload: Record<string, unknown> = {}) {\n if (isDisabled) return true;\n return sendEvent(event, payload);\n },\n\n destroy() {\n // Clean up resources if needed\n },\n };\n};\n\nexport default createTelemetryInstance;\n"],"names":["LIMITED_EVENTS","createTelemetryInstance","strapi","uuid","config","get","telemetryDisabled","isDisabled","isTruthy","process","env","STRAPI_TELEMETRY_DISABLED","sender","createSender","sendEvent","wrapWithRateLimit","limitedEvents","register","cron","add","sendPingEvent","task","options","server","use","createMiddleware","bootstrap","send","event","payload","destroy"],"mappings":";;;;;;;AAYA,MAAMA,cAAiB,GAAA;AACrB,IAAA,iCAAA;AACA,IAAA,yBAAA;AACA,IAAA,gCAAA;AACA,IAAA,+BAAA;AACA,IAAA;AACD,CAAA;AAED,MAAMC,0BAA0B,CAACC,MAAAA,GAAAA;AAC/B,IAAA,MAAMC,IAAOD,GAAAA,MAAAA,CAAOE,MAAM,CAACC,GAAG,CAAC,MAAA,CAAA;AAC/B,IAAA,MAAMC,iBAAoBJ,GAAAA,MAAAA,CAAOE,MAAM,CAACC,GAAG,CAAC,qCAAA,CAAA;IAC5C,MAAME,UAAAA,GACJ,CAACJ,IAAQK,IAAAA,QAAAA,CAASC,QAAQC,GAAG,CAACC,yBAAyB,CAAA,IAAKH,QAASF,CAAAA,iBAAAA,CAAAA;AAEvE,IAAA,MAAMM,WAASC,MAAaX,CAAAA,MAAAA,CAAAA;IAC5B,MAAMY,SAAAA,GAAYC,YAAkBH,QAAQ,EAAA;QAAEI,aAAehB,EAAAA;AAAe,KAAA,CAAA;IAE5E,OAAO;AACL,QAAA,IAAIO,UAAa,CAAA,GAAA;YACf,OAAOA,UAAAA;AACT,SAAA;AAEAU,QAAAA,QAAAA,CAAAA,GAAAA;AACE,YAAA,IAAI,CAACV,UAAY,EAAA;gBACfL,MAAOgB,CAAAA,IAAI,CAACC,GAAG,CAAC;oBACdC,aAAe,EAAA;AACbC,wBAAAA,IAAAA,EAAM,IAAMP,SAAU,CAAA,MAAA,CAAA;wBACtBQ,OAAS,EAAA;AACX;AACF,iBAAA,CAAA;AAEApB,gBAAAA,MAAAA,CAAOqB,MAAM,CAACC,GAAG,CAACC,UAAiB,CAAA;AAAEX,oBAAAA,SAAAA;AAAWZ,oBAAAA;AAAO,iBAAA,CAAA,CAAA;AACzD;AACF,SAAA;QAEAwB,SAAa,CAAA,GAAA,EAAA;AAEb,QAAA,MAAMC,IAAKC,CAAAA,CAAAA,KAAa,EAAEC,OAAAA,GAAmC,EAAE,EAAA;AAC7D,YAAA,IAAItB,YAAY,OAAO,IAAA;AACvB,YAAA,OAAOO,UAAUc,KAAOC,EAAAA,OAAAA,CAAAA;AAC1B,SAAA;AAEAC,QAAAA,OAAAA,CAAAA,GAAAA;;AAEA;AACF,KAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/services/metrics/index.ts"],"sourcesContent":["/**\n * Strapi telemetry package.\n * You can learn more at https://docs.strapi.io/developer-docs/latest/getting-started/usage-information.html\n */\n\nimport type { Core } from '@strapi/types';\n\nimport wrapWithRateLimit from './rate-limiter';\nimport createSender from './sender';\nimport createMiddleware from './middleware';\nimport isTruthy from './is-truthy';\n\nconst LIMITED_EVENTS = [\n 'didSaveMediaWithAlternativeText',\n 'didSaveMediaWithCaption',\n 'didDisableResponsiveDimensions',\n 'didEnableResponsiveDimensions',\n 'didInitializePluginUpload',\n];\n\nconst createTelemetryInstance = (strapi: Core.Strapi) => {\n const uuid = strapi.config.get('uuid');\n const telemetryDisabled = strapi.config.get('packageJsonStrapi.telemetryDisabled');\n const isDisabled =\n !uuid || isTruthy(process.env.STRAPI_TELEMETRY_DISABLED) || isTruthy(telemetryDisabled);\n\n const sender = createSender(strapi);\n const sendEvent = wrapWithRateLimit(sender, { limitedEvents: LIMITED_EVENTS });\n\n return {\n get isDisabled() {\n return isDisabled;\n },\n\n register() {\n if (!isDisabled) {\n strapi.cron.add({\n sendPingEvent: {\n task: () => sendEvent('ping'),\n options: '0 0 12 * * *',\n },\n });\n\n strapi.server.use(createMiddleware({ sendEvent }));\n }\n },\n\n bootstrap() {},\n\n async send(event: string, payload: Record<string, unknown> = {}) {\n if (isDisabled) return true;\n return sendEvent(event, payload);\n },\n\n destroy() {\n // Clean up resources if needed\n },\n };\n};\n\nexport default createTelemetryInstance;\n"],"names":["LIMITED_EVENTS","createTelemetryInstance","strapi","uuid","config","get","telemetryDisabled","isDisabled","isTruthy","process","env","STRAPI_TELEMETRY_DISABLED","sender","createSender","sendEvent","wrapWithRateLimit","limitedEvents","register","cron","add","sendPingEvent","task","options","server","use","createMiddleware","bootstrap","send","event","payload","destroy"],"mappings":";;;;;AAYA,MAAMA,cAAiB,GAAA;AACrB,IAAA,iCAAA;AACA,IAAA,yBAAA;AACA,IAAA,gCAAA;AACA,IAAA,+BAAA;AACA,IAAA;AACD,CAAA;AAED,MAAMC,0BAA0B,CAACC,MAAAA,GAAAA;AAC/B,IAAA,MAAMC,IAAOD,GAAAA,MAAAA,CAAOE,MAAM,CAACC,GAAG,CAAC,MAAA,CAAA;AAC/B,IAAA,MAAMC,iBAAoBJ,GAAAA,MAAAA,CAAOE,MAAM,CAACC,GAAG,CAAC,qCAAA,CAAA;IAC5C,MAAME,UAAAA,GACJ,CAACJ,IAAQK,IAAAA,QAAAA,CAASC,QAAQC,GAAG,CAACC,yBAAyB,CAAA,IAAKH,QAASF,CAAAA,iBAAAA,CAAAA;AAEvE,IAAA,MAAMM,SAASC,YAAaX,CAAAA,MAAAA,CAAAA;IAC5B,MAAMY,SAAAA,GAAYC,kBAAkBH,MAAQ,EAAA;QAAEI,aAAehB,EAAAA;AAAe,KAAA,CAAA;IAE5E,OAAO;AACL,QAAA,IAAIO,UAAa,CAAA,GAAA;YACf,OAAOA,UAAAA;AACT,SAAA;AAEAU,QAAAA,QAAAA,CAAAA,GAAAA;AACE,YAAA,IAAI,CAACV,UAAY,EAAA;gBACfL,MAAOgB,CAAAA,IAAI,CAACC,GAAG,CAAC;oBACdC,aAAe,EAAA;AACbC,wBAAAA,IAAAA,EAAM,IAAMP,SAAU,CAAA,MAAA,CAAA;wBACtBQ,OAAS,EAAA;AACX;AACF,iBAAA,CAAA;AAEApB,gBAAAA,MAAAA,CAAOqB,MAAM,CAACC,GAAG,CAACC,gBAAiB,CAAA;AAAEX,oBAAAA;
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/services/metrics/index.ts"],"sourcesContent":["/**\n * Strapi telemetry package.\n * You can learn more at https://docs.strapi.io/developer-docs/latest/getting-started/usage-information.html\n */\n\nimport type { Core } from '@strapi/types';\n\nimport wrapWithRateLimit from './rate-limiter';\nimport createSender from './sender';\nimport createMiddleware from './middleware';\nimport isTruthy from './is-truthy';\n\nconst LIMITED_EVENTS = [\n 'didSaveMediaWithAlternativeText',\n 'didSaveMediaWithCaption',\n 'didDisableResponsiveDimensions',\n 'didEnableResponsiveDimensions',\n 'didInitializePluginUpload',\n];\n\nconst createTelemetryInstance = (strapi: Core.Strapi) => {\n const uuid = strapi.config.get('uuid');\n const telemetryDisabled = strapi.config.get('packageJsonStrapi.telemetryDisabled');\n const isDisabled =\n !uuid || isTruthy(process.env.STRAPI_TELEMETRY_DISABLED) || isTruthy(telemetryDisabled);\n\n const sender = createSender(strapi);\n const sendEvent = wrapWithRateLimit(sender, { limitedEvents: LIMITED_EVENTS });\n\n return {\n get isDisabled() {\n return isDisabled;\n },\n\n register() {\n if (!isDisabled) {\n strapi.cron.add({\n sendPingEvent: {\n task: () => sendEvent('ping'),\n options: '0 0 12 * * *',\n },\n });\n\n strapi.server.use(createMiddleware({ sendEvent, strapi }));\n }\n },\n\n bootstrap() {},\n\n async send(event: string, payload: Record<string, unknown> = {}) {\n if (isDisabled) return true;\n return sendEvent(event, payload);\n },\n\n destroy() {\n // Clean up resources if needed\n },\n };\n};\n\nexport default createTelemetryInstance;\n"],"names":["LIMITED_EVENTS","createTelemetryInstance","strapi","uuid","config","get","telemetryDisabled","isDisabled","isTruthy","process","env","STRAPI_TELEMETRY_DISABLED","sender","createSender","sendEvent","wrapWithRateLimit","limitedEvents","register","cron","add","sendPingEvent","task","options","server","use","createMiddleware","bootstrap","send","event","payload","destroy"],"mappings":";;;;;AAYA,MAAMA,cAAiB,GAAA;AACrB,IAAA,iCAAA;AACA,IAAA,yBAAA;AACA,IAAA,gCAAA;AACA,IAAA,+BAAA;AACA,IAAA;AACD,CAAA;AAED,MAAMC,0BAA0B,CAACC,MAAAA,GAAAA;AAC/B,IAAA,MAAMC,IAAOD,GAAAA,MAAAA,CAAOE,MAAM,CAACC,GAAG,CAAC,MAAA,CAAA;AAC/B,IAAA,MAAMC,iBAAoBJ,GAAAA,MAAAA,CAAOE,MAAM,CAACC,GAAG,CAAC,qCAAA,CAAA;IAC5C,MAAME,UAAAA,GACJ,CAACJ,IAAQK,IAAAA,QAAAA,CAASC,QAAQC,GAAG,CAACC,yBAAyB,CAAA,IAAKH,QAASF,CAAAA,iBAAAA,CAAAA;AAEvE,IAAA,MAAMM,SAASC,YAAaX,CAAAA,MAAAA,CAAAA;IAC5B,MAAMY,SAAAA,GAAYC,kBAAkBH,MAAQ,EAAA;QAAEI,aAAehB,EAAAA;AAAe,KAAA,CAAA;IAE5E,OAAO;AACL,QAAA,IAAIO,UAAa,CAAA,GAAA;YACf,OAAOA,UAAAA;AACT,SAAA;AAEAU,QAAAA,QAAAA,CAAAA,GAAAA;AACE,YAAA,IAAI,CAACV,UAAY,EAAA;gBACfL,MAAOgB,CAAAA,IAAI,CAACC,GAAG,CAAC;oBACdC,aAAe,EAAA;AACbC,wBAAAA,IAAAA,EAAM,IAAMP,SAAU,CAAA,MAAA,CAAA;wBACtBQ,OAAS,EAAA;AACX;AACF,iBAAA,CAAA;AAEApB,gBAAAA,MAAAA,CAAOqB,MAAM,CAACC,GAAG,CAACC,gBAAiB,CAAA;AAAEX,oBAAAA,SAAAA;AAAWZ,oBAAAA;AAAO,iBAAA,CAAA,CAAA;AACzD;AACF,SAAA;QAEAwB,SAAa,CAAA,GAAA,EAAA;AAEb,QAAA,MAAMC,IAAKC,CAAAA,CAAAA,KAAa,EAAEC,OAAAA,GAAmC,EAAE,EAAA;AAC7D,YAAA,IAAItB,YAAY,OAAO,IAAA;AACvB,YAAA,OAAOO,UAAUc,KAAOC,EAAAA,OAAAA,CAAAA;AAC1B,SAAA;AAEAC,QAAAA,OAAAA,CAAAA,GAAAA;;AAEA;AACF,KAAA;AACF;;;;"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Core } from '@strapi/types';
|
|
2
2
|
import type { Sender } from './sender';
|
|
3
|
-
declare const createMiddleware: ({ sendEvent }: {
|
|
3
|
+
declare const createMiddleware: ({ sendEvent, strapi }: {
|
|
4
4
|
sendEvent: Sender;
|
|
5
|
+
strapi: Core.Strapi;
|
|
5
6
|
}) => Core.MiddlewareHandler;
|
|
6
7
|
export default createMiddleware;
|
|
7
8
|
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/services/metrics/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAWvC,QAAA,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/services/metrics/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAWvC,QAAA,MAAM,gBAAgB,0BAA2B;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,KAAK,MAAM,CAAA;CAAE,2BAgC1F,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
function nextResetDate() {
|
|
4
4
|
return Date.now() + 24 * 60 * 60 * 1000; // Now + 24 hours.
|
|
5
5
|
}
|
|
6
|
-
const createMiddleware = ({ sendEvent })=>{
|
|
6
|
+
const createMiddleware = ({ sendEvent, strapi })=>{
|
|
7
7
|
const state = {
|
|
8
8
|
expires: nextResetDate(),
|
|
9
9
|
counter: 0
|
|
10
10
|
};
|
|
11
11
|
const middleware = async (ctx, next)=>{
|
|
12
12
|
const { url, method } = ctx.request;
|
|
13
|
-
if (!url.includes('.') && [
|
|
13
|
+
if (!url.includes('.') && url.includes(strapi.config.get('api.rest.prefix')) && [
|
|
14
14
|
'GET',
|
|
15
15
|
'PUT',
|
|
16
16
|
'POST',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sources":["../../../src/services/metrics/middleware.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport type { Sender } from './sender';\n\ninterface State {\n expires: number;\n counter: number;\n}\n\nfunction nextResetDate(): number {\n return Date.now() + 24 * 60 * 60 * 1000; // Now + 24 hours.\n}\n\nconst createMiddleware = ({ sendEvent }: { sendEvent: Sender }) => {\n const state: State = {\n expires: nextResetDate(),\n counter: 0,\n };\n\n const middleware: Core.MiddlewareHandler = async (ctx, next) => {\n const { url, method } = ctx.request;\n\n if (!url.includes('.')
|
|
1
|
+
{"version":3,"file":"middleware.js","sources":["../../../src/services/metrics/middleware.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport type { Sender } from './sender';\n\ninterface State {\n expires: number;\n counter: number;\n}\n\nfunction nextResetDate(): number {\n return Date.now() + 24 * 60 * 60 * 1000; // Now + 24 hours.\n}\n\nconst createMiddleware = ({ sendEvent, strapi }: { sendEvent: Sender; strapi: Core.Strapi }) => {\n const state: State = {\n expires: nextResetDate(),\n counter: 0,\n };\n\n const middleware: Core.MiddlewareHandler = async (ctx, next) => {\n const { url, method } = ctx.request;\n\n if (\n !url.includes('.') &&\n url.includes(strapi.config.get('api.rest.prefix')) &&\n ['GET', 'PUT', 'POST', 'DELETE'].includes(method)\n ) {\n if (Date.now() > state.expires) {\n state.expires = nextResetDate();\n state.counter = 0;\n }\n\n // Send max. 1000 events per day.\n if (state.counter < 1000) {\n sendEvent('didReceiveRequest', { eventProperties: { url: ctx.request.url } });\n\n // Increase counter.\n state.counter += 1;\n }\n }\n\n await next();\n };\n\n return middleware;\n};\n\nexport default createMiddleware;\n"],"names":["nextResetDate","Date","now","createMiddleware","sendEvent","strapi","state","expires","counter","middleware","ctx","next","url","method","request","includes","config","get","eventProperties"],"mappings":";;AAQA,SAASA,aAAAA,GAAAA;AACP,IAAA,OAAOC,KAAKC,GAAG,EAAA,GAAK,KAAK,EAAK,GAAA,EAAA,GAAK;AACrC;AAEA,MAAMC,mBAAmB,CAAC,EAAEC,SAAS,EAAEC,MAAM,EAA8C,GAAA;AACzF,IAAA,MAAMC,KAAe,GAAA;QACnBC,OAASP,EAAAA,aAAAA,EAAAA;QACTQ,OAAS,EAAA;AACX,KAAA;IAEA,MAAMC,UAAAA,GAAqC,OAAOC,GAAKC,EAAAA,IAAAA,GAAAA;AACrD,QAAA,MAAM,EAAEC,GAAG,EAAEC,MAAM,EAAE,GAAGH,IAAII,OAAO;AAEnC,QAAA,IACE,CAACF,GAAAA,CAAIG,QAAQ,CAAC,GACdH,CAAAA,IAAAA,GAAAA,CAAIG,QAAQ,CAACV,MAAOW,CAAAA,MAAM,CAACC,GAAG,CAAC,iBAC/B,CAAA,CAAA,IAAA;AAAC,YAAA,KAAA;AAAO,YAAA,KAAA;AAAO,YAAA,MAAA;AAAQ,YAAA;SAAS,CAACF,QAAQ,CAACF,MAC1C,CAAA,EAAA;AACA,YAAA,IAAIZ,IAAKC,CAAAA,GAAG,EAAKI,GAAAA,KAAAA,CAAMC,OAAO,EAAE;AAC9BD,gBAAAA,KAAAA,CAAMC,OAAO,GAAGP,aAAAA,EAAAA;AAChBM,gBAAAA,KAAAA,CAAME,OAAO,GAAG,CAAA;AAClB;;YAGA,IAAIF,KAAAA,CAAME,OAAO,GAAG,IAAM,EAAA;AACxBJ,gBAAAA,SAAAA,CAAU,mBAAqB,EAAA;oBAAEc,eAAiB,EAAA;wBAAEN,GAAKF,EAAAA,GAAAA,CAAII,OAAO,CAACF;AAAI;AAAE,iBAAA,CAAA;;AAG3EN,gBAAAA,KAAAA,CAAME,OAAO,IAAI,CAAA;AACnB;AACF;QAEA,MAAMG,IAAAA,EAAAA;AACR,KAAA;IAEA,OAAOF,UAAAA;AACT;;;;"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
function nextResetDate() {
|
|
2
2
|
return Date.now() + 24 * 60 * 60 * 1000; // Now + 24 hours.
|
|
3
3
|
}
|
|
4
|
-
const createMiddleware = ({ sendEvent })=>{
|
|
4
|
+
const createMiddleware = ({ sendEvent, strapi })=>{
|
|
5
5
|
const state = {
|
|
6
6
|
expires: nextResetDate(),
|
|
7
7
|
counter: 0
|
|
8
8
|
};
|
|
9
9
|
const middleware = async (ctx, next)=>{
|
|
10
10
|
const { url, method } = ctx.request;
|
|
11
|
-
if (!url.includes('.') && [
|
|
11
|
+
if (!url.includes('.') && url.includes(strapi.config.get('api.rest.prefix')) && [
|
|
12
12
|
'GET',
|
|
13
13
|
'PUT',
|
|
14
14
|
'POST',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.mjs","sources":["../../../src/services/metrics/middleware.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport type { Sender } from './sender';\n\ninterface State {\n expires: number;\n counter: number;\n}\n\nfunction nextResetDate(): number {\n return Date.now() + 24 * 60 * 60 * 1000; // Now + 24 hours.\n}\n\nconst createMiddleware = ({ sendEvent }: { sendEvent: Sender }) => {\n const state: State = {\n expires: nextResetDate(),\n counter: 0,\n };\n\n const middleware: Core.MiddlewareHandler = async (ctx, next) => {\n const { url, method } = ctx.request;\n\n if (!url.includes('.')
|
|
1
|
+
{"version":3,"file":"middleware.mjs","sources":["../../../src/services/metrics/middleware.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\nimport type { Sender } from './sender';\n\ninterface State {\n expires: number;\n counter: number;\n}\n\nfunction nextResetDate(): number {\n return Date.now() + 24 * 60 * 60 * 1000; // Now + 24 hours.\n}\n\nconst createMiddleware = ({ sendEvent, strapi }: { sendEvent: Sender; strapi: Core.Strapi }) => {\n const state: State = {\n expires: nextResetDate(),\n counter: 0,\n };\n\n const middleware: Core.MiddlewareHandler = async (ctx, next) => {\n const { url, method } = ctx.request;\n\n if (\n !url.includes('.') &&\n url.includes(strapi.config.get('api.rest.prefix')) &&\n ['GET', 'PUT', 'POST', 'DELETE'].includes(method)\n ) {\n if (Date.now() > state.expires) {\n state.expires = nextResetDate();\n state.counter = 0;\n }\n\n // Send max. 1000 events per day.\n if (state.counter < 1000) {\n sendEvent('didReceiveRequest', { eventProperties: { url: ctx.request.url } });\n\n // Increase counter.\n state.counter += 1;\n }\n }\n\n await next();\n };\n\n return middleware;\n};\n\nexport default createMiddleware;\n"],"names":["nextResetDate","Date","now","createMiddleware","sendEvent","strapi","state","expires","counter","middleware","ctx","next","url","method","request","includes","config","get","eventProperties"],"mappings":"AAQA,SAASA,aAAAA,GAAAA;AACP,IAAA,OAAOC,KAAKC,GAAG,EAAA,GAAK,KAAK,EAAK,GAAA,EAAA,GAAK;AACrC;AAEA,MAAMC,mBAAmB,CAAC,EAAEC,SAAS,EAAEC,MAAM,EAA8C,GAAA;AACzF,IAAA,MAAMC,KAAe,GAAA;QACnBC,OAASP,EAAAA,aAAAA,EAAAA;QACTQ,OAAS,EAAA;AACX,KAAA;IAEA,MAAMC,UAAAA,GAAqC,OAAOC,GAAKC,EAAAA,IAAAA,GAAAA;AACrD,QAAA,MAAM,EAAEC,GAAG,EAAEC,MAAM,EAAE,GAAGH,IAAII,OAAO;AAEnC,QAAA,IACE,CAACF,GAAAA,CAAIG,QAAQ,CAAC,GACdH,CAAAA,IAAAA,GAAAA,CAAIG,QAA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