@juo/blocks 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/dist/ExtensionRoot-CZyBNJZY.js +159 -0
- package/dist/block-VhmfGB3N.js +51 -0
- package/dist/block.d.ts +96 -0
- package/dist/block.d.ts.map +1 -0
- package/dist/bridge-DQsM97cH.js +490 -0
- package/dist/context.d.ts +76 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.test.d.ts +2 -0
- package/dist/context.test.d.ts.map +1 -0
- package/dist/core.js +1163 -0
- package/dist/editor/bridge.d.ts +75 -0
- package/dist/editor/bridge.d.ts.map +1 -0
- package/dist/editor/bridge.test.d.ts +2 -0
- package/dist/editor/bridge.test.d.ts.map +1 -0
- package/dist/editor/components.d.ts +31 -0
- package/dist/editor/components.d.ts.map +1 -0
- package/dist/editor/handler.d.ts +10 -0
- package/dist/editor/handler.d.ts.map +1 -0
- package/dist/editor/main.d.ts +17 -0
- package/dist/editor/main.d.ts.map +1 -0
- package/dist/editor/messages.d.ts +233 -0
- package/dist/editor/messages.d.ts.map +1 -0
- package/dist/editor.js +711 -0
- package/dist/flows/MockWorkflowApiAdapter.d.ts +13 -0
- package/dist/flows/MockWorkflowApiAdapter.d.ts.map +1 -0
- package/dist/flows/WorkflowService.d.ts +175 -0
- package/dist/flows/WorkflowService.d.ts.map +1 -0
- package/dist/flows/__tests__/WorkflowService.test.d.ts +2 -0
- package/dist/flows/__tests__/WorkflowService.test.d.ts.map +1 -0
- package/dist/flows/__tests__/defaults.test.d.ts +2 -0
- package/dist/flows/__tests__/defaults.test.d.ts.map +1 -0
- package/dist/flows/__tests__/juo-workflow.test.d.ts +2 -0
- package/dist/flows/__tests__/juo-workflow.test.d.ts.map +1 -0
- package/dist/flows/__tests__/overlay-behavior.test.d.ts +2 -0
- package/dist/flows/__tests__/overlay-behavior.test.d.ts.map +1 -0
- package/dist/flows/__tests__/theme-state-surfaces.test.d.ts +2 -0
- package/dist/flows/__tests__/theme-state-surfaces.test.d.ts.map +1 -0
- package/dist/flows/defaults.d.ts +15 -0
- package/dist/flows/defaults.d.ts.map +1 -0
- package/dist/flows/index.d.ts +4 -0
- package/dist/flows/index.d.ts.map +1 -0
- package/dist/flows/juo-workflow.d.ts +48 -0
- package/dist/flows/juo-workflow.d.ts.map +1 -0
- package/dist/juo-workflow-RSrOuKUH.js +591 -0
- package/dist/main.d.ts +11 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/preact/block.d.ts +21 -0
- package/dist/preact/block.d.ts.map +1 -0
- package/dist/preact/block.test.d.ts +2 -0
- package/dist/preact/block.test.d.ts.map +1 -0
- package/dist/preact/bridge.d.ts +11 -0
- package/dist/preact/bridge.d.ts.map +1 -0
- package/dist/preact/context.d.ts +31 -0
- package/dist/preact/context.d.ts.map +1 -0
- package/dist/preact/main.d.ts +11 -0
- package/dist/preact/main.d.ts.map +1 -0
- package/dist/preact/signals.d.ts +23 -0
- package/dist/preact/signals.d.ts.map +1 -0
- package/dist/preact.js +230 -0
- package/dist/react/block.d.ts +21 -0
- package/dist/react/block.d.ts.map +1 -0
- package/dist/react/block.test.d.ts +2 -0
- package/dist/react/block.test.d.ts.map +1 -0
- package/dist/react/bridge.d.ts +11 -0
- package/dist/react/bridge.d.ts.map +1 -0
- package/dist/react/context.d.ts +28 -0
- package/dist/react/context.d.ts.map +1 -0
- package/dist/react/main.d.ts +11 -0
- package/dist/react/main.d.ts.map +1 -0
- package/dist/react/signals.d.ts +23 -0
- package/dist/react/signals.d.ts.map +1 -0
- package/dist/react.js +205 -0
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/login/index.d.ts +23 -0
- package/dist/services/login/index.d.ts.map +1 -0
- package/dist/services/login/loginService.d.ts +82 -0
- package/dist/services/login/loginService.d.ts.map +1 -0
- package/dist/services/product/adapter.d.ts +20 -0
- package/dist/services/product/adapter.d.ts.map +1 -0
- package/dist/services/product/index.d.ts +5 -0
- package/dist/services/product/index.d.ts.map +1 -0
- package/dist/services/product/productService.d.ts +12 -0
- package/dist/services/product/productService.d.ts.map +1 -0
- package/dist/services/product/types.d.ts +32 -0
- package/dist/services/product/types.d.ts.map +1 -0
- package/dist/services/subscription/adapter.d.ts +49 -0
- package/dist/services/subscription/adapter.d.ts.map +1 -0
- package/dist/services/subscription/index.d.ts +5 -0
- package/dist/services/subscription/index.d.ts.map +1 -0
- package/dist/services/subscription/list.d.ts +22 -0
- package/dist/services/subscription/list.d.ts.map +1 -0
- package/dist/services/subscription/store.d.ts +30 -0
- package/dist/services/subscription/store.d.ts.map +1 -0
- package/dist/services/subscription/subscriptionService.d.ts +12 -0
- package/dist/services/subscription/subscriptionService.d.ts.map +1 -0
- package/dist/services/subscription/types.d.ts +76 -0
- package/dist/services/subscription/types.d.ts.map +1 -0
- package/dist/shared/block.d.ts +17 -0
- package/dist/shared/block.d.ts.map +1 -0
- package/dist/shared/context.d.ts +16 -0
- package/dist/shared/context.d.ts.map +1 -0
- package/dist/shared/signals.d.ts +17 -0
- package/dist/shared/signals.d.ts.map +1 -0
- package/dist/state.d.ts +81 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/theme-state-BZplRS92.js +886 -0
- package/dist/theme-state.d.ts +85 -0
- package/dist/theme-state.d.ts.map +1 -0
- package/dist/theme-state.locales.test.d.ts +2 -0
- package/dist/theme-state.locales.test.d.ts.map +1 -0
- package/dist/translation.d.ts +14 -0
- package/dist/translation.d.ts.map +1 -0
- package/dist/translation.test.d.ts +2 -0
- package/dist/translation.test.d.ts.map +1 -0
- package/dist/utils/index.d.ts +32 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/login.d.ts +11 -0
- package/dist/utils/login.d.ts.map +1 -0
- package/dist/utils/uuid.d.ts +2 -0
- package/dist/utils/uuid.d.ts.map +1 -0
- package/dist/vue/block.d.ts +7 -0
- package/dist/vue/block.d.ts.map +1 -0
- package/dist/vue/bridge.d.ts +11 -0
- package/dist/vue/bridge.d.ts.map +1 -0
- package/dist/vue/context.d.ts +24 -0
- package/dist/vue/context.d.ts.map +1 -0
- package/dist/vue/main.d.ts +6 -0
- package/dist/vue/main.d.ts.map +1 -0
- package/dist/vue/signals.d.ts +5 -0
- package/dist/vue/signals.d.ts.map +1 -0
- package/dist/vue/target.d.ts +2 -0
- package/dist/vue/target.d.ts.map +1 -0
- package/dist/vue/transform.d.ts +2 -0
- package/dist/vue/transform.d.ts.map +1 -0
- package/dist/vue.js +254 -0
- package/dist/web-components/Block.d.ts +17 -0
- package/dist/web-components/Block.d.ts.map +1 -0
- package/dist/web-components/Block.test.d.ts +2 -0
- package/dist/web-components/Block.test.d.ts.map +1 -0
- package/dist/web-components/ExtensionRoot.d.ts +29 -0
- package/dist/web-components/ExtensionRoot.d.ts.map +1 -0
- package/dist/web-components/editor/InlineText.d.ts +29 -0
- package/dist/web-components/editor/InlineText.d.ts.map +1 -0
- package/dist/web-components/editor/main.d.ts +2 -0
- package/dist/web-components/editor/main.d.ts.map +1 -0
- package/dist/web-components/runtime/InlineText.d.ts +6 -0
- package/dist/web-components/runtime/InlineText.d.ts.map +1 -0
- package/dist/web-components/runtime/main.d.ts +2 -0
- package/dist/web-components/runtime/main.d.ts.map +1 -0
- package/dist/web-components-editor.js +183 -0
- package/dist/web-components-runtime.js +55 -0
- package/package.json +62 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Signal } from '@preact/signals-core';
|
|
2
|
+
export declare enum AuthenticationErrorReason {
|
|
3
|
+
Expired = "expired",
|
|
4
|
+
IncorrectCode = "wrong-code",
|
|
5
|
+
TooManyTries = "too-many-tries",
|
|
6
|
+
NoEmail = "no-email",
|
|
7
|
+
Unknown = "unknown",
|
|
8
|
+
Missing = "missing"
|
|
9
|
+
}
|
|
10
|
+
export declare class AuthenticationError extends Error {
|
|
11
|
+
reason: AuthenticationErrorReason;
|
|
12
|
+
data: Record<string, unknown>;
|
|
13
|
+
constructor(reason: AuthenticationErrorReason, data?: Record<string, unknown>);
|
|
14
|
+
}
|
|
15
|
+
interface RouterService {
|
|
16
|
+
push(options: {
|
|
17
|
+
path: string;
|
|
18
|
+
query?: Record<string, string>;
|
|
19
|
+
}): void;
|
|
20
|
+
replace(path: string): void;
|
|
21
|
+
}
|
|
22
|
+
interface ShopService {
|
|
23
|
+
locale: string | Signal<string>;
|
|
24
|
+
domain: string;
|
|
25
|
+
}
|
|
26
|
+
export type ErrorFormatter = (error: unknown | AuthenticationError) => {
|
|
27
|
+
title: string;
|
|
28
|
+
message: string;
|
|
29
|
+
};
|
|
30
|
+
export interface LoginServiceDependencies {
|
|
31
|
+
apiUrl: string;
|
|
32
|
+
formatError: ErrorFormatter;
|
|
33
|
+
router: RouterService;
|
|
34
|
+
shop: ShopService;
|
|
35
|
+
onLoginSuccess?: () => Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @deprecated Use `createLoginService` instead
|
|
39
|
+
*/
|
|
40
|
+
export declare function loginService(deps: {
|
|
41
|
+
formatError: ErrorFormatter;
|
|
42
|
+
getLocale: () => string;
|
|
43
|
+
router: RouterService;
|
|
44
|
+
shop: {
|
|
45
|
+
domain: string;
|
|
46
|
+
rootUrl: string;
|
|
47
|
+
};
|
|
48
|
+
onLoginSuccess?: () => Promise<void>;
|
|
49
|
+
}): {
|
|
50
|
+
passwordless: {
|
|
51
|
+
email: {
|
|
52
|
+
start(email: string): Promise<import('../../utils').Result<void, import('../../utils').ErrorDetails>>;
|
|
53
|
+
verify(email: string, code: string): Promise<import('../../utils').Result<void, import('../../utils').ErrorDetails>>;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
social: {
|
|
57
|
+
start(provider: "Google" | "Facebook"): Promise<import('../../utils').Result<void, import('../../utils').ErrorDetails>>;
|
|
58
|
+
verify(code: string): Promise<import('../../utils').Result<void, import('../../utils').ErrorDetails>>;
|
|
59
|
+
};
|
|
60
|
+
isAuthenticated: Signal<boolean>;
|
|
61
|
+
getToken(): Promise<string | null>;
|
|
62
|
+
handleQueryParams(query: URLSearchParams): Promise<import('../../utils').Result<void, import('../../utils').ErrorDetails>>;
|
|
63
|
+
logout(): Promise<import('../../utils').Result>;
|
|
64
|
+
};
|
|
65
|
+
export declare function createLoginService(init: LoginServiceDependencies): {
|
|
66
|
+
passwordless: {
|
|
67
|
+
email: {
|
|
68
|
+
start(email: string): Promise<import('../../utils').Result<void, import('../../utils').ErrorDetails>>;
|
|
69
|
+
verify(email: string, code: string): Promise<import('../../utils').Result<void, import('../../utils').ErrorDetails>>;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
social: {
|
|
73
|
+
start(provider: "Google" | "Facebook"): Promise<import('../../utils').Result<void, import('../../utils').ErrorDetails>>;
|
|
74
|
+
verify(code: string): Promise<import('../../utils').Result<void, import('../../utils').ErrorDetails>>;
|
|
75
|
+
};
|
|
76
|
+
isAuthenticated: Signal<boolean>;
|
|
77
|
+
getToken(): Promise<string | null>;
|
|
78
|
+
handleQueryParams(query: URLSearchParams): Promise<import('../../utils').Result<void, import('../../utils').ErrorDetails>>;
|
|
79
|
+
logout(): Promise<import('../../utils').Result>;
|
|
80
|
+
};
|
|
81
|
+
export {};
|
|
82
|
+
//# sourceMappingURL=loginService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loginService.d.ts","sourceRoot":"","sources":["../../../src/services/login/loginService.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAMxE,oBAAY,yBAAyB;IACnC,OAAO,YAAY;IACnB,aAAa,eAAe;IAC5B,YAAY,mBAAmB;IAC/B,OAAO,aAAa;IACpB,OAAO,YAAY;IACnB,OAAO,YAAY;CACpB;AAED,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,MAAM,EAAE,yBAAyB,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAG5B,MAAM,EAAE,yBAA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|
|
2
|
+
import { Product, WithVariants } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Adapter interface for product operations.
|
|
5
|
+
* Implementations should handle API calls, error handling, and data transformation.
|
|
6
|
+
*/
|
|
7
|
+
export interface ProductAdapter {
|
|
8
|
+
getById(id: string): Promise<WithVariants<Product> | null>;
|
|
9
|
+
getByVariantId(variantId: string): Promise<WithVariants<Product> | null>;
|
|
10
|
+
search(opts?: {
|
|
11
|
+
query?: string;
|
|
12
|
+
pagination?: {
|
|
13
|
+
before: string;
|
|
14
|
+
} | {
|
|
15
|
+
after: string;
|
|
16
|
+
};
|
|
17
|
+
}): Promise<PaginatedList<WithVariants<Product>>>;
|
|
18
|
+
}
|
|
19
|
+
export declare function createMockProductAdapter(): ProductAdapter;
|
|
20
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/services/product/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAkB,YAAY,EAAE,MAAM,SAAS,CAAC;AAErE;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IAE3D,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IAEzE,MAAM,CAAC,IAAI,CAAC,EAAE;QACZ,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,UAAU,CAAC,EAAE;YAAE,MAAM,EAAE,MAAM,CAAA;SAAE,GAAG;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC;KACrD,GAAG,OAAO,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;CACnD;AAED,wBAAgB,wBAAwB,IAAI,cAAc,CA0JzD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/product/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAErD,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAE/E,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ContextType } from '../../context';
|
|
2
|
+
import { ProductAdapter } from './adapter';
|
|
3
|
+
import { ProductService } from './types';
|
|
4
|
+
export declare const ProductServiceContext: {
|
|
5
|
+
__context__: ProductService;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Creates a product service that uses the provided adapter for data operations.
|
|
9
|
+
* The adapter pattern decouples the service from specific SDK implementations.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createProductService(adapter: ProductAdapter): ContextType<typeof ProductServiceContext>;
|
|
12
|
+
//# sourceMappingURL=productService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"productService.d.ts","sourceRoot":"","sources":["../../../src/services/product/productService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiB,MAAM,eAAe,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,eAAO,MAAM,qBAAqB;;CACiB,CAAC;AAGpD;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,cAAc,GACtB,WAAW,CAAC,OAAO,qBAAqB,CAAC,CAiB3C"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Image, PaginatedList, PriceWithCurrency } from '../../utils';
|
|
2
|
+
export interface Product {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
featuredImage: Image | null;
|
|
6
|
+
hasOnlyDefaultVariant: boolean;
|
|
7
|
+
collections: {
|
|
8
|
+
handle: string;
|
|
9
|
+
}[];
|
|
10
|
+
}
|
|
11
|
+
export interface ProductVariant {
|
|
12
|
+
id: string;
|
|
13
|
+
title: string;
|
|
14
|
+
image: Image | null;
|
|
15
|
+
price: PriceWithCurrency;
|
|
16
|
+
}
|
|
17
|
+
export type WithVariants<T> = T & {
|
|
18
|
+
variants: PaginatedList<ProductVariant>;
|
|
19
|
+
};
|
|
20
|
+
export type ProductService<T extends WithVariants<Product> = WithVariants<Product>> = {
|
|
21
|
+
getById(id: string): Promise<T | null>;
|
|
22
|
+
getByVariantId(variantId: string): Promise<T | null>;
|
|
23
|
+
search(opts?: {
|
|
24
|
+
query?: string;
|
|
25
|
+
pagination?: {
|
|
26
|
+
before: string;
|
|
27
|
+
} | {
|
|
28
|
+
after: string;
|
|
29
|
+
};
|
|
30
|
+
}): Promise<PaginatedList<T>>;
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/services/product/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE3E,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,KAAK,GAAG,IAAI,CAAC;IAC5B,qBAAqB,EAAE,OAAO,CAAC;IAC/B,WAAW,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACnC;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,iBAAiB,CAAC;CAC1B;AAED,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG;IAChC,QAAQ,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,cAAc,CACxB,CAAC,SAAS,YAAY,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,IACrD;IACF,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACvC,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACrD,MAAM,CAAC,IAAI,CAAC,EAAE;QACZ,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,UAAU,CAAC,EAAE;YAAE,MAAM,EAAE,MAAM,CAAA;SAAE,GAAG;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC;KACrD,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;CAC/B,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Subscription, SellingPlan, SearchOptions, PostableSubscriptionItem } from './types';
|
|
2
|
+
import { Result, PaginatedList } from '../../utils';
|
|
3
|
+
/**
|
|
4
|
+
* Adapter interface for subscription.
|
|
5
|
+
* Implementations should handle API calls, error handling, and data transformation.
|
|
6
|
+
*/
|
|
7
|
+
export interface SubscriptionAdapter {
|
|
8
|
+
search(options?: SearchOptions): Promise<Result<PaginatedList<Subscription>>>;
|
|
9
|
+
getById(id: string): Promise<Result<Subscription | null>>;
|
|
10
|
+
addItem(params: {
|
|
11
|
+
subscriptionId: string;
|
|
12
|
+
item: PostableSubscriptionItem;
|
|
13
|
+
}): Promise<Result>;
|
|
14
|
+
removeItem(params: {
|
|
15
|
+
subscriptionId: string;
|
|
16
|
+
itemId: string;
|
|
17
|
+
}): Promise<Result>;
|
|
18
|
+
addDiscount(params: {
|
|
19
|
+
subscriptionId: string;
|
|
20
|
+
code: string;
|
|
21
|
+
}): Promise<Result>;
|
|
22
|
+
removeDiscount(params: {
|
|
23
|
+
subscriptionId: string;
|
|
24
|
+
discountId: string;
|
|
25
|
+
}): Promise<Result>;
|
|
26
|
+
reschedule(params: {
|
|
27
|
+
subscriptionId: string;
|
|
28
|
+
newDate: string;
|
|
29
|
+
}): Promise<Result<Subscription>>;
|
|
30
|
+
resume(params: {
|
|
31
|
+
subscriptionId: string;
|
|
32
|
+
}): Promise<Result<Subscription>>;
|
|
33
|
+
pause(params: {
|
|
34
|
+
subscriptionId: string;
|
|
35
|
+
}): Promise<Result<Subscription>>;
|
|
36
|
+
reactivate(params: {
|
|
37
|
+
subscriptionId: string;
|
|
38
|
+
}): Promise<Result<Subscription>>;
|
|
39
|
+
cancel(params: {
|
|
40
|
+
subscriptionId: string;
|
|
41
|
+
reason?: string;
|
|
42
|
+
}): Promise<Result<Subscription>>;
|
|
43
|
+
getAvailablePlans(params: {
|
|
44
|
+
subscriptionId: string;
|
|
45
|
+
}): Promise<Result<SellingPlan[]>>;
|
|
46
|
+
getDefaultSubscriptionId(): Promise<Result<string | null>>;
|
|
47
|
+
}
|
|
48
|
+
export declare function createMockSubscriptionAdapter(): SubscriptionAdapter;
|
|
49
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/services/subscription/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,aAAa,EACb,wBAAwB,EACzB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEzD;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,OAAO,CAAC,EAAE,aAAa,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MAAM,CAAC,MAAM,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;IAE3F,iBAAiB,CAAC,MAAM,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IAEtF,wBAAwB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;CAC5D;AAED,wBAAgB,6BAA6B,IAAI,mBAAmB,CAyRnE"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { SubscriptionAdapter } from './adapter';
|
|
2
|
+
export { createMockSubscriptionAdapter } from './adapter';
|
|
3
|
+
export { createSubscriptionService, SubscriptionServiceContext } from './subscriptionService';
|
|
4
|
+
export * from './types';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/subscription/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,6BAA6B,EAAE,MAAM,WAAW,CAAC;AAE1D,OAAO,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAE9F,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Signal } from '@preact/signals-core';
|
|
2
|
+
import { Subscription, SearchOptions } from './types';
|
|
3
|
+
import { PaginatedList, PageInfo } from '../../utils';
|
|
4
|
+
import { SubscriptionAdapter } from './adapter';
|
|
5
|
+
export declare class SubscriptionList {
|
|
6
|
+
subscriptions: Signal<Subscription[]>;
|
|
7
|
+
loading: Signal<boolean>;
|
|
8
|
+
pageInfo: Signal<PageInfo>;
|
|
9
|
+
error: Signal<string | null>;
|
|
10
|
+
private adapter;
|
|
11
|
+
private searchOptions;
|
|
12
|
+
private currentCursor;
|
|
13
|
+
constructor(adapter: SubscriptionAdapter, initialData: PaginatedList<Subscription>, searchOptions?: SearchOptions);
|
|
14
|
+
nextPage(): Promise<void>;
|
|
15
|
+
prevPage(): Promise<void>;
|
|
16
|
+
refresh(): Promise<void>;
|
|
17
|
+
private fetchPage;
|
|
18
|
+
get hasNextPage(): boolean;
|
|
19
|
+
get hasPrevPage(): boolean;
|
|
20
|
+
get isLoading(): boolean;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/services/subscription/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACd,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAErD,qBAAa,gBAAgB;IACpB,aAAa,EAAE,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAEpC,OAAO,CAAC,OAAO,CAAsB;IACrC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,aAAa,CAAuD;gBAG1E,OAAO,EAAE,mBAAmB,EAC5B,WAAW,EAAE,aAAa,CAAC,YAAY,CAAC,EACxC,aAAa,GAAE,aAAkB;IAW7B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAUzB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAUzB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAIhB,SAAS;IA6BvB,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;CACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Signal } from '@preact/signals-core';
|
|
2
|
+
import { Subscription, SubscriptionItem, SearchOptions } from './types';
|
|
3
|
+
import { SubscriptionAdapter } from './adapter';
|
|
4
|
+
import { SubscriptionList } from './list';
|
|
5
|
+
import { Result } from '../../utils';
|
|
6
|
+
export interface SingleSubscriptionStore {
|
|
7
|
+
subscription: Signal<Subscription | null>;
|
|
8
|
+
loading: Signal<boolean>;
|
|
9
|
+
error: Signal<string | null>;
|
|
10
|
+
}
|
|
11
|
+
export interface SubscriptionStore {
|
|
12
|
+
search(options?: SearchOptions): Promise<SubscriptionList>;
|
|
13
|
+
getSubscription(id: string): SingleSubscriptionStore;
|
|
14
|
+
addItem(subscriptionId: string, item: Omit<SubscriptionItem, "id">): Promise<Result>;
|
|
15
|
+
removeItem(subscriptionId: string, itemId: string): Promise<Result>;
|
|
16
|
+
addDiscount(subscriptionId: string, code: string): Promise<Result>;
|
|
17
|
+
removeDiscount(subscriptionId: string, discountId: string): Promise<Result>;
|
|
18
|
+
cancel(subscriptionId: string, reason?: string): Promise<Result>;
|
|
19
|
+
reschedule(subscriptionId: string, newDate: string): Promise<Result>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create a subscription store instance.
|
|
23
|
+
* The store provides methods for fetching and mutating subscriptions.
|
|
24
|
+
*
|
|
25
|
+
* @param adapter - The adapter implementation for API calls
|
|
26
|
+
* @returns A subscription store instance
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
export declare function createSubscriptionStore(adapter: SubscriptionAdapter): SubscriptionStore;
|
|
30
|
+
//# sourceMapp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AM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjE,UAAU,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACtE;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,mBAAmB,GAC3B,iBAAiB,CA0FnB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ContextType } from '../../context';
|
|
2
|
+
import { SubscriptionAdapter } from './adapter';
|
|
3
|
+
import { SubscriptionService } from './types';
|
|
4
|
+
export declare const SubscriptionServiceContext: {
|
|
5
|
+
__context__: SubscriptionService;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Creates a subscription service that uses the provided adapter for data operations.
|
|
9
|
+
* The adapter pattern decouples the service from specific SDK implementations.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createSubscriptionService(adapter: SubscriptionAdapter): ContextType<typeof SubscriptionServiceContext>;
|
|
12
|
+
//# sourceMappingURL=subscriptionService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscriptionService.d.ts","sourceRoot":"","sources":["../../../src/services/subscription/subscriptionService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiB,MAAM,eAAe,CAAC;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,KAAK,EAA4B,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE7E,eAAO,MAAM,0BAA0B;;CACsB,CAAC;AAqC9D;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,mBAAmB,GAC3B,WAAW,CAAC,OAAO,0BAA0B,CAAC,CAyBhD"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { PaginatedList, PriceWithCurrency, Result } from '../../utils';
|
|
2
|
+
export interface SubscriptionItem {
|
|
3
|
+
id: string;
|
|
4
|
+
productId: string;
|
|
5
|
+
variantId: string;
|
|
6
|
+
quantity: number;
|
|
7
|
+
price: PriceWithCurrency;
|
|
8
|
+
nextDeliveryDate?: Date | null;
|
|
9
|
+
}
|
|
10
|
+
export interface PostableSubscriptionItem {
|
|
11
|
+
variantId: string;
|
|
12
|
+
quantity: number;
|
|
13
|
+
}
|
|
14
|
+
export interface SubscriptionDiscount {
|
|
15
|
+
id: string;
|
|
16
|
+
type: "percentage" | "fixed_amount";
|
|
17
|
+
value: number;
|
|
18
|
+
code?: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface Subscription {
|
|
22
|
+
id: string;
|
|
23
|
+
items: SubscriptionItem[];
|
|
24
|
+
discounts: SubscriptionDiscount[];
|
|
25
|
+
status: "active" | "paused" | "canceled" | "expired" | "failed";
|
|
26
|
+
nextDeliveryDate: Date | null;
|
|
27
|
+
frequency: string;
|
|
28
|
+
createdAt: string;
|
|
29
|
+
updatedAt: string;
|
|
30
|
+
customerId: string;
|
|
31
|
+
}
|
|
32
|
+
export interface SellingPlanInterval {
|
|
33
|
+
intervalCount: number;
|
|
34
|
+
interval: string;
|
|
35
|
+
}
|
|
36
|
+
export interface SellingPlan {
|
|
37
|
+
id: string;
|
|
38
|
+
name: string;
|
|
39
|
+
billingPolicy: SellingPlanInterval;
|
|
40
|
+
deliveryPolicy: SellingPlanInterval;
|
|
41
|
+
}
|
|
42
|
+
export interface SubscriptionFilter {
|
|
43
|
+
id?: string;
|
|
44
|
+
serial?: string;
|
|
45
|
+
status?: Subscription["status"];
|
|
46
|
+
createdAt?: string;
|
|
47
|
+
updatedAt?: string;
|
|
48
|
+
nextBillingDate?: string;
|
|
49
|
+
canceledAt?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface SearchOptions {
|
|
52
|
+
filters?: SubscriptionFilter[];
|
|
53
|
+
includeCanceledItems?: boolean;
|
|
54
|
+
pagination?: {
|
|
55
|
+
before: string;
|
|
56
|
+
} | {
|
|
57
|
+
after: string;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export type SubscriptionService = {
|
|
61
|
+
search(options?: SearchOptions): Promise<Result<PaginatedList<Subscription>>>;
|
|
62
|
+
getById(id: string): Promise<Result<Subscription | null>>;
|
|
63
|
+
getCurrentSubscriptionId(): string | null;
|
|
64
|
+
addItem(subscriptionId: string, item: PostableSubscriptionItem): Promise<Result>;
|
|
65
|
+
removeItem(subscriptionId: string, itemId: string): Promise<Result>;
|
|
66
|
+
addDiscount(subscriptionId: string, code: string): Promise<Result>;
|
|
67
|
+
removeDiscount(subscriptionId: string, discountId: string): Promise<Result>;
|
|
68
|
+
reschedule(subscriptionId: string, newDate: string): Promise<Result<Subscription>>;
|
|
69
|
+
resume(subscriptionId: string): Promise<Result<Subscription>>;
|
|
70
|
+
pause(subscriptionId: string): Promise<Result<Subscription>>;
|
|
71
|
+
reactivate(subscriptionId: string): Promise<Result<Subscription>>;
|
|
72
|
+
cancel(subscriptionId: string, reason?: string): Promise<Result<Subscription>>;
|
|
73
|
+
getAvailablePlans(subscriptionId: string): Promise<Result<SellingPlan[]>>;
|
|
74
|
+
getDefaultSubscriptionId(): Promise<Result<string | null>>;
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/services/subscription/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE5E,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,iBAAiB,CAAC;IACzB,gBAAgB,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CA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AE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;IAClE,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;IAC/E,iBAAiB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IAC1E,wBAAwB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;CAC5D,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BlockInstance } from '../main.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Renders block slots to DOM elements
|
|
4
|
+
*/
|
|
5
|
+
export declare function renderBlockSlots(slots: any): BlockInstance | BlockInstance[] | string | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Extracts props and slots from a block instance
|
|
8
|
+
*/
|
|
9
|
+
export declare function extractBlockProps(block: BlockInstance): {
|
|
10
|
+
props: any;
|
|
11
|
+
slots: any;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Creates slot children from block instances or strings
|
|
15
|
+
*/
|
|
16
|
+
export declare function createSlotChildren(block: BlockInstance | BlockInstance[] | string): HTMLElement[];
|
|
17
|
+
//# sourceMappingURL=block.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../src/shared/block.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,GAAG,GACT,aAAa,GAAG,aAAa,EAAE,GAAG,MAAM,GAAG,SAAS,CAQtD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,aAAa;;;EAKrD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,aAAa,GAAG,aAAa,EAAE,GAAG,MAAM,GAC9C,WAAW,EAAE,CAUf"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Signal } from '@preact/signals-core';
|
|
2
|
+
/**
|
|
3
|
+
* Type helper to wrap context values, converting signals to framework state tuples
|
|
4
|
+
*/
|
|
5
|
+
export type Wrap<T> = T extends Signal<infer V> ? [V, (value: V) => void] : T extends Function ? T : T extends Record<any, any> ? {
|
|
6
|
+
[K in keyof T]: Wrap<T[K]>;
|
|
7
|
+
} : T;
|
|
8
|
+
/**
|
|
9
|
+
* Wraps a context value, converting signals to framework state tuples
|
|
10
|
+
*
|
|
11
|
+
* @param obj - The context value to wrap
|
|
12
|
+
* @param toState - Function to convert a signal to framework state tuple
|
|
13
|
+
* @returns The wrapped context value
|
|
14
|
+
*/
|
|
15
|
+
export declare function wrapContext<T>(obj: T, toState: <V extends object>(signal: Signal<V>) => [V, (value: V) => void]): Wrap<T>;
|
|
16
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/shared/context.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C;;GAEG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,CAAC,GAC3C,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC,GACvB,CAAC,SAAS,QAAQ,GAClB,CAAC,GACD,CAAC,SAAS,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAC1B;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC3B,GACD,CAAC,CAAC;AAEN;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,GAAG,EAAE,CAAC,EACN,OAAO,EAAE,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC,GACxE,IAAI,CAAC,CAAC,CAAC,CAeT"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Signal } from '../main.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Converts a framework state or value to an Blocks signal
|
|
4
|
+
*
|
|
5
|
+
* @param value - Framework state or value to convert
|
|
6
|
+
* @returns An Blocks signal that tracks the value
|
|
7
|
+
*/
|
|
8
|
+
export declare function toSignal<T extends object>(value: T | (() => T)): Signal<T>;
|
|
9
|
+
/**
|
|
10
|
+
* Gets the current value from a signal or computed function
|
|
11
|
+
*/
|
|
12
|
+
export declare function getSignalValue<T>(signal: Signal<T> | (() => T)): T;
|
|
13
|
+
/**
|
|
14
|
+
* Sets the value of a signal (throws if it's a computed function)
|
|
15
|
+
*/
|
|
16
|
+
export declare function setSignalValue<T>(signal: Signal<T> | (() => T), value: T): void;
|
|
17
|
+
//# sourceMappingURL=signals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signals.d.ts","sourceRoot":"","sources":["../../src/shared/signals.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAU,MAAM,EAAE,MAAM,aAAa,CAAC;AAI7C;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAc1E;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAElE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAC7B,KAAK,EAAE,CAAC,GACP,IAAI,CAKN"}
|
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
type Product = {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
price: number;
|
|
6
|
+
imageUrl: string;
|
|
7
|
+
};
|
|
8
|
+
type Item = {
|
|
9
|
+
id: string;
|
|
10
|
+
productId: string;
|
|
11
|
+
quantity: number;
|
|
12
|
+
price: number;
|
|
13
|
+
};
|
|
14
|
+
type Subscription = {
|
|
15
|
+
id: string;
|
|
16
|
+
items: Item[];
|
|
17
|
+
status: "active";
|
|
18
|
+
nextDeliveryDate: string;
|
|
19
|
+
frequency: string;
|
|
20
|
+
quantity: number;
|
|
21
|
+
createdAt: string;
|
|
22
|
+
};
|
|
23
|
+
export declare function createState(): {
|
|
24
|
+
discountCode: import('@preact/signals-core').Signal<string | null>;
|
|
25
|
+
products: import('@preact/signals-core').Signal<Product[]>;
|
|
26
|
+
upcomingOrder: import('@preact/signals-core').ReadonlySignal<{
|
|
27
|
+
subtotal: number;
|
|
28
|
+
totalDiscount: number;
|
|
29
|
+
deliveryPrice: number;
|
|
30
|
+
totalPrice: number;
|
|
31
|
+
hasFreeProduct: boolean;
|
|
32
|
+
id: string;
|
|
33
|
+
items: Item[];
|
|
34
|
+
status: "active";
|
|
35
|
+
nextDeliveryDate: string;
|
|
36
|
+
frequency: string;
|
|
37
|
+
quantity: number;
|
|
38
|
+
createdAt: string;
|
|
39
|
+
} | null>;
|
|
40
|
+
subscriptions: import('@preact/signals-core').Signal<Subscription[]>;
|
|
41
|
+
user: import('@preact/signals-core').Signal<{
|
|
42
|
+
name: string;
|
|
43
|
+
}>;
|
|
44
|
+
setDiscountCode(code: string): void;
|
|
45
|
+
addProduct(product: Product): void;
|
|
46
|
+
getProductById(id: string): Product;
|
|
47
|
+
addItemToUpcomingOrder(item: Omit<Item, "price">): void;
|
|
48
|
+
addSubscription(subscription: Subscription): void;
|
|
49
|
+
};
|
|
50
|
+
/** @deprecated Use sepcialized services instead */
|
|
51
|
+
export declare const StateContext: {
|
|
52
|
+
__context__: {
|
|
53
|
+
discountCode: import('@preact/signals-core').Signal<string | null>;
|
|
54
|
+
products: import('@preact/signals-core').Signal<Product[]>;
|
|
55
|
+
upcomingOrder: import('@preact/signals-core').ReadonlySignal<{
|
|
56
|
+
subtotal: number;
|
|
57
|
+
totalDiscount: number;
|
|
58
|
+
deliveryPrice: number;
|
|
59
|
+
totalPrice: number;
|
|
60
|
+
hasFreeProduct: boolean;
|
|
61
|
+
id: string;
|
|
62
|
+
items: Item[];
|
|
63
|
+
status: "active";
|
|
64
|
+
nextDeliveryDate: string;
|
|
65
|
+
frequency: string;
|
|
66
|
+
quantity: number;
|
|
67
|
+
createdAt: string;
|
|
68
|
+
} | null>;
|
|
69
|
+
subscriptions: import('@preact/signals-core').Signal<Subscription[]>;
|
|
70
|
+
user: import('@preact/signals-core').Signal<{
|
|
71
|
+
name: string;
|
|
72
|
+
}>;
|
|
73
|
+
setDiscountCode(code: string): void;
|
|
74
|
+
addProduct(product: Product): void;
|
|
75
|
+
getProductById(id: string): Product;
|
|
76
|
+
addItemToUpcomingOrder(item: Omit<Item, "price">): void;
|
|
77
|
+
addSubscription(subscription: Subscription): void;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
export {};
|
|
81
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAGA,KAAK,OAAO,GAAG;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,IAAI,GAAG;IACV,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,KAAK,YAAY,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,MAAM,EAAE,QAAQ,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,wBAAgB,WAAW;;;;;;;;;YATrB,MAAM;eACH,IAAI,EAAE;gBACL,QAAQ;0BACE,MAAM;mBACb,MAAM;kBACP,MAAM;mBACL,MAAM;;;;;;0BAgDO,MAAM;wBAGR,OAAO;uBAGR,MAAM;iCAOI,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC;kCAclB,YAAY;EAI7C;AAED,mDAAmD;AACnD,eAAO,MAAM,YAAY;;;;;;;;;;gBAxFnB,MAAM;mBACH,IAAI,EAAE;oBACL,QAAQ;8BACE,MAAM;uBACb,MAAM;sBACP,MAAM;uBACL,MAAM;;;;;;8BAgDO,MAAM;4BAGR,OAAO;2BAGR,MAAM;qCAOI,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC;sCAclB,YAAY;;CAOW,CAAC"}
|