@stripe/extensibility-dev-tools 0.23.5

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 (253) hide show
  1. package/LICENSE.md +19 -0
  2. package/dist/bin/build-custom-object-definitions.cjs +2111 -0
  3. package/dist/bin/build-custom-object-definitions.d.ts +11 -0
  4. package/dist/bin/build-custom-object-definitions.d.ts.map +1 -0
  5. package/dist/bin/build-custom-object-definitions.js +2088 -0
  6. package/dist/bin/create-upload-image.cjs +2136 -0
  7. package/dist/bin/create-upload-image.d.ts +17 -0
  8. package/dist/bin/create-upload-image.d.ts.map +1 -0
  9. package/dist/bin/create-upload-image.js +2113 -0
  10. package/dist/bin/dev-tools-rpc.cjs +3874 -0
  11. package/dist/bin/dev-tools-rpc.d.ts +3 -0
  12. package/dist/bin/dev-tools-rpc.d.ts.map +1 -0
  13. package/dist/bin/dev-tools-rpc.js +3864 -0
  14. package/dist/bin/gen-schemas.cjs +20739 -0
  15. package/dist/bin/gen-schemas.d.ts +8 -0
  16. package/dist/bin/gen-schemas.d.ts.map +1 -0
  17. package/dist/bin/gen-schemas.js +20715 -0
  18. package/dist/bin/gen-workspace.cjs +3847 -0
  19. package/dist/bin/gen-workspace.d.ts +8 -0
  20. package/dist/bin/gen-workspace.d.ts.map +1 -0
  21. package/dist/bin/gen-workspace.js +3841 -0
  22. package/dist/bin/manifest.cjs +686 -0
  23. package/dist/bin/manifest.d.ts +10 -0
  24. package/dist/bin/manifest.d.ts.map +1 -0
  25. package/dist/bin/manifest.js +663 -0
  26. package/dist/bin/rpc/dispatch.d.ts +10 -0
  27. package/dist/bin/rpc/dispatch.d.ts.map +1 -0
  28. package/dist/bin/rpc/handlers.d.ts +4 -0
  29. package/dist/bin/rpc/handlers.d.ts.map +1 -0
  30. package/dist/bin/rpc/types.d.ts +29 -0
  31. package/dist/bin/rpc/types.d.ts.map +1 -0
  32. package/dist/bin/template-info.cjs +1511 -0
  33. package/dist/bin/template-info.d.ts +9 -0
  34. package/dist/bin/template-info.d.ts.map +1 -0
  35. package/dist/bin/template-info.js +1488 -0
  36. package/dist/custom-objects/build-definitions.d.ts +98 -0
  37. package/dist/custom-objects/build-definitions.d.ts.map +1 -0
  38. package/dist/custom-objects/generated/proto/custom_objects/pub/api/app_api/object_definitions_app_service.pb.d.ts +191 -0
  39. package/dist/custom-objects/generated/proto/custom_objects/pub/api/app_api/object_definitions_app_service.pb.d.ts.map +1 -0
  40. package/dist/custom-objects/generated/proto/custom_objects/pub/api/common/schema.pb.d.ts +131 -0
  41. package/dist/custom-objects/generated/proto/custom_objects/pub/api/common/schema.pb.d.ts.map +1 -0
  42. package/dist/custom-objects/generated/proto/google/protobuf/descriptor.pb.d.ts +1482 -0
  43. package/dist/custom-objects/generated/proto/google/protobuf/descriptor.pb.d.ts.map +1 -0
  44. package/dist/custom-objects/generated/proto/google/protobuf/timestamp.pb.d.ts +167 -0
  45. package/dist/custom-objects/generated/proto/google/protobuf/timestamp.pb.d.ts.map +1 -0
  46. package/dist/custom-objects/generated/proto/proto/annotations.pb.d.ts +64 -0
  47. package/dist/custom-objects/generated/proto/proto/annotations.pb.d.ts.map +1 -0
  48. package/dist/custom-objects/generated/proto/proto/extensions.pb.d.ts +657 -0
  49. package/dist/custom-objects/generated/proto/proto/extensions.pb.d.ts.map +1 -0
  50. package/dist/custom-objects/generated/proto/vendor/metadata/pub/api/api_metadata.pb.d.ts +105 -0
  51. package/dist/custom-objects/generated/proto/vendor/metadata/pub/api/api_metadata.pb.d.ts.map +1 -0
  52. package/dist/custom-objects/generated/proto/vendor/net/idempotency/idempotency_model.pb.d.ts +79 -0
  53. package/dist/custom-objects/generated/proto/vendor/net/idempotency/idempotency_model.pb.d.ts.map +1 -0
  54. package/dist/custom-objects/generated/proto/vendor/publicapi/api_group_enum.pb.d.ts +129 -0
  55. package/dist/custom-objects/generated/proto/vendor/publicapi/api_group_enum.pb.d.ts.map +1 -0
  56. package/dist/custom-objects/generated/proto/vendor/publicapi/api_visibility.pb.d.ts +76 -0
  57. package/dist/custom-objects/generated/proto/vendor/publicapi/api_visibility.pb.d.ts.map +1 -0
  58. package/dist/custom-objects/generated/proto/vendor/publicapi/customize_dispatch_middleware_enum.pb.d.ts +78 -0
  59. package/dist/custom-objects/generated/proto/vendor/publicapi/customize_dispatch_middleware_enum.pb.d.ts.map +1 -0
  60. package/dist/custom-objects/generated/proto/vendor/publicapi/docs_namespace_group_enum.pb.d.ts +146 -0
  61. package/dist/custom-objects/generated/proto/vendor/publicapi/docs_namespace_group_enum.pb.d.ts.map +1 -0
  62. package/dist/custom-objects/generated/proto/vendor/publicapi/documented_enum.pb.d.ts +76 -0
  63. package/dist/custom-objects/generated/proto/vendor/publicapi/documented_enum.pb.d.ts.map +1 -0
  64. package/dist/custom-objects/generated/proto/vendor/publicapi/event_scope_enum.pb.d.ts +92 -0
  65. package/dist/custom-objects/generated/proto/vendor/publicapi/event_scope_enum.pb.d.ts.map +1 -0
  66. package/dist/custom-objects/generated/proto/vendor/publicapi/extension_interface.pb.d.ts +124 -0
  67. package/dist/custom-objects/generated/proto/vendor/publicapi/extension_interface.pb.d.ts.map +1 -0
  68. package/dist/custom-objects/generated/proto/vendor/publicapi/feature_enum.pb.d.ts +1070 -0
  69. package/dist/custom-objects/generated/proto/vendor/publicapi/feature_enum.pb.d.ts.map +1 -0
  70. package/dist/custom-objects/generated/proto/vendor/publicapi/field_validation_rules.pb.d.ts +279 -0
  71. package/dist/custom-objects/generated/proto/vendor/publicapi/field_validation_rules.pb.d.ts.map +1 -0
  72. package/dist/custom-objects/generated/proto/vendor/publicapi/flavor_enum.pb.d.ts +78 -0
  73. package/dist/custom-objects/generated/proto/vendor/publicapi/flavor_enum.pb.d.ts.map +1 -0
  74. package/dist/custom-objects/generated/proto/vendor/publicapi/http_error_status.pb.d.ts +102 -0
  75. package/dist/custom-objects/generated/proto/vendor/publicapi/http_error_status.pb.d.ts.map +1 -0
  76. package/dist/custom-objects/generated/proto/vendor/publicapi/method_kind_enum.pb.d.ts +86 -0
  77. package/dist/custom-objects/generated/proto/vendor/publicapi/method_kind_enum.pb.d.ts.map +1 -0
  78. package/dist/custom-objects/generated/proto/vendor/publicapi/method_priority.pb.d.ts +80 -0
  79. package/dist/custom-objects/generated/proto/vendor/publicapi/method_priority.pb.d.ts.map +1 -0
  80. package/dist/custom-objects/generated/proto/vendor/publicapi/permission_check_enum.pb.d.ts +74 -0
  81. package/dist/custom-objects/generated/proto/vendor/publicapi/permission_check_enum.pb.d.ts.map +1 -0
  82. package/dist/custom-objects/generated/proto/vendor/publicapi/redaction_enum.pb.d.ts +76 -0
  83. package/dist/custom-objects/generated/proto/vendor/publicapi/redaction_enum.pb.d.ts.map +1 -0
  84. package/dist/custom-objects/generated/proto/vendor/publicapi/region_routers.pb.d.ts +103 -0
  85. package/dist/custom-objects/generated/proto/vendor/publicapi/region_routers.pb.d.ts.map +1 -0
  86. package/dist/custom-objects/generated/proto/vendor/publicapi/rollout_configs.pb.d.ts +153 -0
  87. package/dist/custom-objects/generated/proto/vendor/publicapi/rollout_configs.pb.d.ts.map +1 -0
  88. package/dist/custom-objects/generated/proto/vendor/publicapi/v2ext.pb.d.ts +1111 -0
  89. package/dist/custom-objects/generated/proto/vendor/publicapi/v2ext.pb.d.ts.map +1 -0
  90. package/dist/custom-objects/generated/proto/vendor/vext/annotations.pb.d.ts +602 -0
  91. package/dist/custom-objects/generated/proto/vendor/vext/annotations.pb.d.ts.map +1 -0
  92. package/dist/custom-objects/generated/proto/vendor/vext/extensions.pb.d.ts +144 -0
  93. package/dist/custom-objects/generated/proto/vendor/vext/extensions.pb.d.ts.map +1 -0
  94. package/dist/custom-objects/generated/proto/vendor/vext/privacy_unified_annotations.pb.d.ts +851 -0
  95. package/dist/custom-objects/generated/proto/vendor/vext/privacy_unified_annotations.pb.d.ts.map +1 -0
  96. package/dist/custom-objects/generated/proto/vendor/vext/xml_annotations.pb.d.ts +125 -0
  97. package/dist/custom-objects/generated/proto/vendor/vext/xml_annotations.pb.d.ts.map +1 -0
  98. package/dist/custom-objects/to-proto-json.d.ts +17 -0
  99. package/dist/custom-objects/to-proto-json.d.ts.map +1 -0
  100. package/dist/dependencies/index.cjs +601 -0
  101. package/dist/dependencies/index.d.ts +320 -0
  102. package/dist/dependencies/index.d.ts.map +1 -0
  103. package/dist/dependencies/index.js +560 -0
  104. package/dist/extensibility-dev-tools-alpha.d.ts +199 -0
  105. package/dist/extensibility-dev-tools-beta.d.ts +199 -0
  106. package/dist/extensibility-dev-tools-dependencies-alpha.d.ts +51 -0
  107. package/dist/extensibility-dev-tools-dependencies-beta.d.ts +51 -0
  108. package/dist/extensibility-dev-tools-dependencies-internal.d.ts +372 -0
  109. package/dist/extensibility-dev-tools-dependencies-public.d.ts +51 -0
  110. package/dist/extensibility-dev-tools-internal.d.ts +1722 -0
  111. package/dist/extensibility-dev-tools-jsonschema-tools-alpha.d.ts +57 -0
  112. package/dist/extensibility-dev-tools-jsonschema-tools-beta.d.ts +57 -0
  113. package/dist/extensibility-dev-tools-jsonschema-tools-internal.d.ts +123 -0
  114. package/dist/extensibility-dev-tools-jsonschema-tools-public.d.ts +57 -0
  115. package/dist/extensibility-dev-tools-manifest-alpha.d.ts +31 -0
  116. package/dist/extensibility-dev-tools-manifest-beta.d.ts +31 -0
  117. package/dist/extensibility-dev-tools-manifest-internal.d.ts +461 -0
  118. package/dist/extensibility-dev-tools-manifest-public.d.ts +31 -0
  119. package/dist/extensibility-dev-tools-public.d.ts +199 -0
  120. package/dist/extensibility-dev-tools-schemas-alpha.d.ts +9 -0
  121. package/dist/extensibility-dev-tools-schemas-beta.d.ts +9 -0
  122. package/dist/extensibility-dev-tools-schemas-internal.d.ts +41 -0
  123. package/dist/extensibility-dev-tools-schemas-public.d.ts +9 -0
  124. package/dist/extensibility-dev-tools-templates-alpha.d.ts +67 -0
  125. package/dist/extensibility-dev-tools-templates-beta.d.ts +67 -0
  126. package/dist/extensibility-dev-tools-templates-internal.d.ts +554 -0
  127. package/dist/extensibility-dev-tools-templates-public.d.ts +67 -0
  128. package/dist/extensibility-dev-tools-workspace-alpha.d.ts +51 -0
  129. package/dist/extensibility-dev-tools-workspace-beta.d.ts +51 -0
  130. package/dist/extensibility-dev-tools-workspace-internal.d.ts +410 -0
  131. package/dist/extensibility-dev-tools-workspace-public.d.ts +51 -0
  132. package/dist/index.cjs +3810 -0
  133. package/dist/index.d.ts +18 -0
  134. package/dist/index.d.ts.map +1 -0
  135. package/dist/index.js +3758 -0
  136. package/dist/jsonschema-tools.cjs +20451 -0
  137. package/dist/jsonschema-tools.d.ts +98 -0
  138. package/dist/jsonschema-tools.d.ts.map +1 -0
  139. package/dist/jsonschema-tools.js +20404 -0
  140. package/dist/manifest/index.cjs +610 -0
  141. package/dist/manifest/index.d.ts +8 -0
  142. package/dist/manifest/index.d.ts.map +1 -0
  143. package/dist/manifest/index.js +571 -0
  144. package/dist/manifest/manifest-v1.d.ts +102 -0
  145. package/dist/manifest/manifest-v1.d.ts.map +1 -0
  146. package/dist/manifest/manifest-v2.d.ts +253 -0
  147. package/dist/manifest/manifest-v2.d.ts.map +1 -0
  148. package/dist/manifest/stripe-app-manifest.d.ts +114 -0
  149. package/dist/manifest/stripe-app-manifest.d.ts.map +1 -0
  150. package/dist/schemas/index.cjs +20692 -0
  151. package/dist/schemas/index.d.ts +37 -0
  152. package/dist/schemas/index.d.ts.map +1 -0
  153. package/dist/schemas/index.js +20656 -0
  154. package/dist/templates/diff-viewer/diff-generator.d.ts +22 -0
  155. package/dist/templates/diff-viewer/diff-generator.d.ts.map +1 -0
  156. package/dist/templates/diff-viewer/diff-prompt.d.ts +13 -0
  157. package/dist/templates/diff-viewer/diff-prompt.d.ts.map +1 -0
  158. package/dist/templates/diff-viewer/index.d.ts +7 -0
  159. package/dist/templates/diff-viewer/index.d.ts.map +1 -0
  160. package/dist/templates/diff-viewer/terminal-renderer.d.ts +29 -0
  161. package/dist/templates/diff-viewer/terminal-renderer.d.ts.map +1 -0
  162. package/dist/templates/diff-viewer/types.d.ts +58 -0
  163. package/dist/templates/diff-viewer/types.d.ts.map +1 -0
  164. package/dist/templates/extensions/base.d.ts +23 -0
  165. package/dist/templates/extensions/base.d.ts.map +1 -0
  166. package/dist/templates/extensions/billing.bill.discount_calculation.d.ts +6 -0
  167. package/dist/templates/extensions/billing.bill.discount_calculation.d.ts.map +1 -0
  168. package/dist/templates/extensions/billing.customer_balance_application.d.ts +6 -0
  169. package/dist/templates/extensions/billing.customer_balance_application.d.ts.map +1 -0
  170. package/dist/templates/extensions/billing.invoice_collection_setting.d.ts +6 -0
  171. package/dist/templates/extensions/billing.invoice_collection_setting.d.ts.map +1 -0
  172. package/dist/templates/extensions/billing.prorations.d.ts +6 -0
  173. package/dist/templates/extensions/billing.prorations.d.ts.map +1 -0
  174. package/dist/templates/extensions/billing.recurring_billing_item_handling.d.ts +6 -0
  175. package/dist/templates/extensions/billing.recurring_billing_item_handling.d.ts.map +1 -0
  176. package/dist/templates/extensions/core.workflows.custom_action.d.ts +6 -0
  177. package/dist/templates/extensions/core.workflows.custom_action.d.ts.map +1 -0
  178. package/dist/templates/extensions/extend.objects.custom_objects.d.ts +6 -0
  179. package/dist/templates/extensions/extend.objects.custom_objects.d.ts.map +1 -0
  180. package/dist/templates/extensions/extend.workflows.custom_action.d.ts +6 -0
  181. package/dist/templates/extensions/extend.workflows.custom_action.d.ts.map +1 -0
  182. package/dist/templates/extensions/index.d.ts +13 -0
  183. package/dist/templates/extensions/index.d.ts.map +1 -0
  184. package/dist/templates/extensions/registry.d.ts +10 -0
  185. package/dist/templates/extensions/registry.d.ts.map +1 -0
  186. package/dist/templates/extensions/types.d.ts +104 -0
  187. package/dist/templates/extensions/types.d.ts.map +1 -0
  188. package/dist/templates/file-writer.d.ts +140 -0
  189. package/dist/templates/file-writer.d.ts.map +1 -0
  190. package/dist/templates/fs/_impl.d.ts +29 -0
  191. package/dist/templates/fs/_impl.d.ts.map +1 -0
  192. package/dist/templates/fs/filesystem.d.ts +8 -0
  193. package/dist/templates/fs/filesystem.d.ts.map +1 -0
  194. package/dist/templates/fs/in-memory.d.ts +9 -0
  195. package/dist/templates/fs/in-memory.d.ts.map +1 -0
  196. package/dist/templates/fs/index.d.ts +25 -0
  197. package/dist/templates/fs/index.d.ts.map +1 -0
  198. package/dist/templates/fs-utils.d.ts +17 -0
  199. package/dist/templates/fs-utils.d.ts.map +1 -0
  200. package/dist/templates/index.cjs +2248 -0
  201. package/dist/templates/index.d.ts +32 -0
  202. package/dist/templates/index.d.ts.map +1 -0
  203. package/dist/templates/index.js +2203 -0
  204. package/dist/templates/root/index.d.ts +60 -0
  205. package/dist/templates/root/index.d.ts.map +1 -0
  206. package/dist/templates/simple-templates.d.ts +8 -0
  207. package/dist/templates/simple-templates.d.ts.map +1 -0
  208. package/dist/templates/template-manager.d.ts +8 -0
  209. package/dist/templates/template-manager.d.ts.map +1 -0
  210. package/dist/templates/types.d.ts +9 -0
  211. package/dist/templates/types.d.ts.map +1 -0
  212. package/dist/tsconfig.build.tsbuildinfo +1 -0
  213. package/dist/workspace/index.cjs +3756 -0
  214. package/dist/workspace/index.d.ts +336 -0
  215. package/dist/workspace/index.d.ts.map +1 -0
  216. package/dist/workspace/index.js +3731 -0
  217. package/package.json +137 -0
  218. package/templates/extensions/billing.bill.discount_calculation/index.test.ts +15 -0
  219. package/templates/extensions/billing.bill.discount_calculation/index.ts +20 -0
  220. package/templates/extensions/billing.customer_balance_application/index.test.ts +15 -0
  221. package/templates/extensions/billing.customer_balance_application/index.ts +18 -0
  222. package/templates/extensions/billing.invoice_collection_setting/index.test.ts +15 -0
  223. package/templates/extensions/billing.invoice_collection_setting/index.ts +16 -0
  224. package/templates/extensions/billing.prorations/index.test.ts +15 -0
  225. package/templates/extensions/billing.prorations/index.ts +18 -0
  226. package/templates/extensions/billing.recurring_billing_item_handling/index.test.ts +15 -0
  227. package/templates/extensions/billing.recurring_billing_item_handling/index.ts +42 -0
  228. package/templates/extensions/common/.prettierignore +3 -0
  229. package/templates/extensions/common/eslint.config.mts.mustache +95 -0
  230. package/templates/extensions/common/package.json.mustache +26 -0
  231. package/templates/extensions/common/tsconfig.build.json.mustache +15 -0
  232. package/templates/extensions/common/tsconfig.json.mustache +16 -0
  233. package/templates/extensions/core.workflows.custom_action/custom_input.schema.json +6 -0
  234. package/templates/extensions/core.workflows.custom_action/index.test.ts +15 -0
  235. package/templates/extensions/core.workflows.custom_action/index.ts +31 -0
  236. package/templates/extensions/extend.workflows.custom_action/custom_input.schema.json +6 -0
  237. package/templates/extensions/extend.workflows.custom_action/index.test.ts +15 -0
  238. package/templates/extensions/extend.workflows.custom_action/index.ts +31 -0
  239. package/templates/root/.husky/pre-commit +1 -0
  240. package/templates/root/.prettierignore +5 -0
  241. package/templates/root/.prettierrc +7 -0
  242. package/templates/root/_gitignore +28 -0
  243. package/templates/root/custom-objects/package.json +20 -0
  244. package/templates/root/custom-objects/tsconfig.json +9 -0
  245. package/templates/root/eslint.config.mts +95 -0
  246. package/templates/root/package.json.mustache +32 -0
  247. package/templates/root/pnpm-workspace.yaml +7 -0
  248. package/templates/root/stripe-app.yaml.mustache +6 -0
  249. package/templates/root/tools/test.mts +38 -0
  250. package/templates/root/tsconfig.base.json +23 -0
  251. package/templates/root/tsconfig.json +15 -0
  252. package/templates/root/ui/package.json +17 -0
  253. package/templates/root/vitest.config.mts +47 -0
@@ -0,0 +1,663 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/bin/manifest.ts
4
+ import yargs from "yargs";
5
+ import { hideBin } from "yargs/helpers";
6
+ import { _createLogger, _writeJsonOutput } from "@stripe/extensibility-tool-utils";
7
+
8
+ // src/manifest/stripe-app-manifest.ts
9
+ import { _toSnakeCase } from "@stripe/extensibility-tool-utils";
10
+
11
+ // src/manifest/manifest-v1.ts
12
+ import { readFileSync, writeFileSync, existsSync } from "fs";
13
+ function formatCustomObjectEntry(entry) {
14
+ return `${entry.filePath}#${entry.className}`;
15
+ }
16
+ function parseCustomObjectEntry(entryString) {
17
+ const parts = entryString.split("#");
18
+ if (parts.length !== 2) {
19
+ throw new Error(
20
+ `Invalid object entry format: ${entryString}. Expected format: "path/to/file.d.ts#ClassName"`
21
+ );
22
+ }
23
+ const [filePath, className] = parts;
24
+ if (!filePath || !className) {
25
+ throw new Error(
26
+ `Invalid object entry format: ${entryString}. Expected format: "path/to/file.d.ts#ClassName"`
27
+ );
28
+ }
29
+ return { filePath, className };
30
+ }
31
+ var _ManifestV1 = class __ManifestV1 {
32
+ constructor(filePath, data) {
33
+ this.filePath = filePath;
34
+ this.data = data;
35
+ }
36
+ /**
37
+ * Load stripe-app.json from disk
38
+ * @param filePath - Path to stripe-app.json
39
+ * @throws Error if file is invalid or cannot be read
40
+ */
41
+ static load(filePath) {
42
+ if (!existsSync(filePath)) {
43
+ throw new Error(`Manifest file not found: ${filePath}`);
44
+ }
45
+ const content = readFileSync(filePath, "utf-8");
46
+ const data = JSON.parse(content);
47
+ if (!data.id) {
48
+ throw new Error('Manifest must contain "id" field');
49
+ }
50
+ return new __ManifestV1(filePath, data);
51
+ }
52
+ /**
53
+ * Get the app ID from the manifest
54
+ */
55
+ getAppId() {
56
+ return this.data.id;
57
+ }
58
+ /**
59
+ * Get the app name from the manifest
60
+ */
61
+ getAppName() {
62
+ return this.data.name;
63
+ }
64
+ /**
65
+ * Get all custom objects as structured entries
66
+ */
67
+ getCustomObjects() {
68
+ const entries = [];
69
+ if (this.data.exported_custom_objects) {
70
+ for (const entry of this.data.exported_custom_objects) {
71
+ entries.push(parseCustomObjectEntry(entry));
72
+ }
73
+ }
74
+ return entries;
75
+ }
76
+ /**
77
+ * Check if a custom object entry exists in the manifest
78
+ */
79
+ hasCustomObject(entry) {
80
+ const objects = this.getCustomObjects();
81
+ return objects.some(
82
+ (existing) => existing.filePath === entry.filePath && existing.className === entry.className
83
+ );
84
+ }
85
+ /**
86
+ * Add a custom object entry to the manifest
87
+ * Does nothing if entry already exists
88
+ * @returns true if entry was added, false if it already existed
89
+ */
90
+ addCustomObject(entry) {
91
+ if (this.hasCustomObject(entry)) {
92
+ return false;
93
+ }
94
+ const entryString = formatCustomObjectEntry(entry);
95
+ this.data.exported_custom_objects ??= [];
96
+ this.data.exported_custom_objects.push(entryString);
97
+ return true;
98
+ }
99
+ /**
100
+ * Remove a custom object entry from the manifest
101
+ * @returns true if entry was removed, false if it didn't exist
102
+ */
103
+ removeCustomObject(entry) {
104
+ if (!this.data.exported_custom_objects) {
105
+ return false;
106
+ }
107
+ const entryString = formatCustomObjectEntry(entry);
108
+ const originalLength = this.data.exported_custom_objects.length;
109
+ this.data.exported_custom_objects = this.data.exported_custom_objects.filter(
110
+ (e) => e !== entryString
111
+ );
112
+ if (this.data.exported_custom_objects.length === 0) {
113
+ delete this.data.exported_custom_objects;
114
+ }
115
+ return this.data.exported_custom_objects?.length !== originalLength;
116
+ }
117
+ /**
118
+ * Get the raw manifest data (for reading other fields)
119
+ */
120
+ getRawData() {
121
+ return this.data;
122
+ }
123
+ /**
124
+ * Save changes back to disk
125
+ */
126
+ save() {
127
+ writeFileSync(this.filePath, JSON.stringify(this.data, null, 2) + "\n");
128
+ }
129
+ };
130
+
131
+ // src/manifest/manifest-v2.ts
132
+ import { readFile, writeFile } from "fs/promises";
133
+ import * as yaml from "yaml";
134
+ import { _toPascalCase } from "@stripe/extensibility-tool-utils";
135
+ function isNonEmptyString(value) {
136
+ return typeof value === "string" && value.trim().length > 0;
137
+ }
138
+ function isYamlObject(value) {
139
+ return typeof value === "object" && value !== null && !Array.isArray(value);
140
+ }
141
+ function validateManifestV2Data(data) {
142
+ if (!isNonEmptyString(data.id)) {
143
+ throw new Error('Manifest must contain non-empty "id" field');
144
+ }
145
+ if (!isNonEmptyString(data.name)) {
146
+ throw new Error('Manifest must contain non-empty "name" field');
147
+ }
148
+ if (!isNonEmptyString(data.version)) {
149
+ throw new Error('Manifest must contain non-empty "version" field');
150
+ }
151
+ if ("extensions" in data && !Array.isArray(data.extensions)) {
152
+ throw new Error('Manifest field "extensions" must be an array when provided');
153
+ }
154
+ if ("custom_object_definitions" in data && !isYamlObject(data.custom_object_definitions)) {
155
+ throw new Error(
156
+ 'Manifest field "custom_object_definitions" must be an object with a "definitions" array'
157
+ );
158
+ }
159
+ const coBlock = data.custom_object_definitions;
160
+ const definitions = isYamlObject(coBlock) ? coBlock.definitions : void 0;
161
+ if (!definitions) {
162
+ return;
163
+ }
164
+ if (!Array.isArray(definitions)) {
165
+ throw new Error(
166
+ 'Manifest field "custom_object_definitions.definitions" must be an array'
167
+ );
168
+ }
169
+ for (let i = 0; i < definitions.length; i++) {
170
+ const def = definitions[i];
171
+ const prefix = `custom_object_definitions.definitions[${String(i)}]`;
172
+ if (!isYamlObject(def) || !isNonEmptyString(def.id)) {
173
+ throw new Error(
174
+ `${prefix}: missing or invalid "id" field. Got: ${JSON.stringify(def)}`
175
+ );
176
+ }
177
+ if (!isYamlObject(def.specification)) {
178
+ throw new Error(
179
+ `${prefix}: missing or invalid "specification" field. Expected: { type: "typescript", content: "path/to/file.ts" }. Got: ${JSON.stringify(def)}`
180
+ );
181
+ }
182
+ if (!isNonEmptyString(def.specification.type)) {
183
+ throw new Error(
184
+ `${prefix}: missing or invalid "specification.type" field. Got: ${JSON.stringify(def)}`
185
+ );
186
+ }
187
+ if (!isNonEmptyString(def.specification.content)) {
188
+ throw new Error(
189
+ `${prefix}: missing or invalid "specification.content" field. Got: ${JSON.stringify(def)}`
190
+ );
191
+ }
192
+ }
193
+ }
194
+ var _ManifestV2 = class __ManifestV2 {
195
+ constructor(filePath, data) {
196
+ this.filePath = filePath;
197
+ this.data = data;
198
+ }
199
+ /**
200
+ * Load stripe-app.yaml from disk
201
+ * @param filePath - Path to stripe-app.yaml
202
+ * @throws Error if file is invalid or cannot be read
203
+ */
204
+ static async load(filePath) {
205
+ try {
206
+ const content = await readFile(filePath, "utf-8");
207
+ const parsed = yaml.parse(content);
208
+ if (!isYamlObject(parsed)) {
209
+ throw new Error("Invalid stripe-app.yaml format: root must be an object");
210
+ }
211
+ validateManifestV2Data(parsed);
212
+ const data = parsed;
213
+ data.extensions ??= [];
214
+ return new __ManifestV2(filePath, data);
215
+ } catch (err) {
216
+ if (err instanceof Error) {
217
+ throw new Error(`Error reading stripe-app.yaml: ${err.message}`);
218
+ }
219
+ throw new Error(`Error reading stripe-app.yaml: ${String(err)}`);
220
+ }
221
+ }
222
+ /**
223
+ * Get the app ID from the manifest
224
+ */
225
+ getAppId() {
226
+ return this.data.id;
227
+ }
228
+ /**
229
+ * Get the app name from the manifest
230
+ */
231
+ getAppName() {
232
+ return this.data.name;
233
+ }
234
+ // ============================================================
235
+ // Custom Objects
236
+ // ============================================================
237
+ /**
238
+ * Get all custom object definitions, parsed into internal format.
239
+ * Entries are guaranteed structurally valid by load-time validation.
240
+ */
241
+ getCustomObjects() {
242
+ const definitions = this.data.custom_object_definitions?.definitions;
243
+ if (!definitions || definitions.length === 0) {
244
+ return [];
245
+ }
246
+ return definitions.map((def) => ({
247
+ id: def.id,
248
+ type: def.specification.type,
249
+ path: def.specification.content,
250
+ name: _toPascalCase(def.id)
251
+ }));
252
+ }
253
+ /**
254
+ * Check if a custom object exists by id
255
+ */
256
+ hasCustomObject(id) {
257
+ const definitions = this.data.custom_object_definitions?.definitions;
258
+ if (!definitions) return false;
259
+ return definitions.some((def) => def.id === id);
260
+ }
261
+ /**
262
+ * Add a custom object definition.
263
+ *
264
+ * Identity is keyed on `id` alone. The export name is derived via
265
+ * `_toPascalCase(id)` at read time, so `id` should be valid snake_case
266
+ * (e.g., "device", "loyalty_card", "http_request").
267
+ *
268
+ * @param id - Object identifier (e.g., "device", "loyalty_card")
269
+ * @param content - Path to the definition file (e.g., "src/device.object.ts")
270
+ * @param type - Specification type, defaults to "typescript"
271
+ * @returns true if added, false if already exists
272
+ */
273
+ addCustomObject(id, content, type = "typescript") {
274
+ if (this.hasCustomObject(id)) {
275
+ return false;
276
+ }
277
+ this.data.custom_object_definitions ??= {};
278
+ this.data.custom_object_definitions.definitions ??= [];
279
+ this.data.custom_object_definitions.definitions.push({
280
+ id,
281
+ specification: { type, content }
282
+ });
283
+ return true;
284
+ }
285
+ /**
286
+ * Remove a custom object definition by id
287
+ * @param id - Object identifier to remove
288
+ * @returns true if removed, false if not found
289
+ */
290
+ removeCustomObject(id) {
291
+ const block = this.data.custom_object_definitions;
292
+ if (!block?.definitions) {
293
+ return false;
294
+ }
295
+ const originalLength = block.definitions.length;
296
+ block.definitions = block.definitions.filter((def) => def.id !== id);
297
+ const newLength = block.definitions.length;
298
+ if (newLength === 0) {
299
+ delete this.data.custom_object_definitions;
300
+ }
301
+ return newLength < originalLength;
302
+ }
303
+ // ============================================================
304
+ // Extensions
305
+ // ============================================================
306
+ /**
307
+ * Add a new extension or update an existing one by ID
308
+ * If an extension with the provided ID exists, it will be replaced entirely
309
+ * @param extension - Extension configuration with all required fields including id
310
+ * @returns The extension ID
311
+ */
312
+ addOrUpdateExtension(extension) {
313
+ const newExtension = {
314
+ id: extension.id,
315
+ name: extension.name,
316
+ interface_id: extension.interface_id,
317
+ version: extension.version,
318
+ ...extension.description !== void 0 && {
319
+ description: extension.description
320
+ },
321
+ ...extension.stripe_version !== void 0 && {
322
+ stripe_version: extension.stripe_version
323
+ },
324
+ ...extension.script_entry_point !== void 0 && {
325
+ script_entry_point: extension.script_entry_point
326
+ },
327
+ ...extension.script !== void 0 && { script: extension.script },
328
+ permissions: extension.permissions,
329
+ methods: extension.methods,
330
+ ...extension.configuration !== void 0 && {
331
+ configuration: extension.configuration
332
+ },
333
+ ...extension.endpoints !== void 0 && {
334
+ endpoints: extension.endpoints
335
+ }
336
+ };
337
+ this.data.extensions ??= [];
338
+ const existingIndex = this.data.extensions.findIndex(
339
+ (ext) => ext.id === extension.id
340
+ );
341
+ if (existingIndex !== -1) {
342
+ this.data.extensions[existingIndex] = newExtension;
343
+ } else {
344
+ this.data.extensions.push(newExtension);
345
+ }
346
+ return extension.id;
347
+ }
348
+ /**
349
+ * Get a read-only view of all extensions
350
+ */
351
+ getExtensions() {
352
+ return this.data.extensions ?? [];
353
+ }
354
+ /**
355
+ * Get the raw manifest data (for reading other fields)
356
+ */
357
+ getRawData() {
358
+ return this.data;
359
+ }
360
+ /**
361
+ * Save changes back to disk
362
+ * @throws Error if file cannot be written
363
+ */
364
+ async save() {
365
+ try {
366
+ const updatedContent = yaml.stringify(this.data);
367
+ await writeFile(this.filePath, updatedContent, "utf-8");
368
+ } catch (err) {
369
+ if (err instanceof Error) {
370
+ throw new Error(`Error writing stripe-app.yaml: ${err.message}`);
371
+ }
372
+ throw new Error(`Error writing stripe-app.yaml: ${String(err)}`);
373
+ }
374
+ }
375
+ };
376
+
377
+ // src/manifest/stripe-app-manifest.ts
378
+ var _StripeAppManifest = class __StripeAppManifest {
379
+ constructor(manifestPath, version, v1, v2) {
380
+ this.manifestPath = manifestPath;
381
+ this.version = version;
382
+ this.v1 = v1;
383
+ this.v2 = v2;
384
+ }
385
+ /**
386
+ * Load a manifest file, automatically detecting the version.
387
+ * @param manifestPath - Path to stripe-app.json or stripe-app.yaml
388
+ * @returns Loaded manifest instance
389
+ */
390
+ static async load(manifestPath) {
391
+ const version = __StripeAppManifest.detectVersion(manifestPath);
392
+ if (version === "v1") {
393
+ const reader = _ManifestV1.load(manifestPath);
394
+ return new __StripeAppManifest(manifestPath, version, reader, null);
395
+ } else {
396
+ const reader = await _ManifestV2.load(manifestPath);
397
+ return new __StripeAppManifest(manifestPath, version, null, reader);
398
+ }
399
+ }
400
+ /**
401
+ * Detect manifest version from file path.
402
+ * TODO: Add content-based detection if needed.
403
+ */
404
+ static detectVersion(manifestPath) {
405
+ const lowerPath = manifestPath.toLowerCase();
406
+ if (lowerPath.endsWith(".yaml") || lowerPath.endsWith(".yml")) {
407
+ return "v2";
408
+ }
409
+ if (lowerPath.endsWith(".json")) {
410
+ return "v1";
411
+ }
412
+ throw new Error(
413
+ `Cannot detect manifest version from path: ${manifestPath}. Expected .json (v1) or .yaml/.yml (v2) extension.`
414
+ );
415
+ }
416
+ /**
417
+ * Get the detected manifest version
418
+ */
419
+ getVersion() {
420
+ return this.version;
421
+ }
422
+ /**
423
+ * Get the manifest file path
424
+ */
425
+ getManifestPath() {
426
+ return this.manifestPath;
427
+ }
428
+ // ============================================================
429
+ // App Metadata (supported by both V1 and V2)
430
+ // ============================================================
431
+ /**
432
+ * Get the app ID from the manifest
433
+ */
434
+ getAppId() {
435
+ if (this.v1) {
436
+ return this.v1.getAppId();
437
+ }
438
+ if (this.v2) {
439
+ return this.v2.getAppId();
440
+ }
441
+ return void 0;
442
+ }
443
+ /**
444
+ * Get the app name from the manifest
445
+ */
446
+ getAppName() {
447
+ if (this.v1) {
448
+ return this.v1.getAppName();
449
+ }
450
+ if (this.v2) {
451
+ return this.v2.getAppName();
452
+ }
453
+ return void 0;
454
+ }
455
+ // ============================================================
456
+ // Custom Objects (supported by both V1 and V2)
457
+ // ============================================================
458
+ /**
459
+ * Get all custom objects from the manifest
460
+ */
461
+ getCustomObjects() {
462
+ if (this.v1) {
463
+ return this.v1.getCustomObjects();
464
+ }
465
+ if (this.v2) {
466
+ return this.v2.getCustomObjects().map((obj) => ({
467
+ filePath: obj.path,
468
+ className: obj.name
469
+ }));
470
+ }
471
+ return [];
472
+ }
473
+ /**
474
+ * Check if a custom object entry exists in the manifest.
475
+ *
476
+ * **V2 note:** Identity is keyed on `_toSnakeCase(className)` alone — `filePath`
477
+ * is not considered. Two entries with the same class name but different file
478
+ * paths are treated as the same object. The `_toSnakeCase` → `_toPascalCase`
479
+ * round-trip is lossless for typical class names but lossy for consecutive
480
+ * uppercase (e.g., `HTTPClient` → `http_client` → `HttpClient`). The manifest
481
+ * `id` field is the source of truth; see `_CustomObjectDefinitionYaml` docs.
482
+ */
483
+ hasCustomObject(entry) {
484
+ if (this.v1) {
485
+ return this.v1.hasCustomObject(entry);
486
+ }
487
+ if (this.v2) {
488
+ return this.v2.hasCustomObject(_toSnakeCase(entry.className));
489
+ }
490
+ return false;
491
+ }
492
+ /**
493
+ * Add a custom object entry to the manifest.
494
+ *
495
+ * **V2 note:** The manifest `id` is derived as `_toSnakeCase(className)` and
496
+ * `filePath` is stored as the specification `content` path. Identity/dedup
497
+ * is based on `id` alone — see `hasCustomObject` for details.
498
+ *
499
+ * @param entry - The custom object entry to add
500
+ * @returns true if entry was added, false if it already existed
501
+ */
502
+ addCustomObject(entry) {
503
+ if (this.v1) {
504
+ return this.v1.addCustomObject(entry);
505
+ }
506
+ if (this.v2) {
507
+ return this.v2.addCustomObject(_toSnakeCase(entry.className), entry.filePath);
508
+ }
509
+ return false;
510
+ }
511
+ /**
512
+ * Remove a custom object entry from the manifest.
513
+ *
514
+ * **V2 note:** Removal is keyed on `_toSnakeCase(className)` — `filePath` is
515
+ * not considered. See `hasCustomObject` for identity semantics.
516
+ *
517
+ * @param entry - The custom object entry to remove
518
+ * @returns true if entry was removed, false if it didn't exist
519
+ */
520
+ removeCustomObject(entry) {
521
+ if (this.v1) {
522
+ return this.v1.removeCustomObject(entry);
523
+ }
524
+ if (this.v2) {
525
+ return this.v2.removeCustomObject(_toSnakeCase(entry.className));
526
+ }
527
+ return false;
528
+ }
529
+ // ============================================================
530
+ // Extensions (V2 only)
531
+ // ============================================================
532
+ /**
533
+ * Get all extensions from the manifest
534
+ * @throws Error if manifest version doesn't support extensions
535
+ */
536
+ getExtensions() {
537
+ if (this.v2) {
538
+ return this.v2.getExtensions();
539
+ }
540
+ throw new Error("Extensions are not supported in V1 manifests (stripe-app.json)");
541
+ }
542
+ /**
543
+ * Add or update an extension in the manifest.
544
+ * If an extension with the same ID exists, it will be replaced.
545
+ *
546
+ * @param config - Full extension configuration
547
+ * @returns The extension ID
548
+ * @throws Error if manifest version doesn't support extensions
549
+ */
550
+ addOrUpdateExtension(config) {
551
+ if (this.v2) {
552
+ return this.v2.addOrUpdateExtension(config);
553
+ }
554
+ throw new Error("Extensions are not supported in V1 manifests (stripe-app.json)");
555
+ }
556
+ // ============================================================
557
+ // Persistence
558
+ // ============================================================
559
+ /**
560
+ * Save changes back to disk
561
+ */
562
+ async save() {
563
+ if (this.v1) {
564
+ this.v1.save();
565
+ return;
566
+ }
567
+ if (this.v2) {
568
+ await this.v2.save();
569
+ return;
570
+ }
571
+ throw new Error("No reader loaded - this should never happen");
572
+ }
573
+ };
574
+
575
+ // src/bin/manifest.ts
576
+ var logger = _createLogger({ name: "manifest" });
577
+ function requireV2Manifest(manifestPath) {
578
+ const lower = manifestPath.toLowerCase();
579
+ if (!lower.endsWith(".yaml") && !lower.endsWith(".yml")) {
580
+ throw new Error(
581
+ `This CLI requires a V2 manifest (stripe-app.yaml). Got: ${manifestPath}`
582
+ );
583
+ }
584
+ }
585
+ async function main() {
586
+ await yargs(hideBin(process.argv)).usage("Manage Stripe app manifests").help().version(false).demandCommand(1, "Specify a subcommand: read, add-custom-object").command(
587
+ "read",
588
+ "Read manifest contents",
589
+ (y) => y.option("path", {
590
+ type: "string",
591
+ description: "Path to stripe-app.yaml (V2 manifest)",
592
+ demandOption: true
593
+ }).option("output-path", {
594
+ type: "string",
595
+ description: "Write JSON result to this file instead of stdout"
596
+ }),
597
+ async (args) => {
598
+ requireV2Manifest(args.path);
599
+ const manifest = await _StripeAppManifest.load(args.path);
600
+ const result = {
601
+ appId: manifest.getAppId(),
602
+ appName: manifest.getAppName(),
603
+ customObjects: manifest.getCustomObjects()
604
+ };
605
+ if (args.outputPath) {
606
+ _writeJsonOutput(args.outputPath, result);
607
+ } else {
608
+ process.stdout.write(JSON.stringify(result, null, 2) + "\n");
609
+ }
610
+ }
611
+ ).command(
612
+ "add-custom-object",
613
+ "Add or update a custom object in the manifest (idempotent)",
614
+ (y) => y.option("path", {
615
+ type: "string",
616
+ description: "Path to stripe-app.yaml (V2 manifest)",
617
+ demandOption: true
618
+ }).option("file-path", {
619
+ type: "string",
620
+ description: "Source file path of the custom object",
621
+ demandOption: true
622
+ }).option("class-name", {
623
+ type: "string",
624
+ description: "Class name of the custom object",
625
+ demandOption: true
626
+ }).option("output-path", {
627
+ type: "string",
628
+ description: "Write JSON result to this file instead of stdout"
629
+ }),
630
+ async (args) => {
631
+ requireV2Manifest(args.path);
632
+ const manifest = await _StripeAppManifest.load(args.path);
633
+ const entry = {
634
+ filePath: args.filePath,
635
+ className: args.className
636
+ };
637
+ let outcome;
638
+ const existing = manifest.getCustomObjects().find((co) => co.className === entry.className);
639
+ if (existing?.filePath === entry.filePath) {
640
+ outcome = "unchanged";
641
+ } else if (existing) {
642
+ manifest.removeCustomObject(existing);
643
+ manifest.addCustomObject(entry);
644
+ await manifest.save();
645
+ outcome = "updated";
646
+ } else {
647
+ manifest.addCustomObject(entry);
648
+ await manifest.save();
649
+ outcome = "added";
650
+ }
651
+ const result = { outcome };
652
+ if (args.outputPath) {
653
+ _writeJsonOutput(args.outputPath, result);
654
+ } else {
655
+ process.stdout.write(JSON.stringify(result, null, 2) + "\n");
656
+ }
657
+ }
658
+ ).parse();
659
+ }
660
+ main().catch((err) => {
661
+ logger.error({ err }, "Unexpected error");
662
+ process.exit(1);
663
+ });
@@ -0,0 +1,10 @@
1
+ import type { RpcHandler, RpcResponse } from './types.js';
2
+ /**
3
+ * Dispatch an RPC request to the appropriate handler.
4
+ *
5
+ * Accepts `unknown` because the input comes from untrusted JSON;
6
+ * performs runtime validation before routing.
7
+ * @internal
8
+ */
9
+ export declare function dispatch(request: unknown, methods: Map<string, RpcHandler>): Promise<RpcResponse>;
10
+ //# sourceMappingURL=dispatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../../src/bin/rpc/dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG1D;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,GAC/B,OAAO,CAAC,WAAW,CAAC,CAkCtB"}
@@ -0,0 +1,4 @@
1
+ import type { RpcHandler } from './types.js';
2
+ /** @internal */
3
+ export declare const methods: Map<string, RpcHandler>;
4
+ //# sourceMappingURL=handlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../../src/bin/rpc/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA6B7C,gBAAgB;AAChB,eAAO,MAAM,OAAO,yBAGlB,CAAC"}