@executor-js/emulate 0.6.0 → 0.7.0

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.
@@ -123,9 +123,9 @@ function applyExpand(obj, expandPaths, resolvers) {
123
123
  const result = { ...obj };
124
124
  for (const path of expandPaths) {
125
125
  const resolver = resolvers[path];
126
- const id = result[path];
127
- if (resolver && typeof id === "string") {
128
- const expanded = resolver(id);
126
+ const id2 = result[path];
127
+ if (resolver && typeof id2 === "string") {
128
+ const expanded = resolver(id2);
129
129
  if (expanded) {
130
130
  result[path] = expanded;
131
131
  }
@@ -258,8 +258,8 @@ function customerRoutes({ app, store, webhooks }) {
258
258
  function paymentIntentRoutes({ app, store, webhooks }) {
259
259
  const ss = getStripeStore(store);
260
260
  const expandResolvers = {
261
- customer: (id) => {
262
- const cust = ss.customers.findOneBy("stripe_id", id);
261
+ customer: (id2) => {
262
+ const cust = ss.customers.findOneBy("stripe_id", id2);
263
263
  return cust ? formatCustomer(cust) : void 0;
264
264
  }
265
265
  };
@@ -482,12 +482,12 @@ function formatCharge(ch) {
482
482
  function chargeRoutes({ app, store }) {
483
483
  const ss = getStripeStore(store);
484
484
  const expandResolvers = {
485
- customer: (id) => {
486
- const cust = ss.customers.findOneBy("stripe_id", id);
485
+ customer: (id2) => {
486
+ const cust = ss.customers.findOneBy("stripe_id", id2);
487
487
  return cust ? formatCustomer(cust) : void 0;
488
488
  },
489
- payment_intent: (id) => {
490
- const pi = ss.paymentIntents.findOneBy("stripe_id", id);
489
+ payment_intent: (id2) => {
490
+ const pi = ss.paymentIntents.findOneBy("stripe_id", id2);
491
491
  return pi ? formatPaymentIntent(pi) : void 0;
492
492
  }
493
493
  };
@@ -587,8 +587,8 @@ function formatProduct2(p) {
587
587
  function priceRoutes({ app, store, webhooks }) {
588
588
  const ss = getStripeStore(store);
589
589
  const expandResolvers = {
590
- product: (id) => {
591
- const prod = ss.products.findOneBy("stripe_id", id);
590
+ product: (id2) => {
591
+ const prod = ss.products.findOneBy("stripe_id", id2);
592
592
  return prod ? formatProduct2(prod) : void 0;
593
593
  }
594
594
  };
@@ -1301,6 +1301,349 @@ function customerSessionRoutes({ app, store }) {
1301
1301
  );
1302
1302
  });
1303
1303
  }
1304
+ function openapiRoutes({ app, baseUrl }) {
1305
+ app.get("/openapi.json", (c) => c.json(buildSpec(baseUrl)));
1306
+ }
1307
+ var ok = (description) => ({
1308
+ description,
1309
+ content: { "application/json": { schema: { type: "object" } } }
1310
+ });
1311
+ var id = { name: "id", in: "path", required: true, schema: { type: "string" } };
1312
+ var metadata = { type: "object", additionalProperties: { type: "string" } };
1313
+ var formBody = (properties, required, description) => ({
1314
+ required: required.length > 0,
1315
+ description,
1316
+ content: {
1317
+ "application/x-www-form-urlencoded": {
1318
+ schema: { type: "object", properties, required: [...required] }
1319
+ }
1320
+ }
1321
+ });
1322
+ function buildSpec(baseUrl) {
1323
+ return {
1324
+ openapi: "3.1.0",
1325
+ info: {
1326
+ title: "Stripe API (Emulated)",
1327
+ version: "1.0.0",
1328
+ description: "Emulated subset of the Stripe REST API. Authenticate with a bearer secret API key (mint one at POST /_emulate/credentials). Request bodies are application/x-www-form-urlencoded."
1329
+ },
1330
+ servers: [{ url: baseUrl }],
1331
+ components: {
1332
+ securitySchemes: {
1333
+ bearerAuth: {
1334
+ type: "http",
1335
+ scheme: "bearer",
1336
+ description: "Stripe secret API key, sent as `Authorization: Bearer \u2026`."
1337
+ }
1338
+ }
1339
+ },
1340
+ security: [{ bearerAuth: [] }],
1341
+ paths: {
1342
+ "/v1/customers": {
1343
+ post: {
1344
+ operationId: "PostCustomers",
1345
+ tags: ["customers"],
1346
+ summary: "Create a customer",
1347
+ requestBody: formBody(
1348
+ {
1349
+ email: { type: "string" },
1350
+ name: { type: "string" },
1351
+ description: { type: "string" },
1352
+ metadata
1353
+ },
1354
+ [],
1355
+ "The customer to create."
1356
+ ),
1357
+ responses: { "200": ok("The created customer.") }
1358
+ },
1359
+ get: {
1360
+ operationId: "GetCustomers",
1361
+ tags: ["customers"],
1362
+ summary: "List customers",
1363
+ responses: { "200": ok("Customer list.") }
1364
+ }
1365
+ },
1366
+ "/v1/customers/{id}": {
1367
+ get: {
1368
+ operationId: "GetCustomersCustomer",
1369
+ tags: ["customers"],
1370
+ summary: "Retrieve a customer",
1371
+ parameters: [id],
1372
+ responses: { "200": ok("The customer."), "404": ok("Not found.") }
1373
+ },
1374
+ post: {
1375
+ operationId: "PostCustomersCustomer",
1376
+ tags: ["customers"],
1377
+ summary: "Update a customer",
1378
+ parameters: [id],
1379
+ requestBody: formBody(
1380
+ {
1381
+ email: { type: "string" },
1382
+ name: { type: "string" },
1383
+ description: { type: "string" },
1384
+ metadata
1385
+ },
1386
+ [],
1387
+ "The fields to update."
1388
+ ),
1389
+ responses: { "200": ok("The updated customer."), "404": ok("Not found.") }
1390
+ },
1391
+ delete: {
1392
+ operationId: "DeleteCustomersCustomer",
1393
+ tags: ["customers"],
1394
+ summary: "Delete a customer",
1395
+ parameters: [id],
1396
+ responses: { "200": ok("Deletion confirmation."), "404": ok("Not found.") }
1397
+ }
1398
+ },
1399
+ "/v1/customer_sessions": {
1400
+ post: {
1401
+ operationId: "PostCustomerSessions",
1402
+ tags: ["customers"],
1403
+ summary: "Create a customer session",
1404
+ requestBody: formBody(
1405
+ { customer: { type: "string" }, components: { type: "object" } },
1406
+ ["customer"],
1407
+ "The customer session to create."
1408
+ ),
1409
+ responses: { "200": ok("The created customer session."), "400": ok("Validation error.") }
1410
+ }
1411
+ },
1412
+ "/v1/payment_intents": {
1413
+ post: {
1414
+ operationId: "PostPaymentIntents",
1415
+ tags: ["payment_intents"],
1416
+ summary: "Create a payment intent",
1417
+ requestBody: formBody(
1418
+ {
1419
+ amount: { type: "integer" },
1420
+ currency: { type: "string" },
1421
+ customer: { type: "string" },
1422
+ description: { type: "string" },
1423
+ payment_method: { type: "string" },
1424
+ metadata
1425
+ },
1426
+ ["amount", "currency"],
1427
+ "The payment intent to create."
1428
+ ),
1429
+ responses: { "200": ok("The created payment intent."), "400": ok("Validation error.") }
1430
+ },
1431
+ get: {
1432
+ operationId: "GetPaymentIntents",
1433
+ tags: ["payment_intents"],
1434
+ summary: "List payment intents",
1435
+ responses: { "200": ok("Payment intent list.") }
1436
+ }
1437
+ },
1438
+ "/v1/payment_intents/{id}": {
1439
+ get: {
1440
+ operationId: "GetPaymentIntentsIntent",
1441
+ tags: ["payment_intents"],
1442
+ summary: "Retrieve a payment intent",
1443
+ parameters: [id],
1444
+ responses: { "200": ok("The payment intent."), "404": ok("Not found.") }
1445
+ },
1446
+ post: {
1447
+ operationId: "PostPaymentIntentsIntent",
1448
+ tags: ["payment_intents"],
1449
+ summary: "Update a payment intent",
1450
+ parameters: [id],
1451
+ requestBody: formBody(
1452
+ {
1453
+ amount: { type: "integer" },
1454
+ currency: { type: "string" },
1455
+ description: { type: "string" },
1456
+ payment_method: { type: "string" },
1457
+ metadata
1458
+ },
1459
+ [],
1460
+ "The fields to update."
1461
+ ),
1462
+ responses: { "200": ok("The updated payment intent."), "404": ok("Not found.") }
1463
+ }
1464
+ },
1465
+ "/v1/payment_intents/{id}/confirm": {
1466
+ post: {
1467
+ operationId: "PostPaymentIntentsIntentConfirm",
1468
+ tags: ["payment_intents"],
1469
+ summary: "Confirm a payment intent",
1470
+ parameters: [id],
1471
+ requestBody: formBody(
1472
+ { payment_method: { type: "string" } },
1473
+ [],
1474
+ "Optional payment method to attach before confirming."
1475
+ ),
1476
+ responses: {
1477
+ "200": ok("The confirmed payment intent."),
1478
+ "400": ok("Unexpected state."),
1479
+ "404": ok("Not found.")
1480
+ }
1481
+ }
1482
+ },
1483
+ "/v1/payment_intents/{id}/cancel": {
1484
+ post: {
1485
+ operationId: "PostPaymentIntentsIntentCancel",
1486
+ tags: ["payment_intents"],
1487
+ summary: "Cancel a payment intent",
1488
+ parameters: [id],
1489
+ responses: {
1490
+ "200": ok("The canceled payment intent."),
1491
+ "400": ok("Unexpected state."),
1492
+ "404": ok("Not found.")
1493
+ }
1494
+ }
1495
+ },
1496
+ "/v1/payment_methods": {
1497
+ get: {
1498
+ operationId: "GetPaymentMethods",
1499
+ tags: ["payment_methods"],
1500
+ summary: "List payment methods (seeded test data only)",
1501
+ responses: { "200": ok("Payment method list."), "400": ok("Validation error.") }
1502
+ }
1503
+ },
1504
+ "/v1/charges/{id}": {
1505
+ get: {
1506
+ operationId: "GetChargesCharge",
1507
+ tags: ["charges"],
1508
+ summary: "Retrieve a charge",
1509
+ parameters: [id],
1510
+ responses: { "200": ok("The charge."), "404": ok("Not found.") }
1511
+ }
1512
+ },
1513
+ "/v1/charges": {
1514
+ get: {
1515
+ operationId: "GetCharges",
1516
+ tags: ["charges"],
1517
+ summary: "List charges",
1518
+ responses: { "200": ok("Charge list.") }
1519
+ }
1520
+ },
1521
+ "/v1/products": {
1522
+ post: {
1523
+ operationId: "PostProducts",
1524
+ tags: ["products"],
1525
+ summary: "Create a product",
1526
+ requestBody: formBody(
1527
+ {
1528
+ name: { type: "string" },
1529
+ description: { type: "string" },
1530
+ active: { type: "boolean" },
1531
+ metadata
1532
+ },
1533
+ ["name"],
1534
+ "The product to create."
1535
+ ),
1536
+ responses: { "200": ok("The created product."), "400": ok("Validation error.") }
1537
+ },
1538
+ get: {
1539
+ operationId: "GetProducts",
1540
+ tags: ["products"],
1541
+ summary: "List products",
1542
+ responses: { "200": ok("Product list.") }
1543
+ }
1544
+ },
1545
+ "/v1/products/{id}": {
1546
+ get: {
1547
+ operationId: "GetProductsId",
1548
+ tags: ["products"],
1549
+ summary: "Retrieve a product",
1550
+ parameters: [id],
1551
+ responses: { "200": ok("The product."), "404": ok("Not found.") }
1552
+ }
1553
+ },
1554
+ "/v1/prices": {
1555
+ post: {
1556
+ operationId: "PostPrices",
1557
+ tags: ["prices"],
1558
+ summary: "Create a price",
1559
+ requestBody: formBody(
1560
+ {
1561
+ currency: { type: "string" },
1562
+ product: { type: "string" },
1563
+ unit_amount: { type: "integer" },
1564
+ recurring: { type: "object" },
1565
+ active: { type: "boolean" },
1566
+ metadata
1567
+ },
1568
+ ["currency", "product"],
1569
+ "The price to create."
1570
+ ),
1571
+ responses: { "200": ok("The created price."), "400": ok("Validation error.") }
1572
+ },
1573
+ get: {
1574
+ operationId: "GetPrices",
1575
+ tags: ["prices"],
1576
+ summary: "List prices",
1577
+ responses: { "200": ok("Price list.") }
1578
+ }
1579
+ },
1580
+ "/v1/prices/{id}": {
1581
+ get: {
1582
+ operationId: "GetPricesPrice",
1583
+ tags: ["prices"],
1584
+ summary: "Retrieve a price",
1585
+ parameters: [id],
1586
+ responses: { "200": ok("The price."), "404": ok("Not found.") }
1587
+ }
1588
+ },
1589
+ "/v1/checkout/sessions": {
1590
+ post: {
1591
+ operationId: "PostCheckoutSessions",
1592
+ tags: ["checkout"],
1593
+ summary: "Create a checkout session",
1594
+ requestBody: formBody(
1595
+ {
1596
+ mode: { type: "string", enum: ["payment", "setup", "subscription"] },
1597
+ customer: { type: "string" },
1598
+ success_url: { type: "string" },
1599
+ cancel_url: { type: "string" },
1600
+ line_items: {
1601
+ type: "array",
1602
+ items: {
1603
+ type: "object",
1604
+ properties: { price: { type: "string" }, quantity: { type: "integer" } },
1605
+ required: ["price"]
1606
+ }
1607
+ },
1608
+ metadata
1609
+ },
1610
+ ["mode"],
1611
+ "The checkout session to create."
1612
+ ),
1613
+ responses: { "200": ok("The created checkout session."), "400": ok("Validation error.") }
1614
+ },
1615
+ get: {
1616
+ operationId: "GetCheckoutSessions",
1617
+ tags: ["checkout"],
1618
+ summary: "List checkout sessions",
1619
+ responses: { "200": ok("Checkout session list.") }
1620
+ }
1621
+ },
1622
+ "/v1/checkout/sessions/{id}": {
1623
+ get: {
1624
+ operationId: "GetCheckoutSessionsSession",
1625
+ tags: ["checkout"],
1626
+ summary: "Retrieve a checkout session",
1627
+ parameters: [id],
1628
+ responses: { "200": ok("The checkout session."), "404": ok("Not found.") }
1629
+ }
1630
+ },
1631
+ "/v1/checkout/sessions/{id}/expire": {
1632
+ post: {
1633
+ operationId: "PostCheckoutSessionsSessionExpire",
1634
+ tags: ["checkout"],
1635
+ summary: "Expire an open checkout session",
1636
+ parameters: [id],
1637
+ responses: {
1638
+ "200": ok("The expired checkout session."),
1639
+ "400": ok("Session not open."),
1640
+ "404": ok("Not found.")
1641
+ }
1642
+ }
1643
+ }
1644
+ }
1645
+ };
1646
+ }
1304
1647
  var manifest = {
1305
1648
  id: "stripe",
1306
1649
  name: "Stripe",
@@ -1320,6 +1663,7 @@ var manifest = {
1320
1663
  kind: "openapi",
1321
1664
  title: "Stripe API subset",
1322
1665
  coverage: "hand-authored",
1666
+ url: "/openapi.json",
1323
1667
  operations: [
1324
1668
  { operationId: "PostCustomers", method: "POST", path: "/v1/customers", status: "hand-authored" },
1325
1669
  { operationId: "GetCustomersCustomer", method: "GET", path: "/v1/customers/:id", status: "hand-authored" },
@@ -1554,6 +1898,7 @@ var stripePlugin = {
1554
1898
  priceRoutes(ctx);
1555
1899
  checkoutSessionRoutes(ctx);
1556
1900
  customerSessionRoutes(ctx);
1901
+ openapiRoutes(ctx);
1557
1902
  },
1558
1903
  seed(store, baseUrl) {
1559
1904
  seedDefaults(store, baseUrl);
@@ -1567,4 +1912,4 @@ export {
1567
1912
  seedFromConfig,
1568
1913
  stripePlugin
1569
1914
  };
1570
- //# sourceMappingURL=dist-K4CVTD6K.js.map
1915
+ //# sourceMappingURL=dist-KBZ6SM7D.js.map