spaps 0.3.6 → 0.3.7

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/local-server.js +40 -39
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spaps",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "Sweet Potato Authentication & Payment Service CLI - Zero-config local development and project scaffolding",
5
5
  "main": "bin/spaps.js",
6
6
  "bin": {
@@ -359,51 +359,52 @@ class LocalServer {
359
359
 
360
360
  for (const product of localProducts) {
361
361
  try {
362
- // Check if product already exists in Stripe
362
+ // Check if product already exists in Stripe by searching metadata
363
363
  let stripeProduct;
364
- try {
365
- stripeProduct = await stripe.products.retrieve(product.id);
366
- } catch (error) {
367
- if (error.code === 'resource_missing') {
368
- // Create new product in Stripe
369
- stripeProduct = await stripe.products.create({
370
- id: product.id,
371
- name: product.name,
372
- description: product.description,
373
- metadata: {
374
- spaps_managed: 'true',
375
- created_by: 'spaps_admin'
376
- }
377
- });
378
-
379
- // Create corresponding price
380
- await stripe.prices.create({
381
- id: product.price_id,
382
- product: stripeProduct.id,
383
- unit_amount: product.price,
384
- currency: product.currency,
385
- metadata: {
386
- spaps_managed: 'true'
387
- }
388
- });
389
-
390
- syncResults.push({
391
- id: product.id,
392
- name: product.name,
393
- action: 'created',
394
- stripe_id: stripeProduct.id
395
- });
396
- } else {
397
- throw error;
398
- }
399
- }
364
+ const existingProducts = await stripe.products.list({
365
+ limit: 100,
366
+ expand: ['data.default_price']
367
+ });
368
+
369
+ stripeProduct = existingProducts.data.find(p =>
370
+ p.metadata && p.metadata.spaps_id === product.id
371
+ );
372
+
373
+ if (!stripeProduct) {
374
+ // Create new product in Stripe
375
+ stripeProduct = await stripe.products.create({
376
+ name: product.name,
377
+ description: product.description,
378
+ metadata: {
379
+ spaps_managed: 'true',
380
+ created_by: 'spaps_admin',
381
+ spaps_id: product.id
382
+ }
383
+ });
400
384
 
401
- if (stripeProduct && !syncResults.find(r => r.id === product.id)) {
385
+ // Create corresponding price
386
+ await stripe.prices.create({
387
+ product: stripeProduct.id,
388
+ unit_amount: product.price,
389
+ currency: product.currency,
390
+ metadata: {
391
+ spaps_managed: 'true',
392
+ spaps_price_id: product.price_id
393
+ }
394
+ });
395
+
396
+ syncResults.push({
397
+ id: product.id,
398
+ name: product.name,
399
+ action: 'created',
400
+ stripe_id: stripeProduct.id
401
+ });
402
+ } else {
402
403
  // Update existing product
403
404
  await stripe.products.update(stripeProduct.id, {
404
405
  name: product.name,
405
406
  description: product.description,
406
- active: product.active
407
+ active: product.active !== false
407
408
  });
408
409
 
409
410
  syncResults.push({