@stackframe/stack-shared 2.8.58 → 2.8.59
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/config/migrate-catalogs-to-product-lines.d.mts +12 -0
- package/dist/config/migrate-catalogs-to-product-lines.d.ts +12 -0
- package/dist/config/migrate-catalogs-to-product-lines.js +211 -0
- package/dist/config/migrate-catalogs-to-product-lines.js.map +1 -0
- package/dist/config/schema-fuzzer.test.js +17 -6
- package/dist/config/schema-fuzzer.test.js.map +1 -1
- package/dist/config/schema.d.mts +181 -157
- package/dist/config/schema.d.ts +181 -157
- package/dist/config/schema.js +39 -8
- package/dist/config/schema.js.map +1 -1
- package/dist/esm/config/migrate-catalogs-to-product-lines.js +186 -0
- package/dist/esm/config/migrate-catalogs-to-product-lines.js.map +1 -0
- package/dist/esm/config/schema-fuzzer.test.js +17 -6
- package/dist/esm/config/schema-fuzzer.test.js.map +1 -1
- package/dist/esm/config/schema.js +40 -9
- package/dist/esm/config/schema.js.map +1 -1
- package/dist/esm/interface/client-interface.js +111 -21
- package/dist/esm/interface/client-interface.js.map +1 -1
- package/dist/esm/interface/crud/products.js +12 -1
- package/dist/esm/interface/crud/products.js.map +1 -1
- package/dist/esm/interface/server-interface.js +38 -0
- package/dist/esm/interface/server-interface.js.map +1 -1
- package/dist/esm/known-errors.js +24 -0
- package/dist/esm/known-errors.js.map +1 -1
- package/dist/esm/schema-fields.js +1 -1
- package/dist/esm/schema-fields.js.map +1 -1
- package/dist/interface/client-interface.d.mts +31 -0
- package/dist/interface/client-interface.d.ts +31 -0
- package/dist/interface/client-interface.js +111 -21
- package/dist/interface/client-interface.js.map +1 -1
- package/dist/interface/crud/products.d.mts +77 -0
- package/dist/interface/crud/products.d.ts +77 -0
- package/dist/interface/crud/products.js +12 -1
- package/dist/interface/crud/products.js.map +1 -1
- package/dist/interface/server-interface.d.mts +23 -0
- package/dist/interface/server-interface.d.ts +23 -0
- package/dist/interface/server-interface.js +38 -0
- package/dist/interface/server-interface.js.map +1 -1
- package/dist/known-errors.d.mts +6 -0
- package/dist/known-errors.d.ts +6 -0
- package/dist/known-errors.js +24 -0
- package/dist/known-errors.js.map +1 -1
- package/dist/schema-fields.d.mts +4 -4
- package/dist/schema-fields.d.ts +4 -4
- package/dist/schema-fields.js +1 -1
- package/dist/schema-fields.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/config/migrate-catalogs-to-product-lines.ts"],"sourcesContent":["import { StackAssertionError } from \"../utils/errors\";\nimport { isObjectLike, set, typedEntries } from \"../utils/objects\";\n\n/**\n * Renames properties in an object based on a path condition.\n * This is a local copy to avoid circular dependencies with schema.ts.\n */\nfunction renameProperty(obj: Record<string, any>, oldPath: string | ((path: string[]) => boolean), newName: string | ((path: string[]) => string)): any {\n const pathCond = typeof oldPath === \"function\" ? oldPath : (p: string[]) => p.join(\".\") === oldPath;\n const pathMapper = typeof newName === \"function\" ? newName : (p: string[]) => (newName as string);\n\n const res: Record<string, any> = Array.isArray(obj) ? [] : {};\n for (const [key, originalValue] of typedEntries(obj)) {\n const path = key.split(\".\");\n\n for (let i = 0; i < path.length; i++) {\n const pathPrefix = path.slice(0, i + 1);\n if (pathCond(pathPrefix)) {\n const name = pathMapper(pathPrefix);\n if (name.includes(\".\")) throw new StackAssertionError(`newName must not contain a dot. Provided: ${name}`);\n path[i] = name;\n }\n }\n\n const value = isObjectLike(originalValue) ? renameProperty(originalValue, p => pathCond([...path, ...p]), p => pathMapper([...path, ...p])) : originalValue;\n set(res, path.join(\".\"), value);\n }\n\n return res;\n}\n\n/**\n * Migrates the old \"catalogs\" format to \"productLines\", including:\n * 1. Inferring customerType for each catalog from its products (since old catalogs didn't have customerType)\n * 2. Removing empty catalogs (those with no products) since they can't have customerType inferred\n * 3. Renaming payments.catalogs -> payments.productLines\n * 4. Renaming payments.products.*.catalogId -> payments.products.*.productLineId\n *\n * This handles all config formats (nested objects, flat dot-notation, or mixed).\n */\nexport function migrateCatalogsToProductLines(obj: Record<string, any>): Record<string, any> {\n // Step 1: Collect catalogId -> customerType mappings from products\n const catalogCustomerTypes = new Map<string, string>();\n collectCatalogCustomerTypes(obj, [], catalogCustomerTypes);\n\n // Step 2: Find all catalog IDs that exist\n const allCatalogIds = new Set<string>();\n findAllCatalogIds(obj, [], allCatalogIds);\n\n // Step 3: Add customerType keys for catalogs that need them\n let res = { ...obj };\n for (const catalogId of allCatalogIds) {\n const customerType = catalogCustomerTypes.get(catalogId);\n if (customerType) {\n // Find the format used for this catalog and add customerType in the same format\n res = addCustomerTypeToCatalog(res, catalogId, customerType);\n } else {\n // Empty catalog (no products) - remove it since we can't infer customerType\n res = removeCatalog(res, catalogId);\n }\n }\n\n // Step 4: Rename catalogs -> productLines\n res = renameProperty(res, \"payments.catalogs\", \"productLines\");\n\n // Step 5: Rename catalogId -> productLineId in products\n res = renameProperty(res, (p) => p.length === 4 && p[0] === \"payments\" && p[1] === \"products\" && p[3] === \"catalogId\", () => \"productLineId\");\n\n return res;\n}\n\n/**\n * Recursively collects catalogId -> customerType mappings from products.\n * Handles both nested and flat config formats.\n */\nfunction collectCatalogCustomerTypes(\n obj: Record<string, any>,\n basePath: string[],\n result: Map<string, string>\n): void {\n for (const [key, value] of typedEntries(obj)) {\n const keyParts = key.split(\".\");\n const fullPath = [...basePath, ...keyParts];\n\n // Check for flat format at ROOT level only: payments.products.<productId>.catalogId\n // We check basePath.length === 0 to ensure we're at root and key contains the full path\n if (basePath.length === 0 && fullPath.length === 4 && fullPath[0] === \"payments\" && fullPath[1] === \"products\" && fullPath[3] === \"catalogId\") {\n if (typeof value === \"string\") {\n const productId = fullPath[2];\n // Look for customerType in the same flat format\n const customerTypeKey = `payments.products.${productId}.customerType`;\n if (customerTypeKey in obj && typeof obj[customerTypeKey] === \"string\") {\n result.set(value, obj[customerTypeKey]);\n }\n }\n }\n\n // Check for nested format: payments.products.<productId> with object value\n if (fullPath.length === 3 && fullPath[0] === \"payments\" && fullPath[1] === \"products\" && isObjectLike(value)) {\n const catalogId = findPropertyValue(value, \"catalogId\") ?? findPropertyValue(value, \"productLineId\");\n const customerType = findPropertyValue(value, \"customerType\");\n if (catalogId && typeof catalogId === \"string\" && customerType && typeof customerType === \"string\") {\n result.set(catalogId, customerType);\n }\n }\n\n if (isObjectLike(value)) {\n collectCatalogCustomerTypes(value, fullPath, result);\n }\n }\n}\n\n/**\n * Finds a property value in an object, handling both direct properties and dot-notation keys.\n */\nfunction findPropertyValue(obj: Record<string, any>, propertyName: string): any {\n // Direct property\n if (propertyName in obj) {\n return obj[propertyName];\n }\n // Check for dot-notation keys that end with the property name\n for (const key of Object.keys(obj)) {\n const parts = key.split(\".\");\n if (parts[parts.length - 1] === propertyName) {\n return obj[key];\n }\n }\n return undefined;\n}\n\n/**\n * Finds all catalog IDs that exist in the config.\n */\nfunction findAllCatalogIds(\n obj: Record<string, any>,\n basePath: string[],\n result: Set<string>\n): void {\n for (const [key, value] of typedEntries(obj)) {\n const keyParts = key.split(\".\");\n const fullPath = [...basePath, ...keyParts];\n\n // Check for catalog entry at payments.catalogs.<catalogId>\n if (fullPath.length >= 3 && fullPath[0] === \"payments\" && fullPath[1] === \"catalogs\") {\n const catalogId = fullPath[2];\n result.add(catalogId);\n }\n\n if (isObjectLike(value)) {\n findAllCatalogIds(value, fullPath, result);\n }\n }\n}\n\n/**\n * Removes a catalog from the config in any format (nested or flat).\n */\nfunction removeCatalog(obj: Record<string, any>, catalogId: string): Record<string, any> {\n // Don't process arrays - they should be copied as-is\n if (Array.isArray(obj)) {\n return obj;\n }\n\n const res: Record<string, any> = {};\n\n for (const [key, value] of typedEntries(obj)) {\n const keyParts = key.split(\".\");\n\n // Check if this key is for the catalog we want to remove\n // Format 4: \"payments.catalogs.<catalogId>.displayName\" or similar flat keys\n if (keyParts.length >= 3 && keyParts[0] === \"payments\" && keyParts[1] === \"catalogs\" && keyParts[2] === catalogId) {\n // Skip this key - don't copy it\n continue;\n }\n\n // Format 3: \"payments.catalogs.<catalogId>\" as a single key\n if (key === `payments.catalogs.${catalogId}`) {\n continue;\n }\n\n if (Array.isArray(value)) {\n res[key] = value;\n } else if (isObjectLike(value)) {\n const processed = removeCatalog(value, catalogId);\n // Check if we need to remove the catalog from nested structures\n if (key === \"payments\" && isObjectLike(processed) && \"catalogs\" in processed) {\n const catalogs = processed.catalogs;\n if (isObjectLike(catalogs) && catalogId in catalogs) {\n const { [catalogId]: _, ...rest } = catalogs as Record<string, any>;\n res[key] = { ...processed, catalogs: rest };\n continue;\n }\n }\n // Format 2: \"payments.catalogs\" as a key with nested catalog\n if (key === \"payments.catalogs\" && isObjectLike(processed) && catalogId in processed) {\n const { [catalogId]: _, ...rest } = processed as Record<string, any>;\n res[key] = rest;\n continue;\n }\n res[key] = processed;\n } else {\n res[key] = value;\n }\n }\n\n return res;\n}\n\n/**\n * Adds customerType to a catalog in the appropriate format.\n */\nfunction addCustomerTypeToCatalog(obj: Record<string, any>, catalogId: string, customerType: string): Record<string, any> {\n // Don't process arrays - they should be copied as-is\n if (Array.isArray(obj)) {\n return obj;\n }\n\n const res: Record<string, any> = {};\n\n // First, copy all existing properties\n for (const [key, value] of typedEntries(obj)) {\n if (Array.isArray(value)) {\n // Copy arrays directly without processing\n res[key] = value;\n } else if (isObjectLike(value)) {\n res[key] = addCustomerTypeToCatalog(value, catalogId, customerType);\n } else {\n res[key] = value;\n }\n }\n\n // Check what format the catalog uses\n // Format 1: { payments: { catalogs: { [catalogId]: { ... } } } }\n const payments = res.payments;\n if (payments && isObjectLike(payments) && !Array.isArray(payments) && typeof payments !== \"function\") {\n const paymentsObj = payments as Record<string, any>;\n const catalogs = paymentsObj.catalogs;\n if (catalogs && isObjectLike(catalogs) && !Array.isArray(catalogs) && typeof catalogs !== \"function\") {\n const catalogsObj = catalogs as Record<string, any>;\n const catalog = catalogsObj[catalogId];\n if (catalog && isObjectLike(catalog)) {\n if (!(\"customerType\" in catalog)) {\n catalogsObj[catalogId] = { ...catalog, customerType };\n }\n return res;\n }\n }\n }\n\n // Format 2: { \"payments.catalogs\": { [catalogId]: { ... } } }\n const paymentsCatalogs = res[\"payments.catalogs\"];\n if (paymentsCatalogs && isObjectLike(paymentsCatalogs) && !Array.isArray(paymentsCatalogs) && typeof paymentsCatalogs !== \"function\") {\n const catalogs = paymentsCatalogs as Record<string, any>;\n if (catalogId in catalogs && isObjectLike(catalogs[catalogId])) {\n if (!(\"customerType\" in catalogs[catalogId])) {\n catalogs[catalogId] = { ...catalogs[catalogId], customerType };\n }\n return res;\n }\n }\n\n // Format 3: { \"payments.catalogs.[catalogId]\": { ... } }\n const catalogKey = `payments.catalogs.${catalogId}`;\n if (catalogKey in res && isObjectLike(res[catalogKey])) {\n if (!(\"customerType\" in res[catalogKey])) {\n res[catalogKey] = { ...res[catalogKey], customerType };\n }\n return res;\n }\n\n // Format 4: { \"payments.catalogs.[catalogId].displayName\": \"...\" }\n // Need to add a new key for customerType\n const customerTypeKey = `payments.catalogs.${catalogId}.customerType`;\n for (const key of Object.keys(res)) {\n if (key.startsWith(`payments.catalogs.${catalogId}.`) && key !== customerTypeKey) {\n // Found a flat key for this catalog, add customerType in same format\n res[customerTypeKey] = customerType;\n return res;\n }\n }\n\n return res;\n}\n\n// Tests\nundefined?.test(\"migrateCatalogsToProductLines - basic migrations\", ({ expect }) => {\n // Basic nested format\n expect(migrateCatalogsToProductLines({\n payments: {\n catalogs: {\n myCatalog: { displayName: \"My Catalog\" }\n },\n products: {\n myProduct: { catalogId: \"myCatalog\", customerType: \"user\", prices: {} }\n }\n }\n })).toEqual({\n payments: {\n productLines: {\n myCatalog: { displayName: \"My Catalog\", customerType: \"user\" }\n },\n products: {\n myProduct: { productLineId: \"myCatalog\", customerType: \"user\", prices: {} }\n }\n }\n });\n\n // Flat format\n expect(migrateCatalogsToProductLines({\n \"payments.catalogs.myCatalog\": { displayName: \"My Catalog\" },\n \"payments.products.myProduct.catalogId\": \"myCatalog\",\n \"payments.products.myProduct.customerType\": \"user\",\n })).toEqual({\n \"payments.productLines.myCatalog\": { displayName: \"My Catalog\", customerType: \"user\" },\n \"payments.products.myProduct.productLineId\": \"myCatalog\",\n \"payments.products.myProduct.customerType\": \"user\",\n });\n\n // Mixed format\n expect(migrateCatalogsToProductLines({\n payments: {\n catalogs: { myCatalog: { displayName: \"My Catalog\" } }\n },\n \"payments.products.myProduct\": { catalogId: \"myCatalog\", customerType: \"user\" }\n })).toEqual({\n payments: {\n productLines: { myCatalog: { displayName: \"My Catalog\", customerType: \"user\" } }\n },\n \"payments.products.myProduct\": { productLineId: \"myCatalog\", customerType: \"user\" }\n });\n});\n\nundefined?.test(\"migrateCatalogsToProductLines - does not overwrite existing customerType\", ({ expect }) => {\n // If catalog already has customerType, don't overwrite it\n expect(migrateCatalogsToProductLines({\n payments: {\n catalogs: {\n myCatalog: { displayName: \"My Catalog\", customerType: \"team\" }\n },\n products: {\n myProduct: { catalogId: \"myCatalog\", customerType: \"user\", prices: {} }\n }\n }\n })).toEqual({\n payments: {\n productLines: {\n myCatalog: { displayName: \"My Catalog\", customerType: \"team\" }\n },\n products: {\n myProduct: { productLineId: \"myCatalog\", customerType: \"user\", prices: {} }\n }\n }\n });\n});\n\nundefined?.test(\"migrateCatalogsToProductLines - multiple catalogs and products\", ({ expect }) => {\n expect(migrateCatalogsToProductLines({\n payments: {\n catalogs: {\n userPlans: { displayName: \"User Plans\" },\n teamPlans: { displayName: \"Team Plans\" }\n },\n products: {\n userBasic: { catalogId: \"userPlans\", customerType: \"user\", prices: {} },\n userPro: { catalogId: \"userPlans\", customerType: \"user\", prices: {} },\n teamBasic: { catalogId: \"teamPlans\", customerType: \"team\", prices: {} }\n }\n }\n })).toEqual({\n payments: {\n productLines: {\n userPlans: { displayName: \"User Plans\", customerType: \"user\" },\n teamPlans: { displayName: \"Team Plans\", customerType: \"team\" }\n },\n products: {\n userBasic: { productLineId: \"userPlans\", customerType: \"user\", prices: {} },\n userPro: { productLineId: \"userPlans\", customerType: \"user\", prices: {} },\n teamBasic: { productLineId: \"teamPlans\", customerType: \"team\", prices: {} }\n }\n }\n });\n});\n\nundefined?.test(\"migrateCatalogsToProductLines - catalog without products is removed\", ({ expect }) => {\n // Catalog without any products should be removed since we can't infer customerType\n expect(migrateCatalogsToProductLines({\n payments: {\n catalogs: {\n emptyCatalog: { displayName: \"Empty\" }\n },\n products: {}\n }\n })).toEqual({\n payments: {\n productLines: {},\n products: {}\n }\n });\n});\n\nundefined?.test(\"migrateCatalogsToProductLines - products without catalogId\", ({ expect }) => {\n // Catalogs without any products referencing them should be removed\n expect(migrateCatalogsToProductLines({\n payments: {\n catalogs: {\n myCatalog: { displayName: \"My Catalog\" }\n },\n products: {\n standalone: { customerType: \"user\", prices: {} }\n }\n }\n })).toEqual({\n payments: {\n productLines: {},\n products: {\n standalone: { customerType: \"user\", prices: {} }\n }\n }\n });\n});\n\nundefined?.test(\"migrateCatalogsToProductLines - deeply nested flat format\", ({ expect }) => {\n expect(migrateCatalogsToProductLines({\n \"payments.catalogs.myCatalog.displayName\": \"My Catalog\",\n \"payments.products.myProduct.catalogId\": \"myCatalog\",\n \"payments.products.myProduct.customerType\": \"user\",\n \"payments.products.myProduct.prices\": {},\n })).toEqual({\n \"payments.productLines.myCatalog.displayName\": \"My Catalog\",\n \"payments.productLines.myCatalog.customerType\": \"user\",\n \"payments.products.myProduct.productLineId\": \"myCatalog\",\n \"payments.products.myProduct.customerType\": \"user\",\n \"payments.products.myProduct.prices\": {},\n });\n});\n\nundefined?.test(\"migrateCatalogsToProductLines - no catalogs\", ({ expect }) => {\n // Config without catalogs should pass through unchanged (except productLineId rename)\n expect(migrateCatalogsToProductLines({\n payments: {\n products: {\n myProduct: { catalogId: \"someCatalog\", customerType: \"user\" }\n }\n }\n })).toEqual({\n payments: {\n products: {\n myProduct: { productLineId: \"someCatalog\", customerType: \"user\" }\n }\n }\n });\n});\n\nundefined?.test(\"migrateCatalogsToProductLines - already migrated (productLines)\", ({ expect }) => {\n // Already has productLines, should not change customerType\n expect(migrateCatalogsToProductLines({\n payments: {\n productLines: {\n myLine: { displayName: \"My Line\", customerType: \"team\" }\n },\n products: {\n myProduct: { productLineId: \"myLine\", customerType: \"team\" }\n }\n }\n })).toEqual({\n payments: {\n productLines: {\n myLine: { displayName: \"My Line\", customerType: \"team\" }\n },\n products: {\n myProduct: { productLineId: \"myLine\", customerType: \"team\" }\n }\n }\n });\n});\n"],"mappings":";AAAA,SAAS,2BAA2B;AACpC,SAAS,cAAc,KAAK,oBAAoB;AAMhD,SAAS,eAAe,KAA0B,SAAiD,SAAqD;AACtJ,QAAM,WAAW,OAAO,YAAY,aAAa,UAAU,CAAC,MAAgB,EAAE,KAAK,GAAG,MAAM;AAC5F,QAAM,aAAa,OAAO,YAAY,aAAa,UAAU,CAAC,MAAiB;AAE/E,QAAM,MAA2B,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC;AAC5D,aAAW,CAAC,KAAK,aAAa,KAAK,aAAa,GAAG,GAAG;AACpD,UAAM,OAAO,IAAI,MAAM,GAAG;AAE1B,aAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,YAAM,aAAa,KAAK,MAAM,GAAG,IAAI,CAAC;AACtC,UAAI,SAAS,UAAU,GAAG;AACxB,cAAM,OAAO,WAAW,UAAU;AAClC,YAAI,KAAK,SAAS,GAAG,EAAG,OAAM,IAAI,oBAAoB,6CAA6C,IAAI,EAAE;AACzG,aAAK,CAAC,IAAI;AAAA,MACZ;AAAA,IACF;AAEA,UAAM,QAAQ,aAAa,aAAa,IAAI,eAAe,eAAe,OAAK,SAAS,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,GAAG,OAAK,WAAW,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI;AAC9I,QAAI,KAAK,KAAK,KAAK,GAAG,GAAG,KAAK;AAAA,EAChC;AAEA,SAAO;AACT;AAWO,SAAS,8BAA8B,KAA+C;AAE3F,QAAM,uBAAuB,oBA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,27 @@ var branchSchemaFuzzerConfig = [{
|
|
|
46
46
|
}]
|
|
47
47
|
}],
|
|
48
48
|
payments: [{
|
|
49
|
+
blockNewPurchases: [false, true],
|
|
49
50
|
testMode: [false, true],
|
|
50
51
|
autoPay: [{
|
|
51
52
|
interval: [[[0, 1, -3, 100, 0.333, Infinity], ["day", "week", "month", "year"]]]
|
|
52
53
|
}],
|
|
54
|
+
productLines: [{
|
|
55
|
+
"some-product-line-id": [{
|
|
56
|
+
displayName: ["Some Product Line", "Some Other Product Line"],
|
|
57
|
+
customerType: ["user", "team", "custom"]
|
|
58
|
+
}]
|
|
59
|
+
}],
|
|
53
60
|
catalogs: [{
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
// ensure migration works
|
|
62
|
+
"some-product-line-id": [{
|
|
63
|
+
displayName: ["Some Product Line", "Some Other Product Line"]
|
|
56
64
|
}]
|
|
57
65
|
}],
|
|
58
66
|
groups: [{
|
|
59
|
-
|
|
60
|
-
|
|
67
|
+
// ensure migration works
|
|
68
|
+
"some-product-line-id": [{
|
|
69
|
+
displayName: ["Some Product Line", "Some Other Product Line"]
|
|
61
70
|
}]
|
|
62
71
|
}],
|
|
63
72
|
items: [{
|
|
@@ -73,8 +82,10 @@ var branchSchemaFuzzerConfig = [{
|
|
|
73
82
|
freeTrial: [[[0, 1, -3, 100, 0.333, Infinity], ["day", "week", "month", "year"]]],
|
|
74
83
|
serverOnly: [true, false],
|
|
75
84
|
stackable: [true, false],
|
|
76
|
-
|
|
77
|
-
|
|
85
|
+
productLineId: ["some-product-line-id", "some-other-product-line-id"],
|
|
86
|
+
catalogId: ["some-product-line-id", "some-other-product-line-id"],
|
|
87
|
+
// ensure migration works
|
|
88
|
+
groupId: ["some-product-line-id", "some-other-product-line-id"],
|
|
78
89
|
// ensure migration works
|
|
79
90
|
isAddOnTo: [false, { "some-product-id": [true], "some-other-product-id": [true] }],
|
|
80
91
|
prices: ["include-by-default", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/config/schema-fuzzer.test.ts"],"sourcesContent":["import { ALL_APPS } from \"../apps/apps-config\";\nimport { SUPPORTED_CURRENCIES } from \"../utils/currency-constants\";\nimport { StackAssertionError } from \"../utils/errors\";\nimport { getOrUndefined, isObjectLike, set, typedEntries, typedFromEntries } from \"../utils/objects\";\nimport { nicify } from \"../utils/strings\";\nimport { normalize, override } from \"./format\";\nimport { BranchConfigNormalizedOverride, EnvironmentConfigNormalizedOverride, OrganizationConfigNormalizedOverride, ProjectConfigNormalizedOverride, applyBranchDefaults, applyEnvironmentDefaults, applyOrganizationDefaults, applyProjectDefaults, assertNoConfigOverrideErrors, branchConfigSchema, environmentConfigSchema, migrateConfigOverride, organizationConfigSchema, projectConfigSchema, sanitizeBranchConfig, sanitizeEnvironmentConfig, sanitizeOrganizationConfig, sanitizeProjectConfig } from \"./schema\";\n\ntype FuzzerConfig<T> = ReadonlyArray<T extends object ? ([T] extends [any[]] ? { readonly [K in keyof T]: FuzzerConfig<T[K]> } : Required<{\n [K in keyof T]: FuzzerConfig<T[K]>;\n}> & Record<string, FuzzerConfig<any>>) : T>;\n\nconst projectSchemaFuzzerConfig = [{\n sourceOfTruth: [{\n type: [\"hosted\", \"neon\", \"postgres\"],\n connectionString: [\"\", \"postgres://user:password@host:port/database\", \"THIS IS A STRING LOLOL\"],\n connectionStrings: [{\n \"123-some-branch-id\": [\"\", \"THIS IS A CONNECTION STRING OR SO\"],\n }],\n }],\n}] satisfies FuzzerConfig<ProjectConfigNormalizedOverride>;\n\nconst branchSchemaFuzzerConfig = [{\n apiKeys: [{\n enabled: [{\n team: [true, false],\n user: [true, false],\n }],\n }],\n auth: [{\n allowSignUp: [true, false],\n password: [{\n allowSignIn: [true, false],\n }],\n otp: [{\n allowSignIn: [true, false],\n }],\n passkey: [{\n allowSignIn: [true, false],\n }],\n oauth: [{\n accountMergeStrategy: [\"link_method\", \"raise_error\", \"allow_duplicates\"],\n providers: [{\n \"google\": [{\n type: [\"google\", \"github\", \"x\"] as const,\n allowSignIn: [true, false],\n allowConnectedAccounts: [true, false],\n }],\n }],\n }],\n }],\n dataVault: [{\n stores: [{\n \"some-store-id\": [{\n displayName: [\"Some Store\", \"Some Other Store\"],\n }],\n \"some-other-store-id\": [{\n displayName: [\"Some Store\", \"Some Other Store\"],\n }],\n }],\n }],\n payments: [{\n testMode: [false, true],\n autoPay: [{\n interval: [[[0, 1, -3, 100, 0.333, Infinity], [\"day\", \"week\", \"month\", \"year\"]]] as const,\n }],\n catalogs: [{\n \"some-catalog-id\": [{\n displayName: [\"Some Catalog\", \"Some Other Catalog\"],\n }],\n }],\n groups: [{\n \"some-catalog-id\": [{\n displayName: [\"Some Catalog\", \"Some Other Catalog\"],\n }],\n }],\n items: [{\n \"some-item-id\": [{\n customerType: [\"user\", \"team\", \"custom\"] as const,\n displayName: [\"Some Item\", \"Some Other Item\"],\n }],\n }],\n products: [{\n \"some-product-id\": [{\n displayName: [\"Some Product\", \"Some Other Product\"],\n customerType: [\"user\", \"team\", \"custom\"] as const,\n freeTrial: [[[0, 1, -3, 100, 0.333, Infinity], [\"day\", \"week\", \"month\", \"year\"]]] as const,\n serverOnly: [true, false],\n stackable: [true, false],\n catalogId: [\"some-catalog-id\", \"some-other-catalog-id\"],\n groupId: [\"some-catalog-id\", \"some-other-catalog-id\"], // ensure migration works\n isAddOnTo: [false, { \"some-product-id\": [true], \"some-other-product-id\": [true] }] as const,\n prices: [\"include-by-default\" as \"include-by-default\", {\n \"some-price-id\": [{\n ...typedFromEntries(SUPPORTED_CURRENCIES.map(currency => [currency.code, [\"100_00\", \"not a number\", \"Infinity\", \"0\"]])),\n interval: [[[0, 1, -3, 100, 0.333, Infinity], [\"day\", \"week\", \"month\", \"year\"]]] as const,\n serverOnly: [true, false],\n freeTrial: [[[0, 1, -3, 100, 0.333, Infinity], [\"day\", \"week\", \"month\", \"year\"]]] as const,\n }],\n }],\n includedItems: [{\n \"some-item-id\": [{\n quantity: [0, 1, -3, 100, 0.333, Infinity],\n repeat: [\"never\", [[0, 1, -3, 100, 0.333, Infinity], [\"day\", \"week\", \"month\", \"year\"]]] as const,\n expires: [\"never\", \"when-purchase-expires\", \"when-repeated\"] as const,\n }],\n }],\n }],\n }],\n }],\n emails: [{\n themes: [{\n \"12345678-1234-4234-9234-123456789012\": [{\n displayName: [\"Some Theme\", \"Some Other Theme\"],\n tsxSource: [\"\", \"some typescript source code\"],\n }],\n }],\n selectedThemeId: [\"some-theme-id\", \"some-other-theme-id\"],\n templates: [{\n \"12345678-1234-4234-9234-123456789012\": [{\n themeId: [\"some-theme-id\", \"some-other-theme-id\"],\n displayName: [\"Some Template\", \"Some Other Template\"],\n tsxSource: [\"\", \"some typescript source code\"],\n }],\n }],\n }],\n teams: [{\n createPersonalTeamOnSignUp: [true, false],\n allowClientTeamCreation: [true, false],\n }],\n users: [{\n allowClientUserDeletion: [true, false],\n }],\n rbac: [{\n permissions: [{\n \"some_permission_id\": [{\n containedPermissionIds: [{\n \"some_permission_id\": [true],\n \"$some_other_permission_id\": [true],\n }] as const,\n description: [\"Some Permission\", \"Some Other Permission\"],\n scope: [\"team\", \"project\"] as const,\n }],\n }],\n defaultPermissions: [{\n teamCreator: [{\n \"some_permission_id\": [true],\n \"$some_other_permission_id\": [true],\n }] as const,\n teamMember: [{\n \"some_permission_id\": [true],\n \"$some_other_permission_id\": [true],\n }] as const,\n signUp: [{\n \"some_permission_id\": [true],\n \"$some_other_permission_id\": [true],\n }] as const,\n }],\n }],\n domains: [{\n allowLocalhost: [true, false],\n }],\n apps: [{\n installed: [typedFromEntries(typedEntries(ALL_APPS).map(([key, value]) => [key, [{\n enabled: [true, false],\n }]]))],\n }],\n onboarding: [{\n requireEmailVerification: [true, false],\n }],\n}] satisfies FuzzerConfig<BranchConfigNormalizedOverride>;\n\nconst environmentSchemaFuzzerConfig = [{\n ...branchSchemaFuzzerConfig[0],\n auth: [{\n ...branchSchemaFuzzerConfig[0].auth[0],\n oauth: [{\n ...branchSchemaFuzzerConfig[0].auth[0].oauth[0],\n providers: [typedFromEntries(typedEntries(branchSchemaFuzzerConfig[0].auth[0].oauth[0].providers[0]).map(([key, value]) => [key, [{\n ...value[0],\n isShared: [true, false],\n clientId: [\"some-client-id\"],\n clientSecret: [\"some-client-secret\"],\n facebookConfigId: [\"some-facebook-config-id\"],\n microsoftTenantId: [\"some-microsoft-tenant-id\"],\n }]]))] as const,\n }],\n }],\n domains: [{\n ...branchSchemaFuzzerConfig[0].domains[0],\n trustedDomains: [{\n \"some-domain-id\": [{\n baseUrl: [\"https://example.com/something-here\"],\n handlerPath: [\"/something-here\"],\n }],\n }],\n }],\n emails: [{\n ...branchSchemaFuzzerConfig[0].emails[0],\n server: [{\n isShared: [true, false],\n provider: [\"resend\", \"smtp\"] as const,\n host: [\"example.com\", \"://super weird host that's not valid\"],\n port: [1234, 0.12543, -100, Infinity],\n username: [\"some-username\", \"some username with a space\"],\n password: [\"some-password\", \"some password with a space\"],\n senderName: [\"Some Sender\"],\n senderEmail: [\"some-sender@example.com\", \"some invalid email\"],\n }],\n }],\n}] satisfies FuzzerConfig<EnvironmentConfigNormalizedOverride>;\n\nconst organizationSchemaFuzzerConfig = environmentSchemaFuzzerConfig satisfies FuzzerConfig<OrganizationConfigNormalizedOverride>;\n\nfunction setDeep<T>(obj: T, path: string[], value: any) {\n if (!isObjectLike(obj)) return obj;\n\n if (path.length === 0) {\n throw new Error(\"Path is empty\");\n } else if (path.length === 1) {\n set(obj as any, path[0], value);\n } else {\n const [key, ...rest] = path;\n setDeep(getOrUndefined(obj as any, key), rest, value);\n }\n}\n\nfunction createFuzzerInput<T>(config: FuzzerConfig<T>, progress: number): T {\n progress = Math.min(1, 2 * progress);\n const createShouldRandom = (strength: number) => {\n const chance = Math.random() * strength * 1.2 - 0.1;\n return () => Math.random() < chance;\n };\n const createShouldObjectDependent = (strength: number) => {\n const objectChance = Math.random() * strength * 1.2 - 0.1;\n const primitiveChance = Math.random() * strength * 1.2 - 0.1;\n return (v: any) => Math.random() * Math.random() < (isObjectLike(v) ? objectChance : primitiveChance);\n };\n\n const shouldKeep = createShouldObjectDependent(progress * 1);\n const shouldMakeNested = createShouldObjectDependent(1.25);\n const shouldNull = createShouldRandom(0.25);\n\n let res: any;\n const recurse = <U>(outputPath: string[], config: FuzzerConfig<U>, forceNested: boolean, forceNonNull: boolean) => {\n let subConfig: any = config[Math.floor(Math.random() * config.length)];\n const originalValue = isObjectLike(subConfig) ? (Array.isArray(subConfig) ? [] : {}) : subConfig;\n\n const newValue = forceNonNull || !shouldNull() ? originalValue : null;\n const newOutputPath = forceNested || shouldMakeNested(originalValue) || outputPath.length === 0 ? outputPath : [outputPath.join(\".\")];\n if (outputPath.length === 0) {\n res = newValue;\n } else {\n if (forceNested || shouldKeep(originalValue)) {\n setDeep(res, newOutputPath, newValue);\n }\n }\n if (isObjectLike(subConfig)) {\n for (const [key, newValue] of typedEntries(subConfig)) {\n recurse([...newOutputPath, key], newValue, Array.isArray(subConfig), Array.isArray(subConfig));\n }\n }\n };\n recurse<T>([], config, false, true);\n return res;\n}\n\nundefined?.test(\"fuzz schemas\", async ({ expect }) => {\n const totalIterations = process.env.CI ? 1000 : 200;\n for (let i = 0; i < totalIterations; i++) {\n const projectInput = createFuzzerInput<ProjectConfigNormalizedOverride>(projectSchemaFuzzerConfig, i / totalIterations);\n const branchInput = createFuzzerInput<BranchConfigNormalizedOverride>(branchSchemaFuzzerConfig, i / totalIterations);\n const environmentInput = createFuzzerInput<EnvironmentConfigNormalizedOverride>(environmentSchemaFuzzerConfig, i / totalIterations);\n const organizationInput = createFuzzerInput<OrganizationConfigNormalizedOverride>(organizationSchemaFuzzerConfig, i / totalIterations);\n\n try {\n const projectMigrated = migrateConfigOverride(\"project\", projectInput);\n await assertNoConfigOverrideErrors(projectConfigSchema, projectMigrated);\n const projectOverridden = override({}, projectMigrated);\n await sanitizeProjectConfig(normalize(applyProjectDefaults(projectOverridden), { onDotIntoNonObject: \"ignore\" }) as any);\n\n const branchMigrated = migrateConfigOverride(\"branch\", branchInput);\n await assertNoConfigOverrideErrors(branchConfigSchema, branchMigrated);\n const branchOverridden = override(projectOverridden, branchMigrated);\n await sanitizeBranchConfig(normalize(applyBranchDefaults(branchOverridden), { onDotIntoNonObject: \"ignore\" }) as any);\n\n const environmentMigrated = migrateConfigOverride(\"environment\", environmentInput);\n await assertNoConfigOverrideErrors(environmentConfigSchema, environmentMigrated);\n const environmentOverridden = override(branchOverridden, environmentMigrated);\n await sanitizeEnvironmentConfig(normalize(applyEnvironmentDefaults(environmentOverridden), { onDotIntoNonObject: \"ignore\" }) as any);\n\n const organizationMigrated = migrateConfigOverride(\"organization\", organizationInput);\n await assertNoConfigOverrideErrors(organizationConfigSchema, organizationMigrated);\n const organizationOverridden = override(environmentOverridden, organizationMigrated);\n await sanitizeOrganizationConfig(normalize(applyOrganizationDefaults(organizationOverridden), { onDotIntoNonObject: \"ignore\" }) as any);\n\n } catch (e) {\n const data = {\n cause: e,\n inputs: {\n projectInput,\n branchInput,\n environmentInput,\n organizationInput,\n },\n } as const;\n console.error(\"Failed to fuzz schema in iteration ${i}/${totalIterations}!\", nicify(data));\n throw new StackAssertionError(`Error in iteration ${i}/${totalIterations} of schema fuzz: ${e}`, { cause: e });\n }\n }\n});\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,4BAA4B;AACrC,SAAS,2BAA2B;AACpC,SAAS,gBAAgB,cAAc,KAAK,cAAc,wBAAwB;AAClF,SAAS,cAAc;AACvB,SAAS,WAAW,gBAAgB;AACpC,SAAqJ,qBAAqB,0BAA0B,2BAA2B,sBAAsB,8BAA8B,oBAAoB,yBAAyB,uBAAuB,0BAA0B,qBAAqB,sBAAsB,2BAA2B,4BAA4B,6BAA6B;AAgBhf,IAAM,2BAA2B,CAAC;AAAA,EAChC,SAAS,CAAC;AAAA,IACR,SAAS,CAAC;AAAA,MACR,MAAM,CAAC,MAAM,KAAK;AAAA,MAClB,MAAM,CAAC,MAAM,KAAK;AAAA,IACpB,C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E,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,CAAC;AAAA,QAChI,GAAG,MAAM,CAAC;AAAA,QACV,UAAU,CAAC,MAAM,KAAK;AAAA,QACtB,UAAU,CAAC,gBAAgB;AAAA,QAC3B,cAAc,CAAC,oBAAoB;AAAA,QACnC,kBAAkB,CAAC,yBAAyB;AAAA,QAC5C,mBAAmB,CAAC,0BAA0B;AAAA,MAChD,CAAC,CAAC,CAAC,CAAC,CAAC;AAAA,IACP,CAAC;AAAA,EACH,CAAC;AAAA,EACD,SAAS,CAAC;AAAA,IACR,GAAG,yBAAyB,CAAC,EAAE,QAAQ,CAAC;AAAA,IACxC,gBAAgB,CAAC;AAAA,MACf,kBAAkB,CAAC;AAAA,QACjB,SAAS,CAAC,oCAAoC;AAAA,QAC9C,aAAa,CAAC,iBAAiB;AAAA,MACjC,CAAC;AAAA,IACH,CAAC;AAAA,EACH,CAAC;AAAA,EACD,QAAQ,CAAC;AAAA,IACP,GAAG,yBAAyB,CAAC,EAAE,OAAO,CAAC;AAAA,IACvC,QAAQ,CAAC;AAAA,MACP,UAAU,CAAC,MAAM,KAAK;AAAA,MACtB,UAAU,CAAC,UAAU,MAAM;AAAA,MAC3B,MAAM,CAAC,eAAe,sCAAsC;AAAA,MAC5D,MAAM,CAAC,MAAM,SAAS,MAAM,QAAQ;AAAA,MACpC,UAAU,CAAC,iBAAiB,4BAA4B;AAAA,MACxD,UAAU,CAAC,iBAAiB,4BAA4B;AAAA,MACxD,YAAY,CAAC,aAAa;AAAA,MAC1B,aAAa,CAAC,2BAA2B,oBAAoB;AAAA,IAC/D,CAAC;AAAA,EACH,CAAC;AACH,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/config/schema-fuzzer.test.ts"],"sourcesContent":["import { ALL_APPS } from \"../apps/apps-config\";\nimport { SUPPORTED_CURRENCIES } from \"../utils/currency-constants\";\nimport { StackAssertionError } from \"../utils/errors\";\nimport { getOrUndefined, isObjectLike, set, typedEntries, typedFromEntries } from \"../utils/objects\";\nimport { nicify } from \"../utils/strings\";\nimport { normalize, override } from \"./format\";\nimport { BranchConfigNormalizedOverride, EnvironmentConfigNormalizedOverride, OrganizationConfigNormalizedOverride, ProjectConfigNormalizedOverride, applyBranchDefaults, applyEnvironmentDefaults, applyOrganizationDefaults, applyProjectDefaults, assertNoConfigOverrideErrors, branchConfigSchema, environmentConfigSchema, migrateConfigOverride, organizationConfigSchema, projectConfigSchema, sanitizeBranchConfig, sanitizeEnvironmentConfig, sanitizeOrganizationConfig, sanitizeProjectConfig } from \"./schema\";\n\ntype FuzzerConfig<T> = ReadonlyArray<T extends object ? ([T] extends [any[]] ? { readonly [K in keyof T]: FuzzerConfig<T[K]> } : Required<{\n [K in keyof T]: FuzzerConfig<T[K]>;\n}> & Record<string, FuzzerConfig<any>>) : T>;\n\nconst projectSchemaFuzzerConfig = [{\n sourceOfTruth: [{\n type: [\"hosted\", \"neon\", \"postgres\"],\n connectionString: [\"\", \"postgres://user:password@host:port/database\", \"THIS IS A STRING LOLOL\"],\n connectionStrings: [{\n \"123-some-branch-id\": [\"\", \"THIS IS A CONNECTION STRING OR SO\"],\n }],\n }],\n}] satisfies FuzzerConfig<ProjectConfigNormalizedOverride>;\n\nconst branchSchemaFuzzerConfig = [{\n apiKeys: [{\n enabled: [{\n team: [true, false],\n user: [true, false],\n }],\n }],\n auth: [{\n allowSignUp: [true, false],\n password: [{\n allowSignIn: [true, false],\n }],\n otp: [{\n allowSignIn: [true, false],\n }],\n passkey: [{\n allowSignIn: [true, false],\n }],\n oauth: [{\n accountMergeStrategy: [\"link_method\", \"raise_error\", \"allow_duplicates\"],\n providers: [{\n \"google\": [{\n type: [\"google\", \"github\", \"x\"] as const,\n allowSignIn: [true, false],\n allowConnectedAccounts: [true, false],\n }],\n }],\n }],\n }],\n dataVault: [{\n stores: [{\n \"some-store-id\": [{\n displayName: [\"Some Store\", \"Some Other Store\"],\n }],\n \"some-other-store-id\": [{\n displayName: [\"Some Store\", \"Some Other Store\"],\n }],\n }],\n }],\n payments: [{\n blockNewPurchases: [false, true],\n testMode: [false, true],\n autoPay: [{\n interval: [[[0, 1, -3, 100, 0.333, Infinity], [\"day\", \"week\", \"month\", \"year\"]]] as const,\n }],\n productLines: [{\n \"some-product-line-id\": [{\n displayName: [\"Some Product Line\", \"Some Other Product Line\"],\n customerType: [\"user\", \"team\", \"custom\"] as const,\n }],\n }],\n catalogs: [{ // ensure migration works\n \"some-product-line-id\": [{\n displayName: [\"Some Product Line\", \"Some Other Product Line\"],\n }],\n }],\n groups: [{ // ensure migration works\n \"some-product-line-id\": [{\n displayName: [\"Some Product Line\", \"Some Other Product Line\"],\n }],\n }],\n items: [{\n \"some-item-id\": [{\n customerType: [\"user\", \"team\", \"custom\"] as const,\n displayName: [\"Some Item\", \"Some Other Item\"],\n }],\n }],\n products: [{\n \"some-product-id\": [{\n displayName: [\"Some Product\", \"Some Other Product\"],\n customerType: [\"user\", \"team\", \"custom\"] as const,\n freeTrial: [[[0, 1, -3, 100, 0.333, Infinity], [\"day\", \"week\", \"month\", \"year\"]]] as const,\n serverOnly: [true, false],\n stackable: [true, false],\n productLineId: [\"some-product-line-id\", \"some-other-product-line-id\"],\n catalogId: [\"some-product-line-id\", \"some-other-product-line-id\"], // ensure migration works\n groupId: [\"some-product-line-id\", \"some-other-product-line-id\"], // ensure migration works\n isAddOnTo: [false, { \"some-product-id\": [true], \"some-other-product-id\": [true] }] as const,\n prices: [\"include-by-default\" as \"include-by-default\", {\n \"some-price-id\": [{\n ...typedFromEntries(SUPPORTED_CURRENCIES.map(currency => [currency.code, [\"100_00\", \"not a number\", \"Infinity\", \"0\"]])),\n interval: [[[0, 1, -3, 100, 0.333, Infinity], [\"day\", \"week\", \"month\", \"year\"]]] as const,\n serverOnly: [true, false],\n freeTrial: [[[0, 1, -3, 100, 0.333, Infinity], [\"day\", \"week\", \"month\", \"year\"]]] as const,\n }],\n }],\n includedItems: [{\n \"some-item-id\": [{\n quantity: [0, 1, -3, 100, 0.333, Infinity],\n repeat: [\"never\", [[0, 1, -3, 100, 0.333, Infinity], [\"day\", \"week\", \"month\", \"year\"]]] as const,\n expires: [\"never\", \"when-purchase-expires\", \"when-repeated\"] as const,\n }],\n }],\n }],\n }],\n }],\n emails: [{\n themes: [{\n \"12345678-1234-4234-9234-123456789012\": [{\n displayName: [\"Some Theme\", \"Some Other Theme\"],\n tsxSource: [\"\", \"some typescript source code\"],\n }],\n }],\n selectedThemeId: [\"some-theme-id\", \"some-other-theme-id\"],\n templates: [{\n \"12345678-1234-4234-9234-123456789012\": [{\n themeId: [\"some-theme-id\", \"some-other-theme-id\"],\n displayName: [\"Some Template\", \"Some Other Template\"],\n tsxSource: [\"\", \"some typescript source code\"],\n }],\n }],\n }],\n teams: [{\n createPersonalTeamOnSignUp: [true, false],\n allowClientTeamCreation: [true, false],\n }],\n users: [{\n allowClientUserDeletion: [true, false],\n }],\n rbac: [{\n permissions: [{\n \"some_permission_id\": [{\n containedPermissionIds: [{\n \"some_permission_id\": [true],\n \"$some_other_permission_id\": [true],\n }] as const,\n description: [\"Some Permission\", \"Some Other Permission\"],\n scope: [\"team\", \"project\"] as const,\n }],\n }],\n defaultPermissions: [{\n teamCreator: [{\n \"some_permission_id\": [true],\n \"$some_other_permission_id\": [true],\n }] as const,\n teamMember: [{\n \"some_permission_id\": [true],\n \"$some_other_permission_id\": [true],\n }] as const,\n signUp: [{\n \"some_permission_id\": [true],\n \"$some_other_permission_id\": [true],\n }] as const,\n }],\n }],\n domains: [{\n allowLocalhost: [true, false],\n }],\n apps: [{\n installed: [typedFromEntries(typedEntries(ALL_APPS).map(([key, value]) => [key, [{\n enabled: [true, false],\n }]]))],\n }],\n onboarding: [{\n requireEmailVerification: [true, false],\n }],\n}] satisfies FuzzerConfig<BranchConfigNormalizedOverride>;\n\nconst environmentSchemaFuzzerConfig = [{\n ...branchSchemaFuzzerConfig[0],\n auth: [{\n ...branchSchemaFuzzerConfig[0].auth[0],\n oauth: [{\n ...branchSchemaFuzzerConfig[0].auth[0].oauth[0],\n providers: [typedFromEntries(typedEntries(branchSchemaFuzzerConfig[0].auth[0].oauth[0].providers[0]).map(([key, value]) => [key, [{\n ...value[0],\n isShared: [true, false],\n clientId: [\"some-client-id\"],\n clientSecret: [\"some-client-secret\"],\n facebookConfigId: [\"some-facebook-config-id\"],\n microsoftTenantId: [\"some-microsoft-tenant-id\"],\n }]]))] as const,\n }],\n }],\n domains: [{\n ...branchSchemaFuzzerConfig[0].domains[0],\n trustedDomains: [{\n \"some-domain-id\": [{\n baseUrl: [\"https://example.com/something-here\"],\n handlerPath: [\"/something-here\"],\n }],\n }],\n }],\n emails: [{\n ...branchSchemaFuzzerConfig[0].emails[0],\n server: [{\n isShared: [true, false],\n provider: [\"resend\", \"smtp\"] as const,\n host: [\"example.com\", \"://super weird host that's not valid\"],\n port: [1234, 0.12543, -100, Infinity],\n username: [\"some-username\", \"some username with a space\"],\n password: [\"some-password\", \"some password with a space\"],\n senderName: [\"Some Sender\"],\n senderEmail: [\"some-sender@example.com\", \"some invalid email\"],\n }],\n }],\n}] satisfies FuzzerConfig<EnvironmentConfigNormalizedOverride>;\n\nconst organizationSchemaFuzzerConfig = environmentSchemaFuzzerConfig satisfies FuzzerConfig<OrganizationConfigNormalizedOverride>;\n\nfunction setDeep<T>(obj: T, path: string[], value: any) {\n if (!isObjectLike(obj)) return obj;\n\n if (path.length === 0) {\n throw new Error(\"Path is empty\");\n } else if (path.length === 1) {\n set(obj as any, path[0], value);\n } else {\n const [key, ...rest] = path;\n setDeep(getOrUndefined(obj as any, key), rest, value);\n }\n}\n\nfunction createFuzzerInput<T>(config: FuzzerConfig<T>, progress: number): T {\n progress = Math.min(1, 2 * progress);\n const createShouldRandom = (strength: number) => {\n const chance = Math.random() * strength * 1.2 - 0.1;\n return () => Math.random() < chance;\n };\n const createShouldObjectDependent = (strength: number) => {\n const objectChance = Math.random() * strength * 1.2 - 0.1;\n const primitiveChance = Math.random() * strength * 1.2 - 0.1;\n return (v: any) => Math.random() * Math.random() < (isObjectLike(v) ? objectChance : primitiveChance);\n };\n\n const shouldKeep = createShouldObjectDependent(progress * 1);\n const shouldMakeNested = createShouldObjectDependent(1.25);\n const shouldNull = createShouldRandom(0.25);\n\n let res: any;\n const recurse = <U>(outputPath: string[], config: FuzzerConfig<U>, forceNested: boolean, forceNonNull: boolean) => {\n let subConfig: any = config[Math.floor(Math.random() * config.length)];\n const originalValue = isObjectLike(subConfig) ? (Array.isArray(subConfig) ? [] : {}) : subConfig;\n\n const newValue = forceNonNull || !shouldNull() ? originalValue : null;\n const newOutputPath = forceNested || shouldMakeNested(originalValue) || outputPath.length === 0 ? outputPath : [outputPath.join(\".\")];\n if (outputPath.length === 0) {\n res = newValue;\n } else {\n if (forceNested || shouldKeep(originalValue)) {\n setDeep(res, newOutputPath, newValue);\n }\n }\n if (isObjectLike(subConfig)) {\n for (const [key, newValue] of typedEntries(subConfig)) {\n recurse([...newOutputPath, key], newValue, Array.isArray(subConfig), Array.isArray(subConfig));\n }\n }\n };\n recurse<T>([], config, false, true);\n return res;\n}\n\nundefined?.test(\"fuzz schemas\", async ({ expect }) => {\n const totalIterations = process.env.CI ? 1000 : 200;\n for (let i = 0; i < totalIterations; i++) {\n const projectInput = createFuzzerInput<ProjectConfigNormalizedOverride>(projectSchemaFuzzerConfig, i / totalIterations);\n const branchInput = createFuzzerInput<BranchConfigNormalizedOverride>(branchSchemaFuzzerConfig, i / totalIterations);\n const environmentInput = createFuzzerInput<EnvironmentConfigNormalizedOverride>(environmentSchemaFuzzerConfig, i / totalIterations);\n const organizationInput = createFuzzerInput<OrganizationConfigNormalizedOverride>(organizationSchemaFuzzerConfig, i / totalIterations);\n\n try {\n const projectMigrated = migrateConfigOverride(\"project\", projectInput);\n await assertNoConfigOverrideErrors(projectConfigSchema, projectMigrated);\n const projectOverridden = override({}, projectMigrated);\n await sanitizeProjectConfig(normalize(applyProjectDefaults(projectOverridden), { onDotIntoNonObject: \"ignore\" }) as any);\n\n const branchMigrated = migrateConfigOverride(\"branch\", branchInput);\n await assertNoConfigOverrideErrors(branchConfigSchema, branchMigrated);\n const branchOverridden = override(projectOverridden, branchMigrated);\n await sanitizeBranchConfig(normalize(applyBranchDefaults(branchOverridden), { onDotIntoNonObject: \"ignore\" }) as any);\n\n const environmentMigrated = migrateConfigOverride(\"environment\", environmentInput);\n await assertNoConfigOverrideErrors(environmentConfigSchema, environmentMigrated);\n const environmentOverridden = override(branchOverridden, environmentMigrated);\n await sanitizeEnvironmentConfig(normalize(applyEnvironmentDefaults(environmentOverridden), { onDotIntoNonObject: \"ignore\" }) as any);\n\n const organizationMigrated = migrateConfigOverride(\"organization\", organizationInput);\n await assertNoConfigOverrideErrors(organizationConfigSchema, organizationMigrated);\n const organizationOverridden = override(environmentOverridden, organizationMigrated);\n await sanitizeOrganizationConfig(normalize(applyOrganizationDefaults(organizationOverridden), { onDotIntoNonObject: \"ignore\" }) as any);\n\n } catch (e) {\n const data = {\n cause: e,\n inputs: {\n projectInput,\n branchInput,\n environmentInput,\n organizationInput,\n },\n } as const;\n console.error(\"Failed to fuzz schema in iteration ${i}/${totalIterations}!\", nicify(data));\n throw new StackAssertionError(`Error in iteration ${i}/${totalIterations} of schema fuzz: ${e}`, { cause: e });\n }\n }\n});\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,4BAA4B;AACrC,SAAS,2BAA2B;AACpC,SAAS,gBAAgB,cAAc,KAAK,cAAc,wBAAwB;AAClF,SAAS,cAAc;AACvB,SAAS,WAAW,gBAAgB;AACpC,SAAqJ,qBAAqB,0BAA0B,2BAA2B,sBAAsB,8BAA8B,oBAAoB,yBAAyB,uBAAuB,0BAA0B,qBAAqB,sBAAsB,2BAA2B,4BAA4B,6BAA6B;AAgBhf,IAAM,2BAA2B,CAAC;AAAA,EAChC,SAAS,CAAC;AAAA,IACR,SAAS,CAAC;AAAA,MACR,MAAM,CAAC,MAAM,KAAK;AAAA,MAClB,MAAM,CAAC,MAAM,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AC,aAAa;AAAA,MAC1B,aAAa,CAAC,2BAA2B,oBAAoB;AAAA,IAC/D,CAAC;AAAA,EACH,CAAC;AACH,CAAC;","names":[]}
|
|
@@ -7,10 +7,11 @@ import { productSchema, userSpecifiedIdSchema, yupBoolean, yupDate, yupMixed, yu
|
|
|
7
7
|
import { SUPPORTED_CURRENCIES } from "../utils/currency-constants.js";
|
|
8
8
|
import { StackAssertionError } from "../utils/errors.js";
|
|
9
9
|
import { allProviders } from "../utils/oauth.js";
|
|
10
|
-
import { filterUndefined, get, has, isObjectLike, mapValues, set, typedAssign, typedEntries, typedFromEntries } from "../utils/objects.js";
|
|
10
|
+
import { filterUndefined, get, getOrUndefined, has, isObjectLike, mapValues, set, typedAssign, typedEntries, typedFromEntries } from "../utils/objects.js";
|
|
11
11
|
import { Result } from "../utils/results.js";
|
|
12
12
|
import { typeAssert, typeAssertExtends, typeAssertIs } from "../utils/types.js";
|
|
13
13
|
import { NormalizationError, assertNormalized, getInvalidConfigReason, normalize } from "./format.js";
|
|
14
|
+
import { migrateCatalogsToProductLines } from "./migrate-catalogs-to-product-lines.js";
|
|
14
15
|
var configLevels = ["project", "branch", "environment", "organization"];
|
|
15
16
|
var permissionRegex = /^\$?[a-z0-9_:]+$/;
|
|
16
17
|
var customPermissionRegex = /^[a-z0-9_:]+$/;
|
|
@@ -113,16 +114,18 @@ var branchAuthSchema = yupObject({
|
|
|
113
114
|
})
|
|
114
115
|
});
|
|
115
116
|
var branchPaymentsSchema = yupObject({
|
|
117
|
+
blockNewPurchases: yupBoolean(),
|
|
116
118
|
autoPay: yupObject({
|
|
117
119
|
interval: schemaFields.dayIntervalSchema
|
|
118
120
|
}).optional(),
|
|
119
121
|
testMode: yupBoolean(),
|
|
120
|
-
|
|
121
|
-
userSpecifiedIdSchema("
|
|
122
|
+
productLines: yupRecord(
|
|
123
|
+
userSpecifiedIdSchema("productLineId"),
|
|
122
124
|
yupObject({
|
|
123
|
-
displayName: yupString().optional()
|
|
125
|
+
displayName: yupString().optional(),
|
|
126
|
+
customerType: schemaFields.customerTypeSchema
|
|
124
127
|
})
|
|
125
|
-
).meta({ openapiField: { description: "The
|
|
128
|
+
).meta({ openapiField: { description: "The product lines that products can be in. All products in a product line (besides add-ons) are mutually exclusive.", exampleValue: { "product-line-id": { displayName: "My Product Line", customerType: "user" } } } }),
|
|
126
129
|
products: yupRecord(
|
|
127
130
|
userSpecifiedIdSchema("productId"),
|
|
128
131
|
productSchema
|
|
@@ -134,7 +137,30 @@ var branchPaymentsSchema = yupObject({
|
|
|
134
137
|
customerType: schemaFields.customerTypeSchema
|
|
135
138
|
})
|
|
136
139
|
)
|
|
137
|
-
})
|
|
140
|
+
}).optional().test(
|
|
141
|
+
"product-customer-type-matches-product-line",
|
|
142
|
+
"Product customer type must match its product line customer type",
|
|
143
|
+
function(value) {
|
|
144
|
+
if (!value) return true;
|
|
145
|
+
for (const [productId, product] of Object.entries(value.products)) {
|
|
146
|
+
if (!product.productLineId) continue;
|
|
147
|
+
const productLine = getOrUndefined(value.productLines, product.productLineId);
|
|
148
|
+
if (productLine === void 0) {
|
|
149
|
+
return this.createError({
|
|
150
|
+
message: `Product "${productId}" specifies product line ID "${product.productLineId}", but that product line does not exist`,
|
|
151
|
+
path: `${this.path}.products.${productId}.productLineId`
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
if (product.customerType !== productLine.customerType) {
|
|
155
|
+
return this.createError({
|
|
156
|
+
message: `Product "${productId}" has customer type "${product.customerType}" but its product line "${product.productLineId}" has customer type "${productLine.customerType}"`,
|
|
157
|
+
path: `${this.path}.products.${productId}.customerType`
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
);
|
|
138
164
|
var branchDomain = yupObject({
|
|
139
165
|
allowLocalhost: yupBoolean()
|
|
140
166
|
});
|
|
@@ -254,6 +280,9 @@ function migrateConfigOverride(type, oldUnmigratedConfigOverride) {
|
|
|
254
280
|
res = removeProperty(res, (p) => p[0] === "workflows");
|
|
255
281
|
res = removeProperty(res, (p) => p[0] === "apps" && p[1] === "installed" && p[2] === "workflows");
|
|
256
282
|
}
|
|
283
|
+
if (isBranchOrHigher) {
|
|
284
|
+
res = migrateCatalogsToProductLines(res);
|
|
285
|
+
}
|
|
257
286
|
return res;
|
|
258
287
|
}
|
|
259
288
|
function removeProperty(obj, pathCond) {
|
|
@@ -392,14 +421,16 @@ var organizationConfigDefaults = {
|
|
|
392
421
|
}), DEFAULT_EMAIL_TEMPLATES)
|
|
393
422
|
},
|
|
394
423
|
payments: {
|
|
424
|
+
blockNewPurchases: false,
|
|
395
425
|
testMode: true,
|
|
396
426
|
autoPay: void 0,
|
|
397
|
-
|
|
398
|
-
displayName: void 0
|
|
427
|
+
productLines: (key) => ({
|
|
428
|
+
displayName: void 0,
|
|
429
|
+
customerType: void 0
|
|
399
430
|
}),
|
|
400
431
|
products: (key) => ({
|
|
401
432
|
displayName: key,
|
|
402
|
-
|
|
433
|
+
productLineId: void 0,
|
|
403
434
|
customerType: "user",
|
|
404
435
|
freeTrial: void 0,
|
|
405
436
|
serverOnly: false,
|