@copilotz/billing 0.0.0-stage → 1.0.0-rc.35

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 (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -2
  3. package/contract.d.ts +7 -0
  4. package/contract.js +7 -0
  5. package/credits/actions/check.d.ts +5 -0
  6. package/credits/actions/check.js +97 -0
  7. package/credits/actions/manage.d.ts +9 -0
  8. package/credits/actions/manage.js +266 -0
  9. package/credits/actions/state.d.ts +2 -0
  10. package/credits/actions/state.js +172 -0
  11. package/credits/collections/credit.d.ts +110 -0
  12. package/credits/collections/credit.js +31 -0
  13. package/credits/collections/payment.d.ts +139 -0
  14. package/credits/collections/payment.js +32 -0
  15. package/credits/collections/plan.d.ts +428 -0
  16. package/credits/collections/plan.js +97 -0
  17. package/credits/collections/room.d.ts +85 -0
  18. package/credits/collections/room.js +24 -0
  19. package/credits/contract.d.ts +19 -0
  20. package/credits/contract.js +12 -0
  21. package/credits/mod.d.ts +38 -0
  22. package/credits/mod.js +72 -0
  23. package/credits/shared/apply.d.ts +66 -0
  24. package/credits/shared/apply.js +106 -0
  25. package/credits/shared/settings.d.ts +70 -0
  26. package/credits/shared/settings.js +28 -0
  27. package/credits/shared/standing.d.ts +71 -0
  28. package/credits/shared/standing.js +235 -0
  29. package/credits/shared/walk.d.ts +50 -0
  30. package/credits/shared/walk.js +127 -0
  31. package/credits/views/web/add.d.ts +25 -0
  32. package/credits/views/web/add.js +92 -0
  33. package/credits/views/web/budget.d.ts +16 -0
  34. package/credits/views/web/budget.js +62 -0
  35. package/credits/views/web/composer.d.ts +13 -0
  36. package/credits/views/web/composer.js +65 -0
  37. package/credits/views/web/history.d.ts +12 -0
  38. package/credits/views/web/history.js +55 -0
  39. package/credits/views/web/numbers.d.ts +256 -0
  40. package/credits/views/web/numbers.js +291 -0
  41. package/credits/views/web/org.d.ts +31 -0
  42. package/credits/views/web/org.js +238 -0
  43. package/credits/views/web/plan.d.ts +28 -0
  44. package/credits/views/web/plan.js +84 -0
  45. package/credits/views/web/staff.d.ts +20 -0
  46. package/credits/views/web/staff.js +265 -0
  47. package/credits/views/web/style.d.ts +9 -0
  48. package/credits/views/web/style.js +190 -0
  49. package/credits/views/web/types.d.ts +17 -0
  50. package/credits/views/web/types.js +32 -0
  51. package/credits/web.d.ts +12 -0
  52. package/credits/web.js +33 -0
  53. package/mod.d.ts +26 -0
  54. package/mod.js +25 -0
  55. package/package.json +61 -4
  56. package/stripe/actions/checkout.d.ts +4 -0
  57. package/stripe/actions/checkout.js +188 -0
  58. package/stripe/actions/fact.d.ts +1 -0
  59. package/stripe/actions/fact.js +39 -0
  60. package/stripe/mod.d.ts +30 -0
  61. package/stripe/mod.js +52 -0
  62. package/stripe/routes/webhook.d.ts +16 -0
  63. package/stripe/routes/webhook.js +56 -0
  64. package/stripe/shared/api.d.ts +14 -0
  65. package/stripe/shared/api.js +42 -0
  66. package/stripe/shared/events.d.ts +42 -0
  67. package/stripe/shared/events.js +226 -0
  68. package/stripe/shared/settings.d.ts +39 -0
  69. package/stripe/shared/settings.js +10 -0
  70. package/web.d.ts +13 -0
  71. package/web.js +13 -0
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Credits an org was given or bought, in USD, appended and never changed: the
3
+ * same `_id` again is the one already kept, so a grant that comes from
4
+ * something (a period, a code, a payment) can't land twice. A negative amount
5
+ * takes credits away.
6
+ */
7
+ import { type Infer } from "copilotz";
8
+ export declare const creditSchema: {
9
+ readonly type: "object";
10
+ readonly properties: {
11
+ readonly kind: {
12
+ readonly type: "string";
13
+ readonly enum: readonly ["trial", "plan", "gift", "referral", "purchase", "waived", "adjustment"];
14
+ };
15
+ readonly amount: {
16
+ readonly type: "number";
17
+ };
18
+ readonly at: {
19
+ readonly type: "string";
20
+ };
21
+ /** The first day (UTC, `YYYY-MM-DD`) it no longer counts; none: it doesn't expire. */
22
+ readonly expires: {
23
+ readonly type: "string";
24
+ };
25
+ /** What to show for it. */
26
+ readonly note: {
27
+ readonly type: "string";
28
+ };
29
+ /** Why it was given, and who gave it: for staff. */
30
+ readonly reason: {
31
+ readonly type: "string";
32
+ };
33
+ readonly by: {
34
+ readonly type: "string";
35
+ };
36
+ /** Taken away, what it comes out of first: a refund, of what the money bought. */
37
+ readonly takes: {
38
+ readonly type: "string";
39
+ };
40
+ /** From a test mode: it stops counting when the app goes live. */
41
+ readonly sandbox: {
42
+ readonly type: "boolean";
43
+ };
44
+ };
45
+ readonly required: readonly ["kind", "amount", "at"];
46
+ };
47
+ export type Credit = Infer<typeof creditSchema> & {
48
+ _id: string;
49
+ };
50
+ export declare const credit: {
51
+ schema: {
52
+ readonly type: "object";
53
+ readonly properties: {
54
+ readonly kind: {
55
+ readonly type: "string";
56
+ readonly enum: readonly ["trial", "plan", "gift", "referral", "purchase", "waived", "adjustment"];
57
+ };
58
+ readonly amount: {
59
+ readonly type: "number";
60
+ };
61
+ readonly at: {
62
+ readonly type: "string";
63
+ };
64
+ /** The first day (UTC, `YYYY-MM-DD`) it no longer counts; none: it doesn't expire. */
65
+ readonly expires: {
66
+ readonly type: "string";
67
+ };
68
+ /** What to show for it. */
69
+ readonly note: {
70
+ readonly type: "string";
71
+ };
72
+ /** Why it was given, and who gave it: for staff. */
73
+ readonly reason: {
74
+ readonly type: "string";
75
+ };
76
+ readonly by: {
77
+ readonly type: "string";
78
+ };
79
+ /** Taken away, what it comes out of first: a refund, of what the money bought. */
80
+ readonly takes: {
81
+ readonly type: "string";
82
+ };
83
+ /** From a test mode: it stops counting when the app goes live. */
84
+ readonly sandbox: {
85
+ readonly type: "boolean";
86
+ };
87
+ };
88
+ readonly required: readonly ["kind", "amount", "at"];
89
+ };
90
+ events?: boolean;
91
+ records?: boolean;
92
+ durable?: false;
93
+ indexes?: string[][];
94
+ private?: string[];
95
+ queries?: Record<string, import("copilotz").QueryDef<{
96
+ [x: string]: unknown;
97
+ expires?: string | undefined;
98
+ note?: string | undefined;
99
+ reason?: string | undefined;
100
+ by?: string | undefined;
101
+ takes?: string | undefined;
102
+ sandbox?: boolean | undefined;
103
+ kind: "trial" | "plan" | "gift" | "referral" | "purchase" | "waived" | "adjustment";
104
+ amount: number;
105
+ at: string;
106
+ } & {
107
+ _id: string;
108
+ }>> | undefined;
109
+ vectors?: string[];
110
+ };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Credits an org was given or bought, in USD, appended and never changed: the
3
+ * same `_id` again is the one already kept, so a grant that comes from
4
+ * something (a period, a code, a payment) can't land twice. A negative amount
5
+ * takes credits away.
6
+ */
7
+ import { defineCollection } from "copilotz";
8
+ export const creditSchema = {
9
+ type: "object",
10
+ properties: {
11
+ kind: {
12
+ type: "string",
13
+ enum: ["trial", "plan", "gift", "referral", "purchase", "waived", "adjustment"],
14
+ },
15
+ amount: { type: "number" },
16
+ at: { type: "string" },
17
+ /** The first day (UTC, `YYYY-MM-DD`) it no longer counts; none: it doesn't expire. */
18
+ expires: { type: "string" },
19
+ /** What to show for it. */
20
+ note: { type: "string" },
21
+ /** Why it was given, and who gave it: for staff. */
22
+ reason: { type: "string" },
23
+ by: { type: "string" },
24
+ /** Taken away, what it comes out of first: a refund, of what the money bought. */
25
+ takes: { type: "string" },
26
+ /** From a test mode: it stops counting when the app goes live. */
27
+ sandbox: { type: "boolean" },
28
+ },
29
+ required: ["kind", "amount", "at"],
30
+ };
31
+ export const credit = defineCollection({ records: true, schema: creditSchema });
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Money that came in, however it came: appended, one for each thing a channel
3
+ * collected (`_id`: `<channel>:<ref>`). What commissions and accounts read,
4
+ * so they never need to know who collected it.
5
+ */
6
+ import { type Infer } from "copilotz";
7
+ export declare const paymentSchema: {
8
+ readonly type: "object";
9
+ readonly properties: {
10
+ /** `manual`, `stripe`… and which account of it (a seller). */
11
+ readonly channel: {
12
+ readonly type: "string";
13
+ };
14
+ readonly seller: {
15
+ readonly type: "string";
16
+ };
17
+ readonly ref: {
18
+ readonly type: "string";
19
+ };
20
+ /** What was collected, in its currency's main unit, before tax. */
21
+ readonly amount: {
22
+ readonly type: "number";
23
+ };
24
+ readonly currency: {
25
+ readonly type: "string";
26
+ };
27
+ /** USD per unit of its currency, when it isn't USD. */
28
+ readonly rate: {
29
+ readonly type: "number";
30
+ };
31
+ /** What the channel kept. */
32
+ readonly fee: {
33
+ readonly type: "number";
34
+ };
35
+ /** What it was for, and the credits it bought (USD). */
36
+ readonly purpose: {
37
+ readonly type: "string";
38
+ readonly enum: readonly ["seats", "credits", "contract", "refund"];
39
+ };
40
+ readonly credits: {
41
+ readonly type: "number";
42
+ };
43
+ readonly note: {
44
+ readonly type: "string";
45
+ };
46
+ readonly by: {
47
+ readonly type: "string";
48
+ };
49
+ /** From a test mode: no real money. */
50
+ readonly sandbox: {
51
+ readonly type: "boolean";
52
+ };
53
+ readonly at: {
54
+ readonly type: "string";
55
+ };
56
+ };
57
+ readonly required: readonly ["channel", "ref", "amount", "currency", "purpose", "at"];
58
+ };
59
+ export type Payment = Infer<typeof paymentSchema> & {
60
+ _id: string;
61
+ };
62
+ export declare const payment: {
63
+ schema: {
64
+ readonly type: "object";
65
+ readonly properties: {
66
+ /** `manual`, `stripe`… and which account of it (a seller). */
67
+ readonly channel: {
68
+ readonly type: "string";
69
+ };
70
+ readonly seller: {
71
+ readonly type: "string";
72
+ };
73
+ readonly ref: {
74
+ readonly type: "string";
75
+ };
76
+ /** What was collected, in its currency's main unit, before tax. */
77
+ readonly amount: {
78
+ readonly type: "number";
79
+ };
80
+ readonly currency: {
81
+ readonly type: "string";
82
+ };
83
+ /** USD per unit of its currency, when it isn't USD. */
84
+ readonly rate: {
85
+ readonly type: "number";
86
+ };
87
+ /** What the channel kept. */
88
+ readonly fee: {
89
+ readonly type: "number";
90
+ };
91
+ /** What it was for, and the credits it bought (USD). */
92
+ readonly purpose: {
93
+ readonly type: "string";
94
+ readonly enum: readonly ["seats", "credits", "contract", "refund"];
95
+ };
96
+ readonly credits: {
97
+ readonly type: "number";
98
+ };
99
+ readonly note: {
100
+ readonly type: "string";
101
+ };
102
+ readonly by: {
103
+ readonly type: "string";
104
+ };
105
+ /** From a test mode: no real money. */
106
+ readonly sandbox: {
107
+ readonly type: "boolean";
108
+ };
109
+ readonly at: {
110
+ readonly type: "string";
111
+ };
112
+ };
113
+ readonly required: readonly ["channel", "ref", "amount", "currency", "purpose", "at"];
114
+ };
115
+ events?: boolean;
116
+ records?: boolean;
117
+ durable?: false;
118
+ indexes?: string[][];
119
+ private?: string[];
120
+ queries?: Record<string, import("copilotz").QueryDef<{
121
+ [x: string]: unknown;
122
+ credits?: number | undefined;
123
+ note?: string | undefined;
124
+ by?: string | undefined;
125
+ sandbox?: boolean | undefined;
126
+ seller?: string | undefined;
127
+ rate?: number | undefined;
128
+ fee?: number | undefined;
129
+ amount: number;
130
+ at: string;
131
+ currency: string;
132
+ channel: string;
133
+ purpose: "credits" | "seats" | "contract" | "refund";
134
+ ref: string;
135
+ } & {
136
+ _id: string;
137
+ }>> | undefined;
138
+ vectors?: string[];
139
+ };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Money that came in, however it came: appended, one for each thing a channel
3
+ * collected (`_id`: `<channel>:<ref>`). What commissions and accounts read,
4
+ * so they never need to know who collected it.
5
+ */
6
+ import { defineCollection } from "copilotz";
7
+ export const paymentSchema = {
8
+ type: "object",
9
+ properties: {
10
+ /** `manual`, `stripe`… and which account of it (a seller). */
11
+ channel: { type: "string" },
12
+ seller: { type: "string" },
13
+ ref: { type: "string" },
14
+ /** What was collected, in its currency's main unit, before tax. */
15
+ amount: { type: "number" },
16
+ currency: { type: "string" },
17
+ /** USD per unit of its currency, when it isn't USD. */
18
+ rate: { type: "number" },
19
+ /** What the channel kept. */
20
+ fee: { type: "number" },
21
+ /** What it was for, and the credits it bought (USD). */
22
+ purpose: { type: "string", enum: ["seats", "credits", "contract", "refund"] },
23
+ credits: { type: "number" },
24
+ note: { type: "string" },
25
+ by: { type: "string" },
26
+ /** From a test mode: no real money. */
27
+ sandbox: { type: "boolean" },
28
+ at: { type: "string" },
29
+ },
30
+ required: ["channel", "ref", "amount", "currency", "purpose", "at"],
31
+ };
32
+ export const payment = defineCollection({ records: true, schema: paymentSchema });