atmn 0.0.4 → 0.0.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.
package/dist/constants.js DELETED
@@ -1,55 +0,0 @@
1
- // export const FRONTEND_URL = 'http://localhost:3000';
2
- // export const BACKEND_URL = 'http://localhost:8080';
3
- export const FRONTEND_URL = 'http://app.useautumn.com';
4
- export const BACKEND_URL = 'https://api.useautumn.com';
5
- export const DEFAULT_CONFIG = `import {
6
- feature,
7
- product,
8
- priceItem,
9
- featureItem,
10
- pricedFeatureItem,
11
- } from 'autumn-js/compose';
12
-
13
- const seats = feature({
14
- id: 'seats',
15
- name: 'Seats',
16
- type: 'continuous_use',
17
- });
18
-
19
- const messages = feature({
20
- id: 'messages',
21
- name: 'Messages',
22
- type: 'single_use',
23
- });
24
-
25
- const pro = product({
26
- id: 'pro',
27
- name: 'Pro',
28
- items: [
29
- // 500 messages per month
30
- featureItem({
31
- feature_id: messages.id,
32
- included_usage: 500,
33
- interval: 'month',
34
- }),
35
-
36
- // $10 per seat per month
37
- pricedFeatureItem({
38
- feature_id: seats.id,
39
- price: 10,
40
- interval: 'month',
41
- }),
42
-
43
- // $50 / month
44
- priceItem({
45
- price: 50,
46
- interval: 'month',
47
- }),
48
- ],
49
- });
50
-
51
- export default {
52
- features: [seats, messages],
53
- products: [pro],
54
- };
55
- `;
@@ -1,27 +0,0 @@
1
- export declare function request({ method, base, path, data, headers, customAuth, throwOnError, }: {
2
- method: string;
3
- base: string;
4
- path: string;
5
- data?: any;
6
- headers?: any;
7
- customAuth?: string;
8
- throwOnError?: boolean;
9
- }): Promise<any>;
10
- export declare function internalRequest({ method, path, data, headers, customAuth, }: {
11
- method: string;
12
- path: string;
13
- data?: any;
14
- headers?: any;
15
- customAuth?: string;
16
- }): Promise<any>;
17
- export declare function externalRequest({ method, path, data, headers, customAuth, throwOnError, }: {
18
- method: string;
19
- path: string;
20
- data?: any;
21
- headers?: any;
22
- customAuth?: string;
23
- throwOnError?: boolean;
24
- }): Promise<any>;
25
- export declare function deleteFeature(id: string): Promise<any>;
26
- export declare function deleteProduct(id: string): Promise<any>;
27
- export declare function updateCLIStripeKeys(stripeTestKey: string, stripeLiveKey: string, stripeFlowAuthKey: string): Promise<any>;
package/dist/core/api.js DELETED
@@ -1,75 +0,0 @@
1
- import axios from 'axios';
2
- import chalk from 'chalk';
3
- import { BACKEND_URL } from '../constants.js';
4
- import { readFromEnv } from './utils.js';
5
- const INTERNAL_BASE = BACKEND_URL;
6
- const EXTERNAL_BASE = `${BACKEND_URL}/v1`;
7
- export async function request({ method, base, path, data, headers, customAuth, throwOnError = true, }) {
8
- const apiKey = readFromEnv();
9
- try {
10
- const response = await axios.request({
11
- method,
12
- url: `${base}${path}`,
13
- data,
14
- headers: {
15
- 'Content-Type': 'application/json',
16
- ...headers,
17
- Authorization: customAuth || `Bearer ${apiKey}`,
18
- },
19
- });
20
- return response.data;
21
- }
22
- catch (error) {
23
- if (throwOnError) {
24
- throw error;
25
- }
26
- console.error(chalk.red('Error occured when making API request:'), chalk.red(error.response.data.message || error.response.data.error));
27
- process.exit(1);
28
- }
29
- }
30
- export async function internalRequest({ method, path, data, headers, customAuth, }) {
31
- return await request({
32
- method,
33
- base: INTERNAL_BASE,
34
- path,
35
- data,
36
- headers,
37
- customAuth,
38
- });
39
- }
40
- export async function externalRequest({ method, path, data, headers, customAuth, throwOnError = false, }) {
41
- return await request({
42
- method,
43
- base: EXTERNAL_BASE,
44
- path,
45
- data,
46
- headers,
47
- customAuth,
48
- throwOnError,
49
- });
50
- }
51
- export async function deleteFeature(id) {
52
- return await externalRequest({
53
- method: 'DELETE',
54
- path: `/features/${id}`,
55
- });
56
- }
57
- export async function deleteProduct(id) {
58
- return await externalRequest({
59
- method: 'DELETE',
60
- path: `/products/${id}`,
61
- });
62
- }
63
- export async function updateCLIStripeKeys(stripeTestKey, stripeLiveKey, stripeFlowAuthKey) {
64
- return await internalRequest({
65
- method: 'POST',
66
- path: '/dev/cli/stripe',
67
- data: {
68
- stripeTestKey,
69
- stripeLiveKey,
70
- successUrl: 'https://useautumn.com',
71
- defaultCurrency: 'usd',
72
- },
73
- customAuth: stripeFlowAuthKey,
74
- });
75
- }
@@ -1 +0,0 @@
1
- export declare function getOTP(otp: string): Promise<any>;
package/dist/core/auth.js DELETED
@@ -1,8 +0,0 @@
1
- import { internalRequest } from './api.js';
2
- export async function getOTP(otp) {
3
- const response = await internalRequest({
4
- method: 'GET',
5
- path: `/dev/otp/${otp}`,
6
- });
7
- return response;
8
- }
@@ -1,2 +0,0 @@
1
- import { Feature } from 'autumn-js/compose';
2
- export declare function featureBuilder(feature: Feature): string;
@@ -1,10 +0,0 @@
1
- import { snakeCaseToCamelCase } from '../utils.js';
2
- export function featureBuilder(feature) {
3
- const snippet = `
4
- export const ${snakeCaseToCamelCase(feature.id)} = feature({
5
- id: '${feature.id}',
6
- name: '${feature.name}',
7
- type: '${feature.type}',
8
- })`;
9
- return snippet;
10
- }
@@ -1,7 +0,0 @@
1
- import { ProductItem, Product } from 'autumn-js/compose';
2
- export declare function importBuilder(): string;
3
- export declare function exportBuilder(productIds: string[], featureIds: string[]): string;
4
- export declare function productBuilder(product: Product): string;
5
- export declare function pricedFeatureItemBuilder(item: ProductItem): string;
6
- export declare function featureItemBuilder(item: ProductItem): string;
7
- export declare function priceItemBuilder(item: ProductItem): string;
@@ -1,71 +0,0 @@
1
- import { snakeCaseToCamelCase } from '../utils.js';
2
- const ItemBuilders = {
3
- priced_feature: pricedFeatureItemBuilder,
4
- feature: featureItemBuilder,
5
- price: priceItemBuilder,
6
- };
7
- export function importBuilder() {
8
- return `
9
- import {
10
- feature,
11
- product,
12
- featureItem,
13
- pricedFeatureItem,
14
- priceItem,
15
- } from 'autumn-js/compose';
16
- `;
17
- }
18
- export function exportBuilder(productIds, featureIds) {
19
- const snippet = `
20
- export default {
21
- products: [${productIds.map(id => `${id}Plan`).join(', ')}],
22
- features: [${featureIds.map(id => `${id}`).join(', ')}]
23
- }
24
- `;
25
- return snippet;
26
- }
27
- export function productBuilder(product) {
28
- const snippet = `
29
- export const ${product.id}Plan = product({
30
- id: '${product.id}',
31
- name: '${product.name}',
32
- items: [${product.items
33
- .map((item) => `${ItemBuilders[item.type](item)}`)
34
- .join(' ')} ]
35
- })
36
- `;
37
- return snippet;
38
- }
39
- // Item Builders
40
- export function pricedFeatureItemBuilder(item) {
41
- const intervalLine = item.interval == null ? '' : `\n interval: '${item.interval}',`;
42
- const snippet = `
43
- pricedFeatureItem({
44
- feature_id: ${snakeCaseToCamelCase(item.feature_id)}.id,
45
- price: ${item.price},${intervalLine}
46
- included_usage: ${item.included_usage},
47
- billing_units: ${item.billing_units},
48
- usage_model: '${item.usage_model}',
49
- }),
50
- `;
51
- return snippet;
52
- }
53
- export function featureItemBuilder(item) {
54
- const intervalLine = item.interval == null ? '' : `\n interval: '${item.interval}',`;
55
- const snippet = `
56
- featureItem({
57
- feature_id: ${snakeCaseToCamelCase(item.feature_id)}.id,
58
- included_usage: ${item.included_usage},${intervalLine}
59
- }),
60
- `;
61
- return snippet;
62
- }
63
- export function priceItemBuilder(item) {
64
- const intervalLine = item.interval == null ? '' : `\n interval: '${item.interval}',`;
65
- const snippet = `
66
- priceItem({
67
- price: ${item.price},${intervalLine}
68
- }),
69
- `;
70
- return snippet;
71
- }
@@ -1,2 +0,0 @@
1
- export declare function loadAutumnConfigFile(): Promise<any>;
2
- export declare function writeConfig(config: string): void;
@@ -1,25 +0,0 @@
1
- import path from 'path';
2
- import fs from 'fs';
3
- import createJiti from 'jiti';
4
- import { pathToFileURL } from 'url';
5
- import { resolve } from 'path';
6
- export async function loadAutumnConfigFile() {
7
- const configPath = path.join(process.cwd(), 'autumn.config.ts');
8
- const absolutePath = resolve(configPath);
9
- const fileUrl = pathToFileURL(absolutePath).href;
10
- // Dynamic import the TypeScript config file
11
- const jiti = createJiti(import.meta.url);
12
- const mod = await jiti.import(fileUrl);
13
- const def = mod.default || mod;
14
- if (!def.products || !Array.isArray(def.products)) {
15
- throw new Error("You must export a products field that is an array of products.");
16
- }
17
- if (!def.features || !Array.isArray(def.features)) {
18
- throw new Error("You must export a features field that is an array of products.");
19
- }
20
- return def;
21
- }
22
- export function writeConfig(config) {
23
- const configPath = path.join(process.cwd(), 'autumn.config.ts');
24
- fs.writeFileSync(configPath, config);
25
- }
@@ -1,17 +0,0 @@
1
- export declare function getProducts(ids: string[]): Promise<{
2
- id: string;
3
- name: string;
4
- items: {
5
- type?: "feature" | "priced_feature" | null | undefined;
6
- feature_id?: string | null | undefined;
7
- included_usage?: number | "inf" | null | undefined;
8
- interval?: "minute" | "hour" | "day" | "week" | "month" | "quarter" | "semi_annual" | "year" | null | undefined;
9
- usage_model?: "prepaid" | "pay_per_use" | null | undefined;
10
- price?: number | null | undefined;
11
- billing_units?: number | null | undefined;
12
- }[];
13
- is_add_on?: boolean | undefined;
14
- is_default?: boolean | undefined;
15
- }[]>;
16
- export declare function getAllProducts(): Promise<any>;
17
- export declare function getFeatures(): Promise<any>;
package/dist/core/pull.js DELETED
@@ -1,22 +0,0 @@
1
- import { externalRequest } from './api.js';
2
- export async function getProducts(ids) {
3
- const products = await Promise.all(ids.map(id => externalRequest({
4
- method: 'GET',
5
- path: `/products/${id}`,
6
- })));
7
- return products.map(product => product);
8
- }
9
- export async function getAllProducts() {
10
- const { list } = await externalRequest({
11
- method: 'GET',
12
- path: '/products',
13
- });
14
- return list.map(product => product);
15
- }
16
- export async function getFeatures() {
17
- const { list } = await externalRequest({
18
- method: 'GET',
19
- path: '/features',
20
- });
21
- return list.map(feature => feature);
22
- }
@@ -1,7 +0,0 @@
1
- import { Feature, Product } from 'autumn-js/compose';
2
- export declare function checkForDeletables(currentFeatures: Feature[], currentProducts: Product[]): Promise<{
3
- featuresToDelete: any;
4
- productsToDelete: any;
5
- }>;
6
- export declare function upsertFeature(feature: Feature): Promise<any>;
7
- export declare function upsertProduct(product: Product): Promise<any>;
package/dist/core/push.js DELETED
@@ -1,67 +0,0 @@
1
- import { externalRequest } from './api.js';
2
- import { getFeatures, getAllProducts } from './pull.js';
3
- export async function checkForDeletables(currentFeatures, currentProducts) {
4
- const features = await getFeatures(); // Get from AUTUMN
5
- const featureIds = features.map(feature => feature.id);
6
- const currentFeatureIds = currentFeatures.map(feature => feature.id);
7
- const featuresToDelete = featureIds.filter(featureId => !currentFeatureIds.includes(featureId));
8
- const products = await getAllProducts();
9
- const productIds = products.map(product => product.id);
10
- const currentProductIds = currentProducts.map(product => product.id);
11
- const productsToDelete = productIds.filter(productId => !currentProductIds.includes(productId));
12
- return { featuresToDelete, productsToDelete };
13
- }
14
- export async function upsertFeature(feature) {
15
- try {
16
- const response = await externalRequest({
17
- method: 'POST',
18
- path: `/features`,
19
- data: feature,
20
- throwOnError: true,
21
- // data: {
22
- // ...feature,
23
- // config: {
24
- // filters: [{property: '', operator: '', value: []}],
25
- // usage_type: 'single_use',
26
- // },
27
- // },
28
- });
29
- return response.data;
30
- }
31
- catch (error) {
32
- // If the first request fails, try posting to the specific feature ID endpoint
33
- const response = await externalRequest({
34
- method: 'POST',
35
- path: `/features/${feature.id}`,
36
- data: feature,
37
- // data: {
38
- // ...feature,
39
- // config: {
40
- // filters: [{property: '', operator: '', value: []}],
41
- // usage_type: 'single_use',
42
- // },
43
- // },
44
- });
45
- return response.data;
46
- }
47
- }
48
- export async function upsertProduct(product) {
49
- try {
50
- const response = await externalRequest({
51
- method: 'POST',
52
- path: `/products`,
53
- data: product,
54
- throwOnError: true,
55
- });
56
- return response.data;
57
- }
58
- catch (error) {
59
- // If the first request fails, try posting to the specific product ID endpoint
60
- const response = await externalRequest({
61
- method: 'POST',
62
- path: `/products/${product.id}`,
63
- data: product,
64
- });
65
- return response.data;
66
- }
67
- }
@@ -1,3 +0,0 @@
1
- export declare function snakeCaseToCamelCase(value: string): string;
2
- export declare function storeToEnv(prodKey: string, sandboxKey: string): void;
3
- export declare function readFromEnv(): string;
@@ -1,26 +0,0 @@
1
- import fs from 'fs';
2
- import chalk from 'chalk';
3
- export function snakeCaseToCamelCase(value) {
4
- return value.replace(/_([a-z])/g, (match, letter) => letter.toUpperCase());
5
- }
6
- export function storeToEnv(prodKey, sandboxKey) {
7
- const envPath = `${process.cwd()}/.env`;
8
- const envVars = `# AUTUMN_SECRET_KEY=${prodKey}\nAUTUMN_SECRET_KEY=${sandboxKey}\n`;
9
- if (fs.existsSync(envPath)) {
10
- fs.appendFileSync(envPath, envVars);
11
- console.log(chalk.green('.env file found. Appended keys.'));
12
- }
13
- else {
14
- fs.writeFileSync(envPath, envVars);
15
- console.log(chalk.green('.env file not found. Created new .env file and wrote keys.'));
16
- }
17
- }
18
- export function readFromEnv() {
19
- const envPath = `${process.cwd()}/.env`;
20
- if (!fs.existsSync(envPath)) {
21
- return undefined;
22
- }
23
- const envContent = fs.readFileSync(envPath, 'utf-8');
24
- const match = envContent.match(/^AUTUMN_SECRET_KEY=(.*)$/m);
25
- return match ? match[1] : undefined;
26
- }