@sanity/cli 6.0.0-alpha.4 → 6.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (608) hide show
  1. package/dist/actions/dataset/create.d.ts +49 -0
  2. package/dist/actions/dataset/create.js +48 -0
  3. package/dist/actions/dataset/create.js.map +1 -0
  4. package/dist/actions/dataset/determineDatasetAclMode.d.ts +37 -0
  5. package/dist/actions/dataset/determineDatasetAclMode.js +36 -0
  6. package/dist/actions/dataset/determineDatasetAclMode.js.map +1 -0
  7. package/dist/actions/debug/gatherDebugInfo.js +15 -21
  8. package/dist/actions/debug/gatherDebugInfo.js.map +1 -1
  9. package/dist/actions/debug/types.d.ts +0 -2
  10. package/dist/actions/debug/types.js.map +1 -1
  11. package/dist/actions/deploy/deployApp.js +13 -0
  12. package/dist/actions/deploy/deployApp.js.map +1 -1
  13. package/dist/actions/dev/startStudioDevServer.js +3 -8
  14. package/dist/actions/dev/startStudioDevServer.js.map +1 -1
  15. package/dist/actions/dev/types.d.ts +1 -3
  16. package/dist/actions/dev/types.js.map +1 -1
  17. package/dist/actions/documents/validate.d.ts +0 -2
  18. package/dist/actions/documents/validate.js +21 -1
  19. package/dist/actions/documents/validate.js.map +1 -1
  20. package/dist/actions/exec/execScript.js +1 -1
  21. package/dist/actions/exec/execScript.js.map +1 -1
  22. package/dist/actions/graphql/getGraphQLAPIs.js +1 -1
  23. package/dist/actions/graphql/getGraphQLAPIs.js.map +1 -1
  24. package/dist/actions/init/remoteTemplate.js +1 -1
  25. package/dist/actions/init/remoteTemplate.js.map +1 -1
  26. package/dist/actions/manifest/extractAppManifest.d.ts +20 -0
  27. package/dist/actions/manifest/extractAppManifest.js +51 -0
  28. package/dist/actions/manifest/extractAppManifest.js.map +1 -0
  29. package/dist/actions/manifest/extractManifest.js +2 -5
  30. package/dist/actions/manifest/extractManifest.js.map +1 -1
  31. package/dist/actions/manifest/types.d.ts +6 -1
  32. package/dist/actions/manifest/types.js.map +1 -1
  33. package/dist/actions/media/importAspects.js +2 -1
  34. package/dist/actions/media/importAspects.js.map +1 -1
  35. package/dist/actions/schema/deleteSchemaAction.d.ts +13 -5
  36. package/dist/actions/schema/deleteSchemaAction.js +12 -17
  37. package/dist/actions/schema/deleteSchemaAction.js.map +1 -1
  38. package/dist/actions/schema/deploySchemas.d.ts +15 -0
  39. package/dist/actions/schema/deploySchemas.js +98 -0
  40. package/dist/actions/schema/deploySchemas.js.map +1 -0
  41. package/dist/actions/schema/listSchemas.d.ts +12 -0
  42. package/dist/actions/schema/listSchemas.js +119 -0
  43. package/dist/actions/schema/listSchemas.js.map +1 -0
  44. package/dist/actions/schema/schemaStoreTypes.d.ts +0 -11
  45. package/dist/actions/schema/schemaStoreTypes.js.map +1 -1
  46. package/dist/actions/schema/utils/debug.d.ts +2 -0
  47. package/dist/actions/schema/utils/debug.js +5 -0
  48. package/dist/actions/schema/utils/debug.js.map +1 -0
  49. package/dist/actions/schema/utils/manifestExtractor.d.ts +3 -8
  50. package/dist/actions/schema/utils/manifestExtractor.js +12 -17
  51. package/dist/actions/schema/utils/manifestExtractor.js.map +1 -1
  52. package/dist/actions/schema/utils/manifestReader.d.ts +2 -9
  53. package/dist/actions/schema/utils/manifestReader.js +6 -12
  54. package/dist/actions/schema/utils/manifestReader.js.map +1 -1
  55. package/dist/actions/schema/utils/schemaStoreOutStrings.d.ts +0 -1
  56. package/dist/actions/schema/utils/schemaStoreOutStrings.js +1 -1
  57. package/dist/actions/schema/utils/schemaStoreOutStrings.js.map +1 -1
  58. package/dist/actions/schema/utils/schemaStoreValidation.d.ts +10 -62
  59. package/dist/actions/schema/utils/schemaStoreValidation.js +38 -125
  60. package/dist/actions/schema/utils/schemaStoreValidation.js.map +1 -1
  61. package/dist/actions/schema/utils/uniqByProjectIdDataset.d.ts +14 -0
  62. package/dist/actions/schema/utils/uniqByProjectIdDataset.js +9 -0
  63. package/dist/actions/schema/utils/uniqByProjectIdDataset.js.map +1 -0
  64. package/dist/actions/users/getMembersForProject.d.ts +1 -3
  65. package/dist/actions/users/getMembersForProject.js +6 -17
  66. package/dist/actions/users/getMembersForProject.js.map +1 -1
  67. package/dist/actions/users/types.d.ts +0 -11
  68. package/dist/actions/users/types.js.map +1 -1
  69. package/dist/commands/backup/disable.js +5 -11
  70. package/dist/commands/backup/disable.js.map +1 -1
  71. package/dist/commands/backup/enable.js +5 -11
  72. package/dist/commands/backup/enable.js.map +1 -1
  73. package/dist/commands/backup/list.js +7 -8
  74. package/dist/commands/backup/list.js.map +1 -1
  75. package/dist/commands/cors/add.js +5 -13
  76. package/dist/commands/cors/add.js.map +1 -1
  77. package/dist/commands/cors/delete.js +7 -15
  78. package/dist/commands/cors/delete.js.map +1 -1
  79. package/dist/commands/cors/list.js +2 -10
  80. package/dist/commands/cors/list.js.map +1 -1
  81. package/dist/commands/dataset/create.d.ts +0 -2
  82. package/dist/commands/dataset/create.js +8 -54
  83. package/dist/commands/dataset/create.js.map +1 -1
  84. package/dist/commands/dataset/export.js +4 -4
  85. package/dist/commands/dataset/export.js.map +1 -1
  86. package/dist/commands/debug.js +5 -9
  87. package/dist/commands/debug.js.map +1 -1
  88. package/dist/commands/dev.js +0 -1
  89. package/dist/commands/dev.js.map +1 -1
  90. package/dist/commands/documents/create.d.ts +1 -0
  91. package/dist/commands/documents/create.js +10 -9
  92. package/dist/commands/documents/create.js.map +1 -1
  93. package/dist/commands/documents/delete.js +2 -3
  94. package/dist/commands/documents/delete.js.map +1 -1
  95. package/dist/commands/documents/get.js +2 -3
  96. package/dist/commands/documents/get.js.map +1 -1
  97. package/dist/commands/documents/query.js +2 -3
  98. package/dist/commands/documents/query.js.map +1 -1
  99. package/dist/commands/documents/validate.js +0 -20
  100. package/dist/commands/documents/validate.js.map +1 -1
  101. package/dist/commands/graphql/list.js +2 -2
  102. package/dist/commands/graphql/list.js.map +1 -1
  103. package/dist/commands/graphql/undeploy.js +4 -9
  104. package/dist/commands/graphql/undeploy.js.map +1 -1
  105. package/dist/commands/hook/create.js +2 -6
  106. package/dist/commands/hook/create.js.map +1 -1
  107. package/dist/commands/hook/delete.js +5 -17
  108. package/dist/commands/hook/delete.js.map +1 -1
  109. package/dist/commands/hook/list.js +2 -8
  110. package/dist/commands/hook/list.js.map +1 -1
  111. package/dist/commands/init.d.ts +6 -1
  112. package/dist/commands/init.js +358 -20
  113. package/dist/commands/init.js.map +1 -1
  114. package/dist/commands/manifest/extract.js +7 -8
  115. package/dist/commands/manifest/extract.js.map +1 -1
  116. package/dist/commands/media/export.js +2 -2
  117. package/dist/commands/media/export.js.map +1 -1
  118. package/dist/commands/media/import.js +2 -2
  119. package/dist/commands/media/import.js.map +1 -1
  120. package/dist/commands/projects/list.js +2 -6
  121. package/dist/commands/projects/list.js.map +1 -1
  122. package/dist/commands/schema/delete.d.ts +1 -1
  123. package/dist/commands/schema/delete.js +20 -23
  124. package/dist/commands/schema/delete.js.map +1 -1
  125. package/dist/commands/schema/deploy.d.ts +16 -0
  126. package/dist/commands/schema/deploy.js +98 -0
  127. package/dist/commands/schema/deploy.js.map +1 -0
  128. package/dist/commands/schema/list.d.ts +15 -0
  129. package/dist/commands/schema/list.js +104 -0
  130. package/dist/commands/schema/list.js.map +1 -0
  131. package/dist/commands/tokens/add.js +3 -5
  132. package/dist/commands/tokens/add.js.map +1 -1
  133. package/dist/commands/users/invite.js +6 -17
  134. package/dist/commands/users/invite.js.map +1 -1
  135. package/dist/commands/users/list.js +4 -7
  136. package/dist/commands/users/list.js.map +1 -1
  137. package/dist/config/createCliConfig.d.ts +13 -4
  138. package/dist/prompts/init/promptForTypescript.d.ts +2 -0
  139. package/dist/prompts/init/promptForTypescript.js +15 -0
  140. package/dist/prompts/init/promptForTypescript.js.map +1 -0
  141. package/dist/prompts/promptForDatasetAclMode.d.ts +9 -0
  142. package/dist/prompts/promptForDatasetAclMode.js +27 -0
  143. package/dist/prompts/promptForDatasetAclMode.js.map +1 -0
  144. package/dist/prompts/promptForDatasetName.d.ts +1 -1
  145. package/dist/prompts/promptForDatasetName.js +4 -1
  146. package/dist/prompts/promptForDatasetName.js.map +1 -1
  147. package/dist/services/backup.d.ts +8 -0
  148. package/dist/services/backup.js +19 -0
  149. package/dist/services/backup.js.map +1 -1
  150. package/dist/services/cors.d.ts +23 -0
  151. package/dist/services/cors.js +38 -0
  152. package/dist/services/cors.js.map +1 -0
  153. package/dist/services/graphql.d.ts +7 -0
  154. package/dist/services/graphql.js +11 -0
  155. package/dist/services/graphql.js.map +1 -1
  156. package/dist/services/hooks.d.ts +2 -0
  157. package/dist/services/hooks.js +19 -0
  158. package/dist/services/hooks.js.map +1 -1
  159. package/dist/services/organizations.d.ts +4 -2
  160. package/dist/services/organizations.js +3 -2
  161. package/dist/services/organizations.js.map +1 -1
  162. package/dist/services/projects.d.ts +11 -0
  163. package/dist/services/projects.js +41 -0
  164. package/dist/services/projects.js.map +1 -1
  165. package/dist/services/schemas.d.ts +4 -0
  166. package/dist/services/schemas.js +40 -0
  167. package/dist/services/schemas.js.map +1 -0
  168. package/dist/services/user.d.ts +13 -0
  169. package/dist/services/user.js +27 -3
  170. package/dist/services/user.js.map +1 -1
  171. package/dist/services/userApplications.d.ts +3 -1
  172. package/dist/services/userApplications.js +5 -1
  173. package/dist/services/userApplications.js.map +1 -1
  174. package/dist/util/errorMessages.d.ts +1 -0
  175. package/dist/util/errorMessages.js +1 -0
  176. package/dist/util/errorMessages.js.map +1 -1
  177. package/dist/util/getCliVersion.js +1 -1
  178. package/dist/util/getCliVersion.js.map +1 -1
  179. package/dist/util/readPackageJson.d.ts +1 -15
  180. package/dist/util/readPackageJson.js +1 -1
  181. package/dist/util/readPackageJson.js.map +1 -1
  182. package/dist/util/uniqBy.d.ts +1 -0
  183. package/dist/util/uniqBy.js +14 -0
  184. package/dist/util/uniqBy.js.map +1 -0
  185. package/oclif.manifest.json +284 -139
  186. package/package.json +36 -33
  187. package/templates/app-quickstart/src/App.css +20 -0
  188. package/templates/app-quickstart/src/App.tsx +25 -0
  189. package/templates/app-quickstart/src/ExampleComponent.css +90 -0
  190. package/templates/app-quickstart/src/ExampleComponent.tsx +37 -0
  191. package/templates/app-sanity-ui/src/App.tsx +34 -0
  192. package/templates/app-sanity-ui/src/ExampleComponent.tsx +34 -0
  193. package/templates/app-sanity-ui/src/SanityUI.tsx +23 -0
  194. package/templates/blog/README.md +11 -0
  195. package/templates/blog/schemaTypes/author.js +50 -0
  196. package/templates/blog/schemaTypes/blockContent.js +67 -0
  197. package/templates/blog/schemaTypes/category.js +19 -0
  198. package/templates/blog/schemaTypes/index.js +6 -0
  199. package/templates/blog/schemaTypes/post.js +65 -0
  200. package/templates/blog/static/.gitkeep +1 -0
  201. package/templates/clean/README.md +9 -0
  202. package/templates/clean/schemaTypes/index.js +1 -0
  203. package/templates/clean/static/.gitkeep +1 -0
  204. package/templates/ecommerce/README.md +11 -0
  205. package/templates/ecommerce/plugins/.gitkeep +1 -0
  206. package/templates/ecommerce/plugins/barcode-input/BarcodeInput.js +62 -0
  207. package/templates/ecommerce/plugins/barcode-input/index.js +9 -0
  208. package/templates/ecommerce/plugins/barcode-input/schemaType.js +60 -0
  209. package/templates/ecommerce/schemaTypes/blockContent.js +67 -0
  210. package/templates/ecommerce/schemaTypes/category.js +39 -0
  211. package/templates/ecommerce/schemaTypes/index.js +23 -0
  212. package/templates/ecommerce/schemaTypes/locale/localeBlockContent.js +19 -0
  213. package/templates/ecommerce/schemaTypes/locale/localeString.js +19 -0
  214. package/templates/ecommerce/schemaTypes/locale/localeText.js +19 -0
  215. package/templates/ecommerce/schemaTypes/locale/supportedLanguages.js +5 -0
  216. package/templates/ecommerce/schemaTypes/product.js +83 -0
  217. package/templates/ecommerce/schemaTypes/productVariant.js +52 -0
  218. package/templates/ecommerce/schemaTypes/vendor.js +39 -0
  219. package/templates/ecommerce/static/.gitkeep +1 -0
  220. package/templates/get-started/README.md +9 -0
  221. package/templates/get-started/plugins/.gitkeep +1 -0
  222. package/templates/get-started/plugins/sanity-plugin-tutorial/CustomDefaultLayout.tsx +16 -0
  223. package/templates/get-started/plugins/sanity-plugin-tutorial/GetStartedTutorial.tsx +104 -0
  224. package/templates/get-started/plugins/sanity-plugin-tutorial/index.ts +11 -0
  225. package/templates/get-started/schemaTypes/index.ts +1 -0
  226. package/templates/get-started/static/.gitkeep +1 -0
  227. package/templates/moviedb/README.md +10 -0
  228. package/templates/moviedb/schemaTypes/blockContent.js +67 -0
  229. package/templates/moviedb/schemaTypes/castMember.js +37 -0
  230. package/templates/moviedb/schemaTypes/crewMember.js +52 -0
  231. package/templates/moviedb/schemaTypes/index.js +22 -0
  232. package/templates/moviedb/schemaTypes/movie.js +85 -0
  233. package/templates/moviedb/schemaTypes/person.js +37 -0
  234. package/templates/moviedb/schemaTypes/plotSummaries.js +20 -0
  235. package/templates/moviedb/schemaTypes/plotSummary.js +24 -0
  236. package/templates/moviedb/schemaTypes/screening.js +81 -0
  237. package/templates/moviedb/static/.gitkeep +1 -0
  238. package/templates/quickstart/README.md +9 -0
  239. package/templates/quickstart/schemaTypes/index.js +1 -0
  240. package/templates/quickstart/static/.gitkeep +1 -0
  241. package/templates/shared/gitignore.txt +29 -0
  242. package/templates/shared/tsconfig.json +17 -0
  243. package/templates/shopify/README.md +85 -0
  244. package/templates/shopify/components/hotspots/ProductTooltip.tsx +38 -0
  245. package/templates/shopify/components/icons/Shopify.tsx +20 -0
  246. package/templates/shopify/components/inputs/CollectionHidden.tsx +23 -0
  247. package/templates/shopify/components/inputs/PlaceholderString.tsx +20 -0
  248. package/templates/shopify/components/inputs/ProductHidden.tsx +64 -0
  249. package/templates/shopify/components/inputs/ProductVariantHidden.tsx +24 -0
  250. package/templates/shopify/components/inputs/ProxyString.tsx +32 -0
  251. package/templates/shopify/components/media/ColorTheme.tsx +38 -0
  252. package/templates/shopify/components/media/ShopifyDocumentStatus.tsx +82 -0
  253. package/templates/shopify/components/studio/Navbar.tsx +29 -0
  254. package/templates/shopify/constants.ts +61 -0
  255. package/templates/shopify/docs/features.md +158 -0
  256. package/templates/shopify/plugins/customDocumentActions/index.ts +55 -0
  257. package/templates/shopify/plugins/customDocumentActions/shopifyDelete.tsx +144 -0
  258. package/templates/shopify/plugins/customDocumentActions/shopifyLink.ts +39 -0
  259. package/templates/shopify/plugins/customDocumentActions/types.ts +14 -0
  260. package/templates/shopify/schemaTypes/documents/collection.tsx +142 -0
  261. package/templates/shopify/schemaTypes/documents/colorTheme.tsx +44 -0
  262. package/templates/shopify/schemaTypes/documents/page.ts +70 -0
  263. package/templates/shopify/schemaTypes/documents/product.tsx +132 -0
  264. package/templates/shopify/schemaTypes/documents/productVariant.tsx +67 -0
  265. package/templates/shopify/schemaTypes/index.ts +108 -0
  266. package/templates/shopify/schemaTypes/objects/collection/collectionGroupType.ts +27 -0
  267. package/templates/shopify/schemaTypes/objects/collection/collectionLinksType.ts +16 -0
  268. package/templates/shopify/schemaTypes/objects/customProductOption/customProductOptionColorObjectType.tsx +48 -0
  269. package/templates/shopify/schemaTypes/objects/customProductOption/customProductOptionColorType.tsx +50 -0
  270. package/templates/shopify/schemaTypes/objects/customProductOption/customProductOptionSizeObjectType.ts +40 -0
  271. package/templates/shopify/schemaTypes/objects/customProductOption/customProductOptionSizeType.ts +49 -0
  272. package/templates/shopify/schemaTypes/objects/global/footerType.ts +22 -0
  273. package/templates/shopify/schemaTypes/objects/global/menuLinksType.ts +21 -0
  274. package/templates/shopify/schemaTypes/objects/global/menuType.ts +17 -0
  275. package/templates/shopify/schemaTypes/objects/global/notFoundPageType.ts +37 -0
  276. package/templates/shopify/schemaTypes/objects/hotspot/imageWithProductHotspotsType.ts +48 -0
  277. package/templates/shopify/schemaTypes/objects/hotspot/productHotspotsType.tsx +17 -0
  278. package/templates/shopify/schemaTypes/objects/hotspot/spotType.tsx +60 -0
  279. package/templates/shopify/schemaTypes/objects/link/linkEmailType.tsx +34 -0
  280. package/templates/shopify/schemaTypes/objects/link/linkExternalType.tsx +37 -0
  281. package/templates/shopify/schemaTypes/objects/link/linkInternalType.tsx +33 -0
  282. package/templates/shopify/schemaTypes/objects/link/linkProductType.tsx +60 -0
  283. package/templates/shopify/schemaTypes/objects/module/accordionGroupType.ts +33 -0
  284. package/templates/shopify/schemaTypes/objects/module/accordionType.ts +28 -0
  285. package/templates/shopify/schemaTypes/objects/module/callToActionType.tsx +85 -0
  286. package/templates/shopify/schemaTypes/objects/module/calloutType.ts +38 -0
  287. package/templates/shopify/schemaTypes/objects/module/collectionReferenceType.tsx +47 -0
  288. package/templates/shopify/schemaTypes/objects/module/gridItemType.ts +41 -0
  289. package/templates/shopify/schemaTypes/objects/module/gridType.ts +28 -0
  290. package/templates/shopify/schemaTypes/objects/module/heroType.tsx +40 -0
  291. package/templates/shopify/schemaTypes/objects/module/imageCallToActionType.tsx +19 -0
  292. package/templates/shopify/schemaTypes/objects/module/imageFeatureType.ts +80 -0
  293. package/templates/shopify/schemaTypes/objects/module/imageFeaturesType.tsx +51 -0
  294. package/templates/shopify/schemaTypes/objects/module/instagramType.ts +35 -0
  295. package/templates/shopify/schemaTypes/objects/module/productFeaturesType.tsx +50 -0
  296. package/templates/shopify/schemaTypes/objects/module/productReferenceType.tsx +42 -0
  297. package/templates/shopify/schemaTypes/objects/seoType.ts +31 -0
  298. package/templates/shopify/schemaTypes/objects/shopify/collectionRuleType.tsx +37 -0
  299. package/templates/shopify/schemaTypes/objects/shopify/inventoryType.ts +25 -0
  300. package/templates/shopify/schemaTypes/objects/shopify/optionType.tsx +31 -0
  301. package/templates/shopify/schemaTypes/objects/shopify/placeholderStringType.ts +11 -0
  302. package/templates/shopify/schemaTypes/objects/shopify/priceRangeType.ts +20 -0
  303. package/templates/shopify/schemaTypes/objects/shopify/productWithVariantType.tsx +142 -0
  304. package/templates/shopify/schemaTypes/objects/shopify/proxyStringType.ts +12 -0
  305. package/templates/shopify/schemaTypes/objects/shopify/shopType.ts +15 -0
  306. package/templates/shopify/schemaTypes/objects/shopify/shopifyCollectionType.ts +84 -0
  307. package/templates/shopify/schemaTypes/objects/shopify/shopifyProductType.ts +131 -0
  308. package/templates/shopify/schemaTypes/objects/shopify/shopifyProductVariantType.ts +121 -0
  309. package/templates/shopify/schemaTypes/portableText/portableTextSimpleType.tsx +45 -0
  310. package/templates/shopify/schemaTypes/portableText/portableTextType.tsx +52 -0
  311. package/templates/shopify/schemaTypes/singletons/homeType.ts +49 -0
  312. package/templates/shopify/schemaTypes/singletons/settingsType.ts +96 -0
  313. package/templates/shopify/static/.gitkeep +1 -0
  314. package/templates/shopify/structure/collectionStructure.ts +9 -0
  315. package/templates/shopify/structure/colorThemeStructure.ts +9 -0
  316. package/templates/shopify/structure/homeStructure.ts +9 -0
  317. package/templates/shopify/structure/index.ts +57 -0
  318. package/templates/shopify/structure/pageStructure.ts +11 -0
  319. package/templates/shopify/structure/productStructure.ts +51 -0
  320. package/templates/shopify/structure/settingStructure.ts +9 -0
  321. package/templates/shopify/utils/blocksToText.ts +20 -0
  322. package/templates/shopify/utils/defineStructure.ts +11 -0
  323. package/templates/shopify/utils/getPriceRange.ts +24 -0
  324. package/templates/shopify/utils/shopifyUrls.ts +22 -0
  325. package/templates/shopify/utils/validateSlug.ts +18 -0
  326. package/templates/shopify-online-storefront/README.md +54 -0
  327. package/templates/shopify-online-storefront/components/icons/Shopify.tsx +22 -0
  328. package/templates/shopify-online-storefront/components/inputs/CollectionHidden.tsx +23 -0
  329. package/templates/shopify-online-storefront/components/inputs/PlaceholderString.tsx +25 -0
  330. package/templates/shopify-online-storefront/components/inputs/ProductHidden.tsx +66 -0
  331. package/templates/shopify-online-storefront/components/inputs/ProductVariantHidden.tsx +25 -0
  332. package/templates/shopify-online-storefront/components/inputs/ProxyString.tsx +38 -0
  333. package/templates/shopify-online-storefront/components/media/ShopifyDocumentStatus.tsx +83 -0
  334. package/templates/shopify-online-storefront/constants.ts +18 -0
  335. package/templates/shopify-online-storefront/plugins/shopifyDocumentActions/index.ts +45 -0
  336. package/templates/shopify-online-storefront/plugins/shopifyDocumentActions/shopifyDelete.tsx +144 -0
  337. package/templates/shopify-online-storefront/plugins/shopifyDocumentActions/shopifyLink.ts +39 -0
  338. package/templates/shopify-online-storefront/plugins/shopifyDocumentActions/types.ts +14 -0
  339. package/templates/shopify-online-storefront/schemaTypes/blocks/blockContent.ts +32 -0
  340. package/templates/shopify-online-storefront/schemaTypes/documents/collection.tsx +83 -0
  341. package/templates/shopify-online-storefront/schemaTypes/documents/product.tsx +102 -0
  342. package/templates/shopify-online-storefront/schemaTypes/documents/productVariant.tsx +82 -0
  343. package/templates/shopify-online-storefront/schemaTypes/index.ts +43 -0
  344. package/templates/shopify-online-storefront/schemaTypes/objects/accordion.ts +31 -0
  345. package/templates/shopify-online-storefront/schemaTypes/objects/accordionGroup.ts +35 -0
  346. package/templates/shopify-online-storefront/schemaTypes/objects/callout.ts +40 -0
  347. package/templates/shopify-online-storefront/schemaTypes/objects/inventory.ts +30 -0
  348. package/templates/shopify-online-storefront/schemaTypes/objects/option.ts +30 -0
  349. package/templates/shopify-online-storefront/schemaTypes/objects/priceRange.ts +22 -0
  350. package/templates/shopify-online-storefront/schemaTypes/objects/proxyString.ts +11 -0
  351. package/templates/shopify-online-storefront/schemaTypes/objects/shopifyCollection.ts +109 -0
  352. package/templates/shopify-online-storefront/schemaTypes/objects/shopifyCollectionRule.tsx +45 -0
  353. package/templates/shopify-online-storefront/schemaTypes/objects/shopifyProduct.ts +165 -0
  354. package/templates/shopify-online-storefront/schemaTypes/objects/shopifyProductVariant.ts +151 -0
  355. package/templates/shopify-online-storefront/structure/collectionStructure.ts +9 -0
  356. package/templates/shopify-online-storefront/structure/index.ts +37 -0
  357. package/templates/shopify-online-storefront/structure/productStructure.ts +35 -0
  358. package/templates/shopify-online-storefront/utils/defineStructure.ts +11 -0
  359. package/templates/shopify-online-storefront/utils/getPriceRange.ts +24 -0
  360. package/templates/shopify-online-storefront/utils/shopifyUrls.ts +22 -0
  361. package/dist/actions/build/__tests__/buildApp.test.js +0 -367
  362. package/dist/actions/build/__tests__/buildApp.test.js.map +0 -1
  363. package/dist/actions/build/__tests__/buildStudio.test.js +0 -561
  364. package/dist/actions/build/__tests__/buildStudio.test.js.map +0 -1
  365. package/dist/actions/build/__tests__/checkRequiredDependencies.test.js +0 -233
  366. package/dist/actions/build/__tests__/checkRequiredDependencies.test.js.map +0 -1
  367. package/dist/actions/build/__tests__/checkStudioDependencyVersions.test.js +0 -414
  368. package/dist/actions/build/__tests__/checkStudioDependencyVersions.test.js.map +0 -1
  369. package/dist/actions/build/__tests__/determineBasePath.test.js +0 -24
  370. package/dist/actions/build/__tests__/determineBasePath.test.js.map +0 -1
  371. package/dist/actions/build/__tests__/getAutoUpdatesImportMap.test.js +0 -109
  372. package/dist/actions/build/__tests__/getAutoUpdatesImportMap.test.js.map +0 -1
  373. package/dist/actions/build/__tests__/getViteConfig.test.js +0 -493
  374. package/dist/actions/build/__tests__/getViteConfig.test.js.map +0 -1
  375. package/dist/actions/build/__tests__/renderDocument.test.js +0 -278
  376. package/dist/actions/build/__tests__/renderDocument.test.js.map +0 -1
  377. package/dist/actions/build/__tests__/shouldAutoUpdate.test.js +0 -153
  378. package/dist/actions/build/__tests__/shouldAutoUpdate.test.js.map +0 -1
  379. package/dist/actions/build/renderDocumentWorker/__tests__/renderDocumentWorker.test.js +0 -657
  380. package/dist/actions/build/renderDocumentWorker/__tests__/renderDocumentWorker.test.js.map +0 -1
  381. package/dist/actions/cors/constants.d.ts +0 -1
  382. package/dist/actions/cors/constants.js +0 -3
  383. package/dist/actions/cors/constants.js.map +0 -1
  384. package/dist/actions/cors/types.d.ts +0 -9
  385. package/dist/actions/cors/types.js +0 -3
  386. package/dist/actions/cors/types.js.map +0 -1
  387. package/dist/actions/dataset/__tests__/validateDatasetName.test.js +0 -182
  388. package/dist/actions/dataset/__tests__/validateDatasetName.test.js.map +0 -1
  389. package/dist/actions/deploy/__tests__/checkDir.test.js +0 -120
  390. package/dist/actions/deploy/__tests__/checkDir.test.js.map +0 -1
  391. package/dist/actions/docs/__tests__/normalizeDocsPath.test.js +0 -16
  392. package/dist/actions/docs/__tests__/normalizeDocsPath.test.js.map +0 -1
  393. package/dist/actions/documents/validation/reporters/prettyReporter/__tests__/formatDocumentValidation.test.js +0 -124
  394. package/dist/actions/documents/validation/reporters/prettyReporter/__tests__/formatDocumentValidation.test.js.map +0 -1
  395. package/dist/actions/graphql/__tests__/getGraphQLAPIs.test.js +0 -274
  396. package/dist/actions/graphql/__tests__/getGraphQLAPIs.test.js.map +0 -1
  397. package/dist/actions/media/__tests__/importMedia.test.js +0 -182
  398. package/dist/actions/media/__tests__/importMedia.test.js.map +0 -1
  399. package/dist/actions/schema/__tests__/deleteSchemaAction.test.js +0 -294
  400. package/dist/actions/schema/__tests__/deleteSchemaAction.test.js.map +0 -1
  401. package/dist/actions/schema/__tests__/formatSchemaValidation.test.js +0 -174
  402. package/dist/actions/schema/__tests__/formatSchemaValidation.test.js.map +0 -1
  403. package/dist/actions/schema/__tests__/validateAction.test.js +0 -281
  404. package/dist/actions/schema/__tests__/validateAction.test.js.map +0 -1
  405. package/dist/actions/schema/schemaStoreConstants.d.ts +0 -1
  406. package/dist/actions/schema/schemaStoreConstants.js +0 -4
  407. package/dist/actions/schema/schemaStoreConstants.js.map +0 -1
  408. package/dist/actions/schema/utils/schemaActionHelpers.d.ts +0 -1
  409. package/dist/actions/schema/utils/schemaActionHelpers.js +0 -5
  410. package/dist/actions/schema/utils/schemaActionHelpers.js.map +0 -1
  411. package/dist/actions/schema/utils/schemaApiClient.d.ts +0 -6
  412. package/dist/actions/schema/utils/schemaApiClient.js +0 -17
  413. package/dist/actions/schema/utils/schemaApiClient.js.map +0 -1
  414. package/dist/actions/telemetry/__tests__/fetchTelemetryConsent.test.js +0 -27
  415. package/dist/actions/telemetry/__tests__/fetchTelemetryConsent.test.js.map +0 -1
  416. package/dist/actions/users/__tests__/validateEmail.test.js +0 -16
  417. package/dist/actions/users/__tests__/validateEmail.test.js.map +0 -1
  418. package/dist/actions/users/apiVersion.d.ts +0 -6
  419. package/dist/actions/users/apiVersion.js +0 -7
  420. package/dist/actions/users/apiVersion.js.map +0 -1
  421. package/dist/commands/__tests__/blueprints.test.js +0 -54
  422. package/dist/commands/__tests__/blueprints.test.js.map +0 -1
  423. package/dist/commands/__tests__/build.test.js +0 -132
  424. package/dist/commands/__tests__/build.test.js.map +0 -1
  425. package/dist/commands/__tests__/codemod.test.js +0 -271
  426. package/dist/commands/__tests__/codemod.test.js.map +0 -1
  427. package/dist/commands/__tests__/debug.test.js +0 -697
  428. package/dist/commands/__tests__/debug.test.js.map +0 -1
  429. package/dist/commands/__tests__/deploy.test.js +0 -1913
  430. package/dist/commands/__tests__/deploy.test.js.map +0 -1
  431. package/dist/commands/__tests__/dev.test.js +0 -410
  432. package/dist/commands/__tests__/dev.test.js.map +0 -1
  433. package/dist/commands/__tests__/exec.test.js +0 -207
  434. package/dist/commands/__tests__/exec.test.js.map +0 -1
  435. package/dist/commands/__tests__/init/init.authentication.test.js +0 -60
  436. package/dist/commands/__tests__/init/init.authentication.test.js.map +0 -1
  437. package/dist/commands/__tests__/init/init.create-new-project.test.js +0 -196
  438. package/dist/commands/__tests__/init/init.create-new-project.test.js.map +0 -1
  439. package/dist/commands/__tests__/init/init.plan.test.js +0 -220
  440. package/dist/commands/__tests__/init/init.plan.test.js.map +0 -1
  441. package/dist/commands/__tests__/init/init.setup.test.js +0 -279
  442. package/dist/commands/__tests__/init/init.setup.test.js.map +0 -1
  443. package/dist/commands/__tests__/install.test.js +0 -258
  444. package/dist/commands/__tests__/install.test.js.map +0 -1
  445. package/dist/commands/__tests__/learn.test.js +0 -29
  446. package/dist/commands/__tests__/learn.test.js.map +0 -1
  447. package/dist/commands/__tests__/logout.test.js +0 -88
  448. package/dist/commands/__tests__/logout.test.js.map +0 -1
  449. package/dist/commands/__tests__/manage.test.js +0 -105
  450. package/dist/commands/__tests__/manage.test.js.map +0 -1
  451. package/dist/commands/__tests__/migration.test.js +0 -119
  452. package/dist/commands/__tests__/migration.test.js.map +0 -1
  453. package/dist/commands/__tests__/preview.test.js +0 -261
  454. package/dist/commands/__tests__/preview.test.js.map +0 -1
  455. package/dist/commands/__tests__/start.test.js +0 -253
  456. package/dist/commands/__tests__/start.test.js.map +0 -1
  457. package/dist/commands/__tests__/undeploy.test.js +0 -382
  458. package/dist/commands/__tests__/undeploy.test.js.map +0 -1
  459. package/dist/commands/__tests__/versions.test.js +0 -134
  460. package/dist/commands/__tests__/versions.test.js.map +0 -1
  461. package/dist/commands/backup/__tests__/disable.test.js +0 -207
  462. package/dist/commands/backup/__tests__/disable.test.js.map +0 -1
  463. package/dist/commands/backup/__tests__/download.test.js +0 -679
  464. package/dist/commands/backup/__tests__/download.test.js.map +0 -1
  465. package/dist/commands/backup/__tests__/enable.test.js +0 -317
  466. package/dist/commands/backup/__tests__/enable.test.js.map +0 -1
  467. package/dist/commands/backup/__tests__/list.test.js +0 -321
  468. package/dist/commands/backup/__tests__/list.test.js.map +0 -1
  469. package/dist/commands/cors/__tests__/add.test.js +0 -346
  470. package/dist/commands/cors/__tests__/add.test.js.map +0 -1
  471. package/dist/commands/cors/__tests__/delete.test.js +0 -293
  472. package/dist/commands/cors/__tests__/delete.test.js.map +0 -1
  473. package/dist/commands/cors/__tests__/list.test.js +0 -218
  474. package/dist/commands/cors/__tests__/list.test.js.map +0 -1
  475. package/dist/commands/dataset/__tests__/copy.test.js +0 -520
  476. package/dist/commands/dataset/__tests__/copy.test.js.map +0 -1
  477. package/dist/commands/dataset/__tests__/create.test.js +0 -312
  478. package/dist/commands/dataset/__tests__/create.test.js.map +0 -1
  479. package/dist/commands/dataset/__tests__/delete.test.js +0 -224
  480. package/dist/commands/dataset/__tests__/delete.test.js.map +0 -1
  481. package/dist/commands/dataset/__tests__/export.test.js +0 -561
  482. package/dist/commands/dataset/__tests__/export.test.js.map +0 -1
  483. package/dist/commands/dataset/__tests__/import.test.js +0 -53
  484. package/dist/commands/dataset/__tests__/import.test.js.map +0 -1
  485. package/dist/commands/dataset/__tests__/list.test.js +0 -174
  486. package/dist/commands/dataset/__tests__/list.test.js.map +0 -1
  487. package/dist/commands/dataset/alias/__tests__/create.test.js +0 -299
  488. package/dist/commands/dataset/alias/__tests__/create.test.js.map +0 -1
  489. package/dist/commands/dataset/alias/__tests__/delete.test.js +0 -236
  490. package/dist/commands/dataset/alias/__tests__/delete.test.js.map +0 -1
  491. package/dist/commands/dataset/alias/__tests__/link.test.js +0 -336
  492. package/dist/commands/dataset/alias/__tests__/link.test.js.map +0 -1
  493. package/dist/commands/dataset/alias/__tests__/unlink.test.js +0 -298
  494. package/dist/commands/dataset/alias/__tests__/unlink.test.js.map +0 -1
  495. package/dist/commands/dataset/visibility/__tests__/get.test.js +0 -147
  496. package/dist/commands/dataset/visibility/__tests__/get.test.js.map +0 -1
  497. package/dist/commands/dataset/visibility/__tests__/set.test.js +0 -245
  498. package/dist/commands/dataset/visibility/__tests__/set.test.js.map +0 -1
  499. package/dist/commands/docs/__tests__/browse.test.js +0 -29
  500. package/dist/commands/docs/__tests__/browse.test.js.map +0 -1
  501. package/dist/commands/docs/__tests__/read.test.js +0 -78
  502. package/dist/commands/docs/__tests__/read.test.js.map +0 -1
  503. package/dist/commands/docs/__tests__/search.test.js +0 -254
  504. package/dist/commands/docs/__tests__/search.test.js.map +0 -1
  505. package/dist/commands/documents/__tests__/create.test.js +0 -967
  506. package/dist/commands/documents/__tests__/create.test.js.map +0 -1
  507. package/dist/commands/documents/__tests__/delete.test.js +0 -268
  508. package/dist/commands/documents/__tests__/delete.test.js.map +0 -1
  509. package/dist/commands/documents/__tests__/get.test.js +0 -209
  510. package/dist/commands/documents/__tests__/get.test.js.map +0 -1
  511. package/dist/commands/documents/__tests__/query.test.js +0 -405
  512. package/dist/commands/documents/__tests__/query.test.js.map +0 -1
  513. package/dist/commands/documents/__tests__/validate.test.js +0 -226
  514. package/dist/commands/documents/__tests__/validate.test.js.map +0 -1
  515. package/dist/commands/graphql/__tests__/list.test.js +0 -228
  516. package/dist/commands/graphql/__tests__/list.test.js.map +0 -1
  517. package/dist/commands/graphql/__tests__/undeploy.test.js +0 -384
  518. package/dist/commands/graphql/__tests__/undeploy.test.js.map +0 -1
  519. package/dist/commands/hook/__tests__/attempt.test.js +0 -260
  520. package/dist/commands/hook/__tests__/attempt.test.js.map +0 -1
  521. package/dist/commands/hook/__tests__/create.test.js +0 -121
  522. package/dist/commands/hook/__tests__/create.test.js.map +0 -1
  523. package/dist/commands/hook/__tests__/delete.test.js +0 -220
  524. package/dist/commands/hook/__tests__/delete.test.js.map +0 -1
  525. package/dist/commands/hook/__tests__/list.test.js +0 -138
  526. package/dist/commands/hook/__tests__/list.test.js.map +0 -1
  527. package/dist/commands/hook/__tests__/logs.test.js +0 -770
  528. package/dist/commands/hook/__tests__/logs.test.js.map +0 -1
  529. package/dist/commands/manifest/__tests__/extract.test.js +0 -123
  530. package/dist/commands/manifest/__tests__/extract.test.js.map +0 -1
  531. package/dist/commands/mcp/__tests__/configure.test.js +0 -397
  532. package/dist/commands/mcp/__tests__/configure.test.js.map +0 -1
  533. package/dist/commands/media/__tests__/create-aspect.test.js +0 -160
  534. package/dist/commands/media/__tests__/create-aspect.test.js.map +0 -1
  535. package/dist/commands/media/__tests__/delete-aspect.test.js +0 -333
  536. package/dist/commands/media/__tests__/delete-aspect.test.js.map +0 -1
  537. package/dist/commands/media/__tests__/deploy-aspect.test.js +0 -632
  538. package/dist/commands/media/__tests__/deploy-aspect.test.js.map +0 -1
  539. package/dist/commands/media/__tests__/export.test.js +0 -398
  540. package/dist/commands/media/__tests__/export.test.js.map +0 -1
  541. package/dist/commands/media/__tests__/import.test.js +0 -281
  542. package/dist/commands/media/__tests__/import.test.js.map +0 -1
  543. package/dist/commands/openapi/__tests__/get.test.js +0 -149
  544. package/dist/commands/openapi/__tests__/get.test.js.map +0 -1
  545. package/dist/commands/openapi/__tests__/list.test.js +0 -113
  546. package/dist/commands/openapi/__tests__/list.test.js.map +0 -1
  547. package/dist/commands/projects/__tests__/list.test.js +0 -153
  548. package/dist/commands/projects/__tests__/list.test.js.map +0 -1
  549. package/dist/commands/schema/__tests__/delete.test.js +0 -209
  550. package/dist/commands/schema/__tests__/delete.test.js.map +0 -1
  551. package/dist/commands/schema/__tests__/extract.test.js +0 -113
  552. package/dist/commands/schema/__tests__/extract.test.js.map +0 -1
  553. package/dist/commands/schema/__tests__/validate.test.js +0 -104
  554. package/dist/commands/schema/__tests__/validate.test.js.map +0 -1
  555. package/dist/commands/telemetry/__tests__/disable.test.js +0 -145
  556. package/dist/commands/telemetry/__tests__/disable.test.js.map +0 -1
  557. package/dist/commands/telemetry/__tests__/enable.test.js +0 -131
  558. package/dist/commands/telemetry/__tests__/enable.test.js.map +0 -1
  559. package/dist/commands/telemetry/__tests__/status.test.js +0 -153
  560. package/dist/commands/telemetry/__tests__/status.test.js.map +0 -1
  561. package/dist/commands/tokens/__tests__/add.test.js +0 -420
  562. package/dist/commands/tokens/__tests__/add.test.js.map +0 -1
  563. package/dist/commands/tokens/__tests__/delete.test.js +0 -375
  564. package/dist/commands/tokens/__tests__/delete.test.js.map +0 -1
  565. package/dist/commands/tokens/__tests__/list.test.js +0 -368
  566. package/dist/commands/tokens/__tests__/list.test.js.map +0 -1
  567. package/dist/commands/users/__tests__/invite.test.js +0 -341
  568. package/dist/commands/users/__tests__/invite.test.js.map +0 -1
  569. package/dist/commands/users/__tests__/list.test.js +0 -401
  570. package/dist/commands/users/__tests__/list.test.js.map +0 -1
  571. package/dist/hooks/prerun/__tests__/setupTelemetry.test.js +0 -77
  572. package/dist/hooks/prerun/__tests__/setupTelemetry.test.js.map +0 -1
  573. package/dist/services/__tests__/datasetAliases.test.js +0 -131
  574. package/dist/services/__tests__/datasetAliases.test.js.map +0 -1
  575. package/dist/services/__tests__/datasets.test.js +0 -436
  576. package/dist/services/__tests__/datasets.test.js.map +0 -1
  577. package/dist/services/__tests__/graphql.test.js +0 -43
  578. package/dist/services/__tests__/graphql.test.js.map +0 -1
  579. package/dist/services/__tests__/mediaLibraries.test.js +0 -88
  580. package/dist/services/__tests__/mediaLibraries.test.js.map +0 -1
  581. package/dist/services/__tests__/projects.test.js +0 -41
  582. package/dist/services/__tests__/projects.test.js.map +0 -1
  583. package/dist/services/__tests__/userApplications.test.js +0 -113
  584. package/dist/services/__tests__/userApplications.test.js.map +0 -1
  585. package/dist/util/__tests__/appId.test.js +0 -31
  586. package/dist/util/__tests__/appId.test.js.map +0 -1
  587. package/dist/util/__tests__/cliClient.test.js +0 -184
  588. package/dist/util/__tests__/cliClient.test.js.map +0 -1
  589. package/dist/util/__tests__/compareDependencyVersions.test.js +0 -426
  590. package/dist/util/__tests__/compareDependencyVersions.test.js.map +0 -1
  591. package/dist/util/__tests__/extractDocumentsFromNdjsonOrTarball.test.js +0 -74
  592. package/dist/util/__tests__/extractDocumentsFromNdjsonOrTarball.test.js.map +0 -1
  593. package/dist/util/__tests__/findNdjsonEntry.test.js +0 -54
  594. package/dist/util/__tests__/findNdjsonEntry.test.js.map +0 -1
  595. package/dist/util/__tests__/getCliVersion.test.js +0 -28
  596. package/dist/util/__tests__/getCliVersion.test.js.map +0 -1
  597. package/dist/util/__tests__/getLocalPackageVersion.test.js +0 -84
  598. package/dist/util/__tests__/getLocalPackageVersion.test.js.map +0 -1
  599. package/dist/util/__tests__/getWorkspace.test.js +0 -37
  600. package/dist/util/__tests__/getWorkspace.test.js.map +0 -1
  601. package/dist/util/__tests__/readPackageJson.test.js +0 -69
  602. package/dist/util/__tests__/readPackageJson.test.js.map +0 -1
  603. package/dist/util/__tests__/warnAboutMissingAppId.test.js +0 -28
  604. package/dist/util/__tests__/warnAboutMissingAppId.test.js.map +0 -1
  605. package/dist/util/packageManager/__tests__/installPackages.test.js +0 -388
  606. package/dist/util/packageManager/__tests__/installPackages.test.js.map +0 -1
  607. package/dist/util/validation/ __tests__/validateDocuments.test.js +0 -274
  608. package/dist/util/validation/ __tests__/validateDocuments.test.js.map +0 -1
@@ -1,1913 +0,0 @@
1
- import { runCommand } from '@oclif/test';
2
- import { getCliConfig } from '@sanity/cli-core';
3
- import { confirm, input, select } from '@sanity/cli-core/ux';
4
- import { mockApi, testCommand } from '@sanity/cli-test';
5
- import nock from 'nock';
6
- import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
7
- import { testExample } from '~test/helpers/testExample.js';
8
- import { buildApp } from '../../actions/build/buildApp.js';
9
- import { buildStudio } from '../../actions/build/buildStudio.js';
10
- import { checkDir } from '../../actions/deploy/checkDir.js';
11
- import { USER_APPLICATIONS_API_VERSION } from '../../services/userApplications.js';
12
- import { dirIsEmptyOrNonExistent } from '../../util/dirIsEmptyOrNonExistent.js';
13
- import { readModuleVersion } from '../../util/readModuleVersion.js';
14
- import { DeployCommand } from '../deploy.js';
15
- vi.mock('../../../../cli-core/src/config/cli/getCliConfig.js', ()=>({
16
- getCliConfig: vi.fn()
17
- }));
18
- vi.mock('../../util/readModuleVersion.js', ()=>({
19
- readModuleVersion: vi.fn()
20
- }));
21
- vi.mock('../../actions/build/buildApp.js', ()=>({
22
- buildApp: vi.fn()
23
- }));
24
- vi.mock('../../actions/build/buildStudio.js', ()=>({
25
- buildStudio: vi.fn()
26
- }));
27
- vi.mock('../../actions/deploy/checkDir.js', ()=>({
28
- checkDir: vi.fn()
29
- }));
30
- vi.mock('@sanity/cli-core/ux', async ()=>{
31
- const actual = await vi.importActual('@sanity/cli-core/ux');
32
- return {
33
- ...actual,
34
- confirm: vi.fn(),
35
- input: vi.fn(),
36
- select: vi.fn()
37
- };
38
- });
39
- vi.mock('../../util/dirIsEmptyOrNonExistent.js', ()=>({
40
- dirIsEmptyOrNonExistent: vi.fn(()=>true)
41
- }));
42
- vi.mock('tar-fs', ()=>({
43
- pack: vi.fn(()=>{
44
- return {
45
- pipe: vi.fn()
46
- };
47
- })
48
- }));
49
- const mockGetCliConfig = vi.mocked(getCliConfig);
50
- const mockSelect = vi.mocked(select);
51
- const mockConfirm = vi.mocked(confirm);
52
- const mockInput = vi.mocked(input);
53
- const mockCheckDir = vi.mocked(checkDir);
54
- const mockDirIsEmptyOrNonExistent = vi.mocked(dirIsEmptyOrNonExistent);
55
- const mockReadModuleVersion = vi.mocked(readModuleVersion);
56
- const mockBuildStudio = vi.mocked(buildStudio);
57
- const mockBuildApp = vi.mocked(buildApp);
58
- describe('#deploy', ()=>{
59
- beforeEach(async ()=>{
60
- // Set up default mocks
61
- mockReadModuleVersion.mockImplementation(async (sourceDir, moduleName)=>{
62
- if (moduleName === 'sanity') return '3.0.0' // for studio deployments
63
- ;
64
- if (moduleName === '@sanity/sdk-react') return '1.0.0' // for app deployments
65
- ;
66
- return '1.0.0';
67
- });
68
- mockCheckDir.mockResolvedValue();
69
- });
70
- afterEach(()=>{
71
- vi.clearAllMocks();
72
- const pending = nock.pendingMocks();
73
- nock.cleanAll();
74
- expect(pending, 'pending mocks').toEqual([]);
75
- });
76
- test('help text is correct', async ()=>{
77
- const { stdout } = await runCommand('deploy --help');
78
- expect(stdout).toMatchInlineSnapshot(`
79
- "Builds and deploys Sanity Studio or application to Sanity hosting
80
-
81
- USAGE
82
- $ sanity deploy [SOURCEDIR] [--auto-updates] [--build] [--minify]
83
- [--schema-required] [--source-maps] [--verbose] [-y]
84
-
85
- ARGUMENTS
86
- [SOURCEDIR] Source directory
87
-
88
- FLAGS
89
- -y, --yes Unattended mode, answers "yes" to any "yes/no" prompt
90
- and otherwise uses defaults
91
- --[no-]auto-updates Automatically update the studio to the latest version
92
- --[no-]build Don't build the studio prior to deploy, instead
93
- deploying the version currently in \`dist/\`
94
- --[no-]minify Skip minifying built JavaScript (speeds up build,
95
- increases size of bundle)
96
- --schema-required Fail-fast deployment if schema store fails
97
- --source-maps Enable source maps for built bundles (increases size
98
- of bundle)
99
- --verbose Enable verbose logging
100
-
101
- DESCRIPTION
102
- Builds and deploys Sanity Studio or application to Sanity hosting
103
-
104
- EXAMPLES
105
- Build the studio
106
-
107
- $ sanity deploy
108
-
109
- Deploys non-minified build with source maps
110
-
111
- $ sanity deploy --no-minify --source-maps
112
-
113
- Fail fast on schema store fails - for when other services rely on the stored
114
- schema
115
-
116
- $ sanity deploy --schema-required
117
-
118
- "
119
- `);
120
- });
121
- test('shows an error for invalid flags', async ()=>{
122
- const { error } = await testCommand(DeployCommand, [
123
- '--invalid'
124
- ]);
125
- expect(error?.message).toContain('Nonexistent flag: --invalid');
126
- });
127
- test("should prompt to confirm deleting source directory if it's not empty", async ()=>{
128
- const cwd = await testExample('basic-app');
129
- process.cwd = ()=>cwd;
130
- mockConfirm.mockResolvedValue(true);
131
- mockDirIsEmptyOrNonExistent.mockResolvedValue(false);
132
- const appId = 'app-id';
133
- mockGetCliConfig.mockResolvedValue({
134
- app: {
135
- organizationId: 'org-id'
136
- },
137
- deployment: {
138
- appId
139
- }
140
- });
141
- mockApi({
142
- apiVersion: USER_APPLICATIONS_API_VERSION,
143
- query: {
144
- appType: 'coreApp'
145
- },
146
- uri: `/user-applications/${appId}`
147
- }).reply(200, {
148
- appHost: 'existing-host',
149
- createdAt: '2024-01-01T00:00:00Z',
150
- id: appId,
151
- organizationId: 'org-id',
152
- projectId: null,
153
- title: 'Existing App',
154
- type: 'coreApp',
155
- updatedAt: '2024-01-01T00:00:00Z',
156
- urlType: 'internal'
157
- });
158
- mockApi({
159
- apiVersion: USER_APPLICATIONS_API_VERSION,
160
- method: 'post',
161
- query: {
162
- appType: 'coreApp'
163
- },
164
- uri: `/user-applications/${appId}/deployments`
165
- }).reply(200, {
166
- id: 'deployment-id'
167
- });
168
- const { error } = await testCommand(DeployCommand, [
169
- 'build'
170
- ], {
171
- config: {
172
- root: cwd
173
- }
174
- });
175
- expect(error).toBeUndefined();
176
- expect(mockConfirm).toHaveBeenCalledWith({
177
- default: false,
178
- message: '"./build" is not empty, do you want to proceed?'
179
- });
180
- });
181
- test("should cancel the deployment if the user doesn't want to proceed", async ()=>{
182
- const cwd = await testExample('basic-app');
183
- process.cwd = ()=>cwd;
184
- mockConfirm.mockResolvedValue(false);
185
- const appId = 'app-id';
186
- mockGetCliConfig.mockResolvedValue({
187
- app: {
188
- organizationId: 'org-id'
189
- },
190
- deployment: {
191
- appId
192
- }
193
- });
194
- const { error } = await testCommand(DeployCommand, [
195
- 'build'
196
- ], {
197
- config: {
198
- root: cwd
199
- }
200
- });
201
- expect(error?.message).toContain('Cancelled.');
202
- expect(error?.oclif?.exit).toBe(1);
203
- });
204
- describe('app', ()=>{
205
- test('should re-deploy app if it already exists', async ()=>{
206
- const cwd = await testExample('basic-app');
207
- process.cwd = ()=>cwd;
208
- const appId = 'app-id';
209
- mockGetCliConfig.mockResolvedValue({
210
- app: {
211
- organizationId: 'org-id'
212
- },
213
- deployment: {
214
- appId
215
- }
216
- });
217
- mockApi({
218
- apiVersion: USER_APPLICATIONS_API_VERSION,
219
- query: {
220
- appType: 'coreApp'
221
- },
222
- uri: `/user-applications/${appId}`
223
- }).reply(200, {
224
- appHost: 'existing-host',
225
- createdAt: '2024-01-01T00:00:00Z',
226
- id: appId,
227
- organizationId: 'org-id',
228
- projectId: null,
229
- title: 'Existing App',
230
- type: 'coreApp',
231
- updatedAt: '2024-01-01T00:00:00Z',
232
- urlType: 'internal'
233
- });
234
- mockApi({
235
- apiVersion: USER_APPLICATIONS_API_VERSION,
236
- method: 'post',
237
- query: {
238
- appType: 'coreApp'
239
- },
240
- uri: `/user-applications/${appId}/deployments`
241
- }).reply(200, {
242
- id: 'deployment-id'
243
- });
244
- const { error, stderr, stdout } = await testCommand(DeployCommand, [], {
245
- config: {
246
- root: cwd
247
- }
248
- });
249
- expect(error).toBeUndefined();
250
- expect(stderr).toContain('Checking application info');
251
- expect(stderr).toContain('Verifying local content');
252
- expect(stderr).toContain('Deploying...');
253
- expect(stdout).toContain('Success! Application deployed');
254
- });
255
- test('should handle missing @sanity/sdk-react version', async ()=>{
256
- const cwd = await testExample('basic-app');
257
- process.cwd = ()=>cwd;
258
- const appId = 'app-id';
259
- const organizationId = 'org-id';
260
- mockReadModuleVersion.mockResolvedValue(null);
261
- mockGetCliConfig.mockResolvedValue({
262
- app: {
263
- organizationId
264
- },
265
- deployment: {
266
- appId
267
- }
268
- });
269
- const { error } = await testCommand(DeployCommand, [], {
270
- config: {
271
- root: cwd
272
- }
273
- });
274
- expect(error?.message).toContain('Failed to find installed @sanity/sdk-react version');
275
- });
276
- test('should create new user application if none exists', async ()=>{
277
- const cwd = await testExample('basic-app');
278
- process.cwd = ()=>cwd;
279
- const organizationId = 'org-id';
280
- const newAppId = 'new-app-id';
281
- const deploymentId = 'deployment-id';
282
- mockInput.mockResolvedValue('Test App');
283
- mockGetCliConfig.mockResolvedValue({
284
- app: {
285
- organizationId
286
- }
287
- });
288
- mockApi({
289
- apiVersion: USER_APPLICATIONS_API_VERSION,
290
- query: {
291
- appType: 'coreApp',
292
- organizationId
293
- },
294
- uri: `/user-applications`
295
- }).reply(200, []);
296
- mockApi({
297
- apiVersion: USER_APPLICATIONS_API_VERSION,
298
- method: 'post',
299
- query: {
300
- appType: 'coreApp',
301
- organizationId
302
- },
303
- uri: `/user-applications`
304
- }).reply(200, {
305
- appHost: 'generated-host',
306
- createdAt: '2024-01-01T00:00:00Z',
307
- id: newAppId,
308
- organizationId,
309
- projectId: null,
310
- title: 'Test App',
311
- type: 'coreApp',
312
- updatedAt: '2024-01-01T00:00:00Z',
313
- urlType: 'internal'
314
- });
315
- mockApi({
316
- apiVersion: USER_APPLICATIONS_API_VERSION,
317
- method: 'post',
318
- query: {
319
- appType: 'coreApp'
320
- },
321
- uri: `/user-applications/${newAppId}/deployments`
322
- }).reply(200, {
323
- id: deploymentId
324
- });
325
- const { error, stdout } = await testCommand(DeployCommand, [], {
326
- config: {
327
- root: cwd
328
- }
329
- });
330
- expect(error).toBeUndefined();
331
- expect(stdout).toContain('Success! Application deployed');
332
- expect(stdout).toContain(`Add the deployment.appId to your sanity.cli.js or sanity.cli.ts file:`);
333
- expect(stdout).toContain(`deployment: {
334
- appId: '${newAppId}',`);
335
- expect(mockInput).toHaveBeenCalledWith({
336
- message: 'Enter a title for your application:',
337
- validate: expect.any(Function)
338
- });
339
- });
340
- test('should skip build when --no-build flag is used', async ()=>{
341
- const cwd = await testExample('basic-app');
342
- process.cwd = ()=>cwd;
343
- const existingAppId = 'existing-app-id';
344
- const organizationId = 'org-id';
345
- const deploymentId = 'deployment-id';
346
- mockGetCliConfig.mockResolvedValue({
347
- app: {
348
- organizationId
349
- },
350
- deployment: {
351
- appId: existingAppId
352
- }
353
- });
354
- mockApi({
355
- apiVersion: USER_APPLICATIONS_API_VERSION,
356
- query: {
357
- appType: 'coreApp'
358
- },
359
- uri: `/user-applications/${existingAppId}`
360
- }).reply(200, {
361
- appHost: 'existing-host',
362
- createdAt: '2024-01-01T00:00:00Z',
363
- id: existingAppId,
364
- organizationId,
365
- projectId: null,
366
- title: 'Existing App',
367
- type: 'coreApp',
368
- updatedAt: '2024-01-01T00:00:00Z',
369
- urlType: 'internal'
370
- });
371
- mockApi({
372
- apiVersion: USER_APPLICATIONS_API_VERSION,
373
- method: 'post',
374
- query: {
375
- appType: 'coreApp'
376
- },
377
- uri: `/user-applications/${existingAppId}/deployments`
378
- }).reply(200, {
379
- id: deploymentId
380
- });
381
- const { error, stdout } = await testCommand(DeployCommand, [
382
- '--no-build'
383
- ], {
384
- config: {
385
- root: cwd
386
- }
387
- });
388
- expect(error).toBeUndefined();
389
- expect(stdout).toContain('Success! Application deployed');
390
- expect(mockBuildApp).not.toHaveBeenCalled();
391
- });
392
- test('should handle directory check errors', async ()=>{
393
- const cwd = await testExample('basic-app');
394
- process.cwd = ()=>cwd;
395
- const existingAppId = 'existing-app-id';
396
- const organizationId = 'org-id';
397
- mockCheckDir.mockRejectedValue(new Error('Directory check failed'));
398
- mockGetCliConfig.mockResolvedValue({
399
- app: {
400
- organizationId
401
- },
402
- deployment: {
403
- appId: existingAppId
404
- }
405
- });
406
- mockApi({
407
- apiVersion: USER_APPLICATIONS_API_VERSION,
408
- query: {
409
- appType: 'coreApp'
410
- },
411
- uri: `/user-applications/${existingAppId}`
412
- }).reply(200, {
413
- appHost: 'existing-host',
414
- createdAt: '2024-01-01T00:00:00Z',
415
- id: existingAppId,
416
- organizationId,
417
- projectId: null,
418
- title: 'Existing App',
419
- type: 'coreApp',
420
- updatedAt: '2024-01-01T00:00:00Z',
421
- urlType: 'internal'
422
- });
423
- const { error } = await testCommand(DeployCommand, [
424
- '--no-build'
425
- ], {
426
- config: {
427
- root: cwd
428
- }
429
- });
430
- expect(error?.message).toContain('Error checking directory');
431
- });
432
- test('should error when fetching user applications if user doesn’t have org access', async ()=>{
433
- const cwd = await testExample('basic-app');
434
- process.cwd = ()=>cwd;
435
- const appId = 'some-app-id';
436
- const organizationId = 'org-without-access';
437
- mockGetCliConfig.mockResolvedValue({
438
- app: {
439
- organizationId
440
- },
441
- deployment: {
442
- appId
443
- }
444
- });
445
- // Simulate API returning 403 Forbidden for the given org
446
- mockApi({
447
- apiVersion: USER_APPLICATIONS_API_VERSION,
448
- query: {
449
- appType: 'coreApp'
450
- },
451
- uri: `/user-applications/${appId}`
452
- }).reply(403, {
453
- error: 'Forbidden'
454
- });
455
- const { error } = await testCommand(DeployCommand, [
456
- '--no-build'
457
- ], {
458
- config: {
459
- root: cwd
460
- }
461
- });
462
- expect(error?.message).toContain(`You don’t have permission to view applications for the configured organization ID ("${organizationId}")`);
463
- });
464
- test('should handle user-applications endpoint errors', async ()=>{
465
- const cwd = await testExample('basic-app');
466
- process.cwd = ()=>cwd;
467
- const existingAppId = 'existing-app-id';
468
- const organizationId = 'org-id';
469
- mockGetCliConfig.mockResolvedValue({
470
- app: {
471
- organizationId
472
- },
473
- deployment: {
474
- appId: existingAppId
475
- }
476
- });
477
- mockApi({
478
- apiVersion: USER_APPLICATIONS_API_VERSION,
479
- query: {
480
- appType: 'coreApp'
481
- },
482
- uri: `/user-applications/${existingAppId}`
483
- }).reply(500, {
484
- error: 'Internal server error'
485
- });
486
- const { error } = await testCommand(DeployCommand, [
487
- '--no-build'
488
- ], {
489
- config: {
490
- root: cwd
491
- }
492
- });
493
- expect(error?.message).toContain('Error deploying application');
494
- });
495
- test('should handle deployment API errors', async ()=>{
496
- const cwd = await testExample('basic-app');
497
- process.cwd = ()=>cwd;
498
- const existingAppId = 'existing-app-id';
499
- const organizationId = 'org-id';
500
- mockGetCliConfig.mockResolvedValue({
501
- app: {
502
- organizationId
503
- },
504
- deployment: {
505
- appId: existingAppId
506
- }
507
- });
508
- mockApi({
509
- apiVersion: USER_APPLICATIONS_API_VERSION,
510
- query: {
511
- appType: 'coreApp'
512
- },
513
- uri: `/user-applications/${existingAppId}`
514
- }).reply(200, {
515
- appHost: 'existing-host',
516
- createdAt: '2024-01-01T00:00:00Z',
517
- id: existingAppId,
518
- organizationId,
519
- projectId: null,
520
- title: 'Existing App',
521
- type: 'coreApp',
522
- updatedAt: '2024-01-01T00:00:00Z',
523
- urlType: 'internal'
524
- });
525
- mockApi({
526
- apiVersion: USER_APPLICATIONS_API_VERSION,
527
- method: 'post',
528
- query: {
529
- appType: 'coreApp'
530
- },
531
- uri: `/user-applications/${existingAppId}/deployments`
532
- }).reply(500, {
533
- error: 'Internal server error'
534
- });
535
- const { error } = await testCommand(DeployCommand, [
536
- '--no-build'
537
- ], {
538
- config: {
539
- root: cwd
540
- }
541
- });
542
- expect(error?.message).toContain('Error deploying application');
543
- });
544
- test('should show an error if deployment.appId is configured but the application does not exist', async ()=>{
545
- const cwd = await testExample('basic-app');
546
- process.cwd = ()=>cwd;
547
- const nonExistentAppId = 'non-existent-app-id';
548
- const organizationId = 'org-id';
549
- mockGetCliConfig.mockResolvedValue({
550
- app: {
551
- organizationId
552
- },
553
- deployment: {
554
- appId: nonExistentAppId
555
- }
556
- });
557
- // Simulate API returning no user application for the given app.id
558
- mockApi({
559
- apiVersion: USER_APPLICATIONS_API_VERSION,
560
- query: {
561
- appType: 'coreApp'
562
- },
563
- uri: `/user-applications/${nonExistentAppId}`
564
- }).reply(404, {
565
- error: 'Not found'
566
- });
567
- const { error } = await testCommand(DeployCommand, [
568
- '--no-build'
569
- ], {
570
- config: {
571
- root: cwd
572
- }
573
- });
574
- expect(error?.message).toContain('The `appId` provided in your configuration’s `deployment` object cannot be found in your organization');
575
- });
576
- test('should show an error if deployment.appId and app.id (deprecated) are both in use', async ()=>{
577
- const cwd = await testExample('basic-app');
578
- process.cwd = ()=>cwd;
579
- const appId = 'app-id';
580
- const organizationId = 'org-id';
581
- mockGetCliConfig.mockResolvedValue({
582
- app: {
583
- id: appId,
584
- organizationId
585
- },
586
- deployment: {
587
- appId: appId
588
- }
589
- });
590
- const { error } = await testCommand(DeployCommand, [
591
- '--no-build'
592
- ], {
593
- config: {
594
- root: cwd
595
- }
596
- });
597
- expect(error?.message).toContain('Found both app.id (deprecated) and deployment.appId in your application configuration.\n\nPlease remove app.id from your sanity.cli.js or sanity.cli.ts file.');
598
- });
599
- test('should show a warning if app.id (deprecated) is used', async ()=>{
600
- const cwd = await testExample('basic-app');
601
- process.cwd = ()=>cwd;
602
- const appId = 'app-id';
603
- const organizationId = 'org-id';
604
- mockGetCliConfig.mockResolvedValue({
605
- app: {
606
- id: appId,
607
- organizationId
608
- }
609
- });
610
- const { stderr } = await testCommand(DeployCommand, [
611
- '--no-build'
612
- ], {
613
- config: {
614
- root: cwd
615
- }
616
- });
617
- expect(stderr).toContain('The `app.id` config has moved to `deployment.appId`.');
618
- });
619
- test('should handle app creation with retry when host is taken', async ()=>{
620
- const cwd = await testExample('basic-app');
621
- process.cwd = ()=>cwd;
622
- const organizationId = 'org-id';
623
- const newAppId = 'new-app-id';
624
- const deploymentId = 'deployment-id';
625
- mockInput.mockResolvedValue('Test App');
626
- mockGetCliConfig.mockResolvedValue({
627
- app: {
628
- organizationId
629
- }
630
- });
631
- mockApi({
632
- apiVersion: USER_APPLICATIONS_API_VERSION,
633
- query: {
634
- appType: 'coreApp',
635
- organizationId
636
- },
637
- uri: `/user-applications`
638
- }).reply(200, []);
639
- mockApi({
640
- apiVersion: USER_APPLICATIONS_API_VERSION,
641
- method: 'post',
642
- query: {
643
- appType: 'coreApp',
644
- organizationId
645
- },
646
- uri: `/user-applications`
647
- }).once().reply(409, {
648
- message: 'App host already taken',
649
- statusCode: 409
650
- });
651
- mockApi({
652
- apiVersion: USER_APPLICATIONS_API_VERSION,
653
- method: 'post',
654
- query: {
655
- appType: 'coreApp',
656
- organizationId
657
- },
658
- uri: `/user-applications`
659
- }).once().reply(200, {
660
- appHost: 'generated-host-2',
661
- createdAt: '2024-01-01T00:00:00Z',
662
- id: newAppId,
663
- organizationId,
664
- projectId: null,
665
- title: 'Test App',
666
- type: 'coreApp',
667
- updatedAt: '2024-01-01T00:00:00Z',
668
- urlType: 'internal'
669
- });
670
- mockApi({
671
- apiVersion: USER_APPLICATIONS_API_VERSION,
672
- method: 'post',
673
- query: {
674
- appType: 'coreApp'
675
- },
676
- uri: `/user-applications/${newAppId}/deployments`
677
- }).reply(200, {
678
- id: deploymentId
679
- });
680
- const { error, stdout } = await testCommand(DeployCommand, [], {
681
- config: {
682
- root: cwd
683
- }
684
- });
685
- expect(error).toBeUndefined();
686
- expect(stdout).toContain('Success! Application deployed');
687
- });
688
- test('should handle app creation failure with non-retryable error', async ()=>{
689
- const cwd = await testExample('basic-app');
690
- process.cwd = ()=>cwd;
691
- const organizationId = 'org-id';
692
- mockInput.mockResolvedValue('Test App');
693
- mockGetCliConfig.mockResolvedValue({
694
- app: {
695
- organizationId
696
- }
697
- });
698
- mockApi({
699
- apiVersion: USER_APPLICATIONS_API_VERSION,
700
- query: {
701
- appType: 'coreApp',
702
- organizationId
703
- },
704
- uri: `/user-applications`
705
- }).reply(200, []);
706
- mockApi({
707
- apiVersion: USER_APPLICATIONS_API_VERSION,
708
- method: 'post',
709
- query: {
710
- appType: 'coreApp',
711
- organizationId
712
- },
713
- uri: `/user-applications`
714
- }).reply(500, {
715
- message: 'Internal server error',
716
- statusCode: 500
717
- });
718
- const { error } = await testCommand(DeployCommand, [], {
719
- config: {
720
- root: cwd
721
- }
722
- });
723
- expect(error?.message).toContain('Error deploying application');
724
- });
725
- test('should handle findUserApplicationForApp API errors', async ()=>{
726
- const cwd = await testExample('basic-app');
727
- process.cwd = ()=>cwd;
728
- const existingAppId = 'existing-app-id';
729
- const organizationId = 'org-id';
730
- mockGetCliConfig.mockResolvedValue({
731
- app: {
732
- organizationId
733
- },
734
- deployment: {
735
- appId: existingAppId
736
- }
737
- });
738
- mockApi({
739
- apiVersion: USER_APPLICATIONS_API_VERSION,
740
- query: {
741
- appType: 'coreApp'
742
- },
743
- uri: `/user-applications/${existingAppId}`
744
- }).reply(500, {
745
- error: 'Internal server error'
746
- });
747
- const { error } = await testCommand(DeployCommand, [
748
- '--no-build'
749
- ], {
750
- config: {
751
- root: cwd
752
- }
753
- });
754
- expect(error?.message).toContain('Error deploying application');
755
- expect(error?.oclif?.exit).toBe(1);
756
- });
757
- test('should test input validation for app title', async ()=>{
758
- const cwd = await testExample('basic-app');
759
- process.cwd = ()=>cwd;
760
- const organizationId = 'org-id';
761
- const newAppId = 'new-app-id';
762
- const deploymentId = 'deployment-id';
763
- mockInput.mockResolvedValue('Valid App Title');
764
- mockGetCliConfig.mockResolvedValue({
765
- app: {
766
- organizationId
767
- }
768
- });
769
- mockApi({
770
- apiVersion: USER_APPLICATIONS_API_VERSION,
771
- query: {
772
- appType: 'coreApp',
773
- organizationId
774
- },
775
- uri: `/user-applications`
776
- }).reply(200, []);
777
- mockApi({
778
- apiVersion: USER_APPLICATIONS_API_VERSION,
779
- method: 'post',
780
- query: {
781
- appType: 'coreApp',
782
- organizationId
783
- },
784
- uri: `/user-applications`
785
- }).reply(200, {
786
- appHost: 'generated-host',
787
- createdAt: '2024-01-01T00:00:00Z',
788
- id: newAppId,
789
- organizationId,
790
- projectId: null,
791
- title: 'Valid App Title',
792
- type: 'coreApp',
793
- updatedAt: '2024-01-01T00:00:00Z',
794
- urlType: 'internal'
795
- });
796
- mockApi({
797
- apiVersion: USER_APPLICATIONS_API_VERSION,
798
- method: 'post',
799
- query: {
800
- appType: 'coreApp'
801
- },
802
- uri: `/user-applications/${newAppId}/deployments`
803
- }).reply(200, {
804
- id: deploymentId
805
- });
806
- const { error } = await testCommand(DeployCommand, [], {
807
- config: {
808
- root: cwd
809
- }
810
- });
811
- expect(error).toBeUndefined();
812
- expect(mockInput).toHaveBeenCalledWith({
813
- message: 'Enter a title for your application:',
814
- validate: expect.any(Function)
815
- });
816
- });
817
- test('should allow selecting from list of apps', async ()=>{
818
- const cwd = await testExample('basic-app');
819
- process.cwd = ()=>cwd;
820
- const organizationId = 'org-id';
821
- const existingAppId1 = 'existing-app-id-1';
822
- const existingAppId2 = 'existing-app-id-2';
823
- const deploymentId = 'deployment-id';
824
- mockGetCliConfig.mockResolvedValue({
825
- app: {
826
- organizationId
827
- }
828
- });
829
- mockApi({
830
- apiVersion: USER_APPLICATIONS_API_VERSION,
831
- query: {
832
- appType: 'coreApp',
833
- organizationId
834
- },
835
- uri: `/user-applications`
836
- }).reply(200, [
837
- {
838
- appHost: 'existing-host-1',
839
- createdAt: '2024-01-01T00:00:00Z',
840
- id: existingAppId1,
841
- organizationId,
842
- projectId: null,
843
- title: 'Existing App 1',
844
- type: 'coreApp',
845
- updatedAt: '2024-01-01T00:00:00Z',
846
- urlType: 'internal'
847
- },
848
- {
849
- appHost: 'existing-host-2',
850
- createdAt: '2024-01-01T00:00:00Z',
851
- id: existingAppId2,
852
- organizationId,
853
- projectId: null,
854
- title: 'Existing App 2',
855
- type: 'coreApp',
856
- updatedAt: '2024-01-01T00:00:00Z',
857
- urlType: 'internal'
858
- }
859
- ]);
860
- mockApi({
861
- apiVersion: USER_APPLICATIONS_API_VERSION,
862
- method: 'post',
863
- query: {
864
- appType: 'coreApp'
865
- },
866
- uri: `/user-applications/${existingAppId2}/deployments`
867
- }).reply(200, {
868
- id: deploymentId
869
- });
870
- mockSelect.mockResolvedValue('existing-host-2');
871
- const { error, stdout } = await testCommand(DeployCommand, [], {
872
- config: {
873
- root: cwd
874
- }
875
- });
876
- expect(error).toBeUndefined();
877
- expect(stdout).toContain('Success! Application deployed');
878
- expect(stdout).toContain(`Add the deployment.appId to your sanity.cli.js or sanity.cli.ts file:`);
879
- expect(stdout).toContain(`deployment: {
880
- appId: '${existingAppId2}',`);
881
- });
882
- test('should allow creating a new app by selecting from list of apps', async ()=>{
883
- const cwd = await testExample('basic-app');
884
- process.cwd = ()=>cwd;
885
- const organizationId = 'org-id';
886
- const existingAppId1 = 'existing-app-id-1';
887
- const existingAppId2 = 'existing-app-id-2';
888
- const newAppId = 'new-app-id';
889
- const deploymentId = 'deployment-id';
890
- mockGetCliConfig.mockResolvedValue({
891
- app: {
892
- organizationId
893
- }
894
- });
895
- mockApi({
896
- apiVersion: USER_APPLICATIONS_API_VERSION,
897
- query: {
898
- appType: 'coreApp',
899
- organizationId
900
- },
901
- uri: `/user-applications`
902
- }).reply(200, [
903
- {
904
- appHost: 'existing-host-1',
905
- createdAt: '2024-01-01T00:00:00Z',
906
- id: existingAppId1,
907
- organizationId,
908
- projectId: null,
909
- title: 'Existing App 1',
910
- type: 'coreApp',
911
- updatedAt: '2024-01-01T00:00:00Z',
912
- urlType: 'internal'
913
- },
914
- {
915
- appHost: 'existing-host-2',
916
- createdAt: '2024-01-01T00:00:00Z',
917
- id: existingAppId2,
918
- organizationId,
919
- projectId: null,
920
- title: 'Existing App 2',
921
- type: 'coreApp',
922
- updatedAt: '2024-01-01T00:00:00Z',
923
- urlType: 'internal'
924
- }
925
- ]);
926
- mockApi({
927
- apiVersion: USER_APPLICATIONS_API_VERSION,
928
- method: 'post',
929
- query: {
930
- appType: 'coreApp',
931
- organizationId
932
- },
933
- uri: `/user-applications`
934
- }).reply(200, {
935
- appHost: 'generated-host',
936
- createdAt: '2024-01-01T00:00:00Z',
937
- id: newAppId,
938
- organizationId,
939
- projectId: null,
940
- title: 'Test App',
941
- type: 'coreApp',
942
- updatedAt: '2024-01-01T00:00:00Z',
943
- urlType: 'internal'
944
- });
945
- mockApi({
946
- apiVersion: USER_APPLICATIONS_API_VERSION,
947
- method: 'post',
948
- query: {
949
- appType: 'coreApp'
950
- },
951
- uri: `/user-applications/${newAppId}/deployments`
952
- }).reply(200, {
953
- id: deploymentId
954
- });
955
- mockSelect.mockResolvedValue('NEW_APP');
956
- const { error, stdout } = await testCommand(DeployCommand, [], {
957
- config: {
958
- root: cwd
959
- }
960
- });
961
- expect(error).toBeUndefined();
962
- expect(stdout).toContain('Success! Application deployed');
963
- expect(stdout).toContain(`Add the deployment.appId to your sanity.cli.js or sanity.cli.ts file:`);
964
- expect(stdout).toContain(`deployment: {
965
- appId: '${newAppId}',`);
966
- });
967
- test('should throw an error if organizationId is not set', async ()=>{
968
- const cwd = await testExample('basic-app');
969
- process.cwd = ()=>cwd;
970
- mockGetCliConfig.mockResolvedValue({
971
- app: {
972
- organizationId: undefined
973
- }
974
- });
975
- const { error } = await testCommand(DeployCommand, [], {
976
- config: {
977
- root: cwd
978
- }
979
- });
980
- expect(error?.message).toContain('sanity.cli.ts does not contain an organization identifier ("app.organizationId"), which is required for the Sanity CLI to communicate with the Sanity API');
981
- expect(error?.oclif?.exit).toBe(1);
982
- });
983
- });
984
- describe('studio', ()=>{
985
- test('should handle missing sanity version', async ()=>{
986
- const cwd = await testExample('basic-studio');
987
- process.cwd = ()=>cwd;
988
- mockReadModuleVersion.mockResolvedValue(null);
989
- mockGetCliConfig.mockResolvedValue({
990
- studioHost: 'existing-studio'
991
- });
992
- const { error } = await testCommand(DeployCommand, [], {
993
- config: {
994
- root: cwd
995
- }
996
- });
997
- expect(error?.message).toContain('Failed to find installed sanity version');
998
- });
999
- test('should handle directory check errors', async ()=>{
1000
- const cwd = await testExample('basic-app');
1001
- process.cwd = ()=>cwd;
1002
- const projectId = 'test-project-id';
1003
- const studioHost = 'existing-studio';
1004
- const studioAppId = 'studio-app-id';
1005
- mockCheckDir.mockRejectedValue(new Error('Directory check failed'));
1006
- mockGetCliConfig.mockResolvedValue({
1007
- api: {
1008
- projectId
1009
- },
1010
- studioHost
1011
- });
1012
- mockApi({
1013
- apiVersion: USER_APPLICATIONS_API_VERSION,
1014
- query: {
1015
- appHost: studioHost,
1016
- appType: 'studio'
1017
- },
1018
- uri: `/projects/${projectId}/user-applications`
1019
- }).reply(200, {
1020
- appHost: studioHost,
1021
- createdAt: '2024-01-01T00:00:00Z',
1022
- id: studioAppId,
1023
- projectId,
1024
- title: 'Existing Studio',
1025
- type: 'studio',
1026
- updatedAt: '2024-01-01T00:00:00Z',
1027
- urlType: 'internal'
1028
- });
1029
- const { error } = await testCommand(DeployCommand, [
1030
- '--no-build'
1031
- ], {
1032
- config: {
1033
- root: cwd
1034
- }
1035
- });
1036
- expect(error?.message).toContain('Error checking directory');
1037
- });
1038
- test('should re-deploy studio if it already exists', async ()=>{
1039
- const cwd = await testExample('basic-studio');
1040
- process.cwd = ()=>cwd;
1041
- const projectId = 'test-project-id';
1042
- const studioHost = 'existing-studio';
1043
- const studioAppId = 'studio-app-id';
1044
- const deploymentId = 'deployment-id';
1045
- mockGetCliConfig.mockResolvedValue({
1046
- api: {
1047
- projectId
1048
- },
1049
- studioHost
1050
- });
1051
- mockApi({
1052
- apiVersion: USER_APPLICATIONS_API_VERSION,
1053
- query: {
1054
- appHost: studioHost,
1055
- appType: 'studio'
1056
- },
1057
- uri: `/projects/${projectId}/user-applications`
1058
- }).reply(200, {
1059
- appHost: studioHost,
1060
- createdAt: '2024-01-01T00:00:00Z',
1061
- id: studioAppId,
1062
- projectId,
1063
- title: 'Existing Studio',
1064
- type: 'studio',
1065
- updatedAt: '2024-01-01T00:00:00Z',
1066
- urlType: 'internal'
1067
- });
1068
- mockApi({
1069
- apiVersion: USER_APPLICATIONS_API_VERSION,
1070
- method: 'post',
1071
- query: {
1072
- appType: 'studio'
1073
- },
1074
- uri: `/projects/${projectId}/user-applications/${studioAppId}/deployments`
1075
- }).reply(200, {
1076
- id: deploymentId
1077
- });
1078
- const { error, stderr, stdout } = await testCommand(DeployCommand, [], {
1079
- config: {
1080
- root: cwd
1081
- }
1082
- });
1083
- expect(error).toBeUndefined();
1084
- expect(stderr).toContain('Checking project info');
1085
- expect(stderr).toContain('Verifying local content');
1086
- expect(stderr).toContain('Deploying to sanity.studio');
1087
- expect(stdout).toContain('Success! Studio deployed');
1088
- });
1089
- test('should create new studio hostname when studioHost is provided but does not exist', async ()=>{
1090
- const cwd = await testExample('basic-studio');
1091
- process.cwd = ()=>cwd;
1092
- mockGetCliConfig.mockResolvedValue({
1093
- api: {
1094
- projectId: 'test-project-id'
1095
- },
1096
- studioHost: 'new-studio-host'
1097
- });
1098
- mockApi({
1099
- apiVersion: USER_APPLICATIONS_API_VERSION,
1100
- query: {
1101
- appHost: 'new-studio-host',
1102
- appType: 'studio'
1103
- },
1104
- uri: `/projects/test-project-id/user-applications`
1105
- }).reply(404, {
1106
- message: 'Not found'
1107
- });
1108
- mockApi({
1109
- apiVersion: USER_APPLICATIONS_API_VERSION,
1110
- method: 'post',
1111
- query: {
1112
- appType: 'studio'
1113
- },
1114
- uri: `/projects/test-project-id/user-applications`
1115
- }).reply(200, {
1116
- appHost: 'new-studio-host',
1117
- createdAt: '2024-01-01T00:00:00Z',
1118
- id: 'new-studio-app-id',
1119
- projectId: 'test-project-id',
1120
- title: 'New Studio',
1121
- type: 'studio',
1122
- updatedAt: '2024-01-01T00:00:00Z',
1123
- urlType: 'internal'
1124
- });
1125
- mockApi({
1126
- apiVersion: USER_APPLICATIONS_API_VERSION,
1127
- method: 'post',
1128
- query: {
1129
- appType: 'studio'
1130
- },
1131
- uri: `/projects/test-project-id/user-applications/new-studio-app-id/deployments`
1132
- }).reply(200, {
1133
- id: 'deployment-id'
1134
- });
1135
- const { error, stdout } = await testCommand(DeployCommand, [], {
1136
- config: {
1137
- root: cwd
1138
- }
1139
- });
1140
- expect(error).toBeUndefined();
1141
- expect(stdout).toContain('Success! Studio deployed');
1142
- expect(stdout).toContain('Your project has not been assigned a studio hostname');
1143
- expect(stdout).toContain('Creating https://new-studio-host.sanity.studio');
1144
- });
1145
- test('should handle studio hostname creation failure when name is taken', async ()=>{
1146
- const cwd = await testExample('basic-studio');
1147
- process.cwd = ()=>cwd;
1148
- const projectId = 'test-project-id';
1149
- const studioHost = 'taken-studio-host';
1150
- mockGetCliConfig.mockResolvedValue({
1151
- api: {
1152
- projectId
1153
- },
1154
- studioHost
1155
- });
1156
- mockApi({
1157
- apiVersion: USER_APPLICATIONS_API_VERSION,
1158
- query: {
1159
- appHost: studioHost,
1160
- appType: 'studio'
1161
- },
1162
- uri: `/projects/${projectId}/user-applications`
1163
- }).reply(404, {
1164
- message: 'Not found'
1165
- });
1166
- mockApi({
1167
- apiVersion: USER_APPLICATIONS_API_VERSION,
1168
- method: 'post',
1169
- query: {
1170
- appType: 'studio'
1171
- },
1172
- uri: `/projects/${projectId}/user-applications`
1173
- }).reply(409, {
1174
- message: 'Studio hostname already taken',
1175
- statusCode: 409
1176
- });
1177
- const { error } = await testCommand(DeployCommand, [], {
1178
- config: {
1179
- root: cwd
1180
- }
1181
- });
1182
- expect(error?.message).toContain('Studio hostname already taken');
1183
- expect(error?.oclif?.exit).toBe(1);
1184
- });
1185
- test('should allow selecting from existing studio hostnames', async ()=>{
1186
- const cwd = await testExample('basic-studio');
1187
- process.cwd = ()=>cwd;
1188
- const projectId = 'test-project-id';
1189
- mockGetCliConfig.mockResolvedValue({
1190
- api: {
1191
- projectId
1192
- }
1193
- });
1194
- const studioOneId = 'studio-one-id';
1195
- const studioTwoId = 'studio-two-id';
1196
- const deploymentId = 'deployment-id';
1197
- mockApi({
1198
- apiVersion: USER_APPLICATIONS_API_VERSION,
1199
- query: {
1200
- appType: 'studio'
1201
- },
1202
- uri: `/projects/${projectId}/user-applications`
1203
- }).reply(200, [
1204
- {
1205
- appHost: 'studio-one',
1206
- createdAt: '2024-01-01T00:00:00Z',
1207
- id: studioOneId,
1208
- projectId,
1209
- title: 'Studio One',
1210
- type: 'studio',
1211
- updatedAt: '2024-01-01T00:00:00Z',
1212
- urlType: 'internal'
1213
- },
1214
- {
1215
- appHost: 'studio-two',
1216
- createdAt: '2024-01-01T00:00:00Z',
1217
- id: studioTwoId,
1218
- projectId,
1219
- title: 'Studio Two',
1220
- type: 'studio',
1221
- updatedAt: '2024-01-01T00:00:00Z',
1222
- urlType: 'internal'
1223
- }
1224
- ]);
1225
- mockApi({
1226
- apiVersion: USER_APPLICATIONS_API_VERSION,
1227
- method: 'post',
1228
- query: {
1229
- appType: 'studio'
1230
- },
1231
- uri: `/projects/${projectId}/user-applications/${studioTwoId}/deployments`
1232
- }).reply(200, {
1233
- id: deploymentId,
1234
- location: 'https://studio-two.sanity.studio'
1235
- });
1236
- mockSelect.mockResolvedValue('studio-two');
1237
- const { error, stdout } = await testCommand(DeployCommand, [], {
1238
- config: {
1239
- root: cwd
1240
- }
1241
- });
1242
- expect(error).toBeUndefined();
1243
- expect(stdout).toContain('Success! Studio deployed to https://studio-two.sanity.studio');
1244
- expect(mockSelect).toHaveBeenCalledWith({
1245
- choices: [
1246
- {
1247
- name: 'Create new studio hostname',
1248
- value: 'NEW_STUDIO'
1249
- },
1250
- expect.any(Object),
1251
- {
1252
- name: 'Studio One',
1253
- value: 'studio-one'
1254
- },
1255
- {
1256
- name: 'Studio Two',
1257
- value: 'studio-two'
1258
- }
1259
- ],
1260
- message: 'Select existing studio hostname, or create a new one'
1261
- });
1262
- });
1263
- test('should allow creating new studio hostname from selection menu', async ()=>{
1264
- const cwd = await testExample('basic-studio');
1265
- process.cwd = ()=>cwd;
1266
- const projectId = 'test-project-id';
1267
- const existingStudioId = 'existing-studio-id';
1268
- const newStudioFromMenuId = 'new-studio-from-menu-id';
1269
- const deploymentId = 'deployment-id';
1270
- mockGetCliConfig.mockResolvedValue({
1271
- api: {
1272
- projectId
1273
- }
1274
- });
1275
- mockApi({
1276
- apiVersion: USER_APPLICATIONS_API_VERSION,
1277
- query: {
1278
- appType: 'studio'
1279
- },
1280
- uri: `/projects/${projectId}/user-applications`
1281
- }).once().reply(200, [
1282
- {
1283
- appHost: 'existing-studio',
1284
- createdAt: '2024-01-01T00:00:00Z',
1285
- id: existingStudioId,
1286
- projectId,
1287
- title: 'Existing Studio',
1288
- type: 'studio',
1289
- updatedAt: '2024-01-01T00:00:00Z',
1290
- urlType: 'internal'
1291
- }
1292
- ]);
1293
- mockApi({
1294
- apiVersion: USER_APPLICATIONS_API_VERSION,
1295
- method: 'post',
1296
- query: {
1297
- appType: 'studio'
1298
- },
1299
- uri: `/projects/${projectId}/user-applications`
1300
- }).reply(200, {
1301
- appHost: 'new-studio-from-menu',
1302
- createdAt: '2024-01-01T00:00:00Z',
1303
- id: newStudioFromMenuId,
1304
- projectId,
1305
- title: 'New Studio From Menu',
1306
- type: 'studio',
1307
- updatedAt: '2024-01-01T00:00:00Z',
1308
- urlType: 'internal'
1309
- });
1310
- mockApi({
1311
- apiVersion: USER_APPLICATIONS_API_VERSION,
1312
- method: 'post',
1313
- query: {
1314
- appType: 'studio'
1315
- },
1316
- uri: `/projects/${projectId}/user-applications/${newStudioFromMenuId}/deployments`
1317
- }).reply(200, {
1318
- id: deploymentId
1319
- });
1320
- mockSelect.mockResolvedValue('NEW_STUDIO');
1321
- mockInput.mockImplementation(({ validate })=>{
1322
- const promise = (async ()=>{
1323
- if (validate) {
1324
- await validate('new-studio-from-menu');
1325
- }
1326
- return 'new-studio-from-menu';
1327
- })();
1328
- promise.cancel = ()=>{};
1329
- return promise;
1330
- });
1331
- const { error, stdout } = await testCommand(DeployCommand, [], {
1332
- config: {
1333
- root: cwd
1334
- }
1335
- });
1336
- expect(error).toBeUndefined();
1337
- expect(stdout).toContain('Success! Studio deployed');
1338
- expect(mockInput).toHaveBeenCalledWith({
1339
- message: 'Studio hostname (<value>.sanity.studio):',
1340
- validate: expect.any(Function)
1341
- });
1342
- });
1343
- test('should handle input validation with retry for studio hostname creation', async ()=>{
1344
- const cwd = await testExample('basic-studio');
1345
- process.cwd = ()=>cwd;
1346
- const projectId = 'test-project-id';
1347
- const validStudioId = 'valid-studio-id';
1348
- const deploymentId = 'deployment-id';
1349
- mockInput.mockImplementation(({ validate })=>{
1350
- const promise = (async ()=>{
1351
- if (validate) {
1352
- // First attempt with a name that will be taken (triggers 409)
1353
- let result = await validate('taken-name');
1354
- if (result !== true) {
1355
- // Name was taken, try again with a valid name (triggers 200)
1356
- result = await validate('valid-name');
1357
- }
1358
- }
1359
- return 'valid-name';
1360
- })();
1361
- promise.cancel = ()=>{};
1362
- return promise;
1363
- });
1364
- mockGetCliConfig.mockResolvedValue({
1365
- api: {
1366
- projectId
1367
- }
1368
- });
1369
- mockApi({
1370
- apiVersion: USER_APPLICATIONS_API_VERSION,
1371
- query: {
1372
- appType: 'studio'
1373
- },
1374
- uri: `/projects/${projectId}/user-applications`
1375
- }).reply(200, []);
1376
- // First API call fails (hostname taken)
1377
- mockApi({
1378
- apiVersion: USER_APPLICATIONS_API_VERSION,
1379
- method: 'post',
1380
- query: {
1381
- appType: 'studio'
1382
- },
1383
- uri: `/projects/${projectId}/user-applications`
1384
- }).once().reply(409, {
1385
- message: 'Studio hostname already taken',
1386
- statusCode: 409
1387
- });
1388
- // Second API call succeeds
1389
- mockApi({
1390
- apiVersion: USER_APPLICATIONS_API_VERSION,
1391
- method: 'post',
1392
- query: {
1393
- appType: 'studio'
1394
- },
1395
- uri: `/projects/${projectId}/user-applications`
1396
- }).once().reply(200, {
1397
- appHost: 'valid-name',
1398
- createdAt: '2024-01-01T00:00:00Z',
1399
- id: validStudioId,
1400
- projectId,
1401
- title: 'Valid Studio',
1402
- type: 'studio',
1403
- updatedAt: '2024-01-01T00:00:00Z',
1404
- urlType: 'internal'
1405
- });
1406
- mockApi({
1407
- apiVersion: USER_APPLICATIONS_API_VERSION,
1408
- method: 'post',
1409
- query: {
1410
- appType: 'studio'
1411
- },
1412
- uri: `/projects/${projectId}/user-applications/${validStudioId}/deployments`
1413
- }).reply(200, {
1414
- id: deploymentId
1415
- });
1416
- const { error, stdout } = await testCommand(DeployCommand, [], {
1417
- config: {
1418
- root: cwd
1419
- }
1420
- });
1421
- expect(error).toBeUndefined();
1422
- expect(stdout).toContain('Success! Studio deployed');
1423
- });
1424
- test('should handle input validation fails with unknown error', async ()=>{
1425
- const cwd = await testExample('basic-studio');
1426
- process.cwd = ()=>cwd;
1427
- const projectId = 'test-project-id';
1428
- mockInput.mockImplementation(({ validate })=>{
1429
- const promise = (async ()=>{
1430
- if (validate) {
1431
- // First attempt with a name that will be taken (triggers 409)
1432
- let result = await validate('taken-name');
1433
- if (result !== true) {
1434
- // Name was taken, try again with a valid name (triggers 200)
1435
- result = await validate('valid-name');
1436
- }
1437
- }
1438
- return 'valid-name';
1439
- })();
1440
- promise.cancel = ()=>{};
1441
- return promise;
1442
- });
1443
- mockGetCliConfig.mockResolvedValue({
1444
- api: {
1445
- projectId
1446
- }
1447
- });
1448
- mockApi({
1449
- apiVersion: USER_APPLICATIONS_API_VERSION,
1450
- query: {
1451
- appType: 'studio'
1452
- },
1453
- uri: `/projects/${projectId}/user-applications`
1454
- }).reply(200, []);
1455
- // First API call fails (hostname taken)
1456
- mockApi({
1457
- apiVersion: USER_APPLICATIONS_API_VERSION,
1458
- method: 'post',
1459
- query: {
1460
- appType: 'studio'
1461
- },
1462
- uri: `/projects/${projectId}/user-applications`
1463
- }).once().reply(500, {
1464
- message: 'Internal server error',
1465
- statusCode: 500
1466
- });
1467
- const { error } = await testCommand(DeployCommand, [], {
1468
- config: {
1469
- root: cwd
1470
- }
1471
- });
1472
- expect(error?.message).toContain('Error creating user application');
1473
- expect(error?.oclif?.exit).toBe(1);
1474
- });
1475
- test('should throw error when no projectId is configured', async ()=>{
1476
- const cwd = await testExample('basic-studio');
1477
- process.cwd = ()=>cwd;
1478
- mockGetCliConfig.mockResolvedValue({
1479
- api: {},
1480
- studioHost: 'some-studio'
1481
- });
1482
- const { error } = await testCommand(DeployCommand, [], {
1483
- config: {
1484
- root: cwd
1485
- }
1486
- });
1487
- expect(error?.message).toContain('sanity.cli.ts does not contain a project identifier ("api.projectId"), which is required for the Sanity CLI to communicate with the Sanity API');
1488
- expect(error?.oclif?.exit).toBe(1);
1489
- });
1490
- test('should log a warning if the deprecated auto-updates flag is used', async ()=>{
1491
- const cwd = await testExample('basic-studio');
1492
- process.cwd = ()=>cwd;
1493
- const { stderr } = await testCommand(DeployCommand, [
1494
- '--auto-updates'
1495
- ], {
1496
- config: {
1497
- root: cwd
1498
- }
1499
- });
1500
- expect(stderr).toContain('Warning: The --auto-updates flag is deprecated');
1501
- });
1502
- test('should throw an error when both the current and deprecated autoUpdates config are used', async ()=>{
1503
- const cwd = await testExample('basic-studio');
1504
- process.cwd = ()=>cwd;
1505
- mockGetCliConfig.mockResolvedValue({
1506
- autoUpdates: true,
1507
- deployment: {
1508
- autoUpdates: true
1509
- }
1510
- });
1511
- const { error } = await testCommand(DeployCommand, [], {
1512
- config: {
1513
- root: cwd
1514
- }
1515
- });
1516
- expect(error?.message).toContain('Found both `autoUpdates` (deprecated) and `deployment.autoUpdates` in sanity.cli.');
1517
- expect(error?.oclif?.exit).toBe(1);
1518
- });
1519
- test('should handle general API errors when finding user application', async ()=>{
1520
- const cwd = await testExample('basic-studio');
1521
- process.cwd = ()=>cwd;
1522
- const projectId = 'test-project-id';
1523
- const studioHost = 'existing-studio';
1524
- mockGetCliConfig.mockResolvedValue({
1525
- api: {
1526
- projectId
1527
- },
1528
- studioHost
1529
- });
1530
- mockApi({
1531
- apiVersion: USER_APPLICATIONS_API_VERSION,
1532
- query: {
1533
- appHost: studioHost,
1534
- appType: 'studio'
1535
- },
1536
- uri: `/projects/${projectId}/user-applications`
1537
- }).reply(500, {
1538
- error: 'Internal server error'
1539
- });
1540
- const { error } = await testCommand(DeployCommand, [], {
1541
- config: {
1542
- root: cwd
1543
- }
1544
- });
1545
- expect(error?.message).toContain('Error finding user application');
1546
- expect(error?.oclif?.exit).toBe(1);
1547
- });
1548
- test('should handle deployment API errors for studio', async ()=>{
1549
- const cwd = await testExample('basic-studio');
1550
- process.cwd = ()=>cwd;
1551
- const projectId = 'test-project-id';
1552
- const studioHost = 'existing-studio';
1553
- const studioAppId = 'studio-app-id';
1554
- mockGetCliConfig.mockResolvedValue({
1555
- api: {
1556
- projectId
1557
- },
1558
- studioHost
1559
- });
1560
- mockApi({
1561
- apiVersion: USER_APPLICATIONS_API_VERSION,
1562
- query: {
1563
- appHost: studioHost,
1564
- appType: 'studio'
1565
- },
1566
- uri: `/projects/${projectId}/user-applications`
1567
- }).reply(200, {
1568
- appHost: studioHost,
1569
- createdAt: '2024-01-01T00:00:00Z',
1570
- id: studioAppId,
1571
- projectId,
1572
- title: 'Existing Studio',
1573
- type: 'studio',
1574
- updatedAt: '2024-01-01T00:00:00Z',
1575
- urlType: 'internal'
1576
- });
1577
- mockApi({
1578
- apiVersion: USER_APPLICATIONS_API_VERSION,
1579
- method: 'post',
1580
- query: {
1581
- appType: 'studio'
1582
- },
1583
- uri: `/projects/${projectId}/user-applications/${studioAppId}/deployments`
1584
- }).reply(500, {
1585
- error: 'Internal server error'
1586
- });
1587
- const { error } = await testCommand(DeployCommand, [], {
1588
- config: {
1589
- root: cwd
1590
- }
1591
- });
1592
- expect(error?.message).toContain('Error deploying studio');
1593
- expect(error?.oclif?.exit).toBe(1);
1594
- });
1595
- test('should handle fatal errors during studio hostname creation', async ()=>{
1596
- const cwd = await testExample('basic-studio');
1597
- process.cwd = ()=>cwd;
1598
- const projectId = 'test-project-id';
1599
- const studioHost = 'new-studio-host';
1600
- mockGetCliConfig.mockResolvedValue({
1601
- api: {
1602
- projectId
1603
- },
1604
- studioHost
1605
- });
1606
- mockApi({
1607
- apiVersion: USER_APPLICATIONS_API_VERSION,
1608
- query: {
1609
- appHost: studioHost,
1610
- appType: 'studio'
1611
- },
1612
- uri: `/projects/${projectId}/user-applications`
1613
- }).reply(404, {
1614
- message: 'Not found'
1615
- });
1616
- mockApi({
1617
- apiVersion: USER_APPLICATIONS_API_VERSION,
1618
- method: 'post',
1619
- query: {
1620
- appType: 'studio'
1621
- },
1622
- uri: `/projects/${projectId}/user-applications`
1623
- }).reply(500, {
1624
- message: 'Internal server error',
1625
- statusCode: 500
1626
- });
1627
- const { error } = await testCommand(DeployCommand, [], {
1628
- config: {
1629
- root: cwd
1630
- }
1631
- });
1632
- expect(error?.message).toContain('Error creating user application from config');
1633
- expect(error?.oclif?.exit).toBe(1);
1634
- });
1635
- test('should handle no existing studio applications scenario', async ()=>{
1636
- const cwd = await testExample('basic-studio');
1637
- process.cwd = ()=>cwd;
1638
- const projectId = 'test-project-id';
1639
- const newStudioId = 'new-studio-id';
1640
- const deploymentId = 'deployment-id';
1641
- mockInput.mockImplementation(({ validate })=>{
1642
- const promise = (async ()=>{
1643
- if (validate) {
1644
- await validate('new-studio-name');
1645
- }
1646
- return 'new-studio-name';
1647
- })();
1648
- promise.cancel = ()=>{};
1649
- return promise;
1650
- });
1651
- mockGetCliConfig.mockResolvedValue({
1652
- api: {
1653
- projectId
1654
- }
1655
- });
1656
- mockApi({
1657
- apiVersion: USER_APPLICATIONS_API_VERSION,
1658
- query: {
1659
- appType: 'studio'
1660
- },
1661
- uri: `/projects/${projectId}/user-applications`
1662
- }).reply(200, []);
1663
- mockApi({
1664
- apiVersion: USER_APPLICATIONS_API_VERSION,
1665
- method: 'post',
1666
- query: {
1667
- appType: 'studio'
1668
- },
1669
- uri: `/projects/${projectId}/user-applications`
1670
- }).reply(200, {
1671
- appHost: 'new-studio-name',
1672
- createdAt: '2024-01-01T00:00:00Z',
1673
- id: newStudioId,
1674
- projectId,
1675
- title: 'New Studio',
1676
- type: 'studio',
1677
- updatedAt: '2024-01-01T00:00:00Z',
1678
- urlType: 'internal'
1679
- });
1680
- mockApi({
1681
- apiVersion: USER_APPLICATIONS_API_VERSION,
1682
- method: 'post',
1683
- query: {
1684
- appType: 'studio'
1685
- },
1686
- uri: `/projects/${projectId}/user-applications/${newStudioId}/deployments`
1687
- }).reply(200, {
1688
- id: deploymentId
1689
- });
1690
- const { error, stdout } = await testCommand(DeployCommand, [], {
1691
- config: {
1692
- root: cwd
1693
- }
1694
- });
1695
- expect(error).toBeUndefined();
1696
- expect(stdout).toContain('Success! Studio deployed');
1697
- expect(mockInput).toHaveBeenCalledWith({
1698
- message: 'Studio hostname (<value>.sanity.studio):',
1699
- validate: expect.any(Function)
1700
- });
1701
- });
1702
- test('should skip build when --no-build flag is used for studio', async ()=>{
1703
- const cwd = await testExample('basic-studio');
1704
- process.cwd = ()=>cwd;
1705
- const projectId = 'test-project-id';
1706
- const studioHost = 'existing-studio';
1707
- const studioAppId = 'studio-app-id';
1708
- const deploymentId = 'deployment-id';
1709
- mockGetCliConfig.mockResolvedValue({
1710
- api: {
1711
- projectId
1712
- },
1713
- studioHost
1714
- });
1715
- mockApi({
1716
- apiVersion: USER_APPLICATIONS_API_VERSION,
1717
- query: {
1718
- appHost: studioHost,
1719
- appType: 'studio'
1720
- },
1721
- uri: `/projects/${projectId}/user-applications`
1722
- }).reply(200, {
1723
- appHost: studioHost,
1724
- createdAt: '2024-01-01T00:00:00Z',
1725
- id: studioAppId,
1726
- projectId,
1727
- title: 'Existing Studio',
1728
- type: 'studio',
1729
- updatedAt: '2024-01-01T00:00:00Z',
1730
- urlType: 'internal'
1731
- });
1732
- mockApi({
1733
- apiVersion: USER_APPLICATIONS_API_VERSION,
1734
- method: 'post',
1735
- query: {
1736
- appType: 'studio'
1737
- },
1738
- uri: `/projects/${projectId}/user-applications/${studioAppId}/deployments`
1739
- }).reply(200, {
1740
- id: deploymentId
1741
- });
1742
- const { error, stdout } = await testCommand(DeployCommand, [
1743
- '--no-build'
1744
- ], {
1745
- config: {
1746
- root: cwd
1747
- }
1748
- });
1749
- expect(error).toBeUndefined();
1750
- expect(stdout).toContain('Success! Studio deployed');
1751
- expect(mockBuildStudio).not.toHaveBeenCalled();
1752
- });
1753
- test('should deploy studio using deployment.appId', async ()=>{
1754
- const cwd = await testExample('basic-studio');
1755
- process.cwd = ()=>cwd;
1756
- const projectId = 'test-project-id';
1757
- const studioAppId = 'studio-app-id';
1758
- const appHost = 'my-studio';
1759
- const deploymentId = 'deployment-id';
1760
- mockGetCliConfig.mockResolvedValue({
1761
- api: {
1762
- projectId
1763
- },
1764
- deployment: {
1765
- appId: studioAppId
1766
- }
1767
- });
1768
- mockApi({
1769
- apiVersion: USER_APPLICATIONS_API_VERSION,
1770
- uri: `/projects/${projectId}/user-applications/${studioAppId}`
1771
- }).reply(200, {
1772
- appHost,
1773
- createdAt: '2024-01-01T00:00:00Z',
1774
- id: studioAppId,
1775
- projectId,
1776
- title: 'My Studio',
1777
- type: 'studio',
1778
- updatedAt: '2024-01-01T00:00:00Z',
1779
- urlType: 'internal'
1780
- });
1781
- mockApi({
1782
- apiVersion: USER_APPLICATIONS_API_VERSION,
1783
- method: 'post',
1784
- query: {
1785
- appType: 'studio'
1786
- },
1787
- uri: `/projects/${projectId}/user-applications/${studioAppId}/deployments`
1788
- }).reply(200, {
1789
- id: deploymentId,
1790
- location: `https://${appHost}.sanity.studio`
1791
- });
1792
- const { error, stdout } = await testCommand(DeployCommand, [], {
1793
- config: {
1794
- root: cwd
1795
- }
1796
- });
1797
- expect(error).toBeUndefined();
1798
- expect(stdout).toContain(`Success! Studio deployed to https://${appHost}.sanity.studio`);
1799
- });
1800
- test('should prioritize deployment.appId over studioHost when both are configured', async ()=>{
1801
- const cwd = await testExample('basic-studio');
1802
- process.cwd = ()=>cwd;
1803
- const projectId = 'test-project-id';
1804
- const studioAppId = 'studio-app-id';
1805
- const studioHost = 'my-studio-host';
1806
- const deploymentId = 'deployment-id';
1807
- mockGetCliConfig.mockResolvedValue({
1808
- api: {
1809
- projectId
1810
- },
1811
- deployment: {
1812
- appId: studioAppId
1813
- },
1814
- studioHost
1815
- });
1816
- // Should call by appId, NOT by appHost
1817
- mockApi({
1818
- apiVersion: USER_APPLICATIONS_API_VERSION,
1819
- uri: `/projects/${projectId}/user-applications/${studioAppId}`
1820
- }).reply(200, {
1821
- appHost: studioHost,
1822
- createdAt: '2024-01-01T00:00:00Z',
1823
- id: studioAppId,
1824
- projectId,
1825
- title: 'My Studio',
1826
- type: 'studio',
1827
- updatedAt: '2024-01-01T00:00:00Z',
1828
- urlType: 'internal'
1829
- });
1830
- mockApi({
1831
- apiVersion: USER_APPLICATIONS_API_VERSION,
1832
- method: 'post',
1833
- query: {
1834
- appType: 'studio'
1835
- },
1836
- uri: `/projects/${projectId}/user-applications/${studioAppId}/deployments`
1837
- }).reply(200, {
1838
- id: deploymentId,
1839
- location: `https://${studioHost}.sanity.studio`
1840
- });
1841
- const { error, stdout } = await testCommand(DeployCommand, [], {
1842
- config: {
1843
- root: cwd
1844
- }
1845
- });
1846
- expect(error).toBeUndefined();
1847
- expect(stdout).toContain(`Success! Studio deployed to https://${studioHost}.sanity.studio`);
1848
- });
1849
- test('should handle error when deployment.appId does not exist for the org', async ()=>{
1850
- const cwd = await testExample('basic-studio');
1851
- process.cwd = ()=>cwd;
1852
- const projectId = 'test-project-id';
1853
- const studioAppId = 'non-existent-app-id';
1854
- mockGetCliConfig.mockResolvedValue({
1855
- api: {
1856
- projectId
1857
- },
1858
- deployment: {
1859
- appId: studioAppId
1860
- }
1861
- });
1862
- mockApi({
1863
- apiVersion: USER_APPLICATIONS_API_VERSION,
1864
- uri: `/projects/${projectId}/user-applications/${studioAppId}`
1865
- }).reply(404, {
1866
- message: 'Application not found'
1867
- });
1868
- const { error } = await testCommand(DeployCommand, [], {
1869
- config: {
1870
- root: cwd
1871
- }
1872
- });
1873
- expect(error?.message).toContain('Error finding user application');
1874
- expect(error?.message).toContain(`Cannot find app with app ID ${studioAppId}`);
1875
- expect(error?.oclif?.exit).toBe(1);
1876
- });
1877
- test('should not fall back to studioHost when deployment.appId is configured but does not exist', async ()=>{
1878
- const cwd = await testExample('basic-studio');
1879
- process.cwd = ()=>cwd;
1880
- const projectId = 'test-project-id';
1881
- const studioAppId = 'non-existent-app-id';
1882
- const studioHost = 'valid-studio-host';
1883
- mockGetCliConfig.mockResolvedValue({
1884
- api: {
1885
- projectId
1886
- },
1887
- deployment: {
1888
- appId: studioAppId
1889
- },
1890
- studioHost
1891
- });
1892
- // appId lookup fails
1893
- mockApi({
1894
- apiVersion: USER_APPLICATIONS_API_VERSION,
1895
- uri: `/projects/${projectId}/user-applications/${studioAppId}`
1896
- }).reply(404, {
1897
- message: 'Application not found'
1898
- });
1899
- // Should NOT make a call to studioHost - if it does, this mock will remain unused
1900
- // and cause the test to fail due to pending mocks check
1901
- const { error } = await testCommand(DeployCommand, [], {
1902
- config: {
1903
- root: cwd
1904
- }
1905
- });
1906
- expect(error?.message).toContain('Error finding user application');
1907
- expect(error?.message).toContain(`Cannot find app with app ID ${studioAppId}`);
1908
- expect(error?.oclif?.exit).toBe(1);
1909
- });
1910
- });
1911
- });
1912
-
1913
- //# sourceMappingURL=deploy.test.js.map