🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@cherryport/shared

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cherryport/shared - npm Package Compare versions

Comparing version
0.1.0
to
0.2.0
+155
-1
dist/index.d.mts

@@ -0,3 +1,33 @@

type UniRequestMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | "HEAD";
type UniRequestOptions = {
method?: UniRequestMethod;
data?: unknown;
auth?: boolean;
silent?: boolean;
};
type TokenProvider = () => string | Promise<string>;
type UniRequestConfig = {
baseUrl: string;
getToken?: TokenProvider;
onRequestError?: (message: string, options: UniRequestOptions) => void;
onNetworkError?: (options: UniRequestOptions) => void;
};
declare function createUniRequest(config: UniRequestConfig): <T>(path: string, options?: UniRequestOptions) => Promise<T>;
type TokenStorage = {
getToken: () => string;
setToken: (token: string) => void;
clearToken: () => void;
};
declare function createTokenStorage(tokenKey: string): TokenStorage;
type OrderStatus = "pending" | "paid" | "shipped" | "delivered" | "refunded";
type ProductStatus = "active" | "inactive";
type LeaderStatus = "pending" | "active" | "inactive";
type GroupStatus = "open" | "success" | "failed";
type CouponStatus = "active" | "inactive" | "expired";
type CouponUsageStatus = "unused" | "used" | "expired";
type ReviewStatus = "pending" | "approved" | "rejected";
type AfterSaleStatus = "requested" | "approved" | "rejected" | "processing" | "completed";
type CommissionStatus = "pending" | "settled" | "canceled";
interface ApiResponse<T> {

@@ -14,2 +44,3 @@ code: number;

group_price?: number | null;
cost_price?: number | null;
stock: number;

@@ -19,2 +50,3 @@ status: ProductStatus;

spec?: string | null;
sold_count?: number | null;
created_at: string;

@@ -26,7 +58,14 @@ updated_at: string;

product_id: string;
title?: string | null;
type: string;
price: number;
min_members?: number | null;
max_members?: number | null;
group_duration_hours?: number | null;
start_at?: string | null;
end_at?: string | null;
status: string;
rule_text?: string | null;
created_at?: string | null;
updated_at?: string | null;
}

@@ -50,2 +89,10 @@ interface OrderItem {

activity_id?: string | null;
group_id?: string | null;
leader_id?: string | null;
coupon_id?: string | null;
discount_amount?: number | null;
cost_amount?: number | null;
gross_margin_rate?: number | null;
risk_flag?: number | null;
risk_reason?: string | null;
created_at: string;

@@ -81,3 +128,110 @@ paid_at?: string | null;

}
interface LeaderProfile {
id: string;
name: string;
phone?: string | null;
status: LeaderStatus;
level: string;
commission_rate: number;
code: string;
created_at: string;
updated_at: string;
}
interface GroupInfo {
id: string;
activity_id: string;
product_id: string;
leader_id?: string | null;
creator_user_id?: string | null;
status: GroupStatus;
required_size: number;
current_size: number;
expires_at?: string | null;
created_at: string;
updated_at: string;
}
interface GroupMember {
id: string;
group_id: string;
user_id: string;
order_id: string;
role: "leader" | "member";
status: "joined" | "paid" | "refunded";
joined_at: string;
}
interface Coupon {
id: string;
code: string;
title: string;
discount_type: "amount" | "percent";
discount_value: number;
min_amount?: number | null;
start_at?: string | null;
end_at?: string | null;
total?: number | null;
used?: number | null;
per_user_limit?: number | null;
status: CouponStatus;
created_at: string;
updated_at: string;
}
interface UserCoupon {
id: string;
user_id: string;
coupon_id: string;
status: CouponUsageStatus;
claimed_at: string;
used_at?: string | null;
order_id?: string | null;
}
interface Review {
id: string;
order_id: string;
product_id: string;
user_id: string;
rating: number;
content?: string | null;
images?: string | null;
status: ReviewStatus;
created_at: string;
updated_at: string;
}
interface AfterSale {
id: string;
order_id: string;
user_id: string;
type: "refund" | "return" | "exchange";
reason?: string | null;
status: AfterSaleStatus;
amount?: number | null;
created_at: string;
updated_at: string;
}
interface Commission {
id: string;
leader_id: string;
order_id: string;
amount: number;
status: CommissionStatus;
created_at: string;
settled_at?: string | null;
}
interface AuditLog {
id: string;
actor_type: "admin" | "leader" | "user" | "system";
actor_id?: string | null;
action: string;
target_type?: string | null;
target_id?: string | null;
detail?: string | null;
created_at: string;
}
interface AnalyticsEvent {
id: string;
user_id?: string | null;
name: string;
payload?: string | null;
created_at: string;
}
export type { Activity, ApiResponse, LogisticsInfo, LogisticsTrace, Order, OrderItem, OrderStatus, Product, ProductStatus };
export { type Activity, type AfterSale, type AfterSaleStatus, type AnalyticsEvent, type ApiResponse, type AuditLog, type Commission, type CommissionStatus, type Coupon, type CouponStatus, type CouponUsageStatus, type GroupInfo, type GroupMember, type GroupStatus, type LeaderProfile, type LeaderStatus, type LogisticsInfo, type LogisticsTrace, type Order, type OrderItem, type OrderStatus, type Product, type ProductStatus, type Review, type ReviewStatus, type TokenStorage, type UniRequestConfig, type UniRequestMethod, type UniRequestOptions, type UserCoupon, createTokenStorage, createUniRequest };

@@ -0,3 +1,33 @@

type UniRequestMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | "HEAD";
type UniRequestOptions = {
method?: UniRequestMethod;
data?: unknown;
auth?: boolean;
silent?: boolean;
};
type TokenProvider = () => string | Promise<string>;
type UniRequestConfig = {
baseUrl: string;
getToken?: TokenProvider;
onRequestError?: (message: string, options: UniRequestOptions) => void;
onNetworkError?: (options: UniRequestOptions) => void;
};
declare function createUniRequest(config: UniRequestConfig): <T>(path: string, options?: UniRequestOptions) => Promise<T>;
type TokenStorage = {
getToken: () => string;
setToken: (token: string) => void;
clearToken: () => void;
};
declare function createTokenStorage(tokenKey: string): TokenStorage;
type OrderStatus = "pending" | "paid" | "shipped" | "delivered" | "refunded";
type ProductStatus = "active" | "inactive";
type LeaderStatus = "pending" | "active" | "inactive";
type GroupStatus = "open" | "success" | "failed";
type CouponStatus = "active" | "inactive" | "expired";
type CouponUsageStatus = "unused" | "used" | "expired";
type ReviewStatus = "pending" | "approved" | "rejected";
type AfterSaleStatus = "requested" | "approved" | "rejected" | "processing" | "completed";
type CommissionStatus = "pending" | "settled" | "canceled";
interface ApiResponse<T> {

@@ -14,2 +44,3 @@ code: number;

group_price?: number | null;
cost_price?: number | null;
stock: number;

@@ -19,2 +50,3 @@ status: ProductStatus;

spec?: string | null;
sold_count?: number | null;
created_at: string;

@@ -26,7 +58,14 @@ updated_at: string;

product_id: string;
title?: string | null;
type: string;
price: number;
min_members?: number | null;
max_members?: number | null;
group_duration_hours?: number | null;
start_at?: string | null;
end_at?: string | null;
status: string;
rule_text?: string | null;
created_at?: string | null;
updated_at?: string | null;
}

@@ -50,2 +89,10 @@ interface OrderItem {

activity_id?: string | null;
group_id?: string | null;
leader_id?: string | null;
coupon_id?: string | null;
discount_amount?: number | null;
cost_amount?: number | null;
gross_margin_rate?: number | null;
risk_flag?: number | null;
risk_reason?: string | null;
created_at: string;

@@ -81,3 +128,110 @@ paid_at?: string | null;

}
interface LeaderProfile {
id: string;
name: string;
phone?: string | null;
status: LeaderStatus;
level: string;
commission_rate: number;
code: string;
created_at: string;
updated_at: string;
}
interface GroupInfo {
id: string;
activity_id: string;
product_id: string;
leader_id?: string | null;
creator_user_id?: string | null;
status: GroupStatus;
required_size: number;
current_size: number;
expires_at?: string | null;
created_at: string;
updated_at: string;
}
interface GroupMember {
id: string;
group_id: string;
user_id: string;
order_id: string;
role: "leader" | "member";
status: "joined" | "paid" | "refunded";
joined_at: string;
}
interface Coupon {
id: string;
code: string;
title: string;
discount_type: "amount" | "percent";
discount_value: number;
min_amount?: number | null;
start_at?: string | null;
end_at?: string | null;
total?: number | null;
used?: number | null;
per_user_limit?: number | null;
status: CouponStatus;
created_at: string;
updated_at: string;
}
interface UserCoupon {
id: string;
user_id: string;
coupon_id: string;
status: CouponUsageStatus;
claimed_at: string;
used_at?: string | null;
order_id?: string | null;
}
interface Review {
id: string;
order_id: string;
product_id: string;
user_id: string;
rating: number;
content?: string | null;
images?: string | null;
status: ReviewStatus;
created_at: string;
updated_at: string;
}
interface AfterSale {
id: string;
order_id: string;
user_id: string;
type: "refund" | "return" | "exchange";
reason?: string | null;
status: AfterSaleStatus;
amount?: number | null;
created_at: string;
updated_at: string;
}
interface Commission {
id: string;
leader_id: string;
order_id: string;
amount: number;
status: CommissionStatus;
created_at: string;
settled_at?: string | null;
}
interface AuditLog {
id: string;
actor_type: "admin" | "leader" | "user" | "system";
actor_id?: string | null;
action: string;
target_type?: string | null;
target_id?: string | null;
detail?: string | null;
created_at: string;
}
interface AnalyticsEvent {
id: string;
user_id?: string | null;
name: string;
payload?: string | null;
created_at: string;
}
export type { Activity, ApiResponse, LogisticsInfo, LogisticsTrace, Order, OrderItem, OrderStatus, Product, ProductStatus };
export { type Activity, type AfterSale, type AfterSaleStatus, type AnalyticsEvent, type ApiResponse, type AuditLog, type Commission, type CommissionStatus, type Coupon, type CouponStatus, type CouponUsageStatus, type GroupInfo, type GroupMember, type GroupStatus, type LeaderProfile, type LeaderStatus, type LogisticsInfo, type LogisticsTrace, type Order, type OrderItem, type OrderStatus, type Product, type ProductStatus, type Review, type ReviewStatus, type TokenStorage, type UniRequestConfig, type UniRequestMethod, type UniRequestOptions, type UserCoupon, createTokenStorage, createUniRequest };

@@ -6,2 +6,6 @@ "use strict";

var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {

@@ -19,2 +23,57 @@ if (from && typeof from === "object" || typeof from === "function") {

var index_exports = {};
__export(index_exports, {
createTokenStorage: () => createTokenStorage,
createUniRequest: () => createUniRequest
});
module.exports = __toCommonJS(index_exports);
// src/uni/request.ts
function createUniRequest(config) {
const { baseUrl, getToken, onRequestError, onNetworkError } = config;
return async function request(path, options = {}) {
const token = options.auth === false ? "" : getToken ? await getToken() : "";
return new Promise((resolve, reject) => {
uni.request({
url: `${baseUrl}${path}`,
method: options.method || "GET",
data: options.data,
header: {
"Content-Type": "application/json",
...token ? { Authorization: `Bearer ${token}` } : {}
},
success: (res) => {
const payload = res.data;
if (res.statusCode >= 200 && res.statusCode < 300 && payload.code === 0) {
resolve(payload.data);
} else {
const message = payload.message || "request_failed";
if (onRequestError) {
onRequestError(message, options);
}
reject(new Error(message));
}
},
fail: (err) => {
if (onNetworkError) {
onNetworkError(options);
}
reject(err);
}
});
});
};
}
// src/uni/storage.ts
function createTokenStorage(tokenKey) {
return {
getToken: () => uni.getStorageSync(tokenKey) || "",
setToken: (token) => uni.setStorageSync(tokenKey, token),
clearToken: () => uni.removeStorageSync(tokenKey)
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
createTokenStorage,
createUniRequest
});
{
"name": "@cherryport/shared",
"version": "0.1.0",
"version": "0.2.0",
"repository": {
"type": "git",
"url": "https://github.com/cherryport/cherry.git",
"directory": "packages/shared"
},
"license": "MIT",

@@ -5,0 +10,0 @@ "main": "dist/index.js",