@kelviq/cli 0.4.2 → 0.5.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.
- package/README.md +147 -5
- package/dist/cli-ui/secret-prompt.d.ts +53 -0
- package/dist/cli-ui/secret-prompt.js +119 -0
- package/dist/cli-ui/secret-prompt.js.map +1 -0
- package/dist/cli.js +6 -3
- package/dist/cli.js.map +1 -1
- package/dist/commands/env.js +2 -2
- package/dist/commands/env.js.map +1 -1
- package/dist/commands/import/index.d.ts +15 -0
- package/dist/commands/import/index.js +120 -0
- package/dist/commands/import/index.js.map +1 -0
- package/dist/commands/import/lemon-squeezy.d.ts +2 -0
- package/dist/commands/import/lemon-squeezy.js +90 -0
- package/dist/commands/import/lemon-squeezy.js.map +1 -0
- package/dist/commands/import/redact.d.ts +10 -0
- package/dist/commands/import/redact.js +73 -0
- package/dist/commands/import/redact.js.map +1 -0
- package/dist/commands/import/runner.d.ts +40 -0
- package/dist/commands/import/runner.js +510 -0
- package/dist/commands/import/runner.js.map +1 -0
- package/dist/commands/import/source.d.ts +122 -0
- package/dist/commands/import/source.js +29 -0
- package/dist/commands/import/source.js.map +1 -0
- package/dist/commands/login.js +6 -104
- package/dist/commands/login.js.map +1 -1
- package/dist/core/config.d.ts +2 -0
- package/dist/core/config.js +4 -0
- package/dist/core/config.js.map +1 -1
- package/dist/core/env-file.d.ts +7 -2
- package/dist/core/env-file.js +22 -7
- package/dist/core/env-file.js.map +1 -1
- package/dist/core/errors.d.ts +23 -1
- package/dist/core/errors.js +83 -31
- package/dist/core/errors.js.map +1 -1
- package/dist/core/http.d.ts +4 -0
- package/dist/core/http.js +6 -3
- package/dist/core/http.js.map +1 -1
- package/dist/core/import-env.d.ts +8 -0
- package/dist/core/import-env.js +18 -0
- package/dist/core/import-env.js.map +1 -0
- package/dist/generated/openapi.json +1359 -109
- package/package.json +1 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// The Lemon Squeezy import source: `kelviq import lemon-squeezy`. Data only;
|
|
2
|
+
// runner.ts does the work.
|
|
3
|
+
import { IMPORT_SOURCE_ENV_VARS } from '../../core/import-env.js';
|
|
4
|
+
import { describeValue } from './source.js';
|
|
5
|
+
const ENV = IMPORT_SOURCE_ENV_VARS['lemon-squeezy'];
|
|
6
|
+
/** `--orders` value → the API's `orderType`. The API's own spelling and the plural are accepted beside the documented values. */
|
|
7
|
+
const ORDER_TYPES = {
|
|
8
|
+
all: 'all',
|
|
9
|
+
'one-time': 'one_time',
|
|
10
|
+
one_time: 'one_time',
|
|
11
|
+
subscription: 'subscription',
|
|
12
|
+
subscriptions: 'subscription',
|
|
13
|
+
};
|
|
14
|
+
const ORDER_SUMMARIES = {
|
|
15
|
+
all: 'all (every order and every subscription renewal)',
|
|
16
|
+
one_time: 'one-time (orders that did not start a subscription; renewals are skipped)',
|
|
17
|
+
subscription: 'subscription (orders that started a subscription, and their renewals)',
|
|
18
|
+
};
|
|
19
|
+
export const lemonSqueezy = {
|
|
20
|
+
id: 'lemon-squeezy',
|
|
21
|
+
label: 'Lemon Squeezy',
|
|
22
|
+
path: '/integrations/lemon-squeezy/migrate/',
|
|
23
|
+
credentials: {
|
|
24
|
+
envVar: ENV.credentials,
|
|
25
|
+
label: 'Lemon Squeezy API key',
|
|
26
|
+
bodyField: 'apiKey',
|
|
27
|
+
shortLabel: 'api key',
|
|
28
|
+
createHint: 'Create a key in Lemon Squeezy under Settings → API.',
|
|
29
|
+
},
|
|
30
|
+
locator: {
|
|
31
|
+
flag: '--store <id>',
|
|
32
|
+
description: `Lemon Squeezy store id to import (or set ${ENV.locator}; asked for in an interactive session)`,
|
|
33
|
+
envVar: ENV.locator,
|
|
34
|
+
bodyField: 'storeId',
|
|
35
|
+
noun: 'store',
|
|
36
|
+
prompt: 'Lemon Squeezy store id (the number beside your store under Settings → Stores): ',
|
|
37
|
+
nameField: 'storeName',
|
|
38
|
+
validate: (value) => (/^\d+$/.test(value) ? undefined : 'must be the numeric Lemon Squeezy store id (digits only).'),
|
|
39
|
+
},
|
|
40
|
+
steps: ['store', 'products', 'customers', 'files', 'orders', 'renewals', 'discounts', 'licenses'],
|
|
41
|
+
stepListExample: 'orders,renewals',
|
|
42
|
+
progress: 'Checking the store with Lemon Squeezy and queueing the import…',
|
|
43
|
+
notes: [
|
|
44
|
+
{ label: 'customers', text: 'not emailed; no webhooks fire for imported records' },
|
|
45
|
+
{ label: 'subscriptions', text: 'imported as history; they keep billing on Lemon Squeezy' },
|
|
46
|
+
],
|
|
47
|
+
extraFlags: [
|
|
48
|
+
{
|
|
49
|
+
flag: '--orders <all|one-time|subscription>',
|
|
50
|
+
description: 'Which sales to import (default: all)',
|
|
51
|
+
bodyField: 'orderType',
|
|
52
|
+
parse: (raw) => {
|
|
53
|
+
const orderType = typeof raw === 'string' ? ORDER_TYPES[raw.trim().toLowerCase()] : undefined;
|
|
54
|
+
return orderType ? { value: orderType } : { error: `--orders must be all, one-time or subscription (got ${describeValue(String(raw))}).` };
|
|
55
|
+
},
|
|
56
|
+
summary: {
|
|
57
|
+
label: 'order type',
|
|
58
|
+
text: (value) => ORDER_SUMMARIES[typeof value === 'string' ? value : 'all'],
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
flag: '--overwrite-profile',
|
|
63
|
+
description: 'Overwrite the organization name and business profile fields that are already filled in (default: fill blank fields only)',
|
|
64
|
+
bodyField: 'overwriteProfile',
|
|
65
|
+
parse: (raw) => ({ value: raw === true }),
|
|
66
|
+
summary: {
|
|
67
|
+
label: 'profile',
|
|
68
|
+
text: (value) => (value === true ? 'overwrite the organization name and business profile fields already filled in' : undefined),
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
flag: '--skip-analytics',
|
|
73
|
+
description: 'Do not add the imported sales to revenue analytics',
|
|
74
|
+
bodyField: 'skipAnalytics',
|
|
75
|
+
parse: (raw) => ({ value: raw === true }),
|
|
76
|
+
summary: {
|
|
77
|
+
label: 'analytics',
|
|
78
|
+
text: (value) => (value === true ? 'imported sales are left out of revenue analytics' : undefined),
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
fieldLabels: {
|
|
83
|
+
apiKey: `the Lemon Squeezy API key (${ENV.credentials})`,
|
|
84
|
+
storeId: '--store',
|
|
85
|
+
orderType: '--orders',
|
|
86
|
+
overwriteProfile: '--overwrite-profile',
|
|
87
|
+
skipAnalytics: '--skip-analytics',
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=lemon-squeezy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lemon-squeezy.js","sourceRoot":"","sources":["../../../src/commands/import/lemon-squeezy.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,2BAA2B;AAC3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,aAAa,EAAqB,MAAM,aAAa,CAAC;AAE/D,MAAM,GAAG,GAAG,sBAAsB,CAAC,eAAe,CAAC,CAAC;AAEpD,iIAAiI;AACjI,MAAM,WAAW,GAAqC;IACpD,GAAG,EAAE,KAAK;IACV,UAAU,EAAE,UAAU;IACtB,QAAQ,EAAE,UAAU;IACpB,YAAY,EAAE,cAAc;IAC5B,aAAa,EAAE,cAAc;CAC9B,CAAC;AAEF,MAAM,eAAe,GAAqC;IACxD,GAAG,EAAE,kDAAkD;IACvD,QAAQ,EAAE,2EAA2E;IACrF,YAAY,EAAE,uEAAuE;CACtF,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAiB;IACxC,EAAE,EAAE,eAAe;IACnB,KAAK,EAAE,eAAe;IACtB,IAAI,EAAE,sCAAsC;IAC5C,WAAW,EAAE;QACX,MAAM,EAAE,GAAG,CAAC,WAAW;QACvB,KAAK,EAAE,uBAAuB;QAC9B,SAAS,EAAE,QAAQ;QACnB,UAAU,EAAE,SAAS;QACrB,UAAU,EAAE,qDAAq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E,YAAY;gBACnB,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;aAC5E;SACF;QACD;YACE,IAAI,EAAE,qBAAqB;YAC3B,WAAW,EAAE,0HAA0H;YACvI,SAAS,EAAE,kBAAkB;YAC7B,KAAK,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI,EAAE,CAAC;YACzC,OAAO,EAAE;gBACP,KAAK,EAAE,SAAS;gBAChB,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,+EAA+E,CAAC,CAAC,CAAC,SAAS,CAAC;aAChI;SACF;QACD;YACE,IAAI,EAAE,kBAAkB;YACxB,WAAW,EAAE,oDAAoD;YACjE,SAAS,EAAE,eAAe;YAC1B,KAAK,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI,EAAE,CAAC;YACzC,OAAO,EAAE;gBACP,KAAK,EAAE,WAAW;gBAClB,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,kDAAkD,CAAC,CAAC,CAAC,SAAS,CAAC;aACnG;SACF;KACF;IACD,WAAW,EAAE;QACX,MAAM,EAAE,8BAA8B,GAAG,CAAC,WAAW,GAAG;QACxD,OAAO,EAAE,SAAS;QAClB,SAAS,EAAE,UAAU;QACrB,gBAAgB,EAAE,qBAAqB;QACvC,aAAa,EAAE,kBAAkB;KAClC;CACF,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The spellings a secret takes once something has quoted it back: as typed, inside a JSON string, in a URL or a form body, and in HTML. Longest first. */
|
|
2
|
+
export declare function secretForms(secret: string): string[];
|
|
3
|
+
/** Replaces every spelling of `secret` in `text`, whatever its letter case. */
|
|
4
|
+
export declare function redactText(text: string, secret: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Hides `secret` in every string value of a JSON-shaped value. Property
|
|
7
|
+
* names are never rewritten; a property whose name itself contains the
|
|
8
|
+
* secret is left out.
|
|
9
|
+
*/
|
|
10
|
+
export declare function redactValue(value: unknown, secret: string): unknown;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Keeps the source platform's API key out of everything `kelviq import`
|
|
2
|
+
// writes. The key is hidden in each message string, and in each string value
|
|
3
|
+
// of a `--json` document, BEFORE anything is serialized: the serialized text
|
|
4
|
+
// is never rewritten, so a document's own keys and punctuation cannot be
|
|
5
|
+
// altered and a key that needs JSON escaping cannot slip through re-escaped.
|
|
6
|
+
const HIDDEN = '[hidden]';
|
|
7
|
+
/**
|
|
8
|
+
* Below this length a value is not hidden. Nothing that short is a key (one
|
|
9
|
+
* is rejected before any request is made), and hiding it would blank out
|
|
10
|
+
* ordinary words: a variable holding `1` would otherwise turn `HTTP 400 for
|
|
11
|
+
* store 12345` into `HTTP 400 for store [hidden]2345`.
|
|
12
|
+
*/
|
|
13
|
+
const MIN_HIDDEN_LENGTH = 8;
|
|
14
|
+
function htmlEscape(text, quote, apostrophe) {
|
|
15
|
+
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, quote).replace(/'/g, apostrophe);
|
|
16
|
+
}
|
|
17
|
+
/** The spellings a secret takes once something has quoted it back: as typed, inside a JSON string, in a URL or a form body, and in HTML. Longest first. */
|
|
18
|
+
export function secretForms(secret) {
|
|
19
|
+
const forms = [
|
|
20
|
+
secret,
|
|
21
|
+
JSON.stringify(secret).slice(1, -1),
|
|
22
|
+
htmlEscape(secret, '"', '''),
|
|
23
|
+
htmlEscape(secret, '"', '''),
|
|
24
|
+
htmlEscape(secret, '"', '''),
|
|
25
|
+
htmlEscape(secret, '"', "'"),
|
|
26
|
+
new URLSearchParams({ k: secret }).toString().slice(2),
|
|
27
|
+
];
|
|
28
|
+
try {
|
|
29
|
+
forms.push(encodeURIComponent(secret), encodeURI(secret));
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// A lone surrogate cannot be URL-encoded, so no such spelling exists.
|
|
33
|
+
}
|
|
34
|
+
return [...new Set(forms)].sort((a, b) => b.length - a.length);
|
|
35
|
+
}
|
|
36
|
+
let cached = { secret: '', pattern: undefined };
|
|
37
|
+
/** One case-insensitive pattern matching every spelling of `secret`, or `undefined` when there is nothing to hide. */
|
|
38
|
+
function patternFor(secret) {
|
|
39
|
+
if (cached.secret !== secret) {
|
|
40
|
+
const pattern = secret.length < MIN_HIDDEN_LENGTH
|
|
41
|
+
? undefined
|
|
42
|
+
: new RegExp(secretForms(secret).map((form) => form.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|'), 'gi');
|
|
43
|
+
cached = { secret, pattern };
|
|
44
|
+
}
|
|
45
|
+
return cached.pattern;
|
|
46
|
+
}
|
|
47
|
+
/** Replaces every spelling of `secret` in `text`, whatever its letter case. */
|
|
48
|
+
export function redactText(text, secret) {
|
|
49
|
+
const pattern = patternFor(secret);
|
|
50
|
+
return pattern ? text.replace(pattern, HIDDEN) : text;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Hides `secret` in every string value of a JSON-shaped value. Property
|
|
54
|
+
* names are never rewritten; a property whose name itself contains the
|
|
55
|
+
* secret is left out.
|
|
56
|
+
*/
|
|
57
|
+
export function redactValue(value, secret) {
|
|
58
|
+
if (typeof value === 'string')
|
|
59
|
+
return redactText(value, secret);
|
|
60
|
+
if (Array.isArray(value))
|
|
61
|
+
return value.map((item) => redactValue(item, secret));
|
|
62
|
+
if (typeof value === 'object' && value !== null) {
|
|
63
|
+
const out = {};
|
|
64
|
+
for (const [key, item] of Object.entries(value)) {
|
|
65
|
+
if (redactText(key, secret) !== key)
|
|
66
|
+
continue;
|
|
67
|
+
out[key] = redactValue(item, secret);
|
|
68
|
+
}
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=redact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redact.js","sourceRoot":"","sources":["../../../src/commands/import/redact.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,6EAA6E;AAC7E,6EAA6E;AAC7E,yEAAyE;AACzE,6EAA6E;AAC7E,MAAM,MAAM,GAAG,UAAU,CAAC;AAE1B;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAE5B,SAAS,UAAU,CAAC,IAAY,EAAE,KAAa,EAAE,UAAkB;IACjE,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AAChI,CAAC;AAED,2JAA2J;AAC3J,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,MAAM,KAAK,GAAG;QACZ,MAAM;QACN,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACnC,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC;QACrC,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC;QACtC,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC;QACpC,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC;QAC5B,IAAI,eAAe,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;KACvD,CAAC;IACF,IAAI,CAAC;QACH,KA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c;IACxD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAChE,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IAChF,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,MAAM,GAAG,GAA4B,EAAE,CAAC;QACxC,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAChD,IAAI,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,GAAG;gBAAE,SAAS;YAC9C,GAAG,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACvC,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type KelviqAPIError } from '../../core/errors.js';
|
|
2
|
+
import { type ImportIO, type ImportOptions, type ImportSource } from './source.js';
|
|
3
|
+
export type ImportBody = Record<string, unknown>;
|
|
4
|
+
/** The steps a body asks for, in the order the import runs them: `only` (or every step) minus `skip`. */
|
|
5
|
+
export declare function plannedSteps(source: ImportSource, body: ImportBody): string[];
|
|
6
|
+
/**
|
|
7
|
+
* Turns the flags and environment into the request body, or returns the
|
|
8
|
+
* first validation error. Pure: the source key is read from `env` under the
|
|
9
|
+
* variable the source declares, so a caller that prompted for it passes it in
|
|
10
|
+
* the same way. Fields left at their server default are not sent.
|
|
11
|
+
*/
|
|
12
|
+
export declare function buildImportBody(source: ImportSource, options: ImportOptions, env?: NodeJS.ProcessEnv): {
|
|
13
|
+
body: ImportBody;
|
|
14
|
+
} | {
|
|
15
|
+
error: string;
|
|
16
|
+
};
|
|
17
|
+
/** What the summary says beyond the body. */
|
|
18
|
+
export interface ImportSummaryContext {
|
|
19
|
+
envName: string;
|
|
20
|
+
/** The API host, when it is not the built-in one for the environment. */
|
|
21
|
+
apiHost?: string;
|
|
22
|
+
/** Where the source key came from (`from <variable> (<file or shell>)`, or `typed`); never the key. */
|
|
23
|
+
keyOrigin?: string;
|
|
24
|
+
}
|
|
25
|
+
/** The pre-run summary. Built from the body, minus the source key, which is never printed. */
|
|
26
|
+
export declare function describeImport(source: ImportSource, body: ImportBody, context: ImportSummaryContext): string[];
|
|
27
|
+
interface ImportFailure {
|
|
28
|
+
message: string;
|
|
29
|
+
/** Extra lines for a multi-part error (one per rejected field). */
|
|
30
|
+
details?: string[];
|
|
31
|
+
authHint?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** Turns an API error into what the user should read: field names become the flags and variables that set them. */
|
|
34
|
+
export declare function describeImportError(source: ImportSource, error: KelviqAPIError['error']): ImportFailure;
|
|
35
|
+
/** A request that got no HTTP answer: whether it can have reached Kelviq decides what the user is told. */
|
|
36
|
+
export declare function describeNetworkFailure(host: string, error: KelviqAPIError['error'], timeoutMs: number): ImportFailure;
|
|
37
|
+
export declare function runImport(source: ImportSource, options: ImportOptions, io: ImportIO,
|
|
38
|
+
/** Positional arguments after the source name. There are none to give, so any is a mistake (usually a space inside a list). */
|
|
39
|
+
excessArgs?: readonly string[]): Promise<number>;
|
|
40
|
+
export {};
|