zpan-cloud-sdk 1.0.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 +13 -0
- package/dist/chunk-VMYIHGPC.js +218 -0
- package/dist/index.d.ts +3111 -0
- package/dist/index.js +111 -0
- package/dist/schemas-R0lkMmfq.d.ts +366 -0
- package/dist/schemas.d.ts +2 -0
- package/dist/schemas.js +58 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# zpan-cloud-sdk
|
|
2
|
+
|
|
3
|
+
Public TypeScript SDK and API contract for ZPan Cloud.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { createCloudClient } from 'zpan-cloud-sdk'
|
|
7
|
+
import type { ZpanCloudEvent } from 'zpan-cloud-sdk'
|
|
8
|
+
|
|
9
|
+
const cloud = createCloudClient({
|
|
10
|
+
baseUrl: 'https://cloud.example.com/api',
|
|
11
|
+
token: process.env.ZPAN_CLOUD_TOKEN,
|
|
12
|
+
})
|
|
13
|
+
```
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// src/schemas.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var paginationQuerySchema = z.object({
|
|
4
|
+
limit: z.coerce.number().int().min(1).max(100).optional().default(50),
|
|
5
|
+
offset: z.coerce.number().int().min(0).optional().default(0)
|
|
6
|
+
});
|
|
7
|
+
var createPairingSchema = z.object({
|
|
8
|
+
instanceId: z.string().min(1).max(255),
|
|
9
|
+
instanceName: z.string().min(1).max(255),
|
|
10
|
+
instanceHost: z.string().min(1).max(512)
|
|
11
|
+
});
|
|
12
|
+
var pairingActionSchema = z.object({
|
|
13
|
+
action: z.enum(["approve", "deny"])
|
|
14
|
+
});
|
|
15
|
+
var productPriceSchema = z.object({
|
|
16
|
+
id: z.string().min(1).optional(),
|
|
17
|
+
currency: z.string().min(1),
|
|
18
|
+
amount: z.number().int().positive(),
|
|
19
|
+
lookupKey: z.string().min(1).nullable().optional(),
|
|
20
|
+
nickname: z.string().nullable().optional(),
|
|
21
|
+
recurring: z.object({
|
|
22
|
+
interval: z.enum(["day", "week", "month", "year"]),
|
|
23
|
+
intervalCount: z.number().int().positive(),
|
|
24
|
+
usageType: z.enum(["licensed", "metered"]).optional()
|
|
25
|
+
}).nullable().optional(),
|
|
26
|
+
metadata: z.record(z.string(), z.string()).optional()
|
|
27
|
+
});
|
|
28
|
+
var deliverableSchema = z.record(z.string(), z.unknown());
|
|
29
|
+
var productMetadataSchema = z.object({
|
|
30
|
+
deliverable: deliverableSchema
|
|
31
|
+
});
|
|
32
|
+
function isTrafficMeteredPrice(price) {
|
|
33
|
+
return price.recurring?.usageType === "metered" && price.metadata?.usageResource === "traffic_egress";
|
|
34
|
+
}
|
|
35
|
+
function validateTrafficMeteredPricePairs(prices, ctx) {
|
|
36
|
+
if (!prices) return;
|
|
37
|
+
for (const [index, price] of prices.entries()) {
|
|
38
|
+
if (price.recurring && (price.recurring.interval !== "month" || price.recurring.intervalCount !== 1)) {
|
|
39
|
+
ctx.addIssue({
|
|
40
|
+
code: z.ZodIssueCode.custom,
|
|
41
|
+
path: ["prices", index, "recurring"],
|
|
42
|
+
message: "Subscription prices must bill monthly"
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (price.recurring?.usageType === "metered" && price.metadata?.usageResource !== "traffic_egress") {
|
|
46
|
+
ctx.addIssue({
|
|
47
|
+
code: z.ZodIssueCode.custom,
|
|
48
|
+
path: ["prices", index],
|
|
49
|
+
message: "Metered traffic prices must set usageResource to traffic_egress"
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (price.metadata?.usageResource === "traffic_egress" && price.recurring?.usageType !== "metered") {
|
|
53
|
+
ctx.addIssue({
|
|
54
|
+
code: z.ZodIssueCode.custom,
|
|
55
|
+
path: ["prices", index],
|
|
56
|
+
message: "Traffic overage prices must use metered billing"
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const recurringPrices = prices.filter((price) => price.recurring);
|
|
61
|
+
const currencies = new Set(recurringPrices.map((price) => price.currency));
|
|
62
|
+
for (const currency of currencies) {
|
|
63
|
+
const monthlyCount = recurringPrices.filter(
|
|
64
|
+
(price) => price.currency === currency && !isTrafficMeteredPrice(price)
|
|
65
|
+
).length;
|
|
66
|
+
if (monthlyCount !== 1) {
|
|
67
|
+
ctx.addIssue({
|
|
68
|
+
code: z.ZodIssueCode.custom,
|
|
69
|
+
path: ["prices"],
|
|
70
|
+
message: `Subscription prices for ${currency} must have exactly one monthly price`
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const meteredCount = recurringPrices.filter(
|
|
74
|
+
(price) => price.currency === currency && isTrafficMeteredPrice(price)
|
|
75
|
+
).length;
|
|
76
|
+
if (meteredCount === 1) continue;
|
|
77
|
+
ctx.addIssue({
|
|
78
|
+
code: z.ZodIssueCode.custom,
|
|
79
|
+
path: ["prices"],
|
|
80
|
+
message: `Subscription prices for ${currency} must have exactly one metered traffic price`
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
var createProductSchema = z.object({
|
|
85
|
+
type: z.literal("store_item"),
|
|
86
|
+
name: z.string().min(1),
|
|
87
|
+
description: z.string().nullable().optional(),
|
|
88
|
+
active: z.boolean().optional(),
|
|
89
|
+
sortOrder: z.number().int().optional(),
|
|
90
|
+
metadata: productMetadataSchema,
|
|
91
|
+
prices: z.array(productPriceSchema).min(1)
|
|
92
|
+
}).superRefine((input, ctx) => validateTrafficMeteredPricePairs(input.prices, ctx));
|
|
93
|
+
var updateProductSchema = z.object({
|
|
94
|
+
type: z.literal("store_item").optional(),
|
|
95
|
+
name: z.string().min(1).optional(),
|
|
96
|
+
description: z.string().nullable().optional(),
|
|
97
|
+
active: z.boolean().optional(),
|
|
98
|
+
sortOrder: z.number().int().optional(),
|
|
99
|
+
metadata: productMetadataSchema.optional(),
|
|
100
|
+
prices: z.array(productPriceSchema).min(1).optional()
|
|
101
|
+
}).superRefine((input, ctx) => validateTrafficMeteredPricePairs(input.prices, ctx));
|
|
102
|
+
var productListQuerySchema = paginationQuerySchema.extend({
|
|
103
|
+
type: z.literal("store_item").optional(),
|
|
104
|
+
status: z.enum(["active", "inactive"]).optional()
|
|
105
|
+
});
|
|
106
|
+
var orderItemSchema = z.object({
|
|
107
|
+
productId: z.string().min(1),
|
|
108
|
+
priceId: z.string().min(1).optional(),
|
|
109
|
+
quantity: z.number().int().positive().optional().default(1)
|
|
110
|
+
});
|
|
111
|
+
var createOrderSchema = z.object({
|
|
112
|
+
items: z.array(orderItemSchema).min(1),
|
|
113
|
+
currency: z.string().min(1),
|
|
114
|
+
target: z.record(z.string(), z.unknown()).nullable().optional(),
|
|
115
|
+
deliveryCallbackUrl: z.string().url().optional(),
|
|
116
|
+
idempotencyKey: z.string().nullable().optional()
|
|
117
|
+
});
|
|
118
|
+
var orderListQuerySchema = paginationQuerySchema.extend({
|
|
119
|
+
paymentStatus: z.enum(["unpaid", "pending", "paid", "failed", "refunded", "canceled"]).optional(),
|
|
120
|
+
fulfillmentStatus: z.enum(["pending", "fulfilled", "failed", "canceled"]).optional(),
|
|
121
|
+
customerId: z.string().min(1).optional()
|
|
122
|
+
});
|
|
123
|
+
var paymentSchema = z.object({
|
|
124
|
+
successUrl: z.string().optional(),
|
|
125
|
+
cancelUrl: z.string().optional()
|
|
126
|
+
}).strict();
|
|
127
|
+
var billingPortalSessionSchema = z.object({
|
|
128
|
+
customerId: z.string().min(1),
|
|
129
|
+
returnUrl: z.string().url()
|
|
130
|
+
}).strict();
|
|
131
|
+
var orderPatchSchema = z.object({
|
|
132
|
+
status: z.enum(["canceled"])
|
|
133
|
+
});
|
|
134
|
+
var giftCardCreateSchema = z.object({
|
|
135
|
+
amount: z.number().int().positive(),
|
|
136
|
+
currency: z.string().min(1),
|
|
137
|
+
expiresAt: z.string().optional().nullable(),
|
|
138
|
+
campaignId: z.string().optional().nullable(),
|
|
139
|
+
count: z.number().int().min(1).max(100).optional().default(1)
|
|
140
|
+
});
|
|
141
|
+
var giftCardCampaignCreateSchema = z.object({
|
|
142
|
+
name: z.string().trim().min(1),
|
|
143
|
+
startsAt: z.string().optional().nullable(),
|
|
144
|
+
expiresAt: z.string().optional().nullable()
|
|
145
|
+
});
|
|
146
|
+
var giftCardPatchSchema = z.object({
|
|
147
|
+
disabled: z.boolean().optional(),
|
|
148
|
+
revoked: z.literal(true).optional()
|
|
149
|
+
});
|
|
150
|
+
var giftCardListQuerySchema = paginationQuerySchema.extend({
|
|
151
|
+
status: z.enum(["active", "redeemed", "disabled", "expired", "revoked"]).optional(),
|
|
152
|
+
campaignId: z.string().optional()
|
|
153
|
+
});
|
|
154
|
+
var giftCardCampaignListQuerySchema = paginationQuerySchema.extend({
|
|
155
|
+
status: z.enum(["active", "disabled", "ended"]).optional()
|
|
156
|
+
});
|
|
157
|
+
var usageEventCreateSchema = z.object({
|
|
158
|
+
resource: z.literal("traffic_egress"),
|
|
159
|
+
quantity: z.number().int().positive().optional(),
|
|
160
|
+
bytes: z.number().int().positive().optional(),
|
|
161
|
+
idempotencyKey: z.string().trim().min(1).max(200).optional(),
|
|
162
|
+
eventId: z.string().trim().min(1).max(200).optional(),
|
|
163
|
+
customerId: z.string().trim().min(1)
|
|
164
|
+
}).strict().refine((value) => value.quantity !== void 0 || value.bytes !== void 0, "quantity_required").refine((value) => value.idempotencyKey !== void 0 || value.eventId !== void 0, "idempotency_key_required");
|
|
165
|
+
var accountUsagePeriodSchema = z.string().regex(/^\d{4}-(0[1-9]|1[0-2])$/);
|
|
166
|
+
var accountUsageQuerySchema = z.object({
|
|
167
|
+
customerId: z.string().trim().min(1)
|
|
168
|
+
}).strict();
|
|
169
|
+
var walletRedemptionSchema = z.object({
|
|
170
|
+
codes: z.array(z.string().trim().min(1)).min(1).max(10)
|
|
171
|
+
});
|
|
172
|
+
var accountBillingQuerySchema = paginationQuerySchema.extend({
|
|
173
|
+
ledgerLimit: z.coerce.number().int().min(1).max(100).optional().default(25),
|
|
174
|
+
ledgerOffset: z.coerce.number().int().min(0).optional().default(0)
|
|
175
|
+
});
|
|
176
|
+
var storePatchSchema = z.object({
|
|
177
|
+
name: z.string().min(1).optional(),
|
|
178
|
+
status: z.enum(["active", "disabled"]).optional()
|
|
179
|
+
});
|
|
180
|
+
var adminUserPatchSchema = z.object({
|
|
181
|
+
role: z.enum(["user", "admin"]).optional(),
|
|
182
|
+
membershipTier: z.enum(["none", "silver", "gold", "premier"]).optional(),
|
|
183
|
+
membershipStatus: z.enum(["active", "inactive", "expired"]).optional()
|
|
184
|
+
}).refine((value) => Object.keys(value).length > 0, { message: "at least one field is required" });
|
|
185
|
+
var adminUserListQuerySchema = paginationQuerySchema.extend({
|
|
186
|
+
search: z.string().trim().optional(),
|
|
187
|
+
membershipTier: z.enum(["none", "silver", "gold", "premier"]).optional()
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
export {
|
|
191
|
+
paginationQuerySchema,
|
|
192
|
+
createPairingSchema,
|
|
193
|
+
pairingActionSchema,
|
|
194
|
+
productPriceSchema,
|
|
195
|
+
deliverableSchema,
|
|
196
|
+
productMetadataSchema,
|
|
197
|
+
createProductSchema,
|
|
198
|
+
updateProductSchema,
|
|
199
|
+
productListQuerySchema,
|
|
200
|
+
createOrderSchema,
|
|
201
|
+
orderListQuerySchema,
|
|
202
|
+
paymentSchema,
|
|
203
|
+
billingPortalSessionSchema,
|
|
204
|
+
orderPatchSchema,
|
|
205
|
+
giftCardCreateSchema,
|
|
206
|
+
giftCardCampaignCreateSchema,
|
|
207
|
+
giftCardPatchSchema,
|
|
208
|
+
giftCardListQuerySchema,
|
|
209
|
+
giftCardCampaignListQuerySchema,
|
|
210
|
+
usageEventCreateSchema,
|
|
211
|
+
accountUsagePeriodSchema,
|
|
212
|
+
accountUsageQuerySchema,
|
|
213
|
+
walletRedemptionSchema,
|
|
214
|
+
accountBillingQuerySchema,
|
|
215
|
+
storePatchSchema,
|
|
216
|
+
adminUserPatchSchema,
|
|
217
|
+
adminUserListQuerySchema
|
|
218
|
+
};
|