@compassdigital/sdk.typescript 3.0.0-beta.10

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 (143) hide show
  1. package/.editorconfig +10 -0
  2. package/README.md +40 -0
  3. package/gen.ts +353 -0
  4. package/lib/announcement.d.ts +76 -0
  5. package/lib/announcement.d.ts.map +1 -0
  6. package/lib/announcement.js +3 -0
  7. package/lib/announcement.js.map +1 -0
  8. package/lib/base.d.ts +55 -0
  9. package/lib/base.d.ts.map +1 -0
  10. package/lib/base.js +251 -0
  11. package/lib/base.js.map +1 -0
  12. package/lib/brand.d.ts +16 -0
  13. package/lib/brand.d.ts.map +1 -0
  14. package/lib/brand.js +3 -0
  15. package/lib/brand.js.map +1 -0
  16. package/lib/calendar.d.ts +85 -0
  17. package/lib/calendar.d.ts.map +1 -0
  18. package/lib/calendar.js +3 -0
  19. package/lib/calendar.js.map +1 -0
  20. package/lib/config.d.ts +68 -0
  21. package/lib/config.d.ts.map +1 -0
  22. package/lib/config.js +3 -0
  23. package/lib/config.js.map +1 -0
  24. package/lib/datalake.d.ts +19 -0
  25. package/lib/datalake.d.ts.map +1 -0
  26. package/lib/datalake.js +3 -0
  27. package/lib/datalake.js.map +1 -0
  28. package/lib/delivery.d.ts +34 -0
  29. package/lib/delivery.d.ts.map +1 -0
  30. package/lib/delivery.js +3 -0
  31. package/lib/delivery.js.map +1 -0
  32. package/lib/dh.d.ts +9 -0
  33. package/lib/dh.d.ts.map +1 -0
  34. package/lib/dh.js +3 -0
  35. package/lib/dh.js.map +1 -0
  36. package/lib/email.d.ts +5 -0
  37. package/lib/email.d.ts.map +1 -0
  38. package/lib/email.js +3 -0
  39. package/lib/email.js.map +1 -0
  40. package/lib/file.d.ts +17 -0
  41. package/lib/file.d.ts.map +1 -0
  42. package/lib/file.js +3 -0
  43. package/lib/file.js.map +1 -0
  44. package/lib/index.d.ts +1871 -0
  45. package/lib/index.d.ts.map +1 -0
  46. package/lib/index.js +2199 -0
  47. package/lib/index.js.map +1 -0
  48. package/lib/kds.d.ts +58 -0
  49. package/lib/kds.d.ts.map +1 -0
  50. package/lib/kds.js +3 -0
  51. package/lib/kds.js.map +1 -0
  52. package/lib/location.d.ts +747 -0
  53. package/lib/location.d.ts.map +1 -0
  54. package/lib/location.js +3 -0
  55. package/lib/location.js.map +1 -0
  56. package/lib/logger.d.ts +29 -0
  57. package/lib/logger.d.ts.map +1 -0
  58. package/lib/logger.js +3 -0
  59. package/lib/logger.js.map +1 -0
  60. package/lib/loyalty.d.ts +350 -0
  61. package/lib/loyalty.d.ts.map +1 -0
  62. package/lib/loyalty.js +3 -0
  63. package/lib/loyalty.js.map +1 -0
  64. package/lib/mealplan.d.ts +177 -0
  65. package/lib/mealplan.d.ts.map +1 -0
  66. package/lib/mealplan.js +3 -0
  67. package/lib/mealplan.js.map +1 -0
  68. package/lib/message.d.ts +38 -0
  69. package/lib/message.d.ts.map +1 -0
  70. package/lib/message.js +3 -0
  71. package/lib/message.js.map +1 -0
  72. package/lib/order.d.ts +303 -0
  73. package/lib/order.d.ts.map +1 -0
  74. package/lib/order.js +3 -0
  75. package/lib/order.js.map +1 -0
  76. package/lib/partner.d.ts +389 -0
  77. package/lib/partner.d.ts.map +1 -0
  78. package/lib/partner.js +3 -0
  79. package/lib/partner.js.map +1 -0
  80. package/lib/payment.d.ts +250 -0
  81. package/lib/payment.d.ts.map +1 -0
  82. package/lib/payment.js +3 -0
  83. package/lib/payment.js.map +1 -0
  84. package/lib/promo.d.ts +312 -0
  85. package/lib/promo.d.ts.map +1 -0
  86. package/lib/promo.js +3 -0
  87. package/lib/promo.js.map +1 -0
  88. package/lib/report.d.ts +376 -0
  89. package/lib/report.d.ts.map +1 -0
  90. package/lib/report.js +3 -0
  91. package/lib/report.js.map +1 -0
  92. package/lib/schedule.d.ts +95 -0
  93. package/lib/schedule.d.ts.map +1 -0
  94. package/lib/schedule.js +3 -0
  95. package/lib/schedule.js.map +1 -0
  96. package/lib/shoppingcart.d.ts +279 -0
  97. package/lib/shoppingcart.d.ts.map +1 -0
  98. package/lib/shoppingcart.js +3 -0
  99. package/lib/shoppingcart.js.map +1 -0
  100. package/lib/task.d.ts +171 -0
  101. package/lib/task.d.ts.map +1 -0
  102. package/lib/task.js +3 -0
  103. package/lib/task.js.map +1 -0
  104. package/lib/user.d.ts +359 -0
  105. package/lib/user.d.ts.map +1 -0
  106. package/lib/user.js +3 -0
  107. package/lib/user.js.map +1 -0
  108. package/lib/vote.d.ts +52 -0
  109. package/lib/vote.d.ts.map +1 -0
  110. package/lib/vote.js +3 -0
  111. package/lib/vote.js.map +1 -0
  112. package/manifest.json +104 -0
  113. package/package.json +48 -0
  114. package/src/announcement.ts +120 -0
  115. package/src/base.ts +212 -0
  116. package/src/brand.ts +25 -0
  117. package/src/calendar.ts +118 -0
  118. package/src/config.ts +118 -0
  119. package/src/datalake.ts +28 -0
  120. package/src/delivery.ts +48 -0
  121. package/src/dh.ts +12 -0
  122. package/src/email.ts +4 -0
  123. package/src/file.ts +25 -0
  124. package/src/index.ts +4777 -0
  125. package/src/kds.ts +81 -0
  126. package/src/location.ts +1196 -0
  127. package/src/logger.ts +44 -0
  128. package/src/loyalty.ts +529 -0
  129. package/src/mealplan.ts +262 -0
  130. package/src/message.ts +50 -0
  131. package/src/order.ts +461 -0
  132. package/src/partner.ts +468 -0
  133. package/src/payment.ts +385 -0
  134. package/src/promo.ts +444 -0
  135. package/src/report.ts +559 -0
  136. package/src/schedule.ts +135 -0
  137. package/src/shoppingcart.ts +390 -0
  138. package/src/task.ts +291 -0
  139. package/src/user.ts +582 -0
  140. package/src/vote.ts +67 -0
  141. package/template.ejs +21 -0
  142. package/test/client.test.ts +135 -0
  143. package/tsconfig.json +73 -0
package/.editorconfig ADDED
@@ -0,0 +1,10 @@
1
+ # https://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ indent_style = tab
6
+ indent_size = 4
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+ end_of_line = lf
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # @compassdigital/sdk.typescript
2
+
3
+ Compass Digital Labs TypeScript SDK
4
+
5
+ ## Install
6
+
7
+ ```
8
+ $ npm install --save @compassdigital/sdk.typescript@latest
9
+ ```
10
+
11
+ ## Example Client Usage
12
+
13
+ ``` typescript
14
+ import { ServiceClient } from "@compassdigital/sdk.typescript";
15
+
16
+ const api = new ServiceClient({ stage: "dev" });
17
+
18
+ async function main() {
19
+ const task = await api.get_task(task_id);
20
+ }
21
+ ```
22
+
23
+ ## Example Server Usage
24
+
25
+ ``` typescript
26
+ import Provider from "@compassdigital/provider";
27
+ import { GetTaskRequest, GetTaskResponse } from "@compassdigital/sdk.typescript/task";
28
+
29
+ const provider = new Provider({ type: "payment" });
30
+
31
+ provider.on<GetTaskRequest, GetTaskResponse>("get_task", function (req, next): void {
32
+ // ...
33
+ })
34
+ ```
35
+
36
+ ## Code Gen
37
+
38
+ 1. Add new services to `manifest.json`.
39
+ 2. Run `npm run gen`.
40
+
package/gen.ts ADDED
@@ -0,0 +1,353 @@
1
+
2
+ import fs from "fs";
3
+ import {
4
+ analyse,
5
+ load,
6
+ Schema,
7
+ Printer,
8
+ DocumentDetails,
9
+ OperationDetails,
10
+ isMethod,
11
+ } from "@icholy/openapi-ts";
12
+ import prettier from "prettier";
13
+ import path from "path";
14
+ import ejs from "ejs";
15
+
16
+ interface Manifest {
17
+ services: ManifestService[];
18
+ }
19
+
20
+ interface ManifestService {
21
+ name: string; // service name
22
+ swagger: string; // swagger url or file
23
+ }
24
+
25
+ interface ClientImport {
26
+ path: string;
27
+ name: string;
28
+ }
29
+
30
+ interface MethodParam {
31
+ name: string;
32
+ type: string;
33
+ required: boolean;
34
+ description: string;
35
+ }
36
+
37
+ interface ClientMethod {
38
+ comment: string;
39
+ name: string;
40
+ params: MethodParam[];
41
+ args: string[];
42
+ response: string;
43
+ }
44
+
45
+ /**
46
+ * The method and path combined into snake and pascal style names.
47
+ */
48
+ interface OperationName {
49
+ snake: string; // used for method names
50
+ pascal: string; // used for type names
51
+ }
52
+
53
+ /**
54
+ * This is a mapping between "${method} ${path}" and the default
55
+ * operationId.
56
+ */
57
+ const operationIDs : Record<string, string> = {
58
+ "get /location/group/{id}/deliverydestination": "get_location_group_deliverydestinations",
59
+ "get /location/search": "get_location_search",
60
+ "get /promo": "get_promos",
61
+ "get /schedule": "get_schedules",
62
+ "get /brand": "get_brands",
63
+ "get /announcement/resource": "get_resources"
64
+ };
65
+
66
+ class CodeGenerator {
67
+
68
+ private imports: ClientImport[] = [];
69
+ private methods: ClientMethod[] = [];
70
+
71
+ async generate(manifest: Manifest): Promise<void> {
72
+ // generate service types
73
+ for (const service of manifest.services) {
74
+ const print = new Printer();
75
+ console.log(`reading: ${service.swagger}`);
76
+ const doc = await load(service.swagger);
77
+ const details = analyse(doc);
78
+ this.transform(details, print, service);
79
+ const code = prettier.format(print.code(), { parser: "typescript", printWidth: 100 });
80
+ const filename = path.join("src", `${service.name}.ts`);
81
+ fs.writeFileSync(filename, code);
82
+ }
83
+ // generate client
84
+ const print = new Printer();
85
+ // client imports
86
+ const imports: Record<string, string[]> = {};
87
+ for (const _import of this.imports) {
88
+ imports[_import.path] ??= [];
89
+ imports[_import.path].push(_import.name);
90
+ }
91
+ for (const [path, names] of Object.entries(imports)) {
92
+ print.import(path, names);
93
+ print.blank();
94
+ }
95
+ // client methods
96
+ const template = fs.readFileSync("template.ejs", "utf-8");
97
+ print.raw(ejs.render(template, { methods: this.methods }));
98
+ const code = prettier.format(print.code(), { parser: "typescript", printWidth: 100 });
99
+ const filename = path.join("src", "index.ts");
100
+ fs.writeFileSync(filename, code);
101
+ }
102
+
103
+ /**
104
+ * Add an import that the client will need.
105
+ */
106
+ private addImport(service: ManifestService, name: string): void {
107
+ this.imports.push({
108
+ name,
109
+ path: `./${service.name}`,
110
+ });
111
+ }
112
+
113
+ /**
114
+ * Generate typescript code from the document details.
115
+ */
116
+ private transform(doc: DocumentDetails, print: Printer, service: ManifestService): void {
117
+ // definitions
118
+ for (const [name, schema] of Object.entries(doc.definitions)) {
119
+ print.schema(schema, name);
120
+ print.blank();
121
+ }
122
+ // routes
123
+ for (const op of doc.operations) {
124
+ const { params, path } = op;
125
+ for (const skipped of params.skipped) {
126
+ console.warn("SKIPPED", skipped);
127
+ }
128
+ // add missing path parameters
129
+ for (const name of this.findPathParams(path)) {
130
+ if (!params.path.properties[name]) {
131
+ params.path.setProperty(name, new Schema("string", {
132
+ required: true,
133
+ description: "TODO: add parameter to swagger.json",
134
+ }));
135
+ }
136
+ }
137
+ // make all path parameters required and valid path types.
138
+ for (const param of Object.values(params.path.properties)) {
139
+ if (!param.required) {
140
+ param.required = true;
141
+ if (param.description) {
142
+ param.description += "; ";
143
+ }
144
+ param.description += "TODO: mark parameter as required in swagger";
145
+ }
146
+ if (param.isRef() || param.type === "object") {
147
+ if (param.description) {
148
+ param.description += "; ";
149
+ }
150
+ param.description += `TODO: cannot use ${param.type} as path parameter`;
151
+ param.type = "string";
152
+ }
153
+ }
154
+ const name = this.inferName(op, service);
155
+ let comment = `${op.method.toUpperCase()} ${path}`;
156
+ if (op.obj.summary) {
157
+ comment += ` - ${op.obj.summary}`;
158
+ }
159
+
160
+ print.comment(comment);
161
+ print.blank();
162
+ // path parameters
163
+ if (!params.path.isEmpty()) {
164
+ const pathT = `${name.pascal}Path`;
165
+ print.schema(params.path, pathT);
166
+ print.blank();
167
+ }
168
+ // query parameters
169
+ const queryT = `${name.pascal}Query`;
170
+ if (!params.query.isEmpty()) {
171
+ this.addImport(service, queryT);
172
+ print.schema(params.query, queryT);
173
+ print.blank();
174
+ }
175
+ // body
176
+ const bodyT = `${name.pascal}Body`;
177
+ if (!params.body.isEmpty()) {
178
+ this.addImport(service, bodyT);
179
+ print.schema(params.body, bodyT);
180
+ print.blank();
181
+ }
182
+ // response
183
+ const responseT = `${name.pascal}Response`;
184
+ this.addImport(service, responseT);
185
+ print.schema(params.response, responseT);
186
+ print.blank();
187
+ // server request
188
+ const requestT = `${name.pascal}Request`;
189
+ print.schema(this.toRequestSchema(name, op), requestT);
190
+ print.blank();
191
+
192
+ // method parameters
193
+ const method: ClientMethod = {
194
+ comment: comment,
195
+ name: name.snake,
196
+ params:[],
197
+ args: [`"${service.name}"`, `"${name.snake}"`, `"${op.method}"`],
198
+ response: responseT,
199
+ }
200
+ // turn the path into a template string and add the
201
+ // corresponding method parameters.
202
+ let pathexpr = "`" + path + "`";
203
+ for (const name of this.findPathParams(path)) {
204
+ const schema = params.path.properties[name];
205
+ method.params.push({
206
+ name: name,
207
+ type: Printer.type(schema),
208
+ required: true,
209
+ description: schema.description,
210
+ });
211
+ pathexpr = pathexpr.replace(`{${name}}`, "${" + name + "}");
212
+ }
213
+ method.args.push(pathexpr);
214
+ // if there's a body, make that a parameter too.
215
+ if (!params.body.isEmpty()) {
216
+ method.params.push({
217
+ name: "body",
218
+ type: bodyT,
219
+ required: true,
220
+ description: params.body.description,
221
+ });
222
+ method.args.push("body");
223
+ } else {
224
+ method.args.push("null");
225
+ }
226
+ // build the options type.
227
+ const options = new Schema("empty");
228
+ if (!params.query.isEmpty()) {
229
+ const query = new Schema(queryT);
230
+ if (params.query.hasRequired()) {
231
+ query.required = true;
232
+ options.required = true;
233
+ }
234
+ options.setProperty("query", query);
235
+ }
236
+ options.merge(new Schema("RequestOptions"));
237
+ method.params.push({
238
+ name: "options",
239
+ type: Printer.type(options),
240
+ required: options.required,
241
+ description: "additional request options",
242
+ });
243
+ method.args.push("options");
244
+ this.methods.push(method);
245
+ }
246
+ }
247
+
248
+ /**
249
+ * Infer the operation name from the method and parameter.
250
+ * These are a bunch of dirty hacks to make the generated names consistent.
251
+ */
252
+ private inferName(op: OperationDetails, service: ManifestService): OperationName {
253
+ let { method, path } = op;
254
+ let path_segments: string[] = [];
255
+ // use the operationId from our collection if we have one.
256
+ // TODO: update the swagger.json definitions so we don't need to do this.
257
+ let operationID: string | undefined = operationIDs[`${op.method} ${op.path}`];
258
+ if (!operationID) {
259
+ operationID = op.obj.operationId;
260
+ }
261
+ if (operationID) {
262
+ const parts = operationID.split("_");
263
+ if (parts.length > 1) {
264
+ // replace common operationId values with the canonical ones.
265
+ if (parts[0] === "create") {
266
+ parts[0] = "post";
267
+ }
268
+ if (parts[0] === "update") {
269
+ parts[0] = "put";
270
+ }
271
+ if (parts[0] === "remove") {
272
+ parts[0] = "delete";
273
+ }
274
+ if (parts[0] === "find") {
275
+ parts[0] = "get";
276
+ }
277
+ if (!isMethod(parts[0])) {
278
+ parts.unshift(method);
279
+ }
280
+ if (parts[0] === method) {
281
+ parts.shift(); // remove the method
282
+ if (!parts[0].startsWith(service.name)) {
283
+ parts.unshift(service.name);
284
+ }
285
+ path_segments = parts;
286
+ }
287
+ }
288
+ if (parts.length > 1 && parts[0] === method) {
289
+ parts.shift(); // remove the method
290
+ if (!parts[0].startsWith(service.name)) {
291
+ parts.unshift(service.name);
292
+ }
293
+ path_segments = parts;
294
+ }
295
+ }
296
+ // combined the path & method into a name.
297
+ if (path_segments.length === 0) {
298
+ if (path.endsWith(".json")) {
299
+ path = path.slice(0, -5);
300
+ }
301
+ path_segments = path.split("/").filter(segment => {
302
+ return segment != "" && !segment.includes("{");
303
+ });
304
+ }
305
+ const parts = [method.toLowerCase(), ...path_segments];
306
+ return {
307
+ snake: parts.join("_"),
308
+ pascal: parts.map(s => s.charAt(0).toUpperCase() + s.substr(1)).join(''),
309
+ };
310
+ }
311
+
312
+ /**
313
+ * Find all the path parameter names.
314
+ */
315
+ private findPathParams(path: string): string[] {
316
+ const matches = path.matchAll(/{[^}]*}/g);
317
+ return Array.from(matches).map((match) => {
318
+ return match[0].slice(1, -1);
319
+ });
320
+ }
321
+
322
+ /**
323
+ * Create a Response type by combining the Query, Path, and Body types.
324
+ */
325
+ private toRequestSchema(name: OperationName, details: OperationDetails): Schema {
326
+ const request = new Schema("empty");
327
+ if (!details.params.body.isEmpty()) {
328
+ const body = new Schema(`${name.pascal}Body`);
329
+ body.required = true;
330
+ request.setProperty("body", body);
331
+ }
332
+ if (!details.params.query.isEmpty()) {
333
+ request.merge(new Schema(`${name.pascal}Query`));
334
+ }
335
+ if (!details.params.path.isEmpty()) {
336
+ request.merge(new Schema(`${name.pascal}Path`));
337
+ }
338
+ return request;
339
+ }
340
+ }
341
+
342
+
343
+
344
+ /**
345
+ * Main entry point.
346
+ */
347
+ async function main() {
348
+ const manifest: Manifest = JSON.parse(await fs.promises.readFile("manifest.json", "utf-8"));
349
+ const gen = new CodeGenerator();
350
+ await gen.generate(manifest);
351
+ }
352
+
353
+ main();
@@ -0,0 +1,76 @@
1
+ export interface Error {
2
+ code?: number;
3
+ message?: string;
4
+ }
5
+ export interface Success {
6
+ success?: boolean;
7
+ }
8
+ export interface Announcement {
9
+ id?: string;
10
+ name?: string;
11
+ type?: string;
12
+ key?: string;
13
+ app?: string;
14
+ is_global?: boolean;
15
+ allowed_resources?: string[];
16
+ position?: number;
17
+ active?: boolean;
18
+ info?: {
19
+ en?: Announcement_info;
20
+ fr?: Announcement_info;
21
+ };
22
+ date?: any;
23
+ [index: string]: any;
24
+ }
25
+ export interface Announcements {
26
+ announcements?: Announcement[];
27
+ }
28
+ export interface Announcement_info {
29
+ image_url?: string;
30
+ title?: string;
31
+ description?: string;
32
+ sub_text?: string;
33
+ button_text?: string;
34
+ }
35
+ export declare type PostAnnouncementBody = Announcement;
36
+ export declare type PostAnnouncementResponse = Announcement;
37
+ export interface PostAnnouncementRequest {
38
+ body: PostAnnouncementBody;
39
+ }
40
+ export interface GetAnnouncementResourcePath {
41
+ id: string;
42
+ }
43
+ export interface GetAnnouncementResourceQuery {
44
+ allowed_resource_id?: string;
45
+ disabled?: boolean;
46
+ }
47
+ export declare type GetAnnouncementResourceResponse = Announcements;
48
+ export interface GetAnnouncementResourceRequest extends GetAnnouncementResourceQuery, GetAnnouncementResourcePath {
49
+ }
50
+ export interface GetAnnouncementResourcesQuery {
51
+ disabled?: boolean;
52
+ }
53
+ export declare type GetAnnouncementResourcesResponse = Announcements;
54
+ export interface GetAnnouncementResourcesRequest extends GetAnnouncementResourcesQuery {
55
+ }
56
+ export interface GetAnnouncementPath {
57
+ id: string;
58
+ }
59
+ export declare type GetAnnouncementResponse = Announcement;
60
+ export interface GetAnnouncementRequest extends GetAnnouncementPath {
61
+ }
62
+ export interface PutAnnouncementPath {
63
+ id: string;
64
+ }
65
+ export declare type PutAnnouncementBody = Announcement;
66
+ export declare type PutAnnouncementResponse = Announcement;
67
+ export interface PutAnnouncementRequest extends PutAnnouncementPath {
68
+ body: PutAnnouncementBody;
69
+ }
70
+ export interface DeleteAnnouncementPath {
71
+ id: string;
72
+ }
73
+ export declare type DeleteAnnouncementResponse = Success;
74
+ export interface DeleteAnnouncementRequest extends DeleteAnnouncementPath {
75
+ }
76
+ //# sourceMappingURL=announcement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"announcement.d.ts","sourceRoot":"","sources":["../src/announcement.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,KAAK;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,OAAO;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAE3B,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,IAAI,CAAC,EAAE;QACL,EAAE,CAAC,EAAE,iBAAiB,CAAC;QACvB,EAAE,CAAC,EAAE,iBA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,oBAAY,uBAAuB,GAAG,YAAY,CAAC;AAEnD,MAAM,WAAW,sBAAuB,SAAQ,mBAAmB;IACjE,IAAI,EAAE,mBAAmB,CAAC;CAC3B;AAID,MAAM,WAAW,sBAAsB;IAErC,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,oBAAY,0BAA0B,GAAG,OAAO,CAAC;AAEjD,MAAM,WAAW,yBAA0B,SAAQ,sBAAsB;CAAG"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=announcement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"announcement.js","sourceRoot":"","sources":["../src/announcement.ts"],"names":[],"mappings":""}
package/lib/base.d.ts ADDED
@@ -0,0 +1,55 @@
1
+ export interface RequestOptions {
2
+ stage?: string;
3
+ token?: string;
4
+ headers?: Record<string, string>;
5
+ debug?: boolean;
6
+ retry?: number;
7
+ base_url?: string;
8
+ intercept?: InterceptFn;
9
+ }
10
+ export interface RequestData {
11
+ name: string;
12
+ service: string;
13
+ url: string;
14
+ method: string;
15
+ headers: Record<string, string>;
16
+ body?: string;
17
+ }
18
+ export interface ResponseData {
19
+ ok: boolean;
20
+ status: number;
21
+ body: string;
22
+ }
23
+ export declare type FetchFn = (req: RequestData) => Promise<ResponseData>;
24
+ export declare type InterceptFn = (req: RequestData, fetch: FetchFn) => Promise<ResponseData>;
25
+ export declare type ServiceRequestOptions = Omit<RequestOptions, "allow">;
26
+ export interface ServiceClientOptions extends ServiceRequestOptions {
27
+ services?: Record<string, ServiceRequestOptions>;
28
+ methods?: Record<string, ServiceRequestOptions>;
29
+ }
30
+ export declare class ServiceError extends Error {
31
+ status: number;
32
+ code: number;
33
+ constructor(status: number, // http status
34
+ code: number, // service error code
35
+ message: string);
36
+ static status(err: any): number;
37
+ static code(err: any): number;
38
+ static ignore<T>(codes: number[], response: Promise<T>): Promise<T | null>;
39
+ static from_res(res: ResponseData): ServiceError;
40
+ }
41
+ export declare abstract class BaseServiceClient {
42
+ private options;
43
+ constructor(options?: ServiceClientOptions);
44
+ /**
45
+ * Combine the route and query parameters into a full url.
46
+ */
47
+ private build_url;
48
+ private fetch;
49
+ private is_4xx;
50
+ private get_options;
51
+ protected request(service: string, name: string, method: string, route: string, body: any, options?: {
52
+ query?: any;
53
+ } & RequestOptions): Promise<any>;
54
+ }
55
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,cAAc;IAE7B,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,KAAK,CAAC,EAAE,MAAM,CAAC;IAGf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,SAAS,CAAC,EAAE,WAAW,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED,oBAAY,OAAO,GAAG,CAAC,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;AAElE,oBAAY,WAAW,GAAG,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;AAEtF,oBAAY,q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