@cross-deck/node 0.1.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/CHANGELOG.md +27 -0
- package/LICENSE +21 -0
- package/README.md +238 -0
- package/dist/index.cjs +595 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +187 -0
- package/dist/index.d.ts +187 -0
- package/dist/index.mjs +563 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +57 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
type Environment = "production" | "sandbox";
|
|
2
|
+
type AuditRail = "apple" | "stripe" | "google" | "manual";
|
|
3
|
+
interface PublicEntitlement {
|
|
4
|
+
object: "entitlement";
|
|
5
|
+
key: string;
|
|
6
|
+
isActive: boolean;
|
|
7
|
+
validUntil?: number | null;
|
|
8
|
+
source: {
|
|
9
|
+
rail: AuditRail;
|
|
10
|
+
productId: string;
|
|
11
|
+
subscriptionId: string;
|
|
12
|
+
};
|
|
13
|
+
updatedAt: number;
|
|
14
|
+
}
|
|
15
|
+
interface EntitlementsListResponse {
|
|
16
|
+
object: "list";
|
|
17
|
+
data: PublicEntitlement[];
|
|
18
|
+
crossdeckCustomerId: string;
|
|
19
|
+
env: Environment;
|
|
20
|
+
}
|
|
21
|
+
interface AliasResult {
|
|
22
|
+
object: "alias_result";
|
|
23
|
+
crossdeckCustomerId: string;
|
|
24
|
+
linked: Array<{
|
|
25
|
+
type: "developer";
|
|
26
|
+
id: string;
|
|
27
|
+
} | {
|
|
28
|
+
type: "anonymous";
|
|
29
|
+
id: string;
|
|
30
|
+
}>;
|
|
31
|
+
mergePending: boolean;
|
|
32
|
+
env: Environment;
|
|
33
|
+
}
|
|
34
|
+
interface IngestResponse {
|
|
35
|
+
object: "list";
|
|
36
|
+
received: number;
|
|
37
|
+
env: Environment;
|
|
38
|
+
throttled?: {
|
|
39
|
+
dropped: number;
|
|
40
|
+
sampleRate: number;
|
|
41
|
+
retryAfterMs: number;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
interface PurchaseResult {
|
|
45
|
+
object: "purchase_result";
|
|
46
|
+
crossdeckCustomerId: string;
|
|
47
|
+
env: Environment;
|
|
48
|
+
entitlements: PublicEntitlement[];
|
|
49
|
+
}
|
|
50
|
+
interface ForgetResult {
|
|
51
|
+
object: "forgot";
|
|
52
|
+
crossdeckCustomerId: string | null;
|
|
53
|
+
queuedAt: number;
|
|
54
|
+
env: Environment;
|
|
55
|
+
}
|
|
56
|
+
interface CrossdeckServerOptions {
|
|
57
|
+
secretKey: string;
|
|
58
|
+
baseUrl?: string;
|
|
59
|
+
timeoutMs?: number;
|
|
60
|
+
sdkVersion?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Optional informational appId stamped onto event batches. The server
|
|
63
|
+
* ultimately trusts the API key's resolved app routing, so this is
|
|
64
|
+
* best-effort metadata only.
|
|
65
|
+
*/
|
|
66
|
+
appId?: string;
|
|
67
|
+
}
|
|
68
|
+
interface IdentityHints {
|
|
69
|
+
customerId?: string;
|
|
70
|
+
userId?: string;
|
|
71
|
+
anonymousId?: string;
|
|
72
|
+
}
|
|
73
|
+
interface IdentifyOptions {
|
|
74
|
+
email?: string;
|
|
75
|
+
traits?: Record<string, unknown>;
|
|
76
|
+
}
|
|
77
|
+
interface AliasIdentityInput extends IdentifyOptions {
|
|
78
|
+
userId: string;
|
|
79
|
+
anonymousId: string;
|
|
80
|
+
}
|
|
81
|
+
type ErrorLevel = "error" | "warning" | "info";
|
|
82
|
+
interface ServerEvent {
|
|
83
|
+
eventId?: string;
|
|
84
|
+
name: string;
|
|
85
|
+
timestamp?: number;
|
|
86
|
+
properties?: Record<string, unknown>;
|
|
87
|
+
developerUserId?: string;
|
|
88
|
+
anonymousId?: string;
|
|
89
|
+
crossdeckCustomerId?: string;
|
|
90
|
+
level?: ErrorLevel;
|
|
91
|
+
tags?: Record<string, string>;
|
|
92
|
+
categoryTags?: string[];
|
|
93
|
+
}
|
|
94
|
+
interface IngestOptions {
|
|
95
|
+
idempotencyKey?: string;
|
|
96
|
+
}
|
|
97
|
+
interface SyncPurchaseInput {
|
|
98
|
+
rail?: "apple";
|
|
99
|
+
signedTransactionInfo: string;
|
|
100
|
+
signedRenewalInfo?: string;
|
|
101
|
+
appAccountToken?: string;
|
|
102
|
+
}
|
|
103
|
+
type GrantDuration = "P30D" | "P90D" | "P1Y" | "lifetime";
|
|
104
|
+
interface GrantEntitlementInput {
|
|
105
|
+
customerId: string;
|
|
106
|
+
entitlementKey: string;
|
|
107
|
+
duration: GrantDuration;
|
|
108
|
+
reason: string;
|
|
109
|
+
}
|
|
110
|
+
interface RevokeEntitlementInput {
|
|
111
|
+
customerId: string;
|
|
112
|
+
entitlementKey: string;
|
|
113
|
+
reason: string;
|
|
114
|
+
}
|
|
115
|
+
interface EntitlementMutationResult {
|
|
116
|
+
object: "entitlement_mutation";
|
|
117
|
+
action: "grant" | "revoke";
|
|
118
|
+
crossdeckCustomerId: string;
|
|
119
|
+
entitlement: PublicEntitlement;
|
|
120
|
+
env: Environment;
|
|
121
|
+
}
|
|
122
|
+
type AuditDecision = "applied" | "no_op" | "rejected";
|
|
123
|
+
interface AuditEntry {
|
|
124
|
+
eventId: string;
|
|
125
|
+
rail: AuditRail;
|
|
126
|
+
env: Environment;
|
|
127
|
+
eventType: string;
|
|
128
|
+
projectId: string;
|
|
129
|
+
subscriptionId?: string;
|
|
130
|
+
customerId?: string;
|
|
131
|
+
fromState?: string;
|
|
132
|
+
toState?: string;
|
|
133
|
+
decision: AuditDecision;
|
|
134
|
+
reason?: string;
|
|
135
|
+
derivedSignal?: string;
|
|
136
|
+
signatureVerified: boolean;
|
|
137
|
+
reconciledWithProvider: boolean;
|
|
138
|
+
rawEventReceivedAt: number;
|
|
139
|
+
processedAt: number;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
declare class CrossdeckServer {
|
|
143
|
+
private readonly http;
|
|
144
|
+
private readonly sdkVersion;
|
|
145
|
+
private readonly appId?;
|
|
146
|
+
constructor(options: CrossdeckServerOptions);
|
|
147
|
+
identify(userId: string, anonymousId: string, options?: IdentifyOptions): Promise<AliasResult>;
|
|
148
|
+
aliasIdentity(input: AliasIdentityInput): Promise<AliasResult>;
|
|
149
|
+
forget(hints: IdentityHints): Promise<ForgetResult>;
|
|
150
|
+
getEntitlements(hints: IdentityHints): Promise<EntitlementsListResponse>;
|
|
151
|
+
getCustomerEntitlements(customerId: string): Promise<EntitlementsListResponse>;
|
|
152
|
+
track(event: ServerEvent, options?: IngestOptions): Promise<IngestResponse>;
|
|
153
|
+
ingest(events: ServerEvent[], options?: IngestOptions): Promise<IngestResponse>;
|
|
154
|
+
syncPurchases(input: SyncPurchaseInput): Promise<PurchaseResult>;
|
|
155
|
+
grantEntitlement(input: GrantEntitlementInput): Promise<EntitlementMutationResult>;
|
|
156
|
+
revokeEntitlement(input: RevokeEntitlementInput): Promise<EntitlementMutationResult>;
|
|
157
|
+
getAuditEntry(eventId: string): Promise<AuditEntry>;
|
|
158
|
+
private identityPayload;
|
|
159
|
+
private normalizeEvent;
|
|
160
|
+
private mintEventId;
|
|
161
|
+
private mintBatchId;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
type CrossdeckErrorType = "authentication_error" | "permission_error" | "invalid_request_error" | "rate_limit_error" | "internal_error" | "network_error" | "configuration_error";
|
|
165
|
+
interface CrossdeckErrorPayload {
|
|
166
|
+
type: CrossdeckErrorType;
|
|
167
|
+
code: string;
|
|
168
|
+
message: string;
|
|
169
|
+
requestId?: string;
|
|
170
|
+
status?: number;
|
|
171
|
+
retryAfterMs?: number;
|
|
172
|
+
}
|
|
173
|
+
declare class CrossdeckError extends Error {
|
|
174
|
+
readonly type: CrossdeckErrorType;
|
|
175
|
+
readonly code: string;
|
|
176
|
+
readonly requestId?: string;
|
|
177
|
+
readonly status?: number;
|
|
178
|
+
readonly retryAfterMs?: number;
|
|
179
|
+
constructor(payload: CrossdeckErrorPayload);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
declare const SDK_NAME = "@cross-deck/node";
|
|
183
|
+
declare const SDK_VERSION = "0.1.0";
|
|
184
|
+
declare const DEFAULT_BASE_URL = "https://api.cross-deck.com/v1";
|
|
185
|
+
declare const DEFAULT_TIMEOUT_MS = 15000;
|
|
186
|
+
|
|
187
|
+
export { type AliasIdentityInput, type AliasResult, type AuditDecision, type AuditEntry, CrossdeckError, type CrossdeckErrorPayload, type CrossdeckErrorType, CrossdeckServer, type CrossdeckServerOptions, DEFAULT_BASE_URL, DEFAULT_TIMEOUT_MS, type EntitlementMutationResult, type EntitlementsListResponse, type Environment, type ErrorLevel, type ForgetResult, type GrantDuration, type GrantEntitlementInput, type IdentifyOptions, type IdentityHints, type IngestOptions, type IngestResponse, type PublicEntitlement, type RevokeEntitlementInput, SDK_NAME, SDK_VERSION, type ServerEvent, type SyncPurchaseInput };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
type Environment = "production" | "sandbox";
|
|
2
|
+
type AuditRail = "apple" | "stripe" | "google" | "manual";
|
|
3
|
+
interface PublicEntitlement {
|
|
4
|
+
object: "entitlement";
|
|
5
|
+
key: string;
|
|
6
|
+
isActive: boolean;
|
|
7
|
+
validUntil?: number | null;
|
|
8
|
+
source: {
|
|
9
|
+
rail: AuditRail;
|
|
10
|
+
productId: string;
|
|
11
|
+
subscriptionId: string;
|
|
12
|
+
};
|
|
13
|
+
updatedAt: number;
|
|
14
|
+
}
|
|
15
|
+
interface EntitlementsListResponse {
|
|
16
|
+
object: "list";
|
|
17
|
+
data: PublicEntitlement[];
|
|
18
|
+
crossdeckCustomerId: string;
|
|
19
|
+
env: Environment;
|
|
20
|
+
}
|
|
21
|
+
interface AliasResult {
|
|
22
|
+
object: "alias_result";
|
|
23
|
+
crossdeckCustomerId: string;
|
|
24
|
+
linked: Array<{
|
|
25
|
+
type: "developer";
|
|
26
|
+
id: string;
|
|
27
|
+
} | {
|
|
28
|
+
type: "anonymous";
|
|
29
|
+
id: string;
|
|
30
|
+
}>;
|
|
31
|
+
mergePending: boolean;
|
|
32
|
+
env: Environment;
|
|
33
|
+
}
|
|
34
|
+
interface IngestResponse {
|
|
35
|
+
object: "list";
|
|
36
|
+
received: number;
|
|
37
|
+
env: Environment;
|
|
38
|
+
throttled?: {
|
|
39
|
+
dropped: number;
|
|
40
|
+
sampleRate: number;
|
|
41
|
+
retryAfterMs: number;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
interface PurchaseResult {
|
|
45
|
+
object: "purchase_result";
|
|
46
|
+
crossdeckCustomerId: string;
|
|
47
|
+
env: Environment;
|
|
48
|
+
entitlements: PublicEntitlement[];
|
|
49
|
+
}
|
|
50
|
+
interface ForgetResult {
|
|
51
|
+
object: "forgot";
|
|
52
|
+
crossdeckCustomerId: string | null;
|
|
53
|
+
queuedAt: number;
|
|
54
|
+
env: Environment;
|
|
55
|
+
}
|
|
56
|
+
interface CrossdeckServerOptions {
|
|
57
|
+
secretKey: string;
|
|
58
|
+
baseUrl?: string;
|
|
59
|
+
timeoutMs?: number;
|
|
60
|
+
sdkVersion?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Optional informational appId stamped onto event batches. The server
|
|
63
|
+
* ultimately trusts the API key's resolved app routing, so this is
|
|
64
|
+
* best-effort metadata only.
|
|
65
|
+
*/
|
|
66
|
+
appId?: string;
|
|
67
|
+
}
|
|
68
|
+
interface IdentityHints {
|
|
69
|
+
customerId?: string;
|
|
70
|
+
userId?: string;
|
|
71
|
+
anonymousId?: string;
|
|
72
|
+
}
|
|
73
|
+
interface IdentifyOptions {
|
|
74
|
+
email?: string;
|
|
75
|
+
traits?: Record<string, unknown>;
|
|
76
|
+
}
|
|
77
|
+
interface AliasIdentityInput extends IdentifyOptions {
|
|
78
|
+
userId: string;
|
|
79
|
+
anonymousId: string;
|
|
80
|
+
}
|
|
81
|
+
type ErrorLevel = "error" | "warning" | "info";
|
|
82
|
+
interface ServerEvent {
|
|
83
|
+
eventId?: string;
|
|
84
|
+
name: string;
|
|
85
|
+
timestamp?: number;
|
|
86
|
+
properties?: Record<string, unknown>;
|
|
87
|
+
developerUserId?: string;
|
|
88
|
+
anonymousId?: string;
|
|
89
|
+
crossdeckCustomerId?: string;
|
|
90
|
+
level?: ErrorLevel;
|
|
91
|
+
tags?: Record<string, string>;
|
|
92
|
+
categoryTags?: string[];
|
|
93
|
+
}
|
|
94
|
+
interface IngestOptions {
|
|
95
|
+
idempotencyKey?: string;
|
|
96
|
+
}
|
|
97
|
+
interface SyncPurchaseInput {
|
|
98
|
+
rail?: "apple";
|
|
99
|
+
signedTransactionInfo: string;
|
|
100
|
+
signedRenewalInfo?: string;
|
|
101
|
+
appAccountToken?: string;
|
|
102
|
+
}
|
|
103
|
+
type GrantDuration = "P30D" | "P90D" | "P1Y" | "lifetime";
|
|
104
|
+
interface GrantEntitlementInput {
|
|
105
|
+
customerId: string;
|
|
106
|
+
entitlementKey: string;
|
|
107
|
+
duration: GrantDuration;
|
|
108
|
+
reason: string;
|
|
109
|
+
}
|
|
110
|
+
interface RevokeEntitlementInput {
|
|
111
|
+
customerId: string;
|
|
112
|
+
entitlementKey: string;
|
|
113
|
+
reason: string;
|
|
114
|
+
}
|
|
115
|
+
interface EntitlementMutationResult {
|
|
116
|
+
object: "entitlement_mutation";
|
|
117
|
+
action: "grant" | "revoke";
|
|
118
|
+
crossdeckCustomerId: string;
|
|
119
|
+
entitlement: PublicEntitlement;
|
|
120
|
+
env: Environment;
|
|
121
|
+
}
|
|
122
|
+
type AuditDecision = "applied" | "no_op" | "rejected";
|
|
123
|
+
interface AuditEntry {
|
|
124
|
+
eventId: string;
|
|
125
|
+
rail: AuditRail;
|
|
126
|
+
env: Environment;
|
|
127
|
+
eventType: string;
|
|
128
|
+
projectId: string;
|
|
129
|
+
subscriptionId?: string;
|
|
130
|
+
customerId?: string;
|
|
131
|
+
fromState?: string;
|
|
132
|
+
toState?: string;
|
|
133
|
+
decision: AuditDecision;
|
|
134
|
+
reason?: string;
|
|
135
|
+
derivedSignal?: string;
|
|
136
|
+
signatureVerified: boolean;
|
|
137
|
+
reconciledWithProvider: boolean;
|
|
138
|
+
rawEventReceivedAt: number;
|
|
139
|
+
processedAt: number;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
declare class CrossdeckServer {
|
|
143
|
+
private readonly http;
|
|
144
|
+
private readonly sdkVersion;
|
|
145
|
+
private readonly appId?;
|
|
146
|
+
constructor(options: CrossdeckServerOptions);
|
|
147
|
+
identify(userId: string, anonymousId: string, options?: IdentifyOptions): Promise<AliasResult>;
|
|
148
|
+
aliasIdentity(input: AliasIdentityInput): Promise<AliasResult>;
|
|
149
|
+
forget(hints: IdentityHints): Promise<ForgetResult>;
|
|
150
|
+
getEntitlements(hints: IdentityHints): Promise<EntitlementsListResponse>;
|
|
151
|
+
getCustomerEntitlements(customerId: string): Promise<EntitlementsListResponse>;
|
|
152
|
+
track(event: ServerEvent, options?: IngestOptions): Promise<IngestResponse>;
|
|
153
|
+
ingest(events: ServerEvent[], options?: IngestOptions): Promise<IngestResponse>;
|
|
154
|
+
syncPurchases(input: SyncPurchaseInput): Promise<PurchaseResult>;
|
|
155
|
+
grantEntitlement(input: GrantEntitlementInput): Promise<EntitlementMutationResult>;
|
|
156
|
+
revokeEntitlement(input: RevokeEntitlementInput): Promise<EntitlementMutationResult>;
|
|
157
|
+
getAuditEntry(eventId: string): Promise<AuditEntry>;
|
|
158
|
+
private identityPayload;
|
|
159
|
+
private normalizeEvent;
|
|
160
|
+
private mintEventId;
|
|
161
|
+
private mintBatchId;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
type CrossdeckErrorType = "authentication_error" | "permission_error" | "invalid_request_error" | "rate_limit_error" | "internal_error" | "network_error" | "configuration_error";
|
|
165
|
+
interface CrossdeckErrorPayload {
|
|
166
|
+
type: CrossdeckErrorType;
|
|
167
|
+
code: string;
|
|
168
|
+
message: string;
|
|
169
|
+
requestId?: string;
|
|
170
|
+
status?: number;
|
|
171
|
+
retryAfterMs?: number;
|
|
172
|
+
}
|
|
173
|
+
declare class CrossdeckError extends Error {
|
|
174
|
+
readonly type: CrossdeckErrorType;
|
|
175
|
+
readonly code: string;
|
|
176
|
+
readonly requestId?: string;
|
|
177
|
+
readonly status?: number;
|
|
178
|
+
readonly retryAfterMs?: number;
|
|
179
|
+
constructor(payload: CrossdeckErrorPayload);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
declare const SDK_NAME = "@cross-deck/node";
|
|
183
|
+
declare const SDK_VERSION = "0.1.0";
|
|
184
|
+
declare const DEFAULT_BASE_URL = "https://api.cross-deck.com/v1";
|
|
185
|
+
declare const DEFAULT_TIMEOUT_MS = 15000;
|
|
186
|
+
|
|
187
|
+
export { type AliasIdentityInput, type AliasResult, type AuditDecision, type AuditEntry, CrossdeckError, type CrossdeckErrorPayload, type CrossdeckErrorType, CrossdeckServer, type CrossdeckServerOptions, DEFAULT_BASE_URL, DEFAULT_TIMEOUT_MS, type EntitlementMutationResult, type EntitlementsListResponse, type Environment, type ErrorLevel, type ForgetResult, type GrantDuration, type GrantEntitlementInput, type IdentifyOptions, type IdentityHints, type IngestOptions, type IngestResponse, type PublicEntitlement, type RevokeEntitlementInput, SDK_NAME, SDK_VERSION, type ServerEvent, type SyncPurchaseInput };
|