@oursprivacy/platform-sdk 1.12.0 → 1.14.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.
Files changed (152) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +35 -0
  3. package/client.d.mts +32 -14
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +32 -14
  6. package/client.d.ts.map +1 -1
  7. package/client.js +26 -4
  8. package/client.js.map +1 -1
  9. package/client.mjs +26 -4
  10. package/client.mjs.map +1 -1
  11. package/core/pagination.d.mts +60 -0
  12. package/core/pagination.d.mts.map +1 -0
  13. package/core/pagination.d.ts +60 -0
  14. package/core/pagination.d.ts.map +1 -0
  15. package/core/pagination.js +101 -0
  16. package/core/pagination.js.map +1 -0
  17. package/core/pagination.mjs +95 -0
  18. package/core/pagination.mjs.map +1 -0
  19. package/index.d.mts +1 -0
  20. package/index.d.mts.map +1 -1
  21. package/index.d.ts +1 -0
  22. package/index.d.ts.map +1 -1
  23. package/index.js +3 -1
  24. package/index.js.map +1 -1
  25. package/index.mjs +1 -0
  26. package/index.mjs.map +1 -1
  27. package/package.json +11 -1
  28. package/pagination.d.mts +2 -0
  29. package/pagination.d.mts.map +1 -0
  30. package/pagination.d.ts +2 -0
  31. package/pagination.d.ts.map +1 -0
  32. package/pagination.js +6 -0
  33. package/pagination.js.map +1 -0
  34. package/pagination.mjs +2 -0
  35. package/pagination.mjs.map +1 -0
  36. package/resources/allowed-events.d.mts +18 -18
  37. package/resources/allowed-events.d.mts.map +1 -1
  38. package/resources/allowed-events.d.ts +18 -18
  39. package/resources/allowed-events.d.ts.map +1 -1
  40. package/resources/allowed-events.js +7 -7
  41. package/resources/allowed-events.js.map +1 -1
  42. package/resources/allowed-events.mjs +7 -7
  43. package/resources/allowed-events.mjs.map +1 -1
  44. package/resources/consent-settings.d.mts +2568 -124
  45. package/resources/consent-settings.d.mts.map +1 -1
  46. package/resources/consent-settings.d.ts +2568 -124
  47. package/resources/consent-settings.d.ts.map +1 -1
  48. package/resources/consent-settings.js +24 -7
  49. package/resources/consent-settings.js.map +1 -1
  50. package/resources/consent-settings.mjs +24 -7
  51. package/resources/consent-settings.mjs.map +1 -1
  52. package/resources/destinations.d.mts +33 -32
  53. package/resources/destinations.d.mts.map +1 -1
  54. package/resources/destinations.d.ts +33 -32
  55. package/resources/destinations.d.ts.map +1 -1
  56. package/resources/destinations.js +8 -7
  57. package/resources/destinations.js.map +1 -1
  58. package/resources/destinations.mjs +8 -7
  59. package/resources/destinations.mjs.map +1 -1
  60. package/resources/experiment-settings.d.mts +277 -0
  61. package/resources/experiment-settings.d.mts.map +1 -0
  62. package/resources/experiment-settings.d.ts +277 -0
  63. package/resources/experiment-settings.d.ts.map +1 -0
  64. package/resources/experiment-settings.js +77 -0
  65. package/resources/experiment-settings.js.map +1 -0
  66. package/resources/experiment-settings.mjs +73 -0
  67. package/resources/experiment-settings.mjs.map +1 -0
  68. package/resources/experiment-variants.d.mts +653 -0
  69. package/resources/experiment-variants.d.mts.map +1 -0
  70. package/resources/experiment-variants.d.ts +653 -0
  71. package/resources/experiment-variants.d.ts.map +1 -0
  72. package/resources/experiment-variants.js +86 -0
  73. package/resources/experiment-variants.js.map +1 -0
  74. package/resources/experiment-variants.mjs +82 -0
  75. package/resources/experiment-variants.mjs.map +1 -0
  76. package/resources/experiments.d.mts +2002 -0
  77. package/resources/experiments.d.mts.map +1 -0
  78. package/resources/experiments.d.ts +2002 -0
  79. package/resources/experiments.d.ts.map +1 -0
  80. package/resources/experiments.js +166 -0
  81. package/resources/experiments.js.map +1 -0
  82. package/resources/experiments.mjs +162 -0
  83. package/resources/experiments.mjs.map +1 -0
  84. package/resources/global-dispatch-centers.d.mts +125 -58
  85. package/resources/global-dispatch-centers.d.mts.map +1 -1
  86. package/resources/global-dispatch-centers.d.ts +125 -58
  87. package/resources/global-dispatch-centers.d.ts.map +1 -1
  88. package/resources/global-dispatch-centers.js +10 -7
  89. package/resources/global-dispatch-centers.js.map +1 -1
  90. package/resources/global-dispatch-centers.mjs +10 -7
  91. package/resources/global-dispatch-centers.mjs.map +1 -1
  92. package/resources/index.d.mts +11 -7
  93. package/resources/index.d.mts.map +1 -1
  94. package/resources/index.d.ts +11 -7
  95. package/resources/index.d.ts.map +1 -1
  96. package/resources/index.js +9 -1
  97. package/resources/index.js.map +1 -1
  98. package/resources/index.mjs +4 -0
  99. package/resources/index.mjs.map +1 -1
  100. package/resources/mappings.d.mts +138 -0
  101. package/resources/mappings.d.mts.map +1 -0
  102. package/resources/mappings.d.ts +138 -0
  103. package/resources/mappings.d.ts.map +1 -0
  104. package/resources/mappings.js +45 -0
  105. package/resources/mappings.js.map +1 -0
  106. package/resources/mappings.mjs +41 -0
  107. package/resources/mappings.mjs.map +1 -0
  108. package/resources/replay-settings.d.mts +48 -48
  109. package/resources/replay-settings.d.mts.map +1 -1
  110. package/resources/replay-settings.d.ts +48 -48
  111. package/resources/replay-settings.d.ts.map +1 -1
  112. package/resources/replay-settings.js +13 -8
  113. package/resources/replay-settings.js.map +1 -1
  114. package/resources/replay-settings.mjs +13 -8
  115. package/resources/replay-settings.mjs.map +1 -1
  116. package/resources/sources.d.mts +64 -27
  117. package/resources/sources.d.mts.map +1 -1
  118. package/resources/sources.d.ts +64 -27
  119. package/resources/sources.d.ts.map +1 -1
  120. package/resources/sources.js +14 -7
  121. package/resources/sources.js.map +1 -1
  122. package/resources/sources.mjs +14 -7
  123. package/resources/sources.mjs.map +1 -1
  124. package/resources/versions.d.mts +742 -16
  125. package/resources/versions.d.mts.map +1 -1
  126. package/resources/versions.d.ts +742 -16
  127. package/resources/versions.d.ts.map +1 -1
  128. package/resources/versions.js +45 -5
  129. package/resources/versions.js.map +1 -1
  130. package/resources/versions.mjs +45 -5
  131. package/resources/versions.mjs.map +1 -1
  132. package/src/client.ts +210 -29
  133. package/src/core/pagination.ts +165 -0
  134. package/src/index.ts +1 -0
  135. package/src/pagination.ts +2 -0
  136. package/src/resources/allowed-events.ts +27 -27
  137. package/src/resources/consent-settings.ts +3036 -244
  138. package/src/resources/destinations.ts +128 -127
  139. package/src/resources/experiment-settings.ts +367 -0
  140. package/src/resources/experiment-variants.ts +868 -0
  141. package/src/resources/experiments.ts +2446 -0
  142. package/src/resources/global-dispatch-centers.ts +155 -65
  143. package/src/resources/index.ts +77 -7
  144. package/src/resources/mappings.ts +236 -0
  145. package/src/resources/replay-settings.ts +67 -59
  146. package/src/resources/sources.ts +116 -71
  147. package/src/resources/versions.ts +1130 -17
  148. package/src/version.ts +1 -1
  149. package/version.d.mts +1 -1
  150. package/version.d.ts +1 -1
  151. package/version.js +1 -1
  152. package/version.mjs +1 -1
@@ -0,0 +1,165 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { OursPrivacyPlatformError } from './error';
4
+ import { FinalRequestOptions } from '../internal/request-options';
5
+ import { defaultParseResponse } from '../internal/parse';
6
+ import { type OursPrivacyPlatform } from '../client';
7
+ import { APIPromise } from './api-promise';
8
+ import { type APIResponseProps } from '../internal/parse';
9
+ import { maybeObj } from '../internal/utils/values';
10
+
11
+ export type PageRequestOptions = Pick<FinalRequestOptions, 'query' | 'headers' | 'body' | 'path' | 'method'>;
12
+
13
+ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
14
+ #client: OursPrivacyPlatform;
15
+ protected options: FinalRequestOptions;
16
+
17
+ protected response: Response;
18
+ protected body: unknown;
19
+
20
+ constructor(client: OursPrivacyPlatform, response: Response, body: unknown, options: FinalRequestOptions) {
21
+ this.#client = client;
22
+ this.options = options;
23
+ this.response = response;
24
+ this.body = body;
25
+ }
26
+
27
+ abstract nextPageRequestOptions(): PageRequestOptions | null;
28
+
29
+ abstract getPaginatedItems(): Item[];
30
+
31
+ hasNextPage(): boolean {
32
+ const items = this.getPaginatedItems();
33
+ if (!items.length) return false;
34
+ return this.nextPageRequestOptions() != null;
35
+ }
36
+
37
+ async getNextPage(): Promise<this> {
38
+ const nextOptions = this.nextPageRequestOptions();
39
+ if (!nextOptions) {
40
+ throw new OursPrivacyPlatformError(
41
+ 'No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.',
42
+ );
43
+ }
44
+
45
+ return await this.#client.requestAPIList(this.constructor as any, nextOptions);
46
+ }
47
+
48
+ async *iterPages(): AsyncGenerator<this> {
49
+ let page: this = this;
50
+ yield page;
51
+ while (page.hasNextPage()) {
52
+ page = await page.getNextPage();
53
+ yield page;
54
+ }
55
+ }
56
+
57
+ async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
58
+ for await (const page of this.iterPages()) {
59
+ for (const item of page.getPaginatedItems()) {
60
+ yield item;
61
+ }
62
+ }
63
+ }
64
+ }
65
+
66
+ /**
67
+ * This subclass of Promise will resolve to an instantiated Page once the request completes.
68
+ *
69
+ * It also implements AsyncIterable to allow auto-paginating iteration on an unawaited list call, eg:
70
+ *
71
+ * for await (const item of client.items.list()) {
72
+ * console.log(item)
73
+ * }
74
+ */
75
+ export class PagePromise<
76
+ PageClass extends AbstractPage<Item>,
77
+ Item = ReturnType<PageClass['getPaginatedItems']>[number],
78
+ >
79
+ extends APIPromise<PageClass>
80
+ implements AsyncIterable<Item>
81
+ {
82
+ constructor(
83
+ client: OursPrivacyPlatform,
84
+ request: Promise<APIResponseProps>,
85
+ Page: new (...args: ConstructorParameters<typeof AbstractPage>) => PageClass,
86
+ ) {
87
+ super(
88
+ client,
89
+ request,
90
+ async (client, props) =>
91
+ new Page(client, props.response, await defaultParseResponse(client, props), props.options),
92
+ );
93
+ }
94
+
95
+ /**
96
+ * Allow auto-paginating iteration on an unawaited list call, eg:
97
+ *
98
+ * for await (const item of client.items.list()) {
99
+ * console.log(item)
100
+ * }
101
+ */
102
+ async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
103
+ const page = await this;
104
+ for await (const item of page) {
105
+ yield item;
106
+ }
107
+ }
108
+ }
109
+
110
+ export interface CursorResponse<Item> {
111
+ entities: Array<Item>;
112
+
113
+ pagination: CursorResponse.Pagination;
114
+ }
115
+
116
+ export namespace CursorResponse {
117
+ export interface Pagination {
118
+ hasMore?: boolean;
119
+
120
+ nextCursor?: string | null;
121
+ }
122
+ }
123
+
124
+ export interface CursorParams {
125
+ cursor?: string;
126
+
127
+ limit?: number;
128
+ }
129
+
130
+ export class Cursor<Item> extends AbstractPage<Item> implements CursorResponse<Item> {
131
+ entities: Array<Item>;
132
+
133
+ pagination: CursorResponse.Pagination;
134
+
135
+ constructor(
136
+ client: OursPrivacyPlatform,
137
+ response: Response,
138
+ body: CursorResponse<Item>,
139
+ options: FinalRequestOptions,
140
+ ) {
141
+ super(client, response, body, options);
142
+
143
+ this.entities = body.entities || [];
144
+ this.pagination = body.pagination || {};
145
+ }
146
+
147
+ getPaginatedItems(): Item[] {
148
+ return this.entities ?? [];
149
+ }
150
+
151
+ nextPageRequestOptions(): PageRequestOptions | null {
152
+ const cursor = this.pagination?.nextCursor;
153
+ if (!cursor) {
154
+ return null;
155
+ }
156
+
157
+ return {
158
+ ...this.options,
159
+ query: {
160
+ ...maybeObj(this.options.query),
161
+ cursor,
162
+ },
163
+ };
164
+ }
165
+ }
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ export { OursPrivacyPlatform as default } from './client';
5
5
  export { type Uploadable, toFile } from './core/uploads';
6
6
  export { APIPromise } from './core/api-promise';
7
7
  export { OursPrivacyPlatform, type ClientOptions } from './client';
8
+ export { PagePromise } from './core/pagination';
8
9
  export {
9
10
  OursPrivacyPlatformError,
10
11
  APIError,
@@ -0,0 +1,2 @@
1
+ /** @deprecated Import from ./core/pagination instead */
2
+ export * from './core/pagination';
@@ -6,6 +6,13 @@ import { RequestOptions } from '../internal/request-options';
6
6
  import { path } from '../internal/utils/path';
7
7
 
8
8
  export class AllowedEvents extends APIResource {
9
+ /**
10
+ * List all allowed events. Requires scope: allowedEvent:list
11
+ */
12
+ list(options?: RequestOptions): APIPromise<AllowedEventListResponse> {
13
+ return this._client.get('/rest/v1/allowed-events', options);
14
+ }
15
+
9
16
  /**
10
17
  * Create a new allowed event. Requires scope: allowedEvent:create
11
18
  */
@@ -21,20 +28,31 @@ export class AllowedEvents extends APIResource {
21
28
  }
22
29
 
23
30
  /**
24
- * List all allowed events. Requires scope: allowedEvent:list
25
- */
26
- list(options?: RequestOptions): APIPromise<AllowedEventListResponse> {
27
- return this._client.get('/rest/v1/allowed-events', options);
28
- }
29
-
30
- /**
31
- * Delete a allowed event. Requires scope: allowedEvent:delete
31
+ * Delete an allowed event. Requires scope: allowedEvent:delete
32
32
  */
33
33
  delete(id: string, options?: RequestOptions): APIPromise<AllowedEventDeleteResponse> {
34
34
  return this._client.delete(path`/rest/v1/allowed-events/${id}`, options);
35
35
  }
36
36
  }
37
37
 
38
+ export interface AllowedEventListResponse {
39
+ entities: Array<AllowedEventListResponse.Entity>;
40
+ }
41
+
42
+ export namespace AllowedEventListResponse {
43
+ export interface Entity {
44
+ id: string;
45
+
46
+ createdAt: string;
47
+
48
+ destinationIds: Array<string>;
49
+
50
+ name: string;
51
+
52
+ updatedAt?: string | null;
53
+ }
54
+ }
55
+
38
56
  export interface AllowedEventCreateResponse {
39
57
  id: string;
40
58
 
@@ -59,24 +77,6 @@ export interface AllowedEventRetrieveResponse {
59
77
  updatedAt?: string | null;
60
78
  }
61
79
 
62
- export interface AllowedEventListResponse {
63
- entities: Array<AllowedEventListResponse.Entity>;
64
- }
65
-
66
- export namespace AllowedEventListResponse {
67
- export interface Entity {
68
- id: string;
69
-
70
- createdAt: string;
71
-
72
- destinationIds: Array<string>;
73
-
74
- name: string;
75
-
76
- updatedAt?: string | null;
77
- }
78
- }
79
-
80
80
  export type AllowedEventDeleteResponse = boolean;
81
81
 
82
82
  export interface AllowedEventCreateParams {
@@ -87,9 +87,9 @@ export interface AllowedEventCreateParams {
87
87
 
88
88
  export declare namespace AllowedEvents {
89
89
  export {
90
+ type AllowedEventListResponse as AllowedEventListResponse,
90
91
  type AllowedEventCreateResponse as AllowedEventCreateResponse,
91
92
  type AllowedEventRetrieveResponse as AllowedEventRetrieveResponse,
92
- type AllowedEventListResponse as AllowedEventListResponse,
93
93
  type AllowedEventDeleteResponse as AllowedEventDeleteResponse,
94
94
  type AllowedEventCreateParams as AllowedEventCreateParams,
95
95
  };