atmn 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -44671,11 +44671,18 @@ var init_planItem = __esm(() => {
44671
44671
  return;
44672
44672
  return {
44673
44673
  amount: api.price.amount,
44674
- tiers: api.price.tiers,
44674
+ tiers: api.price.tiers?.map((tier) => {
44675
+ const t = tier;
44676
+ return {
44677
+ to: t.to,
44678
+ amount: t.amount,
44679
+ ...t.flat_amount !== undefined && { flatAmount: t.flat_amount }
44680
+ };
44681
+ }),
44675
44682
  billingUnits: api.price.billing_units,
44676
44683
  maxPurchase: api.price.max_purchase ?? undefined,
44677
44684
  billingMethod: api.price.billing_method,
44678
- tierBehaviour: api.price.tier_behaviour,
44685
+ tierBehavior: api.price.tier_behavior,
44679
44686
  interval: api.price.interval,
44680
44687
  ...api.price.interval_count !== undefined && {
44681
44688
  intervalCount: api.price.interval_count
@@ -44903,6 +44910,23 @@ function planIdToVarName(id) {
44903
44910
  function featureIdToVarName(id) {
44904
44911
  return idToVarName(id, "feature_");
44905
44912
  }
44913
+ function resolveVarNames(featureIds, planIds) {
44914
+ const featureVarMap = new Map;
44915
+ const planVarMap = new Map;
44916
+ for (const id of featureIds) {
44917
+ featureVarMap.set(id, featureIdToVarName(id));
44918
+ }
44919
+ const usedNames = new Set(featureVarMap.values());
44920
+ for (const id of planIds) {
44921
+ let varName = planIdToVarName(id);
44922
+ if (usedNames.has(varName)) {
44923
+ varName = `${varName}_plan`;
44924
+ }
44925
+ planVarMap.set(id, varName);
44926
+ usedNames.add(varName);
44927
+ }
44928
+ return { featureVarMap, planVarMap };
44929
+ }
44906
44930
  function escapeString(str) {
44907
44931
  return str.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/"/g, "\\\"").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
44908
44932
  }
@@ -44933,8 +44957,8 @@ function formatValue(value) {
44933
44957
  }
44934
44958
 
44935
44959
  // src/lib/transforms/sdkToCode/feature.ts
44936
- function buildFeatureCode(feature) {
44937
- const varName = featureIdToVarName(feature.id);
44960
+ function buildFeatureCode(feature, varNameOverride) {
44961
+ const varName = varNameOverride ?? featureIdToVarName(feature.id);
44938
44962
  const lines = [];
44939
44963
  lines.push(`export const ${varName} = feature({`);
44940
44964
  lines.push(` id: '${feature.id}',`);
@@ -45005,8 +45029,8 @@ function buildPlanItemCode(planItem, _features, featureVarMap) {
45005
45029
  if (priceWithBilling.maxPurchase !== undefined) {
45006
45030
  lines.push(` maxPurchase: ${priceWithBilling.maxPurchase},`);
45007
45031
  }
45008
- if (priceWithBilling.tierBehaviour !== undefined) {
45009
- lines.push(` tierBehaviour: '${priceWithBilling.tierBehaviour}',`);
45032
+ if (priceWithBilling.tierBehavior !== undefined) {
45033
+ lines.push(` tierBehavior: '${priceWithBilling.tierBehavior}',`);
45010
45034
  }
45011
45035
  const priceWithInterval = planItem.price;
45012
45036
  if (priceWithInterval.interval) {
@@ -45030,8 +45054,8 @@ function buildPlanItemCode(planItem, _features, featureVarMap) {
45030
45054
  var init_planItem2 = () => {};
45031
45055
 
45032
45056
  // src/lib/transforms/sdkToCode/plan.ts
45033
- function buildPlanCode(plan, features, featureVarMap) {
45034
- const varName = planIdToVarName(plan.id);
45057
+ function buildPlanCode(plan, features, featureVarMap, varNameOverride) {
45058
+ const varName = varNameOverride ?? planIdToVarName(plan.id);
45035
45059
  const lines = [];
45036
45060
  lines.push(`export const ${varName} = plan({`);
45037
45061
  lines.push(` id: '${plan.id}',`);
@@ -45076,18 +45100,10 @@ var init_plan2 = __esm(() => {
45076
45100
  // src/lib/transforms/inPlaceUpdate/updateConfig.ts
45077
45101
  import { existsSync as existsSync4, writeFileSync as writeFileSync2 } from "node:fs";
45078
45102
  function generateFeatureCode(feature, existingVarName) {
45079
- const code = buildFeatureCode(feature);
45080
- if (existingVarName) {
45081
- return code.replace(/export const \w+/, `export const ${existingVarName}`);
45082
- }
45083
- return code;
45103
+ return buildFeatureCode(feature, existingVarName);
45084
45104
  }
45085
45105
  function generatePlanCode(plan, features, existingVarName, featureVarMap) {
45086
- const code = buildPlanCode(plan, features, featureVarMap);
45087
- if (existingVarName) {
45088
- return code.replace(/export const \w+/, `export const ${existingVarName}`);
45089
- }
45090
- return code;
45106
+ return buildPlanCode(plan, features, featureVarMap, existingVarName);
45091
45107
  }
45092
45108
  async function updateConfigInPlace(features, plans, cwd2 = process.cwd()) {
45093
45109
  const configPath = resolveConfigPath(cwd2);
@@ -45111,6 +45127,30 @@ async function updateConfigInPlace(features, plans, cwd2 = process.cwd()) {
45111
45127
  featureVarMap.set(entity.id, entity.varName);
45112
45128
  }
45113
45129
  }
45130
+ const existingVarNames = new Set(parsed.entities.map((e) => e.varName));
45131
+ const newFeatureIds = features.filter((f) => !featureVarMap.has(f.id)).map((f) => f.id);
45132
+ const newFeatureVarMap = new Map;
45133
+ for (const id of newFeatureIds) {
45134
+ const { featureVarMap: resolved } = resolveVarNames([id], []);
45135
+ let varName = resolved.get(id);
45136
+ if (existingVarNames.has(varName)) {
45137
+ varName = `${varName}_feature`;
45138
+ }
45139
+ newFeatureVarMap.set(id, varName);
45140
+ existingVarNames.add(varName);
45141
+ featureVarMap.set(id, varName);
45142
+ }
45143
+ const existingPlanIds = new Set(parsed.entities.filter((e) => e.type === "plan").map((e) => e.id));
45144
+ const newPlanIds = plans.filter((p) => !existingPlanIds.has(p.id)).map((p) => p.id);
45145
+ const newPlanVarMap = new Map;
45146
+ for (const id of newPlanIds) {
45147
+ let varName = planIdToVarName(id);
45148
+ if (existingVarNames.has(varName)) {
45149
+ varName = `${varName}_plan`;
45150
+ }
45151
+ newPlanVarMap.set(id, varName);
45152
+ existingVarNames.add(varName);
45153
+ }
45114
45154
  const matchedFeatureIds = new Set;
45115
45155
  const matchedPlanIds = new Set;
45116
45156
  const outputBlocks = [];
@@ -45202,7 +45242,7 @@ async function updateConfigInPlace(features, plans, cwd2 = process.cwd()) {
45202
45242
  }
45203
45243
  const newFeatures = features.filter((f) => !matchedFeatureIds.has(f.id));
45204
45244
  if (newFeatures.length > 0) {
45205
- const newFeatureCode = newFeatures.map((f) => generateFeatureCode(f)).join(`
45245
+ const newFeatureCode = newFeatures.map((f) => generateFeatureCode(f, newFeatureVarMap.get(f.id))).join(`
45206
45246
 
45207
45247
  `);
45208
45248
  if (lastFeatureBlockIndex >= 0) {
@@ -45242,7 +45282,7 @@ ${newFeatureCode}`);
45242
45282
  }
45243
45283
  const newPlans = plans.filter((p) => !matchedPlanIds.has(p.id));
45244
45284
  if (newPlans.length > 0) {
45245
- const newPlanCode = newPlans.map((p) => generatePlanCode(p, features, undefined, featureVarMap)).join(`
45285
+ const newPlanCode = newPlans.map((p) => generatePlanCode(p, features, featureVarMap, newPlanVarMap.get(p.id))).join(`
45246
45286
 
45247
45287
  `);
45248
45288
  if (lastPlanBlockIndex >= 0) {
@@ -45300,19 +45340,20 @@ var init_inPlaceUpdate = __esm(() => {
45300
45340
  // src/lib/transforms/sdkToCode/configFile.ts
45301
45341
  function buildConfigFile(features, plans) {
45302
45342
  const sections = [];
45343
+ const { featureVarMap, planVarMap } = resolveVarNames(features.map((f) => f.id), plans.map((p) => p.id));
45303
45344
  sections.push(buildImports());
45304
45345
  sections.push("");
45305
45346
  if (features.length > 0) {
45306
45347
  sections.push("// Features");
45307
45348
  for (const feature of features) {
45308
- sections.push(buildFeatureCode(feature));
45349
+ sections.push(buildFeatureCode(feature, featureVarMap.get(feature.id)));
45309
45350
  sections.push("");
45310
45351
  }
45311
45352
  }
45312
45353
  if (plans.length > 0) {
45313
45354
  sections.push("// Plans");
45314
45355
  for (const plan of plans) {
45315
- sections.push(buildPlanCode(plan, features));
45356
+ sections.push(buildPlanCode(plan, features, featureVarMap, planVarMap.get(plan.id)));
45316
45357
  sections.push("");
45317
45358
  }
45318
45359
  }
@@ -45512,7 +45553,7 @@ var init_pull = __esm(() => {
45512
45553
  });
45513
45554
 
45514
45555
  // src/lib/version.ts
45515
- var APP_VERSION = "1.1.0";
45556
+ var APP_VERSION = "1.1.2";
45516
45557
 
45517
45558
  // ../node_modules/.pnpm/@tanstack+query-core@5.90.17/node_modules/@tanstack/query-core/build/modern/subscribable.js
45518
45559
  var Subscribable = class {
@@ -61961,15 +62002,24 @@ function transformPlanItem(planItem) {
61961
62002
  ...planItem.price.amount !== undefined && {
61962
62003
  amount: planItem.price.amount
61963
62004
  },
61964
- ...planItem.price.tiers && { tiers: planItem.price.tiers },
62005
+ ...planItem.price.tiers && {
62006
+ tiers: planItem.price.tiers.map((tier) => {
62007
+ const t = tier;
62008
+ return {
62009
+ to: t.to,
62010
+ amount: t.amount,
62011
+ ...t.flatAmount !== undefined && { flat_amount: t.flatAmount }
62012
+ };
62013
+ })
62014
+ },
61965
62015
  ...intervalCount !== undefined && {
61966
62016
  interval_count: intervalCount
61967
62017
  },
61968
62018
  ...priceWithBilling.maxPurchase !== undefined && {
61969
62019
  max_purchase: priceWithBilling.maxPurchase
61970
62020
  },
61971
- ...priceWithBilling.tierBehaviour !== undefined && {
61972
- tier_behaviour: priceWithBilling.tierBehaviour
62021
+ ...priceWithBilling.tierBehavior !== undefined && {
62022
+ tier_behavior: priceWithBilling.tierBehavior
61973
62023
  }
61974
62024
  };
61975
62025
  }
@@ -17,7 +17,7 @@ export declare const PlanItemSchema: z.ZodObject<{
17
17
  to: z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"inf">]>;
18
18
  amount: z.ZodNumber;
19
19
  }, z.core.$strip>>>;
20
- tier_behaviour: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"graduated">, z.ZodLiteral<"volume">]>>;
20
+ tier_behavior: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"graduated">, z.ZodLiteral<"volume">]>>;
21
21
  interval: z.ZodUnion<readonly [z.ZodLiteral<"week">, z.ZodLiteral<"month">, z.ZodLiteral<"quarter">, z.ZodLiteral<"semi_annual">, z.ZodLiteral<"year">]>;
22
22
  interval_count: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
23
23
  billing_units: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
@@ -65,7 +65,7 @@ export declare const PlanSchema: z.ZodObject<{
65
65
  to: z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"inf">]>;
66
66
  amount: z.ZodNumber;
67
67
  }, z.core.$strip>>>;
68
- tier_behaviour: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"graduated">, z.ZodLiteral<"volume">]>>;
68
+ tier_behavior: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"graduated">, z.ZodLiteral<"volume">]>>;
69
69
  interval: z.ZodUnion<readonly [z.ZodLiteral<"week">, z.ZodLiteral<"month">, z.ZodLiteral<"quarter">, z.ZodLiteral<"semi_annual">, z.ZodLiteral<"year">]>;
70
70
  interval_count: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
71
71
  billing_units: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
@@ -149,17 +149,32 @@ type PriceWithAmount = PriceBaseFields & {
149
149
  /** Cannot have tiers when using flat amount */
150
150
  tiers?: never;
151
151
  };
152
- type PriceWithTiers = PriceBaseFields & {
152
+ type PriceWithGraduatedTiers = PriceBaseFields & {
153
153
  /** Cannot have flat amount when using tiers */
154
154
  amount?: never;
155
- /** Tiered pricing structure based on usage ranges */
155
+ /** Graduated tiered pricing: each tier's amount applies only to units within that tier */
156
156
  tiers: Array<{
157
157
  to: number | "inf";
158
158
  amount: number;
159
159
  }>;
160
- /** Required when tiers is defined: how tiers are applied */
161
- tierBehaviour: "graduated" | "volume";
160
+ /** Graduated: each tier's rate applies only to usage within that tier */
161
+ tierBehavior: "graduated";
162
162
  };
163
+ type PriceWithVolumeTiers = Omit<PriceBaseFields, "billingMethod"> & {
164
+ /** Volume pricing does not support usage_based billing — use 'prepaid' */
165
+ billingMethod: Exclude<BillingMethod, "usage_based">;
166
+ /** Cannot have flat amount when using tiers */
167
+ amount?: never;
168
+ /** Volume tiered pricing: the tier the total usage falls into applies to all units */
169
+ tiers: Array<{
170
+ to: number | "inf";
171
+ amount: number;
172
+ flatAmount?: number;
173
+ }>;
174
+ /** Volume: the rate of the tier the total usage falls into applies to all units */
175
+ tierBehavior: "volume";
176
+ };
177
+ type PriceWithTiers = PriceWithGraduatedTiers | PriceWithVolumeTiers;
163
178
  type PriceAmountOrTiers = PriceWithAmount | PriceWithTiers;
164
179
  type PriceWithoutInterval = PriceAmountOrTiers & {
165
180
  /** Cannot have interval when using top-level reset */
package/package.json CHANGED
@@ -1,97 +1,102 @@
1
1
  {
2
- "name": "atmn",
3
- "version": "1.1.0",
4
- "license": "MIT",
5
- "bin": {
6
- "atmn": "dist/cli.js"
7
- },
8
- "main": "dist/compose/index.js",
9
- "types": "dist/src/compose/index.d.ts",
10
- "type": "module",
11
- "engines": {
12
- "node": ">=16"
13
- },
14
- "scripts": {
15
- "build": "bun run bun.config.ts",
16
- "dev": "nodemon -e ts,tsx --watch src --ignore dist --exec \"bun run bun.config.ts\"",
17
- "dev:bun": "bun run dev.ts",
18
- "test": "bun test",
19
- "test:watch": "bun test --watch",
20
- "test2": "prettier --check . && xo && ava",
21
- "test-cli": "node --trace-deprecation -- ./dist/cli.js"
22
- },
23
- "files": [
24
- "dist",
25
- "package.json",
26
- "README.md"
27
- ],
28
- "dependencies": {
29
- "@inkjs/ui": "^2.0.0",
30
- "@inquirer/prompts": "^7.6.0",
31
- "@mishieck/ink-titled-box": "^0.3.0",
32
- "@tanstack/react-query": "^5.90.17",
33
- "@types/prettier": "^3.0.0",
34
- "arctic": "^3.7.0",
35
- "axios": "^1.10.0",
36
- "cfonts": "^3.3.1",
37
- "chalk": "^5.2.0",
38
- "clipboardy": "^5.0.2",
39
- "commander": "^14.0.0",
40
- "dotenv": "^17.2.0",
41
- "ervy": "^1.0.7",
42
- "ink": "^6.6.0",
43
- "ink-big-text": "^2.0.0",
44
- "ink-chart": "^0.1.1",
45
- "ink-confirm-input": "^2.0.0",
46
- "ink-scroll-list": "^0.4.1",
47
- "ink-scroll-view": "^0.3.5",
48
- "ink-select-input": "^6.2.0",
49
- "ink-spinner": "^5.0.0",
50
- "ink-table": "^3.1.0",
51
- "ink-text-input": "^6.0.0",
52
- "inquirer": "^12.7.0",
53
- "jiti": "^2.4.2",
54
- "open": "^10.1.2",
55
- "prettier": "^3.6.2",
56
- "react": "^19.2.3",
57
- "yocto-spinner": "^1.0.0",
58
- "zod": "^4.0.0",
59
- "conf": "^13.0.1"
60
- },
61
- "devDependencies": {
62
- "@sindresorhus/tsconfig": "^3.0.1",
63
- "@types/bun": "^1.2.21",
64
- "@types/node": "^24.0.10",
65
- "@types/react": "^19.0.0",
66
- "@vdemedes/prettier-config": "^2.0.1",
67
- "ava": "^5.2.0",
68
- "cli-testing-library": "^3.0.1",
69
- "eslint-config-xo-react": "^0.27.0",
70
- "eslint-plugin-react": "^7.32.2",
71
- "eslint-plugin-react-hooks": "^4.6.0",
72
- "ink-testing-library": "^3.0.0",
73
- "nodemon": "^3.1.11",
74
- "react-devtools-core": "^6.1.2",
75
- "ts-node": "^10.9.1",
76
- "tsup": "^8.5.0",
77
- "typescript": "^5.0.3",
78
- "xo": "^0.53.1"
79
- },
80
- "ava": {
81
- "extensions": {
82
- "ts": "module",
83
- "tsx": "module"
84
- },
85
- "nodeArguments": [
86
- "--loader=ts-node/esm"
87
- ]
88
- },
89
- "xo": {
90
- "extends": "xo-react",
91
- "prettier": true,
92
- "rules": {
93
- "react/prop-types": "off"
94
- }
95
- },
96
- "prettier": "@vdemedes/prettier-config"
2
+ "name": "atmn",
3
+ "version": "1.1.2",
4
+ "license": "MIT",
5
+ "bin": {
6
+ "atmn": "dist/cli.js"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/useautumn/typescript"
11
+ },
12
+ "homepage": "https://docs.useautumn.com/api-reference/cli/getting-started",
13
+ "main": "dist/compose/index.js",
14
+ "types": "dist/src/compose/index.d.ts",
15
+ "type": "module",
16
+ "engines": {
17
+ "node": ">=16"
18
+ },
19
+ "scripts": {
20
+ "build": "bun run bun.config.ts",
21
+ "dev": "nodemon -e ts,tsx --watch src --ignore dist --exec \"bun run bun.config.ts\"",
22
+ "dev:bun": "bun run dev.ts",
23
+ "test": "bun test",
24
+ "test:watch": "bun test --watch",
25
+ "test2": "prettier --check . && xo && ava",
26
+ "test-cli": "node --trace-deprecation -- ./dist/cli.js"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "package.json",
31
+ "README.md"
32
+ ],
33
+ "dependencies": {
34
+ "@inkjs/ui": "^2.0.0",
35
+ "@inquirer/prompts": "^7.6.0",
36
+ "@mishieck/ink-titled-box": "^0.3.0",
37
+ "@tanstack/react-query": "^5.90.17",
38
+ "@types/prettier": "^3.0.0",
39
+ "arctic": "^3.7.0",
40
+ "axios": "^1.10.0",
41
+ "cfonts": "^3.3.1",
42
+ "chalk": "^5.2.0",
43
+ "clipboardy": "^5.0.2",
44
+ "commander": "^14.0.0",
45
+ "dotenv": "^17.2.0",
46
+ "ervy": "^1.0.7",
47
+ "ink": "^6.6.0",
48
+ "ink-big-text": "^2.0.0",
49
+ "ink-chart": "^0.1.1",
50
+ "ink-confirm-input": "^2.0.0",
51
+ "ink-scroll-list": "^0.4.1",
52
+ "ink-scroll-view": "^0.3.5",
53
+ "ink-select-input": "^6.2.0",
54
+ "ink-spinner": "^5.0.0",
55
+ "ink-table": "^3.1.0",
56
+ "ink-text-input": "^6.0.0",
57
+ "inquirer": "^12.7.0",
58
+ "jiti": "^2.4.2",
59
+ "open": "^10.1.2",
60
+ "prettier": "^3.6.2",
61
+ "react": "^19.2.3",
62
+ "yocto-spinner": "^1.0.0",
63
+ "zod": "^4.0.0",
64
+ "conf": "^13.0.1"
65
+ },
66
+ "devDependencies": {
67
+ "@sindresorhus/tsconfig": "^3.0.1",
68
+ "@types/bun": "^1.2.21",
69
+ "@types/node": "^24.0.10",
70
+ "@types/react": "^19.0.0",
71
+ "@vdemedes/prettier-config": "^2.0.1",
72
+ "ava": "^5.2.0",
73
+ "cli-testing-library": "^3.0.1",
74
+ "eslint-config-xo-react": "^0.27.0",
75
+ "eslint-plugin-react": "^7.32.2",
76
+ "eslint-plugin-react-hooks": "^4.6.0",
77
+ "ink-testing-library": "^3.0.0",
78
+ "nodemon": "^3.1.11",
79
+ "react-devtools-core": "^6.1.2",
80
+ "ts-node": "^10.9.1",
81
+ "tsup": "^8.5.0",
82
+ "typescript": "^5.0.3",
83
+ "xo": "^0.53.1"
84
+ },
85
+ "ava": {
86
+ "extensions": {
87
+ "ts": "module",
88
+ "tsx": "module"
89
+ },
90
+ "nodeArguments": [
91
+ "--loader=ts-node/esm"
92
+ ]
93
+ },
94
+ "xo": {
95
+ "extends": "xo-react",
96
+ "prettier": true,
97
+ "rules": {
98
+ "react/prop-types": "off"
99
+ }
100
+ },
101
+ "prettier": "@vdemedes/prettier-config"
97
102
  }